]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
Revamp the hash table API.
authorBruno Haible <bruno@clisp.org>
Fri, 7 Oct 2005 11:21:50 +0000 (11:21 +0000)
committerBruno Haible <bruno@clisp.org>
Tue, 23 Jun 2009 10:12:53 +0000 (12:12 +0200)
19 files changed:
gettext-tools/lib/hash.c
gettext-tools/lib/hash.h
gettext-tools/src/message.c
gettext-tools/src/write-qt.c
gettext-tools/src/x-awk.c
gettext-tools/src/x-c.c
gettext-tools/src/x-csharp.c
gettext-tools/src/x-elisp.c
gettext-tools/src/x-glade.c
gettext-tools/src/x-java.c
gettext-tools/src/x-librep.c
gettext-tools/src/x-lisp.c
gettext-tools/src/x-perl.c
gettext-tools/src/x-php.c
gettext-tools/src/x-python.c
gettext-tools/src/x-scheme.c
gettext-tools/src/x-sh.c
gettext-tools/src/x-tcl.c
gettext-tools/src/xgettext.c

index bf3d0bb58da0cea8d1960ac80292f5f606e8ca39..2a962103ebe7e0797e9bb6b82564d909d5ecb11f 100644 (file)
 #include <limits.h>
 #include <sys/types.h>
 
-#include <obstack.h>
+/* Since this simple implementation of hash tables allows only insertion, no
+   removal of entries, the right data structure for the memory holding all keys
+   is an obstack.  */
+#include "obstack.h"
 
+/* Use checked memory allocation.  */
 #include "xalloc.h"
 
 #define obstack_chunk_alloc xmalloc
 #define obstack_chunk_free free
 
+
 typedef struct hash_entry
 {
-  unsigned long used;
-  const void *key;
+  unsigned long used;  /* Hash code of the key, or 0 for an unused entry.  */
+  const void *key;     /* Key.  */
   size_t keylen;
-  void *data;
+  void *data;          /* Value.  */
   struct hash_entry *next;
 }
 hash_entry;
 
-/* Forward declaration of local functions.  */
-static void insert_entry_2 (hash_table *htab,
-                           const void *key, size_t keylen,
-                           unsigned long int hval, size_t idx, void *data);
-static void resize (hash_table *htab);
-static size_t lookup (hash_table *htab,
-                     const void *key, size_t keylen,
-                     unsigned long int hval);
-static unsigned long compute_hashval (const void *key, size_t keylen);
-static int is_prime (unsigned long int candidate);
+
+/* Given an odd CANDIDATE > 1, return true if it is a prime number.  */
+static int
+is_prime (unsigned long int candidate)
+{
+  /* No even number and none less than 10 will be passed here.  */
+  unsigned long int divn = 3;
+  unsigned long int sq = divn * divn;
+
+  while (sq < candidate && candidate % divn != 0)
+    {
+      ++divn;
+      sq += 4 * divn;
+      ++divn;
+    }
+
+  return candidate % divn != 0;
+}
+
+
+/* Given SEED > 1, return the smallest odd prime number >= SEED.  */
+unsigned long
+next_prime (unsigned long int seed)
+{
+  /* Make it definitely odd.  */
+  seed |= 1;
+
+  while (!is_prime (seed))
+    seed += 2;
+
+  return seed;
+}
 
 
+/* Initialize a hash table.  INIT_SIZE > 1 is the initial number of available
+   entries.
+   Return 0 upon successful completion, -1 upon memory allocation error.  */
 int
-init_hash (hash_table *htab, unsigned long int init_size)
+hash_init (hash_table *htab, unsigned long int init_size)
 {
   /* We need the size to be a prime.  */
   init_size = next_prime (init_size);
@@ -76,8 +106,10 @@ init_hash (hash_table *htab, unsigned long int init_size)
 }
 
 
+/* Delete a hash table's contents.
+   Return 0 always.  */
 int
-delete_hash (hash_table *htab)
+hash_destroy (hash_table *htab)
 {
   free (htab->table);
   obstack_free (&htab->mem_pool, NULL);
@@ -85,28 +117,96 @@ delete_hash (hash_table *htab)
 }
 
 
