1 /* A Bison parser, made by GNU Bison 2.3a. */
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.3a"
53 #define YYSKELETON_NAME "yacc.c"
58 /* Using locations. */
59 #define YYLSP_NEEDED 0
63 /* Copy the first part of user declarations. */
64 /* Line 164 of yacc.c. */
67 /* Parse a string into an internal time stamp.
69 Copyright (C) 1999, 2000, 2002, 2003, 2004, 2005, 2006, 2007 Free Software
72 This program is free software; you can redistribute it and/or modify
73 it under the terms of the GNU General Public License as published by
74 the Free Software Foundation; either version 2, or (at your option)
77 This program is distributed in the hope that it will be useful,
78 but WITHOUT ANY WARRANTY; without even the implied warranty of
79 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
80 GNU General Public License for more details.
82 You should have received a copy of the GNU General Public License
83 along with this program; if not, write to the Free Software Foundation,
84 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
86 /* Originally written by Steven M. Bellovin <smb@research.att.com> while
87 at the University of North Carolina at Chapel Hill. Later tweaked by
88 a couple of people on Usenet. Completely overhauled by Rich $alz
89 <rsalz@bbn.com> and Jim Berets <jberets@bbn.com> in August, 1990.
91 Modified by Paul Eggert <eggert@twinsun.com> in August 1999 to do
92 the right thing about local DST. Also modified by Paul Eggert
93 <eggert@cs.ucla.edu> in February 2004 to support
94 nanosecond-resolution time stamps, and in October 2004 to support
95 TZ strings in dates. */
97 /* FIXME: Check for arithmetic overflow in all cases, not just
103 #include "timespec.h"
105 /* There's no need to extend the stack, so there's no need to involve
107 #define YYSTACK_USE_ALLOCA 0
109 /* Tell Bison how much stack space is needed. 20 should be plenty for
110 this grammar, which is not right recursive. Beware setting it too
111 high, since that might cause problems on machines whose
112 implementations have lame stack-overflow checking. */
113 #define YYMAXDEPTH 20
114 #define YYINITDEPTH YYMAXDEPTH
116 /* Since the code of getdate.y is not included in the Emacs executable
117 itself, there is no need to #define static in this file. Even if
118 the code were included in the Emacs executable, it probably
119 wouldn't do any harm to #undef it here; this will only cause
120 problems if we try to write to a static variable, which I don't
121 think this code needs to do. */
136 /* ISDIGIT differs from isdigit, as follows:
137 - Its arg may be any int or unsigned int; it need not be an unsigned char
139 - It's typically faster.
140 POSIX says that only '0' through '9' are digits. Prefer ISDIGIT to
141 isdigit unless it's important to use the locale's definition
142 of `digit' even when the host does not conform to POSIX. */
143 #define ISDIGIT(c) ((unsigned int) (c) - '0' <= 9)
145 #ifndef __attribute__
146 # if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 8) || __STRICT_ANSI__
147 # define __attribute__(x)
151 #ifndef ATTRIBUTE_UNUSED
152 # define ATTRIBUTE_UNUSED __attribute__ ((__unused__))
155 /* Shift A right by B bits portably, by dividing A by 2**B and
156 truncating towards minus infinity. A and B should be free of side
157 effects, and B should be in the range 0 <= B <= INT_BITS - 2, where
158 INT_BITS is the number of useful bits in an int. GNU code can
159 assume that INT_BITS is at least 32.
161 ISO C99 says that A >> B is implementation-defined if A < 0. Some
162 implementations (e.g., UNICOS 9.0 on a Cray Y-MP EL) don't shift
163 right in the usual way when A < 0, so SHR falls back on division if
164 ordinary A >> B doesn't seem to be the usual signed shift. */
168 : (a) / (1 << (b)) - ((a) % (1 << (b)) < 0))
170 #define EPOCH_YEAR 1970
171 #define TM_YEAR_BASE 1900
173 #define HOUR(x) ((x) * 60)
175 /* An integer value, and the number of digits in its textual
184 /* An entry in the lexical lookup table. */
192 /* Meridian: am, pm, or 24-hour style. */
193 enum { MERam, MERpm, MER24 };
195 enum { BILLION = 1000000000, LOG10_BILLION = 9 };
197 /* Relative times. */
200 /* Relative year, month, day, hour, minutes, seconds, and nanoseconds. */
210 #if HAVE_COMPOUND_LITERALS
211 # define RELATIVE_TIME_0 ((relative_time) { 0, 0, 0, 0, 0, 0, 0 })
213 static relative_time const RELATIVE_TIME_0;
216 /* Information passed to and from the parser. */
219 /* The input string remaining to be parsed. */
222 /* N, if this is the Nth Tuesday. */
223 long int day_ordinal;
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, seconds, and nanoseconds. */
243 struct timespec seconds; /* includes nanoseconds */
245 /* Relative year, month, day, hour, minutes, seconds, and nanoseconds. */
248 /* Presence or counts of nonterminals of various flavors parsed so far. */
253 size_t local_zones_seen;
258 /* Table of local time zone abbrevations, terminated by a null entry. */
259 table local_time_zone_table[3];
263 static int yylex (union YYSTYPE *, parser_control *);
264 static int yyerror (parser_control const *, char const *);
265 static long int time_zone_hhmm (textint, long int);
269 /* Enabling traces. */
274 /* Enabling verbose error messages. */
275 #ifdef YYERROR_VERBOSE
276 # undef YYERROR_VERBOSE
277 # define YYERROR_VERBOSE 1
279 # define YYERROR_VERBOSE 0
282 /* Enabling the token table. */
283 #ifndef YYTOKEN_TABLE
284 # define YYTOKEN_TABLE 0
291 /* Put the tokens into the symbol table, so that GDB and other debuggers
311 tSDECIMAL_NUMBER = 275,
312 tUDECIMAL_NUMBER = 276
318 #define tYEAR_UNIT 260
319 #define tMONTH_UNIT 261
320 #define tHOUR_UNIT 262
321 #define tMINUTE_UNIT 263
322 #define tSEC_UNIT 264
323 #define tDAY_UNIT 265
326 #define tLOCAL_ZONE 268
327 #define tMERIDIAN 269
333 #define tSDECIMAL_NUMBER 275
334 #define tUDECIMAL_NUMBER 276
339 #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
340 typedef union YYSTYPE
341 {/* Line 191 of yacc.c. */
342 #line 214 "getdate.y"
346 struct timespec timespec;
349 /* Line 191 of yacc.c. */
350 #line 351 "getdate.c"
352 # define YYSTYPE_IS_TRIVIAL 1
353 # define yystype YYSTYPE /* obsolescent; will be withdrawn */
354 # define YYSTYPE_IS_DECLARED 1
360 /* Copy the second part of user declarations. */
362 /* Line 221 of yacc.c. */
363 #line 364 "getdate.c"
370 typedef YYTYPE_UINT8 yytype_uint8;
372 typedef unsigned char yytype_uint8;
376 typedef YYTYPE_INT8 yytype_int8;
377 #elif (defined __STDC__ || defined __C99__FUNC__ \
378 || defined __cplusplus || defined _MSC_VER)
379 typedef signed char yytype_int8;
381 typedef short int yytype_int8;
385 typedef YYTYPE_UINT16 yytype_uint16;
387 typedef unsigned short int yytype_uint16;
391 typedef YYTYPE_INT16 yytype_int16;
393 typedef short int yytype_int16;
397 # ifdef __SIZE_TYPE__
398 # define YYSIZE_T __SIZE_TYPE__
399 # elif defined size_t
400 # define YYSIZE_T size_t
401 # elif ! defined YYSIZE_T && (defined __STDC__ || defined __C99__FUNC__ \
402 || defined __cplusplus || defined _MSC_VER)
403 # include <stddef.h> /* INFRINGES ON USER NAME SPACE */
404 # define YYSIZE_T size_t
406 # define YYSIZE_T unsigned int
410 #define YYSIZE_MAXIMUM ((YYSIZE_T) -1)
415 # include <libintl.h> /* INFRINGES ON USER NAME SPACE */
416 # define YY_(msgid) dgettext ("bison-runtime", msgid)
420 # define YY_(msgid) msgid
424 /* Suppress unused-variable warnings by "using" E. */
425 #if ! defined lint || defined __GNUC__
426 # define YYUSE(e) ((void) (e))
428 # define YYUSE(e) /* empty */
431 /* Identity function, used to suppress warnings about constant conditions. */
435 #if (defined __STDC__ || defined __C99__FUNC__ \
436 || defined __cplusplus || defined _MSC_VER)
449 #if ! defined yyoverflow || YYERROR_VERBOSE
451 /* The parser invokes alloca or malloc; define the necessary symbols. */
453 # ifdef YYSTACK_USE_ALLOCA
454 # if YYSTACK_USE_ALLOCA
456 # define YYSTACK_ALLOC __builtin_alloca
457 # elif defined __BUILTIN_VA_ARG_INCR
458 # include <alloca.h> /* INFRINGES ON USER NAME SPACE */
460 # define YYSTACK_ALLOC __alloca
461 # elif defined _MSC_VER
462 # include <malloc.h> /* INFRINGES ON USER NAME SPACE */
463 # define alloca _alloca
465 # define YYSTACK_ALLOC alloca
466 # if ! defined _ALLOCA_H && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
467 || defined __cplusplus || defined _MSC_VER)
468 # include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
477 # ifdef YYSTACK_ALLOC
478 /* Pacify GCC's `empty if-body' warning. */
479 # define YYSTACK_FREE(Ptr) do { /* empty */; } while (YYID (0))
480 # ifndef YYSTACK_ALLOC_MAXIMUM
481 /* The OS might guarantee only one guard page at the bottom of the stack,
482 and a page size can be as small as 4096 bytes. So we cannot safely
483 invoke alloca (N) if N exceeds 4096. Use a slightly smaller number
484 to allow for a few compiler-allocated temporary stack slots. */
485 # define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */
488 # define YYSTACK_ALLOC YYMALLOC
489 # define YYSTACK_FREE YYFREE
490 # ifndef YYSTACK_ALLOC_MAXIMUM
491 # define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM
493 # if (defined __cplusplus && ! defined _STDLIB_H \
494 && ! ((defined YYMALLOC || defined malloc) \
495 && (defined YYFREE || defined free)))
496 # include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
502 # define YYMALLOC malloc
503 # if ! defined malloc && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
504 || defined __cplusplus || defined _MSC_VER)
505 void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */
510 # if ! defined free && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
511 || defined __cplusplus || defined _MSC_VER)
512 void free (void *); /* INFRINGES ON USER NAME SPACE */
516 #endif /* ! defined yyoverflow || YYERROR_VERBOSE */
519 #if (! defined yyoverflow \
520 && (! defined __cplusplus \
521 || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
523 /* A type that is properly aligned for any stack member. */
530 /* The size of the maximum gap between one aligned stack and the next. */
531 # define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1)
533 /* The size of an array large to enough to hold all stacks, each with
535 # define YYSTACK_BYTES(N) \
536 ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE)) \
537 + YYSTACK_GAP_MAXIMUM)
539 /* Copy COUNT objects from FROM to TO. The source and destination do
542 # if defined __GNUC__ && 1 < __GNUC__
543 # define YYCOPY(To, From, Count) \
544 __builtin_memcpy (To, From, (Count) * sizeof (*(From)))
546 # define YYCOPY(To, From, Count) \
550 for (yyi = 0; yyi < (Count); yyi++) \
551 (To)[yyi] = (From)[yyi]; \
557 /* Relocate STACK from its old location to the new one. The
558 local variables YYSIZE and YYSTACKSIZE give the old and new number of
559 elements in the stack, and YYPTR gives the new location of the
560 stack. Advance YYPTR to a properly aligned location for the next
562 # define YYSTACK_RELOCATE(Stack) \
565 YYSIZE_T yynewbytes; \
566 YYCOPY (&yyptr->Stack, Stack, yysize); \
567 Stack = &yyptr->Stack; \
568 yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \
569 yyptr += yynewbytes / sizeof (*yyptr); \
575 /* YYFINAL -- State number of the termination state. */
577 /* YYLAST -- Last index in YYTABLE. */
580 /* YYNTOKENS -- Number of terminals. */
582 /* YYNNTS -- Number of nonterminals. */
584 /* YYNRULES -- Number of rules. */
586 /* YYNRULES -- Number of states. */
589 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
591 #define YYMAXUTOK 276
593 #define YYTRANSLATE(YYX) \
594 ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
596 /* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */
597 static const yytype_uint8 yytranslate[] =
599 0, 2, 2, 2, 2, 2, 2, 2, 2, 2,
600 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
601 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
602 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
603 2, 2, 2, 2, 24, 2, 2, 25, 2, 2,
604 2, 2, 2, 2, 2, 2, 2, 2, 23, 2,
605 2, 2, 2, 2, 22, 2, 2, 2, 2, 2,
606 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
607 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
608 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
609 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
610 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
611 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
612 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
613 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
614 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
615 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
616 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
617 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
618 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
619 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
620 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
621 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
622 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
623 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
624 2, 2, 2, 2, 2, 2, 1, 2, 3, 4,
625 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
626 15, 16, 17, 18, 19, 20, 21
630 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
632 static const yytype_uint8 yyprhs[] =
634 0, 0, 3, 5, 7, 10, 11, 14, 16, 18,
635 20, 22, 24, 26, 28, 31, 36, 42, 49, 57,
636 59, 62, 64, 67, 71, 73, 76, 78, 81, 84,
637 87, 91, 97, 101, 105, 109, 112, 117, 120, 124,
638 127, 129, 132, 135, 137, 140, 143, 145, 148, 151,
639 153, 156, 159, 161, 164, 167, 169, 172, 175, 178,
640 181, 183, 185, 188, 191, 194, 197, 200, 203, 205,
641 207, 209, 211, 213, 215, 217, 218, 221, 222
644 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
645 static const yytype_int8 yyrhs[] =
647 27, 0, -1, 28, -1, 29, -1, 22, 39, -1,
648 -1, 29, 30, -1, 31, -1, 32, -1, 33, -1,
649 35, -1, 34, -1, 36, -1, 42, -1, 19, 14,
650 -1, 19, 23, 19, 44, -1, 19, 23, 19, 18,
651 43, -1, 19, 23, 19, 23, 41, 44, -1, 19,
652 23, 19, 23, 41, 18, 43, -1, 13, -1, 13,
653 4, -1, 17, -1, 17, 38, -1, 17, 18, 43,
654 -1, 12, -1, 17, 4, -1, 11, -1, 11, 24,
655 -1, 16, 11, -1, 19, 11, -1, 19, 25, 19,
656 -1, 19, 25, 19, 25, 19, -1, 19, 18, 18,
657 -1, 19, 15, 18, -1, 15, 18, 18, -1, 15,
658 19, -1, 15, 19, 24, 19, -1, 19, 15, -1,
659 19, 15, 19, -1, 37, 3, -1, 37, -1, 16,
660 5, -1, 19, 5, -1, 5, -1, 16, 6, -1,
661 19, 6, -1, 6, -1, 16, 10, -1, 19, 10,
662 -1, 10, -1, 16, 7, -1, 19, 7, -1, 7,
663 -1, 16, 8, -1, 19, 8, -1, 8, -1, 16,
664 9, -1, 19, 9, -1, 20, 9, -1, 21, 9,
665 -1, 9, -1, 38, -1, 18, 5, -1, 18, 6,
666 -1, 18, 10, -1, 18, 7, -1, 18, 8, -1,
667 18, 9, -1, 40, -1, 41, -1, 20, -1, 18,
668 -1, 21, -1, 19, -1, 19, -1, -1, 23, 19,
672 /* YYRLINE[YYN] -- source line where rule number YYN was defined. */
673 static const yytype_uint16 yyrline[] =
675 0, 240, 240, 241, 245, 252, 254, 258, 260, 262,
676 264, 266, 268, 270, 274, 282, 290, 300, 307, 319,
677 324, 332, 334, 344, 346, 348, 353, 358, 363, 368,
678 376, 381, 401, 408, 416, 424, 429, 435, 440, 449,
679 459, 472, 474, 476, 478, 480, 482, 484, 486, 488,
680 490, 492, 494, 496, 498, 500, 502, 504, 506, 508,
681 510, 512, 516, 518, 520, 522, 524, 526, 530, 530,
682 533, 534, 539, 540, 545, 583, 584, 590, 591
686 #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
687 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
688 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
689 static const char *const yytname[] =
691 "$end", "error", "$undefined", "tAGO", "tDST", "tYEAR_UNIT",
692 "tMONTH_UNIT", "tHOUR_UNIT", "tMINUTE_UNIT", "tSEC_UNIT", "tDAY_UNIT",
693 "tDAY", "tDAYZONE", "tLOCAL_ZONE", "tMERIDIAN", "tMONTH", "tORDINAL",
694 "tZONE", "tSNUMBER", "tUNUMBER", "tSDECIMAL_NUMBER", "tUDECIMAL_NUMBER",
695 "'@'", "':'", "','", "'/'", "$accept", "spec", "timespec", "items",
696 "item", "time", "local_zone", "zone", "day", "date", "rel", "relunit",
697 "relunit_snumber", "seconds", "signed_seconds", "unsigned_seconds",
698 "number", "o_colon_minutes", "o_merid", 0
703 /* YYTOKNUM[YYLEX-NUM] -- Internal token number corresponding to
705 static const yytype_uint16 yytoknum[] =
707 0, 256, 257, 258, 259, 260, 261, 262, 263, 264,
708 265, 266, 267, 268, 269, 270, 271, 272, 273, 274,
709 275, 276, 64, 58, 44, 47
713 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
714 static const yytype_uint8 yyr1[] =
716 0, 26, 27, 27, 28, 29, 29, 30, 30, 30,
717 30, 30, 30, 30, 31, 31, 31, 31, 31, 32,
718 32, 33, 33, 33, 33, 33, 34, 34, 34, 34,
719 35, 35, 35, 35, 35, 35, 35, 35, 35, 36,
720 36, 37, 37, 37, 37, 37, 37, 37, 37, 37,
721 37, 37, 37, 37, 37, 37, 37, 37, 37, 37,
722 37, 37, 38, 38, 38, 38, 38, 38, 39, 39,
723 40, 40, 41, 41, 42, 43, 43, 44, 44
726 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
727 static const yytype_uint8 yyr2[] =
729 0, 2, 1, 1, 2, 0, 2, 1, 1, 1,
730 1, 1, 1, 1, 2, 4, 5, 6, 7, 1,
731 2, 1, 2, 3, 1, 2, 1, 2, 2, 2,
732 3, 5, 3, 3, 3, 2, 4, 2, 3, 2,
733 1, 2, 2, 1, 2, 2, 1, 2, 2, 1,
734 2, 2, 1, 2, 2, 1, 2, 2, 2, 2,
735 1, 1, 2, 2, 2, 2, 2, 2, 1, 1,
736 1, 1, 1, 1, 1, 0, 2, 0, 1
739 /* YYDEFACT[STATE-NAME] -- Default rule to reduce with in state
740 STATE-NUM when YYTABLE doesn't specify something else to do. Zero
741 means the default is an error. */
742 static const yytype_uint8 yydefact[] =
744 5, 0, 0, 2, 3, 71, 73, 70, 72, 4,
745 68, 69, 1, 43, 46, 52, 55, 60, 49, 26,
746 24, 19, 0, 0, 21, 0, 74, 0, 0, 6,
747 7, 8, 9, 11, 10, 12, 40, 61, 13, 27,
748 20, 0, 35, 41, 44, 50, 53, 56, 47, 28,
749 25, 75, 22, 62, 63, 65, 66, 67, 64, 42,
750 45, 51, 54, 57, 48, 29, 14, 37, 0, 0,
751 0, 58, 59, 39, 34, 0, 0, 23, 33, 38,
752 32, 77, 30, 36, 76, 78, 75, 0, 15, 0,
753 16, 77, 31, 75, 17, 18
756 /* YYDEFGOTO[NTERM-NUM]. */
757 static const yytype_int8 yydefgoto[] =
759 -1, 2, 3, 4, 29, 30, 31, 32, 33, 34,
760 35, 36, 37, 9, 10, 11, 38, 77, 88
763 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
765 #define YYPACT_NINF -79
766 static const yytype_int8 yypact[] =
768 -10, 47, 27, -79, 25, -79, -79, -79, -79, -79,
769 -79, -79, -79, -79, -79, -79, -79, -79, -79, 5,
770 -79, 59, 43, 42, 10, 49, -5, 62, 63, -79,
771 -79, -79, -79, -79, -79, -79, 70, -79, -79, -79,
772 -79, 56, 52, -79, -79, -79, -79, -79, -79, -79,
773 -79, 16, -79, -79, -79, -79, -79, -79, -79, -79,
774 -79, -79, -79, -79, -79, -79, -79, 51, 57, 58,
775 60, -79, -79, -79, -79, 61, 64, -79, -79, -79,
776 -79, -7, 53, -79, -79, -79, 65, -2, -79, 66,
777 -79, 46, -79, 65, -79, -79
780 /* YYPGOTO[NTERM-NUM]. */
781 static const yytype_int8 yypgoto[] =
783 -79, -79, -79, -79, -79, -79, -79, -79, -79, -79,
784 -79, -79, 67, -79, -79, -6, -79, -78, -9
787 /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
788 positive, shift that token. If negative, reduce the rule which
789 number is the opposite. If zero, do what YYDEFACT says.
790 If YYTABLE_NINF, syntax error. */
791 #define YYTABLE_NINF -1
792 static const yytype_uint8 yytable[] =
794 59, 60, 61, 62, 63, 64, 65, 85, 90, 66,
795 67, 86, 1, 68, 50, 95, 87, 6, 69, 8,
796 70, 53, 54, 55, 56, 57, 58, 12, 51, 39,
797 13, 14, 15, 16, 17, 18, 19, 20, 21, 76,
798 22, 23, 24, 25, 26, 27, 28, 43, 44, 45,
799 46, 47, 48, 49, 53, 54, 55, 56, 57, 58,
800 85, 41, 42, 40, 93, 5, 6, 7, 8, 78,
801 79, 71, 72, 73, 74, 80, 75, 81, 89, 82,
802 83, 91, 94, 84, 0, 92, 0, 0, 76, 0,
806 static const yytype_int8 yycheck[] =
808 5, 6, 7, 8, 9, 10, 11, 14, 86, 14,
809 15, 18, 22, 18, 4, 93, 23, 19, 23, 21,
810 25, 5, 6, 7, 8, 9, 10, 0, 18, 24,
811 5, 6, 7, 8, 9, 10, 11, 12, 13, 23,
812 15, 16, 17, 18, 19, 20, 21, 5, 6, 7,
813 8, 9, 10, 11, 5, 6, 7, 8, 9, 10,
814 14, 18, 19, 4, 18, 18, 19, 20, 21, 18,
815 19, 9, 9, 3, 18, 18, 24, 19, 25, 19,
816 19, 87, 91, 19, -1, 19, -1, -1, 23, -1,
820 /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
821 symbol of state STATE-NUM. */
822 static const yytype_uint8 yystos[] =
824 0, 22, 27, 28, 29, 18, 19, 20, 21, 39,
825 40, 41, 0, 5, 6, 7, 8, 9, 10, 11,
826 12, 13, 15, 16, 17, 18, 19, 20, 21, 30,
827 31, 32, 33, 34, 35, 36, 37, 38, 42, 24,
828 4, 18, 19, 5, 6, 7, 8, 9, 10, 11,
829 4, 18, 38, 5, 6, 7, 8, 9, 10, 5,
830 6, 7, 8, 9, 10, 11, 14, 15, 18, 23,
831 25, 9, 9, 3, 18, 24, 23, 43, 18, 19,
832 18, 19, 19, 19, 19, 14, 18, 23, 44, 25,
833 43, 41, 19, 18, 44, 43
836 #define yyerrok (yyerrstatus = 0)
837 #define yyclearin (yychar = YYEMPTY)
841 #define YYACCEPT goto yyacceptlab
842 #define YYABORT goto yyabortlab
843 #define YYERROR goto yyerrorlab
846 /* Like YYERROR except do call yyerror. This remains here temporarily
847 to ease the transition to the new meaning of YYERROR, for GCC.
848 Once GCC version 2 has supplanted version 1, this can go. */
850 #define YYFAIL goto yyerrlab
852 #define YYRECOVERING() (!!yyerrstatus)
854 #define YYBACKUP(Token, Value) \
856 if (yychar == YYEMPTY && yylen == 1) \
860 yytoken = YYTRANSLATE (yychar); \
866 yyerror (pc, YY_("syntax error: cannot back up")); \
873 #define YYERRCODE 256
876 /* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
877 If N is 0, then set CURRENT to the empty location which ends
878 the previous symbol: RHS[0] (always defined). */
880 #define YYRHSLOC(Rhs, K) ((Rhs)[K])
881 #ifndef YYLLOC_DEFAULT
882 # define YYLLOC_DEFAULT(Current, Rhs, N) \
886 (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \
887 (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \
888 (Current).last_line = YYRHSLOC (Rhs, N).last_line; \
889 (Current).last_column = YYRHSLOC (Rhs, N).last_column; \
893 (Current).first_line = (Current).last_line = \
894 YYRHSLOC (Rhs, 0).last_line; \
895 (Current).first_column = (Current).last_column = \
896 YYRHSLOC (Rhs, 0).last_column; \
902 /* YY_LOCATION_PRINT -- Print the location on the stream.
903 This macro was not mandated originally: define only if we know
904 we won't break user code: when these are the locations we know. */
906 #ifndef YY_LOCATION_PRINT
907 # if YYLTYPE_IS_TRIVIAL
908 # define YY_LOCATION_PRINT(File, Loc) \
909 fprintf (File, "%d.%d-%d.%d", \
910 (Loc).first_line, (Loc).first_column, \
911 (Loc).last_line, (Loc).last_column)
913 # define YY_LOCATION_PRINT(File, Loc) ((void) 0)
918 /* YYLEX -- calling `yylex' with the right arguments. */
921 # define YYLEX yylex (&yylval, YYLEX_PARAM)
923 # define YYLEX yylex (&yylval, pc)
926 /* Enable debugging if requested. */
930 # include <stdio.h> /* INFRINGES ON USER NAME SPACE */
931 # define YYFPRINTF fprintf
934 # define YYDPRINTF(Args) \
940 # define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
944 YYFPRINTF (stderr, "%s ", Title); \
945 yy_symbol_print (stderr, \
947 YYFPRINTF (stderr, "\n"); \
952 /*--------------------------------.
953 | Print this symbol on YYOUTPUT. |
954 `--------------------------------*/
957 #if (defined __STDC__ || defined __C99__FUNC__ \
958 || defined __cplusplus || defined _MSC_VER)
960 yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, parser_control *pc)
963 yy_symbol_value_print (yyoutput, yytype, yyvaluep, pc)
966 YYSTYPE const * const yyvaluep;
974 if (yytype < YYNTOKENS)
975 YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep);
987 /*--------------------------------.
988 | Print this symbol on YYOUTPUT. |
989 `--------------------------------*/
991 #if (defined __STDC__ || defined __C99__FUNC__ \
992 || defined __cplusplus || defined _MSC_VER)
994 yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, parser_control *pc)
997 yy_symbol_print (yyoutput, yytype, yyvaluep, pc)
1000 YYSTYPE const * const yyvaluep;
1004 if (yytype < YYNTOKENS)
1005 YYFPRINTF (yyoutput, "token %s (", yytname[yytype]);
1007 YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]);
1009 yy_symbol_value_print (yyoutput, yytype, yyvaluep, pc);
1010 YYFPRINTF (yyoutput, ")");
1013 /*------------------------------------------------------------------.
1014 | yy_stack_print -- Print the state stack from its BOTTOM up to its |
1016 `------------------------------------------------------------------*/
1018 #if (defined __STDC__ || defined __C99__FUNC__ \
1019 || defined __cplusplus || defined _MSC_VER)
1021 yy_stack_print (yytype_int16 *yybottom, yytype_int16 *yytop)
1024 yy_stack_print (yybottom, yytop)
1025 yytype_int16 *yybottom;
1026 yytype_int16 *yytop;
1029 YYFPRINTF (stderr, "Stack now");
1030 for (; yybottom <= yytop; yybottom++)
1032 int yybot = *yybottom;
1033 YYFPRINTF (stderr, " %d", yybot);
1035 YYFPRINTF (stderr, "\n");
1038 # define YY_STACK_PRINT(Bottom, Top) \
1041 yy_stack_print ((Bottom), (Top)); \
1045 /*------------------------------------------------.
1046 | Report that the YYRULE is going to be reduced. |
1047 `------------------------------------------------*/
1049 #if (defined __STDC__ || defined __C99__FUNC__ \
1050 || defined __cplusplus || defined _MSC_VER)
1052 yy_reduce_print (YYSTYPE *yyvsp, int yyrule, parser_control *pc)
1055 yy_reduce_print (yyvsp, yyrule, pc)
1061 int yynrhs = yyr2[yyrule];
1063 unsigned long int yylno = yyrline[yyrule];
1064 YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n",
1066 /* The symbols being reduced. */
1067 for (yyi = 0; yyi < yynrhs; yyi++)
1069 fprintf (stderr, " $%d = ", yyi + 1);
1070 yy_symbol_print (stderr, yyrhs[yyprhs[yyrule] + yyi],
1071 &(yyvsp[(yyi + 1) - (yynrhs)])
1073 fprintf (stderr, "\n");
1077 # define YY_REDUCE_PRINT(Rule) \
1080 yy_reduce_print (yyvsp, Rule, pc); \
1083 /* Nonzero means print parse trace. It is left uninitialized so that
1084 multiple parsers can coexist. */
1086 #else /* !YYDEBUG */
1087 # define YYDPRINTF(Args)
1088 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
1089 # define YY_STACK_PRINT(Bottom, Top)
1090 # define YY_REDUCE_PRINT(Rule)
1091 #endif /* !YYDEBUG */
1094 /* YYINITDEPTH -- initial size of the parser's stacks. */
1096 # define YYINITDEPTH 200
1099 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
1100 if the built-in stack extension method is used).
1102 Do not make this value too large; the results are undefined if
1103 YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH)
1104 evaluated with infinite-precision integer arithmetic. */
1107 # define YYMAXDEPTH 10000
1115 # if defined __GLIBC__ && defined _STRING_H
1116 # define yystrlen strlen
1118 /* Return the length of YYSTR. */
1119 #if (defined __STDC__ || defined __C99__FUNC__ \
1120 || defined __cplusplus || defined _MSC_VER)
1122 yystrlen (const char *yystr)
1130 for (yylen = 0; yystr[yylen]; yylen++)
1138 # if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
1139 # define yystpcpy stpcpy
1141 /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
1143 #if (defined __STDC__ || defined __C99__FUNC__ \
1144 || defined __cplusplus || defined _MSC_VER)
1146 yystpcpy (char *yydest, const char *yysrc)
1149 yystpcpy (yydest, yysrc)
1155 const char *yys = yysrc;
1157 while ((*yyd++ = *yys++) != '\0')
1166 /* Copy to YYRES the contents of YYSTR after stripping away unnecessary
1167 quotes and backslashes, so that it's suitable for yyerror. The
1168 heuristic is that double-quoting is unnecessary unless the string
1169 contains an apostrophe, a comma, or backslash (other than
1170 backslash-backslash). YYSTR is taken from yytname. If YYRES is
1171 null, do not copy; instead, return the length of what the result
1174 yytnamerr (char *yyres, const char *yystr)
1179 char const *yyp = yystr;
1186 goto do_not_strip_quotes;
1190 goto do_not_strip_quotes;
1203 do_not_strip_quotes: ;
1207 return yystrlen (yystr);
1209 return yystpcpy (yyres, yystr) - yyres;
1213 /* Copy into YYRESULT an error message about the unexpected token
1214 YYCHAR while in state YYSTATE. Return the number of bytes copied,
1215 including the terminating null byte. If YYRESULT is null, do not
1216 copy anything; just return the number of bytes that would be
1217 copied. As a special case, return 0 if an ordinary "syntax error"
1218 message will do. Return YYSIZE_MAXIMUM if overflow occurs during
1219 size calculation. */
1221 yysyntax_error (char *yyresult, int yystate, int yychar)
1223 int yyn = yypact[yystate];
1225 if (! (YYPACT_NINF < yyn && yyn <= YYLAST))
1229 int yytype = YYTRANSLATE (yychar);
1230 YYSIZE_T yysize0 = yytnamerr (0, yytname[yytype]);
1231 YYSIZE_T yysize = yysize0;
1233 int yysize_overflow = 0;
1234 enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
1235 char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
1239 /* This is so xgettext sees the translatable formats that are
1240 constructed on the fly. */
1241 YY_("syntax error, unexpected %s");
1242 YY_("syntax error, unexpected %s, expecting %s");
1243 YY_("syntax error, unexpected %s, expecting %s or %s");
1244 YY_("syntax error, unexpected %s, expecting %s or %s or %s");
1245 YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s");
1249 static char const yyunexpected[] = "syntax error, unexpected %s";
1250 static char const yyexpecting[] = ", expecting %s";
1251 static char const yyor[] = " or %s";
1252 char yyformat[sizeof yyunexpected
1253 + sizeof yyexpecting - 1
1254 + ((YYERROR_VERBOSE_ARGS_MAXIMUM - 2)
1255 * (sizeof yyor - 1))];
1256 char const *yyprefix = yyexpecting;
1258 /* Start YYX at -YYN if negative to avoid negative indexes in
1260 int yyxbegin = yyn < 0 ? -yyn : 0;
1262 /* Stay within bounds of both yycheck and yytname. */
1263 int yychecklim = YYLAST - yyn + 1;
1264 int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
1267 yyarg[0] = yytname[yytype];
1268 yyfmt = yystpcpy (yyformat, yyunexpected);
1270 for (yyx = yyxbegin; yyx < yyxend; ++yyx)
1271 if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)
1273 if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
1277 yyformat[sizeof yyunexpected - 1] = '\0';
1280 yyarg[yycount++] = yytname[yyx];
1281 yysize1 = yysize + yytnamerr (0, yytname[yyx]);
1282 yysize_overflow |= (yysize1 < yysize);
1284 yyfmt = yystpcpy (yyfmt, yyprefix);
1288 yyf = YY_(yyformat);
1289 yysize1 = yysize + yystrlen (yyf);
1290 yysize_overflow |= (yysize1 < yysize);
1293 if (yysize_overflow)
1294 return YYSIZE_MAXIMUM;
1298 /* Avoid sprintf, as that infringes on the user's name space.
1299 Don't have undefined behavior even if the translation
1300 produced a string with the wrong number of "%s"s. */
1301 char *yyp = yyresult;
1303 while ((*yyp = *yyf) != '\0')
1305 if (*yyp == '%' && yyf[1] == 's' && yyi < yycount)
1307 yyp += yytnamerr (yyp, yyarg[yyi++]);
1320 #endif /* YYERROR_VERBOSE */
1323 /*-----------------------------------------------.
1324 | Release the memory associated to this symbol. |
1325 `-----------------------------------------------*/
1328 #if (defined __STDC__ || defined __C99__FUNC__ \
1329 || defined __cplusplus || defined _MSC_VER)
1331 yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep, parser_control *pc)
1334 yydestruct (yymsg, yytype, yyvaluep, pc)
1346 YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
1357 /* Prevent warnings from -Wmissing-prototypes. */
1359 #ifdef YYPARSE_PARAM
1360 #if defined __STDC__ || defined __cplusplus
1361 int yyparse (void *YYPARSE_PARAM);
1365 #else /* ! YYPARSE_PARAM */
1366 #if defined __STDC__ || defined __cplusplus
1367 int yyparse (parser_control *pc);
1371 #endif /* ! YYPARSE_PARAM */
1382 #ifdef YYPARSE_PARAM
1383 #if (defined __STDC__ || defined __C99__FUNC__ \
1384 || defined __cplusplus || defined _MSC_VER)
1386 yyparse (void *YYPARSE_PARAM)
1389 yyparse (YYPARSE_PARAM)
1390 void *YYPARSE_PARAM;
1392 #else /* ! YYPARSE_PARAM */
1393 #if (defined __STDC__ || defined __C99__FUNC__ \
1394 || defined __cplusplus || defined _MSC_VER)
1396 yyparse (parser_control *pc)
1404 /* The lookahead symbol. */
1407 /* The semantic value of the lookahead symbol. */
1410 /* Number of syntax errors so far. */
1416 /* Number of tokens to shift before error messages enabled. */
1418 /* Lookahead token as an internal (translated) token number. */
1421 /* Buffer for error messages, and its allocated size. */
1423 char *yymsg = yymsgbuf;
1424 YYSIZE_T yymsg_alloc = sizeof yymsgbuf;
1427 /* Three stacks and their tools:
1428 `yyss': related to states,
1429 `yyvs': related to semantic values,
1430 `yyls': related to locations.
1432 Refer to the stacks thru separate pointers, to allow yyoverflow
1433 to reallocate them elsewhere. */
1435 /* The state stack. */
1436 yytype_int16 yyssa[YYINITDEPTH];
1437 yytype_int16 *yyss = yyssa;
1438 yytype_int16 *yyssp;
1440 /* The semantic value stack. */
1441 YYSTYPE yyvsa[YYINITDEPTH];
1442 YYSTYPE *yyvs = yyvsa;
1447 #define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N))
1449 YYSIZE_T yystacksize = YYINITDEPTH;
1451 /* The variables used to return semantic value and location from the
1456 /* The number of symbols on the RHS of the reduced rule.
1457 Keep to zero when no symbol should be popped. */
1460 YYDPRINTF ((stderr, "Starting parse\n"));
1465 yychar = YYEMPTY; /* Cause a token to be read. */
1467 /* Initialize stack pointers.
1468 Waste one element of value and location stack
1469 so that they stay on the same level as the state stack.
1470 The wasted elements are never initialized. */
1477 /*------------------------------------------------------------.
1478 | yynewstate -- Push a new state, which is found in yystate. |
1479 `------------------------------------------------------------*/
1481 /* In all cases, when you get here, the value and location stacks
1482 have just been pushed. So pushing a state here evens the stacks. */
1488 if (yyss + yystacksize - 1 <= yyssp)
1490 /* Get the current used size of the three stacks, in elements. */
1491 YYSIZE_T yysize = yyssp - yyss + 1;
1495 /* Give user a chance to reallocate the stack. Use copies of
1496 these so that the &'s don't force the real ones into
1498 YYSTYPE *yyvs1 = yyvs;
1499 yytype_int16 *yyss1 = yyss;
1502 /* Each stack pointer address is followed by the size of the
1503 data in use in that stack, in bytes. This used to be a
1504 conditional around just the two extra args, but that might
1505 be undefined if yyoverflow is a macro. */
1506 yyoverflow (YY_("memory exhausted"),
1507 &yyss1, yysize * sizeof (*yyssp),
1508 &yyvs1, yysize * sizeof (*yyvsp),
1515 #else /* no yyoverflow */
1516 # ifndef YYSTACK_RELOCATE
1517 goto yyexhaustedlab;
1519 /* Extend the stack our own way. */
1520 if (YYMAXDEPTH <= yystacksize)
1521 goto yyexhaustedlab;
1523 if (YYMAXDEPTH < yystacksize)
1524 yystacksize = YYMAXDEPTH;
1527 yytype_int16 *yyss1 = yyss;
1528 union yyalloc *yyptr =
1529 (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
1531 goto yyexhaustedlab;
1532 YYSTACK_RELOCATE (yyss);
1533 YYSTACK_RELOCATE (yyvs);
1535 # undef YYSTACK_RELOCATE
1537 YYSTACK_FREE (yyss1);
1540 #endif /* no yyoverflow */
1542 yyssp = yyss + yysize - 1;
1543 yyvsp = yyvs + yysize - 1;
1546 YYDPRINTF ((stderr, "Stack size increased to %lu\n",
1547 (unsigned long int) yystacksize));
1549 if (yyss + yystacksize - 1 <= yyssp)
1553 YYDPRINTF ((stderr, "Entering state %d\n", yystate));
1555 if (yystate == YYFINAL)
1565 /* Do appropriate processing given the current state. Read a
1566 lookahead token if we need one and don't already have one. */
1568 /* First try to decide what to do without reference to lookahead token. */
1569 yyn = yypact[yystate];
1570 if (yyn == YYPACT_NINF)
1573 /* Not known => get a lookahead token if don't already have one. */
1575 /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol. */
1576 if (yychar == YYEMPTY)
1578 YYDPRINTF ((stderr, "Reading a token: "));
1582 if (yychar <= YYEOF)
1584 yychar = yytoken = YYEOF;
1585 YYDPRINTF ((stderr, "Now at end of input.\n"));
1589 yytoken = YYTRANSLATE (yychar);
1590 YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
1593 /* If the proper action on seeing token YYTOKEN is to reduce or to
1594 detect an error, take that action. */
1596 if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
1601 if (yyn == 0 || yyn == YYTABLE_NINF)
1607 /* Count tokens shifted since error; after three, turn off error
1612 /* Shift the lookahead token. */
1613 YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
1615 /* Discard the shifted token. */
1624 /*-----------------------------------------------------------.
1625 | yydefault -- do the default action for the current state. |
1626 `-----------------------------------------------------------*/
1628 yyn = yydefact[yystate];
1634 /*-----------------------------.
1635 | yyreduce -- Do a reduction. |
1636 `-----------------------------*/
1638 /* yyn is the number of a rule to reduce with. */
1641 /* If YYLEN is nonzero, implement the default value of the action:
1644 Otherwise, the following line sets YYVAL to garbage.
1645 This behavior is undocumented and Bison
1646 users should not rely upon it. Assigning to YYVAL
1647 unconditionally makes the parser a bit smaller, and it avoids a
1648 GCC warning that YYVAL may be used uninitialized. */
1649 yyval = yyvsp[1-yylen];
1652 YY_REDUCE_PRINT (yyn);
1656 /* Line 1269 of yacc.c. */
1657 #line 246 "getdate.y"
1659 pc->seconds = (yyvsp[(2) - (2)].timespec);
1660 pc->timespec_seen = true;
1665 /* Line 1269 of yacc.c. */
1666 #line 259 "getdate.y"
1667 { pc->times_seen++; }
1671 /* Line 1269 of yacc.c. */
1672 #line 261 "getdate.y"
1673 { pc->local_zones_seen++; }
1677 /* Line 1269 of yacc.c. */
1678 #line 263 "getdate.y"
1679 { pc->zones_seen++; }
1683 /* Line 1269 of yacc.c. */
1684 #line 265 "getdate.y"
1685 { pc->dates_seen++; }
1689 /* Line 1269 of yacc.c. */
1690 #line 267 "getdate.y"
1691 { pc->days_seen++; }
1695 /* Line 1269 of yacc.c. */
1696 #line 269 "getdate.y"
1697 { pc->rels_seen = true; }
1701 /* Line 1269 of yacc.c. */
1702 #line 275 "getdate.y"
1704 pc->hour = (yyvsp[(1) - (2)].textintval).value;
1706 pc->seconds.tv_sec = 0;
1707 pc->seconds.tv_nsec = 0;
1708 pc->meridian = (yyvsp[(2) - (2)].intval);
1713 /* Line 1269 of yacc.c. */
1714 #line 283 "getdate.y"
1716 pc->hour = (yyvsp[(1) - (4)].textintval).value;
1717 pc->minutes = (yyvsp[(3) - (4)].textintval).value;
1718 pc->seconds.tv_sec = 0;
1719 pc->seconds.tv_nsec = 0;
1720 pc->meridian = (yyvsp[(4) - (4)].intval);
1725 /* Line 1269 of yacc.c. */
1726 #line 291 "getdate.y"
1728 pc->hour = (yyvsp[(1) - (5)].textintval).value;
1729 pc->minutes = (yyvsp[(3) - (5)].textintval).value;
1730 pc->seconds.tv_sec = 0;
1731 pc->seconds.tv_nsec = 0;
1732 pc->meridian = MER24;
1734 pc->time_zone = time_zone_hhmm ((yyvsp[(4) - (5)].textintval), (yyvsp[(5) - (5)].intval));
1739 /* Line 1269 of yacc.c. */
1740 #line 301 "getdate.y"
1742 pc->hour = (yyvsp[(1) - (6)].textintval).value;
1743 pc->minutes = (yyvsp[(3) - (6)].textintval).value;
1744 pc->seconds = (yyvsp[(5) - (6)].timespec);
1745 pc->meridian = (yyvsp[(6) - (6)].intval);
1750 /* Line 1269 of yacc.c. */
1751 #line 308 "getdate.y"
1753 pc->hour = (yyvsp[(1) - (7)].textintval).value;
1754 pc->minutes = (yyvsp[(3) - (7)].textintval).value;
1755 pc->seconds = (yyvsp[(5) - (7)].timespec);
1756 pc->meridian = MER24;
1758 pc->time_zone = time_zone_hhmm ((yyvsp[(6) - (7)].textintval), (yyvsp[(7) - (7)].intval));
1763 /* Line 1269 of yacc.c. */
1764 #line 320 "getdate.y"
1766 pc->local_isdst = (yyvsp[(1) - (1)].intval);
1767 pc->dsts_seen += (0 < (yyvsp[(1) - (1)].intval));
1772 /* Line 1269 of yacc.c. */
1773 #line 325 "getdate.y"
1775 pc->local_isdst = 1;
1776 pc->dsts_seen += (0 < (yyvsp[(1) - (2)].intval)) + 1;
1781 /* Line 1269 of yacc.c. */
1782 #line 333 "getdate.y"
1783 { pc->time_zone = (yyvsp[(1) - (1)].intval); }
1787 /* Line 1269 of yacc.c. */
1788 #line 335 "getdate.y"
1789 { pc->time_zone = (yyvsp[(1) - (2)].intval);
1790 pc->rel.ns += (yyvsp[(2) - (2)].rel).ns;
1791 pc->rel.seconds += (yyvsp[(2) - (2)].rel).seconds;
1792 pc->rel.minutes += (yyvsp[(2) - (2)].rel).minutes;
1793 pc->rel.hour += (yyvsp[(2) - (2)].rel).hour;
1794 pc->rel.day += (yyvsp[(2) - (2)].rel).day;
1795 pc->rel.month += (yyvsp[(2) - (2)].rel).month;
1796 pc->rel.year += (yyvsp[(2) - (2)].rel).year;
1797 pc->rels_seen = true; }
1801 /* Line 1269 of yacc.c. */
1802 #line 345 "getdate.y"
1803 { pc->time_zone = (yyvsp[(1) - (3)].intval) + time_zone_hhmm ((yyvsp[(2) - (3)].textintval), (yyvsp[(3) - (3)].intval)); }
1807 /* Line 1269 of yacc.c. */
1808 #line 347 "getdate.y"
1809 { pc->time_zone = (yyvsp[(1) - (1)].intval) + 60; }
1813 /* Line 1269 of yacc.c. */
1814 #line 349 "getdate.y"
1815 { pc->time_zone = (yyvsp[(1) - (2)].intval) + 60; }
1819 /* Line 1269 of yacc.c. */
1820 #line 354 "getdate.y"
1822 pc->day_ordinal = 1;
1823 pc->day_number = (yyvsp[(1) - (1)].intval);
1828 /* Line 1269 of yacc.c. */
1829 #line 359 "getdate.y"
1831 pc->day_ordinal = 1;
1832 pc->day_number = (yyvsp[(1) - (2)].intval);
1837 /* Line 1269 of yacc.c. */
1838 #line 364 "getdate.y"
1840 pc->day_ordinal = (yyvsp[(1) - (2)].intval);
1841 pc->day_number = (yyvsp[(2) - (2)].intval);
1846 /* Line 1269 of yacc.c. */
1847 #line 369 "getdate.y"
1849 pc->day_ordinal = (yyvsp[(1) - (2)].textintval).value;
1850 pc->day_number = (yyvsp[(2) - (2)].intval);
1855 /* Line 1269 of yacc.c. */
1856 #line 377 "getdate.y"
1858 pc->month = (yyvsp[(1) - (3)].textintval).value;
1859 pc->day = (yyvsp[(3) - (3)].textintval).value;
1864 /* Line 1269 of yacc.c. */
1865 #line 382 "getdate.y"
1867 /* Interpret as YYYY/MM/DD if the first value has 4 or more digits,
1868 otherwise as MM/DD/YY.
1869 The goal in recognizing YYYY/MM/DD is solely to support legacy
1870 machine-generated dates like those in an RCS log listing. If
1871 you want portability, use the ISO 8601 format. */
1872 if (4 <= (yyvsp[(1) - (5)].textintval).digits)
1874 pc->year = (yyvsp[(1) - (5)].textintval);
1875 pc->month = (yyvsp[(3) - (5)].textintval).value;
1876 pc->day = (yyvsp[(5) - (5)].textintval).value;
1880 pc->month = (yyvsp[(1) - (5)].textintval).value;
1881 pc->day = (yyvsp[(3) - (5)].textintval).value;
1882 pc->year = (yyvsp[(5) - (5)].textintval);
1888 /* Line 1269 of yacc.c. */
1889 #line 402 "getdate.y"
1891 /* ISO 8601 format. YYYY-MM-DD. */
1892 pc->year = (yyvsp[(1) - (3)].textintval);
1893 pc->month = -(yyvsp[(2) - (3)].textintval).value;
1894 pc->day = -(yyvsp[(3) - (3)].textintval).value;
1899 /* Line 1269 of yacc.c. */
1900 #line 409 "getdate.y"
1902 /* e.g. 17-JUN-1992. */
1903 pc->day = (yyvsp[(1) - (3)].textintval).value;
1904 pc->month = (yyvsp[(2) - (3)].intval);
1905 pc->year.value = -(yyvsp[(3) - (3)].textintval).value;
1906 pc->year.digits = (yyvsp[(3) - (3)].textintval).digits;
1911 /* Line 1269 of yacc.c. */
1912 #line 417 "getdate.y"
1914 /* e.g. JUN-17-1992. */
1915 pc->month = (yyvsp[(1) - (3)].intval);
1916 pc->day = -(yyvsp[(2) - (3)].textintval).value;
1917 pc->year.value = -(yyvsp[(3) - (3)].textintval).value;
1918 pc->year.digits = (yyvsp[(3) - (3)].textintval).digits;
1923 /* Line 1269 of yacc.c. */
1924 #line 425 "getdate.y"
1926 pc->month = (yyvsp[(1) - (2)].intval);
1927 pc->day = (yyvsp[(2) - (2)].textintval).value;
1932 /* Line 1269 of yacc.c. */
1933 #line 430 "getdate.y"
1935 pc->month = (yyvsp[(1) - (4)].intval);
1936 pc->day = (yyvsp[(2) - (4)].textintval).value;
1937 pc->year = (yyvsp[(4) - (4)].textintval);
1942 /* Line 1269 of yacc.c. */
1943 #line 436 "getdate.y"
1945 pc->day = (yyvsp[(1) - (2)].textintval).value;
1946 pc->month = (yyvsp[(2) - (2)].intval);
1951 /* Line 1269 of yacc.c. */
1952 #line 441 "getdate.y"
1954 pc->day = (yyvsp[(1) - (3)].textintval).value;
1955 pc->month = (yyvsp[(2) - (3)].intval);
1956 pc->year = (yyvsp[(3) - (3)].textintval);
1961 /* Line 1269 of yacc.c. */
1962 #line 450 "getdate.y"
1964 pc->rel.ns -= (yyvsp[(1) - (2)].rel).ns;
1965 pc->rel.seconds -= (yyvsp[(1) - (2)].rel).seconds;
1966 pc->rel.minutes -= (yyvsp[(1) - (2)].rel).minutes;
1967 pc->rel.hour -= (yyvsp[(1) - (2)].rel).hour;
1968 pc->rel.day -= (yyvsp[(1) - (2)].rel).day;
1969 pc->rel.month -= (yyvsp[(1) - (2)].rel).month;
1970 pc->rel.year -= (yyvsp[(1) - (2)].rel).year;
1975 /* Line 1269 of yacc.c. */
1976 #line 460 "getdate.y"
1978 pc->rel.ns += (yyvsp[(1) - (1)].rel).ns;
1979 pc->rel.seconds += (yyvsp[(1) - (1)].rel).seconds;
1980 pc->rel.minutes += (yyvsp[(1) - (1)].rel).minutes;
1981 pc->rel.hour += (yyvsp[(1) - (1)].rel).hour;
1982 pc->rel.day += (yyvsp[(1) - (1)].rel).day;
1983 pc->rel.month += (yyvsp[(1) - (1)].rel).month;
1984 pc->rel.year += (yyvsp[(1) - (1)].rel).year;
1989 /* Line 1269 of yacc.c. */
1990 #line 473 "getdate.y"
1991 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).year = (yyvsp[(1) - (2)].intval); }
1995 /* Line 1269 of yacc.c. */
1996 #line 475 "getdate.y"
1997 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).year = (yyvsp[(1) - (2)].textintval).value; }
2001 /* Line 1269 of yacc.c. */
2002 #line 477 "getdate.y"
2003 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).year = 1; }
2007 /* Line 1269 of yacc.c. */
2008 #line 479 "getdate.y"
2009 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).month = (yyvsp[(1) - (2)].intval); }
2013 /* Line 1269 of yacc.c. */
2014 #line 481 "getdate.y"
2015 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).month = (yyvsp[(1) - (2)].textintval).value; }
2019 /* Line 1269 of yacc.c. */
2020 #line 483 "getdate.y"
2021 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).month = 1; }
2025 /* Line 1269 of yacc.c. */
2026 #line 485 "getdate.y"
2027 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).day = (yyvsp[(1) - (2)].intval) * (yyvsp[(2) - (2)].intval); }
2031 /* Line 1269 of yacc.c. */
2032 #line 487 "getdate.y"
2033 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).day = (yyvsp[(1) - (2)].textintval).value * (yyvsp[(2) - (2)].intval); }
2037 /* Line 1269 of yacc.c. */
2038 #line 489 "getdate.y"
2039 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).day = (yyvsp[(1) - (1)].intval); }
2043 /* Line 1269 of yacc.c. */
2044 #line 491 "getdate.y"
2045 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).hour = (yyvsp[(1) - (2)].intval); }
2049 /* Line 1269 of yacc.c. */
2050 #line 493 "getdate.y"
2051 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).hour = (yyvsp[(1) - (2)].textintval).value; }
2055 /* Line 1269 of yacc.c. */
2056 #line 495 "getdate.y"
2057 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).hour = 1; }
2061 /* Line 1269 of yacc.c. */
2062 #line 497 "getdate.y"
2063 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).minutes = (yyvsp[(1) - (2)].intval); }
2067 /* Line 1269 of yacc.c. */
2068 #line 499 "getdate.y"
2069 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).minutes = (yyvsp[(1) - (2)].textintval).value; }
2073 /* Line 1269 of yacc.c. */
2074 #line 501 "getdate.y"
2075 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).minutes = 1; }
2079 /* Line 1269 of yacc.c. */
2080 #line 503 "getdate.y"
2081 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).seconds = (yyvsp[(1) - (2)].intval); }
2085 /* Line 1269 of yacc.c. */
2086 #line 505 "getdate.y"
2087 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).seconds = (yyvsp[(1) - (2)].textintval).value; }
2091 /* Line 1269 of yacc.c. */
2092 #line 507 "getdate.y"
2093 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).seconds = (yyvsp[(1) - (2)].timespec).tv_sec; (yyval.rel).ns = (yyvsp[(1) - (2)].timespec).tv_nsec; }
2097 /* Line 1269 of yacc.c. */
2098 #line 509 "getdate.y"
2099 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).seconds = (yyvsp[(1) - (2)].timespec).tv_sec; (yyval.rel).ns = (yyvsp[(1) - (2)].timespec).tv_nsec; }
2103 /* Line 1269 of yacc.c. */
2104 #line 511 "getdate.y"
2105 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).seconds = 1; }
2109 /* Line 1269 of yacc.c. */
2110 #line 517 "getdate.y"
2111 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).year = (yyvsp[(1) - (2)].textintval).value; }
2115 /* Line 1269 of yacc.c. */
2116 #line 519 "getdate.y"
2117 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).month = (yyvsp[(1) - (2)].textintval).value; }
2121 /* Line 1269 of yacc.c. */
2122 #line 521 "getdate.y"
2123 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).day = (yyvsp[(1) - (2)].textintval).value * (yyvsp[(2) - (2)].intval); }
2127 /* Line 1269 of yacc.c. */
2128 #line 523 "getdate.y"
2129 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).hour = (yyvsp[(1) - (2)].textintval).value; }
2133 /* Line 1269 of yacc.c. */
2134 #line 525 "getdate.y"
2135 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).minutes = (yyvsp[(1) - (2)].textintval).value; }
2139 /* Line 1269 of yacc.c. */
2140 #line 527 "getdate.y"
2141 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).seconds = (yyvsp[(1) - (2)].textintval).value; }
2145 /* Line 1269 of yacc.c. */
2146 #line 535 "getdate.y"
2147 { (yyval.timespec).tv_sec = (yyvsp[(1) - (1)].textintval).value; (yyval.timespec).tv_nsec = 0; }
2151 /* Line 1269 of yacc.c. */
2152 #line 541 "getdate.y"
2153 { (yyval.timespec).tv_sec = (yyvsp[(1) - (1)].textintval).value; (yyval.timespec).tv_nsec = 0; }
2157 /* Line 1269 of yacc.c. */
2158 #line 546 "getdate.y"
2160 if (pc->dates_seen && ! pc->year.digits
2161 && ! pc->rels_seen && (pc->times_seen || 2 < (yyvsp[(1) - (1)].textintval).digits))
2162 pc->year = (yyvsp[(1) - (1)].textintval);
2165 if (4 < (yyvsp[(1) - (1)].textintval).digits)
2168 pc->day = (yyvsp[(1) - (1)].textintval).value % 100;
2169 pc->month = ((yyvsp[(1) - (1)].textintval).value / 100) % 100;
2170 pc->year.value = (yyvsp[(1) - (1)].textintval).value / 10000;
2171 pc->year.digits = (yyvsp[(1) - (1)].textintval).digits - 4;
2176 if ((yyvsp[(1) - (1)].textintval).digits <= 2)
2178 pc->hour = (yyvsp[(1) - (1)].textintval).value;
2183 pc->hour = (yyvsp[(1) - (1)].textintval).value / 100;
2184 pc->minutes = (yyvsp[(1) - (1)].textintval).value % 100;
2186 pc->seconds.tv_sec = 0;
2187 pc->seconds.tv_nsec = 0;
2188 pc->meridian = MER24;
2195 /* Line 1269 of yacc.c. */
2196 #line 583 "getdate.y"
2197 { (yyval.intval) = -1; }
2201 /* Line 1269 of yacc.c. */
2202 #line 585 "getdate.y"
2203 { (yyval.intval) = (yyvsp[(2) - (2)].textintval).value; }
2207 /* Line 1269 of yacc.c. */
2208 #line 590 "getdate.y"
2209 { (yyval.intval) = MER24; }
2213 /* Line 1269 of yacc.c. */
2214 #line 592 "getdate.y"
2215 { (yyval.intval) = (yyvsp[(1) - (1)].intval); }
2219 /* Line 1269 of yacc.c. */
2220 #line 2221 "getdate.c"
2223 YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc);
2227 YY_STACK_PRINT (yyss, yyssp);
2232 /* Now `shift' the result of the reduction. Determine what state
2233 that goes to, based on the state we popped back to and the rule
2234 number reduced by. */
2238 yystate = yypgoto[yyn - YYNTOKENS] + *yyssp;
2239 if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp)
2240 yystate = yytable[yystate];
2242 yystate = yydefgoto[yyn - YYNTOKENS];
2247 /*------------------------------------.
2248 | yyerrlab -- here on detecting error |
2249 `------------------------------------*/
2251 /* If not already recovering from an error, report this error. */
2255 #if ! YYERROR_VERBOSE
2256 yyerror (pc, YY_("syntax error"));
2259 YYSIZE_T yysize = yysyntax_error (0, yystate, yychar);
2260 if (yymsg_alloc < yysize && yymsg_alloc < YYSTACK_ALLOC_MAXIMUM)
2262 YYSIZE_T yyalloc = 2 * yysize;
2263 if (! (yysize <= yyalloc && yyalloc <= YYSTACK_ALLOC_MAXIMUM))
2264 yyalloc = YYSTACK_ALLOC_MAXIMUM;
2265 if (yymsg != yymsgbuf)
2266 YYSTACK_FREE (yymsg);
2267 yymsg = (char *) YYSTACK_ALLOC (yyalloc);
2269 yymsg_alloc = yyalloc;
2273 yymsg_alloc = sizeof yymsgbuf;
2277 if (0 < yysize && yysize <= yymsg_alloc)
2279 (void) yysyntax_error (yymsg, yystate, yychar);
2280 yyerror (pc, yymsg);
2284 yyerror (pc, YY_("syntax error"));
2286 goto yyexhaustedlab;
2294 if (yyerrstatus == 3)
2296 /* If just tried and failed to reuse lookahead token after an
2297 error, discard it. */
2299 if (yychar <= YYEOF)
2301 /* Return failure if at end of input. */
2302 if (yychar == YYEOF)
2307 yydestruct ("Error: discarding",
2308 yytoken, &yylval, pc);
2313 /* Else will try to reuse lookahead token after shifting the error
2318 /*---------------------------------------------------.
2319 | yyerrorlab -- error raised explicitly by YYERROR. |
2320 `---------------------------------------------------*/
2323 /* Pacify compilers like GCC when the user code never invokes
2324 YYERROR and the label yyerrorlab therefore never appears in user
2326 if (/*CONSTCOND*/ 0)
2329 /* Do not reclaim the symbols of the rule which action triggered
2333 YY_STACK_PRINT (yyss, yyssp);
2338 /*-------------------------------------------------------------.
2339 | yyerrlab1 -- common code for both syntax error and YYERROR. |
2340 `-------------------------------------------------------------*/
2342 yyerrstatus = 3; /* Each real token shifted decrements this. */
2346 yyn = yypact[yystate];
2347 if (yyn != YYPACT_NINF)
2350 if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
2358 /* Pop the current state because it cannot handle the error token. */
2363 yydestruct ("Error: popping",
2364 yystos[yystate], yyvsp, pc);
2367 YY_STACK_PRINT (yyss, yyssp);
2373 /* Shift the error token. */
2374 YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp);
2380 /*-------------------------------------.
2381 | yyacceptlab -- YYACCEPT comes here. |
2382 `-------------------------------------*/
2387 /*-----------------------------------.
2388 | yyabortlab -- YYABORT comes here. |
2389 `-----------------------------------*/
2395 /*-------------------------------------------------.
2396 | yyexhaustedlab -- memory exhaustion comes here. |
2397 `-------------------------------------------------*/
2399 yyerror (pc, YY_("memory exhausted"));
2405 if (yychar != YYEMPTY)
2406 yydestruct ("Cleanup: discarding lookahead",
2407 yytoken, &yylval, pc);
2408 /* Do not reclaim the symbols of the rule which action triggered
2409 this YYABORT or YYACCEPT. */
2411 YY_STACK_PRINT (yyss, yyssp);
2412 while (yyssp != yyss)
2414 yydestruct ("Cleanup: popping",
2415 yystos[*yyssp], yyvsp, pc);
2420 YYSTACK_FREE (yyss);
2423 if (yymsg != yymsgbuf)
2424 YYSTACK_FREE (yymsg);
2426 /* Make sure YYID is used. */
2427 return YYID (yyresult);
2431 /* Line 1486 of yacc.c. */
2432 #line 595 "getdate.y"
2435 static table const meridian_table[] =
2437 { "AM", tMERIDIAN, MERam },
2438 { "A.M.", tMERIDIAN, MERam },
2439 { "PM", tMERIDIAN, MERpm },
2440 { "P.M.", tMERIDIAN, MERpm },
2444 static table const dst_table[] =
2449 static table const month_and_day_table[] =
2451 { "JANUARY", tMONTH, 1 },
2452 { "FEBRUARY", tMONTH, 2 },
2453 { "MARCH", tMONTH, 3 },
2454 { "APRIL", tMONTH, 4 },
2455 { "MAY", tMONTH, 5 },
2456 { "JUNE", tMONTH, 6 },
2457 { "JULY", tMONTH, 7 },
2458 { "AUGUST", tMONTH, 8 },
2459 { "SEPTEMBER",tMONTH, 9 },
2460 { "SEPT", tMONTH, 9 },
2461 { "OCTOBER", tMONTH, 10 },
2462 { "NOVEMBER", tMONTH, 11 },
2463 { "DECEMBER", tMONTH, 12 },
2464 { "SUNDAY", tDAY, 0 },
2465 { "MONDAY", tDAY, 1 },
2466 { "TUESDAY", tDAY, 2 },
2467 { "TUES", tDAY, 2 },
2468 { "WEDNESDAY",tDAY, 3 },
2469 { "WEDNES", tDAY, 3 },
2470 { "THURSDAY", tDAY, 4 },
2471 { "THUR", tDAY, 4 },
2472 { "THURS", tDAY, 4 },
2473 { "FRIDAY", tDAY, 5 },
2474 { "SATURDAY", tDAY, 6 },
2478 static table const time_units_table[] =
2480 { "YEAR", tYEAR_UNIT, 1 },
2481 { "MONTH", tMONTH_UNIT, 1 },
2482 { "FORTNIGHT",tDAY_UNIT, 14 },
2483 { "WEEK", tDAY_UNIT, 7 },
2484 { "DAY", tDAY_UNIT, 1 },
2485 { "HOUR", tHOUR_UNIT, 1 },
2486 { "MINUTE", tMINUTE_UNIT, 1 },
2487 { "MIN", tMINUTE_UNIT, 1 },
2488 { "SECOND", tSEC_UNIT, 1 },
2489 { "SEC", tSEC_UNIT, 1 },
2493 /* Assorted relative-time words. */
2494 static table const relative_time_table[] =
2496 { "TOMORROW", tDAY_UNIT, 1 },
2497 { "YESTERDAY",tDAY_UNIT, -1 },
2498 { "TODAY", tDAY_UNIT, 0 },
2499 { "NOW", tDAY_UNIT, 0 },
2500 { "LAST", tORDINAL, -1 },
2501 { "THIS", tORDINAL, 0 },
2502 { "NEXT", tORDINAL, 1 },
2503 { "FIRST", tORDINAL, 1 },
2504 /*{ "SECOND", tORDINAL, 2 }, */
2505 { "THIRD", tORDINAL, 3 },
2506 { "FOURTH", tORDINAL, 4 },
2507 { "FIFTH", tORDINAL, 5 },
2508 { "SIXTH", tORDINAL, 6 },
2509 { "SEVENTH", tORDINAL, 7 },
2510 { "EIGHTH", tORDINAL, 8 },
2511 { "NINTH", tORDINAL, 9 },
2512 { "TENTH", tORDINAL, 10 },
2513 { "ELEVENTH", tORDINAL, 11 },
2514 { "TWELFTH", tORDINAL, 12 },
2519 /* The universal time zone table. These labels can be used even for
2520 time stamps that would not otherwise be valid, e.g., GMT time
2521 stamps in London during summer. */
2522 static table const universal_time_zone_table[] =
2524 { "GMT", tZONE, HOUR ( 0) }, /* Greenwich Mean */
2525 { "UT", tZONE, HOUR ( 0) }, /* Universal (Coordinated) */
2526 { "UTC", tZONE, HOUR ( 0) },
2530 /* The time zone table. This table is necessarily incomplete, as time
2531 zone abbreviations are ambiguous; e.g. Australians interpret "EST"
2532 as Eastern time in Australia, not as US Eastern Standard Time.
2533 You cannot rely on getdate to handle arbitrary time zone
2534 abbreviations; use numeric abbreviations like `-0500' instead. */
2535 static table const time_zone_table[] =
2537 { "WET", tZONE, HOUR ( 0) }, /* Western European */
2538 { "WEST", tDAYZONE, HOUR ( 0) }, /* Western European Summer */
2539 { "BST", tDAYZONE, HOUR ( 0) }, /* British Summer */
2540 { "ART", tZONE, -HOUR ( 3) }, /* Argentina */
2541 { "BRT", tZONE, -HOUR ( 3) }, /* Brazil */
2542 { "BRST", tDAYZONE, -HOUR ( 3) }, /* Brazil Summer */
2543 { "NST", tZONE, -(HOUR ( 3) + 30) }, /* Newfoundland Standard */
2544 { "NDT", tDAYZONE,-(HOUR ( 3) + 30) }, /* Newfoundland Daylight */
2545 { "AST", tZONE, -HOUR ( 4) }, /* Atlantic Standard */
2546 { "ADT", tDAYZONE, -HOUR ( 4) }, /* Atlantic Daylight */
2547 { "CLT", tZONE, -HOUR ( 4) }, /* Chile */
2548 { "CLST", tDAYZONE, -HOUR ( 4) }, /* Chile Summer */
2549 { "EST", tZONE, -HOUR ( 5) }, /* Eastern Standard */
2550 { "EDT", tDAYZONE, -HOUR ( 5) }, /* Eastern Daylight */
2551 { "CST", tZONE, -HOUR ( 6) }, /* Central Standard */
2552 { "CDT", tDAYZONE, -HOUR ( 6) }, /* Central Daylight */
2553 { "MST", tZONE, -HOUR ( 7) }, /* Mountain Standard */
2554 { "MDT", tDAYZONE, -HOUR ( 7) }, /* Mountain Daylight */
2555 { "PST", tZONE, -HOUR ( 8) }, /* Pacific Standard */
2556 { "PDT", tDAYZONE, -HOUR ( 8) }, /* Pacific Daylight */
2557 { "AKST", tZONE, -HOUR ( 9) }, /* Alaska Standard */
2558 { "AKDT", tDAYZONE, -HOUR ( 9) }, /* Alaska Daylight */
2559 { "HST", tZONE, -HOUR (10) }, /* Hawaii Standard */
2560 { "HAST", tZONE, -HOUR (10) }, /* Hawaii-Aleutian Standard */
2561 { "HADT", tDAYZONE, -HOUR (10) }, /* Hawaii-Aleutian Daylight */
2562 { "SST", tZONE, -HOUR (12) }, /* Samoa Standard */
2563 { "WAT", tZONE, HOUR ( 1) }, /* West Africa */
2564 { "CET", tZONE, HOUR ( 1) }, /* Central European */
2565 { "CEST", tDAYZONE, HOUR ( 1) }, /* Central European Summer */
2566 { "MET", tZONE, HOUR ( 1) }, /* Middle European */
2567 { "MEZ", tZONE, HOUR ( 1) }, /* Middle European */
2568 { "MEST", tDAYZONE, HOUR ( 1) }, /* Middle European Summer */
2569 { "MESZ", tDAYZONE, HOUR ( 1) }, /* Middle European Summer */
2570 { "EET", tZONE, HOUR ( 2) }, /* Eastern European */
2571 { "EEST", tDAYZONE, HOUR ( 2) }, /* Eastern European Summer */
2572 { "CAT", tZONE, HOUR ( 2) }, /* Central Africa */
2573 { "SAST", tZONE, HOUR ( 2) }, /* South Africa Standard */
2574 { "EAT", tZONE, HOUR ( 3) }, /* East Africa */
2575 { "MSK", tZONE, HOUR ( 3) }, /* Moscow */
2576 { "MSD", tDAYZONE, HOUR ( 3) }, /* Moscow Daylight */
2577 { "IST", tZONE, (HOUR ( 5) + 30) }, /* India Standard */
2578 { "SGT", tZONE, HOUR ( 8) }, /* Singapore */
2579 { "KST", tZONE, HOUR ( 9) }, /* Korea Standard */
2580 { "JST", tZONE, HOUR ( 9) }, /* Japan Standard */
2581 { "GST", tZONE, HOUR (10) }, /* Guam Standard */
2582 { "NZST", tZONE, HOUR (12) }, /* New Zealand Standard */
2583 { "NZDT", tDAYZONE, HOUR (12) }, /* New Zealand Daylight */
2587 /* Military time zone table. */
2588 static table const military_table[] =
2590 { "A", tZONE, -HOUR ( 1) },
2591 { "B", tZONE, -HOUR ( 2) },
2592 { "C", tZONE, -HOUR ( 3) },
2593 { "D", tZONE, -HOUR ( 4) },
2594 { "E", tZONE, -HOUR ( 5) },
2595 { "F", tZONE, -HOUR ( 6) },
2596 { "G", tZONE, -HOUR ( 7) },
2597 { "H", tZONE, -HOUR ( 8) },
2598 { "I", tZONE, -HOUR ( 9) },
2599 { "K", tZONE, -HOUR (10) },
2600 { "L", tZONE, -HOUR (11) },
2601 { "M", tZONE, -HOUR (12) },
2602 { "N", tZONE, HOUR ( 1) },
2603 { "O", tZONE, HOUR ( 2) },
2604 { "P", tZONE, HOUR ( 3) },
2605 { "Q", tZONE, HOUR ( 4) },
2606 { "R", tZONE, HOUR ( 5) },
2607 { "S", tZONE, HOUR ( 6) },
2608 { "T", tZONE, HOUR ( 7) },
2609 { "U", tZONE, HOUR ( 8) },
2610 { "V", tZONE, HOUR ( 9) },
2611 { "W", tZONE, HOUR (10) },
2612 { "X", tZONE, HOUR (11) },
2613 { "Y", tZONE, HOUR (12) },
2614 { "Z", tZONE, HOUR ( 0) },
2620 /* Convert a time zone expressed as HH:MM into an integer count of
2621 minutes. If MM is negative, then S is of the form HHMM and needs
2622 to be picked apart; otherwise, S is of the form HH. */
2625 time_zone_hhmm (textint s, long int mm)
2628 return (s.value / 100) * 60 + s.value % 100;
2630 return s.value * 60 + (s.negative ? -mm : mm);
2634 to_hour (long int hours, int meridian)
2638 default: /* Pacify GCC. */
2640 return 0 <= hours && hours < 24 ? hours : -1;
2642 return 0 < hours && hours < 12 ? hours : hours == 12 ? 0 : -1;
2644 return 0 < hours && hours < 12 ? hours + 12 : hours == 12 ? 12 : -1;
2649 to_year (textint textyear)
2651 long int year = textyear.value;
2656 /* XPG4 suggests that years 00-68 map to 2000-2068, and
2657 years 69-99 map to 1969-1999. */
2658 else if (textyear.digits == 2)
2659 year += year < 69 ? 2000 : 1900;
2664 static table const *
2665 lookup_zone (parser_control const *pc, char const *name)
2669 for (tp = universal_time_zone_table; tp->name; tp++)
2670 if (strcmp (name, tp->name) == 0)
2673 /* Try local zone abbreviations before those in time_zone_table, as
2674 the local ones are more likely to be right. */
2675 for (tp = pc->local_time_zone_table; tp->name; tp++)
2676 if (strcmp (name, tp->name) == 0)
2679 for (tp = time_zone_table; tp->name; tp++)
2680 if (strcmp (name, tp->name) == 0)
2686 #if ! HAVE_TM_GMTOFF
2687 /* Yield the difference between *A and *B,
2688 measured in seconds, ignoring leap seconds.
2689 The body of this function is taken directly from the GNU C Library;
2690 see src/strftime.c. */
2692 tm_diff (struct tm const *a, struct tm const *b)
2694 /* Compute intervening leap days correctly even if year is negative.
2695 Take care to avoid int overflow in leap day calculations. */
2696 int a4 = SHR (a->tm_year, 2) + SHR (TM_YEAR_BASE, 2) - ! (a->tm_year & 3);
2697 int b4 = SHR (b->tm_year, 2) + SHR (TM_YEAR_BASE, 2) - ! (b->tm_year & 3);
2698 int a100 = a4 / 25 - (a4 % 25 < 0);
2699 int b100 = b4 / 25 - (b4 % 25 < 0);
2700 int a400 = SHR (a100, 2);
2701 int b400 = SHR (b100, 2);
2702 int intervening_leap_days = (a4 - b4) - (a100 - b100) + (a400 - b400);
2703 long int ayear = a->tm_year;
2704 long int years = ayear - b->tm_year;
2705 long int days = (365 * years + intervening_leap_days
2706 + (a->tm_yday - b->tm_yday));
2707 return (60 * (60 * (24 * days + (a->tm_hour - b->tm_hour))
2708 + (a->tm_min - b->tm_min))
2709 + (a->tm_sec - b->tm_sec));
2711 #endif /* ! HAVE_TM_GMTOFF */
2713 static table const *
2714 lookup_word (parser_control const *pc, char *word)
2723 /* Make it uppercase. */
2724 for (p = word; *p; p++)
2726 unsigned char ch = *p;
2730 for (tp = meridian_table; tp->name; tp++)
2731 if (strcmp (word, tp->name) == 0)
2734 /* See if we have an abbreviation for a month. */
2735 wordlen = strlen (word);
2736 abbrev = wordlen == 3 || (wordlen == 4 && word[3] == '.');
2738 for (tp = month_and_day_table; tp->name; tp++)
2739 if ((abbrev ? strncmp (word, tp->name, 3) : strcmp (word, tp->name)) == 0)
2742 if ((tp = lookup_zone (pc, word)))
2745 if (strcmp (word, dst_table[0].name) == 0)
2748 for (tp = time_units_table; tp->name; tp++)
2749 if (strcmp (word, tp->name) == 0)
2752 /* Strip off any plural and try the units table again. */
2753 if (word[wordlen - 1] == 'S')
2755 word[wordlen - 1] = '\0';
2756 for (tp = time_units_table; tp->name; tp++)
2757 if (strcmp (word, tp->name) == 0)
2759 word[wordlen - 1] = 'S'; /* For "this" in relative_time_table. */
2762 for (tp = relative_time_table; tp->name; tp++)
2763 if (strcmp (word, tp->name) == 0)
2766 /* Military time zones. */
2768 for (tp = military_table; tp->name; tp++)
2769 if (word[0] == tp->name[0])
2772 /* Drop out any periods and try the time zone table again. */
2773 for (period_found = false, p = q = word; (*p = *q); q++)
2775 period_found = true;
2778 if (period_found && (tp = lookup_zone (pc, word)))
2785 yylex (YYSTYPE *lvalp, parser_control *pc)
2792 while (c = *pc->input, isspace (c))
2795 if (ISDIGIT (c) || c == '-' || c == '+')
2799 unsigned long int value;
2800 if (c == '-' || c == '+')
2802 sign = c == '-' ? -1 : 1;
2803 while (c = *++pc->input, isspace (c))
2806 /* skip the '-' sign */
2812 for (value = 0; ; value *= 10)
2814 unsigned long int value1 = value + (c - '0');
2821 if (ULONG_MAX / 10 < value)
2824 if ((c == '.' || c == ',') && ISDIGIT (p[1]))
2829 unsigned long int value1;
2831 /* Check for overflow when converting value to time_t. */
2846 if (value != value1)
2849 /* Accumulate fraction, to ns precision. */
2852 for (digits = 2; digits <= LOG10_BILLION; digits++)
2859 /* Skip excess digits, truncating toward -Infinity. */
2861 for (; ISDIGIT (*p); p++)
2867 while (ISDIGIT (*p))
2870 /* Adjust to the timespec convention, which is that
2871 tv_nsec is always a positive offset even if tv_sec is
2881 lvalp->timespec.tv_sec = s;
2882 lvalp->timespec.tv_nsec = ns;
2884 return sign ? tSDECIMAL_NUMBER : tUDECIMAL_NUMBER;
2888 lvalp->textintval.negative = sign < 0;
2891 lvalp->textintval.value = - value;
2892 if (0 < lvalp->textintval.value)
2897 lvalp->textintval.value = value;
2898 if (lvalp->textintval.value < 0)
2901 lvalp->textintval.digits = p - pc->input;
2903 return sign ? tSNUMBER : tUNUMBER;
2915 if (p < buff + sizeof buff - 1)
2919 while (isalpha (c) || c == '.');
2922 tp = lookup_word (pc, buff);
2925 lvalp->intval = tp->value;
2930 return *pc->input++;
2946 /* Do nothing if the parser reports an error. */
2948 yyerror (parser_control const *pc ATTRIBUTE_UNUSED,
2949 char const *s ATTRIBUTE_UNUSED)
2954 /* If *TM0 is the old and *TM1 is the new value of a struct tm after
2955 passing it to mktime, return true if it's OK that mktime returned T.
2956 It's not OK if *TM0 has out-of-range members. */
2959 mktime_ok (struct tm const *tm0, struct tm const *tm1, time_t t)
2961 if (t == (time_t) -1)
2963 /* Guard against falsely reporting an error when parsing a time
2964 stamp that happens to equal (time_t) -1, on a host that
2965 supports such a time stamp. */
2966 tm1 = localtime (&t);
2971 return ! ((tm0->tm_sec ^ tm1->tm_sec)
2972 | (tm0->tm_min ^ tm1->tm_min)
2973 | (tm0->tm_hour ^ tm1->tm_hour)
2974 | (tm0->tm_mday ^ tm1->tm_mday)
2975 | (tm0->tm_mon ^ tm1->tm_mon)
2976 | (tm0->tm_year ^ tm1->tm_year));
2979 /* A reasonable upper bound for the size of ordinary TZ strings.
2980 Use heap allocation if TZ's length exceeds this. */
2981 enum { TZBUFSIZE = 100 };
2983 /* Return a copy of TZ, stored in TZBUF if it fits, and heap-allocated
2986 get_tz (char tzbuf[TZBUFSIZE])
2988 char *tz = getenv ("TZ");
2991 size_t tzsize = strlen (tz) + 1;
2992 tz = (tzsize <= TZBUFSIZE
2993 ? memcpy (tzbuf, tz, tzsize)
2994 : xmemdup (tz, tzsize));
2999 /* Parse a date/time string, storing the resulting time value into *RESULT.
3000 The string itself is pointed to by P. Return true if successful.
3001 P can be an incomplete or relative time specification; if so, use
3002 *NOW as the basis for the returned time. */
3004 get_date (struct timespec *result, char const *p, struct timespec const *now)
3008 struct tm const *tmp;
3012 struct timespec gettime_buffer;
3014 bool tz_was_altered = false;
3016 char tz0buf[TZBUFSIZE];
3021 gettime (&gettime_buffer);
3022 now = &gettime_buffer;
3025 Start = now->tv_sec;
3026 Start_ns = now->tv_nsec;
3028 tmp = localtime (&now->tv_sec);
3032 while (c = *p, isspace (c))
3035 if (strncmp (p, "TZ=\"", 4) == 0)
3037 char const *tzbase = p + 4;
3041 for (s = tzbase; *s; s++, tzsize++)
3045 if (! (*s == '\\' || *s == '"'))
3052 char tz1buf[TZBUFSIZE];
3053 bool large_tz = TZBUFSIZE < tzsize;
3055 tz0 = get_tz (tz0buf);
3056 z = tz1 = large_tz ? xmalloc (tzsize) : tz1buf;
3057 for (s = tzbase; *s != '"'; s++)
3058 *z++ = *(s += *s == '\\');
3060 setenv_ok = setenv ("TZ", tz1, 1) == 0;
3065 tz_was_altered = true;
3071 pc.year.value = tmp->tm_year;
3072 pc.year.value += TM_YEAR_BASE;
3074 pc.month = tmp->tm_mon + 1;
3075 pc.day = tmp->tm_mday;
3076 pc.hour = tmp->tm_hour;
3077 pc.minutes = tmp->tm_min;
3078 pc.seconds.tv_sec = tmp->tm_sec;
3079 pc.seconds.tv_nsec = Start_ns;
3080 tm.tm_isdst = tmp->tm_isdst;
3082 pc.meridian = MER24;
3083 pc.rel = RELATIVE_TIME_0;
3084 pc.timespec_seen = false;
3085 pc.rels_seen = false;
3089 pc.local_zones_seen = 0;
3093 #if HAVE_STRUCT_TM_TM_ZONE
3094 pc.local_time_zone_table[0].name = tmp->tm_zone;
3095 pc.local_time_zone_table[0].type = tLOCAL_ZONE;
3096 pc.local_time_zone_table[0].value = tmp->tm_isdst;
3097 pc.local_time_zone_table[1].name = NULL;
3099 /* Probe the names used in the next three calendar quarters, looking
3100 for a tm_isdst different from the one we already have. */
3103 for (quarter = 1; quarter <= 3; quarter++)
3105 time_t probe = Start + quarter * (90 * 24 * 60 * 60);
3106 struct tm const *probe_tm = localtime (&probe);
3107 if (probe_tm && probe_tm->tm_zone
3108 && probe_tm->tm_isdst != pc.local_time_zone_table[0].value)
3111 pc.local_time_zone_table[1].name = probe_tm->tm_zone;
3112 pc.local_time_zone_table[1].type = tLOCAL_ZONE;
3113 pc.local_time_zone_table[1].value = probe_tm->tm_isdst;
3114 pc.local_time_zone_table[2].name = NULL;
3124 extern char *tzname[];
3127 for (i = 0; i < 2; i++)
3129 pc.local_time_zone_table[i].name = tzname[i];
3130 pc.local_time_zone_table[i].type = tLOCAL_ZONE;
3131 pc.local_time_zone_table[i].value = i;
3133 pc.local_time_zone_table[i].name = NULL;
3136 pc.local_time_zone_table[0].name = NULL;
3140 if (pc.local_time_zone_table[0].name && pc.local_time_zone_table[1].name
3141 && ! strcmp (pc.local_time_zone_table[0].name,
3142 pc.local_time_zone_table[1].name))
3144 /* This locale uses the same abbrevation for standard and
3145 daylight times. So if we see that abbreviation, we don't
3146 know whether it's daylight time. */
3147 pc.local_time_zone_table[0].value = -1;
3148 pc.local_time_zone_table[1].name = NULL;
3151 if (yyparse (&pc) != 0)
3154 if (pc.timespec_seen)
3155 *result = pc.seconds;
3158 if (1 < (pc.times_seen | pc.dates_seen | pc.days_seen | pc.dsts_seen
3159 | (pc.local_zones_seen + pc.zones_seen)))
3162 tm.tm_year = to_year (pc.year) - TM_YEAR_BASE;
3163 tm.tm_mon = pc.month - 1;
3164 tm.tm_mday = pc.day;
3165 if (pc.times_seen || (pc.rels_seen && ! pc.dates_seen && ! pc.days_seen))
3167 tm.tm_hour = to_hour (pc.hour, pc.meridian);
3170 tm.tm_min = pc.minutes;
3171 tm.tm_sec = pc.seconds.tv_sec;
3175 tm.tm_hour = tm.tm_min = tm.tm_sec = 0;
3176 pc.seconds.tv_nsec = 0;
3179 /* Let mktime deduce tm_isdst if we have an absolute time stamp. */
3180 if (pc.dates_seen | pc.days_seen | pc.times_seen)
3183 /* But if the input explicitly specifies local time with or without
3184 DST, give mktime that information. */
3185 if (pc.local_zones_seen)
3186 tm.tm_isdst = pc.local_isdst;
3190 Start = mktime (&tm);
3192 if (! mktime_ok (&tm0, &tm, Start))
3194 if (! pc.zones_seen)
3198 /* Guard against falsely reporting errors near the time_t
3199 boundaries when parsing times in other time zones. For
3200 example, suppose the input string "1969-12-31 23:00:00 -0100",
3201 the current time zone is 8 hours ahead of UTC, and the min
3202 time_t value is 1970-01-01 00:00:00 UTC. Then the min
3203 localtime value is 1970-01-01 08:00:00, and mktime will
3204 therefore fail on 1969-12-31 23:00:00. To work around the
3205 problem, set the time zone to 1 hour behind UTC temporarily
3206 by setting TZ="XXX1:00" and try mktime again. */
3208 long int time_zone = pc.time_zone;
3209 long int abs_time_zone = time_zone < 0 ? - time_zone : time_zone;
3210 long int abs_time_zone_hour = abs_time_zone / 60;
3211 int abs_time_zone_min = abs_time_zone % 60;
3212 char tz1buf[sizeof "XXX+0:00"
3213 + sizeof pc.time_zone * CHAR_BIT / 3];
3214 if (!tz_was_altered)
3215 tz0 = get_tz (tz0buf);
3216 sprintf (tz1buf, "XXX%s%ld:%02d", "-" + (time_zone < 0),
3217 abs_time_zone_hour, abs_time_zone_min);
3218 if (setenv ("TZ", tz1buf, 1) != 0)
3220 tz_was_altered = true;
3222 Start = mktime (&tm);
3223 if (! mktime_ok (&tm0, &tm, Start))
3228 if (pc.days_seen && ! pc.dates_seen)
3230 tm.tm_mday += ((pc.day_number - tm.tm_wday + 7) % 7
3231 + 7 * (pc.day_ordinal - (0 < pc.day_ordinal)));
3233 Start = mktime (&tm);
3234 if (Start == (time_t) -1)
3240 long int delta = pc.time_zone * 60;
3242 #ifdef HAVE_TM_GMTOFF
3243 delta -= tm.tm_gmtoff;
3246 struct tm const *gmt = gmtime (&t);
3249 delta -= tm_diff (&tm, gmt);
3252 if ((Start < t1) != (delta < 0))
3253 goto fail; /* time_t overflow */
3257 /* Add relative date. */
3258 if (pc.rel.year | pc.rel.month | pc.rel.day)
3260 int year = tm.tm_year + pc.rel.year;
3261 int month = tm.tm_mon + pc.rel.month;
3262 int day = tm.tm_mday + pc.rel.day;
3263 if (((year < tm.tm_year) ^ (pc.rel.year < 0))
3264 | ((month < tm.tm_mon) ^ (pc.rel.month < 0))
3265 | ((day < tm.tm_mday) ^ (pc.rel.day < 0)))
3270 tm.tm_hour = tm0.tm_hour;
3271 tm.tm_min = tm0.tm_min;
3272 tm.tm_sec = tm0.tm_sec;
3273 tm.tm_isdst = tm0.tm_isdst;
3274 Start = mktime (&tm);
3275 if (Start == (time_t) -1)
3279 /* Add relative hours, minutes, and seconds. On hosts that support
3280 leap seconds, ignore the possibility of leap seconds; e.g.,
3281 "+ 10 minutes" adds 600 seconds, even if one of them is a
3282 leap second. Typically this is not what the user wants, but it's
3283 too hard to do it the other way, because the time zone indicator
3284 must be applied before relative times, and if mktime is applied
3285 again the time zone will be lost. */
3287 long int sum_ns = pc.seconds.tv_nsec + pc.rel.ns;
3288 long int normalized_ns = (sum_ns % BILLION + BILLION) % BILLION;
3290 long int d1 = 60 * 60 * pc.rel.hour;
3291 time_t t1 = t0 + d1;
3292 long int d2 = 60 * pc.rel.minutes;
3293 time_t t2 = t1 + d2;
3294 long int d3 = pc.rel.seconds;
3295 time_t t3 = t2 + d3;
3296 long int d4 = (sum_ns - normalized_ns) / BILLION;
3297 time_t t4 = t3 + d4;
3299 if ((d1 / (60 * 60) ^ pc.rel.hour)
3300 | (d2 / 60 ^ pc.rel.minutes)
3301 | ((t1 < t0) ^ (d1 < 0))
3302 | ((t2 < t1) ^ (d2 < 0))
3303 | ((t3 < t2) ^ (d3 < 0))
3304 | ((t4 < t3) ^ (d4 < 0)))
3307 result->tv_sec = t4;
3308 result->tv_nsec = normalized_ns;
3318 ok &= (tz0 ? setenv ("TZ", tz0, 1) : unsetenv ("TZ")) == 0;
3327 main (int ac, char **av)
3331 printf ("Enter date, or blank line to exit.\n\t> ");
3334 buff[BUFSIZ - 1] = '\0';
3335 while (fgets (buff, BUFSIZ - 1, stdin) && buff[0])
3338 struct tm const *tm;
3339 if (! get_date (&d, buff, NULL))
3340 printf ("Bad format - couldn't convert.\n");
3341 else if (! (tm = localtime (&d.tv_sec)))
3343 long int sec = d.tv_sec;
3344 printf ("localtime (%ld) failed\n", sec);
3349 printf ("%04ld-%02d-%02d %02d:%02d:%02d.%09d\n",
3350 tm->tm_year + 1900L, tm->tm_mon + 1, tm->tm_mday,
3351 tm->tm_hour, tm->tm_min, tm->tm_sec, ns);