]>
git.saurik.com Git - apple/shell_cmds.git/blob - find/y.tab.c
573e77569d6012b6d53f57cbad249ed711bc162d
4 static char yysccsid
[] = "@(#)yaccpar 1.9 (Berkeley) 02/21/93";
6 __IDSTRING(yyrcsid
, "$NetBSD: skeleton.c,v 1.14 1997/10/20 03:41:16 lukem Exp $");
15 #define yyclearin (yychar=(YYEMPTY))
16 #define yyerrok (yyerrflag=0)
17 #define YYRECOVERING (yyerrflag!=0)
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;
26 ** This grammar has 10 shift/reduce conflicts.
28 ** This code is in the public domain and has no copyright.
30 /* SUPPRESS 287 on yaccpar_sccsid *//* Unused static variable */
31 /* SUPPRESS 288 on yyerrlab *//* Label unused */
34 #if defined (emacs) || defined (CONFIG_BROKETS)
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. */
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. */
62 #else /* defined(vms) */
63 # include <sys/types.h>
64 /* don't need xtime.h */
65 # include <sys/time.h>
67 #endif /* !defined(vms) */
69 #include <sys/timeb.h>
71 #if defined (STDC_HEADERS) || defined (USG)
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))
82 #if defined (STDC_HEADERS)
86 /* NOTES on rebuilding getdate.c (particularly for inclusion in CVS
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
99 extern struct tm
*gmtime();
100 extern struct tm
*localtime();
102 #define yyparse getdate_yyparse
103 #define yylex getdate_yylex
104 #define yyerror getdate_yyerror
106 static int yyparse ();
108 static int yyerror ();
111 #define HOUR(x) ((time_t)(x) * 60)
112 #define SECSPERDAY (24L * 60L * 60L)
116 ** An entry in the lexical lookup table.
118 typedef struct _TABLE
{
126 ** Daylight-savings mode: on, off, or not yet known.
128 typedef enum _DSTMODE
{
129 DSTon
, DSToff
, DSTmaybe
133 ** Meridian: am, pm, or 24-hour style.
135 typedef enum _MERIDIAN
{
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.
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
;
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
;
166 #line 150 "getdate.y"
169 enum _MERIDIAN Meridian
;
176 #define tMERIDIAN 261
177 #define tMINUTE_UNIT 262
179 #define tMONTH_UNIT 264
180 #define tSEC_UNIT 265
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,
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,
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,
207 short yydgoto
[] = { 1,
208 45, 11, 12, 13, 14, 15, 16, 17, 18,
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,
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,
224 short yygindex
[] = { 0,
225 -17, 0, 0, 0, 0, 0, 0, 0, 0,
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,
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,
304 #define YYMAXTOKEN 269
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",
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",
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",
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",
359 "o_merid : tMERIDIAN",
364 #define YYMAXDEPTH YYSTACKSIZE
367 #define YYSTACKSIZE YYMAXDEPTH
369 #define YYSTACKSIZE 10000
370 #define YYMAXDEPTH 10000
373 #define YYINITSTACKSIZE 200
386 #line 369 "getdate.y"
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 },
407 { "wednesday", tDAY
, 3 },
408 { "wednes", tDAY
, 3 },
409 { "thursday", tDAY
, 4 },
411 { "thurs", tDAY
, 4 },
412 { "friday", tDAY
, 5 },
413 { "saturday", tDAY
, 6 },
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 },
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 },
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 */
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 */
474 { "nft", tZONE
, HOUR(3.5) }, /* Newfoundland */
475 { "nst", tZONE
, HOUR(3.5) }, /* Newfoundland Standard */
476 { "ndt", tDAYZONE
, HOUR(3.5) }, /* Newfoundland Daylight */
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 */
507 { "it", tZONE
, -HOUR(3.5) },/* Iran */
509 { "zp4", tZONE
, -HOUR(4) }, /* USSR Zone 3 */
510 { "zp5", tZONE
, -HOUR(5) }, /* USSR Zone 4 */
512 { "ist", tZONE
, -HOUR(5.5) },/* Indian Standard */
514 { "zp6", tZONE
, -HOUR(6) }, /* USSR Zone 5 */
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 */
521 { "wast", tZONE
, -HOUR(7) }, /* West Australian Standard */
522 { "wadt", tDAYZONE
, -HOUR(7) }, /* West Australian Daylight */
524 { "jt", tZONE
, -HOUR(7.5) },/* Java (3pm in Cronusland!) */
526 { "cct", tZONE
, -HOUR(8) }, /* China Coast, USSR Zone 7 */
527 { "jst", tZONE
, -HOUR(9) }, /* Japan Standard, USSR Zone 8 */
529 { "cast", tZONE
, -HOUR(9.5) },/* Central Australian Standard */
530 { "cadt", tDAYZONE
, -HOUR(9.5) },/* Central Australian Daylight */
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 */
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) },
585 ToSeconds(Hours
, Minutes
, Seconds
, Meridian
)
591 if (Minutes
< 0 || Minutes
> 59 || Seconds
< 0 || Seconds
> 59)
595 if (Hours
< 0 || Hours
> 23)
597 return (Hours
* 60L + Minutes
) * 60L + Seconds
;
599 if (Hours
< 1 || Hours
> 12)
603 return (Hours
* 60L + Minutes
) * 60L + Seconds
;
605 if (Hours
< 1 || Hours
> 12)
609 return ((Hours
+ 12) * 60L + Minutes
) * 60L + Seconds
;
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). */
622 Convert(Month
, Day
, Year
, Hours
, Minutes
, Seconds
, Meridian
, DSTmode
)
632 static int DaysInMonth
[12] = {
633 31, 0, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
645 DaysInMonth
[1] = Year
% 4 == 0 && (Year
% 100 != 0 || Year
% 400 == 0)
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
])
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)
665 || (DSTmode
== DSTmaybe
&& localtime(&Julian
)->tm_isdst
))
672 DSTcorrect(Start
, Future
)
679 StartDay
= (localtime(&Start
)->tm_hour
+ 1) % 24;
680 FutureDay
= (localtime(&Future
)->tm_hour
+ 1) % 24;
681 return (Future
- Start
) + (StartDay
- FutureDay
) * 60L * 60L;
686 RelativeDate(Start
, DayOrdinal
, DayNumber
)
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
);
703 RelativeMonth(Start
, RelMonth
)
713 tm
= localtime(&Start
);
714 Month
= 12 * (tm
->tm_year
+ 1900) + tm
->tm_mon
+ RelMonth
;
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
,
730 register const TABLE
*tp
;
734 /* Make it lowercase. */
735 for (p
= buff
; *p
; p
++)
739 if (strcmp(buff
, "am") == 0 || strcmp(buff
, "a.m.") == 0) {
740 yylval
.Meridian
= MERam
;
743 if (strcmp(buff
, "pm") == 0 || strcmp(buff
, "p.m.") == 0) {
744 yylval
.Meridian
= MERpm
;
748 /* See if we have an abbreviation for a month. */
749 if (strlen(buff
) == 3)
751 else if (strlen(buff
) == 4 && buff
[3] == '.') {
758 for (tp
= MonthDayTable
; tp
->name
; tp
++) {
760 if (strncmp(buff
, tp
->name
, 3) == 0) {
761 yylval
.Number
= tp
->value
;
765 else if (strcmp(buff
, tp
->name
) == 0) {
766 yylval
.Number
= tp
->value
;
771 for (tp
= TimezoneTable
; tp
->name
; tp
++)
772 if (strcmp(buff
, tp
->name
) == 0) {
773 yylval
.Number
= tp
->value
;
777 if (strcmp(buff
, "dst") == 0)
780 for (tp
= UnitsTable
; tp
->name
; tp
++)
781 if (strcmp(buff
, tp
->name
) == 0) {
782 yylval
.Number
= tp
->value
;
786 /* Strip off any plural and try the units table again. */
787 i
= strlen(buff
) - 1;
788 if (buff
[i
] == 's') {
790 for (tp
= UnitsTable
; tp
->name
; tp
++)
791 if (strcmp(buff
, tp
->name
) == 0) {
792 yylval
.Number
= tp
->value
;
795 buff
[i
] = 's'; /* Put back for "this" in OtherTable. */
798 for (tp
= OtherTable
; tp
->name
; tp
++)
799 if (strcmp(buff
, tp
->name
) == 0) {
800 yylval
.Number
= tp
->value
;
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
;
813 /* Drop out any periods and try the timezone table again. */
814 for (i
= 0, p
= q
= buff
; *q
; q
++)
821 for (tp
= TimezoneTable
; tp
->name
; tp
++)
822 if (strcmp(buff
, tp
->name
) == 0) {
823 yylval
.Number
= tp
->value
;
841 while (isspace(*yyInput
))
844 if (isdigit(c
= *yyInput
) || c
== '-' || c
== '+') {
845 if (c
== '-' || c
== '+') {
846 sign
= c
== '-' ? -1 : 1;
847 if (!isdigit(*++yyInput
))
848 /* skip the '-' sign */
853 for (yylval
.Number
= 0; isdigit(c
= *yyInput
++); )
854 yylval
.Number
= 10 * yylval
.Number
+ c
- '0';
857 yylval
.Number
= -yylval
.Number
;
858 return sign
? tSNUMBER
: tUNUMBER
;
861 for (p
= buff
; isalpha(c
= *yyInput
++) || c
== '.'; )
862 if (p
< &buff
[sizeof buff
- 1])
866 return LookupWord(buff
);
883 #define TM_YEAR_ORIGIN 1900
885 /* Yield A - B, measured in seconds. */
890 int ay
= a
->tm_year
+ (TM_YEAR_ORIGIN
- 1);
891 int by
= b
->tm_year
+ (TM_YEAR_ORIGIN
- 1);
893 /* difference in day of year */
894 a
->tm_yday
- b
->tm_yday
895 /* + intervening leap days */
896 + ((ay
>> 2) - (by
>> 2))
898 + ((ay
/100 >> 2) - (by
/100 >> 2))
899 /* + difference in years * 365 */
900 + (long)(ay
-by
) * 365
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
));
923 (void)time (&nowtime
);
925 gmt_ptr
= gmtime (&nowtime
);
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). */
935 if (! (tm
= localtime (&nowtime
)))
939 ftz
.timezone
= difftm (&gmt
, tm
) / 60;
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
956 tm
= localtime(&nowtime
);
957 yyYear
= tm
->tm_year
+ 1900;
958 yyMonth
= tm
->tm_mon
+ 1;
960 yyTimezone
= now
->timezone
;
961 yyDSTmode
= DSTmaybe
;
975 || yyHaveTime
> 1 || yyHaveZone
> 1 || yyHaveDate
> 1 || yyHaveDay
> 1)
978 if (yyHaveDate
|| yyHaveTime
|| yyHaveDay
) {
979 Start
= Convert(yyMonth
, yyDay
, yyYear
, yyHour
, yyMinutes
, yySeconds
,
980 yyMeridian
, yyDSTmode
);
987 Start
-= ((tm
->tm_hour
* 60L + tm
->tm_min
) * 60L) + tm
->tm_sec
;
990 Start
+= yyRelSeconds
;
991 Start
+= RelativeMonth(Start
, yyRelMonth
);
993 if (yyHaveDay
&& !yyHaveDate
) {
994 tod
= RelativeDate(Start
, yyDayOrdinal
, yyDayNumber
);
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
;
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
);
1020 (void)printf("Bad format - couldn't convert.\n");
1022 (void)printf("%s", ctime(&d
));
1023 (void)printf("\t> ");
1024 (void)fflush(stdout
);
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()
1040 if ((newsize
= yystacksize
) == 0)
1041 newsize
= YYINITSTACKSIZE
;
1042 else if (newsize
>= YYMAXDEPTH
)
1044 else if ((newsize
*= 2) > YYMAXDEPTH
)
1045 newsize
= YYMAXDEPTH
;
1047 if ((newss
= (short *)realloc(yyss
, newsize
* sizeof *newss
)) == NULL
)
1051 if ((newvs
= (YYSTYPE
*)realloc(yyvs
, newsize
* sizeof *newvs
)) == NULL
)
1055 yystacksize
= newsize
;
1056 yysslim
= yyss
+ newsize
- 1;
1060 #define YYABORT goto yyabort
1061 #define YYREJECT goto yyabort
1062 #define YYACCEPT goto yyaccept
1063 #define YYERROR goto yyerrlab
1067 int yym
, yyn
, yystate
;
1071 if ((yys
= getenv("YYDEBUG")) != NULL
)
1074 if (yyn
>= '0' && yyn
<= '9')
1075 yydebug
= yyn
- '0';
1083 if (yyss
== NULL
&& yygrowstack()) goto yyoverflow
;
1086 *yyssp
= yystate
= 0;
1089 if ((yyn
= yydefred
[yystate
]) != 0) goto yyreduce
;
1092 if ((yychar
= yylex()) < 0) yychar
= 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
);
1104 if ((yyn
= yysindex
[yystate
]) && (yyn
+= yychar
) >= 0 &&
1105 yyn
<= YYTABLESIZE
&& yycheck
[yyn
] == yychar
)
1109 printf("%sdebug: state %d, shifting to state %d\n",
1110 YYPREFIX
, yystate
, yytable
[yyn
]);
1112 if (yyssp
>= yysslim
&& yygrowstack())
1116 *++yyssp
= yystate
= yytable
[yyn
];
1119 if (yyerrflag
> 0) --yyerrflag
;
1122 if ((yyn
= yyrindex
[yystate
]) && (yyn
+= yychar
) >= 0 &&
1123 yyn
<= YYTABLESIZE
&& yycheck
[yyn
] == yychar
)
1128 if (yyerrflag
) goto yyinrecovery
;
1131 yyerror("syntax error");
1141 if ((yyn
= yysindex
[*yyssp
]) && (yyn
+= YYERRCODE
) >= 0 &&
1142 yyn
<= YYTABLESIZE
&& yycheck
[yyn
] == YYERRCODE
)
1146 printf("%sdebug: state %d, error recovery shifting\
1147 to state %d\n", YYPREFIX
, *yyssp
, yytable
[yyn
]);
1149 if (yyssp
>= yysslim
&& yygrowstack())
1153 *++yyssp
= yystate
= yytable
[yyn
];
1161 printf("%sdebug: error recovery discarding state %d\n",
1164 if (yyssp
<= yyss
) goto yyabort
;
1172 if (yychar
== 0) goto yyabort
;
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
);
1189 printf("%sdebug: state %d, reducing by rule %d (%s)\n",
1190 YYPREFIX
, yystate
, yyn
, yyrule
[yyn
]);
1193 yyval
= yyvsp
[1-yym
];
1197 #line 168 "getdate.y"
1203 #line 171 "getdate.y"
1209 #line 174 "getdate.y"
1215 #line 177 "getdate.y"
1221 #line 180 "getdate.y"
1227 #line 186 "getdate.y"
1229 yyHour
= yyvsp
[-1].Number
;
1232 yyMeridian
= yyvsp
[0].Meridian
;
1236 #line 192 "getdate.y"
1238 yyHour
= yyvsp
[-3].Number
;
1239 yyMinutes
= yyvsp
[-1].Number
;
1241 yyMeridian
= yyvsp
[0].Meridian
;
1245 #line 198 "getdate.y"
1247 yyHour
= yyvsp
[-3].Number
;
1248 yyMinutes
= yyvsp
[-1].Number
;
1251 yyTimezone
= - (yyvsp
[0].Number
% 100 + (yyvsp
[0].Number
/ 100) * 60);
1255 #line 205 "getdate.y"
1257 yyHour
= yyvsp
[-5].Number
;
1258 yyMinutes
= yyvsp
[-3].Number
;
1259 yySeconds
= yyvsp
[-1].Number
;
1260 yyMeridian
= yyvsp
[0].Meridian
;
1264 #line 211 "getdate.y"
1266 yyHour
= yyvsp
[-5].Number
;
1267 yyMinutes
= yyvsp
[-3].Number
;
1268 yySeconds
= yyvsp
[-1].Number
;
1271 yyTimezone
= - (yyvsp
[0].Number
% 100 + (yyvsp
[0].Number
/ 100) * 60);
1275 #line 221 "getdate.y"
1277 yyTimezone
= yyvsp
[0].Number
;
1282 #line 225 "getdate.y"
1284 yyTimezone
= yyvsp
[0].Number
;
1289 #line 230 "getdate.y"
1291 yyTimezone
= yyvsp
[-1].Number
;
1296 #line 236 "getdate.y"
1299 yyDayNumber
= yyvsp
[0].Number
;
1303 #line 240 "getdate.y"
1306 yyDayNumber
= yyvsp
[-1].Number
;
1310 #line 244 "getdate.y"
1312 yyDayOrdinal
= yyvsp
[-1].Number
;
1313 yyDayNumber
= yyvsp
[0].Number
;
1317 #line 250 "getdate.y"
1319 yyMonth
= yyvsp
[-2].Number
;
1320 yyDay
= yyvsp
[0].Number
;
1324 #line 254 "getdate.y"
1326 if (yyvsp
[-4].Number
>= 100) {
1327 yyYear
= yyvsp
[-4].Number
;
1328 yyMonth
= yyvsp
[-2].Number
;
1329 yyDay
= yyvsp
[0].Number
;
1331 yyMonth
= yyvsp
[-4].Number
;
1332 yyDay
= yyvsp
[-2].Number
;
1333 yyYear
= yyvsp
[0].Number
;
1338 #line 265 "getdate.y"
1340 /* ISO 8601 format. yyyy-mm-dd. */
1341 yyYear
= yyvsp
[-2].Number
;
1342 yyMonth
= -yyvsp
[-1].Number
;
1343 yyDay
= -yyvsp
[0].Number
;
1347 #line 271 "getdate.y"
1349 /* e.g. 17-JUN-1992. */
1350 yyDay
= yyvsp
[-2].Number
;
1351 yyMonth
= yyvsp
[-1].Number
;
1352 yyYear
= -yyvsp
[0].Number
;
1356 #line 277 "getdate.y"
1358 yyMonth
= yyvsp
[-1].Number
;
1359 yyDay
= yyvsp
[0].Number
;
1363 #line 281 "getdate.y"
1365 yyMonth
= yyvsp
[-3].Number
;
1366 yyDay
= yyvsp
[-2].Number
;
1367 yyYear
= yyvsp
[0].Number
;
1371 #line 286 "getdate.y"
1373 yyMonth
= yyvsp
[0].Number
;
1374 yyDay
= yyvsp
[-1].Number
;
1378 #line 290 "getdate.y"
1380 yyMonth
= yyvsp
[-1].Number
;
1381 yyDay
= yyvsp
[-2].Number
;
1382 yyYear
= yyvsp
[0].Number
;
1386 #line 297 "getdate.y"
1388 yyRelSeconds
= -yyRelSeconds
;
1389 yyRelMonth
= -yyRelMonth
;
1393 #line 304 "getdate.y"
1395 yyRelSeconds
+= yyvsp
[-1].Number
* yyvsp
[0].Number
* 60L;
1399 #line 307 "getdate.y"
1401 yyRelSeconds
+= yyvsp
[-1].Number
* yyvsp
[0].Number
* 60L;
1405 #line 310 "getdate.y"
1407 yyRelSeconds
+= yyvsp
[0].Number
* 60L;
1411 #line 313 "getdate.y"
1413 yyRelSeconds
+= yyvsp
[-1].Number
;
1417 #line 316 "getdate.y"
1419 yyRelSeconds
+= yyvsp
[-1].Number
;
1423 #line 319 "getdate.y"
1429 #line 322 "getdate.y"
1431 yyRelMonth
+= yyvsp
[-1].Number
* yyvsp
[0].Number
;
1435 #line 325 "getdate.y"
1437 yyRelMonth
+= yyvsp
[-1].Number
* yyvsp
[0].Number
;
1441 #line 328 "getdate.y"
1443 yyRelMonth
+= yyvsp
[0].Number
;
1447 #line 333 "getdate.y"
1449 if (yyHaveTime
&& yyHaveDate
&& !yyHaveRel
)
1450 yyYear
= yyvsp
[0].Number
;
1452 if(yyvsp
[0].Number
>10000) {
1454 yyDay
= (yyvsp
[0].Number
)%100
;
1455 yyMonth
= (yyvsp
[0].Number
/100)%100
;
1456 yyYear
= yyvsp
[0].Number
/10000;
1460 if (yyvsp
[0].Number
< 100) {
1461 yyHour
= yyvsp
[0].Number
;
1465 yyHour
= yyvsp
[0].Number
/ 100;
1466 yyMinutes
= yyvsp
[0].Number
% 100;
1475 #line 360 "getdate.y"
1477 yyval
.Meridian
= MER24
;
1481 #line 363 "getdate.y"
1483 yyval
.Meridian
= yyvsp
[0].Meridian
;
1486 #line 1487 "y.tab.c"
1492 if (yystate
== 0 && yym
== 0)
1496 printf("%sdebug: after reduction, shifting from state 0 to\
1497 state %d\n", YYPREFIX
, YYFINAL
);
1504 if ((yychar
= yylex()) < 0) yychar
= 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
);
1516 if (yychar
== 0) goto yyaccept
;
1519 if ((yyn
= yygindex
[yym
]) && (yyn
+= yystate
) >= 0 &&
1520 yyn
<= YYTABLESIZE
&& yycheck
[yyn
] == yystate
)
1521 yystate
= yytable
[yyn
];
1523 yystate
= yydgoto
[yym
];
1526 printf("%sdebug: after reduction, shifting from state %d \
1527 to state %d\n", YYPREFIX
, *yyssp
, yystate
);
1529 if (yyssp
>= yysslim
&& yygrowstack())
1537 yyerror("yacc stack overflow");