#!/usr/bin/perl # # sbsdiff.pl # (c) Geoff Huston 2004 # # output HTML file of a side-by-side difference of two files # # sbsdiff.pl >output.html # # requires: sed, wdiff # generates temporary files in /tmp (/tmp/htmlsbs..) # $| = 1 ; $sed = "/usr/bin/sed" ; $wdiff = "/usr/local/bin/wdiff" print("Content-type: text/html\n\n") ; if ((!($file1 = shift)) || (!($file2 = shift))){ print("sbsdiff - error\n") ; print(""); print("

Usage: sbsdiff file1 file2

\n") ; exit ; } if (!(-e $file1)) { print("sbsdiff - error\n") ; print(""); print("

sbsdiff - file1 not found ($file1)

\n") ; exit ; } if (!(-e $file2)) { print("sbsdiff - error\n") ; print(""); print("

sbsdiff - file2 not found ($file2)

\n") ; exit ; } print("

$file1

\n"); print("

$file2

\n"); $f1 = $file1 ; $f2 = $file2 ; $a1 = "/tmp/htmlsbs.1.$$"; $a2 = "/tmp/htmlsbs.2.$$"; $a5 = "/tmp/htmlsbs.5.$$"; system("$sed -e 's/&/\\&/g' -e 's//\\>/g' $f1 > $a1") ; system("$sed -e 's/&/\\&/g' -e 's//\\>/g' $f2 > $a2") ; system("$wdiff -n -w \"\" -x \"\" -y \"\" -z \"\" $a2 $a1 >$a5"); $t1 = $f1 ; $t1 =~ s/^.*\/// ; $t2 = $f2 ; $t2 =~ s/^.*\/// ; print("\n\n"); print("\n\n") ; print("\n"); print("\n") ; print("sbsdiff $f1 $f2\n") ; print("\n\n\n"); print("\n"); print("\n"); $stacklines = 0; $color="0"; $scolor = 0 ; open(I,"$a5") ; while ($l = ) { chop($l); $pl = $l ; $pl =~ s//>/go; if ($color == 1) { $l = "$l"; } elsif ($color == 2) { $l = "$l"; } $scolor = $color ; $color = 0 ; $sl = $l ; $sl =~ s/\.*\<\/t.\>//go; if ($sl =~ //) { $color = 1 ; $l = "$l"; } elsif ($sl =~ //) { $color = 2 ; $l = "$l"; } $ol = $l; $ol =~ s///go; $ol =~ s/<\/t1>/<\/font><\/strong>/go; $ol =~ s///go; $ol =~ s/<\/t2>/<\/font><\/strike>/go; $ol = "$scolor " . $ol . " $color"; $l1 = $l2 = ""; if ($l) { $l1 = $l ; $l1 =~ s/\[^\<]*\<\/t2>//go; if ($l1) { $l1 =~ s///go; $l1 =~ s/<\/t1>/<\/span>/go; } $l2 = $l ; $l2 =~ s/\[^\<]*\<\/t1\>//go; if ($l2) { $l2 =~ s///go; $l2 =~ s/<\/t2>/<\/strike><\/span>/go; } } print("\n"); } print("\n"); print("
$t1 $t2
$l1 $l2


\n"); print("\n\n"); unlink($a1); unlink($a2); unlink($a5); exit ;