-int
-insert_entry (hash_table *htab, const void *key, size_t keylen, void *data)
+/* Compute a hash code for a key consisting of KEYLEN bytes starting at KEY
+   in memory.  */
+static unsigned long
+compute_hashval (const void *key, size_t keylen)
 {
-  unsigned long int hval = compute_hashval (key, keylen);
+  size_t cnt;
+  unsigned long int hval;
+
+  /* Compute the hash value for the given string.  The algorithm
+     is taken from [Aho,Sethi,Ullman], fixed according to
+     http://www.haible.de/bruno/hashfunc.html.  */
+  cnt = 0;
+  hval = keylen;
+  while (cnt < keylen)
+    {
+      hval = (hval << 9) | (hval >> (sizeof (unsigned long) * CHAR_BIT - 9));
+      hval += (unsigned long int) *(((const char *) key) + cnt++);
+    }
+  return hval != 0 ? hval : ~((unsigned long) 0);
+}
+
+
+/* References:
+   [Aho,Sethi,Ullman] Compilers: Principles, Techniques and Tools, 1986
+   [Knuth]           The Art of Computer Programming, part3 (6.4) */
+
+/* Look up a given key in the hash table.
+   Return the index of the entry, if present, or otherwise the index a free
+   entry where it could be inserted.  */
+static size_t
+lookup (hash_table *htab,
+       const void *key, size_t keylen,
+       unsigned long int hval)
+{
+  unsigned long int hash;
+  size_t idx;
   hash_entry *table = (hash_entry *) htab->table;
-  size_t idx = lookup (htab, key, keylen, hval);
+
+  /* First hash function: simply take the modul but prevent zero.  */
+  hash = 1 + hval % htab->size;
+
+  idx = hash;
 
   if (table[idx].used)
-    /* We don't want to overwrite the old value.  */
-    return -1;
-  else
     {
-      /* An empty bucket has been found.  */
-      insert_entry_2 (htab, obstack_copy (&htab->mem_pool, key, keylen),
-                     keylen, hval, idx, data);
-      if (100 * htab->filled > 75 * htab->size)
-       /* Table is filled more than 75%.  Resize the table.  */
-       resize (htab);
-      return 0;
+      if (table[idx].used == hval && table[idx].keylen == keylen
+         && memcmp (table[idx].key, key, keylen) == 0)
+       return idx;
+
+      /* Second hash function as suggested in [Knuth].  */
+      hash = 1 + hval % (htab->size - 2);
+
+      do
+       {
+         if (idx <= hash)
+           idx = htab->size + idx - hash;
+         else
+           idx -= hash;
+
+         /* If entry is found use it.  */
+         if (table[idx].used == hval && table[idx].keylen == keylen
+             && memcmp (table[idx].key, key, keylen) == 0)
+           return idx;
+       }
+      while (table[idx].used);
     }
+  return idx;
+}
+
+
+/* Look up the value of a key in the given table.
+   If found, return 0 and set *RESULT to it.  Otherwise return -1.  */
+int
+hash_find_entry (hash_table *htab, const void *key, size_t keylen,
+                void **result)
+{
+  hash_entry *table = (hash_entry *) htab->table;
+  size_t idx = lookup (htab, key, keylen, compute_hashval (key, keylen));
+
+  if (table[idx].used == 0)
+    return -1;
+
+  *result = table[idx].data;
+  return 0;
 }
 
