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