
# UNISRC_ID: @(#)diffmark.sh	27.2	85/03/10  

# Script to use diffmk to make a diff-marked comparison file.


# Initialize:

	PATH=/bin:/usr/bin:/usr/contrib/bin
	optchar="x"				# option letter, default none.
	default=76				# default line length.
	linelen=$default			# actual line length.
	mac=/tmp/dm.mac$$			# macro file.
	out=/tmp/dm.out$$			# diffmk output file.
	trap "rm -f $mac $out; exit" 0 1 2 3 15


# Check arguments:

	while [ `expr "x$1" : x-` -gt 1 ]	# arg1 starts with "-":
	do
		optlen=`expr length "$1" - 1`		# len of option part.
		option=`expr substr "$1" 2 $optlen`	# grab that part.
		shift

		if [ "$option" = c  -o  "$option" = m  -o  "$option" = t ]
		then
			optchar=$option
		else
			linelen=$option
		fi
	done

	if [ $# != 2 ]
	then
		echo "usage: $0 [-c|-m|-t] [-linelen] oldfile newfile"
		exit 1
	fi


# Build temporary macro file:

	if [ $optchar = c ]
	then					# a slew of stuff:
		cat >$mac <<-!
			.pl 1
			.ll ${linelen:-$default}
			.nf
			.eo
			.nc
		!
	elif [ $optchar = m ]
	then					# just source the macros:
		cat >$mac <<-!
			.so /usr/lib/macros/an
		!
	elif [ $optchar = t ]
	then					# leave off .eo and .nc:
		cat >$mac <<-!
			.pl 1
			.ll ${linelen:-$default}
			.nf
		!
	else					# create empty default:
		>$mac
	fi


# Do diffmk and nroff, then dump results:

	diffmk "$1" "$2" $out
	nroff $mac $out
