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