1 /* This may look like C code, but it is really -*- C++ -*- */
3 /* Handles parsing the Options provided to the user.
5 Copyright (C) 1989-1998, 2000, 2002-2004 Free Software Foundation, Inc.
6 Written by Douglas C. Schmidt <schmidt@ics.uci.edu>
7 and Bruno Haible <bruno@clisp.org>.
9 This file is part of GNU GPERF.
11 GNU GPERF 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 2, or (at your option)
16 GNU GPERF 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.
21 You should have received a copy of the GNU General Public License
22 along with this program; see the file COPYING.
23 If not, write to the Free Software Foundation, Inc.,
24 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
26 /* This module provides a uniform interface to the various options available
27 to a user of the gperf hash function generator. */
33 #include "positions.h"
35 /* Enumeration of the possible boolean options. */
39 /* --- Input file interpretation --- */
41 /* Handle user-defined type structured keyword input. */
44 /* Ignore case of ASCII characters. */
47 /* --- Language for the output code --- */
49 /* Generate K&R C code: no prototypes, no const. */
52 /* Generate C code: no prototypes, but const (user can #define it away). */
55 /* Generate ISO/ANSI C code: prototypes and const, but no class. */
58 /* Generate C++ code: prototypes, const, class, inline, enum. */
61 /* --- Details in the output code --- */
63 /* Assume 7-bit, not 8-bit, characters. */
66 /* Generate a length table for string comparison. */
69 /* Generate strncmp rather than strcmp. */
72 /* Make the generated tables readonly (const). */
75 /* Use enum for constants. */
78 /* Generate #include statements. */
81 /* Make the keyword table a global variable. */
84 /* Use NULL strings instead of empty strings for empty table entries. */
85 NULLSTRINGS = 1 << 13,
87 /* Optimize for position-independent code. */
90 /* Generate switch output to save space. */
93 /* Don't include user-defined type definition in output -- it's already
97 /* --- Algorithm employed by gperf --- */
99 /* Use the given key positions. */
102 /* Handle duplicate hash values for keywords. */
105 /* Don't include keyword length in hash computations. */
108 /* Randomly initialize the associated values table. */
111 /* --- Informative output --- */
113 /* Enable debugging (prints diagnostics to stderr). */
117 /* Class manager for gperf program Options. */
128 /* Parses the options given in the command-line arguments. */
129 void parse_options (int argc, char *argv[]);
131 /* Prints the given options. */
132 void print_options () const;
136 /* Tests a given boolean option. Returns true if set, false otherwise. */
137 bool operator[] (Option_Type option) const;
138 /* Sets a given boolean option. */
139 void set (Option_Type option);
141 /* Returns the input file name. */
142 const char * get_input_file_name () const;
144 /* Returns the output file name. */
145 const char * get_output_file_name () const;
147 /* Sets the output language, if not already set. */
148 void set_language (const char *language);
150 /* Returns the jump value. */
151 int get_jump () const;
153 /* Returns the initial associated character value. */
154 int get_initial_asso_value () const;
156 /* Returns the number of iterations for finding good asso_values. */
157 int get_asso_iterations () const;
159 /* Returns the total number of switch statements to generate. */
160 int get_total_switches () const;
161 /* Sets the total number of switch statements, if not already set. */
162 void set_total_switches (int total_switches);
164 /* Returns the factor by which to multiply the generated table's size. */
165 float get_size_multiple () const;
167 /* Returns the generated function name. */
168 const char * get_function_name () const;
169 /* Sets the generated function name, if not already set. */
170 void set_function_name (const char *name);
172 /* Returns the keyword key name. */
173 const char * get_slot_name () const;
174 /* Sets the keyword key name, if not already set. */
175 void set_slot_name (const char *name);
177 /* Returns the struct initializer suffix. */
178 const char * get_initializer_suffix () const;
179 /* Sets the struct initializer suffix, if not already set. */
180 void set_initializer_suffix (const char *initializers);
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);
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);
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);
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);
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);
207 /* Returns the string used to delimit keywords from other attributes. */
208 const char * get_delimiters () const;
209 /* Sets the delimiters string, if not already set. */
210 void set_delimiters (const char *delimiters);
212 /* Returns key positions. */
213 const Positions& get_key_positions () const;
216 /* Prints program usage to given stream. */
217 static void short_usage (FILE * stream);
219 /* Prints program usage to given stream. */
220 static void long_usage (FILE * stream);
222 /* Records count of command-line arguments. */
225 /* Stores a pointer to command-line argument vector. */
226 char ** _argument_vector;
228 /* Holds the boolean options. */
231 /* Name of input file. */
232 char * _input_file_name;
234 /* Name of output file. */
235 char * _output_file_name;
237 /* The output language. */
238 const char * _language;
240 /* Jump length when trying alternative values. */
243 /* Initial value for asso_values table. */
244 int _initial_asso_value;
246 /* Number of attempts at finding good asso_values. */
247 int _asso_iterations;
249 /* Number of switch statements to generate. */
252 /* Factor by which to multiply the generated table's size. */
253 float _size_multiple;
255 /* Names used for generated lookup function. */
256 const char * _function_name;
258 /* Name used for keyword key. */
259 const char * _slot_name;
261 /* Suffix for empty struct initializers. */
262 const char * _initializer_suffix;
264 /* Name used for generated C++ class. */
265 const char * _class_name;
267 /* Name used for generated hash function. */
268 const char * _hash_name;
270 /* Name used for hash table array. */
271 const char * _wordlist_name;
273 /* Name used for length table array. */
274 const char * _lengthtable_name;
276 /* Name used for the string pool. */
277 const char * _stringpool_name;
279 /* Separates keywords from other attributes. */
280 const char * _delimiters;
282 /* Contains user-specified key choices. */
283 Positions _key_positions;
286 /* Global option coordinator for the entire program. */
287 extern Options option;
291 #define INLINE inline
292 #include "options.icc"