1 /* Copyright (C) 1995, 1996, 1997, 1998, 1999 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 Library General Public License as
7 published by the Free Software Foundation; either version 2 of the
8 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 Library General Public License for more details.
15 You should have received a copy of the GNU Library General Public
16 License along with the GNU C Library; see the file COPYING.LIB. If not,
17 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. */
33 #include "linereader.h"
34 #include "localedef.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];
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
, 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
157 error (0, 0, _("No definition for %s category found"), "LC_TIME");
158 time_startup (NULL
, locale
, 0);
159 time
= locale
->categories
[LC_TIME
].time
;
164 #define TESTARR_ELEM(cat) \
165 if (!time->cat##_defined) \
167 if(! be_quiet && ! nothing) \
168 error (0, 0, _("%s: field `%s' not defined"), "LC_TIME", #cat); \
171 TESTARR_ELEM (abday
);
173 TESTARR_ELEM (abmon
);
175 TESTARR_ELEM (am_pm
);
177 #define TEST_ELEM(cat) \
178 if (time->cat == NULL) \
180 if (! be_quiet && ! nothing) \
181 error (0, 0, _("%s: field `%s' not defined"), "LC_TIME", #cat); \
188 /* According to C.Y.Alexis Cheng <alexis@vnet.ibm.com> the T_FMT_AMPM
189 field is optional. */
190 if (time
->t_fmt_ampm
== NULL
)
192 /* Use the 24h format as default. */
193 time
->t_fmt_ampm
= time
->t_fmt
;
194 time
->wt_fmt_ampm
= time
->wt_fmt
;
197 /* Now process the era entries. */
198 if (time
->num_era
!= 0)
200 const int days_per_month
[12] = { 31, 29, 31, 30, 31, 30,
201 31, 31, 30, 31 ,30, 31 };
206 (struct era_data
*) xmalloc (time
->num_era
207 * sizeof (struct era_data
));
209 for (idx
= 0; idx
< time
->num_era
; ++idx
)
211 size_t era_len
= strlen (time
->era
[idx
]);
212 char *str
= xmalloc ((era_len
+ 1 + 3) & ~3);
215 memcpy (str
, time
->era
[idx
], era_len
+ 1);
217 /* First character must be + or - for the direction. */
218 if (*str
!= '+' && *str
!= '-')
221 error (0, 0, _("%s: direction flag in string %d in `era' field"
222 " is not '+' nor '-'"),
224 /* Default arbitrarily to '+'. */
225 time
->era_entries
[idx
].direction
= '+';
228 time
->era_entries
[idx
].direction
= *str
;
232 error (0, 0, _("%s: direction flag in string %d in `era' field"
233 " is not a single character"),
235 (void) strsep (&str
, ":");
240 /* Now the offset year. */
241 time
->era_entries
[idx
].offset
= strtol (str
, &endp
, 10);
245 error (0, 0, _("%s: invalid number for offset in string %d in"
248 (void) strsep (&str
, ":");
250 else if (*endp
!= ':')
253 error (0, 0, _("%s: garbage at end of offset value in"
254 " string %d in `era' field"),
256 (void) strsep (&str
, ":");
261 /* Next is the starting date in ISO format. */
262 if (strncmp (str
, "-*", 2) == 0)
264 time
->era_entries
[idx
].start_date
[0] =
265 time
->era_entries
[idx
].start_date
[1] =
266 time
->era_entries
[idx
].start_date
[2] = 0x80000000;
268 goto garbage_start_date
;
271 else if (strncmp (str
, "+*", 2) == 0)
273 time
->era_entries
[idx
].start_date
[0] =
274 time
->era_entries
[idx
].start_date
[1] =
275 time
->era_entries
[idx
].start_date
[2] = 0x7fffffff;
277 goto garbage_start_date
;
282 time
->era_entries
[idx
].start_date
[0] = strtol (str
, &endp
, 10);
283 if (endp
== str
|| *endp
!= '/')
284 goto invalid_start_date
;
287 time
->era_entries
[idx
].start_date
[0] -= 1900;
289 time
->era_entries
[idx
].start_date
[1] = strtol (str
, &endp
, 10);
290 if (endp
== str
|| *endp
!= '/')
291 goto invalid_start_date
;
294 time
->era_entries
[idx
].start_date
[1] -= 1;
296 time
->era_entries
[idx
].start_date
[2] = strtol (str
, &endp
, 10);
301 error (0, 0, _("%s: invalid starting date in string %d in"
304 (void) strsep (&str
, ":");
306 else if (*endp
!= ':')
310 error (0, 0, _("%s: garbage at end of starting date "
311 "in string %d in `era' field "),
313 (void) strsep (&str
, ":");
319 /* Check for valid value. */
320 if ((time
->era_entries
[idx
].start_date
[1] < 0
321 || time
->era_entries
[idx
].start_date
[1] >= 12
322 || time
->era_entries
[idx
].start_date
[2] < 0
323 || (time
->era_entries
[idx
].start_date
[2]
324 > days_per_month
[time
->era_entries
[idx
].start_date
[1]])
325 || (time
->era_entries
[idx
].start_date
[1] == 2
326 && time
->era_entries
[idx
].start_date
[2] == 29
327 && !__isleap (time
->era_entries
[idx
].start_date
[0])))
329 error (0, 0, _("%s: starting date is invalid in"
330 " string %d in `era' field"),
335 /* Next is the stopping date in ISO format. */
336 if (strncmp (str
, "-*", 2) == 0)
338 time
->era_entries
[idx
].stop_date
[0] =
339 time
->era_entries
[idx
].stop_date
[1] =
340 time
->era_entries
[idx
].stop_date
[2] = 0x80000000;
342 goto garbage_stop_date
;
345 else if (strncmp (str
, "+*", 2) == 0)
347 time
->era_entries
[idx
].stop_date
[0] =
348 time
->era_entries
[idx
].stop_date
[1] =
349 time
->era_entries
[idx
].stop_date
[2] = 0x7fffffff;
351 goto garbage_stop_date
;
356 time
->era_entries
[idx
].stop_date
[0] = strtol (str
, &endp
, 10);
357 if (endp
== str
|| *endp
!= '/')
358 goto invalid_stop_date
;
361 time
->era_entries
[idx
].stop_date
[0] -= 1900;
363 time
->era_entries
[idx
].stop_date
[1] = strtol (str
, &endp
, 10);
364 if (endp
== str
|| *endp
!= '/')
365 goto invalid_stop_date
;
368 time
->era_entries
[idx
].stop_date
[1] -= 1;
370 time
->era_entries
[idx
].stop_date
[2] = strtol (str
, &endp
, 10);
375 error (0, 0, _("%s: invalid stopping date in string %d in"
378 (void) strsep (&str
, ":");
380 else if (*endp
!= ':')
384 error (0, 0, _("%s: garbage at end of stopping date "
385 "in string %d in `era' field"),
387 (void) strsep (&str
, ":");
393 /* Check for valid value. */
394 if ((time
->era_entries
[idx
].stop_date
[1] < 0
395 || time
->era_entries
[idx
].stop_date
[1] >= 12
396 || time
->era_entries
[idx
].stop_date
[2] < 0
397 || (time
->era_entries
[idx
].stop_date
[2]
398 > days_per_month
[time
->era_entries
[idx
].stop_date
[1]])
399 || (time
->era_entries
[idx
].stop_date
[1] == 2
400 && time
->era_entries
[idx
].stop_date
[2] == 29
401 && !__isleap (time
->era_entries
[idx
].stop_date
[0])))
403 error (0, 0, _("%s: stopping date is invalid in"
404 " string %d in `era' field"),
409 if (str
== NULL
|| *str
== '\0')
412 error (0, 0, _("%s: missing era name in string %d in `era'"
413 " field"), "LC_TIME", idx
+ 1);
414 time
->era_entries
[idx
].name
=
415 time
->era_entries
[idx
].format
= "";
419 time
->era_entries
[idx
].name
= strsep (&str
, ":");
421 if (str
== NULL
|| *str
== '\0')
424 error (0, 0, _("%s: missing era format in string %d"
427 time
->era_entries
[idx
].name
=
428 time
->era_entries
[idx
].format
= "";
431 time
->era_entries
[idx
].format
= str
;
434 /* Now generate the wide character name and format. */
435 wstr
= wcschr ((wchar_t *) time
->wera
[idx
], L
':');/* end direction */
436 wstr
= wstr
? wcschr (wstr
+ 1, L
':') : NULL
; /* end offset */
437 wstr
= wstr
? wcschr (wstr
+ 1, L
':') : NULL
; /* end start */
438 wstr
= wstr
? wcschr (wstr
+ 1, L
':') : NULL
; /* end end */
439 time
->era_entries
[idx
].wname
= (uint32_t *) wstr
+ 1;
440 wstr
= wstr
? wcschr (wstr
+ 1, L
':') : NULL
; /* end name */
442 time
->era_entries
[idx
].wformat
= (uint32_t *) wstr
+ 1;
446 if (time
->week_ndays
== 0)
447 time
->week_ndays
= 7;
449 if (time
->week_1stday
== 0)
450 time
->week_1stday
= 19971130;
452 if (time
->week_1stweek
> time
->week_ndays
)
454 %s: third operand for value of field `%s' must not be larger than %d"),
455 "LC_TIME", "week", 7);
457 if (time
->first_weekday
== '\0')
458 /* The definition does not specify this so the default is used. */
459 time
->first_weekday
= 1;
460 else if (time
->first_weekday
> time
->week_ndays
)
462 %s: values of field `%s' must not be larger than %d"),
463 "LC_TIME", "first_weekday", 7);
465 if (time
->first_workday
== '\0')
466 /* The definition does not specify this so the default is used. */
467 time
->first_workday
= 1;
468 else if (time
->first_workday
> time
->week_ndays
)
470 %s: values of field `%s' must not be larger than %d"),
471 "LC_TIME", "first_workday", 7);
473 if (time
->cal_direction
== '\0')
474 /* The definition does not specify this so the default is used. */
475 time
->cal_direction
= 1;
476 else if (time
->cal_direction
> 3)
478 %s: values for field `%s' must not be larger than 3"),
479 "LC_TIME", "cal_direction", 3);
481 /* XXX We don't perform any tests on the timezone value since this is
482 simply useless, stupid $&$!@... */
483 if (time
->timezone
== NULL
)
489 time_output (struct localedef_t
*locale
, struct charmap_t
*charmap
,
490 const char *output_path
)
492 struct locale_time_t
*time
= locale
->categories
[LC_TIME
].time
;
493 struct iovec iov
[2 + _NL_ITEM_INDEX (_NL_NUM_LC_TIME
)
496 + 1 + time
->num_era
* 10 - 1];
497 struct locale_file data
;
498 uint32_t idx
[_NL_ITEM_INDEX (_NL_NUM_LC_TIME
)];
499 size_t cnt
, last_idx
, num
, n
;
501 data
.magic
= LIMAGIC (LC_TIME
);
502 data
.n
= _NL_ITEM_INDEX (_NL_NUM_LC_TIME
);
503 iov
[0].iov_base
= (void *) &data
;
504 iov
[0].iov_len
= sizeof (data
);
506 iov
[1].iov_base
= (void *) idx
;
507 iov
[1].iov_len
= sizeof (idx
);
509 idx
[0] = iov
[0].iov_len
+ iov
[1].iov_len
;
512 for (cnt
= 0; cnt
<= _NL_ITEM_INDEX (ABDAY_7
); ++cnt
)
514 iov
[2 + cnt
].iov_base
=
515 (void *) (time
->abday
[cnt
- _NL_ITEM_INDEX (ABDAY_1
)] ?: "");
516 iov
[2 + cnt
].iov_len
= strlen (iov
[2 + cnt
].iov_base
) + 1;
517 idx
[1 + cnt
] = idx
[cnt
] + iov
[2 + cnt
].iov_len
;
521 for (; cnt
<= _NL_ITEM_INDEX (DAY_7
); ++cnt
)
523 iov
[2 + cnt
].iov_base
=
524 (void *) (time
->day
[cnt
- _NL_ITEM_INDEX (DAY_1
)] ?: "");
525 iov
[2 + cnt
].iov_len
= strlen (iov
[2 + cnt
].iov_base
) + 1;
526 idx
[1 + cnt
] = idx
[cnt
] + iov
[2 + cnt
].iov_len
;
530 for (; cnt
<= _NL_ITEM_INDEX (ABMON_12
); ++cnt
)
532 iov
[2 + cnt
].iov_base
=
533 (void *) (time
->abmon
[cnt
- _NL_ITEM_INDEX (ABMON_1
)] ?: "");
534 iov
[2 + cnt
].iov_len
= strlen (iov
[2 + cnt
].iov_base
) + 1;
535 idx
[1 + cnt
] = idx
[cnt
] + iov
[2 + cnt
].iov_len
;
539 for (; cnt
<= _NL_ITEM_INDEX (MON_12
); ++cnt
)
541 iov
[2 + cnt
].iov_base
=
542 (void *) (time
->mon
[cnt
- _NL_ITEM_INDEX (MON_1
)] ?: "");
543 iov
[2 + cnt
].iov_len
= strlen (iov
[2 + cnt
].iov_base
) + 1;
544 idx
[1 + cnt
] = idx
[cnt
] + iov
[2 + cnt
].iov_len
;
548 for (; cnt
<= _NL_ITEM_INDEX (PM_STR
); ++cnt
)
550 iov
[2 + cnt
].iov_base
=
551 (void *) (time
->am_pm
[cnt
- _NL_ITEM_INDEX (AM_STR
)] ?: "");
552 iov
[2 + cnt
].iov_len
= strlen (iov
[2 + cnt
].iov_base
) + 1;
553 idx
[1 + cnt
] = idx
[cnt
] + iov
[2 + cnt
].iov_len
;
556 iov
[2 + cnt
].iov_base
= (void *) (time
->d_t_fmt
?: "");
557 iov
[2 + cnt
].iov_len
= strlen (iov
[2 + cnt
].iov_base
) + 1;
558 idx
[1 + cnt
] = idx
[cnt
] + iov
[2 + cnt
].iov_len
;
561 iov
[2 + cnt
].iov_base
= (void *) (time
->d_fmt
?: "");
562 iov
[2 + cnt
].iov_len
= strlen (iov
[2 + cnt
].iov_base
) + 1;
563 idx
[1 + cnt
] = idx
[cnt
] + iov
[2 + cnt
].iov_len
;
566 iov
[2 + cnt
].iov_base
= (void *) (time
->t_fmt
?: "");
567 iov
[2 + cnt
].iov_len
= strlen (iov
[2 + cnt
].iov_base
) + 1;
568 idx
[1 + cnt
] = idx
[cnt
] + iov
[2 + cnt
].iov_len
;
571 iov
[2 + cnt
].iov_base
= (void *) (time
->t_fmt_ampm
?: "");
572 iov
[2 + cnt
].iov_len
= strlen (iov
[2 + cnt
].iov_base
) + 1;
573 idx
[1 + cnt
] = idx
[cnt
] + iov
[2 + cnt
].iov_len
;
576 idx
[1 + last_idx
] = idx
[last_idx
];
577 for (num
= 0; num
< time
->num_era
; ++num
, ++cnt
)
579 iov
[2 + cnt
].iov_base
= (void *) time
->era
[num
];
580 iov
[2 + cnt
].iov_len
= strlen (iov
[2 + cnt
].iov_base
) + 1;
581 idx
[1 + last_idx
] += iov
[2 + cnt
].iov_len
;
585 iov
[2 + cnt
].iov_base
= (void *) (time
->era_year
?: "");
586 iov
[2 + cnt
].iov_len
= strlen (iov
[2 + cnt
].iov_base
) + 1;
587 idx
[1 + last_idx
] = idx
[last_idx
] + iov
[2 + cnt
].iov_len
;
591 iov
[2 + cnt
].iov_base
= (void *) (time
->era_d_fmt
?: "");
592 iov
[2 + cnt
].iov_len
= strlen (iov
[2 + cnt
].iov_base
) + 1;
593 idx
[1 + last_idx
] = idx
[last_idx
] + iov
[2 + cnt
].iov_len
;
597 idx
[1 + last_idx
] = idx
[last_idx
];
598 for (num
= 0; num
< 100; ++num
, ++cnt
)
600 iov
[2 + cnt
].iov_base
= (void *) (time
->alt_digits
[num
] ?: "");
601 iov
[2 + cnt
].iov_len
= strlen (iov
[2 + cnt
].iov_base
) + 1;
602 idx
[1 + last_idx
] += iov
[2 + cnt
].iov_len
;
606 iov
[2 + cnt
].iov_base
= (void *) (time
->era_d_t_fmt
?: "");
607 iov
[2 + cnt
].iov_len
= strlen (iov
[2 + cnt
].iov_base
) + 1;
608 idx
[1 + last_idx
] = idx
[last_idx
] + iov
[2 + cnt
].iov_len
;
612 iov
[2 + cnt
].iov_base
= (void *) (time
->era_t_fmt
?: "");
613 iov
[2 + cnt
].iov_len
= strlen (iov
[2 + cnt
].iov_base
) + 1;
614 idx
[1 + last_idx
] = idx
[last_idx
] + iov
[2 + cnt
].iov_len
;
619 /* We must align the following data. */
620 iov
[2 + cnt
].iov_base
= (void *) "\0\0";
621 iov
[2 + cnt
].iov_len
= ((idx
[last_idx
] + 3) & ~3) - idx
[last_idx
];
622 idx
[last_idx
] = (idx
[last_idx
] + 3) & ~3;
625 /* The `era' data in usable form. */
626 iov
[2 + cnt
].iov_base
= (void *) &time
->num_era
;
627 iov
[2 + cnt
].iov_len
= sizeof (uint32_t);
628 idx
[1 + last_idx
] = idx
[last_idx
] + iov
[2 + cnt
].iov_len
;
632 idx
[1 + last_idx
] = idx
[last_idx
];
633 for (num
= 0; num
< time
->num_era
; ++num
)
637 iov
[2 + cnt
].iov_base
= (void *) &time
->era_entries
[num
].direction
;
638 iov
[2 + cnt
].iov_len
= sizeof (int32_t);
640 iov
[2 + cnt
].iov_base
= (void *) &time
->era_entries
[num
].offset
;
641 iov
[2 + cnt
].iov_len
= sizeof (int32_t);
643 iov
[2 + cnt
].iov_base
= (void *) &time
->era_entries
[num
].start_date
[0];
644 iov
[2 + cnt
].iov_len
= sizeof (int32_t);
646 iov
[2 + cnt
].iov_base
= (void *) &time
->era_entries
[num
].start_date
[1];
647 iov
[2 + cnt
].iov_len
= sizeof (int32_t);
649 iov
[2 + cnt
].iov_base
= (void *) &time
->era_entries
[num
].start_date
[2];
650 iov
[2 + cnt
].iov_len
= sizeof (int32_t);
652 iov
[2 + cnt
].iov_base
= (void *) &time
->era_entries
[num
].stop_date
[0];
653 iov
[2 + cnt
].iov_len
= sizeof (int32_t);
655 iov
[2 + cnt
].iov_base
= (void *) &time
->era_entries
[num
].stop_date
[1];
656 iov
[2 + cnt
].iov_len
= sizeof (int32_t);
658 iov
[2 + cnt
].iov_base
= (void *) &time
->era_entries
[num
].stop_date
[2];
659 iov
[2 + cnt
].iov_len
= sizeof (int32_t);
662 l
= (strchr (time
->era_entries
[num
].format
, '\0')
663 - time
->era_entries
[num
].name
) + 1;
665 iov
[2 + cnt
].iov_base
= (void *) time
->era_entries
[num
].name
;
666 iov
[2 + cnt
].iov_len
= l
;
669 idx
[1 + last_idx
] += 8 * sizeof (int32_t) + l
;
671 assert (idx
[1 + last_idx
] % 4 == 0);
673 iov
[2 + cnt
].iov_base
= (void *) time
->era_entries
[num
].wname
;
674 iov
[2 + cnt
].iov_len
= ((wcschr ((wchar_t *) time
->era_entries
[num
].wformat
, L
'\0')
675 - (wchar_t *) time
->era_entries
[num
].wname
+ 1)
676 * sizeof (uint32_t));
677 idx
[1 + last_idx
] += iov
[2 + cnt
].iov_len
;
682 /* The wide character ab'days. */
683 for (n
= 0; n
< 7; ++n
, ++cnt
, ++last_idx
)
685 iov
[2 + cnt
].iov_base
=
686 (void *) (time
->wabday
[n
] ?: empty_wstr
);
687 iov
[2 + cnt
].iov_len
= ((wcslen (iov
[2 + cnt
].iov_base
) + 1)
688 * sizeof (uint32_t));
689 idx
[1 + last_idx
] = idx
[last_idx
] + iov
[2 + cnt
].iov_len
;
692 /* The wide character days. */
693 for (n
= 0; n
< 7; ++n
, ++cnt
, ++last_idx
)
695 iov
[2 + cnt
].iov_base
=
696 (void *) (time
->wday
[n
] ?: empty_wstr
);
697 iov
[2 + cnt
].iov_len
= ((wcslen (iov
[2 + cnt
].iov_base
) + 1)
698 * sizeof (uint32_t));
699 idx
[1 + last_idx
] = idx
[last_idx
] + iov
[2 + cnt
].iov_len
;
702 /* The wide character ab'mons. */
703 for (n
= 0; n
< 12; ++n
, ++cnt
, ++last_idx
)
705 iov
[2 + cnt
].iov_base
=
706 (void *) (time
->wabmon
[n
] ?: empty_wstr
);
707 iov
[2 + cnt
].iov_len
= ((wcslen (iov
[2 + cnt
].iov_base
) + 1)
708 * sizeof (uint32_t));
709 idx
[1 + last_idx
] = idx
[last_idx
] + iov
[2 + cnt
].iov_len
;
712 /* The wide character mons. */
713 for (n
= 0; n
< 12; ++n
, ++cnt
, ++last_idx
)
715 iov
[2 + cnt
].iov_base
=
716 (void *) (time
->wmon
[n
] ?: empty_wstr
);
717 iov
[2 + cnt
].iov_len
= ((wcslen (iov
[2 + cnt
].iov_base
) + 1)
718 * sizeof (uint32_t));
719 idx
[1 + last_idx
] = idx
[last_idx
] + iov
[2 + cnt
].iov_len
;
722 /* Wide character AM/PM. */
723 for (n
= 0; n
< 2; ++n
, ++cnt
, ++last_idx
)
725 iov
[2 + cnt
].iov_base
=
726 (void *) (time
->wam_pm
[n
] ?: empty_wstr
);
727 iov
[2 + cnt
].iov_len
= ((wcslen (iov
[2 + cnt
].iov_base
) + 1)
728 * sizeof (uint32_t));
729 idx
[1 + last_idx
] = idx
[last_idx
] + iov
[2 + cnt
].iov_len
;
732 iov
[2 + cnt
].iov_base
= (void *) (time
->wd_t_fmt
?: empty_wstr
);
733 iov
[2 + cnt
].iov_len
= ((wcslen (iov
[2 + cnt
].iov_base
) + 1)
734 * sizeof (uint32_t));
735 idx
[1 + last_idx
] = idx
[last_idx
] + iov
[2 + cnt
].iov_len
;
739 iov
[2 + cnt
].iov_base
= (void *) (time
->wd_fmt
?: empty_wstr
);
740 iov
[2 + cnt
].iov_len
= ((wcslen (iov
[2 + cnt
].iov_base
) + 1)
741 * sizeof (uint32_t));
742 idx
[1 + last_idx
] = idx
[last_idx
] + iov
[2 + cnt
].iov_len
;
746 iov
[2 + cnt
].iov_base
= (void *) (time
->wt_fmt
?: empty_wstr
);
747 iov
[2 + cnt
].iov_len
= ((wcslen (iov
[2 + cnt
].iov_base
) + 1)
748 * sizeof (uint32_t));
749 idx
[1 + last_idx
] = idx
[last_idx
] + iov
[2 + cnt
].iov_len
;
753 iov
[2 + cnt
].iov_base
= (void *) (time
->wt_fmt_ampm
?: empty_wstr
);
754 iov
[2 + cnt
].iov_len
= ((wcslen (iov
[2 + cnt
].iov_base
) + 1)
755 * sizeof (uint32_t));
756 idx
[1 + last_idx
] = idx
[last_idx
] + iov
[2 + cnt
].iov_len
;
760 iov
[2 + cnt
].iov_base
= (void *) (time
->wera_year
?: 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
;
767 iov
[2 + cnt
].iov_base
= (void *) (time
->wera_d_fmt
?: empty_wstr
);
768 iov
[2 + cnt
].iov_len
= ((wcslen (iov
[2 + cnt
].iov_base
) + 1)
769 * sizeof (uint32_t));
770 idx
[1 + last_idx
] = idx
[last_idx
] + iov
[2 + cnt
].iov_len
;
774 idx
[1 + last_idx
] = idx
[last_idx
];
775 for (num
= 0; num
< 100; ++num
, ++cnt
)
777 iov
[2 + cnt
].iov_base
= (void *) (time
->walt_digits
[num
]
779 iov
[2 + cnt
].iov_len
= ((wcslen (iov
[2 + cnt
].iov_base
) + 1)
780 * sizeof (uint32_t));
781 idx
[1 + last_idx
] += iov
[2 + cnt
].iov_len
;
785 iov
[2 + cnt
].iov_base
= (void *) (time
->wera_d_t_fmt
?: empty_wstr
);
786 iov
[2 + cnt
].iov_len
= ((wcslen (iov
[2 + cnt
].iov_base
) + 1)
787 * sizeof (uint32_t));
788 idx
[1 + last_idx
] = idx
[last_idx
] + iov
[2 + cnt
].iov_len
;
792 iov
[2 + cnt
].iov_base
= (void *) (time
->wera_t_fmt
?: empty_wstr
);
793 iov
[2 + cnt
].iov_len
= ((wcslen (iov
[2 + cnt
].iov_base
) + 1)
794 * sizeof (uint32_t));
795 idx
[1 + last_idx
] = idx
[last_idx
] + iov
[2 + cnt
].iov_len
;
799 iov
[2 + cnt
].iov_base
= (void *) &time
->week_ndays
;
800 iov
[2 + cnt
].iov_len
= 1;
801 idx
[1 + last_idx
] = idx
[last_idx
] + iov
[2 + cnt
].iov_len
;
805 iov
[2 + cnt
].iov_base
= (void *) &time
->week_1stday
;
806 iov
[2 + cnt
].iov_len
= 1;
807 idx
[1 + last_idx
] = idx
[last_idx
] + iov
[2 + cnt
].iov_len
;
811 iov
[2 + cnt
].iov_base
= (void *) &time
->week_1stweek
;
812 iov
[2 + cnt
].iov_len
= 1;
813 idx
[1 + last_idx
] = idx
[last_idx
] + iov
[2 + cnt
].iov_len
;
817 iov
[2 + cnt
].iov_base
= (void *) &time
->first_weekday
;
818 iov
[2 + cnt
].iov_len
= 1;
819 idx
[1 + last_idx
] = idx
[last_idx
] + iov
[2 + cnt
].iov_len
;
823 iov
[2 + cnt
].iov_base
= (void *) &time
->first_workday
;
824 iov
[2 + cnt
].iov_len
= 1;
825 idx
[1 + last_idx
] = idx
[last_idx
] + iov
[2 + cnt
].iov_len
;
829 iov
[2 + cnt
].iov_base
= (void *) &time
->cal_direction
;
830 iov
[2 + cnt
].iov_len
= 1;
831 idx
[1 + last_idx
] = idx
[last_idx
] + iov
[2 + cnt
].iov_len
;
835 iov
[2 + cnt
].iov_base
= (void *) time
->timezone
;
836 iov
[2 + cnt
].iov_len
= strlen (time
->timezone
) + 1;
840 assert (cnt
== (_NL_ITEM_INDEX (_NL_NUM_LC_TIME
)
843 + 1 + time
->num_era
* 10 - 1));
844 assert (last_idx
== _NL_ITEM_INDEX (_NL_NUM_LC_TIME
));
846 write_locale_data (output_path
, "LC_TIME", 2 + cnt
, iov
);
850 /* The parser for the LC_TIME section of the locale definition. */
852 time_read (struct linereader
*ldfile
, struct localedef_t
*result
,
853 struct charmap_t
*charmap
, const char *repertoire_name
,
856 struct repertoire_t
*repertoire
= NULL
;
857 struct locale_time_t
*time
;
862 /* Get the repertoire we have to use. */
863 if (repertoire_name
!= NULL
)
864 repertoire
= repertoire_read (repertoire_name
);
866 /* The rest of the line containing `LC_TIME' must be free. */
867 lr_ignore_rest (ldfile
, 1);
872 now
= lr_token (ldfile
, charmap
, repertoire
);
875 while (nowtok
== tok_eol
);
877 /* If we see `copy' now we are almost done. */
878 if (nowtok
== tok_copy
)
880 handle_copy (ldfile
, charmap
, repertoire
, result
, tok_lc_time
,
881 LC_TIME
, "LC_TIME", ignore_content
);
885 /* Prepare the data structures. */
886 time_startup (ldfile
, result
, ignore_content
);
887 time
= result
->categories
[LC_TIME
].time
;
891 /* Of course we don't proceed beyond the end of file. */
892 if (nowtok
== tok_eof
)
895 /* Ingore empty lines. */
896 if (nowtok
== tok_eol
)
898 now
= lr_token (ldfile
, charmap
, repertoire
);
905 #define STRARR_ELEM(cat, min, max) \
907 /* Ignore the rest of the line if we don't need the input of \
909 if (ignore_content) \
911 lr_ignore_rest (ldfile, 0); \
915 for (cnt = 0; cnt < max; ++cnt) \
917 now = lr_token (ldfile, charmap, repertoire); \
918 if (now->tok == tok_eol) \
921 lr_error (ldfile, _("%s: too few values for field `%s'"), \
923 if (!ignore_content) \
926 time->cat[cnt] = ""; \
927 time->w##cat[cnt] = empty_wstr; \
929 while (++cnt < max); \
932 else if (now->tok != tok_string) \
934 else if (!ignore_content && (now->val.str.startmb == NULL \
935 || now->val.str.startwc == NULL)) \
937 lr_error (ldfile, _("%s: unknown character in field `%s'"), \
939 time->cat[cnt] = ""; \
940 time->w##cat[cnt] = empty_wstr; \
942 else if (!ignore_content) \
944 time->cat[cnt] = now->val.str.startmb; \
945 time->w##cat[cnt] = now->val.str.startwc; \
948 /* Match the semicolon. */ \
949 now = lr_token (ldfile, charmap, repertoire); \
950 if (now->tok != tok_semicolon && now->tok != tok_eol) \
953 if (now->tok != tok_eol) \
955 while (!ignore_content && cnt < min) \
957 time->cat[cnt] = ""; \
958 time->w##cat[cnt++] = empty_wstr; \
961 if (now->tok == tok_semicolon) \
963 now = lr_token (ldfile, charmap, repertoire); \
964 if (now->tok == tok_eol) \
965 lr_error (ldfile, _("extra trailing semicolon")); \
966 else if (now->tok == tok_string) \
968 lr_error (ldfile, _("\
969 %s: too many values for field `%s'"), \
971 lr_ignore_rest (ldfile, 0); \
979 time->cat##_defined = 1; \
982 STRARR_ELEM (abday
, 7, 7);
983 STRARR_ELEM (day
, 7, 7);
984 STRARR_ELEM (abmon
, 12, 12);
985 STRARR_ELEM (mon
, 12, 12);
986 STRARR_ELEM (am_pm
, 2, 2);
987 STRARR_ELEM (alt_digits
, 0, 100);
990 /* Ignore the rest of the line if we don't need the input of
994 lr_ignore_rest (ldfile
, 0);
999 now
= lr_token (ldfile
, charmap
, repertoire
);
1000 if (now
->tok
!= tok_string
)
1002 if (!ignore_content
&& (now
->val
.str
.startmb
== NULL
1003 || now
->val
.str
.startwc
== NULL
))
1005 lr_error (ldfile
, _("%s: unknown character in field `%s'"),
1007 lr_ignore_rest (ldfile
, 0);
1010 if (!ignore_content
)
1012 time
->era
= xrealloc (time
->era
,
1013 (time
->num_era
+ 1) * sizeof (char *));
1014 time
->era
[time
->num_era
] = now
->val
.str
.startmb
;
1016 time
->wera
= xrealloc (time
->wera
,
1019 time
->wera
[time
->num_era
++] = now
->val
.str
.startwc
;
1021 now
= lr_token (ldfile
, charmap
, repertoire
);
1022 if (now
->tok
!= tok_eol
&& now
->tok
!= tok_semicolon
)
1025 while (now
->tok
== tok_semicolon
);
1028 #define STR_ELEM(cat) \
1030 /* Ignore the rest of the line if we don't need the input of \
1032 if (ignore_content) \
1034 lr_ignore_rest (ldfile, 0); \
1038 now = lr_token (ldfile, charmap, repertoire); \
1039 if (now->tok != tok_string) \
1041 else if (time->cat != NULL) \
1042 lr_error (ldfile, _("\
1043 %s: field `%s' declared more than once"), "LC_TIME", #cat); \
1044 else if (!ignore_content && (now->val.str.startmb == NULL \
1045 || now->val.str.startwc == NULL)) \
1047 lr_error (ldfile, _("%s: unknown character in field `%s'"), \
1050 time->w##cat = empty_wstr; \
1052 else if (!ignore_content) \
1054 time->cat = now->val.str.startmb; \
1055 time->w##cat = now->val.str.startwc; \
1062 STR_ELEM (t_fmt_ampm
);
1063 STR_ELEM (era_year
);
1064 STR_ELEM (era_d_t_fmt
);
1065 STR_ELEM (era_d_fmt
);
1066 STR_ELEM (era_t_fmt
);
1067 STR_ELEM (timezone
);
1069 #define INT_ELEM(cat) \
1071 /* Ignore the rest of the line if we don't need the input of \
1073 if (ignore_content) \
1075 lr_ignore_rest (ldfile, 0); \
1079 now = lr_token (ldfile, charmap, repertoire); \
1080 if (now->tok != tok_number) \
1082 else if (time->cat != 0) \
1083 lr_error (ldfile, _("%s: field `%s' declared more than once"), \
1085 else if (!ignore_content) \
1086 time->cat = now->val.num; \
1089 INT_ELEM (first_weekday
);
1090 INT_ELEM (first_workday
);
1091 INT_ELEM (cal_direction
);
1094 /* Ignore the rest of the line if we don't need the input of
1098 lr_ignore_rest (ldfile
, 0);
1102 now
= lr_token (ldfile
, charmap
, repertoire
);
1103 if (now
->tok
!= tok_number
)
1105 time
->week_ndays
= now
->val
.num
;
1107 now
= lr_token (ldfile
, charmap
, repertoire
);
1108 if (now
->tok
!= tok_semicolon
)
1111 now
= lr_token (ldfile
, charmap
, repertoire
);
1112 if (now
->tok
!= tok_number
)
1114 time
->week_1stday
= now
->val
.num
;
1116 now
= lr_token (ldfile
, charmap
, repertoire
);
1117 if (now
->tok
!= tok_semicolon
)
1120 now
= lr_token (ldfile
, charmap
, repertoire
);
1121 if (now
->tok
!= tok_number
)
1123 time
->week_1stweek
= now
->val
.num
;
1125 lr_ignore_rest (ldfile
, 1);
1129 /* Next we assume `LC_TIME'. */
1130 now
= lr_token (ldfile
, charmap
, repertoire
);
1131 if (now
->tok
== tok_eof
)
1133 if (now
->tok
== tok_eol
)
1134 lr_error (ldfile
, _("%s: incomplete `END' line"), "LC_TIME");
1135 else if (now
->tok
!= tok_lc_time
)
1136 lr_error (ldfile
, _("\
1137 %1$s: definition does not end with `END %1$s'"), "LC_TIME");
1138 lr_ignore_rest (ldfile
, now
->tok
== tok_lc_time
);
1143 SYNTAX_ERROR (_("%s: syntax error"), "LC_TIME");
1146 /* Prepare for the next round. */
1147 now
= lr_token (ldfile
, charmap
, repertoire
);
1151 /* When we come here we reached the end of the file. */
1152 lr_error (ldfile
, _("%s: premature end of file"), "LC_TIME");