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>
35 __FBSDID("$FreeBSD$");
40 #include <sys/types.h>
43 #include "localedef.h"
45 #include "timelocal.h"
52 (void) memset(&tm, 0, sizeof (tm));
56 add_time_str(wchar_t *wcs)
60 if ((str = to_mb_string(wcs)) == NULL) {
81 * This one is a Solaris extension, Too bad date just
82 * doesn't use %c, which would be simpler.
89 /* Silently ignore it. */
100 add_list(const char *ptr[], char *str, int limit)
103 for (i = 0; i < limit; i++) {
104 if (ptr[i] == NULL) {
109 fprintf(stderr,"too many list elements");
113 add_time_list(wchar_t *wcs)
117 if ((str = to_mb_string(wcs)) == NULL) {
125 add_list(tm.mon, str, 12);
128 add_list(tm.month, str, 12);
131 add_list(tm.wday, str, 7);
134 add_list(tm.weekday, str, 7);
139 } else if (tm.pm == NULL) {
142 fprintf(stderr,"too many list elements");
158 check_time_list(void)
162 if (tm.mon[11] != NULL)
166 if (tm.month[11] != NULL)
170 if (tm.wday[6] != NULL)
174 if (tm.weekday[6] != NULL)
185 fprintf(stderr,"unknown list");
189 fprintf(stderr,"too few items in list (%d)", last_kw);
193 reset_time_list(void)
198 for (i = 0; i < 12; i++) {
199 free((char *)tm.mon[i]);
204 for (i = 0; i < 12; i++) {
205 free((char *)tm.month[i]);
210 for (i = 0; i < 7; i++) {
211 free((char *)tm.wday[i]);
216 for (i = 0; i < 7; i++) {
217 free((char *)tm.weekday[i]);
218 tm.weekday[i] = NULL;
236 if ((f = open_category()) == NULL) {
240 for (i = 0; i < 12; i++) {
241 if (putl_category(tm.mon[i], f) == EOF) {
245 for (i = 0; i < 12; i++) {
246 if (putl_category(tm.month[i], f) == EOF) {
250 for (i = 0; i < 7; i++) {
251 if (putl_category(tm.wday[i], f) == EOF) {
255 for (i = 0; i < 7; i++) {
256 if (putl_category(tm.weekday[i], f) == EOF) {
262 * NOTE: If date_fmt is not specified, then we'll default to
263 * using the %c for date. This is reasonable for most
264 * locales, although for reasons that I don't understand
265 * Solaris historically has had a separate format for date.
267 if ((putl_category(tm.X_fmt, f) == EOF) ||
268 (putl_category(tm.x_fmt, f) == EOF) ||
269 (putl_category(tm.c_fmt, f) == EOF) ||
270 (putl_category(tm.am, f) == EOF) ||
271 (putl_category(tm.pm, f) == EOF) ||
272 (putl_category(tm.date_fmt ? tm.date_fmt : tm.c_fmt, f) == EOF) ||
273 (putl_category(tm.ampm_fmt, f) == EOF)) {