diff options
author | Bruno Haible <bruno@clisp.org> | 2002-11-09 01:12:49 +0000 |
---|---|---|
committer | Bruno Haible <bruno@clisp.org> | 2002-11-09 01:12:49 +0000 |
commit | 34da28c8ab95e15d278a541d543ee17257612543 (patch) | |
tree | e3b2c845c985ce9e8ff1bf94f8e6ebfef95b9cad | |
parent | 643c2cab823756c6ad7c42997b6588eff8a28db9 (diff) | |
download | gperf-34da28c8ab95e15d278a541d543ee17257612543.tar.gz |
Prefix all field names with _.
-rw-r--r-- | ChangeLog | 3 | ||||
-rw-r--r-- | src/bool-array.cc | 2 | ||||
-rw-r--r-- | src/bool-array.h | 6 | ||||
-rw-r--r-- | src/bool-array.icc | 16 | ||||
-rw-r--r-- | src/gen-perf.cc | 90 | ||||
-rw-r--r-- | src/gen-perf.h | 8 | ||||
-rw-r--r-- | src/hash-table.cc | 36 | ||||
-rw-r--r-- | src/hash-table.h | 8 | ||||
-rw-r--r-- | src/key-list.cc | 138 | ||||
-rw-r--r-- | src/key-list.h | 28 | ||||
-rw-r--r-- | src/keyword-list.cc | 2 | ||||
-rw-r--r-- | src/keyword-list.h | 4 | ||||
-rw-r--r-- | src/keyword.cc | 28 | ||||
-rw-r--r-- | src/keyword.h | 18 | ||||
-rw-r--r-- | src/options.cc | 232 | ||||
-rw-r--r-- | src/options.h | 36 | ||||
-rw-r--r-- | src/options.icc | 40 | ||||
-rw-r--r-- | src/output.cc | 210 | ||||
-rw-r--r-- | src/output.h | 26 | ||||
-rw-r--r-- | src/read-line.h | 4 | ||||
-rw-r--r-- | src/read-line.icc | 6 | ||||
-rw-r--r-- | src/vectors.cc | 6 | ||||
-rw-r--r-- | src/vectors.h | 8 |
23 files changed, 480 insertions, 475 deletions
@@ -1,5 +1,8 @@ 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. 2002-10-04 Bruno Haible <bruno@clisp.org> diff --git a/src/bool-array.cc b/src/bool-array.cc index e63d315..6041fcb 100644 --- a/src/bool-array.cc +++ b/src/bool-array.cc @@ -31,7 +31,7 @@ Bool_Array::~Bool_Array () if (option[DEBUG]) fprintf (stderr, "\ndumping boolean array information\n" "size = %d\niteration number = %d\nend of array dump\n", - size, iteration_number); + _size, _iteration_number); } #ifndef __OPTIMIZE__ diff --git a/src/bool-array.h b/src/bool-array.h index 01c0f08..45425d9 100644 --- a/src/bool-array.h +++ b/src/bool-array.h @@ -48,11 +48,11 @@ public: int set_bit (unsigned int index); private: - unsigned int size; /* Size of array. */ - unsigned int iteration_number; /* Number of times clear() was called + 1. */ + unsigned int _size; /* Size of array. */ + unsigned int _iteration_number; /* Number of times clear() was called + 1. */ /* For each index, we store in storage_array[index] the iteration_number at the time set_bit(index) was last called. */ - unsigned int *storage_array; + unsigned int *_storage_array; }; #ifdef __OPTIMIZE__ /* efficiency hack! */ diff --git a/src/bool-array.icc b/src/bool-array.icc index 24987a2..35eef84 100644 --- a/src/bool-array.icc +++ b/src/bool-array.icc @@ -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. */ INLINE 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]) 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). */ INLINE int 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. */ return 1; else { /* The last operation on this bit was clear(). Set it now. */ - storage_array[index] = iteration_number; + _storage_array[index] = _iteration_number; return 0; } } @@ -58,10 +58,10 @@ Bool_Array::clear () occurs once about every 2^32 iterations, so it will not happen more frequently than once per second. */ - if (++iteration_number == 0) + if (++_iteration_number == 0) { - iteration_number = 1; - memset (storage_array, 0, size * sizeof (unsigned int)); + _iteration_number = 1; + memset (_storage_array, 0, _size * sizeof (unsigned int)); if (option[DEBUG]) { fprintf (stderr, "(re-initialized bool_array)\n"); diff --git a/src/gen-perf.cc b/src/gen-perf.cc index cd44fd7..f1e3507 100644 --- a/src/gen-perf.cc +++ b/src/gen-perf.cc @@ -45,8 +45,8 @@ Gen_Perf::Gen_Perf () reorder (); asso_value_max = option.get_asso_max (); non_linked_length = Key_List::keyword_list_length (); - num_done = 1; - fewest_collisions = 0; + _num_done = 1; + _fewest_collisions = 0; if (asso_value_max == 0) asso_value_max = non_linked_length; else if (asso_value_max > 0) @@ -60,7 +60,7 @@ Gen_Perf::Gen_Perf () srand ((long) time (0)); 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 { @@ -68,16 +68,16 @@ Gen_Perf::Gen_Perf () if (asso_value) /* Initialize array if user requests non-zero default. */ 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 (); - collision_detector = new Bool_Array (max_hash_value + 1); + _collision_detector = new Bool_Array (_max_hash_value + 1); if (option[DEBUG]) fprintf (stderr, "total non-linked keys = %d\nmaximum associated value is %d" "\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. @@ -138,7 +138,7 @@ Gen_Perf::sort_set (char *union_set, int len) char tmp; 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--) union_set[curr] = union_set[curr - 1]; @@ -151,14 +151,14 @@ Gen_Perf::sort_set (char *union_set, int len) inline int 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; - int i = key_node->selchars_length; + const char *p = key_node->_selchars; + int i = key_node->_selchars_length; 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. @@ -170,7 +170,7 @@ Gen_Perf::hash (KeywordExt *key_node) inline int 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] ? 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; - asso_values[(unsigned char)c] = - (asso_values[(unsigned char)c] + (option.get_jump () ? option.get_jump () : rand ())) + _asso_values[(unsigned char)c] = + (_asso_values[(unsigned char)c] + (option.get_jump () ? option.get_jump () : rand ())) & (option.get_asso_max () - 1); /* 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 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(); - if (collision_detector->set_bit (hash (keyword)) - && ++collisions >= fewest_collisions) + if (_collision_detector->set_bit (hash (keyword)) + && ++collisions >= _fewest_collisions) break; if (keyword == curr) { - fewest_collisions = collisions; + _fewest_collisions = collisions; if (option[DEBUG]) fprintf (stderr, "- resolved after %d iterations", total_iterations - i); return 0; @@ -207,7 +207,7 @@ Gen_Perf::affects_prev (char c, KeywordExt *curr) } /* 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.... */ return 1; } @@ -226,17 +226,17 @@ Gen_Perf::change (KeywordExt *prior, KeywordExt *curr) if (option[DEBUG]) { fprintf (stderr, "collision on keyword #%d, prior = \"%.*s\", curr = \"%.*s\" hash = %d\n", - num_done, - prior->allchars_length, prior->allchars, - curr->allchars_length, curr->allchars, - curr->hash_value); + _num_done, + prior->_allchars_length, prior->_allchars, + curr->_allchars_length, curr->_allchars, + curr->_hash_value); 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); /* Try changing some values, if change doesn't alter other values continue normal action. */ - fewest_collisions++; + _fewest_collisions++; const char *p = union_set; int i = union_set_length; @@ -246,13 +246,13 @@ Gen_Perf::change (KeywordExt *prior, KeywordExt *curr) if (option[DEBUG]) { 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); } 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(); 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", !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); } } @@ -286,36 +286,36 @@ int Gen_Perf::doit_all () { KeywordExt_List *curr; - for (curr = head; curr != NULL; curr = curr->rest()) + for (curr = _head; curr != NULL; curr = curr->rest()) { KeywordExt *currkw = curr->first(); 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(); - if (ptrkw->hash_value == currkw->hash_value) + if (ptrkw->_hash_value == currkw->_hash_value) { change (ptrkw, currkw); break; } } - num_done++; + _num_done++; } /* 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()); - if (collision_detector->set_bit (hashcode)) + if (_collision_detector->set_bit (hashcode)) { if (option[DUP]) /* Keep track of this number... */ - total_duplicates++; + _total_duplicates++; else /* Yow, big problems. we're outta here! */ { fprintf (stderr, @@ -332,9 +332,9 @@ Gen_Perf::doit_all () processing turned out O.K. */ sort (); - Output outputter (head, array_type, return_type, struct_tag, additional_code, - include_src, total_keys, total_duplicates, max_key_len, - min_key_len, this); + Output outputter (_head, _array_type, _return_type, _struct_tag, _additional_code, + _include_src, _total_keys, _total_duplicates, _max_key_len, + _min_key_len, this); outputter.output (); return 0; } @@ -348,13 +348,13 @@ Gen_Perf::~Gen_Perf () fprintf (stderr, "\ndumping occurrence and associated values tables\n"); for (int i = 0; i < ALPHA_SIZE; i++) - if (occurrences[i]) + if (_occurrences[i]) 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"); } - delete collision_detector; + delete _collision_detector; } diff --git a/src/gen-perf.h b/src/gen-perf.h index e9ea402..ec5bae9 100644 --- a/src/gen-perf.h +++ b/src/gen-perf.h @@ -31,10 +31,10 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111, USA. */ class Gen_Perf : private Key_List { private: - int max_hash_value; /* Maximum possible hash value. */ - int fewest_collisions; /* Records fewest # of collisions for asso value. */ - int num_done; /* Number of keywords processed without a collision. */ - Bool_Array *collision_detector; + int _max_hash_value; /* Maximum possible hash value. */ + int _fewest_collisions; /* Records fewest # of collisions for asso value. */ + int _num_done; /* Number of keywords processed without a collision. */ + Bool_Array *_collision_detector; void change (KeywordExt *prior, KeywordExt *curr); int affects_prev (char c, KeywordExt *curr); diff --git a/src/hash-table.cc b/src/hash-table.cc index 4f171b6..c1ad090 100644 --- a/src/hash-table.cc +++ b/src/hash-table.cc @@ -35,9 +35,9 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111, USA. */ memory fragmentation, since we can now use alloca! */ 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 () @@ -50,15 +50,15 @@ Hash_Table::~Hash_Table () "\ndumping the hash table\n" "total available table slots = %d, total bytes = %d, total collisions = %d\n" "location, %*s, keyword\n", - size, size * (int) sizeof (*table), collisions, + _size, _size * (int) sizeof (*_table), _collisions, field_width, "keysig"); - for (int i = size - 1; i >= 0; i--) - if (table[i]) + for (int i = _size - 1; i >= 0; i--) + if (_table[i]) fprintf (stderr, "%8d, %*.*s, %.*s\n", i, - field_width, table[i]->selchars_length, table[i]->selchars, - table[i]->allchars_length, table[i]->allchars); + field_width, _table[i]->_selchars_length, _table[i]->_selchars, + _table[i]->_allchars_length, _table[i]->_allchars); fprintf (stderr, "\nend dumping hash table\n\n"); } @@ -71,21 +71,21 @@ Hash_Table::~Hash_Table () KeywordExt * Hash_Table::insert (KeywordExt *item) { - unsigned hash_val = hashpjw (item->selchars, item->selchars_length); - int probe = hash_val & (size - 1); - int increment = ((hash_val ^ item->allchars_length) | 1) & (size - 1); + unsigned hash_val = hashpjw (item->_selchars, item->_selchars_length); + int probe = hash_val & (_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 - && memcmp (table[probe]->selchars, item->selchars, item->selchars_length) == 0 - && (ignore_length || table[probe]->allchars_length == item->allchars_length)) - return table[probe]; + if (_table[probe]->_selchars_length == item->_selchars_length + && memcmp (_table[probe]->_selchars, item->_selchars, item->_selchars_length) == 0 + && (_ignore_length || _table[probe]->_allchars_length == item->_allchars_length)) + return _table[probe]; - collisions++; - probe = (probe + increment) & (size - 1); + _collisions++; + probe = (probe + increment) & (_size - 1); } - table[probe] = item; + _table[probe] = item; return NULL; } diff --git a/src/hash-table.h b/src/hash-table.h index 61a976e..c0cbee4 100644 --- a/src/hash-table.h +++ b/src/hash-table.h @@ -29,10 +29,10 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111, USA. */ class Hash_Table { private: - KeywordExt **table; /* Vector of pointers to linked lists of keywords. */ - int size; /* Size of the vector. */ - int collisions; /* Find out how well our double hashing is working! */ - int ignore_length; + KeywordExt **_table; /* Vector of pointers to linked lists of keywords. */ + int _size; /* Size of the vector. */ + int _collisions; /* Find out how well our double hashing is working! */ + int _ignore_length; public: Hash_Table (KeywordExt **t, int s, int ignore_len); diff --git a/src/key-list.cc b/src/key-list.cc index e430c75..a865e91 100644 --- a/src/key-list.cc +++ b/src/key-list.cc @@ -33,7 +33,7 @@ static const int TABLE_MULTIPLE = 10; /* 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))) -int Key_List::determined[MAX_ALPHA_SIZE]; +int Key_List::_determined[MAX_ALPHA_SIZE]; /* 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" "\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 (); fprintf (stderr, "End dumping list.\n\n"); } @@ -171,32 +171,32 @@ Key_List::set_output_types () { if (option[TYPE]) { - array_type = get_array_type (); - if (!array_type) + _array_type = get_array_type (); + if (!_array_type) /* Something's wrong, but we'll catch it later on, in read_keys()... */ return; /* 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. */ - while (i > 0 && strchr (" \t", array_type[i-1])) + while (i > 0 && strchr (" \t", _array_type[i-1])) i--; int struct_tag_length = i; /* Set `struct_tag' to a naked "struct something". */ 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'; - struct_tag = structtag; + _struct_tag = structtag; /* The return type of the lookup function is "struct something *". No "const" here, because if !option[CONST], some user code might want to modify the structure. */ 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 + 1] = '*'; rettype[struct_tag_length + 2] = '\0'; - return_type = rettype; + _return_type = rettype; } } @@ -348,7 +348,7 @@ Key_List::read_keys () { char *ptr; - include_src = save_include_src (); + _include_src = save_include_src (); set_output_types (); /* Oops, problem with the input file. */ @@ -365,24 +365,24 @@ Key_List::read_keys () KeywordExt_List *temp; KeywordExt_List *trail = NULL; - head = parse_line (ptr, delimiter); - head->first()->init_selchars(this); + _head = parse_line (ptr, delimiter); + _head->first()->init_selchars(this); - for (temp = head; + for (temp = _head; (ptr = Read_Line::read_next_line ()) && strcmp (ptr, "%%"); temp = temp->rest()) { temp->rest() = parse_line (ptr, delimiter); temp->rest()->first()->init_selchars(this); - total_keys++; + _total_keys++; } /* See if any additional C code is included at end of this file. */ if (ptr) - additional_code = 1; + _additional_code = 1; /* 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. */ 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 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 *other_keyword = found_link.insert (keyword); @@ -404,53 +404,53 @@ Key_List::read_keys () if (other_keyword) { - total_duplicates++; - list_len--; + _total_duplicates++; + _list_len--; trail->rest() = temp->rest(); - temp->first()->duplicate_link = other_keyword->duplicate_link; - other_keyword->duplicate_link = temp->first(); + temp->first()->_duplicate_link = other_keyword->_duplicate_link; + other_keyword->_duplicate_link = temp->first(); /* Complain if user hasn't enabled the duplicate option. */ if (!option[DUP] || option[DEBUG]) fprintf (stderr, "Key link: \"%.*s\" = \"%.*s\", with key set \"%.*s\".\n", - keyword->allchars_length, keyword->allchars, - other_keyword->allchars_length, other_keyword->allchars, - keyword->selchars_length, keyword->selchars); + keyword->_allchars_length, keyword->_allchars, + other_keyword->_allchars_length, other_keyword->_allchars, + keyword->_selchars_length, keyword->_selchars); } else trail = temp; /* Update minimum and maximum keyword length, if needed. */ - if (max_key_len < keyword->allchars_length) - max_key_len = keyword->allchars_length; - if (min_key_len > keyword->allchars_length) - min_key_len = keyword->allchars_length; + if (_max_key_len < keyword->_allchars_length) + _max_key_len = keyword->_allchars_length; + if (_min_key_len > keyword->_allchars_length) + _min_key_len = keyword->_allchars_length; } delete[] table; /* Exit program if links exists and option[DUP] not set, since we can't continue */ - if (total_duplicates) + if (_total_duplicates) { if (option[DUP]) fprintf (stderr, "%d input keys have identical hash values, examine output carefully...\n", - total_duplicates); + _total_duplicates); else { 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 program if an empty string is used as key, since the comparison 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"); exit (1); } 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; break; } - if (occurrence_sort && list1->first()->occurrence < list2->first()->occurrence - || hash_sort && list1->first()->hash_value > list2->first()->hash_value) + if (_occurrence_sort && list1->first()->_occurrence < list2->first()->_occurrence + || _hash_sort && list1->first()->_hash_value > list2->first()->_hash_value) { *resultp = list2; resultp = &list2->rest(); list2 = list1; list1 = *resultp; @@ -526,10 +526,10 @@ Key_List::get_occurrence (KeywordExt *ptr) { int value = 0; - const char *p = ptr->selchars; - unsigned int i = ptr->selchars_length; + const char *p = ptr->_selchars; + unsigned int i = ptr->_selchars_length; for (; i > 0; p++, i--) - value += occurrences[(unsigned char)(*p)]; + value += _occurrences[(unsigned char)(*p)]; return value; } @@ -540,10 +540,10 @@ Key_List::get_occurrence (KeywordExt *ptr) inline void Key_List::set_determined (KeywordExt *ptr) { - const char *p = ptr->selchars; - unsigned int i = ptr->selchars_length; + const char *p = ptr->_selchars; + unsigned int i = ptr->_selchars_length; 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. */ @@ -553,10 +553,10 @@ Key_List::already_determined (KeywordExt *ptr) { int is_determined = 1; - const char *p = ptr->selchars; - unsigned int i = ptr->selchars_length; + const char *p = ptr->_selchars; + unsigned int i = ptr->_selchars_length; for (; is_determined && i > 0; p++, i--) - is_determined = determined[(unsigned char)(*p)]; + is_determined = _determined[(unsigned char)(*p)]; return is_determined; } @@ -571,19 +571,19 @@ void Key_List::reorder () { KeywordExt_List *ptr; - for (ptr = head; ptr; ptr = ptr->rest()) + for (ptr = _head; ptr; ptr = ptr->rest()) { KeywordExt *keyword = ptr->first(); - keyword->occurrence = get_occurrence (keyword); + keyword->_occurrence = get_occurrence (keyword); } - hash_sort = 0; - occurrence_sort = 1; + _hash_sort = 0; + _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()); @@ -613,10 +613,10 @@ Key_List::reorder () void Key_List::sort () { - hash_sort = 1; - occurrence_sort = 0; + _hash_sort = 1; + _occurrence_sort = 0; - head = merge_sort (head); + _head = merge_sort (_head); } /* 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", 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", - ptr->first()->hash_value, ptr->first()->allchars_length, ptr->first()->final_index, - field_width, ptr->first()->selchars_length, ptr->first()->selchars, - ptr->first()->allchars_length, ptr->first()->allchars); + ptr->first()->_hash_value, ptr->first()->_allchars_length, ptr->first()->_final_index, + field_width, ptr->first()->_selchars_length, ptr->first()->_selchars, + ptr->first()->_allchars_length, ptr->first()->_allchars); } /* Simple-minded constructor action here... */ Key_List::Key_List () { - total_keys = 1; - max_key_len = INT_MIN; - min_key_len = INT_MAX; - array_type = 0; - return_type = 0; - struct_tag = 0; - head = 0; - total_duplicates = 0; - additional_code = 0; + _total_keys = 1; + _max_key_len = INT_MIN; + _min_key_len = INT_MAX; + _array_type = 0; + _return_type = 0; + _struct_tag = 0; + _head = 0; + _total_duplicates = 0; + _additional_code = 0; } /* Returns the length of entire key list. */ @@ -656,7 +656,7 @@ Key_List::Key_List () int Key_List::keyword_list_length () { - return list_len; + return _list_len; } /* Returns length of longest key read. */ @@ -664,6 +664,6 @@ Key_List::keyword_list_length () int Key_List::max_key_length () { - return max_key_len; + return _max_key_len; } diff --git a/src/key-list.h b/src/key-list.h index c0cdbc5..54b94ad 100644 --- a/src/key-list.h +++ b/src/key-list.h @@ -36,23 +36,23 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111, USA. */ class Key_List : private Read_Line, public Vectors { protected: - const char *array_type; /* Pointer to the type for word list. */ - const char *return_type; /* Pointer to return type for lookup function. */ - const char *struct_tag; /* Shorthand for user-defined struct tag type. */ - const char *include_src; /* C source code to be included verbatim. */ - int max_key_len; /* Maximum length of the longest keyword. */ - int min_key_len; /* Minimum length of the shortest keyword. */ + const char *_array_type; /* Pointer to the type for word list. */ + const char *_return_type; /* Pointer to return type for lookup function. */ + const char *_struct_tag; /* Shorthand for user-defined struct tag type. */ + const char *_include_src; /* C source code to be included verbatim. */ + int _max_key_len; /* Maximum length of the longest keyword. */ + int _min_key_len; /* Minimum length of the shortest keyword. */ private: - int occurrence_sort; /* True if sorting by occurrence. */ - int hash_sort; /* True if sorting by hash value. */ + int _occurrence_sort; /* True if sorting by occurrence. */ + int _hash_sort; /* True if sorting by hash value. */ protected: - int additional_code; /* True if any additional C code is included. */ + int _additional_code; /* True if any additional C code is included. */ 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: - int total_keys; /* Total number of keys, counting duplicates. */ + int _total_keys; /* Total number of keys, counting duplicates. */ 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); #ifndef strcspn static int strcspn (const char *s, const char *reject); @@ -68,8 +68,8 @@ private: KeywordExt_List *merge_sort (KeywordExt_List *head); protected: - KeywordExt_List *head; /* Points to the head of the linked list. */ - int total_duplicates; /* Total number of duplicate hash values. */ + KeywordExt_List *_head; /* Points to the head of the linked list. */ + int _total_duplicates; /* Total number of duplicate hash values. */ public: Key_List (); diff --git a/src/keyword-list.cc b/src/keyword-list.cc index 38c957a..8aae7f9 100644 --- a/src/keyword-list.cc +++ b/src/keyword-list.cc @@ -24,6 +24,6 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111, USA. */ /* Constructor. */ 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) { } diff --git a/src/keyword-list.h b/src/keyword-list.h index 3b49e4e..d43fba4 100644 --- a/src/keyword-list.h +++ b/src/keyword-list.h @@ -35,10 +35,10 @@ public: /* Access to first element of list. */ KeywordExt* first () { return this; } /* Access to next element of list. */ - KeywordExt_List *& rest () { return cdr; } + KeywordExt_List *& rest () { return _cdr; } private: - KeywordExt_List * cdr; + KeywordExt_List * _cdr; }; #endif diff --git a/src/keyword.cc b/src/keyword.cc index 2d04c90..8d6f77d 100644 --- a/src/keyword.cc +++ b/src/keyword.cc @@ -29,7 +29,7 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111, USA. */ /* Constructor. */ 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. */ 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. */ void KeywordExt::init_selchars (Vectors *v) { - const char *k = allchars; + const char *k = _allchars; 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; int i; if (option[ALLCHARS]) /* Use all the character positions in the KEY. */ - for (i = allchars_length; i > 0; k++, ptr++, i--) - v->occurrences[(unsigned char)(*ptr = *k)]++; + for (i = _allchars_length; i > 0; k++, ptr++, i--) + v->_occurrences[(unsigned char)(*ptr = *k)]++; else /* Only use those character positions specified by the user. */ { @@ -81,23 +81,23 @@ void KeywordExt::init_selchars (Vectors *v) { if (i == WORD_END) /* Special notation for last KEY position, i.e. '$'. */ - *ptr = allchars[allchars_length - 1]; - else if (i <= allchars_length) + *ptr = _allchars[_allchars_length - 1]; + else if (i <= _allchars_length) /* Within range of KEY length, so we'll keep it. */ - *ptr = allchars[i - 1]; + *ptr = _allchars[i - 1]; else /* Out of range of KEY length, so we'll just skip it. */ continue; - v->occurrences[(unsigned char)*ptr]++; + v->_occurrences[(unsigned char)*ptr]++; ptr++; } /* Didn't get any hits and user doesn't want to consider the 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", - allchars_length, allchars); + _allchars_length, _allchars); exit (1); } } @@ -105,8 +105,8 @@ void KeywordExt::init_selchars (Vectors *v) /* Sort the KEY_SET items alphabetically. */ sort_char_set (key_set, ptr - key_set); - selchars = key_set; - selchars_length = ptr - key_set; + _selchars = key_set; + _selchars_length = ptr - key_set; } diff --git a/src/keyword.h b/src/keyword.h index 2f9d7de..e5f8bb7 100644 --- a/src/keyword.h +++ b/src/keyword.h @@ -34,10 +34,10 @@ struct Keyword /* Data members defined immediately by the input file. */ /* The keyword as a string, possibly containing NUL bytes. */ - const char *const allchars; - const int allchars_length; + const char *const _allchars; + const int _allchars_length; /* 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. */ @@ -49,21 +49,21 @@ struct KeywordExt : public Keyword /* Data members depending on the keyposition list. */ /* The selected characters that participate for the hash function, reordered according to the keyposition list. */ - const char * selchars; - int selchars_length; + const char * _selchars; + int _selchars_length; /* Chained list of keywords having the same selchars. */ - KeywordExt * duplicate_link; + KeywordExt * _duplicate_link; /* Methods depending on the keyposition list. */ /* Initialize selchars and selchars_length, and update v->occurrences. */ void init_selchars (Vectors *v); /* Data members used by the algorithm. */ - int occurrence; /* A metric for frequency of key set occurrences. */ - int hash_value; /* Hash value for the key. */ + int _occurrence; /* A metric for frequency of key set occurrences. */ + int _hash_value; /* Hash value for the key. */ /* Data members used by the output routines. */ - int final_index; + int _final_index; }; /* A factory for creating Keyword instances. */ diff --git a/src/options.cc b/src/options.cc index 3d1a97c..583e822 100644 --- a/src/options.cc +++ b/src/options.cc @@ -57,24 +57,24 @@ static const char *const DEFAULT_WORDLIST_NAME = "wordlist"; /* Default delimiters that separate keywords from their attributes. */ static const char *const DEFAULT_DELIMITERS = ",\n"; -int Options::option_word; -int Options::total_switches; -int Options::total_keysig_size; -int Options::size; -int Options::key_pos; -int Options::jump; -int Options::initial_asso_value; -int Options::argument_count; -int Options::iterations; -char **Options::argument_vector; -const char *Options::function_name; -const char *Options::key_name; -const char *Options::initializer_suffix; -const char *Options::class_name; -const char *Options::hash_name; -const char *Options::wordlist_name; -const char *Options::delimiters; -char Options::key_positions[MAX_KEY_POS]; +int Options::_option_word; +int Options::_total_switches; +int Options::_total_keysig_size; +int Options::_size; +int Options::_key_pos; +int Options::_jump; +int Options::_initial_asso_value; +int Options::_argument_count; +int Options::_iterations; +char **Options::_argument_vector; +const char *Options::_function_name; +const char *Options::_key_name; +const char *Options::_initializer_suffix; +const char *Options::_class_name; +const char *Options::_hash_name; +const char *Options::_wordlist_name; +const char *Options::_delimiters; +char Options::_key_positions[MAX_KEY_POS]; /* Prints program usage to given stream. */ @@ -224,9 +224,9 @@ Options::print_options () 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. */ if (*arg == '-') @@ -365,28 +365,30 @@ Options::key_sort (char *base, int len) Options::Options () { - key_positions[0] = WORD_START; - key_positions[1] = WORD_END; - key_positions[2] = EOS; - total_keysig_size = 2; - delimiters = DEFAULT_DELIMITERS; - jump = DEFAULT_JUMP_VALUE; - option_word = DEFAULTCHARS | C; - function_name = DEFAULT_NAME; - key_name = DEFAULT_KEY; - initializer_suffix = DEFAULT_INITIALIZER_SUFFIX; - hash_name = DEFAULT_HASH_NAME; - wordlist_name = DEFAULT_WORDLIST_NAME; - class_name = DEFAULT_CLASS_NAME; - total_switches = size = 1; - initial_asso_value = iterations = 0; + _key_positions[0] = WORD_START; + _key_positions[1] = WORD_END; + _key_positions[2] = EOS; + _total_keysig_size = 2; + _delimiters = DEFAULT_DELIMITERS; + _jump = DEFAULT_JUMP_VALUE; + _option_word = DEFAULTCHARS | C; + _function_name = DEFAULT_NAME; + _key_name = DEFAULT_KEY; + _initializer_suffix = DEFAULT_INITIALIZER_SUFFIX; + _hash_name = DEFAULT_HASH_NAME; + _wordlist_name = DEFAULT_WORDLIST_NAME; + _class_name = DEFAULT_CLASS_NAME; + _size = 1; + _total_switches = 1; + _iterations = 0; + _initial_asso_value = 0; } /* Dumps option status when debug is set. */ Options::~Options () { - if (option_word & DEBUG) + if (_option_word & DEBUG) { char *ptr; @@ -423,38 +425,38 @@ Options::~Options () "\ninitial associated value = %d" "\ndelimiters = %s" "\nnumber of switch statements = %d\n", - option_word & DEBUG ? "enabled" : "disabled", - option_word & ORDER ? "enabled" : "disabled", - option_word & TYPE ? "enabled" : "disabled", - option_word & RANDOM ? "enabled" : "disabled", - option_word & DEFAULTCHARS ? "enabled" : "disabled", - option_word & SWITCH ? "enabled" : "disabled", - option_word & NOLENGTH ? "enabled" : "disabled", - option_word & LENTABLE ? "enabled" : "disabled", - option_word & DUP ? "enabled" : "disabled", - option_word & FAST ? "enabled" : "disabled", - option_word & COMP ? "enabled" : "disabled", - option_word & NOTYPE ? "enabled" : "disabled", - option_word & GLOBAL ? "enabled" : "disabled", - option_word & CONST ? "enabled" : "disabled", - option_word & KRC ? "enabled" : "disabled", - option_word & C ? "enabled" : "disabled", - option_word & ANSIC ? "enabled" : "disabled", - option_word & CPLUSPLUS ? "enabled" : "disabled", - option_word & ENUM ? "enabled" : "disabled", - option_word & INCLUDE ? "enabled" : "disabled", - option_word & SEVENBIT ? "enabled" : "disabled", - iterations, - function_name, hash_name, wordlist_name, key_name, - initializer_suffix, jump, size - 1, initial_asso_value, - delimiters, total_switches); - if (option_word & ALLCHARS) + _option_word & DEBUG ? "enabled" : "disabled", + _option_word & ORDER ? "enabled" : "disabled", + _option_word & TYPE ? "enabled" : "disabled", + _option_word & RANDOM ? "enabled" : "disabled", + _option_word & DEFAULTCHARS ? "enabled" : "disabled", + _option_word & SWITCH ? "enabled" : "disabled", + _option_word & NOLENGTH ? "enabled" : "disabled", + _option_word & LENTABLE ? "enabled" : "disabled", + _option_word & DUP ? "enabled" : "disabled", + _option_word & FAST ? "enabled" : "disabled", + _option_word & COMP ? "enabled" : "disabled", + _option_word & NOTYPE ? "enabled" : "disabled", + _option_word & GLOBAL ? "enabled" : "disabled", + _option_word & CONST ? "enabled" : "disabled", + _option_word & KRC ? "enabled" : "disabled", + _option_word & C ? "enabled" : "disabled", + _option_word & ANSIC ? "enabled" : "disabled", + _option_word & CPLUSPLUS ? "enabled" : "disabled", + _option_word & ENUM ? "enabled" : "disabled", + _option_word & INCLUDE ? "enabled" : "disabled", + _option_word & SEVENBIT ? "enabled" : "disabled", + _iterations, + _function_name, _hash_name, _wordlist_name, _key_name, + _initializer_suffix, _jump, _size - 1, _initial_asso_value, + _delimiters, _total_switches); + if (_option_word & ALLCHARS) fprintf (stderr, "all characters are used in the hash function\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) fprintf (stderr, "$\n"); else @@ -508,11 +510,11 @@ Options::operator() (int argc, char *argv[]) int option_char; program_name = argv[0]; - argument_count = argc; - argument_vector = argv; + _argument_count = argc; + _argument_vector = argv; 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", long_options, NULL)) != -1) @@ -523,56 +525,56 @@ Options::operator() (int argc, char *argv[]) break; /* This is now the default. */ case 'c': /* Generate strncmp rather than strcmp. */ { - option_word |= COMP; + _option_word |= COMP; break; } case 'C': /* Make the generated tables readonly (const). */ { - option_word |= CONST; + _option_word |= CONST; break; } case 'd': /* Enable debugging option. */ { - option_word |= DEBUG; + _option_word |= DEBUG; fprintf (stderr, "Starting program %s, version %s, with debugging on.\n", program_name, version_string); break; } case 'D': /* Enable duplicate option. */ { - option_word |= DUP; + _option_word |= DUP; break; } case 'e': /* Allows user to provide keyword/attribute separator */ { - option.delimiters = /*getopt*/optarg; + _delimiters = /*getopt*/optarg; break; } case 'E': { - option_word |= ENUM; + _option_word |= ENUM; break; } case 'f': /* Generate the hash table ``fast.'' */ { - option_word |= FAST; - if ((iterations = atoi (/*getopt*/optarg)) < 0) + _option_word |= FAST; + if ((_iterations = atoi (/*getopt*/optarg)) < 0) { fprintf (stderr, "iterations value must not be negative, assuming 0\n"); - iterations = 0; + _iterations = 0; } break; } case 'F': { - initializer_suffix = /*getopt*/optarg; + _initializer_suffix = /*getopt*/optarg; break; } case 'g': /* Use the ``inline'' keyword for generated sub-routines, ifdef __GNUC__. */ break; /* This is now the default. */ case 'G': /* Make the keyword table a global variable. */ { - option_word |= GLOBAL; + _option_word |= GLOBAL; break; } 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 */ { - hash_name = /*getopt*/optarg; + _hash_name = /*getopt*/optarg; break; } case 'i': /* Sets the initial value for the associated values array. */ { - if ((initial_asso_value = atoi (/*getopt*/optarg)) < 0) - fprintf (stderr, "Initial value %d should be non-zero, ignoring and continuing.\n", initial_asso_value); + if ((_initial_asso_value = atoi (/*getopt*/optarg)) < 0) + fprintf (stderr, "Initial value %d should be non-zero, ignoring and continuing.\n", _initial_asso_value); if (option[RANDOM]) fprintf (stderr, "warning, -r option superceeds -i, ignoring -i option and continuing\n"); break; } case 'I': /* Enable #include statements. */ { - option_word |= INCLUDE; + _option_word |= INCLUDE; break; } 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); exit (1); } - else if (jump && ((jump % 2) == 0)) - fprintf (stderr, "Jump value %d should be odd, adding 1 and continuing...\n", jump++); + else if (_jump && ((_jump % 2) == 0)) + fprintf (stderr, "Jump value %d should be odd, adding 1 and continuing...\n", _jump++); break; } 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); if (/*getopt*/optarg [0] == '*') /* Use all the characters for hashing!!!! */ - option_word = (option_word & ~DEFAULTCHARS) | ALLCHARS; + _option_word = (_option_word & ~DEFAULTCHARS) | ALLCHARS; else { 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) { 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; - if (! (total_keysig_size = (key_pos - key_positions))) + if (! (_total_keysig_size = (key_pos - _key_positions))) { fprintf (stderr, "No keys selected.\n"); short_usage (stderr); 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"); short_usage (stderr); exit (1); } - if (total_keysig_size != 2 - || (key_positions[0] != 1 || key_positions[1] != WORD_END)) - option_word &= ~DEFAULTCHARS; + if (_total_keysig_size != 2 + || (_key_positions[0] != 1 || _key_positions[1] != WORD_END)) + _option_word &= ~DEFAULTCHARS; } break; } case 'K': /* Make this the keyname for the keyword component field. */ { - key_name = /*getopt*/optarg; + _key_name = /*getopt*/optarg; break; } case 'l': /* Create length table to avoid extra string compares. */ { - option_word |= LENTABLE; + _option_word |= LENTABLE; break; } 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")) - option_word |= KRC; + _option_word |= KRC; else if (!strcmp (/*getopt*/optarg, "C")) - option_word |= C; + _option_word |= C; else if (!strcmp (/*getopt*/optarg, "ANSI-C")) - option_word |= ANSIC; + _option_word |= ANSIC; else if (!strcmp (/*getopt*/optarg, "C++")) - option_word |= CPLUSPLUS; + _option_word |= CPLUSPLUS; else { fprintf (stderr, "unsupported language option %s, defaulting to C\n", /*getopt*/optarg); - option_word |= C; + _option_word |= C; } break; } case 'n': /* Don't include the length when computing hash function. */ { - option_word |= NOLENGTH; + _option_word |= NOLENGTH; break; } case 'N': /* Make generated lookup function name be optarg */ { - function_name = /*getopt*/optarg; + _function_name = /*getopt*/optarg; break; } case 'o': /* Order input by frequency of key set occurrence. */ { - option_word |= ORDER; + _option_word |= ORDER; break; } case 'p': /* Generated lookup function a pointer instead of int. */ break; /* This is now the default. */ case 'r': /* Utilize randomness to initialize the associated values table. */ { - option_word |= RANDOM; - if (option.initial_asso_value != 0) + _option_word |= RANDOM; + if (_initial_asso_value != 0) fprintf (stderr, "warning, -r option superceeds -i, disabling -i option and continuing\n"); break; } case 's': /* Range of associated values, determines size of final table. */ { - 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); + 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); break; } case 'S': /* Generate switch statement output, rather than lookup table. */ { - option_word |= SWITCH; - if ((option.total_switches = atoi (/*getopt*/optarg)) <= 0) + _option_word |= SWITCH; + if ((_total_switches = atoi (/*getopt*/optarg)) <= 0) { fprintf (stderr, "number of switches %s must be a positive number\n", /*getopt*/optarg); short_usage (stderr); @@ -725,12 +727,12 @@ Options::operator() (int argc, char *argv[]) } case 't': /* Enable the TYPE mode, allowing arbitrary user structures. */ { - option_word |= TYPE; + _option_word |= TYPE; break; } case 'T': /* Don't print structure definition. */ { - option_word |= NOTYPE; + _option_word |= NOTYPE; break; } case 'v': /* Print out the version and quit. */ @@ -738,17 +740,17 @@ Options::operator() (int argc, char *argv[]) exit (0); case 'W': /* Sets the name for the hash table array */ { - wordlist_name = /*getopt*/optarg; + _wordlist_name = /*getopt*/optarg; break; } case 'Z': /* Set the class name. */ { - class_name = /*getopt*/optarg; + _class_name = /*getopt*/optarg; break; } case '7': /* Assume 7-bit characters. */ { - option_word |= SEVENBIT; + _option_word |= SEVENBIT; Vectors::ALPHA_SIZE = 128; break; } diff --git a/src/options.h b/src/options.h index ede3058..bcfad96 100644 --- a/src/options.h +++ b/src/options.h @@ -105,24 +105,24 @@ public: static const char *get_delimiter (); private: - static int option_word; /* Holds the user-specified Options. */ - static int total_switches; /* Number of switch statements to generate. */ - static int total_keysig_size; /* Total number of distinct key_positions. */ - static int size; /* Range of the hash table. */ - static int key_pos; /* Tracks current key position for Iterator. */ - static int jump; /* Jump length when trying alternative values. */ - static int initial_asso_value; /* Initial value for asso_values table. */ - static int argument_count; /* Records count of command-line arguments. */ - static int iterations; /* Amount to iterate when a collision occurs. */ - 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 *key_name; /* Name used for keyword key. */ - static const char *initializer_suffix; /* Suffix for empty struct initializers. */ - 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 *wordlist_name; /* Name used for hash table array. */ - static const char *delimiters; /* Separates keywords from other attributes. */ - static char key_positions[MAX_KEY_POS]; /* Contains user-specified key choices. */ + static int _option_word; /* Holds the user-specified Options. */ + static int _total_switches; /* Number of switch statements to generate. */ + static int _total_keysig_size; /* Total number of distinct key_positions. */ + static int _size; /* Range of the hash table. */ + static int _key_pos; /* Tracks current key position for Iterator. */ + static int _jump; /* Jump length when trying alternative values. */ + static int _initial_asso_value; /* Initial value for asso_values table. */ + static int _argument_count; /* Records count of command-line arguments. */ + static int _iterations; /* Amount to iterate when a collision occurs. */ + 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 *_key_name; /* Name used for keyword key. */ + static const char *_initializer_suffix; /* Suffix for empty struct initializers. */ + 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 *_wordlist_name; /* Name used for hash table array. */ + static const char *_delimiters; /* Separates keywords from other attributes. */ + 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 void short_usage (FILE * strm); /* Prints proper program usage. */ static void long_usage (FILE * strm); /* Prints proper program usage. */ diff --git a/src/options.icc b/src/options.icc index 1fb9d98..1470411 100644 --- a/src/options.icc +++ b/src/options.icc @@ -23,138 +23,138 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111, USA. */ INLINE int Options::operator[] (Option_Type option) { - return option_word & option; + return _option_word & option; } /* Enables option OPT. */ INLINE void Options::operator = (enum Option_Type opt) { - option_word |= opt; + _option_word |= opt; } /* Disables option OPT. */ INLINE void Options::operator != (enum Option_Type opt) { - option_word &= ~opt; + _option_word &= ~opt; } /* Initializes the key Iterator. */ INLINE void Options::reset () { - key_pos = 0; + _key_pos = 0; } /* Returns current key_position and advance index. */ INLINE int Options::get () { - return key_positions[key_pos++]; + return _key_positions[_key_pos++]; } /* Sets the size of the table size. */ INLINE void Options::set_asso_max (int r) { - size = r; + _size = r; } /* Returns the size of the table size. */ INLINE int Options::get_asso_max () { - return size; + return _size; } /* Returns total distinct key positions. */ INLINE int Options::get_max_keysig_size () { - return total_keysig_size; + return _total_keysig_size; } /* Sets total distinct key positions. */ INLINE void Options::set_keysig_size (int size) { - total_keysig_size = size; + _total_keysig_size = size; } /* Returns the jump value. */ INLINE int Options::get_jump () { - return jump; + return _jump; } /* Returns the generated function name. */ INLINE const char * Options::get_function_name () { - return function_name; + return _function_name; } /* Returns the keyword key name. */ INLINE const char * Options::get_key_name () { - return key_name; + return _key_name; } /* Returns the struct initializer suffix. */ INLINE const char * Options::get_initializer_suffix () { - return initializer_suffix; + return _initializer_suffix; } /* Returns the hash function name. */ INLINE const char * Options::get_hash_name () { - return hash_name; + return _hash_name; } /* Returns the hash table array name. */ INLINE const char * Options::get_wordlist_name () { - return wordlist_name; + return _wordlist_name; } /* Returns the generated class name. */ INLINE const char * Options::get_class_name () { - return class_name; + return _class_name; } /* Returns the initial associated character value. */ INLINE int Options::initial_value () { - return initial_asso_value; + return _initial_asso_value; } /* Returns the iterations value. */ INLINE int Options::get_iterations () { - return iterations; + return _iterations; } /* Returns the string used to delimit keywords from other attributes. */ INLINE const char * Options::get_delimiter () { - return delimiters; + return _delimiters; } /* Gets the total number of switch statements to generate. */ INLINE int Options::get_total_switches () { - return total_switches; + return _total_switches; } diff --git a/src/output.cc b/src/output.cc index 82c59bc..8265732 100644 --- a/src/output.cc +++ b/src/output.cc @@ -70,11 +70,11 @@ Output::Output (KeywordExt_List *head_, const char *array_type_, int additional_code_, const char *include_src_, int total_keys_, int total_duplicates_, int max_key_len_, int min_key_len_, Vectors *v_) - : head (head_), array_type (array_type_), return_type (return_type_), - struct_tag (struct_tag_), additional_code (additional_code_), - include_src (include_src_), total_keys (total_keys_), - total_duplicates (total_duplicates_), max_key_len (max_key_len_), - min_key_len (min_key_len_), v (v_) + : _head (head_), _array_type (array_type_), _return_type (return_type_), + _struct_tag (struct_tag_), _additional_code (additional_code_), + _include_src (include_src_), _total_keys (total_keys_), + _total_duplicates (total_duplicates_), _max_key_len (max_key_len_), + _min_key_len (min_key_len_), _v (v_) { } @@ -88,11 +88,11 @@ void Output::compute_min_max () { 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; - max_hash_value = temp->first()->hash_value; + _min_hash_value = _head->first()->_hash_value; + _max_hash_value = temp->first()->_hash_value; } /* ------------------------------------------------------------------------- */ @@ -106,11 +106,11 @@ Output::num_hash_values () KeywordExt_List *temp; 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++; } } @@ -198,11 +198,11 @@ void Output::output_constants (struct Output_Constants& style) { style.output_start (); - style.output_item ("TOTAL_KEYWORDS", total_keys); - style.output_item ("MIN_WORD_LENGTH", min_key_len); - style.output_item ("MAX_WORD_LENGTH", max_key_len); - style.output_item ("MIN_HASH_VALUE", min_hash_value); - style.output_item ("MAX_HASH_VALUE", max_hash_value); + style.output_item ("TOTAL_KEYWORDS", _total_keys); + style.output_item ("MIN_WORD_LENGTH", _min_key_len); + style.output_item ("MAX_WORD_LENGTH", _max_key_len); + style.output_item ("MIN_HASH_VALUE", _min_hash_value); + style.output_item ("MAX_HASH_VALUE", _max_hash_value); style.output_end (); } @@ -407,7 +407,7 @@ Output::output_hash_function () /* Calculate maximum number of digits required for MAX_HASH_VALUE. */ field_width = 2; - for (int trunc = max_hash_value; (trunc /= 10) > 0;) + for (int trunc = _max_hash_value; (trunc /= 10) > 0;) field_width++; /* Output the function's head. */ @@ -450,16 +450,16 @@ Output::output_hash_function () printf (" static %s%s asso_values[] =\n" " {", 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) printf (","); if (!(count % max_column)) printf ("\n "); 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" @@ -479,7 +479,7 @@ Output::output_hash_function () /* Get first (also highest) key position. */ 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: 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. */ 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" " hval += asso_values[%sstr[%d]];\n", i, char_to_index, i - 1); @@ -527,7 +527,7 @@ Output::output_hash_function () } 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) break; @@ -546,7 +546,7 @@ Output::output_hash_function () } 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); } @@ -578,23 +578,23 @@ Output::output_keylength_table () printf ("%sstatic %s%s lengthtable[] =\n%s {", indent, const_readonly_array, - smallest_integral_type (max_key_len), + smallest_integral_type (_max_key_len), indent); /* Generate an array of lengths, similar to output_keyword_table. */ 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] - && !(temp->first()->duplicate_link - || (temp->rest() && temp->first()->hash_value == temp->rest()->first()->hash_value))) + && !(temp->first()->_duplicate_link + || (temp->rest() && temp->first()->_hash_value == temp->rest()->first()->_hash_value))) continue; - if (index < temp->first()->hash_value && !option[SWITCH] && !option[DUP]) + if (index < temp->first()->_hash_value && !option[SWITCH] && !option[DUP]) { /* Some blank entries. */ - for ( ; index < temp->first()->hash_value; index++) + for ( ; index < temp->first()->_hash_value; index++) { if (index > 0) printf (","); @@ -608,17 +608,17 @@ Output::output_keylength_table () printf (","); if ((column++ % columns) == 0) printf("\n%s ", indent); - printf ("%3d", temp->first()->allchars_length); + printf ("%3d", temp->first()->_allchars_length); /* Deal with links specially. */ - if (temp->first()->duplicate_link) // implies option[DUP] - for (KeywordExt *links = temp->first()->duplicate_link; links; links = links->duplicate_link) + if (temp->first()->_duplicate_link) // implies option[DUP] + for (KeywordExt *links = temp->first()->_duplicate_link; links; links = links->_duplicate_link) { ++index; printf (","); if ((column++ % columns) == 0) printf("\n%s ", indent); - printf ("%3d", links->allchars_length); + printf ("%3d", links->_allchars_length); } index++; @@ -637,16 +637,16 @@ output_keyword_entry (KeywordExt *temp, const char *indent) printf ("%s ", indent); if (option[TYPE]) printf ("{"); - output_string (temp->allchars, temp->allchars_length); + output_string (temp->_allchars, temp->_allchars_length); if (option[TYPE]) { - if (strlen (temp->rest) > 0) - printf (",%s", temp->rest); + if (strlen (temp->_rest) > 0) + printf (",%s", temp->_rest); printf ("}"); } if (option[DEBUG]) printf (" /* hash value = %d, index = %d */", - temp->hash_value, temp->final_index); + temp->_hash_value, temp->_final_index); } static void @@ -696,7 +696,7 @@ Output::output_keyword_table () printf ("%sstatic ", indent); - output_const_type (const_readonly_array, struct_tag); + output_const_type (const_readonly_array, _struct_tag); printf ("%s[] =\n" "%s {\n", option.get_wordlist_name (), @@ -704,33 +704,33 @@ Output::output_keyword_table () /* 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] - && !(temp->first()->duplicate_link - || (temp->rest() && temp->first()->hash_value == temp->rest()->first()->hash_value))) + && !(temp->first()->_duplicate_link + || (temp->rest() && temp->first()->_hash_value == temp->rest()->first()->_hash_value))) continue; if (index > 0) 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. */ - output_keyword_blank_entries (temp->first()->hash_value - index, indent); + output_keyword_blank_entries (temp->first()->_hash_value - index, indent); 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); /* Deal with links specially. */ - if (temp->first()->duplicate_link) // implies option[DUP] - for (KeywordExt *links = temp->first()->duplicate_link; links; links = links->duplicate_link) + if (temp->first()->_duplicate_link) // implies option[DUP] + for (KeywordExt *links = temp->first()->_duplicate_link; links; links = links->_duplicate_link) { - links->final_index = ++index; + links->_final_index = ++index; printf (",\n"); output_keyword_entry (links, indent); } @@ -764,44 +764,44 @@ Output::output_lookup_array () int count; /* Number of consecutive duplicates at this index. */ }; - duplicate_entry *duplicates = new duplicate_entry[total_duplicates]; - int *lookup_array = new int[max_hash_value + 1 + 2*total_duplicates]; - int lookup_array_size = max_hash_value + 1; + duplicate_entry *duplicates = new duplicate_entry[_total_duplicates]; + int *lookup_array = new int[_max_hash_value + 1 + 2*_total_duplicates]; + int lookup_array_size = _max_hash_value + 1; 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) *--lookup_ptr = DEFAULT_VALUE; /* 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; - lookup_array[hash_value] = temp->first()->final_index; + int hash_value = temp->first()->_hash_value; + lookup_array[hash_value] = temp->first()->_final_index; if (option[DEBUG]) fprintf (stderr, "keyword = %.*s, index = %d\n", - temp->first()->allchars_length, temp->first()->allchars, temp->first()->final_index); - if (temp->first()->duplicate_link - || (temp->rest() && hash_value == temp->rest()->first()->hash_value)) + temp->first()->_allchars_length, temp->first()->_allchars, temp->first()->_final_index); + if (temp->first()->_duplicate_link + || (temp->rest() && hash_value == temp->rest()->first()->_hash_value)) { /* Start a duplicate entry. */ dup_ptr->hash_value = hash_value; - dup_ptr->index = temp->first()->final_index; + dup_ptr->index = temp->first()->_final_index; dup_ptr->count = 1; 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++; if (option[DEBUG]) fprintf (stderr, "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; temp = temp->rest(); @@ -809,7 +809,7 @@ Output::output_lookup_array () dup_ptr->count++; if (option[DEBUG]) 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); dup_ptr++; @@ -842,11 +842,11 @@ Output::output_lookup_array () i = lookup_array_size; lookup_array_size += 2; found_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. */ + /* 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. */ assert (lookup_array[dup_ptr->hash_value] == dup_ptr->index); - lookup_array[dup_ptr->hash_value] = - 1 - total_keys - i; - lookup_array[i] = - total_keys + dup_ptr->index; + lookup_array[dup_ptr->hash_value] = - 1 - _total_keys - i; + lookup_array[i] = - _total_keys + dup_ptr->index; lookup_array[i + 1] = - dup_ptr->count; /* All these three values are <= -2, distinct from DEFAULT_VALUE. */ } @@ -917,9 +917,9 @@ Output::output_lookup_tables () if (option[SWITCH]) { /* 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 (); - if (option[TYPE] || (option[DUP] && total_duplicates > 0)) + if (option[TYPE] || (option[DUP] && _total_duplicates > 0)) output_keyword_table (); } else @@ -941,24 +941,24 @@ output_switch_case (KeywordExt_List *list, int indent, int *jumps_away) { if (option[DEBUG]) 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] - && (list->first()->duplicate_link - || (list->rest() && list->first()->hash_value == list->rest()->first()->hash_value))) + && (list->first()->_duplicate_link + || (list->rest() && list->first()->_hash_value == list->rest()->first()->_hash_value))) { if (option[LENTABLE]) printf ("%*slengthptr = &lengthtable[%d];\n", - indent, "", list->first()->final_index); + indent, "", list->first()->_final_index); 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; 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++; - 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; } @@ -974,16 +974,16 @@ output_switch_case (KeywordExt_List *list, int indent, int *jumps_away) { printf ("%*sif (len == %d)\n" "%*s {\n", - indent, "", list->first()->allchars_length, + indent, "", list->first()->_allchars_length, indent, ""); indent += 4; } printf ("%*sresword = ", indent, ""); 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 - output_string (list->first()->allchars, list->first()->allchars_length); + output_string (list->first()->_allchars, list->first()->_allchars_length); printf (";\n"); printf ("%*sgoto compare;\n", indent, ""); @@ -997,7 +997,7 @@ output_switch_case (KeywordExt_List *list, int indent, int *jumps_away) *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(); return list; @@ -1023,24 +1023,24 @@ output_switches (KeywordExt_List *list, int num_switches, int size, int min_hash KeywordExt_List *temp = list; 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(); } printf ("%*sif (key < %d)\n" "%*s {\n", - indent, "", temp->first()->hash_value, + indent, "", temp->first()->_hash_value, 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" "%*selse\n" "%*s {\n", 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", indent, ""); @@ -1048,7 +1048,7 @@ output_switches (KeywordExt_List *list, int num_switches, int size, int min_hash else { /* Output a single switch. */ - int lowest_case_value = list->first()->hash_value; + int lowest_case_value = list->first()->_hash_value; if (size == 1) { 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; 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); if (!jumps_away) printf ("%*s break;\n", @@ -1114,25 +1114,25 @@ Output::output_lookup_function_body (const Output_Compare& comparison) { if (option[LENTABLE]) printf (" register %s%s *lengthptr;\n", - const_always, smallest_integral_type (max_key_len)); + const_always, smallest_integral_type (_max_key_len)); printf (" register "); - output_const_type (const_readonly_array, struct_tag); + output_const_type (const_readonly_array, _struct_tag); printf ("*wordptr;\n"); printf (" register "); - output_const_type (const_readonly_array, struct_tag); + output_const_type (const_readonly_array, _struct_tag); printf ("*wordendptr;\n"); } if (option[TYPE]) { printf (" register "); - output_const_type (const_readonly_array, struct_tag); + output_const_type (const_readonly_array, _struct_tag); printf ("*resword;\n\n"); } else 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]) { @@ -1241,7 +1241,7 @@ Output::output_lookup_function_body (const Output_Compare& comparison) indent -= 4; printf ("%*s }\n", indent, ""); } - if (total_duplicates > 0) + if (_total_duplicates > 0) { printf ("%*s else if (index < -TOTAL_KEYWORDS)\n" "%*s {\n" @@ -1249,15 +1249,15 @@ Output::output_lookup_function_body (const Output_Compare& comparison) indent, "", indent, "", indent, ""); if (option[LENTABLE]) 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 ", 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", option.get_wordlist_name ()); printf ("%*s register ", 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 ("%*s while (wordptr < wordendptr)\n" "%*s {\n", @@ -1350,7 +1350,7 @@ Output::output_lookup_function () "#endif\n"); printf ("%s%s\n", - const_for_struct, return_type); + const_for_struct, _return_type); if (option[CPLUSPLUS]) printf ("%s::", option.get_class_name ()); printf ("%s ", option.get_function_name ()); @@ -1416,8 +1416,8 @@ Output::output () if (!option[TYPE]) { - return_type = (const_always[0] ? "const char *" : "char *"); - struct_tag = (const_always[0] ? "const char *" : "char *"); + _return_type = (const_always[0] ? "const char *" : "char *"); + _struct_tag = (const_always[0] ? "const char *" : "char *"); } char_to_index = (option[SEVENBIT] ? "" : "(unsigned char)"); @@ -1434,10 +1434,10 @@ Output::output () printf (" code produced by gperf version %s */\n", version_string); 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.... */ - printf ("%s;\n", array_type); + printf ("%s;\n", _array_type); if (option[INCLUDE]) printf ("#include <string.h>\n"); /* Declare strlen(), strcmp(), strncmp(). */ @@ -1454,7 +1454,7 @@ Output::output () } 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]) printf ("class %s\n" @@ -1466,7 +1466,7 @@ Output::output () "};\n" "\n", 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 (); @@ -1475,7 +1475,7 @@ Output::output () output_lookup_function (); - if (additional_code) + if (_additional_code) for (int c; (c = getchar ()) != EOF; putchar (c)) ; diff --git a/src/output.h b/src/output.h index e2c5db5..c4a0d1e 100644 --- a/src/output.h +++ b/src/output.h @@ -49,31 +49,31 @@ private: void output_lookup_function (); /* Linked list of keywords. */ - KeywordExt_List *head; + KeywordExt_List *_head; /* Pointer to the type for word list. */ - const char *array_type; + const char *_array_type; /* Pointer to return type for lookup function. */ - const char *return_type; + const char *_return_type; /* Shorthand for user-defined struct tag type. */ - const char *struct_tag; + const char *_struct_tag; /* True if any additional C code is included. */ - int additional_code; + int _additional_code; /* C source code to be included verbatim. */ - const char *include_src; + const char *_include_src; /* Total number of keys, counting duplicates. */ - int total_keys; + int _total_keys; /* Total number of duplicate hash values. */ - int total_duplicates; + int _total_duplicates; /* Maximum length of the longest keyword. */ - int max_key_len; + int _max_key_len; /* Minimum length of the shortest keyword. */ - int min_key_len; + int _min_key_len; /* Minimum hash value for all keywords. */ - int min_hash_value; + int _min_hash_value; /* Maximum hash value for all keywords. */ - int max_hash_value; - Vectors * v; + int _max_hash_value; + Vectors * _v; }; #endif diff --git a/src/read-line.h b/src/read-line.h index 39700a0..83c53c9 100644 --- a/src/read-line.h +++ b/src/read-line.h @@ -35,7 +35,7 @@ class Read_Line public: /* 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, and ignoring lines starting with '#'. Returns NULL on error or EOF. @@ -44,7 +44,7 @@ public: char *read_next_line (); private: - FILE *fp; /* FILE pointer to the input stream. */ + FILE * const _fp; /* FILE pointer to the input stream. */ }; #ifdef __OPTIMIZE__ diff --git a/src/read-line.icc b/src/read-line.icc index e23db94..18bc727 100644 --- a/src/read-line.icc +++ b/src/read-line.icc @@ -32,9 +32,9 @@ Read_Line::read_next_line () { 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) @@ -48,7 +48,7 @@ Read_Line::read_next_line () char *line = NULL; size_t linesize = 0; - int length = get_line (&line, &linesize, fp); + int length = get_line (&line, &linesize, _fp); if (length < 0) { delete[] line; diff --git a/src/vectors.cc b/src/vectors.cc index 1da014d..ef61ef2 100644 --- a/src/vectors.cc +++ b/src/vectors.cc @@ -1,5 +1,5 @@ /* 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) 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" int Vectors::ALPHA_SIZE = MAX_ALPHA_SIZE; -int Vectors::occurrences[MAX_ALPHA_SIZE]; -int Vectors::asso_values[MAX_ALPHA_SIZE]; +int Vectors::_occurrences[MAX_ALPHA_SIZE]; +int Vectors::_asso_values[MAX_ALPHA_SIZE]; diff --git a/src/vectors.h b/src/vectors.h index 28a1053..c9d42fa 100644 --- a/src/vectors.h +++ b/src/vectors.h @@ -3,7 +3,7 @@ /* Static class data members that are shared between several classes via 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) This file is part of GNU GPERF. @@ -29,9 +29,9 @@ static const int MAX_ALPHA_SIZE = 256; struct Vectors { - static int ALPHA_SIZE; /* Size of alphabet. */ - 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 ALPHA_SIZE; /* Size of alphabet. */ + 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. */ }; #endif |