#!/usr/local/bin/perl

# diff_faq v. 15 Nov 94 Dave Schweisguth <dcs@proton.chem.yale.edu>
# Produces a unidiff-like comparison of two files, ignoring deletions.
# Sections where differences are to be marked must begin with (at least) two
#   columns worth of whitespace.

($whatami = $0)	=~ s|.*/||;		# `basename $0`
die "$whatami: Specify two input files.\n" unless @ARGV == 2;
@diff = `diff -cw100000 @ARGV`;
if (($status = $? >> 8) == 2) {
    die "$whatami: diff exited unhappily.\n";
} elsif ($status == 0) {		# No differences; just cat $ARGV[1]
    open(NEW, $ARGV[1]) || die "$whatami: Couldn't open $ARGV[1]!?!\n";
    print <NEW>;
    close;
} else {				# Differences
    1 until shift(@diff) =~ /^--- \d+(,\d+)? ----/;
    foreach (@diff) {
	s/^([!+])   /$1 / ||	    # Diff line beginning with "  "
	s/^([!+]) \t/$1\t/ ||	    # Diff line beginning with \t
	s/^([!+])  \t/$1 \t/ ||	    # Diff line beginning with " \t"
	s/^[!+ ] //;		    # Something else; get rid of diff mark
	print;
    }
}
