#!/usr/bin/perl -w

#
# This Script converts a Montagaer OpenVMS Hobbyist License
# Into a nice DCL update script, which dies the unloading
# of the old and loading of the new license.
#
# Feed the Montagar file into stdin and you get the new
# DCL script on stdout
#
# Copyright (c) 2003 by Matthias Cramer, cramer@freestone.net
# You may do with this script whatever you like, as long as
# the original copyright is in place.
#

use strict;

my $line;
my $first=1;
my $product;
my $auth;
my $producer;
my $temp;

while ($line = <>) {
  if ($line =~ /^\$ LICENSE REGISTER/) {
    if ($first == 1) {
      print $temp;
      $first=0;
    } else {
      print "\$ LICENSE DISABLE/LOG $product\n";
      print "\$ WRITE SYS\$OUTPUT \"Registering and Loading $product\"\n";
      print "\$ WRITE SYS\$OUTPUT \"\"\n";
      print $temp;
      print "\$ LICENSE UNLOAD/LOG $product/PRODUCER = $producer\n";
      print "\$ LICENSE ENABLE $product /AUTH=$auth\n";
      print "\$ LICENSE LOAD $product /PRODUCER=$producer\n";
      print "\$!\n";
    }
    $temp="";
  }

  if ($line =~ /^\$ LICENSE REGISTER ([\w\d\-]+)\s/) {
    $product=$1;
  } elsif ($line =~ /AUTHORIZATION=([\w\d\-]+)\s/) {
    $auth=$1;
  } elsif ($line =~ /PRODUCER=([\w\d\-]+)/) {
    $producer=$1;
  }

  $temp.=$line;
}
