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.
38 #include <sys/types.h>
41 #include "localedef.h"
43 #include "timelocal.h"
45 static struct lc_time_T tm;
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. */
97 add_list(const char *ptr[], char *str, int limit)
100 for (i = 0; i < limit; i++) {
101 if (ptr[i] == NULL) {
106 fprintf(stderr,"too many list elements");
110 add_time_list(wchar_t *wcs)
114 if ((str = to_mb_string(wcs)) == NULL) {
122 add_list(tm.mon, str, 12);
125 add_list(tm.month, str, 12);
128 add_list(tm.wday, str, 7);
131 add_list(tm.weekday, str, 7);
136 } else if (tm.pm == NULL) {
139 fprintf(stderr,"too many list elements");
154 check_time_list(void)
158 if (tm.mon[11] != NULL)
162 if (tm.month[11] != NULL)
166 if (tm.wday[6] != NULL)
170 if (tm.weekday[6] != NULL)
181 fprintf(stderr,"unknown list");
185 fprintf(stderr,"too few items in list (%d)", last_kw);
188 #pragma GCC diagnostic push
189 #pragma GCC diagnostic ignored "-Wcast-qual"
192 reset_time_list(void)
197 for (i = 0; i < 12; i++) {
198 free((char *)tm.mon[i]);
203 for (i = 0; i < 12; i++) {
204 free((char *)tm.month[i]);
209 for (i = 0; i < 7; i++) {
210 free((char *)tm.wday[i]);
215 for (i = 0; i < 7; i++) {
216 free((char *)tm.weekday[i]);
217 tm.weekday[i] = NULL;
229 #pragma GCC diagnostic pop
237 if ((f = open_category()) == NULL) {
241 for (i = 0; i < 12; i++) {
242 if (putl_category(tm.mon[i], f) == EOF) {
246 for (i = 0; i < 12; i++) {
247 if (putl_category(tm.month[i], f) == EOF) {
251 for (i = 0; i < 7; i++) {
252 if (putl_category(tm.wday[i], f) == EOF) {
256 for (i = 0; i < 7; i++) {
257 if (putl_category(tm.weekday[i], f) == EOF) {
263 * NOTE: If date_fmt is not specified, then we'll default to
264 * using the %c for date. This is reasonable for most
265 * locales, although for reasons that I don't understand
266 * Solaris historically has had a seperate format for date.
268 if ((putl_category(tm.X_fmt, f) == EOF) ||
269 (putl_category(tm.x_fmt, f) == EOF) ||
270 (putl_category(tm.c_fmt, f) == EOF) ||
271 (putl_category(tm.am, f) == EOF) ||
272 (putl_category(tm.pm, f) == EOF) ||
273 (putl_category(tm.date_fmt ? tm.date_fmt : tm.c_fmt, f) == EOF) ||
274 (putl_category(tm.ampm_fmt, f) == EOF)) {