1
0
mirror of https://git.savannah.gnu.org/git/gperf.git synced 2025-12-02 21:19:24 +00:00

Cleanup options.

Improve usage message.
Improve output of options like --key-positions=1,2,$.
This commit is contained in:
Bruno Haible
2003-04-03 10:16:13 +00:00
parent 7dfd32b736
commit 68f03b3ea7
3 changed files with 152 additions and 121 deletions

View File

@@ -1,5 +1,13 @@
2002-12-10 Bruno Haible <bruno@clisp.org> 2002-12-10 Bruno Haible <bruno@clisp.org>
* 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.h (UPPERLOWER): New enum value.
* src/options.cc (Options::long_usage): Document option --ignore-case. * src/options.cc (Options::long_usage): Document option --ignore-case.
(Options::~Options): Update. (Options::~Options): Update.

View File

@@ -64,15 +64,14 @@ static const char *const DEFAULT_DELIMITERS = ",";
/* Prints program usage to given stream. */ /* Prints program usage to given stream. */
void void
Options::short_usage (FILE * stream) const Options::short_usage (FILE * stream)
{ {
fprintf (stream, "Usage: %s [-cCdDef[num]F<initializers>GhH<hashname>i<init>Ij<jump>k<keys>K<keyname>lL<language>m<num>nN<function name>oPrs<size>S<switches>tTvW<wordlistname>Z<class name>7] [input-file]\n" fprintf (stream,
"Try '%s --help' for more information.\n", "Try '%s --help' for more information.\n", program_name);
program_name, program_name);
} }
void void
Options::long_usage (FILE * stream) const Options::long_usage (FILE * stream)
{ {
fprintf (stream, fprintf (stream,
"GNU 'gperf' generates perfect hash functions.\n"); "GNU 'gperf' generates perfect hash functions.\n");
@@ -254,11 +253,9 @@ Options::long_usage (FILE * stream) const
void void
Options::print_options () const Options::print_options () const
{ {
int i;
printf ("/* Command-line: "); printf ("/* Command-line: ");
for (i = 0; i < _argument_count; i++) for (int i = 0; i < _argument_count; i++)
{ {
const char *arg = _argument_vector[i]; const char *arg = _argument_vector[i];
@@ -272,6 +269,20 @@ Options::print_options () const
putchar (*arg); putchar (*arg);
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) if (strpbrk (arg, "\t\n !\"#$&'()*;<>?[\\]`{|}~") != NULL)
{ {
@@ -442,32 +453,33 @@ Options::Options ()
{ {
} }
/* Dumps option status when debug is set. */ /* Dumps option status when debugging is enabled. */
Options::~Options () Options::~Options ()
{ {
if (_option_word & DEBUG) if (_option_word & DEBUG)
{ {
fprintf (stderr, "\ndumping Options:" fprintf (stderr, "\ndumping Options:"
"\nDEBUG is.......: %s"
"\nTYPE is........: %s" "\nTYPE is........: %s"
"\nRANDOM is......: %s" "\nUPPERLOWER 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"
"\nKRC is.........: %s" "\nKRC is.........: %s"
"\nC is...........: %s" "\nC is...........: %s"
"\nANSIC is.......: %s" "\nANSIC is.......: %s"
"\nCPLUSPLUS is...: %s" "\nCPLUSPLUS is...: %s"
"\nSEVENBIT is....: %s"
"\nLENTABLE is....: %s"
"\nCOMP is........: %s"
"\nCONST is.......: %s"
"\nENUM is........: %s" "\nENUM is........: %s"
"\nINCLUDE is.....: %s" "\nINCLUDE is.....: %s"
"\nSEVENBIT is....: %s" "\nGLOBAL is......: %s"
"\nUPPERLOWER 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" "\nlookup function name = %s"
"\nhash function name = %s" "\nhash function name = %s"
"\nword list name = %s" "\nword list name = %s"
@@ -479,25 +491,26 @@ Options::~Options ()
"\ninitial associated value = %d" "\ninitial associated value = %d"
"\ndelimiters = %s" "\ndelimiters = %s"
"\nnumber of switch statements = %d\n", "\nnumber of switch statements = %d\n",
_option_word & DEBUG ? "enabled" : "disabled",
_option_word & TYPE ? "enabled" : "disabled", _option_word & TYPE ? "enabled" : "disabled",
_option_word & RANDOM ? "enabled" : "disabled", _option_word & UPPERLOWER ? "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 & KRC ? "enabled" : "disabled", _option_word & KRC ? "enabled" : "disabled",
_option_word & C ? "enabled" : "disabled", _option_word & C ? "enabled" : "disabled",
_option_word & ANSIC ? "enabled" : "disabled", _option_word & ANSIC ? "enabled" : "disabled",
_option_word & CPLUSPLUS ? "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 & ENUM ? "enabled" : "disabled",
_option_word & INCLUDE ? "enabled" : "disabled", _option_word & INCLUDE ? "enabled" : "disabled",
_option_word & SEVENBIT ? "enabled" : "disabled", _option_word & GLOBAL ? "enabled" : "disabled",
_option_word & UPPERLOWER ? "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, _function_name, _hash_name, _wordlist_name, _slot_name,
_initializer_suffix, _asso_iterations, _jump, _size_multiple, _initializer_suffix, _asso_iterations, _jump, _size_multiple,
_initial_asso_value, _delimiters, _total_switches); _initial_asso_value, _delimiters, _total_switches);
@@ -721,7 +734,7 @@ Options::parse_options (int argc, char *argv[])
long_usage (stdout); long_usage (stdout);
exit (0); exit (0);
} }
case 'H': /* Sets the name for the hash function */ case 'H': /* Sets the name for the hash function. */
{ {
_hash_name = /*getopt*/optarg; _hash_name = /*getopt*/optarg;
break; break;
@@ -839,7 +852,7 @@ Options::parse_options (int argc, char *argv[])
_option_word |= NOLENGTH; _option_word |= NOLENGTH;
break; break;
} }
case 'N': /* Make generated lookup function name be optarg */ case 'N': /* Make generated lookup function name be optarg. */
{ {
_function_name = /*getopt*/optarg; _function_name = /*getopt*/optarg;
break; break;
@@ -859,7 +872,7 @@ Options::parse_options (int argc, char *argv[])
{ {
_option_word |= RANDOM; _option_word |= RANDOM;
if (_initial_asso_value != 0) 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; break;
} }
case 's': /* Range of associated values, determines size of final table. */ case 's': /* Range of associated values, determines size of final table. */
@@ -936,7 +949,7 @@ warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\
fprintf (stdout, "Written by %s and %s.\n", fprintf (stdout, "Written by %s and %s.\n",
"Douglas C. Schmidt", "Bruno Haible"); "Douglas C. Schmidt", "Bruno Haible");
exit (0); 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; _wordlist_name = /*getopt*/optarg;
break; break;

View File

@@ -36,72 +36,82 @@
enum Option_Type enum Option_Type
{ {
/* Enable debugging (prints diagnostics to stderr). */ /* --- Input file interpretation --- */
DEBUG = 1 << 0,
/* Use the given key positions. */
POSITIONS = 1 << 1,
/* Use all characters in hash function. */
ALLCHARS = 1 << 2,
/* Handle user-defined type structured keyword input. */ /* Handle user-defined type structured keyword input. */
TYPE = 1 << 3, TYPE = 1 << 0,
/* Randomly initialize the associated values table. */ /* Ignore case of ASCII characters. */
RANDOM = 1 << 4, UPPERLOWER = 1 << 1,
/* Generate switch output to save space. */ /* --- Language for the output code --- */
SWITCH = 1 << 5,
/* Don't include keyword length in hash computations. */ /* Generate K&R C code: no prototypes, no const. */
NOLENGTH = 1 << 6, KRC = 1 << 2,
/* Generate C code: no prototypes, but const (user can #define it away). */
C = 1 << 3,
/* 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. */ /* Generate a length table for string comparison. */
LENTABLE = 1 << 7, LENTABLE = 1 << 7,
/* Handle duplicate hash values for keywords. */ /* Generate strncmp rather than strcmp. */
DUP = 1 << 8, COMP = 1 << 8,
/* Make the generated tables readonly (const). */
CONST = 1 << 9,
/* Use enum for constants. */
ENUM = 1 << 10,
/* Generate #include statements. */
INCLUDE = 1 << 11,
/* Make the keyword table a global variable. */
GLOBAL = 1 << 12,
/* Optimize for position-independent code. */
SHAREDLIB = 1 << 13,
/* Generate switch output to save space. */
SWITCH = 1 << 14,
/* Don't include user-defined type definition in output -- it's already /* Don't include user-defined type definition in output -- it's already
defined elsewhere. */ defined elsewhere. */
NOTYPE = 1 << 9, NOTYPE = 1 << 15,
/* Generate strncmp rather than strcmp. */ /* --- Algorithm employed by gperf --- */
COMP = 1 << 10,
/* Make the keyword table a global variable. */ /* Use the given key positions. */
GLOBAL = 1 << 11, POSITIONS = 1 << 16,
/* Make the generated tables readonly (const). */ /* Use all characters in hash function. */
CONST = 1 << 12, ALLCHARS = 1 << 17,
/* Generate K&R C code: no prototypes, no const. */ /* Handle duplicate hash values for keywords. */
KRC = 1 << 13, DUP = 1 << 18,
/* Generate C code: no prototypes, but const (user can #define it away). */ /* Don't include keyword length in hash computations. */
C = 1 << 14, NOLENGTH = 1 << 19,
/* Generate ISO/ANSI C code: prototypes and const, but no class. */ /* Randomly initialize the associated values table. */
ANSIC = 1 << 15, RANDOM = 1 << 20,
/* Generate C++ code: prototypes, const, class, inline, enum. */ /* --- Informative output --- */
CPLUSPLUS = 1 << 16,
/* Use enum for constants. */ /* Enable debugging (prints diagnostics to stderr). */
ENUM = 1 << 17, DEBUG = 1 << 21
/* Generate #include statements. */
INCLUDE = 1 << 18,
/* Assume 7-bit, not 8-bit, characters. */
SEVENBIT = 1 << 19,
/* Optimize for position-independent code. */
SHAREDLIB = 1 << 20,
/* Ignore case of ASCII characters. */
UPPERLOWER = 1 << 21
}; };
/* Class manager for gperf program Options. */ /* Class manager for gperf program Options. */
@@ -193,10 +203,10 @@ public:
private: private:
/* Prints program usage to given stream. */ /* Prints program usage to given stream. */
void short_usage (FILE * stream) const; static void short_usage (FILE * stream);
/* Prints program usage to given 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. */ /* Records count of command-line arguments. */
int _argument_count; int _argument_count;