#!/bin/sh
#	rcsdiffp - do an rcsdiff on this file and the previous
#			revision in RCS (as determined from the RCSid in
#			this file).

#  Henry Grebler     5 Jun 97  Don't assume format around Id:
#  Henry Grebler    14 Jun 96  If RCSid is absent, try rlog.
#  Henry Grebler     3 Jan 96  RCS munged the error message.
#  Henry Grebler     3 Jan 96  Use $Id: not RCS.
#  Henry Grebler     5 Nov 93  First cut.
########################################################################

#!!!!!		Warning		!!!!!

#	You cannot have <dollar>Id: <anything> <dollar> in the same line

	id_string='$Id:'
	method=id


try_head () {
	rev=`rlog -h $1 | sed -n 's/^head:[   ]*//p'`
	trev=`echo $rev | cut -f2 -d.`
	trev=`expr $trev - 1`
	prev=`echo $rev | cut -f1 -d.`.$trev
	method=rlog
}

calc_trev () {
	l=`echo -n $rev | wc -c`
	while true
	do
		m=`expr $l - 1`
		c=`echo $rev | cut -c$m`
		if [ "$c" = "." ]; then break; fi
		l=$m
	done

	trev=`echo $rev | cut -c$l-`
	trev=`expr $trev - 1`
	prev=`echo $rev | cut -c1-$m`$trev
			
}

	rev=`fgrep $id_string $1 | cut -f2 -d'$' | cut -f3 -d' '`
	if [ "$rev" = "" ]
	then
		echo RCSid not present in file $1
		echo Try from head
		try_head $1
	fi
	if [ "$rev" = "" ]
	then
		echo "Couldn't work out version numbers"
		exit 1
	fi

	if [ $method = id ]
	then
		calc_trev
	fi
	
	rcsdiff -r$prev $1
