1 /* Copyright (C) 1995-2023 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published
6 by the Free Software Foundation; version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, see <https://www.gnu.org/licenses/>. */
31 #include "localedef.h"
32 #include "linereader.h"
33 #include "localeinfo.h"
37 /* Entry describing an entry of the era specification. */
42 int32_t start_date
[3];
51 /* The real definition of the struct for the LC_TIME locale. */
55 const uint32_t *wabday
[7];
58 const uint32_t *wday
[7];
60 const char *abmon
[12];
61 const uint32_t *wabmon
[12];
64 const uint32_t *wmon
[12];
67 const uint32_t *wam_pm
[2];
70 const uint32_t *wd_t_fmt
;
72 const uint32_t *wd_fmt
;
74 const uint32_t *wt_fmt
;
75 const char *t_fmt_ampm
;
76 const uint32_t *wt_fmt_ampm
;
78 const uint32_t **wera
;
81 const uint32_t *wera_year
;
82 const char *era_d_t_fmt
;
83 const uint32_t *wera_d_t_fmt
;
84 const char *era_t_fmt
;
85 const uint32_t *wera_t_fmt
;
86 const char *era_d_fmt
;
87 const uint32_t *wera_d_fmt
;
88 const char *alt_digits
[100];
89 const uint32_t *walt_digits
[100];
91 const uint32_t *wdate_fmt
;
92 int alt_digits_defined
;
93 const char *alt_mon
[12];
94 const uint32_t *walt_mon
[12];
96 const char *ab_alt_mon
[12];
97 const uint32_t *wab_alt_mon
[12];
98 int ab_alt_mon_defined
;
99 unsigned char week_ndays
;
100 uint32_t week_1stday
;
101 unsigned char week_1stweek
;
102 unsigned char first_weekday
;
103 unsigned char first_workday
;
104 unsigned char cal_direction
;
105 const char *timezone
;
106 const uint32_t *wtimezone
;
108 struct era_data
*era_entries
;
112 /* This constant is used to represent an empty wide character string. */
113 static const uint32_t empty_wstr
[1] = { 0 };
117 time_startup (struct linereader
*lr
, struct localedef_t
*locale
,
121 locale
->categories
[LC_TIME
].time
=
122 (struct locale_time_t
*) xcalloc (1, sizeof (struct locale_time_t
));
126 lr
->translate_strings
= 1;
127 lr
->return_widestr
= 1;
133 time_finish (struct localedef_t
*locale
, const struct charmap_t
*charmap
)
135 struct locale_time_t
*time
= locale
->categories
[LC_TIME
].time
;
138 /* Now resolve copying and also handle completely missing definitions. */
141 /* First see whether we were supposed to copy. If yes, find the
142 actual definition. */
143 if (locale
->copy_name
[LC_TIME
] != NULL
)
145 /* Find the copying locale. This has to happen transitively since
146 the locale we are copying from might also copying another one. */
147 struct localedef_t
*from
= locale
;
150 from
= find_locale (LC_TIME
, from
->copy_name
[LC_TIME
],
151 from
->repertoire_name
, charmap
);
152 while (from
->categories
[LC_TIME
].time
== NULL
153 && from
->copy_name
[LC_TIME
] != NULL
);
155 time
= locale
->categories
[LC_TIME
].time
156 = from
->categories
[LC_TIME
].time
;
159 /* If there is still no definition issue an warning and create an
164 No definition for %s category found"), "LC_TIME");
165 time_startup (NULL
, locale
, 0);
166 time
= locale
->categories
[LC_TIME
].time
;
171 #define noparen(arg1, argn...) arg1, ##argn
172 #define TESTARR_ELEM(cat, val) \
173 if (!time->cat##_defined) \
175 const char *initval[] = { noparen val }; \
179 record_error (0, 0, _("%s: field `%s' not defined"), \
182 for (i = 0; i < sizeof (initval) / sizeof (initval[0]); ++i) \
183 time->cat[i] = initval[i]; \
186 TESTARR_ELEM (abday
, ( "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" ));
187 TESTARR_ELEM (day
, ( "Sunday", "Monday", "Tuesday", "Wednesday",
188 "Thursday", "Friday", "Saturday" ));
189 TESTARR_ELEM (abmon
, ( "Jan", "Feb", "Mar", "Apr", "May", "Jun",
190 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" ));
191 TESTARR_ELEM (mon
, ( "January", "February", "March", "April",
192 "May", "June", "July", "August",
193 "September", "October", "November", "December" ));
194 TESTARR_ELEM (am_pm
, ( "AM", "PM" ));
196 #define TEST_ELEM(cat, initval) \
197 if (time->cat == NULL) \
200 record_error (0, 0, _("%s: field `%s' not defined"), \
203 time->cat = initval; \
206 TEST_ELEM (d_t_fmt
, "%a %b %e %H:%M:%S %Y");
207 TEST_ELEM (d_fmt
, "%m/%d/%y");
208 TEST_ELEM (t_fmt
, "%H:%M:%S");
210 /* According to C.Y.Alexis Cheng <alexis@vnet.ibm.com> the T_FMT_AMPM
211 field is optional. */
212 if (time
->t_fmt_ampm
== NULL
)
214 if (time
->am_pm
[0][0] == '\0' && time
->am_pm
[1][0] == '\0')
216 /* No AM/PM strings defined, use the 24h format as default. */
217 time
->t_fmt_ampm
= time
->t_fmt
;
218 time
->wt_fmt_ampm
= time
->wt_fmt
;
222 time
->t_fmt_ampm
= "%I:%M:%S %p";
223 time
->wt_fmt_ampm
= (const uint32_t *) L
"%I:%M:%S %p";
227 /* Now process the era entries. */
228 if (time
->num_era
!= 0)
230 const int days_per_month
[12] = { 31, 29, 31, 30, 31, 30,
231 31, 31, 30, 31 ,30, 31 };
236 (struct era_data
*) xmalloc (time
->num_era
237 * sizeof (struct era_data
));
239 for (idx
= 0; idx
< time
->num_era
; ++idx
)
241 size_t era_len
= strlen (time
->era
[idx
]);
242 char *str
= xmalloc ((era_len
+ 1 + 3) & ~3);
245 memcpy (str
, time
->era
[idx
], era_len
+ 1);
247 /* First character must be + or - for the direction. */
248 if (*str
!= '+' && *str
!= '-')
250 record_error (0, 0, _("\
251 %s: direction flag in string %Zd in `era' field is not '+' nor '-'"),
253 /* Default arbitrarily to '+'. */
254 time
->era_entries
[idx
].direction
= '+';
257 time
->era_entries
[idx
].direction
= *str
;
260 record_error (0, 0, _("\
261 %s: direction flag in string %Zd in `era' field is not a single character"),
263 (void) strsep (&str
, ":");
268 /* Now the offset year. */
269 time
->era_entries
[idx
].offset
= strtol (str
, &endp
, 10);
272 record_error (0, 0, _("\
273 %s: invalid number for offset in string %Zd in `era' field"),
275 (void) strsep (&str
, ":");
277 else if (*endp
!= ':')
279 record_error (0, 0, _("\
280 %s: garbage at end of offset value in string %Zd in `era' field"),
282 (void) strsep (&str
, ":");
287 /* Next is the starting date in ISO format. */
288 if (strncmp (str
, "-*", 2) == 0)
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;
294 goto garbage_start_date
;
297 else if (strncmp (str
, "+*", 2) == 0)
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;
303 goto garbage_start_date
;
308 time
->era_entries
[idx
].start_date
[0] = strtol (str
, &endp
, 10);
309 if (endp
== str
|| *endp
!= '/')
310 goto invalid_start_date
;
313 time
->era_entries
[idx
].start_date
[0] -= 1900;
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];
318 time
->era_entries
[idx
].start_date
[1] = strtol (str
, &endp
, 10);
319 if (endp
== str
|| *endp
!= '/')
320 goto invalid_start_date
;
323 time
->era_entries
[idx
].start_date
[1] -= 1;
325 time
->era_entries
[idx
].start_date
[2] = strtol (str
, &endp
, 10);
329 record_error (0, 0, _("\
330 %s: invalid starting date in string %Zd in `era' field"),
332 (void) strsep (&str
, ":");
334 else if (*endp
!= ':')
337 record_error (0, 0, _("\
338 %s: garbage at end of starting date in string %Zd in `era' field "),
340 (void) strsep (&str
, ":");
346 /* Check for valid value. */
347 if ((time
->era_entries
[idx
].start_date
[1] < 0
348 || time
->era_entries
[idx
].start_date
[1] >= 12
349 || time
->era_entries
[idx
].start_date
[2] < 0
350 || (time
->era_entries
[idx
].start_date
[2]
351 > days_per_month
[time
->era_entries
[idx
].start_date
[1]])
352 || (time
->era_entries
[idx
].start_date
[1] == 2
353 && time
->era_entries
[idx
].start_date
[2] == 29
354 && !__isleap (time
->era_entries
[idx
].start_date
[0]))))
355 record_error (0, 0, _("\
356 %s: starting date is invalid in string %Zd in `era' field"),
361 /* Next is the stopping date in ISO format. */
362 if (strncmp (str
, "-*", 2) == 0)
364 time
->era_entries
[idx
].stop_date
[0] =
365 time
->era_entries
[idx
].stop_date
[1] =
366 time
->era_entries
[idx
].stop_date
[2] = 0x80000000;
368 goto garbage_stop_date
;
371 else if (strncmp (str
, "+*", 2) == 0)
373 time
->era_entries
[idx
].stop_date
[0] =
374 time
->era_entries
[idx
].stop_date
[1] =
375 time
->era_entries
[idx
].stop_date
[2] = 0x7fffffff;
377 goto garbage_stop_date
;
382 time
->era_entries
[idx
].stop_date
[0] = strtol (str
, &endp
, 10);
383 if (endp
== str
|| *endp
!= '/')
384 goto invalid_stop_date
;
387 time
->era_entries
[idx
].stop_date
[0] -= 1900;
388 /* year -1 represent 1 B.C. (not -1 A.D.) */
389 if (time
->era_entries
[idx
].stop_date
[0] < -1900)
390 ++time
->era_entries
[idx
].stop_date
[0];
392 time
->era_entries
[idx
].stop_date
[1] = strtol (str
, &endp
, 10);
393 if (endp
== str
|| *endp
!= '/')
394 goto invalid_stop_date
;
397 time
->era_entries
[idx
].stop_date
[1] -= 1;
399 time
->era_entries
[idx
].stop_date
[2] = strtol (str
, &endp
, 10);
403 record_error (0, 0, _("\
404 %s: invalid stopping date in string %Zd in `era' field"),
406 (void) strsep (&str
, ":");
408 else if (*endp
!= ':')
411 record_error (0, 0, _("\
412 %s: garbage at end of stopping date in string %Zd in `era' field"),
414 (void) strsep (&str
, ":");
420 /* Check for valid value. */
421 if ((time
->era_entries
[idx
].stop_date
[1] < 0
422 || time
->era_entries
[idx
].stop_date
[1] >= 12
423 || time
->era_entries
[idx
].stop_date
[2] < 0
424 || (time
->era_entries
[idx
].stop_date
[2]
425 > days_per_month
[time
->era_entries
[idx
].stop_date
[1]])
426 || (time
->era_entries
[idx
].stop_date
[1] == 2
427 && time
->era_entries
[idx
].stop_date
[2] == 29
428 && !__isleap (time
->era_entries
[idx
].stop_date
[0]))))
429 record_error (0, 0, _("\
430 %s: invalid stopping date in string %Zd in `era' field"),
435 if (str
== NULL
|| *str
== '\0')
437 record_error (0, 0, _("\
438 %s: missing era name in string %Zd in `era' field"), "LC_TIME", idx
+ 1);
439 time
->era_entries
[idx
].name
=
440 time
->era_entries
[idx
].format
= "";
444 time
->era_entries
[idx
].name
= strsep (&str
, ":");
446 if (str
== NULL
|| *str
== '\0')
448 record_error (0, 0, _("\
449 %s: missing era format in string %Zd in `era' field"),
451 time
->era_entries
[idx
].name
=
452 time
->era_entries
[idx
].format
= "";
455 time
->era_entries
[idx
].format
= str
;
458 /* Now generate the wide character name and format. */
459 wstr
= wcschr ((wchar_t *) time
->wera
[idx
], L
':');/* end direction */
460 wstr
= wstr
? wcschr (wstr
+ 1, L
':') : NULL
; /* end offset */
461 wstr
= wstr
? wcschr (wstr
+ 1, L
':') : NULL
; /* end start */
462 wstr
= wstr
? wcschr (wstr
+ 1, L
':') : NULL
; /* end end */
465 time
->era_entries
[idx
].wname
= (uint32_t *) wstr
+ 1;
466 wstr
= wcschr (wstr
+ 1, L
':'); /* end name */
470 time
->era_entries
[idx
].wformat
= (uint32_t *) wstr
+ 1;
473 time
->era_entries
[idx
].wname
=
474 time
->era_entries
[idx
].wformat
= (uint32_t *) L
"";
477 time
->era_entries
[idx
].wname
=
478 time
->era_entries
[idx
].wformat
= (uint32_t *) L
"";
482 /* Set up defaults based on ISO 30112 WD10 [2014]. */
483 if (time
->week_ndays
== 0)
484 time
->week_ndays
= 7;
486 if (time
->week_1stday
== 0)
487 time
->week_1stday
= 19971130;
489 if (time
->week_1stweek
== 0)
490 time
->week_1stweek
= 7;
492 if (time
->week_1stweek
> time
->week_ndays
)
493 record_error (0, 0, _("\
494 %s: third operand for value of field `%s' must not be larger than %d"),
495 "LC_TIME", "week", 7);
497 if (time
->first_weekday
== '\0')
498 /* The definition does not specify this so the default is used. */
499 time
->first_weekday
= 1;
500 else if (time
->first_weekday
> time
->week_ndays
)
501 record_error (0, 0, _("\
502 %s: values for field `%s' must not be larger than %d"),
503 "LC_TIME", "first_weekday", 7);
505 if (time
->first_workday
== '\0')
506 /* The definition does not specify this so the default is used. */
507 time
->first_workday
= 2;
508 else if (time
->first_workday
> time
->week_ndays
)
509 record_error (0, 0, _("\
510 %s: values for field `%s' must not be larger than %d"),
511 "LC_TIME", "first_workday", 7);
513 if (time
->cal_direction
== '\0')
514 /* The definition does not specify this so the default is used. */
515 time
->cal_direction
= 1;
516 else if (time
->cal_direction
> 3)
517 record_error (0, 0, _("\
518 %s: values for field `%s' must not be larger than %d"),
519 "LC_TIME", "cal_direction", 3);
521 /* XXX We don't perform any tests on the timezone value since this is
522 simply useless, stupid $&$!@... */
523 if (time
->timezone
== NULL
)
526 if (time
->date_fmt
== NULL
)
527 time
->date_fmt
= "%a %b %e %H:%M:%S %Z %Y";
528 if (time
->wdate_fmt
== NULL
)
529 time
->wdate_fmt
= (const uint32_t *) L
"%a %b %e %H:%M:%S %Z %Y";
534 time_output (struct localedef_t
*locale
, const struct charmap_t
*charmap
,
535 const char *output_path
)
537 struct locale_time_t
*time
= locale
->categories
[LC_TIME
].time
;
538 struct locale_file file
;
541 init_locale_data (&file
, _NL_ITEM_INDEX (_NL_NUM_LC_TIME
));
544 for (n
= 0; n
< 7; ++n
)
545 add_locale_string (&file
, time
->abday
[n
] ?: "");
548 for (n
= 0; n
< 7; ++n
)
549 add_locale_string (&file
, time
->day
[n
] ?: "");
552 for (n
= 0; n
< 12; ++n
)
553 add_locale_string (&file
, time
->abmon
[n
] ?: "");
556 for (n
= 0; n
< 12; ++n
)
557 add_locale_string (&file
, time
->mon
[n
] ?: "");
560 for (n
= 0; n
< 2; ++n
)
561 add_locale_string (&file
, time
->am_pm
[n
]);
563 add_locale_string (&file
, time
->d_t_fmt
?: "");
564 add_locale_string (&file
, time
->d_fmt
?: "");
565 add_locale_string (&file
, time
->t_fmt
?: "");
566 add_locale_string (&file
, time
->t_fmt_ampm
?: "");
568 start_locale_structure (&file
);
569 for (num
= 0; num
< time
->num_era
; ++num
)
570 add_locale_string (&file
, time
->era
[num
]);
571 end_locale_structure (&file
);
573 add_locale_string (&file
, time
->era_year
?: "");
574 add_locale_string (&file
, time
->era_d_fmt
?: "");
576 start_locale_structure (&file
);
577 for (num
= 0; num
< 100; ++num
)
578 add_locale_string (&file
, time
->alt_digits
[num
] ?: "");
579 end_locale_structure (&file
);
581 add_locale_string (&file
, time
->era_d_t_fmt
?: "");
582 add_locale_string (&file
, time
->era_t_fmt
?: "");
583 add_locale_uint32 (&file
, time
->num_era
);
585 start_locale_structure (&file
);
586 for (num
= 0; num
< time
->num_era
; ++num
)
588 add_locale_uint32 (&file
, time
->era_entries
[num
].direction
);
589 add_locale_uint32 (&file
, time
->era_entries
[num
].offset
);
590 add_locale_uint32 (&file
, time
->era_entries
[num
].start_date
[0]);
591 add_locale_uint32 (&file
, time
->era_entries
[num
].start_date
[1]);
592 add_locale_uint32 (&file
, time
->era_entries
[num
].start_date
[2]);
593 add_locale_uint32 (&file
, time
->era_entries
[num
].stop_date
[0]);
594 add_locale_uint32 (&file
, time
->era_entries
[num
].stop_date
[1]);
595 add_locale_uint32 (&file
, time
->era_entries
[num
].stop_date
[2]);
596 add_locale_string (&file
, time
->era_entries
[num
].name
);
597 add_locale_string (&file
, time
->era_entries
[num
].format
);
598 add_locale_wstring (&file
, time
->era_entries
[num
].wname
);
599 add_locale_wstring (&file
, time
->era_entries
[num
].wformat
);
601 end_locale_structure (&file
);
603 /* The wide character ab'days. */
604 for (n
= 0; n
< 7; ++n
)
605 add_locale_wstring (&file
, time
->wabday
[n
] ?: empty_wstr
);
607 /* The wide character days. */
608 for (n
= 0; n
< 7; ++n
)
609 add_locale_wstring (&file
, time
->wday
[n
] ?: empty_wstr
);
611 /* The wide character ab'mons. */
612 for (n
= 0; n
< 12; ++n
)
613 add_locale_wstring (&file
, time
->wabmon
[n
] ?: empty_wstr
);
615 /* The wide character mons. */
616 for (n
= 0; n
< 12; ++n
)
617 add_locale_wstring (&file
, time
->wmon
[n
] ?: empty_wstr
);
619 /* Wide character AM/PM. */
620 for (n
= 0; n
< 2; ++n
)
621 add_locale_wstring (&file
, time
->wam_pm
[n
] ?: empty_wstr
);
623 add_locale_wstring (&file
, time
->wd_t_fmt
?: empty_wstr
);
624 add_locale_wstring (&file
, time
->wd_fmt
?: empty_wstr
);
625 add_locale_wstring (&file
, time
->wt_fmt
?: empty_wstr
);
626 add_locale_wstring (&file
, time
->wt_fmt_ampm
?: empty_wstr
);
627 add_locale_wstring (&file
, time
->wera_year
?: empty_wstr
);
628 add_locale_wstring (&file
, time
->wera_d_fmt
?: empty_wstr
);
630 start_locale_structure (&file
);
631 for (num
= 0; num
< 100; ++num
)
632 add_locale_wstring (&file
, time
->walt_digits
[num
] ?: empty_wstr
);
633 end_locale_structure (&file
);
635 add_locale_wstring (&file
, time
->wera_d_t_fmt
?: empty_wstr
);
636 add_locale_wstring (&file
, time
->wera_t_fmt
?: empty_wstr
);
637 add_locale_char (&file
, time
->week_ndays
);
638 add_locale_uint32 (&file
, time
->week_1stday
);
639 add_locale_char (&file
, time
->week_1stweek
);
640 add_locale_char (&file
, time
->first_weekday
);
641 add_locale_char (&file
, time
->first_workday
);
642 add_locale_char (&file
, time
->cal_direction
);
643 add_locale_string (&file
, time
->timezone
);
644 add_locale_string (&file
, time
->date_fmt
);
645 add_locale_wstring (&file
, time
->wdate_fmt
);
646 add_locale_string (&file
, charmap
->code_set_name
);
649 for (n
= 0; n
< 12; ++n
)
650 add_locale_string (&file
, time
->alt_mon
[n
] ?: "");
652 /* The wide character alt'mons. */
653 for (n
= 0; n
< 12; ++n
)
654 add_locale_wstring (&file
, time
->walt_mon
[n
] ?: empty_wstr
);
656 /* The ab'alt'mons. */
657 for (n
= 0; n
< 12; ++n
)
658 add_locale_string (&file
, time
->ab_alt_mon
[n
] ?: "");
660 /* The wide character ab'alt'mons. */
661 for (n
= 0; n
< 12; ++n
)
662 add_locale_wstring (&file
, time
->wab_alt_mon
[n
] ?: empty_wstr
);
664 write_locale_data (output_path
, LC_TIME
, "LC_TIME", &file
);
668 /* The parser for the LC_TIME section of the locale definition. */
670 time_read (struct linereader
*ldfile
, struct localedef_t
*result
,
671 const struct charmap_t
*charmap
, const char *repertoire_name
,
674 struct repertoire_t
*repertoire
= NULL
;
675 struct locale_time_t
*time
;
680 /* Get the repertoire we have to use. */
681 if (repertoire_name
!= NULL
)
682 repertoire
= repertoire_read (repertoire_name
);
684 /* The rest of the line containing `LC_TIME' must be free. */
685 lr_ignore_rest (ldfile
, 1);
690 now
= lr_token (ldfile
, charmap
, result
, repertoire
, verbose
);
693 while (nowtok
== tok_eol
);
695 /* If we see `copy' now we are almost done. */
696 if (nowtok
== tok_copy
)
698 handle_copy (ldfile
, charmap
, repertoire_name
, result
, tok_lc_time
,
699 LC_TIME
, "LC_TIME", ignore_content
);
703 /* Prepare the data structures. */
704 time_startup (ldfile
, result
, ignore_content
);
705 time
= result
->categories
[LC_TIME
].time
;
709 /* Of course we don't proceed beyond the end of file. */
710 if (nowtok
== tok_eof
)
713 /* Ingore empty lines. */
714 if (nowtok
== tok_eol
)
716 now
= lr_token (ldfile
, charmap
, result
, repertoire
, verbose
);
723 #define STRARR_ELEM(cat, min, max) \
725 /* Ignore the rest of the line if we don't need the input of \
727 if (ignore_content) \
729 lr_ignore_rest (ldfile, 0); \
733 for (cnt = 0; cnt < max; ++cnt) \
735 now = lr_token (ldfile, charmap, result, repertoire, verbose); \
736 if (now->tok == tok_eol) \
739 lr_error (ldfile, _("%s: too few values for field `%s'"), \
741 if (!ignore_content) \
744 time->cat[cnt] = ""; \
745 time->w##cat[cnt] = empty_wstr; \
747 while (++cnt < max); \
750 else if (now->tok != tok_string) \
752 else if (!ignore_content && (now->val.str.startmb == NULL \
753 || now->val.str.startwc == NULL)) \
755 lr_error (ldfile, _("%s: unknown character in field `%s'"), \
757 time->cat[cnt] = ""; \
758 time->w##cat[cnt] = empty_wstr; \
760 else if (!ignore_content) \
762 time->cat[cnt] = now->val.str.startmb; \
763 time->w##cat[cnt] = now->val.str.startwc; \
766 /* Match the semicolon. */ \
767 now = lr_token (ldfile, charmap, result, repertoire, verbose); \
768 if (now->tok != tok_semicolon && now->tok != tok_eol) \
771 if (now->tok != tok_eol) \
773 while (!ignore_content && cnt < min) \
775 time->cat[cnt] = ""; \
776 time->w##cat[cnt++] = empty_wstr; \
779 if (now->tok == tok_semicolon) \
781 now = lr_token (ldfile, charmap, result, repertoire, \
783 if (now->tok == tok_eol) \
784 lr_error (ldfile, _("extra trailing semicolon")); \
785 else if (now->tok == tok_string) \
787 lr_error (ldfile, _("\
788 %s: too many values for field `%s'"), \
790 lr_ignore_rest (ldfile, 0); \
798 time->cat##_defined = 1; \
801 STRARR_ELEM (abday
, 7, 7);
802 STRARR_ELEM (day
, 7, 7);
803 STRARR_ELEM (abmon
, 12, 12);
804 STRARR_ELEM (mon
, 12, 12);
805 STRARR_ELEM (am_pm
, 2, 2);
806 STRARR_ELEM (alt_digits
, 0, 100);
807 STRARR_ELEM (alt_mon
, 12, 12);
808 STRARR_ELEM (ab_alt_mon
, 12, 12);
811 /* Ignore the rest of the line if we don't need the input of
815 lr_ignore_rest (ldfile
, 0);
820 now
= lr_token (ldfile
, charmap
, result
, repertoire
, verbose
);
821 if (now
->tok
!= tok_string
)
823 if (!ignore_content
&& (now
->val
.str
.startmb
== NULL
824 || now
->val
.str
.startwc
== NULL
))
826 lr_error (ldfile
, _("%s: unknown character in field `%s'"),
828 lr_ignore_rest (ldfile
, 0);
833 time
->era
= xrealloc (time
->era
,
834 (time
->num_era
+ 1) * sizeof (char *));
835 time
->era
[time
->num_era
] = now
->val
.str
.startmb
;
837 time
->wera
= xrealloc (time
->wera
,
840 time
->wera
[time
->num_era
++] = now
->val
.str
.startwc
;
842 now
= lr_token (ldfile
, charmap
, result
, repertoire
, verbose
);
843 if (now
->tok
!= tok_eol
&& now
->tok
!= tok_semicolon
)
846 while (now
->tok
== tok_semicolon
);
849 #define STR_ELEM(cat) \
851 /* Ignore the rest of the line if we don't need the input of \
853 if (ignore_content) \
855 lr_ignore_rest (ldfile, 0); \
859 now = lr_token (ldfile, charmap, result, repertoire, verbose); \
860 if (now->tok != tok_string) \
862 else if (time->cat != NULL) \
863 lr_error (ldfile, _("\
864 %s: field `%s' declared more than once"), "LC_TIME", #cat); \
865 else if (!ignore_content && (now->val.str.startmb == NULL \
866 || now->val.str.startwc == NULL)) \
868 lr_error (ldfile, _("%s: unknown character in field `%s'"), \
871 time->w##cat = empty_wstr; \
873 else if (!ignore_content) \
875 time->cat = now->val.str.startmb; \
876 time->w##cat = now->val.str.startwc; \
883 STR_ELEM (t_fmt_ampm
);
885 STR_ELEM (era_d_t_fmt
);
886 STR_ELEM (era_d_fmt
);
887 STR_ELEM (era_t_fmt
);
891 #define INT_ELEM(cat) \
893 /* Ignore the rest of the line if we don't need the input of \
895 if (ignore_content) \
897 lr_ignore_rest (ldfile, 0); \
901 now = lr_token (ldfile, charmap, result, repertoire, verbose); \
902 if (now->tok != tok_number) \
904 else if (time->cat != 0) \
905 lr_error (ldfile, _("%s: field `%s' declared more than once"), \
907 else if (!ignore_content) \
908 time->cat = now->val.num; \
911 INT_ELEM (first_weekday
);
912 INT_ELEM (first_workday
);
913 INT_ELEM (cal_direction
);
916 /* Ignore the rest of the line if we don't need the input of
920 lr_ignore_rest (ldfile
, 0);
924 now
= lr_token (ldfile
, charmap
, result
, repertoire
, verbose
);
925 if (now
->tok
!= tok_number
)
927 time
->week_ndays
= now
->val
.num
;
929 now
= lr_token (ldfile
, charmap
, result
, repertoire
, verbose
);
930 if (now
->tok
!= tok_semicolon
)
933 now
= lr_token (ldfile
, charmap
, result
, repertoire
, verbose
);
934 if (now
->tok
!= tok_number
)
936 time
->week_1stday
= now
->val
.num
;
938 now
= lr_token (ldfile
, charmap
, result
, repertoire
, verbose
);
939 if (now
->tok
!= tok_semicolon
)
942 now
= lr_token (ldfile
, charmap
, result
, repertoire
, verbose
);
943 if (now
->tok
!= tok_number
)
945 time
->week_1stweek
= now
->val
.num
;
947 lr_ignore_rest (ldfile
, 1);
951 /* Next we assume `LC_TIME'. */
952 now
= lr_token (ldfile
, charmap
, result
, repertoire
, verbose
);
953 if (now
->tok
== tok_eof
)
955 if (now
->tok
== tok_eol
)
956 lr_error (ldfile
, _("%s: incomplete `END' line"), "LC_TIME");
957 else if (now
->tok
!= tok_lc_time
)
958 lr_error (ldfile
, _("\
959 %1$s: definition does not end with `END %1$s'"), "LC_TIME");
960 lr_ignore_rest (ldfile
, now
->tok
== tok_lc_time
);
962 /* If alt_mon was not specified, make it a copy of mon. */
963 if (!ignore_content
&& !time
->alt_mon_defined
)
965 memcpy (time
->alt_mon
, time
->mon
, sizeof (time
->mon
));
966 memcpy (time
->walt_mon
, time
->wmon
, sizeof (time
->wmon
));
967 time
->alt_mon_defined
= 1;
969 /* The same for abbreviated versions. */
970 if (!ignore_content
&& !time
->ab_alt_mon_defined
)
972 memcpy (time
->ab_alt_mon
, time
->abmon
, sizeof (time
->abmon
));
973 memcpy (time
->wab_alt_mon
, time
->wabmon
, sizeof (time
->wabmon
));
974 time
->ab_alt_mon_defined
= 1;
980 SYNTAX_ERROR (_("%s: syntax error"), "LC_TIME");
983 /* Prepare for the next round. */
984 now
= lr_token (ldfile
, charmap
, result
, repertoire
, verbose
);
988 /* When we come here we reached the end of the file. */
989 lr_error (ldfile
, _("%s: premature end of file"), "LC_TIME");