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