diff options
Diffstat (limited to 'locale')
-rw-r--r-- | locale/Makefile | 4 | ||||
-rw-r--r-- | locale/coll-lookup.c | 81 | ||||
-rw-r--r-- | locale/coll-lookup.h | 83 | ||||
-rw-r--r-- | locale/programs/3level.h | 3 | ||||
-rw-r--r-- | locale/programs/ld-collate.c | 83 | ||||
-rw-r--r-- | locale/programs/locfile.c | 60 | ||||
-rw-r--r-- | locale/programs/locfile.h | 66 | ||||
-rw-r--r-- | locale/weightwc.h | 2 |
8 files changed, 212 insertions, 170 deletions
diff --git a/locale/Makefile b/locale/Makefile index 976926bb8e..2f2d2ba5f1 100644 --- a/locale/Makefile +++ b/locale/Makefile @@ -1,4 +1,4 @@ -# Copyright (C) 1991,92,1995-1999,2000,2001,2002 Free Software Foundation, Inc. +# Copyright (C) 1991,1992,1995-2002,2003 Free Software Foundation, Inc. # This file is part of the GNU C Library. # The GNU C Library is free software; you can redistribute it and/or @@ -42,7 +42,7 @@ tests = tst-C-locale categories = ctype messages monetary numeric time paper name \ address telephone measurement identification collate aux = $(categories:%=lc-%) $(categories:%=C-%) SYS_libc C_name \ - xlocale localename global-locale + xlocale localename global-locale coll-lookup others = localedef locale #others-static = localedef locale install-bin = localedef locale diff --git a/locale/coll-lookup.c b/locale/coll-lookup.c new file mode 100644 index 0000000000..6c765727cc --- /dev/null +++ b/locale/coll-lookup.c @@ -0,0 +1,81 @@ +/* Copyright (C) 2000, 2003 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Bruno Haible <haible@clisp.cons.org>, 2000. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <stdint.h> + +/* Lookup in a table of int32_t, with default value 0. */ +int32_t +internal_function +__collidx_table_lookup (const char *table, uint32_t wc) +{ + uint32_t shift1 = ((const uint32_t *) table)[0]; + uint32_t index1 = wc >> shift1; + uint32_t bound = ((const uint32_t *) table)[1]; + if (index1 < bound) + { + uint32_t lookup1 = ((const uint32_t *) table)[5 + index1]; + if (lookup1 != 0) + { + uint32_t shift2 = ((const uint32_t *) table)[2]; + uint32_t mask2 = ((const uint32_t *) table)[3]; + uint32_t index2 = (wc >> shift2) & mask2; + uint32_t lookup2 = ((const uint32_t *)(table + lookup1))[index2]; + if (lookup2 != 0) + { + uint32_t mask3 = ((const uint32_t *) table)[4]; + uint32_t index3 = wc & mask3; + int32_t lookup3 = ((const int32_t *)(table + lookup2))[index3]; + + return lookup3; + } + } + } + return 0; +} + + +/* Lookup in a table of uint32_t, with default value 0xffffffff. */ +uint32_t +internal_function +__collseq_table_lookup (const char *table, uint32_t wc) +{ + uint32_t shift1 = ((const uint32_t *) table)[0]; + uint32_t index1 = wc >> shift1; + uint32_t bound = ((const uint32_t *) table)[1]; + if (index1 < bound) + { + uint32_t lookup1 = ((const uint32_t *) table)[5 + index1]; + if (lookup1 != 0) + { + uint32_t shift2 = ((const uint32_t *) table)[2]; + uint32_t mask2 = ((const uint32_t *) table)[3]; + uint32_t index2 = (wc >> shift2) & mask2; + uint32_t lookup2 = ((const uint32_t *)(table + lookup1))[index2]; + if (lookup2 != 0) + { + uint32_t mask3 = ((const uint32_t *) table)[4]; + uint32_t index3 = wc & mask3; + uint32_t lookup3 = ((const uint32_t *)(table + lookup2))[index3]; + + return lookup3; + } + } + } + return ~((uint32_t) 0); +} diff --git a/locale/coll-lookup.h b/locale/coll-lookup.h index 6a396fa878..3fe6bafb71 100644 --- a/locale/coll-lookup.h +++ b/locale/coll-lookup.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2000 Free Software Foundation, Inc. +/* Copyright (C) 2000, 2003 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Bruno Haible <haible@clisp.cons.org>, 2000. @@ -17,85 +17,12 @@ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -/* Word tables are accessed by cutting wc in three blocks of bits: - - the high 32-q-p bits, - - the next q bits, - - the next p bits. - - +------------------+-----+-----+ - wc = + 32-q-p | q | p | - +------------------+-----+-----+ - - p and q are variable. For 16-bit Unicode it is sufficient to - choose p and q such that q+p <= 16. - - The table contains the following uint32_t words: - - q+p, - - s = upper exclusive bound for wc >> (q+p), - - p, - - 2^q-1, - - 2^p-1, - - 1st-level table: s offsets, pointing into the 2nd-level table, - - 2nd-level table: k*2^q offsets, pointing into the 3rd-level table, - - 3rd-level table: j*2^p words, each containing 32 bits of data. -*/ - #include <stdint.h> /* Lookup in a table of int32_t, with default value 0. */ -static inline int32_t -collidx_table_lookup (const char *table, uint32_t wc) -{ - uint32_t shift1 = ((const uint32_t *) table)[0]; - uint32_t index1 = wc >> shift1; - uint32_t bound = ((const uint32_t *) table)[1]; - if (index1 < bound) - { - uint32_t lookup1 = ((const uint32_t *) table)[5 + index1]; - if (lookup1 != 0) - { - uint32_t shift2 = ((const uint32_t *) table)[2]; - uint32_t mask2 = ((const uint32_t *) table)[3]; - uint32_t index2 = (wc >> shift2) & mask2; - uint32_t lookup2 = ((const uint32_t *)(table + lookup1))[index2]; - if (lookup2 != 0) - { - uint32_t mask3 = ((const uint32_t *) table)[4]; - uint32_t index3 = wc & mask3; - int32_t lookup3 = ((const int32_t *)(table + lookup2))[index3]; - - return lookup3; - } - } - } - return 0; -} +extern int32_t __collidx_table_lookup (const char *table, uint32_t wc) + internal_function; /* Lookup in a table of uint32_t, with default value 0xffffffff. */ -static inline uint32_t -collseq_table_lookup (const char *table, uint32_t wc) -{ - uint32_t shift1 = ((const uint32_t *) table)[0]; - uint32_t index1 = wc >> shift1; - uint32_t bound = ((const uint32_t *) table)[1]; - if (index1 < bound) - { - uint32_t lookup1 = ((const uint32_t *) table)[5 + index1]; - if (lookup1 != 0) - { - uint32_t shift2 = ((const uint32_t *) table)[2]; - uint32_t mask2 = ((const uint32_t *) table)[3]; - uint32_t index2 = (wc >> shift2) & mask2; - uint32_t lookup2 = ((const uint32_t *)(table + lookup1))[index2]; - if (lookup2 != 0) - { - uint32_t mask3 = ((const uint32_t *) table)[4]; - uint32_t index3 = wc & mask3; - uint32_t lookup3 = ((const uint32_t *)(table + lookup2))[index3]; - - return lookup3; - } - } - } - return ~((uint32_t) 0); -} +extern uint32_t __collseq_table_lookup (const char *table, uint32_t wc) + internal_function; diff --git a/locale/programs/3level.h b/locale/programs/3level.h index f4d641d67c..ef4ba2bbc0 100644 --- a/locale/programs/3level.h +++ b/locale/programs/3level.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2000-2001 Free Software Foundation, Inc. +/* Copyright (C) 2000-2001, 2003 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Bruno Haible <haible@clisp.cons.org>, 2000. @@ -80,6 +80,7 @@ CONCAT(TABLE,_init) (struct TABLE *t) /* Retrieve an entry. */ static inline ELEMENT +__attribute ((always_inline)) CONCAT(TABLE,_get) (struct TABLE *t, uint32_t wc) { uint32_t index1 = wc >> (t->q + t->p); diff --git a/locale/programs/ld-collate.c b/locale/programs/ld-collate.c index 9d2bca437a..6d0d03c235 100644 --- a/locale/programs/ld-collate.c +++ b/locale/programs/ld-collate.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1995-1999, 2000, 2001, 2002 Free Software Foundation, Inc. +/* Copyright (C) 1995-2002, 2003 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@gnu.org>, 1995. @@ -42,6 +42,7 @@ #define obstack_chunk_free free static inline void +__attribute ((always_inline)) obstack_int32_grow (struct obstack *obstack, int32_t data) { if (sizeof (int32_t) == sizeof (int)) @@ -51,6 +52,7 @@ obstack_int32_grow (struct obstack *obstack, int32_t data) } static inline void +__attribute ((always_inline)) obstack_int32_grow_fast (struct obstack *obstack, int32_t data) { if (sizeof (int32_t) == sizeof (int)) @@ -249,6 +251,7 @@ static uint32_t nrules; /* We need UTF-8 encoding of numbers. */ static inline int +__attribute ((always_inline)) utf8_encode (char *buf, int val) { int retval; @@ -606,10 +609,10 @@ static struct element_t * find_element (struct linereader *ldfile, struct locale_collate_t *collate, const char *str, size_t len) { - struct element_t *result = NULL; + void *result = NULL; /* Search for the entries among the collation sequences already define. */ - if (find_entry (&collate->seq_table, str, len, (void **) &result) != 0) + if (find_entry (&collate->seq_table, str, len, &result) != 0) { /* Nope, not define yet. So we see whether it is a collation symbol. */ @@ -625,8 +628,7 @@ find_element (struct linereader *ldfile, struct locale_collate_t *collate, result = sym->order = new_element (collate, NULL, 0, NULL, NULL, 0, 0); } - else if (find_entry (&collate->elem_table, str, len, - (void **) &result) != 0) + else if (find_entry (&collate->elem_table, str, len, &result) != 0) { /* It's also no collation element. So it is a character element defined later. */ @@ -636,7 +638,7 @@ find_element (struct linereader *ldfile, struct locale_collate_t *collate, } } - return result; + return (struct element_t *) result; } @@ -944,8 +946,8 @@ insert_value (struct linereader *ldfile, const char *symstr, size_t symlen, { /* It's no character, so look through the collation elements and symbol list. */ - if (find_entry (&collate->elem_table, symstr, symlen, - (void **) &elem) != 0) + void *ptr = elem; + if (find_entry (&collate->elem_table, symstr, symlen, &ptr) != 0) { void *result; struct symbol_t *sym = NULL; @@ -976,12 +978,15 @@ insert_value (struct linereader *ldfile, const char *symstr, size_t symlen, insert_entry (&collate->seq_table, symstr, symlen, elem); } } + else + /* Copy the result back. */ + elem = ptr; } else { /* Otherwise the symbols stands for a character. */ - if (find_entry (&collate->seq_table, symstr, symlen, - (void **) &elem) != 0) + void *ptr = elem; + if (find_entry (&collate->seq_table, symstr, symlen, &ptr) != 0) { uint32_t wcs[2] = { wc, 0 }; @@ -998,6 +1003,9 @@ insert_value (struct linereader *ldfile, const char *symstr, size_t symlen, } else { + /* Copy the result back. */ + elem = ptr; + /* Maybe the character was used before the definition. In this case we have to insert the byte sequences now. */ if (elem->mbs == NULL && seq != NULL) @@ -1169,8 +1177,9 @@ sequence is not lower than that of the last character"), "LC_COLLATE"); /* Now we are ready to insert the new value in the sequence. Find out whether the element is already known. */ + void *ptr; if (find_entry (&collate->seq_table, seq->name, namelen, - (void **) &elem) != 0) + &ptr) != 0) { uint32_t wcs[2] = { seq->ucs4, 0 }; @@ -1186,6 +1195,9 @@ sequence is not lower than that of the last character"), "LC_COLLATE"); /* This cannot happen. */ assert (! "Internal error"); } + else + /* Copy the result. */ + elem = ptr; /* Test whether this element is not already in the list. */ if (elem->next != NULL || (collate->cursor != NULL @@ -1324,9 +1336,12 @@ order for `%.*s' already defined at %s:%Zu"), sprintf (buf + preflen, base == 10 ? "%ld" : "%lX", from); /* Look whether this name is already defined. */ - if (find_entry (&collate->seq_table, buf, symlen, - (void **) &elem) == 0) + void *ptr; + if (find_entry (&collate->seq_table, buf, symlen, &ptr) == 0) { + /* Copy back the result. */ + elem = ptr; + if (elem->next != NULL || (collate->cursor != NULL && elem->next == collate->cursor)) { @@ -3009,7 +3024,7 @@ collate_read (struct linereader *ldfile, struct localedef_t *result, size_t newname_len = arg->val.str.lenmb; const char *symname; size_t symname_len; - struct symbol_t *symval; + void *symval; /* Actually struct symbol_t* */ arg = lr_token (ldfile, charmap, result, repertoire, verbose); if (arg->tok != tok_bsymbol) @@ -3045,7 +3060,7 @@ collate_read (struct linereader *ldfile, struct localedef_t *result, /* See whether the symbol name is already defined. */ if (find_entry (&collate->sym_table, symname, symname_len, - (void **) &symval) != 0) + &symval) != 0) { lr_error (ldfile, _("\ %s: unknown symbol `%s' in equivalent definition"), @@ -3294,6 +3309,7 @@ error while adding equivalent collating symbol")); size_t lenmb; struct element_t *insp; int no_error = 1; + void *ptr; if (arg->tok == tok_bsymbol) { @@ -3307,18 +3323,20 @@ error while adding equivalent collating symbol")); lenmb = 9; } - if (find_entry (&collate->seq_table, startmb, lenmb, - (void **) &insp) == 0) + if (find_entry (&collate->seq_table, startmb, lenmb, &ptr) == 0) /* Yes, the symbol exists. Simply point the cursor to it. */ - collate->cursor = insp; + collate->cursor = (struct element_t *) ptr; else { struct symbol_t *symbp; + void *ptr; if (find_entry (&collate->sym_table, startmb, lenmb, - (void **) &symbp) == 0) + &ptr) == 0) { + symbp = ptr; + if (symbp->order->last != NULL || symbp->order->next != NULL) collate->cursor = symbp->order; @@ -3334,8 +3352,10 @@ error while adding equivalent collating symbol")); } } else if (find_entry (&collate->elem_table, startmb, lenmb, - (void **) &insp) == 0) + &ptr) == 0) { + insp = (struct element_t *) ptr; + if (insp->last != NULL || insp->next != NULL) collate->cursor = insp; else @@ -3517,10 +3537,12 @@ error while adding equivalent collating symbol")); collation symbols since these are purely abstract values and don't need directions associated. */ struct element_t *seqp; + void *ptr; - if (find_entry (&collate->seq_table, symstr, symlen, - (void **) &seqp) == 0) + if (find_entry (&collate->seq_table, symstr, symlen, &ptr) == 0) { + seqp = ptr; + /* It's already defined. First check whether this is really a collating symbol. */ if (seqp->is_character) @@ -3561,8 +3583,9 @@ error while adding equivalent collating symbol")); { /* It is possible that we already have this collation sequence. In this case we move the entry. */ - struct element_t *seqp; + struct element_t *seqp = NULL; void *sym; + void *ptr; /* If the symbol after which we have to insert was not found ignore all entries. */ @@ -3572,17 +3595,19 @@ error while adding equivalent collating symbol")); break; } - if (find_entry (&collate->seq_table, symstr, symlen, - (void **) &seqp) == 0) - goto move_entry; + if (find_entry (&collate->seq_table, symstr, symlen, &ptr) == 0) + { + seqp = (struct element_t *) ptr; + goto move_entry; + } if (find_entry (&collate->sym_table, symstr, symlen, &sym) == 0 && (seqp = ((struct symbol_t *) sym)->order) != NULL) goto move_entry; - if (find_entry (&collate->elem_table, symstr, symlen, - (void **) &seqp) == 0 - && (seqp->last != NULL || seqp->next != NULL + if (find_entry (&collate->elem_table, symstr, symlen, &ptr) == 0 + && (seqp = (struct element_t *) ptr, + seqp->last != NULL || seqp->next != NULL || (collate->start != NULL && seqp == collate->start))) { move_entry: diff --git a/locale/programs/locfile.c b/locale/programs/locfile.c index 1e8e434ee1..2eeed96141 100644 --- a/locale/programs/locfile.c +++ b/locale/programs/locfile.c @@ -764,3 +764,63 @@ cannot create output file `%s' for category `%s'"), fname, category)); free (fname); } + + +/* General handling of `copy'. */ +void +handle_copy (struct linereader *ldfile, const struct charmap_t *charmap, + const char *repertoire_name, struct localedef_t *result, + enum token_t token, int locale, const char *locale_name, + int ignore_content) +{ + struct token *now; + int warned = 0; + + now = lr_token (ldfile, charmap, result, NULL, verbose); + if (now->tok != tok_string) + lr_error (ldfile, _("expect string argument for `copy'")); + else if (!ignore_content) + { + if (now->val.str.startmb == NULL) + lr_error (ldfile, _("\ +locale name should consist only of portable characters")); + else + { + (void) add_to_readlist (locale, now->val.str.startmb, + repertoire_name, 1, NULL); + result->copy_name[locale] = now->val.str.startmb; + } + } + + lr_ignore_rest (ldfile, now->tok == tok_string); + + /* The rest of the line must be empty and the next keyword must be + `END xxx'. */ + while ((now = lr_token (ldfile, charmap, result, NULL, verbose))->tok + != tok_end && now->tok != tok_eof) + { + if (warned == 0) + { + lr_error (ldfile, _("\ +no other keyword shall be specified when `copy' is used")); + warned = 1; + } + + lr_ignore_rest (ldfile, 0); + } + + if (now->tok != tok_eof) + { + /* Handle `END xxx'. */ + now = lr_token (ldfile, charmap, result, NULL, verbose); + + if (now->tok != token) + lr_error (ldfile, _("\ +`%1$s' definition does not end with `END %1$s'"), locale_name); + + lr_ignore_rest (ldfile, now->tok == token); + } + else + /* When we come here we reached the end of the file. */ + lr_error (ldfile, _("%s: premature end of file"), locale_name); +} diff --git a/locale/programs/locfile.h b/locale/programs/locfile.h index 2e96c62ec7..db34f462e3 100644 --- a/locale/programs/locfile.h +++ b/locale/programs/locfile.h @@ -1,4 +1,4 @@ -/* Copyright (C) 1996-2001, 2002 Free Software Foundation, Inc. +/* Copyright (C) 1996-2001, 2002, 2003 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@gnu.org>, 1996. @@ -45,64 +45,12 @@ struct locale_file /* General handling of `copy'. */ -static inline void -handle_copy (struct linereader *ldfile, const struct charmap_t *charmap, - const char *repertoire_name, struct localedef_t *result, - enum token_t token, int locale, const char *locale_name, - int ignore_content) -{ - struct token *now; - int warned = 0; - - now = lr_token (ldfile, charmap, result, NULL, verbose); - if (now->tok != tok_string) - lr_error (ldfile, _("expect string argument for `copy'")); - else if (!ignore_content) - { - if (now->val.str.startmb == NULL) - lr_error (ldfile, _("\ -locale name should consist only of portable characters")); - else - { - (void) add_to_readlist (locale, now->val.str.startmb, - repertoire_name, 1, NULL); - result->copy_name[locale] = now->val.str.startmb; - } - } - - lr_ignore_rest (ldfile, now->tok == tok_string); - - /* The rest of the line must be empty and the next keyword must be - `END xxx'. */ - while ((now = lr_token (ldfile, charmap, result, NULL, verbose))->tok - != tok_end && now->tok != tok_eof) - { - if (warned == 0) - { - lr_error (ldfile, _("\ -no other keyword shall be specified when `copy' is used")); - warned = 1; - } - - lr_ignore_rest (ldfile, 0); - } - - if (now->tok != tok_eof) - { - /* Handle `END xxx'. */ - now = lr_token (ldfile, charmap, result, NULL, verbose); - - if (now->tok != token) - lr_error (ldfile, _("\ -`%1$s' definition does not end with `END %1$s'"), locale_name); - - lr_ignore_rest (ldfile, now->tok == token); - } - else - /* When we come here we reached the end of the file. */ - lr_error (ldfile, _("%s: premature end of file"), locale_name); -} - +extern void handle_copy (struct linereader *ldfile, + const struct charmap_t *charmap, + const char *repertoire_name, + struct localedef_t *result, enum token_t token, + int locale, const char *locale_name, + int ignore_content); /* Found in locfile.c. */ extern int locfile_read (struct localedef_t *result, diff --git a/locale/weightwc.h b/locale/weightwc.h index 649b7a77ad..9957893def 100644 --- a/locale/weightwc.h +++ b/locale/weightwc.h @@ -27,7 +27,7 @@ findidx (const wint_t **cpp) wint_t ch; ch = *(*cpp)++; - i = collidx_table_lookup ((const char *) table, ch); + i = __collidx_table_lookup ((const char *) table, ch); if (i >= 0) /* This is an index into the weight table. Cool. */ |