#!/usr/bin/perl -w

#
# Function:  
#  Handle all the renames & edits needed to cut a new version of the 3380/3390/3375 mods
#

my $oldver = '08';
my $newver = '09';
my $oldname = 'i';
my $newname = 'j';

my $sed = "sed -f /herc2/mvs/3390/misc/new-version.sed";
	
sub fixfile {
	my($old, $new, $save);
	if (@_ == 2) {
		($old, $new) = @_;		# grab passed args
		$save = 'no';
	}
	if (@_ == 3) {
		($old, $new, $save) = @_;	# grab passed args
	}
	if ($save eq 'save') {
		system "mv $new $old";
	}
	print "FixFile $old $new\n";
	system "$sed $old > $new"		# make changes
		if -e $old;
	system "rm $old"			# remove old file
		if -e $old;
}

#-------------------------------------------------------------------------------

my $dir = "/herc2/mvs/3390";
chdir $dir or die "cannot chdir to directory $dir\n";
system "rm *~ 2> /dev/null";

#-------------------------------------------------------------------------------

$dir = "/herc2/mvs/3390/asm";
chdir $dir or die "cannot chdir to directory $dir\n";
system "rm *~ 2> /dev/null";
&fixfile("stage1.old", "stage1.asm", "save");

#-------------------------------------------------------------------------------

$dir = "/herc2/mvs/3390/jcl";
chdir $dir or die "cannot chdir to directory $dir\n";
system "rm *~ 2> /dev/null";
my @jclfiles = glob "*.jcl";
foreach $file (@jclfiles) {
	&fixfile("$file.old", "$file", "save");
}

#-------------------------------------------------------------------------------

$dir = "/herc2/mvs/3390/misc";
chdir $dir or die "cannot chdir to directory $dir\n";
system "rm *~ 2> /dev/null";
&fixfile("loc5$oldver.ctl", "loc5$newver.ctl");
&fixfile("mvs5$oldver.ctl", "mvs5$newver.ctl");
&fixfile("mvs7$oldver.ctl", "mvs7$newver.ctl");
&fixfile("mvs8$oldver.ctl", "mvs8$newver.ctl");
&fixfile("mvs9$oldver.ctl", "mvs9$newver.ctl");
&fixfile("pag$oldname" . "01.ctl", "pag$newname" . "01.ctl");
&fixfile("pag$oldname" . "02.ctl", "pag$newname" . "02.ctl");
&fixfile("pag$oldname" . "03.ctl", "pag$newname" . "03.ctl");
system "mv herc00$oldver.cnf herc00$newver.cnf"
	if -e "herc00$oldver.cnf";

#-------------------------------------------------------------------------------

print "\n";
print "Don't forget to update stage1 for new device support\n";
print "Don't forget to change new-dasd, and run it\n";
print "Don't forget to edit herc00xx.cnf for new dasd volumes\n";
print "... and note CUU used in 02-init-sysres.jcl\n";
print "Don't forget to edit misc/mvs38j for new configuration file name\n";
print "\n";
print "Warning: I haven't figured out how to make sed make multiple changes\n";
print "on a line, so reviewing the JCL before running it is a good idea.\n";
print "For the most part, I've tried to eliminate duplicate hits in the input JCL\n";

exit 0;

# Change log:
#
# 2002-04-22	removed fixfile call for updte, jobcard.updte no longer needed.
#		added 3375 control file - mvs7xx






