Commit | Line | Data |
54310121 |
1 | #!/usr/local/bin/perl |
2 | |
3 | $DIFF = "/usr/bin/diff"; |
4 | $PERL = "/usr/bin/perl"; |
5 | |
6 | use CGI qw(:standard); |
7 | use CGI::Carp; |
8 | |
9 | print header; |
10 | print start_html("File Diff Example"); |
11 | print "<strong>Version </strong>$CGI::VERSION<p>"; |
12 | |
13 | print <<EOF; |
14 | <H1>File Diff Example</H1> |
15 | Enter two files. When you press "submit" their diff will be |
16 | produced. |
17 | EOF |
18 | ; |
19 | |
20 | # Start a multipart form. |
21 | print start_multipart_form; |
22 | print "File #1:",filefield(-name=>'file1',-size=>45),"<BR>\n"; |
23 | print "File #2:",filefield(-name=>'file2',-size=>45),"<BR>\n"; |
24 | print "Diff type: ",radio_group(-name=>'type', |
25 | -value=>['context','normal']),"<br>\n"; |
26 | print reset,submit(-name=>'submit',-value=>'Do Diff'); |
27 | print endform; |
28 | |
29 | # Process the form if there is a file name entered |
30 | $file1 = param('file1'); |
31 | $file2 = param('file2'); |
32 | |
33 | $|=1; # for buffering |
34 | if ($file1 && $file2) { |
35 | $realfile1 = tmpFileName($file1); |
36 | $realfile2 = tmpFileName($file2); |
37 | print "<HR>\n"; |
38 | print "<H2>$file1 vs $file2</H2>\n"; |
39 | |
40 | print "<PRE>\n"; |
41 | $options = "-c" if param('type') eq 'context'; |
42 | system "$DIFF $options $realfile1 $realfile2 | $PERL -pe 's/>/>/g; s/</</g;'"; |
43 | close $file1; |
44 | close $file2; |
45 | print "</PRE>\n"; |
46 | } |
47 | |
48 | print <<EOF; |
49 | <HR> |
50 | <A HREF="../cgi_docs.html">CGI documentation</A> |
51 | <HR> |
52 | <ADDRESS> |
53 | <A HREF="/~lstein">Lincoln D. Stein</A> |
54 | </ADDRESS><BR> |
55 | Last modified 17 July 1996 |
56 | EOF |
57 | ; |
58 | print end_html; |
59 | |
60 | sub sanitize { |
61 | my $name = shift; |
62 | my($safe) = $name=~/([a-zA-Z0-9._~#,]+)/; |
63 | unless ($safe) { |
64 | print "<strong>$name is not a valid Unix filename -- sorry</strong>"; |
65 | exit 0; |
66 | } |
67 | return $safe; |
68 | } |