1 /* A Bison parser, made by GNU Bison 2.5.1. */
3 /* Bison implementation for Yacc-like parsers in C
5 Copyright (C) 1984, 1989-1990, 2000-2012 Free Software Foundation, Inc.
7 This program is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20 /* As a special exception, you may create a larger work that contains
21 part or all of the Bison parser skeleton and distribute that work
22 under terms of your choice, so long as that work isn't itself a
23 parser generator using the skeleton or a modified version thereof
24 as a parser skeleton. Alternatively, if you modify or redistribute
25 the parser skeleton itself, you may (at your option) remove this
26 special exception, which will cause the skeleton and the resulting
27 Bison output files to be licensed under the GNU General Public
28 License without this special exception.
30 This special exception was added by the Free Software Foundation in
31 version 2.2 of Bison. */
33 /* C LALR(1) parser skeleton written by Richard Stallman, by
34 simplifying the original so-called "semantic" parser. */
36 /* All symbols defined below should begin with yy or YY, to avoid
37 infringing on user name space. This should be done even for local
38 variables, as they might otherwise be expanded by user macros.
39 There are some unavoidable exceptions within include files to
40 define necessary library symbols; they are noted "INFRINGES ON
41 USER NAME SPACE" below. */
43 /* Identify Bison output. */
47 #define YYBISON_VERSION "2.5.1"
50 #define YYSKELETON_NAME "yacc.c"
61 /* Using locations. */
62 #define YYLSP_NEEDED 0
66 /* Copy the first part of user declarations. */
68 /* Line 268 of yacc.c */
69 #line 1 "./parse-datetime.y"
71 /* Parse a string into an internal time stamp.
73 Copyright (C) 1999-2000, 2002-2015 Free Software Foundation, Inc.
75 This program is free software: you can redistribute it and/or modify
76 it under the terms of the GNU General Public License as published by
77 the Free Software Foundation; either version 3 of the License, or
78 (at your option) any later version.
80 This program is distributed in the hope that it will be useful,
81 but WITHOUT ANY WARRANTY; without even the implied warranty of
82 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
83 GNU General Public License for more details.
85 You should have received a copy of the GNU General Public License
86 along with this program. If not, see <http://www.gnu.org/licenses/>. */
88 /* Originally written by Steven M. Bellovin <smb@research.att.com> while
89 at the University of North Carolina at Chapel Hill. Later tweaked by
90 a couple of people on Usenet. Completely overhauled by Rich $alz
91 <rsalz@bbn.com> and Jim Berets <jberets@bbn.com> in August, 1990.
93 Modified by Paul Eggert <eggert@twinsun.com> in August 1999 to do
94 the right thing about local DST. Also modified by Paul Eggert
95 <eggert@cs.ucla.edu> in February 2004 to support
96 nanosecond-resolution time stamps, and in October 2004 to support
97 TZ strings in dates. */
99 /* FIXME: Check for arithmetic overflow in all cases, not just
104 #include "parse-datetime.h"
106 #include "intprops.h"
107 #include "timespec.h"
110 /* There's no need to extend the stack, so there's no need to involve
112 #define YYSTACK_USE_ALLOCA 0
114 /* Tell Bison how much stack space is needed. 20 should be plenty for
115 this grammar, which is not right recursive. Beware setting it too
116 high, since that might cause problems on machines whose
117 implementations have lame stack-overflow checking. */
118 #define YYMAXDEPTH 20
119 #define YYINITDEPTH YYMAXDEPTH
121 /* Since the code of parse-datetime.y is not included in the Emacs executable
122 itself, there is no need to #define static in this file. Even if
123 the code were included in the Emacs executable, it probably
124 wouldn't do any harm to #undef it here; this will only cause
125 problems if we try to write to a static variable, which I don't
126 think this code needs to do. */
139 /* Bison's skeleton tests _STDLIB_H, while some stdlib.h headers
140 use _STDLIB_H_ as witness. Map the latter to the one bison uses. */
141 /* FIXME: this is temporary. Remove when we have a mechanism to ensure
142 that the version we're using is fixed, too. */
148 /* ISDIGIT differs from isdigit, as follows:
149 - Its arg may be any int or unsigned int; it need not be an unsigned char
151 - It's typically faster.
152 POSIX says that only '0' through '9' are digits. Prefer ISDIGIT to
153 isdigit unless it's important to use the locale's definition
154 of "digit" even when the host does not conform to POSIX. */
155 #define ISDIGIT(c) ((unsigned int) (c) - '0' <= 9)
157 /* Shift A right by B bits portably, by dividing A by 2**B and
158 truncating towards minus infinity. A and B should be free of side
159 effects, and B should be in the range 0 <= B <= INT_BITS - 2, where
160 INT_BITS is the number of useful bits in an int. GNU code can
161 assume that INT_BITS is at least 32.
163 ISO C99 says that A >> B is implementation-defined if A < 0. Some
164 implementations (e.g., UNICOS 9.0 on a Cray Y-MP EL) don't shift
165 right in the usual way when A < 0, so SHR falls back on division if
166 ordinary A >> B doesn't seem to be the usual signed shift. */
170 : (a) / (1 << (b)) - ((a) % (1 << (b)) < 0))
172 #define EPOCH_YEAR 1970
173 #define TM_YEAR_BASE 1900
175 #define HOUR(x) ((x) * 60)
177 /* long_time_t is a signed integer type that contains all time_t values. */
178 verify (TYPE_IS_INTEGER (time_t));
179 #if TIME_T_FITS_IN_LONG_INT
180 typedef long int long_time_t;
182 typedef time_t long_time_t;
185 /* Convert a possibly-signed character to an unsigned character. This is
186 a bit safer than casting to unsigned char, since it catches some type
187 errors that the cast doesn't. */
188 static unsigned char to_uchar (char ch) { return ch; }
190 /* Lots of this code assumes time_t and time_t-like values fit into
192 verify (TYPE_MINIMUM (long_time_t) <= TYPE_MINIMUM (time_t)
193 && TYPE_MAXIMUM (time_t) <= TYPE_MAXIMUM (long_time_t));
195 /* FIXME: It also assumes that signed integer overflow silently wraps around,
196 but this is not true any more with recent versions of GCC 4. */
198 /* An integer value, and the number of digits in its textual
207 /* An entry in the lexical lookup table. */
215 /* Meridian: am, pm, or 24-hour style. */
216 enum { MERam, MERpm, MER24 };
218 enum { BILLION = 1000000000, LOG10_BILLION = 9 };
220 /* Relative times. */
223 /* Relative year, month, day, hour, minutes, seconds, and nanoseconds. */
233 #if HAVE_COMPOUND_LITERALS
234 # define RELATIVE_TIME_0 ((relative_time) { 0, 0, 0, 0, 0, 0, 0 })
236 static relative_time const RELATIVE_TIME_0;
239 /* Information passed to and from the parser. */
242 /* The input string remaining to be parsed. */
245 /* N, if this is the Nth Tuesday. */
246 long int day_ordinal;
248 /* Day of week; Sunday is 0. */
251 /* tm_isdst flag for the local zone. */
254 /* Time zone, in minutes east of UTC. */
257 /* Style used for time. */
260 /* Gregorian year, month, day, hour, minutes, seconds, and nanoseconds. */
266 struct timespec seconds; /* includes nanoseconds */
268 /* Relative year, month, day, hour, minutes, seconds, and nanoseconds. */
271 /* Presence or counts of nonterminals of various flavors parsed so far. */
276 size_t local_zones_seen;
281 /* Table of local time zone abbreviations, terminated by a null entry. */
282 table local_time_zone_table[3];
286 static int yylex (union YYSTYPE *, parser_control *);
287 static int yyerror (parser_control const *, char const *);
288 static long int time_zone_hhmm (parser_control *, textint, long int);
290 /* Extract into *PC any date and time info from a string of digits
291 of the form e.g., YYYYMMDD, YYMMDD, HHMM, HH (and sometimes YYY,
294 digits_to_date_time (parser_control *pc, textint text_int)
296 if (pc->dates_seen && ! pc->year.digits
297 && ! pc->rels_seen && (pc->times_seen || 2 < text_int.digits))
301 if (4 < text_int.digits)
304 pc->day = text_int.value % 100;
305 pc->month = (text_int.value / 100) % 100;
306 pc->year.value = text_int.value / 10000;
307 pc->year.digits = text_int.digits - 4;
312 if (text_int.digits <= 2)
314 pc->hour = text_int.value;
319 pc->hour = text_int.value / 100;
320 pc->minutes = text_int.value % 100;
322 pc->seconds.tv_sec = 0;
323 pc->seconds.tv_nsec = 0;
324 pc->meridian = MER24;
329 /* Increment PC->rel by FACTOR * REL (FACTOR is 1 or -1). */
331 apply_relative_time (parser_control *pc, relative_time rel, int factor)
333 pc->rel.ns += factor * rel.ns;
334 pc->rel.seconds += factor * rel.seconds;
335 pc->rel.minutes += factor * rel.minutes;
336 pc->rel.hour += factor * rel.hour;
337 pc->rel.day += factor * rel.day;
338 pc->rel.month += factor * rel.month;
339 pc->rel.year += factor * rel.year;
340 pc->rels_seen = true;
343 /* Set PC-> hour, minutes, seconds and nanoseconds members from arguments. */
345 set_hhmmss (parser_control *pc, long int hour, long int minutes,
346 time_t sec, long int nsec)
349 pc->minutes = minutes;
350 pc->seconds.tv_sec = sec;
351 pc->seconds.tv_nsec = nsec;
356 /* Line 268 of yacc.c */
357 #line 358 "parse-datetime.c"
360 # if defined __cplusplus && 201103L <= __cplusplus
361 # define YY_NULL nullptr
367 /* Enabling traces. */
372 /* Enabling verbose error messages. */
373 #ifdef YYERROR_VERBOSE
374 # undef YYERROR_VERBOSE
375 # define YYERROR_VERBOSE 1
377 # define YYERROR_VERBOSE 0
380 /* Enabling the token table. */
381 #ifndef YYTOKEN_TABLE
382 # define YYTOKEN_TABLE 0
389 /* Put the tokens into the symbol table, so that GDB and other debuggers
410 tSDECIMAL_NUMBER = 276,
411 tUDECIMAL_NUMBER = 277
417 #define tYEAR_UNIT 260
418 #define tMONTH_UNIT 261
419 #define tHOUR_UNIT 262
420 #define tMINUTE_UNIT 263
421 #define tSEC_UNIT 264
422 #define tDAY_UNIT 265
423 #define tDAY_SHIFT 266
426 #define tLOCAL_ZONE 269
427 #define tMERIDIAN 270
433 #define tSDECIMAL_NUMBER 276
434 #define tUDECIMAL_NUMBER 277
439 #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
440 typedef union YYSTYPE
443 /* Line 295 of yacc.c */
444 #line 297 "./parse-datetime.y"
448 struct timespec timespec;
453 /* Line 295 of yacc.c */
454 #line 455 "parse-datetime.c"
456 # define YYSTYPE_IS_TRIVIAL 1
457 # define yystype YYSTYPE /* obsolescent; will be withdrawn */
458 # define YYSTYPE_IS_DECLARED 1
462 /* Copy the second part of user declarations. */
465 /* Line 345 of yacc.c */
466 #line 467 "parse-datetime.c"
473 typedef YYTYPE_UINT8 yytype_uint8;
475 typedef unsigned char yytype_uint8;
479 typedef YYTYPE_INT8 yytype_int8;
480 #elif (defined __STDC__ || defined __C99__FUNC__ \
481 || defined __cplusplus || defined _MSC_VER)
482 typedef signed char yytype_int8;
484 typedef short int yytype_int8;
488 typedef YYTYPE_UINT16 yytype_uint16;
490 typedef unsigned short int yytype_uint16;
494 typedef YYTYPE_INT16 yytype_int16;
496 typedef short int yytype_int16;
500 # ifdef __SIZE_TYPE__
501 # define YYSIZE_T __SIZE_TYPE__
502 # elif defined size_t
503 # define YYSIZE_T size_t
504 # elif ! defined YYSIZE_T && (defined __STDC__ || defined __C99__FUNC__ \
505 || defined __cplusplus || defined _MSC_VER)
506 # include <stddef.h> /* INFRINGES ON USER NAME SPACE */
507 # define YYSIZE_T size_t
509 # define YYSIZE_T unsigned int
513 #define YYSIZE_MAXIMUM ((YYSIZE_T) -1)
516 # if defined YYENABLE_NLS && YYENABLE_NLS
518 # include <libintl.h> /* INFRINGES ON USER NAME SPACE */
519 # define YY_(msgid) dgettext ("bison-runtime", msgid)
523 # define YY_(msgid) msgid
527 /* Suppress unused-variable warnings by "using" E. */
528 #if ! defined lint || defined __GNUC__
529 # define YYUSE(e) ((void) (e))
531 # define YYUSE(e) /* empty */
534 /* Identity function, used to suppress warnings about constant conditions. */
538 #if (defined __STDC__ || defined __C99__FUNC__ \
539 || defined __cplusplus || defined _MSC_VER)
552 #if ! defined yyoverflow || YYERROR_VERBOSE
554 /* The parser invokes alloca or malloc; define the necessary symbols. */
556 # ifdef YYSTACK_USE_ALLOCA
557 # if YYSTACK_USE_ALLOCA
559 # define YYSTACK_ALLOC __builtin_alloca
560 # elif defined __BUILTIN_VA_ARG_INCR
561 # include <alloca.h> /* INFRINGES ON USER NAME SPACE */
563 # define YYSTACK_ALLOC __alloca
564 # elif defined _MSC_VER
565 # include <malloc.h> /* INFRINGES ON USER NAME SPACE */
566 # define alloca _alloca
568 # define YYSTACK_ALLOC alloca
569 # if ! defined _ALLOCA_H && ! defined EXIT_SUCCESS && (defined __STDC__ || defined __C99__FUNC__ \
570 || defined __cplusplus || defined _MSC_VER)
571 # include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
572 /* Use EXIT_SUCCESS as a witness for stdlib.h. */
573 # ifndef EXIT_SUCCESS
574 # define EXIT_SUCCESS 0
581 # ifdef YYSTACK_ALLOC
582 /* Pacify GCC's `empty if-body' warning. */
583 # define YYSTACK_FREE(Ptr) do { /* empty */; } while (YYID (0))
584 # ifndef YYSTACK_ALLOC_MAXIMUM
585 /* The OS might guarantee only one guard page at the bottom of the stack,
586 and a page size can be as small as 4096 bytes. So we cannot safely
587 invoke alloca (N) if N exceeds 4096. Use a slightly smaller number
588 to allow for a few compiler-allocated temporary stack slots. */
589 # define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */
592 # define YYSTACK_ALLOC YYMALLOC
593 # define YYSTACK_FREE YYFREE
594 # ifndef YYSTACK_ALLOC_MAXIMUM
595 # define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM
597 # if (defined __cplusplus && ! defined EXIT_SUCCESS \
598 && ! ((defined YYMALLOC || defined malloc) \
599 && (defined YYFREE || defined free)))
600 # include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
601 # ifndef EXIT_SUCCESS
602 # define EXIT_SUCCESS 0
606 # define YYMALLOC malloc
607 # if ! defined malloc && ! defined EXIT_SUCCESS && (defined __STDC__ || defined __C99__FUNC__ \
608 || defined __cplusplus || defined _MSC_VER)
609 void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */
614 # if ! defined free && ! defined EXIT_SUCCESS && (defined __STDC__ || defined __C99__FUNC__ \
615 || defined __cplusplus || defined _MSC_VER)
616 void free (void *); /* INFRINGES ON USER NAME SPACE */
620 #endif /* ! defined yyoverflow || YYERROR_VERBOSE */
623 #if (! defined yyoverflow \
624 && (! defined __cplusplus \
625 || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
627 /* A type that is properly aligned for any stack member. */
630 yytype_int16 yyss_alloc;
634 /* The size of the maximum gap between one aligned stack and the next. */
635 # define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1)
637 /* The size of an array large to enough to hold all stacks, each with
639 # define YYSTACK_BYTES(N) \
640 ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE)) \
641 + YYSTACK_GAP_MAXIMUM)
643 # define YYCOPY_NEEDED 1
645 /* Relocate STACK from its old location to the new one. The
646 local variables YYSIZE and YYSTACKSIZE give the old and new number of
647 elements in the stack, and YYPTR gives the new location of the
648 stack. Advance YYPTR to a properly aligned location for the next
650 # define YYSTACK_RELOCATE(Stack_alloc, Stack) \
653 YYSIZE_T yynewbytes; \
654 YYCOPY (&yyptr->Stack_alloc, Stack, yysize); \
655 Stack = &yyptr->Stack_alloc; \
656 yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \
657 yyptr += yynewbytes / sizeof (*yyptr); \
663 #if defined YYCOPY_NEEDED && YYCOPY_NEEDED
664 /* Copy COUNT objects from SRC to DST. The source and destination do
667 # if defined __GNUC__ && 1 < __GNUC__
668 # define YYCOPY(Dst, Src, Count) \
669 __builtin_memcpy (Dst, Src, (Count) * sizeof (*(Src)))
671 # define YYCOPY(Dst, Src, Count) \
675 for (yyi = 0; yyi < (Count); yyi++) \
676 (Dst)[yyi] = (Src)[yyi]; \
681 #endif /* !YYCOPY_NEEDED */
683 /* YYFINAL -- State number of the termination state. */
685 /* YYLAST -- Last index in YYTABLE. */
688 /* YYNTOKENS -- Number of terminals. */
690 /* YYNNTS -- Number of nonterminals. */
692 /* YYNRULES -- Number of rules. */
694 /* YYNRULES -- Number of states. */
695 #define YYNSTATES 114
697 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
699 #define YYMAXUTOK 277
701 #define YYTRANSLATE(YYX) \
702 ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
704 /* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */
705 static const yytype_uint8 yytranslate[] =
707 0, 2, 2, 2, 2, 2, 2, 2, 2, 2,
708 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
709 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
710 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
711 2, 2, 2, 2, 26, 2, 2, 27, 2, 2,
712 2, 2, 2, 2, 2, 2, 2, 2, 25, 2,
713 2, 2, 2, 2, 23, 2, 2, 2, 2, 2,
714 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
715 2, 2, 2, 2, 24, 2, 2, 2, 2, 2,
716 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
717 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
718 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
719 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
720 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
721 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
722 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
723 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
724 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
725 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
726 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
727 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
728 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
729 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
730 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
731 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
732 2, 2, 2, 2, 2, 2, 1, 2, 3, 4,
733 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
734 15, 16, 17, 18, 19, 20, 21, 22
738 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
740 static const yytype_uint8 yyprhs[] =
742 0, 0, 3, 5, 7, 10, 11, 14, 16, 18,
743 20, 22, 24, 26, 28, 30, 32, 34, 38, 41,
744 46, 53, 55, 58, 63, 70, 71, 73, 76, 78,
745 81, 83, 85, 88, 91, 95, 97, 100, 102, 105,
746 108, 111, 115, 121, 125, 129, 132, 137, 140, 144,
747 146, 150, 153, 155, 157, 160, 163, 165, 168, 171,
748 173, 176, 179, 181, 184, 187, 189, 192, 195, 197,
749 200, 203, 206, 209, 211, 213, 216, 219, 222, 225,
750 228, 231, 233, 235, 237, 239, 241, 243, 245, 247,
754 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
755 static const yytype_int8 yyrhs[] =
757 29, 0, -1, 30, -1, 31, -1, 23, 48, -1,
758 -1, 31, 32, -1, 33, -1, 35, -1, 39, -1,
759 40, -1, 42, -1, 41, -1, 44, -1, 51, -1,
760 52, -1, 34, -1, 43, 24, 36, -1, 20, 15,
761 -1, 20, 25, 20, 15, -1, 20, 25, 20, 25,
762 50, 15, -1, 36, -1, 20, 38, -1, 20, 25,
763 20, 37, -1, 20, 25, 20, 25, 50, 37, -1,
764 -1, 38, -1, 19, 53, -1, 14, -1, 14, 4,
765 -1, 18, -1, 24, -1, 18, 46, -1, 24, 46,
766 -1, 18, 19, 53, -1, 13, -1, 18, 4, -1,
767 12, -1, 12, 26, -1, 17, 12, -1, 20, 12,
768 -1, 20, 27, 20, -1, 20, 27, 20, 27, 20,
769 -1, 20, 16, 19, -1, 16, 19, 19, -1, 16,
770 20, -1, 16, 20, 26, 20, -1, 20, 16, -1,
771 20, 16, 20, -1, 43, -1, 20, 19, 19, -1,
772 45, 3, -1, 45, -1, 47, -1, 17, 5, -1,
773 20, 5, -1, 5, -1, 17, 6, -1, 20, 6,
774 -1, 6, -1, 17, 10, -1, 20, 10, -1, 10,
775 -1, 17, 7, -1, 20, 7, -1, 7, -1, 17,
776 8, -1, 20, 8, -1, 8, -1, 17, 9, -1,
777 20, 9, -1, 21, 9, -1, 22, 9, -1, 9,
778 -1, 46, -1, 19, 5, -1, 19, 6, -1, 19,
779 10, -1, 19, 7, -1, 19, 8, -1, 19, 9,
780 -1, 11, -1, 49, -1, 50, -1, 21, -1, 19,
781 -1, 22, -1, 20, -1, 20, -1, 20, 46, -1,
785 /* YYRLINE[YYN] -- source line where rule number YYN was defined. */
786 static const yytype_uint16 yyrline[] =
788 0, 324, 324, 325, 329, 336, 338, 342, 344, 346,
789 348, 350, 352, 354, 355, 356, 360, 364, 368, 373,
790 378, 383, 387, 392, 397, 404, 406, 410, 418, 423,
791 433, 435, 437, 440, 443, 445, 447, 452, 457, 462,
792 467, 475, 480, 500, 508, 516, 521, 527, 532, 538,
793 542, 552, 554, 556, 561, 563, 565, 567, 569, 571,
794 573, 575, 577, 579, 581, 583, 585, 587, 589, 591,
795 593, 595, 597, 599, 601, 605, 607, 609, 611, 613,
796 615, 620, 624, 624, 627, 628, 633, 634, 639, 644,
801 #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
802 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
803 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
804 static const char *const yytname[] =
806 "$end", "error", "$undefined", "tAGO", "tDST", "tYEAR_UNIT",
807 "tMONTH_UNIT", "tHOUR_UNIT", "tMINUTE_UNIT", "tSEC_UNIT", "tDAY_UNIT",
808 "tDAY_SHIFT", "tDAY", "tDAYZONE", "tLOCAL_ZONE", "tMERIDIAN", "tMONTH",
809 "tORDINAL", "tZONE", "tSNUMBER", "tUNUMBER", "tSDECIMAL_NUMBER",
810 "tUDECIMAL_NUMBER", "'@'", "'T'", "':'", "','", "'/'", "$accept", "spec",
811 "timespec", "items", "item", "datetime", "iso_8601_datetime", "time",
812 "iso_8601_time", "o_zone_offset", "zone_offset", "local_zone", "zone",
813 "day", "date", "iso_8601_date", "rel", "relunit", "relunit_snumber",
814 "dayshift", "seconds", "signed_seconds", "unsigned_seconds", "number",
815 "hybrid", "o_colon_minutes", YY_NULL
820 /* YYTOKNUM[YYLEX-NUM] -- Internal token number corresponding to
822 static const yytype_uint16 yytoknum[] =
824 0, 256, 257, 258, 259, 260, 261, 262, 263, 264,
825 265, 266, 267, 268, 269, 270, 271, 272, 273, 274,
826 275, 276, 277, 64, 84, 58, 44, 47
830 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
831 static const yytype_uint8 yyr1[] =
833 0, 28, 29, 29, 30, 31, 31, 32, 32, 32,
834 32, 32, 32, 32, 32, 32, 33, 34, 35, 35,
835 35, 35, 36, 36, 36, 37, 37, 38, 39, 39,
836 40, 40, 40, 40, 40, 40, 40, 41, 41, 41,
837 41, 42, 42, 42, 42, 42, 42, 42, 42, 42,
838 43, 44, 44, 44, 45, 45, 45, 45, 45, 45,
839 45, 45, 45, 45, 45, 45, 45, 45, 45, 45,
840 45, 45, 45, 45, 45, 46, 46, 46, 46, 46,
841 46, 47, 48, 48, 49, 49, 50, 50, 51, 52,
845 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
846 static const yytype_uint8 yyr2[] =
848 0, 2, 1, 1, 2, 0, 2, 1, 1, 1,
849 1, 1, 1, 1, 1, 1, 1, 3, 2, 4,
850 6, 1, 2, 4, 6, 0, 1, 2, 1, 2,
851 1, 1, 2, 2, 3, 1, 2, 1, 2, 2,
852 2, 3, 5, 3, 3, 2, 4, 2, 3, 1,
853 3, 2, 1, 1, 2, 2, 1, 2, 2, 1,
854 2, 2, 1, 2, 2, 1, 2, 2, 1, 2,
855 2, 2, 2, 1, 1, 2, 2, 2, 2, 2,
856 2, 1, 1, 1, 1, 1, 1, 1, 1, 2,
860 /* YYDEFACT[STATE-NAME] -- Default reduction number in state STATE-NUM.
861 Performed when YYTABLE doesn't specify something else to do. Zero
862 means the default is an error. */
863 static const yytype_uint8 yydefact[] =
865 5, 0, 0, 2, 3, 85, 87, 84, 86, 4,
866 82, 83, 1, 56, 59, 65, 68, 73, 62, 81,
867 37, 35, 28, 0, 0, 30, 0, 88, 0, 0,
868 31, 6, 7, 16, 8, 21, 9, 10, 12, 11,
869 49, 13, 52, 74, 53, 14, 15, 38, 29, 0,
870 45, 54, 57, 63, 66, 69, 60, 39, 36, 90,
871 32, 75, 76, 78, 79, 80, 77, 55, 58, 64,
872 67, 70, 61, 40, 18, 47, 90, 0, 0, 22,
873 89, 71, 72, 33, 0, 51, 44, 0, 0, 34,
874 43, 48, 50, 27, 25, 41, 0, 17, 46, 91,
875 19, 90, 0, 23, 26, 0, 0, 25, 42, 25,
879 /* YYDEFGOTO[NTERM-NUM]. */
880 static const yytype_int8 yydefgoto[] =
882 -1, 2, 3, 4, 31, 32, 33, 34, 35, 103,
883 104, 36, 37, 38, 39, 40, 41, 42, 43, 44,
884 9, 10, 11, 45, 46, 93
887 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
889 #define YYPACT_NINF -93
890 static const yytype_int8 yypact[] =
892 38, 27, 77, -93, 46, -93, -93, -93, -93, -93,
893 -93, -93, -93, -93, -93, -93, -93, -93, -93, -93,
894 62, -93, 82, -3, 66, 3, 74, -4, 83, 84,
895 75, -93, -93, -93, -93, -93, -93, -93, -93, -93,
896 71, -93, 93, -93, -93, -93, -93, -93, -93, 78,
897 72, -93, -93, -93, -93, -93, -93, -93, -93, 25,
898 -93, -93, -93, -93, -93, -93, -93, -93, -93, -93,
899 -93, -93, -93, -93, -93, 21, 19, 79, 80, -93,
900 -93, -93, -93, -93, 81, -93, -93, 85, 86, -93,
901 -93, -93, -93, -93, -6, 76, 17, -93, -93, -93,
902 -93, 87, 69, -93, -93, 88, 89, -1, -93, 18,
906 /* YYPGOTO[NTERM-NUM]. */
907 static const yytype_int8 yypgoto[] =
909 -93, -93, -93, -93, -93, -93, -93, -93, 20, -68,
910 -27, -93, -93, -93, -93, -93, -93, -93, 60, -93,
911 -93, -93, -92, -93, -93, 43
914 /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
915 positive, shift that token. If negative, reduce the rule which
916 number is the opposite. If YYTABLE_NINF, syntax error. */
917 #define YYTABLE_NINF -1
918 static const yytype_uint8 yytable[] =
920 79, 67, 68, 69, 70, 71, 72, 58, 73, 100,
921 107, 74, 75, 101, 110, 76, 49, 50, 101, 102,
922 113, 77, 59, 78, 61, 62, 63, 64, 65, 66,
923 61, 62, 63, 64, 65, 66, 101, 101, 92, 111,
924 90, 91, 106, 112, 88, 111, 5, 6, 7, 8,
925 88, 13, 14, 15, 16, 17, 18, 19, 20, 21,
926 22, 1, 23, 24, 25, 26, 27, 28, 29, 79,
927 30, 51, 52, 53, 54, 55, 56, 12, 57, 61,
928 62, 63, 64, 65, 66, 60, 48, 80, 47, 6,
929 83, 8, 81, 82, 26, 84, 85, 86, 87, 94,
930 95, 96, 89, 105, 97, 98, 99, 0, 108, 109,
934 #define yypact_value_is_default(yystate) \
937 #define yytable_value_is_error(yytable_value) \
940 static const yytype_int8 yycheck[] =
942 27, 5, 6, 7, 8, 9, 10, 4, 12, 15,
943 102, 15, 16, 19, 15, 19, 19, 20, 19, 25,
944 112, 25, 19, 27, 5, 6, 7, 8, 9, 10,
945 5, 6, 7, 8, 9, 10, 19, 19, 19, 107,
946 19, 20, 25, 25, 25, 113, 19, 20, 21, 22,
947 25, 5, 6, 7, 8, 9, 10, 11, 12, 13,
948 14, 23, 16, 17, 18, 19, 20, 21, 22, 96,
949 24, 5, 6, 7, 8, 9, 10, 0, 12, 5,
950 6, 7, 8, 9, 10, 25, 4, 27, 26, 20,
951 30, 22, 9, 9, 19, 24, 3, 19, 26, 20,
952 20, 20, 59, 27, 84, 20, 20, -1, 20, 20,
956 /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
957 symbol of state STATE-NUM. */
958 static const yytype_uint8 yystos[] =
960 0, 23, 29, 30, 31, 19, 20, 21, 22, 48,
961 49, 50, 0, 5, 6, 7, 8, 9, 10, 11,
962 12, 13, 14, 16, 17, 18, 19, 20, 21, 22,
963 24, 32, 33, 34, 35, 36, 39, 40, 41, 42,
964 43, 44, 45, 46, 47, 51, 52, 26, 4, 19,
965 20, 5, 6, 7, 8, 9, 10, 12, 4, 19,
966 46, 5, 6, 7, 8, 9, 10, 5, 6, 7,
967 8, 9, 10, 12, 15, 16, 19, 25, 27, 38,
968 46, 9, 9, 46, 24, 3, 19, 26, 25, 53,
969 19, 20, 19, 53, 20, 20, 20, 36, 20, 20,
970 15, 19, 25, 37, 38, 27, 25, 50, 20, 20,
974 #define yyerrok (yyerrstatus = 0)
975 #define yyclearin (yychar = YYEMPTY)
979 #define YYACCEPT goto yyacceptlab
980 #define YYABORT goto yyabortlab
981 #define YYERROR goto yyerrorlab
984 /* Like YYERROR except do call yyerror. This remains here temporarily
985 to ease the transition to the new meaning of YYERROR, for GCC.
986 Once GCC version 2 has supplanted version 1, this can go. However,
987 YYFAIL appears to be in use. Nevertheless, it is formally deprecated
988 in Bison 2.4.2's NEWS entry, where a plan to phase it out is
991 #define YYFAIL goto yyerrlab
993 /* This is here to suppress warnings from the GCC cpp's
994 -Wunused-macros. Normally we don't worry about that warning, but
995 some users do, and we want to make it easy for users to remove
996 YYFAIL uses, which will produce warnings from Bison 2.5. */
999 #define YYRECOVERING() (!!yyerrstatus)
1001 #define YYBACKUP(Token, Value) \
1003 if (yychar == YYEMPTY) \
1007 YYPOPSTACK (yylen); \
1013 yyerror (pc, YY_("syntax error: cannot back up")); \
1020 #define YYERRCODE 256
1023 /* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
1024 If N is 0, then set CURRENT to the empty location which ends
1025 the previous symbol: RHS[0] (always defined). */
1027 #define YYRHSLOC(Rhs, K) ((Rhs)[K])
1028 #ifndef YYLLOC_DEFAULT
1029 # define YYLLOC_DEFAULT(Current, Rhs, N) \
1033 (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \
1034 (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \
1035 (Current).last_line = YYRHSLOC (Rhs, N).last_line; \
1036 (Current).last_column = YYRHSLOC (Rhs, N).last_column; \
1040 (Current).first_line = (Current).last_line = \
1041 YYRHSLOC (Rhs, 0).last_line; \
1042 (Current).first_column = (Current).last_column = \
1043 YYRHSLOC (Rhs, 0).last_column; \
1049 /* This macro is provided for backward compatibility. */
1051 #ifndef YY_LOCATION_PRINT
1052 # define YY_LOCATION_PRINT(File, Loc) ((void) 0)
1056 /* YYLEX -- calling `yylex' with the right arguments. */
1059 # define YYLEX yylex (&yylval, YYLEX_PARAM)
1061 # define YYLEX yylex (&yylval, pc)
1064 /* Enable debugging if requested. */
1068 # include <stdio.h> /* INFRINGES ON USER NAME SPACE */
1069 # define YYFPRINTF fprintf
1072 # define YYDPRINTF(Args) \
1078 # define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
1082 YYFPRINTF (stderr, "%s ", Title); \
1083 yy_symbol_print (stderr, \
1085 YYFPRINTF (stderr, "\n"); \
1090 /*--------------------------------.
1091 | Print this symbol on YYOUTPUT. |
1092 `--------------------------------*/
1095 #if (defined __STDC__ || defined __C99__FUNC__ \
1096 || defined __cplusplus || defined _MSC_VER)
1098 yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, parser_control *pc)
1101 yy_symbol_value_print (yyoutput, yytype, yyvaluep, pc)
1104 YYSTYPE const * const yyvaluep;
1108 FILE *yyo = yyoutput;
1114 if (yytype < YYNTOKENS)
1115 YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep);
1127 /*--------------------------------.
1128 | Print this symbol on YYOUTPUT. |
1129 `--------------------------------*/
1131 #if (defined __STDC__ || defined __C99__FUNC__ \
1132 || defined __cplusplus || defined _MSC_VER)
1134 yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, parser_control *pc)
1137 yy_symbol_print (yyoutput, yytype, yyvaluep, pc)
1140 YYSTYPE const * const yyvaluep;
1144 if (yytype < YYNTOKENS)
1145 YYFPRINTF (yyoutput, "token %s (", yytname[yytype]);
1147 YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]);
1149 yy_symbol_value_print (yyoutput, yytype, yyvaluep, pc);
1150 YYFPRINTF (yyoutput, ")");
1153 /*------------------------------------------------------------------.
1154 | yy_stack_print -- Print the state stack from its BOTTOM up to its |
1156 `------------------------------------------------------------------*/
1158 #if (defined __STDC__ || defined __C99__FUNC__ \
1159 || defined __cplusplus || defined _MSC_VER)
1161 yy_stack_print (yytype_int16 *yybottom, yytype_int16 *yytop)
1164 yy_stack_print (yybottom, yytop)
1165 yytype_int16 *yybottom;
1166 yytype_int16 *yytop;
1169 YYFPRINTF (stderr, "Stack now");
1170 for (; yybottom <= yytop; yybottom++)
1172 int yybot = *yybottom;
1173 YYFPRINTF (stderr, " %d", yybot);
1175 YYFPRINTF (stderr, "\n");
1178 # define YY_STACK_PRINT(Bottom, Top) \
1181 yy_stack_print ((Bottom), (Top)); \
1185 /*------------------------------------------------.
1186 | Report that the YYRULE is going to be reduced. |
1187 `------------------------------------------------*/
1189 #if (defined __STDC__ || defined __C99__FUNC__ \
1190 || defined __cplusplus || defined _MSC_VER)
1192 yy_reduce_print (YYSTYPE *yyvsp, int yyrule, parser_control *pc)
1195 yy_reduce_print (yyvsp, yyrule, pc)
1201 int yynrhs = yyr2[yyrule];
1203 unsigned long int yylno = yyrline[yyrule];
1204 YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n",
1206 /* The symbols being reduced. */
1207 for (yyi = 0; yyi < yynrhs; yyi++)
1209 YYFPRINTF (stderr, " $%d = ", yyi + 1);
1210 yy_symbol_print (stderr, yyrhs[yyprhs[yyrule] + yyi],
1211 &(yyvsp[(yyi + 1) - (yynrhs)])
1213 YYFPRINTF (stderr, "\n");
1217 # define YY_REDUCE_PRINT(Rule) \
1220 yy_reduce_print (yyvsp, Rule, pc); \
1223 /* Nonzero means print parse trace. It is left uninitialized so that
1224 multiple parsers can coexist. */
1226 #else /* !YYDEBUG */
1227 # define YYDPRINTF(Args)
1228 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
1229 # define YY_STACK_PRINT(Bottom, Top)
1230 # define YY_REDUCE_PRINT(Rule)
1231 #endif /* !YYDEBUG */
1234 /* YYINITDEPTH -- initial size of the parser's stacks. */
1236 # define YYINITDEPTH 200
1239 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
1240 if the built-in stack extension method is used).
1242 Do not make this value too large; the results are undefined if
1243 YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH)
1244 evaluated with infinite-precision integer arithmetic. */
1247 # define YYMAXDEPTH 10000
1254 # if defined __GLIBC__ && defined _STRING_H
1255 # define yystrlen strlen
1257 /* Return the length of YYSTR. */
1258 #if (defined __STDC__ || defined __C99__FUNC__ \
1259 || defined __cplusplus || defined _MSC_VER)
1261 yystrlen (const char *yystr)
1269 for (yylen = 0; yystr[yylen]; yylen++)
1277 # if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
1278 # define yystpcpy stpcpy
1280 /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
1282 #if (defined __STDC__ || defined __C99__FUNC__ \
1283 || defined __cplusplus || defined _MSC_VER)
1285 yystpcpy (char *yydest, const char *yysrc)
1288 yystpcpy (yydest, yysrc)
1294 const char *yys = yysrc;
1296 while ((*yyd++ = *yys++) != '\0')
1305 /* Copy to YYRES the contents of YYSTR after stripping away unnecessary
1306 quotes and backslashes, so that it's suitable for yyerror. The
1307 heuristic is that double-quoting is unnecessary unless the string
1308 contains an apostrophe, a comma, or backslash (other than
1309 backslash-backslash). YYSTR is taken from yytname. If YYRES is
1310 null, do not copy; instead, return the length of what the result
1313 yytnamerr (char *yyres, const char *yystr)
1318 char const *yyp = yystr;
1325 goto do_not_strip_quotes;
1329 goto do_not_strip_quotes;
1342 do_not_strip_quotes: ;
1346 return yystrlen (yystr);
1348 return yystpcpy (yyres, yystr) - yyres;
1352 /* Copy into *YYMSG, which is of size *YYMSG_ALLOC, an error message
1353 about the unexpected token YYTOKEN for the state stack whose top is
1356 Return 0 if *YYMSG was successfully written. Return 1 if *YYMSG is
1357 not large enough to hold the message. In that case, also set
1358 *YYMSG_ALLOC to the required number of bytes. Return 2 if the
1359 required number of bytes is too large to store. */
1361 yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg,
1362 yytype_int16 *yyssp, int yytoken)
1364 YYSIZE_T yysize0 = yytnamerr (YY_NULL, yytname[yytoken]);
1365 YYSIZE_T yysize = yysize0;
1367 enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
1368 /* Internationalized format string. */
1369 const char *yyformat = YY_NULL;
1370 /* Arguments of yyformat. */
1371 char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
1372 /* Number of reported tokens (one for the "unexpected", one per
1376 /* There are many possibilities here to consider:
1377 - Assume YYFAIL is not used. It's too flawed to consider. See
1378 <http://lists.gnu.org/archive/html/bison-patches/2009-12/msg00024.html>
1379 for details. YYERROR is fine as it does not invoke this
1381 - If this state is a consistent state with a default action, then
1382 the only way this function was invoked is if the default action
1383 is an error action. In that case, don't check for expected
1384 tokens because there are none.
1385 - The only way there can be no lookahead present (in yychar) is if
1386 this state is a consistent state with a default action. Thus,
1387 detecting the absence of a lookahead is sufficient to determine
1388 that there is no unexpected or expected token to report. In that
1389 case, just report a simple "syntax error".
1390 - Don't assume there isn't a lookahead just because this state is a
1391 consistent state with a default action. There might have been a
1392 previous inconsistent state, consistent state with a non-default
1393 action, or user semantic action that manipulated yychar.
1394 - Of course, the expected token list depends on states to have
1395 correct lookahead information, and it depends on the parser not
1396 to perform extra reductions after fetching a lookahead from the
1397 scanner and before detecting a syntax error. Thus, state merging
1398 (from LALR or IELR) and default reductions corrupt the expected
1399 token list. However, the list is correct for canonical LR with
1400 one exception: it will still contain any token that will not be
1401 accepted due to an error action in a later state.
1403 if (yytoken != YYEMPTY)
1405 int yyn = yypact[*yyssp];
1406 yyarg[yycount++] = yytname[yytoken];
1407 if (!yypact_value_is_default (yyn))
1409 /* Start YYX at -YYN if negative to avoid negative indexes in
1410 YYCHECK. In other words, skip the first -YYN actions for
1411 this state because they are default actions. */
1412 int yyxbegin = yyn < 0 ? -yyn : 0;
1413 /* Stay within bounds of both yycheck and yytname. */
1414 int yychecklim = YYLAST - yyn + 1;
1415 int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
1418 for (yyx = yyxbegin; yyx < yyxend; ++yyx)
1419 if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR
1420 && !yytable_value_is_error (yytable[yyx + yyn]))
1422 if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
1428 yyarg[yycount++] = yytname[yyx];
1429 yysize1 = yysize + yytnamerr (YY_NULL, yytname[yyx]);
1430 if (! (yysize <= yysize1
1431 && yysize1 <= YYSTACK_ALLOC_MAXIMUM))
1440 # define YYCASE_(N, S) \
1444 YYCASE_(0, YY_("syntax error"));
1445 YYCASE_(1, YY_("syntax error, unexpected %s"));
1446 YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s"));
1447 YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s"));
1448 YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s"));
1449 YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"));
1453 yysize1 = yysize + yystrlen (yyformat);
1454 if (! (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM))
1458 if (*yymsg_alloc < yysize)
1460 *yymsg_alloc = 2 * yysize;
1461 if (! (yysize <= *yymsg_alloc
1462 && *yymsg_alloc <= YYSTACK_ALLOC_MAXIMUM))
1463 *yymsg_alloc = YYSTACK_ALLOC_MAXIMUM;
1467 /* Avoid sprintf, as that infringes on the user's name space.
1468 Don't have undefined behavior even if the translation
1469 produced a string with the wrong number of "%s"s. */
1473 while ((*yyp = *yyformat) != '\0')
1474 if (*yyp == '%' && yyformat[1] == 's' && yyi < yycount)
1476 yyp += yytnamerr (yyp, yyarg[yyi++]);
1487 #endif /* YYERROR_VERBOSE */
1489 /*-----------------------------------------------.
1490 | Release the memory associated to this symbol. |
1491 `-----------------------------------------------*/
1494 #if (defined __STDC__ || defined __C99__FUNC__ \
1495 || defined __cplusplus || defined _MSC_VER)
1497 yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep, parser_control *pc)
1500 yydestruct (yymsg, yytype, yyvaluep, pc)
1512 YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
1523 /* Prevent warnings from -Wmissing-prototypes. */
1524 #ifdef YYPARSE_PARAM
1525 #if defined __STDC__ || defined __cplusplus
1526 int yyparse (void *YYPARSE_PARAM);
1530 #else /* ! YYPARSE_PARAM */
1531 #if defined __STDC__ || defined __cplusplus
1532 int yyparse (parser_control *pc);
1536 #endif /* ! YYPARSE_PARAM */
1543 #ifdef YYPARSE_PARAM
1544 #if (defined __STDC__ || defined __C99__FUNC__ \
1545 || defined __cplusplus || defined _MSC_VER)
1547 yyparse (void *YYPARSE_PARAM)
1550 yyparse (YYPARSE_PARAM)
1551 void *YYPARSE_PARAM;
1553 #else /* ! YYPARSE_PARAM */
1554 #if (defined __STDC__ || defined __C99__FUNC__ \
1555 || defined __cplusplus || defined _MSC_VER)
1557 yyparse (parser_control *pc)
1565 /* The lookahead symbol. */
1568 /* The semantic value of the lookahead symbol. */
1571 /* Number of syntax errors so far. */
1575 /* Number of tokens to shift before error messages enabled. */
1578 /* The stacks and their tools:
1579 `yyss': related to states.
1580 `yyvs': related to semantic values.
1582 Refer to the stacks through separate pointers, to allow yyoverflow
1583 to reallocate them elsewhere. */
1585 /* The state stack. */
1586 yytype_int16 yyssa[YYINITDEPTH];
1588 yytype_int16 *yyssp;
1590 /* The semantic value stack. */
1591 YYSTYPE yyvsa[YYINITDEPTH];
1595 YYSIZE_T yystacksize;
1599 /* Lookahead token as an internal (translated) token number. */
1601 /* The variables used to return semantic value and location from the
1606 /* Buffer for error messages, and its allocated size. */
1608 char *yymsg = yymsgbuf;
1609 YYSIZE_T yymsg_alloc = sizeof yymsgbuf;
1612 #define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N))
1614 /* The number of symbols on the RHS of the reduced rule.
1615 Keep to zero when no symbol should be popped. */
1621 yystacksize = YYINITDEPTH;
1623 YYDPRINTF ((stderr, "Starting parse\n"));
1628 yychar = YYEMPTY; /* Cause a token to be read. */
1630 /* Initialize stack pointers.
1631 Waste one element of value and location stack
1632 so that they stay on the same level as the state stack.
1633 The wasted elements are never initialized. */
1639 /*------------------------------------------------------------.
1640 | yynewstate -- Push a new state, which is found in yystate. |
1641 `------------------------------------------------------------*/
1643 /* In all cases, when you get here, the value and location stacks
1644 have just been pushed. So pushing a state here evens the stacks. */
1650 if (yyss + yystacksize - 1 <= yyssp)
1652 /* Get the current used size of the three stacks, in elements. */
1653 YYSIZE_T yysize = yyssp - yyss + 1;
1657 /* Give user a chance to reallocate the stack. Use copies of
1658 these so that the &'s don't force the real ones into
1660 YYSTYPE *yyvs1 = yyvs;
1661 yytype_int16 *yyss1 = yyss;
1663 /* Each stack pointer address is followed by the size of the
1664 data in use in that stack, in bytes. This used to be a
1665 conditional around just the two extra args, but that might
1666 be undefined if yyoverflow is a macro. */
1667 yyoverflow (YY_("memory exhausted"),
1668 &yyss1, yysize * sizeof (*yyssp),
1669 &yyvs1, yysize * sizeof (*yyvsp),
1675 #else /* no yyoverflow */
1676 # ifndef YYSTACK_RELOCATE
1677 goto yyexhaustedlab;
1679 /* Extend the stack our own way. */
1680 if (YYMAXDEPTH <= yystacksize)
1681 goto yyexhaustedlab;
1683 if (YYMAXDEPTH < yystacksize)
1684 yystacksize = YYMAXDEPTH;
1687 yytype_int16 *yyss1 = yyss;
1688 union yyalloc *yyptr =
1689 (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
1691 goto yyexhaustedlab;
1692 YYSTACK_RELOCATE (yyss_alloc, yyss);
1693 YYSTACK_RELOCATE (yyvs_alloc, yyvs);
1694 # undef YYSTACK_RELOCATE
1696 YYSTACK_FREE (yyss1);
1699 #endif /* no yyoverflow */
1701 yyssp = yyss + yysize - 1;
1702 yyvsp = yyvs + yysize - 1;
1704 YYDPRINTF ((stderr, "Stack size increased to %lu\n",
1705 (unsigned long int) yystacksize));
1707 if (yyss + yystacksize - 1 <= yyssp)
1711 YYDPRINTF ((stderr, "Entering state %d\n", yystate));
1713 if (yystate == YYFINAL)
1723 /* Do appropriate processing given the current state. Read a
1724 lookahead token if we need one and don't already have one. */
1726 /* First try to decide what to do without reference to lookahead token. */
1727 yyn = yypact[yystate];
1728 if (yypact_value_is_default (yyn))
1731 /* Not known => get a lookahead token if don't already have one. */
1733 /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol. */
1734 if (yychar == YYEMPTY)
1736 YYDPRINTF ((stderr, "Reading a token: "));
1740 if (yychar <= YYEOF)
1742 yychar = yytoken = YYEOF;
1743 YYDPRINTF ((stderr, "Now at end of input.\n"));
1747 yytoken = YYTRANSLATE (yychar);
1748 YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
1751 /* If the proper action on seeing token YYTOKEN is to reduce or to
1752 detect an error, take that action. */
1754 if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
1759 if (yytable_value_is_error (yyn))
1765 /* Count tokens shifted since error; after three, turn off error
1770 /* Shift the lookahead token. */
1771 YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
1773 /* Discard the shifted token. */
1782 /*-----------------------------------------------------------.
1783 | yydefault -- do the default action for the current state. |
1784 `-----------------------------------------------------------*/
1786 yyn = yydefact[yystate];
1792 /*-----------------------------.
1793 | yyreduce -- Do a reduction. |
1794 `-----------------------------*/
1796 /* yyn is the number of a rule to reduce with. */
1799 /* If YYLEN is nonzero, implement the default value of the action:
1802 Otherwise, the following line sets YYVAL to garbage.
1803 This behavior is undocumented and Bison
1804 users should not rely upon it. Assigning to YYVAL
1805 unconditionally makes the parser a bit smaller, and it avoids a
1806 GCC warning that YYVAL may be used uninitialized. */
1807 yyval = yyvsp[1-yylen];
1810 YY_REDUCE_PRINT (yyn);
1815 /* Line 1810 of yacc.c */
1816 #line 330 "./parse-datetime.y"
1818 pc->seconds = (yyvsp[(2) - (2)].timespec);
1819 pc->timespec_seen = true;
1825 /* Line 1810 of yacc.c */
1826 #line 343 "./parse-datetime.y"
1827 { pc->times_seen++; pc->dates_seen++; }
1832 /* Line 1810 of yacc.c */
1833 #line 345 "./parse-datetime.y"
1834 { pc->times_seen++; }
1839 /* Line 1810 of yacc.c */
1840 #line 347 "./parse-datetime.y"
1841 { pc->local_zones_seen++; }
1846 /* Line 1810 of yacc.c */
1847 #line 349 "./parse-datetime.y"
1848 { pc->zones_seen++; }
1853 /* Line 1810 of yacc.c */
1854 #line 351 "./parse-datetime.y"
1855 { pc->dates_seen++; }
1860 /* Line 1810 of yacc.c */
1861 #line 353 "./parse-datetime.y"
1862 { pc->days_seen++; }
1867 /* Line 1810 of yacc.c */
1868 #line 369 "./parse-datetime.y"
1870 set_hhmmss (pc, (yyvsp[(1) - (2)].textintval).value, 0, 0, 0);
1871 pc->meridian = (yyvsp[(2) - (2)].intval);
1877 /* Line 1810 of yacc.c */
1878 #line 374 "./parse-datetime.y"
1880 set_hhmmss (pc, (yyvsp[(1) - (4)].textintval).value, (yyvsp[(3) - (4)].textintval).value, 0, 0);
1881 pc->meridian = (yyvsp[(4) - (4)].intval);
1887 /* Line 1810 of yacc.c */
1888 #line 379 "./parse-datetime.y"
1890 set_hhmmss (pc, (yyvsp[(1) - (6)].textintval).value, (yyvsp[(3) - (6)].textintval).value, (yyvsp[(5) - (6)].timespec).tv_sec, (yyvsp[(5) - (6)].timespec).tv_nsec);
1891 pc->meridian = (yyvsp[(6) - (6)].intval);
1897 /* Line 1810 of yacc.c */
1898 #line 388 "./parse-datetime.y"
1900 set_hhmmss (pc, (yyvsp[(1) - (2)].textintval).value, 0, 0, 0);
1901 pc->meridian = MER24;
1907 /* Line 1810 of yacc.c */
1908 #line 393 "./parse-datetime.y"
1910 set_hhmmss (pc, (yyvsp[(1) - (4)].textintval).value, (yyvsp[(3) - (4)].textintval).value, 0, 0);
1911 pc->meridian = MER24;
1917 /* Line 1810 of yacc.c */
1918 #line 398 "./parse-datetime.y"
1920 set_hhmmss (pc, (yyvsp[(1) - (6)].textintval).value, (yyvsp[(3) - (6)].textintval).value, (yyvsp[(5) - (6)].timespec).tv_sec, (yyvsp[(5) - (6)].timespec).tv_nsec);
1921 pc->meridian = MER24;
1927 /* Line 1810 of yacc.c */
1928 #line 411 "./parse-datetime.y"
1931 pc->time_zone = time_zone_hhmm (pc, (yyvsp[(1) - (2)].textintval), (yyvsp[(2) - (2)].intval));
1937 /* Line 1810 of yacc.c */
1938 #line 419 "./parse-datetime.y"
1940 pc->local_isdst = (yyvsp[(1) - (1)].intval);
1941 pc->dsts_seen += (0 < (yyvsp[(1) - (1)].intval));
1947 /* Line 1810 of yacc.c */
1948 #line 424 "./parse-datetime.y"
1950 pc->local_isdst = 1;
1951 pc->dsts_seen += (0 < (yyvsp[(1) - (2)].intval)) + 1;
1957 /* Line 1810 of yacc.c */
1958 #line 434 "./parse-datetime.y"
1959 { pc->time_zone = (yyvsp[(1) - (1)].intval); }
1964 /* Line 1810 of yacc.c */
1965 #line 436 "./parse-datetime.y"
1966 { pc->time_zone = HOUR(7); }
1971 /* Line 1810 of yacc.c */
1972 #line 438 "./parse-datetime.y"
1973 { pc->time_zone = (yyvsp[(1) - (2)].intval);
1974 apply_relative_time (pc, (yyvsp[(2) - (2)].rel), 1); }
1979 /* Line 1810 of yacc.c */
1980 #line 441 "./parse-datetime.y"
1981 { pc->time_zone = HOUR(7);
1982 apply_relative_time (pc, (yyvsp[(2) - (2)].rel), 1); }
1987 /* Line 1810 of yacc.c */
1988 #line 444 "./parse-datetime.y"
1989 { pc->time_zone = (yyvsp[(1) - (3)].intval) + time_zone_hhmm (pc, (yyvsp[(2) - (3)].textintval), (yyvsp[(3) - (3)].intval)); }
1994 /* Line 1810 of yacc.c */
1995 #line 446 "./parse-datetime.y"
1996 { pc->time_zone = (yyvsp[(1) - (1)].intval) + 60; }
2001 /* Line 1810 of yacc.c */
2002 #line 448 "./parse-datetime.y"
2003 { pc->time_zone = (yyvsp[(1) - (2)].intval) + 60; }
2008 /* Line 1810 of yacc.c */
2009 #line 453 "./parse-datetime.y"
2011 pc->day_ordinal = 0;
2012 pc->day_number = (yyvsp[(1) - (1)].intval);
2018 /* Line 1810 of yacc.c */
2019 #line 458 "./parse-datetime.y"
2021 pc->day_ordinal = 0;
2022 pc->day_number = (yyvsp[(1) - (2)].intval);
2028 /* Line 1810 of yacc.c */
2029 #line 463 "./parse-datetime.y"
2031 pc->day_ordinal = (yyvsp[(1) - (2)].intval);
2032 pc->day_number = (yyvsp[(2) - (2)].intval);
2038 /* Line 1810 of yacc.c */
2039 #line 468 "./parse-datetime.y"
2041 pc->day_ordinal = (yyvsp[(1) - (2)].textintval).value;
2042 pc->day_number = (yyvsp[(2) - (2)].intval);
2048 /* Line 1810 of yacc.c */
2049 #line 476 "./parse-datetime.y"
2051 pc->month = (yyvsp[(1) - (3)].textintval).value;
2052 pc->day = (yyvsp[(3) - (3)].textintval).value;
2058 /* Line 1810 of yacc.c */
2059 #line 481 "./parse-datetime.y"
2061 /* Interpret as YYYY/MM/DD if the first value has 4 or more digits,
2062 otherwise as MM/DD/YY.
2063 The goal in recognizing YYYY/MM/DD is solely to support legacy
2064 machine-generated dates like those in an RCS log listing. If
2065 you want portability, use the ISO 8601 format. */
2066 if (4 <= (yyvsp[(1) - (5)].textintval).digits)
2068 pc->year = (yyvsp[(1) - (5)].textintval);
2069 pc->month = (yyvsp[(3) - (5)].textintval).value;
2070 pc->day = (yyvsp[(5) - (5)].textintval).value;
2074 pc->month = (yyvsp[(1) - (5)].textintval).value;
2075 pc->day = (yyvsp[(3) - (5)].textintval).value;
2076 pc->year = (yyvsp[(5) - (5)].textintval);
2083 /* Line 1810 of yacc.c */
2084 #line 501 "./parse-datetime.y"
2086 /* e.g. 17-JUN-1992. */
2087 pc->day = (yyvsp[(1) - (3)].textintval).value;
2088 pc->month = (yyvsp[(2) - (3)].intval);
2089 pc->year.value = -(yyvsp[(3) - (3)].textintval).value;
2090 pc->year.digits = (yyvsp[(3) - (3)].textintval).digits;
2096 /* Line 1810 of yacc.c */
2097 #line 509 "./parse-datetime.y"
2099 /* e.g. JUN-17-1992. */
2100 pc->month = (yyvsp[(1) - (3)].intval);
2101 pc->day = -(yyvsp[(2) - (3)].textintval).value;
2102 pc->year.value = -(yyvsp[(3) - (3)].textintval).value;
2103 pc->year.digits = (yyvsp[(3) - (3)].textintval).digits;
2109 /* Line 1810 of yacc.c */
2110 #line 517 "./parse-datetime.y"
2112 pc->month = (yyvsp[(1) - (2)].intval);
2113 pc->day = (yyvsp[(2) - (2)].textintval).value;
2119 /* Line 1810 of yacc.c */
2120 #line 522 "./parse-datetime.y"
2122 pc->month = (yyvsp[(1) - (4)].intval);
2123 pc->day = (yyvsp[(2) - (4)].textintval).value;
2124 pc->year = (yyvsp[(4) - (4)].textintval);
2130 /* Line 1810 of yacc.c */
2131 #line 528 "./parse-datetime.y"
2133 pc->day = (yyvsp[(1) - (2)].textintval).value;
2134 pc->month = (yyvsp[(2) - (2)].intval);
2140 /* Line 1810 of yacc.c */
2141 #line 533 "./parse-datetime.y"
2143 pc->day = (yyvsp[(1) - (3)].textintval).value;
2144 pc->month = (yyvsp[(2) - (3)].intval);
2145 pc->year = (yyvsp[(3) - (3)].textintval);
2151 /* Line 1810 of yacc.c */
2152 #line 543 "./parse-datetime.y"
2154 /* ISO 8601 format. YYYY-MM-DD. */
2155 pc->year = (yyvsp[(1) - (3)].textintval);
2156 pc->month = -(yyvsp[(2) - (3)].textintval).value;
2157 pc->day = -(yyvsp[(3) - (3)].textintval).value;
2163 /* Line 1810 of yacc.c */
2164 #line 553 "./parse-datetime.y"
2165 { apply_relative_time (pc, (yyvsp[(1) - (2)].rel), (yyvsp[(2) - (2)].intval)); }
2170 /* Line 1810 of yacc.c */
2171 #line 555 "./parse-datetime.y"
2172 { apply_relative_time (pc, (yyvsp[(1) - (1)].rel), 1); }
2177 /* Line 1810 of yacc.c */
2178 #line 557 "./parse-datetime.y"
2179 { apply_relative_time (pc, (yyvsp[(1) - (1)].rel), 1); }
2184 /* Line 1810 of yacc.c */
2185 #line 562 "./parse-datetime.y"
2186 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).year = (yyvsp[(1) - (2)].intval); }
2191 /* Line 1810 of yacc.c */
2192 #line 564 "./parse-datetime.y"
2193 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).year = (yyvsp[(1) - (2)].textintval).value; }
2198 /* Line 1810 of yacc.c */
2199 #line 566 "./parse-datetime.y"
2200 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).year = 1; }
2205 /* Line 1810 of yacc.c */
2206 #line 568 "./parse-datetime.y"
2207 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).month = (yyvsp[(1) - (2)].intval); }
2212 /* Line 1810 of yacc.c */
2213 #line 570 "./parse-datetime.y"
2214 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).month = (yyvsp[(1) - (2)].textintval).value; }
2219 /* Line 1810 of yacc.c */
2220 #line 572 "./parse-datetime.y"
2221 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).month = 1; }
2226 /* Line 1810 of yacc.c */
2227 #line 574 "./parse-datetime.y"
2228 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).day = (yyvsp[(1) - (2)].intval) * (yyvsp[(2) - (2)].intval); }
2233 /* Line 1810 of yacc.c */
2234 #line 576 "./parse-datetime.y"
2235 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).day = (yyvsp[(1) - (2)].textintval).value * (yyvsp[(2) - (2)].intval); }
2240 /* Line 1810 of yacc.c */
2241 #line 578 "./parse-datetime.y"
2242 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).day = (yyvsp[(1) - (1)].intval); }
2247 /* Line 1810 of yacc.c */
2248 #line 580 "./parse-datetime.y"
2249 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).hour = (yyvsp[(1) - (2)].intval); }
2254 /* Line 1810 of yacc.c */
2255 #line 582 "./parse-datetime.y"
2256 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).hour = (yyvsp[(1) - (2)].textintval).value; }
2261 /* Line 1810 of yacc.c */
2262 #line 584 "./parse-datetime.y"
2263 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).hour = 1; }
2268 /* Line 1810 of yacc.c */
2269 #line 586 "./parse-datetime.y"
2270 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).minutes = (yyvsp[(1) - (2)].intval); }
2275 /* Line 1810 of yacc.c */
2276 #line 588 "./parse-datetime.y"
2277 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).minutes = (yyvsp[(1) - (2)].textintval).value; }
2282 /* Line 1810 of yacc.c */
2283 #line 590 "./parse-datetime.y"
2284 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).minutes = 1; }
2289 /* Line 1810 of yacc.c */
2290 #line 592 "./parse-datetime.y"
2291 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).seconds = (yyvsp[(1) - (2)].intval); }
2296 /* Line 1810 of yacc.c */
2297 #line 594 "./parse-datetime.y"
2298 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).seconds = (yyvsp[(1) - (2)].textintval).value; }
2303 /* Line 1810 of yacc.c */
2304 #line 596 "./parse-datetime.y"
2305 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).seconds = (yyvsp[(1) - (2)].timespec).tv_sec; (yyval.rel).ns = (yyvsp[(1) - (2)].timespec).tv_nsec; }
2310 /* Line 1810 of yacc.c */
2311 #line 598 "./parse-datetime.y"
2312 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).seconds = (yyvsp[(1) - (2)].timespec).tv_sec; (yyval.rel).ns = (yyvsp[(1) - (2)].timespec).tv_nsec; }
2317 /* Line 1810 of yacc.c */
2318 #line 600 "./parse-datetime.y"
2319 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).seconds = 1; }
2324 /* Line 1810 of yacc.c */
2325 #line 606 "./parse-datetime.y"
2326 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).year = (yyvsp[(1) - (2)].textintval).value; }
2331 /* Line 1810 of yacc.c */
2332 #line 608 "./parse-datetime.y"
2333 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).month = (yyvsp[(1) - (2)].textintval).value; }
2338 /* Line 1810 of yacc.c */
2339 #line 610 "./parse-datetime.y"
2340 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).day = (yyvsp[(1) - (2)].textintval).value * (yyvsp[(2) - (2)].intval); }
2345 /* Line 1810 of yacc.c */
2346 #line 612 "./parse-datetime.y"
2347 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).hour = (yyvsp[(1) - (2)].textintval).value; }
2352 /* Line 1810 of yacc.c */
2353 #line 614 "./parse-datetime.y"
2354 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).minutes = (yyvsp[(1) - (2)].textintval).value; }
2359 /* Line 1810 of yacc.c */
2360 #line 616 "./parse-datetime.y"
2361 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).seconds = (yyvsp[(1) - (2)].textintval).value; }
2366 /* Line 1810 of yacc.c */
2367 #line 621 "./parse-datetime.y"
2368 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).day = (yyvsp[(1) - (1)].intval); }
2373 /* Line 1810 of yacc.c */
2374 #line 629 "./parse-datetime.y"
2375 { (yyval.timespec).tv_sec = (yyvsp[(1) - (1)].textintval).value; (yyval.timespec).tv_nsec = 0; }
2380 /* Line 1810 of yacc.c */
2381 #line 635 "./parse-datetime.y"
2382 { (yyval.timespec).tv_sec = (yyvsp[(1) - (1)].textintval).value; (yyval.timespec).tv_nsec = 0; }
2387 /* Line 1810 of yacc.c */
2388 #line 640 "./parse-datetime.y"
2389 { digits_to_date_time (pc, (yyvsp[(1) - (1)].textintval)); }
2394 /* Line 1810 of yacc.c */
2395 #line 645 "./parse-datetime.y"
2397 /* Hybrid all-digit and relative offset, so that we accept e.g.,
2398 "YYYYMMDD +N days" as well as "YYYYMMDD N days". */
2399 digits_to_date_time (pc, (yyvsp[(1) - (2)].textintval));
2400 apply_relative_time (pc, (yyvsp[(2) - (2)].rel), 1);
2406 /* Line 1810 of yacc.c */
2407 #line 655 "./parse-datetime.y"
2408 { (yyval.intval) = -1; }
2413 /* Line 1810 of yacc.c */
2414 #line 657 "./parse-datetime.y"
2415 { (yyval.intval) = (yyvsp[(2) - (2)].textintval).value; }
2420 /* Line 1810 of yacc.c */
2421 #line 2422 "parse-datetime.c"
2424 /* User semantic actions sometimes alter yychar, and that requires
2425 that yytoken be updated with the new translation. We take the
2426 approach of translating immediately before every use of yytoken.
2427 One alternative is translating here after every semantic action,
2428 but that translation would be missed if the semantic action invokes
2429 YYABORT, YYACCEPT, or YYERROR immediately after altering yychar or
2430 if it invokes YYBACKUP. In the case of YYABORT or YYACCEPT, an
2431 incorrect destructor might then be invoked immediately. In the
2432 case of YYERROR or YYBACKUP, subsequent parser actions might lead
2433 to an incorrect destructor call or verbose syntax error message
2434 before the lookahead is translated. */
2435 YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc);
2439 YY_STACK_PRINT (yyss, yyssp);
2443 /* Now `shift' the result of the reduction. Determine what state
2444 that goes to, based on the state we popped back to and the rule
2445 number reduced by. */
2449 yystate = yypgoto[yyn - YYNTOKENS] + *yyssp;
2450 if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp)
2451 yystate = yytable[yystate];
2453 yystate = yydefgoto[yyn - YYNTOKENS];
2458 /*------------------------------------.
2459 | yyerrlab -- here on detecting error |
2460 `------------------------------------*/
2462 /* Make sure we have latest lookahead translation. See comments at
2463 user semantic actions for why this is necessary. */
2464 yytoken = yychar == YYEMPTY ? YYEMPTY : YYTRANSLATE (yychar);
2466 /* If not already recovering from an error, report this error. */
2470 #if ! YYERROR_VERBOSE
2471 yyerror (pc, YY_("syntax error"));
2473 # define YYSYNTAX_ERROR yysyntax_error (&yymsg_alloc, &yymsg, \
2476 char const *yymsgp = YY_("syntax error");
2477 int yysyntax_error_status;
2478 yysyntax_error_status = YYSYNTAX_ERROR;
2479 if (yysyntax_error_status == 0)
2481 else if (yysyntax_error_status == 1)
2483 if (yymsg != yymsgbuf)
2484 YYSTACK_FREE (yymsg);
2485 yymsg = (char *) YYSTACK_ALLOC (yymsg_alloc);
2489 yymsg_alloc = sizeof yymsgbuf;
2490 yysyntax_error_status = 2;
2494 yysyntax_error_status = YYSYNTAX_ERROR;
2498 yyerror (pc, yymsgp);
2499 if (yysyntax_error_status == 2)
2500 goto yyexhaustedlab;
2502 # undef YYSYNTAX_ERROR
2508 if (yyerrstatus == 3)
2510 /* If just tried and failed to reuse lookahead token after an
2511 error, discard it. */
2513 if (yychar <= YYEOF)
2515 /* Return failure if at end of input. */
2516 if (yychar == YYEOF)
2521 yydestruct ("Error: discarding",
2522 yytoken, &yylval, pc);
2527 /* Else will try to reuse lookahead token after shifting the error
2532 /*---------------------------------------------------.
2533 | yyerrorlab -- error raised explicitly by YYERROR. |
2534 `---------------------------------------------------*/
2537 /* Pacify compilers like GCC when the user code never invokes
2538 YYERROR and the label yyerrorlab therefore never appears in user
2540 if (/*CONSTCOND*/ 0)
2543 /* Do not reclaim the symbols of the rule which action triggered
2547 YY_STACK_PRINT (yyss, yyssp);
2552 /*-------------------------------------------------------------.
2553 | yyerrlab1 -- common code for both syntax error and YYERROR. |
2554 `-------------------------------------------------------------*/
2556 yyerrstatus = 3; /* Each real token shifted decrements this. */
2560 yyn = yypact[yystate];
2561 if (!yypact_value_is_default (yyn))
2564 if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
2572 /* Pop the current state because it cannot handle the error token. */
2577 yydestruct ("Error: popping",
2578 yystos[yystate], yyvsp, pc);
2581 YY_STACK_PRINT (yyss, yyssp);
2587 /* Shift the error token. */
2588 YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp);
2594 /*-------------------------------------.
2595 | yyacceptlab -- YYACCEPT comes here. |
2596 `-------------------------------------*/
2601 /*-----------------------------------.
2602 | yyabortlab -- YYABORT comes here. |
2603 `-----------------------------------*/
2608 #if !defined yyoverflow || YYERROR_VERBOSE
2609 /*-------------------------------------------------.
2610 | yyexhaustedlab -- memory exhaustion comes here. |
2611 `-------------------------------------------------*/
2613 yyerror (pc, YY_("memory exhausted"));
2619 if (yychar != YYEMPTY)
2621 /* Make sure we have latest lookahead translation. See comments at
2622 user semantic actions for why this is necessary. */
2623 yytoken = YYTRANSLATE (yychar);
2624 yydestruct ("Cleanup: discarding lookahead",
2625 yytoken, &yylval, pc);
2627 /* Do not reclaim the symbols of the rule which action triggered
2628 this YYABORT or YYACCEPT. */
2630 YY_STACK_PRINT (yyss, yyssp);
2631 while (yyssp != yyss)
2633 yydestruct ("Cleanup: popping",
2634 yystos[*yyssp], yyvsp, pc);
2639 YYSTACK_FREE (yyss);
2642 if (yymsg != yymsgbuf)
2643 YYSTACK_FREE (yymsg);
2645 /* Make sure YYID is used. */
2646 return YYID (yyresult);
2651 /* Line 2071 of yacc.c */
2652 #line 660 "./parse-datetime.y"
2655 static table const meridian_table[] =
2657 { "AM", tMERIDIAN, MERam },
2658 { "A.M.", tMERIDIAN, MERam },
2659 { "PM", tMERIDIAN, MERpm },
2660 { "P.M.", tMERIDIAN, MERpm },
2664 static table const dst_table[] =
2669 static table const month_and_day_table[] =
2671 { "JANUARY", tMONTH, 1 },
2672 { "FEBRUARY", tMONTH, 2 },
2673 { "MARCH", tMONTH, 3 },
2674 { "APRIL", tMONTH, 4 },
2675 { "MAY", tMONTH, 5 },
2676 { "JUNE", tMONTH, 6 },
2677 { "JULY", tMONTH, 7 },
2678 { "AUGUST", tMONTH, 8 },
2679 { "SEPTEMBER",tMONTH, 9 },
2680 { "SEPT", tMONTH, 9 },
2681 { "OCTOBER", tMONTH, 10 },
2682 { "NOVEMBER", tMONTH, 11 },
2683 { "DECEMBER", tMONTH, 12 },
2684 { "SUNDAY", tDAY, 0 },
2685 { "MONDAY", tDAY, 1 },
2686 { "TUESDAY", tDAY, 2 },
2687 { "TUES", tDAY, 2 },
2688 { "WEDNESDAY",tDAY, 3 },
2689 { "WEDNES", tDAY, 3 },
2690 { "THURSDAY", tDAY, 4 },
2691 { "THUR", tDAY, 4 },
2692 { "THURS", tDAY, 4 },
2693 { "FRIDAY", tDAY, 5 },
2694 { "SATURDAY", tDAY, 6 },
2698 static table const time_units_table[] =
2700 { "YEAR", tYEAR_UNIT, 1 },
2701 { "MONTH", tMONTH_UNIT, 1 },
2702 { "FORTNIGHT",tDAY_UNIT, 14 },
2703 { "WEEK", tDAY_UNIT, 7 },
2704 { "DAY", tDAY_UNIT, 1 },
2705 { "HOUR", tHOUR_UNIT, 1 },
2706 { "MINUTE", tMINUTE_UNIT, 1 },
2707 { "MIN", tMINUTE_UNIT, 1 },
2708 { "SECOND", tSEC_UNIT, 1 },
2709 { "SEC", tSEC_UNIT, 1 },
2713 /* Assorted relative-time words. */
2714 static table const relative_time_table[] =
2716 { "TOMORROW", tDAY_SHIFT, 1 },
2717 { "YESTERDAY",tDAY_SHIFT, -1 },
2718 { "TODAY", tDAY_SHIFT, 0 },
2719 { "NOW", tDAY_SHIFT, 0 },
2720 { "LAST", tORDINAL, -1 },
2721 { "THIS", tORDINAL, 0 },
2722 { "NEXT", tORDINAL, 1 },
2723 { "FIRST", tORDINAL, 1 },
2724 /*{ "SECOND", tORDINAL, 2 }, */
2725 { "THIRD", tORDINAL, 3 },
2726 { "FOURTH", tORDINAL, 4 },
2727 { "FIFTH", tORDINAL, 5 },
2728 { "SIXTH", tORDINAL, 6 },
2729 { "SEVENTH", tORDINAL, 7 },
2730 { "EIGHTH", tORDINAL, 8 },
2731 { "NINTH", tORDINAL, 9 },
2732 { "TENTH", tORDINAL, 10 },
2733 { "ELEVENTH", tORDINAL, 11 },
2734 { "TWELFTH", tORDINAL, 12 },
2735 { "AGO", tAGO, -1 },
2736 { "HENCE", tAGO, 1 },
2740 /* The universal time zone table. These labels can be used even for
2741 time stamps that would not otherwise be valid, e.g., GMT time
2742 stamps in London during summer. */
2743 static table const universal_time_zone_table[] =
2745 { "GMT", tZONE, HOUR ( 0) }, /* Greenwich Mean */
2746 { "UT", tZONE, HOUR ( 0) }, /* Universal (Coordinated) */
2747 { "UTC", tZONE, HOUR ( 0) },
2751 /* The time zone table. This table is necessarily incomplete, as time
2752 zone abbreviations are ambiguous; e.g. Australians interpret "EST"
2753 as Eastern time in Australia, not as US Eastern Standard Time.
2754 You cannot rely on parse_datetime to handle arbitrary time zone
2755 abbreviations; use numeric abbreviations like "-0500" instead. */
2756 static table const time_zone_table[] =
2758 { "WET", tZONE, HOUR ( 0) }, /* Western European */
2759 { "WEST", tDAYZONE, HOUR ( 0) }, /* Western European Summer */
2760 { "BST", tDAYZONE, HOUR ( 0) }, /* British Summer */
2761 { "ART", tZONE, -HOUR ( 3) }, /* Argentina */
2762 { "BRT", tZONE, -HOUR ( 3) }, /* Brazil */
2763 { "BRST", tDAYZONE, -HOUR ( 3) }, /* Brazil Summer */
2764 { "NST", tZONE, -(HOUR ( 3) + 30) }, /* Newfoundland Standard */
2765 { "NDT", tDAYZONE,-(HOUR ( 3) + 30) }, /* Newfoundland Daylight */
2766 { "AST", tZONE, -HOUR ( 4) }, /* Atlantic Standard */
2767 { "ADT", tDAYZONE, -HOUR ( 4) }, /* Atlantic Daylight */
2768 { "CLT", tZONE, -HOUR ( 4) }, /* Chile */
2769 { "CLST", tDAYZONE, -HOUR ( 4) }, /* Chile Summer */
2770 { "EST", tZONE, -HOUR ( 5) }, /* Eastern Standard */
2771 { "EDT", tDAYZONE, -HOUR ( 5) }, /* Eastern Daylight */
2772 { "CST", tZONE, -HOUR ( 6) }, /* Central Standard */
2773 { "CDT", tDAYZONE, -HOUR ( 6) }, /* Central Daylight */
2774 { "MST", tZONE, -HOUR ( 7) }, /* Mountain Standard */
2775 { "MDT", tDAYZONE, -HOUR ( 7) }, /* Mountain Daylight */
2776 { "PST", tZONE, -HOUR ( 8) }, /* Pacific Standard */
2777 { "PDT", tDAYZONE, -HOUR ( 8) }, /* Pacific Daylight */
2778 { "AKST", tZONE, -HOUR ( 9) }, /* Alaska Standard */
2779 { "AKDT", tDAYZONE, -HOUR ( 9) }, /* Alaska Daylight */
2780 { "HST", tZONE, -HOUR (10) }, /* Hawaii Standard */
2781 { "HAST", tZONE, -HOUR (10) }, /* Hawaii-Aleutian Standard */
2782 { "HADT", tDAYZONE, -HOUR (10) }, /* Hawaii-Aleutian Daylight */
2783 { "SST", tZONE, -HOUR (12) }, /* Samoa Standard */
2784 { "WAT", tZONE, HOUR ( 1) }, /* West Africa */
2785 { "CET", tZONE, HOUR ( 1) }, /* Central European */
2786 { "CEST", tDAYZONE, HOUR ( 1) }, /* Central European Summer */
2787 { "MET", tZONE, HOUR ( 1) }, /* Middle European */
2788 { "MEZ", tZONE, HOUR ( 1) }, /* Middle European */
2789 { "MEST", tDAYZONE, HOUR ( 1) }, /* Middle European Summer */
2790 { "MESZ", tDAYZONE, HOUR ( 1) }, /* Middle European Summer */
2791 { "EET", tZONE, HOUR ( 2) }, /* Eastern European */
2792 { "EEST", tDAYZONE, HOUR ( 2) }, /* Eastern European Summer */
2793 { "CAT", tZONE, HOUR ( 2) }, /* Central Africa */
2794 { "SAST", tZONE, HOUR ( 2) }, /* South Africa Standard */
2795 { "EAT", tZONE, HOUR ( 3) }, /* East Africa */
2796 { "MSK", tZONE, HOUR ( 3) }, /* Moscow */
2797 { "MSD", tDAYZONE, HOUR ( 3) }, /* Moscow Daylight */
2798 { "IST", tZONE, (HOUR ( 5) + 30) }, /* India Standard */
2799 { "SGT", tZONE, HOUR ( 8) }, /* Singapore */
2800 { "KST", tZONE, HOUR ( 9) }, /* Korea Standard */
2801 { "JST", tZONE, HOUR ( 9) }, /* Japan Standard */
2802 { "GST", tZONE, HOUR (10) }, /* Guam Standard */
2803 { "NZST", tZONE, HOUR (12) }, /* New Zealand Standard */
2804 { "NZDT", tDAYZONE, HOUR (12) }, /* New Zealand Daylight */
2808 /* Military time zone table.
2810 Note 'T' is a special case, as it is used as the separator in ISO
2811 8601 date and time of day representation. */
2812 static table const military_table[] =
2814 { "A", tZONE, -HOUR ( 1) },
2815 { "B", tZONE, -HOUR ( 2) },
2816 { "C", tZONE, -HOUR ( 3) },
2817 { "D", tZONE, -HOUR ( 4) },
2818 { "E", tZONE, -HOUR ( 5) },
2819 { "F", tZONE, -HOUR ( 6) },
2820 { "G", tZONE, -HOUR ( 7) },
2821 { "H", tZONE, -HOUR ( 8) },
2822 { "I", tZONE, -HOUR ( 9) },
2823 { "K", tZONE, -HOUR (10) },
2824 { "L", tZONE, -HOUR (11) },
2825 { "M", tZONE, -HOUR (12) },
2826 { "N", tZONE, HOUR ( 1) },
2827 { "O", tZONE, HOUR ( 2) },
2828 { "P", tZONE, HOUR ( 3) },
2829 { "Q", tZONE, HOUR ( 4) },
2830 { "R", tZONE, HOUR ( 5) },
2831 { "S", tZONE, HOUR ( 6) },
2833 { "U", tZONE, HOUR ( 8) },
2834 { "V", tZONE, HOUR ( 9) },
2835 { "W", tZONE, HOUR (10) },
2836 { "X", tZONE, HOUR (11) },
2837 { "Y", tZONE, HOUR (12) },
2838 { "Z", tZONE, HOUR ( 0) },
2844 /* Convert a time zone expressed as HH:MM into an integer count of
2845 minutes. If MM is negative, then S is of the form HHMM and needs
2846 to be picked apart; otherwise, S is of the form HH. As specified in
2847 http://www.opengroup.org/susv3xbd/xbd_chap08.html#tag_08_03, allow
2848 only valid TZ range, and consider first two digits as hours, if no
2849 minutes specified. */
2852 time_zone_hhmm (parser_control *pc, textint s, long int mm)
2856 /* If the length of S is 1 or 2 and no minutes are specified,
2857 interpret it as a number of hours. */
2858 if (s.digits <= 2 && mm < 0)
2862 n_minutes = (s.value / 100) * 60 + s.value % 100;
2864 n_minutes = s.value * 60 + (s.negative ? -mm : mm);
2866 /* If the absolute number of minutes is larger than 24 hours,
2867 arrange to reject it by incrementing pc->zones_seen. Thus,
2868 we allow only values in the range UTC-24:00 to UTC+24:00. */
2869 if (24 * 60 < abs (n_minutes))
2876 to_hour (long int hours, int meridian)
2880 default: /* Pacify GCC. */
2882 return 0 <= hours && hours < 24 ? hours : -1;
2884 return 0 < hours && hours < 12 ? hours : hours == 12 ? 0 : -1;
2886 return 0 < hours && hours < 12 ? hours + 12 : hours == 12 ? 12 : -1;
2891 to_year (textint textyear)
2893 long int year = textyear.value;
2898 /* XPG4 suggests that years 00-68 map to 2000-2068, and
2899 years 69-99 map to 1969-1999. */
2900 else if (textyear.digits == 2)
2901 year += year < 69 ? 2000 : 1900;
2906 static table const * _GL_ATTRIBUTE_PURE
2907 lookup_zone (parser_control const *pc, char const *name)
2911 for (tp = universal_time_zone_table; tp->name; tp++)
2912 if (strcmp (name, tp->name) == 0)
2915 /* Try local zone abbreviations before those in time_zone_table, as
2916 the local ones are more likely to be right. */
2917 for (tp = pc->local_time_zone_table; tp->name; tp++)
2918 if (strcmp (name, tp->name) == 0)
2921 for (tp = time_zone_table; tp->name; tp++)
2922 if (strcmp (name, tp->name) == 0)
2928 #if ! HAVE_TM_GMTOFF
2929 /* Yield the difference between *A and *B,
2930 measured in seconds, ignoring leap seconds.
2931 The body of this function is taken directly from the GNU C Library;
2932 see src/strftime.c. */
2934 tm_diff (struct tm const *a, struct tm const *b)
2936 /* Compute intervening leap days correctly even if year is negative.
2937 Take care to avoid int overflow in leap day calculations. */
2938 int a4 = SHR (a->tm_year, 2) + SHR (TM_YEAR_BASE, 2) - ! (a->tm_year & 3);
2939 int b4 = SHR (b->tm_year, 2) + SHR (TM_YEAR_BASE, 2) - ! (b->tm_year & 3);
2940 int a100 = a4 / 25 - (a4 % 25 < 0);
2941 int b100 = b4 / 25 - (b4 % 25 < 0);
2942 int a400 = SHR (a100, 2);
2943 int b400 = SHR (b100, 2);
2944 int intervening_leap_days = (a4 - b4) - (a100 - b100) + (a400 - b400);
2945 long int ayear = a->tm_year;
2946 long int years = ayear - b->tm_year;
2947 long int days = (365 * years + intervening_leap_days
2948 + (a->tm_yday - b->tm_yday));
2949 return (60 * (60 * (24 * days + (a->tm_hour - b->tm_hour))
2950 + (a->tm_min - b->tm_min))
2951 + (a->tm_sec - b->tm_sec));
2953 #endif /* ! HAVE_TM_GMTOFF */
2955 static table const *
2956 lookup_word (parser_control const *pc, char *word)
2965 /* Make it uppercase. */
2966 for (p = word; *p; p++)
2968 unsigned char ch = *p;
2969 *p = c_toupper (ch);
2972 for (tp = meridian_table; tp->name; tp++)
2973 if (strcmp (word, tp->name) == 0)
2976 /* See if we have an abbreviation for a month. */
2977 wordlen = strlen (word);
2978 abbrev = wordlen == 3 || (wordlen == 4 && word[3] == '.');
2980 for (tp = month_and_day_table; tp->name; tp++)
2981 if ((abbrev ? strncmp (word, tp->name, 3) : strcmp (word, tp->name)) == 0)
2984 if ((tp = lookup_zone (pc, word)))
2987 if (strcmp (word, dst_table[0].name) == 0)
2990 for (tp = time_units_table; tp->name; tp++)
2991 if (strcmp (word, tp->name) == 0)
2994 /* Strip off any plural and try the units table again. */
2995 if (word[wordlen - 1] == 'S')
2997 word[wordlen - 1] = '\0';
2998 for (tp = time_units_table; tp->name; tp++)
2999 if (strcmp (word, tp->name) == 0)
3001 word[wordlen - 1] = 'S'; /* For "this" in relative_time_table. */
3004 for (tp = relative_time_table; tp->name; tp++)
3005 if (strcmp (word, tp->name) == 0)
3008 /* Military time zones. */
3010 for (tp = military_table; tp->name; tp++)
3011 if (word[0] == tp->name[0])
3014 /* Drop out any periods and try the time zone table again. */
3015 for (period_found = false, p = q = word; (*p = *q); q++)
3017 period_found = true;
3020 if (period_found && (tp = lookup_zone (pc, word)))
3027 yylex (union YYSTYPE *lvalp, parser_control *pc)
3034 while (c = *pc->input, c_isspace (c))
3037 if (ISDIGIT (c) || c == '-' || c == '+')
3041 unsigned long int value;
3042 if (c == '-' || c == '+')
3044 sign = c == '-' ? -1 : 1;
3045 while (c = *++pc->input, c_isspace (c))
3048 /* skip the '-' sign */
3054 for (value = 0; ; value *= 10)
3056 unsigned long int value1 = value + (c - '0');
3063 if (ULONG_MAX / 10 < value)
3066 if ((c == '.' || c == ',') && ISDIGIT (p[1]))
3071 unsigned long int value1;
3073 /* Check for overflow when converting value to time_t. */
3088 if (value != value1)
3091 /* Accumulate fraction, to ns precision. */
3094 for (digits = 2; digits <= LOG10_BILLION; digits++)
3101 /* Skip excess digits, truncating toward -Infinity. */
3103 for (; ISDIGIT (*p); p++)
3109 while (ISDIGIT (*p))
3112 /* Adjust to the timespec convention, which is that
3113 tv_nsec is always a positive offset even if tv_sec is
3123 lvalp->timespec.tv_sec = s;
3124 lvalp->timespec.tv_nsec = ns;
3126 return sign ? tSDECIMAL_NUMBER : tUDECIMAL_NUMBER;
3130 lvalp->textintval.negative = sign < 0;
3133 lvalp->textintval.value = - value;
3134 if (0 < lvalp->textintval.value)
3139 lvalp->textintval.value = value;
3140 if (lvalp->textintval.value < 0)
3143 lvalp->textintval.digits = p - pc->input;
3145 return sign ? tSNUMBER : tUNUMBER;
3157 if (p < buff + sizeof buff - 1)
3161 while (c_isalpha (c) || c == '.');
3164 tp = lookup_word (pc, buff);
3167 lvalp->intval = tp->value;
3172 return to_uchar (*pc->input++);
3189 /* Do nothing if the parser reports an error. */
3191 yyerror (parser_control const *pc _GL_UNUSED,
3192 char const *s _GL_UNUSED)
3197 /* If *TM0 is the old and *TM1 is the new value of a struct tm after
3198 passing it to mktime, return true if it's OK that mktime returned T.
3199 It's not OK if *TM0 has out-of-range members. */
3202 mktime_ok (struct tm const *tm0, struct tm const *tm1, time_t t)
3204 if (t == (time_t) -1)
3206 /* Guard against falsely reporting an error when parsing a time
3207 stamp that happens to equal (time_t) -1, on a host that
3208 supports such a time stamp. */
3209 tm1 = localtime (&t);
3214 return ! ((tm0->tm_sec ^ tm1->tm_sec)
3215 | (tm0->tm_min ^ tm1->tm_min)
3216 | (tm0->tm_hour ^ tm1->tm_hour)
3217 | (tm0->tm_mday ^ tm1->tm_mday)
3218 | (tm0->tm_mon ^ tm1->tm_mon)
3219 | (tm0->tm_year ^ tm1->tm_year));
3222 /* A reasonable upper bound for the size of ordinary TZ strings.
3223 Use heap allocation if TZ's length exceeds this. */
3224 enum { TZBUFSIZE = 100 };
3226 /* Return a copy of TZ, stored in TZBUF if it fits, and heap-allocated
3229 get_tz (char tzbuf[TZBUFSIZE])
3231 char *tz = getenv ("TZ");
3234 size_t tzsize = strlen (tz) + 1;
3235 tz = (tzsize <= TZBUFSIZE
3236 ? memcpy (tzbuf, tz, tzsize)
3237 : xmemdup (tz, tzsize));
3242 /* Parse a date/time string, storing the resulting time value into *RESULT.
3243 The string itself is pointed to by P. Return true if successful.
3244 P can be an incomplete or relative time specification; if so, use
3245 *NOW as the basis for the returned time. */
3247 parse_datetime (struct timespec *result, char const *p,
3248 struct timespec const *now)
3252 struct tm const *tmp;
3256 struct timespec gettime_buffer;
3258 bool tz_was_altered = false;
3260 char tz0buf[TZBUFSIZE];
3265 gettime (&gettime_buffer);
3266 now = &gettime_buffer;
3269 Start = now->tv_sec;
3270 Start_ns = now->tv_nsec;
3272 tmp = localtime (&now->tv_sec);
3276 while (c = *p, c_isspace (c))
3279 if (strncmp (p, "TZ=\"", 4) == 0)
3281 char const *tzbase = p + 4;
3285 for (s = tzbase; *s; s++, tzsize++)
3289 if (! (*s == '\\' || *s == '"'))
3296 char tz1buf[TZBUFSIZE];
3297 bool large_tz = TZBUFSIZE < tzsize;
3299 tz0 = get_tz (tz0buf);
3300 z = tz1 = large_tz ? xmalloc (tzsize) : tz1buf;
3301 for (s = tzbase; *s != '"'; s++)
3302 *z++ = *(s += *s == '\\');
3304 setenv_ok = setenv ("TZ", tz1, 1) == 0;
3309 tz_was_altered = true;
3312 while (c = *p, c_isspace (c))
3319 /* As documented, be careful to treat the empty string just like
3320 a date string of "0". Without this, an empty string would be
3321 declared invalid when parsed during a DST transition. */
3326 pc.year.value = tmp->tm_year;
3327 pc.year.value += TM_YEAR_BASE;
3329 pc.month = tmp->tm_mon + 1;
3330 pc.day = tmp->tm_mday;
3331 pc.hour = tmp->tm_hour;
3332 pc.minutes = tmp->tm_min;
3333 pc.seconds.tv_sec = tmp->tm_sec;
3334 pc.seconds.tv_nsec = Start_ns;
3335 tm.tm_isdst = tmp->tm_isdst;
3337 pc.meridian = MER24;
3338 pc.rel = RELATIVE_TIME_0;
3339 pc.timespec_seen = false;
3340 pc.rels_seen = false;
3344 pc.local_zones_seen = 0;
3348 #if HAVE_STRUCT_TM_TM_ZONE
3349 pc.local_time_zone_table[0].name = tmp->tm_zone;
3350 pc.local_time_zone_table[0].type = tLOCAL_ZONE;
3351 pc.local_time_zone_table[0].value = tmp->tm_isdst;
3352 pc.local_time_zone_table[1].name = NULL;
3354 /* Probe the names used in the next three calendar quarters, looking
3355 for a tm_isdst different from the one we already have. */
3358 for (quarter = 1; quarter <= 3; quarter++)
3360 time_t probe = Start + quarter * (90 * 24 * 60 * 60);
3361 struct tm const *probe_tm = localtime (&probe);
3362 if (probe_tm && probe_tm->tm_zone
3363 && probe_tm->tm_isdst != pc.local_time_zone_table[0].value)
3366 pc.local_time_zone_table[1].name = probe_tm->tm_zone;
3367 pc.local_time_zone_table[1].type = tLOCAL_ZONE;
3368 pc.local_time_zone_table[1].value = probe_tm->tm_isdst;
3369 pc.local_time_zone_table[2].name = NULL;
3378 # if !HAVE_DECL_TZNAME
3379 extern char *tzname[];
3382 for (i = 0; i < 2; i++)
3384 pc.local_time_zone_table[i].name = tzname[i];
3385 pc.local_time_zone_table[i].type = tLOCAL_ZONE;
3386 pc.local_time_zone_table[i].value = i;
3388 pc.local_time_zone_table[i].name = NULL;
3391 pc.local_time_zone_table[0].name = NULL;
3395 if (pc.local_time_zone_table[0].name && pc.local_time_zone_table[1].name
3396 && ! strcmp (pc.local_time_zone_table[0].name,
3397 pc.local_time_zone_table[1].name))
3399 /* This locale uses the same abbreviation for standard and
3400 daylight times. So if we see that abbreviation, we don't
3401 know whether it's daylight time. */
3402 pc.local_time_zone_table[0].value = -1;
3403 pc.local_time_zone_table[1].name = NULL;
3406 if (yyparse (&pc) != 0)
3409 if (pc.timespec_seen)
3410 *result = pc.seconds;
3413 if (1 < (pc.times_seen | pc.dates_seen | pc.days_seen | pc.dsts_seen
3414 | (pc.local_zones_seen + pc.zones_seen)))
3417 tm.tm_year = to_year (pc.year) - TM_YEAR_BASE;
3418 tm.tm_mon = pc.month - 1;
3419 tm.tm_mday = pc.day;
3420 if (pc.times_seen || (pc.rels_seen && ! pc.dates_seen && ! pc.days_seen))
3422 tm.tm_hour = to_hour (pc.hour, pc.meridian);
3425 tm.tm_min = pc.minutes;
3426 tm.tm_sec = pc.seconds.tv_sec;
3430 tm.tm_hour = tm.tm_min = tm.tm_sec = 0;
3431 pc.seconds.tv_nsec = 0;
3434 /* Let mktime deduce tm_isdst if we have an absolute time stamp. */
3435 if (pc.dates_seen | pc.days_seen | pc.times_seen)
3438 /* But if the input explicitly specifies local time with or without
3439 DST, give mktime that information. */
3440 if (pc.local_zones_seen)
3441 tm.tm_isdst = pc.local_isdst;
3445 Start = mktime (&tm);
3447 if (! mktime_ok (&tm0, &tm, Start))
3449 if (! pc.zones_seen)
3453 /* Guard against falsely reporting errors near the time_t
3454 boundaries when parsing times in other time zones. For
3455 example, suppose the input string "1969-12-31 23:00:00 -0100",
3456 the current time zone is 8 hours ahead of UTC, and the min
3457 time_t value is 1970-01-01 00:00:00 UTC. Then the min
3458 localtime value is 1970-01-01 08:00:00, and mktime will
3459 therefore fail on 1969-12-31 23:00:00. To work around the
3460 problem, set the time zone to 1 hour behind UTC temporarily
3461 by setting TZ="XXX1:00" and try mktime again. */
3463 long int time_zone = pc.time_zone;
3464 long int abs_time_zone = time_zone < 0 ? - time_zone : time_zone;
3465 long int abs_time_zone_hour = abs_time_zone / 60;
3466 int abs_time_zone_min = abs_time_zone % 60;
3467 char tz1buf[sizeof "XXX+0:00"
3468 + sizeof pc.time_zone * CHAR_BIT / 3];
3469 if (!tz_was_altered)
3470 tz0 = get_tz (tz0buf);
3471 sprintf (tz1buf, "XXX%s%ld:%02d", &"-"[time_zone < 0],
3472 abs_time_zone_hour, abs_time_zone_min);
3473 if (setenv ("TZ", tz1buf, 1) != 0)
3475 tz_was_altered = true;
3477 Start = mktime (&tm);
3478 if (! mktime_ok (&tm0, &tm, Start))
3483 if (pc.days_seen && ! pc.dates_seen)
3485 tm.tm_mday += ((pc.day_number - tm.tm_wday + 7) % 7
3486 + 7 * (pc.day_ordinal
3487 - (0 < pc.day_ordinal
3488 && tm.tm_wday != pc.day_number)));
3490 Start = mktime (&tm);
3491 if (Start == (time_t) -1)
3495 /* Add relative date. */
3496 if (pc.rel.year | pc.rel.month | pc.rel.day)
3498 int year = tm.tm_year + pc.rel.year;
3499 int month = tm.tm_mon + pc.rel.month;
3500 int day = tm.tm_mday + pc.rel.day;
3501 if (((year < tm.tm_year) ^ (pc.rel.year < 0))
3502 | ((month < tm.tm_mon) ^ (pc.rel.month < 0))
3503 | ((day < tm.tm_mday) ^ (pc.rel.day < 0)))
3508 tm.tm_hour = tm0.tm_hour;
3509 tm.tm_min = tm0.tm_min;
3510 tm.tm_sec = tm0.tm_sec;
3511 tm.tm_isdst = tm0.tm_isdst;
3512 Start = mktime (&tm);
3513 if (Start == (time_t) -1)
3517 /* The only "output" of this if-block is an updated Start value,
3518 so this block must follow others that clobber Start. */
3521 long int delta = pc.time_zone * 60;
3523 #ifdef HAVE_TM_GMTOFF
3524 delta -= tm.tm_gmtoff;
3527 struct tm const *gmt = gmtime (&t);
3530 delta -= tm_diff (&tm, gmt);
3533 if ((Start < t1) != (delta < 0))
3534 goto fail; /* time_t overflow */
3538 /* Add relative hours, minutes, and seconds. On hosts that support
3539 leap seconds, ignore the possibility of leap seconds; e.g.,
3540 "+ 10 minutes" adds 600 seconds, even if one of them is a
3541 leap second. Typically this is not what the user wants, but it's
3542 too hard to do it the other way, because the time zone indicator
3543 must be applied before relative times, and if mktime is applied
3544 again the time zone will be lost. */
3546 long int sum_ns = pc.seconds.tv_nsec + pc.rel.ns;
3547 long int normalized_ns = (sum_ns % BILLION + BILLION) % BILLION;
3549 long int d1 = 60 * 60 * pc.rel.hour;
3550 time_t t1 = t0 + d1;
3551 long int d2 = 60 * pc.rel.minutes;
3552 time_t t2 = t1 + d2;
3553 long_time_t d3 = pc.rel.seconds;
3554 long_time_t t3 = t2 + d3;
3555 long int d4 = (sum_ns - normalized_ns) / BILLION;
3556 long_time_t t4 = t3 + d4;
3559 if ((d1 / (60 * 60) ^ pc.rel.hour)
3560 | (d2 / 60 ^ pc.rel.minutes)
3561 | ((t1 < t0) ^ (d1 < 0))
3562 | ((t2 < t1) ^ (d2 < 0))
3563 | ((t3 < t2) ^ (d3 < 0))
3564 | ((t4 < t3) ^ (d4 < 0))
3568 result->tv_sec = t5;
3569 result->tv_nsec = normalized_ns;
3579 ok &= (tz0 ? setenv ("TZ", tz0, 1) : unsetenv ("TZ")) == 0;
3588 main (int ac, char **av)
3592 printf ("Enter date, or blank line to exit.\n\t> ");
3595 buff[BUFSIZ - 1] = '\0';
3596 while (fgets (buff, BUFSIZ - 1, stdin) && buff[0])
3599 struct tm const *tm;
3600 if (! parse_datetime (&d, buff, NULL))
3601 printf ("Bad format - couldn't convert.\n");
3602 else if (! (tm = localtime (&d.tv_sec)))
3604 long int sec = d.tv_sec;
3605 printf ("localtime (%ld) failed\n", sec);
3610 printf ("%04ld-%02d-%02d %02d:%02d:%02d.%09d\n",
3611 tm->tm_year + 1900L, tm->tm_mon + 1, tm->tm_mday,
3612 tm->tm_hour, tm->tm_min, tm->tm_sec, ns);