Back to index

glibc  2.9
ld-time.c
Go to the documentation of this file.
00001 /* Copyright (C) 1995-2005, 2006, 2007, 2008 Free Software Foundation, Inc.
00002    This file is part of the GNU C Library.
00003    Contributed by Ulrich Drepper <drepper@gnu.org>, 1995.
00004 
00005    This program is free software; you can redistribute it and/or modify
00006    it under the terms of the GNU General Public License as published
00007    by the Free Software Foundation; version 2 of the License, or
00008    (at your option) any later version.
00009 
00010    This program is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013    GNU General Public License for more details.
00014 
00015    You should have received a copy of the GNU General Public License
00016    along with this program; if not, write to the Free Software Foundation,
00017    Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
00018 
00019 #ifdef HAVE_CONFIG_H
00020 # include <config.h>
00021 #endif
00022 
00023 #include <byteswap.h>
00024 #include <langinfo.h>
00025 #include <stdlib.h>
00026 #include <string.h>
00027 #include <wchar.h>
00028 #include <sys/uio.h>
00029 
00030 #include <assert.h>
00031 
00032 #include "localedef.h"
00033 #include "linereader.h"
00034 #include "localeinfo.h"
00035 #include "locfile.h"
00036 
00037 
00038 /* Entry describing an entry of the era specification.  */
00039 struct era_data
00040 {
00041   int32_t direction;
00042   int32_t offset;
00043   int32_t start_date[3];
00044   int32_t stop_date[3];
00045   const char *name;
00046   const char *format;
00047   uint32_t *wname;
00048   uint32_t *wformat;
00049 };
00050 
00051 
00052 /* The real definition of the struct for the LC_TIME locale.  */
00053 struct locale_time_t
00054 {
00055   const char *abday[7];
00056   const uint32_t *wabday[7];
00057   int abday_defined;
00058   const char *day[7];
00059   const uint32_t *wday[7];
00060   int day_defined;
00061   const char *abmon[12];
00062   const uint32_t *wabmon[12];
00063   int abmon_defined;
00064   const char *mon[12];
00065   const uint32_t *wmon[12];
00066   int mon_defined;
00067   const char *am_pm[2];
00068   const uint32_t *wam_pm[2];
00069   int am_pm_defined;
00070   const char *d_t_fmt;
00071   const uint32_t *wd_t_fmt;
00072   const char *d_fmt;
00073   const uint32_t *wd_fmt;
00074   const char *t_fmt;
00075   const uint32_t *wt_fmt;
00076   const char *t_fmt_ampm;
00077   const uint32_t *wt_fmt_ampm;
00078   const char **era;
00079   const uint32_t **wera;
00080   uint32_t num_era;
00081   const char *era_year;
00082   const uint32_t *wera_year;
00083   const char *era_d_t_fmt;
00084   const uint32_t *wera_d_t_fmt;
00085   const char *era_t_fmt;
00086   const uint32_t *wera_t_fmt;
00087   const char *era_d_fmt;
00088   const uint32_t *wera_d_fmt;
00089   const char *alt_digits[100];
00090   const uint32_t *walt_digits[100];
00091   const char *date_fmt;
00092   const uint32_t *wdate_fmt;
00093   int alt_digits_defined;
00094   unsigned char week_ndays;
00095   uint32_t week_1stday;
00096   unsigned char week_1stweek;
00097   unsigned char first_weekday;
00098   unsigned char first_workday;
00099   unsigned char cal_direction;
00100   const char *timezone;
00101   const uint32_t *wtimezone;
00102 
00103   struct era_data *era_entries;
00104 };
00105 
00106 
00107 /* This constant is used to represent an empty wide character string.  */
00108 static const uint32_t empty_wstr[1] = { 0 };
00109 
00110 
00111 static void
00112 time_startup (struct linereader *lr, struct localedef_t *locale,
00113              int ignore_content)
00114 {
00115   if (!ignore_content)
00116     locale->categories[LC_TIME].time =
00117       (struct locale_time_t *) xcalloc (1, sizeof (struct locale_time_t));
00118 
00119   if (lr != NULL)
00120     {
00121       lr->translate_strings = 1;
00122       lr->return_widestr = 1;
00123     }
00124 }
00125 
00126 
00127 void
00128 time_finish (struct localedef_t *locale, const struct charmap_t *charmap)
00129 {
00130   struct locale_time_t *time = locale->categories[LC_TIME].time;
00131   int nothing = 0;
00132 
00133   /* Now resolve copying and also handle completely missing definitions.  */
00134   if (time == NULL)
00135     {
00136       /* First see whether we were supposed to copy.  If yes, find the
00137         actual definition.  */
00138       if (locale->copy_name[LC_TIME] != NULL)
00139        {
00140          /* Find the copying locale.  This has to happen transitively since
00141             the locale we are copying from might also copying another one.  */
00142          struct localedef_t *from = locale;
00143 
00144          do
00145            from = find_locale (LC_TIME, from->copy_name[LC_TIME],
00146                             from->repertoire_name, charmap);
00147          while (from->categories[LC_TIME].time == NULL
00148                && from->copy_name[LC_TIME] != NULL);
00149 
00150          time = locale->categories[LC_TIME].time
00151            = from->categories[LC_TIME].time;
00152        }
00153 
00154       /* If there is still no definition issue an warning and create an
00155         empty one.  */
00156       if (time == NULL)
00157        {
00158          if (! be_quiet)
00159            WITH_CUR_LOCALE (error (0, 0, _("\
00160 No definition for %s category found"), "LC_TIME"));
00161          time_startup (NULL, locale, 0);
00162          time = locale->categories[LC_TIME].time;
00163          nothing = 1;
00164        }
00165     }
00166 
00167 #define noparen(arg1, argn...) arg1, ##argn
00168 #define TESTARR_ELEM(cat, val) \
00169   if (!time->cat##_defined)                                          \
00170     {                                                                \
00171       const char *initval[] = { noparen val };                              \
00172       unsigned int i;                                                       \
00173                                                                      \
00174       if (! be_quiet && ! nothing)                                   \
00175        WITH_CUR_LOCALE (error (0, 0, _("%s: field `%s' not defined"),       \
00176                             "LC_TIME", #cat));                              \
00177                                                                      \
00178       for (i = 0; i < sizeof (initval) / sizeof (initval[0]); ++i)          \
00179        time->cat[i] = initval[i];                                    \
00180     }
00181 
00182   TESTARR_ELEM (abday, ( "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" ));
00183   TESTARR_ELEM (day, ( "Sunday", "Monday", "Tuesday", "Wednesday",
00184                       "Thursday", "Friday", "Saturday" ));
00185   TESTARR_ELEM (abmon, ( "Jan", "Feb", "Mar", "Apr", "May", "Jun",
00186                        "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" ));
00187   TESTARR_ELEM (mon, ( "January", "February", "March", "April",
00188                      "May", "June", "July", "August",
00189                      "September", "October", "November", "December" ));
00190   TESTARR_ELEM (am_pm, ( "AM", "PM" ));
00191 
00192 #define TEST_ELEM(cat, initval) \
00193   if (time->cat == NULL)                                             \
00194     {                                                                \
00195       if (! be_quiet && ! nothing)                                   \
00196        WITH_CUR_LOCALE (error (0, 0, _("%s: field `%s' not defined"),       \
00197                             "LC_TIME", #cat));                              \
00198                                                                      \
00199       time->cat = initval;                                           \
00200     }
00201 
00202   TEST_ELEM (d_t_fmt, "%a %b %e %H:%M:%S %Y");
00203   TEST_ELEM (d_fmt, "%m/%d/%y");
00204   TEST_ELEM (t_fmt, "%H:%M:%S");
00205 
00206   /* According to C.Y.Alexis Cheng <alexis@vnet.ibm.com> the T_FMT_AMPM
00207      field is optional.  */
00208   if (time->t_fmt_ampm == NULL)
00209     {
00210       if (time->am_pm[0][0] == '\0' && time->am_pm[1][0] == '\0')
00211        {
00212          /* No AM/PM strings defined, use the 24h format as default.  */
00213          time->t_fmt_ampm = time->t_fmt;
00214          time->wt_fmt_ampm = time->wt_fmt;
00215        }
00216       else
00217        {
00218          time->t_fmt_ampm = "%I:%M:%S %p";
00219          time->wt_fmt_ampm = (const uint32_t *) L"%I:%M:%S %p";
00220        }
00221     }
00222 
00223   /* Now process the era entries.  */
00224   if (time->num_era != 0)
00225     {
00226       const int days_per_month[12] = { 31, 29, 31, 30, 31, 30,
00227                                    31, 31, 30, 31 ,30, 31 };
00228       size_t idx;
00229       wchar_t *wstr;
00230 
00231       time->era_entries =
00232        (struct era_data *) xmalloc (time->num_era
00233                                  * sizeof (struct era_data));
00234 
00235       for (idx = 0; idx < time->num_era; ++idx)
00236        {
00237          size_t era_len = strlen (time->era[idx]);
00238          char *str = xmalloc ((era_len + 1 + 3) & ~3);
00239          char *endp;
00240 
00241          memcpy (str, time->era[idx], era_len + 1);
00242 
00243          /* First character must be + or - for the direction.  */
00244          if (*str != '+' && *str != '-')
00245            {
00246              if (!be_quiet)
00247               WITH_CUR_LOCALE (error (0, 0, _("\
00248 %s: direction flag in string %Zd in `era' field is not '+' nor '-'"),
00249                                    "LC_TIME", idx + 1));
00250              /* Default arbitrarily to '+'.  */
00251              time->era_entries[idx].direction = '+';
00252            }
00253          else
00254            time->era_entries[idx].direction = *str;
00255          if (*++str != ':')
00256            {
00257              if (!be_quiet)
00258               WITH_CUR_LOCALE (error (0, 0, _("\
00259 %s: direction flag in string %Zd in `era' field is not a single character"),
00260                                    "LC_TIME", idx + 1));
00261              (void) strsep (&str, ":");
00262            }
00263          else
00264            ++str;
00265 
00266          /* Now the offset year.  */
00267          time->era_entries[idx].offset = strtol (str, &endp, 10);
00268          if (endp == str)
00269            {
00270              if (!be_quiet)
00271               WITH_CUR_LOCALE (error (0, 0, _("\
00272 %s: invalid number for offset in string %Zd in `era' field"),
00273                                    "LC_TIME", idx + 1));
00274              (void) strsep (&str, ":");
00275            }
00276          else if (*endp != ':')
00277            {
00278              if (!be_quiet)
00279               WITH_CUR_LOCALE (error (0, 0, _("\
00280 %s: garbage at end of offset value in string %Zd in `era' field"),
00281                                    "LC_TIME", idx + 1));
00282              (void) strsep (&str, ":");
00283            }
00284          else
00285            str = endp + 1;
00286 
00287          /* Next is the starting date in ISO format.  */
00288          if (strncmp (str, "-*", 2) == 0)
00289            {
00290              time->era_entries[idx].start_date[0] =
00291               time->era_entries[idx].start_date[1] =
00292               time->era_entries[idx].start_date[2] = 0x80000000;
00293              if (str[2] != ':')
00294               goto garbage_start_date;
00295              str += 3;
00296            }
00297          else if (strncmp (str, "+*", 2) == 0)
00298            {
00299              time->era_entries[idx].start_date[0] =
00300               time->era_entries[idx].start_date[1] =
00301               time->era_entries[idx].start_date[2] = 0x7fffffff;
00302              if (str[2] != ':')
00303               goto garbage_start_date;
00304              str += 3;
00305            }
00306          else
00307            {
00308              time->era_entries[idx].start_date[0] = strtol (str, &endp, 10);
00309              if (endp == str || *endp != '/')
00310               goto invalid_start_date;
00311              else
00312               str = endp + 1;
00313              time->era_entries[idx].start_date[0] -= 1900;
00314              /* year -1 represent 1 B.C. (not -1 A.D.) */
00315              if (time->era_entries[idx].start_date[0] < -1900)
00316               ++time->era_entries[idx].start_date[0];
00317 
00318              time->era_entries[idx].start_date[1] = strtol (str, &endp, 10);
00319              if (endp == str || *endp != '/')
00320               goto invalid_start_date;
00321              else
00322               str = endp + 1;
00323              time->era_entries[idx].start_date[1] -= 1;
00324 
00325              time->era_entries[idx].start_date[2] = strtol (str, &endp, 10);
00326              if (endp == str)
00327               {
00328               invalid_start_date:
00329                 if (!be_quiet)
00330                   WITH_CUR_LOCALE (error (0, 0, _("\
00331 %s: invalid starting date in string %Zd in `era' field"),
00332                                        "LC_TIME", idx + 1));
00333                 (void) strsep (&str, ":");
00334               }
00335              else if (*endp != ':')
00336               {
00337               garbage_start_date:
00338                 if (!be_quiet)
00339                   WITH_CUR_LOCALE (error (0, 0, _("\
00340 %s: garbage at end of starting date in string %Zd in `era' field "),
00341                                        "LC_TIME", idx + 1));
00342                 (void) strsep (&str, ":");
00343               }
00344              else
00345               {
00346                 str = endp + 1;
00347 
00348                 /* Check for valid value.  */
00349                 if ((time->era_entries[idx].start_date[1] < 0
00350                      || time->era_entries[idx].start_date[1] >= 12
00351                      || time->era_entries[idx].start_date[2] < 0
00352                      || (time->era_entries[idx].start_date[2]
00353                         > days_per_month[time->era_entries[idx].start_date[1]])
00354                      || (time->era_entries[idx].start_date[1] == 2
00355                         && time->era_entries[idx].start_date[2] == 29
00356                         && !__isleap (time->era_entries[idx].start_date[0])))
00357                     && !be_quiet)
00358                        WITH_CUR_LOCALE (error (0, 0, _("\
00359 %s: starting date is invalid in string %Zd in `era' field"),
00360                                             "LC_TIME", idx + 1));
00361               }
00362            }
00363 
00364          /* Next is the stopping date in ISO format.  */
00365          if (strncmp (str, "-*", 2) == 0)
00366            {
00367              time->era_entries[idx].stop_date[0] =
00368               time->era_entries[idx].stop_date[1] =
00369               time->era_entries[idx].stop_date[2] = 0x80000000;
00370              if (str[2] != ':')
00371               goto garbage_stop_date;
00372              str += 3;
00373            }
00374          else if (strncmp (str, "+*", 2) == 0)
00375            {
00376              time->era_entries[idx].stop_date[0] =
00377               time->era_entries[idx].stop_date[1] =
00378               time->era_entries[idx].stop_date[2] = 0x7fffffff;
00379              if (str[2] != ':')
00380               goto garbage_stop_date;
00381              str += 3;
00382            }
00383          else
00384            {
00385              time->era_entries[idx].stop_date[0] = strtol (str, &endp, 10);
00386              if (endp == str || *endp != '/')
00387               goto invalid_stop_date;
00388              else
00389               str = endp + 1;
00390              time->era_entries[idx].stop_date[0] -= 1900;
00391              /* year -1 represent 1 B.C. (not -1 A.D.) */
00392              if (time->era_entries[idx].stop_date[0] < -1900)
00393               ++time->era_entries[idx].stop_date[0];
00394 
00395              time->era_entries[idx].stop_date[1] = strtol (str, &endp, 10);
00396              if (endp == str || *endp != '/')
00397               goto invalid_stop_date;
00398              else
00399               str = endp + 1;
00400              time->era_entries[idx].stop_date[1] -= 1;
00401 
00402              time->era_entries[idx].stop_date[2] = strtol (str, &endp, 10);
00403              if (endp == str)
00404               {
00405               invalid_stop_date:
00406                 if (!be_quiet)
00407                   WITH_CUR_LOCALE (error (0, 0, _("\
00408 %s: invalid stopping date in string %Zd in `era' field"),
00409                                        "LC_TIME", idx + 1));
00410                 (void) strsep (&str, ":");
00411               }
00412              else if (*endp != ':')
00413               {
00414               garbage_stop_date:
00415                 if (!be_quiet)
00416                   WITH_CUR_LOCALE (error (0, 0, _("\
00417 %s: garbage at end of stopping date in string %Zd in `era' field"),
00418                                        "LC_TIME", idx + 1));
00419                 (void) strsep (&str, ":");
00420               }
00421              else
00422               {
00423                 str = endp + 1;
00424 
00425                 /* Check for valid value.  */
00426                 if ((time->era_entries[idx].stop_date[1] < 0
00427                      || time->era_entries[idx].stop_date[1] >= 12
00428                      || time->era_entries[idx].stop_date[2] < 0
00429                      || (time->era_entries[idx].stop_date[2]
00430                         > days_per_month[time->era_entries[idx].stop_date[1]])
00431                      || (time->era_entries[idx].stop_date[1] == 2
00432                         && time->era_entries[idx].stop_date[2] == 29
00433                         && !__isleap (time->era_entries[idx].stop_date[0])))
00434                     && !be_quiet)
00435                        WITH_CUR_LOCALE (error (0, 0, _("\
00436 %s: invalid stopping date in string %Zd in `era' field"),
00437                                             "LC_TIME", idx + 1));
00438               }
00439            }
00440 
00441          if (str == NULL || *str == '\0')
00442            {
00443              if (!be_quiet)
00444               WITH_CUR_LOCALE (error (0, 0, _("\
00445 %s: missing era name in string %Zd in `era' field"), "LC_TIME", idx + 1));
00446              time->era_entries[idx].name =
00447               time->era_entries[idx].format = "";
00448            }
00449          else
00450            {
00451              time->era_entries[idx].name = strsep (&str, ":");
00452 
00453              if (str == NULL || *str == '\0')
00454               {
00455                 if (!be_quiet)
00456                   WITH_CUR_LOCALE (error (0, 0, _("\
00457 %s: missing era format in string %Zd in `era' field"),
00458                                        "LC_TIME", idx + 1));
00459                 time->era_entries[idx].name =
00460                   time->era_entries[idx].format = "";
00461               }
00462              else
00463               time->era_entries[idx].format = str;
00464            }
00465 
00466          /* Now generate the wide character name and format.  */
00467          wstr = wcschr ((wchar_t *) time->wera[idx], L':');/* end direction */
00468          wstr = wstr ? wcschr (wstr + 1, L':') : NULL;  /* end offset */
00469          wstr = wstr ? wcschr (wstr + 1, L':') : NULL;  /* end start */
00470          wstr = wstr ? wcschr (wstr + 1, L':') : NULL;  /* end end */
00471          if (wstr != NULL)
00472            {
00473              time->era_entries[idx].wname = (uint32_t *) wstr + 1;
00474              wstr = wcschr (wstr + 1, L':');     /* end name */
00475              if (wstr != NULL)
00476               {
00477                 *wstr = L'\0';
00478                 time->era_entries[idx].wformat = (uint32_t *) wstr + 1;
00479               }
00480              else
00481               time->era_entries[idx].wname =
00482                 time->era_entries[idx].wformat = (uint32_t *) L"";
00483            }
00484          else
00485            time->era_entries[idx].wname =
00486              time->era_entries[idx].wformat = (uint32_t *) L"";
00487        }
00488     }
00489 
00490   if (time->week_ndays == 0)
00491     time->week_ndays = 7;
00492 
00493   if (time->week_1stday == 0)
00494     time->week_1stday = 19971130;
00495 
00496   if (time->week_1stweek > time->week_ndays)
00497     WITH_CUR_LOCALE (error (0, 0, _("\
00498 %s: third operand for value of field `%s' must not be larger than %d"),
00499                          "LC_TIME", "week", 7));
00500 
00501   if (time->first_weekday == '\0')
00502     /* The definition does not specify this so the default is used.  */
00503     time->first_weekday = 1;
00504   else if (time->first_weekday > time->week_ndays)
00505     WITH_CUR_LOCALE (error (0, 0, _("\
00506 %s: values for field `%s' must not be larger than %d"),
00507                          "LC_TIME", "first_weekday", 7));
00508 
00509   if (time->first_workday == '\0')
00510     /* The definition does not specify this so the default is used.  */
00511     time->first_workday = 2;
00512   else if (time->first_workday > time->week_ndays)
00513     WITH_CUR_LOCALE (error (0, 0, _("\
00514 %s: values for field `%s' must not be larger than %d"),
00515                          "LC_TIME", "first_workday", 7));
00516 
00517   if (time->cal_direction == '\0')
00518     /* The definition does not specify this so the default is used.  */
00519     time->cal_direction = 1;
00520   else if (time->cal_direction > 3)
00521     WITH_CUR_LOCALE (error (0, 0, _("\
00522 %s: values for field `%s' must not be larger than %d"),
00523                          "LC_TIME", "cal_direction", 3));
00524 
00525   /* XXX We don't perform any tests on the timezone value since this is
00526      simply useless, stupid $&$!@...  */
00527   if (time->timezone == NULL)
00528     time->timezone = "";
00529 
00530   if (time->date_fmt == NULL)
00531     time->date_fmt = "%a %b %e %H:%M:%S %Z %Y";
00532   if (time->wdate_fmt == NULL)
00533     time->wdate_fmt = (const uint32_t *) L"%a %b %e %H:%M:%S %Z %Y";
00534 }
00535 
00536 
00537 void
00538 time_output (struct localedef_t *locale, const struct charmap_t *charmap,
00539             const char *output_path)
00540 {
00541   struct locale_time_t *time = locale->categories[LC_TIME].time;
00542   struct iovec *iov = alloca (sizeof *iov
00543                            * (2 + _NL_ITEM_INDEX (_NL_NUM_LC_TIME)
00544                              + time->num_era - 1
00545                              + 2 * 99
00546                              + 2 + time->num_era * 10));
00547   struct locale_file data;
00548   uint32_t idx[_NL_ITEM_INDEX (_NL_NUM_LC_TIME)];
00549   size_t cnt, last_idx, num, n;
00550 
00551   data.magic = LIMAGIC (LC_TIME);
00552   data.n = _NL_ITEM_INDEX (_NL_NUM_LC_TIME);
00553   iov[0].iov_base = (void *) &data;
00554   iov[0].iov_len = sizeof (data);
00555 
00556   iov[1].iov_base = (void *) idx;
00557   iov[1].iov_len = sizeof (idx);
00558 
00559   idx[0] = iov[0].iov_len + iov[1].iov_len;
00560 
00561   /* The ab'days.  */
00562   for (cnt = 0; cnt <= _NL_ITEM_INDEX (ABDAY_7); ++cnt)
00563     {
00564       iov[2 + cnt].iov_base =
00565        (void *) (time->abday[cnt - _NL_ITEM_INDEX (ABDAY_1)] ?: "");
00566       iov[2 + cnt].iov_len = strlen (iov[2 + cnt].iov_base) + 1;
00567       idx[1 + cnt] = idx[cnt] + iov[2 + cnt].iov_len;
00568     }
00569 
00570   /* The days.  */
00571   for (; cnt <= _NL_ITEM_INDEX (DAY_7); ++cnt)
00572     {
00573       iov[2 + cnt].iov_base =
00574        (void *) (time->day[cnt - _NL_ITEM_INDEX (DAY_1)] ?: "");
00575       iov[2 + cnt].iov_len = strlen (iov[2 + cnt].iov_base) + 1;
00576       idx[1 + cnt] = idx[cnt] + iov[2 + cnt].iov_len;
00577     }
00578 
00579   /* The ab'mons.  */
00580   for (; cnt <= _NL_ITEM_INDEX (ABMON_12); ++cnt)
00581     {
00582       iov[2 + cnt].iov_base =
00583        (void *) (time->abmon[cnt - _NL_ITEM_INDEX (ABMON_1)] ?: "");
00584       iov[2 + cnt].iov_len = strlen (iov[2 + cnt].iov_base) + 1;
00585       idx[1 + cnt] = idx[cnt] + iov[2 + cnt].iov_len;
00586     }
00587 
00588   /* The mons.  */
00589   for (; cnt <= _NL_ITEM_INDEX (MON_12); ++cnt)
00590     {
00591       iov[2 + cnt].iov_base =
00592        (void *) (time->mon[cnt - _NL_ITEM_INDEX (MON_1)] ?: "");
00593       iov[2 + cnt].iov_len = strlen (iov[2 + cnt].iov_base) + 1;
00594       idx[1 + cnt] = idx[cnt] + iov[2 + cnt].iov_len;
00595     }
00596 
00597   /* AM/PM.  */
00598   for (; cnt <= _NL_ITEM_INDEX (PM_STR); ++cnt)
00599     {
00600       iov[2 + cnt].iov_base =
00601        (void *) (time->am_pm[cnt - _NL_ITEM_INDEX (AM_STR)] ?: "");
00602       iov[2 + cnt].iov_len = strlen (iov[2 + cnt].iov_base) + 1;
00603       idx[1 + cnt] = idx[cnt] + iov[2 + cnt].iov_len;
00604     }
00605 
00606   iov[2 + cnt].iov_base = (void *) (time->d_t_fmt ?: "");
00607   iov[2 + cnt].iov_len = strlen (iov[2 + cnt].iov_base) + 1;
00608   idx[1 + cnt] = idx[cnt] + iov[2 + cnt].iov_len;
00609   ++cnt;
00610 
00611   iov[2 + cnt].iov_base = (void *) (time->d_fmt ?: "");
00612   iov[2 + cnt].iov_len = strlen (iov[2 + cnt].iov_base) + 1;
00613   idx[1 + cnt] = idx[cnt] + iov[2 + cnt].iov_len;
00614   ++cnt;
00615 
00616   iov[2 + cnt].iov_base = (void *) (time->t_fmt ?: "");
00617   iov[2 + cnt].iov_len = strlen (iov[2 + cnt].iov_base) + 1;
00618   idx[1 + cnt] = idx[cnt] + iov[2 + cnt].iov_len;
00619   ++cnt;
00620 
00621   iov[2 + cnt].iov_base = (void *) (time->t_fmt_ampm ?: "");
00622   iov[2 + cnt].iov_len = strlen (iov[2 + cnt].iov_base) + 1;
00623   idx[1 + cnt] = idx[cnt] + iov[2 + cnt].iov_len;
00624   last_idx = ++cnt;
00625 
00626   idx[1 + last_idx] = idx[last_idx];
00627   for (num = 0; num < time->num_era; ++num, ++cnt)
00628     {
00629       iov[2 + cnt].iov_base = (void *) time->era[num];
00630       iov[2 + cnt].iov_len = strlen (iov[2 + cnt].iov_base) + 1;
00631       idx[1 + last_idx] += iov[2 + cnt].iov_len;
00632     }
00633   ++last_idx;
00634 
00635   iov[2 + cnt].iov_base = (void *) (time->era_year ?: "");
00636   iov[2 + cnt].iov_len = strlen (iov[2 + cnt].iov_base) + 1;
00637   idx[1 + last_idx] = idx[last_idx] + iov[2 + cnt].iov_len;
00638   ++cnt;
00639   ++last_idx;
00640 
00641   iov[2 + cnt].iov_base = (void *) (time->era_d_fmt ?: "");
00642   iov[2 + cnt].iov_len = strlen (iov[2 + cnt].iov_base) + 1;
00643   idx[1 + last_idx] = idx[last_idx] + iov[2 + cnt].iov_len;
00644   ++cnt;
00645   ++last_idx;
00646 
00647   idx[1 + last_idx] = idx[last_idx];
00648   for (num = 0; num < 100; ++num, ++cnt)
00649     {
00650       iov[2 + cnt].iov_base = (void *) (time->alt_digits[num] ?: "");
00651       iov[2 + cnt].iov_len = strlen (iov[2 + cnt].iov_base) + 1;
00652       idx[1 + last_idx] += iov[2 + cnt].iov_len;
00653     }
00654   ++last_idx;
00655 
00656   iov[2 + cnt].iov_base = (void *) (time->era_d_t_fmt ?: "");
00657   iov[2 + cnt].iov_len = strlen (iov[2 + cnt].iov_base) + 1;
00658   idx[1 + last_idx] = idx[last_idx] + iov[2 + cnt].iov_len;
00659   ++cnt;
00660   ++last_idx;
00661 
00662   iov[2 + cnt].iov_base = (void *) (time->era_t_fmt ?: "");
00663   iov[2 + cnt].iov_len = strlen (iov[2 + cnt].iov_base) + 1;
00664   idx[1 + last_idx] = idx[last_idx] + iov[2 + cnt].iov_len;
00665   ++cnt;
00666   ++last_idx;
00667 
00668 
00669   /* We must align the following data.  */
00670   iov[2 + cnt].iov_base = (void *) "\0\0";
00671   iov[2 + cnt].iov_len = ((idx[last_idx] + 3) & ~3) - idx[last_idx];
00672   idx[last_idx] = (idx[last_idx] + 3) & ~3;
00673   ++cnt;
00674 
00675   /* The `era' data in usable form.  */
00676   iov[2 + cnt].iov_base = (void *) &time->num_era;
00677   iov[2 + cnt].iov_len = sizeof (uint32_t);
00678   idx[1 + last_idx] = idx[last_idx] + iov[2 + cnt].iov_len;
00679   ++cnt;
00680   ++last_idx;
00681 
00682   idx[1 + last_idx] = idx[last_idx];
00683   for (num = 0; num < time->num_era; ++num)
00684     {
00685       size_t l, l2;
00686 
00687       iov[2 + cnt].iov_base = (void *) &time->era_entries[num].direction;
00688       iov[2 + cnt].iov_len = sizeof (int32_t);
00689       ++cnt;
00690       iov[2 + cnt].iov_base = (void *) &time->era_entries[num].offset;
00691       iov[2 + cnt].iov_len = sizeof (int32_t);
00692       ++cnt;
00693       iov[2 + cnt].iov_base = (void *) &time->era_entries[num].start_date[0];
00694       iov[2 + cnt].iov_len = sizeof (int32_t);
00695       ++cnt;
00696       iov[2 + cnt].iov_base = (void *) &time->era_entries[num].start_date[1];
00697       iov[2 + cnt].iov_len = sizeof (int32_t);
00698       ++cnt;
00699       iov[2 + cnt].iov_base = (void *) &time->era_entries[num].start_date[2];
00700       iov[2 + cnt].iov_len = sizeof (int32_t);
00701       ++cnt;
00702       iov[2 + cnt].iov_base = (void *) &time->era_entries[num].stop_date[0];
00703       iov[2 + cnt].iov_len = sizeof (int32_t);
00704       ++cnt;
00705       iov[2 + cnt].iov_base = (void *) &time->era_entries[num].stop_date[1];
00706       iov[2 + cnt].iov_len = sizeof (int32_t);
00707       ++cnt;
00708       iov[2 + cnt].iov_base = (void *) &time->era_entries[num].stop_date[2];
00709       iov[2 + cnt].iov_len = sizeof (int32_t);
00710       ++cnt;
00711 
00712       l = ((char *) rawmemchr (time->era_entries[num].format, '\0')
00713           - time->era_entries[num].name) + 1;
00714       l2 = (l + 3) & ~3;
00715       iov[2 + cnt].iov_base = alloca (l2);
00716       memset (mempcpy (iov[2 + cnt].iov_base, time->era_entries[num].name, l),
00717              '\0', l2 - l);
00718       iov[2 + cnt].iov_len = l2;
00719       ++cnt;
00720 
00721       idx[1 + last_idx] += 8 * sizeof (int32_t) + l2;
00722 
00723       assert (idx[1 + last_idx] % 4 == 0);
00724 
00725       iov[2 + cnt].iov_base = (void *) time->era_entries[num].wname;
00726       iov[2 + cnt].iov_len = ((wcschr ((wchar_t *) time->era_entries[num].wformat, L'\0')
00727                             - (wchar_t *) time->era_entries[num].wname + 1)
00728                            * sizeof (uint32_t));
00729       idx[1 + last_idx] += iov[2 + cnt].iov_len;
00730       ++cnt;
00731     }
00732   ++last_idx;
00733 
00734   /* The wide character ab'days.  */
00735   for (n = 0; n < 7; ++n, ++cnt, ++last_idx)
00736     {
00737       iov[2 + cnt].iov_base =
00738        (void *) (time->wabday[n] ?: empty_wstr);
00739       iov[2 + cnt].iov_len = ((wcslen (iov[2 + cnt].iov_base) + 1)
00740                            * sizeof (uint32_t));
00741       idx[1 + last_idx] = idx[last_idx] + iov[2 + cnt].iov_len;
00742     }
00743 
00744   /* The wide character days.  */
00745   for (n = 0; n < 7; ++n, ++cnt, ++last_idx)
00746     {
00747       iov[2 + cnt].iov_base =
00748        (void *) (time->wday[n] ?: empty_wstr);
00749       iov[2 + cnt].iov_len = ((wcslen (iov[2 + cnt].iov_base) + 1)
00750                            * sizeof (uint32_t));
00751       idx[1 + last_idx] = idx[last_idx] + iov[2 + cnt].iov_len;
00752     }
00753 
00754   /* The wide character ab'mons.  */
00755   for (n = 0; n < 12; ++n, ++cnt, ++last_idx)
00756     {
00757       iov[2 + cnt].iov_base =
00758        (void *) (time->wabmon[n] ?: empty_wstr);
00759       iov[2 + cnt].iov_len = ((wcslen (iov[2 + cnt].iov_base) + 1)
00760                            * sizeof (uint32_t));
00761       idx[1 + last_idx] = idx[last_idx] + iov[2 + cnt].iov_len;
00762     }
00763 
00764   /* The wide character mons.  */
00765   for (n = 0; n < 12; ++n, ++cnt, ++last_idx)
00766     {
00767       iov[2 + cnt].iov_base =
00768        (void *) (time->wmon[n] ?: empty_wstr);
00769       iov[2 + cnt].iov_len = ((wcslen (iov[2 + cnt].iov_base) + 1)
00770                            * sizeof (uint32_t));
00771       idx[1 + last_idx] = idx[last_idx] + iov[2 + cnt].iov_len;
00772     }
00773 
00774   /* Wide character AM/PM.  */
00775   for (n = 0; n < 2; ++n, ++cnt, ++last_idx)
00776     {
00777       iov[2 + cnt].iov_base =
00778        (void *) (time->wam_pm[n] ?: empty_wstr);
00779       iov[2 + cnt].iov_len = ((wcslen (iov[2 + cnt].iov_base) + 1)
00780                            * sizeof (uint32_t));
00781       idx[1 + last_idx] = idx[last_idx] + iov[2 + cnt].iov_len;
00782     }
00783 
00784   iov[2 + cnt].iov_base = (void *) (time->wd_t_fmt ?: empty_wstr);
00785   iov[2 + cnt].iov_len = ((wcslen (iov[2 + cnt].iov_base) + 1)
00786                        * sizeof (uint32_t));
00787   idx[1 + last_idx] = idx[last_idx] + iov[2 + cnt].iov_len;
00788   ++cnt;
00789   ++last_idx;
00790 
00791   iov[2 + cnt].iov_base = (void *) (time->wd_fmt ?: empty_wstr);
00792   iov[2 + cnt].iov_len = ((wcslen (iov[2 + cnt].iov_base) + 1)
00793                        * sizeof (uint32_t));
00794   idx[1 + last_idx] = idx[last_idx] + iov[2 + cnt].iov_len;
00795   ++cnt;
00796   ++last_idx;
00797 
00798   iov[2 + cnt].iov_base = (void *) (time->wt_fmt ?: empty_wstr);
00799   iov[2 + cnt].iov_len = ((wcslen (iov[2 + cnt].iov_base) + 1)
00800                        * sizeof (uint32_t));
00801   idx[1 + last_idx] = idx[last_idx] + iov[2 + cnt].iov_len;
00802   ++cnt;
00803   ++last_idx;
00804 
00805   iov[2 + cnt].iov_base = (void *) (time->wt_fmt_ampm ?: empty_wstr);
00806   iov[2 + cnt].iov_len = ((wcslen (iov[2 + cnt].iov_base) + 1)
00807                        * sizeof (uint32_t));
00808   idx[1 + last_idx] = idx[last_idx] + iov[2 + cnt].iov_len;
00809   ++cnt;
00810   ++last_idx;
00811 
00812   iov[2 + cnt].iov_base = (void *) (time->wera_year ?: empty_wstr);
00813   iov[2 + cnt].iov_len = ((wcslen (iov[2 + cnt].iov_base) + 1)
00814                        * sizeof (uint32_t));
00815   idx[1 + last_idx] = idx[last_idx] + iov[2 + cnt].iov_len;
00816   ++cnt;
00817   ++last_idx;
00818 
00819   iov[2 + cnt].iov_base = (void *) (time->wera_d_fmt ?: empty_wstr);
00820   iov[2 + cnt].iov_len = ((wcslen (iov[2 + cnt].iov_base) + 1)
00821                        * sizeof (uint32_t));
00822   idx[1 + last_idx] = idx[last_idx] + iov[2 + cnt].iov_len;
00823   ++cnt;
00824   ++last_idx;
00825 
00826   idx[1 + last_idx] = idx[last_idx];
00827   for (num = 0; num < 100; ++num, ++cnt)
00828     {
00829       iov[2 + cnt].iov_base = (void *) (time->walt_digits[num]
00830                                    ?: empty_wstr);
00831       iov[2 + cnt].iov_len = ((wcslen (iov[2 + cnt].iov_base) + 1)
00832                            * sizeof (uint32_t));
00833       idx[1 + last_idx] += iov[2 + cnt].iov_len;
00834     }
00835   ++last_idx;
00836 
00837   iov[2 + cnt].iov_base = (void *) (time->wera_d_t_fmt ?: empty_wstr);
00838   iov[2 + cnt].iov_len = ((wcslen (iov[2 + cnt].iov_base) + 1)
00839                        * sizeof (uint32_t));
00840   idx[1 + last_idx] = idx[last_idx] + iov[2 + cnt].iov_len;
00841   ++cnt;
00842   ++last_idx;
00843 
00844   iov[2 + cnt].iov_base = (void *) (time->wera_t_fmt ?: empty_wstr);
00845   iov[2 + cnt].iov_len = ((wcslen (iov[2 + cnt].iov_base) + 1)
00846                        * sizeof (uint32_t));
00847   idx[1 + last_idx] = idx[last_idx] + iov[2 + cnt].iov_len;
00848   ++cnt;
00849   ++last_idx;
00850 
00851   iov[2 + cnt].iov_base = (void *) &time->week_ndays;
00852   iov[2 + cnt].iov_len = 1;
00853   idx[1 + last_idx] = idx[last_idx] + iov[2 + cnt].iov_len;
00854   ++cnt;
00855   ++last_idx;
00856 
00857   /* We must align the following data.  */
00858   iov[2 + cnt].iov_base = (void *) "\0\0";
00859   iov[2 + cnt].iov_len = ((idx[last_idx] + 3) & ~3) - idx[last_idx];
00860   idx[last_idx] = (idx[last_idx] + 3) & ~3;
00861   ++cnt;
00862 
00863   iov[2 + cnt].iov_base = (void *) &time->week_1stday;
00864   iov[2 + cnt].iov_len = sizeof(uint32_t);
00865   idx[1 + last_idx] = idx[last_idx] + iov[2 + cnt].iov_len;
00866   ++cnt;
00867   ++last_idx;
00868 
00869   iov[2 + cnt].iov_base = (void *) &time->week_1stweek;
00870   iov[2 + cnt].iov_len = 1;
00871   idx[1 + last_idx] = idx[last_idx] + iov[2 + cnt].iov_len;
00872   ++cnt;
00873   ++last_idx;
00874 
00875   iov[2 + cnt].iov_base = (void *) &time->first_weekday;
00876   iov[2 + cnt].iov_len = 1;
00877   idx[1 + last_idx] = idx[last_idx] + iov[2 + cnt].iov_len;
00878   ++cnt;
00879   ++last_idx;
00880 
00881   iov[2 + cnt].iov_base = (void *) &time->first_workday;
00882   iov[2 + cnt].iov_len = 1;
00883   idx[1 + last_idx] = idx[last_idx] + iov[2 + cnt].iov_len;
00884   ++cnt;
00885   ++last_idx;
00886 
00887   iov[2 + cnt].iov_base = (void *) &time->cal_direction;
00888   iov[2 + cnt].iov_len = 1;
00889   idx[1 + last_idx] = idx[last_idx] + iov[2 + cnt].iov_len;
00890   ++cnt;
00891   ++last_idx;
00892 
00893   iov[2 + cnt].iov_base = (void *) time->timezone;
00894   iov[2 + cnt].iov_len = strlen (time->timezone) + 1;
00895   idx[1 + last_idx] = idx[last_idx] + iov[2 + cnt].iov_len;
00896   ++cnt;
00897   ++last_idx;
00898 
00899   iov[2 + cnt].iov_base = (void *) time->date_fmt;
00900   iov[2 + cnt].iov_len = strlen (iov[2 + cnt].iov_base) + 1;
00901   idx[1 + last_idx] = idx[last_idx] + iov[2 + cnt].iov_len;
00902   ++cnt;
00903   ++last_idx;
00904 
00905   /* We must align the following data.  */
00906   iov[2 + cnt].iov_base = (void *) "\0\0";
00907   iov[2 + cnt].iov_len = -idx[last_idx] & 3;
00908   idx[last_idx] += -idx[last_idx] & 3;
00909   ++cnt;
00910 
00911   iov[2 + cnt].iov_base = (void *) time->wdate_fmt;
00912   iov[2 + cnt].iov_len = ((wcslen (iov[2 + cnt].iov_base) + 1)
00913                           * sizeof (uint32_t));
00914   idx[1 + last_idx] = idx[last_idx] + iov[2 + cnt].iov_len;
00915   ++cnt;
00916   ++last_idx;
00917 
00918   iov[2 + cnt].iov_base = (void *) charmap->code_set_name;
00919   iov[2 + cnt].iov_len = strlen (iov[2 + cnt].iov_base) + 1;
00920   ++cnt;
00921   ++last_idx;
00922 
00923   assert (cnt == (_NL_ITEM_INDEX (_NL_NUM_LC_TIME)
00924                 + time->num_era - 1
00925                 + 2 * 99
00926                 + 2 + time->num_era * 10));
00927   assert (last_idx  == _NL_ITEM_INDEX (_NL_NUM_LC_TIME));
00928 
00929   write_locale_data (output_path, LC_TIME, "LC_TIME", 2 + cnt, iov);
00930 }
00931 
00932 
00933 /* The parser for the LC_TIME section of the locale definition.  */
00934 void
00935 time_read (struct linereader *ldfile, struct localedef_t *result,
00936           const struct charmap_t *charmap, const char *repertoire_name,
00937           int ignore_content)
00938 {
00939   struct repertoire_t *repertoire = NULL;
00940   struct locale_time_t *time;
00941   struct token *now;
00942   enum token_t nowtok;
00943   size_t cnt;
00944 
00945   /* Get the repertoire we have to use.  */
00946   if (repertoire_name != NULL)
00947     repertoire = repertoire_read (repertoire_name);
00948 
00949   /* The rest of the line containing `LC_TIME' must be free.  */
00950   lr_ignore_rest (ldfile, 1);
00951 
00952 
00953   do
00954     {
00955       now = lr_token (ldfile, charmap, result, repertoire, verbose);
00956       nowtok = now->tok;
00957     }
00958   while (nowtok == tok_eol);
00959 
00960   /* If we see `copy' now we are almost done.  */
00961   if (nowtok == tok_copy)
00962     {
00963       handle_copy (ldfile, charmap, repertoire_name, result, tok_lc_time,
00964                  LC_TIME, "LC_TIME", ignore_content);
00965       return;
00966     }
00967 
00968   /* Prepare the data structures.  */
00969   time_startup (ldfile, result, ignore_content);
00970   time = result->categories[LC_TIME].time;
00971 
00972   while (1)
00973     {
00974       /* Of course we don't proceed beyond the end of file.  */
00975       if (nowtok == tok_eof)
00976        break;
00977 
00978       /* Ingore empty lines.  */
00979       if (nowtok == tok_eol)
00980        {
00981          now = lr_token (ldfile, charmap, result, repertoire, verbose);
00982          nowtok = now->tok;
00983          continue;
00984        }
00985 
00986       switch (nowtok)
00987        {
00988 #define STRARR_ELEM(cat, min, max) \
00989        case tok_##cat:                                                      \
00990          /* Ignore the rest of the line if we don't need the input of       \
00991             this line.  */                                           \
00992          if (ignore_content)                                                \
00993            {                                                         \
00994              lr_ignore_rest (ldfile, 0);                             \
00995              break;                                                  \
00996            }                                                         \
00997                                                                      \
00998          for (cnt = 0; cnt < max; ++cnt)                             \
00999            {                                                         \
01000              now = lr_token (ldfile, charmap, result, repertoire, verbose);  \
01001              if (now->tok == tok_eol)                                       \
01002               {                                                      \
01003                 if (cnt < min)                                       \
01004                   lr_error (ldfile, _("%s: too few values for field `%s'"), \
01005                            "LC_TIME", #cat);                                \
01006                 if (!ignore_content)                                        \
01007                   do                                                 \
01008                     {                                                       \
01009                      time->cat[cnt] = "";                            \
01010                      time->w##cat[cnt] = empty_wstr;                        \
01011                     }                                                       \
01012                   while (++cnt < max);                               \
01013                 break;                                               \
01014               }                                                      \
01015              else if (now->tok != tok_string)                               \
01016               goto err_label;                                               \
01017              else if (!ignore_content && (now->val.str.startmb == NULL             \
01018                                       || now->val.str.startwc == NULL))  \
01019               {                                                      \
01020                 lr_error (ldfile, _("%s: unknown character in field `%s'"), \
01021                          "LC_TIME", #cat);                                  \
01022                 time->cat[cnt] = "";                                        \
01023                 time->w##cat[cnt] = empty_wstr;                      \
01024               }                                                      \
01025              else if (!ignore_content)                                      \
01026               {                                                      \
01027                 time->cat[cnt] = now->val.str.startmb;               \
01028                 time->w##cat[cnt] = now->val.str.startwc;                   \
01029               }                                                      \
01030                                                                      \
01031              /* Match the semicolon.  */                             \
01032              now = lr_token (ldfile, charmap, result, repertoire, verbose);  \
01033              if (now->tok != tok_semicolon && now->tok != tok_eol)          \
01034               break;                                                 \
01035            }                                                         \
01036          if (now->tok != tok_eol)                                    \
01037            {                                                         \
01038              while (!ignore_content && cnt < min)                           \
01039               {                                                      \
01040                 time->cat[cnt] = "";                                        \
01041                 time->w##cat[cnt++] = empty_wstr;                           \
01042               }                                                      \
01043                                                                      \
01044              if (now->tok == tok_semicolon)                                 \
01045               {                                                      \
01046                 now = lr_token (ldfile, charmap, result, repertoire,        \
01047                               verbose);                              \
01048                 if (now->tok == tok_eol)                             \
01049                   lr_error (ldfile, _("extra trailing semicolon"));         \
01050                 else if (now->tok == tok_string)                     \
01051                   {                                                  \
01052                     lr_error (ldfile, _("\
01053 %s: too many values for field `%s'"),                                       \
01054                             "LC_TIME", #cat);                        \
01055                     lr_ignore_rest (ldfile, 0);                      \
01056                   }                                                  \
01057                 else                                                 \
01058                   goto err_label;                                    \
01059               }                                                      \
01060              else                                                    \
01061               goto err_label;                                               \
01062            }                                                         \
01063          time->cat##_defined = 1;                                    \
01064          break
01065 
01066          STRARR_ELEM (abday, 7, 7);
01067          STRARR_ELEM (day, 7, 7);
01068          STRARR_ELEM (abmon, 12, 12);
01069          STRARR_ELEM (mon, 12, 12);
01070          STRARR_ELEM (am_pm, 2, 2);
01071          STRARR_ELEM (alt_digits, 0, 100);
01072 
01073        case tok_era:
01074          /* Ignore the rest of the line if we don't need the input of
01075             this line.  */
01076          if (ignore_content)
01077            {
01078              lr_ignore_rest (ldfile, 0);
01079              break;
01080            }
01081          do
01082            {
01083              now = lr_token (ldfile, charmap, result, repertoire, verbose);
01084              if (now->tok != tok_string)
01085               goto err_label;
01086              if (!ignore_content && (now->val.str.startmb == NULL
01087                                   || now->val.str.startwc == NULL))
01088               {
01089                 lr_error (ldfile, _("%s: unknown character in field `%s'"),
01090                          "LC_TIME", "era");
01091                 lr_ignore_rest (ldfile, 0);
01092                 break;
01093               }
01094              if (!ignore_content)
01095               {
01096                 time->era = xrealloc (time->era,
01097                                    (time->num_era + 1) * sizeof (char *));
01098                 time->era[time->num_era] = now->val.str.startmb;
01099 
01100                 time->wera = xrealloc (time->wera,
01101                                     (time->num_era + 1)
01102                                     * sizeof (char *));
01103                 time->wera[time->num_era++] = now->val.str.startwc;
01104               }
01105              now = lr_token (ldfile, charmap, result, repertoire, verbose);
01106              if (now->tok != tok_eol && now->tok != tok_semicolon)
01107               goto err_label;
01108            }
01109          while (now->tok == tok_semicolon);
01110          break;
01111 
01112 #define STR_ELEM(cat) \
01113        case tok_##cat:                                                      \
01114          /* Ignore the rest of the line if we don't need the input of       \
01115             this line.  */                                           \
01116          if (ignore_content)                                                \
01117            {                                                         \
01118              lr_ignore_rest (ldfile, 0);                             \
01119              break;                                                  \
01120            }                                                         \
01121                                                                      \
01122          now = lr_token (ldfile, charmap, result, repertoire, verbose);      \
01123          if (now->tok != tok_string)                                        \
01124            goto err_label;                                           \
01125          else if (time->cat != NULL)                                        \
01126            lr_error (ldfile, _("\
01127 %s: field `%s' declared more than once"), "LC_TIME", #cat);                 \
01128          else if (!ignore_content && (now->val.str.startmb == NULL          \
01129                                    || now->val.str.startwc == NULL))      \
01130            {                                                         \
01131              lr_error (ldfile, _("%s: unknown character in field `%s'"),     \
01132                      "LC_TIME", #cat);                               \
01133              time->cat = "";                                                \
01134              time->w##cat = empty_wstr;                              \
01135            }                                                         \
01136          else if (!ignore_content)                                   \
01137            {                                                         \
01138              time->cat = now->val.str.startmb;                              \
01139              time->w##cat = now->val.str.startwc;                           \
01140            }                                                         \
01141          break
01142 
01143          STR_ELEM (d_t_fmt);
01144          STR_ELEM (d_fmt);
01145          STR_ELEM (t_fmt);
01146          STR_ELEM (t_fmt_ampm);
01147          STR_ELEM (era_year);
01148          STR_ELEM (era_d_t_fmt);
01149          STR_ELEM (era_d_fmt);
01150          STR_ELEM (era_t_fmt);
01151          STR_ELEM (timezone);
01152          STR_ELEM (date_fmt);
01153 
01154 #define INT_ELEM(cat) \
01155        case tok_##cat:                                                      \
01156          /* Ignore the rest of the line if we don't need the input of       \
01157             this line.  */                                           \
01158          if (ignore_content)                                                \
01159            {                                                         \
01160              lr_ignore_rest (ldfile, 0);                             \
01161              break;                                                  \
01162            }                                                         \
01163                                                                      \
01164          now = lr_token (ldfile, charmap, result, repertoire, verbose);      \
01165          if (now->tok != tok_number)                                        \
01166            goto err_label;                                           \
01167          else if (time->cat != 0)                                    \
01168            lr_error (ldfile, _("%s: field `%s' declared more than once"),    \
01169                     "LC_TIME", #cat);                                       \
01170          else if (!ignore_content)                                   \
01171            time->cat = now->val.num;                                        \
01172          break
01173 
01174          INT_ELEM (first_weekday);
01175          INT_ELEM (first_workday);
01176          INT_ELEM (cal_direction);
01177 
01178        case tok_week:
01179          /* Ignore the rest of the line if we don't need the input of
01180             this line.  */
01181          if (ignore_content)
01182            {
01183              lr_ignore_rest (ldfile, 0);
01184              break;
01185            }
01186 
01187          now = lr_token (ldfile, charmap, result, repertoire, verbose);
01188          if (now->tok != tok_number)
01189            goto err_label;
01190          time->week_ndays = now->val.num;
01191 
01192          now = lr_token (ldfile, charmap, result, repertoire, verbose);
01193          if (now->tok != tok_semicolon)
01194            goto err_label;
01195 
01196          now = lr_token (ldfile, charmap, result, repertoire, verbose);
01197          if (now->tok != tok_number)
01198            goto err_label;
01199          time->week_1stday = now->val.num;
01200 
01201          now = lr_token (ldfile, charmap, result, repertoire, verbose);
01202          if (now->tok != tok_semicolon)
01203            goto err_label;
01204 
01205          now = lr_token (ldfile, charmap, result, repertoire, verbose);
01206          if (now->tok != tok_number)
01207            goto err_label;
01208          time->week_1stweek = now->val.num;
01209 
01210          lr_ignore_rest (ldfile,  1);
01211          break;
01212 
01213        case tok_end:
01214          /* Next we assume `LC_TIME'.  */
01215          now = lr_token (ldfile, charmap, result, repertoire, verbose);
01216          if (now->tok == tok_eof)
01217            break;
01218          if (now->tok == tok_eol)
01219            lr_error (ldfile, _("%s: incomplete `END' line"), "LC_TIME");
01220          else if (now->tok != tok_lc_time)
01221            lr_error (ldfile, _("\
01222 %1$s: definition does not end with `END %1$s'"), "LC_TIME");
01223          lr_ignore_rest (ldfile, now->tok == tok_lc_time);
01224          return;
01225 
01226        default:
01227        err_label:
01228          SYNTAX_ERROR (_("%s: syntax error"), "LC_TIME");
01229        }
01230 
01231       /* Prepare for the next round.  */
01232       now = lr_token (ldfile, charmap, result, repertoire, verbose);
01233       nowtok = now->tok;
01234     }
01235 
01236   /* When we come here we reached the end of the file.  */
01237   lr_error (ldfile, _("%s: premature end of file"), "LC_TIME");
01238 }