158551Skris/* This may look like C code, but it is really -*- C++ -*- */ 258551Skris 318214Speter/* Handles parsing the Options provided to the user. 418214Speter 5228060Sbapt Copyright (C) 1989-1998, 2000, 2002-2004 Free Software Foundation, Inc. 6228060Sbapt Written by Douglas C. Schmidt <schmidt@ics.uci.edu> 7228060Sbapt and Bruno Haible <bruno@clisp.org>. 818214Speter 9228060Sbapt This file is part of GNU GPERF. 1018214Speter 11228060Sbapt GNU GPERF is free software; you can redistribute it and/or modify 12228060Sbapt it under the terms of the GNU General Public License as published by 13228060Sbapt the Free Software Foundation; either version 2, or (at your option) 14228060Sbapt any later version. 1518214Speter 16228060Sbapt GNU GPERF is distributed in the hope that it will be useful, 17228060Sbapt but WITHOUT ANY WARRANTY; without even the implied warranty of 18228060Sbapt MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19228060Sbapt GNU General Public License for more details. 2018214Speter 21228060Sbapt You should have received a copy of the GNU General Public License 22228060Sbapt along with this program; see the file COPYING. 23228060Sbapt If not, write to the Free Software Foundation, Inc., 24228060Sbapt 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ 2518214Speter 2658551Skris/* This module provides a uniform interface to the various options available 27228060Sbapt to a user of the gperf hash function generator. */ 2818214Speter 2958551Skris#ifndef options_h 3058551Skris#define options_h 1 3118214Speter 3218214Speter#include <stdio.h> 33228060Sbapt#include "positions.h" 3418214Speter 35228060Sbapt/* Enumeration of the possible boolean options. */ 3618214Speter 3758551Skrisenum Option_Type 3818214Speter{ 39228060Sbapt /* --- Input file interpretation --- */ 4018214Speter 41228060Sbapt /* Handle user-defined type structured keyword input. */ 42228060Sbapt TYPE = 1 << 0, 4318214Speter 44228060Sbapt /* Ignore case of ASCII characters. */ 45228060Sbapt UPPERLOWER = 1 << 1, 46228060Sbapt 47228060Sbapt /* --- Language for the output code --- */ 48228060Sbapt 49228060Sbapt /* Generate K&R C code: no prototypes, no const. */ 50228060Sbapt KRC = 1 << 2, 51228060Sbapt 52228060Sbapt /* Generate C code: no prototypes, but const (user can #define it away). */ 53228060Sbapt C = 1 << 3, 54228060Sbapt 55228060Sbapt /* Generate ISO/ANSI C code: prototypes and const, but no class. */ 56228060Sbapt ANSIC = 1 << 4, 57228060Sbapt 58228060Sbapt /* Generate C++ code: prototypes, const, class, inline, enum. */ 59228060Sbapt CPLUSPLUS = 1 << 5, 60228060Sbapt 61228060Sbapt /* --- Details in the output code --- */ 62228060Sbapt 63228060Sbapt /* Assume 7-bit, not 8-bit, characters. */ 64228060Sbapt SEVENBIT = 1 << 6, 65228060Sbapt 66228060Sbapt /* Generate a length table for string comparison. */ 67228060Sbapt LENTABLE = 1 << 7, 68228060Sbapt 69228060Sbapt /* Generate strncmp rather than strcmp. */ 70228060Sbapt COMP = 1 << 8, 71228060Sbapt 72228060Sbapt /* Make the generated tables readonly (const). */ 73228060Sbapt CONST = 1 << 9, 74228060Sbapt 75228060Sbapt /* Use enum for constants. */ 76228060Sbapt ENUM = 1 << 10, 77228060Sbapt 78228060Sbapt /* Generate #include statements. */ 79228060Sbapt INCLUDE = 1 << 11, 80228060Sbapt 81228060Sbapt /* Make the keyword table a global variable. */ 82228060Sbapt GLOBAL = 1 << 12, 83228060Sbapt 84228060Sbapt /* Use NULL strings instead of empty strings for empty table entries. */ 85228060Sbapt NULLSTRINGS = 1 << 13, 86228060Sbapt 87228060Sbapt /* Optimize for position-independent code. */ 88228060Sbapt SHAREDLIB = 1 << 14, 89228060Sbapt 90228060Sbapt /* Generate switch output to save space. */ 91228060Sbapt SWITCH = 1 << 15, 92228060Sbapt 93228060Sbapt /* Don't include user-defined type definition in output -- it's already 94228060Sbapt defined elsewhere. */ 95228060Sbapt NOTYPE = 1 << 16, 96228060Sbapt 97228060Sbapt /* --- Algorithm employed by gperf --- */ 98228060Sbapt 99228060Sbapt /* Use the given key positions. */ 100228060Sbapt POSITIONS = 1 << 17, 101228060Sbapt 102228060Sbapt /* Handle duplicate hash values for keywords. */ 103228060Sbapt DUP = 1 << 18, 104228060Sbapt 105228060Sbapt /* Don't include keyword length in hash computations. */ 106228060Sbapt NOLENGTH = 1 << 19, 107228060Sbapt 108228060Sbapt /* Randomly initialize the associated values table. */ 109228060Sbapt RANDOM = 1 << 20, 110228060Sbapt 111228060Sbapt /* --- Informative output --- */ 112228060Sbapt 113228060Sbapt /* Enable debugging (prints diagnostics to stderr). */ 114228060Sbapt DEBUG = 1 << 21 11558551Skris}; 11618214Speter 117228060Sbapt/* Class manager for gperf program Options. */ 11818214Speter 11958551Skrisclass Options 12058551Skris{ 12158551Skrispublic: 122228060Sbapt /* Constructor. */ 123228060Sbapt Options (); 12418214Speter 125228060Sbapt /* Destructor. */ 126228060Sbapt ~Options (); 127228060Sbapt 128228060Sbapt /* Parses the options given in the command-line arguments. */ 129228060Sbapt void parse_options (int argc, char *argv[]); 130228060Sbapt 131228060Sbapt /* Prints the given options. */ 132228060Sbapt void print_options () const; 133228060Sbapt 134228060Sbapt /* Accessors. */ 135228060Sbapt 136228060Sbapt /* Tests a given boolean option. Returns true if set, false otherwise. */ 137228060Sbapt bool operator[] (Option_Type option) const; 138228060Sbapt /* Sets a given boolean option. */ 139228060Sbapt void set (Option_Type option); 140228060Sbapt 141228060Sbapt /* Returns the input file name. */ 142228060Sbapt const char * get_input_file_name () const; 143228060Sbapt 144228060Sbapt /* Returns the output file name. */ 145228060Sbapt const char * get_output_file_name () const; 146228060Sbapt 147228060Sbapt /* Sets the output language, if not already set. */ 148228060Sbapt void set_language (const char *language); 149228060Sbapt 150228060Sbapt /* Returns the jump value. */ 151228060Sbapt int get_jump () const; 152228060Sbapt 153228060Sbapt /* Returns the initial associated character value. */ 154228060Sbapt int get_initial_asso_value () const; 155228060Sbapt 156228060Sbapt /* Returns the number of iterations for finding good asso_values. */ 157228060Sbapt int get_asso_iterations () const; 158228060Sbapt 159228060Sbapt /* Returns the total number of switch statements to generate. */ 160228060Sbapt int get_total_switches () const; 161228060Sbapt /* Sets the total number of switch statements, if not already set. */ 162228060Sbapt void set_total_switches (int total_switches); 163228060Sbapt 164228060Sbapt /* Returns the factor by which to multiply the generated table's size. */ 165228060Sbapt float get_size_multiple () const; 166228060Sbapt 167228060Sbapt /* Returns the generated function name. */ 168228060Sbapt const char * get_function_name () const; 169228060Sbapt /* Sets the generated function name, if not already set. */ 170228060Sbapt void set_function_name (const char *name); 171228060Sbapt 172228060Sbapt /* Returns the keyword key name. */ 173228060Sbapt const char * get_slot_name () const; 174228060Sbapt /* Sets the keyword key name, if not already set. */ 175228060Sbapt void set_slot_name (const char *name); 176228060Sbapt 177228060Sbapt /* Returns the struct initializer suffix. */ 178228060Sbapt const char * get_initializer_suffix () const; 179228060Sbapt /* Sets the struct initializer suffix, if not already set. */ 180228060Sbapt void set_initializer_suffix (const char *initializers); 181228060Sbapt 182228060Sbapt /* Returns the generated class name. */ 183228060Sbapt const char * get_class_name () const; 184228060Sbapt /* Sets the generated class name, if not already set. */ 185228060Sbapt void set_class_name (const char *name); 186228060Sbapt 187228060Sbapt /* Returns the hash function name. */ 188228060Sbapt const char * get_hash_name () const; 189228060Sbapt /* Sets the hash function name, if not already set. */ 190228060Sbapt void set_hash_name (const char *name); 191228060Sbapt 192228060Sbapt /* Returns the hash table array name. */ 193228060Sbapt const char * get_wordlist_name () const; 194228060Sbapt /* Sets the hash table array name, if not already set. */ 195228060Sbapt void set_wordlist_name (const char *name); 196228060Sbapt 197228060Sbapt /* Returns the length table array name. */ 198228060Sbapt const char * get_lengthtable_name () const; 199228060Sbapt /* Sets the length table array name, if not already set. */ 200228060Sbapt void set_lengthtable_name (const char *name); 201228060Sbapt 202228060Sbapt /* Returns the string pool name. */ 203228060Sbapt const char * get_stringpool_name () const; 204228060Sbapt /* Sets the string pool name, if not already set. */ 205228060Sbapt void set_stringpool_name (const char *name); 206228060Sbapt 207228060Sbapt /* Returns the string used to delimit keywords from other attributes. */ 208228060Sbapt const char * get_delimiters () const; 209228060Sbapt /* Sets the delimiters string, if not already set. */ 210228060Sbapt void set_delimiters (const char *delimiters); 211228060Sbapt 212228060Sbapt /* Returns key positions. */ 213228060Sbapt const Positions& get_key_positions () const; 214228060Sbapt 21558551Skrisprivate: 216228060Sbapt /* Prints program usage to given stream. */ 217228060Sbapt static void short_usage (FILE * stream); 218228060Sbapt 219228060Sbapt /* Prints program usage to given stream. */ 220228060Sbapt static void long_usage (FILE * stream); 221228060Sbapt 222228060Sbapt /* Records count of command-line arguments. */ 223228060Sbapt int _argument_count; 224228060Sbapt 225228060Sbapt /* Stores a pointer to command-line argument vector. */ 226228060Sbapt char ** _argument_vector; 227228060Sbapt 228228060Sbapt /* Holds the boolean options. */ 229228060Sbapt int _option_word; 230228060Sbapt 231228060Sbapt /* Name of input file. */ 232228060Sbapt char * _input_file_name; 233228060Sbapt 234228060Sbapt /* Name of output file. */ 235228060Sbapt char * _output_file_name; 236228060Sbapt 237228060Sbapt /* The output language. */ 238228060Sbapt const char * _language; 239228060Sbapt 240228060Sbapt /* Jump length when trying alternative values. */ 241228060Sbapt int _jump; 242228060Sbapt 243228060Sbapt /* Initial value for asso_values table. */ 244228060Sbapt int _initial_asso_value; 245228060Sbapt 246228060Sbapt /* Number of attempts at finding good asso_values. */ 247228060Sbapt int _asso_iterations; 248228060Sbapt 249228060Sbapt /* Number of switch statements to generate. */ 250228060Sbapt int _total_switches; 251228060Sbapt 252228060Sbapt /* Factor by which to multiply the generated table's size. */ 253228060Sbapt float _size_multiple; 254228060Sbapt 255228060Sbapt /* Names used for generated lookup function. */ 256228060Sbapt const char * _function_name; 257228060Sbapt 258228060Sbapt /* Name used for keyword key. */ 259228060Sbapt const char * _slot_name; 260228060Sbapt 261228060Sbapt /* Suffix for empty struct initializers. */ 262228060Sbapt const char * _initializer_suffix; 263228060Sbapt 264228060Sbapt /* Name used for generated C++ class. */ 265228060Sbapt const char * _class_name; 266228060Sbapt 267228060Sbapt /* Name used for generated hash function. */ 268228060Sbapt const char * _hash_name; 269228060Sbapt 270228060Sbapt /* Name used for hash table array. */ 271228060Sbapt const char * _wordlist_name; 272228060Sbapt 273228060Sbapt /* Name used for length table array. */ 274228060Sbapt const char * _lengthtable_name; 275228060Sbapt 276228060Sbapt /* Name used for the string pool. */ 277228060Sbapt const char * _stringpool_name; 278228060Sbapt 279228060Sbapt /* Separates keywords from other attributes. */ 280228060Sbapt const char * _delimiters; 281228060Sbapt 282228060Sbapt /* Contains user-specified key choices. */ 283228060Sbapt Positions _key_positions; 28458551Skris}; 28518214Speter 286228060Sbapt/* Global option coordinator for the entire program. */ 28758551Skrisextern Options option; 28818214Speter 28958551Skris#ifdef __OPTIMIZE__ 29018214Speter 29158551Skris#define INLINE inline 29258551Skris#include "options.icc" 29358551Skris#undef INLINE 29418214Speter 29558551Skris#endif 29618214Speter 29758551Skris#endif 298