. 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.
This commit is contained in:
Alexey Zelkin 2001-02-10 15:36:46 +00:00
parent 531f27501e
commit 1bd7723d09
5 changed files with 84 additions and 15 deletions

View File

@ -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 \

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}