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