summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruno Haible <bruno@clisp.org>2004-08-22 15:52:15 +0000
committerBruno Haible <bruno@clisp.org>2004-08-22 15:52:15 +0000
commite5f2f1dc440a3ce66cb12851074909a804ce3a7c (patch)
tree31ead138b75a20fc7d70fc33079430fd886822e4
parent6bbbca983fecf28e7f7ed783cd6aa2e5491bdaf0 (diff)
downloadgperf-e5f2f1dc440a3ce66cb12851074909a804ce3a7c.tar.gz
Add a length-table-name option and declaration.
-rw-r--r--ChangeLog21
-rw-r--r--NEWS5
-rw-r--r--doc/gperf.texi20
-rw-r--r--src/input.cc7
-rw-r--r--src/options.cc33
-rw-r--r--src/options.h10
-rw-r--r--src/options.icc9
-rw-r--r--src/output.cc23
8 files changed, 107 insertions, 21 deletions
diff --git a/ChangeLog b/ChangeLog
index 1af586c..ca4740e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,24 @@
+2004-08-21 Bruce Lilly <blilly@erols.com>
+
+ * src/input.cc (Input::read_input): Accept length-table-name
+ declaration.
+ * src/options.h (Options::get_lengthtable_name,
+ Options::set_lengthtable_name): New declarations.
+ (Options): Add field _lengthtable_name.
+ * src/options.icc (Options::get_lengthtable_name): New inline method.
+ * src/options.cc (DEFAULT_LENGTHTABLE_NAME): New constant.
+ (Options::long_usage): Document --length-table-name option.
+ (Options::Options): Initialize _lengthtable_name field.
+ (Options::~Options): Update.
+ (Options::set_lengthtable_name): New method.
+ (long_options): Add option --length-table-name.
+ (Options::parse_options): Implement --length-table-name option.
+ * src/output.cc (Output::output_keylength_table, output_switch_case,
+ Output::output_lookup_function_body): Use option.get_lengthtable_name.
+ * doc/gperf.texi (Gperf Declarations): Document %define
+ length-table-name.
+ (Output Details): Document --length-table-name option.
+
2003-06-12 Bruno Haible <bruno@clisp.org>
* gperf-3.0.1 released.
diff --git a/NEWS b/NEWS
index efa3ca0..f3060f5 100644
--- a/NEWS
+++ b/NEWS
@@ -1,3 +1,8 @@
+New in 3.1:
+
+* Added option --length-table-name.
+* Added declaration %define length-table-name.
+
New in 3.0.1:
* Bug fix.
diff --git a/doc/gperf.texi b/doc/gperf.texi
index b280e55..689dac2 100644
--- a/doc/gperf.texi
+++ b/doc/gperf.texi
@@ -7,7 +7,7 @@
@c some day we should @include version.texi instead of defining
@c these values at hand.
-@set UPDATED 12 June 2003
+@set UPDATED 22 August 2004
@set EDITION 3.0.1
@set VERSION 3.0.1
@c ---------------------
@@ -28,7 +28,7 @@
This file documents the features of the GNU Perfect Hash Function
Generator @value{VERSION}.
-Copyright @copyright{} 1989-2003 Free Software Foundation, Inc.
+Copyright @copyright{} 1989-2004 Free Software Foundation, Inc.
Permission is granted to make and distribute verbatim copies of this
manual provided the copyright notice and this permission notice are
@@ -66,7 +66,7 @@ Software Foundation instead of in the original English.
@page
@vskip 0pt plus 1filll
-Copyright @copyright{} 1989-2003 Free Software Foundation, Inc.
+Copyright @copyright{} 1989-2004 Free Software Foundation, Inc.
Permission is granted to make and distribute verbatim copies of
@@ -605,6 +605,13 @@ hash table. Default name is @samp{wordlist}. This option permits the
use of two hash tables in the same file, even when the option @samp{-G}
(or, equivalently, the @samp{%global-table} declaration) is given.
+@item %define length-table-name @var{name}
+@cindex @samp{%define length-table-name}
+Allows you to specify the name for the generated array containing the
+length table. Default name is @samp{lengthtable}. This option permits the
+use of two length tables in the same file, even when the option @samp{-G}
+(or, equivalently, the @samp{%global-table} declaration) is given.
+
@item %switch=@var{count}
@cindex @samp{%switch}
Causes the generated C code to use a @code{switch} statement scheme,
@@ -1082,6 +1089,13 @@ hash table. Default name is @samp{wordlist}. This option permits the
use of two hash tables in the same file, even when the option @samp{-G}
(or, equivalently, the @samp{%global-table} declaration) is given.
+@itemx --length-table-name=@var{length-table-array-name}
+@cindex Array name
+Allows you to specify the name for the generated array containing the
+length table. Default name is @samp{lengthtable}. This option permits the
+use of two length tables in the same file, even when the option @samp{-G}
+(or, equivalently, the @samp{%global-table} declaration) is given.
+
@item -S @var{total-switch-statements}
@itemx --switch=@var{total-switch-statements}
@cindex @code{switch}
diff --git a/src/input.cc b/src/input.cc
index 1b2c459..c98ab98 100644
--- a/src/input.cc
+++ b/src/input.cc
@@ -1,5 +1,5 @@
/* Input routines.
- Copyright (C) 1989-1998, 2002-2003 Free Software Foundation, Inc.
+ Copyright (C) 1989-1998, 2002-2004 Free Software Foundation, Inc.
Written by Douglas C. Schmidt <schmidt@ics.uci.edu>
and Bruno Haible <bruno@clisp.org>.
@@ -552,6 +552,11 @@ Input::read_input ()
option.set_wordlist_name (arg);
else
+ if (is_define_declaration (line, line_end, lineno,
+ "length-table-name", &arg))
+ option.set_lengthtable_name (arg);
+ else
+
if (is_declaration_with_arg (line, line_end, lineno,
"switch", &arg))
{
diff --git a/src/options.cc b/src/options.cc
index 88ae9fc..5c615b0 100644
--- a/src/options.cc
+++ b/src/options.cc
@@ -1,5 +1,5 @@
/* Handles parsing the Options provided to the user.
- Copyright (C) 1989-1998, 2000, 2002-2003 Free Software Foundation, Inc.
+ Copyright (C) 1989-1998, 2000, 2002-2004 Free Software Foundation, Inc.
Written by Douglas C. Schmidt <schmidt@ics.uci.edu>
and Bruno Haible <bruno@clisp.org>.
@@ -58,6 +58,9 @@ static const char *const DEFAULT_HASH_NAME = "hash";
/* Default name for generated hash table array. */
static const char *const DEFAULT_WORDLIST_NAME = "wordlist";
+/* Default name for generated length table array. */
+static const char *const DEFAULT_LENGTHTABLE_NAME = "lengthtable";
+
/* Default name for string pool. */
static const char *const DEFAULT_STRINGPOOL_NAME = "stringpool";
@@ -180,6 +183,10 @@ Options::long_usage (FILE * stream)
" Specify name of word list array. Default name is\n"
" 'wordlist'.\n");
fprintf (stream,
+ " --length-table-name=NAME\n"
+ " Specify name of length table array. Default name is\n"
+ " 'lengthtable'.\n");
+ fprintf (stream,
" -S, --switch=COUNT Causes the generated C code to use a switch\n"
" statement scheme, rather than an array lookup table.\n"
" This can lead to a reduction in both time and space\n"
@@ -458,6 +465,7 @@ Options::Options ()
_class_name (DEFAULT_CLASS_NAME),
_hash_name (DEFAULT_HASH_NAME),
_wordlist_name (DEFAULT_WORDLIST_NAME),
+ _lengthtable_name (DEFAULT_LENGTHTABLE_NAME),
_stringpool_name (DEFAULT_STRINGPOOL_NAME),
_delimiters (DEFAULT_DELIMITERS),
_key_positions ()
@@ -495,6 +503,7 @@ Options::~Options ()
"\nlookup function name = %s"
"\nhash function name = %s"
"\nword list name = %s"
+ "\nlength table name = %s"
"\nstring pool name = %s"
"\nslot name = %s"
"\ninitializer suffix = %s"
@@ -525,10 +534,10 @@ Options::~Options ()
_option_word & NOLENGTH ? "enabled" : "disabled",
_option_word & RANDOM ? "enabled" : "disabled",
_option_word & DEBUG ? "enabled" : "disabled",
- _function_name, _hash_name, _wordlist_name, _stringpool_name,
- _slot_name, _initializer_suffix, _asso_iterations, _jump,
- _size_multiple, _initial_asso_value, _delimiters,
- _total_switches);
+ _function_name, _hash_name, _wordlist_name, _lengthtable_name,
+ _stringpool_name, _slot_name, _initializer_suffix,
+ _asso_iterations, _jump, _size_multiple, _initial_asso_value,
+ _delimiters, _total_switches);
if (_key_positions.is_useall())
fprintf (stderr, "all characters are used in the hash function\n");
else
@@ -633,6 +642,14 @@ Options::set_wordlist_name (const char *name)
_wordlist_name = name;
}
+/* Sets the length table array name, if not already set. */
+void
+Options::set_lengthtable_name (const char *name)
+{
+ if (_lengthtable_name == DEFAULT_LENGTHTABLE_NAME)
+ _lengthtable_name = name;
+}
+
/* Sets the string pool name, if not already set. */
void
Options::set_stringpool_name (const char *name)
@@ -673,6 +690,7 @@ static const struct option long_options[] =
{ "includes", no_argument, NULL, 'I' },
{ "global-table", no_argument, NULL, 'G' },
{ "word-array-name", required_argument, NULL, 'W' },
+ { "length-table-name", required_argument, NULL, CHAR_MAX + 4 },
{ "switch", required_argument, NULL, 'S' },
{ "omit-struct-type", no_argument, NULL, 'T' },
{ "key-positions", required_argument, NULL, 'k' },
@@ -1021,6 +1039,11 @@ warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\
_option_word |= NULLSTRINGS;
break;
}
+ case CHAR_MAX + 4: /* Sets the name for the length table array. */
+ {
+ _lengthtable_name = /*getopt*/optarg;
+ break;
+ }
default:
short_usage (stderr);
exit (1);
diff --git a/src/options.h b/src/options.h
index 2507590..179400a 100644
--- a/src/options.h
+++ b/src/options.h
@@ -2,7 +2,7 @@
/* Handles parsing the Options provided to the user.
- Copyright (C) 1989-1998, 2000, 2002-2003 Free Software Foundation, Inc.
+ Copyright (C) 1989-1998, 2000, 2002-2004 Free Software Foundation, Inc.
Written by Douglas C. Schmidt <schmidt@ics.uci.edu>
and Bruno Haible <bruno@clisp.org>.
@@ -194,6 +194,11 @@ public:
/* Sets the hash table array name, if not already set. */
void set_wordlist_name (const char *name);
+ /* Returns the length table array name. */
+ const char * get_lengthtable_name () const;
+ /* Sets the length table array name, if not already set. */
+ void set_lengthtable_name (const char *name);
+
/* Returns the string pool name. */
const char * get_stringpool_name () const;
/* Sets the string pool name, if not already set. */
@@ -265,6 +270,9 @@ private:
/* Name used for hash table array. */
const char * _wordlist_name;
+ /* Name used for length table array. */
+ const char * _lengthtable_name;
+
/* Name used for the string pool. */
const char * _stringpool_name;
diff --git a/src/options.icc b/src/options.icc
index 1d21cc5..a2aa29e 100644
--- a/src/options.icc
+++ b/src/options.icc
@@ -1,6 +1,6 @@
/* Inline Functions for options.{h,cc}.
- Copyright (C) 1989-1998, 2000, 2002-2003 Free Software Foundation, Inc.
+ Copyright (C) 1989-1998, 2000, 2002-2004 Free Software Foundation, Inc.
Written by Douglas C. Schmidt <schmidt@ics.uci.edu>
and Bruno Haible <bruno@clisp.org>.
@@ -128,6 +128,13 @@ Options::get_wordlist_name () const
return _wordlist_name;
}
+/* Returns the length table array name. */
+INLINE const char *
+Options::get_lengthtable_name () const
+{
+ return _lengthtable_name;
+}
+
/* Returns the string pool name. */
INLINE const char *
Options::get_stringpool_name () const
diff --git a/src/output.cc b/src/output.cc
index f693505..5f95445 100644
--- a/src/output.cc
+++ b/src/output.cc
@@ -1,5 +1,5 @@
/* Output routines.
- Copyright (C) 1989-1998, 2000, 2002-2003 Free Software Foundation, Inc.
+ Copyright (C) 1989-1998, 2000, 2002-2004 Free Software Foundation, Inc.
Written by Douglas C. Schmidt <schmidt@ics.uci.edu>
and Bruno Haible <bruno@clisp.org>.
@@ -916,9 +916,11 @@ Output::output_keylength_table () const
const int columns = 14;
const char * const indent = option[GLOBAL] ? "" : " ";
- printf ("%sstatic %s%s lengthtable[] =\n%s {",
+ printf ("%sstatic %s%s %s[] =\n"
+ "%s {",
indent, const_readonly_array,
smallest_integral_type (_max_key_len),
+ option.get_lengthtable_name (),
indent);
/* Generate an array of lengths, similar to output_keyword_table. */
@@ -1423,8 +1425,8 @@ output_switch_case (KeywordExt_List *list, int indent, int *jumps_away)
if (option[DUP] && list->first()->_duplicate_link)
{
if (option[LENTABLE])
- printf ("%*slengthptr = &lengthtable[%d];\n",
- indent, "", list->first()->_final_index);
+ printf ("%*slengthptr = &%s[%d];\n",
+ indent, "", option.get_lengthtable_name (), list->first()->_final_index);
printf ("%*swordptr = &%s[%d];\n",
indent, "", option.get_wordlist_name (), list->first()->_final_index);
@@ -1682,8 +1684,8 @@ Output::output_lookup_function_body (const Output_Compare& comparison) const
if (option[LENTABLE])
{
printf ("%*s {\n"
- "%*s if (len == lengthtable[index])\n",
- indent, "", indent, "");
+ "%*s if (len == %s[index])\n",
+ indent, "", indent, "", option.get_lengthtable_name ());
indent += 4;
}
printf ("%*s {\n"
@@ -1721,8 +1723,9 @@ Output::output_lookup_function_body (const Output_Compare& comparison) const
"%*s register int offset = - 1 - TOTAL_KEYWORDS - index;\n",
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));
+ printf ("%*s register %s%s *lengthptr = &%s[TOTAL_KEYWORDS + lookup[offset]];\n",
+ indent, "", const_always, smallest_integral_type (_max_key_len),
+ option.get_lengthtable_name ());
printf ("%*s register ",
indent, "");
output_const_type (const_readonly_array, _wordlist_eltype);
@@ -1781,8 +1784,8 @@ Output::output_lookup_function_body (const Output_Compare& comparison) const
int indent = 8;
if (option[LENTABLE])
{
- printf ("%*sif (len == lengthtable[key])\n",
- indent, "");
+ printf ("%*sif (len == %s[key])\n",
+ indent, "", option.get_lengthtable_name ());
indent += 2;
}