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
86 tSDECIMAL_NUMBER = 275,
87 tUDECIMAL_NUMBER = 276
93 #define tYEAR_UNIT 260
94 #define tMONTH_UNIT 261
95 #define tHOUR_UNIT 262
96 #define tMINUTE_UNIT 263
101 #define tLOCAL_ZONE 268
102 #define tMERIDIAN 269
108 #define tSDECIMAL_NUMBER 275
109 #define tUDECIMAL_NUMBER 276
114 /* Copy the first part of user declarations. */
117 /* Parse a string into an internal time stamp.
119 Copyright (C) 1999, 2000, 2002, 2003, 2004, 2005, 2006, 2007 Free Software
122 This program is free software: you can redistribute it and/or modify
123 it under the terms of the GNU General Public License as published by
124 the Free Software Foundation; either version 3 of the License, or
125 (at your option) any later version.
127 This program is distributed in the hope that it will be useful,
128 but WITHOUT ANY WARRANTY; without even the implied warranty of
129 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
130 GNU General Public License for more details.
132 You should have received a copy of the GNU General Public License
133 along with this program. If not, see <http://www.gnu.org/licenses/>. */
135 /* Originally written by Steven M. Bellovin <smb@research.att.com> while
136 at the University of North Carolina at Chapel Hill. Later tweaked by
137 a couple of people on Usenet. Completely overhauled by Rich $alz
138 <rsalz@bbn.com> and Jim Berets <jberets@bbn.com> in August, 1990.
140 Modified by Paul Eggert <eggert@twinsun.com> in August 1999 to do
141 the right thing about local DST. Also modified by Paul Eggert
142 <eggert@cs.ucla.edu> in February 2004 to support
143 nanosecond-resolution time stamps, and in October 2004 to support
144 TZ strings in dates. */
146 /* FIXME: Check for arithmetic overflow in all cases, not just
153 #include "intprops.h"
154 #include "timespec.h"
157 /* There's no need to extend the stack, so there's no need to involve
159 #define YYSTACK_USE_ALLOCA 0
161 /* Tell Bison how much stack space is needed. 20 should be plenty for
162 this grammar, which is not right recursive. Beware setting it too
163 high, since that might cause problems on machines whose
164 implementations have lame stack-overflow checking. */
165 #define YYMAXDEPTH 20
166 #define YYINITDEPTH YYMAXDEPTH
168 /* Since the code of getdate.y is not included in the Emacs executable
169 itself, there is no need to #define static in this file. Even if
170 the code were included in the Emacs executable, it probably
171 wouldn't do any harm to #undef it here; this will only cause
172 problems if we try to write to a static variable, which I don't
173 think this code needs to do. */
187 /* ISDIGIT differs from isdigit, as follows:
188 - Its arg may be any int or unsigned int; it need not be an unsigned char
190 - It's typically faster.
191 POSIX says that only '0' through '9' are digits. Prefer ISDIGIT to
192 isdigit unless it's important to use the locale's definition
193 of `digit' even when the host does not conform to POSIX. */
194 #define ISDIGIT(c) ((unsigned int) (c) - '0' <= 9)
196 #ifndef __attribute__
197 # if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 8) || __STRICT_ANSI__
198 # define __attribute__(x)
202 #ifndef ATTRIBUTE_UNUSED
203 # define ATTRIBUTE_UNUSED __attribute__ ((__unused__))
206 /* Shift A right by B bits portably, by dividing A by 2**B and
207 truncating towards minus infinity. A and B should be free of side
208 effects, and B should be in the range 0 <= B <= INT_BITS - 2, where
209 INT_BITS is the number of useful bits in an int. GNU code can
210 assume that INT_BITS is at least 32.
212 ISO C99 says that A >> B is implementation-defined if A < 0. Some
213 implementations (e.g., UNICOS 9.0 on a Cray Y-MP EL) don't shift
214 right in the usual way when A < 0, so SHR falls back on division if
215 ordinary A >> B doesn't seem to be the usual signed shift. */
219 : (a) / (1 << (b)) - ((a) % (1 << (b)) < 0))
221 #define EPOCH_YEAR 1970
222 #define TM_YEAR_BASE 1900
224 #define HOUR(x) ((x) * 60)
226 /* Lots of this code assumes time_t and time_t-like values fit into
227 long int. It also assumes that signed integer overflow silently
228 wraps around, but there's no portable way to check for that at
230 verify (TYPE_IS_INTEGER (time_t));
231 verify (LONG_MIN <= TYPE_MINIMUM (time_t) && TYPE_MAXIMUM (time_t) <= LONG_MAX);
233 /* An integer value, and the number of digits in its textual
242 /* An entry in the lexical lookup table. */
250 /* Meridian: am, pm, or 24-hour style. */
251 enum { MERam, MERpm, MER24 };
253 enum { BILLION = 1000000000, LOG10_BILLION = 9 };
255 /* Relative times. */
258 /* Relative year, month, day, hour, minutes, seconds, and nanoseconds. */
268 #if HAVE_COMPOUND_LITERALS
269 # define RELATIVE_TIME_0 ((relative_time) { 0, 0, 0, 0, 0, 0, 0 })
271 static relative_time const RELATIVE_TIME_0;
274 /* Information passed to and from the parser. */
277 /* The input string remaining to be parsed. */
280 /* N, if this is the Nth Tuesday. */
281 long int day_ordinal;
283 /* Day of week; Sunday is 0. */
286 /* tm_isdst flag for the local zone. */
289 /* Time zone, in minutes east of UTC. */
292 /* Style used for time. */
295 /* Gregorian year, month, day, hour, minutes, seconds, and nanoseconds. */
301 struct timespec seconds; /* includes nanoseconds */
303 /* Relative year, month, day, hour, minutes, seconds, and nanoseconds. */
306 /* Presence or counts of nonterminals of various flavors parsed so far. */
311 size_t local_zones_seen;
316 /* Table of local time zone abbrevations, terminated by a null entry. */
317 table local_time_zone_table[3];
321 static int yylex (union YYSTYPE *, parser_control *);
322 static int yyerror (parser_control const *, char const *);
323 static long int time_zone_hhmm (textint, long int);
325 /* Extract into *PC any date and time info from a string of digits
326 of the form e.g., YYYYMMDD, YYMMDD, HHMM, HH (and sometimes YYY,
329 digits_to_date_time (parser_control *pc, textint text_int)
331 if (pc->dates_seen && ! pc->year.digits
332 && ! pc->rels_seen && (pc->times_seen || 2 < text_int.digits))
336 if (4 < text_int.digits)
339 pc->day = text_int.value % 100;
340 pc->month = (text_int.value / 100) % 100;
341 pc->year.value = text_int.value / 10000;
342 pc->year.digits = text_int.digits - 4;
347 if (text_int.digits <= 2)
349 pc->hour = text_int.value;
354 pc->hour = text_int.value / 100;
355 pc->minutes = text_int.value % 100;
357 pc->seconds.tv_sec = 0;
358 pc->seconds.tv_nsec = 0;
359 pc->meridian = MER24;
366 /* Enabling traces. */
371 /* Enabling verbose error messages. */
372 #ifdef YYERROR_VERBOSE
373 # undef YYERROR_VERBOSE
374 # define YYERROR_VERBOSE 1
376 # define YYERROR_VERBOSE 0
379 /* Enabling the token table. */
380 #ifndef YYTOKEN_TABLE
381 # define YYTOKEN_TABLE 0
384 #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
385 typedef union YYSTYPE
386 #line 261 "getdate.y"
390 struct timespec timespec;
393 /* Line 187 of yacc.c. */
394 #line 395 "getdate.c"
396 # define yystype YYSTYPE /* obsolescent; will be withdrawn */
397 # define YYSTYPE_IS_DECLARED 1
398 # define YYSTYPE_IS_TRIVIAL 1
403 /* Copy the second part of user declarations. */
406 /* Line 216 of yacc.c. */
407 #line 408 "getdate.c"
414 typedef YYTYPE_UINT8 yytype_uint8;
416 typedef unsigned char yytype_uint8;
420 typedef YYTYPE_INT8 yytype_int8;
421 #elif (defined __STDC__ || defined __C99__FUNC__ \
422 || defined __cplusplus || defined _MSC_VER)
423 typedef signed char yytype_int8;
425 typedef short int yytype_int8;
429 typedef YYTYPE_UINT16 yytype_uint16;
431 typedef unsigned short int yytype_uint16;
435 typedef YYTYPE_INT16 yytype_int16;
437 typedef short int yytype_int16;
441 # ifdef __SIZE_TYPE__
442 # define YYSIZE_T __SIZE_TYPE__
443 # elif defined size_t
444 # define YYSIZE_T size_t
445 # elif ! defined YYSIZE_T && (defined __STDC__ || defined __C99__FUNC__ \
446 || defined __cplusplus || defined _MSC_VER)
447 # include <stddef.h> /* INFRINGES ON USER NAME SPACE */
448 # define YYSIZE_T size_t
450 # define YYSIZE_T unsigned int
454 #define YYSIZE_MAXIMUM ((YYSIZE_T) -1)
459 # include <libintl.h> /* INFRINGES ON USER NAME SPACE */
460 # define YY_(msgid) dgettext ("bison-runtime", msgid)
464 # define YY_(msgid) msgid
468 /* Suppress unused-variable warnings by "using" E. */
469 #if ! defined lint || defined __GNUC__
470 # define YYUSE(e) ((void) (e))
472 # define YYUSE(e) /* empty */
475 /* Identity function, used to suppress warnings about constant conditions. */
479 #if (defined __STDC__ || defined __C99__FUNC__ \
480 || defined __cplusplus || defined _MSC_VER)
493 #if ! defined yyoverflow || YYERROR_VERBOSE
495 /* The parser invokes alloca or malloc; define the necessary symbols. */
497 # ifdef YYSTACK_USE_ALLOCA
498 # if YYSTACK_USE_ALLOCA
500 # define YYSTACK_ALLOC __builtin_alloca
501 # elif defined __BUILTIN_VA_ARG_INCR
502 # include <alloca.h> /* INFRINGES ON USER NAME SPACE */
504 # define YYSTACK_ALLOC __alloca
505 # elif defined _MSC_VER
506 # include <malloc.h> /* INFRINGES ON USER NAME SPACE */
507 # define alloca _alloca
509 # define YYSTACK_ALLOC alloca
510 # if ! defined _ALLOCA_H && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
511 || defined __cplusplus || defined _MSC_VER)
512 # include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
521 # ifdef YYSTACK_ALLOC
522 /* Pacify GCC's `empty if-body' warning. */
523 # define YYSTACK_FREE(Ptr) do { /* empty */; } while (YYID (0))
524 # ifndef YYSTACK_ALLOC_MAXIMUM
525 /* The OS might guarantee only one guard page at the bottom of the stack,
526 and a page size can be as small as 4096 bytes. So we cannot safely
527 invoke alloca (N) if N exceeds 4096. Use a slightly smaller number
528 to allow for a few compiler-allocated temporary stack slots. */
529 # define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */
532 # define YYSTACK_ALLOC YYMALLOC
533 # define YYSTACK_FREE YYFREE
534 # ifndef YYSTACK_ALLOC_MAXIMUM
535 # define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM
537 # if (defined __cplusplus && ! defined _STDLIB_H \
538 && ! ((defined YYMALLOC || defined malloc) \
539 && (defined YYFREE || defined free)))
540 # include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
546 # define YYMALLOC malloc
547 # if ! defined malloc && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
548 || defined __cplusplus || defined _MSC_VER)
549 void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */
554 # if ! defined free && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
555 || defined __cplusplus || defined _MSC_VER)
556 void free (void *); /* INFRINGES ON USER NAME SPACE */
560 #endif /* ! defined yyoverflow || YYERROR_VERBOSE */
563 #if (! defined yyoverflow \
564 && (! defined __cplusplus \
565 || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
567 /* A type that is properly aligned for any stack member. */
574 /* The size of the maximum gap between one aligned stack and the next. */
575 # define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1)
577 /* The size of an array large to enough to hold all stacks, each with
579 # define YYSTACK_BYTES(N) \
580 ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE)) \
581 + YYSTACK_GAP_MAXIMUM)
583 /* Copy COUNT objects from FROM to TO. The source and destination do
586 # if defined __GNUC__ && 1 < __GNUC__
587 # define YYCOPY(To, From, Count) \
588 __builtin_memcpy (To, From, (Count) * sizeof (*(From)))
590 # define YYCOPY(To, From, Count) \
594 for (yyi = 0; yyi < (Count); yyi++) \
595 (To)[yyi] = (From)[yyi]; \
601 /* Relocate STACK from its old location to the new one. The
602 local variables YYSIZE and YYSTACKSIZE give the old and new number of
603 elements in the stack, and YYPTR gives the new location of the
604 stack. Advance YYPTR to a properly aligned location for the next
606 # define YYSTACK_RELOCATE(Stack) \
609 YYSIZE_T yynewbytes; \
610 YYCOPY (&yyptr->Stack, Stack, yysize); \
611 Stack = &yyptr->Stack; \
612 yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \
613 yyptr += yynewbytes / sizeof (*yyptr); \
619 /* YYFINAL -- State number of the termination state. */
621 /* YYLAST -- Last index in YYTABLE. */
624 /* YYNTOKENS -- Number of terminals. */
626 /* YYNNTS -- Number of nonterminals. */
628 /* YYNRULES -- Number of rules. */
630 /* YYNRULES -- Number of states. */
633 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
635 #define YYMAXUTOK 276
637 #define YYTRANSLATE(YYX) \
638 ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
640 /* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */
641 static const yytype_uint8 yytranslate[] =
643 0, 2, 2, 2, 2, 2, 2, 2, 2, 2,
644 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
645 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
646 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
647 2, 2, 2, 2, 24, 2, 2, 25, 2, 2,
648 2, 2, 2, 2, 2, 2, 2, 2, 23, 2,
649 2, 2, 2, 2, 22, 2, 2, 2, 2, 2,
650 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
651 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
652 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
653 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
654 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
655 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
656 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
657 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
658 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
659 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
660 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
661 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
662 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
663 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
664 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
665 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
666 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
667 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
668 2, 2, 2, 2, 2, 2, 1, 2, 3, 4,
669 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
670 15, 16, 17, 18, 19, 20, 21
674 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
676 static const yytype_uint8 yyprhs[] =
678 0, 0, 3, 5, 7, 10, 11, 14, 16, 18,
679 20, 22, 24, 26, 28, 30, 33, 38, 44, 51,
680 59, 61, 64, 66, 69, 73, 75, 78, 80, 83,
681 86, 89, 93, 99, 103, 107, 111, 114, 119, 122,
682 126, 129, 131, 134, 137, 139, 142, 145, 147, 150,
683 153, 155, 158, 161, 163, 166, 169, 171, 174, 177,
684 180, 183, 185, 187, 190, 193, 196, 199, 202, 205,
685 207, 209, 211, 213, 215, 217, 219, 222, 223, 226,
689 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
690 static const yytype_int8 yyrhs[] =
692 27, 0, -1, 28, -1, 29, -1, 22, 39, -1,
693 -1, 29, 30, -1, 31, -1, 32, -1, 33, -1,
694 35, -1, 34, -1, 36, -1, 42, -1, 43, -1,
695 19, 14, -1, 19, 23, 19, 45, -1, 19, 23,
696 19, 18, 44, -1, 19, 23, 19, 23, 41, 45,
697 -1, 19, 23, 19, 23, 41, 18, 44, -1, 13,
698 -1, 13, 4, -1, 17, -1, 17, 38, -1, 17,
699 18, 44, -1, 12, -1, 17, 4, -1, 11, -1,
700 11, 24, -1, 16, 11, -1, 19, 11, -1, 19,
701 25, 19, -1, 19, 25, 19, 25, 19, -1, 19,
702 18, 18, -1, 19, 15, 18, -1, 15, 18, 18,
703 -1, 15, 19, -1, 15, 19, 24, 19, -1, 19,
704 15, -1, 19, 15, 19, -1, 37, 3, -1, 37,
705 -1, 16, 5, -1, 19, 5, -1, 5, -1, 16,
706 6, -1, 19, 6, -1, 6, -1, 16, 10, -1,
707 19, 10, -1, 10, -1, 16, 7, -1, 19, 7,
708 -1, 7, -1, 16, 8, -1, 19, 8, -1, 8,
709 -1, 16, 9, -1, 19, 9, -1, 20, 9, -1,
710 21, 9, -1, 9, -1, 38, -1, 18, 5, -1,
711 18, 6, -1, 18, 10, -1, 18, 7, -1, 18,
712 8, -1, 18, 9, -1, 40, -1, 41, -1, 20,
713 -1, 18, -1, 21, -1, 19, -1, 19, -1, 19,
714 38, -1, -1, 23, 19, -1, -1, 14, -1
717 /* YYRLINE[YYN] -- source line where rule number YYN was defined. */
718 static const yytype_uint16 yyrline[] =
720 0, 287, 287, 288, 292, 299, 301, 305, 307, 309,
721 311, 313, 315, 317, 318, 322, 330, 338, 348, 355,
722 367, 372, 380, 382, 392, 394, 396, 401, 406, 411,
723 416, 424, 429, 449, 456, 464, 472, 477, 483, 488,
724 497, 507, 520, 522, 524, 526, 528, 530, 532, 534,
725 536, 538, 540, 542, 544, 546, 548, 550, 552, 554,
726 556, 558, 560, 564, 566, 568, 570, 572, 574, 578,
727 578, 581, 582, 587, 588, 593, 598, 616, 617, 623,
732 #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
733 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
734 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
735 static const char *const yytname[] =
737 "$end", "error", "$undefined", "tAGO", "tDST", "tYEAR_UNIT",
738 "tMONTH_UNIT", "tHOUR_UNIT", "tMINUTE_UNIT", "tSEC_UNIT", "tDAY_UNIT",
739 "tDAY", "tDAYZONE", "tLOCAL_ZONE", "tMERIDIAN", "tMONTH", "tORDINAL",
740 "tZONE", "tSNUMBER", "tUNUMBER", "tSDECIMAL_NUMBER", "tUDECIMAL_NUMBER",
741 "'@'", "':'", "','", "'/'", "$accept", "spec", "timespec", "items",
742 "item", "time", "local_zone", "zone", "day", "date", "rel", "relunit",
743 "relunit_snumber", "seconds", "signed_seconds", "unsigned_seconds",
744 "number", "hybrid", "o_colon_minutes", "o_merid", 0
749 /* YYTOKNUM[YYLEX-NUM] -- Internal token number corresponding to
751 static const yytype_uint16 yytoknum[] =
753 0, 256, 257, 258, 259, 260, 261, 262, 263, 264,
754 265, 266, 267, 268, 269, 270, 271, 272, 273, 274,
755 275, 276, 64, 58, 44, 47
759 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
760 static const yytype_uint8 yyr1[] =
762 0, 26, 27, 27, 28, 29, 29, 30, 30, 30,
763 30, 30, 30, 30, 30, 31, 31, 31, 31, 31,
764 32, 32, 33, 33, 33, 33, 33, 34, 34, 34,
765 34, 35, 35, 35, 35, 35, 35, 35, 35, 35,
766 36, 36, 37, 37, 37, 37, 37, 37, 37, 37,
767 37, 37, 37, 37, 37, 37, 37, 37, 37, 37,
768 37, 37, 37, 38, 38, 38, 38, 38, 38, 39,
769 39, 40, 40, 41, 41, 42, 43, 44, 44, 45,
773 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
774 static const yytype_uint8 yyr2[] =
776 0, 2, 1, 1, 2, 0, 2, 1, 1, 1,
777 1, 1, 1, 1, 1, 2, 4, 5, 6, 7,
778 1, 2, 1, 2, 3, 1, 2, 1, 2, 2,
779 2, 3, 5, 3, 3, 3, 2, 4, 2, 3,
780 2, 1, 2, 2, 1, 2, 2, 1, 2, 2,
781 1, 2, 2, 1, 2, 2, 1, 2, 2, 2,
782 2, 1, 1, 2, 2, 2, 2, 2, 2, 1,
783 1, 1, 1, 1, 1, 1, 2, 0, 2, 0,
787 /* YYDEFACT[STATE-NAME] -- Default rule to reduce with in state
788 STATE-NUM when YYTABLE doesn't specify something else to do. Zero
789 means the default is an error. */
790 static const yytype_uint8 yydefact[] =
792 5, 0, 0, 2, 3, 72, 74, 71, 73, 4,
793 69, 70, 1, 44, 47, 53, 56, 61, 50, 27,
794 25, 20, 0, 0, 22, 0, 75, 0, 0, 6,
795 7, 8, 9, 11, 10, 12, 41, 62, 13, 14,
796 28, 21, 0, 36, 42, 45, 51, 54, 57, 48,
797 29, 26, 77, 23, 63, 64, 66, 67, 68, 65,
798 43, 46, 52, 55, 58, 49, 30, 15, 38, 0,
799 0, 0, 76, 59, 60, 40, 35, 0, 0, 24,
800 34, 39, 33, 79, 31, 37, 78, 80, 77, 0,
801 16, 0, 17, 79, 32, 77, 18, 19
804 /* YYDEFGOTO[NTERM-NUM]. */
805 static const yytype_int8 yydefgoto[] =
807 -1, 2, 3, 4, 29, 30, 31, 32, 33, 34,
808 35, 36, 37, 9, 10, 11, 38, 39, 79, 90
811 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
813 #define YYPACT_NINF -81
814 static const yytype_int8 yypact[] =
816 -10, 54, 70, -81, 25, -81, -81, -81, -81, -81,
817 -81, -81, -81, -81, -81, -81, -81, -81, -81, 55,
818 -81, 74, 50, 48, 10, 56, -5, 71, 72, -81,
819 -81, -81, -81, -81, -81, -81, 79, -81, -81, -81,
820 -81, -81, 65, 60, -81, -81, -81, -81, -81, -81,
821 -81, -81, 16, -81, -81, -81, -81, -81, -81, -81,
822 -81, -81, -81, -81, -81, -81, -81, -81, 58, 42,
823 66, 67, -81, -81, -81, -81, -81, 68, 69, -81,
824 -81, -81, -81, -7, 64, -81, -81, -81, 73, -2,
825 -81, 75, -81, 53, -81, 73, -81, -81
828 /* YYPGOTO[NTERM-NUM]. */
829 static const yytype_int8 yypgoto[] =
831 -81, -81, -81, -81, -81, -81, -81, -81, -81, -81,
832 -81, -81, 3, -81, -81, 1, -81, -81, -80, -1
835 /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
836 positive, shift that token. If negative, reduce the rule which
837 number is the opposite. If zero, do what YYDEFACT says.
838 If YYTABLE_NINF, syntax error. */
839 #define YYTABLE_NINF -1
840 static const yytype_uint8 yytable[] =
842 60, 61, 62, 63, 64, 65, 66, 87, 92, 67,
843 68, 88, 1, 69, 51, 97, 89, 6, 70, 8,
844 71, 54, 55, 56, 57, 58, 59, 53, 52, 72,
845 13, 14, 15, 16, 17, 18, 19, 20, 21, 78,
846 22, 23, 24, 25, 26, 27, 28, 54, 55, 56,
847 57, 58, 59, 44, 45, 46, 47, 48, 49, 50,
848 82, 54, 55, 56, 57, 58, 59, 87, 42, 43,
849 12, 95, 5, 6, 7, 8, 80, 81, 41, 40,
850 73, 74, 75, 76, 77, 83, 84, 85, 86, 91,
851 93, 0, 96, 0, 94, 0, 78
854 static const yytype_int8 yycheck[] =
856 5, 6, 7, 8, 9, 10, 11, 14, 88, 14,
857 15, 18, 22, 18, 4, 95, 23, 19, 23, 21,
858 25, 5, 6, 7, 8, 9, 10, 24, 18, 26,
859 5, 6, 7, 8, 9, 10, 11, 12, 13, 23,
860 15, 16, 17, 18, 19, 20, 21, 5, 6, 7,
861 8, 9, 10, 5, 6, 7, 8, 9, 10, 11,
862 18, 5, 6, 7, 8, 9, 10, 14, 18, 19,
863 0, 18, 18, 19, 20, 21, 18, 19, 4, 24,
864 9, 9, 3, 18, 24, 19, 19, 19, 19, 25,
865 89, -1, 93, -1, 19, -1, 23
868 /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
869 symbol of state STATE-NUM. */
870 static const yytype_uint8 yystos[] =
872 0, 22, 27, 28, 29, 18, 19, 20, 21, 39,
873 40, 41, 0, 5, 6, 7, 8, 9, 10, 11,
874 12, 13, 15, 16, 17, 18, 19, 20, 21, 30,
875 31, 32, 33, 34, 35, 36, 37, 38, 42, 43,
876 24, 4, 18, 19, 5, 6, 7, 8, 9, 10,
877 11, 4, 18, 38, 5, 6, 7, 8, 9, 10,
878 5, 6, 7, 8, 9, 10, 11, 14, 15, 18,
879 23, 25, 38, 9, 9, 3, 18, 24, 23, 44,
880 18, 19, 18, 19, 19, 19, 19, 14, 18, 23,
881 45, 25, 44, 41, 19, 18, 45, 44
884 #define yyerrok (yyerrstatus = 0)
885 #define yyclearin (yychar = YYEMPTY)
889 #define YYACCEPT goto yyacceptlab
890 #define YYABORT goto yyabortlab
891 #define YYERROR goto yyerrorlab
894 /* Like YYERROR except do call yyerror. This remains here temporarily
895 to ease the transition to the new meaning of YYERROR, for GCC.
896 Once GCC version 2 has supplanted version 1, this can go. */
898 #define YYFAIL goto yyerrlab
900 #define YYRECOVERING() (!!yyerrstatus)
902 #define YYBACKUP(Token, Value) \
904 if (yychar == YYEMPTY && yylen == 1) \
908 yytoken = YYTRANSLATE (yychar); \
914 yyerror (pc, YY_("syntax error: cannot back up")); \
921 #define YYERRCODE 256
924 /* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
925 If N is 0, then set CURRENT to the empty location which ends
926 the previous symbol: RHS[0] (always defined). */
928 #define YYRHSLOC(Rhs, K) ((Rhs)[K])
929 #ifndef YYLLOC_DEFAULT
930 # define YYLLOC_DEFAULT(Current, Rhs, N) \
934 (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \
935 (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \
936 (Current).last_line = YYRHSLOC (Rhs, N).last_line; \
937 (Current).last_column = YYRHSLOC (Rhs, N).last_column; \
941 (Current).first_line = (Current).last_line = \
942 YYRHSLOC (Rhs, 0).last_line; \
943 (Current).first_column = (Current).last_column = \
944 YYRHSLOC (Rhs, 0).last_column; \
950 /* YY_LOCATION_PRINT -- Print the location on the stream.
951 This macro was not mandated originally: define only if we know
952 we won't break user code: when these are the locations we know. */
954 #ifndef YY_LOCATION_PRINT
955 # if YYLTYPE_IS_TRIVIAL
956 # define YY_LOCATION_PRINT(File, Loc) \
957 fprintf (File, "%d.%d-%d.%d", \
958 (Loc).first_line, (Loc).first_column, \
959 (Loc).last_line, (Loc).last_column)
961 # define YY_LOCATION_PRINT(File, Loc) ((void) 0)
966 /* YYLEX -- calling `yylex' with the right arguments. */
969 # define YYLEX yylex (&yylval, YYLEX_PARAM)
971 # define YYLEX yylex (&yylval, pc)
974 /* Enable debugging if requested. */
978 # include <stdio.h> /* INFRINGES ON USER NAME SPACE */
979 # define YYFPRINTF fprintf
982 # define YYDPRINTF(Args) \
988 # define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
992 YYFPRINTF (stderr, "%s ", Title); \
993 yy_symbol_print (stderr, \
995 YYFPRINTF (stderr, "\n"); \
1000 /*--------------------------------.
1001 | Print this symbol on YYOUTPUT. |
1002 `--------------------------------*/
1005 #if (defined __STDC__ || defined __C99__FUNC__ \
1006 || defined __cplusplus || defined _MSC_VER)
1008 yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, parser_control *pc)
1011 yy_symbol_value_print (yyoutput, yytype, yyvaluep, pc)
1014 YYSTYPE const * const yyvaluep;
1022 if (yytype < YYNTOKENS)
1023 YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep);
1035 /*--------------------------------.
1036 | Print this symbol on YYOUTPUT. |
1037 `--------------------------------*/
1039 #if (defined __STDC__ || defined __C99__FUNC__ \
1040 || defined __cplusplus || defined _MSC_VER)
1042 yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, parser_control *pc)
1045 yy_symbol_print (yyoutput, yytype, yyvaluep, pc)
1048 YYSTYPE const * const yyvaluep;
1052 if (yytype < YYNTOKENS)
1053 YYFPRINTF (yyoutput, "token %s (", yytname[yytype]);
1055 YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]);
1057 yy_symbol_value_print (yyoutput, yytype, yyvaluep, pc);
1058 YYFPRINTF (yyoutput, ")");
1061 /*------------------------------------------------------------------.
1062 | yy_stack_print -- Print the state stack from its BOTTOM up to its |
1064 `------------------------------------------------------------------*/
1066 #if (defined __STDC__ || defined __C99__FUNC__ \
1067 || defined __cplusplus || defined _MSC_VER)
1069 yy_stack_print (yytype_int16 *bottom, yytype_int16 *top)
1072 yy_stack_print (bottom, top)
1073 yytype_int16 *bottom;
1077 YYFPRINTF (stderr, "Stack now");
1078 for (; bottom <= top; ++bottom)
1079 YYFPRINTF (stderr, " %d", *bottom);
1080 YYFPRINTF (stderr, "\n");
1083 # define YY_STACK_PRINT(Bottom, Top) \
1086 yy_stack_print ((Bottom), (Top)); \
1090 /*------------------------------------------------.
1091 | Report that the YYRULE is going to be reduced. |
1092 `------------------------------------------------*/
1094 #if (defined __STDC__ || defined __C99__FUNC__ \
1095 || defined __cplusplus || defined _MSC_VER)
1097 yy_reduce_print (YYSTYPE *yyvsp, int yyrule, parser_control *pc)
1100 yy_reduce_print (yyvsp, yyrule, pc)
1106 int yynrhs = yyr2[yyrule];
1108 unsigned long int yylno = yyrline[yyrule];
1109 YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n",
1111 /* The symbols being reduced. */
1112 for (yyi = 0; yyi < yynrhs; yyi++)
1114 fprintf (stderr, " $%d = ", yyi + 1);
1115 yy_symbol_print (stderr, yyrhs[yyprhs[yyrule] + yyi],
1116 &(yyvsp[(yyi + 1) - (yynrhs)])
1118 fprintf (stderr, "\n");
1122 # define YY_REDUCE_PRINT(Rule) \
1125 yy_reduce_print (yyvsp, Rule, pc); \
1128 /* Nonzero means print parse trace. It is left uninitialized so that
1129 multiple parsers can coexist. */
1131 #else /* !YYDEBUG */
1132 # define YYDPRINTF(Args)
1133 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
1134 # define YY_STACK_PRINT(Bottom, Top)
1135 # define YY_REDUCE_PRINT(Rule)
1136 #endif /* !YYDEBUG */
1139 /* YYINITDEPTH -- initial size of the parser's stacks. */
1141 # define YYINITDEPTH 200
1144 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
1145 if the built-in stack extension method is used).
1147 Do not make this value too large; the results are undefined if
1148 YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH)
1149 evaluated with infinite-precision integer arithmetic. */
1152 # define YYMAXDEPTH 10000
1160 # if defined __GLIBC__ && defined _STRING_H
1161 # define yystrlen strlen
1163 /* Return the length of YYSTR. */
1164 #if (defined __STDC__ || defined __C99__FUNC__ \
1165 || defined __cplusplus || defined _MSC_VER)
1167 yystrlen (const char *yystr)
1175 for (yylen = 0; yystr[yylen]; yylen++)
1183 # if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
1184 # define yystpcpy stpcpy
1186 /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
1188 #if (defined __STDC__ || defined __C99__FUNC__ \
1189 || defined __cplusplus || defined _MSC_VER)
1191 yystpcpy (char *yydest, const char *yysrc)
1194 yystpcpy (yydest, yysrc)
1200 const char *yys = yysrc;
1202 while ((*yyd++ = *yys++) != '\0')
1211 /* Copy to YYRES the contents of YYSTR after stripping away unnecessary
1212 quotes and backslashes, so that it's suitable for yyerror. The
1213 heuristic is that double-quoting is unnecessary unless the string
1214 contains an apostrophe, a comma, or backslash (other than
1215 backslash-backslash). YYSTR is taken from yytname. If YYRES is
1216 null, do not copy; instead, return the length of what the result
1219 yytnamerr (char *yyres, const char *yystr)
1224 char const *yyp = yystr;
1231 goto do_not_strip_quotes;
1235 goto do_not_strip_quotes;
1248 do_not_strip_quotes: ;
1252 return yystrlen (yystr);
1254 return yystpcpy (yyres, yystr) - yyres;
1258 /* Copy into YYRESULT an error message about the unexpected token
1259 YYCHAR while in state YYSTATE. Return the number of bytes copied,
1260 including the terminating null byte. If YYRESULT is null, do not
1261 copy anything; just return the number of bytes that would be
1262 copied. As a special case, return 0 if an ordinary "syntax error"
1263 message will do. Return YYSIZE_MAXIMUM if overflow occurs during
1264 size calculation. */
1266 yysyntax_error (char *yyresult, int yystate, int yychar)
1268 int yyn = yypact[yystate];
1270 if (! (YYPACT_NINF < yyn && yyn <= YYLAST))
1274 int yytype = YYTRANSLATE (yychar);
1275 YYSIZE_T yysize0 = yytnamerr (0, yytname[yytype]);
1276 YYSIZE_T yysize = yysize0;
1278 int yysize_overflow = 0;
1279 enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
1280 char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
1284 /* This is so xgettext sees the translatable formats that are
1285 constructed on the fly. */
1286 YY_("syntax error, unexpected %s");
1287 YY_("syntax error, unexpected %s, expecting %s");
1288 YY_("syntax error, unexpected %s, expecting %s or %s");
1289 YY_("syntax error, unexpected %s, expecting %s or %s or %s");
1290 YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s");
1294 static char const yyunexpected[] = "syntax error, unexpected %s";
1295 static char const yyexpecting[] = ", expecting %s";
1296 static char const yyor[] = " or %s";
1297 char yyformat[sizeof yyunexpected
1298 + sizeof yyexpecting - 1
1299 + ((YYERROR_VERBOSE_ARGS_MAXIMUM - 2)
1300 * (sizeof yyor - 1))];
1301 char const *yyprefix = yyexpecting;
1303 /* Start YYX at -YYN if negative to avoid negative indexes in
1305 int yyxbegin = yyn < 0 ? -yyn : 0;
1307 /* Stay within bounds of both yycheck and yytname. */
1308 int yychecklim = YYLAST - yyn + 1;
1309 int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
1312 yyarg[0] = yytname[yytype];
1313 yyfmt = yystpcpy (yyformat, yyunexpected);
1315 for (yyx = yyxbegin; yyx < yyxend; ++yyx)
1316 if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)
1318 if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
1322 yyformat[sizeof yyunexpected - 1] = '\0';
1325 yyarg[yycount++] = yytname[yyx];
1326 yysize1 = yysize + yytnamerr (0, yytname[yyx]);
1327 yysize_overflow |= (yysize1 < yysize);
1329 yyfmt = yystpcpy (yyfmt, yyprefix);
1333 yyf = YY_(yyformat);
1334 yysize1 = yysize + yystrlen (yyf);
1335 yysize_overflow |= (yysize1 < yysize);
1338 if (yysize_overflow)
1339 return YYSIZE_MAXIMUM;
1343 /* Avoid sprintf, as that infringes on the user's name space.
1344 Don't have undefined behavior even if the translation
1345 produced a string with the wrong number of "%s"s. */
1346 char *yyp = yyresult;
1348 while ((*yyp = *yyf) != '\0')
1350 if (*yyp == '%' && yyf[1] == 's' && yyi < yycount)
1352 yyp += yytnamerr (yyp, yyarg[yyi++]);
1365 #endif /* YYERROR_VERBOSE */
1368 /*-----------------------------------------------.
1369 | Release the memory associated to this symbol. |
1370 `-----------------------------------------------*/
1373 #if (defined __STDC__ || defined __C99__FUNC__ \
1374 || defined __cplusplus || defined _MSC_VER)
1376 yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep, parser_control *pc)
1379 yydestruct (yymsg, yytype, yyvaluep, pc)
1391 YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
1402 /* Prevent warnings from -Wmissing-prototypes. */
1404 #ifdef YYPARSE_PARAM
1405 #if defined __STDC__ || defined __cplusplus
1406 int yyparse (void *YYPARSE_PARAM);
1410 #else /* ! YYPARSE_PARAM */
1411 #if defined __STDC__ || defined __cplusplus
1412 int yyparse (parser_control *pc);
1416 #endif /* ! YYPARSE_PARAM */
1427 #ifdef YYPARSE_PARAM
1428 #if (defined __STDC__ || defined __C99__FUNC__ \
1429 || defined __cplusplus || defined _MSC_VER)
1431 yyparse (void *YYPARSE_PARAM)
1434 yyparse (YYPARSE_PARAM)
1435 void *YYPARSE_PARAM;
1437 #else /* ! YYPARSE_PARAM */
1438 #if (defined __STDC__ || defined __C99__FUNC__ \
1439 || defined __cplusplus || defined _MSC_VER)
1441 yyparse (parser_control *pc)
1449 /* The look-ahead symbol. */
1452 /* The semantic value of the look-ahead symbol. */
1455 /* Number of syntax errors so far. */
1461 /* Number of tokens to shift before error messages enabled. */
1463 /* Look-ahead token as an internal (translated) token number. */
1466 /* Buffer for error messages, and its allocated size. */
1468 char *yymsg = yymsgbuf;
1469 YYSIZE_T yymsg_alloc = sizeof yymsgbuf;
1472 /* Three stacks and their tools:
1473 `yyss': related to states,
1474 `yyvs': related to semantic values,
1475 `yyls': related to locations.
1477 Refer to the stacks thru separate pointers, to allow yyoverflow
1478 to reallocate them elsewhere. */
1480 /* The state stack. */
1481 yytype_int16 yyssa[YYINITDEPTH];
1482 yytype_int16 *yyss = yyssa;
1483 yytype_int16 *yyssp;
1485 /* The semantic value stack. */
1486 YYSTYPE yyvsa[YYINITDEPTH];
1487 YYSTYPE *yyvs = yyvsa;
1492 #define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N))
1494 YYSIZE_T yystacksize = YYINITDEPTH;
1496 /* The variables used to return semantic value and location from the
1501 /* The number of symbols on the RHS of the reduced rule.
1502 Keep to zero when no symbol should be popped. */
1505 YYDPRINTF ((stderr, "Starting parse\n"));
1510 yychar = YYEMPTY; /* Cause a token to be read. */
1512 /* Initialize stack pointers.
1513 Waste one element of value and location stack
1514 so that they stay on the same level as the state stack.
1515 The wasted elements are never initialized. */
1522 /*------------------------------------------------------------.
1523 | yynewstate -- Push a new state, which is found in yystate. |
1524 `------------------------------------------------------------*/
1526 /* In all cases, when you get here, the value and location stacks
1527 have just been pushed. So pushing a state here evens the stacks. */
1533 if (yyss + yystacksize - 1 <= yyssp)
1535 /* Get the current used size of the three stacks, in elements. */
1536 YYSIZE_T yysize = yyssp - yyss + 1;
1540 /* Give user a chance to reallocate the stack. Use copies of
1541 these so that the &'s don't force the real ones into
1543 YYSTYPE *yyvs1 = yyvs;
1544 yytype_int16 *yyss1 = yyss;
1547 /* Each stack pointer address is followed by the size of the
1548 data in use in that stack, in bytes. This used to be a
1549 conditional around just the two extra args, but that might
1550 be undefined if yyoverflow is a macro. */
1551 yyoverflow (YY_("memory exhausted"),
1552 &yyss1, yysize * sizeof (*yyssp),
1553 &yyvs1, yysize * sizeof (*yyvsp),
1560 #else /* no yyoverflow */
1561 # ifndef YYSTACK_RELOCATE
1562 goto yyexhaustedlab;
1564 /* Extend the stack our own way. */
1565 if (YYMAXDEPTH <= yystacksize)
1566 goto yyexhaustedlab;
1568 if (YYMAXDEPTH < yystacksize)
1569 yystacksize = YYMAXDEPTH;
1572 yytype_int16 *yyss1 = yyss;
1573 union yyalloc *yyptr =
1574 (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
1576 goto yyexhaustedlab;
1577 YYSTACK_RELOCATE (yyss);
1578 YYSTACK_RELOCATE (yyvs);
1580 # undef YYSTACK_RELOCATE
1582 YYSTACK_FREE (yyss1);
1585 #endif /* no yyoverflow */
1587 yyssp = yyss + yysize - 1;
1588 yyvsp = yyvs + yysize - 1;
1591 YYDPRINTF ((stderr, "Stack size increased to %lu\n",
1592 (unsigned long int) yystacksize));
1594 if (yyss + yystacksize - 1 <= yyssp)
1598 YYDPRINTF ((stderr, "Entering state %d\n", yystate));
1607 /* Do appropriate processing given the current state. Read a
1608 look-ahead token if we need one and don't already have one. */
1610 /* First try to decide what to do without reference to look-ahead token. */
1611 yyn = yypact[yystate];
1612 if (yyn == YYPACT_NINF)
1615 /* Not known => get a look-ahead token if don't already have one. */
1617 /* YYCHAR is either YYEMPTY or YYEOF or a valid look-ahead symbol. */
1618 if (yychar == YYEMPTY)
1620 YYDPRINTF ((stderr, "Reading a token: "));
1624 if (yychar <= YYEOF)
1626 yychar = yytoken = YYEOF;
1627 YYDPRINTF ((stderr, "Now at end of input.\n"));
1631 yytoken = YYTRANSLATE (yychar);
1632 YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
1635 /* If the proper action on seeing token YYTOKEN is to reduce or to
1636 detect an error, take that action. */
1638 if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
1643 if (yyn == 0 || yyn == YYTABLE_NINF)
1652 /* Count tokens shifted since error; after three, turn off error
1657 /* Shift the look-ahead token. */
1658 YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
1660 /* Discard the shifted token unless it is eof. */
1661 if (yychar != YYEOF)
1670 /*-----------------------------------------------------------.
1671 | yydefault -- do the default action for the current state. |
1672 `-----------------------------------------------------------*/
1674 yyn = yydefact[yystate];
1680 /*-----------------------------.
1681 | yyreduce -- Do a reduction. |
1682 `-----------------------------*/
1684 /* yyn is the number of a rule to reduce with. */
1687 /* If YYLEN is nonzero, implement the default value of the action:
1690 Otherwise, the following line sets YYVAL to garbage.
1691 This behavior is undocumented and Bison
1692 users should not rely upon it. Assigning to YYVAL
1693 unconditionally makes the parser a bit smaller, and it avoids a
1694 GCC warning that YYVAL may be used uninitialized. */
1695 yyval = yyvsp[1-yylen];
1698 YY_REDUCE_PRINT (yyn);
1702 #line 293 "getdate.y"
1704 pc->seconds = (yyvsp[(2) - (2)].timespec);
1705 pc->timespec_seen = true;
1710 #line 306 "getdate.y"
1711 { pc->times_seen++; }
1715 #line 308 "getdate.y"
1716 { pc->local_zones_seen++; }
1720 #line 310 "getdate.y"
1721 { pc->zones_seen++; }
1725 #line 312 "getdate.y"
1726 { pc->dates_seen++; }
1730 #line 314 "getdate.y"
1731 { pc->days_seen++; }
1735 #line 316 "getdate.y"
1736 { pc->rels_seen = true; }
1740 #line 323 "getdate.y"
1742 pc->hour = (yyvsp[(1) - (2)].textintval).value;
1744 pc->seconds.tv_sec = 0;
1745 pc->seconds.tv_nsec = 0;
1746 pc->meridian = (yyvsp[(2) - (2)].intval);
1751 #line 331 "getdate.y"
1753 pc->hour = (yyvsp[(1) - (4)].textintval).value;
1754 pc->minutes = (yyvsp[(3) - (4)].textintval).value;
1755 pc->seconds.tv_sec = 0;
1756 pc->seconds.tv_nsec = 0;
1757 pc->meridian = (yyvsp[(4) - (4)].intval);
1762 #line 339 "getdate.y"
1764 pc->hour = (yyvsp[(1) - (5)].textintval).value;
1765 pc->minutes = (yyvsp[(3) - (5)].textintval).value;
1766 pc->seconds.tv_sec = 0;
1767 pc->seconds.tv_nsec = 0;
1768 pc->meridian = MER24;
1770 pc->time_zone = time_zone_hhmm ((yyvsp[(4) - (5)].textintval), (yyvsp[(5) - (5)].intval));
1775 #line 349 "getdate.y"
1777 pc->hour = (yyvsp[(1) - (6)].textintval).value;
1778 pc->minutes = (yyvsp[(3) - (6)].textintval).value;
1779 pc->seconds = (yyvsp[(5) - (6)].timespec);
1780 pc->meridian = (yyvsp[(6) - (6)].intval);
1785 #line 356 "getdate.y"
1787 pc->hour = (yyvsp[(1) - (7)].textintval).value;
1788 pc->minutes = (yyvsp[(3) - (7)].textintval).value;
1789 pc->seconds = (yyvsp[(5) - (7)].timespec);
1790 pc->meridian = MER24;
1792 pc->time_zone = time_zone_hhmm ((yyvsp[(6) - (7)].textintval), (yyvsp[(7) - (7)].intval));
1797 #line 368 "getdate.y"
1799 pc->local_isdst = (yyvsp[(1) - (1)].intval);
1800 pc->dsts_seen += (0 < (yyvsp[(1) - (1)].intval));
1805 #line 373 "getdate.y"
1807 pc->local_isdst = 1;
1808 pc->dsts_seen += (0 < (yyvsp[(1) - (2)].intval)) + 1;
1813 #line 381 "getdate.y"
1814 { pc->time_zone = (yyvsp[(1) - (1)].intval); }
1818 #line 383 "getdate.y"
1819 { pc->time_zone = (yyvsp[(1) - (2)].intval);
1820 pc->rel.ns += (yyvsp[(2) - (2)].rel).ns;
1821 pc->rel.seconds += (yyvsp[(2) - (2)].rel).seconds;
1822 pc->rel.minutes += (yyvsp[(2) - (2)].rel).minutes;
1823 pc->rel.hour += (yyvsp[(2) - (2)].rel).hour;
1824 pc->rel.day += (yyvsp[(2) - (2)].rel).day;
1825 pc->rel.month += (yyvsp[(2) - (2)].rel).month;
1826 pc->rel.year += (yyvsp[(2) - (2)].rel).year;
1827 pc->rels_seen = true; }
1831 #line 393 "getdate.y"
1832 { pc->time_zone = (yyvsp[(1) - (3)].intval) + time_zone_hhmm ((yyvsp[(2) - (3)].textintval), (yyvsp[(3) - (3)].intval)); }
1836 #line 395 "getdate.y"
1837 { pc->time_zone = (yyvsp[(1) - (1)].intval) + 60; }
1841 #line 397 "getdate.y"
1842 { pc->time_zone = (yyvsp[(1) - (2)].intval) + 60; }
1846 #line 402 "getdate.y"
1848 pc->day_ordinal = 1;
1849 pc->day_number = (yyvsp[(1) - (1)].intval);
1854 #line 407 "getdate.y"
1856 pc->day_ordinal = 1;
1857 pc->day_number = (yyvsp[(1) - (2)].intval);
1862 #line 412 "getdate.y"
1864 pc->day_ordinal = (yyvsp[(1) - (2)].intval);
1865 pc->day_number = (yyvsp[(2) - (2)].intval);
1870 #line 417 "getdate.y"
1872 pc->day_ordinal = (yyvsp[(1) - (2)].textintval).value;
1873 pc->day_number = (yyvsp[(2) - (2)].intval);
1878 #line 425 "getdate.y"
1880 pc->month = (yyvsp[(1) - (3)].textintval).value;
1881 pc->day = (yyvsp[(3) - (3)].textintval).value;
1886 #line 430 "getdate.y"
1888 /* Interpret as YYYY/MM/DD if the first value has 4 or more digits,
1889 otherwise as MM/DD/YY.
1890 The goal in recognizing YYYY/MM/DD is solely to support legacy
1891 machine-generated dates like those in an RCS log listing. If
1892 you want portability, use the ISO 8601 format. */
1893 if (4 <= (yyvsp[(1) - (5)].textintval).digits)
1895 pc->year = (yyvsp[(1) - (5)].textintval);
1896 pc->month = (yyvsp[(3) - (5)].textintval).value;
1897 pc->day = (yyvsp[(5) - (5)].textintval).value;
1901 pc->month = (yyvsp[(1) - (5)].textintval).value;
1902 pc->day = (yyvsp[(3) - (5)].textintval).value;
1903 pc->year = (yyvsp[(5) - (5)].textintval);
1909 #line 450 "getdate.y"
1911 /* ISO 8601 format. YYYY-MM-DD. */
1912 pc->year = (yyvsp[(1) - (3)].textintval);
1913 pc->month = -(yyvsp[(2) - (3)].textintval).value;
1914 pc->day = -(yyvsp[(3) - (3)].textintval).value;
1919 #line 457 "getdate.y"
1921 /* e.g. 17-JUN-1992. */
1922 pc->day = (yyvsp[(1) - (3)].textintval).value;
1923 pc->month = (yyvsp[(2) - (3)].intval);
1924 pc->year.value = -(yyvsp[(3) - (3)].textintval).value;
1925 pc->year.digits = (yyvsp[(3) - (3)].textintval).digits;
1930 #line 465 "getdate.y"
1932 /* e.g. JUN-17-1992. */
1933 pc->month = (yyvsp[(1) - (3)].intval);
1934 pc->day = -(yyvsp[(2) - (3)].textintval).value;
1935 pc->year.value = -(yyvsp[(3) - (3)].textintval).value;
1936 pc->year.digits = (yyvsp[(3) - (3)].textintval).digits;
1941 #line 473 "getdate.y"
1943 pc->month = (yyvsp[(1) - (2)].intval);
1944 pc->day = (yyvsp[(2) - (2)].textintval).value;
1949 #line 478 "getdate.y"
1951 pc->month = (yyvsp[(1) - (4)].intval);
1952 pc->day = (yyvsp[(2) - (4)].textintval).value;
1953 pc->year = (yyvsp[(4) - (4)].textintval);
1958 #line 484 "getdate.y"
1960 pc->day = (yyvsp[(1) - (2)].textintval).value;
1961 pc->month = (yyvsp[(2) - (2)].intval);
1966 #line 489 "getdate.y"
1968 pc->day = (yyvsp[(1) - (3)].textintval).value;
1969 pc->month = (yyvsp[(2) - (3)].intval);
1970 pc->year = (yyvsp[(3) - (3)].textintval);
1975 #line 498 "getdate.y"
1977 pc->rel.ns -= (yyvsp[(1) - (2)].rel).ns;
1978 pc->rel.seconds -= (yyvsp[(1) - (2)].rel).seconds;
1979 pc->rel.minutes -= (yyvsp[(1) - (2)].rel).minutes;
1980 pc->rel.hour -= (yyvsp[(1) - (2)].rel).hour;
1981 pc->rel.day -= (yyvsp[(1) - (2)].rel).day;
1982 pc->rel.month -= (yyvsp[(1) - (2)].rel).month;
1983 pc->rel.year -= (yyvsp[(1) - (2)].rel).year;
1988 #line 508 "getdate.y"
1990 pc->rel.ns += (yyvsp[(1) - (1)].rel).ns;
1991 pc->rel.seconds += (yyvsp[(1) - (1)].rel).seconds;
1992 pc->rel.minutes += (yyvsp[(1) - (1)].rel).minutes;
1993 pc->rel.hour += (yyvsp[(1) - (1)].rel).hour;
1994 pc->rel.day += (yyvsp[(1) - (1)].rel).day;
1995 pc->rel.month += (yyvsp[(1) - (1)].rel).month;
1996 pc->rel.year += (yyvsp[(1) - (1)].rel).year;
2001 #line 521 "getdate.y"
2002 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).year = (yyvsp[(1) - (2)].intval); }
2006 #line 523 "getdate.y"
2007 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).year = (yyvsp[(1) - (2)].textintval).value; }
2011 #line 525 "getdate.y"
2012 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).year = 1; }
2016 #line 527 "getdate.y"
2017 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).month = (yyvsp[(1) - (2)].intval); }
2021 #line 529 "getdate.y"
2022 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).month = (yyvsp[(1) - (2)].textintval).value; }
2026 #line 531 "getdate.y"
2027 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).month = 1; }
2031 #line 533 "getdate.y"
2032 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).day = (yyvsp[(1) - (2)].intval) * (yyvsp[(2) - (2)].intval); }
2036 #line 535 "getdate.y"
2037 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).day = (yyvsp[(1) - (2)].textintval).value * (yyvsp[(2) - (2)].intval); }
2041 #line 537 "getdate.y"
2042 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).day = (yyvsp[(1) - (1)].intval); }
2046 #line 539 "getdate.y"
2047 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).hour = (yyvsp[(1) - (2)].intval); }
2051 #line 541 "getdate.y"
2052 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).hour = (yyvsp[(1) - (2)].textintval).value; }
2056 #line 543 "getdate.y"
2057 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).hour = 1; }
2061 #line 545 "getdate.y"
2062 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).minutes = (yyvsp[(1) - (2)].intval); }
2066 #line 547 "getdate.y"
2067 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).minutes = (yyvsp[(1) - (2)].textintval).value; }
2071 #line 549 "getdate.y"
2072 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).minutes = 1; }
2076 #line 551 "getdate.y"
2077 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).seconds = (yyvsp[(1) - (2)].intval); }
2081 #line 553 "getdate.y"
2082 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).seconds = (yyvsp[(1) - (2)].textintval).value; }
2086 #line 555 "getdate.y"
2087 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).seconds = (yyvsp[(1) - (2)].timespec).tv_sec; (yyval.rel).ns = (yyvsp[(1) - (2)].timespec).tv_nsec; }
2091 #line 557 "getdate.y"
2092 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).seconds = (yyvsp[(1) - (2)].timespec).tv_sec; (yyval.rel).ns = (yyvsp[(1) - (2)].timespec).tv_nsec; }
2096 #line 559 "getdate.y"
2097 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).seconds = 1; }
2101 #line 565 "getdate.y"
2102 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).year = (yyvsp[(1) - (2)].textintval).value; }
2106 #line 567 "getdate.y"
2107 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).month = (yyvsp[(1) - (2)].textintval).value; }
2111 #line 569 "getdate.y"
2112 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).day = (yyvsp[(1) - (2)].textintval).value * (yyvsp[(2) - (2)].intval); }
2116 #line 571 "getdate.y"
2117 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).hour = (yyvsp[(1) - (2)].textintval).value; }
2121 #line 573 "getdate.y"
2122 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).minutes = (yyvsp[(1) - (2)].textintval).value; }
2126 #line 575 "getdate.y"
2127 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).seconds = (yyvsp[(1) - (2)].textintval).value; }
2131 #line 583 "getdate.y"
2132 { (yyval.timespec).tv_sec = (yyvsp[(1) - (1)].textintval).value; (yyval.timespec).tv_nsec = 0; }
2136 #line 589 "getdate.y"
2137 { (yyval.timespec).tv_sec = (yyvsp[(1) - (1)].textintval).value; (yyval.timespec).tv_nsec = 0; }
2141 #line 594 "getdate.y"
2142 { digits_to_date_time (pc, (yyvsp[(1) - (1)].textintval)); }
2146 #line 599 "getdate.y"
2148 /* Hybrid all-digit and relative offset, so that we accept e.g.,
2149 "YYYYMMDD +N days" as well as "YYYYMMDD N days". */
2150 digits_to_date_time (pc, (yyvsp[(1) - (2)].textintval));
2151 pc->rel.ns += (yyvsp[(2) - (2)].rel).ns;
2152 pc->rel.seconds += (yyvsp[(2) - (2)].rel).seconds;
2153 pc->rel.minutes += (yyvsp[(2) - (2)].rel).minutes;
2154 pc->rel.hour += (yyvsp[(2) - (2)].rel).hour;
2155 pc->rel.day += (yyvsp[(2) - (2)].rel).day;
2156 pc->rel.month += (yyvsp[(2) - (2)].rel).month;
2157 pc->rel.year += (yyvsp[(2) - (2)].rel).year;
2158 pc->rels_seen = true;
2163 #line 616 "getdate.y"
2164 { (yyval.intval) = -1; }
2168 #line 618 "getdate.y"
2169 { (yyval.intval) = (yyvsp[(2) - (2)].textintval).value; }
2173 #line 623 "getdate.y"
2174 { (yyval.intval) = MER24; }
2178 #line 625 "getdate.y"
2179 { (yyval.intval) = (yyvsp[(1) - (1)].intval); }
2183 /* Line 1267 of yacc.c. */
2184 #line 2185 "getdate.c"
2187 YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc);
2191 YY_STACK_PRINT (yyss, yyssp);
2196 /* Now `shift' the result of the reduction. Determine what state
2197 that goes to, based on the state we popped back to and the rule
2198 number reduced by. */
2202 yystate = yypgoto[yyn - YYNTOKENS] + *yyssp;
2203 if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp)
2204 yystate = yytable[yystate];
2206 yystate = yydefgoto[yyn - YYNTOKENS];
2211 /*------------------------------------.
2212 | yyerrlab -- here on detecting error |
2213 `------------------------------------*/
2215 /* If not already recovering from an error, report this error. */
2219 #if ! YYERROR_VERBOSE
2220 yyerror (pc, YY_("syntax error"));
2223 YYSIZE_T yysize = yysyntax_error (0, yystate, yychar);
2224 if (yymsg_alloc < yysize && yymsg_alloc < YYSTACK_ALLOC_MAXIMUM)
2226 YYSIZE_T yyalloc = 2 * yysize;
2227 if (! (yysize <= yyalloc && yyalloc <= YYSTACK_ALLOC_MAXIMUM))
2228 yyalloc = YYSTACK_ALLOC_MAXIMUM;
2229 if (yymsg != yymsgbuf)
2230 YYSTACK_FREE (yymsg);
2231 yymsg = (char *) YYSTACK_ALLOC (yyalloc);
2233 yymsg_alloc = yyalloc;
2237 yymsg_alloc = sizeof yymsgbuf;
2241 if (0 < yysize && yysize <= yymsg_alloc)
2243 (void) yysyntax_error (yymsg, yystate, yychar);
2244 yyerror (pc, yymsg);
2248 yyerror (pc, YY_("syntax error"));
2250 goto yyexhaustedlab;
2258 if (yyerrstatus == 3)
2260 /* If just tried and failed to reuse look-ahead token after an
2261 error, discard it. */
2263 if (yychar <= YYEOF)
2265 /* Return failure if at end of input. */
2266 if (yychar == YYEOF)
2271 yydestruct ("Error: discarding",
2272 yytoken, &yylval, pc);
2277 /* Else will try to reuse look-ahead token after shifting the error
2282 /*---------------------------------------------------.
2283 | yyerrorlab -- error raised explicitly by YYERROR. |
2284 `---------------------------------------------------*/
2287 /* Pacify compilers like GCC when the user code never invokes
2288 YYERROR and the label yyerrorlab therefore never appears in user
2290 if (/*CONSTCOND*/ 0)
2293 /* Do not reclaim the symbols of the rule which action triggered
2297 YY_STACK_PRINT (yyss, yyssp);
2302 /*-------------------------------------------------------------.
2303 | yyerrlab1 -- common code for both syntax error and YYERROR. |
2304 `-------------------------------------------------------------*/
2306 yyerrstatus = 3; /* Each real token shifted decrements this. */
2310 yyn = yypact[yystate];
2311 if (yyn != YYPACT_NINF)
2314 if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
2322 /* Pop the current state because it cannot handle the error token. */
2327 yydestruct ("Error: popping",
2328 yystos[yystate], yyvsp, pc);
2331 YY_STACK_PRINT (yyss, yyssp);
2340 /* Shift the error token. */
2341 YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp);
2347 /*-------------------------------------.
2348 | yyacceptlab -- YYACCEPT comes here. |
2349 `-------------------------------------*/
2354 /*-----------------------------------.
2355 | yyabortlab -- YYABORT comes here. |
2356 `-----------------------------------*/
2362 /*-------------------------------------------------.
2363 | yyexhaustedlab -- memory exhaustion comes here. |
2364 `-------------------------------------------------*/
2366 yyerror (pc, YY_("memory exhausted"));
2372 if (yychar != YYEOF && yychar != YYEMPTY)
2373 yydestruct ("Cleanup: discarding lookahead",
2374 yytoken, &yylval, pc);
2375 /* Do not reclaim the symbols of the rule which action triggered
2376 this YYABORT or YYACCEPT. */
2378 YY_STACK_PRINT (yyss, yyssp);
2379 while (yyssp != yyss)
2381 yydestruct ("Cleanup: popping",
2382 yystos[*yyssp], yyvsp, pc);
2387 YYSTACK_FREE (yyss);
2390 if (yymsg != yymsgbuf)
2391 YYSTACK_FREE (yymsg);
2393 /* Make sure YYID is used. */
2394 return YYID (yyresult);
2398 #line 628 "getdate.y"
2401 static table const meridian_table[] =
2403 { "AM", tMERIDIAN, MERam },
2404 { "A.M.", tMERIDIAN, MERam },
2405 { "PM", tMERIDIAN, MERpm },
2406 { "P.M.", tMERIDIAN, MERpm },
2410 static table const dst_table[] =
2415 static table const month_and_day_table[] =
2417 { "JANUARY", tMONTH, 1 },
2418 { "FEBRUARY", tMONTH, 2 },
2419 { "MARCH", tMONTH, 3 },
2420 { "APRIL", tMONTH, 4 },
2421 { "MAY", tMONTH, 5 },
2422 { "JUNE", tMONTH, 6 },
2423 { "JULY", tMONTH, 7 },
2424 { "AUGUST", tMONTH, 8 },
2425 { "SEPTEMBER",tMONTH, 9 },
2426 { "SEPT", tMONTH, 9 },
2427 { "OCTOBER", tMONTH, 10 },
2428 { "NOVEMBER", tMONTH, 11 },
2429 { "DECEMBER", tMONTH, 12 },
2430 { "SUNDAY", tDAY, 0 },
2431 { "MONDAY", tDAY, 1 },
2432 { "TUESDAY", tDAY, 2 },
2433 { "TUES", tDAY, 2 },
2434 { "WEDNESDAY",tDAY, 3 },
2435 { "WEDNES", tDAY, 3 },
2436 { "THURSDAY", tDAY, 4 },
2437 { "THUR", tDAY, 4 },
2438 { "THURS", tDAY, 4 },
2439 { "FRIDAY", tDAY, 5 },
2440 { "SATURDAY", tDAY, 6 },
2444 static table const time_units_table[] =
2446 { "YEAR", tYEAR_UNIT, 1 },
2447 { "MONTH", tMONTH_UNIT, 1 },
2448 { "FORTNIGHT",tDAY_UNIT, 14 },
2449 { "WEEK", tDAY_UNIT, 7 },
2450 { "DAY", tDAY_UNIT, 1 },
2451 { "HOUR", tHOUR_UNIT, 1 },
2452 { "MINUTE", tMINUTE_UNIT, 1 },
2453 { "MIN", tMINUTE_UNIT, 1 },
2454 { "SECOND", tSEC_UNIT, 1 },
2455 { "SEC", tSEC_UNIT, 1 },
2459 /* Assorted relative-time words. */
2460 static table const relative_time_table[] =
2462 { "TOMORROW", tDAY_UNIT, 1 },
2463 { "YESTERDAY",tDAY_UNIT, -1 },
2464 { "TODAY", tDAY_UNIT, 0 },
2465 { "NOW", tDAY_UNIT, 0 },
2466 { "LAST", tORDINAL, -1 },
2467 { "THIS", tORDINAL, 0 },
2468 { "NEXT", tORDINAL, 1 },
2469 { "FIRST", tORDINAL, 1 },
2470 /*{ "SECOND", tORDINAL, 2 }, */
2471 { "THIRD", tORDINAL, 3 },
2472 { "FOURTH", tORDINAL, 4 },
2473 { "FIFTH", tORDINAL, 5 },
2474 { "SIXTH", tORDINAL, 6 },
2475 { "SEVENTH", tORDINAL, 7 },
2476 { "EIGHTH", tORDINAL, 8 },
2477 { "NINTH", tORDINAL, 9 },
2478 { "TENTH", tORDINAL, 10 },
2479 { "ELEVENTH", tORDINAL, 11 },
2480 { "TWELFTH", tORDINAL, 12 },
2485 /* The universal time zone table. These labels can be used even for
2486 time stamps that would not otherwise be valid, e.g., GMT time
2487 stamps in London during summer. */
2488 static table const universal_time_zone_table[] =
2490 { "GMT", tZONE, HOUR ( 0) }, /* Greenwich Mean */
2491 { "UT", tZONE, HOUR ( 0) }, /* Universal (Coordinated) */
2492 { "UTC", tZONE, HOUR ( 0) },
2496 /* The time zone table. This table is necessarily incomplete, as time
2497 zone abbreviations are ambiguous; e.g. Australians interpret "EST"
2498 as Eastern time in Australia, not as US Eastern Standard Time.
2499 You cannot rely on getdate to handle arbitrary time zone
2500 abbreviations; use numeric abbreviations like `-0500' instead. */
2501 static table const time_zone_table[] =
2503 { "WET", tZONE, HOUR ( 0) }, /* Western European */
2504 { "WEST", tDAYZONE, HOUR ( 0) }, /* Western European Summer */
2505 { "BST", tDAYZONE, HOUR ( 0) }, /* British Summer */
2506 { "ART", tZONE, -HOUR ( 3) }, /* Argentina */
2507 { "BRT", tZONE, -HOUR ( 3) }, /* Brazil */
2508 { "BRST", tDAYZONE, -HOUR ( 3) }, /* Brazil Summer */
2509 { "NST", tZONE, -(HOUR ( 3) + 30) }, /* Newfoundland Standard */
2510 { "NDT", tDAYZONE,-(HOUR ( 3) + 30) }, /* Newfoundland Daylight */
2511 { "AST", tZONE, -HOUR ( 4) }, /* Atlantic Standard */
2512 { "ADT", tDAYZONE, -HOUR ( 4) }, /* Atlantic Daylight */
2513 { "CLT", tZONE, -HOUR ( 4) }, /* Chile */
2514 { "CLST", tDAYZONE, -HOUR ( 4) }, /* Chile Summer */
2515 { "EST", tZONE, -HOUR ( 5) }, /* Eastern Standard */
2516 { "EDT", tDAYZONE, -HOUR ( 5) }, /* Eastern Daylight */
2517 { "CST", tZONE, -HOUR ( 6) }, /* Central Standard */
2518 { "CDT", tDAYZONE, -HOUR ( 6) }, /* Central Daylight */
2519 { "MST", tZONE, -HOUR ( 7) }, /* Mountain Standard */
2520 { "MDT", tDAYZONE, -HOUR ( 7) }, /* Mountain Daylight */
2521 { "PST", tZONE, -HOUR ( 8) }, /* Pacific Standard */
2522 { "PDT", tDAYZONE, -HOUR ( 8) }, /* Pacific Daylight */
2523 { "AKST", tZONE, -HOUR ( 9) }, /* Alaska Standard */
2524 { "AKDT", tDAYZONE, -HOUR ( 9) }, /* Alaska Daylight */
2525 { "HST", tZONE, -HOUR (10) }, /* Hawaii Standard */
2526 { "HAST", tZONE, -HOUR (10) }, /* Hawaii-Aleutian Standard */
2527 { "HADT", tDAYZONE, -HOUR (10) }, /* Hawaii-Aleutian Daylight */
2528 { "SST", tZONE, -HOUR (12) }, /* Samoa Standard */
2529 { "WAT", tZONE, HOUR ( 1) }, /* West Africa */
2530 { "CET", tZONE, HOUR ( 1) }, /* Central European */
2531 { "CEST", tDAYZONE, HOUR ( 1) }, /* Central European Summer */
2532 { "MET", tZONE, HOUR ( 1) }, /* Middle European */
2533 { "MEZ", tZONE, HOUR ( 1) }, /* Middle European */
2534 { "MEST", tDAYZONE, HOUR ( 1) }, /* Middle European Summer */
2535 { "MESZ", tDAYZONE, HOUR ( 1) }, /* Middle European Summer */
2536 { "EET", tZONE, HOUR ( 2) }, /* Eastern European */
2537 { "EEST", tDAYZONE, HOUR ( 2) }, /* Eastern European Summer */
2538 { "CAT", tZONE, HOUR ( 2) }, /* Central Africa */
2539 { "SAST", tZONE, HOUR ( 2) }, /* South Africa Standard */
2540 { "EAT", tZONE, HOUR ( 3) }, /* East Africa */
2541 { "MSK", tZONE, HOUR ( 3) }, /* Moscow */
2542 { "MSD", tDAYZONE, HOUR ( 3) }, /* Moscow Daylight */
2543 { "IST", tZONE, (HOUR ( 5) + 30) }, /* India Standard */
2544 { "SGT", tZONE, HOUR ( 8) }, /* Singapore */
2545 { "KST", tZONE, HOUR ( 9) }, /* Korea Standard */
2546 { "JST", tZONE, HOUR ( 9) }, /* Japan Standard */
2547 { "GST", tZONE, HOUR (10) }, /* Guam Standard */
2548 { "NZST", tZONE, HOUR (12) }, /* New Zealand Standard */
2549 { "NZDT", tDAYZONE, HOUR (12) }, /* New Zealand Daylight */
2553 /* Military time zone table. */
2554 static table const military_table[] =
2556 { "A", tZONE, -HOUR ( 1) },
2557 { "B", tZONE, -HOUR ( 2) },
2558 { "C", tZONE, -HOUR ( 3) },
2559 { "D", tZONE, -HOUR ( 4) },
2560 { "E", tZONE, -HOUR ( 5) },
2561 { "F", tZONE, -HOUR ( 6) },
2562 { "G", tZONE, -HOUR ( 7) },
2563 { "H", tZONE, -HOUR ( 8) },
2564 { "I", tZONE, -HOUR ( 9) },
2565 { "K", tZONE, -HOUR (10) },
2566 { "L", tZONE, -HOUR (11) },
2567 { "M", tZONE, -HOUR (12) },
2568 { "N", tZONE, HOUR ( 1) },
2569 { "O", tZONE, HOUR ( 2) },
2570 { "P", tZONE, HOUR ( 3) },
2571 { "Q", tZONE, HOUR ( 4) },
2572 { "R", tZONE, HOUR ( 5) },
2573 { "S", tZONE, HOUR ( 6) },
2574 { "T", tZONE, HOUR ( 7) },
2575 { "U", tZONE, HOUR ( 8) },
2576 { "V", tZONE, HOUR ( 9) },
2577 { "W", tZONE, HOUR (10) },
2578 { "X", tZONE, HOUR (11) },
2579 { "Y", tZONE, HOUR (12) },
2580 { "Z", tZONE, HOUR ( 0) },
2586 /* Convert a time zone expressed as HH:MM into an integer count of
2587 minutes. If MM is negative, then S is of the form HHMM and needs
2588 to be picked apart; otherwise, S is of the form HH. */
2591 time_zone_hhmm (textint s, long int mm)
2594 return (s.value / 100) * 60 + s.value % 100;
2596 return s.value * 60 + (s.negative ? -mm : mm);
2600 to_hour (long int hours, int meridian)
2604 default: /* Pacify GCC. */
2606 return 0 <= hours && hours < 24 ? hours : -1;
2608 return 0 < hours && hours < 12 ? hours : hours == 12 ? 0 : -1;
2610 return 0 < hours && hours < 12 ? hours + 12 : hours == 12 ? 12 : -1;
2615 to_year (textint textyear)
2617 long int year = textyear.value;
2622 /* XPG4 suggests that years 00-68 map to 2000-2068, and
2623 years 69-99 map to 1969-1999. */
2624 else if (textyear.digits == 2)
2625 year += year < 69 ? 2000 : 1900;
2630 static table const *
2631 lookup_zone (parser_control const *pc, char const *name)
2635 for (tp = universal_time_zone_table; tp->name; tp++)
2636 if (strcmp (name, tp->name) == 0)
2639 /* Try local zone abbreviations before those in time_zone_table, as
2640 the local ones are more likely to be right. */
2641 for (tp = pc->local_time_zone_table; tp->name; tp++)
2642 if (strcmp (name, tp->name) == 0)
2645 for (tp = time_zone_table; tp->name; tp++)
2646 if (strcmp (name, tp->name) == 0)
2652 #if ! HAVE_TM_GMTOFF
2653 /* Yield the difference between *A and *B,
2654 measured in seconds, ignoring leap seconds.
2655 The body of this function is taken directly from the GNU C Library;
2656 see src/strftime.c. */
2658 tm_diff (struct tm const *a, struct tm const *b)
2660 /* Compute intervening leap days correctly even if year is negative.
2661 Take care to avoid int overflow in leap day calculations. */
2662 int a4 = SHR (a->tm_year, 2) + SHR (TM_YEAR_BASE, 2) - ! (a->tm_year & 3);
2663 int b4 = SHR (b->tm_year, 2) + SHR (TM_YEAR_BASE, 2) - ! (b->tm_year & 3);
2664 int a100 = a4 / 25 - (a4 % 25 < 0);
2665 int b100 = b4 / 25 - (b4 % 25 < 0);
2666 int a400 = SHR (a100, 2);
2667 int b400 = SHR (b100, 2);
2668 int intervening_leap_days = (a4 - b4) - (a100 - b100) + (a400 - b400);
2669 long int ayear = a->tm_year;
2670 long int years = ayear - b->tm_year;
2671 long int days = (365 * years + intervening_leap_days
2672 + (a->tm_yday - b->tm_yday));
2673 return (60 * (60 * (24 * days + (a->tm_hour - b->tm_hour))
2674 + (a->tm_min - b->tm_min))
2675 + (a->tm_sec - b->tm_sec));
2677 #endif /* ! HAVE_TM_GMTOFF */
2679 static table const *
2680 lookup_word (parser_control const *pc, char *word)
2689 /* Make it uppercase. */
2690 for (p = word; *p; p++)
2692 unsigned char ch = *p;
2696 for (tp = meridian_table; tp->name; tp++)
2697 if (strcmp (word, tp->name) == 0)
2700 /* See if we have an abbreviation for a month. */
2701 wordlen = strlen (word);
2702 abbrev = wordlen == 3 || (wordlen == 4 && word[3] == '.');
2704 for (tp = month_and_day_table; tp->name; tp++)
2705 if ((abbrev ? strncmp (word, tp->name, 3) : strcmp (word, tp->name)) == 0)
2708 if ((tp = lookup_zone (pc, word)))
2711 if (strcmp (word, dst_table[0].name) == 0)
2714 for (tp = time_units_table; tp->name; tp++)
2715 if (strcmp (word, tp->name) == 0)
2718 /* Strip off any plural and try the units table again. */
2719 if (word[wordlen - 1] == 'S')
2721 word[wordlen - 1] = '\0';
2722 for (tp = time_units_table; tp->name; tp++)
2723 if (strcmp (word, tp->name) == 0)
2725 word[wordlen - 1] = 'S'; /* For "this" in relative_time_table. */
2728 for (tp = relative_time_table; tp->name; tp++)
2729 if (strcmp (word, tp->name) == 0)
2732 /* Military time zones. */
2734 for (tp = military_table; tp->name; tp++)
2735 if (word[0] == tp->name[0])
2738 /* Drop out any periods and try the time zone table again. */
2739 for (period_found = false, p = q = word; (*p = *q); q++)
2741 period_found = true;
2744 if (period_found && (tp = lookup_zone (pc, word)))
2751 yylex (YYSTYPE *lvalp, parser_control *pc)
2758 while (c = *pc->input, isspace (c))
2761 if (ISDIGIT (c) || c == '-' || c == '+')
2765 unsigned long int value;
2766 if (c == '-' || c == '+')
2768 sign = c == '-' ? -1 : 1;
2769 while (c = *++pc->input, isspace (c))
2772 /* skip the '-' sign */
2778 for (value = 0; ; value *= 10)
2780 unsigned long int value1 = value + (c - '0');
2787 if (ULONG_MAX / 10 < value)
2790 if ((c == '.' || c == ',') && ISDIGIT (p[1]))
2795 unsigned long int value1;
2797 /* Check for overflow when converting value to time_t. */
2812 if (value != value1)
2815 /* Accumulate fraction, to ns precision. */
2818 for (digits = 2; digits <= LOG10_BILLION; digits++)
2825 /* Skip excess digits, truncating toward -Infinity. */
2827 for (; ISDIGIT (*p); p++)
2833 while (ISDIGIT (*p))
2836 /* Adjust to the timespec convention, which is that
2837 tv_nsec is always a positive offset even if tv_sec is
2847 lvalp->timespec.tv_sec = s;
2848 lvalp->timespec.tv_nsec = ns;
2850 return sign ? tSDECIMAL_NUMBER : tUDECIMAL_NUMBER;
2854 lvalp->textintval.negative = sign < 0;
2857 lvalp->textintval.value = - value;
2858 if (0 < lvalp->textintval.value)
2863 lvalp->textintval.value = value;
2864 if (lvalp->textintval.value < 0)
2867 lvalp->textintval.digits = p - pc->input;
2869 return sign ? tSNUMBER : tUNUMBER;
2881 if (p < buff + sizeof buff - 1)
2885 while (isalpha (c) || c == '.');
2888 tp = lookup_word (pc, buff);
2891 lvalp->intval = tp->value;
2896 return *pc->input++;
2912 /* Do nothing if the parser reports an error. */
2914 yyerror (parser_control const *pc ATTRIBUTE_UNUSED,
2915 char const *s ATTRIBUTE_UNUSED)
2920 /* If *TM0 is the old and *TM1 is the new value of a struct tm after
2921 passing it to mktime, return true if it's OK that mktime returned T.
2922 It's not OK if *TM0 has out-of-range members. */
2925 mktime_ok (struct tm const *tm0, struct tm const *tm1, time_t t)
2927 if (t == (time_t) -1)
2929 /* Guard against falsely reporting an error when parsing a time
2930 stamp that happens to equal (time_t) -1, on a host that
2931 supports such a time stamp. */
2932 tm1 = localtime (&t);
2937 return ! ((tm0->tm_sec ^ tm1->tm_sec)
2938 | (tm0->tm_min ^ tm1->tm_min)
2939 | (tm0->tm_hour ^ tm1->tm_hour)
2940 | (tm0->tm_mday ^ tm1->tm_mday)
2941 | (tm0->tm_mon ^ tm1->tm_mon)
2942 | (tm0->tm_year ^ tm1->tm_year));
2945 /* A reasonable upper bound for the size of ordinary TZ strings.
2946 Use heap allocation if TZ's length exceeds this. */
2947 enum { TZBUFSIZE = 100 };
2949 /* Return a copy of TZ, stored in TZBUF if it fits, and heap-allocated
2952 get_tz (char tzbuf[TZBUFSIZE])
2954 char *tz = getenv ("TZ");
2957 size_t tzsize = strlen (tz) + 1;
2958 tz = (tzsize <= TZBUFSIZE
2959 ? memcpy (tzbuf, tz, tzsize)
2960 : xmemdup (tz, tzsize));
2965 /* Parse a date/time string, storing the resulting time value into *RESULT.
2966 The string itself is pointed to by P. Return true if successful.
2967 P can be an incomplete or relative time specification; if so, use
2968 *NOW as the basis for the returned time. */
2970 get_date (struct timespec *result, char const *p, struct timespec const *now)
2974 struct tm const *tmp;
2978 struct timespec gettime_buffer;
2980 bool tz_was_altered = false;
2982 char tz0buf[TZBUFSIZE];
2987 gettime (&gettime_buffer);
2988 now = &gettime_buffer;
2991 Start = now->tv_sec;
2992 Start_ns = now->tv_nsec;
2994 tmp = localtime (&now->tv_sec);
2998 while (c = *p, isspace (c))
3001 if (strncmp (p, "TZ=\"", 4) == 0)
3003 char const *tzbase = p + 4;
3007 for (s = tzbase; *s; s++, tzsize++)
3011 if (! (*s == '\\' || *s == '"'))
3018 char tz1buf[TZBUFSIZE];
3019 bool large_tz = TZBUFSIZE < tzsize;
3021 tz0 = get_tz (tz0buf);
3022 z = tz1 = large_tz ? xmalloc (tzsize) : tz1buf;
3023 for (s = tzbase; *s != '"'; s++)
3024 *z++ = *(s += *s == '\\');
3026 setenv_ok = setenv ("TZ", tz1, 1) == 0;
3031 tz_was_altered = true;
3036 /* As documented, be careful to treat the empty string just like
3037 a date string of "0". Without this, an empty string would be
3038 declared invalid when parsed during a DST transition. */
3043 pc.year.value = tmp->tm_year;
3044 pc.year.value += TM_YEAR_BASE;
3046 pc.month = tmp->tm_mon + 1;
3047 pc.day = tmp->tm_mday;
3048 pc.hour = tmp->tm_hour;
3049 pc.minutes = tmp->tm_min;
3050 pc.seconds.tv_sec = tmp->tm_sec;
3051 pc.seconds.tv_nsec = Start_ns;
3052 tm.tm_isdst = tmp->tm_isdst;
3054 pc.meridian = MER24;
3055 pc.rel = RELATIVE_TIME_0;
3056 pc.timespec_seen = false;
3057 pc.rels_seen = false;
3061 pc.local_zones_seen = 0;
3065 #if HAVE_STRUCT_TM_TM_ZONE
3066 pc.local_time_zone_table[0].name = tmp->tm_zone;
3067 pc.local_time_zone_table[0].type = tLOCAL_ZONE;
3068 pc.local_time_zone_table[0].value = tmp->tm_isdst;
3069 pc.local_time_zone_table[1].name = NULL;
3071 /* Probe the names used in the next three calendar quarters, looking
3072 for a tm_isdst different from the one we already have. */
3075 for (quarter = 1; quarter <= 3; quarter++)
3077 time_t probe = Start + quarter * (90 * 24 * 60 * 60);
3078 struct tm const *probe_tm = localtime (&probe);
3079 if (probe_tm && probe_tm->tm_zone
3080 && probe_tm->tm_isdst != pc.local_time_zone_table[0].value)
3083 pc.local_time_zone_table[1].name = probe_tm->tm_zone;
3084 pc.local_time_zone_table[1].type = tLOCAL_ZONE;
3085 pc.local_time_zone_table[1].value = probe_tm->tm_isdst;
3086 pc.local_time_zone_table[2].name = NULL;
3095 # if !HAVE_DECL_TZNAME
3096 extern char *tzname[];
3099 for (i = 0; i < 2; i++)
3101 pc.local_time_zone_table[i].name = tzname[i];
3102 pc.local_time_zone_table[i].type = tLOCAL_ZONE;
3103 pc.local_time_zone_table[i].value = i;
3105 pc.local_time_zone_table[i].name = NULL;
3108 pc.local_time_zone_table[0].name = NULL;
3112 if (pc.local_time_zone_table[0].name && pc.local_time_zone_table[1].name
3113 && ! strcmp (pc.local_time_zone_table[0].name,
3114 pc.local_time_zone_table[1].name))
3116 /* This locale uses the same abbrevation for standard and
3117 daylight times. So if we see that abbreviation, we don't
3118 know whether it's daylight time. */
3119 pc.local_time_zone_table[0].value = -1;
3120 pc.local_time_zone_table[1].name = NULL;
3123 if (yyparse (&pc) != 0)
3126 if (pc.timespec_seen)
3127 *result = pc.seconds;
3130 if (1 < (pc.times_seen | pc.dates_seen | pc.days_seen | pc.dsts_seen
3131 | (pc.local_zones_seen + pc.zones_seen)))
3134 tm.tm_year = to_year (pc.year) - TM_YEAR_BASE;
3135 tm.tm_mon = pc.month - 1;
3136 tm.tm_mday = pc.day;
3137 if (pc.times_seen || (pc.rels_seen && ! pc.dates_seen && ! pc.days_seen))
3139 tm.tm_hour = to_hour (pc.hour, pc.meridian);
3142 tm.tm_min = pc.minutes;
3143 tm.tm_sec = pc.seconds.tv_sec;
3147 tm.tm_hour = tm.tm_min = tm.tm_sec = 0;
3148 pc.seconds.tv_nsec = 0;
3151 /* Let mktime deduce tm_isdst if we have an absolute time stamp. */
3152 if (pc.dates_seen | pc.days_seen | pc.times_seen)
3155 /* But if the input explicitly specifies local time with or without
3156 DST, give mktime that information. */
3157 if (pc.local_zones_seen)
3158 tm.tm_isdst = pc.local_isdst;
3162 Start = mktime (&tm);
3164 if (! mktime_ok (&tm0, &tm, Start))
3166 if (! pc.zones_seen)
3170 /* Guard against falsely reporting errors near the time_t
3171 boundaries when parsing times in other time zones. For
3172 example, suppose the input string "1969-12-31 23:00:00 -0100",
3173 the current time zone is 8 hours ahead of UTC, and the min
3174 time_t value is 1970-01-01 00:00:00 UTC. Then the min
3175 localtime value is 1970-01-01 08:00:00, and mktime will
3176 therefore fail on 1969-12-31 23:00:00. To work around the
3177 problem, set the time zone to 1 hour behind UTC temporarily
3178 by setting TZ="XXX1:00" and try mktime again. */
3180 long int time_zone = pc.time_zone;
3181 long int abs_time_zone = time_zone < 0 ? - time_zone : time_zone;
3182 long int abs_time_zone_hour = abs_time_zone / 60;
3183 int abs_time_zone_min = abs_time_zone % 60;
3184 char tz1buf[sizeof "XXX+0:00"
3185 + sizeof pc.time_zone * CHAR_BIT / 3];
3186 if (!tz_was_altered)
3187 tz0 = get_tz (tz0buf);
3188 sprintf (tz1buf, "XXX%s%ld:%02d", "-" + (time_zone < 0),
3189 abs_time_zone_hour, abs_time_zone_min);
3190 if (setenv ("TZ", tz1buf, 1) != 0)
3192 tz_was_altered = true;
3194 Start = mktime (&tm);
3195 if (! mktime_ok (&tm0, &tm, Start))
3200 if (pc.days_seen && ! pc.dates_seen)
3202 tm.tm_mday += ((pc.day_number - tm.tm_wday + 7) % 7
3203 + 7 * (pc.day_ordinal - (0 < pc.day_ordinal)));
3205 Start = mktime (&tm);
3206 if (Start == (time_t) -1)
3212 long int delta = pc.time_zone * 60;
3214 #ifdef HAVE_TM_GMTOFF
3215 delta -= tm.tm_gmtoff;
3218 struct tm const *gmt = gmtime (&t);
3221 delta -= tm_diff (&tm, gmt);
3224 if ((Start < t1) != (delta < 0))
3225 goto fail; /* time_t overflow */
3229 /* Add relative date. */
3230 if (pc.rel.year | pc.rel.month | pc.rel.day)
3232 int year = tm.tm_year + pc.rel.year;
3233 int month = tm.tm_mon + pc.rel.month;
3234 int day = tm.tm_mday + pc.rel.day;
3235 if (((year < tm.tm_year) ^ (pc.rel.year < 0))
3236 | ((month < tm.tm_mon) ^ (pc.rel.month < 0))
3237 | ((day < tm.tm_mday) ^ (pc.rel.day < 0)))
3242 tm.tm_hour = tm0.tm_hour;
3243 tm.tm_min = tm0.tm_min;
3244 tm.tm_sec = tm0.tm_sec;
3245 tm.tm_isdst = tm0.tm_isdst;
3246 Start = mktime (&tm);
3247 if (Start == (time_t) -1)
3251 /* Add relative hours, minutes, and seconds. On hosts that support
3252 leap seconds, ignore the possibility of leap seconds; e.g.,
3253 "+ 10 minutes" adds 600 seconds, even if one of them is a
3254 leap second. Typically this is not what the user wants, but it's
3255 too hard to do it the other way, because the time zone indicator
3256 must be applied before relative times, and if mktime is applied
3257 again the time zone will be lost. */
3259 long int sum_ns = pc.seconds.tv_nsec + pc.rel.ns;
3260 long int normalized_ns = (sum_ns % BILLION + BILLION) % BILLION;
3262 long int d1 = 60 * 60 * pc.rel.hour;
3263 time_t t1 = t0 + d1;
3264 long int d2 = 60 * pc.rel.minutes;
3265 time_t t2 = t1 + d2;
3266 long int d3 = pc.rel.seconds;
3267 time_t t3 = t2 + d3;
3268 long int d4 = (sum_ns - normalized_ns) / BILLION;
3269 time_t t4 = t3 + d4;
3271 if ((d1 / (60 * 60) ^ pc.rel.hour)
3272 | (d2 / 60 ^ pc.rel.minutes)
3273 | ((t1 < t0) ^ (d1 < 0))
3274 | ((t2 < t1) ^ (d2 < 0))
3275 | ((t3 < t2) ^ (d3 < 0))
3276 | ((t4 < t3) ^ (d4 < 0)))
3279 result->tv_sec = t4;
3280 result->tv_nsec = normalized_ns;
3290 ok &= (tz0 ? setenv ("TZ", tz0, 1) : unsetenv ("TZ")) == 0;
3299 main (int ac, char **av)
3303 printf ("Enter date, or blank line to exit.\n\t> ");
3306 buff[BUFSIZ - 1] = '\0';
3307 while (fgets (buff, BUFSIZ - 1, stdin) && buff[0])
3310 struct tm const *tm;
3311 if (! get_date (&d, buff, NULL))
3312 printf ("Bad format - couldn't convert.\n");
3313 else if (! (tm = localtime (&d.tv_sec)))
3315 long int sec = d.tv_sec;
3316 printf ("localtime (%ld) failed\n", sec);
3321 printf ("%04ld-%02d-%02d %02d:%02d:%02d.%09d\n",
3322 tm->tm_year + 1900L, tm->tm_mon + 1, tm->tm_mday,
3323 tm->tm_hour, tm->tm_min, tm->tm_sec, ns);