#!/usr/bin/perl use Getopt::Std; use strict; my $Usage=" Preview - ver 1.01 Purpose: To list files that will be installed for a CTP Syntax: perl \/preview ProductLine Patch#... Examples (Unix): perl \$GENDIR/bin/preview testline 1001 1423 Examples (Windows): perl %gendir%\\bin\\preview testline 1001 1423 Arguments: ProductLine : product line to process Patch#... : one or more patch number(s) to process separated by spaces Patch#... : can also include dbdef filenames "; sub CheckProgram; sub GetArguments; sub ValidateProductLine; sub BuildProgramSystemTable; sub CheckPatchFiles; sub ProcessPatchFiles; sub DetermineObjects; sub DetermineLibPrograms; sub BuildOutput; sub PrintSummary; sub FlagProgram; my $BackupDir; my $BackupFile; my $BackupPatch; my $BreakLine="----------------------------------------------------------------\n"; my $ChgFile; my $Cmd; my $CmdRet; my $Continue; my $ExVerLine; my $FlgProgram; my $Lawdir; my $PRODUCTLINE; my $Patch; my $PatchFile; my $ProductLine; my $Prog; my $ProgHash; my $ReadFile; my $Replace; my $ScriptFile=""; my $Srgen; my $Status; my $Type; my $X; my $productline; my %FileList; my %GWFs; my %Invokes; my %Libraries; my %Pdlibs; my %ProgLib; my %ProgramSystem; my %Programs; my %Wslibs; my %SumProgs; my @CmdRet; my @CmdTmp; my @CtpLine; my @CtpVerNum; my @ExPrgVer; my @ExVerNum; my @Patches; $Lawdir=$ENV{'LAWDIR'}; ### print Usage if no arguments ### if ( @ARGV == 0 ) { print "$Usage\n"; exit 1; } #------------------------------------------------------------------------------ # Main processing GetArguments; ValidateProductLine; BuildProgramSystemTable; CheckPatchFiles; ProcessPatchFiles; if ( $#Patches > 0 ) { PrintSummary; } #------------------------------------------------------------------------------ # Get the command line parameters sub GetArguments { @Patches=@ARGV; $ProductLine=shift(@Patches); } #---------------------------------------------------------------------------- # Product Line validation sub ValidateProductLine { $PRODUCTLINE = uc $ProductLine; $productline = lc $ProductLine; my $ProdLine = `rngdbdump -nt gen prodline -f productline -k $PRODUCTLINE`; chomp $ProdLine; if ( $ProdLine eq "" ) { print "$ProductLine is not a valid product line.\n"; exit 1; } } #---------------------------------------------------------------------------- # This routine will build a list of programs and system codes they belong to # in the %ProgramSystem table, and builds a second table to indicate the # programs that are invoked in %Invokes sub BuildProgramSystemTable { foreach (`rngdbdump -nt -ipgmset1 gen program -f programcode systemcode iscalled -k $PRODUCTLINE`) { chomp $_; my ($ProgramCode,$SystemCode,$IsCalled)=split / +/,$_; $ProgramSystem{$ProgramCode}=$SystemCode; $IsCalled == 1 and $Invokes{$ProgramCode}="yes"; } } #------------------------------------------------------------------------------ # Verify the patch files exist sub CheckPatchFiles { $Continue="y"; foreach $Patch (@Patches) { $PatchFile="8.0.3_patch_".$Patch.".tar"; if ( ! -e $PatchFile ) { print "*** Patch file missing for $Patch\n"; $Continue="n"; } } if ($Continue eq "n") { exit 1; } } #------------------------------------------------------------------------------ # process the patch files sub ProcessPatchFiles { foreach $Patch (@Patches) { undef %FileList; undef %GWFs; undef %Invokes; undef %Libraries; undef %Pdlibs; undef %ProgLib; undef %Programs; undef %Wslibs; print "Processing $Patch against $productline\n"; print $BreakLine; print "The following files will be updated from this CTP\n"; print "\n"; print "File Old Version New Version\n"; print "-------------------- -------------------- ------------------\n"; $PatchFile="8.0.3_patch_".$Patch.".tar"; # extract the version file my $Result=`tar -xf $PatchFile Versions`; # read through the versions file file open VERSIONS, "Versions" or die "Can't open versions file for processing\n"; $Status=0; while () { chomp; if (/,/) { CheckProgram; } } # Clean up unlink "Versions"; print $BreakLine; DetermineObjects; DetermineLibPrograms; BuildOutput; } } #---------------------------------------------------------------------------- # Program check routine - looks to see if the new program will replace the # existing program. sub CheckProgram { @CtpLine=split /,/; @CtpVerNum=split /\./,@CtpLine[2]; $Prog=$Lawdir."/".$productline."/".@CtpLine[0]."/".@CtpLine[1]; # print "Checking $Prog\n"; if ( ! -e $Prog ) { @ExPrgVer[1]=$Prog; @ExPrgVer[2]="None"; } else { $ExVerLine=`head -1 $Prog`; $ExVerLine=~s/\*//g; @ExPrgVer=split / /, $ExVerLine; } @ExVerNum=split /\./, @ExPrgVer[2]; # print "Versions $ExPrgVer[2]\n"; $Replace="n"; if ($#CtpVerNum==$#ExVerNum) { # print "Check #1 testing\n"; for ($X=0; $X <= $#ExVerNum; $X++) { if ($CtpVerNum[$X] > $ExVerNum[$X]) { $Replace="y"; last; } elsif ($CtpVerNum[$X] < $ExVerNum[$X]) { last; } } } elsif ($#CtpVerNum<$#ExVerNum) { # print "Check #2 testing\n"; for ($X=0; $X <= $#CtpVerNum; $X++) { if ($CtpVerNum[$X] > $ExVerNum[$X]) { $Replace="y"; last; } elsif ($CtpVerNum[$X] < $ExVerNum[$X]) { last; } } } elsif ($#CtpVerNum>$#ExVerNum) { # print "Check #3 testing\n"; for ($X=0; $X <= $#ExVerNum; $X++) { # print "Checking $CtpVerNum[$X] against $ExVerNum[$X]\n"; if ($CtpVerNum[$X] > $ExVerNum[$X]) { $Replace="y"; last; } elsif ($CtpVerNum[$X] < $ExVerNum[$X]) { last; } } $Replace="y"; } else { print "How did I get here, screwy programming!"; } if ( $Replace eq "y" ) { printf "%-20s %-20s %-20s\n", $CtpLine[1], @ExPrgVer[2], @CtpLine[2]; $ChgFile=@CtpLine[1]; $_=$Prog; s!$Lawdir/$productline/!!; $FileList{$_}="yes"; } } #---------------------------------------------------------------------------- sub DetermineObjects { foreach my $PatchFile (sort keys %FileList) { if ($PatchFile =~ "pdlib/") { $_=$PatchFile; s!.*pdlib/!!; $Pdlibs{$_}=$_; } elsif ($PatchFile =~ "wslib/") { $_=$PatchFile; s!.*wslib/!!; $Wslibs{$_}=$_; } elsif ($PatchFile =~ "^..src/") { $_=$PatchFile; s!^..src/!!; if (/\.[so]r$/) { $Srgen="yes"; } elsif (s/\.scr$//) { if ( !($Programs{$_}) ) { FlagProgram($_,"A-Patched"); } if ( $Invokes{$_} ) { foreach my $Invoking (`rngdbdump -nt -iPLCSET2 gen pgmcall -f programcode -k $PRODUCTLINE $_`) { chomp $Invoking; if ( !($Programs{$Invoking}) ) { FlagProgram($Invoking,"B-Invoke "); } } } } elsif (s/(\.rpt|\.cfg|PD|WS)$//) { if ( !($Programs{$_}) ) { FlagProgram($_,"A-Patched "); } } } elsif ($PatchFile =~ "^metadata/..meta/") { $_=$PatchFile; s!^metadata/..meta/!!; if (/\.skn$/) { $Srgen="yes"; } elsif (s/\.pgm//) { if ( !($Programs{$_}) ) { FlagProgram($_,"A-Patched "); } } elsif (s/\.lib$//) { # Process it as both a pdlib and wslib - no errors are caused later. # This is more efficient than looking up which type of lib this is. $Pdlibs{$_}=$PatchFile; $Wslibs{$_}=$PatchFile; } elsif (s/\.wrk$//) { s/_.*$//; if ( !($Programs{$_}) ) { FlagProgram($_,"C-Workfile "); } } } elsif ($PatchFile =~ "^metadata/globalmeta/") { $_=$PatchFile; s!^metadata/globalmeta/!!; if (s/\.wrk$//) { s/GLOBAL_//; $GWFs{$_}=$PatchFile; } } } } #------------------------------------------------------------------------------ sub DetermineLibPrograms { foreach my $GWF (sort keys %GWFs) { foreach my $WFPdlib (`rngdbdump -nt -ilwfset2 gen librarywf -f libname -k $PRODUCTLINE $GWF`) { chomp $WFPdlib; $Pdlibs{$WFPdlib}=$GWFs{$GWF}; } } foreach my $Wslib (sort keys %Wslibs) { foreach my $WsPdlib (`rngdbdump -nt -ilwsset2 gen libraryws -f libname -k $PRODUCTLINE $Wslib`) { chomp $WsPdlib; $Pdlibs{$WsPdlib}=$Wslibs{$Wslib}; } } foreach my $Pdlib (sort keys %Pdlibs) { foreach my $PdlibProg (`rngdbdump -nt -iplbset2 gen pgmlib -f programcode -k $PRODUCTLINE $Pdlib`) { chomp $PdlibProg; # if ( !($Programs{$PdlibProg}) ) { $ProgHash=$PdlibProg."-".$Pdlibs{$Pdlib}; if ( !($ProgLib{$ProgHash}) ) { $ProgLib{$ProgHash}="yes"; if ( !($Programs{$PdlibProg}) ) { FlagProgram($PdlibProg,"E-Lib"); $Libraries{$PdlibProg}=$Pdlibs{$Pdlib}; } else { if ( $Programs{$PdlibProg} eq "E-Lib" ) { $Libraries{$PdlibProg}=$Libraries{$PdlibProg}.",".$Pdlibs{$Pdlib}; } } } # } } } } #------------------------------------------------------------------------------ sub FlagProgram { ($FlgProgram,$Type)=@_; if ( $Programs{$FlgProgram} ) { if ( $Programs{$FlgProgram} =~ /E-/ ) { $Programs{$FlgProgram} = $Type; } elsif ( $Programs{$FlgProgram} =~ /D-/ ) { if ( $Type =~ /(C-|B-|A-)/ ) { $Programs{$FlgProgram} = $Type; } } elsif ( $Programs{$FlgProgram} =~ /C-/ ) { if ( $Type =~ /(B-|A-)/ ) { $Programs{$FlgProgram} = $Type; } } elsif ( $Programs{$FlgProgram} =~ /B-/ ) { if ( $Type =~ /A-/ ) { $Programs{$FlgProgram} = $Type; } } } else { $Programs{$FlgProgram} = $Type; } } #------------------------------------------------------------------------------ sub BuildOutput { print "\n"; print "The following programs will be compiled\n"; print "\n"; my $ExecCmd; my %ChgList; foreach my $Program (sort keys %Programs) { my $Change=$Programs{$Program}; my $ChgKey=$Change.$Program; $ChgList{$ChgKey}=$Program; } foreach my $ChgRec (sort keys %ChgList) { my $Program=$ChgList{$ChgRec}; my $System=$ProgramSystem{$Program}; my $Change=$Programs{$Program}; my $LibList=$Libraries{$Program}; printf "%-12s %-2s %-5s %-40s\n", $Change,$System,$Program,$LibList; if ( $#Patches > 0 ) { my $SumData=$System." ".$Program; if ( ! $SumProgs{$SumData} ) { $SumProgs{$SumData}=$Change; } else { $SumProgs{$SumData}=$SumProgs{$SumData}.",".$Change; } } } print $BreakLine; print "\f"; } #------------------------------------------------------------------------------ sub PrintSummary { print "The following programs will be compiled for CTPs\n"; print " @Patches"; print "\n\n"; foreach my $Program ( sort keys %SumProgs ) { printf "%-8s %-70s\n", $Program,$SumProgs{$Program}; } print $BreakLine; }