home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / gnu / cperf-2.1 / src / options.h < prev    next >
Encoding:
C/C++ Source or Header  |  1989-11-11  |  6.3 KB  |  154 lines

  1. /* Handles parsing the Options provided to the user.
  2.  
  3.    Copyright (C) 1989 Free Software Foundation, Inc.
  4.    written by Douglas C. Schmidt (schmidt@ics.uci.edu)
  5.  
  6. This file is part of GNU GPERF.
  7.  
  8. GNU GPERF is free software; you can redistribute it and/or modify
  9. it under the terms of the GNU General Public License as published by
  10. the Free Software Foundation; either version 1, or (at your option)
  11. any later version.
  12.  
  13. GNU GPERF is distributed in the hope that it will be useful,
  14. but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16. GNU General Public License for more details.
  17.  
  18. You should have received a copy of the GNU General Public License
  19. along with GNU GPERF; see the file COPYING.  If not, write to
  20. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  21.  
  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
  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.  
  30. #ifndef _options_h
  31. #define _options_h
  32.  
  33. #include <stdio.h>
  34. #include "prototype.h"
  35.  
  36. /* Enumerate the potential debugging Options. */
  37.  
  38. enum option_type 
  39. {
  40.   DEBUG        = 01,            /* Enable debugging (prints diagnostics to Std_Err). */
  41.   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). */
  59. };
  60.  
  61. /* Define some useful constants. */
  62.  
  63. /* Max size of each word's key set. */
  64. #define MAX_KEY_POS (128 - 1)
  65.  
  66. /* Signals the start of a word. */
  67. #define WORD_START 1           
  68.  
  69. /* Signals the end of a word. */
  70. #define WORD_END 0             
  71.  
  72. /* Signals end of the key list. */
  73. #define EOS MAX_KEY_POS        
  74.  
  75. /* Returns TRUE if option O is enabled. */
  76. #define OPTION_ENABLED(OW,O) (OW.option_word & (int)O)
  77.  
  78. /* Enables option O in OPTION_WORD. */
  79. #define SET_OPTION(OW,O) (OW.option_word |= (int)O)
  80.  
  81. /* Disable option O in OPTION_WORD. */
  82. #define UNSET_OPTION(OW,O) (OW.option_word &= ~(int)(O))
  83.  
  84. /* Returns total distinct key positions. */
  85. #define GET_CHARSET_SIZE(O) (O.total_charset_size)
  86.  
  87. /* Set the total distinct key positions. */
  88. #define SET_CHARSET_SIZE(O,S) (O.total_charset_size = (S))
  89.  
  90. /* Initializes the key Iterator. */
  91. #define RESET(O) (O.key_pos = 0)
  92.  
  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.  
  131. typedef 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.  
  150. extern void    options_init P ((int argc, char *argv[]));
  151. extern void    options_destroy P ((void));
  152. extern OPTIONS option;       
  153. #endif /* _options_h */
  154.