1 /* A Bison parser, made by GNU Bison 3.7.6. */
2
3 /* Bison implementation for Yacc-like parsers in C
4
5 Copyright (C) 1984, 1989-1990, 2000-2015, 2018-2021 Free Software Foundation,
6 Inc.
7
8 This program is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <https://www.gnu.org/licenses/>. */
20
21 /* As a special exception, you may create a larger work that contains
22 part or all of the Bison parser skeleton and distribute that work
23 under terms of your choice, so long as that work isn't itself a
24 parser generator using the skeleton or a modified version thereof
25 as a parser skeleton. Alternatively, if you modify or redistribute
26 the parser skeleton itself, you may (at your option) remove this
27 special exception, which will cause the skeleton and the resulting
28 Bison output files to be licensed under the GNU General Public
29 License without this special exception.
30
31 This special exception was added by the Free Software Foundation in
32 version 2.2 of Bison. */
33
34 /* C LALR(1) parser skeleton written by Richard Stallman, by
35 simplifying the original so-called "semantic" parser. */
36
37 /* DO NOT RELY ON FEATURES THAT ARE NOT DOCUMENTED in the manual,
38 especially those whose name start with YY_ or yy_. They are
39 private implementation details that can be changed or removed. */
40
41 /* All symbols defined below should begin with yy or YY, to avoid
42 infringing on user name space. This should be done even for local
43 variables, as they might otherwise be expanded by user macros.
44 There are some unavoidable exceptions within include files to
45 define necessary library symbols; they are noted "INFRINGES ON
46 USER NAME SPACE" below. */
47
48 /* Identify Bison output, and Bison version. */
49 #define YYBISON 30706
50
51 /* Bison version string. */
52 #define YYBISON_VERSION "3.7.6"
53
54 /* Skeleton name. */
55 #define YYSKELETON_NAME "yacc.c"
56
57 /* Pure parsers. */
58 #define YYPURE 0
59
60 /* Push parsers. */
61 #define YYPUSH 0
62
63 /* Pull parsers. */
64 #define YYPULL 1
65
66
67
68
69 /* First part of user prologue. */
70 #line 1 "getdate.y"
71
72 /*
73 ** Originally written by Steven M. Bellovin <smb@research.att.com> while
74 ** at the University of North Carolina at Chapel Hill. Later tweaked by
75 ** a couple of people on Usenet. Completely overhauled by Rich $alz
76 ** <rsalz@bbn.com> and Jim Berets <jberets@bbn.com> in August, 1990.
77 **
78 ** This code is in the public domain and has no copyright.
79 */
80
81 #include "config.h"
82
83 /* Since the code of getdate.y is not included in the Emacs executable
84 itself, there is no need to #define static in this file. Even if
85 the code were included in the Emacs executable, it probably
86 wouldn't do any harm to #undef it here; this will only cause
87 problems if we try to write to a static variable, which I don't
88 think this code needs to do. */
89 #ifdef emacs
90 # undef static
91 #endif
92
93 #include <stdio.h>
94 #include <ctype.h>
95
96 #if HAVE_STDLIB_H
97 # include <stdlib.h> /* for `free'; used by Bison 1.27 */
98 #endif
99
100 #if defined (STDC_HEADERS) || (!defined (isascii) && !defined (HAVE_ISASCII))
101 # define IN_CTYPE_DOMAIN(c) 1
102 #else
103 # define IN_CTYPE_DOMAIN(c) isascii(c)
104 #endif
105
106 #define ISSPACE(c) (IN_CTYPE_DOMAIN (c) && isspace (c))
107 #define ISALPHA(c) (IN_CTYPE_DOMAIN (c) && isalpha (c))
108 #define ISUPPER(c) (IN_CTYPE_DOMAIN (c) && isupper (c))
109 #define ISDIGIT_LOCALE(c) (IN_CTYPE_DOMAIN (c) && isdigit (c))
110
111 /* ISDIGIT differs from ISDIGIT_LOCALE, as follows:
112 - Its arg may be any int or unsigned int; it need not be an unsigned char.
113 - It's guaranteed to evaluate its argument exactly once.
114 - It's typically faster.
115 Posix 1003.2-1992 section 2.5.2.1 page 50 lines 1556-1558 says that
116 only '0' through '9' are digits. Prefer ISDIGIT to ISDIGIT_LOCALE unless
117 it's important to use the locale's definition of `digit' even when the
118 host does not conform to Posix. */
119 #define ISDIGIT(c) ((unsigned) (c) - '0' <= 9)
120
121 #if defined (STDC_HEADERS) || defined (USG)
122 # include <string.h>
123 #endif
124
125 #if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7)
126 # define __attribute__(x)
127 #endif
128
129 #ifndef ATTRIBUTE_UNUSED
130 # define ATTRIBUTE_UNUSED __attribute__ ((__unused__))
131 #endif
132
133 /* Some old versions of bison generate parsers that use bcopy.
134 That loses on systems that don't provide the function, so we have
135 to redefine it here. */
136 #if !defined (HAVE_BCOPY) && defined (HAVE_MEMCPY) && !defined (bcopy)
137 # define bcopy(from, to, len) memcpy ((to), (from), (len))
138 #endif
139
140 /* Remap normal yacc parser interface names (yyparse, yylex, yyerror, etc),
141 as well as gratuitiously global symbol names, so we can have multiple
142 yacc generated parsers in the same program. Note that these are only
143 the variables produced by yacc. If other parser generators (bison,
144 byacc, etc) produce additional global names that conflict at link time,
145 then those parser generators need to be fixed instead of adding those
146 names to this list. */
147
148 #define yymaxdepth gd_maxdepth
149 #define yyparse gd_parse
150 #define yylex gd_lex
151 #define yyerror gd_error
152 #define yylval gd_lval
153 #define yychar gd_char
154 #define yydebug gd_debug
155 #define yypact gd_pact
156 #define yyr1 gd_r1
157 #define yyr2 gd_r2
158 #define yydef gd_def
159 #define yychk gd_chk
160 #define yypgo gd_pgo
161 #define yyact gd_act
162 #define yyexca gd_exca
163 #define yyerrflag gd_errflag
164 #define yynerrs gd_nerrs
165 #define yyps gd_ps
166 #define yypv gd_pv
167 #define yys gd_s
168 #define yy_yys gd_yys
169 #define yystate gd_state
170 #define yytmp gd_tmp
171 #define yyv gd_v
172 #define yy_yyv gd_yyv
173 #define yyval gd_val
174 #define yylloc gd_lloc
175 #define yyreds gd_reds /* With YYDEBUG defined */
176 #define yytoks gd_toks /* With YYDEBUG defined */
177 #define yylhs gd_yylhs
178 #define yylen gd_yylen
179 #define yydefred gd_yydefred
180 #define yydgoto gd_yydgoto
181 #define yysindex gd_yysindex
182 #define yyrindex gd_yyrindex
183 #define yygindex gd_yygindex
184 #define yytable gd_yytable
185 #define yycheck gd_yycheck
186
187 static int yylex (void);
188 static int yyerror (char *s);
189
190 #define EPOCH 1970
191 #define HOUR(x) ((x) * 60)
192
193 #define MAX_BUFF_LEN 128 /* size of buffer to read the date into */
194
195 /*
196 ** An entry in the lexical lookup table.
197 */
198 typedef struct _TABLE {
199 const char *name;
200 int type;
201 int value;
202 } TABLE;
203
204
205 /*
206 ** Meridian: am, pm, or 24-hour style.
207 */
208 typedef enum _MERIDIAN {
209 MERam, MERpm, MER24
210 } MERIDIAN;
211
212
213 /*
214 ** Global variables. We could get rid of most of these by using a good
215 ** union as the yacc stack. (This routine was originally written before
216 ** yacc had the %union construct.) Maybe someday; right now we only use
217 ** the %union very rarely.
218 */
219 static const char *yyInput;
220 static int yyDayOrdinal;
221 static int yyDayNumber;
222 static int yyHaveDate;
223 static int yyHaveDay;
224 static int yyHaveRel;
225 static int yyHaveTime;
226 static int yyHaveZone;
227 static int yyTimezone;
228 static int yyDay;
229 static int yyHour;
230 static int yyMinutes;
231 static int yyMonth;
232 static int yySeconds;
233 static int yyYear;
234 static MERIDIAN yyMeridian;
235 static int yyRelDay;
236 static int yyRelHour;
237 static int yyRelMinutes;
238 static int yyRelMonth;
239 static int yyRelSeconds;
240 static int yyRelYear;
241
242
243 #line 244 "getdate.c"
244
245 # ifndef YY_CAST
246 # ifdef __cplusplus
247 # define YY_CAST(Type, Val) static_cast<Type> (Val)
248 # define YY_REINTERPRET_CAST(Type, Val) reinterpret_cast<Type> (Val)
249 # else
250 # define YY_CAST(Type, Val) ((Type) (Val))
251 # define YY_REINTERPRET_CAST(Type, Val) ((Type) (Val))
252 # endif
253 # endif
254 # ifndef YY_NULLPTR
255 # if defined __cplusplus
256 # if 201103L <= __cplusplus
257 # define YY_NULLPTR nullptr
258 # else
259 # define YY_NULLPTR 0
260 # endif
261 # else
262 # define YY_NULLPTR ((void*)0)
263 # endif
264 # endif
265
266
267 /* Debug traces. */
268 #ifndef YYDEBUG
269 # define YYDEBUG 0
270 #endif
271 #if YYDEBUG
272 extern int yydebug;
273 #endif
274
275 /* Token kinds. */
276 #ifndef YYTOKENTYPE
277 # define YYTOKENTYPE
278 enum yytokentype
279 {
280 YYEMPTY = -2,
281 YYEOF = 0, /* "end of file" */
282 YYerror = 256, /* error */
283 YYUNDEF = 257, /* "invalid token" */
284 tAGO = 258, /* tAGO */
285 tDAY = 259, /* tDAY */
286 tDAY_UNIT = 260, /* tDAY_UNIT */
287 tDAYZONE = 261, /* tDAYZONE */
288 tDST = 262, /* tDST */
289 tHOUR_UNIT = 263, /* tHOUR_UNIT */
290 tID = 264, /* tID */
291 tMERIDIAN = 265, /* tMERIDIAN */
292 tMINUTE_UNIT = 266, /* tMINUTE_UNIT */
293 tMONTH = 267, /* tMONTH */
294 tMONTH_UNIT = 268, /* tMONTH_UNIT */
295 tSEC_UNIT = 269, /* tSEC_UNIT */
296 tSNUMBER = 270, /* tSNUMBER */
297 tUNUMBER = 271, /* tUNUMBER */
298 tYEAR_UNIT = 272, /* tYEAR_UNIT */
299 tZONE = 273 /* tZONE */
300 };
301 typedef enum yytokentype yytoken_kind_t;
302 #endif
303
304 /* Value type. */
305 #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
306 union YYSTYPE
307 {
308 #line 177 "getdate.y"
309
310 int Number;
311 enum _MERIDIAN Meridian;
312
313 #line 314 "getdate.c"
314
315 };
316 typedef union YYSTYPE YYSTYPE;
317 # define YYSTYPE_IS_TRIVIAL 1
318 # define YYSTYPE_IS_DECLARED 1
319 #endif
320
321
322 extern YYSTYPE yylval;
323
324 int yyparse (void);
325
326
327 /* Symbol kind. */
328 enum yysymbol_kind_t
329 {
330 YYSYMBOL_YYEMPTY = -2,
331 YYSYMBOL_YYEOF = 0, /* "end of file" */
332 YYSYMBOL_YYerror = 1, /* error */
333 YYSYMBOL_YYUNDEF = 2, /* "invalid token" */
334 YYSYMBOL_tAGO = 3, /* tAGO */
335 YYSYMBOL_tDAY = 4, /* tDAY */
336 YYSYMBOL_tDAY_UNIT = 5, /* tDAY_UNIT */
337 YYSYMBOL_tDAYZONE = 6, /* tDAYZONE */
338 YYSYMBOL_tDST = 7, /* tDST */
339 YYSYMBOL_tHOUR_UNIT = 8, /* tHOUR_UNIT */
340 YYSYMBOL_tID = 9, /* tID */
341 YYSYMBOL_tMERIDIAN = 10, /* tMERIDIAN */
342 YYSYMBOL_tMINUTE_UNIT = 11, /* tMINUTE_UNIT */
343 YYSYMBOL_tMONTH = 12, /* tMONTH */
344 YYSYMBOL_tMONTH_UNIT = 13, /* tMONTH_UNIT */
345 YYSYMBOL_tSEC_UNIT = 14, /* tSEC_UNIT */
346 YYSYMBOL_tSNUMBER = 15, /* tSNUMBER */
347 YYSYMBOL_tUNUMBER = 16, /* tUNUMBER */
348 YYSYMBOL_tYEAR_UNIT = 17, /* tYEAR_UNIT */
349 YYSYMBOL_tZONE = 18, /* tZONE */
350 YYSYMBOL_19_ = 19, /* ':' */
351 YYSYMBOL_20_ = 20, /* ',' */
352 YYSYMBOL_21_ = 21, /* '/' */
353 YYSYMBOL_YYACCEPT = 22, /* $accept */
354 YYSYMBOL_spec = 23, /* spec */
355 YYSYMBOL_item = 24, /* item */
356 YYSYMBOL_time = 25, /* time */
357 YYSYMBOL_zone = 26, /* zone */
358 YYSYMBOL_day = 27, /* day */
359 YYSYMBOL_date = 28, /* date */
360 YYSYMBOL_rel = 29, /* rel */
361 YYSYMBOL_relunit = 30, /* relunit */
362 YYSYMBOL_number = 31, /* number */
363 YYSYMBOL_o_merid = 32 /* o_merid */
364 };
365 typedef enum yysymbol_kind_t yysymbol_kind_t;
366
367
368
369
370 #ifdef short
371 # undef short
372 #endif
373
374 /* On compilers that do not define __PTRDIFF_MAX__ etc., make sure
375 <limits.h> and (if available) <stdint.h> are included
376 so that the code can choose integer types of a good width. */
377
378 #ifndef __PTRDIFF_MAX__
379 # include <limits.h> /* INFRINGES ON USER NAME SPACE */
380 # if defined __STDC_VERSION__ && 199901 <= __STDC_VERSION__
381 # include <stdint.h> /* INFRINGES ON USER NAME SPACE */
382 # define YY_STDINT_H
383 # endif
384 #endif
385
386 /* Narrow types that promote to a signed type and that can represent a
387 signed or unsigned integer of at least N bits. In tables they can
388 save space and decrease cache pressure. Promoting to a signed type
389 helps avoid bugs in integer arithmetic. */
390
391 #ifdef __INT_LEAST8_MAX__
392 typedef __INT_LEAST8_TYPE__ yytype_int8;
393 #elif defined YY_STDINT_H
394 typedef int_least8_t yytype_int8;
395 #else
396 typedef signed char yytype_int8;
397 #endif
398
399 #ifdef __INT_LEAST16_MAX__
400 typedef __INT_LEAST16_TYPE__ yytype_int16;
401 #elif defined YY_STDINT_H
402 typedef int_least16_t yytype_int16;
403 #else
404 typedef short yytype_int16;
405 #endif
406
407 /* Work around bug in HP-UX 11.23, which defines these macros
408 incorrectly for preprocessor constants. This workaround can likely
409 be removed in 2023, as HPE has promised support for HP-UX 11.23
410 (aka HP-UX 11i v2) only through the end of 2022; see Table 2 of
411 <https://h20195.www2.hpe.com/V2/getpdf.aspx/4AA4-7673ENW.pdf>. */
412 #ifdef __hpux
413 # undef UINT_LEAST8_MAX
414 # undef UINT_LEAST16_MAX
415 # define UINT_LEAST8_MAX 255
416 # define UINT_LEAST16_MAX 65535
417 #endif
418
419 #if defined __UINT_LEAST8_MAX__ && __UINT_LEAST8_MAX__ <= __INT_MAX__
420 typedef __UINT_LEAST8_TYPE__ yytype_uint8;
421 #elif (!defined __UINT_LEAST8_MAX__ && defined YY_STDINT_H \
422 && UINT_LEAST8_MAX <= INT_MAX)
423 typedef uint_least8_t yytype_uint8;
424 #elif !defined __UINT_LEAST8_MAX__ && UCHAR_MAX <= INT_MAX
425 typedef unsigned char yytype_uint8;
426 #else
427 typedef short yytype_uint8;
428 #endif
429
430 #if defined __UINT_LEAST16_MAX__ && __UINT_LEAST16_MAX__ <= __INT_MAX__
431 typedef __UINT_LEAST16_TYPE__ yytype_uint16;
432 #elif (!defined __UINT_LEAST16_MAX__ && defined YY_STDINT_H \
433 && UINT_LEAST16_MAX <= INT_MAX)
434 typedef uint_least16_t yytype_uint16;
435 #elif !defined __UINT_LEAST16_MAX__ && USHRT_MAX <= INT_MAX
436 typedef unsigned short yytype_uint16;
437 #else
438 typedef int yytype_uint16;
439 #endif
440
441 #ifndef YYPTRDIFF_T
442 # if defined __PTRDIFF_TYPE__ && defined __PTRDIFF_MAX__
443 # define YYPTRDIFF_T __PTRDIFF_TYPE__
444 # define YYPTRDIFF_MAXIMUM __PTRDIFF_MAX__
445 # elif defined PTRDIFF_MAX
446 # ifndef ptrdiff_t
447 # include <stddef.h> /* INFRINGES ON USER NAME SPACE */
448 # endif
449 # define YYPTRDIFF_T ptrdiff_t
450 # define YYPTRDIFF_MAXIMUM PTRDIFF_MAX
451 # else
452 # define YYPTRDIFF_T long
453 # define YYPTRDIFF_MAXIMUM LONG_MAX
454 # endif
455 #endif
456
457 #ifndef YYSIZE_T
458 # ifdef __SIZE_TYPE__
459 # define YYSIZE_T __SIZE_TYPE__
460 # elif defined size_t
461 # define YYSIZE_T size_t
462 # elif defined __STDC_VERSION__ && 199901 <= __STDC_VERSION__
463 # include <stddef.h> /* INFRINGES ON USER NAME SPACE */
464 # define YYSIZE_T size_t
465 # else
466 # define YYSIZE_T unsigned
467 # endif
468 #endif
469
470 #define YYSIZE_MAXIMUM \
471 YY_CAST (YYPTRDIFF_T, \
472 (YYPTRDIFF_MAXIMUM < YY_CAST (YYSIZE_T, -1) \
473 ? YYPTRDIFF_MAXIMUM \
474 : YY_CAST (YYSIZE_T, -1)))
475
476 #define YYSIZEOF(X) YY_CAST (YYPTRDIFF_T, sizeof (X))
477
478
479 /* Stored state numbers (used for stacks). */
480 typedef yytype_int8 yy_state_t;
481
482 /* State numbers in computations. */
483 typedef int yy_state_fast_t;
484
485 #ifndef YY_
486 # if defined YYENABLE_NLS && YYENABLE_NLS
487 # if ENABLE_NLS
488 # include <libintl.h> /* INFRINGES ON USER NAME SPACE */
489 # define YY_(Msgid) dgettext ("bison-runtime", Msgid)
490 # endif
491 # endif
492 # ifndef YY_
493 # define YY_(Msgid) Msgid
494 # endif
495 #endif
496
497
498 #ifndef YY_ATTRIBUTE_PURE
499 # if defined __GNUC__ && 2 < __GNUC__ + (96 <= __GNUC_MINOR__)
500 # define YY_ATTRIBUTE_PURE __attribute__ ((__pure__))
501 # else
502 # define YY_ATTRIBUTE_PURE
503 # endif
504 #endif
505
506 #ifndef YY_ATTRIBUTE_UNUSED
507 # if defined __GNUC__ && 2 < __GNUC__ + (7 <= __GNUC_MINOR__)
508 # define YY_ATTRIBUTE_UNUSED __attribute__ ((__unused__))
509 # else
510 # define YY_ATTRIBUTE_UNUSED
511 # endif
512 #endif
513
514 /* Suppress unused-variable warnings by "using" E. */
515 #if ! defined lint || defined __GNUC__
516 # define YY_USE(E) ((void) (E))
517 #else
518 # define YY_USE(E) /* empty */
519 #endif
520
521 #if defined __GNUC__ && ! defined __ICC && 407 <= __GNUC__ * 100 + __GNUC_MINOR__
522 /* Suppress an incorrect diagnostic about yylval being uninitialized. */
523 # define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \
524 _Pragma ("GCC diagnostic push") \
525 _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"") \
526 _Pragma ("GCC diagnostic ignored \"-Wmaybe-uninitialized\"")
527 # define YY_IGNORE_MAYBE_UNINITIALIZED_END \
528 _Pragma ("GCC diagnostic pop")
529 #else
530 # define YY_INITIAL_VALUE(Value) Value
531 #endif
532 #ifndef YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
533 # define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
534 # define YY_IGNORE_MAYBE_UNINITIALIZED_END
535 #endif
536 #ifndef YY_INITIAL_VALUE
537 # define YY_INITIAL_VALUE(Value) /* Nothing. */
538 #endif
539
540 #if defined __cplusplus && defined __GNUC__ && ! defined __ICC && 6 <= __GNUC__
541 # define YY_IGNORE_USELESS_CAST_BEGIN \
542 _Pragma ("GCC diagnostic push") \
543 _Pragma ("GCC diagnostic ignored \"-Wuseless-cast\"")
544 # define YY_IGNORE_USELESS_CAST_END \
545 _Pragma ("GCC diagnostic pop")
546 #endif
547 #ifndef YY_IGNORE_USELESS_CAST_BEGIN
548 # define YY_IGNORE_USELESS_CAST_BEGIN
549 # define YY_IGNORE_USELESS_CAST_END
550 #endif
551
552
553 #define YY_ASSERT(E) ((void) (0 && (E)))
554
555 #if !defined yyoverflow
556
557 /* The parser invokes alloca or malloc; define the necessary symbols. */
558
559 # ifdef YYSTACK_USE_ALLOCA
560 # if YYSTACK_USE_ALLOCA
561 # ifdef __GNUC__
562 # define YYSTACK_ALLOC __builtin_alloca
563 # elif defined __BUILTIN_VA_ARG_INCR
564 # include <alloca.h> /* INFRINGES ON USER NAME SPACE */
565 # elif defined _AIX
566 # define YYSTACK_ALLOC __alloca
567 # elif defined _MSC_VER
568 # include <malloc.h> /* INFRINGES ON USER NAME SPACE */
569 # define alloca _alloca
570 # else
571 # define YYSTACK_ALLOC alloca
572 # if ! defined _ALLOCA_H && ! defined EXIT_SUCCESS
573 # include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
574 /* Use EXIT_SUCCESS as a witness for stdlib.h. */
575 # ifndef EXIT_SUCCESS
576 # define EXIT_SUCCESS 0
577 # endif
578 # endif
579 # endif
580 # endif
581 # endif
582
583 # ifdef YYSTACK_ALLOC
584 /* Pacify GCC's 'empty if-body' warning. */
585 # define YYSTACK_FREE(Ptr) do { /* empty */; } while (0)
586 # ifndef YYSTACK_ALLOC_MAXIMUM
587 /* The OS might guarantee only one guard page at the bottom of the stack,
588 and a page size can be as small as 4096 bytes. So we cannot safely
589 invoke alloca (N) if N exceeds 4096. Use a slightly smaller number
590 to allow for a few compiler-allocated temporary stack slots. */
591 # define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */
592 # endif
593 # else
594 # define YYSTACK_ALLOC YYMALLOC
595 # define YYSTACK_FREE YYFREE
596 # ifndef YYSTACK_ALLOC_MAXIMUM
597 # define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM
598 # endif
599 # if (defined __cplusplus && ! defined EXIT_SUCCESS \
600 && ! ((defined YYMALLOC || defined malloc) \
601 && (defined YYFREE || defined free)))
602 # include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
603 # ifndef EXIT_SUCCESS
604 # define EXIT_SUCCESS 0
605 # endif
606 # endif
607 # ifndef YYMALLOC
608 # define YYMALLOC malloc
609 # if ! defined malloc && ! defined EXIT_SUCCESS
610 void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */
611 # endif
612 # endif
613 # ifndef YYFREE
614 # define YYFREE free
615 # if ! defined free && ! defined EXIT_SUCCESS
616 void free (void *); /* INFRINGES ON USER NAME SPACE */
617 # endif
618 # endif
619 # endif
620 #endif /* !defined yyoverflow */
621
622 #if (! defined yyoverflow \
623 && (! defined __cplusplus \
624 || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
625
626 /* A type that is properly aligned for any stack member. */
627 union yyalloc
628 {
629 yy_state_t yyss_alloc;
630 YYSTYPE yyvs_alloc;
631 };
632
633 /* The size of the maximum gap between one aligned stack and the next. */
634 # define YYSTACK_GAP_MAXIMUM (YYSIZEOF (union yyalloc) - 1)
635
636 /* The size of an array large to enough to hold all stacks, each with
637 N elements. */
638 # define YYSTACK_BYTES(N) \
639 ((N) * (YYSIZEOF (yy_state_t) + YYSIZEOF (YYSTYPE)) \
640 + YYSTACK_GAP_MAXIMUM)
641
642 # define YYCOPY_NEEDED 1
643
644 /* Relocate STACK from its old location to the new one. The
645 local variables YYSIZE and YYSTACKSIZE give the old and new number of
646 elements in the stack, and YYPTR gives the new location of the
647 stack. Advance YYPTR to a properly aligned location for the next
648 stack. */
649 # define YYSTACK_RELOCATE(Stack_alloc, Stack) \
650 do \
651 { \
652 YYPTRDIFF_T yynewbytes; \
653 YYCOPY (&yyptr->Stack_alloc, Stack, yysize); \
654 Stack = &yyptr->Stack_alloc; \
655 yynewbytes = yystacksize * YYSIZEOF (*Stack) + YYSTACK_GAP_MAXIMUM; \
656 yyptr += yynewbytes / YYSIZEOF (*yyptr); \
657 } \
658 while (0)
659
660 #endif
661
662 #if defined YYCOPY_NEEDED && YYCOPY_NEEDED
663 /* Copy COUNT objects from SRC to DST. The source and destination do
664 not overlap. */
665 # ifndef YYCOPY
666 # if defined __GNUC__ && 1 < __GNUC__
667 # define YYCOPY(Dst, Src, Count) \
668 __builtin_memcpy (Dst, Src, YY_CAST (YYSIZE_T, (Count)) * sizeof (*(Src)))
669 # else
670 # define YYCOPY(Dst, Src, Count) \
671 do \
672 { \
673 YYPTRDIFF_T yyi; \
674 for (yyi = 0; yyi < (Count); yyi++) \
675 (Dst)[yyi] = (Src)[yyi]; \
676 } \
677 while (0)
678 # endif
679 # endif
680 #endif /* !YYCOPY_NEEDED */
681
682 /* YYFINAL -- State number of the termination state. */
683 #define YYFINAL 2
684 /* YYLAST -- Last index in YYTABLE. */
685 #define YYLAST 50
686
687 /* YYNTOKENS -- Number of terminals. */
688 #define YYNTOKENS 22
689 /* YYNNTS -- Number of nonterminals. */
690 #define YYNNTS 11
691 /* YYNRULES -- Number of rules. */
692 #define YYNRULES 51
693 /* YYNSTATES -- Number of states. */
694 #define YYNSTATES 61
695
696 /* YYMAXUTOK -- Last valid token kind. */
697 #define YYMAXUTOK 273
698
699
700 /* YYTRANSLATE(TOKEN-NUM) -- Symbol number corresponding to TOKEN-NUM
701 as returned by yylex, with out-of-bounds checking. */
702 #define YYTRANSLATE(YYX) \
703 (0 <= (YYX) && (YYX) <= YYMAXUTOK \
704 ? YY_CAST (yysymbol_kind_t, yytranslate[YYX]) \
705 : YYSYMBOL_YYUNDEF)
706
707 /* YYTRANSLATE[TOKEN-NUM] -- Symbol number corresponding to TOKEN-NUM
708 as returned by yylex. */
709 static const yytype_int8 yytranslate[] =
710 {
711 0, 2, 2, 2, 2, 2, 2, 2, 2, 2,
712 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
713 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
714 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
715 2, 2, 2, 2, 20, 2, 2, 21, 2, 2,
716 2, 2, 2, 2, 2, 2, 2, 2, 19, 2,
717 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
718 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
719 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
720 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
721 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
722 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
723 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
724 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
725 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
726 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
727 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
728 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
729 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
730 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
731 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
732 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
733 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
734 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
735 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
736 2, 2, 2, 2, 2, 2, 1, 2, 3, 4,
737 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
738 15, 16, 17, 18
739 };
740
741 #if YYDEBUG
742 /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */
743 static const yytype_int16 yyrline[] =
744 {
745 0, 193, 193, 194, 197, 200, 203, 206, 209, 212,
746 215, 221, 227, 236, 242, 254, 257, 261, 266, 270,
747 274, 280, 284, 302, 308, 314, 318, 323, 327, 334,
748 342, 345, 348, 351, 354, 357, 360, 363, 366, 369,
749 372, 375, 378, 381, 384, 387, 390, 393, 396, 401,
750 435, 438
751 };
752 #endif
753
754 /** Accessing symbol of state STATE. */
755 #define YY_ACCESSING_SYMBOL(State) YY_CAST (yysymbol_kind_t, yystos[State])
756
757 #if YYDEBUG || 0
758 /* The user-facing name of the symbol whose (internal) number is
759 YYSYMBOL. No bounds checking. */
760 static const char *yysymbol_name (yysymbol_kind_t yysymbol) YY_ATTRIBUTE_UNUSED;
761
762 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
763 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
764 static const char *const yytname[] =
765 {
766 "\"end of file\"", "error", "\"invalid token\"", "tAGO", "tDAY",
767 "tDAY_UNIT", "tDAYZONE", "tDST", "tHOUR_UNIT", "tID", "tMERIDIAN",
768 "tMINUTE_UNIT", "tMONTH", "tMONTH_UNIT", "tSEC_UNIT", "tSNUMBER",
769 "tUNUMBER", "tYEAR_UNIT", "tZONE", "':'", "','", "'/'", "$accept",
770 "spec", "item", "time", "zone", "day", "date", "rel", "relunit",
771 "number", "o_merid", YY_NULLPTR
772 };
773
774 static const char *
yysymbol_name(yysymbol_kind_t yysymbol)775 yysymbol_name (yysymbol_kind_t yysymbol)
776 {
777 return yytname[yysymbol];
778 }
779 #endif
780
781 #ifdef YYPRINT
782 /* YYTOKNUM[NUM] -- (External) token number corresponding to the
783 (internal) symbol number NUM (which must be that of a token). */
784 static const yytype_int16 yytoknum[] =
785 {
786 0, 256, 257, 258, 259, 260, 261, 262, 263, 264,
787 265, 266, 267, 268, 269, 270, 271, 272, 273, 58,
788 44, 47
789 };
790 #endif
791
792 #define YYPACT_NINF (-20)
793
794 #define yypact_value_is_default(Yyn) \
795 ((Yyn) == YYPACT_NINF)
796
797 #define YYTABLE_NINF (-1)
798
799 #define yytable_value_is_error(Yyn) \
800 0
801
802 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
803 STATE-NUM. */
804 static const yytype_int8 yypact[] =
805 {
806 -20, 0, -20, -19, -20, -20, -20, -20, -13, -20,
807 -20, 30, 15, -20, 14, -20, -20, -20, -20, -20,
808 -20, 19, -20, -20, 4, -20, -20, -20, -20, -20,
809 -20, -20, -20, -20, -20, -20, -6, -20, -20, 16,
810 -20, 17, 23, -20, -20, 24, -20, -20, -20, 27,
811 28, -20, -20, -20, 29, -20, 32, -8, -20, -20,
812 -20
813 };
814
815 /* YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM.
816 Performed when YYTABLE does not specify something else to do. Zero
817 means the default is an error. */
818 static const yytype_int8 yydefact[] =
819 {
820 2, 0, 1, 18, 39, 16, 42, 45, 0, 36,
821 48, 0, 49, 33, 15, 3, 4, 5, 7, 6,
822 8, 30, 9, 19, 25, 38, 41, 44, 35, 47,
823 32, 20, 37, 40, 10, 43, 27, 34, 46, 0,
824 31, 0, 0, 17, 29, 0, 24, 28, 23, 50,
825 21, 26, 51, 12, 0, 11, 0, 50, 22, 14,
826 13
827 };
828
829 /* YYPGOTO[NTERM-NUM]. */
830 static const yytype_int8 yypgoto[] =
831 {
832 -20, -20, -20, -20, -20, -20, -20, -20, -20, -20,
833 -7
834 };
835
836 /* YYDEFGOTO[NTERM-NUM]. */
837 static const yytype_int8 yydefgoto[] =
838 {
839 0, 1, 15, 16, 17, 18, 19, 20, 21, 22,
840 55
841 };
842
843 /* YYTABLE[YYPACT[STATE-NUM]] -- What to do in state STATE-NUM. If
844 positive, shift that token. If negative, reduce the rule whose
845 number is the opposite. If YYTABLE_NINF, syntax error. */
846 static const yytype_int8 yytable[] =
847 {
848 2, 23, 52, 24, 3, 4, 5, 59, 6, 46,
849 47, 7, 8, 9, 10, 11, 12, 13, 14, 31,
850 32, 43, 44, 33, 45, 34, 35, 36, 37, 38,
851 39, 48, 40, 49, 41, 25, 42, 52, 26, 50,
852 51, 27, 53, 28, 29, 57, 54, 30, 58, 56,
853 60
854 };
855
856 static const yytype_int8 yycheck[] =
857 {
858 0, 20, 10, 16, 4, 5, 6, 15, 8, 15,
859 16, 11, 12, 13, 14, 15, 16, 17, 18, 4,
860 5, 7, 3, 8, 20, 10, 11, 12, 13, 14,
861 15, 15, 17, 16, 19, 5, 21, 10, 8, 16,
862 16, 11, 15, 13, 14, 16, 19, 17, 16, 21,
863 57
864 };
865
866 /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
867 symbol of state STATE-NUM. */
868 static const yytype_int8 yystos[] =
869 {
870 0, 23, 0, 4, 5, 6, 8, 11, 12, 13,
871 14, 15, 16, 17, 18, 24, 25, 26, 27, 28,
872 29, 30, 31, 20, 16, 5, 8, 11, 13, 14,
873 17, 4, 5, 8, 10, 11, 12, 13, 14, 15,
874 17, 19, 21, 7, 3, 20, 15, 16, 15, 16,
875 16, 16, 10, 15, 19, 32, 21, 16, 16, 15,
876 32
877 };
878
879 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
880 static const yytype_int8 yyr1[] =
881 {
882 0, 22, 23, 23, 24, 24, 24, 24, 24, 24,
883 25, 25, 25, 25, 25, 26, 26, 26, 27, 27,
884 27, 28, 28, 28, 28, 28, 28, 28, 28, 29,
885 29, 30, 30, 30, 30, 30, 30, 30, 30, 30,
886 30, 30, 30, 30, 30, 30, 30, 30, 30, 31,
887 32, 32
888 };
889
890 /* YYR2[YYN] -- Number of symbols on the right hand side of rule YYN. */
891 static const yytype_int8 yyr2[] =
892 {
893 0, 2, 0, 2, 1, 1, 1, 1, 1, 1,
894 2, 4, 4, 6, 6, 1, 1, 2, 1, 2,
895 2, 3, 5, 3, 3, 2, 4, 2, 3, 2,
896 1, 2, 2, 1, 2, 2, 1, 2, 2, 1,
897 2, 2, 1, 2, 2, 1, 2, 2, 1, 1,
898 0, 1
899 };
900
901
902 enum { YYENOMEM = -2 };
903
904 #define yyerrok (yyerrstatus = 0)
905 #define yyclearin (yychar = YYEMPTY)
906
907 #define YYACCEPT goto yyacceptlab
908 #define YYABORT goto yyabortlab
909 #define YYERROR goto yyerrorlab
910
911
912 #define YYRECOVERING() (!!yyerrstatus)
913
914 #define YYBACKUP(Token, Value) \
915 do \
916 if (yychar == YYEMPTY) \
917 { \
918 yychar = (Token); \
919 yylval = (Value); \
920 YYPOPSTACK (yylen); \
921 yystate = *yyssp; \
922 goto yybackup; \
923 } \
924 else \
925 { \
926 yyerror (YY_("syntax error: cannot back up")); \
927 YYERROR; \
928 } \
929 while (0)
930
931 /* Backward compatibility with an undocumented macro.
932 Use YYerror or YYUNDEF. */
933 #define YYERRCODE YYUNDEF
934
935
936 /* Enable debugging if requested. */
937 #if YYDEBUG
938
939 # ifndef YYFPRINTF
940 # include <stdio.h> /* INFRINGES ON USER NAME SPACE */
941 # define YYFPRINTF fprintf
942 # endif
943
944 # define YYDPRINTF(Args) \
945 do { \
946 if (yydebug) \
947 YYFPRINTF Args; \
948 } while (0)
949
950 /* This macro is provided for backward compatibility. */
951 # ifndef YY_LOCATION_PRINT
952 # define YY_LOCATION_PRINT(File, Loc) ((void) 0)
953 # endif
954
955
956 # define YY_SYMBOL_PRINT(Title, Kind, Value, Location) \
957 do { \
958 if (yydebug) \
959 { \
960 YYFPRINTF (stderr, "%s ", Title); \
961 yy_symbol_print (stderr, \
962 Kind, Value); \
963 YYFPRINTF (stderr, "\n"); \
964 } \
965 } while (0)
966
967
968 /*-----------------------------------.
969 | Print this symbol's value on YYO. |
970 `-----------------------------------*/
971
972 static void
yy_symbol_value_print(FILE * yyo,yysymbol_kind_t yykind,YYSTYPE const * const yyvaluep)973 yy_symbol_value_print (FILE *yyo,
974 yysymbol_kind_t yykind, YYSTYPE const * const yyvaluep)
975 {
976 FILE *yyoutput = yyo;
977 YY_USE (yyoutput);
978 if (!yyvaluep)
979 return;
980 # ifdef YYPRINT
981 if (yykind < YYNTOKENS)
982 YYPRINT (yyo, yytoknum[yykind], *yyvaluep);
983 # endif
984 YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
985 YY_USE (yykind);
986 YY_IGNORE_MAYBE_UNINITIALIZED_END
987 }
988
989
990 /*---------------------------.
991 | Print this symbol on YYO. |
992 `---------------------------*/
993
994 static void
yy_symbol_print(FILE * yyo,yysymbol_kind_t yykind,YYSTYPE const * const yyvaluep)995 yy_symbol_print (FILE *yyo,
996 yysymbol_kind_t yykind, YYSTYPE const * const yyvaluep)
997 {
998 YYFPRINTF (yyo, "%s %s (",
999 yykind < YYNTOKENS ? "token" : "nterm", yysymbol_name (yykind));
1000
1001 yy_symbol_value_print (yyo, yykind, yyvaluep);
1002 YYFPRINTF (yyo, ")");
1003 }
1004
1005 /*------------------------------------------------------------------.
1006 | yy_stack_print -- Print the state stack from its BOTTOM up to its |
1007 | TOP (included). |
1008 `------------------------------------------------------------------*/
1009
1010 static void
yy_stack_print(yy_state_t * yybottom,yy_state_t * yytop)1011 yy_stack_print (yy_state_t *yybottom, yy_state_t *yytop)
1012 {
1013 YYFPRINTF (stderr, "Stack now");
1014 for (; yybottom <= yytop; yybottom++)
1015 {
1016 int yybot = *yybottom;
1017 YYFPRINTF (stderr, " %d", yybot);
1018 }
1019 YYFPRINTF (stderr, "\n");
1020 }
1021
1022 # define YY_STACK_PRINT(Bottom, Top) \
1023 do { \
1024 if (yydebug) \
1025 yy_stack_print ((Bottom), (Top)); \
1026 } while (0)
1027
1028
1029 /*------------------------------------------------.
1030 | Report that the YYRULE is going to be reduced. |
1031 `------------------------------------------------*/
1032
1033 static void
yy_reduce_print(yy_state_t * yyssp,YYSTYPE * yyvsp,int yyrule)1034 yy_reduce_print (yy_state_t *yyssp, YYSTYPE *yyvsp,
1035 int yyrule)
1036 {
1037 int yylno = yyrline[yyrule];
1038 int yynrhs = yyr2[yyrule];
1039 int yyi;
1040 YYFPRINTF (stderr, "Reducing stack by rule %d (line %d):\n",
1041 yyrule - 1, yylno);
1042 /* The symbols being reduced. */
1043 for (yyi = 0; yyi < yynrhs; yyi++)
1044 {
1045 YYFPRINTF (stderr, " $%d = ", yyi + 1);
1046 yy_symbol_print (stderr,
1047 YY_ACCESSING_SYMBOL (+yyssp[yyi + 1 - yynrhs]),
1048 &yyvsp[(yyi + 1) - (yynrhs)]);
1049 YYFPRINTF (stderr, "\n");
1050 }
1051 }
1052
1053 # define YY_REDUCE_PRINT(Rule) \
1054 do { \
1055 if (yydebug) \
1056 yy_reduce_print (yyssp, yyvsp, Rule); \
1057 } while (0)
1058
1059 /* Nonzero means print parse trace. It is left uninitialized so that
1060 multiple parsers can coexist. */
1061 int yydebug;
1062 #else /* !YYDEBUG */
1063 # define YYDPRINTF(Args) ((void) 0)
1064 # define YY_SYMBOL_PRINT(Title, Kind, Value, Location)
1065 # define YY_STACK_PRINT(Bottom, Top)
1066 # define YY_REDUCE_PRINT(Rule)
1067 #endif /* !YYDEBUG */
1068
1069
1070 /* YYINITDEPTH -- initial size of the parser's stacks. */
1071 #ifndef YYINITDEPTH
1072 # define YYINITDEPTH 200
1073 #endif
1074
1075 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
1076 if the built-in stack extension method is used).
1077
1078 Do not make this value too large; the results are undefined if
1079 YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH)
1080 evaluated with infinite-precision integer arithmetic. */
1081
1082 #ifndef YYMAXDEPTH
1083 # define YYMAXDEPTH 10000
1084 #endif
1085
1086
1087
1088
1089
1090
1091 /*-----------------------------------------------.
1092 | Release the memory associated to this symbol. |
1093 `-----------------------------------------------*/
1094
1095 static void
yydestruct(const char * yymsg,yysymbol_kind_t yykind,YYSTYPE * yyvaluep)1096 yydestruct (const char *yymsg,
1097 yysymbol_kind_t yykind, YYSTYPE *yyvaluep)
1098 {
1099 YY_USE (yyvaluep);
1100 if (!yymsg)
1101 yymsg = "Deleting";
1102 YY_SYMBOL_PRINT (yymsg, yykind, yyvaluep, yylocationp);
1103
1104 YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
1105 YY_USE (yykind);
1106 YY_IGNORE_MAYBE_UNINITIALIZED_END
1107 }
1108
1109
1110 /* Lookahead token kind. */
1111 int yychar;
1112
1113 /* The semantic value of the lookahead symbol. */
1114 YYSTYPE yylval;
1115 /* Number of syntax errors so far. */
1116 int yynerrs;
1117
1118
1119
1120
1121 /*----------.
1122 | yyparse. |
1123 `----------*/
1124
1125 int
yyparse(void)1126 yyparse (void)
1127 {
1128 yy_state_fast_t yystate = 0;
1129 /* Number of tokens to shift before error messages enabled. */
1130 int yyerrstatus = 0;
1131
1132 /* Refer to the stacks through separate pointers, to allow yyoverflow
1133 to reallocate them elsewhere. */
1134
1135 /* Their size. */
1136 YYPTRDIFF_T yystacksize = YYINITDEPTH;
1137
1138 /* The state stack: array, bottom, top. */
1139 yy_state_t yyssa[YYINITDEPTH];
1140 yy_state_t *yyss = yyssa;
1141 yy_state_t *yyssp = yyss;
1142
1143 /* The semantic value stack: array, bottom, top. */
1144 YYSTYPE yyvsa[YYINITDEPTH];
1145 YYSTYPE *yyvs = yyvsa;
1146 YYSTYPE *yyvsp = yyvs;
1147
1148 int yyn;
1149 /* The return value of yyparse. */
1150 int yyresult;
1151 /* Lookahead symbol kind. */
1152 yysymbol_kind_t yytoken = YYSYMBOL_YYEMPTY;
1153 /* The variables used to return semantic value and location from the
1154 action routines. */
1155 YYSTYPE yyval;
1156
1157
1158
1159 #define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N))
1160
1161 /* The number of symbols on the RHS of the reduced rule.
1162 Keep to zero when no symbol should be popped. */
1163 int yylen = 0;
1164
1165 YYDPRINTF ((stderr, "Starting parse\n"));
1166
1167 yychar = YYEMPTY; /* Cause a token to be read. */
1168 goto yysetstate;
1169
1170
1171 /*------------------------------------------------------------.
1172 | yynewstate -- push a new state, which is found in yystate. |
1173 `------------------------------------------------------------*/
1174 yynewstate:
1175 /* In all cases, when you get here, the value and location stacks
1176 have just been pushed. So pushing a state here evens the stacks. */
1177 yyssp++;
1178
1179
1180 /*--------------------------------------------------------------------.
1181 | yysetstate -- set current state (the top of the stack) to yystate. |
1182 `--------------------------------------------------------------------*/
1183 yysetstate:
1184 YYDPRINTF ((stderr, "Entering state %d\n", yystate));
1185 YY_ASSERT (0 <= yystate && yystate < YYNSTATES);
1186 YY_IGNORE_USELESS_CAST_BEGIN
1187 *yyssp = YY_CAST (yy_state_t, yystate);
1188 YY_IGNORE_USELESS_CAST_END
1189 YY_STACK_PRINT (yyss, yyssp);
1190
1191 if (yyss + yystacksize - 1 <= yyssp)
1192 #if !defined yyoverflow && !defined YYSTACK_RELOCATE
1193 goto yyexhaustedlab;
1194 #else
1195 {
1196 /* Get the current used size of the three stacks, in elements. */
1197 YYPTRDIFF_T yysize = yyssp - yyss + 1;
1198
1199 # if defined yyoverflow
1200 {
1201 /* Give user a chance to reallocate the stack. Use copies of
1202 these so that the &'s don't force the real ones into
1203 memory. */
1204 yy_state_t *yyss1 = yyss;
1205 YYSTYPE *yyvs1 = yyvs;
1206
1207 /* Each stack pointer address is followed by the size of the
1208 data in use in that stack, in bytes. This used to be a
1209 conditional around just the two extra args, but that might
1210 be undefined if yyoverflow is a macro. */
1211 yyoverflow (YY_("memory exhausted"),
1212 &yyss1, yysize * YYSIZEOF (*yyssp),
1213 &yyvs1, yysize * YYSIZEOF (*yyvsp),
1214 &yystacksize);
1215 yyss = yyss1;
1216 yyvs = yyvs1;
1217 }
1218 # else /* defined YYSTACK_RELOCATE */
1219 /* Extend the stack our own way. */
1220 if (YYMAXDEPTH <= yystacksize)
1221 goto yyexhaustedlab;
1222 yystacksize *= 2;
1223 if (YYMAXDEPTH < yystacksize)
1224 yystacksize = YYMAXDEPTH;
1225
1226 {
1227 yy_state_t *yyss1 = yyss;
1228 union yyalloc *yyptr =
1229 YY_CAST (union yyalloc *,
1230 YYSTACK_ALLOC (YY_CAST (YYSIZE_T, YYSTACK_BYTES (yystacksize))));
1231 if (! yyptr)
1232 goto yyexhaustedlab;
1233 YYSTACK_RELOCATE (yyss_alloc, yyss);
1234 YYSTACK_RELOCATE (yyvs_alloc, yyvs);
1235 # undef YYSTACK_RELOCATE
1236 if (yyss1 != yyssa)
1237 YYSTACK_FREE (yyss1);
1238 }
1239 # endif
1240
1241 yyssp = yyss + yysize - 1;
1242 yyvsp = yyvs + yysize - 1;
1243
1244 YY_IGNORE_USELESS_CAST_BEGIN
1245 YYDPRINTF ((stderr, "Stack size increased to %ld\n",
1246 YY_CAST (long, yystacksize)));
1247 YY_IGNORE_USELESS_CAST_END
1248
1249 if (yyss + yystacksize - 1 <= yyssp)
1250 YYABORT;
1251 }
1252 #endif /* !defined yyoverflow && !defined YYSTACK_RELOCATE */
1253
1254 if (yystate == YYFINAL)
1255 YYACCEPT;
1256
1257 goto yybackup;
1258
1259
1260 /*-----------.
1261 | yybackup. |
1262 `-----------*/
1263 yybackup:
1264 /* Do appropriate processing given the current state. Read a
1265 lookahead token if we need one and don't already have one. */
1266
1267 /* First try to decide what to do without reference to lookahead token. */
1268 yyn = yypact[yystate];
1269 if (yypact_value_is_default (yyn))
1270 goto yydefault;
1271
1272 /* Not known => get a lookahead token if don't already have one. */
1273
1274 /* YYCHAR is either empty, or end-of-input, or a valid lookahead. */
1275 if (yychar == YYEMPTY)
1276 {
1277 YYDPRINTF ((stderr, "Reading a token\n"));
1278 yychar = yylex ();
1279 }
1280
1281 if (yychar <= YYEOF)
1282 {
1283 yychar = YYEOF;
1284 yytoken = YYSYMBOL_YYEOF;
1285 YYDPRINTF ((stderr, "Now at end of input.\n"));
1286 }
1287 else if (yychar == YYerror)
1288 {
1289 /* The scanner already issued an error message, process directly
1290 to error recovery. But do not keep the error token as
1291 lookahead, it is too special and may lead us to an endless
1292 loop in error recovery. */
1293 yychar = YYUNDEF;
1294 yytoken = YYSYMBOL_YYerror;
1295 goto yyerrlab1;
1296 }
1297 else
1298 {
1299 yytoken = YYTRANSLATE (yychar);
1300 YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
1301 }
1302
1303 /* If the proper action on seeing token YYTOKEN is to reduce or to
1304 detect an error, take that action. */
1305 yyn += yytoken;
1306 if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
1307 goto yydefault;
1308 yyn = yytable[yyn];
1309 if (yyn <= 0)
1310 {
1311 if (yytable_value_is_error (yyn))
1312 goto yyerrlab;
1313 yyn = -yyn;
1314 goto yyreduce;
1315 }
1316
1317 /* Count tokens shifted since error; after three, turn off error
1318 status. */
1319 if (yyerrstatus)
1320 yyerrstatus--;
1321
1322 /* Shift the lookahead token. */
1323 YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
1324 yystate = yyn;
1325 YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
1326 *++yyvsp = yylval;
1327 YY_IGNORE_MAYBE_UNINITIALIZED_END
1328
1329 /* Discard the shifted token. */
1330 yychar = YYEMPTY;
1331 goto yynewstate;
1332
1333
1334 /*-----------------------------------------------------------.
1335 | yydefault -- do the default action for the current state. |
1336 `-----------------------------------------------------------*/
1337 yydefault:
1338 yyn = yydefact[yystate];
1339 if (yyn == 0)
1340 goto yyerrlab;
1341 goto yyreduce;
1342
1343
1344 /*-----------------------------.
1345 | yyreduce -- do a reduction. |
1346 `-----------------------------*/
1347 yyreduce:
1348 /* yyn is the number of a rule to reduce with. */
1349 yylen = yyr2[yyn];
1350
1351 /* If YYLEN is nonzero, implement the default value of the action:
1352 '$$ = $1'.
1353
1354 Otherwise, the following line sets YYVAL to garbage.
1355 This behavior is undocumented and Bison
1356 users should not rely upon it. Assigning to YYVAL
1357 unconditionally makes the parser a bit smaller, and it avoids a
1358 GCC warning that YYVAL may be used uninitialized. */
1359 yyval = yyvsp[1-yylen];
1360
1361
1362 YY_REDUCE_PRINT (yyn);
1363 switch (yyn)
1364 {
1365 case 4: /* item: time */
1366 #line 197 "getdate.y"
1367 {
1368 yyHaveTime++;
1369 }
1370 #line 1371 "getdate.c"
1371 break;
1372
1373 case 5: /* item: zone */
1374 #line 200 "getdate.y"
1375 {
1376 yyHaveZone++;
1377 }
1378 #line 1379 "getdate.c"
1379 break;
1380
1381 case 6: /* item: date */
1382 #line 203 "getdate.y"
1383 {
1384 yyHaveDate++;
1385 }
1386 #line 1387 "getdate.c"
1387 break;
1388
1389 case 7: /* item: day */
1390 #line 206 "getdate.y"
1391 {
1392 yyHaveDay++;
1393 }
1394 #line 1395 "getdate.c"
1395 break;
1396
1397 case 8: /* item: rel */
1398 #line 209 "getdate.y"
1399 {
1400 yyHaveRel++;
1401 }
1402 #line 1403 "getdate.c"
1403 break;
1404
1405 case 10: /* time: tUNUMBER tMERIDIAN */
1406 #line 215 "getdate.y"
1407 {
1408 yyHour = (yyvsp[-1].Number);
1409 yyMinutes = 0;
1410 yySeconds = 0;
1411 yyMeridian = (yyvsp[0].Meridian);
1412 }
1413 #line 1414 "getdate.c"
1414 break;
1415
1416 case 11: /* time: tUNUMBER ':' tUNUMBER o_merid */
1417 #line 221 "getdate.y"
1418 {
1419 yyHour = (yyvsp[-3].Number);
1420 yyMinutes = (yyvsp[-1].Number);
1421 yySeconds = 0;
1422 yyMeridian = (yyvsp[0].Meridian);
1423 }
1424 #line 1425 "getdate.c"
1425 break;
1426
1427 case 12: /* time: tUNUMBER ':' tUNUMBER tSNUMBER */
1428 #line 227 "getdate.y"
1429 {
1430 yyHour = (yyvsp[-3].Number);
1431 yyMinutes = (yyvsp[-1].Number);
1432 yyMeridian = MER24;
1433 yyHaveZone++;
1434 yyTimezone = ((yyvsp[0].Number) < 0
1435 ? -(yyvsp[0].Number) % 100 + (-(yyvsp[0].Number) / 100) * 60
1436 : - ((yyvsp[0].Number) % 100 + ((yyvsp[0].Number) / 100) * 60));
1437 }
1438 #line 1439 "getdate.c"
1439 break;
1440
1441 case 13: /* time: tUNUMBER ':' tUNUMBER ':' tUNUMBER o_merid */
1442 #line 236 "getdate.y"
1443 {
1444 yyHour = (yyvsp[-5].Number);
1445 yyMinutes = (yyvsp[-3].Number);
1446 yySeconds = (yyvsp[-1].Number);
1447 yyMeridian = (yyvsp[0].Meridian);
1448 }
1449 #line 1450 "getdate.c"
1450 break;
1451
1452 case 14: /* time: tUNUMBER ':' tUNUMBER ':' tUNUMBER tSNUMBER */
1453 #line 242 "getdate.y"
1454 {
1455 yyHour = (yyvsp[-5].Number);
1456 yyMinutes = (yyvsp[-3].Number);
1457 yySeconds = (yyvsp[-1].Number);
1458 yyMeridian = MER24;
1459 yyHaveZone++;
1460 yyTimezone = ((yyvsp[0].Number) < 0
1461 ? -(yyvsp[0].Number) % 100 + (-(yyvsp[0].Number) / 100) * 60
1462 : - ((yyvsp[0].Number) % 100 + ((yyvsp[0].Number) / 100) * 60));
1463 }
1464 #line 1465 "getdate.c"
1465 break;
1466
1467 case 15: /* zone: tZONE */
1468 #line 254 "getdate.y"
1469 {
1470 yyTimezone = (yyvsp[0].Number);
1471 }
1472 #line 1473 "getdate.c"
1473 break;
1474
1475 case 16: /* zone: tDAYZONE */
1476 #line 257 "getdate.y"
1477 {
1478 yyTimezone = (yyvsp[0].Number) - 60;
1479 }
1480 #line 1481 "getdate.c"
1481 break;
1482
1483 case 17: /* zone: tZONE tDST */
1484 #line 261 "getdate.y"
1485 {
1486 yyTimezone = (yyvsp[-1].Number) - 60;
1487 }
1488 #line 1489 "getdate.c"
1489 break;
1490
1491 case 18: /* day: tDAY */
1492 #line 266 "getdate.y"
1493 {
1494 yyDayOrdinal = 1;
1495 yyDayNumber = (yyvsp[0].Number);
1496 }
1497 #line 1498 "getdate.c"
1498 break;
1499
1500 case 19: /* day: tDAY ',' */
1501 #line 270 "getdate.y"
1502 {
1503 yyDayOrdinal = 1;
1504 yyDayNumber = (yyvsp[-1].Number);
1505 }
1506 #line 1507 "getdate.c"
1507 break;
1508
1509 case 20: /* day: tUNUMBER tDAY */
1510 #line 274 "getdate.y"
1511 {
1512 yyDayOrdinal = (yyvsp[-1].Number);
1513 yyDayNumber = (yyvsp[0].Number);
1514 }
1515 #line 1516 "getdate.c"
1516 break;
1517
1518 case 21: /* date: tUNUMBER '/' tUNUMBER */
1519 #line 280 "getdate.y"
1520 {
1521 yyMonth = (yyvsp[-2].Number);
1522 yyDay = (yyvsp[0].Number);
1523 }
1524 #line 1525 "getdate.c"
1525 break;
1526
1527 case 22: /* date: tUNUMBER '/' tUNUMBER '/' tUNUMBER */
1528 #line 284 "getdate.y"
1529 {
1530 /* Interpret as YYYY/MM/DD if $1 >= 1000, otherwise as MM/DD/YY.
1531 The goal in recognizing YYYY/MM/DD is solely to support legacy
1532 machine-generated dates like those in an RCS log listing. If
1533 you want portability, use the ISO 8601 format. */
1534 if ((yyvsp[-4].Number) >= 1000)
1535 {
1536 yyYear = (yyvsp[-4].Number);
1537 yyMonth = (yyvsp[-2].Number);
1538 yyDay = (yyvsp[0].Number);
1539 }
1540 else
1541 {
1542 yyMonth = (yyvsp[-4].Number);
1543 yyDay = (yyvsp[-2].Number);
1544 yyYear = (yyvsp[0].Number);
1545 }
1546 }
1547 #line 1548 "getdate.c"
1548 break;
1549
1550 case 23: /* date: tUNUMBER tSNUMBER tSNUMBER */
1551 #line 302 "getdate.y"
1552 {
1553 /* ISO 8601 format. yyyy-mm-dd. */
1554 yyYear = (yyvsp[-2].Number);
1555 yyMonth = -(yyvsp[-1].Number);
1556 yyDay = -(yyvsp[0].Number);
1557 }
1558 #line 1559 "getdate.c"
1559 break;
1560
1561 case 24: /* date: tUNUMBER tMONTH tSNUMBER */
1562 #line 308 "getdate.y"
1563 {
1564 /* e.g. 17-JUN-1992. */
1565 yyDay = (yyvsp[-2].Number);
1566 yyMonth = (yyvsp[-1].Number);
1567 yyYear = -(yyvsp[0].Number);
1568 }
1569 #line 1570 "getdate.c"
1570 break;
1571
1572 case 25: /* date: tMONTH tUNUMBER */
1573 #line 314 "getdate.y"
1574 {
1575 yyMonth = (yyvsp[-1].Number);
1576 yyDay = (yyvsp[0].Number);
1577 }
1578 #line 1579 "getdate.c"
1579 break;
1580
1581 case 26: /* date: tMONTH tUNUMBER ',' tUNUMBER */
1582 #line 318 "getdate.y"
1583 {
1584 yyMonth = (yyvsp[-3].Number);
1585 yyDay = (yyvsp[-2].Number);
1586 yyYear = (yyvsp[0].Number);
1587 }
1588 #line 1589 "getdate.c"
1589 break;
1590
1591 case 27: /* date: tUNUMBER tMONTH */
1592 #line 323 "getdate.y"
1593 {
1594 yyMonth = (yyvsp[0].Number);
1595 yyDay = (yyvsp[-1].Number);
1596 }
1597 #line 1598 "getdate.c"
1598 break;
1599
1600 case 28: /* date: tUNUMBER tMONTH tUNUMBER */
1601 #line 327 "getdate.y"
1602 {
1603 yyMonth = (yyvsp[-1].Number);
1604 yyDay = (yyvsp[-2].Number);
1605 yyYear = (yyvsp[0].Number);
1606 }
1607 #line 1608 "getdate.c"
1608 break;
1609
1610 case 29: /* rel: relunit tAGO */
1611 #line 334 "getdate.y"
1612 {
1613 yyRelSeconds = -yyRelSeconds;
1614 yyRelMinutes = -yyRelMinutes;
1615 yyRelHour = -yyRelHour;
1616 yyRelDay = -yyRelDay;
1617 yyRelMonth = -yyRelMonth;
1618 yyRelYear = -yyRelYear;
1619 }
1620 #line 1621 "getdate.c"
1621 break;
1622
1623 case 31: /* relunit: tUNUMBER tYEAR_UNIT */
1624 #line 345 "getdate.y"
1625 {
1626 yyRelYear += (yyvsp[-1].Number) * (yyvsp[0].Number);
1627 }
1628 #line 1629 "getdate.c"
1629 break;
1630
1631 case 32: /* relunit: tSNUMBER tYEAR_UNIT */
1632 #line 348 "getdate.y"
1633 {
1634 yyRelYear += (yyvsp[-1].Number) * (yyvsp[0].Number);
1635 }
1636 #line 1637 "getdate.c"
1637 break;
1638
1639 case 33: /* relunit: tYEAR_UNIT */
1640 #line 351 "getdate.y"
1641 {
1642 yyRelYear += (yyvsp[0].Number);
1643 }
1644 #line 1645 "getdate.c"
1645 break;
1646
1647 case 34: /* relunit: tUNUMBER tMONTH_UNIT */
1648 #line 354 "getdate.y"
1649 {
1650 yyRelMonth += (yyvsp[-1].Number) * (yyvsp[0].Number);
1651 }
1652 #line 1653 "getdate.c"
1653 break;
1654
1655 case 35: /* relunit: tSNUMBER tMONTH_UNIT */
1656 #line 357 "getdate.y"
1657 {
1658 yyRelMonth += (yyvsp[-1].Number) * (yyvsp[0].Number);
1659 }
1660 #line 1661 "getdate.c"
1661 break;
1662
1663 case 36: /* relunit: tMONTH_UNIT */
1664 #line 360 "getdate.y"
1665 {
1666 yyRelMonth += (yyvsp[0].Number);
1667 }
1668 #line 1669 "getdate.c"
1669 break;
1670
1671 case 37: /* relunit: tUNUMBER tDAY_UNIT */
1672 #line 363 "getdate.y"
1673 {
1674 yyRelDay += (yyvsp[-1].Number) * (yyvsp[0].Number);
1675 }
1676 #line 1677 "getdate.c"
1677 break;
1678
1679 case 38: /* relunit: tSNUMBER tDAY_UNIT */
1680 #line 366 "getdate.y"
1681 {
1682 yyRelDay += (yyvsp[-1].Number) * (yyvsp[0].Number);
1683 }
1684 #line 1685 "getdate.c"
1685 break;
1686
1687 case 39: /* relunit: tDAY_UNIT */
1688 #line 369 "getdate.y"
1689 {
1690 yyRelDay += (yyvsp[0].Number);
1691 }
1692 #line 1693 "getdate.c"
1693 break;
1694
1695 case 40: /* relunit: tUNUMBER tHOUR_UNIT */
1696 #line 372 "getdate.y"
1697 {
1698 yyRelHour += (yyvsp[-1].Number) * (yyvsp[0].Number);
1699 }
1700 #line 1701 "getdate.c"
1701 break;
1702
1703 case 41: /* relunit: tSNUMBER tHOUR_UNIT */
1704 #line 375 "getdate.y"
1705 {
1706 yyRelHour += (yyvsp[-1].Number) * (yyvsp[0].Number);
1707 }
1708 #line 1709 "getdate.c"
1709 break;
1710
1711 case 42: /* relunit: tHOUR_UNIT */
1712 #line 378 "getdate.y"
1713 {
1714 yyRelHour += (yyvsp[0].Number);
1715 }
1716 #line 1717 "getdate.c"
1717 break;
1718
1719 case 43: /* relunit: tUNUMBER tMINUTE_UNIT */
1720 #line 381 "getdate.y"
1721 {
1722 yyRelMinutes += (yyvsp[-1].Number) * (yyvsp[0].Number);
1723 }
1724 #line 1725 "getdate.c"
1725 break;
1726
1727 case 44: /* relunit: tSNUMBER tMINUTE_UNIT */
1728 #line 384 "getdate.y"
1729 {
1730 yyRelMinutes += (yyvsp[-1].Number) * (yyvsp[0].Number);
1731 }
1732 #line 1733 "getdate.c"
1733 break;
1734
1735 case 45: /* relunit: tMINUTE_UNIT */
1736 #line 387 "getdate.y"
1737 {
1738 yyRelMinutes += (yyvsp[0].Number);
1739 }
1740 #line 1741 "getdate.c"
1741 break;
1742
1743 case 46: /* relunit: tUNUMBER tSEC_UNIT */
1744 #line 390 "getdate.y"
1745 {
1746 yyRelSeconds += (yyvsp[-1].Number) * (yyvsp[0].Number);
1747 }
1748 #line 1749 "getdate.c"
1749 break;
1750
1751 case 47: /* relunit: tSNUMBER tSEC_UNIT */
1752 #line 393 "getdate.y"
1753 {
1754 yyRelSeconds += (yyvsp[-1].Number) * (yyvsp[0].Number);
1755 }
1756 #line 1757 "getdate.c"
1757 break;
1758
1759 case 48: /* relunit: tSEC_UNIT */
1760 #line 396 "getdate.y"
1761 {
1762 yyRelSeconds += (yyvsp[0].Number);
1763 }
1764 #line 1765 "getdate.c"
1765 break;
1766
1767 case 49: /* number: tUNUMBER */
1768 #line 402 "getdate.y"
1769 {
1770 if (yyHaveTime && yyHaveDate && !yyHaveRel)
1771 yyYear = (yyvsp[0].Number);
1772 else
1773 {
1774 if ((yyvsp[0].Number)>10000)
1775 {
1776 yyHaveDate++;
1777 yyDay= ((yyvsp[0].Number))%100;
1778 yyMonth= ((yyvsp[0].Number)/100)%100;
1779 yyYear = (yyvsp[0].Number)/10000;
1780 }
1781 else
1782 {
1783 yyHaveTime++;
1784 if ((yyvsp[0].Number) < 100)
1785 {
1786 yyHour = (yyvsp[0].Number);
1787 yyMinutes = 0;
1788 }
1789 else
1790 {
1791 yyHour = (yyvsp[0].Number) / 100;
1792 yyMinutes = (yyvsp[0].Number) % 100;
1793 }
1794 yySeconds = 0;
1795 yyMeridian = MER24;
1796 }
1797 }
1798 }
1799 #line 1800 "getdate.c"
1800 break;
1801
1802 case 50: /* o_merid: %empty */
1803 #line 435 "getdate.y"
1804 {
1805 (yyval.Meridian) = MER24;
1806 }
1807 #line 1808 "getdate.c"
1808 break;
1809
1810 case 51: /* o_merid: tMERIDIAN */
1811 #line 439 "getdate.y"
1812 {
1813 (yyval.Meridian) = (yyvsp[0].Meridian);
1814 }
1815 #line 1816 "getdate.c"
1816 break;
1817
1818
1819 #line 1820 "getdate.c"
1820
1821 default: break;
1822 }
1823 /* User semantic actions sometimes alter yychar, and that requires
1824 that yytoken be updated with the new translation. We take the
1825 approach of translating immediately before every use of yytoken.
1826 One alternative is translating here after every semantic action,
1827 but that translation would be missed if the semantic action invokes
1828 YYABORT, YYACCEPT, or YYERROR immediately after altering yychar or
1829 if it invokes YYBACKUP. In the case of YYABORT or YYACCEPT, an
1830 incorrect destructor might then be invoked immediately. In the
1831 case of YYERROR or YYBACKUP, subsequent parser actions might lead
1832 to an incorrect destructor call or verbose syntax error message
1833 before the lookahead is translated. */
1834 YY_SYMBOL_PRINT ("-> $$ =", YY_CAST (yysymbol_kind_t, yyr1[yyn]), &yyval, &yyloc);
1835
1836 YYPOPSTACK (yylen);
1837 yylen = 0;
1838
1839 *++yyvsp = yyval;
1840
1841 /* Now 'shift' the result of the reduction. Determine what state
1842 that goes to, based on the state we popped back to and the rule
1843 number reduced by. */
1844 {
1845 const int yylhs = yyr1[yyn] - YYNTOKENS;
1846 const int yyi = yypgoto[yylhs] + *yyssp;
1847 yystate = (0 <= yyi && yyi <= YYLAST && yycheck[yyi] == *yyssp
1848 ? yytable[yyi]
1849 : yydefgoto[yylhs]);
1850 }
1851
1852 goto yynewstate;
1853
1854
1855 /*--------------------------------------.
1856 | yyerrlab -- here on detecting error. |
1857 `--------------------------------------*/
1858 yyerrlab:
1859 /* Make sure we have latest lookahead translation. See comments at
1860 user semantic actions for why this is necessary. */
1861 yytoken = yychar == YYEMPTY ? YYSYMBOL_YYEMPTY : YYTRANSLATE (yychar);
1862 /* If not already recovering from an error, report this error. */
1863 if (!yyerrstatus)
1864 {
1865 ++yynerrs;
1866 yyerror (YY_("syntax error"));
1867 }
1868
1869 if (yyerrstatus == 3)
1870 {
1871 /* If just tried and failed to reuse lookahead token after an
1872 error, discard it. */
1873
1874 if (yychar <= YYEOF)
1875 {
1876 /* Return failure if at end of input. */
1877 if (yychar == YYEOF)
1878 YYABORT;
1879 }
1880 else
1881 {
1882 yydestruct ("Error: discarding",
1883 yytoken, &yylval);
1884 yychar = YYEMPTY;
1885 }
1886 }
1887
1888 /* Else will try to reuse lookahead token after shifting the error
1889 token. */
1890 goto yyerrlab1;
1891
1892
1893 /*---------------------------------------------------.
1894 | yyerrorlab -- error raised explicitly by YYERROR. |
1895 `---------------------------------------------------*/
1896 yyerrorlab:
1897 /* Pacify compilers when the user code never invokes YYERROR and the
1898 label yyerrorlab therefore never appears in user code. */
1899 if (0)
1900 YYERROR;
1901
1902 /* Do not reclaim the symbols of the rule whose action triggered
1903 this YYERROR. */
1904 YYPOPSTACK (yylen);
1905 yylen = 0;
1906 YY_STACK_PRINT (yyss, yyssp);
1907 yystate = *yyssp;
1908 goto yyerrlab1;
1909
1910
1911 /*-------------------------------------------------------------.
1912 | yyerrlab1 -- common code for both syntax error and YYERROR. |
1913 `-------------------------------------------------------------*/
1914 yyerrlab1:
1915 yyerrstatus = 3; /* Each real token shifted decrements this. */
1916
1917 /* Pop stack until we find a state that shifts the error token. */
1918 for (;;)
1919 {
1920 yyn = yypact[yystate];
1921 if (!yypact_value_is_default (yyn))
1922 {
1923 yyn += YYSYMBOL_YYerror;
1924 if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYSYMBOL_YYerror)
1925 {
1926 yyn = yytable[yyn];
1927 if (0 < yyn)
1928 break;
1929 }
1930 }
1931
1932 /* Pop the current state because it cannot handle the error token. */
1933 if (yyssp == yyss)
1934 YYABORT;
1935
1936
1937 yydestruct ("Error: popping",
1938 YY_ACCESSING_SYMBOL (yystate), yyvsp);
1939 YYPOPSTACK (1);
1940 yystate = *yyssp;
1941 YY_STACK_PRINT (yyss, yyssp);
1942 }
1943
1944 YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
1945 *++yyvsp = yylval;
1946 YY_IGNORE_MAYBE_UNINITIALIZED_END
1947
1948
1949 /* Shift the error token. */
1950 YY_SYMBOL_PRINT ("Shifting", YY_ACCESSING_SYMBOL (yyn), yyvsp, yylsp);
1951
1952 yystate = yyn;
1953 goto yynewstate;
1954
1955
1956 /*-------------------------------------.
1957 | yyacceptlab -- YYACCEPT comes here. |
1958 `-------------------------------------*/
1959 yyacceptlab:
1960 yyresult = 0;
1961 goto yyreturn;
1962
1963
1964 /*-----------------------------------.
1965 | yyabortlab -- YYABORT comes here. |
1966 `-----------------------------------*/
1967 yyabortlab:
1968 yyresult = 1;
1969 goto yyreturn;
1970
1971
1972 #if !defined yyoverflow
1973 /*-------------------------------------------------.
1974 | yyexhaustedlab -- memory exhaustion comes here. |
1975 `-------------------------------------------------*/
1976 yyexhaustedlab:
1977 yyerror (YY_("memory exhausted"));
1978 yyresult = 2;
1979 goto yyreturn;
1980 #endif
1981
1982
1983 /*-------------------------------------------------------.
1984 | yyreturn -- parsing is finished, clean up and return. |
1985 `-------------------------------------------------------*/
1986 yyreturn:
1987 if (yychar != YYEMPTY)
1988 {
1989 /* Make sure we have latest lookahead translation. See comments at
1990 user semantic actions for why this is necessary. */
1991 yytoken = YYTRANSLATE (yychar);
1992 yydestruct ("Cleanup: discarding lookahead",
1993 yytoken, &yylval);
1994 }
1995 /* Do not reclaim the symbols of the rule whose action triggered
1996 this YYABORT or YYACCEPT. */
1997 YYPOPSTACK (yylen);
1998 YY_STACK_PRINT (yyss, yyssp);
1999 while (yyssp != yyss)
2000 {
2001 yydestruct ("Cleanup: popping",
2002 YY_ACCESSING_SYMBOL (+*yyssp), yyvsp);
2003 YYPOPSTACK (1);
2004 }
2005 #ifndef yyoverflow
2006 if (yyss != yyssa)
2007 YYSTACK_FREE (yyss);
2008 #endif
2009
2010 return yyresult;
2011 }
2012
2013 #line 444 "getdate.y"
2014
2015
2016 /* Include this file down here because bison inserts code above which
2017 may define-away `const'. We want the prototype for get_date to have
2018 the same signature as the function definition does. */
2019 #include "getdate.h"
2020
2021 extern struct tm *gmtime ();
2022 extern struct tm *localtime ();
2023 extern time_t mktime ();
2024
2025 /* Month and day table. */
2026 static TABLE const MonthDayTable[] = {
2027 { "january", tMONTH, 1 },
2028 { "february", tMONTH, 2 },
2029 { "march", tMONTH, 3 },
2030 { "april", tMONTH, 4 },
2031 { "may", tMONTH, 5 },
2032 { "june", tMONTH, 6 },
2033 { "july", tMONTH, 7 },
2034 { "august", tMONTH, 8 },
2035 { "september", tMONTH, 9 },
2036 { "sept", tMONTH, 9 },
2037 { "october", tMONTH, 10 },
2038 { "november", tMONTH, 11 },
2039 { "december", tMONTH, 12 },
2040 { "sunday", tDAY, 0 },
2041 { "monday", tDAY, 1 },
2042 { "tuesday", tDAY, 2 },
2043 { "tues", tDAY, 2 },
2044 { "wednesday", tDAY, 3 },
2045 { "wednes", tDAY, 3 },
2046 { "thursday", tDAY, 4 },
2047 { "thur", tDAY, 4 },
2048 { "thurs", tDAY, 4 },
2049 { "friday", tDAY, 5 },
2050 { "saturday", tDAY, 6 },
2051 { NULL, 0, 0 }
2052 };
2053
2054 /* Time units table. */
2055 static TABLE const UnitsTable[] = {
2056 { "year", tYEAR_UNIT, 1 },
2057 { "month", tMONTH_UNIT, 1 },
2058 { "fortnight", tDAY_UNIT, 14 },
2059 { "week", tDAY_UNIT, 7 },
2060 { "day", tDAY_UNIT, 1 },
2061 { "hour", tHOUR_UNIT, 1 },
2062 { "minute", tMINUTE_UNIT, 1 },
2063 { "min", tMINUTE_UNIT, 1 },
2064 { "second", tSEC_UNIT, 1 },
2065 { "sec", tSEC_UNIT, 1 },
2066 { NULL, 0, 0 }
2067 };
2068
2069 /* Assorted relative-time words. */
2070 static TABLE const OtherTable[] = {
2071 { "tomorrow", tMINUTE_UNIT, 1 * 24 * 60 },
2072 { "yesterday", tMINUTE_UNIT, -1 * 24 * 60 },
2073 { "today", tMINUTE_UNIT, 0 },
2074 { "now", tMINUTE_UNIT, 0 },
2075 { "last", tUNUMBER, -1 },
2076 { "this", tMINUTE_UNIT, 0 },
2077 { "next", tUNUMBER, 1 },
2078 { "first", tUNUMBER, 1 },
2079 /* { "second", tUNUMBER, 2 }, */
2080 { "third", tUNUMBER, 3 },
2081 { "fourth", tUNUMBER, 4 },
2082 { "fifth", tUNUMBER, 5 },
2083 { "sixth", tUNUMBER, 6 },
2084 { "seventh", tUNUMBER, 7 },
2085 { "eighth", tUNUMBER, 8 },
2086 { "ninth", tUNUMBER, 9 },
2087 { "tenth", tUNUMBER, 10 },
2088 { "eleventh", tUNUMBER, 11 },
2089 { "twelfth", tUNUMBER, 12 },
2090 { "ago", tAGO, 1 },
2091 { NULL, 0, 0 }
2092 };
2093
2094 /* The timezone table. */
2095 static TABLE const TimezoneTable[] = {
2096 { "gmt", tZONE, HOUR ( 0) }, /* Greenwich Mean */
2097 { "ut", tZONE, HOUR ( 0) }, /* Universal (Coordinated) */
2098 { "utc", tZONE, HOUR ( 0) },
2099 { "wet", tZONE, HOUR ( 0) }, /* Western European */
2100 { "bst", tDAYZONE, HOUR ( 0) }, /* British Summer */
2101 { "wat", tZONE, HOUR ( 1) }, /* West Africa */
2102 { "at", tZONE, HOUR ( 2) }, /* Azores */
2103 #if 0
2104 /* For completeness. BST is also British Summer, and GST is
2105 * also Guam Standard. */
2106 { "bst", tZONE, HOUR ( 3) }, /* Brazil Standard */
2107 { "gst", tZONE, HOUR ( 3) }, /* Greenland Standard */
2108 #endif
2109 #if 0
2110 { "nft", tZONE, HOUR (3.5) }, /* Newfoundland */
2111 { "nst", tZONE, HOUR (3.5) }, /* Newfoundland Standard */
2112 { "ndt", tDAYZONE, HOUR (3.5) }, /* Newfoundland Daylight */
2113 #endif
2114 { "ast", tZONE, HOUR ( 4) }, /* Atlantic Standard */
2115 { "adt", tDAYZONE, HOUR ( 4) }, /* Atlantic Daylight */
2116 { "est", tZONE, HOUR ( 5) }, /* Eastern Standard */
2117 { "edt", tDAYZONE, HOUR ( 5) }, /* Eastern Daylight */
2118 { "cst", tZONE, HOUR ( 6) }, /* Central Standard */
2119 { "cdt", tDAYZONE, HOUR ( 6) }, /* Central Daylight */
2120 { "mst", tZONE, HOUR ( 7) }, /* Mountain Standard */
2121 { "mdt", tDAYZONE, HOUR ( 7) }, /* Mountain Daylight */
2122 { "pst", tZONE, HOUR ( 8) }, /* Pacific Standard */
2123 { "pdt", tDAYZONE, HOUR ( 8) }, /* Pacific Daylight */
2124 { "yst", tZONE, HOUR ( 9) }, /* Yukon Standard */
2125 { "ydt", tDAYZONE, HOUR ( 9) }, /* Yukon Daylight */
2126 { "hst", tZONE, HOUR (10) }, /* Hawaii Standard */
2127 { "hdt", tDAYZONE, HOUR (10) }, /* Hawaii Daylight */
2128 { "cat", tZONE, HOUR (10) }, /* Central Alaska */
2129 { "ahst", tZONE, HOUR (10) }, /* Alaska-Hawaii Standard */
2130 { "nt", tZONE, HOUR (11) }, /* Nome */
2131 { "idlw", tZONE, HOUR (12) }, /* International Date Line West */
2132 { "cet", tZONE, -HOUR (1) }, /* Central European */
2133 { "met", tZONE, -HOUR (1) }, /* Middle European */
2134 { "mewt", tZONE, -HOUR (1) }, /* Middle European Winter */
2135 { "mest", tDAYZONE, -HOUR (1) }, /* Middle European Summer */
2136 { "mesz", tDAYZONE, -HOUR (1) }, /* Middle European Summer */
2137 { "swt", tZONE, -HOUR (1) }, /* Swedish Winter */
2138 { "sst", tDAYZONE, -HOUR (1) }, /* Swedish Summer */
2139 { "fwt", tZONE, -HOUR (1) }, /* French Winter */
2140 { "fst", tDAYZONE, -HOUR (1) }, /* French Summer */
2141 { "eet", tZONE, -HOUR (2) }, /* Eastern Europe, USSR Zone 1 */
2142 { "bt", tZONE, -HOUR (3) }, /* Baghdad, USSR Zone 2 */
2143 #if 0
2144 { "it", tZONE, -HOUR (3.5) },/* Iran */
2145 #endif
2146 { "zp4", tZONE, -HOUR (4) }, /* USSR Zone 3 */
2147 { "zp5", tZONE, -HOUR (5) }, /* USSR Zone 4 */
2148 #if 0
2149 { "ist", tZONE, -HOUR (5.5) },/* Indian Standard */
2150 #endif
2151 { "zp6", tZONE, -HOUR (6) }, /* USSR Zone 5 */
2152 #if 0
2153 /* For completeness. NST is also Newfoundland Standard, and SST is
2154 * also Swedish Summer. */
2155 { "nst", tZONE, -HOUR (6.5) },/* North Sumatra */
2156 { "sst", tZONE, -HOUR (7) }, /* South Sumatra, USSR Zone 6 */
2157 #endif /* 0 */
2158 { "wast", tZONE, -HOUR (7) }, /* West Australian Standard */
2159 { "wadt", tDAYZONE, -HOUR (7) }, /* West Australian Daylight */
2160 #if 0
2161 { "jt", tZONE, -HOUR (7.5) },/* Java (3pm in Cronusland!) */
2162 #endif
2163 { "cct", tZONE, -HOUR (8) }, /* China Coast, USSR Zone 7 */
2164 { "jst", tZONE, -HOUR (9) }, /* Japan Standard, USSR Zone 8 */
2165 #if 0
2166 { "cast", tZONE, -HOUR (9.5) },/* Central Australian Standard */
2167 { "cadt", tDAYZONE, -HOUR (9.5) },/* Central Australian Daylight */
2168 #endif
2169 { "east", tZONE, -HOUR (10) }, /* Eastern Australian Standard */
2170 { "eadt", tDAYZONE, -HOUR (10) }, /* Eastern Australian Daylight */
2171 { "gst", tZONE, -HOUR (10) }, /* Guam Standard, USSR Zone 9 */
2172 { "nzt", tZONE, -HOUR (12) }, /* New Zealand */
2173 { "nzst", tZONE, -HOUR (12) }, /* New Zealand Standard */
2174 { "nzdt", tDAYZONE, -HOUR (12) }, /* New Zealand Daylight */
2175 { "idle", tZONE, -HOUR (12) }, /* International Date Line East */
2176 { NULL, 0, 0 }
2177 };
2178
2179 /* Military timezone table. */
2180 static TABLE const MilitaryTable[] = {
2181 { "a", tZONE, HOUR ( 1) },
2182 { "b", tZONE, HOUR ( 2) },
2183 { "c", tZONE, HOUR ( 3) },
2184 { "d", tZONE, HOUR ( 4) },
2185 { "e", tZONE, HOUR ( 5) },
2186 { "f", tZONE, HOUR ( 6) },
2187 { "g", tZONE, HOUR ( 7) },
2188 { "h", tZONE, HOUR ( 8) },
2189 { "i", tZONE, HOUR ( 9) },
2190 { "k", tZONE, HOUR ( 10) },
2191 { "l", tZONE, HOUR ( 11) },
2192 { "m", tZONE, HOUR ( 12) },
2193 { "n", tZONE, HOUR (- 1) },
2194 { "o", tZONE, HOUR (- 2) },
2195 { "p", tZONE, HOUR (- 3) },
2196 { "q", tZONE, HOUR (- 4) },
2197 { "r", tZONE, HOUR (- 5) },
2198 { "s", tZONE, HOUR (- 6) },
2199 { "t", tZONE, HOUR (- 7) },
2200 { "u", tZONE, HOUR (- 8) },
2201 { "v", tZONE, HOUR (- 9) },
2202 { "w", tZONE, HOUR (-10) },
2203 { "x", tZONE, HOUR (-11) },
2204 { "y", tZONE, HOUR (-12) },
2205 { "z", tZONE, HOUR ( 0) },
2206 { NULL, 0, 0 }
2207 };
2208
2209
2210
2211
2212 /* ARGSUSED */
2213 static int
yyerror(s)2214 yyerror (s)
2215 char *s ATTRIBUTE_UNUSED;
2216 {
2217 return 0;
2218 }
2219
2220 static int
ToHour(Hours,Meridian)2221 ToHour (Hours, Meridian)
2222 int Hours;
2223 MERIDIAN Meridian;
2224 {
2225 switch (Meridian)
2226 {
2227 case MER24:
2228 if (Hours < 0 || Hours > 23)
2229 return -1;
2230 return Hours;
2231 case MERam:
2232 if (Hours < 1 || Hours > 12)
2233 return -1;
2234 if (Hours == 12)
2235 Hours = 0;
2236 return Hours;
2237 case MERpm:
2238 if (Hours < 1 || Hours > 12)
2239 return -1;
2240 if (Hours == 12)
2241 Hours = 0;
2242 return Hours + 12;
2243 default:
2244 abort ();
2245 }
2246 /* NOTREACHED */
2247 }
2248
2249 static int
ToYear(Year)2250 ToYear (Year)
2251 int Year;
2252 {
2253 if (Year < 0)
2254 Year = -Year;
2255
2256 /* XPG4 suggests that years 00-68 map to 2000-2068, and
2257 years 69-99 map to 1969-1999. */
2258 if (Year < 69)
2259 Year += 2000;
2260 else if (Year < 100)
2261 Year += 1900;
2262
2263 return Year;
2264 }
2265
2266 static int
LookupWord(buff)2267 LookupWord (buff)
2268 char *buff;
2269 {
2270 register char *p;
2271 register char *q;
2272 register const TABLE *tp;
2273 int i;
2274 int abbrev;
2275
2276 /* Make it lowercase. */
2277 for (p = buff; *p; p++)
2278 if (ISUPPER ((unsigned char) *p))
2279 *p = tolower ((unsigned char) *p);
2280
2281 if (strcmp (buff, "am") == 0 || strcmp (buff, "a.m.") == 0)
2282 {
2283 yylval.Meridian = MERam;
2284 return tMERIDIAN;
2285 }
2286 if (strcmp (buff, "pm") == 0 || strcmp (buff, "p.m.") == 0)
2287 {
2288 yylval.Meridian = MERpm;
2289 return tMERIDIAN;
2290 }
2291
2292 /* See if we have an abbreviation for a month. */
2293 if (strlen (buff) == 3)
2294 abbrev = 1;
2295 else if (strlen (buff) == 4 && buff[3] == '.')
2296 {
2297 abbrev = 1;
2298 buff[3] = '\0';
2299 }
2300 else
2301 abbrev = 0;
2302
2303 for (tp = MonthDayTable; tp->name; tp++)
2304 {
2305 if (abbrev)
2306 {
2307 if (strncmp (buff, tp->name, 3) == 0)
2308 {
2309 yylval.Number = tp->value;
2310 return tp->type;
2311 }
2312 }
2313 else if (strcmp (buff, tp->name) == 0)
2314 {
2315 yylval.Number = tp->value;
2316 return tp->type;
2317 }
2318 }
2319
2320 for (tp = TimezoneTable; tp->name; tp++)
2321 if (strcmp (buff, tp->name) == 0)
2322 {
2323 yylval.Number = tp->value;
2324 return tp->type;
2325 }
2326
2327 if (strcmp (buff, "dst") == 0)
2328 return tDST;
2329
2330 for (tp = UnitsTable; tp->name; tp++)
2331 if (strcmp (buff, tp->name) == 0)
2332 {
2333 yylval.Number = tp->value;
2334 return tp->type;
2335 }
2336
2337 /* Strip off any plural and try the units table again. */
2338 i = strlen (buff) - 1;
2339 if (buff[i] == 's')
2340 {
2341 buff[i] = '\0';
2342 for (tp = UnitsTable; tp->name; tp++)
2343 if (strcmp (buff, tp->name) == 0)
2344 {
2345 yylval.Number = tp->value;
2346 return tp->type;
2347 }
2348 buff[i] = 's'; /* Put back for "this" in OtherTable. */
2349 }
2350
2351 for (tp = OtherTable; tp->name; tp++)
2352 if (strcmp (buff, tp->name) == 0)
2353 {
2354 yylval.Number = tp->value;
2355 return tp->type;
2356 }
2357
2358 /* Military timezones. */
2359 if (buff[1] == '\0' && ISALPHA ((unsigned char) *buff))
2360 {
2361 for (tp = MilitaryTable; tp->name; tp++)
2362 if (strcmp (buff, tp->name) == 0)
2363 {
2364 yylval.Number = tp->value;
2365 return tp->type;
2366 }
2367 }
2368
2369 /* Drop out any periods and try the timezone table again. */
2370 for (i = 0, p = q = buff; *q; q++)
2371 if (*q != '.')
2372 *p++ = *q;
2373 else
2374 i++;
2375 *p = '\0';
2376 if (i)
2377 for (tp = TimezoneTable; tp->name; tp++)
2378 if (strcmp (buff, tp->name) == 0)
2379 {
2380 yylval.Number = tp->value;
2381 return tp->type;
2382 }
2383
2384 return tID;
2385 }
2386
2387 static int
yylex()2388 yylex ()
2389 {
2390 register unsigned char c;
2391 register char *p;
2392 char buff[20];
2393 int Count;
2394 int sign;
2395
2396 for (;;)
2397 {
2398 while (ISSPACE ((unsigned char) *yyInput))
2399 yyInput++;
2400
2401 if (ISDIGIT (c = *yyInput) || c == '-' || c == '+')
2402 {
2403 if (c == '-' || c == '+')
2404 {
2405 sign = c == '-' ? -1 : 1;
2406 if (!ISDIGIT (*++yyInput))
2407 /* skip the '-' sign */
2408 continue;
2409 }
2410 else
2411 sign = 0;
2412 for (yylval.Number = 0; ISDIGIT (c = *yyInput++);)
2413 yylval.Number = 10 * yylval.Number + c - '0';
2414 yyInput--;
2415 if (sign < 0)
2416 yylval.Number = -yylval.Number;
2417 return sign ? tSNUMBER : tUNUMBER;
2418 }
2419 if (ISALPHA (c))
2420 {
2421 for (p = buff; (c = *yyInput++, ISALPHA (c)) || c == '.';)
2422 if (p < &buff[sizeof buff - 1])
2423 *p++ = c;
2424 *p = '\0';
2425 yyInput--;
2426 return LookupWord (buff);
2427 }
2428 if (c != '(')
2429 return *yyInput++;
2430 Count = 0;
2431 do
2432 {
2433 c = *yyInput++;
2434 if (c == '\0')
2435 return c;
2436 if (c == '(')
2437 Count++;
2438 else if (c == ')')
2439 Count--;
2440 }
2441 while (Count > 0);
2442 }
2443 }
2444
2445 #define TM_YEAR_ORIGIN 1900
2446
2447 /* Yield A - B, measured in seconds. */
2448 static long
difftm(struct tm * a,struct tm * b)2449 difftm (struct tm *a, struct tm *b)
2450 {
2451 int ay = a->tm_year + (TM_YEAR_ORIGIN - 1);
2452 int by = b->tm_year + (TM_YEAR_ORIGIN - 1);
2453 long days = (
2454 /* difference in day of year */
2455 a->tm_yday - b->tm_yday
2456 /* + intervening leap days */
2457 + ((ay >> 2) - (by >> 2))
2458 - (ay / 100 - by / 100)
2459 + ((ay / 100 >> 2) - (by / 100 >> 2))
2460 /* + difference in years * 365 */
2461 + (long) (ay - by) * 365
2462 );
2463 return (60 * (60 * (24 * days + (a->tm_hour - b->tm_hour))
2464 + (a->tm_min - b->tm_min))
2465 + (a->tm_sec - b->tm_sec));
2466 }
2467
2468 time_t
get_date(const char * p,const time_t * now)2469 get_date (const char *p, const time_t *now)
2470 {
2471 struct tm tm, tm0, *tmp;
2472 time_t Start;
2473
2474 yyInput = p;
2475 Start = now ? *now : time ((time_t *) NULL);
2476 tmp = localtime (&Start);
2477 if (!tmp)
2478 return -1;
2479 yyYear = tmp->tm_year + TM_YEAR_ORIGIN;
2480 yyMonth = tmp->tm_mon + 1;
2481 yyDay = tmp->tm_mday;
2482 yyHour = tmp->tm_hour;
2483 yyMinutes = tmp->tm_min;
2484 yySeconds = tmp->tm_sec;
2485 tm.tm_isdst = tmp->tm_isdst;
2486 yyMeridian = MER24;
2487 yyRelSeconds = 0;
2488 yyRelMinutes = 0;
2489 yyRelHour = 0;
2490 yyRelDay = 0;
2491 yyRelMonth = 0;
2492 yyRelYear = 0;
2493 yyHaveDate = 0;
2494 yyHaveDay = 0;
2495 yyHaveRel = 0;
2496 yyHaveTime = 0;
2497 yyHaveZone = 0;
2498
2499 if (yyparse ()
2500 || yyHaveTime > 1 || yyHaveZone > 1 || yyHaveDate > 1 || yyHaveDay > 1)
2501 return -1;
2502
2503 tm.tm_year = ToYear (yyYear) - TM_YEAR_ORIGIN + yyRelYear;
2504 tm.tm_mon = yyMonth - 1 + yyRelMonth;
2505 tm.tm_mday = yyDay + yyRelDay;
2506 if (yyHaveTime || (yyHaveRel && !yyHaveDate && !yyHaveDay))
2507 {
2508 tm.tm_hour = ToHour (yyHour, yyMeridian);
2509 if (tm.tm_hour < 0)
2510 return -1;
2511 tm.tm_min = yyMinutes;
2512 tm.tm_sec = yySeconds;
2513 }
2514 else
2515 {
2516 tm.tm_hour = tm.tm_min = tm.tm_sec = 0;
2517 }
2518 tm.tm_hour += yyRelHour;
2519 tm.tm_min += yyRelMinutes;
2520 tm.tm_sec += yyRelSeconds;
2521
2522 /* Let mktime deduce tm_isdst if we have an absolute timestamp,
2523 or if the relative timestamp mentions days, months, or years. */
2524 if (yyHaveDate | yyHaveDay | yyHaveTime | yyRelDay | yyRelMonth | yyRelYear)
2525 tm.tm_isdst = -1;
2526
2527 tm0 = tm;
2528
2529 Start = mktime (&tm);
2530
2531 if (Start == (time_t) -1)
2532 {
2533
2534 /* Guard against falsely reporting errors near the time_t boundaries
2535 when parsing times in other time zones. For example, if the min
2536 time_t value is 1970-01-01 00:00:00 UTC and we are 8 hours ahead
2537 of UTC, then the min localtime value is 1970-01-01 08:00:00; if
2538 we apply mktime to 1970-01-01 00:00:00 we will get an error, so
2539 we apply mktime to 1970-01-02 08:00:00 instead and adjust the time
2540 zone by 24 hours to compensate. This algorithm assumes that
2541 there is no DST transition within a day of the time_t boundaries. */
2542 if (yyHaveZone)
2543 {
2544 tm = tm0;
2545 if (tm.tm_year <= EPOCH - TM_YEAR_ORIGIN)
2546 {
2547 tm.tm_mday++;
2548 yyTimezone -= 24 * 60;
2549 }
2550 else
2551 {
2552 tm.tm_mday--;
2553 yyTimezone += 24 * 60;
2554 }
2555 Start = mktime (&tm);
2556 }
2557
2558 if (Start == (time_t) -1)
2559 return Start;
2560 }
2561
2562 if (yyHaveDay && !yyHaveDate)
2563 {
2564 tm.tm_mday += ((yyDayNumber - tm.tm_wday + 7) % 7
2565 + 7 * (yyDayOrdinal - (0 < yyDayOrdinal)));
2566 Start = mktime (&tm);
2567 if (Start == (time_t) -1)
2568 return Start;
2569 }
2570
2571 if (yyHaveZone)
2572 {
2573 long delta;
2574 struct tm *gmt = gmtime (&Start);
2575 if (!gmt)
2576 return -1;
2577 delta = yyTimezone * 60L + difftm (&tm, gmt);
2578 if ((Start + delta < Start) != (delta < 0))
2579 return -1; /* time_t overflow */
2580 Start += delta;
2581 }
2582
2583 return Start;
2584 }
2585
2586 #if defined (TEST)
2587
2588 /* ARGSUSED */
2589 int
main(ac,av)2590 main (ac, av)
2591 int ac;
2592 char *av[];
2593 {
2594 char buff[MAX_BUFF_LEN + 1];
2595 time_t d;
2596
2597 (void) printf ("Enter date, or blank line to exit.\n\t> ");
2598 (void) fflush (stdout);
2599
2600 buff[MAX_BUFF_LEN] = 0;
2601 while (fgets (buff, MAX_BUFF_LEN, stdin) && buff[0])
2602 {
2603 d = get_date (buff, (time_t *) NULL);
2604 if (d == -1)
2605 (void) printf ("Bad format - couldn't convert.\n");
2606 else
2607 (void) printf ("%s", ctime (&d));
2608 (void) printf ("\t> ");
2609 (void) fflush (stdout);
2610 }
2611 exit (0);
2612 /* NOTREACHED */
2613 }
2614 #endif /* defined (TEST) */
2615