home *** CD-ROM | disk | FTP | other *** search
- *** src/lib/cmdline.h.OLD Fri Mar 26 10:50:26 1993
- --- src/lib/cmdline.h Tue Mar 23 17:02:47 1993
- ***************
- *** 9,14 ****
- --- 9,21 ----
- //
- // ^HISTORY:
- // 03/19/92 Brad Appleton <brad@ssd.csd.harris.com> Created
- + //
- + // 03/01/93 Brad Appleton <brad@ssd.csd.harris.com>
- + // - Added arg_sequence field to CmdArg
- + // - Added cmd_nargs_parsed field to CmdLine
- + // - Added cmd_description field to CmdLine
- + // - Added exit_handler() and quit() member-functions to CmdLine
- + // - Added ALLOW_PLUS to list of CmdLine configuration flags
- //-^^---------------------------------------------------------------------
-
- #ifndef _usr_include_cmdline_h
- ***************
- *** 68,78 ****
- --- 75,93 ----
- isLIST = 0x20, // argument is a list
- isPOS = 0x40, // argument is positional
- isHIDDEN = 0x80, // argument is not to be printed in usage
- + #ifndef __gplusplus
- isVALTAKEN = (isVALREQ | isVALOPT), // argument takes a value
- isOPTVALOPT = (isOPT | isVALOPT),
- isOPTVALREQ = (isOPT | isVALREQ),
- isPOSVALOPT = (isPOS | isVALOPT),
- isPOSVALREQ = (isPOS | isVALREQ),
- + #else
- + isVALTAKEN = 0x06, // g++ doesnt seem to recognize enums that
- + isOPTVALOPT = 0x02, // are defined in terms of previous values
- + isOPTVALREQ = 0x04, // so I have to hard code the values instead.
- + isPOSVALOPT = 0x42, //
- + isPOSVALREQ = 0x44, // If this ever changes -- remove this stuff!
- + #endif
- } ;
-
- // Flags that say how the argument was specied on the command-line
- ***************
- *** 204,209 ****
- --- 219,234 ----
- unsigned
- flags(void) const { return arg_flags; }
-
- + // Get the sequence number corresponding to the last
- + // time this argument was matched on the command-line.
- + //
- + // If this argument was not matched, the sequence number
- + // will be zero, otherwise it will be 'N' where the last
- + // time this argument was matched, it was the 'N'th argument
- + // encountered.
- + unsigned
- + sequence(void) const { return arg_sequence; }
- +
- // Get the character (short-option) name of this argument.
- // Returns '\0' if there isnt one.
- char
- ***************
- *** 248,253 ****
- --- 273,281 ----
- void
- clear(unsigned flags =~0) { arg_flags &= ~flags; }
-
- + // set sequence number
- + void
- + sequence(unsigned num) { arg_sequence = num; }
-
- // Private data members
-
- ***************
- *** 256,261 ****
- --- 284,291 ----
- unsigned arg_flags : 8 ;
- unsigned arg_syntax : 8 ;
-
- + unsigned arg_sequence;
- +
- char arg_char_name;
- const char * arg_keyword_name;
- const char * arg_value_name;
- ***************
- *** 309,314 ****
- --- 339,345 ----
- virtual const char *
- operator()(void);
-
- + // is_temporary returns 0 for CmdArgvIter
- virtual int
- is_temporary(void) const;
-
- ***************
- *** 361,366 ****
- --- 392,398 ----
- void
- delimiters(const char * new_delimiters) { seps = new_delimiters; }
-
- + // is_temporary returns 1 for CmdStrTokIter
- virtual int
- is_temporary(void) const;
-
- ***************
- *** 387,392 ****
- --- 419,432 ----
- //
- class CmdIstreamIter : public CmdLineArgIter {
- public:
- + static const unsigned MAX_LINE_LEN ;
- +
- + #ifdef vms
- + enum { c_COMMENT = '!' } ;
- + #else
- + enum { c_COMMENT = '#' } ;
- + #endif
- +
- CmdIstreamIter(istream & input);
-
- virtual ~CmdIstreamIter(void);
- ***************
- *** 394,399 ****
- --- 434,440 ----
- virtual const char *
- operator()(void);
-
- + // is_temporary returns 1 for CmdIstreamIter
- virtual int
- is_temporary(void) const;
-
- ***************
- *** 420,426 ****
- enum CmdFlags {
- ANY_CASE_OPTS = 0x001, // Ignore character-case for short-options
- PROMPT_USER = 0x002, // Prompt the user for missing required args
- ! NO_ABORT = 0x004, // Dont exit upon syntax error
- OPTS_FIRST = 0x008, // No options after positional parameters
- OPTS_ONLY = 0x010, // Dont accept short-options
- KWDS_ONLY = 0x020, // Dont accept long-options
- --- 461,467 ----
- enum CmdFlags {
- ANY_CASE_OPTS = 0x001, // Ignore character-case for short-options
- PROMPT_USER = 0x002, // Prompt the user for missing required args
- ! NO_ABORT = 0x004, // Dont quit upon syntax error
- OPTS_FIRST = 0x008, // No options after positional parameters
- OPTS_ONLY = 0x010, // Dont accept short-options
- KWDS_ONLY = 0x020, // Dont accept long-options
- ***************
- *** 431,436 ****
- --- 472,479 ----
- // when we see an unmatched option,
- // we will try to see if it matches
- // a keyword (and vice-versa).
- + ALLOW_PLUS = 0x200, // Allow "+" (as well as "--") as a prefix
- + // indicating long-options.
- } ;
-
- // Flags to convey parsing-status
- ***************
- *** 477,482 ****
- --- 520,535 ----
- void
- name(const char * progname);
-
- + // Get the command description.
- + const char *
- + description(void) const { return cmd_description; }
- +
- + // Specify a command description.
- + void
- + description(const char * the_description) {
- + cmd_description = the_description;
- + }
- +
- // Append an argument
- CmdLine &
- append(CmdArg * cmdarg);
- ***************
- *** 615,620 ****
- --- 668,708 ----
- epilogue(void) ;
-
- //
- + // Find out the number of arguments parsed so far
- + //
- +
- + unsigned
- + nargs_parsed(void) const { return cmd_nargs_parsed; }
- +
- + //
- + // Exception handling (well -- not really)
- + //
- +
- + typedef void (* quit_func_t)(int);
- +
- + // When a fatal error is encounteredi or when parsing needs to
- + // terminate immediately, the quit() member function is called.
- + // If the programmer has used quit_handler() to setup his own
- + // handler-function, that that function is called; otherwise
- + // exit() is called with the given status.
- + //
- + void
- + quit(int status);
- +
- + // Set the quit-handler. The quit-handler is a pointer to
- + // a function that has no return value and takes a single
- + // integer parameter.
- + //
- + void
- + quit_handler(quit_func_t quit_func) { cmd_quit_handler = quit_func ; }
- +
- + // Get the current quit-handler (returns NULL if there isnt one)
- + //
- + quit_func_t
- + quit_handler(void) const { return cmd_quit_handler; }
- +
- +
- + //
- // Retrieve a specific argument
- //
-
- ***************
- *** 704,713 ****
- --- 792,804 ----
- unsigned cmd_state : 8 ;
- unsigned cmd_flags : 16 ;
- unsigned cmd_status : 16 ;
- + unsigned cmd_nargs_parsed ;
- const char * cmd_name ;
- + const char * cmd_description ;
- CmdArg * cmd_matched_arg ;
- CmdArgListList * cmd_args ;
- ostream * cmd_err ;
- + quit_func_t cmd_quit_handler ;
-
- // Disallow copying and assignment
- CmdLine(const CmdLine & );
- *** src/lib/cmdtest.c.OLD Fri Mar 26 10:50:31 1993
- --- src/lib/cmdtest.c Wed Mar 3 14:11:57 1993
- ***************
- *** 6,11 ****
- --- 6,14 ----
- //
- // ^HISTORY:
- // 03/18/92 Brad Appleton <brad@ssd.csd.harris.com> Created
- + //
- + // 03/01/93 Brad Appleton <brad@ssd.csd.harris.com>
- + // - Attached a description to the command.
- //-^^---------------------------------------------------------------------
-
- #include <stdlib.h>
- ***************
- *** 74,79 ****
- --- 77,84 ----
-
- case 'g' : new_flags |= CmdLine::NO_GUESSING; break;
-
- + case '+' : new_flags |= CmdLine::ALLOW_PLUS; break;
- +
- default : break;
- } //switch
- } //for
- ***************
- *** 100,105 ****
- --- 105,111 ----
- 't' = Temporary-args\n\
- 'q' = Quiet!\n\
- 'g' = no-Guessing\n\
- + '+' = allow-plus\n\
- This-is-a-very-long-line-containing-no-whitespace-\
- characters-and-I-just-want-to-see-if-it-gets-\
- formatted-appropriately!"
- ***************
- *** 200,207 ****
- --- 206,219 ----
- & name,
- & files,
- NULL);
- +
- CmdArgvIter argv_iter(--argc, ++argv);
-
- + cmd.description(
- + "This program is intended to statically and dynamically test \
- + the CmdLine(3C++) class library."
- + );
- +
- cout << "Test of " << CmdLine::ident() << endl ;
-
- xflag = 0;
- ***************
- *** 226,232 ****
- int parse_cin = infile;
-
- // Parse arguments from a string
- ! if (str) {
- CmdStrTokIter tok_iter(str);
-
- xflag = 0;
- --- 238,244 ----
- int parse_cin = infile;
-
- // Parse arguments from a string
- ! if (! str.isNULL()) {
- CmdStrTokIter tok_iter(str);
-
- xflag = 0;
- *** src/lib/dump.c.OLD Fri Mar 26 10:50:35 1993
- --- src/lib/dump.c Mon Mar 1 11:01:33 1993
- ***************
- *** 8,13 ****
- --- 8,18 ----
- //
- // ^HISTORY:
- // 04/01/92 Brad Appleton <brad@ssd.csd.harris.com> Created
- + //
- + // 03/01/93 Brad Appleton <brad@ssd.csd.harris.com>
- + // - Added arg_sequence field to CmdArg
- + // - Added cmd_nargs_parsed field to CmdLine
- + // - Added cmd_description field to CmdLine
- //-^^---------------------------------------------------------------------
-
- #include "cmdline.h"
- ***************
- *** 295,300 ****
- --- 300,307 ----
- ::indent(os, level + 1) << "flags=" ;
- dump_arg_flags(os, arg_flags) << "\n";
-
- + ::indent(os, level + 1) << "sequence=" << arg_sequence << "\n";
- +
- ::indent(os, level) << "}" << endl;
- #endif
- }
- ***************
- *** 309,314 ****
- --- 316,323 ----
-
- ::indent(os, level + 1) << "name=\"" << cmd_name << "\"\n";
-
- + ::indent(os, level + 1) << "description=\"" << cmd_description << "\"\n";
- +
- ::indent(os, level + 1) << "flags=" ;
- dump_cmd_flags(os, cmd_flags) << "\n";
-
- ***************
- *** 327,332 ****
- --- 336,344 ----
- } else {
- os << "matched_arg=" << (void *)cmd_matched_arg << "\n";
- }
- +
- + ::indent(os, level + 1) << "# valid-args-parsed="
- + << cmd_nargs_parsed << "\n" ;
-
- ::indent(os, level) << "}" << endl;
- #endif
- *** src/lib/parse.c.OLD Fri Mar 26 10:50:41 1993
- --- src/lib/parse.c Wed Mar 3 10:02:21 1993
- ***************
- *** 10,15 ****
- --- 10,19 ----
- //
- // ^HISTORY:
- // 12/05/91 Brad Appleton <brad@ssd.csd.harris.com> Created
- + //
- + // 03/01/93 Brad Appleton <brad@ssd.csd.harris.com>
- + // - Added cmd_nargs_parsed field to CmdLine
- + // - Added exit_handler() and quit() member-functions to CmdLine
- //-^^---------------------------------------------------------------------
-
- #include <stdlib.h>
- ***************
- *** 58,63 ****
- --- 62,68 ----
- cmd_parse_state = cmd_START_STATE ;
- cmd_state = 0 ;
- cmd_status = NO_ERROR ;
- + cmd_nargs_parsed = 0 ;
-
- // reset parse-specific attributes for each argument
- CmdArgListListIter list_iter(cmd_args);
- ***************
- *** 94,100 ****
- //
- // Prints a usage message if there were syntax error.
- //
- ! // Terminates program execution by calling ::exit(e_SYNTAX) if
- // (NO_ABORT is NOT set and the command-status is NOT NO_ERROR).
- //
- // ^RETURN-VALUE:
- --- 99,105 ----
- //
- // Prints a usage message if there were syntax error.
- //
- ! // Terminates program execution by calling quit(e_SYNTAX) if
- // (NO_ABORT is NOT set and the command-status is NOT NO_ERROR).
- //
- // ^RETURN-VALUE:
- ***************
- *** 121,130 ****
- // print usage if necessary
- if (cmd_status & ARG_MISSING) {
- usage();
- ! ::exit(e_SYNTAX);
- } else if (cmd_status && (! (cmd_flags & NO_ABORT))) {
- usage();
- ! ::exit(e_SYNTAX);
- }
-
- return cmd_status ;
- --- 126,135 ----
- // print usage if necessary
- if (cmd_status & ARG_MISSING) {
- usage();
- ! quit(e_SYNTAX);
- } else if (cmd_status && (! (cmd_flags & NO_ABORT))) {
- usage();
- ! quit(e_SYNTAX);
- }
-
- return cmd_status ;
- *** src/lib/patchlevel.c.OLD Fri Mar 26 10:50:46 1993
- --- src/lib/patchlevel.c Wed Mar 3 14:41:41 1993
- ***************
- *** 9,14 ****
- --- 9,17 ----
- //
- // ^HISTORY:
- // 04/03/92 Brad Appleton <brad@ssd.csd.harris.com> Created
- + //
- + // 03/03/93 Brad Appleton <brad@ssd.csd.harris.com>
- + // - Modified for patch 1
- //-^^---------------------------------------------------------------------
-
- #include "cmdline.h"
- ***************
- *** 21,33 ****
- // file that makes up this version of the project.
- //
- static const char ident[] =
- ! "@(#)SMS task: cmdline-1.00" ;
-
-
- // Release and patchlevel information
- #define CMDLINE_RELEASE 1
- ! #define CMDLINE_PATCHLEVEL 0
- ! #define CMDLINE_IDENT "@(#)CmdLine 1.00"
-
- unsigned
- CmdLine::release(void) { return CMDLINE_RELEASE; }
- --- 24,36 ----
- // file that makes up this version of the project.
- //
- static const char ident[] =
- ! "@(#)SMS task: cmdline-1.01" ;
-
-
- // Release and patchlevel information
- #define CMDLINE_RELEASE 1
- ! #define CMDLINE_PATCHLEVEL 1
- ! #define CMDLINE_IDENT "@(#)CmdLine 1.01"
-
- unsigned
- CmdLine::release(void) { return CMDLINE_RELEASE; }
- *** src/lib/private.c.OLD Fri Mar 26 10:50:51 1993
- --- src/lib/private.c Wed Mar 3 10:03:01 1993
- ***************
- *** 15,20 ****
- --- 15,23 ----
- //
- // ^HISTORY:
- // 01/09/92 Brad Appleton <brad@ssd.csd.harris.com> Created
- + //
- + // 03/03/93 Brad Appleton <brad@ssd.csd.harris.com>
- + // - Added exit_handler() and quit() member-functions to CmdLine
- //-^^---------------------------------------------------------------------
-
- #include <iostream.h>
- ***************
- *** 96,102 ****
- // with the argument "cmdarg".
- //
- // ^ALGORITHM:
- ! // - if this is a cmdargUsage argument then print usage and call exit(3C)
- // - call the operator() of "cmdarg" and save the result.
- // - if the above call returned SUCCESS then set the GIVEN and VALGIVEN
- // flags of the argument.
- --- 99,105 ----
- // with the argument "cmdarg".
- //
- // ^ALGORITHM:
- ! // - if this is a cmdargUsage argument then print usage and call quit()
- // - call the operator() of "cmdarg" and save the result.
- // - if the above call returned SUCCESS then set the GIVEN and VALGIVEN
- // flags of the argument.
- ***************
- *** 107,119 ****
- int
- CmdLine::handle_arg(CmdArg * cmdarg, const char * & arg)
- {
- ! int bad_val ;
-
- // call the argument compiler
- const char * save_arg = arg ; // just in case someone forgets to set it
- ! bad_val = (*cmdarg)(arg, *this);
- if (! bad_val) {
- cmdarg->set(CmdArg::GIVEN) ;
- if (arg != save_arg) {
- cmdarg->set(CmdArg::VALGIVEN) ;
- }
- --- 110,123 ----
- int
- CmdLine::handle_arg(CmdArg * cmdarg, const char * & arg)
- {
- ! ++cmd_nargs_parsed; // update the number of parsed args
-
- // call the argument compiler
- const char * save_arg = arg ; // just in case someone forgets to set it
- ! int bad_val = (*cmdarg)(arg, *this);
- if (! bad_val) {
- cmdarg->set(CmdArg::GIVEN) ;
- + cmdarg->sequence(cmd_nargs_parsed) ;
- if (arg != save_arg) {
- cmdarg->set(CmdArg::VALGIVEN) ;
- }
- ***************
- *** 397,403 ****
- //
- // ^SIDE-EFFECTS:
- // - modifies the status of "cmd".
- ! // - terminates execution by calling exit(3C) if cmd_NOABORT is NOT
- // set and a required argument (that was not properly supplied by
- // the user) is not given.
- // - prints on stderr if an argument is missing and cmd_QUIET is NOT set.
- --- 401,407 ----
- //
- // ^SIDE-EFFECTS:
- // - modifies the status of "cmd".
- ! // - terminates execution by calling quit() if cmd_NOABORT is NOT
- // set and a required argument (that was not properly supplied by
- // the user) is not given.
- // - prints on stderr if an argument is missing and cmd_QUIET is NOT set.
- *** src/lib/states.h.OLD Fri Mar 26 10:50:57 1993
- --- src/lib/states.h Mon Feb 22 14:24:12 1993
- ***************
- *** 56,69 ****
- --- 56,81 ----
- cmd_TOK_REQUIRED = 0x01, // is the "wanted" token required?
-
- cmd_WANT_VAL = 0x02, // are we expecting a value?
- + #ifndef __gplusplus
- cmd_NEED_VAL = (cmd_WANT_VAL | cmd_TOK_REQUIRED),
- + #else
- + cmd_NEED_VAL = 0x03,
- + #endif
-
- #ifdef vms_style
- cmd_WANT_VALSEP = 0x04, // are we expecting ':' or '='
- + # ifndef __gplusplus
- cmd_NEED_VALSEP = (cmd_WANT_VALSEP | cmd_TOK_REQUIRED),
- + # else
- + cmd_NEED_VALSEP = 0x05,
- + # endif
-
- cmd_WANT_LISTSEP = 0x08, // are we expecting ',' or '+'
- + # ifndef __gplusplus
- cmd_NEED_LISTSEP = (cmd_WANT_LISTSEP | cmd_TOK_REQUIRED),
- + # else
- + cmd_NEED_LISTSEP = 0x09,
- + # endif
- #endif
- } ;
-
- *** src/lib/unix.c.OLD Fri Mar 26 10:51:03 1993
- --- src/lib/unix.c Wed Mar 3 14:20:20 1993
- ***************
- *** 16,21 ****
- --- 16,24 ----
- //
- // ^HISTORY:
- // 01/09/92 Brad Appleton <brad@ssd.csd.harris.com> Created
- + //
- + // 03/01/93 Brad Appleton <brad@ssd.csd.harris.com>
- + // - Added ALLOW_PLUS to list of CmdLine configuration flags
- //-^^---------------------------------------------------------------------
-
- #include <iostream.h>
- ***************
- *** 27,34 ****
- #include "cmdline.h"
- #include "states.h"
-
- ! // Prefix string used for short options
- ! static const char OPT_PFX[] = "-" ;
-
- // Function to tell us if an argument looks like an option
- inline static int
- --- 30,38 ----
- #include "cmdline.h"
- #include "states.h"
-
- ! //
- ! // Some Helper function for getting and recognizing prefixes
- ! //
-
- // Function to tell us if an argument looks like an option
- inline static int
- ***************
- *** 36,60 ****
- return ((*(s) == '-') && ((*((s)+1) != '-')) && ((*((s)+1) != '\0'))) ;
- }
-
- ! // Need a prefix string for a long-option and a function to tell us
- ! // if an argument looks like a long-option as well.
- ! //
- ! #ifdef USE_PLUS
- ! static const char KWD_PFX[] = "+" ;
-
- - inline static int
- - isKEYWORD(const char *s) {
- - return ((*(s) == '+') && ((*((s)+1) != '\0'))) ;
- - }
- - #else
- - static const char KWD_PFX[] = "--" ;
-
- ! inline static int
- ! isKEYWORD(const char *s) {
- ! return ((*(s) == '-') && (*((s)+1) == '-') && (*((s)+2) != '\0')) ;
- ! }
- ! #endif
-
- // Need to know when an argument means "end-of-options"
- inline static int
- isENDOPTIONS(const char *s) {
- --- 40,64 ----
- return ((*(s) == '-') && ((*((s)+1) != '-')) && ((*((s)+1) != '\0'))) ;
- }
-
- ! // Function to return the option-prefix
- ! inline static const char *
- ! OptionPrefix(void) { return "-" ; }
-
-
- ! // Function to tell us if an argument looks like a long-option.
- ! //
- ! // NOTE: allowing "+" does not preclude the use of "--"
- ! //
- ! inline static int
- ! isKEYWORD(const char *s, int allow_plus) {
- ! return (((*(s) == '-') && (*((s)+1) == '-') && (*((s)+2) != '\0')) ||
- ! (allow_plus && (*(s) == '+') && ((*((s)+1) != '\0')))) ;
- ! }
-
- + // Function to return the long-option prefix
- + inline static const char *
- + KeywordPrefix(int allow_plus) { return (allow_plus) ? "+" : "--" ; }
- +
- // Need to know when an argument means "end-of-options"
- inline static int
- isENDOPTIONS(const char *s) {
- ***************
- *** 61,67 ****
- --- 65,75 ----
- return ((*(s) == '-') && (*((s)+1) == '-') && (*((s)+2) == '\0')) ;
- }
-
- + // Function to return the "end-of-options" string
- + inline static const char *
- + EndOptions(void) { return "--" ; }
-
- +
- //-------
- // ^FUNCTION: CmdLine::parse_option - parse a Unix option
- //
- ***************
- *** 140,146 ****
- }
- }
- if (! (cmd_flags & QUIET)) {
- ! error() << "unknown option \"" << OPT_PFX << char(*arg)
- << "\"." << endl ;
- }
- rc |= BAD_OPTION ;
- --- 148,154 ----
- }
- }
- if (! (cmd_flags & QUIET)) {
- ! error() << "unknown option \"" << OptionPrefix() << char(*arg)
- << "\"." << endl ;
- }
- rc |= BAD_OPTION ;
- ***************
- *** 164,170 ****
- if (cmdarg->syntax() & CmdArg::isVALREQ) {
- if (! (cmd_flags & QUIET)) {
- error() << "value required in same argument for "
- ! << OPT_PFX << char(cmdarg->char_name())
- << " option." << endl;
- }
- rc |= (VAL_MISSING | VAL_NOTSTICKY) ;
- --- 172,178 ----
- if (cmdarg->syntax() & CmdArg::isVALREQ) {
- if (! (cmd_flags & QUIET)) {
- error() << "value required in same argument for "
- ! << OptionPrefix() << char(cmdarg->char_name())
- << " option." << endl;
- }
- rc |= (VAL_MISSING | VAL_NOTSTICKY) ;
- ***************
- *** 204,210 ****
- (cmdarg->syntax() & CmdArg::isVALSEP)) {
- if (! (cmd_flags & QUIET)) {
- error() << "value required in separate argument for "
- ! << OPT_PFX << char(cmdarg->char_name())
- << " option." << endl;
- }
- rc |= (VAL_MISSING | VAL_NOTSEP) ;
- --- 212,218 ----
- (cmdarg->syntax() & CmdArg::isVALSEP)) {
- if (! (cmd_flags & QUIET)) {
- error() << "value required in separate argument for "
- ! << OptionPrefix() << char(cmdarg->char_name())
- << " option." << endl;
- }
- rc |= (VAL_MISSING | VAL_NOTSEP) ;
- ***************
- *** 285,290 ****
- --- 293,300 ----
- int ambiguous = 0, len = -1, bad_val;
- const char * val = NULL ;
-
- + int plus = (cmd_flags & ALLOW_PLUS) ; // Can we use "+"?
- +
- // see if we left an argument dangling without a value
- ck_need_val() ;
-
- ***************
- *** 312,318 ****
- }
- if (! (cmd_flags & QUIET)) {
- error() << ((ambiguous) ? "ambiguous" : "unknown") << " option "
- ! << "\"" << ((cmd_flags & KWDS_ONLY) ? OPT_PFX : KWD_PFX)
- << arg << "\"." << endl ;
- }
- rc |= ((ambiguous) ? KWD_AMBIGUOUS : BAD_KEYWORD) ;
- --- 322,329 ----
- }
- if (! (cmd_flags & QUIET)) {
- error() << ((ambiguous) ? "ambiguous" : "unknown") << " option "
- ! << "\"" << ((cmd_flags & KWDS_ONLY) ? OptionPrefix()
- ! : KeywordPrefix(plus))
- << arg << "\"." << endl ;
- }
- rc |= ((ambiguous) ? KWD_AMBIGUOUS : BAD_KEYWORD) ;
- ***************
- *** 334,340 ****
- if (cmdarg->syntax() & CmdArg::isVALREQ) {
- if (! (cmd_flags & QUIET)) {
- error() << "value required in same argument for "
- ! << ((cmd_flags & KWDS_ONLY) ? OPT_PFX : KWD_PFX)
- << cmdarg->keyword_name() << " option." << endl;
- }
- rc |= (VAL_MISSING | VAL_NOTSTICKY) ;
- --- 345,352 ----
- if (cmdarg->syntax() & CmdArg::isVALREQ) {
- if (! (cmd_flags & QUIET)) {
- error() << "value required in same argument for "
- ! << ((cmd_flags & KWDS_ONLY) ? OptionPrefix()
- ! : KeywordPrefix(plus))
- << cmdarg->keyword_name() << " option." << endl;
- }
- rc |= (VAL_MISSING | VAL_NOTSTICKY) ;
- ***************
- *** 374,380 ****
- (cmdarg->syntax() & CmdArg::isVALSEP)) {
- if (! (cmd_flags & QUIET)) {
- error() << "value required in separate argument for "
- ! << ((cmd_flags & KWDS_ONLY) ? OPT_PFX : KWD_PFX)
- << cmdarg->keyword_name() << " option." << endl;
- }
- rc |= (VAL_MISSING | VAL_NOTSEP) ;
- --- 386,393 ----
- (cmdarg->syntax() & CmdArg::isVALSEP)) {
- if (! (cmd_flags & QUIET)) {
- error() << "value required in separate argument for "
- ! << ((cmd_flags & KWDS_ONLY) ? OptionPrefix()
- ! : KeywordPrefix(plus))
- << cmdarg->keyword_name() << " option." << endl;
- }
- rc |= (VAL_MISSING | VAL_NOTSEP) ;
- ***************
- *** 544,549 ****
- --- 557,564 ----
- {
- if (arg == NULL) return cmd_status ;
-
- + int plus = (cmd_flags & ALLOW_PLUS) ; // Can we use "+"?
- +
- if (cmd_parse_state & cmd_TOK_REQUIRED) {
- // If a required value is expected, then this argument MUST be
- // the value (even if it looks like an option
- ***************
- *** 559,570 ****
- cmd_status |= parse_option(arg) ;
- }
- } else if ((! (cmd_flags & OPTS_ONLY))
- ! && isKEYWORD(arg) && (! (cmd_state & cmd_END_OF_OPTIONS))) {
- cmd_state |= cmd_KEYWORDS_USED ;
- ! ++arg ; // skip over '+' keyword prefix
- ! #ifndef USE_PLUS
- ! ++arg ; // skip over '--' keyword prefix
- ! #endif
- cmd_status |= parse_keyword(arg) ;
- } else if (isENDOPTIONS(arg) && (! (cmd_state & cmd_END_OF_OPTIONS))) {
- cmd_state |= cmd_END_OF_OPTIONS ;
- --- 574,586 ----
- cmd_status |= parse_option(arg) ;
- }
- } else if ((! (cmd_flags & OPTS_ONLY))
- ! && isKEYWORD(arg, plus) && (! (cmd_state & cmd_END_OF_OPTIONS))) {
- cmd_state |= cmd_KEYWORDS_USED ;
- ! if (*arg == '+') {
- ! ++arg ; // skip over '+' keyword prefix
- ! } else {
- ! arg += 2 ; // skip over '--' keyword prefix
- ! }
- cmd_status |= parse_keyword(arg) ;
- } else if (isENDOPTIONS(arg) && (! (cmd_state & cmd_END_OF_OPTIONS))) {
- cmd_state |= cmd_END_OF_OPTIONS ;
- ***************
- *** 611,624 ****
- ostream &
- CmdLine::arg_error(const char * error_str, const CmdArg * cmdarg) const
- {
- ostream & os = error() << error_str << char(' ') ;
-
- if (cmdarg->flags() & CmdArg::GIVEN) {
- if (cmdarg->flags() & CmdArg::KEYWORD) {
- ! os << ((cmd_flags & KWDS_ONLY) ? OPT_PFX : KWD_PFX)
- << cmdarg->keyword_name() << " option" ;
- } else if (cmdarg->flags() & CmdArg::OPTION) {
- ! os << OPT_PFX << (char)cmdarg->char_name() << " option" ;
- } else {
- os << cmdarg->value_name() << " argument" ;
- }
- --- 627,643 ----
- ostream &
- CmdLine::arg_error(const char * error_str, const CmdArg * cmdarg) const
- {
- + int plus = (cmd_flags & ALLOW_PLUS) ; // Can we use "+"?
- +
- ostream & os = error() << error_str << char(' ') ;
-
- if (cmdarg->flags() & CmdArg::GIVEN) {
- if (cmdarg->flags() & CmdArg::KEYWORD) {
- ! os << ((cmd_flags & KWDS_ONLY) ? OptionPrefix()
- ! : KeywordPrefix(plus))
- << cmdarg->keyword_name() << " option" ;
- } else if (cmdarg->flags() & CmdArg::OPTION) {
- ! os << OptionPrefix() << (char)cmdarg->char_name() << " option" ;
- } else {
- os << cmdarg->value_name() << " argument" ;
- }
- ***************
- *** 627,635 ****
- os << cmdarg->value_name() << " argument" ;
- } else {
- if (cmd_flags & KWDS_ONLY) {
- ! os << OPT_PFX << cmdarg->keyword_name() << " option" ;
- } else {
- ! os << OPT_PFX << (char)cmdarg->char_name() << " option" ;
- }
- }
- }
- --- 646,654 ----
- os << cmdarg->value_name() << " argument" ;
- } else {
- if (cmd_flags & KWDS_ONLY) {
- ! os << OptionPrefix() << cmdarg->keyword_name() << " option" ;
- } else {
- ! os << OptionPrefix() << (char)cmdarg->char_name() << " option" ;
- }
- }
- }
- ***************
- *** 686,691 ****
- --- 705,711 ----
- ostrstream oss(buf, bufsize);
- *buf = '\0';
-
- + int plus = (cmd_flags & ALLOW_PLUS) ; // Can we use "+"?
- char optchar = cmdarg->char_name();
- const char * keyword = cmdarg->keyword_name();
-
- ***************
- *** 723,734 ****
- (cmdarg->syntax() & CmdArg::isVALSTICKY))
- {
- if (cmdarg->syntax() & CmdArg::isVALOPT) {
- ! oss << OPT_PFX << char(optchar) << char('[') << cmdarg->value_name()
- ! << "]|" << KWD_PFX << keyword << "[=" << cmdarg->value_name()
- ! << char(']') ;
- } else {
- ! oss << OPT_PFX << optchar << cmdarg->value_name() << char('|')
- ! << KWD_PFX << keyword << char('=') << cmdarg->value_name() ;
- }
- if ((level == VERBOSE_USAGE) && (cmdarg->syntax() & CmdArg::isLIST)) {
- oss << " ..." ;
- --- 743,755 ----
- (cmdarg->syntax() & CmdArg::isVALSTICKY))
- {
- if (cmdarg->syntax() & CmdArg::isVALOPT) {
- ! oss << OptionPrefix() << char(optchar) << char('[')
- ! << cmdarg->value_name() << "]|" << KeywordPrefix(plus)
- ! << keyword << "[=" << cmdarg->value_name() << char(']') ;
- } else {
- ! oss << OptionPrefix() << optchar << cmdarg->value_name()
- ! << char('|') << KeywordPrefix(plus) << keyword << char('=')
- ! << cmdarg->value_name() ;
- }
- if ((level == VERBOSE_USAGE) && (cmdarg->syntax() & CmdArg::isLIST)) {
- oss << " ..." ;
- ***************
- *** 743,758 ****
- if (! (cmdarg->syntax() & CmdArg::isPOS)) {
- switch(syntax) {
- case cmd_OPTS_ONLY :
- ! oss << OPT_PFX << char(optchar) ;
- break ;
-
- case cmd_KWDS_ONLY :
- ! oss << ((cmd_flags & KWDS_ONLY) ? OPT_PFX : KWD_PFX) << keyword ;
- break ;
-
- case cmd_BOTH :
- ! oss << OPT_PFX << char(optchar) << char('|')
- ! << KWD_PFX << keyword ;
- break ;
-
- default :
- --- 764,780 ----
- if (! (cmdarg->syntax() & CmdArg::isPOS)) {
- switch(syntax) {
- case cmd_OPTS_ONLY :
- ! oss << OptionPrefix() << char(optchar) ;
- break ;
-
- case cmd_KWDS_ONLY :
- ! oss << ((cmd_flags & KWDS_ONLY) ? OptionPrefix()
- ! : KeywordPrefix(plus)) << keyword ;
- break ;
-
- case cmd_BOTH :
- ! oss << OptionPrefix() << char(optchar) << char('|')
- ! << KeywordPrefix(plus) << keyword ;
- break ;
-
- default :
- *** src/lib/usage.c.OLD Fri Mar 26 10:51:13 1993
- --- src/lib/usage.c Mon Mar 1 10:48:48 1993
- ***************
- *** 8,13 ****
- --- 8,16 ----
- //
- // ^HISTORY:
- // 01/09/92 Brad Appleton <brad@ssd.csd.harris.com> Created
- + //
- + // 03/01/93 Brad Appleton <brad@ssd.csd.harris.com>
- + // - Added cmd_description field to CmdLine
- //-^^---------------------------------------------------------------------
-
- #include <iostream.h>
- ***************
- *** 304,309 ****
- --- 307,319 ----
- // now print argument descriptions
- os << "\n" ;
- print_descriptions(cmd_syntax, os, max_cols, longest) ;
- +
- + // now print the command-description if there is one
- + if (cmd_description && *cmd_description) {
- + os << "\nDescription:" << endl;
- + strindent(os, max_cols, 8, "", 0, cmd_description);
- + }
- +
- return os;
- }
-
-