+
+/* Insert the pair (KEY[0..KEYLEN-1], DATA) in the hash table at index IDX.
+   HVAL is the key's hash code.  IDX depends on it.  The table entry at index
+   IDX is known to be unused.  */
 static void
 insert_entry_2 (hash_table *htab,
                const void *key, size_t keylen,
@@ -136,6 +236,7 @@ insert_entry_2 (hash_table *htab,
 }
 
 
+/* Grow the hash table.  */
 static void
 resize (hash_table *htab)
 {
@@ -160,23 +261,71 @@ resize (hash_table *htab)
 }
 
 
+/* Try to insert the pair (KEY[0..KEYLEN-1], DATA) in the hash table.
+   Return 0 if successful, or -1 if there is already an entry with the given
+   key.  */
 int
-find_entry (hash_table *htab, const void *key, size_t keylen, void **result)
+hash_insert_entry (hash_table *htab,
+                  const void *key, size_t keylen,
+                  void *data)
 {
+  unsigned long int hval = compute_hashval (key, keylen);
   hash_entry *table = (hash_entry *) htab->table;
-  size_t idx = lookup (htab, key, keylen, compute_hashval (key, keylen));
+  size_t idx = lookup (htab, key, keylen, hval);
 
-  if (table[idx].used == 0)
+  if (table[idx].used)
+    /* We don't want to overwrite the old value.  */
     return -1;
+  else
+    {
+      /* An empty bucket has been found.  */
+      void *keycopy = obstack_copy (&htab->mem_pool, key, keylen);
+      insert_entry_2 (htab, keycopy, keylen, hval, idx, data);
+      if (100 * htab->filled > 75 * htab->size)
+       /* Table is filled more than 75%.  Resize the table.  */
+       resize (htab);
+      return 0;
+    }
+}
 
-  *result = table[idx].data;
-  return 0;
+
+/* Insert the pair (KEY[0..KEYLEN-1], DATA) in the hash table.
+   Return 0.  */
+int
+hash_set_value (hash_table *htab,
+               const void *key, size_t keylen,
+               void *data)
+{
+  unsigned long int hval = compute_hashval (key, keylen);
+  hash_entry *table = (hash_entry *) htab->table;
+  size_t idx = lookup (htab, key, keylen, hval);
+
+  if (table[idx].used)
+    {
+      /* Overwrite the old value.  */
+      table[idx].data = data;
+      return 0;
+    }
+  else
+    {
+      /* An empty bucket has been found.  */
+      void *keycopy = obstack_copy (&htab->mem_pool, key, keylen);
+      insert_entry_2 (htab, keycopy, keylen, hval, idx, data);
+      if (100 * htab->filled > 75 * htab->size)
+       /* Table is filled more than 75%.  Resize the table.  */
+       resize (htab);
+      return 0;
+    }
 }
 
 
+/* Steps *PTR forward to the next used entry in the given hash table.  *PTR
+   should be initially set to NULL.  Store information about the next entry
+   in *KEY, *KEYLEN, *DATA.
+   Return 0.  */
 int
-iterate_table (hash_table *htab, void **ptr, const void **key, size_t *keylen,
-              void **data)
+hash_iterate (hash_table *htab, void **ptr, const void **key, size_t *keylen,
+             void **data)
 {
   if (*ptr == NULL)
     {
@@ -188,7 +337,7 @@ iterate_table (hash_table *htab, void **ptr, const void **key, size_t *keylen,
     {
       if (*ptr == htab->first)
        return -1;
-      *ptr = (void *) (((hash_entry *) *ptr)->next);
+      *ptr = (void *) ((hash_entry *) *ptr)->next;
     }
 
   *key = ((hash_entry *) *ptr)->key;
@@ -196,98 +345,3 @@ iterate_table (hash_table *htab, void **ptr, const void **key, size_t *keylen,
   *data = ((hash_entry *) *ptr)->data;
   return 0;
 }
-
-
-/* References:
-   [Aho,Sethi,Ullman] Compilers: Principles, Techniques and Tools, 1986
-   [Knuth]           The Art of Computer Programming, part3 (6.4) */
-
-static size_t
-lookup (hash_table *htab,
-       const void *key, size_t keylen,
-       unsigned long int hval)
-{
-  unsigned long int hash;
-  size_t idx;
-  hash_entry *table = (hash_entry *) htab->table;
-
-  /* First hash function: simply take the modul but prevent zero.  */
-  hash = 1 + hval % htab->size;
-
-  idx = hash;
-
-  if (table[idx].used)
-    {
-      if (table[idx].used == hval && table[idx].keylen == keylen
-         && memcmp (table[idx].key, key, keylen) == 0)
-       return idx;
-
-      /* Second hash function as suggested in [Knuth].  */
-      hash = 1 + hval % (htab->size - 2);
-
-      do
-       {
-         if (idx <= hash)
-           idx = htab->size + idx - hash;
-         else
-           idx -= hash;
-
-         /* If entry is found use it.  */
-         if (table[idx].used == hval && table[idx].keylen == keylen
-             && memcmp (table[idx].key, key, keylen) == 0)
-           return idx;
-       }
-      while (table[idx].used);
-    }
-  return idx;
-}
-
-
-static unsigned long
-compute_hashval (const void *key, size_t keylen)
-{
-  size_t cnt;
-  unsigned long int hval;
-
-  /* Compute the hash value for the given string.  The algorithm
-     is taken from [Aho,Sethi,Ullman].  */
-  cnt = 0;
-  hval = keylen;
-  while (cnt < keylen)
-    {
-      hval = (hval << 9) | (hval >> (sizeof (unsigned long) * CHAR_BIT - 9));
-      hval += (unsigned long int) *(((const char *) key) + cnt++);
-    }
-  return hval != 0 ? hval : ~((unsigned long) 0);
-}
-
-
-unsigned long
-next_prime (unsigned long int seed)
-{
-  /* Make it definitely odd.  */
-  seed |= 1;
-
-  while (!is_prime (seed))
-    seed += 2;
-
-  return seed;
-}
-
-
-static int
-is_prime (unsigned long int candidate)
-{
-  /* No even number and none less than 10 will be passed here.  */
-  unsigned long int divn = 3;
-  unsigned long int sq = divn * divn;
-
-  while (sq < candidate && candidate % divn != 0)
-    {
-      ++divn;
-      sq += 4 * divn;
-      ++divn;
-    }
-
-  return candidate % divn != 0;
-}
index 8a67868c758874c9f907370ca7f7006e3bb05f62..2e6ea52fae88221176e17b65bb458eee486fd4db 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 1995, 2000-2003 Free Software Foundation, Inc.
+/* Copyright (C) 1995, 2000-2003, 2005 Free Software Foundation, Inc.
 
    The GNU C Library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public License as
@@ -18,7 +18,7 @@
 #ifndef _HASH_H
 #define _HASH_H
 
-#include <obstack.h>
+#include "obstack.h"
 
 #ifdef __cplusplus
 extern "C" {
@@ -26,27 +26,51 @@ extern "C" {
 
 typedef struct hash_table
 {
-  unsigned long int size;
-  unsigned long int filled;
-  void *first;
-  void *table;
-  struct obstack mem_pool;
+  unsigned long int size;   /* Number of allocated entries.  */
+  unsigned long int filled; /* Number of used entries.  */
+  void *first;              /* Pointer to head of list of entries.  */
+  void *table;              /* Pointer to array of entries.  */
+  struct obstack mem_pool;  /* Memory pool holding the keys.  */
 }
 hash_table;
 
-extern int init_hash (hash_table *htab, unsigned long int init_size);
-extern int delete_hash (hash_table *htab);
-extern int insert_entry (hash_table *htab,
-                        const void *key, size_t keylen,
-                        void *data);
-extern int find_entry (hash_table *htab,
-                      const void *key, size_t keylen,
-                      void **result);
+/* Initialize a hash table.  INIT_SIZE > 1 is the initial number of available
+   entries.
+   Return 0 upon successful completion, -1 upon memory allocation error.  */
+extern int hash_init (hash_table *htab, unsigned long int init_size);
 
-extern int iterate_table (hash_table *htab, void **ptr,
-                         const void **key, size_t *keylen,
-                         void **data);
+/* Delete a hash table's contents.
+   Return 0 always.  */
+extern int hash_destroy (hash_table *htab);
 
+/* Look up the value of a key in the given table.
+   If found, return 0 and set *RESULT to it.  Otherwise return -1.  */
+extern int hash_find_entry (hash_table *htab,
+                           const void *key, size_t keylen,
+                           void **result);
+
+/* Try to insert the pair (KEY[0..KEYLEN-1], DATA) in the hash table.
+   Return 0 if successful, or -1 if there is already an entry with the given
+   key.  */
+extern int hash_insert_entry (hash_table *htab,
+                             const void *key, size_t keylen,
+                             void *data);
+
+/* Insert the pair (KEY[0..KEYLEN-1], DATA) in the hash table.
+   Return 0.  */
+extern int hash_set_value (hash_table *htab,
+                          const void *key, size_t keylen,
+                          void *data);
+
+/* Steps *PTR forward to the next used entry in the given hash table.  *PTR
+   should be initially set to NULL.  Store information about the next entry
+   in *KEY, *KEYLEN, *DATA.
+   Return 0.  */
+extern int hash_iterate (hash_table *htab, void **ptr,
+                        const void **key, size_t *keylen,
+                        void **data);
+
+/* Given SEED > 1, return the smallest odd prime number >= SEED.  */
 extern unsigned long int next_prime (unsigned long int seed);
 
 #ifdef __cplusplus
index d9b55785841474fcdae26166f4b9a25eeb5b7420..b2b30108a8c865a6079fc61f3673029bf230dedd 100644 (file)
@@ -229,7 +229,7 @@ message_list_alloc (bool use_hashtable)
   mlp->nitems_max = 0;
   mlp->item = NULL;
   if ((mlp->use_hashtable = use_hashtable))
-    init_hash (&mlp->htable, 10);
+    hash_init (&mlp->htable, 10);
   return mlp;
 }
 
@@ -244,7 +244,7 @@ message_list_free (message_list_ty *mlp)
   if (mlp->item)
     free (mlp->item);
   if (mlp->use_hashtable)
-    delete_hash (&mlp->htable);
+    hash_destroy (&mlp->htable);
   free (mlp);
 }
 
@@ -276,7 +276,7 @@ message_list_hash_insert_entry (hash_table *htable, message_ty *mp)
       keylen = strlen (mp->msgid) + 1;
     }
 
