2 * Copyright 2010 Nexenta Systems, Inc. All rights reserved.
3 * Copyright 2015 John Marino <draco@marino.st>
5 * This source code is derived from the illumos localedef command, and
6 * provided under BSD-style license terms by Nexenta Systems, Inc.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
22 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 * POSSIBILITY OF SUCH DAMAGE.
32 * LC_MONETARY database generation routines for localedef.
34 #include <sys/cdefs.h>
35 __FBSDID("$FreeBSD$");
40 #include <sys/types.h>
43 #include "localedef.h"
45 #include "lmonetary.h"
47 static struct lc_monetary_T mon
;
52 (void) memset(&mon
, 0, sizeof (mon
));
56 add_monetary_str(wchar_t *wcs
)
60 if ((str
= to_mb_string(wcs
)) == NULL
) {
66 case T_INT_CURR_SYMBOL
:
67 mon
.int_curr_symbol
= str
;
69 case T_CURRENCY_SYMBOL
:
70 mon
.currency_symbol
= str
;
72 case T_MON_DECIMAL_POINT
:
73 mon
.mon_decimal_point
= str
;
75 case T_MON_THOUSANDS_SEP
:
76 mon
.mon_thousands_sep
= str
;
79 mon
.positive_sign
= str
;
82 mon
.negative_sign
= str
;
92 add_monetary_num(int n
)
96 (void) asprintf(&str
, "%d", n
);
98 fprintf(stderr
, "out of memory");
103 case T_INT_FRAC_DIGITS
:
104 mon
.int_frac_digits
= str
;
107 mon
.frac_digits
= str
;
109 case T_P_CS_PRECEDES
:
110 mon
.p_cs_precedes
= str
;
112 case T_P_SEP_BY_SPACE
:
113 mon
.p_sep_by_space
= str
;
115 case T_N_CS_PRECEDES
:
116 mon
.n_cs_precedes
= str
;
118 case T_N_SEP_BY_SPACE
:
119 mon
.n_sep_by_space
= str
;
122 mon
.p_sign_posn
= str
;
125 mon
.n_sign_posn
= str
;
127 case T_INT_P_CS_PRECEDES
:
128 mon
.int_p_cs_precedes
= str
;
130 case T_INT_N_CS_PRECEDES
:
131 mon
.int_n_cs_precedes
= str
;
133 case T_INT_P_SEP_BY_SPACE
:
134 mon
.int_p_sep_by_space
= str
;
136 case T_INT_N_SEP_BY_SPACE
:
137 mon
.int_n_sep_by_space
= str
;
139 case T_INT_P_SIGN_POSN
:
140 mon
.int_p_sign_posn
= str
;
142 case T_INT_N_SIGN_POSN
:
143 mon
.int_n_sign_posn
= str
;
146 mon
.mon_grouping
= str
;
155 reset_monetary_group(void)
157 free((char *)mon
.mon_grouping
);
158 mon
.mon_grouping
= NULL
;
162 add_monetary_group(int n
)
166 if (mon
.mon_grouping
== NULL
) {
167 (void) asprintf(&s
, "%d", n
);
169 (void) asprintf(&s
, "%s;%d", mon
.mon_grouping
, n
);
172 fprintf(stderr
, "out of memory");
174 free((char *)mon
.mon_grouping
);
175 mon
.mon_grouping
= s
;
183 if ((f
= open_category()) == NULL
) {
187 if ((putl_category(mon
.int_curr_symbol
, f
) == EOF
) ||
188 (putl_category(mon
.currency_symbol
, f
) == EOF
) ||
189 (putl_category(mon
.mon_decimal_point
, f
) == EOF
) ||
190 (putl_category(mon
.mon_thousands_sep
, f
) == EOF
) ||
191 (putl_category(mon
.mon_grouping
, f
) == EOF
) ||
192 (putl_category(mon
.positive_sign
, f
) == EOF
) ||
193 (putl_category(mon
.negative_sign
, f
) == EOF
) ||
194 (putl_category(mon
.int_frac_digits
, f
) == EOF
) ||
195 (putl_category(mon
.frac_digits
, f
) == EOF
) ||
196 (putl_category(mon
.p_cs_precedes
, f
) == EOF
) ||
197 (putl_category(mon
.p_sep_by_space
, f
) == EOF
) ||
198 (putl_category(mon
.n_cs_precedes
, f
) == EOF
) ||
199 (putl_category(mon
.n_sep_by_space
, f
) == EOF
) ||
200 (putl_category(mon
.p_sign_posn
, f
) == EOF
) ||
201 (putl_category(mon
.n_sign_posn
, f
) == EOF
) ||
202 (putl_category(mon
.int_p_cs_precedes
, f
) == EOF
) ||
203 (putl_category(mon
.int_n_cs_precedes
, f
) == EOF
) ||
204 (putl_category(mon
.int_p_sep_by_space
, f
) == EOF
) ||
205 (putl_category(mon
.int_n_sep_by_space
, f
) == EOF
) ||
206 (putl_category(mon
.int_p_sign_posn
, f
) == EOF
) ||
207 (putl_category(mon
.int_n_sign_posn
, f
) == EOF
)) {