]>
git.ipfire.org Git - thirdparty/glibc.git/blob - locale/programs/ld-time.c
1 /* Copyright (C) 1995-1999, 2000, 2001, 2002 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
[2 + _NL_ITEM_INDEX (_NL_NUM_LC_TIME
)
534 + 2 + time
->num_era
* 10 - 1];
535 struct locale_file data
;
536 uint32_t idx
[_NL_ITEM_INDEX (_NL_NUM_LC_TIME
)];
537 size_t cnt
, last_idx
, num
, n
;
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
);
544 iov
[1].iov_base
= (void *) idx
;
545 iov
[1].iov_len
= sizeof (idx
);
547 idx
[0] = iov
[0].iov_len
+ iov
[1].iov_len
;
550 for (cnt
= 0; cnt
<= _NL_ITEM_INDEX (ABDAY_7
); ++cnt
)
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
;
559 for (; cnt
<= _NL_ITEM_INDEX (DAY_7
); ++cnt
)
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
;
568 for (; cnt
<= _NL_ITEM_INDEX (ABMON_12
); ++cnt
)
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
;
577 for (; cnt
<= _NL_ITEM_INDEX (MON_12
); ++cnt
)
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
;
586 for (; cnt
<= _NL_ITEM_INDEX (PM_STR
); ++cnt
)
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
;
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
;
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
;
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
;
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
;
614 idx
[1 + last_idx
] = idx
[last_idx
];
615 for (num
= 0; num
< time
->num_era
; ++num
, ++cnt
)
617 iov
[2 + cnt
].iov_base
= (void *) time
->era
[num
];
618 iov
[2 + cnt
].iov_len
= strlen (iov
[2 + cnt
].iov_base
) + 1;
619 idx
[1 + last_idx
] += iov
[2 + cnt
].iov_len
;
623 iov
[2 + cnt
].iov_base
= (void *) (time
->era_year
?: "");
624 iov
[2 + cnt
].iov_len
= strlen (iov
[2 + cnt
].iov_base
) + 1;
625 idx
[1 + last_idx
] = idx
[last_idx
] + iov
[2 + cnt
].iov_len
;
629 iov
[2 + cnt
].iov_base
= (void *) (time
->era_d_fmt
?: "");
630 iov
[2 + cnt
].iov_len
= strlen (iov
[2 + cnt
].iov_base
) + 1;
631 idx
[1 + last_idx
] = idx
[last_idx
] + iov
[2 + cnt
].iov_len
;
635 idx
[1 + last_idx
] = idx
[last_idx
];
636 for (num
= 0; num
< 100; ++num
, ++cnt
)
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
;
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
;
650 iov
[2 + cnt
].iov_base
= (void *) (time
->era_t_fmt
?: "");
651 iov
[2 + cnt
].iov_len
= strlen (iov
[2 + cnt
].iov_base
) + 1;
652 idx
[1 + last_idx
] = idx
[last_idx
] + iov
[2 + cnt
].iov_len
;
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;
663 /* The `era' data in usable form. */
664 iov
[2 + cnt
].iov_base
= (void *) &time
->num_era
;
665 iov
[2 + cnt
].iov_len
= sizeof (uint32_t);
666 idx
[1 + last_idx
] = idx
[last_idx
] + iov
[2 + cnt
].iov_len
;
670 idx
[1 + last_idx
] = idx
[last_idx
];
671 for (num
= 0; num
< time
->num_era
; ++num
)
675 iov
[2 + cnt
].iov_base
= (void *) &time
->era_entries
[num
].direction
;
676 iov
[2 + cnt
].iov_len
= sizeof (int32_t);
678 iov
[2 + cnt
].iov_base
= (void *) &time
->era_entries
[num
].offset
;
679 iov
[2 + cnt
].iov_len
= sizeof (int32_t);
681 iov
[2 + cnt
].iov_base
= (void *) &time
->era_entries
[num
].start_date
[0];
682 iov
[2 + cnt
].iov_len
= sizeof (int32_t);
684 iov
[2 + cnt
].iov_base
= (void *) &time
->era_entries
[num
].start_date
[1];
685 iov
[2 + cnt
].iov_len
= sizeof (int32_t);
687 iov
[2 + cnt
].iov_base
= (void *) &time
->era_entries
[num
].start_date
[2];
688 iov
[2 + cnt
].iov_len
= sizeof (int32_t);
690 iov
[2 + cnt
].iov_base
= (void *) &time
->era_entries
[num
].stop_date
[0];
691 iov
[2 + cnt
].iov_len
= sizeof (int32_t);
693 iov
[2 + cnt
].iov_base
= (void *) &time
->era_entries
[num
].stop_date
[1];
694 iov
[2 + cnt
].iov_len
= sizeof (int32_t);
696 iov
[2 + cnt
].iov_base
= (void *) &time
->era_entries
[num
].stop_date
[2];
697 iov
[2 + cnt
].iov_len
= sizeof (int32_t);
700 l
= (strchr (time
->era_entries
[num
].format
, '\0')
701 - time
->era_entries
[num
].name
) + 1;
703 iov
[2 + cnt
].iov_base
= (void *) time
->era_entries
[num
].name
;
704 iov
[2 + cnt
].iov_len
= l
;
707 idx
[1 + last_idx
] += 8 * sizeof (int32_t) + l
;
709 assert (idx
[1 + last_idx
] % 4 == 0);
711 iov
[2 + cnt
].iov_base
= (void *) time
->era_entries
[num
].wname
;
712 iov
[2 + cnt
].iov_len
= ((wcschr ((wchar_t *) time
->era_entries
[num
].wformat
, L
'\0')
713 - (wchar_t *) time
->era_entries
[num
].wname
+ 1)
714 * sizeof (uint32_t));
715 idx
[1 + last_idx
] += iov
[2 + cnt
].iov_len
;
720 /* The wide character ab'days. */
721 for (n
= 0; n
< 7; ++n
, ++cnt
, ++last_idx
)
723 iov
[2 + cnt
].iov_base
=
724 (void *) (time
->wabday
[n
] ?: empty_wstr
);
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
;
730 /* The wide character days. */
731 for (n
= 0; n
< 7; ++n
, ++cnt
, ++last_idx
)
733 iov
[2 + cnt
].iov_base
=
734 (void *) (time
->wday
[n
] ?: empty_wstr
);
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
;
740 /* The wide character ab'mons. */
741 for (n
= 0; n
< 12; ++n
, ++cnt
, ++last_idx
)
743 iov
[2 + cnt
].iov_base
=
744 (void *) (time
->wabmon
[n
] ?: empty_wstr
);
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
;
750 /* The wide character mons. */
751 for (n
= 0; n
< 12; ++n
, ++cnt
, ++last_idx
)
753 iov
[2 + cnt
].iov_base
=
754 (void *) (time
->wmon
[n
] ?: empty_wstr
);
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
;
760 /* Wide character AM/PM. */
761 for (n
= 0; n
< 2; ++n
, ++cnt
, ++last_idx
)
763 iov
[2 + cnt
].iov_base
=
764 (void *) (time
->wam_pm
[n
] ?: empty_wstr
);
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
;
770 iov
[2 + cnt
].iov_base
= (void *) (time
->wd_t_fmt
?: empty_wstr
);
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
;
777 iov
[2 + cnt
].iov_base
= (void *) (time
->wd_fmt
?: empty_wstr
);
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
;
784 iov
[2 + cnt
].iov_base
= (void *) (time
->wt_fmt
?: empty_wstr
);
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
;
791 iov
[2 + cnt
].iov_base
= (void *) (time
->wt_fmt_ampm
?: empty_wstr
);
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
;
798 iov
[2 + cnt
].iov_base
= (void *) (time
->wera_year
?: empty_wstr
);
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
;
805 iov
[2 + cnt
].iov_base
= (void *) (time
->wera_d_fmt
?: empty_wstr
);
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
;
812 idx
[1 + last_idx
] = idx
[last_idx
];
813 for (num
= 0; num
< 100; ++num
, ++cnt
)
815 iov
[2 + cnt
].iov_base
= (void *) (time
->walt_digits
[num
]
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
;
823 iov
[2 + cnt
].iov_base
= (void *) (time
->wera_d_t_fmt
?: empty_wstr
);
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
;
830 iov
[2 + cnt
].iov_base
= (void *) (time
->wera_t_fmt
?: empty_wstr
);
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
;
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
;
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;
849 iov
[2 + cnt
].iov_base
= (void *) &time
->week_1stday
;
850 iov
[2 + cnt
].iov_len
= sizeof(uint32_t);
851 idx
[1 + last_idx
] = idx
[last_idx
] + iov
[2 + cnt
].iov_len
;
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
;
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
;
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
;
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
;
879 iov
[2 + cnt
].iov_base
= (void *) time
->timezone
;
880 iov
[2 + cnt
].iov_len
= strlen (time
->timezone
) + 1;
881 idx
[1 + last_idx
] = idx
[last_idx
] + iov
[2 + cnt
].iov_len
;
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
;
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));
894 idx
[1 + last_idx
] = idx
[last_idx
] + iov
[2 + cnt
].iov_len
;
898 iov
[2 + cnt
].iov_base
= (void *) charmap
->code_set_name
;
899 iov
[2 + cnt
].iov_len
= strlen (iov
[2 + cnt
].iov_base
) + 1;
903 assert (cnt
== (_NL_ITEM_INDEX (_NL_NUM_LC_TIME
)
906 + 2 + time
->num_era
* 10 - 1));
907 assert (last_idx
== _NL_ITEM_INDEX (_NL_NUM_LC_TIME
));
909 write_locale_data (output_path
, "LC_TIME", 2 + cnt
, iov
);
913 /* The parser for the LC_TIME section of the locale definition. */
915 time_read (struct linereader
*ldfile
, struct localedef_t
*result
,
916 const struct charmap_t
*charmap
, const char *repertoire_name
,
919 struct repertoire_t
*repertoire
= NULL
;
920 struct locale_time_t
*time
;
925 /* Get the repertoire we have to use. */
926 if (repertoire_name
!= NULL
)
927 repertoire
= repertoire_read (repertoire_name
);
929 /* The rest of the line containing `LC_TIME' must be free. */
930 lr_ignore_rest (ldfile
, 1);
935 now
= lr_token (ldfile
, charmap
, result
, repertoire
, verbose
);
938 while (nowtok
== tok_eol
);
940 /* If we see `copy' now we are almost done. */
941 if (nowtok
== tok_copy
)
943 handle_copy (ldfile
, charmap
, repertoire_name
, result
, tok_lc_time
,
944 LC_TIME
, "LC_TIME", ignore_content
);
948 /* Prepare the data structures. */
949 time_startup (ldfile
, result
, ignore_content
);
950 time
= result
->categories
[LC_TIME
].time
;
954 /* Of course we don't proceed beyond the end of file. */
955 if (nowtok
== tok_eof
)
958 /* Ingore empty lines. */
959 if (nowtok
== tok_eol
)
961 now
= lr_token (ldfile
, charmap
, result
, repertoire
, verbose
);
968 #define STRARR_ELEM(cat, min, max) \
970 /* Ignore the rest of the line if we don't need the input of \
972 if (ignore_content) \
974 lr_ignore_rest (ldfile, 0); \
978 for (cnt = 0; cnt < max; ++cnt) \
980 now = lr_token (ldfile, charmap, result, repertoire, verbose); \
981 if (now->tok == tok_eol) \
984 lr_error (ldfile, _("%s: too few values for field `%s'"), \
986 if (!ignore_content) \
989 time->cat[cnt] = ""; \
990 time->w##cat[cnt] = empty_wstr; \
992 while (++cnt < max); \
995 else if (now->tok != tok_string) \
997 else if (!ignore_content && (now->val.str.startmb == NULL \
998 || now->val.str.startwc == NULL)) \
1000 lr_error (ldfile, _("%s: unknown character in field `%s'"), \
1002 time->cat[cnt] = ""; \
1003 time->w##cat[cnt] = empty_wstr; \
1005 else if (!ignore_content) \
1007 time->cat[cnt] = now->val.str.startmb; \
1008 time->w##cat[cnt] = now->val.str.startwc; \
1011 /* Match the semicolon. */ \
1012 now = lr_token (ldfile, charmap, result, repertoire, verbose); \
1013 if (now->tok != tok_semicolon && now->tok != tok_eol) \
1016 if (now->tok != tok_eol) \
1018 while (!ignore_content && cnt < min) \
1020 time->cat[cnt] = ""; \
1021 time->w##cat[cnt++] = empty_wstr; \
1024 if (now->tok == tok_semicolon) \
1026 now = lr_token (ldfile, charmap, result, repertoire, \
1028 if (now->tok == tok_eol) \
1029 lr_error (ldfile, _("extra trailing semicolon")); \
1030 else if (now->tok == tok_string) \
1032 lr_error (ldfile, _("\
1033 %s: too many values for field `%s'"), \
1035 lr_ignore_rest (ldfile, 0); \
1043 time->cat##_defined = 1; \
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);
1054 /* Ignore the rest of the line if we don't need the input of
1058 lr_ignore_rest (ldfile
, 0);
1063 now
= lr_token (ldfile
, charmap
, result
, repertoire
, verbose
);
1064 if (now
->tok
!= tok_string
)
1066 if (!ignore_content
&& (now
->val
.str
.startmb
== NULL
1067 || now
->val
.str
.startwc
== NULL
))
1069 lr_error (ldfile
, _("%s: unknown character in field `%s'"),
1071 lr_ignore_rest (ldfile
, 0);
1074 if (!ignore_content
)
1076 time
->era
= xrealloc (time
->era
,
1077 (time
->num_era
+ 1) * sizeof (char *));
1078 time
->era
[time
->num_era
] = now
->val
.str
.startmb
;
1080 time
->wera
= xrealloc (time
->wera
,
1083 time
->wera
[time
->num_era
++] = now
->val
.str
.startwc
;
1085 now
= lr_token (ldfile
, charmap
, result
, repertoire
, verbose
);
1086 if (now
->tok
!= tok_eol
&& now
->tok
!= tok_semicolon
)
1089 while (now
->tok
== tok_semicolon
);
1092 #define STR_ELEM(cat) \
1094 /* Ignore the rest of the line if we don't need the input of \
1096 if (ignore_content) \
1098 lr_ignore_rest (ldfile, 0); \
1102 now = lr_token (ldfile, charmap, result, repertoire, verbose); \
1103 if (now->tok != tok_string) \
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)) \
1111 lr_error (ldfile, _("%s: unknown character in field `%s'"), \
1114 time->w##cat = empty_wstr; \
1116 else if (!ignore_content) \
1118 time->cat = now->val.str.startmb; \
1119 time->w##cat = now->val.str.startwc; \
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
);
1132 STR_ELEM (date_fmt
);
1134 #define INT_ELEM(cat) \
1136 /* Ignore the rest of the line if we don't need the input of \
1138 if (ignore_content) \
1140 lr_ignore_rest (ldfile, 0); \
1144 now = lr_token (ldfile, charmap, result, repertoire, verbose); \
1145 if (now->tok != tok_number) \
1147 else if (time->cat != 0) \
1148 lr_error (ldfile, _("%s: field `%s' declared more than once"), \
1150 else if (!ignore_content) \
1151 time->cat = now->val.num; \
1154 INT_ELEM (first_weekday
);
1155 INT_ELEM (first_workday
);
1156 INT_ELEM (cal_direction
);
1159 /* Ignore the rest of the line if we don't need the input of
1163 lr_ignore_rest (ldfile
, 0);
1167 now
= lr_token (ldfile
, charmap
, result
, repertoire
, verbose
);
1168 if (now
->tok
!= tok_number
)
1170 time
->week_ndays
= now
->val
.num
;
1172 now
= lr_token (ldfile
, charmap
, result
, repertoire
, verbose
);
1173 if (now
->tok
!= tok_semicolon
)
1176 now
= lr_token (ldfile
, charmap
, result
, repertoire
, verbose
);
1177 if (now
->tok
!= tok_number
)
1179 time
->week_1stday
= now
->val
.num
;
1181 now
= lr_token (ldfile
, charmap
, result
, repertoire
, verbose
);
1182 if (now
->tok
!= tok_semicolon
)
1185 now
= lr_token (ldfile
, charmap
, result
, repertoire
, verbose
);
1186 if (now
->tok
!= tok_number
)
1188 time
->week_1stweek
= now
->val
.num
;
1190 lr_ignore_rest (ldfile
, 1);
1194 /* Next we assume `LC_TIME'. */
1195 now
= lr_token (ldfile
, charmap
, result
, repertoire
, verbose
);
1196 if (now
->tok
== tok_eof
)
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
);
1208 SYNTAX_ERROR (_("%s: syntax error"), "LC_TIME");
1211 /* Prepare for the next round. */
1212 now
= lr_token (ldfile
, charmap
, result
, repertoire
, verbose
);
1216 /* When we come here we reached the end of the file. */
1217 lr_error (ldfile
, _("%s: premature end of file"), "LC_TIME");