1 #ifndef CGPERF_OPTIONS_H
2 #define CGPERF_OPTIONS_H
6 /*------------------------------------------------------------------------------------------------*/
7 #include "namespace/positions.h"
8 #include "namespace/options.h"
9 /*------------------------------------------------------------------------------------------------*/
12 /* records the program name */
13 static u8
*opts_program_name
;
14 /*}}} globals -- END */
17 /* size to jump on a collision */
18 OPTS_DEFAULT_JUMP_VALUE
= 5,
19 /* enumeration of the possible boolean options */
20 /* --- input file interpretation --- */
21 /* handle user-defined type structured keyword input */
23 /* ignore case of ASCII characters */
24 OPTS_UPPERLOWER
= 1 << 1,
25 /* --- language for the output code --- */
26 /* generate K&R C code: no prototypes, no const */
28 /* generate C code: no prototypes, but const (user can #define it away) */
30 /* generate ISO/ANSI C code: prototypes and const, but no class */
32 /* generate C++ code: prototypes, const, class, inline, enum */
33 OPTS_CPLUSPLUS
= 1 << 5,
34 /* --- details in the output code --- */
35 /* assume 7-bit, not 8-bit, characters */
36 OPTS_SEVENBIT
= 1 << 6,
37 /* generate a length table for string comparison */
38 OPTS_LENTABLE
= 1 << 7,
39 /* generate strncmp rather than strcmp */
41 /* make the generated tables readonly (const) */
43 /* use enum for constants */
45 /* generate #include statements */
46 OPTS_INCLUDE
= 1 << 11,
47 /* make the keyword table a global variable */
48 OPTS_GLOBAL
= 1 << 12,
49 /* use NULL strings instead of empty strings for empty table entries */
50 OPTS_NULLSTRINGS
= 1 << 13,
51 /* optimize for position-independent code */
52 OPTS_SHAREDLIB
= 1 << 14,
53 /* generate switch output to save space */
54 OPTS_SWITCH
= 1 << 15,
55 /* don't include user-defined type definition in output -- it's already defined elsewhere */
56 OPTS_NOTYPE
= 1 << 16,
57 /* --- algorithm employed by gperf --- */
58 /* use the given key positions */
59 OPTS_POSITIONS
= 1 << 17,
60 /* handle duplicate hash values for keywords */
62 /* don't include keyword length in hash computations */
63 OPTS_NOLENGTH
= 1 << 19,
64 /* randomly initialize the associated values table */
65 OPTS_RANDOM
= 1 << 20,
66 /* --- informative output --- */
67 /* enable debugging (prints diagnostics to stderr) */
70 /*}}} constants -- END */
73 /* records count of command-line arguments */
75 /* stores a pointer to command-line argument vector */
77 /* holds the boolean options */
79 /* separates keywords from other attributes */
81 /* suffix for empty struct initializers */
82 u8
*initializer_suffix
;
83 /* name used for generated hash function */
85 /* initial value for asso_values table */
86 s32 initial_asso_value
;
87 /* jump length when trying alternative values */
89 /* contains user-specified key choices */
90 struct Positions
*key_positions
;
91 /* Name used for keyword key */
93 /* the output language */
95 /* number of attempts at finding good asso_values */
97 /* names used for generated lookup function */
99 /* name used for the string pool */
101 /* factor by which to multiply the generated table's size */
103 /* number of switch statements to generate */
105 /* name used for hash table array */
107 /* name used for generated C++ class */
109 /* name of output file */
110 u8
*output_file_name
;
111 /* name used for length table array */
112 u8
*lengthtable_name
;
113 /* prefix for the constants */
114 u8
*constants_prefix
;
115 /* name of input file */
118 /*}}} types -- END */
119 /*{{{ public static methods */
120 static struct Options
*opts_new(void);
121 static void opts_del(struct Options
*t
);
122 static void opts_parse_options(struct Options
*t
, u32 argc
, u8
**argv
);
123 static void opts_long_usage(FILE *stream
);
124 static void opts_short_usage(FILE *stream
);
125 static void opts_print(struct Options
*t
);
127 static void opts_set_delimiters(struct Options
*t
, u8
*delimiters
);
128 static void opts_set_language(struct Options
*t
, u8
*language
);
129 static void opts_set_slot_name(struct Options
*t
, u8
*name
);
130 static void opts_set_initializer_suffix(struct Options
*t
, u8
*initializers
);
131 static void opts_set_hash_name(struct Options
*t
, u8
*name
);
132 static void opts_set_function_name(struct Options
*t
, u8
*name
);
133 static void opts_set_class_name(struct Options
*t
, u8
*name
);
134 static void opts_set_stringpool_name(struct Options
*t
, u8
*name
);
135 static void opts_set_constants_prefix(struct Options
*t
, u8
*prefix
);
136 static void opts_set_wordlist_name(struct Options
*t
, u8
*name
);
137 static void opts_set_lengthtable_name(struct Options
*t
, u8
*name
);
138 static void opts_set_total_switches(struct Options
*t
, s32 total_switches
);
140 /*}}} public static methods -- END */
141 /*}}} Options -- END */
142 /*{{{ PositionStringParser */
143 /*{{{ constants and types */
144 struct PositionStringParser
{
146 /* A pointer to the string provided by the user */
148 /* Smallest possible value, inclusive */
150 /* Greatest possible value, inclusive */
152 /* A value marking the abstract "end of word" ( usually '$') */
154 /* Error value returned when input is syntactically erroneous */
156 /* Value returned after last key is processed */
158 /* Intermediate state for producing a range of positions */
159 bool in_range
; /* True while producing a range of positions */
160 s32 range_upper_bound
; /* Upper bound (inclusive) of the range */
161 s32 range_curr_value
; /* Last value returned */
162 /*}}} private -- END */
164 /*}}} constants and types -- END */
165 /*{{{ public static methods */
166 static struct PositionStringParser
*posstrp_new(u8
*str
, s32 low_bound
, s32 high_bound
,
167 s32 end_word_marker
, s32 error_value
, s32 end_marker
);
168 static void posstrp_del(struct PositionStringParser
*t
);
169 static s32
posstrp_nextPosition(struct PositionStringParser
*t
);
170 /*}}} public static methods -- END */
171 /*}}} PositionStringParser -- END */
172 /*------------------------------------------------------------------------------------------------*/
174 #include "namespace/positions.h"
175 #include "namespace/options.h"
177 /*------------------------------------------------------------------------------------------------*/