home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / misc / volume36 / cmdline / patch01b < prev    next >
Encoding:
Text File  |  1993-04-03  |  33.8 KB  |  1,047 lines

  1. Newsgroups: comp.sources.misc
  2. From: brad@hcx1.ssd.csd.harris.com (Brad Appleton)
  3. Subject: v36i094:  cmdline - C++ Library for parsing command-line arguments, Patch01b/2
  4. Message-ID: <1993Apr4.175913.10214@sparky.imd.sterling.com>
  5. X-Md4-Signature: 692efde6dd35fd51bafa4d0e544bf21d
  6. Date: Sun, 4 Apr 1993 17:59:13 GMT
  7. Approved: kent@sparky.imd.sterling.com
  8.  
  9. Submitted-by: brad@hcx1.ssd.csd.harris.com (Brad Appleton)
  10. Posting-number: Volume 36, Issue 94
  11. Archive-name: cmdline/patch01b
  12. Environment: C++
  13. Patch-To: cmdline: Volume 31, Issue 47-54
  14.  
  15. #! /bin/sh
  16. # This is a shell archive.  Remove anything before this line, then feed it
  17. # into a shell via "sh file" or similar.  To overwrite existing files,
  18. # type "sh file -c".
  19. # Contents:  PATCH01.B
  20. # Wrapped by kent@sparky on Sun Apr  4 12:46:49 1993
  21. PATH=/bin:/usr/bin:/usr/ucb:/usr/local/bin:/usr/lbin ; export PATH
  22. echo If this archive is complete, you will see the following message:
  23. echo '          "shar: End of archive 2 (of 2)."'
  24. if test -f 'PATCH01.B' -a "${1}" != "-c" ; then 
  25.   echo shar: Will not clobber existing file \"'PATCH01.B'\"
  26. else
  27.   echo shar: Extracting \"'PATCH01.B'\" \(31550 characters\)
  28.   sed "s/^X//" >'PATCH01.B' <<'END_OF_FILE'
  29. X*** src/lib/cmdline.h.OLD    Fri Mar 26 10:50:26 1993
  30. X--- src/lib/cmdline.h    Tue Mar 23 17:02:47 1993
  31. X***************
  32. X*** 9,14 ****
  33. X--- 9,21 ----
  34. X  //
  35. X  // ^HISTORY:
  36. X  //    03/19/92    Brad Appleton    <brad@ssd.csd.harris.com>    Created
  37. X+ //
  38. X+ //    03/01/93    Brad Appleton    <brad@ssd.csd.harris.com>
  39. X+ //    - Added arg_sequence field to CmdArg
  40. X+ //    - Added cmd_nargs_parsed field to CmdLine
  41. X+ //    - Added cmd_description field to CmdLine
  42. X+ //    - Added exit_handler() and quit() member-functions to CmdLine
  43. X+ //    - Added ALLOW_PLUS to list of CmdLine configuration flags
  44. X  //-^^---------------------------------------------------------------------
  45. X  
  46. X  #ifndef _usr_include_cmdline_h
  47. X***************
  48. X*** 68,78 ****
  49. X--- 75,93 ----
  50. X        isLIST      = 0x20,  // argument is a list
  51. X        isPOS       = 0x40,  // argument is positional
  52. X        isHIDDEN    = 0x80,  // argument is not to be printed in usage
  53. X+ #ifndef __gplusplus
  54. X        isVALTAKEN  = (isVALREQ | isVALOPT),    // argument takes a value
  55. X        isOPTVALOPT = (isOPT | isVALOPT),
  56. X        isOPTVALREQ = (isOPT | isVALREQ),
  57. X        isPOSVALOPT = (isPOS | isVALOPT),
  58. X        isPOSVALREQ = (isPOS | isVALREQ),
  59. X+ #else
  60. X+       isVALTAKEN  = 0x06,     // g++ doesnt seem to recognize enums that
  61. X+       isOPTVALOPT = 0x02,     // are defined in terms of previous values
  62. X+       isOPTVALREQ = 0x04,     // so I have to hard code the values instead.
  63. X+       isPOSVALOPT = 0x42,     //
  64. X+       isPOSVALREQ = 0x44,     // If this ever changes -- remove this stuff!
  65. X+ #endif
  66. X     } ;
  67. X  
  68. X       // Flags that say how the argument was specied on the command-line
  69. X***************
  70. X*** 204,209 ****
  71. X--- 219,234 ----
  72. X     unsigned
  73. X     flags(void) const  { return  arg_flags; }
  74. X  
  75. X+       // Get the sequence number corresponding to the last
  76. X+       // time this argument was matched on the command-line.
  77. X+       //
  78. X+       // If this argument was not matched, the sequence number
  79. X+       // will be zero, otherwise it will be 'N' where the last
  80. X+       // time this argument was matched, it was the 'N'th argument
  81. X+       // encountered.
  82. X+    unsigned
  83. X+    sequence(void) const { return arg_sequence; }
  84. X+ 
  85. X        // Get the character (short-option) name of this argument.
  86. X        // Returns '\0' if there isnt one.
  87. X     char
  88. X***************
  89. X*** 248,253 ****
  90. X--- 273,281 ----
  91. X     void
  92. X     clear(unsigned flags =~0)  { arg_flags &= ~flags; }
  93. X  
  94. X+       // set sequence number
  95. X+    void
  96. X+    sequence(unsigned  num) { arg_sequence = num; }
  97. X  
  98. X     // Private data members
  99. X  
  100. X***************
  101. X*** 256,261 ****
  102. X--- 284,291 ----
  103. X     unsigned     arg_flags : 8 ;
  104. X     unsigned     arg_syntax : 8 ;
  105. X  
  106. X+    unsigned     arg_sequence;
  107. X+ 
  108. X     char         arg_char_name;
  109. X     const char * arg_keyword_name;
  110. X     const char * arg_value_name;
  111. X***************
  112. X*** 309,314 ****
  113. X--- 339,345 ----
  114. X     virtual const char *
  115. X     operator()(void);
  116. X  
  117. X+       // is_temporary returns 0 for CmdArgvIter
  118. X     virtual int
  119. X     is_temporary(void) const;
  120. X  
  121. X***************
  122. X*** 361,366 ****
  123. X--- 392,398 ----
  124. X     void
  125. X     delimiters(const char * new_delimiters)  { seps = new_delimiters; }
  126. X  
  127. X+       // is_temporary returns 1 for CmdStrTokIter
  128. X     virtual int
  129. X     is_temporary(void) const;
  130. X  
  131. X***************
  132. X*** 387,392 ****
  133. X--- 419,432 ----
  134. X     //
  135. X  class  CmdIstreamIter : public CmdLineArgIter {
  136. X  public:
  137. X+    static const unsigned  MAX_LINE_LEN ;
  138. X+ 
  139. X+ #ifdef vms
  140. X+    enum { c_COMMENT = '!' } ;
  141. X+ #else
  142. X+    enum { c_COMMENT = '#' } ;
  143. X+ #endif
  144. X+ 
  145. X     CmdIstreamIter(istream & input);
  146. X  
  147. X     virtual ~CmdIstreamIter(void);
  148. X***************
  149. X*** 394,399 ****
  150. X--- 434,440 ----
  151. X     virtual const char *
  152. X     operator()(void);
  153. X  
  154. X+       // is_temporary returns 1 for CmdIstreamIter
  155. X     virtual int
  156. X     is_temporary(void) const;
  157. X  
  158. X***************
  159. X*** 420,426 ****
  160. X     enum CmdFlags {
  161. X        ANY_CASE_OPTS = 0x001, // Ignore character-case for short-options
  162. X        PROMPT_USER   = 0x002, // Prompt the user for missing required args
  163. X!       NO_ABORT      = 0x004, // Dont exit upon syntax error
  164. X        OPTS_FIRST    = 0x008, // No options after positional parameters
  165. X        OPTS_ONLY     = 0x010, // Dont accept short-options
  166. X        KWDS_ONLY     = 0x020, // Dont accept long-options
  167. X--- 461,467 ----
  168. X     enum CmdFlags {
  169. X        ANY_CASE_OPTS = 0x001, // Ignore character-case for short-options
  170. X        PROMPT_USER   = 0x002, // Prompt the user for missing required args
  171. X!       NO_ABORT      = 0x004, // Dont quit upon syntax error
  172. X        OPTS_FIRST    = 0x008, // No options after positional parameters
  173. X        OPTS_ONLY     = 0x010, // Dont accept short-options
  174. X        KWDS_ONLY     = 0x020, // Dont accept long-options
  175. X***************
  176. X*** 431,436 ****
  177. X--- 472,479 ----
  178. X                                  // when we see an unmatched option,
  179. X                                  // we will try to see if it matches
  180. X                                  // a keyword (and vice-versa).
  181. X+       ALLOW_PLUS    = 0x200, // Allow "+" (as well as "--") as a prefix
  182. X+                                 // indicating long-options.
  183. X     } ;
  184. X  
  185. X        // Flags to convey parsing-status
  186. X***************
  187. X*** 477,482 ****
  188. X--- 520,535 ----
  189. X     void
  190. X     name(const char * progname);
  191. X  
  192. X+       // Get the command description.
  193. X+    const char *
  194. X+    description(void)  const  { return  cmd_description; }
  195. X+ 
  196. X+       // Specify a command description.
  197. X+    void
  198. X+    description(const char * the_description) {
  199. X+       cmd_description = the_description;
  200. X+    }
  201. X+ 
  202. X        // Append an argument
  203. X     CmdLine &
  204. X     append(CmdArg * cmdarg);
  205. X***************
  206. X*** 615,620 ****
  207. X--- 668,708 ----
  208. X     epilogue(void) ;
  209. X  
  210. X     //
  211. X+    // Find out the number of arguments parsed so far
  212. X+    //
  213. X+ 
  214. X+    unsigned
  215. X+    nargs_parsed(void) const { return cmd_nargs_parsed; }
  216. X+ 
  217. X+    //
  218. X+    // Exception handling (well -- not really)
  219. X+    //
  220. X+ 
  221. X+    typedef  void (* quit_func_t)(int);
  222. X+ 
  223. X+       // When a fatal error is encounteredi or when parsing needs to
  224. X+       // terminate immediately, the quit() member function is called.
  225. X+       // If the programmer has used quit_handler() to setup his own
  226. X+       // handler-function, that that function is called; otherwise
  227. X+       // exit() is called with the given status.
  228. X+       // 
  229. X+    void
  230. X+    quit(int status);
  231. X+ 
  232. X+       // Set the quit-handler. The quit-handler is a pointer to
  233. X+       // a function that has no return value and takes a single
  234. X+       // integer parameter.
  235. X+       //
  236. X+    void
  237. X+    quit_handler(quit_func_t  quit_func) { cmd_quit_handler = quit_func ; }
  238. X+ 
  239. X+       // Get the current quit-handler (returns NULL if there isnt one)
  240. X+       //
  241. X+    quit_func_t
  242. X+    quit_handler(void) const { return  cmd_quit_handler; }
  243. X+ 
  244. X+ 
  245. X+    //
  246. X     // Retrieve a specific argument
  247. X     //
  248. X  
  249. X***************
  250. X*** 704,713 ****
  251. X--- 792,804 ----
  252. X     unsigned          cmd_state  : 8 ;
  253. X     unsigned          cmd_flags  : 16 ;
  254. X     unsigned          cmd_status : 16 ;
  255. X+    unsigned          cmd_nargs_parsed ;
  256. X     const char      * cmd_name ;
  257. X+    const char      * cmd_description ;
  258. X     CmdArg          * cmd_matched_arg ;
  259. X     CmdArgListList  * cmd_args ;
  260. X     ostream         * cmd_err ;
  261. X+    quit_func_t       cmd_quit_handler ;
  262. X  
  263. X        // Disallow copying and assignment
  264. X     CmdLine(const CmdLine & );
  265. X*** src/lib/cmdtest.c.OLD    Fri Mar 26 10:50:31 1993
  266. X--- src/lib/cmdtest.c    Wed Mar  3 14:11:57 1993
  267. X***************
  268. X*** 6,11 ****
  269. X--- 6,14 ----
  270. X  //
  271. X  // ^HISTORY:
  272. X  //    03/18/92    Brad Appleton    <brad@ssd.csd.harris.com>    Created
  273. X+ //
  274. X+ //    03/01/93    Brad Appleton    <brad@ssd.csd.harris.com>
  275. X+ //    - Attached a description to the command.
  276. X  //-^^---------------------------------------------------------------------
  277. X  
  278. X  #include <stdlib.h>
  279. X***************
  280. X*** 74,79 ****
  281. X--- 77,84 ----
  282. X  
  283. X           case 'g' : new_flags |= CmdLine::NO_GUESSING;    break;
  284. X  
  285. X+          case '+' : new_flags |= CmdLine::ALLOW_PLUS;     break;
  286. X+ 
  287. X           default  : break;
  288. X        } //switch
  289. X     } //for
  290. X***************
  291. X*** 100,105 ****
  292. X--- 105,111 ----
  293. X     't' = Temporary-args\n\
  294. X     'q' = Quiet!\n\
  295. X     'g' = no-Guessing\n\
  296. X+    '+' = allow-plus\n\
  297. X  This-is-a-very-long-line-containing-no-whitespace-\
  298. X  characters-and-I-just-want-to-see-if-it-gets-\
  299. X  formatted-appropriately!"
  300. X***************
  301. X*** 200,207 ****
  302. X--- 206,219 ----
  303. X                  & name,
  304. X                  & files,
  305. X                  NULL);
  306. X+ 
  307. X     CmdArgvIter  argv_iter(--argc, ++argv);
  308. X  
  309. X+    cmd.description(
  310. X+ "This program is intended to statically and dynamically test \
  311. X+ the CmdLine(3C++) class library."
  312. X+    );
  313. X+ 
  314. X     cout << "Test of " << CmdLine::ident() << endl ;
  315. X  
  316. X     xflag = 0;
  317. X***************
  318. X*** 226,232 ****
  319. X     int  parse_cin = infile;
  320. X  
  321. X     // Parse arguments from a string
  322. X!    if (str) {
  323. X        CmdStrTokIter  tok_iter(str);
  324. X  
  325. X        xflag = 0;
  326. X--- 238,244 ----
  327. X     int  parse_cin = infile;
  328. X  
  329. X     // Parse arguments from a string
  330. X!    if (! str.isNULL()) {
  331. X        CmdStrTokIter  tok_iter(str);
  332. X  
  333. X        xflag = 0;
  334. X*** src/lib/dump.c.OLD    Fri Mar 26 10:50:35 1993
  335. X--- src/lib/dump.c    Mon Mar  1 11:01:33 1993
  336. X***************
  337. X*** 8,13 ****
  338. X--- 8,18 ----
  339. X  //
  340. X  // ^HISTORY:
  341. X  //    04/01/92    Brad Appleton    <brad@ssd.csd.harris.com>    Created
  342. X+ //
  343. X+ //    03/01/93    Brad Appleton    <brad@ssd.csd.harris.com>
  344. X+ //    - Added arg_sequence field to CmdArg
  345. X+ //    - Added cmd_nargs_parsed field to CmdLine
  346. X+ //    - Added cmd_description field to CmdLine
  347. X  //-^^---------------------------------------------------------------------
  348. X  
  349. X  #include  "cmdline.h"
  350. X***************
  351. X*** 295,300 ****
  352. X--- 300,307 ----
  353. X     ::indent(os, level + 1) << "flags=" ;
  354. X     dump_arg_flags(os, arg_flags) << "\n";
  355. X  
  356. X+    ::indent(os, level + 1) << "sequence=" << arg_sequence << "\n";
  357. X+ 
  358. X     ::indent(os, level) << "}" << endl;
  359. X  #endif
  360. X  }
  361. X***************
  362. X*** 309,314 ****
  363. X--- 316,323 ----
  364. X  
  365. X     ::indent(os, level + 1) << "name=\"" << cmd_name << "\"\n";
  366. X  
  367. X+    ::indent(os, level + 1) << "description=\"" << cmd_description << "\"\n";
  368. X+ 
  369. X     ::indent(os, level + 1) << "flags=" ;
  370. X     dump_cmd_flags(os, cmd_flags) << "\n";
  371. X  
  372. X***************
  373. X*** 327,332 ****
  374. X--- 336,344 ----
  375. X     } else {
  376. X        os << "matched_arg=" << (void *)cmd_matched_arg << "\n";
  377. X     }
  378. X+ 
  379. X+    ::indent(os, level + 1) << "# valid-args-parsed="
  380. X+                            << cmd_nargs_parsed << "\n" ;
  381. X  
  382. X     ::indent(os, level) << "}" << endl;
  383. X  #endif
  384. X*** src/lib/parse.c.OLD    Fri Mar 26 10:50:41 1993
  385. X--- src/lib/parse.c    Wed Mar  3 10:02:21 1993
  386. X***************
  387. X*** 10,15 ****
  388. X--- 10,19 ----
  389. X  //
  390. X  // ^HISTORY:
  391. X  //    12/05/91    Brad Appleton    <brad@ssd.csd.harris.com>    Created
  392. X+ //
  393. X+ //    03/01/93    Brad Appleton    <brad@ssd.csd.harris.com>
  394. X+ //    - Added cmd_nargs_parsed field to CmdLine
  395. X+ //    - Added exit_handler() and quit() member-functions to CmdLine
  396. X  //-^^---------------------------------------------------------------------
  397. X  
  398. X  #include <stdlib.h>
  399. X***************
  400. X*** 58,63 ****
  401. X--- 62,68 ----
  402. X     cmd_parse_state = cmd_START_STATE ;
  403. X     cmd_state = 0 ;
  404. X     cmd_status = NO_ERROR ;
  405. X+    cmd_nargs_parsed = 0 ;
  406. X  
  407. X     // reset parse-specific attributes for each argument
  408. X     CmdArgListListIter  list_iter(cmd_args);
  409. X***************
  410. X*** 94,100 ****
  411. X  //
  412. X  //    Prints a usage message if there were syntax error.
  413. X  //
  414. X! //    Terminates program execution by calling ::exit(e_SYNTAX) if
  415. X  //    (NO_ABORT is NOT set and the command-status is NOT NO_ERROR).
  416. X  //
  417. X  // ^RETURN-VALUE:
  418. X--- 99,105 ----
  419. X  //
  420. X  //    Prints a usage message if there were syntax error.
  421. X  //
  422. X! //    Terminates program execution by calling quit(e_SYNTAX) if
  423. X  //    (NO_ABORT is NOT set and the command-status is NOT NO_ERROR).
  424. X  //
  425. X  // ^RETURN-VALUE:
  426. X***************
  427. X*** 121,130 ****
  428. X     // print usage if necessary
  429. X     if (cmd_status & ARG_MISSING) {
  430. X        usage();
  431. X!       ::exit(e_SYNTAX);
  432. X     } else if (cmd_status && (! (cmd_flags & NO_ABORT))) {
  433. X        usage();
  434. X!       ::exit(e_SYNTAX);
  435. X     }
  436. X  
  437. X     return  cmd_status ;
  438. X--- 126,135 ----
  439. X     // print usage if necessary
  440. X     if (cmd_status & ARG_MISSING) {
  441. X        usage();
  442. X!       quit(e_SYNTAX);
  443. X     } else if (cmd_status && (! (cmd_flags & NO_ABORT))) {
  444. X        usage();
  445. X!       quit(e_SYNTAX);
  446. X     }
  447. X  
  448. X     return  cmd_status ;
  449. X*** src/lib/patchlevel.c.OLD    Fri Mar 26 10:50:46 1993
  450. X--- src/lib/patchlevel.c    Wed Mar  3 14:41:41 1993
  451. X***************
  452. X*** 9,14 ****
  453. X--- 9,17 ----
  454. X  //
  455. X  // ^HISTORY:
  456. X  //    04/03/92    Brad Appleton    <brad@ssd.csd.harris.com>    Created
  457. X+ //
  458. X+ //    03/03/93    Brad Appleton    <brad@ssd.csd.harris.com>
  459. X+ //    - Modified for patch 1
  460. X  //-^^---------------------------------------------------------------------
  461. X  
  462. X  #include "cmdline.h"
  463. X***************
  464. X*** 21,33 ****
  465. X     // file that makes up this version of the project.
  466. X     //
  467. X  static const char ident[] =
  468. X!    "@(#)SMS  task: cmdline-1.00" ;
  469. X  
  470. X  
  471. X     // Release and patchlevel information
  472. X  #define  CMDLINE_RELEASE     1
  473. X! #define  CMDLINE_PATCHLEVEL  0
  474. X! #define  CMDLINE_IDENT       "@(#)CmdLine    1.00"
  475. X  
  476. X  unsigned
  477. X  CmdLine::release(void)  { return  CMDLINE_RELEASE; }
  478. X--- 24,36 ----
  479. X     // file that makes up this version of the project.
  480. X     //
  481. X  static const char ident[] =
  482. X!    "@(#)SMS  task: cmdline-1.01" ;
  483. X  
  484. X  
  485. X     // Release and patchlevel information
  486. X  #define  CMDLINE_RELEASE     1
  487. X! #define  CMDLINE_PATCHLEVEL  1
  488. X! #define  CMDLINE_IDENT       "@(#)CmdLine    1.01"
  489. X  
  490. X  unsigned
  491. X  CmdLine::release(void)  { return  CMDLINE_RELEASE; }
  492. X*** src/lib/private.c.OLD    Fri Mar 26 10:50:51 1993
  493. X--- src/lib/private.c    Wed Mar  3 10:03:01 1993
  494. X***************
  495. X*** 15,20 ****
  496. X--- 15,23 ----
  497. X  //
  498. X  // ^HISTORY:
  499. X  //    01/09/92    Brad Appleton    <brad@ssd.csd.harris.com>    Created
  500. X+ //
  501. X+ //    03/03/93    Brad Appleton    <brad@ssd.csd.harris.com>
  502. X+ //    - Added exit_handler() and quit() member-functions to CmdLine
  503. X  //-^^---------------------------------------------------------------------
  504. X  
  505. X  #include <iostream.h>
  506. X***************
  507. X*** 96,102 ****
  508. X  //    with the argument "cmdarg".
  509. X  //
  510. X  // ^ALGORITHM:
  511. X! //    - if this is a cmdargUsage argument then print usage and call exit(3C)
  512. X  //    - call the operator() of "cmdarg" and save the result.
  513. X  //    - if the above call returned SUCCESS then set the GIVEN and VALGIVEN
  514. X  //      flags of the argument.
  515. X--- 99,105 ----
  516. X  //    with the argument "cmdarg".
  517. X  //
  518. X  // ^ALGORITHM:
  519. X! //    - if this is a cmdargUsage argument then print usage and call quit()
  520. X  //    - call the operator() of "cmdarg" and save the result.
  521. X  //    - if the above call returned SUCCESS then set the GIVEN and VALGIVEN
  522. X  //      flags of the argument.
  523. X***************
  524. X*** 107,119 ****
  525. X  int
  526. X  CmdLine::handle_arg(CmdArg * cmdarg, const char * & arg)
  527. X  {
  528. X!    int  bad_val ;
  529. X  
  530. X     // call the argument compiler
  531. X     const char * save_arg = arg ;  // just in case someone forgets to set it
  532. X!    bad_val = (*cmdarg)(arg, *this);
  533. X     if (! bad_val) {
  534. X        cmdarg->set(CmdArg::GIVEN) ;
  535. X        if (arg != save_arg) {
  536. X           cmdarg->set(CmdArg::VALGIVEN) ;
  537. X        }
  538. X--- 110,123 ----
  539. X  int
  540. X  CmdLine::handle_arg(CmdArg * cmdarg, const char * & arg)
  541. X  {
  542. X!    ++cmd_nargs_parsed;  // update the number of parsed args
  543. X  
  544. X     // call the argument compiler
  545. X     const char * save_arg = arg ;  // just in case someone forgets to set it
  546. X!    int  bad_val = (*cmdarg)(arg, *this);
  547. X     if (! bad_val) {
  548. X        cmdarg->set(CmdArg::GIVEN) ;
  549. X+       cmdarg->sequence(cmd_nargs_parsed) ;
  550. X        if (arg != save_arg) {
  551. X           cmdarg->set(CmdArg::VALGIVEN) ;
  552. X        }
  553. X***************
  554. X*** 397,403 ****
  555. X  //
  556. X  // ^SIDE-EFFECTS:
  557. X  //    - modifies the status of "cmd".
  558. X! //    - terminates execution by calling exit(3C) if cmd_NOABORT is NOT
  559. X  //      set and a required argument (that was not properly supplied by
  560. X  //      the user) is not given.
  561. X  //    - prints on stderr if an argument is missing and cmd_QUIET is NOT set.
  562. X--- 401,407 ----
  563. X  //
  564. X  // ^SIDE-EFFECTS:
  565. X  //    - modifies the status of "cmd".
  566. X! //    - terminates execution by calling quit() if cmd_NOABORT is NOT
  567. X  //      set and a required argument (that was not properly supplied by
  568. X  //      the user) is not given.
  569. X  //    - prints on stderr if an argument is missing and cmd_QUIET is NOT set.
  570. X*** src/lib/states.h.OLD    Fri Mar 26 10:50:57 1993
  571. X--- src/lib/states.h    Mon Feb 22 14:24:12 1993
  572. X***************
  573. X*** 56,69 ****
  574. X--- 56,81 ----
  575. X     cmd_TOK_REQUIRED = 0x01,  // is the "wanted" token required?
  576. X  
  577. X     cmd_WANT_VAL     = 0x02,  // are we expecting a value?
  578. X+ #ifndef __gplusplus
  579. X     cmd_NEED_VAL     = (cmd_WANT_VAL | cmd_TOK_REQUIRED),
  580. X+ #else
  581. X+    cmd_NEED_VAL     = 0x03,
  582. X+ #endif
  583. X  
  584. X  #ifdef vms_style
  585. X     cmd_WANT_VALSEP  = 0x04,  // are we expecting ':' or '='
  586. X+ # ifndef __gplusplus
  587. X     cmd_NEED_VALSEP  = (cmd_WANT_VALSEP | cmd_TOK_REQUIRED),
  588. X+ # else
  589. X+    cmd_NEED_VALSEP  = 0x05,
  590. X+ # endif
  591. X  
  592. X     cmd_WANT_LISTSEP = 0x08,  // are we expecting ',' or '+'
  593. X+ # ifndef __gplusplus
  594. X     cmd_NEED_LISTSEP = (cmd_WANT_LISTSEP | cmd_TOK_REQUIRED),
  595. X+ # else
  596. X+    cmd_NEED_LISTSEP = 0x09,
  597. X+ # endif
  598. X  #endif
  599. X  } ;
  600. X  
  601. X*** src/lib/unix.c.OLD    Fri Mar 26 10:51:03 1993
  602. X--- src/lib/unix.c    Wed Mar  3 14:20:20 1993
  603. X***************
  604. X*** 16,21 ****
  605. X--- 16,24 ----
  606. X  //
  607. X  // ^HISTORY:
  608. X  //    01/09/92    Brad Appleton    <brad@ssd.csd.harris.com>    Created
  609. X+ //
  610. X+ //    03/01/93    Brad Appleton    <brad@ssd.csd.harris.com>
  611. X+ //    - Added ALLOW_PLUS to list of CmdLine configuration flags
  612. X  //-^^---------------------------------------------------------------------
  613. X  
  614. X  #include <iostream.h>
  615. X***************
  616. X*** 27,34 ****
  617. X  #include "cmdline.h"
  618. X  #include "states.h"
  619. X  
  620. X!   // Prefix string used for short options
  621. X! static const char OPT_PFX[] = "-" ;
  622. X  
  623. X    // Function to tell us if an argument looks like an option
  624. X  inline static int
  625. X--- 30,38 ----
  626. X  #include "cmdline.h"
  627. X  #include "states.h"
  628. X  
  629. X! //
  630. X! // Some Helper function for getting and recognizing prefixes
  631. X! //
  632. X  
  633. X    // Function to tell us if an argument looks like an option
  634. X  inline static int
  635. X***************
  636. X*** 36,60 ****
  637. X     return  ((*(s) == '-') && ((*((s)+1) != '-')) && ((*((s)+1) != '\0'))) ;
  638. X  }
  639. X  
  640. X!   // Need a prefix string for a long-option and a function to tell us
  641. X!   // if an argument looks like a long-option as well.
  642. X!   //
  643. X! #ifdef  USE_PLUS
  644. X!    static const char KWD_PFX[] = "+" ;
  645. X  
  646. X-    inline static int
  647. X-    isKEYWORD(const char *s) {
  648. X-       return   ((*(s) == '+') && ((*((s)+1) != '\0'))) ;
  649. X-    }
  650. X- #else
  651. X-    static const char KWD_PFX[] = "--" ;
  652. X  
  653. X!    inline static int
  654. X!    isKEYWORD(const char *s) {
  655. X!       return  ((*(s) == '-') && (*((s)+1) == '-')  && (*((s)+2) != '\0')) ;
  656. X!    }
  657. X! #endif
  658. X  
  659. X     // Need to know when an argument means "end-of-options"
  660. X  inline static int
  661. X  isENDOPTIONS(const char *s) {
  662. X--- 40,64 ----
  663. X     return  ((*(s) == '-') && ((*((s)+1) != '-')) && ((*((s)+1) != '\0'))) ;
  664. X  }
  665. X  
  666. X!    // Function to return the option-prefix
  667. X! inline static const char *
  668. X! OptionPrefix(void) { return  "-" ; }
  669. X  
  670. X  
  671. X!    // Function to tell us if an argument looks like a long-option.
  672. X!    //
  673. X!    // NOTE: allowing "+" does not preclude the use of "--"
  674. X!    //
  675. X! inline static int
  676. X! isKEYWORD(const char *s, int allow_plus) {
  677. X!    return  (((*(s) == '-') && (*((s)+1) == '-')  && (*((s)+2) != '\0')) ||
  678. X!             (allow_plus && (*(s) == '+') && ((*((s)+1) != '\0')))) ;
  679. X! }
  680. X  
  681. X+    // Function to return the long-option prefix
  682. X+ inline static const char *
  683. X+ KeywordPrefix(int allow_plus) { return  (allow_plus) ? "+" : "--" ; }
  684. X+ 
  685. X     // Need to know when an argument means "end-of-options"
  686. X  inline static int
  687. X  isENDOPTIONS(const char *s) {
  688. X***************
  689. X*** 61,67 ****
  690. X--- 65,75 ----
  691. X     return  ((*(s) == '-') && (*((s)+1) == '-')  && (*((s)+2) == '\0')) ;
  692. X  }
  693. X  
  694. X+    // Function to return the "end-of-options" string
  695. X+ inline static const char *
  696. X+ EndOptions(void) { return "--" ; }
  697. X  
  698. X+ 
  699. X  //-------
  700. X  // ^FUNCTION: CmdLine::parse_option - parse a Unix option
  701. X  //
  702. X***************
  703. X*** 140,146 ****
  704. X              }
  705. X           }
  706. X           if (! (cmd_flags & QUIET)) {
  707. X!             error() << "unknown option \"" << OPT_PFX << char(*arg)
  708. X                      << "\"." << endl ;
  709. X           }
  710. X           rc |= BAD_OPTION ;
  711. X--- 148,154 ----
  712. X              }
  713. X           }
  714. X           if (! (cmd_flags & QUIET)) {
  715. X!             error() << "unknown option \"" << OptionPrefix() << char(*arg)
  716. X                      << "\"." << endl ;
  717. X           }
  718. X           rc |= BAD_OPTION ;
  719. X***************
  720. X*** 164,170 ****
  721. X              if (cmdarg->syntax() & CmdArg::isVALREQ) {
  722. X                 if (! (cmd_flags & QUIET)) {
  723. X                    error() << "value required in same argument for "
  724. X!                           << OPT_PFX << char(cmdarg->char_name())
  725. X                            << " option." << endl;
  726. X                 }
  727. X                 rc |= (VAL_MISSING | VAL_NOTSTICKY) ;
  728. X--- 172,178 ----
  729. X              if (cmdarg->syntax() & CmdArg::isVALREQ) {
  730. X                 if (! (cmd_flags & QUIET)) {
  731. X                    error() << "value required in same argument for "
  732. X!                           << OptionPrefix() << char(cmdarg->char_name())
  733. X                            << " option." << endl;
  734. X                 }
  735. X                 rc |= (VAL_MISSING | VAL_NOTSTICKY) ;
  736. X***************
  737. X*** 204,210 ****
  738. X            (cmdarg->syntax() & CmdArg::isVALSEP)) {
  739. X           if (! (cmd_flags & QUIET)) {
  740. X              error() << "value required in separate argument for "
  741. X!                     << OPT_PFX << char(cmdarg->char_name())
  742. X                      << " option." << endl;
  743. X           }
  744. X           rc |= (VAL_MISSING | VAL_NOTSEP) ;
  745. X--- 212,218 ----
  746. X            (cmdarg->syntax() & CmdArg::isVALSEP)) {
  747. X           if (! (cmd_flags & QUIET)) {
  748. X              error() << "value required in separate argument for "
  749. X!                     << OptionPrefix() << char(cmdarg->char_name())
  750. X                      << " option." << endl;
  751. X           }
  752. X           rc |= (VAL_MISSING | VAL_NOTSEP) ;
  753. X***************
  754. X*** 285,290 ****
  755. X--- 293,300 ----
  756. X     int  ambiguous = 0, len = -1, bad_val;
  757. X     const char * val = NULL ;
  758. X  
  759. X+    int  plus = (cmd_flags & ALLOW_PLUS) ;  // Can we use "+"?
  760. X+ 
  761. X     // see if we left an argument dangling without a value
  762. X     ck_need_val() ;
  763. X  
  764. X***************
  765. X*** 312,318 ****
  766. X        }
  767. X        if (! (cmd_flags & QUIET)) {
  768. X           error() << ((ambiguous) ? "ambiguous" : "unknown") << " option "
  769. X!                  << "\"" << ((cmd_flags & KWDS_ONLY) ? OPT_PFX : KWD_PFX)
  770. X                   << arg << "\"." << endl ;
  771. X        }
  772. X        rc |= ((ambiguous) ? KWD_AMBIGUOUS : BAD_KEYWORD) ;
  773. X--- 322,329 ----
  774. X        }
  775. X        if (! (cmd_flags & QUIET)) {
  776. X           error() << ((ambiguous) ? "ambiguous" : "unknown") << " option "
  777. X!                  << "\"" << ((cmd_flags & KWDS_ONLY) ? OptionPrefix()
  778. X!                                                      : KeywordPrefix(plus))
  779. X                   << arg << "\"." << endl ;
  780. X        }
  781. X        rc |= ((ambiguous) ? KWD_AMBIGUOUS : BAD_KEYWORD) ;
  782. X***************
  783. X*** 334,340 ****
  784. X           if (cmdarg->syntax() & CmdArg::isVALREQ) {
  785. X              if (! (cmd_flags & QUIET)) {
  786. X                 error() << "value required in same argument for "
  787. X!                        << ((cmd_flags & KWDS_ONLY) ? OPT_PFX : KWD_PFX)
  788. X                         << cmdarg->keyword_name() << " option." << endl;
  789. X              }
  790. X              rc |= (VAL_MISSING | VAL_NOTSTICKY) ;
  791. X--- 345,352 ----
  792. X           if (cmdarg->syntax() & CmdArg::isVALREQ) {
  793. X              if (! (cmd_flags & QUIET)) {
  794. X                 error() << "value required in same argument for "
  795. X!                        << ((cmd_flags & KWDS_ONLY) ? OptionPrefix()
  796. X!                                                    : KeywordPrefix(plus))
  797. X                         << cmdarg->keyword_name() << " option." << endl;
  798. X              }
  799. X              rc |= (VAL_MISSING | VAL_NOTSTICKY) ;
  800. X***************
  801. X*** 374,380 ****
  802. X         (cmdarg->syntax() & CmdArg::isVALSEP)) {
  803. X        if (! (cmd_flags & QUIET)) {
  804. X           error() << "value required in separate argument for "
  805. X!                  << ((cmd_flags & KWDS_ONLY) ? OPT_PFX : KWD_PFX)
  806. X                   << cmdarg->keyword_name() << " option." << endl;
  807. X        }
  808. X        rc |= (VAL_MISSING | VAL_NOTSEP) ;
  809. X--- 386,393 ----
  810. X         (cmdarg->syntax() & CmdArg::isVALSEP)) {
  811. X        if (! (cmd_flags & QUIET)) {
  812. X           error() << "value required in separate argument for "
  813. X!                  << ((cmd_flags & KWDS_ONLY) ? OptionPrefix()
  814. X!                                              : KeywordPrefix(plus))
  815. X                   << cmdarg->keyword_name() << " option." << endl;
  816. X        }
  817. X        rc |= (VAL_MISSING | VAL_NOTSEP) ;
  818. X***************
  819. X*** 544,549 ****
  820. X--- 557,564 ----
  821. X  {
  822. X     if (arg == NULL)  return  cmd_status ;
  823. X  
  824. X+    int  plus = (cmd_flags & ALLOW_PLUS) ;  // Can we use "+"?
  825. X+ 
  826. X     if (cmd_parse_state & cmd_TOK_REQUIRED) {
  827. X        // If a required value is expected, then this argument MUST be
  828. X        // the value (even if it looks like an option
  829. X***************
  830. X*** 559,570 ****
  831. X           cmd_status |=  parse_option(arg) ;
  832. X        }
  833. X     } else if ((! (cmd_flags & OPTS_ONLY))
  834. X!               && isKEYWORD(arg) && (! (cmd_state & cmd_END_OF_OPTIONS))) {
  835. X        cmd_state |= cmd_KEYWORDS_USED ;
  836. X!       ++arg ;  // skip over '+' keyword prefix
  837. X! #ifndef USE_PLUS
  838. X!       ++arg ;  // skip over '--' keyword prefix
  839. X! #endif
  840. X        cmd_status |= parse_keyword(arg) ;
  841. X     } else if (isENDOPTIONS(arg) && (! (cmd_state & cmd_END_OF_OPTIONS))) {
  842. X        cmd_state |= cmd_END_OF_OPTIONS ;
  843. X--- 574,586 ----
  844. X           cmd_status |=  parse_option(arg) ;
  845. X        }
  846. X     } else if ((! (cmd_flags & OPTS_ONLY))
  847. X!               && isKEYWORD(arg, plus) && (! (cmd_state & cmd_END_OF_OPTIONS))) {
  848. X        cmd_state |= cmd_KEYWORDS_USED ;
  849. X!       if (*arg == '+') {
  850. X!          ++arg ;  // skip over '+' keyword prefix
  851. X!       } else {
  852. X!          arg += 2 ;  // skip over '--' keyword prefix
  853. X!       }
  854. X        cmd_status |= parse_keyword(arg) ;
  855. X     } else if (isENDOPTIONS(arg) && (! (cmd_state & cmd_END_OF_OPTIONS))) {
  856. X        cmd_state |= cmd_END_OF_OPTIONS ;
  857. X***************
  858. X*** 611,624 ****
  859. X  ostream &
  860. X  CmdLine::arg_error(const char * error_str, const CmdArg * cmdarg) const
  861. X  {
  862. X     ostream & os = error() << error_str << char(' ') ;
  863. X  
  864. X     if (cmdarg->flags() & CmdArg::GIVEN) {
  865. X         if (cmdarg->flags() & CmdArg::KEYWORD) {
  866. X!           os << ((cmd_flags & KWDS_ONLY) ? OPT_PFX : KWD_PFX)
  867. X               << cmdarg->keyword_name() << " option" ;
  868. X         } else if (cmdarg->flags() & CmdArg::OPTION) {
  869. X!           os << OPT_PFX << (char)cmdarg->char_name() << " option" ;
  870. X         } else {
  871. X            os << cmdarg->value_name() << " argument" ;
  872. X         }
  873. X--- 627,643 ----
  874. X  ostream &
  875. X  CmdLine::arg_error(const char * error_str, const CmdArg * cmdarg) const
  876. X  {
  877. X+    int  plus = (cmd_flags & ALLOW_PLUS) ;  // Can we use "+"?
  878. X+ 
  879. X     ostream & os = error() << error_str << char(' ') ;
  880. X  
  881. X     if (cmdarg->flags() & CmdArg::GIVEN) {
  882. X         if (cmdarg->flags() & CmdArg::KEYWORD) {
  883. X!           os << ((cmd_flags & KWDS_ONLY) ? OptionPrefix()
  884. X!                                          : KeywordPrefix(plus))
  885. X               << cmdarg->keyword_name() << " option" ;
  886. X         } else if (cmdarg->flags() & CmdArg::OPTION) {
  887. X!           os << OptionPrefix() << (char)cmdarg->char_name() << " option" ;
  888. X         } else {
  889. X            os << cmdarg->value_name() << " argument" ;
  890. X         }
  891. X***************
  892. X*** 627,635 ****
  893. X            os << cmdarg->value_name() << " argument" ;
  894. X         } else {
  895. X            if (cmd_flags & KWDS_ONLY) {
  896. X!              os << OPT_PFX << cmdarg->keyword_name() << " option" ;
  897. X            } else {
  898. X!              os << OPT_PFX << (char)cmdarg->char_name() << " option" ;
  899. X            }
  900. X         }
  901. X     }
  902. X--- 646,654 ----
  903. X            os << cmdarg->value_name() << " argument" ;
  904. X         } else {
  905. X            if (cmd_flags & KWDS_ONLY) {
  906. X!              os << OptionPrefix() << cmdarg->keyword_name() << " option" ;
  907. X            } else {
  908. X!              os << OptionPrefix() << (char)cmdarg->char_name() << " option" ;
  909. X            }
  910. X         }
  911. X     }
  912. X***************
  913. X*** 686,691 ****
  914. X--- 705,711 ----
  915. X     ostrstream  oss(buf, bufsize);
  916. X     *buf = '\0';
  917. X  
  918. X+    int  plus = (cmd_flags & ALLOW_PLUS) ;  // Can we use "+"?
  919. X     char optchar = cmdarg->char_name();
  920. X     const char * keyword = cmdarg->keyword_name();
  921. X  
  922. X***************
  923. X*** 723,734 ****
  924. X         (cmdarg->syntax() & CmdArg::isVALSTICKY))
  925. X     {
  926. X        if (cmdarg->syntax() & CmdArg::isVALOPT) {
  927. X!          oss << OPT_PFX << char(optchar) << char('[') << cmdarg->value_name()
  928. X!              << "]|" << KWD_PFX << keyword << "[=" << cmdarg->value_name()
  929. X!              << char(']') ;
  930. X        } else {
  931. X!          oss << OPT_PFX << optchar << cmdarg->value_name() << char('|')
  932. X!              << KWD_PFX << keyword << char('=') << cmdarg->value_name() ;
  933. X        }
  934. X        if ((level == VERBOSE_USAGE) && (cmdarg->syntax() & CmdArg::isLIST)) {
  935. X           oss << " ..." ;
  936. X--- 743,755 ----
  937. X         (cmdarg->syntax() & CmdArg::isVALSTICKY))
  938. X     {
  939. X        if (cmdarg->syntax() & CmdArg::isVALOPT) {
  940. X!          oss << OptionPrefix() << char(optchar) << char('[')
  941. X!              << cmdarg->value_name() << "]|" << KeywordPrefix(plus)
  942. X!              << keyword << "[=" << cmdarg->value_name() << char(']') ;
  943. X        } else {
  944. X!          oss << OptionPrefix() << optchar << cmdarg->value_name()
  945. X!              << char('|') << KeywordPrefix(plus) << keyword << char('=')
  946. X!              << cmdarg->value_name() ;
  947. X        }
  948. X        if ((level == VERBOSE_USAGE) && (cmdarg->syntax() & CmdArg::isLIST)) {
  949. X           oss << " ..." ;
  950. X***************
  951. X*** 743,758 ****
  952. X     if (! (cmdarg->syntax() & CmdArg::isPOS)) {
  953. X        switch(syntax) {
  954. X           case cmd_OPTS_ONLY :
  955. X!             oss << OPT_PFX << char(optchar) ;
  956. X              break ;
  957. X  
  958. X           case cmd_KWDS_ONLY :
  959. X!             oss << ((cmd_flags & KWDS_ONLY) ? OPT_PFX : KWD_PFX) << keyword ;
  960. X              break ;
  961. X  
  962. X           case cmd_BOTH :
  963. X!             oss << OPT_PFX << char(optchar) << char('|')
  964. X!                 << KWD_PFX << keyword ;
  965. X              break ;
  966. X  
  967. X           default :
  968. X--- 764,780 ----
  969. X     if (! (cmdarg->syntax() & CmdArg::isPOS)) {
  970. X        switch(syntax) {
  971. X           case cmd_OPTS_ONLY :
  972. X!             oss << OptionPrefix() << char(optchar) ;
  973. X              break ;
  974. X  
  975. X           case cmd_KWDS_ONLY :
  976. X!             oss << ((cmd_flags & KWDS_ONLY) ? OptionPrefix()
  977. X!                                             : KeywordPrefix(plus)) << keyword ;
  978. X              break ;
  979. X  
  980. X           case cmd_BOTH :
  981. X!             oss << OptionPrefix() << char(optchar) << char('|')
  982. X!                 << KeywordPrefix(plus) << keyword ;
  983. X              break ;
  984. X  
  985. X           default :
  986. X*** src/lib/usage.c.OLD    Fri Mar 26 10:51:13 1993
  987. X--- src/lib/usage.c    Mon Mar  1 10:48:48 1993
  988. X***************
  989. X*** 8,13 ****
  990. X--- 8,16 ----
  991. X  //
  992. X  // ^HISTORY:
  993. X  //    01/09/92    Brad Appleton    <brad@ssd.csd.harris.com>    Created
  994. X+ //
  995. X+ //    03/01/93    Brad Appleton    <brad@ssd.csd.harris.com>
  996. X+ //    - Added cmd_description field to CmdLine
  997. X  //-^^---------------------------------------------------------------------
  998. X  
  999. X  #include <iostream.h>
  1000. X***************
  1001. X*** 304,309 ****
  1002. X--- 307,319 ----
  1003. X     // now print argument descriptions
  1004. X     os << "\n" ;
  1005. X     print_descriptions(cmd_syntax, os, max_cols, longest) ;
  1006. X+ 
  1007. X+    // now print the command-description if there is one
  1008. X+    if (cmd_description && *cmd_description) {
  1009. X+       os << "\nDescription:" << endl;
  1010. X+       strindent(os, max_cols, 8, "", 0, cmd_description);
  1011. X+    }
  1012. X+ 
  1013. X     return  os;
  1014. X  }
  1015. X  
  1016. END_OF_FILE
  1017.   if test 31550 -ne `wc -c <'PATCH01.B'`; then
  1018.     echo shar: \"'PATCH01.B'\" unpacked with wrong size!
  1019.   elif test -f 'PATCH01.A' ; then
  1020.     echo shar: Combining  \"'PATCH01'\" \(68045 characters\)
  1021.     cat 'PATCH01.A' 'PATCH01.B' > 'PATCH01'
  1022.     if test 68045 -ne `wc -c <'PATCH01'`; then
  1023.       echo shar: \"'PATCH01'\" combined with wrong size!
  1024.     else 
  1025.       rm PATCH01.A PATCH01.B 
  1026.     fi 
  1027.   fi 
  1028.   # end of 'PATCH01.B'
  1029. fi
  1030. echo shar: End of archive 2 \(of 2\).
  1031. cp /dev/null ark2isdone
  1032. MISSING=""
  1033. for I in 1 2 ; do
  1034.     if test ! -f ark${I}isdone ; then
  1035.     MISSING="${MISSING} ${I}"
  1036.     fi
  1037. done
  1038. if test "${MISSING}" = "" ; then
  1039.     echo You have unpacked both archives.
  1040.     rm -f ark[1-9]isdone
  1041. else
  1042.     echo You still must unpack the following archives:
  1043.     echo "        " ${MISSING}
  1044. fi
  1045. exit 0
  1046. exit 0 # Just in case...
  1047.