2 * Copyright (c) 2000, 2001 Alexey Zelkin <phantom@FreeBSD.org>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD: src/lib/libc/locale/lmonetary.c,v 1.19 2003/06/26 10:46:16 phantom Exp $");
35 #include "lmonetary.h"
37 extern int __mlocale_changed
;
38 extern const char * __fix_locale_grouping_str(const char *);
40 #define LCMONETARY_SIZE_FULL (sizeof(struct lc_monetary_T) / sizeof(char *))
41 #define LCMONETARY_SIZE_MIN \
42 (offsetof(struct lc_monetary_T, int_p_cs_precedes) / \
45 static char empty
[] = "";
46 static char numempty
[] = { CHAR_MAX
, '\0'};
48 static const struct lc_monetary_T _C_monetary_locale
= {
49 empty
, /* int_curr_symbol */
50 empty
, /* currency_symbol */
51 empty
, /* mon_decimal_point */
52 empty
, /* mon_thousands_sep */
53 numempty
, /* mon_grouping */
54 empty
, /* positive_sign */
55 empty
, /* negative_sign */
56 numempty
, /* int_frac_digits */
57 numempty
, /* frac_digits */
58 numempty
, /* p_cs_precedes */
59 numempty
, /* p_sep_by_space */
60 numempty
, /* n_cs_precedes */
61 numempty
, /* n_sep_by_space */
62 numempty
, /* p_sign_posn */
63 numempty
, /* n_sign_posn */
64 numempty
, /* int_p_cs_precedes */
65 numempty
, /* int_n_cs_precedes */
66 numempty
, /* int_p_sep_by_space */
67 numempty
, /* int_n_sep_by_space */
68 numempty
, /* int_p_sign_posn */
69 numempty
/* int_n_sign_posn */
72 static struct lc_monetary_T _monetary_locale
;
73 static int _monetary_using_locale
;
74 static char *_monetary_locale_buf
;
79 int i
= strtol(str
, NULL
, 10);
87 __monetary_load_locale(const char *name
)
91 ret
= __part_load_locale(name
, &_monetary_using_locale
,
92 &_monetary_locale_buf
, "LC_MONETARY",
93 LCMONETARY_SIZE_FULL
, LCMONETARY_SIZE_MIN
,
94 (const char **)&_monetary_locale
);
95 if (ret
!= _LDP_ERROR
)
96 __mlocale_changed
= 1;
97 if (ret
== _LDP_LOADED
) {
98 _monetary_locale
.mon_grouping
=
99 __fix_locale_grouping_str(_monetary_locale
.mon_grouping
);
101 #define M_ASSIGN_CHAR(NAME) (((char *)_monetary_locale.NAME)[0] = \
102 cnv(_monetary_locale.NAME))
104 M_ASSIGN_CHAR(int_frac_digits
);
105 M_ASSIGN_CHAR(frac_digits
);
106 M_ASSIGN_CHAR(p_cs_precedes
);
107 M_ASSIGN_CHAR(p_sep_by_space
);
108 M_ASSIGN_CHAR(n_cs_precedes
);
109 M_ASSIGN_CHAR(n_sep_by_space
);
110 M_ASSIGN_CHAR(p_sign_posn
);
111 M_ASSIGN_CHAR(n_sign_posn
);
114 * The six additional C99 international monetary formatting
115 * parameters default to the national parameters when
116 * reading FreeBSD LC_MONETARY data files.
118 #define M_ASSIGN_ICHAR(NAME) \
120 if (_monetary_locale.int_##NAME == NULL) \
121 _monetary_locale.int_##NAME = \
122 _monetary_locale.NAME; \
124 M_ASSIGN_CHAR(int_##NAME); \
127 M_ASSIGN_ICHAR(p_cs_precedes
);
128 M_ASSIGN_ICHAR(n_cs_precedes
);
129 M_ASSIGN_ICHAR(p_sep_by_space
);
130 M_ASSIGN_ICHAR(n_sep_by_space
);
131 M_ASSIGN_ICHAR(p_sign_posn
);
132 M_ASSIGN_ICHAR(n_sign_posn
);
137 struct lc_monetary_T
*
138 __get_current_monetary_locale(void)
140 return (_monetary_using_locale
142 : (struct lc_monetary_T
*)&_C_monetary_locale
);
148 printf( "int_curr_symbol = %s\n"
149 "currency_symbol = %s\n"
150 "mon_decimal_point = %s\n"
151 "mon_thousands_sep = %s\n"
152 "mon_grouping = %s\n"
153 "positive_sign = %s\n"
154 "negative_sign = %s\n"
155 "int_frac_digits = %d\n"
157 "p_cs_precedes = %d\n"
158 "p_sep_by_space = %d\n"
159 "n_cs_precedes = %d\n"
160 "n_sep_by_space = %d\n"
162 "n_sign_posn = %d\n",
163 "int_p_cs_precedes = %d\n"
164 "int_p_sep_by_space = %d\n"
165 "int_n_cs_precedes = %d\n"
166 "int_n_sep_by_space = %d\n"
167 "int_p_sign_posn = %d\n"
168 "int_n_sign_posn = %d\n",
169 _monetary_locale
.int_curr_symbol
,
170 _monetary_locale
.currency_symbol
,
171 _monetary_locale
.mon_decimal_point
,
172 _monetary_locale
.mon_thousands_sep
,
173 _monetary_locale
.mon_grouping
,
174 _monetary_locale
.positive_sign
,
175 _monetary_locale
.negative_sign
,
176 _monetary_locale
.int_frac_digits
[0],
177 _monetary_locale
.frac_digits
[0],
178 _monetary_locale
.p_cs_precedes
[0],
179 _monetary_locale
.p_sep_by_space
[0],
180 _monetary_locale
.n_cs_precedes
[0],
181 _monetary_locale
.n_sep_by_space
[0],
182 _monetary_locale
.p_sign_posn
[0],
183 _monetary_locale
.n_sign_posn
[0],
184 _monetary_locale
.int_p_cs_precedes
[0],
185 _monetary_locale
.int_p_sep_by_space
[0],
186 _monetary_locale
.int_n_cs_precedes
[0],
187 _monetary_locale
.int_n_sep_by_space
[0],
188 _monetary_locale
.int_p_sign_posn
[0],
189 _monetary_locale
.int_n_sign_posn
[0]
192 #endif /* LOCALE_DEBUG */