]> git.saurik.com Git - apple/shell_cmds.git/blob - find/y.tab.c
573e77569d6012b6d53f57cbad249ed711bc162d
[apple/shell_cmds.git] / find / y.tab.c
1 #include <sys/cdefs.h>
2 #ifndef lint
3 #if 0
4 static char yysccsid[] = "@(#)yaccpar 1.9 (Berkeley) 02/21/93";
5 #else
6 __IDSTRING(yyrcsid, "$NetBSD: skeleton.c,v 1.14 1997/10/20 03:41:16 lukem Exp $");
7 #endif
8 #endif
9 #include <stdlib.h>
10 #define YYBYACC 1
11 #define YYMAJOR 1
12 #define YYMINOR 9
13 #define YYLEX yylex()
14 #define YYEMPTY -1
15 #define yyclearin (yychar=(YYEMPTY))
16 #define yyerrok (yyerrflag=0)
17 #define YYRECOVERING (yyerrflag!=0)
18 #define YYPREFIX "yy"
19 #line 2 "getdate.y"
20 /*
21 ** Originally written by Steven M. Bellovin <smb@research.att.com> while
22 ** at the University of North Carolina at Chapel Hill. Later tweaked by
23 ** a couple of people on Usenet. Completely overhauled by Rich $alz
24 ** <rsalz@bbn.com> and Jim Berets <jberets@bbn.com> in August, 1990;
25 **
26 ** This grammar has 10 shift/reduce conflicts.
27 **
28 ** This code is in the public domain and has no copyright.
29 */
30 /* SUPPRESS 287 on yaccpar_sccsid *//* Unused static variable */
31 /* SUPPRESS 288 on yyerrlab *//* Label unused */
32
33 #ifdef HAVE_CONFIG_H
34 #if defined (emacs) || defined (CONFIG_BROKETS)
35 #include <config.h>
36 #else
37 #include "config.h"
38 #endif
39 #endif
40
41 /* Since the code of getdate.y is not included in the Emacs executable
42 itself, there is no need to #define static in this file. Even if
43 the code were included in the Emacs executable, it probably
44 wouldn't do any harm to #undef it here; this will only cause
45 problems if we try to write to a static variable, which I don't
46 think this code needs to do. */
47 #ifdef emacs
48 #undef static
49 #endif
50
51 #include <stdio.h>
52 #include <ctype.h>
53 #include <string.h>
54
55 /* The code at the top of get_date which figures out the offset of the
56 current time zone checks various CPP symbols to see if special
57 tricks are need, but defaults to using the gettimeofday system call.
58 Include <sys/time.h> if that will be used. */
59
60 #if defined(vms)
61 # include <types.h>
62 #else /* defined(vms) */
63 # include <sys/types.h>
64 /* don't need xtime.h */
65 # include <sys/time.h>
66 # include <time.h>
67 #endif /* !defined(vms) */
68
69 #include <sys/timeb.h>
70
71 #if defined (STDC_HEADERS) || defined (USG)
72 #include <string.h>
73 #endif
74
75 /* Some old versions of bison generate parsers that use bcopy.
76 That loses on systems that don't provide the function, so we have
77 to redefine it here. */
78 #if !defined (HAVE_BCOPY) && defined (HAVE_MEMCPY) && !defined (bcopy)
79 #define bcopy(from, to, len) memcpy ((to), (from), (len))
80 #endif
81
82 #if defined (STDC_HEADERS)
83 #include <stdlib.h>
84 #endif
85
86 /* NOTES on rebuilding getdate.c (particularly for inclusion in CVS
87 releases):
88
89 We don't want to mess with all the portability hassles of alloca.
90 In particular, most (all?) versions of bison will use alloca in
91 their parser. If bison works on your system (e.g. it should work
92 with gcc), then go ahead and use it, but the more general solution
93 is to use byacc instead of bison, which should generate a portable
94 parser. I played with adding "#define alloca dont_use_alloca", to
95 give an error if the parser generator uses alloca (and thus detect
96 unportable getdate.c's), but that seems to cause as many problems
97 as it solves. */
98
99 extern struct tm *gmtime();
100 extern struct tm *localtime();
101
102 #define yyparse getdate_yyparse
103 #define yylex getdate_yylex
104 #define yyerror getdate_yyerror
105
106 static int yyparse ();
107 static int yylex ();
108 static int yyerror ();
109
110 #define EPOCH 1970
111 #define HOUR(x) ((time_t)(x) * 60)
112 #define SECSPERDAY (24L * 60L * 60L)
113
114
115 /*
116 ** An entry in the lexical lookup table.
117 */
118 typedef struct _TABLE {
119 char *name;
120 int type;
121 time_t value;
122 } TABLE;
123
124
125 /*
126 ** Daylight-savings mode: on, off, or not yet known.
127 */
128 typedef enum _DSTMODE {
129 DSTon, DSToff, DSTmaybe
130 } DSTMODE;
131
132 /*
133 ** Meridian: am, pm, or 24-hour style.
134 */
135 typedef enum _MERIDIAN {
136 MERam, MERpm, MER24
137 } MERIDIAN;
138
139
140 /*
141 ** Global variables. We could get rid of most of these by using a good
142 ** union as the yacc stack. (This routine was originally written before
143 ** yacc had the %union construct.) Maybe someday; right now we only use
144 ** the %union very rarely.
145 */
146 static char *yyInput;
147 static DSTMODE yyDSTmode;
148 static time_t yyDayOrdinal;
149 static time_t yyDayNumber;
150 static int yyHaveDate;
151 static int yyHaveDay;
152 static int yyHaveRel;
153 static int yyHaveTime;
154 static int yyHaveZone;
155 static time_t yyTimezone;
156 static time_t yyDay;
157 static time_t yyHour;
158 static time_t yyMinutes;
159 static time_t yyMonth;
160 static time_t yySeconds;
161 static time_t yyYear;
162 static MERIDIAN yyMeridian;
163 static time_t yyRelMonth;
164 static time_t yyRelSeconds;
165
166 #line 150 "getdate.y"
167 typedef union {
168 time_t Number;
169 enum _MERIDIAN Meridian;
170 } YYSTYPE;
171 #line 172 "y.tab.c"
172 #define tAGO 257
173 #define tDAY 258
174 #define tDAYZONE 259
175 #define tID 260
176 #define tMERIDIAN 261
177 #define tMINUTE_UNIT 262
178 #define tMONTH 263
179 #define tMONTH_UNIT 264
180 #define tSEC_UNIT 265
181 #define tSNUMBER 266
182 #define tUNUMBER 267
183 #define tZONE 268
184 #define tDST 269
185 #define YYERRCODE 256
186 short yylhs[] = { -1,
187 0, 0, 2, 2, 2, 2, 2, 2, 3, 3,
188 3, 3, 3, 4, 4, 4, 6, 6, 6, 5,
189 5, 5, 5, 5, 5, 5, 5, 7, 7, 9,
190 9, 9, 9, 9, 9, 9, 9, 9, 8, 1,
191 1,
192 };
193 short yylen[] = { 2,
194 0, 2, 1, 1, 1, 1, 1, 1, 2, 4,
195 4, 6, 6, 1, 1, 2, 1, 2, 2, 3,
196 5, 3, 3, 2, 4, 2, 3, 2, 1, 2,
197 2, 1, 2, 2, 1, 2, 2, 1, 1, 0,
198 1,
199 };
200 short yydefred[] = { 1,
201 0, 0, 15, 32, 0, 38, 35, 0, 0, 0,
202 2, 3, 4, 5, 6, 7, 8, 0, 18, 0,
203 31, 36, 33, 19, 9, 30, 0, 37, 34, 0,
204 0, 0, 16, 28, 0, 23, 27, 22, 0, 0,
205 25, 41, 11, 0, 10, 0, 0, 21, 13, 12,
206 };
207 short yydgoto[] = { 1,
208 45, 11, 12, 13, 14, 15, 16, 17, 18,
209 };
210 short yysindex[] = { 0,
211 -249, -38, 0, 0, -260, 0, 0, -240, -47, -248,
212 0, 0, 0, 0, 0, 0, 0, -237, 0, -18,
213 0, 0, 0, 0, 0, 0, -262, 0, 0, -239,
214 -238, -236, 0, 0, -235, 0, 0, 0, -56, -19,
215 0, 0, 0, -234, 0, -232, -258, 0, 0, 0,
216 };
217 short yyrindex[] = { 0,
218 0, 1, 0, 0, 0, 0, 0, 0, 69, 12,
219 0, 0, 0, 0, 0, 0, 0, 23, 0, 34,
220 0, 0, 0, 0, 0, 0, 67, 0, 0, 0,
221 0, 0, 0, 0, 0, 0, 0, 0, 56, 45,
222 0, 0, 0, 0, 0, 0, 56, 0, 0, 0,
223 };
224 short yygindex[] = { 0,
225 -17, 0, 0, 0, 0, 0, 0, 0, 0,
226 };
227 #define YYTABLESIZE 337
228 short yytable[] = { 32,
229 17, 44, 42, 36, 37, 19, 20, 49, 2, 3,
230 31, 14, 4, 5, 6, 7, 8, 9, 10, 34,
231 33, 21, 29, 22, 23, 35, 38, 46, 39, 50,
232 40, 41, 47, 24, 48, 0, 0, 0, 0, 0,
233 0, 0, 0, 0, 20, 0, 0, 0, 0, 0,
234 0, 0, 0, 0, 0, 40, 0, 0, 0, 0,
235 0, 0, 0, 0, 0, 0, 26, 0, 39, 0,
236 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
237 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
238 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
239 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
240 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
241 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
242 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
243 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
244 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
245 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
246 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
247 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
248 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
249 0, 0, 0, 0, 42, 0, 0, 0, 0, 43,
250 24, 0, 0, 25, 26, 27, 28, 29, 30, 0,
251 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
252 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
253 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
254 0, 0, 0, 0, 0, 0, 0, 0, 17, 17,
255 0, 0, 17, 17, 17, 17, 17, 17, 17, 14,
256 14, 0, 0, 14, 14, 14, 14, 14, 14, 14,
257 29, 29, 0, 0, 29, 29, 29, 29, 29, 29,
258 29, 24, 24, 0, 0, 24, 24, 24, 24, 24,
259 24, 24, 20, 20, 0, 0, 20, 20, 20, 20,
260 20, 20, 20, 40, 40, 0, 0, 40, 40, 40,
261 40, 0, 40, 40, 26, 26, 0, 39, 26, 26,
262 26, 26, 0, 0, 26, 39, 39,
263 };
264 short yycheck[] = { 47,
265 0, 58, 261, 266, 267, 44, 267, 266, 258, 259,
266 58, 0, 262, 263, 264, 265, 266, 267, 268, 257,
267 269, 262, 0, 264, 265, 44, 266, 47, 267, 47,
268 267, 267, 267, 0, 267, -1, -1, -1, -1, -1,
269 -1, -1, -1, -1, 0, -1, -1, -1, -1, -1,
270 -1, -1, -1, -1, -1, 0, -1, -1, -1, -1,
271 -1, -1, -1, -1, -1, -1, 0, -1, 0, -1,
272 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
273 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
274 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
275 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
276 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
277 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
278 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
279 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
280 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
281 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
282 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
283 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
284 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
285 -1, -1, -1, -1, 261, -1, -1, -1, -1, 266,
286 258, -1, -1, 261, 262, 263, 264, 265, 266, -1,
287 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
288 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
289 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
290 -1, -1, -1, -1, -1, -1, -1, -1, 258, 259,
291 -1, -1, 262, 263, 264, 265, 266, 267, 268, 258,
292 259, -1, -1, 262, 263, 264, 265, 266, 267, 268,
293 258, 259, -1, -1, 262, 263, 264, 265, 266, 267,
294 268, 258, 259, -1, -1, 262, 263, 264, 265, 266,
295 267, 268, 258, 259, -1, -1, 262, 263, 264, 265,
296 266, 267, 268, 258, 259, -1, -1, 262, 263, 264,
297 265, -1, 267, 268, 258, 259, -1, 259, 262, 263,
298 264, 265, -1, -1, 268, 267, 268,
299 };
300 #define YYFINAL 1
301 #ifndef YYDEBUG
302 #define YYDEBUG 0
303 #endif
304 #define YYMAXTOKEN 269
305 #if YYDEBUG
306 char *yyname[] = {
307 "end-of-file",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
308 0,0,0,0,0,0,0,0,0,0,"','",0,0,"'/'",0,0,0,0,0,0,0,0,0,0,"':'",0,0,0,0,0,0,0,0,0,
309 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
310 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
311 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
312 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
313 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,"tAGO","tDAY",
314 "tDAYZONE","tID","tMERIDIAN","tMINUTE_UNIT","tMONTH","tMONTH_UNIT","tSEC_UNIT",
315 "tSNUMBER","tUNUMBER","tZONE","tDST",
316 };
317 char *yyrule[] = {
318 "$accept : spec",
319 "spec :",
320 "spec : spec item",
321 "item : time",
322 "item : zone",
323 "item : date",
324 "item : day",
325 "item : rel",
326 "item : number",
327 "time : tUNUMBER tMERIDIAN",
328 "time : tUNUMBER ':' tUNUMBER o_merid",
329 "time : tUNUMBER ':' tUNUMBER tSNUMBER",
330 "time : tUNUMBER ':' tUNUMBER ':' tUNUMBER o_merid",
331 "time : tUNUMBER ':' tUNUMBER ':' tUNUMBER tSNUMBER",
332 "zone : tZONE",
333 "zone : tDAYZONE",
334 "zone : tZONE tDST",
335 "day : tDAY",
336 "day : tDAY ','",
337 "day : tUNUMBER tDAY",
338 "date : tUNUMBER '/' tUNUMBER",
339 "date : tUNUMBER '/' tUNUMBER '/' tUNUMBER",
340 "date : tUNUMBER tSNUMBER tSNUMBER",
341 "date : tUNUMBER tMONTH tSNUMBER",
342 "date : tMONTH tUNUMBER",
343 "date : tMONTH tUNUMBER ',' tUNUMBER",
344 "date : tUNUMBER tMONTH",
345 "date : tUNUMBER tMONTH tUNUMBER",
346 "rel : relunit tAGO",
347 "rel : relunit",
348 "relunit : tUNUMBER tMINUTE_UNIT",
349 "relunit : tSNUMBER tMINUTE_UNIT",
350 "relunit : tMINUTE_UNIT",
351 "relunit : tSNUMBER tSEC_UNIT",
352 "relunit : tUNUMBER tSEC_UNIT",
353 "relunit : tSEC_UNIT",
354 "relunit : tSNUMBER tMONTH_UNIT",
355 "relunit : tUNUMBER tMONTH_UNIT",
356 "relunit : tMONTH_UNIT",
357 "number : tUNUMBER",
358 "o_merid :",
359 "o_merid : tMERIDIAN",
360 };
361 #endif
362 #ifdef YYSTACKSIZE
363 #undef YYMAXDEPTH
364 #define YYMAXDEPTH YYSTACKSIZE
365 #else
366 #ifdef YYMAXDEPTH
367 #define YYSTACKSIZE YYMAXDEPTH
368 #else
369 #define YYSTACKSIZE 10000
370 #define YYMAXDEPTH 10000
371 #endif
372 #endif
373 #define YYINITSTACKSIZE 200
374 int yydebug;
375 int yynerrs;
376 int yyerrflag;
377 int yychar;
378 short *yyssp;
379 YYSTYPE *yyvsp;
380 YYSTYPE yyval;
381 YYSTYPE yylval;
382 short *yyss;
383 short *yysslim;
384 YYSTYPE *yyvs;
385 int yystacksize;
386 #line 369 "getdate.y"
387
388 /* Month and day table. */
389 static TABLE const MonthDayTable[] = {
390 { "january", tMONTH, 1 },
391 { "february", tMONTH, 2 },
392 { "march", tMONTH, 3 },
393 { "april", tMONTH, 4 },
394 { "may", tMONTH, 5 },
395 { "june", tMONTH, 6 },
396 { "july", tMONTH, 7 },
397 { "august", tMONTH, 8 },
398 { "september", tMONTH, 9 },
399 { "sept", tMONTH, 9 },
400 { "october", tMONTH, 10 },
401 { "november", tMONTH, 11 },
402 { "december", tMONTH, 12 },
403 { "sunday", tDAY, 0 },
404 { "monday", tDAY, 1 },
405 { "tuesday", tDAY, 2 },
406 { "tues", tDAY, 2 },
407 { "wednesday", tDAY, 3 },
408 { "wednes", tDAY, 3 },
409 { "thursday", tDAY, 4 },
410 { "thur", tDAY, 4 },
411 { "thurs", tDAY, 4 },
412 { "friday", tDAY, 5 },
413 { "saturday", tDAY, 6 },
414 { NULL }
415 };
416
417 /* Time units table. */
418 static TABLE const UnitsTable[] = {
419 { "year", tMONTH_UNIT, 12 },
420 { "month", tMONTH_UNIT, 1 },
421 { "fortnight", tMINUTE_UNIT, 14 * 24 * 60 },
422 { "week", tMINUTE_UNIT, 7 * 24 * 60 },
423 { "day", tMINUTE_UNIT, 1 * 24 * 60 },
424 { "hour", tMINUTE_UNIT, 60 },
425 { "minute", tMINUTE_UNIT, 1 },
426 { "min", tMINUTE_UNIT, 1 },
427 { "second", tSEC_UNIT, 1 },
428 { "sec", tSEC_UNIT, 1 },
429 { NULL }
430 };
431
432 /* Assorted relative-time words. */
433 static TABLE const OtherTable[] = {
434 { "tomorrow", tMINUTE_UNIT, 1 * 24 * 60 },
435 { "yesterday", tMINUTE_UNIT, -1 * 24 * 60 },
436 { "today", tMINUTE_UNIT, 0 },
437 { "now", tMINUTE_UNIT, 0 },
438 { "last", tUNUMBER, -1 },
439 { "this", tMINUTE_UNIT, 0 },
440 { "next", tUNUMBER, 2 },
441 { "first", tUNUMBER, 1 },
442 /* { "second", tUNUMBER, 2 }, */
443 { "third", tUNUMBER, 3 },
444 { "fourth", tUNUMBER, 4 },
445 { "fifth", tUNUMBER, 5 },
446 { "sixth", tUNUMBER, 6 },
447 { "seventh", tUNUMBER, 7 },
448 { "eighth", tUNUMBER, 8 },
449 { "ninth", tUNUMBER, 9 },
450 { "tenth", tUNUMBER, 10 },
451 { "eleventh", tUNUMBER, 11 },
452 { "twelfth", tUNUMBER, 12 },
453 { "ago", tAGO, 1 },
454 { NULL }
455 };
456
457 /* The timezone table. */
458 /* Some of these are commented out because a time_t can't store a float. */
459 static TABLE const TimezoneTable[] = {
460 { "gmt", tZONE, HOUR( 0) }, /* Greenwich Mean */
461 { "ut", tZONE, HOUR( 0) }, /* Universal (Coordinated) */
462 { "utc", tZONE, HOUR( 0) },
463 { "wet", tZONE, HOUR( 0) }, /* Western European */
464 { "bst", tDAYZONE, HOUR( 0) }, /* British Summer */
465 { "wat", tZONE, HOUR( 1) }, /* West Africa */
466 { "at", tZONE, HOUR( 2) }, /* Azores */
467 #if 0
468 /* For completeness. BST is also British Summer, and GST is
469 * also Guam Standard. */
470 { "bst", tZONE, HOUR( 3) }, /* Brazil Standard */
471 { "gst", tZONE, HOUR( 3) }, /* Greenland Standard */
472 #endif
473 #if 0
474 { "nft", tZONE, HOUR(3.5) }, /* Newfoundland */
475 { "nst", tZONE, HOUR(3.5) }, /* Newfoundland Standard */
476 { "ndt", tDAYZONE, HOUR(3.5) }, /* Newfoundland Daylight */
477 #endif
478 { "ast", tZONE, HOUR( 4) }, /* Atlantic Standard */
479 { "adt", tDAYZONE, HOUR( 4) }, /* Atlantic Daylight */
480 { "est", tZONE, HOUR( 5) }, /* Eastern Standard */
481 { "edt", tDAYZONE, HOUR( 5) }, /* Eastern Daylight */
482 { "cst", tZONE, HOUR( 6) }, /* Central Standard */
483 { "cdt", tDAYZONE, HOUR( 6) }, /* Central Daylight */
484 { "mst", tZONE, HOUR( 7) }, /* Mountain Standard */
485 { "mdt", tDAYZONE, HOUR( 7) }, /* Mountain Daylight */
486 { "pst", tZONE, HOUR( 8) }, /* Pacific Standard */
487 { "pdt", tDAYZONE, HOUR( 8) }, /* Pacific Daylight */
488 { "yst", tZONE, HOUR( 9) }, /* Yukon Standard */
489 { "ydt", tDAYZONE, HOUR( 9) }, /* Yukon Daylight */
490 { "hst", tZONE, HOUR(10) }, /* Hawaii Standard */
491 { "hdt", tDAYZONE, HOUR(10) }, /* Hawaii Daylight */
492 { "cat", tZONE, HOUR(10) }, /* Central Alaska */
493 { "ahst", tZONE, HOUR(10) }, /* Alaska-Hawaii Standard */
494 { "nt", tZONE, HOUR(11) }, /* Nome */
495 { "idlw", tZONE, HOUR(12) }, /* International Date Line West */
496 { "cet", tZONE, -HOUR(1) }, /* Central European */
497 { "met", tZONE, -HOUR(1) }, /* Middle European */
498 { "mewt", tZONE, -HOUR(1) }, /* Middle European Winter */
499 { "mest", tDAYZONE, -HOUR(1) }, /* Middle European Summer */
500 { "swt", tZONE, -HOUR(1) }, /* Swedish Winter */
501 { "sst", tDAYZONE, -HOUR(1) }, /* Swedish Summer */
502 { "fwt", tZONE, -HOUR(1) }, /* French Winter */
503 { "fst", tDAYZONE, -HOUR(1) }, /* French Summer */
504 { "eet", tZONE, -HOUR(2) }, /* Eastern Europe, USSR Zone 1 */
505 { "bt", tZONE, -HOUR(3) }, /* Baghdad, USSR Zone 2 */
506 #if 0
507 { "it", tZONE, -HOUR(3.5) },/* Iran */
508 #endif
509 { "zp4", tZONE, -HOUR(4) }, /* USSR Zone 3 */
510 { "zp5", tZONE, -HOUR(5) }, /* USSR Zone 4 */
511 #if 0
512 { "ist", tZONE, -HOUR(5.5) },/* Indian Standard */
513 #endif
514 { "zp6", tZONE, -HOUR(6) }, /* USSR Zone 5 */
515 #if 0
516 /* For completeness. NST is also Newfoundland Stanard, and SST is
517 * also Swedish Summer. */
518 { "nst", tZONE, -HOUR(6.5) },/* North Sumatra */
519 { "sst", tZONE, -HOUR(7) }, /* South Sumatra, USSR Zone 6 */
520 #endif /* 0 */
521 { "wast", tZONE, -HOUR(7) }, /* West Australian Standard */
522 { "wadt", tDAYZONE, -HOUR(7) }, /* West Australian Daylight */
523 #if 0
524 { "jt", tZONE, -HOUR(7.5) },/* Java (3pm in Cronusland!) */
525 #endif
526 { "cct", tZONE, -HOUR(8) }, /* China Coast, USSR Zone 7 */
527 { "jst", tZONE, -HOUR(9) }, /* Japan Standard, USSR Zone 8 */
528 #if 0
529 { "cast", tZONE, -HOUR(9.5) },/* Central Australian Standard */
530 { "cadt", tDAYZONE, -HOUR(9.5) },/* Central Australian Daylight */
531 #endif
532 { "east", tZONE, -HOUR(10) }, /* Eastern Australian Standard */
533 { "eadt", tDAYZONE, -HOUR(10) }, /* Eastern Australian Daylight */
534 { "gst", tZONE, -HOUR(10) }, /* Guam Standard, USSR Zone 9 */
535 { "nzt", tZONE, -HOUR(12) }, /* New Zealand */
536 { "nzst", tZONE, -HOUR(12) }, /* New Zealand Standard */
537 { "nzdt", tDAYZONE, -HOUR(12) }, /* New Zealand Daylight */
538 { "idle", tZONE, -HOUR(12) }, /* International Date Line East */
539 { NULL }
540 };
541
542 /* Military timezone table. */
543 static TABLE const MilitaryTable[] = {
544 { "a", tZONE, HOUR( 1) },
545 { "b", tZONE, HOUR( 2) },
546 { "c", tZONE, HOUR( 3) },
547 { "d", tZONE, HOUR( 4) },
548 { "e", tZONE, HOUR( 5) },
549 { "f", tZONE, HOUR( 6) },
550 { "g", tZONE, HOUR( 7) },
551 { "h", tZONE, HOUR( 8) },
552 { "i", tZONE, HOUR( 9) },
553 { "k", tZONE, HOUR( 10) },
554 { "l", tZONE, HOUR( 11) },
555 { "m", tZONE, HOUR( 12) },
556 { "n", tZONE, HOUR(- 1) },
557 { "o", tZONE, HOUR(- 2) },
558 { "p", tZONE, HOUR(- 3) },
559 { "q", tZONE, HOUR(- 4) },
560 { "r", tZONE, HOUR(- 5) },
561 { "s", tZONE, HOUR(- 6) },
562 { "t", tZONE, HOUR(- 7) },
563 { "u", tZONE, HOUR(- 8) },
564 { "v", tZONE, HOUR(- 9) },
565 { "w", tZONE, HOUR(-10) },
566 { "x", tZONE, HOUR(-11) },
567 { "y", tZONE, HOUR(-12) },
568 { "z", tZONE, HOUR( 0) },
569 { NULL }
570 };
571
572 \f
573
574
575 /* ARGSUSED */
576 static int
577 yyerror(s)
578 char *s;
579 {
580 return 0;
581 }
582
583
584 static time_t
585 ToSeconds(Hours, Minutes, Seconds, Meridian)
586 time_t Hours;
587 time_t Minutes;
588 time_t Seconds;
589 MERIDIAN Meridian;
590 {
591 if (Minutes < 0 || Minutes > 59 || Seconds < 0 || Seconds > 59)
592 return -1;
593 switch (Meridian) {
594 case MER24:
595 if (Hours < 0 || Hours > 23)
596 return -1;
597 return (Hours * 60L + Minutes) * 60L + Seconds;
598 case MERam:
599 if (Hours < 1 || Hours > 12)
600 return -1;
601 if (Hours == 12)
602 Hours = 0;
603 return (Hours * 60L + Minutes) * 60L + Seconds;
604 case MERpm:
605 if (Hours < 1 || Hours > 12)
606 return -1;
607 if (Hours == 12)
608 Hours = 0;
609 return ((Hours + 12) * 60L + Minutes) * 60L + Seconds;
610 default:
611 abort ();
612 }
613 /* NOTREACHED */
614 }
615
616
617 /* Year is either
618 * A negative number, which means to use its absolute value (why?)
619 * A number from 0 to 99, which means a year from 1900 to 1999, or
620 * The actual year (>=100). */
621 static time_t
622 Convert(Month, Day, Year, Hours, Minutes, Seconds, Meridian, DSTmode)
623 time_t Month;
624 time_t Day;
625 time_t Year;
626 time_t Hours;
627 time_t Minutes;
628 time_t Seconds;
629 MERIDIAN Meridian;
630 DSTMODE DSTmode;
631 {
632 static int DaysInMonth[12] = {
633 31, 0, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
634 };
635 time_t tod;
636 time_t Julian;
637 int i;
638
639 if (Year < 0)
640 Year = -Year;
641 if (Year < 69)
642 Year += 2000;
643 else if (Year < 100)
644 Year += 1900;
645 DaysInMonth[1] = Year % 4 == 0 && (Year % 100 != 0 || Year % 400 == 0)
646 ? 29 : 28;
647 /* Checking for 2038 bogusly assumes that time_t is 32 bits. But
648 I'm too lazy to try to check for time_t overflow in another way. */
649 if (Year < EPOCH || Year > 2038
650 || Month < 1 || Month > 12
651 /* Lint fluff: "conversion from long may lose accuracy" */
652 || Day < 1 || Day > DaysInMonth[(int)--Month])
653 return -1;
654
655 for (Julian = Day - 1, i = 0; i < Month; i++)
656 Julian += DaysInMonth[i];
657 for (i = EPOCH; i < Year; i++)
658 Julian += 365 + (i % 4 == 0);
659 Julian *= SECSPERDAY;
660 Julian += yyTimezone * 60L;
661 if ((tod = ToSeconds(Hours, Minutes, Seconds, Meridian)) < 0)
662 return -1;
663 Julian += tod;
664 if (DSTmode == DSTon
665 || (DSTmode == DSTmaybe && localtime(&Julian)->tm_isdst))
666 Julian -= 60 * 60;
667 return Julian;
668 }
669
670
671 static time_t
672 DSTcorrect(Start, Future)
673 time_t Start;
674 time_t Future;
675 {
676 time_t StartDay;
677 time_t FutureDay;
678
679 StartDay = (localtime(&Start)->tm_hour + 1) % 24;
680 FutureDay = (localtime(&Future)->tm_hour + 1) % 24;
681 return (Future - Start) + (StartDay - FutureDay) * 60L * 60L;
682 }
683
684
685 static time_t
686 RelativeDate(Start, DayOrdinal, DayNumber)
687 time_t Start;
688 time_t DayOrdinal;
689 time_t DayNumber;
690 {
691 struct tm *tm;
692 time_t now;
693
694 now = Start;
695 tm = localtime(&now);
696 now += SECSPERDAY * ((DayNumber - tm->tm_wday + 7) % 7);
697 now += 7 * SECSPERDAY * (DayOrdinal <= 0 ? DayOrdinal : DayOrdinal - 1);
698 return DSTcorrect(Start, now);
699 }
700
701
702 static time_t
703 RelativeMonth(Start, RelMonth)
704 time_t Start;
705 time_t RelMonth;
706 {
707 struct tm *tm;
708 time_t Month;
709 time_t Year;
710
711 if (RelMonth == 0)
712 return 0;
713 tm = localtime(&Start);
714 Month = 12 * (tm->tm_year + 1900) + tm->tm_mon + RelMonth;
715 Year = Month / 12;
716 Month = Month % 12 + 1;
717 return DSTcorrect(Start,
718 Convert(Month, (time_t)tm->tm_mday, Year,
719 (time_t)tm->tm_hour, (time_t)tm->tm_min, (time_t)tm->tm_sec,
720 MER24, DSTmaybe));
721 }
722
723
724 static int
725 LookupWord(buff)
726 char *buff;
727 {
728 register char *p;
729 register char *q;
730 register const TABLE *tp;
731 int i;
732 int abbrev;
733
734 /* Make it lowercase. */
735 for (p = buff; *p; p++)
736 if (isupper(*p))
737 *p = tolower(*p);
738
739 if (strcmp(buff, "am") == 0 || strcmp(buff, "a.m.") == 0) {
740 yylval.Meridian = MERam;
741 return tMERIDIAN;
742 }
743 if (strcmp(buff, "pm") == 0 || strcmp(buff, "p.m.") == 0) {
744 yylval.Meridian = MERpm;
745 return tMERIDIAN;
746 }
747
748 /* See if we have an abbreviation for a month. */
749 if (strlen(buff) == 3)
750 abbrev = 1;
751 else if (strlen(buff) == 4 && buff[3] == '.') {
752 abbrev = 1;
753 buff[3] = '\0';
754 }
755 else
756 abbrev = 0;
757
758 for (tp = MonthDayTable; tp->name; tp++) {
759 if (abbrev) {
760 if (strncmp(buff, tp->name, 3) == 0) {
761 yylval.Number = tp->value;
762 return tp->type;
763 }
764 }
765 else if (strcmp(buff, tp->name) == 0) {
766 yylval.Number = tp->value;
767 return tp->type;
768 }
769 }
770
771 for (tp = TimezoneTable; tp->name; tp++)
772 if (strcmp(buff, tp->name) == 0) {
773 yylval.Number = tp->value;
774 return tp->type;
775 }
776
777 if (strcmp(buff, "dst") == 0)
778 return tDST;
779
780 for (tp = UnitsTable; tp->name; tp++)
781 if (strcmp(buff, tp->name) == 0) {
782 yylval.Number = tp->value;
783 return tp->type;
784 }
785
786 /* Strip off any plural and try the units table again. */
787 i = strlen(buff) - 1;
788 if (buff[i] == 's') {
789 buff[i] = '\0';
790 for (tp = UnitsTable; tp->name; tp++)
791 if (strcmp(buff, tp->name) == 0) {
792 yylval.Number = tp->value;
793 return tp->type;
794 }
795 buff[i] = 's'; /* Put back for "this" in OtherTable. */
796 }
797
798 for (tp = OtherTable; tp->name; tp++)
799 if (strcmp(buff, tp->name) == 0) {
800 yylval.Number = tp->value;
801 return tp->type;
802 }
803
804 /* Military timezones. */
805 if (buff[1] == '\0' && isalpha(*buff)) {
806 for (tp = MilitaryTable; tp->name; tp++)
807 if (strcmp(buff, tp->name) == 0) {
808 yylval.Number = tp->value;
809 return tp->type;
810 }
811 }
812
813 /* Drop out any periods and try the timezone table again. */
814 for (i = 0, p = q = buff; *q; q++)
815 if (*q != '.')
816 *p++ = *q;
817 else
818 i++;
819 *p = '\0';
820 if (i)
821 for (tp = TimezoneTable; tp->name; tp++)
822 if (strcmp(buff, tp->name) == 0) {
823 yylval.Number = tp->value;
824 return tp->type;
825 }
826
827 return tID;
828 }
829
830
831 static int
832 yylex()
833 {
834 register char c;
835 register char *p;
836 char buff[20];
837 int Count;
838 int sign;
839
840 for ( ; ; ) {
841 while (isspace(*yyInput))
842 yyInput++;
843
844 if (isdigit(c = *yyInput) || c == '-' || c == '+') {
845 if (c == '-' || c == '+') {
846 sign = c == '-' ? -1 : 1;
847 if (!isdigit(*++yyInput))
848 /* skip the '-' sign */
849 continue;
850 }
851 else
852 sign = 0;
853 for (yylval.Number = 0; isdigit(c = *yyInput++); )
854 yylval.Number = 10 * yylval.Number + c - '0';
855 yyInput--;
856 if (sign < 0)
857 yylval.Number = -yylval.Number;
858 return sign ? tSNUMBER : tUNUMBER;
859 }
860 if (isalpha(c)) {
861 for (p = buff; isalpha(c = *yyInput++) || c == '.'; )
862 if (p < &buff[sizeof buff - 1])
863 *p++ = c;
864 *p = '\0';
865 yyInput--;
866 return LookupWord(buff);
867 }
868 if (c != '(')
869 return *yyInput++;
870 Count = 0;
871 do {
872 c = *yyInput++;
873 if (c == '\0')
874 return c;
875 if (c == '(')
876 Count++;
877 else if (c == ')')
878 Count--;
879 } while (Count > 0);
880 }
881 }
882
883 #define TM_YEAR_ORIGIN 1900
884
885 /* Yield A - B, measured in seconds. */
886 static long
887 difftm (a, b)
888 struct tm *a, *b;
889 {
890 int ay = a->tm_year + (TM_YEAR_ORIGIN - 1);
891 int by = b->tm_year + (TM_YEAR_ORIGIN - 1);
892 int days = (
893 /* difference in day of year */
894 a->tm_yday - b->tm_yday
895 /* + intervening leap days */
896 + ((ay >> 2) - (by >> 2))
897 - (ay/100 - by/100)
898 + ((ay/100 >> 2) - (by/100 >> 2))
899 /* + difference in years * 365 */
900 + (long)(ay-by) * 365
901 );
902 return (60*(60*(24*days + (a->tm_hour - b->tm_hour))
903 + (a->tm_min - b->tm_min))
904 + (a->tm_sec - b->tm_sec));
905 }
906
907 time_t
908 get_date(p, now)
909 char *p;
910 struct timeb *now;
911 {
912 struct tm *tm, gmt;
913 struct timeb ftz;
914 time_t Start;
915 time_t tod;
916 time_t nowtime;
917
918 yyInput = p;
919 if (now == NULL) {
920 struct tm *gmt_ptr;
921
922 now = &ftz;
923 (void)time (&nowtime);
924
925 gmt_ptr = gmtime (&nowtime);
926 if (gmt_ptr != NULL)
927 {
928 /* Make a copy, in case localtime modifies *tm (I think
929 that comment now applies to *gmt_ptr, but I am too
930 lazy to dig into how gmtime and locatime allocate the
931 structures they return pointers to). */
932 gmt = *gmt_ptr;
933 }
934
935 if (! (tm = localtime (&nowtime)))
936 return -1;
937
938 if (gmt_ptr != NULL)
939 ftz.timezone = difftm (&gmt, tm) / 60;
940 else
941 /* We are on a system like VMS, where the system clock is
942 in local time and the system has no concept of timezones.
943 Hopefully we can fake this out (for the case in which the
944 user specifies no timezone) by just saying the timezone
945 is zero. */
946 ftz.timezone = 0;
947
948 if(tm->tm_isdst)
949 ftz.timezone += 60;
950 }
951 else
952 {
953 nowtime = now->time;
954 }
955
956 tm = localtime(&nowtime);
957 yyYear = tm->tm_year + 1900;
958 yyMonth = tm->tm_mon + 1;
959 yyDay = tm->tm_mday;
960 yyTimezone = now->timezone;
961 yyDSTmode = DSTmaybe;
962 yyHour = 0;
963 yyMinutes = 0;
964 yySeconds = 0;
965 yyMeridian = MER24;
966 yyRelSeconds = 0;
967 yyRelMonth = 0;
968 yyHaveDate = 0;
969 yyHaveDay = 0;
970 yyHaveRel = 0;
971 yyHaveTime = 0;
972 yyHaveZone = 0;
973
974 if (yyparse()
975 || yyHaveTime > 1 || yyHaveZone > 1 || yyHaveDate > 1 || yyHaveDay > 1)
976 return -1;
977
978 if (yyHaveDate || yyHaveTime || yyHaveDay) {
979 Start = Convert(yyMonth, yyDay, yyYear, yyHour, yyMinutes, yySeconds,
980 yyMeridian, yyDSTmode);
981 if (Start < 0)
982 return -1;
983 }
984 else {
985 Start = nowtime;
986 if (!yyHaveRel)
987 Start -= ((tm->tm_hour * 60L + tm->tm_min) * 60L) + tm->tm_sec;
988 }
989
990 Start += yyRelSeconds;
991 Start += RelativeMonth(Start, yyRelMonth);
992
993 if (yyHaveDay && !yyHaveDate) {
994 tod = RelativeDate(Start, yyDayOrdinal, yyDayNumber);
995 Start += tod;
996 }
997
998 /* Have to do *something* with a legitimate -1 so it's distinguishable
999 * from the error return value. (Alternately could set errno on error.) */
1000 return Start == -1 ? 0 : Start;
1001 }
1002
1003
1004 #if defined(TEST)
1005
1006 /* ARGSUSED */
1007 int
1008 main(ac, av)
1009 int ac;
1010 char *av[];
1011 {
1012 char buff[128];
1013 time_t d;
1014
1015 (void)printf("Enter date, or blank line to exit.\n\t> ");
1016 (void)fflush(stdout);
1017 while (gets(buff) && buff[0]) {
1018 d = get_date(buff, (struct timeb *)NULL);
1019 if (d == -1)
1020 (void)printf("Bad format - couldn't convert.\n");
1021 else
1022 (void)printf("%s", ctime(&d));
1023 (void)printf("\t> ");
1024 (void)fflush(stdout);
1025 }
1026 exit(0);
1027 /* NOTREACHED */
1028 }
1029 #endif /* defined(TEST) */
1030 #line 1031 "y.tab.c"
1031 /* allocate initial stack or double stack size, up to YYMAXDEPTH */
1032 int yyparse __P((void));
1033 static int yygrowstack __P((void));
1034 static int yygrowstack()
1035 {
1036 int newsize, i;
1037 short *newss;
1038 YYSTYPE *newvs;
1039
1040 if ((newsize = yystacksize) == 0)
1041 newsize = YYINITSTACKSIZE;
1042 else if (newsize >= YYMAXDEPTH)
1043 return -1;
1044 else if ((newsize *= 2) > YYMAXDEPTH)
1045 newsize = YYMAXDEPTH;
1046 i = yyssp - yyss;
1047 if ((newss = (short *)realloc(yyss, newsize * sizeof *newss)) == NULL)
1048 return -1;
1049 yyss = newss;
1050 yyssp = newss + i;
1051 if ((newvs = (YYSTYPE *)realloc(yyvs, newsize * sizeof *newvs)) == NULL)
1052 return -1;
1053 yyvs = newvs;
1054 yyvsp = newvs + i;
1055 yystacksize = newsize;
1056 yysslim = yyss + newsize - 1;
1057 return 0;
1058 }
1059
1060 #define YYABORT goto yyabort
1061 #define YYREJECT goto yyabort
1062 #define YYACCEPT goto yyaccept
1063 #define YYERROR goto yyerrlab
1064 int
1065 yyparse()
1066 {
1067 int yym, yyn, yystate;
1068 #if YYDEBUG
1069 char *yys;
1070
1071 if ((yys = getenv("YYDEBUG")) != NULL)
1072 {
1073 yyn = *yys;
1074 if (yyn >= '0' && yyn <= '9')
1075 yydebug = yyn - '0';
1076 }
1077 #endif
1078
1079 yynerrs = 0;
1080 yyerrflag = 0;
1081 yychar = (-1);
1082
1083 if (yyss == NULL && yygrowstack()) goto yyoverflow;
1084 yyssp = yyss;
1085 yyvsp = yyvs;
1086 *yyssp = yystate = 0;
1087
1088 yyloop:
1089 if ((yyn = yydefred[yystate]) != 0) goto yyreduce;
1090 if (yychar < 0)
1091 {
1092 if ((yychar = yylex()) < 0) yychar = 0;
1093 #if YYDEBUG
1094 if (yydebug)
1095 {
1096 yys = 0;
1097 if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
1098 if (!yys) yys = "illegal-symbol";
1099 printf("%sdebug: state %d, reading %d (%s)\n",
1100 YYPREFIX, yystate, yychar, yys);
1101 }
1102 #endif
1103 }
1104 if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 &&
1105 yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
1106 {
1107 #if YYDEBUG
1108 if (yydebug)
1109 printf("%sdebug: state %d, shifting to state %d\n",
1110 YYPREFIX, yystate, yytable[yyn]);
1111 #endif
1112 if (yyssp >= yysslim && yygrowstack())
1113 {
1114 goto yyoverflow;
1115 }
1116 *++yyssp = yystate = yytable[yyn];
1117 *++yyvsp = yylval;
1118 yychar = (-1);
1119 if (yyerrflag > 0) --yyerrflag;
1120 goto yyloop;
1121 }
1122 if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 &&
1123 yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
1124 {
1125 yyn = yytable[yyn];
1126 goto yyreduce;
1127 }
1128 if (yyerrflag) goto yyinrecovery;
1129 goto yynewerror;
1130 yynewerror:
1131 yyerror("syntax error");
1132 goto yyerrlab;
1133 yyerrlab:
1134 ++yynerrs;
1135 yyinrecovery:
1136 if (yyerrflag < 3)
1137 {
1138 yyerrflag = 3;
1139 for (;;)
1140 {
1141 if ((yyn = yysindex[*yyssp]) && (yyn += YYERRCODE) >= 0 &&
1142 yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE)
1143 {
1144 #if YYDEBUG
1145 if (yydebug)
1146 printf("%sdebug: state %d, error recovery shifting\
1147 to state %d\n", YYPREFIX, *yyssp, yytable[yyn]);
1148 #endif
1149 if (yyssp >= yysslim && yygrowstack())
1150 {
1151 goto yyoverflow;
1152 }
1153 *++yyssp = yystate = yytable[yyn];
1154 *++yyvsp = yylval;
1155 goto yyloop;
1156 }
1157 else
1158 {
1159 #if YYDEBUG
1160 if (yydebug)
1161 printf("%sdebug: error recovery discarding state %d\n",
1162 YYPREFIX, *yyssp);
1163 #endif
1164 if (yyssp <= yyss) goto yyabort;
1165 --yyssp;
1166 --yyvsp;
1167 }
1168 }
1169 }
1170 else
1171 {
1172 if (yychar == 0) goto yyabort;
1173 #if YYDEBUG
1174 if (yydebug)
1175 {
1176 yys = 0;
1177 if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
1178 if (!yys) yys = "illegal-symbol";
1179 printf("%sdebug: state %d, error recovery discards token %d (%s)\n",
1180 YYPREFIX, yystate, yychar, yys);
1181 }
1182 #endif
1183 yychar = (-1);
1184 goto yyloop;
1185 }
1186 yyreduce:
1187 #if YYDEBUG
1188 if (yydebug)
1189 printf("%sdebug: state %d, reducing by rule %d (%s)\n",
1190 YYPREFIX, yystate, yyn, yyrule[yyn]);
1191 #endif
1192 yym = yylen[yyn];
1193 yyval = yyvsp[1-yym];
1194 switch (yyn)
1195 {
1196 case 3:
1197 #line 168 "getdate.y"
1198 {
1199 yyHaveTime++;
1200 }
1201 break;
1202 case 4:
1203 #line 171 "getdate.y"
1204 {
1205 yyHaveZone++;
1206 }
1207 break;
1208 case 5:
1209 #line 174 "getdate.y"
1210 {
1211 yyHaveDate++;
1212 }
1213 break;
1214 case 6:
1215 #line 177 "getdate.y"
1216 {
1217 yyHaveDay++;
1218 }
1219 break;
1220 case 7:
1221 #line 180 "getdate.y"
1222 {
1223 yyHaveRel++;
1224 }
1225 break;
1226 case 9:
1227 #line 186 "getdate.y"
1228 {
1229 yyHour = yyvsp[-1].Number;
1230 yyMinutes = 0;
1231 yySeconds = 0;
1232 yyMeridian = yyvsp[0].Meridian;
1233 }
1234 break;
1235 case 10:
1236 #line 192 "getdate.y"
1237 {
1238 yyHour = yyvsp[-3].Number;
1239 yyMinutes = yyvsp[-1].Number;
1240 yySeconds = 0;
1241 yyMeridian = yyvsp[0].Meridian;
1242 }
1243 break;
1244 case 11:
1245 #line 198 "getdate.y"
1246 {
1247 yyHour = yyvsp[-3].Number;
1248 yyMinutes = yyvsp[-1].Number;
1249 yyMeridian = MER24;
1250 yyDSTmode = DSToff;
1251 yyTimezone = - (yyvsp[0].Number % 100 + (yyvsp[0].Number / 100) * 60);
1252 }
1253 break;
1254 case 12:
1255 #line 205 "getdate.y"
1256 {
1257 yyHour = yyvsp[-5].Number;
1258 yyMinutes = yyvsp[-3].Number;
1259 yySeconds = yyvsp[-1].Number;
1260 yyMeridian = yyvsp[0].Meridian;
1261 }
1262 break;
1263 case 13:
1264 #line 211 "getdate.y"
1265 {
1266 yyHour = yyvsp[-5].Number;
1267 yyMinutes = yyvsp[-3].Number;
1268 yySeconds = yyvsp[-1].Number;
1269 yyMeridian = MER24;
1270 yyDSTmode = DSToff;
1271 yyTimezone = - (yyvsp[0].Number % 100 + (yyvsp[0].Number / 100) * 60);
1272 }
1273 break;
1274 case 14:
1275 #line 221 "getdate.y"
1276 {
1277 yyTimezone = yyvsp[0].Number;
1278 yyDSTmode = DSToff;
1279 }
1280 break;
1281 case 15:
1282 #line 225 "getdate.y"
1283 {
1284 yyTimezone = yyvsp[0].Number;
1285 yyDSTmode = DSTon;
1286 }
1287 break;
1288 case 16:
1289 #line 230 "getdate.y"
1290 {
1291 yyTimezone = yyvsp[-1].Number;
1292 yyDSTmode = DSTon;
1293 }
1294 break;
1295 case 17:
1296 #line 236 "getdate.y"
1297 {
1298 yyDayOrdinal = 1;
1299 yyDayNumber = yyvsp[0].Number;
1300 }
1301 break;
1302 case 18:
1303 #line 240 "getdate.y"
1304 {
1305 yyDayOrdinal = 1;
1306 yyDayNumber = yyvsp[-1].Number;
1307 }
1308 break;
1309 case 19:
1310 #line 244 "getdate.y"
1311 {
1312 yyDayOrdinal = yyvsp[-1].Number;
1313 yyDayNumber = yyvsp[0].Number;
1314 }
1315 break;
1316 case 20:
1317 #line 250 "getdate.y"
1318 {
1319 yyMonth = yyvsp[-2].Number;
1320 yyDay = yyvsp[0].Number;
1321 }
1322 break;
1323 case 21:
1324 #line 254 "getdate.y"
1325 {
1326 if (yyvsp[-4].Number >= 100) {
1327 yyYear = yyvsp[-4].Number;
1328 yyMonth = yyvsp[-2].Number;
1329 yyDay = yyvsp[0].Number;
1330 } else {
1331 yyMonth = yyvsp[-4].Number;
1332 yyDay = yyvsp[-2].Number;
1333 yyYear = yyvsp[0].Number;
1334 }
1335 }
1336 break;
1337 case 22:
1338 #line 265 "getdate.y"
1339 {
1340 /* ISO 8601 format. yyyy-mm-dd. */
1341 yyYear = yyvsp[-2].Number;
1342 yyMonth = -yyvsp[-1].Number;
1343 yyDay = -yyvsp[0].Number;
1344 }
1345 break;
1346 case 23:
1347 #line 271 "getdate.y"
1348 {
1349 /* e.g. 17-JUN-1992. */
1350 yyDay = yyvsp[-2].Number;
1351 yyMonth = yyvsp[-1].Number;
1352 yyYear = -yyvsp[0].Number;
1353 }
1354 break;
1355 case 24:
1356 #line 277 "getdate.y"
1357 {
1358 yyMonth = yyvsp[-1].Number;
1359 yyDay = yyvsp[0].Number;
1360 }
1361 break;
1362 case 25:
1363 #line 281 "getdate.y"
1364 {
1365 yyMonth = yyvsp[-3].Number;
1366 yyDay = yyvsp[-2].Number;
1367 yyYear = yyvsp[0].Number;
1368 }
1369 break;
1370 case 26:
1371 #line 286 "getdate.y"
1372 {
1373 yyMonth = yyvsp[0].Number;
1374 yyDay = yyvsp[-1].Number;
1375 }
1376 break;
1377 case 27:
1378 #line 290 "getdate.y"
1379 {
1380 yyMonth = yyvsp[-1].Number;
1381 yyDay = yyvsp[-2].Number;
1382 yyYear = yyvsp[0].Number;
1383 }
1384 break;
1385 case 28:
1386 #line 297 "getdate.y"
1387 {
1388 yyRelSeconds = -yyRelSeconds;
1389 yyRelMonth = -yyRelMonth;
1390 }
1391 break;
1392 case 30:
1393 #line 304 "getdate.y"
1394 {
1395 yyRelSeconds += yyvsp[-1].Number * yyvsp[0].Number * 60L;
1396 }
1397 break;
1398 case 31:
1399 #line 307 "getdate.y"
1400 {
1401 yyRelSeconds += yyvsp[-1].Number * yyvsp[0].Number * 60L;
1402 }
1403 break;
1404 case 32:
1405 #line 310 "getdate.y"
1406 {
1407 yyRelSeconds += yyvsp[0].Number * 60L;
1408 }
1409 break;
1410 case 33:
1411 #line 313 "getdate.y"
1412 {
1413 yyRelSeconds += yyvsp[-1].Number;
1414 }
1415 break;
1416 case 34:
1417 #line 316 "getdate.y"
1418 {
1419 yyRelSeconds += yyvsp[-1].Number;
1420 }
1421 break;
1422 case 35:
1423 #line 319 "getdate.y"
1424 {
1425 yyRelSeconds++;
1426 }
1427 break;
1428 case 36:
1429 #line 322 "getdate.y"
1430 {
1431 yyRelMonth += yyvsp[-1].Number * yyvsp[0].Number;
1432 }
1433 break;
1434 case 37:
1435 #line 325 "getdate.y"
1436 {
1437 yyRelMonth += yyvsp[-1].Number * yyvsp[0].Number;
1438 }
1439 break;
1440 case 38:
1441 #line 328 "getdate.y"
1442 {
1443 yyRelMonth += yyvsp[0].Number;
1444 }
1445 break;
1446 case 39:
1447 #line 333 "getdate.y"
1448 {
1449 if (yyHaveTime && yyHaveDate && !yyHaveRel)
1450 yyYear = yyvsp[0].Number;
1451 else {
1452 if(yyvsp[0].Number>10000) {
1453 yyHaveDate++;
1454 yyDay= (yyvsp[0].Number)%100;
1455 yyMonth= (yyvsp[0].Number/100)%100;
1456 yyYear = yyvsp[0].Number/10000;
1457 }
1458 else {
1459 yyHaveTime++;
1460 if (yyvsp[0].Number < 100) {
1461 yyHour = yyvsp[0].Number;
1462 yyMinutes = 0;
1463 }
1464 else {
1465 yyHour = yyvsp[0].Number / 100;
1466 yyMinutes = yyvsp[0].Number % 100;
1467 }
1468 yySeconds = 0;
1469 yyMeridian = MER24;
1470 }
1471 }
1472 }
1473 break;
1474 case 40:
1475 #line 360 "getdate.y"
1476 {
1477 yyval.Meridian = MER24;
1478 }
1479 break;
1480 case 41:
1481 #line 363 "getdate.y"
1482 {
1483 yyval.Meridian = yyvsp[0].Meridian;
1484 }
1485 break;
1486 #line 1487 "y.tab.c"
1487 }
1488 yyssp -= yym;
1489 yystate = *yyssp;
1490 yyvsp -= yym;
1491 yym = yylhs[yyn];
1492 if (yystate == 0 && yym == 0)
1493 {
1494 #if YYDEBUG
1495 if (yydebug)
1496 printf("%sdebug: after reduction, shifting from state 0 to\
1497 state %d\n", YYPREFIX, YYFINAL);
1498 #endif
1499 yystate = YYFINAL;
1500 *++yyssp = YYFINAL;
1501 *++yyvsp = yyval;
1502 if (yychar < 0)
1503 {
1504 if ((yychar = yylex()) < 0) yychar = 0;
1505 #if YYDEBUG
1506 if (yydebug)
1507 {
1508 yys = 0;
1509 if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
1510 if (!yys) yys = "illegal-symbol";
1511 printf("%sdebug: state %d, reading %d (%s)\n",
1512 YYPREFIX, YYFINAL, yychar, yys);
1513 }
1514 #endif
1515 }
1516 if (yychar == 0) goto yyaccept;
1517 goto yyloop;
1518 }
1519 if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 &&
1520 yyn <= YYTABLESIZE && yycheck[yyn] == yystate)
1521 yystate = yytable[yyn];
1522 else
1523 yystate = yydgoto[yym];
1524 #if YYDEBUG
1525 if (yydebug)
1526 printf("%sdebug: after reduction, shifting from state %d \
1527 to state %d\n", YYPREFIX, *yyssp, yystate);
1528 #endif
1529 if (yyssp >= yysslim && yygrowstack())
1530 {
1531 goto yyoverflow;
1532 }
1533 *++yyssp = yystate;
1534 *++yyvsp = yyval;
1535 goto yyloop;
1536 yyoverflow:
1537 yyerror("yacc stack overflow");
1538 yyabort:
1539 return (1);
1540 yyaccept:
1541 return (0);
1542 }