#!/bin/csh -f
#
#	resetrev <destdir> <version> <revfile> <subdirlist> <rcsfiles>
#
#	find the highest revision for this version
#
set nonomatch

if ($#argv < 5) then
    echo "Usage: $0 <destdir> <version> <revfile> <subdirlist> <rcsfiles>"
    exit 1
endif

if (! -d $1) then
    echo "Error: <destdir> $1 does not exist"
    exit 1
endif

set sourcedir=$cwd
cd $1
set dcstring="0sm [lqsm]ss [dsqlm<sz0<r]sr z0<r lmp"
if (-e $3) then
    set maxlabel=(`cat $3`)
else
    set maxlabel=()
endif
set subdirs=($4)
if ($#subdirs != 0) then
    foreach i ($subdirs)
	if (-e $i/${i}_rev.rev) then
	    set maxlabel=($maxlabel `cat $i/${i}_rev.rev`)
	endif
    end
endif
foreach i ($argv[5-])
    if ((-e RCS/$i,v) || (-e $i,v)) then
	rlog -h $i | grep "^symbolic names:" | sed -n -e \
	    "s/[^$2]*$2_\([0-9]*\)[^;]*;/\1 /gp" | sed -e \
	    "s/ [^ ]*[^0-9 ][^ ]*//g" >/tmp/maxlabel$$
	set maxlabel=($maxlabel `echo "$dcstring" | dc /tmp/maxlabel$$`)
    endif
end
rm -f /tmp/maxlabel$$
set maxlabel=`echo $maxlabel $dcstring | dc`
cd $sourcedir
if ($maxlabel > 0) then
    @ maxlabel = $maxlabel - 1
    echo $maxlabel >$3
    chmod 666 $3
    echo $3 set to $maxlabel
    set include=$3:r
    if (-e $include.i) then
	rm -f $include.i
	echo rm $include.i
    endif
    if (-e $include.h) then
	rm -f $include.h
	echo rm $include.h
    endif
else
    echo $3 not set
endif
