]>
git.ipfire.org Git - thirdparty/glibc.git/blob - locale/programs/ld-time.c
1 /* Copyright (C) 1995-2018 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Ulrich Drepper <drepper@gnu.org>, 1995.
5 This program is free software; you can redistribute it and/or modify
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.
10 This program 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
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, see <http://www.gnu.org/licenses/>. */
32 #include "localedef.h"
33 #include "linereader.h"
34 #include "localeinfo.h"
38 /* Entry describing an entry of the era specification. */
43 int32_t start_date
[3];
52 /* The real definition of the struct for the LC_TIME locale. */
56 const uint32_t *wabday
[7];
59 const uint32_t *wday
[7];
61 const char *abmon
[12];
62 const uint32_t *wabmon
[12];
65 const uint32_t *wmon
[12];
68 const uint32_t *wam_pm
[2];
71 const uint32_t *wd_t_fmt
;
73 const uint32_t *wd_fmt
;
75 const uint32_t *wt_fmt
;
76 const char *t_fmt_ampm
;
77 const uint32_t *wt_fmt_ampm
;
79 const uint32_t **wera
;
82 const uint32_t *wera_year
;
83 const char *era_d_t_fmt
;
84 const uint32_t *wera_d_t_fmt
;
85 const char *era_t_fmt
;
86 const uint32_t *wera_t_fmt
;
87 const char *era_d_fmt
;
88 const uint32_t *wera_d_fmt
;
89 const char *alt_digits
[100];
90 const uint32_t *walt_digits
[100];
92 const uint32_t *wdate_fmt
;
93 int alt_digits_defined
;
94 unsigned char week_ndays
;
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
;
103 struct era_data
*era_entries
;
107 /* This constant is used to represent an empty wide character string. */
108 static const uint32_t empty_wstr
[1] = { 0 };
112 time_startup (struct linereader
*lr
, struct localedef_t
*locale
,
116 locale
->categories
[LC_TIME
].time
=
117 (struct locale_time_t
*) xcalloc (1, sizeof (struct locale_time_t
));
121 lr
->translate_strings
= 1;
122 lr
->return_widestr
= 1;
128 time_finish (struct localedef_t
*locale
, const struct charmap_t
*charmap
)
130 struct locale_time_t
*time
= locale
->categories
[LC_TIME
].time
;
133 /* Now resolve copying and also handle completely missing definitions. */
136 /* First see whether we were supposed to copy. If yes, find the
137 actual definition. */
138 if (locale
->copy_name
[LC_TIME
] != NULL
)
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
;
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
);
150 time
= locale
->categories
[LC_TIME
].time
151 = from
->categories
[LC_TIME
].time
;
154 /* If there is still no definition issue an warning and create an
159 No definition for %s category found"), "LC_TIME");
160 time_startup (NULL
, locale
, 0);
161 time
= locale
->categories
[LC_TIME
].time
;
166 #define noparen(arg1, argn...) arg1, ##argn
167 #define TESTARR_ELEM(cat, val) \
168 if (!time->cat##_defined) \
170 const char *initval[] = { noparen val }; \
174 record_error (0, 0, _("%s: field `%s' not defined"), \
177 for (i = 0; i < sizeof (initval) / sizeof (initval[0]); ++i) \
178 time->cat[i] = initval[i]; \
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" ));
191 #define TEST_ELEM(cat, initval) \
192 if (time->cat == NULL) \
195 record_error (0, 0, _("%s: field `%s' not defined"), \
198 time->cat = initval; \
201 TEST_ELEM (d_t_fmt
, "%a %b %e %H:%M:%S %Y");
202 TEST_ELEM (d_fmt
, "%m/%d/%y");
203 TEST_ELEM (t_fmt
, "%H:%M:%S");
205 /* According to C.Y.Alexis Cheng <alexis@vnet.ibm.com> the T_FMT_AMPM
206 field is optional. */
207 if (time
->t_fmt_ampm
== NULL
)
209 if (time
->am_pm
[0][0] == '\0' && time
->am_pm
[1][0] == '\0')
211 /* No AM/PM strings defined, use the 24h format as default. */
212 time
->t_fmt_ampm
= time
->t_fmt
;
213 time
->wt_fmt_ampm
= time
->wt_fmt
;
217 time
->t_fmt_ampm
= "%I:%M:%S %p";
218 time
->wt_fmt_ampm
= (const uint32_t *) L
"%I:%M:%S %p";
222 /* Now process the era entries. */
223 if (time
->num_era
!= 0)
225 const int days_per_month
[12] = { 31, 29, 31, 30, 31, 30,
226 31, 31, 30, 31 ,30, 31 };
231 (struct era_data
*) xmalloc (time
->num_era
232 * sizeof (struct era_data
));
234 for (idx
= 0; idx
< time
->num_era
; ++idx
)
236 size_t era_len
= strlen (time
->era
[idx
]);
237 char *str
= xmalloc ((era_len
+ 1 + 3) & ~3);
240 memcpy (str
, time
->era
[idx
], era_len
+ 1);
242 /* First character must be + or - for the direction. */
243 if (*str
!= '+' && *str
!= '-')
245 record_error (0, 0, _("\
246 %s: direction flag in string %Zd in `era' field is not '+' nor '-'"),
248 /* Default arbitrarily to '+'. */
249 time
->era_entries
[idx
].direction
= '+';
252 time
->era_entries
[idx
].direction
= *str
;
255 record_error (0, 0, _("\
256 %s: direction flag in string %Zd in `era' field is not a single character"),
258 (void) strsep (&str
, ":");
263 /* Now the offset year. */
264 time
->era_entries
[idx
].offset
= strtol (str
, &endp
, 10);
267 record_error (0, 0, _("\
268 %s: invalid number for offset in string %Zd in `era' field"),
270 (void) strsep (&str
, ":");
272 else if (*endp
!= ':')
274 record_error (0, 0, _("\
275 %s: garbage at end of offset value in string %Zd in `era' field"),
277 (void) strsep (&str
, ":");
282 /* Next is the starting date in ISO format. */
283 if (strncmp (str
, "-*", 2) == 0)
285 time
->era_entries
[idx
].start_date
[0] =
286 time
->era_entries
[idx
].start_date
[1] =
287 time
->era_entries
[idx
].start_date
[2] = 0x80000000;
289 goto garbage_start_date
;
292 else if (strncmp (str
, "+*", 2) == 0)
294 time
->era_entries
[idx
].start_date
[0] =
295 time
->era_entries
[idx
].start_date
[1] =
296 time
->era_entries
[idx
].start_date
[2] = 0x7fffffff;
298 goto garbage_start_date
;
303 time
->era_entries
[idx
].start_date
[0] = strtol (str
, &endp
, 10);
304 if (endp
== str
|| *endp
!= '/')
305 goto invalid_start_date
;
308 time
->era_entries
[idx
].start_date
[0] -= 1900;
309 /* year -1 represent 1 B.C. (not -1 A.D.) */
310 if (time
->era_entries
[idx
].start_date
[0] < -1900)
311 ++time
->era_entries
[idx
].start_date
[0];
313 time
->era_entries
[idx
].start_date
[1] = strtol (str
, &endp
, 10);
314 if (endp
== str
|| *endp
!= '/')
315 goto invalid_start_date
;
318 time
->era_entries
[idx
].start_date
[1] -= 1;
320 time
->era_entries
[idx
].start_date
[2] = strtol (str
, &endp
, 10);
324 record_error (0, 0, _("\
325 %s: invalid starting date in string %Zd in `era' field"),
327 (void) strsep (&str
, ":");
329 else if (*endp
!= ':')
332 record_error (0, 0, _("\
333 %s: garbage at end of starting date in string %Zd in `era' field "),
335 (void) strsep (&str
, ":");
341 /* Check for valid value. */
342 if ((time
->era_entries
[idx
].start_date
[1] < 0
343 || time
->era_entries
[idx
].start_date
[1] >= 12
344 || time
->era_entries
[idx
].start_date
[2] < 0
345 || (time
->era_entries
[idx
].start_date
[2]
346 > days_per_month
[time
->era_entries
[idx
].start_date
[1]])
347 || (time
->era_entries
[idx
].start_date
[1] == 2
348 && time
->era_entries
[idx
].start_date
[2] == 29
349 && !__isleap (time
->era_entries
[idx
].start_date
[0]))))
350 record_error (0, 0, _("\
351 %s: starting date is invalid in string %Zd in `era' field"),
356 /* Next is the stopping date in ISO format. */
357 if (strncmp (str
, "-*", 2) == 0)
359 time
->era_entries
[idx
].stop_date
[0] =
360 time
->era_entries
[idx
].stop_date
[1] =
361 time
->era_entries
[idx
].stop_date
[2] = 0x80000000;
363 goto garbage_stop_date
;
366 else if (strncmp (str
, "+*", 2) == 0)
368 time
->era_entries
[idx
].stop_date
[0] =
369 time
->era_entries
[idx
].stop_date
[1] =
370 time
->era_entries
[idx
].stop_date
[2] = 0x7fffffff;
372 goto garbage_stop_date
;
377 time
->era_entries
[idx
].stop_date
[0] = strtol (str
, &endp
, 10);
378 if (endp
== str
|| *endp
!= '/')
379 goto invalid_stop_date
;
382 time
->era_entries
[idx
].stop_date
[0] -= 1900;
383 /* year -1 represent 1 B.C. (not -1 A.D.) */
384 if (time
->era_entries
[idx
].stop_date
[0] < -1900)
385 ++time
->era_entries
[idx
].stop_date
[0];
387 time
->era_entries
[idx
].stop_date
[1] = strtol (str
, &endp
, 10);
388 if (endp
== str
|| *endp
!= '/')
389 goto invalid_stop_date
;
392 time
->era_entries
[idx
].stop_date
[1] -= 1;
394 time
->era_entries
[idx
].stop_date
[2] = strtol (str
, &endp
, 10);
398 record_error (0, 0, _("\
399 %s: invalid stopping date in string %Zd in `era' field"),
401 (void) strsep (&str
, ":");
403 else if (*endp
!= ':')
406 record_error (0, 0, _("\
407 %s: garbage at end of stopping date in string %Zd in `era' field"),
409 (void) strsep (&str
, ":");
415 /* Check for valid value. */
416 if ((time
->era_entries
[idx
].stop_date
[1] < 0
417 || time
->era_entries
[idx
].stop_date
[1] >= 12
418 || time
->era_entries
[idx
].stop_date
[2] < 0
419 || (time
->era_entries
[idx
].stop_date
[2]
420 > days_per_month
[time
->era_entries
[idx
].stop_date
[1]])
421 || (time
->era_entries
[idx
].stop_date
[1] == 2
422 && time
->era_entries
[idx
].stop_date
[2] == 29
423 && !__isleap (time
->era_entries
[idx
].stop_date
[0]))))
424 record_error (0, 0, _("\
425 %s: invalid stopping date in string %Zd in `era' field"),
430 if (str
== NULL
|| *str
== '\0')
432 record_error (0, 0, _("\
433 %s: missing era name in string %Zd in `era' field"), "LC_TIME", idx
+ 1);
434 time
->era_entries
[idx
].name
=
435 time
->era_entries
[idx
].format
= "";
439 time
->era_entries
[idx
].name
= strsep (&str
, ":");
441 if (str
== NULL
|| *str
== '\0')
443 record_error (0, 0, _("\
444 %s: missing era format in string %Zd in `era' field"),
446 time
->era_entries
[idx
].name
=
447 time
->era_entries
[idx
].format
= "";
450 time
->era_entries
[idx
].format
= str
;
453 /* Now generate the wide character name and format. */
454 wstr
= wcschr ((wchar_t *) time
->wera
[idx
], L
':');/* end direction */
455 wstr
= wstr
? wcschr (wstr
+ 1, L
':') : NULL
; /* end offset */
456 wstr
= wstr
? wcschr (wstr
+ 1, L
':') : NULL
; /* end start */
457 wstr
= wstr
? wcschr (wstr
+ 1, L
':') : NULL
; /* end end */
460 time
->era_entries
[idx
].wname
= (uint32_t *) wstr
+ 1;
461 wstr
= wcschr (wstr
+ 1, L
':'); /* end name */
465 time
->era_entries
[idx
].wformat
= (uint32_t *) wstr
+ 1;
468 time
->era_entries
[idx
].wname
=
469 time
->era_entries
[idx
].wformat
= (uint32_t *) L
"";
472 time
->era_entries
[idx
].wname
=
473 time
->era_entries
[idx
].wformat
= (uint32_t *) L
"";
477 /* Set up defaults based on ISO 30112 WD10 [2014]. */
478 if (time
->week_ndays
== 0)
479 time
->week_ndays
= 7;
481 if (time
->week_1stday
== 0)
482 time
->week_1stday
= 19971130;
484 if (time
->week_1stweek
== 0)
485 time
->week_1stweek
= 7;
487 if (time
->week_1stweek
> time
->week_ndays
)
488 record_error (0, 0, _("\
489 %s: third operand for value of field `%s' must not be larger than %d"),
490 "LC_TIME", "week", 7);
492 if (time
->first_weekday
== '\0')
493 /* The definition does not specify this so the default is used. */
494 time
->first_weekday
= 1;
495 else if (time
->first_weekday
> time
->week_ndays
)
496 record_error (0, 0, _("\
497 %s: values for field `%s' must not be larger than %d"),
498 "LC_TIME", "first_weekday", 7);
500 if (time
->first_workday
== '\0')
501 /* The definition does not specify this so the default is used. */
502 time
->first_workday
= 2;
503 else if (time
->first_workday
> time
->week_ndays
)
504 record_error (0, 0, _("\
505 %s: values for field `%s' must not be larger than %d"),
506 "LC_TIME", "first_workday", 7);
508 if (time
->cal_direction
== '\0')
509 /* The definition does not specify this so the default is used. */
510 time
->cal_direction
= 1;
511 else if (time
->cal_direction
> 3)
512 record_error (0, 0, _("\
513 %s: values for field `%s' must not be larger than %d"),
514 "LC_TIME", "cal_direction", 3);
516 /* XXX We don't perform any tests on the timezone value since this is
517 simply useless, stupid $&$!@... */
518 if (time
->timezone
== NULL
)
521 if (time
->date_fmt
== NULL
)
522 time
->date_fmt
= "%a %b %e %H:%M:%S %Z %Y";
523 if (time
->wdate_fmt
== NULL
)
524 time
->wdate_fmt
= (const uint32_t *) L
"%a %b %e %H:%M:%S %Z %Y";
529 time_output (struct localedef_t
*locale
, const struct charmap_t
*charmap
,
530 const char *output_path
)
532 struct locale_time_t
*time
= locale
->categories
[LC_TIME
].time
;
533 struct locale_file file
;
536 init_locale_data (&file
, _NL_ITEM_INDEX (_NL_NUM_LC_TIME
));
539 for (n
= 0; n
< 7; ++n
)
540 add_locale_string (&file
, time
->abday
[n
] ?: "");
543 for (n
= 0; n
< 7; ++n
)
544 add_locale_string (&file
, time
->day
[n
] ?: "");
547 for (n
= 0; n
< 12; ++n
)
548 add_locale_string (&file
, time
->abmon
[n
] ?: "");
551 for (n
= 0; n
< 12; ++n
)
552 add_locale_string (&file
, time
->mon
[n
] ?: "");
555 for (n
= 0; n
< 2; ++n
)
556 add_locale_string (&file
, time
->am_pm
[n
]);
558 add_locale_string (&file
, time
->d_t_fmt
?: "");
559 add_locale_string (&file
, time
->d_fmt
?: "");
560 add_locale_string (&file
, time
->t_fmt
?: "");
561 add_locale_string (&file
, time
->t_fmt_ampm
?: "");
563 start_locale_structure (&file
);
564 for (num
= 0; num
< time
->num_era
; ++num
)
565 add_locale_string (&file
, time
->era
[num
]);
566 end_locale_structure (&file
);
568 add_locale_string (&file
, time
->era_year
?: "");
569 add_locale_string (&file
, time
->era_d_fmt
?: "");
571 start_locale_structure (&file
);
572 for (num
= 0; num
< 100; ++num
)
573 add_locale_string (&file
, time
->alt_digits
[num
] ?: "");
574 end_locale_structure (&file
);
576 add_locale_string (&file
, time
->era_d_t_fmt
?: "");
577 add_locale_string (&file
, time
->era_t_fmt
?: "");
578 add_locale_uint32 (&file
, time
->num_era
);
580 start_locale_structure (&file
);
581 for (num
= 0; num
< time
->num_era
; ++num
)
583 add_locale_uint32 (&file
, time
->era_entries
[num
].direction
);
584 add_locale_uint32 (&file
, time
->era_entries
[num
].offset
);
585 add_locale_uint32 (&file
, time
->era_entries
[num
].start_date
[0]);
586 add_locale_uint32 (&file
, time
->era_entries
[num
].start_date
[1]);
587 add_locale_uint32 (&file
, time
->era_entries
[num
].start_date
[2]);
588 add_locale_uint32 (&file
, time
->era_entries
[num
].stop_date
[0]);
589 add_locale_uint32 (&file
, time
->era_entries
[num
].stop_date
[1]);
590 add_locale_uint32 (&file
, time
->era_entries
[num
].stop_date
[2]);
591 add_locale_string (&file
, time
->era_entries
[num
].name
);
592 add_locale_string (&file
, time
->era_entries
[num
].format
);
593 add_locale_wstring (&file
, time
->era_entries
[num
].wname
);
594 add_locale_wstring (&file
, time
->era_entries
[num
].wformat
);
596 end_locale_structure (&file
);
598 /* The wide character ab'days. */
599 for (n
= 0; n
< 7; ++n
)
600 add_locale_wstring (&file
, time
->wabday
[n
] ?: empty_wstr
);
602 /* The wide character days. */
603 for (n
= 0; n
< 7; ++n
)
604 add_locale_wstring (&file
, time
->wday
[n
] ?: empty_wstr
);
606 /* The wide character ab'mons. */
607 for (n
= 0; n
< 12; ++n
)
608 add_locale_wstring (&file
, time
->wabmon
[n
] ?: empty_wstr
);
610 /* The wide character mons. */
611 for (n
= 0; n
< 12; ++n
)
612 add_locale_wstring (&file
, time
->wmon
[n
] ?: empty_wstr
);
614 /* Wide character AM/PM. */
615 for (n
= 0; n
< 2; ++n
)
616 add_locale_wstring (&file
, time
->wam_pm
[n
] ?: empty_wstr
);
618 add_locale_wstring (&file
, time
->wd_t_fmt
?: empty_wstr
);
619 add_locale_wstring (&file
, time
->wd_fmt
?: empty_wstr
);
620 add_locale_wstring (&file
, time
->wt_fmt
?: empty_wstr
);
621 add_locale_wstring (&file
, time
->wt_fmt_ampm
?: empty_wstr
);
622 add_locale_wstring (&file
, time
->wera_year
?: empty_wstr
);
623 add_locale_wstring (&file
, time
->wera_d_fmt
?: empty_wstr
);
625 start_locale_structure (&file
);
626 for (num
= 0; num
< 100; ++num
)
627 add_locale_wstring (&file
, time
->walt_digits
[num
] ?: empty_wstr
);
628 end_locale_structure (&file
);
630 add_locale_wstring (&file
, time
->wera_d_t_fmt
?: empty_wstr
);
631 add_locale_wstring (&file
, time
->wera_t_fmt
?: empty_wstr
);
632 add_locale_char (&file
, time
->week_ndays
);
633 add_locale_uint32 (&file
, time
->week_1stday
);
634 add_locale_char (&file
, time
->week_1stweek
);
635 add_locale_char (&file
, time
->first_weekday
);
636 add_locale_char (&file
, time
->first_workday
);
637 add_locale_char (&file
, time
->cal_direction
);
638 add_locale_string (&file
, time
->timezone
);
639 add_locale_string (&file
, time
->date_fmt
);
640 add_locale_wstring (&file
, time
->wdate_fmt
);
641 add_locale_string (&file
, charmap
->code_set_name
);
642 write_locale_data (output_path
, LC_TIME
, "LC_TIME", &file
);
646 /* The parser for the LC_TIME section of the locale definition. */
648 time_read (struct linereader
*ldfile
, struct localedef_t
*result
,
649 const struct charmap_t
*charmap
, const char *repertoire_name
,
652 struct repertoire_t
*repertoire
= NULL
;
653 struct locale_time_t
*time
;
658 /* Get the repertoire we have to use. */
659 if (repertoire_name
!= NULL
)
660 repertoire
= repertoire_read (repertoire_name
);
662 /* The rest of the line containing `LC_TIME' must be free. */
663 lr_ignore_rest (ldfile
, 1);
668 now
= lr_token (ldfile
, charmap
, result
, repertoire
, verbose
);
671 while (nowtok
== tok_eol
);
673 /* If we see `copy' now we are almost done. */
674 if (nowtok
== tok_copy
)
676 handle_copy (ldfile
, charmap
, repertoire_name
, result
, tok_lc_time
,
677 LC_TIME
, "LC_TIME", ignore_content
);
681 /* Prepare the data structures. */
682 time_startup (ldfile
, result
, ignore_content
);
683 time
= result
->categories
[LC_TIME
].time
;
687 /* Of course we don't proceed beyond the end of file. */
688 if (nowtok
== tok_eof
)
691 /* Ingore empty lines. */
692 if (nowtok
== tok_eol
)
694 now
= lr_token (ldfile
, charmap
, result
, repertoire
, verbose
);
701 #define STRARR_ELEM(cat, min, max) \
703 /* Ignore the rest of the line if we don't need the input of \
705 if (ignore_content) \
707 lr_ignore_rest (ldfile, 0); \
711 for (cnt = 0; cnt < max; ++cnt) \
713 now = lr_token (ldfile, charmap, result, repertoire, verbose); \
714 if (now->tok == tok_eol) \
717 lr_error (ldfile, _("%s: too few values for field `%s'"), \
719 if (!ignore_content) \
722 time->cat[cnt] = ""; \
723 time->w##cat[cnt] = empty_wstr; \
725 while (++cnt < max); \
728 else if (now->tok != tok_string) \
730 else if (!ignore_content && (now->val.str.startmb == NULL \
731 || now->val.str.startwc == NULL)) \
733 lr_error (ldfile, _("%s: unknown character in field `%s'"), \
735 time->cat[cnt] = ""; \
736 time->w##cat[cnt] = empty_wstr; \
738 else if (!ignore_content) \
740 time->cat[cnt] = now->val.str.startmb; \
741 time->w##cat[cnt] = now->val.str.startwc; \
744 /* Match the semicolon. */ \
745 now = lr_token (ldfile, charmap, result, repertoire, verbose); \
746 if (now->tok != tok_semicolon && now->tok != tok_eol) \
749 if (now->tok != tok_eol) \
751 while (!ignore_content && cnt < min) \
753 time->cat[cnt] = ""; \
754 time->w##cat[cnt++] = empty_wstr; \
757 if (now->tok == tok_semicolon) \
759 now = lr_token (ldfile, charmap, result, repertoire, \
761 if (now->tok == tok_eol) \
762 lr_error (ldfile, _("extra trailing semicolon")); \
763 else if (now->tok == tok_string) \
765 lr_error (ldfile, _("\
766 %s: too many values for field `%s'"), \
768 lr_ignore_rest (ldfile, 0); \
776 time->cat##_defined = 1; \
779 STRARR_ELEM (abday
, 7, 7);
780 STRARR_ELEM (day
, 7, 7);
781 STRARR_ELEM (abmon
, 12, 12);
782 STRARR_ELEM (mon
, 12, 12);
783 STRARR_ELEM (am_pm
, 2, 2);
784 STRARR_ELEM (alt_digits
, 0, 100);
787 /* Ignore the rest of the line if we don't need the input of
791 lr_ignore_rest (ldfile
, 0);
796 now
= lr_token (ldfile
, charmap
, result
, repertoire
, verbose
);
797 if (now
->tok
!= tok_string
)
799 if (!ignore_content
&& (now
->val
.str
.startmb
== NULL
800 || now
->val
.str
.startwc
== NULL
))
802 lr_error (ldfile
, _("%s: unknown character in field `%s'"),
804 lr_ignore_rest (ldfile
, 0);
809 time
->era
= xrealloc (time
->era
,
810 (time
->num_era
+ 1) * sizeof (char *));
811 time
->era
[time
->num_era
] = now
->val
.str
.startmb
;
813 time
->wera
= xrealloc (time
->wera
,
816 time
->wera
[time
->num_era
++] = now
->val
.str
.startwc
;
818 now
= lr_token (ldfile
, charmap
, result
, repertoire
, verbose
);
819 if (now
->tok
!= tok_eol
&& now
->tok
!= tok_semicolon
)
822 while (now
->tok
== tok_semicolon
);
825 #define STR_ELEM(cat) \
827 /* Ignore the rest of the line if we don't need the input of \
829 if (ignore_content) \
831 lr_ignore_rest (ldfile, 0); \
835 now = lr_token (ldfile, charmap, result, repertoire, verbose); \
836 if (now->tok != tok_string) \
838 else if (time->cat != NULL) \
839 lr_error (ldfile, _("\
840 %s: field `%s' declared more than once"), "LC_TIME", #cat); \
841 else if (!ignore_content && (now->val.str.startmb == NULL \
842 || now->val.str.startwc == NULL)) \
844 lr_error (ldfile, _("%s: unknown character in field `%s'"), \
847 time->w##cat = empty_wstr; \
849 else if (!ignore_content) \
851 time->cat = now->val.str.startmb; \
852 time->w##cat = now->val.str.startwc; \
859 STR_ELEM (t_fmt_ampm
);
861 STR_ELEM (era_d_t_fmt
);
862 STR_ELEM (era_d_fmt
);
863 STR_ELEM (era_t_fmt
);
867 #define INT_ELEM(cat) \
869 /* Ignore the rest of the line if we don't need the input of \
871 if (ignore_content) \
873 lr_ignore_rest (ldfile, 0); \
877 now = lr_token (ldfile, charmap, result, repertoire, verbose); \
878 if (now->tok != tok_number) \
880 else if (time->cat != 0) \
881 lr_error (ldfile, _("%s: field `%s' declared more than once"), \
883 else if (!ignore_content) \
884 time->cat = now->val.num; \
887 INT_ELEM (first_weekday
);
888 INT_ELEM (first_workday
);
889 INT_ELEM (cal_direction
);
892 /* Ignore the rest of the line if we don't need the input of
896 lr_ignore_rest (ldfile
, 0);
900 now
= lr_token (ldfile
, charmap
, result
, repertoire
, verbose
);
901 if (now
->tok
!= tok_number
)
903 time
->week_ndays
= now
->val
.num
;
905 now
= lr_token (ldfile
, charmap
, result
, repertoire
, verbose
);
906 if (now
->tok
!= tok_semicolon
)
909 now
= lr_token (ldfile
, charmap
, result
, repertoire
, verbose
);
910 if (now
->tok
!= tok_number
)
912 time
->week_1stday
= now
->val
.num
;
914 now
= lr_token (ldfile
, charmap
, result
, repertoire
, verbose
);
915 if (now
->tok
!= tok_semicolon
)
918 now
= lr_token (ldfile
, charmap
, result
, repertoire
, verbose
);
919 if (now
->tok
!= tok_number
)
921 time
->week_1stweek
= now
->val
.num
;
923 lr_ignore_rest (ldfile
, 1);
927 /* Next we assume `LC_TIME'. */
928 now
= lr_token (ldfile
, charmap
, result
, repertoire
, verbose
);
929 if (now
->tok
== tok_eof
)
931 if (now
->tok
== tok_eol
)
932 lr_error (ldfile
, _("%s: incomplete `END' line"), "LC_TIME");
933 else if (now
->tok
!= tok_lc_time
)
934 lr_error (ldfile
, _("\
935 %1$s: definition does not end with `END %1$s'"), "LC_TIME");
936 lr_ignore_rest (ldfile
, now
->tok
== tok_lc_time
);
941 SYNTAX_ERROR (_("%s: syntax error"), "LC_TIME");
944 /* Prepare for the next round. */
945 now
= lr_token (ldfile
, charmap
, result
, repertoire
, verbose
);
949 /* When we come here we reached the end of the file. */
950 lr_error (ldfile
, _("%s: premature end of file"), "LC_TIME");