#!/usr/local/bin/perl $DIFF = "/usr/bin/diff"; $PERL = "/usr/bin/perl"; use CGI qw(:standard); use CGI::Carp; print header; print start_html("File Diff Example"); print "Version $CGI::VERSION
";
print <
\n";
print "File #2:",filefield(-name=>'file2',-size=>45),"
\n";
print "Diff type: ",radio_group(-name=>'type',
-value=>['context','normal']),"
\n";
print reset,submit(-name=>'submit',-value=>'Do Diff');
print endform;
# Process the form if there is a file name entered
$file1 = param('file1');
$file2 = param('file2');
$|=1; # for buffering
if ($file1 && $file2) {
$realfile1 = tmpFileName($file1);
$realfile2 = tmpFileName($file2);
print "
\n";
print "$file1 vs $file2
\n";
print "\n";
$options = "-c" if param('type') eq 'context';
system "$DIFF $options $realfile1 $realfile2 | $PERL -pe 's/>/>/g; s/</g;'";
close $file1;
close $file2;
print "
\n";
}
print <
Lincoln D. Stein
Last modified 17 July 1996
EOF
;
print end_html;
sub sanitize {
my $name = shift;
my($safe) = $name=~/([a-zA-Z0-9._~#,]+)/;
unless ($safe) {
print "$name is not a valid Unix filename -- sorry";
exit 0;
}
return $safe;
}