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