
#	$Id: gnu-merge.sh,v 1.1 90/01/10 16:28:55 trinkle Exp $

PATH=/bin:/usr/bin
DIFF=/usr/local/gnu/diff
DIFF3=/usr/local/gnu/diff3
p=w
case $1 in
-p)
	p='1,$p'
	shift
esac

case $# in
0|1|2)
	echo >&2 "merge: usage: merge [-p] file1 file2 file3"
	exit 1
esac

case $p in
w)
	if test ! -w $1
	then
		echo >&2 "$1 not writeable"
		exit 1
	fi
esac

trap 's=$?; rm -f /tmp/d3a$$ /tmp/d3b$$; exit $s' 0
trap exit 1 2 3 13 15
umask 077

{
	$DIFF3 -E $1 $2 $3
	case $? in
	0) ;;
	1) echo >&2 merge: warning: there were overlaps during merge.;;
	esac
	if test -n "$5"
	then
		echo 'g;^>>>>>>> '$3'$;s;;>>>>>>> '$5';'
	fi
	echo $p
} | ed - $1
