Plan 9 from Bell Labs’s /usr/web/sources/contrib/boyd/sys/src/cmd/vidi

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


#!/bin/rc
#
#	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
#

if (! ~ $#* 1) {
	echo usage: `{basename $0} new-file >[1=2]
	exit usage
}

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

diff -e /tmp/vidi.$pid $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$pid

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

rm -f /tmp/vidi.*$pid

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to [email protected].