4 * Copyright (C) 1989 Free Software Foundation, Inc.
5 * written by Douglas C. Schmidt (d.schmidt@vanderbilt.edu)
7 * This file is part of GNU GPERF.
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27 #include "ace/Log_Msg.h"
28 #include "ace/SString.h"
29 #include "ace/Copy_Disabled.h"
31 #if !defined (ACE_LACKS_PRAGMA_ONCE)
33 #endif /* ACE_LACKS_PRAGMA_ONCE */
35 /// Enumerate the potential debugging Options.
38 DEBUGGING
= 01, /* Enable debugging (prints diagnostics to stderr). */
39 ORDER
= 02, /**< Apply ordering heuristic to speed-up search time. */
40 ANSI
= 04, /**< Generate ANSI prototypes. */
41 ALLCHARS
= 010, /**< Use all characters in hash function. */
42 INLINE
= 020, /**< Generate code for inline functions. */
43 TYPE
= 040, /**< Handle user-defined type structured keyword input. */
44 RANDOM
= 0100, /**< Randomly initialize the associated values table. */
45 DEFAULTCHARS
= 0200, /**< Make default char positions be 1,$ (end of keyword). */
46 SWITCH
= 0400, /**< Generate switch output to save space. */
47 POINTER
= 01000, /**< Have in_word_set function return pointer, not boolean. */
48 NOLENGTH
= 02000, /**< Don't include keyword length in hash computations. */
49 LENTABLE
= 04000, /**< Generate a length table for string comparison. */
50 DUP
= 010000, /**< Handle duplicate hash values for keywords. */
51 FAST
= 020000, /**< Generate the hash function ``fast.'' */
52 NOTYPE
= 040000, /**< Don't include user-defined type definition in output -- it's already defined elsewhere. */
53 COMP
= 0100000, /**< Generate strncmp rather than strcmp. */
54 GLOBAL
= 0200000, /**< Make the keyword table a global variable. */
55 CONSTANT
= 0400000, /**< Make the generated tables readonly (const). */
56 CPLUSPLUS
= 01000000, /**< Generate C++ code. */
57 C
= 02000000, /**< Generate C code. */
58 ENUM
= 04000000, /**< Use enum for constants. */
59 STRCASECMP
= 010000000, /**< Use the case insensitive comparison. */
60 OPTIMIZE
= 020000000, /**< Assume all input keywords are in the keyset. */
61 ADA
= 040000000, /**< Generate Ada code. */
62 MUTE
= 0100000000, /**< Dont print the warnings. */
63 SKIPCLASS
= 0200000000, /**< Skip the class definition part in the output while in C++ mode. */
64 SKIPSTRINGH
= 0400000000, /**< Skip including the header file ace/OS_NS_string.h. */
65 BINARYSEARCH
= 01000000000, /**< Generates Binary Search code. */
66 LINEARSEARCH
= 02000000000 /**< Generates Linear Search code. */
69 // Define some useful constants (these don't really belong here, but
70 // I'm not sure where else to put them!). These should be consts, but
71 // g++ doesn't seem to do the right thing with them at the
76 MAX_KEY_POS
= 128 - 1, /**< Max size of each word's key set. */
77 WORD_START
= 1, /**< Signals the start of a word. */
78 WORD_END
= 0, /**< Signals the end of a word. */
79 EOS
= MAX_KEY_POS
/**< Signals end of the key list. */
83 * This class provides a uniform interface to the various options
84 * available to a user of the gperf hash function generator.
86 * In addition to the run-time options, found in the <Option_Type>
87 * there is also the hash table Size and the Keys to be used in
88 * the hashing. The overall design of this module was an
89 * experiment in using C++ classes as a mechanism to enhance
90 * centralization of option and and error handling.
92 * @todo The Options class should be changed to use the Singleton pattern.
94 class Options
: private ACE_Copy_Disabled
99 int operator[] (Option_Type option
);
100 int parse_args (int argc
, ACE_TCHAR
*argv
[]);
101 void operator= (enum Option_Type
);
102 bool operator!= (enum Option_Type
);
103 static void print_options ();
104 static void asso_max (int r
);
105 static int asso_max ();
106 static void reset ();
108 static int iterations ();
109 static u_int
max_keysig_size ();
110 static void keysig_size (u_int
);
112 static int initial_value ();
113 static int total_switches ();
114 static const char *function_name ();
115 static const char *fill_default ();
116 static const char *key_name ();
117 static const char *class_name ();
118 static const char *hash_name ();
119 static const char *delimiter ();
122 /// Holds the user-specified Options.
123 static int option_word_
;
125 /// Number of switch statements to generate.
126 static int total_switches_
;
128 /// Total number of distinct key_positions.
129 static u_int total_keysig_size_
;
131 /// Range of the hash table.
134 /// Tracks current key position for Iterator.
137 /// Tracks current key position for Iterator.
140 /// Initial value for asso_values table.
141 static int initial_asso_value_
;
143 /// Amount to iterate when a collision occurs.
144 static int iterations_
;
146 /// Records count of command-line arguments.
149 /// Stores a pointer to command-line vector.
150 static ACE_TCHAR
**argv_
;
152 /// Names used for generated lookup function.
153 static ACE_CString function_name_
;
155 /// Expression used to assign default values in keyword table.
156 static ACE_CString fill_default_
;
158 /// Name used for keyword key.
159 static ACE_CString key_name_
;
161 /// Name used for generated C++ class.
162 static ACE_CString class_name_
;
164 /// Name used for generated hash function.
165 static ACE_CString hash_name_
;
167 /// Separates keywords from other attributes.
168 static ACE_CString delimiters_
;
170 /// Contains user-specified key choices.
171 static char key_positions_
[MAX_KEY_POS
];
173 /// Sorts key positions in REVERSE order.
174 static int key_sort (char *base
, int len
);
176 /// Prints proper program usage.
177 static void usage ();
180 /// Global option coordinator for the entire program.
181 extern Options option
;
183 #endif /* OPTIONS_H */