home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / misc / volume40 / cmdline / patch03 < prev    next >
Encoding:
Text File  |  1993-11-24  |  29.9 KB  |  812 lines

  1. Newsgroups: comp.sources.misc
  2. From: brad@amber.ssd.csd.harris.com (Brad Appleton)
  3. Subject: v40i158:  cmdline - C++ Library for parsing command-line arguments, Patch03
  4. Message-ID: <1993Nov24.165756.3495@sparky.sterling.com>
  5. X-Md4-Signature: 5ab46a8b87dc003b9ba80b0a73c981fe
  6. Sender: kent@sparky.sterling.com (Kent Landfield)
  7. Reply-To: brad@travis.csd.harris.com
  8. Organization: Harris Computer Systems
  9. Date: Wed, 24 Nov 1993 16:57:56 GMT
  10. Approved: kent@sparky.sterling.com
  11.  
  12. Submitted-by: brad@amber.ssd.csd.harris.com (Brad Appleton)
  13. Posting-number: Volume 40, Issue 158
  14. Archive-name: cmdline/patch03
  15. Environment: C++
  16. Patch-To: cmdline: Volume 31, Issue 47-54
  17.  
  18. This is patch-level 3 of "CmdLine":  a C++ library for parsing
  19. command arguments and assigning the corresponding values to program
  20. variables. "CmdLine" includes "cmdparse", a program to provide an
  21. interface to CmdLine for shell-scripts.
  22.  
  23.  To apply this patch:
  24.  --------------------
  25.    0) save this article to a file in your "CmdLine" source directory
  26.  
  27.    1) "cd" to your CmdLine source directory
  28.  
  29.    2) Remove all lines in the sharfile (the file you saved in #0)
  30.       that precede the line that starts with "#! /bin/sh".
  31.  
  32.    3) Run the command "sh sharfile" (or whatever you named your sharfile).
  33.       This will create a file named "PATCH03" in your current directory,
  34.       and will also create the files "TO-DO" and "Suggestions" (the latter
  35.       two files are new additions to the current release of CmdLine).
  36.  
  37.    4) Run "patch -p0 < PATCH03"
  38.  
  39. For those of you who are unfamiliar with "CmdLine" and "cmdparse",
  40. an overview is included later on in this article. You can send
  41. e-mail to me at brad@ssd.csd.harris.com if you want the complete
  42. C++ source.
  43.  
  44.  Changes in this release:
  45.  ------------------------
  46.  - documented "secret" arguments in cmdparse(1)
  47.  
  48.  - fixed a very rarely encountered bug with matching and recognizing
  49.      a positional list that has been interrupted and then continued.
  50.  
  51.  CmdLine is now part of the test-suite for the FSF's g++. The following are
  52.  the changes they made to CmdLine for g++ 2.5:
  53.  
  54.  - The preprocessor defines __GNUG__, so the user doesn't need to
  55.    define __gplusplus
  56.  
  57.  - src/lib/cmdline.h, src/lib/states.h: the enums work properly now
  58.  
  59.  - src/lib/fifolist.c: NULL wasn't defined on my system, so I put it
  60.    in if it's not already been defined
  61.  
  62.  These changes were e-mailed to me by Brendan Kehoe <brendan@lisa.cygnus.com>
  63.  Unfortunately, Brendan also tells me that he cant get CmdLine to compile
  64.  under g++ with -DTEMPLATES #defined because it involves some non-trivial
  65.  fixes to the compiler. 
  66.  
  67.  -----------------------------------------------------------------------------
  68.  
  69.  
  70.                     An overview of CmdLine and cmdparse
  71.                     ===================================
  72.  
  73.                  by Brad Appleton <brad@ssd.csd.harris.com>
  74.  
  75.  
  76.  
  77.  Introduction
  78.  ------------
  79.  CmdLine is a C++ Library for parsing command-line arguments. It is 
  80.  approximately 2000 lines of C++ code (excluding comments).
  81.  
  82.  Cmdparse is a command-line interface to CmdLine for Unix shell-scripts.
  83.  It is approximately 1200 lines of C++ code (excluding comments).
  84.  
  85.  
  86.  CmdLine(3C++)
  87.  -------------
  88.  CmdLine is a set of classes to parse command-line arguments.  Unlike
  89.  getopt() and its variants, CmdLine does more than just split up the
  90.  command-line into some canonical form.  CmdLine will actually parse
  91.  the command-line, assigning the appropriate command-line values to
  92.  the corresponding variables, and will verify the command-line syntax
  93.  (and print a usage message if necessary) all in one member function
  94.  call.  Furthermore, many features of CmdLine's parsing behavior are
  95.  configurable at run-time.  These features include the following:
  96.  
  97.      o  Prompting the user for missing arguments.
  98.      o  Allowing keywords (-count=4) and/or options (-c4).
  99.      o  Ignoring bad syntax instead of terminating.
  100.      o  Ignoring upper/lower case on the command-line.
  101.      o  Suppressing the printing of syntax error messages.
  102.      o  Controlling the verboseness of usage messages.
  103.      o  Controlling whether or not options may be processed
  104.           after positional parameters have been seen.
  105.  
  106.  CmdLine also allows for options that take an optional argument, options
  107.  that take a (possibly optional) list of one or more arguments, sticky
  108.  options (options whose argument must reside in the same token as the
  109.  option itself), and options whose argument must reside in a separate
  110.  token from the option itself.
  111.  
  112.  CmdLine consists of a set of C++ classes to parse arguments from an
  113.  input source called a CmdLineArgIter (which is a base class for iterating
  114.  over arguments from an arbitrary input source).  Argument iterators are
  115.  defined for an argv[] array (with or without a corresponding argc), for
  116.  a string of tokens that are separated by a given set of delimiters, and
  117.  for an input-stream.  Users can easily extend CmdLine to parse arguments
  118.  from other input sources simply by creating their own argument iterator
  119.  classes derived from the CmdLineArgIter class defined in <cmdline.h>.
  120.  
  121.  Command-line arguments are themselves objects that contain a specific
  122.  command-line interface, and a function that performs the desired actions
  123.  when its corresponding argument is seen on the command line.  Predefined
  124.  command-line argument types (derived from the abstract class CmdArg in
  125.  <cmdline.h>) exist for boolean, integer, floating-point, character, and
  126.  string arguments, and for lists of integers, floats, and strings.  These
  127.  predefined subclasses of CmdArg may be found in <cmdargs.h>.  Users can
  128.  also create their own command-argument types on the fly by defining and
  129.  implementing an appropriate subclass of the CmdArg class.
  130.  
  131.  Using CmdLine is relatively easy - you need to construct your arguments,
  132.  your command-line, and your argument iterator.  Then all that is left to
  133.  do is call the "parse" member function of your CmdLine object.  The
  134.  following is a simple example:
  135.  
  136.     #include <stdlib.h>
  137.     #include <iostream.h>
  138.     #include <cmdargs.h>
  139.  
  140.     int  main(int argc, char * argv[])
  141.     {
  142.           // Declare arguments
  143.        CmdArgInt  count('c', "count", "number", "number of copies to print.");
  144.        CmdArgBool xflag('x', "xmode", "turn on 'x'-mode.");
  145.        CmdArgChar fdsep('s', "separator", "char", "field-separator to use.");
  146.        CmdArgStr  input("input-file",  "input file to read.");
  147.        CmdArgStrList  output("[output-file ...]",  "where to print output.");
  148.  
  149.           // Declare command object and its argument-iterator
  150.        CmdLine  cmd(*argv, &count, &xflag, &fdsep, &input, &output, NULL);
  151.        CmdArgvIter  arg_iter(--argc, ++argv);
  152.  
  153.           // Initialize arguments to appropriate default values.
  154.        count = 1;
  155.        xflag = 0;
  156.        fdsep = ',';
  157.  
  158.           // Parse arguments
  159.        cmd.parse(arg_iter);
  160.  
  161.           // Print arguments
  162.        cout << "count=" << count << endl ;
  163.        cout << "xflag=" << (xflag ? "ON" : "OFF") << endl ;
  164.        cout << "fdsep='" << (char) fdsep << "'" << endl ;
  165.        cout << "input=\"" << input << "\"" << endl ;
  166.        
  167.        for (int i = 0 ; i < output.count() ; i++) {
  168.           cout << "output[" << i << "]=" << output[i] << endl ;
  169.        }
  170.  
  171.        return  0;
  172.     }
  173.  
  174.  
  175.  The Unix command-line syntax for the above program would be as follows:
  176.  
  177.     Usage: progname [-c number] [-x] [-s char] input-file [output-file ...]
  178.  
  179.     Options/Arguments:
  180.             -c number        number of copies to print.
  181.             -x               turn on 'x'-mode.
  182.             -s char          field-separator to use.
  183.             input-file       input file to read.
  184.             output-file ...  where to print output.
  185.  
  186.  
  187.  The Unix command-line syntax using long-options (keywords) for the above
  188.  program would be as follows:
  189.  
  190.     Usage: progname [--count number] [--xmode] [--separator char]
  191.                     input-file [output-file ...]
  192.  
  193.     Options/Arguments:
  194.             --count number    number of copies to print.
  195.             --xmode           turn on 'x'-mode.
  196.             --separator char  field-separator to use.
  197.             input-file        input file to read.
  198.             output-file ...   where to print output.
  199.  
  200.  If desired, one can set a configuration flag at run-time to allow "+"
  201.  to also be recognized (in addition to "--") as a long-option prefix.
  202.  
  203.  By default, CmdLine allows both options and long-options to appear on the
  204.  command-line. You can instruct CmdLine to disallow one or the other however.
  205.  As an "extra", when options are disallowed, the "-" prefix is assumed to
  206.  denote a long-option instead of an option (hence either "-" or "--" denotes
  207.  a keyword in this case).  Using this feature, CmdLine can be used to supply
  208.  the type of long-option syntax that is now becoming quite popular in the
  209.  Unix world. Using this "new" syntax, the command-line syntax for the above
  210.  command would be the following:
  211.  
  212.     Usage: progname [-count number] [-xmode] [-separator char]
  213.                     input-file [output-file ...]
  214.  
  215.     Options/Arguments:
  216.             -count number    number of copies to print.
  217.             -xmode           turn on 'x'-mode.
  218.             -separator char  field-separator to use.
  219.             input-file       input file to read.
  220.             output-file ...  where to print output.
  221.  
  222.  
  223.  It should be mentioned that, when long-options are used, only a unique
  224.  prefix of the keyword needs to be given (and character-case is ignored).
  225.  Hence, in the above example, "-x", "-X", and "-xm" will match "-xmode".
  226.  
  227.  
  228.  cmdparse(1)
  229.  -----------
  230.  Using "cmdparse" is even easier than using CmdLine. You declare your
  231.  arguments in a string and then you invoke cmdparse with the command
  232.  line of your shell-script and cmdparse will output a script of variable
  233.  settings for you to evaluate.  The following is an example (using the
  234.  same arguments as in our sample program):
  235.  
  236.     #!/bin/sh
  237.     NAME="`/bin/basename $0`"
  238.  
  239.     ARGS='
  240.        ArgInt   count  "[c|count number]"    "number of copies to print."
  241.        ArgBool  xflag  "[x|xmode]"           "turn on x-mode."
  242.        ArgChar  fdsep  "[s|separator char]"  "field-separator to use."
  243.        ArgStr   input  "input-file"          "input file to read."
  244.        ArgStr   output "[output-file ...]"   "where to print output."
  245.     '
  246.  
  247.     if  cmdparse -shell=sh -decls="$ARGS" -- $NAME "$@" > tmp$$
  248.     then
  249.        . tmp$$
  250.        /bin/rm -f tmp$$
  251.     else
  252.        EXITVAL=$?
  253.        /bin/rm -f tmp$$
  254.        exit $EXITVAL
  255.     fi
  256.  
  257.     echo "xflag=" $xflag
  258.     echo "count=" $count
  259.     echo "fdsep=" $fdsep
  260.     echo "input=" $input
  261.     if [ "$output" ] ; then
  262.        echo "output=" $output
  263.     fi
  264.  
  265.  
  266.  Note that you declare the syntax of an argument differently for cmdparse
  267.  than for CmdLine. The syntax for a single argument for cmdparse looks like
  268.  the following:
  269.  
  270.     <arg-type>  <arg-name>  <syntax>  <description>
  271.  
  272.  Where <arg-type> is one of the following:
  273.  
  274.     ArgInt     --  an integer value (or list of values)
  275.     ArgFloat   --  a floating-point value (or list of values)
  276.     ArgChar    --  a character value (or list of values)
  277.     ArgStr     --  a string value (or list of values)
  278.     ArgBool    --  a boolean flag that is turned ON
  279.     ArgClear   --  a boolean flag that is turned OFF
  280.     ArgToggle  --  a boolean flag that is toggled
  281.     ArgUsage   --  print usage and exit
  282.     ArgDummy   --  a dummy argument
  283.  
  284.  If desired, the leading "Arg" portion may be omitted from the type-name.
  285.  
  286.  <arg-name> is simply the name of the variable in your script that you wish
  287.  to contain the resultant value from the command-line.  Any default value
  288.  must be assigned to the variable before invoking cmdparse.
  289.  
  290.  <syntax> and <description> *MUST* be enclosed in either single or double
  291.  quotes! <description> is simply that, the description of the argument.
  292.  
  293.  <syntax> is a little trickier, there are three basic forms of syntax:
  294.  
  295.    1)  "c|keyword"        -- an option the takes no value
  296.    2)  "c|keyword value"  -- an option that takes a value
  297.    3)  "value"            -- a positional parameter
  298.  
  299.  Note that the option-character MUST precede the keyword-name and that
  300.  there must be NO spaces surrounding the '|' in "c|keyword"!
  301.  
  302.  Any "optional" parts of the argument should appear inside square-brackets
  303.  ('[' and ']') and a list of values is denoted by an ellipsis (" ...").
  304.  Most options will be inside of square brackets to reflect the fact that
  305.  they are "optional".
  306.  
  307.  Some example <syntax> strings follow:
  308.  
  309.     "c|keyword"                -- a required option
  310.     "[c|keyword]"              -- an option with no value
  311.     "[c|keyword value]"        -- an option that takes a value
  312.     "[c|keyword [value]]"      -- an option that takes an optional value
  313.     "[c|keyword value ...]"    -- an option that takes 1 or more values
  314.     "[c|keyword [value ...]]"  -- an option that takes 0 or more values
  315.     "value"                    -- a required positional parameter
  316.     "[value]"                  -- an optional positional-parameter
  317.     "[c|keyword] value"        -- a required argument that may be matched
  318.                                   either positionally or by keyword!
  319.  
  320.  
  321.  Further Information
  322.  -------------------
  323.  This is just a brief overview of what the CmdLine package can do. Please
  324.  read the documentation for a more thorough explanation of this products'
  325.  capabilities and limitations!
  326.  
  327.  
  328.  ______________________ "And miles to go before I sleep." ______________________
  329.   Brad Appleton, Senior Software Engineer    Harris Computer Systems Division
  330.     E-mail: brad@ssd.csd.harris.com          2101 W. Cypress Creek Rd., M/S 161 
  331.     Phone : (305) 973-5190                   Fort Lauderdale, FL  USA  33309
  332.  ~~~~~~~~~~~~~~~~~~~ Disclaimer: I said it, not my employer! ~~~~~~~~~~~~~~~~~~~
  333. --------
  334. #! /bin/sh
  335. # This is a shell archive.  Remove anything before this line, then unpack
  336. # it by saving it into a file and typing "sh file".  To overwrite existing
  337. # files, type "sh file -c".  You can also feed this as standard input via
  338. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  339. # will see the following message at the end:
  340. #        "End of shell archive."
  341. # Contents:  PATCH03 Suggestions TO-DO
  342. # Wrapped by brad@amber on Fri Nov  5 15:21:30 1993
  343. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  344. if test -f 'PATCH03' -a "${1}" != "-c" ; then 
  345.   echo shar: Will not clobber existing file \"'PATCH03'\"
  346. else
  347. echo shar: Extracting \"'PATCH03'\" \(13063 characters\)
  348. sed "s/^X//" >'PATCH03' <<'END_OF_FILE'
  349. X*** MANIFEST.OLD    Fri Nov 05 15:19:07 1993
  350. X--- MANIFEST    Fri Nov 05 15:18:21 1993
  351. X***************
  352. X*** 5,10 ****
  353. X--- 5,12 ----
  354. X   Makefile                   1    Makefile for the product
  355. X   Overview                   4    A brief overview of the product
  356. X   README                     1    Read this file first
  357. X+  Suggestions                1    List of Suggestions for CmdLine/cmdparse
  358. X+  TO-DO                      1    Things still to do for CmdLine/cmdparse
  359. X   doc                        1    Documentation directory
  360. X   doc/Makefile               1    Makefile for the documentation
  361. X   doc/bugs.man               1    documents known bugs
  362. X***************
  363. X*** 25,31 ****
  364. X   src/cmd/argtypes.c         2    implementation of shell-script arguments
  365. X   src/cmd/argtypes.h         2    definition of shell-script arguments
  366. X   src/cmd/cmdparse.c         6    the guts of the cmdparse program
  367. X!  src/cmd/cmdparse.h         1    the specification of the cmdparse program
  368. X   src/cmd/cmdparse.pl        2    cmdparse for Perl programmers
  369. X   src/cmd/cmdparse.tcl       2    cmdparse for Tcl programmers
  370. X   src/cmd/fsm.c              2    finite-state-machine for parsing arg-syntax
  371. X--- 27,33 ----
  372. X   src/cmd/argtypes.c         2    implementation of shell-script arguments
  373. X   src/cmd/argtypes.h         2    definition of shell-script arguments
  374. X   src/cmd/cmdparse.c         6    the guts of the cmdparse program
  375. X!  src/cmd/cmdparse.h         2    the specification of the cmdparse program
  376. X   src/cmd/cmdparse.pl        2    cmdparse for Perl programmers
  377. X   src/cmd/cmdparse.tcl       2    cmdparse for Tcl programmers
  378. X   src/cmd/fsm.c              2    finite-state-machine for parsing arg-syntax
  379. X*** README.OLD    Fri Nov 05 15:19:11 1993
  380. X--- README    Wed Oct 27 10:30:11 1993
  381. X***************
  382. X*** 62,69 ****
  383. X   msdos           Needed for MS-DOS systems.
  384. X   os2             Needed for OS/2 Systems.
  385. X  
  386. X-  __gplusplus     Needed if you are using g++ as your C++ compiler.
  387. X- 
  388. X   unix_style      (This is the default) Use this to have CmdLine parse
  389. X                   command-lines using traditional Unix command-line syntax.
  390. X  
  391. X--- 62,67 ----
  392. X***************
  393. X*** 191,193 ****
  394. X--- 189,228 ----
  395. X   -----------------------------------------------------------------------------
  396. X   - Fixed a problem that some machines/compilers had with the contructor
  397. X     ignoring the first CmdArg.
  398. X+ 
  399. X+  10/08/93        Brad Appleton        <brad@ssd.csd.harris.com>
  400. X+  -----------------------------------------------------------------------------
  401. X+  CmdLine is now part of the test-suite for the FSF's g++. The following are
  402. X+  the changes they made to CmdLine for g++ 2.5:
  403. X+ 
  404. X+  - The preprocessor defines __GNUG__, so the user doesn't need to
  405. X+    define __gplusplus
  406. X+ 
  407. X+  - src/lib/cmdline.h, src/lib/states.h: the enums work properly now
  408. X+ 
  409. X+  - src/lib/fifolist.c: NULL wasn't defined on my system, so I put it
  410. X+    in if it's not already been defined
  411. X+ 
  412. X+  These changes were e-mailed to me by Brendan Kehoe <brendan@lisa.cygnus.com>
  413. X+  Unfortunately, Brendan also tells me that he cant get CmdLine to compile
  414. X+  under g++ with -DTEMPLATES #defined because it involves some non-trivial
  415. X+  fixes to the compiler. 
  416. X+ 
  417. X+  10/26/93        Brad Appleton        <brad@ssd.csd.harris.com>
  418. X+  -----------------------------------------------------------------------------
  419. X+  - documented "secret" arguments in cmdparse(1)
  420. X+  - fixed the following bug:
  421. X+      CmdLine did not properly handle an "interrupted" positional-list.
  422. X+      For example, If I have a program whose syntax is:
  423. X+ 
  424. X+          prog [-x] arg ...
  425. X+ 
  426. X+      And I have OPTS_FIRST disabled so that options may occur after
  427. X+      positional parameters, then the following should be equivalent:
  428. X+ 
  429. X+          prog -x arg1 arg2 prog arg1 -x arg2
  430. X+ 
  431. X+      CmdLine was not correctly recognizing that "arg2" was part of
  432. X+      the the previously specified positional list. This has been
  433. X+      fixed!
  434. X+ 
  435. X*** doc/cmdparse.man1.OLD    Fri Nov 05 15:19:16 1993
  436. X--- doc/cmdparse.man1    Wed Oct 27 10:27:16 1993
  437. X***************
  438. X*** 311,319 ****
  439. X  to quote the field to also appear within the field, then precede the quote
  440. X  character (inside the quotes) with a backslash (`\\').
  441. X  
  442. X! The <\fIdescription\fP> is simply a textual description of the argument.
  443. X!  
  444. X! The <\fIsyntax\fP> is a little trickier, there are three basic forms of syntax:
  445. X  
  446. X  .RS
  447. X  .TP
  448. X--- 311,323 ----
  449. X  to quote the field to also appear within the field, then precede the quote
  450. X  character (inside the quotes) with a backslash (`\\').
  451. X  
  452. X! The <\fIdescription\fP> is simply a textual description of the
  453. X! argument.  If the first non-white character of the argument
  454. X! description is a semicolon (`;'), then the argument is considered
  455. X! to be "secret" and is NOT printed in usage messages.
  456. X! 
  457. X! The <\fIsyntax\fP> is a little trickier, there are three basic
  458. X! forms of syntax:
  459. X  
  460. X  .RS
  461. X  .TP
  462. X*** src/cmd/Makefile.OLD    Fri Nov 05 15:19:23 1993
  463. X--- src/cmd/Makefile    Fri Oct 08 09:45:02 1993
  464. X***************
  465. X*** 74,80 ****
  466. X      ( $(CHDIR) $(PROGLIBDIR) ; $(BUILD) $@ ; )
  467. X  
  468. X  $(PROGRAM): $(OBJS)
  469. X!     $(CC) $(EXE)$@ $(OBJS) $(PROGLIB)
  470. X  
  471. X  ###
  472. X  # maintenance dependencies
  473. X--- 74,80 ----
  474. X      ( $(CHDIR) $(PROGLIBDIR) ; $(BUILD) $@ ; )
  475. X  
  476. X  $(PROGRAM): $(OBJS)
  477. X!     $(CC) $(EXE) $@ $(OBJS) $(PROGLIB)
  478. X  
  479. X  ###
  480. X  # maintenance dependencies
  481. X*** src/lib/Makefile.OLD    Fri Nov 05 15:19:32 1993
  482. X--- src/lib/Makefile    Fri Oct 08 09:44:27 1993
  483. X***************
  484. X*** 70,76 ****
  485. X  test: cmdtest$(EXECEXT)
  486. X  
  487. X  cmdtest$(EXECEXT): cmdtest$(OBJEXT) $(OBJS)
  488. X!     $(CC) $(EXE)$@ cmdtest$(OBJEXT) $(LIBRARY)
  489. X  
  490. X  $(LIBRARY): $(OBJS)
  491. X      $(AR) $@ $(OBJS)
  492. X--- 70,76 ----
  493. X  test: cmdtest$(EXECEXT)
  494. X  
  495. X  cmdtest$(EXECEXT): cmdtest$(OBJEXT) $(OBJS)
  496. X!     $(CC) $(EXE) $@ cmdtest$(OBJEXT) $(LIBRARY)
  497. X  
  498. X  $(LIBRARY): $(OBJS)
  499. X      $(AR) $@ $(OBJS)
  500. X*** src/lib/cmdargs.c.OLD    Fri Nov 05 15:19:38 1993
  501. X--- src/lib/cmdargs.c    Fri Oct 08 09:36:29 1993
  502. X***************
  503. X*** 271,277 ****
  504. X  
  505. X  typedef  CmdArgStrCompiler::casc_string  CmdArgString ;
  506. X  
  507. X! #ifndef __gplusplus
  508. X  CmdArgString::~casc_string(void)
  509. X  {
  510. X     if (is_alloc)  delete [] (char *)str;
  511. X--- 271,277 ----
  512. X  
  513. X  typedef  CmdArgStrCompiler::casc_string  CmdArgString ;
  514. X  
  515. X! #ifndef __GNUG__
  516. X  CmdArgString::~casc_string(void)
  517. X  {
  518. X     if (is_alloc)  delete [] (char *)str;
  519. X*** src/lib/cmdargs.h.OLD    Fri Nov 05 15:19:44 1993
  520. X--- src/lib/cmdargs.h    Fri Oct 08 09:37:06 1993
  521. X***************
  522. X*** 462,468 ****
  523. X        operator const char*(void)  const { return  str; }
  524. X  
  525. X        virtual ~casc_string(void)
  526. X! #ifdef __gplusplus
  527. X           { if (is_alloc)   delete [] (char *) str; }
  528. X  #endif
  529. X        ;
  530. X--- 462,468 ----
  531. X        operator const char*(void)  const { return  str; }
  532. X  
  533. X        virtual ~casc_string(void)
  534. X! #ifdef __GNUG__
  535. X           { if (is_alloc)   delete [] (char *) str; }
  536. X  #endif
  537. X        ;
  538. X*** src/lib/cmdline.h.OLD    Fri Nov 05 15:19:49 1993
  539. X--- src/lib/cmdline.h    Fri Oct 08 09:38:01 1993
  540. X***************
  541. X*** 75,93 ****
  542. X        isLIST      = 0x20,  // argument is a list
  543. X        isPOS       = 0x40,  // argument is positional
  544. X        isHIDDEN    = 0x80,  // argument is not to be printed in usage
  545. X- #ifndef __gplusplus
  546. X        isVALTAKEN  = (isVALREQ | isVALOPT),    // argument takes a value
  547. X        isOPTVALOPT = (isOPT | isVALOPT),
  548. X        isOPTVALREQ = (isOPT | isVALREQ),
  549. X        isPOSVALOPT = (isPOS | isVALOPT),
  550. X        isPOSVALREQ = (isPOS | isVALREQ),
  551. X- #else
  552. X-       isVALTAKEN  = 0x06,     // g++ doesnt seem to recognize enums that
  553. X-       isOPTVALOPT = 0x02,     // are defined in terms of previous values
  554. X-       isOPTVALREQ = 0x04,     // so I have to hard code the values instead.
  555. X-       isPOSVALOPT = 0x42,     //
  556. X-       isPOSVALREQ = 0x44,     // If this ever changes -- remove this stuff!
  557. X- #endif
  558. X     } ;
  559. X  
  560. X       // Flags that say how the argument was specied on the command-line
  561. X--- 75,85 ----
  562. X*** src/lib/fifolist.c.OLD    Fri Nov 05 15:19:56 1993
  563. X--- src/lib/fifolist.c    Fri Oct 08 09:38:53 1993
  564. X***************
  565. X*** 12,17 ****
  566. X--- 12,21 ----
  567. X  #include "cmdline.h"
  568. X  #include "fifolist.h"
  569. X  
  570. X+ #ifndef NULL
  571. X+ # define NULL 0L
  572. X+ #endif
  573. X+ 
  574. X  //------------------------------------------------------------- GenericFifoList
  575. X  
  576. X     // Destructor
  577. X*** src/lib/patchlevel.c.OLD    Fri Nov 05 15:20:00 1993
  578. X--- src/lib/patchlevel.c    Fri Oct 08 09:28:19 1993
  579. X***************
  580. X*** 12,22 ****
  581. X  //
  582. X  //    03/03/93    Brad Appleton    <brad@ssd.csd.harris.com>
  583. X  //    - Modified for patch 1
  584. X  //-^^---------------------------------------------------------------------
  585. X  
  586. X  #include "cmdline.h"
  587. X  
  588. X!    // Record the version-identifier for this project.
  589. X     //
  590. X     // My source-code management system lets me use a symbolic-name
  591. X     // to identify a given configuration of the project. From this
  592. X--- 12,28 ----
  593. X  //
  594. X  //    03/03/93    Brad Appleton    <brad@ssd.csd.harris.com>
  595. X  //    - Modified for patch 1
  596. X+ //
  597. X+ //    08/19/93    Brad Appleton    <brad@ssd.csd.harris.com>
  598. X+ //    - Modified for patch 2
  599. X+ //
  600. X+ //    10/08/93    Brad Appleton    <brad@ssd.csd.harris.com>
  601. X+ //    - Modified for patch 3
  602. X  //-^^---------------------------------------------------------------------
  603. X  
  604. X  #include "cmdline.h"
  605. X  
  606. X!    // Record the version-identifier for this configuration of the project.
  607. X     //
  608. X     // My source-code management system lets me use a symbolic-name
  609. X     // to identify a given configuration of the project. From this
  610. X***************
  611. X*** 24,36 ****
  612. X     // file that makes up this version of the project.
  613. X     //
  614. X  static const char ident[] =
  615. X!    "@(#)SMS  task: cmdline-1.02" ;
  616. X  
  617. X  
  618. X     // Release and patchlevel information
  619. X  #define  CMDLINE_RELEASE     1
  620. X! #define  CMDLINE_PATCHLEVEL  2
  621. X! #define  CMDLINE_IDENT       "@(#)CmdLine    1.02"
  622. X  
  623. X  unsigned
  624. X  CmdLine::release(void)  { return  CMDLINE_RELEASE; }
  625. X--- 30,42 ----
  626. X     // file that makes up this version of the project.
  627. X     //
  628. X  static const char ident[] =
  629. X!    "@(#)SMS  task: cmdline-1.03" ;
  630. X  
  631. X  
  632. X     // Release and patchlevel information
  633. X  #define  CMDLINE_RELEASE     1
  634. X! #define  CMDLINE_PATCHLEVEL  3
  635. X! #define  CMDLINE_IDENT       "@(#)CmdLine    1.03"
  636. X  
  637. X  unsigned
  638. X  CmdLine::release(void)  { return  CMDLINE_RELEASE; }
  639. X*** src/lib/private.c.OLD    Fri Nov 05 15:20:03 1993
  640. X--- src/lib/private.c    Tue Oct 26 11:53:23 1993
  641. X***************
  642. X*** 612,619 ****
  643. X  // ^PARAMETERS:
  644. X  //
  645. X  // ^DESCRIPTION:
  646. X! //    If "cmd" has an positional argument that has not yet been given
  647. X! //    then this function will find and return the first such argument.
  648. X  //
  649. X  // ^REQUIREMENTS:
  650. X  //
  651. X--- 612,620 ----
  652. X  // ^PARAMETERS:
  653. X  //
  654. X  // ^DESCRIPTION:
  655. X! //    If "cmd" has an positional argument that has not yet been given,
  656. X! //    or that corresponds to a list, then this function will find and
  657. X! //    return the first such argument.
  658. X  //
  659. X  // ^REQUIREMENTS:
  660. X  //
  661. X***************
  662. X*** 625,646 ****
  663. X  //    otherwise we return NULL.
  664. X  //
  665. X  // ^ALGORITHM:
  666. X! //    Trivial.
  667. X  //-^^----
  668. X  CmdArg *
  669. X  CmdLine::pos_match(void) const
  670. X  {
  671. X     CmdArgListListIter  list_iter(cmd_args);
  672. X     for (CmdArgList * alist = list_iter() ; alist ; alist = list_iter()) {
  673. X        CmdArgListIter  iter(alist);
  674. X        for (CmdArg * cmdarg = iter() ; cmdarg ; cmdarg = iter()) {
  675. X           if (cmdarg->is_dummy())  continue;
  676. X!          if ((cmdarg->syntax() & CmdArg::isPOS) &&
  677. X!              (! (cmdarg->flags() & CmdArg::GIVEN)))
  678. X!          {
  679. X!             return  cmdarg ;
  680. X           }
  681. X        } //for iter
  682. X     } //for list_iter
  683. X!    return  NULL ;
  684. X  }
  685. X--- 626,651 ----
  686. X  //    otherwise we return NULL.
  687. X  //
  688. X  // ^ALGORITHM:
  689. X! //    First look for the first unmatched positional argument!!
  690. X! //    If there aren't any, then look for the LAST positional list!
  691. X  //-^^----
  692. X  CmdArg *
  693. X  CmdLine::pos_match(void) const
  694. X  {
  695. X+    CmdArg * last_pos_list = NULL;
  696. X     CmdArgListListIter  list_iter(cmd_args);
  697. X     for (CmdArgList * alist = list_iter() ; alist ; alist = list_iter()) {
  698. X        CmdArgListIter  iter(alist);
  699. X        for (CmdArg * cmdarg = iter() ; cmdarg ; cmdarg = iter()) {
  700. X           if (cmdarg->is_dummy())  continue;
  701. X!          if (cmdarg->syntax() & CmdArg::isPOS) {
  702. X!             if (! (cmdarg->flags() & CmdArg::GIVEN)) {
  703. X!                return  cmdarg ;
  704. X!             } else if (cmdarg->flags() & CmdArg::isLIST) {
  705. X!                last_pos_list = cmdarg;
  706. X!             }
  707. X           }
  708. X        } //for iter
  709. X     } //for list_iter
  710. X!    return  last_pos_list ;
  711. X  }
  712. X*** src/lib/states.h.OLD    Fri Nov 05 15:20:09 1993
  713. X--- src/lib/states.h    Fri Oct 08 09:39:23 1993
  714. X***************
  715. X*** 56,81 ****
  716. X     cmd_TOK_REQUIRED = 0x01,  // is the "wanted" token required?
  717. X  
  718. X     cmd_WANT_VAL     = 0x02,  // are we expecting a value?
  719. X- #ifndef __gplusplus
  720. X     cmd_NEED_VAL     = (cmd_WANT_VAL | cmd_TOK_REQUIRED),
  721. X- #else
  722. X-    cmd_NEED_VAL     = 0x03,
  723. X- #endif
  724. X  
  725. X  #ifdef vms_style
  726. X     cmd_WANT_VALSEP  = 0x04,  // are we expecting ':' or '='
  727. X- # ifndef __gplusplus
  728. X     cmd_NEED_VALSEP  = (cmd_WANT_VALSEP | cmd_TOK_REQUIRED),
  729. X- # else
  730. X-    cmd_NEED_VALSEP  = 0x05,
  731. X- # endif
  732. X  
  733. X     cmd_WANT_LISTSEP = 0x08,  // are we expecting ',' or '+'
  734. X- # ifndef __gplusplus
  735. X     cmd_NEED_LISTSEP = (cmd_WANT_LISTSEP | cmd_TOK_REQUIRED),
  736. X- # else
  737. X-    cmd_NEED_LISTSEP = 0x09,
  738. X- # endif
  739. X  #endif
  740. X  } ;
  741. X  
  742. X--- 56,69 ----
  743. END_OF_FILE
  744. if test 13063 -ne `wc -c <'PATCH03'`; then
  745.     echo shar: \"'PATCH03'\" unpacked with wrong size!
  746. fi
  747. # end of 'PATCH03'
  748. fi
  749. if test -f 'Suggestions' -a "${1}" != "-c" ; then 
  750.   echo shar: Will not clobber existing file \"'Suggestions'\"
  751. else
  752. echo shar: Extracting \"'Suggestions'\" \(1128 characters\)
  753. sed "s/^X//" >'Suggestions' <<'END_OF_FILE'
  754. XList of suggestions and ideas for CmdLine/cmdparse:
  755. X-------------------------------------------------------------------------------
  756. X
  757. X- What about letting the user define an "ArgCatcher" handler of sorts to
  758. X  "handle" bad/unknown arguments (we have to tell them the bad argument
  759. X  and the reason it was bad - in addition to the usual stuff). What would
  760. X  this function return?
  761. X
  762. X- Perhaps each CmdArg<Type> that is a not abstract should have 2 versions
  763. X  of each constructor: one that takes an initial value and one that doesnt.
  764. X
  765. X- Perhaps a CmdLine should have facilities to get/set the long & short
  766. X  option prefixes (and the end-options string too).
  767. X
  768. X- Maybe I need a more abstract class that is a parent of CmdLine. Perhaps
  769. X  some of the stuff in CmdLine could be transferred to this class. I would
  770. X  need to make some private stuff protected though - do I really want that?
  771. X
  772. X- What about a CmdArgAlias class that mereley adds another interface on top
  773. X  of an existing CmdArg? Only problem is, would you want them to share
  774. X  flags (not syntax flags but the specification flags)??? Dont know how
  775. X  I would do this if you did!
  776. X
  777. END_OF_FILE
  778. if test 1128 -ne `wc -c <'Suggestions'`; then
  779.     echo shar: \"'Suggestions'\" unpacked with wrong size!
  780. fi
  781. # end of 'Suggestions'
  782. fi
  783. if test -f 'TO-DO' -a "${1}" != "-c" ; then 
  784.   echo shar: Will not clobber existing file \"'TO-DO'\"
  785. else
  786. echo shar: Extracting \"'TO-DO'\" \(679 characters\)
  787. sed "s/^X//" >'TO-DO' <<'END_OF_FILE'
  788. XList of things still to do for CmdLine/cmdparse:
  789. X-------------------------------------------------------------------------------
  790. X
  791. X- Get cmdparse(1) to work with the 'es' shell.
  792. X
  793. X- Implement vms_style parsing
  794. X  For this - I will need to add a "last_list_matched" to the cmdline-object
  795. X  to handle stuff like "(a,b/c,d)".  Also, what am I going to do about
  796. X  looking at the original command-line (with lib$get_foreign)? I dont 
  797. X  think it is reasonable to always compare the argv[] of a CmdArgvIter
  798. X  to the command-line. Perhaps VMS should have a parse(void) member function
  799. X  of a CmdLine that does nothing for Unix (or perhaps uses <execargs.h>).
  800. X
  801. X- Implement ibm_style parsing
  802. END_OF_FILE
  803. if test 679 -ne `wc -c <'TO-DO'`; then
  804.     echo shar: \"'TO-DO'\" unpacked with wrong size!
  805. fi
  806. # end of 'TO-DO'
  807. fi
  808. echo shar: End of shell archive.
  809. exit 0
  810.  
  811. exit 0 # Just in case...
  812.