#! /bin/csh -f # Last modified on Tue Sep 20 21:53:12 1988 by stolfi #=============================================================== # Usage: filter-files [-h] ... # Applies a command to a bunch of files, and compares each # output with the original file. # When the two differ, the is renamed ,@ and the # filter output takes its place. Otherwise the remains # unchanged. # It also lists all changes in the file # /tmp/filter-files.log. # the -h switch, if present, is passed to diff. #=============================================================== set log="/tmp/$$filter-files.log" echo fixing files... echo '# File: '$log > $log echo '# Last modified by '$0' on '`date` >> $log echo '# ' >> $log if ($#argv > 10) then echo '# ' "$0 $argv[1-10]" '...' >> $log else echo '# ' "$0 $*" >> $log endif echo '# ' >> $log echo '# Changes (< = original, > = new): ' >> $log echo '# ' >> $log set diffopt = "" if ("$1" == "-h" ) then set diffopt = "$1" shift endif foreach infile ($argv[2-]) echo -n "Fixing $infile ... " echo ' ' >> $log echo -n "Fixing $infile ... " >> $log if (-f $infile == 0) then echo $infile is not a file\! continue endif if ("$infile:h" != "$infile") then set backup = "$infile:h/,@$infile:t" set result = "$infile:h/,@@@$infile:t" set oldbackup = "$infile:h/,,@$infile:t" else set backup = ",@$infile" set result = ",@@@$infile" set oldbackup = ",,@$infile" endif $1 < $infile > $result if ( $status > 0 ) then rm $result echo "failed, status = $status." echo "failed, status = $status." >> $log break else if ((-e $result == 0) || ({ cmp -s $infile $result })) then rm $result echo "no changes." echo "no changes." >> $log continue else if (-e $backup) then mv $backup $oldbackup endif mv $infile $backup mv $result $infile echo done. echo ' changed:' >> $log echo ' ' >>$log diff $diffopt $backup $infile | sed '/^---/d\ 1,$s/^[0-9].*//g' >> $log endif end echo "Done (see $log)."