Initial commit
[cgperf.git] / options.h
blobb7853ef0ce8248e2c4cd5a6349ab586201d56368
1 #ifndef CGPERF_OPTIONS_H
2 #define CGPERF_OPTIONS_H
3 #include <stdbool.h>
4 #include <stdio.h>
5 #include "c_fixing.h"
6 /*------------------------------------------------------------------------------------------------*/
7 #include "namespace/positions.h"
8 #include "namespace/options.h"
9 /*------------------------------------------------------------------------------------------------*/
10 /*{{{ Options */
11 /*{{{ globals */
12 /* records the program name */
13 static u8 *opts_program_name;
14 /*}}} globals -- END */
15 /*{{{ constants */
16 enum {
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 */
22 OPTS_TYPE = 1 << 0,
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 */
27 OPTS_KRC = 1 << 2,
28 /* generate C code: no prototypes, but const (user can #define it away) */
29 OPTS_C = 1 << 3,
30 /* generate ISO/ANSI C code: prototypes and const, but no class */
31 OPTS_ANSIC = 1 << 4,
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 */
40 OPTS_COMP = 1 << 8,
41 /* make the generated tables readonly (const) */
42 OPTS_CONST = 1 << 9,
43 /* use enum for constants */
44 OPTS_ENUM = 1 << 10,
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 */
61 OPTS_DUP = 1 << 18,
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) */
68 OPTS_DEBUG = 1 << 21,
70 /*}}} constants -- END */
71 /*{{{ types */
72 struct Options {
73 /* records count of command-line arguments */
74 u32 argument_count;
75 /* stores a pointer to command-line argument vector */
76 u8 **argument_vector;
77 /* holds the boolean options */
78 u32 option_word;
79 /* separates keywords from other attributes */
80 u8 *delimiters;
81 /* suffix for empty struct initializers */
82 u8 *initializer_suffix;
83 /* name used for generated hash function */
84 u8 *hash_name;
85 /* initial value for asso_values table */
86 s32 initial_asso_value;
87 /* jump length when trying alternative values */
88 s32 jump;
89 /* contains user-specified key choices */
90 struct Positions *key_positions;
91 /* Name used for keyword key */
92 u8 *slot_name;
93 /* the output language */
94 u8 *language;
95 /* number of attempts at finding good asso_values */
96 s32 asso_iterations;
97 /* names used for generated lookup function */
98 u8 *function_name;
99 /* name used for the string pool */
100 u8 *stringpool_name;
101 /* factor by which to multiply the generated table's size */
102 f32 size_multiple;
103 /* number of switch statements to generate */
104 s32 total_switches;
105 /* name used for hash table array */
106 u8 *wordlist_name;
107 /* name used for generated C++ class */
108 u8 *class_name;
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 */
116 u8 *input_file_name;
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);
126 /*{{{ accessors */
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);
139 /*}}}*/
140 /*}}} public static methods -- END */
141 /*}}} Options -- END */
142 /*{{{ PositionStringParser */
143 /*{{{ constants and types */
144 struct PositionStringParser {
145 /*{{{ private */
146 /* A pointer to the string provided by the user */
147 u8 *str;
148 /* Smallest possible value, inclusive */
149 s32 low_bound;
150 /* Greatest possible value, inclusive */
151 s32 high_bound;
152 /* A value marking the abstract "end of word" ( usually '$') */
153 s32 end_word_marker;
154 /* Error value returned when input is syntactically erroneous */
155 s32 error_value;
156 /* Value returned after last key is processed */
157 s32 end_marker;
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 /*------------------------------------------------------------------------------------------------*/
173 #define EPILOG
174 #include "namespace/positions.h"
175 #include "namespace/options.h"
176 #undef EPILOG
177 /*------------------------------------------------------------------------------------------------*/
178 #endif