#! /bin/sh

# $Copyright:	$
# Copyright (c) 1984, 1985, 1986, 1987, 1988, 1989, 1990 
# Sequent Computer Systems, Inc.   All rights reserved.
#  
# This software is furnished under a license and may be used
# only in accordance with the terms of that license and with the
# inclusion of the above copyright notice.   This software may not
# be provided or otherwise made available to, or used by, any
# other person.  No title to or ownership of the software is
# hereby transferred.

#	Copyright (c) 1984 AT&T
#	  All Rights Reserved

#	THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T
#	The copyright notice above does not evidence any
#	actual or intended publication of such source code.

#ident	"$Header: diffmk.sh 1.4 89/10/10 $@(#)diffmk:diffmk.sh	1.9"
#		Copyright (c) 1984 AT&T
#		  All Rights Reserved
#     THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T
#   The copyright notice above does not evidence any actual
#   or intended publication of such source code.
trap 'rm -f /tmp/d$$; exit' 1 2 3 15
if [ $? != 0 ] || test -z "$3" -o "$3" = "$1" -o "$3" = "$2"; then
	echo "usage: diffmk name1 name2 name3 -- name3 must be different" >&2
	exit 2
fi
if test "$3" = "-" -o "$1" = "-" -a "$2" = "-"; then
	echo "usage: diffmk name1 name2 name3 -- name3 must be different" >&2
	exit 2
fi
if test "$1" != "-" && test ! -r "$1"; then
	echo "diffmk: $1 can not be read" >&2
	exit 2
fi
if test "$2" != "-" && test ! -r "$2"; then
	echo "diffmk: $2 can not be read" >&2
	exit 2
fi
if test "$1" = "-"; then
	file1=/tmp/d$$
	cat - >$file1
else
	file1=$1
fi
diff -e $file1 $2 | (sed -n -e '
/[ac]$/{
	p
	a\
.mc \\(br
: loop
	n
	/^\.$/b done1
	p
	b loop
: done1
	a\
.mc\
.
	b
}

/d$/{
	s/d/c/p
	a\
.mc \\(**\
.mc\
.
	b
}'; echo '1,$p') | ed - $file1| sed -e '
/^\.TS/,/.*\. *$/b pos
/^\.T&/,/.*\. *$/b pos
p
d
:pos
/^\.mc/d
' > $3
if test "$1" = "-"; then
	rm -f /tmp/d$$
fi
