6 written by Douglas C. Schmidt (schmidt@ics.uci.edu) 7 8This file is part of GNU GPERF. 9 10GNU GPERF is free software; you can redistribute it and/or modify 11it under the terms of the GNU General Public License as published by 12the Free Software Foundation; either version 1, or (at your option) 13any later version. 14 15GNU GPERF is distributed in the hope that it will be useful, 16but WITHOUT ANY WARRANTY; without even the implied warranty of 17MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18GNU General Public License for more details. 19 20You should have received a copy of the GNU General Public License 21along with GNU GPERF; see the file COPYING. If not, write to the Free 22Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111, USA. */ 23 24/* This module provides a uniform interface to the various options available 25 to a user of the gperf hash function generator. In addition to the 26 run-time options, found in the Option_Type below, there is also the 27 hash table Size and the Keys to be used in the hashing. 28 The overall design of this module was an experiment in using C++ 29 classes as a mechanism to enhance centralization of option and 30 and error handling, which tend to get out of hand in a C program. */ 31 32#ifndef options_h 33#define options_h 1 34 35#include <stdio.h> 36 37/* Enumerate the potential debugging Options. */ 38 39enum Option_Type 40{ 41 DEBUG = 01, /* Enable debugging (prints diagnostics to stderr). */ 42 ORDER = 02, /* Apply ordering heuristic to speed-up search time. */ 43 ALLCHARS = 04, /* Use all characters in hash function. */ 44 TYPE = 010, /* Handle user-defined type structured keyword input. */ 45 RANDOM = 020, /* Randomly initialize the associated values table. */ 46 DEFAULTCHARS = 040, /* Make default char positions be 1,$ (end of keyword). */ 47 SWITCH = 0100, /* Generate switch output to save space. */ 48 NOLENGTH = 0200, /* Don't include keyword length in hash computations. */ 49 LENTABLE = 0400, /* Generate a length table for string comparison. */ 50 DUP = 01000, /* Handle duplicate hash values for keywords. */ 51 FAST = 02000, /* Generate the hash function ``fast.'' */ 52 NOTYPE = 04000, /* Don't include user-defined type definition in output -- it's already defined elsewhere. */ 53 COMP = 010000, /* Generate strncmp rather than strcmp. */ 54 GLOBAL = 020000, /* Make the keyword table a global variable. */ 55 CONST = 040000, /* Make the generated tables readonly (const). */ 56 KRC = 0100000, /* Generate K&R C code: no prototypes, no const. */ 57 C = 0200000, /* Generate C code: no prototypes, but const (user can #define it away). */ 58 ANSIC = 0400000, /* Generate ISO/ANSI C code: prototypes and const, but no class. */ 59 CPLUSPLUS = 01000000, /* Generate C++ code: prototypes, const, class, inline, enum. */ 60 ENUM = 02000000, /* Use enum for constants. */ 61 INCLUDE = 04000000, /* Generate #include statements. */ 62 SEVENBIT = 010000000 /* Assume 7-bit, not 8-bit, characters. */ 63}; 64 65/* Define some useful constants (these don't really belong here, but I'm 66 not sure where else to put them!). These should be consts, but g++ 67 doesn't seem to do the right thing with them at the moment... ;-( */ 68 69enum 70{ 71 MAX_KEY_POS = 128 - 1, /* Max size of each word's key set. */ 72 WORD_START = 1, /* Signals the start of a word. */ 73 WORD_END = 0, /* Signals the end of a word. */ 74 EOS = MAX_KEY_POS /* Signals end of the key list. */ 75}; 76 77/* Class manager for gperf program Options. */ 78 79class Options 80{ 81public: 82 Options (void); 83 ~Options (void); 84 int operator[] (Option_Type option); 85 void operator() (int argc, char *argv[]); 86 void operator= (enum Option_Type); 87 void operator!= (enum Option_Type); 88 static void print_options (void); 89 static void set_asso_max (int r); 90 static int get_asso_max (void); 91 static void reset (void); 92 static int get (void); 93 static int get_iterations (void); 94 static int get_max_keysig_size (void); 95 static void set_keysig_size (int); 96 static int get_jump (void); 97 static int initial_value (void); 98 static int get_total_switches (void); 99 static const char *get_function_name (void); 100 static const char *get_key_name (void);
| 6 written by Douglas C. Schmidt (schmidt@ics.uci.edu) 7 8This file is part of GNU GPERF. 9 10GNU GPERF is free software; you can redistribute it and/or modify 11it under the terms of the GNU General Public License as published by 12the Free Software Foundation; either version 1, or (at your option) 13any later version. 14 15GNU GPERF is distributed in the hope that it will be useful, 16but WITHOUT ANY WARRANTY; without even the implied warranty of 17MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18GNU General Public License for more details. 19 20You should have received a copy of the GNU General Public License 21along with GNU GPERF; see the file COPYING. If not, write to the Free 22Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111, USA. */ 23 24/* This module provides a uniform interface to the various options available 25 to a user of the gperf hash function generator. In addition to the 26 run-time options, found in the Option_Type below, there is also the 27 hash table Size and the Keys to be used in the hashing. 28 The overall design of this module was an experiment in using C++ 29 classes as a mechanism to enhance centralization of option and 30 and error handling, which tend to get out of hand in a C program. */ 31 32#ifndef options_h 33#define options_h 1 34 35#include <stdio.h> 36 37/* Enumerate the potential debugging Options. */ 38 39enum Option_Type 40{ 41 DEBUG = 01, /* Enable debugging (prints diagnostics to stderr). */ 42 ORDER = 02, /* Apply ordering heuristic to speed-up search time. */ 43 ALLCHARS = 04, /* Use all characters in hash function. */ 44 TYPE = 010, /* Handle user-defined type structured keyword input. */ 45 RANDOM = 020, /* Randomly initialize the associated values table. */ 46 DEFAULTCHARS = 040, /* Make default char positions be 1,$ (end of keyword). */ 47 SWITCH = 0100, /* Generate switch output to save space. */ 48 NOLENGTH = 0200, /* Don't include keyword length in hash computations. */ 49 LENTABLE = 0400, /* Generate a length table for string comparison. */ 50 DUP = 01000, /* Handle duplicate hash values for keywords. */ 51 FAST = 02000, /* Generate the hash function ``fast.'' */ 52 NOTYPE = 04000, /* Don't include user-defined type definition in output -- it's already defined elsewhere. */ 53 COMP = 010000, /* Generate strncmp rather than strcmp. */ 54 GLOBAL = 020000, /* Make the keyword table a global variable. */ 55 CONST = 040000, /* Make the generated tables readonly (const). */ 56 KRC = 0100000, /* Generate K&R C code: no prototypes, no const. */ 57 C = 0200000, /* Generate C code: no prototypes, but const (user can #define it away). */ 58 ANSIC = 0400000, /* Generate ISO/ANSI C code: prototypes and const, but no class. */ 59 CPLUSPLUS = 01000000, /* Generate C++ code: prototypes, const, class, inline, enum. */ 60 ENUM = 02000000, /* Use enum for constants. */ 61 INCLUDE = 04000000, /* Generate #include statements. */ 62 SEVENBIT = 010000000 /* Assume 7-bit, not 8-bit, characters. */ 63}; 64 65/* Define some useful constants (these don't really belong here, but I'm 66 not sure where else to put them!). These should be consts, but g++ 67 doesn't seem to do the right thing with them at the moment... ;-( */ 68 69enum 70{ 71 MAX_KEY_POS = 128 - 1, /* Max size of each word's key set. */ 72 WORD_START = 1, /* Signals the start of a word. */ 73 WORD_END = 0, /* Signals the end of a word. */ 74 EOS = MAX_KEY_POS /* Signals end of the key list. */ 75}; 76 77/* Class manager for gperf program Options. */ 78 79class Options 80{ 81public: 82 Options (void); 83 ~Options (void); 84 int operator[] (Option_Type option); 85 void operator() (int argc, char *argv[]); 86 void operator= (enum Option_Type); 87 void operator!= (enum Option_Type); 88 static void print_options (void); 89 static void set_asso_max (int r); 90 static int get_asso_max (void); 91 static void reset (void); 92 static int get (void); 93 static int get_iterations (void); 94 static int get_max_keysig_size (void); 95 static void set_keysig_size (int); 96 static int get_jump (void); 97 static int initial_value (void); 98 static int get_total_switches (void); 99 static const char *get_function_name (void); 100 static const char *get_key_name (void);
|