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

Rework the options handling.

This commit is contained in:
Bruno Haible
2002-11-13 18:18:48 +00:00
parent 5e5d12ca2d
commit c8f007fe8b
12 changed files with 739 additions and 439 deletions

View File

@@ -19,128 +19,193 @@ You should have received a copy of the GNU General Public License
along with GNU GPERF; see the file COPYING. If not, write to the Free
Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111, USA. */
/* TRUE if option enable, else FALSE. */
INLINE
Positions::Positions ()
: _size (0)
{
_positions[0] = PositionIterator::EOS;
}
INLINE
Positions::Positions (int key1)
: _size (1)
{
_positions[0] = key1;
_positions[1] = PositionIterator::EOS;
}
INLINE
Positions::Positions (int key1, int key2)
: _size (2)
{
_positions[0] = key1;
_positions[1] = key2;
_positions[2] = PositionIterator::EOS;
}
INLINE int
Options::operator[] (Option_Type option)
Positions::operator[] (unsigned int index) const
{
return _option_word & option;
return _positions[index];
}
/* Initializes the key Iterator. */
INLINE void
Options::reset ()
{
_key_pos = 0;
}
/* Returns current key_position and advance index. */
INLINE int
Options::get ()
{
return _key_positions[_key_pos++];
}
/* Sets the size of the table size. */
INLINE void
Options::set_asso_max (int r)
{
_size = r;
}
/* Returns the size of the table size. */
INLINE int
Options::get_asso_max ()
INLINE unsigned int
Positions::get_size () const
{
return _size;
}
/* Returns total distinct key positions. */
INLINE int
Options::get_max_keysig_size ()
INLINE unsigned char *
Positions::pointer ()
{
return _total_keysig_size;
return _positions;
}
/* Sets total distinct key positions. */
INLINE void
Options::set_keysig_size (int size)
Positions::set_size (unsigned int size)
{
_total_keysig_size = size;
_size = size;
}
/* Returns the jump value. */
/* Sorts the array in reverse order.
Returns 1 if there are no duplicates, 0 otherwise. */
INLINE int
Options::get_jump ()
Positions::sort ()
{
return _jump;
/* Bubble sort. */
int duplicate_free = 1;
unsigned char *base = _positions;
unsigned int len = _size;
for (unsigned int i = 1; i < len; i++)
{
unsigned int j;
int tmp;
for (j = i, tmp = base[j]; j > 0 && tmp >= base[j - 1]; j--)
if ((base[j] = base[j - 1]) == tmp) /* oh no, a duplicate!!! */
duplicate_free = 0;
base[j] = tmp;
}
return duplicate_free;
}
/* Returns the generated function name. */
INLINE const char *
Options::get_function_name ()
INLINE
PositionIterator::PositionIterator (Positions const& positions)
: _set (positions),
_index (0)
{
return _function_name;
}
/* Returns the keyword key name. */
INLINE const char *
Options::get_key_name ()
{
return _key_name;
}
/* Returns the struct initializer suffix. */
INLINE const char *
Options::get_initializer_suffix ()
{
return _initializer_suffix;
}
/* Returns the hash function name. */
INLINE const char *
Options::get_hash_name ()
{
return _hash_name;
}
/* Returns the hash table array name. */
INLINE const char *
Options::get_wordlist_name ()
{
return _wordlist_name;
}
/* Returns the generated class name. */
INLINE const char *
Options::get_class_name ()
{
return _class_name;
}
/* Returns the initial associated character value. */
INLINE int
Options::initial_value ()
PositionIterator::next ()
{
return _initial_asso_value;
return _set._positions[_index++];
}
/* Returns the iterations value. */
/* Tests a given boolean option. Returns 1 if set, 0 otherwise. */
INLINE int
Options::get_iterations ()
Options::operator[] (Option_Type option) const
{
return _option_word & option;
}
/* Returns the iterations value. */
INLINE int
Options::get_iterations () const
{
return _iterations;
}
/* Returns the string used to delimit keywords from other attributes. */
/* Returns the jump value. */
INLINE int
Options::get_jump () const
{
return _jump;
}
/* Returns the initial associated character value. */
INLINE int
Options::get_initial_asso_value () const
{
return _initial_asso_value;
}
/* Returns the total number of switch statements to generate. */
INLINE int
Options::get_total_switches () const
{
return _total_switches;
}
/* Returns the factor by which to multiply the generated table's size. */
INLINE int
Options::get_size_multiple () const
{
return _size_multiple;
}
/* Returns the generated function name. */
INLINE const char *
Options::get_delimiter ()
Options::get_function_name () const
{
return _function_name;
}
/* Returns the keyword key name. */
INLINE const char *
Options::get_key_name () const
{
return _key_name;
}
/* Returns the struct initializer suffix. */
INLINE const char *
Options::get_initializer_suffix () const
{
return _initializer_suffix;
}
/* Returns the generated class name. */
INLINE const char *
Options::get_class_name () const
{
return _class_name;
}
/* Returns the hash function name. */
INLINE const char *
Options::get_hash_name () const
{
return _hash_name;
}
/* Returns the hash table array name. */
INLINE const char *
Options::get_wordlist_name () const
{
return _wordlist_name;
}
/* Returns the string used to delimit keywords from other attributes. */
INLINE const char *
Options::get_delimiter () const
{
return _delimiters;
}
/* Gets the total number of switch statements to generate. */
INLINE int
Options::get_total_switches ()
/* Returns key positions. */
INLINE const Positions&
Options::get_key_positions () const
{
return _total_switches;
return _key_positions;
}
/* Returns total distinct key positions. */
INLINE int
Options::get_max_keysig_size () const
{
return _key_positions.get_size();
}