#!/bin/csh -f
#
#	test.csh - C-shell script to test out the parseargs command!
#
set NAME="`basename $0`"

setenv ARGUMENTS "\
  '?', ARGHIDDEN, argUsage, NULL,    'Help {print usage and exit}', \
  'S', ARGVALOPT, argStr,   string,  'STRing {optional string arg}', \
  'g', ARGLIST,   argStr,   groups,  'newsGROUPS {groups to test}', \
  'r', ARGOPT,    argInt,   count,   'REPcount {# to repeat each group}', \
  'd', ARGOPT,    argStr,   dirname, 'DIRectory {working directory}', \
  'x', ARGOPT,    argBool,  xflag,   'Xflag {turn on X-mode}', \
  'y', ARGOPT,    argUBool, yflag,   'Yflag {turn off Y-mode}', \
  's', ARGOPT,    argChar,  sepch,   'SEPchar {field separator}', \
  'f', ARGLIST,   argStr,   files,   'files {files to process}', \
  'n', ARGREQ|ARGPOS, argStr, name,  'name {name to use}', \
  ' ', ARGLIST,   argStr,   argv,    'argv {any remaining arguments}', \
  ENDOFARGS \
"
## set defaults ##
set groups='mygroup'   ## default group used by everyone
set count='1'          ## only do once unless otherwise specified
set dirname='.'        ## default to current directory
set xflag=''           ## default xflag is false
set yflag='TRUE'       ## default yflag is true
set sepch=','          ## default separator is a comma
set files=()

## parse command-line ##
parseargs -s csh -e ARGUMENTS -u -- "$NAME" $argv:q >/tmp/tmp$$
if ( $status != 0 ) then  ## improper syntax (or just wanted usage)
	rm -f /tmp/tmp$$
	exit 2
endif

## evaluate output from parseargs & remove temporary file
source /tmp/tmp$$
rm -f /tmp/tmp$$

## echo arguments ##
echo "ARGUMENTS:"
echo "=========="
echo Groups=$groups:q
echo Count=$count:q
echo Directory=$dirname:q
echo XFlag=$xflag:q
echo YFlag=$yflag:q
echo SepChar=$sepch:q
echo Name=$name:q
echo Files=$files:q
if ( $?string_flag ) then
  if ( ! $?string ) set string="\!string arg ommited on cmd-line\!"
else
  set string="default string"
endif
echo String=$string:q
echo New Positional Parameters=$argv:q

## print usage ##
parseargs -e ARGUMENTS -U "$NAME"
