diff options
-rw-r--r-- | ChangeLog | 4 | ||||
-rw-r--r-- | src/key-list.cc | 39 |
2 files changed, 40 insertions, 3 deletions
@@ -1,5 +1,9 @@ 2000-08-19 Bruno Haible <bruno@linuix.math.u-bordeaux.fr> + * src/key-list.cc (Output_Compare_Memcmp): New class. + (Key_List::output_lookup_function): When option -l is given, use + memcmp instead of strcmp or strncmp. + * doc/gperf.texi: The bug report address is <bug-gnu-utils@gnu.org>. The download address is ftp.gnu.org. Remove mention of -a and -g options (now nops). Explain effect of -c option. diff --git a/src/key-list.cc b/src/key-list.cc index 33c3906..27a2ff8 100644 --- a/src/key-list.cc +++ b/src/key-list.cc @@ -810,6 +810,34 @@ void Output_Compare_Strncmp::output_comparison (const Output_Expr& expr1, printf ("[len] == '\\0'"); } +/* This class outputs a comparison using memcmp. + Note that the length of expr1 (available through the local variable `len') + must be verified to be equal to the length of expr2 prior to this + comparison. */ + +struct Output_Compare_Memcmp : public Output_Compare +{ + virtual void output_comparison (const Output_Expr& expr1, + const Output_Expr& expr2) const; + Output_Compare_Memcmp () {} + virtual ~Output_Compare_Memcmp () {} +}; + +void Output_Compare_Memcmp::output_comparison (const Output_Expr& expr1, + const Output_Expr& expr2) const +{ + T (Trace t ("Output_Compare_Memcmp::output_comparison");) + printf ("*"); + expr1.output_expr (); + printf (" == *"); + expr2.output_expr (); + printf (" && !memcmp ("); + expr1.output_expr (); + printf (" + 1, "); + expr2.output_expr (); + printf (" + 1, len - 1)"); +} + /* ------------------------------------------------------------------------- */ /* Generates C code for the hash function that returns the @@ -1820,10 +1848,15 @@ Key_List::output_lookup_function (void) if (!option[GLOBAL]) output_lookup_tables (); - if (option[COMP]) - output_lookup_function_body (Output_Compare_Strncmp ()); + if (option[LENTABLE]) + output_lookup_function_body (Output_Compare_Memcmp ()); else - output_lookup_function_body (Output_Compare_Strcmp ()); + { + if (option[COMP]) + output_lookup_function_body (Output_Compare_Strncmp ()); + else + output_lookup_function_body (Output_Compare_Strcmp ()); + } printf ("}\n"); } |