home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume29 / parseargs / part01 / test.rc < prev    next >
Encoding:
Plan 9 rc shell script  |  1992-05-19  |  1.8 KB  |  52 lines

  1. #!/bin/rc
  2. #    test.rc - rc shell script to test out the parseargs command!
  3. #
  4. #   NOTE: This script tests Byron Rakitzis' version of rc. NOT the
  5. #         Plan 9 version (there are a few differences such as the use
  6. #         of "else" instead of "if not" and the use of "$^variable").
  7. #
  8. NAME=`{basename $0}
  9.  
  10. ARGUMENTS='
  11.   "?", ARGHIDDEN, argUsage, NULL,    "Help : print usage and exit",
  12.   "S", ARGVALOPT, argStr,   string,  "STRing : optional string arg",
  13.   "g", ARGLIST,   argStr,   groups,  "newsGROUPS : groups to test",
  14.   "r", ARGOPT,    argInt,   count,   "REPcount <# to repeat each group>",
  15.   "d", ARGOPT,    argStr,   dirname, "DIRectory : working directory",
  16.   "x", ARGOPT,    argBool,  xflag,   "Xflag : turn on X-mode",
  17.   "y", ARGOPT,    argUBool, yflag,   "Yflag : turn off Y-mode",
  18.   "s", ARGOPT,    argChar,  sepch,   "SEPchar : field separator",
  19.   "f", ARGLIST,   argStr,   files,   "files : files to process",
  20.   "n", ARGREQ|ARGPOS, argStr, name,  "name : name to use",
  21.   " ", ARGLIST,   argStr,   argv,      "argv : any remaining arguments",
  22.   ENDOFARGS
  23. '
  24.  
  25. yflag='TRUE'     ## set defaults (dir="."; count=1; sepch=',') ##
  26. count=1
  27. sepch=','
  28.  
  29. ## parse command-line and save assignments in a temporary file ##
  30. if ( parseargs -s rc -e ARGUMENTS -u -- $^NAME $* >/tmp/tmp$pid ) {
  31.    ## evaluate results from parseargs and remove temporary file
  32.    . /tmp/tmp$pid;  rm -f /tmp/tmp$pid
  33. } else {
  34.   rm -f /tmp/tmp$pid;
  35.   exit 2  ## non-zero status (usage given)
  36. }
  37.  
  38.  
  39. ## echo  the parsed arguments (use defaults if not defined)
  40. echo 'ARGUMENTS:'
  41. echo '=========='
  42. echo 'Name='"$name", 'Count='$count
  43. echo 'XFlag='"$xflag", 'YFlag='"$yflag"
  44. echo 'Directory='"$dirname", 'SepChar='"$sepch"
  45. echo 'Groups='"$groups"
  46. echo 'Files='"$files"
  47. echo 'string_flag='$^string_flag
  48. echo 'String='"$string"
  49. echo 'argv=' "$argv"
  50.  
  51. parseargs -a $^ARGUMENTS -U $^NAME     ## print usage ##
  52.