Debian Codegraph @

src/options.h

raw
1 /* This may look like C code, but it is really -*- C++ -*- */
2
3 /* Handles parsing the Options provided to the user.
4
5 Copyright (C) 1989-1998, 2000, 2002-2004, 2011, 2023 Free Software Foundation, Inc.
6 Written by Douglas C. Schmidt <[email protected]>
7 and Bruno Haible <[email protected]>.
8
9 This file is part of GNU GPERF.
10
11 This program is free software: you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 3 of the License, or
14 (at your option) any later version.
15
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with this program. If not, see <https://www.gnu.org/licenses/>. */
23
24 /* This module provides a uniform interface to the various options available
25 to a user of the gperf hash function generator. */
26
27 #ifndef options_h
28 #define options_h 1
29
30 #include <stdio.h>
31 #include "positions.h"
32
33 /* Enumeration of the possible boolean options. */
34
35 enum Option_Type
36 {
37 /* --- Input file interpretation --- */
38
39 /* Handle user-defined type structured keyword input. */
40 TYPE = 1 << 0,
41
42 /* Ignore case of ASCII characters. */
43 UPPERLOWER = 1 << 1,
44
45 /* --- Language for the output code --- */
46
47 /* Generate K&R C code: no prototypes, no const. */
48 KRC = 1 << 2,
49
50 /* Generate C code: no prototypes, but const (user can #define it away). */
51 C = 1 << 3,
52
53 /* Generate ISO/ANSI C code: prototypes and const, but no class. */
54 ANSIC = 1 << 4,
55
56 /* Generate C++ code: prototypes, const, class, inline, enum. */
57 CPLUSPLUS = 1 << 5,
58
59 /* --- Details in the output code --- */
60
61 /* Assume 7-bit, not 8-bit, characters. */
62 SEVENBIT = 1 << 6,
63
64 /* Generate a length table for string comparison. */
65 LENTABLE = 1 << 7,
66
67 /* Generate strncmp rather than strcmp. */
68 COMP = 1 << 8,
69
70 /* Make the generated tables readonly (const). */
71 CONST = 1 << 9,
72
73 /* Use enum for constants. */
74 ENUM = 1 << 10,
75
76 /* Generate #include statements. */
77 INCLUDE = 1 << 11,
78
79 /* Make the keyword table a global variable. */
80 GLOBAL = 1 << 12,
81
82 /* Use NULL strings instead of empty strings for empty table entries. */
83 NULLSTRINGS = 1 << 13,
84
85 /* Optimize for position-independent code. */
86 SHAREDLIB = 1 << 14,
87
88 /* Generate switch output to save space. */
89 SWITCH = 1 << 15,
90
91 /* Don't include user-defined type definition in output -- it's already
92 defined elsewhere. */
93 NOTYPE = 1 << 16,
94
95 /* --- Algorithm employed by gperf --- */
96
97 /* Use the given key positions. */
98 POSITIONS = 1 << 17,
99
100 /* Handle duplicate hash values for keywords. */
101 DUP = 1 << 18,
102
103 /* Don't include keyword length in hash computations. */
104 NOLENGTH = 1 << 19,
105
106 /* Randomly initialize the associated values table. */
107 RANDOM = 1 << 20,
108
109 /* --- Informative output --- */
110
111 /* Enable debugging (prints diagnostics to stderr). */
112 DEBUG = 1 << 21
113 };
114
115 /* Class manager for gperf program Options. */
116
117 class Options
118 {
119 public:
120 /* Constructor. */
121 Options ();
122
123 /* Destructor. */
124 ~Options ();
125
126 /* Parses the options given in the command-line arguments. */
127 void parse_options (int argc, char *argv[]);
128
129 /* Prints the given options. */
130 void print_options () const;
131
132 /* Accessors. */
133
134 /* Tests a given boolean option. Returns true if set, false otherwise. */
135 bool operator[] (Option_Type option) const;
136 /* Sets a given boolean option. */
137 void set (Option_Type option);
138
139 /* Returns the input file name. */
140 const char * get_input_file_name () const;
141
142 /* Returns the output file name. */
143 const char * get_output_file_name () const;
144
145 /* Sets the output language, if not already set. */
146 void set_language (const char *language);
147
148 /* Returns the jump value. */
149 int get_jump () const;
150
151 /* Returns the initial associated character value. */
152 int get_initial_asso_value () const;
153
154 /* Returns the number of iterations for finding good asso_values. */
155 int get_asso_iterations () const;
156
157 /* Returns the total number of switch statements to generate. */
158 int get_total_switches () const;
159 /* Sets the total number of switch statements, if not already set. */
160 void set_total_switches (int total_switches);
161
162 /* Returns the factor by which to multiply the generated table's size. */
163 float get_size_multiple () const;
164
165 /* Returns the generated function name. */
166 const char * get_function_name () const;
167 /* Sets the generated function name, if not already set. */
168 void set_function_name (const char *name);
169
170 /* Returns the keyword key name. */
171 const char * get_slot_name () const;
172 /* Sets the keyword key name, if not already set. */
173 void set_slot_name (const char *name);
174
175 /* Returns the struct initializer suffix. */
176 const char * get_initializer_suffix () const;
177 /* Returns true if the struct initializer suffix has been set. */
178 bool has_initializer_suffix () const;
179 /* Sets the struct initializer suffix, if not already set. */
180 void set_initializer_suffix (const char *initializers);
181
182 /* Returns the generated class name. */
183 const char * get_class_name () const;
184 /* Sets the generated class name, if not already set. */
185 void set_class_name (const char *name);
186
187 /* Returns the hash function name. */
188 const char * get_hash_name () const;
189 /* Sets the hash function name, if not already set. */
190 void set_hash_name (const char *name);
191
192 /* Returns the hash table array name. */
193 const char * get_wordlist_name () const;
194 /* Sets the hash table array name, if not already set. */
195 void set_wordlist_name (const char *name);
196
197 /* Returns the length table array name. */
198 const char * get_lengthtable_name () const;
199 /* Sets the length table array name, if not already set. */
200 void set_lengthtable_name (const char *name);
201
202 /* Returns the string pool name. */
203 const char * get_stringpool_name () const;
204 /* Sets the string pool name, if not already set. */
205 void set_stringpool_name (const char *name);
206
207 /* Returns the prefix for the constants. */
208 const char * get_constants_prefix () const;
209 /* Sets the prefix for the constants, if not already set. */
210 void set_constants_prefix (const char *prefix);
211
212 /* Returns the string used to delimit keywords from other attributes. */
213 const char * get_delimiters () const;
214 /* Sets the delimiters string, if not already set. */
215 void set_delimiters (const char *delimiters);
216
217 /* Returns key positions. */
218 const Positions& get_key_positions () const;
219
220 private:
221 /* Prints program usage to given stream. */
222 static void short_usage (FILE * stream);
223
224 /* Prints program usage to given stream. */
225 static void long_usage (FILE * stream);
226
227 /* Records count of command-line arguments. */
228 int _argument_count;
229
230 /* Stores a pointer to command-line argument vector. */
231 char ** _argument_vector;
232
233 /* Holds the boolean options. */
234 int _option_word;
235
236 /* Name of input file. */
237 char * _input_file_name;
238
239 /* Name of output file. */
240 char * _output_file_name;
241
242 /* The output language. */
243 const char * _language;
244
245 /* Jump length when trying alternative values. */
246 int _jump;
247
248 /* Initial value for asso_values table. */
249 int _initial_asso_value;
250
251 /* Number of attempts at finding good asso_values. */
252 int _asso_iterations;
253
254 /* Number of switch statements to generate. */
255 int _total_switches;
256
257 /* Factor by which to multiply the generated table's size. */
258 float _size_multiple;
259
260 /* Names used for generated lookup function. */
261 const char * _function_name;
262
263 /* Name used for keyword key. */
264 const char * _slot_name;
265
266 /* Suffix for empty struct initializers. */
267 const char * _initializer_suffix;
268
269 /* Name used for generated C++ class. */
270 const char * _class_name;
271
272 /* Name used for generated hash function. */
273 const char * _hash_name;
274
275 /* Name used for hash table array. */
276 const char * _wordlist_name;
277
278 /* Name used for length table array. */
279 const char * _lengthtable_name;
280
281 /* Name used for the string pool. */
282 const char * _stringpool_name;
283
284 /* Prefix for the constants. */
285 const char * _constants_prefix;
286
287 /* Separates keywords from other attributes. */
288 const char * _delimiters;
289
290 /* Contains user-specified key choices. */
291 Positions _key_positions;
292 };
293
294 /* Global option coordinator for the entire program. */
295 extern Options option;
296
297 #ifdef __OPTIMIZE__
298
299 #define INLINE inline
300 #include "options.icc"
301 #undef INLINE
302
303 #endif
304
305 #endif