]> sourceware.org Git - glibc.git/blob - locale/programs/ld-time.c
Update.
[glibc.git] / locale / programs / ld-time.c
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.ai.mit.edu>, 1995.
4
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.
9
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.
14
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. */
19
20 #ifdef HAVE_CONFIG_H
21 # include <config.h>
22 #endif
23
24 #include <langinfo.h>
25 #include <string.h>
26
27 /* Undefine following line in production version. */
28 /* #define NDEBUG 1 */
29 #include <assert.h>
30 #include <stdlib.h>
31
32 #include "locales.h"
33 #include "localeinfo.h"
34 #include "stringtrans.h"
35
36 #define SWAPU32(w) \
37 (((w) << 24) | (((w) & 0xff00) << 8) | (((w) >> 8) & 0xff00) | ((w) >> 24))
38
39
40 extern void *xmalloc (size_t __n);
41 extern void *xrealloc (void *__p, size_t __n);
42
43
44 /* Entry describing an entry of the era specification. */
45 struct era_data
46 {
47 int32_t direction;
48 int32_t offset;
49 int32_t start_date[3];
50 int32_t stop_date[3];
51 const char *name;
52 const char *format;
53 };
54
55
56 /* The real definition of the struct for the LC_TIME locale. */
57 struct locale_time_t
58 {
59 const char *abday[7];
60 size_t cur_num_abday;
61 const char *day[7];
62 size_t cur_num_day;
63 const char *abmon[12];
64 size_t cur_num_abmon;
65 const char *mon[12];
66 size_t cur_num_mon;
67 const char *am_pm[2];
68 size_t cur_num_am_pm;
69 const char *d_t_fmt;
70 const char *d_fmt;
71 const char *t_fmt;
72 const char *t_fmt_ampm;
73 const char **era;
74 u_int32_t cur_num_era;
75 const char *era_year;
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;
81
82 struct era_data *era_entries;
83 struct era_data *era_entries_ob;
84 };
85
86
87 void
88 time_startup (struct linereader *lr, struct localedef_t *locale,
89 struct charset_t *charset)
90 {
91 struct locale_time_t *time;
92
93 /* We have a definition for LC_TIME. */
94 copy_posix.mask &= ~(1 << LC_TIME);
95
96 /* It is important that we always use UCS1 encoding for strings now. */
97 encoding_method = ENC_UCS1;
98
99 locale->categories[LC_TIME].time = time =
100 (struct locale_time_t *) xmalloc (sizeof (struct locale_time_t));
101
102 memset (time, '\0', sizeof (struct locale_time_t));
103 }
104
105
106 void
107 time_finish (struct localedef_t *locale)
108 {
109 struct locale_time_t *time = locale->categories[LC_TIME].time;
110
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"), \
114 #cat, "LC_TIME"); \
115 else if (time->cur_num_##cat != max && !be_quiet) \
116 error (0, 0, _("field `%s' in category `%s' has not enough values"), \
117 #cat, "LC_TIME")
118
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);
124
125 #define TEST_ELEM(cat) \
126 if (time->cat == NULL && !be_quiet) \
127 error (0, 0, _("field `%s' in category `%s' undefined"), \
128 #cat, "LC_TIME")
129
130 TEST_ELEM (d_t_fmt);
131 TEST_ELEM (d_fmt);
132 TEST_ELEM (t_fmt);
133
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;
139
140 /* Now process the era entries. */
141 if (time->cur_num_era != 0)
142 {
143 const int days_per_month[12] = { 31, 29, 31, 30, 31, 30,
144 31, 31, 30, 31 ,30, 31 };
145 size_t idx;
146
147 time->era_entries =
148 (struct era_data *) xmalloc (time->cur_num_era
149 * sizeof (struct era_data));
150
151 for (idx = 0; idx < time->cur_num_era; ++idx)
152 {
153 size_t era_len = strlen (time->era[idx]);
154 char *str = xmalloc ((era_len + 1 + 3) & ~3);
155 char *endp;
156
157 memcpy (str, time->era[idx], era_len + 1);
158
159 /* First character must be + or - for the direction. */
160 if (*str != '+' && *str != '-')
161 {
162 if (!be_quiet)
163 error (0, 0, _("direction flag in string %d in `era' field"
164 " in category `%s' is not '+' nor '-'"),
165 idx + 1, "LC_TIME");
166 /* Default arbitrarily to '+'. */
167 time->era_entries[idx].direction = '+';
168 }
169 else
170 time->era_entries[idx].direction = *str;
171 if (*++str != ':')
172 {
173 if (!be_quiet)
174 error (0, 0, _("direction flag in string %d in `era' field"
175 " in category `%s' is not a single character"),
176 idx + 1, "LC_TIME");
177 (void) strsep (&str, ":");
178 }
179 else
180 ++str;
181
182 /* Now the offset year. */
183 time->era_entries[idx].offset = strtol (str, &endp, 10);
184 if (endp == str)
185 {
186 if (!be_quiet)
187 error (0, 0, _("illegal number for offset in string %d in"
188 " `era' field in category `%s'"),
189 idx + 1, "LC_TIME");
190 (void) strsep (&str, ":");
191 }
192 else if (*endp != ':')
193 {
194 if (!be_quiet)
195 error (0, 0, _("garbage at end of offset value in string %d in"
196 " `era' field in category `%s'"),
197 idx + 1, "LC_TIME");
198 (void) strsep (&str, ":");
199 }
200 else
201 str = endp + 1;
202
203 /* Next is the starting date in ISO format. */
204 if (strncmp (str, "-*", 2) == 0)
205 {
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;
209 if (str[2] != ':')
210 goto garbage_start_date;
211 str += 3;
212 }
213 else if (strncmp (str, "+*", 2) == 0)
214 {
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;
218 if (str[2] != ':')
219 goto garbage_start_date;
220 str += 3;
221 }
222 else
223 {
224 time->era_entries[idx].start_date[0] = strtol (str, &endp, 10);
225 if (endp == str || *endp != '/')
226 goto invalid_start_date;
227 else
228 str = endp + 1;
229 time->era_entries[idx].start_date[0] -= 1900;
230
231 time->era_entries[idx].start_date[1] = strtol (str, &endp, 10);
232 if (endp == str || *endp != '/')
233 goto invalid_start_date;
234 else
235 str = endp + 1;
236 time->era_entries[idx].start_date[1] -= 1;
237
238 time->era_entries[idx].start_date[2] = strtol (str, &endp, 10);
239 if (endp == str)
240 {
241 invalid_start_date:
242 if (!be_quiet)
243 error (0, 0, _("illegal starting date in string %d in"
244 " `era' field in category `%s'"),
245 idx + 1, "LC_TIME");
246 (void) strsep (&str, ":");
247 }
248 else if (*endp != ':')
249 {
250 garbage_start_date:
251 if (!be_quiet)
252 error (0, 0, _("garbage at end of starting date "
253 "in string %d in `era' field "
254 "in category `%s'"),
255 idx + 1, "LC_TIME");
256 (void) strsep (&str, ":");
257 }
258 else
259 {
260 str = endp + 1;
261
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])))
271 && !be_quiet)
272 error (0, 0, _("starting date is illegal in"
273 " string %d in `era' field in"
274 " category `%s'"),
275 idx + 1, "LC_TIME");
276 }
277 }
278
279 /* Next is the stopping date in ISO format. */
280 if (strncmp (str, "-*", 2) == 0)
281 {
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;
285 if (str[2] != ':')
286 goto garbage_stop_date;
287 str += 3;
288 }
289 else if (strncmp (str, "+*", 2) == 0)
290 {
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;
294 if (str[2] != ':')
295 goto garbage_stop_date;
296 str += 3;
297 }
298 else
299 {
300 time->era_entries[idx].stop_date[0] = strtol (str, &endp, 10);
301 if (endp == str || *endp != '/')
302 goto invalid_stop_date;
303 else
304 str = endp + 1;
305 time->era_entries[idx].stop_date[0] -= 1900;
306
307 time->era_entries[idx].stop_date[1] = strtol (str, &endp, 10);
308 if (endp == str || *endp != '/')
309 goto invalid_stop_date;
310 else
311 str = endp + 1;
312 time->era_entries[idx].stop_date[1] -= 1;
313
314 time->era_entries[idx].stop_date[2] = strtol (str, &endp, 10);
315 if (endp == str)
316 {
317 invalid_stop_date:
318 if (!be_quiet)
319 error (0, 0, _("illegal stopping date in string %d in"
320 " `era' field in category `%s'"),
321 idx + 1, "LC_TIME");
322 (void) strsep (&str, ":");
323 }
324 else if (*endp != ':')
325 {
326 garbage_stop_date:
327 if (!be_quiet)
328 error (0, 0, _("garbage at end of stopping date "
329 "in string %d in `era' field "
330 "in category `%s'"),
331 idx + 1, "LC_TIME");
332 (void) strsep (&str, ":");
333 }
334 else
335 {
336 str = endp + 1;
337
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])))
347 && !be_quiet)
348 error (0, 0, _("stopping date is illegal in"
349 " string %d in `era' field in"
350 " category `%s'"),
351 idx + 1, "LC_TIME");
352 }
353 }
354
355 if (str == NULL || *str == '\0')
356 {
357 if (!be_quiet)
358 error (0, 0, _("missing era name in string %d in `era' field"
359 " in category `%s'"), idx + 1, "LC_TIME");
360 /* Make sure that name and format are adjacent strings
361 in memory. */
362 time->era_entries[idx].name = "\0";
363 time->era_entries[idx].format
364 = time->era_entries[idx].name + 1;
365 }
366 else
367 {
368 time->era_entries[idx].name = strsep (&str, ":");
369
370 if (str == NULL || *str == '\0')
371 {
372 if (!be_quiet)
373 error (0, 0, _("missing era format in string %d in `era'"
374 " field in category `%s'"),
375 idx + 1, "LC_TIME");
376 /* Make sure that name and format are adjacent strings
377 in memory. */
378 time->era_entries[idx].name = "\0";
379 time->era_entries[idx].format
380 = time->era_entries[idx].name + 1;
381 }
382 else
383 time->era_entries[idx].format = str;
384 }
385 }
386
387 /* Construct the array for the other byte order. */
388 time->era_entries_ob =
389 (struct era_data *) xmalloc (time->cur_num_era
390 * sizeof (struct era_data));
391
392 for (idx = 0; idx < time->cur_num_era; ++idx)
393 {
394 time->era_entries_ob[idx].direction =
395 SWAPU32 (time->era_entries[idx].direction);
396 time->era_entries_ob[idx].offset =
397 SWAPU32 (time->era_entries[idx].offset);
398 time->era_entries_ob[idx].start_date[0] =
399 SWAPU32 (time->era_entries[idx].start_date[0]);
400 time->era_entries_ob[idx].start_date[1] =
401 SWAPU32 (time->era_entries[idx].start_date[1]);
402 time->era_entries_ob[idx].start_date[2] =
403 SWAPU32 (time->era_entries[idx].stop_date[2]);
404 time->era_entries_ob[idx].stop_date[0] =
405 SWAPU32 (time->era_entries[idx].stop_date[0]);
406 time->era_entries_ob[idx].stop_date[1] =
407 SWAPU32 (time->era_entries[idx].stop_date[1]);
408 time->era_entries_ob[idx].stop_date[2] =
409 SWAPU32 (time->era_entries[idx].stop_date[2]);
410 time->era_entries_ob[idx].name =
411 time->era_entries[idx].name;
412 time->era_entries_ob[idx].format =
413 time->era_entries[idx].format;
414 }
415 }
416 }
417
418
419 void
420 time_output (struct localedef_t *locale, const char *output_path)
421 {
422 struct locale_time_t *time = locale->categories[LC_TIME].time;
423 struct iovec iov[2 + _NL_ITEM_INDEX (_NL_NUM_LC_TIME)
424 + time->cur_num_era - 1
425 + time->cur_num_alt_digits - 1
426 + 1 + (time->cur_num_era * 9 - 1) * 2
427 + (time->cur_num_era == 0)];
428 struct locale_file data;
429 u_int32_t idx[_NL_ITEM_INDEX (_NL_NUM_LC_TIME)];
430 size_t cnt, last_idx, num;
431
432 if ((locale->binary & (1 << LC_TIME)) != 0)
433 {
434 iov[0].iov_base = time;
435 iov[0].iov_len = locale->len[LC_TIME];
436
437 write_locale_data (output_path, "LC_TIME", 1, iov);
438
439 return;
440 }
441
442 data.magic = LIMAGIC (LC_TIME);
443 data.n = _NL_ITEM_INDEX (_NL_NUM_LC_TIME);
444 iov[0].iov_base = (void *) &data;
445 iov[0].iov_len = sizeof (data);
446
447 iov[1].iov_base = (void *) idx;
448 iov[1].iov_len = sizeof (idx);
449
450 idx[0] = iov[0].iov_len + iov[1].iov_len;
451
452 /* The ab'days. */
453 for (cnt = 0; cnt <= _NL_ITEM_INDEX (ABDAY_7); ++cnt)
454 {
455 iov[2 + cnt].iov_base =
456 (void *) (time->abday[cnt - _NL_ITEM_INDEX (ABDAY_1)] ?: "");
457 iov[2 + cnt].iov_len = strlen (iov[2 + cnt].iov_base) + 1;
458 idx[1 + cnt] = idx[cnt] + iov[2 + cnt].iov_len;
459 }
460
461 /* The days. */
462 for (; cnt <= _NL_ITEM_INDEX (DAY_7); ++cnt)
463 {
464 iov[2 + cnt].iov_base =
465 (void *) (time->day[cnt - _NL_ITEM_INDEX (DAY_1)] ?: "");
466 iov[2 + cnt].iov_len = strlen (iov[2 + cnt].iov_base) + 1;
467 idx[1 + cnt] = idx[cnt] + iov[2 + cnt].iov_len;
468 }
469
470 /* The ab'mons. */
471 for (; cnt <= _NL_ITEM_INDEX (ABMON_12); ++cnt)
472 {
473 iov[2 + cnt].iov_base =
474 (void *) (time->abmon[cnt - _NL_ITEM_INDEX (ABMON_1)] ?: "");
475 iov[2 + cnt].iov_len = strlen (iov[2 + cnt].iov_base) + 1;
476 idx[1 + cnt] = idx[cnt] + iov[2 + cnt].iov_len;
477 }
478
479 /* The mons. */
480 for (; cnt <= _NL_ITEM_INDEX (MON_12); ++cnt)
481 {
482 iov[2 + cnt].iov_base =
483 (void *) (time->mon[cnt - _NL_ITEM_INDEX (MON_1)] ?: "");
484 iov[2 + cnt].iov_len = strlen (iov[2 + cnt].iov_base) + 1;
485 idx[1 + cnt] = idx[cnt] + iov[2 + cnt].iov_len;
486 }
487
488 /* AM/PM. */
489 for (; cnt <= _NL_ITEM_INDEX (PM_STR); ++cnt)
490 {
491 iov[2 + cnt].iov_base =
492 (void *) (time->am_pm[cnt - _NL_ITEM_INDEX (AM_STR)] ?: "");
493 iov[2 + cnt].iov_len = strlen (iov[2 + cnt].iov_base) + 1;
494 idx[1 + cnt] = idx[cnt] + iov[2 + cnt].iov_len;
495 }
496
497 iov[2 + cnt].iov_base = (void *) (time->d_t_fmt ?: "");
498 iov[2 + cnt].iov_len = strlen (iov[2 + cnt].iov_base) + 1;
499 idx[1 + cnt] = idx[cnt] + iov[2 + cnt].iov_len;
500 ++cnt;
501
502 iov[2 + cnt].iov_base = (void *) (time->d_fmt ?: "");
503 iov[2 + cnt].iov_len = strlen (iov[2 + cnt].iov_base) + 1;
504 idx[1 + cnt] = idx[cnt] + iov[2 + cnt].iov_len;
505 ++cnt;
506
507 iov[2 + cnt].iov_base = (void *) (time->t_fmt ?: "");
508 iov[2 + cnt].iov_len = strlen (iov[2 + cnt].iov_base) + 1;
509 idx[1 + cnt] = idx[cnt] + iov[2 + cnt].iov_len;
510 ++cnt;
511
512 iov[2 + cnt].iov_base = (void *) (time->t_fmt_ampm ?: "");
513 iov[2 + cnt].iov_len = strlen (iov[2 + cnt].iov_base) + 1;
514 idx[1 + cnt] = idx[cnt] + iov[2 + cnt].iov_len;
515 last_idx = ++cnt;
516
517 idx[1 + last_idx] = idx[last_idx];
518 for (num = 0; num < time->cur_num_era; ++num, ++cnt)
519 {
520 iov[2 + cnt].iov_base = (void *) time->era[num];
521 iov[2 + cnt].iov_len = strlen (iov[2 + cnt].iov_base) + 1;
522 idx[1 + last_idx] += iov[2 + cnt].iov_len;
523 }
524 ++last_idx;
525
526 iov[2 + cnt].iov_base = (void *) (time->era_year ?: "");
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;
529 ++cnt;
530 ++last_idx;
531
532 iov[2 + cnt].iov_base = (void *) (time->era_d_fmt ?: "");
533 iov[2 + cnt].iov_len = strlen (iov[2 + cnt].iov_base) + 1;
534 idx[1 + last_idx] = idx[last_idx] + iov[2 + cnt].iov_len;
535 ++cnt;
536 ++last_idx;
537
538 idx[1 + last_idx] = idx[last_idx];
539 for (num = 0; num < time->cur_num_alt_digits; ++num, ++cnt)
540 {
541 iov[2 + cnt].iov_base = (void *) (time->alt_digits[num] ?: "");
542 iov[2 + cnt].iov_len = strlen (iov[2 + cnt].iov_base) + 1;
543 idx[1 + last_idx] += iov[2 + cnt].iov_len;
544 }
545 ++last_idx;
546
547 iov[2 + cnt].iov_base = (void *) (time->era_d_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;
550 ++cnt;
551 ++last_idx;
552
553 iov[2 + cnt].iov_base = (void *) (time->era_t_fmt ?: "");
554 iov[2 + cnt].iov_len = strlen (iov[2 + cnt].iov_base) + 1;
555 idx[1 + last_idx] = idx[last_idx] + iov[2 + cnt].iov_len;
556 ++cnt;
557 ++last_idx;
558
559
560 /* We must align the following data. */
561 iov[2 + cnt].iov_base = (void *) "\0\0";
562 iov[2 + cnt].iov_len = ((idx[last_idx] + 3) & ~3) - idx[last_idx];
563 idx[last_idx] = (idx[last_idx] + 3) & ~3;
564 ++cnt;
565
566 iov[2 + cnt].iov_base = (void *) &time->cur_num_alt_digits;
567 iov[2 + cnt].iov_len = sizeof (u_int32_t);
568 idx[1 + last_idx] = idx[last_idx] + iov[2 + cnt].iov_len;
569 ++cnt;
570 ++last_idx;
571
572 /* The `era' data in usable form. */
573 iov[2 + cnt].iov_base = (void *) &time->cur_num_era;
574 iov[2 + cnt].iov_len = sizeof (u_int32_t);
575 idx[1 + last_idx] = idx[last_idx] + iov[2 + cnt].iov_len;
576 ++cnt;
577 ++last_idx;
578
579 #if __BYTE_ORDER == __LITTLE_ENDIAN
580 # define ERA_B1 time->era_entries_ob
581 # define ERA_B2 time->era_entries
582 #else
583 # define ERA_B1 time->era_entries
584 # define ERA_B2 time->era_entries_ob
585 #endif
586 idx[1 + last_idx] = idx[last_idx];
587 for (num = 0; num < time->cur_num_era; ++num)
588 {
589 size_t l;
590
591 iov[2 + cnt].iov_base = (void *) &ERA_B1[num].direction;
592 iov[2 + cnt].iov_len = sizeof (int32_t);
593 ++cnt;
594 iov[2 + cnt].iov_base = (void *) &ERA_B1[num].offset;
595 iov[2 + cnt].iov_len = sizeof (int32_t);
596 ++cnt;
597 iov[2 + cnt].iov_base = (void *) &ERA_B1[num].start_date[0];
598 iov[2 + cnt].iov_len = 3 * sizeof (int32_t);
599 ++cnt;
600 iov[2 + cnt].iov_base = (void *) &ERA_B1[num].stop_date[0];
601 iov[2 + cnt].iov_len = 3 * sizeof (int32_t);
602 ++cnt;
603
604 l = (strchr (ERA_B1[num].format, '\0') - ERA_B1[num].name) + 1;
605 l = (l + 3) & ~3;
606 iov[2 + cnt].iov_base = (void *) ERA_B1[num].name;
607 iov[2 + cnt].iov_len = l;
608 ++cnt;
609
610 idx[1 + last_idx] += 8 * sizeof (int32_t) + l;
611
612 assert (idx[1 + last_idx] % 4 == 0);
613 }
614 ++last_idx;
615
616 /* idx[1 + last_idx] = idx[last_idx]; */
617 for (num = 0; num < time->cur_num_era; ++num)
618 {
619 size_t l;
620
621 iov[2 + cnt].iov_base = (void *) &ERA_B2[num].direction;
622 iov[2 + cnt].iov_len = sizeof (int32_t);
623 ++cnt;
624 iov[2 + cnt].iov_base = (void *) &ERA_B2[num].offset;
625 iov[2 + cnt].iov_len = sizeof (int32_t);
626 ++cnt;
627 iov[2 + cnt].iov_base = (void *) &ERA_B2[num].start_date[0];
628 iov[2 + cnt].iov_len = 3 * sizeof (int32_t);
629 ++cnt;
630 iov[2 + cnt].iov_base = (void *) &ERA_B2[num].stop_date[0];
631 iov[2 + cnt].iov_len = 3 * sizeof (int32_t);
632 ++cnt;
633
634 l = (strchr (ERA_B2[num].format, '\0') - ERA_B2[num].name) + 1;
635 l = (l + 3) & ~3;
636 iov[2 + cnt].iov_base = (void *) ERA_B2[num].name;
637 iov[2 + cnt].iov_len = l;
638 ++cnt;
639
640 /* idx[1 + last_idx] += 8 * sizeof (int32_t) + l; */
641 }
642
643 /* We have a problem when no era data is present. In this case the
644 data pointer for _NL_TIME_ERA_ENTRIES_EB and
645 _NL_TIME_ERA_ENTRIES_EL point after the end of the file. So we
646 introduce some dummy data here. */
647 if (time->cur_num_era == 0)
648 {
649 static u_int32_t dummy = 0;
650 iov[2 + cnt].iov_base = (void *) &dummy;
651 iov[2 + cnt].iov_len = 4;
652 ++cnt;
653 }
654
655 assert (cnt == (_NL_ITEM_INDEX (_NL_NUM_LC_TIME)
656 + time->cur_num_era - 1
657 + time->cur_num_alt_digits - 1
658 + 1 + (time->cur_num_era * 9 - 1) * 2
659 + (time->cur_num_era == 0))
660 && last_idx + 1 == _NL_ITEM_INDEX (_NL_NUM_LC_TIME));
661
662 write_locale_data (output_path, "LC_TIME", 2 + cnt, iov);
663 }
664
665
666 void
667 time_add (struct linereader *lr, struct localedef_t *locale,
668 enum token_t tok, struct token *code,
669 struct charset_t *charset)
670 {
671 struct locale_time_t *time = locale->categories[LC_TIME].time;
672
673 switch (tok)
674 {
675 #define STRARR_ELEM(cat, max) \
676 case tok_##cat: \
677 if (time->cur_num_##cat >= max) \
678 lr_error (lr, _("\
679 too many values for field `%s' in category `%s'"), \
680 #cat, "LC_TIME"); \
681 else if (code->val.str.start == NULL) \
682 { \
683 lr_error (lr, _("unknown character in field `%s' of category `%s'"),\
684 #cat, "LC_TIME"); \
685 time->cat[time->cur_num_##cat++] = ""; \
686 } \
687 else \
688 time->cat[time->cur_num_##cat++] = code->val.str.start; \
689 break
690
691 STRARR_ELEM (abday, 7);
692 STRARR_ELEM (day, 7);
693 STRARR_ELEM (abmon, 12);
694 STRARR_ELEM (mon, 12);
695 STRARR_ELEM (am_pm, 2);
696 STRARR_ELEM (alt_digits, 100);
697
698 case tok_era:
699 if (code->val.str.start == NULL)
700 lr_error (lr, _("unknown character in field `%s' of category `%s'"),
701 "era", "LC_TIME");
702 else
703 {
704 ++time->cur_num_era;
705 time->era = xrealloc (time->era,
706 time->cur_num_era * sizeof (char *));
707 time->era[time->cur_num_era - 1] = code->val.str.start;
708 }
709 break;
710
711 #define STR_ELEM(cat) \
712 case tok_##cat: \
713 if (time->cat != NULL) \
714 lr_error (lr, _("\
715 field `%s' in category `%s' declared more than once"), \
716 #cat, "LC_TIME"); \
717 else if (code->val.str.start == NULL) \
718 { \
719 lr_error (lr, _("unknown character in field `%s' of category `%s'"),\
720 #cat, "LC_TIME"); \
721 time->cat = ""; \
722 } \
723 else \
724 time->cat = code->val.str.start; \
725 break
726
727 STR_ELEM (d_t_fmt);
728 STR_ELEM (d_fmt);
729 STR_ELEM (t_fmt);
730 STR_ELEM (t_fmt_ampm);
731 STR_ELEM (era_year);
732 STR_ELEM (era_d_t_fmt);
733 STR_ELEM (era_d_fmt);
734 STR_ELEM (era_t_fmt);
735
736 default:
737 assert (! "unknown token in category `LC_TIME': should not happen");
738 }
739 }
This page took 0.076019 seconds and 5 git commands to generate.