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_TIME database generation routines for localedef.
34 #include <sys/cdefs.h>
38 #include <sys/types.h>
41 #include "localedef.h"
43 #include "timelocal.h"
50 (void) memset(&tm
, 0, sizeof (tm
));
54 add_time_str(wchar_t *wcs
)
58 if ((str
= to_mb_string(wcs
)) == NULL
) {
79 * This one is a Solaris extension, Too bad date just
80 * doesn't use %c, which would be simpler.
87 /* Silently ignore it. */
98 add_list(const char *ptr
[], char *str
, int limit
)
101 for (i
= 0; i
< limit
; i
++) {
102 if (ptr
[i
] == NULL
) {
107 fprintf(stderr
,"too many list elements\n");
111 add_time_list(wchar_t *wcs
)
115 if ((str
= to_mb_string(wcs
)) == NULL
) {
123 add_list(tm
.mon
, str
, 12);
126 add_list(tm
.month
, str
, 12);
129 add_list(tm
.wday
, str
, 7);
132 add_list(tm
.weekday
, str
, 7);
137 } else if (tm
.pm
== NULL
) {
140 fprintf(stderr
,"too many list elements\n");
156 check_time_list(void)
160 if (tm
.mon
[11] != NULL
)
164 if (tm
.month
[11] != NULL
)
168 if (tm
.wday
[6] != NULL
)
172 if (tm
.weekday
[6] != NULL
)
183 fprintf(stderr
,"unknown list\n");
187 fprintf(stderr
,"too few items in list (%d)\n", last_kw
);
191 reset_time_list(void)
196 for (i
= 0; i
< 12; i
++) {
197 free((char *)tm
.mon
[i
]);
202 for (i
= 0; i
< 12; i
++) {
203 free((char *)tm
.month
[i
]);
208 for (i
= 0; i
< 7; i
++) {
209 free((char *)tm
.wday
[i
]);
214 for (i
= 0; i
< 7; i
++) {
215 free((char *)tm
.weekday
[i
]);
216 tm
.weekday
[i
] = NULL
;
234 if ((f
= open_category()) == NULL
) {
238 for (i
= 0; i
< 12; i
++) {
239 if (putl_category(tm
.mon
[i
], f
) == EOF
) {
243 for (i
= 0; i
< 12; i
++) {
244 if (putl_category(tm
.month
[i
], f
) == EOF
) {
248 for (i
= 0; i
< 7; i
++) {
249 if (putl_category(tm
.wday
[i
], f
) == EOF
) {
253 for (i
= 0; i
< 7; i
++) {
254 if (putl_category(tm
.weekday
[i
], f
) == EOF
) {
260 * NOTE: If date_fmt is not specified, then we'll default to
261 * using the %c for date. This is reasonable for most
262 * locales, although for reasons that I don't understand
263 * Solaris historically has had a separate format for date.
265 if ((putl_category(tm
.X_fmt
, f
) == EOF
) ||
266 (putl_category(tm
.x_fmt
, f
) == EOF
) ||
267 (putl_category(tm
.c_fmt
, f
) == EOF
) ||
268 (putl_category(tm
.am
, f
) == EOF
) ||
269 (putl_category(tm
.pm
, f
) == EOF
) ||
270 (putl_category(tm
.date_fmt
? tm
.date_fmt
: tm
.c_fmt
, f
) == EOF
) ||
271 (putl_category(tm
.ampm_fmt
, f
) == EOF
)) {