1
0
mirror of https://git.savannah.gnu.org/git/gperf.git synced 2025-12-02 21:19:24 +00:00

Prefix all field names with _.

This commit is contained in:
Bruno Haible
2002-11-09 01:12:49 +00:00
parent 643c2cab82
commit 34da28c8ab
23 changed files with 480 additions and 475 deletions

View File

@@ -1,5 +1,8 @@
2002-10-13 Bruno Haible <bruno@clisp.org> 2002-10-13 Bruno Haible <bruno@clisp.org>
* src/*.h: Prefix all field names with _.
* src/*.cc, src/*.icc: Update.
* src/*: Simplify declarations of functions without arguments. * src/*: Simplify declarations of functions without arguments.
2002-10-04 Bruno Haible <bruno@clisp.org> 2002-10-04 Bruno Haible <bruno@clisp.org>

View File

@@ -31,7 +31,7 @@ Bool_Array::~Bool_Array ()
if (option[DEBUG]) if (option[DEBUG])
fprintf (stderr, "\ndumping boolean array information\n" fprintf (stderr, "\ndumping boolean array information\n"
"size = %d\niteration number = %d\nend of array dump\n", "size = %d\niteration number = %d\nend of array dump\n",
size, iteration_number); _size, _iteration_number);
} }
#ifndef __OPTIMIZE__ #ifndef __OPTIMIZE__

View File

@@ -48,11 +48,11 @@ public:
int set_bit (unsigned int index); int set_bit (unsigned int index);
private: private:
unsigned int size; /* Size of array. */ unsigned int _size; /* Size of array. */
unsigned int iteration_number; /* Number of times clear() was called + 1. */ unsigned int _iteration_number; /* Number of times clear() was called + 1. */
/* For each index, we store in storage_array[index] the iteration_number at /* For each index, we store in storage_array[index] the iteration_number at
the time set_bit(index) was last called. */ the time set_bit(index) was last called. */
unsigned int *storage_array; unsigned int *_storage_array;
}; };
#ifdef __OPTIMIZE__ /* efficiency hack! */ #ifdef __OPTIMIZE__ /* efficiency hack! */

View File

