1/* A Bison parser, made by GNU Bison 2.4.460-505e. */ 2 3/* Implementation for Bison's Yacc-like parsers in C 4 5 Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 6 2007, 2008, 2009 Free Software Foundation, Inc. 7 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 3 of the License, or 11 (at your option) any later version. 12 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. 17 18 You should have received a copy of the GNU General Public License 19 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 20 21/* As a special exception, you may create a larger work that contains 22 part or all of the Bison parser skeleton and distribute that work 23 under terms of your choice, so long as that work isn't itself a 24 parser generator using the skeleton or a modified version thereof 25 as a parser skeleton. Alternatively, if you modify or redistribute 26 the parser skeleton itself, you may (at your option) remove this 27 special exception, which will cause the skeleton and the resulting 28 Bison output files to be licensed under the GNU General Public 29 License without this special exception. 30 31 This special exception was added by the Free Software Foundation in 32 version 2.2 of Bison. */ 33 34/* C LALR(1) parser skeleton written by Richard Stallman, by 35 simplifying the original so-called "semantic" parser. */ 36 37/* All symbols defined below should begin with yy or YY, to avoid 38 infringing on user name space. This should be done even for local 39 variables, as they might otherwise be expanded by user macros. 40 There are some unavoidable exceptions within include files to 41 define necessary library symbols; they are noted "INFRINGES ON 42 USER NAME SPACE" below. */ 43 44/* Identify Bison output. */ 45#define YYBISON 1 46 47/* Bison version. */ 48#define YYBISON_VERSION "2.4.460-505e" 49 50/* Skeleton name. */ 51#define YYSKELETON_NAME "yacc.c" 52 53/* Pure parsers. */ 54#define YYPURE 1 55 56/* Push parsers. */ 57#define YYPUSH 0 58 59/* Pull parsers. */ 60#define YYPULL 1 61 62/* Using locations. */ 63#define YYLSP_NEEDED 0 64 65 66 67/* Copy the first part of user declarations. */ 68/* Line 253 of yacc.c */ 69#line 1 "getdate.y" 70 71/* Parse a string into an internal time stamp. 72 73 Copyright (C) 1999, 2000, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 74 2010 Free Software Foundation, Inc. 75 76 This program is free software: you can redistribute it and/or modify 77 it under the terms of the GNU General Public License as published by 78 the Free Software Foundation; either version 3 of the License, or 79 (at your option) any later version. 80 81 This program is distributed in the hope that it will be useful, 82 but WITHOUT ANY WARRANTY; without even the implied warranty of 83 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 84 GNU General Public License for more details. 85 86 You should have received a copy of the GNU General Public License 87 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 88 89/* Originally written by Steven M. Bellovin <smb@research.att.com> while 90 at the University of North Carolina at Chapel Hill. Later tweaked by 91 a couple of people on Usenet. Completely overhauled by Rich $alz 92 <rsalz@bbn.com> and Jim Berets <jberets@bbn.com> in August, 1990. 93 94 Modified by Paul Eggert <eggert@twinsun.com> in August 1999 to do 95 the right thing about local DST. Also modified by Paul Eggert 96 <eggert@cs.ucla.edu> in February 2004 to support 97 nanosecond-resolution time stamps, and in October 2004 to support 98 TZ strings in dates. */ 99 100/* FIXME: Check for arithmetic overflow in all cases, not just 101 some of them. */ 102 103#include <config.h> 104 105#include "getdate.h" 106 107#include "intprops.h" 108#include "timespec.h" 109#include "verify.h" 110 111/* There's no need to extend the stack, so there's no need to involve 112 alloca. */ 113#define YYSTACK_USE_ALLOCA 0 114 115/* Tell Bison how much stack space is needed. 20 should be plenty for 116 this grammar, which is not right recursive. Beware setting it too 117 high, since that might cause problems on machines whose 118 implementations have lame stack-overflow checking. */ 119#define YYMAXDEPTH 20 120#define YYINITDEPTH YYMAXDEPTH 121 122/* Since the code of getdate.y is not included in the Emacs executable 123 itself, there is no need to #define static in this file. Even if 124 the code were included in the Emacs executable, it probably 125 wouldn't do any harm to #undef it here; this will only cause 126 problems if we try to write to a static variable, which I don't 127 think this code needs to do. */ 128#ifdef emacs 129# undef static 130#endif 131 132#include <c-ctype.h> 133#include <limits.h> 134#include <stdio.h> 135#include <stdlib.h> 136#include <string.h> 137 138#include "xalloc.h" 139 140 141/* ISDIGIT differs from isdigit, as follows: 142 - Its arg may be any int or unsigned int; it need not be an unsigned char 143 or EOF. 144 - It's typically faster. 145 POSIX says that only '0' through '9' are digits. Prefer ISDIGIT to 146 isdigit unless it's important to use the locale's definition 147 of `digit' even when the host does not conform to POSIX. */ 148#define ISDIGIT(c) ((unsigned int) (c) - '0' <= 9) 149 150/* Shift A right by B bits portably, by dividing A by 2**B and 151 truncating towards minus infinity. A and B should be free of side 152 effects, and B should be in the range 0 <= B <= INT_BITS - 2, where 153 INT_BITS is the number of useful bits in an int. GNU code can 154 assume that INT_BITS is at least 32. 155 156 ISO C99 says that A >> B is implementation-defined if A < 0. Some 157 implementations (e.g., UNICOS 9.0 on a Cray Y-MP EL) don't shift 158 right in the usual way when A < 0, so SHR falls back on division if 159 ordinary A >> B doesn't seem to be the usual signed shift. */ 160#define SHR(a, b) \ 161 (-1 >> 1 == -1 \ 162 ? (a) >> (b) \ 163 : (a) / (1 << (b)) - ((a) % (1 << (b)) < 0)) 164 165#define EPOCH_YEAR 1970 166#define TM_YEAR_BASE 1900 167 168#define HOUR(x) ((x) * 60) 169 170/* long_time_t is a signed integer type that contains all time_t values. */ 171verify (TYPE_IS_INTEGER (time_t)); 172#if TIME_T_FITS_IN_LONG_INT 173typedef long int long_time_t; 174#else 175typedef time_t long_time_t; 176#endif 177 178/* Lots of this code assumes time_t and time_t-like values fit into 179 long_time_t. */ 180verify (TYPE_MINIMUM (long_time_t) <= TYPE_MINIMUM (time_t) 181 && TYPE_MAXIMUM (time_t) <= TYPE_MAXIMUM (long_time_t)); 182 183/* FIXME: It also assumes that signed integer overflow silently wraps around, 184 but this is not true any more with recent versions of GCC 4. */ 185 186/* An integer value, and the number of digits in its textual 187 representation. */ 188typedef struct 189{ 190 bool negative; 191 long int value; 192 size_t digits; 193} textint; 194 195/* An entry in the lexical lookup table. */ 196typedef struct 197{ 198 char const *name; 199 int type; 200 int value; 201} table; 202 203/* Meridian: am, pm, or 24-hour style. */ 204enum { MERam, MERpm, MER24 }; 205 206enum { BILLION = 1000000000, LOG10_BILLION = 9 }; 207 208/* Relative times. */ 209typedef struct 210{ 211 /* Relative year, month, day, hour, minutes, seconds, and nanoseconds. */ 212 long int year; 213 long int month; 214 long int day; 215 long int hour; 216 long int minutes; 217 long_time_t seconds; 218 long int ns; 219} relative_time; 220 221#if HAVE_COMPOUND_LITERALS 222# define RELATIVE_TIME_0 ((relative_time) { 0, 0, 0, 0, 0, 0, 0 }) 223#else 224static relative_time const RELATIVE_TIME_0; 225#endif 226 227/* Information passed to and from the parser. */ 228typedef struct 229{ 230 /* The input string remaining to be parsed. */ 231 const char *input; 232 233 /* N, if this is the Nth Tuesday. */ 234 long int day_ordinal; 235 236 /* Day of week; Sunday is 0. */ 237 int day_number; 238 239 /* tm_isdst flag for the local zone. */ 240 int local_isdst; 241 242 /* Time zone, in minutes east of UTC. */ 243 long int time_zone; 244 245 /* Style used for time. */ 246 int meridian; 247 248 /* Gregorian year, month, day, hour, minutes, seconds, and nanoseconds. */ 249 textint year; 250 long int month; 251 long int day; 252 long int hour; 253 long int minutes; 254 struct timespec seconds; /* includes nanoseconds */ 255 256 /* Relative year, month, day, hour, minutes, seconds, and nanoseconds. */ 257 relative_time rel; 258 259 /* Presence or counts of nonterminals of various flavors parsed so far. */ 260 bool timespec_seen; 261 bool rels_seen; 262 size_t dates_seen; 263 size_t days_seen; 264 size_t local_zones_seen; 265 size_t dsts_seen; 266 size_t times_seen; 267 size_t zones_seen; 268 269 /* Table of local time zone abbrevations, terminated by a null entry. */ 270 table local_time_zone_table[3]; 271} parser_control; 272 273union YYSTYPE; 274static int yylex (union YYSTYPE *, parser_control *); 275static int yyerror (parser_control const *, char const *); 276static long int time_zone_hhmm (parser_control *, textint, long int); 277 278/* Extract into *PC any date and time info from a string of digits 279 of the form e.g., YYYYMMDD, YYMMDD, HHMM, HH (and sometimes YYY, 280 YYYY, ...). */ 281static void 282digits_to_date_time (parser_control *pc, textint text_int) 283{ 284 if (pc->dates_seen && ! pc->year.digits 285 && ! pc->rels_seen && (pc->times_seen || 2 < text_int.digits)) 286 pc->year = text_int; 287 else 288 { 289 if (4 < text_int.digits) 290 { 291 pc->dates_seen++; 292 pc->day = text_int.value % 100; 293 pc->month = (text_int.value / 100) % 100; 294 pc->year.value = text_int.value / 10000; 295 pc->year.digits = text_int.digits - 4; 296 } 297 else 298 { 299 pc->times_seen++; 300 if (text_int.digits <= 2) 301 { 302 pc->hour = text_int.value; 303 pc->minutes = 0; 304 } 305 else 306 { 307 pc->hour = text_int.value / 100; 308 pc->minutes = text_int.value % 100; 309 } 310 pc->seconds.tv_sec = 0; 311 pc->seconds.tv_nsec = 0; 312 pc->meridian = MER24; 313 } 314 } 315} 316 317/* Increment PC->rel by FACTOR * REL (FACTOR is 1 or -1). */ 318static void 319apply_relative_time (parser_control *pc, relative_time rel, int factor) 320{ 321 pc->rel.ns += factor * rel.ns; 322 pc->rel.seconds += factor * rel.seconds; 323 pc->rel.minutes += factor * rel.minutes; 324 pc->rel.hour += factor * rel.hour; 325 pc->rel.day += factor * rel.day; 326 pc->rel.month += factor * rel.month; 327 pc->rel.year += factor * rel.year; 328 pc->rels_seen = true; 329} 330 331/* Set PC-> hour, minutes, seconds and nanoseconds members from arguments. */ 332static void 333set_hhmmss (parser_control *pc, long int hour, long int minutes, 334 time_t sec, long int nsec) 335{ 336 pc->hour = hour; 337 pc->minutes = minutes; 338 pc->seconds.tv_sec = sec; 339 pc->seconds.tv_nsec = nsec; 340} 341 342 343/* Line 253 of yacc.c */ 344#line 345 "getdate.c" 345 346/* Enabling traces. */ 347#ifndef YYDEBUG 348# define YYDEBUG 0 349#endif 350 351/* Enabling verbose error messages. */ 352#ifdef YYERROR_VERBOSE 353# undef YYERROR_VERBOSE 354# define YYERROR_VERBOSE 1 355#else 356# define YYERROR_VERBOSE 0 357#endif 358 359/* Enabling the token table. */ 360#ifndef YYTOKEN_TABLE 361# define YYTOKEN_TABLE 0 362#endif 363 364 365/* Tokens. */ 366#ifndef YYTOKENTYPE 367# define YYTOKENTYPE 368 /* Put the tokens into the symbol table, so that GDB and other debuggers 369 know about them. */ 370 enum yytokentype { 371 tAGO = 258, 372 tDST = 259, 373 tYEAR_UNIT = 260, 374 tMONTH_UNIT = 261, 375 tHOUR_UNIT = 262, 376 tMINUTE_UNIT = 263, 377 tSEC_UNIT = 264, 378 tDAY_UNIT = 265, 379 tDAY_SHIFT = 266, 380 tDAY = 267, 381 tDAYZONE = 268, 382 tLOCAL_ZONE = 269, 383 tMERIDIAN = 270, 384 tMONTH = 271, 385 tORDINAL = 272, 386 tZONE = 273, 387 tSNUMBER = 274, 388 tUNUMBER = 275, 389 tSDECIMAL_NUMBER = 276, 390 tUDECIMAL_NUMBER = 277 391 }; 392#endif 393/* Tokens. */ 394#define tAGO 258 395#define tDST 259 396#define tYEAR_UNIT 260 397#define tMONTH_UNIT 261 398#define tHOUR_UNIT 262 399#define tMINUTE_UNIT 263 400#define tSEC_UNIT 264 401#define tDAY_UNIT 265 402#define tDAY_SHIFT 266 403#define tDAY 267 404#define tDAYZONE 268 405#define tLOCAL_ZONE 269 406#define tMERIDIAN 270 407#define tMONTH 271 408#define tORDINAL 272 409#define tZONE 273 410#define tSNUMBER 274 411#define tUNUMBER 275 412#define tSDECIMAL_NUMBER 276 413#define tUDECIMAL_NUMBER 277 414 415 416 417 418#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED 419typedef union YYSTYPE 420{ 421/* Line 278 of yacc.c */ 422#line 285 "getdate.y" 423 424 long int intval; 425 textint textintval; 426 struct timespec timespec; 427 relative_time rel; 428 429 430/* Line 278 of yacc.c */ 431#line 432 "getdate.c" 432} YYSTYPE; 433# define YYSTYPE_IS_TRIVIAL 1 434# define yystype YYSTYPE /* obsolescent; will be withdrawn */ 435# define YYSTYPE_IS_DECLARED 1 436#endif 437 438 439/* Copy the second part of user declarations. */ 440 441/* Line 328 of yacc.c */ 442#line 443 "getdate.c" 443 444#ifdef short 445# undef short 446#endif 447 448#ifdef YYTYPE_UINT8 449typedef YYTYPE_UINT8 yytype_uint8; 450#else 451typedef unsigned char yytype_uint8; 452#endif 453 454#ifdef YYTYPE_INT8 455typedef YYTYPE_INT8 yytype_int8; 456#elif (defined __STDC__ || defined __C99__FUNC__ \ 457 || defined __cplusplus || defined _MSC_VER) 458typedef signed char yytype_int8; 459#else 460typedef short int yytype_int8; 461#endif 462 463#ifdef YYTYPE_UINT16 464typedef YYTYPE_UINT16 yytype_uint16; 465#else 466typedef unsigned short int yytype_uint16; 467#endif 468 469#ifdef YYTYPE_INT16 470typedef YYTYPE_INT16 yytype_int16; 471#else 472typedef short int yytype_int16; 473#endif 474 475#ifndef YYSIZE_T 476# ifdef __SIZE_TYPE__ 477# define YYSIZE_T __SIZE_TYPE__ 478# elif defined size_t 479# define YYSIZE_T size_t 480# elif ! defined YYSIZE_T && (defined __STDC__ || defined __C99__FUNC__ \ 481 || defined __cplusplus || defined _MSC_VER) 482# include <stddef.h> /* INFRINGES ON USER NAME SPACE */ 483# define YYSIZE_T size_t 484# else 485# define YYSIZE_T unsigned int 486# endif 487#endif 488 489#define YYSIZE_MAXIMUM ((YYSIZE_T) -1) 490 491#ifndef YY_ 492# if defined YYENABLE_NLS && YYENABLE_NLS 493# if ENABLE_NLS 494# include <libintl.h> /* INFRINGES ON USER NAME SPACE */ 495# define YY_(msgid) dgettext ("bison-runtime", msgid) 496# endif 497# endif 498# ifndef YY_ 499# define YY_(msgid) msgid 500# endif 501#endif 502 503/* Suppress unused-variable warnings by "using" E. */ 504#if ! defined lint || defined __GNUC__ 505# define YYUSE(e) ((void) (e)) 506#else 507# define YYUSE(e) /* empty */ 508#endif 509 510/* Identity function, used to suppress warnings about constant conditions. */ 511#ifndef lint 512# define YYID(n) (n) 513#else 514#if (defined __STDC__ || defined __C99__FUNC__ \ 515 || defined __cplusplus || defined _MSC_VER) 516static int 517YYID (int yyi) 518#else 519static int 520YYID (yyi) 521 int yyi; 522#endif 523{ 524 return yyi; 525} 526#endif 527 528#if ! defined yyoverflow || YYERROR_VERBOSE 529 530/* The parser invokes alloca or malloc; define the necessary symbols. */ 531 532# ifdef YYSTACK_USE_ALLOCA 533# if YYSTACK_USE_ALLOCA 534# ifdef __GNUC__ 535# define YYSTACK_ALLOC __builtin_alloca 536# elif defined __BUILTIN_VA_ARG_INCR 537# include <alloca.h> /* INFRINGES ON USER NAME SPACE */ 538# elif defined _AIX 539# define YYSTACK_ALLOC __alloca 540# elif defined _MSC_VER 541# include <malloc.h> /* INFRINGES ON USER NAME SPACE */ 542# define alloca _alloca 543# else 544# define YYSTACK_ALLOC alloca 545# if ! defined _ALLOCA_H && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \ 546 || defined __cplusplus || defined _MSC_VER) 547# include <stdlib.h> /* INFRINGES ON USER NAME SPACE */ 548# ifndef _STDLIB_H 549# define _STDLIB_H 1 550# endif 551# endif 552# endif 553# endif 554# endif 555 556# ifdef YYSTACK_ALLOC 557 /* Pacify GCC's `empty if-body' warning. */ 558# define YYSTACK_FREE(Ptr) do { /* empty */; } while (YYID (0)) 559# ifndef YYSTACK_ALLOC_MAXIMUM 560 /* The OS might guarantee only one guard page at the bottom of the stack, 561 and a page size can be as small as 4096 bytes. So we cannot safely 562 invoke alloca (N) if N exceeds 4096. Use a slightly smaller number 563 to allow for a few compiler-allocated temporary stack slots. */ 564# define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */ 565# endif 566# else 567# define YYSTACK_ALLOC YYMALLOC 568# define YYSTACK_FREE YYFREE 569# ifndef YYSTACK_ALLOC_MAXIMUM 570# define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM 571# endif 572# if (defined __cplusplus && ! defined _STDLIB_H \ 573 && ! ((defined YYMALLOC || defined malloc) \ 574 && (defined YYFREE || defined free))) 575# include <stdlib.h> /* INFRINGES ON USER NAME SPACE */ 576# ifndef _STDLIB_H 577# define _STDLIB_H 1 578# endif 579# endif 580# ifndef YYMALLOC 581# define YYMALLOC malloc 582# if ! defined malloc && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \ 583 || defined __cplusplus || defined _MSC_VER) 584void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */ 585# endif 586# endif 587# ifndef YYFREE 588# define YYFREE free 589# if ! defined free && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \ 590 || defined __cplusplus || defined _MSC_VER) 591void free (void *); /* INFRINGES ON USER NAME SPACE */ 592# endif 593# endif 594# endif 595#endif /* ! defined yyoverflow || YYERROR_VERBOSE */ 596 597 598#if (! defined yyoverflow \ 599 && (! defined __cplusplus \ 600 || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL))) 601 602/* A type that is properly aligned for any stack member. */ 603union yyalloc 604{ 605 yytype_int16 yyss_alloc; 606 YYSTYPE yyvs_alloc; 607}; 608 609/* The size of the maximum gap between one aligned stack and the next. */ 610# define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1) 611 612/* The size of an array large to enough to hold all stacks, each with 613 N elements. */ 614# define YYSTACK_BYTES(N) \ 615 ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE)) \ 616 + YYSTACK_GAP_MAXIMUM) 617 618/* Copy COUNT objects from FROM to TO. The source and destination do 619 not overlap. */ 620# ifndef YYCOPY 621# if defined __GNUC__ && 1 < __GNUC__ 622# define YYCOPY(To, From, Count) \ 623 __builtin_memcpy (To, From, (Count) * sizeof (*(From))) 624# else 625# define YYCOPY(To, From, Count) \ 626 do \ 627 { \ 628 YYSIZE_T yyi; \ 629 for (yyi = 0; yyi < (Count); yyi++) \ 630 (To)[yyi] = (From)[yyi]; \ 631 } \ 632 while (YYID (0)) 633# endif 634# endif 635 636/* Relocate STACK from its old location to the new one. The 637 local variables YYSIZE and YYSTACKSIZE give the old and new number of 638 elements in the stack, and YYPTR gives the new location of the 639 stack. Advance YYPTR to a properly aligned location for the next 640 stack. */ 641# define YYSTACK_RELOCATE(Stack_alloc, Stack) \ 642 do \ 643 { \ 644 YYSIZE_T yynewbytes; \ 645 YYCOPY (&yyptr->Stack_alloc, Stack, yysize); \ 646 Stack = &yyptr->Stack_alloc; \ 647 yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \ 648 yyptr += yynewbytes / sizeof (*yyptr); \ 649 } \ 650 while (YYID (0)) 651 652#endif 653 654/* YYFINAL -- State number of the termination state. */ 655#define YYFINAL 12 656/* YYLAST -- Last index in YYTABLE. */ 657#define YYLAST 98 658 659/* YYNTOKENS -- Number of terminals. */ 660#define YYNTOKENS 27 661/* YYNNTS -- Number of nonterminals. */ 662#define YYNNTS 21 663/* YYNRULES -- Number of rules. */ 664#define YYNRULES 82 665/* YYNSTATES -- Number of states. */ 666#define YYNSTATES 100 667 668/* YYTRANSLATE[YYX] -- Symbol number corresponding to YYX as returned 669 by yylex, with out-of-bounds checking. */ 670#define YYUNDEFTOK 2 671#define YYMAXUTOK 277 672 673#define YYTRANSLATE(YYX) \ 674 ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK) 675 676/* YYTRANSLATE[TOKEN-NUM] -- Symbol number corresponding to TOKEN-NUM 677 as returned by yylex, without out-of-bounds checking. */ 678static const yytype_uint8 yytranslate[] = 679{ 680 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 681 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 682 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 683 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 684 2, 2, 2, 2, 25, 2, 2, 26, 2, 2, 685 2, 2, 2, 2, 2, 2, 2, 2, 24, 2, 686 2, 2, 2, 2, 23, 2, 2, 2, 2, 2, 687 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 688 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 689 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 690 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 691 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 692 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 693 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 694 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 695 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 696 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 697 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 698 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 699 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 700 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 701 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 702 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 703 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 704 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 705 2, 2, 2, 2, 2, 2, 1, 2, 3, 4, 706 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 707 15, 16, 17, 18, 19, 20, 21, 22 708}; 709 710#if YYDEBUG 711 /* YYRLINEYYN -- Source line where rule number YYN was defined. */ 712static const yytype_uint16 yyrline[] = 713{ 714 0, 311, 311, 312, 316, 323, 325, 329, 331, 333, 715 335, 337, 339, 340, 341, 345, 350, 355, 362, 367, 716 377, 382, 390, 392, 395, 397, 399, 404, 409, 414, 717 419, 427, 432, 452, 459, 467, 475, 480, 486, 491, 718 500, 502, 504, 509, 511, 513, 515, 517, 519, 521, 719 523, 525, 527, 529, 531, 533, 535, 537, 539, 541, 720 543, 545, 547, 549, 553, 555, 557, 559, 561, 563, 721 568, 572, 572, 575, 576, 581, 582, 587, 592, 603, 722 604, 610, 611 723}; 724#endif 725 726#if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE 727/* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM. 728 First, the terminals, then, starting at YYNTOKENS, nonterminals. */ 729static const char *const yytname[] = 730{ 731 "$end", "error", "$undefined", "tAGO", "tDST", "tYEAR_UNIT", 732 "tMONTH_UNIT", "tHOUR_UNIT", "tMINUTE_UNIT", "tSEC_UNIT", "tDAY_UNIT", 733 "tDAY_SHIFT", "tDAY", "tDAYZONE", "tLOCAL_ZONE", "tMERIDIAN", "tMONTH", 734 "tORDINAL", "tZONE", "tSNUMBER", "tUNUMBER", "tSDECIMAL_NUMBER", 735 "tUDECIMAL_NUMBER", "'@'", "':'", "','", "'/'", "$accept", "spec", 736 "timespec", "items", "item", "time", "local_zone", "zone", "day", "date", 737 "rel", "relunit", "relunit_snumber", "dayshift", "seconds", 738 "signed_seconds", "unsigned_seconds", "number", "hybrid", 739 "o_colon_minutes", "o_merid", 0 740}; 741#endif 742 743# ifdef YYPRINT 744/* YYTOKNUM[NUM] -- (External) token number corresponding to the 745 (internal) symbol number NUM (which must be that of a token). */ 746static const yytype_uint16 yytoknum[] = 747{ 748 0, 256, 257, 258, 259, 260, 261, 262, 263, 264, 749 265, 266, 267, 268, 269, 270, 271, 272, 273, 274, 750 275, 276, 277, 64, 58, 44, 47 751}; 752# endif 753 754#define YYPACT_NINF -82 755 756#define yypact_value_is_default(yystate) \ 757 ((yystate) == (-82)) 758 759#define YYTABLE_NINF -1 760 761#define yytable_value_is_error(yytable_value) \ 762 YYID (0) 763 764 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing 765 STATE-NUM. */ 766static const yytype_int8 yypact[] = 767{ 768 -17, 56, 15, -82, 26, -82, -82, -82, -82, -82, 769 -82, -82, -82, -82, -82, -82, -82, -82, -82, -82, 770 36, -82, 68, 10, 50, 9, 59, -5, 72, 73, 771 -82, -82, -82, -82, -82, -82, -82, 80, -82, -82, 772 -82, -82, -82, -82, 65, 61, -82, -82, -82, -82, 773 -82, -82, -82, -82, 17, -82, -82, -82, -82, -82, 774 -82, -82, -82, -82, -82, -82, -82, -82, -82, -82, 775 60, 44, 67, 69, -82, -82, -82, -82, -82, 70, 776 71, -82, -82, -82, -82, -7, 62, -82, -82, -82, 777 74, -2, -82, 75, -82, 55, -82, 74, -82, -82 778}; 779 780 /* YYDEFACT[S] -- default reduction number in state S. Performed when 781 YYTABLE does not specify something else to do. Zero means the default 782 is an error. */ 783static const yytype_uint8 yydefact[] = 784{ 785 5, 0, 0, 2, 3, 74, 76, 73, 75, 4, 786 71, 72, 1, 45, 48, 54, 57, 62, 51, 70, 787 27, 25, 20, 0, 0, 22, 0, 77, 0, 0, 788 6, 7, 8, 9, 11, 10, 12, 41, 63, 42, 789 13, 14, 28, 21, 0, 36, 43, 46, 52, 55, 790 58, 49, 29, 26, 79, 23, 64, 65, 67, 68, 791 69, 66, 44, 47, 53, 56, 59, 50, 30, 15, 792 38, 0, 0, 0, 78, 60, 61, 40, 35, 0, 793 0, 24, 34, 39, 33, 81, 31, 37, 80, 82, 794 79, 0, 16, 0, 17, 81, 32, 79, 18, 19 795}; 796 797 /* YYPGOTO[NTERM-NUM]. */ 798static const yytype_int8 yypgoto[] = 799{ 800 -82, -82, -82, -82, -82, -82, -82, -82, -82, -82, 801 -82, -82, 46, -82, -82, -82, -6, -82, -82, -81, 802 -3 803}; 804 805 /* YYDEFGOTO[NTERM-NUM]. */ 806static const yytype_int8 yydefgoto[] = 807{ 808 -1, 2, 3, 4, 30, 31, 32, 33, 34, 35, 809 36, 37, 38, 39, 9, 10, 11, 40, 41, 81, 810 92 811}; 812 813 /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If 814 positive, shift that token. If negative, reduce the rule which 815 number is the opposite. If YYTABLE_NINF, syntax error. */ 816static const yytype_uint8 yytable[] = 817{ 818 62, 63, 64, 65, 66, 67, 1, 68, 89, 94, 819 69, 70, 90, 53, 71, 12, 99, 91, 6, 72, 820 8, 73, 56, 57, 58, 59, 60, 61, 54, 44, 821 45, 13, 14, 15, 16, 17, 18, 19, 20, 21, 822 22, 80, 23, 24, 25, 26, 27, 28, 29, 56, 823 57, 58, 59, 60, 61, 46, 47, 48, 49, 50, 824 51, 42, 52, 84, 56, 57, 58, 59, 60, 61, 825 89, 55, 43, 74, 97, 5, 6, 7, 8, 82, 826 83, 75, 76, 77, 78, 95, 79, 85, 93, 86, 827 87, 88, 98, 0, 0, 96, 0, 0, 80 828}; 829 830static const yytype_int8 yycheck[] = 831{ 832 5, 6, 7, 8, 9, 10, 23, 12, 15, 90, 833 15, 16, 19, 4, 19, 0, 97, 24, 20, 24, 834 22, 26, 5, 6, 7, 8, 9, 10, 19, 19, 835 20, 5, 6, 7, 8, 9, 10, 11, 12, 13, 836 14, 24, 16, 17, 18, 19, 20, 21, 22, 5, 837 6, 7, 8, 9, 10, 5, 6, 7, 8, 9, 838 10, 25, 12, 19, 5, 6, 7, 8, 9, 10, 839 15, 25, 4, 27, 19, 19, 20, 21, 22, 19, 840 20, 9, 9, 3, 19, 91, 25, 20, 26, 20, 841 20, 20, 95, -1, -1, 20, -1, -1, 24 842}; 843 844 /* STOS_[STATE-NUM] -- The (internal number of the) accessing 845 symbol of state STATE-NUM. */ 846static const yytype_uint8 yystos[] = 847{ 848 0, 23, 28, 29, 30, 19, 20, 21, 22, 41, 849 42, 43, 0, 5, 6, 7, 8, 9, 10, 11, 850 12, 13, 14, 16, 17, 18, 19, 20, 21, 22, 851 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 852 44, 45, 25, 4, 19, 20, 5, 6, 7, 8, 853 9, 10, 12, 4, 19, 39, 5, 6, 7, 8, 854 9, 10, 5, 6, 7, 8, 9, 10, 12, 15, 855 16, 19, 24, 26, 39, 9, 9, 3, 19, 25, 856 24, 46, 19, 20, 19, 20, 20, 20, 20, 15, 857 19, 24, 47, 26, 46, 43, 20, 19, 47, 46 858}; 859 860 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */ 861static const yytype_uint8 yyr1[] = 862{ 863 0, 27, 28, 28, 29, 30, 30, 31, 31, 31, 864 31, 31, 31, 31, 31, 32, 32, 32, 32, 32, 865 33, 33, 34, 34, 34, 34, 34, 35, 35, 35, 866 35, 36, 36, 36, 36, 36, 36, 36, 36, 36, 867 37, 37, 37, 38, 38, 38, 38, 38, 38, 38, 868 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 869 38, 38, 38, 38, 39, 39, 39, 39, 39, 39, 870 40, 41, 41, 42, 42, 43, 43, 44, 45, 46, 871 46, 47, 47 872}; 873 874 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */ 875static const yytype_uint8 yyr2[] = 876{ 877 0, 2, 1, 1, 2, 0, 2, 1, 1, 1, 878 1, 1, 1, 1, 1, 2, 4, 5, 6, 7, 879 1, 2, 1, 2, 3, 1, 2, 1, 2, 2, 880 2, 3, 5, 3, 3, 3, 2, 4, 2, 3, 881 2, 1, 1, 2, 2, 1, 2, 2, 1, 2, 882 2, 1, 2, 2, 1, 2, 2, 1, 2, 2, 883 2, 2, 1, 1, 2, 2, 2, 2, 2, 2, 884 1, 1, 1, 1, 1, 1, 1, 1, 2, 0, 885 2, 0, 1 886}; 887 888 889#define yyerrok (yyerrstatus = 0) 890#define yyclearin (yychar = YYEMPTY) 891#define YYEMPTY (-2) 892#define YYEOF 0 893 894#define YYACCEPT goto yyacceptlab 895#define YYABORT goto yyabortlab 896#define YYERROR goto yyerrorlab 897 898 899/* Like YYERROR except do call yyerror. This remains here temporarily 900 to ease the transition to the new meaning of YYERROR, for GCC. 901 Once GCC version 2 has supplanted version 1, this can go. However, 902 YYFAIL appears to be in use. Nevertheless, it is formally deprecated 903 in Bison 2.4.2's NEWS entry, where a plan to phase it out is 904 discussed. */ 905 906#define YYFAIL goto yyerrlab 907#if defined YYFAIL 908 /* This is here to suppress warnings from the GCC cpp's 909 -Wunused-macros. Normally we don't worry about that warning, but 910 some users do, and we want to make it easy for users to remove 911 YYFAIL uses, which will produce warnings from Bison 2.5. */ 912#endif 913 914#define YYRECOVERING() (!!yyerrstatus) 915 916#define YYBACKUP(Token, Value) \ 917do \ 918 if (yychar == YYEMPTY && yylen == 1) \ 919 { \ 920 yychar = (Token); \ 921 yylval = (Value); \ 922 YYPOPSTACK (1); \ 923 goto yybackup; \ 924 } \ 925 else \ 926 { \ 927 yyerror (pc, YY_("syntax error: cannot back up")); \ 928 YYERROR; \ 929 } \ 930while (YYID (0)) 931 932 933#define YYTERROR 1 934#define YYERRCODE 256 935 936 937/* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N]. 938 If N is 0, then set CURRENT to the empty location which ends 939 the previous symbol: RHS[0] (always defined). */ 940 941#define YYRHSLOC(Rhs, K) ((Rhs)[K]) 942#ifndef YYLLOC_DEFAULT 943# define YYLLOC_DEFAULT(Current, Rhs, N) \ 944 do \ 945 if (YYID (N)) \ 946 { \ 947 (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \ 948 (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \ 949 (Current).last_line = YYRHSLOC (Rhs, N).last_line; \ 950 (Current).last_column = YYRHSLOC (Rhs, N).last_column; \ 951 } \ 952 else \ 953 { \ 954 (Current).first_line = (Current).last_line = \ 955 YYRHSLOC (Rhs, 0).last_line; \ 956 (Current).first_column = (Current).last_column = \ 957 YYRHSLOC (Rhs, 0).last_column; \ 958 } \ 959 while (YYID (0)) 960#endif 961 962 963/* This macro is provided for backward compatibility. */ 964 965#ifndef YY_LOCATION_PRINT 966# define YY_LOCATION_PRINT(File, Loc) ((void) 0) 967#endif 968 969 970/* YYLEX -- calling `yylex' with the right arguments. */ 971 972#ifdef YYLEX_PARAM 973# define YYLEX yylex (&yylval, YYLEX_PARAM) 974#else 975# define YYLEX yylex (&yylval, pc) 976#endif 977 978/* Enable debugging if requested. */ 979#if YYDEBUG 980 981# ifndef YYFPRINTF 982# include <stdio.h> /* INFRINGES ON USER NAME SPACE */ 983# define YYFPRINTF fprintf 984# endif 985 986# define YYDPRINTF(Args) \ 987do { \ 988 if (yydebug) \ 989 YYFPRINTF Args; \ 990} while (YYID (0)) 991 992# define YY_SYMBOL_PRINT(Title, Type, Value, Location) \ 993do { \ 994 if (yydebug) \ 995 { \ 996 YYFPRINTF (stderr, "%s ", Title); \ 997 yy_symbol_print (stderr, \ 998 Type, Value, pc); \ 999 YYFPRINTF (stderr, "\n"); \ 1000 } \ 1001} while (YYID (0)) 1002 1003 1004/*--------------------------------. 1005| Print this symbol on YYOUTPUT. | 1006`--------------------------------*/ 1007 1008/*ARGSUSED*/ 1009#if (defined __STDC__ || defined __C99__FUNC__ \ 1010 || defined __cplusplus || defined _MSC_VER) 1011static void 1012yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, parser_control *pc) 1013#else 1014static void 1015yy_symbol_value_print (yyoutput, yytype, yyvaluep, pc) 1016 FILE *yyoutput; 1017 int yytype; 1018 YYSTYPE const * const yyvaluep; 1019 parser_control *pc; 1020#endif 1021{ 1022 if (!yyvaluep) 1023 return; 1024 YYUSE (pc); 1025# ifdef YYPRINT 1026 if (yytype < YYNTOKENS) 1027 YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep); 1028# else 1029 YYUSE (yyoutput); 1030# endif 1031 switch (yytype) 1032 { 1033 default: 1034 break; 1035 } 1036} 1037 1038 1039/*--------------------------------. 1040| Print this symbol on YYOUTPUT. | 1041`--------------------------------*/ 1042 1043#if (defined __STDC__ || defined __C99__FUNC__ \ 1044 || defined __cplusplus || defined _MSC_VER) 1045static void 1046yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, parser_control *pc) 1047#else 1048static void 1049yy_symbol_print (yyoutput, yytype, yyvaluep, pc) 1050 FILE *yyoutput; 1051 int yytype; 1052 YYSTYPE const * const yyvaluep; 1053 parser_control *pc; 1054#endif 1055{ 1056 if (yytype < YYNTOKENS) 1057 YYFPRINTF (yyoutput, "token %s (", yytname[yytype]); 1058 else 1059 YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]); 1060 1061 yy_symbol_value_print (yyoutput, yytype, yyvaluep, pc); 1062 YYFPRINTF (yyoutput, ")"); 1063} 1064 1065/*------------------------------------------------------------------. 1066| yy_stack_print -- Print the state stack from its BOTTOM up to its | 1067| TOP (included). | 1068`------------------------------------------------------------------*/ 1069 1070#if (defined __STDC__ || defined __C99__FUNC__ \ 1071 || defined __cplusplus || defined _MSC_VER) 1072static void 1073yy_stack_print (yytype_int16 *yybottom, yytype_int16 *yytop) 1074#else 1075static void 1076yy_stack_print (yybottom, yytop) 1077 yytype_int16 *yybottom; 1078 yytype_int16 *yytop; 1079#endif 1080{ 1081 YYFPRINTF (stderr, "Stack now"); 1082 for (; yybottom <= yytop; yybottom++) 1083 { 1084 int yybot = *yybottom; 1085 YYFPRINTF (stderr, " %d", yybot); 1086 } 1087 YYFPRINTF (stderr, "\n"); 1088} 1089 1090# define YY_STACK_PRINT(Bottom, Top) \ 1091do { \ 1092 if (yydebug) \ 1093 yy_stack_print ((Bottom), (Top)); \ 1094} while (YYID (0)) 1095 1096 1097/*------------------------------------------------. 1098| Report that the YYRULE is going to be reduced. | 1099`------------------------------------------------*/ 1100 1101#if (defined __STDC__ || defined __C99__FUNC__ \ 1102 || defined __cplusplus || defined _MSC_VER) 1103static void 1104yy_reduce_print (yytype_int16 *yyssp, YYSTYPE *yyvsp, int yyrule, parser_control *pc) 1105#else 1106static void 1107yy_reduce_print (yyssp, yyvsp, yyrule, pc) 1108 yytype_int16 *yyssp; 1109 YYSTYPE *yyvsp; 1110 int yyrule; 1111 parser_control *pc; 1112#endif 1113{ 1114 unsigned long int yylno = yyrline[yyrule]; 1115 int yynrhs = yyr2[yyrule]; 1116 int yyi; 1117 YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n", 1118 yyrule - 1, yylno); 1119 /* The symbols being reduced. */ 1120 for (yyi = 0; yyi < yynrhs; yyi++) 1121 { 1122 YYFPRINTF (stderr, " $%d = ", yyi + 1); 1123 yy_symbol_print (stderr, 1124 yystos[yyssp[yyi + 1 - yynrhs]], 1125 &(yyvsp[(yyi + 1) - (yynrhs)]) 1126 , pc); 1127 YYFPRINTF (stderr, "\n"); 1128 } 1129} 1130 1131# define YY_REDUCE_PRINT(Rule) \ 1132do { \ 1133 if (yydebug) \ 1134 yy_reduce_print (yyssp, yyvsp, Rule, pc); \ 1135} while (YYID (0)) 1136 1137/* Nonzero means print parse trace. It is left uninitialized so that 1138 multiple parsers can coexist. */ 1139int yydebug; 1140#else /* !YYDEBUG */ 1141# define YYDPRINTF(Args) 1142# define YY_SYMBOL_PRINT(Title, Type, Value, Location) 1143# define YY_STACK_PRINT(Bottom, Top) 1144# define YY_REDUCE_PRINT(Rule) 1145#endif /* !YYDEBUG */ 1146 1147 1148/* YYINITDEPTH -- initial size of the parser's stacks. */ 1149#ifndef YYINITDEPTH 1150# define YYINITDEPTH 200 1151#endif 1152 1153/* YYMAXDEPTH -- maximum size the stacks can grow to (effective only 1154 if the built-in stack extension method is used). 1155 1156 Do not make this value too large; the results are undefined if 1157 YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH) 1158 evaluated with infinite-precision integer arithmetic. */ 1159 1160#ifndef YYMAXDEPTH 1161# define YYMAXDEPTH 10000 1162#endif 1163 1164 1165 1166#if YYERROR_VERBOSE 1167 1168# ifndef yystrlen 1169# if defined __GLIBC__ && defined _STRING_H 1170# define yystrlen strlen 1171# else 1172/* Return the length of YYSTR. */ 1173#if (defined __STDC__ || defined __C99__FUNC__ \ 1174 || defined __cplusplus || defined _MSC_VER) 1175static YYSIZE_T 1176yystrlen (const char *yystr) 1177#else 1178static YYSIZE_T 1179yystrlen (yystr) 1180 const char *yystr; 1181#endif 1182{ 1183 YYSIZE_T yylen; 1184 for (yylen = 0; yystr[yylen]; yylen++) 1185 continue; 1186 return yylen; 1187} 1188# endif 1189# endif 1190 1191# ifndef yystpcpy 1192# if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE 1193# define yystpcpy stpcpy 1194# else 1195/* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in 1196 YYDEST. */ 1197#if (defined __STDC__ || defined __C99__FUNC__ \ 1198 || defined __cplusplus || defined _MSC_VER) 1199static char * 1200yystpcpy (char *yydest, const char *yysrc) 1201#else 1202static char * 1203yystpcpy (yydest, yysrc) 1204 char *yydest; 1205 const char *yysrc; 1206#endif 1207{ 1208 char *yyd = yydest; 1209 const char *yys = yysrc; 1210 1211 while ((*yyd++ = *yys++) != '\0') 1212 continue; 1213 1214 return yyd - 1; 1215} 1216# endif 1217# endif 1218 1219# ifndef yytnamerr 1220/* Copy to YYRES the contents of YYSTR after stripping away unnecessary 1221 quotes and backslashes, so that it's suitable for yyerror. The 1222 heuristic is that double-quoting is unnecessary unless the string 1223 contains an apostrophe, a comma, or backslash (other than 1224 backslash-backslash). YYSTR is taken from yytname. If YYRES is 1225 null, do not copy; instead, return the length of what the result 1226 would have been. */ 1227static YYSIZE_T 1228yytnamerr (char *yyres, const char *yystr) 1229{ 1230 if (*yystr == '"') 1231 { 1232 YYSIZE_T yyn = 0; 1233 char const *yyp = yystr; 1234 1235 for (;;) 1236 switch (*++yyp) 1237 { 1238 case '\'': 1239 case ',': 1240 goto do_not_strip_quotes; 1241 1242 case '\\': 1243 if (*++yyp != '\\') 1244 goto do_not_strip_quotes; 1245 /* Fall through. */ 1246 default: 1247 if (yyres) 1248 yyres[yyn] = *yyp; 1249 yyn++; 1250 break; 1251 1252 case '"': 1253 if (yyres) 1254 yyres[yyn] = '\0'; 1255 return yyn; 1256 } 1257 do_not_strip_quotes: ; 1258 } 1259 1260 if (! yyres) 1261 return yystrlen (yystr); 1262 1263 return yystpcpy (yyres, yystr) - yyres; 1264} 1265# endif 1266 1267/* Copy into *YYMSG, which is of size *YYMSG_ALLOC, an error message 1268 about the unexpected token YYTOKEN while in state YYSTATE. 1269 1270 Return 0 if *YYMSG was successfully written. Return 1 if an ordinary 1271 "syntax error" message will suffice instead. Return 2 if *YYMSG is 1272 not large enough to hold the message. In the last case, also set 1273 *YYMSG_ALLOC to either (a) the required number of bytes or (b) zero 1274 if the required number of bytes is too large to store. */ 1275static int 1276yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg, 1277 int yystate, int yytoken) 1278{ 1279 int yyn = yypact[yystate]; 1280 1281 if (! (YYPACT_NINF < yyn && yyn <= YYLAST)) 1282 return 1; 1283 else 1284 { 1285 YYSIZE_T yysize0 = yytnamerr (0, yytname[yytoken]); 1286 YYSIZE_T yysize = yysize0; 1287 YYSIZE_T yysize1; 1288 enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 }; 1289 /* Internationalized format string. */ 1290 const char *yyformat = 0; 1291 /* Arguments of yyformat. */ 1292 char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM]; 1293 1294 /* Start YYX at -YYN if negative to avoid negative indexes in 1295 YYCHECK. In other words, skip the first -YYN actions for this 1296 state because they are default actions. */ 1297 int yyxbegin = yyn < 0 ? -yyn : 0; 1298 1299 /* Stay within bounds of both yycheck and yytname. */ 1300 int yychecklim = YYLAST - yyn + 1; 1301 int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS; 1302 /* Number of reported tokens (one for the "unexpected", one per 1303 "expected"). */ 1304 int yycount = 0; 1305 int yyx; 1306 1307 yyarg[yycount++] = yytname[yytoken]; 1308 1309 for (yyx = yyxbegin; yyx < yyxend; ++yyx) 1310 if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR 1311 && !yytable_value_is_error (yytable[yyx + yyn])) 1312 { 1313 if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM) 1314 { 1315 yycount = 1; 1316 yysize = yysize0; 1317 break; 1318 } 1319 yyarg[yycount++] = yytname[yyx]; 1320 yysize1 = yysize + yytnamerr (0, yytname[yyx]); 1321 if (! (yysize <= yysize1 1322 && yysize1 <= YYSTACK_ALLOC_MAXIMUM)) 1323 { 1324 /* Overflow. */ 1325 *yymsg_alloc = 0; 1326 return 2; 1327 } 1328 yysize = yysize1; 1329 } 1330 1331 switch (yycount) 1332 { 1333#define YYCASE_(N, S) \ 1334 case N: \ 1335 yyformat = S; \ 1336 break 1337 YYCASE_(1, YY_("syntax error, unexpected %s")); 1338 YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s")); 1339 YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s")); 1340 YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s")); 1341 YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s")); 1342#undef YYCASE_ 1343 } 1344 1345 yysize1 = yysize + yystrlen (yyformat); 1346 if (! (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM)) 1347 { 1348 /* Overflow. */ 1349 *yymsg_alloc = 0; 1350 return 2; 1351 } 1352 yysize = yysize1; 1353 1354 if (*yymsg_alloc < yysize) 1355 { 1356 *yymsg_alloc = 2 * yysize; 1357 if (! (yysize <= *yymsg_alloc 1358 && *yymsg_alloc <= YYSTACK_ALLOC_MAXIMUM)) 1359 *yymsg_alloc = YYSTACK_ALLOC_MAXIMUM; 1360 return 2; 1361 } 1362 1363 /* Avoid sprintf, as that infringes on the user's name space. 1364 Don't have undefined behavior even if the translation 1365 produced a string with the wrong number of "%s"s. */ 1366 { 1367 char *yyp = *yymsg; 1368 int yyi = 0; 1369 while ((*yyp = *yyformat) != '\0') 1370 if (*yyp == '%' && yyformat[1] == 's' && yyi < yycount) 1371 { 1372 yyp += yytnamerr (yyp, yyarg[yyi++]); 1373 yyformat += 2; 1374 } 1375 else 1376 { 1377 yyp++; 1378 yyformat++; 1379 } 1380 } 1381 return 0; 1382 } 1383} 1384#endif /* YYERROR_VERBOSE */ 1385 1386 1387/*-----------------------------------------------. 1388| Release the memory associated to this symbol. | 1389`-----------------------------------------------*/ 1390 1391/*ARGSUSED*/ 1392#if (defined __STDC__ || defined __C99__FUNC__ \ 1393 || defined __cplusplus || defined _MSC_VER) 1394static void 1395yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep, parser_control *pc) 1396#else 1397static void 1398yydestruct (yymsg, yytype, yyvaluep, pc) 1399 const char *yymsg; 1400 int yytype; 1401 YYSTYPE *yyvaluep; 1402 parser_control *pc; 1403#endif 1404{ 1405 YYUSE (yyvaluep); 1406 YYUSE (pc); 1407 1408 if (!yymsg) 1409 yymsg = "Deleting"; 1410 YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp); 1411 1412 switch (yytype) 1413 { 1414 default: 1415 break; 1416 } 1417} 1418 1419 1420/* Prevent warnings from -Wmissing-prototypes. */ 1421#ifdef YYPARSE_PARAM 1422#if (defined __STDC__ || defined __C99__FUNC__ \ 1423 || defined __cplusplus || defined _MSC_VER) 1424int yyparse (void *YYPARSE_PARAM); 1425#else 1426int yyparse (); 1427#endif 1428#else /* ! YYPARSE_PARAM */ 1429#if (defined __STDC__ || defined __C99__FUNC__ \ 1430 || defined __cplusplus || defined _MSC_VER) 1431int yyparse (parser_control *pc); 1432#else 1433int yyparse (); 1434#endif 1435#endif /* ! YYPARSE_PARAM */ 1436 1437 1438/*----------. 1439| yyparse. | 1440`----------*/ 1441 1442#ifdef YYPARSE_PARAM 1443#if (defined __STDC__ || defined __C99__FUNC__ \ 1444 || defined __cplusplus || defined _MSC_VER) 1445int 1446yyparse (void *YYPARSE_PARAM) 1447#else 1448int 1449yyparse (YYPARSE_PARAM) 1450 void *YYPARSE_PARAM; 1451#endif 1452#else /* ! YYPARSE_PARAM */ 1453#if (defined __STDC__ || defined __C99__FUNC__ \ 1454 || defined __cplusplus || defined _MSC_VER) 1455int 1456yyparse (parser_control *pc) 1457#else 1458int 1459yyparse (pc) 1460 parser_control *pc; 1461#endif 1462#endif 1463{ 1464/* The lookahead symbol. */ 1465int yychar; 1466 1467/* The semantic value of the lookahead symbol. */ 1468YYSTYPE yylval; 1469 1470 /* Number of syntax errors so far. */ 1471 int yynerrs; 1472 1473 int yystate; 1474 /* Number of tokens to shift before error messages enabled. */ 1475 int yyerrstatus; 1476 1477 /* The stacks and their tools: 1478 `yyss': related to states. 1479 `yyvs': related to semantic values. 1480 1481 Refer to the stacks thru separate pointers, to allow yyoverflow 1482 to reallocate them elsewhere. */ 1483 1484 /* The state stack. */ 1485 yytype_int16 yyssa[YYINITDEPTH]; 1486 yytype_int16 *yyss; 1487 yytype_int16 *yyssp; 1488 1489 /* The semantic value stack. */ 1490 YYSTYPE yyvsa[YYINITDEPTH]; 1491 YYSTYPE *yyvs; 1492 YYSTYPE *yyvsp; 1493 1494 YYSIZE_T yystacksize; 1495 1496 int yyn; 1497 int yyresult; 1498 /* Lookahead token as an internal (translated) token number. */ 1499 int yytoken; 1500 /* The variables used to return semantic value and location from the 1501 action routines. */ 1502 YYSTYPE yyval; 1503 1504#if YYERROR_VERBOSE 1505 /* Buffer for error messages, and its allocated size. */ 1506 char yymsgbuf[128]; 1507 char *yymsg = yymsgbuf; 1508 YYSIZE_T yymsg_alloc = sizeof yymsgbuf; 1509#endif 1510 1511#define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N)) 1512 1513 /* The number of symbols on the RHS of the reduced rule. 1514 Keep to zero when no symbol should be popped. */ 1515 int yylen = 0; 1516 1517 yytoken = 0; 1518 yyss = yyssa; 1519 yyvs = yyvsa; 1520 yystacksize = YYINITDEPTH; 1521 1522 YYDPRINTF ((stderr, "Starting parse\n")); 1523 1524 yystate = 0; 1525 yyerrstatus = 0; 1526 yynerrs = 0; 1527 yychar = YYEMPTY; /* Cause a token to be read. */ 1528 1529 /* Initialize stack pointers. 1530 Waste one element of value and location stack 1531 so that they stay on the same level as the state stack. 1532 The wasted elements are never initialized. */ 1533 yyssp = yyss; 1534 yyvsp = yyvs; 1535 1536 goto yysetstate; 1537 1538/*------------------------------------------------------------. 1539| yynewstate -- Push a new state, which is found in yystate. | 1540`------------------------------------------------------------*/ 1541 yynewstate: 1542 /* In all cases, when you get here, the value and location stacks 1543 have just been pushed. So pushing a state here evens the stacks. */ 1544 yyssp++; 1545 1546 yysetstate: 1547 *yyssp = yystate; 1548 1549 if (yyss + yystacksize - 1 <= yyssp) 1550 { 1551 /* Get the current used size of the three stacks, in elements. */ 1552 YYSIZE_T yysize = yyssp - yyss + 1; 1553 1554#ifdef yyoverflow 1555 { 1556 /* Give user a chance to reallocate the stack. Use copies of 1557 these so that the &'s don't force the real ones into 1558 memory. */ 1559 YYSTYPE *yyvs1 = yyvs; 1560 yytype_int16 *yyss1 = yyss; 1561 1562 /* Each stack pointer address is followed by the size of the 1563 data in use in that stack, in bytes. This used to be a 1564 conditional around just the two extra args, but that might 1565 be undefined if yyoverflow is a macro. */ 1566 yyoverflow (YY_("memory exhausted"), 1567 &yyss1, yysize * sizeof (*yyssp), 1568 &yyvs1, yysize * sizeof (*yyvsp), 1569 &yystacksize); 1570 1571 yyss = yyss1; 1572 yyvs = yyvs1; 1573 } 1574#else /* no yyoverflow */ 1575# ifndef YYSTACK_RELOCATE 1576 goto yyexhaustedlab; 1577# else 1578 /* Extend the stack our own way. */ 1579 if (YYMAXDEPTH <= yystacksize) 1580 goto yyexhaustedlab; 1581 yystacksize *= 2; 1582 if (YYMAXDEPTH < yystacksize) 1583 yystacksize = YYMAXDEPTH; 1584 1585 { 1586 yytype_int16 *yyss1 = yyss; 1587 union yyalloc *yyptr = 1588 (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize)); 1589 if (! yyptr) 1590 goto yyexhaustedlab; 1591 YYSTACK_RELOCATE (yyss_alloc, yyss); 1592 YYSTACK_RELOCATE (yyvs_alloc, yyvs); 1593# undef YYSTACK_RELOCATE 1594 if (yyss1 != yyssa) 1595 YYSTACK_FREE (yyss1); 1596 } 1597# endif 1598#endif /* no yyoverflow */ 1599 1600 yyssp = yyss + yysize - 1; 1601 yyvsp = yyvs + yysize - 1; 1602 1603 YYDPRINTF ((stderr, "Stack size increased to %lu\n", 1604 (unsigned long int) yystacksize)); 1605 1606 if (yyss + yystacksize - 1 <= yyssp) 1607 YYABORT; 1608 } 1609 1610 YYDPRINTF ((stderr, "Entering state %d\n", yystate)); 1611 1612 if (yystate == YYFINAL) 1613 YYACCEPT; 1614 1615 goto yybackup; 1616 1617/*-----------. 1618| yybackup. | 1619`-----------*/ 1620yybackup: 1621 1622 /* Do appropriate processing given the current state. Read a 1623 lookahead token if we need one and don't already have one. */ 1624 1625 /* First try to decide what to do without reference to lookahead token. */ 1626 yyn = yypact[yystate]; 1627 if (yypact_value_is_default (yyn)) 1628 goto yydefault; 1629 1630 /* Not known => get a lookahead token if don't already have one. */ 1631 1632 /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol. */ 1633 if (yychar == YYEMPTY) 1634 { 1635 YYDPRINTF ((stderr, "Reading a token: ")); 1636 yychar = YYLEX; 1637 } 1638 1639 if (yychar <= YYEOF) 1640 { 1641 yychar = yytoken = YYEOF; 1642 YYDPRINTF ((stderr, "Now at end of input.\n")); 1643 } 1644 else 1645 { 1646 yytoken = YYTRANSLATE (yychar); 1647 YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc); 1648 } 1649 1650 /* If the proper action on seeing token YYTOKEN is to reduce or to 1651 detect an error, take that action. */ 1652 yyn += yytoken; 1653 if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken) 1654 goto yydefault; 1655 yyn = yytable[yyn]; 1656 if (yyn <= 0) 1657 { 1658 if (yytable_value_is_error (yyn)) 1659 goto yyerrlab; 1660 yyn = -yyn; 1661 goto yyreduce; 1662 } 1663 1664 /* Count tokens shifted since error; after three, turn off error 1665 status. */ 1666 if (yyerrstatus) 1667 yyerrstatus--; 1668 1669 /* Shift the lookahead token. */ 1670 YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc); 1671 1672 /* Discard the shifted token. */ 1673 yychar = YYEMPTY; 1674 1675 yystate = yyn; 1676 *++yyvsp = yylval; 1677 1678 goto yynewstate; 1679 1680 1681/*-----------------------------------------------------------. 1682| yydefault -- do the default action for the current state. | 1683`-----------------------------------------------------------*/ 1684yydefault: 1685 yyn = yydefact[yystate]; 1686 if (yyn == 0) 1687 goto yyerrlab; 1688 goto yyreduce; 1689 1690 1691/*-----------------------------. 1692| yyreduce -- Do a reduction. | 1693`-----------------------------*/ 1694yyreduce: 1695 /* yyn is the number of a rule to reduce with. */ 1696 yylen = yyr2[yyn]; 1697 1698 /* If YYLEN is nonzero, implement the default value of the action: 1699 `$$ = $1'. 1700 1701 Otherwise, the following line sets YYVAL to garbage. 1702 This behavior is undocumented and Bison 1703 users should not rely upon it. Assigning to YYVAL 1704 unconditionally makes the parser a bit smaller, and it avoids a 1705 GCC warning that YYVAL may be used uninitialized. */ 1706 yyval = yyvsp[1-yylen]; 1707 1708 1709 YY_REDUCE_PRINT (yyn); 1710 switch (yyn) 1711 { 1712 case 4: 1713/* Line 1428 of yacc.c */ 1714#line 317 "getdate.y" 1715 { 1716 pc->seconds = (yyvsp[0].timespec); 1717 pc->timespec_seen = true; 1718 } 1719/* Line 1428 of yacc.c */ 1720#line 1721 "getdate.c" 1721 break; 1722 1723 case 7: 1724/* Line 1428 of yacc.c */ 1725#line 330 "getdate.y" 1726 { pc->times_seen++; } 1727/* Line 1428 of yacc.c */ 1728#line 1729 "getdate.c" 1729 break; 1730 1731 case 8: 1732/* Line 1428 of yacc.c */ 1733#line 332 "getdate.y" 1734 { pc->local_zones_seen++; } 1735/* Line 1428 of yacc.c */ 1736#line 1737 "getdate.c" 1737 break; 1738 1739 case 9: 1740/* Line 1428 of yacc.c */ 1741#line 334 "getdate.y" 1742 { pc->zones_seen++; } 1743/* Line 1428 of yacc.c */ 1744#line 1745 "getdate.c" 1745 break; 1746 1747 case 10: 1748/* Line 1428 of yacc.c */ 1749#line 336 "getdate.y" 1750 { pc->dates_seen++; } 1751/* Line 1428 of yacc.c */ 1752#line 1753 "getdate.c" 1753 break; 1754 1755 case 11: 1756/* Line 1428 of yacc.c */ 1757#line 338 "getdate.y" 1758 { pc->days_seen++; } 1759/* Line 1428 of yacc.c */ 1760#line 1761 "getdate.c" 1761 break; 1762 1763 case 15: 1764/* Line 1428 of yacc.c */ 1765#line 346 "getdate.y" 1766 { 1767 set_hhmmss (pc, (yyvsp[-1].textintval).value, 0, 0, 0); 1768 pc->meridian = (yyvsp[0].intval); 1769 } 1770/* Line 1428 of yacc.c */ 1771#line 1772 "getdate.c" 1772 break; 1773 1774 case 16: 1775/* Line 1428 of yacc.c */ 1776#line 351 "getdate.y" 1777 { 1778 set_hhmmss (pc, (yyvsp[-3].textintval).value, (yyvsp[-1].textintval).value, 0, 0); 1779 pc->meridian = (yyvsp[0].intval); 1780 } 1781/* Line 1428 of yacc.c */ 1782#line 1783 "getdate.c" 1783 break; 1784 1785 case 17: 1786/* Line 1428 of yacc.c */ 1787#line 356 "getdate.y" 1788 { 1789 set_hhmmss (pc, (yyvsp[-4].textintval).value, (yyvsp[-2].textintval).value, 0, 0); 1790 pc->meridian = MER24; 1791 pc->zones_seen++; 1792 pc->time_zone = time_zone_hhmm (pc, (yyvsp[-1].textintval), (yyvsp[0].intval)); 1793 } 1794/* Line 1428 of yacc.c */ 1795#line 1796 "getdate.c" 1796 break; 1797 1798 case 18: 1799/* Line 1428 of yacc.c */ 1800#line 363 "getdate.y" 1801 { 1802 set_hhmmss (pc, (yyvsp[-5].textintval).value, (yyvsp[-3].textintval).value, (yyvsp[-1].timespec).tv_sec, (yyvsp[-1].timespec).tv_nsec); 1803 pc->meridian = (yyvsp[0].intval); 1804 } 1805/* Line 1428 of yacc.c */ 1806#line 1807 "getdate.c" 1807 break; 1808 1809 case 19: 1810/* Line 1428 of yacc.c */ 1811#line 368 "getdate.y" 1812 { 1813 set_hhmmss (pc, (yyvsp[-6].textintval).value, (yyvsp[-4].textintval).value, (yyvsp[-2].timespec).tv_sec, (yyvsp[-2].timespec).tv_nsec); 1814 pc->meridian = MER24; 1815 pc->zones_seen++; 1816 pc->time_zone = time_zone_hhmm (pc, (yyvsp[-1].textintval), (yyvsp[0].intval)); 1817 } 1818/* Line 1428 of yacc.c */ 1819#line 1820 "getdate.c" 1820 break; 1821 1822 case 20: 1823/* Line 1428 of yacc.c */ 1824#line 378 "getdate.y" 1825 { 1826 pc->local_isdst = (yyvsp[0].intval); 1827 pc->dsts_seen += (0 < (yyvsp[0].intval)); 1828 } 1829/* Line 1428 of yacc.c */ 1830#line 1831 "getdate.c" 1831 break; 1832 1833 case 21: 1834/* Line 1428 of yacc.c */ 1835#line 383 "getdate.y" 1836 { 1837 pc->local_isdst = 1; 1838 pc->dsts_seen += (0 < (yyvsp[-1].intval)) + 1; 1839 } 1840/* Line 1428 of yacc.c */ 1841#line 1842 "getdate.c" 1842 break; 1843 1844 case 22: 1845/* Line 1428 of yacc.c */ 1846#line 391 "getdate.y" 1847 { pc->time_zone = (yyvsp[0].intval); } 1848/* Line 1428 of yacc.c */ 1849#line 1850 "getdate.c" 1850 break; 1851 1852 case 23: 1853/* Line 1428 of yacc.c */ 1854#line 393 "getdate.y" 1855 { pc->time_zone = (yyvsp[-1].intval); 1856 apply_relative_time (pc, (yyvsp[0].rel), 1); } 1857/* Line 1428 of yacc.c */ 1858#line 1859 "getdate.c" 1859 break; 1860 1861 case 24: 1862/* Line 1428 of yacc.c */ 1863#line 396 "getdate.y" 1864 { pc->time_zone = (yyvsp[-2].intval) + time_zone_hhmm (pc, (yyvsp[-1].textintval), (yyvsp[0].intval)); } 1865/* Line 1428 of yacc.c */ 1866#line 1867 "getdate.c" 1867 break; 1868 1869 case 25: 1870/* Line 1428 of yacc.c */ 1871#line 398 "getdate.y" 1872 { pc->time_zone = (yyvsp[0].intval) + 60; } 1873/* Line 1428 of yacc.c */ 1874#line 1875 "getdate.c" 1875 break; 1876 1877 case 26: 1878/* Line 1428 of yacc.c */ 1879#line 400 "getdate.y" 1880 { pc->time_zone = (yyvsp[-1].intval) + 60; } 1881/* Line 1428 of yacc.c */ 1882#line 1883 "getdate.c" 1883 break; 1884 1885 case 27: 1886/* Line 1428 of yacc.c */ 1887#line 405 "getdate.y" 1888 { 1889 pc->day_ordinal = 0; 1890 pc->day_number = (yyvsp[0].intval); 1891 } 1892/* Line 1428 of yacc.c */ 1893#line 1894 "getdate.c" 1894 break; 1895 1896 case 28: 1897/* Line 1428 of yacc.c */ 1898#line 410 "getdate.y" 1899 { 1900 pc->day_ordinal = 0; 1901 pc->day_number = (yyvsp[-1].intval); 1902 } 1903/* Line 1428 of yacc.c */ 1904#line 1905 "getdate.c" 1905 break; 1906 1907 case 29: 1908/* Line 1428 of yacc.c */ 1909#line 415 "getdate.y" 1910 { 1911 pc->day_ordinal = (yyvsp[-1].intval); 1912 pc->day_number = (yyvsp[0].intval); 1913 } 1914/* Line 1428 of yacc.c */ 1915#line 1916 "getdate.c" 1916 break; 1917 1918 case 30: 1919/* Line 1428 of yacc.c */ 1920#line 420 "getdate.y" 1921 { 1922 pc->day_ordinal = (yyvsp[-1].textintval).value; 1923 pc->day_number = (yyvsp[0].intval); 1924 } 1925/* Line 1428 of yacc.c */ 1926#line 1927 "getdate.c" 1927 break; 1928 1929 case 31: 1930/* Line 1428 of yacc.c */ 1931#line 428 "getdate.y" 1932 { 1933 pc->month = (yyvsp[-2].textintval).value; 1934 pc->day = (yyvsp[0].textintval).value; 1935 } 1936/* Line 1428 of yacc.c */ 1937#line 1938 "getdate.c" 1938 break; 1939 1940 case 32: 1941/* Line 1428 of yacc.c */ 1942#line 433 "getdate.y" 1943 { 1944 /* Interpret as YYYY/MM/DD if the first value has 4 or more digits, 1945 otherwise as MM/DD/YY. 1946 The goal in recognizing YYYY/MM/DD is solely to support legacy 1947 machine-generated dates like those in an RCS log listing. If 1948 you want portability, use the ISO 8601 format. */ 1949 if (4 <= (yyvsp[-4].textintval).digits) 1950 { 1951 pc->year = (yyvsp[-4].textintval); 1952 pc->month = (yyvsp[-2].textintval).value; 1953 pc->day = (yyvsp[0].textintval).value; 1954 } 1955 else 1956 { 1957 pc->month = (yyvsp[-4].textintval).value; 1958 pc->day = (yyvsp[-2].textintval).value; 1959 pc->year = (yyvsp[0].textintval); 1960 } 1961 } 1962/* Line 1428 of yacc.c */ 1963#line 1964 "getdate.c" 1964 break; 1965 1966 case 33: 1967/* Line 1428 of yacc.c */ 1968#line 453 "getdate.y" 1969 { 1970 /* ISO 8601 format. YYYY-MM-DD. */ 1971 pc->year = (yyvsp[-2].textintval); 1972 pc->month = -(yyvsp[-1].textintval).value; 1973 pc->day = -(yyvsp[0].textintval).value; 1974 } 1975/* Line 1428 of yacc.c */ 1976#line 1977 "getdate.c" 1977 break; 1978 1979 case 34: 1980/* Line 1428 of yacc.c */ 1981#line 460 "getdate.y" 1982 { 1983 /* e.g. 17-JUN-1992. */ 1984 pc->day = (yyvsp[-2].textintval).value; 1985 pc->month = (yyvsp[-1].intval); 1986 pc->year.value = -(yyvsp[0].textintval).value; 1987 pc->year.digits = (yyvsp[0].textintval).digits; 1988 } 1989/* Line 1428 of yacc.c */ 1990#line 1991 "getdate.c" 1991 break; 1992 1993 case 35: 1994/* Line 1428 of yacc.c */ 1995#line 468 "getdate.y" 1996 { 1997 /* e.g. JUN-17-1992. */ 1998 pc->month = (yyvsp[-2].intval); 1999 pc->day = -(yyvsp[-1].textintval).value; 2000 pc->year.value = -(yyvsp[0].textintval).value; 2001 pc->year.digits = (yyvsp[0].textintval).digits; 2002 } 2003/* Line 1428 of yacc.c */ 2004#line 2005 "getdate.c" 2005 break; 2006 2007 case 36: 2008/* Line 1428 of yacc.c */ 2009#line 476 "getdate.y" 2010 { 2011 pc->month = (yyvsp[-1].intval); 2012 pc->day = (yyvsp[0].textintval).value; 2013 } 2014/* Line 1428 of yacc.c */ 2015#line 2016 "getdate.c" 2016 break; 2017 2018 case 37: 2019/* Line 1428 of yacc.c */ 2020#line 481 "getdate.y" 2021 { 2022 pc->month = (yyvsp[-3].intval); 2023 pc->day = (yyvsp[-2].textintval).value; 2024 pc->year = (yyvsp[0].textintval); 2025 } 2026/* Line 1428 of yacc.c */ 2027#line 2028 "getdate.c" 2028 break; 2029 2030 case 38: 2031/* Line 1428 of yacc.c */ 2032#line 487 "getdate.y" 2033 { 2034 pc->day = (yyvsp[-1].textintval).value; 2035 pc->month = (yyvsp[0].intval); 2036 } 2037/* Line 1428 of yacc.c */ 2038#line 2039 "getdate.c" 2039 break; 2040 2041 case 39: 2042/* Line 1428 of yacc.c */ 2043#line 492 "getdate.y" 2044 { 2045 pc->day = (yyvsp[-2].textintval).value; 2046 pc->month = (yyvsp[-1].intval); 2047 pc->year = (yyvsp[0].textintval); 2048 } 2049/* Line 1428 of yacc.c */ 2050#line 2051 "getdate.c" 2051 break; 2052 2053 case 40: 2054/* Line 1428 of yacc.c */ 2055#line 501 "getdate.y" 2056 { apply_relative_time (pc, (yyvsp[-1].rel), -1); } 2057/* Line 1428 of yacc.c */ 2058#line 2059 "getdate.c" 2059 break; 2060 2061 case 41: 2062/* Line 1428 of yacc.c */ 2063#line 503 "getdate.y" 2064 { apply_relative_time (pc, (yyvsp[0].rel), 1); } 2065/* Line 1428 of yacc.c */ 2066#line 2067 "getdate.c" 2067 break; 2068 2069 case 42: 2070/* Line 1428 of yacc.c */ 2071#line 505 "getdate.y" 2072 { apply_relative_time (pc, (yyvsp[0].rel), 1); } 2073/* Line 1428 of yacc.c */ 2074#line 2075 "getdate.c" 2075 break; 2076 2077 case 43: 2078/* Line 1428 of yacc.c */ 2079#line 510 "getdate.y" 2080 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).year = (yyvsp[-1].intval); } 2081/* Line 1428 of yacc.c */ 2082#line 2083 "getdate.c" 2083 break; 2084 2085 case 44: 2086/* Line 1428 of yacc.c */ 2087#line 512 "getdate.y" 2088 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).year = (yyvsp[-1].textintval).value; } 2089/* Line 1428 of yacc.c */ 2090#line 2091 "getdate.c" 2091 break; 2092 2093 case 45: 2094/* Line 1428 of yacc.c */ 2095#line 514 "getdate.y" 2096 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).year = 1; } 2097/* Line 1428 of yacc.c */ 2098#line 2099 "getdate.c" 2099 break; 2100 2101 case 46: 2102/* Line 1428 of yacc.c */ 2103#line 516 "getdate.y" 2104 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).month = (yyvsp[-1].intval); } 2105/* Line 1428 of yacc.c */ 2106#line 2107 "getdate.c" 2107 break; 2108 2109 case 47: 2110/* Line 1428 of yacc.c */ 2111#line 518 "getdate.y" 2112 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).month = (yyvsp[-1].textintval).value; } 2113/* Line 1428 of yacc.c */ 2114#line 2115 "getdate.c" 2115 break; 2116 2117 case 48: 2118/* Line 1428 of yacc.c */ 2119#line 520 "getdate.y" 2120 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).month = 1; } 2121/* Line 1428 of yacc.c */ 2122#line 2123 "getdate.c" 2123 break; 2124 2125 case 49: 2126/* Line 1428 of yacc.c */ 2127#line 522 "getdate.y" 2128 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).day = (yyvsp[-1].intval) * (yyvsp[0].intval); } 2129/* Line 1428 of yacc.c */ 2130#line 2131 "getdate.c" 2131 break; 2132 2133 case 50: 2134/* Line 1428 of yacc.c */ 2135#line 524 "getdate.y" 2136 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).day = (yyvsp[-1].textintval).value * (yyvsp[0].intval); } 2137/* Line 1428 of yacc.c */ 2138#line 2139 "getdate.c" 2139 break; 2140 2141 case 51: 2142/* Line 1428 of yacc.c */ 2143#line 526 "getdate.y" 2144 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).day = (yyvsp[0].intval); } 2145/* Line 1428 of yacc.c */ 2146#line 2147 "getdate.c" 2147 break; 2148 2149 case 52: 2150/* Line 1428 of yacc.c */ 2151#line 528 "getdate.y" 2152 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).hour = (yyvsp[-1].intval); } 2153/* Line 1428 of yacc.c */ 2154#line 2155 "getdate.c" 2155 break; 2156 2157 case 53: 2158/* Line 1428 of yacc.c */ 2159#line 530 "getdate.y" 2160 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).hour = (yyvsp[-1].textintval).value; } 2161/* Line 1428 of yacc.c */ 2162#line 2163 "getdate.c" 2163 break; 2164 2165 case 54: 2166/* Line 1428 of yacc.c */ 2167#line 532 "getdate.y" 2168 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).hour = 1; } 2169/* Line 1428 of yacc.c */ 2170#line 2171 "getdate.c" 2171 break; 2172 2173 case 55: 2174/* Line 1428 of yacc.c */ 2175#line 534 "getdate.y" 2176 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).minutes = (yyvsp[-1].intval); } 2177/* Line 1428 of yacc.c */ 2178#line 2179 "getdate.c" 2179 break; 2180 2181 case 56: 2182/* Line 1428 of yacc.c */ 2183#line 536 "getdate.y" 2184 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).minutes = (yyvsp[-1].textintval).value; } 2185/* Line 1428 of yacc.c */ 2186#line 2187 "getdate.c" 2187 break; 2188 2189 case 57: 2190/* Line 1428 of yacc.c */ 2191#line 538 "getdate.y" 2192 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).minutes = 1; } 2193/* Line 1428 of yacc.c */ 2194#line 2195 "getdate.c" 2195 break; 2196 2197 case 58: 2198/* Line 1428 of yacc.c */ 2199#line 540 "getdate.y" 2200 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).seconds = (yyvsp[-1].intval); } 2201/* Line 1428 of yacc.c */ 2202#line 2203 "getdate.c" 2203 break; 2204 2205 case 59: 2206/* Line 1428 of yacc.c */ 2207#line 542 "getdate.y" 2208 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).seconds = (yyvsp[-1].textintval).value; } 2209/* Line 1428 of yacc.c */ 2210#line 2211 "getdate.c" 2211 break; 2212 2213 case 60: 2214/* Line 1428 of yacc.c */ 2215#line 544 "getdate.y" 2216 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).seconds = (yyvsp[-1].timespec).tv_sec; (yyval.rel).ns = (yyvsp[-1].timespec).tv_nsec; } 2217/* Line 1428 of yacc.c */ 2218#line 2219 "getdate.c" 2219 break; 2220 2221 case 61: 2222/* Line 1428 of yacc.c */ 2223#line 546 "getdate.y" 2224 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).seconds = (yyvsp[-1].timespec).tv_sec; (yyval.rel).ns = (yyvsp[-1].timespec).tv_nsec; } 2225/* Line 1428 of yacc.c */ 2226#line 2227 "getdate.c" 2227 break; 2228 2229 case 62: 2230/* Line 1428 of yacc.c */ 2231#line 548 "getdate.y" 2232 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).seconds = 1; } 2233/* Line 1428 of yacc.c */ 2234#line 2235 "getdate.c" 2235 break; 2236 2237 case 64: 2238/* Line 1428 of yacc.c */ 2239#line 554 "getdate.y" 2240 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).year = (yyvsp[-1].textintval).value; } 2241/* Line 1428 of yacc.c */ 2242#line 2243 "getdate.c" 2243 break; 2244 2245 case 65: 2246/* Line 1428 of yacc.c */ 2247#line 556 "getdate.y" 2248 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).month = (yyvsp[-1].textintval).value; } 2249/* Line 1428 of yacc.c */ 2250#line 2251 "getdate.c" 2251 break; 2252 2253 case 66: 2254/* Line 1428 of yacc.c */ 2255#line 558 "getdate.y" 2256 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).day = (yyvsp[-1].textintval).value * (yyvsp[0].intval); } 2257/* Line 1428 of yacc.c */ 2258#line 2259 "getdate.c" 2259 break; 2260 2261 case 67: 2262/* Line 1428 of yacc.c */ 2263#line 560 "getdate.y" 2264 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).hour = (yyvsp[-1].textintval).value; } 2265/* Line 1428 of yacc.c */ 2266#line 2267 "getdate.c" 2267 break; 2268 2269 case 68: 2270/* Line 1428 of yacc.c */ 2271#line 562 "getdate.y" 2272 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).minutes = (yyvsp[-1].textintval).value; } 2273/* Line 1428 of yacc.c */ 2274#line 2275 "getdate.c" 2275 break; 2276 2277 case 69: 2278/* Line 1428 of yacc.c */ 2279#line 564 "getdate.y" 2280 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).seconds = (yyvsp[-1].textintval).value; } 2281/* Line 1428 of yacc.c */ 2282#line 2283 "getdate.c" 2283 break; 2284 2285 case 70: 2286/* Line 1428 of yacc.c */ 2287#line 569 "getdate.y" 2288 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).day = (yyvsp[0].intval); } 2289/* Line 1428 of yacc.c */ 2290#line 2291 "getdate.c" 2291 break; 2292 2293 case 74: 2294/* Line 1428 of yacc.c */ 2295#line 577 "getdate.y" 2296 { (yyval.timespec).tv_sec = (yyvsp[0].textintval).value; (yyval.timespec).tv_nsec = 0; } 2297/* Line 1428 of yacc.c */ 2298#line 2299 "getdate.c" 2299 break; 2300 2301 case 76: 2302/* Line 1428 of yacc.c */ 2303#line 583 "getdate.y" 2304 { (yyval.timespec).tv_sec = (yyvsp[0].textintval).value; (yyval.timespec).tv_nsec = 0; } 2305/* Line 1428 of yacc.c */ 2306#line 2307 "getdate.c" 2307 break; 2308 2309 case 77: 2310/* Line 1428 of yacc.c */ 2311#line 588 "getdate.y" 2312 { digits_to_date_time (pc, (yyvsp[0].textintval)); } 2313/* Line 1428 of yacc.c */ 2314#line 2315 "getdate.c" 2315 break; 2316 2317 case 78: 2318/* Line 1428 of yacc.c */ 2319#line 593 "getdate.y" 2320 { 2321 /* Hybrid all-digit and relative offset, so that we accept e.g., 2322 "YYYYMMDD +N days" as well as "YYYYMMDD N days". */ 2323 digits_to_date_time (pc, (yyvsp[-1].textintval)); 2324 apply_relative_time (pc, (yyvsp[0].rel), 1); 2325 } 2326/* Line 1428 of yacc.c */ 2327#line 2328 "getdate.c" 2328 break; 2329 2330 case 79: 2331/* Line 1428 of yacc.c */ 2332#line 603 "getdate.y" 2333 { (yyval.intval) = -1; } 2334/* Line 1428 of yacc.c */ 2335#line 2336 "getdate.c" 2336 break; 2337 2338 case 80: 2339/* Line 1428 of yacc.c */ 2340#line 605 "getdate.y" 2341 { (yyval.intval) = (yyvsp[0].textintval).value; } 2342/* Line 1428 of yacc.c */ 2343#line 2344 "getdate.c" 2344 break; 2345 2346 case 81: 2347/* Line 1428 of yacc.c */ 2348#line 610 "getdate.y" 2349 { (yyval.intval) = MER24; } 2350/* Line 1428 of yacc.c */ 2351#line 2352 "getdate.c" 2352 break; 2353 2354 case 82: 2355/* Line 1428 of yacc.c */ 2356#line 612 "getdate.y" 2357 { (yyval.intval) = (yyvsp[0].intval); } 2358/* Line 1428 of yacc.c */ 2359#line 2360 "getdate.c" 2360 break; 2361 2362 2363/* Line 1428 of yacc.c */ 2364#line 2365 "getdate.c" 2365 default: break; 2366 } 2367 /* User semantic actions sometimes alter yychar, and that requires 2368 that yytoken be updated with the new translation. We take the 2369 approach of translating immediately before every use of yytoken. 2370 One alternative is translating here after every semantic action, 2371 but that translation would be missed if the semantic action invokes 2372 YYABORT, YYACCEPT, or YYERROR immediately after altering yychar or 2373 if it invokes YYBACKUP. In the case of YYABORT or YYACCEPT, an 2374 incorrect destructor might then be invoked immediately. In the 2375 case of YYERROR or YYBACKUP, subsequent parser actions might lead 2376 to an incorrect destructor call or verbose syntax error message 2377 before the lookahead is translated. */ 2378 YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc); 2379 2380 YYPOPSTACK (yylen); 2381 yylen = 0; 2382 YY_STACK_PRINT (yyss, yyssp); 2383 2384 *++yyvsp = yyval; 2385 2386 /* Now `shift' the result of the reduction. Determine what state 2387 that goes to, based on the state we popped back to and the rule 2388 number reduced by. */ 2389 2390 yyn = yyr1[yyn]; 2391 2392 yystate = yypgoto[yyn - YYNTOKENS] + *yyssp; 2393 if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp) 2394 yystate = yytable[yystate]; 2395 else 2396 yystate = yydefgoto[yyn - YYNTOKENS]; 2397 2398 goto yynewstate; 2399 2400 2401/*------------------------------------. 2402| yyerrlab -- here on detecting error | 2403`------------------------------------*/ 2404yyerrlab: 2405 /* Make sure we have latest lookahead translation. See comments at 2406 user semantic actions for why this is necessary. */ 2407 yytoken = YYTRANSLATE (yychar); 2408 2409 /* If not already recovering from an error, report this error. */ 2410 if (!yyerrstatus) 2411 { 2412 ++yynerrs; 2413#if ! YYERROR_VERBOSE 2414 yyerror (pc, YY_("syntax error")); 2415#else 2416 while (1) 2417 { 2418 int yysyntax_error_status = 2419 yysyntax_error (&yymsg_alloc, &yymsg, yystate, yytoken); 2420 if (yysyntax_error_status == 2 && 0 < yymsg_alloc) 2421 { 2422 if (yymsg != yymsgbuf) 2423 YYSTACK_FREE (yymsg); 2424 yymsg = (char *) YYSTACK_ALLOC (yymsg_alloc); 2425 if (yymsg) 2426 continue; 2427 yymsg = yymsgbuf; 2428 yymsg_alloc = sizeof yymsgbuf; 2429 } 2430 if (yysyntax_error_status == 0) 2431 yyerror (pc, yymsg); 2432 else 2433 yyerror (pc, YY_("syntax error")); 2434 if (yysyntax_error_status == 2) 2435 goto yyexhaustedlab; 2436 break; 2437 } 2438#endif 2439 } 2440 2441 2442 2443 if (yyerrstatus == 3) 2444 { 2445 /* If just tried and failed to reuse lookahead token after an 2446 error, discard it. */ 2447 2448 if (yychar <= YYEOF) 2449 { 2450 /* Return failure if at end of input. */ 2451 if (yychar == YYEOF) 2452 YYABORT; 2453 } 2454 else 2455 { 2456 yydestruct ("Error: discarding", 2457 yytoken, &yylval, pc); 2458 yychar = YYEMPTY; 2459 } 2460 } 2461 2462 /* Else will try to reuse lookahead token after shifting the error 2463 token. */ 2464 goto yyerrlab1; 2465 2466 2467/*---------------------------------------------------. 2468| yyerrorlab -- error raised explicitly by YYERROR. | 2469`---------------------------------------------------*/ 2470yyerrorlab: 2471 2472 /* Pacify compilers like GCC when the user code never invokes 2473 YYERROR and the label yyerrorlab therefore never appears in user 2474 code. */ 2475 if (/*CONSTCOND*/ 0) 2476 goto yyerrorlab; 2477 2478 /* Do not reclaim the symbols of the rule which action triggered 2479 this YYERROR. */ 2480 YYPOPSTACK (yylen); 2481 yylen = 0; 2482 YY_STACK_PRINT (yyss, yyssp); 2483 yystate = *yyssp; 2484 goto yyerrlab1; 2485 2486 2487/*-------------------------------------------------------------. 2488| yyerrlab1 -- common code for both syntax error and YYERROR. | 2489`-------------------------------------------------------------*/ 2490yyerrlab1: 2491 yyerrstatus = 3; /* Each real token shifted decrements this. */ 2492 2493 for (;;) 2494 { 2495 yyn = yypact[yystate]; 2496 if (!yypact_value_is_default (yyn)) 2497 { 2498 yyn += YYTERROR; 2499 if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR) 2500 { 2501 yyn = yytable[yyn]; 2502 if (0 < yyn) 2503 break; 2504 } 2505 } 2506 2507 /* Pop the current state because it cannot handle the error token. */ 2508 if (yyssp == yyss) 2509 YYABORT; 2510 2511 2512 yydestruct ("Error: popping", 2513 yystos[yystate], yyvsp, pc); 2514 YYPOPSTACK (1); 2515 yystate = *yyssp; 2516 YY_STACK_PRINT (yyss, yyssp); 2517 } 2518 2519 *++yyvsp = yylval; 2520 2521 2522 /* Shift the error token. */ 2523 YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp); 2524 2525 yystate = yyn; 2526 goto yynewstate; 2527 2528 2529/*-------------------------------------. 2530| yyacceptlab -- YYACCEPT comes here. | 2531`-------------------------------------*/ 2532yyacceptlab: 2533 yyresult = 0; 2534 goto yyreturn; 2535 2536/*-----------------------------------. 2537| yyabortlab -- YYABORT comes here. | 2538`-----------------------------------*/ 2539yyabortlab: 2540 yyresult = 1; 2541 goto yyreturn; 2542 2543#if !defined(yyoverflow) || YYERROR_VERBOSE 2544/*-------------------------------------------------. 2545| yyexhaustedlab -- memory exhaustion comes here. | 2546`-------------------------------------------------*/ 2547yyexhaustedlab: 2548 yyerror (pc, YY_("memory exhausted")); 2549 yyresult = 2; 2550 /* Fall through. */ 2551#endif 2552 2553yyreturn: 2554 if (yychar != YYEMPTY) 2555 { 2556 /* Make sure we have latest lookahead translation. See comments at 2557 user semantic actions for why this is necessary. */ 2558 yytoken = YYTRANSLATE (yychar); 2559 yydestruct ("Cleanup: discarding lookahead", 2560 yytoken, &yylval, pc); 2561 } 2562 /* Do not reclaim the symbols of the rule which action triggered 2563 this YYABORT or YYACCEPT. */ 2564 YYPOPSTACK (yylen); 2565 YY_STACK_PRINT (yyss, yyssp); 2566 while (yyssp != yyss) 2567 { 2568 yydestruct ("Cleanup: popping", 2569 yystos[*yyssp], yyvsp, pc); 2570 YYPOPSTACK (1); 2571 } 2572#ifndef yyoverflow 2573 if (yyss != yyssa) 2574 YYSTACK_FREE (yyss); 2575#endif 2576#if YYERROR_VERBOSE 2577 if (yymsg != yymsgbuf) 2578 YYSTACK_FREE (yymsg); 2579#endif 2580 /* Make sure YYID is used. */ 2581 return YYID (yyresult); 2582} 2583 2584/* Line 1658 of yacc.c */ 2585#line 615 "getdate.y" 2586 2587 2588static table const meridian_table[] = 2589{ 2590 { "AM", tMERIDIAN, MERam }, 2591 { "A.M.", tMERIDIAN, MERam }, 2592 { "PM", tMERIDIAN, MERpm }, 2593 { "P.M.", tMERIDIAN, MERpm }, 2594 { NULL, 0, 0 } 2595}; 2596 2597static table const dst_table[] = 2598{ 2599 { "DST", tDST, 0 } 2600}; 2601 2602static table const month_and_day_table[] = 2603{ 2604 { "JANUARY", tMONTH, 1 }, 2605 { "FEBRUARY", tMONTH, 2 }, 2606 { "MARCH", tMONTH, 3 }, 2607 { "APRIL", tMONTH, 4 }, 2608 { "MAY", tMONTH, 5 }, 2609 { "JUNE", tMONTH, 6 }, 2610 { "JULY", tMONTH, 7 }, 2611 { "AUGUST", tMONTH, 8 }, 2612 { "SEPTEMBER",tMONTH, 9 }, 2613 { "SEPT", tMONTH, 9 }, 2614 { "OCTOBER", tMONTH, 10 }, 2615 { "NOVEMBER", tMONTH, 11 }, 2616 { "DECEMBER", tMONTH, 12 }, 2617 { "SUNDAY", tDAY, 0 }, 2618 { "MONDAY", tDAY, 1 }, 2619 { "TUESDAY", tDAY, 2 }, 2620 { "TUES", tDAY, 2 }, 2621 { "WEDNESDAY",tDAY, 3 }, 2622 { "WEDNES", tDAY, 3 }, 2623 { "THURSDAY", tDAY, 4 }, 2624 { "THUR", tDAY, 4 }, 2625 { "THURS", tDAY, 4 }, 2626 { "FRIDAY", tDAY, 5 }, 2627 { "SATURDAY", tDAY, 6 }, 2628 { NULL, 0, 0 } 2629}; 2630 2631static table const time_units_table[] = 2632{ 2633 { "YEAR", tYEAR_UNIT, 1 }, 2634 { "MONTH", tMONTH_UNIT, 1 }, 2635 { "FORTNIGHT",tDAY_UNIT, 14 }, 2636 { "WEEK", tDAY_UNIT, 7 }, 2637 { "DAY", tDAY_UNIT, 1 }, 2638 { "HOUR", tHOUR_UNIT, 1 }, 2639 { "MINUTE", tMINUTE_UNIT, 1 }, 2640 { "MIN", tMINUTE_UNIT, 1 }, 2641 { "SECOND", tSEC_UNIT, 1 }, 2642 { "SEC", tSEC_UNIT, 1 }, 2643 { NULL, 0, 0 } 2644}; 2645 2646/* Assorted relative-time words. */ 2647static table const relative_time_table[] = 2648{ 2649 { "TOMORROW", tDAY_SHIFT, 1 }, 2650 { "YESTERDAY",tDAY_SHIFT, -1 }, 2651 { "TODAY", tDAY_SHIFT, 0 }, 2652 { "NOW", tDAY_SHIFT, 0 }, 2653 { "LAST", tORDINAL, -1 }, 2654 { "THIS", tORDINAL, 0 }, 2655 { "NEXT", tORDINAL, 1 }, 2656 { "FIRST", tORDINAL, 1 }, 2657/*{ "SECOND", tORDINAL, 2 }, */ 2658 { "THIRD", tORDINAL, 3 }, 2659 { "FOURTH", tORDINAL, 4 }, 2660 { "FIFTH", tORDINAL, 5 }, 2661 { "SIXTH", tORDINAL, 6 }, 2662 { "SEVENTH", tORDINAL, 7 }, 2663 { "EIGHTH", tORDINAL, 8 }, 2664 { "NINTH", tORDINAL, 9 }, 2665 { "TENTH", tORDINAL, 10 }, 2666 { "ELEVENTH", tORDINAL, 11 }, 2667 { "TWELFTH", tORDINAL, 12 }, 2668 { "AGO", tAGO, 1 }, 2669 { NULL, 0, 0 } 2670}; 2671 2672/* The universal time zone table. These labels can be used even for 2673 time stamps that would not otherwise be valid, e.g., GMT time 2674 stamps in London during summer. */ 2675static table const universal_time_zone_table[] = 2676{ 2677 { "GMT", tZONE, HOUR ( 0) }, /* Greenwich Mean */ 2678 { "UT", tZONE, HOUR ( 0) }, /* Universal (Coordinated) */ 2679 { "UTC", tZONE, HOUR ( 0) }, 2680 { NULL, 0, 0 } 2681}; 2682 2683/* The time zone table. This table is necessarily incomplete, as time 2684 zone abbreviations are ambiguous; e.g. Australians interpret "EST" 2685 as Eastern time in Australia, not as US Eastern Standard Time. 2686 You cannot rely on getdate to handle arbitrary time zone 2687 abbreviations; use numeric abbreviations like `-0500' instead. */ 2688static table const time_zone_table[] = 2689{ 2690 { "WET", tZONE, HOUR ( 0) }, /* Western European */ 2691 { "WEST", tDAYZONE, HOUR ( 0) }, /* Western European Summer */ 2692 { "BST", tDAYZONE, HOUR ( 0) }, /* British Summer */ 2693 { "ART", tZONE, -HOUR ( 3) }, /* Argentina */ 2694 { "BRT", tZONE, -HOUR ( 3) }, /* Brazil */ 2695 { "BRST", tDAYZONE, -HOUR ( 3) }, /* Brazil Summer */ 2696 { "NST", tZONE, -(HOUR ( 3) + 30) }, /* Newfoundland Standard */ 2697 { "NDT", tDAYZONE,-(HOUR ( 3) + 30) }, /* Newfoundland Daylight */ 2698 { "AST", tZONE, -HOUR ( 4) }, /* Atlantic Standard */ 2699 { "ADT", tDAYZONE, -HOUR ( 4) }, /* Atlantic Daylight */ 2700 { "CLT", tZONE, -HOUR ( 4) }, /* Chile */ 2701 { "CLST", tDAYZONE, -HOUR ( 4) }, /* Chile Summer */ 2702 { "EST", tZONE, -HOUR ( 5) }, /* Eastern Standard */ 2703 { "EDT", tDAYZONE, -HOUR ( 5) }, /* Eastern Daylight */ 2704 { "CST", tZONE, -HOUR ( 6) }, /* Central Standard */ 2705 { "CDT", tDAYZONE, -HOUR ( 6) }, /* Central Daylight */ 2706 { "MST", tZONE, -HOUR ( 7) }, /* Mountain Standard */ 2707 { "MDT", tDAYZONE, -HOUR ( 7) }, /* Mountain Daylight */ 2708 { "PST", tZONE, -HOUR ( 8) }, /* Pacific Standard */ 2709 { "PDT", tDAYZONE, -HOUR ( 8) }, /* Pacific Daylight */ 2710 { "AKST", tZONE, -HOUR ( 9) }, /* Alaska Standard */ 2711 { "AKDT", tDAYZONE, -HOUR ( 9) }, /* Alaska Daylight */ 2712 { "HST", tZONE, -HOUR (10) }, /* Hawaii Standard */ 2713 { "HAST", tZONE, -HOUR (10) }, /* Hawaii-Aleutian Standard */ 2714 { "HADT", tDAYZONE, -HOUR (10) }, /* Hawaii-Aleutian Daylight */ 2715 { "SST", tZONE, -HOUR (12) }, /* Samoa Standard */ 2716 { "WAT", tZONE, HOUR ( 1) }, /* West Africa */ 2717 { "CET", tZONE, HOUR ( 1) }, /* Central European */ 2718 { "CEST", tDAYZONE, HOUR ( 1) }, /* Central European Summer */ 2719 { "MET", tZONE, HOUR ( 1) }, /* Middle European */ 2720 { "MEZ", tZONE, HOUR ( 1) }, /* Middle European */ 2721 { "MEST", tDAYZONE, HOUR ( 1) }, /* Middle European Summer */ 2722 { "MESZ", tDAYZONE, HOUR ( 1) }, /* Middle European Summer */ 2723 { "EET", tZONE, HOUR ( 2) }, /* Eastern European */ 2724 { "EEST", tDAYZONE, HOUR ( 2) }, /* Eastern European Summer */ 2725 { "CAT", tZONE, HOUR ( 2) }, /* Central Africa */ 2726 { "SAST", tZONE, HOUR ( 2) }, /* South Africa Standard */ 2727 { "EAT", tZONE, HOUR ( 3) }, /* East Africa */ 2728 { "MSK", tZONE, HOUR ( 3) }, /* Moscow */ 2729 { "MSD", tDAYZONE, HOUR ( 3) }, /* Moscow Daylight */ 2730 { "IST", tZONE, (HOUR ( 5) + 30) }, /* India Standard */ 2731 { "SGT", tZONE, HOUR ( 8) }, /* Singapore */ 2732 { "KST", tZONE, HOUR ( 9) }, /* Korea Standard */ 2733 { "JST", tZONE, HOUR ( 9) }, /* Japan Standard */ 2734 { "GST", tZONE, HOUR (10) }, /* Guam Standard */ 2735 { "NZST", tZONE, HOUR (12) }, /* New Zealand Standard */ 2736 { "NZDT", tDAYZONE, HOUR (12) }, /* New Zealand Daylight */ 2737 { NULL, 0, 0 } 2738}; 2739 2740/* Military time zone table. */ 2741static table const military_table[] = 2742{ 2743 { "A", tZONE, -HOUR ( 1) }, 2744 { "B", tZONE, -HOUR ( 2) }, 2745 { "C", tZONE, -HOUR ( 3) }, 2746 { "D", tZONE, -HOUR ( 4) }, 2747 { "E", tZONE, -HOUR ( 5) }, 2748 { "F", tZONE, -HOUR ( 6) }, 2749 { "G", tZONE, -HOUR ( 7) }, 2750 { "H", tZONE, -HOUR ( 8) }, 2751 { "I", tZONE, -HOUR ( 9) }, 2752 { "K", tZONE, -HOUR (10) }, 2753 { "L", tZONE, -HOUR (11) }, 2754 { "M", tZONE, -HOUR (12) }, 2755 { "N", tZONE, HOUR ( 1) }, 2756 { "O", tZONE, HOUR ( 2) }, 2757 { "P", tZONE, HOUR ( 3) }, 2758 { "Q", tZONE, HOUR ( 4) }, 2759 { "R", tZONE, HOUR ( 5) }, 2760 { "S", tZONE, HOUR ( 6) }, 2761 { "T", tZONE, HOUR ( 7) }, 2762 { "U", tZONE, HOUR ( 8) }, 2763 { "V", tZONE, HOUR ( 9) }, 2764 { "W", tZONE, HOUR (10) }, 2765 { "X", tZONE, HOUR (11) }, 2766 { "Y", tZONE, HOUR (12) }, 2767 { "Z", tZONE, HOUR ( 0) }, 2768 { NULL, 0, 0 } 2769}; 2770 2771 2772 2773/* Convert a time zone expressed as HH:MM into an integer count of 2774 minutes. If MM is negative, then S is of the form HHMM and needs 2775 to be picked apart; otherwise, S is of the form HH. As specified in 2776 http://www.opengroup.org/susv3xbd/xbd_chap08.html#tag_08_03, allow 2777 only valid TZ range, and consider first two digits as hours, if no 2778 minutes specified. */ 2779 2780static long int 2781time_zone_hhmm (parser_control *pc, textint s, long int mm) 2782{ 2783 long int n_minutes; 2784 2785 /* If the length of S is 1 or 2 and no minutes are specified, 2786 interpret it as a number of hours. */ 2787 if (s.digits <= 2 && mm < 0) 2788 s.value *= 100; 2789 2790 if (mm < 0) 2791 n_minutes = (s.value / 100) * 60 + s.value % 100; 2792 else 2793 n_minutes = s.value * 60 + (s.negative ? -mm : mm); 2794 2795 /* If the absolute number of minutes is larger than 24 hours, 2796 arrange to reject it by incrementing pc->zones_seen. Thus, 2797 we allow only values in the range UTC-24:00 to UTC+24:00. */ 2798 if (24 * 60 < abs (n_minutes)) 2799 pc->zones_seen++; 2800 2801 return n_minutes; 2802} 2803 2804static int 2805to_hour (long int hours, int meridian) 2806{ 2807 switch (meridian) 2808 { 2809 default: /* Pacify GCC. */ 2810 case MER24: 2811 return 0 <= hours && hours < 24 ? hours : -1; 2812 case MERam: 2813 return 0 < hours && hours < 12 ? hours : hours == 12 ? 0 : -1; 2814 case MERpm: 2815 return 0 < hours && hours < 12 ? hours + 12 : hours == 12 ? 12 : -1; 2816 } 2817} 2818 2819static long int 2820to_year (textint textyear) 2821{ 2822 long int year = textyear.value; 2823 2824 if (year < 0) 2825 year = -year; 2826 2827 /* XPG4 suggests that years 00-68 map to 2000-2068, and 2828 years 69-99 map to 1969-1999. */ 2829 else if (textyear.digits == 2) 2830 year += year < 69 ? 2000 : 1900; 2831 2832 return year; 2833} 2834 2835static table const * 2836lookup_zone (parser_control const *pc, char const *name) 2837{ 2838 table const *tp; 2839 2840 for (tp = universal_time_zone_table; tp->name; tp++) 2841 if (strcmp (name, tp->name) == 0) 2842 return tp; 2843 2844 /* Try local zone abbreviations before those in time_zone_table, as 2845 the local ones are more likely to be right. */ 2846 for (tp = pc->local_time_zone_table; tp->name; tp++) 2847 if (strcmp (name, tp->name) == 0) 2848 return tp; 2849 2850 for (tp = time_zone_table; tp->name; tp++) 2851 if (strcmp (name, tp->name) == 0) 2852 return tp; 2853 2854 return NULL; 2855} 2856 2857#if ! HAVE_TM_GMTOFF 2858/* Yield the difference between *A and *B, 2859 measured in seconds, ignoring leap seconds. 2860 The body of this function is taken directly from the GNU C Library; 2861 see src/strftime.c. */ 2862static long int 2863tm_diff (struct tm const *a, struct tm const *b) 2864{ 2865 /* Compute intervening leap days correctly even if year is negative. 2866 Take care to avoid int overflow in leap day calculations. */ 2867 int a4 = SHR (a->tm_year, 2) + SHR (TM_YEAR_BASE, 2) - ! (a->tm_year & 3); 2868 int b4 = SHR (b->tm_year, 2) + SHR (TM_YEAR_BASE, 2) - ! (b->tm_year & 3); 2869 int a100 = a4 / 25 - (a4 % 25 < 0); 2870 int b100 = b4 / 25 - (b4 % 25 < 0); 2871 int a400 = SHR (a100, 2); 2872 int b400 = SHR (b100, 2); 2873 int intervening_leap_days = (a4 - b4) - (a100 - b100) + (a400 - b400); 2874 long int ayear = a->tm_year; 2875 long int years = ayear - b->tm_year; 2876 long int days = (365 * years + intervening_leap_days 2877 + (a->tm_yday - b->tm_yday)); 2878 return (60 * (60 * (24 * days + (a->tm_hour - b->tm_hour)) 2879 + (a->tm_min - b->tm_min)) 2880 + (a->tm_sec - b->tm_sec)); 2881} 2882#endif /* ! HAVE_TM_GMTOFF */ 2883 2884static table const * 2885lookup_word (parser_control const *pc, char *word) 2886{ 2887 char *p; 2888 char *q; 2889 size_t wordlen; 2890 table const *tp; 2891 bool period_found; 2892 bool abbrev; 2893 2894 /* Make it uppercase. */ 2895 for (p = word; *p; p++) 2896 { 2897 unsigned char ch = *p; 2898 *p = c_toupper (ch); 2899 } 2900 2901 for (tp = meridian_table; tp->name; tp++) 2902 if (strcmp (word, tp->name) == 0) 2903 return tp; 2904 2905 /* See if we have an abbreviation for a month. */ 2906 wordlen = strlen (word); 2907 abbrev = wordlen == 3 || (wordlen == 4 && word[3] == '.'); 2908 2909 for (tp = month_and_day_table; tp->name; tp++) 2910 if ((abbrev ? strncmp (word, tp->name, 3) : strcmp (word, tp->name)) == 0) 2911 return tp; 2912 2913 if ((tp = lookup_zone (pc, word))) 2914 return tp; 2915 2916 if (strcmp (word, dst_table[0].name) == 0) 2917 return dst_table; 2918 2919 for (tp = time_units_table; tp->name; tp++) 2920 if (strcmp (word, tp->name) == 0) 2921 return tp; 2922 2923 /* Strip off any plural and try the units table again. */ 2924 if (word[wordlen - 1] == 'S') 2925 { 2926 word[wordlen - 1] = '\0'; 2927 for (tp = time_units_table; tp->name; tp++) 2928 if (strcmp (word, tp->name) == 0) 2929 return tp; 2930 word[wordlen - 1] = 'S'; /* For "this" in relative_time_table. */ 2931 } 2932 2933 for (tp = relative_time_table; tp->name; tp++) 2934 if (strcmp (word, tp->name) == 0) 2935 return tp; 2936 2937 /* Military time zones. */ 2938 if (wordlen == 1) 2939 for (tp = military_table; tp->name; tp++) 2940 if (word[0] == tp->name[0]) 2941 return tp; 2942 2943 /* Drop out any periods and try the time zone table again. */ 2944 for (period_found = false, p = q = word; (*p = *q); q++) 2945 if (*q == '.') 2946 period_found = true; 2947 else 2948 p++; 2949 if (period_found && (tp = lookup_zone (pc, word))) 2950 return tp; 2951 2952 return NULL; 2953} 2954 2955static int 2956yylex (YYSTYPE *lvalp, parser_control *pc) 2957{ 2958 unsigned char c; 2959 size_t count; 2960 2961 for (;;) 2962 { 2963 while (c = *pc->input, c_isspace (c)) 2964 pc->input++; 2965 2966 if (ISDIGIT (c) || c == '-' || c == '+') 2967 { 2968 char const *p; 2969 int sign; 2970 unsigned long int value; 2971 if (c == '-' || c == '+') 2972 { 2973 sign = c == '-' ? -1 : 1; 2974 while (c = *++pc->input, c_isspace (c)) 2975 continue; 2976 if (! ISDIGIT (c)) 2977 /* skip the '-' sign */ 2978 continue; 2979 } 2980 else 2981 sign = 0; 2982 p = pc->input; 2983 for (value = 0; ; value *= 10) 2984 { 2985 unsigned long int value1 = value + (c - '0'); 2986 if (value1 < value) 2987 return '?'; 2988 value = value1; 2989 c = *++p; 2990 if (! ISDIGIT (c)) 2991 break; 2992 if (ULONG_MAX / 10 < value) 2993 return '?'; 2994 } 2995 if ((c == '.' || c == ',') && ISDIGIT (p[1])) 2996 { 2997 time_t s; 2998 int ns; 2999 int digits; 3000 unsigned long int value1; 3001 3002 /* Check for overflow when converting value to time_t. */ 3003 if (sign < 0) 3004 { 3005 s = - value; 3006 if (0 < s) 3007 return '?'; 3008 value1 = -s; 3009 } 3010 else 3011 { 3012 s = value; 3013 if (s < 0) 3014 return '?'; 3015 value1 = s; 3016 } 3017 if (value != value1) 3018 return '?'; 3019 3020 /* Accumulate fraction, to ns precision. */ 3021 p++; 3022 ns = *p++ - '0'; 3023 for (digits = 2; digits <= LOG10_BILLION; digits++) 3024 { 3025 ns *= 10; 3026 if (ISDIGIT (*p)) 3027 ns += *p++ - '0'; 3028 } 3029 3030 /* Skip excess digits, truncating toward -Infinity. */ 3031 if (sign < 0) 3032 for (; ISDIGIT (*p); p++) 3033 if (*p != '0') 3034 { 3035 ns++; 3036 break; 3037 } 3038 while (ISDIGIT (*p)) 3039 p++; 3040 3041 /* Adjust to the timespec convention, which is that 3042 tv_nsec is always a positive offset even if tv_sec is 3043 negative. */ 3044 if (sign < 0 && ns) 3045 { 3046 s--; 3047 if (! (s < 0)) 3048 return '?'; 3049 ns = BILLION - ns; 3050 } 3051 3052 lvalp->timespec.tv_sec = s; 3053 lvalp->timespec.tv_nsec = ns; 3054 pc->input = p; 3055 return sign ? tSDECIMAL_NUMBER : tUDECIMAL_NUMBER; 3056 } 3057 else 3058 { 3059 lvalp->textintval.negative = sign < 0; 3060 if (sign < 0) 3061 { 3062 lvalp->textintval.value = - value; 3063 if (0 < lvalp->textintval.value) 3064 return '?'; 3065 } 3066 else 3067 { 3068 lvalp->textintval.value = value; 3069 if (lvalp->textintval.value < 0) 3070 return '?'; 3071 } 3072 lvalp->textintval.digits = p - pc->input; 3073 pc->input = p; 3074 return sign ? tSNUMBER : tUNUMBER; 3075 } 3076 } 3077 3078 if (c_isalpha (c)) 3079 { 3080 char buff[20]; 3081 char *p = buff; 3082 table const *tp; 3083 3084 do 3085 { 3086 if (p < buff + sizeof buff - 1) 3087 *p++ = c; 3088 c = *++pc->input; 3089 } 3090 while (c_isalpha (c) || c == '.'); 3091 3092 *p = '\0'; 3093 tp = lookup_word (pc, buff); 3094 if (! tp) 3095 return '?'; 3096 lvalp->intval = tp->value; 3097 return tp->type; 3098 } 3099 3100 if (c != '(') 3101 return *pc->input++; 3102 count = 0; 3103 do 3104 { 3105 c = *pc->input++; 3106 if (c == '\0') 3107 return c; 3108 if (c == '(') 3109 count++; 3110 else if (c == ')') 3111 count--; 3112 } 3113 while (count != 0); 3114 } 3115} 3116 3117/* Do nothing if the parser reports an error. */ 3118static int 3119yyerror (parser_control const *pc _GL_UNUSED, 3120 char const *s _GL_UNUSED) 3121{ 3122 return 0; 3123} 3124 3125/* If *TM0 is the old and *TM1 is the new value of a struct tm after 3126 passing it to mktime, return true if it's OK that mktime returned T. 3127 It's not OK if *TM0 has out-of-range members. */ 3128 3129static bool 3130mktime_ok (struct tm const *tm0, struct tm const *tm1, time_t t) 3131{ 3132 if (t == (time_t) -1) 3133 { 3134 /* Guard against falsely reporting an error when parsing a time 3135 stamp that happens to equal (time_t) -1, on a host that 3136 supports such a time stamp. */ 3137 tm1 = localtime (&t); 3138 if (!tm1) 3139 return false; 3140 } 3141 3142 return ! ((tm0->tm_sec ^ tm1->tm_sec) 3143 | (tm0->tm_min ^ tm1->tm_min) 3144 | (tm0->tm_hour ^ tm1->tm_hour) 3145 | (tm0->tm_mday ^ tm1->tm_mday) 3146 | (tm0->tm_mon ^ tm1->tm_mon) 3147 | (tm0->tm_year ^ tm1->tm_year)); 3148} 3149 3150/* A reasonable upper bound for the size of ordinary TZ strings. 3151 Use heap allocation if TZ's length exceeds this. */ 3152enum { TZBUFSIZE = 100 }; 3153 3154/* Return a copy of TZ, stored in TZBUF if it fits, and heap-allocated 3155 otherwise. */ 3156static char * 3157get_tz (char tzbuf[TZBUFSIZE]) 3158{ 3159 char *tz = getenv ("TZ"); 3160 if (tz) 3161 { 3162 size_t tzsize = strlen (tz) + 1; 3163 tz = (tzsize <= TZBUFSIZE 3164 ? memcpy (tzbuf, tz, tzsize) 3165 : xmemdup (tz, tzsize)); 3166 } 3167 return tz; 3168} 3169 3170/* Parse a date/time string, storing the resulting time value into *RESULT. 3171 The string itself is pointed to by P. Return true if successful. 3172 P can be an incomplete or relative time specification; if so, use 3173 *NOW as the basis for the returned time. */ 3174bool 3175get_date (struct timespec *result, char const *p, struct timespec const *now) 3176{ 3177 time_t Start; 3178 long int Start_ns; 3179 struct tm const *tmp; 3180 struct tm tm; 3181 struct tm tm0; 3182 parser_control pc; 3183 struct timespec gettime_buffer; 3184 unsigned char c; 3185 bool tz_was_altered = false; 3186 char *tz0 = NULL; 3187 char tz0buf[TZBUFSIZE]; 3188 bool ok = true; 3189 3190 if (! now) 3191 { 3192 gettime (&gettime_buffer); 3193 now = &gettime_buffer; 3194 } 3195 3196 Start = now->tv_sec; 3197 Start_ns = now->tv_nsec; 3198 3199 tmp = localtime (&now->tv_sec); 3200 if (! tmp) 3201 return false; 3202 3203 while (c = *p, c_isspace (c)) 3204 p++; 3205 3206 if (strncmp (p, "TZ=\"", 4) == 0) 3207 { 3208 char const *tzbase = p + 4; 3209 size_t tzsize = 1; 3210 char const *s; 3211 3212 for (s = tzbase; *s; s++, tzsize++) 3213 if (*s == '\\') 3214 { 3215 s++; 3216 if (! (*s == '\\' || *s == '"')) 3217 break; 3218 } 3219 else if (*s == '"') 3220 { 3221 char *z; 3222 char *tz1; 3223 char tz1buf[TZBUFSIZE]; 3224 bool large_tz = TZBUFSIZE < tzsize; 3225 bool setenv_ok; 3226 tz0 = get_tz (tz0buf); 3227 z = tz1 = large_tz ? xmalloc (tzsize) : tz1buf; 3228 for (s = tzbase; *s != '"'; s++) 3229 *z++ = *(s += *s == '\\'); 3230 *z = '\0'; 3231 setenv_ok = setenv ("TZ", tz1, 1) == 0; 3232 if (large_tz) 3233 free (tz1); 3234 if (!setenv_ok) 3235 goto fail; 3236 tz_was_altered = true; 3237 p = s + 1; 3238 } 3239 } 3240 3241 /* As documented, be careful to treat the empty string just like 3242 a date string of "0". Without this, an empty string would be 3243 declared invalid when parsed during a DST transition. */ 3244 if (*p == '\0') 3245 p = "0"; 3246 3247 pc.input = p; 3248 pc.year.value = tmp->tm_year; 3249 pc.year.value += TM_YEAR_BASE; 3250 pc.year.digits = 0; 3251 pc.month = tmp->tm_mon + 1; 3252 pc.day = tmp->tm_mday; 3253 pc.hour = tmp->tm_hour; 3254 pc.minutes = tmp->tm_min; 3255 pc.seconds.tv_sec = tmp->tm_sec; 3256 pc.seconds.tv_nsec = Start_ns; 3257 tm.tm_isdst = tmp->tm_isdst; 3258 3259 pc.meridian = MER24; 3260 pc.rel = RELATIVE_TIME_0; 3261 pc.timespec_seen = false; 3262 pc.rels_seen = false; 3263 pc.dates_seen = 0; 3264 pc.days_seen = 0; 3265 pc.times_seen = 0; 3266 pc.local_zones_seen = 0; 3267 pc.dsts_seen = 0; 3268 pc.zones_seen = 0; 3269 3270#if HAVE_STRUCT_TM_TM_ZONE 3271 pc.local_time_zone_table[0].name = tmp->tm_zone; 3272 pc.local_time_zone_table[0].type = tLOCAL_ZONE; 3273 pc.local_time_zone_table[0].value = tmp->tm_isdst; 3274 pc.local_time_zone_table[1].name = NULL; 3275 3276 /* Probe the names used in the next three calendar quarters, looking 3277 for a tm_isdst different from the one we already have. */ 3278 { 3279 int quarter; 3280 for (quarter = 1; quarter <= 3; quarter++) 3281 { 3282 time_t probe = Start + quarter * (90 * 24 * 60 * 60); 3283 struct tm const *probe_tm = localtime (&probe); 3284 if (probe_tm && probe_tm->tm_zone 3285 && probe_tm->tm_isdst != pc.local_time_zone_table[0].value) 3286 { 3287 { 3288 pc.local_time_zone_table[1].name = probe_tm->tm_zone; 3289 pc.local_time_zone_table[1].type = tLOCAL_ZONE; 3290 pc.local_time_zone_table[1].value = probe_tm->tm_isdst; 3291 pc.local_time_zone_table[2].name = NULL; 3292 } 3293 break; 3294 } 3295 } 3296 } 3297#else 3298#if HAVE_TZNAME 3299 { 3300# if !HAVE_DECL_TZNAME 3301 extern char *tzname[]; 3302# endif 3303 int i; 3304 for (i = 0; i < 2; i++) 3305 { 3306 pc.local_time_zone_table[i].name = tzname[i]; 3307 pc.local_time_zone_table[i].type = tLOCAL_ZONE; 3308 pc.local_time_zone_table[i].value = i; 3309 } 3310 pc.local_time_zone_table[i].name = NULL; 3311 } 3312#else 3313 pc.local_time_zone_table[0].name = NULL; 3314#endif 3315#endif 3316 3317 if (pc.local_time_zone_table[0].name && pc.local_time_zone_table[1].name 3318 && ! strcmp (pc.local_time_zone_table[0].name, 3319 pc.local_time_zone_table[1].name)) 3320 { 3321 /* This locale uses the same abbrevation for standard and 3322 daylight times. So if we see that abbreviation, we don't 3323 know whether it's daylight time. */ 3324 pc.local_time_zone_table[0].value = -1; 3325 pc.local_time_zone_table[1].name = NULL; 3326 } 3327 3328 if (yyparse (&pc) != 0) 3329 goto fail; 3330 3331 if (pc.timespec_seen) 3332 *result = pc.seconds; 3333 else 3334 { 3335 if (1 < (pc.times_seen | pc.dates_seen | pc.days_seen | pc.dsts_seen 3336 | (pc.local_zones_seen + pc.zones_seen))) 3337 goto fail; 3338 3339 tm.tm_year = to_year (pc.year) - TM_YEAR_BASE; 3340 tm.tm_mon = pc.month - 1; 3341 tm.tm_mday = pc.day; 3342 if (pc.times_seen || (pc.rels_seen && ! pc.dates_seen && ! pc.days_seen)) 3343 { 3344 tm.tm_hour = to_hour (pc.hour, pc.meridian); 3345 if (tm.tm_hour < 0) 3346 goto fail; 3347 tm.tm_min = pc.minutes; 3348 tm.tm_sec = pc.seconds.tv_sec; 3349 } 3350 else 3351 { 3352 tm.tm_hour = tm.tm_min = tm.tm_sec = 0; 3353 pc.seconds.tv_nsec = 0; 3354 } 3355 3356 /* Let mktime deduce tm_isdst if we have an absolute time stamp. */ 3357 if (pc.dates_seen | pc.days_seen | pc.times_seen) 3358 tm.tm_isdst = -1; 3359 3360 /* But if the input explicitly specifies local time with or without 3361 DST, give mktime that information. */ 3362 if (pc.local_zones_seen) 3363 tm.tm_isdst = pc.local_isdst; 3364 3365 tm0 = tm; 3366 3367 Start = mktime (&tm); 3368 3369 if (! mktime_ok (&tm0, &tm, Start)) 3370 { 3371 if (! pc.zones_seen) 3372 goto fail; 3373 else 3374 { 3375 /* Guard against falsely reporting errors near the time_t 3376 boundaries when parsing times in other time zones. For 3377 example, suppose the input string "1969-12-31 23:00:00 -0100", 3378 the current time zone is 8 hours ahead of UTC, and the min 3379 time_t value is 1970-01-01 00:00:00 UTC. Then the min 3380 localtime value is 1970-01-01 08:00:00, and mktime will 3381 therefore fail on 1969-12-31 23:00:00. To work around the 3382 problem, set the time zone to 1 hour behind UTC temporarily 3383 by setting TZ="XXX1:00" and try mktime again. */ 3384 3385 long int time_zone = pc.time_zone; 3386 long int abs_time_zone = time_zone < 0 ? - time_zone : time_zone; 3387 long int abs_time_zone_hour = abs_time_zone / 60; 3388 int abs_time_zone_min = abs_time_zone % 60; 3389 char tz1buf[sizeof "XXX+0:00" 3390 + sizeof pc.time_zone * CHAR_BIT / 3]; 3391 if (!tz_was_altered) 3392 tz0 = get_tz (tz0buf); 3393 sprintf (tz1buf, "XXX%s%ld:%02d", "-" + (time_zone < 0), 3394 abs_time_zone_hour, abs_time_zone_min); 3395 if (setenv ("TZ", tz1buf, 1) != 0) 3396 goto fail; 3397 tz_was_altered = true; 3398 tm = tm0; 3399 Start = mktime (&tm); 3400 if (! mktime_ok (&tm0, &tm, Start)) 3401 goto fail; 3402 } 3403 } 3404 3405 if (pc.days_seen && ! pc.dates_seen) 3406 { 3407 tm.tm_mday += ((pc.day_number - tm.tm_wday + 7) % 7 3408 + 7 * (pc.day_ordinal 3409 - (0 < pc.day_ordinal 3410 && tm.tm_wday != pc.day_number))); 3411 tm.tm_isdst = -1; 3412 Start = mktime (&tm); 3413 if (Start == (time_t) -1) 3414 goto fail; 3415 } 3416 3417 /* Add relative date. */ 3418 if (pc.rel.year | pc.rel.month | pc.rel.day) 3419 { 3420 int year = tm.tm_year + pc.rel.year; 3421 int month = tm.tm_mon + pc.rel.month; 3422 int day = tm.tm_mday + pc.rel.day; 3423 if (((year < tm.tm_year) ^ (pc.rel.year < 0)) 3424 | ((month < tm.tm_mon) ^ (pc.rel.month < 0)) 3425 | ((day < tm.tm_mday) ^ (pc.rel.day < 0))) 3426 goto fail; 3427 tm.tm_year = year; 3428 tm.tm_mon = month; 3429 tm.tm_mday = day; 3430 tm.tm_hour = tm0.tm_hour; 3431 tm.tm_min = tm0.tm_min; 3432 tm.tm_sec = tm0.tm_sec; 3433 tm.tm_isdst = tm0.tm_isdst; 3434 Start = mktime (&tm); 3435 if (Start == (time_t) -1) 3436 goto fail; 3437 } 3438 3439 /* The only "output" of this if-block is an updated Start value, 3440 so this block must follow others that clobber Start. */ 3441 if (pc.zones_seen) 3442 { 3443 long int delta = pc.time_zone * 60; 3444 time_t t1; 3445#ifdef HAVE_TM_GMTOFF 3446 delta -= tm.tm_gmtoff; 3447#else 3448 time_t t = Start; 3449 struct tm const *gmt = gmtime (&t); 3450 if (! gmt) 3451 goto fail; 3452 delta -= tm_diff (&tm, gmt); 3453#endif 3454 t1 = Start - delta; 3455 if ((Start < t1) != (delta < 0)) 3456 goto fail; /* time_t overflow */ 3457 Start = t1; 3458 } 3459 3460 /* Add relative hours, minutes, and seconds. On hosts that support 3461 leap seconds, ignore the possibility of leap seconds; e.g., 3462 "+ 10 minutes" adds 600 seconds, even if one of them is a 3463 leap second. Typically this is not what the user wants, but it's 3464 too hard to do it the other way, because the time zone indicator 3465 must be applied before relative times, and if mktime is applied 3466 again the time zone will be lost. */ 3467 { 3468 long int sum_ns = pc.seconds.tv_nsec + pc.rel.ns; 3469 long int normalized_ns = (sum_ns % BILLION + BILLION) % BILLION; 3470 time_t t0 = Start; 3471 long int d1 = 60 * 60 * pc.rel.hour; 3472 time_t t1 = t0 + d1; 3473 long int d2 = 60 * pc.rel.minutes; 3474 time_t t2 = t1 + d2; 3475 long_time_t d3 = pc.rel.seconds; 3476 long_time_t t3 = t2 + d3; 3477 long int d4 = (sum_ns - normalized_ns) / BILLION; 3478 long_time_t t4 = t3 + d4; 3479 time_t t5 = t4; 3480 3481 if ((d1 / (60 * 60) ^ pc.rel.hour) 3482 | (d2 / 60 ^ pc.rel.minutes) 3483 | ((t1 < t0) ^ (d1 < 0)) 3484 | ((t2 < t1) ^ (d2 < 0)) 3485 | ((t3 < t2) ^ (d3 < 0)) 3486 | ((t4 < t3) ^ (d4 < 0)) 3487 | (t5 != t4)) 3488 goto fail; 3489 3490 result->tv_sec = t5; 3491 result->tv_nsec = normalized_ns; 3492 } 3493 } 3494 3495 goto done; 3496 3497 fail: 3498 ok = false; 3499 done: 3500 if (tz_was_altered) 3501 ok &= (tz0 ? setenv ("TZ", tz0, 1) : unsetenv ("TZ")) == 0; 3502 if (tz0 != tz0buf) 3503 free (tz0); 3504 return ok; 3505} 3506 3507#if TEST 3508 3509int 3510main (int ac, char **av) 3511{ 3512 char buff[BUFSIZ]; 3513 3514 printf ("Enter date, or blank line to exit.\n\t> "); 3515 fflush (stdout); 3516 3517 buff[BUFSIZ - 1] = '\0'; 3518 while (fgets (buff, BUFSIZ - 1, stdin) && buff[0]) 3519 { 3520 struct timespec d; 3521 struct tm const *tm; 3522 if (! get_date (&d, buff, NULL)) 3523 printf ("Bad format - couldn't convert.\n"); 3524 else if (! (tm = localtime (&d.tv_sec))) 3525 { 3526 long int sec = d.tv_sec; 3527 printf ("localtime (%ld) failed\n", sec); 3528 } 3529 else 3530 { 3531 int ns = d.tv_nsec; 3532 printf ("%04ld-%02d-%02d %02d:%02d:%02d.%09d\n", 3533 tm->tm_year + 1900L, tm->tm_mon + 1, tm->tm_mday, 3534 tm->tm_hour, tm->tm_min, tm->tm_sec, ns); 3535 } 3536 printf ("\t> "); 3537 fflush (stdout); 3538 } 3539 return 0; 3540} 3541#endif /* TEST */ 3542