This script uses tachyon's color coded diff code.
Tachyon's script was hilighting the lines that were differents between 2 files. This script hilights only the part of the line that is different from the line in the other file (just like emacs' compare 2 file does)
traverse_sequence is the only function i changed, that's why get and escape html functions are not re-printed here.
html output is netscape 4+ and ie4+ compliant
# stolen at http://www.perlmonks.org/index.pl?node_id=115928
# as well as the get and escapeHTML functions
# get options and file contents as array refs
my $old = get($old_file, 1, 1);
my $new = get($file, 1, 1);
open (SDIFF, "> $result_file") || &Error("Can't open $result_file:
+ $!");
# print out the colour coded diff - common code is black
# code in $old_file but not $new_file is (bg) red
# code in $new_file but not $old_file is (bg) green
print SDIFF "<div><table align=center bgcolor=white celpadding=0 c
+ellspacing=0><tr><th>Color Key:</th></tr>";
print SDIFF "<tr><td bgcolor=lightcoral>".escapeHTML($old_file)."<
+/td></tr>";
print SDIFF "<tr><td bgcolor=darkseagreen>".escapeHTML($file)."</t
+d></tr>\n";
print SDIFF "</table><br><table celpadding=0 cellspacing=0>";
my $a;
my $b;
my $a_lines;
my $b_lines;
traverse_sequences({
MATCH => sub
{
if ($a)
{
if ($b)
{
#$b_lines to compare with $a_lines
# print a_lines with hilited diffs
print SDIFF "<tr><td bgcolor=lightcoral>";
my @a_table=split(/ */, $a_lines);
my @b_table=split(/ */, $b_lines);
traverse_sequences(
{
MATCH => sub { print SDIFF escapeHTM
+L($a_table[$_[0]]) },
DISCARD_A => sub { print SDIFF "<span st
+yle=\"background-color:yellow\">" . escapeHTML($a_table[$_[0]])."</sp
+an>"},
DISCARD_B => sub { print SDIFF "" },
},
\@a_table, \@b_table,);
print SDIFF "</td></tr>";
# now print b_lines with hilited diffs
print SDIFF "<tr><td bgcolor=darkseagreen>";
traverse_sequences(
{
MATCH => sub { print SDIFF escapeHTM
+L($b_table[$_[1]]) },
DISCARD_A => sub { print SDIFF ""},
DISCARD_B => sub { print SDIFF "<span st
+yle=\"background-color:yellow\">" . escapeHTML($b_table[$_[1]])."</sp
+an>" },
},
\@a_table, \@b_table,);
print SDIFF "</td></tr>";
$b=0;
$b_lines="";
}
else
{
print SDIFF "<tr><td bgcolor=lightcoral>".escap
+eHTML($a_lines)."</td></tr>";
}
$a=0;
$a_lines="";
}
else
{
if ($b)
{
print SDIFF "<tr><td bgcolor=darkseagreen>".esc
+apeHTML($b_lines)."</td></tr>";
$b=0;
$b_lines="";
}
}
print SDIFF "<tr><td bgcolor=white>".escapeHTML($ol
+d->[$_[0]])."</td></tr>"
},
DISCARD_A => sub {
$a++;
$a_lines.=$old->[$_[0]];
},
DISCARD_B => sub {
$b++;
$b_lines.=$new->[$_[1]];
}}, $old, $new, );
print SDIFF "</table>\n";
close SDIFF;
last if $caught_sigint;
}