2 * This file and its contents are supplied under the terms of the
3 * Common Development and Distribution License ("CDDL"), version 1.0.
4 * You may only use this file in accordance with the terms of version
7 * A full copy of the text of the CDDL should have accompanied this
8 * source. A copy of the CDDL is also available via the Internet at
9 * http://www.illumos.org/license/CDDL.
13 * Copyright 2013 Garrett D'Amore <garrett@damore.org>
14 * Copyright 2017 Nexenta Systems, Inc.
18 * LC_TIME database generation routines for localedef.
24 #include <sys/types.h>
27 #include "localedef.h"
28 #include "parser.tab.h"
29 #include "timelocal.h"
36 (void) memset(&tm
, 0, sizeof (tm
));
40 add_time_str(wchar_t *wcs
)
44 if ((str
= to_mb_string(wcs
)) == NULL
) {
65 * This one is a Solaris extension. Too bad date just
66 * doesn't use %c, which would be simpler.
73 /* Silently ignore it. */
84 add_list(const char *ptr
[], char *str
, int limit
)
87 for (i
= 0; i
< limit
; i
++) {
93 errf(_("too many list elements"));
97 add_time_list(wchar_t *wcs
)
101 if ((str
= to_mb_string(wcs
)) == NULL
) {
109 add_list(tm
.mon
, str
, 12);
112 add_list(tm
.month
, str
, 12);
115 add_list(tm
.wday
, str
, 7);
118 add_list(tm
.weekday
, str
, 7);
123 } else if (tm
.pm
== NULL
) {
126 errf(_("too many list elements"));
142 check_time_list(void)
146 if (tm
.mon
[11] != NULL
)
150 if (tm
.month
[11] != NULL
)
154 if (tm
.wday
[6] != NULL
)
158 if (tm
.weekday
[6] != NULL
)
169 errf(_("unknown list"));
173 errf(_("too few items in list (%d)"), last_kw
);
177 reset_time_list(void)
182 for (i
= 0; i
< 12; i
++) {
183 free((char *)tm
.mon
[i
]);
188 for (i
= 0; i
< 12; i
++) {
189 free((char *)tm
.month
[i
]);
194 for (i
= 0; i
< 7; i
++) {
195 free((char *)tm
.wday
[i
]);
200 for (i
= 0; i
< 7; i
++) {
201 free((char *)tm
.weekday
[i
]);
202 tm
.weekday
[i
] = NULL
;
221 if ((f
= open_category()) == NULL
) {
225 for (i
= 0; i
< 12; i
++) {
226 if (putl_category(tm
.mon
[i
], f
) == EOF
) {
230 for (i
= 0; i
< 12; i
++) {
231 if (putl_category(tm
.month
[i
], f
) == EOF
) {
235 for (i
= 0; i
< 7; i
++) {
236 if (putl_category(tm
.wday
[i
], f
) == EOF
) {
240 for (i
= 0; i
< 7; i
++) {
241 if (putl_category(tm
.weekday
[i
], f
) == EOF
) {
247 * NOTE: If date_fmt is not specified, then we'll default to
248 * using the %c for date. This is reasonable for most
249 * locales, although for reasons that I don't understand
250 * Solaris historically has had a separate format for date.
252 if ((putl_category(tm
.X_fmt
, f
) == EOF
) ||
253 (putl_category(tm
.x_fmt
, f
) == EOF
) ||
254 (putl_category(tm
.c_fmt
, f
) == EOF
) ||
255 (putl_category(tm
.am
, f
) == EOF
) ||
256 (putl_category(tm
.pm
, f
) == EOF
) ||
257 (putl_category(tm
.date_fmt
? tm
.date_fmt
: tm
.c_fmt
, f
) == EOF
) ||
258 (putl_category(tm
.ampm_fmt
, f
) == EOF
)) {