#!/bin/sh
#
#	Diff standard input against $1 and produce a context style
#	diff which can be edited by hand to include modifications.
#
#	Lines with:
#
#			+ are new
#			- reqire deletion
#			| should be replaced
#			? should be substituted
#

case $# in
1)
	;;

*)
	echo "usage: `basename $0` new-file" 1>&2
	exit 1
	;;
esac

trap 'rm /tmp/vidi.*$$' 0

sed '/^[-+|?.]/s/^/./' > /tmp/vidi.$$

diff -e /tmp/vidi.$$ "$1" | awk '
cmd == ""	{
			printf("%s", substr($1, 1, length($1) - 1))

			cmd = substr($1, length($1), 1)

			if (cmd == "d")
			{
				print "s/^/-/"
				cmd = ""
				next
			}
			
			if (cmd == "c")
			{
				print "s/^/?/"
				char = "|"
			}
			else
				char = "+"

			print "a"
			next
		}

$0 == "."	{
			cmd = ""
			print $0
			next
		}

		{
			print char $0
		}

END		{
			print "1,$p"
		}
' > /tmp/vidi.e$$

ed - /tmp/vidi.$$ < /tmp/vidi.e$$ 


© 1998, Boyd Roberts: boyd@fr.inter.net