##ifndef NBDBUPG_PL_HEADER
##define NBDBUPG_PL_HEADER
##static char SCCS_ID[] = @(#) LIV  2001/05/22 13:59:41   nbdbupg.pl \main\callpilot2.0\2 ~
## LIV  2001/05/22 13:59:41   nbdbupg.pl \main\callpilot2.0\2 ~
## [liv/Database/nbdb0059] Changes for notification server
##
## vobadm  2000/06/28 02:10:39   nbdbupg.pl \main\callpilot2.0\1 ~
## [callpilot2.0_setup]
##
## vobadm  2000/06/28 02:10:38   nbdbupg.pl \main\callpilot2.0\1 ~
## [callpilot2.0_setup]
##
## suj  1999/12/01 11:22:07   nbdbupg.pl \main\callpilot\3 ~
## [nbdb0006] fix the upgrade problem from 5.11 to 7.06
##
## suj  1999/12/01 11:22:04   nbdbupg.pl \main\callpilot\3 ~
## [nbdb0006] fix the upgrade problem from 5.11 to 7.06
##
## suj  99/10/12 17:31:41   nbdbupg.pl \main\callpilot\2 ~
## [NBCFG_INCA] DB schema change for Inca
##
## suj  99/10/12 17:31:39   nbdbupg.pl \main\callpilot\2 ~
## [NBCFG_INCA] DB schema change for Inca
##
## suj  99/8/17 12:5:50   nbdbupg.pl \main\callpilot\1 ~
## [nbdb0002] version numver change in the database upgrade scripts
##
## suj  99/8/17 12:5:47   nbdbupg.pl \main\callpilot\1 ~
## [nbdb0002] version numver change in the database upgrade scripts
##
## suj  99/2/15 16:46:36   nbdbupg.pl \main\r2\2 ~
## [nbdb0020] DSE connectivity database change for SQL Anywhere upgrade
##
## johnlee  98/7/30 17:12:9   nbdbupg.pl \main\r2\1 ~
## [9T14_TM02127_2] - upgrade fixes
##
##endif
# selects the applicable portion of the upgrade file
sub usage
{
	print ("Usage: nbdbupg.pl <old_release> <upgrade_file> <new_upgrade_file\n");
	print ("Finds the updates that needs to be applied from the old release.\n");
	print ("and creates a new upgrade file.\n");

	exit(0);
}

if ($#ARGV != 2)
{
	&usage();
}

$old_release = @ARGV[0];

$upgrade_file = @ARGV[1];

$new_upgrade_file = @ARGV[2];

# open upgrade file and new upgrade file
unless(open(INFILE, $upgrade_file)) {
	die("Can't open upgrade file $upgrade_file\n");
}

unless(open(OUTFILE, ">" . $new_upgrade_file)) {
	die("Can't open new upgrade file $new_upgrade_file \n");
}

# look for key word UPGRELEASE which separates updates for each release
$found = 0;
#$org_release = $old_release;
while (($line = <INFILE>) && ($found == 0)) {
	if ($line =~ /UPGRELEASE/) {
		$line = <INFILE>;
		#print("\n$line");
		$line =~ s/\./0/g;
        	$old_release =~ s/\./0/g;
		@words = split(/ /, $line);
		$w = 1;
		# stop if less than or equal to old release
		while (($w <= @words) && ($found == 0)) {
			if ($words[$w-1] >= $old_release) {
				#print("$org_release found\n");
				$found = 1;
			}
			$w++;
		}
	}
} 

# if found, dump the rest of the file to the new file
if ($found == 1) {
	while ($line = <INFILE>) {
		print OUTFILE ($line);
	}
}
close(INFILE);
close(OUTFILE);
