#!/bin/csh -fe
#
#	gethighrev <version> <rcsfiles>
#
#	get the highest revision file for this version
#
set nonomatch

if ($#argv < 2) then
    echo "Usage: $0 <version> <rcsfiles>"
    exit 1
endif


set dcstring="0sm [lqsm]ss [dsqlm<sz0<r]sr z0<r lmp"
set maxlabel=()

rlog -h $2 | grep "^symbolic names:" | sed -n -e \
    "s/[^$1]*$1_\([0-9]*\)[^;]*;/\1 /gp" | sed -e \
    "s/ [^ ]*[^0-9 ][^ ]*//g" >/tmp/maxlabel$$
set maxlabel=($maxlabel `echo "$dcstring" | dc /tmp/maxlabel$$`)


rm -f /tmp/maxlabel$$
set maxlabel=`echo $maxlabel $dcstring | dc`

if ($maxlabel > 0) then
    foreach i ($argv[2-])
	echo "checkout last internal: $i"
	co -qV$1_$maxlabel $i
	if ($status) then
	    echo "ERROR! co -rV$1_$maxlabel $1 failed"
	    exit 1
	endif
    end
else
    echo "Can't find revision, has a 'make internal' been done?"
    exit 1
endif
