home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / misc / volume29 / parsearg / part01 < prev    next >
Encoding:
Text File  |  1992-05-18  |  83.8 KB  |  2,015 lines

  1. Newsgroups: comp.sources.misc
  2. From: brad@hcx1.ssd.csd.harris.com (Brad Appleton)
  3. Subject:  v29i116:  parseargs - functions to parse command line arguments, Part01/10
  4. Message-ID: <1992May17.182221.28490@sparky.imd.sterling.com>
  5. X-Md4-Signature: d30d5f3b7ec44dc723b06665f9923280
  6. Date: Sun, 17 May 1992 18:22:21 GMT
  7. Approved: kent@sparky.imd.sterling.com
  8.  
  9. Submitted-by: brad@hcx1.ssd.csd.harris.com (Brad Appleton)
  10. Posting-number: Volume 29, Issue 116
  11. Archive-name: parseargs/part01
  12. Environment: UNIX, VMS, MS-DOS, OS/2, Amiga
  13. Supersedes: parseargs: Volume 17, Issue 46-57
  14.  
  15. #! /bin/sh
  16. # This is a shell archive.  Remove anything before this line, then unpack
  17. # it by saving it into a file and typing "sh file".  To overwrite existing
  18. # files, type "sh file -c".  You can also feed this as standard input via
  19. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  20. # will see the following message at the end:
  21. #        "End of archive 1 (of 10)."
  22. # Contents:  MANIFEST README doc doc/argvalopt.inc doc/caveats.inc
  23. #   doc/cmd_macros.inc doc/defargs.inc doc/effects.inc
  24. #   doc/fparseargs3.inc doc/lib_bugs.inc doc/lparseargs3.inc
  25. #   doc/parseargs1.inc doc/parseargs3.inc doc/parsecntl.man3
  26. #   doc/parsecntl3.inc doc/parsemodes.inc doc/sparseargs3.inc
  27. #   doc/usage3.inc doc/vparseargs3.inc exit_codes.h pgopen.h test.pl
  28. #   test.rc test.sh test.tcl
  29. # Wrapped by brad@hcx1 on Thu May  7 12:12:13 1992
  30. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  31. if test -f 'MANIFEST' -a "${1}" != "-c" ; then 
  32.   echo shar: Will not clobber existing file \"'MANIFEST'\"
  33. else
  34. echo shar: Extracting \"'MANIFEST'\" \(4410 characters\)
  35. sed "s/^X//" >'MANIFEST' <<'END_OF_FILE'
  36. X   File Name        Archive #    Description
  37. X-----------------------------------------------------------
  38. X Intro                      2    Introduction to parseargs
  39. X MANIFEST                   1    This file
  40. X Makefile                   2    makefile for parseargs library
  41. X README                     1    release information
  42. X VMSbuild.com               2    VMS makefile for the parseargs library
  43. X amiga_args.c               5    parse AmigaDOS command-lines
  44. X arglist.c                  3    implement the listXxxx functions for arglists
  45. X argtype.c                  5    implement the argXxxx argument type functions
  46. X doc                        1    directory containing documentation
  47. X doc/Makefile               2    makefile for the documentation
  48. X doc/arg_macros.inc         2    describe arg-xxx and ARG_XXX macros
  49. X doc/argdesc.inc            2    describe an ARGDESC structure
  50. X doc/argflags.inc           2    describe argument flags
  51. X doc/argtype.man3           3    {n,t}roff source for argtype(3)
  52. X doc/argvalopt.inc          1    describe options with optional arguments
  53. X doc/bugs.inc               2    BUGS section for parseargs(1)
  54. X doc/caveats.inc            1    CAVEATS section for parseargs(1) and (3)
  55. X doc/cmd_macros.inc         1    describe CMD_XXX macros
  56. X doc/defargs.inc            1    describe the default argdesc-array
  57. X doc/effects.inc            1    describe the side-effects of parseargs(3)
  58. X doc/env_args.inc           2    describe use of $CMD_ARGS
  59. X doc/env_parse.inc          2    describe use of $PARSECNTL
  60. X doc/env_usage.inc          2    describe use of $USAGECNTL
  61. X doc/fparseargs3.inc        1    describe fparseargs(3)
  62. X doc/lib_bugs.inc           1    BUGS section for parseargs(3)
  63. X doc/lparseargs3.inc        1    describe lparseargs(3)
  64. X doc/multivals.inc          2    describe multivals(3)
  65. X doc/parseargs.man1         4    {n,t}roff source for parseargs(1)
  66. X doc/parseargs.man3         4    {n,t}roff source for parseargs(3)
  67. X doc/parseargs1.inc         1    describe parseargs(1)
  68. X doc/parseargs3.inc         1    describe parseargs(3)
  69. X doc/parsecntl.man3         1    {n,t}roff source for parsecntl(3)
  70. X doc/parsecntl3.inc         1    describe parsecntl(3)
  71. X doc/parsecntls.inc         2    describe function-codes for parsecntl(3)
  72. X doc/parseflags.inc         3    describe parse flags
  73. X doc/parsemodes.inc         1    describe modes for parsecntl(3)
  74. X doc/returns.inc            2    describe function return values
  75. X doc/sh_arrays.inc          3    describe handling of shell arrays
  76. X doc/shells.inc             2    describe handling of different shells
  77. X doc/sparseargs3.inc        1    describe sparseargs(3)
  78. X doc/usage3.inc             1    describe usage(3)
  79. X doc/vparseargs3.inc        1    describe vparseargs(3)
  80. X exit_codes.h               1    #defines for arguments to exit(3C)
  81. X ibm_args.c                 6    parse MS-DOS and OS/2 command-lines
  82. X parseargs.awk              3    parseargs for awk
  83. X parseargs.c               10    C source for parseargs(1)
  84. X parseargs.h                8    include file for parseargs library
  85. X parseargs.pl               2    parseargs for perl
  86. X parseargs.tcl              2    parseargs for tcl
  87. X patchlevel.h               3    list of patches (most recent first)
  88. X pgopen.c                   4    pipe output to a pager
  89. X pgopen.h                   1    include file for pgopen.c
  90. X stest.c                    4    test program for parseargs(3)
  91. X strfuncs.c                 7    string library
  92. X strfuncs.h                 2    include file for strfuncs.c
  93. X syserr.c                   3    diagnostic message printing routines
  94. X test.awk                   3    awk test program for parseargs(1)
  95. X test.csh                   2    C-shell test program for parseargs(1)
  96. X test.ksh                   2    Korn shell test program for parseargs(1)
  97. X test.pl                    1    perl test program for parseargs(1)
  98. X test.rc                    1    Plan 9 shell test program for parseargs(1)
  99. X test.sh                    1    Bourne shell test program for parseargs(1)
  100. X test.tcl                   1    tcl test program for parseargs(1)
  101. X test.zsh                   2    Z shell test program for parseargs(1)
  102. X unix_args.c                5    parse Unix command-lines
  103. X unix_man.c                 4    print Unix manual-page templates
  104. X useful.h                   4    common include file for the library
  105. X vms_args.c                 6    parse VAX/VMS DCL command-lines
  106. X vprintf.c                  3    portable vfprintf, vprintf, and vsprintf
  107. X winsize.c                  3    determine # rows and # columns of window
  108. X xparse.c                   9    implement the parseargs library
  109. END_OF_FILE
  110. if test 4410 -ne `wc -c <'MANIFEST'`; then
  111.     echo shar: \"'MANIFEST'\" unpacked with wrong size!
  112. fi
  113. # end of 'MANIFEST'
  114. fi
  115. if test -f 'README' -a "${1}" != "-c" ; then 
  116.   echo shar: Will not clobber existing file \"'README'\"
  117. else
  118. echo shar: Extracting \"'README'\" \(41528 characters\)
  119. sed "s/^X//" >'README' <<'END_OF_FILE'
  120. X
  121. X
  122. X
  123. X                                   PARSEARGS
  124. X
  125. X                          extracted from Eric Allman's
  126. X
  127. X                             NIFTY UTILITY LIBRARY
  128. X
  129. X                                 Eric P. Allman
  130. X                            University of California
  131. X                              Berkeley, California
  132. X                               eric@Berkeley.EDU
  133. X
  134. X                                modifications by
  135. X
  136. X                                 Peter da Silva
  137. X                  Ferranti International Controls Corporation
  138. X                               Sugar Land, Texas
  139. X                               peter@ferranti.com
  140. X
  141. X                          modified and rewritten by
  142. X
  143. X                                 Brad Appleton
  144. X                 Harris Corporation, Computer Systems Division
  145. X                         Fort Lauderdale, Florida USA
  146. X                            brad@ssd.csd.harris.com
  147. X
  148. X
  149. X
  150. X SUMMARY
  151. X =======
  152. X This directory contains a subset of a utility library that I have used
  153. X (in various forms) for several years now. This particular version is
  154. X rather sparse, being a relatively recent reimplementation.
  155. X
  156. X [ The rest of the utility library has been left out, to reduce the
  157. X size of Parseargs. The complete set of utilities was pubbed in the
  158. X first comp.sources.misc distribution. -- PDS ]
  159. X
  160. X I am making this available as a  result of the rather surprising
  161. X response to my C  Advisor column in UNIX Review Vol. 7 No. 11 on
  162. X argument parsing, in which I  described an alternative to getopt.
  163. X Several dozen people have asked for the source code -- an amazing
  164. X number, considering that in the four years prior to this column, I
  165. X have gotten perhaps six letters in total.
  166. X
  167. X
  168. X COPY/REUSE POLICY
  169. X =================
  170. X Permission is hereby granted to freely copy and redistribute this
  171. X software, provided that the author is clearly credited in all copies
  172. X and derivations. Neither the name of the author nor that of the
  173. X University may be used to endorse or promote products derived from
  174. X this software without specific written permission. This software is
  175. X provided ``As Is'' and without any express or implied warranties.
  176. X
  177. X
  178. X CONTENTS
  179. X ========
  180. X See the file "MANIFEST" in the distribution for a complete list and
  181. X description of all the files included in this release.
  182. X
  183. X TO DO
  184. X =====
  185. X The parseargs routines really ought to have a way of matching a  list
  186. X (e.g., return the rest of argv). This isn't especially hard to do, but
  187. X I haven't gotten around to it yet. [ Added, with ARGLIST flag -- PDS ]
  188. X
  189. X [ Added argUsage and argDummy pseudo-argument types -- BDA ]
  190. X [ Added arg{S,T,U}Bool boolean argument types -- BDA ]
  191. X [ Added ARGNOVAL argument flag to implement trigger types -- BDA ]
  192. X [ Added ARGVALOPT, ARGVALREQ, and ARGVALGIVEN argument flags to
  193. X   implement options with optional arguments -- BDA ]
  194. X [ Added ARGPOS argument flag to implement arguments that may be
  195. X    matched both positonally and by keyword -- BDA ]
  196. X [ Added ARGVEC for argc/argv structures and implemented them for
  197. X   string, character, floating point, and integer types -- BDA ]
  198. X [ Added fparseargs(3), sparseargs(3), vparseargs(3), lparseargs(3),
  199. X   and parsecntl(3) functions for flexibility and robustness -- BDA ]
  200. X
  201. X
  202. X DISCLAIMERS
  203. X ===========
  204. X I hacked this code up to (hopefully) work on ANSI C  compilers, since
  205. X several readers seem to be interested in this sort of thing. I can't
  206. X claim to have really tested this.
  207. X [ Now compiles under both BSD & AT&T Unix Systems using both ANSI and
  208. X   non-ANSI C compilers -- BDA ]
  209. X [ non-ANSI C compilers that have <stdlib.h> need to explicitly #include
  210. X   <stdlib.h> in useful.h -- BDA ]
  211. X
  212. X The original version was tested under SunOS 4.0 on SPARC
  213. X architectures. The version you see has been loosely tested on a Mips
  214. X M/2000 running RISC/os 4.01; I  have only tried it in the BSD
  215. X environment, and that only loosely.
  216. X
  217. X ACKNOWLEDGEMENTS
  218. X ================
  219. X I wrote the first version of this code while working at the
  220. X International Computer Science Institute in Berkeley, CA.
  221. X
  222. X ______________________________________________________________________________
  223. X
  224. X      Update to parseargs by Peter da Silva (peter@ferranti.com):
  225. X
  226. X (2nd update: more improvements to arg parsing, argChar type)
  227. X (3rd update: return to original calling sequence, argList type)
  228. X (4th update: removed routines not relevant to parseargs,
  229. X              removed tracing/interactive stuff.)
  230. X
  231. X
  232. X Parseargs is a really nifty set of routines, but it doesn't fit too
  233. X well with standard UNIX semantics. In particular, you can get into a
  234. X lot of trouble using it in a script if it drops into interactive mode
  235. X on you. Also, it's not as useful as it could be for non-UNIX systems.
  236. X To make it work better, I've made a couple of changes.
  237. X
  238. X It compiled straight out of the box on System III once I'd provided
  239. X bcopy, bcmp, and strtol. The strtol I've provided is almost totally
  240. X untested, but hopefully you won't need to use it. It's only for folks
  241. X with old UNIX systems.
  242. X
  243. X First change was to disable the interactive prompting for arguments. I
  244. X think that's inconsistent with usual UNIX semantics.
  245. X
  246. X The second change was to allow for a trailing list of arguments. I
  247. X originally implemented this by changing the calling sequence to
  248. X parseargs. On reflection this would just produce incompatibilities, so
  249. X I added a  new flag, ARGLIST, and a new type, listStr. Later, other
  250. X kinds of lists can presumably be added. A list handles a pointer to a
  251. X list of objects:
  252. X
  253. X     struct arglist *fred;
  254. X
  255. X Operations are defined on arglists, L_NEXT(fred) produces the next
  256. X element in fred. L_STRING(fred) produces the value of fred cast to
  257. X "char *".
  258. X
  259. X During evaluation the list is kept in LIFO order, and it's reversed
  260. X just before returning to parseargs. This simplifies the coding of the
  261. X list routines, but still lets you step through the list in a
  262. X reasonable order. [ lists are now maintained in FIFO order --BDA ]
  263. X
  264. X The final change is the addition of a  'argChar' type. This parses
  265. X character arguments (such as the '-T' option to 'awk'), accepting
  266. X single characters,
  267. X
  268. X Parseargs itself no longer uses ckalloc, traceset, funclist, and so
  269. X on. these routines are pretty cool, but when you're grafting parseargs
  270. X onto an existing program they just get in the way. Also, it's possible
  271. X to make parseargs fail in a cleaner fashion by handling out-of-memory
  272. X cases myself. Certainly there's not going to be any loose memory lying
  273. X around to be collected when parseargs starts up!
  274. X
  275. X Also, the error messages have been made a  bit more descriptive.
  276. X Instead of saying "stest: value required for -c flag", it prints
  277. X "stest: RepCount required for -c flag". The ad_prompt element should
  278. X really be a descriptive word that can be used in a sentence... or for
  279. X non_UNIX systems a multi-character or keyword based flag. I have an
  280. X Amiga version included, for example, that uses keyword syntax. In that
  281. X version, the usage message reads:
  282. X
  283. X     Usage: amiga_test <name> [GROUP <newsgroup>]... [REP <repcount>] +
  284. X             [DIR <dirname>] [X] [Y] [Z] [TAB <tabchar>] [<file>]...
  285. X
  286. X Instead of:
  287. X
  288. X     Usage: unix_test <Name> [-n <newsGROUP>]... [-c <REPcount>] [-d <DIRname>] [-x] [-y] [-z] [-t <TABchar>] [<File>]...
  289. X
  290. X
  291. X This would solve the old problem of UNIX programs sticking out like a
  292. X sore thumb in other operating systems.
  293. X
  294. X The Amiga version still needs to prompt for options if called with a
  295. X single types and finally integrate CLI and Workbench environments.
  296. X
  297. X Latest update: the prompt string may include a more extensive comment
  298. X (in parentheses, after the one-word initial comment), that will be
  299. X used in error messages and listed in the usage message.
  300. X
  301. X [ comment may appear in square brackets, curly braces, angle brackets,
  302. X   or parentheses (so one can use the other 3 in the comment) -- BDA ]
  303. X
  304. X The environment variable USAGE controls the printing of the usage
  305. X message:
  306. X
  307. X     USAGE == -1 No usage message.
  308. X     USAGE == 0 Short message (default).
  309. X     USAGE == 1 Names of flags given in parentheses.
  310. X     USAGE == 2 Long description of options given.
  311. X     USAGE == 3 Both flag names and long description given.
  312. X
  313. X Examples:
  314. X
  315. X     $ USAGE=3; export USAGE
  316. X     $ unix_test -c
  317. X     unix_test: REPcount (number of times to repeat each group) required for -c flag
  318. X     unix_test: Name required
  319. X     Usage: unix_test <Name> [-n <newsGROUP>]... [-c <REPcount>] [-d <DIRname>] [-x] (Xflag) [-y] (Yflag) [-z] (Zflag) [-t <TABchar>] [<File>]...
  320. X     Options:
  321. X             -n newsGROUP newsgroups to test
  322. X             -c REPcount number of times to repeat each group
  323. X             -x (Xflag) expand in X direction
  324. X             -y (Yflag) expand in Y direction
  325. X             -z (Zflag) expand in Z direction
  326. X     $ USAGE=0; export USAGE
  327. X     $ unix_test
  328. X     unix_test: Name required
  329. X     Usage: unix_test <Name> [-n <newsGROUP>]... [-c <REPcount>] [-d <DIRname>] [-x] [-y] [-z] [-t <TABchar>] [<File>]...
  330. X     $ USAGE=-1; export USAGE
  331. X     $ unix_test
  332. X     unix_test: Name required
  333. X
  334. X
  335. X [ changed to use the environment variable USAGECNTL instead of USAGE.
  336. X   "USAGE" is a variable name commonly used in shell scripts. --BDA ]
  337. X
  338. X [ when keywords are desired (via USAGECNTL) their actual command-line
  339. X   syntax is now displayed (instead of just appearing in parentheses)
  340. X   -- BDA ]
  341. X
  342. X ______________________________________________________________________________
  343. X
  344. X
  345. X             Update to parseargs (and major re-write) by Brad Appleton
  346. X                        (brad@ssd.csd.harris.com)
  347. X                              Last Update: 08/15/91
  348. X
  349. X THIS RELEASE
  350. X ============
  351. X Read the file patchlevel.h in the distribution to find out what version
  352. X and patchlevel of parseargs you have received.
  353. X
  354. X
  355. X DISCLAIMER
  356. X ==========
  357. X Neither Brad Appleton, nor Harris Corporation (including any of its
  358. X subsidiaries and subdivisions and Harris Computer Systems Division in
  359. X particular) are responsible for maintaining and supporting this
  360. X software or for any consequences resulting from the use of this
  361. X software, no matter how awful, even if they arise from flaws in the
  362. X software.
  363. X
  364. X
  365. X NEW FILES: parseargs.c, xparse.c, pgopen.[ch], vprintf.c
  366. X ========================================================
  367. X I thought parseargs was so cool that I wanted to be able to use it for
  368. X shell-scripts too! To do that I would need a command-line interface.
  369. X I decided to make the command-line interface look as close as possible
  370. X to the C-interface so I  basically implemented a  very small
  371. X interpreter; Hence, parseargs.c was resurrected but this time as an
  372. X interface to the parseargs library instead of being the guts of it.
  373. X
  374. X Xparse.c implements routines to parse arguments from a   file
  375. X (fparseargs), from an arglist (lparseargs), from a  string
  376. X (sparseargs), from a variable argument-list (vparseargs), and from a
  377. X string-vector (parseargs). It also contains the routine parsecntl()
  378. X which controls the parsing behavior of a  commands, and the routine
  379. X usage() which prints a usage message. Each of the <os>_args.c files
  380. X used to implement its own parseargs() and usage() functions, this has
  381. X been changed so that parseargs() and usage() are implemented in
  382. X xparse.c and the guts of the os-specific parsing and formatting is
  383. X implemented in the routines <os>_parse() and <os>_usage() in the file
  384. X <os>_args.c!
  385. X
  386. X On Unix systems, if the user desires, usage messages are paged using
  387. X popen(3S). The pager used is ${USAGE_PAGER:-${PAGER:-/usr/ucb/more}}.
  388. X If for some reason this fails then no paging is performed. The pager
  389. X library is implemented in the file pgopen.c and only used if the macro
  390. X USE_PAGER is #defined. Pgopen.h is an include file which will include
  391. X the external declarations for pgopen.c if USE_PAGER is #defined and
  392. X defines some functionally equivalent (but non-paging) macros instead.
  393. X
  394. X The file vprintf.c is a  portable implementation of vprintf(),
  395. X vfprintf(), and vsprintf() for systems (such as BSD Unix) that don't
  396. X already have them.
  397. X
  398. X
  399. X NEW ARGUMENT TYPES: argUsage, arg[UTS]Bool, & argDummy
  400. X ======================================================
  401. X I added the following argument types to parseargs:
  402. X
  403. X    argUsage -- print a usage message
  404. X    argDummy -- dummy argument, not parsed but used for messages
  405. X    argSBool -- set a boolean flag
  406. X    argTBool -- toggle a boolean flag
  407. X    argUBool -- unset a boolean flag
  408. X
  409. X Consult the manual page for argtype(3) for more information.
  410. X I also added the capability to handle ARGVEC arguments into the
  411. X remaining argument type functions.
  412. X
  413. X
  414. X NEW ARGUMENT FLAGS:
  415. X ===================
  416. X I added the following argument flags to parseargs:
  417. X
  418. X     ARGPOS -- arg is positionally matched and keyword matched
  419. X     ARGNOVAL -- arg takes no value
  420. X     ARGVALOPT -- arg takes an optional value
  421. X     ARGVALREQ -- arg requires a value
  422. X     ARGGIVEN -- arg was supplied on command-line
  423. X     ARGVALGIVEN -- arg-value was supplied on command-line
  424. X     ARGDESCRIBED -- argument was given a description
  425. X     ARGKEYWORD -- argument was matched as a keyword
  426. X     ARGVALSEP -- arg-value was in a separate token from the argument
  427. X
  428. X Consult the manual page for parseargs(1) & parseargs(3) for more information.
  429. X
  430. X
  431. X NEW INTERFACE
  432. X =============
  433. X I added a set of Macros to allow a more "self documenting" approach to
  434. X declaring argument-descriptor arrays. The "old-style" is still
  435. X accepted (but if used it is recommended that the STARTOFARGS macro is
  436. X used in conjunction with ENDOFARGS). The new style is documented in the
  437. X parseargs(3) manual under the heading "CMD MACROS"
  438. X
  439. X
  440. X MODIFICATIONS TO USAGE MESSAGES
  441. X ===============================
  442. X After Peter modified usage() to look at the USAGE environment
  443. X variable, I decided that, even if the user had turned USAGE off, that
  444. X (s)he really did want the usage if an argUsage option was specified so
  445. X I added a  static global Usage_Requested to xparse.c to over-ride
  446. X the USAGE variable (if necessary) so that a verbose message is always
  447. X given when an argUsage option is specified (regardless of the value in
  448. X the environment variable).
  449. X
  450. X I also changed the name of the environment variable that gets "looked"
  451. X up to be USAGECNTL instead of USAGE since USAGE is a common variable
  452. X name for shell scripts. Furthermore, I changed the contents of USAGECNTL
  453. X from a number to a sequence of mnemonic strings (for better readability).
  454. X I also made USAGECNTL control whether or not a command-description is
  455. X printed and whether or not the message is piped to a pager on Unix.
  456. X
  457. X Under VMS, the global symbol USAGECNTL is used in lieu of an environment
  458. X variable.  See the parseargs(3) and parseargs(1) manual pages for more
  459. X information regarding USAGECNTL.
  460. X
  461. X
  462. X SPECIFYING ALTERNATE PARSING BEHAVIOR
  463. X =====================================
  464. X Parseargs provides 3 methods for controlling "how" the command-line is
  465. X parsed. There is a parsecntl() function which may be used to specify
  466. X flags other than the default parse-behavior. The user may define the
  467. X environment variable (or global symbol) PARSECNTL to contain the option-
  468. X string that corresponds to the desired combination of pa_XXXX flags
  469. X #defined in parseargs.h. The parseargs command, also allows for options
  470. X to specify certain parsing behavior. The parsecntl() function provides
  471. X finer control than either of the other two methods. The user's PARSECNTL
  472. X variable will always over-ride any conflicting flags that were set by
  473. X parsecntl() or by the parseargs command via command-line options.
  474. X See the manual pages for parseargs(1), parseargs(3), and parsecntl(3)
  475. X for more information.
  476. X
  477. X
  478. X GIVING DEFAULT ARGUMENTS
  479. X ========================
  480. X Programs that use parseargs may be given default arguments under UNIX
  481. X and PCs through the use of environment variables (symbols are used for
  482. X VMS systems). If a C-program or a shell-script uses parseargs to imple-
  483. X -ment a command named "foo" then the environment variable (or global
  484. X symbol) FOO_ARGS will be parsed for any "default" arguments before argv
  485. X is parsed.  Argv will over-ride any options that are specified in
  486. X FOO_ARGS (except that ARGLISTs and ARGVECs set in FOO_ARGS will be
  487. X appended from argv[]).
  488. X
  489. X
  490. X SPECIFYING DEFAULT ARGDESCs TO SEARCH
  491. X =====================================
  492. X If a given option/qualifier does not appear to match any items in the
  493. X argdesc-array, a  default argdesc-array is then searched to match the
  494. X option. If it is STILL unmatched then it is flagged as such. The
  495. X default-argdesc array is automatically used by all programmer-defined
  496. X argdesc-array but may be unset or reset using the pc_DEFARGS function
  497. X of parsecntl(3).
  498. X
  499. X
  500. X ADDING NEW SHELLS TO parseargs(1)
  501. X =================================
  502. X I did my best to implement parseargs.c in a manner that would make it
  503. X relatively easy to add new shell-types. At this point in time, parseargs
  504. X will generate output for the following command-interpreters:
  505. X
  506. X     sh               (Bourne Shell)
  507. X     csh/tcsh/itcsh   (C-Shell)
  508. X     bash             (Bourne-Again Shell)
  509. X     ksh              (Korn Shell)
  510. X     rc               (Plan 9 Shell)
  511. X     zsh              (Z shell)
  512. X     perl
  513. X     tcl
  514. X     ash
  515. X     awk
  516. X
  517. X Parseargs.c thinks the Free Software Foundation's Bourne-Again Shell
  518. X (bash) is equivalent to the Bourne shell (sh). Bash is a superset of
  519. X sh (so I am told) but I do not know enough about it to treat it
  520. X differently. I  hope someone who is familiar with bash syntax will
  521. X correct this deficiency (particularly with shell arrays).
  522. X
  523. X If someone wants to try to add more shell-types to parseargs.c, here
  524. X are the main things that need to be done:
  525. X
  526. X 1. add an entry for the shell type into the type definition for the
  527. X    "shell_t" enumerated type.
  528. X
  529. X 2. add a shell_info entry for the shell into the array Shell[].
  530. X
  531. X 3. print_args doesnt really do any shell specific stuff outside of
  532. X    indexing into the table. The print_arglist() function does some
  533. X    shell specific stuff and MAY need a case added to the switch statement(s)
  534. X    for the newly added shell.
  535. X
  536. X 4. If the information in the shell-info structure is not sufficient
  537. X    for the new shell then you should either:
  538. X       a) redefine the structure for all shells including your shell.
  539. X       b) add some special code into print_args() for your shell!
  540. X
  541. X For a more thorough discussion of parseargs(1), consult the manual pages!
  542. X
  543. X
  544. X MODIFICATIONS TO KEYWORD MATCHING
  545. X =================================
  546. X I changed keyword matching in strfuncs.c just a tad by allowing only a
  547. X partial match on the keyword (instead of a full match), this way the
  548. X user only needs to give enough of the keyword on the command line so
  549. X that it will uniquely match a  suffix of a  keyword in the arg-
  550. X descriptor table. A drawback to this is that if the user does NOT
  551. X specify enough of the keyword to uniquely match ONE arg-desc entry,
  552. X then the first such entry encountered will be considered to match the
  553. X partial keyword on the command-line.
  554. X
  555. X This "shortest-prefix" matching is performed 1st on only the uppercase
  556. X characters in the ad_prompt, and then (if no match) on the whole
  557. X prompt. This is "nice" in that the user only needs to specify the
  558. X shortest prefix but it also means that a typo can very easily be
  559. X interpreted as an option when it shouldnt be (both "+new" and "+gr"
  560. X would match "newsGROUPS") or the wrong option may be matched if too
  561. X small a portion of the keyword is provided.
  562. X
  563. X To help prevent this type of thing... Unless the keyword to be matched
  564. X has length < 2, I force the user to specify at least 2 characters for
  565. X the keyword (for VAX/VMS this minimum length becomes 4 iff the keyword
  566. X starts with "NO").
  567. X
  568. X amiga_args.c still uses the old keyword matching function. Since
  569. X AmigaDOS keywords have no '/' or '-' prefix -- I thought it would be
  570. X too dangerous to allow such "partial matching" because it would be too
  571. X easy for bona-fide arguments to partially match a keyword!
  572. X
  573. X
  574. X MODIFICATIONS TO CHARACTER ARGTYPES
  575. X ===================================
  576. X Under UNIX, an argChar option argument may now be provided on the
  577. X command-line immediately following the option-letter and the
  578. X characters following the character argument are still processed as
  579. X options. Hence, if '-c' is an argChar option and '-x', '-y', and '-z'
  580. X are boolean options, then we may specify the character '_' as an
  581. X argument to '-c' as well as specifying the '-x', '-y' and '-z' flags
  582. X in the following manner:
  583. X
  584. X     -c_xyz
  585. X
  586. X Of course, the following will have the same effect:
  587. X
  588. X     -c_ -xyz
  589. X
  590. X as will this:
  591. X
  592. X     -c _ -xyz
  593. X
  594. X but the following is incorrect:
  595. X
  596. X     -c _xyz
  597. X
  598. X In other words, only the character that immediately follows an argChar
  599. X option is considered to be an argument to the option and other option
  600. X characters may immediately precede the single-character argument.
  601. X
  602. X
  603. X MODIFICATIONS TO BOOLEAN ARGTYPES
  604. X =================================
  605. X Boolean types may now take an argument if so desired. under VAX/VMS:
  606. X
  607. X     "/FLAG" (1)
  608. X
  609. X will turn ON an an argBool or argSBool flag, will turn OFF an argUBool
  610. X flag, and will toggle an argTBool flag. However, the following:
  611. X
  612. X     "/FLAG=ON" (2)
  613. X
  614. X will turn ON the flag regardless of whether it is argBool, argSBool,
  615. X argUBool, or argTBool (so long as it is one of them). Similarly,
  616. X
  617. X     "/FLAG=OFF" (3)
  618. X
  619. X will always turn a boolean flag OFF!
  620. X
  621. X Similar syntax is used for AmigaDOS, the corresponding Amiga
  622. X specification for examples (1)-(3) above would be:
  623. X
  624. X     FLAG (1)
  625. X     FLAG=ON (2)
  626. X     FLAG=OFF (3)
  627. X
  628. X For the Amiga, the boolean argument MUST be part of the same argv[]
  629. X element as the keyword itself ("FLAG ON" or "FLAG OFF" is not
  630. X acceptable).
  631. X
  632. X For Unix (and IBM-PCs), long option examples of (1)-(3) would be the
  633. X following:
  634. X
  635. X     +flag (1)
  636. X     +flag=on (2)
  637. X     +flag=off (3)
  638. X
  639. X As with the Amiga, the boolean argument ("on" or "off") MUST be part
  640. X of the same argv[] element as the long-option itself.
  641. X
  642. X For single character options under Unix, the corresponding examples
  643. X for (1)-(3) are as follows:
  644. X
  645. X     -f (1)
  646. X     -f+ (2)
  647. X     -f- (3)
  648. X
  649. X As with Unix, the boolean argument ("on" or "off") MUST be part of the
  650. X same argv[] element as the long-option itself.
  651. X
  652. X For single character options under MS-DOS and OS/2, the corresponding
  653. X examples for (1)-(3) are as follows:
  654. X
  655. X     /f (1)
  656. X     /f+ (2)
  657. X     /f- (3)
  658. X
  659. X With single character options, any boolean argument must be a  single
  660. X character and must be in the character immediately following the the
  661. X option character. If the character following the option character is
  662. X NOT one of '-', '+', '0', ment) then the default action will be taken
  663. X (set, clear or toggle depending upon the type of boolean flag) and the
  664. X character immediately following the boolean option is assumed to be
  665. X another option-specification (e.g. -fc4 and -f+c4 are both allowed
  666. X where 'f' is a boolean flag and 'c' is an integer (argInt) flag).
  667. X
  668. X With all supported operating systems, the following arguments may be
  669. X used as Boolean arguments (differences between uppercase/lowercase are
  670. X ignored):
  671. X
  672. X      Arg        Effect
  673. X     =====  ====================
  674. X       ^    Toggles flag (single character options only)
  675. X       ~    Toggles flag (single character options only)
  676. X       1    Sets flag
  677. X       0    Unsets flag
  678. X       +    Sets flag
  679. X       -    Unsets flag
  680. X       T    Sets flag
  681. X       F    Unsets flag
  682. X      YES   Sets flag
  683. X       NO   Unsets flag
  684. X       ON   Sets flag
  685. X      OFF   Unsets flag
  686. X     TRUE   Sets flag
  687. X    FALSE   Unsets flag
  688. X
  689. X With single character options under Unix and IBM-PCs, only '+', '-',
  690. X '0', '1', '^' and '~' may be used.
  691. X
  692. X
  693. X CHANGES TO ARGTYPE RETURN VALUES
  694. X ================================
  695. X In order to allow only a single character to be consumed for arguments
  696. X to boolean and character options, I  had to change the way return
  697. X values from an argtype function were handled. Previously, the argtype
  698. X function merely returned TRUE (1) upon success and FALSE (0) upon
  699. X failure. I changed this slightly. Now, an argument type function
  700. X returns:
  701. X
  702. X     FALSE (0) if the argument was NOT successfully interpreted
  703. X
  704. X     TRUE (1) if the argument was successfully interpreted and ALL
  705. X             characters of the argument were used.
  706. X
  707. X     -N (<0) if the argument was successfully interpreted AND only
  708. X             the first N characters of the argument were used.
  709. X
  710. X At this time, only the Boolean and argChar argument type functions
  711. X return any value other than TRUE or FALSE.
  712. X
  713. X
  714. X NEW ARGUMENT LISTS
  715. X ==================
  716. X Arglists have been enhanced with a new type called arg-vectors (and
  717. X use the ARGVEC flag instead of the ARGLIST flag). Arg-vectors are a
  718. X structure containing an argv/argc pair. There are two macros in
  719. X parseargs.h which are used for arg-vectors. ARGVEC_T may be used to
  720. X declare a vector structure or a vector type; ARGVEC_EMPTY may be used
  721. X to initialize the structure. It is strongly recommended that ARGVEC_T
  722. X be used to declare vector types in a typedef statement (particularly
  723. X if one is using function prototypes) but for those who insist, it may
  724. X be used to directly declare a  structure. An example of both uses (as
  725. X well as an example use of ArgLists) may be found in the documentation.
  726. X
  727. X
  728. X MISCELLANEOUS FIXES/ENHANCEMENTS
  729. X ================================
  730. X unix_args.c did not consider '-' or '+' to be valid arguments unless
  731. X '--' had already been specified. This has been fixed.
  732. X
  733. X The compile-time interactive option seemed to have been removed from
  734. X parseargs so I put it back in and made it a run-time option (that is
  735. X selected using the pa_PROMPT function-code to parsecntl()). I  also
  736. X made it prompt repeatedly for arglists (a blank line ends the list).
  737. X No characters are escaped or trimmed (such as whitespace, quotes, or
  738. X special characters) when a prompted argument is read from the user!
  739. X
  740. X amiga_args.c will now check to see if an argument matches a  keyword
  741. X before assigning it as a keyword argument. If 'STRING' is an argStr
  742. X and 'REP' is an argInt then: "cmd STRING REP=4" will leave string
  743. X without a  value and assign REP to be 4. Previously, this would have
  744. X resulted in assigning the value of optional keyword arguments.
  745. X
  746. X Arglists are no longer stored in LIFO order and then reversed at the
  747. X last minute, they are now always stored in FIFO order (the order given
  748. X on the command-line).
  749. X
  750. X I also provided extensive updating to the manual pages so that they
  751. X now reflect the current capabilities of parseargs!
  752. X
  753. X Since the FSF has decided to change the use of '+' as a long-option prefix
  754. X to '--' (in order to be POSIX conformant), I added some #ifdef POSIX_SOURCE
  755. X code to unix_args.c to use '--' instead of '+' as the long option prefix.
  756. X
  757. X MODIFICATIONS TO parseargs.h
  758. X ============================
  759. X I hacked parseargs.h up a bit so that certain items may be excluded or
  760. X included by #defining certain names before including the file.
  761. X
  762. X If PARSEARGS_PRIVATE is #defined, then various type and macro
  763. X definitions which are specific to the implementation of parseargs (but
  764. X not to its use) are included. This is my hack at C++ friend functions;
  765. X A file declares itself to be a  "friend" by #defining PARSEARGS_PRIVATE
  766. X before #including the file parseargs.h
  767. X
  768. X If PARSEARGS_NEXTERNS is #defined, then the external function declarations
  769. X for the various parseargs functions (parseargs, parsecntl, fparseargs,
  770. X etc ...) are NOT included. This is really only useful to the files that
  771. X actually implement the various parseargs functions.
  772. X
  773. X If PARSEARGS_NARGTYPES is #defined, then the external function
  774. X declarations for the various argtype functions (argInt, argStr,
  775. X listStr, etc ..) are NOT included. This is really only useful to the
  776. X files that actually implement the various argtype functions.
  777. X
  778. X Also, ARGDESC is now a typedef instead of a #define. On the same note,
  779. X arglists may be declared by using the "ArgList" typedef or by using
  780. X the "struct arglist" structure declaration.
  781. X
  782. X
  783. X MODIFICATIONS TO THE ARGDESC ARRAY
  784. X ==================================
  785. X Before I got my hands on it - parseargs had no parsecntl() or means of
  786. X parsing arguments from a file or a string. Any and all arguments to be
  787. X parsed would be handled in a single invocation of parseargs. In order
  788. X to allow arguments to be parsed using multiple passes (which would be
  789. X required if we were to parse arguments in a file for example) I  added
  790. X the notion of parse-flags to modify parsing behavior. Because of this,
  791. X I also required certain local variables to now be static. In order to
  792. X allow parsing for multiple commands - I put the parse-flags and the
  793. X static variables into the argument descriptor array itself. This way -
  794. X each arg-descriptor has its own set of flags and state variables to
  795. X record its own context.
  796. X
  797. X To implement this without changing the existing syntax, I put all this
  798. X stuff into the FIRST & LAST argument descriptors in the array. If an
  799. X argdesc-array is declared using the CMD_XXXXX macros, then this is
  800. X already taken care of. If an argdesc array is used using the old-style
  801. X syntax, ENDOFARGS will now define two arg-descs at the end of the
  802. X array. Parseargs needs to recognize the old syntax and shift each
  803. X element in the array down by one position (creating room for a new one
  804. X at the top). I would have preferred to just swap the first and last
  805. X entries in this case but I have to preserve the original order of any
  806. X positionally-matched parameters! This means that extra pre-processing
  807. X (to shift the array) needs to be performed for argdesc-arrays that are
  808. X declared using the old syntax! To avoid this overhead - users of the
  809. X old syntax could use the pre#defined macro STARTOFARGS and make it the
  810. X first entry in the argdesc-array.
  811. X
  812. X Also, each arg-descriptor is now precompiled so that the argument
  813. X prompt and the argument description are stored in two separate strings
  814. X (the first of which is pointed to by the "ad_prompt" field). This
  815. X avoids the need to constantly write code to "locate" the description
  816. X every time it is desired by the programmer.
  817. X
  818. X In order to ease the use of the various attributes of arg-descriptors,
  819. X (including the argument-prompt and the argument description) a set of
  820. X macros is available for extracting the corresponding attributes of a
  821. X command, or one of its argument entries.  Public macros are documented
  822. X in the manual pages, private ones are listed here:
  823. X
  824. X     cmd_name(Args) -- the given command-name
  825. X     cmd_flags(Args) -- the command parse flags
  826. X     cmd_context(Args) -- pointer to the command-context
  827. X                          (which is stored in the last argument-descriptor)
  828. X     cmd_state(Args) -- the command-state flags
  829. X     cmd_list(Args) -- pointer to currently active arg-list
  830. X     cmd_prev(Args) -- pointer to previously matched arg (Amiga only)
  831. X     cmd_defargs(Args) -- pointer to default argdesc for this command
  832. X     cmd_argv0(Args) -- pointer to argv[0] from command-line
  833. X     cmd_purpose(Args) -- one-line description of command
  834. X     cmd_description(Args) -- multi-line description of command
  835. X
  836. X The cmd_xxx macros are included only if PARSEARGS_PRIVATE is #defined.
  837. X
  838. X Similarly, there are also some macros (some public, some private) to
  839. X query certain attributes of an argument descriptor (or assist in its
  840. X manipulation). The public macros are documented in the manual pages,
  841. X private ones are listed here:
  842. X
  843. X     ARG_isBOOLEAN(ad) -- is this arg an argBool, or an arg[STU]Bool type?
  844. X     ARG_isPSEUDOARG(ad) -- is this arg an argDummy or an argUsage type?
  845. X     ARG_FIRST(argd) -- return the first argument-entry
  846. X     ARG_LAST(argd) -- return the first last-entry
  847. X     ARG_isEND(ad) -- are we at the end of the argument list?
  848. X     ARG_ADVANCE(ad) -- return the next argument entry.
  849. X     ARG_RETREAT(ad) -- return the previous argument entry.
  850. X
  851. X
  852. X These last five macros are for traversing all the entries in the
  853. X argument descriptor array that correspond to actual command-line
  854. X arguments (i.e. the 2nd thru 2nd-to-last entries in the array):
  855. X
  856. X     for ( ad = ARG_FIRST(argd) ; !ARG_isEND(ad) ; ARG_ADVANCE(ad) )  ...
  857. X or
  858. X     for ( ad = ARG_LAST(argd) ; !ARG_isEND(ad) ; ARG_RETREAT(ad) )  ...
  859. X
  860. X
  861. X OPERATING SYSTEM DEPENDENCIES
  862. X =============================
  863. X I also added "-D${os}_style" to the CFLAGS macro used in the Makefile.
  864. X It is used to conditionally include OS dependent code in the parseargs
  865. X files. I tried to keep "#ifdef <os>_style" sections of code to a
  866. X minimum.
  867. X
  868. X I tried to make a distinction between portions of the code that depend
  869. X upon the underlying OS and portions of the code that depend on the
  870. X desired argument parsing style so that - in theory - one could compile
  871. X for any of the existing styles on any of the supported systems. Thus,
  872. X just because "unix_style" is #defined does not necessarily imply that
  873. X the underlying OS is unix. This would only be implied if "unix" was
  874. X #defined.
  875. X
  876. X It is assumed that the following constants are #defined for the
  877. X following operating systems:
  878. X
  879. X        NAME                        OS
  880. X    ------------------   ------------------------
  881. X     unix                Unix (BSD or AT&T)
  882. X     BSD, SYSV           BSD Unix or AT&T Unix (only one should be present)
  883. X     MANX, AZTEC         AmigaDOS
  884. X     MSDOS               MS-DOS for IBM PCs
  885. X     OS2                 OS/2 for IBM PCs
  886. X     vms                 VAX/VMS
  887. X
  888. X As of this writing, as long as the above constants are defined for the
  889. X corresponding OS, parseargs compiles without errors on both BSD and
  890. X AT&T Unix Systems using both ANSI and non-ANSI C Compilers.
  891. X
  892. X NOTE: If you are using the curses library with parseargs and your system's
  893. X       <curses.h> #defined VOID (as it does for the Sun), then you will
  894. X       need to #undef VOID after including <parseargs.h> but before
  895. X       including <curses.h> (or vice-versa).
  896. X
  897. X       Also - if your compiler is NOT an ANSI compiler but does have the
  898. X       #include file named <stdlib.h> then you will need to modify the 
  899. X       file useful.h to explicitly include <stdlib.h>.
  900. X
  901. X
  902. X COMPILE-TIME CONSTANTS
  903. X ======================
  904. X If any of the following macros are #defined at compile time then they will
  905. X have the following effect:
  906. X
  907. X    USE_PAGER    --  For Unix systems only. Parseargs will include the code
  908. X                     which pipes usage messages to a paging program
  909. X
  910. X    NOFLOAT      --  Parseargs will NOT include the code for the predefined
  911. X                     floating point arg-types argFloat() and argDouble().
  912. X
  913. X    SVR4         --  Parseargs(1) with the -M option will generate the new
  914. X                     Style Unix manual template.
  915. X
  916. X    USE_CURSES
  917. X    USE_TERMINFO
  918. X    USE_TERMCAP  --  Parseargs will use curses/terminfo/termcap when trying
  919. X                     to figure out the size of the screen.
  920. X
  921. X    POSIX_SOURCE --  For unix_style only. Parseargs will use '--' instead of
  922. X                     '+' as the long-option prefix.
  923. X
  924. X IBM-PC VERSION OF parseargs(3)
  925. X ==============================
  926. X I also added ibm_args.c for MS-DOS and OS/2.
  927. X
  928. X IBM_ARGS.C HAS NOT BEEN TESTED ON AN IBM-PC! I did not have one to
  929. X test it on.
  930. X
  931. X The ibm-pc version is VERY similar to the unix version. The difference
  932. X is that ibm_args.c will look in $SWITCHAR for the option character(s)
  933. X to use. If the option character is '-', it behaves just like
  934. X unix_args.c, if the option character is something else or $SWITCHAR is
  935. X undefined then it behaves more like normal MS-DOS stuff. The main
  936. X difference is that if the ibm-pc version is NOT emulating unix, than
  937. X all option arguments MUST be in the same argument as the option itself
  938. X and they must be separated by an '=' character (so "/S=str" is fine
  939. X but "/Sstr" and "/S str" are not).
  940. X
  941. X By default, if SWITCHAR is undefined then both the long and short
  942. X option prefix character are '/'. One is able to distinguish an option
  943. X from a long-option in this case because the third character of an
  944. X option-arg will always be '=' or '\0'. Hence, using the test program
  945. X with the defaults, both "ibm_test foo /D=directory" and "ibm_test
  946. X /DIR=directory" are equivalent.
  947. X
  948. X
  949. X VAX/VMS VERSION OF parseargs(3)
  950. X ===============================
  951. X I also added vms_args.c for VAX/VMS.
  952. X
  953. X vms_args.c has been tested by people (other than myself) on a VAX/VMS
  954. X system and seems to work okay. It does not use the CLI$XXXXX routines
  955. X for parsing. It should accept command-line arguments as described in
  956. X the "Grammar Rules" section of the VAX manual with one slight exception
  957. X which is noted below.
  958. X
  959. X ARGLIST and ARGVEC are comma-separated lists in the VMS version of
  960. X parseargs (not whitespace separated lists). In order to preserve a
  961. X one-to-one mapping between UNIX & AmigaDOS whitespace separated lists
  962. X with VMS comma-separated lists, a  VMS ARGLIST or ARGVEC that
  963. X corresponds to a positional parameter may use both commas and white-
  964. X space to separate its arguments. This avoids having VMS command lines
  965. X like the following:
  966. X
  967. X     cmdname file1,file2,file3 directory1,directory2
  968. X
  969. X for which there exists no corresponding command-line for UNIX or or
  970. X AmigaDOS programs without changing the standard command-line syntax
  971. X for these systems.
  972. X
  973. X In addition to a help option in the default argument descriptor, The
  974. X VMS version of parseargs(3) also has /OUTPUT, /INPUT, and /ERROR
  975. X qualifiers in the standard default argument-descriptor array. These
  976. X all serve to redirect stdin, stdout, or stderr to or from a file (many
  977. X thanks to posters from comp.os.vms for giving me a clue on how to do
  978. X this). As a result of this, under VAX/VMS, there are two new argtype
  979. X functions "argInput" and "argOutput": each requires that ad->ad_valp
  980. X be a pointer to a file pointer (not a FILE * variable as in "__ stdin"
  981. X but an actual FILE ** variable as in "__ &stdin"). ArgInput & argOutput
  982. X close the stream associated with the given file-pointer and reconnect
  983. X the stream to the named file for input or output (so the effect is to
  984. X redirect input (output) from (to) the stream to the named file. If
  985. X redirection fails, the original stream remains closed (sorry -- its a
  986. X side-effect of freopen()).
  987. X
  988. X One can implement a "negatable" vms qualifier by using two entries in
  989. X the argument descriptor table as follows:
  990. X
  991. X     'F', ARGOPT, argSBool, __ &myflag, "FLAG {set flag}",
  992. X     'f', ARGOPT, argUBool, __ &myflag, "NOFLAG {unset flag}",
  993. X
  994. X so that /FLAG will turn the flag on (via argBool or argSBool) and
  995. X /NOFLAG will turn it off (via argUBool).
  996. X
  997. X I did not know what to do (if anything) to add the VAX/VMS shell (DCL)
  998. X into the parseargs command-line interface (parseargs(1)) so it is not
  999. X currently implemented. I  will leave the task of configuring
  1000. X parseargs(1) for DCL programmers to some other brave soul who knows
  1001. X more than I about DCL! I was thinking that for DCL, the parseargs
  1002. X command could directly set the value of a symbol (with the proper
  1003. X scope of course) at execution time instead of printing something on
  1004. X stdout that would be evaluated later (as the UNIX version does).
  1005. X
  1006. X Anyone who uses VAX/VMS is strongly encouraged to test vms_args.c on
  1007. X their system (and make changes if need be) and to modify the usage and
  1008. X parsing functions accordingly!!! It would probably be a good idea to
  1009. X use some builtin VMS system call to replace the method used for
  1010. X finding the basename of a file (basename() in strfuncs.c) when "#ifdef
  1011. X vms" is true. There are also some command-line parsing routines
  1012. X available through DCL that could replace a  lot of the guts of
  1013. X vms_args.c as well.
  1014. X
  1015. X
  1016. X TO DO
  1017. X =====
  1018. X - get parseargs(1) to work for DCL under VMS using symbols
  1019. X - add ash to the list of shells supported by parseargs(1)
  1020. X - add clam to the list of shells supported by parseargs(1)
  1021. X - get parseargs(1) to support arrays for bash
  1022. X - verify that parseargs(1) works for rc, the Plan 9 shell
  1023. X - verify that parseargs(1) works for zsh
  1024. X - verify that parseargs(3) works on MS-DOS and OS/2 systems.
  1025. X
  1026. X
  1027. X LITERATE PROGRAMMING
  1028. X ====================
  1029. X If you look at the source code you will notice that it contains lots
  1030. X of funny looking comments with sections that have titles enclosed
  1031. X between '^' and ':' characters. This is my own feeble attempt at
  1032. X literate programming. I have a Korn shell script (xdoc) which will
  1033. X extract certain portions of these "structured" comments so that I may
  1034. X dump them directly into the documentation (and thus attempt to keep
  1035. X the documentation up-to-date at the same rate as the source). If anyone
  1036. X is interested in my script(s) please let me know and I will gladly
  1037. X e-mail them to the interested parties.
  1038. X
  1039. X
  1040. X ACKNOWLEDGEMENTS
  1041. X ================
  1042. X I was in constant contact with Peter Da Silva during the entire period
  1043. X that I  implemented all of the above modifications and would like to
  1044. X thank him for his time and his sage advice. Many of the ideas which I 
  1045. X implemented are a direct result of our discussions.
  1046. X
  1047. X Thanx also to Jim Barbour for helping me with some VMS specific things
  1048. X (like getting the original, unparsed command-line from DCL and
  1049. X retrieving the value of a symbol), and to Tom Christiansen and Raymond
  1050. X Chen for their help in getting parseargs(1) to work for perl scripts.
  1051. X
  1052. X Thanx also to Gillmer J. Derge, Marco Nijdam, Chris Johnston, Earl Chew
  1053. X and Mike Levin for sending me their bug reports and fixes so that I could
  1054. X incorporate them into the latest patch of parseargs.
  1055. X
  1056. X Lastly, thanks to all those who use and will continue to improve
  1057. X Parseargs.  Unfortunately - with the release of Patchlevel 11, I
  1058. X will no longer have the time (or inclination) to continue to support
  1059. X Parseargs.  If anyone out there wishes to take over the job for me,
  1060. X please let me know and I will give you some extra "goodies" that I
  1061. X use for maintenance that are not part of the regular Parseargs 
  1062. X distribution.
  1063. X
  1064. X PS - C++ user's be on the lookout for "CmdLine", a C++ re-write of
  1065. X      Parseargs (written by your's truly).
  1066. END_OF_FILE
  1067. if test 41528 -ne `wc -c <'README'`; then
  1068.     echo shar: \"'README'\" unpacked with wrong size!
  1069. fi
  1070. # end of 'README'
  1071. fi
  1072. if test ! -d 'doc' ; then
  1073.     echo shar: Creating directory \"'doc'\"
  1074.     mkdir 'doc'
  1075. fi
  1076. if test -f 'doc/argvalopt.inc' -a "${1}" != "-c" ; then 
  1077.   echo shar: Will not clobber existing file \"'doc/argvalopt.inc'\"
  1078. else
  1079. echo shar: Extracting \"'doc/argvalopt.inc'\" \(1216 characters\)
  1080. sed "s/^X//" >'doc/argvalopt.inc' <<'END_OF_FILE'
  1081. X.\"----------------------------------------------------------------------------
  1082. X.\"-- This text was extracted using the following command:
  1083. X.\"--   xdoc -man -p '[ \t]*' -s ARGVALOPT ../parseargs.c
  1084. X.\"----------------------------------------------------------------------------
  1085. X.SH OPTIONS WITH OPTIONAL ARGUMENTS
  1086. X.PP
  1087. XOptions that may take an optional argument need special consideration.
  1088. XThe shell programmer needs to know whether or not the option was given, and
  1089. X(if given) if it was accompanied by an argument. In order to accommodate this
  1090. Xneed, \fBparseargs\fP will set an additional shell variable for each argument
  1091. Xthat is given the \s-1ARGVALOPT\s+1 flag if it is supplied on the command line
  1092. X\fIregardless of whether or not it was accompanied by its optional argument\fP.
  1093. XIf the user has defined an option which may optionally
  1094. Xtake an argument and the option appears on the command line
  1095. X\fIwith or without\fP its associated argument, then the shell variable
  1096. X\fI<name>\fP\f4_flag\fP will be assigned the value ``\f4TRUE\fP''
  1097. X(or the value supplied with the \fB\-T\fP option to \fBparseargs\fP) where
  1098. X\fI<name>\fP is the name of the shell variable associated with the option
  1099. Xin the argument description string.
  1100. END_OF_FILE
  1101. if test 1216 -ne `wc -c <'doc/argvalopt.inc'`; then
  1102.     echo shar: \"'doc/argvalopt.inc'\" unpacked with wrong size!
  1103. fi
  1104. # end of 'doc/argvalopt.inc'
  1105. fi
  1106. if test -f 'doc/caveats.inc' -a "${1}" != "-c" ; then 
  1107.   echo shar: Will not clobber existing file \"'doc/caveats.inc'\"
  1108. else
  1109. echo shar: Extracting \"'doc/caveats.inc'\" \(1768 characters\)
  1110. sed "s/^X//" >'doc/caveats.inc' <<'END_OF_FILE'
  1111. X.\"----------------------------------------------------------------------------
  1112. X.\"-- This text was extracted using the following command:
  1113. X.\"--   xdoc -man -n -p '[ \t]*' -I CAVEATS ../xparse.c
  1114. X.\"----------------------------------------------------------------------------
  1115. X.SH CAVEATS
  1116. X.PP
  1117. XBecause of the way argument parsing is implemented under \s-1UNIX\s+1,
  1118. X\s-1MS-DOS\s+1, and \s-1OS/2\s+1,
  1119. Xoption arguments which contain a leading dash (`\-') (or whatever the
  1120. Xoption prefix character is defined to be) may \fInot\fP be specified
  1121. Xas a separate argument on the command line, it must be part of the
  1122. Xsame argument. That is to say that if a program has a \fB\-f\fP option
  1123. Xthat requires a string argument, then the following:
  1124. X.sp 4p
  1125. X.RS
  1126. X.ft 4
  1127. X\-f\-arg
  1128. X.ft R
  1129. X.RE
  1130. X.sp 4p
  1131. Xwill properly assign the string ``\fB\-arg\fP'' to the option whereas
  1132. Xthe following:
  1133. X.sp 4p
  1134. X.RS
  1135. X.ft 4
  1136. X\-f\0\-arg
  1137. X.RE
  1138. X.sp 4p
  1139. Xwill be interpreted by \fIparseargs\fP as two option strings: the first
  1140. Xof which (``\fB\-f\fP'') is missing a required argument and the second of
  1141. Xwhich (``\fB\-arg\fP'') will most likely be flagged as an invalid option.
  1142. X.PP
  1143. XSimilarly, if the user requires an \s-1\fIARGLIST\fP\s+1 option
  1144. Xto take multiple arguments with leading dashes then the following
  1145. Xmethod must be used: It is a ``feature'' of \fIparseargs\fP that
  1146. X\s-1\fIARGLIST\fP\s+1 arguments are always appended to the current
  1147. Xlist of arguments for the given option. Thus, if ``\fB\-f\fP'' is
  1148. Xan option taking a list of arguments, then the following are all
  1149. Xequivalent:
  1150. X.sp 8p
  1151. X.RS
  1152. X.ft 4
  1153. X\-farg1 arg2
  1154. X.sp 4p
  1155. X\-f arg1 arg2
  1156. X.sp 4p
  1157. X\-farg1 \-farg2
  1158. X.sp 4p
  1159. X\-f arg1 \-f arg2
  1160. X.ft R
  1161. X.RE
  1162. X.sp 8p
  1163. XHence multiple ``leading dash'' arguments may specified as follows:
  1164. X.sp 4p
  1165. X.RS
  1166. X.ft 4
  1167. X\-f\-dash_arg1 \-f\-dash_arg2  ...
  1168. X.ft R
  1169. X.RE
  1170. END_OF_FILE
  1171. if test 1768 -ne `wc -c <'doc/caveats.inc'`; then
  1172.     echo shar: \"'doc/caveats.inc'\" unpacked with wrong size!
  1173. fi
  1174. # end of 'doc/caveats.inc'
  1175. fi
  1176. if test -f 'doc/cmd_macros.inc' -a "${1}" != "-c" ; then 
  1177.   echo shar: Will not clobber existing file \"'doc/cmd_macros.inc'\"
  1178. else
  1179. echo shar: Extracting \"'doc/cmd_macros.inc'\" \(1635 characters\)
  1180. sed "s/^X//" >'doc/cmd_macros.inc' <<'END_OF_FILE'
  1181. X.\"----------------------------------------------------------------------------
  1182. X.\"-- This text was extracted using the following command:
  1183. X.\"--   xdoc -man -p '[ \t]*' -s CMD-MACROS ../parseargs.h
  1184. X.\"----------------------------------------------------------------------------
  1185. X.SH "CMD MACROS"
  1186. X\f4<parseargs.h>\fP defines a set of macros to allow a more "self documenting"
  1187. Xapproach to declaring argument-descriptor arrays. The "old-style" is
  1188. Xstill accepted (but if used it is recommended that the \s-1STARTOFARGS\s+1
  1189. Xmacro is used in conjunction with \s-1ENDOFARGS\s+1).
  1190. XAn example use of these macros (which, with one exception, all begin with
  1191. X``\s-1CMD\s+1'') follows:
  1192. X.RS
  1193. X.nf
  1194. X.ft 4
  1195. X#include <parseargs.h>
  1196. X
  1197. Xstatic BOOL bflag = FALSE;
  1198. Xstatic char *arg1 = CHARNULL;
  1199. Xstatic char *arg2 = CHARNULL;
  1200. X
  1201. Xstatic
  1202. X   CMD_OBJECT
  1203. X      MyCmd
  1204. X
  1205. X   CMD_NAME
  1206. X      "mycmd -- one line statement of purpose"
  1207. X
  1208. X   CMD_DESCRIPTION
  1209. X      "Mycmd will try really really hard to run without errors \\
  1210. Xand do whatever the heck it is supposed to do. If (God forbid) \\
  1211. Xsomething should actually go wrong it will say so."
  1212. X
  1213. X   CMD_ARGUMENTS
  1214. X      'H', ARGOPT, argUsage, __ NULL,
  1215. X      "Help -- display usage and quit",
  1216. X
  1217. X      'b', ARGOPT, argSBool, __ &bflag,
  1218. X      "bflag -- turn on `b'-mode (whatever that is)",
  1219. X
  1220. X      ' ', ARGREQ, argStr, __ &arg1,
  1221. X      "arg1 -- first argument to this spiffy program",
  1222. X
  1223. X      ' ', ARGOPT, argStr, __ &arg2,
  1224. X      "arg2 -- optional second argument to this spiffy program",
  1225. X
  1226. X      END_ARGUMENTS
  1227. X   CMD_END
  1228. X
  1229. Xmain( int argc, char *argv[] )
  1230. X{
  1231. X   (void) parseargs( argv, MyCmd );
  1232. X   (void) dostuff();
  1233. X   exit( 0 );
  1234. X}
  1235. X.ft R
  1236. X.fi
  1237. X.RE
  1238. END_OF_FILE
  1239. if test 1635 -ne `wc -c <'doc/cmd_macros.inc'`; then
  1240.     echo shar: \"'doc/cmd_macros.inc'\" unpacked with wrong size!
  1241. fi
  1242. # end of 'doc/cmd_macros.inc'
  1243. fi
  1244. if test -f 'doc/defargs.inc' -a "${1}" != "-c" ; then 
  1245.   echo shar: Will not clobber existing file \"'doc/defargs.inc'\"
  1246. else
  1247. echo shar: Extracting \"'doc/defargs.inc'\" \(1117 characters\)
  1248. sed "s/^X//" >'doc/defargs.inc' <<'END_OF_FILE'
  1249. X.\"----------------------------------------------------------------------------
  1250. X.\"-- This text was extracted using the following command:
  1251. X.\"--   xdoc -man -p '[ \t]*' -s DEFAULT-ARGUMENT ../xparse.c
  1252. X.\"----------------------------------------------------------------------------
  1253. X.SH "DEFAULT ARGUMENT DESCRIPTOR"
  1254. X.PP
  1255. XEach argdesc-array has an initial default argument list (which may be reset
  1256. Xusing the pc_DEFARGS function code with \fIparsecntl\fP). This initial
  1257. Xdefault argument-list contains `?' and `H' which may be used as single
  1258. Xcharacter keywords to display command-usage for all command-line styles.
  1259. XSimilarly, ``?'', ``H'', and ``Help'' may be used as long-keywords to display
  1260. Xcommand-usage for all command-line styles.  In Addition, for \s-1VMS\s+1
  1261. Xstyle commands, the qualifiers \fB\s-1/INPUT\s+1=\fIfile\fR,
  1262. X\fB\s-1/OUTPUT\s+1=\fIfile\fR, and \fB\s-1/ERROR\s+1=\fIfile\fR, may be used
  1263. Xto redirect \f4stdin\fP, \f4stdout\fP, and \f4stderr\fP (respectively) to a
  1264. Xfile.  For Amiga\s-1DOS\s+1 style commands, the keyword ``ENDKWDS'' may be
  1265. Xused to disable parsing for any more keywords on the command-line.
  1266. END_OF_FILE
  1267. if test 1117 -ne `wc -c <'doc/defargs.inc'`; then
  1268.     echo shar: \"'doc/defargs.inc'\" unpacked with wrong size!
  1269. fi
  1270. # end of 'doc/defargs.inc'
  1271. fi
  1272. if test -f 'doc/effects.inc' -a "${1}" != "-c" ; then 
  1273.   echo shar: Will not clobber existing file \"'doc/effects.inc'\"
  1274. else
  1275. echo shar: Extracting \"'doc/effects.inc'\" \(1060 characters\)
  1276. sed "s/^X//" >'doc/effects.inc' <<'END_OF_FILE'
  1277. X.\"----------------------------------------------------------------------------
  1278. X.\"-- This text was extracted using the following command:
  1279. X.\"--   xdoc -man -n -p '[ \t]*' -I SIDE-EFFECTS  ../xparse.c
  1280. X.\"----------------------------------------------------------------------------
  1281. X.SH "SIDE EFFECTS"
  1282. X.PP
  1283. XEach of the functions in the \fIparseargs\fP library will set the external
  1284. Xcharacter string \fIProgName\fP to be the name of the last command that
  1285. Xwas operated upon by any of the library routines.
  1286. X.PP
  1287. XWhen an argument-descriptor array is first encountered by any of the
  1288. Xparseargs library routines, it is initially compiled into an intermediate
  1289. Xform that is more convenient to manipulate. As a direct result, it is not
  1290. Xadvisable to attempt to index directly into the array to manipulate one
  1291. Xof the argument descriptors (because the argdesc that you thought was there
  1292. Xmay actually be somewhere else). After the array has been given its initial
  1293. Xvalue(s), only \fIparsecntl\fP(3) should be used to manipulate or query the
  1294. Xattributes of an argument descriptor.
  1295. END_OF_FILE
  1296. if test 1060 -ne `wc -c <'doc/effects.inc'`; then
  1297.     echo shar: \"'doc/effects.inc'\" unpacked with wrong size!
  1298. fi
  1299. # end of 'doc/effects.inc'
  1300. fi
  1301. if test -f 'doc/fparseargs3.inc' -a "${1}" != "-c" ; then 
  1302.   echo shar: Will not clobber existing file \"'doc/fparseargs3.inc'\"
  1303. else
  1304. echo shar: Extracting \"'doc/fparseargs3.inc'\" \(932 characters\)
  1305. sed "s/^X//" >'doc/fparseargs3.inc' <<'END_OF_FILE'
  1306. X.\"----------------------------------------------------------------------------
  1307. X.\"-- This text was extracted using the following command:
  1308. X.\"--   xdoc -man -n -p '[ \t]*' -I DESCRIPTION -f fparseargs ../xparse.c
  1309. X.\"----------------------------------------------------------------------------
  1310. X.PP
  1311. XGiven a readable input stream and an argdesc array, \fIfparseargs\fP
  1312. Xwill parse arguments in a file in the same manner as \fIparseargs\fP.
  1313. XA maximum-line length of 255 characters is imposed.  NO ``escaping'' of any
  1314. Xkind is performed. Comments of a limited form are permitted: if the first
  1315. Xnon-whitespace character on a line is a '#' (or '!' for \s-1VMS\s+1) then
  1316. Xthat entire line is considered a comment and is ignored.  If a value is
  1317. Xprovided for an argument that is NOT a list or a vector, then the value MUST
  1318. Xbe on the same line as the argument (in other words, ``\fB\-v\fI val\fR'' is
  1319. Xfine but ``\fB\-v\f4\\n\fIval\fR'' is a not).
  1320. END_OF_FILE
  1321. if test 932 -ne `wc -c <'doc/fparseargs3.inc'`; then
  1322.     echo shar: \"'doc/fparseargs3.inc'\" unpacked with wrong size!
  1323. fi
  1324. # end of 'doc/fparseargs3.inc'
  1325. fi
  1326. if test -f 'doc/lib_bugs.inc' -a "${1}" != "-c" ; then 
  1327.   echo shar: Will not clobber existing file \"'doc/lib_bugs.inc'\"
  1328. else
  1329. echo shar: Extracting \"'doc/lib_bugs.inc'\" \(1102 characters\)
  1330. sed "s/^X//" >'doc/lib_bugs.inc' <<'END_OF_FILE'
  1331. X.\"----------------------------------------------------------------------------
  1332. X.\"-- This text was extracted using the following command:
  1333. X.\"--   xdoc -man -n -p '[ \t]*' -I BUGS  ../xparse.c
  1334. X.\"----------------------------------------------------------------------------
  1335. X.SH BUGS
  1336. X.PP
  1337. XWhen a non-multivalued argument appears more than once on the command-line
  1338. Xthen only the last value supplied is used. A problem occurs however in the
  1339. Xfollowing scenario: suppose `\fB\-s\fP' is an option that takes an optional
  1340. Xstring argument (and suppose `\fB\-x\fP' is some boolean flag). Then if the
  1341. Xfollowing command-line is issued:
  1342. X
  1343. X.RS
  1344. X.nf
  1345. X.ft 4
  1346. Xcommand  \-s string  \-x  \-s
  1347. X.ft R
  1348. X.fi
  1349. X.RE
  1350. X
  1351. Xthen, the argument flags will properly correspond to the second instance
  1352. Xof the `\fB\-s\fP' option (namely \s-1ARGGIVEN\s+1 will be set but 
  1353. X\s-1ARGVALGIVEN\s+1 will be unset) but the value associated with the
  1354. Xoption will be ``\fIstring\fP'' (because the first instance overwrote
  1355. Xthe default).  Because of this, it may be safest to reassign the default
  1356. Xvalue if \s-1ARGGIVEN\s+1 is set but \s-1ARGVALGIVEN\s+1 is unset.
  1357. END_OF_FILE
  1358. if test 1102 -ne `wc -c <'doc/lib_bugs.inc'`; then
  1359.     echo shar: \"'doc/lib_bugs.inc'\" unpacked with wrong size!
  1360. fi
  1361. # end of 'doc/lib_bugs.inc'
  1362. fi
  1363. if test -f 'doc/lparseargs3.inc' -a "${1}" != "-c" ; then 
  1364.   echo shar: Will not clobber existing file \"'doc/lparseargs3.inc'\"
  1365. else
  1366. echo shar: Extracting \"'doc/lparseargs3.inc'\" \(427 characters\)
  1367. sed "s/^X//" >'doc/lparseargs3.inc' <<'END_OF_FILE'
  1368. X.\"----------------------------------------------------------------------------
  1369. X.\"-- This text was extracted using the following command:
  1370. X.\"--   xdoc -man -n -p '[ \t]*' -I DESCRIPTION -f lparseargs ../xparse.c
  1371. X.\"----------------------------------------------------------------------------
  1372. X.PP
  1373. XGiven an ArgList and an argdesc array, \fIlparseargs\fP
  1374. Xwill parse arguments in an ArgList in the same manner as \fIparseargs\fP.
  1375. END_OF_FILE
  1376. if test 427 -ne `wc -c <'doc/lparseargs3.inc'`; then
  1377.     echo shar: \"'doc/lparseargs3.inc'\" unpacked with wrong size!
  1378. fi
  1379. # end of 'doc/lparseargs3.inc'
  1380. fi
  1381. if test -f 'doc/parseargs1.inc' -a "${1}" != "-c" ; then 
  1382.   echo shar: Will not clobber existing file \"'doc/parseargs1.inc'\"
  1383. else
  1384. echo shar: Extracting \"'doc/parseargs1.inc'\" \(1622 characters\)
  1385. sed "s/^X//" >'doc/parseargs1.inc' <<'END_OF_FILE'
  1386. X.\"----------------------------------------------------------------------------
  1387. X.\"-- This text was extracted using the following command:
  1388. X.\"--   xdoc -man -n -p '[ \t]*' -I DESCRIPTION ../parseargs.c
  1389. X.\"----------------------------------------------------------------------------
  1390. X.SH DESCRIPTION
  1391. XGiven a command name, a vector of string-valued arguments
  1392. Xsuch as that passed to a shell script,
  1393. Xand a specification string describing the possible arguments,
  1394. X.B parseargs
  1395. Xmatches actual arguments to possible arguments,
  1396. Xconverts values to the desired type,
  1397. Xand diagnoses problems such as
  1398. Xmissing arguments,
  1399. Xextra arguments,
  1400. Xand argument values that are syntactically incorrect.
  1401. XOther behavior such as prompting the user for missing arguments and
  1402. Xignoring bad command-line syntax may be specified on the command-line
  1403. Xthrough the use of various options, or through the use of the
  1404. X``\s-1PARSECNTL\s+1'' environment variable.
  1405. X.PP
  1406. XGiven the command name and the argument specification string,
  1407. X.B parseargs \-U
  1408. Xprints a reasonably friendly version of the usage of the
  1409. Xcalling program on standard diagnostic output. The ``verbosity''
  1410. Xof the usage message may be controlled through the use of the
  1411. X``\s-1USAGECNTL\s+1'' environment variable.
  1412. X.PP
  1413. XGiven the command name and the argument specification string,
  1414. X.B parseargs \-M
  1415. Xprints a template of the command-syntax on standard output that is
  1416. Xsuitable for input to \fInroff\fP or \fItroff\fP using the \fI\-man\fP
  1417. Xmacro package.
  1418. X.PP
  1419. XGiven no other arguments
  1420. X\fBparseargs \-#\fP prints on standard output, the current version and
  1421. Xpatchlevel of the running version of \fBparseargs\fP.
  1422. X
  1423. END_OF_FILE
  1424. if test 1622 -ne `wc -c <'doc/parseargs1.inc'`; then
  1425.     echo shar: \"'doc/parseargs1.inc'\" unpacked with wrong size!
  1426. fi
  1427. # end of 'doc/parseargs1.inc'
  1428. fi
  1429. if test -f 'doc/parseargs3.inc' -a "${1}" != "-c" ; then 
  1430.   echo shar: Will not clobber existing file \"'doc/parseargs3.inc'\"
  1431. else
  1432. echo shar: Extracting \"'doc/parseargs3.inc'\" \(642 characters\)
  1433. sed "s/^X//" >'doc/parseargs3.inc' <<'END_OF_FILE'
  1434. X.\"----------------------------------------------------------------------------
  1435. X.\"-- This text was extracted using the following command:
  1436. X.\"--   xdoc -man -n -p '[ \t]*' -I DESCRIPTION -f parseargs ../xparse.c
  1437. X.\"----------------------------------------------------------------------------
  1438. X.PP
  1439. XGiven a vector of string-valued arguments such as that passed to \fImain\fP
  1440. Xand a vector describing the possible arguments, \fIparseargs\fP matches
  1441. Xactual arguments to possible arguments, converts values to the desired type,
  1442. Xand diagnoses problems such as missing arguments, extra arguments,
  1443. Xand argument values that are syntactically incorrect.
  1444. END_OF_FILE
  1445. if test 642 -ne `wc -c <'doc/parseargs3.inc'`; then
  1446.     echo shar: \"'doc/parseargs3.inc'\" unpacked with wrong size!
  1447. fi
  1448. # end of 'doc/parseargs3.inc'
  1449. fi
  1450. if test -f 'doc/parsecntl.man3' -a "${1}" != "-c" ; then 
  1451.   echo shar: Will not clobber existing file \"'doc/parsecntl.man3'\"
  1452. else
  1453. echo shar: Extracting \"'doc/parsecntl.man3'\" \(1022 characters\)
  1454. sed "s/^X//" >'doc/parsecntl.man3' <<'END_OF_FILE'
  1455. X.\"---------- TO PRINT, USE: {n,t}roff -man file ----------
  1456. X.TH PARSECNTL 3
  1457. X.\"-----------------------------------
  1458. X.SH NAME
  1459. Xparsecntl \- get and set attributes of an argument descriptor array
  1460. X.\"-----------------------------------
  1461. X.SH SYNOPSIS
  1462. X#include <parseargs.h>
  1463. X.PP
  1464. X.nf
  1465. Xint  parsecntl( ARGDESC argd[\|],  parsecntl_t func,  parsemode_t mode,  ... );
  1466. X.fi
  1467. X
  1468. X.\"-----------------------------------
  1469. X.so parsecntl3.inc
  1470. X.\"-----------------------------------
  1471. X.so parsecntls.inc
  1472. X.\"-----------------------------------
  1473. X.so parsemodes.inc
  1474. X.\"-----------------------------------
  1475. X.so parseflags.inc
  1476. X.\"-----------------------------------
  1477. X.so argflags.inc
  1478. X.\"-----------------------------------
  1479. X.so returns.inc
  1480. X.\"-----------------------------------
  1481. X.so effects.inc
  1482. X.\"-----------------------------------
  1483. X.SH SEE ALSO
  1484. X.IR argtype (3),
  1485. X.IR parseargs (3),
  1486. X.IR parseargs (1)
  1487. X.\"-----------------------------------
  1488. X.SH AUTHOR
  1489. X.PP
  1490. X.nf
  1491. XBrad Appleton  (\fIbrad@ssd.csd.harris.com\fP)
  1492. XHarris Computer Systems, Fort Lauderdale, FL USA
  1493. X.fi
  1494. END_OF_FILE
  1495. if test 1022 -ne `wc -c <'doc/parsecntl.man3'`; then
  1496.     echo shar: \"'doc/parsecntl.man3'\" unpacked with wrong size!
  1497. fi
  1498. # end of 'doc/parsecntl.man3'
  1499. fi
  1500. if test -f 'doc/parsecntl3.inc' -a "${1}" != "-c" ; then 
  1501.   echo shar: Will not clobber existing file \"'doc/parsecntl3.inc'\"
  1502. else
  1503. echo shar: Extracting \"'doc/parsecntl3.inc'\" \(1720 characters\)
  1504. sed "s/^X//" >'doc/parsecntl3.inc' <<'END_OF_FILE'
  1505. X.\"----------------------------------------------------------------------------
  1506. X.\"-- This text was extracted using the following command:
  1507. X.\"--   xdoc -man -n -p '[ \t]*' -I DESCRIPTION -f parsecntl ../xparse.c
  1508. X.\"----------------------------------------------------------------------------
  1509. X.SH "DESCRIPTION"
  1510. X.PP
  1511. X.I Parsecntl
  1512. Xwill read and/or write the desired attributes of the given
  1513. Xcommand-object. The attributes to be operated upon are specified by
  1514. Xthe second parameter to
  1515. X.I parsecntl.
  1516. XThe desired mode (read, write, or both) are specified by the third parameter to
  1517. X.I parsecntl.
  1518. XIf the operation to be performed is
  1519. X.I pc_\s-1ARGFLAGS\s+1,
  1520. Xthen the fourth argument to
  1521. X.I parsecntl
  1522. Xshould be the keyword name of the argument whose flags
  1523. Xare to be retrieved.  The last parameter to
  1524. X.I parsecntl
  1525. Xis always the object to contain the attribute(s) to be read/written.
  1526. XIf the attribute(s) are to be read (regardless of whether or not they are 
  1527. Xalso being changed) then the last argument should be a pointer to
  1528. Xan object, otherwise the last argument should be the object itself.
  1529. X.PP
  1530. XIf mode is
  1531. X.I pc_\s-1READ\s+1,
  1532. Xthen the desired attributes are copied into
  1533. Xthe object pointed to by the last parameter. If the mode is
  1534. X.I pc_\s-1WRITE\s+1,
  1535. Xthen the attributes from the last parameter are copied to the
  1536. Xcommand-object. If mode is
  1537. X.I pc_\s-1RDWR\s+1,
  1538. Xthen the attributes pointed to by the last
  1539. Xparameter are copied to the command-object, and then the previous value
  1540. Xof these attributes (before they were overwritten) is copied into the
  1541. Xobject pointed to by the last parameter.
  1542. X.PP
  1543. XIf cntl is
  1544. X.I pc_\s-1ARGFLAGS\s+1,
  1545. Xthen the only valid mode is
  1546. X.I pc_\s-1READ\s+1.
  1547. XAll other attributes may be written or read by
  1548. X.I parsecntl.
  1549. END_OF_FILE
  1550. if test 1720 -ne `wc -c <'doc/parsecntl3.inc'`; then
  1551.     echo shar: \"'doc/parsecntl3.inc'\" unpacked with wrong size!
  1552. fi
  1553. # end of 'doc/parsecntl3.inc'
  1554. fi
  1555. if test -f 'doc/parsemodes.inc' -a "${1}" != "-c" ; then 
  1556.   echo shar: Will not clobber existing file \"'doc/parsemodes.inc'\"
  1557. else
  1558. echo shar: Extracting \"'doc/parsemodes.inc'\" \(1435 characters\)
  1559. sed "s/^X//" >'doc/parsemodes.inc' <<'END_OF_FILE'
  1560. X.\"----------------------------------------------------------------------------
  1561. X.\"-- This text was extracted using the following command:
  1562. X.\"--   xdoc -man -p '[ \t]*' -s PARSE-MODES ../parseargs.h
  1563. X.\"----------------------------------------------------------------------------
  1564. X.SH "PARSE MODES"
  1565. X.PP
  1566. X\fIParsecntl\fP may be used to read current command attributes, write
  1567. X(assign) new command attributes, or both. The mode argument to
  1568. Xparsecntl determines which of these three alternatives are
  1569. Xdesired. If the programmer merely wishes to assign new attributes,
  1570. Xthen invoking \fIparsecntl\fP in \fIpc_\s-1WRITE\s+1\fP mode and passing
  1571. Xthe new attributes will do the job. If the programmer wishes simply to query
  1572. Xattributes, then invoking \fIparsecntl\fP in \fIpc_\s-1READ\s+1\fP mode and
  1573. Xpassing a pointer to the desired object in which to write the attribute
  1574. Xsettings will suffice.
  1575. X
  1576. XIf the programmer wishes to assign new attributes and at the same time
  1577. Xfind out what the attributes were before making the assignment, then
  1578. Xprogrammer must invoke \fIparsecntl\fP for \fIpc_\s-1RDWR\s+1\fP mode
  1579. Xand pass a pointer to the object containing the new attribute settings;
  1580. XWhen \fIparsecntl\fP returns, then (assuming it returns 0) the desired
  1581. Xattributes will have been assigned and the object that contained the
  1582. Xnew attribute settings will now contain the attribute settings that
  1583. Xwere in effect immediately before \fIparsecntl\fP was invoked.
  1584. END_OF_FILE
  1585. if test 1435 -ne `wc -c <'doc/parsemodes.inc'`; then
  1586.     echo shar: \"'doc/parsemodes.inc'\" unpacked with wrong size!
  1587. fi
  1588. # end of 'doc/parsemodes.inc'
  1589. fi
  1590. if test -f 'doc/sparseargs3.inc' -a "${1}" != "-c" ; then 
  1591.   echo shar: Will not clobber existing file \"'doc/sparseargs3.inc'\"
  1592. else
  1593. echo shar: Extracting \"'doc/sparseargs3.inc'\" \(830 characters\)
  1594. sed "s/^X//" >'doc/sparseargs3.inc' <<'END_OF_FILE'
  1595. X.\"----------------------------------------------------------------------------
  1596. X.\"-- This text was extracted using the following command:
  1597. X.\"--   xdoc -man -n -p '[ \t]*' -I DESCRIPTION -f sparseargs ../xparse.c
  1598. X.\"----------------------------------------------------------------------------
  1599. X.PP
  1600. XGiven a single string and an argdesc array, \fIsparseargs\fP
  1601. Xwill parse arguments from a string in much the manner as \fIparseargs\fP.
  1602. X.I Sparseargs
  1603. Xwill split the given string up into a vector of whitespace
  1604. Xseparated tokens and then attempt to parse the resultant vector as
  1605. Xif it were given as \f4argv[]\fP on the command-line.
  1606. XNO special treatment is given to characters such as single-quotes,
  1607. Xdouble-quotes, or anything else. \fISparseargs\fP will always assume that
  1608. Xany whitespace characters are intended as argument separators.
  1609. END_OF_FILE
  1610. if test 830 -ne `wc -c <'doc/sparseargs3.inc'`; then
  1611.     echo shar: \"'doc/sparseargs3.inc'\" unpacked with wrong size!
  1612. fi
  1613. # end of 'doc/sparseargs3.inc'
  1614. fi
  1615. if test -f 'doc/usage3.inc' -a "${1}" != "-c" ; then 
  1616.   echo shar: Will not clobber existing file \"'doc/usage3.inc'\"
  1617. else
  1618. echo shar: Extracting \"'doc/usage3.inc'\" \(449 characters\)
  1619. sed "s/^X//" >'doc/usage3.inc' <<'END_OF_FILE'
  1620. X.\"----------------------------------------------------------------------------
  1621. X.\"-- This text was extracted using the following command:
  1622. X.\"--   xdoc -man -n -p '[ \t]*' -I DESCRIPTION -f usage ../xparse.c
  1623. X.\"----------------------------------------------------------------------------
  1624. X.PP
  1625. XGiven an argdesc array, \fIusage\fP will print the usage for the given
  1626. Xcommand in the format specified by the user's \s-1USAGECNTL\s+1 environment
  1627. Xvariable.
  1628. END_OF_FILE
  1629. if test 449 -ne `wc -c <'doc/usage3.inc'`; then
  1630.     echo shar: \"'doc/usage3.inc'\" unpacked with wrong size!
  1631. fi
  1632. # end of 'doc/usage3.inc'
  1633. fi
  1634. if test -f 'doc/vparseargs3.inc' -a "${1}" != "-c" ; then 
  1635.   echo shar: Will not clobber existing file \"'doc/vparseargs3.inc'\"
  1636. else
  1637. echo shar: Extracting \"'doc/vparseargs3.inc'\" \(731 characters\)
  1638. sed "s/^X//" >'doc/vparseargs3.inc' <<'END_OF_FILE'
  1639. X.\"----------------------------------------------------------------------------
  1640. X.\"-- This text was extracted using the following command:
  1641. X.\"--   xdoc -man -n -p '[ \t]*' -I DESCRIPTION -f vparseargs ../xparse.c
  1642. X.\"----------------------------------------------------------------------------
  1643. X.PP
  1644. X.I Vparseargs
  1645. Xtakes an argdesc array, the number of arguments to parse, and a
  1646. X(possibly NULL terminated) list of argument-strings
  1647. Xand parses them in the same manner as \fIparseargs\fP.
  1648. XUnlike
  1649. X.I sparseargs,
  1650. X.I vparseargs
  1651. Xassumes that all parameters are already split up into tokens, hence any
  1652. Xwhitespace characters contained in any of the string-parameters are used as
  1653. Xis (and will be considered a part of an argument name or value).
  1654. END_OF_FILE
  1655. if test 731 -ne `wc -c <'doc/vparseargs3.inc'`; then
  1656.     echo shar: \"'doc/vparseargs3.inc'\" unpacked with wrong size!
  1657. fi
  1658. # end of 'doc/vparseargs3.inc'
  1659. fi
  1660. if test -f 'exit_codes.h' -a "${1}" != "-c" ; then 
  1661.   echo shar: Will not clobber existing file \"'exit_codes.h'\"
  1662. else
  1663. echo shar: Extracting \"'exit_codes.h'\" \(1098 characters\)
  1664. sed "s/^X//" >'exit_codes.h' <<'END_OF_FILE'
  1665. X/*************************************************************************
  1666. X** ^FILE: exit_codes.h - define exit codes used by the parseargs library
  1667. X**
  1668. X** ^DESCRIPTION:
  1669. X**    When we call exit(3C), we want to use a value that is appropriate
  1670. X**    for the operating system that we are on.  Here are the values
  1671. X**    that we need to define:
  1672. X**
  1673. X**       exit_NORMAL  -- no errors everything is fine
  1674. X**       exit_USAGE   -- no errors but we didnt parse the command-line
  1675. X**                       because we say an argUsage argument
  1676. X**       exit_SYNTAX  -- a syntax error occurred
  1677. X**       exit_SYSTEM  -- a system error occurred
  1678. X**
  1679. X** ^HISTORY:
  1680. X**    04/13/92    Brad Appleton    <brad@ssd.csd.harris.com>    Created
  1681. X***^^********************************************************************/
  1682. X
  1683. X#ifndef exit_NORMAL
  1684. X
  1685. X#ifdef vms
  1686. X# include <ssdef.h>
  1687. X# define  exit_NORMAL  SS$_NORMAL
  1688. X# define  exit_USAGE   SS$_NOTMODIFIED
  1689. X# define  exit_SYNTAX  SS$_BADPARAM
  1690. X# define  exit_SYSTEM  SS$_CANCEL
  1691. X#else
  1692. X# define  exit_NORMAL  0
  1693. X# define  exit_USAGE   1
  1694. X# define  exit_SYNTAX  2
  1695. X# define  exit_SYSTEM  127
  1696. X#endif
  1697. X
  1698. X#endif
  1699. END_OF_FILE
  1700. if test 1098 -ne `wc -c <'exit_codes.h'`; then
  1701.     echo shar: \"'exit_codes.h'\" unpacked with wrong size!
  1702. fi
  1703. # end of 'exit_codes.h'
  1704. fi
  1705. if test -f 'pgopen.h' -a "${1}" != "-c" ; then 
  1706.   echo shar: Will not clobber existing file \"'pgopen.h'\"
  1707. else
  1708. echo shar: Extracting \"'pgopen.h'\" \(977 characters\)
  1709. sed "s/^X//" >'pgopen.h' <<'END_OF_FILE'
  1710. X/*************************************************************************
  1711. X** ^FILE: pgopen.h - include file for pgopen.c
  1712. X**
  1713. X** ^DESCRIPTION:
  1714. X**    If USE_PAGER is #define'd then this file will define the function
  1715. X**    prototypes needed to use the paging library implemented in pgopen.c;
  1716. X**    Otherwise it will #define macros with the same name as the paging
  1717. X**    library routines which do NOT perform any paging.
  1718. X**
  1719. X** ^HISTORY:
  1720. X**    01/02/91     Brad Appleton     <brad@ssd.csd.harris.com>     Created
  1721. X***^^**********************************************************************/
  1722. X
  1723. X#ifndef NULL
  1724. X#  include <stdio.h>
  1725. X#endif
  1726. X#include <useful.h>
  1727. X
  1728. X#ifdef  USE_PAGER
  1729. X   EXTERN   FILE *pgopen    ARGS(( FILE *, const char * ));
  1730. X   EXTERN   int   pgclose   ARGS(( FILE * ));
  1731. X   EXTERN   int   pgactive  ARGS(( const FILE * ));
  1732. X#else
  1733. X#  define  pgopen(fp,s)  (( !fp ) ? fp : (fflush(fp), fp))
  1734. X#  define  pgclose(fp)   (( !fp ) ?  0 : (fflush(fp), 0))
  1735. X#  define  pgactive(fp)  ( fp )
  1736. X#endif
  1737. END_OF_FILE
  1738. if test 977 -ne `wc -c <'pgopen.h'`; then
  1739.     echo shar: \"'pgopen.h'\" unpacked with wrong size!
  1740. fi
  1741. # end of 'pgopen.h'
  1742. fi
  1743. if test -f 'test.pl' -a "${1}" != "-c" ; then 
  1744.   echo shar: Will not clobber existing file \"'test.pl'\"
  1745. else
  1746. echo shar: Extracting \"'test.pl'\" \(1718 characters\)
  1747. sed "s/^X//" >'test.pl' <<'END_OF_FILE'
  1748. X#!/usr/bin/perl
  1749. X
  1750. Xrequire  'parseargs.pl';
  1751. X
  1752. X$ARGD = '
  1753. X  { "?", ARGHIDDEN, argUsage, NULL,    "Help : print usage and exit" },
  1754. X  { "S", ARGVALOPT, argStr,   string,  "STRing : optional string arg" },
  1755. X  { "g", ARGLIST,   argStr,   groups,  "newsGROUPS : groups to test" },
  1756. X  { "r", ARGOPT,    argInt,   count,   "REPcount : group repeat count" },
  1757. X  { "d", ARGOPT,    argStr,   dirname, "DIRectory : working directory" },
  1758. X  { "x", ARGOPT,    argBool,  xflag,   "Xflag : turn on X-mode" },
  1759. X  { "y", ARGOPT,    argUBool, yflag,   "Yflag : turn off Y-mode" },
  1760. X  { "s", ARGOPT,    argChar,  sepch,   "SEPchar : field separator" },
  1761. X  { "f", ARGLIST,   argStr,   files,   "files : files to process" },
  1762. X  { "n", ARGREQ|ARGPOS, argStr, name,  "name : name to use" },
  1763. X  { " ", ARGLIST,   argStr,   ARGV,    "ARGV : any remaining arguments" },
  1764. X  "ENDOFARGS" ';
  1765. X
  1766. X$count = 1;
  1767. X$dirname = '.';
  1768. X$sepch = ',';
  1769. X$yflag = 'TRUE';
  1770. X
  1771. X&parseargs( @ARGV, $ARGD );
  1772. X
  1773. X## print  the parsed arguments (use defaults if not defined)
  1774. Xprint "ARGUMENTS:\n";
  1775. Xprint "==========\n";
  1776. Xfor ( $i = $[ ; $i <= $#groups ; $i++ ) {
  1777. X  printf( "Groups[%d] = '%s'\n", $i, $groups[$i] );
  1778. X}
  1779. Xprintf( "Count = %d\n", $count );
  1780. Xprintf( "Directory = '%s'\n", $dirname );
  1781. Xprintf( "XFlag = '%s'\n", $xflag );
  1782. Xprintf( "YFlag = '%s'\n", $yflag );
  1783. Xprintf( "SepChar = '%s'\n", $sepch );
  1784. Xprintf( "Name = '%s'\n", $name );
  1785. Xfor ( $i = $[ ; $i <= $#files ; $i++ ) {
  1786. X  printf( "Files[%d] = '%s'\n", $i, $files[$i] );
  1787. X}
  1788. Xif ( $string_flag ) {
  1789. X  if ( ! $string ) {
  1790. X    $string = '!string arg ommitted on cmd-line!';
  1791. X  }
  1792. X}
  1793. Xelse {
  1794. X  $string = 'default string';
  1795. X}
  1796. Xprintf( "String = '%s'\n", $string );
  1797. Xfor ( $i = $[ ; $i <= $#ARGV ; $i++ ) {
  1798. X  printf( "ARGV[%d] = '%s'\n", $i, $ARGV[$i] );
  1799. X}
  1800. END_OF_FILE
  1801. if test 1718 -ne `wc -c <'test.pl'`; then
  1802.     echo shar: \"'test.pl'\" unpacked with wrong size!
  1803. fi
  1804. chmod +x 'test.pl'
  1805. # end of 'test.pl'
  1806. fi
  1807. if test -f 'test.rc' -a "${1}" != "-c" ; then 
  1808.   echo shar: Will not clobber existing file \"'test.rc'\"
  1809. else
  1810. echo shar: Extracting \"'test.rc'\" \(1873 characters\)
  1811. sed "s/^X//" >'test.rc' <<'END_OF_FILE'
  1812. X#!/bin/rc
  1813. X#    test.rc - rc shell script to test out the parseargs command!
  1814. X#
  1815. X#   NOTE: This script tests Byron Rakitzis' version of rc. NOT the
  1816. X#         Plan 9 version (there are a few differences such as the use
  1817. X#         of "else" instead of "if not" and the use of "$^variable").
  1818. X#
  1819. XNAME=`{basename $0}
  1820. X
  1821. XARGUMENTS='
  1822. X  "?", ARGHIDDEN, argUsage, NULL,    "Help : print usage and exit",
  1823. X  "S", ARGVALOPT, argStr,   string,  "STRing : optional string arg",
  1824. X  "g", ARGLIST,   argStr,   groups,  "newsGROUPS : groups to test",
  1825. X  "r", ARGOPT,    argInt,   count,   "REPcount <# to repeat each group>",
  1826. X  "d", ARGOPT,    argStr,   dirname, "DIRectory : working directory",
  1827. X  "x", ARGOPT,    argBool,  xflag,   "Xflag : turn on X-mode",
  1828. X  "y", ARGOPT,    argUBool, yflag,   "Yflag : turn off Y-mode",
  1829. X  "s", ARGOPT,    argChar,  sepch,   "SEPchar : field separator",
  1830. X  "f", ARGLIST,   argStr,   files,   "files : files to process",
  1831. X  "n", ARGREQ|ARGPOS, argStr, name,  "name : name to use",
  1832. X  " ", ARGLIST,   argStr,   argv,      "argv : any remaining arguments",
  1833. X  ENDOFARGS
  1834. X'
  1835. X
  1836. Xyflag='TRUE'     ## set defaults (dir="."; count=1; sepch=',') ##
  1837. Xcount=1
  1838. Xsepch=','
  1839. X
  1840. X## parse command-line and save assignments in a temporary file ##
  1841. Xif ( parseargs -s rc -e ARGUMENTS -u -- $^NAME $* >/tmp/tmp$pid ) {
  1842. X   ## evaluate results from parseargs and remove temporary file
  1843. X   . /tmp/tmp$pid;  rm -f /tmp/tmp$pid
  1844. X} else {
  1845. X  rm -f /tmp/tmp$pid;
  1846. X  exit 2  ## non-zero status (usage given)
  1847. X}
  1848. X
  1849. X
  1850. X## echo  the parsed arguments (use defaults if not defined)
  1851. Xecho 'ARGUMENTS:'
  1852. Xecho '=========='
  1853. Xecho 'Name='"$name", 'Count='$count
  1854. Xecho 'XFlag='"$xflag", 'YFlag='"$yflag"
  1855. Xecho 'Directory='"$dirname", 'SepChar='"$sepch"
  1856. Xecho 'Groups='"$groups"
  1857. Xecho 'Files='"$files"
  1858. Xecho 'string_flag='$^string_flag
  1859. Xecho 'String='"$string"
  1860. Xecho 'argv=' "$argv"
  1861. X
  1862. Xparseargs -a $^ARGUMENTS -U $^NAME     ## print usage ##
  1863. END_OF_FILE
  1864. if test 1873 -ne `wc -c <'test.rc'`; then
  1865.     echo shar: \"'test.rc'\" unpacked with wrong size!
  1866. fi
  1867. chmod +x 'test.rc'
  1868. # end of 'test.rc'
  1869. fi
  1870. if test -f 'test.sh' -a "${1}" != "-c" ; then 
  1871.   echo shar: Will not clobber existing file \"'test.sh'\"
  1872. else
  1873. echo shar: Extracting \"'test.sh'\" \(1790 characters\)
  1874. sed "s/^X//" >'test.sh' <<'END_OF_FILE'
  1875. X#!/bin/sh
  1876. X#    test.sh - Bourne shell script to test out the parseargs command!
  1877. X#
  1878. XNAME="`basename $0`";  DOT=".";
  1879. X
  1880. XARGUMENTS="
  1881. X  '?', ARGHIDDEN, argUsage, NULL,    'Help : print usage and exit',
  1882. X  'S', ARGVALOPT, argStr,   string,  'STRing : optional string arg',
  1883. X  'g', ARGLIST,   argStr,   groups,  'newsGROUPS : groups to test',
  1884. X  'r', ARGOPT,    argInt,   count,   'REPcount <# to repeat each group>',
  1885. X  'd', ARGOPT,    argStr,   dirname, 'DIRectory : working directory',
  1886. X  'x', ARGOPT,    argBool,  xflag,   'Xflag : turn on X-mode',
  1887. X  'y', ARGOPT,    argUBool, yflag,   'Yflag : turn off Y-mode',
  1888. X  's', ARGOPT,    argChar,  sepch,   'SEPchar : field separator',
  1889. X  'f', ARGLIST,   argStr,   files,   'files : files to process',
  1890. X  'n', ARGREQ|ARGPOS, argStr, name,  'name : name to use',
  1891. X  ' ', ARGLIST,   argStr,   -- ,     'argv : any remaining arguments',
  1892. X  ENDOFARGS
  1893. X"
  1894. Xexport ARGUMENTS
  1895. X
  1896. Xyflag='TRUE'     ## set defaults (dir="."; count=1; sepch=',') ##
  1897. X
  1898. X## parse command-line and save assignments in a temporary file ##
  1899. Xparseargs -s sh -e ARGUMENTS -u -- "$NAME" "$@" > /tmp/tmp$$
  1900. Xif [ $? -ne 0 ]
  1901. X  then rm -f /tmp/tmp$$; exit 2  ## non-zero status (usage given)
  1902. Xfi
  1903. X
  1904. X## evaluate results from parseargs and remove temporary file
  1905. X$DOT /tmp/tmp$$;  rm -f /tmp/tmp$$
  1906. X
  1907. X## echo  the parsed arguments (use defaults if not defined)
  1908. Xecho "ARGUMENTS:"
  1909. Xecho "=========="
  1910. Xecho "Name='$name', Count='${count:-1}'"
  1911. Xecho "XFlag='$xflag', YFlag='$yflag'"
  1912. Xecho "Directory='${dirname:-"."}', SepChar='${sepch:-","}'"
  1913. Xecho "Groups='$groups'"
  1914. Xecho "Files='$files'"
  1915. Xif [ "$string_flag" ]
  1916. X  then string=${string:-"!string arg ommitted on cmd-line!"}
  1917. X  else string="default string"
  1918. Xfi
  1919. Xecho "String='$string'"
  1920. Xecho "New Positional Parameters='$*'"
  1921. X
  1922. Xparseargs -a "$ARGUMENTS" -U "$NAME"     ## print usage ##
  1923. END_OF_FILE
  1924. if test 1790 -ne `wc -c <'test.sh'`; then
  1925.     echo shar: \"'test.sh'\" unpacked with wrong size!
  1926. fi
  1927. chmod +x 'test.sh'
  1928. # end of 'test.sh'
  1929. fi
  1930. if test -f 'test.tcl' -a "${1}" != "-c" ; then 
  1931.   echo shar: Will not clobber existing file \"'test.tcl'\"
  1932. else
  1933. echo shar: Extracting \"'test.tcl'\" \(1616 characters\)
  1934. sed "s/^X//" >'test.tcl' <<'END_OF_FILE'
  1935. X#!/usr/bin/tcl -q
  1936. X
  1937. Xsource parseargs.tcl
  1938. X
  1939. Xset arguments {
  1940. X  { '?', ARGHIDDEN, argUsage, NULL,    "Help : print usage and exit" },
  1941. X  { 'S', ARGVALOPT, argStr,   string,  "STRing : optional string arg" },
  1942. X  { 'g', ARGLIST,   argStr,   groups,  "newsGROUPS : groups to test" },
  1943. X  { 'r', ARGOPT,    argInt,   count,   "REPcount : group repeat count" },
  1944. X  { 'd', ARGOPT,    argStr,   dirname, "DIRectory : working directory" },
  1945. X  { 'x', ARGOPT,    argBool,  xflag,   "Xflag : turn on X-mode" },
  1946. X  { 'y', ARGOPT,    argUBool, yflag,   "Yflag : turn off Y-mode" },
  1947. X  { 's', ARGOPT,    argChar,  sepch,   "SEPchar : field separator" },
  1948. X  { 'f', ARGLIST,   argStr,   files,   "files : files to process" },
  1949. X  { 'n', ARGREQ|ARGPOS, argStr, name,  "name : name to use" },
  1950. X  { ' ', ARGLIST,   argStr,   argv,    "argv : any remaining arguments" },
  1951. X  ENDOFARGS
  1952. X}
  1953. X
  1954. Xset count 1
  1955. Xset dirname "."
  1956. Xset sepch ","
  1957. Xset xflag ""
  1958. Xset yflag "TRUE"
  1959. Xset files {}
  1960. Xset groups {}
  1961. Xset name ""
  1962. Xset string ""
  1963. Xset string_flag ""
  1964. X
  1965. Xeval [ parseargs -u -a $arguments $scriptName $argv ]
  1966. X
  1967. X## print  the parsed arguments (use defaults if not defined)
  1968. Xputs stdout "ARGUMENTS:"
  1969. Xputs stdout "=========="
  1970. Xputs stdout "Groups = $groups"
  1971. Xputs stdout "Count = $count"
  1972. Xputs stdout "Directory = $dirname"
  1973. Xputs stdout "XFlag = $xflag"
  1974. Xputs stdout "YFlag = $yflag"
  1975. Xputs stdout "SepChar = $sepch"
  1976. Xputs stdout "Name = $name"
  1977. Xputs stdout "Files = $files"
  1978. Xif {( "$string_flag" != "") } {
  1979. X  if {( "$string" == "" )} {
  1980. X    set string "!string arg ommitted on cmd-line!"
  1981. X  }
  1982. X} else {
  1983. X  set string "default string"
  1984. X}
  1985. Xputs stdout "String = $string"
  1986. Xputs stdout "argv = $argv"
  1987. X
  1988. END_OF_FILE
  1989. if test 1616 -ne `wc -c <'test.tcl'`; then
  1990.     echo shar: \"'test.tcl'\" unpacked with wrong size!
  1991. fi
  1992. chmod +x 'test.tcl'
  1993. # end of 'test.tcl'
  1994. fi
  1995. echo shar: End of archive 1 \(of 10\).
  1996. cp /dev/null ark1isdone
  1997. MISSING=""
  1998. for I in 1 2 3 4 5 6 7 8 9 10 ; do
  1999.     if test ! -f ark${I}isdone ; then
  2000.     MISSING="${MISSING} ${I}"
  2001.     fi
  2002. done
  2003. if test "${MISSING}" = "" ; then
  2004.     echo You have unpacked all 10 archives.
  2005.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  2006. else
  2007.     echo You still need to unpack the following archives:
  2008.     echo "        " ${MISSING}
  2009. fi
  2010. ##  End of shell archive.
  2011. exit 0
  2012.  
  2013. exit 0 # Just in case...
  2014.