From 661c41a09e39a182865e0b51e34cc995a0dc96e8 Mon Sep 17 00:00:00 2001 From: Norbert Preining Date: Wed, 12 May 2010 16:54:37 +0000 Subject: move tlperl.straw to tlperl git-svn-id: svn://tug.org/texlive/trunk@18210 c570f23f-e606-0410-a88d-b1316a301751 --- Master/tlpkg/tlperl/lib/Algorithm/htmldiff.pl | 100 ++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100755 Master/tlpkg/tlperl/lib/Algorithm/htmldiff.pl (limited to 'Master/tlpkg/tlperl/lib/Algorithm/htmldiff.pl') diff --git a/Master/tlpkg/tlperl/lib/Algorithm/htmldiff.pl b/Master/tlpkg/tlperl/lib/Algorithm/htmldiff.pl new file mode 100755 index 00000000000..fdc81021582 --- /dev/null +++ b/Master/tlpkg/tlperl/lib/Algorithm/htmldiff.pl @@ -0,0 +1,100 @@ +#!/usr/bin/perl -w +# diffs two files and writes an HTML output file. +use strict; +use CGI qw(:standard :html3); +use Algorithm::Diff 'traverse_sequences'; +use Text::Tabs; + +my ( @a, @b ); + +# Take care of whitespace. +sub preprocess +{ + my $arrayRef = shift; + chomp(@$arrayRef); + @$arrayRef = expand(@$arrayRef); +} + +# This will be called with both lines are the same +sub match +{ + my ( $ia, $ib ) = @_; + print pre( $a[$ia] ), "\n"; +} + +# This will be called when there is a line in A that isn't in B +sub only_a +{ + my ( $ia, $ib ) = @_; + print pre( { -class => 'onlyA' }, $a[$ia] ), "\n"; +} + +# This will be called when there is a line in B that isn't in A +sub only_b +{ + my ( $ia, $ib ) = @_; + print pre( { -class => 'onlyB' }, $b[$ib] ), "\n"; +} + +# MAIN PROGRAM + +# Check for two arguments. +print "usage: $0 file1 file2 > diff.html\n" if @ARGV != 2; + +$tabstop = 4; # For Text::Tabs + +# Read each file into an array. +open FH, $ARGV[0]; +@a = ; +close FH; + +open FH, $ARGV[1]; +@b = ; +close FH; + +# Expand whitespace +preprocess( \@a ); +preprocess( \@b ); + +# inline style +my $style = < "$ARGV[0] vs. $ARGV[1]", + -style => { -code => $style } + } + ), + h1( + { -style => 'margin-left: 24pt' }, + span( { -style => 'color: red' }, $ARGV[0] ), + span(" vs. "), + span( { -style => 'color: blue' }, $ARGV[1] ) + ), + "\n"; + +# And compare the arrays +traverse_sequences( + \@a, # first sequence + \@b, # second sequence + { + MATCH => \&match, # callback on identical lines + DISCARD_A => \&only_a, # callback on A-only + DISCARD_B => \&only_b, # callback on B-only + } +); + +print end_html(); -- cgit v1.2.3