From 68f03b3ea7cd6b2df10d395caf52652da7ca0df6 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Thu, 3 Apr 2003 10:16:13 +0000 Subject: Cleanup options. Improve usage message. Improve output of options like --key-positions=1,2,$. --- ChangeLog | 8 +++ src/options.cc | 155 +++++++++++++++++++++++++++++++-------------------------- src/options.h | 102 ++++++++++++++++++++----------------- 3 files changed, 148 insertions(+), 117 deletions(-) diff --git a/ChangeLog b/ChangeLog index 746d66e..52e34d0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,13 @@ 2002-12-10 Bruno Haible + * src/options.h: Reorder enum values. + (Options::short_usage, Options::long_usage): Make static. + * src/options.cc (Options::short_usage); No longer print a monster + usage line. + (Options::print_options): Improve output of options like + --key-positions=1,2,$. + (Options::~Options): Update. + * src/options.h (UPPERLOWER): New enum value. * src/options.cc (Options::long_usage): Document option --ignore-case. (Options::~Options): Update. diff --git a/src/options.cc b/src/options.cc index 7e533cd..2439ae6 100644 --- a/src/options.cc +++ b/src/options.cc @@ -61,18 +61,17 @@ static const char *const DEFAULT_WORDLIST_NAME = "wordlist"; /* Default delimiters that separate keywords from their attributes. */ static const char *const DEFAULT_DELIMITERS = ","; -/* Prints program usage to given stream. */ +/* Prints program usage to given stream. */ void -Options::short_usage (FILE * stream) const +Options::short_usage (FILE * stream) { - fprintf (stream, "Usage: %s [-cCdDef[num]FGhHiIjkKlLmnNoPrsStTvWZ7] [input-file]\n" - "Try '%s --help' for more information.\n", - program_name, program_name); + fprintf (stream, + "Try '%s --help' for more information.\n", program_name); } void -Options::long_usage (FILE * stream) const +Options::long_usage (FILE * stream) { fprintf (stream, "GNU 'gperf' generates perfect hash functions.\n"); @@ -254,11 +253,9 @@ Options::long_usage (FILE * stream) const void Options::print_options () const { - int i; - printf ("/* Command-line: "); - for (i = 0; i < _argument_count; i++) + for (int i = 0; i < _argument_count; i++) { const char *arg = _argument_vector[i]; @@ -272,6 +269,20 @@ Options::print_options () const putchar (*arg); arg++; } + else if (*arg == '-') + { + do + { + putchar (*arg); + arg++; + } + while (*arg >= 'A' && *arg <= 'Z' || *arg >= 'a' && *arg <= 'z' || *arg == '-'); + if (*arg == '=') + { + putchar (*arg); + arg++; + } + } } if (strpbrk (arg, "\t\n !\"#$&'()*;<>?[\\]`{|}~") != NULL) { @@ -419,7 +430,7 @@ PositionStringParser::nextPosition () /* ------------------------------------------------------------------------- */ -/* Sets the default Options. */ +/* Sets the default Options. */ Options::Options () : _option_word (C), @@ -442,32 +453,33 @@ Options::Options () { } -/* Dumps option status when debug is set. */ +/* Dumps option status when debugging is enabled. */ Options::~Options () { if (_option_word & DEBUG) { fprintf (stderr, "\ndumping Options:" - "\nDEBUG is.......: %s" "\nTYPE is........: %s" - "\nRANDOM is......: %s" - "\nSWITCH is......: %s" - "\nNOLENGTH is....: %s" - "\nLENTABLE is....: %s" - "\nDUP is.........: %s" - "\nCOMP is........: %s" - "\nNOTYPE is......: %s" - "\nGLOBAL is......: %s" - "\nCONST is.......: %s" + "\nUPPERLOWER is..: %s" "\nKRC is.........: %s" "\nC is...........: %s" "\nANSIC is.......: %s" "\nCPLUSPLUS is...: %s" + "\nSEVENBIT is....: %s" + "\nLENTABLE is....: %s" + "\nCOMP is........: %s" + "\nCONST is.......: %s" "\nENUM is........: %s" "\nINCLUDE is.....: %s" - "\nSEVENBIT is....: %s" - "\nUPPERLOWER is..: %s" + "\nGLOBAL is......: %s" + "\nSHAREDLIB is...: %s" + "\nSWITCH is......: %s" + "\nNOTYPE is......: %s" + "\nDUP is.........: %s" + "\nNOLENGTH is....: %s" + "\nRANDOM is......: %s" + "\nDEBUG is.......: %s" "\nlookup function name = %s" "\nhash function name = %s" "\nword list name = %s" @@ -479,25 +491,26 @@ Options::~Options () "\ninitial associated value = %d" "\ndelimiters = %s" "\nnumber of switch statements = %d\n", - _option_word & DEBUG ? "enabled" : "disabled", _option_word & TYPE ? "enabled" : "disabled", - _option_word & RANDOM ? "enabled" : "disabled", - _option_word & SWITCH ? "enabled" : "disabled", - _option_word & NOLENGTH ? "enabled" : "disabled", - _option_word & LENTABLE ? "enabled" : "disabled", - _option_word & DUP ? "enabled" : "disabled", - _option_word & COMP ? "enabled" : "disabled", - _option_word & NOTYPE ? "enabled" : "disabled", - _option_word & GLOBAL ? "enabled" : "disabled", - _option_word & CONST ? "enabled" : "disabled", + _option_word & UPPERLOWER ? "enabled" : "disabled", _option_word & KRC ? "enabled" : "disabled", _option_word & C ? "enabled" : "disabled", _option_word & ANSIC ? "enabled" : "disabled", _option_word & CPLUSPLUS ? "enabled" : "disabled", + _option_word & SEVENBIT ? "enabled" : "disabled", + _option_word & LENTABLE ? "enabled" : "disabled", + _option_word & COMP ? "enabled" : "disabled", + _option_word & CONST ? "enabled" : "disabled", _option_word & ENUM ? "enabled" : "disabled", _option_word & INCLUDE ? "enabled" : "disabled", - _option_word & SEVENBIT ? "enabled" : "disabled", - _option_word & UPPERLOWER ? "enabled" : "disabled", + _option_word & GLOBAL ? "enabled" : "disabled", + _option_word & SHAREDLIB ? "enabled" : "disabled", + _option_word & SWITCH ? "enabled" : "disabled", + _option_word & NOTYPE ? "enabled" : "disabled", + _option_word & DUP ? "enabled" : "disabled", + _option_word & NOLENGTH ? "enabled" : "disabled", + _option_word & RANDOM ? "enabled" : "disabled", + _option_word & DEBUG ? "enabled" : "disabled", _function_name, _hash_name, _wordlist_name, _slot_name, _initializer_suffix, _asso_iterations, _jump, _size_multiple, _initial_asso_value, _delimiters, _total_switches); @@ -606,7 +619,7 @@ Options::set_delimiters (const char *delimiters) } -/* Parses the command line Options and sets appropriate flags in option_word. */ +/* Parses the command line Options and sets appropriate flags in option_word. */ static const struct option long_options[] = { @@ -668,26 +681,26 @@ Options::parse_options (int argc, char *argv[]) { switch (option_char) { - case 'a': /* Generated code uses the ANSI prototype format. */ - break; /* This is now the default. */ - case 'c': /* Generate strncmp rather than strcmp. */ + case 'a': /* Generated code uses the ANSI prototype format. */ + break; /* This is now the default. */ + case 'c': /* Generate strncmp rather than strcmp. */ { _option_word |= COMP; break; } - case 'C': /* Make the generated tables readonly (const). */ + case 'C': /* Make the generated tables readonly (const). */ { _option_word |= CONST; break; } - case 'd': /* Enable debugging option. */ + case 'd': /* Enable debugging option. */ { _option_word |= DEBUG; fprintf (stderr, "Starting program %s, version %s, with debugging on.\n", program_name, version_string); break; } - case 'D': /* Enable duplicate option. */ + case 'D': /* Enable duplicate option. */ { _option_word |= DUP; break; @@ -702,31 +715,31 @@ Options::parse_options (int argc, char *argv[]) _option_word |= ENUM; break; } - case 'f': /* Generate the hash table "fast". */ + case 'f': /* Generate the hash table "fast". */ break; /* Not needed any more. */ case 'F': { _initializer_suffix = /*getopt*/optarg; break; } - case 'g': /* Use the 'inline' keyword for generated sub-routines, ifdef __GNUC__. */ - break; /* This is now the default. */ - case 'G': /* Make the keyword table a global variable. */ + case 'g': /* Use the 'inline' keyword for generated sub-routines, ifdef __GNUC__. */ + break; /* This is now the default. */ + case 'G': /* Make the keyword table a global variable. */ { _option_word |= GLOBAL; break; } - case 'h': /* Displays a list of helpful Options to the user. */ + case 'h': /* Displays a list of helpful Options to the user. */ { long_usage (stdout); exit (0); } - case 'H': /* Sets the name for the hash function */ + case 'H': /* Sets the name for the hash function. */ { _hash_name = /*getopt*/optarg; break; } - case 'i': /* Sets the initial value for the associated values array. */ + case 'i': /* Sets the initial value for the associated values array. */ { if ((_initial_asso_value = atoi (/*getopt*/optarg)) < 0) fprintf (stderr, "Initial value %d should be non-zero, ignoring and continuing.\n", _initial_asso_value); @@ -734,12 +747,12 @@ Options::parse_options (int argc, char *argv[]) fprintf (stderr, "warning, -r option superceeds -i, ignoring -i option and continuing\n"); break; } - case 'I': /* Enable #include statements. */ + case 'I': /* Enable #include statements. */ { _option_word |= INCLUDE; break; } - case 'j': /* Sets the jump value, must be odd for later algorithms. */ + case 'j': /* Sets the jump value, must be odd for later algorithms. */ { if ((_jump = atoi (/*getopt*/optarg)) < 0) { @@ -751,7 +764,7 @@ Options::parse_options (int argc, char *argv[]) fprintf (stderr, "Jump value %d should be odd, adding 1 and continuing...\n", _jump++); break; } - case 'k': /* Sets key positions used for hash function. */ + case 'k': /* Sets key positions used for hash function. */ { _option_word |= POSITIONS; const int BAD_VALUE = -2; @@ -809,17 +822,17 @@ Options::parse_options (int argc, char *argv[]) } break; } - case 'K': /* Make this the keyname for the keyword component field. */ + case 'K': /* Make this the keyname for the keyword component field. */ { _slot_name = /*getopt*/optarg; break; } - case 'l': /* Create length table to avoid extra string compares. */ + case 'l': /* Create length table to avoid extra string compares. */ { _option_word |= LENTABLE; break; } - case 'L': /* Deal with different generated languages. */ + case 'L': /* Deal with different generated languages. */ { _language = NULL; set_language (/*getopt*/optarg); @@ -834,35 +847,35 @@ Options::parse_options (int argc, char *argv[]) } break; } - case 'n': /* Don't include the length when computing hash function. */ + case 'n': /* Don't include the length when computing hash function. */ { _option_word |= NOLENGTH; break; } - case 'N': /* Make generated lookup function name be optarg */ + case 'N': /* Make generated lookup function name be optarg. */ { _function_name = /*getopt*/optarg; break; } - case 'o': /* Order input by frequency of key set occurrence. */ + case 'o': /* Order input by frequency of key set occurrence. */ break; /* Not needed any more. */ case 'O': /* Optimized choice during collision resolution. */ break; /* Not needed any more. */ - case 'p': /* Generated lookup function a pointer instead of int. */ - break; /* This is now the default. */ + case 'p': /* Generated lookup function a pointer instead of int. */ + break; /* This is now the default. */ case 'P': /* Optimize for position-independent code. */ { _option_word |= SHAREDLIB; break; } - case 'r': /* Utilize randomness to initialize the associated values table. */ + case 'r': /* Utilize randomness to initialize the associated values table. */ { _option_word |= RANDOM; if (_initial_asso_value != 0) - fprintf (stderr, "warning, -r option superceeds -i, disabling -i option and continuing\n"); + fprintf (stderr, "warning, -r option supersedes -i, disabling -i option and continuing\n"); break; } - case 's': /* Range of associated values, determines size of final table. */ + case 's': /* Range of associated values, determines size of final table. */ { float numerator; float denominator = 1; @@ -904,7 +917,7 @@ Options::parse_options (int argc, char *argv[]) fprintf (stderr, "Size multiple %g is extremely small, did you really mean this?! (try '%s --help' for help)\n", _size_multiple, program_name); break; } - case 'S': /* Generate switch statement output, rather than lookup table. */ + case 'S': /* Generate switch statement output, rather than lookup table. */ { _option_word |= SWITCH; _total_switches = atoi (/*getopt*/optarg); @@ -916,17 +929,17 @@ Options::parse_options (int argc, char *argv[]) } break; } - case 't': /* Enable the TYPE mode, allowing arbitrary user structures. */ + case 't': /* Enable the TYPE mode, allowing arbitrary user structures. */ { _option_word |= TYPE; break; } - case 'T': /* Don't print structure definition. */ + case 'T': /* Don't print structure definition. */ { _option_word |= NOTYPE; break; } - case 'v': /* Print out the version and quit. */ + case 'v': /* Print out the version and quit. */ fprintf (stdout, "GNU gperf %s\n", version_string); fprintf (stdout, "Copyright (C) %s Free Software Foundation, Inc.\n\ This is free software; see the source for copying conditions. There is NO\n\ @@ -936,22 +949,22 @@ warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\ fprintf (stdout, "Written by %s and %s.\n", "Douglas C. Schmidt", "Bruno Haible"); exit (0); - case 'W': /* Sets the name for the hash table array */ + case 'W': /* Sets the name for the hash table array. */ { _wordlist_name = /*getopt*/optarg; break; } - case 'Z': /* Set the class name. */ + case 'Z': /* Set the class name. */ { _class_name = /*getopt*/optarg; break; } - case '7': /* Assume 7-bit characters. */ + case '7': /* Assume 7-bit characters. */ { _option_word |= SEVENBIT; break; } - case CHAR_MAX + 1: /* Set the output file name. */ + case CHAR_MAX + 1: /* Set the output file name. */ { _output_file_name = /*getopt*/optarg; break; diff --git a/src/options.h b/src/options.h index 4dda513..7eb7fe1 100644 --- a/src/options.h +++ b/src/options.h @@ -32,79 +32,89 @@ #include #include "positions.h" -/* Enumeration of the possible boolean options. */ +/* Enumeration of the possible boolean options. */ enum Option_Type { - /* Enable debugging (prints diagnostics to stderr). */ - DEBUG = 1 << 0, + /* --- Input file interpretation --- */ - /* Use the given key positions. */ - POSITIONS = 1 << 1, + /* Handle user-defined type structured keyword input. */ + TYPE = 1 << 0, - /* Use all characters in hash function. */ - ALLCHARS = 1 << 2, + /* Ignore case of ASCII characters. */ + UPPERLOWER = 1 << 1, - /* Handle user-defined type structured keyword input. */ - TYPE = 1 << 3, + /* --- Language for the output code --- */ - /* Randomly initialize the associated values table. */ - RANDOM = 1 << 4, + /* Generate K&R C code: no prototypes, no const. */ + KRC = 1 << 2, - /* Generate switch output to save space. */ - SWITCH = 1 << 5, + /* Generate C code: no prototypes, but const (user can #define it away). */ + C = 1 << 3, - /* Don't include keyword length in hash computations. */ - NOLENGTH = 1 << 6, + /* Generate ISO/ANSI C code: prototypes and const, but no class. */ + ANSIC = 1 << 4, + + /* Generate C++ code: prototypes, const, class, inline, enum. */ + CPLUSPLUS = 1 << 5, + + /* --- Details in the output code --- */ + + /* Assume 7-bit, not 8-bit, characters. */ + SEVENBIT = 1 << 6, /* Generate a length table for string comparison. */ LENTABLE = 1 << 7, - /* Handle duplicate hash values for keywords. */ - DUP = 1 << 8, + /* Generate strncmp rather than strcmp. */ + COMP = 1 << 8, - /* Don't include user-defined type definition in output -- it's already - defined elsewhere. */ - NOTYPE = 1 << 9, + /* Make the generated tables readonly (const). */ + CONST = 1 << 9, - /* Generate strncmp rather than strcmp. */ - COMP = 1 << 10, + /* Use enum for constants. */ + ENUM = 1 << 10, + + /* Generate #include statements. */ + INCLUDE = 1 << 11, /* Make the keyword table a global variable. */ - GLOBAL = 1 << 11, + GLOBAL = 1 << 12, - /* Make the generated tables readonly (const). */ - CONST = 1 << 12, + /* Optimize for position-independent code. */ + SHAREDLIB = 1 << 13, - /* Generate K&R C code: no prototypes, no const. */ - KRC = 1 << 13, + /* Generate switch output to save space. */ + SWITCH = 1 << 14, - /* Generate C code: no prototypes, but const (user can #define it away). */ - C = 1 << 14, + /* Don't include user-defined type definition in output -- it's already + defined elsewhere. */ + NOTYPE = 1 << 15, - /* Generate ISO/ANSI C code: prototypes and const, but no class. */ - ANSIC = 1 << 15, + /* --- Algorithm employed by gperf --- */ - /* Generate C++ code: prototypes, const, class, inline, enum. */ - CPLUSPLUS = 1 << 16, + /* Use the given key positions. */ + POSITIONS = 1 << 16, - /* Use enum for constants. */ - ENUM = 1 << 17, + /* Use all characters in hash function. */ + ALLCHARS = 1 << 17, - /* Generate #include statements. */ - INCLUDE = 1 << 18, + /* Handle duplicate hash values for keywords. */ + DUP = 1 << 18, - /* Assume 7-bit, not 8-bit, characters. */ - SEVENBIT = 1 << 19, + /* Don't include keyword length in hash computations. */ + NOLENGTH = 1 << 19, - /* Optimize for position-independent code. */ - SHAREDLIB = 1 << 20, + /* Randomly initialize the associated values table. */ + RANDOM = 1 << 20, - /* Ignore case of ASCII characters. */ - UPPERLOWER = 1 << 21 + /* --- Informative output --- */ + + /* Enable debugging (prints diagnostics to stderr). */ + DEBUG = 1 << 21 }; -/* Class manager for gperf program Options. */ +/* Class manager for gperf program Options. */ class Options { @@ -193,10 +203,10 @@ public: private: /* Prints program usage to given stream. */ - void short_usage (FILE * stream) const; + static void short_usage (FILE * stream); /* Prints program usage to given stream. */ - void long_usage (FILE * stream) const; + static void long_usage (FILE * stream); /* Records count of command-line arguments. */ int _argument_count; -- cgit v1.2.1