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

  1. Newsgroups: comp.sources.misc
  2. From: brad@hcx1.ssd.csd.harris.com (Brad Appleton)
  3. Subject:  v29i117:  parseargs - functions to parse command line arguments, Part02/10
  4. Message-ID: <1992May17.182252.28563@sparky.imd.sterling.com>
  5. X-Md4-Signature: 2c484de31185875751a3408ea9e7eb71
  6. Date: Sun, 17 May 1992 18:22:52 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 117
  11. Archive-name: parseargs/part02
  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 2 (of 10)."
  22. # Contents:  Intro Makefile VMSbuild.com doc/Makefile
  23. #   doc/arg_macros.inc doc/argdesc.inc doc/argflags.inc doc/bugs.inc
  24. #   doc/env_args.inc doc/env_parse.inc doc/env_usage.inc
  25. #   doc/multivals.inc doc/parsecntls.inc doc/returns.inc
  26. #   doc/shells.inc parseargs.pl parseargs.tcl strfuncs.h test.csh
  27. #   test.ksh test.zsh
  28. # Wrapped by brad@hcx1 on Thu May  7 12:12:17 1992
  29. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  30. if test -f 'Intro' -a "${1}" != "-c" ; then 
  31.   echo shar: Will not clobber existing file \"'Intro'\"
  32. else
  33. echo shar: Extracting \"'Intro'\" \(5025 characters\)
  34. sed "s/^X//" >'Intro' <<'END_OF_FILE'
  35. X
  36. X                                  PARSEARGS
  37. X
  38. X                        extracted from Eric Allman's
  39. X
  40. X                            NIFTY UTILITY LIBRARY
  41. X
  42. X                          Created by Eric P. Allman
  43. X                             <eric@Berkeley.EDU>
  44. X
  45. X                         Modified by Peter da Silva
  46. X                            <peter@Ferranti.COM>
  47. X
  48. X                   Modified and Rewritten by Brad Appleton
  49. X                          <brad@SSD.CSD.Harris.COM>
  50. X
  51. X
  52. X Welcome to parseargs! Dont let the initial size of this package scare you.
  53. X over 75% of it is English text, and more than 50% of the source is comments.
  54. X
  55. X Parseargs is a set of functions to parse command-line arguments. Unlike
  56. X getopt and its variants, parseargs does more than just split up the
  57. X command-line into some canonical form. Parseargs will actually parse the
  58. X command-line, assigning the appropriate command-line values to the
  59. X corresponding variables, and will verify the command-line syntax (and print
  60. X a usage message if necessary). Furthermore, many features of it's parsing
  61. X behavior are configurable at run-time. Some of these features include the
  62. X following:
  63. X
  64. X     o  Prompting the user for missing arguments
  65. X     o  Allowing keywords (+count=4) and/or options (-c4)
  66. X     o  Checking for default arguments in an environment variable
  67. X     o  Ignoring bad syntax instead of terminating
  68. X     o  Ignoring upper/lower case on the command-line
  69. X     o  Controlling the location of non-positional parameters
  70. X     o  Controlling the contents (syntax and verbosity) of usage messages
  71. X     o  Having long usage messages piped through a paging program
  72. X
  73. X Parseargs also allows for options that take an optional argument, and
  74. X options that take a (possibly optional) list of one or more arguments.
  75. X In addition, parseargs may be configured at compile-time to parse
  76. X command-lines in accordance with the native command-syntax of any of the
  77. X following operating systems:
  78. X
  79. X     o  Unix
  80. X     o  VAX/VMS
  81. X     o  OS/2
  82. X     o  MS-DOS
  83. X     o  AmigaDOS
  84. X
  85. X Parseargs consists of a set of C-functions to parse arguments from the
  86. X command-line, from files, from strings, from linked-lists, and from
  87. X string-vectors. Also included is a command-line interface which will parse
  88. X arguments for shell scripts (sh, csh/tcsh/itcsh, ksh, bash, zsh, and rc),
  89. X awk-scripts, perl-scripts and tcl-scripts.
  90. X
  91. X The basic structure used by parseargs is the argument-descriptor (sometimes
  92. X called "argdesc" for brevity).  An array/string of argdescs is declared by
  93. X the user to describe the command in question.  The resulting argdesc-array
  94. X is passed to all the parseargs functions and is used to hold all information
  95. X about the command. a sample argdesc-array is shown below.
  96. X
  97. X    STARTOFARGS,
  98. X    { 'a', ARGVALOPT, argStr,   &area,    "AREAcode : optional area-code" },
  99. X    { 'g', ARGLIST,   argStr,   &groups,  "newsGROUPS : groups to test" },
  100. X    { 'r', ARGOPT,    argInt,   &count,   "REPcount : repetition factor" },
  101. X    { 's', ARGOPT,    argChar,  &sepch,   "SEPchar : field separator" },
  102. X    { 'x', ARGOPT,    argBool,  &xflag,   "Xflag : turn on X-mode" },
  103. X    { ' ', ARGREQ,    argStr,   &name,    "name : name to use" },
  104. X    { ' ', ARGLIST,   argStr,   &args,    "args : any remaining arguments" },
  105. X    ENDOFARGS
  106. X
  107. X Once the above array/string is declared it is a simple matter to invoke
  108. X parseargs from C as in the following example:
  109. X
  110. X    status = parseargs( argv, argdesc_array );
  111. X
  112. X or from a shell script as in the following example:
  113. X
  114. X    echo "$ARGDESC_STR" | parseargs -s sh -- "$0" "$@" >tmp$$
  115. X    test  $? = 0  &&  . tmp$$
  116. X    /bin/rm -f tmp$$
  117. X
  118. X And before you know it, your command-line had been parsed, all variables 
  119. X have been assigned their corresponding values from the command-line, syntax
  120. X have been verified, and a usage message (if required) has been printed. 
  121. X
  122. X Under UNIX, the command-line syntax (using single character options) for the
  123. X above command would be:
  124. X
  125. X    cmdname [-a [<areacode>]] [-g <newsgroups>...] [-r <repcount>]
  126. X            [-s <sepchar>] [-x]  <name>  [<args>...]
  127. X
  128. X The UNIX command-line syntax using keywords (or long options) would be:
  129. X
  130. X    cmdname [+area [<areacode>]] [+groups <newsgroups>...] [+rep <repcount>]
  131. X            [+sep <sepchar>] [+x]  <name>  [<args>...]
  132. X
  133. X The VMS command-line syntax would be the following:
  134. X
  135. X    cmdname [/AREA[=<areacode>]] [/GROUPS=<newsgroups>[,<newsgroups>...]]
  136. X            [/REP=<repcount>] [/SEP=<sepchar>] [/X]  <name>
  137. X            [<args>[,<args>...]]
  138. X
  139. X The MS-DOS and OS/2 command-line syntax would be the following (unless the
  140. X environment variable $SWITCHAR is '-' in which case UNIX syntax is used):
  141. X
  142. X    cmdname [/a[=<areacode>]] [/g=<newsgroups>...] [/r=<repcount>]
  143. X            [/s=<sepchar>] [/x]  <name>  [<args>...]
  144. X
  145. X The AmigaDOS command-line syntax would be the following:
  146. X
  147. X    cmdname [AREA [<areacode>]] [GROUPS <newsgroups>...] [REP <repcount>]
  148. X            [SEP <sepchar>] [X]  <name>  [<args>...]
  149. X
  150. X
  151. X Please look at the README files and manpages for more detailed information!
  152. END_OF_FILE
  153. if test 5025 -ne `wc -c <'Intro'`; then
  154.     echo shar: \"'Intro'\" unpacked with wrong size!
  155. fi
  156. # end of 'Intro'
  157. fi
  158. if test -f 'Makefile' -a "${1}" != "-c" ; then 
  159.   echo shar: Will not clobber existing file \"'Makefile'\"
  160. else
  161. echo shar: Extracting \"'Makefile'\" \(4720 characters\)
  162. sed "s/^X//" >'Makefile' <<'END_OF_FILE'
  163. X# $Header: Makefile,v 2.1 89/12/30 20:59:01 eric Exp $
  164. X
  165. X###
  166. X# operating-system dependent stuff
  167. X###
  168. X.UNIVERSE =    att
  169. X#.UNIVERSE =    ucb
  170. XOS_TYPE =    unix
  171. X# OS_DEFS =    -D${OS_TYPE} -D${.UNIVERSE}_universe
  172. X
  173. X###
  174. X# targets
  175. X###
  176. XNAME =    parseargs
  177. XPROGRAM =    ${NAME}
  178. XLIBRARY =    ${NAME}
  179. XSTYLE =    unix
  180. X
  181. X###
  182. X# target directories
  183. X###
  184. XLOCAL =  /usr/local
  185. XLIBDIR = ${LOCAL}/lib
  186. XINCDIR = ${LOCAL}/include
  187. XPERLLIB = ${LIB}/perl
  188. X
  189. X###
  190. X# compilation options
  191. X###
  192. XINCLUDES =    -I.
  193. X# MODEL =    -Ms
  194. X# MODELNAME =    S
  195. X# OPT =    -O
  196. XOPT =    -g
  197. XTEST_DEFS =    
  198. XUSR_DEFS =    -DUSE_PAGER
  199. XDEFINES =    ${OS_DEFS} ${USR_DEFS} ${TEST_DEFS} -D${STYLE}_style
  200. XOPTIONS =
  201. XCFLAGS =    ${OPT} ${MODEL} ${INCLUDES} ${DEFINES} ${OPTIONS}
  202. XLINTFLAGS =    ${INCLUDES} ${DEFINES} ${OPTIONS}
  203. X
  204. X###
  205. X# libraries
  206. X###
  207. XLIBARGS =    ${MODELNAME}lib${STYLE}_args.a
  208. XLIBFILE =    ${MODELNAME}libparse.a
  209. XLOCLIBS =    ${LIBARGS}
  210. X# SYSLIBS =    -lm -lcurses -ltermcap
  211. XLIBS =    ${LOCLIBS} ${SYSLIBS}
  212. X
  213. X###
  214. X# commands
  215. X###
  216. XAR =    ar rvu
  217. XDEL =    rm -f
  218. XCOPY =    cp
  219. XCHDIR =    cd
  220. XLINT =    lint
  221. XMKTAGS =    ctags
  222. XPRINT =    pr
  223. XRANLIB =    ranlib
  224. XSHAR =    shar
  225. XSQZ =    compress -v
  226. XSTRIP =    strip
  227. X
  228. X###
  229. X# files used
  230. X###
  231. XDOCS=    doc/Makefile \
  232. X        doc/argtype.man3 \
  233. X        doc/parseargs.man1 \
  234. X        doc/parseargs.man3 \
  235. X        doc/parsecntl.man3 \
  236. X        doc/arg_macros.inc \
  237. X        doc/argdesc.inc \
  238. X        doc/argflags.inc \
  239. X        doc/argvalopt.inc \
  240. X        doc/bugs.inc \
  241. X        doc/caveats.inc \
  242. X        doc/cmd_macros.inc \
  243. X        doc/defargs.inc \
  244. X        doc/effects.inc \
  245. X        doc/env_args.inc \
  246. X        doc/env_parse.inc \
  247. X        doc/env_usage.inc \
  248. X        doc/fparseargs3.inc \
  249. X        doc/lib_bugs.inc \
  250. X        doc/lparseargs3.inc \
  251. X        doc/multivals.inc \
  252. X        doc/parseargs1.inc \
  253. X        doc/parseargs3.inc \
  254. X        doc/parsecntl3.inc \
  255. X        doc/parsecntls.inc \
  256. X        doc/parseflags.inc \
  257. X        doc/parsemodes.inc \
  258. X        doc/returns.inc \
  259. X        doc/sh_arrays.inc \
  260. X        doc/shells.inc \
  261. X        doc/sparseargs3.inc \
  262. X        doc/usage3.inc \
  263. X        doc/vparseargs3.inc
  264. XSCRIPTS =    test.sh  test.csh  test.ksh  test.rc  test.awk  test.pl
  265. XPERLSUB =    ${NAME}.pl
  266. XXXFILES =    Intro  README  MANIFEST  Makefile  Makefile.cpp
  267. X
  268. XHDRS =    ${NAME}.h \
  269. X        patchlevel.h \
  270. X        pgopen.h \
  271. X        strfuncs.h \
  272. X        useful.h
  273. X
  274. XSRCS =    ${NAME}.c \
  275. X        argtype.c \
  276. X        arglist.c \
  277. X        amiga_args.c \
  278. X        ibm_args.c \
  279. X        pgopen.c \
  280. X        stest.c \
  281. X        strfuncs.c \
  282. X        syserr.c \
  283. X        unix_args.c \
  284. X        unix_man.c \
  285. X        vms_args.c \
  286. X        vprintf.c \
  287. X        winsize.c \
  288. X        xparse.c
  289. X
  290. XOBJS =  ${STYLE}_args.o \
  291. X         arglist.o \
  292. X         argtype.o \
  293. X         pgopen.o \
  294. X         strfuncs.o \
  295. X         syserr.o \
  296. X         vprintf.o \
  297. X         winsize.o \
  298. X         xparse.o
  299. X
  300. XPROG_OBJS =  ${NAME}.o   unix_man.o
  301. XTEST_OBJS =  stest.o
  302. X
  303. XFILES =    ${XXFILES} ${DOCS} ${HDRS} ${SRCS} ${PERLSUB} ${SCRIPTS}
  304. X
  305. X###
  306. X# target dependencies
  307. X###
  308. Xall: ${LIBARGS} test ${PROGRAM}
  309. X
  310. Xtest: ${STYLE}_test
  311. X
  312. X${STYLE}_test :  stest.o ${LOCLIBS}
  313. X    ${CC} ${CFLAGS} -o ${STYLE}_test  stest.o ${LOCLIBS} ${SYSLIBS}
  314. X
  315. X${LIBARGS}: ${OBJS}
  316. X    ${AR} $@ ${OBJS}
  317. X    ${RANLIB} $@
  318. X
  319. X${PROGRAM}: ${PROG_OBJS} ${LOCLIBS}
  320. X    ${CC} ${CFLAGS} -o $@ ${PROG_OBJS} ${LOCLIBS} ${SYSLIBS}
  321. X
  322. X###
  323. X# object dependencies
  324. X###
  325. X${NAME}.o:    ${NAME}.c ${NAME}.h patchlevel.h strfuncs.h useful.h
  326. Xamiga_args.o:    amiga_args.c ${NAME}.h pgopen.h strfuncs.h useful.h \
  327. X                exit_codes.h
  328. Xarglist.o:    arglist.c ${NAME}.h strfuncs.h useful.h
  329. Xargtype.o:    argtype.c ${NAME}.h strfuncs.h useful.h
  330. Xibm_args.o:    ibm_args.c ${NAME}.h pgopen.h strfuncs.h useful.h exit_codes.h
  331. Xpgopen.o:    pgopen.c useful.h exit_codes.h
  332. Xstest.o:    stest.c ${NAME}.h useful.h
  333. Xstrfuncs.o:    strfuncs.c useful.h
  334. Xsyserr.o:    syserr.c useful.h
  335. Xunix_args.o:    unix_args.c ${NAME}.h pgopen.h strfuncs.h useful.h exit_codes.h
  336. Xunix_man.o:    unix_man.c ${NAME}.h strfuncs.h useful.h
  337. Xvms_args.o:    vms_args.c ${NAME}.h pgopen.h strfuncs.h useful.h exit_codes.h
  338. Xvprintf.o:    vprintf.c useful.h
  339. Xwinsize.o:    winsize.c useful.h
  340. Xxparse.o:    xparse.c ${NAME}.h strfuncs.h useful.h exit_codes.h
  341. X
  342. X###
  343. X# installation dependencies
  344. X###
  345. Xinstall:  ${INCDIR}/${NAME}.h \
  346. X         ${LIBDIR}/${LIBFILE} \
  347. X         ${LOCAL}/${PROGRAM}
  348. X
  349. X ${INCDIR}/${NAME}.h: ${NAME}.h useful.h
  350. X    ( ${CHDIR} ${INCDIR}; ${DEL} ${NAME}.h useful.h )
  351. X    ${COPY} ${NAME}.h useful.h ${INCDIR}
  352. X
  353. X ${LIBDIR}/${LIBFILE}: ${LIBARGS}
  354. X    ${DEL}   ${LIBDIR}/${LIBFILE}
  355. X    ${COPY} ${LIBARGS}   ${LIBDIR}/${LIBFILE}
  356. X    ${RANLIB}   ${LIBDIR}/${LIBFILE}
  357. X
  358. X ${LOCAL}/${PROGRAM}: ${PROGRAM} ${PERLSUB}
  359. X    ${DEL} ${LOCAL}/${PROGRAM} ${PERLIB}/${PERLSUB}
  360. X    ${COPY} ${PROGRAM} ${LOCAL}
  361. X    ${STRIP} ${LOCAL}/${PROGRAM}
  362. X    ${COPY} ${PERLSUB} ${PERLLIB}
  363. X
  364. X###
  365. X# maintenance dependencies
  366. X###
  367. Xlint: ${SRCS}
  368. X    ${LINT} ${LINTFLAGS} ${SRCS}
  369. X
  370. Xshar: ${NAME}.shar
  371. X
  372. X${NAME}.shar: ${FILES}
  373. X    ${DEL} ${NAME}.shar
  374. X    ${SHAR} ${FILES}  >${NAME}.shar
  375. X
  376. Xclean:
  377. X    ${DEL} ${OBJS} ${PROG_OBJS} ${TEST_OBJS}
  378. X    ${DEL} tags core .exrc
  379. X
  380. Xclobber: clean
  381. X    ${DEL} ${LIBARGS}  ${PROGRAM}  ${STYLE}_test
  382. X
  383. Xtags: ${SRCS} ${HDRS}
  384. X    ${MKTAGS} ${SRCS} ${HDRS}
  385. X
  386. Xcollapse: clobber shar
  387. X    ${SQZ} ${NAME}.shar
  388. X    ${DEL} ${FILES}
  389. X
  390. Xprint: ${SRCS} ${HDRS}
  391. X    @${PRINT} ${SRCS} ${HDRS}
  392. X
  393. END_OF_FILE
  394. if test 4720 -ne `wc -c <'Makefile'`; then
  395.     echo shar: \"'Makefile'\" unpacked with wrong size!
  396. fi
  397. # end of 'Makefile'
  398. fi
  399. if test -f 'VMSbuild.com' -a "${1}" != "-c" ; then 
  400.   echo shar: Will not clobber existing file \"'VMSbuild.com'\"
  401. else
  402. echo shar: Extracting \"'VMSbuild.com'\" \(2417 characters\)
  403. sed "s/^X//" >'VMSbuild.com' <<'END_OF_FILE'
  404. X$! --- VMSbuild.com ---
  405. X$!
  406. X$! Build the ParseArgs suite under VMS
  407. X$!
  408. X$! Luke Brennan                             e-mail: brennan@coco.cchs.su.oz.AU
  409. X$! EDP Unit, S209                                   lukeb@casino.cchs.su.oz.AU
  410. X$!                                    brennan%coco.cchs.su.oz.au@cunyvm.BITNET
  411. X$! Cumberland College of Health Sciences,                              ,-_|\  
  412. X$! The University of Sydney                  voice: +61 2 646 6402    /     \ 
  413. X$! East Street, Lidcombe, NSW 2141             fax: +61 2 646 4853    \_,-._* 
  414. X$! AUSTRALIA                                                               v  
  415. X$!
  416. X$!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  417. X$!
  418. X$ If (P1 .nes. "")
  419. X$ Then OPSYS := 'P1'
  420. X$ Else OPSYS := 'f$getsyi("node_SWtype")'
  421. X$ EndIF
  422. X$!
  423. X$!
  424. X$ If (OPSYS .eqs. "UNIX")
  425. X$ Then use_pager := /Define="""USE_PAGER"""
  426. X$ Else use_pager :=
  427. X$ EndIF
  428. X$ os_style    = f$edit(OPSYS,"LOWERCASE") + "_style"
  429. X$ os_library := LIB'opsys'ARGS.OLB
  430. X$!
  431. X$!
  432. X$! compile the appropriate source files
  433. X$!
  434. X$ CC /Include=([]) 'OPSYS'_Args    /Define="''os_style'"
  435. X$ CC /Include=([]) Xparse        /Define="''os_style'"
  436. X$ CC /Include=([]) ArgType        /Define="''os_style'"
  437. X$ CC /Include=([]) STRfuncs        /Define="''os_style'"
  438. X$ CC /Include=([]) ArgList
  439. X$ CC /Include=([]) PgOpen        'use_pager'
  440. X$ CC /Include=([]) SYSerr
  441. X$ CC /Include=([]) Vprintf
  442. X$ CC /Include=([]) WinSize
  443. X$!
  444. X$! make the archive library
  445. X$!
  446. X$ If (f$search("''os_library'") .nes. "") Then Delete 'os_library';
  447. X$ Library/Object/Create 'os_library'        -
  448. X    'opsys'_args, arglist, argtype, pgopen,    -
  449. X     strfuncs, syserr, vprintf, winsize, xparse
  450. X$!
  451. X$!
  452. X$! VMS requires an OPTIONS file for correct linkage with the C libraries
  453. X$ If (f$search("VMS_C_OPTIONS.OPT") .eqs. "") Then GoSub Make_Opts_File
  454. X$!
  455. X$!
  456. X$! now we can build the actual executables..
  457. X$!
  458. X$ CC /Include=([]) Stest
  459. X$ Link /Executable='OPSYS'_test -
  460. X        Stest,'os_library'/Library,VMS_C_Options/OPTION
  461. X$!
  462. X$ CC /Include=([]) Unix_Man
  463. X$ CC /Include=([]) ParseArgs
  464. X$ Link /Executable=ParseArgs -
  465. X        ParseArgs,Unix_Man,'os_library'/Library,VMS_C_Options/OPTION
  466. X$!
  467. X$ Exit
  468. X$!
  469. X$!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  470. X$!
  471. X$MAKE_OPTS_FILE:
  472. X$ Open/WRITE fd VMS_C_Options.opt
  473. X$ Write fd -
  474. X"! Default system options file to link against the sharable C runtime library"
  475. X$ Write fd "!"
  476. X$ Write fd "Sys$Share:VaxCrtl/share"
  477. X$ Write fd " "
  478. X$ Close fd
  479. X$!
  480. X$ Return
  481. X
  482. END_OF_FILE
  483. if test 2417 -ne `wc -c <'VMSbuild.com'`; then
  484.     echo shar: \"'VMSbuild.com'\" unpacked with wrong size!
  485. fi
  486. # end of 'VMSbuild.com'
  487. fi
  488. if test -f 'doc/Makefile' -a "${1}" != "-c" ; then 
  489.   echo shar: Will not clobber existing file \"'doc/Makefile'\"
  490. else
  491. echo shar: Extracting \"'doc/Makefile'\" \(3356 characters\)
  492. sed "s/^X//" >'doc/Makefile' <<'END_OF_FILE'
  493. X# $Header: Man.mk,v 1.0 90/03/05 09:21:28 brad Exp $
  494. X
  495. X###
  496. X# target directories
  497. X###
  498. XMAN1=    man1
  499. XMAN3=    man3
  500. XLOCALMAN=    local_man
  501. XMANDIR=    /usr/man/${LOCALMAN}
  502. XCATMANDIR=    /usr/catman/${LOCALMAN}
  503. X
  504. X###
  505. X# commands
  506. X###
  507. XCOL=    col
  508. XCOLFLAGS=    -b
  509. XSOELIM=    /usr/ucb/soelim
  510. XMANTOCATMAN=    /usr/ucb/mantocatman
  511. XTROFF=    roff
  512. XTRFLAGS=    -man -dimagen1
  513. XNROFF=    nroff
  514. XNRFLAGS=    -man
  515. XSPELL=    spell
  516. XCOPY=    /bin/cp
  517. XDEL=    /bin/rm -f
  518. X
  519. X###
  520. X# files used
  521. X###
  522. XINCS=    *.inc
  523. XSRCS=    argtype.man3  parseargs.man1  parseargs.man3  parsecntl.man3
  524. XMANIFEST=    Manifest
  525. XMAN3FILES=    argtype.3  parseargs.3  parsecntl.3
  526. XMAN1FILES=    parseargs.1
  527. XCATMAN3FILES=    argtype.3.z  parseargs.3.z  parsecntl.3.z
  528. XCATMAN1FILES=    parseargs.1.z
  529. X
  530. X###
  531. X# target dependencies
  532. X###
  533. X.SUFFIXES: .man1 .man3 .1 .3
  534. X
  535. X.man1.1:
  536. X    ${SOELIM} $< >$*.1
  537. X    ${MANTOCATMAN} $*.1
  538. X
  539. X.man3.3:
  540. X    ${SOELIM} $< >$*.3
  541. X    ${MANTOCATMAN} $*.3
  542. X
  543. X###
  544. X# give a usage message if no target is given
  545. X###
  546. Xusage:
  547. X    @echo "Usage: make <target>"
  548. X    @echo " "
  549. X    @echo "where <target> is one of the following: "
  550. X    @echo " "
  551. X    @echo "   install  -- to install the documentation"
  552. X    @echo "   installman  -- to install the unpacked documentation"
  553. X    @echo "   installcatman  -- to install the packed documentation"
  554. X    @echo "   print  -- to print the documentation"
  555. X    @echo "   view   -- to view the documentation"
  556. X    @echo "   text   -- to build text copies of the documentation"
  557. X    @echo "   spell  -- to spell check the documentation"
  558. X    @echo "   clean  -- to remove all intermediate files"
  559. X    @echo "   clobber  -- to remove all created files"
  560. X
  561. X###
  562. X# installation dependencies
  563. X###
  564. Xinstall: installman installcatman
  565. X
  566. Xinstallman: installman1 installman3
  567. X
  568. Xinstallcatman: installcatman1 installcatman3
  569. X
  570. Xinstallman1: ${MAN1FILES}
  571. X    ${COPY} ${MAN1FILES} ${MANDIR}/${MAN1}
  572. X
  573. Xinstallcatman1: ${CATMAN1FILES}
  574. X    ${COPY} ${CATMAN1FILES} ${CATMANDIR}/${MAN1}
  575. X
  576. Xinstallman3: ${MAN3FILES}
  577. X    ${COPY} ${MAN3FILES} ${MANDIR}/${MAN3}
  578. X
  579. Xinstallcatman3: ${CATMAN3FILES}
  580. X    ${COPY} ${CATMAN3FILES} ${CATMANDIR}/${MAN3}
  581. X
  582. X###
  583. X# include dependencies
  584. X###
  585. Xargtype.3:    argtype.man3
  586. X
  587. Xparseargs.1:    parseargs.man1 \
  588. X        ../test.sh \
  589. X        argvalopt.inc \
  590. X        bugs.inc \
  591. X        caveats.inc \
  592. X        env_args.inc \
  593. X        env_parse.inc \
  594. X        env_usage.inc \
  595. X        parseargs1.inc \
  596. X        sh_arrays.inc \
  597. X        shells.inc
  598. X
  599. Xparseargs.3:    parseargs.man3 \
  600. X        arg_macros.inc \
  601. X        argdesc.inc \
  602. X        argflags.inc \
  603. X        caveats.inc \
  604. X        cmd_macros.inc \
  605. X        defargs.inc \
  606. X        effects.inc \
  607. X        env_args.inc \
  608. X        env_parse.inc \
  609. X        env_usage.inc \
  610. X        fparseargs3.inc \
  611. X        lib_bugs.inc \
  612. X        lparseargs3.inc \
  613. X        multivals.inc \
  614. X        parseargs3.inc \
  615. X        returns.inc \
  616. X        sparseargs3.inc \
  617. X        usage3.inc \
  618. X        vparseargs3.inc
  619. X
  620. Xparsecntl.3:    parsecntl.man3 \
  621. X        argflags.inc \
  622. X        effects.inc \
  623. X        parsecntl3.inc \
  624. X        parsecntls.inc \
  625. X        parseflags.inc \
  626. X        parsemodes.inc \
  627. X        returns.inc
  628. X
  629. X
  630. X###
  631. X# maintenance dependencies
  632. X###
  633. Xclean:
  634. X    ${DEL} ${MAN1FILES} ${MAN3FILES} ${CATMAN1FILES} ${CATMAN3FILES}
  635. X
  636. Xclobber: clean
  637. X    ${DEL} *.txt
  638. X
  639. Xspell: ${INCS} ${SRCS}
  640. X    ${SPELL} ${SPELLFLAGS} ${INCS} ${SRCS}
  641. X
  642. Xprint: ${MANFILES} ${INCS}
  643. X    ${TROFF} ${TRFLAGS} ${SRCS}
  644. X
  645. Xtext: ascii
  646. Xtxt: ascii
  647. Xascii:
  648. X    ${NROFF} ${NRFLAGS} argtype.man3 | ${COL} ${COLFLAGS} >argtype3.txt
  649. X    ${NROFF} ${NRFLAGS} parseargs.man1 | ${COL} ${COLFLAGS} >parseargs1.txt
  650. X    ${NROFF} ${NRFLAGS} parseargs.man3 | ${COL} ${COLFLAGS} >parseargs3.txt
  651. X    ${NROFF} ${NRFLAGS} parsecntl.man3 | ${COL} ${COLFLAGS} >parsecntl3.txt
  652. X
  653. Xview: ${MANFILES} ${INCS}
  654. X    ${NROFF} ${NRFLAGS} ${SRCS}
  655. X
  656. END_OF_FILE
  657. if test 3356 -ne `wc -c <'doc/Makefile'`; then
  658.     echo shar: \"'doc/Makefile'\" unpacked with wrong size!
  659. fi
  660. # end of 'doc/Makefile'
  661. fi
  662. if test -f 'doc/arg_macros.inc' -a "${1}" != "-c" ; then 
  663.   echo shar: Will not clobber existing file \"'doc/arg_macros.inc'\"
  664. else
  665. echo shar: Extracting \"'doc/arg_macros.inc'\" \(3592 characters\)
  666. sed "s/^X//" >'doc/arg_macros.inc' <<'END_OF_FILE'
  667. X.\"----------------------------------------------------------------------------
  668. X.\"-- This text was extracted using the following command:
  669. X.\"--   xdoc -man -p '[ \t]*' -s ARGDESC-MACROS ../parseargs.h
  670. X.\"----------------------------------------------------------------------------
  671. X.SH "ARGDESC MACROS"
  672. X.PP
  673. XThe following macros are used to extract and query the attributes
  674. Xof a pointer to a preprocessed arg-descriptor:
  675. X.\"---------------------------------------------
  676. X.IP "\fIarg_cname\fP(ad)"
  677. XReturn the single-character name of an argument.
  678. X.\"---------------------------------------------
  679. X.IP "\fIarg_flags\fP(ad)"
  680. XReturn the argument flags of an argument.  The flags themselves may be
  681. Xmanipulated using the \s-1BTEST\s+1, \s-1BSET\s+1, and \s-1BCLEAR\s+1
  682. Xmacros defined in <useful.h>.
  683. X.\"---------------------------------------------
  684. X.IP "\fIarg_type\fP(ad)"
  685. XReturn the pointer to the value-translation-routine of an argument.
  686. X.\"---------------------------------------------
  687. X.IP "\fIarg_valp\fP(ad)"
  688. XReturn the pointer to the value of this argument.
  689. X.\"---------------------------------------------
  690. X.IP "\fIarg_sname\fP(ad)"
  691. XReturn the string name of an argument.
  692. X.\"---------------------------------------------
  693. X.IP "\fIarg_sdesc\fP(ad)"
  694. XReturn the description of an argument. If a description was supplied,
  695. Xthe \fI\s-1ARGDESCRIBED\s+1\fP flag will be set and the description will
  696. Ximmediately follow the terminating NULL byte of the string name.
  697. X.\"---------------------------------------------
  698. X.IP "\fIARG_isDESCRIBED\fP(ad)"
  699. XEvaluates to \s-1TRUE\s+1 only if an argument description was provided.
  700. X.\"---------------------------------------------
  701. X.IP "\fIarg_description\fP(ad)"
  702. XReturn the description string (or an empty string if no description
  703. Xwas given) for this argument.
  704. X.\"---------------------------------------------
  705. X.IP "\fIARG_isPOSITIONAL\fP(ad)"
  706. XEvaluates to \s-1TRUE\s+1 if this argument may be positionally matched.
  707. X.\"---------------------------------------------
  708. X.IP "\fIARG_isPOSONLY\fP(ad)"
  709. XEvaluates to \s-1TRUE\s+1 if this argument may only be positionally matched.
  710. X.\"---------------------------------------------
  711. X.IP "\fIARG_isLIST\fP(ad)"
  712. XEvaluates to \s-1TRUE\s+1 if this argument is an arglist.
  713. X.\"---------------------------------------------
  714. X.IP "\fIARG_isVEC\fP(ad)"
  715. XEvaluates to \s-1TRUE\s+1 if this argument is a vector.
  716. X.\"---------------------------------------------
  717. X.IP "\fIARG_isMULTIVAL\fP(ad)"
  718. XEvaluates to \s-1TRUE\s+1 if this argument is an arglist or a vector.
  719. X.\"---------------------------------------------
  720. X.IP "\fIARG_isVALTAKEN\fP(ad)"
  721. XEvaluates to \s-1TRUE\s+1 if this argument does NOT take a value.
  722. X.\"---------------------------------------------
  723. X.IP "\fIARG_isGIVEN\fP(ad)"
  724. XEvaluates to \s-1TRUE\s+1 if this argument was given on the command-line.
  725. X.\"---------------------------------------------
  726. X.IP "\fIARG_isVALGIVEN\fP(ad)"
  727. XEvaluates to \s-1TRUE\s+1 if the argument value was given on the command-line.
  728. X.\"---------------------------------------------
  729. X.IP "\fIARG_isREQUIRED\fP(ad)"
  730. XEvaluates to \s-1TRUE\s+1 if this argument is required.
  731. X.\"---------------------------------------------
  732. X.IP "\fIARG_isVALOPTIONAL\fP(ad)"
  733. XEvaluates to \s-1TRUE\s+1 if the argument value is optional.
  734. X.\"---------------------------------------------
  735. X.IP "\fIARG_isVALSEPARATE\fP(ad)"
  736. XEvaluates to \s-1TRUE\s+1 if the argument value is optional.
  737. X.\"---------------------------------------------
  738. X.IP "\fIARG_isHIDDEN\fP(ad)"
  739. XEvaluates to \s-1TRUE\s+1 if this argument is omitted from usage messages.
  740. X.\"---------------------------------------------
  741. END_OF_FILE
  742. if test 3592 -ne `wc -c <'doc/arg_macros.inc'`; then
  743.     echo shar: \"'doc/arg_macros.inc'\" unpacked with wrong size!
  744. fi
  745. # end of 'doc/arg_macros.inc'
  746. fi
  747. if test -f 'doc/argdesc.inc' -a "${1}" != "-c" ; then 
  748.   echo shar: Will not clobber existing file \"'doc/argdesc.inc'\"
  749. else
  750. echo shar: Extracting \"'doc/argdesc.inc'\" \(3866 characters\)
  751. sed "s/^X//" >'doc/argdesc.inc' <<'END_OF_FILE'
  752. X.\"----------------------------------------------------------------------------
  753. X.\"-- This text was extracted using the following command:
  754. X.\"--   xdoc -man -p '[ \t]*' -t STRUCT=ARGDESC ../parseargs.h
  755. X.\"----------------------------------------------------------------------------
  756. X.SH "THE ARGUMENT STRUCTURE"
  757. XThe basic type used by the \fIparseargs\fP library is the argument descriptor
  758. X(or "argdesc" for short). An \s-1ARGDESC\s+1 structure is used to describe a
  759. Xcommand-line argument. Each command line argument contains various
  760. Xfields which need to be set and/or queried by the programmer.
  761. XThe individual fields of an \s-1ARGDESC\s+1 structure are desribed below:
  762. X.\"---------------------------------------------
  763. X.IP "\fIchar  ad_name;\fP"
  764. XThis is a single character which corresponds to the option-letter
  765. X(case-sensitive) from the command-line that matches the argument
  766. Xdescribed by this structure. Positional-arguments are denoted by
  767. Xputting a a space character in this field.
  768. X.\"---------------------------------------------
  769. X.IP "\fIargMask_t  ad_flags;\fP"
  770. XThis field contains the various bitflags that describe the semantics
  771. Xof this argument. See the \fB\s-1ARGUMENT FLAGS\s+1\fP section for more
  772. Xinformation on the possible combinations of bitmasks for this field.
  773. X.\"---------------------------------------------
  774. X.IP "\fIargTypePtr_t  ad_type;\fP"
  775. XThis field is a pointer to a type conversion function (such as the
  776. Xones provided in \fIargtype\fP(3)). The type conversion function is
  777. Xresponsible for verifying the validity of the argument, allocating any
  778. Xnecessary storage for its internal representation, and converting
  779. Xthe command-line argument into its required internal form. The type
  780. Xconversion function used may be one of the pre-defined \fIargtype\fP(3)
  781. Xfunctions. The function is given three parameters: The first is
  782. Xa pointer to the \s-1ARGDESC\s+1 struct in question, the second is the
  783. Xstring-value (if any) supplied on the command-line, and the third
  784. Xis a boolean value that is \s-1TRUE\s+1 only if the second parameter points
  785. Xto temporary storage (and hence may need to be copied).
  786. XIn the case of \fIparseargs\fP(1) this field must correspond to the name
  787. Xof one of the argument type functions described in \fIargtype\fP(3).
  788. X.\"---------------------------------------------
  789. X.IP "\fIARBPTR  ad_valp;\fP"
  790. XThis field is a generic pointer to the storage used to represent
  791. Xthe internal value of the command-line argument. It may be a
  792. Xpointer to a number, a boolean value, a string, a list, or anything
  793. Xelse for which there exists a corresponding arg-type function to
  794. Xuse in the \fIad_type\fP field. In the case of of \fIparseargs\fP(1) this
  795. Xfield must be the name of the corresponding shell variable which will
  796. Xeventually hold the value of the argument given on the command-line.
  797. X.\"---------------------------------------------
  798. X.IP "\fIconst char  *ad_prompt;\fP"
  799. XThis field contains the long-name of the argument and an optional
  800. Xdescription (the description must be separated from the long-name by
  801. Xat least one whitespace character and may optionally be enclosed in
  802. Xa set of balanced delimiters (such as parentheses, curly-braces,
  803. Xsquare-brackets, or angle-brackets). The longname may be specifed
  804. Xin two parts: a keyword name and an argument name. The argument
  805. Xname may be separated from the keyword name by a single equal sign
  806. X(`='). No whitespace is allowed before or after the equal sign.
  807. X
  808. XAlternatatively, the keyword name may be distinguished from the
  809. Xargument name by character case: if the long-name contains any
  810. Xuppercase characters, then the substring of long-name consisting of
  811. Xall uppercase characters is used as the argument keyword and the
  812. Xentire long-name is used as the name of the argument (if a value may
  813. Xbe supplied). The long-name may be matched by supplying a unique
  814. Xprefix of either the argument keyword or the argument name.
  815. END_OF_FILE
  816. if test 3866 -ne `wc -c <'doc/argdesc.inc'`; then
  817.     echo shar: \"'doc/argdesc.inc'\" unpacked with wrong size!
  818. fi
  819. # end of 'doc/argdesc.inc'
  820. fi
  821. if test -f 'doc/argflags.inc' -a "${1}" != "-c" ; then 
  822.   echo shar: Will not clobber existing file \"'doc/argflags.inc'\"
  823. else
  824. echo shar: Extracting \"'doc/argflags.inc'\" \(5234 characters\)
  825. sed "s/^X//" >'doc/argflags.inc' <<'END_OF_FILE'
  826. X.\"----------------------------------------------------------------------------
  827. X.\"-- This text was extracted using the following command:
  828. X.\"--   xdoc -man -p '[ \t]*' -s ARG-FLAGS ../parseargs.h
  829. X.\"----------------------------------------------------------------------------
  830. X.SH "ARGUMENT FLAGS"
  831. X.PP
  832. XThese are the possible bitmasks that may be turned ON or OFF in
  833. Xthe \fIad_flags\fP field of an \fI\s-1ARGDESC\s+1\fP structure.
  834. X.\"---------------------------------------------
  835. X.IP "\fI\s-1ARGOPT\s+1\fP"
  836. XThis flag is actually a dummy flag (i.e. it is the default). This flag
  837. Xspecifies that the command-line argument is optional (need not appear
  838. Xon the command-line). It is only needed if no other flags are used to
  839. Xdefine the given argument.  If other flags are given and \fI\s-1ARGREQ\s+1\fP
  840. Xis \s-1NOT\s+1 one of them, then \fI\s-1ARGOPT\s+1\fP is always assumed.
  841. X.\"---------------------------------------------
  842. X.IP "\fI\s-1ARGREQ\s+1\fP"
  843. XThe associated command argument is required on the command-line.
  844. X.\"---------------------------------------------
  845. X.IP "\fI\s-1ARGPOS\s+1\fP"
  846. XThe associated command argument is positonal. The difference between
  847. Xusing this flag to indicate a positional argument and between using
  848. Xa blank in the \fIad_name\fP field to indicate a positional arguments is
  849. Xthe following: If this flag is set but the \fIad_name\fP of the argument
  850. Xis non-blank, then this argument may be matched either positionally
  851. Xor by keyword. If the \fIad_name\fP field is blank, then this argument may
  852. Xonly be matched positionally.
  853. X.\"---------------------------------------------
  854. X.IP "\fI\s-1ARGNOVAL\s+1\fP"
  855. XThe associated command argument takes no value (as in "\fB\-x\fI value\fR");
  856. XIts mere presence (or lack thereof) on the command-line is sufficient
  857. Xto determine the necessary action(s) to take (as in "\fB\-x\fP").
  858. XBoolean argument types and Pseudo-argument types automatically default to
  859. X\fI\s-1ARGNOVAL\s+1\fP.
  860. X.\"---------------------------------------------
  861. X.IP "\fI\s-1ARGVALOPT\s+1\fP"
  862. XThis flag is used to indicate that the command-line argument takes a value
  863. X(as in "\fB\-s\fI string\fR" or "\fB/str\fP=\fIstring\fP") but that the value
  864. Xto this command-line argument is \s-1NOT\s+1 required (hence simply
  865. X"\fB\-s\fP" or "\fB/str\fP" is also permissable).
  866. X.\"---------------------------------------------
  867. X.IP "\fI\s-1ARGVALREQ\s+1\fP"
  868. XAnother "dummy" flag. Unless \fI\s-1ARGNOVAL\s+1\fP or \fI\s-1ARGVALOPT\s+1\fP
  869. Xis specified, \fI\s-1ARGVALREQ\s+1\fP is always assumed. This flag indicates
  870. Xthat the value to a command-line argument is required (hence
  871. X"\fB\-s\fI string\fR" is okay but just "\fB\-s\fP" is not).
  872. X.\"---------------------------------------------
  873. X.IP "\fI\s-1ARGHIDDEN\s+1\fP"
  874. XDon't display this argument in usage messages but still attempt to
  875. Xmatch it against strings given on the command-line.
  876. X.\"---------------------------------------------
  877. X.IP "\fI\s-1ARGLIST\s+1\fP"
  878. XA variable number of values are used for this argument (and hence may
  879. Xuse more than one or two \f4argv\fP elements from the command-line as in
  880. X"\fB\-l\fI val1 val2\fR ..."). The list of values must be stored in an
  881. X.I ArgList
  882. Xstructure (\s-1NOT\s+1 a vector structure), an the corresponding argument-type
  883. Xfunction should be one of the \fIlistXxxx\fP functions.
  884. X.\"---------------------------------------------
  885. X.IP "\fI\s-1ARGVEC\s+1\fP"
  886. XA variable number of values are used for this argument (and hence may
  887. Xuse more than one or two argv elements from the command-line as in
  888. Xin "\fB\-v\fI val1 val2\fR ..."). The list of values must be stored in a
  889. Xvector structure (\s-1NOT\s+1 an \fIArgList\fP structure).
  890. X.\"---------------------------------------------
  891. X.PP
  892. XThe following bitmasks may also be present, but, unlike the above masks
  893. Xwhich must be specified by the programmer at initialization time, the
  894. Xfollowing masks must only be read (never set) by the programmer. They may
  895. Xbe queried by using the \fIpc_\s-1ARGFLAGS\s+1\fP function code and the
  896. Xmode \fIpc_\s-1READ\s+1\fP with \fIparsecntl\fP(3).
  897. X.\"---------------------------------------------
  898. X.IP "\fI\s-1ARGGIVEN\s+1\fP"
  899. XThe argument \s-1WAS\s+1 given on the command-line.
  900. X.\"---------------------------------------------
  901. X.IP "\fI\s-1ARGVALGIVEN\s+1\fP"
  902. XThe value for this argument was given on the command-line.
  903. X.\"---------------------------------------------
  904. X.IP "\fI\s-1ARGVALSEP\s+1\fP"
  905. XThe value to this argument was supplied in a separate argv element
  906. Xfrom the argument itself (as in "\fB\-x\fI value\fR" as opposed to
  907. X"\fB\-x\fIvalue\fR").
  908. X.\"---------------------------------------------
  909. X.IP "\fI\s-1ARGKEYWORD\s+1\fP"
  910. XThis argument was matched as a keyword (long-form) on the command-line
  911. Xand not as a single character.
  912. X.\"---------------------------------------------
  913. X.IP "\fI\s-1ARGDESCRIBED\s+1\fP"
  914. XThis argument was given a description by the programmer at
  915. Xinitialization.
  916. X.\"---------------------------------------------
  917. X.IP "\fI\s-1ARGCOPYF\s+1\fP"
  918. XThis flag is only used for lists and vectors (multivalued arguments)
  919. Xand is used on a per-item basis. If it is set, it means that the 
  920. Xcorresponding value in the vector/list required space to be allocated
  921. X(such as the duplication of a temporary string).
  922. X.\"---------------------------------------------
  923. END_OF_FILE
  924. if test 5234 -ne `wc -c <'doc/argflags.inc'`; then
  925.     echo shar: \"'doc/argflags.inc'\" unpacked with wrong size!
  926. fi
  927. # end of 'doc/argflags.inc'
  928. fi
  929. if test -f 'doc/bugs.inc' -a "${1}" != "-c" ; then 
  930.   echo shar: Will not clobber existing file \"'doc/bugs.inc'\"
  931. else
  932. echo shar: Extracting \"'doc/bugs.inc'\" \(1956 characters\)
  933. sed "s/^X//" >'doc/bugs.inc' <<'END_OF_FILE'
  934. X.\"----------------------------------------------------------------------------
  935. X.\"-- This text was extracted using the following command:
  936. X.\"--   xdoc -man -n -p '[ \t]*' -I BUGS ../parseargs.c
  937. X.\"----------------------------------------------------------------------------
  938. X.SH BUGS
  939. X.PP
  940. XIt does not make sense to use any arguments of type \fIargTBool\fP
  941. Xsince \fBparseargs\fP currently has no way of knowing what the
  942. Xinitial value of the variable is. For this reason, \fIargTBool\fP
  943. Xis not recognized as a valid argument type (even though it is used
  944. Xby \fIparseargs\fP\s-1\^(3)\s+1\|). By the same token, since the
  945. Xuser cannot create their own arguments types on the fly from a shell-script,
  946. X\fI\s-1ARGNOVAL\s+1\fP is not recognized as a valid argument flag.
  947. X.PP
  948. XCommas will not be interpreted properly if any field in the
  949. Xargument specification string contains double quotes that are nested
  950. Xinside of double quotes, or single quotes that are nested inside of
  951. Xsingle quotes.
  952. X.PP
  953. XInside the argument specification string, any repeated string of commas
  954. Xthat does not appear inside of double or single quotes will be treated
  955. Xas a single comma.
  956. X.PP
  957. XText descriptions for argument entries are automatically formatted in
  958. Xusage messages. Any attempt by the user to include tabs and/or newlines
  959. Xin the description will cause it to be formatted improperly.
  960. X.PP
  961. X\fIParseargs\fP cannot properly preserve any newlines in shell variables
  962. Xif the \fBeval\fP command is used to read its output (this is a shortcoming
  963. Xof the \fBeval\fP command, not of \fBparseargs\fP). If the user is concerned
  964. Xabout this particular case, then the user should redirect the output from
  965. X\fBparseargs\fP to a temporary file and use the \fBsource\fP command in
  966. X\fIcsh\fP or the dot command (`\fB.\fP') in sh and ksh, to interpret the
  967. Xresults; otherwise, newlines will be translated into spaces, or characters
  968. Xfollowing a newline may be lost, in any variables that are set by
  969. X\fBparseargs\fP.
  970. END_OF_FILE
  971. if test 1956 -ne `wc -c <'doc/bugs.inc'`; then
  972.     echo shar: \"'doc/bugs.inc'\" unpacked with wrong size!
  973. fi
  974. # end of 'doc/bugs.inc'
  975. fi
  976. if test -f 'doc/env_args.inc' -a "${1}" != "-c" ; then 
  977.   echo shar: Will not clobber existing file \"'doc/env_args.inc'\"
  978. else
  979. echo shar: Extracting \"'doc/env_args.inc'\" \(2008 characters\)
  980. sed "s/^X//" >'doc/env_args.inc' <<'END_OF_FILE'
  981. X.\"----------------------------------------------------------------------------
  982. X.\"-- This text was extracted using the following command:
  983. X.\"--   xdoc -man -n -p '[ \t]*' -I DESCRIPTION -f get_user_defaults ../xparse.c
  984. X.\"----------------------------------------------------------------------------
  985. X.SH "SUPPLYING DEFAULT ARGUMENTS"
  986. XPrograms that use \fIparseargs\fP may be given default arguments under UNIX
  987. Xand PCs through the use of environment variables (symbols are used for VMS
  988. Xsystems). If a  C-program or shell-script uses \fIparseargs\fP to implement a
  989. Xcommand named ``\fIcmd\fP'' then the environment variable ``\s-1CMD_ARGS\s+1''
  990. Xwill be parsed for any "default" arguments before the command-line is parsed.
  991. XThe command-line will over-ride any options that are specified in this
  992. Xenvironment variable (except that \s-1ARGLIST\s+1s and \s-1ARGVEC\s+1s set in
  993. X``\s-1CMD_ARGS\s+1'' will be appended from the command-line if they are
  994. Xselected).
  995. X
  996. XIt is important to note that the contents of the ``\s-1\fICMD\fP_ARGS\s+1''
  997. Xenvironment variable are NOT expanded by the shell and hence any special
  998. Xcharacters (such as quotes or back-slashes) will NOT be escaped or removed
  999. Xby \fIparseargs\fP. Furthermore, it will not be possible to try and use a
  1000. Xtab, space, or newline character in the environment variable as anything
  1001. Xother than an argument separator.
  1002. X
  1003. XLastly, parts of an option specification in ``\s-1CMD_ARGS\s+1'' may NOT be
  1004. Xcontinued on the command-line. As an example, if \fB\-f\fP requires an argument
  1005. Xand \s-1CMD_ARGS\s+1="\-f", then the command-line "\fIcmd  bah\fP" will NOT
  1006. Xassign "\fIbah\fP" as the argument to \fB\-f\fP but will instead complain about
  1007. Xa missing argument for \fB\-f\fP. Similarly, if \fB\-l\fP takes a list of
  1008. Xarguments and \s-1CMD_ARGS\s+1="\-l item1 item2", then the command-line
  1009. X"\fIcmd  bah\fP", will NOT assign "\fIbah\fP" to the end of the list
  1010. Xcontaining "item1" and "item2" but will instead treat "\fIbah\fP" as 
  1011. Xthe first positional parameter on the command-line.
  1012. END_OF_FILE
  1013. if test 2008 -ne `wc -c <'doc/env_args.inc'`; then
  1014.     echo shar: \"'doc/env_args.inc'\" unpacked with wrong size!
  1015. fi
  1016. # end of 'doc/env_args.inc'
  1017. fi
  1018. if test -f 'doc/env_parse.inc' -a "${1}" != "-c" ; then 
  1019.   echo shar: Will not clobber existing file \"'doc/env_parse.inc'\"
  1020. else
  1021. echo shar: Extracting \"'doc/env_parse.inc'\" \(3662 characters\)
  1022. sed "s/^X//" >'doc/env_parse.inc' <<'END_OF_FILE'
  1023. X.\"----------------------------------------------------------------------------
  1024. X.\"-- This text was extracted using the following command:
  1025. X.\"--   xdoc -man -n -p '[ \t]*' -I DESCRIPTION -f get_parse_env ../xparse.c
  1026. X.\"----------------------------------------------------------------------------
  1027. X.SH PARSING BEHAVIOR
  1028. XThe programmer may control parsing behavior through the use of
  1029. X.IR parsecntl (3).
  1030. XThe user may set his (or her) own desired parsing
  1031. Xbehavior through the use of the ``\s-1PARSECNTL\s+1'' environment variable.
  1032. XBy indicating any number of flags (possibly negated) the user will
  1033. Xdirectly modify the behavior of the \fIparseargs\fP library. Flags may be
  1034. Xcombined by placing a `+' or `|' character in between flags. A switch
  1035. Xis negated by immediately preceding it with a `!' or `-' character.
  1036. XThe possible ``flags'' are given by the following table. 
  1037. XFlags are case-insensitive.
  1038. X.sp 4p
  1039. X.\"---------------------------------------------
  1040. X.IP "\fIPrompt\fP"
  1041. XPrompt the user for any missing arguments that are required on the
  1042. Xcommand-line. No special escaping or quoting is performed on the
  1043. Xuser input. Required arguments that expect a list of values will
  1044. Xbe repeatedly prompted for (one item per line) until a blank line
  1045. X(followed by a carriage return) is entered.
  1046. X.\"---------------------------------------------
  1047. X.IP "\fIIgnore\fP"
  1048. XIgnore any unrecognized or improperly specified command-line arguments
  1049. Xand continue execution of the program. Normally, if a required argument is
  1050. Xunmatched (or an argument is improperly specified), a usage message is printed
  1051. Xprogram execution is terminated.
  1052. X.\"---------------------------------------------
  1053. X.IP "\fIOptsOnly\fP"
  1054. XUnder \s-1UNIX\s+1, setting this flag will disable the parsing of long-option
  1055. Xsyntax. This will cause all arguments starting with `+' to always be
  1056. Xtreated as a positional parameter (instead of a long-option).
  1057. X.\"---------------------------------------------
  1058. X.IP "\fIKwdsOnly\fP"
  1059. XUnder \s-1UNIX\s+1, setting this flag disables the parsing of single-character
  1060. Xoptions.  This will cause all arguments starting with `\-' to always
  1061. Xbe treated as a positional parameter (instead of an option).
  1062. X.\"---------------------------------------------
  1063. X.IP "\fILoptsOnly\fP"
  1064. XSame as \fIKwdsOnly\fP.
  1065. X.\"---------------------------------------------
  1066. X.IP "\fIFlags1st\fP"
  1067. XSetting this flag causes the \fIparseargs\fP library to force any and all
  1068. Xnon-positional arguments to be specified before any positional ones.
  1069. XAs an example, under \s-1UNIX\s+1, if this flag is \s-1SET\s+1 then
  1070. X.I parseargs
  1071. Xwill consider the command line "\fBcmd \-x\fI arg\fR" to consist of one
  1072. Xoption and one positional argument; however the command line
  1073. X"\fBcmd\fI arg -x\fR" would be considered to consist of two positional
  1074. Xarguments (the \fB\-x\fP option will be unmatched).
  1075. X
  1076. XIf this flag is \s-1UNSET\s+1, then both of the previous examples are
  1077. Xconsidered to consist of one option and one positional argument.
  1078. X.\"---------------------------------------------
  1079. X.IP "\fICaseIgnore\fP"
  1080. XSetting this flag will cause character-case to be ignored when attempting
  1081. Xto match single-character argument names (i.e. causes "\fB\-i\fP" and
  1082. X"\fB\-I\fP" to be considered equivalent).
  1083. X.\"---------------------------------------------
  1084. X.sp 4p
  1085. X.PP
  1086. XIf the environment variable ``\s-1PARSECNTL\s+1'' is empty or
  1087. Xundefined, then the parsing behavior set by the programmer is used.
  1088. XIf the programmer has not explicitly used
  1089. X.IR parsecntl (3)
  1090. Xto modify the parsing behavior, then the default behavior will be
  1091. X``Flags1st'' for Unix systems, ``!Prompt + !Ignore'' for AmigaDOS
  1092. Xsystems, ``CaseIgnore'' for MS-DOS and OS/2 systems, and ``Prompt''
  1093. Xfor VMS systems.
  1094. END_OF_FILE
  1095. if test 3662 -ne `wc -c <'doc/env_parse.inc'`; then
  1096.     echo shar: \"'doc/env_parse.inc'\" unpacked with wrong size!
  1097. fi
  1098. # end of 'doc/env_parse.inc'
  1099. fi
  1100. if test -f 'doc/env_usage.inc' -a "${1}" != "-c" ; then 
  1101.   echo shar: Will not clobber existing file \"'doc/env_usage.inc'\"
  1102. else
  1103. echo shar: Extracting \"'doc/env_usage.inc'\" \(2827 characters\)
  1104. sed "s/^X//" >'doc/env_usage.inc' <<'END_OF_FILE'
  1105. X.\"----------------------------------------------------------------------------
  1106. X.\"-- This text was extracted using the following command:
  1107. X.\"--   xdoc -man -n -p '[ \t]*' -I DESCRIPTION -f get_usage_env ../xparse.c
  1108. X.\"----------------------------------------------------------------------------
  1109. X.SH USAGE MESSAGES
  1110. XThrough the use of an environment variable (or a VMS symbol), the user
  1111. Xmay control the syntax and the verbosity of the command-usage messages
  1112. Xthat are printed by \fIparseargs\fP. The desired level of verbosity may
  1113. Xbe set by defining the environment variable ``\s-1USAGECNTL\s+1" to be
  1114. Xa combination of strings (case insensitive). The value of each string
  1115. Xcontrols one of three different ``modes'' of behavior in the displaying
  1116. Xof usage messages:
  1117. XThe first ``mode'' is ``verbose'' mode, which controls whether or not a
  1118. Xdetailed description of each argument should accompany the usual command-line
  1119. Xsysnopsis. If verbose mode is ``off'', then only a command-line synopsis is
  1120. Xprinted (this is also refferred to as ``terse'' mode). The other two ``modes''
  1121. Xcontrol the displaying of option syntax and long-option syntax. A mode may
  1122. Xbe explicitly disabled by preceding its corresponding string with the `!'
  1123. Xor `-' character. The ``modes'' which correspond to the possible values of the
  1124. X``\s-1USAGECNTL\s+1'' environment variable are given by the following table.
  1125. X.sp 4p
  1126. X.\"---------------------------------------
  1127. X.IP "\fIQuiet\fP"
  1128. XNo usage message of any kind is displayed.
  1129. X.\"---------------------------------------
  1130. X.IP "\fISilent\fP"
  1131. XSame as \fIQuiet\fP.
  1132. X.\"---------------------------------------
  1133. X.IP "\fIPaged\fP"
  1134. XThe usage message is piped to a pager. The pager used is named
  1135. Xby the ``\s-1USAGE_PAGER\s+1'' environment variable. If this
  1136. Xvariable is unset or empty (or is not the name of an executable program)
  1137. Xthen the pager named by the ``\s-1PAGER\s+1'' environment variable us used.
  1138. XIf this variable is unset or empty (or is not the name of an executable
  1139. Xprogram) then \fI/usr/ucb/more\fP is used.
  1140. X.\"---------------------------------------
  1141. X.IP "\fIDescription\fP"
  1142. XThe command description is printed.
  1143. X.\"---------------------------------------
  1144. X.IP "\fITerse\fP"
  1145. XTerse mode, just print command-line synopsis.
  1146. X.\"---------------------------------------
  1147. X.IP "\fIVerbose\fP"
  1148. XVerbose mode, print descriptions for each argument
  1149. X.\"---------------------------------------
  1150. X.IP "\fIOptions\fP"
  1151. XOption syntax is displayed.
  1152. X.\"---------------------------------------
  1153. X.IP "\fILongOpts\fP"
  1154. XLong-option syntax is displayed.
  1155. X.\"---------------------------------------
  1156. X.IP "\fIKeyWords\fP"
  1157. XSame as \fILongOpts\fP.
  1158. X.\"---------------------------------------
  1159. X.sp 4p
  1160. X.PP
  1161. XIf the environment variable ``\s-1USAGECNTL\s+1'' is empty or
  1162. Xundefined, then the default usage level (which is presently
  1163. X``Verbose + Options'') will be used.
  1164. END_OF_FILE
  1165. if test 2827 -ne `wc -c <'doc/env_usage.inc'`; then
  1166.     echo shar: \"'doc/env_usage.inc'\" unpacked with wrong size!
  1167. fi
  1168. # end of 'doc/env_usage.inc'
  1169. fi
  1170. if test -f 'doc/multivals.inc' -a "${1}" != "-c" ; then 
  1171.   echo shar: Will not clobber existing file \"'doc/multivals.inc'\"
  1172. else
  1173. echo shar: Extracting \"'doc/multivals.inc'\" \(4794 characters\)
  1174. sed "s/^X//" >'doc/multivals.inc' <<'END_OF_FILE'
  1175. X.\"----------------------------------------------------------------------------
  1176. X.\"-- This text was extracted using the following command:
  1177. X.\"--   xdoc -man -p '[ \t]*' -s MULTI-VALUED_ARGUMENTS ../parseargs.h
  1178. X.\"----------------------------------------------------------------------------
  1179. X.SH MULTI-VALUED ARGUMENTS
  1180. X.PP
  1181. X.I Parseargs
  1182. Xsupports two different types of multi-valued arguments: linked-lists and
  1183. Xvectors. The linked-lists are called argument lists (or arg-lists) and are 
  1184. Xspecified by supplying the \s-1ARGLIST\s+1 flag along with an associated
  1185. X\fIlistXxxx\fP argument-translation routine. The value associated with an
  1186. Xarg-list should be a list structure of type ArgList. The include file
  1187. X\f4<parseargs.h>\fP
  1188. Xdefines four macros for manipulating ArgList structures:
  1189. X\s-1ARGLISTNULL\s+1,
  1190. X\s-1L_NEXT\s+1,
  1191. X\s-1L_STRING\s+1,
  1192. Xand \s-1L_FLAGS\s+1.
  1193. X.PP
  1194. X\s-1ARGLISTNULL\s+1 is simply the \s-1NULL\s+1 argument-list pointer.
  1195. X\s-1L_NEXT\s+1 and \s-1L_STRING\s+1 each take a pointer to a non-\s-1NULL\s+1
  1196. XArgList structure. \s-1L_NEXT\s+1 returns the address of the next item in the
  1197. Xlist and \s-1L_STRING\s+1 returns the string-value of the current list-item.
  1198. X\s-1L_FLAGS\s+1 return the arg-flags for a given item in the list. With
  1199. Xnon-multivalued arguments, only the flags in the argument descriptor are
  1200. Xneeded; lists and vectors however need a set of flags for each item they
  1201. Xcontain. Once an arg-list has been created, it may be deallocated using
  1202. Xthe function
  1203. X.I listFree.
  1204. X.I ListFree
  1205. Xtakes one parameter: the address of the first item in the arg-list.
  1206. X.PP
  1207. XAn alternative to argument-lists is argument vectors (or arg-vectors).
  1208. XArg-vectors use the \s-1ARGVEC\s+1 flag instead of the \s-1ARGLIST\s+1 flag
  1209. Xand do not require a special \fIlistXxxx\fP function for each vector-type.
  1210. XEach of the \fIargXxxx\fP functions is responsible for handling vectors of its
  1211. Xtype (although some \fIargXxx\fP functions such as the boolean types do not
  1212. Xsupport vectors). An arg-vector is a structure which contains a count, an
  1213. Xarray of elements (i.e. an \f4argc,argv\fP pair), and an array of flags,
  1214. Xone for each element of argv. There are two macros in defined in
  1215. X\f4<parseargs.h>\fR which are used for arg-vectors. \s-1ARGVEC_T\s+1 may be
  1216. Xused to declare a vector structure or a vector type;
  1217. X\s-1ARGVEC_EMPTY\s+1 may be used to initialize the structure.
  1218. XIt is strongly recommended that \s-1ARGVEC_T\s+1 be used to declare vector
  1219. Xtypes in a typedef statement (particularly if one is using function prototypes)
  1220. Xbut for those who insist, it may be used to directly declare a  structure.
  1221. XString-vectors will always have an extra \s-1NULL\s+1-pointer at the end
  1222. Xsuch that:
  1223. X
  1224. X.RS
  1225. X.nf
  1226. X.ft 4
  1227. X( StrVec.array[ StrVec.count ] == (char *)NULL )
  1228. X.ft R
  1229. X.fi
  1230. X.RE
  1231. X
  1232. Xis always true, and character-vectors will always have an extra
  1233. X\s-1NUL\s+1-character at the end such that:
  1234. X
  1235. X.RS
  1236. X.nf
  1237. X.ft 4
  1238. X( CharVec.array[ CharVec.count ] == '\\0' )
  1239. X.ft R
  1240. X.fi
  1241. X.RE
  1242. X
  1243. Xis always true. Integer and floating point vectors contain no extra
  1244. X"null" elements.
  1245. X
  1246. XOnce created, arg-vectors may be deallocated by calling the macro
  1247. X\fIvecFree\fP or the macro \fIvecDeepFree\fP and passing it the
  1248. Xarg-vector structure. The differemce between these two macros is 
  1249. Xthat the latter will also free each item in the vector that required
  1250. Xspace to be allocated (at the expense of traversing the vector).
  1251. XAt this writing, the only predefined argument-types that would
  1252. Xbenefit from \fIvecDeepFree\fP is \fIargStr\fP vectors.
  1253. X.PP
  1254. XAn example use of arg-lists, and of arg-vectors follows:
  1255. X
  1256. X.RS
  1257. X.nf
  1258. X.ft 4
  1259. X#include <parseargs.h>
  1260. X
  1261. Xtypedef ARGVEC_T(char *) strvec_t;
  1262. X
  1263. Xstatic ArgList  *StringList = ARGLISTNULL;
  1264. Xstatic strvec_t  StringVec = ARGVEC_EMPTY(char *);
  1265. Xstatic ARGVEC_T(int)  NumberVec = ARGVEC_EMPTY(int);
  1266. X
  1267. Xstatic
  1268. X  CMD_OBJECT  Args
  1269. X  CMD_NAME    "foo -- do whatever foo does"
  1270. X  CMD_DESCRIPTION  "put a brief paragraph here"
  1271. X  CMD_ARGUMENTS
  1272. X     'l', ARGLIST, listStr, __ &StrList, "LiSt {list of strings}",
  1273. X     's', ARGVEC,  argStr,  __ &StrVec,  "STRing {vector of strings}",
  1274. X     'i', ARGVEC,  argInt,  __ &NumVec,  "NUMber {vector of numbers}",
  1275. X     END_ARGUMENTS
  1276. X  CMD_END
  1277. X
  1278. Xmain( int argc, char *argv[] )
  1279. X{
  1280. X   int i, *ls;
  1281. X
  1282. X   if ( parseargs(argv, Args) )  syserr( "parseargs failed" );
  1283. X
  1284. X   for ( ls = StrList, i=1 ; ls ; ls = L_NEXT(ls), i++ )
  1285. X      printf( "List item %d=%s, flags=%x\\n",
  1286. X              i, L_STRING(ls), L_FLAGS(ls) );
  1287. X
  1288. X   for ( i = 0 ; i < StrVec.count ; i++ )
  1289. X      printf( "String[%d]=%s, flags=%x\\n",
  1290. X              i, StrVec.array[i], StrVec.flags[i] );
  1291. X
  1292. X   for ( i = 0 ; i < NumVec.count ; i++ )
  1293. X      printf( "Number[%d]=%s, flags=%x\\n",
  1294. X              i, NumVec.array[i], NumVec.flags[i] );
  1295. X
  1296. X   listFree( StrList );
  1297. X   StrList = ARGLISTNULL;
  1298. X
  1299. X   vecDeepFree( StrVec, char * );
  1300. X   vecFree( NumVec, int );
  1301. X
  1302. X   exit( 0 );
  1303. X}
  1304. X
  1305. X.ft R
  1306. X.fi
  1307. X.RE
  1308. END_OF_FILE
  1309. if test 4794 -ne `wc -c <'doc/multivals.inc'`; then
  1310.     echo shar: \"'doc/multivals.inc'\" unpacked with wrong size!
  1311. fi
  1312. # end of 'doc/multivals.inc'
  1313. fi
  1314. if test -f 'doc/parsecntls.inc' -a "${1}" != "-c" ; then 
  1315.   echo shar: Will not clobber existing file \"'doc/parsecntls.inc'\"
  1316. else
  1317. echo shar: Extracting \"'doc/parsecntls.inc'\" \(4891 characters\)
  1318. sed "s/^X//" >'doc/parsecntls.inc' <<'END_OF_FILE'
  1319. X.\"----------------------------------------------------------------------------
  1320. X.\"-- This text was extracted using the following command:
  1321. X.\"--   xdoc -man -p '[ \t]*' -s PARSE-CNTLS ../parseargs.h
  1322. X.\"----------------------------------------------------------------------------
  1323. X.SH "FUNCTION CODES"
  1324. X.PP
  1325. XEach of the following function codes specifies an attribute that
  1326. Xis to be manipulated by \fIparsecntl\fP.  The function code is the
  1327. Xsecond parameter to \fIparsecntl\fP. With the exception of
  1328. X.I pc_\s-1ARGFLAGS\s+1,
  1329. Xeach of the function codes corresponds to a call to \fIparsecntl\fP
  1330. Xusing four parameters (
  1331. X.I pc_\s-1ARGFLAGS\s+1
  1332. Xuses 5 parameters). In each case,
  1333. Xthe last parameter is either the address of a buffer to write the
  1334. Xattribute to, or the actual buffer to read the attribute from 
  1335. X(depending upon the mode \- the third parameter to \fIparsecntl\fP).
  1336. X.\"---------------------------------------------
  1337. X.IP "\fIpc_\s-1PARSEFLAGS\s+1"
  1338. XThis function code is used to read and/or modify the existing parsing 
  1339. Xparsing behavior. The fourth parameter to \fIparsecntl\fP should be a 
  1340. Xcombination of pc_XXXX bitmasks if the parse-flags are only being
  1341. Xwritten, otherwise it should be a pointer to an \fIargMask_t\fP variable.
  1342. X.\"---------------------------------------------
  1343. X.IP "\fIpc_\s-1ARGFLAGS\s+1"
  1344. XThis function code may only be used to read the argument-flags of
  1345. Xa named argument. It is an error to specify a mode that attempts
  1346. Xto write the argument-flags with this function code. The fourth
  1347. Xparameter to \fIparsecntl\fP should be the keyword name of the argument
  1348. Xwhose flags are to be read. The fifth (and final) argument should
  1349. Xbe a pointer to the \fIargMask_t\fP variable which will receive the resulting
  1350. Xargument-flags.
  1351. X.\"---------------------------------------------
  1352. X.IP "\fIpc_\s-1DEFARGS\s+1"
  1353. XThis function code is used to query or modify the current default
  1354. Xargument-descriptor list for the given command. The fourth parameter
  1355. Xto \fIparsecntl\fP should be the argument-descriptor array to assign as the
  1356. Xnew default-list (or the address of an argdesc-array if the default
  1357. Xlist is being retrieved).
  1358. X
  1359. XIf a given option/qualifier does not appear to match any items in the
  1360. Xargdesc-array, a  default argdesc-array is then searched to match the
  1361. Xoption. If it is STILL unmatched then it is flagged as such. The
  1362. Xdefault-argdesc array is automatically used by all programmer-defined
  1363. Xargdesc-array but may be unset or reset using the
  1364. X.I pc_\s-1DEFARGS\s+1
  1365. Xfunction of
  1366. X.I parsecntl.
  1367. XIn such a  manner, a  programmer could specify a
  1368. Xdifferent set of default-arguments to search for. Furthermore, default
  1369. Xargdesc-arrays may also be assigned default argdesc-arrays, thus
  1370. Xallowing the programmer to define a whole search-list of default
  1371. Xargdesc-arrays for a given command.
  1372. X
  1373. XThis could prove useful in a situation where a set of commands have a
  1374. Xfew common-options and differ in their remaining ones. If the same
  1375. X\fImain()\fP were used for each command, then main could define one common
  1376. Xargdesc-array and then a set of argdesc-arrays for each command. \fIMain\fP
  1377. Xcould then figure out which argdesc-array to used based on the name in
  1378. X\fIargv[0]\fP, and set its default argdesc-array to be the common
  1379. Xargdesc-array, as in the following:
  1380. X
  1381. X.nf
  1382. X.ft 4
  1383. X#include <parseargs.h>
  1384. X     .
  1385. X     .  \fIvariable declarations\fP
  1386. X     .
  1387. X
  1388. Xstatic ARGDESC common_args[] = {
  1389. X   STARTOFARGS,
  1390. X   { 'L', ARGOPT, argBool, __ &lflag, "list (list the items)" },
  1391. X   { 'I', ARGOPT, argStr, __ &item, "item (item to use)" },
  1392. X   ENDOFARGS
  1393. X};
  1394. X
  1395. Xstatic ARGDESC cmd1_args[] = {
  1396. X   STARTOFARGS,
  1397. X   { 's', ARGOPT, argBool, __ &sflag, "S (set S)" },
  1398. X   { 't', ARGOPT, argBool, __ &tflag, "T (set T)" },
  1399. X   ENDOFARGS
  1400. X};
  1401. X
  1402. Xstatic ARGDESC cmd2_args[] = {
  1403. X   STARTOFARGS,
  1404. X   { 'x', ARGOPT, argBool, __ &xflag, "X (set X)" },
  1405. X   { 'y', ARGOPT, argBool, __ &yflag, "Y (set Y)" },
  1406. X   ENDOFARGS
  1407. X};
  1408. X
  1409. Xmain( int argc, char *argv[] )
  1410. X{
  1411. X   ARGDESC *cmd = cmd1_args;
  1412. X   int  rc;
  1413. X
  1414. X   if ( strcmp(*argv, "cmd2") == 0 )
  1415. X      cmd = cmd2_args;
  1416. X
  1417. X   rc = parsecntl( cmd, pc_DEFARGS, pc_WRITE, common_args );
  1418. X   if ( rc != pe_SUCCESS )
  1419. X      syserr( "unable to set default args" );
  1420. X
  1421. X   rc = parseargs( argv, cmd );
  1422. X      .
  1423. X      .
  1424. X      .
  1425. X}
  1426. X.ft R
  1427. X.fi
  1428. X
  1429. XNote that in the above call to \fIparsecntl\fP\^(3), that zero will be
  1430. Xreturned upon success and non-zero upon failure. If pe_DEFARGS is
  1431. Xreturned, then \f4cmd\fP is already on \f4common_args\fP's list of defaults
  1432. X(and would result in an infinite loop while parsing).
  1433. X.\"---------------------------------------------
  1434. X.IP "\fIpc_\s-1NAME\s+1\fP"
  1435. X.IP "\fIpc_\s-1PURPOSE\s+1\fP"
  1436. X.IP "\fIpc_\s-1DESCRIPTION\s+1\fP"
  1437. XEach of these last three function codes are used to modify or query the
  1438. Xname, purpose, or description associated with a command. The fourth
  1439. Xparameter to \fIparsecntl\fP should be the new string to use (or the address
  1440. Xof the string, a \fIchar**\fP variable, to recieve the current value).
  1441. END_OF_FILE
  1442. if test 4891 -ne `wc -c <'doc/parsecntls.inc'`; then
  1443.     echo shar: \"'doc/parsecntls.inc'\" unpacked with wrong size!
  1444. fi
  1445. # end of 'doc/parsecntls.inc'
  1446. fi
  1447. if test -f 'doc/returns.inc' -a "${1}" != "-c" ; then 
  1448.   echo shar: Will not clobber existing file \"'doc/returns.inc'\"
  1449. else
  1450. echo shar: Extracting \"'doc/returns.inc'\" \(2122 characters\)
  1451. sed "s/^X//" >'doc/returns.inc' <<'END_OF_FILE'
  1452. X.\"----------------------------------------------------------------------------
  1453. X.\"-- This text was extracted using the following command:
  1454. X.\"--   xdoc -man -p '[ \t]*' -s RETURN-CODES ../parsearegs.h
  1455. X.\"----------------------------------------------------------------------------
  1456. X.SH "RETURN VALUE"
  1457. X.PP
  1458. XThe functions in the \fIparseargs\fP library will return a value of zero
  1459. Xupon succesful completion. They may however, return any of
  1460. Xthe following status codes (which are defined in <parseargs.h>):
  1461. X.\"---------------------------------------------
  1462. X.IP "\fIpe_\s-1SYSTEM\s+1\fP"
  1463. XA system error occurred. The global variable \fIerrno\fP may indicate
  1464. Xthe problem (then again, it may not).
  1465. X.\"---------------------------------------------
  1466. X.IP "\fIpe_\s-1SUCCESS\s+1\fP"
  1467. XSuccess, no errors encountered (zero is returned).
  1468. X.\"---------------------------------------------
  1469. X.IP "\fIpe_\s-1SYNTAX\s+1\fP"
  1470. XA command-line syntax error was encountered
  1471. X.\"---------------------------------------------
  1472. X.IP "\fIpe_\s-1DEFARGS\s+1\fP"
  1473. XAn attempt (using \fIparsecntl\fP) was made to change the
  1474. Xdefault arg-search list of a command to point to an argdesc-array
  1475. Xwhich already has the given command on its default arg-search list
  1476. X(which would cause an infinite loop when attempting to match an
  1477. Xunknown command-line argument).
  1478. X.\"---------------------------------------------
  1479. X.IP "\fIpe_\s-1NOMATCH\s+1\fP"
  1480. XUnable to match the named argument. This occurs
  1481. Xwhen the argument keyword name passed to \fIparsecntl\fP (using the 
  1482. X\fIpc_\s-1ARGFLAGS\s+1\fP functions code) was NOT found in the given
  1483. Xargdesc-array or in its default-list.
  1484. X.\"---------------------------------------------
  1485. X.IP "\fIpe_\s-1BADMODE\s+1\fP"
  1486. XBad mode for given command in \fIparsecntl\fP. This occurs when 
  1487. X\fIpc_\s-1WRITE\s+1\fP or \fIpc_\s-1RDWR\s+1\fP mode is passed to
  1488. X.I parsecntl
  1489. Xin conjunction with the \fIpc_ARGFLAGS\fP functions code.
  1490. X.I Parsecntl
  1491. Xwill not modify existing arguments.
  1492. X.\"---------------------------------------------
  1493. X.IP "\fIpe_\s-1BADCNTL\s+1\fP"
  1494. XBad command for parsecntl. This occurs if an unknown function-code
  1495. Xwas passed to \fIparsecntl\fP.
  1496. END_OF_FILE
  1497. if test 2122 -ne `wc -c <'doc/returns.inc'`; then
  1498.     echo shar: \"'doc/returns.inc'\" unpacked with wrong size!
  1499. fi
  1500. # end of 'doc/returns.inc'
  1501. fi
  1502. if test -f 'doc/shells.inc' -a "${1}" != "-c" ; then 
  1503.   echo shar: Will not clobber existing file \"'doc/shells.inc'\"
  1504. else
  1505. echo shar: Extracting \"'doc/shells.inc'\" \(2294 characters\)
  1506. sed "s/^X//" >'doc/shells.inc' <<'END_OF_FILE'
  1507. X.\"----------------------------------------------------------------------------
  1508. X.\"-- This text was extracted using the following command:
  1509. X.\"--   xdoc -man -p '[ \t]*' -s SHELLS ../parseargs.c
  1510. X.\"----------------------------------------------------------------------------
  1511. X.SH SHELLS
  1512. X.PP
  1513. XAfter the command line has been parsed, \fBparseargs\fP will print on
  1514. Xstandard output, a script to set the shell variables which correspond to
  1515. Xarguments that were present on the command-line.
  1516. XThis script may be evaluated by redirecting it to a file and then executing
  1517. Xthe file, or by directly evaluating the output from \fBparseargs\fP
  1518. X(under most \s-1UNIX\s+1 shells, this could be done using \fBeval\fP).
  1519. XIf any arguments on the command line contained any special characters that
  1520. Xneeded to be escaped from the shell, these characters will remain intact
  1521. X(not be evaluated by the shell) in the corresponding shell variable.
  1522. X.PP
  1523. XThe \fB\-s\fP \fIshell\fP option may be used to tell \fBparseargs\fP which
  1524. Xshell syntax to use. At present, \fBparseargs\fP only recognizes the following
  1525. Xshells as valid command-interpreters:
  1526. X
  1527. X.RS
  1528. X.nf
  1529. Xsh
  1530. Xbash
  1531. Xksh
  1532. Xcsh
  1533. Xtcsh
  1534. Xitcsh
  1535. Xzsh
  1536. Xash
  1537. Xrc
  1538. Xawk
  1539. Xperl
  1540. Xtcl
  1541. X.fi
  1542. X.RE
  1543. X
  1544. X.PP
  1545. X\fIAwk\fP output is slightly different from 
  1546. Xthat of the other shells in that the actual variable settings are not
  1547. Xprinted but each line of an associative array is printed (the first field
  1548. Xis the array index, the second is the value for that index).
  1549. XIf no shell is specified, then the Bourne shell (``sh'') will be assumed.
  1550. X.PP
  1551. XIf the user wishes to use a value other than ``\s-1TRUE\s+1'' for a boolean
  1552. Xflag that is true, this may be done using the \fB\-T\fP \fIstring\fP option.
  1553. XThe same may also be done for a boolean flag that is false using the
  1554. X\fB\-F\fP \fIstring\fP option.
  1555. X.PP
  1556. X.B Parseargs
  1557. Xwill only set the values of variables that correspond to arguments that
  1558. Xwere given on the command line. If a particular argument was not supplied
  1559. Xon the command line, then no assignment is made for the corresponding
  1560. Xshell variable and it will have the same value that it had before
  1561. X.B parseargs
  1562. Xwas invoked. The only exception to this is that if the \fB\-u\fP option is
  1563. Xspecified, then the positional parameters are unset before any shell variable
  1564. Xassignments (which may reset the positional parameters) are made.
  1565. END_OF_FILE
  1566. if test 2294 -ne `wc -c <'doc/shells.inc'`; then
  1567.     echo shar: \"'doc/shells.inc'\" unpacked with wrong size!
  1568. fi
  1569. # end of 'doc/shells.inc'
  1570. fi
  1571. if test -f 'parseargs.pl' -a "${1}" != "-c" ; then 
  1572.   echo shar: Will not clobber existing file \"'parseargs.pl'\"
  1573. else
  1574. echo shar: Extracting \"'parseargs.pl'\" \(2715 characters\)
  1575. sed "s/^X//" >'parseargs.pl' <<'END_OF_FILE'
  1576. X;#########################################################################
  1577. X;# ^FILE: parseargs.pl - parseargs for perl programs
  1578. X;#
  1579. X;# ^DESCRIPTION:
  1580. X;#    This file defines a perl function named parseargs to parse
  1581. X;#    command-line arguments for perl scripts.
  1582. X;#
  1583. X;# ^HISTORY:
  1584. X;#    02/25/91    Brad Appleton    <brad@ssd.csd.harris.com>    Created
  1585. X;##^^#####################################################################
  1586. X
  1587. X
  1588. X;########
  1589. X;# ^FUNCTION: parseargs - parse command-line argument vectors
  1590. X;#
  1591. X;# ^SYNOPSIS:
  1592. X;#    rc = &parseargs( @argv, $argd )
  1593. X;#
  1594. X;# ^PARAMETERS:
  1595. X;#    argv -- the vector of command-line arguments (usually ARGV).
  1596. X;#    argd -- the argument-description string
  1597. X;#
  1598. X;# ^DESCRIPTION:
  1599. X;#    Parseargs will invoke parseargs(1) to parse the command-line given
  1600. X;#    in <argv> for the command defined by <argd>.  The resulting values
  1601. X;#    will be assigned to the variables indicated by the argument-description
  1602. X;#    string.
  1603. X;#
  1604. X;# ^REQUIREMENTS:
  1605. X;#    Any desired initial values for variables from the argument-description
  1606. X;#    string should be assigned BEFORE calling this function.
  1607. X;#
  1608. X;#    The following global variables from package "main" may be assigned
  1609. X;#    before calling parseargs:
  1610. X;#
  1611. X;#       PARSEOPTS -- any extra options to pass to parseargs() (default="-u")
  1612. X;#
  1613. X;# ^SIDE-EFFECTS:
  1614. X;#    The global variable PARSEARGS will contain the command-line used to
  1615. X;#    invoke parseargs(1).
  1616. X;#
  1617. X;#    ARGV and (and any other variables named in <argd>) may be overwritten.
  1618. X;#
  1619. X;# ^RETURN-VALUE:
  1620. X;#    The exit code returned by parseargs(1).
  1621. X;#
  1622. X;# ^ALGORITHM:
  1623. X;#    - read $PARSECNTL environment variable and use corresponding syntax
  1624. X;#      (long-options or short options) when invoking parseargs(1)
  1625. X;#    - set defaults for PARSEOPTS
  1626. X;#    - build the parseargs command (dont forget to quote arguments).
  1627. X;#    - run parseargs(1) and evaluate the output unless $?
  1628. X;##^^####
  1629. X
  1630. Xsub parseargs {
  1631. X   local($argd, @argv) = ( pop(@_), $0, @_ );
  1632. X   local($unset, $sh, $env, $end) = ( '-u', '-s', '-e', '--' );
  1633. X   local($parse_output, $_);
  1634. X
  1635. X   $_ = $main'ENV{'PARSECNTL'};
  1636. X   if ( /[^!~\^]\s*[KkLl]/ ) {  ## KeyWords only!
  1637. X      ($unset, $sh, $env, $end) = ( '+unset', '+shell', '+env', '++' );
  1638. X   }
  1639. X
  1640. X   if ( ! $main'PARSEOPTS )  { $main'PARSEOPTS = "$unset"; }
  1641. X
  1642. X   grep( s/'/'\\''/g, @argv );  ## escape embedded quotes
  1643. X   $PARSEARGS = "parseargs $main'PARSEOPTS $sh perl $env ARGD $end ";
  1644. X   $PARSEARGS .= "'" . join( "' '", @argv ) . "'";
  1645. X
  1646. X   $main'ENV{'ARGD'} = $argd;         ## put argd-array into environment
  1647. X   $parse_output = `$PARSEARGS`;      ## invoke parseargs(1)
  1648. X   eval $parse_output unless $?;      ## evaluate the output-script
  1649. X   if ( $? ) {
  1650. X      $! = 0;
  1651. X      die "\n";
  1652. X   }
  1653. X   return $?;
  1654. X}
  1655. X
  1656. X1;
  1657. END_OF_FILE
  1658. if test 2715 -ne `wc -c <'parseargs.pl'`; then
  1659.     echo shar: \"'parseargs.pl'\" unpacked with wrong size!
  1660. fi
  1661. chmod +x 'parseargs.pl'
  1662. # end of 'parseargs.pl'
  1663. fi
  1664. if test -f 'parseargs.tcl' -a "${1}" != "-c" ; then 
  1665.   echo shar: Will not clobber existing file \"'parseargs.tcl'\"
  1666. else
  1667. echo shar: Extracting \"'parseargs.tcl'\" \(4852 characters\)
  1668. sed "s/^X//" >'parseargs.tcl' <<'END_OF_FILE'
  1669. X#########################################################################
  1670. X# ^FILE: parseargs.tcl - parseargs for tcl scripts
  1671. X#
  1672. X# ^DESCRIPTION:
  1673. X#    This file defines a tcl procedure named parseargs to parse
  1674. X#    command-line arguments for tcl scripts.
  1675. X#
  1676. X# ^HISTORY:
  1677. X#    05/07/92  Brad Appleton   <brad@ssd.csd.harris.com>   Created
  1678. X##^^#####################################################################
  1679. X
  1680. X########
  1681. X# ^PROCEDURE: parseargs - parse command-line argument lists
  1682. X#
  1683. X# ^SYNOPSIS:
  1684. X#    parseargs <options> -- $scriptName arg [arg ...]
  1685. X#
  1686. X#        where <options> is any valid option combination for parseargs(1)
  1687. X#
  1688. X# ^DESCRIPTION:
  1689. X#    Parseargs will invoke parseargs(1) with the options and arguments
  1690. X#    specified by the caller.
  1691. X#
  1692. X# ^RETURN-VALUE:
  1693. X#    A string of variable settings for the caller to evaluate
  1694. X#
  1695. X# ^EXAMPLE:
  1696. X#     #!/usr/bin/tcl -q
  1697. X#     
  1698. X#     source parseargs.tcl
  1699. X#     
  1700. X#     set arguments {
  1701. X#       { '?', ARGHIDDEN, argUsage, NULL,    "Help : print usage and exit" },
  1702. X#       { 'S', ARGVALOPT, argStr,   string,  "STRing : optional string arg" },
  1703. X#       { 'g', ARGLIST,   argStr,   groups,  "newsGROUPS : groups to test" },
  1704. X#       { 'r', ARGOPT,    argInt,   count,   "REPcount : group repeat count" },
  1705. X#       { 'd', ARGOPT,    argStr,   dirname, "DIRectory : working directory" },
  1706. X#       { 'x', ARGOPT,    argBool,  xflag,   "Xflag : turn on X-mode" },
  1707. X#       { 'y', ARGOPT,    argUBool, yflag,   "Yflag : turn off Y-mode" },
  1708. X#       { 's', ARGOPT,    argChar,  sepch,   "SEPchar : field separator" },
  1709. X#       { 'f', ARGLIST,   argStr,   files,   "files : files to process" },
  1710. X#       { 'n', ARGREQ|ARGPOS, argStr, name,  "name : name to use" },
  1711. X#       { ' ', ARGLIST,   argStr,   argv,    "argv : remaining arguments" },
  1712. X#       ENDOFARGS
  1713. X#     }
  1714. X#     
  1715. X#     set count 1 ;    set dirname "." ;   set sepch "," ;
  1716. X#     set xflag "" ;   set yflag "TRUE" ;
  1717. X#     set files {} ;   set groups {} ;  set name "" ;
  1718. X#     set string "" ;  set string_flag "" ;
  1719. X#     
  1720. X#     eval [ parseargs -u -a $arguments $scriptName $argv ]
  1721. X#
  1722. X#
  1723. X# ^ALGORITHM:
  1724. X#    We need to do an "eval exec parseargs $args" in order have exec
  1725. X#    treat $args as many arguments instead of just one argument. Before
  1726. X#    we can do that however, we must quote each argument in $args and
  1727. X#    escape any special characters that it contains.  Hence we have the
  1728. X#    following algorithm:
  1729. X#
  1730. X#       - quote and escape special character for each arg in $args
  1731. X#       - do an "eval exec $args" and save the results
  1732. X#       - if parseargs(1) exit-status is non-zero than exit (and make
  1733. X#            sure the parseargs message(s) is/are printed).
  1734. X#         else
  1735. X#            return the standard-output of parseargs(1)
  1736. X#         endif
  1737. X#
  1738. X#
  1739. X# ^BUGS:
  1740. X#    Actually - this procedure doesnt work. It has some problems,
  1741. X#    some of which I know about and can describe below:
  1742. X#
  1743. X# 1) TCL refuses to let ME do the error-checking after exec'ing parseargs(1).
  1744. X#    What I need to do is look at the exit-status and exit if it is non-zero.
  1745. X#    If parseargs happens to write anything to stderr (which it always does
  1746. X#    if it prints usage or a syntax error) then TCL automatically terminates
  1747. X#    my procedure (not the process) and doesnt let me check the exit-status.
  1748. X#
  1749. X# 2) Error messages printed by parseargs(1) are prefixed with "Error: "
  1750. X#    and suffixed by some other error-message info added by TCL. I dont
  1751. X#    want ANY of this, just let parseargs(1) print the error text and dont
  1752. X#    embellish it. As a fix, I tried to have parseargs(1) write error messages
  1753. X#    to stdout (for TCL only) and exit with a non-zero status. This didnt
  1754. X#    work at all (and Im not completely sure as to why).
  1755. X#
  1756. X# 3) I ought to be able to use far fewer "regsub" statements below but I
  1757. X#    couldnt seem to get "&" or "\0" to work as documented as substitution
  1758. X#    strings.
  1759. X#
  1760. X# If you happen to get this procedure (along with test.tcl) working, then
  1761. X# please, PLEASE let me know and tell me how you did it!!
  1762. X#
  1763. X###^^####
  1764. Xproc parseargs args {
  1765. X   set escaped_args {}
  1766. X   foreach arg $args {
  1767. X      regsub -all "\\\\" "$arg" "\\\\" arg
  1768. X      regsub -all "\\\$" "$arg" "\\\$" arg
  1769. X      regsub -all "\\\[" "$arg" "\\\[" arg
  1770. X      regsub -all "\]" "$arg" "\\\]" arg
  1771. X      regsub -all "\{" "$arg" "\\\{" arg
  1772. X      regsub -all "\]" "$arg" "\\\]" arg
  1773. X      regsub -all "\"" "$arg" "\\\"" arg
  1774. X      regsub -all "\t" "$arg" "\\t" arg
  1775. X      regsub -all "\n" "$arg" "\\n" arg
  1776. X      regsub -all "\r" "$arg" "\\r" arg
  1777. X      regsub -all "\v" "$arg" "\\v" arg
  1778. X      regsub -all "\f" "$arg" "\\f" arg
  1779. X      regsub -all "\b" "$arg" "\\b" arg
  1780. X      append escaped_args " \"$arg\""
  1781. X   }
  1782. X   set  errorCode {}
  1783. X   set  opt_settings [ eval exec parseargs -s tcl $escaped_args ]
  1784. X   if {( $errorCode != {} )} { 
  1785. X      ## echo $opt_settings
  1786. X      exit [lindex $errorCode 2]
  1787. X   }
  1788. X   return  $opt_settings ;
  1789. X}
  1790. X
  1791. END_OF_FILE
  1792. if test 4852 -ne `wc -c <'parseargs.tcl'`; then
  1793.     echo shar: \"'parseargs.tcl'\" unpacked with wrong size!
  1794. fi
  1795. # end of 'parseargs.tcl'
  1796. fi
  1797. if test -f 'strfuncs.h' -a "${1}" != "-c" ; then 
  1798.   echo shar: Will not clobber existing file \"'strfuncs.h'\"
  1799. else
  1800. echo shar: Extracting \"'strfuncs.h'\" \(2118 characters\)
  1801. sed "s/^X//" >'strfuncs.h' <<'END_OF_FILE'
  1802. X/***************************************************************************
  1803. X** ^FILE: strfuncs.h - string functions
  1804. X**
  1805. X** ^DESCRIPTION:
  1806. X**    External declarations for the functions implemented in strfuncs.c
  1807. X**
  1808. X** ^HISTORY:
  1809. X**    27/08/91     Earl Chew     <cechew@bruce.cs.monash.edu.au>
  1810. X**    - Add extra argument to indent_para()
  1811. X**    - Add new prototypes for get_argdesc() and get_argpfx()
  1812. X**
  1813. X**    01/07/91    Brad Appleton    <brad@ssd.csd.harris.com>    Created
  1814. X***^^**********************************************************************/
  1815. X
  1816. X#ifndef STRFUNCS_H
  1817. X#define STRFUNCS_H
  1818. X
  1819. X#include <useful.h>
  1820. X
  1821. XEXTERN  char  *strucpy      ARGS(( char *, const char * ));
  1822. XEXTERN  char  *strlcpy      ARGS(( char *, const char * ));
  1823. XEXTERN  char  *strupr       ARGS(( char * ));
  1824. XEXTERN  char  *strlwr       ARGS(( char * ));
  1825. XEXTERN  int    stricmp      ARGS(( const char *, const char * ));
  1826. XEXTERN  int    strnicmp     ARGS(( const char *, const char *, size_t ));
  1827. XEXTERN  char  *strndup      ARGS(( const char * ));
  1828. XEXTERN  char  *strndup      ARGS(( const char * ));
  1829. XEXTERN  char  *strdup       ARGS(( const char * ));
  1830. X
  1831. X#ifdef BSD
  1832. X   EXTERN  char  *strpbrk   ARGS(( const char *, const char * ));
  1833. X   EXTERN  int    strspn    ARGS(( const char *, const char * ));
  1834. X   EXTERN  int    strcspn   ARGS(( const char *, const char * ));
  1835. X#endif
  1836. X
  1837. XEXTERN  char  *strltrim     ARGS(( char *, const char * ));
  1838. XEXTERN  char  *strrtrim     ARGS(( char *, const char * ));
  1839. XEXTERN  char  *strtrim      ARGS(( char *, const char * ));
  1840. XEXTERN  int    strsplit     ARGS(( char ***, char *, const char * ));
  1841. XEXTERN  char  *strjoin      ARGS(( const char **, const char * ));
  1842. X
  1843. XEXTERN  char  *get_argname  ARGS(( const char *, char * ));
  1844. XEXTERN  char  *get_kwdname  ARGS(( const char *, char * ));
  1845. XEXTERN  char  *get_argdesc  ARGS(( const char *, int * ));
  1846. XEXTERN  int    get_argpfx   ARGS(( const char * ));
  1847. XEXTERN  int    match        ARGS(( const char *, const char * ));
  1848. XEXTERN  char  *basename     ARGS(( char * ));
  1849. XEXTERN  VOID   indent_para  ARGS(( FILE *, int, int,
  1850. X                                   const char *, int, const char *, int ));
  1851. X
  1852. X#endif
  1853. END_OF_FILE
  1854. if test 2118 -ne `wc -c <'strfuncs.h'`; then
  1855.     echo shar: \"'strfuncs.h'\" unpacked with wrong size!
  1856. fi
  1857. # end of 'strfuncs.h'
  1858. fi
  1859. if test -f 'test.csh' -a "${1}" != "-c" ; then 
  1860.   echo shar: Will not clobber existing file \"'test.csh'\"
  1861. else
  1862. echo shar: Extracting \"'test.csh'\" \(2024 characters\)
  1863. sed "s/^X//" >'test.csh' <<'END_OF_FILE'
  1864. X#!/bin/csh -f
  1865. X#
  1866. X#    test.csh - C-shell script to test out the parseargs command!
  1867. X#
  1868. Xset NAME="`basename $0`"
  1869. X
  1870. Xsetenv ARGUMENTS "\
  1871. X  '?', ARGHIDDEN, argUsage, NULL,    'Help {print usage and exit}', \
  1872. X  'S', ARGVALOPT, argStr,   string,  'STRing {optional string arg}', \
  1873. X  'g', ARGLIST,   argStr,   groups,  'newsGROUPS {groups to test}', \
  1874. X  'r', ARGOPT,    argInt,   count,   'REPcount {# to repeat each group}', \
  1875. X  'd', ARGOPT,    argStr,   dirname, 'DIRectory {working directory}', \
  1876. X  'x', ARGOPT,    argBool,  xflag,   'Xflag {turn on X-mode}', \
  1877. X  'y', ARGOPT,    argUBool, yflag,   'Yflag {turn off Y-mode}', \
  1878. X  's', ARGOPT,    argChar,  sepch,   'SEPchar {field separator}', \
  1879. X  'f', ARGLIST,   argStr,   files,   'files {files to process}', \
  1880. X  'n', ARGREQ|ARGPOS, argStr, name,  'name {name to use}', \
  1881. X  ' ', ARGLIST,   argStr,   argv,    'argv {any remaining arguments}', \
  1882. X  ENDOFARGS \
  1883. X"
  1884. X## set defaults ##
  1885. Xset groups='mygroup'   ## default group used by everyone
  1886. Xset count='1'          ## only do once unless otherwise specified
  1887. Xset dirname='.'        ## default to current directory
  1888. Xset xflag=''           ## default xflag is false
  1889. Xset yflag='TRUE'       ## default yflag is true
  1890. Xset sepch=','          ## default separator is a comma
  1891. Xset files=()
  1892. X
  1893. X## parse command-line ##
  1894. Xparseargs -s csh -e ARGUMENTS -u -- "$NAME" $argv:q > /tmp/tmp$$
  1895. Xif ( $status != 0 ) then  ## improper syntax (or just wanted usage)
  1896. X    rm -f /tmp/tmp$$
  1897. X    exit 2
  1898. Xendif
  1899. X
  1900. X## evaluate output from parseargs & remove temporary file
  1901. Xsource /tmp/tmp$$
  1902. Xrm -f /tmp/tmp$$
  1903. X
  1904. X## echo arguments ##
  1905. Xecho "ARGUMENTS:"
  1906. Xecho "=========="
  1907. Xecho Groups=$groups:q
  1908. Xecho Count=$count:q
  1909. Xecho Directory=$dirname:q
  1910. Xecho XFlag=$xflag:q
  1911. Xecho YFlag=$yflag:q
  1912. Xecho SepChar=$sepch:q
  1913. Xecho Name=$name:q
  1914. Xecho Files=$files:q
  1915. Xif ( $?string_flag ) then
  1916. X  if ( ! $?string ) set string="\!string arg ommited on cmd-line\!"
  1917. Xelse
  1918. X  set string="default string"
  1919. Xendif
  1920. Xecho String=$string:q
  1921. Xecho New Positional Parameters=$argv:q
  1922. X
  1923. X## print usage ##
  1924. Xparseargs -e ARGUMENTS -U "$NAME"
  1925. END_OF_FILE
  1926. if test 2024 -ne `wc -c <'test.csh'`; then
  1927.     echo shar: \"'test.csh'\" unpacked with wrong size!
  1928. fi
  1929. chmod +x 'test.csh'
  1930. # end of 'test.csh'
  1931. fi
  1932. if test -f 'test.ksh' -a "${1}" != "-c" ; then 
  1933.   echo shar: Will not clobber existing file \"'test.ksh'\"
  1934. else
  1935. echo shar: Extracting \"'test.ksh'\" \(2053 characters\)
  1936. sed "s/^X//" >'test.ksh' <<'END_OF_FILE'
  1937. X#!/bin/ksh
  1938. X#
  1939. X#    test.ksh - Korn shell script to test out the parseargs command!
  1940. X#
  1941. X
  1942. XNAME="$(basename $0)"
  1943. X
  1944. XARGUMENTS="
  1945. X  '?', ARGHIDDEN, argUsage, NULL,    'Help -- print usage and exit',
  1946. X  'S', ARGVALOPT, argStr,   string,  'STRing -- optional string arg',
  1947. X  'g', ARGLIST,   argStr,   groups,  'newsGROUPS -- groups to test',
  1948. X  'r', ARGOPT,    argInt,   count,   'REPcount -- number to repeat each group',
  1949. X  'd', ARGOPT,    argStr,   dirname, 'DIRectory -- working directory',
  1950. X  'x', ARGOPT,    argBool,  xflag,   'Xflag -- turn on X-mode',
  1951. X  'y', ARGOPT,    argUBool, yflag,   'Yflag -- turn off Y-mode',
  1952. X  's', ARGOPT,    argChar,  sepch,   'SEPchar -- field separator',
  1953. X  'f', ARGLIST,   argStr,   files,   'files -- files to process',
  1954. X  'n', ARGREQ|ARGPOS, argStr, name,  'name -- name to use',
  1955. X  ' ', ARGLIST,   argStr,    -- ,    'argv -- any remaining arguments',
  1956. X  ENDOFARGS
  1957. X"
  1958. Xexport ARGUMENTS
  1959. X
  1960. X## set defaults ##
  1961. Xtypeset count='1'          ## only do once unless otherwise specified
  1962. Xtypeset dirname='.'        ## default to current directory
  1963. Xtypeset xflag=''           ## default xflag is false
  1964. Xtypeset yflag='TRUE'       ## default yflag is true
  1965. Xtypeset sepch=','          ## default separator is a comma
  1966. Xtypeset groups[]
  1967. Xtypeset files[]
  1968. X
  1969. X## parse command-line ##
  1970. Xparseargs -s ksh -e ARGUMENTS -uip -- "$NAME" "$@" >/tmp/tmp$$
  1971. Xif [ $? -ne 0 ] ; then
  1972. X  rm -f /tmp/tmp$$
  1973. X  exit 2  ## improper syntax (or just wanted usage)
  1974. Xfi
  1975. X
  1976. X## evaluate results from parseargs and remove temporary file ##
  1977. XINTERPRET="."
  1978. X$INTERPRET /tmp/tmp$$
  1979. Xrm -f /tmp/tmp$$
  1980. X
  1981. X## print arguments ##
  1982. Xprint "ARGUMENTS:"
  1983. Xprint "=========="
  1984. Xprint "Groups='${groups[@]}'"
  1985. Xprint "Count='$count'"
  1986. Xprint "Directory='$dirname'"
  1987. Xprint "XFlag='$xflag'"
  1988. Xprint "YFlag='$yflag'"
  1989. Xprint "SepChar='$sepch'"
  1990. Xprint "Name='$name'"
  1991. Xprint "Files='${files[@]}'"
  1992. Xif [ "$string_flag" ] ; then
  1993. X  string=${string:-"!string arg ommitted on cmd-line!"}
  1994. Xelse
  1995. X  string="default string"
  1996. Xfi
  1997. Xprint "String='$string'"
  1998. Xprint "New Positional Parameters='$*'"
  1999. X
  2000. X## print usage ##
  2001. Xparseargs -a "$ARGUMENTS" -U "$NAME"
  2002. END_OF_FILE
  2003. if test 2053 -ne `wc -c <'test.ksh'`; then
  2004.     echo shar: \"'test.ksh'\" unpacked with wrong size!
  2005. fi
  2006. chmod +x 'test.ksh'
  2007. # end of 'test.ksh'
  2008. fi
  2009. if test -f 'test.zsh' -a "${1}" != "-c" ; then 
  2010.   echo shar: Will not clobber existing file \"'test.zsh'\"
  2011. else
  2012. echo shar: Extracting \"'test.zsh'\" \(2052 characters\)
  2013. sed "s/^X//" >'test.zsh' <<'END_OF_FILE'
  2014. X#!/bin/zsh
  2015. X#
  2016. X#    test.zsh - Z shell script to test out the parseargs command!
  2017. X#
  2018. X
  2019. XNAME="`basename $0`"
  2020. X
  2021. XARGUMENTS="
  2022. X  '?', ARGHIDDEN, argUsage, NULL,    'Help -- print usage and exit',
  2023. X  'S', ARGVALOPT, argStr,   string,  'STRing -- optional string arg',
  2024. X  'g', ARGLIST,   argStr,   groups,  'newsGROUPS -- groups to test',
  2025. X  'r', ARGOPT,    argInt,   count,   'REPcount -- number to repeat each group',
  2026. X  'd', ARGOPT,    argStr,   dirname, 'DIRectory -- working directory',
  2027. X  'x', ARGOPT,    argBool,  xflag,   'Xflag -- turn on X-mode',
  2028. X  'y', ARGOPT,    argUBool, yflag,   'Yflag -- turn off Y-mode',
  2029. X  's', ARGOPT,    argChar,  sepch,   'SEPchar -- field separator',
  2030. X  'f', ARGLIST,   argStr,   files,   'files -- files to process',
  2031. X  'n', ARGREQ|ARGPOS, argStr, name,  'name -- name to use',
  2032. X  ' ', ARGLIST,   argStr,   args,    'args -- any remaining arguments',
  2033. X  ENDOFARGS
  2034. X"
  2035. Xexport ARGUMENTS
  2036. X
  2037. X## set defaults ##
  2038. Xtypeset count='1'          ## only do once unless otherwise specified
  2039. Xtypeset dirname='.'        ## default to current directory
  2040. Xtypeset xflag=''           ## default xflag is false
  2041. Xtypeset yflag='TRUE'       ## default yflag is true
  2042. Xtypeset sepch=','          ## default separator is a comma
  2043. Xtypeset groups
  2044. Xtypeset files  
  2045. X
  2046. X## parse command-line ##
  2047. Xparseargs -s zsh -e ARGUMENTS -u -- "$NAME" $argv[@] >/tmp/tmp$$
  2048. Xif [ $status -ne 0 ] ; then
  2049. X  rm -f /tmp/tmp$$
  2050. X  exit 2  ## improper syntax (or just wanted usage)
  2051. Xfi
  2052. X
  2053. X## evaluate results from parseargs and remove temporary file ##
  2054. XINTERPRET="."
  2055. X$INTERPRET /tmp/tmp$$
  2056. Xrm -f /tmp/tmp$$
  2057. X
  2058. X## print arguments ##
  2059. Xecho "ARGUMENTS:"
  2060. Xecho "=========="
  2061. Xecho "Groups='${groups[@]}'"
  2062. Xecho "Count='$count'"
  2063. Xecho "Directory='$dirname'"
  2064. Xecho "XFlag='$xflag'"
  2065. Xecho "YFlag='$yflag'"
  2066. Xecho "SepChar='$sepch'"
  2067. Xecho "Name='$name'"
  2068. Xecho "Files='${files[@]}'"
  2069. Xif [ -z "$string_flag" ] ; then
  2070. X  string="default string"
  2071. Xelse
  2072. X  string=${string:-'\!string arg ommitted on cmd-line\!'}
  2073. Xfi
  2074. Xecho "String='$string'"
  2075. Xecho "New Positional Parameters='$args[@]'"
  2076. X
  2077. X## echo usage ##
  2078. Xparseargs -a "$ARGUMENTS" -U "$NAME"
  2079. END_OF_FILE
  2080. if test 2052 -ne `wc -c <'test.zsh'`; then
  2081.     echo shar: \"'test.zsh'\" unpacked with wrong size!
  2082. fi
  2083. chmod +x 'test.zsh'
  2084. # end of 'test.zsh'
  2085. fi
  2086. echo shar: End of archive 2 \(of 10\).
  2087. cp /dev/null ark2isdone
  2088. MISSING=""
  2089. for I in 1 2 3 4 5 6 7 8 9 10 ; do
  2090.     if test ! -f ark${I}isdone ; then
  2091.     MISSING="${MISSING} ${I}"
  2092.     fi
  2093. done
  2094. if test "${MISSING}" = "" ; then
  2095.     echo You have unpacked all 10 archives.
  2096.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  2097. else
  2098.     echo You still need to unpack the following archives:
  2099.     echo "        " ${MISSING}
  2100. fi
  2101. ##  End of shell archive.
  2102. exit 0
  2103.  
  2104. exit 0 # Just in case...
  2105.