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