lnumeric.c revision 72283
1234285Sdim/*
2234285Sdim * Copyright (c) 2000, 2001 Alexey Zelkin
3234285Sdim * All rights reserved.
4234285Sdim *
5234285Sdim * Redistribution and use in source and binary forms, with or without
6234285Sdim * modification, are permitted provided that the following conditions
7234285Sdim * are met:
8234285Sdim * 1. Redistributions of source code must retain the above copyright
9234285Sdim *    notice, this list of conditions and the following disclaimer.
10234285Sdim * 2. Redistributions in binary form must reproduce the above copyright
11234285Sdim *    notice, this list of conditions and the following disclaimer in the
12234285Sdim *    documentation and/or other materials provided with the distribution.
13234285Sdim *
14234285Sdim * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15234285Sdim * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16234285Sdim * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17234285Sdim * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18234285Sdim * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19234285Sdim * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20234285Sdim * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21234285Sdim * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22234285Sdim * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23234285Sdim * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24234285Sdim * SUCH DAMAGE.
25234285Sdim *
26234285Sdim * $FreeBSD: head/lib/libc/locale/lnumeric.c 72283 2001-02-10 03:31:23Z ache $
27234285Sdim */
28234285Sdim
29234285Sdim#include "lnumeric.h"
30234285Sdim#include "ldpart.h"
31234285Sdim
32234285Sdimextern int __nlocale_changed;
33234285Sdim
34234285Sdim#define LCNUMERIC_SIZE (sizeof(struct lc_numeric_T) / sizeof(char *))
35234285Sdim
36234285Sdimstatic char     numempty[] = "-1";
37234285Sdim
38234285Sdimstatic const struct lc_numeric_T _C_numeric_locale = {
39234285Sdim	".",     /* decimal_point */
40234285Sdim	"",      /* thousands_sep */
41234285Sdim	numempty /* grouping */
42234285Sdim};
43234285Sdim
44249423Sdimstatic struct lc_numeric_T _numeric_locale;
45234285Sdimstatic int _numeric_using_locale;
46234285Sdimstatic char *	numeric_locale_buf;
47234285Sdim
48234285Sdimint
49234285Sdim__numeric_load_locale(const char *name) {
50234285Sdim
51243830Sdim	int ret;
52243830Sdim
53234285Sdim	ret = __part_load_locale(name, &_numeric_using_locale,
54234285Sdim		numeric_locale_buf, "LC_NUMERIC", LCNUMERIC_SIZE,
55234285Sdim		(const char **)&_numeric_locale);
56234285Sdim	if (!ret)
57234285Sdim		__nlocale_changed = 1;
58234285Sdim	return ret;
59234285Sdim}
60234285Sdim
61234285Sdimstruct lc_numeric_T *
62234285Sdim__get_current_numeric_locale(void) {
63234285Sdim
64234285Sdim	return (_numeric_using_locale
65234285Sdim		? &_numeric_locale
66234285Sdim		: (struct lc_numeric_T *)&_C_numeric_locale);
67234285Sdim}
68234285Sdim
69234285Sdim#ifdef LOCALE_DEBUG
70234285Sdimvoid
71234285Sdimnumericdebug(void) {
72234285Sdimprintf(	"decimal_point = %s\n"
73234285Sdim	"thousands_sep = %s\n"
74234285Sdim	"grouping = %s\n",
75234285Sdim	_numeric_locale.decimal_point,
76	_numeric_locale.thousands_sep,
77	_numeric_locale.grouping
78);
79}
80#endif /* LOCALE_DEBUG */
81