#!/bin/tcsh

set args=""
while ($#argv)
 switch ($1)
  default:
   set args=($args $1);
   breaksw;
 endsw
 shift
end

if ($#args != 1) goto usage
if ("$args" == "") goto usage

set group   = $args[1]
set tagsets = tagsets/$group

if (! -e $tagsets) then
  echo "target $group not found in tagsets"
  exit 2
endif

foreach target (`cat $tagsets | grep -v \#`)
 set name = `echo $target | tr ':' ' '`
 set dir = $name[1]
 set tag = $name[2]

 set current = `pwd`
 cd ../$dir
 
 echo ""
 echo "***** updating $name ($target) *****"
 pwd

 switch ($tag)
  case HEAD:
   cvs -q up -d -A
   if ($status) goto failure;
   breaksw;
  case NONE:
   breaksw;
  default:
   cvs -q up -d -r $tag
   if ($status) goto failure;
   breaksw;
 endsw

 success:
 cd $current
end

exit 0

usage:
  echo "USAGE: psupdate (group)"
  exit 2

failure:
  echo "psupdate failed"
  echo "target: $target"
  echo "dir: $dir"
  echo "tag: $tag"
  exit 2
