1 /* A Bison parser, made by GNU Bison 2.3. */
3 /* Skeleton implementation for Bison's Yacc-like parsers in C
5 Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006
6 Free Software Foundation, Inc.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 Boston, MA 02110-1301, USA. */
23 /* As a special exception, you may create a larger work that contains
24 part or all of the Bison parser skeleton and distribute that work
25 under terms of your choice, so long as that work isn't itself a
26 parser generator using the skeleton or a modified version thereof
27 as a parser skeleton. Alternatively, if you modify or redistribute
28 the parser skeleton itself, you may (at your option) remove this
29 special exception, which will cause the skeleton and the resulting
30 Bison output files to be licensed under the GNU General Public
31 License without this special exception.
33 This special exception was added by the Free Software Foundation in
34 version 2.2 of Bison. */
36 /* C LALR(1) parser skeleton written by Richard Stallman, by
37 simplifying the original so-called "semantic" parser. */
39 /* All symbols defined below should begin with yy or YY, to avoid
40 infringing on user name space. This should be done even for local
41 variables, as they might otherwise be expanded by user macros.
42 There are some unavoidable exceptions within include files to
43 define necessary library symbols; they are noted "INFRINGES ON
44 USER NAME SPACE" below. */
46 /* Identify Bison output. */
50 #define YYBISON_VERSION "2.3"
53 #define YYSKELETON_NAME "yacc.c"
58 /* Using locations. */
59 #define YYLSP_NEEDED 0
66 /* Put the tokens into the symbol table, so that GDB and other debuggers
93 #define tHOUR_UNIT 263
94 #define tLOCAL_ZONE 264
96 #define tMINUTE_UNIT 266
98 #define tMONTH_UNIT 268
100 #define tYEAR_UNIT 270
108 /* Copy the first part of user declarations. */
111 /* Parse a string into an internal time stamp.
112 Copyright (C) 1999, 2000, 2002 Free Software Foundation, Inc.
114 This program is free software; you can redistribute it and/or modify
115 it under the terms of the GNU General Public License as published by
116 the Free Software Foundation; either version 2, or (at your option)
119 This program is distributed in the hope that it will be useful,
120 but WITHOUT ANY WARRANTY; without even the implied warranty of
121 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
122 GNU General Public License for more details.
124 You should have received a copy of the GNU General Public License
125 along with this program; if not, see <http://www.gnu.org/licenses/>. */
127 /* Originally written by Steven M. Bellovin <smb@research.att.com> while
128 at the University of North Carolina at Chapel Hill. Later tweaked by
129 a couple of people on Usenet. Completely overhauled by Rich $alz
130 <rsalz@bbn.com> and Jim Berets <jberets@bbn.com> in August, 1990.
132 Modified by Paul Eggert <eggert@twinsun.com> in August 1999 to do
133 the right thing about local DST. Unlike previous versions, this
134 version is reentrant. */
138 # ifdef HAVE_ALLOCA_H
143 /* Since the code of getdate.y is not included in the Emacs executable
144 itself, there is no need to #define static in this file. Even if
145 the code were included in the Emacs executable, it probably
146 wouldn't do any harm to #undef it here; this will only cause
147 problems if we try to write to a static variable, which I don't
148 think this code needs to do. */
157 # include <stdlib.h> /* for `free'; used by Bison 1.27 */
160 #if STDC_HEADERS || (! defined isascii && ! HAVE_ISASCII)
161 # define IN_CTYPE_DOMAIN(c) 1
163 # define IN_CTYPE_DOMAIN(c) isascii (c)
166 #define ISSPACE(c) (IN_CTYPE_DOMAIN (c) && isspace (c))
167 #define ISALPHA(c) (IN_CTYPE_DOMAIN (c) && isalpha (c))
168 #define ISLOWER(c) (IN_CTYPE_DOMAIN (c) && islower (c))
169 #define ISDIGIT_LOCALE(c) (IN_CTYPE_DOMAIN (c) && isdigit (c))
171 /* ISDIGIT differs from ISDIGIT_LOCALE, as follows:
172 - Its arg may be any int or unsigned int; it need not be an unsigned char.
173 - It's guaranteed to evaluate its argument exactly once.
174 - It's typically faster.
175 POSIX says that only '0' through '9' are digits. Prefer ISDIGIT to
176 ISDIGIT_LOCALE unless it's important to use the locale's definition
177 of `digit' even when the host does not conform to POSIX. */
178 #define ISDIGIT(c) ((unsigned) (c) - '0' <= 9)
180 #if STDC_HEADERS || HAVE_STRING_H
184 #if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 8) || __STRICT_ANSI__
185 # define __attribute__(x)
188 #ifndef ATTRIBUTE_UNUSED
189 # define ATTRIBUTE_UNUSED __attribute__ ((__unused__))
192 #define EPOCH_YEAR 1970
193 #define TM_YEAR_BASE 1900
195 #define HOUR(x) ((x) * 60)
197 /* An integer value, and the number of digits in its textual
205 /* An entry in the lexical lookup table. */
213 /* Meridian: am, pm, or 24-hour style. */
214 enum { MERam
, MERpm
, MER24
};
216 /* Information passed to and from the parser. */
219 /* The input string remaining to be parsed. */
222 /* N, if this is the Nth Tuesday. */
225 /* Day of week; Sunday is 0. */
228 /* tm_isdst flag for the local zone. */
231 /* Time zone, in minutes east of UTC. */
234 /* Style used for time. */
237 /* Gregorian year, month, day, hour, minutes, and seconds. */
245 /* Relative year, month, day, hour, minutes, and seconds. */
253 /* Counts of nonterminals of various flavors parsed so far. */
256 int local_zones_seen
;
261 /* Table of local time zone abbrevations, terminated by a null entry. */
262 table local_time_zone_table
[3];
265 #define PC (* (parser_control *) parm)
266 #define YYLEX_PARAM parm
267 #define YYPARSE_PARAM parm
271 /* Enabling traces. */
276 /* Enabling verbose error messages. */
277 #ifdef YYERROR_VERBOSE
278 # undef YYERROR_VERBOSE
279 # define YYERROR_VERBOSE 1
281 # define YYERROR_VERBOSE 0
284 /* Enabling the token table. */
285 #ifndef YYTOKEN_TABLE
286 # define YYTOKEN_TABLE 0
289 #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
290 typedef union YYSTYPE
291 #line 169 "getdate.y"
296 /* Line 187 of yacc.c. */
297 #line 298 "getdate.c"
299 # define yystype YYSTYPE /* obsolescent; will be withdrawn */
300 # define YYSTYPE_IS_DECLARED 1
301 # define YYSTYPE_IS_TRIVIAL 1
306 /* Copy the second part of user declarations. */
307 #line 174 "getdate.y"
310 static int yyerror(const char *);
311 static int yylex(YYSTYPE
*, parser_control
*);
315 /* Line 216 of yacc.c. */
316 #line 317 "getdate.c"
323 typedef YYTYPE_UINT8 yytype_uint8
;
325 typedef unsigned char yytype_uint8
;
329 typedef YYTYPE_INT8 yytype_int8
;
330 #elif (defined __STDC__ || defined __C99__FUNC__ \
331 || defined __cplusplus || defined _MSC_VER)
332 typedef signed char yytype_int8
;
334 typedef short int yytype_int8
;
338 typedef YYTYPE_UINT16 yytype_uint16
;
340 typedef unsigned short int yytype_uint16
;
344 typedef YYTYPE_INT16 yytype_int16
;
346 typedef short int yytype_int16
;
350 # ifdef __SIZE_TYPE__
351 # define YYSIZE_T __SIZE_TYPE__
352 # elif defined size_t
353 # define YYSIZE_T size_t
354 # elif ! defined YYSIZE_T && (defined __STDC__ || defined __C99__FUNC__ \
355 || defined __cplusplus || defined _MSC_VER)
356 # include <stddef.h> /* INFRINGES ON USER NAME SPACE */
357 # define YYSIZE_T size_t
359 # define YYSIZE_T unsigned int
363 #define YYSIZE_MAXIMUM ((YYSIZE_T) -1)
368 # include <libintl.h> /* INFRINGES ON USER NAME SPACE */
369 # define YY_(msgid) dgettext ("bison-runtime", msgid)
373 # define YY_(msgid) msgid
377 /* Suppress unused-variable warnings by "using" E. */
378 #if ! defined lint || defined __GNUC__
379 # define YYUSE(e) ((void) (e))
381 # define YYUSE(e) /* empty */
384 /* Identity function, used to suppress warnings about constant conditions. */
388 #if (defined __STDC__ || defined __C99__FUNC__ \
389 || defined __cplusplus || defined _MSC_VER)
402 #if ! defined yyoverflow || YYERROR_VERBOSE
404 /* The parser invokes alloca or malloc; define the necessary symbols. */
406 # ifdef YYSTACK_USE_ALLOCA
407 # if YYSTACK_USE_ALLOCA
409 # define YYSTACK_ALLOC __builtin_alloca
410 # elif defined __BUILTIN_VA_ARG_INCR
411 # include <alloca.h> /* INFRINGES ON USER NAME SPACE */
413 # define YYSTACK_ALLOC __alloca
414 # elif defined _MSC_VER
415 # include <malloc.h> /* INFRINGES ON USER NAME SPACE */
416 # define alloca _alloca
418 # define YYSTACK_ALLOC alloca
419 # if ! defined _ALLOCA_H && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
420 || defined __cplusplus || defined _MSC_VER)
421 # include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
430 # ifdef YYSTACK_ALLOC
431 /* Pacify GCC's `empty if-body' warning. */
432 # define YYSTACK_FREE(Ptr) do { /* empty */; } while (YYID (0))
433 # ifndef YYSTACK_ALLOC_MAXIMUM
434 /* The OS might guarantee only one guard page at the bottom of the stack,
435 and a page size can be as small as 4096 bytes. So we cannot safely
436 invoke alloca (N) if N exceeds 4096. Use a slightly smaller number
437 to allow for a few compiler-allocated temporary stack slots. */
438 # define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */
441 # define YYSTACK_ALLOC YYMALLOC
442 # define YYSTACK_FREE YYFREE
443 # ifndef YYSTACK_ALLOC_MAXIMUM
444 # define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM
446 # if (defined __cplusplus && ! defined _STDLIB_H \
447 && ! ((defined YYMALLOC || defined malloc) \
448 && (defined YYFREE || defined free)))
449 # include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
455 # define YYMALLOC malloc
456 # if ! defined malloc && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
457 || defined __cplusplus || defined _MSC_VER)
458 void *malloc (YYSIZE_T
); /* INFRINGES ON USER NAME SPACE */
463 # if ! defined free && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
464 || defined __cplusplus || defined _MSC_VER)
465 void free (void *); /* INFRINGES ON USER NAME SPACE */
469 #endif /* ! defined yyoverflow || YYERROR_VERBOSE */
472 #if (! defined yyoverflow \
473 && (! defined __cplusplus \
474 || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
476 /* A type that is properly aligned for any stack member. */
483 /* The size of the maximum gap between one aligned stack and the next. */
484 # define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1)
486 /* The size of an array large to enough to hold all stacks, each with
488 # define YYSTACK_BYTES(N) \
489 ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE)) \
490 + YYSTACK_GAP_MAXIMUM)
492 /* Copy COUNT objects from FROM to TO. The source and destination do
495 # if defined __GNUC__ && 1 < __GNUC__
496 # define YYCOPY(To, From, Count) \
497 __builtin_memcpy (To, From, (Count) * sizeof (*(From)))
499 # define YYCOPY(To, From, Count) \
503 for (yyi = 0; yyi < (Count); yyi++) \
504 (To)[yyi] = (From)[yyi]; \
510 /* Relocate STACK from its old location to the new one. The
511 local variables YYSIZE and YYSTACKSIZE give the old and new number of
512 elements in the stack, and YYPTR gives the new location of the
513 stack. Advance YYPTR to a properly aligned location for the next
515 # define YYSTACK_RELOCATE(Stack) \
518 YYSIZE_T yynewbytes; \
519 YYCOPY (&yyptr->Stack, Stack, yysize); \
520 Stack = &yyptr->Stack; \
521 yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \
522 yyptr += yynewbytes / sizeof (*yyptr); \
528 /* YYFINAL -- State number of the termination state. */
530 /* YYLAST -- Last index in YYTABLE. */
533 /* YYNTOKENS -- Number of terminals. */
535 /* YYNNTS -- Number of nonterminals. */
537 /* YYNRULES -- Number of rules. */
539 /* YYNRULES -- Number of states. */
542 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
544 #define YYMAXUTOK 273
546 #define YYTRANSLATE(YYX) \
547 ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
549 /* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */
550 static const yytype_uint8 yytranslate
[] =
552 0, 2, 2, 2, 2, 2, 2, 2, 2, 2,
553 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
554 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
555 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
556 2, 2, 2, 2, 20, 2, 2, 21, 2, 2,
557 2, 2, 2, 2, 2, 2, 2, 2, 19, 2,
558 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
559 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
560 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
561 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
562 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
563 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
564 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
565 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
566 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
567 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
568 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
569 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
570 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
571 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
572 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
573 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
574 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
575 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
576 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
577 2, 2, 2, 2, 2, 2, 1, 2, 3, 4,
578 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
583 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
585 static const yytype_uint8 yyprhs
[] =
587 0, 0, 3, 4, 7, 9, 11, 13, 15, 17,
588 19, 21, 24, 29, 34, 41, 48, 50, 53, 55,
589 57, 60, 62, 65, 68, 72, 78, 82, 86, 89,
590 94, 97, 101, 104, 106, 109, 112, 114, 117, 120,
591 122, 125, 128, 130, 133, 136, 138, 141, 144, 146,
592 149, 152, 154, 156, 157
595 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
596 static const yytype_int8 yyrhs
[] =
598 23, 0, -1, -1, 23, 24, -1, 25, -1, 26,
599 -1, 27, -1, 29, -1, 28, -1, 30, -1, 32,
600 -1, 18, 10, -1, 18, 19, 18, 33, -1, 18,
601 19, 18, 17, -1, 18, 19, 18, 19, 18, 33,
602 -1, 18, 19, 18, 19, 18, 17, -1, 9, -1,
603 9, 4, -1, 16, -1, 7, -1, 16, 4, -1,
604 5, -1, 5, 20, -1, 18, 5, -1, 18, 21,
605 18, -1, 18, 21, 18, 21, 18, -1, 18, 17,
606 17, -1, 18, 12, 17, -1, 12, 18, -1, 12,
607 18, 20, 18, -1, 18, 12, -1, 18, 12, 18,
608 -1, 31, 3, -1, 31, -1, 18, 15, -1, 17,
609 15, -1, 15, -1, 18, 13, -1, 17, 13, -1,
610 13, -1, 18, 6, -1, 17, 6, -1, 6, -1,
611 18, 8, -1, 17, 8, -1, 8, -1, 18, 11,
612 -1, 17, 11, -1, 11, -1, 18, 14, -1, 17,
613 14, -1, 14, -1, 18, -1, -1, 10, -1
616 /* YYRLINE[YYN] -- source line where rule number YYN was defined. */
617 static const yytype_uint16 yyrline
[] =
619 0, 192, 192, 194, 198, 200, 202, 204, 206, 208,
620 210, 214, 221, 228, 236, 243, 255, 257, 262, 264,
621 266, 271, 276, 281, 289, 294, 314, 321, 329, 334,
622 340, 345, 354, 363, 367, 369, 371, 373, 375, 377,
623 379, 381, 383, 385, 387, 389, 391, 393, 395, 397,
624 399, 401, 406, 443, 444
628 #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
629 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
630 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
631 static const char *const yytname
[] =
633 "$end", "error", "$undefined", "tAGO", "tDST", "tDAY", "tDAY_UNIT",
634 "tDAYZONE", "tHOUR_UNIT", "tLOCAL_ZONE", "tMERIDIAN", "tMINUTE_UNIT",
635 "tMONTH", "tMONTH_UNIT", "tSEC_UNIT", "tYEAR_UNIT", "tZONE", "tSNUMBER",
636 "tUNUMBER", "':'", "','", "'/'", "$accept", "spec", "item", "time",
637 "local_zone", "zone", "day", "date", "rel", "relunit", "number",
643 /* YYTOKNUM[YYLEX-NUM] -- Internal token number corresponding to
645 static const yytype_uint16 yytoknum
[] =
647 0, 256, 257, 258, 259, 260, 261, 262, 263, 264,
648 265, 266, 267, 268, 269, 270, 271, 272, 273, 58,
653 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
654 static const yytype_uint8 yyr1
[] =
656 0, 22, 23, 23, 24, 24, 24, 24, 24, 24,
657 24, 25, 25, 25, 25, 25, 26, 26, 27, 27,
658 27, 28, 28, 28, 29, 29, 29, 29, 29, 29,
659 29, 29, 30, 30, 31, 31, 31, 31, 31, 31,
660 31, 31, 31, 31, 31, 31, 31, 31, 31, 31,
664 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
665 static const yytype_uint8 yyr2
[] =
667 0, 2, 0, 2, 1, 1, 1, 1, 1, 1,
668 1, 2, 4, 4, 6, 6, 1, 2, 1, 1,
669 2, 1, 2, 2, 3, 5, 3, 3, 2, 4,
670 2, 3, 2, 1, 2, 2, 1, 2, 2, 1,
671 2, 2, 1, 2, 2, 1, 2, 2, 1, 2,
675 /* YYDEFACT[STATE-NAME] -- Default rule to reduce with in state
676 STATE-NUM when YYTABLE doesn't specify something else to do. Zero
677 means the default is an error. */
678 static const yytype_uint8 yydefact
[] =
680 2, 0, 1, 21, 42, 19, 45, 16, 48, 0,
681 39, 51, 36, 18, 0, 52, 3, 4, 5, 6,
682 8, 7, 9, 33, 10, 22, 17, 28, 20, 41,
683 44, 47, 38, 50, 35, 23, 40, 43, 11, 46,
684 30, 37, 49, 34, 0, 0, 0, 32, 0, 27,
685 31, 26, 53, 24, 29, 54, 13, 0, 12, 0,
689 /* YYDEFGOTO[NTERM-NUM]. */
690 static const yytype_int8 yydefgoto
[] =
692 -1, 1, 16, 17, 18, 19, 20, 21, 22, 23,
696 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
698 #define YYPACT_NINF -17
699 static const yytype_int8 yypact
[] =
701 -17, 0, -17, 1, -17, -17, -17, 19, -17, -14,
702 -17, -17, -17, 32, 26, 14, -17, -17, -17, -17,
703 -17, -17, -17, 27, -17, -17, -17, 22, -17, -17,
704 -17, -17, -17, -17, -17, -17, -17, -17, -17, -17,
705 -16, -17, -17, -17, 29, 25, 30, -17, 31, -17,
706 -17, -17, 28, 23, -17, -17, -17, 33, -17, 34,
710 /* YYPGOTO[NTERM-NUM]. */
711 static const yytype_int8 yypgoto
[] =
713 -17, -17, -17, -17, -17, -17, -17, -17, -17, -17,
717 /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
718 positive, shift that token. If negative, reduce the rule which
719 number is the opposite. If zero, do what YYDEFACT says.
720 If YYTABLE_NINF, syntax error. */
721 #define YYTABLE_NINF -1
722 static const yytype_uint8 yytable
[] =
724 2, 49, 50, 55, 27, 3, 4, 5, 6, 7,
725 62, 8, 9, 10, 11, 12, 13, 14, 15, 35,
726 36, 25, 37, 26, 38, 39, 40, 41, 42, 43,
727 47, 44, 29, 45, 30, 46, 28, 31, 55, 32,
728 33, 34, 48, 52, 59, 56, 51, 57, 53, 54,
732 static const yytype_uint8 yycheck
[] =
734 0, 17, 18, 10, 18, 5, 6, 7, 8, 9,
735 17, 11, 12, 13, 14, 15, 16, 17, 18, 5,
736 6, 20, 8, 4, 10, 11, 12, 13, 14, 15,
737 3, 17, 6, 19, 8, 21, 4, 11, 10, 13,
738 14, 15, 20, 18, 21, 17, 17, 19, 18, 18,
742 /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
743 symbol of state STATE-NUM. */
744 static const yytype_uint8 yystos
[] =
746 0, 23, 0, 5, 6, 7, 8, 9, 11, 12,
747 13, 14, 15, 16, 17, 18, 24, 25, 26, 27,
748 28, 29, 30, 31, 32, 20, 4, 18, 4, 6,
749 8, 11, 13, 14, 15, 5, 6, 8, 10, 11,
750 12, 13, 14, 15, 17, 19, 21, 3, 20, 17,
751 18, 17, 18, 18, 18, 10, 17, 19, 33, 21,
755 #define yyerrok (yyerrstatus = 0)
756 #define yyclearin (yychar = YYEMPTY)
760 #define YYACCEPT goto yyacceptlab
761 #define YYABORT goto yyabortlab
762 #define YYERROR goto yyerrorlab
765 /* Like YYERROR except do call yyerror. This remains here temporarily
766 to ease the transition to the new meaning of YYERROR, for GCC.
767 Once GCC version 2 has supplanted version 1, this can go. */
769 #define YYFAIL goto yyerrlab
771 #define YYRECOVERING() (!!yyerrstatus)
773 #define YYBACKUP(Token, Value) \
775 if (yychar == YYEMPTY && yylen == 1) \
779 yytoken = YYTRANSLATE (yychar); \
785 yyerror (YY_("syntax error: cannot back up")); \
792 #define YYERRCODE 256
795 /* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
796 If N is 0, then set CURRENT to the empty location which ends
797 the previous symbol: RHS[0] (always defined). */
799 #define YYRHSLOC(Rhs, K) ((Rhs)[K])
800 #ifndef YYLLOC_DEFAULT
801 # define YYLLOC_DEFAULT(Current, Rhs, N) \
805 (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \
806 (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \
807 (Current).last_line = YYRHSLOC (Rhs, N).last_line; \
808 (Current).last_column = YYRHSLOC (Rhs, N).last_column; \
812 (Current).first_line = (Current).last_line = \
813 YYRHSLOC (Rhs, 0).last_line; \
814 (Current).first_column = (Current).last_column = \
815 YYRHSLOC (Rhs, 0).last_column; \
821 /* YY_LOCATION_PRINT -- Print the location on the stream.
822 This macro was not mandated originally: define only if we know
823 we won't break user code: when these are the locations we know. */
825 #ifndef YY_LOCATION_PRINT
826 # if YYLTYPE_IS_TRIVIAL
827 # define YY_LOCATION_PRINT(File, Loc) \
828 fprintf (File, "%d.%d-%d.%d", \
829 (Loc).first_line, (Loc).first_column, \
830 (Loc).last_line, (Loc).last_column)
832 # define YY_LOCATION_PRINT(File, Loc) ((void) 0)
837 /* YYLEX -- calling `yylex' with the right arguments. */
840 # define YYLEX yylex (&yylval, YYLEX_PARAM)
842 # define YYLEX yylex (&yylval)
845 /* Enable debugging if requested. */
849 # include <stdio.h> /* INFRINGES ON USER NAME SPACE */
850 # define YYFPRINTF fprintf
853 # define YYDPRINTF(Args) \
859 # define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
863 YYFPRINTF (stderr, "%s ", Title); \
864 yy_symbol_print (stderr, \
866 YYFPRINTF (stderr, "\n"); \
871 /*--------------------------------.
872 | Print this symbol on YYOUTPUT. |
873 `--------------------------------*/
876 #if (defined __STDC__ || defined __C99__FUNC__ \
877 || defined __cplusplus || defined _MSC_VER)
879 yy_symbol_value_print (FILE *yyoutput
, int yytype
, YYSTYPE
const * const yyvaluep
)
882 yy_symbol_value_print (yyoutput
, yytype
, yyvaluep
)
885 YYSTYPE
const * const yyvaluep
;
891 if (yytype
< YYNTOKENS
)
892 YYPRINT (yyoutput
, yytoknum
[yytype
], *yyvaluep
);
904 /*--------------------------------.
905 | Print this symbol on YYOUTPUT. |
906 `--------------------------------*/
908 #if (defined __STDC__ || defined __C99__FUNC__ \
909 || defined __cplusplus || defined _MSC_VER)
911 yy_symbol_print (FILE *yyoutput
, int yytype
, YYSTYPE
const * const yyvaluep
)
914 yy_symbol_print (yyoutput
, yytype
, yyvaluep
)
917 YYSTYPE
const * const yyvaluep
;
920 if (yytype
< YYNTOKENS
)
921 YYFPRINTF (yyoutput
, "token %s (", yytname
[yytype
]);
923 YYFPRINTF (yyoutput
, "nterm %s (", yytname
[yytype
]);
925 yy_symbol_value_print (yyoutput
, yytype
, yyvaluep
);
926 YYFPRINTF (yyoutput
, ")");
929 /*------------------------------------------------------------------.
930 | yy_stack_print -- Print the state stack from its BOTTOM up to its |
932 `------------------------------------------------------------------*/
934 #if (defined __STDC__ || defined __C99__FUNC__ \
935 || defined __cplusplus || defined _MSC_VER)
937 yy_stack_print (yytype_int16
*bottom
, yytype_int16
*top
)
940 yy_stack_print (bottom
, top
)
941 yytype_int16
*bottom
;
945 YYFPRINTF (stderr
, "Stack now");
946 for (; bottom
<= top
; ++bottom
)
947 YYFPRINTF (stderr
, " %d", *bottom
);
948 YYFPRINTF (stderr
, "\n");
951 # define YY_STACK_PRINT(Bottom, Top) \
954 yy_stack_print ((Bottom), (Top)); \
958 /*------------------------------------------------.
959 | Report that the YYRULE is going to be reduced. |
960 `------------------------------------------------*/
962 #if (defined __STDC__ || defined __C99__FUNC__ \
963 || defined __cplusplus || defined _MSC_VER)
965 yy_reduce_print (YYSTYPE
*yyvsp
, int yyrule
)
968 yy_reduce_print (yyvsp
, yyrule
)
973 int yynrhs
= yyr2
[yyrule
];
975 unsigned long int yylno
= yyrline
[yyrule
];
976 YYFPRINTF (stderr
, "Reducing stack by rule %d (line %lu):\n",
978 /* The symbols being reduced. */
979 for (yyi
= 0; yyi
< yynrhs
; yyi
++)
981 fprintf (stderr
, " $%d = ", yyi
+ 1);
982 yy_symbol_print (stderr
, yyrhs
[yyprhs
[yyrule
] + yyi
],
983 &(yyvsp
[(yyi
+ 1) - (yynrhs
)])
985 fprintf (stderr
, "\n");
989 # define YY_REDUCE_PRINT(Rule) \
992 yy_reduce_print (yyvsp, Rule); \
995 /* Nonzero means print parse trace. It is left uninitialized so that
996 multiple parsers can coexist. */
999 # define YYDPRINTF(Args)
1000 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
1001 # define YY_STACK_PRINT(Bottom, Top)
1002 # define YY_REDUCE_PRINT(Rule)
1003 #endif /* !YYDEBUG */
1006 /* YYINITDEPTH -- initial size of the parser's stacks. */
1008 # define YYINITDEPTH 200
1011 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
1012 if the built-in stack extension method is used).
1014 Do not make this value too large; the results are undefined if
1015 YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH)
1016 evaluated with infinite-precision integer arithmetic. */
1019 # define YYMAXDEPTH 10000
1027 # if defined __GLIBC__ && defined _STRING_H
1028 # define yystrlen strlen
1030 /* Return the length of YYSTR. */
1031 #if (defined __STDC__ || defined __C99__FUNC__ \
1032 || defined __cplusplus || defined _MSC_VER)
1034 yystrlen (const char *yystr
)
1042 for (yylen
= 0; yystr
[yylen
]; yylen
++)
1050 # if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
1051 # define yystpcpy stpcpy
1053 /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
1055 #if (defined __STDC__ || defined __C99__FUNC__ \
1056 || defined __cplusplus || defined _MSC_VER)
1058 yystpcpy (char *yydest
, const char *yysrc
)
1061 yystpcpy (yydest
, yysrc
)
1067 const char *yys
= yysrc
;
1069 while ((*yyd
++ = *yys
++) != '\0')
1078 /* Copy to YYRES the contents of YYSTR after stripping away unnecessary
1079 quotes and backslashes, so that it's suitable for yyerror. The
1080 heuristic is that double-quoting is unnecessary unless the string
1081 contains an apostrophe, a comma, or backslash (other than
1082 backslash-backslash). YYSTR is taken from yytname. If YYRES is
1083 null, do not copy; instead, return the length of what the result
1086 yytnamerr (char *yyres
, const char *yystr
)
1091 char const *yyp
= yystr
;
1098 goto do_not_strip_quotes
;
1102 goto do_not_strip_quotes
;
1115 do_not_strip_quotes
: ;
1119 return yystrlen (yystr
);
1121 return yystpcpy (yyres
, yystr
) - yyres
;
1125 /* Copy into YYRESULT an error message about the unexpected token
1126 YYCHAR while in state YYSTATE. Return the number of bytes copied,
1127 including the terminating null byte. If YYRESULT is null, do not
1128 copy anything; just return the number of bytes that would be
1129 copied. As a special case, return 0 if an ordinary "syntax error"
1130 message will do. Return YYSIZE_MAXIMUM if overflow occurs during
1131 size calculation. */
1133 yysyntax_error (char *yyresult
, int yystate
, int yychar
)
1135 int yyn
= yypact
[yystate
];
1137 if (! (YYPACT_NINF
< yyn
&& yyn
<= YYLAST
))
1141 int yytype
= YYTRANSLATE (yychar
);
1142 YYSIZE_T yysize0
= yytnamerr (0, yytname
[yytype
]);
1143 YYSIZE_T yysize
= yysize0
;
1145 int yysize_overflow
= 0;
1146 enum { YYERROR_VERBOSE_ARGS_MAXIMUM
= 5 };
1147 char const *yyarg
[YYERROR_VERBOSE_ARGS_MAXIMUM
];
1151 /* This is so xgettext sees the translatable formats that are
1152 constructed on the fly. */
1153 YY_("syntax error, unexpected %s");
1154 YY_("syntax error, unexpected %s, expecting %s");
1155 YY_("syntax error, unexpected %s, expecting %s or %s");
1156 YY_("syntax error, unexpected %s, expecting %s or %s or %s");
1157 YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s");
1161 static char const yyunexpected
[] = "syntax error, unexpected %s";
1162 static char const yyexpecting
[] = ", expecting %s";
1163 static char const yyor
[] = " or %s";
1164 char yyformat
[sizeof yyunexpected
1165 + sizeof yyexpecting
- 1
1166 + ((YYERROR_VERBOSE_ARGS_MAXIMUM
- 2)
1167 * (sizeof yyor
- 1))];
1168 char const *yyprefix
= yyexpecting
;
1170 /* Start YYX at -YYN if negative to avoid negative indexes in
1172 int yyxbegin
= yyn
< 0 ? -yyn
: 0;
1174 /* Stay within bounds of both yycheck and yytname. */
1175 int yychecklim
= YYLAST
- yyn
+ 1;
1176 int yyxend
= yychecklim
< YYNTOKENS
? yychecklim
: YYNTOKENS
;
1179 yyarg
[0] = yytname
[yytype
];
1180 yyfmt
= yystpcpy (yyformat
, yyunexpected
);
1182 for (yyx
= yyxbegin
; yyx
< yyxend
; ++yyx
)
1183 if (yycheck
[yyx
+ yyn
] == yyx
&& yyx
!= YYTERROR
)
1185 if (yycount
== YYERROR_VERBOSE_ARGS_MAXIMUM
)
1189 yyformat
[sizeof yyunexpected
- 1] = '\0';
1192 yyarg
[yycount
++] = yytname
[yyx
];
1193 yysize1
= yysize
+ yytnamerr (0, yytname
[yyx
]);
1194 yysize_overflow
|= (yysize1
< yysize
);
1196 yyfmt
= yystpcpy (yyfmt
, yyprefix
);
1200 yyf
= YY_(yyformat
);
1201 yysize1
= yysize
+ yystrlen (yyf
);
1202 yysize_overflow
|= (yysize1
< yysize
);
1205 if (yysize_overflow
)
1206 return YYSIZE_MAXIMUM
;
1210 /* Avoid sprintf, as that infringes on the user's name space.
1211 Don't have undefined behavior even if the translation
1212 produced a string with the wrong number of "%s"s. */
1213 char *yyp
= yyresult
;
1215 while ((*yyp
= *yyf
) != '\0')
1217 if (*yyp
== '%' && yyf
[1] == 's' && yyi
< yycount
)
1219 yyp
+= yytnamerr (yyp
, yyarg
[yyi
++]);
1232 #endif /* YYERROR_VERBOSE */
1235 /*-----------------------------------------------.
1236 | Release the memory associated to this symbol. |
1237 `-----------------------------------------------*/
1240 #if (defined __STDC__ || defined __C99__FUNC__ \
1241 || defined __cplusplus || defined _MSC_VER)
1243 yydestruct (const char *yymsg
, int yytype
, YYSTYPE
*yyvaluep
)
1246 yydestruct (yymsg
, yytype
, yyvaluep
)
1256 YY_SYMBOL_PRINT (yymsg
, yytype
, yyvaluep
, yylocationp
);
1267 /* Prevent warnings from -Wmissing-prototypes. */
1269 #ifdef YYPARSE_PARAM
1270 #if defined __STDC__ || defined __cplusplus
1271 int yyparse (void *YYPARSE_PARAM
);
1275 #else /* ! YYPARSE_PARAM */
1276 #if defined __STDC__ || defined __cplusplus
1281 #endif /* ! YYPARSE_PARAM */
1292 #ifdef YYPARSE_PARAM
1293 #if (defined __STDC__ || defined __C99__FUNC__ \
1294 || defined __cplusplus || defined _MSC_VER)
1296 yyparse (void *YYPARSE_PARAM
)
1299 yyparse (YYPARSE_PARAM
)
1300 void *YYPARSE_PARAM
;
1302 #else /* ! YYPARSE_PARAM */
1303 #if (defined __STDC__ || defined __C99__FUNC__ \
1304 || defined __cplusplus || defined _MSC_VER)
1314 /* The look-ahead symbol. */
1317 /* The semantic value of the look-ahead symbol. */
1320 /* Number of syntax errors so far. */
1326 /* Number of tokens to shift before error messages enabled. */
1328 /* Look-ahead token as an internal (translated) token number. */
1331 /* Buffer for error messages, and its allocated size. */
1333 char *yymsg
= yymsgbuf
;
1334 YYSIZE_T yymsg_alloc
= sizeof yymsgbuf
;
1337 /* Three stacks and their tools:
1338 `yyss': related to states,
1339 `yyvs': related to semantic values,
1340 `yyls': related to locations.
1342 Refer to the stacks thru separate pointers, to allow yyoverflow
1343 to reallocate them elsewhere. */
1345 /* The state stack. */
1346 yytype_int16 yyssa
[YYINITDEPTH
];
1347 yytype_int16
*yyss
= yyssa
;
1348 yytype_int16
*yyssp
;
1350 /* The semantic value stack. */
1351 YYSTYPE yyvsa
[YYINITDEPTH
];
1352 YYSTYPE
*yyvs
= yyvsa
;
1357 #define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N))
1359 YYSIZE_T yystacksize
= YYINITDEPTH
;
1361 /* The variables used to return semantic value and location from the
1366 /* The number of symbols on the RHS of the reduced rule.
1367 Keep to zero when no symbol should be popped. */
1370 YYDPRINTF ((stderr
, "Starting parse\n"));
1375 yychar
= YYEMPTY
; /* Cause a token to be read. */
1377 /* Initialize stack pointers.
1378 Waste one element of value and location stack
1379 so that they stay on the same level as the state stack.
1380 The wasted elements are never initialized. */
1387 /*------------------------------------------------------------.
1388 | yynewstate -- Push a new state, which is found in yystate. |
1389 `------------------------------------------------------------*/
1391 /* In all cases, when you get here, the value and location stacks
1392 have just been pushed. So pushing a state here evens the stacks. */
1398 if (yyss
+ yystacksize
- 1 <= yyssp
)
1400 /* Get the current used size of the three stacks, in elements. */
1401 YYSIZE_T yysize
= yyssp
- yyss
+ 1;
1405 /* Give user a chance to reallocate the stack. Use copies of
1406 these so that the &'s don't force the real ones into
1408 YYSTYPE
*yyvs1
= yyvs
;
1409 yytype_int16
*yyss1
= yyss
;
1412 /* Each stack pointer address is followed by the size of the
1413 data in use in that stack, in bytes. This used to be a
1414 conditional around just the two extra args, but that might
1415 be undefined if yyoverflow is a macro. */
1416 yyoverflow (YY_("memory exhausted"),
1417 &yyss1
, yysize
* sizeof (*yyssp
),
1418 &yyvs1
, yysize
* sizeof (*yyvsp
),
1425 #else /* no yyoverflow */
1426 # ifndef YYSTACK_RELOCATE
1427 goto yyexhaustedlab
;
1429 /* Extend the stack our own way. */
1430 if (YYMAXDEPTH
<= yystacksize
)
1431 goto yyexhaustedlab
;
1433 if (YYMAXDEPTH
< yystacksize
)
1434 yystacksize
= YYMAXDEPTH
;
1437 yytype_int16
*yyss1
= yyss
;
1438 union yyalloc
*yyptr
=
1439 (union yyalloc
*) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize
));
1441 goto yyexhaustedlab
;
1442 YYSTACK_RELOCATE (yyss
);
1443 YYSTACK_RELOCATE (yyvs
);
1445 # undef YYSTACK_RELOCATE
1447 YYSTACK_FREE (yyss1
);
1450 #endif /* no yyoverflow */
1452 yyssp
= yyss
+ yysize
- 1;
1453 yyvsp
= yyvs
+ yysize
- 1;
1456 YYDPRINTF ((stderr
, "Stack size increased to %lu\n",
1457 (unsigned long int) yystacksize
));
1459 if (yyss
+ yystacksize
- 1 <= yyssp
)
1463 YYDPRINTF ((stderr
, "Entering state %d\n", yystate
));
1472 /* Do appropriate processing given the current state. Read a
1473 look-ahead token if we need one and don't already have one. */
1475 /* First try to decide what to do without reference to look-ahead token. */
1476 yyn
= yypact
[yystate
];
1477 if (yyn
== YYPACT_NINF
)
1480 /* Not known => get a look-ahead token if don't already have one. */
1482 /* YYCHAR is either YYEMPTY or YYEOF or a valid look-ahead symbol. */
1483 if (yychar
== YYEMPTY
)
1485 YYDPRINTF ((stderr
, "Reading a token: "));
1489 if (yychar
<= YYEOF
)
1491 yychar
= yytoken
= YYEOF
;
1492 YYDPRINTF ((stderr
, "Now at end of input.\n"));
1496 yytoken
= YYTRANSLATE (yychar
);
1497 YY_SYMBOL_PRINT ("Next token is", yytoken
, &yylval
, &yylloc
);
1500 /* If the proper action on seeing token YYTOKEN is to reduce or to
1501 detect an error, take that action. */
1503 if (yyn
< 0 || YYLAST
< yyn
|| yycheck
[yyn
] != yytoken
)
1508 if (yyn
== 0 || yyn
== YYTABLE_NINF
)
1517 /* Count tokens shifted since error; after three, turn off error
1522 /* Shift the look-ahead token. */
1523 YY_SYMBOL_PRINT ("Shifting", yytoken
, &yylval
, &yylloc
);
1525 /* Discard the shifted token unless it is eof. */
1526 if (yychar
!= YYEOF
)
1535 /*-----------------------------------------------------------.
1536 | yydefault -- do the default action for the current state. |
1537 `-----------------------------------------------------------*/
1539 yyn
= yydefact
[yystate
];
1545 /*-----------------------------.
1546 | yyreduce -- Do a reduction. |
1547 `-----------------------------*/
1549 /* yyn is the number of a rule to reduce with. */
1552 /* If YYLEN is nonzero, implement the default value of the action:
1555 Otherwise, the following line sets YYVAL to garbage.
1556 This behavior is undocumented and Bison
1557 users should not rely upon it. Assigning to YYVAL
1558 unconditionally makes the parser a bit smaller, and it avoids a
1559 GCC warning that YYVAL may be used uninitialized. */
1560 yyval
= yyvsp
[1-yylen
];
1563 YY_REDUCE_PRINT (yyn
);
1567 #line 199 "getdate.y"
1568 { PC
.times_seen
++; ;}
1572 #line 201 "getdate.y"
1573 { PC
.local_zones_seen
++; ;}
1577 #line 203 "getdate.y"
1578 { PC
.zones_seen
++; ;}
1582 #line 205 "getdate.y"
1583 { PC
.dates_seen
++; ;}
1587 #line 207 "getdate.y"
1588 { PC
.days_seen
++; ;}
1592 #line 209 "getdate.y"
1593 { PC
.rels_seen
++; ;}
1597 #line 215 "getdate.y"
1599 PC
.hour
= (yyvsp
[(1) - (2)].textintval
).value
;
1602 PC
.meridian
= (yyvsp
[(2) - (2)].intval
);
1607 #line 222 "getdate.y"
1609 PC
.hour
= (yyvsp
[(1) - (4)].textintval
).value
;
1610 PC
.minutes
= (yyvsp
[(3) - (4)].textintval
).value
;
1612 PC
.meridian
= (yyvsp
[(4) - (4)].intval
);
1617 #line 229 "getdate.y"
1619 PC
.hour
= (yyvsp
[(1) - (4)].textintval
).value
;
1620 PC
.minutes
= (yyvsp
[(3) - (4)].textintval
).value
;
1621 PC
.meridian
= MER24
;
1623 PC
.time_zone
= (yyvsp
[(4) - (4)].textintval
).value
% 100 + ((yyvsp
[(4) - (4)].textintval
).value
/ 100) * 60;
1628 #line 237 "getdate.y"
1630 PC
.hour
= (yyvsp
[(1) - (6)].textintval
).value
;
1631 PC
.minutes
= (yyvsp
[(3) - (6)].textintval
).value
;
1632 PC
.seconds
= (yyvsp
[(5) - (6)].textintval
).value
;
1633 PC
.meridian
= (yyvsp
[(6) - (6)].intval
);
1638 #line 244 "getdate.y"
1640 PC
.hour
= (yyvsp
[(1) - (6)].textintval
).value
;
1641 PC
.minutes
= (yyvsp
[(3) - (6)].textintval
).value
;
1642 PC
.seconds
= (yyvsp
[(5) - (6)].textintval
).value
;
1643 PC
.meridian
= MER24
;
1645 PC
.time_zone
= (yyvsp
[(6) - (6)].textintval
).value
% 100 + ((yyvsp
[(6) - (6)].textintval
).value
/ 100) * 60;
1650 #line 256 "getdate.y"
1651 { PC
.local_isdst
= (yyvsp
[(1) - (1)].intval
); ;}
1655 #line 258 "getdate.y"
1656 { PC
.local_isdst
= (yyvsp
[(1) - (2)].intval
) < 0 ? 1 : (yyvsp
[(1) - (2)].intval
) + 1; ;}
1660 #line 263 "getdate.y"
1661 { PC
.time_zone
= (yyvsp
[(1) - (1)].intval
); ;}
1665 #line 265 "getdate.y"
1666 { PC
.time_zone
= (yyvsp
[(1) - (1)].intval
) + 60; ;}
1670 #line 267 "getdate.y"
1671 { PC
.time_zone
= (yyvsp
[(1) - (2)].intval
) + 60; ;}
1675 #line 272 "getdate.y"
1678 PC
.day_number
= (yyvsp
[(1) - (1)].intval
);
1683 #line 277 "getdate.y"
1686 PC
.day_number
= (yyvsp
[(1) - (2)].intval
);
1691 #line 282 "getdate.y"
1693 PC
.day_ordinal
= (yyvsp
[(1) - (2)].textintval
).value
;
1694 PC
.day_number
= (yyvsp
[(2) - (2)].intval
);
1699 #line 290 "getdate.y"
1701 PC
.month
= (yyvsp
[(1) - (3)].textintval
).value
;
1702 PC
.day
= (yyvsp
[(3) - (3)].textintval
).value
;
1707 #line 295 "getdate.y"
1709 /* Interpret as YYYY/MM/DD if the first value has 4 or more digits,
1710 otherwise as MM/DD/YY.
1711 The goal in recognizing YYYY/MM/DD is solely to support legacy
1712 machine-generated dates like those in an RCS log listing. If
1713 you want portability, use the ISO 8601 format. */
1714 if (4 <= (yyvsp
[(1) - (5)].textintval
).digits
)
1716 PC
.year
= (yyvsp
[(1) - (5)].textintval
);
1717 PC
.month
= (yyvsp
[(3) - (5)].textintval
).value
;
1718 PC
.day
= (yyvsp
[(5) - (5)].textintval
).value
;
1722 PC
.month
= (yyvsp
[(1) - (5)].textintval
).value
;
1723 PC
.day
= (yyvsp
[(3) - (5)].textintval
).value
;
1724 PC
.year
= (yyvsp
[(5) - (5)].textintval
);
1730 #line 315 "getdate.y"
1732 /* ISO 8601 format. YYYY-MM-DD. */
1733 PC
.year
= (yyvsp
[(1) - (3)].textintval
);
1734 PC
.month
= -(yyvsp
[(2) - (3)].textintval
).value
;
1735 PC
.day
= -(yyvsp
[(3) - (3)].textintval
).value
;
1740 #line 322 "getdate.y"
1742 /* e.g. 17-JUN-1992. */
1743 PC
.day
= (yyvsp
[(1) - (3)].textintval
).value
;
1744 PC
.month
= (yyvsp
[(2) - (3)].intval
);
1745 PC
.year
.value
= -(yyvsp
[(3) - (3)].textintval
).value
;
1746 PC
.year
.digits
= (yyvsp
[(3) - (3)].textintval
).digits
;
1751 #line 330 "getdate.y"
1753 PC
.month
= (yyvsp
[(1) - (2)].intval
);
1754 PC
.day
= (yyvsp
[(2) - (2)].textintval
).value
;
1759 #line 335 "getdate.y"
1761 PC
.month
= (yyvsp
[(1) - (4)].intval
);
1762 PC
.day
= (yyvsp
[(2) - (4)].textintval
).value
;
1763 PC
.year
= (yyvsp
[(4) - (4)].textintval
);
1768 #line 341 "getdate.y"
1770 PC
.day
= (yyvsp
[(1) - (2)].textintval
).value
;
1771 PC
.month
= (yyvsp
[(2) - (2)].intval
);
1776 #line 346 "getdate.y"
1778 PC
.day
= (yyvsp
[(1) - (3)].textintval
).value
;
1779 PC
.month
= (yyvsp
[(2) - (3)].intval
);
1780 PC
.year
= (yyvsp
[(3) - (3)].textintval
);
1785 #line 355 "getdate.y"
1787 PC
.rel_seconds
= -PC
.rel_seconds
;
1788 PC
.rel_minutes
= -PC
.rel_minutes
;
1789 PC
.rel_hour
= -PC
.rel_hour
;
1790 PC
.rel_day
= -PC
.rel_day
;
1791 PC
.rel_month
= -PC
.rel_month
;
1792 PC
.rel_year
= -PC
.rel_year
;
1797 #line 368 "getdate.y"
1798 { PC
.rel_year
+= (yyvsp
[(1) - (2)].textintval
).value
* (yyvsp
[(2) - (2)].intval
); ;}
1802 #line 370 "getdate.y"
1803 { PC
.rel_year
+= (yyvsp
[(1) - (2)].textintval
).value
* (yyvsp
[(2) - (2)].intval
); ;}
1807 #line 372 "getdate.y"
1808 { PC
.rel_year
+= (yyvsp
[(1) - (1)].intval
); ;}
1812 #line 374 "getdate.y"
1813 { PC
.rel_month
+= (yyvsp
[(1) - (2)].textintval
).value
* (yyvsp
[(2) - (2)].intval
); ;}
1817 #line 376 "getdate.y"
1818 { PC
.rel_month
+= (yyvsp
[(1) - (2)].textintval
).value
* (yyvsp
[(2) - (2)].intval
); ;}
1822 #line 378 "getdate.y"
1823 { PC
.rel_month
+= (yyvsp
[(1) - (1)].intval
); ;}
1827 #line 380 "getdate.y"
1828 { PC
.rel_day
+= (yyvsp
[(1) - (2)].textintval
).value
* (yyvsp
[(2) - (2)].intval
); ;}
1832 #line 382 "getdate.y"
1833 { PC
.rel_day
+= (yyvsp
[(1) - (2)].textintval
).value
* (yyvsp
[(2) - (2)].intval
); ;}
1837 #line 384 "getdate.y"
1838 { PC
.rel_day
+= (yyvsp
[(1) - (1)].intval
); ;}
1842 #line 386 "getdate.y"
1843 { PC
.rel_hour
+= (yyvsp
[(1) - (2)].textintval
).value
* (yyvsp
[(2) - (2)].intval
); ;}
1847 #line 388 "getdate.y"
1848 { PC
.rel_hour
+= (yyvsp
[(1) - (2)].textintval
).value
* (yyvsp
[(2) - (2)].intval
); ;}
1852 #line 390 "getdate.y"
1853 { PC
.rel_hour
+= (yyvsp
[(1) - (1)].intval
); ;}
1857 #line 392 "getdate.y"
1858 { PC
.rel_minutes
+= (yyvsp
[(1) - (2)].textintval
).value
* (yyvsp
[(2) - (2)].intval
); ;}
1862 #line 394 "getdate.y"
1863 { PC
.rel_minutes
+= (yyvsp
[(1) - (2)].textintval
).value
* (yyvsp
[(2) - (2)].intval
); ;}
1867 #line 396 "getdate.y"
1868 { PC
.rel_minutes
+= (yyvsp
[(1) - (1)].intval
); ;}
1872 #line 398 "getdate.y"
1873 { PC
.rel_seconds
+= (yyvsp
[(1) - (2)].textintval
).value
* (yyvsp
[(2) - (2)].intval
); ;}
1877 #line 400 "getdate.y"
1878 { PC
.rel_seconds
+= (yyvsp
[(1) - (2)].textintval
).value
* (yyvsp
[(2) - (2)].intval
); ;}
1882 #line 402 "getdate.y"
1883 { PC
.rel_seconds
+= (yyvsp
[(1) - (1)].intval
); ;}
1887 #line 407 "getdate.y"
1890 && ! PC
.rels_seen
&& (PC
.times_seen
|| 2 < (yyvsp
[(1) - (1)].textintval
).digits
))
1891 PC
.year
= (yyvsp
[(1) - (1)].textintval
);
1894 if (4 < (yyvsp
[(1) - (1)].textintval
).digits
)
1897 PC
.day
= (yyvsp
[(1) - (1)].textintval
).value
% 100;
1898 PC
.month
= ((yyvsp
[(1) - (1)].textintval
).value
/ 100) % 100;
1899 PC
.year
.value
= (yyvsp
[(1) - (1)].textintval
).value
/ 10000;
1900 PC
.year
.digits
= (yyvsp
[(1) - (1)].textintval
).digits
- 4;
1905 if ((yyvsp
[(1) - (1)].textintval
).digits
<= 2)
1907 PC
.hour
= (yyvsp
[(1) - (1)].textintval
).value
;
1912 PC
.hour
= (yyvsp
[(1) - (1)].textintval
).value
/ 100;
1913 PC
.minutes
= (yyvsp
[(1) - (1)].textintval
).value
% 100;
1916 PC
.meridian
= MER24
;
1923 #line 443 "getdate.y"
1924 { (yyval
.intval
) = MER24
; ;}
1928 #line 445 "getdate.y"
1929 { (yyval
.intval
) = (yyvsp
[(1) - (1)].intval
); ;}
1933 /* Line 1267 of yacc.c. */
1934 #line 1935 "getdate.c"
1937 YY_SYMBOL_PRINT ("-> $$ =", yyr1
[yyn
], &yyval
, &yyloc
);
1941 YY_STACK_PRINT (yyss
, yyssp
);
1946 /* Now `shift' the result of the reduction. Determine what state
1947 that goes to, based on the state we popped back to and the rule
1948 number reduced by. */
1952 yystate
= yypgoto
[yyn
- YYNTOKENS
] + *yyssp
;
1953 if (0 <= yystate
&& yystate
<= YYLAST
&& yycheck
[yystate
] == *yyssp
)
1954 yystate
= yytable
[yystate
];
1956 yystate
= yydefgoto
[yyn
- YYNTOKENS
];
1961 /*------------------------------------.
1962 | yyerrlab -- here on detecting error |
1963 `------------------------------------*/
1965 /* If not already recovering from an error, report this error. */
1969 #if ! YYERROR_VERBOSE
1970 yyerror (YY_("syntax error"));
1973 YYSIZE_T yysize
= yysyntax_error (0, yystate
, yychar
);
1974 if (yymsg_alloc
< yysize
&& yymsg_alloc
< YYSTACK_ALLOC_MAXIMUM
)
1976 YYSIZE_T yyalloc
= 2 * yysize
;
1977 if (! (yysize
<= yyalloc
&& yyalloc
<= YYSTACK_ALLOC_MAXIMUM
))
1978 yyalloc
= YYSTACK_ALLOC_MAXIMUM
;
1979 if (yymsg
!= yymsgbuf
)
1980 YYSTACK_FREE (yymsg
);
1981 yymsg
= (char *) YYSTACK_ALLOC (yyalloc
);
1983 yymsg_alloc
= yyalloc
;
1987 yymsg_alloc
= sizeof yymsgbuf
;
1991 if (0 < yysize
&& yysize
<= yymsg_alloc
)
1993 (void) yysyntax_error (yymsg
, yystate
, yychar
);
1998 yyerror (YY_("syntax error"));
2000 goto yyexhaustedlab
;
2008 if (yyerrstatus
== 3)
2010 /* If just tried and failed to reuse look-ahead token after an
2011 error, discard it. */
2013 if (yychar
<= YYEOF
)
2015 /* Return failure if at end of input. */
2016 if (yychar
== YYEOF
)
2021 yydestruct ("Error: discarding",
2027 /* Else will try to reuse look-ahead token after shifting the error
2032 /*---------------------------------------------------.
2033 | yyerrorlab -- error raised explicitly by YYERROR. |
2034 `---------------------------------------------------*/
2037 /* Pacify compilers like GCC when the user code never invokes
2038 YYERROR and the label yyerrorlab therefore never appears in user
2040 if (/*CONSTCOND*/ 0)
2043 /* Do not reclaim the symbols of the rule which action triggered
2047 YY_STACK_PRINT (yyss
, yyssp
);
2052 /*-------------------------------------------------------------.
2053 | yyerrlab1 -- common code for both syntax error and YYERROR. |
2054 `-------------------------------------------------------------*/
2056 yyerrstatus
= 3; /* Each real token shifted decrements this. */
2060 yyn
= yypact
[yystate
];
2061 if (yyn
!= YYPACT_NINF
)
2064 if (0 <= yyn
&& yyn
<= YYLAST
&& yycheck
[yyn
] == YYTERROR
)
2072 /* Pop the current state because it cannot handle the error token. */
2077 yydestruct ("Error: popping",
2078 yystos
[yystate
], yyvsp
);
2081 YY_STACK_PRINT (yyss
, yyssp
);
2090 /* Shift the error token. */
2091 YY_SYMBOL_PRINT ("Shifting", yystos
[yyn
], yyvsp
, yylsp
);
2097 /*-------------------------------------.
2098 | yyacceptlab -- YYACCEPT comes here. |
2099 `-------------------------------------*/
2104 /*-----------------------------------.
2105 | yyabortlab -- YYABORT comes here. |
2106 `-----------------------------------*/
2112 /*-------------------------------------------------.
2113 | yyexhaustedlab -- memory exhaustion comes here. |
2114 `-------------------------------------------------*/
2116 yyerror (YY_("memory exhausted"));
2122 if (yychar
!= YYEOF
&& yychar
!= YYEMPTY
)
2123 yydestruct ("Cleanup: discarding lookahead",
2125 /* Do not reclaim the symbols of the rule which action triggered
2126 this YYABORT or YYACCEPT. */
2128 YY_STACK_PRINT (yyss
, yyssp
);
2129 while (yyssp
!= yyss
)
2131 yydestruct ("Cleanup: popping",
2132 yystos
[*yyssp
], yyvsp
);
2137 YYSTACK_FREE (yyss
);
2140 if (yymsg
!= yymsgbuf
)
2141 YYSTACK_FREE (yymsg
);
2143 /* Make sure YYID is used. */
2144 return YYID (yyresult
);
2148 #line 448 "getdate.y"
2151 /* Include this file down here because bison inserts code above which
2152 may define-away `const'. We want the prototype for get_date to have
2153 the same signature as the function definition. */
2154 #include "modules/getdate.h"
2157 struct tm
*gmtime (const time_t *);
2160 struct tm
*localtime (const time_t *);
2163 time_t mktime (struct tm
*);
2166 static table
const meridian_table
[] =
2168 { "AM", tMERIDIAN
, MERam
},
2169 { "A.M.", tMERIDIAN
, MERam
},
2170 { "PM", tMERIDIAN
, MERpm
},
2171 { "P.M.", tMERIDIAN
, MERpm
},
2175 static table
const dst_table
[] =
2180 static table
const month_and_day_table
[] =
2182 { "JANUARY", tMONTH
, 1 },
2183 { "FEBRUARY", tMONTH
, 2 },
2184 { "MARCH", tMONTH
, 3 },
2185 { "APRIL", tMONTH
, 4 },
2186 { "MAY", tMONTH
, 5 },
2187 { "JUNE", tMONTH
, 6 },
2188 { "JULY", tMONTH
, 7 },
2189 { "AUGUST", tMONTH
, 8 },
2190 { "SEPTEMBER",tMONTH
, 9 },
2191 { "SEPT", tMONTH
, 9 },
2192 { "OCTOBER", tMONTH
, 10 },
2193 { "NOVEMBER", tMONTH
, 11 },
2194 { "DECEMBER", tMONTH
, 12 },
2195 { "SUNDAY", tDAY
, 0 },
2196 { "MONDAY", tDAY
, 1 },
2197 { "TUESDAY", tDAY
, 2 },
2198 { "TUES", tDAY
, 2 },
2199 { "WEDNESDAY",tDAY
, 3 },
2200 { "WEDNES", tDAY
, 3 },
2201 { "THURSDAY", tDAY
, 4 },
2202 { "THUR", tDAY
, 4 },
2203 { "THURS", tDAY
, 4 },
2204 { "FRIDAY", tDAY
, 5 },
2205 { "SATURDAY", tDAY
, 6 },
2209 static table
const time_units_table
[] =
2211 { "YEAR", tYEAR_UNIT
, 1 },
2212 { "MONTH", tMONTH_UNIT
, 1 },
2213 { "FORTNIGHT",tDAY_UNIT
, 14 },
2214 { "WEEK", tDAY_UNIT
, 7 },
2215 { "DAY", tDAY_UNIT
, 1 },
2216 { "HOUR", tHOUR_UNIT
, 1 },
2217 { "MINUTE", tMINUTE_UNIT
, 1 },
2218 { "MIN", tMINUTE_UNIT
, 1 },
2219 { "SECOND", tSEC_UNIT
, 1 },
2220 { "SEC", tSEC_UNIT
, 1 },
2224 /* Assorted relative-time words. */
2225 static table
const relative_time_table
[] =
2227 { "TOMORROW", tMINUTE_UNIT
, 24 * 60 },
2228 { "YESTERDAY",tMINUTE_UNIT
, - (24 * 60) },
2229 { "TODAY", tMINUTE_UNIT
, 0 },
2230 { "NOW", tMINUTE_UNIT
, 0 },
2231 { "LAST", tUNUMBER
, -1 },
2232 { "THIS", tUNUMBER
, 0 },
2233 { "NEXT", tUNUMBER
, 1 },
2234 { "FIRST", tUNUMBER
, 1 },
2235 /*{ "SECOND", tUNUMBER, 2 }, */
2236 { "THIRD", tUNUMBER
, 3 },
2237 { "FOURTH", tUNUMBER
, 4 },
2238 { "FIFTH", tUNUMBER
, 5 },
2239 { "SIXTH", tUNUMBER
, 6 },
2240 { "SEVENTH", tUNUMBER
, 7 },
2241 { "EIGHTH", tUNUMBER
, 8 },
2242 { "NINTH", tUNUMBER
, 9 },
2243 { "TENTH", tUNUMBER
, 10 },
2244 { "ELEVENTH", tUNUMBER
, 11 },
2245 { "TWELFTH", tUNUMBER
, 12 },
2250 /* The time zone table. This table is necessarily incomplete, as time
2251 zone abbreviations are ambiguous; e.g. Australians interpret "EST"
2252 as Eastern time in Australia, not as US Eastern Standard Time.
2253 You cannot rely on getdate to handle arbitrary time zone
2254 abbreviations; use numeric abbreviations like `-0500' instead. */
2255 static table
const time_zone_table
[] =
2257 { "GMT", tZONE
, HOUR ( 0) }, /* Greenwich Mean */
2258 { "UT", tZONE
, HOUR ( 0) }, /* Universal (Coordinated) */
2259 { "UTC", tZONE
, HOUR ( 0) },
2260 { "WET", tZONE
, HOUR ( 0) }, /* Western European */
2261 { "WEST", tDAYZONE
, HOUR ( 0) }, /* Western European Summer */
2262 { "BST", tDAYZONE
, HOUR ( 0) }, /* British Summer */
2263 { "ART", tZONE
, -HOUR ( 3) }, /* Argentina */
2264 { "BRT", tZONE
, -HOUR ( 3) }, /* Brazil */
2265 { "BRST", tDAYZONE
, -HOUR ( 3) }, /* Brazil Summer */
2266 { "NST", tZONE
, -(HOUR ( 3) + 30) }, /* Newfoundland Standard */
2267 { "NDT", tDAYZONE
,-(HOUR ( 3) + 30) }, /* Newfoundland Daylight */
2268 { "AST", tZONE
, -HOUR ( 4) }, /* Atlantic Standard */
2269 { "ADT", tDAYZONE
, -HOUR ( 4) }, /* Atlantic Daylight */
2270 { "CLT", tZONE
, -HOUR ( 4) }, /* Chile */
2271 { "CLST", tDAYZONE
, -HOUR ( 4) }, /* Chile Summer */
2272 { "EST", tZONE
, -HOUR ( 5) }, /* Eastern Standard */
2273 { "EDT", tDAYZONE
, -HOUR ( 5) }, /* Eastern Daylight */
2274 { "CST", tZONE
, -HOUR ( 6) }, /* Central Standard */
2275 { "CDT", tDAYZONE
, -HOUR ( 6) }, /* Central Daylight */
2276 { "MST", tZONE
, -HOUR ( 7) }, /* Mountain Standard */
2277 { "MDT", tDAYZONE
, -HOUR ( 7) }, /* Mountain Daylight */
2278 { "PST", tZONE
, -HOUR ( 8) }, /* Pacific Standard */
2279 { "PDT", tDAYZONE
, -HOUR ( 8) }, /* Pacific Daylight */
2280 { "AKST", tZONE
, -HOUR ( 9) }, /* Alaska Standard */
2281 { "AKDT", tDAYZONE
, -HOUR ( 9) }, /* Alaska Daylight */
2282 { "HST", tZONE
, -HOUR (10) }, /* Hawaii Standard */
2283 { "HAST", tZONE
, -HOUR (10) }, /* Hawaii-Aleutian Standard */
2284 { "HADT", tDAYZONE
, -HOUR (10) }, /* Hawaii-Aleutian Daylight */
2285 { "SST", tZONE
, -HOUR (12) }, /* Samoa Standard */
2286 { "WAT", tZONE
, HOUR ( 1) }, /* West Africa */
2287 { "CET", tZONE
, HOUR ( 1) }, /* Central European */
2288 { "CEST", tDAYZONE
, HOUR ( 1) }, /* Central European Summer */
2289 { "MET", tZONE
, HOUR ( 1) }, /* Middle European */
2290 { "MEZ", tZONE
, HOUR ( 1) }, /* Middle European */
2291 { "MEST", tDAYZONE
, HOUR ( 1) }, /* Middle European Summer */
2292 { "MESZ", tDAYZONE
, HOUR ( 1) }, /* Middle European Summer */
2293 { "EET", tZONE
, HOUR ( 2) }, /* Eastern European */
2294 { "EEST", tDAYZONE
, HOUR ( 2) }, /* Eastern European Summer */
2295 { "CAT", tZONE
, HOUR ( 2) }, /* Central Africa */
2296 { "SAST", tZONE
, HOUR ( 2) }, /* South Africa Standard */
2297 { "EAT", tZONE
, HOUR ( 3) }, /* East Africa */
2298 { "MSK", tZONE
, HOUR ( 3) }, /* Moscow */
2299 { "MSD", tDAYZONE
, HOUR ( 3) }, /* Moscow Daylight */
2300 { "IST", tZONE
, (HOUR ( 5) + 30) }, /* India Standard */
2301 { "SGT", tZONE
, HOUR ( 8) }, /* Singapore */
2302 { "KST", tZONE
, HOUR ( 9) }, /* Korea Standard */
2303 { "JST", tZONE
, HOUR ( 9) }, /* Japan Standard */
2304 { "GST", tZONE
, HOUR (10) }, /* Guam Standard */
2305 { "NZST", tZONE
, HOUR (12) }, /* New Zealand Standard */
2306 { "NZDT", tDAYZONE
, HOUR (12) }, /* New Zealand Daylight */
2310 /* Military time zone table. */
2311 static table
const military_table
[] =
2313 { "A", tZONE
, -HOUR ( 1) },
2314 { "B", tZONE
, -HOUR ( 2) },
2315 { "C", tZONE
, -HOUR ( 3) },
2316 { "D", tZONE
, -HOUR ( 4) },
2317 { "E", tZONE
, -HOUR ( 5) },
2318 { "F", tZONE
, -HOUR ( 6) },
2319 { "G", tZONE
, -HOUR ( 7) },
2320 { "H", tZONE
, -HOUR ( 8) },
2321 { "I", tZONE
, -HOUR ( 9) },
2322 { "K", tZONE
, -HOUR (10) },
2323 { "L", tZONE
, -HOUR (11) },
2324 { "M", tZONE
, -HOUR (12) },
2325 { "N", tZONE
, HOUR ( 1) },
2326 { "O", tZONE
, HOUR ( 2) },
2327 { "P", tZONE
, HOUR ( 3) },
2328 { "Q", tZONE
, HOUR ( 4) },
2329 { "R", tZONE
, HOUR ( 5) },
2330 { "S", tZONE
, HOUR ( 6) },
2331 { "T", tZONE
, HOUR ( 7) },
2332 { "U", tZONE
, HOUR ( 8) },
2333 { "V", tZONE
, HOUR ( 9) },
2334 { "W", tZONE
, HOUR (10) },
2335 { "X", tZONE
, HOUR (11) },
2336 { "Y", tZONE
, HOUR (12) },
2337 { "Z", tZONE
, HOUR ( 0) },
2344 to_hour (int hours
, int meridian
)
2349 return 0 <= hours
&& hours
< 24 ? hours
: -1;
2351 return 0 < hours
&& hours
< 12 ? hours
: hours
== 12 ? 0 : -1;
2353 return 0 < hours
&& hours
< 12 ? hours
+ 12 : hours
== 12 ? 12 : -1;
2362 to_year (textint textyear
)
2364 int year
= textyear
.value
;
2369 /* XPG4 suggests that years 00-68 map to 2000-2068, and
2370 years 69-99 map to 1969-1999. */
2371 if (textyear
.digits
== 2)
2372 year
+= year
< 69 ? 2000 : 1900;
2377 static table
const *
2378 lookup_zone (parser_control
const *pc
, char const *name
)
2382 /* Try local zone abbreviations first; they're more likely to be right. */
2383 for (tp
= pc
->local_time_zone_table
; tp
->name
; tp
++)
2384 if (strcmp (name
, tp
->name
) == 0)
2387 for (tp
= time_zone_table
; tp
->name
; tp
++)
2388 if (strcmp (name
, tp
->name
) == 0)
2394 #if ! HAVE_TM_GMTOFF
2395 /* Yield the difference between *A and *B,
2396 measured in seconds, ignoring leap seconds.
2397 The body of this function is taken directly from the GNU C Library;
2398 see src/strftime.c. */
2400 tm_diff (struct tm
const *a
, struct tm
const *b
)
2402 /* Compute intervening leap days correctly even if year is negative.
2403 Take care to avoid int overflow in leap day calculations,
2404 but it's OK to assume that A and B are close to each other. */
2405 int a4
= (a
->tm_year
>> 2) + (TM_YEAR_BASE
>> 2) - ! (a
->tm_year
& 3);
2406 int b4
= (b
->tm_year
>> 2) + (TM_YEAR_BASE
>> 2) - ! (b
->tm_year
& 3);
2407 int a100
= a4
/ 25 - (a4
% 25 < 0);
2408 int b100
= b4
/ 25 - (b4
% 25 < 0);
2409 int a400
= a100
>> 2;
2410 int b400
= b100
>> 2;
2411 int intervening_leap_days
= (a4
- b4
) - (a100
- b100
) + (a400
- b400
);
2412 int years
= a
->tm_year
- b
->tm_year
;
2413 int days
= (365 * years
+ intervening_leap_days
2414 + (a
->tm_yday
- b
->tm_yday
));
2415 return (60 * (60 * (24 * days
+ (a
->tm_hour
- b
->tm_hour
))
2416 + (a
->tm_min
- b
->tm_min
))
2417 + (a
->tm_sec
- b
->tm_sec
));
2419 #endif /* ! HAVE_TM_GMTOFF */
2421 static table
const *
2422 lookup_word (parser_control
const *pc
, char *word
)
2431 /* Make it uppercase. */
2432 for (p
= word
; *p
; p
++)
2433 if (ISLOWER ((unsigned char) *p
))
2434 *p
= toupper ((unsigned char) *p
);
2436 for (tp
= meridian_table
; tp
->name
; tp
++)
2437 if (strcmp (word
, tp
->name
) == 0)
2440 /* See if we have an abbreviation for a month. */
2441 wordlen
= strlen (word
);
2442 abbrev
= wordlen
== 3 || (wordlen
== 4 && word
[3] == '.');
2444 for (tp
= month_and_day_table
; tp
->name
; tp
++)
2445 if ((abbrev
? strncmp (word
, tp
->name
, 3) : strcmp (word
, tp
->name
)) == 0)
2448 if ((tp
= lookup_zone (pc
, word
)))
2451 if (strcmp (word
, dst_table
[0].name
) == 0)
2454 for (tp
= time_units_table
; tp
->name
; tp
++)
2455 if (strcmp (word
, tp
->name
) == 0)
2458 /* Strip off any plural and try the units table again. */
2459 if (word
[wordlen
- 1] == 'S')
2461 word
[wordlen
- 1] = '\0';
2462 for (tp
= time_units_table
; tp
->name
; tp
++)
2463 if (strcmp (word
, tp
->name
) == 0)
2465 word
[wordlen
- 1] = 'S'; /* For "this" in relative_time_table. */
2468 for (tp
= relative_time_table
; tp
->name
; tp
++)
2469 if (strcmp (word
, tp
->name
) == 0)
2472 /* Military time zones. */
2474 for (tp
= military_table
; tp
->name
; tp
++)
2475 if (word
[0] == tp
->name
[0])
2478 /* Drop out any periods and try the time zone table again. */
2479 for (i
= 0, p
= q
= word
; (*p
= *q
); q
++)
2484 if (i
&& (tp
= lookup_zone (pc
, word
)))
2491 yylex (YYSTYPE
*lvalp
, parser_control
*pc
)
2498 while (c
= *pc
->input
, ISSPACE (c
))
2501 if (ISDIGIT (c
) || c
== '-' || c
== '+')
2506 if (c
== '-' || c
== '+')
2508 sign
= c
== '-' ? -1 : 1;
2511 /* skip the '-' sign */
2520 value
= 10 * value
+ c
- '0';
2523 while (ISDIGIT (c
));
2524 lvalp
->textintval
.value
= sign
< 0 ? -value
: value
;
2525 lvalp
->textintval
.digits
= p
- pc
->input
;
2527 return sign
? tSNUMBER
: tUNUMBER
;
2538 if (p
< buff
+ sizeof buff
- 1)
2542 while (ISALPHA (c
) || c
== '.');
2545 tp
= lookup_word (pc
, buff
);
2548 lvalp
->intval
= tp
->value
;
2553 return *pc
->input
++;
2569 /* Do nothing if the parser reports an error. */
2571 yyerror (const char *s ATTRIBUTE_UNUSED
)
2576 /* Parse a date/time string P. Return the corresponding time_t value,
2577 or (time_t) -1 if there is an error. P can be an incomplete or
2578 relative time specification; if so, use *NOW as the basis for the
2581 get_date (const char *p
, const time_t *now
)
2583 time_t Start
= now
? *now
: time (0);
2584 struct tm
*tmp
= localtime (&Start
);
2593 pc
.year
.value
= tmp
->tm_year
+ TM_YEAR_BASE
;
2595 pc
.month
= tmp
->tm_mon
+ 1;
2596 pc
.day
= tmp
->tm_mday
;
2597 pc
.hour
= tmp
->tm_hour
;
2598 pc
.minutes
= tmp
->tm_min
;
2599 pc
.seconds
= tmp
->tm_sec
;
2600 tm
.tm_isdst
= tmp
->tm_isdst
;
2602 pc
.meridian
= MER24
;
2613 pc
.local_zones_seen
= 0;
2616 #if HAVE_STRUCT_TM_TM_ZONE
2617 pc
.local_time_zone_table
[0].name
= tmp
->tm_zone
;
2618 pc
.local_time_zone_table
[0].type
= tLOCAL_ZONE
;
2619 pc
.local_time_zone_table
[0].value
= tmp
->tm_isdst
;
2620 pc
.local_time_zone_table
[1].name
= 0;
2622 /* Probe the names used in the next three calendar quarters, looking
2623 for a tm_isdst different from the one we already have. */
2626 for (quarter
= 1; quarter
<= 3; quarter
++)
2628 time_t probe
= Start
+ quarter
* (90 * 24 * 60 * 60);
2629 struct tm
*probe_tm
= localtime (&probe
);
2630 if (probe_tm
&& probe_tm
->tm_zone
2631 && probe_tm
->tm_isdst
!= pc
.local_time_zone_table
[0].value
)
2634 pc
.local_time_zone_table
[1].name
= probe_tm
->tm_zone
;
2635 pc
.local_time_zone_table
[1].type
= tLOCAL_ZONE
;
2636 pc
.local_time_zone_table
[1].value
= probe_tm
->tm_isdst
;
2637 pc
.local_time_zone_table
[2].name
= 0;
2647 extern char *tzname
[];
2650 for (i
= 0; i
< 2; i
++)
2652 pc
.local_time_zone_table
[i
].name
= tzname
[i
];
2653 pc
.local_time_zone_table
[i
].type
= tLOCAL_ZONE
;
2654 pc
.local_time_zone_table
[i
].value
= i
;
2656 pc
.local_time_zone_table
[i
].name
= 0;
2659 pc
.local_time_zone_table
[0].name
= 0;
2663 if (pc
.local_time_zone_table
[0].name
&& pc
.local_time_zone_table
[1].name
2664 && ! strcmp (pc
.local_time_zone_table
[0].name
,
2665 pc
.local_time_zone_table
[1].name
))
2667 /* This locale uses the same abbrevation for standard and
2668 daylight times. So if we see that abbreviation, we don't
2669 know whether it's daylight time. */
2670 pc
.local_time_zone_table
[0].value
= -1;
2671 pc
.local_time_zone_table
[1].name
= 0;
2674 if (yyparse (&pc
) != 0
2675 || 1 < pc
.times_seen
|| 1 < pc
.dates_seen
|| 1 < pc
.days_seen
2676 || 1 < (pc
.local_zones_seen
+ pc
.zones_seen
)
2677 || (pc
.local_zones_seen
&& 1 < pc
.local_isdst
))
2680 tm
.tm_year
= to_year (pc
.year
) - TM_YEAR_BASE
+ pc
.rel_year
;
2681 tm
.tm_mon
= pc
.month
- 1 + pc
.rel_month
;
2682 tm
.tm_mday
= pc
.day
+ pc
.rel_day
;
2683 if (pc
.times_seen
|| (pc
.rels_seen
&& ! pc
.dates_seen
&& ! pc
.days_seen
))
2685 tm
.tm_hour
= to_hour (pc
.hour
, pc
.meridian
);
2688 tm
.tm_min
= pc
.minutes
;
2689 tm
.tm_sec
= pc
.seconds
;
2693 tm
.tm_hour
= tm
.tm_min
= tm
.tm_sec
= 0;
2696 /* Let mktime deduce tm_isdst if we have an absolute time stamp,
2697 or if the relative time stamp mentions days, months, or years. */
2698 if (pc
.dates_seen
| pc
.days_seen
| pc
.times_seen
| pc
.rel_day
2699 | pc
.rel_month
| pc
.rel_year
)
2702 /* But if the input explicitly specifies local time with or without
2703 DST, give mktime that information. */
2704 if (pc
.local_zones_seen
)
2705 tm
.tm_isdst
= pc
.local_isdst
;
2709 Start
= mktime (&tm
);
2711 if (Start
== (time_t) -1)
2714 /* Guard against falsely reporting errors near the time_t boundaries
2715 when parsing times in other time zones. For example, if the min
2716 time_t value is 1970-01-01 00:00:00 UTC and we are 8 hours ahead
2717 of UTC, then the min localtime value is 1970-01-01 08:00:00; if
2718 we apply mktime to 1970-01-01 00:00:00 we will get an error, so
2719 we apply mktime to 1970-01-02 08:00:00 instead and adjust the time
2720 zone by 24 hours to compensate. This algorithm assumes that
2721 there is no DST transition within a day of the time_t boundaries. */
2725 if (tm
.tm_year
<= EPOCH_YEAR
- TM_YEAR_BASE
)
2728 pc
.time_zone
+= 24 * 60;
2733 pc
.time_zone
-= 24 * 60;
2735 Start
= mktime (&tm
);
2738 if (Start
== (time_t) -1)
2742 if (pc
.days_seen
&& ! pc
.dates_seen
)
2744 tm
.tm_mday
+= ((pc
.day_number
- tm
.tm_wday
+ 7) % 7
2745 + 7 * (pc
.day_ordinal
- (0 < pc
.day_ordinal
)));
2747 Start
= mktime (&tm
);
2748 if (Start
== (time_t) -1)
2754 int delta
= pc
.time_zone
* 60;
2755 #ifdef HAVE_TM_GMTOFF
2756 delta
-= tm
.tm_gmtoff
;
2758 struct tm
*gmt
= gmtime (&Start
);
2761 delta
-= tm_diff (&tm
, gmt
);
2763 if ((Start
< Start
- delta
) != (delta
< 0))
2764 return -1; /* time_t overflow */
2768 /* Add relative hours, minutes, and seconds. Ignore leap seconds;
2769 i.e. "+ 10 minutes" means 600 seconds, even if one of them is a
2770 leap second. Typically this is not what the user wants, but it's
2771 too hard to do it the other way, because the time zone indicator
2772 must be applied before relative times, and if mktime is applied
2773 again the time zone will be lost. */
2776 long d1
= 60 * 60 * (long) pc
.rel_hour
;
2777 time_t t1
= t0
+ d1
;
2778 long d2
= 60 * (long) pc
.rel_minutes
;
2779 time_t t2
= t1
+ d2
;
2780 int d3
= pc
.rel_seconds
;
2781 time_t t3
= t2
+ d3
;
2782 if ((d1
/ (60 * 60) ^ pc
.rel_hour
)
2783 | (d2
/ 60 ^ pc
.rel_minutes
)
2784 | ((t0
+ d1
< t0
) ^ (d1
< 0))
2785 | ((t1
+ d2
< t1
) ^ (d2
< 0))
2786 | ((t2
+ d3
< t2
) ^ (d3
< 0)))
2799 main (int ac
, char **av
)
2804 printf ("Enter date, or blank line to exit.\n\t> ");
2807 buff
[BUFSIZ
- 1] = 0;
2808 while (fgets (buff
, BUFSIZ
- 1, stdin
) && buff
[0])
2810 d
= get_date (buff
, 0);
2811 if (d
== (time_t) -1)
2812 printf ("Bad format - couldn't convert.\n");
2814 printf ("%s", ctime (&d
));
2820 #endif /* defined TEST */