home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume18 / parseargs / patch04c < prev    next >
Internet Message Format  |  1991-04-25  |  52KB

  1. From: brad@hcx1.ssd.csd.harris.com (Brad Appleton)
  2. Newsgroups: comp.sources.misc
  3. Subject: v18i103:  parseargs - functions to parse command line arguments, Patch04c/4
  4. Message-ID: <1991Apr26.040409.18835@sparky.IMD.Sterling.COM>
  5. Date: 26 Apr 91 04:04:09 GMT
  6. Approved: kent@sparky.imd.sterling.com
  7. X-Checksum-Snefru: 75770d7e 5d47a300 1d126843 7518ec44
  8.  
  9. Submitted-by: Brad Appleton <brad@hcx1.ssd.csd.harris.com>
  10. Posting-number: Volume 18, Issue 103
  11. Archive-name: parseargs/patch04c
  12. Patch-To: parseargs: Volume 17, Issue 45-57
  13.  
  14. #!/bin/sh
  15. # This is part 3 of a multipart archive
  16. # do not concatenate these parts, unpack them in order with /bin/sh
  17. # file PATCH continued
  18. #
  19. if test ! -r _shar_seq_.tmp; then
  20.     echo 'Please unpack part 1 first!'
  21.     exit 1
  22. fi
  23. (read Scheck
  24.  if test "$Scheck" != 3; then
  25.     echo Please unpack part "$Scheck" next!
  26.     exit 1
  27.  else
  28.     exit 0
  29.  fi
  30. ) < _shar_seq_.tmp || exit 1
  31. echo 'x - continuing file PATCH'
  32. sed 's/^X//' << 'SHAR_EOF' >> 'PATCH' &&
  33. X  positional parameters (even if one begins with '-' or '+')",
  34. ***************
  35. *** 392,417 ****
  36. X  
  37. X  
  38. X  /***************************************************************************
  39. ! ** ^FUNCTION: cleanup - deallocate all global storage
  40. X  **
  41. X  ** ^SYNOPSIS:
  42. X  */
  43. X  #ifndef __ANSI_C__
  44. !    static  VOID cleanup()
  45. ! #endif  /* !__ANSI_C__ */
  46. X  /*
  47. X  ** ^PARAMETERS:
  48. ! **    None.
  49. X  **
  50. - ** ^DESCRIPTION:
  51. - **    Cleanup is used to deallocate any global storage. It is called
  52. - **    before exiting.
  53. - **
  54. X  ** ^REQUIREMENTS:
  55. X  **    None.
  56. X  **
  57. X  ** ^SIDE-EFECTS:
  58. ! **    Storage associated with all dynamically allocated global-variables
  59. X  **    is released and set to NULL.
  60. X  **
  61. X  ** ^RETURN-VALUE:
  62. --- 430,456 ----
  63. X  
  64. X  
  65. X  /***************************************************************************
  66. ! ** ^FUNCTION: free_vectors - deallocate all vectors in an ARGDESC
  67. X  **
  68. X  ** ^SYNOPSIS:
  69. X  */
  70. X  #ifndef __ANSI_C__
  71. !    static  VOID free_vectors( argd )
  72. X  /*
  73. X  ** ^PARAMETERS:
  74. ! */
  75. !    ARGDESC argd[];
  76. ! #endif  /* !__ANSI_C__ */
  77. ! /* ^DESCRIPTION:
  78. ! **    Free_vectors will deallocate the storage used for each arg-vector
  79. ! **    referenced by argd.
  80. X  **
  81. X  ** ^REQUIREMENTS:
  82. X  **    None.
  83. X  **
  84. X  ** ^SIDE-EFECTS:
  85. ! **    Storage associated with all dynamically allocated arg-vectors
  86. X  **    is released and set to NULL.
  87. X  **
  88. X  ** ^RETURN-VALUE:
  89. ***************
  90. *** 421,434 ****
  91. X  **    Trivial.
  92. X  ***^^**********************************************************************/
  93. X  #ifdef __ANSI_C__
  94. !    static void cleanup( void )
  95. X  #endif
  96. X  {
  97. X     register ARGDESC *ad;
  98. X     register storage_t val;
  99. !    
  100. !    /* free up any vectors from the command-line */
  101. !    for ( ad = ARG_FIRST(UsrArgd) ; !ARG_isEND(ad) ; ARG_ADVANCE(ad) ) {
  102. X        if ( ! BTEST(arg_flags(ad), ARGVEC) )  continue;
  103. X  
  104. X        val = *((storage_t *) arg_valp(ad));
  105. --- 460,474 ----
  106. X  **    Trivial.
  107. X  ***^^**********************************************************************/
  108. X  #ifdef __ANSI_C__
  109. !    static void free_vectors( ARGDESC argd[] )
  110. X  #endif
  111. X  {
  112. X     register ARGDESC *ad;
  113. X     register storage_t val;
  114. !    if ( !argd  ||  !CMD_isINIT(argd) )  return;
  115. !    for ( ad = ARG_FIRST(argd) ; !ARG_isEND(ad) ; ARG_ADVANCE(ad) ) {
  116. X        if ( ! BTEST(arg_flags(ad), ARGVEC) )  continue;
  117. X  
  118. X        val = *((storage_t *) arg_valp(ad));
  119. ***************
  120. *** 442,450 ****
  121. --- 482,527 ----
  122. X        else if ( arg_type(ad) == argDouble )  vecFree( val.Double_vec, double );
  123. X     }
  124. X  
  125. + }
  126. + /***************************************************************************
  127. + ** ^FUNCTION: cleanup - deallocate all global storage
  128. + **
  129. + ** ^SYNOPSIS:
  130. + */
  131. + #ifndef __ANSI_C__
  132. +    static  VOID cleanup()
  133. + #endif  /* !__ANSI_C__ */
  134. + /*
  135. + ** ^PARAMETERS:
  136. + **    None.
  137. + **
  138. + ** ^DESCRIPTION:
  139. + **    Cleanup is used to deallocate any global storage. It is called
  140. + **    before exiting.
  141. + **
  142. + ** ^REQUIREMENTS:
  143. + **    None.
  144. + **
  145. + ** ^SIDE-EFECTS:
  146. + **    Storage associated with all dynamically allocated global-variables
  147. + **    is released and set to NULL.
  148. + **
  149. + ** ^RETURN-VALUE:
  150. + **    None.
  151. + **
  152. + ** ^ALGORITHM:
  153. + **    Trivial.
  154. + ***^^**********************************************************************/
  155. + #ifdef __ANSI_C__
  156. +    static void cleanup( void )
  157. + #endif
  158. + {
  159. X     /* free up tables */
  160. X     vecFree( UsrArgv, char * );
  161. X     if ( UsrArgd ) {
  162. +       free_vectors( UsrArgd );
  163. X        free( UsrArgd );
  164. X        UsrArgd = ARGDESCNULL;
  165. X     }
  166. ***************
  167. *** 851,857 ****
  168. X  #endif
  169. X  {
  170. X     int  isatty  ARGS((int));
  171. !    int  fread   ARGS((char *, int, int, FILE *));
  172. X     FILE *fp;
  173. X     char *buf;
  174. X     register int  nchars = 0;   /* # bytes read */
  175. --- 928,934 ----
  176. X  #endif
  177. X  {
  178. X     int  isatty  ARGS((int));
  179. !    int  fread   ARGS((ARBPTR, size_t, size_t, FILE *));
  180. X     FILE *fp;
  181. X     char *buf;
  182. X     register int  nchars = 0;   /* # bytes read */
  183. ***************
  184. *** 1245,1254 ****
  185. X           fprintf( fp, "\\\n" );
  186. X           return;
  187. X        }
  188. -       else if ( UsrSh == PERL ) {
  189. -          fprintf( fp, "\\n" );
  190. -          return;
  191. -       }
  192. X     }/*if newline*/
  193. X  
  194. X     if ( strchr( Shell[ UsrSh ].metachars, ch ) ) {
  195. --- 1322,1327 ----
  196. ***************
  197. *** 1372,1385 ****
  198. X        }
  199. X  
  200. X        if ( arg_type(ad) == argStr ) {
  201. -          if ( UsrSh == PERL )  fputc( '\'', fp );
  202. X           put_str_arg( fp, val->value.Str_vec.array[idx] );
  203. -          if ( UsrSh == PERL )  fputc( '\'', fp );
  204. X        }
  205. X        else if ( arg_type(ad) == argChar ) {
  206. -          if ( UsrSh == PERL )  fputc( '\'', fp );
  207. X           put_char_arg( fp, val->value.Char_vec.array[idx] );
  208. -          if ( UsrSh == PERL )  fputc( '\'', fp );
  209. X        }
  210. X        else if ( arg_type(ad) == argDouble ) {
  211. X           fprintf( fp, "%lf", val->value.Double_vec.array[idx] );
  212. --- 1445,1454 ----
  213. ***************
  214. *** 1547,1553 ****
  215. X  **
  216. X  ** ^Plan_9_Shell_Argument_Lists:
  217. X  **    For the Plan 9 shell, if the associated variable name is not "*" then
  218. ! **    it is considered to be word-list and set using the following syntax:
  219. X  **
  220. X  **         name=( 'arg1'  'arg2'  ... )
  221. X  **
  222. --- 1616,1622 ----
  223. X  **
  224. X  ** ^Plan_9_Shell_Argument_Lists:
  225. X  **    For the Plan 9 shell, if the associated variable name is not "*" then
  226. ! **    it is considered to be a word-list and set using the following syntax:
  227. X  **
  228. X  **         name=( 'arg1'  'arg2'  ... )
  229. X  **
  230. ***************
  231. *** 1563,1569 ****
  232. X  **
  233. X  **    If the -A option is given, then the associated variable is considered
  234. X  **    the root name of an array. The ouput for the array will consist of two
  235. ! **    lines for each item in the list (as in the following expample):
  236. X  **
  237. X  **         name1
  238. X  **         arg1
  239. --- 1632,1638 ----
  240. X  **
  241. X  **    If the -A option is given, then the associated variable is considered
  242. X  **    the root name of an array. The ouput for the array will consist of two
  243. ! **    lines for each item in the list (as in the following example):
  244. X  **
  245. X  **         name1
  246. X  **         arg1
  247. ***************
  248. *** 1578,1584 ****
  249. X  **    For perl, each argument list is considered an array and is set using
  250. X  **    the following syntax:
  251. X  **
  252. ! **         @name=( arg1 , arg2 ,  ... );
  253. X  **
  254. X  ** ^A_Final_Note_on_Argument_Lists:
  255. X  **    The word-lists used by the C shell, the arrays used by the Korn shell,
  256. --- 1647,1653 ----
  257. X  **    For perl, each argument list is considered an array and is set using
  258. X  **    the following syntax:
  259. X  **
  260. ! **         @name=( 'arg1' , 'arg2' ,  ... );
  261. X  **
  262. X  ** ^A_Final_Note_on_Argument_Lists:
  263. X  **    The word-lists used by the C shell, the arrays used by the Korn shell,
  264. ***************
  265. *** 1678,1688 ****
  266. X        }
  267. X     }/* end-for */
  268. X  
  269. -    if ( val->value.Vector.array ) {
  270. -       free( val->value.Vector.array );
  271. -       val->value.Vector.array = NULL;
  272. -    }
  273. X     if ( UsrSh == CSH  ||  UsrSh == TCSH  || UsrSh == RC  ||  UsrSh == PERL ) {
  274. X       fputc( ')', stdout );
  275. X     }
  276. --- 1747,1752 ----
  277. ***************
  278. *** 2057,2064 ****
  279. X        manpage( UsrArgd );
  280. X     }
  281. X     else {   /* parse callers command-line & print variable settings */
  282. !       if ( Prompt )  BSET(flags, pa_PROMPT);
  283. !       if ( Ignore )  BSET(flags, pa_IGNORE);
  284. X        if ( flags )  (VOID) parsecntl( UsrArgd, pc_PARSEFLAGS, pc_WRITE, flags );
  285. X  
  286. X        if ( (rc = parseargs( UsrArgv.array, UsrArgd )) != 0 ) {
  287. --- 2121,2130 ----
  288. X        manpage( UsrArgd );
  289. X     }
  290. X     else {   /* parse callers command-line & print variable settings */
  291. !       if ( Prompt )    BSET(flags, pa_PROMPT);
  292. !       if ( Ignore )    BSET(flags, pa_IGNORE);
  293. !       if ( AnyCase )   BSET(flags, pa_ANYCASE);
  294. !       if ( Flags1st )  BSET(flags, pa_FLAGS1ST);
  295. X        if ( flags )  (VOID) parsecntl( UsrArgd, pc_PARSEFLAGS, pc_WRITE, flags );
  296. X  
  297. X        if ( (rc = parseargs( UsrArgv.array, UsrArgd )) != 0 ) {
  298. *** /hx1d3/lp/brad/parseargs_patch03/parseargs/parseargs.h    Wed Apr 10 09:54:08 1991
  299. --- parseargs.h    Thu Apr 11 11:07:17 1991
  300. ***************
  301. *** 280,286 ****
  302. X  #define  arg_sdesc(ad)        ( arg_sname(ad) + strlen(arg_sname(ad)) + 1 )
  303. X  /*    -- return the description of an argument. If a description was supplied,
  304. X  **       the ARGDESCRIBED flag will be set and the description will immediately
  305. ! **       follow the NUL byte of the string name.
  306. X  */
  307. X  #define  ARG_isDESCRIBED(ad)  BTEST( arg_flags(ad), ARGDESCRIBED )
  308. X  /*    -- Evaluates to TRUE only if an argument description was provided.
  309. --- 280,286 ----
  310. X  #define  arg_sdesc(ad)        ( arg_sname(ad) + strlen(arg_sname(ad)) + 1 )
  311. X  /*    -- return the description of an argument. If a description was supplied,
  312. X  **       the ARGDESCRIBED flag will be set and the description will immediately
  313. ! **       follow the NULL byte of the string name.
  314. X  */
  315. X  #define  ARG_isDESCRIBED(ad)  BTEST( arg_flags(ad), ARGDESCRIBED )
  316. X  /*    -- Evaluates to TRUE only if an argument description was provided.
  317. ***************
  318. *** 562,570 ****
  319. X  */
  320. X  #define pa_IGNORE    0x0002
  321. X  /*    -- Ignore any unrecognized or improperly specified command-line arguments
  322. ! **       and continue execution of the program. Normally, if an argument is
  323. ! **       unmatched (or is improperly specified), a usage message is printed
  324. ! **       program execution is terminated.
  325. X  */
  326. X  #define pa_OPTSONLY  0x0004
  327. X  /*    -- Under UNIX, setting this flag will disable the parsing of long-option
  328. --- 562,570 ----
  329. X  */
  330. X  #define pa_IGNORE    0x0002
  331. X  /*    -- Ignore any unrecognized or improperly specified command-line arguments
  332. ! **       and continue execution of the program. Normally, if a required
  333. ! **       argument is unmatched (or an argument is improperly specified),
  334. ! **       a usage message is printed program execution is terminated.
  335. X  */
  336. X  #define pa_OPTSONLY  0x0004
  337. X  /*    -- Under UNIX, setting this flag will disable the parsing of long-option
  338. ***************
  339. *** 591,597 ****
  340. X  #define pa_ANYCASE   0x0020
  341. X  /*    -- Setting this flag cause character-case to be ignored when attempting
  342. X  **       to match single-character argument names (i.e. causes "-i" and "-I"
  343. ! **       will be considered equivalent).
  344. X  */
  345. X  #define pa_ARGV0     0x0040
  346. X  /*    -- Normally, the parseargs library will assume that the first argument
  347. --- 591,597 ----
  348. X  #define pa_ANYCASE   0x0020
  349. X  /*    -- Setting this flag cause character-case to be ignored when attempting
  350. X  **       to match single-character argument names (i.e. causes "-i" and "-I"
  351. ! **       to be considered equivalent).
  352. X  */
  353. X  #define pa_ARGV0     0x0040
  354. X  /*    -- Normally, the parseargs library will assume that the first argument
  355. ***************
  356. *** 608,614 ****
  357. X  **
  358. X  **       Keeping this flag on until the final set of arguments is parsed will
  359. X  **       cause parseargs to not check for missing arguments until the last set
  360. ! **       of arguments has been parsed (by the final call to *parseargs).
  361. X  */
  362. X  #define pa_CONTINUE  0x0100
  363. X  /*    -- Setting this flag will cause subsequent calls to the parseargs library
  364. --- 608,615 ----
  365. X  **
  366. X  **       Keeping this flag on until the final set of arguments is parsed will
  367. X  **       cause parseargs to not check for missing arguments until the last set
  368. ! **       of arguments has been parsed (by the final call to one of the
  369. ! **       functions in the parseargs library).
  370. X  */
  371. X  #define pa_CONTINUE  0x0100
  372. X  /*    -- Setting this flag will cause subsequent calls to the parseargs library
  373. ***************
  374. *** 763,769 ****
  375. X  ** ^SECTION: PARSE-MODES - modes to get/set command attributes.
  376. X  **    Parsecntl may be used to read current command attributes, write/assign
  377. X  **    new command attributes, or both. The mode argument to parsecntl
  378. ! **    determines the which of these three alternatives are desired. If the
  379. X  **    programmer merely wishes to assign new attributes, then invoking
  380. X  **    parsecntl in pc_WRITE mode and passing the new attributes will do the
  381. X  **    job. If the programmer wishes simply to query attributes, then
  382. --- 764,770 ----
  383. X  ** ^SECTION: PARSE-MODES - modes to get/set command attributes.
  384. X  **    Parsecntl may be used to read current command attributes, write/assign
  385. X  **    new command attributes, or both. The mode argument to parsecntl
  386. ! **    determines which of these three alternatives are desired. If the
  387. X  **    programmer merely wishes to assign new attributes, then invoking
  388. X  **    parsecntl in pc_WRITE mode and passing the new attributes will do the
  389. X  **    job. If the programmer wishes simply to query attributes, then
  390. ***************
  391. *** 776,783 ****
  392. X  **    to the object containing the new attribute settings; When parsecntl
  393. X  **    returns, then (assuming it returns 0) the desired attributes will have
  394. X  **    been assigned and the object that contained the new attribute settings
  395. ! **    will now contain the attribute settings that were in effect before
  396. ! **    parsecntl was invoked.
  397. X  */
  398. X  typedef enum  {
  399. X     pc_READ,
  400. --- 777,784 ----
  401. X  **    to the object containing the new attribute settings; When parsecntl
  402. X  **    returns, then (assuming it returns 0) the desired attributes will have
  403. X  **    been assigned and the object that contained the new attribute settings
  404. ! **    will now contain the attribute settings that were in effect immediately
  405. ! **    before parsecntl was invoked.
  406. X  */
  407. X  typedef enum  {
  408. X     pc_READ,
  409. *** /hx1d3/lp/brad/parseargs_patch03/parseargs/parseargs.pl    Wed Apr 10 09:47:38 1991
  410. --- parseargs.pl    Thu Apr 11 11:07:20 1991
  411. ***************
  412. *** 30,36 ****
  413. X  ;#    Any desired initial values for variables from the argument-description
  414. X  ;#    string should be assigned BEFORE calling this function.
  415. X  ;#
  416. ! ;#    The following global variables may be assigned before calling parseargs:
  417. X  ;#
  418. X  ;#       PARSEOPTS -- any extra options to pass to parseargs() (default="-u")
  419. X  ;#
  420. --- 30,37 ----
  421. X  ;#    Any desired initial values for variables from the argument-description
  422. X  ;#    string should be assigned BEFORE calling this function.
  423. X  ;#
  424. ! ;#    The following global variables from package "main" may be assigned
  425. ! ;#    before calling parseargs:
  426. X  ;#
  427. X  ;#       PARSEOPTS -- any extra options to pass to parseargs() (default="-u")
  428. X  ;#
  429. ***************
  430. *** 44,49 ****
  431. --- 45,52 ----
  432. X  ;#    The exit code returned by parseargs(1).
  433. X  ;#
  434. X  ;# ^ALGORITHM:
  435. + ;#    - read $PARSECNTL environment variable and use corresponding syntax
  436. + ;#      (long-options or short options) when invoking parseargs(1)
  437. X  ;#    - set defaults for PARSEOPTS
  438. X  ;#    - build the parseargs command (dont forget to quote arguments).
  439. X  ;#    - run parseargs(1) and evaluate the output unless $?
  440. ***************
  441. *** 50,78 ****
  442. X  ;##^^####
  443. X  
  444. X  sub parseargs {
  445. !     local(@argv) = @_;
  446. !     local($argd);
  447. !     local($parse_output);
  448. !     local($_);
  449. !     local($[) = 0;
  450. !     local($i);
  451. X  
  452. !     $argd = pop( @argv );   ## get last arg and remove it
  453. X  
  454. !     if ( $PARSEOPTS == "" ) {
  455. !         $PARSEOPTS = '-u';
  456. !     }
  457. !     $PARSEARGS = 'parseargs -s perl ' . $PARSEOPTS . " -- '" . $0 . "'";
  458. !     for ( $i = $[ ; $i <= $#argv ; $i++ ) {
  459. !       $argv[$i] =~ s/'/'\\''/g;
  460. !       $PARSEARGS .= " '" . $argv[$i] . "'";
  461. !     }
  462. !     $parse_output = `echo \'$argd\' | $PARSEARGS`;
  463. !     eval $parse_output unless $?;
  464. !     if ( $? ) {
  465. X        $! = 0;
  466. X        die "\n";
  467. !     }
  468. X  }
  469. X  
  470. X  1;
  471. --- 53,81 ----
  472. X  ;##^^####
  473. X  
  474. X  sub parseargs {
  475. !    local($argd, @argv) = ( pop(@_), $0, @_ );
  476. !    local($unset, $end, $sh, $env) = ( '-u', '--', '-s', '-e' );
  477. !    local($parse_output, $_);
  478. X  
  479. !    $_ = $main'ENV{'PARSECNTL'};
  480. !    if ( /[^!~\^]\s*[KkLl]/ ) {  ## KeyWords only!
  481. !       ($unset, $end, $sh, $env) = ( '+unset', '++', '+shell', '+env' );
  482. !    }
  483. X  
  484. !    if ( ! $main'PARSEOPTS )  { $main'PARSEOPTS = "$unset"; }
  485. !    grep( s/'/'\\''/g, @argv );  ## escape embedded quotes
  486. !    $PARSEARGS = "parseargs $main'PARSEOPTS $sh perl $env ARGD $end ";
  487. !    $PARSEARGS .= "'" . join( "' '", @argv ) . "'";
  488. !    $main'ENV{'ARGD'} = $argd;         ## put argd-array into environment
  489. !    $parse_output = `$PARSEARGS`;      ## invoke parseargs(1)
  490. !    eval $parse_output unless $?;      ## evaluate the output-script
  491. !    if ( $? ) {
  492. X        $! = 0;
  493. X        die "\n";
  494. !    }
  495. !    return $?;
  496. X  }
  497. X  
  498. X  1;
  499. *** /hx1d3/lp/brad/parseargs_patch03/parseargs/pgopen.c    Wed Apr 10 09:47:51 1991
  500. --- pgopen.c    Thu Apr 11 11:07:27 1991
  501. ***************
  502. *** 26,31 ****
  503. --- 26,32 ----
  504. X  
  505. X  
  506. X  #include <stdio.h>
  507. + #include <errno.h>
  508. X  #include <signal.h>
  509. X  #include <setjmp.h>
  510. X  #include <useful.h>
  511. ***************
  512. *** 71,79 ****
  513. X  extern  int   access();
  514. X  extern  int   isatty();
  515. X  extern  int   wait();
  516. ! extern  int   sleep();
  517. ! extern  int  errno;
  518. X  
  519. X  static void  pg_error();       /* broken-pipe exception handler */
  520. X  static jmp_buf pg_recover;     /* jump-buffer for exception handler */
  521. --- 72,78 ----
  522. X  extern  int   access();
  523. X  extern  int   isatty();
  524. X  extern  int   wait();
  525. ! extern  unsigned   sleep();
  526. X  
  527. X  static void  pg_error();       /* broken-pipe exception handler */
  528. X  static jmp_buf pg_recover;     /* jump-buffer for exception handler */
  529. *** /hx1d3/lp/brad/parseargs_patch03/parseargs/strfuncs.c    Wed Apr 10 09:47:55 1991
  530. --- strfuncs.c    Thu Apr 11 11:07:42 1991
  531. ***************
  532. *** 263,274 ****
  533. X  
  534. X        if (c1 != c2)  return  (int)(c1 -c2);
  535. X     }
  536. !    return   (*s1 == *s2) ? 0 : (int)(*s1 - *s2);
  537. X  }
  538. X  
  539. X  
  540. - #ifdef BSD
  541. X  /***************************************************************************
  542. X  ** ^FUNCTION: strdup - copy a string
  543. X  **
  544. --- 263,272 ----
  545. X  
  546. X        if (c1 != c2)  return  (int)(c1 -c2);
  547. X     }
  548. !    return   (!len  ||  (*s1 == *s2)) ? 0 : (int)(*s1 - *s2);
  549. X  }
  550. X  
  551. X  
  552. X  /***************************************************************************
  553. X  ** ^FUNCTION: strdup - copy a string
  554. X  **
  555. ***************
  556. *** 314,319 ****
  557. --- 312,319 ----
  558. X    return p;
  559. X  }
  560. X  
  561. + #ifdef BSD
  562. X  
  563. X  /***************************************************************************
  564. X  ** ^FUNCTION: strpbrk - return the first occurrence of characters in a string
  565. *** /hx1d3/lp/brad/parseargs_patch03/parseargs/strfuncs.h    Wed Apr 10 09:47:57 1991
  566. --- strfuncs.h    Thu Apr 11 11:07:45 1991
  567. ***************
  568. *** 19,27 ****
  569. X  EXTERN  char  *strlwr       ARGS(( char * ));
  570. X  EXTERN  int    stricmp      ARGS(( const char *, const char * ));
  571. X  EXTERN  int    strnicmp     ARGS(( const char *, const char *, size_t ));
  572. X  
  573. X  #ifdef BSD
  574. -    EXTERN  char  *strdup    ARGS(( const char * ));
  575. X     EXTERN  char  *strpbrk   ARGS(( const char *, const char * ));
  576. X     EXTERN  int    strspn    ARGS(( const char *, const char * ));
  577. X     EXTERN  int    strcspn   ARGS(( const char *, const char * ));
  578. --- 19,27 ----
  579. X  EXTERN  char  *strlwr       ARGS(( char * ));
  580. X  EXTERN  int    stricmp      ARGS(( const char *, const char * ));
  581. X  EXTERN  int    strnicmp     ARGS(( const char *, const char *, size_t ));
  582. + EXTERN  char  *strdup       ARGS(( const char * ));
  583. X  
  584. X  #ifdef BSD
  585. X     EXTERN  char  *strpbrk   ARGS(( const char *, const char * ));
  586. X     EXTERN  int    strspn    ARGS(( const char *, const char * ));
  587. X     EXTERN  int    strcspn   ARGS(( const char *, const char * ));
  588. *** /hx1d3/lp/brad/parseargs_patch03/parseargs/syserr.c    Wed Apr 10 09:47:59 1991
  589. --- syserr.c    Thu Apr 11 11:07:48 1991
  590. ***************
  591. *** 21,26 ****
  592. --- 21,27 ----
  593. X  ***^^**********************************************************************/
  594. X  
  595. X  #include <stdio.h>
  596. + #include <errno.h>
  597. X  #include <useful.h>
  598. X  /* #include <funclist.h> */
  599. X  
  600. ***************
  601. *** 27,33 ****
  602. X  VERSIONID("$Header: syserr.c,v 2.0 89/12/24 00:56:31 eric Exp $");
  603. X  
  604. X  extern  char *ProgName;
  605. - extern  int   errno;
  606. X  EXTERN  int   vfprintf  ARGS((FILE *, const char *, va_list));
  607. X  
  608. X  
  609. --- 28,33 ----
  610. *** /hx1d3/lp/brad/parseargs_patch03/parseargs/unix_args.c    Wed Apr 10 09:48:06 1991
  611. --- unix_args.c    Thu Apr 11 11:08:11 1991
  612. ***************
  613. *** 167,174 ****
  614. X           }
  615. X  
  616. X           flags = arg_flags(ad);
  617. !          if ( ARG_isGIVEN(ad) )
  618. !             BCLEAR( arg_flags(ad), ARGVALSEP | ARGVALGIVEN | ARGKEYWORD );
  619. X  
  620. X           BSET( arg_flags(ad), ARGKEYWORD );
  621. X  
  622. --- 167,176 ----
  623. X           }
  624. X  
  625. X           flags = arg_flags(ad);
  626. !          if ( ARG_isGIVEN(ad) ) {
  627. !             BCLEAR( arg_flags(ad), ARGVALSEP | ARGKEYWORD );
  628. !             if ( !ARG_isMULTIVAL(ad) )  BCLEAR( arg_flags(ad), ARGVALGIVEN );
  629. !          }
  630. X  
  631. X           BSET( arg_flags(ad), ARGKEYWORD );
  632. X  
  633. ***************
  634. *** 275,282 ****
  635. X              }/* if unknown-option */
  636. X  
  637. X              flags = arg_flags(ad);
  638. !             if ( ARG_isGIVEN(ad) )
  639. !                BCLEAR( arg_flags(ad), ARGVALSEP | ARGVALGIVEN | ARGKEYWORD );
  640. X  
  641. X              if( ARG_isMULTIVAL(ad) ) {
  642. X                 cmd_list(cmd) = ad;
  643. --- 277,286 ----
  644. X              }/* if unknown-option */
  645. X  
  646. X              flags = arg_flags(ad);
  647. !             if ( ARG_isGIVEN(ad) ) {
  648. !                BCLEAR( arg_flags(ad), ARGVALSEP | ARGKEYWORD );
  649. !                if ( !ARG_isMULTIVAL(ad) )  BCLEAR( arg_flags(ad), ARGVALGIVEN );
  650. !             }
  651. X  
  652. X              if( ARG_isMULTIVAL(ad) ) {
  653. X                 cmd_list(cmd) = ad;
  654. ***************
  655. *** 354,364 ****
  656. X        }/*elif option*/
  657. X        else {
  658. X              /* parsing a list of arguments */
  659. !          if( cmd_list(cmd) ) {
  660. X              ad = cmd_list(cmd);
  661. X              flags = arg_flags(ad);
  662. !             if ( ARG_isGIVEN(ad) )
  663. !                BCLEAR( arg_flags(ad), ARGVALGIVEN | ARGVALSEP | ARGKEYWORD );
  664. X  
  665. X              BSET( arg_flags(ad), ARGVALSEP );
  666. X  
  667. --- 358,369 ----
  668. X        }/*elif option*/
  669. X        else {
  670. X              /* parsing a list of arguments */
  671. !          if ( cmd_list(cmd) ) {
  672. X              ad = cmd_list(cmd);
  673. X              flags = arg_flags(ad);
  674. !             if ( ARG_isGIVEN(ad) ) {
  675. !                BCLEAR( arg_flags(ad), ARGVALSEP | ARGKEYWORD );
  676. !             }
  677. X  
  678. X              BSET( arg_flags(ad), ARGVALSEP );
  679. X  
  680. ***************
  681. *** 391,398 ****
  682. X           }
  683. X  
  684. X           flags = arg_flags(ad);
  685. !          if ( ARG_isGIVEN(ad) )
  686. !             BCLEAR( arg_flags(ad), ARGVALGIVEN | ARGKEYWORD | ARGVALSEP );
  687. X  
  688. X           if ( ARG_isMULTIVAL(ad) ) {
  689. X              cmd_list(cmd) = ad;
  690. --- 396,405 ----
  691. X           }
  692. X  
  693. X           flags = arg_flags(ad);
  694. !          if ( ARG_isGIVEN(ad) ) {
  695. !             BCLEAR( arg_flags(ad), ARGVALSEP | ARGKEYWORD );
  696. !             if ( !ARG_isMULTIVAL(ad) )  BCLEAR( arg_flags(ad), ARGVALGIVEN );
  697. !          }
  698. X  
  699. X           if ( ARG_isMULTIVAL(ad) ) {
  700. X              cmd_list(cmd) = ad;
  701. *** /hx1d3/lp/brad/parseargs_patch03/parseargs/unix_man.c    Wed Apr 10 09:48:07 1991
  702. --- unix_man.c    Thu Apr 11 11:08:16 1991
  703. ***************
  704. *** 87,93 ****
  705. X         return  strlen(name);
  706. X     }/*if parm*/
  707. X  
  708. !    sprintf(buf, "\\fB\-%c\\fP", arg_cname(ad));
  709. X     pos = buf + strlen(buf);
  710. X  
  711. X     if ( ARG_isVALTAKEN(ad)  &&  !ARG_isBOOLEAN(ad)  &&  !ARG_isPSEUDOARG(ad) ) {
  712. --- 87,93 ----
  713. X         return  strlen(name);
  714. X     }/*if parm*/
  715. X  
  716. !    sprintf(buf, "\\fB\\-%c\\fP", arg_cname(ad));
  717. X     pos = buf + strlen(buf);
  718. X  
  719. X     if ( ARG_isVALTAKEN(ad)  &&  !ARG_isBOOLEAN(ad)  &&  !ARG_isPSEUDOARG(ad) ) {
  720. *** /hx1d3/lp/brad/parseargs_patch03/parseargs/useful.h    Wed Apr 10 09:48:09 1991
  721. --- useful.h    Thu Apr 11 11:08:19 1991
  722. ***************
  723. *** 8,13 ****
  724. --- 8,14 ----
  725. X  **
  726. X  ** ^HISTORY:
  727. X  **    --/--/--    Brad Appleton    <brad@ssd.csd.harris.com>    
  728. + **    - Added OS specific #defines for unix, SYSV, BSD, etc ...
  729. X  **    - Added structured block comments
  730. X  **    - Added varargs/stdarg macros
  731. X  **    - Added BSET, BCLEAR, BTEST macros for handling bitmasks
  732. ***************
  733. *** 24,66 ****
  734. X  #ifndef _USEFUL_H_
  735. X  #define _USEFUL_H_
  736. X  
  737. ! #ifndef unix
  738. ! # if (defined(_unix) || defined(_unix_) || defined(__unix) || defined(__unix__) || defined(UNIX) || defined(_UNIX) || defined(_UNIX_) || defined(__UNIX) || defined(__UNIX__) || defined(Unix) || defined(_Unix) || defined(_Unix_) || defined(__Unix) || defined(__Unix__) || defined(sun))
  739. X  #   define unix
  740. ! # endif /* _UNIX */
  741. ! #endif /* unix */
  742. X  
  743. ! #ifndef BSD
  744. ! # if (defined(ucb_universe) || defined(UCB) || defined(_BSD) || defined(_BSD_) || defined(__BSD) || defined(__BSD__) || defined(BSD_UNIX) || defined(_BSD_UNIX) || defined(_BSD_UNIX_) || defined(__BSD_UNIX) || defined(__BSD_UNIX__) || defined(sun))
  745. X  #   define BSD
  746. ! # endif /* _BSD */
  747. ! #endif /* BSD */
  748. X  
  749. X  #ifndef AmigaDOS
  750. ! # if (defined(MANX) || defined(AZTEC))
  751. X  #   define AmigaDOS
  752. X  # endif
  753. X  #endif /* AmigaDOS */
  754. X  
  755. - #ifndef vms
  756. - # if (defined(_vms) || defined(_vms_) || defined(__vms) || defined(__vms__) || defined(VMS) || defined(_VMS) || defined(_VMS_) || defined(__VMS) || defined(__VMS__))
  757. - #   define vms
  758. - # endif /* _VMS */
  759. - #endif /* vms */
  760. X  
  761. ! #ifndef MSDOS
  762. ! # if (defined(_MSDOS) || defined(_MSDOS_) || defined(__MSDOS) || defined(__MSDOS__) || defined(MS_DOS) || defined(_MS_DOS) || defined(_MS_DOS_) || defined(__MS_DOS) || defined(__MS_DOS__))
  763. ! #   define MSDOS
  764. ! # endif /* _MSDOS */
  765. ! #endif /* MSDOS */
  766. X  
  767. - #ifndef OS2
  768. - # if (defined(_OS2) || defined(_OS2_) || defined(__OS2) || defined(__OS2__))
  769. - #   define OS2
  770. - # endif /* _OS2 */
  771. - #endif /* OS2 */
  772. X  #ifndef FILE
  773. X  # include <stdio.h>
  774. X  #endif
  775. --- 25,112 ----
  776. X  #ifndef _USEFUL_H_
  777. X  #define _USEFUL_H_
  778. X  
  779. ! #if ( defined(_unix) || defined(UNIX) || defined(__UNIX) )
  780. ! # ifndef unix
  781. X  #   define unix
  782. ! # endif
  783. ! #endif /* _unix */
  784. X  
  785. !    /* give a stab at the dual Unix universe dilemma (UCB vs AT&T) */
  786. ! #ifdef unix
  787. ! # if ( defined(_BSD) && !defined(BSD) )
  788. ! #  define BSD
  789. ! # endif
  790. ! # if ( defined(_SYSV) && !defined(SYSV) )
  791. ! #  define SYSV
  792. ! # endif
  793. ! # ifndef BSD
  794. ! #  ifdef sun
  795. X  #   define BSD
  796. ! #  endif
  797. ! #  ifdef apollo
  798. ! #   define BSD
  799. ! #  endif
  800. ! #  if ( defined(_CX_UX) && defined(ucb_universe) )
  801. ! #   define BSD
  802. ! #  endif
  803. ! #  if ( defined(VAX_BSD) || defined(ULTRIX) || defined(ultrix) )
  804. ! #   define BSD
  805. ! #  endif
  806. ! #  if ( defined(DYNIX) || defined(dynix) )
  807. ! #   define BSD
  808. ! #  endif
  809. ! #  if ( defined(UTX) || defined(utx) )
  810. ! #   define BSD
  811. ! #  endif
  812. ! # endif /* !BSD */
  813. X  
  814. + # ifndef SYSV
  815. + #  ifdef mips
  816. + #   define SYSV
  817. + #  endif
  818. + #  ifdef DGUX
  819. + #   define SYSV
  820. + #  endif
  821. + #  if ( defined(_CX_UX) && defined(att_universe) )
  822. + #   define SYSV
  823. + #  endif
  824. + #  if ( defined(hpux) || defined(HPUX) )
  825. + #   define SYSV
  826. + #  endif
  827. + #  if ( defined(irix) || defined(IRIX) )
  828. + #   define SYSV
  829. + #  endif
  830. + #  if ( defined(aix) || defined(AIX) )
  831. + #   define SYSV
  832. + #  endif
  833. + # endif /* !SYSV */
  834. + #endif /* unix */
  835. + #ifndef MSDOS
  836. + # if ( defined(_MSDOS_) || defined(__MSDOS__) || defined(_MSDOS) )
  837. + #  define MSDOS
  838. + # endif
  839. + #endif
  840. + #ifndef OS2
  841. + # if ( defined(_OS2_) || defined(__OS2__) || defined(_OS2) )
  842. + #  define OS2
  843. + # endif
  844. + #endif
  845. X  #ifndef AmigaDOS
  846. ! # if ( defined(MANX) || defined(AZTEC) )
  847. X  #   define AmigaDOS
  848. X  # endif
  849. X  #endif /* AmigaDOS */
  850. X  
  851. X  
  852. ! #ifdef __STDC__
  853. ! # include <stddef.h>
  854. ! # include <stdlib.h>
  855. ! #endif
  856. X  
  857. X  #ifndef FILE
  858. X  # include <stdio.h>
  859. X  #endif
  860. ***************
  861. *** 108,118 ****
  862. X  #  define  VA_END(ap)         va_end(ap)
  863. X  #endif
  864. X  
  865. - #if ( !defined(__ANSI_C__)  &&  !defined(_SIZE_T_DEFINED) )
  866. -   typedef unsigned int size_t;
  867. - # define _SIZE_T_DEFINED 1
  868. - #endif
  869. X  #ifndef VOID
  870. X  #  if ( defined(__ANSI_C__)  ||  !defined(NOVOID) )
  871. X  #    define VOID        void
  872. --- 154,159 ----
  873. ***************
  874. *** 190,197 ****
  875. X  #define BSET(bstr,mask)     (bstr) |= (mask)
  876. X  #define BCLEAR(bstr,mask)   (bstr) &= ~(mask)
  877. X  
  878. ! #ifndef STRING_H
  879. ! # define STRING_H
  880. X     EXTERN  char  *strcat    ARGS(( char *, const char * ));
  881. X     EXTERN  char  *strncat   ARGS(( char *, const char *, int ));
  882. X     EXTERN  int    strcmp    ARGS(( const char *, const char * ));
  883. --- 231,238 ----
  884. X  #define BSET(bstr,mask)     (bstr) |= (mask)
  885. X  #define BCLEAR(bstr,mask)   (bstr) &= ~(mask)
  886. X  
  887. ! #ifndef __STRING_H
  888. ! # define __STRING_H
  889. X     EXTERN  char  *strcat    ARGS(( char *, const char * ));
  890. X     EXTERN  char  *strncat   ARGS(( char *, const char *, int ));
  891. X     EXTERN  int    strcmp    ARGS(( const char *, const char * ));
  892. ***************
  893. *** 218,229 ****
  894. X     EXTERN  char  *rindex    ARGS(( const char *, int ));
  895. X  # endif /* !BSD */
  896. X     
  897. ! # ifdef BSD
  898. X  #  define bcmp(b1,b2,n)   memcmp(b1,b2,n)
  899. X  #  define bcopy(b1,b2,n)  memcpy(b2,b1,n)
  900. X  #  define bzero(b,n)      memset(b,'\0',n)
  901. ! #  ifndef MEMORY_H
  902. ! #    define MEMORY_H
  903. X     EXTERN  ARBPTR  memccpy   ARGS(( ARBPTR, const ARBPTR, int, int ));
  904. X     EXTERN  ARBPTR  memchr    ARGS(( ARBPTR, int, int ));
  905. X     EXTERN  int     memcmp    ARGS(( const ARBPTR, const ARBPTR, int ));
  906. --- 259,270 ----
  907. X     EXTERN  char  *rindex    ARGS(( const char *, int ));
  908. X  # endif /* !BSD */
  909. X     
  910. ! # ifndef BSD
  911. X  #  define bcmp(b1,b2,n)   memcmp(b1,b2,n)
  912. X  #  define bcopy(b1,b2,n)  memcpy(b2,b1,n)
  913. X  #  define bzero(b,n)      memset(b,'\0',n)
  914. ! #  ifndef __MEMORY_H
  915. ! #    define __MEMORY_H
  916. X     EXTERN  ARBPTR  memccpy   ARGS(( ARBPTR, const ARBPTR, int, int ));
  917. X     EXTERN  ARBPTR  memchr    ARGS(( ARBPTR, int, int ));
  918. X     EXTERN  int     memcmp    ARGS(( const ARBPTR, const ARBPTR, int ));
  919. ***************
  920. *** 230,254 ****
  921. X     EXTERN  ARBPTR  memcpy    ARGS(( ARBPTR, const ARBPTR, int ));
  922. X     EXTERN  ARBPTR  memmove   ARGS(( ARBPTR, const ARBPTR, int ));
  923. X     EXTERN  ARBPTR  memset    ARGS(( ARBPTR, int, int ));
  924. ! #  endif  /* MEMORY_H */
  925. X     
  926. X  # else
  927. X  #  define memcmp(b1,b2,n)  bcmp(b1,b2,n)
  928. X  #  define memcpy(b1,b2,n)  bcopy(b2,b1,n)
  929. ! #  ifndef BSTRING_H
  930. ! #    define BSTRING_H
  931. X     EXTERN  VOID   bcopy     ARGS(( const ARBPTR, ARBPTR, int ));
  932. X     EXTERN  int    bcmp      ARGS(( const ARBPTR, const ARBPTR, int ));
  933. X     EXTERN  VOID   bzero     ARGS(( ARBPTR, int ));
  934. X     EXTERN  int    ffs       ARGS(( int ));
  935. ! #  endif  /* BSTRING_H */
  936. X  # endif /* !BSD */
  937. ! #endif /* STRING_H */
  938. X  
  939. ! EXTERN  ARBPTR  malloc   ARGS(( size_t ));
  940. X  EXTERN  ARBPTR  ckalloc  ARGS(( size_t ));
  941. - EXTERN  ARBPTR  realloc  ARGS(( ARBPTR, size_t ));
  942. - EXTERN  ARBPTR  free     ARGS(( ARBPTR ));
  943. X  EXTERN  VOID    exit     ARGS(( int ));
  944. X  
  945. X  #define MAXINPUTLINE    200        /* maximum string input line */
  946. --- 271,315 ----
  947. X     EXTERN  ARBPTR  memcpy    ARGS(( ARBPTR, const ARBPTR, int ));
  948. X     EXTERN  ARBPTR  memmove   ARGS(( ARBPTR, const ARBPTR, int ));
  949. X     EXTERN  ARBPTR  memset    ARGS(( ARBPTR, int, int ));
  950. ! #  endif  /* __MEMORY_H */
  951. X     
  952. X  # else
  953. X  #  define memcmp(b1,b2,n)  bcmp(b1,b2,n)
  954. X  #  define memcpy(b1,b2,n)  bcopy(b2,b1,n)
  955. ! #  ifndef __BSTRING_H
  956. ! #    define __BSTRING_H
  957. X     EXTERN  VOID   bcopy     ARGS(( const ARBPTR, ARBPTR, int ));
  958. X     EXTERN  int    bcmp      ARGS(( const ARBPTR, const ARBPTR, int ));
  959. X     EXTERN  VOID   bzero     ARGS(( ARBPTR, int ));
  960. X     EXTERN  int    ffs       ARGS(( int ));
  961. ! #  endif  /* __BSTRING_H */
  962. X  # endif /* !BSD */
  963. ! #endif /* __STRING_H */
  964. X  
  965. ! #if ( !defined(__ANSI_C__)  &&  !defined(_SIZE_T_DEFINED) )
  966. ! # if (defined(sun) && defined(BSD))
  967. ! #  if (!defined (__sys_stdtypes_h))
  968. !     /* size_t is also defined in <sys/stdtypes.h> in SunOS 4.1 */
  969. !     typedef int size_t;
  970. ! #  endif
  971. ! #  define _SIZE_T_DEFINED 1
  972. ! # endif /* sun */
  973. ! # if (defined(vms) && defined(__STDDEF_LOADED))
  974. ! #  define _SIZE_T_DEFINED 1
  975. ! # endif /* vms */
  976. ! # ifndef _SIZE_T_DEFINED
  977. !    typedef unsigned int size_t;
  978. ! #  define _SIZE_T_DEFINED 1
  979. ! # endif  /* !_SIZE_T_DEFINED */
  980. ! #endif
  981. ! #ifndef __malloc_h
  982. !  EXTERN  ARBPTR  malloc   ARGS(( size_t ));
  983. !  EXTERN  ARBPTR  realloc  ARGS(( ARBPTR, size_t ));
  984. !  EXTERN  VOID    free     ARGS(( ARBPTR ));
  985. ! #endif /*__malloc_h*/
  986. X  EXTERN  ARBPTR  ckalloc  ARGS(( size_t ));
  987. X  EXTERN  VOID    exit     ARGS(( int ));
  988. X  
  989. X  #define MAXINPUTLINE    200        /* maximum string input line */
  990. *** /hx1d3/lp/brad/parseargs_patch03/parseargs/vms_args.c    Wed Apr 10 09:48:11 1991
  991. --- vms_args.c    Thu Apr 11 11:08:24 1991
  992. ***************
  993. *** 655,662 ****
  994. X           }
  995. X              /* have we seen this one before */
  996. X           flags = arg_flags(ad);
  997. !          if ( ARG_isGIVEN(ad) )
  998. !             BCLEAR( arg_flags(ad), ARGVALGIVEN | ARGVALSEP );
  999. X  
  1000. X              /* ARGNOVALs are special, having no value */
  1001. X           if ( ! ARG_isVALTAKEN(ad) ) {
  1002. --- 655,664 ----
  1003. X           }
  1004. X              /* have we seen this one before */
  1005. X           flags = arg_flags(ad);
  1006. !          if ( ARG_isGIVEN(ad) ) {
  1007. !             BCLEAR( arg_flags(ad), ARGVALSEP );
  1008. !             if ( !ARG_isMULTIVAL(ad) )  BCLEAR( arg_flags(ad), ARGVALGIVEN );
  1009. !          }
  1010. X  
  1011. X              /* ARGNOVALs are special, having no value */
  1012. X           if ( ! ARG_isVALTAKEN(ad) ) {
  1013. ***************
  1014. *** 712,719 ****
  1015. X           if ( cmd_list(cmd) ) {
  1016. X              ad = cmd_list(cmd);
  1017. X              flags = arg_flags(ad);
  1018. !             if ( ARG_isGIVEN(ad) )
  1019. !                BCLEAR( arg_flags(ad), ARGVALGIVEN | ARGVALSEP );
  1020. X  
  1021. X              BSET( arg_flags(ad), ARGVALSEP );
  1022. X  
  1023. --- 714,722 ----
  1024. X           if ( cmd_list(cmd) ) {
  1025. X              ad = cmd_list(cmd);
  1026. X              flags = arg_flags(ad);
  1027. !             if ( ARG_isGIVEN(ad) ) {
  1028. !                BCLEAR( arg_flags(ad), ARGVALSEP );
  1029. !             }
  1030. X  
  1031. X              BSET( arg_flags(ad), ARGVALSEP );
  1032. X  
  1033. ***************
  1034. *** 753,760 ****
  1035. X              BSET( cmd_state(cmd), ps_NOFLAGS );
  1036. X           }
  1037. X           flags = arg_flags(ad);
  1038. !          if ( ARG_isGIVEN(ad) )
  1039. !             BCLEAR( arg_flags(ad), ARGVALGIVEN | ARGVALSEP );
  1040. X  
  1041. X           BSET( arg_flags(ad), ARGVALSEP );
  1042. X  
  1043. --- 756,765 ----
  1044. X              BSET( cmd_state(cmd), ps_NOFLAGS );
  1045. X           }
  1046. X           flags = arg_flags(ad);
  1047. !          if ( ARG_isGIVEN(ad) ) {
  1048. !             BCLEAR( arg_flags(ad), ARGVALSEP );
  1049. !             if ( !ARG_isMULTIVAL(ad) )  BCLEAR( arg_flags(ad), ARGVALGIVEN );
  1050. !          }
  1051. X  
  1052. X           BSET( arg_flags(ad), ARGVALSEP );
  1053. X  
  1054. ***************
  1055. *** 973,981 ****
  1056. X              ll += pl;
  1057. X  
  1058. X                  /* show the argument */
  1059. !             if ( ARG_isREQUIRED(ad) )  fputc('[', fp);
  1060. X              fprintf(fp, buf);
  1061. !             if ( ARG_isREQUIRED(ad) )  fputc(']', fp);
  1062. X  
  1063. X              first = FALSE;  /* not first line anymore */
  1064. X           }/*for each ad */
  1065. --- 978,986 ----
  1066. X              ll += pl;
  1067. X  
  1068. X                  /* show the argument */
  1069. !             if ( !ARG_isREQUIRED(ad) )  fputc('[', fp);
  1070. X              fprintf(fp, buf);
  1071. !             if ( !ARG_isREQUIRED(ad) )  fputc(']', fp);
  1072. X  
  1073. X              first = FALSE;  /* not first line anymore */
  1074. X           }/*for each ad */
  1075. *** /hx1d3/lp/brad/parseargs_patch03/parseargs/xparse.c    Wed Apr 10 09:54:11 1991
  1076. --- xparse.c    Thu Apr 11 11:08:40 1991
  1077. ***************
  1078. *** 21,32 ****
  1079. X  **    Each of these functions returns 0 upon success and non-zero otherwise
  1080. X  **    (except for usage() & init_args, which have no return value).
  1081. X  **
  1082. X  ** ^FILES:
  1083. X  **    <useful.h>
  1084. X  **    <parseargs.h>
  1085. X  **
  1086. X  ** ^SEE_ALSO:
  1087. ! **    argtype(3), parseargs(1), parseargs(3), parsecntl(3),
  1088. X  **
  1089. X  ** ^CAVEATS:
  1090. X  **    Because of the way argument parsing is implemented under UNIX, MS-DOS
  1091. --- 21,47 ----
  1092. X  **    Each of these functions returns 0 upon success and non-zero otherwise
  1093. X  **    (except for usage() & init_args, which have no return value).
  1094. X  **
  1095. + ** ^SIDE-EFFECTS:
  1096. + **    Each of the functions in the parseargs library will set the external
  1097. + **    character string ProgName to be the name of the last command that was
  1098. + **    operated upon by any of the library routines.
  1099. + **
  1100. + **    When an argument-descriptor array is first encountered by any of the
  1101. + **    parseargs library routines, it is initially compiled into an inter-
  1102. + **    mediate form that is more convenient to manipulate. As a direct
  1103. + **    result, it is not advisable to attempt to index directly into the
  1104. + **    array to manipulate one of the argument descriptors (because the
  1105. + **    argdesc that you thought was there may actually be somewhere else).
  1106. + **    After the array has been given its initial value(s), only parsecntl(3)
  1107. + **    should be used to manipulate or query the attributes of an argument
  1108. + **    descriptor.
  1109. + **
  1110. X  ** ^FILES:
  1111. X  **    <useful.h>
  1112. X  **    <parseargs.h>
  1113. X  **
  1114. X  ** ^SEE_ALSO:
  1115. ! **    argtype(3), parseargs(1), parseargs(3)
  1116. X  **
  1117. X  ** ^CAVEATS:
  1118. X  **    Because of the way argument parsing is implemented under UNIX, MS-DOS
  1119. ***************
  1120. *** 77,82 ****
  1121. --- 92,103 ----
  1122. X  **
  1123. X  ** ^HISTORY:
  1124. X  **    01/02/91     Brad Appleton     <brad@ssd.csd.harris.com>     Created
  1125. + **
  1126. + **    04/03/91     Brad Appleton     <brad@ssd.csd.harris.com>
  1127. + **    - fixed bug in [fvsl]parseargs() and parseargs().
  1128. + **      previous parse-flags should not be reset until AFTER required
  1129. + **      arguments are checked for, otherwise we may forget to prompt
  1130. + **      for them if $PARSECNTL asked us to do so.
  1131. X  ***^^**********************************************************************/
  1132. X  
  1133. X  #include <stdio.h>
  1134. ***************
  1135. *** 202,210 ****
  1136. --- 223,237 ----
  1137. X  #endif
  1138. X  
  1139. X  #ifdef vms_style
  1140. + # ifdef vms
  1141. +    { '<', ARGHIDDEN, argInput, __ &stdin,   "INPUT (redirect SYS$INPUT)" },
  1142. +    { '>', ARGHIDDEN, argOutput, __ &stdout, "OUTPUT (redirect SYS$OUTPUT)" },
  1143. +    { '%', ARGHIDDEN, argOutput, __ &stderr, "ERROR (redirect SYS$ERROR)" },
  1144. + # else
  1145. X     { '<', ARGHIDDEN, argInput, __ stdin,   "INPUT (redirect SYS$INPUT)" },
  1146. X     { '>', ARGHIDDEN, argOutput, __ stdout, "OUTPUT (redirect SYS$OUTPUT)" },
  1147. X     { '%', ARGHIDDEN, argOutput, __ stderr, "ERROR (redirect SYS$ERROR)" },
  1148. + # endif
  1149. X  #endif
  1150. X  
  1151. X     END_ARGUMENTS
  1152. ***************
  1153. *** 227,233 ****
  1154. X  #endif
  1155. X  
  1156. X  #ifdef vms
  1157. ! #  define  getenv(s)   getsymbol(s)
  1158. X  #  define  envfree(s)  (s) = ( !(s) ) ? CHARNULL : (free(s), CHARNULL)
  1159. X  #  include <descrip.h>
  1160. X  #  include <libdef.h>
  1161. --- 254,260 ----
  1162. X  #endif
  1163. X  
  1164. X  #ifdef vms
  1165. ! #  define  getenv(s)   get_symbol(s)
  1166. X  #  define  envfree(s)  (s) = ( !(s) ) ? CHARNULL : (free(s), CHARNULL)
  1167. X  #  include <descrip.h>
  1168. X  #  include <libdef.h>
  1169. ***************
  1170. *** 749,755 ****
  1171. X        }
  1172. X  
  1173. X        /* try to convert what we read (remember - buf is transient) */
  1174. !       if (  HANDLE( ad, buf, TRUE ) )
  1175. X           BSET(arg_flags(ad), ARGGIVEN | ARGVALGIVEN);
  1176. X        else
  1177. X           error = TRUE;
  1178. --- 776,782 ----
  1179. X        }
  1180. X  
  1181. X        /* try to convert what we read (remember - buf is transient) */
  1182. !       if (  (*arg_type(ad))(ad, buf, TRUE) )
  1183. X           BSET(arg_flags(ad), ARGGIVEN | ARGVALGIVEN);
  1184. X        else
  1185. X           error = TRUE;
  1186. ***************
  1187. *** 1010,1042 ****
  1188. X  **    refferred to as "terse" mode). The other two "modes" control the
  1189. X  **    displaying of option syntax and long-option syntax. A mode may be
  1190. X  **    explicitly disabled by preceding its corresponding string with the `!'
  1191. ! **    character. The "modes" which correspond to the possible values of the
  1192. ! **    "USAGECNTL" environment variable are given by the following table.
  1193. X  **
  1194. ! **         "Quiet"        No usage message of any kind is displayed.
  1195. X  **
  1196. ! **         "Silent"       Same as Quiet.
  1197. X  **
  1198. ! **         "Paged"        The usage message is piped to a pager. The pager
  1199. ! **                        used is named by the "USAGE_PAGER" environment
  1200. ! **                        variable. If this variable is unset or empty (or
  1201. ! **                        is not the name of an executable program), the
  1202. ! **                        pager named by the "PAGER" environment variable
  1203. ! **                        us used.  If this variable is unset or empty (or
  1204. ! **                        is not the name of an executable program) then
  1205. ! **                        the program "/usr/ucb/more" is used.
  1206. ! **         "Description"  The command description is printed.
  1207. X  **
  1208. ! **         "Terse"        Terse mode, just print command-line synopsis.
  1209. X  **
  1210. ! **         "Verbose"      Verbose mode, print descriptions for each argument
  1211. X  **
  1212. ! **         "Options"      Option syntax is displayed.
  1213. X  **
  1214. ! **         "LongOpts"     Long-option syntax is displayed.
  1215. X  **
  1216. ! **         "KeyWords"     Same as "LongOpts".
  1217. X  **
  1218. X  **    If the environment variable "USAGECNTL" is empty or undefined, then
  1219. X  **    the default usage level (which is presently "Verbose + Options")
  1220. X  **    will be used.
  1221. --- 1037,1077 ----
  1222. X  **    refferred to as "terse" mode). The other two "modes" control the
  1223. X  **    displaying of option syntax and long-option syntax. A mode may be
  1224. X  **    explicitly disabled by preceding its corresponding string with the `!'
  1225. ! **    or `-' character. The "modes" which correspond to the possible values of
  1226. ! **    the "USAGECNTL" environment variable are given by the following table.
  1227. X  **
  1228. ! **    "Quiet"
  1229. ! **       No usage message of any kind is displayed.
  1230. X  **
  1231. ! **    "Silent"
  1232. ! **       Same as Quiet.
  1233. X  **
  1234. ! **    "Paged"
  1235. ! **       The usage message is piped to a pager. The pager used is named by
  1236. ! **       the "USAGE_PAGER" environment variable. If this variable is unset
  1237. ! **       or empty (or is not the name of an executable program), the pager
  1238. ! **       named by the "PAGER" environment variable us used.  If this variable
  1239. ! **       is unset or empty (or is not the name of an executable program) then
  1240. ! **       the program "/usr/ucb/more" is used.
  1241. X  **
  1242. ! **    "Description"
  1243. ! **       The command description is printed.
  1244. X  **
  1245. ! **    "Terse"
  1246. ! **       Terse mode, just print command-line synopsis.
  1247. X  **
  1248. ! **    "Verbose"
  1249. ! **       Verbose mode, print descriptions for each argument
  1250. X  **
  1251. ! **    "Options"
  1252. ! **       Option syntax is displayed.
  1253. X  **
  1254. ! **    "LongOpts"
  1255. ! **       Long-option syntax is displayed.
  1256. X  **
  1257. + **    "KeyWords"
  1258. + **       Same as "LongOpts".
  1259. + **
  1260. X  **    If the environment variable "USAGECNTL" is empty or undefined, then
  1261. X  **    the default usage level (which is presently "Verbose + Options")
  1262. X  **    will be used.
  1263. ***************
  1264. *** 1131,1180 ****
  1265. X  **    it with a `!' or `-' character.  The possible "flags" are given by
  1266. X  **    the following table. Flags are case-insensitive.
  1267. X  **
  1268. ! **         "Prompt"      Prompt the user for any missing arguments that are
  1269. ! **                       required on the command-line. No special escaping
  1270. ! **                       or quoting is performed on the user input. Required
  1271. ! **                       arguments that expect a list of values will be
  1272. ! **                       repeatedly prompted for (one item per line) until a
  1273. ! **                       blank line (followed by a carriage return) is
  1274. ! **                       entered.
  1275. X  **
  1276. ! **         "Ignore"      Ignore any unrecognized or improperly specified
  1277. ! **                       command-line arguments and continue execution of
  1278. ! **                       the program. Normally, if an argument is unmatched
  1279. ! **                       (or is improperly specified), a usage message is
  1280. ! **                       printed and program execution is terminated.
  1281. X  **
  1282. ! **         "OptsOnly"    Under UNIX, setting this flag will disable the
  1283. ! **                       parsing of long-option syntax. This will cause all
  1284. ! **                       arguments starting with '+' to always be treated as
  1285. ! **                       a positional parameter (instead of a long-option).
  1286. X  **
  1287. ! **         "KwdsOnly"    Under UNIX, setting this flag disables the parsing
  1288. ! **                       of single-character options.  This will cause all
  1289. ! **                       arguments starting with '-' to always be treated as
  1290. ! **                       a positional parameter (instead of an option).
  1291. X  **
  1292. ! **         "LoptsOnly"   Same as KwdsOnly.
  1293. X  **
  1294. ! **         "Flags1st"    Setting this flag causes the parseargs library to
  1295. ! **                       force any and all non-positional arguments to be
  1296. ! **                       specified before any positional ones.  As an exam-
  1297. ! **                       ple, under UNIX, if this flag is SET then parseargs
  1298. ! **                       will consider the command line "cmd -x arg" to con-
  1299. ! **                       sist of one option and one positional argument;
  1300. ! **                       however the command line "cmd arg -x" would be con-
  1301. ! **                       sidered to consist of two positional arguments (the
  1302. ! **                       -x option will be unmatched).
  1303. X  **
  1304. ! **                       If this flag is UNSET, then both of the previous
  1305. ! **                       examples are considered to consist of one option
  1306. ! **                       and one positional argument.
  1307. X  **
  1308. ! **         "CaseIgnore"  Setting this flag causes character-case to be
  1309. ! **                       ignored when attempting to match single-character
  1310. ! **                       argument names (i.e. causes "-i" and "-I" will be
  1311. ! **                       considered equivalent).
  1312. X  **
  1313. X  **    If the environment variable "PARSECNTL" is empty or undefined, then the
  1314. X  **    parsing behavior set by the programmer is used.  If the programmer has
  1315. --- 1166,1213 ----
  1316. X  **    it with a `!' or `-' character.  The possible "flags" are given by
  1317. X  **    the following table. Flags are case-insensitive.
  1318. X  **
  1319. ! **    "Prompt"
  1320. ! **       Prompt the user for any missing arguments that are required on the
  1321. ! **       command-line. No special escaping or quoting is performed on the
  1322. ! **       user input. Required arguments that expect a list of values will
  1323. ! **       be repeatedly prompted for (one item per line) until a blank line
  1324. ! **       (followed by a carriage return) is entered.
  1325. X  **
  1326. ! **    "Ignore"
  1327. ! **       Ignore any unrecognized or improperly specified command-line arguments
  1328. ! **       and continue execution of the program. Normally, if a required
  1329. ! **       argument is unmatched (or an argument is improperly specified), a
  1330. ! **       usage message is printed and program execution is terminated.
  1331. X  **
  1332. ! **    "OptsOnly"
  1333. ! **       Under UNIX, setting this flag will disable the parsing of long-option
  1334. ! **       syntax. This will cause all arguments starting with '+' to always be
  1335. ! **       treated as a positional parameter (instead of a long-option).
  1336. X  **
  1337. ! **    "KwdsOnly"
  1338. ! **       Under UNIX, setting this flag disables the parsing of single-character
  1339. ! **       options.  This will cause all arguments starting with '-' to always be
  1340. ! **       treated as a positional parameter (instead of an option).
  1341. X  **
  1342. ! **    "LoptsOnly"
  1343. ! **       Same as KwdsOnly.
  1344. X  **
  1345. ! **    "Flags1st"
  1346. ! **       Setting this flag causes the parseargs library to force any and all
  1347. ! **       non-positional arguments to be specified before any positional ones.
  1348. ! **       As an example, under UNIX, if this flag is SET then parseargs will
  1349. ! **       consider the command line "cmd -x arg" to consist of one option and
  1350. ! **       one positional argument; however the command line "cmd arg -x" would
  1351. ! **       be considered to consist of two positional arguments (the -x option
  1352. ! **       will be unmatched).
  1353. X  **
  1354. ! **       If this flag is UNSET, then both of the previous examples are
  1355. ! **       considered to consist of one option and one positional argument.
  1356. X  **
  1357. ! **    "CaseIgnore"
  1358. ! **       Setting this flag causes character-case to be ignored when attempting
  1359. ! **       to match single-character argument names (i.e. causes "-i" and "-I"
  1360. ! **       will be considered equivalent).
  1361. X  **
  1362. X  **    If the environment variable "PARSECNTL" is empty or undefined, then the
  1363. X  **    parsing behavior set by the programmer is used.  If the programmer has
  1364. ***************
  1365. *** 1790,1796 ****
  1366. X    
  1367. X  /* ^DESCRIPTION:
  1368. X  **    Given a single string and an argdesc array, sparseargs will parse
  1369. ! **    arguments from a string in much the same manner as parseargs.
  1370. X  **    Sparseargs will split the given string up into a vector of whitespace
  1371. X  **    separated tokens and then attempt to parse the resultant vector as if
  1372. X  **    it were given as argv[] on the command-line.  NO special treatment is
  1373. --- 1823,1829 ----
  1374. X    
  1375. X  /* ^DESCRIPTION:
  1376. X  **    Given a single string and an argdesc array, sparseargs will parse
  1377. ! **    arguments from a string in the same manner as parseargs.
  1378. X  **    Sparseargs will split the given string up into a vector of whitespace
  1379. X  **    separated tokens and then attempt to parse the resultant vector as if
  1380. X  **    it were given as argv[] on the command-line.  NO special treatment is
  1381. ***************
  1382. *** 1848,1856 ****
  1383. X  
  1384. X     rc = parse_argv_style( argv, parse_init( &argd ) );
  1385. X  
  1386. -       /* reset previous parse flags */
  1387. -    cmd_flags(argd)  =  saveflags;
  1388. X        /* scan for missing required arguments */
  1389. X     if ( SYNTAX_ERROR(rc, argd) ) {
  1390. X        fputc( '\n', stderr );
  1391. --- 1881,1886 ----
  1392. ***************
  1393. *** 1858,1863 ****
  1394. --- 1888,1896 ----
  1395. X        exit( 2 );
  1396. X     }
  1397. X  
  1398. +       /* reset previous parse flags */
  1399. +    cmd_flags(argd)  =  saveflags;
  1400. X     return  rc;
  1401. X  }
  1402. X  
  1403. ***************
  1404. *** 1882,1888 ****
  1405. X  
  1406. X  /* ^DESCRIPTION:
  1407. X  **    Given a readable input stream and an argdesc array, fparseargs will
  1408. ! **    parse arguments in a file in much the same manner as parseargs.  A
  1409. X  **    maximum-line length of 255 characters is imposed.  NO "escaping" of
  1410. X  **    any kind is performed. Comments of a limited form are permitted: if
  1411. X  **    the first non-whitespace character on a line is a '#' (or '!' for VMS)
  1412. --- 1915,1921 ----
  1413. X  
  1414. X  /* ^DESCRIPTION:
  1415. X  **    Given a readable input stream and an argdesc array, fparseargs will
  1416. ! **    parse arguments in a file in the same manner as parseargs.  A
  1417. X  **    maximum-line length of 255 characters is imposed.  NO "escaping" of
  1418. X  **    any kind is performed. Comments of a limited form are permitted: if
  1419. X  **    the first non-whitespace character on a line is a '#' (or '!' for VMS)
  1420. ***************
  1421. *** 1961,1968 ****
  1422. X        BSET(cmd_flags(argd), pa_CONTINUE);
  1423. X     }/*while !EOF*/
  1424. X  
  1425. !       /* reset previous parse flags */
  1426. !    cmd_flags(argd)  =  saveflags;
  1427. X  
  1428. X        /* scan for missing required args */
  1429. X     if ( SYNTAX_ERROR(rc, argd) ) {
  1430. --- 1994,2000 ----
  1431. X        BSET(cmd_flags(argd), pa_CONTINUE);
  1432. X     }/*while !EOF*/
  1433. X  
  1434. !    if ( !BTEST(saveflags, pa_NOCHECK) )  BCLEAR(cmd_flags(argd), pa_NOCHECK);
  1435. SHAR_EOF
  1436. true || echo 'restore of PATCH failed'
  1437. echo 'End of  part 3'
  1438. echo 'File PATCH is continued in part 4'
  1439. echo 4 > _shar_seq_.tmp
  1440. exit 0
  1441. exit 0 # Just in case...
  1442. -- 
  1443. Kent Landfield                   INTERNET: kent@sparky.IMD.Sterling.COM
  1444. Sterling Software, IMD           UUCP:     uunet!sparky!kent
  1445. Phone:    (402) 291-8300         FAX:      (402) 291-4362
  1446. Please send comp.sources.misc-related mail to kent@uunet.uu.net.
  1447.