#sccs	"@(#)fndetc/convert:convbydiff	1.3"

#
#	FILE:  convbydiff
#
#	This program looks at the differences between the old and
#	new versions od a file.  Anything missing from the old
#	version is appended to the new version.
#

if [ $# -lt 2 ]
then
	echo "usage:  convbydiff {old file} {new file}"
	exit
fi

if [ $# -eq 3 ]
then	VERBOSE=$3
else	VERBOSE=""
fi

OLDFILE=$1
NEWFILE=$2

#	The old file and new file must be diff'ed.  Anything missing
#	from the old file is appended to the end of the new file.

diff $OLDFILE $NEWFILE | getmissing - > /tmp/missing

cp /tmp/missing /tmp/compare
while read LINE
do
	if [ -z "$LINE" ] ; then continue; fi
	if grep "$LINE" $NEWFILE > /dev/null
	then
		grep -v "$LINE" /tmp/missing > /tmp/lessline
		mv /tmp/lessline /tmp/missing
	fi
done < /tmp/compare

cat /tmp/missing >> $NEWFILE

#	Do listing update as necessary.

if [ "$VERBOSE" ]
then 
	echo "new Release file updated with:"
	cat /tmp/missing
	echo
fi

#	Clean up scratch files created.

rm -f /tmp/missing /tmp/compare

