Print this page
2964 need POSIX 2008 locale object support
Reviewed by: Robert Mustacchi <rm@joyent.com>
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/cmd/localedef/monetary.c
+++ new/usr/src/cmd/localedef/monetary.c
1 1 /*
2 2 * This file and its contents are supplied under the terms of the
↓ open down ↓ |
2 lines elided |
↑ open up ↑ |
3 3 * Common Development and Distribution License ("CDDL"), version 1.0.
4 4 * You may only use this file in accordance with the terms of version
5 5 * 1.0 of the CDDL.
6 6 *
7 7 * A full copy of the text of the CDDL should have accompanied this
8 8 * source. A copy of the CDDL is also available via the Internet at
9 9 * http://www.illumos.org/license/CDDL.
10 10 */
11 11
12 12 /*
13 + * Copyright 2013 Garrett D'Amore <garrett@damore.org>
13 14 * Copyright 2010 Nexenta Systems, Inc. All rights reserved.
14 15 */
15 16
16 17 /*
17 18 * LC_MONETARY database generation routines for localedef.
18 19 */
19 20
20 21 #include <stdio.h>
21 22 #include <stdlib.h>
22 23 #include <errno.h>
23 24 #include <sys/types.h>
24 25 #include <string.h>
25 26 #include <unistd.h>
26 27 #include "localedef.h"
27 28 #include "parser.tab.h"
28 29 #include "lmonetary.h"
29 30
30 -static struct lc_monetary_T mon;
31 +static struct lc_monetary mon;
31 32
32 33 void
33 34 init_monetary(void)
34 35 {
35 36 (void) memset(&mon, 0, sizeof (mon));
36 37 }
37 38
38 39 void
39 40 add_monetary_str(wchar_t *wcs)
40 41 {
41 42 char *str;
42 43
43 44 if ((str = to_mb_string(wcs)) == NULL) {
44 45 INTERR;
45 46 return;
46 47 }
47 48 free(wcs);
48 49 switch (last_kw) {
49 50 case T_INT_CURR_SYMBOL:
50 51 mon.int_curr_symbol = str;
51 52 break;
52 53 case T_CURRENCY_SYMBOL:
53 54 mon.currency_symbol = str;
54 55 break;
55 56 case T_MON_DECIMAL_POINT:
56 57 mon.mon_decimal_point = str;
57 58 break;
58 59 case T_MON_THOUSANDS_SEP:
59 60 mon.mon_thousands_sep = str;
60 61 break;
61 62 case T_POSITIVE_SIGN:
62 63 mon.positive_sign = str;
63 64 break;
64 65 case T_NEGATIVE_SIGN:
65 66 mon.negative_sign = str;
66 67 break;
67 68 default:
68 69 free(str);
69 70 INTERR;
70 71 break;
71 72 }
72 73 }
73 74
74 75 void
75 76 add_monetary_num(int n)
76 77 {
77 78 char *str = NULL;
78 79
79 80 (void) asprintf(&str, "%d", n);
80 81 if (str == NULL) {
81 82 errf(_("out of memory"));
82 83 return;
83 84 }
84 85
85 86 switch (last_kw) {
86 87 case T_INT_FRAC_DIGITS:
87 88 mon.int_frac_digits = str;
88 89 break;
89 90 case T_FRAC_DIGITS:
90 91 mon.frac_digits = str;
91 92 break;
92 93 case T_P_CS_PRECEDES:
93 94 mon.p_cs_precedes = str;
94 95 break;
95 96 case T_P_SEP_BY_SPACE:
96 97 mon.p_sep_by_space = str;
97 98 break;
98 99 case T_N_CS_PRECEDES:
99 100 mon.n_cs_precedes = str;
100 101 break;
101 102 case T_N_SEP_BY_SPACE:
102 103 mon.n_sep_by_space = str;
103 104 break;
104 105 case T_P_SIGN_POSN:
105 106 mon.p_sign_posn = str;
106 107 break;
107 108 case T_N_SIGN_POSN:
108 109 mon.n_sign_posn = str;
109 110 break;
110 111 case T_INT_P_CS_PRECEDES:
111 112 mon.int_p_cs_precedes = str;
112 113 break;
113 114 case T_INT_N_CS_PRECEDES:
114 115 mon.int_n_cs_precedes = str;
115 116 break;
116 117 case T_INT_P_SEP_BY_SPACE:
117 118 mon.int_p_sep_by_space = str;
118 119 break;
119 120 case T_INT_N_SEP_BY_SPACE:
120 121 mon.int_n_sep_by_space = str;
121 122 break;
122 123 case T_INT_P_SIGN_POSN:
123 124 mon.int_p_sign_posn = str;
124 125 break;
125 126 case T_INT_N_SIGN_POSN:
126 127 mon.int_n_sign_posn = str;
127 128 break;
128 129 case T_MON_GROUPING:
129 130 mon.mon_grouping = str;
130 131 break;
131 132 default:
132 133 INTERR;
133 134 break;
134 135 }
135 136 }
136 137
137 138 void
138 139 reset_monetary_group(void)
139 140 {
140 141 free((char *)mon.mon_grouping);
141 142 mon.mon_grouping = NULL;
142 143 }
143 144
144 145 void
145 146 add_monetary_group(int n)
146 147 {
147 148 char *s = NULL;
148 149
149 150 if (mon.mon_grouping == NULL) {
150 151 (void) asprintf(&s, "%d", n);
151 152 } else {
152 153 (void) asprintf(&s, "%s;%d", mon.mon_grouping, n);
153 154 }
154 155 if (s == NULL)
155 156 errf(_("out of memory"));
156 157
157 158 free((char *)mon.mon_grouping);
158 159 mon.mon_grouping = s;
159 160 }
160 161
161 162 void
162 163 dump_monetary(void)
163 164 {
164 165 FILE *f;
165 166
166 167 if ((f = open_category()) == NULL) {
167 168 return;
168 169 }
169 170
170 171 if ((putl_category(mon.int_curr_symbol, f) == EOF) ||
171 172 (putl_category(mon.currency_symbol, f) == EOF) ||
172 173 (putl_category(mon.mon_decimal_point, f) == EOF) ||
173 174 (putl_category(mon.mon_thousands_sep, f) == EOF) ||
174 175 (putl_category(mon.mon_grouping, f) == EOF) ||
175 176 (putl_category(mon.positive_sign, f) == EOF) ||
176 177 (putl_category(mon.negative_sign, f) == EOF) ||
177 178 (putl_category(mon.int_frac_digits, f) == EOF) ||
178 179 (putl_category(mon.frac_digits, f) == EOF) ||
179 180 (putl_category(mon.p_cs_precedes, f) == EOF) ||
180 181 (putl_category(mon.p_sep_by_space, f) == EOF) ||
181 182 (putl_category(mon.n_cs_precedes, f) == EOF) ||
182 183 (putl_category(mon.n_sep_by_space, f) == EOF) ||
183 184 (putl_category(mon.p_sign_posn, f) == EOF) ||
184 185 (putl_category(mon.n_sign_posn, f) == EOF) ||
185 186 (putl_category(mon.int_p_cs_precedes, f) == EOF) ||
186 187 (putl_category(mon.int_n_cs_precedes, f) == EOF) ||
187 188 (putl_category(mon.int_p_sep_by_space, f) == EOF) ||
188 189 (putl_category(mon.int_n_sep_by_space, f) == EOF) ||
189 190 (putl_category(mon.int_p_sign_posn, f) == EOF) ||
190 191 (putl_category(mon.int_n_sign_posn, f) == EOF)) {
191 192 return;
192 193 }
193 194 close_category(f);
194 195 }
↓ open down ↓ |
154 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX