diff options
author | Ulrich Drepper <drepper@redhat.com> | 2000-01-29 02:54:27 +0000 |
---|---|---|
committer | Ulrich Drepper <drepper@redhat.com> | 2000-01-29 02:54:27 +0000 |
commit | 4295702fe36902ad82587748b918d828ce62c446 (patch) | |
tree | 538686004e11cb2af80a3be1e1fc5b95f859b4ff /locale | |
parent | 8217ddf5c6137488b6ea5b244f74c7668b800f83 (diff) | |
download | glibc-4295702fe36902ad82587748b918d828ce62c446.tar glibc-4295702fe36902ad82587748b918d828ce62c446.tar.gz glibc-4295702fe36902ad82587748b918d828ce62c446.tar.bz2 glibc-4295702fe36902ad82587748b918d828ce62c446.zip |
Update.
2000-01-28 Ulrich Drepper <drepper@cygnus.com>
* locale/C-monetary.c: Add initializers for new fields.
* locale/C-numeric.c: Likewise.
* locale/Makefile (distribute): Add indigits.h, indigitswc.h,
outdigits.h, and outdigitswc.h.
* locale/langinfo.h: Add _NL_MONETARY_DECIMAL_POINT_WC,
_NL_MONETARY_THOUSANDS_SEP_WC, _NL_NUMERIC_DECIMAL_POINT_WC,
and _NL_NUMERIC_THOUSANDS_SEP_WC.
* locale/indigits.h: New file.
* locale/indigitswc.h: New file.
* locale/outdigits.h: New file.
* locale/outdigitswc.h: New file.
* locale/programs/ld-monetary.c: Write out decimal point and
thousands separator info in wide character form.
* locale/programs/ld-numeric.c: Likewise.
* stdio-common/Makefile (routines): Add _i18n_itoa and _i18n_itowa.
(distribute): Add _i18n_itoa.h and _i18n_itowa.h.
* stdio-common/_i18n_itoa.c: New file.
* stdio-common/_i18n_itoa.h: New file.
* stdio-common/_i18n_itowa.c: New file.
* stdio-common/_i18n_itowa.h: New file.
* stdio-common/printf-parse.h: Parse 'I' flag.
* stdio-common/printf.h (struct printf_info): Add i18n field.
* stdio-common/vfprintf.c: Implement 'I' flag to print using locales'
outdigits.
Diffstat (limited to 'locale')
-rw-r--r-- | locale/Makefile | 1 | ||||
-rw-r--r-- | locale/indigits.h | 98 | ||||
-rw-r--r-- | locale/indigitswc.h | 88 | ||||
-rw-r--r-- | locale/langinfo.h | 6 | ||||
-rw-r--r-- | locale/outdigits.h | 45 | ||||
-rw-r--r-- | locale/outdigitswc.h | 35 | ||||
-rw-r--r-- | locale/programs/ld-monetary.c | 58 | ||||
-rw-r--r-- | locale/programs/ld-numeric.c | 47 |
8 files changed, 361 insertions, 17 deletions
diff --git a/locale/Makefile b/locale/Makefile index 71bd457dce..bc49c90636 100644 --- a/locale/Makefile +++ b/locale/Makefile @@ -24,6 +24,7 @@ subdir := locale headers = locale.h langinfo.h xlocale.h distribute = localeinfo.h categories.def iso-639.def iso-3166.def \ iso-4217.def weight.h strlen-hash.h elem-hash.h \ + indigits.h indigitswc.h outdigits.h outdigitswc.h \ $(addprefix programs/, \ locale.c localedef.c \ $(localedef-modules:=.c) $(locale-modules:=.c) \ diff --git a/locale/indigits.h b/locale/indigits.h new file mode 100644 index 0000000000..a5289cec06 --- /dev/null +++ b/locale/indigits.h @@ -0,0 +1,98 @@ +/* Copyright (C) 2000 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Ulrich Drepper <drepper@gnu.org>, 2000. + + 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 + published by the Free Software Foundation; either version 2 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with the GNU C Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ + +#include <assert.h> +#include <langinfo.h> +#include <string.h> + +/* Look up the value of the next multibyte character and return its numerical + value if it is one of the digits known in the locale. If *DECIDED is + -1 this means it is not yet decided which form it is and we have to + search through all available digits. Otherwise we know which script + the digits are from. */ +static inline int +indigit_value (const char **s, size_t *len, int *decided) +{ + int from_level; + int to_level; + const char *mbdigits[10]; + int n; + + if (*decided != -1) + from_level = to_level = *decided; + else + { + from_level = 0; + to_level = _NL_CURRENT_WORD (LC_CTYPE, _NL_CTYPE_INDIGITS_MB_LEN) - 1; + assert (from_level <= to_level); + } + + /* In this round we get the pointer to the digit strings and also perform + the first round of comparisons. */ + for (n = 0; n < 10; ++n) + { + size_t dlen; + + /* Get the string for the digits with value N. */ + mbdigits[n] = _NL_CURRENT (LC_CTYPE, _NL_CTYPE_INDIGITS0_MB + n); + dlen = strlen (mbdigits[n]); + + if (dlen <= len && memcmp (*s, mbdigits[n], dlen) == 0) + { + /* Found it. */ + *s += dlen; + len -= dlen; + if (*decided == -1) + *decided = 0; + return n; + } + + /* Advance the pointer to the next string. */ + mbdigits[n] += dlen + 1; + } + + /* Now perform the remaining tests. */ + while (++from_level <= to_level) + { + /* Search all ten digits of this level. */ + for (n = 0; n < 10; ++n) + { + size_t dlen = strlen (mbdigits[n]); + + if (dlen <= len && memcmp (*s, mbdigits[n], dlen) == 0) + { + /* Found it. */ + *s += dlen; + len -= dlen; + if (*decided == -1) + *decided = from_level; + return n; + } + + /* Advance the pointer to the next string. */ + mbdigits[n] += dlen + 1; + } + + /* Next level. */ + ++from_level; + } + + /* If we reach this point no matching digit was found. */ + return -1; +} diff --git a/locale/indigitswc.h b/locale/indigitswc.h new file mode 100644 index 0000000000..8afbb7ea17 --- /dev/null +++ b/locale/indigitswc.h @@ -0,0 +1,88 @@ +/* Copyright (C) 2000 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Ulrich Drepper <drepper@gnu.org>, 2000. + + 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 + published by the Free Software Foundation; either version 2 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with the GNU C Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ + +#include <assert.h> +#include <langinfo.h> + +/* Look up the value of the next multibyte character and return its numerical + value if it is one of the digits known in the locale. If *DECIDED is + -1 this means it is not yet decided which form it is and we have to + search through all available digits. Otherwise we know which script + the digits are from. */ +static inline int +indigitwc_value (wchar_t wc, int *decided) +{ + int from_level; + int to_level; + const wchar_t *wcdigits[10]; + int n; + + if (*decided != -1) + from_level = to_level = *decided; + else + { + from_level = 0; + to_level = _NL_CURRENT_WORD (LC_CTYPE, _NL_CTYPE_INDIGITS_WC_LEN) - 1; + assert (from_level <= to_level); + } + + /* In this round we get the pointer to the digit strings and also perform + the first round of comparisons. */ + for (n = 0; n < 10; ++n) + { + /* Get the string for the digits with value N. */ + wcdigits[n] = _NL_CURRENT (LC_CTYPE, _NL_CTYPE_INDIGITS0_WC + n); + + if (wc == wcdigits[n]) + { + /* Found it. */ + if (*decided == -1) + *decided = 0; + return n; + } + + /* Advance the pointer to the next string. */ + ++wcdigits[n]; + } + + /* Now perform the remaining tests. */ + while (++from_level <= to_level) + { + /* Search all ten digits of this level. */ + for (n = 0; n < 10; ++n) + { + if (wc == wcdigits[n]) + { + /* Found it. */ + if (*decided == -1) + *decided = from_level; + return n; + } + + /* Advance the pointer to the next string. */ + ++wcdigits[n]; + } + + /* Next level. */ + ++from_level; + } + + /* If we reach this point no matching digit was found. */ + return -1; +} diff --git a/locale/langinfo.h b/locale/langinfo.h index 69341223cb..9ae6c8160c 100644 --- a/locale/langinfo.h +++ b/locale/langinfo.h @@ -1,5 +1,5 @@ /* Access to locale-dependent parameters. - Copyright (C) 1995, 1996, 1997, 1998, 1999 Free Software Foundation, Inc. + Copyright (C) 1995-1999, 2000 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 @@ -381,6 +381,8 @@ enum _NL_MONETARY_DUO_VALID_FROM, _NL_MONETARY_DUO_VALID_TO, _NL_MONETARY_CONVERSION_RATE, + _NL_MONETARY_DECIMAL_POINT_WC, + _NL_MONETARY_THOUSANDS_SEP_WC, _NL_NUM_LC_MONETARY, /* LC_NUMERIC category: formatting of numbers. @@ -399,6 +401,8 @@ enum #endif GROUPING, #define GROUPING GROUPING + _NL_NUMERIC_DECIMAL_POINT_WC, + _NL_NUMERIC_THOUSANDS_SEP_WC, _NL_NUM_LC_NUMERIC, YESEXPR = _NL_ITEM (LC_MESSAGES, 0), /* Regex matching ``yes'' input. */ diff --git a/locale/outdigits.h b/locale/outdigits.h new file mode 100644 index 0000000000..413dfe465e --- /dev/null +++ b/locale/outdigits.h @@ -0,0 +1,45 @@ +/* Copyright (C) 2000 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Ulrich Drepper <drepper@gnu.org>, 2000. + + 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 + published by the Free Software Foundation; either version 2 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with the GNU C Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ + +#include <assert.h> +#include <langinfo.h> +#include <string.h> +#include "../locale/localeinfo.h" + +/* Look up the value of the next multibyte character and return its numerical + value if it is one of the digits known in the locale. If *DECIDED is + -1 this means it is not yet decided which form it is and we have to + search through all available digits. Otherwise we know which script + the digits are from. */ +static inline char * +outdigit_value (char *s, int n) +{ + const char *outdigit; + size_t dlen; + + assert (0 <= n && n <= 9); + outdigit = _NL_CURRENT (LC_CTYPE, _NL_CTYPE_OUTDIGIT0_MB + n); + dlen = strlen (outdigit); + + s -= dlen; + while (dlen-- > 0) + s[dlen] = outdigit[dlen]; + + return s; +} diff --git a/locale/outdigitswc.h b/locale/outdigitswc.h new file mode 100644 index 0000000000..5ff8e1b63d --- /dev/null +++ b/locale/outdigitswc.h @@ -0,0 +1,35 @@ +/* Copyright (C) 2000 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Ulrich Drepper <drepper@gnu.org>, 2000. + + 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 + published by the Free Software Foundation; either version 2 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with the GNU C Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ + +#include <assert.h> +#include <langinfo.h> +#include "../locale/localeinfo.h" + +/* Look up the value of the next multibyte character and return its numerical + value if it is one of the digits known in the locale. If *DECIDED is + -1 this means it is not yet decided which form it is and we have to + search through all available digits. Otherwise we know which script + the digits are from. */ +static inline wchar_t +outdigitwc_value (int n) +{ + assert (0 <= n && n <= 9); + + return _NL_CURRENT_WORD (LC_CTYPE, _NL_CTYPE_OUTDIGIT0_WC + n); +} diff --git a/locale/programs/ld-monetary.c b/locale/programs/ld-monetary.c index 6a7655817c..2b2ac63397 100644 --- a/locale/programs/ld-monetary.c +++ b/locale/programs/ld-monetary.c @@ -43,6 +43,8 @@ struct locale_monetary_t const char *currency_symbol; const char *mon_decimal_point; const char *mon_thousands_sep; + uint32_t mon_decimal_point_wc; + uint32_t mon_thousands_sep_wc; char *mon_grouping; size_t mon_grouping_len; const char *positive_sign; @@ -150,7 +152,7 @@ monetary_startup (struct linereader *lr, struct localedef_t *locale, if (lr != NULL) { lr->translate_strings = 1; - lr->return_widestr = 0; + lr->return_widestr = 1; } } @@ -248,6 +250,8 @@ not correspond to a valid name in ISO 4217"), %s: value for field `%s' must not be the empty string"), "LC_MONETARY", "mon_decimal_point"); } + if (monetary->mon_decimal_point_wc == L'\0') + monetary->mon_decimal_point_wc = L'.'; if (monetary->mon_grouping_len == 0) { @@ -575,6 +579,16 @@ monetary_output (struct localedef_t *locale, struct charmap_t *charmap, iov[cnt].iov_len = 8; ++cnt; + idx[cnt - 2] = idx[cnt - 3] + iov[cnt - 1].iov_len; + iov[cnt].iov_base = (void *) &monetary->mon_decimal_point_wc; + iov[cnt].iov_len = sizeof (uint32_t); + ++cnt; + + idx[cnt - 2] = idx[cnt - 3] + iov[cnt - 1].iov_len; + iov[cnt].iov_base = (void *) &monetary->mon_thousands_sep_wc; + iov[cnt].iov_len = sizeof (uint32_t); + ++cnt; + assert (cnt == 2 + _NL_ITEM_INDEX (_NL_NUM_LC_MONETARY)); write_locale_data (output_path, "LC_MONETARY", @@ -666,13 +680,51 @@ monetary_read (struct linereader *ldfile, struct localedef_t *result, STR_ELEM (int_curr_symbol); STR_ELEM (currency_symbol); - STR_ELEM (mon_decimal_point); - STR_ELEM (mon_thousands_sep); STR_ELEM (positive_sign); STR_ELEM (negative_sign); STR_ELEM (duo_int_curr_symbol); STR_ELEM (duo_currency_symbol); +#define STR_ELEM_WC(cat) \ + case tok_##cat: \ + /* Ignore the rest of the line if we don't need the input of \ + this line. */ \ + if (ignore_content) \ + { \ + lr_ignore_rest (ldfile, 0); \ + break; \ + } \ + \ + now = lr_token (ldfile, charmap, NULL); \ + if (now->tok != tok_string) \ + goto err_label; \ + if (monetary->cat != NULL) \ + lr_error (ldfile, _("\ +%s: field `%s' declared more than once"), "LC_MONETARY", #cat); \ + else if (!ignore_content && now->val.str.startmb == NULL) \ + { \ + lr_error (ldfile, _("\ +%s: unknown character in field `%s'"), "LC_MONETARY", #cat); \ + monetary->cat = ""; \ + monetary->cat##_wc = L'\0'; \ + } \ + else if (now->val.str.startwc != NULL && now->val.str.lenwc > 1) \ + { \ + lr_error (ldfile, _("\ +%s: value for field `%s' must be a single character"), "LC_MONETARY", #cat); \ + } \ + else if (!ignore_content) \ + { \ + monetary->cat = now->val.str.startmb; \ + \ + if (now->val.str.startwc != NULL) \ + monetary->cat##_wc = *now->val.str.startwc; \ + } \ + break + + STR_ELEM_WC (mon_decimal_point); + STR_ELEM_WC (mon_thousands_sep); + #define INT_ELEM(cat) \ case tok_##cat: \ /* Ignore the rest of the line if we don't need the input of \ diff --git a/locale/programs/ld-numeric.c b/locale/programs/ld-numeric.c index e61db91e8b..d7cec903a8 100644 --- a/locale/programs/ld-numeric.c +++ b/locale/programs/ld-numeric.c @@ -40,6 +40,8 @@ struct locale_numeric_t const char *thousands_sep; char *grouping; size_t grouping_len; + uint32_t decimal_point_wc; + uint32_t thousands_sep_wc; }; @@ -49,19 +51,15 @@ numeric_startup (struct linereader *lr, struct localedef_t *locale, { if (!ignore_content) { - struct locale_numeric_t *numeric; - - locale->categories[LC_NUMERIC].numeric = numeric = - (struct locale_numeric_t *) xcalloc (1, sizeof (*numeric)); - - numeric->grouping = NULL; - numeric->grouping_len = 0; + locale->categories[LC_NUMERIC].numeric = + (struct locale_numeric_t *) xcalloc (1, + sizeof (struct locale_numeric_t)); } if (lr != NULL) { lr->translate_strings = 1; - lr->return_widestr = 0; + lr->return_widestr = 1; } } @@ -106,12 +104,14 @@ numeric_finish (struct localedef_t *locale, struct charmap_t *charmap) } } -#define TEST_ELEM(cat) \ +#define TEST_ELEM(cat, default) \ if (numeric->cat == NULL && ! be_quiet && ! nothing) \ - error (0, 0, _("%s: field `%s' not defined"), "LC_NUMERIC", #cat) + error (0, 0, _("%s: field `%s' not defined"), "LC_NUMERIC", #cat); \ + if (numeric->cat##_wc == L'\0') \ + numeric->cat##_wc = default - TEST_ELEM (decimal_point); - TEST_ELEM (thousands_sep); + TEST_ELEM (decimal_point, L'.'); + TEST_ELEM (thousands_sep, L'\0'); /* The decimal point must not be empty. This is not said explicitly in POSIX but ANSI C (ISO/IEC 9899) says in 4.4.2.1 it has to be @@ -169,6 +169,16 @@ numeric_output (struct localedef_t *locale, struct charmap_t *charmap, iov[cnt].iov_base = numeric->grouping; iov[cnt].iov_len = numeric->grouping_len; + idx[cnt - 2] = iov[0].iov_len + iov[1].iov_len; + iov[cnt].iov_base = (void *) &numeric->decimal_point_wc; + iov[cnt].iov_len = sizeof (uint32_t); + ++cnt; + + idx[cnt - 2] = idx[cnt - 3] + iov[cnt - 1].iov_len; + iov[cnt].iov_base = (void *) &numeric->thousands_sep_wc; + iov[cnt].iov_len = sizeof (uint32_t);; + ++cnt; + assert (cnt + 1 == 2 + _NL_ITEM_INDEX (_NL_NUM_LC_NUMERIC)); write_locale_data (output_path, "LC_NUMERIC", @@ -246,9 +256,20 @@ numeric_read (struct linereader *ldfile, struct localedef_t *result, lr_error (ldfile, _("\ %s: unknown character in field `%s'"), "LC_NUMERIC", #cat); \ numeric->cat = ""; \ + numeric->cat##_wc = L'\0'; \ + } \ + else if (now->val.str.startwc != NULL && now->val.str.lenwc > 1) \ + { \ + lr_error (ldfile, _("\ +%s: value for field `%s' must be a single character"), "LC_NUMERIC", #cat); \ } \ else if (!ignore_content) \ - numeric->cat = now->val.str.startmb; \ + { \ + numeric->cat = now->val.str.startmb; \ + \ + if (now->val.str.startwc != NULL) \ + numeric->cat##_wc = *now->val.str.startwc; \ + } \ break STR_ELEM (decimal_point); |