]> git.ipfire.org Git - thirdparty/glibc.git/blame - locale/programs/ld-time.c
Fix ChangeLog.
[thirdparty/glibc.git] / locale / programs / ld-time.c
CommitLineData
568035b7 1/* Copyright (C) 1995-2013 Free Software Foundation, Inc.
6d52618b 2 This file is part of the GNU C Library.
4b10dd6c 3 Contributed by Ulrich Drepper <drepper@gnu.org>, 1995.
19bc17a9 4
43bc8ac6 5 This program is free software; you can redistribute it and/or modify
2e2efe65
RM
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; version 2 of the License, or
8 (at your option) any later version.
19bc17a9 9
43bc8ac6 10 This program is distributed in the hope that it will be useful,
6d52618b 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
43bc8ac6
UD
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
19bc17a9 14
43bc8ac6 15 You should have received a copy of the GNU General Public License
59ba27a6 16 along with this program; if not, see <http://www.gnu.org/licenses/>. */
19bc17a9
RM
17
18#ifdef HAVE_CONFIG_H
19# include <config.h>
20#endif
21
4b10dd6c 22#include <byteswap.h>
19bc17a9 23#include <langinfo.h>
4b10dd6c 24#include <stdlib.h>
19bc17a9 25#include <string.h>
4b10dd6c 26#include <wchar.h>
e054f494 27#include <stdint.h>
4b10dd6c 28#include <sys/uio.h>
19bc17a9 29
19bc17a9
RM
30#include <assert.h>
31
4b10dd6c 32#include "localedef.h"
f2b98f97 33#include "linereader.h"
19bc17a9 34#include "localeinfo.h"
4b10dd6c 35#include "locfile.h"
19bc17a9
RM
36
37
c4029823
UD
38/* Entry describing an entry of the era specification. */
39struct era_data
40{
41 int32_t direction;
42 int32_t offset;
43 int32_t start_date[3];
44 int32_t stop_date[3];
45 const char *name;
46 const char *format;
4b10dd6c
UD
47 uint32_t *wname;
48 uint32_t *wformat;
c4029823
UD
49};
50
51
19bc17a9
RM
52/* The real definition of the struct for the LC_TIME locale. */
53struct locale_time_t
54{
55 const char *abday[7];
4b10dd6c 56 const uint32_t *wabday[7];
4b10dd6c 57 int abday_defined;
19bc17a9 58 const char *day[7];
4b10dd6c 59 const uint32_t *wday[7];
4b10dd6c 60 int day_defined;
19bc17a9 61 const char *abmon[12];
4b10dd6c 62 const uint32_t *wabmon[12];
4b10dd6c 63 int abmon_defined;
19bc17a9 64 const char *mon[12];
4b10dd6c 65 const uint32_t *wmon[12];
4b10dd6c 66 int mon_defined;
19bc17a9 67 const char *am_pm[2];
4b10dd6c 68 const uint32_t *wam_pm[2];
4b10dd6c 69 int am_pm_defined;
19bc17a9 70 const char *d_t_fmt;
4b10dd6c 71 const uint32_t *wd_t_fmt;
19bc17a9 72 const char *d_fmt;
4b10dd6c 73 const uint32_t *wd_fmt;
19bc17a9 74 const char *t_fmt;
4b10dd6c 75 const uint32_t *wt_fmt;
19bc17a9 76 const char *t_fmt_ampm;
4b10dd6c 77 const uint32_t *wt_fmt_ampm;
ec4b0518 78 const char **era;
4b10dd6c 79 const uint32_t **wera;
4b10dd6c 80 uint32_t num_era;
19bc17a9 81 const char *era_year;
4b10dd6c 82 const uint32_t *wera_year;
19bc17a9 83 const char *era_d_t_fmt;
4b10dd6c 84 const uint32_t *wera_d_t_fmt;
19bc17a9 85 const char *era_t_fmt;
4b10dd6c 86 const uint32_t *wera_t_fmt;
19bc17a9 87 const char *era_d_fmt;
4b10dd6c 88 const uint32_t *wera_d_fmt;
19bc17a9 89 const char *alt_digits[100];
4b10dd6c 90 const uint32_t *walt_digits[100];
d8337213
UD
91 const char *date_fmt;
92 const uint32_t *wdate_fmt;
4b10dd6c
UD
93 int alt_digits_defined;
94 unsigned char week_ndays;
95 uint32_t week_1stday;
96 unsigned char week_1stweek;
97 unsigned char first_weekday;
98 unsigned char first_workday;
99 unsigned char cal_direction;
100 const char *timezone;
101 const uint32_t *wtimezone;
c4029823
UD
102
103 struct era_data *era_entries;
19bc17a9
RM
104};
105
106
4b10dd6c
UD
107/* This constant is used to represent an empty wide character string. */
108static const uint32_t empty_wstr[1] = { 0 };
816e6eb5 109
19bc17a9 110
4b10dd6c
UD
111static void
112time_startup (struct linereader *lr, struct localedef_t *locale,
113 int ignore_content)
114{
115 if (!ignore_content)
116 locale->categories[LC_TIME].time =
117 (struct locale_time_t *) xcalloc (1, sizeof (struct locale_time_t));
19bc17a9 118
1ceb8afe 119 if (lr != NULL)
b9eb05d6
UD
120 {
121 lr->translate_strings = 1;
a9c27b3e 122 lr->return_widestr = 1;
b9eb05d6 123 }
19bc17a9
RM
124}
125
126
127void
47e8b443 128time_finish (struct localedef_t *locale, const struct charmap_t *charmap)
19bc17a9
RM
129{
130 struct locale_time_t *time = locale->categories[LC_TIME].time;
b9eb05d6
UD
131 int nothing = 0;
132
133 /* Now resolve copying and also handle completely missing definitions. */
134 if (time == NULL)
135 {
136 /* First see whether we were supposed to copy. If yes, find the
137 actual definition. */
138 if (locale->copy_name[LC_TIME] != NULL)
139 {
140 /* Find the copying locale. This has to happen transitively since
141 the locale we are copying from might also copying another one. */
142 struct localedef_t *from = locale;
143
144 do
145 from = find_locale (LC_TIME, from->copy_name[LC_TIME],
146 from->repertoire_name, charmap);
147 while (from->categories[LC_TIME].time == NULL
148 && from->copy_name[LC_TIME] != NULL);
149
150 time = locale->categories[LC_TIME].time
151 = from->categories[LC_TIME].time;
152 }
153
154 /* If there is still no definition issue an warning and create an
155 empty one. */
156 if (time == NULL)
157 {
70e51ab9 158 if (! be_quiet)
f2b98f97
UD
159 WITH_CUR_LOCALE (error (0, 0, _("\
160No definition for %s category found"), "LC_TIME"));
b9eb05d6
UD
161 time_startup (NULL, locale, 0);
162 time = locale->categories[LC_TIME].time;
163 nothing = 1;
164 }
165 }
4b10dd6c 166
3cc41984
UD
167#define noparen(arg1, argn...) arg1, ##argn
168#define TESTARR_ELEM(cat, val) \
b9eb05d6
UD
169 if (!time->cat##_defined) \
170 { \
3cc41984 171 const char *initval[] = { noparen val }; \
86d27307 172 unsigned int i; \
3cc41984
UD
173 \
174 if (! be_quiet && ! nothing) \
f2b98f97
UD
175 WITH_CUR_LOCALE (error (0, 0, _("%s: field `%s' not defined"), \
176 "LC_TIME", #cat)); \
3cc41984
UD
177 \
178 for (i = 0; i < sizeof (initval) / sizeof (initval[0]); ++i) \
179 time->cat[i] = initval[i]; \
4b10dd6c
UD
180 }
181
3cc41984
UD
182 TESTARR_ELEM (abday, ( "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" ));
183 TESTARR_ELEM (day, ( "Sunday", "Monday", "Tuesday", "Wednesday",
184 "Thursday", "Friday", "Saturday" ));
185 TESTARR_ELEM (abmon, ( "Jan", "Feb", "Mar", "Apr", "May", "Jun",
186 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" ));
187 TESTARR_ELEM (mon, ( "January", "February", "March", "April",
188 "May", "June", "July", "August",
189 "September", "October", "November", "December" ));
190 TESTARR_ELEM (am_pm, ( "AM", "PM" ));
191
192#define TEST_ELEM(cat, initval) \
b9eb05d6
UD
193 if (time->cat == NULL) \
194 { \
195 if (! be_quiet && ! nothing) \
f2b98f97
UD
196 WITH_CUR_LOCALE (error (0, 0, _("%s: field `%s' not defined"), \
197 "LC_TIME", #cat)); \
3cc41984
UD
198 \
199 time->cat = initval; \
4b10dd6c 200 }
19bc17a9 201
3cc41984
UD
202 TEST_ELEM (d_t_fmt, "%a %b %e %H:%M:%S %Y");
203 TEST_ELEM (d_fmt, "%m/%d/%y");
204 TEST_ELEM (t_fmt, "%H:%M:%S");
5a97622d
UD
205
206 /* According to C.Y.Alexis Cheng <alexis@vnet.ibm.com> the T_FMT_AMPM
207 field is optional. */
208 if (time->t_fmt_ampm == NULL)
4b10dd6c 209 {
3cc41984
UD
210 if (time->am_pm[0][0] == '\0' && time->am_pm[1][0] == '\0')
211 {
212 /* No AM/PM strings defined, use the 24h format as default. */
213 time->t_fmt_ampm = time->t_fmt;
214 time->wt_fmt_ampm = time->wt_fmt;
215 }
216 else
217 {
218 time->t_fmt_ampm = "%I:%M:%S %p";
219 time->wt_fmt_ampm = (const uint32_t *) L"%I:%M:%S %p";
220 }
4b10dd6c 221 }
c4029823
UD
222
223 /* Now process the era entries. */
4b10dd6c 224 if (time->num_era != 0)
c4029823
UD
225 {
226 const int days_per_month[12] = { 31, 29, 31, 30, 31, 30,
227 31, 31, 30, 31 ,30, 31 };
228 size_t idx;
4b10dd6c 229 wchar_t *wstr;
c4029823
UD
230
231 time->era_entries =
4b10dd6c 232 (struct era_data *) xmalloc (time->num_era
c4029823
UD
233 * sizeof (struct era_data));
234
4b10dd6c 235 for (idx = 0; idx < time->num_era; ++idx)
c4029823
UD
236 {
237 size_t era_len = strlen (time->era[idx]);
238 char *str = xmalloc ((era_len + 1 + 3) & ~3);
239 char *endp;
240
241 memcpy (str, time->era[idx], era_len + 1);
242
243 /* First character must be + or - for the direction. */
880f421f 244 if (*str != '+' && *str != '-')
c4029823 245 {
880f421f 246 if (!be_quiet)
f2b98f97
UD
247 WITH_CUR_LOCALE (error (0, 0, _("\
248%s: direction flag in string %Zd in `era' field is not '+' nor '-'"),
249 "LC_TIME", idx + 1));
c4029823
UD
250 /* Default arbitrarily to '+'. */
251 time->era_entries[idx].direction = '+';
252 }
253 else
254 time->era_entries[idx].direction = *str;
880f421f 255 if (*++str != ':')
c4029823 256 {
880f421f 257 if (!be_quiet)
f2b98f97
UD
258 WITH_CUR_LOCALE (error (0, 0, _("\
259%s: direction flag in string %Zd in `era' field is not a single character"),
260 "LC_TIME", idx + 1));
c4029823
UD
261 (void) strsep (&str, ":");
262 }
263 else
264 ++str;
265
266 /* Now the offset year. */
267 time->era_entries[idx].offset = strtol (str, &endp, 10);
880f421f 268 if (endp == str)
c4029823 269 {
880f421f 270 if (!be_quiet)
f2b98f97
UD
271 WITH_CUR_LOCALE (error (0, 0, _("\
272%s: invalid number for offset in string %Zd in `era' field"),
273 "LC_TIME", idx + 1));
c4029823
UD
274 (void) strsep (&str, ":");
275 }
880f421f 276 else if (*endp != ':')
c4029823 277 {
880f421f 278 if (!be_quiet)
f2b98f97
UD
279 WITH_CUR_LOCALE (error (0, 0, _("\
280%s: garbage at end of offset value in string %Zd in `era' field"),
281 "LC_TIME", idx + 1));
c4029823
UD
282 (void) strsep (&str, ":");
283 }
284 else
285 str = endp + 1;
286
287 /* Next is the starting date in ISO format. */
288 if (strncmp (str, "-*", 2) == 0)
289 {
290 time->era_entries[idx].start_date[0] =
291 time->era_entries[idx].start_date[1] =
292 time->era_entries[idx].start_date[2] = 0x80000000;
293 if (str[2] != ':')
294 goto garbage_start_date;
295 str += 3;
296 }
297 else if (strncmp (str, "+*", 2) == 0)
298 {
299 time->era_entries[idx].start_date[0] =
300 time->era_entries[idx].start_date[1] =
301 time->era_entries[idx].start_date[2] = 0x7fffffff;
302 if (str[2] != ':')
303 goto garbage_start_date;
304 str += 3;
305 }
306 else
307 {
308 time->era_entries[idx].start_date[0] = strtol (str, &endp, 10);
309 if (endp == str || *endp != '/')
310 goto invalid_start_date;
311 else
312 str = endp + 1;
313 time->era_entries[idx].start_date[0] -= 1900;
958d6807
UD
314 /* year -1 represent 1 B.C. (not -1 A.D.) */
315 if (time->era_entries[idx].start_date[0] < -1900)
316 ++time->era_entries[idx].start_date[0];
c4029823
UD
317
318 time->era_entries[idx].start_date[1] = strtol (str, &endp, 10);
319 if (endp == str || *endp != '/')
320 goto invalid_start_date;
321 else
322 str = endp + 1;
323 time->era_entries[idx].start_date[1] -= 1;
324
325 time->era_entries[idx].start_date[2] = strtol (str, &endp, 10);
880f421f 326 if (endp == str)
c4029823
UD
327 {
328 invalid_start_date:
880f421f 329 if (!be_quiet)
f2b98f97
UD
330 WITH_CUR_LOCALE (error (0, 0, _("\
331%s: invalid starting date in string %Zd in `era' field"),
332 "LC_TIME", idx + 1));
c4029823
UD
333 (void) strsep (&str, ":");
334 }
880f421f 335 else if (*endp != ':')
c4029823
UD
336 {
337 garbage_start_date:
880f421f 338 if (!be_quiet)
f2b98f97
UD
339 WITH_CUR_LOCALE (error (0, 0, _("\
340%s: garbage at end of starting date in string %Zd in `era' field "),
341 "LC_TIME", idx + 1));
c4029823
UD
342 (void) strsep (&str, ":");
343 }
344 else
345 {
346 str = endp + 1;
347
348 /* Check for valid value. */
c84142e8
UD
349 if ((time->era_entries[idx].start_date[1] < 0
350 || time->era_entries[idx].start_date[1] >= 12
351 || time->era_entries[idx].start_date[2] < 0
352 || (time->era_entries[idx].start_date[2]
353 > days_per_month[time->era_entries[idx].start_date[1]])
354 || (time->era_entries[idx].start_date[1] == 2
355 && time->era_entries[idx].start_date[2] == 29
356 && !__isleap (time->era_entries[idx].start_date[0])))
357 && !be_quiet)
f2b98f97
UD
358 WITH_CUR_LOCALE (error (0, 0, _("\
359%s: starting date is invalid in string %Zd in `era' field"),
360 "LC_TIME", idx + 1));
c4029823
UD
361 }
362 }
363
6d52618b 364 /* Next is the stopping date in ISO format. */
c4029823
UD
365 if (strncmp (str, "-*", 2) == 0)
366 {
367 time->era_entries[idx].stop_date[0] =
368 time->era_entries[idx].stop_date[1] =
369 time->era_entries[idx].stop_date[2] = 0x80000000;
370 if (str[2] != ':')
371 goto garbage_stop_date;
372 str += 3;
373 }
374 else if (strncmp (str, "+*", 2) == 0)
375 {
376 time->era_entries[idx].stop_date[0] =
377 time->era_entries[idx].stop_date[1] =
378 time->era_entries[idx].stop_date[2] = 0x7fffffff;
379 if (str[2] != ':')
380 goto garbage_stop_date;
381 str += 3;
382 }
383 else
384 {
385 time->era_entries[idx].stop_date[0] = strtol (str, &endp, 10);
386 if (endp == str || *endp != '/')
387 goto invalid_stop_date;
388 else
389 str = endp + 1;
390 time->era_entries[idx].stop_date[0] -= 1900;
958d6807
UD
391 /* year -1 represent 1 B.C. (not -1 A.D.) */
392 if (time->era_entries[idx].stop_date[0] < -1900)
393 ++time->era_entries[idx].stop_date[0];
c4029823
UD
394
395 time->era_entries[idx].stop_date[1] = strtol (str, &endp, 10);
396 if (endp == str || *endp != '/')
397 goto invalid_stop_date;
398 else
399 str = endp + 1;
400 time->era_entries[idx].stop_date[1] -= 1;
401
402 time->era_entries[idx].stop_date[2] = strtol (str, &endp, 10);
880f421f 403 if (endp == str)
c4029823
UD
404 {
405 invalid_stop_date:
880f421f 406 if (!be_quiet)
f2b98f97
UD
407 WITH_CUR_LOCALE (error (0, 0, _("\
408%s: invalid stopping date in string %Zd in `era' field"),
409 "LC_TIME", idx + 1));
c4029823
UD
410 (void) strsep (&str, ":");
411 }
880f421f 412 else if (*endp != ':')
c4029823
UD
413 {
414 garbage_stop_date:
880f421f 415 if (!be_quiet)
f2b98f97
UD
416 WITH_CUR_LOCALE (error (0, 0, _("\
417%s: garbage at end of stopping date in string %Zd in `era' field"),
418 "LC_TIME", idx + 1));
c4029823
UD
419 (void) strsep (&str, ":");
420 }
421 else
422 {
423 str = endp + 1;
424
425 /* Check for valid value. */
c84142e8
UD
426 if ((time->era_entries[idx].stop_date[1] < 0
427 || time->era_entries[idx].stop_date[1] >= 12
428 || time->era_entries[idx].stop_date[2] < 0
429 || (time->era_entries[idx].stop_date[2]
430 > days_per_month[time->era_entries[idx].stop_date[1]])
431 || (time->era_entries[idx].stop_date[1] == 2
432 && time->era_entries[idx].stop_date[2] == 29
433 && !__isleap (time->era_entries[idx].stop_date[0])))
434 && !be_quiet)
f2b98f97 435 WITH_CUR_LOCALE (error (0, 0, _("\
1d20f7f8 436%s: invalid stopping date in string %Zd in `era' field"),
f2b98f97 437 "LC_TIME", idx + 1));
c4029823
UD
438 }
439 }
440
880f421f 441 if (str == NULL || *str == '\0')
c4029823 442 {
880f421f 443 if (!be_quiet)
f2b98f97
UD
444 WITH_CUR_LOCALE (error (0, 0, _("\
445%s: missing era name in string %Zd in `era' field"), "LC_TIME", idx + 1));
4b10dd6c
UD
446 time->era_entries[idx].name =
447 time->era_entries[idx].format = "";
c4029823
UD
448 }
449 else
450 {
451 time->era_entries[idx].name = strsep (&str, ":");
452
880f421f 453 if (str == NULL || *str == '\0')
c4029823 454 {
880f421f 455 if (!be_quiet)
f2b98f97
UD
456 WITH_CUR_LOCALE (error (0, 0, _("\
457%s: missing era format in string %Zd in `era' field"),
458 "LC_TIME", idx + 1));
4b10dd6c
UD
459 time->era_entries[idx].name =
460 time->era_entries[idx].format = "";
c4029823
UD
461 }
462 else
463 time->era_entries[idx].format = str;
464 }
4b10dd6c
UD
465
466 /* Now generate the wide character name and format. */
a9c27b3e
UD
467 wstr = wcschr ((wchar_t *) time->wera[idx], L':');/* end direction */
468 wstr = wstr ? wcschr (wstr + 1, L':') : NULL; /* end offset */
469 wstr = wstr ? wcschr (wstr + 1, L':') : NULL; /* end start */
470 wstr = wstr ? wcschr (wstr + 1, L':') : NULL; /* end end */
e7c8359e
UD
471 if (wstr != NULL)
472 {
3d237e42 473 time->era_entries[idx].wname = (uint32_t *) wstr + 1;
e7c8359e 474 wstr = wcschr (wstr + 1, L':'); /* end name */
3d237e42
UD
475 if (wstr != NULL)
476 {
477 *wstr = L'\0';
478 time->era_entries[idx].wformat = (uint32_t *) wstr + 1;
479 }
480 else
481 time->era_entries[idx].wname =
482 time->era_entries[idx].wformat = (uint32_t *) L"";
e7c8359e
UD
483 }
484 else
3d237e42
UD
485 time->era_entries[idx].wname =
486 time->era_entries[idx].wformat = (uint32_t *) L"";
c4029823 487 }
c4029823 488 }
4b10dd6c
UD
489
490 if (time->week_ndays == 0)
491 time->week_ndays = 7;
492
493 if (time->week_1stday == 0)
494 time->week_1stday = 19971130;
495
496 if (time->week_1stweek > time->week_ndays)
f2b98f97 497 WITH_CUR_LOCALE (error (0, 0, _("\
4b10dd6c 498%s: third operand for value of field `%s' must not be larger than %d"),
f2b98f97 499 "LC_TIME", "week", 7));
4b10dd6c
UD
500
501 if (time->first_weekday == '\0')
502 /* The definition does not specify this so the default is used. */
503 time->first_weekday = 1;
504 else if (time->first_weekday > time->week_ndays)
f2b98f97 505 WITH_CUR_LOCALE (error (0, 0, _("\
11bf311e 506%s: values for field `%s' must not be larger than %d"),
f2b98f97 507 "LC_TIME", "first_weekday", 7));
4b10dd6c
UD
508
509 if (time->first_workday == '\0')
510 /* The definition does not specify this so the default is used. */
659a9013 511 time->first_workday = 2;
4b10dd6c 512 else if (time->first_workday > time->week_ndays)
f2b98f97 513 WITH_CUR_LOCALE (error (0, 0, _("\
11bf311e 514%s: values for field `%s' must not be larger than %d"),
f2b98f97 515 "LC_TIME", "first_workday", 7));
4b10dd6c
UD
516
517 if (time->cal_direction == '\0')
518 /* The definition does not specify this so the default is used. */
519 time->cal_direction = 1;
520 else if (time->cal_direction > 3)
f2b98f97 521 WITH_CUR_LOCALE (error (0, 0, _("\
70e51ab9 522%s: values for field `%s' must not be larger than %d"),
f2b98f97 523 "LC_TIME", "cal_direction", 3));
4b10dd6c
UD
524
525 /* XXX We don't perform any tests on the timezone value since this is
526 simply useless, stupid $&$!@... */
527 if (time->timezone == NULL)
528 time->timezone = "";
d8337213
UD
529
530 if (time->date_fmt == NULL)
531 time->date_fmt = "%a %b %e %H:%M:%S %Z %Y";
532 if (time->wdate_fmt == NULL)
533 time->wdate_fmt = (const uint32_t *) L"%a %b %e %H:%M:%S %Z %Y";
19bc17a9
RM
534}
535
536
537void
47e8b443 538time_output (struct localedef_t *locale, const struct charmap_t *charmap,
4b10dd6c 539 const char *output_path)
19bc17a9
RM
540{
541 struct locale_time_t *time = locale->categories[LC_TIME].time;
db2f05ba
RM
542 struct iovec *iov = alloca (sizeof *iov
543 * (2 + _NL_ITEM_INDEX (_NL_NUM_LC_TIME)
544 + time->num_era - 1
545 + 2 * 99
9a5c46e8 546 + 2 + time->num_era * 10));
19bc17a9 547 struct locale_file data;
4b10dd6c
UD
548 uint32_t idx[_NL_ITEM_INDEX (_NL_NUM_LC_TIME)];
549 size_t cnt, last_idx, num, n;
19bc17a9
RM
550
551 data.magic = LIMAGIC (LC_TIME);
552 data.n = _NL_ITEM_INDEX (_NL_NUM_LC_TIME);
553 iov[0].iov_base = (void *) &data;
554 iov[0].iov_len = sizeof (data);
555
556 iov[1].iov_base = (void *) idx;
557 iov[1].iov_len = sizeof (idx);
558
559 idx[0] = iov[0].iov_len + iov[1].iov_len;
560
561 /* The ab'days. */
562 for (cnt = 0; cnt <= _NL_ITEM_INDEX (ABDAY_7); ++cnt)
563 {
564 iov[2 + cnt].iov_base =
565 (void *) (time->abday[cnt - _NL_ITEM_INDEX (ABDAY_1)] ?: "");
566 iov[2 + cnt].iov_len = strlen (iov[2 + cnt].iov_base) + 1;
567 idx[1 + cnt] = idx[cnt] + iov[2 + cnt].iov_len;
568 }
569
570 /* The days. */
571 for (; cnt <= _NL_ITEM_INDEX (DAY_7); ++cnt)
572 {
573 iov[2 + cnt].iov_base =
574 (void *) (time->day[cnt - _NL_ITEM_INDEX (DAY_1)] ?: "");
575 iov[2 + cnt].iov_len = strlen (iov[2 + cnt].iov_base) + 1;
576 idx[1 + cnt] = idx[cnt] + iov[2 + cnt].iov_len;
577 }
578
579 /* The ab'mons. */
580 for (; cnt <= _NL_ITEM_INDEX (ABMON_12); ++cnt)
581 {
582 iov[2 + cnt].iov_base =
583 (void *) (time->abmon[cnt - _NL_ITEM_INDEX (ABMON_1)] ?: "");
584 iov[2 + cnt].iov_len = strlen (iov[2 + cnt].iov_base) + 1;
585 idx[1 + cnt] = idx[cnt] + iov[2 + cnt].iov_len;
586 }
587
588 /* The mons. */
589 for (; cnt <= _NL_ITEM_INDEX (MON_12); ++cnt)
590 {
591 iov[2 + cnt].iov_base =
592 (void *) (time->mon[cnt - _NL_ITEM_INDEX (MON_1)] ?: "");
593 iov[2 + cnt].iov_len = strlen (iov[2 + cnt].iov_base) + 1;
594 idx[1 + cnt] = idx[cnt] + iov[2 + cnt].iov_len;
595 }
596
597 /* AM/PM. */
598 for (; cnt <= _NL_ITEM_INDEX (PM_STR); ++cnt)
599 {
600 iov[2 + cnt].iov_base =
601 (void *) (time->am_pm[cnt - _NL_ITEM_INDEX (AM_STR)] ?: "");
602 iov[2 + cnt].iov_len = strlen (iov[2 + cnt].iov_base) + 1;
603 idx[1 + cnt] = idx[cnt] + iov[2 + cnt].iov_len;
604 }
605
606 iov[2 + cnt].iov_base = (void *) (time->d_t_fmt ?: "");
607 iov[2 + cnt].iov_len = strlen (iov[2 + cnt].iov_base) + 1;
608 idx[1 + cnt] = idx[cnt] + iov[2 + cnt].iov_len;
609 ++cnt;
610
611 iov[2 + cnt].iov_base = (void *) (time->d_fmt ?: "");
612 iov[2 + cnt].iov_len = strlen (iov[2 + cnt].iov_base) + 1;
613 idx[1 + cnt] = idx[cnt] + iov[2 + cnt].iov_len;
614 ++cnt;
615
616 iov[2 + cnt].iov_base = (void *) (time->t_fmt ?: "");
617 iov[2 + cnt].iov_len = strlen (iov[2 + cnt].iov_base) + 1;
618 idx[1 + cnt] = idx[cnt] + iov[2 + cnt].iov_len;
619 ++cnt;
620
621 iov[2 + cnt].iov_base = (void *) (time->t_fmt_ampm ?: "");
622 iov[2 + cnt].iov_len = strlen (iov[2 + cnt].iov_base) + 1;
623 idx[1 + cnt] = idx[cnt] + iov[2 + cnt].iov_len;
ec4b0518 624 last_idx = ++cnt;
19bc17a9 625
ec4b0518 626 idx[1 + last_idx] = idx[last_idx];
4b10dd6c 627 for (num = 0; num < time->num_era; ++num, ++cnt)
ec4b0518
UD
628 {
629 iov[2 + cnt].iov_base = (void *) time->era[num];
630 iov[2 + cnt].iov_len = strlen (iov[2 + cnt].iov_base) + 1;
c4029823 631 idx[1 + last_idx] += iov[2 + cnt].iov_len;
ec4b0518
UD
632 }
633 ++last_idx;
19bc17a9
RM
634
635 iov[2 + cnt].iov_base = (void *) (time->era_year ?: "");
636 iov[2 + cnt].iov_len = strlen (iov[2 + cnt].iov_base) + 1;
ec4b0518 637 idx[1 + last_idx] = idx[last_idx] + iov[2 + cnt].iov_len;
19bc17a9 638 ++cnt;
ec4b0518 639 ++last_idx;
19bc17a9
RM
640
641 iov[2 + cnt].iov_base = (void *) (time->era_d_fmt ?: "");
642 iov[2 + cnt].iov_len = strlen (iov[2 + cnt].iov_base) + 1;
ec4b0518
UD
643 idx[1 + last_idx] = idx[last_idx] + iov[2 + cnt].iov_len;
644 ++cnt;
645 ++last_idx;
19bc17a9
RM
646
647 idx[1 + last_idx] = idx[last_idx];
4b10dd6c 648 for (num = 0; num < 100; ++num, ++cnt)
19bc17a9
RM
649 {
650 iov[2 + cnt].iov_base = (void *) (time->alt_digits[num] ?: "");
651 iov[2 + cnt].iov_len = strlen (iov[2 + cnt].iov_base) + 1;
652 idx[1 + last_idx] += iov[2 + cnt].iov_len;
653 }
654 ++last_idx;
655
656 iov[2 + cnt].iov_base = (void *) (time->era_d_t_fmt ?: "");
657 iov[2 + cnt].iov_len = strlen (iov[2 + cnt].iov_base) + 1;
658 idx[1 + last_idx] = idx[last_idx] + iov[2 + cnt].iov_len;
659 ++cnt;
c4029823 660 ++last_idx;
19bc17a9 661
c4029823 662 iov[2 + cnt].iov_base = (void *) (time->era_t_fmt ?: "");
19bc17a9 663 iov[2 + cnt].iov_len = strlen (iov[2 + cnt].iov_base) + 1;
c4029823 664 idx[1 + last_idx] = idx[last_idx] + iov[2 + cnt].iov_len;
19bc17a9 665 ++cnt;
c4029823
UD
666 ++last_idx;
667
668
669 /* We must align the following data. */
670 iov[2 + cnt].iov_base = (void *) "\0\0";
671 iov[2 + cnt].iov_len = ((idx[last_idx] + 3) & ~3) - idx[last_idx];
672 idx[last_idx] = (idx[last_idx] + 3) & ~3;
673 ++cnt;
674
4b10dd6c 675 /* The `era' data in usable form. */
4a33c2f5 676 iov[2 + cnt].iov_base = (void *) &time->num_era;
4b10dd6c 677 iov[2 + cnt].iov_len = sizeof (uint32_t);
c4029823
UD
678 idx[1 + last_idx] = idx[last_idx] + iov[2 + cnt].iov_len;
679 ++cnt;
680 ++last_idx;
681
c4029823 682 idx[1 + last_idx] = idx[last_idx];
4b10dd6c 683 for (num = 0; num < time->num_era; ++num)
c4029823 684 {
ad316adf 685 size_t l, l2;
c4029823 686
4a33c2f5 687 iov[2 + cnt].iov_base = (void *) &time->era_entries[num].direction;
c4029823
UD
688 iov[2 + cnt].iov_len = sizeof (int32_t);
689 ++cnt;
4a33c2f5 690 iov[2 + cnt].iov_base = (void *) &time->era_entries[num].offset;
c4029823
UD
691 iov[2 + cnt].iov_len = sizeof (int32_t);
692 ++cnt;
4a33c2f5 693 iov[2 + cnt].iov_base = (void *) &time->era_entries[num].start_date[0];
4b10dd6c
UD
694 iov[2 + cnt].iov_len = sizeof (int32_t);
695 ++cnt;
4a33c2f5 696 iov[2 + cnt].iov_base = (void *) &time->era_entries[num].start_date[1];
4b10dd6c
UD
697 iov[2 + cnt].iov_len = sizeof (int32_t);
698 ++cnt;
4a33c2f5 699 iov[2 + cnt].iov_base = (void *) &time->era_entries[num].start_date[2];
4b10dd6c 700 iov[2 + cnt].iov_len = sizeof (int32_t);
c4029823 701 ++cnt;
4a33c2f5 702 iov[2 + cnt].iov_base = (void *) &time->era_entries[num].stop_date[0];
4b10dd6c
UD
703 iov[2 + cnt].iov_len = sizeof (int32_t);
704 ++cnt;
4a33c2f5 705 iov[2 + cnt].iov_base = (void *) &time->era_entries[num].stop_date[1];
4b10dd6c
UD
706 iov[2 + cnt].iov_len = sizeof (int32_t);
707 ++cnt;
4a33c2f5 708 iov[2 + cnt].iov_base = (void *) &time->era_entries[num].stop_date[2];
4b10dd6c 709 iov[2 + cnt].iov_len = sizeof (int32_t);
c4029823
UD
710 ++cnt;
711
86d27307 712 l = ((char *) rawmemchr (time->era_entries[num].format, '\0')
4a33c2f5 713 - time->era_entries[num].name) + 1;
ad316adf
UD
714 l2 = (l + 3) & ~3;
715 iov[2 + cnt].iov_base = alloca (l2);
716 memset (mempcpy (iov[2 + cnt].iov_base, time->era_entries[num].name, l),
717 '\0', l2 - l);
718 iov[2 + cnt].iov_len = l2;
c4029823
UD
719 ++cnt;
720
ad316adf 721 idx[1 + last_idx] += 8 * sizeof (int32_t) + l2;
c4029823
UD
722
723 assert (idx[1 + last_idx] % 4 == 0);
4b10dd6c 724
4a33c2f5 725 iov[2 + cnt].iov_base = (void *) time->era_entries[num].wname;
a9c27b3e 726 iov[2 + cnt].iov_len = ((wcschr ((wchar_t *) time->era_entries[num].wformat, L'\0')
4a33c2f5 727 - (wchar_t *) time->era_entries[num].wname + 1)
4b10dd6c 728 * sizeof (uint32_t));
4b10dd6c 729 idx[1 + last_idx] += iov[2 + cnt].iov_len;
a9c27b3e 730 ++cnt;
c4029823 731 }
4b10dd6c 732 ++last_idx;
c4029823 733
4b10dd6c
UD
734 /* The wide character ab'days. */
735 for (n = 0; n < 7; ++n, ++cnt, ++last_idx)
a68b0d31 736 {
4b10dd6c 737 iov[2 + cnt].iov_base =
4a33c2f5 738 (void *) (time->wabday[n] ?: empty_wstr);
4b10dd6c
UD
739 iov[2 + cnt].iov_len = ((wcslen (iov[2 + cnt].iov_base) + 1)
740 * sizeof (uint32_t));
741 idx[1 + last_idx] = idx[last_idx] + iov[2 + cnt].iov_len;
742 }
743
744 /* The wide character days. */
745 for (n = 0; n < 7; ++n, ++cnt, ++last_idx)
746 {
747 iov[2 + cnt].iov_base =
4a33c2f5 748 (void *) (time->wday[n] ?: empty_wstr);
4b10dd6c
UD
749 iov[2 + cnt].iov_len = ((wcslen (iov[2 + cnt].iov_base) + 1)
750 * sizeof (uint32_t));
751 idx[1 + last_idx] = idx[last_idx] + iov[2 + cnt].iov_len;
752 }
753
754 /* The wide character ab'mons. */
755 for (n = 0; n < 12; ++n, ++cnt, ++last_idx)
756 {
757 iov[2 + cnt].iov_base =
4a33c2f5 758 (void *) (time->wabmon[n] ?: empty_wstr);
4b10dd6c
UD
759 iov[2 + cnt].iov_len = ((wcslen (iov[2 + cnt].iov_base) + 1)
760 * sizeof (uint32_t));
761 idx[1 + last_idx] = idx[last_idx] + iov[2 + cnt].iov_len;
762 }
763
764 /* The wide character mons. */
765 for (n = 0; n < 12; ++n, ++cnt, ++last_idx)
766 {
767 iov[2 + cnt].iov_base =
4a33c2f5 768 (void *) (time->wmon[n] ?: empty_wstr);
4b10dd6c
UD
769 iov[2 + cnt].iov_len = ((wcslen (iov[2 + cnt].iov_base) + 1)
770 * sizeof (uint32_t));
771 idx[1 + last_idx] = idx[last_idx] + iov[2 + cnt].iov_len;
772 }
773
774 /* Wide character AM/PM. */
775 for (n = 0; n < 2; ++n, ++cnt, ++last_idx)
776 {
777 iov[2 + cnt].iov_base =
4a33c2f5 778 (void *) (time->wam_pm[n] ?: empty_wstr);
4b10dd6c
UD
779 iov[2 + cnt].iov_len = ((wcslen (iov[2 + cnt].iov_base) + 1)
780 * sizeof (uint32_t));
781 idx[1 + last_idx] = idx[last_idx] + iov[2 + cnt].iov_len;
782 }
783
4a33c2f5 784 iov[2 + cnt].iov_base = (void *) (time->wd_t_fmt ?: empty_wstr);
4b10dd6c
UD
785 iov[2 + cnt].iov_len = ((wcslen (iov[2 + cnt].iov_base) + 1)
786 * sizeof (uint32_t));
787 idx[1 + last_idx] = idx[last_idx] + iov[2 + cnt].iov_len;
788 ++cnt;
789 ++last_idx;
790
4a33c2f5 791 iov[2 + cnt].iov_base = (void *) (time->wd_fmt ?: empty_wstr);
4b10dd6c
UD
792 iov[2 + cnt].iov_len = ((wcslen (iov[2 + cnt].iov_base) + 1)
793 * sizeof (uint32_t));
794 idx[1 + last_idx] = idx[last_idx] + iov[2 + cnt].iov_len;
795 ++cnt;
796 ++last_idx;
797
4a33c2f5 798 iov[2 + cnt].iov_base = (void *) (time->wt_fmt ?: empty_wstr);
4b10dd6c
UD
799 iov[2 + cnt].iov_len = ((wcslen (iov[2 + cnt].iov_base) + 1)
800 * sizeof (uint32_t));
801 idx[1 + last_idx] = idx[last_idx] + iov[2 + cnt].iov_len;
802 ++cnt;
803 ++last_idx;
804
4a33c2f5 805 iov[2 + cnt].iov_base = (void *) (time->wt_fmt_ampm ?: empty_wstr);
4b10dd6c
UD
806 iov[2 + cnt].iov_len = ((wcslen (iov[2 + cnt].iov_base) + 1)
807 * sizeof (uint32_t));
808 idx[1 + last_idx] = idx[last_idx] + iov[2 + cnt].iov_len;
809 ++cnt;
810 ++last_idx;
811
4a33c2f5 812 iov[2 + cnt].iov_base = (void *) (time->wera_year ?: empty_wstr);
4b10dd6c
UD
813 iov[2 + cnt].iov_len = ((wcslen (iov[2 + cnt].iov_base) + 1)
814 * sizeof (uint32_t));
815 idx[1 + last_idx] = idx[last_idx] + iov[2 + cnt].iov_len;
816 ++cnt;
817 ++last_idx;
818
4a33c2f5 819 iov[2 + cnt].iov_base = (void *) (time->wera_d_fmt ?: empty_wstr);
4b10dd6c
UD
820 iov[2 + cnt].iov_len = ((wcslen (iov[2 + cnt].iov_base) + 1)
821 * sizeof (uint32_t));
822 idx[1 + last_idx] = idx[last_idx] + iov[2 + cnt].iov_len;
823 ++cnt;
824 ++last_idx;
825
826 idx[1 + last_idx] = idx[last_idx];
827 for (num = 0; num < 100; ++num, ++cnt)
828 {
4a33c2f5 829 iov[2 + cnt].iov_base = (void *) (time->walt_digits[num]
4b10dd6c
UD
830 ?: empty_wstr);
831 iov[2 + cnt].iov_len = ((wcslen (iov[2 + cnt].iov_base) + 1)
832 * sizeof (uint32_t));
833 idx[1 + last_idx] += iov[2 + cnt].iov_len;
834 }
835 ++last_idx;
836
4a33c2f5 837 iov[2 + cnt].iov_base = (void *) (time->wera_d_t_fmt ?: empty_wstr);
4b10dd6c
UD
838 iov[2 + cnt].iov_len = ((wcslen (iov[2 + cnt].iov_base) + 1)
839 * sizeof (uint32_t));
840 idx[1 + last_idx] = idx[last_idx] + iov[2 + cnt].iov_len;
841 ++cnt;
842 ++last_idx;
843
4a33c2f5 844 iov[2 + cnt].iov_base = (void *) (time->wera_t_fmt ?: empty_wstr);
4b10dd6c
UD
845 iov[2 + cnt].iov_len = ((wcslen (iov[2 + cnt].iov_base) + 1)
846 * sizeof (uint32_t));
847 idx[1 + last_idx] = idx[last_idx] + iov[2 + cnt].iov_len;
848 ++cnt;
849 ++last_idx;
850
851 iov[2 + cnt].iov_base = (void *) &time->week_ndays;
852 iov[2 + cnt].iov_len = 1;
853 idx[1 + last_idx] = idx[last_idx] + iov[2 + cnt].iov_len;
854 ++cnt;
855 ++last_idx;
856
a0edd63e
UD
857 /* We must align the following data. */
858 iov[2 + cnt].iov_base = (void *) "\0\0";
859 iov[2 + cnt].iov_len = ((idx[last_idx] + 3) & ~3) - idx[last_idx];
860 idx[last_idx] = (idx[last_idx] + 3) & ~3;
861 ++cnt;
862
4b10dd6c 863 iov[2 + cnt].iov_base = (void *) &time->week_1stday;
a0edd63e 864 iov[2 + cnt].iov_len = sizeof(uint32_t);
4b10dd6c
UD
865 idx[1 + last_idx] = idx[last_idx] + iov[2 + cnt].iov_len;
866 ++cnt;
867 ++last_idx;
868
869 iov[2 + cnt].iov_base = (void *) &time->week_1stweek;
870 iov[2 + cnt].iov_len = 1;
871 idx[1 + last_idx] = idx[last_idx] + iov[2 + cnt].iov_len;
872 ++cnt;
873 ++last_idx;
874
875 iov[2 + cnt].iov_base = (void *) &time->first_weekday;
876 iov[2 + cnt].iov_len = 1;
877 idx[1 + last_idx] = idx[last_idx] + iov[2 + cnt].iov_len;
878 ++cnt;
879 ++last_idx;
880
881 iov[2 + cnt].iov_base = (void *) &time->first_workday;
882 iov[2 + cnt].iov_len = 1;
883 idx[1 + last_idx] = idx[last_idx] + iov[2 + cnt].iov_len;
884 ++cnt;
885 ++last_idx;
886
887 iov[2 + cnt].iov_base = (void *) &time->cal_direction;
888 iov[2 + cnt].iov_len = 1;
889 idx[1 + last_idx] = idx[last_idx] + iov[2 + cnt].iov_len;
890 ++cnt;
891 ++last_idx;
892
893 iov[2 + cnt].iov_base = (void *) time->timezone;
894 iov[2 + cnt].iov_len = strlen (time->timezone) + 1;
d8337213
UD
895 idx[1 + last_idx] = idx[last_idx] + iov[2 + cnt].iov_len;
896 ++cnt;
897 ++last_idx;
898
899 iov[2 + cnt].iov_base = (void *) time->date_fmt;
900 iov[2 + cnt].iov_len = strlen (iov[2 + cnt].iov_base) + 1;
901 idx[1 + last_idx] = idx[last_idx] + iov[2 + cnt].iov_len;
902 ++cnt;
903 ++last_idx;
904
9a5c46e8
UD
905 /* We must align the following data. */
906 iov[2 + cnt].iov_base = (void *) "\0\0";
907 iov[2 + cnt].iov_len = -idx[last_idx] & 3;
908 idx[last_idx] += -idx[last_idx] & 3;
909 ++cnt;
910
d8337213
UD
911 iov[2 + cnt].iov_base = (void *) time->wdate_fmt;
912 iov[2 + cnt].iov_len = ((wcslen (iov[2 + cnt].iov_base) + 1)
913 * sizeof (uint32_t));
e7f21fa6
UD
914 idx[1 + last_idx] = idx[last_idx] + iov[2 + cnt].iov_len;
915 ++cnt;
916 ++last_idx;
917
918 iov[2 + cnt].iov_base = (void *) charmap->code_set_name;
919 iov[2 + cnt].iov_len = strlen (iov[2 + cnt].iov_base) + 1;
4b10dd6c
UD
920 ++cnt;
921 ++last_idx;
19bc17a9 922
c4029823 923 assert (cnt == (_NL_ITEM_INDEX (_NL_NUM_LC_TIME)
4b10dd6c 924 + time->num_era - 1
90952c77 925 + 2 * 99
9a5c46e8 926 + 2 + time->num_era * 10));
4b10dd6c 927 assert (last_idx == _NL_ITEM_INDEX (_NL_NUM_LC_TIME));
19bc17a9 928
a7b65cdc 929 write_locale_data (output_path, LC_TIME, "LC_TIME", 2 + cnt, iov);
19bc17a9
RM
930}
931
932
4b10dd6c 933/* The parser for the LC_TIME section of the locale definition. */
19bc17a9 934void
4b10dd6c 935time_read (struct linereader *ldfile, struct localedef_t *result,
47e8b443 936 const struct charmap_t *charmap, const char *repertoire_name,
4b10dd6c 937 int ignore_content)
19bc17a9 938{
4b10dd6c
UD
939 struct repertoire_t *repertoire = NULL;
940 struct locale_time_t *time;
941 struct token *now;
942 enum token_t nowtok;
943 size_t cnt;
944
945 /* Get the repertoire we have to use. */
946 if (repertoire_name != NULL)
947 repertoire = repertoire_read (repertoire_name);
948
949 /* The rest of the line containing `LC_TIME' must be free. */
950 lr_ignore_rest (ldfile, 1);
19bc17a9 951
4b10dd6c
UD
952
953 do
19bc17a9 954 {
47e8b443 955 now = lr_token (ldfile, charmap, result, repertoire, verbose);
4b10dd6c
UD
956 nowtok = now->tok;
957 }
958 while (nowtok == tok_eol);
959
960 /* If we see `copy' now we are almost done. */
961 if (nowtok == tok_copy)
962 {
01ff9d0b 963 handle_copy (ldfile, charmap, repertoire_name, result, tok_lc_time,
b9eb05d6 964 LC_TIME, "LC_TIME", ignore_content);
4b10dd6c
UD
965 return;
966 }
967
968 /* Prepare the data structures. */
969 time_startup (ldfile, result, ignore_content);
970 time = result->categories[LC_TIME].time;
971
972 while (1)
973 {
974 /* Of course we don't proceed beyond the end of file. */
975 if (nowtok == tok_eof)
976 break;
977
978 /* Ingore empty lines. */
979 if (nowtok == tok_eol)
ec4b0518 980 {
47e8b443 981 now = lr_token (ldfile, charmap, result, repertoire, verbose);
4b10dd6c
UD
982 nowtok = now->tok;
983 continue;
ec4b0518 984 }
4b10dd6c
UD
985
986 switch (nowtok)
987 {
988#define STRARR_ELEM(cat, min, max) \
989 case tok_##cat: \
b9eb05d6
UD
990 /* Ignore the rest of the line if we don't need the input of \
991 this line. */ \
992 if (ignore_content) \
993 { \
994 lr_ignore_rest (ldfile, 0); \
995 break; \
996 } \
997 \
4b10dd6c
UD
998 for (cnt = 0; cnt < max; ++cnt) \
999 { \
47e8b443 1000 now = lr_token (ldfile, charmap, result, repertoire, verbose); \
4b10dd6c
UD
1001 if (now->tok == tok_eol) \
1002 { \
1003 if (cnt < min) \
1004 lr_error (ldfile, _("%s: too few values for field `%s'"), \
1005 "LC_TIME", #cat); \
1006 if (!ignore_content) \
1007 do \
1008 { \
1009 time->cat[cnt] = ""; \
1010 time->w##cat[cnt] = empty_wstr; \
1011 } \
1012 while (++cnt < max); \
1013 break; \
1014 } \
1015 else if (now->tok != tok_string) \
1016 goto err_label; \
1017 else if (!ignore_content && (now->val.str.startmb == NULL \
1018 || now->val.str.startwc == NULL)) \
1019 { \
1020 lr_error (ldfile, _("%s: unknown character in field `%s'"), \
1021 "LC_TIME", #cat); \
1022 time->cat[cnt] = ""; \
1023 time->w##cat[cnt] = empty_wstr; \
1024 } \
1025 else if (!ignore_content) \
1026 { \
1027 time->cat[cnt] = now->val.str.startmb; \
1028 time->w##cat[cnt] = now->val.str.startwc; \
1029 } \
1030 \
1031 /* Match the semicolon. */ \
47e8b443 1032 now = lr_token (ldfile, charmap, result, repertoire, verbose); \
4b10dd6c
UD
1033 if (now->tok != tok_semicolon && now->tok != tok_eol) \
1034 break; \
1035 } \
1036 if (now->tok != tok_eol) \
1037 { \
1038 while (!ignore_content && cnt < min) \
1039 { \
1040 time->cat[cnt] = ""; \
1041 time->w##cat[cnt++] = empty_wstr; \
1042 } \
1043 \
1044 if (now->tok == tok_semicolon) \
1045 { \
47e8b443
UD
1046 now = lr_token (ldfile, charmap, result, repertoire, \
1047 verbose); \
4b10dd6c
UD
1048 if (now->tok == tok_eol) \
1049 lr_error (ldfile, _("extra trailing semicolon")); \
1050 else if (now->tok == tok_string) \
1051 { \
1052 lr_error (ldfile, _("\
1053%s: too many values for field `%s'"), \
1054 "LC_TIME", #cat); \
1055 lr_ignore_rest (ldfile, 0); \
1056 } \
1057 else \
1058 goto err_label; \
1059 } \
1060 else \
1061 goto err_label; \
1062 } \
1063 time->cat##_defined = 1; \
1064 break
1065
1066 STRARR_ELEM (abday, 7, 7);
1067 STRARR_ELEM (day, 7, 7);
1068 STRARR_ELEM (abmon, 12, 12);
1069 STRARR_ELEM (mon, 12, 12);
1070 STRARR_ELEM (am_pm, 2, 2);
1071 STRARR_ELEM (alt_digits, 0, 100);
1072
1073 case tok_era:
b9eb05d6
UD
1074 /* Ignore the rest of the line if we don't need the input of
1075 this line. */
1076 if (ignore_content)
1077 {
1078 lr_ignore_rest (ldfile, 0);
1079 break;
1080 }
4b10dd6c
UD
1081 do
1082 {
47e8b443 1083 now = lr_token (ldfile, charmap, result, repertoire, verbose);
4b10dd6c
UD
1084 if (now->tok != tok_string)
1085 goto err_label;
1086 if (!ignore_content && (now->val.str.startmb == NULL
1087 || now->val.str.startwc == NULL))
1088 {
1089 lr_error (ldfile, _("%s: unknown character in field `%s'"),
1090 "LC_TIME", "era");
1091 lr_ignore_rest (ldfile, 0);
1092 break;
1093 }
4b10dd6c
UD
1094 if (!ignore_content)
1095 {
1096 time->era = xrealloc (time->era,
1097 (time->num_era + 1) * sizeof (char *));
1098 time->era[time->num_era] = now->val.str.startmb;
1099
1100 time->wera = xrealloc (time->wera,
1101 (time->num_era + 1)
1102 * sizeof (char *));
1103 time->wera[time->num_era++] = now->val.str.startwc;
1104 }
47e8b443 1105 now = lr_token (ldfile, charmap, result, repertoire, verbose);
a9c27b3e 1106 if (now->tok != tok_eol && now->tok != tok_semicolon)
4b10dd6c
UD
1107 goto err_label;
1108 }
1109 while (now->tok == tok_semicolon);
1110 break;
1111
1112#define STR_ELEM(cat) \
1113 case tok_##cat: \
b9eb05d6
UD
1114 /* Ignore the rest of the line if we don't need the input of \
1115 this line. */ \
1116 if (ignore_content) \
1117 { \
1118 lr_ignore_rest (ldfile, 0); \
1119 break; \
1120 } \
1121 \
47e8b443 1122 now = lr_token (ldfile, charmap, result, repertoire, verbose); \
4b10dd6c
UD
1123 if (now->tok != tok_string) \
1124 goto err_label; \
1125 else if (time->cat != NULL) \
1126 lr_error (ldfile, _("\
1127%s: field `%s' declared more than once"), "LC_TIME", #cat); \
1128 else if (!ignore_content && (now->val.str.startmb == NULL \
1129 || now->val.str.startwc == NULL)) \
1130 { \
1131 lr_error (ldfile, _("%s: unknown character in field `%s'"), \
1132 "LC_TIME", #cat); \
1133 time->cat = ""; \
1134 time->w##cat = empty_wstr; \
1135 } \
1136 else if (!ignore_content) \
1137 { \
1138 time->cat = now->val.str.startmb; \
1139 time->w##cat = now->val.str.startwc; \
1140 } \
1141 break
1142
1143 STR_ELEM (d_t_fmt);
1144 STR_ELEM (d_fmt);
1145 STR_ELEM (t_fmt);
1146 STR_ELEM (t_fmt_ampm);
1147 STR_ELEM (era_year);
1148 STR_ELEM (era_d_t_fmt);
1149 STR_ELEM (era_d_fmt);
1150 STR_ELEM (era_t_fmt);
1151 STR_ELEM (timezone);
d8337213 1152 STR_ELEM (date_fmt);
4b10dd6c
UD
1153
1154#define INT_ELEM(cat) \
1155 case tok_##cat: \
b9eb05d6
UD
1156 /* Ignore the rest of the line if we don't need the input of \
1157 this line. */ \
1158 if (ignore_content) \
1159 { \
1160 lr_ignore_rest (ldfile, 0); \
1161 break; \
1162 } \
1163 \
47e8b443 1164 now = lr_token (ldfile, charmap, result, repertoire, verbose); \
4b10dd6c
UD
1165 if (now->tok != tok_number) \
1166 goto err_label; \
1167 else if (time->cat != 0) \
1168 lr_error (ldfile, _("%s: field `%s' declared more than once"), \
1169 "LC_TIME", #cat); \
1170 else if (!ignore_content) \
1171 time->cat = now->val.num; \
1172 break
1173
1174 INT_ELEM (first_weekday);
1175 INT_ELEM (first_workday);
1176 INT_ELEM (cal_direction);
1177
1178 case tok_week:
b9eb05d6
UD
1179 /* Ignore the rest of the line if we don't need the input of
1180 this line. */
1181 if (ignore_content)
1182 {
1183 lr_ignore_rest (ldfile, 0);
1184 break;
1185 }
1186
47e8b443 1187 now = lr_token (ldfile, charmap, result, repertoire, verbose);
4b10dd6c
UD
1188 if (now->tok != tok_number)
1189 goto err_label;
1190 time->week_ndays = now->val.num;
1191
47e8b443 1192 now = lr_token (ldfile, charmap, result, repertoire, verbose);
4b10dd6c
UD
1193 if (now->tok != tok_semicolon)
1194 goto err_label;
1195
47e8b443 1196 now = lr_token (ldfile, charmap, result, repertoire, verbose);
4b10dd6c
UD
1197 if (now->tok != tok_number)
1198 goto err_label;
1199 time->week_1stday = now->val.num;
1200
47e8b443 1201 now = lr_token (ldfile, charmap, result, repertoire, verbose);
4b10dd6c
UD
1202 if (now->tok != tok_semicolon)
1203 goto err_label;
1204
47e8b443 1205 now = lr_token (ldfile, charmap, result, repertoire, verbose);
4b10dd6c
UD
1206 if (now->tok != tok_number)
1207 goto err_label;
1208 time->week_1stweek = now->val.num;
1209
1210 lr_ignore_rest (ldfile, 1);
1211 break;
1212
1213 case tok_end:
1214 /* Next we assume `LC_TIME'. */
47e8b443 1215 now = lr_token (ldfile, charmap, result, repertoire, verbose);
4b10dd6c
UD
1216 if (now->tok == tok_eof)
1217 break;
1218 if (now->tok == tok_eol)
1219 lr_error (ldfile, _("%s: incomplete `END' line"), "LC_TIME");
1220 else if (now->tok != tok_lc_time)
1221 lr_error (ldfile, _("\
1222%1$s: definition does not end with `END %1$s'"), "LC_TIME");
1223 lr_ignore_rest (ldfile, now->tok == tok_lc_time);
1224 return;
1225
1226 default:
1227 err_label:
1228 SYNTAX_ERROR (_("%s: syntax error"), "LC_TIME");
1229 }
1230
1231 /* Prepare for the next round. */
47e8b443 1232 now = lr_token (ldfile, charmap, result, repertoire, verbose);
4b10dd6c 1233 nowtok = now->tok;
19bc17a9 1234 }
4b10dd6c
UD
1235
1236 /* When we come here we reached the end of the file. */
1237 lr_error (ldfile, _("%s: premature end of file"), "LC_TIME");
19bc17a9 1238}