#!/bin/csh -f
#
# show_cadgroup_of: tries to find the cadgroup of the student given as argument.
#  Failure gives exit status 1, success returns the cadgroup found.
#
# usage: show_cadgroup_of <student>
#
set progname = `basename $0`
setenv CADLIB /vol/vlsi/local/lib
set path = ($path /vol/lab/bin) #for errecho!

if ($#argv != 1) then
  errecho "$progname : usage: $progname <student>"
  exit 1
endif

set student = $1
set cadgroups_to_try = `show_all_cadgroups`

foreach cadgroup ($cadgroups_to_try)
  if (`cat $CADLIB/$cadgroup/logins.real $CADLIB/$cadgroup/logins.fake | sed 's/#.*$//' | tr -s ' 	' '\012' | sort -u | grep -w $student` == "$student") then
    echo $cadgroup
    exit 0
  endif
end #foreach

errecho "$progname : student $student not in any cadgroup"
exit 1
