diff options
author | phantom <phantom@FreeBSD.org> | 2001-02-10 15:36:46 +0000 |
---|---|---|
committer | phantom <phantom@FreeBSD.org> | 2001-02-10 15:36:46 +0000 |
commit | d4e3ae3d2b0ba71baec8eaa715b2e04f155901bf (patch) | |
tree | f16898ec334a52d00a42f5c776a5e65c5fb55cf4 /lib/libc | |
parent | bab9f921621ed124781eef8abdf07b4bab79169a (diff) | |
download | FreeBSD-src-d4e3ae3d2b0ba71baec8eaa715b2e04f155901bf.zip FreeBSD-src-d4e3ae3d2b0ba71baec8eaa715b2e04f155901bf.tar.gz |
. Fix semantics of grouping (LC_MONETARY::mon_grouping,
LC_NUMERIC::grouping) values.
. Always set __XXX_changed flags then loading numeric & monetary locale
categories to allow localeconv() to use C locale also.
Diffstat (limited to 'lib/libc')
-rw-r--r-- | lib/libc/locale/Makefile.inc | 3 | ||||
-rw-r--r-- | lib/libc/locale/fix_grouping.c | 68 | ||||
-rw-r--r-- | lib/libc/locale/lmonetary.c | 8 | ||||
-rw-r--r-- | lib/libc/locale/lnumeric.c | 8 | ||||
-rw-r--r-- | lib/libc/locale/localeconv.c | 12 |
5 files changed, 84 insertions, 15 deletions
diff --git a/lib/libc/locale/Makefile.inc b/lib/libc/locale/Makefile.inc index d93d17a..573ed17 100644 --- a/lib/libc/locale/Makefile.inc +++ b/lib/libc/locale/Makefile.inc @@ -4,7 +4,8 @@ # locale sources .PATH: ${.CURDIR}/../libc/${MACHINE_ARCH}/locale ${.CURDIR}/../libc/locale -SRCS+= ansi.c big5.c collate.c collcmp.c euc.c frune.c isctype.c \ +SRCS+= ansi.c big5.c collate.c collcmp.c euc.c frune.c fix_grouping.c \ + isctype.c \ ldpart.c lmessages.c lmonetary.c lnumeric.c localeconv.c mbrune.c \ mskanji.c nl_langinfo.c nomacros.c none.c rune.c \ runetype.c setinvalidrune.c setlocale.c setrunelocale.c table.c \ diff --git a/lib/libc/locale/fix_grouping.c b/lib/libc/locale/fix_grouping.c new file mode 100644 index 0000000..ab11655 --- /dev/null +++ b/lib/libc/locale/fix_grouping.c @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2001 Alexey Zelkin + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#include <limits.h> + +static const char nogrouping[] = { CHAR_MAX, '\0' }; + +/* + * "3;3;-1" -> "\003\003\177" + * NOTE: one digit numbers assumed! + */ + +const char * +__fix_locale_grouping_str(const char *str) { + + char *src, *dst; + + if (str == 0) { + return nogrouping; + } + for (src = (char*)str, dst = (char*)str; *src; src++) { + char cur; + + /* input string examples: "3;3", "3;2;-1" */ + if (*src == ';') + continue; + + if (*src == '-' && *(src+1) == '1') { + *dst++ = CHAR_MAX; + src++; + continue; + } + + if (!isdigit(*src)) { + /* broken grouping string */ + return nogrouping; + } + + *dst++ = *src - '0'; + } + *dst = '\0'; + return str; +} diff --git a/lib/libc/locale/lmonetary.c b/lib/libc/locale/lmonetary.c index 715790e..e42c6c5 100644 --- a/lib/libc/locale/lmonetary.c +++ b/lib/libc/locale/lmonetary.c @@ -26,15 +26,17 @@ * $FreeBSD$ */ +#include <limits.h> #include "lmonetary.h" #include "ldpart.h" extern int __mlocale_changed; +extern const char * __fix_locale_grouping_str(const char *); #define LCMONETARY_SIZE (sizeof(struct lc_monetary_T) / sizeof(char *)) static char empty[] = ""; -static char numempty[] = "-1"; +static char numempty[] = { CHAR_MAX, '\0'}; static const struct lc_monetary_T _C_monetary_locale = { empty , /* int_curr_symbol */ @@ -62,11 +64,13 @@ int __monetary_load_locale(const char *name) { int ret; + __mlocale_changed = 1; ret = __part_load_locale(name, &_monetary_using_locale, monetary_locale_buf, "LC_MONETARY", LCMONETARY_SIZE, (const char **)&_monetary_locale); if (!ret) - __mlocale_changed = 1; + _monetary_locale.mon_grouping = + __fix_locale_grouping_str(_monetary_locale.mon_grouping); return ret; } diff --git a/lib/libc/locale/lnumeric.c b/lib/libc/locale/lnumeric.c index 0de5a32..8754069 100644 --- a/lib/libc/locale/lnumeric.c +++ b/lib/libc/locale/lnumeric.c @@ -26,14 +26,16 @@ * $FreeBSD$ */ +#include <limits.h> #include "lnumeric.h" #include "ldpart.h" extern int __nlocale_changed; +extern const char * __fix_locale_grouping_str(const char *); #define LCNUMERIC_SIZE (sizeof(struct lc_numeric_T) / sizeof(char *)) -static char numempty[] = "-1"; +static char numempty[] = { CHAR_MAX, '\0' }; static const struct lc_numeric_T _C_numeric_locale = { ".", /* decimal_point */ @@ -50,11 +52,13 @@ __numeric_load_locale(const char *name) { int ret; + __nlocale_changed = 1; ret = __part_load_locale(name, &_numeric_using_locale, numeric_locale_buf, "LC_NUMERIC", LCNUMERIC_SIZE, (const char **)&_numeric_locale); if (!ret) - __nlocale_changed = 1; + _numeric_locale.grouping = + __fix_locale_grouping_str(_numeric_locale.grouping); return ret; } diff --git a/lib/libc/locale/localeconv.c b/lib/libc/locale/localeconv.c index 7e2acea..24ff28f 100644 --- a/lib/libc/locale/localeconv.c +++ b/lib/libc/locale/localeconv.c @@ -50,10 +50,6 @@ static char rcsid[] = "$FreeBSD$"; int __mlocale_changed = 1; int __nlocale_changed = 1; -/* XXX: FIXME! */ -/* Numbers separated by ";" must be parsed into byte array. */ -static char nogrouping[] = { CHAR_MAX, '\0' }; - static char cnv(char *str) { int i = strtol(str, NULL, 10); @@ -82,9 +78,7 @@ localeconv() M_ASSIGN_STR(currency_symbol); M_ASSIGN_STR(mon_decimal_point); M_ASSIGN_STR(mon_thousands_sep); - /* XXX: FIXME! */ - /* Numbers separated by ";" must be parsed into byte array. */ - ret.mon_grouping = nogrouping; + M_ASSIGN_STR(mon_grouping); M_ASSIGN_STR(positive_sign); M_ASSIGN_STR(negative_sign); M_ASSIGN_CHAR(int_frac_digits); @@ -107,9 +101,7 @@ localeconv() nptr = __get_current_numeric_locale(); N_ASSIGN_STR(decimal_point); N_ASSIGN_STR(thousands_sep); - /* XXX: FIXME! */ - /* Numbers separated by ";" must be parsed into byte array. */ - ret.grouping = nogrouping; + N_ASSIGN_STR(grouping); __nlocale_changed = 0; } |