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