#!/bin/rc
#	test.rc - rc shell script to test out the parseargs command!
#
NAME=`{basename $0}

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 : any remaining arguments",
  ENDOFARGS
'

yflag='TRUE'     ## set defaults (dir="."; count=1; sepch=',') ##

## parse command-line and save assignments in a temporary file ##
parseargs -s rc -e ARGUMENTS -u -- $^NAME "$@" >/tmp/tmp$$
if ( $status != 0 ) {
  rm -f /tmp/tmp$$;
  exit 2  ## non-zero status (usage given)
}

## evaluate results from parseargs and remove temporary file
. /tmp/tmp$$;  rm -f /tmp/tmp$$

## echo  the parsed arguments (use defaults if not defined)
echo 'ARGUMENTS:'
echo '=========='
echo Name="$name", Count=${count:-1}
echo XFlag="$xflag", YFlag="$yflag"
echo Directory="${dirname:-'.'}", SepChar="${sepch:-','}"
echo Groups="$groups"
echo Files="$files"
if ( $^string_flag )
  string=${string:-'!string arg ommitted on cmd-line!'}
else
  string='default string'
echo String="$string"
echo New Positional Parameters="$^*"

parseargs -a $^ARGUMENTS -U $^NAME     ## print usage ##
