#!/usr/bonsaitools/bin/perl # $Id: diff,v 1.1 1998/06/11 23:56:15 jwz Exp $ # diff -- Display diff output with markup. # # Arne Georg Gleditsch # Per Kristian Gjermshus # # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. ###################################################################### use lib 'lib/'; use SimpleParse; use LXR::Common; use LXR::Config; use DB_File; sub htmlsub { my ($s, $l) = @_; my @s = split(/(<[^>]*>|&[\#\w\d]+;?)/, $s); $s = ''; while (@s) { my $f = substr(shift(@s), 0, $l); $l -= length($f); $s .= $f; $f = shift(@s); if ($f =~ /^&/) { if ($l > 0) { $s .= $f; $l--; } } else { $s .= $f; } } $s .= ' ' x $l; return $s; } sub printdiff { unless ($diffvar) { foreach ($Conf->allvariables) { push(@vars, $Conf->vardescription($_)); } $vars[$#vars-1] .= " or ".pop(@vars) if $#vars > 0; print("

\n", "Please indicate the version of the file you wish to\n", "compare to by clicking on the appropriate\n", join(", ",@vars)," button.\n", "

\n"); return; } unless ($Path->{'file'}) { print("

Diff not yet supported for directories.

\n"); return; } $origvirt = $Path->{'virt'}.$Path->{'file'}; $origreal = $Path->{'real'}.$Path->{'file'}; $origval = $Conf->variable($diffvar); $Conf->variable($diffvar,$diffval); $diffvirt = $Conf->mappath($Path->{'virt'}).$Path->{'file'}; $diffreal = $Conf->sourceroot.$diffvirt; $Conf->variable($diffvar,$origval); # print("

Diff of $origvirt -> $diffvirt

\n"); # print("

($origreal -> $diffreal)

\n"); # FIXME: Check existence of $origreal & $diffreal. &fflush; unless (open(DIFF, "-|")){ open(STDERR, ">&STDOUT"); exec('diff', '-U0', $origreal, $diffreal); print "*** Diff subprocess died unexpextedly: $!\n"; exit; } while () { if (($os, $ol, $ns, $nl) = /@@ -(\d+)(?:,(\d+)|) \+(\d+)(?:,(\d+)|) @@/) { $os++ if $ol eq '0'; $ns++ if $nl eq '0'; $ol = 1 unless defined($ol); $nl = 1 unless defined($nl); $bo = $os + $ofs; if ($ol < $nl) { $ofs += $nl - $ol; $dir = '>>'; $ms = $nl - $ol; $ml = $ol; $orig{$os+$ol} = $ms; } else { $dir = '<<'; $ms = $ol - $nl; $ml = $nl; $new{$ns+$nl} = $ms; } foreach (0..$ml - 1) { $chg{$bo + $_} = '!!'; } foreach (0..$ms - 1) { $chg{$bo + $ml + $_} = $dir; } } } close(); print("

Diff markup

\n", "

Differences between ", &fileref("$origvirt (".$Conf->vardescription($diffvar). " $origval)", $origvirt, undef, "$diffvar=$origval"), " and ", &fileref("$diffvirt (".$Conf->vardescription($diffvar). " $diffval)",$diffvirt, undef, "$diffvar=$diffval"), "


\n"); # "\n\n\n
", # # &fileref("$origvirt (".$Conf->vardescription($diffvar). # " $origval)", $origvirt, undef, "$diffvar=$origval"), # "
", # # &fileref("$diffvirt (".$Conf->vardescription($diffvar). # " $diffval)",$diffvirt, undef, "$diffvar=$diffval"), # "
\n"); open(FOO, $origreal); $orig = ''; &markupfile(\*FOO, $Path->{'virt'}, $Path->{'file'}, sub { $orig .= shift }); $len = $.+$ofs; close(FOO); $Conf->variable($diffvar, $diffval); open(FOO, $diffreal); $new = ''; &markupfile(\*FOO, $Conf->mappath($Path->{'virt'}), $Path->{'file'}, sub { $new .= shift }); close(FOO); $Conf->variable($diffvar, $origval); $i = 1; $orig =~ s/^/"\n" x ($orig{$i++})/mge; $i = 1; $new =~ s/^/"\n" x ($new{$i++})/mge; @orig = split(/\n/, $orig); @new = split(/\n/, $new); print("
");
    foreach $i (0..$len) {
	$o = &htmlsub($orig[$i], 50);
#	$n = &htmlsub($new[$i], 999);
	$n = $new[$i];

#	print("$o".
#	      " ", $chg{$i+1}, " ".
#	      "$n\n");
	print("$o ", ($chg{$i+1} || "  "), " $n\n");
    }
    print("
"); # print(""); } ($Conf, $HTTP, $Path) = &init; $diffvar = $HTTP->{'param'}->{'diffvar'}; $diffval = $HTTP->{'param'}->{'diffval'}; &makeheader('diff'); &printdiff; &makefooter('diff');