@@ -27,25 +27,25 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
/* Initializes the bit array with room for s bits, numbered from 0 to s-1. */ /* Initializes the bit array with room for s bits, numbered from 0 to s-1. */
INLINE INLINE
Bool_Array::Bool_Array (unsigned int s) Bool_Array::Bool_Array (unsigned int s)
: size (s), iteration_number (1), storage_array (new unsigned int [s]) : _size (s), _iteration_number (1), _storage_array (new unsigned int [s])
{ {
memset (storage_array, 0, s * sizeof (unsigned int)); memset (_storage_array, 0, s * sizeof (unsigned int));
if (option[DEBUG]) if (option[DEBUG])
fprintf (stderr, "\nbool array size = %d, total bytes = %d\n", fprintf (stderr, "\nbool array size = %d, total bytes = %d\n",
size, (unsigned int) (size * sizeof (*storage_array))); _size, (unsigned int) (_size * sizeof (*_storage_array)));
} }
/* Sets the specified bit to one. Returns its previous value (0 or 1). */ /* Sets the specified bit to one. Returns its previous value (0 or 1). */
INLINE int INLINE int
Bool_Array::set_bit (unsigned int index) Bool_Array::set_bit (unsigned int index)
{ {
if (storage_array[index] == iteration_number) if (_storage_array[index] == _iteration_number)
/* The bit was set since the last clear() call. */ /* The bit was set since the last clear() call. */
return 1; return 1;
else else
{ {
/* The last operation on this bit was clear(). Set it now. */ /* The last operation on this bit was clear(). Set it now. */
storage_array[index] = iteration_number; _storage_array[index] = _iteration_number;
return 0; return 0;
} }
} }
@@ -58,10 +58,10 @@ Bool_Array::clear ()
occurs once about every 2^32 iterations, so it will not happen more occurs once about every 2^32 iterations, so it will not happen more
frequently than once per second. */ frequently than once per second. */
if (++iteration_number == 0) if (++_iteration_number == 0)
{ {
iteration_number = 1; _iteration_number = 1;
memset (storage_array, 0, size * sizeof (unsigned int)); memset (_storage_array, 0, _size * sizeof (unsigned int));
if (option[DEBUG]) if (option[DEBUG])
{ {
fprintf (stderr, "(re-initialized bool_array)\n"); fprintf (stderr, "(re-initialized bool_array)\n");

View File

@@ -45,8 +45,8 @@ Gen_Perf::Gen_Perf ()
reorder (); reorder ();
asso_value_max = option.get_asso_max (); asso_value_max = option.get_asso_max ();
non_linked_length = Key_List::keyword_list_length (); non_linked_length = Key_List::keyword_list_length ();
num_done = 1; _num_done = 1;
fewest_collisions = 0; _fewest_collisions = 0;
if (asso_value_max == 0) if (asso_value_max == 0)
asso_value_max = non_linked_length; asso_value_max = non_linked_length;
else if (asso_value_max > 0) else if (asso_value_max > 0)
@@ -60,7 +60,7 @@ Gen_Perf::Gen_Perf ()
srand ((long) time (0)); srand ((long) time (0));
for (int i = 0; i < ALPHA_SIZE; i++) for (int i = 0; i < ALPHA_SIZE; i++)
asso_values[i] = (rand () & asso_value_max - 1); _asso_values[i] = (rand () & asso_value_max - 1);
} }
else else
{ {
@@ -68,16 +68,16 @@ Gen_Perf::Gen_Perf ()
if (asso_value) /* Initialize array if user requests non-zero default. */ if (asso_value) /* Initialize array if user requests non-zero default. */
for (int i = ALPHA_SIZE - 1; i >= 0; i--) for (int i = ALPHA_SIZE - 1; i >= 0; i--)
asso_values[i] = asso_value & option.get_asso_max () - 1; _asso_values[i] = asso_value & option.get_asso_max () - 1;
} }
max_hash_value = Key_List::max_key_length () + option.get_asso_max () * _max_hash_value = Key_List::max_key_length () + option.get_asso_max () *
option.get_max_keysig_size (); option.get_max_keysig_size ();
collision_detector = new Bool_Array (max_hash_value + 1); _collision_detector = new Bool_Array (_max_hash_value + 1);
if (option[DEBUG]) if (option[DEBUG])
fprintf (stderr, "total non-linked keys = %d\nmaximum associated value is %d" fprintf (stderr, "total non-linked keys = %d\nmaximum associated value is %d"
"\nmaximum size of generated hash table is %d\n", "\nmaximum size of generated hash table is %d\n",
non_linked_length, asso_value_max, max_hash_value); non_linked_length, asso_value_max, _max_hash_value);
} }
/* Merge two disjoint hash key multisets to form the ordered disjoint union of the sets. /* Merge two disjoint hash key multisets to form the ordered disjoint union of the sets.
@@ -138,7 +138,7 @@ Gen_Perf::sort_set (char *union_set, int len)
char tmp; char tmp;
for (curr = i + 1, tmp = union_set[curr]; for (curr = i + 1, tmp = union_set[curr];
curr > 0 && occurrences[(unsigned char)tmp] < occurrences[(unsigned char)(union_set[curr-1])]; curr > 0 && _occurrences[(unsigned char)tmp] < _occurrences[(unsigned char)(union_set[curr-1])];
curr--) curr--)
union_set[curr] = union_set[curr - 1]; union_set[curr] = union_set[curr - 1];
@@ -151,14 +151,14 @@ Gen_Perf::sort_set (char *union_set, int len)
inline int inline int
Gen_Perf::hash (KeywordExt *key_node) Gen_Perf::hash (KeywordExt *key_node)
{ {
int sum = option[NOLENGTH] ? 0 : key_node->allchars_length; int sum = option[NOLENGTH] ? 0 : key_node->_allchars_length;
const char *p = key_node->selchars; const char *p = key_node->_selchars;
int i = key_node->selchars_length; int i = key_node->_selchars_length;
for (; i > 0; p++, i--) for (; i > 0; p++, i--)
sum += asso_values[(unsigned char)(*p)]; sum += _asso_values[(unsigned char)(*p)];
return key_node->hash_value = sum; return key_node->_hash_value = sum;
} }
/* Find out how character value change affects successfully hashed items. /* Find out how character value change affects successfully hashed items.
@@ -170,7 +170,7 @@ Gen_Perf::hash (KeywordExt *key_node)
inline int inline int
Gen_Perf::affects_prev (char c, KeywordExt *curr) Gen_Perf::affects_prev (char c, KeywordExt *curr)
{ {
int original_char = asso_values[(unsigned char)c]; int original_char = _asso_values[(unsigned char)c];
int total_iterations = !option[FAST] int total_iterations = !option[FAST]
? option.get_asso_max () : option.get_iterations () ? option.get_iterations () : keyword_list_length (); ? option.get_asso_max () : option.get_iterations () ? option.get_iterations () : keyword_list_length ();
@@ -180,25 +180,25 @@ Gen_Perf::affects_prev (char c, KeywordExt *curr)
{ {
int collisions = 0; int collisions = 0;
asso_values[(unsigned char)c] = _asso_values[(unsigned char)c] =
(asso_values[(unsigned char)c] + (option.get_jump () ? option.get_jump () : rand ())) (_asso_values[(unsigned char)c] + (option.get_jump () ? option.get_jump () : rand ()))
& (option.get_asso_max () - 1); & (option.get_asso_max () - 1);
/* Iteration Number array is a win, O(1) intialization time! */ /* Iteration Number array is a win, O(1) intialization time! */
collision_detector->clear (); _collision_detector->clear ();
/* See how this asso_value change affects previous keywords. If /* See how this asso_value change affects previous keywords. If
it does better than before we'll take it! */ it does better than before we'll take it! */
for (KeywordExt_List *ptr = head; ; ptr = ptr->rest()) for (KeywordExt_List *ptr = _head; ; ptr = ptr->rest())
{ {
KeywordExt *keyword = ptr->first(); KeywordExt *keyword = ptr->first();
if (collision_detector->set_bit (hash (keyword)) if (_collision_detector->set_bit (hash (keyword))
&& ++collisions >= fewest_collisions) && ++collisions >= _fewest_collisions)
break; break;
if (keyword == curr) if (keyword == curr)
{ {
fewest_collisions = collisions; _fewest_collisions = collisions;
if (option[DEBUG]) if (option[DEBUG])
fprintf (stderr, "- resolved after %d iterations", total_iterations - i); fprintf (stderr, "- resolved after %d iterations", total_iterations - i);
return 0; return 0;
@@ -207,7 +207,7 @@ Gen_Perf::affects_prev (char c, KeywordExt *curr)
} }
/* Restore original values, no more tries. */ /* Restore original values, no more tries. */
asso_values[(unsigned char)c] = original_char; _asso_values[(unsigned char)c] = original_char;
/* If we're this far it's time to try the next character.... */ /* If we're this far it's time to try the next character.... */
return 1; return 1;
} }
@@ -226,17 +226,17 @@ Gen_Perf::change (KeywordExt *prior, KeywordExt *curr)
if (option[DEBUG]) if (option[DEBUG])
{ {
fprintf (stderr, "collision on keyword #%d, prior = \"%.*s\", curr = \"%.*s\" hash = %d\n", fprintf (stderr, "collision on keyword #%d, prior = \"%.*s\", curr = \"%.*s\" hash = %d\n",
num_done, _num_done,
prior->allchars_length, prior->allchars, prior->_allchars_length, prior->_allchars,
curr->allchars_length, curr->allchars, curr->_allchars_length, curr->_allchars,
curr->hash_value); curr->_hash_value);
fflush (stderr); fflush (stderr);
} }
union_set_length = compute_disjoint_union (prior->selchars, prior->selchars_length, curr->selchars, curr->selchars_length, union_set); union_set_length = compute_disjoint_union (prior->_selchars, prior->_selchars_length, curr->_selchars, curr->_selchars_length, union_set);
sort_set (union_set, union_set_length); sort_set (union_set, union_set_length);
/* Try changing some values, if change doesn't alter other values continue normal action. */ /* Try changing some values, if change doesn't alter other values continue normal action. */
fewest_collisions++; _fewest_collisions++;
const char *p = union_set; const char *p = union_set;
int i = union_set_length; int i = union_set_length;
@@ -246,13 +246,13 @@ Gen_Perf::change (KeywordExt *prior, KeywordExt *curr)
if (option[DEBUG]) if (option[DEBUG])
{ {
fprintf (stderr, " by changing asso_value['%c'] (char #%d) to %d\n", fprintf (stderr, " by changing asso_value['%c'] (char #%d) to %d\n",
*p, p - union_set + 1, asso_values[(unsigned char)(*p)]); *p, p - union_set + 1, _asso_values[(unsigned char)(*p)]);
fflush (stderr); fflush (stderr);
} }
return; /* Good, doesn't affect previous hash values, we'll take it. */ return; /* Good, doesn't affect previous hash values, we'll take it. */
} }
for (KeywordExt_List *ptr = head; ; ptr = ptr->rest()) for (KeywordExt_List *ptr = _head; ; ptr = ptr->rest())
{ {
KeywordExt* keyword = ptr->first(); KeywordExt* keyword = ptr->first();
if (keyword == curr) if (keyword == curr)
@@ -266,7 +266,7 @@ Gen_Perf::change (KeywordExt *prior, KeywordExt *curr)
{ {
fprintf (stderr, "** collision not resolved after %d iterations, %d duplicates remain, continuing...\n", fprintf (stderr, "** collision not resolved after %d iterations, %d duplicates remain, continuing...\n",
!option[FAST] ? option.get_asso_max () : option.get_iterations () ? option.get_iterations () : keyword_list_length (), !option[FAST] ? option.get_asso_max () : option.get_iterations () ? option.get_iterations () : keyword_list_length (),
fewest_collisions + total_duplicates); _fewest_collisions + _total_duplicates);
fflush (stderr); fflush (stderr);
} }
} }
@@ -286,36 +286,36 @@ int
Gen_Perf::doit_all () Gen_Perf::doit_all ()
{ {
KeywordExt_List *curr; KeywordExt_List *curr;
for (curr = head; curr != NULL; curr = curr->rest()) for (curr = _head; curr != NULL; curr = curr->rest())
{ {
KeywordExt *currkw = curr->first(); KeywordExt *currkw = curr->first();
hash (currkw); hash (currkw);
for (KeywordExt_List *ptr = head; ptr != curr; ptr = ptr->rest()) for (KeywordExt_List *ptr = _head; ptr != curr; ptr = ptr->rest())
{ {
KeywordExt *ptrkw = ptr->first(); KeywordExt *ptrkw = ptr->first();
if (ptrkw->hash_value == currkw->hash_value) if (ptrkw->_hash_value == currkw->_hash_value)
{ {
change (ptrkw, currkw); change (ptrkw, currkw);
break; break;
} }
} }
num_done++; _num_done++;
} }
/* Make one final check, just to make sure nothing weird happened.... */ /* Make one final check, just to make sure nothing weird happened.... */
collision_detector->clear (); _collision_detector->clear ();
for (curr = head; curr; curr = curr->rest()) for (curr = _head; curr; curr = curr->rest())
{ {
unsigned int hashcode = hash (curr->first()); unsigned int hashcode = hash (curr->first());
if (collision_detector->set_bit (hashcode)) if (_collision_detector->set_bit (hashcode))
{ {
if (option[DUP]) /* Keep track of this number... */ if (option[DUP]) /* Keep track of this number... */
total_duplicates++; _total_duplicates++;
else /* Yow, big problems. we're outta here! */ else /* Yow, big problems. we're outta here! */
{ {
fprintf (stderr, fprintf (stderr,
@@ -332,9 +332,9 @@ Gen_Perf::doit_all ()
processing turned out O.K. */ processing turned out O.K. */
sort (); sort ();
Output outputter (head, array_type, return_type, struct_tag, additional_code, Output outputter (_head, _array_type, _return_type, _struct_tag, _additional_code,
include_src, total_keys, total_duplicates, max_key_len, _include_src, _total_keys, _total_duplicates, _max_key_len,
min_key_len, this); _min_key_len, this);
outputter.output (); outputter.output ();
return 0; return 0;
} }
@@ -348,13 +348,13 @@ Gen_Perf::~Gen_Perf ()
fprintf (stderr, "\ndumping occurrence and associated values tables\n"); fprintf (stderr, "\ndumping occurrence and associated values tables\n");
for (int i = 0; i < ALPHA_SIZE; i++) for (int i = 0; i < ALPHA_SIZE; i++)
if (occurrences[i]) if (_occurrences[i])
fprintf (stderr, "asso_values[%c] = %6d, occurrences[%c] = %6d\n", fprintf (stderr, "asso_values[%c] = %6d, occurrences[%c] = %6d\n",
i, asso_values[i], i, occurrences[i]); i, _asso_values[i], i, _occurrences[i]);
fprintf (stderr, "end table dumping\n"); fprintf (stderr, "end table dumping\n");
} }
delete collision_detector; delete _collision_detector;
} }

View File

@@ -31,10 +31,10 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111, USA. */
class Gen_Perf : private Key_List class Gen_Perf : private Key_List
{ {
private: private:
int max_hash_value; /* Maximum possible hash value. */ int _max_hash_value; /* Maximum possible hash value. */
int fewest_collisions; /* Records fewest # of collisions for asso value. */ int _fewest_collisions; /* Records fewest # of collisions for asso value. */
int num_done; /* Number of keywords processed without a collision. */ int _num_done; /* Number of keywords processed without a collision. */
Bool_Array *collision_detector; Bool_Array *_collision_detector;
void change (KeywordExt *prior, KeywordExt *curr); void change (KeywordExt *prior, KeywordExt *curr);
int affects_prev (char c, KeywordExt *curr); int affects_prev (char c, KeywordExt *curr);

View File

@@ -35,9 +35,9 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111, USA. */
memory fragmentation, since we can now use alloca! */ memory fragmentation, since we can now use alloca! */
Hash_Table::Hash_Table (KeywordExt **table_ptr, int s, int ignore_len): Hash_Table::Hash_Table (KeywordExt **table_ptr, int s, int ignore_len):
table (table_ptr), size (s), collisions (0), ignore_length (ignore_len) _table (table_ptr), _size (s), _collisions (0), _ignore_length (ignore_len)
{ {
memset ((char *) table, 0, size * sizeof (*table)); memset ((char *) _table, 0, _size * sizeof (*_table));
} }
Hash_Table::~Hash_Table () Hash_Table::~Hash_Table ()
@@ -50,15 +50,15 @@ Hash_Table::~Hash_Table ()
"\ndumping the hash table\n" "\ndumping the hash table\n"
"total available table slots = %d, total bytes = %d, total collisions = %d\n" "total available table slots = %d, total bytes = %d, total collisions = %d\n"
"location, %*s, keyword\n", "location, %*s, keyword\n",
size, size * (int) sizeof (*table), collisions, _size, _size * (int) sizeof (*_table), _collisions,
field_width, "keysig"); field_width, "keysig");
for (int i = size - 1; i >= 0; i--) for (int i = _size - 1; i >= 0; i--)
if (table[i]) if (_table[i])
fprintf (stderr, "%8d, %*.*s, %.*s\n", fprintf (stderr, "%8d, %*.*s, %.*s\n",
i, i,
field_width, table[i]->selchars_length, table[i]->selchars, field_width, _table[i]->_selchars_length, _table[i]->_selchars,
table[i]->allchars_length, table[i]->allchars); _table[i]->_allchars_length, _table[i]->_allchars);
fprintf (stderr, "\nend dumping hash table\n\n"); fprintf (stderr, "\nend dumping hash table\n\n");
} }
@@ -71,21 +71,21 @@ Hash_Table::~Hash_Table ()
KeywordExt * KeywordExt *
Hash_Table::insert (KeywordExt *item) Hash_Table::insert (KeywordExt *item)
{ {
unsigned hash_val = hashpjw (item->selchars, item->selchars_length); unsigned hash_val = hashpjw (item->_selchars, item->_selchars_length);
int probe = hash_val & (size - 1); int probe = hash_val & (_size - 1);
int increment = ((hash_val ^ item->allchars_length) | 1) & (size - 1); int increment = ((hash_val ^ item->_allchars_length) | 1) & (_size - 1);
while (table[probe]) while (_table[probe])
{ {
if (table[probe]->selchars_length == item->selchars_length if (_table[probe]->_selchars_length == item->_selchars_length
&& memcmp (table[probe]->selchars, item->selchars, item->selchars_length) == 0 && memcmp (_table[probe]->_selchars, item->_selchars, item->_selchars_length) == 0
&& (ignore_length || table[probe]->allchars_length == item->allchars_length)) && (_ignore_length || _table[probe]->_allchars_length == item->_allchars_length))
return table[probe]; return _table[probe];
collisions++; _collisions++;
probe = (probe + increment) & (size - 1); probe = (probe + increment) & (_size - 1);
} }
table[probe] = item; _table[probe] = item;
return NULL; return NULL;
} }

View File

@@ -29,10 +29,10 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111, USA. */
class Hash_Table class Hash_Table
{ {
private: private:
KeywordExt **table; /* Vector of pointers to linked lists of keywords. */ KeywordExt **_table; /* Vector of pointers to linked lists of keywords. */
int size; /* Size of the vector. */ int _size; /* Size of the vector. */
int collisions; /* Find out how well our double hashing is working! */ int _collisions; /* Find out how well our double hashing is working! */
int ignore_length; int _ignore_length;
public: public:
Hash_Table (KeywordExt **t, int s, int ignore_len); Hash_Table (KeywordExt **t, int s, int ignore_len);

View File

@@ -33,7 +33,7 @@ static const int TABLE_MULTIPLE = 10;
/* Efficiently returns the least power of two greater than or equal to X! */ /* Efficiently returns the least power of two greater than or equal to X! */
#define POW(X) ((!X)?1:(X-=1,X|=X>>1,X|=X>>2,X|=X>>4,X|=X>>8,X|=X>>16,(++X))) #define POW(X) ((!X)?1:(X-=1,X|=X>>1,X|=X>>2,X|=X>>4,X|=X>>8,X|=X>>16,(++X)))
int Key_List::determined[MAX_ALPHA_SIZE]; int Key_List::_determined[MAX_ALPHA_SIZE];
/* Destructor dumps diagnostics during debugging. */ /* Destructor dumps diagnostics during debugging. */
@@ -43,7 +43,7 @@ Key_List::~Key_List ()
{ {
fprintf (stderr, "\nDumping key list information:\ntotal non-static linked keywords = %d" fprintf (stderr, "\nDumping key list information:\ntotal non-static linked keywords = %d"
"\ntotal keywords = %d\ntotal duplicates = %d\nmaximum key length = %d\n", "\ntotal keywords = %d\ntotal duplicates = %d\nmaximum key length = %d\n",
list_len, total_keys, total_duplicates, max_key_len); _list_len, _total_keys, _total_duplicates, _max_key_len);
dump (); dump ();
fprintf (stderr, "End dumping list.\n\n"); fprintf (stderr, "End dumping list.\n\n");
} }
@@ -171,32 +171,32 @@ Key_List::set_output_types ()
{ {
if (option[TYPE]) if (option[TYPE])
{ {
array_type = get_array_type (); _array_type = get_array_type ();
if (!array_type) if (!_array_type)
/* Something's wrong, but we'll catch it later on, in read_keys()... */ /* Something's wrong, but we'll catch it later on, in read_keys()... */
return; return;
/* Yow, we've got a user-defined type... */ /* Yow, we've got a user-defined type... */
int i = strcspn (array_type, "{\n\0"); int i = strcspn (_array_type, "{\n\0");
/* Remove trailing whitespace. */ /* Remove trailing whitespace. */
while (i > 0 && strchr (" \t", array_type[i-1])) while (i > 0 && strchr (" \t", _array_type[i-1]))
i--; i--;
int struct_tag_length = i; int struct_tag_length = i;
/* Set `struct_tag' to a naked "struct something". */ /* Set `struct_tag' to a naked "struct something". */
char *structtag = new char[struct_tag_length + 1]; char *structtag = new char[struct_tag_length + 1];
strncpy (structtag, array_type, struct_tag_length); strncpy (structtag, _array_type, struct_tag_length);
structtag[struct_tag_length] = '\0'; structtag[struct_tag_length] = '\0';
struct_tag = structtag; _struct_tag = structtag;
/* The return type of the lookup function is "struct something *". /* The return type of the lookup function is "struct something *".
No "const" here, because if !option[CONST], some user code might want No "const" here, because if !option[CONST], some user code might want
to modify the structure. */ to modify the structure. */
char *rettype = new char[struct_tag_length + 3]; char *rettype = new char[struct_tag_length + 3];
strncpy (rettype, array_type, struct_tag_length); strncpy (rettype, _array_type, struct_tag_length);
rettype[struct_tag_length] = ' '; rettype[struct_tag_length] = ' ';
rettype[struct_tag_length + 1] = '*'; rettype[struct_tag_length + 1] = '*';
rettype[struct_tag_length + 2] = '\0'; rettype[struct_tag_length + 2] = '\0';
return_type = rettype; _return_type = rettype;
} }
} }
@@ -348,7 +348,7 @@ Key_List::read_keys ()
{ {
char *ptr; char *ptr;
include_src = save_include_src (); _include_src = save_include_src ();
set_output_types (); set_output_types ();
/* Oops, problem with the input file. */ /* Oops, problem with the input file. */
@@ -365,24 +365,24 @@ Key_List::read_keys ()
KeywordExt_List *temp; KeywordExt_List *temp;
KeywordExt_List *trail = NULL; KeywordExt_List *trail = NULL;
head = parse_line (ptr, delimiter); _head = parse_line (ptr, delimiter);
head->first()->init_selchars(this); _head->first()->init_selchars(this);
for (temp = head; for (temp = _head;
(ptr = Read_Line::read_next_line ()) && strcmp (ptr, "%%"); (ptr = Read_Line::read_next_line ()) && strcmp (ptr, "%%");
temp = temp->rest()) temp = temp->rest())
{ {
temp->rest() = parse_line (ptr, delimiter); temp->rest() = parse_line (ptr, delimiter);
temp->rest()->first()->init_selchars(this); temp->rest()->first()->init_selchars(this);
total_keys++; _total_keys++;
} }
/* See if any additional C code is included at end of this file. */ /* See if any additional C code is included at end of this file. */
if (ptr) if (ptr)
additional_code = 1; _additional_code = 1;
/* Hash table this number of times larger than keyword number. */ /* Hash table this number of times larger than keyword number. */
int table_size = (list_len = total_keys) * TABLE_MULTIPLE; int table_size = (_list_len = _total_keys) * TABLE_MULTIPLE;
/* Table must be a power of 2 for the hash function scheme to work. */ /* Table must be a power of 2 for the hash function scheme to work. */
KeywordExt **table = new KeywordExt*[POW (table_size)]; KeywordExt **table = new KeywordExt*[POW (table_size)];
@@ -392,7 +392,7 @@ Key_List::read_keys ()
/* Test whether there are any links and also set the maximum length of /* Test whether there are any links and also set the maximum length of
an identifier in the keyword list. */ an identifier in the keyword list. */
for (temp = head; temp; temp = temp->rest()) for (temp = _head; temp; temp = temp->rest())
{ {
KeywordExt *keyword = temp->first(); KeywordExt *keyword = temp->first();
KeywordExt *other_keyword = found_link.insert (keyword); KeywordExt *other_keyword = found_link.insert (keyword);
@@ -404,53 +404,53 @@ Key_List::read_keys ()
if (other_keyword) if (other_keyword)
{ {
total_duplicates++; _total_duplicates++;
list_len--; _list_len--;
trail->rest() = temp->rest(); trail->rest() = temp->rest();
temp->first()->duplicate_link = other_keyword->duplicate_link; temp->first()->_duplicate_link = other_keyword->_duplicate_link;
other_keyword->duplicate_link = temp->first(); other_keyword->_duplicate_link = temp->first();
/* Complain if user hasn't enabled the duplicate option. */ /* Complain if user hasn't enabled the duplicate option. */
if (!option[DUP] || option[DEBUG]) if (!option[DUP] || option[DEBUG])
fprintf (stderr, "Key link: \"%.*s\" = \"%.*s\", with key set \"%.*s\".\n", fprintf (stderr, "Key link: \"%.*s\" = \"%.*s\", with key set \"%.*s\".\n",
keyword->allchars_length, keyword->allchars, keyword->_allchars_length, keyword->_allchars,
other_keyword->allchars_length, other_keyword->allchars, other_keyword->_allchars_length, other_keyword->_allchars,
keyword->selchars_length, keyword->selchars); keyword->_selchars_length, keyword->_selchars);
} }
else else
trail = temp; trail = temp;
/* Update minimum and maximum keyword length, if needed. */ /* Update minimum and maximum keyword length, if needed. */
if (max_key_len < keyword->allchars_length) if (_max_key_len < keyword->_allchars_length)
max_key_len = keyword->allchars_length; _max_key_len = keyword->_allchars_length;
if (min_key_len > keyword->allchars_length) if (_min_key_len > keyword->_allchars_length)
min_key_len = keyword->allchars_length; _min_key_len = keyword->_allchars_length;
} }
delete[] table; delete[] table;
/* Exit program if links exists and option[DUP] not set, since we can't continue */ /* Exit program if links exists and option[DUP] not set, since we can't continue */
if (total_duplicates) if (_total_duplicates)
{ {
if (option[DUP]) if (option[DUP])
fprintf (stderr, "%d input keys have identical hash values, examine output carefully...\n", fprintf (stderr, "%d input keys have identical hash values, examine output carefully...\n",
total_duplicates); _total_duplicates);
else else
{ {
fprintf (stderr, "%d input keys have identical hash values,\ntry different key positions or use option -D.\n", fprintf (stderr, "%d input keys have identical hash values,\ntry different key positions or use option -D.\n",
total_duplicates); _total_duplicates);
exit (1); exit (1);
} }
} }
/* Exit program if an empty string is used as key, since the comparison /* Exit program if an empty string is used as key, since the comparison
expressions don't work correctly for looking up an empty string. */ expressions don't work correctly for looking up an empty string. */
if (min_key_len == 0) if (_min_key_len == 0)
{ {
fprintf (stderr, "Empty input key is not allowed.\nTo recognize an empty input key, your code should check for\nlen == 0 before calling the gperf generated lookup function.\n"); fprintf (stderr, "Empty input key is not allowed.\nTo recognize an empty input key, your code should check for\nlen == 0 before calling the gperf generated lookup function.\n");
exit (1); exit (1);
} }
if (option[ALLCHARS]) if (option[ALLCHARS])
option.set_keysig_size (max_key_len); option.set_keysig_size (_max_key_len);
} }
} }
@@ -477,8 +477,8 @@ Key_List::merge (KeywordExt_List *list1, KeywordExt_List *list2)
*resultp = list1; *resultp = list1;
break; break;
} }
if (occurrence_sort && list1->first()->occurrence < list2->first()->occurrence if (_occurrence_sort && list1->first()->_occurrence < list2->first()->_occurrence
|| hash_sort && list1->first()->hash_value > list2->first()->hash_value) || _hash_sort && list1->first()->_hash_value > list2->first()->_hash_value)
{ {
*resultp = list2; *resultp = list2;
resultp = &list2->rest(); list2 = list1; list1 = *resultp; resultp = &list2->rest(); list2 = list1; list1 = *resultp;
@@ -526,10 +526,10 @@ Key_List::get_occurrence (KeywordExt *ptr)
{ {
int value = 0; int value = 0;
const char *p = ptr->selchars; const char *p = ptr->_selchars;
unsigned int i = ptr->selchars_length; unsigned int i = ptr->_selchars_length;
for (; i > 0; p++, i--) for (; i > 0; p++, i--)
value += occurrences[(unsigned char)(*p)]; value += _occurrences[(unsigned char)(*p)];
return value; return value;
} }
@@ -540,10 +540,10 @@ Key_List::get_occurrence (KeywordExt *ptr)
inline void inline void
Key_List::set_determined (KeywordExt *ptr) Key_List::set_determined (KeywordExt *ptr)
{ {
const char *p = ptr->selchars; const char *p = ptr->_selchars;
unsigned int i = ptr->selchars_length; unsigned int i = ptr->_selchars_length;
for (; i > 0; p++, i--) for (; i > 0; p++, i--)
determined[(unsigned char)(*p)] = 1; _determined[(unsigned char)(*p)] = 1;
} }
/* Returns TRUE if PTR's key set is already completely determined. */ /* Returns TRUE if PTR's key set is already completely determined. */
@@ -553,10 +553,10 @@ Key_List::already_determined (KeywordExt *ptr)
{ {
int is_determined = 1; int is_determined = 1;
const char *p = ptr->selchars; const char *p = ptr->_selchars;
unsigned int i = ptr->selchars_length; unsigned int i = ptr->_selchars_length;
for (; is_determined && i > 0; p++, i--) for (; is_determined && i > 0; p++, i--)
is_determined = determined[(unsigned char)(*p)]; is_determined = _determined[(unsigned char)(*p)];
return is_determined; return is_determined;
} }
@@ -571,19 +571,19 @@ void
Key_List::reorder () Key_List::reorder ()
{ {
KeywordExt_List *ptr; KeywordExt_List *ptr;
for (ptr = head; ptr; ptr = ptr->rest()) for (ptr = _head; ptr; ptr = ptr->rest())
{ {
KeywordExt *keyword = ptr->first(); KeywordExt *keyword = ptr->first();
keyword->occurrence = get_occurrence (keyword); keyword->_occurrence = get_occurrence (keyword);
} }
hash_sort = 0; _hash_sort = 0;
occurrence_sort = 1; _occurrence_sort = 1;
head = merge_sort (head); _head = merge_sort (_head);
for (ptr = head; ptr->rest(); ptr = ptr->rest()) for (ptr = _head; ptr->rest(); ptr = ptr->rest())
{ {
set_determined (ptr->first()); set_determined (ptr->first());
@@ -613,10 +613,10 @@ Key_List::reorder ()
void void
Key_List::sort () Key_List::sort ()
{ {
hash_sort = 1; _hash_sort = 1;
occurrence_sort = 0; _occurrence_sort = 0;
head = merge_sort (head); _head = merge_sort (_head);
} }
/* Dumps the key list to stderr stream. */ /* Dumps the key list to stderr stream. */
@@ -629,26 +629,26 @@ Key_List::dump ()
fprintf (stderr, "\nList contents are:\n(hash value, key length, index, %*s, keyword):\n", fprintf (stderr, "\nList contents are:\n(hash value, key length, index, %*s, keyword):\n",
field_width, "selchars"); field_width, "selchars");
for (KeywordExt_List *ptr = head; ptr; ptr = ptr->rest()) for (KeywordExt_List *ptr = _head; ptr; ptr = ptr->rest())
fprintf (stderr, "%11d,%11d,%6d, %*.*s, %.*s\n", fprintf (stderr, "%11d,%11d,%6d, %*.*s, %.*s\n",
ptr->first()->hash_value, ptr->first()->allchars_length, ptr->first()->final_index, ptr->first()->_hash_value, ptr->first()->_allchars_length, ptr->first()->_final_index,
field_width, ptr->first()->selchars_length, ptr->first()->selchars, field_width, ptr->first()->_selchars_length, ptr->first()->_selchars,
ptr->first()->allchars_length, ptr->first()->allchars); ptr->first()->_allchars_length, ptr->first()->_allchars);
} }
/* Simple-minded constructor action here... */ /* Simple-minded constructor action here... */
Key_List::Key_List () Key_List::Key_List ()
{ {
total_keys = 1; _total_keys = 1;
max_key_len = INT_MIN; _max_key_len = INT_MIN;
min_key_len = INT_MAX; _min_key_len = INT_MAX;
array_type = 0; _array_type = 0;
return_type = 0; _return_type = 0;
struct_tag = 0; _struct_tag = 0;
head = 0; _head = 0;
total_duplicates = 0; _total_duplicates = 0;
additional_code = 0; _additional_code = 0;
} }
/* Returns the length of entire key list. */ /* Returns the length of entire key list. */
@@ -656,7 +656,7 @@ Key_List::Key_List ()
int int
Key_List::keyword_list_length () Key_List::keyword_list_length ()
{ {
return list_len; return _list_len;
} }
/* Returns length of longest key read. */ /* Returns length of longest key read. */
@@ -664,6 +664,6 @@ Key_List::keyword_list_length ()
int int
Key_List::max_key_length () Key_List::max_key_length ()
{ {
return max_key_len; return _max_key_len;
} }

View File

@@ -36,23 +36,23 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111, USA. */
class Key_List : private Read_Line, public Vectors class Key_List : private Read_Line, public Vectors
{ {
protected: protected:
const char *array_type; /* Pointer to the type for word list. */ const char *_array_type; /* Pointer to the type for word list. */
const char *return_type; /* Pointer to return type for lookup function. */ const char *_return_type; /* Pointer to return type for lookup function. */
const char *struct_tag; /* Shorthand for user-defined struct tag type. */ const char *_struct_tag; /* Shorthand for user-defined struct tag type. */
const char *include_src; /* C source code to be included verbatim. */ const char *_include_src; /* C source code to be included verbatim. */
int max_key_len; /* Maximum length of the longest keyword. */ int _max_key_len; /* Maximum length of the longest keyword. */
int min_key_len; /* Minimum length of the shortest keyword. */ int _min_key_len; /* Minimum length of the shortest keyword. */
private: private:
int occurrence_sort; /* True if sorting by occurrence. */ int _occurrence_sort; /* True if sorting by occurrence. */
int hash_sort; /* True if sorting by hash value. */ int _hash_sort; /* True if sorting by hash value. */
protected: protected:
int additional_code; /* True if any additional C code is included. */ int _additional_code; /* True if any additional C code is included. */
private: private:
int list_len; /* Length of head's Key_List, not counting duplicates. */ int _list_len; /* Length of head's Key_List, not counting duplicates. */
protected: protected:
int total_keys; /* Total number of keys, counting duplicates. */ int _total_keys; /* Total number of keys, counting duplicates. */
private: private:
static int determined[MAX_ALPHA_SIZE]; /* Used in function reorder, below. */ static int _determined[MAX_ALPHA_SIZE]; /* Used in function reorder, below. */
static int get_occurrence (KeywordExt *ptr); static int get_occurrence (KeywordExt *ptr);
#ifndef strcspn #ifndef strcspn
static int strcspn (const char *s, const char *reject); static int strcspn (const char *s, const char *reject);
@@ -68,8 +68,8 @@ private:
KeywordExt_List *merge_sort (KeywordExt_List *head); KeywordExt_List *merge_sort (KeywordExt_List *head);
protected: protected:
KeywordExt_List *head; /* Points to the head of the linked list. */ KeywordExt_List *_head; /* Points to the head of the linked list. */
int total_duplicates; /* Total number of duplicate hash values. */ int _total_duplicates; /* Total number of duplicate hash values. */
public: public:
Key_List (); Key_List ();

View File

@@ -24,6 +24,6 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111, USA. */
/* Constructor. */ /* Constructor. */
KeywordExt_List::KeywordExt_List (const char *s, int s_len, const char *r) KeywordExt_List::KeywordExt_List (const char *s, int s_len, const char *r)
: KeywordExt (s, s_len, r), cdr (NULL) : KeywordExt (s, s_len, r), _cdr (NULL)
{ {
} }

View File

@@ -35,10 +35,10 @@ public:
/* Access to first element of list. */ /* Access to first element of list. */
KeywordExt* first () { return this; } KeywordExt* first () { return this; }
/* Access to next element of list. */ /* Access to next element of list. */
KeywordExt_List *& rest () { return cdr; } KeywordExt_List *& rest () { return _cdr; }
private: private:
KeywordExt_List * cdr; KeywordExt_List * _cdr;
}; };
#endif #endif

View File

@@ -29,7 +29,7 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111, USA. */
/* Constructor. */ /* Constructor. */
Keyword::Keyword (const char *s, int s_len, const char *r) Keyword::Keyword (const char *s, int s_len, const char *r)
: allchars (s), allchars_length (s_len), rest (r) : _allchars (s), _allchars_length (s_len), _rest (r)
{ {
} }
@@ -38,7 +38,7 @@ Keyword::Keyword (const char *s, int s_len, const char *r)
/* Constructor. */ /* Constructor. */
KeywordExt::KeywordExt (const char *s, int s_len, const char *r) KeywordExt::KeywordExt (const char *s, int s_len, const char *r)
: Keyword (s, s_len, r), duplicate_link (NULL), final_index (0) : Keyword (s, s_len, r), _duplicate_link (NULL), _final_index (0)
{ {
} }
@@ -61,16 +61,16 @@ static inline void sort_char_set (char *base, int len)
/* Initialize selchars and selchars_length, and update v->occurrences. */ /* Initialize selchars and selchars_length, and update v->occurrences. */
void KeywordExt::init_selchars (Vectors *v) void KeywordExt::init_selchars (Vectors *v)
{ {
const char *k = allchars; const char *k = _allchars;
char *key_set = char *key_set =
new char[(option[ALLCHARS] ? allchars_length : option.get_max_keysig_size ())]; new char[(option[ALLCHARS] ? _allchars_length : option.get_max_keysig_size ())];
char *ptr = key_set; char *ptr = key_set;
int i; int i;
if (option[ALLCHARS]) if (option[ALLCHARS])
/* Use all the character positions in the KEY. */ /* Use all the character positions in the KEY. */
for (i = allchars_length; i > 0; k++, ptr++, i--) for (i = _allchars_length; i > 0; k++, ptr++, i--)
v->occurrences[(unsigned char)(*ptr = *k)]++; v->_occurrences[(unsigned char)(*ptr = *k)]++;
else else
/* Only use those character positions specified by the user. */ /* Only use those character positions specified by the user. */
{ {
@@ -81,23 +81,23 @@ void KeywordExt::init_selchars (Vectors *v)
{ {
if (i == WORD_END) if (i == WORD_END)
/* Special notation for last KEY position, i.e. '$'. */ /* Special notation for last KEY position, i.e. '$'. */
*ptr = allchars[allchars_length - 1]; *ptr = _allchars[_allchars_length - 1];
else if (i <= allchars_length) else if (i <= _allchars_length)
/* Within range of KEY length, so we'll keep it. */ /* Within range of KEY length, so we'll keep it. */
*ptr = allchars[i - 1]; *ptr = _allchars[i - 1];
else else
/* Out of range of KEY length, so we'll just skip it. */ /* Out of range of KEY length, so we'll just skip it. */
continue; continue;
v->occurrences[(unsigned char)*ptr]++; v->_occurrences[(unsigned char)*ptr]++;
ptr++; ptr++;
} }
/* Didn't get any hits and user doesn't want to consider the /* Didn't get any hits and user doesn't want to consider the
keylength, so there are essentially no usable hash positions! */ keylength, so there are essentially no usable hash positions! */
if (ptr == selchars && option[NOLENGTH]) if (ptr == _selchars && option[NOLENGTH])
{ {
fprintf (stderr, "Can't hash keyword %.*s with chosen key positions.\n", fprintf (stderr, "Can't hash keyword %.*s with chosen key positions.\n",
allchars_length, allchars); _allchars_length, _allchars);
exit (1); exit (1);
} }
} }
@@ -105,8 +105,8 @@ void KeywordExt::init_selchars (Vectors *v)
/* Sort the KEY_SET items alphabetically. */ /* Sort the KEY_SET items alphabetically. */
sort_char_set (key_set, ptr - key_set); sort_char_set (key_set, ptr - key_set);
selchars = key_set; _selchars = key_set;
selchars_length = ptr - key_set; _selchars_length = ptr - key_set;
} }

View File

@@ -34,10 +34,10 @@ struct Keyword
/* Data members defined immediately by the input file. */ /* Data members defined immediately by the input file. */
/* The keyword as a string, possibly containing NUL bytes. */ /* The keyword as a string, possibly containing NUL bytes. */
const char *const allchars; const char *const _allchars;
const int allchars_length; const int _allchars_length;
/* Additional stuff seen on the same line of the input file. */ /* Additional stuff seen on the same line of the input file. */
const char *const rest; const char *const _rest;
}; };
/* A keyword, in the context of a given keyposition list. */ /* A keyword, in the context of a given keyposition list. */
@@ -49,21 +49,21 @@ struct KeywordExt : public Keyword
/* Data members depending on the keyposition list. */ /* Data members depending on the keyposition list. */
/* The selected characters that participate for the hash function, /* The selected characters that participate for the hash function,
reordered according to the keyposition list. */ reordered according to the keyposition list. */
const char * selchars; const char * _selchars;
int selchars_length; int _selchars_length;
/* Chained list of keywords having the same selchars. */ /* Chained list of keywords having the same selchars. */
KeywordExt * duplicate_link; KeywordExt * _duplicate_link;
/* Methods depending on the keyposition list. */ /* Methods depending on the keyposition list. */
/* Initialize selchars and selchars_length, and update v->occurrences. */ /* Initialize selchars and selchars_length, and update v->occurrences. */
void init_selchars (Vectors *v); void init_selchars (Vectors *v);
/* Data members used by the algorithm. */ /* Data members used by the algorithm. */
int occurrence; /* A metric for frequency of key set occurrences. */ int _occurrence; /* A metric for frequency of key set occurrences. */
int hash_value; /* Hash value for the key. */ int _hash_value; /* Hash value for the key. */
/* Data members used by the output routines. */ /* Data members used by the output routines. */
int final_index; int _final_index;
}; };
/* A factory for creating Keyword instances. */ /* A factory for creating Keyword instances. */

