lnumeric.c revision 72165
1145519Sdarrenr/*
2145510Sdarrenr * Copyright (c) 2000, 2001 Alexey Zelkin
3145510Sdarrenr * All rights reserved.
4145510Sdarrenr *
5145510Sdarrenr * Redistribution and use in source and binary forms, with or without
6145510Sdarrenr * modification, are permitted provided that the following conditions
7145510Sdarrenr * are met:
8145510Sdarrenr * 1. Redistributions of source code must retain the above copyright
9145510Sdarrenr *    notice, this list of conditions and the following disclaimer.
10145510Sdarrenr * 2. Redistributions in binary form must reproduce the above copyright
11145510Sdarrenr *    notice, this list of conditions and the following disclaimer in the
12145510Sdarrenr *    documentation and/or other materials provided with the distribution.
13145510Sdarrenr *
14145510Sdarrenr * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15145510Sdarrenr * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16145510Sdarrenr * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17145510Sdarrenr * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18145510Sdarrenr * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19145510Sdarrenr * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20145510Sdarrenr * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21153881Sguido * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22153881Sguido * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23153881Sguido * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24145554Sdarrenr * SUCH DAMAGE.
25145510Sdarrenr *
26145510Sdarrenr * $FreeBSD: head/lib/libc/locale/lnumeric.c 72165 2001-02-08 16:58:53Z phantom $
27145510Sdarrenr */
28145510Sdarrenr
29145510Sdarrenr#include "lnumeric.h"
30145510Sdarrenr#include "ldpart.h"
31145510Sdarrenr
32255332Scyextern int __nlocale_changed;
33145510Sdarrenr
34145510Sdarrenr#define LCNUMERIC_SIZE (sizeof(struct lc_numeric_T) / sizeof(char *))
35145510Sdarrenr
36145510Sdarrenrstatic const struct lc_numeric_T _C_numeric_locale = {
37145510Sdarrenr	".",	/* decimal_point */
38145510Sdarrenr	"",	/* thousands_sep */
39145510Sdarrenr	"-1"	/* grouping */
40145510Sdarrenr};
41145510Sdarrenr
42145510Sdarrenrstatic struct lc_numeric_T _numeric_locale;
43145510Sdarrenrstatic int _numeric_using_locale;
44145510Sdarrenrstatic char *	numeric_locale_buf;
45145510Sdarrenr
46145510Sdarrenrint
47145510Sdarrenr__numeric_load_locale(const char *name) {
48145510Sdarrenr
49145510Sdarrenr	int ret;
50145510Sdarrenr
51145510Sdarrenr	ret = __part_load_locale(name, &_numeric_using_locale,
52145510Sdarrenr		numeric_locale_buf, "LC_NUMERIC", LCNUMERIC_SIZE,
53145510Sdarrenr		(const char **)&_numeric_locale);
54145510Sdarrenr	if (!ret)
55145510Sdarrenr		__nlocale_changed = 1;
56145510Sdarrenr	return ret;
57145510Sdarrenr}
58145510Sdarrenr
59145510Sdarrenrstruct lc_numeric_T *
60145510Sdarrenr__get_current_numeric_locale(void) {
61145510Sdarrenr
62145510Sdarrenr	return (_numeric_using_locale
63145510Sdarrenr		? &_numeric_locale
64145510Sdarrenr		: (struct lc_numeric_T *)&_C_numeric_locale);
65145510Sdarrenr}
66145510Sdarrenr
67145510Sdarrenr#ifdef LOCALE_DEBUG
68145510Sdarrenrvoid
69145510Sdarrenrnumericdebug(void) {
70145510Sdarrenrprintf(	"decimal_point = %s\n"
71145510Sdarrenr	"thousands_sep = %s\n"
72145510Sdarrenr	"grouping = %s\n",
73145510Sdarrenr	_numeric_locale.decimal_point,
74145510Sdarrenr	_numeric_locale.thousands_sep,
75145510Sdarrenr	_numeric_locale.grouping
76145510Sdarrenr);
77145510Sdarrenr}
78145510Sdarrenr#endif /* LOCALE_DEBUG */
79145510Sdarrenr