1 /* A Bison parser, made by GNU Bison 2.5. */
3 /* Bison implementation for Yacc-like parsers in C
5 Copyright (C) 1984, 1989-1990, 2000-2011 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"
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-2014 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"
359 /* Enabling traces. */
364 /* Enabling verbose error messages. */
365 #ifdef YYERROR_VERBOSE
366 # undef YYERROR_VERBOSE
367 # define YYERROR_VERBOSE 1
369 # define YYERROR_VERBOSE 0
372 /* Enabling the token table. */
373 #ifndef YYTOKEN_TABLE
374 # define YYTOKEN_TABLE 0
381 /* Put the tokens into the symbol table, so that GDB and other debuggers
402 tSDECIMAL_NUMBER = 276,
403 tUDECIMAL_NUMBER = 277
409 #define tYEAR_UNIT 260
410 #define tMONTH_UNIT 261
411 #define tHOUR_UNIT 262
412 #define tMINUTE_UNIT 263
413 #define tSEC_UNIT 264
414 #define tDAY_UNIT 265
415 #define tDAY_SHIFT 266
418 #define tLOCAL_ZONE 269
419 #define tMERIDIAN 270
425 #define tSDECIMAL_NUMBER 276
426 #define tUDECIMAL_NUMBER 277
431 #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
432 typedef union YYSTYPE
435 /* Line 293 of yacc.c */
436 #line 297 "parse-datetime.y"
440 struct timespec timespec;
445 /* Line 293 of yacc.c */
446 #line 447 "parse-datetime.c"
448 # define YYSTYPE_IS_TRIVIAL 1
449 # define yystype YYSTYPE /* obsolescent; will be withdrawn */
450 # define YYSTYPE_IS_DECLARED 1
454 /* Copy the second part of user declarations. */
457 /* Line 343 of yacc.c */
458 #line 459 "parse-datetime.c"
465 typedef YYTYPE_UINT8 yytype_uint8;
467 typedef unsigned char yytype_uint8;
471 typedef YYTYPE_INT8 yytype_int8;
472 #elif (defined __STDC__ || defined __C99__FUNC__ \
473 || defined __cplusplus || defined _MSC_VER)
474 typedef signed char yytype_int8;
476 typedef short int yytype_int8;
480 typedef YYTYPE_UINT16 yytype_uint16;
482 typedef unsigned short int yytype_uint16;
486 typedef YYTYPE_INT16 yytype_int16;
488 typedef short int yytype_int16;
492 # ifdef __SIZE_TYPE__
493 # define YYSIZE_T __SIZE_TYPE__
494 # elif defined size_t
495 # define YYSIZE_T size_t
496 # elif ! defined YYSIZE_T && (defined __STDC__ || defined __C99__FUNC__ \
497 || defined __cplusplus || defined _MSC_VER)
498 # include <stddef.h> /* INFRINGES ON USER NAME SPACE */
499 # define YYSIZE_T size_t
501 # define YYSIZE_T unsigned int
505 #define YYSIZE_MAXIMUM ((YYSIZE_T) -1)
508 # if defined YYENABLE_NLS && YYENABLE_NLS
510 # include <libintl.h> /* INFRINGES ON USER NAME SPACE */
511 # define YY_(msgid) dgettext ("bison-runtime", msgid)
515 # define YY_(msgid) msgid
519 /* Suppress unused-variable warnings by "using" E. */
520 #if ! defined lint || defined __GNUC__
521 # define YYUSE(e) ((void) (e))
523 # define YYUSE(e) /* empty */
526 /* Identity function, used to suppress warnings about constant conditions. */
530 #if (defined __STDC__ || defined __C99__FUNC__ \
531 || defined __cplusplus || defined _MSC_VER)
544 #if ! defined yyoverflow || YYERROR_VERBOSE
546 /* The parser invokes alloca or malloc; define the necessary symbols. */
548 # ifdef YYSTACK_USE_ALLOCA
549 # if YYSTACK_USE_ALLOCA
551 # define YYSTACK_ALLOC __builtin_alloca
552 # elif defined __BUILTIN_VA_ARG_INCR
553 # include <alloca.h> /* INFRINGES ON USER NAME SPACE */
555 # define YYSTACK_ALLOC __alloca
556 # elif defined _MSC_VER
557 # include <malloc.h> /* INFRINGES ON USER NAME SPACE */
558 # define alloca _alloca
560 # define YYSTACK_ALLOC alloca
561 # if ! defined _ALLOCA_H && ! defined EXIT_SUCCESS && (defined __STDC__ || defined __C99__FUNC__ \
562 || defined __cplusplus || defined _MSC_VER)
563 # include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
564 # ifndef EXIT_SUCCESS
565 # define EXIT_SUCCESS 0
572 # ifdef YYSTACK_ALLOC
573 /* Pacify GCC's `empty if-body' warning. */
574 # define YYSTACK_FREE(Ptr) do { /* empty */; } while (YYID (0))
575 # ifndef YYSTACK_ALLOC_MAXIMUM
576 /* The OS might guarantee only one guard page at the bottom of the stack,
577 and a page size can be as small as 4096 bytes. So we cannot safely
578 invoke alloca (N) if N exceeds 4096. Use a slightly smaller number
579 to allow for a few compiler-allocated temporary stack slots. */
580 # define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */
583 # define YYSTACK_ALLOC YYMALLOC
584 # define YYSTACK_FREE YYFREE
585 # ifndef YYSTACK_ALLOC_MAXIMUM
586 # define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM
588 # if (defined __cplusplus && ! defined EXIT_SUCCESS \
589 && ! ((defined YYMALLOC || defined malloc) \
590 && (defined YYFREE || defined free)))
591 # include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
592 # ifndef EXIT_SUCCESS
593 # define EXIT_SUCCESS 0
597 # define YYMALLOC malloc
598 # if ! defined malloc && ! defined EXIT_SUCCESS && (defined __STDC__ || defined __C99__FUNC__ \
599 || defined __cplusplus || defined _MSC_VER)
600 void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */
605 # if ! defined free && ! defined EXIT_SUCCESS && (defined __STDC__ || defined __C99__FUNC__ \
606 || defined __cplusplus || defined _MSC_VER)
607 void free (void *); /* INFRINGES ON USER NAME SPACE */
611 #endif /* ! defined yyoverflow || YYERROR_VERBOSE */
614 #if (! defined yyoverflow \
615 && (! defined __cplusplus \
616 || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
618 /* A type that is properly aligned for any stack member. */
621 yytype_int16 yyss_alloc;
625 /* The size of the maximum gap between one aligned stack and the next. */
626 # define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1)
628 /* The size of an array large to enough to hold all stacks, each with
630 # define YYSTACK_BYTES(N) \
631 ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE)) \
632 + YYSTACK_GAP_MAXIMUM)
634 # define YYCOPY_NEEDED 1
636 /* Relocate STACK from its old location to the new one. The
637 local variables YYSIZE and YYSTACKSIZE give the old and new number of
638 elements in the stack, and YYPTR gives the new location of the
639 stack. Advance YYPTR to a properly aligned location for the next
641 # define YYSTACK_RELOCATE(Stack_alloc, Stack) \
644 YYSIZE_T yynewbytes; \
645 YYCOPY (&yyptr->Stack_alloc, Stack, yysize); \
646 Stack = &yyptr->Stack_alloc; \
647 yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \
648 yyptr += yynewbytes / sizeof (*yyptr); \
654 #if defined YYCOPY_NEEDED && YYCOPY_NEEDED
655 /* Copy COUNT objects from FROM to TO. The source and destination do
658 # if defined __GNUC__ && 1 < __GNUC__
659 # define YYCOPY(To, From, Count) \
660 __builtin_memcpy (To, From, (Count) * sizeof (*(From)))
662 # define YYCOPY(To, From, Count) \
666 for (yyi = 0; yyi < (Count); yyi++) \
667 (To)[yyi] = (From)[yyi]; \
672 #endif /* !YYCOPY_NEEDED */
674 /* YYFINAL -- State number of the termination state. */
676 /* YYLAST -- Last index in YYTABLE. */
679 /* YYNTOKENS -- Number of terminals. */
681 /* YYNNTS -- Number of nonterminals. */
683 /* YYNRULES -- Number of rules. */
685 /* YYNRULES -- Number of states. */
686 #define YYNSTATES 114
688 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
690 #define YYMAXUTOK 277
692 #define YYTRANSLATE(YYX) \
693 ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
695 /* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */
696 static const yytype_uint8 yytranslate[] =
698 0, 2, 2, 2, 2, 2, 2, 2, 2, 2,
699 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
700 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
701 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
702 2, 2, 2, 2, 26, 2, 2, 27, 2, 2,
703 2, 2, 2, 2, 2, 2, 2, 2, 25, 2,
704 2, 2, 2, 2, 23, 2, 2, 2, 2, 2,
705 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
706 2, 2, 2, 2, 24, 2, 2, 2, 2, 2,
707 2, 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, 2, 2, 2, 2, 2, 2,
712 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
713 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
714 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
715 2, 2, 2, 2, 2, 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, 1, 2, 3, 4,
724 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
725 15, 16, 17, 18, 19, 20, 21, 22
729 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
731 static const yytype_uint8 yyprhs[] =
733 0, 0, 3, 5, 7, 10, 11, 14, 16, 18,
734 20, 22, 24, 26, 28, 30, 32, 34, 38, 41,
735 46, 53, 55, 58, 63, 70, 71, 73, 76, 78,
736 81, 83, 85, 88, 91, 95, 97, 100, 102, 105,
737 108, 111, 115, 121, 125, 129, 132, 137, 140, 144,
738 146, 150, 153, 155, 157, 160, 163, 165, 168, 171,
739 173, 176, 179, 181, 184, 187, 189, 192, 195, 197,
740 200, 203, 206, 209, 211, 213, 216, 219, 222, 225,
741 228, 231, 233, 235, 237, 239, 241, 243, 245, 247,
745 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
746 static const yytype_int8 yyrhs[] =
748 29, 0, -1, 30, -1, 31, -1, 23, 48, -1,
749 -1, 31, 32, -1, 33, -1, 35, -1, 39, -1,
750 40, -1, 42, -1, 41, -1, 44, -1, 51, -1,
751 52, -1, 34, -1, 43, 24, 36, -1, 20, 15,
752 -1, 20, 25, 20, 15, -1, 20, 25, 20, 25,
753 50, 15, -1, 36, -1, 20, 38, -1, 20, 25,
754 20, 37, -1, 20, 25, 20, 25, 50, 37, -1,
755 -1, 38, -1, 19, 53, -1, 14, -1, 14, 4,
756 -1, 18, -1, 24, -1, 18, 46, -1, 24, 46,
757 -1, 18, 19, 53, -1, 13, -1, 18, 4, -1,
758 12, -1, 12, 26, -1, 17, 12, -1, 20, 12,
759 -1, 20, 27, 20, -1, 20, 27, 20, 27, 20,
760 -1, 20, 16, 19, -1, 16, 19, 19, -1, 16,
761 20, -1, 16, 20, 26, 20, -1, 20, 16, -1,
762 20, 16, 20, -1, 43, -1, 20, 19, 19, -1,
763 45, 3, -1, 45, -1, 47, -1, 17, 5, -1,
764 20, 5, -1, 5, -1, 17, 6, -1, 20, 6,
765 -1, 6, -1, 17, 10, -1, 20, 10, -1, 10,
766 -1, 17, 7, -1, 20, 7, -1, 7, -1, 17,
767 8, -1, 20, 8, -1, 8, -1, 17, 9, -1,
768 20, 9, -1, 21, 9, -1, 22, 9, -1, 9,
769 -1, 46, -1, 19, 5, -1, 19, 6, -1, 19,
770 10, -1, 19, 7, -1, 19, 8, -1, 19, 9,
771 -1, 11, -1, 49, -1, 50, -1, 21, -1, 19,
772 -1, 22, -1, 20, -1, 20, -1, 20, 46, -1,
776 /* YYRLINE[YYN] -- source line where rule number YYN was defined. */
777 static const yytype_uint16 yyrline[] =
779 0, 324, 324, 325, 329, 336, 338, 342, 344, 346,
780 348, 350, 352, 354, 355, 356, 360, 364, 368, 373,
781 378, 383, 387, 392, 397, 404, 406, 410, 418, 423,
782 433, 435, 437, 440, 443, 445, 447, 452, 457, 462,
783 467, 475, 480, 500, 508, 516, 521, 527, 532, 538,
784 542, 552, 554, 556, 561, 563, 565, 567, 569, 571,
785 573, 575, 577, 579, 581, 583, 585, 587, 589, 591,
786 593, 595, 597, 599, 601, 605, 607, 609, 611, 613,
787 615, 620, 624, 624, 627, 628, 633, 634, 639, 644,
792 #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
793 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
794 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
795 static const char *const yytname[] =
797 "$end", "error", "$undefined", "tAGO", "tDST", "tYEAR_UNIT",
798 "tMONTH_UNIT", "tHOUR_UNIT", "tMINUTE_UNIT", "tSEC_UNIT", "tDAY_UNIT",
799 "tDAY_SHIFT", "tDAY", "tDAYZONE", "tLOCAL_ZONE", "tMERIDIAN", "tMONTH",
800 "tORDINAL", "tZONE", "tSNUMBER", "tUNUMBER", "tSDECIMAL_NUMBER",
801 "tUDECIMAL_NUMBER", "'@'", "'T'", "':'", "','", "'/'", "$accept", "spec",
802 "timespec", "items", "item", "datetime", "iso_8601_datetime", "time",
803 "iso_8601_time", "o_zone_offset", "zone_offset", "local_zone", "zone",
804 "day", "date", "iso_8601_date", "rel", "relunit", "relunit_snumber",
805 "dayshift", "seconds", "signed_seconds", "unsigned_seconds", "number",
806 "hybrid", "o_colon_minutes", 0
811 /* YYTOKNUM[YYLEX-NUM] -- Internal token number corresponding to
813 static const yytype_uint16 yytoknum[] =
815 0, 256, 257, 258, 259, 260, 261, 262, 263, 264,
816 265, 266, 267, 268, 269, 270, 271, 272, 273, 274,
817 275, 276, 277, 64, 84, 58, 44, 47
821 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
822 static const yytype_uint8 yyr1[] =
824 0, 28, 29, 29, 30, 31, 31, 32, 32, 32,
825 32, 32, 32, 32, 32, 32, 33, 34, 35, 35,
826 35, 35, 36, 36, 36, 37, 37, 38, 39, 39,
827 40, 40, 40, 40, 40, 40, 40, 41, 41, 41,
828 41, 42, 42, 42, 42, 42, 42, 42, 42, 42,
829 43, 44, 44, 44, 45, 45, 45, 45, 45, 45,
830 45, 45, 45, 45, 45, 45, 45, 45, 45, 45,
831 45, 45, 45, 45, 45, 46, 46, 46, 46, 46,
832 46, 47, 48, 48, 49, 49, 50, 50, 51, 52,
836 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
837 static const yytype_uint8 yyr2[] =
839 0, 2, 1, 1, 2, 0, 2, 1, 1, 1,
840 1, 1, 1, 1, 1, 1, 1, 3, 2, 4,
841 6, 1, 2, 4, 6, 0, 1, 2, 1, 2,
842 1, 1, 2, 2, 3, 1, 2, 1, 2, 2,
843 2, 3, 5, 3, 3, 2, 4, 2, 3, 1,
844 3, 2, 1, 1, 2, 2, 1, 2, 2, 1,
845 2, 2, 1, 2, 2, 1, 2, 2, 1, 2,
846 2, 2, 2, 1, 1, 2, 2, 2, 2, 2,
847 2, 1, 1, 1, 1, 1, 1, 1, 1, 2,
851 /* YYDEFACT[STATE-NAME] -- Default reduction number in state STATE-NUM.
852 Performed when YYTABLE doesn't specify something else to do. Zero
853 means the default is an error. */
854 static const yytype_uint8 yydefact[] =
856 5, 0, 0, 2, 3, 85, 87, 84, 86, 4,
857 82, 83, 1, 56, 59, 65, 68, 73, 62, 81,
858 37, 35, 28, 0, 0, 30, 0, 88, 0, 0,
859 31, 6, 7, 16, 8, 21, 9, 10, 12, 11,
860 49, 13, 52, 74, 53, 14, 15, 38, 29, 0,
861 45, 54, 57, 63, 66, 69, 60, 39, 36, 90,
862 32, 75, 76, 78, 79, 80, 77, 55, 58, 64,
863 67, 70, 61, 40, 18, 47, 90, 0, 0, 22,
864 89, 71, 72, 33, 0, 51, 44, 0, 0, 34,
865 43, 48, 50, 27, 25, 41, 0, 17, 46, 91,
866 19, 90, 0, 23, 26, 0, 0, 25, 42, 25,
870 /* YYDEFGOTO[NTERM-NUM]. */
871 static const yytype_int8 yydefgoto[] =
873 -1, 2, 3, 4, 31, 32, 33, 34, 35, 103,
874 104, 36, 37, 38, 39, 40, 41, 42, 43, 44,
875 9, 10, 11, 45, 46, 93
878 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
880 #define YYPACT_NINF -93
881 static const yytype_int8 yypact[] =
883 38, 27, 77, -93, 46, -93, -93, -93, -93, -93,
884 -93, -93, -93, -93, -93, -93, -93, -93, -93, -93,
885 62, -93, 82, -3, 66, 3, 74, -4, 83, 84,
886 75, -93, -93, -93, -93, -93, -93, -93, -93, -93,
887 71, -93, 93, -93, -93, -93, -93, -93, -93, 78,
888 72, -93, -93, -93, -93, -93, -93, -93, -93, 25,
889 -93, -93, -93, -93, -93, -93, -93, -93, -93, -93,
890 -93, -93, -93, -93, -93, 21, 19, 79, 80, -93,
891 -93, -93, -93, -93, 81, -93, -93, 85, 86, -93,
892 -93, -93, -93, -93, -6, 76, 17, -93, -93, -93,
893 -93, 87, 69, -93, -93, 88, 89, -1, -93, 18,
897 /* YYPGOTO[NTERM-NUM]. */
898 static const yytype_int8 yypgoto[] =
900 -93, -93, -93, -93, -93, -93, -93, -93, 20, -68,
901 -27, -93, -93, -93, -93, -93, -93, -93, 60, -93,
902 -93, -93, -92, -93, -93, 43
905 /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
906 positive, shift that token. If negative, reduce the rule which
907 number is the opposite. If YYTABLE_NINF, syntax error. */
908 #define YYTABLE_NINF -1
909 static const yytype_uint8 yytable[] =
911 79, 67, 68, 69, 70, 71, 72, 58, 73, 100,
912 107, 74, 75, 101, 110, 76, 49, 50, 101, 102,
913 113, 77, 59, 78, 61, 62, 63, 64, 65, 66,
914 61, 62, 63, 64, 65, 66, 101, 101, 92, 111,
915 90, 91, 106, 112, 88, 111, 5, 6, 7, 8,
916 88, 13, 14, 15, 16, 17, 18, 19, 20, 21,
917 22, 1, 23, 24, 25, 26, 27, 28, 29, 79,
918 30, 51, 52, 53, 54, 55, 56, 12, 57, 61,
919 62, 63, 64, 65, 66, 60, 48, 80, 47, 6,
920 83, 8, 81, 82, 26, 84, 85, 86, 87, 94,
921 95, 96, 89, 105, 97, 98, 99, 0, 108, 109,
925 #define yypact_value_is_default(yystate) \
928 #define yytable_value_is_error(yytable_value) \
931 static const yytype_int8 yycheck[] =
933 27, 5, 6, 7, 8, 9, 10, 4, 12, 15,
934 102, 15, 16, 19, 15, 19, 19, 20, 19, 25,
935 112, 25, 19, 27, 5, 6, 7, 8, 9, 10,
936 5, 6, 7, 8, 9, 10, 19, 19, 19, 107,
937 19, 20, 25, 25, 25, 113, 19, 20, 21, 22,
938 25, 5, 6, 7, 8, 9, 10, 11, 12, 13,
939 14, 23, 16, 17, 18, 19, 20, 21, 22, 96,
940 24, 5, 6, 7, 8, 9, 10, 0, 12, 5,
941 6, 7, 8, 9, 10, 25, 4, 27, 26, 20,
942 30, 22, 9, 9, 19, 24, 3, 19, 26, 20,
943 20, 20, 59, 27, 84, 20, 20, -1, 20, 20,
947 /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
948 symbol of state STATE-NUM. */
949 static const yytype_uint8 yystos[] =
951 0, 23, 29, 30, 31, 19, 20, 21, 22, 48,
952 49, 50, 0, 5, 6, 7, 8, 9, 10, 11,
953 12, 13, 14, 16, 17, 18, 19, 20, 21, 22,
954 24, 32, 33, 34, 35, 36, 39, 40, 41, 42,
955 43, 44, 45, 46, 47, 51, 52, 26, 4, 19,
956 20, 5, 6, 7, 8, 9, 10, 12, 4, 19,
957 46, 5, 6, 7, 8, 9, 10, 5, 6, 7,
958 8, 9, 10, 12, 15, 16, 19, 25, 27, 38,
959 46, 9, 9, 46, 24, 3, 19, 26, 25, 53,
960 19, 20, 19, 53, 20, 20, 20, 36, 20, 20,
961 15, 19, 25, 37, 38, 27, 25, 50, 20, 20,
965 #define yyerrok (yyerrstatus = 0)
966 #define yyclearin (yychar = YYEMPTY)
970 #define YYACCEPT goto yyacceptlab
971 #define YYABORT goto yyabortlab
972 #define YYERROR goto yyerrorlab
975 /* Like YYERROR except do call yyerror. This remains here temporarily
976 to ease the transition to the new meaning of YYERROR, for GCC.
977 Once GCC version 2 has supplanted version 1, this can go. However,
978 YYFAIL appears to be in use. Nevertheless, it is formally deprecated
979 in Bison 2.4.2's NEWS entry, where a plan to phase it out is
982 #define YYFAIL goto yyerrlab
984 /* This is here to suppress warnings from the GCC cpp's
985 -Wunused-macros. Normally we don't worry about that warning, but
986 some users do, and we want to make it easy for users to remove
987 YYFAIL uses, which will produce warnings from Bison 2.5. */
990 #define YYRECOVERING() (!!yyerrstatus)
992 #define YYBACKUP(Token, Value) \
994 if (yychar == YYEMPTY && yylen == 1) \
1003 yyerror (pc, YY_("syntax error: cannot back up")); \
1010 #define YYERRCODE 256
1013 /* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
1014 If N is 0, then set CURRENT to the empty location which ends
1015 the previous symbol: RHS[0] (always defined). */
1017 #define YYRHSLOC(Rhs, K) ((Rhs)[K])
1018 #ifndef YYLLOC_DEFAULT
1019 # define YYLLOC_DEFAULT(Current, Rhs, N) \
1023 (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \
1024 (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \
1025 (Current).last_line = YYRHSLOC (Rhs, N).last_line; \
1026 (Current).last_column = YYRHSLOC (Rhs, N).last_column; \
1030 (Current).first_line = (Current).last_line = \
1031 YYRHSLOC (Rhs, 0).last_line; \
1032 (Current).first_column = (Current).last_column = \
1033 YYRHSLOC (Rhs, 0).last_column; \
1039 /* This macro is provided for backward compatibility. */
1041 #ifndef YY_LOCATION_PRINT
1042 # define YY_LOCATION_PRINT(File, Loc) ((void) 0)
1046 /* YYLEX -- calling `yylex' with the right arguments. */
1049 # define YYLEX yylex (&yylval, YYLEX_PARAM)
1051 # define YYLEX yylex (&yylval, pc)
1054 /* Enable debugging if requested. */
1058 # include <stdio.h> /* INFRINGES ON USER NAME SPACE */
1059 # define YYFPRINTF fprintf
1062 # define YYDPRINTF(Args) \
1068 # define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
1072 YYFPRINTF (stderr, "%s ", Title); \
1073 yy_symbol_print (stderr, \
1075 YYFPRINTF (stderr, "\n"); \
1080 /*--------------------------------.
1081 | Print this symbol on YYOUTPUT. |
1082 `--------------------------------*/
1085 #if (defined __STDC__ || defined __C99__FUNC__ \
1086 || defined __cplusplus || defined _MSC_VER)
1088 yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, parser_control *pc)
1091 yy_symbol_value_print (yyoutput, yytype, yyvaluep, pc)
1094 YYSTYPE const * const yyvaluep;
1102 if (yytype < YYNTOKENS)
1103 YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep);
1115 /*--------------------------------.
1116 | Print this symbol on YYOUTPUT. |
1117 `--------------------------------*/
1119 #if (defined __STDC__ || defined __C99__FUNC__ \
1120 || defined __cplusplus || defined _MSC_VER)
1122 yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, parser_control *pc)
1125 yy_symbol_print (yyoutput, yytype, yyvaluep, pc)
1128 YYSTYPE const * const yyvaluep;
1132 if (yytype < YYNTOKENS)
1133 YYFPRINTF (yyoutput, "token %s (", yytname[yytype]);
1135 YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]);
1137 yy_symbol_value_print (yyoutput, yytype, yyvaluep, pc);
1138 YYFPRINTF (yyoutput, ")");
1141 /*------------------------------------------------------------------.
1142 | yy_stack_print -- Print the state stack from its BOTTOM up to its |
1144 `------------------------------------------------------------------*/
1146 #if (defined __STDC__ || defined __C99__FUNC__ \
1147 || defined __cplusplus || defined _MSC_VER)
1149 yy_stack_print (yytype_int16 *yybottom, yytype_int16 *yytop)
1152 yy_stack_print (yybottom, yytop)
1153 yytype_int16 *yybottom;
1154 yytype_int16 *yytop;
1157 YYFPRINTF (stderr, "Stack now");
1158 for (; yybottom <= yytop; yybottom++)
1160 int yybot = *yybottom;
1161 YYFPRINTF (stderr, " %d", yybot);
1163 YYFPRINTF (stderr, "\n");
1166 # define YY_STACK_PRINT(Bottom, Top) \
1169 yy_stack_print ((Bottom), (Top)); \
1173 /*------------------------------------------------.
1174 | Report that the YYRULE is going to be reduced. |
1175 `------------------------------------------------*/
1177 #if (defined __STDC__ || defined __C99__FUNC__ \
1178 || defined __cplusplus || defined _MSC_VER)
1180 yy_reduce_print (YYSTYPE *yyvsp, int yyrule, parser_control *pc)
1183 yy_reduce_print (yyvsp, yyrule, pc)
1189 int yynrhs = yyr2[yyrule];
1191 unsigned long int yylno = yyrline[yyrule];
1192 YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n",
1194 /* The symbols being reduced. */
1195 for (yyi = 0; yyi < yynrhs; yyi++)
1197 YYFPRINTF (stderr, " $%d = ", yyi + 1);
1198 yy_symbol_print (stderr, yyrhs[yyprhs[yyrule] + yyi],
1199 &(yyvsp[(yyi + 1) - (yynrhs)])
1201 YYFPRINTF (stderr, "\n");
1205 # define YY_REDUCE_PRINT(Rule) \
1208 yy_reduce_print (yyvsp, Rule, pc); \
1211 /* Nonzero means print parse trace. It is left uninitialized so that
1212 multiple parsers can coexist. */
1214 #else /* !YYDEBUG */
1215 # define YYDPRINTF(Args)
1216 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
1217 # define YY_STACK_PRINT(Bottom, Top)
1218 # define YY_REDUCE_PRINT(Rule)
1219 #endif /* !YYDEBUG */
1222 /* YYINITDEPTH -- initial size of the parser's stacks. */
1224 # define YYINITDEPTH 200
1227 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
1228 if the built-in stack extension method is used).
1230 Do not make this value too large; the results are undefined if
1231 YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH)
1232 evaluated with infinite-precision integer arithmetic. */
1235 # define YYMAXDEPTH 10000
1242 # if defined __GLIBC__ && defined _STRING_H
1243 # define yystrlen strlen
1245 /* Return the length of YYSTR. */
1246 #if (defined __STDC__ || defined __C99__FUNC__ \
1247 || defined __cplusplus || defined _MSC_VER)
1249 yystrlen (const char *yystr)
1257 for (yylen = 0; yystr[yylen]; yylen++)
1265 # if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
1266 # define yystpcpy stpcpy
1268 /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
1270 #if (defined __STDC__ || defined __C99__FUNC__ \
1271 || defined __cplusplus || defined _MSC_VER)
1273 yystpcpy (char *yydest, const char *yysrc)
1276 yystpcpy (yydest, yysrc)
1282 const char *yys = yysrc;
1284 while ((*yyd++ = *yys++) != '\0')
1293 /* Copy to YYRES the contents of YYSTR after stripping away unnecessary
1294 quotes and backslashes, so that it's suitable for yyerror. The
1295 heuristic is that double-quoting is unnecessary unless the string
1296 contains an apostrophe, a comma, or backslash (other than
1297 backslash-backslash). YYSTR is taken from yytname. If YYRES is
1298 null, do not copy; instead, return the length of what the result
1301 yytnamerr (char *yyres, const char *yystr)
1306 char const *yyp = yystr;
1313 goto do_not_strip_quotes;
1317 goto do_not_strip_quotes;
1330 do_not_strip_quotes: ;
1334 return yystrlen (yystr);
1336 return yystpcpy (yyres, yystr) - yyres;
1340 /* Copy into *YYMSG, which is of size *YYMSG_ALLOC, an error message
1341 about the unexpected token YYTOKEN for the state stack whose top is
1344 Return 0 if *YYMSG was successfully written. Return 1 if *YYMSG is
1345 not large enough to hold the message. In that case, also set
1346 *YYMSG_ALLOC to the required number of bytes. Return 2 if the
1347 required number of bytes is too large to store. */
1349 yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg,
1350 yytype_int16 *yyssp, int yytoken)
1352 YYSIZE_T yysize0 = yytnamerr (0, yytname[yytoken]);
1353 YYSIZE_T yysize = yysize0;
1355 enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
1356 /* Internationalized format string. */
1357 const char *yyformat = 0;
1358 /* Arguments of yyformat. */
1359 char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
1360 /* Number of reported tokens (one for the "unexpected", one per
1364 /* There are many possibilities here to consider:
1365 - Assume YYFAIL is not used. It's too flawed to consider. See
1366 <http://lists.gnu.org/archive/html/bison-patches/2009-12/msg00024.html>
1367 for details. YYERROR is fine as it does not invoke this
1369 - If this state is a consistent state with a default action, then
1370 the only way this function was invoked is if the default action
1371 is an error action. In that case, don't check for expected
1372 tokens because there are none.
1373 - The only way there can be no lookahead present (in yychar) is if
1374 this state is a consistent state with a default action. Thus,
1375 detecting the absence of a lookahead is sufficient to determine
1376 that there is no unexpected or expected token to report. In that
1377 case, just report a simple "syntax error".
1378 - Don't assume there isn't a lookahead just because this state is a
1379 consistent state with a default action. There might have been a
1380 previous inconsistent state, consistent state with a non-default
1381 action, or user semantic action that manipulated yychar.
1382 - Of course, the expected token list depends on states to have
1383 correct lookahead information, and it depends on the parser not
1384 to perform extra reductions after fetching a lookahead from the
1385 scanner and before detecting a syntax error. Thus, state merging
1386 (from LALR or IELR) and default reductions corrupt the expected
1387 token list. However, the list is correct for canonical LR with
1388 one exception: it will still contain any token that will not be
1389 accepted due to an error action in a later state.
1391 if (yytoken != YYEMPTY)
1393 int yyn = yypact[*yyssp];
1394 yyarg[yycount++] = yytname[yytoken];
1395 if (!yypact_value_is_default (yyn))
1397 /* Start YYX at -YYN if negative to avoid negative indexes in
1398 YYCHECK. In other words, skip the first -YYN actions for
1399 this state because they are default actions. */
1400 int yyxbegin = yyn < 0 ? -yyn : 0;
1401 /* Stay within bounds of both yycheck and yytname. */
1402 int yychecklim = YYLAST - yyn + 1;
1403 int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
1406 for (yyx = yyxbegin; yyx < yyxend; ++yyx)
1407 if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR
1408 && !yytable_value_is_error (yytable[yyx + yyn]))
1410 if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
1416 yyarg[yycount++] = yytname[yyx];
1417 yysize1 = yysize + yytnamerr (0, yytname[yyx]);
1418 if (! (yysize <= yysize1
1419 && yysize1 <= YYSTACK_ALLOC_MAXIMUM))
1428 # define YYCASE_(N, S) \
1432 YYCASE_(0, YY_("syntax error"));
1433 YYCASE_(1, YY_("syntax error, unexpected %s"));
1434 YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s"));
1435 YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s"));
1436 YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s"));
1437 YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"));
1441 yysize1 = yysize + yystrlen (yyformat);
1442 if (! (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM))
1446 if (*yymsg_alloc < yysize)
1448 *yymsg_alloc = 2 * yysize;
1449 if (! (yysize <= *yymsg_alloc
1450 && *yymsg_alloc <= YYSTACK_ALLOC_MAXIMUM))
1451 *yymsg_alloc = YYSTACK_ALLOC_MAXIMUM;
1455 /* Avoid sprintf, as that infringes on the user's name space.
1456 Don't have undefined behavior even if the translation
1457 produced a string with the wrong number of "%s"s. */
1461 while ((*yyp = *yyformat) != '\0')
1462 if (*yyp == '%' && yyformat[1] == 's' && yyi < yycount)
1464 yyp += yytnamerr (yyp, yyarg[yyi++]);
1475 #endif /* YYERROR_VERBOSE */
1477 /*-----------------------------------------------.
1478 | Release the memory associated to this symbol. |
1479 `-----------------------------------------------*/
1482 #if (defined __STDC__ || defined __C99__FUNC__ \
1483 || defined __cplusplus || defined _MSC_VER)
1485 yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep, parser_control *pc)
1488 yydestruct (yymsg, yytype, yyvaluep, pc)
1500 YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
1511 /* Prevent warnings from -Wmissing-prototypes. */
1512 #ifdef YYPARSE_PARAM
1513 #if defined __STDC__ || defined __cplusplus
1514 int yyparse (void *YYPARSE_PARAM);
1518 #else /* ! YYPARSE_PARAM */
1519 #if defined __STDC__ || defined __cplusplus
1520 int yyparse (parser_control *pc);
1524 #endif /* ! YYPARSE_PARAM */
1531 #ifdef YYPARSE_PARAM
1532 #if (defined __STDC__ || defined __C99__FUNC__ \
1533 || defined __cplusplus || defined _MSC_VER)
1535 yyparse (void *YYPARSE_PARAM)
1538 yyparse (YYPARSE_PARAM)
1539 void *YYPARSE_PARAM;
1541 #else /* ! YYPARSE_PARAM */
1542 #if (defined __STDC__ || defined __C99__FUNC__ \
1543 || defined __cplusplus || defined _MSC_VER)
1545 yyparse (parser_control *pc)
1553 /* The lookahead symbol. */
1556 /* The semantic value of the lookahead symbol. */
1559 /* Number of syntax errors so far. */
1563 /* Number of tokens to shift before error messages enabled. */
1566 /* The stacks and their tools:
1567 `yyss': related to states.
1568 `yyvs': related to semantic values.
1570 Refer to the stacks thru separate pointers, to allow yyoverflow
1571 to reallocate them elsewhere. */
1573 /* The state stack. */
1574 yytype_int16 yyssa[YYINITDEPTH];
1576 yytype_int16 *yyssp;
1578 /* The semantic value stack. */
1579 YYSTYPE yyvsa[YYINITDEPTH];
1583 YYSIZE_T yystacksize;
1587 /* Lookahead token as an internal (translated) token number. */
1589 /* The variables used to return semantic value and location from the
1594 /* Buffer for error messages, and its allocated size. */
1596 char *yymsg = yymsgbuf;
1597 YYSIZE_T yymsg_alloc = sizeof yymsgbuf;
1600 #define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N))
1602 /* The number of symbols on the RHS of the reduced rule.
1603 Keep to zero when no symbol should be popped. */
1609 yystacksize = YYINITDEPTH;
1611 YYDPRINTF ((stderr, "Starting parse\n"));
1616 yychar = YYEMPTY; /* Cause a token to be read. */
1618 /* Initialize stack pointers.
1619 Waste one element of value and location stack
1620 so that they stay on the same level as the state stack.
1621 The wasted elements are never initialized. */
1627 /*------------------------------------------------------------.
1628 | yynewstate -- Push a new state, which is found in yystate. |
1629 `------------------------------------------------------------*/
1631 /* In all cases, when you get here, the value and location stacks
1632 have just been pushed. So pushing a state here evens the stacks. */
1638 if (yyss + yystacksize - 1 <= yyssp)
1640 /* Get the current used size of the three stacks, in elements. */
1641 YYSIZE_T yysize = yyssp - yyss + 1;
1645 /* Give user a chance to reallocate the stack. Use copies of
1646 these so that the &'s don't force the real ones into
1648 YYSTYPE *yyvs1 = yyvs;
1649 yytype_int16 *yyss1 = yyss;
1651 /* Each stack pointer address is followed by the size of the
1652 data in use in that stack, in bytes. This used to be a
1653 conditional around just the two extra args, but that might
1654 be undefined if yyoverflow is a macro. */
1655 yyoverflow (YY_("memory exhausted"),
1656 &yyss1, yysize * sizeof (*yyssp),
1657 &yyvs1, yysize * sizeof (*yyvsp),
1663 #else /* no yyoverflow */
1664 # ifndef YYSTACK_RELOCATE
1665 goto yyexhaustedlab;
1667 /* Extend the stack our own way. */
1668 if (YYMAXDEPTH <= yystacksize)
1669 goto yyexhaustedlab;
1671 if (YYMAXDEPTH < yystacksize)
1672 yystacksize = YYMAXDEPTH;
1675 yytype_int16 *yyss1 = yyss;
1676 union yyalloc *yyptr =
1677 (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
1679 goto yyexhaustedlab;
1680 YYSTACK_RELOCATE (yyss_alloc, yyss);
1681 YYSTACK_RELOCATE (yyvs_alloc, yyvs);
1682 # undef YYSTACK_RELOCATE
1684 YYSTACK_FREE (yyss1);
1687 #endif /* no yyoverflow */
1689 yyssp = yyss + yysize - 1;
1690 yyvsp = yyvs + yysize - 1;
1692 YYDPRINTF ((stderr, "Stack size increased to %lu\n",
1693 (unsigned long int) yystacksize));
1695 if (yyss + yystacksize - 1 <= yyssp)
1699 YYDPRINTF ((stderr, "Entering state %d\n", yystate));
1701 if (yystate == YYFINAL)
1711 /* Do appropriate processing given the current state. Read a
1712 lookahead token if we need one and don't already have one. */
1714 /* First try to decide what to do without reference to lookahead token. */
1715 yyn = yypact[yystate];
1716 if (yypact_value_is_default (yyn))
1719 /* Not known => get a lookahead token if don't already have one. */
1721 /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol. */
1722 if (yychar == YYEMPTY)
1724 YYDPRINTF ((stderr, "Reading a token: "));
1728 if (yychar <= YYEOF)
1730 yychar = yytoken = YYEOF;
1731 YYDPRINTF ((stderr, "Now at end of input.\n"));
1735 yytoken = YYTRANSLATE (yychar);
1736 YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
1739 /* If the proper action on seeing token YYTOKEN is to reduce or to
1740 detect an error, take that action. */
1742 if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
1747 if (yytable_value_is_error (yyn))
1753 /* Count tokens shifted since error; after three, turn off error
1758 /* Shift the lookahead token. */
1759 YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
1761 /* Discard the shifted token. */
1770 /*-----------------------------------------------------------.
1771 | yydefault -- do the default action for the current state. |
1772 `-----------------------------------------------------------*/
1774 yyn = yydefact[yystate];
1780 /*-----------------------------.
1781 | yyreduce -- Do a reduction. |
1782 `-----------------------------*/
1784 /* yyn is the number of a rule to reduce with. */
1787 /* If YYLEN is nonzero, implement the default value of the action:
1790 Otherwise, the following line sets YYVAL to garbage.
1791 This behavior is undocumented and Bison
1792 users should not rely upon it. Assigning to YYVAL
1793 unconditionally makes the parser a bit smaller, and it avoids a
1794 GCC warning that YYVAL may be used uninitialized. */
1795 yyval = yyvsp[1-yylen];
1798 YY_REDUCE_PRINT (yyn);
1803 /* Line 1806 of yacc.c */
1804 #line 330 "parse-datetime.y"
1806 pc->seconds = (yyvsp[(2) - (2)].timespec);
1807 pc->timespec_seen = true;
1813 /* Line 1806 of yacc.c */
1814 #line 343 "parse-datetime.y"
1815 { pc->times_seen++; pc->dates_seen++; }
1820 /* Line 1806 of yacc.c */
1821 #line 345 "parse-datetime.y"
1822 { pc->times_seen++; }
1827 /* Line 1806 of yacc.c */
1828 #line 347 "parse-datetime.y"
1829 { pc->local_zones_seen++; }
1834 /* Line 1806 of yacc.c */
1835 #line 349 "parse-datetime.y"
1836 { pc->zones_seen++; }
1841 /* Line 1806 of yacc.c */
1842 #line 351 "parse-datetime.y"
1843 { pc->dates_seen++; }
1848 /* Line 1806 of yacc.c */
1849 #line 353 "parse-datetime.y"
1850 { pc->days_seen++; }
1855 /* Line 1806 of yacc.c */
1856 #line 369 "parse-datetime.y"
1858 set_hhmmss (pc, (yyvsp[(1) - (2)].textintval).value, 0, 0, 0);
1859 pc->meridian = (yyvsp[(2) - (2)].intval);
1865 /* Line 1806 of yacc.c */
1866 #line 374 "parse-datetime.y"
1868 set_hhmmss (pc, (yyvsp[(1) - (4)].textintval).value, (yyvsp[(3) - (4)].textintval).value, 0, 0);
1869 pc->meridian = (yyvsp[(4) - (4)].intval);
1875 /* Line 1806 of yacc.c */
1876 #line 379 "parse-datetime.y"
1878 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);
1879 pc->meridian = (yyvsp[(6) - (6)].intval);
1885 /* Line 1806 of yacc.c */
1886 #line 388 "parse-datetime.y"
1888 set_hhmmss (pc, (yyvsp[(1) - (2)].textintval).value, 0, 0, 0);
1889 pc->meridian = MER24;
1895 /* Line 1806 of yacc.c */
1896 #line 393 "parse-datetime.y"
1898 set_hhmmss (pc, (yyvsp[(1) - (4)].textintval).value, (yyvsp[(3) - (4)].textintval).value, 0, 0);
1899 pc->meridian = MER24;
1905 /* Line 1806 of yacc.c */
1906 #line 398 "parse-datetime.y"
1908 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);
1909 pc->meridian = MER24;
1915 /* Line 1806 of yacc.c */
1916 #line 411 "parse-datetime.y"
1919 pc->time_zone = time_zone_hhmm (pc, (yyvsp[(1) - (2)].textintval), (yyvsp[(2) - (2)].intval));
1925 /* Line 1806 of yacc.c */
1926 #line 419 "parse-datetime.y"
1928 pc->local_isdst = (yyvsp[(1) - (1)].intval);
1929 pc->dsts_seen += (0 < (yyvsp[(1) - (1)].intval));
1935 /* Line 1806 of yacc.c */
1936 #line 424 "parse-datetime.y"
1938 pc->local_isdst = 1;
1939 pc->dsts_seen += (0 < (yyvsp[(1) - (2)].intval)) + 1;
1945 /* Line 1806 of yacc.c */
1946 #line 434 "parse-datetime.y"
1947 { pc->time_zone = (yyvsp[(1) - (1)].intval); }
1952 /* Line 1806 of yacc.c */
1953 #line 436 "parse-datetime.y"
1954 { pc->time_zone = HOUR(7); }
1959 /* Line 1806 of yacc.c */
1960 #line 438 "parse-datetime.y"
1961 { pc->time_zone = (yyvsp[(1) - (2)].intval);
1962 apply_relative_time (pc, (yyvsp[(2) - (2)].rel), 1); }
1967 /* Line 1806 of yacc.c */
1968 #line 441 "parse-datetime.y"
1969 { pc->time_zone = HOUR(7);
1970 apply_relative_time (pc, (yyvsp[(2) - (2)].rel), 1); }
1975 /* Line 1806 of yacc.c */
1976 #line 444 "parse-datetime.y"
1977 { pc->time_zone = (yyvsp[(1) - (3)].intval) + time_zone_hhmm (pc, (yyvsp[(2) - (3)].textintval), (yyvsp[(3) - (3)].intval)); }
1982 /* Line 1806 of yacc.c */
1983 #line 446 "parse-datetime.y"
1984 { pc->time_zone = (yyvsp[(1) - (1)].intval) + 60; }
1989 /* Line 1806 of yacc.c */
1990 #line 448 "parse-datetime.y"
1991 { pc->time_zone = (yyvsp[(1) - (2)].intval) + 60; }
1996 /* Line 1806 of yacc.c */
1997 #line 453 "parse-datetime.y"
1999 pc->day_ordinal = 0;
2000 pc->day_number = (yyvsp[(1) - (1)].intval);
2006 /* Line 1806 of yacc.c */
2007 #line 458 "parse-datetime.y"
2009 pc->day_ordinal = 0;
2010 pc->day_number = (yyvsp[(1) - (2)].intval);
2016 /* Line 1806 of yacc.c */
2017 #line 463 "parse-datetime.y"
2019 pc->day_ordinal = (yyvsp[(1) - (2)].intval);
2020 pc->day_number = (yyvsp[(2) - (2)].intval);
2026 /* Line 1806 of yacc.c */
2027 #line 468 "parse-datetime.y"
2029 pc->day_ordinal = (yyvsp[(1) - (2)].textintval).value;
2030 pc->day_number = (yyvsp[(2) - (2)].intval);
2036 /* Line 1806 of yacc.c */
2037 #line 476 "parse-datetime.y"
2039 pc->month = (yyvsp[(1) - (3)].textintval).value;
2040 pc->day = (yyvsp[(3) - (3)].textintval).value;
2046 /* Line 1806 of yacc.c */
2047 #line 481 "parse-datetime.y"
2049 /* Interpret as YYYY/MM/DD if the first value has 4 or more digits,
2050 otherwise as MM/DD/YY.
2051 The goal in recognizing YYYY/MM/DD is solely to support legacy
2052 machine-generated dates like those in an RCS log listing. If
2053 you want portability, use the ISO 8601 format. */
2054 if (4 <= (yyvsp[(1) - (5)].textintval).digits)
2056 pc->year = (yyvsp[(1) - (5)].textintval);
2057 pc->month = (yyvsp[(3) - (5)].textintval).value;
2058 pc->day = (yyvsp[(5) - (5)].textintval).value;
2062 pc->month = (yyvsp[(1) - (5)].textintval).value;
2063 pc->day = (yyvsp[(3) - (5)].textintval).value;
2064 pc->year = (yyvsp[(5) - (5)].textintval);
2071 /* Line 1806 of yacc.c */
2072 #line 501 "parse-datetime.y"
2074 /* e.g. 17-JUN-1992. */
2075 pc->day = (yyvsp[(1) - (3)].textintval).value;
2076 pc->month = (yyvsp[(2) - (3)].intval);
2077 pc->year.value = -(yyvsp[(3) - (3)].textintval).value;
2078 pc->year.digits = (yyvsp[(3) - (3)].textintval).digits;
2084 /* Line 1806 of yacc.c */
2085 #line 509 "parse-datetime.y"
2087 /* e.g. JUN-17-1992. */
2088 pc->month = (yyvsp[(1) - (3)].intval);
2089 pc->day = -(yyvsp[(2) - (3)].textintval).value;
2090 pc->year.value = -(yyvsp[(3) - (3)].textintval).value;
2091 pc->year.digits = (yyvsp[(3) - (3)].textintval).digits;
2097 /* Line 1806 of yacc.c */
2098 #line 517 "parse-datetime.y"
2100 pc->month = (yyvsp[(1) - (2)].intval);
2101 pc->day = (yyvsp[(2) - (2)].textintval).value;
2107 /* Line 1806 of yacc.c */
2108 #line 522 "parse-datetime.y"
2110 pc->month = (yyvsp[(1) - (4)].intval);
2111 pc->day = (yyvsp[(2) - (4)].textintval).value;
2112 pc->year = (yyvsp[(4) - (4)].textintval);
2118 /* Line 1806 of yacc.c */
2119 #line 528 "parse-datetime.y"
2121 pc->day = (yyvsp[(1) - (2)].textintval).value;
2122 pc->month = (yyvsp[(2) - (2)].intval);
2128 /* Line 1806 of yacc.c */
2129 #line 533 "parse-datetime.y"
2131 pc->day = (yyvsp[(1) - (3)].textintval).value;
2132 pc->month = (yyvsp[(2) - (3)].intval);
2133 pc->year = (yyvsp[(3) - (3)].textintval);
2139 /* Line 1806 of yacc.c */
2140 #line 543 "parse-datetime.y"
2142 /* ISO 8601 format. YYYY-MM-DD. */
2143 pc->year = (yyvsp[(1) - (3)].textintval);
2144 pc->month = -(yyvsp[(2) - (3)].textintval).value;
2145 pc->day = -(yyvsp[(3) - (3)].textintval).value;
2151 /* Line 1806 of yacc.c */
2152 #line 553 "parse-datetime.y"
2153 { apply_relative_time (pc, (yyvsp[(1) - (2)].rel), (yyvsp[(2) - (2)].intval)); }
2158 /* Line 1806 of yacc.c */
2159 #line 555 "parse-datetime.y"
2160 { apply_relative_time (pc, (yyvsp[(1) - (1)].rel), 1); }
2165 /* Line 1806 of yacc.c */
2166 #line 557 "parse-datetime.y"
2167 { apply_relative_time (pc, (yyvsp[(1) - (1)].rel), 1); }
2172 /* Line 1806 of yacc.c */
2173 #line 562 "parse-datetime.y"
2174 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).year = (yyvsp[(1) - (2)].intval); }
2179 /* Line 1806 of yacc.c */
2180 #line 564 "parse-datetime.y"
2181 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).year = (yyvsp[(1) - (2)].textintval).value; }
2186 /* Line 1806 of yacc.c */
2187 #line 566 "parse-datetime.y"
2188 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).year = 1; }
2193 /* Line 1806 of yacc.c */
2194 #line 568 "parse-datetime.y"
2195 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).month = (yyvsp[(1) - (2)].intval); }
2200 /* Line 1806 of yacc.c */
2201 #line 570 "parse-datetime.y"
2202 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).month = (yyvsp[(1) - (2)].textintval).value; }
2207 /* Line 1806 of yacc.c */
2208 #line 572 "parse-datetime.y"
2209 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).month = 1; }
2214 /* Line 1806 of yacc.c */
2215 #line 574 "parse-datetime.y"
2216 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).day = (yyvsp[(1) - (2)].intval) * (yyvsp[(2) - (2)].intval); }
2221 /* Line 1806 of yacc.c */
2222 #line 576 "parse-datetime.y"
2223 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).day = (yyvsp[(1) - (2)].textintval).value * (yyvsp[(2) - (2)].intval); }
2228 /* Line 1806 of yacc.c */
2229 #line 578 "parse-datetime.y"
2230 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).day = (yyvsp[(1) - (1)].intval); }
2235 /* Line 1806 of yacc.c */
2236 #line 580 "parse-datetime.y"
2237 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).hour = (yyvsp[(1) - (2)].intval); }
2242 /* Line 1806 of yacc.c */
2243 #line 582 "parse-datetime.y"
2244 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).hour = (yyvsp[(1) - (2)].textintval).value; }
2249 /* Line 1806 of yacc.c */
2250 #line 584 "parse-datetime.y"
2251 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).hour = 1; }
2256 /* Line 1806 of yacc.c */
2257 #line 586 "parse-datetime.y"
2258 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).minutes = (yyvsp[(1) - (2)].intval); }
2263 /* Line 1806 of yacc.c */
2264 #line 588 "parse-datetime.y"
2265 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).minutes = (yyvsp[(1) - (2)].textintval).value; }
2270 /* Line 1806 of yacc.c */
2271 #line 590 "parse-datetime.y"
2272 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).minutes = 1; }
2277 /* Line 1806 of yacc.c */
2278 #line 592 "parse-datetime.y"
2279 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).seconds = (yyvsp[(1) - (2)].intval); }
2284 /* Line 1806 of yacc.c */
2285 #line 594 "parse-datetime.y"
2286 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).seconds = (yyvsp[(1) - (2)].textintval).value; }
2291 /* Line 1806 of yacc.c */
2292 #line 596 "parse-datetime.y"
2293 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).seconds = (yyvsp[(1) - (2)].timespec).tv_sec; (yyval.rel).ns = (yyvsp[(1) - (2)].timespec).tv_nsec; }
2298 /* Line 1806 of yacc.c */
2299 #line 598 "parse-datetime.y"
2300 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).seconds = (yyvsp[(1) - (2)].timespec).tv_sec; (yyval.rel).ns = (yyvsp[(1) - (2)].timespec).tv_nsec; }
2305 /* Line 1806 of yacc.c */
2306 #line 600 "parse-datetime.y"
2307 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).seconds = 1; }
2312 /* Line 1806 of yacc.c */
2313 #line 606 "parse-datetime.y"
2314 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).year = (yyvsp[(1) - (2)].textintval).value; }
2319 /* Line 1806 of yacc.c */
2320 #line 608 "parse-datetime.y"
2321 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).month = (yyvsp[(1) - (2)].textintval).value; }
2326 /* Line 1806 of yacc.c */
2327 #line 610 "parse-datetime.y"
2328 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).day = (yyvsp[(1) - (2)].textintval).value * (yyvsp[(2) - (2)].intval); }
2333 /* Line 1806 of yacc.c */
2334 #line 612 "parse-datetime.y"
2335 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).hour = (yyvsp[(1) - (2)].textintval).value; }
2340 /* Line 1806 of yacc.c */
2341 #line 614 "parse-datetime.y"
2342 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).minutes = (yyvsp[(1) - (2)].textintval).value; }
2347 /* Line 1806 of yacc.c */
2348 #line 616 "parse-datetime.y"
2349 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).seconds = (yyvsp[(1) - (2)].textintval).value; }
2354 /* Line 1806 of yacc.c */
2355 #line 621 "parse-datetime.y"
2356 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).day = (yyvsp[(1) - (1)].intval); }
2361 /* Line 1806 of yacc.c */
2362 #line 629 "parse-datetime.y"
2363 { (yyval.timespec).tv_sec = (yyvsp[(1) - (1)].textintval).value; (yyval.timespec).tv_nsec = 0; }
2368 /* Line 1806 of yacc.c */
2369 #line 635 "parse-datetime.y"
2370 { (yyval.timespec).tv_sec = (yyvsp[(1) - (1)].textintval).value; (yyval.timespec).tv_nsec = 0; }
2375 /* Line 1806 of yacc.c */
2376 #line 640 "parse-datetime.y"
2377 { digits_to_date_time (pc, (yyvsp[(1) - (1)].textintval)); }
2382 /* Line 1806 of yacc.c */
2383 #line 645 "parse-datetime.y"
2385 /* Hybrid all-digit and relative offset, so that we accept e.g.,
2386 "YYYYMMDD +N days" as well as "YYYYMMDD N days". */
2387 digits_to_date_time (pc, (yyvsp[(1) - (2)].textintval));
2388 apply_relative_time (pc, (yyvsp[(2) - (2)].rel), 1);
2394 /* Line 1806 of yacc.c */
2395 #line 655 "parse-datetime.y"
2396 { (yyval.intval) = -1; }
2401 /* Line 1806 of yacc.c */
2402 #line 657 "parse-datetime.y"
2403 { (yyval.intval) = (yyvsp[(2) - (2)].textintval).value; }
2408 /* Line 1806 of yacc.c */
2409 #line 2410 "parse-datetime.c"
2412 /* User semantic actions sometimes alter yychar, and that requires
2413 that yytoken be updated with the new translation. We take the
2414 approach of translating immediately before every use of yytoken.
2415 One alternative is translating here after every semantic action,
2416 but that translation would be missed if the semantic action invokes
2417 YYABORT, YYACCEPT, or YYERROR immediately after altering yychar or
2418 if it invokes YYBACKUP. In the case of YYABORT or YYACCEPT, an
2419 incorrect destructor might then be invoked immediately. In the
2420 case of YYERROR or YYBACKUP, subsequent parser actions might lead
2421 to an incorrect destructor call or verbose syntax error message
2422 before the lookahead is translated. */
2423 YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc);
2427 YY_STACK_PRINT (yyss, yyssp);
2431 /* Now `shift' the result of the reduction. Determine what state
2432 that goes to, based on the state we popped back to and the rule
2433 number reduced by. */
2437 yystate = yypgoto[yyn - YYNTOKENS] + *yyssp;
2438 if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp)
2439 yystate = yytable[yystate];
2441 yystate = yydefgoto[yyn - YYNTOKENS];
2446 /*------------------------------------.
2447 | yyerrlab -- here on detecting error |
2448 `------------------------------------*/
2450 /* Make sure we have latest lookahead translation. See comments at
2451 user semantic actions for why this is necessary. */
2452 yytoken = yychar == YYEMPTY ? YYEMPTY : YYTRANSLATE (yychar);
2454 /* If not already recovering from an error, report this error. */
2458 #if ! YYERROR_VERBOSE
2459 yyerror (pc, YY_("syntax error"));
2461 # define YYSYNTAX_ERROR yysyntax_error (&yymsg_alloc, &yymsg, \
2464 char const *yymsgp = YY_("syntax error");
2465 int yysyntax_error_status;
2466 yysyntax_error_status = YYSYNTAX_ERROR;
2467 if (yysyntax_error_status == 0)
2469 else if (yysyntax_error_status == 1)
2471 if (yymsg != yymsgbuf)
2472 YYSTACK_FREE (yymsg);
2473 yymsg = (char *) YYSTACK_ALLOC (yymsg_alloc);
2477 yymsg_alloc = sizeof yymsgbuf;
2478 yysyntax_error_status = 2;
2482 yysyntax_error_status = YYSYNTAX_ERROR;
2486 yyerror (pc, yymsgp);
2487 if (yysyntax_error_status == 2)
2488 goto yyexhaustedlab;
2490 # undef YYSYNTAX_ERROR
2496 if (yyerrstatus == 3)
2498 /* If just tried and failed to reuse lookahead token after an
2499 error, discard it. */
2501 if (yychar <= YYEOF)
2503 /* Return failure if at end of input. */
2504 if (yychar == YYEOF)
2509 yydestruct ("Error: discarding",
2510 yytoken, &yylval, pc);
2515 /* Else will try to reuse lookahead token after shifting the error
2520 /*---------------------------------------------------.
2521 | yyerrorlab -- error raised explicitly by YYERROR. |
2522 `---------------------------------------------------*/
2525 /* Pacify compilers like GCC when the user code never invokes
2526 YYERROR and the label yyerrorlab therefore never appears in user
2528 if (/*CONSTCOND*/ 0)
2531 /* Do not reclaim the symbols of the rule which action triggered
2535 YY_STACK_PRINT (yyss, yyssp);
2540 /*-------------------------------------------------------------.
2541 | yyerrlab1 -- common code for both syntax error and YYERROR. |
2542 `-------------------------------------------------------------*/
2544 yyerrstatus = 3; /* Each real token shifted decrements this. */
2548 yyn = yypact[yystate];
2549 if (!yypact_value_is_default (yyn))
2552 if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
2560 /* Pop the current state because it cannot handle the error token. */
2565 yydestruct ("Error: popping",
2566 yystos[yystate], yyvsp, pc);
2569 YY_STACK_PRINT (yyss, yyssp);
2575 /* Shift the error token. */
2576 YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp);
2582 /*-------------------------------------.
2583 | yyacceptlab -- YYACCEPT comes here. |
2584 `-------------------------------------*/
2589 /*-----------------------------------.
2590 | yyabortlab -- YYABORT comes here. |
2591 `-----------------------------------*/
2596 #if !defined(yyoverflow) || YYERROR_VERBOSE
2597 /*-------------------------------------------------.
2598 | yyexhaustedlab -- memory exhaustion comes here. |
2599 `-------------------------------------------------*/
2601 yyerror (pc, YY_("memory exhausted"));
2607 if (yychar != YYEMPTY)
2609 /* Make sure we have latest lookahead translation. See comments at
2610 user semantic actions for why this is necessary. */
2611 yytoken = YYTRANSLATE (yychar);
2612 yydestruct ("Cleanup: discarding lookahead",
2613 yytoken, &yylval, pc);
2615 /* Do not reclaim the symbols of the rule which action triggered
2616 this YYABORT or YYACCEPT. */
2618 YY_STACK_PRINT (yyss, yyssp);
2619 while (yyssp != yyss)
2621 yydestruct ("Cleanup: popping",
2622 yystos[*yyssp], yyvsp, pc);
2627 YYSTACK_FREE (yyss);
2630 if (yymsg != yymsgbuf)
2631 YYSTACK_FREE (yymsg);
2633 /* Make sure YYID is used. */
2634 return YYID (yyresult);
2639 /* Line 2067 of yacc.c */
2640 #line 660 "parse-datetime.y"
2643 static table const meridian_table[] =
2645 { "AM", tMERIDIAN, MERam },
2646 { "A.M.", tMERIDIAN, MERam },
2647 { "PM", tMERIDIAN, MERpm },
2648 { "P.M.", tMERIDIAN, MERpm },
2652 static table const dst_table[] =
2657 static table const month_and_day_table[] =
2659 { "JANUARY", tMONTH, 1 },
2660 { "FEBRUARY", tMONTH, 2 },
2661 { "MARCH", tMONTH, 3 },
2662 { "APRIL", tMONTH, 4 },
2663 { "MAY", tMONTH, 5 },
2664 { "JUNE", tMONTH, 6 },
2665 { "JULY", tMONTH, 7 },
2666 { "AUGUST", tMONTH, 8 },
2667 { "SEPTEMBER",tMONTH, 9 },
2668 { "SEPT", tMONTH, 9 },
2669 { "OCTOBER", tMONTH, 10 },
2670 { "NOVEMBER", tMONTH, 11 },
2671 { "DECEMBER", tMONTH, 12 },
2672 { "SUNDAY", tDAY, 0 },
2673 { "MONDAY", tDAY, 1 },
2674 { "TUESDAY", tDAY, 2 },
2675 { "TUES", tDAY, 2 },
2676 { "WEDNESDAY",tDAY, 3 },
2677 { "WEDNES", tDAY, 3 },
2678 { "THURSDAY", tDAY, 4 },
2679 { "THUR", tDAY, 4 },
2680 { "THURS", tDAY, 4 },
2681 { "FRIDAY", tDAY, 5 },
2682 { "SATURDAY", tDAY, 6 },
2686 static table const time_units_table[] =
2688 { "YEAR", tYEAR_UNIT, 1 },
2689 { "MONTH", tMONTH_UNIT, 1 },
2690 { "FORTNIGHT",tDAY_UNIT, 14 },
2691 { "WEEK", tDAY_UNIT, 7 },
2692 { "DAY", tDAY_UNIT, 1 },
2693 { "HOUR", tHOUR_UNIT, 1 },
2694 { "MINUTE", tMINUTE_UNIT, 1 },
2695 { "MIN", tMINUTE_UNIT, 1 },
2696 { "SECOND", tSEC_UNIT, 1 },
2697 { "SEC", tSEC_UNIT, 1 },
2701 /* Assorted relative-time words. */
2702 static table const relative_time_table[] =
2704 { "TOMORROW", tDAY_SHIFT, 1 },
2705 { "YESTERDAY",tDAY_SHIFT, -1 },
2706 { "TODAY", tDAY_SHIFT, 0 },
2707 { "NOW", tDAY_SHIFT, 0 },
2708 { "LAST", tORDINAL, -1 },
2709 { "THIS", tORDINAL, 0 },
2710 { "NEXT", tORDINAL, 1 },
2711 { "FIRST", tORDINAL, 1 },
2712 /*{ "SECOND", tORDINAL, 2 }, */
2713 { "THIRD", tORDINAL, 3 },
2714 { "FOURTH", tORDINAL, 4 },
2715 { "FIFTH", tORDINAL, 5 },
2716 { "SIXTH", tORDINAL, 6 },
2717 { "SEVENTH", tORDINAL, 7 },
2718 { "EIGHTH", tORDINAL, 8 },
2719 { "NINTH", tORDINAL, 9 },
2720 { "TENTH", tORDINAL, 10 },
2721 { "ELEVENTH", tORDINAL, 11 },
2722 { "TWELFTH", tORDINAL, 12 },
2723 { "AGO", tAGO, -1 },
2724 { "HENCE", tAGO, 1 },
2728 /* The universal time zone table. These labels can be used even for
2729 time stamps that would not otherwise be valid, e.g., GMT time
2730 stamps in London during summer. */
2731 static table const universal_time_zone_table[] =
2733 { "GMT", tZONE, HOUR ( 0) }, /* Greenwich Mean */
2734 { "UT", tZONE, HOUR ( 0) }, /* Universal (Coordinated) */
2735 { "UTC", tZONE, HOUR ( 0) },
2739 /* The time zone table. This table is necessarily incomplete, as time
2740 zone abbreviations are ambiguous; e.g. Australians interpret "EST"
2741 as Eastern time in Australia, not as US Eastern Standard Time.
2742 You cannot rely on parse_datetime to handle arbitrary time zone
2743 abbreviations; use numeric abbreviations like "-0500" instead. */
2744 static table const time_zone_table[] =
2746 { "WET", tZONE, HOUR ( 0) }, /* Western European */
2747 { "WEST", tDAYZONE, HOUR ( 0) }, /* Western European Summer */
2748 { "BST", tDAYZONE, HOUR ( 0) }, /* British Summer */
2749 { "ART", tZONE, -HOUR ( 3) }, /* Argentina */
2750 { "BRT", tZONE, -HOUR ( 3) }, /* Brazil */
2751 { "BRST", tDAYZONE, -HOUR ( 3) }, /* Brazil Summer */
2752 { "NST", tZONE, -(HOUR ( 3) + 30) }, /* Newfoundland Standard */
2753 { "NDT", tDAYZONE,-(HOUR ( 3) + 30) }, /* Newfoundland Daylight */
2754 { "AST", tZONE, -HOUR ( 4) }, /* Atlantic Standard */
2755 { "ADT", tDAYZONE, -HOUR ( 4) }, /* Atlantic Daylight */
2756 { "CLT", tZONE, -HOUR ( 4) }, /* Chile */
2757 { "CLST", tDAYZONE, -HOUR ( 4) }, /* Chile Summer */
2758 { "EST", tZONE, -HOUR ( 5) }, /* Eastern Standard */
2759 { "EDT", tDAYZONE, -HOUR ( 5) }, /* Eastern Daylight */
2760 { "CST", tZONE, -HOUR ( 6) }, /* Central Standard */
2761 { "CDT", tDAYZONE, -HOUR ( 6) }, /* Central Daylight */
2762 { "MST", tZONE, -HOUR ( 7) }, /* Mountain Standard */
2763 { "MDT", tDAYZONE, -HOUR ( 7) }, /* Mountain Daylight */
2764 { "PST", tZONE, -HOUR ( 8) }, /* Pacific Standard */
2765 { "PDT", tDAYZONE, -HOUR ( 8) }, /* Pacific Daylight */
2766 { "AKST", tZONE, -HOUR ( 9) }, /* Alaska Standard */
2767 { "AKDT", tDAYZONE, -HOUR ( 9) }, /* Alaska Daylight */
2768 { "HST", tZONE, -HOUR (10) }, /* Hawaii Standard */
2769 { "HAST", tZONE, -HOUR (10) }, /* Hawaii-Aleutian Standard */
2770 { "HADT", tDAYZONE, -HOUR (10) }, /* Hawaii-Aleutian Daylight */
2771 { "SST", tZONE, -HOUR (12) }, /* Samoa Standard */
2772 { "WAT", tZONE, HOUR ( 1) }, /* West Africa */
2773 { "CET", tZONE, HOUR ( 1) }, /* Central European */
2774 { "CEST", tDAYZONE, HOUR ( 1) }, /* Central European Summer */
2775 { "MET", tZONE, HOUR ( 1) }, /* Middle European */
2776 { "MEZ", tZONE, HOUR ( 1) }, /* Middle European */
2777 { "MEST", tDAYZONE, HOUR ( 1) }, /* Middle European Summer */
2778 { "MESZ", tDAYZONE, HOUR ( 1) }, /* Middle European Summer */
2779 { "EET", tZONE, HOUR ( 2) }, /* Eastern European */
2780 { "EEST", tDAYZONE, HOUR ( 2) }, /* Eastern European Summer */
2781 { "CAT", tZONE, HOUR ( 2) }, /* Central Africa */
2782 { "SAST", tZONE, HOUR ( 2) }, /* South Africa Standard */
2783 { "EAT", tZONE, HOUR ( 3) }, /* East Africa */
2784 { "MSK", tZONE, HOUR ( 3) }, /* Moscow */
2785 { "MSD", tDAYZONE, HOUR ( 3) }, /* Moscow Daylight */
2786 { "IST", tZONE, (HOUR ( 5) + 30) }, /* India Standard */
2787 { "SGT", tZONE, HOUR ( 8) }, /* Singapore */
2788 { "KST", tZONE, HOUR ( 9) }, /* Korea Standard */
2789 { "JST", tZONE, HOUR ( 9) }, /* Japan Standard */
2790 { "GST", tZONE, HOUR (10) }, /* Guam Standard */
2791 { "NZST", tZONE, HOUR (12) }, /* New Zealand Standard */
2792 { "NZDT", tDAYZONE, HOUR (12) }, /* New Zealand Daylight */
2796 /* Military time zone table.
2798 Note 'T' is a special case, as it is used as the separator in ISO
2799 8601 date and time of day representation. */
2800 static table const military_table[] =
2802 { "A", tZONE, -HOUR ( 1) },
2803 { "B", tZONE, -HOUR ( 2) },
2804 { "C", tZONE, -HOUR ( 3) },
2805 { "D", tZONE, -HOUR ( 4) },
2806 { "E", tZONE, -HOUR ( 5) },
2807 { "F", tZONE, -HOUR ( 6) },
2808 { "G", tZONE, -HOUR ( 7) },
2809 { "H", tZONE, -HOUR ( 8) },
2810 { "I", tZONE, -HOUR ( 9) },
2811 { "K", tZONE, -HOUR (10) },
2812 { "L", tZONE, -HOUR (11) },
2813 { "M", tZONE, -HOUR (12) },
2814 { "N", tZONE, HOUR ( 1) },
2815 { "O", tZONE, HOUR ( 2) },
2816 { "P", tZONE, HOUR ( 3) },
2817 { "Q", tZONE, HOUR ( 4) },
2818 { "R", tZONE, HOUR ( 5) },
2819 { "S", tZONE, HOUR ( 6) },
2821 { "U", tZONE, HOUR ( 8) },
2822 { "V", tZONE, HOUR ( 9) },
2823 { "W", tZONE, HOUR (10) },
2824 { "X", tZONE, HOUR (11) },
2825 { "Y", tZONE, HOUR (12) },
2826 { "Z", tZONE, HOUR ( 0) },
2832 /* Convert a time zone expressed as HH:MM into an integer count of
2833 minutes. If MM is negative, then S is of the form HHMM and needs
2834 to be picked apart; otherwise, S is of the form HH. As specified in
2835 http://www.opengroup.org/susv3xbd/xbd_chap08.html#tag_08_03, allow
2836 only valid TZ range, and consider first two digits as hours, if no
2837 minutes specified. */
2840 time_zone_hhmm (parser_control *pc, textint s, long int mm)
2844 /* If the length of S is 1 or 2 and no minutes are specified,
2845 interpret it as a number of hours. */
2846 if (s.digits <= 2 && mm < 0)
2850 n_minutes = (s.value / 100) * 60 + s.value % 100;
2852 n_minutes = s.value * 60 + (s.negative ? -mm : mm);
2854 /* If the absolute number of minutes is larger than 24 hours,
2855 arrange to reject it by incrementing pc->zones_seen. Thus,
2856 we allow only values in the range UTC-24:00 to UTC+24:00. */
2857 if (24 * 60 < abs (n_minutes))
2864 to_hour (long int hours, int meridian)
2868 default: /* Pacify GCC. */
2870 return 0 <= hours && hours < 24 ? hours : -1;
2872 return 0 < hours && hours < 12 ? hours : hours == 12 ? 0 : -1;
2874 return 0 < hours && hours < 12 ? hours + 12 : hours == 12 ? 12 : -1;
2879 to_year (textint textyear)
2881 long int year = textyear.value;
2886 /* XPG4 suggests that years 00-68 map to 2000-2068, and
2887 years 69-99 map to 1969-1999. */
2888 else if (textyear.digits == 2)
2889 year += year < 69 ? 2000 : 1900;
2894 static table const * _GL_ATTRIBUTE_PURE
2895 lookup_zone (parser_control const *pc, char const *name)
2899 for (tp = universal_time_zone_table; tp->name; tp++)
2900 if (strcmp (name, tp->name) == 0)
2903 /* Try local zone abbreviations before those in time_zone_table, as
2904 the local ones are more likely to be right. */
2905 for (tp = pc->local_time_zone_table; tp->name; tp++)
2906 if (strcmp (name, tp->name) == 0)
2909 for (tp = time_zone_table; tp->name; tp++)
2910 if (strcmp (name, tp->name) == 0)
2916 #if ! HAVE_TM_GMTOFF
2917 /* Yield the difference between *A and *B,
2918 measured in seconds, ignoring leap seconds.
2919 The body of this function is taken directly from the GNU C Library;
2920 see src/strftime.c. */
2922 tm_diff (struct tm const *a, struct tm const *b)
2924 /* Compute intervening leap days correctly even if year is negative.
2925 Take care to avoid int overflow in leap day calculations. */
2926 int a4 = SHR (a->tm_year, 2) + SHR (TM_YEAR_BASE, 2) - ! (a->tm_year & 3);
2927 int b4 = SHR (b->tm_year, 2) + SHR (TM_YEAR_BASE, 2) - ! (b->tm_year & 3);
2928 int a100 = a4 / 25 - (a4 % 25 < 0);
2929 int b100 = b4 / 25 - (b4 % 25 < 0);
2930 int a400 = SHR (a100, 2);
2931 int b400 = SHR (b100, 2);
2932 int intervening_leap_days = (a4 - b4) - (a100 - b100) + (a400 - b400);
2933 long int ayear = a->tm_year;
2934 long int years = ayear - b->tm_year;
2935 long int days = (365 * years + intervening_leap_days
2936 + (a->tm_yday - b->tm_yday));
2937 return (60 * (60 * (24 * days + (a->tm_hour - b->tm_hour))
2938 + (a->tm_min - b->tm_min))
2939 + (a->tm_sec - b->tm_sec));
2941 #endif /* ! HAVE_TM_GMTOFF */
2943 static table const *
2944 lookup_word (parser_control const *pc, char *word)
2953 /* Make it uppercase. */
2954 for (p = word; *p; p++)
2956 unsigned char ch = *p;
2957 *p = c_toupper (ch);
2960 for (tp = meridian_table; tp->name; tp++)
2961 if (strcmp (word, tp->name) == 0)
2964 /* See if we have an abbreviation for a month. */
2965 wordlen = strlen (word);
2966 abbrev = wordlen == 3 || (wordlen == 4 && word[3] == '.');
2968 for (tp = month_and_day_table; tp->name; tp++)
2969 if ((abbrev ? strncmp (word, tp->name, 3) : strcmp (word, tp->name)) == 0)
2972 if ((tp = lookup_zone (pc, word)))
2975 if (strcmp (word, dst_table[0].name) == 0)
2978 for (tp = time_units_table; tp->name; tp++)
2979 if (strcmp (word, tp->name) == 0)
2982 /* Strip off any plural and try the units table again. */
2983 if (word[wordlen - 1] == 'S')
2985 word[wordlen - 1] = '\0';
2986 for (tp = time_units_table; tp->name; tp++)
2987 if (strcmp (word, tp->name) == 0)
2989 word[wordlen - 1] = 'S'; /* For "this" in relative_time_table. */
2992 for (tp = relative_time_table; tp->name; tp++)
2993 if (strcmp (word, tp->name) == 0)
2996 /* Military time zones. */
2998 for (tp = military_table; tp->name; tp++)
2999 if (word[0] == tp->name[0])
3002 /* Drop out any periods and try the time zone table again. */
3003 for (period_found = false, p = q = word; (*p = *q); q++)
3005 period_found = true;
3008 if (period_found && (tp = lookup_zone (pc, word)))
3015 yylex (YYSTYPE *lvalp, parser_control *pc)
3022 while (c = *pc->input, c_isspace (c))
3025 if (ISDIGIT (c) || c == '-' || c == '+')
3029 unsigned long int value;
3030 if (c == '-' || c == '+')
3032 sign = c == '-' ? -1 : 1;
3033 while (c = *++pc->input, c_isspace (c))
3036 /* skip the '-' sign */
3042 for (value = 0; ; value *= 10)
3044 unsigned long int value1 = value + (c - '0');
3051 if (ULONG_MAX / 10 < value)
3054 if ((c == '.' || c == ',') && ISDIGIT (p[1]))
3059 unsigned long int value1;
3061 /* Check for overflow when converting value to time_t. */
3076 if (value != value1)
3079 /* Accumulate fraction, to ns precision. */
3082 for (digits = 2; digits <= LOG10_BILLION; digits++)
3089 /* Skip excess digits, truncating toward -Infinity. */
3091 for (; ISDIGIT (*p); p++)
3097 while (ISDIGIT (*p))
3100 /* Adjust to the timespec convention, which is that
3101 tv_nsec is always a positive offset even if tv_sec is
3111 lvalp->timespec.tv_sec = s;
3112 lvalp->timespec.tv_nsec = ns;
3114 return sign ? tSDECIMAL_NUMBER : tUDECIMAL_NUMBER;
3118 lvalp->textintval.negative = sign < 0;
3121 lvalp->textintval.value = - value;
3122 if (0 < lvalp->textintval.value)
3127 lvalp->textintval.value = value;
3128 if (lvalp->textintval.value < 0)
3131 lvalp->textintval.digits = p - pc->input;
3133 return sign ? tSNUMBER : tUNUMBER;
3145 if (p - buff < sizeof buff - 1)
3149 while (c_isalpha (c) || c == '.');
3152 tp = lookup_word (pc, buff);
3155 lvalp->intval = tp->value;
3160 return to_uchar (*pc->input++);
3177 /* Do nothing if the parser reports an error. */
3179 yyerror (parser_control const *pc _GL_UNUSED,
3180 char const *s _GL_UNUSED)
3185 /* If *TM0 is the old and *TM1 is the new value of a struct tm after
3186 passing it to mktime, return true if it's OK that mktime returned T.
3187 It's not OK if *TM0 has out-of-range members. */
3190 mktime_ok (struct tm const *tm0, struct tm const *tm1, time_t t)
3192 if (t == (time_t) -1)
3194 /* Guard against falsely reporting an error when parsing a time
3195 stamp that happens to equal (time_t) -1, on a host that
3196 supports such a time stamp. */
3197 tm1 = localtime (&t);
3202 return ! ((tm0->tm_sec ^ tm1->tm_sec)
3203 | (tm0->tm_min ^ tm1->tm_min)
3204 | (tm0->tm_hour ^ tm1->tm_hour)
3205 | (tm0->tm_mday ^ tm1->tm_mday)
3206 | (tm0->tm_mon ^ tm1->tm_mon)
3207 | (tm0->tm_year ^ tm1->tm_year));
3210 /* A reasonable upper bound for the size of ordinary TZ strings.
3211 Use heap allocation if TZ's length exceeds this. */
3212 enum { TZBUFSIZE = 100 };
3214 /* Return a copy of TZ, stored in TZBUF if it fits, and heap-allocated
3217 get_tz (char tzbuf[TZBUFSIZE])
3219 char *tz = getenv ("TZ");
3222 size_t tzsize = strlen (tz) + 1;
3223 tz = (tzsize <= TZBUFSIZE
3224 ? memcpy (tzbuf, tz, tzsize)
3225 : xmemdup (tz, tzsize));
3230 /* Parse a date/time string, storing the resulting time value into *RESULT.
3231 The string itself is pointed to by P. Return true if successful.
3232 P can be an incomplete or relative time specification; if so, use
3233 *NOW as the basis for the returned time. */
3235 parse_datetime (struct timespec *result, char const *p,
3236 struct timespec const *now)
3240 struct tm const *tmp;
3244 struct timespec gettime_buffer;
3246 bool tz_was_altered = false;
3248 char tz0buf[TZBUFSIZE];
3253 gettime (&gettime_buffer);
3254 now = &gettime_buffer;
3257 Start = now->tv_sec;
3258 Start_ns = now->tv_nsec;
3260 tmp = localtime (&now->tv_sec);
3264 while (c = *p, c_isspace (c))
3267 if (strncmp (p, "TZ=\"", 4) == 0)
3269 char const *tzbase = p + 4;
3273 for (s = tzbase; *s; s++, tzsize++)
3277 if (! (*s == '\\' || *s == '"'))
3284 char tz1buf[TZBUFSIZE];
3285 bool large_tz = TZBUFSIZE < tzsize;
3287 tz0 = get_tz (tz0buf);
3288 z = tz1 = large_tz ? xmalloc (tzsize) : tz1buf;
3289 for (s = tzbase; *s != '"'; s++)
3290 *z++ = *(s += *s == '\\');
3292 setenv_ok = setenv ("TZ", tz1, 1) == 0;
3297 tz_was_altered = true;
3300 while (c = *p, c_isspace (c))
3307 /* As documented, be careful to treat the empty string just like
3308 a date string of "0". Without this, an empty string would be
3309 declared invalid when parsed during a DST transition. */
3314 pc.year.value = tmp->tm_year;
3315 pc.year.value += TM_YEAR_BASE;
3317 pc.month = tmp->tm_mon + 1;
3318 pc.day = tmp->tm_mday;
3319 pc.hour = tmp->tm_hour;
3320 pc.minutes = tmp->tm_min;
3321 pc.seconds.tv_sec = tmp->tm_sec;
3322 pc.seconds.tv_nsec = Start_ns;
3323 tm.tm_isdst = tmp->tm_isdst;
3325 pc.meridian = MER24;
3326 pc.rel = RELATIVE_TIME_0;
3327 pc.timespec_seen = false;
3328 pc.rels_seen = false;
3332 pc.local_zones_seen = 0;
3336 #if HAVE_STRUCT_TM_TM_ZONE
3337 pc.local_time_zone_table[0].name = tmp->tm_zone;
3338 pc.local_time_zone_table[0].type = tLOCAL_ZONE;
3339 pc.local_time_zone_table[0].value = tmp->tm_isdst;
3340 pc.local_time_zone_table[1].name = NULL;
3342 /* Probe the names used in the next three calendar quarters, looking
3343 for a tm_isdst different from the one we already have. */
3346 for (quarter = 1; quarter <= 3; quarter++)
3348 time_t probe = Start + quarter * (90 * 24 * 60 * 60);
3349 struct tm const *probe_tm = localtime (&probe);
3350 if (probe_tm && probe_tm->tm_zone
3351 && probe_tm->tm_isdst != pc.local_time_zone_table[0].value)
3354 pc.local_time_zone_table[1].name = probe_tm->tm_zone;
3355 pc.local_time_zone_table[1].type = tLOCAL_ZONE;
3356 pc.local_time_zone_table[1].value = probe_tm->tm_isdst;
3357 pc.local_time_zone_table[2].name = NULL;
3366 # if !HAVE_DECL_TZNAME
3367 extern char *tzname[];
3370 for (i = 0; i < 2; i++)
3372 pc.local_time_zone_table[i].name = tzname[i];
3373 pc.local_time_zone_table[i].type = tLOCAL_ZONE;
3374 pc.local_time_zone_table[i].value = i;
3376 pc.local_time_zone_table[i].name = NULL;
3379 pc.local_time_zone_table[0].name = NULL;
3383 if (pc.local_time_zone_table[0].name && pc.local_time_zone_table[1].name
3384 && ! strcmp (pc.local_time_zone_table[0].name,
3385 pc.local_time_zone_table[1].name))
3387 /* This locale uses the same abbreviation for standard and
3388 daylight times. So if we see that abbreviation, we don't
3389 know whether it's daylight time. */
3390 pc.local_time_zone_table[0].value = -1;
3391 pc.local_time_zone_table[1].name = NULL;
3394 if (yyparse (&pc) != 0)
3397 if (pc.timespec_seen)
3398 *result = pc.seconds;
3401 if (1 < (pc.times_seen | pc.dates_seen | pc.days_seen | pc.dsts_seen
3402 | (pc.local_zones_seen + pc.zones_seen)))
3405 tm.tm_year = to_year (pc.year) - TM_YEAR_BASE;
3406 tm.tm_mon = pc.month - 1;
3407 tm.tm_mday = pc.day;
3408 if (pc.times_seen || (pc.rels_seen && ! pc.dates_seen && ! pc.days_seen))
3410 tm.tm_hour = to_hour (pc.hour, pc.meridian);
3413 tm.tm_min = pc.minutes;
3414 tm.tm_sec = pc.seconds.tv_sec;
3418 tm.tm_hour = tm.tm_min = tm.tm_sec = 0;
3419 pc.seconds.tv_nsec = 0;
3422 /* Let mktime deduce tm_isdst if we have an absolute time stamp. */
3423 if (pc.dates_seen | pc.days_seen | pc.times_seen)
3426 /* But if the input explicitly specifies local time with or without
3427 DST, give mktime that information. */
3428 if (pc.local_zones_seen)
3429 tm.tm_isdst = pc.local_isdst;
3433 Start = mktime (&tm);
3435 if (! mktime_ok (&tm0, &tm, Start))
3437 if (! pc.zones_seen)
3441 /* Guard against falsely reporting errors near the time_t
3442 boundaries when parsing times in other time zones. For
3443 example, suppose the input string "1969-12-31 23:00:00 -0100",
3444 the current time zone is 8 hours ahead of UTC, and the min
3445 time_t value is 1970-01-01 00:00:00 UTC. Then the min
3446 localtime value is 1970-01-01 08:00:00, and mktime will
3447 therefore fail on 1969-12-31 23:00:00. To work around the
3448 problem, set the time zone to 1 hour behind UTC temporarily
3449 by setting TZ="XXX1:00" and try mktime again. */
3451 long int time_zone = pc.time_zone;
3452 long int abs_time_zone = time_zone < 0 ? - time_zone : time_zone;
3453 long int abs_time_zone_hour = abs_time_zone / 60;
3454 int abs_time_zone_min = abs_time_zone % 60;
3455 char tz1buf[sizeof "XXX+0:00"
3456 + sizeof pc.time_zone * CHAR_BIT / 3];
3457 if (!tz_was_altered)
3458 tz0 = get_tz (tz0buf);
3459 sprintf (tz1buf, "XXX%s%ld:%02d", &"-"[time_zone < 0],
3460 abs_time_zone_hour, abs_time_zone_min);
3461 if (setenv ("TZ", tz1buf, 1) != 0)
3463 tz_was_altered = true;
3465 Start = mktime (&tm);
3466 if (! mktime_ok (&tm0, &tm, Start))
3471 if (pc.days_seen && ! pc.dates_seen)
3473 tm.tm_mday += ((pc.day_number - tm.tm_wday + 7) % 7
3474 + 7 * (pc.day_ordinal
3475 - (0 < pc.day_ordinal
3476 && tm.tm_wday != pc.day_number)));
3478 Start = mktime (&tm);
3479 if (Start == (time_t) -1)
3483 /* Add relative date. */
3484 if (pc.rel.year | pc.rel.month | pc.rel.day)
3486 int year = tm.tm_year + pc.rel.year;
3487 int month = tm.tm_mon + pc.rel.month;
3488 int day = tm.tm_mday + pc.rel.day;
3489 if (((year < tm.tm_year) ^ (pc.rel.year < 0))
3490 | ((month < tm.tm_mon) ^ (pc.rel.month < 0))
3491 | ((day < tm.tm_mday) ^ (pc.rel.day < 0)))
3496 tm.tm_hour = tm0.tm_hour;
3497 tm.tm_min = tm0.tm_min;
3498 tm.tm_sec = tm0.tm_sec;
3499 tm.tm_isdst = tm0.tm_isdst;
3500 Start = mktime (&tm);
3501 if (Start == (time_t) -1)
3505 /* The only "output" of this if-block is an updated Start value,
3506 so this block must follow others that clobber Start. */
3509 long int delta = pc.time_zone * 60;
3511 #ifdef HAVE_TM_GMTOFF
3512 delta -= tm.tm_gmtoff;
3515 struct tm const *gmt = gmtime (&t);
3518 delta -= tm_diff (&tm, gmt);
3521 if ((Start < t1) != (delta < 0))
3522 goto fail; /* time_t overflow */
3526 /* Add relative hours, minutes, and seconds. On hosts that support
3527 leap seconds, ignore the possibility of leap seconds; e.g.,
3528 "+ 10 minutes" adds 600 seconds, even if one of them is a
3529 leap second. Typically this is not what the user wants, but it's
3530 too hard to do it the other way, because the time zone indicator
3531 must be applied before relative times, and if mktime is applied
3532 again the time zone will be lost. */
3534 long int sum_ns = pc.seconds.tv_nsec + pc.rel.ns;
3535 long int normalized_ns = (sum_ns % BILLION + BILLION) % BILLION;
3537 long int d1 = 60 * 60 * pc.rel.hour;
3538 time_t t1 = t0 + d1;
3539 long int d2 = 60 * pc.rel.minutes;
3540 time_t t2 = t1 + d2;
3541 long_time_t d3 = pc.rel.seconds;
3542 long_time_t t3 = t2 + d3;
3543 long int d4 = (sum_ns - normalized_ns) / BILLION;
3544 long_time_t t4 = t3 + d4;
3547 if ((d1 / (60 * 60) ^ pc.rel.hour)
3548 | (d2 / 60 ^ pc.rel.minutes)
3549 | ((t1 < t0) ^ (d1 < 0))
3550 | ((t2 < t1) ^ (d2 < 0))
3551 | ((t3 < t2) ^ (d3 < 0))
3552 | ((t4 < t3) ^ (d4 < 0))
3556 result->tv_sec = t5;
3557 result->tv_nsec = normalized_ns;
3567 ok &= (tz0 ? setenv ("TZ", tz0, 1) : unsetenv ("TZ")) == 0;
3576 main (int ac, char **av)
3580 printf ("Enter date, or blank line to exit.\n\t> ");
3583 buff[BUFSIZ - 1] = '\0';
3584 while (fgets (buff, BUFSIZ - 1, stdin) && buff[0])
3587 struct tm const *tm;
3588 if (! parse_datetime (&d, buff, NULL))
3589 printf ("Bad format - couldn't convert.\n");
3590 else if (! (tm = localtime (&d.tv_sec)))
3592 long int sec = d.tv_sec;
3593 printf ("localtime (%ld) failed\n", sec);
3598 printf ("%04ld-%02d-%02d %02d:%02d:%02d.%09d\n",
3599 tm->tm_year + 1900L, tm->tm_mon + 1, tm->tm_mday,
3600 tm->tm_hour, tm->tm_min, tm->tm_sec, ns);