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

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


<html>
<body>
<pre>
<tt>
#!/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&gt;&amp;2
	exit 1
	;;
esac

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

sed '/^[-+|?.]/s/^/./' &gt; /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"
		}
' &gt; /tmp/vidi.e$$

ed - /tmp/vidi.$$ &lt; /tmp/vidi.e$$ 
</tt>
</pre>
<HR>
&copy 1998,
Boyd Roberts:
<A HREF="mailto:[email protected]">[email protected]</A>
</body>
</html>

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].