* Add this nice filesystem testing tool that I've recently
[dragonfly.git] / contrib / gperf / src / options.h
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 Free Software Foundation, Inc.
6    written by Douglas C. Schmidt (schmidt@ics.uci.edu)
7
8 This file is part of GNU GPERF.
9
10 GNU GPERF is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 1, or (at your option)
13 any later version.
14
15 GNU GPERF is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 GNU General Public License for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with GNU GPERF; see the file COPYING.  If not, write to the Free
22 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111, USA.  */
23
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
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
32 #ifndef options_h
33 #define options_h 1
34
35 #include <stdio.h>
36
37 /* Enumerate the potential debugging Options. */
38
39 enum Option_Type
40 {
41   DEBUG        = 01,            /* Enable debugging (prints diagnostics to stderr). */
42   ORDER        = 02,            /* Apply ordering heuristic to speed-up search time. */
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. */
63 };
64
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... ;-( */
68
69 enum
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 };
76
77 /* Class manager for gperf program Options. */
78
79 class Options
80 {
81 public:
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_initializer_suffix (void);
102   static const char  *get_class_name (void);
103   static const char  *get_hash_name (void);
104   static const char  *get_wordlist_name (void);
105   static const char  *get_delimiter (void);
106
107 private:
108   static int          option_word;                        /* Holds the user-specified Options. */
109   static int          total_switches;                     /* Number of switch statements to generate. */
110   static int          total_keysig_size;                  /* Total number of distinct key_positions. */
111   static int          size;                               /* Range of the hash table. */
112   static int          key_pos;                            /* Tracks current key position for Iterator. */
113   static int          jump;                               /* Jump length when trying alternative values. */
114   static int          initial_asso_value;                 /* Initial value for asso_values table. */
115   static int          argument_count;                     /* Records count of command-line arguments. */
116   static int          iterations;                         /* Amount to iterate when a collision occurs. */
117   static char       **argument_vector;                    /* Stores a pointer to command-line vector. */
118   static const char  *function_name;                      /* Names used for generated lookup function. */
119   static const char  *key_name;                           /* Name used for keyword key. */
120   static const char  *initializer_suffix;                 /* Suffix for empty struct initializers. */
121   static const char  *class_name;                         /* Name used for generated C++ class. */
122   static const char  *hash_name;                          /* Name used for generated hash function. */
123   static const char  *wordlist_name;                      /* Name used for hash table array. */
124   static const char  *delimiters;                         /* Separates keywords from other attributes. */
125   static char         key_positions[MAX_KEY_POS];         /* Contains user-specified key choices. */
126   static int          key_sort (char *base, int len);     /* Sorts key positions in REVERSE order. */
127   static void         short_usage (FILE * strm);          /* Prints proper program usage. */
128   static void         long_usage (FILE * strm);           /* Prints proper program usage. */
129 };
130
131 /* Global option coordinator for the entire program. */
132 extern Options option;
133
134 /* Set to 1 if your want to stack-allocate some large arrays.
135    This requires compiler support for variable-size arrays on the stack
136    (not ANSI). */
137 #ifndef LARGE_STACK_ARRAYS
138 #if defined(__GNUG__) && !defined(__STRICT_ANSI__)
139 #define LARGE_STACK_ARRAYS 1
140 #else
141 #define LARGE_STACK_ARRAYS 0
142 #endif
143 #endif
144
145 /* Set to 1 if the stack is large enough for holding a text line. */
146 #ifndef LARGE_STACK
147 #define LARGE_STACK 1
148 #endif
149
150 #ifdef __OPTIMIZE__
151
152 #include "trace.h"
153 #define INLINE inline
154 #include "options.icc"
155 #undef INLINE
156
157 #endif
158
159 #endif