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

  1. Newsgroups: comp.sources.misc
  2. From: brad@hcx1.ssd.csd.harris.com (Brad Appleton)
  3. Subject: v36i093:  cmdline - C++ Library for parsing command-line arguments, Patch01a/2
  4. Message-ID: <csm-v36i093=cmdline.125351@sparky.IMD.Sterling.COM>
  5. X-Md4-Signature: d5a29f9fc42655e644590ff4f9a878bf
  6. Date: Sun, 4 Apr 1993 17:54:42 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 93
  11. Archive-name: cmdline/patch01a
  12. Environment: C++
  13. Patch-To: cmdline: Volume 31, Issue 47-54
  14.  
  15. This is patch01 for the CmdLine C++ library and cmdparse command.
  16.  
  17. To apply this patch:
  18.  
  19. 1) cd to your "CmdLine" source directory
  20. 2) unshar this file by typing "sh name-of-this-file"
  21.    (this will create the file PATCH01)
  22. 3) type "patch -p0 <PATCH01"
  23.  
  24. The changes made in this patch are as follows:
  25.  
  26. - Made some more fixes to get the package to compile with g++.
  27.  
  28. - A description string may now be attached to a CmdLine object and it will
  29.   be printed (with the heading "Description:") as the last part of verbose
  30.   usage messages if the description-string is non-NULL and non-empty.
  31.  
  32. - Added a "sequence" to a CmdArg that indicates the relative order in
  33.   which the arguments appeared on the command line. Also added a member
  34.   to CmdLine that returns the number of valid arguments found (the sequence
  35.   of an argument will be zero if it was not given, otherwise it will be in
  36.   the range 1 .. #valid-args-parsed).
  37.  
  38. - Added a facility for programmers to setup their own parse-termination
  39.   handler so they can do something besides exit if they so desire.
  40.  
  41. - Added the ability to allow (at run-time) the use of "+" as the long-option
  42.   prefix (this could be done only at compile-time until now).
  43.  
  44. If you don't already have either Options or CmdLine sources, you can get 
  45. them from your nearest comp.sources.misc archive or you can e-mail me at
  46. brad@travis.csd.harris.com and I will send them to you.
  47.  
  48. For those of you that are unfamiliar with CmdLine and/or cmdparse,
  49. the description from the Overview file follows:
  50.  
  51.  
  52.  
  53.                     An overview of CmdLine and cmdparse
  54.                     ===================================
  55.  
  56.                  by Brad Appleton <brad@ssd.csd.harris.com>
  57.  
  58.  
  59.  Introduction
  60.  ------------
  61.  CmdLine is a C++ Library for parsing command-line arguments. It is 
  62.  approximately 2000 lines of C++ code (excluding comments).
  63.  
  64.  Cmdparse is a command-line interface to CmdLine for Unix shell-scripts.
  65.  It is approximately 1200 lines of C++ code (excluding comments).
  66.  
  67.  
  68.  CmdLine(3C++)
  69.  -------------
  70.  CmdLine is a set of classes to parse command-line arguments.  Unlike
  71.  getopt() and its variants, CmdLine does more than just split up the
  72.  command-line into some canonical form.  CmdLine will actually parse
  73.  the command-line, assigning the appropriate command-line values to
  74.  the corresponding variables, and will verify the command-line syntax
  75.  (and print a usage message if necessary) all in one member function
  76.  call.  Furthermore, many features of CmdLine's parsing behavior are
  77.  configurable at run-time.  These features include the following:
  78.  
  79.      o  Prompting the user for missing arguments.
  80.      o  Allowing keywords (-count=4) and/or options (-c4).
  81.      o  Ignoring bad syntax instead of terminating.
  82.      o  Ignoring upper/lower case on the command-line.
  83.      o  Suppressing the printing of syntax error messages.
  84.      o  Controlling the verboseness of usage messages.
  85.      o  Controlling whether or not options may be processed
  86.           after positional parameters have been seen.
  87.  
  88.  CmdLine also allows for options that take an optional argument, options
  89.  that take a (possibly optional) list of one or more arguments, sticky
  90.  options (options whose argument must reside in the same token as the
  91.  option itself), and options whose argument must reside in a separate
  92.  token from the option itself.
  93.  
  94.  CmdLine consists of a set of C++ classes to parse arguments from an
  95.  input source called a CmdLineArgIter (which is a base class for iterating
  96.  over arguments from an arbitrary input source).  Argument iterators are
  97.  defined for an argv[] array (with or without a corresponding argc), for
  98.  a string of tokens that are separated by a given set of delimiters, and
  99.  for an input-stream.  Users can easily extend CmdLine to parse arguments
  100.  from other input sources simply by creating their own argument iterator
  101.  classes derived from the CmdLineArgIter class defined in <cmdline.h>.
  102.  
  103.  Command-line arguments are themselves objects that contain a specific
  104.  command-line interface, and a function that performs the desired actions
  105.  when its corresponding argument is seen on the command line.  Predefined
  106.  command-line argument types (derived from the abstract class CmdArg in
  107.  <cmdline.h>) exist for boolean, integer, floating-point, character, and
  108.  string arguments, and for lists of integers, floats, and strings.  These
  109.  predefined subclasses of CmdArg may be found in <cmdargs.h>.  Users can
  110.  also create their own command-argument types on the fly by defining and
  111.  implementing an appropriate subclass of the CmdArg class.
  112.  
  113.  Using CmdLine is relatively easy - you need to construct your arguments,
  114.  your command-line, and your argument iterator.  Then all that is left to
  115.  do is call the "parse" member function of your CmdLine object.  The
  116.  following is a simple example:
  117.  
  118.     #include <stdlib.h>
  119.     #include <iostream.h>
  120.     #include <cmdargs.h>
  121.  
  122.     int  main(int argc, char * argv[])
  123.     {
  124.           // Declare arguments
  125.        CmdArgInt  count('c', "count", "number", "number of copies to print.");
  126.        CmdArgBool xflag('x', "xmode", "turn on 'x'-mode.");
  127.        CmdArgChar fdsep('s', "separator", "char", "field-separator to use.");
  128.        CmdArgStr  input("input-file",  "input file to read.");
  129.        CmdArgStrList  output("[output-file ...]",  "where to print output.");
  130.  
  131.           // Declare command object and its argument-iterator
  132.        CmdLine  cmd(*argv, &count, &xflag, &fdsep, &input, &output, NULL);
  133.        CmdArgvIter  arg_iter(--argc, ++argv);
  134.  
  135.           // Initialize arguments to appropriate default values.
  136.        count = 1;
  137.        xflag = 0;
  138.        fdsep = ',';
  139.  
  140.           // Parse arguments
  141.        cmd.parse(arg_iter);
  142.  
  143.           // Print arguments
  144.        cout << "count=" << count << endl ;
  145.        cout << "xflag=" << (xflag ? "ON" : "OFF") << endl ;
  146.        cout << "fdsep='" << (char) fdsep << "'" << endl ;
  147.        cout << "input=\"" << input << "\"" << endl ;
  148.        
  149.        for (int i = 0 ; i < output.count() ; i++) {
  150.           cout << "output[" << i << "]=" << output[i] << endl ;
  151.        }
  152.  
  153.        return  0;
  154.     }
  155.  
  156.  
  157.  The Unix command-line syntax for the above program would be as follows:
  158.  
  159.     Usage: progname [-c number] [-x] [-s char] input-file [output-file ...]
  160.  
  161.     Options/Arguments:
  162.             -c number        number of copies to print.
  163.             -x               turn on 'x'-mode.
  164.             -s char          field-separator to use.
  165.             input-file       input file to read.
  166.             output-file ...  where to print output.
  167.  
  168.  
  169.  The Unix command-line syntax using long-options (keywords) for the above
  170.  program would be as follows:
  171.  
  172.     Usage: progname [--count number] [--xmode] [--separator char]
  173.                     input-file [output-file ...]
  174.  
  175.     Options/Arguments:
  176.             --count number    number of copies to print.
  177.             --xmode           turn on 'x'-mode.
  178.             --separator char  field-separator to use.
  179.             input-file        input file to read.
  180.             output-file ...   where to print output.
  181.  
  182.  If desired, one can set a configuration flag at run-time to allow "+"
  183.  to also be recognized (in addition to "--") as a long-option prefix.
  184.  
  185.  By default, CmdLine allows both options and long-options to appear on the
  186.  command-line. You can instruct CmdLine to disallow one or the other however.
  187.  As an "extra", when options are disallowed, the "-" prefix is assumed to
  188.  denote a long-option instead of an option (hence either "-" or "--" denotes
  189.  a keyword in this case).  Using this feature, CmdLine can be used to supply
  190.  the type of long-option syntax that is now becoming quite popular in the
  191.  Unix world. Using this "new" syntax, the command-line syntax for the above
  192.  command would be the following:
  193.  
  194.     Usage: progname [-count number] [-xmode] [-separator char]
  195.                     input-file [output-file ...]
  196.  
  197.     Options/Arguments:
  198.             -count number    number of copies to print.
  199.             -xmode           turn on 'x'-mode.
  200.             -separator char  field-separator to use.
  201.             input-file       input file to read.
  202.             output-file ...  where to print output.
  203.  
  204.  
  205.  It should be mentioned that, when long-options are used, only a unique
  206.  prefix of the keyword needs to be given (and character-case is ignored).
  207.  Hence, in the above example, "-x", "-X", and "-xm" will match "-xmode".
  208.  
  209.  
  210.  cmdparse(1)
  211.  -----------
  212.  Using "cmdparse" is even easier than using CmdLine. You declare your
  213.  arguments in a string and then you invoke cmdparse with the command
  214.  line of your shell-script and cmdparse will output a script of variable
  215.  settings for you to evaluate.  The following is an example (using the
  216.  same arguments as in our sample program):
  217.  
  218.     #!/bin/sh
  219.     NAME="`/bin/basename $0`"
  220.  
  221.     ARGS='
  222.        ArgInt   count  "[c|count number]"    "number of copies to print."
  223.        ArgBool  xflag  "[x|xmode]"           "turn on x-mode."
  224.        ArgChar  fdsep  "[s|separator char]"  "field-separator to use."
  225.        ArgStr   input  "input-file"          "input file to read."
  226.        ArgStr   output "[output-file ...]"   "where to print output."
  227.     '
  228.  
  229.     if  cmdparse -shell=sh -decls="$ARGS" -- $NAME "$@" > tmp$$
  230.     then
  231.        . tmp$$
  232.        /bin/rm -f tmp$$
  233.     else
  234.        EXITVAL=$?
  235.        /bin/rm -f tmp$$
  236.        exit $EXITVAL
  237.     fi
  238.  
  239.     echo "xflag=" $xflag
  240.     echo "count=" $count
  241.     echo "fdsep=" $fdsep
  242.     echo "input=" $input
  243.     if [ "$output" ] ; then
  244.        echo "output=" $output
  245.     fi
  246.  
  247.  
  248.  Note that you declare the syntax of an argument differently for cmdparse
  249.  than for CmdLine. The syntax for a single argument for cmdparse looks like
  250.  the following:
  251.  
  252.     <arg-type>  <arg-name>  <syntax>  <description>
  253.  
  254.  Where <arg-type> is one of the following:
  255.  
  256.     ArgInt     --  an integer value (or list of values)
  257.     ArgFloat   --  a floating-point value (or list of values)
  258.     ArgChar    --  a character value (or list of values)
  259.     ArgStr     --  a string value (or list of values)
  260.     ArgBool    --  a boolean flag that is turned ON
  261.     ArgClear   --  a boolean flag that is turned OFF
  262.     ArgToggle  --  a boolean flag that is toggled
  263.     ArgUsage   --  print usage and exit
  264.     ArgDummy   --  a dummy argument
  265.  
  266.  If desired, the leading "Arg" portion may be omitted from the type-name.
  267.  
  268.  <arg-name> is simply the name of the variable in your script that you wish
  269.  to contain the resultant value from the command-line.  Any default value
  270.  must be assigned to the variable before invoking cmdparse.
  271.  
  272.  <syntax> and <description> *MUST* be enclosed in either single or double
  273.  quotes! <description> is simply that, the description of the argument.
  274.  
  275.  <syntax> is a little trickier, there are three basic forms of syntax:
  276.  
  277.    1)  "c|keyword"        -- an option the takes no value
  278.    2)  "c|keyword value"  -- an option that takes a value
  279.    3)  "value"            -- a positional parameter
  280.  
  281.  Note that the option-character MUST precede the keyword-name and that
  282.  there must be NO spaces surrounding the '|' in "c|keyword"!
  283.  
  284.  Any "optional" parts of the argument should appear inside square-brackets
  285.  ('[' and ']') and a list of values is denoted by an ellipsis (" ...").
  286.  Most options will be inside of square brackets to reflect the fact that
  287.  they are "optional".
  288.  
  289.  Some example <syntax> strings follow:
  290.  
  291.     "c|keyword"                -- a required option
  292.     "[c|keyword]"              -- an option with no value
  293.     "[c|keyword value]"        -- an option that takes a value
  294.     "[c|keyword [value]]"      -- an option that takes an optional value
  295.     "[c|keyword value ...]"    -- an option that takes 1 or more values
  296.     "[c|keyword [value ...]]"  -- an option that takes 0 or more values
  297.     "value"                    -- a required positional parameter
  298.     "[value]"                  -- an optional positional-parameter
  299.     "[c|keyword] value"        -- a required argument that may be matched
  300.                                   either positionally or by keyword!
  301.  
  302.  
  303.  Further Information
  304.  -------------------
  305.  This is just a brief overview of what the CmdLine package can do. Please
  306.  read the documentation for a more thorough explanation of this products'
  307.  capabilities and limitations!
  308.  
  309.  
  310. ______________________ "And miles to go before I sleep." ______________________
  311.  Brad Appleton                         Harris Corp., Computer Systems Division
  312.    Senior Software Engineer            2101 West Cypress Creek Road,  M/S 161 
  313.      brad@ssd.csd.harris.com           Fort Lauderdale, FL  33309-1892  USA
  314.        ...!uunet!travis!brad                 Phone: (305) 973-5190
  315. ~~~~~~~~~~~~~~~~~~~ Disclaimer: I said it, not my employer! ~~~~~~~~~~~~~~~~~~~
  316.  
  317. #! /bin/sh
  318. # This is a shell archive.  Remove anything before this line, then feed it
  319. # into a shell via "sh file" or similar.  To overwrite existing files,
  320. # type "sh file -c".
  321. # Contents:  PATCH01.A
  322. # Wrapped by kent@sparky on Sun Apr  4 12:46:49 1993
  323. PATH=/bin:/usr/bin:/usr/ucb:/usr/local/bin:/usr/lbin ; export PATH
  324. echo If this archive is complete, you will see the following message:
  325. echo '          "shar: End of archive 1 (of 2)."'
  326. if test -f 'PATCH01.A' -a "${1}" != "-c" ; then 
  327.   echo shar: Will not clobber existing file \"'PATCH01.A'\"
  328. else
  329.   echo shar: Extracting \"'PATCH01.A'\" \(36495 characters\)
  330.   sed "s/^X//" >'PATCH01.A' <<'END_OF_FILE'
  331. X*** Config.mk.OLD    Fri Mar 26 10:48:58 1993
  332. X--- Config.mk    Mon Mar  1 10:54:09 1993
  333. X***************
  334. X*** 73,79 ****
  335. X  CAT=cat
  336. X  
  337. X     ## maintain archives
  338. X! AR=ar -r
  339. X  
  340. X     ## maintain library archives
  341. X  RANLIB=ranlib
  342. X--- 73,79 ----
  343. X  CAT=cat
  344. X  
  345. X     ## maintain archives
  346. X! AR=ar r
  347. X  
  348. X     ## maintain library archives
  349. X  RANLIB=ranlib
  350. X***************
  351. X*** 164,170 ****
  352. X  DBG=-g
  353. X  
  354. X     ## option to indicate the name of the executable file
  355. X! EXE=-o
  356. X  
  357. X     ## option to suppress the loading phase
  358. X  NOLD=-c
  359. X--- 164,170 ----
  360. X  DBG=-g
  361. X  
  362. X     ## option to indicate the name of the executable file
  363. X! EXE=-o 
  364. X  
  365. X     ## option to suppress the loading phase
  366. X  NOLD=-c
  367. X***************
  368. X*** 183,198 ****
  369. X  FLAG=$(OPT)
  370. X  # FLAG=$(DBG)
  371. X  TESTDEFS=
  372. X! # USRDEFS=$(DEF)DEBUG_CMDLINE
  373. X  OPTIONS=
  374. X  
  375. X  #------------------------------------------------------------------------------
  376. X  # Define the macro to pass to recursive makes
  377. X  #
  378. X! RECUR= FLAG=$(FLAG) \
  379. X!    TESTDEFS=$(TESTDEFS) \
  380. X!    USRDEFS=$(USRDEFS) \
  381. X!    OPTIONS=$(OPTIONS)
  382. X  
  383. X  #------------------------------------------------------------------------------
  384. X  # Define the command for recursive makes
  385. X--- 183,198 ----
  386. X  FLAG=$(OPT)
  387. X  # FLAG=$(DBG)
  388. X  TESTDEFS=
  389. X! USRDEFS=$(DEF)DEBUG_CMDLINE
  390. X  OPTIONS=
  391. X  
  392. X  #------------------------------------------------------------------------------
  393. X  # Define the macro to pass to recursive makes
  394. X  #
  395. X! RECUR= "FLAG=$(FLAG)" \
  396. X!    "TESTDEFS=$(TESTDEFS)" \
  397. X!    "USRDEFS=$(USRDEFS)" \
  398. X!    "OPTIONS=$(OPTIONS)"
  399. X  
  400. X  #------------------------------------------------------------------------------
  401. X  # Define the command for recursive makes
  402. X*** MANIFEST.OLD    Fri Mar 26 10:49:02 1993
  403. X--- MANIFEST    Tue Mar 23 17:08:01 1993
  404. X***************
  405. X*** 3,9 ****
  406. X   Config.mk                  2    Make flags for the product
  407. X   MANIFEST                   1    This shipping list
  408. X   Makefile                   1    Makefile for the product
  409. X!  Overview                   3    A brief overview of the product
  410. X   README                     1    Read this file first
  411. X   doc                        1    Documentation directory
  412. X   doc/Makefile               1    Makefile for the documentation
  413. X--- 3,9 ----
  414. X   Config.mk                  2    Make flags for the product
  415. X   MANIFEST                   1    This shipping list
  416. X   Makefile                   1    Makefile for the product
  417. X!  Overview                   4    A brief overview of the product
  418. X   README                     1    Read this file first
  419. X   doc                        1    Documentation directory
  420. X   doc/Makefile               1    Makefile for the documentation
  421. X***************
  422. X*** 12,18 ****
  423. X   doc/classes.man            4    documents the basics of the most common classes
  424. X   doc/cmdargs.man3           2    documents <cmdargs.h>
  425. X   doc/cmdline.man3           2    documents <cmdline.h>
  426. X!  doc/cmdparse.man1          5    documents cmdparse(1)
  427. X   doc/environ.man            1    documents the use of environment variables
  428. X   doc/example.man            1    documents example use of CmdLine(3C++)
  429. X   doc/files.man              1    documents files used by CmdLine(3C++)
  430. X--- 12,18 ----
  431. X   doc/classes.man            4    documents the basics of the most common classes
  432. X   doc/cmdargs.man3           2    documents <cmdargs.h>
  433. X   doc/cmdline.man3           2    documents <cmdline.h>
  434. X!  doc/cmdparse.man1          6    documents cmdparse(1)
  435. X   doc/environ.man            1    documents the use of environment variables
  436. X   doc/example.man            1    documents example use of CmdLine(3C++)
  437. X   doc/files.man              1    documents files used by CmdLine(3C++)
  438. X***************
  439. X*** 27,33 ****
  440. X   src/cmd/cmdparse.c         6    the guts of the cmdparse program
  441. X   src/cmd/cmdparse.h         1    the specification of the cmdparse program
  442. X   src/cmd/cmdparse.pl        2    cmdparse for Perl programmers
  443. X!  src/cmd/cmdparse.tcl       1    cmdparse for Tcl programmers
  444. X   src/cmd/fsm.c              2    finite-state-machine for parsing arg-syntax
  445. X   src/cmd/fsm.h              1    finite-state-machine specification
  446. X   src/cmd/main.c             1    main program for cmdparse(1)
  447. X--- 27,33 ----
  448. X   src/cmd/cmdparse.c         6    the guts of the cmdparse program
  449. X   src/cmd/cmdparse.h         1    the specification of the cmdparse program
  450. X   src/cmd/cmdparse.pl        2    cmdparse for Perl programmers
  451. X!  src/cmd/cmdparse.tcl       2    cmdparse for Tcl programmers
  452. X   src/cmd/fsm.c              2    finite-state-machine for parsing arg-syntax
  453. X   src/cmd/fsm.h              1    finite-state-machine specification
  454. X   src/cmd/main.c             1    main program for cmdparse(1)
  455. X***************
  456. X*** 35,41 ****
  457. X   src/cmd/quoted.h           1    definition of a quoted-string class
  458. X   src/cmd/shell_arg.c        1    implementation of an abstract shell-script arg
  459. X   src/cmd/shell_arg.h        1    definition of an abstract shell-script argument
  460. X!  src/cmd/shells.c           4    implementation of command-interpreters
  461. X   src/cmd/shells.h           4    definitions of various command-interpreters
  462. X   src/cmd/syntax.c           4    implementation of an argument-syntax object
  463. X   src/cmd/syntax.h           1    definition of an argument-syntax object
  464. X--- 35,41 ----
  465. X   src/cmd/quoted.h           1    definition of a quoted-string class
  466. X   src/cmd/shell_arg.c        1    implementation of an abstract shell-script arg
  467. X   src/cmd/shell_arg.h        1    definition of an abstract shell-script argument
  468. X!  src/cmd/shells.c           5    implementation of command-interpreters
  469. X   src/cmd/shells.h           4    definitions of various command-interpreters
  470. X   src/cmd/syntax.c           4    implementation of an argument-syntax object
  471. X   src/cmd/syntax.h           1    definition of an argument-syntax object
  472. X***************
  473. X*** 45,51 ****
  474. X   src/lib/arglist.h          1    command argument list type definitions
  475. X   src/lib/cmdarg.c           3    implementation of base class CmdArg
  476. X   src/lib/cmdargs.c          5    implementation of the various argument types
  477. X!  src/lib/cmdargs.h          7    include file for the various argument types
  478. X   src/lib/cmdline.c          3    constructors/destructors for CmdLine objects
  479. X   src/lib/cmdline.h          7    include file for the library
  480. X   src/lib/cmdtest.c          3    test program for the library
  481. X--- 45,51 ----
  482. X   src/lib/arglist.h          1    command argument list type definitions
  483. X   src/lib/cmdarg.c           3    implementation of base class CmdArg
  484. X   src/lib/cmdargs.c          5    implementation of the various argument types
  485. X!  src/lib/cmdargs.h          8    include file for the various argument types
  486. X   src/lib/cmdline.c          3    constructors/destructors for CmdLine objects
  487. X   src/lib/cmdline.h          7    include file for the library
  488. X   src/lib/cmdtest.c          3    test program for the library
  489. X***************
  490. X*** 52,62 ****
  491. X   src/lib/dump.c             3    dumping/debugging member functions
  492. X   src/lib/exits.h            1    definition of exit codes used for exit(3C)
  493. X   src/lib/fifolist.c         1    implementation of a generic FIFO linked list
  494. X!  src/lib/fifolist.h         2    definition of a generic FIFO linked list
  495. X   src/lib/parse.c            2    public parsing functions for CmdLine
  496. X   src/lib/patchlevel.c       1    functions to return version information
  497. X   src/lib/private.c          5    private/protected functions for a CmdLine
  498. X   src/lib/states.h           1    state enumeration definitions
  499. X   src/lib/strindent.c        3    function to print a hanging indented paragraph
  500. X!  src/lib/unix.c             6    Unix specific parts of a CmdLine
  501. X   src/lib/usage.c            3    usage-message specific parts of a CmdLine
  502. X--- 52,62 ----
  503. X   src/lib/dump.c             3    dumping/debugging member functions
  504. X   src/lib/exits.h            1    definition of exit codes used for exit(3C)
  505. X   src/lib/fifolist.c         1    implementation of a generic FIFO linked list
  506. X!  src/lib/fifolist.h         3    definition of a generic FIFO linked list
  507. X   src/lib/parse.c            2    public parsing functions for CmdLine
  508. X   src/lib/patchlevel.c       1    functions to return version information
  509. X   src/lib/private.c          5    private/protected functions for a CmdLine
  510. X   src/lib/states.h           1    state enumeration definitions
  511. X   src/lib/strindent.c        3    function to print a hanging indented paragraph
  512. X!  src/lib/unix.c             7    Unix specific parts of a CmdLine
  513. X   src/lib/usage.c            3    usage-message specific parts of a CmdLine
  514. X*** Overview.OLD    Fri Mar 26 10:49:11 1993
  515. X--- Overview    Wed Mar  3 14:57:55 1993
  516. X***************
  517. X*** 37,46 ****
  518. X            after positional parameters have been seen.
  519. X  
  520. X   CmdLine also allows for options that take an optional argument, options
  521. X!  that take a (possibly optional) list of one or more arguments, options
  522. X!  whose argument must reside in the same token as the option itself, and
  523. X!  options whose argument must reside in a separate token from the option
  524. X!  itself.
  525. X  
  526. X   CmdLine consists of a set of C++ classes to parse arguments from an
  527. X   input source called a CmdLineArgIter (which is a base class for iterating
  528. X--- 37,46 ----
  529. X            after positional parameters have been seen.
  530. X  
  531. X   CmdLine also allows for options that take an optional argument, options
  532. X!  that take a (possibly optional) list of one or more arguments, sticky
  533. X!  options (options whose argument must reside in the same token as the
  534. X!  option itself), and options whose argument must reside in a separate
  535. X!  token from the option itself.
  536. X  
  537. X   CmdLine consists of a set of C++ classes to parse arguments from an
  538. X   input source called a CmdLineArgIter (which is a base class for iterating
  539. X***************
  540. X*** 130,135 ****
  541. X--- 130,137 ----
  542. X              input-file        input file to read.
  543. X              output-file ...   where to print output.
  544. X  
  545. X+  If desired, one can set a configuration flag at run-time to allow "+"
  546. X+  to also be recognized (in addition to "--") as a long-option prefix.
  547. X  
  548. X   By default, CmdLine allows both options and long-options to appear on the
  549. X   command-line. You can instruct CmdLine to disallow one or the other however.
  550. X***************
  551. X*** 210,216 ****
  552. X      ArgClear   --  a boolean flag that is turned OFF
  553. X      ArgToggle  --  a boolean flag that is toggled
  554. X      ArgUsage   --  print usage and exit
  555. X!     ArgDummy   -- a dummy argument
  556. X  
  557. X   If desired, the leading "Arg" portion may be omitted from the type-name.
  558. X  
  559. X--- 212,218 ----
  560. X      ArgClear   --  a boolean flag that is turned OFF
  561. X      ArgToggle  --  a boolean flag that is toggled
  562. X      ArgUsage   --  print usage and exit
  563. X!     ArgDummy   --  a dummy argument
  564. X  
  565. X   If desired, the leading "Arg" portion may be omitted from the type-name.
  566. X  
  567. X*** README.OLD    Fri Mar 26 10:49:15 1993
  568. X--- README    Wed Mar  3 14:47:09 1993
  569. X***************
  570. X*** 62,67 ****
  571. X--- 62,69 ----
  572. X   msdos           Needed for MS-DOS systems.
  573. X   os2             Needed for OS/2 Systems.
  574. X  
  575. X+  __gplusplus     Needed if you are using g++ as your C++ compiler.
  576. X+ 
  577. X   unix_style      (This is the default) Use this to have CmdLine parse
  578. X                   command-lines using traditional Unix command-line syntax.
  579. X  
  580. X***************
  581. X*** 68,75 ****
  582. X   vms_style       (Not yet supported) Use this to have CmdLine parse
  583. X                   command-lines using traditional VAX/VMS DCL syntax.
  584. X  
  585. X!  USE_PLUS        Makes CmdLine use "+" instead of "--" as the keyword prefix
  586. X!                  when -Dunix_style is used.
  587. X  
  588. X   DEBUG_CMDLINE   Enables use of the "dump" member functions in the CmdLine
  589. X                   library.
  590. X--- 70,77 ----
  591. X   vms_style       (Not yet supported) Use this to have CmdLine parse
  592. X                   command-lines using traditional VAX/VMS DCL syntax.
  593. X  
  594. X!  ibm_style       (Not yet supported) Use this to have CmdLine parse
  595. X!                  command-lines using traditional IBM-PC (MS-DOS) syntax.
  596. X  
  597. X   DEBUG_CMDLINE   Enables use of the "dump" member functions in the CmdLine
  598. X                   library.
  599. X***************
  600. X*** 154,156 ****
  601. X--- 156,189 ----
  602. X   -----------------------------------------------------------------------------
  603. X   First release.
  604. X  
  605. X+ 
  606. X+  11/13/92        Brad Appleton        <brad@ssd.csd.harris.com>
  607. X+  -----------------------------------------------------------------------------
  608. X+  Made some fixes to get the package to compile with g++ and Borland C++.
  609. X+ 
  610. X+ 
  611. X+  02/24/93        Brad Appleton        <brad@ssd.csd.harris.com>
  612. X+  -----------------------------------------------------------------------------
  613. X+  Made some more fixes to get the package to compile with g++.
  614. X+ 
  615. X+ 
  616. X+  03/03/93        Brad Appleton        <brad@ssd.csd.harris.com>
  617. X+  -----------------------------------------------------------------------------
  618. X+  Added a few new features:
  619. X+ 
  620. X+  - A description string may now be attached to a CmdLine object and it will
  621. X+    be printed (with the heading "Description:") as the last part of verbose
  622. X+    usage messages if the description-string is non-NULL and non-empty.
  623. X+ 
  624. X+  - Added a "sequence" to a CmdArg that indicates the relative order in
  625. X+    which the arguments appeared on the command line. Also added a member
  626. X+    to CmdLine that returns the number of valid arguments found (the sequence
  627. X+    of an argument will be zero if it was not given, otherwise it will be in
  628. X+    the range 1 .. #valid-args-parsed).
  629. X+ 
  630. X+  - Added a facility for programmers to setup their own parse-termination
  631. X+    handler so they can do something besides exit if they so desire.
  632. X+ 
  633. X+  - Added the ability to allow (at run-time) the use of "+" as the long-option
  634. X+    prefix (this could be done only at compile-time until now).
  635. X+    
  636. X*** doc/cmdparse.man1.OLD    Fri Mar 26 10:49:22 1993
  637. X--- doc/cmdparse.man1    Wed Mar  3 14:34:45 1993
  638. X***************
  639. X*** 20,25 ****
  640. X--- 20,26 ----
  641. X  [\fB\-noabort\fP]
  642. X  [\fB\-noguessing\fP]
  643. X  [\fB\-prompt\fP]
  644. X+ [\fB\-plus\fP]
  645. X  .if t .br
  646. X  [\fB\-options-only\fP]
  647. X  [\fB\-keywords-only\fP]
  648. X***************
  649. X*** 167,172 ****
  650. X--- 168,177 ----
  651. X  \fB\-prompt\fP
  652. X  Prompt the user interactively for any missing required arguments.
  653. X  .TP
  654. X+ \fB\-plus\fP
  655. X+ Allow the prefix ``+'' to be used to indicate a long-option.
  656. X+ (this may also be specified by saying \fB\-+\fP).
  657. X+ .TP
  658. X  \fB\-options-only\fP
  659. X  Don't match keywords (long-options).  Look only for single-character options.
  660. X  .TP
  661. X***************
  662. X*** 391,397 ****
  663. X  At present, \*(NM knows about the following shells:
  664. X  .RS
  665. X  .IP \fIsh\fP  6
  666. X! The Bourne Shell. This shell is the standard unix shell
  667. X  (designed and written by Stephen R. Bourne).
  668. X  .IP \fIcsh\fP  6
  669. X  The C Shell. Bill Joy's answer to \fIsh\fP using C-like syntax.
  670. X--- 396,402 ----
  671. X  At present, \*(NM knows about the following shells:
  672. X  .RS
  673. X  .IP \fIsh\fP  6
  674. X! The Bourne Shell. This shell is the standard Unix shell
  675. X  (designed and written by Stephen R. Bourne).
  676. X  .IP \fIcsh\fP  6
  677. X  The C Shell. Bill Joy's answer to \fIsh\fP using C-like syntax.
  678. X*** doc/parsing.man.OLD    Fri Mar 26 10:49:28 1993
  679. X--- doc/parsing.man    Wed Mar  3 14:34:32 1993
  680. X***************
  681. X*** 9,15 ****
  682. X  By default, \*(NM will allow both single-character options \fIand\fP
  683. X  keywords (long-options) to be matched on the command-line.
  684. X  Under Unix, a single character option is prefixed by the string ``\-''.
  685. X! and a long-option is prefixed by the string ``\*(--''.  If a token
  686. X  on the command-line exactly matches the string ``\*(--'', then all
  687. X  further matching of options (both long and short) are disabled and
  688. X  any remaining arguments are considered to be positional parameters
  689. X--- 9,17 ----
  690. X  By default, \*(NM will allow both single-character options \fIand\fP
  691. X  keywords (long-options) to be matched on the command-line.
  692. X  Under Unix, a single character option is prefixed by the string ``\-''.
  693. X! and a long-option is prefixed by the string ``\*(--''.
  694. X! (If desired, the string ``+'' may also be used as a long-option prefix
  695. X! by explicitly specifying the corresponding flag).  If a token
  696. X  on the command-line exactly matches the string ``\*(--'', then all
  697. X  further matching of options (both long and short) are disabled and
  698. X  any remaining arguments are considered to be positional parameters
  699. X***************
  700. X*** 17,26 ****
  701. X  
  702. X  If short-option processing is disabled, then the prefix ``\-'' may be used
  703. X  to indicate a long-option (the ``\*(--'' prefix will still be accepted).
  704. X- 
  705. X- If desired, the string ``+'' may be used as the long-option prefix
  706. X- instead of ``\*(--'' by defining the constant \s-1USE_PLUS\s+1 when
  707. X- building \f4CmdLine\fP.
  708. X  .RE
  709. X  
  710. X  .SS "OPTION MATCHING"
  711. X--- 19,24 ----
  712. X*** src/cmd/cmdparse.c.OLD    Fri Mar 26 10:49:36 1993
  713. X--- src/cmd/cmdparse.c    Wed Mar  3 14:09:57 1993
  714. X***************
  715. X*** 7,12 ****
  716. X--- 7,15 ----
  717. X  //
  718. X  // ^HISTORY:
  719. X  //    04/26/92    Brad Appleton    <brad@ssd.csd.harris.com>    Created
  720. X+ //
  721. X+ //    03/01/93    Brad Appleton    <brad@ssd.csd.harris.com>
  722. X+ //    - Added ALLOW_PLUS to list of CmdLine configuration flags
  723. X  //-^^---------------------------------------------------------------------
  724. X  
  725. X  #include <stdlib.h>
  726. X***************
  727. X*** 84,90 ****
  728. X  {
  729. X     cerr << cmd.name() << "\trelease " << cmd.release()
  730. X          << " at patchlevel " << cmd.patchlevel() << endl ;
  731. X!    ::exit(e_VERSION);
  732. X     return  0;  // shutup the compiler about not returning a value
  733. X  }
  734. X  
  735. X--- 87,93 ----
  736. X  {
  737. X     cerr << cmd.name() << "\trelease " << cmd.release()
  738. X          << " at patchlevel " << cmd.patchlevel() << endl ;
  739. X!    cmd.quit(e_VERSION);
  740. X     return  0;  // shutup the compiler about not returning a value
  741. X  }
  742. X  
  743. X***************
  744. X*** 566,571 ****
  745. X--- 569,577 ----
  746. X       prompt('p', "prompt",
  747. X          "Prompt the user interactively for any missing required arguments."
  748. X       ),
  749. X+      plus('+', "plus",
  750. X+         "Allow the string \"+\" to be used as a long-option prefix."
  751. X+      ),
  752. X       opts_only('o', "options-only",
  753. X          "Dont match keywords (long-options)."
  754. X       ),
  755. X***************
  756. X*** 617,627 ****
  757. X          (CmdArg::isPOS | CmdArg::isREQ | CmdArg::isVALREQ)
  758. X       ),
  759. X       usr_args("[arguments ...]",
  760. X!         "The program-arguments to be parsed",
  761. X       )
  762. X  {
  763. X        // Append options.
  764. X!    (*this) << anywhere << anycase << no_abort << no_guessing << prompt
  765. X             << opts_only << kwds_only << quiet << array_variant << usage
  766. X             << version << true_str << false_str << suffix_str << usr_shell
  767. X             << input_file << input_var << input_str << dummy_arg ;
  768. X--- 623,633 ----
  769. X          (CmdArg::isPOS | CmdArg::isREQ | CmdArg::isVALREQ)
  770. X       ),
  771. X       usr_args("[arguments ...]",
  772. X!         "The program-arguments to be parsed"
  773. X       )
  774. X  {
  775. X        // Append options.
  776. X!    (*this) << anywhere << anycase << no_abort << no_guessing << prompt << plus
  777. X             << opts_only << kwds_only << quiet << array_variant << usage
  778. X             << version << true_str << false_str << suffix_str << usr_shell
  779. X             << input_file << input_var << input_str << dummy_arg ;
  780. X***************
  781. X*** 713,718 ****
  782. X--- 719,725 ----
  783. X     if (no_abort)     usr_cmd.set(CmdLine::NO_ABORT);
  784. X     if (no_guessing)  usr_cmd.set(CmdLine::NO_GUESSING);
  785. X     if (prompt)       usr_cmd.set(CmdLine::PROMPT_USER);
  786. X+    if (plus)         usr_cmd.set(CmdLine::ALLOW_PLUS);
  787. X     if (opts_only)    usr_cmd.set(CmdLine::OPTS_ONLY);
  788. X     if (kwds_only)    usr_cmd.set(CmdLine::KWDS_ONLY);
  789. X     if (quiet)        usr_cmd.set(CmdLine::QUIET);
  790. X*** src/cmd/cmdparse.h.OLD    Fri Mar 26 10:49:41 1993
  791. X--- src/cmd/cmdparse.h    Wed Mar  3 14:08:06 1993
  792. X***************
  793. X*** 7,12 ****
  794. X--- 7,15 ----
  795. X  //
  796. X  // ^HISTORY:
  797. X  //    05/01/92    Brad Appleton    <brad@ssd.csd.harris.com>    Created
  798. X+ //
  799. X+ //    03/01/93    Brad Appleton    <brad@ssd.csd.harris.com>
  800. X+ //    - Added ALLOW_PLUS to list of CmdLine configuration flags
  801. X  //-^^---------------------------------------------------------------------
  802. X  
  803. X  #ifndef _cmdparse_h
  804. X***************
  805. X*** 87,92 ****
  806. X--- 90,96 ----
  807. X     CmdArgBool     no_abort;         // set NO_ABORT
  808. X     CmdArgBool     no_guessing;      // set NO_GUESSING
  809. X     CmdArgBool     prompt;           // set PROMPT_USER
  810. X+    CmdArgBool     plus;             // set ALLOW_PLUS
  811. X     CmdArgBool     opts_only;        // set OPTS_ONLY
  812. X     CmdArgBool     kwds_only;        // set KWDS_ONLY
  813. X     CmdArgBool     quiet;            // set QUIET
  814. X*** src/lib/argiter.c.OLD    Fri Mar 26 10:49:57 1993
  815. X--- src/lib/argiter.c    Tue Mar 23 17:00:10 1993
  816. X***************
  817. X*** 94,107 ****
  818. X  
  819. X  //-------------------------------------------------------- class CmdIstreamIter
  820. X  
  821. X! static const unsigned  MAX_LINE_LEN = 1024 ;
  822. X  
  823. X- #ifdef vms
  824. X-    enum { c_COMMENT = '!' } ;
  825. X- #else
  826. X-    enum { c_COMMENT = '#' } ;
  827. X- #endif
  828. X- 
  829. X     // Constructor
  830. X  CmdIstreamIter::CmdIstreamIter(istream & input) : is(input), tok_iter(NULL)
  831. X  {
  832. X--- 94,101 ----
  833. X  
  834. X  //-------------------------------------------------------- class CmdIstreamIter
  835. X  
  836. X! const unsigned  CmdIstreamIter::MAX_LINE_LEN = 1024 ;
  837. X  
  838. X     // Constructor
  839. X  CmdIstreamIter::CmdIstreamIter(istream & input) : is(input), tok_iter(NULL)
  840. X  {
  841. X***************
  842. X*** 129,141 ****
  843. X     if (result)  return  result;
  844. X     if (! is)  return  NULL;
  845. X  
  846. X!    char buf[MAX_LINE_LEN];
  847. X     do {
  848. X        *buf = '\0';
  849. X        is.getline(buf, sizeof(buf));
  850. X        char * ptr = buf;
  851. X        while (isspace(*ptr)) ++ptr;
  852. X!       if (*ptr && (*ptr != c_COMMENT)) {
  853. X           if (tok_iter) {
  854. X              tok_iter->reset(ptr);
  855. X           } else {
  856. X--- 123,135 ----
  857. X     if (result)  return  result;
  858. X     if (! is)  return  NULL;
  859. X  
  860. X!    char buf[CmdIstreamIter::MAX_LINE_LEN];
  861. X     do {
  862. X        *buf = '\0';
  863. X        is.getline(buf, sizeof(buf));
  864. X        char * ptr = buf;
  865. X        while (isspace(*ptr)) ++ptr;
  866. X!       if (*ptr && (*ptr != CmdIstreamIter::c_COMMENT)) {
  867. X           if (tok_iter) {
  868. X              tok_iter->reset(ptr);
  869. X           } else {
  870. X*** src/lib/cmdarg.c.OLD    Fri Mar 26 10:50:03 1993
  871. X--- src/lib/cmdarg.c    Mon Mar  1 10:31:54 1993
  872. X***************
  873. X*** 7,12 ****
  874. X--- 7,15 ----
  875. X  //
  876. X  // ^HISTORY:
  877. X  //    03/25/92    Brad Appleton    <brad@ssd.csd.harris.com>    Created
  878. X+ //
  879. X+ //    03/01/93    Brad Appleton    <brad@ssd.csd.harris.com>
  880. X+ //    - Added arg_sequence field to CmdArg
  881. X  //-^^---------------------------------------------------------------------
  882. X  
  883. X  #include <stdlib.h>
  884. X***************
  885. X*** 22,34 ****
  886. X  
  887. X     // Copy-Constructor
  888. X  CmdArg::CmdArg(const CmdArg & cp)
  889. X!    : arg_char_name(cp.arg_char_name),
  890. X       arg_keyword_name(cp.arg_keyword_name),
  891. X       arg_value_name(cp.arg_value_name),
  892. X!      alloc_value_name(cp.alloc_value_name),
  893. X!      arg_syntax(cp.arg_syntax),
  894. X!      arg_description(cp.arg_description),
  895. X!      arg_flags(cp.arg_flags)
  896. X  {
  897. X     if (alloc_value_name) {
  898. X        char * val_name = new char[::strlen(cp.arg_value_name) + 1] ;
  899. X--- 25,38 ----
  900. X  
  901. X     // Copy-Constructor
  902. X  CmdArg::CmdArg(const CmdArg & cp)
  903. X!    : alloc_value_name(cp.alloc_value_name),
  904. X!      arg_flags(cp.arg_flags),
  905. X!      arg_syntax(cp.arg_syntax),
  906. X!      arg_sequence(cp.arg_sequence),
  907. X!      arg_char_name(cp.arg_char_name),
  908. X       arg_keyword_name(cp.arg_keyword_name),
  909. X       arg_value_name(cp.arg_value_name),
  910. X!      arg_description(cp.arg_description)
  911. X  {
  912. X     if (alloc_value_name) {
  913. X        char * val_name = new char[::strlen(cp.arg_value_name) + 1] ;
  914. X***************
  915. X*** 44,55 ****
  916. X                 const char * value,
  917. X                 const char * description,
  918. X                 unsigned     syntax_flags)
  919. X!    : arg_char_name(optchar),
  920. X!      arg_keyword_name(keyword),
  921. X!      arg_value_name(value), alloc_value_name(0),
  922. X       arg_syntax(syntax_flags),
  923. X!      arg_description(description),
  924. X!      arg_flags(0)
  925. X  {
  926. X     parse_description();
  927. X     parse_value();
  928. X--- 48,61 ----
  929. X                 const char * value,
  930. X                 const char * description,
  931. X                 unsigned     syntax_flags)
  932. X!    : alloc_value_name(0),
  933. X!      arg_flags(0),
  934. X       arg_syntax(syntax_flags),
  935. X!      arg_sequence(0),
  936. X!      arg_char_name(optchar),
  937. X!      arg_keyword_name(keyword),
  938. X!      arg_value_name(value),
  939. X!      arg_description(description)
  940. X  {
  941. X     parse_description();
  942. X     parse_value();
  943. X***************
  944. X*** 61,72 ****
  945. X                 const char * keyword,
  946. X                 const char * description,
  947. X                 unsigned     syntax_flags)
  948. X!    : arg_char_name(optchar),
  949. X!      arg_keyword_name(keyword),
  950. X!      arg_value_name(NULL), alloc_value_name(0),
  951. X       arg_syntax(syntax_flags),
  952. X!      arg_description(description),
  953. X!      arg_flags(0)
  954. X  {
  955. X     parse_description();
  956. X     adjust_syntax();
  957. X--- 67,80 ----
  958. X                 const char * keyword,
  959. X                 const char * description,
  960. X                 unsigned     syntax_flags)
  961. X!    : alloc_value_name(0),
  962. X!      arg_flags(0),
  963. X       arg_syntax(syntax_flags),
  964. X!      arg_sequence(0),
  965. X!      arg_char_name(optchar),
  966. X!      arg_keyword_name(keyword),
  967. X!      arg_value_name(NULL),
  968. X!      arg_description(description)
  969. X  {
  970. X     parse_description();
  971. X     adjust_syntax();
  972. X***************
  973. X*** 76,87 ****
  974. X  CmdArg::CmdArg(const char * value,
  975. X                 const char * description,
  976. X                 unsigned     syntax_flags)
  977. X!    : arg_char_name(0),
  978. X!      arg_keyword_name(NULL),
  979. X!      arg_value_name(value), alloc_value_name(0),
  980. X       arg_syntax(syntax_flags),
  981. X!      arg_description(description),
  982. X!      arg_flags(0)
  983. X  {
  984. X     parse_description();
  985. X     parse_value();
  986. X--- 84,97 ----
  987. X  CmdArg::CmdArg(const char * value,
  988. X                 const char * description,
  989. X                 unsigned     syntax_flags)
  990. X!    : alloc_value_name(0),
  991. X!      arg_flags(0),
  992. X       arg_syntax(syntax_flags),
  993. X!      arg_sequence(0),
  994. X!      arg_char_name(0),
  995. X!      arg_keyword_name(NULL),
  996. X!      arg_value_name(value),
  997. X!      arg_description(description)
  998. X  {
  999. X     parse_description();
  1000. X     parse_value();
  1001. X*** src/lib/cmdargs.c.OLD    Fri Mar 26 10:50:09 1993
  1002. X--- src/lib/cmdargs.c    Wed Mar  3 10:01:29 1993
  1003. X***************
  1004. X*** 7,12 ****
  1005. X--- 7,15 ----
  1006. X  //
  1007. X  // ^HISTORY:
  1008. X  //    03/25/92    Brad Appleton    <brad@ssd.csd.harris.com>    Created
  1009. X+ //
  1010. X+ //    03/03/93    Brad Appleton    <brad@ssd.csd.harris.com>
  1011. X+ //    - Added exit_handler() and quit() member-functions to CmdLine
  1012. X  //-^^---------------------------------------------------------------------
  1013. X  
  1014. X  #include <stdlib.h>
  1015. X***************
  1016. X*** 110,117 ****
  1017. X  CmdArgUsage::operator()(const char * & , CmdLine & cmd)
  1018. X  {
  1019. X     cmd.usage(cmd.error(CmdLine::NOPRINT), CmdLine::VERBOSE_USAGE);
  1020. X!    ::exit(e_USAGE);
  1021. X!    return  SUCCESS;  // get the compiler to shut up about NO return value!
  1022. X  }
  1023. X  
  1024. X  //----------------------------------------------------------- Integer Arguments
  1025. X--- 113,120 ----
  1026. X  CmdArgUsage::operator()(const char * & , CmdLine & cmd)
  1027. X  {
  1028. X     cmd.usage(cmd.error(CmdLine::NOPRINT), CmdLine::VERBOSE_USAGE);
  1029. X!    cmd.quit(e_USAGE);
  1030. X!    return  SUCCESS;
  1031. X  }
  1032. X  
  1033. X  //----------------------------------------------------------- Integer Arguments
  1034. X***************
  1035. X*** 266,283 ****
  1036. X  
  1037. X  //------------------------------------------------------------ String Arguments
  1038. X  
  1039. X! typedef  CmdArgStrCompiler::string  CmdArgString ;
  1040. X  
  1041. X! CmdArgString::~string(void)
  1042. X  {
  1043. X     if (is_alloc)  delete [] (char *)str;
  1044. X  }
  1045. X  
  1046. X     // Copy a string (allocating storage if necessary)
  1047. X  void
  1048. X  CmdArgString::copy(unsigned  is_temporary, const char * s)
  1049. X  {
  1050. X!    if (is_alloc)  delete  (char *)str;
  1051. X     is_alloc = (is_temporary) ? 1 : 0;
  1052. X     str = s;
  1053. X     if (is_alloc && s) {
  1054. X--- 269,288 ----
  1055. X  
  1056. X  //------------------------------------------------------------ String Arguments
  1057. X  
  1058. X! typedef  CmdArgStrCompiler::casc_string  CmdArgString ;
  1059. X  
  1060. X! #ifndef __gplusplus
  1061. X! CmdArgString::~casc_string(void)
  1062. X  {
  1063. X     if (is_alloc)  delete [] (char *)str;
  1064. X  }
  1065. X+ #endif 
  1066. X  
  1067. X     // Copy a string (allocating storage if necessary)
  1068. X  void
  1069. X  CmdArgString::copy(unsigned  is_temporary, const char * s)
  1070. X  {
  1071. X!    if (is_alloc)  delete [] (char *)str;
  1072. X     is_alloc = (is_temporary) ? 1 : 0;
  1073. X     str = s;
  1074. X     if (is_alloc && s) {
  1075. X***************
  1076. X*** 315,321 ****
  1077. X  }
  1078. X  
  1079. X  ostream &
  1080. X! operator<<(ostream & os, const CmdArgStrCompiler::string & str)
  1081. X  {
  1082. X     return  (os << str.str) ;
  1083. X  }
  1084. X--- 320,326 ----
  1085. X  }
  1086. X  
  1087. X  ostream &
  1088. X! operator<<(ostream & os, const CmdArgStrCompiler::casc_string & str)
  1089. X  {
  1090. X     return  (os << str.str) ;
  1091. X  }
  1092. X*** src/lib/cmdargs.h.OLD    Fri Mar 26 10:50:15 1993
  1093. X--- src/lib/cmdargs.h    Thu Feb 25 14:19:53 1993
  1094. X***************
  1095. X*** 435,467 ****
  1096. X     // type that make it unnecessary to know the difference between
  1097. X     // it and a "char *" (in most cases).
  1098. X     //
  1099. X!    struct  string {
  1100. X        unsigned     is_alloc : 1 ;
  1101. X        const char * str ;
  1102. X  
  1103. X!       string(void) : is_alloc(0), str(0) {}
  1104. X  
  1105. X!       string(const char * s) : is_alloc(0), str(s) {}
  1106. X  
  1107. X        void
  1108. X        copy(unsigned  is_temporary, const char * s);
  1109. X  
  1110. X!       string(unsigned  is_temporary, const char * s)
  1111. X           : is_alloc(0), str(0) { copy(is_temporary, s); }
  1112. X  
  1113. X!       string(const string & cp)
  1114. X           : is_alloc(0), str(0) { copy(cp.is_alloc, cp.str); }
  1115. X  
  1116. X!       string &
  1117. X!       operator=(const string & cp)
  1118. X           { copy(cp.is_alloc, cp.str); return *this; }
  1119. X  
  1120. X!       string &
  1121. X        operator=(const char * cp) { copy(0, cp); return *this; }
  1122. X  
  1123. X        operator const char*(void)  const { return  str; }
  1124. X  
  1125. X!       virtual ~string(void);
  1126. X     } ;
  1127. X  
  1128. X     CmdArgStrCompiler(char         optchar,
  1129. X--- 435,471 ----
  1130. X     // type that make it unnecessary to know the difference between
  1131. X     // it and a "char *" (in most cases).
  1132. X     //
  1133. X!    struct  casc_string {
  1134. X        unsigned     is_alloc : 1 ;
  1135. X        const char * str ;
  1136. X  
  1137. X!       casc_string(void) : is_alloc(0), str(0) {}
  1138. X  
  1139. X!       casc_string(const char * s) : is_alloc(0), str(s) {}
  1140. X  
  1141. X        void
  1142. X        copy(unsigned  is_temporary, const char * s);
  1143. X  
  1144. X!       casc_string(unsigned  is_temporary, const char * s)
  1145. X           : is_alloc(0), str(0) { copy(is_temporary, s); }
  1146. X  
  1147. X!       casc_string(const casc_string & cp)
  1148. X           : is_alloc(0), str(0) { copy(cp.is_alloc, cp.str); }
  1149. X  
  1150. X!       casc_string &
  1151. X!       operator=(const casc_string & cp)
  1152. X           { copy(cp.is_alloc, cp.str); return *this; }
  1153. X  
  1154. X!       casc_string &
  1155. X        operator=(const char * cp) { copy(0, cp); return *this; }
  1156. X  
  1157. X        operator const char*(void)  const { return  str; }
  1158. X  
  1159. X!       virtual ~casc_string(void)
  1160. X! #ifdef __gplusplus
  1161. X!          { if (is_alloc)   delete [] (char *) str; }
  1162. X! #endif
  1163. X!       ;
  1164. X     } ;
  1165. X  
  1166. X     CmdArgStrCompiler(char         optchar,
  1167. X***************
  1168. X*** 486,492 ****
  1169. X     operator()(const char * & arg, CmdLine & cmd) = 0;
  1170. X  
  1171. X     int
  1172. X!    compile(const char * & arg, CmdLine & cmd, string & value) ;
  1173. X  } ;
  1174. X  
  1175. X  
  1176. X--- 490,496 ----
  1177. X     operator()(const char * & arg, CmdLine & cmd) = 0;
  1178. X  
  1179. X     int
  1180. X!    compile(const char * & arg, CmdLine & cmd, casc_string & value) ;
  1181. X  } ;
  1182. X  
  1183. X  
  1184. X***************
  1185. X*** 540,561 ****
  1186. X     operator=(const CmdArgStr & cp)  { val = cp.val; return  *this; }
  1187. X  
  1188. X     CmdArgStr &
  1189. X!    operator=(const CmdArgStrCompiler::string & cp)
  1190. X        { val = cp; return  *this; }
  1191. X  
  1192. X     CmdArgStr &
  1193. X     operator=(const char * cp)  { val = cp; return  *this; }
  1194. X  
  1195. X!    operator CmdArgStrCompiler::string(void)  { return  val; }
  1196. X  
  1197. X     operator const char*(void)  const { return  val.str; }
  1198. X  
  1199. X  private:
  1200. X!    CmdArgStrCompiler::string  val;
  1201. X  } ;
  1202. X  
  1203. X  ostream &
  1204. X! operator<<(ostream & os, const CmdArgStrCompiler::string & str);
  1205. X  
  1206. X  ostream &
  1207. X  operator<<(ostream & os, const CmdArgStr & str_arg);
  1208. X--- 544,568 ----
  1209. X     operator=(const CmdArgStr & cp)  { val = cp.val; return  *this; }
  1210. X  
  1211. X     CmdArgStr &
  1212. X!    operator=(const CmdArgStrCompiler::casc_string & cp)
  1213. X        { val = cp; return  *this; }
  1214. X  
  1215. X     CmdArgStr &
  1216. X     operator=(const char * cp)  { val = cp; return  *this; }
  1217. X  
  1218. X!    operator CmdArgStrCompiler::casc_string(void)  { return  val; }
  1219. X  
  1220. X     operator const char*(void)  const { return  val.str; }
  1221. X  
  1222. X+    // use this for comparing to NULL
  1223. X+    int isNULL(void) const { return (val.str) ? 0 : 1; }
  1224. X+ 
  1225. X  private:
  1226. X!    CmdArgStrCompiler::casc_string  val;
  1227. X  } ;
  1228. X  
  1229. X  ostream &
  1230. X! operator<<(ostream & os, const CmdArgStrCompiler::casc_string & str);
  1231. X  
  1232. X  ostream &
  1233. X  operator<<(ostream & os, const CmdArgStr & str_arg);
  1234. X***************
  1235. X*** 699,705 ****
  1236. X     unsigned
  1237. X     count(void) const;
  1238. X  
  1239. X!    CmdArgStrCompiler::string &
  1240. X     operator[](unsigned  index);
  1241. X  
  1242. X  private:
  1243. X--- 706,712 ----
  1244. X     unsigned
  1245. X     count(void) const;
  1246. X  
  1247. X!    CmdArgStrCompiler::casc_string &
  1248. X     operator[](unsigned  index);
  1249. X  
  1250. X  private:
  1251. X*** src/lib/cmdline.c.OLD    Fri Mar 26 10:50:21 1993
  1252. X--- src/lib/cmdline.c    Wed Mar  3 14:40:15 1993
  1253. X***************
  1254. X*** 13,18 ****
  1255. X--- 13,23 ----
  1256. X  //
  1257. X  // ^HISTORY:
  1258. X  //    03/21/92    Brad Appleton    <brad@ssd.csd.harris.com>    Created
  1259. X+ //
  1260. X+ //    03/01/93    Brad Appleton    <brad@ssd.csd.harris.com>
  1261. X+ //    - Added cmd_nargs_parsed field to CmdLine
  1262. X+ //    - Added cmd_description field to CmdLine
  1263. X+ //    - Added exit_handler() and quit() member-functions to CmdLine
  1264. X  //-^^---------------------------------------------------------------------
  1265. X  
  1266. X  #include <stdlib.h>
  1267. X***************
  1268. X*** 127,136 ****
  1269. X  
  1270. X  #if (defined(vms) || defined(msdos) || defined(os2))
  1271. X     const char * start, * p1, * p2 ;
  1272. X!    const char * str, * ext;
  1273. X  
  1274. X  # ifdef vms
  1275. X!    const char * ver;
  1276. X     // remove leading directory and/or device name
  1277. X     p1 = ::strrchr(filename, ':');
  1278. X     p2 = ::strrchr(filename, ']');
  1279. X--- 132,141 ----
  1280. X  
  1281. X  #if (defined(vms) || defined(msdos) || defined(os2))
  1282. X     const char * start, * p1, * p2 ;
  1283. X!    char * str, * ext;
  1284. X  
  1285. X  # ifdef vms
  1286. X!    char * ver;
  1287. X     // remove leading directory and/or device name
  1288. X     p1 = ::strrchr(filename, ':');
  1289. X     p2 = ::strrchr(filename, ']');
  1290. X***************
  1291. X*** 154,165 ****
  1292. X  
  1293. X     // remove the extension
  1294. X     ext = ::strrchr(str, '.');
  1295. X!    if (ext)  *ext = '0' ;
  1296. X  
  1297. X  # ifdef vms
  1298. X     // remove the version
  1299. X     ver = ::strrchr(str, ';');
  1300. X!    if (ver)  *ver = '0' ;
  1301. X  # endif
  1302. X  
  1303. X     return  str ;
  1304. X--- 159,170 ----
  1305. X  
  1306. X     // remove the extension
  1307. X     ext = ::strrchr(str, '.');
  1308. X!    if (ext)  *ext = '\0' ;
  1309. X  
  1310. X  # ifdef vms
  1311. X     // remove the version
  1312. X     ver = ::strrchr(str, ';');
  1313. X!    if (ver)  *ver = '\0' ;
  1314. X  # endif
  1315. X  
  1316. X     return  str ;
  1317. X***************
  1318. X*** 181,190 ****
  1319. X       cmd_state(cmd_START_STATE),
  1320. X       cmd_flags(DEFAULT_CMDFLAGS),
  1321. X       cmd_status(CmdLine::NO_ERROR),
  1322. X       cmd_name(NULL),
  1323. X       cmd_matched_arg(NULL),
  1324. X       cmd_args(NULL),
  1325. X!      cmd_err(NULL)
  1326. X  {
  1327. X     name(cmdname);
  1328. X     ::init_args(cmd_args);
  1329. X--- 186,198 ----
  1330. X       cmd_state(cmd_START_STATE),
  1331. X       cmd_flags(DEFAULT_CMDFLAGS),
  1332. X       cmd_status(CmdLine::NO_ERROR),
  1333. X+      cmd_nargs_parsed(0),
  1334. X       cmd_name(NULL),
  1335. X+      cmd_description(NULL),
  1336. X       cmd_matched_arg(NULL),
  1337. X       cmd_args(NULL),
  1338. X!      cmd_err(NULL),
  1339. X!      cmd_quit_handler(NULL)
  1340. X  {
  1341. X     name(cmdname);
  1342. X     ::init_args(cmd_args);
  1343. X***************
  1344. X*** 196,205 ****
  1345. X       cmd_state(cmd_START_STATE),
  1346. X       cmd_flags(DEFAULT_CMDFLAGS),
  1347. X       cmd_status(CmdLine::NO_ERROR),
  1348. X       cmd_name(NULL),
  1349. X       cmd_matched_arg(NULL),
  1350. X       cmd_args(NULL),
  1351. X!      cmd_err(NULL)
  1352. X  {
  1353. X     name(cmdname);
  1354. X     ::init_args(cmd_args);
  1355. X--- 204,216 ----
  1356. X       cmd_state(cmd_START_STATE),
  1357. X       cmd_flags(DEFAULT_CMDFLAGS),
  1358. X       cmd_status(CmdLine::NO_ERROR),
  1359. X+      cmd_nargs_parsed(0),
  1360. X       cmd_name(NULL),
  1361. X+      cmd_description(NULL),
  1362. X       cmd_matched_arg(NULL),
  1363. X       cmd_args(NULL),
  1364. X!      cmd_err(NULL),
  1365. X!      cmd_quit_handler(NULL)
  1366. X  {
  1367. X     name(cmdname);
  1368. X     ::init_args(cmd_args);
  1369. X***************
  1370. X*** 222,231 ****
  1371. X       cmd_state(cmd_START_STATE),
  1372. X       cmd_flags(DEFAULT_CMDFLAGS),
  1373. X       cmd_status(CmdLine::NO_ERROR),
  1374. X       cmd_name(NULL),
  1375. X       cmd_matched_arg(NULL),
  1376. X       cmd_args(NULL),
  1377. X!      cmd_err(NULL)
  1378. X  {
  1379. X     if (cmdarg == NULL)  return;
  1380. X     ::init_args(cmd_args);
  1381. X--- 233,245 ----
  1382. X       cmd_state(cmd_START_STATE),
  1383. X       cmd_flags(DEFAULT_CMDFLAGS),
  1384. X       cmd_status(CmdLine::NO_ERROR),
  1385. X+      cmd_nargs_parsed(0),
  1386. X       cmd_name(NULL),
  1387. X+      cmd_description(NULL),
  1388. X       cmd_matched_arg(NULL),
  1389. X       cmd_args(NULL),
  1390. X!      cmd_err(NULL),
  1391. X!      cmd_quit_handler(NULL)
  1392. X  {
  1393. X     if (cmdarg == NULL)  return;
  1394. X     ::init_args(cmd_args);
  1395. X***************
  1396. X*** 271,277 ****
  1397. X  ostream &
  1398. X  CmdLine::error(int  print) const
  1399. X  {
  1400. X!    ostream * os = (cmd_err) ? (ostream *)cmd_err : &cerr ;
  1401. X     if (print && cmd_name && *cmd_name)  *os << cmd_name << ": " ;
  1402. X     return  *os;
  1403. X  }
  1404. X--- 285,291 ----
  1405. X  ostream &
  1406. X  CmdLine::error(int  print) const
  1407. X  {
  1408. X!    ostream * os = (cmd_err) ? cmd_err : &cerr ;
  1409. X     if (print && cmd_name && *cmd_name)  *os << cmd_name << ": " ;
  1410. X     return  *os;
  1411. X  }
  1412. X***************
  1413. X*** 288,293 ****
  1414. X--- 302,316 ----
  1415. X     return  *this ;
  1416. X  }
  1417. X  
  1418. X+    // terminate parsing altogether
  1419. X+ void
  1420. X+ CmdLine::quit(int status) {
  1421. X+    if (cmd_quit_handler != NULL) {
  1422. X+       (*cmd_quit_handler)(status);
  1423. X+    } else {
  1424. X+       ::exit(status);
  1425. X+    }
  1426. X+ }
  1427. X  
  1428. X  //---------------------------------------------------------- CmdLineCmdArgIter
  1429. X  
  1430. END_OF_FILE
  1431.   if test 36495 -ne `wc -c <'PATCH01.A'`; then
  1432.     echo shar: \"'PATCH01.A'\" unpacked with wrong size!
  1433.   elif test -f 'PATCH01.B' ; then
  1434.     echo shar: Combining  \"'PATCH01'\" \(68045 characters\)
  1435.     cat 'PATCH01.A' 'PATCH01.B' > 'PATCH01'
  1436.     if test 68045 -ne `wc -c <'PATCH01'`; then
  1437.       echo shar: \"'PATCH01'\" combined with wrong size!
  1438.     else
  1439.       rm PATCH01.A PATCH01.B
  1440.     fi
  1441.   fi
  1442.   # end of 'PATCH01.A'
  1443. fi
  1444. echo shar: End of archive 1 \(of 2\).
  1445. cp /dev/null ark1isdone
  1446. MISSING=""
  1447. for I in 1 2 ; do
  1448.     if test ! -f ark${I}isdone ; then
  1449.     MISSING="${MISSING} ${I}"
  1450.     fi
  1451. done
  1452. if test "${MISSING}" = "" ; then
  1453.     echo You have unpacked both archives.
  1454.     rm -f ark[1-9]isdone
  1455. else
  1456.     echo You still must unpack the following archives:
  1457.     echo "        " ${MISSING}
  1458. fi
  1459. exit 0
  1460. exit 0 # Just in case...
  1461.