#! /bin/sh
#
# rdiff		--- merge of two files with diffs marked by > or <
#
# deleted fields are prefixed with "<" and new fields with a ">"
#
# Author: Oscar Nierstrasz 30/5/91

plus='> '
min='< '
u='Usage: rdiff [+=<string>] [-=<string>] <old> <new>'

for arg
do
	case $arg in
	+=* )	plus=`echo "$arg" | sed 's/^+=//'` ;;
	-=* )	min=`echo "$arg" | sed 's/^-=//'` ;;
	-* )	echo "$u" 1>&2 ; exit ;;
	* )	files="$files $arg" ;;
	esac
done

diff -Ddiff $files | awk '
	/^#ifdef/  { prefix = plus ; next }
	/^#ifndef/ { prefix = min ; next }
	/^#else/ {
		if (prefix == min)
			prefix = plus
		else	prefix = min
		next
		}
	/^#endif/  { prefix = "" ; next }
	{ printf "%s%s\n", prefix, $0 }' plus="${plus}" min="${min}"

exit

