home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 3 / 3402 < prev    next >
Encoding:
Internet Message Format  |  1991-05-23  |  6.6 KB

  1. From: brad@SSD.CSD.HARRIS.COM (Brad Appleton)
  2. Newsgroups: alt.sources
  3. Subject: Re: yet Another test AND a PD getopt
  4. Message-ID: <3454@travis.csd.harris.com>
  5. Date: 22 May 91 14:22:29 GMT
  6.  
  7. In article <1074@isgtec.UUCP> robert@isgtec.UUCP writes:
  8. >In article <remus@paul.alpha.edu>, denv@nywu writes:
  9. >|> this is just a test.
  10. >
  11. >Why is this in alt.sources?  It was crossposted to alt.test, so obviously
  12. >it's more than just the fact that you're a moron.  Why post a test
  13. >why not post some sources?
  14. >
  15. >Rob.
  16. >
  17. >OB. Source
  18. >
  19. >Here is a getopt I wrote (now PD) because Turbo C doesn't have one!
  20. >(Maybe they'll put this one into their libraries now :-)
  21. >
  22. First of all - AT&T already put getopt into the Public domain. Second,
  23. getopt is a piece of crap. DOWN WITH GETOPT! There is much better stuff
  24. available. Take Parseargs for example (which I released). For any 
  25. interested parties, the following is a brief description of Parseargs.
  26. You can get the latest version from me, or you can look in your local
  27. comp.sources.misc archives for the sources and latest patches (patch05).
  28.  
  29. ______________________ "And miles to go before I sleep." ______________________
  30.  Brad Appleton           brad@ssd.csd.harris.com       Harris Computer Systems
  31.                              uunet!hcx1!brad           Fort Lauderdale, FL USA
  32. ~~~~~~~~~~~~~~~~~~~~ Disclaimer: I said it, not my company! ~~~~~~~~~~~~~~~~~~~
  33.  
  34.  
  35.                                   PARSEARGS
  36.  
  37.                         extracted from Eric Allman's
  38.  
  39.                             NIFTY UTILITY LIBRARY
  40.  
  41.                           Created by Eric P. Allman
  42.                              <eric@Berkeley.EDU>
  43.  
  44.                          Modified by Peter da Silva
  45.                             <peter@Ferranti.COM>
  46.  
  47.                    Modified and Rewritten by Brad Appleton
  48.                           <brad@SSD.CSD.Harris.COM>
  49.  
  50.  
  51.  Welcome to parseargs! Dont let the initial size of this package scare you.
  52.  over 75% of it is English text, and more than 50% of the source is comments.
  53.  
  54.  Parseargs is a set of functions to parse command-line arguments. Unlike
  55.  getopt and its variants, parseargs does more than just split up the
  56.  command-line into some canonical form. Parseargs will actually parse the
  57.  command-line, assigning the appropriate command-line values to the
  58.  corresponding variables, and will verify the command-line syntax (and print
  59.  a usage message if necessary). Furthermore, many features of it's parsing
  60.  behavior are configurable at run-time. Some of these features include the
  61.  following:
  62.  
  63.      o  Prompting the user for missing arguments
  64.      o  Allowing keywords (+count=4) and/or options (-c4)
  65.      o  Checking for default arguments in an environment variable
  66.      o  Ignoring bad syntax instead of terminating
  67.      o  Ignoring upper/lower case on the command-line
  68.      o  Controlling the location of non-positional parameters
  69.      o  Controlling the contents (syntax and verbosity) of usage messages
  70.      o  Having long usage messages piped through a paging program
  71.  
  72.  Parseargs also allows for options that take an optional argument, and
  73.  options that take a (possibly optional) list of one or more arguments.
  74.  In addition, parseargs may be configured at compile-time to parse
  75.  command-lines in accordance with the native command-syntax of any of the
  76.  following operating systems:
  77.  
  78.      o  Unix
  79.      o  VAX/VMS
  80.      o  OS/2
  81.      o  MS-DOS
  82.      o  AmigaDOS
  83.  
  84.  Parseargs consists of a set of C-functions to parse arguments from the
  85.  command-line, from files, from strings, from linked-lists, and from
  86.  string-vectors. Also included is a command-line interface which will parse
  87.  arguments for shell scripts (sh, csh/tcsh/itcsh, ksh, bash, zsh, and rc),
  88.  awk-scripts, and perl-scripts.
  89.  
  90.  The basic structure used by parseargs is the argument-descriptor (sometimes
  91.  called "argdesc" for brevity).  An array/string of argdescs is declared by
  92.  the user to describe the command in question.  The resulting argdesc-array
  93.  is passed to all the parseargs functions and is used to hold all information
  94.  about the command. a sample argdesc-array is shown below.
  95.  
  96.     STARTOFARGS,
  97.     { 'a', ARGVALOPT, argStr,   &area,    "AREAcode : optional area-code" },
  98.     { 'g', ARGLIST,   argStr,   &groups,  "newsGROUPS : groups to test" },
  99.     { 'r', ARGOPT,    argInt,   &count,   "REPcount : repetition factor" },
  100.     { 's', ARGOPT,    argChar,  &sepch,   "SEPchar : field separator" },
  101.     { 'x', ARGOPT,    argBool,  &xflag,   "Xflag : turn on X-mode" },
  102.     { ' ', ARGREQ,    argStr,   &name,    "name : name to use" },
  103.     { ' ', ARGLIST,   argStr,   &args,    "args : any remaining arguments" },
  104.     ENDOFARGS
  105.  
  106.  Once the above array/string is declared it is a simple matter to invoke
  107.  parseargs from C as in the following example:
  108.  
  109.     status = parseargs( argdesc_array, argv );
  110.  
  111.  or from a shell script as in the following example:
  112.  
  113.     echo "$ARGDESC_STR" | parseargs -s sh -- "$0" "$@" >tmp$$
  114.     test  $? = 0  &&  . tmp$$
  115.     /bin/rm -f tmp$$
  116.  
  117.  And before you know it, your command-line had been parsed, all variables 
  118.  have been assigned their corresponding values from the command-line, syntax
  119.  has been verified, and a usage message (if required) has been printed. 
  120.  
  121.  Under UNIX, the command-line syntax (using single character options) for the
  122.  above command would be:
  123.  
  124.     cmdname [-a [<areacode>]] [-g <newsgroups>...] [-r <repcount>]
  125.             [-s <sepchar>] [-x]  <name>  [<args>...]
  126.  
  127.  The UNIX command-line syntax using keywords (or long options) would be:
  128.  
  129.     cmdname [+area [<areacode>]] [+groups <newsgroups>...] [+rep <repcount>]
  130.             [+sep <sepchar>] [+x]  <name>  [<args>...]
  131.  
  132.  The VMS command-line syntax would be the following:
  133.  
  134.     cmdname [/AREA[=<areacode>]] [/GROUPS=<newsgroups>[,<newsgroups>...]
  135.             [/REP=<repcount>] [/SEP=<sepchar>] [/X]  <name>
  136.             [<args>[,<args>...]]
  137.  
  138.  The MS-DOS and OS/2 command-line syntax would be the following (unless the
  139.  environment variable $SWITCHAR is '-' in which case UNIX syntax is used):
  140.  
  141.     cmdname [/a[=<areacode>]] [/g=<newsgroups>...] [/r=<repcount>]
  142.             [/s=<sepchar>] [/x]  <name>  [<args>...]
  143.  
  144.   The AmigaDOS command-line syntax would be the following:
  145.  
  146.     cmdname [AREA [<areacode>]] [GROUPS <newsgroups>...] [REP <repcount>]
  147.             [SEP <sepchar>] [X]  <name>  [<args>...]
  148.  
  149.  
  150.  Please look at the README files and manpages for more detailed information!
  151. ______________________ "And miles to go before I sleep." ______________________
  152.  Brad Appleton           brad@ssd.csd.harris.com       Harris Computer Systems
  153.                              uunet!hcx1!brad           Fort Lauderdale, FL USA
  154. ~~~~~~~~~~~~~~~~~~~~ Disclaimer: I said it, not my company! ~~~~~~~~~~~~~~~~~~~
  155.