1 /* Copyright (C) 1995, 1996, 1997, 1998 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, 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. */
27 /* Undefine following line in production version. */
28 /* #define NDEBUG 1 */
33 #include "localeinfo.h"
34 #include "stringtrans.h"
37 (((w) << 24) | (((w) & 0xff00) << 8) | (((w) >> 8) & 0xff00) | ((w) >> 24))
40 extern void *xmalloc (size_t __n
);
41 extern void *xrealloc (void *__p
, size_t __n
);
44 /* Entry describing an entry of the era specification. */
49 int32_t start_date
[3];
56 /* The real definition of the struct for the LC_TIME locale. */
63 const char *abmon
[12];
72 const char *t_fmt_ampm
;
74 u_int32_t cur_num_era
;
76 const char *era_d_t_fmt
;
77 const char *era_t_fmt
;
78 const char *era_d_fmt
;
79 const char *alt_digits
[100];
80 u_int32_t cur_num_alt_digits
;
82 struct era_data
*era_entries
;
83 struct era_data
*era_entries_ob
;
88 time_startup (struct linereader
*lr
, struct localedef_t
*locale
,
89 struct charset_t
*charset
)
91 struct locale_time_t
*time
;
93 /* We have a definition for LC_TIME. */
94 copy_posix
.mask
&= ~(1 << LC_TIME
);
96 /* It is important that we always use UCS1 encoding for strings now. */
97 encoding_method
= ENC_UCS1
;
99 locale
->categories
[LC_TIME
].time
= time
=
100 (struct locale_time_t
*) xmalloc (sizeof (struct locale_time_t
));
102 memset (time
, '\0', sizeof (struct locale_time_t
));
107 time_finish (struct localedef_t
*locale
)
109 struct locale_time_t
*time
= locale
->categories
[LC_TIME
].time
;
111 #define TESTARR_ELEM(cat, max) \
112 if (time->cur_num_##cat == 0 && !be_quiet) \
113 error (0, 0, _("field `%s' in category `%s' undefined"), \
115 else if (time->cur_num_##cat != max && !be_quiet) \
116 error (0, 0, _("field `%s' in category `%s' has not enough values"), \
119 TESTARR_ELEM (abday
, 7);
120 TESTARR_ELEM (day
, 7);
121 TESTARR_ELEM (abmon
, 12);
122 TESTARR_ELEM (mon
, 12);
123 TESTARR_ELEM (am_pm
, 2);
125 #define TEST_ELEM(cat) \
126 if (time->cat == NULL && !be_quiet) \
127 error (0, 0, _("field `%s' in category `%s' undefined"), \
134 /* According to C.Y.Alexis Cheng <alexis@vnet.ibm.com> the T_FMT_AMPM
135 field is optional. */
136 if (time
->t_fmt_ampm
== NULL
)
137 /* Use the 24h format as default. */
138 time
->t_fmt_ampm
= time
->t_fmt
;
140 /* Now process the era entries. */
141 if (time
->cur_num_era
!= 0)
143 const int days_per_month
[12] = { 31, 29, 31, 30, 31, 30,
144 31, 31, 30, 31 ,30, 31 };
148 (struct era_data
*) xmalloc (time
->cur_num_era
149 * sizeof (struct era_data
));
151 for (idx
= 0; idx
< time
->cur_num_era
; ++idx
)
153 size_t era_len
= strlen (time
->era
[idx
]);
154 char *str
= xmalloc ((era_len
+ 1 + 3) & ~3);
157 memcpy (str
, time
->era
[idx
], era_len
+ 1);
159 /* First character must be + or - for the direction. */
160 if (*str
!= '+' && *str
!= '-')
163 error (0, 0, _("direction flag in string %d in `era' field"
164 " in category `%s' is not '+' nor '-'"),
166 /* Default arbitrarily to '+'. */
167 time
->era_entries
[idx
].direction
= '+';
170 time
->era_entries
[idx
].direction
= *str
;
174 error (0, 0, _("direction flag in string %d in `era' field"
175 " in category `%s' is not a single character"),
177 (void) strsep (&str
, ":");
182 /* Now the offset year. */
183 time
->era_entries
[idx
].offset
= strtol (str
, &endp
, 10);
187 error (0, 0, _("illegal number for offset in string %d in"
188 " `era' field in category `%s'"),
190 (void) strsep (&str
, ":");
192 else if (*endp
!= ':')
195 error (0, 0, _("garbage at end of offset value in string %d in"
196 " `era' field in category `%s'"),
198 (void) strsep (&str
, ":");
203 /* Next is the starting date in ISO format. */
204 if (strncmp (str
, "-*", 2) == 0)
206 time
->era_entries
[idx
].start_date
[0] =
207 time
->era_entries
[idx
].start_date
[1] =
208 time
->era_entries
[idx
].start_date
[2] = 0x80000000;
210 goto garbage_start_date
;
213 else if (strncmp (str
, "+*", 2) == 0)
215 time
->era_entries
[idx
].start_date
[0] =
216 time
->era_entries
[idx
].start_date
[1] =
217 time
->era_entries
[idx
].start_date
[2] = 0x7fffffff;
219 goto garbage_start_date
;
224 time
->era_entries
[idx
].start_date
[0] = strtol (str
, &endp
, 10);
225 if (endp
== str
|| *endp
!= '/')
226 goto invalid_start_date
;
229 time
->era_entries
[idx
].start_date
[0] -= 1900;
231 time
->era_entries
[idx
].start_date
[1] = strtol (str
, &endp
, 10);
232 if (endp
== str
|| *endp
!= '/')
233 goto invalid_start_date
;
236 time
->era_entries
[idx
].start_date
[1] -= 1;
238 time
->era_entries
[idx
].start_date
[2] = strtol (str
, &endp
, 10);
243 error (0, 0, _("illegal starting date in string %d in"
244 " `era' field in category `%s'"),
246 (void) strsep (&str
, ":");
248 else if (*endp
!= ':')
252 error (0, 0, _("garbage at end of starting date "
253 "in string %d in `era' field "
256 (void) strsep (&str
, ":");
262 /* Check for valid value. */
263 if ((time
->era_entries
[idx
].start_date
[1] < 0
264 || time
->era_entries
[idx
].start_date
[1] >= 12
265 || time
->era_entries
[idx
].start_date
[2] < 0
266 || (time
->era_entries
[idx
].start_date
[2]
267 > days_per_month
[time
->era_entries
[idx
].start_date
[1]])
268 || (time
->era_entries
[idx
].start_date
[1] == 2
269 && time
->era_entries
[idx
].start_date
[2] == 29
270 && !__isleap (time
->era_entries
[idx
].start_date
[0])))
272 error (0, 0, _("starting date is illegal in"
273 " string %d in `era' field in"
279 /* Next is the stopping date in ISO format. */
280 if (strncmp (str
, "-*", 2) == 0)
282 time
->era_entries
[idx
].stop_date
[0] =
283 time
->era_entries
[idx
].stop_date
[1] =
284 time
->era_entries
[idx
].stop_date
[2] = 0x80000000;
286 goto garbage_stop_date
;
289 else if (strncmp (str
, "+*", 2) == 0)
291 time
->era_entries
[idx
].stop_date
[0] =
292 time
->era_entries
[idx
].stop_date
[1] =
293 time
->era_entries
[idx
].stop_date
[2] = 0x7fffffff;
295 goto garbage_stop_date
;
300 time
->era_entries
[idx
].stop_date
[0] = strtol (str
, &endp
, 10);
301 if (endp
== str
|| *endp
!= '/')
302 goto invalid_stop_date
;
305 time
->era_entries
[idx
].stop_date
[0] -= 1900;
307 time
->era_entries
[idx
].stop_date
[1] = strtol (str
, &endp
, 10);
308 if (endp
== str
|| *endp
!= '/')
309 goto invalid_stop_date
;
312 time
->era_entries
[idx
].stop_date
[1] -= 1;
314 time
->era_entries
[idx
].stop_date
[2] = strtol (str
, &endp
, 10);
319 error (0, 0, _("illegal stopping date in string %d in"
320 " `era' field in category `%s'"),
322 (void) strsep (&str
, ":");
324 else if (*endp
!= ':')
328 error (0, 0, _("garbage at end of stopping date "
329 "in string %d in `era' field "
332 (void) strsep (&str
, ":");
338 /* Check for valid value. */
339 if ((time
->era_entries
[idx
].stop_date
[1] < 0
340 || time
->era_entries
[idx
].stop_date
[1] >= 12
341 || time
->era_entries
[idx
].stop_date
[2] < 0
342 || (time
->era_entries
[idx
].stop_date
[2]
343 > days_per_month
[time
->era_entries
[idx
].stop_date
[1]])
344 || (time
->era_entries
[idx
].stop_date
[1] == 2
345 && time
->era_entries
[idx
].stop_date
[2] == 29
346 && !__isleap (time
->era_entries
[idx
].stop_date
[0])))
348 error (0, 0, _("stopping date is illegal in"
349 " string %d in `era' field in"
355 if (str
== NULL
|| *str
== '\0')
358 error (0, 0, _("missing era name in string %d in `era' field"
359 " in category `%s'"), idx
+ 1, "LC_TIME");
360 time
->era_entries
[idx
].name
=
361 time
->era_entries
[idx
].format
= "";
365 time
->era_entries
[idx
].name
= strsep (&str
, ":");
367 if (str
== NULL
|| *str
== '\0')
370 error (0, 0, _("missing era format in string %d in `era'"
371 " field in category `%s'"),
373 time
->era_entries
[idx
].name
=
374 time
->era_entries
[idx
].format
= "";
377 time
->era_entries
[idx
].format
= str
;
381 /* Construct the array for the other byte order. */
382 time
->era_entries_ob
=
383 (struct era_data
*) xmalloc (time
->cur_num_era
384 * sizeof (struct era_data
));
386 for (idx
= 0; idx
< time
->cur_num_era
; ++idx
)
388 time
->era_entries_ob
[idx
].direction
=
389 SWAPU32 (time
->era_entries
[idx
].direction
);
390 time
->era_entries_ob
[idx
].offset
=
391 SWAPU32 (time
->era_entries
[idx
].offset
);
392 time
->era_entries_ob
[idx
].start_date
[0] =
393 SWAPU32 (time
->era_entries
[idx
].start_date
[0]);
394 time
->era_entries_ob
[idx
].start_date
[1] =
395 SWAPU32 (time
->era_entries
[idx
].start_date
[1]);
396 time
->era_entries_ob
[idx
].start_date
[2] =
397 SWAPU32 (time
->era_entries
[idx
].stop_date
[2]);
398 time
->era_entries_ob
[idx
].stop_date
[0] =
399 SWAPU32 (time
->era_entries
[idx
].stop_date
[0]);
400 time
->era_entries_ob
[idx
].stop_date
[1] =
401 SWAPU32 (time
->era_entries
[idx
].stop_date
[1]);
402 time
->era_entries_ob
[idx
].stop_date
[2] =
403 SWAPU32 (time
->era_entries
[idx
].stop_date
[2]);
404 time
->era_entries_ob
[idx
].name
=
405 time
->era_entries
[idx
].name
;
406 time
->era_entries_ob
[idx
].format
=
407 time
->era_entries
[idx
].format
;
414 time_output (struct localedef_t
*locale
, const char *output_path
)
416 struct locale_time_t
*time
= locale
->categories
[LC_TIME
].time
;
417 struct iovec iov
[2 + _NL_ITEM_INDEX (_NL_NUM_LC_TIME
)
418 + time
->cur_num_era
- 1
419 + time
->cur_num_alt_digits
- 1
420 + 1 + (time
->cur_num_era
* 9 - 1) * 2
421 + (time
->cur_num_era
== 0)];
422 struct locale_file data
;
423 u_int32_t idx
[_NL_ITEM_INDEX (_NL_NUM_LC_TIME
)];
424 size_t cnt
, last_idx
, num
;
426 if ((locale
->binary
& (1 << LC_TIME
)) != 0)
428 iov
[0].iov_base
= time
;
429 iov
[0].iov_len
= locale
->len
[LC_TIME
];
431 write_locale_data (output_path
, "LC_TIME", 1, iov
);
436 data
.magic
= LIMAGIC (LC_TIME
);
437 data
.n
= _NL_ITEM_INDEX (_NL_NUM_LC_TIME
);
438 iov
[0].iov_base
= (void *) &data
;
439 iov
[0].iov_len
= sizeof (data
);
441 iov
[1].iov_base
= (void *) idx
;
442 iov
[1].iov_len
= sizeof (idx
);
444 idx
[0] = iov
[0].iov_len
+ iov
[1].iov_len
;
447 for (cnt
= 0; cnt
<= _NL_ITEM_INDEX (ABDAY_7
); ++cnt
)
449 iov
[2 + cnt
].iov_base
=
450 (void *) (time
->abday
[cnt
- _NL_ITEM_INDEX (ABDAY_1
)] ?: "");
451 iov
[2 + cnt
].iov_len
= strlen (iov
[2 + cnt
].iov_base
) + 1;
452 idx
[1 + cnt
] = idx
[cnt
] + iov
[2 + cnt
].iov_len
;
456 for (; cnt
<= _NL_ITEM_INDEX (DAY_7
); ++cnt
)
458 iov
[2 + cnt
].iov_base
=
459 (void *) (time
->day
[cnt
- _NL_ITEM_INDEX (DAY_1
)] ?: "");
460 iov
[2 + cnt
].iov_len
= strlen (iov
[2 + cnt
].iov_base
) + 1;
461 idx
[1 + cnt
] = idx
[cnt
] + iov
[2 + cnt
].iov_len
;
465 for (; cnt
<= _NL_ITEM_INDEX (ABMON_12
); ++cnt
)
467 iov
[2 + cnt
].iov_base
=
468 (void *) (time
->abmon
[cnt
- _NL_ITEM_INDEX (ABMON_1
)] ?: "");
469 iov
[2 + cnt
].iov_len
= strlen (iov
[2 + cnt
].iov_base
) + 1;
470 idx
[1 + cnt
] = idx
[cnt
] + iov
[2 + cnt
].iov_len
;
474 for (; cnt
<= _NL_ITEM_INDEX (MON_12
); ++cnt
)
476 iov
[2 + cnt
].iov_base
=
477 (void *) (time
->mon
[cnt
- _NL_ITEM_INDEX (MON_1
)] ?: "");
478 iov
[2 + cnt
].iov_len
= strlen (iov
[2 + cnt
].iov_base
) + 1;
479 idx
[1 + cnt
] = idx
[cnt
] + iov
[2 + cnt
].iov_len
;
483 for (; cnt
<= _NL_ITEM_INDEX (PM_STR
); ++cnt
)
485 iov
[2 + cnt
].iov_base
=
486 (void *) (time
->am_pm
[cnt
- _NL_ITEM_INDEX (AM_STR
)] ?: "");
487 iov
[2 + cnt
].iov_len
= strlen (iov
[2 + cnt
].iov_base
) + 1;
488 idx
[1 + cnt
] = idx
[cnt
] + iov
[2 + cnt
].iov_len
;
491 iov
[2 + cnt
].iov_base
= (void *) (time
->d_t_fmt
?: "");
492 iov
[2 + cnt
].iov_len
= strlen (iov
[2 + cnt
].iov_base
) + 1;
493 idx
[1 + cnt
] = idx
[cnt
] + iov
[2 + cnt
].iov_len
;
496 iov
[2 + cnt
].iov_base
= (void *) (time
->d_fmt
?: "");
497 iov
[2 + cnt
].iov_len
= strlen (iov
[2 + cnt
].iov_base
) + 1;
498 idx
[1 + cnt
] = idx
[cnt
] + iov
[2 + cnt
].iov_len
;
501 iov
[2 + cnt
].iov_base
= (void *) (time
->t_fmt
?: "");
502 iov
[2 + cnt
].iov_len
= strlen (iov
[2 + cnt
].iov_base
) + 1;
503 idx
[1 + cnt
] = idx
[cnt
] + iov
[2 + cnt
].iov_len
;
506 iov
[2 + cnt
].iov_base
= (void *) (time
->t_fmt_ampm
?: "");
507 iov
[2 + cnt
].iov_len
= strlen (iov
[2 + cnt
].iov_base
) + 1;
508 idx
[1 + cnt
] = idx
[cnt
] + iov
[2 + cnt
].iov_len
;
511 idx
[1 + last_idx
] = idx
[last_idx
];
512 for (num
= 0; num
< time
->cur_num_era
; ++num
, ++cnt
)
514 iov
[2 + cnt
].iov_base
= (void *) time
->era
[num
];
515 iov
[2 + cnt
].iov_len
= strlen (iov
[2 + cnt
].iov_base
) + 1;
516 idx
[1 + last_idx
] += iov
[2 + cnt
].iov_len
;
520 iov
[2 + cnt
].iov_base
= (void *) (time
->era_year
?: "");
521 iov
[2 + cnt
].iov_len
= strlen (iov
[2 + cnt
].iov_base
) + 1;
522 idx
[1 + last_idx
] = idx
[last_idx
] + iov
[2 + cnt
].iov_len
;
526 iov
[2 + cnt
].iov_base
= (void *) (time
->era_d_fmt
?: "");
527 iov
[2 + cnt
].iov_len
= strlen (iov
[2 + cnt
].iov_base
) + 1;
528 idx
[1 + last_idx
] = idx
[last_idx
] + iov
[2 + cnt
].iov_len
;
532 idx
[1 + last_idx
] = idx
[last_idx
];
533 for (num
= 0; num
< time
->cur_num_alt_digits
; ++num
, ++cnt
)
535 iov
[2 + cnt
].iov_base
= (void *) (time
->alt_digits
[num
] ?: "");
536 iov
[2 + cnt
].iov_len
= strlen (iov
[2 + cnt
].iov_base
) + 1;
537 idx
[1 + last_idx
] += iov
[2 + cnt
].iov_len
;
541 iov
[2 + cnt
].iov_base
= (void *) (time
->era_d_t_fmt
?: "");
542 iov
[2 + cnt
].iov_len
= strlen (iov
[2 + cnt
].iov_base
) + 1;
543 idx
[1 + last_idx
] = idx
[last_idx
] + iov
[2 + cnt
].iov_len
;
547 iov
[2 + cnt
].iov_base
= (void *) (time
->era_t_fmt
?: "");
548 iov
[2 + cnt
].iov_len
= strlen (iov
[2 + cnt
].iov_base
) + 1;
549 idx
[1 + last_idx
] = idx
[last_idx
] + iov
[2 + cnt
].iov_len
;
554 /* We must align the following data. */
555 iov
[2 + cnt
].iov_base
= (void *) "\0\0";
556 iov
[2 + cnt
].iov_len
= ((idx
[last_idx
] + 3) & ~3) - idx
[last_idx
];
557 idx
[last_idx
] = (idx
[last_idx
] + 3) & ~3;
560 iov
[2 + cnt
].iov_base
= (void *) &time
->cur_num_alt_digits
;
561 iov
[2 + cnt
].iov_len
= sizeof (u_int32_t
);
562 idx
[1 + last_idx
] = idx
[last_idx
] + iov
[2 + cnt
].iov_len
;
566 /* The `era' data in usable form. */
567 iov
[2 + cnt
].iov_base
= (void *) &time
->cur_num_era
;
568 iov
[2 + cnt
].iov_len
= sizeof (u_int32_t
);
569 idx
[1 + last_idx
] = idx
[last_idx
] + iov
[2 + cnt
].iov_len
;
573 #if __BYTE_ORDER == __LITTLE_ENDIAN
574 # define ERA_B1 time->era_entries_ob
575 # define ERA_B2 time->era_entries
577 # define ERA_B1 time->era_entries
578 # define ERA_B2 time->era_entries_ob
580 idx
[1 + last_idx
] = idx
[last_idx
];
581 for (num
= 0; num
< time
->cur_num_era
; ++num
)
585 iov
[2 + cnt
].iov_base
= (void *) &ERA_B1
[num
].direction
;
586 iov
[2 + cnt
].iov_len
= sizeof (int32_t);
588 iov
[2 + cnt
].iov_base
= (void *) &ERA_B1
[num
].offset
;
589 iov
[2 + cnt
].iov_len
= sizeof (int32_t);
591 iov
[2 + cnt
].iov_base
= (void *) &ERA_B1
[num
].start_date
[0];
592 iov
[2 + cnt
].iov_len
= sizeof (int32_t);
594 iov
[2 + cnt
].iov_base
= (void *) &ERA_B1
[num
].start_date
[1];
595 iov
[2 + cnt
].iov_len
= sizeof (int32_t);
597 iov
[2 + cnt
].iov_base
= (void *) &ERA_B1
[num
].start_date
[2];
598 iov
[2 + cnt
].iov_len
= sizeof (int32_t);
600 iov
[2 + cnt
].iov_base
= (void *) &ERA_B1
[num
].stop_date
[0];
601 iov
[2 + cnt
].iov_len
= sizeof (int32_t);
603 iov
[2 + cnt
].iov_base
= (void *) &ERA_B1
[num
].stop_date
[1];
604 iov
[2 + cnt
].iov_len
= sizeof (int32_t);
606 iov
[2 + cnt
].iov_base
= (void *) &ERA_B1
[num
].stop_date
[2];
607 iov
[2 + cnt
].iov_len
= sizeof (int32_t);
610 l
= (strchr (ERA_B1
[num
].format
, '\0') - ERA_B1
[num
].name
) + 1;
612 iov
[2 + cnt
].iov_base
= (void *) ERA_B1
[num
].name
;
613 iov
[2 + cnt
].iov_len
= l
;
616 idx
[1 + last_idx
] += 8 * sizeof (int32_t) + l
;
618 assert (idx
[1 + last_idx
] % 4 == 0);
622 /* idx[1 + last_idx] = idx[last_idx]; */
623 for (num
= 0; num
< time
->cur_num_era
; ++num
)
627 iov
[2 + cnt
].iov_base
= (void *) &ERA_B2
[num
].direction
;
628 iov
[2 + cnt
].iov_len
= sizeof (int32_t);
630 iov
[2 + cnt
].iov_base
= (void *) &ERA_B2
[num
].offset
;
631 iov
[2 + cnt
].iov_len
= sizeof (int32_t);
633 iov
[2 + cnt
].iov_base
= (void *) &ERA_B2
[num
].start_date
[0];
634 iov
[2 + cnt
].iov_len
= sizeof (int32_t);
636 iov
[2 + cnt
].iov_base
= (void *) &ERA_B2
[num
].start_date
[1];
637 iov
[2 + cnt
].iov_len
= sizeof (int32_t);
639 iov
[2 + cnt
].iov_base
= (void *) &ERA_B2
[num
].start_date
[2];
640 iov
[2 + cnt
].iov_len
= sizeof (int32_t);
642 iov
[2 + cnt
].iov_base
= (void *) &ERA_B2
[num
].stop_date
[0];
643 iov
[2 + cnt
].iov_len
= sizeof (int32_t);
645 iov
[2 + cnt
].iov_base
= (void *) &ERA_B2
[num
].stop_date
[1];
646 iov
[2 + cnt
].iov_len
= sizeof (int32_t);
648 iov
[2 + cnt
].iov_base
= (void *) &ERA_B2
[num
].stop_date
[2];
649 iov
[2 + cnt
].iov_len
= sizeof (int32_t);
652 l
= (strchr (ERA_B2
[num
].format
, '\0') - ERA_B2
[num
].name
) + 1;
654 iov
[2 + cnt
].iov_base
= (void *) ERA_B2
[num
].name
;
655 iov
[2 + cnt
].iov_len
= l
;
658 /* idx[1 + last_idx] += 8 * sizeof (int32_t) + l; */
661 /* We have a problem when no era data is present. In this case the
662 data pointer for _NL_TIME_ERA_ENTRIES_EB and
663 _NL_TIME_ERA_ENTRIES_EL point after the end of the file. So we
664 introduce some dummy data here. */
665 if (time
->cur_num_era
== 0)
667 static u_int32_t dummy
= 0;
668 iov
[2 + cnt
].iov_base
= (void *) &dummy
;
669 iov
[2 + cnt
].iov_len
= 4;
673 assert (cnt
== (_NL_ITEM_INDEX (_NL_NUM_LC_TIME
)
674 + time
->cur_num_era
- 1
675 + time
->cur_num_alt_digits
- 1
676 + 1 + (time
->cur_num_era
* 9 - 1) * 2
677 + (time
->cur_num_era
== 0))
678 && last_idx
+ 1 == _NL_ITEM_INDEX (_NL_NUM_LC_TIME
));
680 write_locale_data (output_path
, "LC_TIME", 2 + cnt
, iov
);
685 time_add (struct linereader
*lr
, struct localedef_t
*locale
,
686 enum token_t tok
, struct token
*code
,
687 struct charset_t
*charset
)
689 struct locale_time_t
*time
= locale
->categories
[LC_TIME
].time
;
693 #define STRARR_ELEM(cat, max) \
695 if (time->cur_num_##cat >= max) \
697 too many values for field `%s' in category `%s'"), \
699 else if (code->val.str.start == NULL) \
701 lr_error (lr, _("unknown character in field `%s' of category `%s'"),\
703 time->cat[time->cur_num_##cat++] = ""; \
706 time->cat[time->cur_num_##cat++] = code->val.str.start; \
709 STRARR_ELEM (abday
, 7);
710 STRARR_ELEM (day
, 7);
711 STRARR_ELEM (abmon
, 12);
712 STRARR_ELEM (mon
, 12);
713 STRARR_ELEM (am_pm
, 2);
714 STRARR_ELEM (alt_digits
, 100);
717 if (code
->val
.str
.start
== NULL
)
718 lr_error (lr
, _("unknown character in field `%s' of category `%s'"),
723 time
->era
= xrealloc (time
->era
,
724 time
->cur_num_era
* sizeof (char *));
725 time
->era
[time
->cur_num_era
- 1] = code
->val
.str
.start
;
729 #define STR_ELEM(cat) \
731 if (time->cat != NULL) \
733 field `%s' in category `%s' declared more than once"), \
735 else if (code->val.str.start == NULL) \
737 lr_error (lr, _("unknown character in field `%s' of category `%s'"),\
742 time->cat = code->val.str.start; \
748 STR_ELEM (t_fmt_ampm
);
750 STR_ELEM (era_d_t_fmt
);
751 STR_ELEM (era_d_fmt
);
752 STR_ELEM (era_t_fmt
);
755 assert (! "unknown token in category `LC_TIME': should not happen");