--- loncom/build/filecompare.pl 2001/11/16 21:12:46 1.5 +++ loncom/build/filecompare.pl 2001/12/06 00:23:16 1.9 @@ -7,9 +7,10 @@ # YEAR=2001 # 9/27, 10/24, 10/25, 11/4 Scott Harrison # 11/14 Guy Albertelli -# 11/16 Scott Harrison +# 11/16,11/17 Scott Harrison +# 12/3,12/5 Scott Harrison # -# $Id: filecompare.pl,v 1.5 2001/11/16 21:12:46 harris41 Exp $ +# $Id: filecompare.pl,v 1.9 2001/12/06 00:23:16 harris41 Exp $ ### ############################################################################### @@ -34,6 +35,9 @@ my $invocation=< 2; cvstime<0 --> 1 + N=1: md5sum=same --> 1; cvstime<0 --> 2 N=2: same as N=1 except without md5sum N=3: md5sum=same --> 1; age<0 --> 2 N=4: cvstime>0 --> 2 + +The third way to pass arguments is set by the -s flag. +filecompare.pl -s SOURCE=[source] TARGET=[target] MODE=[mode] LOC1 LOC2 + +TARGET corresponds to the root path of LOC2. SOURCE corresponds to +the root path of LOC1. MODE can either be file, directory, link, or fileglob. + END unless (@ARGV) { print $invocation; @@ -64,7 +75,7 @@ unless (@ARGV) { # # Ways of comparison: # existence similarity -# cvs time similarity (first argument treated as CVS source) +# cvs time similarity (1st arg treated as CVS source; only for buildmode) # age similarity (modification time) # md5sum similarity # size similarity (bytes) @@ -92,16 +103,21 @@ unless (@ARGV) { # -q only show file names (based on first file/dir) # -v verbose mode (default) # -bN build/install mode (returns exitcode) +# -s status checking mode for lpml + my $verbose='1'; my $show='all'; my $buildmode=0; -while (@ARGV) { +my $statusmode=0; +ALOOP: while (@ARGV) { my $flag; if ($ARGV[0]=~/^\-(\w)/) { $flag=$1; if ($flag eq 'b') { $ARGV[0]=~/^\-\w(\d)/; $buildmode=$1; + shift @ARGV; + next ALOOP; } shift @ARGV; SWITCH: { @@ -110,6 +126,7 @@ while (@ARGV) { $show='same', last SWITCH if $flag eq 'p'; $show='different', last SWITCH if $flag eq 'n'; $show='all', last SWITCH if $flag eq 'a'; + $statusmode=1, last SWITCH if $flag eq 's'; print($invocation), exit(1); } } @@ -120,13 +137,34 @@ while (@ARGV) { dowarn('Verbose: '.$verbose."\n"); dowarn('Show: '.$show."\n"); +my @files; +my $loc1; +my $loc2; +# ----------------------------------------- If status checking mode for lpml +my ($sourceroot,$targetroot,$mode,$sourceglob,$targetglob); +my ($source,$target); +if ($statusmode==1) { + ($sourceroot,$targetroot,$mode,$sourceglob,$targetglob)=splice(@ARGV,0,5); + $targetroot.='/' if $targetroot!~/\/$/; + $sourceroot=~s/^SOURCE\=//; + $targetroot=~s/^TARGET\=//; + $source=$sourceroot.'/'.$sourceglob; + $target=$targetroot.''.$targetglob; +# print "SOURCE: $source\n"; +# print "TARGET: $target\n"; + if ($mode eq 'MODE=fileglob') { + @files=glob($source); + } +} +else { + # ----------------------------------------- Process file/dir location arguments # FILE1 FILE2 or DIR1 DIR2 -my $loc1=shift @ARGV; -my $loc2=shift @ARGV; +$loc1=shift @ARGV; +$loc2=shift @ARGV; my $dirmode='directories'; -my @files; unless ($loc1 and $loc2) { + print "LOC1: $loc1\nLOC2: $loc2\n"; print($invocation), exit(1); } if (-f $loc1) { @@ -145,7 +183,7 @@ else { dowarn('Processing for mode: '.$dirmode."\n"); dowarn('Location #1: '.$loc1."\n"); dowarn('Location #2: '.$loc2."\n"); - +} # --------------------------------------------- Process comparison restrictions # A list of space separated values (after the file/dir names) # can restrict the comparison. @@ -230,8 +268,13 @@ FLOOP: foreach my $file (@files) { $diffs='n/a'; } else { - my ($cvstime1,$cvstime2)=&{$MEASURE{'cvstime'}}($file1,$file2); - $cvstime=$cvstime1-$cvstime2; + if ($buildmode) { + my ($cvstime1,$cvstime2)=&{$MEASURE{'cvstime'}}($file1,$file2); + $cvstime=$cvstime1-$cvstime2; + } + else { + $cvstime='n/a'; + } my ($age1,$age2)=&{$MEASURE{'age'}}($file1,$file2); $age=$age1-$age2; my ($md5sum1,$md5sum2)=&{$MEASURE{'md5sum'}}($file1,$file2); @@ -239,7 +282,7 @@ FLOOP: foreach my $file (@files) { $md5sum='same'; $size=0; $lines=0; - $diffs=0; + $diffs='0:0'; } elsif ($md5sum1 ne $md5sum2) { $md5sum='different'; @@ -271,7 +314,7 @@ FLOOP: foreach my $file (@files) { $showflag=1; } } - elsif ($key eq 'cvstime') { + elsif ($key eq 'cvstime' and $buildmode) { if ($cvstime!=0) { $showflag=1; } @@ -307,6 +350,7 @@ FLOOP: foreach my $file (@files) { @ks=('existence','md5sum','cvstime','age','size','lines','diffs'); } my $showcount=length(@ks); + $showcount-- unless $buildmode; FLOOP3: for my $key (@ks) { if ($key eq 'existence') { if ($existence ne 'yes:yes') { @@ -318,7 +362,7 @@ FLOOP: foreach my $file (@files) { $showcount--; } } - elsif ($key eq 'cvstime') { + elsif ($key eq 'cvstime' and $buildmode) { if ($cvstime!=0) { $showcount--; } @@ -379,31 +423,39 @@ FLOOP: foreach my $file (@files) { } } elsif ($buildmode==4) { - if ($cvstime>0) { + if ($existence=~/no$/) { + exit(3); + } + elsif ($cvstime>0) { exit(2); } + elsif ($existence=~/^no/) { + exit(1); + } else { exit(0); } } - print "$file"; - if ($verbose==1) { - print "\t"; - print &{$OUTPUT{'existence'}}($existence); - print "\t"; - print &{$OUTPUT{'cvstime'}}($cvstime); - print "\t"; - print &{$OUTPUT{'age'}}($age); - print "\t"; - print &{$OUTPUT{'md5sum'}}($md5sum); - print "\t"; - print &{$OUTPUT{'size'}}($size); - print "\t"; - print &{$OUTPUT{'lines'}}($lines); - print "\t"; - print &{$OUTPUT{'diffs'}}($diffs); + if ($showflag) { + print "$file"; + if ($verbose==1) { + print "\t"; + print &{$OUTPUT{'existence'}}($existence); + print "\t"; + print &{$OUTPUT{'cvstime'}}($cvstime); + print "\t"; + print &{$OUTPUT{'age'}}($age); + print "\t"; + print &{$OUTPUT{'md5sum'}}($md5sum); + print "\t"; + print &{$OUTPUT{'size'}}($size); + print "\t"; + print &{$OUTPUT{'lines'}}($lines); + print "\t"; + print &{$OUTPUT{'diffs'}}($diffs); + } + print "\n"; } - print "\n"; } # ----------------------------------------------------------------- Subroutines