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