#perl # ###################################################################### # This is file changes.pl. # # Determine the changed pages between 2 dvi files using dvii and diff # use strict ; my $version = "0.02 (17 August 2002)" ; # CHANGE these two values (if needed) to point to the dvii and diff # executables. our $DVII = "dvii" ; our $DIFF = "diff" ; use Getopt::Std ; my $usage_string = "changes.pl $version USAGE: changes.pl [options] dvi_file1 dvi_file2 \n" ; my $number_of_args = $#ARGV ; # Check that there are at least three arguments. if ($number_of_args < 1) { print STDOUT $usage_string ; exit 0 ; } # Get the 2 filenames my $dvifile1 = $ARGV[0] ; my $dvifile2 = $ARGV[1] ; # ERROR CHECKING. # Check that these two files exist. if (!(-f $dvifile1)) { # Maybe we need to append a .dvi if (-f "$dvifile1.dvi") { $dvifile1 = "$ARGV[0]" . ".dvi" ; } else { print "ERROR. Cannot find file $dvifile1 or $dvifile1.dvi. Exiting.\n" ; exit 1 ; } } if (!(-f $dvifile2)) { # Maybe we need to append a .dvi if (-f "$dvifile2.dvi") { $dvifile2 = "$ARGV[1]" . ".dvi" ; } else { print "ERROR. Cannot find file $dvifile2 or $dvifile2.dvi. Exiting.\n" ; exit 1 ; } } # Check that these two files are in fact dvi files. if (is_dvii_file($dvifile1) < 0) { print "ERROR. $dvifile1 is not a valid .dvi file. Exiting.\n" ; exit 1 ; } if (is_dvii_file($dvifile2) < 0) { print "ERROR. $dvifile2 is not a valid .dvi file. Exiting.\n" ; exit 1 ; } my $mdfile1 = tempfilename() ; my $mdfile2 = tempfilename() ; # Set up to erase the files at end of script END { if (-e $mdfile1) { unlink($mdfile1) or die "Couldn't unlink $mdfile1 : $!" ; } if (-e $mdfile2) { unlink($mdfile2) or die "Couldn't unlink $mdfile2 : $!" ; } } # At this point we have two valid .dvi files. Compute their message digests. my ($cmd1, $cmd2, $cmd, $rv) ; $cmd1 = "$DVII -M1 $dvifile1 > $mdfile1" ; $cmd2 = "$DVII -M1 $dvifile2 > $mdfile2" ; $rv = `$cmd1` ; $rv = `$cmd2` ; # Do the diff $cmd = "$DIFF $mdfile1 $mdfile2" ; $rv = `$cmd` ; print "$rv\n" ; exit 0 ; ###################################################################### sub tempfilename { my ($tempfile_name) ; # Need both of these: use Fcntl; use POSIX qw(tmpnam); no strict 'subs' ; # Loop until we get a name that we can open. do { $tempfile_name = tmpnam() } until sysopen(TMPFH, $tempfile_name, O_RDWR|O_CREAT|O_EXCL); # Close the file handle. close(TMPFH) ; # Return the filename return $tempfile_name ; } sub is_dvii_file { my ($file, $rv) ; my $file = $_[0] ; $rv = `$DVII -C $file` ; if (!($rv =~ /passed/)) { return -1 ; } else { return 0 ; } }