version 1.1, 2001/10/26 00:18:54
|
version 1.2, 2001/11/05 02:57:21
|
Line 2
|
Line 2
|
|
|
# Scott Harrison |
# Scott Harrison |
# YEAR=2001 |
# YEAR=2001 |
# 9/27, 10/24, 10/25 |
# 9/27, 10/24, 10/25, 11/4 |
|
|
my $invocation=<<END; |
my $invocation=<<END; |
# ------------------------------------------------------------------ Invocation |
# ------------------------------------------------------------------ Invocation |
Line 12 my $invocation=<<END;
|
Line 12 my $invocation=<<END;
|
# |
# |
# A list of space separated values (after the file/dir names) |
# A list of space separated values (after the file/dir names) |
# can restrict the comparison. |
# can restrict the comparison. |
# These values can be: existence, age, md5sum, size, lines, and/or diffs. |
# These values can be: existence, cvstime, age, md5sum, size, lines, |
|
# and/or diffs. |
# |
# |
# Flags (before file/dir names): |
# Flags (before file/dir names): |
# -p show all files the same |
# -p show all files the same |
Line 32 unless (@ARGV) {
|
Line 33 unless (@ARGV) {
|
# |
# |
# Ways of comparison: |
# Ways of comparison: |
# existence similarity |
# existence similarity |
|
# cvs time similarity (first argument treated as CVS source) |
# age similarity (modification time) |
# age similarity (modification time) |
# md5sum similarity |
# md5sum similarity |
# size similarity (bytes) |
# size similarity (bytes) |
Line 40 unless (@ARGV) {
|
Line 42 unless (@ARGV) {
|
# |
# |
# Quantities of comparison: |
# Quantities of comparison: |
# existence (no,yes); other values become 'n/a' |
# existence (no,yes); other values become 'n/a' |
|
# cvstime in seconds |
# age in seconds |
# age in seconds |
# md5sum ("same" or "different") |
# md5sum ("same" or "different") |
# size similarity (byte difference) |
# size similarity (byte difference) |
Line 48 unless (@ARGV) {
|
Line 51 unless (@ARGV) {
|
# |
# |
# Text output of comparison: |
# Text output of comparison: |
# existence VALUE |
# existence VALUE |
|
# cvstime VALUE |
# age VALUE |
# age VALUE |
# md5sum VALUE |
# md5sum VALUE |
# size VALUE |
# size VALUE |
Line 57 unless (@ARGV) {
|
Line 61 unless (@ARGV) {
|
# Output of comparison: |
# Output of comparison: |
# exist |
# exist |
# if md5sum not same, then different |
# if md5sum not same, then different |
|
# if cvstime not 0, then older/newer |
# if age not 0, then older/newer |
# if age not 0, then older/newer |
# if size not 0, then bigger/smaller |
# if size not 0, then bigger/smaller |
# if lines not 0, then more lines of code/less lines of code |
# if lines not 0, then more lines of code/less lines of code |
Line 72 unless (@ARGV) {
|
Line 77 unless (@ARGV) {
|
# -a show all files (with comparisons) |
# -a show all files (with comparisons) |
# -q only show file names (based on first file/dir) |
# -q only show file names (based on first file/dir) |
# -v verbose mode (default) |
# -v verbose mode (default) |
|
# -b build/install mode (returns exitcode) |
my $verbose='1'; |
my $verbose='1'; |
my $show='all'; |
my $show='all'; |
|
my $buildmode=0; |
while (@ARGV) { |
while (@ARGV) { |
my $flag; |
my $flag; |
if ($ARGV[0]=~/^\-(\w)/) { |
if ($ARGV[0]=~/^\-(\w)/) { |
Line 85 while (@ARGV) {
|
Line 92 while (@ARGV) {
|
$show='same', last SWITCH if $flag eq 'p'; |
$show='same', last SWITCH if $flag eq 'p'; |
$show='different', last SWITCH if $flag eq 'n'; |
$show='different', last SWITCH if $flag eq 'n'; |
$show='all', last SWITCH if $flag eq 'a'; |
$show='all', last SWITCH if $flag eq 'a'; |
|
$buildmode=1, last SWITCH if $flag eq 'b'; |
|
$buildmode=2, last SWITCH if $flag eq 'B'; |
|
$buildmode=3, last SWITCH if $flag eq 'g'; |
|
$buildmode=4, last SWITCH if $flag eq 'G'; |
print($invocation), exit(1); |
print($invocation), exit(1); |
} |
} |
} |
} |
Line 92 while (@ARGV) {
|
Line 103 while (@ARGV) {
|
last; |
last; |
} |
} |
} |
} |
warn('Verbose: '.$verbose."\n"); |
dowarn('Verbose: '.$verbose."\n"); |
warn('Show: '.$show."\n"); |
dowarn('Show: '.$show."\n"); |
|
|
# FILE1 FILE2 or DIR1 DIR2 |
# FILE1 FILE2 or DIR1 DIR2 |
my $loc1=shift @ARGV; |
my $loc1=shift @ARGV; |
Line 116 else {
|
Line 127 else {
|
} |
} |
map {chomp; s/^$loc1\///; $_} @files; |
map {chomp; s/^$loc1\///; $_} @files; |
} |
} |
warn('Processing for mode: '.$dirmode."\n"); |
dowarn('Processing for mode: '.$dirmode."\n"); |
warn('Location #1: '.$loc1."\n"); |
dowarn('Location #1: '.$loc1."\n"); |
warn('Location #2: '.$loc2."\n"); |
dowarn('Location #2: '.$loc2."\n"); |
|
|
# A list of space separated values (after the file/dir names) |
# A list of space separated values (after the file/dir names) |
# can restrict the comparison. |
# can restrict the comparison. |
Line 126 my %restrict;
|
Line 137 my %restrict;
|
while (@ARGV) { |
while (@ARGV) { |
my $r=shift @ARGV; |
my $r=shift @ARGV; |
if ($r eq 'existence' or |
if ($r eq 'existence' or |
|
$r eq 'cvstime' or |
$r eq 'md5sum' or |
$r eq 'md5sum' or |
$r eq 'age' or |
$r eq 'age' or |
$r eq 'size' or |
$r eq 'size' or |
Line 155 my %OUTPUT=(
|
Line 167 my %OUTPUT=(
|
return; |
return; |
} |
} |
), |
), |
|
'cvstime'=>( |
|
sub { |
|
print 'cvstime: '.@_[0]; |
|
return; |
|
} |
|
), |
'age'=>( |
'age'=>( |
sub { |
sub { |
print 'age: '.@_[0]; |
print 'age: '.@_[0]; |
Line 198 my %MEASURE=(
|
Line 216 my %MEASURE=(
|
return ($rv1,$rv2); |
return ($rv1,$rv2); |
} |
} |
), |
), |
|
'cvstime'=>( |
|
sub { |
|
my ($file1,$file2)=@_; |
|
my $rv1=&cvstime($file1); |
|
my @a=stat($file2); my $gmt=gmtime($a[9]); |
|
my $rv2=&utctime($gmt); |
|
return ($rv1,$rv2); |
|
} |
|
), |
'age'=>( |
'age'=>( |
sub { |
sub { |
my ($file1,$file2)=@_; |
my ($file1,$file2)=@_; |
my @a=stat($file1); my $rv1=$a[10]; |
my @a=stat($file1); my $rv1=$a[9]; |
@a=stat($file2); my $rv2=$a[10]; |
@a=stat($file2); my $rv2=$a[9]; |
return ($rv1,$rv2); |
return ($rv1,$rv2); |
} |
} |
), |
), |
Line 247 FLOP: foreach my $file (@files) {
|
Line 274 FLOP: foreach my $file (@files) {
|
} |
} |
my ($existence1,$existence2)=&{$MEASURE{'existence'}}($file1,$file2); |
my ($existence1,$existence2)=&{$MEASURE{'existence'}}($file1,$file2); |
my $existence=$existence1.':'.$existence2; |
my $existence=$existence1.':'.$existence2; |
my ($md5sum,$age,$size,$lines,$diffs); |
my ($cvstime,$md5sum,$age,$size,$lines,$diffs); |
if ($existence1 eq 'no' or $existence2 eq 'no') { |
if ($existence1 eq 'no' or $existence2 eq 'no') { |
$md5sum='n/a'; |
$md5sum='n/a'; |
$age='n/a'; |
$age='n/a'; |
|
$cvstime='n/a'; |
$size='n/a'; |
$size='n/a'; |
$lines='n/a'; |
$lines='n/a'; |
$diffs='n/a'; |
$diffs='n/a'; |
} |
} |
else { |
else { |
|
my ($cvstime1,$cvstime2)=&{$MEASURE{'cvstime'}}($file1,$file2); |
|
$cvstime=$cvstime1-$cvstime2; |
my ($age1,$age2)=&{$MEASURE{'age'}}($file1,$file2); |
my ($age1,$age2)=&{$MEASURE{'age'}}($file1,$file2); |
$age=$age1-$age2; |
$age=$age1-$age2; |
my ($md5sum1,$md5sum2)=&{$MEASURE{'md5sum'}}($file1,$file2); |
my ($md5sum1,$md5sum2)=&{$MEASURE{'md5sum'}}($file1,$file2); |
Line 282 FLOP: foreach my $file (@files) {
|
Line 312 FLOP: foreach my $file (@files) {
|
if ($show eq 'different') { |
if ($show eq 'different') { |
my @ks=(keys %restrict); |
my @ks=(keys %restrict); |
unless (@ks) { |
unless (@ks) { |
@ks=('existence','md5sum','age','size','lines','diffs'); |
@ks=('existence','cvstime','md5sum','age','size','lines','diffs'); |
} |
} |
FLOP2: for my $key (@ks) { |
FLOP2: for my $key (@ks) { |
if ($key eq 'existence') { |
if ($key eq 'existence') { |
Line 295 FLOP: foreach my $file (@files) {
|
Line 325 FLOP: foreach my $file (@files) {
|
$showflag=1; |
$showflag=1; |
} |
} |
} |
} |
|
elsif ($key eq 'cvstime') { |
|
if ($cvstime!=0) { |
|
$showflag=1; |
|
} |
|
} |
elsif ($key eq 'age') { |
elsif ($key eq 'age') { |
if ($age!=0) { |
if ($age!=0) { |
$showflag=1; |
$showflag=1; |
Line 323 FLOP: foreach my $file (@files) {
|
Line 358 FLOP: foreach my $file (@files) {
|
elsif ($show eq 'same') { |
elsif ($show eq 'same') { |
my @ks=(keys %restrict); |
my @ks=(keys %restrict); |
unless (@ks) { |
unless (@ks) { |
@ks=('existence','md5sum','age','size','lines','diffs'); |
@ks=('existence','md5sum','cvstime','age','size','lines','diffs'); |
} |
} |
my $showcount=length(@ks); |
my $showcount=length(@ks); |
FLOP3: for my $key (@ks) { |
FLOP3: for my $key (@ks) { |
Line 337 FLOP: foreach my $file (@files) {
|
Line 372 FLOP: foreach my $file (@files) {
|
$showcount--; |
$showcount--; |
} |
} |
} |
} |
|
elsif ($key eq 'cvstime') { |
|
if ($cvstime!=0) { |
|
$showcount--; |
|
} |
|
} |
elsif ($key eq 'age') { |
elsif ($key eq 'age') { |
if ($age!=0) { |
if ($age!=0) { |
$showcount--; |
$showcount--; |
Line 362 FLOP: foreach my $file (@files) {
|
Line 402 FLOP: foreach my $file (@files) {
|
$showflag=1; |
$showflag=1; |
} |
} |
} |
} |
|
if ($buildmode==1) { |
|
if ($md5sum eq 'same') { |
|
exit(1); |
|
} |
|
elsif ($cvstime<0) { |
|
exit(2); |
|
} |
|
else { |
|
exit(0); |
|
} |
|
} |
|
elsif ($buildmode==2) { |
|
if ($cvstime<0) { |
|
exit(2); |
|
} |
|
else { |
|
exit(0); |
|
} |
|
} |
|
elsif ($buildmode==3) { |
|
if ($md5sum eq 'same') { |
|
exit(1); |
|
} |
|
elsif ($age<0) { |
|
exit(2); |
|
} |
|
else { |
|
exit(0); |
|
} |
|
} |
|
elsif ($buildmode==4) { |
|
if ($cvstime>0) { |
|
exit(2); |
|
} |
|
else { |
|
exit(0); |
|
} |
|
} |
print "$file"; |
print "$file"; |
if ($verbose==1) { |
if ($verbose==1) { |
print "\t"; |
print "\t"; |
print &{$OUTPUT{'existence'}}($existence); |
print &{$OUTPUT{'existence'}}($existence); |
print "\t"; |
print "\t"; |
|
print &{$OUTPUT{'cvstime'}}($cvstime); |
|
print "\t"; |
print &{$OUTPUT{'age'}}($age); |
print &{$OUTPUT{'age'}}($age); |
print "\t"; |
print "\t"; |
print &{$OUTPUT{'md5sum'}}($md5sum); |
print &{$OUTPUT{'md5sum'}}($md5sum); |
Line 380 FLOP: foreach my $file (@files) {
|
Line 460 FLOP: foreach my $file (@files) {
|
print "\n"; |
print "\n"; |
} |
} |
|
|
|
sub cvstime { |
|
my ($f)=@_; |
|
my $path; my $file; |
|
if ($f=~/^(.*\/)(.*?)$/) { |
|
$f=~/^(.*\/)(.*?)$/; |
|
($path,$file)=($1,$2); |
|
} |
|
else { |
|
$file=$f; $path=''; |
|
} |
|
my $cvstime; |
|
if ($buildmode!=3) { |
|
my $entry=`grep '^/$file/' ${path}CVS/Entries` or |
|
die('*** ERROR *** cannot grep against '.${path}. |
|
'CVS/Entries for ' .$file . "\n"); |
|
my @fields=split(/\//,$entry); |
|
$cvstime=`date -d '$fields[3] UTC' --utc +"%s"`; |
|
chomp $cvstime; |
|
} |
|
else { |
|
$cvstime='n/a'; |
|
} |
|
return $cvstime; |
|
} |
|
|
|
sub utctime { |
|
my ($f)=@_; |
|
my $utctime=`date -d '$f UTC' --utc +"%s"`; |
|
chomp $utctime; |
|
return $utctime; |
|
} |
|
|
|
sub dowarn { |
|
my ($msg)=@_; |
|
warn($msg) unless $buildmode; |
|
} |