home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume29 / parseargs / part02 / test.csh < prev    next >
Encoding:
Linux/UNIX/POSIX Shell Script  |  1992-05-19  |  2.0 KB  |  62 lines

  1. #!/bin/csh -f
  2. #
  3. #    test.csh - C-shell script to test out the parseargs command!
  4. #
  5. set NAME="`basename $0`"
  6.  
  7. setenv ARGUMENTS "\
  8.   '?', ARGHIDDEN, argUsage, NULL,    'Help {print usage and exit}', \
  9.   'S', ARGVALOPT, argStr,   string,  'STRing {optional string arg}', \
  10.   'g', ARGLIST,   argStr,   groups,  'newsGROUPS {groups to test}', \
  11.   'r', ARGOPT,    argInt,   count,   'REPcount {# to repeat each group}', \
  12.   'd', ARGOPT,    argStr,   dirname, 'DIRectory {working directory}', \
  13.   'x', ARGOPT,    argBool,  xflag,   'Xflag {turn on X-mode}', \
  14.   'y', ARGOPT,    argUBool, yflag,   'Yflag {turn off Y-mode}', \
  15.   's', ARGOPT,    argChar,  sepch,   'SEPchar {field separator}', \
  16.   'f', ARGLIST,   argStr,   files,   'files {files to process}', \
  17.   'n', ARGREQ|ARGPOS, argStr, name,  'name {name to use}', \
  18.   ' ', ARGLIST,   argStr,   argv,    'argv {any remaining arguments}', \
  19.   ENDOFARGS \
  20. "
  21. ## set defaults ##
  22. set groups='mygroup'   ## default group used by everyone
  23. set count='1'          ## only do once unless otherwise specified
  24. set dirname='.'        ## default to current directory
  25. set xflag=''           ## default xflag is false
  26. set yflag='TRUE'       ## default yflag is true
  27. set sepch=','          ## default separator is a comma
  28. set files=()
  29.  
  30. ## parse command-line ##
  31. parseargs -s csh -e ARGUMENTS -u -- "$NAME" $argv:q > /tmp/tmp$$
  32. if ( $status != 0 ) then  ## improper syntax (or just wanted usage)
  33.     rm -f /tmp/tmp$$
  34.     exit 2
  35. endif
  36.  
  37. ## evaluate output from parseargs & remove temporary file
  38. source /tmp/tmp$$
  39. rm -f /tmp/tmp$$
  40.  
  41. ## echo arguments ##
  42. echo "ARGUMENTS:"
  43. echo "=========="
  44. echo Groups=$groups:q
  45. echo Count=$count:q
  46. echo Directory=$dirname:q
  47. echo XFlag=$xflag:q
  48. echo YFlag=$yflag:q
  49. echo SepChar=$sepch:q
  50. echo Name=$name:q
  51. echo Files=$files:q
  52. if ( $?string_flag ) then
  53.   if ( ! $?string ) set string="\!string arg ommited on cmd-line\!"
  54. else
  55.   set string="default string"
  56. endif
  57. echo String=$string:q
  58. echo New Positional Parameters=$argv:q
  59.  
  60. ## print usage ##
  61. parseargs -e ARGUMENTS -U "$NAME"
  62.