2 # diffs two files and writes an HTML output file.
4 use CGI qw(:standard :html3);
5 use Algorithm::Diff 'traverse_sequences';
10 # Take care of whitespace.
15 @$arrayRef = expand(@$arrayRef);
18 # This will be called with both lines are the same
22 print pre( $a[$ia] ), "\n";
25 # This will be called when there is a line in A that isn't in B
29 print pre( { -class => 'onlyA' }, $a[$ia] ), "\n";
32 # This will be called when there is a line in B that isn't in A
36 print pre( { -class => 'onlyB' }, $b[$ib] ), "\n";
41 # Check for two arguments.
42 print "usage: $0 file1 file2 > diff.html\n" if @ARGV != 2;
44 $tabstop = 4; # For Text::Tabs
46 # Read each file into an array.
64 font-family: Courier, monospaced;
67 PRE.onlyA { color: red }
68 PRE.onlyB { color: blue }
71 # Print out the starting HTML
77 -title => "$ARGV[0] vs. $ARGV[1]",
78 -style => { -code => $style }
82 { -style => 'margin-left: 24pt' },
83 span( { -style => 'color: red' }, $ARGV[0] ),
85 span( { -style => 'color: blue' }, $ARGV[1] )
89 # And compare the arrays
92 \@b, # second sequence
94 MATCH => \&match, # callback on identical lines
95 DISCARD_A => \&only_a, # callback on A-only
96 DISCARD_B => \&only_b, # callback on B-only