diff options
author | Bruno Haible <bruno@clisp.org> | 2005-10-07 11:21:50 +0000 |
---|---|---|
committer | Bruno Haible <bruno@clisp.org> | 2009-06-23 12:12:53 +0200 |
commit | 135b998c2230a94a19e4d66f3da1ea1a68f0728e (patch) | |
tree | 62d71a4fa6b867a9ffa19966e1a403f009a1d193 /gettext-tools | |
parent | f1f805bcf63cd5073235be63957b064899427516 (diff) | |
download | external_gettext-135b998c2230a94a19e4d66f3da1ea1a68f0728e.zip external_gettext-135b998c2230a94a19e4d66f3da1ea1a68f0728e.tar.gz external_gettext-135b998c2230a94a19e4d66f3da1ea1a68f0728e.tar.bz2 |
Revamp the hash table API.
Diffstat (limited to 'gettext-tools')
-rw-r--r-- | gettext-tools/lib/hash.c | 320 | ||||
-rw-r--r-- | gettext-tools/lib/hash.h | 60 | ||||
-rw-r--r-- | gettext-tools/src/message.c | 18 | ||||
-rw-r--r-- | gettext-tools/src/write-qt.c | 12 | ||||
-rw-r--r-- | gettext-tools/src/x-awk.c | 12 | ||||
-rw-r--r-- | gettext-tools/src/x-c.c | 13 | ||||
-rw-r--r-- | gettext-tools/src/x-csharp.c | 10 | ||||
-rw-r--r-- | gettext-tools/src/x-elisp.c | 14 | ||||
-rw-r--r-- | gettext-tools/src/x-glade.c | 8 | ||||
-rw-r--r-- | gettext-tools/src/x-java.c | 12 | ||||
-rw-r--r-- | gettext-tools/src/x-librep.c | 14 | ||||
-rw-r--r-- | gettext-tools/src/x-lisp.c | 14 | ||||
-rw-r--r-- | gettext-tools/src/x-perl.c | 22 | ||||
-rw-r--r-- | gettext-tools/src/x-php.c | 12 | ||||
-rw-r--r-- | gettext-tools/src/x-python.c | 10 | ||||
-rw-r--r-- | gettext-tools/src/x-scheme.c | 12 | ||||
-rw-r--r-- | gettext-tools/src/x-sh.c | 12 | ||||
-rw-r--r-- | gettext-tools/src/x-tcl.c | 12 | ||||
-rw-r--r-- | gettext-tools/src/xgettext.c | 8 |
19 files changed, 338 insertions, 257 deletions
diff --git a/gettext-tools/lib/hash.c b/gettext-tools/lib/hash.c index bf3d0bb..2a96210 100644 --- a/gettext-tools/lib/hash.c +++ b/gettext-tools/lib/hash.c @@ -29,37 +29,67 @@ #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; -} diff --git a/gettext-tools/lib/hash.h b/gettext-tools/lib/hash.h index 8a67868..2e6ea52 100644 --- a/gettext-tools/lib/hash.h +++ b/gettext-tools/lib/hash.h @@ -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 diff --git a/gettext-tools/src/message.c b/gettext-tools/src/message.c index d9b5578..b2b3010 100644 --- a/gettext-tools/src/message.c +++ b/gettext-tools/src/message.c @@ -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); diff --git a/gettext-tools/src/write-qt.c b/gettext-tools/src/write-qt.c index c4ee7b6..b32ae30 100644 --- a/gettext-tools/src/write-qt.c +++ b/gettext-tools/src/write-qt.c @@ -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); } } diff --git a/gettext-tools/src/x-awk.c b/gettext-tools/src/x-awk.c index 1a3b7af..95c9bc1 100644 --- a/gettext-tools/src/x-awk.c +++ b/gettext-tools/src/x-awk.c @@ -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); diff --git a/gettext-tools/src/x-c.c b/gettext-tools/src/x-c.c index 6e868ef..624cd2d 100644 --- a/gettext-tools/src/x-c.c +++ b/gettext-tools/src/x-c.c @@ -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; diff --git a/gettext-tools/src/x-csharp.c b/gettext-tools/src/x-csharp.c index 91b939e..a866720 100644 --- a/gettext-tools/src/x-csharp.c +++ b/gettext-tools/src/x-csharp.c @@ -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); diff --git a/gettext-tools/src/x-elisp.c b/gettext-tools/src/x-elisp.c index bcaeadc..a27fa1e 100644 --- a/gettext-tools/src/x-elisp.c +++ b/gettext-tools/src/x-elisp.c @@ -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); diff --git a/gettext-tools/src/x-glade.c b/gettext-tools/src/x-glade.c index 1cf7f8f..1f6648a 100644 --- a/gettext-tools/src/x-glade.c +++ b/gettext-tools/src/x-glade.c @@ -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 diff --git a/gettext-tools/src/x-java.c b/gettext-tools/src/x-java.c index eb7f5d7..01bf2c5 100644 --- a/gettext-tools/src/x-java.c +++ b/gettext-tools/src/x-java.c @@ -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); diff --git a/gettext-tools/src/x-librep.c b/gettext-tools/src/x-librep.c index 74db90f..8ef65d4 100644 --- a/gettext-tools/src/x-librep.c +++ b/gettext-tools/src/x-librep.c @@ -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); diff --git a/gettext-tools/src/x-lisp.c b/gettext-tools/src/x-lisp.c index 6b17772..2617b21 100644 --- a/gettext-tools/src/x-lisp.c +++ b/gettext-tools/src/x-lisp.c @@ -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); diff --git a/gettext-tools/src/x-perl.c b/gettext-tools/src/x-perl.c index 0258ea9..cc7d410 100644 --- a/gettext-tools/src/x-perl.c +++ b/gettext-tools/src/x-perl.c @@ -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; diff --git a/gettext-tools/src/x-php.c b/gettext-tools/src/x-php.c index 9c2bc13..a0b9397 100644 --- a/gettext-tools/src/x-php.c +++ b/gettext-tools/src/x-php.c @@ -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); diff --git a/gettext-tools/src/x-python.c b/gettext-tools/src/x-python.c index 21c686a..0093904 100644 --- a/gettext-tools/src/x-python.c +++ b/gettext-tools/src/x-python.c @@ -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); diff --git a/gettext-tools/src/x-scheme.c b/gettext-tools/src/x-scheme.c index a758f4b..113509e 100644 --- a/gettext-tools/src/x-scheme.c +++ b/gettext-tools/src/x-scheme.c @@ -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); diff --git a/gettext-tools/src/x-sh.c b/gettext-tools/src/x-sh.c index 66e913f..6f0b82e 100644 --- a/gettext-tools/src/x-sh.c +++ b/gettext-tools/src/x-sh.c @@ -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); diff --git a/gettext-tools/src/x-tcl.c b/gettext-tools/src/x-tcl.c index 8af4436..eae7cf6 100644 --- a/gettext-tools/src/x-tcl.c +++ b/gettext-tools/src/x-tcl.c @@ -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); diff --git a/gettext-tools/src/xgettext.c b/gettext-tools/src/xgettext.c index c9c9fa0..1aa34a5 100644 --- a/gettext-tools/src/xgettext.c +++ b/gettext-tools/src/xgettext.c @@ -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 { |