Deleted Added
full compact
options.h (18214) options.h (58551)
1/* This may look like C code, but it is really -*- C++ -*- */
2
1/* Handles parsing the Options provided to the user.
2
3/* Handles parsing the Options provided to the user.
4
3 Copyright (C) 1989 Free Software Foundation, Inc.
5 Copyright (C) 1989-1998 Free Software Foundation, Inc.
4 written by Douglas C. Schmidt (schmidt@ics.uci.edu)
5
6This file is part of GNU GPERF.
7
8GNU GPERF is free software; you can redistribute it and/or modify
9it under the terms of the GNU General Public License as published by
10the Free Software Foundation; either version 1, or (at your option)
11any later version.
12
13GNU GPERF is distributed in the hope that it will be useful,
14but WITHOUT ANY WARRANTY; without even the implied warranty of
15MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16GNU General Public License for more details.
17
18You should have received a copy of the GNU General Public License
6 written by Douglas C. Schmidt (schmidt@ics.uci.edu)
7
8This file is part of GNU GPERF.
9
10GNU GPERF is free software; you can redistribute it and/or modify
11it under the terms of the GNU General Public License as published by
12the Free Software Foundation; either version 1, or (at your option)
13any later version.
14
15GNU GPERF is distributed in the hope that it will be useful,
16but WITHOUT ANY WARRANTY; without even the implied warranty of
17MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18GNU General Public License for more details.
19
20You should have received a copy of the GNU General Public License
19along with GNU GPERF; see the file COPYING. If not, write to
20the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
21along with GNU GPERF; see the file COPYING. If not, write to the Free
22Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111, USA. */
21
23
22/* This module provides a uniform interface to the various Options available
23 to a user of the Perfect.hash function generator. In addition to the
24 run-time Options, found in the Option_Type below, there is also the
24/* This module provides a uniform interface to the various options available
25 to a user of the gperf hash function generator. In addition to the
26 run-time options, found in the Option_Type below, there is also the
25 hash table Size and the Keys to be used in the hashing.
26 The overall design of this module was an experiment in using C++
27 classes as a mechanism to enhance centralization of option and
28 and error handling, which tend to get out of hand in a C program. */
29
27 hash table Size and the Keys to be used in the hashing.
28 The overall design of this module was an experiment in using C++
29 classes as a mechanism to enhance centralization of option and
30 and error handling, which tend to get out of hand in a C program. */
31
30#ifndef _options_h
31#define _options_h
32#ifndef options_h
33#define options_h 1
32
33#include <stdio.h>
34
35#include <stdio.h>
34#include "prototype.h"
35
36/* Enumerate the potential debugging Options. */
37
36
37/* Enumerate the potential debugging Options. */
38
38enum option_type
39enum Option_Type
39{
40{
40 DEBUG = 01, /* Enable debugging (prints diagnostics to Std_Err). */
41 DEBUG = 01, /* Enable debugging (prints diagnostics to stderr). */
41 ORDER = 02, /* Apply ordering heuristic to speed-up search time. */
42 ORDER = 02, /* Apply ordering heuristic to speed-up search time. */
42 ANSI = 04, /* Generate ANSI prototypes. */
43 ALLCHARS = 010, /* Use all characters in hash function. */
44 GNU = 020, /* Assume GNU extensions (primarily function inline). */
45 TYPE = 040, /* Handle user-defined type structured keyword input. */
46 RANDOM = 0100, /* Randomly initialize the associated values table. */
47 DEFAULTCHARS = 0200, /* Make default char positions be 1,$ (end of keyword). */
48 SWITCH = 0400, /* Generate switch output to save space. */
49 POINTER = 01000, /* Have in_word_set function return pointer, not boolean. */
50 NOLENGTH = 02000, /* Don't include keyword length in hash computations. */
51 LENTABLE = 04000, /* Generate a length table for string comparison. */
52 DUP = 010000, /* Handle duplicate hash values for keywords. */
53 FAST = 020000, /* Generate the hash function ``fast.'' */
54 NOTYPE = 040000, /* Don't include user-defined type definition
55 in output -- it's already defined elsewhere. */
56 COMP = 0100000, /* Generate strncmp rather than strcmp. */
57 GLOBAL = 0200000, /* Make the keyword table a global variable. */
58 CONST = 0400000, /* Make the generated tables readonly (const). */
43 ALLCHARS = 04, /* Use all characters in hash function. */
44 TYPE = 010, /* Handle user-defined type structured keyword input. */
45 RANDOM = 020, /* Randomly initialize the associated values table. */
46 DEFAULTCHARS = 040, /* Make default char positions be 1,$ (end of keyword). */
47 SWITCH = 0100, /* Generate switch output to save space. */
48 NOLENGTH = 0200, /* Don't include keyword length in hash computations. */
49 LENTABLE = 0400, /* Generate a length table for string comparison. */
50 DUP = 01000, /* Handle duplicate hash values for keywords. */
51 FAST = 02000, /* Generate the hash function ``fast.'' */
52 NOTYPE = 04000, /* Don't include user-defined type definition in output -- it's already defined elsewhere. */
53 COMP = 010000, /* Generate strncmp rather than strcmp. */
54 GLOBAL = 020000, /* Make the keyword table a global variable. */
55 CONST = 040000, /* Make the generated tables readonly (const). */
56 KRC = 0100000, /* Generate K&R C code: no prototypes, no const. */
57 C = 0200000, /* Generate C code: no prototypes, but const (user can #define it away). */
58 ANSIC = 0400000, /* Generate ISO/ANSI C code: prototypes and const, but no class. */
59 CPLUSPLUS = 01000000, /* Generate C++ code: prototypes, const, class, inline, enum. */
60 ENUM = 02000000, /* Use enum for constants. */
61 INCLUDE = 04000000, /* Generate #include statements. */
62 SEVENBIT = 010000000 /* Assume 7-bit, not 8-bit, characters. */
59};
60
63};
64
61/* Define some useful constants. */
65/* Define some useful constants (these don't really belong here, but I'm
66 not sure where else to put them!). These should be consts, but g++
67 doesn't seem to do the right thing with them at the moment... ;-( */
62
68
63/* Max size of each word's key set. */
64#define MAX_KEY_POS (128 - 1)
69enum
70{
71 MAX_KEY_POS = 128 - 1, /* Max size of each word's key set. */
72 WORD_START = 1, /* Signals the start of a word. */
73 WORD_END = 0, /* Signals the end of a word. */
74 EOS = MAX_KEY_POS /* Signals end of the key list. */
75};
65
76
66/* Signals the start of a word. */
67#define WORD_START 1
77/* Class manager for gperf program Options. */
68
78
69/* Signals the end of a word. */
70#define WORD_END 0
79class Options
80{
81public:
82 Options (void);
83 ~Options (void);
84 int operator[] (Option_Type option);
85 void operator() (int argc, char *argv[]);
86 void operator= (enum Option_Type);
87 void operator!= (enum Option_Type);
88 static void print_options (void);
89 static void set_asso_max (int r);
90 static int get_asso_max (void);
91 static void reset (void);
92 static int get (void);
93 static int get_iterations (void);
94 static int get_max_keysig_size (void);
95 static void set_keysig_size (int);
96 static int get_jump (void);
97 static int initial_value (void);
98 static int get_total_switches (void);
99 static const char *get_function_name (void);
100 static const char *get_key_name (void);
101 static const char *get_class_name (void);
102 static const char *get_hash_name (void);
103 static const char *get_wordlist_name (void);
104 static const char *get_delimiter (void);
71
105
72/* Signals end of the key list. */
73#define EOS MAX_KEY_POS
106private:
107 static int option_word; /* Holds the user-specified Options. */
108 static int total_switches; /* Number of switch statements to generate. */
109 static int total_keysig_size; /* Total number of distinct key_positions. */
110 static int size; /* Range of the hash table. */
111 static int key_pos; /* Tracks current key position for Iterator. */
112 static int jump; /* Jump length when trying alternative values. */
113 static int initial_asso_value; /* Initial value for asso_values table. */
114 static int argument_count; /* Records count of command-line arguments. */
115 static int iterations; /* Amount to iterate when a collision occurs. */
116 static char **argument_vector; /* Stores a pointer to command-line vector. */
117 static const char *function_name; /* Names used for generated lookup function. */
118 static const char *key_name; /* Name used for keyword key. */
119 static const char *class_name; /* Name used for generated C++ class. */
120 static const char *hash_name; /* Name used for generated hash function. */
121 static const char *wordlist_name; /* Name used for hash table array. */
122 static const char *delimiters; /* Separates keywords from other attributes. */
123 static char key_positions[MAX_KEY_POS]; /* Contains user-specified key choices. */
124 static int key_sort (char *base, int len); /* Sorts key positions in REVERSE order. */
125 static void short_usage (FILE * strm); /* Prints proper program usage. */
126 static void long_usage (FILE * strm); /* Prints proper program usage. */
127};
74
128
75/* Returns TRUE if option O is enabled. */
76#define OPTION_ENABLED(OW,O) (OW.option_word & (int)O)
129/* Global option coordinator for the entire program. */
130extern Options option;
77
131
78/* Enables option O in OPTION_WORD. */
79#define SET_OPTION(OW,O) (OW.option_word |= (int)O)
132/* Set to 1 if your want to stack-allocate some large arrays.
133 This requires compiler support for variable-size arrays on the stack
134 (not ANSI). */
135#ifndef LARGE_STACK_ARRAYS
136#if defined(__GNUG__) && !defined(__STRICT_ANSI__)
137#define LARGE_STACK_ARRAYS 1
138#else
139#define LARGE_STACK_ARRAYS 0
140#endif
141#endif
80
142
81/* Disable option O in OPTION_WORD. */
82#define UNSET_OPTION(OW,O) (OW.option_word &= ~(int)(O))
143/* Set to 1 if the stack is large enough for holding a text line. */
144#ifndef LARGE_STACK
145#define LARGE_STACK 1
146#endif
83
147
84/* Returns total distinct key positions. */
85#define GET_CHARSET_SIZE(O) (O.total_charset_size)
148#ifdef __OPTIMIZE__
86
149
87/* Set the total distinct key positions. */
88#define SET_CHARSET_SIZE(O,S) (O.total_charset_size = (S))
150#include "trace.h"
151#define INLINE inline
152#include "options.icc"
153#undef INLINE
89
154
90/* Initializes the key Iterator. */
91#define RESET(O) (O.key_pos = 0)
155#endif
92
156
93/* Returns current key_position and advances index. */
94#define GET(O) (O.key_positions[O.key_pos++])
95
96/* Sets the size of the table size. */
97#define SET_ASSO_MAX(O,R) (O.size = (R))
98
99/* Returns the size of the table size. */
100#define GET_ASSO_MAX(O) (O.size)
101
102/* Returns the jump value. */
103#define GET_JUMP(O) (O.jump)
104
105/* Returns the iteration value. */
106#define GET_ITERATIONS(O) (O.iterations)
107
108/* Returns the lookup function name. */
109#define GET_FUNCTION_NAME(O) (O.function_name)
110
111/* Returns the keyword key name. */
112#define GET_KEY_NAME(O) (O.key_name)
113
114/* Returns the hash function name. */
115#define GET_HASH_NAME(O) (O.hash_name)
116
117/* Returns the initial associated character value. */
118#define INITIAL_VALUE(O) (O.initial_asso_value)
119
120/* Returns the string used to delimit keywords from other attributes. */
121#define GET_DELIMITER(O) (O.delimiters)
122
123/* Sets the keyword/attribute delimiters with value of D. */
124#define SET_DELIMITERS(O,D) (O.delimiters = (D))
125
126/* Gets the total number of switch statements to generate. */
127#define GET_TOTAL_SWITCHES(O) (O.total_switches)
128
129/* Class manager for gperf program options. */
130
131typedef struct options
132{
133 int option_word; /* Holds the user-specified Options. */
134 int total_charset_size; /* Total number of distinct key_positions. */
135 int size; /* Range of the hash table. */
136 int key_pos; /* Tracks current key position for Iterator. */
137 int jump; /* Jump length when trying alternative values. */
138 int initial_asso_value; /* Initial value for asso_values table. */
139 int argument_count; /* Records count of command-line arguments. */
140 int iterations; /* Amount to iterate when a collision occurs. */
141 int total_switches; /* Number of switch statements to generate. */
142 char **argument_vector; /* Stores a pointer to command-line vector. */
143 char *function_name; /* Name used for generated lookup function. */
144 char *key_name; /* Name used for keyword key. */
145 char *hash_name; /* Name used for generated hash function. */
146 char *delimiters; /* Separates keywords from other attributes. */
147 char key_positions[MAX_KEY_POS]; /* Contains user-specified key choices. */
148} OPTIONS;
149
150extern void options_init P ((int argc, char *argv[]));
151extern void options_destroy P ((void));
152extern OPTIONS option;
153#endif /* _options_h */
157#endif