-  found = insert_entry (htable, key, keylen, mp);
+  found = hash_insert_entry (htable, key, keylen, mp);
 
   if (mp->msgctxt != NULL)
     freesa (alloced_key);
@@ -374,7 +374,7 @@ message_list_delete_nth (message_list_ty *mlp, size_t n)
   if (mlp->use_hashtable)
     {
       /* Our simple-minded hash tables don't support removal.  */
-      delete_hash (&mlp->htable);
+      hash_destroy (&mlp->htable);
       mlp->use_hashtable = false;
     }
 }
@@ -393,7 +393,7 @@ message_list_remove_if_not (message_list_ty *mlp,
   if (mlp->use_hashtable && i < mlp->nitems)
     {
       /* Our simple-minded hash tables don't support removal.  */
-      delete_hash (&mlp->htable);
+      hash_destroy (&mlp->htable);
       mlp->use_hashtable = false;
     }
   mlp->nitems = i;
@@ -408,8 +408,8 @@ message_list_msgids_changed (message_list_ty *mlp)
       unsigned long int size = mlp->htable.size;
       size_t j;
 
-      delete_hash (&mlp->htable);
-      init_hash (&mlp->htable, size);
+      hash_destroy (&mlp->htable);
+      hash_init (&mlp->htable, size);
 
       for (j = 0; j < mlp->nitems; j++)
        {
@@ -420,7 +420,7 @@ message_list_msgids_changed (message_list_ty *mlp)
               the assertion that it wouldn't have duplicates, and before the
               msgids changed it indeed didn't have duplicates.  */
            {
-             delete_hash (&mlp->htable);
+             hash_destroy (&mlp->htable);
              mlp->use_hashtable = false;
              return true;
            }
@@ -461,7 +461,7 @@ message_list_search (message_list_ty *mlp,
 
       {
        void *htable_value;
-       int found = !find_entry (&mlp->htable, key, keylen, &htable_value);
+       int found = !hash_find_entry (&mlp->htable, key, keylen, &htable_value);
 
        if (msgctxt != NULL)
          freesa (alloced_key);
index c4ee7b65447627d3906ab910107ea33c9a8a7373..b32ae30ffd792eac5fdc510fcd9b3521183c80b3 100644 (file)
@@ -495,15 +495,15 @@ write_qm (FILE *output_file, message_list_ty *mlp)
        unsigned long table_size;
 
        /* Collect the contexts, removing duplicates.  */
-       init_hash (&all_contexts, 10);
+       hash_init (&all_contexts, 10);
        for (j = 0; j < mlp->nitems; j++)
          {
            message_ty *mp = mlp->item[j];
 
            if (!is_header (mp))
-             insert_entry (&all_contexts,
-                           mp->msgctxt, strlen (mp->msgctxt) + 1,
-                           NULL);
+             hash_insert_entry (&all_contexts,
+                                mp->msgctxt, strlen (mp->msgctxt) + 1,
+                                NULL);
          }
 
        /* Compute the number of different contexts.  */
@@ -541,7 +541,7 @@ write_qm (FILE *output_file, message_list_ty *mlp)
            void *null;
 
            iter = NULL;
-           while (iterate_table (&all_contexts, &iter, &key, &keylen, &null)
+           while (hash_iterate (&all_contexts, &iter, &key, &keylen, &null)
                   == 0)
              {
                const char *context = (const char *)key;
@@ -638,7 +638,7 @@ write_qm (FILE *output_file, message_list_ty *mlp)
          free (list_memory);
        }
 
-       delete_hash (&all_contexts);
+       hash_destroy (&all_contexts);
       }
   }
 
index 1a3b7af224ba32514e80e069b5a83a090744a474..95c9bc1cb841091e05042a9079d356a6e057045d 100644 (file)
@@ -1,5 +1,5 @@
 /* xgettext awk backend.
-   Copyright (C) 2002-2003 Free Software Foundation, Inc.
+   Copyright (C) 2002-2003, 2005 Free Software Foundation, Inc.
 
    This file was written by Bruno Haible <haible@clisp.cons.org>, 2002.
 
@@ -72,7 +72,7 @@ x_awk_keyword (const char *name)
       const char *colon;
 
       if (keywords.table == NULL)
-       init_hash (&keywords, 100);
+       hash_init (&keywords, 100);
 
       split_keywordspec (name, &end, &argnum1, &argnum2);
 
@@ -83,8 +83,8 @@ x_awk_keyword (const char *name)
        {
          if (argnum1 == 0)
            argnum1 = 1;
-         insert_entry (&keywords, name, end - name,
-                       (void *) (long) (argnum1 + (argnum2 << 10)));
+         hash_insert_entry (&keywords, name, end - name,
+                            (void *) (long) (argnum1 + (argnum2 << 10)));
        }
     }
 }
@@ -744,8 +744,8 @@ extract_parenthesized (message_list_ty *mlp,
          {
            void *keyword_value;
 
-           if (find_entry (&keywords, token.string, strlen (token.string),
-                           &keyword_value)
+           if (hash_find_entry (&keywords, token.string, strlen (token.string),
+                                &keyword_value)
                == 0)
              {
                int argnum1 = (int) (long) keyword_value & ((1 << 10) - 1);
index 6e868efbf111899488d7ddc8dfe6a12ab937402a..624cd2de0b1f7fad2637cc4c67afa9caad59b3ca 100644 (file)
@@ -1,5 +1,5 @@
 /* xgettext C/C++/ObjectiveC backend.
-   Copyright (C) 1995-1998, 2000-2004 Free Software Foundation, Inc.
+   Copyright (C) 1995-1998, 2000-2005 Free Software Foundation, Inc.
 
    This file was written by Peter Miller <millerp@canb.auug.org.au>
 
@@ -117,7 +117,7 @@ add_keyword (const char *name, hash_table *keywords)
       const char *colon;
 
       if (keywords->table == NULL)
-       init_hash (keywords, 100);
+       hash_init (keywords, 100);
 
       split_keywordspec (name, &end, &argnum1, &argnum2);
 
@@ -128,8 +128,8 @@ add_keyword (const char *name, hash_table *keywords)
        {
          if (argnum1 == 0)
            argnum1 = 1;
-         insert_entry (keywords, name, end - name,
-                       (void *) (long) (argnum1 + (argnum2 << 10)));
+         hash_insert_entry (keywords, name, end - name,
+                            (void *) (long) (argnum1 + (argnum2 << 10)));
        }
     }
 }
@@ -1564,8 +1564,9 @@ x_c_lex (xgettext_token_ty *tp)
        case token_type_name:
          last_non_comment_line = newline_count;
 
-         if (find_entry (objc_extensions ? &objc_keywords : &c_keywords,
-                         token.string, strlen (token.string), &keyword_value)
+         if (hash_find_entry (objc_extensions ? &objc_keywords : &c_keywords,
+                              token.string, strlen (token.string),
+                              &keyword_value)
              == 0)
            {
              tp->type = xgettext_token_type_keyword;
index 91b939e69d4c32bc9dd9077dcf73741869e102ac..a8667203cbaf798dff6a0a47528392ee20231b2f 100644 (file)
@@ -80,7 +80,7 @@ x_csharp_keyword (const char *name)
       const char *colon;
 
       if (keywords.table == NULL)
-       init_hash (&keywords, 100);
+       hash_init (&keywords, 100);
 
       split_keywordspec (name, &end, &argnum1, &argnum2);
 
@@ -92,8 +92,8 @@ x_csharp_keyword (const char *name)
        {
          if (argnum1 == 0)
            argnum1 = 1;
-         insert_entry (&keywords, name, end - name,
-                       (void *) (long) (argnum1 + (argnum2 << 10)));
+         hash_insert_entry (&keywords, name, end - name,
+                            (void *) (long) (argnum1 + (argnum2 << 10)));
        }
     }
 }
@@ -1949,8 +1949,8 @@ extract_parenthesized (message_list_ty *mlp, token_type_ty terminator,
              {
                void *keyword_value;
 
-               if (find_entry (&keywords, dottedname, strlen (dottedname),
-                               &keyword_value)
+               if (hash_find_entry (&keywords, dottedname, strlen (dottedname),
+                                    &keyword_value)
                    == 0)
                  {
                    int argnum1 = (int) (long) keyword_value & ((1 << 10) - 1);
index bcaeadc4cb76722121c14943ada7175a6cded768..a27fa1e06b83a1cf86a48e9248dbd58f955cc0dc 100644 (file)
@@ -1,5 +1,5 @@
 /* xgettext Emacs Lisp backend.
-   Copyright (C) 2001-2003 Free Software Foundation, Inc.
+   Copyright (C) 2001-2003, 2005 Free Software Foundation, Inc.
 
    This file was written by Bruno Haible <haible@clisp.cons.org>, 2001-2002.
 
@@ -87,7 +87,7 @@ x_elisp_keyword (const char *name)
       const char *colon;
 
       if (keywords.table == NULL)
-       init_hash (&keywords, 100);
+       hash_init (&keywords, 100);
 
       split_keywordspec (name, &end, &argnum1, &argnum2);
 
@@ -98,8 +98,8 @@ x_elisp_keyword (const char *name)
        {
          if (argnum1 == 0)
            argnum1 = 1;
-         insert_entry (&keywords, name, end - name,
-                       (void *) (long) (argnum1 + (argnum2 << 10)));
+         hash_insert_entry (&keywords, name, end - name,
+                            (void *) (long) (argnum1 + (argnum2 << 10)));
        }
     }
 }
@@ -690,9 +690,9 @@ read_object (struct object *op, bool first_in_list, bool new_backquote_flag,
                        char *symbol_name = string_of_object (&inner);
                        void *keyword_value;
 
-                       if (find_entry (&keywords,
-                                       symbol_name, strlen (symbol_name),
-                                       &keyword_value)
+                       if (hash_find_entry (&keywords,
+                                            symbol_name, strlen (symbol_name),
+                                            &keyword_value)
                            == 0)
                          {
                            argnum1 = (int) (long) keyword_value & ((1 << 10) - 1);
index 1cf7f8f174b0676e13f9b284a3e5da8ec120c5d3..1f6648a20c92582fd9d5261ec9a3be372a1af3c7 100644 (file)
@@ -1,5 +1,5 @@
 /* xgettext glade backend.
-   Copyright (C) 2002-2003 Free Software Foundation, Inc.
+   Copyright (C) 2002-2003, 2005 Free Software Foundation, Inc.
 
    This file was written by Bruno Haible <haible@clisp.cons.org>, 2002.
 
@@ -78,9 +78,9 @@ x_glade_keyword (const char *name)
   else
     {
       if (keywords.table == NULL)
-       init_hash (&keywords, 100);
+       hash_init (&keywords, 100);
 
-      insert_entry (&keywords, name, strlen (name), NULL);
+      hash_insert_entry (&keywords, name, strlen (name), NULL);
     }
 }
 
@@ -234,7 +234,7 @@ start_element_handler (void *userData, const char *name,
   /* In Glade 1, a few specific elements are translatable.  */
   if (!p->extract_string)
     p->extract_string =
-      (find_entry (&keywords, name, strlen (name), &hash_result) == 0);
+      (hash_find_entry (&keywords, name, strlen (name), &hash_result) == 0);
   /* In Glade 2, all <property> and <atkproperty> elements are translatable
      that have the attribute translatable="yes".  */
   if (!p->extract_string
index eb7f5d7daad1f18e9ed71d9aabb266e46bcc056b..01bf2c54edb2abb7384edc014b59a72f3dd50806 100644 (file)
@@ -1,5 +1,5 @@
 /* xgettext Java backend.
-   Copyright (C) 2003 Free Software Foundation, Inc.
+   Copyright (C) 2003, 2005 Free Software Foundation, Inc.
    Written by Bruno Haible <bruno@clisp.org>, 2003.
 
    This program is free software; you can redistribute it and/or modify
@@ -78,7 +78,7 @@ x_java_keyword (const char *name)
       const char *colon;
 
       if (keywords.table == NULL)
-       init_hash (&keywords, 100);
+       hash_init (&keywords, 100);
 
       split_keywordspec (name, &end, &argnum1, &argnum2);
 
@@ -90,8 +90,8 @@ x_java_keyword (const char *name)
        {
          if (argnum1 == 0)
            argnum1 = 1;
-         insert_entry (&keywords, name, end - name,
-                       (void *) (long) (argnum1 + (argnum2 << 10)));
+         hash_insert_entry (&keywords, name, end - name,
+                            (void *) (long) (argnum1 + (argnum2 << 10)));
        }
     }
 }
@@ -1261,8 +1261,8 @@ extract_parenthesized (message_list_ty *mlp, token_type_ty terminator,
              {
                void *keyword_value;
 
-               if (find_entry (&keywords, dottedname, strlen (dottedname),
-                               &keyword_value)
+               if (hash_find_entry (&keywords, dottedname, strlen (dottedname),
+                                    &keyword_value)
                    == 0)
                  {
                    int argnum1 = (int) (long) keyword_value & ((1 << 10) - 1);
index 74db90fa292f44ca764454301bc6e384a87da4e2..8ef65d4b1f35fde66a3cfa988b53dafe0e29859d 100644 (file)
@@ -1,5 +1,5 @@
 /* xgettext librep backend.
-   Copyright (C) 2001-2003 Free Software Foundation, Inc.
+   Copyright (C) 2001-2003, 2005 Free Software Foundation, Inc.
 
    This file was written by Bruno Haible <haible@clisp.cons.org>, 2001.
 
@@ -89,7 +89,7 @@ x_librep_keyword (const char *name)
       const char *colon;
 
       if (keywords.table == NULL)
-       init_hash (&keywords, 100);
+       hash_init (&keywords, 100);
 
       split_keywordspec (name, &end, &argnum1, &argnum2);
 
@@ -100,8 +100,8 @@ x_librep_keyword (const char *name)
        {
          if (argnum1 == 0)
            argnum1 = 1;
-         insert_entry (&keywords, name, end - name,
-                       (void *) (long) (argnum1 + (argnum2 << 10)));
+         hash_insert_entry (&keywords, name, end - name,
+                            (void *) (long) (argnum1 + (argnum2 << 10)));
        }
     }
 }
@@ -664,9 +664,9 @@ read_object (struct object *op, flag_context_ty outer_context)
                        char *symbol_name = string_of_object (&inner);
                        void *keyword_value;
 
-                       if (find_entry (&keywords,
-                                       symbol_name, strlen (symbol_name),
-                                       &keyword_value)
+                       if (hash_find_entry (&keywords,
+                                            symbol_name, strlen (symbol_name),
+                                            &keyword_value)
                            == 0)
                          {
                            argnum1 = (int) (long) keyword_value & ((1 << 10) - 1);
index 6b1777269dc937cd5b6b4e54f2c9fd37c2f57abf..2617b214accc202505ae39ff49c749ec1d7ad497 100644 (file)
@@ -133,7 +133,7 @@ x_lisp_keyword (const char *name)
       size_t i;
 
       if (keywords.table == NULL)
-       init_hash (&keywords, 100);
+       hash_init (&keywords, 100);
 
       split_keywordspec (name, &end, &argnum1, &argnum2);
 
@@ -159,8 +159,8 @@ x_lisp_keyword (const char *name)
 
       if (argnum1 == 0)
        argnum1 = 1;
-      insert_entry (&keywords, symname, len,
-                   (void *) (long) (argnum1 + (argnum2 << 10)));
+      hash_insert_entry (&keywords, symname, len,
+                        (void *) (long) (argnum1 + (argnum2 << 10)));
     }
 }
 
@@ -1065,10 +1065,10 @@ read_object (struct object *op, flag_context_ty outer_context)
                              i--;
                            prefix_len = i;
 
-                           if (find_entry (&keywords,
-                                           symbol_name + prefix_len,
-                                           strlen (symbol_name + prefix_len),
-                                           &keyword_value)
+                           if (hash_find_entry (&keywords,
+                                                symbol_name + prefix_len,
+                                                strlen (symbol_name + prefix_len),
+                                                &keyword_value)
                                == 0)
                              {
                                argnum1 = (int) (long) keyword_value & ((1 << 10) - 1);
index 0258ea9374559938ead9f26cf971908aabace1f3..cc7d4104d8aa65d563f72baaa311d36847cd76ae 100644 (file)
@@ -1,5 +1,5 @@
 /* xgettext Perl backend.
-   Copyright (C) 2002-2004 Free Software Foundation, Inc.
+   Copyright (C) 2002-2005 Free Software Foundation, Inc.
 
    This file was written by Guido Flohr <guido@imperia.net>, 2002-2003.
 
@@ -79,7 +79,7 @@ x_perl_keyword (const char *name)
       const char *colon;
 
       if (keywords.table == NULL)
-       init_hash (&keywords, 100);
+       hash_init (&keywords, 100);
 
       split_keywordspec (name, &end, &argnum1, &argnum2);
 
@@ -90,8 +90,8 @@ x_perl_keyword (const char *name)
        {
          if (argnum1 == 0)
            argnum1 = 1;
-         insert_entry (&keywords, name, end - name,
-                       (void *) (long) (argnum1 + (argnum2 << 10)));
+         hash_insert_entry (&keywords, name, end - name,
+                            (void *) (long) (argnum1 + (argnum2 << 10)));
        }
     }
 }
@@ -1497,8 +1497,8 @@ extract_variable (message_list_ty *mlp, token_ty *tp, int first)
                   real_file_name, line_number);
 #endif
 
-         if (find_entry (&keywords, tp->string, strlen (tp->string),
-                         &keyword_value) == 0)
+         if (hash_find_entry (&keywords, tp->string, strlen (tp->string),
+                              &keyword_value) == 0)
            {
              /* Extract a possible string from the key.  Before proceeding
                 we check whether the open curly is followed by a symbol and
@@ -1754,7 +1754,8 @@ interpolate_keywords (message_list_ty *mlp, const char *string, int lineno)
          switch (c)
            {
            case '-':
-             if (find_entry (&keywords, buffer, bufpos, &keyword_value) == 0)
+             if (hash_find_entry (&keywords, buffer, bufpos, &keyword_value)
+                 == 0)
                {
                  flag_context_list_iterator_ty context_iter =
                    flag_context_list_iterator (
@@ -1773,7 +1774,8 @@ interpolate_keywords (message_list_ty *mlp, const char *string, int lineno)
            case '{':
              if (!maybe_hash_deref)
                buffer[0] = '%';
-             if (find_entry (&keywords, buffer, bufpos, &keyword_value) == 0)
+             if (hash_find_entry (&keywords, buffer, bufpos, &keyword_value)
+                 == 0)
                {
                  flag_context_list_iterator_ty context_iter =
                    flag_context_list_iterator (
@@ -2879,8 +2881,8 @@ extract_balanced (message_list_ty *mlp, int state, token_type_ty delim,
          {
            void *keyword_value;
 
-           if (find_entry (&keywords, tp->string, strlen (tp->string),
-                           &keyword_value) == 0)
+           if (hash_find_entry (&keywords, tp->string, strlen (tp->string),
+                                &keyword_value) == 0)
              {
                last_token = token_type_keyword_symbol;
 
index 9c2bc1309ee1655640c5f9d68262016d1bd4063b..a0b9397f93c69ad3e89db6172e97bcf9a6320794 100644 (file)
@@ -1,5 +1,5 @@
 /* xgettext PHP backend.
-   Copyright (C) 2001-2003 Free Software Foundation, Inc.
+   Copyright (C) 2001-2003, 2005 Free Software Foundation, Inc.
 
    This file was written by Bruno Haible <bruno@clisp.org>, 2002.
 
@@ -72,7 +72,7 @@ x_php_keyword (const char *name)
       const char *colon;
 
       if (keywords.table == NULL)
-       init_hash (&keywords, 100);
+       hash_init (&keywords, 100);
 
       split_keywordspec (name, &end, &argnum1, &argnum2);
 
@@ -83,8 +83,8 @@ x_php_keyword (const char *name)
        {
          if (argnum1 == 0)
            argnum1 = 1;
-         insert_entry (&keywords, name, end - name,
-                       (void *) (long) (argnum1 + (argnum2 << 10)));
+         hash_insert_entry (&keywords, name, end - name,
+                            (void *) (long) (argnum1 + (argnum2 << 10)));
        }
     }
 }
@@ -1257,8 +1257,8 @@ extract_parenthesized (message_list_ty *mlp,
          {
            void *keyword_value;
 
-           if (find_entry (&keywords, token.string, strlen (token.string),
-                           &keyword_value)
+           if (hash_find_entry (&keywords, token.string, strlen (token.string),
+                                &keyword_value)
                == 0)
              {
                int argnum1 = (int) (long) keyword_value & ((1 << 10) - 1);
index 21c686a6275bcbafb689bd3058f4d3d827b54e11..009390479e988aa94ab1e125b342b3ac5e9d3b51 100644 (file)
@@ -89,7 +89,7 @@ x_python_keyword (const char *name)
       const char *colon;
 
       if (keywords.table == NULL)
-       init_hash (&keywords, 100);
+       hash_init (&keywords, 100);
 
       split_keywordspec (name, &end, &argnum1, &argnum2);
 
@@ -100,8 +100,8 @@ x_python_keyword (const char *name)
        {
          if (argnum1 == 0)
            argnum1 = 1;
-         insert_entry (&keywords, name, end - name,
-                       (void *) (long) (argnum1 + (argnum2 << 10)));
+         hash_insert_entry (&keywords, name, end - name,
+                            (void *) (long) (argnum1 + (argnum2 << 10)));
        }
     }
 }
@@ -1689,8 +1689,8 @@ extract_parenthesized (message_list_ty *mlp,
          {
            void *keyword_value;
 
-           if (find_entry (&keywords, token.string, strlen (token.string),
-                           &keyword_value)
+           if (hash_find_entry (&keywords, token.string, strlen (token.string),
+                                &keyword_value)
                == 0)
              {
                int argnum1 = (int) (long) keyword_value & ((1 << 10) - 1);
index a758f4b1167a1a857886f3d00748f85484ece7e6..113509ea8f9b1275fe291bcb3e4aa17f0d4c49f4 100644 (file)
@@ -99,7 +99,7 @@ x_scheme_keyword (const char *name)
       const char *colon;
 
       if (keywords.table == NULL)
-       init_hash (&keywords, 100);
+       hash_init (&keywords, 100);
 
       split_keywordspec (name, &end, &argnum1, &argnum2);
 
@@ -118,8 +118,8 @@ x_scheme_keyword (const char *name)
 
       if (argnum1 == 0)
        argnum1 = 1;
-      insert_entry (&keywords, name, end - name,
-                   (void *) (long) (argnum1 + (argnum2 << 10)));
+      hash_insert_entry (&keywords, name, end - name,
+                        (void *) (long) (argnum1 + (argnum2 << 10)));
     }
 }
 
@@ -773,9 +773,9 @@ read_object (struct object *op, flag_context_ty outer_context)
                        char *symbol_name = string_of_object (&inner);
                        void *keyword_value;
 
-                       if (find_entry (&keywords,
-                                       symbol_name, strlen (symbol_name),
-                                       &keyword_value)
+                       if (hash_find_entry (&keywords,
+                                            symbol_name, strlen (symbol_name),
+                                            &keyword_value)
                            == 0)
                          {
                            argnum1 = (int) (long) keyword_value & ((1 << 10) - 1);
index 66e913fb3d54bccff4efbcd1852fffb4b8610aaa..6f0b82e541cbf49e8174660de2693553c7b75e4e 100644 (file)
@@ -90,7 +90,7 @@ x_sh_keyword (const char *name)
       const char *colon;
 
       if (keywords.table == NULL)
-       init_hash (&keywords, 100);
+       hash_init (&keywords, 100);
 
       split_keywordspec (name, &end, &argnum1, &argnum2);
 
@@ -101,8 +101,8 @@ x_sh_keyword (const char *name)
        {
          if (argnum1 == 0)
            argnum1 = 1;
-         insert_entry (&keywords, name, end - name,
-                       (void *) (long) (argnum1 + (argnum2 << 10)));
+         hash_insert_entry (&keywords, name, end - name,
+                            (void *) (long) (argnum1 + (argnum2 << 10)));
        }
     }
 }
@@ -1191,9 +1191,9 @@ read_command (int looking_for, flag_context_ty outer_context)
                  char *function_name = string_of_word (&inner);
                  void *keyword_value;
 
-                 if (find_entry (&keywords,
-                                 function_name, strlen (function_name),
-                                 &keyword_value)
+                 if (hash_find_entry (&keywords,
+                                      function_name, strlen (function_name),
+                                      &keyword_value)
                      == 0)
                    {
                      argnum1 = (int) (long) keyword_value & ((1 << 10) - 1);
index 8af44361a201c8fa6c5578f9b0aa75aedbca64a9..eae7cf628b2e7b65a0049ad9780f35197a9050f7 100644 (file)
@@ -91,7 +91,7 @@ x_tcl_keyword (const char *name)
       int argnum2;
 
       if (keywords.table == NULL)
-       init_hash (&keywords, 100);
+       hash_init (&keywords, 100);
 
       split_keywordspec (name, &end, &argnum1, &argnum2);
 
@@ -102,8 +102,8 @@ x_tcl_keyword (const char *name)
 
       if (argnum1 == 0)
        argnum1 = 1;
-      insert_entry (&keywords, name, end - name,
-                   (void *) (long) (argnum1 + (argnum2 << 10)));
+      hash_insert_entry (&keywords, name, end - name,
+                        (void *) (long) (argnum1 + (argnum2 << 10)));
     }
 }
 
@@ -904,9 +904,9 @@ read_command (int looking_for, flag_context_ty outer_context)
                if (function_name[0] == ':' && function_name[1] == ':')
                  stripped_name += 2;
 
-               if (find_entry (&keywords,
-                               stripped_name, strlen (stripped_name),
-                               &keyword_value)
+               if (hash_find_entry (&keywords,
+                                    stripped_name, strlen (stripped_name),
+                                    &keyword_value)
                    == 0)
                  {
                    argnum1 = (int) (long) keyword_value & ((1 << 10) - 1);
index c9c9fa0be6d83268fd3eb09abb9cfc9001fd6c2f..1aa34a5331db3b6577d8f7378e28a820a5f13469 100644 (file)
@@ -1103,7 +1103,7 @@ flag_context_list_table_lookup (flag_context_list_table_ty *flag_table,
   void *entry;
 
   if (flag_table->table != NULL
-      && find_entry (flag_table, key, keylen, &entry) == 0)
+      && hash_find_entry (flag_table, key, keylen, &entry) == 0)
     return (flag_context_list_ty *) entry;
   else
     return NULL;
@@ -1143,11 +1143,11 @@ flag_context_list_table_insert (flag_context_list_table_ty *table,
   /* Insert the pair (VALUE, PASS) at INDEX in the element numbered ARGNUM
      of the list corresponding to NAME in the TABLE.  */
   if (table->table == NULL)
-    init_hash (table, 100);
+    hash_init (table, 100);
   {
     void *entry;
 
-    if (find_entry (table, name_start, name_end - name_start, &entry) != 0)
+    if (hash_find_entry (table, name_start, name_end - name_start, &entry) != 0)
       {
        /* Create new hash table entry.  */
        flag_context_list_ty *list =
@@ -1168,7 +1168,7 @@ flag_context_list_table_insert (flag_context_list_table_ty *table,
            abort ();
          }
        list->next = NULL;
-       insert_entry (table, name_start, name_end - name_start, list);
+       hash_insert_entry (table, name_start, name_end - name_start, list);
       }
     else
       {