View File

@@ -57,24 +57,24 @@ static const char *const DEFAULT_WORDLIST_NAME = "wordlist";
/* Default delimiters that separate keywords from their attributes. */ /* Default delimiters that separate keywords from their attributes. */
static const char *const DEFAULT_DELIMITERS = ",\n"; static const char *const DEFAULT_DELIMITERS = ",\n";
int Options::option_word; int Options::_option_word;
int Options::total_switches; int Options::_total_switches;
int Options::total_keysig_size; int Options::_total_keysig_size;
int Options::size; int Options::_size;
int Options::key_pos; int Options::_key_pos;
int Options::jump; int Options::_jump;
int Options::initial_asso_value; int Options::_initial_asso_value;
int Options::argument_count; int Options::_argument_count;
int Options::iterations; int Options::_iterations;
char **Options::argument_vector; char **Options::_argument_vector;
const char *Options::function_name; const char *Options::_function_name;
const char *Options::key_name; const char *Options::_key_name;
const char *Options::initializer_suffix; const char *Options::_initializer_suffix;
const char *Options::class_name; const char *Options::_class_name;
const char *Options::hash_name; const char *Options::_hash_name;
const char *Options::wordlist_name; const char *Options::_wordlist_name;
const char *Options::delimiters; const char *Options::_delimiters;
char Options::key_positions[MAX_KEY_POS]; char Options::_key_positions[MAX_KEY_POS];
/* Prints program usage to given stream. */ /* Prints program usage to given stream. */
@@ -224,9 +224,9 @@ Options::print_options ()
printf ("/* Command-line: "); printf ("/* Command-line: ");
for (i = 0; i < argument_count; i++) for (i = 0; i < _argument_count; i++)
{ {
const char *arg = argument_vector[i]; const char *arg = _argument_vector[i];
/* Escape arg if it contains shell metacharacters. */ /* Escape arg if it contains shell metacharacters. */
if (*arg == '-') if (*arg == '-')
@@ -365,28 +365,30 @@ Options::key_sort (char *base, int len)
Options::Options () Options::Options ()
{ {
key_positions[0] = WORD_START; _key_positions[0] = WORD_START;
key_positions[1] = WORD_END; _key_positions[1] = WORD_END;
key_positions[2] = EOS; _key_positions[2] = EOS;
total_keysig_size = 2; _total_keysig_size = 2;
delimiters = DEFAULT_DELIMITERS; _delimiters = DEFAULT_DELIMITERS;
jump = DEFAULT_JUMP_VALUE; _jump = DEFAULT_JUMP_VALUE;
option_word = DEFAULTCHARS | C; _option_word = DEFAULTCHARS | C;
function_name = DEFAULT_NAME; _function_name = DEFAULT_NAME;
key_name = DEFAULT_KEY; _key_name = DEFAULT_KEY;
initializer_suffix = DEFAULT_INITIALIZER_SUFFIX; _initializer_suffix = DEFAULT_INITIALIZER_SUFFIX;
hash_name = DEFAULT_HASH_NAME; _hash_name = DEFAULT_HASH_NAME;
wordlist_name = DEFAULT_WORDLIST_NAME; _wordlist_name = DEFAULT_WORDLIST_NAME;
class_name = DEFAULT_CLASS_NAME; _class_name = DEFAULT_CLASS_NAME;
total_switches = size = 1; _size = 1;
initial_asso_value = iterations = 0; _total_switches = 1;
_iterations = 0;
_initial_asso_value = 0;
} }
/* Dumps option status when debug is set. */ /* Dumps option status when debug is set. */
Options::~Options () Options::~Options ()
{ {
if (option_word & DEBUG) if (_option_word & DEBUG)
{ {
char *ptr; char *ptr;
@@ -423,38 +425,38 @@ Options::~Options ()
"\ninitial associated value = %d" "\ninitial associated value = %d"
"\ndelimiters = %s" "\ndelimiters = %s"
"\nnumber of switch statements = %d\n", "\nnumber of switch statements = %d\n",
option_word & DEBUG ? "enabled" : "disabled", _option_word & DEBUG ? "enabled" : "disabled",
option_word & ORDER ? "enabled" : "disabled", _option_word & ORDER ? "enabled" : "disabled",
option_word & TYPE ? "enabled" : "disabled", _option_word & TYPE ? "enabled" : "disabled",
option_word & RANDOM ? "enabled" : "disabled", _option_word & RANDOM ? "enabled" : "disabled",
option_word & DEFAULTCHARS ? "enabled" : "disabled", _option_word & DEFAULTCHARS ? "enabled" : "disabled",
option_word & SWITCH ? "enabled" : "disabled", _option_word & SWITCH ? "enabled" : "disabled",
option_word & NOLENGTH ? "enabled" : "disabled", _option_word & NOLENGTH ? "enabled" : "disabled",
option_word & LENTABLE ? "enabled" : "disabled", _option_word & LENTABLE ? "enabled" : "disabled",
option_word & DUP ? "enabled" : "disabled", _option_word & DUP ? "enabled" : "disabled",
option_word & FAST ? "enabled" : "disabled", _option_word & FAST ? "enabled" : "disabled",
option_word & COMP ? "enabled" : "disabled", _option_word & COMP ? "enabled" : "disabled",
option_word & NOTYPE ? "enabled" : "disabled", _option_word & NOTYPE ? "enabled" : "disabled",
option_word & GLOBAL ? "enabled" : "disabled", _option_word & GLOBAL ? "enabled" : "disabled",
option_word & CONST ? "enabled" : "disabled", _option_word & CONST ? "enabled" : "disabled",
option_word & KRC ? "enabled" : "disabled", _option_word & KRC ? "enabled" : "disabled",
option_word & C ? "enabled" : "disabled", _option_word & C ? "enabled" : "disabled",
option_word & ANSIC ? "enabled" : "disabled", _option_word & ANSIC ? "enabled" : "disabled",
option_word & CPLUSPLUS ? "enabled" : "disabled", _option_word & CPLUSPLUS ? "enabled" : "disabled",
option_word & ENUM ? "enabled" : "disabled", _option_word & ENUM ? "enabled" : "disabled",
option_word & INCLUDE ? "enabled" : "disabled", _option_word & INCLUDE ? "enabled" : "disabled",
option_word & SEVENBIT ? "enabled" : "disabled", _option_word & SEVENBIT ? "enabled" : "disabled",
iterations, _iterations,
function_name, hash_name, wordlist_name, key_name, _function_name, _hash_name, _wordlist_name, _key_name,
initializer_suffix, jump, size - 1, initial_asso_value, _initializer_suffix, _jump, _size - 1, _initial_asso_value,
delimiters, total_switches); _delimiters, _total_switches);
if (option_word & ALLCHARS) if (_option_word & ALLCHARS)
fprintf (stderr, "all characters are used in the hash function\n"); fprintf (stderr, "all characters are used in the hash function\n");
fprintf (stderr, "maximum keysig size = %d\nkey positions are: \n", fprintf (stderr, "maximum keysig size = %d\nkey positions are: \n",
total_keysig_size); _total_keysig_size);
for (ptr = key_positions; *ptr != EOS; ptr++) for (ptr = _key_positions; *ptr != EOS; ptr++)
if (*ptr == WORD_END) if (*ptr == WORD_END)
fprintf (stderr, "$\n"); fprintf (stderr, "$\n");
else else
@@ -508,11 +510,11 @@ Options::operator() (int argc, char *argv[])
int option_char; int option_char;
program_name = argv[0]; program_name = argv[0];
argument_count = argc; _argument_count = argc;
argument_vector = argv; _argument_vector = argv;
while ((option_char = while ((option_char =
getopt_long (argument_count, argument_vector, getopt_long (_argument_count, _argument_vector,
"adcCDe:Ef:F:gGhH:i:Ij:k:K:lL:nN:oprs:S:tTvW:Z:7", "adcCDe:Ef:F:gGhH:i:Ij:k:K:lL:nN:oprs:S:tTvW:Z:7",
long_options, NULL)) long_options, NULL))
!= -1) != -1)
@@ -523,56 +525,56 @@ Options::operator() (int argc, char *argv[])
break; /* This is now the default. */ break; /* This is now the default. */
case 'c': /* Generate strncmp rather than strcmp. */ case 'c': /* Generate strncmp rather than strcmp. */
{ {
option_word |= COMP; _option_word |= COMP;
break; break;
} }
case 'C': /* Make the generated tables readonly (const). */ case 'C': /* Make the generated tables readonly (const). */
{ {
option_word |= CONST; _option_word |= CONST;
break; break;
} }
case 'd': /* Enable debugging option. */ case 'd': /* Enable debugging option. */
{ {
option_word |= DEBUG; _option_word |= DEBUG;
fprintf (stderr, "Starting program %s, version %s, with debugging on.\n", fprintf (stderr, "Starting program %s, version %s, with debugging on.\n",
program_name, version_string); program_name, version_string);
break; break;
} }
case 'D': /* Enable duplicate option. */ case 'D': /* Enable duplicate option. */
{ {
option_word |= DUP; _option_word |= DUP;
break; break;
} }
case 'e': /* Allows user to provide keyword/attribute separator */ case 'e': /* Allows user to provide keyword/attribute separator */
{ {
option.delimiters = /*getopt*/optarg; _delimiters = /*getopt*/optarg;
break; break;
} }
case 'E': case 'E':
{ {
option_word |= ENUM; _option_word |= ENUM;
break; break;
} }
case 'f': /* Generate the hash table ``fast.'' */ case 'f': /* Generate the hash table ``fast.'' */
{ {
option_word |= FAST; _option_word |= FAST;
if ((iterations = atoi (/*getopt*/optarg)) < 0) if ((_iterations = atoi (/*getopt*/optarg)) < 0)
{ {
fprintf (stderr, "iterations value must not be negative, assuming 0\n"); fprintf (stderr, "iterations value must not be negative, assuming 0\n");
iterations = 0; _iterations = 0;
} }
break; break;
} }
case 'F': case 'F':
{ {
initializer_suffix = /*getopt*/optarg; _initializer_suffix = /*getopt*/optarg;
break; break;
} }
case 'g': /* Use the ``inline'' keyword for generated sub-routines, ifdef __GNUC__. */ case 'g': /* Use the ``inline'' keyword for generated sub-routines, ifdef __GNUC__. */
break; /* This is now the default. */ break; /* This is now the default. */
case 'G': /* Make the keyword table a global variable. */ case 'G': /* Make the keyword table a global variable. */
{ {
option_word |= GLOBAL; _option_word |= GLOBAL;
break; break;
} }
case 'h': /* Displays a list of helpful Options to the user. */ case 'h': /* Displays a list of helpful Options to the user. */
@@ -582,32 +584,32 @@ Options::operator() (int argc, char *argv[])
} }
case 'H': /* Sets the name for the hash function */ case 'H': /* Sets the name for the hash function */
{ {
hash_name = /*getopt*/optarg; _hash_name = /*getopt*/optarg;
break; break;
} }
case 'i': /* Sets the initial value for the associated values array. */ case 'i': /* Sets the initial value for the associated values array. */
{ {
if ((initial_asso_value = atoi (/*getopt*/optarg)) < 0) if ((_initial_asso_value = atoi (/*getopt*/optarg)) < 0)
fprintf (stderr, "Initial value %d should be non-zero, ignoring and continuing.\n", initial_asso_value); fprintf (stderr, "Initial value %d should be non-zero, ignoring and continuing.\n", _initial_asso_value);
if (option[RANDOM]) if (option[RANDOM])
fprintf (stderr, "warning, -r option superceeds -i, ignoring -i option and continuing\n"); fprintf (stderr, "warning, -r option superceeds -i, ignoring -i option and continuing\n");
break; break;
} }
case 'I': /* Enable #include statements. */ case 'I': /* Enable #include statements. */
{ {
option_word |= INCLUDE; _option_word |= INCLUDE;
break; break;
} }
case 'j': /* Sets the jump value, must be odd for later algorithms. */ case 'j': /* Sets the jump value, must be odd for later algorithms. */
{ {
if ((jump = atoi (/*getopt*/optarg)) < 0) if ((_jump = atoi (/*getopt*/optarg)) < 0)
{ {
fprintf (stderr, "Jump value %d must be a positive number.\n", jump); fprintf (stderr, "Jump value %d must be a positive number.\n", _jump);
short_usage (stderr); short_usage (stderr);
exit (1); exit (1);
} }
else if (jump && ((jump % 2) == 0)) else if (_jump && ((_jump % 2) == 0))
fprintf (stderr, "Jump value %d should be odd, adding 1 and continuing...\n", jump++); fprintf (stderr, "Jump value %d should be odd, adding 1 and continuing...\n", _jump++);
break; break;
} }
case 'k': /* Sets key positions used for hash function. */ case 'k': /* Sets key positions used for hash function. */
@@ -617,12 +619,12 @@ Options::operator() (int argc, char *argv[])
PositionStringParser sparser (/*getopt*/optarg, 1, MAX_KEY_POS - 1, WORD_END, BAD_VALUE, EOS); PositionStringParser sparser (/*getopt*/optarg, 1, MAX_KEY_POS - 1, WORD_END, BAD_VALUE, EOS);
if (/*getopt*/optarg [0] == '*') /* Use all the characters for hashing!!!! */ if (/*getopt*/optarg [0] == '*') /* Use all the characters for hashing!!!! */
option_word = (option_word & ~DEFAULTCHARS) | ALLCHARS; _option_word = (_option_word & ~DEFAULTCHARS) | ALLCHARS;
else else
{ {
char *key_pos; char *key_pos;
for (key_pos = key_positions; (value = sparser.nextPosition()) != EOS; key_pos++) for (key_pos = _key_positions; (value = sparser.nextPosition()) != EOS; key_pos++)
if (value == BAD_VALUE) if (value == BAD_VALUE)
{ {
fprintf (stderr, "Illegal key value or range, use 1,2,3-%d,'$' or '*'.\n", fprintf (stderr, "Illegal key value or range, use 1,2,3-%d,'$' or '*'.\n",
@@ -635,87 +637,87 @@ Options::operator() (int argc, char *argv[])
*key_pos = EOS; *key_pos = EOS;
if (! (total_keysig_size = (key_pos - key_positions))) if (! (_total_keysig_size = (key_pos - _key_positions)))
{ {
fprintf (stderr, "No keys selected.\n"); fprintf (stderr, "No keys selected.\n");
short_usage (stderr); short_usage (stderr);
exit (1); exit (1);
} }
else if (! key_sort (key_positions, total_keysig_size)) else if (! key_sort (_key_positions, _total_keysig_size))
{ {
fprintf (stderr, "Duplicate keys selected\n"); fprintf (stderr, "Duplicate keys selected\n");
short_usage (stderr); short_usage (stderr);
exit (1); exit (1);
} }
if (total_keysig_size != 2 if (_total_keysig_size != 2
|| (key_positions[0] != 1 || key_positions[1] != WORD_END)) || (_key_positions[0] != 1 || _key_positions[1] != WORD_END))
option_word &= ~DEFAULTCHARS; _option_word &= ~DEFAULTCHARS;
} }
break; break;
} }
case 'K': /* Make this the keyname for the keyword component field. */ case 'K': /* Make this the keyname for the keyword component field. */
{ {
key_name = /*getopt*/optarg; _key_name = /*getopt*/optarg;
break; break;
} }
case 'l': /* Create length table to avoid extra string compares. */ case 'l': /* Create length table to avoid extra string compares. */
{ {
option_word |= LENTABLE; _option_word |= LENTABLE;
break; break;
} }
case 'L': /* Deal with different generated languages. */ case 'L': /* Deal with different generated languages. */
{ {
option_word &= ~(KRC | C | ANSIC | CPLUSPLUS); _option_word &= ~(KRC | C | ANSIC | CPLUSPLUS);
if (!strcmp (/*getopt*/optarg, "KR-C")) if (!strcmp (/*getopt*/optarg, "KR-C"))
option_word |= KRC; _option_word |= KRC;
else if (!strcmp (/*getopt*/optarg, "C")) else if (!strcmp (/*getopt*/optarg, "C"))
option_word |= C; _option_word |= C;
else if (!strcmp (/*getopt*/optarg, "ANSI-C")) else if (!strcmp (/*getopt*/optarg, "ANSI-C"))
option_word |= ANSIC; _option_word |= ANSIC;
else if (!strcmp (/*getopt*/optarg, "C++")) else if (!strcmp (/*getopt*/optarg, "C++"))
option_word |= CPLUSPLUS; _option_word |= CPLUSPLUS;
else else
{ {
fprintf (stderr, "unsupported language option %s, defaulting to C\n", /*getopt*/optarg); fprintf (stderr, "unsupported language option %s, defaulting to C\n", /*getopt*/optarg);
option_word |= C; _option_word |= C;
} }
break; break;
} }
case 'n': /* Don't include the length when computing hash function. */ case 'n': /* Don't include the length when computing hash function. */
{ {
option_word |= NOLENGTH; _option_word |= NOLENGTH;
break; break;
} }
case 'N': /* Make generated lookup function name be optarg */ case 'N': /* Make generated lookup function name be optarg */
{ {
function_name = /*getopt*/optarg; _function_name = /*getopt*/optarg;
break; break;
} }
case 'o': /* Order input by frequency of key set occurrence. */ case 'o': /* Order input by frequency of key set occurrence. */
{ {
option_word |= ORDER; _option_word |= ORDER;
break; break;
} }
case 'p': /* Generated lookup function a pointer instead of int. */ case 'p': /* Generated lookup function a pointer instead of int. */
break; /* This is now the default. */ break; /* This is now the default. */
case 'r': /* Utilize randomness to initialize the associated values table. */ case 'r': /* Utilize randomness to initialize the associated values table. */
{ {
option_word |= RANDOM; _option_word |= RANDOM;
if (option.initial_asso_value != 0) if (_initial_asso_value != 0)
fprintf (stderr, "warning, -r option superceeds -i, disabling -i option and continuing\n"); fprintf (stderr, "warning, -r option superceeds -i, disabling -i option and continuing\n");
break; break;
} }
case 's': /* Range of associated values, determines size of final table. */ case 's': /* Range of associated values, determines size of final table. */
{ {
if (abs (size = atoi (/*getopt*/optarg)) > 50) if (abs (_size = atoi (/*getopt*/optarg)) > 50)
fprintf (stderr, "%d is excessive, did you really mean this?! (try `%s --help' for help)\n", size, program_name); fprintf (stderr, "%d is excessive, did you really mean this?! (try `%s --help' for help)\n", _size, program_name);
break; break;
} }
case 'S': /* Generate switch statement output, rather than lookup table. */ case 'S': /* Generate switch statement output, rather than lookup table. */
{ {
option_word |= SWITCH; _option_word |= SWITCH;
if ((option.total_switches = atoi (/*getopt*/optarg)) <= 0) if ((_total_switches = atoi (/*getopt*/optarg)) <= 0)
{ {
fprintf (stderr, "number of switches %s must be a positive number\n", /*getopt*/optarg); fprintf (stderr, "number of switches %s must be a positive number\n", /*getopt*/optarg);
short_usage (stderr); short_usage (stderr);
@@ -725,12 +727,12 @@ Options::operator() (int argc, char *argv[])
} }
case 't': /* Enable the TYPE mode, allowing arbitrary user structures. */ case 't': /* Enable the TYPE mode, allowing arbitrary user structures. */
{ {
option_word |= TYPE; _option_word |= TYPE;
break; break;
} }
case 'T': /* Don't print structure definition. */ case 'T': /* Don't print structure definition. */
{ {
option_word |= NOTYPE; _option_word |= NOTYPE;
break; break;
} }
case 'v': /* Print out the version and quit. */ case 'v': /* Print out the version and quit. */
@@ -738,17 +740,17 @@ Options::operator() (int argc, char *argv[])
exit (0); exit (0);
case 'W': /* Sets the name for the hash table array */ case 'W': /* Sets the name for the hash table array */
{ {
wordlist_name = /*getopt*/optarg; _wordlist_name = /*getopt*/optarg;
break; break;
} }
case 'Z': /* Set the class name. */ case 'Z': /* Set the class name. */
{ {
class_name = /*getopt*/optarg; _class_name = /*getopt*/optarg;
break; break;
} }
case '7': /* Assume 7-bit characters. */ case '7': /* Assume 7-bit characters. */
{ {
option_word |= SEVENBIT; _option_word |= SEVENBIT;
Vectors::ALPHA_SIZE = 128; Vectors::ALPHA_SIZE = 128;
break; break;
} }

View File

@@ -105,24 +105,24 @@ public:
static const char *get_delimiter (); static const char *get_delimiter ();
private: private:
static int option_word; /* Holds the user-specified Options. */ static int _option_word; /* Holds the user-specified Options. */
static int total_switches; /* Number of switch statements to generate. */ static int _total_switches; /* Number of switch statements to generate. */
static int total_keysig_size; /* Total number of distinct key_positions. */ static int _total_keysig_size; /* Total number of distinct key_positions. */
static int size; /* Range of the hash table. */ static int _size; /* Range of the hash table. */
static int key_pos; /* Tracks current key position for Iterator. */ static int _key_pos; /* Tracks current key position for Iterator. */
static int jump; /* Jump length when trying alternative values. */ static int _jump; /* Jump length when trying alternative values. */
static int initial_asso_value; /* Initial value for asso_values table. */ static int _initial_asso_value; /* Initial value for asso_values table. */
static int argument_count; /* Records count of command-line arguments. */ static int _argument_count; /* Records count of command-line arguments. */
static int iterations; /* Amount to iterate when a collision occurs. */ static int _iterations; /* Amount to iterate when a collision occurs. */
static char **argument_vector; /* Stores a pointer to command-line vector. */ static char **_argument_vector; /* Stores a pointer to command-line vector. */
static const char *function_name; /* Names used for generated lookup function. */ static const char *_function_name; /* Names used for generated lookup function. */
static const char *key_name; /* Name used for keyword key. */ static const char *_key_name; /* Name used for keyword key. */
static const char *initializer_suffix; /* Suffix for empty struct initializers. */ static const char *_initializer_suffix; /* Suffix for empty struct initializers. */
static const char *class_name; /* Name used for generated C++ class. */ static const char *_class_name; /* Name used for generated C++ class. */
static const char *hash_name; /* Name used for generated hash function. */ static const char *_hash_name; /* Name used for generated hash function. */
static const char *wordlist_name; /* Name used for hash table array. */ static const char *_wordlist_name; /* Name used for hash table array. */
static const char *delimiters; /* Separates keywords from other attributes. */ static const char *_delimiters; /* Separates keywords from other attributes. */
static char key_positions[MAX_KEY_POS]; /* Contains user-specified key choices. */ static char _key_positions[MAX_KEY_POS]; /* Contains user-specified key choices. */
static int key_sort (char *base, int len); /* Sorts key positions in REVERSE order. */ static int key_sort (char *base, int len); /* Sorts key positions in REVERSE order. */
static void short_usage (FILE * strm); /* Prints proper program usage. */ static void short_usage (FILE * strm); /* Prints proper program usage. */
static void long_usage (FILE * strm); /* Prints proper program usage. */ static void long_usage (FILE * strm); /* Prints proper program usage. */

View File

@@ -23,138 +23,138 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111, USA. */
INLINE int INLINE int
Options::operator[] (Option_Type option) Options::operator[] (Option_Type option)
{ {
return option_word & option; return _option_word & option;
} }
/* Enables option OPT. */ /* Enables option OPT. */
INLINE void INLINE void
Options::operator = (enum Option_Type opt) Options::operator = (enum Option_Type opt)
{ {
option_word |= opt; _option_word |= opt;
} }
/* Disables option OPT. */ /* Disables option OPT. */
INLINE void INLINE void
Options::operator != (enum Option_Type opt) Options::operator != (enum Option_Type opt)
{ {
option_word &= ~opt; _option_word &= ~opt;
} }
/* Initializes the key Iterator. */ /* Initializes the key Iterator. */
INLINE void INLINE void
Options::reset () Options::reset ()
{ {
key_pos = 0; _key_pos = 0;
} }
/* Returns current key_position and advance index. */ /* Returns current key_position and advance index. */
INLINE int INLINE int
Options::get () Options::get ()
{ {
return key_positions[key_pos++]; return _key_positions[_key_pos++];
} }
/* Sets the size of the table size. */ /* Sets the size of the table size. */
INLINE void INLINE void
Options::set_asso_max (int r) Options::set_asso_max (int r)
{ {
size = r; _size = r;
} }
/* Returns the size of the table size. */ /* Returns the size of the table size. */
INLINE int INLINE int
Options::get_asso_max () Options::get_asso_max ()
{ {
return size; return _size;
} }
/* Returns total distinct key positions. */ /* Returns total distinct key positions. */
INLINE int INLINE int
Options::get_max_keysig_size () Options::get_max_keysig_size ()
{ {
return total_keysig_size; return _total_keysig_size;
} }
/* Sets total distinct key positions. */ /* Sets total distinct key positions. */
INLINE void INLINE void
Options::set_keysig_size (int size) Options::set_keysig_size (int size)
{ {
total_keysig_size = size; _total_keysig_size = size;
} }
/* Returns the jump value. */ /* Returns the jump value. */
INLINE int INLINE int
Options::get_jump () Options::get_jump ()
{ {
return jump; return _jump;
} }
/* Returns the generated function name. */ /* Returns the generated function name. */
INLINE const char * INLINE const char *
Options::get_function_name () Options::get_function_name ()
{ {
return function_name; return _function_name;
} }
/* Returns the keyword key name. */ /* Returns the keyword key name. */
INLINE const char * INLINE const char *
Options::get_key_name () Options::get_key_name ()
{ {
return key_name; return _key_name;
} }
/* Returns the struct initializer suffix. */ /* Returns the struct initializer suffix. */
INLINE const char * INLINE const char *
Options::get_initializer_suffix () Options::get_initializer_suffix ()
{ {
return initializer_suffix; return _initializer_suffix;
} }
/* Returns the hash function name. */ /* Returns the hash function name. */
INLINE const char * INLINE const char *
Options::get_hash_name () Options::get_hash_name ()
{ {
return hash_name; return _hash_name;
} }
/* Returns the hash table array name. */ /* Returns the hash table array name. */
INLINE const char * INLINE const char *
Options::get_wordlist_name () Options::get_wordlist_name ()
{ {
return wordlist_name; return _wordlist_name;
} }
/* Returns the generated class name. */ /* Returns the generated class name. */
INLINE const char * INLINE const char *
Options::get_class_name () Options::get_class_name ()
{ {
return class_name; return _class_name;
} }
/* Returns the initial associated character value. */ /* Returns the initial associated character value. */
INLINE int INLINE int
Options::initial_value () Options::initial_value ()
{ {
return initial_asso_value; return _initial_asso_value;
} }
/* Returns the iterations value. */ /* Returns the iterations value. */
INLINE int INLINE int
Options::get_iterations () Options::get_iterations ()
{ {
return iterations; return _iterations;
} }
/* Returns the string used to delimit keywords from other attributes. */ /* Returns the string used to delimit keywords from other attributes. */
INLINE const char * INLINE const char *
Options::get_delimiter () Options::get_delimiter ()
{ {
return delimiters; return _delimiters;
} }
/* Gets the total number of switch statements to generate. */ /* Gets the total number of switch statements to generate. */
INLINE int INLINE int
Options::get_total_switches () Options::get_total_switches ()
{ {
return total_switches; return _total_switches;
} }

View File

@@ -70,11 +70,11 @@ Output::Output (KeywordExt_List *head_, const char *array_type_,
int additional_code_, const char *include_src_, int additional_code_, const char *include_src_,
int total_keys_, int total_duplicates_, int max_key_len_, int total_keys_, int total_duplicates_, int max_key_len_,
int min_key_len_, Vectors *v_) int min_key_len_, Vectors *v_)
: head (head_), array_type (array_type_), return_type (return_type_), : _head (head_), _array_type (array_type_), _return_type (return_type_),
struct_tag (struct_tag_), additional_code (additional_code_), _struct_tag (struct_tag_), _additional_code (additional_code_),
include_src (include_src_), total_keys (total_keys_), _include_src (include_src_), _total_keys (total_keys_),
total_duplicates (total_duplicates_), max_key_len (max_key_len_), _total_duplicates (total_duplicates_), _max_key_len (max_key_len_),
min_key_len (min_key_len_), v (v_) _min_key_len (min_key_len_), _v (v_)
{ {
} }
@@ -88,11 +88,11 @@ void
Output::compute_min_max () Output::compute_min_max ()
{ {
KeywordExt_List *temp; KeywordExt_List *temp;
for (temp = head; temp->rest(); temp = temp->rest()) for (temp = _head; temp->rest(); temp = temp->rest())
; ;
min_hash_value = head->first()->hash_value; _min_hash_value = _head->first()->_hash_value;
max_hash_value = temp->first()->hash_value; _max_hash_value = temp->first()->_hash_value;
} }
/* ------------------------------------------------------------------------- */ /* ------------------------------------------------------------------------- */
@@ -106,11 +106,11 @@ Output::num_hash_values ()
KeywordExt_List *temp; KeywordExt_List *temp;
int value; int value;
for (temp = head, value = temp->first()->hash_value; (temp = temp->rest()) != NULL; ) for (temp = _head, value = temp->first()->_hash_value; (temp = temp->rest()) != NULL; )
{ {
if (value != temp->first()->hash_value) if (value != temp->first()->_hash_value)
{ {
value = temp->first()->hash_value; value = temp->first()->_hash_value;
count++; count++;
} }
} }
@@ -198,11 +198,11 @@ void
Output::output_constants (struct Output_Constants& style) Output::output_constants (struct Output_Constants& style)
{ {
style.output_start (); style.output_start ();
style.output_item ("TOTAL_KEYWORDS", total_keys); style.output_item ("TOTAL_KEYWORDS", _total_keys);
style.output_item ("MIN_WORD_LENGTH", min_key_len); style.output_item ("MIN_WORD_LENGTH", _min_key_len);
style.output_item ("MAX_WORD_LENGTH", max_key_len); style.output_item ("MAX_WORD_LENGTH", _max_key_len);
style.output_item ("MIN_HASH_VALUE", min_hash_value); style.output_item ("MIN_HASH_VALUE", _min_hash_value);
style.output_item ("MAX_HASH_VALUE", max_hash_value); style.output_item ("MAX_HASH_VALUE", _max_hash_value);
style.output_end (); style.output_end ();
} }
@@ -407,7 +407,7 @@ Output::output_hash_function ()
/* Calculate maximum number of digits required for MAX_HASH_VALUE. */ /* Calculate maximum number of digits required for MAX_HASH_VALUE. */
field_width = 2; field_width = 2;
for (int trunc = max_hash_value; (trunc /= 10) > 0;) for (int trunc = _max_hash_value; (trunc /= 10) > 0;)
field_width++; field_width++;
/* Output the function's head. */ /* Output the function's head. */
@@ -450,16 +450,16 @@ Output::output_hash_function ()
printf (" static %s%s asso_values[] =\n" printf (" static %s%s asso_values[] =\n"
" {", " {",
const_readonly_array, const_readonly_array,
smallest_integral_type (max_hash_value + 1)); smallest_integral_type (_max_hash_value + 1));
for (int count = 0; count < v->ALPHA_SIZE; count++) for (int count = 0; count < _v->ALPHA_SIZE; count++)
{ {
if (count > 0) if (count > 0)
printf (","); printf (",");
if (!(count % max_column)) if (!(count % max_column))
printf ("\n "); printf ("\n ");
printf ("%*d", field_width, printf ("%*d", field_width,
v->occurrences[count] ? v->asso_values[count] : max_hash_value + 1); _v->_occurrences[count] ? _v->_asso_values[count] : _max_hash_value + 1);
} }
printf ("\n" printf ("\n"
@@ -479,7 +479,7 @@ Output::output_hash_function ()
/* Get first (also highest) key position. */ /* Get first (also highest) key position. */
key_pos = option.get (); key_pos = option.get ();
if (!option[ALLCHARS] && (key_pos == WORD_END || key_pos <= min_key_len)) if (!option[ALLCHARS] && (key_pos == WORD_END || key_pos <= _min_key_len))
{ {
/* We can perform additional optimizations here: /* We can perform additional optimizations here:
Write it out as a single expression. Note that the values Write it out as a single expression. Note that the values
@@ -516,7 +516,7 @@ Output::output_hash_function ()
/* User wants *all* characters considered in hash. */ /* User wants *all* characters considered in hash. */
if (option[ALLCHARS]) if (option[ALLCHARS])
{ {
for (int i = max_key_len; i > 0; i--) for (int i = _max_key_len; i > 0; i--)
printf (" case %d:\n" printf (" case %d:\n"
" hval += asso_values[%sstr[%d]];\n", " hval += asso_values[%sstr[%d]];\n",
i, char_to_index, i - 1); i, char_to_index, i - 1);
@@ -527,7 +527,7 @@ Output::output_hash_function ()
} }
else /* do the hard part... */ else /* do the hard part... */
{ {
while (key_pos != WORD_END && key_pos > max_key_len) while (key_pos != WORD_END && key_pos > _max_key_len)
if ((key_pos = option.get ()) == EOS) if ((key_pos = option.get ()) == EOS)
break; break;
@@ -546,7 +546,7 @@ Output::output_hash_function ()
} }
while (key_pos != EOS && key_pos != WORD_END); while (key_pos != EOS && key_pos != WORD_END);
for ( ; i >= min_key_len; i--) for ( ; i >= _min_key_len; i--)
printf (" case %d:\n", i); printf (" case %d:\n", i);
} }
@@ -578,23 +578,23 @@ Output::output_keylength_table ()
printf ("%sstatic %s%s lengthtable[] =\n%s {", printf ("%sstatic %s%s lengthtable[] =\n%s {",
indent, const_readonly_array, indent, const_readonly_array,
smallest_integral_type (max_key_len), smallest_integral_type (_max_key_len),
indent); indent);
/* Generate an array of lengths, similar to output_keyword_table. */ /* Generate an array of lengths, similar to output_keyword_table. */
column = 0; column = 0;
for (temp = head, index = 0; temp; temp = temp->rest()) for (temp = _head, index = 0; temp; temp = temp->rest())
{ {
if (option[SWITCH] && !option[TYPE] if (option[SWITCH] && !option[TYPE]
&& !(temp->first()->duplicate_link && !(temp->first()->_duplicate_link
|| (temp->rest() && temp->first()->hash_value == temp->rest()->first()->hash_value))) || (temp->rest() && temp->first()->_hash_value == temp->rest()->first()->_hash_value)))
continue; continue;
if (index < temp->first()->hash_value && !option[SWITCH] && !option[DUP]) if (index < temp->first()->_hash_value && !option[SWITCH] && !option[DUP])
{ {
/* Some blank entries. */ /* Some blank entries. */
for ( ; index < temp->first()->hash_value; index++) for ( ; index < temp->first()->_hash_value; index++)
{ {
if (index > 0) if (index > 0)
printf (","); printf (",");
@@ -608,17 +608,17 @@ Output::output_keylength_table ()
printf (","); printf (",");
if ((column++ % columns) == 0) if ((column++ % columns) == 0)
printf("\n%s ", indent); printf("\n%s ", indent);
printf ("%3d", temp->first()->allchars_length); printf ("%3d", temp->first()->_allchars_length);
/* Deal with links specially. */ /* Deal with links specially. */
if (temp->first()->duplicate_link) // implies option[DUP] if (temp->first()->_duplicate_link) // implies option[DUP]
for (KeywordExt *links = temp->first()->duplicate_link; links; links = links->duplicate_link) for (KeywordExt *links = temp->first()->_duplicate_link; links; links = links->_duplicate_link)
{ {
++index; ++index;
printf (","); printf (",");
if ((column++ % columns) == 0) if ((column++ % columns) == 0)
printf("\n%s ", indent); printf("\n%s ", indent);
printf ("%3d", links->allchars_length); printf ("%3d", links->_allchars_length);
} }
index++; index++;
@@ -637,16 +637,16 @@ output_keyword_entry (KeywordExt *temp, const char *indent)
printf ("%s ", indent); printf ("%s ", indent);
if (option[TYPE]) if (option[TYPE])
printf ("{"); printf ("{");
output_string (temp->allchars, temp->allchars_length); output_string (temp->_allchars, temp->_allchars_length);
if (option[TYPE]) if (option[TYPE])
{ {
if (strlen (temp->rest) > 0) if (strlen (temp->_rest) > 0)
printf (",%s", temp->rest); printf (",%s", temp->_rest);
printf ("}"); printf ("}");
} }
if (option[DEBUG]) if (option[DEBUG])
printf (" /* hash value = %d, index = %d */", printf (" /* hash value = %d, index = %d */",
temp->hash_value, temp->final_index); temp->_hash_value, temp->_final_index);
} }
static void static void
@@ -696,7 +696,7 @@ Output::output_keyword_table ()
printf ("%sstatic ", printf ("%sstatic ",
indent); indent);
output_const_type (const_readonly_array, struct_tag); output_const_type (const_readonly_array, _struct_tag);
printf ("%s[] =\n" printf ("%s[] =\n"
"%s {\n", "%s {\n",
option.get_wordlist_name (), option.get_wordlist_name (),
@@ -704,33 +704,33 @@ Output::output_keyword_table ()
/* Generate an array of reserved words at appropriate locations. */ /* Generate an array of reserved words at appropriate locations. */
for (temp = head, index = 0; temp; temp = temp->rest()) for (temp = _head, index = 0; temp; temp = temp->rest())
{ {
if (option[SWITCH] && !option[TYPE] if (option[SWITCH] && !option[TYPE]
&& !(temp->first()->duplicate_link && !(temp->first()->_duplicate_link
|| (temp->rest() && temp->first()->hash_value == temp->rest()->first()->hash_value))) || (temp->rest() && temp->first()->_hash_value == temp->rest()->first()->_hash_value)))
continue; continue;
if (index > 0) if (index > 0)
printf (",\n"); printf (",\n");
if (index < temp->first()->hash_value && !option[SWITCH] && !option[DUP]) if (index < temp->first()->_hash_value && !option[SWITCH] && !option[DUP])
{ {
/* Some blank entries. */ /* Some blank entries. */
output_keyword_blank_entries (temp->first()->hash_value - index, indent); output_keyword_blank_entries (temp->first()->_hash_value - index, indent);
printf (",\n"); printf (",\n");
index = temp->first()->hash_value; index = temp->first()->_hash_value;
} }
temp->first()->final_index = index; temp->first()->_final_index = index;
output_keyword_entry (temp->first(), indent); output_keyword_entry (temp->first(), indent);
/* Deal with links specially. */ /* Deal with links specially. */
if (temp->first()->duplicate_link) // implies option[DUP] if (temp->first()->_duplicate_link) // implies option[DUP]
for (KeywordExt *links = temp->first()->duplicate_link; links; links = links->duplicate_link) for (KeywordExt *links = temp->first()->_duplicate_link; links; links = links->_duplicate_link)
{ {
links->final_index = ++index; links->_final_index = ++index;
printf (",\n"); printf (",\n");
output_keyword_entry (links, indent); output_keyword_entry (links, indent);
} }
@@ -764,44 +764,44 @@ Output::output_lookup_array ()
int count; /* Number of consecutive duplicates at this index. */ int count; /* Number of consecutive duplicates at this index. */
}; };
duplicate_entry *duplicates = new duplicate_entry[total_duplicates]; duplicate_entry *duplicates = new duplicate_entry[_total_duplicates];
int *lookup_array = new int[max_hash_value + 1 + 2*total_duplicates]; int *lookup_array = new int[_max_hash_value + 1 + 2*_total_duplicates];
int lookup_array_size = max_hash_value + 1; int lookup_array_size = _max_hash_value + 1;
duplicate_entry *dup_ptr = &duplicates[0]; duplicate_entry *dup_ptr = &duplicates[0];
int *lookup_ptr = &lookup_array[max_hash_value + 1 + 2*total_duplicates]; int *lookup_ptr = &lookup_array[_max_hash_value + 1 + 2*_total_duplicates];
while (lookup_ptr > lookup_array) while (lookup_ptr > lookup_array)
*--lookup_ptr = DEFAULT_VALUE; *--lookup_ptr = DEFAULT_VALUE;
/* Now dup_ptr = &duplicates[0] and lookup_ptr = &lookup_array[0]. */ /* Now dup_ptr = &duplicates[0] and lookup_ptr = &lookup_array[0]. */
for (KeywordExt_List *temp = head; temp; temp = temp->rest()) for (KeywordExt_List *temp = _head; temp; temp = temp->rest())
{ {
int hash_value = temp->first()->hash_value; int hash_value = temp->first()->_hash_value;
lookup_array[hash_value] = temp->first()->final_index; lookup_array[hash_value] = temp->first()->_final_index;
if (option[DEBUG]) if (option[DEBUG])
fprintf (stderr, "keyword = %.*s, index = %d\n", fprintf (stderr, "keyword = %.*s, index = %d\n",
temp->first()->allchars_length, temp->first()->allchars, temp->first()->final_index); temp->first()->_allchars_length, temp->first()->_allchars, temp->first()->_final_index);
if (temp->first()->duplicate_link if (temp->first()->_duplicate_link
|| (temp->rest() && hash_value == temp->rest()->first()->hash_value)) || (temp->rest() && hash_value == temp->rest()->first()->_hash_value))
{ {
/* Start a duplicate entry. */ /* Start a duplicate entry. */
dup_ptr->hash_value = hash_value; dup_ptr->hash_value = hash_value;
dup_ptr->index = temp->first()->final_index; dup_ptr->index = temp->first()->_final_index;
dup_ptr->count = 1; dup_ptr->count = 1;
for (;;) for (;;)
{ {
for (KeywordExt *ptr = temp->first()->duplicate_link; ptr; ptr = ptr->duplicate_link) for (KeywordExt *ptr = temp->first()->_duplicate_link; ptr; ptr = ptr->_duplicate_link)
{ {
dup_ptr->count++; dup_ptr->count++;
if (option[DEBUG]) if (option[DEBUG])
fprintf (stderr, fprintf (stderr,
"static linked keyword = %.*s, index = %d\n", "static linked keyword = %.*s, index = %d\n",
ptr->allchars_length, ptr->allchars, ptr->final_index); ptr->_allchars_length, ptr->_allchars, ptr->_final_index);
} }
if (!(temp->rest() && hash_value == temp->rest()->first()->hash_value)) if (!(temp->rest() && hash_value == temp->rest()->first()->_hash_value))
break; break;
temp = temp->rest(); temp = temp->rest();
@@ -809,7 +809,7 @@ Output::output_lookup_array ()
dup_ptr->count++; dup_ptr->count++;
if (option[DEBUG]) if (option[DEBUG])
fprintf (stderr, "dynamic linked keyword = %.*s, index = %d\n", fprintf (stderr, "dynamic linked keyword = %.*s, index = %d\n",
temp->first()->allchars_length, temp->first()->allchars, temp->first()->final_index); temp->first()->_allchars_length, temp->first()->_allchars, temp->first()->_final_index);
} }
assert (dup_ptr->count >= 2); assert (dup_ptr->count >= 2);
dup_ptr++; dup_ptr++;
@@ -842,11 +842,11 @@ Output::output_lookup_array ()
i = lookup_array_size; i = lookup_array_size;
lookup_array_size += 2; lookup_array_size += 2;
found_i: found_i:
/* Put in an indirection from dup_ptr->hash_value to i. /* Put in an indirection from dup_ptr->_hash_value to i.
At i and i+1 store dup_ptr->final_index and dup_ptr->count. */ At i and i+1 store dup_ptr->_final_index and dup_ptr->count. */
assert (lookup_array[dup_ptr->hash_value] == dup_ptr->index); assert (lookup_array[dup_ptr->hash_value] == dup_ptr->index);
lookup_array[dup_ptr->hash_value] = - 1 - total_keys - i; lookup_array[dup_ptr->hash_value] = - 1 - _total_keys - i;
lookup_array[i] = - total_keys + dup_ptr->index; lookup_array[i] = - _total_keys + dup_ptr->index;
lookup_array[i + 1] = - dup_ptr->count; lookup_array[i + 1] = - dup_ptr->count;
/* All these three values are <= -2, distinct from DEFAULT_VALUE. */ /* All these three values are <= -2, distinct from DEFAULT_VALUE. */
} }
@@ -917,9 +917,9 @@ Output::output_lookup_tables ()
if (option[SWITCH]) if (option[SWITCH])
{ {
/* Use the switch in place of lookup table. */ /* Use the switch in place of lookup table. */
if (option[LENTABLE] && (option[DUP] && total_duplicates > 0)) if (option[LENTABLE] && (option[DUP] && _total_duplicates > 0))
output_keylength_table (); output_keylength_table ();
if (option[TYPE] || (option[DUP] && total_duplicates > 0)) if (option[TYPE] || (option[DUP] && _total_duplicates > 0))
output_keyword_table (); output_keyword_table ();
} }
else else
@@ -941,24 +941,24 @@ output_switch_case (KeywordExt_List *list, int indent, int *jumps_away)
{ {
if (option[DEBUG]) if (option[DEBUG])
printf ("%*s/* hash value = %4d, keyword = \"%.*s\" */\n", printf ("%*s/* hash value = %4d, keyword = \"%.*s\" */\n",
indent, "", list->first()->hash_value, list->first()->allchars_length, list->first()->allchars); indent, "", list->first()->_hash_value, list->first()->_allchars_length, list->first()->_allchars);
if (option[DUP] if (option[DUP]
&& (list->first()->duplicate_link && (list->first()->_duplicate_link
|| (list->rest() && list->first()->hash_value == list->rest()->first()->hash_value))) || (list->rest() && list->first()->_hash_value == list->rest()->first()->_hash_value)))
{ {
if (option[LENTABLE]) if (option[LENTABLE])
printf ("%*slengthptr = &lengthtable[%d];\n", printf ("%*slengthptr = &lengthtable[%d];\n",
indent, "", list->first()->final_index); indent, "", list->first()->_final_index);
printf ("%*swordptr = &%s[%d];\n", printf ("%*swordptr = &%s[%d];\n",
indent, "", option.get_wordlist_name (), list->first()->final_index); indent, "", option.get_wordlist_name (), list->first()->_final_index);
int count = 0; int count = 0;
for (KeywordExt_List *temp = list; ; temp = temp->rest()) for (KeywordExt_List *temp = list; ; temp = temp->rest())
{ {
for (KeywordExt *links = temp->first(); links; links = links->duplicate_link) for (KeywordExt *links = temp->first(); links; links = links->_duplicate_link)
count++; count++;
if (!(temp->rest() && temp->first()->hash_value == temp->rest()->first()->hash_value)) if (!(temp->rest() && temp->first()->_hash_value == temp->rest()->first()->_hash_value))
break; break;
} }
@@ -974,16 +974,16 @@ output_switch_case (KeywordExt_List *list, int indent, int *jumps_away)
{ {
printf ("%*sif (len == %d)\n" printf ("%*sif (len == %d)\n"
"%*s {\n", "%*s {\n",
indent, "", list->first()->allchars_length, indent, "", list->first()->_allchars_length,
indent, ""); indent, "");
indent += 4; indent += 4;
} }
printf ("%*sresword = ", printf ("%*sresword = ",
indent, ""); indent, "");
if (option[TYPE]) if (option[TYPE])
printf ("&%s[%d]", option.get_wordlist_name (), list->first()->final_index); printf ("&%s[%d]", option.get_wordlist_name (), list->first()->_final_index);
else else
output_string (list->first()->allchars, list->first()->allchars_length); output_string (list->first()->_allchars, list->first()->_allchars_length);
printf (";\n"); printf (";\n");
printf ("%*sgoto compare;\n", printf ("%*sgoto compare;\n",
indent, ""); indent, "");
@@ -997,7 +997,7 @@ output_switch_case (KeywordExt_List *list, int indent, int *jumps_away)
*jumps_away = 1; *jumps_away = 1;
} }
while (list->rest() && list->first()->hash_value == list->rest()->first()->hash_value) while (list->rest() && list->first()->_hash_value == list->rest()->first()->_hash_value)
list = list->rest(); list = list->rest();
list = list->rest(); list = list->rest();
return list; return list;
@@ -1023,24 +1023,24 @@ output_switches (KeywordExt_List *list, int num_switches, int size, int min_hash
KeywordExt_List *temp = list; KeywordExt_List *temp = list;
for (int count = size1; count > 0; count--) for (int count = size1; count > 0; count--)
{ {
while (temp->first()->hash_value == temp->rest()->first()->hash_value) while (temp->first()->_hash_value == temp->rest()->first()->_hash_value)
temp = temp->rest(); temp = temp->rest();
temp = temp->rest(); temp = temp->rest();
} }
printf ("%*sif (key < %d)\n" printf ("%*sif (key < %d)\n"
"%*s {\n", "%*s {\n",
indent, "", temp->first()->hash_value, indent, "", temp->first()->_hash_value,
indent, ""); indent, "");
output_switches (list, part1, size1, min_hash_value, temp->first()->hash_value-1, indent+4); output_switches (list, part1, size1, min_hash_value, temp->first()->_hash_value-1, indent+4);
printf ("%*s }\n" printf ("%*s }\n"
"%*selse\n" "%*selse\n"
"%*s {\n", "%*s {\n",
indent, "", indent, "", indent, ""); indent, "", indent, "", indent, "");
output_switches (temp, part2, size2, temp->first()->hash_value, max_hash_value, indent+4); output_switches (temp, part2, size2, temp->first()->_hash_value, max_hash_value, indent+4);
printf ("%*s }\n", printf ("%*s }\n",
indent, ""); indent, "");
@@ -1048,7 +1048,7 @@ output_switches (KeywordExt_List *list, int num_switches, int size, int min_hash
else else
{ {
/* Output a single switch. */ /* Output a single switch. */
int lowest_case_value = list->first()->hash_value; int lowest_case_value = list->first()->_hash_value;
if (size == 1) if (size == 1)
{ {
int jumps_away = 0; int jumps_away = 0;
@@ -1079,7 +1079,7 @@ output_switches (KeywordExt_List *list, int num_switches, int size, int min_hash
{ {
int jumps_away = 0; int jumps_away = 0;
printf ("%*s case %d:\n", printf ("%*s case %d:\n",
indent, "", list->first()->hash_value - lowest_case_value); indent, "", list->first()->_hash_value - lowest_case_value);
list = output_switch_case (list, indent+6, &jumps_away); list = output_switch_case (list, indent+6, &jumps_away);
if (!jumps_away) if (!jumps_away)
printf ("%*s break;\n", printf ("%*s break;\n",
@@ -1114,25 +1114,25 @@ Output::output_lookup_function_body (const Output_Compare& comparison)
{ {
if (option[LENTABLE]) if (option[LENTABLE])
printf (" register %s%s *lengthptr;\n", printf (" register %s%s *lengthptr;\n",
const_always, smallest_integral_type (max_key_len)); const_always, smallest_integral_type (_max_key_len));
printf (" register "); printf (" register ");
output_const_type (const_readonly_array, struct_tag); output_const_type (const_readonly_array, _struct_tag);
printf ("*wordptr;\n"); printf ("*wordptr;\n");
printf (" register "); printf (" register ");
output_const_type (const_readonly_array, struct_tag); output_const_type (const_readonly_array, _struct_tag);
printf ("*wordendptr;\n"); printf ("*wordendptr;\n");
} }
if (option[TYPE]) if (option[TYPE])
{ {
printf (" register "); printf (" register ");
output_const_type (const_readonly_array, struct_tag); output_const_type (const_readonly_array, _struct_tag);
printf ("*resword;\n\n"); printf ("*resword;\n\n");
} }
else else
printf (" register %sresword;\n\n", printf (" register %sresword;\n\n",
struct_tag); _struct_tag);
output_switches (head, num_switches, switch_size, min_hash_value, max_hash_value, 10); output_switches (_head, num_switches, switch_size, _min_hash_value, _max_hash_value, 10);
if (option[DUP]) if (option[DUP])
{ {
@@ -1241,7 +1241,7 @@ Output::output_lookup_function_body (const Output_Compare& comparison)
indent -= 4; indent -= 4;
printf ("%*s }\n", indent, ""); printf ("%*s }\n", indent, "");
} }
if (total_duplicates > 0) if (_total_duplicates > 0)
{ {
printf ("%*s else if (index < -TOTAL_KEYWORDS)\n" printf ("%*s else if (index < -TOTAL_KEYWORDS)\n"
"%*s {\n" "%*s {\n"
@@ -1249,15 +1249,15 @@ Output::output_lookup_function_body (const Output_Compare& comparison)
indent, "", indent, "", indent, ""); indent, "", indent, "", indent, "");
if (option[LENTABLE]) if (option[LENTABLE])
printf ("%*s register %s%s *lengthptr = &lengthtable[TOTAL_KEYWORDS + lookup[offset]];\n", printf ("%*s register %s%s *lengthptr = &lengthtable[TOTAL_KEYWORDS + lookup[offset]];\n",
indent, "", const_always, smallest_integral_type (max_key_len)); indent, "", const_always, smallest_integral_type (_max_key_len));
printf ("%*s register ", printf ("%*s register ",
indent, ""); indent, "");
output_const_type (const_readonly_array, struct_tag); output_const_type (const_readonly_array, _struct_tag);
printf ("*wordptr = &%s[TOTAL_KEYWORDS + lookup[offset]];\n", printf ("*wordptr = &%s[TOTAL_KEYWORDS + lookup[offset]];\n",
option.get_wordlist_name ()); option.get_wordlist_name ());
printf ("%*s register ", printf ("%*s register ",
indent, ""); indent, "");
output_const_type (const_readonly_array, struct_tag); output_const_type (const_readonly_array, _struct_tag);
printf ("*wordendptr = wordptr + -lookup[offset + 1];\n\n"); printf ("*wordendptr = wordptr + -lookup[offset + 1];\n\n");
printf ("%*s while (wordptr < wordendptr)\n" printf ("%*s while (wordptr < wordendptr)\n"
"%*s {\n", "%*s {\n",
@@ -1350,7 +1350,7 @@ Output::output_lookup_function ()
"#endif\n"); "#endif\n");
printf ("%s%s\n", printf ("%s%s\n",
const_for_struct, return_type); const_for_struct, _return_type);
if (option[CPLUSPLUS]) if (option[CPLUSPLUS])
printf ("%s::", option.get_class_name ()); printf ("%s::", option.get_class_name ());
printf ("%s ", option.get_function_name ()); printf ("%s ", option.get_function_name ());
@@ -1416,8 +1416,8 @@ Output::output ()
if (!option[TYPE]) if (!option[TYPE])
{ {
return_type = (const_always[0] ? "const char *" : "char *"); _return_type = (const_always[0] ? "const char *" : "char *");
struct_tag = (const_always[0] ? "const char *" : "char *"); _struct_tag = (const_always[0] ? "const char *" : "char *");
} }
char_to_index = (option[SEVENBIT] ? "" : "(unsigned char)"); char_to_index = (option[SEVENBIT] ? "" : "(unsigned char)");
@@ -1434,10 +1434,10 @@ Output::output ()
printf (" code produced by gperf version %s */\n", version_string); printf (" code produced by gperf version %s */\n", version_string);
Options::print_options (); Options::print_options ();
printf ("%s\n", include_src); printf ("%s\n", _include_src);
if (option[TYPE] && !option[NOTYPE]) /* Output type declaration now, reference it later on.... */ if (option[TYPE] && !option[NOTYPE]) /* Output type declaration now, reference it later on.... */
printf ("%s;\n", array_type); printf ("%s;\n", _array_type);
if (option[INCLUDE]) if (option[INCLUDE])
printf ("#include <string.h>\n"); /* Declare strlen(), strcmp(), strncmp(). */ printf ("#include <string.h>\n"); /* Declare strlen(), strcmp(), strncmp(). */
@@ -1454,7 +1454,7 @@ Output::output ()
} }
printf ("/* maximum key range = %d, duplicates = %d */\n\n", printf ("/* maximum key range = %d, duplicates = %d */\n\n",
max_hash_value - min_hash_value + 1, total_duplicates); _max_hash_value - _min_hash_value + 1, _total_duplicates);
if (option[CPLUSPLUS]) if (option[CPLUSPLUS])
printf ("class %s\n" printf ("class %s\n"
@@ -1466,7 +1466,7 @@ Output::output ()
"};\n" "};\n"
"\n", "\n",
option.get_class_name (), option.get_hash_name (), option.get_class_name (), option.get_hash_name (),
const_for_struct, return_type, option.get_function_name ()); const_for_struct, _return_type, option.get_function_name ());
output_hash_function (); output_hash_function ();
@@ -1475,7 +1475,7 @@ Output::output ()
output_lookup_function (); output_lookup_function ();
if (additional_code) if (_additional_code)
for (int c; (c = getchar ()) != EOF; putchar (c)) for (int c; (c = getchar ()) != EOF; putchar (c))
; ;

View File

@@ -49,31 +49,31 @@ private:
void output_lookup_function (); void output_lookup_function ();
/* Linked list of keywords. */ /* Linked list of keywords. */
KeywordExt_List *head; KeywordExt_List *_head;
/* Pointer to the type for word list. */ /* Pointer to the type for word list. */
const char *array_type; const char *_array_type;
/* Pointer to return type for lookup function. */ /* Pointer to return type for lookup function. */
const char *return_type; const char *_return_type;
/* Shorthand for user-defined struct tag type. */ /* Shorthand for user-defined struct tag type. */
const char *struct_tag; const char *_struct_tag;
/* True if any additional C code is included. */ /* True if any additional C code is included. */
int additional_code; int _additional_code;
/* C source code to be included verbatim. */ /* C source code to be included verbatim. */
const char *include_src; const char *_include_src;
/* Total number of keys, counting duplicates. */ /* Total number of keys, counting duplicates. */
int total_keys; int _total_keys;
/* Total number of duplicate hash values. */ /* Total number of duplicate hash values. */
int total_duplicates; int _total_duplicates;
/* Maximum length of the longest keyword. */ /* Maximum length of the longest keyword. */
int max_key_len; int _max_key_len;
/* Minimum length of the shortest keyword. */ /* Minimum length of the shortest keyword. */
int min_key_len; int _min_key_len;
/* Minimum hash value for all keywords. */ /* Minimum hash value for all keywords. */
int min_hash_value; int _min_hash_value;
/* Maximum hash value for all keywords. */ /* Maximum hash value for all keywords. */
int max_hash_value; int _max_hash_value;
Vectors * v; Vectors * _v;
}; };
#endif #endif

View File

@@ -35,7 +35,7 @@ class Read_Line
public: public:
/* Initializes the instance with a given input stream. */ /* Initializes the instance with a given input stream. */
Read_Line (FILE *stream = stdin) : fp (stream) {} Read_Line (FILE *stream = stdin) : _fp (stream) {}
/* Reads the next line and returns it, excluding the terminating newline, /* Reads the next line and returns it, excluding the terminating newline,
and ignoring lines starting with '#'. Returns NULL on error or EOF. and ignoring lines starting with '#'. Returns NULL on error or EOF.
@@ -44,7 +44,7 @@ public:
char *read_next_line (); char *read_next_line ();
private: private:
FILE *fp; /* FILE pointer to the input stream. */ FILE * const _fp; /* FILE pointer to the input stream. */
}; };
#ifdef __OPTIMIZE__ #ifdef __OPTIMIZE__

View File

@@ -32,9 +32,9 @@ Read_Line::read_next_line ()
{ {
int c; int c;
while ((c = getc (fp)) == '#') while ((c = getc (_fp)) == '#')
{ {
while (c = getc (fp), c != EOF && c != '\n') while (c = getc (_fp), c != EOF && c != '\n')
; ;
if (c == EOF) if (c == EOF)
@@ -48,7 +48,7 @@ Read_Line::read_next_line ()
char *line = NULL; char *line = NULL;
size_t linesize = 0; size_t linesize = 0;
int length = get_line (&line, &linesize, fp); int length = get_line (&line, &linesize, _fp);
if (length < 0) if (length < 0)
{ {
delete[] line; delete[] line;

View File

@@ -1,5 +1,5 @@
/* Static class data members that are shared between several classes. /* Static class data members that are shared between several classes.
Copyright (C) 1989-1998 Free Software Foundation, Inc. Copyright (C) 1989-1998, 2002 Free Software Foundation, Inc.
written by Douglas C. Schmidt (schmidt@ics.uci.edu) written by Douglas C. Schmidt (schmidt@ics.uci.edu)
This file is part of GNU GPERF. This file is part of GNU GPERF.
@@ -21,5 +21,5 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111, USA. */
#include "vectors.h" #include "vectors.h"
int Vectors::ALPHA_SIZE = MAX_ALPHA_SIZE; int Vectors::ALPHA_SIZE = MAX_ALPHA_SIZE;
int Vectors::occurrences[MAX_ALPHA_SIZE]; int Vectors::_occurrences[MAX_ALPHA_SIZE];
int Vectors::asso_values[MAX_ALPHA_SIZE]; int Vectors::_asso_values[MAX_ALPHA_SIZE];

View File

@@ -3,7 +3,7 @@
/* Static class data members that are shared between several classes via /* Static class data members that are shared between several classes via
inheritance. inheritance.
Copyright (C) 1989-1998 Free Software Foundation, Inc. Copyright (C) 1989-1998, 2002 Free Software Foundation, Inc.
written by Douglas C. Schmidt (schmidt@ics.uci.edu) written by Douglas C. Schmidt (schmidt@ics.uci.edu)
This file is part of GNU GPERF. This file is part of GNU GPERF.
@@ -29,9 +29,9 @@ static const int MAX_ALPHA_SIZE = 256;
struct Vectors struct Vectors
{ {
static int ALPHA_SIZE; /* Size of alphabet. */ static int ALPHA_SIZE; /* Size of alphabet. */
static int occurrences[MAX_ALPHA_SIZE]; /* Counts occurrences of each key set character. */ static int _occurrences[MAX_ALPHA_SIZE]; /* Counts occurrences of each key set character. */
static int asso_values[MAX_ALPHA_SIZE]; /* Value associated with each character. */ static int _asso_values[MAX_ALPHA_SIZE]; /* Value associated with each character. */
}; };
#endif #endif