1 /* Copyright (C) 1995-2005, 2006, 2007 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, write to the Free Software Foundation,
17 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
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 WITH_CUR_LOCALE (error (0, 0, _("\
160 No definition for %s category found"), "LC_TIME"));
161 time_startup (NULL
, locale
, 0);
162 time
= locale
->categories
[LC_TIME
].time
;
167 #define noparen(arg1, argn...) arg1, ##argn
168 #define TESTARR_ELEM(cat, val) \
169 if (!time->cat##_defined) \
171 const char *initval[] = { noparen val }; \
174 if (! be_quiet && ! nothing) \
175 WITH_CUR_LOCALE (error (0, 0, _("%s: field `%s' not defined"), \
178 for (i = 0; i < sizeof (initval) / sizeof (initval[0]); ++i) \
179 time->cat[i] = initval[i]; \
182 TESTARR_ELEM (abday
, ( "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" ));
183 TESTARR_ELEM (day
, ( "Sunday", "Monday", "Tuesday", "Wednesday",
184 "Thursday", "Friday", "Saturday" ));
185 TESTARR_ELEM (abmon
, ( "Jan", "Feb", "Mar", "Apr", "May", "Jun",
186 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" ));
187 TESTARR_ELEM (mon
, ( "January", "February", "March", "April",
188 "May", "June", "July", "August",
189 "September", "October", "November", "December" ));
190 TESTARR_ELEM (am_pm
, ( "AM", "PM" ));
192 #define TEST_ELEM(cat, initval) \
193 if (time->cat == NULL) \
195 if (! be_quiet && ! nothing) \
196 WITH_CUR_LOCALE (error (0, 0, _("%s: field `%s' not defined"), \
199 time->cat = initval; \
202 TEST_ELEM (d_t_fmt
, "%a %b %e %H:%M:%S %Y");
203 TEST_ELEM (d_fmt
, "%m/%d/%y");
204 TEST_ELEM (t_fmt
, "%H:%M:%S");
206 /* According to C.Y.Alexis Cheng <alexis@vnet.ibm.com> the T_FMT_AMPM
207 field is optional. */
208 if (time
->t_fmt_ampm
== NULL
)
210 if (time
->am_pm
[0][0] == '\0' && time
->am_pm
[1][0] == '\0')
212 /* No AM/PM strings defined, use the 24h format as default. */
213 time
->t_fmt_ampm
= time
->t_fmt
;
214 time
->wt_fmt_ampm
= time
->wt_fmt
;
218 time
->t_fmt_ampm
= "%I:%M:%S %p";
219 time
->wt_fmt_ampm
= (const uint32_t *) L
"%I:%M:%S %p";
223 /* Now process the era entries. */
224 if (time
->num_era
!= 0)
226 const int days_per_month
[12] = { 31, 29, 31, 30, 31, 30,
227 31, 31, 30, 31 ,30, 31 };
232 (struct era_data
*) xmalloc (time
->num_era
233 * sizeof (struct era_data
));
235 for (idx
= 0; idx
< time
->num_era
; ++idx
)
237 size_t era_len
= strlen (time
->era
[idx
]);
238 char *str
= xmalloc ((era_len
+ 1 + 3) & ~3);
241 memcpy (str
, time
->era
[idx
], era_len
+ 1);
243 /* First character must be + or - for the direction. */
244 if (*str
!= '+' && *str
!= '-')
247 WITH_CUR_LOCALE (error (0, 0, _("\
248 %s: direction flag in string %Zd in `era' field is not '+' nor '-'"),
249 "LC_TIME", idx
+ 1));
250 /* Default arbitrarily to '+'. */
251 time
->era_entries
[idx
].direction
= '+';
254 time
->era_entries
[idx
].direction
= *str
;
258 WITH_CUR_LOCALE (error (0, 0, _("\
259 %s: direction flag in string %Zd in `era' field is not a single character"),
260 "LC_TIME", idx
+ 1));
261 (void) strsep (&str
, ":");
266 /* Now the offset year. */
267 time
->era_entries
[idx
].offset
= strtol (str
, &endp
, 10);
271 WITH_CUR_LOCALE (error (0, 0, _("\
272 %s: invalid number for offset in string %Zd in `era' field"),
273 "LC_TIME", idx
+ 1));
274 (void) strsep (&str
, ":");
276 else if (*endp
!= ':')
279 WITH_CUR_LOCALE (error (0, 0, _("\
280 %s: garbage at end of offset value in string %Zd in `era' field"),
281 "LC_TIME", idx
+ 1));
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);
330 WITH_CUR_LOCALE (error (0, 0, _("\
331 %s: invalid starting date in string %Zd in `era' field"),
332 "LC_TIME", idx
+ 1));
333 (void) strsep (&str
, ":");
335 else if (*endp
!= ':')
339 WITH_CUR_LOCALE (error (0, 0, _("\
340 %s: garbage at end of starting date in string %Zd in `era' field "),
341 "LC_TIME", idx
+ 1));
342 (void) strsep (&str
, ":");
348 /* Check for valid value. */
349 if ((time
->era_entries
[idx
].start_date
[1] < 0
350 || time
->era_entries
[idx
].start_date
[1] >= 12
351 || time
->era_entries
[idx
].start_date
[2] < 0
352 || (time
->era_entries
[idx
].start_date
[2]
353 > days_per_month
[time
->era_entries
[idx
].start_date
[1]])
354 || (time
->era_entries
[idx
].start_date
[1] == 2
355 && time
->era_entries
[idx
].start_date
[2] == 29
356 && !__isleap (time
->era_entries
[idx
].start_date
[0])))
358 WITH_CUR_LOCALE (error (0, 0, _("\
359 %s: starting date is invalid in string %Zd in `era' field"),
360 "LC_TIME", idx
+ 1));
364 /* Next is the stopping date in ISO format. */
365 if (strncmp (str
, "-*", 2) == 0)
367 time
->era_entries
[idx
].stop_date
[0] =
368 time
->era_entries
[idx
].stop_date
[1] =
369 time
->era_entries
[idx
].stop_date
[2] = 0x80000000;
371 goto garbage_stop_date
;
374 else if (strncmp (str
, "+*", 2) == 0)
376 time
->era_entries
[idx
].stop_date
[0] =
377 time
->era_entries
[idx
].stop_date
[1] =
378 time
->era_entries
[idx
].stop_date
[2] = 0x7fffffff;
380 goto garbage_stop_date
;
385 time
->era_entries
[idx
].stop_date
[0] = strtol (str
, &endp
, 10);
386 if (endp
== str
|| *endp
!= '/')
387 goto invalid_stop_date
;
390 time
->era_entries
[idx
].stop_date
[0] -= 1900;
391 /* year -1 represent 1 B.C. (not -1 A.D.) */
392 if (time
->era_entries
[idx
].stop_date
[0] < -1900)
393 ++time
->era_entries
[idx
].stop_date
[0];
395 time
->era_entries
[idx
].stop_date
[1] = strtol (str
, &endp
, 10);
396 if (endp
== str
|| *endp
!= '/')
397 goto invalid_stop_date
;
400 time
->era_entries
[idx
].stop_date
[1] -= 1;
402 time
->era_entries
[idx
].stop_date
[2] = strtol (str
, &endp
, 10);
407 WITH_CUR_LOCALE (error (0, 0, _("\
408 %s: invalid stopping date in string %Zd in `era' field"),
409 "LC_TIME", idx
+ 1));
410 (void) strsep (&str
, ":");
412 else if (*endp
!= ':')
416 WITH_CUR_LOCALE (error (0, 0, _("\
417 %s: garbage at end of stopping date in string %Zd in `era' field"),
418 "LC_TIME", idx
+ 1));
419 (void) strsep (&str
, ":");
425 /* Check for valid value. */
426 if ((time
->era_entries
[idx
].stop_date
[1] < 0
427 || time
->era_entries
[idx
].stop_date
[1] >= 12
428 || time
->era_entries
[idx
].stop_date
[2] < 0
429 || (time
->era_entries
[idx
].stop_date
[2]
430 > days_per_month
[time
->era_entries
[idx
].stop_date
[1]])
431 || (time
->era_entries
[idx
].stop_date
[1] == 2
432 && time
->era_entries
[idx
].stop_date
[2] == 29
433 && !__isleap (time
->era_entries
[idx
].stop_date
[0])))
435 WITH_CUR_LOCALE (error (0, 0, _("\
436 %s: stopping date is invalid in string %Zd in `era' field"),
437 "LC_TIME", idx
+ 1));
441 if (str
== NULL
|| *str
== '\0')
444 WITH_CUR_LOCALE (error (0, 0, _("\
445 %s: missing era name in string %Zd in `era' field"), "LC_TIME", idx
+ 1));
446 time
->era_entries
[idx
].name
=
447 time
->era_entries
[idx
].format
= "";
451 time
->era_entries
[idx
].name
= strsep (&str
, ":");
453 if (str
== NULL
|| *str
== '\0')
456 WITH_CUR_LOCALE (error (0, 0, _("\
457 %s: missing era format in string %Zd in `era' field"),
458 "LC_TIME", idx
+ 1));
459 time
->era_entries
[idx
].name
=
460 time
->era_entries
[idx
].format
= "";
463 time
->era_entries
[idx
].format
= str
;
466 /* Now generate the wide character name and format. */
467 wstr
= wcschr ((wchar_t *) time
->wera
[idx
], L
':');/* end direction */
468 wstr
= wstr
? wcschr (wstr
+ 1, L
':') : NULL
; /* end offset */
469 wstr
= wstr
? wcschr (wstr
+ 1, L
':') : NULL
; /* end start */
470 wstr
= wstr
? wcschr (wstr
+ 1, L
':') : NULL
; /* end end */
473 time
->era_entries
[idx
].wname
= (uint32_t *) wstr
+ 1;
474 wstr
= wcschr (wstr
+ 1, L
':'); /* end name */
478 time
->era_entries
[idx
].wformat
= (uint32_t *) wstr
+ 1;
481 time
->era_entries
[idx
].wname
=
482 time
->era_entries
[idx
].wformat
= (uint32_t *) L
"";
485 time
->era_entries
[idx
].wname
=
486 time
->era_entries
[idx
].wformat
= (uint32_t *) L
"";
490 if (time
->week_ndays
== 0)
491 time
->week_ndays
= 7;
493 if (time
->week_1stday
== 0)
494 time
->week_1stday
= 19971130;
496 if (time
->week_1stweek
> time
->week_ndays
)
497 WITH_CUR_LOCALE (error (0, 0, _("\
498 %s: third operand for value of field `%s' must not be larger than %d"),
499 "LC_TIME", "week", 7));
501 if (time
->first_weekday
== '\0')
502 /* The definition does not specify this so the default is used. */
503 time
->first_weekday
= 1;
504 else if (time
->first_weekday
> time
->week_ndays
)
505 WITH_CUR_LOCALE (error (0, 0, _("\
506 %s: values for field `%s' must not be larger than %d"),
507 "LC_TIME", "first_weekday", 7));
509 if (time
->first_workday
== '\0')
510 /* The definition does not specify this so the default is used. */
511 time
->first_workday
= 2;
512 else if (time
->first_workday
> time
->week_ndays
)
513 WITH_CUR_LOCALE (error (0, 0, _("\
514 %s: values for field `%s' must not be larger than %d"),
515 "LC_TIME", "first_workday", 7));
517 if (time
->cal_direction
== '\0')
518 /* The definition does not specify this so the default is used. */
519 time
->cal_direction
= 1;
520 else if (time
->cal_direction
> 3)
521 WITH_CUR_LOCALE (error (0, 0, _("\
522 %s: values for field `%s' must not be larger than %d"),
523 "LC_TIME", "cal_direction", 3));
525 /* XXX We don't perform any tests on the timezone value since this is
526 simply useless, stupid $&$!@... */
527 if (time
->timezone
== NULL
)
530 if (time
->date_fmt
== NULL
)
531 time
->date_fmt
= "%a %b %e %H:%M:%S %Z %Y";
532 if (time
->wdate_fmt
== NULL
)
533 time
->wdate_fmt
= (const uint32_t *) L
"%a %b %e %H:%M:%S %Z %Y";
538 time_output (struct localedef_t
*locale
, const struct charmap_t
*charmap
,
539 const char *output_path
)
541 struct locale_time_t
*time
= locale
->categories
[LC_TIME
].time
;
542 struct iovec
*iov
= alloca (sizeof *iov
543 * (2 + _NL_ITEM_INDEX (_NL_NUM_LC_TIME
)
546 + 2 + time
->num_era
* 10));
547 struct locale_file data
;
548 uint32_t idx
[_NL_ITEM_INDEX (_NL_NUM_LC_TIME
)];
549 size_t cnt
, last_idx
, num
, n
;
551 data
.magic
= LIMAGIC (LC_TIME
);
552 data
.n
= _NL_ITEM_INDEX (_NL_NUM_LC_TIME
);
553 iov
[0].iov_base
= (void *) &data
;
554 iov
[0].iov_len
= sizeof (data
);
556 iov
[1].iov_base
= (void *) idx
;
557 iov
[1].iov_len
= sizeof (idx
);
559 idx
[0] = iov
[0].iov_len
+ iov
[1].iov_len
;
562 for (cnt
= 0; cnt
<= _NL_ITEM_INDEX (ABDAY_7
); ++cnt
)
564 iov
[2 + cnt
].iov_base
=
565 (void *) (time
->abday
[cnt
- _NL_ITEM_INDEX (ABDAY_1
)] ?: "");
566 iov
[2 + cnt
].iov_len
= strlen (iov
[2 + cnt
].iov_base
) + 1;
567 idx
[1 + cnt
] = idx
[cnt
] + iov
[2 + cnt
].iov_len
;
571 for (; cnt
<= _NL_ITEM_INDEX (DAY_7
); ++cnt
)
573 iov
[2 + cnt
].iov_base
=
574 (void *) (time
->day
[cnt
- _NL_ITEM_INDEX (DAY_1
)] ?: "");
575 iov
[2 + cnt
].iov_len
= strlen (iov
[2 + cnt
].iov_base
) + 1;
576 idx
[1 + cnt
] = idx
[cnt
] + iov
[2 + cnt
].iov_len
;
580 for (; cnt
<= _NL_ITEM_INDEX (ABMON_12
); ++cnt
)
582 iov
[2 + cnt
].iov_base
=
583 (void *) (time
->abmon
[cnt
- _NL_ITEM_INDEX (ABMON_1
)] ?: "");
584 iov
[2 + cnt
].iov_len
= strlen (iov
[2 + cnt
].iov_base
) + 1;
585 idx
[1 + cnt
] = idx
[cnt
] + iov
[2 + cnt
].iov_len
;
589 for (; cnt
<= _NL_ITEM_INDEX (MON_12
); ++cnt
)
591 iov
[2 + cnt
].iov_base
=
592 (void *) (time
->mon
[cnt
- _NL_ITEM_INDEX (MON_1
)] ?: "");
593 iov
[2 + cnt
].iov_len
= strlen (iov
[2 + cnt
].iov_base
) + 1;
594 idx
[1 + cnt
] = idx
[cnt
] + iov
[2 + cnt
].iov_len
;
598 for (; cnt
<= _NL_ITEM_INDEX (PM_STR
); ++cnt
)
600 iov
[2 + cnt
].iov_base
=
601 (void *) (time
->am_pm
[cnt
- _NL_ITEM_INDEX (AM_STR
)] ?: "");
602 iov
[2 + cnt
].iov_len
= strlen (iov
[2 + cnt
].iov_base
) + 1;
603 idx
[1 + cnt
] = idx
[cnt
] + iov
[2 + cnt
].iov_len
;
606 iov
[2 + cnt
].iov_base
= (void *) (time
->d_t_fmt
?: "");
607 iov
[2 + cnt
].iov_len
= strlen (iov
[2 + cnt
].iov_base
) + 1;
608 idx
[1 + cnt
] = idx
[cnt
] + iov
[2 + cnt
].iov_len
;
611 iov
[2 + cnt
].iov_base
= (void *) (time
->d_fmt
?: "");
612 iov
[2 + cnt
].iov_len
= strlen (iov
[2 + cnt
].iov_base
) + 1;
613 idx
[1 + cnt
] = idx
[cnt
] + iov
[2 + cnt
].iov_len
;
616 iov
[2 + cnt
].iov_base
= (void *) (time
->t_fmt
?: "");
617 iov
[2 + cnt
].iov_len
= strlen (iov
[2 + cnt
].iov_base
) + 1;
618 idx
[1 + cnt
] = idx
[cnt
] + iov
[2 + cnt
].iov_len
;
621 iov
[2 + cnt
].iov_base
= (void *) (time
->t_fmt_ampm
?: "");
622 iov
[2 + cnt
].iov_len
= strlen (iov
[2 + cnt
].iov_base
) + 1;
623 idx
[1 + cnt
] = idx
[cnt
] + iov
[2 + cnt
].iov_len
;
626 idx
[1 + last_idx
] = idx
[last_idx
];
627 for (num
= 0; num
< time
->num_era
; ++num
, ++cnt
)
629 iov
[2 + cnt
].iov_base
= (void *) time
->era
[num
];
630 iov
[2 + cnt
].iov_len
= strlen (iov
[2 + cnt
].iov_base
) + 1;
631 idx
[1 + last_idx
] += iov
[2 + cnt
].iov_len
;
635 iov
[2 + cnt
].iov_base
= (void *) (time
->era_year
?: "");
636 iov
[2 + cnt
].iov_len
= strlen (iov
[2 + cnt
].iov_base
) + 1;
637 idx
[1 + last_idx
] = idx
[last_idx
] + iov
[2 + cnt
].iov_len
;
641 iov
[2 + cnt
].iov_base
= (void *) (time
->era_d_fmt
?: "");
642 iov
[2 + cnt
].iov_len
= strlen (iov
[2 + cnt
].iov_base
) + 1;
643 idx
[1 + last_idx
] = idx
[last_idx
] + iov
[2 + cnt
].iov_len
;
647 idx
[1 + last_idx
] = idx
[last_idx
];
648 for (num
= 0; num
< 100; ++num
, ++cnt
)
650 iov
[2 + cnt
].iov_base
= (void *) (time
->alt_digits
[num
] ?: "");
651 iov
[2 + cnt
].iov_len
= strlen (iov
[2 + cnt
].iov_base
) + 1;
652 idx
[1 + last_idx
] += iov
[2 + cnt
].iov_len
;
656 iov
[2 + cnt
].iov_base
= (void *) (time
->era_d_t_fmt
?: "");
657 iov
[2 + cnt
].iov_len
= strlen (iov
[2 + cnt
].iov_base
) + 1;
658 idx
[1 + last_idx
] = idx
[last_idx
] + iov
[2 + cnt
].iov_len
;
662 iov
[2 + cnt
].iov_base
= (void *) (time
->era_t_fmt
?: "");
663 iov
[2 + cnt
].iov_len
= strlen (iov
[2 + cnt
].iov_base
) + 1;
664 idx
[1 + last_idx
] = idx
[last_idx
] + iov
[2 + cnt
].iov_len
;
669 /* We must align the following data. */
670 iov
[2 + cnt
].iov_base
= (void *) "\0\0";
671 iov
[2 + cnt
].iov_len
= ((idx
[last_idx
] + 3) & ~3) - idx
[last_idx
];
672 idx
[last_idx
] = (idx
[last_idx
] + 3) & ~3;
675 /* The `era' data in usable form. */
676 iov
[2 + cnt
].iov_base
= (void *) &time
->num_era
;
677 iov
[2 + cnt
].iov_len
= sizeof (uint32_t);
678 idx
[1 + last_idx
] = idx
[last_idx
] + iov
[2 + cnt
].iov_len
;
682 idx
[1 + last_idx
] = idx
[last_idx
];
683 for (num
= 0; num
< time
->num_era
; ++num
)
687 iov
[2 + cnt
].iov_base
= (void *) &time
->era_entries
[num
].direction
;
688 iov
[2 + cnt
].iov_len
= sizeof (int32_t);
690 iov
[2 + cnt
].iov_base
= (void *) &time
->era_entries
[num
].offset
;
691 iov
[2 + cnt
].iov_len
= sizeof (int32_t);
693 iov
[2 + cnt
].iov_base
= (void *) &time
->era_entries
[num
].start_date
[0];
694 iov
[2 + cnt
].iov_len
= sizeof (int32_t);
696 iov
[2 + cnt
].iov_base
= (void *) &time
->era_entries
[num
].start_date
[1];
697 iov
[2 + cnt
].iov_len
= sizeof (int32_t);
699 iov
[2 + cnt
].iov_base
= (void *) &time
->era_entries
[num
].start_date
[2];
700 iov
[2 + cnt
].iov_len
= sizeof (int32_t);
702 iov
[2 + cnt
].iov_base
= (void *) &time
->era_entries
[num
].stop_date
[0];
703 iov
[2 + cnt
].iov_len
= sizeof (int32_t);
705 iov
[2 + cnt
].iov_base
= (void *) &time
->era_entries
[num
].stop_date
[1];
706 iov
[2 + cnt
].iov_len
= sizeof (int32_t);
708 iov
[2 + cnt
].iov_base
= (void *) &time
->era_entries
[num
].stop_date
[2];
709 iov
[2 + cnt
].iov_len
= sizeof (int32_t);
712 l
= ((char *) rawmemchr (time
->era_entries
[num
].format
, '\0')
713 - time
->era_entries
[num
].name
) + 1;
715 iov
[2 + cnt
].iov_base
= alloca (l2
);
716 memset (mempcpy (iov
[2 + cnt
].iov_base
, time
->era_entries
[num
].name
, l
),
718 iov
[2 + cnt
].iov_len
= l2
;
721 idx
[1 + last_idx
] += 8 * sizeof (int32_t) + l2
;
723 assert (idx
[1 + last_idx
] % 4 == 0);
725 iov
[2 + cnt
].iov_base
= (void *) time
->era_entries
[num
].wname
;
726 iov
[2 + cnt
].iov_len
= ((wcschr ((wchar_t *) time
->era_entries
[num
].wformat
, L
'\0')
727 - (wchar_t *) time
->era_entries
[num
].wname
+ 1)
728 * sizeof (uint32_t));
729 idx
[1 + last_idx
] += iov
[2 + cnt
].iov_len
;
734 /* The wide character ab'days. */
735 for (n
= 0; n
< 7; ++n
, ++cnt
, ++last_idx
)
737 iov
[2 + cnt
].iov_base
=
738 (void *) (time
->wabday
[n
] ?: empty_wstr
);
739 iov
[2 + cnt
].iov_len
= ((wcslen (iov
[2 + cnt
].iov_base
) + 1)
740 * sizeof (uint32_t));
741 idx
[1 + last_idx
] = idx
[last_idx
] + iov
[2 + cnt
].iov_len
;
744 /* The wide character days. */
745 for (n
= 0; n
< 7; ++n
, ++cnt
, ++last_idx
)
747 iov
[2 + cnt
].iov_base
=
748 (void *) (time
->wday
[n
] ?: empty_wstr
);
749 iov
[2 + cnt
].iov_len
= ((wcslen (iov
[2 + cnt
].iov_base
) + 1)
750 * sizeof (uint32_t));
751 idx
[1 + last_idx
] = idx
[last_idx
] + iov
[2 + cnt
].iov_len
;
754 /* The wide character ab'mons. */
755 for (n
= 0; n
< 12; ++n
, ++cnt
, ++last_idx
)
757 iov
[2 + cnt
].iov_base
=
758 (void *) (time
->wabmon
[n
] ?: empty_wstr
);
759 iov
[2 + cnt
].iov_len
= ((wcslen (iov
[2 + cnt
].iov_base
) + 1)
760 * sizeof (uint32_t));
761 idx
[1 + last_idx
] = idx
[last_idx
] + iov
[2 + cnt
].iov_len
;
764 /* The wide character mons. */
765 for (n
= 0; n
< 12; ++n
, ++cnt
, ++last_idx
)
767 iov
[2 + cnt
].iov_base
=
768 (void *) (time
->wmon
[n
] ?: empty_wstr
);
769 iov
[2 + cnt
].iov_len
= ((wcslen (iov
[2 + cnt
].iov_base
) + 1)
770 * sizeof (uint32_t));
771 idx
[1 + last_idx
] = idx
[last_idx
] + iov
[2 + cnt
].iov_len
;
774 /* Wide character AM/PM. */
775 for (n
= 0; n
< 2; ++n
, ++cnt
, ++last_idx
)
777 iov
[2 + cnt
].iov_base
=
778 (void *) (time
->wam_pm
[n
] ?: empty_wstr
);
779 iov
[2 + cnt
].iov_len
= ((wcslen (iov
[2 + cnt
].iov_base
) + 1)
780 * sizeof (uint32_t));
781 idx
[1 + last_idx
] = idx
[last_idx
] + iov
[2 + cnt
].iov_len
;
784 iov
[2 + cnt
].iov_base
= (void *) (time
->wd_t_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
->wd_fmt
?: 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
->wt_fmt
?: 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
->wt_fmt_ampm
?: 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 iov
[2 + cnt
].iov_base
= (void *) (time
->wera_year
?: empty_wstr
);
813 iov
[2 + cnt
].iov_len
= ((wcslen (iov
[2 + cnt
].iov_base
) + 1)
814 * sizeof (uint32_t));
815 idx
[1 + last_idx
] = idx
[last_idx
] + iov
[2 + cnt
].iov_len
;
819 iov
[2 + cnt
].iov_base
= (void *) (time
->wera_d_fmt
?: empty_wstr
);
820 iov
[2 + cnt
].iov_len
= ((wcslen (iov
[2 + cnt
].iov_base
) + 1)
821 * sizeof (uint32_t));
822 idx
[1 + last_idx
] = idx
[last_idx
] + iov
[2 + cnt
].iov_len
;
826 idx
[1 + last_idx
] = idx
[last_idx
];
827 for (num
= 0; num
< 100; ++num
, ++cnt
)
829 iov
[2 + cnt
].iov_base
= (void *) (time
->walt_digits
[num
]
831 iov
[2 + cnt
].iov_len
= ((wcslen (iov
[2 + cnt
].iov_base
) + 1)
832 * sizeof (uint32_t));
833 idx
[1 + last_idx
] += iov
[2 + cnt
].iov_len
;
837 iov
[2 + cnt
].iov_base
= (void *) (time
->wera_d_t_fmt
?: empty_wstr
);
838 iov
[2 + cnt
].iov_len
= ((wcslen (iov
[2 + cnt
].iov_base
) + 1)
839 * sizeof (uint32_t));
840 idx
[1 + last_idx
] = idx
[last_idx
] + iov
[2 + cnt
].iov_len
;
844 iov
[2 + cnt
].iov_base
= (void *) (time
->wera_t_fmt
?: empty_wstr
);
845 iov
[2 + cnt
].iov_len
= ((wcslen (iov
[2 + cnt
].iov_base
) + 1)
846 * sizeof (uint32_t));
847 idx
[1 + last_idx
] = idx
[last_idx
] + iov
[2 + cnt
].iov_len
;
851 iov
[2 + cnt
].iov_base
= (void *) &time
->week_ndays
;
852 iov
[2 + cnt
].iov_len
= 1;
853 idx
[1 + last_idx
] = idx
[last_idx
] + iov
[2 + cnt
].iov_len
;
857 /* We must align the following data. */
858 iov
[2 + cnt
].iov_base
= (void *) "\0\0";
859 iov
[2 + cnt
].iov_len
= ((idx
[last_idx
] + 3) & ~3) - idx
[last_idx
];
860 idx
[last_idx
] = (idx
[last_idx
] + 3) & ~3;
863 iov
[2 + cnt
].iov_base
= (void *) &time
->week_1stday
;
864 iov
[2 + cnt
].iov_len
= sizeof(uint32_t);
865 idx
[1 + last_idx
] = idx
[last_idx
] + iov
[2 + cnt
].iov_len
;
869 iov
[2 + cnt
].iov_base
= (void *) &time
->week_1stweek
;
870 iov
[2 + cnt
].iov_len
= 1;
871 idx
[1 + last_idx
] = idx
[last_idx
] + iov
[2 + cnt
].iov_len
;
875 iov
[2 + cnt
].iov_base
= (void *) &time
->first_weekday
;
876 iov
[2 + cnt
].iov_len
= 1;
877 idx
[1 + last_idx
] = idx
[last_idx
] + iov
[2 + cnt
].iov_len
;
881 iov
[2 + cnt
].iov_base
= (void *) &time
->first_workday
;
882 iov
[2 + cnt
].iov_len
= 1;
883 idx
[1 + last_idx
] = idx
[last_idx
] + iov
[2 + cnt
].iov_len
;
887 iov
[2 + cnt
].iov_base
= (void *) &time
->cal_direction
;
888 iov
[2 + cnt
].iov_len
= 1;
889 idx
[1 + last_idx
] = idx
[last_idx
] + iov
[2 + cnt
].iov_len
;
893 iov
[2 + cnt
].iov_base
= (void *) time
->timezone
;
894 iov
[2 + cnt
].iov_len
= strlen (time
->timezone
) + 1;
895 idx
[1 + last_idx
] = idx
[last_idx
] + iov
[2 + cnt
].iov_len
;
899 iov
[2 + cnt
].iov_base
= (void *) time
->date_fmt
;
900 iov
[2 + cnt
].iov_len
= strlen (iov
[2 + cnt
].iov_base
) + 1;
901 idx
[1 + last_idx
] = idx
[last_idx
] + iov
[2 + cnt
].iov_len
;
905 /* We must align the following data. */
906 iov
[2 + cnt
].iov_base
= (void *) "\0\0";
907 iov
[2 + cnt
].iov_len
= -idx
[last_idx
] & 3;
908 idx
[last_idx
] += -idx
[last_idx
] & 3;
911 iov
[2 + cnt
].iov_base
= (void *) time
->wdate_fmt
;
912 iov
[2 + cnt
].iov_len
= ((wcslen (iov
[2 + cnt
].iov_base
) + 1)
913 * sizeof (uint32_t));
914 idx
[1 + last_idx
] = idx
[last_idx
] + iov
[2 + cnt
].iov_len
;
918 iov
[2 + cnt
].iov_base
= (void *) charmap
->code_set_name
;
919 iov
[2 + cnt
].iov_len
= strlen (iov
[2 + cnt
].iov_base
) + 1;
923 assert (cnt
== (_NL_ITEM_INDEX (_NL_NUM_LC_TIME
)
926 + 2 + time
->num_era
* 10));
927 assert (last_idx
== _NL_ITEM_INDEX (_NL_NUM_LC_TIME
));
929 write_locale_data (output_path
, LC_TIME
, "LC_TIME", 2 + cnt
, iov
);
933 /* The parser for the LC_TIME section of the locale definition. */
935 time_read (struct linereader
*ldfile
, struct localedef_t
*result
,
936 const struct charmap_t
*charmap
, const char *repertoire_name
,
939 struct repertoire_t
*repertoire
= NULL
;
940 struct locale_time_t
*time
;
945 /* Get the repertoire we have to use. */
946 if (repertoire_name
!= NULL
)
947 repertoire
= repertoire_read (repertoire_name
);
949 /* The rest of the line containing `LC_TIME' must be free. */
950 lr_ignore_rest (ldfile
, 1);
955 now
= lr_token (ldfile
, charmap
, result
, repertoire
, verbose
);
958 while (nowtok
== tok_eol
);
960 /* If we see `copy' now we are almost done. */
961 if (nowtok
== tok_copy
)
963 handle_copy (ldfile
, charmap
, repertoire_name
, result
, tok_lc_time
,
964 LC_TIME
, "LC_TIME", ignore_content
);
968 /* Prepare the data structures. */
969 time_startup (ldfile
, result
, ignore_content
);
970 time
= result
->categories
[LC_TIME
].time
;
974 /* Of course we don't proceed beyond the end of file. */
975 if (nowtok
== tok_eof
)
978 /* Ingore empty lines. */
979 if (nowtok
== tok_eol
)
981 now
= lr_token (ldfile
, charmap
, result
, repertoire
, verbose
);
988 #define STRARR_ELEM(cat, min, max) \
990 /* Ignore the rest of the line if we don't need the input of \
992 if (ignore_content) \
994 lr_ignore_rest (ldfile, 0); \
998 for (cnt = 0; cnt < max; ++cnt) \
1000 now = lr_token (ldfile, charmap, result, repertoire, verbose); \
1001 if (now->tok == tok_eol) \
1004 lr_error (ldfile, _("%s: too few values for field `%s'"), \
1006 if (!ignore_content) \
1009 time->cat[cnt] = ""; \
1010 time->w##cat[cnt] = empty_wstr; \
1012 while (++cnt < max); \
1015 else if (now->tok != tok_string) \
1017 else if (!ignore_content && (now->val.str.startmb == NULL \
1018 || now->val.str.startwc == NULL)) \
1020 lr_error (ldfile, _("%s: unknown character in field `%s'"), \
1022 time->cat[cnt] = ""; \
1023 time->w##cat[cnt] = empty_wstr; \
1025 else if (!ignore_content) \
1027 time->cat[cnt] = now->val.str.startmb; \
1028 time->w##cat[cnt] = now->val.str.startwc; \
1031 /* Match the semicolon. */ \
1032 now = lr_token (ldfile, charmap, result, repertoire, verbose); \
1033 if (now->tok != tok_semicolon && now->tok != tok_eol) \
1036 if (now->tok != tok_eol) \
1038 while (!ignore_content && cnt < min) \
1040 time->cat[cnt] = ""; \
1041 time->w##cat[cnt++] = empty_wstr; \
1044 if (now->tok == tok_semicolon) \
1046 now = lr_token (ldfile, charmap, result, repertoire, \
1048 if (now->tok == tok_eol) \
1049 lr_error (ldfile, _("extra trailing semicolon")); \
1050 else if (now->tok == tok_string) \
1052 lr_error (ldfile, _("\
1053 %s: too many values for field `%s'"), \
1055 lr_ignore_rest (ldfile, 0); \
1063 time->cat##_defined = 1; \
1066 STRARR_ELEM (abday
, 7, 7);
1067 STRARR_ELEM (day
, 7, 7);
1068 STRARR_ELEM (abmon
, 12, 12);
1069 STRARR_ELEM (mon
, 12, 12);
1070 STRARR_ELEM (am_pm
, 2, 2);
1071 STRARR_ELEM (alt_digits
, 0, 100);
1074 /* Ignore the rest of the line if we don't need the input of
1078 lr_ignore_rest (ldfile
, 0);
1083 now
= lr_token (ldfile
, charmap
, result
, repertoire
, verbose
);
1084 if (now
->tok
!= tok_string
)
1086 if (!ignore_content
&& (now
->val
.str
.startmb
== NULL
1087 || now
->val
.str
.startwc
== NULL
))
1089 lr_error (ldfile
, _("%s: unknown character in field `%s'"),
1091 lr_ignore_rest (ldfile
, 0);
1094 if (!ignore_content
)
1096 time
->era
= xrealloc (time
->era
,
1097 (time
->num_era
+ 1) * sizeof (char *));
1098 time
->era
[time
->num_era
] = now
->val
.str
.startmb
;
1100 time
->wera
= xrealloc (time
->wera
,
1103 time
->wera
[time
->num_era
++] = now
->val
.str
.startwc
;
1105 now
= lr_token (ldfile
, charmap
, result
, repertoire
, verbose
);
1106 if (now
->tok
!= tok_eol
&& now
->tok
!= tok_semicolon
)
1109 while (now
->tok
== tok_semicolon
);
1112 #define STR_ELEM(cat) \
1114 /* Ignore the rest of the line if we don't need the input of \
1116 if (ignore_content) \
1118 lr_ignore_rest (ldfile, 0); \
1122 now = lr_token (ldfile, charmap, result, repertoire, verbose); \
1123 if (now->tok != tok_string) \
1125 else if (time->cat != NULL) \
1126 lr_error (ldfile, _("\
1127 %s: field `%s' declared more than once"), "LC_TIME", #cat); \
1128 else if (!ignore_content && (now->val.str.startmb == NULL \
1129 || now->val.str.startwc == NULL)) \
1131 lr_error (ldfile, _("%s: unknown character in field `%s'"), \
1134 time->w##cat = empty_wstr; \
1136 else if (!ignore_content) \
1138 time->cat = now->val.str.startmb; \
1139 time->w##cat = now->val.str.startwc; \
1146 STR_ELEM (t_fmt_ampm
);
1147 STR_ELEM (era_year
);
1148 STR_ELEM (era_d_t_fmt
);
1149 STR_ELEM (era_d_fmt
);
1150 STR_ELEM (era_t_fmt
);
1151 STR_ELEM (timezone
);
1152 STR_ELEM (date_fmt
);
1154 #define INT_ELEM(cat) \
1156 /* Ignore the rest of the line if we don't need the input of \
1158 if (ignore_content) \
1160 lr_ignore_rest (ldfile, 0); \
1164 now = lr_token (ldfile, charmap, result, repertoire, verbose); \
1165 if (now->tok != tok_number) \
1167 else if (time->cat != 0) \
1168 lr_error (ldfile, _("%s: field `%s' declared more than once"), \
1170 else if (!ignore_content) \
1171 time->cat = now->val.num; \
1174 INT_ELEM (first_weekday
);
1175 INT_ELEM (first_workday
);
1176 INT_ELEM (cal_direction
);
1179 /* Ignore the rest of the line if we don't need the input of
1183 lr_ignore_rest (ldfile
, 0);
1187 now
= lr_token (ldfile
, charmap
, result
, repertoire
, verbose
);
1188 if (now
->tok
!= tok_number
)
1190 time
->week_ndays
= now
->val
.num
;
1192 now
= lr_token (ldfile
, charmap
, result
, repertoire
, verbose
);
1193 if (now
->tok
!= tok_semicolon
)
1196 now
= lr_token (ldfile
, charmap
, result
, repertoire
, verbose
);
1197 if (now
->tok
!= tok_number
)
1199 time
->week_1stday
= now
->val
.num
;
1201 now
= lr_token (ldfile
, charmap
, result
, repertoire
, verbose
);
1202 if (now
->tok
!= tok_semicolon
)
1205 now
= lr_token (ldfile
, charmap
, result
, repertoire
, verbose
);
1206 if (now
->tok
!= tok_number
)
1208 time
->week_1stweek
= now
->val
.num
;
1210 lr_ignore_rest (ldfile
, 1);
1214 /* Next we assume `LC_TIME'. */
1215 now
= lr_token (ldfile
, charmap
, result
, repertoire
, verbose
);
1216 if (now
->tok
== tok_eof
)
1218 if (now
->tok
== tok_eol
)
1219 lr_error (ldfile
, _("%s: incomplete `END' line"), "LC_TIME");
1220 else if (now
->tok
!= tok_lc_time
)
1221 lr_error (ldfile
, _("\
1222 %1$s: definition does not end with `END %1$s'"), "LC_TIME");
1223 lr_ignore_rest (ldfile
, now
->tok
== tok_lc_time
);
1228 SYNTAX_ERROR (_("%s: syntax error"), "LC_TIME");
1231 /* Prepare for the next round. */
1232 now
= lr_token (ldfile
, charmap
, result
, repertoire
, verbose
);
1236 /* When we come here we reached the end of the file. */
1237 lr_error (ldfile
, _("%s: premature end of file"), "LC_TIME");