2 * This file and its contents are supplied under the terms of the
3 * Common Development and Distribution License ("CDDL"), version 1.0.
4 * You may only use this file in accordance with the terms of version
7 * A full copy of the text of the CDDL should have accompanied this
8 * source. A copy of the CDDL is also available via the Internet at
9 * http://www.illumos.org/license/CDDL.
13 * Copyright 2013 Garrett D'Amore <garrett@damore.org>
14 * Copyright 2010 Nexenta Systems, Inc. All rights reserved.
18 * LC_MONETARY database generation routines for localedef.
24 #include <sys/types.h>
27 #include "localedef.h"
28 #include "parser.tab.h"
29 #include "lmonetary.h"
31 static struct lc_monetary mon
;
36 (void) memset(&mon
, 0, sizeof (mon
));
40 add_monetary_str(wchar_t *wcs
)
44 if ((str
= to_mb_string(wcs
)) == NULL
) {
50 case T_INT_CURR_SYMBOL
:
51 mon
.int_curr_symbol
= str
;
53 case T_CURRENCY_SYMBOL
:
54 mon
.currency_symbol
= str
;
56 case T_MON_DECIMAL_POINT
:
57 mon
.mon_decimal_point
= str
;
59 case T_MON_THOUSANDS_SEP
:
60 mon
.mon_thousands_sep
= str
;
63 mon
.positive_sign
= str
;
66 mon
.negative_sign
= str
;
76 add_monetary_num(int n
)
80 (void) asprintf(&str
, "%d", n
);
82 errf(_("out of memory"));
87 case T_INT_FRAC_DIGITS
:
88 mon
.int_frac_digits
= str
;
91 mon
.frac_digits
= str
;
94 mon
.p_cs_precedes
= str
;
96 case T_P_SEP_BY_SPACE
:
97 mon
.p_sep_by_space
= str
;
100 mon
.n_cs_precedes
= str
;
102 case T_N_SEP_BY_SPACE
:
103 mon
.n_sep_by_space
= str
;
106 mon
.p_sign_posn
= str
;
109 mon
.n_sign_posn
= str
;
111 case T_INT_P_CS_PRECEDES
:
112 mon
.int_p_cs_precedes
= str
;
114 case T_INT_N_CS_PRECEDES
:
115 mon
.int_n_cs_precedes
= str
;
117 case T_INT_P_SEP_BY_SPACE
:
118 mon
.int_p_sep_by_space
= str
;
120 case T_INT_N_SEP_BY_SPACE
:
121 mon
.int_n_sep_by_space
= str
;
123 case T_INT_P_SIGN_POSN
:
124 mon
.int_p_sign_posn
= str
;
126 case T_INT_N_SIGN_POSN
:
127 mon
.int_n_sign_posn
= str
;
130 mon
.mon_grouping
= str
;
139 reset_monetary_group(void)
141 free((char *)mon
.mon_grouping
);
142 mon
.mon_grouping
= NULL
;
146 add_monetary_group(int n
)
150 if (mon
.mon_grouping
== NULL
) {
151 (void) asprintf(&s
, "%d", n
);
153 (void) asprintf(&s
, "%s;%d", mon
.mon_grouping
, n
);
156 errf(_("out of memory"));
158 free((char *)mon
.mon_grouping
);
159 mon
.mon_grouping
= s
;
167 if ((f
= open_category()) == NULL
) {
171 if ((putl_category(mon
.int_curr_symbol
, f
) == EOF
) ||
172 (putl_category(mon
.currency_symbol
, f
) == EOF
) ||
173 (putl_category(mon
.mon_decimal_point
, f
) == EOF
) ||
174 (putl_category(mon
.mon_thousands_sep
, f
) == EOF
) ||
175 (putl_category(mon
.mon_grouping
, f
) == EOF
) ||
176 (putl_category(mon
.positive_sign
, f
) == EOF
) ||
177 (putl_category(mon
.negative_sign
, f
) == EOF
) ||
178 (putl_category(mon
.int_frac_digits
, f
) == EOF
) ||
179 (putl_category(mon
.frac_digits
, f
) == EOF
) ||
180 (putl_category(mon
.p_cs_precedes
, f
) == EOF
) ||
181 (putl_category(mon
.p_sep_by_space
, f
) == EOF
) ||
182 (putl_category(mon
.n_cs_precedes
, f
) == EOF
) ||
183 (putl_category(mon
.n_sep_by_space
, f
) == EOF
) ||
184 (putl_category(mon
.p_sign_posn
, f
) == EOF
) ||
185 (putl_category(mon
.n_sign_posn
, f
) == EOF
) ||
186 (putl_category(mon
.int_p_cs_precedes
, f
) == EOF
) ||
187 (putl_category(mon
.int_n_cs_precedes
, f
) == EOF
) ||
188 (putl_category(mon
.int_p_sep_by_space
, f
) == EOF
) ||
189 (putl_category(mon
.int_n_sep_by_space
, f
) == EOF
) ||
190 (putl_category(mon
.int_p_sign_posn
, f
) == EOF
) ||
191 (putl_category(mon
.int_n_sign_posn
, f
) == EOF
)) {