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