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:
@@ -1,5 +1,13 @@
|
||||
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.cc (Options::long_usage): Document option --ignore-case.
|
||||
(Options::~Options): Update.
|
||||
|
||||
@@ -64,15 +64,14 @@ static const char *const DEFAULT_DELIMITERS = ",";
|
||||
/* Prints program usage to given stream. */
|
||||
|
||||
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"
|
||||
"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)
|
||||
{
|
||||
@@ -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);
|
||||
@@ -721,7 +734,7 @@ Options::parse_options (int argc, char *argv[])
|
||||
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;
|
||||
@@ -839,7 +852,7 @@ Options::parse_options (int argc, char *argv[])
|
||||
_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;
|
||||
@@ -859,7 +872,7 @@ Options::parse_options (int argc, char *argv[])
|
||||
{
|
||||
_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. */
|
||||
@@ -936,7 +949,7 @@ 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;
|
||||
|
||||
106
src/options.h
106
src/options.h
@@ -36,72 +36,82 @@
|
||||
|
||||
enum Option_Type
|
||||
{
|
||||
/* Enable debugging (prints diagnostics to stderr). */
|
||||
DEBUG = 1 << 0,
|
||||
|
||||
/* Use the given key positions. */
|
||||
POSITIONS = 1 << 1,
|
||||
|
||||
/* Use all characters in hash function. */
|
||||
ALLCHARS = 1 << 2,
|
||||
/* --- Input file interpretation --- */
|
||||
|
||||
/* Handle user-defined type structured keyword input. */
|
||||
TYPE = 1 << 3,
|
||||
TYPE = 1 << 0,
|
||||
|
||||
/* Randomly initialize the associated values table. */
|
||||
RANDOM = 1 << 4,
|
||||
/* Ignore case of ASCII characters. */
|
||||
UPPERLOWER = 1 << 1,
|
||||
|
||||
/* Generate switch output to save space. */
|
||||
SWITCH = 1 << 5,
|
||||
/* --- Language for the output code --- */
|
||||
|
||||
/* Don't include keyword length in hash computations. */
|
||||
NOLENGTH = 1 << 6,
|
||||
/* Generate K&R C code: no prototypes, no const. */
|
||||
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. */
|
||||
LENTABLE = 1 << 7,
|
||||
|
||||
/* Handle duplicate hash values for keywords. */
|
||||
DUP = 1 << 8,
|
||||
/* Generate strncmp rather than strcmp. */
|
||||
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
|
||||
defined elsewhere. */
|
||||
NOTYPE = 1 << 9,
|
||||
NOTYPE = 1 << 15,
|
||||
|
||||
/* Generate strncmp rather than strcmp. */
|
||||
COMP = 1 << 10,
|
||||
/* --- Algorithm employed by gperf --- */
|
||||
|
||||
/* Make the keyword table a global variable. */
|
||||
GLOBAL = 1 << 11,
|
||||
/* Use the given key positions. */
|
||||
POSITIONS = 1 << 16,
|
||||
|
||||
/* Make the generated tables readonly (const). */
|
||||
CONST = 1 << 12,
|
||||
/* Use all characters in hash function. */
|
||||
ALLCHARS = 1 << 17,
|
||||
|
||||
/* Generate K&R C code: no prototypes, no const. */
|
||||
KRC = 1 << 13,
|
||||
/* Handle duplicate hash values for keywords. */
|
||||
DUP = 1 << 18,
|
||||
|
||||
/* Generate C code: no prototypes, but const (user can #define it away). */
|
||||
C = 1 << 14,
|
||||
/* Don't include keyword length in hash computations. */
|
||||
NOLENGTH = 1 << 19,
|
||||
|
||||
/* Generate ISO/ANSI C code: prototypes and const, but no class. */
|
||||
ANSIC = 1 << 15,
|
||||
/* Randomly initialize the associated values table. */
|
||||
RANDOM = 1 << 20,
|
||||
|
||||
/* Generate C++ code: prototypes, const, class, inline, enum. */
|
||||
CPLUSPLUS = 1 << 16,
|
||||
/* --- Informative output --- */
|
||||
|
||||
/* Use enum for constants. */
|
||||
ENUM = 1 << 17,
|
||||
|
||||
/* 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
|
||||
/* Enable debugging (prints diagnostics to stderr). */
|
||||
DEBUG = 1 << 21
|
||||
};
|
||||
|
||||
/* Class manager for gperf program 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;
|
||||
|
||||
Reference in New Issue
Block a user