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