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