Print this page
2964 need POSIX 2008 locale object support
Reviewed by: Robert Mustacchi <rm@joyent.com>
Reviewed by: Gordon Ross <gordon.ross@nexenta.com>
Approved by: TBD
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/cmd/localedef/time.c
+++ new/usr/src/cmd/localedef/time.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_TIME 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 "timelocal.h"
29 30
30 -struct lc_time_T tm;
31 +struct lc_time tm;
31 32
32 33 void
33 34 init_time(void)
34 35 {
35 36 (void) memset(&tm, 0, sizeof (tm));
36 37 }
37 38
38 39 void
39 40 add_time_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
49 50 switch (last_kw) {
50 51 case T_D_T_FMT:
51 52 tm.c_fmt = str;
52 53 break;
53 54 case T_D_FMT:
54 55 tm.x_fmt = str;
55 56 break;
56 57 case T_T_FMT:
57 58 tm.X_fmt = str;
58 59 break;
59 60 case T_T_FMT_AMPM:
60 61 tm.ampm_fmt = str;
61 62 break;
62 63 case T_DATE_FMT:
63 64 /*
64 65 * This one is a Solaris extension, Too bad date just
65 66 * doesn't use %c, which would be simpler.
66 67 */
67 68 tm.date_fmt = str;
68 69 break;
69 70 case T_ERA_D_FMT:
70 71 case T_ERA_T_FMT:
71 72 case T_ERA_D_T_FMT:
72 73 /* Silently ignore it. */
73 74 break;
74 75 default:
75 76 free(str);
76 77 INTERR;
77 78 break;
78 79 }
79 80 }
80 81
81 82 static void
82 83 add_list(const char *ptr[], char *str, int limit)
83 84 {
84 85 int i;
85 86 for (i = 0; i < limit; i++) {
86 87 if (ptr[i] == NULL) {
87 88 ptr[i] = str;
88 89 return;
89 90 }
90 91 }
91 92 errf(_("too many list elements"));
92 93 }
93 94
94 95 void
95 96 add_time_list(wchar_t *wcs)
96 97 {
97 98 char *str;
98 99
99 100 if ((str = to_mb_string(wcs)) == NULL) {
100 101 INTERR;
101 102 return;
102 103 }
103 104 free(wcs);
104 105
105 106 switch (last_kw) {
106 107 case T_ABMON:
107 108 add_list(tm.mon, str, 12);
108 109 break;
109 110 case T_MON:
110 111 add_list(tm.month, str, 12);
111 112 break;
112 113 case T_ABDAY:
113 114 add_list(tm.wday, str, 7);
114 115 break;
115 116 case T_DAY:
116 117 add_list(tm.weekday, str, 7);
117 118 break;
118 119 case T_AM_PM:
119 120 if (tm.am == NULL) {
120 121 tm.am = str;
121 122 } else if (tm.pm == NULL) {
122 123 tm.pm = str;
123 124 } else {
124 125 errf(_("too many list elements"));
125 126 }
126 127 break;
127 128 case T_ALT_DIGITS:
128 129 case T_ERA:
129 130 free(str);
130 131 break;
131 132 default:
132 133 free(str);
133 134 INTERR;
134 135 break;
135 136 }
136 137 }
137 138
138 139 void
139 140 check_time_list(void)
140 141 {
141 142 switch (last_kw) {
142 143 case T_ABMON:
143 144 if (tm.mon[11] != NULL)
144 145 return;
145 146 break;
146 147 case T_MON:
147 148 if (tm.month[11] != NULL)
148 149 return;
149 150 break;
150 151 case T_ABDAY:
151 152 if (tm.wday[6] != NULL)
152 153 return;
153 154 break;
154 155 case T_DAY:
155 156 if (tm.weekday[6] != NULL)
156 157 return;
157 158 break;
158 159 case T_AM_PM:
159 160 if (tm.pm != NULL)
160 161 return;
161 162 break;
162 163 case T_ERA:
163 164 case T_ALT_DIGITS:
164 165 return;
165 166 default:
166 167 errf(_("unknown list"));
167 168 break;
168 169 }
169 170
170 171 errf(_("too few items in list (%d)"), last_kw);
171 172 }
172 173
173 174 void
174 175 reset_time_list(void)
175 176 {
176 177 int i;
177 178 switch (last_kw) {
178 179 case T_ABMON:
179 180 for (i = 0; i < 12; i++) {
180 181 free((char *)tm.mon[i]);
181 182 tm.mon[i] = NULL;
182 183 }
183 184 break;
184 185 case T_MON:
185 186 for (i = 0; i < 12; i++) {
186 187 free((char *)tm.month[i]);
187 188 tm.month[i] = NULL;
188 189 }
189 190 break;
190 191 case T_ABDAY:
191 192 for (i = 0; i < 7; i++) {
192 193 free((char *)tm.wday[i]);
193 194 tm.wday[i] = NULL;
194 195 }
195 196 break;
196 197 case T_DAY:
197 198 for (i = 0; i < 7; i++) {
198 199 free((char *)tm.weekday[i]);
199 200 tm.weekday[i] = NULL;
200 201 }
201 202 break;
202 203 case T_AM_PM:
203 204 free((char *)tm.am);
204 205 tm.am = NULL;
205 206 free((char *)tm.pm);
206 207 tm.pm = NULL;
207 208 break;
208 209 }
209 210 }
210 211
211 212
212 213 void
213 214 dump_time(void)
214 215 {
215 216 FILE *f;
216 217 int i;
217 218
218 219 if ((f = open_category()) == NULL) {
219 220 return;
220 221 }
221 222
222 223 for (i = 0; i < 12; i++) {
223 224 if (putl_category(tm.mon[i], f) == EOF) {
224 225 return;
225 226 }
226 227 }
227 228 for (i = 0; i < 12; i++) {
228 229 if (putl_category(tm.month[i], f) == EOF) {
229 230 return;
230 231 }
231 232 }
232 233 for (i = 0; i < 7; i++) {
233 234 if (putl_category(tm.wday[i], f) == EOF) {
234 235 return;
235 236 }
236 237 }
237 238 for (i = 0; i < 7; i++) {
238 239 if (putl_category(tm.weekday[i], f) == EOF) {
239 240 return;
240 241 }
241 242 }
242 243
243 244 /*
244 245 * NOTE: If date_fmt is not specified, then we'll default to
245 246 * using the %c for date. This is reasonable for most
246 247 * locales, although for reasons that I don't understand
247 248 * Solaris historically has had a seperate format for date.
248 249 */
249 250 if ((putl_category(tm.X_fmt, f) == EOF) ||
250 251 (putl_category(tm.x_fmt, f) == EOF) ||
251 252 (putl_category(tm.c_fmt, f) == EOF) ||
252 253 (putl_category(tm.am, f) == EOF) ||
253 254 (putl_category(tm.pm, f) == EOF) ||
254 255 (putl_category(tm.date_fmt ? tm.date_fmt : tm.c_fmt, f) == EOF) ||
255 256 (putl_category(tm.ampm_fmt, f) == EOF)) {
256 257 return;
257 258 }
258 259 close_category(f);
259 260 }
↓ open down ↓ |
219 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX