1 /* Copyright (C) 1995-2002, 2003, 2004 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Ulrich Drepper <drepper@gnu.org>, 1995.
5 The GNU C Library is free software; you can redistribute it and/or
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.
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
13 Lesser General Public License for more details.
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
33 #include "localedef.h"
34 #include "linereader.h"
35 #include "localeinfo.h"
39 /* Entry describing an entry of the era specification. */
44 int32_t start_date
[3];
53 /* The real definition of the struct for the LC_TIME locale. */
57 const uint32_t *wabday
[7];
60 const uint32_t *wday
[7];
62 const char *abmon
[12];
63 const uint32_t *wabmon
[12];
66 const uint32_t *wmon
[12];
69 const uint32_t *wam_pm
[2];
72 const uint32_t *wd_t_fmt
;
74 const uint32_t *wd_fmt
;
76 const uint32_t *wt_fmt
;
77 const char *t_fmt_ampm
;
78 const uint32_t *wt_fmt_ampm
;
80 const uint32_t **wera
;
83 const uint32_t *wera_year
;
84 const char *era_d_t_fmt
;
85 const uint32_t *wera_d_t_fmt
;
86 const char *era_t_fmt
;
87 const uint32_t *wera_t_fmt
;
88 const char *era_d_fmt
;
89 const uint32_t *wera_d_fmt
;
90 const char *alt_digits
[100];
91 const uint32_t *walt_digits
[100];
93 const uint32_t *wdate_fmt
;
94 int alt_digits_defined
;
95 unsigned char week_ndays
;
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
;
104 struct era_data
*era_entries
;
108 /* This constant is used to represent an empty wide character string. */
109 static const uint32_t empty_wstr
[1] = { 0 };
113 time_startup (struct linereader
*lr
, struct localedef_t
*locale
,
117 locale
->categories
[LC_TIME
].time
=
118 (struct locale_time_t
*) xcalloc (1, sizeof (struct locale_time_t
));
122 lr
->translate_strings
= 1;
123 lr
->return_widestr
= 1;
129 time_finish (struct localedef_t
*locale
, const struct charmap_t
*charmap
)
131 struct locale_time_t
*time
= locale
->categories
[LC_TIME
].time
;
134 /* Now resolve copying and also handle completely missing definitions. */
137 /* First see whether we were supposed to copy. If yes, find the
138 actual definition. */
139 if (locale
->copy_name
[LC_TIME
] != NULL
)
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
;
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
);
151 time
= locale
->categories
[LC_TIME
].time
152 = from
->categories
[LC_TIME
].time
;
155 /* If there is still no definition issue an warning and create an
160 WITH_CUR_LOCALE (error (0, 0, _("\
161 No definition for %s category found"), "LC_TIME"));
162 time_startup (NULL
, locale
, 0);
163 time
= locale
->categories
[LC_TIME
].time
;
168 #define noparen(arg1, argn...) arg1, ##argn
169 #define TESTARR_ELEM(cat, val) \
170 if (!time->cat##_defined) \
172 const char *initval[] = { noparen val }; \
175 if (! be_quiet && ! nothing) \
176 WITH_CUR_LOCALE (error (0, 0, _("%s: field `%s' not defined"), \
179 for (i = 0; i < sizeof (initval) / sizeof (initval[0]); ++i) \
180 time->cat[i] = initval[i]; \
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" ));
193 #define TEST_ELEM(cat, initval) \
194 if (time->cat == NULL) \
196 if (! be_quiet && ! nothing) \
197 WITH_CUR_LOCALE (error (0, 0, _("%s: field `%s' not defined"), \
200 time->cat = initval; \
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");
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
)
211 if (time
->am_pm
[0][0] == '\0' && time
->am_pm
[1][0] == '\0')
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
;
219 time
->t_fmt_ampm
= "%I:%M:%S %p";
220 time
->wt_fmt_ampm
= (const uint32_t *) L
"%I:%M:%S %p";
224 /* Now process the era entries. */
225 if (time
->num_era
!= 0)
227 const int days_per_month
[12] = { 31, 29, 31, 30, 31, 30,
228 31, 31, 30, 31 ,30, 31 };
233 (struct era_data
*) xmalloc (time
->num_era
234 * sizeof (struct era_data
));
236 for (idx
= 0; idx
< time
->num_era
; ++idx
)
238 size_t era_len
= strlen (time
->era
[idx
]);
239 char *str
= xmalloc ((era_len
+ 1 + 3) & ~3);
242 memcpy (str
, time
->era
[idx
], era_len
+ 1);
244 /* First character must be + or - for the direction. */
245 if (*str
!= '+' && *str
!= '-')
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));
251 /* Default arbitrarily to '+'. */
252 time
->era_entries
[idx
].direction
= '+';
255 time
->era_entries
[idx
].direction
= *str
;
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));
262 (void) strsep (&str
, ":");
267 /* Now the offset year. */
268 time
->era_entries
[idx
].offset
= strtol (str
, &endp
, 10);
272 WITH_CUR_LOCALE (error (0, 0, _("\
273 %s: invalid number for offset in string %Zd in `era' field"),
274 "LC_TIME", idx
+ 1));
275 (void) strsep (&str
, ":");
277 else if (*endp
!= ':')
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));
283 (void) strsep (&str
, ":");
288 /* Next is the starting date in ISO format. */
289 if (strncmp (str
, "-*", 2) == 0)
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;
295 goto garbage_start_date
;
298 else if (strncmp (str
, "+*", 2) == 0)
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;
304 goto garbage_start_date
;
309 time
->era_entries
[idx
].start_date
[0] = strtol (str
, &endp
, 10);
310 if (endp
== str
|| *endp
!= '/')
311 goto invalid_start_date
;
314 time
->era_entries
[idx
].start_date
[0] -= 1900;
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];
319 time
->era_entries
[idx
].start_date
[1] = strtol (str
, &endp
, 10);
320 if (endp
== str
|| *endp
!= '/')
321 goto invalid_start_date
;
324 time
->era_entries
[idx
].start_date
[1] -= 1;
326 time
->era_entries
[idx
].start_date
[2] = strtol (str
, &endp
, 10);
331 WITH_CUR_LOCALE (error (0, 0, _("\
332 %s: invalid starting date in string %Zd in `era' field"),
333 "LC_TIME", idx
+ 1));
334 (void) strsep (&str
, ":");
336 else if (*endp
!= ':')
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));
343 (void) strsep (&str
, ":");
349 /* Check for valid value. */
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])))
359 WITH_CUR_LOCALE (error (0, 0, _("\
360 %s: starting date is invalid in string %Zd in `era' field"),
361 "LC_TIME", idx
+ 1));
365 /* Next is the stopping date in ISO format. */
366 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] = 0x80000000;
372 goto garbage_stop_date
;
375 else if (strncmp (str
, "+*", 2) == 0)
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;
381 goto garbage_stop_date
;
386 time
->era_entries
[idx
].stop_date
[0] = strtol (str
, &endp
, 10);
387 if (endp
== str
|| *endp
!= '/')
388 goto invalid_stop_date
;
391 time
->era_entries
[idx
].stop_date
[0] -= 1900;
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];
396 time
->era_entries
[idx
].stop_date
[1] = strtol (str
, &endp
, 10);
397 if (endp
== str
|| *endp
!= '/')
398 goto invalid_stop_date
;
401 time
->era_entries
[idx
].stop_date
[1] -= 1;
403 time
->era_entries
[idx
].stop_date
[2] = strtol (str
, &endp
, 10);
408 WITH_CUR_LOCALE (error (0, 0, _("\
409 %s: invalid stopping date in string %Zd in `era' field"),
410 "LC_TIME", idx
+ 1));
411 (void) strsep (&str
, ":");
413 else if (*endp
!= ':')
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));
420 (void) strsep (&str
, ":");
426 /* Check for valid value. */
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])))
436 WITH_CUR_LOCALE (error (0, 0, _("\
437 %s: stopping date is invalid in string %Zd in `era' field"),
438 "LC_TIME", idx
+ 1));
442 if (str
== NULL
|| *str
== '\0')
445 WITH_CUR_LOCALE (error (0, 0, _("\
446 %s: missing era name in string %Zd in `era' field"), "LC_TIME", idx
+ 1));
447 time
->era_entries
[idx
].name
=
448 time
->era_entries
[idx
].format
= "";
452 time
->era_entries
[idx
].name
= strsep (&str
, ":");
454 if (str
== NULL
|| *str
== '\0')
457 WITH_CUR_LOCALE (error (0, 0, _("\
458 %s: missing era format in string %Zd in `era' field"),
459 "LC_TIME", idx
+ 1));
460 time
->era_entries
[idx
].name
=
461 time
->era_entries
[idx
].format
= "";
464 time
->era_entries
[idx
].format
= str
;
467 /* Now generate the wide character name and format. */
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 */
472 time
->era_entries
[idx
].wname
= (uint32_t *) wstr
+ 1;
473 wstr
= wstr
? wcschr (wstr
+ 1, L
':') : NULL
; /* end name */
475 time
->era_entries
[idx
].wformat
= (uint32_t *) wstr
+ 1;
479 if (time
->week_ndays
== 0)
480 time
->week_ndays
= 7;
482 if (time
->week_1stday
== 0)
483 time
->week_1stday
= 19971130;
485 if (time
->week_1stweek
> time
->week_ndays
)
486 WITH_CUR_LOCALE (error (0, 0, _("\
487 %s: third operand for value of field `%s' must not be larger than %d"),
488 "LC_TIME", "week", 7));
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
)
494 WITH_CUR_LOCALE (error (0, 0, _("\
495 %s: values of field `%s' must not be larger than %d"),
496 "LC_TIME", "first_weekday", 7));
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
)
502 WITH_CUR_LOCALE (error (0, 0, _("\
503 %s: values of field `%s' must not be larger than %d"),
504 "LC_TIME", "first_workday", 7));
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)
510 WITH_CUR_LOCALE (error (0, 0, _("\
511 %s: values for field `%s' must not be larger than %d"),
512 "LC_TIME", "cal_direction", 3));
514 /* XXX We don't perform any tests on the timezone value since this is
515 simply useless, stupid $&$!@... */
516 if (time
->timezone
== NULL
)
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";
527 time_output (struct localedef_t
*locale
, const struct charmap_t
*charmap
,
528 const char *output_path
)
530 struct locale_time_t
*time
= locale
->categories
[LC_TIME
].time
;
531 struct iovec
*iov
= alloca (sizeof *iov
532 * (2 + _NL_ITEM_INDEX (_NL_NUM_LC_TIME
)
535 + 2 + time
->num_era
* 10 - 1));
536 struct locale_file data
;
537 uint32_t idx
[_NL_ITEM_INDEX (_NL_NUM_LC_TIME
)];
538 size_t cnt
, last_idx
, num
, n
;
540 data
.magic
= LIMAGIC (LC_TIME
);
541 data
.n
= _NL_ITEM_INDEX (_NL_NUM_LC_TIME
);
542 iov
[0].iov_base
= (void *) &data
;
543 iov
[0].iov_len
= sizeof (data
);
545 iov
[1].iov_base
= (void *) idx
;
546 iov
[1].iov_len
= sizeof (idx
);
548 idx
[0] = iov
[0].iov_len
+ iov
[1].iov_len
;
551 for (cnt
= 0; cnt
<= _NL_ITEM_INDEX (ABDAY_7
); ++cnt
)
553 iov
[2 + cnt
].iov_base
=
554 (void *) (time
->abday
[cnt
- _NL_ITEM_INDEX (ABDAY_1
)] ?: "");
555 iov
[2 + cnt
].iov_len
= strlen (iov
[2 + cnt
].iov_base
) + 1;
556 idx
[1 + cnt
] = idx
[cnt
] + iov
[2 + cnt
].iov_len
;
560 for (; cnt
<= _NL_ITEM_INDEX (DAY_7
); ++cnt
)
562 iov
[2 + cnt
].iov_base
=
563 (void *) (time
->day
[cnt
- _NL_ITEM_INDEX (DAY_1
)] ?: "");
564 iov
[2 + cnt
].iov_len
= strlen (iov
[2 + cnt
].iov_base
) + 1;
565 idx
[1 + cnt
] = idx
[cnt
] + iov
[2 + cnt
].iov_len
;
569 for (; cnt
<= _NL_ITEM_INDEX (ABMON_12
); ++cnt
)
571 iov
[2 + cnt
].iov_base
=
572 (void *) (time
->abmon
[cnt
- _NL_ITEM_INDEX (ABMON_1
)] ?: "");
573 iov
[2 + cnt
].iov_len
= strlen (iov
[2 + cnt
].iov_base
) + 1;
574 idx
[1 + cnt
] = idx
[cnt
] + iov
[2 + cnt
].iov_len
;
578 for (; cnt
<= _NL_ITEM_INDEX (MON_12
); ++cnt
)
580 iov
[2 + cnt
].iov_base
=
581 (void *) (time
->mon
[cnt
- _NL_ITEM_INDEX (MON_1
)] ?: "");
582 iov
[2 + cnt
].iov_len
= strlen (iov
[2 + cnt
].iov_base
) + 1;
583 idx
[1 + cnt
] = idx
[cnt
] + iov
[2 + cnt
].iov_len
;
587 for (; cnt
<= _NL_ITEM_INDEX (PM_STR
); ++cnt
)
589 iov
[2 + cnt
].iov_base
=
590 (void *) (time
->am_pm
[cnt
- _NL_ITEM_INDEX (AM_STR
)] ?: "");
591 iov
[2 + cnt
].iov_len
= strlen (iov
[2 + cnt
].iov_base
) + 1;
592 idx
[1 + cnt
] = idx
[cnt
] + iov
[2 + cnt
].iov_len
;
595 iov
[2 + cnt
].iov_base
= (void *) (time
->d_t_fmt
?: "");
596 iov
[2 + cnt
].iov_len
= strlen (iov
[2 + cnt
].iov_base
) + 1;
597 idx
[1 + cnt
] = idx
[cnt
] + iov
[2 + cnt
].iov_len
;
600 iov
[2 + cnt
].iov_base
= (void *) (time
->d_fmt
?: "");
601 iov
[2 + cnt
].iov_len
= strlen (iov
[2 + cnt
].iov_base
) + 1;
602 idx
[1 + cnt
] = idx
[cnt
] + iov
[2 + cnt
].iov_len
;
605 iov
[2 + cnt
].iov_base
= (void *) (time
->t_fmt
?: "");
606 iov
[2 + cnt
].iov_len
= strlen (iov
[2 + cnt
].iov_base
) + 1;
607 idx
[1 + cnt
] = idx
[cnt
] + iov
[2 + cnt
].iov_len
;
610 iov
[2 + cnt
].iov_base
= (void *) (time
->t_fmt_ampm
?: "");
611 iov
[2 + cnt
].iov_len
= strlen (iov
[2 + cnt
].iov_base
) + 1;
612 idx
[1 + cnt
] = idx
[cnt
] + iov
[2 + cnt
].iov_len
;
615 idx
[1 + last_idx
] = idx
[last_idx
];
616 for (num
= 0; num
< time
->num_era
; ++num
, ++cnt
)
618 iov
[2 + cnt
].iov_base
= (void *) time
->era
[num
];
619 iov
[2 + cnt
].iov_len
= strlen (iov
[2 + cnt
].iov_base
) + 1;
620 idx
[1 + last_idx
] += iov
[2 + cnt
].iov_len
;
624 iov
[2 + cnt
].iov_base
= (void *) (time
->era_year
?: "");
625 iov
[2 + cnt
].iov_len
= strlen (iov
[2 + cnt
].iov_base
) + 1;
626 idx
[1 + last_idx
] = idx
[last_idx
] + iov
[2 + cnt
].iov_len
;
630 iov
[2 + cnt
].iov_base
= (void *) (time
->era_d_fmt
?: "");
631 iov
[2 + cnt
].iov_len
= strlen (iov
[2 + cnt
].iov_base
) + 1;
632 idx
[1 + last_idx
] = idx
[last_idx
] + iov
[2 + cnt
].iov_len
;
636 idx
[1 + last_idx
] = idx
[last_idx
];
637 for (num
= 0; num
< 100; ++num
, ++cnt
)
639 iov
[2 + cnt
].iov_base
= (void *) (time
->alt_digits
[num
] ?: "");
640 iov
[2 + cnt
].iov_len
= strlen (iov
[2 + cnt
].iov_base
) + 1;
641 idx
[1 + last_idx
] += iov
[2 + cnt
].iov_len
;
645 iov
[2 + cnt
].iov_base
= (void *) (time
->era_d_t_fmt
?: "");
646 iov
[2 + cnt
].iov_len
= strlen (iov
[2 + cnt
].iov_base
) + 1;
647 idx
[1 + last_idx
] = idx
[last_idx
] + iov
[2 + cnt
].iov_len
;
651 iov
[2 + cnt
].iov_base
= (void *) (time
->era_t_fmt
?: "");
652 iov
[2 + cnt
].iov_len
= strlen (iov
[2 + cnt
].iov_base
) + 1;
653 idx
[1 + last_idx
] = idx
[last_idx
] + iov
[2 + cnt
].iov_len
;
658 /* We must align the following data. */
659 iov
[2 + cnt
].iov_base
= (void *) "\0\0";
660 iov
[2 + cnt
].iov_len
= ((idx
[last_idx
] + 3) & ~3) - idx
[last_idx
];
661 idx
[last_idx
] = (idx
[last_idx
] + 3) & ~3;
664 /* The `era' data in usable form. */
665 iov
[2 + cnt
].iov_base
= (void *) &time
->num_era
;
666 iov
[2 + cnt
].iov_len
= sizeof (uint32_t);
667 idx
[1 + last_idx
] = idx
[last_idx
] + iov
[2 + cnt
].iov_len
;
671 idx
[1 + last_idx
] = idx
[last_idx
];
672 for (num
= 0; num
< time
->num_era
; ++num
)
676 iov
[2 + cnt
].iov_base
= (void *) &time
->era_entries
[num
].direction
;
677 iov
[2 + cnt
].iov_len
= sizeof (int32_t);
679 iov
[2 + cnt
].iov_base
= (void *) &time
->era_entries
[num
].offset
;
680 iov
[2 + cnt
].iov_len
= sizeof (int32_t);
682 iov
[2 + cnt
].iov_base
= (void *) &time
->era_entries
[num
].start_date
[0];
683 iov
[2 + cnt
].iov_len
= sizeof (int32_t);
685 iov
[2 + cnt
].iov_base
= (void *) &time
->era_entries
[num
].start_date
[1];
686 iov
[2 + cnt
].iov_len
= sizeof (int32_t);
688 iov
[2 + cnt
].iov_base
= (void *) &time
->era_entries
[num
].start_date
[2];
689 iov
[2 + cnt
].iov_len
= sizeof (int32_t);
691 iov
[2 + cnt
].iov_base
= (void *) &time
->era_entries
[num
].stop_date
[0];
692 iov
[2 + cnt
].iov_len
= sizeof (int32_t);
694 iov
[2 + cnt
].iov_base
= (void *) &time
->era_entries
[num
].stop_date
[1];
695 iov
[2 + cnt
].iov_len
= sizeof (int32_t);
697 iov
[2 + cnt
].iov_base
= (void *) &time
->era_entries
[num
].stop_date
[2];
698 iov
[2 + cnt
].iov_len
= sizeof (int32_t);
701 l
= ((char *) rawmemchr (time
->era_entries
[num
].format
, '\0')
702 - time
->era_entries
[num
].name
) + 1;
704 iov
[2 + cnt
].iov_base
= alloca (l2
);
705 memset (mempcpy (iov
[2 + cnt
].iov_base
, time
->era_entries
[num
].name
, l
),
707 iov
[2 + cnt
].iov_len
= l2
;
710 idx
[1 + last_idx
] += 8 * sizeof (int32_t) + l2
;
712 assert (idx
[1 + last_idx
] % 4 == 0);
714 iov
[2 + cnt
].iov_base
= (void *) time
->era_entries
[num
].wname
;
715 iov
[2 + cnt
].iov_len
= ((wcschr ((wchar_t *) time
->era_entries
[num
].wformat
, L
'\0')
716 - (wchar_t *) time
->era_entries
[num
].wname
+ 1)
717 * sizeof (uint32_t));
718 idx
[1 + last_idx
] += iov
[2 + cnt
].iov_len
;
723 /* The wide character ab'days. */
724 for (n
= 0; n
< 7; ++n
, ++cnt
, ++last_idx
)
726 iov
[2 + cnt
].iov_base
=
727 (void *) (time
->wabday
[n
] ?: empty_wstr
);
728 iov
[2 + cnt
].iov_len
= ((wcslen (iov
[2 + cnt
].iov_base
) + 1)
729 * sizeof (uint32_t));
730 idx
[1 + last_idx
] = idx
[last_idx
] + iov
[2 + cnt
].iov_len
;
733 /* The wide character days. */
734 for (n
= 0; n
< 7; ++n
, ++cnt
, ++last_idx
)
736 iov
[2 + cnt
].iov_base
=
737 (void *) (time
->wday
[n
] ?: empty_wstr
);
738 iov
[2 + cnt
].iov_len
= ((wcslen (iov
[2 + cnt
].iov_base
) + 1)
739 * sizeof (uint32_t));
740 idx
[1 + last_idx
] = idx
[last_idx
] + iov
[2 + cnt
].iov_len
;
743 /* The wide character ab'mons. */
744 for (n
= 0; n
< 12; ++n
, ++cnt
, ++last_idx
)
746 iov
[2 + cnt
].iov_base
=
747 (void *) (time
->wabmon
[n
] ?: empty_wstr
);
748 iov
[2 + cnt
].iov_len
= ((wcslen (iov
[2 + cnt
].iov_base
) + 1)
749 * sizeof (uint32_t));
750 idx
[1 + last_idx
] = idx
[last_idx
] + iov
[2 + cnt
].iov_len
;
753 /* The wide character mons. */
754 for (n
= 0; n
< 12; ++n
, ++cnt
, ++last_idx
)
756 iov
[2 + cnt
].iov_base
=
757 (void *) (time
->wmon
[n
] ?: empty_wstr
);
758 iov
[2 + cnt
].iov_len
= ((wcslen (iov
[2 + cnt
].iov_base
) + 1)
759 * sizeof (uint32_t));
760 idx
[1 + last_idx
] = idx
[last_idx
] + iov
[2 + cnt
].iov_len
;
763 /* Wide character AM/PM. */
764 for (n
= 0; n
< 2; ++n
, ++cnt
, ++last_idx
)
766 iov
[2 + cnt
].iov_base
=
767 (void *) (time
->wam_pm
[n
] ?: empty_wstr
);
768 iov
[2 + cnt
].iov_len
= ((wcslen (iov
[2 + cnt
].iov_base
) + 1)
769 * sizeof (uint32_t));
770 idx
[1 + last_idx
] = idx
[last_idx
] + iov
[2 + cnt
].iov_len
;
773 iov
[2 + cnt
].iov_base
= (void *) (time
->wd_t_fmt
?: empty_wstr
);
774 iov
[2 + cnt
].iov_len
= ((wcslen (iov
[2 + cnt
].iov_base
) + 1)
775 * sizeof (uint32_t));
776 idx
[1 + last_idx
] = idx
[last_idx
] + iov
[2 + cnt
].iov_len
;
780 iov
[2 + cnt
].iov_base
= (void *) (time
->wd_fmt
?: empty_wstr
);
781 iov
[2 + cnt
].iov_len
= ((wcslen (iov
[2 + cnt
].iov_base
) + 1)
782 * sizeof (uint32_t));
783 idx
[1 + last_idx
] = idx
[last_idx
] + iov
[2 + cnt
].iov_len
;
787 iov
[2 + cnt
].iov_base
= (void *) (time
->wt_fmt
?: empty_wstr
);
788 iov
[2 + cnt
].iov_len
= ((wcslen (iov
[2 + cnt
].iov_base
) + 1)
789 * sizeof (uint32_t));
790 idx
[1 + last_idx
] = idx
[last_idx
] + iov
[2 + cnt
].iov_len
;
794 iov
[2 + cnt
].iov_base
= (void *) (time
->wt_fmt_ampm
?: empty_wstr
);
795 iov
[2 + cnt
].iov_len
= ((wcslen (iov
[2 + cnt
].iov_base
) + 1)
796 * sizeof (uint32_t));
797 idx
[1 + last_idx
] = idx
[last_idx
] + iov
[2 + cnt
].iov_len
;
801 iov
[2 + cnt
].iov_base
= (void *) (time
->wera_year
?: empty_wstr
);
802 iov
[2 + cnt
].iov_len
= ((wcslen (iov
[2 + cnt
].iov_base
) + 1)
803 * sizeof (uint32_t));
804 idx
[1 + last_idx
] = idx
[last_idx
] + iov
[2 + cnt
].iov_len
;
808 iov
[2 + cnt
].iov_base
= (void *) (time
->wera_d_fmt
?: empty_wstr
);
809 iov
[2 + cnt
].iov_len
= ((wcslen (iov
[2 + cnt
].iov_base
) + 1)
810 * sizeof (uint32_t));
811 idx
[1 + last_idx
] = idx
[last_idx
] + iov
[2 + cnt
].iov_len
;
815 idx
[1 + last_idx
] = idx
[last_idx
];
816 for (num
= 0; num
< 100; ++num
, ++cnt
)
818 iov
[2 + cnt
].iov_base
= (void *) (time
->walt_digits
[num
]
820 iov
[2 + cnt
].iov_len
= ((wcslen (iov
[2 + cnt
].iov_base
) + 1)
821 * sizeof (uint32_t));
822 idx
[1 + last_idx
] += iov
[2 + cnt
].iov_len
;
826 iov
[2 + cnt
].iov_base
= (void *) (time
->wera_d_t_fmt
?: empty_wstr
);
827 iov
[2 + cnt
].iov_len
= ((wcslen (iov
[2 + cnt
].iov_base
) + 1)
828 * sizeof (uint32_t));
829 idx
[1 + last_idx
] = idx
[last_idx
] + iov
[2 + cnt
].iov_len
;
833 iov
[2 + cnt
].iov_base
= (void *) (time
->wera_t_fmt
?: empty_wstr
);
834 iov
[2 + cnt
].iov_len
= ((wcslen (iov
[2 + cnt
].iov_base
) + 1)
835 * sizeof (uint32_t));
836 idx
[1 + last_idx
] = idx
[last_idx
] + iov
[2 + cnt
].iov_len
;
840 iov
[2 + cnt
].iov_base
= (void *) &time
->week_ndays
;
841 iov
[2 + cnt
].iov_len
= 1;
842 idx
[1 + last_idx
] = idx
[last_idx
] + iov
[2 + cnt
].iov_len
;
846 /* We must align the following data. */
847 iov
[2 + cnt
].iov_base
= (void *) "\0\0";
848 iov
[2 + cnt
].iov_len
= ((idx
[last_idx
] + 3) & ~3) - idx
[last_idx
];
849 idx
[last_idx
] = (idx
[last_idx
] + 3) & ~3;
852 iov
[2 + cnt
].iov_base
= (void *) &time
->week_1stday
;
853 iov
[2 + cnt
].iov_len
= sizeof(uint32_t);
854 idx
[1 + last_idx
] = idx
[last_idx
] + iov
[2 + cnt
].iov_len
;
858 iov
[2 + cnt
].iov_base
= (void *) &time
->week_1stweek
;
859 iov
[2 + cnt
].iov_len
= 1;
860 idx
[1 + last_idx
] = idx
[last_idx
] + iov
[2 + cnt
].iov_len
;
864 iov
[2 + cnt
].iov_base
= (void *) &time
->first_weekday
;
865 iov
[2 + cnt
].iov_len
= 1;
866 idx
[1 + last_idx
] = idx
[last_idx
] + iov
[2 + cnt
].iov_len
;
870 iov
[2 + cnt
].iov_base
= (void *) &time
->first_workday
;
871 iov
[2 + cnt
].iov_len
= 1;
872 idx
[1 + last_idx
] = idx
[last_idx
] + iov
[2 + cnt
].iov_len
;
876 iov
[2 + cnt
].iov_base
= (void *) &time
->cal_direction
;
877 iov
[2 + cnt
].iov_len
= 1;
878 idx
[1 + last_idx
] = idx
[last_idx
] + iov
[2 + cnt
].iov_len
;
882 iov
[2 + cnt
].iov_base
= (void *) time
->timezone
;
883 iov
[2 + cnt
].iov_len
= strlen (time
->timezone
) + 1;
884 idx
[1 + last_idx
] = idx
[last_idx
] + iov
[2 + cnt
].iov_len
;
888 iov
[2 + cnt
].iov_base
= (void *) time
->date_fmt
;
889 iov
[2 + cnt
].iov_len
= strlen (iov
[2 + cnt
].iov_base
) + 1;
890 idx
[1 + last_idx
] = idx
[last_idx
] + iov
[2 + cnt
].iov_len
;
894 iov
[2 + cnt
].iov_base
= (void *) time
->wdate_fmt
;
895 iov
[2 + cnt
].iov_len
= ((wcslen (iov
[2 + cnt
].iov_base
) + 1)
896 * sizeof (uint32_t));
897 idx
[1 + last_idx
] = idx
[last_idx
] + iov
[2 + cnt
].iov_len
;
901 iov
[2 + cnt
].iov_base
= (void *) charmap
->code_set_name
;
902 iov
[2 + cnt
].iov_len
= strlen (iov
[2 + cnt
].iov_base
) + 1;
906 assert (cnt
== (_NL_ITEM_INDEX (_NL_NUM_LC_TIME
)
909 + 2 + time
->num_era
* 10 - 1));
910 assert (last_idx
== _NL_ITEM_INDEX (_NL_NUM_LC_TIME
));
912 write_locale_data (output_path
, LC_TIME
, "LC_TIME", 2 + cnt
, iov
);
916 /* The parser for the LC_TIME section of the locale definition. */
918 time_read (struct linereader
*ldfile
, struct localedef_t
*result
,
919 const struct charmap_t
*charmap
, const char *repertoire_name
,
922 struct repertoire_t
*repertoire
= NULL
;
923 struct locale_time_t
*time
;
928 /* Get the repertoire we have to use. */
929 if (repertoire_name
!= NULL
)
930 repertoire
= repertoire_read (repertoire_name
);
932 /* The rest of the line containing `LC_TIME' must be free. */
933 lr_ignore_rest (ldfile
, 1);
938 now
= lr_token (ldfile
, charmap
, result
, repertoire
, verbose
);
941 while (nowtok
== tok_eol
);
943 /* If we see `copy' now we are almost done. */
944 if (nowtok
== tok_copy
)
946 handle_copy (ldfile
, charmap
, repertoire_name
, result
, tok_lc_time
,
947 LC_TIME
, "LC_TIME", ignore_content
);
951 /* Prepare the data structures. */
952 time_startup (ldfile
, result
, ignore_content
);
953 time
= result
->categories
[LC_TIME
].time
;
957 /* Of course we don't proceed beyond the end of file. */
958 if (nowtok
== tok_eof
)
961 /* Ingore empty lines. */
962 if (nowtok
== tok_eol
)
964 now
= lr_token (ldfile
, charmap
, result
, repertoire
, verbose
);
971 #define STRARR_ELEM(cat, min, max) \
973 /* Ignore the rest of the line if we don't need the input of \
975 if (ignore_content) \
977 lr_ignore_rest (ldfile, 0); \
981 for (cnt = 0; cnt < max; ++cnt) \
983 now = lr_token (ldfile, charmap, result, repertoire, verbose); \
984 if (now->tok == tok_eol) \
987 lr_error (ldfile, _("%s: too few values for field `%s'"), \
989 if (!ignore_content) \
992 time->cat[cnt] = ""; \
993 time->w##cat[cnt] = empty_wstr; \
995 while (++cnt < max); \
998 else if (now->tok != tok_string) \
1000 else if (!ignore_content && (now->val.str.startmb == NULL \
1001 || now->val.str.startwc == NULL)) \
1003 lr_error (ldfile, _("%s: unknown character in field `%s'"), \
1005 time->cat[cnt] = ""; \
1006 time->w##cat[cnt] = empty_wstr; \
1008 else if (!ignore_content) \
1010 time->cat[cnt] = now->val.str.startmb; \
1011 time->w##cat[cnt] = now->val.str.startwc; \
1014 /* Match the semicolon. */ \
1015 now = lr_token (ldfile, charmap, result, repertoire, verbose); \
1016 if (now->tok != tok_semicolon && now->tok != tok_eol) \
1019 if (now->tok != tok_eol) \
1021 while (!ignore_content && cnt < min) \
1023 time->cat[cnt] = ""; \
1024 time->w##cat[cnt++] = empty_wstr; \
1027 if (now->tok == tok_semicolon) \
1029 now = lr_token (ldfile, charmap, result, repertoire, \
1031 if (now->tok == tok_eol) \
1032 lr_error (ldfile, _("extra trailing semicolon")); \
1033 else if (now->tok == tok_string) \
1035 lr_error (ldfile, _("\
1036 %s: too many values for field `%s'"), \
1038 lr_ignore_rest (ldfile, 0); \
1046 time->cat##_defined = 1; \
1049 STRARR_ELEM (abday
, 7, 7);
1050 STRARR_ELEM (day
, 7, 7);
1051 STRARR_ELEM (abmon
, 12, 12);
1052 STRARR_ELEM (mon
, 12, 12);
1053 STRARR_ELEM (am_pm
, 2, 2);
1054 STRARR_ELEM (alt_digits
, 0, 100);
1057 /* Ignore the rest of the line if we don't need the input of
1061 lr_ignore_rest (ldfile
, 0);
1066 now
= lr_token (ldfile
, charmap
, result
, repertoire
, verbose
);
1067 if (now
->tok
!= tok_string
)
1069 if (!ignore_content
&& (now
->val
.str
.startmb
== NULL
1070 || now
->val
.str
.startwc
== NULL
))
1072 lr_error (ldfile
, _("%s: unknown character in field `%s'"),
1074 lr_ignore_rest (ldfile
, 0);
1077 if (!ignore_content
)
1079 time
->era
= xrealloc (time
->era
,
1080 (time
->num_era
+ 1) * sizeof (char *));
1081 time
->era
[time
->num_era
] = now
->val
.str
.startmb
;
1083 time
->wera
= xrealloc (time
->wera
,
1086 time
->wera
[time
->num_era
++] = now
->val
.str
.startwc
;
1088 now
= lr_token (ldfile
, charmap
, result
, repertoire
, verbose
);
1089 if (now
->tok
!= tok_eol
&& now
->tok
!= tok_semicolon
)
1092 while (now
->tok
== tok_semicolon
);
1095 #define STR_ELEM(cat) \
1097 /* Ignore the rest of the line if we don't need the input of \
1099 if (ignore_content) \
1101 lr_ignore_rest (ldfile, 0); \
1105 now = lr_token (ldfile, charmap, result, repertoire, verbose); \
1106 if (now->tok != tok_string) \
1108 else if (time->cat != NULL) \
1109 lr_error (ldfile, _("\
1110 %s: field `%s' declared more than once"), "LC_TIME", #cat); \
1111 else if (!ignore_content && (now->val.str.startmb == NULL \
1112 || now->val.str.startwc == NULL)) \
1114 lr_error (ldfile, _("%s: unknown character in field `%s'"), \
1117 time->w##cat = empty_wstr; \
1119 else if (!ignore_content) \
1121 time->cat = now->val.str.startmb; \
1122 time->w##cat = now->val.str.startwc; \
1129 STR_ELEM (t_fmt_ampm
);
1130 STR_ELEM (era_year
);
1131 STR_ELEM (era_d_t_fmt
);
1132 STR_ELEM (era_d_fmt
);
1133 STR_ELEM (era_t_fmt
);
1134 STR_ELEM (timezone
);
1135 STR_ELEM (date_fmt
);
1137 #define INT_ELEM(cat) \
1139 /* Ignore the rest of the line if we don't need the input of \
1141 if (ignore_content) \
1143 lr_ignore_rest (ldfile, 0); \
1147 now = lr_token (ldfile, charmap, result, repertoire, verbose); \
1148 if (now->tok != tok_number) \
1150 else if (time->cat != 0) \
1151 lr_error (ldfile, _("%s: field `%s' declared more than once"), \
1153 else if (!ignore_content) \
1154 time->cat = now->val.num; \
1157 INT_ELEM (first_weekday
);
1158 INT_ELEM (first_workday
);
1159 INT_ELEM (cal_direction
);
1162 /* Ignore the rest of the line if we don't need the input of
1166 lr_ignore_rest (ldfile
, 0);
1170 now
= lr_token (ldfile
, charmap
, result
, repertoire
, verbose
);
1171 if (now
->tok
!= tok_number
)
1173 time
->week_ndays
= now
->val
.num
;
1175 now
= lr_token (ldfile
, charmap
, result
, repertoire
, verbose
);
1176 if (now
->tok
!= tok_semicolon
)
1179 now
= lr_token (ldfile
, charmap
, result
, repertoire
, verbose
);
1180 if (now
->tok
!= tok_number
)
1182 time
->week_1stday
= now
->val
.num
;
1184 now
= lr_token (ldfile
, charmap
, result
, repertoire
, verbose
);
1185 if (now
->tok
!= tok_semicolon
)
1188 now
= lr_token (ldfile
, charmap
, result
, repertoire
, verbose
);
1189 if (now
->tok
!= tok_number
)
1191 time
->week_1stweek
= now
->val
.num
;
1193 lr_ignore_rest (ldfile
, 1);
1197 /* Next we assume `LC_TIME'. */
1198 now
= lr_token (ldfile
, charmap
, result
, repertoire
, verbose
);
1199 if (now
->tok
== tok_eof
)
1201 if (now
->tok
== tok_eol
)
1202 lr_error (ldfile
, _("%s: incomplete `END' line"), "LC_TIME");
1203 else if (now
->tok
!= tok_lc_time
)
1204 lr_error (ldfile
, _("\
1205 %1$s: definition does not end with `END %1$s'"), "LC_TIME");
1206 lr_ignore_rest (ldfile
, now
->tok
== tok_lc_time
);
1211 SYNTAX_ERROR (_("%s: syntax error"), "LC_TIME");
1214 /* Prepare for the next round. */
1215 now
= lr_token (ldfile
, charmap
, result
, repertoire
, verbose
);
1219 /* When we come here we reached the end of the file. */
1220 lr_error (ldfile
, _("%s: premature end of file"), "LC_TIME");