home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume17 / parseargs / part03 < prev    next >
Encoding:
Internet Message Format  |  1991-03-18  |  61.4 KB

  1. From: brad@hcx1.ssd.csd.harris.com (Brad Appleton)
  2. Newsgroups: comp.sources.misc
  3. Subject: v17i048:  parseargs - functions to parse command line arguments, Part03/12
  4. Message-ID: <1991Mar17.200625.17814@sparky.IMD.Sterling.COM>
  5. Date: 17 Mar 91 20:06:25 GMT
  6. Approved: kent@sparky.imd.sterling.com
  7. X-Checksum-Snefru: df4d8af5 051ef17c b8e27396 09a0aa05
  8.  
  9. Submitted-by: Brad Appleton <brad@hcx1.ssd.csd.harris.com>
  10. Posting-number: Volume 17, Issue 48
  11. Archive-name: parseargs/part03
  12.  
  13. This is part 3 of parseargs
  14.  
  15. #!/bin/sh
  16. # this is Part.03 (part 3 of a multipart archive)
  17. # do not concatenate these parts, unpack them in order with /bin/sh
  18. # file parseargs/argtype3.txt continued
  19. #
  20. if test ! -r _shar_seq_.tmp; then
  21.     echo 'Please unpack part 1 first!'
  22.     exit 1
  23. fi
  24. (read Scheck
  25.  if test "$Scheck" != 3; then
  26.     echo Please unpack part "$Scheck" next!
  27.     exit 1
  28.  else
  29.     exit 0
  30.  fi
  31. ) < _shar_seq_.tmp || exit 1
  32. if test ! -f _shar_wnt_.tmp; then
  33.     echo 'x - still skipping parseargs/argtype3.txt'
  34. else
  35. echo 'x - continuing file parseargs/argtype3.txt'
  36. sed 's/^X//' << 'SHAR_EOF' >> 'parseargs/argtype3.txt' &&
  37. X     end).
  38. X
  39. X     ArgStr ensures that the very last item in a vector    of
  40. X     strings (the one accessed as vec.array[ vec.count ]) will
  41. X     always be NULL.
  42. X
  43. X
  44. X
  45. X
  46. X
  47. Page 2
  48. X
  49. X
  50. X
  51. X
  52. X
  53. X
  54. ARGTYPE(3)                           ARGTYPE(3)
  55. X
  56. X
  57. X
  58. CHARACTER-TYPES
  59. X     ArgChar assigns the given character to the    value referenced
  60. X     by    arg_valp(ad) (unless the argument is a vector in which
  61. X     case the given character is appended to the end).
  62. X
  63. X     ArgChar ensures that the very last    item in    a vector of char-
  64. X     acter (the    one accessed as    vec.array[ vec.count ])    will
  65. X     always be a NULL byte so that the resulting vector    may also
  66. X     be    used as    a NULL terminated string.
  67. X
  68. X     Unlike argStr, argChar will translate character escape
  69. X     sequences such as `\n' and    `\012'.
  70. X
  71. INTEGER-TYPES
  72. X     Each of these functions converts the given    string to the
  73. X     desired integral type. The    value may be specified as an
  74. X     octal number by specifying    the first digit    to be 0. Simi-
  75. X     larly, If the first two characters    are `0x' then the number
  76. X     is    treated    as hexadecimal.
  77. X
  78. FLOATING-POINT-TYPES
  79. X     Each of these functions converts the given    string to the
  80. X     desired floating-point type.
  81. X
  82. BOOLEAN-TYPES
  83. X     ArgBool and argSBool set a    boolean    value (if no value is
  84. X     given).  ArgUBool unsets a    boolean    value (if no value is
  85. X     given). ArgTBool toggles a    boolean    value (if no value is
  86. X     given). If    a value    is supplied to any of these routines,
  87. X     then the string is    looked up in a table and assigned the
  88. X     corresponding value.
  89. X
  90. X     If    a value    is supplied for    an argument that was matched via
  91. X     its single    character name and is part of the same argv ele-
  92. X     ment as the argument-name (so that    both ARGKEYWORD    and
  93. X     ARGVALSEP are not set), then only the first character of the
  94. X     value is used (unless it is not found in our table, in which
  95. X     case the value is ignored and the default action is taken).
  96. X     The table used for    single-character-options is the    follow-
  97. X     ing:
  98. X
  99. X     `0' or `-'
  100. X      The corresponding boolean flag is set    to FALSE.
  101. X
  102. X     `1' or `+'
  103. X      The corresponding boolean flag is set    to TRUE.
  104. X
  105. X     `^' or `~'
  106. X      The corresponding boolean flag is toggled.
  107. X
  108. X     The possible argument strings for long-options (keywords)
  109. X     are as follows (case-insensitive):
  110. X
  111. X
  112. X
  113. Page 3
  114. X
  115. X
  116. X
  117. X
  118. X
  119. X
  120. ARGTYPE(3)                           ARGTYPE(3)
  121. X
  122. X
  123. X
  124. X     ``0'', ``-'', ``OFF'', or ``FALSE''
  125. X      The corresponding boolean flag is set    to FALSE.
  126. X
  127. X     ``1'', ``+'', ``ON'', or ``TRUE''
  128. X      The corresponding boolean flag is set    to TRUE.
  129. X
  130. LIST TYPES
  131. X     The listStr argument translation routine is only intended
  132. X     for use on    behalf of arguments that have the ARGLIST flag
  133. X     enabled. It will allocate space for a new node (and for the
  134. X     new string    if copyf is set) and append it to the end of the
  135. X     list. The argument-list may later be deallocated by invoking
  136. X     the function listFree and passing it the address of the
  137. X     first item    in the list.
  138. X
  139. X
  140. X     VecFree is    a macro    that is    used to    deallocate argument-
  141. X     vectors.  It will free the    array and flags    fields of a vec-
  142. X     tor, set them to NULL, and    set the    count field to zero. Vec-
  143. X     DeepFree is a macro that is similar to vecFree but    will
  144. X     additionally look at each item in the array; any component
  145. X     of    the array that had ARGCOPYF enabled will also be deallo-
  146. X     cated.  Both macros are given the vector structure    to free
  147. X     followed by the type of the items in the vector.
  148. X
  149. SEE ALSO
  150. X     parseargs(3), parseargs(1),
  151. X
  152. X
  153. X
  154. X
  155. X
  156. X
  157. X
  158. X
  159. X
  160. X
  161. X
  162. X
  163. X
  164. X
  165. X
  166. X
  167. X
  168. X
  169. X
  170. X
  171. X
  172. X
  173. X
  174. X
  175. X
  176. X
  177. X
  178. X
  179. Page 4
  180. X
  181. X
  182. X
  183. SHAR_EOF
  184. echo 'File parseargs/argtype3.txt is complete' &&
  185. chmod 0664 parseargs/argtype3.txt ||
  186. echo 'restore of parseargs/argtype3.txt failed'
  187. Wc_c="`wc -c < 'parseargs/argtype3.txt'`"
  188. test 7427 -eq "$Wc_c" ||
  189.     echo 'parseargs/argtype3.txt: original size 7427, current size' "$Wc_c"
  190. rm -f _shar_wnt_.tmp
  191. fi
  192. # ============= parseargs/doc/Makefile ==============
  193. if test ! -d 'parseargs/doc'; then
  194.     echo 'x - creating directory parseargs/doc'
  195.     mkdir 'parseargs/doc'
  196. fi
  197. if test -f 'parseargs/doc/Makefile' -a X"$1" != X"-c"; then
  198.     echo 'x - skipping parseargs/doc/Makefile (File already exists)'
  199.     rm -f _shar_wnt_.tmp
  200. else
  201. > _shar_wnt_.tmp
  202. echo 'x - extracting parseargs/doc/Makefile (Text)'
  203. sed 's/^X//' << 'SHAR_EOF' > 'parseargs/doc/Makefile' &&
  204. # $Header: Man.mk,v 1.0 90/03/05 09:21:28 brad Exp $
  205. X
  206. ###
  207. # target directories
  208. ###
  209. MAN1=    man1
  210. MAN3=    man3
  211. LOCALMAN=    local_man
  212. MANDIR=    /usr/man/${LOCALMAN}
  213. CATMANDIR=    /usr/catman/${LOCALMAN}
  214. X
  215. ###
  216. # commands
  217. ###
  218. COL=    col
  219. COLFLAGS=    -b
  220. SOELIM=    /usr/ucb/soelim
  221. MANTOCATMAN=    /usr/ucb/mantocatman
  222. TROFF=    roff
  223. TRFLAGS=    -man -dimagen1
  224. NROFF=    nroff
  225. NRFLAGS=    -man
  226. SPELL=    spell
  227. COPY=    /bin/cp
  228. DEL=    /bin/rm -f
  229. X
  230. ###
  231. # files used
  232. ###
  233. INCS=    *.inc
  234. SRCS=    argtype.man3  parseargs.man1  parseargs.man3  parsecntl.man3
  235. MANIFEST=    Manifest
  236. MAN3FILES=    argtype.3  parseargs.3  parsecntl.3
  237. MAN1FILES=    parseargs.1
  238. CATMAN3FILES=    argtype.3.z  parseargs.3.z  parsecntl.3.z
  239. CATMAN1FILES=    parseargs.1.z
  240. X
  241. ###
  242. # target dependencies
  243. ###
  244. .SUFFIXES: .man1 .man3 .1 .3
  245. X
  246. .man1.1:
  247. X    ${SOELIM} $< >$*.1
  248. X    ${MANTOCATMAN} $*.1
  249. X
  250. .man3.3:
  251. X    ${SOELIM} $< >$*.3
  252. X    ${MANTOCATMAN} $*.3
  253. X
  254. ###
  255. # give a usage message if no target is given
  256. ###
  257. usage:
  258. X    @echo "Usage: make <target>"
  259. X    @echo " "
  260. X    @echo "where <target> is one of the following: "
  261. X    @echo " "
  262. X    @echo "   install  -- to install the documentation"
  263. X    @echo "   print    -- to print the documentation"
  264. X    @echo "   view     -- to view the documentation"
  265. X    @echo "   text     -- to build text copies of the documentation"
  266. X    @echo "   spell    -- to spell check the documentation"
  267. X    @echo "   clean    -- to remove files"
  268. X
  269. ###
  270. # installation dependencies
  271. ###
  272. install: man1  man3
  273. X
  274. man1: ${MAN1FILES}
  275. X    ${COPY} ${MAN1FILES} ${MANDIR}/${MAN1}
  276. X    ${COPY} ${CATMAN1FILES} ${CATMANDIR}/${MAN1}
  277. X
  278. man3: ${MAN3FILES}
  279. X    ${COPY} ${MAN3FILES} ${MANDIR}/${MAN3}
  280. X    ${COPY} ${CATMAN3FILES} ${CATMANDIR}/${MAN3}
  281. X
  282. ###
  283. # include dependencies
  284. ###
  285. argtype.3:
  286. parseargs.1:
  287. parseargs.3:
  288. parsecntl.3:
  289. X
  290. X
  291. ###
  292. # maintenance dependencies
  293. ###
  294. clean:
  295. X    ${DEL} ${MAN1FILES} ${MAN3FILES} ${CATMAN1FILES} ${CATMAN3FILES}
  296. X
  297. clobber: clean
  298. X    ${DEL} *.txt
  299. X
  300. spell: ${INCS} ${SRCS}}
  301. X    ${SPELL} ${SPELLFLAGS} ${INCS} ${SRCS}
  302. X
  303. print: ${MANFILES} ${INCS}
  304. X    ${TROFF} ${TRFLAGS} ${SRCS}
  305. X
  306. text: ascii
  307. txt: ascii
  308. ascii:
  309. X    ${NROFF} ${NRFLAGS} argtype.man3 | ${COL} ${COLFLAGS} >argtype3.txt
  310. X    ${NROFF} ${NRFLAGS} parseargs.man1 | ${COL} ${COLFLAGS} >parseargs1.txt
  311. X    ${NROFF} ${NRFLAGS} parseargs.man3 | ${COL} ${COLFLAGS} >parseargs3.txt
  312. X    ${NROFF} ${NRFLAGS} parsecntl.man3 | ${COL} ${COLFLAGS} >parsecntl3.txt
  313. X
  314. view: ${MANFILES} ${INCS}
  315. X    ${NROFF} ${NRFLAGS} ${SRCS}
  316. X
  317. SHAR_EOF
  318. chmod 0664 parseargs/doc/Makefile ||
  319. echo 'restore of parseargs/doc/Makefile failed'
  320. Wc_c="`wc -c < 'parseargs/doc/Makefile'`"
  321. test 2300 -eq "$Wc_c" ||
  322.     echo 'parseargs/doc/Makefile: original size 2300, current size' "$Wc_c"
  323. rm -f _shar_wnt_.tmp
  324. fi
  325. # ============= parseargs/doc/arg_macros.inc ==============
  326. if test -f 'parseargs/doc/arg_macros.inc' -a X"$1" != X"-c"; then
  327.     echo 'x - skipping parseargs/doc/arg_macros.inc (File already exists)'
  328.     rm -f _shar_wnt_.tmp
  329. else
  330. > _shar_wnt_.tmp
  331. echo 'x - extracting parseargs/doc/arg_macros.inc (Text)'
  332. sed 's/^X//' << 'SHAR_EOF' > 'parseargs/doc/arg_macros.inc' &&
  333. .\"----------------------------------------------------------------------------
  334. .\"-- This text was extracted using the following command:
  335. .\"--   xdoc -man -p '[ \t]*' -s ARGDESC-MACROS ../parseargs.h
  336. .\"----------------------------------------------------------------------------
  337. .SH "ARGDESC MACROS"
  338. .PP
  339. The following macros are used to extract and query the attributes
  340. of a pointer to a preprocessed arg-descriptor:
  341. .\"---------------------------------------------
  342. .IP "\fIarg_cname\fP(ad)"
  343. Return the single-character name of an argument.
  344. .\"---------------------------------------------
  345. .IP "\fIarg_flags\fP(ad)"
  346. Return the argument flags of an argument.  The flags themselves may be
  347. manipulated using the \s-1BTEST\s+1, \s-1BSET\s+1, and \s-1BCLEAR\s+1
  348. macros defined in <useful.h>.
  349. .\"---------------------------------------------
  350. .IP "\fIarg_type\fP(ad)"
  351. Return the pointer to the value-translation-routine of an argument.
  352. .\"---------------------------------------------
  353. .IP "\fIarg_valp\fP(ad)"
  354. Return the pointer to the value of this argument.
  355. .\"---------------------------------------------
  356. .IP "\fIarg_sname\fP(ad)"
  357. Return the string name of an argument.
  358. .\"---------------------------------------------
  359. .IP "\fIarg_sdesc\fP(ad)"
  360. Return the description of an argument. If a description was supplied,
  361. the \fI\s-1ARGDESCRIBED\s+1\fP flag will be set and the description will
  362. immediately follow the terminating NUL byte of the string name.
  363. .\"---------------------------------------------
  364. .IP "\fIARG_isDESCRIBED\fP(ad)"
  365. Evaluates to \s-1TRUE\s+1 only if an argument description was provided.
  366. .\"---------------------------------------------
  367. .IP "\fIarg_description\fP(ad)"
  368. Return the description string (or an empty string if no description
  369. was given) for this argument.
  370. .\"---------------------------------------------
  371. .IP "\fIARG_isPOSITIONAL\fP(ad)"
  372. Evaluates to \s-1TRUE\s+1 if this argument may be positionally matched.
  373. .\"---------------------------------------------
  374. .IP "\fIARG_isPOSONLY\fP(ad)"
  375. Evaluates to \s-1TRUE\s+1 if this argument may only be positionally matched.
  376. .\"---------------------------------------------
  377. .IP "\fIARG_isLIST\fP(ad)"
  378. Evaluates to \s-1TRUE\s+1 if this argument is an arglist.
  379. .\"---------------------------------------------
  380. .IP "\fIARG_isVEC\fP(ad)"
  381. Evaluates to \s-1TRUE\s+1 if this argument is a vector.
  382. .\"---------------------------------------------
  383. .IP "\fIARG_isMULTIVAL\fP(ad)"
  384. Evaluates to \s-1TRUE\s+1 if this argument is an arglist or a vector.
  385. .\"---------------------------------------------
  386. .IP "\fIARG_isVALTAKEN\fP(ad)"
  387. Evaluates to \s-1TRUE\s+1 if this argument does NOT take a value.
  388. .\"---------------------------------------------
  389. .IP "\fIARG_isGIVEN\fP(ad)"
  390. Evaluates to \s-1TRUE\s+1 if this argument was given on the command-line.
  391. .\"---------------------------------------------
  392. .IP "\fIARG_isVALGIVEN\fP(ad)"
  393. Evaluates to \s-1TRUE\s+1 if the argument value was given on the command-line.
  394. .\"---------------------------------------------
  395. .IP "\fIARG_isREQUIRED\fP(ad)"
  396. Evaluates to \s-1TRUE\s+1 if this argument is required.
  397. .\"---------------------------------------------
  398. .IP "\fIARG_isVALOPTIONAL\fP(ad)"
  399. Evaluates to \s-1TRUE\s+1 if the argument value is optional.
  400. .\"---------------------------------------------
  401. .IP "\fIARG_isVALSEPARATE\fP(ad)"
  402. Evaluates to \s-1TRUE\s+1 if the argument value is optional.
  403. .\"---------------------------------------------
  404. .IP "\fIARG_isHIDDEN\fP(ad)"
  405. Evaluates to \s-1TRUE\s+1 if this argument is omitted from usage messages.
  406. .\"---------------------------------------------
  407. SHAR_EOF
  408. chmod 0664 parseargs/doc/arg_macros.inc ||
  409. echo 'restore of parseargs/doc/arg_macros.inc failed'
  410. Wc_c="`wc -c < 'parseargs/doc/arg_macros.inc'`"
  411. test 3591 -eq "$Wc_c" ||
  412.     echo 'parseargs/doc/arg_macros.inc: original size 3591, current size' "$Wc_c"
  413. rm -f _shar_wnt_.tmp
  414. fi
  415. # ============= parseargs/doc/argdesc.inc ==============
  416. if test -f 'parseargs/doc/argdesc.inc' -a X"$1" != X"-c"; then
  417.     echo 'x - skipping parseargs/doc/argdesc.inc (File already exists)'
  418.     rm -f _shar_wnt_.tmp
  419. else
  420. > _shar_wnt_.tmp
  421. echo 'x - extracting parseargs/doc/argdesc.inc (Text)'
  422. sed 's/^X//' << 'SHAR_EOF' > 'parseargs/doc/argdesc.inc' &&
  423. .\"----------------------------------------------------------------------------
  424. .\"-- This text was extracted using the following command:
  425. .\"--   xdoc -man -p '[ \t]*' -t STRUCT=ARGDESC ../parseargs.h
  426. .\"----------------------------------------------------------------------------
  427. .SH "THE ARGUMENT STRUCTURE"
  428. The basic type used by the \fIparseargs\fP library is the argument descriptor
  429. (or "argdesc" for short). An \s-1ARGDESC\s+1 structure is used to describe a
  430. command-line argument. Each command line argument contains various
  431. fields which need to be set and/or queried by the programmer.
  432. The individual fields of an \s-1ARGDESC\s+1 structure are desribed below:
  433. .\"---------------------------------------------
  434. .IP "\fIchar  ad_name;\fP"
  435. This is a single character which corresponds to the option-letter
  436. (case-sensitive) from the command-line that matches the argument
  437. described by this structure. Positional-arguments are denoted by
  438. putting a a space character in this field.
  439. .\"---------------------------------------------
  440. .IP "\fIargMask_t  ad_flags;\fP"
  441. This field contains the various bitflags that describe the semantics
  442. of this argument. See the \fB\s-1ARGUMENT FLAGS\s+1\fP section for more
  443. information on the possible combinations of bitmasks for this field.
  444. .\"---------------------------------------------
  445. .IP "\fIargTypePtr_t  ad_type;\fP"
  446. This field is a pointer to a type conversion function (such as the
  447. ones provided in \fIargtype\fP(3). The type conversion function is
  448. responsible for verifying the validity of the argument, allocating any
  449. necessary storage for its internal representation, and converting
  450. the command-line argument into its required internal form. The type
  451. conversion function used may be one of the pre-defined \fIargtype\fP(3)
  452. functions. The function is given three parameters: The first is
  453. a pointer to the \s-1ARGDESC\s+1 struct in question, the second is the
  454. string-value (if any) supplied on the command-line, and the third
  455. is a boolean value that is \s-1TRUE\s+1 only if the second parameter points
  456. to temporary storage (and hence may need to be copied).
  457. In the case of \fIparseargs\fP(1) this field must correspond to the name
  458. of one of the argument type functions described in \fIargtype\fP(3).
  459. .\"---------------------------------------------
  460. .IP "\fIARBPTR  ad_valp;\fP"
  461. This field is a generic pointer to the storage used to represent
  462. the internal value of the command-line argument. It may be a
  463. pointer to a number, a boolean value, a string, a list, or anything
  464. else for which there exists a corresponding arg-type function to
  465. use in the \fIad_type\fP field. In the case of of \fIparseargs\fP(1) this
  466. field must be the name of the corresponding shell variable which eventually
  467. hold the value of the argument given on the command-line.
  468. .\"---------------------------------------------
  469. .IP "\fIconst char  *ad_prompt;\fP"
  470. This field contains the long-name of the argument and an optional
  471. description (the description must be separated from the long-name by
  472. at least one whitespace characters and may optionally be enclosed in
  473. a set of balanced delimiters (such as parentheses, curly-braces,
  474. square-brackets, or angle-brackets. If the long-name contains any
  475. uppercase characters, then the substring of long-name consisting of
  476. all uppercase characters is used as the argument name and the entire
  477. long-name is used as the name of the argument-value (if a value my be
  478. supplied). The long-name may be matched by supplying a unique prefix
  479. of either the argument name or the argument-value name.
  480. SHAR_EOF
  481. chmod 0664 parseargs/doc/argdesc.inc ||
  482. echo 'restore of parseargs/doc/argdesc.inc failed'
  483. Wc_c="`wc -c < 'parseargs/doc/argdesc.inc'`"
  484. test 3543 -eq "$Wc_c" ||
  485.     echo 'parseargs/doc/argdesc.inc: original size 3543, current size' "$Wc_c"
  486. rm -f _shar_wnt_.tmp
  487. fi
  488. # ============= parseargs/doc/argflags.inc ==============
  489. if test -f 'parseargs/doc/argflags.inc' -a X"$1" != X"-c"; then
  490.     echo 'x - skipping parseargs/doc/argflags.inc (File already exists)'
  491.     rm -f _shar_wnt_.tmp
  492. else
  493. > _shar_wnt_.tmp
  494. echo 'x - extracting parseargs/doc/argflags.inc (Text)'
  495. sed 's/^X//' << 'SHAR_EOF' > 'parseargs/doc/argflags.inc' &&
  496. .\"----------------------------------------------------------------------------
  497. .\"-- This text was extracted using the following command:
  498. .\"--   xdoc -man -p '[ \t]*' -s ARG-FLAGS ../parseargs.h
  499. .\"----------------------------------------------------------------------------
  500. .SH "ARGUMENT FLAGS"
  501. .PP
  502. These are the possible bitmasks that may be turned ON or OFF in
  503. the \fIad_flags\fP field of an \fI\s-1ARGDESC\s+1\fP structure.
  504. .\"---------------------------------------------
  505. .IP "\fI\s-1ARGOPT\s+1\fP"
  506. This flag is actually a dummy flag (i.e. it is the default). This flag
  507. specifies that the command-line argument is optional (need not appear
  508. on the command-line). It is only needed if no other flags are used to
  509. define the given argument.  If other flags are given and \fI\s-1ARGREQ\s+1\fP
  510. is \s-1NOT\s+1 one of them, then \fI\s-1ARGOPT\s+1\fP is always assumed.
  511. .\"---------------------------------------------
  512. .IP "\fI\s-1ARGREQ\s+1\fP"
  513. The associated command argument is required on the command-line.
  514. .\"---------------------------------------------
  515. .IP "\fI\s-1ARGPOS\s+1\fP"
  516. The associated command argument is positonal. The difference between
  517. using this flag to indicate a positional argument and between using
  518. a blank in the \fIad_name\fP field to indicate a positional arguments is
  519. the following: If this flag is set but the \fIad_name\fP of the argument
  520. is non-blank, then this argument may be matched either positionally
  521. or by keyword. If the \fIad_name\fP field is blank, then this argument may
  522. only be matched positionally.
  523. .\"---------------------------------------------
  524. .IP "\fI\s-1ARGNOVAL\s+1\fP"
  525. The associated command argument takes no value (as in "\fB\-x\fI value\fR");
  526. Its mere presence (or lack thereof) on the command-line is sufficient
  527. to determine the necessary action(s) to take (as in "\fB\-x\fP").
  528. Boolean argument types and Pseudo-argument types automatically default to
  529. \fI\s-1ARGNOVAL\s+1\fP.
  530. .\"---------------------------------------------
  531. .IP "\fI\s-1ARGVALOPT\s+1\fP"
  532. This flag is used to indicate that the command-line argument takes a value
  533. (as in "\fB\-s\fI string\fR" or "\fB/str\fP=\fIstring\fP") but that the value
  534. to this command-line argument is \s-1NOT\s+1 required (hence simply
  535. "\fB\-s\fP" or "\fB/str\fP" is also permissable).
  536. .\"---------------------------------------------
  537. .IP "\fI\s-1ARGVALREQ\s+1\fP"
  538. Another "dummy" flag. Unless \fI\s-1ARGNOVAL\s+1\fP or \fI\s-1ARGVALOPT\s+1\fP
  539. is specified, \fI\s-1ARGVALREQ\s+1\fP is always assumed. This flag indicates
  540. that the value to a command-line argument is required (hence
  541. "\fB\-s\fI string\fR" is okay but just "\fB\-s\fP" is not).
  542. .\"---------------------------------------------
  543. .IP "\fI\s-1ARGHIDDEN\s+1\fP"
  544. Don't display this argument in usage messages but still attempt to
  545. match it against strings given on the command-line.
  546. .\"---------------------------------------------
  547. .IP "\fI\s-1ARGLIST\s+1\fP"
  548. A variable number of values are used for this argument (and hence may
  549. use more than one or two argv elements from the command-line as in
  550. "\fB\-l\fI val1 val2\fR ..."). The list of values must be stored in an
  551. .I ArgList
  552. structure (\s-1NOT\s+1 a vector structure), an the corresponding argument-type
  553. function should be one of the \fIlistXxxx\fP functions.
  554. .\"---------------------------------------------
  555. .IP "\fI\s-1ARGVEC\s+1\fP"
  556. A variable number of values are used for this argument (and hence may
  557. use more than one or two argv elements from the command-line as in
  558. in "\fB\-v\fI val1 val2\fR ..."). The list of values must be stored in a
  559. vector structure (\s-1NOT\s+1 an \fIArgList\fP structure).
  560. .\"---------------------------------------------
  561. .PP
  562. The following bitmasks may also be present, but, unlike the above masks
  563. which must be specified by the programmer at initialization time, the
  564. following masks must only be read (never set) by the programmer. They may
  565. be queried by using the \fIpc_\s-1ARGFLAGS\s+1\fP function code and the
  566. mode \fIpc_\s-1READ\s+1\fP with \fIparsecntl\fP(3).
  567. .\"---------------------------------------------
  568. .IP "\fI\s-1ARGGIVEN\s+1\fP"
  569. The argument \s-1WAS\s+1 given on the command-line.
  570. .\"---------------------------------------------
  571. .IP "\fI\s-1ARGVALGIVEN\s+1\fP"
  572. The value for this argument was given on the command-line.
  573. .\"---------------------------------------------
  574. .IP "\fI\s-1ARGVALSEP\s+1\fP"
  575. The value to this argument was supplied in a separate argv element
  576. from the argument itself (as in "\fB\-x\fI value\fR" as opposed to
  577. "\fB\-x\fIvalue\fR").
  578. .\"---------------------------------------------
  579. .IP "\fI\s-1ARGKEYWORD\s+1\fP"
  580. This argument was matched as a keyword (long-form) on the command-line
  581. and not as a single character.
  582. .\"---------------------------------------------
  583. .IP "\fI\s-1ARGDESCRIBED\s+1\fP"
  584. This argument was given a description by the programmer at
  585. initialization.
  586. .\"---------------------------------------------
  587. .IP "\fI\s-1ARGCOPYF\s+1\fP"
  588. This flag is only used for lists and vectors (multivalued arguments)
  589. and is used on a per-item basis. If it is set, it means that the 
  590. corresponding value in the vector/list required space to be allocated
  591. (such as the duplication of a temporary string).
  592. .\"---------------------------------------------
  593. SHAR_EOF
  594. chmod 0664 parseargs/doc/argflags.inc ||
  595. echo 'restore of parseargs/doc/argflags.inc failed'
  596. Wc_c="`wc -c < 'parseargs/doc/argflags.inc'`"
  597. test 5228 -eq "$Wc_c" ||
  598.     echo 'parseargs/doc/argflags.inc: original size 5228, current size' "$Wc_c"
  599. rm -f _shar_wnt_.tmp
  600. fi
  601. # ============= parseargs/doc/argtype.man3 ==============
  602. if test -f 'parseargs/doc/argtype.man3' -a X"$1" != X"-c"; then
  603.     echo 'x - skipping parseargs/doc/argtype.man3 (File already exists)'
  604.     rm -f _shar_wnt_.tmp
  605. else
  606. > _shar_wnt_.tmp
  607. echo 'x - extracting parseargs/doc/argtype.man3 (Text)'
  608. sed 's/^X//' << 'SHAR_EOF' > 'parseargs/doc/argtype.man3' &&
  609. .\" $Header: argtype.3,v 1.0 90/11/17 11:34:06 brad Exp $
  610. .TH ARGTYPE 3
  611. .SH NAME
  612. argtype \- argument type functions used by parseargs(3)
  613. .SH SYNOPSIS
  614. #include <parseargs.h>
  615. .PP
  616. .nf
  617. \s-1BOOL\s+1  argUsage(  argdesc,  argstr,  copyf  );
  618. \s-1BOOL\s+1  argEnd(  argdesc,  argstr,  copyf  );
  619. \s-1BOOL\s+1  argDummy(  argdesc,  argstr,  copyf  );
  620. \s-1BOOL\s+1  argBool(  argdesc,  argstr,  copyf  );
  621. \s-1BOOL\s+1  argSBool(  argdesc,  argstr,  copyf  );
  622. \s-1BOOL\s+1  argUBool(  argdesc,  argstr,  copyf  );
  623. \s-1BOOL\s+1  argTBool(  argdesc,  argstr,  copyf  );
  624. \s-1BOOL\s+1  argChar(  argdesc,  argstr,  copyf  );
  625. \s-1BOOL\s+1  argStr(  argdesc,  argstr,  copyf  );
  626. \s-1BOOL\s+1  argInt(  argdesc,  argstr,  copyf  );
  627. \s-1BOOL\s+1  argShort(  argdesc,  argstr,  copyf  );
  628. \s-1BOOL\s+1  argLong(  argdesc,  argstr,  copyf  );
  629. \s-1BOOL\s+1  argFloat(  argdesc,  argstr,  copyf  );
  630. \s-1BOOL\s+1  argDouble(  argdesc,  argstr,  copyf  );
  631. \s-1BOOL\s+1  listStr(  argdesc,  argstr,  copyf  );
  632. \s-1void\s+1  listFree(  arglist  );
  633. \s-1void\s+1  vecFree(  argvec, type  );
  634. \s-1void\s+1  vecDeepFree(  argvec, type  );
  635. X
  636. \s-1ARGDESC\s+1  *argdesc;
  637. char  *argstr;
  638. \s-1BOOL\s+1  copyf;
  639. ArgList  *arglist;
  640. .fi
  641. .SH "DESCRIPTION"
  642. .PP
  643. Each of these converts a parameter value to the internal form,
  644. including validity checking.  Their parameters and return values
  645. all behave similarly. One of these routines are called when an
  646. argunent of that particular type is matched by one of the argument
  647. parsing function in \fIparseargs\fP(3). When such an argument is matched,
  648. its argument translation routines is invoked and is passed (1) the address of
  649. the argument descriptor for the matched argument, (2) the possible argument
  650. string for that matched argument, and (3) a boolean filed that is \s-1TRUE\s+1
  651. only if the second parameter points to temporary storage (indicating that
  652. some copying may need to be done instead of just pointing to the same object).
  653. X
  654. Once the argument translation routine is invoked, it is responsible for
  655. converting the argument string to the desired internal form (perhaps a number),
  656. and assigning the resultant value to the \fIarg_valp(ad)\fP field of the
  657. argument descriptor (this includes handling any necessary (re)allocation if
  658. the matched argument has the \s-1ARGVEC\s+1 flag enabled). If the argument is
  659. an \s-1ARGVEC\s+1 or \s-1ARGLIST\s+1 then the routine is responsible for
  660. allocating any space, copying the arg-flags to the value-specific flags, and
  661. setting the \s-1ARGCOPYF\fP flag for the value if it needs to be allocated
  662. as well.
  663. X
  664. .SH "RETURN VALUE"
  665. .IP "TRUE" 8
  666. The conversion was successful and the entire value was used.
  667. X
  668. .IP "FALSE" 8
  669. The conversion failed.  The reason for failure should be
  670. diagnosed using \fIusrerr\fP(3).
  671. X
  672. .IP "-\fIN\fP" 8
  673. The conversion was successful but only \fIN\fP characters of the value
  674. were used, the remaining characters may still match other arguments.
  675. X
  676. .SH "PSEUDO-TYPES"
  677. .PP
  678. .I ArgUsage
  679. is used to specify an argument that causes the command usage to be printed.
  680. X
  681. .I ArgDummy
  682. is used to force an item to show up in usage-messages but
  683. the item itself is never matched against any argumenmts from the
  684. command-line.
  685. X
  686. .I ArgEnd
  687. is used by Amiga style command-lines to indicate an argument
  688. that forces all remaining arguments to be considered positional args.
  689. X
  690. These three are dummy functions. The routines themselves do nothing
  691. of importance, we just need to have their addresses available for
  692. identification in the corresponding command-line styles.
  693. .SH "STRING-TYPES"
  694. .PP
  695. \fIArgStr\fP is one of the few argument translation routines that actually
  696. uses the \fIcopyf\fP flag. If \fIcopyf\fP is true then the string is
  697. duplicated.
  698. X
  699. \fIArgStr\fP assigns the given string (or a copy of it) to the value
  700. referenced by \fIarg_valp(ad)\fP (unless the argument is a vector in which
  701. case the given string is appended to the end).
  702. X
  703. \fIArgStr\fP ensures that the very last item in a vector of strings (the one
  704. accessed as \f4vec.array[ vec.count ]\fP) will always be \s-1NULL\s+1.
  705. .SH "CHARACTER-TYPES"
  706. .PP
  707. .I ArgChar
  708. assigns the given character to the value referenced by \fIarg_valp(ad)\fP
  709. (unless the argument is a vector in which case the given character
  710. is appended to the end).
  711. X
  712. .I ArgChar
  713. ensures that the very last item in a vector of character (the one
  714. accessed as \f4vec.array[ vec.count ]\fP) will always be a \s-1NULL\s+1
  715. byte so that the resulting vector may also be used as a \s-1NULL\s+1
  716. terminated string.
  717. X
  718. Unlike \fIargStr\fP, \fIargChar\fP will translate character escape sequences
  719. such as `\\n' and `\\012'.
  720. .SH "INTEGER-TYPES"
  721. .PP
  722. Each of these functions converts the given string to the desired
  723. integral type. The value may be specified as an octal number by
  724. specifying the first digit to be 0. Similarly, If the first two 
  725. characters are `0x' then the number is treated as hexadecimal.
  726. .SH "FLOATING-POINT-TYPES"
  727. .PP
  728. Each of these functions converts the given string to the desired
  729. floating-point type.
  730. .SH "BOOLEAN-TYPES"
  731. .PP
  732. \fIArgBool\fP and \fIargSBool\fP set a boolean value (if no value is given).
  733. \fIArgUBool\fP unsets a boolean value (if no value is given). \fIArgTBool\fP
  734. toggles a boolean value (if no value is given). If a value is
  735. supplied to any of these routines, then the string is looked up
  736. in a table and assigned the corresponding value.
  737. X
  738. If a value is supplied for an argument that was matched via its
  739. single character name and is part of the same argv element as the
  740. argument-name (so that both \fBARGKEYWORD\fP and \fBARGVALSEP\fP
  741. are not set),
  742. then only the first character of the value is used (unless it is
  743. not found in our table, in which case the value is ignored and the
  744. default action is taken). The table used for single-character-options
  745. is the following:
  746. .IP "`0' or `-'"
  747. The corresponding boolean flag is set to \s-1FALSE\s+1.
  748. .IP "`1' or `+'"
  749. The corresponding boolean flag is set to \s-1TRUE\s+1.
  750. .IP "`^' or `~'"
  751. The corresponding boolean flag is toggled.
  752. .PP
  753. The possible argument strings for long-options (keywords) are as follows
  754. (case-insensitive):
  755. .IP "``0'', ``-'', ``OFF'', or ``FALSE''"
  756. The corresponding boolean flag is set to \s-1FALSE\s+1.
  757. .IP "``1'', ``+'', ``ON'', or ``TRUE''"
  758. The corresponding boolean flag is set to \s-1TRUE\s+1.
  759. .SH LIST TYPES
  760. .PP
  761. The \fIlistStr\fP argument translation routine is only intended for use
  762. on behalf of arguments that have the \s-1ARGLIST\s+1 flag enabled. It will
  763. allocate space for a new node (and for the new string if \fIcopyf\fP is
  764. set) and append it to the end of the list. The argument-list may later
  765. be deallocated by invoking the function \fIlistFree\fP and passing it
  766. the address of the first item in the list.
  767. X
  768. .PP
  769. \fIVecFree\fP is a macro that is used to deallocate argument-vectors.
  770. It will free the array and flags fields of a vector, set them to
  771. \s-1NULL\s+1, and set the count field to zero. \fIVecDeepFree\fP is
  772. a macro that is similar to \fIvecFree\fP but will additionally look
  773. at each item in the array; any component of the array that had
  774. \s-1ARGCOPYF\s+1 enabled will also be deallocated.
  775. Both macros are given the vector structure to free followed by the
  776. type of the items in the vector.
  777. .SH SEE ALSO
  778. .IR parseargs (3),
  779. .IR parseargs (1),
  780. SHAR_EOF
  781. chmod 0664 parseargs/doc/argtype.man3 ||
  782. echo 'restore of parseargs/doc/argtype.man3 failed'
  783. Wc_c="`wc -c < 'parseargs/doc/argtype.man3'`"
  784. test 7204 -eq "$Wc_c" ||
  785.     echo 'parseargs/doc/argtype.man3: original size 7204, current size' "$Wc_c"
  786. rm -f _shar_wnt_.tmp
  787. fi
  788. # ============= parseargs/doc/argvalopt.inc ==============
  789. if test -f 'parseargs/doc/argvalopt.inc' -a X"$1" != X"-c"; then
  790.     echo 'x - skipping parseargs/doc/argvalopt.inc (File already exists)'
  791.     rm -f _shar_wnt_.tmp
  792. else
  793. > _shar_wnt_.tmp
  794. echo 'x - extracting parseargs/doc/argvalopt.inc (Text)'
  795. sed 's/^X//' << 'SHAR_EOF' > 'parseargs/doc/argvalopt.inc' &&
  796. .\"----------------------------------------------------------------------------
  797. .\"-- This text was extracted using the following command:
  798. .\"--   xdoc -man -p '[ \t]*' -s ARGVALOPT ../parseargs.c
  799. .\"----------------------------------------------------------------------------
  800. .SH OPTIONS WITH OPTIONAL ARGUMENTS
  801. .PP
  802. Options that may take an optional argument need special consideration.
  803. The shell programmer needs to know whether or not the option was given, and
  804. (if given) if it was accompanied by an argument. In order to accommodate this
  805. need, \fBparseargs\fP will set an additional shell variable for each argument
  806. that is given the \s-1ARGVALOPT\s+1 flag if it is supplied on the command line
  807. \fIregardless of whether or not it was accompanied by its optional argument\fP.
  808. If the user has defined an option which may optionally
  809. take an argument and the option appears on the command line
  810. \fIwith or without\fP its associated argument, then the shell variable
  811. \fI<name>\fP\f4_flag\fP will be assigned the value ``\f4TRUE\fP''
  812. (or the value supplied with the \fB\-T\fP option to \fBparseargs\fP) where
  813. \fI<name>\fP is the name of the shell variable associated with the option
  814. in the argument description string.
  815. SHAR_EOF
  816. chmod 0664 parseargs/doc/argvalopt.inc ||
  817. echo 'restore of parseargs/doc/argvalopt.inc failed'
  818. Wc_c="`wc -c < 'parseargs/doc/argvalopt.inc'`"
  819. test 1216 -eq "$Wc_c" ||
  820.     echo 'parseargs/doc/argvalopt.inc: original size 1216, current size' "$Wc_c"
  821. rm -f _shar_wnt_.tmp
  822. fi
  823. # ============= parseargs/doc/bugs.inc ==============
  824. if test -f 'parseargs/doc/bugs.inc' -a X"$1" != X"-c"; then
  825.     echo 'x - skipping parseargs/doc/bugs.inc (File already exists)'
  826.     rm -f _shar_wnt_.tmp
  827. else
  828. > _shar_wnt_.tmp
  829. echo 'x - extracting parseargs/doc/bugs.inc (Text)'
  830. sed 's/^X//' << 'SHAR_EOF' > 'parseargs/doc/bugs.inc' &&
  831. .\"----------------------------------------------------------------------------
  832. .\"-- This text was extracted using the following command:
  833. .\"--   xdoc -man -n -p '[ \t]*' -I BUGS ../parseargs.c
  834. .\"----------------------------------------------------------------------------
  835. .SH BUGS
  836. .PP
  837. It does not make sense to use any arguments of type \fIargTBool\fP
  838. since \fBparseargs\fP currently has no way of knowing what the
  839. initial value of the variable is. For this reason, \fIargTBool\fP
  840. is not recognized as a valid argument type (even though it is used
  841. by \fIparseargs\fP\s-1\^(3)\s+1\|). By the same token, since the
  842. user cannot create their own arguments types on the fly from a shell-script,
  843. \fI\s-1ARGNOVAL\s+1\fP is not recognized as a valid argument flag.
  844. .PP
  845. Commas will not be interpreted properly if any field in the
  846. argument specification string contains double quotes that are nested
  847. inside of double quotes, or single quotes that are nested inside of
  848. single quotes.
  849. .PP
  850. Inside the argument specification string, any repeated string of commas
  851. that does not appear inside of double or single quotes will be treated
  852. as a single comma.
  853. .PP
  854. Text descriptions for argument entries are automatically formatted in
  855. usage messages. Any attempt by the user to include tabs and/or newlines
  856. in the description will cause it to be formatted improperly.
  857. .PP
  858. \fIParseargs\fP cannot properly preserve any newlines in shell variables
  859. if the \fBeval\fP command is used to read its output (this is a shortcoming
  860. of the eval command, not of parseargs). If the user is concerned about this
  861. particular case, then the user should redirect the output from \fBparseargs\fP
  862. to a temporary file and use the \fBsource\fP command in \fIcsh\fP or the
  863. dot command (`\fB.\fP') in sh and ksh, to interpret the results; otherwise,
  864. newlines will be translated into spaces, or characters following
  865. a newline may be lost, in any variables that are set by \fBparseargs\fP.
  866. .PP
  867. Parseargs(1) is subject to the same caveats as parseargs(3). Refer to the
  868. \s-1CAVEATS\s+1 section of the parseargs(3) manual page(s) for more information.
  869. SHAR_EOF
  870. chmod 0664 parseargs/doc/bugs.inc ||
  871. echo 'restore of parseargs/doc/bugs.inc failed'
  872. Wc_c="`wc -c < 'parseargs/doc/bugs.inc'`"
  873. test 2103 -eq "$Wc_c" ||
  874.     echo 'parseargs/doc/bugs.inc: original size 2103, current size' "$Wc_c"
  875. rm -f _shar_wnt_.tmp
  876. fi
  877. # ============= parseargs/doc/caveats.inc ==============
  878. if test -f 'parseargs/doc/caveats.inc' -a X"$1" != X"-c"; then
  879.     echo 'x - skipping parseargs/doc/caveats.inc (File already exists)'
  880.     rm -f _shar_wnt_.tmp
  881. else
  882. > _shar_wnt_.tmp
  883. echo 'x - extracting parseargs/doc/caveats.inc (Text)'
  884. sed 's/^X//' << 'SHAR_EOF' > 'parseargs/doc/caveats.inc' &&
  885. .\"----------------------------------------------------------------------------
  886. .\"-- This text was extracted using the following command:
  887. .\"--   xdoc -man -n -p '[ \t]*' -I CAVEATS ../xparse.c
  888. .\"----------------------------------------------------------------------------
  889. .SH CAVEATS
  890. .PP
  891. Because of the way argument parsing is implemented under \s-1UNIX\s+1,
  892. \s-1MS-DOS\s+1, and \s-1OS/2\s+1,
  893. option arguments which contain a leading dash (`\-') (or whatever the
  894. option prefix character is defined to be) may \fInot\fP be specified
  895. as a separate argument on the command line, it must be part of the
  896. same argument. That is to say that if a program has a \fB\-f\fP option
  897. that requires a string argument, then the following:
  898. .sp 4p
  899. .RS
  900. .ft 4
  901. \-f\-arg
  902. .ft R
  903. .RE
  904. .sp 4p
  905. will properly assign the string ``\fB\-arg\fP'' to the option whereas
  906. the following:
  907. .sp 4p
  908. .RS
  909. .ft 4
  910. \-f\0\-arg
  911. .RE
  912. .sp 4p
  913. will be interpreted by \fIparseargs\fP as two option strings: the first
  914. of which (``\fB\-f\fP'') is missing a required argument and the second of
  915. which (``\fB\-arg\fP'') will most likely be flagged as an invalid option.
  916. .PP
  917. Similarly, if the user requires an \s-1\fIARGLIST\fP\s+1 option
  918. to take multiple arguments with leading dashes then the following
  919. method must be used: It is a ``feature'' of \fIparseargs\fP that
  920. \s-1\fIARGLIST\fP\s+1 arguments are always appended to the current
  921. list of arguments for the given option. Thus, if ``\fB\-f\fP'' is
  922. an option taking a list of arguments, then the following are all
  923. equivalent:
  924. .sp 8p
  925. .RS
  926. .ft 4
  927. \-farg1 arg2
  928. .sp 4p
  929. \-f arg1 arg2
  930. .sp 4p
  931. \-farg1 \-farg2
  932. .sp 4p
  933. \-f arg1 \-f arg2
  934. .ft R
  935. .RE
  936. .sp 8p
  937. Hence multiple ``leading dash'' arguments may specified as follows:
  938. .sp 4p
  939. .RS
  940. .ft 4
  941. \-f\-dash_arg1 \-f\-dash_arg2  ...
  942. .ft R
  943. .RE
  944. SHAR_EOF
  945. chmod 0664 parseargs/doc/caveats.inc ||
  946. echo 'restore of parseargs/doc/caveats.inc failed'
  947. Wc_c="`wc -c < 'parseargs/doc/caveats.inc'`"
  948. test 1768 -eq "$Wc_c" ||
  949.     echo 'parseargs/doc/caveats.inc: original size 1768, current size' "$Wc_c"
  950. rm -f _shar_wnt_.tmp
  951. fi
  952. # ============= parseargs/doc/cmd_macros.inc ==============
  953. if test -f 'parseargs/doc/cmd_macros.inc' -a X"$1" != X"-c"; then
  954.     echo 'x - skipping parseargs/doc/cmd_macros.inc (File already exists)'
  955.     rm -f _shar_wnt_.tmp
  956. else
  957. > _shar_wnt_.tmp
  958. echo 'x - extracting parseargs/doc/cmd_macros.inc (Text)'
  959. sed 's/^X//' << 'SHAR_EOF' > 'parseargs/doc/cmd_macros.inc' &&
  960. .\"----------------------------------------------------------------------------
  961. .\"-- This text was extracted using the following command:
  962. .\"--   xdoc -man -p '[ \t]*' -s CMD-MACROS ../parseargs.h
  963. .\"----------------------------------------------------------------------------
  964. .SH "CMD MACROS"
  965. Parseargs.h defines a set of macros to allow a more "self documenting"
  966. approach to declaring argument-descriptor arrays. The "old-style" is
  967. still accepted (but if used it is recommended that the \s-1STARTOFARGS\s+1
  968. macro is used in conjunction with \s-1ENDOFARGS\s+1).
  969. An example use of these macros (which, with one exception, all begin with
  970. ``\s-1CMD\s+1'') follows:
  971. .RS
  972. .nf
  973. .ft 4
  974. #include <parseargs.h>
  975. X
  976. static BOOL bflag = FALSE;
  977. static char *arg1 = CHARNULL;
  978. static char *arg2 = CHARNULL;
  979. X
  980. static
  981. X   CMD_OBJECT
  982. X      MyCmd
  983. X
  984. X   CMD_NAME
  985. X      "mycmd -- one line statement of purpose"
  986. X
  987. X   CMD_DESCRIPTION
  988. X      "Mycmd will try really really hard to run without errors \\
  989. and do whatever the heck it is supposed to do. If (God forbid) \\
  990. something should actually go wrong it will say so."
  991. X
  992. X   CMD_ARGUMENTS
  993. X      'H', ARGOPT, argUsage, __ NULL,
  994. X      "Help -- display usage and quit",
  995. X
  996. X      'b', ARGOPT, argSBool, __ &bflag,
  997. X      "bflag -- turn on `b'-mode (whatever that is)",
  998. X
  999. X      ' ', ARGREQ, argStr, __ &arg1,
  1000. X      "arg1 -- first argument to this spiffy program",
  1001. X
  1002. X      ' ', ARGOPT, argStr, __ &arg2,
  1003. X      "arg2 -- optional second argument to this spiffy program",
  1004. X
  1005. X      END_ARGUMENTS
  1006. X   CMD_END
  1007. X
  1008. main( int argc, char *argv[] )
  1009. {
  1010. X   (void) parseargs( argv, MyCmd );
  1011. X   (void) dostuff();
  1012. X   exit( 0 );
  1013. }
  1014. .ft R
  1015. .fi
  1016. .RE
  1017. SHAR_EOF
  1018. chmod 0664 parseargs/doc/cmd_macros.inc ||
  1019. echo 'restore of parseargs/doc/cmd_macros.inc failed'
  1020. Wc_c="`wc -c < 'parseargs/doc/cmd_macros.inc'`"
  1021. test 1627 -eq "$Wc_c" ||
  1022.     echo 'parseargs/doc/cmd_macros.inc: original size 1627, current size' "$Wc_c"
  1023. rm -f _shar_wnt_.tmp
  1024. fi
  1025. # ============= parseargs/doc/defargs.inc ==============
  1026. if test -f 'parseargs/doc/defargs.inc' -a X"$1" != X"-c"; then
  1027.     echo 'x - skipping parseargs/doc/defargs.inc (File already exists)'
  1028.     rm -f _shar_wnt_.tmp
  1029. else
  1030. > _shar_wnt_.tmp
  1031. echo 'x - extracting parseargs/doc/defargs.inc (Text)'
  1032. sed 's/^X//' << 'SHAR_EOF' > 'parseargs/doc/defargs.inc' &&
  1033. .\"----------------------------------------------------------------------------
  1034. .\"-- This text was extracted using the following command:
  1035. .\"--   xdoc -man -p '[ \t]*' -s DEFAULT-ARGUMENT ../xparse.c
  1036. .\"----------------------------------------------------------------------------
  1037. .SH "DEFAULT ARGUMENT DESCRIPTOR"
  1038. .PP
  1039. Each argdesc-array has an initial default argument list (which may
  1040. be reset using the pc_DEFARGS function code with parsecntl). This initial
  1041. default argument-list contains `?' and `H' which may be used as single
  1042. character keywords to display command-usage for all command-line styles.
  1043. Similarly, ``?'', ``H'', and ``Help'' may be used as long-keywords to display
  1044. command-usage for all command-line styles.  In Addition, for \s-1VMS\s+1
  1045. style commands, the qualifiers \fB\s-1/INPUT\s+1=\fIfile\fR,
  1046. \fB\s-1/OUTPUT\s+1=\fIfile\fR, and \fB\s-1/ERROR\s+1=\fIfile\fR, may be used
  1047. to redirect stdin, stdout, and stderr (respectively) to a file.  For
  1048. Amiga\s-1DOS\s+1 style commands, the keyword ``ENDKWDS'' may be used to
  1049. disable parsing for any more keywords on the command-line.
  1050. SHAR_EOF
  1051. chmod 0664 parseargs/doc/defargs.inc ||
  1052. echo 'restore of parseargs/doc/defargs.inc failed'
  1053. Wc_c="`wc -c < 'parseargs/doc/defargs.inc'`"
  1054. test 1093 -eq "$Wc_c" ||
  1055.     echo 'parseargs/doc/defargs.inc: original size 1093, current size' "$Wc_c"
  1056. rm -f _shar_wnt_.tmp
  1057. fi
  1058. # ============= parseargs/doc/env_args.inc ==============
  1059. if test -f 'parseargs/doc/env_args.inc' -a X"$1" != X"-c"; then
  1060.     echo 'x - skipping parseargs/doc/env_args.inc (File already exists)'
  1061.     rm -f _shar_wnt_.tmp
  1062. else
  1063. > _shar_wnt_.tmp
  1064. echo 'x - extracting parseargs/doc/env_args.inc (Text)'
  1065. sed 's/^X//' << 'SHAR_EOF' > 'parseargs/doc/env_args.inc' &&
  1066. .\"----------------------------------------------------------------------------
  1067. .\"-- This text was extracted using the following command:
  1068. .\"--   xdoc -man -n -p '[ \t]*' -I DESCRIPTION -f get_user_defaults ../xparse.c
  1069. .\"----------------------------------------------------------------------------
  1070. .SH "SUPPLYING DEFAULT ARGUMENTS"
  1071. Programs that use \fIparseargs\fP may be given default arguments under UNIX
  1072. and PCs through the use of environment variables (symbols are used for VMS
  1073. systems). If a  C-program or shell-script uses parseargs to implement a
  1074. command named ``\fIcmd\fP'' then the environment variable ``\s-1CMD_ARGS\s+1''
  1075. will be parsed for any "default" arguments before the command-line is parsed.
  1076. The command-line will over-ride any options that are specified in this
  1077. environment variable (except that \s-1ARGLIST\s+1s and \s-1ARGVEC\s+1s set in
  1078. ``\s-1CMD_ARGS\s+1'' will be appended from the command-line
  1079. X
  1080. It is important to note that the contents of the ``\s-1\fICMD\fP_ARGS\s+1''
  1081. environment variable are NOT expanded by the shell and hence any special
  1082. characters (such as quotes or back-slashes) will NOT be escaped or removed
  1083. by \fIparseargs\fP. Furthermore, it will not be possible to try and use a
  1084. tab, space, or newline character in the environment variable as anything
  1085. other than an argument separator.
  1086. X
  1087. Lastly, parts of an option specification in ``\s-1CMD_ARGS\s+1'' may NOT be
  1088. continued on the command-line. As an example, if \fB\-f\fP requires an argument
  1089. and \s-1CMD_ARGS\s+1="\-f", then the command-line "\fIcmd  bah\fP" will NOT
  1090. assign "\fIbah\fP" as the argument to \fB\-f\fP but will instead complain about
  1091. a missing argument for \fB\-f\fP. Similarly, if \fB\-l\fP takes a list of
  1092. arguments and \s-1CMD_ARGS\s+1="\-l item1 item2", then the command-line
  1093. "\fIcmd  bah\fP", will NOT assign "\fIbah\fP" to the end of the list
  1094. containing "item1" and "item2" but will instead treat "\fIbah\fP" as 
  1095. the first positional parameter on the command-line.
  1096. SHAR_EOF
  1097. chmod 0664 parseargs/doc/env_args.inc ||
  1098. echo 'restore of parseargs/doc/env_args.inc failed'
  1099. Wc_c="`wc -c < 'parseargs/doc/env_args.inc'`"
  1100. test 1979 -eq "$Wc_c" ||
  1101.     echo 'parseargs/doc/env_args.inc: original size 1979, current size' "$Wc_c"
  1102. rm -f _shar_wnt_.tmp
  1103. fi
  1104. # ============= parseargs/doc/env_parse.inc ==============
  1105. if test -f 'parseargs/doc/env_parse.inc' -a X"$1" != X"-c"; then
  1106.     echo 'x - skipping parseargs/doc/env_parse.inc (File already exists)'
  1107.     rm -f _shar_wnt_.tmp
  1108. else
  1109. > _shar_wnt_.tmp
  1110. echo 'x - extracting parseargs/doc/env_parse.inc (Text)'
  1111. sed 's/^X//' << 'SHAR_EOF' > 'parseargs/doc/env_parse.inc' &&
  1112. .\"----------------------------------------------------------------------------
  1113. .\"-- This text was extracted using the following command:
  1114. .\"--   xdoc -man -n -p '[ \t]*' -I DESCRIPTION -f get_parse_env ../xparse.c
  1115. .\"----------------------------------------------------------------------------
  1116. .SH PARSING BEHAVIOR
  1117. The programmer may control parsing behavior through the use of
  1118. .IR parsecntl (3).
  1119. The user may set his (or her) own desired parsing
  1120. behavior through the use of the ``\s-1PARSECNTL\s+1'' environment variable.
  1121. By indicating any number of flags (possibly negated) the user will
  1122. directly modify the behavior of the parseargs library. Flags may be
  1123. combined by placing a `+' or `|' character in between flags. A switch
  1124. is negated by immediately preceding it with a `!' or `-' character.
  1125. The possible ``flags'' are given by the following table. 
  1126. Flags are case-insensitive.
  1127. .sp 4p
  1128. .IP "\fIPrompt\fP"
  1129. Prompt the user for any missing arguments that are required on the
  1130. command-line. No special escaping or quoting is performed on the
  1131. user input. Required arguments that expect a list of values will
  1132. be repeatedly prompted for (one item per line) until a blank line
  1133. (followed by a carriage return) is entered.
  1134. .\"----------------------
  1135. .IP "\fIIgnore\fP"
  1136. Ignore any unrecognized or improperly specified command-line arguments
  1137. and continue execution of the program. Normally, if an argument is
  1138. unmatched (or is improperly specified), a usage message is printed
  1139. program execution is terminated.
  1140. .\"----------------------
  1141. .IP "\fIOptsOnly\fP"
  1142. Under UNIX, setting this flag will disable the parsing of long-option
  1143. syntax. This will cause all arguments starting with '+' to always be
  1144. treated as a positional parameter (instead of a long-option).
  1145. .\"----------------------
  1146. .IP "\fIKwdsOnly\fP"
  1147. Under UNIX, setting this flag disables the parsing of single-character
  1148. options.  This will cause all arguments starting with '-' to always
  1149. be treated as a positional parameter (instead of an option).
  1150. .\"----------------------
  1151. .IP "\fILoptsOnly\fP"
  1152. Same as \fIKwdsOnly\fP.
  1153. .\"----------------------
  1154. .IP "\fIFlags1st\fP"
  1155. Setting this flag causes the parseargs library to force any and all
  1156. non-positional arguments to be specified before any positional ones.
  1157. As an example, under UNIX, if this flag is SET then parseargs will
  1158. consider the command line "cmd -x arg" to consist of one option and
  1159. one positional argument; however the command line "cmd arg -x" would
  1160. be considered to consist of two positional arguments (the -x option
  1161. will be unmatched).
  1162. X
  1163. If this flag is UNSET, then both of the previous examples are
  1164. considered to consist of one option and one positional argument.
  1165. .\"----------------------
  1166. .IP "\fICaseIgnore\fP"
  1167. Setting this flag cause character-case to be ignored when attempting
  1168. to match single-character argument names (i.e. causes "-i" and "-I"
  1169. will be considered equivalent).
  1170. .sp 4p
  1171. .PP
  1172. If the environment variable ``\s-1PARSECNTL\s+1'' is empty or
  1173. undefined, then parsing behavior set by the programmer is used.
  1174. If the programmer has not explicitly used
  1175. .IR parsecntl (3)
  1176. to modify the parsing behavior will be ``!Prompt + !Ignore'' for Unix
  1177. MS-DOS, OS/2, and AmigaDOS systems, and ``Prompt'' for VMS systems.
  1178. SHAR_EOF
  1179. chmod 0664 parseargs/doc/env_parse.inc ||
  1180. echo 'restore of parseargs/doc/env_parse.inc failed'
  1181. Wc_c="`wc -c < 'parseargs/doc/env_parse.inc'`"
  1182. test 3224 -eq "$Wc_c" ||
  1183.     echo 'parseargs/doc/env_parse.inc: original size 3224, current size' "$Wc_c"
  1184. rm -f _shar_wnt_.tmp
  1185. fi
  1186. # ============= parseargs/doc/env_usage.inc ==============
  1187. if test -f 'parseargs/doc/env_usage.inc' -a X"$1" != X"-c"; then
  1188.     echo 'x - skipping parseargs/doc/env_usage.inc (File already exists)'
  1189.     rm -f _shar_wnt_.tmp
  1190. else
  1191. > _shar_wnt_.tmp
  1192. echo 'x - extracting parseargs/doc/env_usage.inc (Text)'
  1193. sed 's/^X//' << 'SHAR_EOF' > 'parseargs/doc/env_usage.inc' &&
  1194. .\"----------------------------------------------------------------------------
  1195. .\"-- This text was extracted using the following command:
  1196. .\"--   xdoc -man -n -p '[ \t]*' -I DESCRIPTION -f get_usage_env ../xparse.c
  1197. .\"----------------------------------------------------------------------------
  1198. .SH USAGE MESSAGES
  1199. Through the use of an environment variable (or a VMS symbol), the user
  1200. may control the syntax and the verbosity of the command-usage messages
  1201. that are printed by \fIparseargs\fP. The desired level of verbosity may
  1202. be set by defining the environment variable ``\s-1USAGECNTL\s+1" to be
  1203. a combination of strings (case insensitive). The value of each string
  1204. controls one of three different ``modes'' of behavior in the displaying
  1205. of usage messages:
  1206. The first ``mode'' is ``verbose'' mode, which controls whether or not a
  1207. detailed description of each argument should accompany the usual command-line
  1208. sysnopsis. If verbose mode is ``off'', then only a command-line synopsis is
  1209. printed (this is also refferred to as ``terse'' mode). The other two ``modes''
  1210. control the displaying of option syntax and long-option syntax. A mode may
  1211. be explicitly disabled by preceding its corresponding string with the `!'
  1212. character. The ``modes'' which correspond to the possible values of the
  1213. ``\s-1USAGECNTL\s+1'' environment variable are given by the following table.
  1214. .sp 4p
  1215. .\"---------------------------------------
  1216. .IP "\fIQuiet\fP"
  1217. No usage message of any kind is displayed.
  1218. .\"---------------------------------------
  1219. .IP "\fISilent\fP"
  1220. Same as \fIQuiet\fP.
  1221. .\"---------------------------------------
  1222. .IP "\fIPaged\fP"
  1223. The usage message is piped to a pager. The pager used is named
  1224. by the ``\s-1USAGE_PAGER\s+1'' environment variable. If this
  1225. variable is unset or empty (or is not the name of an executable program)
  1226. then the pager named by the ``\s-1PAGER\s+1'' environment variable us used.
  1227. If this variable is unset or empty (or is not the name of an executable
  1228. program) then \fI/usr/ucb/more\fP is used.
  1229. .\"---------------------------------------
  1230. .IP "\fIDescription\fP"
  1231. The command description is printed.
  1232. .\"---------------------------------------
  1233. .IP "\fITerse\fP"
  1234. Terse mode, just print command-line synopsis.
  1235. .\"---------------------------------------
  1236. .IP "\fIVerbose\fP"
  1237. Verbose mode, print descriptions for each argument
  1238. .\"---------------------------------------
  1239. .IP "\fIOptions\fP"
  1240. Option syntax is displayed.
  1241. .\"---------------------------------------
  1242. .IP "\fILongOpts\fP"
  1243. Long-option syntax is displayed.
  1244. .\"---------------------------------------
  1245. .IP "\fIKeyWords\fP"
  1246. Same as \fILongOpts\fP.
  1247. .\"---------------------------------------
  1248. .sp 4p
  1249. .PP
  1250. If the environment variable ``\s-1USAGECNTL\s+1'' is empty or
  1251. undefined, then the default usage level (which is presently
  1252. ``Verbose + Options'') will be used.
  1253. SHAR_EOF
  1254. chmod 0664 parseargs/doc/env_usage.inc ||
  1255. echo 'restore of parseargs/doc/env_usage.inc failed'
  1256. Wc_c="`wc -c < 'parseargs/doc/env_usage.inc'`"
  1257. test 2820 -eq "$Wc_c" ||
  1258.     echo 'parseargs/doc/env_usage.inc: original size 2820, current size' "$Wc_c"
  1259. rm -f _shar_wnt_.tmp
  1260. fi
  1261. # ============= parseargs/doc/fparseargs3.inc ==============
  1262. if test -f 'parseargs/doc/fparseargs3.inc' -a X"$1" != X"-c"; then
  1263.     echo 'x - skipping parseargs/doc/fparseargs3.inc (File already exists)'
  1264.     rm -f _shar_wnt_.tmp
  1265. else
  1266. > _shar_wnt_.tmp
  1267. echo 'x - extracting parseargs/doc/fparseargs3.inc (Text)'
  1268. sed 's/^X//' << 'SHAR_EOF' > 'parseargs/doc/fparseargs3.inc' &&
  1269. .\"----------------------------------------------------------------------------
  1270. .\"-- This text was extracted using the following command:
  1271. .\"--   xdoc -man -n -p '[ \t]*' -I DESCRIPTION -f fparseargs ../xparse.c
  1272. .\"----------------------------------------------------------------------------
  1273. .PP
  1274. Given a readable input stream and an argdesc array, \fIfparseargs\fP
  1275. will parse arguments in a file in much the same manner as \fIparseargs\fP.
  1276. A maximum-line length of 255 characters is imposed.  NO ``escaping'' of any
  1277. kind is performed. Comments of a limited form are permitted: if the first
  1278. non-whitespace character on a line is a '#' (or '!' for \s-1VMS\s+1) then
  1279. that entire line is considered a comment and is ignored.  If a value is
  1280. provided for an argument that is NOT a list or a vector, then the value MUST
  1281. be on the same line as the argument (in other words, ``\fB\-v\fI val\fR'' is
  1282. fine but ``\fB\-v\f4\\n\fIval\fR'' is a not).
  1283. SHAR_EOF
  1284. chmod 0664 parseargs/doc/fparseargs3.inc ||
  1285. echo 'restore of parseargs/doc/fparseargs3.inc failed'
  1286. Wc_c="`wc -c < 'parseargs/doc/fparseargs3.inc'`"
  1287. test 937 -eq "$Wc_c" ||
  1288.     echo 'parseargs/doc/fparseargs3.inc: original size 937, current size' "$Wc_c"
  1289. rm -f _shar_wnt_.tmp
  1290. fi
  1291. # ============= parseargs/doc/lib_bugs.inc ==============
  1292. if test -f 'parseargs/doc/lib_bugs.inc' -a X"$1" != X"-c"; then
  1293.     echo 'x - skipping parseargs/doc/lib_bugs.inc (File already exists)'
  1294.     rm -f _shar_wnt_.tmp
  1295. else
  1296. > _shar_wnt_.tmp
  1297. echo 'x - extracting parseargs/doc/lib_bugs.inc (Text)'
  1298. sed 's/^X//' << 'SHAR_EOF' > 'parseargs/doc/lib_bugs.inc' &&
  1299. .\"----------------------------------------------------------------------------
  1300. .\"-- This text was extracted using the following command:
  1301. .\"--   xdoc -man -n -p '[ \t]*' -I BUGS  ../xparse.c
  1302. .\"----------------------------------------------------------------------------
  1303. .SH BUGS
  1304. .PP
  1305. When a non-multivalued argument appears more than once on the command-line
  1306. then only the last value supplied is used. A problem occurs however in the
  1307. following scenario: suppose `\fB\-s\fP' is an option that takes an optional
  1308. string argument (nd suppose `\fB\-x\fP' is some boolean flag). Then if the
  1309. following command-line is issued:
  1310. X
  1311. .RS
  1312. .nf
  1313. .ft 4
  1314. command  \-s string  \-x  \-s
  1315. .ft R
  1316. .fi
  1317. .RE
  1318. X
  1319. then, the argument flags will properly correspond to the second instance
  1320. of the `\fB\-s\fP' option (namely \s-1ARGGIVEN\s+1 will be set but 
  1321. \s-1ARGVALGIVEN\s+1 will be unset) but the value associated with the
  1322. option will be ``\fIstring\fP'' (because the first instance overwrote
  1323. the default).  Because of this, it may be safest to reassign the default
  1324. value if \s-1ARGGIVEN\s+1 is set but \s-1ARGVALGIVEN\s+1 is unset.
  1325. SHAR_EOF
  1326. chmod 0664 parseargs/doc/lib_bugs.inc ||
  1327. echo 'restore of parseargs/doc/lib_bugs.inc failed'
  1328. Wc_c="`wc -c < 'parseargs/doc/lib_bugs.inc'`"
  1329. test 1101 -eq "$Wc_c" ||
  1330.     echo 'parseargs/doc/lib_bugs.inc: original size 1101, current size' "$Wc_c"
  1331. rm -f _shar_wnt_.tmp
  1332. fi
  1333. # ============= parseargs/doc/lparseargs3.inc ==============
  1334. if test -f 'parseargs/doc/lparseargs3.inc' -a X"$1" != X"-c"; then
  1335.     echo 'x - skipping parseargs/doc/lparseargs3.inc (File already exists)'
  1336.     rm -f _shar_wnt_.tmp
  1337. else
  1338. > _shar_wnt_.tmp
  1339. echo 'x - extracting parseargs/doc/lparseargs3.inc (Text)'
  1340. sed 's/^X//' << 'SHAR_EOF' > 'parseargs/doc/lparseargs3.inc' &&
  1341. .\"----------------------------------------------------------------------------
  1342. .\"-- This text was extracted using the following command:
  1343. .\"--   xdoc -man -n -p '[ \t]*' -I DESCRIPTION -f lparseargs ../xparse.c
  1344. .\"----------------------------------------------------------------------------
  1345. .PP
  1346. Given an ArgList and an argdesc array, \fIlparseargs\fP
  1347. will parse arguments in a file in much the same manner as \fIparseargs\fP.
  1348. SHAR_EOF
  1349. chmod 0664 parseargs/doc/lparseargs3.inc ||
  1350. echo 'restore of parseargs/doc/lparseargs3.inc failed'
  1351. Wc_c="`wc -c < 'parseargs/doc/lparseargs3.inc'`"
  1352. test 428 -eq "$Wc_c" ||
  1353.     echo 'parseargs/doc/lparseargs3.inc: original size 428, current size' "$Wc_c"
  1354. rm -f _shar_wnt_.tmp
  1355. fi
  1356. # ============= parseargs/doc/multivals.inc ==============
  1357. if test -f 'parseargs/doc/multivals.inc' -a X"$1" != X"-c"; then
  1358.     echo 'x - skipping parseargs/doc/multivals.inc (File already exists)'
  1359.     rm -f _shar_wnt_.tmp
  1360. else
  1361. > _shar_wnt_.tmp
  1362. echo 'x - extracting parseargs/doc/multivals.inc (Text)'
  1363. sed 's/^X//' << 'SHAR_EOF' > 'parseargs/doc/multivals.inc' &&
  1364. .\"----------------------------------------------------------------------------
  1365. .\"-- This text was extracted using the following command:
  1366. .\"--   xdoc -man -p '[ \t]*' -s MULTI-VALUED_ARGUMENTS ../parseargs.h
  1367. .\"----------------------------------------------------------------------------
  1368. .SH MULTI-VALUED ARGUMENTS
  1369. .PP
  1370. .I Parseargs
  1371. supports two different types of multi-valued arguments: linked-lists and
  1372. vectors. The linked-lists are called argument lists (or arg-lists) and are 
  1373. specified by supplying the \s-1ARGLIST\s+1 flag along with an associated
  1374. \fIlistXxxx\fP argument-translation routine. The value associated with an
  1375. arg-list should be a list structure of type ArgList. The include file
  1376. \f4<parseargs.h>\fP
  1377. defines four macros for manipulating ArgList structures:
  1378. \s-1ARGLISTNULL\s+1,
  1379. \s-1L_NEXT\s+1,
  1380. \s-1L_STRING\s+1,
  1381. and \s-1L_FLAGS\s+1.
  1382. .PP
  1383. \s-1ARGLISTNULL\s+1 is simply the \s-1NULL\s+1 argument-list pointer.
  1384. \s-1L_NEXT\s+1 and \s-1L_STRING\s+1 each take a pointer to a non-\s-1NULL\s+1
  1385. ArgList structure. \s-1L_NEXT\s+1 returns the address of the next item in the
  1386. list and \s-1L_STRING\s+1 returns the string-value of the current list-item.
  1387. \s-1L_FLAGS\s+1 return the arg-flags for a given item in the list. With
  1388. non-multivalued, only the flags in the argument descriptor are needed; lists
  1389. and vectors however need a set of flags for each item they contain. 
  1390. Once an arg-list has been created, it may be deallocated using the function
  1391. .I listFree.
  1392. .I ListFree
  1393. takes two parameters, the first of which is the address of the first item in
  1394. the arg-list, and the second of which is a boolean value that is \s-1TRUE\s+1
  1395. only if each value pointed to by each item should also be deallocated.
  1396. .PP
  1397. An alternative to argument-lists is argument vectors (or arg-vectors).
  1398. Arg-vectors use the \s-1ARGVEC\s+1 flag instead of the \s-1ARGLIST\s+1 flag
  1399. and do not require a special \fIlistXxxx\fP function for each vector-type.
  1400. Each of the \fIargXxxx\fP functions is responsible for handling vectors of its
  1401. type (although some argXxx functions such as the boolean types do not support
  1402. vectors). An arg-vector is a structure which contains a count, an
  1403. array of elements (i.e. an argc/argv pair), and an array of flags, one for 
  1404. each element of argv. There are two macros in defined in
  1405. \f4<parseargs.h>\fR which are used for arg-vectors. \s-1ARGVEC_T\s+1 may be
  1406. used to declare a vector structure or a vector type;
  1407. \s-1ARGVEC_EMPTY\s+1 may be used to initialize the structure.
  1408. It is strongly recommended that \s-1ARGVEC_T\s+1 be used to declare vector
  1409. types in a typedef statement (particularly if one is using function prototypes)
  1410. but for those who insist, it may be used to directly declare a  structure.
  1411. String-vectors will always have an extra \s-1NULL\s+1-pointer at the end
  1412. such that:
  1413. X
  1414. .RS
  1415. .nf
  1416. .ft 4
  1417. ( StrVec.array[ StrVec.count ] == (char *)NULL )
  1418. .ft R
  1419. .fi
  1420. .RE
  1421. X
  1422. is always true, and character-vectors will always have an extra
  1423. \s-1NUL\s+1-character at the end such that:
  1424. X
  1425. .RS
  1426. .nf
  1427. .ft 4
  1428. ( CharVec.array[ CharVec.count ] == '\\0' )
  1429. .ft R
  1430. .fi
  1431. .RE
  1432. X
  1433. is always true. Integer and floating point vectors contain no extra
  1434. "null" elements.
  1435. X
  1436. Once created, arg-vectors may be deallocated by calling the macro
  1437. \fIvecFree\fP or the macro \fIvecDeepFree\fP and passing it the
  1438. arg-vector structure. The differemce between these two macros is 
  1439. that the latter will also free each item in the vector that required
  1440. space to be allocated (at the expense of traversing the vector).
  1441. At this writing, the only predefined argument-types that would
  1442. benefit from \fIvecDeepFree\fP is \fIargStr\fP vectors.
  1443. .PP
  1444. An example use of arg-lists, and of arg-vectors follows:
  1445. X
  1446. .RS
  1447. .nf
  1448. .ft 4
  1449. #include <parseargs.h>
  1450. X
  1451. typedef ARGVEC_T(char *) strvec_t;
  1452. X
  1453. static ArgList  *StringList = ARGLISTNULL;
  1454. static strvec_t  StringVec = ARGVEC_EMPTY(char *);
  1455. static ARGVEC_T(int)  NumberVec = ARGVEC_EMPTY(int);
  1456. X
  1457. static
  1458. X  CMD_OBJECT  Args
  1459. X  CMD_NAME    "foo -- do whatever foo does"
  1460. X  CMD_DESCRIPTION  "put a brief paragraph here"
  1461. X  CMD_ARGUMENTS
  1462. X     'l', ARGLIST, listStr, __ &StrList, "LiSt {list of strings}",
  1463. X     's', ARGVEC,  argStr,  __ &StrVec,  "STRing {vector of strings}",
  1464. X     'i', ARGVEC,  argInt,  __ &NumVec,  "NUMber {vector of numbers}",
  1465. X     END_ARGUMENTS
  1466. X  CMD_END
  1467. X
  1468. main( int argc, char *argv[] )
  1469. {
  1470. X   int i, *ls;
  1471. X
  1472. X   if ( parseargs(argv, Args) )  syserr( "parseargs failed" );
  1473. X
  1474. X   for ( ls = StrList, i=1 ; ls ; ls = L_NEXT(ls), i++ )
  1475. X      printf( "List item %d=%s, flags=%x\\n",
  1476. X              i, L_STRING(ls), L_FLAGS(ls) );
  1477. X
  1478. X   for ( i = 0 ; i < StrVec.count ; i++ )
  1479. X      printf( "String[%d]=%s, flags=%x\\n",
  1480. X              i, StrVec.array[i], StrVec.flags[i] );
  1481. X
  1482. X   for ( i = 0 ; i < NumVec.count ; i++ )
  1483. X      printf( "Number[%d]=%s, flags=%x\\n",
  1484. X              i, NumVec.array[i], NumVec.flags[i] );
  1485. X
  1486. X   listFree( StrList );
  1487. X   StrList = ARGLISTNULL;
  1488. X
  1489. X   vecDeepFree( StrVec, char * );
  1490. X   vecFree( NumVec, int );
  1491. X
  1492. X   exit( 0 );
  1493. }
  1494. X
  1495. .ft R
  1496. .fi
  1497. .RE
  1498. SHAR_EOF
  1499. chmod 0664 parseargs/doc/multivals.inc ||
  1500. echo 'restore of parseargs/doc/multivals.inc failed'
  1501. Wc_c="`wc -c < 'parseargs/doc/multivals.inc'`"
  1502. test 4932 -eq "$Wc_c" ||
  1503.     echo 'parseargs/doc/multivals.inc: original size 4932, current size' "$Wc_c"
  1504. rm -f _shar_wnt_.tmp
  1505. fi
  1506. # ============= parseargs/doc/parseargs.man1 ==============
  1507. if test -f 'parseargs/doc/parseargs.man1' -a X"$1" != X"-c"; then
  1508.     echo 'x - skipping parseargs/doc/parseargs.man1 (File already exists)'
  1509.     rm -f _shar_wnt_.tmp
  1510. else
  1511. > _shar_wnt_.tmp
  1512. echo 'x - extracting parseargs/doc/parseargs.man1 (Text)'
  1513. sed 's/^X//' << 'SHAR_EOF' > 'parseargs/doc/parseargs.man1' &&
  1514. .\" $Header: parseargs.1,v 1.0 90/07/24 Brad Appleton $
  1515. .de SS
  1516. .sp 8p
  1517. \s+1\fB\\$1\fP\s-1
  1518. .br
  1519. ..
  1520. .TH PARSEARGS 1
  1521. .nh
  1522. .SH NAME
  1523. parseargs \- parse command line arguments in shell scripts
  1524. .\"-----------------------------------------------------------
  1525. .SH SYNOPSIS
  1526. .TP 12
  1527. \fBparseargs\fP
  1528. [\fB\-U\fP]
  1529. [\fB\-M\fP]
  1530. [\fB\-T\fP\ \fIstring\fP]
  1531. [\fB\-F\fP\ \fIstring\fP]
  1532. [\fB\-A\fP]
  1533. [\fB\-a\fP\ \fIarg-spec\fP]
  1534. [\fB\-e\fP\ \fIname\fP]
  1535. [\fB\-f\fP\ \fIfile\fP]
  1536. [\fB\-l\fP]
  1537. [\fB\-o\fP]
  1538. [\fB\-s\fP\ \fIshell\fP\^]
  1539. [\fB\-u\fP]
  1540. [\fB\-i\fP]
  1541. [\fB\-p\fP]
  1542. \fB\-\^\-\fP
  1543. \fIname\fP
  1544. [\fIarguments\fP\ .\^.\^.\^]
  1545. .\"-----------------------------------------------------------
  1546. .SH OPTIONS
  1547. .TP 14
  1548. \fB\-U\fP
  1549. just print program usage, do not parse the command line
  1550. .TP 14
  1551. \fB\-M\fP
  1552. just print (n|t)roff \-man manual page template, do not parse the command line
  1553. .TP 14
  1554. \fB\-T\fP \fIstring\fP
  1555. string to use for true boolean arguments\|  (\fIdefault=``\s-1TRUE\s+1\^''\fP\|)
  1556. SHAR_EOF
  1557. true || echo 'restore of parseargs/doc/parseargs.man1 failed'
  1558. fi
  1559. echo 'End of  part 3'
  1560. echo 'File parseargs/doc/parseargs.man1 is continued in part 4'
  1561. echo 4 > _shar_seq_.tmp
  1562. exit 0
  1563. exit 0 # Just in case...
  1564. -- 
  1565. Kent Landfield                   INTERNET: kent@sparky.IMD.Sterling.COM
  1566. Sterling Software, IMD           UUCP:     uunet!sparky!kent
  1567. Phone:    (402) 291-8300         FAX:      (402) 291-4362
  1568. Please send comp.sources.misc-related mail to kent@uunet.uu.net.
  1569.