1 /* Copyright (C) 1995-2005, 2006 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 version 2 as
7 published by the Free Software Foundation.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software Foundation,
16 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
31 #include "localedef.h"
32 #include "linereader.h"
33 #include "localeinfo.h"
37 /* Entry describing an entry of the era specification. */
42 int32_t start_date
[3];
51 /* The real definition of the struct for the LC_TIME locale. */
55 const uint32_t *wabday
[7];
58 const uint32_t *wday
[7];
60 const char *abmon
[12];
61 const uint32_t *wabmon
[12];
64 const uint32_t *wmon
[12];
67 const uint32_t *wam_pm
[2];
70 const uint32_t *wd_t_fmt
;
72 const uint32_t *wd_fmt
;
74 const uint32_t *wt_fmt
;
75 const char *t_fmt_ampm
;
76 const uint32_t *wt_fmt_ampm
;
78 const uint32_t **wera
;
81 const uint32_t *wera_year
;
82 const char *era_d_t_fmt
;
83 const uint32_t *wera_d_t_fmt
;
84 const char *era_t_fmt
;
85 const uint32_t *wera_t_fmt
;
86 const char *era_d_fmt
;
87 const uint32_t *wera_d_fmt
;
88 const char *alt_digits
[100];
89 const uint32_t *walt_digits
[100];
91 const uint32_t *wdate_fmt
;
92 int alt_digits_defined
;
93 unsigned char week_ndays
;
95 unsigned char week_1stweek
;
96 unsigned char first_weekday
;
97 unsigned char first_workday
;
98 unsigned char cal_direction
;
100 const uint32_t *wtimezone
;
102 struct era_data
*era_entries
;
106 /* This constant is used to represent an empty wide character string. */
107 static const uint32_t empty_wstr
[1] = { 0 };
111 time_startup (struct linereader
*lr
, struct localedef_t
*locale
,
115 locale
->categories
[LC_TIME
].time
=
116 (struct locale_time_t
*) xcalloc (1, sizeof (struct locale_time_t
));
120 lr
->translate_strings
= 1;
121 lr
->return_widestr
= 1;
127 time_finish (struct localedef_t
*locale
, const struct charmap_t
*charmap
)
129 struct locale_time_t
*time
= locale
->categories
[LC_TIME
].time
;
132 /* Now resolve copying and also handle completely missing definitions. */
135 /* First see whether we were supposed to copy. If yes, find the
136 actual definition. */
137 if (locale
->copy_name
[LC_TIME
] != NULL
)
139 /* Find the copying locale. This has to happen transitively since
140 the locale we are copying from might also copying another one. */
141 struct localedef_t
*from
= locale
;
144 from
= find_locale (LC_TIME
, from
->copy_name
[LC_TIME
],
145 from
->repertoire_name
, charmap
);
146 while (from
->categories
[LC_TIME
].time
== NULL
147 && from
->copy_name
[LC_TIME
] != NULL
);
149 time
= locale
->categories
[LC_TIME
].time
150 = from
->categories
[LC_TIME
].time
;
153 /* If there is still no definition issue an warning and create an
158 WITH_CUR_LOCALE (error (0, 0, _("\
159 No definition for %s category found"), "LC_TIME"));
160 time_startup (NULL
, locale
, 0);
161 time
= locale
->categories
[LC_TIME
].time
;
166 #define noparen(arg1, argn...) arg1, ##argn
167 #define TESTARR_ELEM(cat, val) \
168 if (!time->cat##_defined) \
170 const char *initval[] = { noparen val }; \
173 if (! be_quiet && ! nothing) \
174 WITH_CUR_LOCALE (error (0, 0, _("%s: field `%s' not defined"), \
177 for (i = 0; i < sizeof (initval) / sizeof (initval[0]); ++i) \
178 time->cat[i] = initval[i]; \
181 TESTARR_ELEM (abday
, ( "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" ));
182 TESTARR_ELEM (day
, ( "Sunday", "Monday", "Tuesday", "Wednesday",
183 "Thursday", "Friday", "Saturday" ));
184 TESTARR_ELEM (abmon
, ( "Jan", "Feb", "Mar", "Apr", "May", "Jun",
185 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" ));
186 TESTARR_ELEM (mon
, ( "January", "February", "March", "April",
187 "May", "June", "July", "August",
188 "September", "October", "November", "December" ));
189 TESTARR_ELEM (am_pm
, ( "AM", "PM" ));
191 #define TEST_ELEM(cat, initval) \
192 if (time->cat == NULL) \
194 if (! be_quiet && ! nothing) \
195 WITH_CUR_LOCALE (error (0, 0, _("%s: field `%s' not defined"), \
198 time->cat = initval; \
201 TEST_ELEM (d_t_fmt
, "%a %b %e %H:%M:%S %Y");
202 TEST_ELEM (d_fmt
, "%m/%d/%y");
203 TEST_ELEM (t_fmt
, "%H:%M:%S");
205 /* According to C.Y.Alexis Cheng <alexis@vnet.ibm.com> the T_FMT_AMPM
206 field is optional. */
207 if (time
->t_fmt_ampm
== NULL
)
209 if (time
->am_pm
[0][0] == '\0' && time
->am_pm
[1][0] == '\0')
211 /* No AM/PM strings defined, use the 24h format as default. */
212 time
->t_fmt_ampm
= time
->t_fmt
;
213 time
->wt_fmt_ampm
= time
->wt_fmt
;
217 time
->t_fmt_ampm
= "%I:%M:%S %p";
218 time
->wt_fmt_ampm
= (const uint32_t *) L
"%I:%M:%S %p";
222 /* Now process the era entries. */
223 if (time
->num_era
!= 0)
225 const int days_per_month
[12] = { 31, 29, 31, 30, 31, 30,
226 31, 31, 30, 31 ,30, 31 };
231 (struct era_data
*) xmalloc (time
->num_era
232 * sizeof (struct era_data
));
234 for (idx
= 0; idx
< time
->num_era
; ++idx
)
236 size_t era_len
= strlen (time
->era
[idx
]);
237 char *str
= xmalloc ((era_len
+ 1 + 3) & ~3);
240 memcpy (str
, time
->era
[idx
], era_len
+ 1);
242 /* First character must be + or - for the direction. */
243 if (*str
!= '+' && *str
!= '-')
246 WITH_CUR_LOCALE (error (0, 0, _("\
247 %s: direction flag in string %Zd in `era' field is not '+' nor '-'"),
248 "LC_TIME", idx
+ 1));
249 /* Default arbitrarily to '+'. */
250 time
->era_entries
[idx
].direction
= '+';
253 time
->era_entries
[idx
].direction
= *str
;
257 WITH_CUR_LOCALE (error (0, 0, _("\
258 %s: direction flag in string %Zd in `era' field is not a single character"),
259 "LC_TIME", idx
+ 1));
260 (void) strsep (&str
, ":");
265 /* Now the offset year. */
266 time
->era_entries
[idx
].offset
= strtol (str
, &endp
, 10);
270 WITH_CUR_LOCALE (error (0, 0, _("\
271 %s: invalid number for offset in string %Zd in `era' field"),
272 "LC_TIME", idx
+ 1));
273 (void) strsep (&str
, ":");
275 else if (*endp
!= ':')
278 WITH_CUR_LOCALE (error (0, 0, _("\
279 %s: garbage at end of offset value in string %Zd in `era' field"),
280 "LC_TIME", idx
+ 1));
281 (void) strsep (&str
, ":");
286 /* Next is the starting date in ISO format. */
287 if (strncmp (str
, "-*", 2) == 0)
289 time
->era_entries
[idx
].start_date
[0] =
290 time
->era_entries
[idx
].start_date
[1] =
291 time
->era_entries
[idx
].start_date
[2] = 0x80000000;
293 goto garbage_start_date
;
296 else if (strncmp (str
, "+*", 2) == 0)
298 time
->era_entries
[idx
].start_date
[0] =
299 time
->era_entries
[idx
].start_date
[1] =
300 time
->era_entries
[idx
].start_date
[2] = 0x7fffffff;
302 goto garbage_start_date
;
307 time
->era_entries
[idx
].start_date
[0] = strtol (str
, &endp
, 10);
308 if (endp
== str
|| *endp
!= '/')
309 goto invalid_start_date
;
312 time
->era_entries
[idx
].start_date
[0] -= 1900;
313 /* year -1 represent 1 B.C. (not -1 A.D.) */
314 if (time
->era_entries
[idx
].start_date
[0] < -1900)
315 ++time
->era_entries
[idx
].start_date
[0];
317 time
->era_entries
[idx
].start_date
[1] = strtol (str
, &endp
, 10);
318 if (endp
== str
|| *endp
!= '/')
319 goto invalid_start_date
;
322 time
->era_entries
[idx
].start_date
[1] -= 1;
324 time
->era_entries
[idx
].start_date
[2] = strtol (str
, &endp
, 10);
329 WITH_CUR_LOCALE (error (0, 0, _("\
330 %s: invalid starting date in string %Zd in `era' field"),
331 "LC_TIME", idx
+ 1));
332 (void) strsep (&str
, ":");
334 else if (*endp
!= ':')
338 WITH_CUR_LOCALE (error (0, 0, _("\
339 %s: garbage at end of starting date in string %Zd in `era' field "),
340 "LC_TIME", idx
+ 1));
341 (void) strsep (&str
, ":");
347 /* Check for valid value. */
348 if ((time
->era_entries
[idx
].start_date
[1] < 0
349 || time
->era_entries
[idx
].start_date
[1] >= 12
350 || time
->era_entries
[idx
].start_date
[2] < 0
351 || (time
->era_entries
[idx
].start_date
[2]
352 > days_per_month
[time
->era_entries
[idx
].start_date
[1]])
353 || (time
->era_entries
[idx
].start_date
[1] == 2
354 && time
->era_entries
[idx
].start_date
[2] == 29
355 && !__isleap (time
->era_entries
[idx
].start_date
[0])))
357 WITH_CUR_LOCALE (error (0, 0, _("\
358 %s: starting date is invalid in string %Zd in `era' field"),
359 "LC_TIME", idx
+ 1));
363 /* Next is the stopping date in ISO format. */
364 if (strncmp (str
, "-*", 2) == 0)
366 time
->era_entries
[idx
].stop_date
[0] =
367 time
->era_entries
[idx
].stop_date
[1] =
368 time
->era_entries
[idx
].stop_date
[2] = 0x80000000;
370 goto garbage_stop_date
;
373 else if (strncmp (str
, "+*", 2) == 0)
375 time
->era_entries
[idx
].stop_date
[0] =
376 time
->era_entries
[idx
].stop_date
[1] =
377 time
->era_entries
[idx
].stop_date
[2] = 0x7fffffff;
379 goto garbage_stop_date
;
384 time
->era_entries
[idx
].stop_date
[0] = strtol (str
, &endp
, 10);
385 if (endp
== str
|| *endp
!= '/')
386 goto invalid_stop_date
;
389 time
->era_entries
[idx
].stop_date
[0] -= 1900;
390 /* year -1 represent 1 B.C. (not -1 A.D.) */
391 if (time
->era_entries
[idx
].stop_date
[0] < -1900)
392 ++time
->era_entries
[idx
].stop_date
[0];
394 time
->era_entries
[idx
].stop_date
[1] = strtol (str
, &endp
, 10);
395 if (endp
== str
|| *endp
!= '/')
396 goto invalid_stop_date
;
399 time
->era_entries
[idx
].stop_date
[1] -= 1;
401 time
->era_entries
[idx
].stop_date
[2] = strtol (str
, &endp
, 10);
406 WITH_CUR_LOCALE (error (0, 0, _("\
407 %s: invalid stopping date in string %Zd in `era' field"),
408 "LC_TIME", idx
+ 1));
409 (void) strsep (&str
, ":");
411 else if (*endp
!= ':')
415 WITH_CUR_LOCALE (error (0, 0, _("\
416 %s: garbage at end of stopping date in string %Zd in `era' field"),
417 "LC_TIME", idx
+ 1));
418 (void) strsep (&str
, ":");
424 /* Check for valid value. */
425 if ((time
->era_entries
[idx
].stop_date
[1] < 0
426 || time
->era_entries
[idx
].stop_date
[1] >= 12
427 || time
->era_entries
[idx
].stop_date
[2] < 0
428 || (time
->era_entries
[idx
].stop_date
[2]
429 > days_per_month
[time
->era_entries
[idx
].stop_date
[1]])
430 || (time
->era_entries
[idx
].stop_date
[1] == 2
431 && time
->era_entries
[idx
].stop_date
[2] == 29
432 && !__isleap (time
->era_entries
[idx
].stop_date
[0])))
434 WITH_CUR_LOCALE (error (0, 0, _("\
435 %s: stopping date is invalid in string %Zd in `era' field"),
436 "LC_TIME", idx
+ 1));
440 if (str
== NULL
|| *str
== '\0')
443 WITH_CUR_LOCALE (error (0, 0, _("\
444 %s: missing era name in string %Zd in `era' field"), "LC_TIME", idx
+ 1));
445 time
->era_entries
[idx
].name
=
446 time
->era_entries
[idx
].format
= "";
450 time
->era_entries
[idx
].name
= strsep (&str
, ":");
452 if (str
== NULL
|| *str
== '\0')
455 WITH_CUR_LOCALE (error (0, 0, _("\
456 %s: missing era format in string %Zd in `era' field"),
457 "LC_TIME", idx
+ 1));
458 time
->era_entries
[idx
].name
=
459 time
->era_entries
[idx
].format
= "";
462 time
->era_entries
[idx
].format
= str
;
465 /* Now generate the wide character name and format. */
466 wstr
= wcschr ((wchar_t *) time
->wera
[idx
], L
':');/* end direction */
467 wstr
= wstr
? wcschr (wstr
+ 1, L
':') : NULL
; /* end offset */
468 wstr
= wstr
? wcschr (wstr
+ 1, L
':') : NULL
; /* end start */
469 wstr
= wstr
? wcschr (wstr
+ 1, L
':') : NULL
; /* end end */
470 time
->era_entries
[idx
].wname
= (uint32_t *) wstr
+ 1;
473 wstr
= wcschr (wstr
+ 1, L
':'); /* end name */
475 time
->era_entries
[idx
].wformat
= (uint32_t *) wstr
+ 1;
478 time
->era_entries
[idx
].wformat
= NULL
;
482 if (time
->week_ndays
== 0)
483 time
->week_ndays
= 7;
485 if (time
->week_1stday
== 0)
486 time
->week_1stday
= 19971130;
488 if (time
->week_1stweek
> time
->week_ndays
)
489 WITH_CUR_LOCALE (error (0, 0, _("\
490 %s: third operand for value of field `%s' must not be larger than %d"),
491 "LC_TIME", "week", 7));
493 if (time
->first_weekday
== '\0')
494 /* The definition does not specify this so the default is used. */
495 time
->first_weekday
= 1;
496 else if (time
->first_weekday
> time
->week_ndays
)
497 WITH_CUR_LOCALE (error (0, 0, _("\
498 %s: values of field `%s' must not be larger than %d"),
499 "LC_TIME", "first_weekday", 7));
501 if (time
->first_workday
== '\0')
502 /* The definition does not specify this so the default is used. */
503 time
->first_workday
= 1;
504 else if (time
->first_workday
> time
->week_ndays
)
505 WITH_CUR_LOCALE (error (0, 0, _("\
506 %s: values of field `%s' must not be larger than %d"),
507 "LC_TIME", "first_workday", 7));
509 if (time
->cal_direction
== '\0')
510 /* The definition does not specify this so the default is used. */
511 time
->cal_direction
= 1;
512 else if (time
->cal_direction
> 3)
513 WITH_CUR_LOCALE (error (0, 0, _("\
514 %s: values for field `%s' must not be larger than %d"),
515 "LC_TIME", "cal_direction", 3));
517 /* XXX We don't perform any tests on the timezone value since this is
518 simply useless, stupid $&$!@... */
519 if (time
->timezone
== NULL
)
522 if (time
->date_fmt
== NULL
)
523 time
->date_fmt
= "%a %b %e %H:%M:%S %Z %Y";
524 if (time
->wdate_fmt
== NULL
)
525 time
->wdate_fmt
= (const uint32_t *) L
"%a %b %e %H:%M:%S %Z %Y";
530 time_output (struct localedef_t
*locale
, const struct charmap_t
*charmap
,
531 const char *output_path
)
533 struct locale_time_t
*time
= locale
->categories
[LC_TIME
].time
;
534 struct iovec
*iov
= alloca (sizeof *iov
535 * (2 + _NL_ITEM_INDEX (_NL_NUM_LC_TIME
)
538 + 2 + time
->num_era
* 10 - 1));
539 struct locale_file data
;
540 uint32_t idx
[_NL_ITEM_INDEX (_NL_NUM_LC_TIME
)];
541 size_t cnt
, last_idx
, num
, n
;
543 data
.magic
= LIMAGIC (LC_TIME
);
544 data
.n
= _NL_ITEM_INDEX (_NL_NUM_LC_TIME
);
545 iov
[0].iov_base
= (void *) &data
;
546 iov
[0].iov_len
= sizeof (data
);
548 iov
[1].iov_base
= (void *) idx
;
549 iov
[1].iov_len
= sizeof (idx
);
551 idx
[0] = iov
[0].iov_len
+ iov
[1].iov_len
;
554 for (cnt
= 0; cnt
<= _NL_ITEM_INDEX (ABDAY_7
); ++cnt
)
556 iov
[2 + cnt
].iov_base
=
557 (void *) (time
->abday
[cnt
- _NL_ITEM_INDEX (ABDAY_1
)] ?: "");
558 iov
[2 + cnt
].iov_len
= strlen (iov
[2 + cnt
].iov_base
) + 1;
559 idx
[1 + cnt
] = idx
[cnt
] + iov
[2 + cnt
].iov_len
;
563 for (; cnt
<= _NL_ITEM_INDEX (DAY_7
); ++cnt
)
565 iov
[2 + cnt
].iov_base
=
566 (void *) (time
->day
[cnt
- _NL_ITEM_INDEX (DAY_1
)] ?: "");
567 iov
[2 + cnt
].iov_len
= strlen (iov
[2 + cnt
].iov_base
) + 1;
568 idx
[1 + cnt
] = idx
[cnt
] + iov
[2 + cnt
].iov_len
;
572 for (; cnt
<= _NL_ITEM_INDEX (ABMON_12
); ++cnt
)
574 iov
[2 + cnt
].iov_base
=
575 (void *) (time
->abmon
[cnt
- _NL_ITEM_INDEX (ABMON_1
)] ?: "");
576 iov
[2 + cnt
].iov_len
= strlen (iov
[2 + cnt
].iov_base
) + 1;
577 idx
[1 + cnt
] = idx
[cnt
] + iov
[2 + cnt
].iov_len
;
581 for (; cnt
<= _NL_ITEM_INDEX (MON_12
); ++cnt
)
583 iov
[2 + cnt
].iov_base
=
584 (void *) (time
->mon
[cnt
- _NL_ITEM_INDEX (MON_1
)] ?: "");
585 iov
[2 + cnt
].iov_len
= strlen (iov
[2 + cnt
].iov_base
) + 1;
586 idx
[1 + cnt
] = idx
[cnt
] + iov
[2 + cnt
].iov_len
;
590 for (; cnt
<= _NL_ITEM_INDEX (PM_STR
); ++cnt
)
592 iov
[2 + cnt
].iov_base
=
593 (void *) (time
->am_pm
[cnt
- _NL_ITEM_INDEX (AM_STR
)] ?: "");
594 iov
[2 + cnt
].iov_len
= strlen (iov
[2 + cnt
].iov_base
) + 1;
595 idx
[1 + cnt
] = idx
[cnt
] + iov
[2 + cnt
].iov_len
;
598 iov
[2 + cnt
].iov_base
= (void *) (time
->d_t_fmt
?: "");
599 iov
[2 + cnt
].iov_len
= strlen (iov
[2 + cnt
].iov_base
) + 1;
600 idx
[1 + cnt
] = idx
[cnt
] + iov
[2 + cnt
].iov_len
;
603 iov
[2 + cnt
].iov_base
= (void *) (time
->d_fmt
?: "");
604 iov
[2 + cnt
].iov_len
= strlen (iov
[2 + cnt
].iov_base
) + 1;
605 idx
[1 + cnt
] = idx
[cnt
] + iov
[2 + cnt
].iov_len
;
608 iov
[2 + cnt
].iov_base
= (void *) (time
->t_fmt
?: "");
609 iov
[2 + cnt
].iov_len
= strlen (iov
[2 + cnt
].iov_base
) + 1;
610 idx
[1 + cnt
] = idx
[cnt
] + iov
[2 + cnt
].iov_len
;
613 iov
[2 + cnt
].iov_base
= (void *) (time
->t_fmt_ampm
?: "");
614 iov
[2 + cnt
].iov_len
= strlen (iov
[2 + cnt
].iov_base
) + 1;
615 idx
[1 + cnt
] = idx
[cnt
] + iov
[2 + cnt
].iov_len
;
618 idx
[1 + last_idx
] = idx
[last_idx
];
619 for (num
= 0; num
< time
->num_era
; ++num
, ++cnt
)
621 iov
[2 + cnt
].iov_base
= (void *) time
->era
[num
];
622 iov
[2 + cnt
].iov_len
= strlen (iov
[2 + cnt
].iov_base
) + 1;
623 idx
[1 + last_idx
] += iov
[2 + cnt
].iov_len
;
627 iov
[2 + cnt
].iov_base
= (void *) (time
->era_year
?: "");
628 iov
[2 + cnt
].iov_len
= strlen (iov
[2 + cnt
].iov_base
) + 1;
629 idx
[1 + last_idx
] = idx
[last_idx
] + iov
[2 + cnt
].iov_len
;
633 iov
[2 + cnt
].iov_base
= (void *) (time
->era_d_fmt
?: "");
634 iov
[2 + cnt
].iov_len
= strlen (iov
[2 + cnt
].iov_base
) + 1;
635 idx
[1 + last_idx
] = idx
[last_idx
] + iov
[2 + cnt
].iov_len
;
639 idx
[1 + last_idx
] = idx
[last_idx
];
640 for (num
= 0; num
< 100; ++num
, ++cnt
)
642 iov
[2 + cnt
].iov_base
= (void *) (time
->alt_digits
[num
] ?: "");
643 iov
[2 + cnt
].iov_len
= strlen (iov
[2 + cnt
].iov_base
) + 1;
644 idx
[1 + last_idx
] += iov
[2 + cnt
].iov_len
;
648 iov
[2 + cnt
].iov_base
= (void *) (time
->era_d_t_fmt
?: "");
649 iov
[2 + cnt
].iov_len
= strlen (iov
[2 + cnt
].iov_base
) + 1;
650 idx
[1 + last_idx
] = idx
[last_idx
] + iov
[2 + cnt
].iov_len
;
654 iov
[2 + cnt
].iov_base
= (void *) (time
->era_t_fmt
?: "");
655 iov
[2 + cnt
].iov_len
= strlen (iov
[2 + cnt
].iov_base
) + 1;
656 idx
[1 + last_idx
] = idx
[last_idx
] + iov
[2 + cnt
].iov_len
;
661 /* We must align the following data. */
662 iov
[2 + cnt
].iov_base
= (void *) "\0\0";
663 iov
[2 + cnt
].iov_len
= ((idx
[last_idx
] + 3) & ~3) - idx
[last_idx
];
664 idx
[last_idx
] = (idx
[last_idx
] + 3) & ~3;
667 /* The `era' data in usable form. */
668 iov
[2 + cnt
].iov_base
= (void *) &time
->num_era
;
669 iov
[2 + cnt
].iov_len
= sizeof (uint32_t);
670 idx
[1 + last_idx
] = idx
[last_idx
] + iov
[2 + cnt
].iov_len
;
674 idx
[1 + last_idx
] = idx
[last_idx
];
675 for (num
= 0; num
< time
->num_era
; ++num
)
679 iov
[2 + cnt
].iov_base
= (void *) &time
->era_entries
[num
].direction
;
680 iov
[2 + cnt
].iov_len
= sizeof (int32_t);
682 iov
[2 + cnt
].iov_base
= (void *) &time
->era_entries
[num
].offset
;
683 iov
[2 + cnt
].iov_len
= sizeof (int32_t);
685 iov
[2 + cnt
].iov_base
= (void *) &time
->era_entries
[num
].start_date
[0];
686 iov
[2 + cnt
].iov_len
= sizeof (int32_t);
688 iov
[2 + cnt
].iov_base
= (void *) &time
->era_entries
[num
].start_date
[1];
689 iov
[2 + cnt
].iov_len
= sizeof (int32_t);
691 iov
[2 + cnt
].iov_base
= (void *) &time
->era_entries
[num
].start_date
[2];
692 iov
[2 + cnt
].iov_len
= sizeof (int32_t);
694 iov
[2 + cnt
].iov_base
= (void *) &time
->era_entries
[num
].stop_date
[0];
695 iov
[2 + cnt
].iov_len
= sizeof (int32_t);
697 iov
[2 + cnt
].iov_base
= (void *) &time
->era_entries
[num
].stop_date
[1];
698 iov
[2 + cnt
].iov_len
= sizeof (int32_t);
700 iov
[2 + cnt
].iov_base
= (void *) &time
->era_entries
[num
].stop_date
[2];
701 iov
[2 + cnt
].iov_len
= sizeof (int32_t);
704 l
= ((char *) rawmemchr (time
->era_entries
[num
].format
, '\0')
705 - time
->era_entries
[num
].name
) + 1;
707 iov
[2 + cnt
].iov_base
= alloca (l2
);
708 memset (mempcpy (iov
[2 + cnt
].iov_base
, time
->era_entries
[num
].name
, l
),
710 iov
[2 + cnt
].iov_len
= l2
;
713 idx
[1 + last_idx
] += 8 * sizeof (int32_t) + l2
;
715 assert (idx
[1 + last_idx
] % 4 == 0);
717 iov
[2 + cnt
].iov_base
= (void *) time
->era_entries
[num
].wname
;
718 iov
[2 + cnt
].iov_len
= ((wcschr ((wchar_t *) time
->era_entries
[num
].wformat
, L
'\0')
719 - (wchar_t *) time
->era_entries
[num
].wname
+ 1)
720 * sizeof (uint32_t));
721 idx
[1 + last_idx
] += iov
[2 + cnt
].iov_len
;
726 /* The wide character ab'days. */
727 for (n
= 0; n
< 7; ++n
, ++cnt
, ++last_idx
)
729 iov
[2 + cnt
].iov_base
=
730 (void *) (time
->wabday
[n
] ?: empty_wstr
);
731 iov
[2 + cnt
].iov_len
= ((wcslen (iov
[2 + cnt
].iov_base
) + 1)
732 * sizeof (uint32_t));
733 idx
[1 + last_idx
] = idx
[last_idx
] + iov
[2 + cnt
].iov_len
;
736 /* The wide character days. */
737 for (n
= 0; n
< 7; ++n
, ++cnt
, ++last_idx
)
739 iov
[2 + cnt
].iov_base
=
740 (void *) (time
->wday
[n
] ?: empty_wstr
);
741 iov
[2 + cnt
].iov_len
= ((wcslen (iov
[2 + cnt
].iov_base
) + 1)
742 * sizeof (uint32_t));
743 idx
[1 + last_idx
] = idx
[last_idx
] + iov
[2 + cnt
].iov_len
;
746 /* The wide character ab'mons. */
747 for (n
= 0; n
< 12; ++n
, ++cnt
, ++last_idx
)
749 iov
[2 + cnt
].iov_base
=
750 (void *) (time
->wabmon
[n
] ?: empty_wstr
);
751 iov
[2 + cnt
].iov_len
= ((wcslen (iov
[2 + cnt
].iov_base
) + 1)
752 * sizeof (uint32_t));
753 idx
[1 + last_idx
] = idx
[last_idx
] + iov
[2 + cnt
].iov_len
;
756 /* The wide character mons. */
757 for (n
= 0; n
< 12; ++n
, ++cnt
, ++last_idx
)
759 iov
[2 + cnt
].iov_base
=
760 (void *) (time
->wmon
[n
] ?: empty_wstr
);
761 iov
[2 + cnt
].iov_len
= ((wcslen (iov
[2 + cnt
].iov_base
) + 1)
762 * sizeof (uint32_t));
763 idx
[1 + last_idx
] = idx
[last_idx
] + iov
[2 + cnt
].iov_len
;
766 /* Wide character AM/PM. */
767 for (n
= 0; n
< 2; ++n
, ++cnt
, ++last_idx
)
769 iov
[2 + cnt
].iov_base
=
770 (void *) (time
->wam_pm
[n
] ?: 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
;
776 iov
[2 + cnt
].iov_base
= (void *) (time
->wd_t_fmt
?: empty_wstr
);
777 iov
[2 + cnt
].iov_len
= ((wcslen (iov
[2 + cnt
].iov_base
) + 1)
778 * sizeof (uint32_t));
779 idx
[1 + last_idx
] = idx
[last_idx
] + iov
[2 + cnt
].iov_len
;
783 iov
[2 + cnt
].iov_base
= (void *) (time
->wd_fmt
?: empty_wstr
);
784 iov
[2 + cnt
].iov_len
= ((wcslen (iov
[2 + cnt
].iov_base
) + 1)
785 * sizeof (uint32_t));
786 idx
[1 + last_idx
] = idx
[last_idx
] + iov
[2 + cnt
].iov_len
;
790 iov
[2 + cnt
].iov_base
= (void *) (time
->wt_fmt
?: empty_wstr
);
791 iov
[2 + cnt
].iov_len
= ((wcslen (iov
[2 + cnt
].iov_base
) + 1)
792 * sizeof (uint32_t));
793 idx
[1 + last_idx
] = idx
[last_idx
] + iov
[2 + cnt
].iov_len
;
797 iov
[2 + cnt
].iov_base
= (void *) (time
->wt_fmt_ampm
?: empty_wstr
);
798 iov
[2 + cnt
].iov_len
= ((wcslen (iov
[2 + cnt
].iov_base
) + 1)
799 * sizeof (uint32_t));
800 idx
[1 + last_idx
] = idx
[last_idx
] + iov
[2 + cnt
].iov_len
;
804 iov
[2 + cnt
].iov_base
= (void *) (time
->wera_year
?: empty_wstr
);
805 iov
[2 + cnt
].iov_len
= ((wcslen (iov
[2 + cnt
].iov_base
) + 1)
806 * sizeof (uint32_t));
807 idx
[1 + last_idx
] = idx
[last_idx
] + iov
[2 + cnt
].iov_len
;
811 iov
[2 + cnt
].iov_base
= (void *) (time
->wera_d_fmt
?: empty_wstr
);
812 iov
[2 + cnt
].iov_len
= ((wcslen (iov
[2 + cnt
].iov_base
) + 1)
813 * sizeof (uint32_t));
814 idx
[1 + last_idx
] = idx
[last_idx
] + iov
[2 + cnt
].iov_len
;
818 idx
[1 + last_idx
] = idx
[last_idx
];
819 for (num
= 0; num
< 100; ++num
, ++cnt
)
821 iov
[2 + cnt
].iov_base
= (void *) (time
->walt_digits
[num
]
823 iov
[2 + cnt
].iov_len
= ((wcslen (iov
[2 + cnt
].iov_base
) + 1)
824 * sizeof (uint32_t));
825 idx
[1 + last_idx
] += iov
[2 + cnt
].iov_len
;
829 iov
[2 + cnt
].iov_base
= (void *) (time
->wera_d_t_fmt
?: empty_wstr
);
830 iov
[2 + cnt
].iov_len
= ((wcslen (iov
[2 + cnt
].iov_base
) + 1)
831 * sizeof (uint32_t));
832 idx
[1 + last_idx
] = idx
[last_idx
] + iov
[2 + cnt
].iov_len
;
836 iov
[2 + cnt
].iov_base
= (void *) (time
->wera_t_fmt
?: empty_wstr
);
837 iov
[2 + cnt
].iov_len
= ((wcslen (iov
[2 + cnt
].iov_base
) + 1)
838 * sizeof (uint32_t));
839 idx
[1 + last_idx
] = idx
[last_idx
] + iov
[2 + cnt
].iov_len
;
843 iov
[2 + cnt
].iov_base
= (void *) &time
->week_ndays
;
844 iov
[2 + cnt
].iov_len
= 1;
845 idx
[1 + last_idx
] = idx
[last_idx
] + iov
[2 + cnt
].iov_len
;
849 /* We must align the following data. */
850 iov
[2 + cnt
].iov_base
= (void *) "\0\0";
851 iov
[2 + cnt
].iov_len
= ((idx
[last_idx
] + 3) & ~3) - idx
[last_idx
];
852 idx
[last_idx
] = (idx
[last_idx
] + 3) & ~3;
855 iov
[2 + cnt
].iov_base
= (void *) &time
->week_1stday
;
856 iov
[2 + cnt
].iov_len
= sizeof(uint32_t);
857 idx
[1 + last_idx
] = idx
[last_idx
] + iov
[2 + cnt
].iov_len
;
861 iov
[2 + cnt
].iov_base
= (void *) &time
->week_1stweek
;
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_weekday
;
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
->first_workday
;
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
->cal_direction
;
880 iov
[2 + cnt
].iov_len
= 1;
881 idx
[1 + last_idx
] = idx
[last_idx
] + iov
[2 + cnt
].iov_len
;
885 iov
[2 + cnt
].iov_base
= (void *) time
->timezone
;
886 iov
[2 + cnt
].iov_len
= strlen (time
->timezone
) + 1;
887 idx
[1 + last_idx
] = idx
[last_idx
] + iov
[2 + cnt
].iov_len
;
891 iov
[2 + cnt
].iov_base
= (void *) time
->date_fmt
;
892 iov
[2 + cnt
].iov_len
= strlen (iov
[2 + cnt
].iov_base
) + 1;
893 idx
[1 + last_idx
] = idx
[last_idx
] + iov
[2 + cnt
].iov_len
;
897 iov
[2 + cnt
].iov_base
= (void *) time
->wdate_fmt
;
898 iov
[2 + cnt
].iov_len
= ((wcslen (iov
[2 + cnt
].iov_base
) + 1)
899 * sizeof (uint32_t));
900 idx
[1 + last_idx
] = idx
[last_idx
] + iov
[2 + cnt
].iov_len
;
904 iov
[2 + cnt
].iov_base
= (void *) charmap
->code_set_name
;
905 iov
[2 + cnt
].iov_len
= strlen (iov
[2 + cnt
].iov_base
) + 1;
909 assert (cnt
== (_NL_ITEM_INDEX (_NL_NUM_LC_TIME
)
912 + 2 + time
->num_era
* 10 - 1));
913 assert (last_idx
== _NL_ITEM_INDEX (_NL_NUM_LC_TIME
));
915 write_locale_data (output_path
, LC_TIME
, "LC_TIME", 2 + cnt
, iov
);
919 /* The parser for the LC_TIME section of the locale definition. */
921 time_read (struct linereader
*ldfile
, struct localedef_t
*result
,
922 const struct charmap_t
*charmap
, const char *repertoire_name
,
925 struct repertoire_t
*repertoire
= NULL
;
926 struct locale_time_t
*time
;
931 /* Get the repertoire we have to use. */
932 if (repertoire_name
!= NULL
)
933 repertoire
= repertoire_read (repertoire_name
);
935 /* The rest of the line containing `LC_TIME' must be free. */
936 lr_ignore_rest (ldfile
, 1);
941 now
= lr_token (ldfile
, charmap
, result
, repertoire
, verbose
);
944 while (nowtok
== tok_eol
);
946 /* If we see `copy' now we are almost done. */
947 if (nowtok
== tok_copy
)
949 handle_copy (ldfile
, charmap
, repertoire_name
, result
, tok_lc_time
,
950 LC_TIME
, "LC_TIME", ignore_content
);
954 /* Prepare the data structures. */
955 time_startup (ldfile
, result
, ignore_content
);
956 time
= result
->categories
[LC_TIME
].time
;
960 /* Of course we don't proceed beyond the end of file. */
961 if (nowtok
== tok_eof
)
964 /* Ingore empty lines. */
965 if (nowtok
== tok_eol
)
967 now
= lr_token (ldfile
, charmap
, result
, repertoire
, verbose
);
974 #define STRARR_ELEM(cat, min, max) \
976 /* Ignore the rest of the line if we don't need the input of \
978 if (ignore_content) \
980 lr_ignore_rest (ldfile, 0); \
984 for (cnt = 0; cnt < max; ++cnt) \
986 now = lr_token (ldfile, charmap, result, repertoire, verbose); \
987 if (now->tok == tok_eol) \
990 lr_error (ldfile, _("%s: too few values for field `%s'"), \
992 if (!ignore_content) \
995 time->cat[cnt] = ""; \
996 time->w##cat[cnt] = empty_wstr; \
998 while (++cnt < max); \
1001 else if (now->tok != tok_string) \
1003 else if (!ignore_content && (now->val.str.startmb == NULL \
1004 || now->val.str.startwc == NULL)) \
1006 lr_error (ldfile, _("%s: unknown character in field `%s'"), \
1008 time->cat[cnt] = ""; \
1009 time->w##cat[cnt] = empty_wstr; \
1011 else if (!ignore_content) \
1013 time->cat[cnt] = now->val.str.startmb; \
1014 time->w##cat[cnt] = now->val.str.startwc; \
1017 /* Match the semicolon. */ \
1018 now = lr_token (ldfile, charmap, result, repertoire, verbose); \
1019 if (now->tok != tok_semicolon && now->tok != tok_eol) \
1022 if (now->tok != tok_eol) \
1024 while (!ignore_content && cnt < min) \
1026 time->cat[cnt] = ""; \
1027 time->w##cat[cnt++] = empty_wstr; \
1030 if (now->tok == tok_semicolon) \
1032 now = lr_token (ldfile, charmap, result, repertoire, \
1034 if (now->tok == tok_eol) \
1035 lr_error (ldfile, _("extra trailing semicolon")); \
1036 else if (now->tok == tok_string) \
1038 lr_error (ldfile, _("\
1039 %s: too many values for field `%s'"), \
1041 lr_ignore_rest (ldfile, 0); \
1049 time->cat##_defined = 1; \
1052 STRARR_ELEM (abday
, 7, 7);
1053 STRARR_ELEM (day
, 7, 7);
1054 STRARR_ELEM (abmon
, 12, 12);
1055 STRARR_ELEM (mon
, 12, 12);
1056 STRARR_ELEM (am_pm
, 2, 2);
1057 STRARR_ELEM (alt_digits
, 0, 100);
1060 /* Ignore the rest of the line if we don't need the input of
1064 lr_ignore_rest (ldfile
, 0);
1069 now
= lr_token (ldfile
, charmap
, result
, repertoire
, verbose
);
1070 if (now
->tok
!= tok_string
)
1072 if (!ignore_content
&& (now
->val
.str
.startmb
== NULL
1073 || now
->val
.str
.startwc
== NULL
))
1075 lr_error (ldfile
, _("%s: unknown character in field `%s'"),
1077 lr_ignore_rest (ldfile
, 0);
1080 if (!ignore_content
)
1082 time
->era
= xrealloc (time
->era
,
1083 (time
->num_era
+ 1) * sizeof (char *));
1084 time
->era
[time
->num_era
] = now
->val
.str
.startmb
;
1086 time
->wera
= xrealloc (time
->wera
,
1089 time
->wera
[time
->num_era
++] = now
->val
.str
.startwc
;
1091 now
= lr_token (ldfile
, charmap
, result
, repertoire
, verbose
);
1092 if (now
->tok
!= tok_eol
&& now
->tok
!= tok_semicolon
)
1095 while (now
->tok
== tok_semicolon
);
1098 #define STR_ELEM(cat) \
1100 /* Ignore the rest of the line if we don't need the input of \
1102 if (ignore_content) \
1104 lr_ignore_rest (ldfile, 0); \
1108 now = lr_token (ldfile, charmap, result, repertoire, verbose); \
1109 if (now->tok != tok_string) \
1111 else if (time->cat != NULL) \
1112 lr_error (ldfile, _("\
1113 %s: field `%s' declared more than once"), "LC_TIME", #cat); \
1114 else if (!ignore_content && (now->val.str.startmb == NULL \
1115 || now->val.str.startwc == NULL)) \
1117 lr_error (ldfile, _("%s: unknown character in field `%s'"), \
1120 time->w##cat = empty_wstr; \
1122 else if (!ignore_content) \
1124 time->cat = now->val.str.startmb; \
1125 time->w##cat = now->val.str.startwc; \
1132 STR_ELEM (t_fmt_ampm
);
1133 STR_ELEM (era_year
);
1134 STR_ELEM (era_d_t_fmt
);
1135 STR_ELEM (era_d_fmt
);
1136 STR_ELEM (era_t_fmt
);
1137 STR_ELEM (timezone
);
1138 STR_ELEM (date_fmt
);
1140 #define INT_ELEM(cat) \
1142 /* Ignore the rest of the line if we don't need the input of \
1144 if (ignore_content) \
1146 lr_ignore_rest (ldfile, 0); \
1150 now = lr_token (ldfile, charmap, result, repertoire, verbose); \
1151 if (now->tok != tok_number) \
1153 else if (time->cat != 0) \
1154 lr_error (ldfile, _("%s: field `%s' declared more than once"), \
1156 else if (!ignore_content) \
1157 time->cat = now->val.num; \
1160 INT_ELEM (first_weekday
);
1161 INT_ELEM (first_workday
);
1162 INT_ELEM (cal_direction
);
1165 /* Ignore the rest of the line if we don't need the input of
1169 lr_ignore_rest (ldfile
, 0);
1173 now
= lr_token (ldfile
, charmap
, result
, repertoire
, verbose
);
1174 if (now
->tok
!= tok_number
)
1176 time
->week_ndays
= now
->val
.num
;
1178 now
= lr_token (ldfile
, charmap
, result
, repertoire
, verbose
);
1179 if (now
->tok
!= tok_semicolon
)
1182 now
= lr_token (ldfile
, charmap
, result
, repertoire
, verbose
);
1183 if (now
->tok
!= tok_number
)
1185 time
->week_1stday
= now
->val
.num
;
1187 now
= lr_token (ldfile
, charmap
, result
, repertoire
, verbose
);
1188 if (now
->tok
!= tok_semicolon
)
1191 now
= lr_token (ldfile
, charmap
, result
, repertoire
, verbose
);
1192 if (now
->tok
!= tok_number
)
1194 time
->week_1stweek
= now
->val
.num
;
1196 lr_ignore_rest (ldfile
, 1);
1200 /* Next we assume `LC_TIME'. */
1201 now
= lr_token (ldfile
, charmap
, result
, repertoire
, verbose
);
1202 if (now
->tok
== tok_eof
)
1204 if (now
->tok
== tok_eol
)
1205 lr_error (ldfile
, _("%s: incomplete `END' line"), "LC_TIME");
1206 else if (now
->tok
!= tok_lc_time
)
1207 lr_error (ldfile
, _("\
1208 %1$s: definition does not end with `END %1$s'"), "LC_TIME");
1209 lr_ignore_rest (ldfile
, now
->tok
== tok_lc_time
);
1214 SYNTAX_ERROR (_("%s: syntax error"), "LC_TIME");
1217 /* Prepare for the next round. */
1218 now
= lr_token (ldfile
, charmap
, result
, repertoire
, verbose
);
1222 /* When we come here we reached the end of the file. */
1223 lr_error (ldfile
, _("%s: premature end of file"), "LC_TIME");