#!/usr/bin/perl
#
# Copyright (c) 2001,2002 Florent Villard (warly@laposte.net)
# Published under the GPL license.
#

use strict;
my $version = "0.0.1";
@ARGV == 2 or usage();

foreach my $t (2,1){
    open my $DIFF, "wdiff -w [ -x ] -y [ -z ] -n -$t $ARGV[0] $ARGV[1]|";
    
    while (<$DIFF>){
	print if $t == 2;
	/<body/ and last;
    }
    while (<$DIFF>){
	s/<div id="d1">/<div id="c$t">/;
	s/<div id="d2">/<div id="e$t">/;
	/<\/body>/ and last;
	s/\[<p\]/<p/g;

#	s/\[\-(.*)<\/p>\-\]/[-$1-]/g;

	s/<p([^>]*)\[([^>]*)(?:>|(\]$))/<p$1$2>[$3/g;

	s/\[\-([^<>]*)>/[/g;

	s/<p([^>]*)\[([^>]*)>/<p$1$2>[/g;

	s/\[<p([^>]*)>/<p$1>[/g;

	s/<\/p>\]/]<\/p>/g;

	s/\[((?!\])*)\]/<b>$1<\/b>/g;

	s/\[((?!\])*)/<b>$1/g;
	s/((?!\])*)\]/<\/b>$1/g;
	print
    }
}
print qq{</div></body>};

exit;

sub usage {
    print "viewdiff version $version
    
    usage:
    
	viewdiff <vie.xml file 1> <vie.xml file 2>\n\n";
    exit
}
