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

  1. Newsgroups: comp.sources.misc
  2. From: Brad Appleton <brad@hcx1.ssd.csd.harris.com>
  3. Subject:  v19i086:  parseargs - functions to parse command line argument, Patch05e/5
  4. Message-ID: <1991May17.181800.22489@sparky.IMD.Sterling.COM>
  5. X-Md4-Signature: f1fb0a6c2dc16439374a41b9d125ca4b
  6. Date: Fri, 17 May 1991 18:18:00 GMT
  7. Approved: kent@sparky.imd.sterling.com
  8.  
  9. Submitted-by: Brad Appleton <brad@hcx1.ssd.csd.harris.com>
  10. Posting-number: Volume 19, Issue 86
  11. Archive-name: parseargs/patch05e
  12. Patch-To: parseargs: Volume 17, Issue 45-57
  13.  
  14. #!/bin/sh
  15. # do not concatenate these parts, unpack them in order with /bin/sh
  16. # file PATCH05 continued
  17. #
  18. if test ! -r _shar_seq_.tmp; then
  19.     echo 'Please unpack part 1 first!'
  20.     exit 1
  21. fi
  22. (read Scheck
  23.  if test "$Scheck" != 5; then
  24.     echo Please unpack part "$Scheck" next!
  25.     exit 1
  26.  else
  27.     exit 0
  28.  fi
  29. ) < _shar_seq_.tmp || exit 1
  30. if test ! -f _shar_wnt_.tmp; then
  31.     echo 'x - still skipping PATCH05'
  32. else
  33. echo 'x - continuing file PATCH05'
  34. sed 's/^X//' << 'SHAR_EOF' >> 'PATCH05' &&
  35. -      ment should be the    object itself.
  36. -      If    mode is    pc_READ, then the desired attributes are copied
  37. -      into the object pointed to    by the last parameter. If the
  38. -      mode is pc_WRITE, then the    attributes from    the last parame-
  39. -      ter are copied to the command- object. If mode is pc_RDWR,
  40. -      then the attributes pointed to by the last    parameter are
  41. -      copied to the command-object, and then the    previous value of
  42. -      these attributes (before they were    overwritten) is    copied
  43. -      into the object pointed to    by the last parameter.
  44. -      If    cntl is    pc_ARGFLAGS, then the only valid mode is pc_READ.
  45. -      All other attributes may be written or read by parsecntl.
  46. - FUNCTION CODES
  47. -      Each of the following function codes specifies an attribute
  48. -      that is to    be manipulated by parsecntl.  The function code
  49. -      is    the second parameter to    parsecntl. With    the exception of
  50. -      pc_ARGFLAGS, each of the function codes corresponds to a
  51. -      call to parsecntl using four parameters ( pc_ARGFLAGS uses    5
  52. -      parameters). In each case,    the last parameter is either the
  53. -      address of    a buffer to write the attribute    to, or the actual
  54. -      buffer to read the    attribute from (depending upon the mode    -
  55. -      the third parameter to parsecntl).
  56. -      pc_PARSEFLAGS
  57. -       This function    code is    used to    read and/or modify the
  58. -       existing parsing parsing behavior. The fourth    parameter
  59. -       to parsecntl should be a combination of pc_XXXX
  60. - Page 1
  61. - PARSECNTL(3)                         PARSECNTL(3)
  62. -       bitmasks if the parse-flags are only being written,
  63. -       otherwise it should be a pointer to an argMask_t vari-
  64. -       able.
  65. -      pc_ARGFLAGS
  66. -       This function    code may only be used to read the
  67. -       argument-flags of a named argument. It is an error to
  68. -       specify a mode that attempts to write    the argument-
  69. -       flags    with this function code. The fourth parameter to
  70. -       parsecntl should be the keyword name of the argument
  71. -       whose    flags are to be    read. The fifth    (and final) argu-
  72. -       ment should be a pointer to the argMask_t variable
  73. -       which    will receive the resulting argument-flags.
  74. -      pc_DEFARGS
  75. -       This function    code is    used to    query or modify    the
  76. -       current default argument-descriptor list for the given
  77. -       command. The fourth parameter    to parsecntl should be
  78. -       the argument-descriptor array    to assign as the new
  79. -       default-list (or the address of an argdesc-array if the
  80. -       default list is being    retrieved).
  81. -       If a given option/qualifier does not appear to match
  82. -       any items in the argdesc-array, a  default argdesc-
  83. -       array    is then    searched to match the option. If it is
  84. -       STILL    unmatched then it is flagged as    such. The
  85. -       default-argdesc array    is automatically used by all
  86. -       programmer-defined argdesc-array but may be unset or
  87. -       reset    using the pc_DEFARGS function of parsecntl. In
  88. -       such a  manner, a  programmer    could specify a    different
  89. -       set of default-arguments to search for. Furthermore,
  90. -       default argdesc-arrays may also be assigned default
  91. -       argdesc-arrays, thus allowing    the programmer to define
  92. -       a whole search-list of default argdesc-arrays    for a
  93. -       given    command.
  94. -       This could prove useful in a situation where a set of
  95. -       commands have    a few common-options and differ    in their
  96. -       remaining ones. If the same main() were used for each
  97. -       command, then    main could define one common argdesc-
  98. -       array    and then a set of argdesc-arrays for each com-
  99. -       mand.    Main could then    figure out which argdesc-array to
  100. -       used based on    the name in argv[0], and set its default
  101. -       argdesc-array    to be the common argdesc-array,    as in the
  102. -       following:
  103. -       #include <parseargs.h>
  104. -            .
  105. -            .  variable declarations
  106. -            .
  107. -       static ARGDESC common_args[] = {
  108. - Page 2
  109. - PARSECNTL(3)                         PARSECNTL(3)
  110. -          STARTOFARGS,
  111. -          { 'L', ARGOPT, argBool, __    &lflag,    "list (list the    items)"    },
  112. -          { 'I', ARGOPT, argStr, __ &item, "item (item to use)" },
  113. -          ENDOFARGS
  114. -       };
  115. -       static ARGDESC cmd1_args[] = {
  116. -          STARTOFARGS,
  117. -          { 's', ARGOPT, argBool, __    &sflag,    "S (set    S)" },
  118. -          { 't', ARGOPT, argBool, __    &tflag,    "T (set    T)" },
  119. -          ENDOFARGS
  120. -       };
  121. -       static ARGDESC cmd2_args[] = {
  122. -          STARTOFARGS,
  123. -          { 'x', ARGOPT, argBool, __    &xflag,    "X (set    X)" },
  124. -          { 'y', ARGOPT, argBool, __    &yflag,    "Y (set    Y)" },
  125. -          ENDOFARGS
  126. -       };
  127. -       main(    int argc, char *argv[] )
  128. -       {
  129. -          ARGDESC *cmd = cmd1_args;
  130. -          int  rc;
  131. -          if    ( strcmp(*argv,    "cmd2")    == 0 )
  132. -         cmd = cmd2_args;
  133. -          rc    = parsecntl( cmd, pc_DEFARGS, pc_WRITE,    common_args );
  134. -          if    ( rc !=    pe_SUCCESS )
  135. -         syserr(    "unable    to set default args" );
  136. -          rc    = parseargs( argv, cmd );
  137. -         .
  138. -         .
  139. -         .
  140. -       }
  141. -       Note that in the above call to parsecntl(3), that zero
  142. -       will be returned upon    success    and non-zero upon
  143. -       failure. If pe_DEFARGS is returned, then cmd is already
  144. -       on common_args's list    of defaults (and would result in
  145. -       an infinite loop while parsing).
  146. -      pc_NAME
  147. -      pc_PURPOSE
  148. -      pc_DESCRIPTION
  149. -       Each of these    last three function codes are used to
  150. -       modify or query the name, purpose, or    description asso-
  151. -       ciated with a    command. The fourth parameter to
  152. - Page 3
  153. - PARSECNTL(3)                         PARSECNTL(3)
  154. -       parsecntl should be the new string to    use (or    the
  155. -       address of the string, a char** variable, to recieve
  156. -       the current value).
  157. - PARSE MODES
  158. -      Parsecntl may be used to read current command attributes,
  159. -      write (assign) new    command    attributes, or both. The mode
  160. -      argument to parsecntl determines which of these three alter-
  161. -      natives are desired. If the programmer merely wishes to
  162. -      assign new    attributes, then invoking parsecntl in pc_WRITE
  163. -      mode and passing the new attributes will do the job. If the
  164. -      programmer    wishes simply to query attributes, then    invoking
  165. -      parsecntl in pc_READ mode and passing a pointer to    the
  166. -      desired object in which to    write the attribute settings will
  167. -      suffice.
  168. -      If    the programmer wishes to assign    new attributes and at the
  169. -      same time find out    what the attributes were before    making
  170. -      the assignment, then programmer must invoke parsecntl for
  171. -      pc_RDWR mode and pass a pointer to    the object containing the
  172. -      new attribute settings; When parsecntl returns, then (assum-
  173. -      ing it returns 0) the desired attributes will have    been
  174. -      assigned and the object that contained the    new attribute
  175. -      settings will now contain the attribute settings that were
  176. -      in    effect immediately before parsecntl was    invoked.
  177. - PARSE FLAGS
  178. -      The following bitmasks may    be combined in order to    modify
  179. -      the behavior of the parseargs library. The    parse flags for    a
  180. -      given may be set through the use of the parsecntl(3) func-
  181. -      tion.
  182. -      pa_PROMPT
  183. -       Prompt the user for any missing arguments that are
  184. -       required on the command-line.    No special escaping or
  185. -       quoting is performed on the user input. Required argu-
  186. -       ments    that expect a list of values will be repeatedly
  187. -       prompted for (one item per line) until a blank line
  188. -       (followed by a carriage return) is entered.
  189. -      pa_IGNORE
  190. -       Ignore any unrecognized or improperly    specified
  191. -       command-line arguments and continue execution    of the
  192. -       program. Normally, if    a required argument is unmatched
  193. -       (or an argument is improperly    specified), a usage mes-
  194. -       sage is printed program execution is terminated.
  195. -      pa_OPTSONLY
  196. -       Under    UNIX, setting this flag    will disable the parsing
  197. -       of long-option syntax. This will cause all arguments
  198. -       starting with    `+' to always be treated as a positional
  199. -       parameter (instead of    a long-option).
  200. - Page 4
  201. - PARSECNTL(3)                         PARSECNTL(3)
  202. -      pa_KWDSONLY
  203. -       Under    UNIX, setting this flag    disables the parsing of
  204. -       single-character options.  This will cause all argu-
  205. -       ments    starting with `-' to always be treated as a posi-
  206. -       tional parameter (instead of an option).
  207. -      pa_FLAGS1ST
  208. -       Setting this flag causes the parseargs library to force
  209. -       any and all non-positional arguments to be specified
  210. -       before any positional    ones.  As an example, under UNIX,
  211. -       if this flag is SET then parseargs will consider the
  212. -       command line "cmd -x arg" to consist of one option and
  213. -       one positional argument; however the command line "cmd
  214. -       arg -x" would    be considered to consist of two    posi-
  215. -       tional arguments (the    -x option will be unmatched).
  216. -       If this flag is UNSET, then both of the previous exam-
  217. -       ples are considered to consist of one    option and one
  218. -       positional argument.
  219. -      pa_ANYCASE
  220. -       Setting this flag will cause character-case to be
  221. -       ignored when attempting to match single-character argu-
  222. -       ment names (i.e. causes "-i" and "-I"    to be considered
  223. -       equivalent).
  224. -      pa_ARGV0
  225. -       Normally, the    parseargs library will assume that the
  226. -       first    argument on the    command-line is    the name of the
  227. -       command. Setting this    flag tells parseargs that this is
  228. -       NOT the case and that    the very first argument    on the
  229. -       command-line is a bona-fide argument to the command.
  230. -      pa_NOCHECK
  231. -       Setting this flag will prevent parseargs from    checking
  232. -       for any required arguments that were not given on the
  233. -       command-line.    This is    useful when more than one call to
  234. -       the parseargs    library    is needed to parse all the
  235. -       command-line arguments (which    could occur if the
  236. -       command-line argument    came from a file or from two
  237. -       argv-vectors).
  238. -       Keeping this flag on until the final set of arguments
  239. -       is parsed will cause parseargs to not    check for missing
  240. -       arguments until the last set of arguments has    been
  241. -       parsed (by the final call to one of the functions in
  242. -       the parseargs    library).
  243. -      pa_CONTINUE
  244. -       Setting this flag will cause subsequent calls    to the
  245. -       parseargs library to NOT reset the current command-
  246. -       state. Hence,    all arguments will not be initially set
  247. - Page 5
  248. - PARSECNTL(3)                         PARSECNTL(3)
  249. -       to "NOT GIVEN" and other (normal) initializations are
  250. -       not be performed.  This is useful in conjunction with
  251. -       the pa_NOCHECK flag when more    than one call to par-
  252. -       seargs is required to    parse all the command arguments.
  253. -       In this scenario, pa_CONTINUE    should be unset    (the
  254. -       default setting) for the very    first call to parseargs,
  255. -       but should then be set before    any subsequent calls to
  256. -       parseargs are    made.
  257. -      pa_NOCMDENV
  258. -       Setting this flag prevents parseargs from checking the
  259. -       CMD-NAME_ARGS    environment variable (or symbol) for any
  260. -       user-defined default command arguments.
  261. -      pa_COPYF
  262. -       When this flag is OFF    (the default), a value of FALSE
  263. -       is provided as the copyf argument to all the arg-type
  264. -       (argXxxxx) functions when an argument    is matched. Set-
  265. -       ting this flag will cause a value of TRUE to be pro-
  266. -       vided    as the copyf argument to all the arg-type
  267. -       (argXxxxx) functions when an argument    is matched.
  268. - ARGUMENT FLAGS
  269. -      These are the possible bitmasks that may be turned    ON or OFF
  270. -      in    the ad_flags field of an ARGDESC structure.
  271. -      ARGOPT
  272. -       This flag is actually    a dummy    flag (i.e. it is the
  273. -       default). This flag specifies    that the command-line
  274. -       argument is optional (need not appear    on the command-
  275. -       line). It is only needed if no other flags are used to
  276. -       define the given argument.  If other flags are given
  277. -       and ARGREQ is    NOT one    of them, then ARGOPT is    always
  278. -       assumed.
  279. -      ARGREQ
  280. -       The associated command argument is required on the
  281. -       command-line.
  282. -      ARGPOS
  283. -       The associated command argument is positonal.    The
  284. -       difference between using this    flag to    indicate a posi-
  285. -       tional argument and between using a blank in the
  286. -       ad_name field    to indicate a positional arguments is the
  287. -       following: If    this flag is set but the ad_name of the
  288. -       argument is non-blank, then this argument may    be
  289. -       matched either positionally or by keyword. If    the
  290. -       ad_name field    is blank, then this argument may only be
  291. -       matched positionally.
  292. -      ARGNOVAL
  293. -       The associated command argument takes    no value (as in
  294. - Page 6
  295. - PARSECNTL(3)                         PARSECNTL(3)
  296. -       "-x value"); Its mere    presence (or lack thereof) on the
  297. -       command-line is sufficient to    determine the necessary
  298. -       action(s) to take (as    in "-x").  Boolean argument types
  299. -       and Pseudo-argument types automatically default to ARG-
  300. -       NOVAL.
  301. -      ARGVALOPT
  302. -       This flag is used to indicate    that the command-line
  303. -       argument takes a value (as in    "-s string" or
  304. -       "/str=string") but that the value to this command-line
  305. -       argument is NOT required (hence simply "-s" or "/str"
  306. -       is also permissable).
  307. -      ARGVALREQ
  308. -       Another "dummy" flag.    Unless ARGNOVAL    or ARGVALOPT is
  309. -       specified, ARGVALREQ is always assumed. This flag indi-
  310. -       cates    that the value to a command-line argument is
  311. -       required (hence "-s string" is okay but just "-s" is
  312. -       not).
  313. -      ARGHIDDEN
  314. -       Don't    display    this argument in usage messages    but still
  315. -       attempt to match it against strings given on the
  316. -       command-line.
  317. -      ARGLIST
  318. -       A variable number of values are used for this    argument
  319. -       (and hence may use more than one or two argv elements
  320. -       from the command-line    as in "-l val1 val2 ..."). The
  321. -       list of values must be stored    in an ArgList structure
  322. -       (NOT a vector    structure), an the corresponding
  323. -       argument-type    function should    be one of the listXxxx
  324. -       functions.
  325. -      ARGVEC
  326. -       A variable number of values are used for this    argument
  327. -       (and hence may use more than one or two argv elements
  328. -       from the command-line    as in in "-v val1 val2 ..."). The
  329. -       list of values must be stored    in a vector structure
  330. -       (NOT an ArgList structure).
  331. -      The following bitmasks may    also be    present, but, unlike the
  332. -      above masks which must be specified by the    programmer at
  333. -      initialization time, the following    masks must only    be read
  334. -      (never set) by the    programmer. They may be    queried    by using
  335. -      the pc_ARGFLAGS function code and the mode    pc_READ    with par-
  336. -      secntl(3).
  337. -      ARGGIVEN
  338. -       The argument WAS given on the    command-line.
  339. -      ARGVALGIVEN
  340. - Page 7
  341. - PARSECNTL(3)                         PARSECNTL(3)
  342. -       The value for    this argument was given    on the command-
  343. -       line.
  344. -      ARGVALSEP
  345. -       The value to this argument was supplied in a separate
  346. -       argv element from the    argument itself    (as in "-x value"
  347. -       as opposed to    "-xvalue").
  348. -      ARGKEYWORD
  349. -       This argument    was matched as a keyword (long-form) on
  350. -       the command-line and not as a    single character.
  351. -      ARGDESCRIBED
  352. -       This argument    was given a description    by the programmer
  353. -       at initialization.
  354. -      ARGCOPYF
  355. -       This flag is only used for lists and vectors (mul-
  356. -       tivalued arguments) and is used on a per-item    basis. If
  357. -       it is    set, it    means that the corresponding value in the
  358. -       vector/list required space to    be allocated (such as the
  359. -       duplication of a temporary string).
  360. - RETURN VALUE
  361. -      The functions in the parseargs library will return    a value
  362. -      of    zero upon succesful completion.    They may however, return
  363. -      any of the    following status codes (which are defined in
  364. -      <parseargs.h>):
  365. -      pe_SYSTEM
  366. -       A system error occurred. The global variable errno may
  367. -       indicate the problem (then again, it may not).
  368. -      pe_SUCCESS
  369. -       Success, no errors encountered (zero is returned).
  370. -      pe_SYNTAX
  371. -       A command-line syntax    error was encountered
  372. -      pe_DEFARGS
  373. -       An attempt (using parsecntl) was made    to change the
  374. -       default arg-search list of a command to point    to an
  375. -       argdesc-array    which already has the given command on
  376. -       its default arg-search list (which would cause an
  377. -       infinite loop    when attempting    to match an unknown
  378. -       command-line argument).
  379. -      pe_NOMATCH
  380. -       Unable to match the named argument. This occurs when
  381. -       the argument keyword name passed to parsecntl    (using
  382. -       the pc_ARGFLAGS functions code) was found in the given
  383. -       argdesc-array    or in its default-list.
  384. - Page 8
  385. - PARSECNTL(3)                         PARSECNTL(3)
  386. -      pe_BADMODE
  387. -       Bad mode for given command in    parsecntl. This    occurs
  388. -       when pc_WRITE    or pc_RDWR mode    is passed to parsecntl in
  389. -       conjunction with the pc_ARGFLAGS functions code.  Par-
  390. -       secntl will not modify existing arguments.
  391. -      pe_BADCNTL
  392. -       Bad command for parsecntl. This occurs if an unknown
  393. -       function-code    was passed to parsecntl.
  394. - SIDE EFFECTS
  395. -      Each of the functions in the parseargs library will set the
  396. -      external character    string ProgName    to be the name of the
  397. -      last command that was operated upon by any    of the library
  398. -      routines.
  399. -      When an argument-descriptor array is first    encountered by
  400. -      any of the    parseargs library routines, it is initially com-
  401. -      piled into    an intermediate    form that is more convenient to
  402. -      manipulate. As a direct result, it    is not advisable to
  403. -      attempt to    index directly into the    array to manipulate one
  404. -      of    the argument descriptors (because the argdesc that you
  405. -      thought was there may actually be somewhere else).    After the
  406. -      array has been given its initial value(s),    only parsecntl(3)
  407. -      should be used to manipulate or query the attributes of an
  408. -      argument descriptor.
  409. - SEE ALSO
  410. -      argtype(3), parseargs(3), parseargs(1)
  411. - AUTHOR
  412. -      Brad Appleton  (brad@ssd.csd.harris.com)
  413. -      Harris Computer Systems, Fort Lauderdale, FL USA
  414. - Page 9
  415. --- 0 ----
  416. diff -cNr ../patchlevel4/patchlevel.h ./patchlevel.h
  417. *** ../patchlevel4/patchlevel.h    Thu May  2 11:05:47 1991
  418. --- ./patchlevel.h    Thu May  2 14:36:20 1991
  419. ***************
  420. *** 2,22 ****
  421. X  ** ^FILE: patchlevel.h - current patchlevel for parseargs
  422. X  **
  423. X  ** ^HISTORY:
  424. X  **    04/10/91    Brad Appleton    <brad@ssd.csd.harris.com>
  425. X  **    Patch04
  426. X  **    - fixed problem with prompting in xparse.c:prompt_user()
  427. ! **    - under vms, getenv was defined to be 'getsymbol', it should be
  428. ! **      'get_symbol' (note the underscore).
  429. ! **    - now uses <errno.h>
  430. ! **    - parseargs no longer included <fcntl.h>
  431. X  **    - fix bug in vms_args.c printing '[]' for required args and vis-a-vis
  432. ! **    - fixed bug in argInput and argOutput in argtype.c
  433. X  **    - fixed bug in <os>_args.c where ARGVALGIVEN was improperly being
  434. X  **      cleared if the argument was a list or a vector. This was causing
  435. X  **      parseargs(1) to screw up on optional lists.
  436. ! **    - fixed bug in strfuncs.c:strnicmp()
  437. X  **    - changed strfuncs.[ch] so that my version of strdup is always used
  438. ! **      (my version dies if malloc failed, others return NULL).
  439. X  **    - Added some changes for SUN and VAX
  440. X  **    - Added -1 option to parseargs(1)
  441. X  **    - Unhid the -# option to parseargs(1)
  442. --- 2,36 ----
  443. X  ** ^FILE: patchlevel.h - current patchlevel for parseargs
  444. X  **
  445. X  ** ^HISTORY:
  446. + **    04/25/91    Brad Appleton    <brad@ssd.csd.harris.com>
  447. + **    Patch05
  448. + **    - documented support for zsh in parseargs(1)
  449. + **    - added missing call to pclose() in pgopen.c:pgclose()
  450. + **    - added zsh to the list of shells supported by parseargs(1)
  451. + **      (I have yet to document this in the man-pages)
  452. + **    - changed the shell_info structure used by parseargs(1) to 
  453. + **      represent different shells. It should now be much simpler
  454. + **      to add new shells to parseargs.c
  455. + **    - fixed a bug in strfuncs.c:basename() for VMS systems
  456. + **    - added more comments to explain whats going on in each <os>_args.c
  457. + **    - updated the README file to correspond with the patchlevel(s)
  458. + **    - updated dependencies in doc/Makefile
  459. + **
  460. X  **    04/10/91    Brad Appleton    <brad@ssd.csd.harris.com>
  461. X  **    Patch04
  462. X  **    - fixed problem with prompting in xparse.c:prompt_user()
  463. ! **    - under VMS, getenv was defined to be 'getsymbol', it should
  464. ! **      be 'get_symbol' (note the underscore).
  465. ! **    - now includes <errno.h> to declare errno
  466. ! **    - parseargs no longer includes <fcntl.h>
  467. X  **    - fix bug in vms_args.c printing '[]' for required args and vis-a-vis
  468. ! **    - fixed bug in argInput and argOutput in argtype.c for VMS
  469. X  **    - fixed bug in <os>_args.c where ARGVALGIVEN was improperly being
  470. X  **      cleared if the argument was a list or a vector. This was causing
  471. X  **      parseargs(1) to screw up on optional lists.
  472. ! **    - fixed bug in strfuncs.c:strnicmp() (it was ignoring the length)
  473. X  **    - changed strfuncs.[ch] so that my version of strdup is always used
  474. ! **      (my version exits if malloc failed, others return NULL).
  475. X  **    - Added some changes for SUN and VAX
  476. X  **    - Added -1 option to parseargs(1)
  477. X  **    - Unhid the -# option to parseargs(1)
  478. ***************
  479. *** 25,31 ****
  480. X  **    04/04/91    Brad Appleton    <brad@ssd.csd.harris.com>
  481. X  **    Patch04 (continued)
  482. X  **    - fixed bug in xparse.c with PARSECNTL='Prompt' being ignored.
  483. - **    - added test.pl to test.all and added options to test.all
  484. X  **    - fixed newline printing error in perl-scripts for parseargs(1)
  485. X  **    - added -C option to parseargs(1) and to the docs
  486. X  **    - added "patchlevel.h" to distribution
  487. --- 39,44 ----
  488. ***************
  489. *** 53,59 ****
  490. X  
  491. X  #define  VERSION     2
  492. X  #define  REVISION    0
  493. ! #define  PATCHLEVEL  4
  494. X  
  495. X  #ifdef __STDC__
  496. X     static const char
  497. --- 66,72 ----
  498. X  
  499. X  #define  VERSION     2
  500. X  #define  REVISION    0
  501. ! #define  PATCHLEVEL  5
  502. X  
  503. X  #ifdef __STDC__
  504. X     static const char
  505. ***************
  506. *** 60,63 ****
  507. X  #else
  508. X     static char
  509. X  #endif
  510. !    _Ident[] = "@(#)parseargs  2.0  patchlevel 4";
  511. --- 73,76 ----
  512. X  #else
  513. X     static char
  514. X  #endif
  515. !    _Ident[] = "@(#)parseargs  2.0  patchlevel 5";
  516. diff -cNr ../patchlevel4/pgopen.c ./pgopen.c
  517. *** ../patchlevel4/pgopen.c    Thu May  2 11:06:13 1991
  518. --- ./pgopen.c    Thu May  2 14:36:23 1991
  519. ***************
  520. *** 71,77 ****
  521. X  extern  int   strcmp();
  522. X  extern  int   access();
  523. X  extern  int   isatty();
  524. - extern  int   wait();
  525. X  extern  unsigned   sleep();
  526. X  
  527. X  static void  pg_error();       /* broken-pipe exception handler */
  528. --- 71,76 ----
  529. ***************
  530. *** 157,163 ****
  531. X  **    - if we used popen() to open this pager then
  532. X  **       - call pclose to close the pager-program
  533. X  **       - unset the SIGPIPE signal-handler
  534. - **       - wait for the pager-process to die
  535. X  **      end-if
  536. X  **    - reset the pager-file-pointer to NULL
  537. X  **    - set the pager-state to closed
  538. --- 156,161 ----
  539. ***************
  540. *** 172,179 ****
  541. X     fflush( Pager_FP );
  542. X  
  543. X     if ( Pager_Type == PG_ENV  ||  Pager_Type == PG_DFLT ) {
  544. !       signal( SIGPIPE, (void (*)())SIG_IGN );
  545. !       wait( (int *) 0 );
  546. X     }
  547. X  
  548. X     Pager_FP = (FILE *)NULL;
  549. --- 170,177 ----
  550. X     fflush( Pager_FP );
  551. X  
  552. X     if ( Pager_Type == PG_ENV  ||  Pager_Type == PG_DFLT ) {
  553. !       (VOID) pclose( Pager_FP );
  554. !       (VOID) signal( SIGPIPE, (void (*)())SIG_IGN );
  555. X     }
  556. X  
  557. X     Pager_FP = (FILE *)NULL;
  558. diff -cNr ../patchlevel4/strfuncs.c ./strfuncs.c
  559. *** ../patchlevel4/strfuncs.c    Thu May  2 11:06:14 1991
  560. --- ./strfuncs.c    Thu May  2 14:36:35 1991
  561. ***************
  562. *** 12,17 ****
  563. --- 12,19 ----
  564. X  **       strlcpy() -- copy a string and map to lowercase
  565. X  **       strupr() -- convert a string to uppercase
  566. X  **       strlwr() -- convert a string to lowercase
  567. + **       stricmp() -- case insensitive comparison of strings
  568. + **       strnicmp() -- case insensitive length-limited comparison of strings
  569. X  **       strdup() -- return a (newly allocated) copy of a string
  570. X  **       strpbrk() -- return first occurrence of character in a set
  571. X  **       strspn() -- return length of initial prefix of a character set
  572. ***************
  573. *** 20,31 ****
  574. X  **       strrtrim() -- trim rightmost (trailing) characters in a string
  575. X  **       strtrim() -- trim leading and trailing characters in a string
  576. X  **       strsplit() -- split a string up into a vector of tokens
  577. ! **       strjoin() -- join a vector of token into a single string
  578. X  **       get_name() -- return the aname (argument-name) of an argument
  579. X  **       get_keyword() -- return the sname (keyword-name) of an argument
  580. X  **       match() -- match two keywords (case insensitive) upto a unique prefix
  581. - **       stricmp() -- case insensitive comparison of strings
  582. - **       strnicmp() -- case insensitive length-limited comparison of strings
  583. X  **       basename() -- remove the leading directories (and disks) from a path
  584. X  **       indent_para() -- print an indented hanging paragraph
  585. X  **
  586. --- 22,31 ----
  587. X  **       strrtrim() -- trim rightmost (trailing) characters in a string
  588. X  **       strtrim() -- trim leading and trailing characters in a string
  589. X  **       strsplit() -- split a string up into a vector of tokens
  590. ! **       strjoin() -- join a vector of tokens into a single string
  591. X  **       get_name() -- return the aname (argument-name) of an argument
  592. X  **       get_keyword() -- return the sname (keyword-name) of an argument
  593. X  **       match() -- match two keywords (case insensitive) upto a unique prefix
  594. X  **       basename() -- remove the leading directories (and disks) from a path
  595. X  **       indent_para() -- print an indented hanging paragraph
  596. X  **
  597. ***************
  598. *** 601,607 ****
  599. X  **    - for i in 0 .. (numtokens - 1) do
  600. X  **         - vector[i] = token_str
  601. X  **         - advance token_str to point at the next character past the
  602. ! **           righmost NUL-byte (which should be the start of the next token).
  603. X  **      end-for
  604. X  **    - return the number of tokens parsed.
  605. X  ***^^**********************************************************************/
  606. --- 601,607 ----
  607. X  **    - for i in 0 .. (numtokens - 1) do
  608. X  **         - vector[i] = token_str
  609. X  **         - advance token_str to point at the next character past the
  610. ! **           rightmost NUL-byte (which should be the start of the next token).
  611. X  **      end-for
  612. X  **    - return the number of tokens parsed.
  613. X  ***^^**********************************************************************/
  614. ***************
  615. *** 680,687 ****
  616. X  
  617. X  /* ^DESCRIPTION:
  618. X  **    Strjoin will make a single string out of the given vector by copying
  619. ! **    all the tokens from the given vector (in order) toa newly allocated
  620. ! **    string. Each token will be separated by an occurence of <separator>.
  621. X  **
  622. X  **    If <separator> is NULL then a single space is used as the separator.
  623. X  **    If <separator> is empty, then no separator is used and the tokens are
  624. --- 680,687 ----
  625. X  
  626. X  /* ^DESCRIPTION:
  627. X  **    Strjoin will make a single string out of the given vector by copying
  628. ! **    all the tokens from the given vector (in order) to a newly allocated
  629. ! **    string. Tokens will be separated by a single occurence of <separator>.
  630. X  **
  631. X  **    If <separator> is NULL then a single space is used as the separator.
  632. X  **    If <separator> is empty, then no separator is used and the tokens are
  633. ***************
  634. *** 688,701 ****
  635. X  **    simply concatenated together.
  636. X  **
  637. X  ** ^REQUIREMENTS:
  638. ! **    argv must be non-NULL (it must be a valid address), and must be terminated
  639. ! **    by a pointer to NULL (argv[last+1] == NULL).
  640. X  **
  641. X  ** ^SIDE-EFECTS:
  642. X  **    Storage is allocated.
  643. X  **
  644. X  ** ^RETURN-VALUE:
  645. ! **    The addres of the newly-joined results (which should be deallocated
  646. X  **    using free()). Returns NULL if nothing was joined.
  647. X  **
  648. X  ** ^ALGORITHM:
  649. --- 688,701 ----
  650. X  **    simply concatenated together.
  651. X  **
  652. X  ** ^REQUIREMENTS:
  653. ! **    argv must be non-NULL (it must be a valid address), and must be
  654. ! **    terminated by a pointer to NULL (argv[last+1] == NULL).
  655. X  **
  656. X  ** ^SIDE-EFECTS:
  657. X  **    Storage is allocated.
  658. X  **
  659. X  ** ^RETURN-VALUE:
  660. ! **    The address of the newly-joined result (which should be deallocated
  661. X  **    using free()). Returns NULL if nothing was joined.
  662. X  **
  663. X  ** ^ALGORITHM:
  664. ***************
  665. *** 1078,1084 ****
  666. X  
  667. X        if ( vers )  *vers ='\0';
  668. X        if ( ext  &&  (!stricmp(ext, ".COM") || !stricmp(ext, ".EXE")) ) {
  669. !           ext = '\0';
  670. X        }
  671. X  
  672. X        return  base;
  673. --- 1078,1084 ----
  674. X  
  675. X        if ( vers )  *vers ='\0';
  676. X        if ( ext  &&  (!stricmp(ext, ".COM") || !stricmp(ext, ".EXE")) ) {
  677. !           *ext = '\0';
  678. X        }
  679. X  
  680. X        return  base;
  681. ***************
  682. *** 1200,1206 ****
  683. X     char ch;
  684. X  
  685. X     /* print the title */
  686. !       fprintf( fp, "%*s%-*s", margin, "", indent, title );
  687. X  
  688. X     idx = maxcols - margin - indent;
  689. X  
  690. --- 1200,1206 ----
  691. X     char ch;
  692. X  
  693. X     /* print the title */
  694. !    fprintf( fp, "%*s%-*s", margin, "", indent, title );
  695. X  
  696. X     idx = maxcols - margin - indent;
  697. X  
  698. diff -cNr ../patchlevel4/strfuncs.h ./strfuncs.h
  699. *** ../patchlevel4/strfuncs.h    Thu May  2 11:06:15 1991
  700. --- ./strfuncs.h    Thu May  2 14:36:38 1991
  701. ***************
  702. *** 32,37 ****
  703. --- 32,38 ----
  704. X  EXTERN  char  *strtrim      ARGS(( char *, const char * ));
  705. X  EXTERN  int    strsplit     ARGS(( char ***, char *, const char * ));
  706. X  EXTERN  char  *strjoin      ARGS(( const char **, const char * ));
  707. X  EXTERN  char  *get_name     ARGS(( const char *, char * ));
  708. X  EXTERN  char  *get_keyword  ARGS(( const char *, char * ));
  709. X  EXTERN  int    match        ARGS(( const char *, const char * ));
  710. diff -cNr ../patchlevel4/test.ksh ./test.ksh
  711. *** ../patchlevel4/test.ksh    Thu May  2 10:57:08 1991
  712. --- ./test.ksh    Thu May  2 14:36:50 1991
  713. ***************
  714. *** 22,33 ****
  715. X  export ARGUMENTS
  716. X  
  717. X  ## set defaults ##
  718. - typeset groups[]           ## default group used by everyone
  719. X  typeset count='1'          ## only do once unless otherwise specified
  720. X  typeset dirname='.'        ## default to current directory
  721. X  typeset xflag=''           ## default xflag is false
  722. X  typeset yflag='TRUE'       ## default yflag is true
  723. X  typeset sepch=','          ## default separator is a comma
  724. X  typeset files[]
  725. X  
  726. X  ## parse command-line ##
  727. --- 22,33 ----
  728. X  export ARGUMENTS
  729. X  
  730. X  ## set defaults ##
  731. X  typeset count='1'          ## only do once unless otherwise specified
  732. X  typeset dirname='.'        ## default to current directory
  733. X  typeset xflag=''           ## default xflag is false
  734. X  typeset yflag='TRUE'       ## default yflag is true
  735. X  typeset sepch=','          ## default separator is a comma
  736. + typeset groups[]
  737. X  typeset files[]
  738. X  
  739. X  ## parse command-line ##
  740. diff -cNr ../patchlevel4/test.zsh ./test.zsh
  741. *** ../patchlevel4/test.zsh    Wed Dec 31 18:00:00 1969
  742. --- ./test.zsh    Thu May  2 14:36:59 1991
  743. ***************
  744. *** 0 ****
  745. --- 1,65 ----
  746. + #!/bin/zsh
  747. + #
  748. + #    test.zsh - Z shell script to test out the parseargs command!
  749. + #
  750. + NAME="`basename $0`"
  751. + ARGUMENTS="
  752. +   '?', ARGHIDDEN, argUsage, NULL,    'Help -- print usage and exit',
  753. +   'S', ARGVALOPT, argStr,   string,  'STRing -- optional string arg',
  754. +   'g', ARGLIST,   argStr,   groups,  'newsGROUPS -- groups to test',
  755. +   'r', ARGOPT,    argInt,   count,   'REPcount -- number to repeat each group',
  756. +   'd', ARGOPT,    argStr,   dirname, 'DIRectory -- working directory',
  757. +   'x', ARGOPT,    argBool,  xflag,   'Xflag -- turn on X-mode',
  758. +   'y', ARGOPT,    argUBool, yflag,   'Yflag -- turn off Y-mode',
  759. +   's', ARGOPT,    argChar,  sepch,   'SEPchar -- field separator',
  760. +   'f', ARGLIST,   argStr,   files,   'files -- files to process',
  761. +   'n', ARGREQ|ARGPOS, argStr, name,  'name -- name to use',
  762. +   ' ', ARGLIST,   argStr,   argv,    'argv -- any remaining arguments',
  763. +   ENDOFARGS
  764. + "
  765. + export ARGUMENTS
  766. + ## set defaults ##
  767. + typeset count='1'          ## only do once unless otherwise specified
  768. + typeset dirname='.'        ## default to current directory
  769. + typeset xflag=''           ## default xflag is false
  770. + typeset yflag='TRUE'       ## default yflag is true
  771. + typeset sepch=','          ## default separator is a comma
  772. + typeset groups
  773. + typeset files  
  774. + ## parse command-line ##
  775. + parseargs -s zsh -e ARGUMENTS -u -- "$NAME" "$@" >/tmp/tmp$$
  776. + if [ $? -ne 0 ] ; then
  777. +   rm -f /tmp/tmp$$
  778. +   exit 2  ## improper syntax (or just wanted usage)
  779. + fi
  780. + ## evaluate results from parseargs and remove temporary file ##
  781. + INTERPRET="."
  782. + $INTERPRET /tmp/tmp$$
  783. + rm -f /tmp/tmp$$
  784. + ## print arguments ##
  785. + print "ARGUMENTS:"
  786. + print "=========="
  787. + print "Groups='${groups[@]}'"
  788. + print "Count='$count'"
  789. + print "Directory='$dirname'"
  790. + print "XFlag='$xflag'"
  791. + print "YFlag='$yflag'"
  792. + print "SepChar='$sepch'"
  793. + print "Name='$name'"
  794. + print "Files='${files[@]}'"
  795. + if [ "$string_flag" ] ; then
  796. +   string=${string:-"!string arg ommitted on cmd-line!"}
  797. + else
  798. +   string="default string"
  799. + fi
  800. + print "String='$string'"
  801. + print "New Positional Parameters='$*'"
  802. + ## print usage ##
  803. + parseargs -a "$ARGUMENTS" -U "$NAME"
  804. diff -cNr ../patchlevel4/unix_args.c ./unix_args.c
  805. *** ../patchlevel4/unix_args.c    Thu May  2 11:06:16 1991
  806. --- ./unix_args.c    Thu May  2 14:37:02 1991
  807. ***************
  808. *** 128,134 ****
  809. X     cmd = argd;
  810. X  
  811. X     while ( av  &&  (p = *av++) ) {
  812. !       if ( isKWD(p) ) {
  813. X           char *s, c = '\0';
  814. X  
  815. X           /* check for `++' to end flags */
  816. --- 128,134 ----
  817. X     cmd = argd;
  818. X  
  819. X     while ( av  &&  (p = *av++) ) {
  820. !       if ( isKWD(p) ) {  /* we have a keyword here */
  821. X           char *s, c = '\0';
  822. X  
  823. X           /* check for `++' to end flags */
  824. ***************
  825. *** 166,171 ****
  826. --- 166,176 ----
  827. X              continue;
  828. X           }
  829. X  
  830. +          /* reset the argument flags - if this arg was already given, some
  831. +          ** of its flags may be set to indicate how it was given before. 
  832. +          ** we need to know how it was given now (but save the old ones
  833. +          ** just in case the new one fails).
  834. +          */
  835. X           flags = arg_flags(ad);
  836. X           if ( ARG_isGIVEN(ad) ) {
  837. X              BCLEAR( arg_flags(ad), ARGVALSEP | ARGKEYWORD );
  838. ***************
  839. *** 174,180 ****
  840. X  
  841. X           BSET( arg_flags(ad), ARGKEYWORD );
  842. X  
  843. !          if( ARG_isMULTIVAL(ad) ) {
  844. X              cmd_list(cmd) = ad;
  845. X           }
  846. X           else {
  847. --- 179,185 ----
  848. X  
  849. X           BSET( arg_flags(ad), ARGKEYWORD );
  850. X  
  851. !          if( ARG_isMULTIVAL(ad) ) { /* we matched a list (or a vector) */
  852. X              cmd_list(cmd) = ad;
  853. X           }
  854. X           else {
  855. ***************
  856. *** 245,251 ****
  857. X              continue;
  858. X           }
  859. X  
  860. !             /* flag argument */
  861. X           while (*p) {
  862. X  
  863. X                 /* find the flag in the list */
  864. --- 250,261 ----
  865. X              continue;
  866. X           }
  867. X  
  868. !          /* We have a flag argument;
  869. !          ** remember that in the case of single character keywords,
  870. !          ** the conversion function (ad_type) tells us how many characters
  871. !          ** were used. We need that information to decide how many 
  872. !          ** characters to skip before the next iteration of the while loop.
  873. !          */
  874. X           while (*p) {
  875. X  
  876. X                 /* find the flag in the list */
  877. ***************
  878. *** 276,281 ****
  879. --- 286,296 ----
  880. X                    continue;
  881. X              }/* if unknown-option */
  882. X  
  883. +             /* reset the argument flags - if this arg was already given, some
  884. +             ** of its flags may be set to indicate how it was given before.
  885. +             ** we need to know how it was given now (but save the old ones
  886. +             ** just in case the new one fails).
  887. +             */
  888. X              flags = arg_flags(ad);
  889. X              if ( ARG_isGIVEN(ad) ) {
  890. X                 BCLEAR( arg_flags(ad), ARGVALSEP | ARGKEYWORD );
  891. ***************
  892. *** 283,289 ****
  893. X              }
  894. X  
  895. X              if( ARG_isMULTIVAL(ad) ) {
  896. !                cmd_list(cmd) = ad;
  897. X              }
  898. X              else {
  899. X                 cmd_list(cmd) = ARGDESCNULL;
  900. --- 298,304 ----
  901. X              }
  902. X  
  903. X              if( ARG_isMULTIVAL(ad) ) {
  904. !                cmd_list(cmd) = ad;  /* we matched a list (or a vector) */
  905. X              }
  906. X              else {
  907. X                 cmd_list(cmd) = ARGDESCNULL;
  908. ***************
  909. *** 358,365 ****
  910. X        }/*elif option*/
  911. X        else {
  912. X              /* parsing a list of arguments */
  913. !          if ( cmd_list(cmd) ) {
  914. X              ad = cmd_list(cmd);
  915. X              flags = arg_flags(ad);
  916. X              if ( ARG_isGIVEN(ad) ) {
  917. X                 BCLEAR( arg_flags(ad), ARGVALSEP | ARGKEYWORD );
  918. --- 373,386 ----
  919. X        }/*elif option*/
  920. X        else {
  921. X              /* parsing a list of arguments */
  922. !          if ( cmd_list(cmd) ) {  /* we're in the middle of a list */
  923. X              ad = cmd_list(cmd);
  924. +             /* reset the argument flags - if this arg was already given, some
  925. +             ** of its flags may be set to indicate how it was given before.
  926. +             ** we need to know how it was given now (but save the old ones
  927. +             ** just in case the new one fails).
  928. +             */
  929. X              flags = arg_flags(ad);
  930. X              if ( ARG_isGIVEN(ad) ) {
  931. X                 BCLEAR( arg_flags(ad), ARGVALSEP | ARGKEYWORD );
  932. ***************
  933. *** 395,400 ****
  934. --- 416,426 ----
  935. X              continue;
  936. X           }
  937. X  
  938. +          /* reset the argument flags - if this arg was already given, some
  939. +          ** of its flags may be set to indicate how it was given before.
  940. +          ** we need to know how it was given now (but save the old ones
  941. +          ** just in case the new one fails).
  942. +          */
  943. X           flags = arg_flags(ad);
  944. X           if ( ARG_isGIVEN(ad) ) {
  945. X              BCLEAR( arg_flags(ad), ARGVALSEP | ARGKEYWORD );
  946. ***************
  947. *** 401,410 ****
  948. X              if ( !ARG_isMULTIVAL(ad) )  BCLEAR( arg_flags(ad), ARGVALGIVEN );
  949. X           }
  950. X  
  951. !          if ( ARG_isMULTIVAL(ad) ) {
  952. X              cmd_list(cmd) = ad;
  953. X           }
  954. X  
  955. X           if ( BTEST(cmd_flags(cmd), pa_FLAGS1ST) ) {
  956. X              BSET( cmd_state(cmd), ps_NOFLAGS );
  957. X           }
  958. --- 427,437 ----
  959. X              if ( !ARG_isMULTIVAL(ad) )  BCLEAR( arg_flags(ad), ARGVALGIVEN );
  960. X           }
  961. X  
  962. !          if ( ARG_isMULTIVAL(ad) ) {  /* we positionally matched a list */
  963. X              cmd_list(cmd) = ad;
  964. X           }
  965. X  
  966. +          /* if FLAGS1ST is set then first positional marks end-of-flags */
  967. X           if ( BTEST(cmd_flags(cmd), pa_FLAGS1ST) ) {
  968. X              BSET( cmd_state(cmd), ps_NOFLAGS );
  969. X           }
  970. diff -cNr ../patchlevel4/useful.h ./useful.h
  971. *** ../patchlevel4/useful.h    Thu May  2 11:06:17 1991
  972. --- ./useful.h    Thu May  2 14:37:07 1991
  973. ***************
  974. *** 25,31 ****
  975. X  #ifndef _USEFUL_H_
  976. X  #define _USEFUL_H_
  977. X  
  978. ! #if ( defined(_unix) || defined(UNIX) || defined(__UNIX) )
  979. X  # ifndef unix
  980. X  #   define unix
  981. X  # endif
  982. --- 25,31 ----
  983. X  #ifndef _USEFUL_H_
  984. X  #define _USEFUL_H_
  985. X  
  986. ! #if (defined(_unix) || defined(__unix) || defined(_unix_) || defined(__unix__))
  987. X  # ifndef unix
  988. X  #   define unix
  989. X  # endif
  990. ***************
  991. *** 44,50 ****
  992. X  #  ifdef sun
  993. X  #   define BSD
  994. X  #  endif
  995. ! #  ifdef apollo
  996. X  #   define BSD
  997. X  #  endif
  998. X  #  if ( defined(_CX_UX) && defined(ucb_universe) )
  999. --- 44,50 ----
  1000. X  #  ifdef sun
  1001. X  #   define BSD
  1002. X  #  endif
  1003. ! #  if ( defined(apollo) || defined(aegis) )
  1004. X  #   define BSD
  1005. X  #  endif
  1006. X  #  if ( defined(_CX_UX) && defined(ucb_universe) )
  1007. ***************
  1008. *** 203,209 ****
  1009. X  #  define FILENULL    ((FILE *) NULL)
  1010. X  #endif
  1011. X  
  1012. ! #ifdef __ANSI_C__
  1013. X     typedef   void *ARBPTR;
  1014. X  #else
  1015. X     typedef   char *ARBPTR;
  1016. --- 203,209 ----
  1017. X  #  define FILENULL    ((FILE *) NULL)
  1018. X  #endif
  1019. X  
  1020. ! #if ( defined(__ANSI_C__)  ||  defined(vms) )
  1021. X     typedef   void *ARBPTR;
  1022. X  #else
  1023. X     typedef   char *ARBPTR;
  1024. diff -cNr ../patchlevel4/vms_args.c ./vms_args.c
  1025. *** ../patchlevel4/vms_args.c    Thu May  2 11:06:18 1991
  1026. --- ./vms_args.c    Thu May  2 14:37:09 1991
  1027. ***************
  1028. *** 653,659 ****
  1029. X              cmd_flags(cmd) = saveflags;
  1030. X              exit(1);
  1031. X           }
  1032. !             /* have we seen this one before */
  1033. X           flags = arg_flags(ad);
  1034. X           if ( ARG_isGIVEN(ad) ) {
  1035. X              BCLEAR( arg_flags(ad), ARGVALSEP );
  1036. --- 653,663 ----
  1037. X              cmd_flags(cmd) = saveflags;
  1038. X              exit(1);
  1039. X           }
  1040. !          /* reset the argument flags - if this arg was already given, some
  1041. !          ** of its flags may be set to indicate how it was given before.
  1042. !          ** we need to know how it was given now (but save the old ones
  1043. !          ** just in case the new one fails).
  1044. !          */
  1045. X           flags = arg_flags(ad);
  1046. X           if ( ARG_isGIVEN(ad) ) {
  1047. X              BCLEAR( arg_flags(ad), ARGVALSEP );
  1048. ***************
  1049. *** 752,760 ****
  1050. --- 756,771 ----
  1051. X              continue;
  1052. X           }
  1053. X  
  1054. +          /* if FLAGS1ST is set then first positional marks end-of-flags */
  1055. X           if ( BTEST(cmd_flags(cmd), pa_FLAGS1ST) ) {
  1056. X              BSET( cmd_state(cmd), ps_NOFLAGS );
  1057. X           }
  1058. +          /* reset the argument flags - if this arg was already given, some
  1059. +          ** of its flags may be set to indicate how it was given before.
  1060. +          ** we need to know how it was given now (but save the old ones
  1061. +          ** just in case the new one fails).
  1062. +          */
  1063. X           flags = arg_flags(ad);
  1064. X           if ( ARG_isGIVEN(ad) ) {
  1065. X              BCLEAR( arg_flags(ad), ARGVALSEP );
  1066. diff -cNr ../patchlevel4/winsize.c ./winsize.c
  1067. *** ../patchlevel4/winsize.c    Thu May  2 10:57:14 1991
  1068. --- ./winsize.c    Thu May  2 14:37:13 1991
  1069. ***************
  1070. *** 46,52 ****
  1071. X  **     System dependent.
  1072. X  ***^^**********************************************************************/
  1073. X  
  1074. ! #if ( defined(__STDC__) || defined(c_plusplus) || defined(__cplusplus) )
  1075. X  # define  GET_WINSIZE(fd,nrows,ncols)  \
  1076. X      void get_winsize( int fd, int *nrows, int *ncols )
  1077. X  #else
  1078. --- 46,54 ----
  1079. X  **     System dependent.
  1080. X  ***^^**********************************************************************/
  1081. X  
  1082. ! #include <stdio.h>
  1083. ! #ifdef __ANSI_C__
  1084. X  # define  GET_WINSIZE(fd,nrows,ncols)  \
  1085. X      void get_winsize( int fd, int *nrows, int *ncols )
  1086. X  #else
  1087. ***************
  1088. *** 55,63 ****
  1089. X      int fd, *nrows, *ncols;   /* nrows and ncols are passed by reference */
  1090. X  #endif
  1091. X  
  1092. - #include <stdio.h>
  1093. - #include <useful.h>
  1094. X  #define  DEFAULT_ROWS  24
  1095. X  #define  DEFAULT_COLS  80
  1096. X  
  1097. --- 57,62 ----
  1098. ***************
  1099. *** 67,72 ****
  1100. --- 66,72 ----
  1101. X  #include <iodef.h>
  1102. X  #include <ssdef.h>
  1103. X  #include <descrip.h>
  1104. + #include <useful.h>
  1105. X  
  1106. X     /* structure to contain terminal characteristics */
  1107. X  typedef  struct {
  1108. ***************
  1109. *** 127,132 ****
  1110. --- 127,134 ----
  1111. X  #if ( !defined(TIOCGWINSZ)  &&  !defined(TIOCGSIZE)  &&  !defined(WIOCGETD) )
  1112. X  #include <sgtty.h>
  1113. X  #endif
  1114. + #include <useful.h>
  1115. X  
  1116. X  /*
  1117. X  ** get_winsize() -- determine # of rows/columns that will fit on the screen.
  1118. diff -cNr ../patchlevel4/xparse.c ./xparse.c
  1119. *** ../patchlevel4/xparse.c    Thu May  2 11:06:20 1991
  1120. --- ./xparse.c    Thu May  2 14:37:17 1991
  1121. ***************
  1122. *** 139,145 ****
  1123. X  #endif
  1124. X  
  1125. X  
  1126. ! #if vms
  1127. X  #  define  USER_VARIABLE "symbol"
  1128. X  #else
  1129. X  #  define  USER_VARIABLE "environment variable"
  1130. --- 139,145 ----
  1131. X  #endif
  1132. X  
  1133. X  
  1134. ! #ifdef vms
  1135. X  #  define  USER_VARIABLE "symbol"
  1136. X  #else
  1137. X  #  define  USER_VARIABLE "environment variable"
  1138. ***************
  1139. *** 180,186 ****
  1140. X  **    command-name (specified on the command-line) of the command that
  1141. X  **    has most recently invoked a function in the parseargs library.
  1142. X  ***^^**********************************************************************/
  1143. ! CONST char *ProgName = (char *)NULL;
  1144. X  
  1145. X  EXTERN  VOID  syserr   ARGS((const char *, ...));
  1146. X  EXTERN  VOID  usrerr   ARGS((const char *, ...));
  1147. --- 180,186 ----
  1148. X  **    command-name (specified on the command-line) of the command that
  1149. X  **    has most recently invoked a function in the parseargs library.
  1150. X  ***^^**********************************************************************/
  1151. ! CONST char *ProgName = CHARNULL;
  1152. X  
  1153. X  EXTERN  VOID  syserr   ARGS((const char *, ...));
  1154. X  EXTERN  VOID  usrerr   ARGS((const char *, ...));
  1155. ***************
  1156. *** 521,527 ****
  1157. X     register ARGDESC *ad, *anchor;
  1158. X     int  ad_count = 0;
  1159. X     BOOL old_style = FALSE;
  1160. !    char *description = (char *)NULL, *purpose = (char *)NULL;
  1161. X  
  1162. X     if ( !argd )  return;
  1163. X  
  1164. --- 521,527 ----
  1165. X     register ARGDESC *ad, *anchor;
  1166. X     int  ad_count = 0;
  1167. X     BOOL old_style = FALSE;
  1168. !    char *description = CHARNULL, *purpose = CHARNULL;
  1169. X  
  1170. X     if ( !argd )  return;
  1171. X  
  1172. ***************
  1173. *** 1382,1388 ****
  1174. X        BSET( cmd_state(cmd), ps_NOCMDENV );
  1175. X  
  1176. X            /* split line up into whitespace separated tokens */
  1177. !       if ( !strsplit( &argv, env_val, (char *)NULL ) ) {
  1178. X           free( argv );
  1179. X           return;
  1180. X        }
  1181. --- 1382,1388 ----
  1182. X        BSET( cmd_state(cmd), ps_NOCMDENV );
  1183. X  
  1184. X            /* split line up into whitespace separated tokens */
  1185. !       if ( !strsplit( &argv, env_val, CHARNULL ) ) {
  1186. X           free( argv );
  1187. X           return;
  1188. X        }
  1189. ***************
  1190. *** 1874,1880 ****
  1191. X     BSET(cmd_flags(argd), pa_ARGV0);
  1192. X  
  1193. X        /* split line up into whitespace separated tokens */
  1194. !    if ( !strsplit( &argv, str, (char *)NULL ) ) {
  1195. X        free( argv );
  1196. X        return  rc;
  1197. X     }
  1198. --- 1874,1880 ----
  1199. X     BSET(cmd_flags(argd), pa_ARGV0);
  1200. X  
  1201. X        /* split line up into whitespace separated tokens */
  1202. !    if ( !strsplit( &argv, str, CHARNULL ) ) {
  1203. X        free( argv );
  1204. X        return  rc;
  1205. X     }
  1206. ***************
  1207. *** 1972,1977 ****
  1208. --- 1972,1997 ----
  1209. X  
  1210. X     if ( !CMD_isINIT(argd) )  init_args(argd);
  1211. X  
  1212. +       /* We want the following scenario for the various calls to sparseargs():
  1213. +       ** assume there are N lines in the input file. Then there will be N
  1214. +       ** calls to sparseargs(). For all calls, we want pa_ARGV0 and pa_COPYF
  1215. +       ** to be ON. Then for the ALL but the very last call, we want pa_NOCHECK
  1216. +       ** to be off. For all but the very first call - we want pa_CONTINUE to
  1217. +       ** be turned ON. So we have the following table:
  1218. +       **
  1219. +       **     Parse     ||           invocation of sparseargs
  1220. +       **      Flag     ||   0    |     1     |     2 .. N-1    |     N
  1221. +       **   ============++========+===========+=================+=============== 
  1222. +       **      ARGV0    ||   on   |    on     |       on        |     on
  1223. +       **   ------------++--------+-----------+-----------------+--------------- 
  1224. +       **      COPYF    ||   on   |    on     |       on        |     on
  1225. +       **   ------------++--------+-----------+-----------------+--------------- 
  1226. +       **      NOCHECK  ||   on   |    on     |       on        |     OFF
  1227. +       **   ------------++--------+-----------+-----------------+--------------- 
  1228. +       **      CONTINUE ||   OFF  |    on     |       on        |     on
  1229. +       **   ============++========+===========+=================+=============== 
  1230. +       */
  1231. +       
  1232. X        /* save old flags & initialize parse flags for first call */
  1233. X     saveflags = cmd_flags(argd);
  1234. X     BSET(cmd_flags(argd), pa_ARGV0 | pa_NOCHECK | pa_COPYF);
  1235. ***************
  1236. *** 1985,1997 ****
  1237. X        }/*if*/
  1238. X  
  1239. X           /* trim leading and trailing whitespace and check for comments */
  1240. !       (VOID) strtrim( text, (char *)NULL );
  1241. X        if ( !text  ||  !(*text)  ||  *text == c_COMMENT )  continue;
  1242. X  
  1243. X        rc = sparseargs( text, argd );
  1244. X  
  1245. X           /* set up parseflags for next call */
  1246. !       BSET(cmd_flags(argd), pa_CONTINUE);
  1247. X     }/*while !EOF*/
  1248. X  
  1249. X     if ( !BTEST(saveflags, pa_NOCHECK) )  BCLEAR(cmd_flags(argd), pa_NOCHECK);
  1250. --- 2005,2019 ----
  1251. X        }/*if*/
  1252. X  
  1253. X           /* trim leading and trailing whitespace and check for comments */
  1254. !       (VOID) strtrim( text, CHARNULL );
  1255. X        if ( !text  ||  !(*text)  ||  *text == c_COMMENT )  continue;
  1256. X  
  1257. X        rc = sparseargs( text, argd );
  1258. X  
  1259. X           /* set up parseflags for next call */
  1260. !       if ( !BTEST(cmd_flags(argd), pa_CONTINUE) ) {
  1261. !          BSET(cmd_flags(argd), pa_CONTINUE);
  1262. !       }
  1263. X     }/*while !EOF*/
  1264. X  
  1265. X     if ( !BTEST(saveflags, pa_NOCHECK) )  BCLEAR(cmd_flags(argd), pa_NOCHECK);
  1266. ***************
  1267. *** 2079,2085 ****
  1268. X        /* allocate a NULL terminated arg-vector */
  1269. X     argv = (char **)malloc( (argc + 1) * sizeof(char *) );
  1270. X     if ( !argv )  return  pe_SYSTEM;
  1271. !    argv[ argc ] = (char *)NULL;
  1272. X  
  1273. X        /* make 2nd pass to assign the elements of the vector */
  1274. X     for ( ls = argls, i = 0 ; ls ; ls = L_NEXT(ls), i++ ) {
  1275. --- 2101,2107 ----
  1276. X        /* allocate a NULL terminated arg-vector */
  1277. X     argv = (char **)malloc( (argc + 1) * sizeof(char *) );
  1278. X     if ( !argv )  return  pe_SYSTEM;
  1279. !    argv[ argc ] = CHARNULL;
  1280. X  
  1281. X        /* make 2nd pass to assign the elements of the vector */
  1282. X     for ( ls = argls, i = 0 ; ls ; ls = L_NEXT(ls), i++ ) {
  1283. ***************
  1284. *** 2183,2189 ****
  1285. X        /* allocate a NULL terminated arg-vector */
  1286. X     argv = (char **) malloc( (argc + 1) * sizeof(char *) );
  1287. X     if ( !argv )  return  pe_SYSTEM;
  1288. !    argv[ argc ] = (char *)NULL;
  1289. X  
  1290. X     VA_START(ap, argc);
  1291. X     for ( i = 0; i < argc  &&  (arg = VA_ARG(ap, char *)) ; i++ ) {
  1292. --- 2205,2211 ----
  1293. X        /* allocate a NULL terminated arg-vector */
  1294. X     argv = (char **) malloc( (argc + 1) * sizeof(char *) );
  1295. X     if ( !argv )  return  pe_SYSTEM;
  1296. !    argv[ argc ] = CHARNULL;
  1297. X  
  1298. X     VA_START(ap, argc);
  1299. X     for ( i = 0; i < argc  &&  (arg = VA_ARG(ap, char *)) ; i++ ) {
  1300. SHAR_EOF
  1301. echo 'File PATCH05 is complete' &&
  1302. chmod 0664 PATCH05 ||
  1303. echo 'restore of PATCH05 failed'
  1304. Wc_c="`wc -c < 'PATCH05'`"
  1305. test 268263 -eq "$Wc_c" ||
  1306.     echo 'PATCH05: original size 268263, current size' "$Wc_c"
  1307. rm -f _shar_wnt_.tmp
  1308. fi
  1309. rm -f _shar_seq_.tmp
  1310. echo You have unpacked the last part
  1311. exit 0
  1312. exit 0 # Just in case...
  1313. -- 
  1314. Kent Landfield                   INTERNET: kent@sparky.IMD.Sterling.COM
  1315. Sterling Software, IMD           UUCP:     uunet!sparky!kent
  1316. Phone:    (402) 291-8300         FAX:      (402) 291-4362
  1317. Please send comp.sources.misc-related mail to kent@uunet.uu.net.
  1318.