lnumeric.c revision 72273
160484Sobrien/*
2218822Sdim * Copyright (c) 2000, 2001 Alexey Zelkin
3218822Sdim * All rights reserved.
460484Sobrien *
560484Sobrien * Redistribution and use in source and binary forms, with or without
680016Sobrien * modification, are permitted provided that the following conditions
760484Sobrien * are met:
860484Sobrien * 1. Redistributions of source code must retain the above copyright
960484Sobrien *    notice, this list of conditions and the following disclaimer.
1060484Sobrien * 2. Redistributions in binary form must reproduce the above copyright
1160484Sobrien *    notice, this list of conditions and the following disclaimer in the
1260484Sobrien *    documentation and/or other materials provided with the distribution.
1360484Sobrien *
1460484Sobrien * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1560484Sobrien * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1660484Sobrien * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1760484Sobrien * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
1860484Sobrien * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1960484Sobrien * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2060484Sobrien * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2160484Sobrien * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22218822Sdim * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23218822Sdim * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2460484Sobrien * SUCH DAMAGE.
25130561Sobrien *
2660484Sobrien * $FreeBSD: head/lib/libc/locale/lnumeric.c 72273 2001-02-10 02:00:56Z ache $
27218822Sdim */
28130561Sobrien
29130561Sobrien#include <limits.h>
30130561Sobrien#include <sys/cdefs.h>
31130561Sobrien#include "lnumeric.h"
32130561Sobrien#include "ldpart.h"
33130561Sobrien
34130561Sobrienextern int __nlocale_changed;
35130561Sobrien
36130561Sobrien#define LCNUMERIC_SIZE (sizeof(struct lc_numeric_T) / sizeof(char *))
37130561Sobrien
38130561Sobrienstatic char     numempty[] = __XSTRING(CHAR_MAX);
39130561Sobrien
40130561Sobrienstatic const struct lc_numeric_T _C_numeric_locale = {
41130561Sobrien	".",     /* decimal_point */
42130561Sobrien	"",      /* thousands_sep */
43130561Sobrien	numempty /* grouping */
44218822Sdim};
4560484Sobrien
4660484Sobrienstatic struct lc_numeric_T _numeric_locale;
4760484Sobrienstatic int _numeric_using_locale;
4860484Sobrienstatic char *	numeric_locale_buf;
49218822Sdim
50218822Sdimint
51218822Sdim__numeric_load_locale(const char *name) {
52218822Sdim
53218822Sdim	int ret;
54218822Sdim
55218822Sdim	ret = __part_load_locale(name, &_numeric_using_locale,
56218822Sdim		numeric_locale_buf, "LC_NUMERIC", LCNUMERIC_SIZE,
57218822Sdim		(const char **)&_numeric_locale);
58218822Sdim	if (!ret)
59218822Sdim		__nlocale_changed = 1;
60218822Sdim	return ret;
61218822Sdim}
62218822Sdim
63218822Sdimstruct lc_numeric_T *
64218822Sdim__get_current_numeric_locale(void) {
65218822Sdim
66218822Sdim	return (_numeric_using_locale
67218822Sdim		? &_numeric_locale
6860484Sobrien		: (struct lc_numeric_T *)&_C_numeric_locale);
6960484Sobrien}
7060484Sobrien
71130561Sobrien#ifdef LOCALE_DEBUG
7260484Sobrienvoid
7360484Sobriennumericdebug(void) {
7460484Sobrienprintf(	"decimal_point = %s\n"
7560484Sobrien	"thousands_sep = %s\n"
7660484Sobrien	"grouping = %s\n",
77218822Sdim	_numeric_locale.decimal_point,
78218822Sdim	_numeric_locale.thousands_sep,
7960484Sobrien	_numeric_locale.grouping
8060484Sobrien);
8160484Sobrien}
8260484Sobrien#endif /* LOCALE_DEBUG */
8360484Sobrien