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, 2002-2003 Free Software Foundation, Inc.
6    Written by Douglas C. Schmidt <schmidt@ics.uci.edu>
7    and Bruno Haible <bruno@clisp.org>.
8 
9    This file is part of GNU GPERF.
10 
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)
14    any later version.
15 
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.
20 
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.  */
25 
26 /* This module provides a uniform interface to the various options available
27    to a user of the gperf hash function generator.  */
28 
29 #ifndef options_h
30 #define options_h 1
31 
32 #include <stdio.h>
33 #include "positions.h"
34 
35 /* Enumeration of the possible boolean options.  */
36 
37 enum Option_Type
38 {
39   /* --- Input file interpretation --- */
40 
41   /* Ignore case of ASCII characters.  */
42   UPPERLOWER   = 1 << 1,
43 
44   /* --- Details in the output code --- */
45 
46   /* Assume 7-bit, not 8-bit, characters.  */
47   SEVENBIT     = 1 << 6,
48 
49   /* --- Algorithm employed by gperf --- */
50 
51   /* Use the given key positions.  */
52   POSITIONS    = 1 << 17,
53 
54   /* Handle duplicate hash values for keywords.  */
55   DUP          = 1 << 18,
56 
57   /* Don't include keyword length in hash computations.  */
58   NOLENGTH     = 1 << 19,
59 
60   /* Randomly initialize the associated values table.  */
61   RANDOM       = 1 << 20,
62 
63   /* --- Informative output --- */
64 
65   /* Enable debugging (prints diagnostics to stderr).  */
66   DEBUG        = 1 << 21
67 };
68 
69 /* Class manager for gperf program Options.  */
70 
71 struct Options
72 {
73 public:
74   /* Constructor.  */
75                         Options ();
76 
77   /* Accessors.  */
78 
79   /* Tests a given boolean option.  Returns true if set, false otherwise.  */
80   bool                  operator[] (Option_Type option) const;
81 
82   /* Sets a given boolean option.  */
83   void                  set (Option_Type option);
84 
85   /* Returns the jump value.  */
86   int                   get_jump () const;
87 
88   /* Returns the initial associated character value.  */
89   int                   get_initial_asso_value () const;
90 
91   /* Returns the number of iterations for finding good asso_values.  */
92   int                   get_asso_iterations () const;
93 
94   /* Returns the factor by which to multiply the generated table's size.  */
95   float                 get_size_multiple () const;
96 
97   /* Returns key positions.  */
98   const Positions&      get_key_positions () const;
99 
100   /* Holds the boolean options.  */
101   int                   _option_word;
102 
103   /* Jump length when trying alternative values.  */
104   int                   _jump;
105 
106   /* Initial value for asso_values table.  */
107   int                   _initial_asso_value;
108 
109   /* Number of attempts at finding good asso_values.  */
110   int                   _asso_iterations;
111 
112   /* Factor by which to multiply the generated table's size.  */
113   float                 _size_multiple;
114 
115   /* Contains user-specified key choices.  */
116   Positions             _key_positions;
117 };
118 
119 /* Global option coordinator for the entire program.  */
120 extern Options option;
121 
122 #ifdef __OPTIMIZE__
123 
124 #define INLINE inline
125 #include "options.icc"
126 #undef INLINE
127 
128 #endif
129 
130 #endif
131