re-mark 1.29b-2 as not yet uploaded (merge madness!)
[debian/tar] / gnu / parse-datetime.c
1 /* A Bison parser, made by GNU Bison 2.5.1.  */
2
3 /* Bison implementation for Yacc-like parsers in C
4    
5       Copyright (C) 1984, 1989-1990, 2000-2012 Free Software Foundation, Inc.
6    
7    This program is free software: you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation, either version 3 of the License, or
10    (at your option) any later version.
11    
12    This program is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16    
17    You should have received a copy of the GNU General Public License
18    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
19
20 /* As a special exception, you may create a larger work that contains
21    part or all of the Bison parser skeleton and distribute that work
22    under terms of your choice, so long as that work isn't itself a
23    parser generator using the skeleton or a modified version thereof
24    as a parser skeleton.  Alternatively, if you modify or redistribute
25    the parser skeleton itself, you may (at your option) remove this
26    special exception, which will cause the skeleton and the resulting
27    Bison output files to be licensed under the GNU General Public
28    License without this special exception.
29    
30    This special exception was added by the Free Software Foundation in
31    version 2.2 of Bison.  */
32
33 /* C LALR(1) parser skeleton written by Richard Stallman, by
34    simplifying the original so-called "semantic" parser.  */
35
36 /* All symbols defined below should begin with yy or YY, to avoid
37    infringing on user name space.  This should be done even for local
38    variables, as they might otherwise be expanded by user macros.
39    There are some unavoidable exceptions within include files to
40    define necessary library symbols; they are noted "INFRINGES ON
41    USER NAME SPACE" below.  */
42
43 /* Identify Bison output.  */
44 #define YYBISON 1
45
46 /* Bison version.  */
47 #define YYBISON_VERSION "2.5.1"
48
49 /* Skeleton name.  */
50 #define YYSKELETON_NAME "yacc.c"
51
52 /* Pure parsers.  */
53 #define YYPURE 1
54
55 /* Push parsers.  */
56 #define YYPUSH 0
57
58 /* Pull parsers.  */
59 #define YYPULL 1
60
61 /* Using locations.  */
62 #define YYLSP_NEEDED 0
63
64
65
66 /* Copy the first part of user declarations.  */
67
68 /* Line 268 of yacc.c  */
69 #line 1 "./parse-datetime.y"
70
71 /* Parse a string into an internal time stamp.
72
73    Copyright (C) 1999-2000, 2002-2015 Free Software Foundation, Inc.
74
75    This program is free software: you can redistribute it and/or modify
76    it under the terms of the GNU General Public License as published by
77    the Free Software Foundation; either version 3 of the License, or
78    (at your option) any later version.
79
80    This program is distributed in the hope that it will be useful,
81    but WITHOUT ANY WARRANTY; without even the implied warranty of
82    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
83    GNU General Public License for more details.
84
85    You should have received a copy of the GNU General Public License
86    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
87
88 /* Originally written by Steven M. Bellovin <smb@research.att.com> while
89    at the University of North Carolina at Chapel Hill.  Later tweaked by
90    a couple of people on Usenet.  Completely overhauled by Rich $alz
91    <rsalz@bbn.com> and Jim Berets <jberets@bbn.com> in August, 1990.
92
93    Modified by Paul Eggert <eggert@twinsun.com> in August 1999 to do
94    the right thing about local DST.  Also modified by Paul Eggert
95    <eggert@cs.ucla.edu> in February 2004 to support
96    nanosecond-resolution time stamps, and in October 2004 to support
97    TZ strings in dates.  */
98
99 /* FIXME: Check for arithmetic overflow in all cases, not just
100    some of them.  */
101
102 #include <config.h>
103
104 #include "parse-datetime.h"
105
106 #include "intprops.h"
107 #include "timespec.h"
108 #include "verify.h"
109
110 /* There's no need to extend the stack, so there's no need to involve
111    alloca.  */
112 #define YYSTACK_USE_ALLOCA 0
113
114 /* Tell Bison how much stack space is needed.  20 should be plenty for
115    this grammar, which is not right recursive.  Beware setting it too
116    high, since that might cause problems on machines whose
117    implementations have lame stack-overflow checking.  */
118 #define YYMAXDEPTH 20
119 #define YYINITDEPTH YYMAXDEPTH
120
121 /* Since the code of parse-datetime.y is not included in the Emacs executable
122    itself, there is no need to #define static in this file.  Even if
123    the code were included in the Emacs executable, it probably
124    wouldn't do any harm to #undef it here; this will only cause
125    problems if we try to write to a static variable, which I don't
126    think this code needs to do.  */
127 #ifdef emacs
128 # undef static
129 #endif
130
131 #include <c-ctype.h>
132 #include <limits.h>
133 #include <stdio.h>
134 #include <stdlib.h>
135 #include <string.h>
136
137 #include "xalloc.h"
138
139 /* Bison's skeleton tests _STDLIB_H, while some stdlib.h headers
140    use _STDLIB_H_ as witness.  Map the latter to the one bison uses.  */
141 /* FIXME: this is temporary.  Remove when we have a mechanism to ensure
142    that the version we're using is fixed, too.  */
143 #ifdef _STDLIB_H_
144 # undef _STDLIB_H
145 # define _STDLIB_H 1
146 #endif
147
148 /* ISDIGIT differs from isdigit, as follows:
149    - Its arg may be any int or unsigned int; it need not be an unsigned char
150      or EOF.
151    - It's typically faster.
152    POSIX says that only '0' through '9' are digits.  Prefer ISDIGIT to
153    isdigit unless it's important to use the locale's definition
154    of "digit" even when the host does not conform to POSIX.  */
155 #define ISDIGIT(c) ((unsigned int) (c) - '0' <= 9)
156
157 /* Shift A right by B bits portably, by dividing A by 2**B and
158    truncating towards minus infinity.  A and B should be free of side
159    effects, and B should be in the range 0 <= B <= INT_BITS - 2, where
160    INT_BITS is the number of useful bits in an int.  GNU code can
161    assume that INT_BITS is at least 32.
162
163    ISO C99 says that A >> B is implementation-defined if A < 0.  Some
164    implementations (e.g., UNICOS 9.0 on a Cray Y-MP EL) don't shift
165    right in the usual way when A < 0, so SHR falls back on division if
166    ordinary A >> B doesn't seem to be the usual signed shift.  */
167 #define SHR(a, b)       \
168   (-1 >> 1 == -1        \
169    ? (a) >> (b)         \
170    : (a) / (1 << (b)) - ((a) % (1 << (b)) < 0))
171
172 #define EPOCH_YEAR 1970
173 #define TM_YEAR_BASE 1900
174
175 #define HOUR(x) ((x) * 60)
176
177 /* long_time_t is a signed integer type that contains all time_t values.  */
178 verify (TYPE_IS_INTEGER (time_t));
179 #if TIME_T_FITS_IN_LONG_INT
180 typedef long int long_time_t;
181 #else
182 typedef time_t long_time_t;
183 #endif
184
185 /* Convert a possibly-signed character to an unsigned character.  This is
186    a bit safer than casting to unsigned char, since it catches some type
187    errors that the cast doesn't.  */
188 static unsigned char to_uchar (char ch) { return ch; }
189
190 /* Lots of this code assumes time_t and time_t-like values fit into
191    long_time_t.  */
192 verify (TYPE_MINIMUM (long_time_t) <= TYPE_MINIMUM (time_t)
193         && TYPE_MAXIMUM (time_t) <= TYPE_MAXIMUM (long_time_t));
194
195 /* FIXME: It also assumes that signed integer overflow silently wraps around,
196    but this is not true any more with recent versions of GCC 4.  */
197
198 /* An integer value, and the number of digits in its textual
199    representation.  */
200 typedef struct
201 {
202   bool negative;
203   long int value;
204   size_t digits;
205 } textint;
206
207 /* An entry in the lexical lookup table.  */
208 typedef struct
209 {
210   char const *name;
211   int type;
212   int value;
213 } table;
214
215 /* Meridian: am, pm, or 24-hour style.  */
216 enum { MERam, MERpm, MER24 };
217
218 enum { BILLION = 1000000000, LOG10_BILLION = 9 };
219
220 /* Relative times.  */
221 typedef struct
222 {
223   /* Relative year, month, day, hour, minutes, seconds, and nanoseconds.  */
224   long int year;
225   long int month;
226   long int day;
227   long int hour;
228   long int minutes;
229   long_time_t seconds;
230   long int ns;
231 } relative_time;
232
233 #if HAVE_COMPOUND_LITERALS
234 # define RELATIVE_TIME_0 ((relative_time) { 0, 0, 0, 0, 0, 0, 0 })
235 #else
236 static relative_time const RELATIVE_TIME_0;
237 #endif
238
239 /* Information passed to and from the parser.  */
240 typedef struct
241 {
242   /* The input string remaining to be parsed. */
243   const char *input;
244
245   /* N, if this is the Nth Tuesday.  */
246   long int day_ordinal;
247
248   /* Day of week; Sunday is 0.  */
249   int day_number;
250
251   /* tm_isdst flag for the local zone.  */
252   int local_isdst;
253
254   /* Time zone, in minutes east of UTC.  */
255   long int time_zone;
256
257   /* Style used for time.  */
258   int meridian;
259
260   /* Gregorian year, month, day, hour, minutes, seconds, and nanoseconds.  */
261   textint year;
262   long int month;
263   long int day;
264   long int hour;
265   long int minutes;
266   struct timespec seconds; /* includes nanoseconds */
267
268   /* Relative year, month, day, hour, minutes, seconds, and nanoseconds.  */
269   relative_time rel;
270
271   /* Presence or counts of nonterminals of various flavors parsed so far.  */
272   bool timespec_seen;
273   bool rels_seen;
274   size_t dates_seen;
275   size_t days_seen;
276   size_t local_zones_seen;
277   size_t dsts_seen;
278   size_t times_seen;
279   size_t zones_seen;
280
281   /* Table of local time zone abbreviations, terminated by a null entry.  */
282   table local_time_zone_table[3];
283 } parser_control;
284
285 union YYSTYPE;
286 static int yylex (union YYSTYPE *, parser_control *);
287 static int yyerror (parser_control const *, char const *);
288 static long int time_zone_hhmm (parser_control *, textint, long int);
289
290 /* Extract into *PC any date and time info from a string of digits
291    of the form e.g., YYYYMMDD, YYMMDD, HHMM, HH (and sometimes YYY,
292    YYYY, ...).  */
293 static void
294 digits_to_date_time (parser_control *pc, textint text_int)
295 {
296   if (pc->dates_seen && ! pc->year.digits
297       && ! pc->rels_seen && (pc->times_seen || 2 < text_int.digits))
298     pc->year = text_int;
299   else
300     {
301       if (4 < text_int.digits)
302         {
303           pc->dates_seen++;
304           pc->day = text_int.value % 100;
305           pc->month = (text_int.value / 100) % 100;
306           pc->year.value = text_int.value / 10000;
307           pc->year.digits = text_int.digits - 4;
308         }
309       else
310         {
311           pc->times_seen++;
312           if (text_int.digits <= 2)
313             {
314               pc->hour = text_int.value;
315               pc->minutes = 0;
316             }
317           else
318             {
319               pc->hour = text_int.value / 100;
320               pc->minutes = text_int.value % 100;
321             }
322           pc->seconds.tv_sec = 0;
323           pc->seconds.tv_nsec = 0;
324           pc->meridian = MER24;
325         }
326     }
327 }
328
329 /* Increment PC->rel by FACTOR * REL (FACTOR is 1 or -1).  */
330 static void
331 apply_relative_time (parser_control *pc, relative_time rel, int factor)
332 {
333   pc->rel.ns += factor * rel.ns;
334   pc->rel.seconds += factor * rel.seconds;
335   pc->rel.minutes += factor * rel.minutes;
336   pc->rel.hour += factor * rel.hour;
337   pc->rel.day += factor * rel.day;
338   pc->rel.month += factor * rel.month;
339   pc->rel.year += factor * rel.year;
340   pc->rels_seen = true;
341 }
342
343 /* Set PC-> hour, minutes, seconds and nanoseconds members from arguments.  */
344 static void
345 set_hhmmss (parser_control *pc, long int hour, long int minutes,
346             time_t sec, long int nsec)
347 {
348   pc->hour = hour;
349   pc->minutes = minutes;
350   pc->seconds.tv_sec = sec;
351   pc->seconds.tv_nsec = nsec;
352 }
353
354
355
356 /* Line 268 of yacc.c  */
357 #line 358 "parse-datetime.c"
358
359 # ifndef YY_NULL
360 #  if defined __cplusplus && 201103L <= __cplusplus
361 #   define YY_NULL nullptr
362 #  else
363 #   define YY_NULL 0
364 #  endif
365 # endif
366
367 /* Enabling traces.  */
368 #ifndef YYDEBUG
369 # define YYDEBUG 0
370 #endif
371
372 /* Enabling verbose error messages.  */
373 #ifdef YYERROR_VERBOSE
374 # undef YYERROR_VERBOSE
375 # define YYERROR_VERBOSE 1
376 #else
377 # define YYERROR_VERBOSE 0
378 #endif
379
380 /* Enabling the token table.  */
381 #ifndef YYTOKEN_TABLE
382 # define YYTOKEN_TABLE 0
383 #endif
384
385
386 /* Tokens.  */
387 #ifndef YYTOKENTYPE
388 # define YYTOKENTYPE
389    /* Put the tokens into the symbol table, so that GDB and other debuggers
390       know about them.  */
391    enum yytokentype {
392      tAGO = 258,
393      tDST = 259,
394      tYEAR_UNIT = 260,
395      tMONTH_UNIT = 261,
396      tHOUR_UNIT = 262,
397      tMINUTE_UNIT = 263,
398      tSEC_UNIT = 264,
399      tDAY_UNIT = 265,
400      tDAY_SHIFT = 266,
401      tDAY = 267,
402      tDAYZONE = 268,
403      tLOCAL_ZONE = 269,
404      tMERIDIAN = 270,
405      tMONTH = 271,
406      tORDINAL = 272,
407      tZONE = 273,
408      tSNUMBER = 274,
409      tUNUMBER = 275,
410      tSDECIMAL_NUMBER = 276,
411      tUDECIMAL_NUMBER = 277
412    };
413 #endif
414 /* Tokens.  */
415 #define tAGO 258
416 #define tDST 259
417 #define tYEAR_UNIT 260
418 #define tMONTH_UNIT 261
419 #define tHOUR_UNIT 262
420 #define tMINUTE_UNIT 263
421 #define tSEC_UNIT 264
422 #define tDAY_UNIT 265
423 #define tDAY_SHIFT 266
424 #define tDAY 267
425 #define tDAYZONE 268
426 #define tLOCAL_ZONE 269
427 #define tMERIDIAN 270
428 #define tMONTH 271
429 #define tORDINAL 272
430 #define tZONE 273
431 #define tSNUMBER 274
432 #define tUNUMBER 275
433 #define tSDECIMAL_NUMBER 276
434 #define tUDECIMAL_NUMBER 277
435
436
437
438
439 #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
440 typedef union YYSTYPE
441 {
442
443 /* Line 295 of yacc.c  */
444 #line 297 "./parse-datetime.y"
445
446   long int intval;
447   textint textintval;
448   struct timespec timespec;
449   relative_time rel;
450
451
452
453 /* Line 295 of yacc.c  */
454 #line 455 "parse-datetime.c"
455 } YYSTYPE;
456 # define YYSTYPE_IS_TRIVIAL 1
457 # define yystype YYSTYPE /* obsolescent; will be withdrawn */
458 # define YYSTYPE_IS_DECLARED 1
459 #endif
460
461
462 /* Copy the second part of user declarations.  */
463
464
465 /* Line 345 of yacc.c  */
466 #line 467 "parse-datetime.c"
467
468 #ifdef short
469 # undef short
470 #endif
471
472 #ifdef YYTYPE_UINT8
473 typedef YYTYPE_UINT8 yytype_uint8;
474 #else
475 typedef unsigned char yytype_uint8;
476 #endif
477
478 #ifdef YYTYPE_INT8
479 typedef YYTYPE_INT8 yytype_int8;
480 #elif (defined __STDC__ || defined __C99__FUNC__ \
481      || defined __cplusplus || defined _MSC_VER)
482 typedef signed char yytype_int8;
483 #else
484 typedef short int yytype_int8;
485 #endif
486
487 #ifdef YYTYPE_UINT16
488 typedef YYTYPE_UINT16 yytype_uint16;
489 #else
490 typedef unsigned short int yytype_uint16;
491 #endif
492
493 #ifdef YYTYPE_INT16
494 typedef YYTYPE_INT16 yytype_int16;
495 #else
496 typedef short int yytype_int16;
497 #endif
498
499 #ifndef YYSIZE_T
500 # ifdef __SIZE_TYPE__
501 #  define YYSIZE_T __SIZE_TYPE__
502 # elif defined size_t
503 #  define YYSIZE_T size_t
504 # elif ! defined YYSIZE_T && (defined __STDC__ || defined __C99__FUNC__ \
505      || defined __cplusplus || defined _MSC_VER)
506 #  include <stddef.h> /* INFRINGES ON USER NAME SPACE */
507 #  define YYSIZE_T size_t
508 # else
509 #  define YYSIZE_T unsigned int
510 # endif
511 #endif
512
513 #define YYSIZE_MAXIMUM ((YYSIZE_T) -1)
514
515 #ifndef YY_
516 # if defined YYENABLE_NLS && YYENABLE_NLS
517 #  if ENABLE_NLS
518 #   include <libintl.h> /* INFRINGES ON USER NAME SPACE */
519 #   define YY_(msgid) dgettext ("bison-runtime", msgid)
520 #  endif
521 # endif
522 # ifndef YY_
523 #  define YY_(msgid) msgid
524 # endif
525 #endif
526
527 /* Suppress unused-variable warnings by "using" E.  */
528 #if ! defined lint || defined __GNUC__
529 # define YYUSE(e) ((void) (e))
530 #else
531 # define YYUSE(e) /* empty */
532 #endif
533
534 /* Identity function, used to suppress warnings about constant conditions.  */
535 #ifndef lint
536 # define YYID(n) (n)
537 #else
538 #if (defined __STDC__ || defined __C99__FUNC__ \
539      || defined __cplusplus || defined _MSC_VER)
540 static int
541 YYID (int yyi)
542 #else
543 static int
544 YYID (yyi)
545     int yyi;
546 #endif
547 {
548   return yyi;
549 }
550 #endif
551
552 #if ! defined yyoverflow || YYERROR_VERBOSE
553
554 /* The parser invokes alloca or malloc; define the necessary symbols.  */
555
556 # ifdef YYSTACK_USE_ALLOCA
557 #  if YYSTACK_USE_ALLOCA
558 #   ifdef __GNUC__
559 #    define YYSTACK_ALLOC __builtin_alloca
560 #   elif defined __BUILTIN_VA_ARG_INCR
561 #    include <alloca.h> /* INFRINGES ON USER NAME SPACE */
562 #   elif defined _AIX
563 #    define YYSTACK_ALLOC __alloca
564 #   elif defined _MSC_VER
565 #    include <malloc.h> /* INFRINGES ON USER NAME SPACE */
566 #    define alloca _alloca
567 #   else
568 #    define YYSTACK_ALLOC alloca
569 #    if ! defined _ALLOCA_H && ! defined EXIT_SUCCESS && (defined __STDC__ || defined __C99__FUNC__ \
570      || defined __cplusplus || defined _MSC_VER)
571 #     include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
572       /* Use EXIT_SUCCESS as a witness for stdlib.h.  */
573 #     ifndef EXIT_SUCCESS
574 #      define EXIT_SUCCESS 0
575 #     endif
576 #    endif
577 #   endif
578 #  endif
579 # endif
580
581 # ifdef YYSTACK_ALLOC
582    /* Pacify GCC's `empty if-body' warning.  */
583 #  define YYSTACK_FREE(Ptr) do { /* empty */; } while (YYID (0))
584 #  ifndef YYSTACK_ALLOC_MAXIMUM
585     /* The OS might guarantee only one guard page at the bottom of the stack,
586        and a page size can be as small as 4096 bytes.  So we cannot safely
587        invoke alloca (N) if N exceeds 4096.  Use a slightly smaller number
588        to allow for a few compiler-allocated temporary stack slots.  */
589 #   define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */
590 #  endif
591 # else
592 #  define YYSTACK_ALLOC YYMALLOC
593 #  define YYSTACK_FREE YYFREE
594 #  ifndef YYSTACK_ALLOC_MAXIMUM
595 #   define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM
596 #  endif
597 #  if (defined __cplusplus && ! defined EXIT_SUCCESS \
598        && ! ((defined YYMALLOC || defined malloc) \
599              && (defined YYFREE || defined free)))
600 #   include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
601 #   ifndef EXIT_SUCCESS
602 #    define EXIT_SUCCESS 0
603 #   endif
604 #  endif
605 #  ifndef YYMALLOC
606 #   define YYMALLOC malloc
607 #   if ! defined malloc && ! defined EXIT_SUCCESS && (defined __STDC__ || defined __C99__FUNC__ \
608      || defined __cplusplus || defined _MSC_VER)
609 void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */
610 #   endif
611 #  endif
612 #  ifndef YYFREE
613 #   define YYFREE free
614 #   if ! defined free && ! defined EXIT_SUCCESS && (defined __STDC__ || defined __C99__FUNC__ \
615      || defined __cplusplus || defined _MSC_VER)
616 void free (void *); /* INFRINGES ON USER NAME SPACE */
617 #   endif
618 #  endif
619 # endif
620 #endif /* ! defined yyoverflow || YYERROR_VERBOSE */
621
622
623 #if (! defined yyoverflow \
624      && (! defined __cplusplus \
625          || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
626
627 /* A type that is properly aligned for any stack member.  */
628 union yyalloc
629 {
630   yytype_int16 yyss_alloc;
631   YYSTYPE yyvs_alloc;
632 };
633
634 /* The size of the maximum gap between one aligned stack and the next.  */
635 # define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1)
636
637 /* The size of an array large to enough to hold all stacks, each with
638    N elements.  */
639 # define YYSTACK_BYTES(N) \
640      ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE)) \
641       + YYSTACK_GAP_MAXIMUM)
642
643 # define YYCOPY_NEEDED 1
644
645 /* Relocate STACK from its old location to the new one.  The
646    local variables YYSIZE and YYSTACKSIZE give the old and new number of
647    elements in the stack, and YYPTR gives the new location of the
648    stack.  Advance YYPTR to a properly aligned location for the next
649    stack.  */
650 # define YYSTACK_RELOCATE(Stack_alloc, Stack)                           \
651     do                                                                  \
652       {                                                                 \
653         YYSIZE_T yynewbytes;                                            \
654         YYCOPY (&yyptr->Stack_alloc, Stack, yysize);                    \
655         Stack = &yyptr->Stack_alloc;                                    \
656         yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \
657         yyptr += yynewbytes / sizeof (*yyptr);                          \
658       }                                                                 \
659     while (YYID (0))
660
661 #endif
662
663 #if defined YYCOPY_NEEDED && YYCOPY_NEEDED
664 /* Copy COUNT objects from SRC to DST.  The source and destination do
665    not overlap.  */
666 # ifndef YYCOPY
667 #  if defined __GNUC__ && 1 < __GNUC__
668 #   define YYCOPY(Dst, Src, Count) \
669       __builtin_memcpy (Dst, Src, (Count) * sizeof (*(Src)))
670 #  else
671 #   define YYCOPY(Dst, Src, Count)              \
672       do                                        \
673         {                                       \
674           YYSIZE_T yyi;                         \
675           for (yyi = 0; yyi < (Count); yyi++)   \
676             (Dst)[yyi] = (Src)[yyi];            \
677         }                                       \
678       while (YYID (0))
679 #  endif
680 # endif
681 #endif /* !YYCOPY_NEEDED */
682
683 /* YYFINAL -- State number of the termination state.  */
684 #define YYFINAL  12
685 /* YYLAST -- Last index in YYTABLE.  */
686 #define YYLAST   112
687
688 /* YYNTOKENS -- Number of terminals.  */
689 #define YYNTOKENS  28
690 /* YYNNTS -- Number of nonterminals.  */
691 #define YYNNTS  26
692 /* YYNRULES -- Number of rules.  */
693 #define YYNRULES  91
694 /* YYNRULES -- Number of states.  */
695 #define YYNSTATES  114
696
697 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX.  */
698 #define YYUNDEFTOK  2
699 #define YYMAXUTOK   277
700
701 #define YYTRANSLATE(YYX)                                                \
702   ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
703
704 /* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX.  */
705 static const yytype_uint8 yytranslate[] =
706 {
707        0,     2,     2,     2,     2,     2,     2,     2,     2,     2,
708        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
709        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
710        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
711        2,     2,     2,     2,    26,     2,     2,    27,     2,     2,
712        2,     2,     2,     2,     2,     2,     2,     2,    25,     2,
713        2,     2,     2,     2,    23,     2,     2,     2,     2,     2,
714        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
715        2,     2,     2,     2,    24,     2,     2,     2,     2,     2,
716        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
717        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
718        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
719        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
720        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
721        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
722        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
723        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
724        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
725        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
726        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
727        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
728        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
729        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
730        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
731        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
732        2,     2,     2,     2,     2,     2,     1,     2,     3,     4,
733        5,     6,     7,     8,     9,    10,    11,    12,    13,    14,
734       15,    16,    17,    18,    19,    20,    21,    22
735 };
736
737 #if YYDEBUG
738 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
739    YYRHS.  */
740 static const yytype_uint8 yyprhs[] =
741 {
742        0,     0,     3,     5,     7,    10,    11,    14,    16,    18,
743       20,    22,    24,    26,    28,    30,    32,    34,    38,    41,
744       46,    53,    55,    58,    63,    70,    71,    73,    76,    78,
745       81,    83,    85,    88,    91,    95,    97,   100,   102,   105,
746      108,   111,   115,   121,   125,   129,   132,   137,   140,   144,
747      146,   150,   153,   155,   157,   160,   163,   165,   168,   171,
748      173,   176,   179,   181,   184,   187,   189,   192,   195,   197,
749      200,   203,   206,   209,   211,   213,   216,   219,   222,   225,
750      228,   231,   233,   235,   237,   239,   241,   243,   245,   247,
751      250,   251
752 };
753
754 /* YYRHS -- A `-1'-separated list of the rules' RHS.  */
755 static const yytype_int8 yyrhs[] =
756 {
757       29,     0,    -1,    30,    -1,    31,    -1,    23,    48,    -1,
758       -1,    31,    32,    -1,    33,    -1,    35,    -1,    39,    -1,
759       40,    -1,    42,    -1,    41,    -1,    44,    -1,    51,    -1,
760       52,    -1,    34,    -1,    43,    24,    36,    -1,    20,    15,
761       -1,    20,    25,    20,    15,    -1,    20,    25,    20,    25,
762       50,    15,    -1,    36,    -1,    20,    38,    -1,    20,    25,
763       20,    37,    -1,    20,    25,    20,    25,    50,    37,    -1,
764       -1,    38,    -1,    19,    53,    -1,    14,    -1,    14,     4,
765       -1,    18,    -1,    24,    -1,    18,    46,    -1,    24,    46,
766       -1,    18,    19,    53,    -1,    13,    -1,    18,     4,    -1,
767       12,    -1,    12,    26,    -1,    17,    12,    -1,    20,    12,
768       -1,    20,    27,    20,    -1,    20,    27,    20,    27,    20,
769       -1,    20,    16,    19,    -1,    16,    19,    19,    -1,    16,
770       20,    -1,    16,    20,    26,    20,    -1,    20,    16,    -1,
771       20,    16,    20,    -1,    43,    -1,    20,    19,    19,    -1,
772       45,     3,    -1,    45,    -1,    47,    -1,    17,     5,    -1,
773       20,     5,    -1,     5,    -1,    17,     6,    -1,    20,     6,
774       -1,     6,    -1,    17,    10,    -1,    20,    10,    -1,    10,
775       -1,    17,     7,    -1,    20,     7,    -1,     7,    -1,    17,
776        8,    -1,    20,     8,    -1,     8,    -1,    17,     9,    -1,
777       20,     9,    -1,    21,     9,    -1,    22,     9,    -1,     9,
778       -1,    46,    -1,    19,     5,    -1,    19,     6,    -1,    19,
779       10,    -1,    19,     7,    -1,    19,     8,    -1,    19,     9,
780       -1,    11,    -1,    49,    -1,    50,    -1,    21,    -1,    19,
781       -1,    22,    -1,    20,    -1,    20,    -1,    20,    46,    -1,
782       -1,    25,    20,    -1
783 };
784
785 /* YYRLINE[YYN] -- source line where rule number YYN was defined.  */
786 static const yytype_uint16 yyrline[] =
787 {
788        0,   324,   324,   325,   329,   336,   338,   342,   344,   346,
789      348,   350,   352,   354,   355,   356,   360,   364,   368,   373,
790      378,   383,   387,   392,   397,   404,   406,   410,   418,   423,
791      433,   435,   437,   440,   443,   445,   447,   452,   457,   462,
792      467,   475,   480,   500,   508,   516,   521,   527,   532,   538,
793      542,   552,   554,   556,   561,   563,   565,   567,   569,   571,
794      573,   575,   577,   579,   581,   583,   585,   587,   589,   591,
795      593,   595,   597,   599,   601,   605,   607,   609,   611,   613,
796      615,   620,   624,   624,   627,   628,   633,   634,   639,   644,
797      655,   656
798 };
799 #endif
800
801 #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
802 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
803    First, the terminals, then, starting at YYNTOKENS, nonterminals.  */
804 static const char *const yytname[] =
805 {
806   "$end", "error", "$undefined", "tAGO", "tDST", "tYEAR_UNIT",
807   "tMONTH_UNIT", "tHOUR_UNIT", "tMINUTE_UNIT", "tSEC_UNIT", "tDAY_UNIT",
808   "tDAY_SHIFT", "tDAY", "tDAYZONE", "tLOCAL_ZONE", "tMERIDIAN", "tMONTH",
809   "tORDINAL", "tZONE", "tSNUMBER", "tUNUMBER", "tSDECIMAL_NUMBER",
810   "tUDECIMAL_NUMBER", "'@'", "'T'", "':'", "','", "'/'", "$accept", "spec",
811   "timespec", "items", "item", "datetime", "iso_8601_datetime", "time",
812   "iso_8601_time", "o_zone_offset", "zone_offset", "local_zone", "zone",
813   "day", "date", "iso_8601_date", "rel", "relunit", "relunit_snumber",
814   "dayshift", "seconds", "signed_seconds", "unsigned_seconds", "number",
815   "hybrid", "o_colon_minutes", YY_NULL
816 };
817 #endif
818
819 # ifdef YYPRINT
820 /* YYTOKNUM[YYLEX-NUM] -- Internal token number corresponding to
821    token YYLEX-NUM.  */
822 static const yytype_uint16 yytoknum[] =
823 {
824        0,   256,   257,   258,   259,   260,   261,   262,   263,   264,
825      265,   266,   267,   268,   269,   270,   271,   272,   273,   274,
826      275,   276,   277,    64,    84,    58,    44,    47
827 };
828 # endif
829
830 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives.  */
831 static const yytype_uint8 yyr1[] =
832 {
833        0,    28,    29,    29,    30,    31,    31,    32,    32,    32,
834       32,    32,    32,    32,    32,    32,    33,    34,    35,    35,
835       35,    35,    36,    36,    36,    37,    37,    38,    39,    39,
836       40,    40,    40,    40,    40,    40,    40,    41,    41,    41,
837       41,    42,    42,    42,    42,    42,    42,    42,    42,    42,
838       43,    44,    44,    44,    45,    45,    45,    45,    45,    45,
839       45,    45,    45,    45,    45,    45,    45,    45,    45,    45,
840       45,    45,    45,    45,    45,    46,    46,    46,    46,    46,
841       46,    47,    48,    48,    49,    49,    50,    50,    51,    52,
842       53,    53
843 };
844
845 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN.  */
846 static const yytype_uint8 yyr2[] =
847 {
848        0,     2,     1,     1,     2,     0,     2,     1,     1,     1,
849        1,     1,     1,     1,     1,     1,     1,     3,     2,     4,
850        6,     1,     2,     4,     6,     0,     1,     2,     1,     2,
851        1,     1,     2,     2,     3,     1,     2,     1,     2,     2,
852        2,     3,     5,     3,     3,     2,     4,     2,     3,     1,
853        3,     2,     1,     1,     2,     2,     1,     2,     2,     1,
854        2,     2,     1,     2,     2,     1,     2,     2,     1,     2,
855        2,     2,     2,     1,     1,     2,     2,     2,     2,     2,
856        2,     1,     1,     1,     1,     1,     1,     1,     1,     2,
857        0,     2
858 };
859
860 /* YYDEFACT[STATE-NAME] -- Default reduction number in state STATE-NUM.
861    Performed when YYTABLE doesn't specify something else to do.  Zero
862    means the default is an error.  */
863 static const yytype_uint8 yydefact[] =
864 {
865        5,     0,     0,     2,     3,    85,    87,    84,    86,     4,
866       82,    83,     1,    56,    59,    65,    68,    73,    62,    81,
867       37,    35,    28,     0,     0,    30,     0,    88,     0,     0,
868       31,     6,     7,    16,     8,    21,     9,    10,    12,    11,
869       49,    13,    52,    74,    53,    14,    15,    38,    29,     0,
870       45,    54,    57,    63,    66,    69,    60,    39,    36,    90,
871       32,    75,    76,    78,    79,    80,    77,    55,    58,    64,
872       67,    70,    61,    40,    18,    47,    90,     0,     0,    22,
873       89,    71,    72,    33,     0,    51,    44,     0,     0,    34,
874       43,    48,    50,    27,    25,    41,     0,    17,    46,    91,
875       19,    90,     0,    23,    26,     0,     0,    25,    42,    25,
876       20,    24,     0,    25
877 };
878
879 /* YYDEFGOTO[NTERM-NUM].  */
880 static const yytype_int8 yydefgoto[] =
881 {
882       -1,     2,     3,     4,    31,    32,    33,    34,    35,   103,
883      104,    36,    37,    38,    39,    40,    41,    42,    43,    44,
884        9,    10,    11,    45,    46,    93
885 };
886
887 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
888    STATE-NUM.  */
889 #define YYPACT_NINF -93
890 static const yytype_int8 yypact[] =
891 {
892       38,    27,    77,   -93,    46,   -93,   -93,   -93,   -93,   -93,
893      -93,   -93,   -93,   -93,   -93,   -93,   -93,   -93,   -93,   -93,
894       62,   -93,    82,    -3,    66,     3,    74,    -4,    83,    84,
895       75,   -93,   -93,   -93,   -93,   -93,   -93,   -93,   -93,   -93,
896       71,   -93,    93,   -93,   -93,   -93,   -93,   -93,   -93,    78,
897       72,   -93,   -93,   -93,   -93,   -93,   -93,   -93,   -93,    25,
898      -93,   -93,   -93,   -93,   -93,   -93,   -93,   -93,   -93,   -93,
899      -93,   -93,   -93,   -93,   -93,    21,    19,    79,    80,   -93,
900      -93,   -93,   -93,   -93,    81,   -93,   -93,    85,    86,   -93,
901      -93,   -93,   -93,   -93,    -6,    76,    17,   -93,   -93,   -93,
902      -93,    87,    69,   -93,   -93,    88,    89,    -1,   -93,    18,
903      -93,   -93,    69,    91
904 };
905
906 /* YYPGOTO[NTERM-NUM].  */
907 static const yytype_int8 yypgoto[] =
908 {
909      -93,   -93,   -93,   -93,   -93,   -93,   -93,   -93,    20,   -68,
910      -27,   -93,   -93,   -93,   -93,   -93,   -93,   -93,    60,   -93,
911      -93,   -93,   -92,   -93,   -93,    43
912 };
913
914 /* YYTABLE[YYPACT[STATE-NUM]].  What to do in state STATE-NUM.  If
915    positive, shift that token.  If negative, reduce the rule which
916    number is the opposite.  If YYTABLE_NINF, syntax error.  */
917 #define YYTABLE_NINF -1
918 static const yytype_uint8 yytable[] =
919 {
920       79,    67,    68,    69,    70,    71,    72,    58,    73,   100,
921      107,    74,    75,   101,   110,    76,    49,    50,   101,   102,
922      113,    77,    59,    78,    61,    62,    63,    64,    65,    66,
923       61,    62,    63,    64,    65,    66,   101,   101,    92,   111,
924       90,    91,   106,   112,    88,   111,     5,     6,     7,     8,
925       88,    13,    14,    15,    16,    17,    18,    19,    20,    21,
926       22,     1,    23,    24,    25,    26,    27,    28,    29,    79,
927       30,    51,    52,    53,    54,    55,    56,    12,    57,    61,
928       62,    63,    64,    65,    66,    60,    48,    80,    47,     6,
929       83,     8,    81,    82,    26,    84,    85,    86,    87,    94,
930       95,    96,    89,   105,    97,    98,    99,     0,   108,   109,
931      101,     0,    88
932 };
933
934 #define yypact_value_is_default(yystate) \
935   ((yystate) == (-93))
936
937 #define yytable_value_is_error(yytable_value) \
938   YYID (0)
939
940 static const yytype_int8 yycheck[] =
941 {
942       27,     5,     6,     7,     8,     9,    10,     4,    12,    15,
943      102,    15,    16,    19,    15,    19,    19,    20,    19,    25,
944      112,    25,    19,    27,     5,     6,     7,     8,     9,    10,
945        5,     6,     7,     8,     9,    10,    19,    19,    19,   107,
946       19,    20,    25,    25,    25,   113,    19,    20,    21,    22,
947       25,     5,     6,     7,     8,     9,    10,    11,    12,    13,
948       14,    23,    16,    17,    18,    19,    20,    21,    22,    96,
949       24,     5,     6,     7,     8,     9,    10,     0,    12,     5,
950        6,     7,     8,     9,    10,    25,     4,    27,    26,    20,
951       30,    22,     9,     9,    19,    24,     3,    19,    26,    20,
952       20,    20,    59,    27,    84,    20,    20,    -1,    20,    20,
953       19,    -1,    25
954 };
955
956 /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
957    symbol of state STATE-NUM.  */
958 static const yytype_uint8 yystos[] =
959 {
960        0,    23,    29,    30,    31,    19,    20,    21,    22,    48,
961       49,    50,     0,     5,     6,     7,     8,     9,    10,    11,
962       12,    13,    14,    16,    17,    18,    19,    20,    21,    22,
963       24,    32,    33,    34,    35,    36,    39,    40,    41,    42,
964       43,    44,    45,    46,    47,    51,    52,    26,     4,    19,
965       20,     5,     6,     7,     8,     9,    10,    12,     4,    19,
966       46,     5,     6,     7,     8,     9,    10,     5,     6,     7,
967        8,     9,    10,    12,    15,    16,    19,    25,    27,    38,
968       46,     9,     9,    46,    24,     3,    19,    26,    25,    53,
969       19,    20,    19,    53,    20,    20,    20,    36,    20,    20,
970       15,    19,    25,    37,    38,    27,    25,    50,    20,    20,
971       15,    37,    25,    50
972 };
973
974 #define yyerrok         (yyerrstatus = 0)
975 #define yyclearin       (yychar = YYEMPTY)
976 #define YYEMPTY         (-2)
977 #define YYEOF           0
978
979 #define YYACCEPT        goto yyacceptlab
980 #define YYABORT         goto yyabortlab
981 #define YYERROR         goto yyerrorlab
982
983
984 /* Like YYERROR except do call yyerror.  This remains here temporarily
985    to ease the transition to the new meaning of YYERROR, for GCC.
986    Once GCC version 2 has supplanted version 1, this can go.  However,
987    YYFAIL appears to be in use.  Nevertheless, it is formally deprecated
988    in Bison 2.4.2's NEWS entry, where a plan to phase it out is
989    discussed.  */
990
991 #define YYFAIL          goto yyerrlab
992 #if defined YYFAIL
993   /* This is here to suppress warnings from the GCC cpp's
994      -Wunused-macros.  Normally we don't worry about that warning, but
995      some users do, and we want to make it easy for users to remove
996      YYFAIL uses, which will produce warnings from Bison 2.5.  */
997 #endif
998
999 #define YYRECOVERING()  (!!yyerrstatus)
1000
1001 #define YYBACKUP(Token, Value)                                  \
1002 do                                                              \
1003   if (yychar == YYEMPTY)                                        \
1004     {                                                           \
1005       yychar = (Token);                                         \
1006       yylval = (Value);                                         \
1007       YYPOPSTACK (yylen);                                       \
1008       yystate = *yyssp;                                         \
1009       goto yybackup;                                            \
1010     }                                                           \
1011   else                                                          \
1012     {                                                           \
1013       yyerror (pc, YY_("syntax error: cannot back up")); \
1014       YYERROR;                                                  \
1015     }                                                           \
1016 while (YYID (0))
1017
1018
1019 #define YYTERROR        1
1020 #define YYERRCODE       256
1021
1022
1023 /* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
1024    If N is 0, then set CURRENT to the empty location which ends
1025    the previous symbol: RHS[0] (always defined).  */
1026
1027 #define YYRHSLOC(Rhs, K) ((Rhs)[K])
1028 #ifndef YYLLOC_DEFAULT
1029 # define YYLLOC_DEFAULT(Current, Rhs, N)                                \
1030     do                                                                  \
1031       if (YYID (N))                                                    \
1032         {                                                               \
1033           (Current).first_line   = YYRHSLOC (Rhs, 1).first_line;        \
1034           (Current).first_column = YYRHSLOC (Rhs, 1).first_column;      \
1035           (Current).last_line    = YYRHSLOC (Rhs, N).last_line;         \
1036           (Current).last_column  = YYRHSLOC (Rhs, N).last_column;       \
1037         }                                                               \
1038       else                                                              \
1039         {                                                               \
1040           (Current).first_line   = (Current).last_line   =              \
1041             YYRHSLOC (Rhs, 0).last_line;                                \
1042           (Current).first_column = (Current).last_column =              \
1043             YYRHSLOC (Rhs, 0).last_column;                              \
1044         }                                                               \
1045     while (YYID (0))
1046 #endif
1047
1048
1049 /* This macro is provided for backward compatibility. */
1050
1051 #ifndef YY_LOCATION_PRINT
1052 # define YY_LOCATION_PRINT(File, Loc) ((void) 0)
1053 #endif
1054
1055
1056 /* YYLEX -- calling `yylex' with the right arguments.  */
1057
1058 #ifdef YYLEX_PARAM
1059 # define YYLEX yylex (&yylval, YYLEX_PARAM)
1060 #else
1061 # define YYLEX yylex (&yylval, pc)
1062 #endif
1063
1064 /* Enable debugging if requested.  */
1065 #if YYDEBUG
1066
1067 # ifndef YYFPRINTF
1068 #  include <stdio.h> /* INFRINGES ON USER NAME SPACE */
1069 #  define YYFPRINTF fprintf
1070 # endif
1071
1072 # define YYDPRINTF(Args)                        \
1073 do {                                            \
1074   if (yydebug)                                  \
1075     YYFPRINTF Args;                             \
1076 } while (YYID (0))
1077
1078 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)                    \
1079 do {                                                                      \
1080   if (yydebug)                                                            \
1081     {                                                                     \
1082       YYFPRINTF (stderr, "%s ", Title);                                   \
1083       yy_symbol_print (stderr,                                            \
1084                   Type, Value, pc); \
1085       YYFPRINTF (stderr, "\n");                                           \
1086     }                                                                     \
1087 } while (YYID (0))
1088
1089
1090 /*--------------------------------.
1091 | Print this symbol on YYOUTPUT.  |
1092 `--------------------------------*/
1093
1094 /*ARGSUSED*/
1095 #if (defined __STDC__ || defined __C99__FUNC__ \
1096      || defined __cplusplus || defined _MSC_VER)
1097 static void
1098 yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, parser_control *pc)
1099 #else
1100 static void
1101 yy_symbol_value_print (yyoutput, yytype, yyvaluep, pc)
1102     FILE *yyoutput;
1103     int yytype;
1104     YYSTYPE const * const yyvaluep;
1105     parser_control *pc;
1106 #endif
1107 {
1108   FILE *yyo = yyoutput;
1109   YYUSE (yyo);
1110   if (!yyvaluep)
1111     return;
1112   YYUSE (pc);
1113 # ifdef YYPRINT
1114   if (yytype < YYNTOKENS)
1115     YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep);
1116 # else
1117   YYUSE (yyoutput);
1118 # endif
1119   switch (yytype)
1120     {
1121       default:
1122         break;
1123     }
1124 }
1125
1126
1127 /*--------------------------------.
1128 | Print this symbol on YYOUTPUT.  |
1129 `--------------------------------*/
1130
1131 #if (defined __STDC__ || defined __C99__FUNC__ \
1132      || defined __cplusplus || defined _MSC_VER)
1133 static void
1134 yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, parser_control *pc)
1135 #else
1136 static void
1137 yy_symbol_print (yyoutput, yytype, yyvaluep, pc)
1138     FILE *yyoutput;
1139     int yytype;
1140     YYSTYPE const * const yyvaluep;
1141     parser_control *pc;
1142 #endif
1143 {
1144   if (yytype < YYNTOKENS)
1145     YYFPRINTF (yyoutput, "token %s (", yytname[yytype]);
1146   else
1147     YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]);
1148
1149   yy_symbol_value_print (yyoutput, yytype, yyvaluep, pc);
1150   YYFPRINTF (yyoutput, ")");
1151 }
1152
1153 /*------------------------------------------------------------------.
1154 | yy_stack_print -- Print the state stack from its BOTTOM up to its |
1155 | TOP (included).                                                   |
1156 `------------------------------------------------------------------*/
1157
1158 #if (defined __STDC__ || defined __C99__FUNC__ \
1159      || defined __cplusplus || defined _MSC_VER)
1160 static void
1161 yy_stack_print (yytype_int16 *yybottom, yytype_int16 *yytop)
1162 #else
1163 static void
1164 yy_stack_print (yybottom, yytop)
1165     yytype_int16 *yybottom;
1166     yytype_int16 *yytop;
1167 #endif
1168 {
1169   YYFPRINTF (stderr, "Stack now");
1170   for (; yybottom <= yytop; yybottom++)
1171     {
1172       int yybot = *yybottom;
1173       YYFPRINTF (stderr, " %d", yybot);
1174     }
1175   YYFPRINTF (stderr, "\n");
1176 }
1177
1178 # define YY_STACK_PRINT(Bottom, Top)                            \
1179 do {                                                            \
1180   if (yydebug)                                                  \
1181     yy_stack_print ((Bottom), (Top));                           \
1182 } while (YYID (0))
1183
1184
1185 /*------------------------------------------------.
1186 | Report that the YYRULE is going to be reduced.  |
1187 `------------------------------------------------*/
1188
1189 #if (defined __STDC__ || defined __C99__FUNC__ \
1190      || defined __cplusplus || defined _MSC_VER)
1191 static void
1192 yy_reduce_print (YYSTYPE *yyvsp, int yyrule, parser_control *pc)
1193 #else
1194 static void
1195 yy_reduce_print (yyvsp, yyrule, pc)
1196     YYSTYPE *yyvsp;
1197     int yyrule;
1198     parser_control *pc;
1199 #endif
1200 {
1201   int yynrhs = yyr2[yyrule];
1202   int yyi;
1203   unsigned long int yylno = yyrline[yyrule];
1204   YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n",
1205              yyrule - 1, yylno);
1206   /* The symbols being reduced.  */
1207   for (yyi = 0; yyi < yynrhs; yyi++)
1208     {
1209       YYFPRINTF (stderr, "   $%d = ", yyi + 1);
1210       yy_symbol_print (stderr, yyrhs[yyprhs[yyrule] + yyi],
1211                        &(yyvsp[(yyi + 1) - (yynrhs)])
1212                                        , pc);
1213       YYFPRINTF (stderr, "\n");
1214     }
1215 }
1216
1217 # define YY_REDUCE_PRINT(Rule)          \
1218 do {                                    \
1219   if (yydebug)                          \
1220     yy_reduce_print (yyvsp, Rule, pc); \
1221 } while (YYID (0))
1222
1223 /* Nonzero means print parse trace.  It is left uninitialized so that
1224    multiple parsers can coexist.  */
1225 int yydebug;
1226 #else /* !YYDEBUG */
1227 # define YYDPRINTF(Args)
1228 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
1229 # define YY_STACK_PRINT(Bottom, Top)
1230 # define YY_REDUCE_PRINT(Rule)
1231 #endif /* !YYDEBUG */
1232
1233
1234 /* YYINITDEPTH -- initial size of the parser's stacks.  */
1235 #ifndef YYINITDEPTH
1236 # define YYINITDEPTH 200
1237 #endif
1238
1239 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
1240    if the built-in stack extension method is used).
1241
1242    Do not make this value too large; the results are undefined if
1243    YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH)
1244    evaluated with infinite-precision integer arithmetic.  */
1245
1246 #ifndef YYMAXDEPTH
1247 # define YYMAXDEPTH 10000
1248 #endif
1249
1250
1251 #if YYERROR_VERBOSE
1252
1253 # ifndef yystrlen
1254 #  if defined __GLIBC__ && defined _STRING_H
1255 #   define yystrlen strlen
1256 #  else
1257 /* Return the length of YYSTR.  */
1258 #if (defined __STDC__ || defined __C99__FUNC__ \
1259      || defined __cplusplus || defined _MSC_VER)
1260 static YYSIZE_T
1261 yystrlen (const char *yystr)
1262 #else
1263 static YYSIZE_T
1264 yystrlen (yystr)
1265     const char *yystr;
1266 #endif
1267 {
1268   YYSIZE_T yylen;
1269   for (yylen = 0; yystr[yylen]; yylen++)
1270     continue;
1271   return yylen;
1272 }
1273 #  endif
1274 # endif
1275
1276 # ifndef yystpcpy
1277 #  if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
1278 #   define yystpcpy stpcpy
1279 #  else
1280 /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
1281    YYDEST.  */
1282 #if (defined __STDC__ || defined __C99__FUNC__ \
1283      || defined __cplusplus || defined _MSC_VER)
1284 static char *
1285 yystpcpy (char *yydest, const char *yysrc)
1286 #else
1287 static char *
1288 yystpcpy (yydest, yysrc)
1289     char *yydest;
1290     const char *yysrc;
1291 #endif
1292 {
1293   char *yyd = yydest;
1294   const char *yys = yysrc;
1295
1296   while ((*yyd++ = *yys++) != '\0')
1297     continue;
1298
1299   return yyd - 1;
1300 }
1301 #  endif
1302 # endif
1303
1304 # ifndef yytnamerr
1305 /* Copy to YYRES the contents of YYSTR after stripping away unnecessary
1306    quotes and backslashes, so that it's suitable for yyerror.  The
1307    heuristic is that double-quoting is unnecessary unless the string
1308    contains an apostrophe, a comma, or backslash (other than
1309    backslash-backslash).  YYSTR is taken from yytname.  If YYRES is
1310    null, do not copy; instead, return the length of what the result
1311    would have been.  */
1312 static YYSIZE_T
1313 yytnamerr (char *yyres, const char *yystr)
1314 {
1315   if (*yystr == '"')
1316     {
1317       YYSIZE_T yyn = 0;
1318       char const *yyp = yystr;
1319
1320       for (;;)
1321         switch (*++yyp)
1322           {
1323           case '\'':
1324           case ',':
1325             goto do_not_strip_quotes;
1326
1327           case '\\':
1328             if (*++yyp != '\\')
1329               goto do_not_strip_quotes;
1330             /* Fall through.  */
1331           default:
1332             if (yyres)
1333               yyres[yyn] = *yyp;
1334             yyn++;
1335             break;
1336
1337           case '"':
1338             if (yyres)
1339               yyres[yyn] = '\0';
1340             return yyn;
1341           }
1342     do_not_strip_quotes: ;
1343     }
1344
1345   if (! yyres)
1346     return yystrlen (yystr);
1347
1348   return yystpcpy (yyres, yystr) - yyres;
1349 }
1350 # endif
1351
1352 /* Copy into *YYMSG, which is of size *YYMSG_ALLOC, an error message
1353    about the unexpected token YYTOKEN for the state stack whose top is
1354    YYSSP.
1355
1356    Return 0 if *YYMSG was successfully written.  Return 1 if *YYMSG is
1357    not large enough to hold the message.  In that case, also set
1358    *YYMSG_ALLOC to the required number of bytes.  Return 2 if the
1359    required number of bytes is too large to store.  */
1360 static int
1361 yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg,
1362                 yytype_int16 *yyssp, int yytoken)
1363 {
1364   YYSIZE_T yysize0 = yytnamerr (YY_NULL, yytname[yytoken]);
1365   YYSIZE_T yysize = yysize0;
1366   YYSIZE_T yysize1;
1367   enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
1368   /* Internationalized format string. */
1369   const char *yyformat = YY_NULL;
1370   /* Arguments of yyformat. */
1371   char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
1372   /* Number of reported tokens (one for the "unexpected", one per
1373      "expected"). */
1374   int yycount = 0;
1375
1376   /* There are many possibilities here to consider:
1377      - Assume YYFAIL is not used.  It's too flawed to consider.  See
1378        <http://lists.gnu.org/archive/html/bison-patches/2009-12/msg00024.html>
1379        for details.  YYERROR is fine as it does not invoke this
1380        function.
1381      - If this state is a consistent state with a default action, then
1382        the only way this function was invoked is if the default action
1383        is an error action.  In that case, don't check for expected
1384        tokens because there are none.
1385      - The only way there can be no lookahead present (in yychar) is if
1386        this state is a consistent state with a default action.  Thus,
1387        detecting the absence of a lookahead is sufficient to determine
1388        that there is no unexpected or expected token to report.  In that
1389        case, just report a simple "syntax error".
1390      - Don't assume there isn't a lookahead just because this state is a
1391        consistent state with a default action.  There might have been a
1392        previous inconsistent state, consistent state with a non-default
1393        action, or user semantic action that manipulated yychar.
1394      - Of course, the expected token list depends on states to have
1395        correct lookahead information, and it depends on the parser not
1396        to perform extra reductions after fetching a lookahead from the
1397        scanner and before detecting a syntax error.  Thus, state merging
1398        (from LALR or IELR) and default reductions corrupt the expected
1399        token list.  However, the list is correct for canonical LR with
1400        one exception: it will still contain any token that will not be
1401        accepted due to an error action in a later state.
1402   */
1403   if (yytoken != YYEMPTY)
1404     {
1405       int yyn = yypact[*yyssp];
1406       yyarg[yycount++] = yytname[yytoken];
1407       if (!yypact_value_is_default (yyn))
1408         {
1409           /* Start YYX at -YYN if negative to avoid negative indexes in
1410              YYCHECK.  In other words, skip the first -YYN actions for
1411              this state because they are default actions.  */
1412           int yyxbegin = yyn < 0 ? -yyn : 0;
1413           /* Stay within bounds of both yycheck and yytname.  */
1414           int yychecklim = YYLAST - yyn + 1;
1415           int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
1416           int yyx;
1417
1418           for (yyx = yyxbegin; yyx < yyxend; ++yyx)
1419             if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR
1420                 && !yytable_value_is_error (yytable[yyx + yyn]))
1421               {
1422                 if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
1423                   {
1424                     yycount = 1;
1425                     yysize = yysize0;
1426                     break;
1427                   }
1428                 yyarg[yycount++] = yytname[yyx];
1429                 yysize1 = yysize + yytnamerr (YY_NULL, yytname[yyx]);
1430                 if (! (yysize <= yysize1
1431                        && yysize1 <= YYSTACK_ALLOC_MAXIMUM))
1432                   return 2;
1433                 yysize = yysize1;
1434               }
1435         }
1436     }
1437
1438   switch (yycount)
1439     {
1440 # define YYCASE_(N, S)                      \
1441       case N:                               \
1442         yyformat = S;                       \
1443       break
1444       YYCASE_(0, YY_("syntax error"));
1445       YYCASE_(1, YY_("syntax error, unexpected %s"));
1446       YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s"));
1447       YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s"));
1448       YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s"));
1449       YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"));
1450 # undef YYCASE_
1451     }
1452
1453   yysize1 = yysize + yystrlen (yyformat);
1454   if (! (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM))
1455     return 2;
1456   yysize = yysize1;
1457
1458   if (*yymsg_alloc < yysize)
1459     {
1460       *yymsg_alloc = 2 * yysize;
1461       if (! (yysize <= *yymsg_alloc
1462              && *yymsg_alloc <= YYSTACK_ALLOC_MAXIMUM))
1463         *yymsg_alloc = YYSTACK_ALLOC_MAXIMUM;
1464       return 1;
1465     }
1466
1467   /* Avoid sprintf, as that infringes on the user's name space.
1468      Don't have undefined behavior even if the translation
1469      produced a string with the wrong number of "%s"s.  */
1470   {
1471     char *yyp = *yymsg;
1472     int yyi = 0;
1473     while ((*yyp = *yyformat) != '\0')
1474       if (*yyp == '%' && yyformat[1] == 's' && yyi < yycount)
1475         {
1476           yyp += yytnamerr (yyp, yyarg[yyi++]);
1477           yyformat += 2;
1478         }
1479       else
1480         {
1481           yyp++;
1482           yyformat++;
1483         }
1484   }
1485   return 0;
1486 }
1487 #endif /* YYERROR_VERBOSE */
1488
1489 /*-----------------------------------------------.
1490 | Release the memory associated to this symbol.  |
1491 `-----------------------------------------------*/
1492
1493 /*ARGSUSED*/
1494 #if (defined __STDC__ || defined __C99__FUNC__ \
1495      || defined __cplusplus || defined _MSC_VER)
1496 static void
1497 yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep, parser_control *pc)
1498 #else
1499 static void
1500 yydestruct (yymsg, yytype, yyvaluep, pc)
1501     const char *yymsg;
1502     int yytype;
1503     YYSTYPE *yyvaluep;
1504     parser_control *pc;
1505 #endif
1506 {
1507   YYUSE (yyvaluep);
1508   YYUSE (pc);
1509
1510   if (!yymsg)
1511     yymsg = "Deleting";
1512   YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
1513
1514   switch (yytype)
1515     {
1516
1517       default:
1518         break;
1519     }
1520 }
1521
1522
1523 /* Prevent warnings from -Wmissing-prototypes.  */
1524 #ifdef YYPARSE_PARAM
1525 #if defined __STDC__ || defined __cplusplus
1526 int yyparse (void *YYPARSE_PARAM);
1527 #else
1528 int yyparse ();
1529 #endif
1530 #else /* ! YYPARSE_PARAM */
1531 #if defined __STDC__ || defined __cplusplus
1532 int yyparse (parser_control *pc);
1533 #else
1534 int yyparse ();
1535 #endif
1536 #endif /* ! YYPARSE_PARAM */
1537
1538
1539 /*----------.
1540 | yyparse.  |
1541 `----------*/
1542
1543 #ifdef YYPARSE_PARAM
1544 #if (defined __STDC__ || defined __C99__FUNC__ \
1545      || defined __cplusplus || defined _MSC_VER)
1546 int
1547 yyparse (void *YYPARSE_PARAM)
1548 #else
1549 int
1550 yyparse (YYPARSE_PARAM)
1551     void *YYPARSE_PARAM;
1552 #endif
1553 #else /* ! YYPARSE_PARAM */
1554 #if (defined __STDC__ || defined __C99__FUNC__ \
1555      || defined __cplusplus || defined _MSC_VER)
1556 int
1557 yyparse (parser_control *pc)
1558 #else
1559 int
1560 yyparse (pc)
1561     parser_control *pc;
1562 #endif
1563 #endif
1564 {
1565 /* The lookahead symbol.  */
1566 int yychar;
1567
1568 /* The semantic value of the lookahead symbol.  */
1569 YYSTYPE yylval;
1570
1571     /* Number of syntax errors so far.  */
1572     int yynerrs;
1573
1574     int yystate;
1575     /* Number of tokens to shift before error messages enabled.  */
1576     int yyerrstatus;
1577
1578     /* The stacks and their tools:
1579        `yyss': related to states.
1580        `yyvs': related to semantic values.
1581
1582        Refer to the stacks through separate pointers, to allow yyoverflow
1583        to reallocate them elsewhere.  */
1584
1585     /* The state stack.  */
1586     yytype_int16 yyssa[YYINITDEPTH];
1587     yytype_int16 *yyss;
1588     yytype_int16 *yyssp;
1589
1590     /* The semantic value stack.  */
1591     YYSTYPE yyvsa[YYINITDEPTH];
1592     YYSTYPE *yyvs;
1593     YYSTYPE *yyvsp;
1594
1595     YYSIZE_T yystacksize;
1596
1597   int yyn;
1598   int yyresult;
1599   /* Lookahead token as an internal (translated) token number.  */
1600   int yytoken;
1601   /* The variables used to return semantic value and location from the
1602      action routines.  */
1603   YYSTYPE yyval;
1604
1605 #if YYERROR_VERBOSE
1606   /* Buffer for error messages, and its allocated size.  */
1607   char yymsgbuf[128];
1608   char *yymsg = yymsgbuf;
1609   YYSIZE_T yymsg_alloc = sizeof yymsgbuf;
1610 #endif
1611
1612 #define YYPOPSTACK(N)   (yyvsp -= (N), yyssp -= (N))
1613
1614   /* The number of symbols on the RHS of the reduced rule.
1615      Keep to zero when no symbol should be popped.  */
1616   int yylen = 0;
1617
1618   yytoken = 0;
1619   yyss = yyssa;
1620   yyvs = yyvsa;
1621   yystacksize = YYINITDEPTH;
1622
1623   YYDPRINTF ((stderr, "Starting parse\n"));
1624
1625   yystate = 0;
1626   yyerrstatus = 0;
1627   yynerrs = 0;
1628   yychar = YYEMPTY; /* Cause a token to be read.  */
1629
1630   /* Initialize stack pointers.
1631      Waste one element of value and location stack
1632      so that they stay on the same level as the state stack.
1633      The wasted elements are never initialized.  */
1634   yyssp = yyss;
1635   yyvsp = yyvs;
1636
1637   goto yysetstate;
1638
1639 /*------------------------------------------------------------.
1640 | yynewstate -- Push a new state, which is found in yystate.  |
1641 `------------------------------------------------------------*/
1642  yynewstate:
1643   /* In all cases, when you get here, the value and location stacks
1644      have just been pushed.  So pushing a state here evens the stacks.  */
1645   yyssp++;
1646
1647  yysetstate:
1648   *yyssp = yystate;
1649
1650   if (yyss + yystacksize - 1 <= yyssp)
1651     {
1652       /* Get the current used size of the three stacks, in elements.  */
1653       YYSIZE_T yysize = yyssp - yyss + 1;
1654
1655 #ifdef yyoverflow
1656       {
1657         /* Give user a chance to reallocate the stack.  Use copies of
1658            these so that the &'s don't force the real ones into
1659            memory.  */
1660         YYSTYPE *yyvs1 = yyvs;
1661         yytype_int16 *yyss1 = yyss;
1662
1663         /* Each stack pointer address is followed by the size of the
1664            data in use in that stack, in bytes.  This used to be a
1665            conditional around just the two extra args, but that might
1666            be undefined if yyoverflow is a macro.  */
1667         yyoverflow (YY_("memory exhausted"),
1668                     &yyss1, yysize * sizeof (*yyssp),
1669                     &yyvs1, yysize * sizeof (*yyvsp),
1670                     &yystacksize);
1671
1672         yyss = yyss1;
1673         yyvs = yyvs1;
1674       }
1675 #else /* no yyoverflow */
1676 # ifndef YYSTACK_RELOCATE
1677       goto yyexhaustedlab;
1678 # else
1679       /* Extend the stack our own way.  */
1680       if (YYMAXDEPTH <= yystacksize)
1681         goto yyexhaustedlab;
1682       yystacksize *= 2;
1683       if (YYMAXDEPTH < yystacksize)
1684         yystacksize = YYMAXDEPTH;
1685
1686       {
1687         yytype_int16 *yyss1 = yyss;
1688         union yyalloc *yyptr =
1689           (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
1690         if (! yyptr)
1691           goto yyexhaustedlab;
1692         YYSTACK_RELOCATE (yyss_alloc, yyss);
1693         YYSTACK_RELOCATE (yyvs_alloc, yyvs);
1694 #  undef YYSTACK_RELOCATE
1695         if (yyss1 != yyssa)
1696           YYSTACK_FREE (yyss1);
1697       }
1698 # endif
1699 #endif /* no yyoverflow */
1700
1701       yyssp = yyss + yysize - 1;
1702       yyvsp = yyvs + yysize - 1;
1703
1704       YYDPRINTF ((stderr, "Stack size increased to %lu\n",
1705                   (unsigned long int) yystacksize));
1706
1707       if (yyss + yystacksize - 1 <= yyssp)
1708         YYABORT;
1709     }
1710
1711   YYDPRINTF ((stderr, "Entering state %d\n", yystate));
1712
1713   if (yystate == YYFINAL)
1714     YYACCEPT;
1715
1716   goto yybackup;
1717
1718 /*-----------.
1719 | yybackup.  |
1720 `-----------*/
1721 yybackup:
1722
1723   /* Do appropriate processing given the current state.  Read a
1724      lookahead token if we need one and don't already have one.  */
1725
1726   /* First try to decide what to do without reference to lookahead token.  */
1727   yyn = yypact[yystate];
1728   if (yypact_value_is_default (yyn))
1729     goto yydefault;
1730
1731   /* Not known => get a lookahead token if don't already have one.  */
1732
1733   /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol.  */
1734   if (yychar == YYEMPTY)
1735     {
1736       YYDPRINTF ((stderr, "Reading a token: "));
1737       yychar = YYLEX;
1738     }
1739
1740   if (yychar <= YYEOF)
1741     {
1742       yychar = yytoken = YYEOF;
1743       YYDPRINTF ((stderr, "Now at end of input.\n"));
1744     }
1745   else
1746     {
1747       yytoken = YYTRANSLATE (yychar);
1748       YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
1749     }
1750
1751   /* If the proper action on seeing token YYTOKEN is to reduce or to
1752      detect an error, take that action.  */
1753   yyn += yytoken;
1754   if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
1755     goto yydefault;
1756   yyn = yytable[yyn];
1757   if (yyn <= 0)
1758     {
1759       if (yytable_value_is_error (yyn))
1760         goto yyerrlab;
1761       yyn = -yyn;
1762       goto yyreduce;
1763     }
1764
1765   /* Count tokens shifted since error; after three, turn off error
1766      status.  */
1767   if (yyerrstatus)
1768     yyerrstatus--;
1769
1770   /* Shift the lookahead token.  */
1771   YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
1772
1773   /* Discard the shifted token.  */
1774   yychar = YYEMPTY;
1775
1776   yystate = yyn;
1777   *++yyvsp = yylval;
1778
1779   goto yynewstate;
1780
1781
1782 /*-----------------------------------------------------------.
1783 | yydefault -- do the default action for the current state.  |
1784 `-----------------------------------------------------------*/
1785 yydefault:
1786   yyn = yydefact[yystate];
1787   if (yyn == 0)
1788     goto yyerrlab;
1789   goto yyreduce;
1790
1791
1792 /*-----------------------------.
1793 | yyreduce -- Do a reduction.  |
1794 `-----------------------------*/
1795 yyreduce:
1796   /* yyn is the number of a rule to reduce with.  */
1797   yylen = yyr2[yyn];
1798
1799   /* If YYLEN is nonzero, implement the default value of the action:
1800      `$$ = $1'.
1801
1802      Otherwise, the following line sets YYVAL to garbage.
1803      This behavior is undocumented and Bison
1804      users should not rely upon it.  Assigning to YYVAL
1805      unconditionally makes the parser a bit smaller, and it avoids a
1806      GCC warning that YYVAL may be used uninitialized.  */
1807   yyval = yyvsp[1-yylen];
1808
1809
1810   YY_REDUCE_PRINT (yyn);
1811   switch (yyn)
1812     {
1813         case 4:
1814
1815 /* Line 1810 of yacc.c  */
1816 #line 330 "./parse-datetime.y"
1817     {
1818         pc->seconds = (yyvsp[(2) - (2)].timespec);
1819         pc->timespec_seen = true;
1820       }
1821     break;
1822
1823   case 7:
1824
1825 /* Line 1810 of yacc.c  */
1826 #line 343 "./parse-datetime.y"
1827     { pc->times_seen++; pc->dates_seen++; }
1828     break;
1829
1830   case 8:
1831
1832 /* Line 1810 of yacc.c  */
1833 #line 345 "./parse-datetime.y"
1834     { pc->times_seen++; }
1835     break;
1836
1837   case 9:
1838
1839 /* Line 1810 of yacc.c  */
1840 #line 347 "./parse-datetime.y"
1841     { pc->local_zones_seen++; }
1842     break;
1843
1844   case 10:
1845
1846 /* Line 1810 of yacc.c  */
1847 #line 349 "./parse-datetime.y"
1848     { pc->zones_seen++; }
1849     break;
1850
1851   case 11:
1852
1853 /* Line 1810 of yacc.c  */
1854 #line 351 "./parse-datetime.y"
1855     { pc->dates_seen++; }
1856     break;
1857
1858   case 12:
1859
1860 /* Line 1810 of yacc.c  */
1861 #line 353 "./parse-datetime.y"
1862     { pc->days_seen++; }
1863     break;
1864
1865   case 18:
1866
1867 /* Line 1810 of yacc.c  */
1868 #line 369 "./parse-datetime.y"
1869     {
1870         set_hhmmss (pc, (yyvsp[(1) - (2)].textintval).value, 0, 0, 0);
1871         pc->meridian = (yyvsp[(2) - (2)].intval);
1872       }
1873     break;
1874
1875   case 19:
1876
1877 /* Line 1810 of yacc.c  */
1878 #line 374 "./parse-datetime.y"
1879     {
1880         set_hhmmss (pc, (yyvsp[(1) - (4)].textintval).value, (yyvsp[(3) - (4)].textintval).value, 0, 0);
1881         pc->meridian = (yyvsp[(4) - (4)].intval);
1882       }
1883     break;
1884
1885   case 20:
1886
1887 /* Line 1810 of yacc.c  */
1888 #line 379 "./parse-datetime.y"
1889     {
1890         set_hhmmss (pc, (yyvsp[(1) - (6)].textintval).value, (yyvsp[(3) - (6)].textintval).value, (yyvsp[(5) - (6)].timespec).tv_sec, (yyvsp[(5) - (6)].timespec).tv_nsec);
1891         pc->meridian = (yyvsp[(6) - (6)].intval);
1892       }
1893     break;
1894
1895   case 22:
1896
1897 /* Line 1810 of yacc.c  */
1898 #line 388 "./parse-datetime.y"
1899     {
1900         set_hhmmss (pc, (yyvsp[(1) - (2)].textintval).value, 0, 0, 0);
1901         pc->meridian = MER24;
1902       }
1903     break;
1904
1905   case 23:
1906
1907 /* Line 1810 of yacc.c  */
1908 #line 393 "./parse-datetime.y"
1909     {
1910         set_hhmmss (pc, (yyvsp[(1) - (4)].textintval).value, (yyvsp[(3) - (4)].textintval).value, 0, 0);
1911         pc->meridian = MER24;
1912       }
1913     break;
1914
1915   case 24:
1916
1917 /* Line 1810 of yacc.c  */
1918 #line 398 "./parse-datetime.y"
1919     {
1920         set_hhmmss (pc, (yyvsp[(1) - (6)].textintval).value, (yyvsp[(3) - (6)].textintval).value, (yyvsp[(5) - (6)].timespec).tv_sec, (yyvsp[(5) - (6)].timespec).tv_nsec);
1921         pc->meridian = MER24;
1922       }
1923     break;
1924
1925   case 27:
1926
1927 /* Line 1810 of yacc.c  */
1928 #line 411 "./parse-datetime.y"
1929     {
1930         pc->zones_seen++;
1931         pc->time_zone = time_zone_hhmm (pc, (yyvsp[(1) - (2)].textintval), (yyvsp[(2) - (2)].intval));
1932       }
1933     break;
1934
1935   case 28:
1936
1937 /* Line 1810 of yacc.c  */
1938 #line 419 "./parse-datetime.y"
1939     {
1940         pc->local_isdst = (yyvsp[(1) - (1)].intval);
1941         pc->dsts_seen += (0 < (yyvsp[(1) - (1)].intval));
1942       }
1943     break;
1944
1945   case 29:
1946
1947 /* Line 1810 of yacc.c  */
1948 #line 424 "./parse-datetime.y"
1949     {
1950         pc->local_isdst = 1;
1951         pc->dsts_seen += (0 < (yyvsp[(1) - (2)].intval)) + 1;
1952       }
1953     break;
1954
1955   case 30:
1956
1957 /* Line 1810 of yacc.c  */
1958 #line 434 "./parse-datetime.y"
1959     { pc->time_zone = (yyvsp[(1) - (1)].intval); }
1960     break;
1961
1962   case 31:
1963
1964 /* Line 1810 of yacc.c  */
1965 #line 436 "./parse-datetime.y"
1966     { pc->time_zone = HOUR(7); }
1967     break;
1968
1969   case 32:
1970
1971 /* Line 1810 of yacc.c  */
1972 #line 438 "./parse-datetime.y"
1973     { pc->time_zone = (yyvsp[(1) - (2)].intval);
1974         apply_relative_time (pc, (yyvsp[(2) - (2)].rel), 1); }
1975     break;
1976
1977   case 33:
1978
1979 /* Line 1810 of yacc.c  */
1980 #line 441 "./parse-datetime.y"
1981     { pc->time_zone = HOUR(7);
1982         apply_relative_time (pc, (yyvsp[(2) - (2)].rel), 1); }
1983     break;
1984
1985   case 34:
1986
1987 /* Line 1810 of yacc.c  */
1988 #line 444 "./parse-datetime.y"
1989     { pc->time_zone = (yyvsp[(1) - (3)].intval) + time_zone_hhmm (pc, (yyvsp[(2) - (3)].textintval), (yyvsp[(3) - (3)].intval)); }
1990     break;
1991
1992   case 35:
1993
1994 /* Line 1810 of yacc.c  */
1995 #line 446 "./parse-datetime.y"
1996     { pc->time_zone = (yyvsp[(1) - (1)].intval) + 60; }
1997     break;
1998
1999   case 36:
2000
2001 /* Line 1810 of yacc.c  */
2002 #line 448 "./parse-datetime.y"
2003     { pc->time_zone = (yyvsp[(1) - (2)].intval) + 60; }
2004     break;
2005
2006   case 37:
2007
2008 /* Line 1810 of yacc.c  */
2009 #line 453 "./parse-datetime.y"
2010     {
2011         pc->day_ordinal = 0;
2012         pc->day_number = (yyvsp[(1) - (1)].intval);
2013       }
2014     break;
2015
2016   case 38:
2017
2018 /* Line 1810 of yacc.c  */
2019 #line 458 "./parse-datetime.y"
2020     {
2021         pc->day_ordinal = 0;
2022         pc->day_number = (yyvsp[(1) - (2)].intval);
2023       }
2024     break;
2025
2026   case 39:
2027
2028 /* Line 1810 of yacc.c  */
2029 #line 463 "./parse-datetime.y"
2030     {
2031         pc->day_ordinal = (yyvsp[(1) - (2)].intval);
2032         pc->day_number = (yyvsp[(2) - (2)].intval);
2033       }
2034     break;
2035
2036   case 40:
2037
2038 /* Line 1810 of yacc.c  */
2039 #line 468 "./parse-datetime.y"
2040     {
2041         pc->day_ordinal = (yyvsp[(1) - (2)].textintval).value;
2042         pc->day_number = (yyvsp[(2) - (2)].intval);
2043       }
2044     break;
2045
2046   case 41:
2047
2048 /* Line 1810 of yacc.c  */
2049 #line 476 "./parse-datetime.y"
2050     {
2051         pc->month = (yyvsp[(1) - (3)].textintval).value;
2052         pc->day = (yyvsp[(3) - (3)].textintval).value;
2053       }
2054     break;
2055
2056   case 42:
2057
2058 /* Line 1810 of yacc.c  */
2059 #line 481 "./parse-datetime.y"
2060     {
2061         /* Interpret as YYYY/MM/DD if the first value has 4 or more digits,
2062            otherwise as MM/DD/YY.
2063            The goal in recognizing YYYY/MM/DD is solely to support legacy
2064            machine-generated dates like those in an RCS log listing.  If
2065            you want portability, use the ISO 8601 format.  */
2066         if (4 <= (yyvsp[(1) - (5)].textintval).digits)
2067           {
2068             pc->year = (yyvsp[(1) - (5)].textintval);
2069             pc->month = (yyvsp[(3) - (5)].textintval).value;
2070             pc->day = (yyvsp[(5) - (5)].textintval).value;
2071           }
2072         else
2073           {
2074             pc->month = (yyvsp[(1) - (5)].textintval).value;
2075             pc->day = (yyvsp[(3) - (5)].textintval).value;
2076             pc->year = (yyvsp[(5) - (5)].textintval);
2077           }
2078       }
2079     break;
2080
2081   case 43:
2082
2083 /* Line 1810 of yacc.c  */
2084 #line 501 "./parse-datetime.y"
2085     {
2086         /* e.g. 17-JUN-1992.  */
2087         pc->day = (yyvsp[(1) - (3)].textintval).value;
2088         pc->month = (yyvsp[(2) - (3)].intval);
2089         pc->year.value = -(yyvsp[(3) - (3)].textintval).value;
2090         pc->year.digits = (yyvsp[(3) - (3)].textintval).digits;
2091       }
2092     break;
2093
2094   case 44:
2095
2096 /* Line 1810 of yacc.c  */
2097 #line 509 "./parse-datetime.y"
2098     {
2099         /* e.g. JUN-17-1992.  */
2100         pc->month = (yyvsp[(1) - (3)].intval);
2101         pc->day = -(yyvsp[(2) - (3)].textintval).value;
2102         pc->year.value = -(yyvsp[(3) - (3)].textintval).value;
2103         pc->year.digits = (yyvsp[(3) - (3)].textintval).digits;
2104       }
2105     break;
2106
2107   case 45:
2108
2109 /* Line 1810 of yacc.c  */
2110 #line 517 "./parse-datetime.y"
2111     {
2112         pc->month = (yyvsp[(1) - (2)].intval);
2113         pc->day = (yyvsp[(2) - (2)].textintval).value;
2114       }
2115     break;
2116
2117   case 46:
2118
2119 /* Line 1810 of yacc.c  */
2120 #line 522 "./parse-datetime.y"
2121     {
2122         pc->month = (yyvsp[(1) - (4)].intval);
2123         pc->day = (yyvsp[(2) - (4)].textintval).value;
2124         pc->year = (yyvsp[(4) - (4)].textintval);
2125       }
2126     break;
2127
2128   case 47:
2129
2130 /* Line 1810 of yacc.c  */
2131 #line 528 "./parse-datetime.y"
2132     {
2133         pc->day = (yyvsp[(1) - (2)].textintval).value;
2134         pc->month = (yyvsp[(2) - (2)].intval);
2135       }
2136     break;
2137
2138   case 48:
2139
2140 /* Line 1810 of yacc.c  */
2141 #line 533 "./parse-datetime.y"
2142     {
2143         pc->day = (yyvsp[(1) - (3)].textintval).value;
2144         pc->month = (yyvsp[(2) - (3)].intval);
2145         pc->year = (yyvsp[(3) - (3)].textintval);
2146       }
2147     break;
2148
2149   case 50:
2150
2151 /* Line 1810 of yacc.c  */
2152 #line 543 "./parse-datetime.y"
2153     {
2154         /* ISO 8601 format.  YYYY-MM-DD.  */
2155         pc->year = (yyvsp[(1) - (3)].textintval);
2156         pc->month = -(yyvsp[(2) - (3)].textintval).value;
2157         pc->day = -(yyvsp[(3) - (3)].textintval).value;
2158       }
2159     break;
2160
2161   case 51:
2162
2163 /* Line 1810 of yacc.c  */
2164 #line 553 "./parse-datetime.y"
2165     { apply_relative_time (pc, (yyvsp[(1) - (2)].rel), (yyvsp[(2) - (2)].intval)); }
2166     break;
2167
2168   case 52:
2169
2170 /* Line 1810 of yacc.c  */
2171 #line 555 "./parse-datetime.y"
2172     { apply_relative_time (pc, (yyvsp[(1) - (1)].rel), 1); }
2173     break;
2174
2175   case 53:
2176
2177 /* Line 1810 of yacc.c  */
2178 #line 557 "./parse-datetime.y"
2179     { apply_relative_time (pc, (yyvsp[(1) - (1)].rel), 1); }
2180     break;
2181
2182   case 54:
2183
2184 /* Line 1810 of yacc.c  */
2185 #line 562 "./parse-datetime.y"
2186     { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).year = (yyvsp[(1) - (2)].intval); }
2187     break;
2188
2189   case 55:
2190
2191 /* Line 1810 of yacc.c  */
2192 #line 564 "./parse-datetime.y"
2193     { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).year = (yyvsp[(1) - (2)].textintval).value; }
2194     break;
2195
2196   case 56:
2197
2198 /* Line 1810 of yacc.c  */
2199 #line 566 "./parse-datetime.y"
2200     { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).year = 1; }
2201     break;
2202
2203   case 57:
2204
2205 /* Line 1810 of yacc.c  */
2206 #line 568 "./parse-datetime.y"
2207     { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).month = (yyvsp[(1) - (2)].intval); }
2208     break;
2209
2210   case 58:
2211
2212 /* Line 1810 of yacc.c  */
2213 #line 570 "./parse-datetime.y"
2214     { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).month = (yyvsp[(1) - (2)].textintval).value; }
2215     break;
2216
2217   case 59:
2218
2219 /* Line 1810 of yacc.c  */
2220 #line 572 "./parse-datetime.y"
2221     { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).month = 1; }
2222     break;
2223
2224   case 60:
2225
2226 /* Line 1810 of yacc.c  */
2227 #line 574 "./parse-datetime.y"
2228     { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).day = (yyvsp[(1) - (2)].intval) * (yyvsp[(2) - (2)].intval); }
2229     break;
2230
2231   case 61:
2232
2233 /* Line 1810 of yacc.c  */
2234 #line 576 "./parse-datetime.y"
2235     { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).day = (yyvsp[(1) - (2)].textintval).value * (yyvsp[(2) - (2)].intval); }
2236     break;
2237
2238   case 62:
2239
2240 /* Line 1810 of yacc.c  */
2241 #line 578 "./parse-datetime.y"
2242     { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).day = (yyvsp[(1) - (1)].intval); }
2243     break;
2244
2245   case 63:
2246
2247 /* Line 1810 of yacc.c  */
2248 #line 580 "./parse-datetime.y"
2249     { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).hour = (yyvsp[(1) - (2)].intval); }
2250     break;
2251
2252   case 64:
2253
2254 /* Line 1810 of yacc.c  */
2255 #line 582 "./parse-datetime.y"
2256     { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).hour = (yyvsp[(1) - (2)].textintval).value; }
2257     break;
2258
2259   case 65:
2260
2261 /* Line 1810 of yacc.c  */
2262 #line 584 "./parse-datetime.y"
2263     { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).hour = 1; }
2264     break;
2265
2266   case 66:
2267
2268 /* Line 1810 of yacc.c  */
2269 #line 586 "./parse-datetime.y"
2270     { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).minutes = (yyvsp[(1) - (2)].intval); }
2271     break;
2272
2273   case 67:
2274
2275 /* Line 1810 of yacc.c  */
2276 #line 588 "./parse-datetime.y"
2277     { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).minutes = (yyvsp[(1) - (2)].textintval).value; }
2278     break;
2279
2280   case 68:
2281
2282 /* Line 1810 of yacc.c  */
2283 #line 590 "./parse-datetime.y"
2284     { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).minutes = 1; }
2285     break;
2286
2287   case 69:
2288
2289 /* Line 1810 of yacc.c  */
2290 #line 592 "./parse-datetime.y"
2291     { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).seconds = (yyvsp[(1) - (2)].intval); }
2292     break;
2293
2294   case 70:
2295
2296 /* Line 1810 of yacc.c  */
2297 #line 594 "./parse-datetime.y"
2298     { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).seconds = (yyvsp[(1) - (2)].textintval).value; }
2299     break;
2300
2301   case 71:
2302
2303 /* Line 1810 of yacc.c  */
2304 #line 596 "./parse-datetime.y"
2305     { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).seconds = (yyvsp[(1) - (2)].timespec).tv_sec; (yyval.rel).ns = (yyvsp[(1) - (2)].timespec).tv_nsec; }
2306     break;
2307
2308   case 72:
2309
2310 /* Line 1810 of yacc.c  */
2311 #line 598 "./parse-datetime.y"
2312     { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).seconds = (yyvsp[(1) - (2)].timespec).tv_sec; (yyval.rel).ns = (yyvsp[(1) - (2)].timespec).tv_nsec; }
2313     break;
2314
2315   case 73:
2316
2317 /* Line 1810 of yacc.c  */
2318 #line 600 "./parse-datetime.y"
2319     { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).seconds = 1; }
2320     break;
2321
2322   case 75:
2323
2324 /* Line 1810 of yacc.c  */
2325 #line 606 "./parse-datetime.y"
2326     { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).year = (yyvsp[(1) - (2)].textintval).value; }
2327     break;
2328
2329   case 76:
2330
2331 /* Line 1810 of yacc.c  */
2332 #line 608 "./parse-datetime.y"
2333     { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).month = (yyvsp[(1) - (2)].textintval).value; }
2334     break;
2335
2336   case 77:
2337
2338 /* Line 1810 of yacc.c  */
2339 #line 610 "./parse-datetime.y"
2340     { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).day = (yyvsp[(1) - (2)].textintval).value * (yyvsp[(2) - (2)].intval); }
2341     break;
2342
2343   case 78:
2344
2345 /* Line 1810 of yacc.c  */
2346 #line 612 "./parse-datetime.y"
2347     { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).hour = (yyvsp[(1) - (2)].textintval).value; }
2348     break;
2349
2350   case 79:
2351
2352 /* Line 1810 of yacc.c  */
2353 #line 614 "./parse-datetime.y"
2354     { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).minutes = (yyvsp[(1) - (2)].textintval).value; }
2355     break;
2356
2357   case 80:
2358
2359 /* Line 1810 of yacc.c  */
2360 #line 616 "./parse-datetime.y"
2361     { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).seconds = (yyvsp[(1) - (2)].textintval).value; }
2362     break;
2363
2364   case 81:
2365
2366 /* Line 1810 of yacc.c  */
2367 #line 621 "./parse-datetime.y"
2368     { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).day = (yyvsp[(1) - (1)].intval); }
2369     break;
2370
2371   case 85:
2372
2373 /* Line 1810 of yacc.c  */
2374 #line 629 "./parse-datetime.y"
2375     { (yyval.timespec).tv_sec = (yyvsp[(1) - (1)].textintval).value; (yyval.timespec).tv_nsec = 0; }
2376     break;
2377
2378   case 87:
2379
2380 /* Line 1810 of yacc.c  */
2381 #line 635 "./parse-datetime.y"
2382     { (yyval.timespec).tv_sec = (yyvsp[(1) - (1)].textintval).value; (yyval.timespec).tv_nsec = 0; }
2383     break;
2384
2385   case 88:
2386
2387 /* Line 1810 of yacc.c  */
2388 #line 640 "./parse-datetime.y"
2389     { digits_to_date_time (pc, (yyvsp[(1) - (1)].textintval)); }
2390     break;
2391
2392   case 89:
2393
2394 /* Line 1810 of yacc.c  */
2395 #line 645 "./parse-datetime.y"
2396     {
2397         /* Hybrid all-digit and relative offset, so that we accept e.g.,
2398            "YYYYMMDD +N days" as well as "YYYYMMDD N days".  */
2399         digits_to_date_time (pc, (yyvsp[(1) - (2)].textintval));
2400         apply_relative_time (pc, (yyvsp[(2) - (2)].rel), 1);
2401       }
2402     break;
2403
2404   case 90:
2405
2406 /* Line 1810 of yacc.c  */
2407 #line 655 "./parse-datetime.y"
2408     { (yyval.intval) = -1; }
2409     break;
2410
2411   case 91:
2412
2413 /* Line 1810 of yacc.c  */
2414 #line 657 "./parse-datetime.y"
2415     { (yyval.intval) = (yyvsp[(2) - (2)].textintval).value; }
2416     break;
2417
2418
2419
2420 /* Line 1810 of yacc.c  */
2421 #line 2422 "parse-datetime.c"
2422       default: break;
2423     }
2424   /* User semantic actions sometimes alter yychar, and that requires
2425      that yytoken be updated with the new translation.  We take the
2426      approach of translating immediately before every use of yytoken.
2427      One alternative is translating here after every semantic action,
2428      but that translation would be missed if the semantic action invokes
2429      YYABORT, YYACCEPT, or YYERROR immediately after altering yychar or
2430      if it invokes YYBACKUP.  In the case of YYABORT or YYACCEPT, an
2431      incorrect destructor might then be invoked immediately.  In the
2432      case of YYERROR or YYBACKUP, subsequent parser actions might lead
2433      to an incorrect destructor call or verbose syntax error message
2434      before the lookahead is translated.  */
2435   YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc);
2436
2437   YYPOPSTACK (yylen);
2438   yylen = 0;
2439   YY_STACK_PRINT (yyss, yyssp);
2440
2441   *++yyvsp = yyval;
2442
2443   /* Now `shift' the result of the reduction.  Determine what state
2444      that goes to, based on the state we popped back to and the rule
2445      number reduced by.  */
2446
2447   yyn = yyr1[yyn];
2448
2449   yystate = yypgoto[yyn - YYNTOKENS] + *yyssp;
2450   if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp)
2451     yystate = yytable[yystate];
2452   else
2453     yystate = yydefgoto[yyn - YYNTOKENS];
2454
2455   goto yynewstate;
2456
2457
2458 /*------------------------------------.
2459 | yyerrlab -- here on detecting error |
2460 `------------------------------------*/
2461 yyerrlab:
2462   /* Make sure we have latest lookahead translation.  See comments at
2463      user semantic actions for why this is necessary.  */
2464   yytoken = yychar == YYEMPTY ? YYEMPTY : YYTRANSLATE (yychar);
2465
2466   /* If not already recovering from an error, report this error.  */
2467   if (!yyerrstatus)
2468     {
2469       ++yynerrs;
2470 #if ! YYERROR_VERBOSE
2471       yyerror (pc, YY_("syntax error"));
2472 #else
2473 # define YYSYNTAX_ERROR yysyntax_error (&yymsg_alloc, &yymsg, \
2474                                         yyssp, yytoken)
2475       {
2476         char const *yymsgp = YY_("syntax error");
2477         int yysyntax_error_status;
2478         yysyntax_error_status = YYSYNTAX_ERROR;
2479         if (yysyntax_error_status == 0)
2480           yymsgp = yymsg;
2481         else if (yysyntax_error_status == 1)
2482           {
2483             if (yymsg != yymsgbuf)
2484               YYSTACK_FREE (yymsg);
2485             yymsg = (char *) YYSTACK_ALLOC (yymsg_alloc);
2486             if (!yymsg)
2487               {
2488                 yymsg = yymsgbuf;
2489                 yymsg_alloc = sizeof yymsgbuf;
2490                 yysyntax_error_status = 2;
2491               }
2492             else
2493               {
2494                 yysyntax_error_status = YYSYNTAX_ERROR;
2495                 yymsgp = yymsg;
2496               }
2497           }
2498         yyerror (pc, yymsgp);
2499         if (yysyntax_error_status == 2)
2500           goto yyexhaustedlab;
2501       }
2502 # undef YYSYNTAX_ERROR
2503 #endif
2504     }
2505
2506
2507
2508   if (yyerrstatus == 3)
2509     {
2510       /* If just tried and failed to reuse lookahead token after an
2511          error, discard it.  */
2512
2513       if (yychar <= YYEOF)
2514         {
2515           /* Return failure if at end of input.  */
2516           if (yychar == YYEOF)
2517             YYABORT;
2518         }
2519       else
2520         {
2521           yydestruct ("Error: discarding",
2522                       yytoken, &yylval, pc);
2523           yychar = YYEMPTY;
2524         }
2525     }
2526
2527   /* Else will try to reuse lookahead token after shifting the error
2528      token.  */
2529   goto yyerrlab1;
2530
2531
2532 /*---------------------------------------------------.
2533 | yyerrorlab -- error raised explicitly by YYERROR.  |
2534 `---------------------------------------------------*/
2535 yyerrorlab:
2536
2537   /* Pacify compilers like GCC when the user code never invokes
2538      YYERROR and the label yyerrorlab therefore never appears in user
2539      code.  */
2540   if (/*CONSTCOND*/ 0)
2541      goto yyerrorlab;
2542
2543   /* Do not reclaim the symbols of the rule which action triggered
2544      this YYERROR.  */
2545   YYPOPSTACK (yylen);
2546   yylen = 0;
2547   YY_STACK_PRINT (yyss, yyssp);
2548   yystate = *yyssp;
2549   goto yyerrlab1;
2550
2551
2552 /*-------------------------------------------------------------.
2553 | yyerrlab1 -- common code for both syntax error and YYERROR.  |
2554 `-------------------------------------------------------------*/
2555 yyerrlab1:
2556   yyerrstatus = 3;      /* Each real token shifted decrements this.  */
2557
2558   for (;;)
2559     {
2560       yyn = yypact[yystate];
2561       if (!yypact_value_is_default (yyn))
2562         {
2563           yyn += YYTERROR;
2564           if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
2565             {
2566               yyn = yytable[yyn];
2567               if (0 < yyn)
2568                 break;
2569             }
2570         }
2571
2572       /* Pop the current state because it cannot handle the error token.  */
2573       if (yyssp == yyss)
2574         YYABORT;
2575
2576
2577       yydestruct ("Error: popping",
2578                   yystos[yystate], yyvsp, pc);
2579       YYPOPSTACK (1);
2580       yystate = *yyssp;
2581       YY_STACK_PRINT (yyss, yyssp);
2582     }
2583
2584   *++yyvsp = yylval;
2585
2586
2587   /* Shift the error token.  */
2588   YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp);
2589
2590   yystate = yyn;
2591   goto yynewstate;
2592
2593
2594 /*-------------------------------------.
2595 | yyacceptlab -- YYACCEPT comes here.  |
2596 `-------------------------------------*/
2597 yyacceptlab:
2598   yyresult = 0;
2599   goto yyreturn;
2600
2601 /*-----------------------------------.
2602 | yyabortlab -- YYABORT comes here.  |
2603 `-----------------------------------*/
2604 yyabortlab:
2605   yyresult = 1;
2606   goto yyreturn;
2607
2608 #if !defined yyoverflow || YYERROR_VERBOSE
2609 /*-------------------------------------------------.
2610 | yyexhaustedlab -- memory exhaustion comes here.  |
2611 `-------------------------------------------------*/
2612 yyexhaustedlab:
2613   yyerror (pc, YY_("memory exhausted"));
2614   yyresult = 2;
2615   /* Fall through.  */
2616 #endif
2617
2618 yyreturn:
2619   if (yychar != YYEMPTY)
2620     {
2621       /* Make sure we have latest lookahead translation.  See comments at
2622          user semantic actions for why this is necessary.  */
2623       yytoken = YYTRANSLATE (yychar);
2624       yydestruct ("Cleanup: discarding lookahead",
2625                   yytoken, &yylval, pc);
2626     }
2627   /* Do not reclaim the symbols of the rule which action triggered
2628      this YYABORT or YYACCEPT.  */
2629   YYPOPSTACK (yylen);
2630   YY_STACK_PRINT (yyss, yyssp);
2631   while (yyssp != yyss)
2632     {
2633       yydestruct ("Cleanup: popping",
2634                   yystos[*yyssp], yyvsp, pc);
2635       YYPOPSTACK (1);
2636     }
2637 #ifndef yyoverflow
2638   if (yyss != yyssa)
2639     YYSTACK_FREE (yyss);
2640 #endif
2641 #if YYERROR_VERBOSE
2642   if (yymsg != yymsgbuf)
2643     YYSTACK_FREE (yymsg);
2644 #endif
2645   /* Make sure YYID is used.  */
2646   return YYID (yyresult);
2647 }
2648
2649
2650
2651 /* Line 2071 of yacc.c  */
2652 #line 660 "./parse-datetime.y"
2653
2654
2655 static table const meridian_table[] =
2656 {
2657   { "AM",   tMERIDIAN, MERam },
2658   { "A.M.", tMERIDIAN, MERam },
2659   { "PM",   tMERIDIAN, MERpm },
2660   { "P.M.", tMERIDIAN, MERpm },
2661   { NULL, 0, 0 }
2662 };
2663
2664 static table const dst_table[] =
2665 {
2666   { "DST", tDST, 0 }
2667 };
2668
2669 static table const month_and_day_table[] =
2670 {
2671   { "JANUARY",  tMONTH,  1 },
2672   { "FEBRUARY", tMONTH,  2 },
2673   { "MARCH",    tMONTH,  3 },
2674   { "APRIL",    tMONTH,  4 },
2675   { "MAY",      tMONTH,  5 },
2676   { "JUNE",     tMONTH,  6 },
2677   { "JULY",     tMONTH,  7 },
2678   { "AUGUST",   tMONTH,  8 },
2679   { "SEPTEMBER",tMONTH,  9 },
2680   { "SEPT",     tMONTH,  9 },
2681   { "OCTOBER",  tMONTH, 10 },
2682   { "NOVEMBER", tMONTH, 11 },
2683   { "DECEMBER", tMONTH, 12 },
2684   { "SUNDAY",   tDAY,    0 },
2685   { "MONDAY",   tDAY,    1 },
2686   { "TUESDAY",  tDAY,    2 },
2687   { "TUES",     tDAY,    2 },
2688   { "WEDNESDAY",tDAY,    3 },
2689   { "WEDNES",   tDAY,    3 },
2690   { "THURSDAY", tDAY,    4 },
2691   { "THUR",     tDAY,    4 },
2692   { "THURS",    tDAY,    4 },
2693   { "FRIDAY",   tDAY,    5 },
2694   { "SATURDAY", tDAY,    6 },
2695   { NULL, 0, 0 }
2696 };
2697
2698 static table const time_units_table[] =
2699 {
2700   { "YEAR",     tYEAR_UNIT,      1 },
2701   { "MONTH",    tMONTH_UNIT,     1 },
2702   { "FORTNIGHT",tDAY_UNIT,      14 },
2703   { "WEEK",     tDAY_UNIT,       7 },
2704   { "DAY",      tDAY_UNIT,       1 },
2705   { "HOUR",     tHOUR_UNIT,      1 },
2706   { "MINUTE",   tMINUTE_UNIT,    1 },
2707   { "MIN",      tMINUTE_UNIT,    1 },
2708   { "SECOND",   tSEC_UNIT,       1 },
2709   { "SEC",      tSEC_UNIT,       1 },
2710   { NULL, 0, 0 }
2711 };
2712
2713 /* Assorted relative-time words. */
2714 static table const relative_time_table[] =
2715 {
2716   { "TOMORROW", tDAY_SHIFT,      1 },
2717   { "YESTERDAY",tDAY_SHIFT,     -1 },
2718   { "TODAY",    tDAY_SHIFT,      0 },
2719   { "NOW",      tDAY_SHIFT,      0 },
2720   { "LAST",     tORDINAL,       -1 },
2721   { "THIS",     tORDINAL,        0 },
2722   { "NEXT",     tORDINAL,        1 },
2723   { "FIRST",    tORDINAL,        1 },
2724 /*{ "SECOND",   tORDINAL,        2 }, */
2725   { "THIRD",    tORDINAL,        3 },
2726   { "FOURTH",   tORDINAL,        4 },
2727   { "FIFTH",    tORDINAL,        5 },
2728   { "SIXTH",    tORDINAL,        6 },
2729   { "SEVENTH",  tORDINAL,        7 },
2730   { "EIGHTH",   tORDINAL,        8 },
2731   { "NINTH",    tORDINAL,        9 },
2732   { "TENTH",    tORDINAL,       10 },
2733   { "ELEVENTH", tORDINAL,       11 },
2734   { "TWELFTH",  tORDINAL,       12 },
2735   { "AGO",      tAGO,           -1 },
2736   { "HENCE",    tAGO,            1 },
2737   { NULL, 0, 0 }
2738 };
2739
2740 /* The universal time zone table.  These labels can be used even for
2741    time stamps that would not otherwise be valid, e.g., GMT time
2742    stamps in London during summer.  */
2743 static table const universal_time_zone_table[] =
2744 {
2745   { "GMT",      tZONE,     HOUR ( 0) }, /* Greenwich Mean */
2746   { "UT",       tZONE,     HOUR ( 0) }, /* Universal (Coordinated) */
2747   { "UTC",      tZONE,     HOUR ( 0) },
2748   { NULL, 0, 0 }
2749 };
2750
2751 /* The time zone table.  This table is necessarily incomplete, as time
2752    zone abbreviations are ambiguous; e.g. Australians interpret "EST"
2753    as Eastern time in Australia, not as US Eastern Standard Time.
2754    You cannot rely on parse_datetime to handle arbitrary time zone
2755    abbreviations; use numeric abbreviations like "-0500" instead.  */
2756 static table const time_zone_table[] =
2757 {
2758   { "WET",      tZONE,     HOUR ( 0) }, /* Western European */
2759   { "WEST",     tDAYZONE,  HOUR ( 0) }, /* Western European Summer */
2760   { "BST",      tDAYZONE,  HOUR ( 0) }, /* British Summer */
2761   { "ART",      tZONE,    -HOUR ( 3) }, /* Argentina */
2762   { "BRT",      tZONE,    -HOUR ( 3) }, /* Brazil */
2763   { "BRST",     tDAYZONE, -HOUR ( 3) }, /* Brazil Summer */
2764   { "NST",      tZONE,   -(HOUR ( 3) + 30) },   /* Newfoundland Standard */
2765   { "NDT",      tDAYZONE,-(HOUR ( 3) + 30) },   /* Newfoundland Daylight */
2766   { "AST",      tZONE,    -HOUR ( 4) }, /* Atlantic Standard */
2767   { "ADT",      tDAYZONE, -HOUR ( 4) }, /* Atlantic Daylight */
2768   { "CLT",      tZONE,    -HOUR ( 4) }, /* Chile */
2769   { "CLST",     tDAYZONE, -HOUR ( 4) }, /* Chile Summer */
2770   { "EST",      tZONE,    -HOUR ( 5) }, /* Eastern Standard */
2771   { "EDT",      tDAYZONE, -HOUR ( 5) }, /* Eastern Daylight */
2772   { "CST",      tZONE,    -HOUR ( 6) }, /* Central Standard */
2773   { "CDT",      tDAYZONE, -HOUR ( 6) }, /* Central Daylight */
2774   { "MST",      tZONE,    -HOUR ( 7) }, /* Mountain Standard */
2775   { "MDT",      tDAYZONE, -HOUR ( 7) }, /* Mountain Daylight */
2776   { "PST",      tZONE,    -HOUR ( 8) }, /* Pacific Standard */
2777   { "PDT",      tDAYZONE, -HOUR ( 8) }, /* Pacific Daylight */
2778   { "AKST",     tZONE,    -HOUR ( 9) }, /* Alaska Standard */
2779   { "AKDT",     tDAYZONE, -HOUR ( 9) }, /* Alaska Daylight */
2780   { "HST",      tZONE,    -HOUR (10) }, /* Hawaii Standard */
2781   { "HAST",     tZONE,    -HOUR (10) }, /* Hawaii-Aleutian Standard */
2782   { "HADT",     tDAYZONE, -HOUR (10) }, /* Hawaii-Aleutian Daylight */
2783   { "SST",      tZONE,    -HOUR (12) }, /* Samoa Standard */
2784   { "WAT",      tZONE,     HOUR ( 1) }, /* West Africa */
2785   { "CET",      tZONE,     HOUR ( 1) }, /* Central European */
2786   { "CEST",     tDAYZONE,  HOUR ( 1) }, /* Central European Summer */
2787   { "MET",      tZONE,     HOUR ( 1) }, /* Middle European */
2788   { "MEZ",      tZONE,     HOUR ( 1) }, /* Middle European */
2789   { "MEST",     tDAYZONE,  HOUR ( 1) }, /* Middle European Summer */
2790   { "MESZ",     tDAYZONE,  HOUR ( 1) }, /* Middle European Summer */
2791   { "EET",      tZONE,     HOUR ( 2) }, /* Eastern European */
2792   { "EEST",     tDAYZONE,  HOUR ( 2) }, /* Eastern European Summer */
2793   { "CAT",      tZONE,     HOUR ( 2) }, /* Central Africa */
2794   { "SAST",     tZONE,     HOUR ( 2) }, /* South Africa Standard */
2795   { "EAT",      tZONE,     HOUR ( 3) }, /* East Africa */
2796   { "MSK",      tZONE,     HOUR ( 3) }, /* Moscow */
2797   { "MSD",      tDAYZONE,  HOUR ( 3) }, /* Moscow Daylight */
2798   { "IST",      tZONE,    (HOUR ( 5) + 30) },   /* India Standard */
2799   { "SGT",      tZONE,     HOUR ( 8) }, /* Singapore */
2800   { "KST",      tZONE,     HOUR ( 9) }, /* Korea Standard */
2801   { "JST",      tZONE,     HOUR ( 9) }, /* Japan Standard */
2802   { "GST",      tZONE,     HOUR (10) }, /* Guam Standard */
2803   { "NZST",     tZONE,     HOUR (12) }, /* New Zealand Standard */
2804   { "NZDT",     tDAYZONE,  HOUR (12) }, /* New Zealand Daylight */
2805   { NULL, 0, 0 }
2806 };
2807
2808 /* Military time zone table.
2809
2810    Note 'T' is a special case, as it is used as the separator in ISO
2811    8601 date and time of day representation. */
2812 static table const military_table[] =
2813 {
2814   { "A", tZONE, -HOUR ( 1) },
2815   { "B", tZONE, -HOUR ( 2) },
2816   { "C", tZONE, -HOUR ( 3) },
2817   { "D", tZONE, -HOUR ( 4) },
2818   { "E", tZONE, -HOUR ( 5) },
2819   { "F", tZONE, -HOUR ( 6) },
2820   { "G", tZONE, -HOUR ( 7) },
2821   { "H", tZONE, -HOUR ( 8) },
2822   { "I", tZONE, -HOUR ( 9) },
2823   { "K", tZONE, -HOUR (10) },
2824   { "L", tZONE, -HOUR (11) },
2825   { "M", tZONE, -HOUR (12) },
2826   { "N", tZONE,  HOUR ( 1) },
2827   { "O", tZONE,  HOUR ( 2) },
2828   { "P", tZONE,  HOUR ( 3) },
2829   { "Q", tZONE,  HOUR ( 4) },
2830   { "R", tZONE,  HOUR ( 5) },
2831   { "S", tZONE,  HOUR ( 6) },
2832   { "T", 'T',    0 },
2833   { "U", tZONE,  HOUR ( 8) },
2834   { "V", tZONE,  HOUR ( 9) },
2835   { "W", tZONE,  HOUR (10) },
2836   { "X", tZONE,  HOUR (11) },
2837   { "Y", tZONE,  HOUR (12) },
2838   { "Z", tZONE,  HOUR ( 0) },
2839   { NULL, 0, 0 }
2840 };
2841
2842 \f
2843
2844 /* Convert a time zone expressed as HH:MM into an integer count of
2845    minutes.  If MM is negative, then S is of the form HHMM and needs
2846    to be picked apart; otherwise, S is of the form HH.  As specified in
2847    http://www.opengroup.org/susv3xbd/xbd_chap08.html#tag_08_03, allow
2848    only valid TZ range, and consider first two digits as hours, if no
2849    minutes specified.  */
2850
2851 static long int
2852 time_zone_hhmm (parser_control *pc, textint s, long int mm)
2853 {
2854   long int n_minutes;
2855
2856   /* If the length of S is 1 or 2 and no minutes are specified,
2857      interpret it as a number of hours.  */
2858   if (s.digits <= 2 && mm < 0)
2859     s.value *= 100;
2860
2861   if (mm < 0)
2862     n_minutes = (s.value / 100) * 60 + s.value % 100;
2863   else
2864     n_minutes = s.value * 60 + (s.negative ? -mm : mm);
2865
2866   /* If the absolute number of minutes is larger than 24 hours,
2867      arrange to reject it by incrementing pc->zones_seen.  Thus,
2868      we allow only values in the range UTC-24:00 to UTC+24:00.  */
2869   if (24 * 60 < abs (n_minutes))
2870     pc->zones_seen++;
2871
2872   return n_minutes;
2873 }
2874
2875 static int
2876 to_hour (long int hours, int meridian)
2877 {
2878   switch (meridian)
2879     {
2880     default: /* Pacify GCC.  */
2881     case MER24:
2882       return 0 <= hours && hours < 24 ? hours : -1;
2883     case MERam:
2884       return 0 < hours && hours < 12 ? hours : hours == 12 ? 0 : -1;
2885     case MERpm:
2886       return 0 < hours && hours < 12 ? hours + 12 : hours == 12 ? 12 : -1;
2887     }
2888 }
2889
2890 static long int
2891 to_year (textint textyear)
2892 {
2893   long int year = textyear.value;
2894
2895   if (year < 0)
2896     year = -year;
2897
2898   /* XPG4 suggests that years 00-68 map to 2000-2068, and
2899      years 69-99 map to 1969-1999.  */
2900   else if (textyear.digits == 2)
2901     year += year < 69 ? 2000 : 1900;
2902
2903   return year;
2904 }
2905
2906 static table const * _GL_ATTRIBUTE_PURE
2907 lookup_zone (parser_control const *pc, char const *name)
2908 {
2909   table const *tp;
2910
2911   for (tp = universal_time_zone_table; tp->name; tp++)
2912     if (strcmp (name, tp->name) == 0)
2913       return tp;
2914
2915   /* Try local zone abbreviations before those in time_zone_table, as
2916      the local ones are more likely to be right.  */
2917   for (tp = pc->local_time_zone_table; tp->name; tp++)
2918     if (strcmp (name, tp->name) == 0)
2919       return tp;
2920
2921   for (tp = time_zone_table; tp->name; tp++)
2922     if (strcmp (name, tp->name) == 0)
2923       return tp;
2924
2925   return NULL;
2926 }
2927
2928 #if ! HAVE_TM_GMTOFF
2929 /* Yield the difference between *A and *B,
2930    measured in seconds, ignoring leap seconds.
2931    The body of this function is taken directly from the GNU C Library;
2932    see src/strftime.c.  */
2933 static long int
2934 tm_diff (struct tm const *a, struct tm const *b)
2935 {
2936   /* Compute intervening leap days correctly even if year is negative.
2937      Take care to avoid int overflow in leap day calculations.  */
2938   int a4 = SHR (a->tm_year, 2) + SHR (TM_YEAR_BASE, 2) - ! (a->tm_year & 3);
2939   int b4 = SHR (b->tm_year, 2) + SHR (TM_YEAR_BASE, 2) - ! (b->tm_year & 3);
2940   int a100 = a4 / 25 - (a4 % 25 < 0);
2941   int b100 = b4 / 25 - (b4 % 25 < 0);
2942   int a400 = SHR (a100, 2);
2943   int b400 = SHR (b100, 2);
2944   int intervening_leap_days = (a4 - b4) - (a100 - b100) + (a400 - b400);
2945   long int ayear = a->tm_year;
2946   long int years = ayear - b->tm_year;
2947   long int days = (365 * years + intervening_leap_days
2948                    + (a->tm_yday - b->tm_yday));
2949   return (60 * (60 * (24 * days + (a->tm_hour - b->tm_hour))
2950                 + (a->tm_min - b->tm_min))
2951           + (a->tm_sec - b->tm_sec));
2952 }
2953 #endif /* ! HAVE_TM_GMTOFF */
2954
2955 static table const *
2956 lookup_word (parser_control const *pc, char *word)
2957 {
2958   char *p;
2959   char *q;
2960   size_t wordlen;
2961   table const *tp;
2962   bool period_found;
2963   bool abbrev;
2964
2965   /* Make it uppercase.  */
2966   for (p = word; *p; p++)
2967     {
2968       unsigned char ch = *p;
2969       *p = c_toupper (ch);
2970     }
2971
2972   for (tp = meridian_table; tp->name; tp++)
2973     if (strcmp (word, tp->name) == 0)
2974       return tp;
2975
2976   /* See if we have an abbreviation for a month. */
2977   wordlen = strlen (word);
2978   abbrev = wordlen == 3 || (wordlen == 4 && word[3] == '.');
2979
2980   for (tp = month_and_day_table; tp->name; tp++)
2981     if ((abbrev ? strncmp (word, tp->name, 3) : strcmp (word, tp->name)) == 0)
2982       return tp;
2983
2984   if ((tp = lookup_zone (pc, word)))
2985     return tp;
2986
2987   if (strcmp (word, dst_table[0].name) == 0)
2988     return dst_table;
2989
2990   for (tp = time_units_table; tp->name; tp++)
2991     if (strcmp (word, tp->name) == 0)
2992       return tp;
2993
2994   /* Strip off any plural and try the units table again. */
2995   if (word[wordlen - 1] == 'S')
2996     {
2997       word[wordlen - 1] = '\0';
2998       for (tp = time_units_table; tp->name; tp++)
2999         if (strcmp (word, tp->name) == 0)
3000           return tp;
3001       word[wordlen - 1] = 'S';  /* For "this" in relative_time_table.  */
3002     }
3003
3004   for (tp = relative_time_table; tp->name; tp++)
3005     if (strcmp (word, tp->name) == 0)
3006       return tp;
3007
3008   /* Military time zones. */
3009   if (wordlen == 1)
3010     for (tp = military_table; tp->name; tp++)
3011       if (word[0] == tp->name[0])
3012         return tp;
3013
3014   /* Drop out any periods and try the time zone table again. */
3015   for (period_found = false, p = q = word; (*p = *q); q++)
3016     if (*q == '.')
3017       period_found = true;
3018     else
3019       p++;
3020   if (period_found && (tp = lookup_zone (pc, word)))
3021     return tp;
3022
3023   return NULL;
3024 }
3025
3026 static int
3027 yylex (union YYSTYPE *lvalp, parser_control *pc)
3028 {
3029   unsigned char c;
3030   size_t count;
3031
3032   for (;;)
3033     {
3034       while (c = *pc->input, c_isspace (c))
3035         pc->input++;
3036
3037       if (ISDIGIT (c) || c == '-' || c == '+')
3038         {
3039           char const *p;
3040           int sign;
3041           unsigned long int value;
3042           if (c == '-' || c == '+')
3043             {
3044               sign = c == '-' ? -1 : 1;
3045               while (c = *++pc->input, c_isspace (c))
3046                 continue;
3047               if (! ISDIGIT (c))
3048                 /* skip the '-' sign */
3049                 continue;
3050             }
3051           else
3052             sign = 0;
3053           p = pc->input;
3054           for (value = 0; ; value *= 10)
3055             {
3056               unsigned long int value1 = value + (c - '0');
3057               if (value1 < value)
3058                 return '?';
3059               value = value1;
3060               c = *++p;
3061               if (! ISDIGIT (c))
3062                 break;
3063               if (ULONG_MAX / 10 < value)
3064                 return '?';
3065             }
3066           if ((c == '.' || c == ',') && ISDIGIT (p[1]))
3067             {
3068               time_t s;
3069               int ns;
3070               int digits;
3071               unsigned long int value1;
3072
3073               /* Check for overflow when converting value to time_t.  */
3074               if (sign < 0)
3075                 {
3076                   s = - value;
3077                   if (0 < s)
3078                     return '?';
3079                   value1 = -s;
3080                 }
3081               else
3082                 {
3083                   s = value;
3084                   if (s < 0)
3085                     return '?';
3086                   value1 = s;
3087                 }
3088               if (value != value1)
3089                 return '?';
3090
3091               /* Accumulate fraction, to ns precision.  */
3092               p++;
3093               ns = *p++ - '0';
3094               for (digits = 2; digits <= LOG10_BILLION; digits++)
3095                 {
3096                   ns *= 10;
3097                   if (ISDIGIT (*p))
3098                     ns += *p++ - '0';
3099                 }
3100
3101               /* Skip excess digits, truncating toward -Infinity.  */
3102               if (sign < 0)
3103                 for (; ISDIGIT (*p); p++)
3104                   if (*p != '0')
3105                     {
3106                       ns++;
3107                       break;
3108                     }
3109               while (ISDIGIT (*p))
3110                 p++;
3111
3112               /* Adjust to the timespec convention, which is that
3113                  tv_nsec is always a positive offset even if tv_sec is
3114                  negative.  */
3115               if (sign < 0 && ns)
3116                 {
3117                   s--;
3118                   if (! (s < 0))
3119                     return '?';
3120                   ns = BILLION - ns;
3121                 }
3122
3123               lvalp->timespec.tv_sec = s;
3124               lvalp->timespec.tv_nsec = ns;
3125               pc->input = p;
3126               return sign ? tSDECIMAL_NUMBER : tUDECIMAL_NUMBER;
3127             }
3128           else
3129             {
3130               lvalp->textintval.negative = sign < 0;
3131               if (sign < 0)
3132                 {
3133                   lvalp->textintval.value = - value;
3134                   if (0 < lvalp->textintval.value)
3135                     return '?';
3136                 }
3137               else
3138                 {
3139                   lvalp->textintval.value = value;
3140                   if (lvalp->textintval.value < 0)
3141                     return '?';
3142                 }
3143               lvalp->textintval.digits = p - pc->input;
3144               pc->input = p;
3145               return sign ? tSNUMBER : tUNUMBER;
3146             }
3147         }
3148
3149       if (c_isalpha (c))
3150         {
3151           char buff[20];
3152           char *p = buff;
3153           table const *tp;
3154
3155           do
3156             {
3157               if (p < buff + sizeof buff - 1)
3158                 *p++ = c;
3159               c = *++pc->input;
3160             }
3161           while (c_isalpha (c) || c == '.');
3162
3163           *p = '\0';
3164           tp = lookup_word (pc, buff);
3165           if (! tp)
3166             return '?';
3167           lvalp->intval = tp->value;
3168           return tp->type;
3169         }
3170
3171       if (c != '(')
3172         return to_uchar (*pc->input++);
3173
3174       count = 0;
3175       do
3176         {
3177           c = *pc->input++;
3178           if (c == '\0')
3179             return c;
3180           if (c == '(')
3181             count++;
3182           else if (c == ')')
3183             count--;
3184         }
3185       while (count != 0);
3186     }
3187 }
3188
3189 /* Do nothing if the parser reports an error.  */
3190 static int
3191 yyerror (parser_control const *pc _GL_UNUSED,
3192          char const *s _GL_UNUSED)
3193 {
3194   return 0;
3195 }
3196
3197 /* If *TM0 is the old and *TM1 is the new value of a struct tm after
3198    passing it to mktime, return true if it's OK that mktime returned T.
3199    It's not OK if *TM0 has out-of-range members.  */
3200
3201 static bool
3202 mktime_ok (struct tm const *tm0, struct tm const *tm1, time_t t)
3203 {
3204   if (t == (time_t) -1)
3205     {
3206       /* Guard against falsely reporting an error when parsing a time
3207          stamp that happens to equal (time_t) -1, on a host that
3208          supports such a time stamp.  */
3209       tm1 = localtime (&t);
3210       if (!tm1)
3211         return false;
3212     }
3213
3214   return ! ((tm0->tm_sec ^ tm1->tm_sec)
3215             | (tm0->tm_min ^ tm1->tm_min)
3216             | (tm0->tm_hour ^ tm1->tm_hour)
3217             | (tm0->tm_mday ^ tm1->tm_mday)
3218             | (tm0->tm_mon ^ tm1->tm_mon)
3219             | (tm0->tm_year ^ tm1->tm_year));
3220 }
3221
3222 /* A reasonable upper bound for the size of ordinary TZ strings.
3223    Use heap allocation if TZ's length exceeds this.  */
3224 enum { TZBUFSIZE = 100 };
3225
3226 /* Return a copy of TZ, stored in TZBUF if it fits, and heap-allocated
3227    otherwise.  */
3228 static char *
3229 get_tz (char tzbuf[TZBUFSIZE])
3230 {
3231   char *tz = getenv ("TZ");
3232   if (tz)
3233     {
3234       size_t tzsize = strlen (tz) + 1;
3235       tz = (tzsize <= TZBUFSIZE
3236             ? memcpy (tzbuf, tz, tzsize)
3237             : xmemdup (tz, tzsize));
3238     }
3239   return tz;
3240 }
3241
3242 /* Parse a date/time string, storing the resulting time value into *RESULT.
3243    The string itself is pointed to by P.  Return true if successful.
3244    P can be an incomplete or relative time specification; if so, use
3245    *NOW as the basis for the returned time.  */
3246 bool
3247 parse_datetime (struct timespec *result, char const *p,
3248                 struct timespec const *now)
3249 {
3250   time_t Start;
3251   long int Start_ns;
3252   struct tm const *tmp;
3253   struct tm tm;
3254   struct tm tm0;
3255   parser_control pc;
3256   struct timespec gettime_buffer;
3257   unsigned char c;
3258   bool tz_was_altered = false;
3259   char *tz0 = NULL;
3260   char tz0buf[TZBUFSIZE];
3261   bool ok = true;
3262
3263   if (! now)
3264     {
3265       gettime (&gettime_buffer);
3266       now = &gettime_buffer;
3267     }
3268
3269   Start = now->tv_sec;
3270   Start_ns = now->tv_nsec;
3271
3272   tmp = localtime (&now->tv_sec);
3273   if (! tmp)
3274     return false;
3275
3276   while (c = *p, c_isspace (c))
3277     p++;
3278
3279   if (strncmp (p, "TZ=\"", 4) == 0)
3280     {
3281       char const *tzbase = p + 4;
3282       size_t tzsize = 1;
3283       char const *s;
3284
3285       for (s = tzbase; *s; s++, tzsize++)
3286         if (*s == '\\')
3287           {
3288             s++;
3289             if (! (*s == '\\' || *s == '"'))
3290               break;
3291           }
3292         else if (*s == '"')
3293           {
3294             char *z;
3295             char *tz1;
3296             char tz1buf[TZBUFSIZE];
3297             bool large_tz = TZBUFSIZE < tzsize;
3298             bool setenv_ok;
3299             tz0 = get_tz (tz0buf);
3300             z = tz1 = large_tz ? xmalloc (tzsize) : tz1buf;
3301             for (s = tzbase; *s != '"'; s++)
3302               *z++ = *(s += *s == '\\');
3303             *z = '\0';
3304             setenv_ok = setenv ("TZ", tz1, 1) == 0;
3305             if (large_tz)
3306               free (tz1);
3307             if (!setenv_ok)
3308               goto fail;
3309             tz_was_altered = true;
3310
3311             p = s + 1;
3312             while (c = *p, c_isspace (c))
3313               p++;
3314
3315             break;
3316           }
3317     }
3318
3319   /* As documented, be careful to treat the empty string just like
3320      a date string of "0".  Without this, an empty string would be
3321      declared invalid when parsed during a DST transition.  */
3322   if (*p == '\0')
3323     p = "0";
3324
3325   pc.input = p;
3326   pc.year.value = tmp->tm_year;
3327   pc.year.value += TM_YEAR_BASE;
3328   pc.year.digits = 0;
3329   pc.month = tmp->tm_mon + 1;
3330   pc.day = tmp->tm_mday;
3331   pc.hour = tmp->tm_hour;
3332   pc.minutes = tmp->tm_min;
3333   pc.seconds.tv_sec = tmp->tm_sec;
3334   pc.seconds.tv_nsec = Start_ns;
3335   tm.tm_isdst = tmp->tm_isdst;
3336
3337   pc.meridian = MER24;
3338   pc.rel = RELATIVE_TIME_0;
3339   pc.timespec_seen = false;
3340   pc.rels_seen = false;
3341   pc.dates_seen = 0;
3342   pc.days_seen = 0;
3343   pc.times_seen = 0;
3344   pc.local_zones_seen = 0;
3345   pc.dsts_seen = 0;
3346   pc.zones_seen = 0;
3347
3348 #if HAVE_STRUCT_TM_TM_ZONE
3349   pc.local_time_zone_table[0].name = tmp->tm_zone;
3350   pc.local_time_zone_table[0].type = tLOCAL_ZONE;
3351   pc.local_time_zone_table[0].value = tmp->tm_isdst;
3352   pc.local_time_zone_table[1].name = NULL;
3353
3354   /* Probe the names used in the next three calendar quarters, looking
3355      for a tm_isdst different from the one we already have.  */
3356   {
3357     int quarter;
3358     for (quarter = 1; quarter <= 3; quarter++)
3359       {
3360         time_t probe = Start + quarter * (90 * 24 * 60 * 60);
3361         struct tm const *probe_tm = localtime (&probe);
3362         if (probe_tm && probe_tm->tm_zone
3363             && probe_tm->tm_isdst != pc.local_time_zone_table[0].value)
3364           {
3365               {
3366                 pc.local_time_zone_table[1].name = probe_tm->tm_zone;
3367                 pc.local_time_zone_table[1].type = tLOCAL_ZONE;
3368                 pc.local_time_zone_table[1].value = probe_tm->tm_isdst;
3369                 pc.local_time_zone_table[2].name = NULL;
3370               }
3371             break;
3372           }
3373       }
3374   }
3375 #else
3376 #if HAVE_TZNAME
3377   {
3378 # if !HAVE_DECL_TZNAME
3379     extern char *tzname[];
3380 # endif
3381     int i;
3382     for (i = 0; i < 2; i++)
3383       {
3384         pc.local_time_zone_table[i].name = tzname[i];
3385         pc.local_time_zone_table[i].type = tLOCAL_ZONE;
3386         pc.local_time_zone_table[i].value = i;
3387       }
3388     pc.local_time_zone_table[i].name = NULL;
3389   }
3390 #else
3391   pc.local_time_zone_table[0].name = NULL;
3392 #endif
3393 #endif
3394
3395   if (pc.local_time_zone_table[0].name && pc.local_time_zone_table[1].name
3396       && ! strcmp (pc.local_time_zone_table[0].name,
3397                    pc.local_time_zone_table[1].name))
3398     {
3399       /* This locale uses the same abbreviation for standard and
3400          daylight times.  So if we see that abbreviation, we don't
3401          know whether it's daylight time.  */
3402       pc.local_time_zone_table[0].value = -1;
3403       pc.local_time_zone_table[1].name = NULL;
3404     }
3405
3406   if (yyparse (&pc) != 0)
3407     goto fail;
3408
3409   if (pc.timespec_seen)
3410     *result = pc.seconds;
3411   else
3412     {
3413       if (1 < (pc.times_seen | pc.dates_seen | pc.days_seen | pc.dsts_seen
3414                | (pc.local_zones_seen + pc.zones_seen)))
3415         goto fail;
3416
3417       tm.tm_year = to_year (pc.year) - TM_YEAR_BASE;
3418       tm.tm_mon = pc.month - 1;
3419       tm.tm_mday = pc.day;
3420       if (pc.times_seen || (pc.rels_seen && ! pc.dates_seen && ! pc.days_seen))
3421         {
3422           tm.tm_hour = to_hour (pc.hour, pc.meridian);
3423           if (tm.tm_hour < 0)
3424             goto fail;
3425           tm.tm_min = pc.minutes;
3426           tm.tm_sec = pc.seconds.tv_sec;
3427         }
3428       else
3429         {
3430           tm.tm_hour = tm.tm_min = tm.tm_sec = 0;
3431           pc.seconds.tv_nsec = 0;
3432         }
3433
3434       /* Let mktime deduce tm_isdst if we have an absolute time stamp.  */
3435       if (pc.dates_seen | pc.days_seen | pc.times_seen)
3436         tm.tm_isdst = -1;
3437
3438       /* But if the input explicitly specifies local time with or without
3439          DST, give mktime that information.  */
3440       if (pc.local_zones_seen)
3441         tm.tm_isdst = pc.local_isdst;
3442
3443       tm0 = tm;
3444
3445       Start = mktime (&tm);
3446
3447       if (! mktime_ok (&tm0, &tm, Start))
3448         {
3449           if (! pc.zones_seen)
3450             goto fail;
3451           else
3452             {
3453               /* Guard against falsely reporting errors near the time_t
3454                  boundaries when parsing times in other time zones.  For
3455                  example, suppose the input string "1969-12-31 23:00:00 -0100",
3456                  the current time zone is 8 hours ahead of UTC, and the min
3457                  time_t value is 1970-01-01 00:00:00 UTC.  Then the min
3458                  localtime value is 1970-01-01 08:00:00, and mktime will
3459                  therefore fail on 1969-12-31 23:00:00.  To work around the
3460                  problem, set the time zone to 1 hour behind UTC temporarily
3461                  by setting TZ="XXX1:00" and try mktime again.  */
3462
3463               long int time_zone = pc.time_zone;
3464               long int abs_time_zone = time_zone < 0 ? - time_zone : time_zone;
3465               long int abs_time_zone_hour = abs_time_zone / 60;
3466               int abs_time_zone_min = abs_time_zone % 60;
3467               char tz1buf[sizeof "XXX+0:00"
3468                           + sizeof pc.time_zone * CHAR_BIT / 3];
3469               if (!tz_was_altered)
3470                 tz0 = get_tz (tz0buf);
3471               sprintf (tz1buf, "XXX%s%ld:%02d", &"-"[time_zone < 0],
3472                        abs_time_zone_hour, abs_time_zone_min);
3473               if (setenv ("TZ", tz1buf, 1) != 0)
3474                 goto fail;
3475               tz_was_altered = true;
3476               tm = tm0;
3477               Start = mktime (&tm);
3478               if (! mktime_ok (&tm0, &tm, Start))
3479                 goto fail;
3480             }
3481         }
3482
3483       if (pc.days_seen && ! pc.dates_seen)
3484         {
3485           tm.tm_mday += ((pc.day_number - tm.tm_wday + 7) % 7
3486                          + 7 * (pc.day_ordinal
3487                                 - (0 < pc.day_ordinal
3488                                    && tm.tm_wday != pc.day_number)));
3489           tm.tm_isdst = -1;
3490           Start = mktime (&tm);
3491           if (Start == (time_t) -1)
3492             goto fail;
3493         }
3494
3495       /* Add relative date.  */
3496       if (pc.rel.year | pc.rel.month | pc.rel.day)
3497         {
3498           int year = tm.tm_year + pc.rel.year;
3499           int month = tm.tm_mon + pc.rel.month;
3500           int day = tm.tm_mday + pc.rel.day;
3501           if (((year < tm.tm_year) ^ (pc.rel.year < 0))
3502               | ((month < tm.tm_mon) ^ (pc.rel.month < 0))
3503               | ((day < tm.tm_mday) ^ (pc.rel.day < 0)))
3504             goto fail;
3505           tm.tm_year = year;
3506           tm.tm_mon = month;
3507           tm.tm_mday = day;
3508           tm.tm_hour = tm0.tm_hour;
3509           tm.tm_min = tm0.tm_min;
3510           tm.tm_sec = tm0.tm_sec;
3511           tm.tm_isdst = tm0.tm_isdst;
3512           Start = mktime (&tm);
3513           if (Start == (time_t) -1)
3514             goto fail;
3515         }
3516
3517       /* The only "output" of this if-block is an updated Start value,
3518          so this block must follow others that clobber Start.  */
3519       if (pc.zones_seen)
3520         {
3521           long int delta = pc.time_zone * 60;
3522           time_t t1;
3523 #ifdef HAVE_TM_GMTOFF
3524           delta -= tm.tm_gmtoff;
3525 #else
3526           time_t t = Start;
3527           struct tm const *gmt = gmtime (&t);
3528           if (! gmt)
3529             goto fail;
3530           delta -= tm_diff (&tm, gmt);
3531 #endif
3532           t1 = Start - delta;
3533           if ((Start < t1) != (delta < 0))
3534             goto fail;  /* time_t overflow */
3535           Start = t1;
3536         }
3537
3538       /* Add relative hours, minutes, and seconds.  On hosts that support
3539          leap seconds, ignore the possibility of leap seconds; e.g.,
3540          "+ 10 minutes" adds 600 seconds, even if one of them is a
3541          leap second.  Typically this is not what the user wants, but it's
3542          too hard to do it the other way, because the time zone indicator
3543          must be applied before relative times, and if mktime is applied
3544          again the time zone will be lost.  */
3545       {
3546         long int sum_ns = pc.seconds.tv_nsec + pc.rel.ns;
3547         long int normalized_ns = (sum_ns % BILLION + BILLION) % BILLION;
3548         time_t t0 = Start;
3549         long int d1 = 60 * 60 * pc.rel.hour;
3550         time_t t1 = t0 + d1;
3551         long int d2 = 60 * pc.rel.minutes;
3552         time_t t2 = t1 + d2;
3553         long_time_t d3 = pc.rel.seconds;
3554         long_time_t t3 = t2 + d3;
3555         long int d4 = (sum_ns - normalized_ns) / BILLION;
3556         long_time_t t4 = t3 + d4;
3557         time_t t5 = t4;
3558
3559         if ((d1 / (60 * 60) ^ pc.rel.hour)
3560             | (d2 / 60 ^ pc.rel.minutes)
3561             | ((t1 < t0) ^ (d1 < 0))
3562             | ((t2 < t1) ^ (d2 < 0))
3563             | ((t3 < t2) ^ (d3 < 0))
3564             | ((t4 < t3) ^ (d4 < 0))
3565             | (t5 != t4))
3566           goto fail;
3567
3568         result->tv_sec = t5;
3569         result->tv_nsec = normalized_ns;
3570       }
3571     }
3572
3573   goto done;
3574
3575  fail:
3576   ok = false;
3577  done:
3578   if (tz_was_altered)
3579     ok &= (tz0 ? setenv ("TZ", tz0, 1) : unsetenv ("TZ")) == 0;
3580   if (tz0 != tz0buf)
3581     free (tz0);
3582   return ok;
3583 }
3584
3585 #if TEST
3586
3587 int
3588 main (int ac, char **av)
3589 {
3590   char buff[BUFSIZ];
3591
3592   printf ("Enter date, or blank line to exit.\n\t> ");
3593   fflush (stdout);
3594
3595   buff[BUFSIZ - 1] = '\0';
3596   while (fgets (buff, BUFSIZ - 1, stdin) && buff[0])
3597     {
3598       struct timespec d;
3599       struct tm const *tm;
3600       if (! parse_datetime (&d, buff, NULL))
3601         printf ("Bad format - couldn't convert.\n");
3602       else if (! (tm = localtime (&d.tv_sec)))
3603         {
3604           long int sec = d.tv_sec;
3605           printf ("localtime (%ld) failed\n", sec);
3606         }
3607       else
3608         {
3609           int ns = d.tv_nsec;
3610           printf ("%04ld-%02d-%02d %02d:%02d:%02d.%09d\n",
3611                   tm->tm_year + 1900L, tm->tm_mon + 1, tm->tm_mday,
3612                   tm->tm_hour, tm->tm_min, tm->tm_sec, ns);
3613         }
3614       printf ("\t> ");
3615       fflush (stdout);
3616     }
3617   return 0;
3618 }
3619 #endif /* TEST */
3620