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