home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume19 / parseargs / patch05d < prev    next >
Text File  |  1991-05-17  |  57KB  |  1,753 lines

  1. Newsgroups: comp.sources.misc
  2. From: Brad Appleton <brad@hcx1.ssd.csd.harris.com>
  3. Subject:  v19i085:  parseargs - functions to parse command line argument, Patch05d/5
  4. Message-ID: <1991May17.181729.22411@sparky.IMD.Sterling.COM>
  5. X-Md4-Signature: 1970d4735e92701e5f225a33c7262b15
  6. Date: Fri, 17 May 1991 18:17:29 GMT
  7. Approved: kent@sparky.imd.sterling.com
  8.  
  9. Submitted-by: Brad Appleton <brad@hcx1.ssd.csd.harris.com>
  10. Posting-number: Volume 19, Issue 85
  11. Archive-name: parseargs/patch05d
  12. Patch-To: parseargs: Volume 17, Issue 45-57
  13.  
  14. #!/bin/sh
  15. # do not concatenate these parts, unpack them in order with /bin/sh
  16. # file PATCH05 continued
  17. #
  18. if test ! -r _shar_seq_.tmp; then
  19.     echo 'Please unpack part 1 first!'
  20.     exit 1
  21. fi
  22. (read Scheck
  23.  if test "$Scheck" != 4; then
  24.     echo Please unpack part "$Scheck" next!
  25.     exit 1
  26.  else
  27.     exit 0
  28.  fi
  29. ) < _shar_seq_.tmp || exit 1
  30. if test ! -f _shar_wnt_.tmp; then
  31.     echo 'x - still skipping PATCH05'
  32. else
  33. echo 'x - continuing file PATCH05'
  34. sed 's/^X//' << 'SHAR_EOF' >> 'PATCH05' &&
  35. -      ``verbose'' mode, which controls whether or not a detailed
  36. -      description of each argument should accompany the usual
  37. -      command-line sysnopsis. If    verbose    mode is    ``off'', then
  38. -      only a command-line synopsis is printed (this is also
  39. -      refferred to as ``terse'' mode). The other    two ``modes''
  40. -      control the displaying of option syntax and long-option
  41. - Page 10
  42. - PARSEARGS(1)                         PARSEARGS(1)
  43. -      syntax. A mode may    be explicitly disabled by preceding its
  44. -      corresponding string with the `!'    or `-' character. The
  45. -      ``modes'' which correspond    to the possible    values of the
  46. -      ``USAGECNTL'' environment variable    are given by the
  47. -      following table.
  48. -      Quiet
  49. -       No usage message of any kind is displayed.
  50. -      Silent
  51. -       Same as Quiet.
  52. -      Paged
  53. -       The usage message is piped to    a pager. The pager used
  54. -       is named by the ``USAGE_PAGER'' environment variable.
  55. -       If this variable is unset or empty (or is not    the name
  56. -       of an    executable program) then the pager named by the
  57. -       ``PAGER'' environment    variable us used.  If this
  58. -       variable is unset or empty (or is not    the name of an
  59. -       executable program) then /usr/ucb/more is used.
  60. -      Description
  61. -       The command description is printed.
  62. -      Terse
  63. -       Terse    mode, just print command-line synopsis.
  64. -      Verbose
  65. -       Verbose mode,    print descriptions for each argument
  66. -      Options
  67. -       Option syntax    is displayed.
  68. -      LongOpts
  69. -       Long-option syntax is    displayed.
  70. -      KeyWords
  71. -       Same as LongOpts.
  72. -      If    the environment    variable ``USAGECNTL'' is empty    or
  73. -      undefined,    then the default usage level (which is presently
  74. -      ``Verbose + Options'') will be used.
  75. - EXAMPLES
  76. -      As    a first    example, consider the following    argument
  77. -      specification for a Bourne    shell script:
  78. -      #!/bin/sh
  79. -      RepCount=2;
  80. -      Verbose="";
  81. - Page 11
  82. - PARSEARGS(1)                         PARSEARGS(1)
  83. -      ARGSPEC="
  84. -      'c', ARGOPT,          argInt,  RepCount, 'count    {# times to repeat}',
  85. -      'v', ARGOPT,          argBool, Verbose,     'verbose {turn    on verbose mode}',
  86. -      ' ', ARGREQ,          argStr,  InFile,     'input    {file to read from}',
  87. -      ' ', ARGOPT,          argStr,  OutFile,     'output {file to write    to}',
  88. -      'X', ARGHIDDEN,      argBool, XRated,     'xrated {naughty! naughty!}',
  89. -      ' ', ARGOPT|ARGLIST, listStr, Files,     'files    {files to process}',
  90. -      ENDOFARGS
  91. -      "
  92. -      eval `echo    "$ARGSPEC" | parseargs -s sh --    $0 "$@"`
  93. -      This describes a Bourne shell script accepting up to three
  94. -      flag arguments and    one or two positional arguments, plus a
  95. -      list of additional    file arguments.     Only the first
  96. -      positional    argument is required.  The possible flags (in
  97. -      UNIX) are:
  98. -       -c count  An integer repetition count.  This defaults
  99. -             to two.
  100. -       -v        A Boolean ``verbose'' flag.     It defaults to
  101. -             FALSE (an empty string).
  102. -       -X        A Boolean ``X Rated'' flag.     This is not
  103. -             printed in the usage message.
  104. -      The two positional    arguments are both strings, as is the
  105. -      final list.  If we    were to    invoke the above script    with the
  106. -      following command line:
  107. -       cmdname  -v  input_file  output_file    file1  file2
  108. -      Then, after invoking parseargs, the following shell
  109. -      variables would contain the following values:
  110. -       $RepCount would evaluate to ``2''
  111. -       $Verbose would evaluate to ``TRUE''
  112. -       $InFile would    evaluate to ``input_file''
  113. -       $OutFile would evaluate to ``output_file''
  114. -       $Files would evaluate    to ``file1  file2''
  115. -       $XRated would    be unset and would evaluate to an empty
  116. -       string (``'').
  117. -      Now let's present a more complete example.    The following
  118. -      page shows    a Bourne shell script which uses parseargs to
  119. -      parse its command line, echoes the    settings of all    its
  120. -      associated    command    line variables,    and then prints    its
  121. -      command usage.
  122. - Page 12
  123. - PARSEARGS(1)                         PARSEARGS(1)
  124. -      #!/bin/sh
  125. -      #      test.sh - Bourne shell script    to test    out the    parseargs command!
  126. -      #
  127. -      NAME="`basename $0`";  DOT=".";
  128. -      ARGUMENTS="
  129. -        '?', ARGHIDDEN, argUsage, NULL,      'Help    : print    usage and exit',
  130. -        'S', ARGVALOPT, argStr,     string,  'STRing : optional string arg',
  131. -        'g', ARGLIST,   argStr,     groups,  'newsGROUPS :    groups to test',
  132. -        'r', ARGOPT,    argInt,     count,      'REPcount <# to repeat each group>',
  133. -        'd', ARGOPT,    argStr,     dirname, 'DIRectory : working directory',
  134. -        'x', ARGOPT,    argBool,     xflag,      'Xflag : turn    on X-mode',
  135. -        'y', ARGOPT,    argUBool, yflag,      'Yflag : turn    off Y-mode',
  136. -        's', ARGOPT,    argChar,     sepch,      'SEPchar : field separator',
  137. -        'f', ARGLIST,   argStr,     files,      'files : files to process',
  138. -        'n', ARGREQ|ARGPOS, argStr, name,  'name    : name to use',
  139. -        ' ', ARGLIST,   argStr,     -- ,      'argv    : any remaining    arguments',
  140. -        ENDOFARGS
  141. -      "
  142. -      export ARGUMENTS
  143. -      yflag='TRUE'     ## set defaults (dir=".";    count=1; sepch=',') ##
  144. -      ##    parse command-line and save assignments    in a temporary file ##
  145. -      parseargs -s sh -e    ARGUMENTS -u --    "$NAME"    "$@" >/tmp/tmp$$
  146. -      if    [ $? -ne 0 ]
  147. -        then rm -f /tmp/tmp$$; exit 2  ## non-zero status (usage    given)
  148. -      fi
  149. -      ##    evaluate results from parseargs    and remove temporary file
  150. -      $DOT /tmp/tmp$$;  rm -f /tmp/tmp$$
  151. -      ##    echo  the parsed arguments (use    defaults if not    defined)
  152. -      echo "ARGUMENTS:"
  153. -      echo "=========="
  154. -      echo "Name='$name', Count='${count:-1}'"
  155. -      echo "XFlag='$xflag', YFlag='$yflag'"
  156. -      echo "Directory='${dirname:-"."}',    SepChar='${sepch:-","}'"
  157. -      echo "Groups='$groups'"
  158. -      echo "Files='$files'"
  159. -      if    [ "$string_flag" ]
  160. -        then string=${string:-"!string arg ommitted on cmd-line!"}
  161. -        else string="default string"
  162. -      fi
  163. -      echo "String='$string'"
  164. -      echo "New Positional Parameters='$*'"
  165. -      parseargs -a "$ARGUMENTS" -U "$NAME"     ## print usage ##
  166. - DIAGNOSTICS
  167. -      Parseargs may exit    with one of the    following status codes:
  168. - Page 13
  169. - PARSEARGS(1)                         PARSEARGS(1)
  170. -      -1      Some type of system error occurred during execution,
  171. -       causing the program to exit prematurely.
  172. -      0      Normal exit status (no problems were encountered).
  173. -      1      The calling program specified    the -#,    the -U or the -M
  174. -       option to parseargs, or specified an argUsage    flag on
  175. -       the command line.  Only the appropriate message is
  176. -       displayed.
  177. -      2      A command line syntax    error was encountered by
  178. -       parseargs. The offending command line    argument may have
  179. -       been intended    for either parseargs or    for the    calling
  180. -       program.
  181. -      3      The environment variable that    was specified with the -e
  182. -       option is either NULL    (has an    empty value) or    does not
  183. -       exist. Perhaps the user specified a shell variable
  184. -       and/or forgot    to export it.
  185. -      4      A syntax error was encountered in the    argument
  186. -       specification    string that was    specified to parseargs.
  187. - FILES
  188. -      /usr/local/parseargs.pl
  189. -       This file defines a perl function named parseargs to
  190. -       parse    arguments more conveniently for    perl-scripts. The
  191. -       function is both documented and implemented in this
  192. -       file.    The user should    ``require'' this file in his/her
  193. -       perl-script before invoking the function.
  194. -      /usr/local/parseargs.awk
  195. -       This file defines an awk function named parseargs to
  196. -       parse    arguments more conveniently for    awk-scripts. The
  197. -       function is both documented and implemented in this
  198. -       file.    The user should    include    this file in his/her
  199. -       awk-script before invoking the function.
  200. - SEE ALSO
  201. -      argtype(3), parseargs(3), parsecntl(3)
  202. - CAVEATS
  203. -      Because of    the way    argument parsing is implemented    under
  204. -      UNIX, MS-DOS, and OS/2, option arguments which contain a
  205. -      leading dash (`-')    (or whatever the option    prefix character
  206. -      is    defined    to be) may not be specified as a separate
  207. -      argument on the command line, it must be part of the same
  208. -      argument. That is to say that if a    program    has a -f option
  209. -      that requires a string argument, then the following:
  210. -       -f-arg
  211. -      will properly assign the string ``-arg'' to the option
  212. - Page 14
  213. - PARSEARGS(1)                         PARSEARGS(1)
  214. -      whereas the following:
  215. -       -f -arg
  216. -      will be interpreted by parseargs as two option strings: the
  217. -      first of which (``-f'') is    missing    a required argument and
  218. -      the second    of which (``-arg'') will most likely be    flagged
  219. -      as    an invalid option.
  220. -      Similarly,    if the user requires an    ARGLIST    option to take
  221. -      multiple arguments    with leading dashes then the following
  222. -      method must be used: It is    a ``feature'' of parseargs that
  223. -      ARGLIST arguments are always appended to the current list of
  224. -      arguments for the given option. Thus, if ``-f'' is    an option
  225. -      taking a list of arguments, then the following are    all
  226. -      equivalent:
  227. -       -farg1 arg2
  228. -       -f arg1 arg2
  229. -       -farg1 -farg2
  230. -       -f arg1 -f arg2
  231. -      Hence multiple ``leading dash'' arguments may specified as
  232. -      follows:
  233. -       -f-dash_arg1 -f-dash_arg2  ...
  234. - BUGS
  235. -      It    does not make sense to use any arguments of type argTBool
  236. -      since parseargs currently has no way of knowing what the
  237. -      initial value of the variable is. For this    reason,    argTBool
  238. -      is    not recognized as a valid argument type    (even though it
  239. -      is    used by    parseargs(3)). By the same token, since    the user
  240. -      cannot create their own arguments types on    the fly    from a
  241. -      shell-script, ARGNOVAL is not recognized as a valid argument
  242. -      flag.
  243. -      Commas will not be    interpreted properly if    any field in the
  244. -      argument specification string contains double quotes that
  245. -      are nested    inside of double quotes, or single quotes that
  246. -      are nested    inside of single quotes.
  247. -      Inside the    argument specification string, any repeated
  248. -      string of commas that does    not appear inside of double or
  249. -      single quotes will    be treated as a    single comma.
  250. -      Text descriptions for argument entries are    automatically
  251. -      formatted in usage    messages. Any attempt by the user to
  252. -      include tabs and/or newlines in the description will cause
  253. -      it    to be formatted    improperly.
  254. -      Parseargs cannot properly preserve    any newlines in    shell
  255. -      variables if the eval command is used to read its output
  256. - Page 15
  257. - PARSEARGS(1)                         PARSEARGS(1)
  258. -      (this is a    shortcoming of the eval    command, not of
  259. -      parseargs). If the    user is    concerned about    this particular
  260. -      case, then    the user should    redirect the output from
  261. -      parseargs to a temporary file and use the source command in
  262. -      csh or the    dot command (`.') in sh    and ksh, to interpret the
  263. -      results; otherwise, newlines will be translated into spaces,
  264. -      or    characters following a newline may be lost, in any
  265. -      variables that are    set by parseargs.
  266. - AUTHOR
  267. -      Brad Appleton  (brad@ssd.csd.harris.com)
  268. -      Harris Computer Systems, Fort Lauderdale, FL USA
  269. - Page 16
  270. --- 0 ----
  271. diff -cNr ../patchlevel4/parseargs3.txt ./parseargs3.txt
  272. *** ../patchlevel4/parseargs3.txt    Thu May  2 11:06:45 1991
  273. --- ./parseargs3.txt    Wed Dec 31 18:00:00 1969
  274. ***************
  275. *** 1,1254 ****
  276. - PARSEARGS(3)                         PARSEARGS(3)
  277. - NAME
  278. -      parseargs - parse command line argument vectors
  279. - SYNOPSIS
  280. -      #include <parseargs.h>
  281. -      int  parseargs(  char *argv[],  ARGDESC *argd  );
  282. -      int  fparseargs(  FILE *fp,  ARGDESC *argd     );
  283. -      int  lparseargs(  ArgList *argls,    ARGDESC    *argd  );
  284. -      int  sparseargs(  char *str,  ARGDESC *argd  );
  285. -      int  vparseargs(  ARGDESC *argd, int argc,     ...  );
  286. -      void  usage(  const ARGDESC *argd    );
  287. -      extern  const char    *ProgName;
  288. - DESCRIPTION
  289. -      Given a vector of string-valued arguments such as that
  290. -      passed to main and    a vector describing the    possible argu-
  291. -      ments, parseargs matches actual arguments to possible argu-
  292. -      ments, converts values to the desired type, and diagnoses
  293. -      problems such as missing arguments, extra arguments, and
  294. -      argument values that are syntactically incorrect.
  295. -      Given a readable input stream and an argdesc array, fpar-
  296. -      seargs will parse arguments in a file in the same manner as
  297. -      parseargs.     A maximum-line    length of 255 characters is
  298. -      imposed.  NO ``escaping'' of any kind is performed. Comments
  299. -      of    a limited form are permitted: if the first non-whitespace
  300. -      character on a line is a '#' (or '!' for VMS) then    that
  301. -      entire line is considered a comment and is    ignored.  If a
  302. -      value is provided for an argument that is NOT a list or a
  303. -      vector, then the value MUST be on the same    line as    the argu-
  304. -      ment (in other words, ``-v    val'' is fine but ``-v\nval'' is
  305. -      a not).
  306. -      Given an ArgList and an argdesc array, lparseargs will parse
  307. -      arguments in an ArgList in    the same manner    as parseargs.
  308. -      Given a single string and an argdesc array, sparseargs will
  309. -      parse arguments from a string in much the manner as par-
  310. -      seargs.  Sparseargs will split the    given string up    into a
  311. -      vector of whitespace separated tokens and then attempt to
  312. -      parse the resultant vector    as if it were given as argv[] on
  313. -      the command-line.    NO special treatment is    given to charac-
  314. -      ters such as single-quotes, double-quotes,    or anything else.
  315. -      Sparseargs    will always assume that    any whitespace characters
  316. -      are intended as argument separators.
  317. -      Vparseargs    takes an argdesc array,    the number of arguments
  318. -      to    parse, and a (possibly NULL terminated)    list of
  319. -      argument-strings and parses them in the same manner as par-
  320. -      seargs.  Unlike sparseargs, vparseargs assumes that all
  321. -      parameters    are already split up into tokens, hence    any
  322. - Page 1
  323. - PARSEARGS(3)                         PARSEARGS(3)
  324. -      whitespace    characters contained in    any of the string-
  325. -      parameters    are used as is (and will be considered a part of
  326. -      an    argument name or value).
  327. -      Given an argdesc array, usage will    print the usage    for the
  328. -      given command in the format specified by the user's
  329. -      USAGECNTL environment variable.
  330. -      After returning from any of the aforementioned functions,
  331. -      the global    string ProgName    will contain the name of the com-
  332. -      mand corresponding    to the argument-descriptor array that was
  333. -      most recently operated upon by one    the functions in the par-
  334. -      seargs(3) function    library.
  335. - THE ARGUMENT STRUCTURE
  336. -      The basic type used by the    parseargs library is the argument
  337. -      descriptor    (or "argdesc" for short). An ARGDESC structure is
  338. -      used to describe a    command-line argument. Each command line
  339. -      argument contains various fields which need to be set and/or
  340. -      queried by    the programmer.     The individual    fields of an
  341. -      ARGDESC structure are desribed below:
  342. -      char  ad_name;
  343. -       This is a single character which corresponds to the
  344. -       option-letter    (case-sensitive) from the command-line
  345. -       that matches the argument described by this structure.
  346. -       Positional-arguments are denoted by putting a    a space
  347. -       character in this field.
  348. -      argMask_t    ad_flags;
  349. -       This field contains the various bitflags that    describe
  350. -       the semantics    of this    argument. See the ARGUMENT FLAGS
  351. -       section for more information on the possible combina-
  352. -       tions    of bitmasks for    this field.
  353. -      argTypePtr_t  ad_type;
  354. -       This field is    a pointer to a type conversion function
  355. -       (such    as the ones provided in    argtype(3)). The type
  356. -       conversion function is responsible for verifying the
  357. -       validity of the argument, allocating any necessary
  358. -       storage for its internal representation, and converting
  359. -       the command-line argument into its required internal
  360. -       form.    The type conversion function used may be one of
  361. -       the pre-defined argtype(3) functions.    The function is
  362. -       given    three parameters: The first is a pointer to the
  363. -       ARGDESC struct in question, the second is the    string-
  364. -       value    (if any) supplied on the command-line, and the
  365. -       third    is a boolean value that    is TRUE    only if    the
  366. -       second parameter points to temporary storage (and hence
  367. -       may need to be copied).  In the case of parseargs(1)
  368. -       this field must correspond to    the name of one    of the
  369. -       argument type    functions described in argtype(3).
  370. - Page 2
  371. - PARSEARGS(3)                         PARSEARGS(3)
  372. -      ARBPTR  ad_valp;
  373. -       This field is    a generic pointer to the storage used to
  374. -       represent the    internal value of the command-line argu-
  375. -       ment.    It may be a pointer to a number, a boolean value,
  376. -       a string, a list, or anything    else for which there
  377. -       exists a corresponding arg-type function to use in the
  378. -       ad_type field. In the    case of    of parseargs(1)    this
  379. -       field    must be    the name of the    corresponding shell vari-
  380. -       able which will eventually hold the value of the argu-
  381. -       ment given on    the command-line.
  382. -      const char     *ad_prompt;
  383. -       This field contains the long-name of the argument and
  384. -       an optional description (the description must    be
  385. -       separated from the long-name by at least one whitespace
  386. -       character and    may optionally be enclosed in a    set of
  387. -       balanced delimiters (such as parentheses, curly-braces,
  388. -       square-brackets, or angle-brackets). If the long-name
  389. -       contains any uppercase characters, then the substring
  390. -       of long-name consisting of all uppercase characters is
  391. -       used as the argument keyword and the entire long-name
  392. -       is used as the name of the argument (if a value may be
  393. -       supplied). The long-name may be matched by supplying a
  394. -       unique prefix    of either the argument keyword or the
  395. -       argument name.
  396. - DEFINING ARGDESC ARRAYS
  397. -      When defining an argdesc array, the first item in the list
  398. -      should be the item    STARTOFARGS. Normal arguments (defined by
  399. -      the programmer) may then be specified as documented in this
  400. -      manual.  The list of arguments is terminated using
  401. -      ENDOFARGS.
  402. -      For example, consider the description:
  403. -        int  RepCount =       2;
  404. -        BOOL Verbose = FALSE;
  405. -        char *InFile;
  406. -        char *OutFile =       CHARNULL;
  407. -        BOOL XRated =  FALSE;
  408. -        ArgList *Files =       ARGLISTNULL;
  409. -        ARGDESC Args[] =
  410. -        {
  411. -      STARTOFARGS,
  412. -      'c', ARGOPT,     argInt,  __ &RepCount,    "REPcount {# of    repetitions}",
  413. -      'v', ARGOPT,     argBool, __ &Verbose,    "Verbose {set verbose mode}",
  414. -      ' ', ARGREQ,     argStr,  __ &InFile,    "INPUTfile {input file}",
  415. -      ' ', ARGOPT,     argStr,  __ &OutFile,    "OUTPUTfile {output file}",
  416. -      'X', ARGHIDDEN, argBool, __ &XRated,    "XratedMODE {naughty stuff!}",
  417. -      ' ', ARGLIST,     listStr, __ &Files,    "File {files to    be read}",
  418. -      ENDOFARGS
  419. -        };
  420. - Page 3
  421. - PARSEARGS(3)                         PARSEARGS(3)
  422. -      This describes a program accepting    up to three flag argu-
  423. -      ments and one or two positional arguments,    plus a list of
  424. -      additional    file arguments.     Only the first    positional argu-
  425. -      ment is required.    The possible flags (in UNIX) are:
  426. -      -c    count  An integer repetition count.  This defaults to
  427. -            two.
  428. -      -v           A Boolean ``verbose'' flag.  It defaults    to FALSE.
  429. -      -X           A Boolean ``X Rated'' flag.  This is not    printed
  430. -            in the usage message.
  431. -      The two positional    arguments are both strings, as is the
  432. -      final list.  In AmigaDOS, the options would be REP    count, V,
  433. -      and XMODE.     In VAX/VMS, the qualifiers would be /REP=count,
  434. -      /V, and /XMODE.
  435. - ARGUMENT FLAGS
  436. -      These are the possible bitmasks that may be turned    ON or OFF
  437. -      in    the ad_flags field of an ARGDESC structure.
  438. -      ARGOPT
  439. -       This flag is actually    a dummy    flag (i.e. it is the
  440. -       default). This flag specifies    that the command-line
  441. -       argument is optional (need not appear    on the command-
  442. -       line). It is only needed if no other flags are used to
  443. -       define the given argument.  If other flags are given
  444. -       and ARGREQ is    NOT one    of them, then ARGOPT is    always
  445. -       assumed.
  446. -      ARGREQ
  447. -       The associated command argument is required on the
  448. -       command-line.
  449. -      ARGPOS
  450. -       The associated command argument is positonal.    The
  451. -       difference between using this    flag to    indicate a posi-
  452. -       tional argument and between using a blank in the
  453. -       ad_name field    to indicate a positional arguments is the
  454. -       following: If    this flag is set but the ad_name of the
  455. -       argument is non-blank, then this argument may    be
  456. -       matched either positionally or by keyword. If    the
  457. -       ad_name field    is blank, then this argument may only be
  458. -       matched positionally.
  459. -      ARGNOVAL
  460. -       The associated command argument takes    no value (as in
  461. -       "-x value"); Its mere    presence (or lack thereof) on the
  462. -       command-line is sufficient to    determine the necessary
  463. -       action(s) to take (as    in "-x").  Boolean argument types
  464. -       and Pseudo-argument types automatically default to
  465. - Page 4
  466. - PARSEARGS(3)                         PARSEARGS(3)
  467. -       ARGNOVAL.
  468. -      ARGVALOPT
  469. -       This flag is used to indicate    that the command-line
  470. -       argument takes a value (as in    "-s string" or
  471. -       "/str=string") but that the value to this command-line
  472. -       argument is NOT required (hence simply "-s" or "/str"
  473. -       is also permissable).
  474. -      ARGVALREQ
  475. -       Another "dummy" flag.    Unless ARGNOVAL    or ARGVALOPT is
  476. -       specified, ARGVALREQ is always assumed. This flag indi-
  477. -       cates    that the value to a command-line argument is
  478. -       required (hence "-s string" is okay but just "-s" is
  479. -       not).
  480. -      ARGHIDDEN
  481. -       Don't    display    this argument in usage messages    but still
  482. -       attempt to match it against strings given on the
  483. -       command-line.
  484. -      ARGLIST
  485. -       A variable number of values are used for this    argument
  486. -       (and hence may use more than one or two argv elements
  487. -       from the command-line    as in "-l val1 val2 ..."). The
  488. -       list of values must be stored    in an ArgList structure
  489. -       (NOT a vector    structure), an the corresponding
  490. -       argument-type    function should    be one of the listXxxx
  491. -       functions.
  492. -      ARGVEC
  493. -       A variable number of values are used for this    argument
  494. -       (and hence may use more than one or two argv elements
  495. -       from the command-line    as in in "-v val1 val2 ..."). The
  496. -       list of values must be stored    in a vector structure
  497. -       (NOT an ArgList structure).
  498. -      The following bitmasks may    also be    present, but, unlike the
  499. -      above masks which must be specified by the    programmer at
  500. -      initialization time, the following    masks must only    be read
  501. -      (never set) by the    programmer. They may be    queried    by using
  502. -      the pc_ARGFLAGS function code and the mode    pc_READ    with par-
  503. -      secntl(3).
  504. -      ARGGIVEN
  505. -       The argument WAS given on the    command-line.
  506. -      ARGVALGIVEN
  507. -       The value for    this argument was given    on the command-
  508. -       line.
  509. -      ARGVALSEP
  510. - Page 5
  511. - PARSEARGS(3)                         PARSEARGS(3)
  512. -       The value to this argument was supplied in a separate
  513. -       argv element from the    argument itself    (as in "-x value"
  514. -       as opposed to    "-xvalue").
  515. -      ARGKEYWORD
  516. -       This argument    was matched as a keyword (long-form) on
  517. -       the command-line and not as a    single character.
  518. -      ARGDESCRIBED
  519. -       This argument    was given a description    by the programmer
  520. -       at initialization.
  521. -      ARGCOPYF
  522. -       This flag is only used for lists and vectors (mul-
  523. -       tivalued arguments) and is used on a per-item    basis. If
  524. -       it is    set, it    means that the corresponding value in the
  525. -       vector/list required space to    be allocated (such as the
  526. -       duplication of a temporary string).
  527. - ARGDESC    MACROS
  528. -      The following macros are used to extract and query    the
  529. -      attributes    of a pointer to    a preprocessed arg-descriptor:
  530. -      arg_cname(ad)
  531. -       Return the single-character name of an argument.
  532. -      arg_flags(ad)
  533. -       Return the argument flags of an argument.  The flags
  534. -       themselves may be manipulated    using the BTEST, BSET,
  535. -       and BCLEAR macros defined in <useful.h>.
  536. -      arg_type(ad)
  537. -       Return the pointer to    the value-translation-routine of
  538. -       an argument.
  539. -      arg_valp(ad)
  540. -       Return the pointer to    the value of this argument.
  541. -      arg_sname(ad)
  542. -       Return the string name of an argument.
  543. -      arg_sdesc(ad)
  544. -       Return the description of an argument. If a description
  545. -       was supplied,    the ARGDESCRIBED flag will be set and the
  546. -       description will immediately follow the terminating
  547. -       NULL byte of the string name.
  548. -      ARG_isDESCRIBED(ad)
  549. -       Evaluates to TRUE only if an argument    description was
  550. -       provided.
  551. -      arg_description(ad)
  552. - Page 6
  553. - PARSEARGS(3)                         PARSEARGS(3)
  554. -       Return the description string    (or an empty string if no
  555. -       description was given) for this argument.
  556. -      ARG_isPOSITIONAL(ad)
  557. -       Evaluates to TRUE if this argument may be positionally
  558. -       matched.
  559. -      ARG_isPOSONLY(ad)
  560. -       Evaluates to TRUE if this argument may only be posi-
  561. -       tionally matched.
  562. -      ARG_isLIST(ad)
  563. -       Evaluates to TRUE if this argument is    an arglist.
  564. -      ARG_isVEC(ad)
  565. -       Evaluates to TRUE if this argument is    a vector.
  566. -      ARG_isMULTIVAL(ad)
  567. -       Evaluates to TRUE if this argument is    an arglist or a
  568. -       vector.
  569. -      ARG_isVALTAKEN(ad)
  570. -       Evaluates to TRUE if this argument does NOT take a
  571. -       value.
  572. -      ARG_isGIVEN(ad)
  573. -       Evaluates to TRUE if this argument was given on the
  574. -       command-line.
  575. -      ARG_isVALGIVEN(ad)
  576. -       Evaluates to TRUE if the argument value was given on
  577. -       the command-line.
  578. -      ARG_isREQUIRED(ad)
  579. -       Evaluates to TRUE if this argument is    required.
  580. -      ARG_isVALOPTIONAL(ad)
  581. -       Evaluates to TRUE if the argument value is optional.
  582. -      ARG_isVALSEPARATE(ad)
  583. -       Evaluates to TRUE if the argument value is optional.
  584. -      ARG_isHIDDEN(ad)
  585. -       Evaluates to TRUE if this argument is    omitted    from
  586. -       usage    messages.
  587. - CMD MACROS
  588. -      <parseargs.h> defines a set of macros to allow a more "self
  589. -      documenting" approach to declaring    argument-descriptor
  590. -      arrays. The "old-style" is    still accepted (but if used it is
  591. -      recommended that the STARTOFARGS macro is used in conjunc-
  592. -      tion with ENDOFARGS).  An example use of these macros
  593. - Page 7
  594. - PARSEARGS(3)                         PARSEARGS(3)
  595. -      (which, with one exception, all begin with    ``CMD'') follows:
  596. -       #include <parseargs.h>
  597. -       static BOOL bflag = FALSE;
  598. -       static char *arg1 = CHARNULL;
  599. -       static char *arg2 = CHARNULL;
  600. -       static
  601. -          CMD_OBJECT
  602. -         MyCmd
  603. -          CMD_NAME
  604. -         "mycmd -- one line statement of    purpose"
  605. -          CMD_DESCRIPTION
  606. -         "Mycmd will try    really really hard to run without errors \
  607. -       and do whatever the heck it is supposed to do. If (God forbid) \
  608. -       something should actually go wrong it    will say so."
  609. -          CMD_ARGUMENTS
  610. -         'H', ARGOPT, argUsage, __ NULL,
  611. -         "Help -- display usage and quit",
  612. -         'b', ARGOPT, argSBool, __ &bflag,
  613. -         "bflag -- turn on `b'-mode (whatever that is)",
  614. -         ' ', ARGREQ, argStr, __    &arg1,
  615. -         "arg1 -- first argument    to this    spiffy program",
  616. -         ' ', ARGOPT, argStr, __    &arg2,
  617. -         "arg2 -- optional second argument to this spiffy program",
  618. -         END_ARGUMENTS
  619. -          CMD_END
  620. -       main(    int argc, char *argv[] )
  621. -       {
  622. -          (void) parseargs( argv, MyCmd );
  623. -          (void) dostuff();
  624. -          exit( 0 );
  625. -       }
  626. - DEFAULT    ARGUMENT DESCRIPTOR
  627. -      Each argdesc-array    has an initial default argument    list
  628. -      (which may    be reset using the pc_DEFARGS function code with
  629. -      parsecntl). This initial default argument-list contains `?'
  630. -      and `H' which may be used as single character keywords to
  631. -      display command-usage for all command-line    styles.     Simi-
  632. -      larly, ``?'', ``H'', and ``Help'' may be used as long-
  633. -      keywords to display command-usage for all command-line
  634. -      styles.  In Addition, for VMS style commands, the qualifiers
  635. -      /INPUT=file, /OUTPUT=file,    and /ERROR=file, may be    used to
  636. - Page 8
  637. - PARSEARGS(3)                         PARSEARGS(3)
  638. -      redirect stdin, stdout, and stderr    (respectively) to a file.
  639. -      For AmigaDOS style    commands, the keyword ``ENDKWDS'' may be
  640. -      used to disable parsing for any more keywords on the
  641. -      command-line.
  642. - SUPPLYING DEFAULT ARGUMENTS
  643. -      Programs that use parseargs may be    given default arguments
  644. -      under UNIX    and PCs    through    the use    of environment variables
  645. -      (symbols are used for VMS systems). If a  C-program or
  646. -      shell-script uses parseargs to implement a    command    named
  647. -      ``cmd'' then the environment variable ``CMD_ARGS''    will be
  648. -      parsed for    any "default" arguments    before the command-line
  649. -      is    parsed.     The command-line will over-ride any options that
  650. -      are specified in this environment variable    (except    that
  651. -      ARGLISTs and ARGVECs set in ``CMD_ARGS'' will be appended
  652. -      from the command-line if they are selected).
  653. -      It    is important to    note that the contents of the
  654. -      ``CMD_ARGS'' environment variable are NOT expanded    by the
  655. -      shell and hence any special characters (such as quotes or
  656. -      back-slashes) will    NOT be escaped or removed by parseargs.
  657. -      Furthermore, it will not be possible to try and use a tab,
  658. -      space, or newline character in the    environment variable as
  659. -      anything other than an argument separator.
  660. -      Lastly, parts of an option    specification in ``CMD_ARGS'' may
  661. -      NOT be continued on the command-line. As an example, if -f
  662. -      requires an argument and CMD_ARGS="-f", then the command-
  663. -      line "cmd    bah" will NOT assign "bah" as the argument to -f
  664. -      but will instead complain about a missing argument    for -f.
  665. -      Similarly,    if -l takes a list of arguments    and CMD_ARGS="-l
  666. -      item1 item2", then    the command-line "cmd  bah", will NOT
  667. -      assign "bah" to the end of    the list containing "item1" and
  668. -      "item2" but will instead treat "bah" as the first positional
  669. -      parameter on the command-line.
  670. - PARSING    BEHAVIOR
  671. -      The programmer may    control    parsing    behavior through the use
  672. -      of    parsecntl(3).  The user    may set    his (or    her) own desired
  673. -      parsing behavior through the use of the ``PARSECNTL''
  674. -      environment variable.  By indicating any number of    flags
  675. -      (possibly negated)    the user will directly modify the
  676. -      behavior of the parseargs library.    Flags may be combined by
  677. -      placing a `+' or `|' character in between flags. A    switch is
  678. -      negated by    immediately preceding it with a    `!' or `-' char-
  679. -      acter.  The possible ``flags'' are    given by the following
  680. -      table. Flags are case-insensitive.
  681. -      Prompt
  682. -       Prompt the user for any missing arguments that are
  683. -       required on the command-line.    No special escaping or
  684. -       quoting is performed on the user input. Required
  685. - Page 9
  686. - PARSEARGS(3)                         PARSEARGS(3)
  687. -       arguments that expect    a list of values will be repeat-
  688. -       edly prompted    for (one item per line)    until a    blank
  689. -       line (followed by a carriage return) is entered.
  690. -      Ignore
  691. -       Ignore any unrecognized or improperly    specified
  692. -       command-line arguments and continue execution    of the
  693. -       program. Normally, if    a required argument is unmatched
  694. -       (or an argument is improperly    specified), a usage mes-
  695. -       sage is printed program execution is terminated.
  696. -      OptsOnly
  697. -       Under    UNIX, setting this flag    will disable the parsing
  698. -       of long-option syntax. This will cause all arguments
  699. -       starting with    `+' to always be treated as a positional
  700. -       parameter (instead of    a long-option).
  701. -      KwdsOnly
  702. -       Under    UNIX, setting this flag    disables the parsing of
  703. -       single-character options.  This will cause all argu-
  704. -       ments    starting with `-' to always be treated as a posi-
  705. -       tional parameter (instead of an option).
  706. -      LoptsOnly
  707. -       Same as KwdsOnly.
  708. -      Flags1st
  709. -       Setting this flag causes the parseargs library to force
  710. -       any and all non-positional arguments to be specified
  711. -       before any positional    ones.  As an example, under UNIX,
  712. -       if this flag is SET then parseargs will consider the
  713. -       command line "cmd -x arg" to consist of one option and
  714. -       one positional argument; however the command line "cmd
  715. -       arg -x" would    be considered to consist of two    posi-
  716. -       tional arguments (the    -x option will be unmatched).
  717. -       If this flag is UNSET, then both of the previous exam-
  718. -       ples are considered to consist of one    option and one
  719. -       positional argument.
  720. -      CaseIgnore
  721. -       Setting this flag will cause character-case to be
  722. -       ignored when attempting to match single-character argu-
  723. -       ment names (i.e. causes "-i" and "-I"    to be considered
  724. -       equivalent).
  725. -      If    the environment    variable ``PARSECNTL'' is empty    or unde-
  726. -      fined, then the parsing behavior set by the programmer is
  727. -      used.  If the programmer has not explicitly used par-
  728. -      secntl(3) to modify the parsing behavior, then the    default
  729. -      behavior will be ``Flags1st'' for Unix systems, ``!Prompt +
  730. -      !Ignore'' for AmigaDOS systems, ``CaseIgnore'' for    MS-DOS
  731. - Page 10
  732. - PARSEARGS(3)                         PARSEARGS(3)
  733. -      and OS/2 systems, and ``Prompt'' for VMS systems.
  734. - USAGE MESSAGES
  735. -      Through the use of    an environment variable    (or a VMS sym-
  736. -      bol), the user may    control    the syntax and the verbosity of
  737. -      the command-usage messages    that are printed by parseargs.
  738. -      The desired level of verbosity may    be set by defining the
  739. -      environment variable ``USAGECNTL" to be a combination of
  740. -      strings (case insensitive). The value of each string con-
  741. -      trols one of three    different ``modes'' of behavior    in the
  742. -      displaying    of usage messages:  The    first ``mode'' is ``ver-
  743. -      bose'' mode, which    controls whether or not    a detailed
  744. -      description of each argument should accompany the usual
  745. -      command-line sysnopsis. If    verbose    mode is    ``off'', then
  746. -      only a command-line synopsis is printed (this is also ref-
  747. -      ferred to as ``terse'' mode). The other two ``modes'' con-
  748. -      trol the displaying of option syntax and long-option syntax.
  749. -      A mode may    be explicitly disabled by preceding its
  750. -      corresponding string with the `!'    or `-' character. The
  751. -      ``modes'' which correspond    to the possible    values of the
  752. -      ``USAGECNTL'' environment variable    are given by the follow-
  753. -      ing table.
  754. -      Quiet
  755. -       No usage message of any kind is displayed.
  756. -      Silent
  757. -       Same as Quiet.
  758. -      Paged
  759. -       The usage message is piped to    a pager. The pager used
  760. -       is named by the ``USAGE_PAGER'' environment variable.
  761. -       If this variable is unset or empty (or is not    the name
  762. -       of an    executable program) then the pager named by the
  763. -       ``PAGER'' environment    variable us used.  If this vari-
  764. -       able is unset    or empty (or is    not the    name of    an exe-
  765. -       cutable program) then    /usr/ucb/more is used.
  766. -      Description
  767. -       The command description is printed.
  768. -      Terse
  769. -       Terse    mode, just print command-line synopsis.
  770. -      Verbose
  771. -       Verbose mode,    print descriptions for each argument
  772. -      Options
  773. -       Option syntax    is displayed.
  774. -      LongOpts
  775. -       Long-option syntax is    displayed.
  776. - Page 11
  777. - PARSEARGS(3)                         PARSEARGS(3)
  778. -      KeyWords
  779. -       Same as LongOpts.
  780. -      If    the environment    variable ``USAGECNTL'' is empty    or unde-
  781. -      fined, then the default usage level (which    is presently
  782. -      ``Verbose + Options'') will be used.
  783. - MULTI-VALUED ARGUMENTS
  784. -      Parseargs supports    two different types of multi-valued argu-
  785. -      ments: linked-lists and vectors. The linked-lists are called
  786. -      argument lists (or    arg-lists) and are specified by    supplying
  787. -      the ARGLIST flag along with an associated listXxxx
  788. -      argument-translation routine. The value associated    with an
  789. -      arg-list should be    a list structure of type ArgList. The
  790. -      include file <parseargs.h>    defines    four macros for    manipu-
  791. -      lating ArgList structures:     ARGLISTNULL, L_NEXT, L_STRING,
  792. -      and L_FLAGS.
  793. -      ARGLISTNULL is simply the NULL argument-list pointer.
  794. -      L_NEXT and    L_STRING each take a pointer to    a non-NULL
  795. -      ArgList structure.    L_NEXT returns the address of the next
  796. -      item in the list and L_STRING returns the string-value of
  797. -      the current list-item.  L_FLAGS return the    arg-flags for a
  798. -      given item    in the list. With non-multivalued arguments, only
  799. -      the flags in the argument descriptor are needed; lists and
  800. -      vectors however need a set    of flags for each item they con-
  801. -      tain. Once    an arg-list has    been created, it may be    deallo-
  802. -      cated using the function listFree.    ListFree takes one param-
  803. -      eter: the address of the first item in the    arg-list.
  804. -      An    alternative to argument-lists is argument vectors (or
  805. -      arg-vectors).  Arg-vectors    use the    ARGVEC flag instead of
  806. -      the ARGLIST flag and do not require a special listXxxx func-
  807. -      tion for each vector-type.     Each of the argXxxx functions is
  808. -      responsible for handling vectors of its type (although some
  809. -      argXxx functions such as the boolean types    do not support
  810. -      vectors). An arg-vector is    a structure which contains a
  811. -      count, an array of    elements (i.e. an argc,argv pair), and an
  812. -      array of flags, one for each element of argv. There are two
  813. -      macros in defined in <parseargs.h>    which are used for arg-
  814. -      vectors. ARGVEC_T may be used to declare a    vector structure
  815. -      or    a vector type; ARGVEC_EMPTY may    be used    to initialize the
  816. -      structure.     It is strongly    recommended that ARGVEC_T be used
  817. -      to    declare    vector types in    a typedef statement (particularly
  818. -      if    one is using function prototypes) but for those    who
  819. -      insist, it    may be used to directly    declare    a  structure.
  820. -      String-vectors will always    have an    extra NULL-pointer at the
  821. -      end such that:
  822. -       ( StrVec.array[ StrVec.count ] == (char *)NULL )
  823. -      is    always true, and character-vectors will    always have an
  824. - Page 12
  825. - PARSEARGS(3)                         PARSEARGS(3)
  826. -      extra NUL-character at the    end such that:
  827. -       ( CharVec.array[ CharVec.count ] == '\0' )
  828. -      is    always true. Integer and floating point    vectors    contain
  829. -      no    extra "null" elements.
  830. -      Once created, arg-vectors may be deallocated by calling the
  831. -      macro vecFree or the macro    vecDeepFree and    passing    it the
  832. -      arg-vector    structure. The differemce between these    two mac-
  833. -      ros is that the latter will also free each    item in    the vec-
  834. -      tor that required space to    be allocated (at the expense of
  835. -      traversing    the vector).  At this writing, the only    prede-
  836. -      fined argument-types that would benefit from vecDeepFree is
  837. -      argStr vectors.
  838. -      An    example    use of arg-lists, and of arg-vectors follows:
  839. -       #include <parseargs.h>
  840. -       typedef ARGVEC_T(char    *) strvec_t;
  841. -       static ArgList  *StringList =    ARGLISTNULL;
  842. -       static strvec_t  StringVec = ARGVEC_EMPTY(char *);
  843. -       static ARGVEC_T(int)    NumberVec = ARGVEC_EMPTY(int);
  844. -       static
  845. -         CMD_OBJECT    Args
  846. -         CMD_NAME    "foo --    do whatever foo    does"
  847. -         CMD_DESCRIPTION  "put a brief paragraph here"
  848. -         CMD_ARGUMENTS
  849. -            'l', ARGLIST, listStr, __ &StrList, "LiSt {list of strings}",
  850. -            's', ARGVEC,  argStr,  __ &StrVec,  "STRing {vector of strings}",
  851. -            'i', ARGVEC,  argInt,  __ &NumVec,  "NUMber {vector of numbers}",
  852. -            END_ARGUMENTS
  853. -         CMD_END
  854. -       main(    int argc, char *argv[] )
  855. -       {
  856. -          int i, *ls;
  857. -          if    ( parseargs(argv, Args)    )  syserr( "parseargs failed" );
  858. -          for ( ls =    StrList, i=1 ; ls ; ls = L_NEXT(ls), i++ )
  859. -         printf(    "List item %d=%s, flags=%x\n",
  860. -             i, L_STRING(ls), L_FLAGS(ls) );
  861. -          for ( i = 0 ; i < StrVec.count ; i++ )
  862. -         printf(    "String[%d]=%s,    flags=%x\n",
  863. -             i, StrVec.array[i], StrVec.flags[i] );
  864. -          for ( i = 0 ; i < NumVec.count ; i++ )
  865. - Page 13
  866. - PARSEARGS(3)                         PARSEARGS(3)
  867. -         printf(    "Number[%d]=%s,    flags=%x\n",
  868. -             i, NumVec.array[i], NumVec.flags[i] );
  869. -          listFree( StrList );
  870. -          StrList = ARGLISTNULL;
  871. -          vecDeepFree( StrVec, char * );
  872. -          vecFree( NumVec, int );
  873. -          exit( 0 );
  874. -       }
  875. - ARGUMENT TYPE FUNCTIONS
  876. -      The argument types    recognized by parseargs    can be extended
  877. -      by    adding new type    functions.  Argument type functions are
  878. -      declared as:
  879. -       BOOL    argXxx(     ARGDESC *ad,  char *vp,  BOOL copyf  )
  880. -      The ad argument points to the descriptor for the argument
  881. -      being converted. Its main use is to find the location in
  882. -      which to store the    converted value, located in ad->ad_valp.
  883. -      The string    value to be converted is passed    in vp (which will
  884. -      be    NULL if    the ARGNOVAL flag was set for the corresponding
  885. -      entry in the arg-descriptor table).  The copyf flag is TRUE
  886. -      if    the vp string value must be copied when    saved.    Most
  887. -      non-string    types are copied implicitly (for example, integer
  888. -      arguments are stored in binary form, so the original string
  889. -      value need    not be saved), so this argument    can usually be
  890. -      ignored.  Put simply, this    flag is    TRUE when vp points to a
  891. -      temporary buffer area.
  892. -      If    the type function successfully converts    the value, and
  893. -      uses the entire value, it should return TRUE.  If the type
  894. -      function successfully converts the    value, and uses    only N
  895. -      characters    of the value, it should    return -N.  Otherwise, it
  896. -      should print a message using usrerr(3) and    return FALSE.
  897. -      This message should be of the form    "invalid xxxx option
  898. -      'yyyy' for    Zzzz", where xxxx is the type of the option, yyyy
  899. -      is    the string passed in vp, and zzzz is the name (taken from
  900. -      ad->ad_prompt).  The argXxxx function is responsible for
  901. -      detecting if the given argument descriptor    is an ARGVEC
  902. -      argument and for taking the appropriate action.
  903. -      For example, a type function that took a filename and stored
  904. -      an    open file pointer might    be coded as:
  905. -       #define REALLOC(ptr,size)  ((! ptr) ?    malloc(size) : realloc(ptr, size))
  906. -       typedef ARGVEC_T(FILE    *)  FILEvec_t;
  907. -       BOOL    argReadFile(  ARGDESC *ad,  char *vp,  BOOL copyf  )
  908. - Page 14
  909. - PARSEARGS(3)                         PARSEARGS(3)
  910. -       {
  911. -            register    FILE *fp;
  912. -            fp = fopen(vp, "r");
  913. -            if ( ! fp ) {
  914. -             usrerr("cannot open    '%s' for reading", vp);
  915. -             return (FALSE);
  916. -            }
  917. -            if ( BTEST(arg_flags(ad), ARGVEC) ) {
  918. -             FILEvec_t  *vec = (FILEvec_t *) arg_valp(ad);
  919. -             size_t  size  = (1 + vec->count) * (sizeof (FILE *));
  920. -             vec->array = (FILE **) REALLOC(vec->array, size);
  921. -             if ( ! vec->array )
  922. -              syserr( "(m|re)alloc failed in    argReadFile" );
  923. -             vec->flags = (FILE **) REALLOC(vec->flags, size);
  924. -             if ( ! vec->flags )
  925. -              syserr( "(m|re)alloc failed in    argReadFile" );
  926. -             vec->flags[    vec->count ] = arg_flags(ad);
  927. -             vec->array[    (vec->count)++ ] = fp;
  928. -            }
  929. -            else
  930. -             *(FILE *) arg_valp(ad) = fp;
  931. -            return (TRUE);
  932. -       }
  933. - LONG OPTIONS
  934. -      Under UNIX, MS-DOS, and OS/2, parseargs also allows for long
  935. -      options in    addition to single character options.  Under
  936. -      UNIX, long    options    are denoted by a `+' character.     Under
  937. -      MS-DOS, and OS/2, long options are    denoted    by the second
  938. -      character in the SWITCHAR environment variable. If    there is
  939. -      no    second character, then if the first character is `-',
  940. -      then a `+'    is used, otherwise a `/' is used.  The keyword
  941. -      that is used is the first word in the prompt field    of an
  942. -      argument descriptor entry.    Long options are case insensi-
  943. -      tive!  Under UNIX,    an argument to a long option may be
  944. -      separated from the    long option by an equal    sign (`=') or by
  945. -      one or more whitespace characters.     Thus, if an entry looks
  946. -      like:
  947. -      then ``-c4'', ``+repcount=4'', ``+count=4'', ``+rep-
  948. -      count 4'',    and ``+count 4'' will all have the same    effect.
  949. -      The long option names for ``-?'' in the default argument
  950. -      descriptor    are ``+help'' and ``+?'' (respectively). In addi-
  951. -      tion, ``++'' may be used to indicate the end of options so
  952. -      that all remaining    arguments will be interpreted as posi-
  953. -      tional parameters (even if    one begins with    a `+' or a `-').
  954. - Page 15
  955. - PARSEARGS(3)                         PARSEARGS(3)
  956. -      Under MS-DOS, and OS/2, an    argument to a long-option must be
  957. -      separated from the    long option by an equal    sign (`=')
  958. -      (unless the first character of $SWITCHAR is a `-',    in which
  959. -      case UNIX syntax is used).     The long option names for ``/?''
  960. -      in    the default argument descriptor    are ``/help'' and ``/?''
  961. -      (respectively).
  962. -      Under VAX/VMS and AmigaDOS, single-character options are not
  963. -      used and the ``long'' name    (in the    prompt field of    an argu-
  964. -      ment descriptor) is always    used to    match for possible argu-
  965. -      ments (or keywords, or qualifiers).
  966. -      For all supported operating systems, a long option    may be
  967. -      matched in    one of two ways: it may    match all uppercase char-
  968. -      acters in the prompt field, or it may match all characters
  969. -      in    the prompt field (as in    ``+count=4'' and ``+rep-
  970. -      count=4'').
  971. -      Under all systems except AmigaDOS,    only the number    of char-
  972. -      acters required to    uniquely identify the desired argument
  973. -      are needed, but at    least two characters must be given
  974. -      (unless the prompt    field is itself    less than two characters
  975. -      long). This means that using the above example, that
  976. -      ``+rep=4''    and ``+cou=4'' would also work but ``+c=4'' would
  977. -      NOT (in other words, if you only want to use one character,
  978. -      use ``-c4'' instead).
  979. -      Under VAX/VMS, the    possibilities using the    above example
  980. -      would be:    ``/REPCOUNT=4'', ``/COUNT=4'', ``/REP=4'', and
  981. -      ``/COU=4'',
  982. -      Under AmigaDOS, no    ``shortened'' keywords are accepted and
  983. -      the possibilities using the above example would be:  ``REP-
  984. -      COUNT 4'',    and ``COUNT 4''
  985. - RETURN VALUE
  986. -      The functions in the parseargs library will return    a value
  987. -      of    zero upon succesful completion.    They may however, return
  988. -      any of the    following status codes (which are defined in
  989. -      <parseargs.h>):
  990. -      pe_SYSTEM
  991. -       A system error occurred. The global variable errno may
  992. -       indicate the problem (then again, it may not).
  993. -      pe_SUCCESS
  994. -       Success, no errors encountered (zero is returned).
  995. -      pe_SYNTAX
  996. -       A command-line syntax    error was encountered
  997. -      pe_DEFARGS
  998. - Page 16
  999. - PARSEARGS(3)                         PARSEARGS(3)
  1000. -       An attempt (using parsecntl) was made    to change the
  1001. -       default arg-search list of a command to point    to an
  1002. -       argdesc-array    which already has the given command on
  1003. -       its default arg-search list (which would cause an
  1004. -       infinite loop    when attempting    to match an unknown
  1005. -       command-line argument).
  1006. -      pe_NOMATCH
  1007. -       Unable to match the named argument. This occurs when
  1008. -       the argument keyword name passed to parsecntl    (using
  1009. -       the pc_ARGFLAGS functions code) was found in the given
  1010. -       argdesc-array    or in its default-list.
  1011. -      pe_BADMODE
  1012. -       Bad mode for given command in    parsecntl. This    occurs
  1013. -       when pc_WRITE    or pc_RDWR mode    is passed to parsecntl in
  1014. -       conjunction with the pc_ARGFLAGS functions code.  Par-
  1015. -       secntl will not modify existing arguments.
  1016. -      pe_BADCNTL
  1017. -       Bad command for parsecntl. This occurs if an unknown
  1018. -       function-code    was passed to parsecntl.
  1019. - SIDE EFFECTS
  1020. -      Each of the functions in the parseargs library will set the
  1021. -      external character    string ProgName    to be the name of the
  1022. -      last command that was operated upon by any    of the library
  1023. -      routines.
  1024. -      When an argument-descriptor array is first    encountered by
  1025. -      any of the    parseargs library routines, it is initially com-
  1026. -      piled into    an intermediate    form that is more convenient to
  1027. -      manipulate. As a direct result, it    is not advisable to
  1028. -      attempt to    index directly into the    array to manipulate one
  1029. -      of    the argument descriptors (because the argdesc that you
  1030. -      thought was there may actually be somewhere else).    After the
  1031. -      array has been given its initial value(s),    only parsecntl(3)
  1032. -      should be used to manipulate or query the attributes of an
  1033. -      argument descriptor.
  1034. - DOCUMENTING YOUR COMMANDS
  1035. -      The commands that you write with parseargs(3) may be docu-
  1036. -      mented using parseargs(1).    Just copy the argument descriptor
  1037. -      array into    a separate file, and invoke parseargs(1) with the
  1038. -      -M    option and pass    it the command-name (dont forget to
  1039. -      redirect input to come from your newly created file). It is
  1040. -      important to note that the    only portion of    that argdesc
  1041. -      array to insert into your file is the portion starting with
  1042. -      the very first command-line argument, all the way down to
  1043. -      (and including) the ENDOFARGS or END_ARGUMENTS entry.
  1044. - Page 17
  1045. - PARSEARGS(3)                         PARSEARGS(3)
  1046. - FILES
  1047. -      /usr/local/lib/libparse.a
  1048. -       Link library for parseargs.
  1049. -      /usr/local/include/parseargs.h
  1050. -       Include file for parseargs.
  1051. -      /usr/local/include/useful.h
  1052. -       Include file for portability.
  1053. - SEE ALSO
  1054. -      argtype(3), parseargs(1), parsecntl(3)
  1055. -      The ``C Advisor'' column in UNIX Review Vol. 7 No.    11.
  1056. - CAVEATS
  1057. -      Because of    the way    argument parsing is implemented    under
  1058. -      UNIX, MS-DOS, and OS/2, option arguments which contain a
  1059. -      leading dash (`-')    (or whatever the option    prefix character
  1060. -      is    defined    to be) may not be specified as a separate argu-
  1061. -      ment on the command line, it must be part of the same argu-
  1062. -      ment. That    is to say that if a program has    a -f option that
  1063. -      requires a    string argument, then the following:
  1064. -       -f-arg
  1065. -      will properly assign the string ``-arg'' to the option
  1066. -      whereas the following:
  1067. -       -f -arg
  1068. -      will be interpreted by parseargs as two option strings: the
  1069. -      first of which (``-f'') is    missing    a required argument and
  1070. -      the second    of which (``-arg'') will most likely be    flagged
  1071. -      as    an invalid option.
  1072. -      Similarly,    if the user requires an    ARGLIST    option to take
  1073. -      multiple arguments    with leading dashes then the following
  1074. -      method must be used: It is    a ``feature'' of parseargs that
  1075. -      ARGLIST arguments are always appended to the current list of
  1076. -      arguments for the given option. Thus, if ``-f'' is    an option
  1077. -      taking a list of arguments, then the following are    all
  1078. -      equivalent:
  1079. -       -farg1 arg2
  1080. -       -f arg1 arg2
  1081. -       -farg1 -farg2
  1082. -       -f arg1 -f arg2
  1083. -      Hence multiple ``leading dash'' arguments may specified as
  1084. -      follows:
  1085. -       -f-dash_arg1 -f-dash_arg2  ...
  1086. - Page 18
  1087. - PARSEARGS(3)                         PARSEARGS(3)
  1088. - BUGS
  1089. -      When a non-multivalued argument appears more than once on
  1090. -      the command-line then only    the last value supplied    is used.
  1091. -      A problem occurs however in the following scenario: suppose
  1092. -      `-s' is an    option that takes an optional string argument
  1093. -      (and suppose `-x' is some boolean flag). Then if the follow-
  1094. -      ing command-line is issued:
  1095. -       command  -s string  -x  -s
  1096. -      then, the argument    flags will properly correspond to the
  1097. -      second instance of    the `-s' option    (namely    ARGGIVEN will be
  1098. -      set but ARGVALGIVEN will be unset)    but the    value associated
  1099. -      with the option will be ``string''    (because the first
  1100. -      instance overwrote    the default).  Because of this,    it may be
  1101. -      safest to reassign    the default value if ARGGIVEN is set but
  1102. -      ARGVALGIVEN is unset.
  1103. - AUTHOR
  1104. -      Eric Allman, University of    California, Berkeley
  1105. - MODIFICATIONS
  1106. -      Modified to accept    a vector of arguments, better error mes-
  1107. -      sages, Unix keyword matching, and AmigaDOS    version    by Peter
  1108. -      da    Silva.
  1109. -      Rewritten by Brad Appleton.  Parseargs(1);    functions par-
  1110. -      secntl, sparseargs, fparseargs, lparseargs, and vparseargs;
  1111. -      argument types argUsage, argDummy,    argUBool, and argTBool;
  1112. -      argument flags ARGPOS, ARGVALOPT, ARGVALREQ, ARGVALGIVEN,
  1113. -      ARGNOVAL, and ARGVEC; and VAX/VMS version and IBM-PC version
  1114. -      by    Brad Appleton
  1115. - Page 19
  1116. --- 0 ----
  1117. diff -cNr ../patchlevel4/parsecntl3.txt ./parsecntl3.txt
  1118. *** ../patchlevel4/parsecntl3.txt    Thu May  2 11:06:46 1991
  1119. --- ./parsecntl3.txt    Wed Dec 31 18:00:00 1969
  1120. ***************
  1121. *** 1,594 ****
  1122. - PARSECNTL(3)                         PARSECNTL(3)
  1123. - NAME
  1124. -      parsecntl - get and set attributes    of an argument descriptor
  1125. -      array
  1126. - SYNOPSIS
  1127. -      #include <parseargs.h>
  1128. -      int  parsecntl( ARGDESC argd[],  parsecntl_t func,     parsemode_t mode,  ...    );
  1129. - DESCRIPTION
  1130. -      Parsecntl will read and/or    write the desired attributes of
  1131. -      the given command-object. The attributes to be operated upon
  1132. -      are specified by the second parameter to parsecntl. The
  1133. -      desired mode (read, write,    or both) are specified by the
  1134. -      third parameter to    parsecntl. If the operation to be per-
  1135. -      formed is pc_ARGFLAGS, then the fourth argument to    parsecntl
  1136. -      should be the keyword name    of the argument    whose flags are
  1137. -      to    be retrieved.  The last    parameter to parsecntl is always
  1138. -      the object    to contain the attribute(s) to be read/written.
  1139. -      If    the attribute(s) are to    be read    (regardless of whether or
  1140. -      not they are also being changed) then the last argument
  1141. -      should be a pointer to an object, otherwise the last argu-
  1142. SHAR_EOF
  1143. true || echo 'restore of PATCH05 failed'
  1144. fi
  1145. echo 'End of  part 4'
  1146. echo 'File PATCH05 is continued in part 5'
  1147. echo 5 > _shar_seq_.tmp
  1148. exit 0
  1149. exit 0 # Just in case...
  1150. -- 
  1151. Kent Landfield                   INTERNET: kent@sparky.IMD.Sterling.COM
  1152. Sterling Software, IMD           UUCP:     uunet!sparky!kent
  1153. Phone:    (402) 291-8300         FAX:      (402) 291-4362
  1154. Please send comp.sources.misc-related mail to kent@uunet.uu.net.
  1155.