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