1
/*@-globstate -statictrans -unqualifiedtrans -noparams @*/
2
/*@-retvalint -usedef -varuse -nullderef -nullassign @*/
3
/*@-readonlytrans -modunconnomods @*/
6
yyrcsid[] = "$FreeBSD: src/usr.bin/yacc/skeleton.c,v 1.28 2000/01/17 02:04:06 bde Exp $";
14
#define yyclearin (yychar=(YYEMPTY))
15
#define yyerrok (yyerrflag=0)
16
#define YYRECOVERING() (yyerrflag!=0)
17
static int yygrowstack();
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. */
54
/* The code at the top of get_date which figures out the offset of the
55
current time zone checks various CPP symbols to see if special
56
tricks are need, but defaults to using the gettimeofday system call.
57
Include <sys/time.h> if that will be used. */
66
#include <sys/types.h>
68
#ifdef TIME_WITH_SYS_TIME
72
#ifdef HAVE_SYS_TIME_H
80
#undef timezone /* needed for sgi */
83
#if defined(HAVE_SYS_TIMEB_H)
84
#include <sys/timeb.h>
87
** We use the obsolete `struct timeb' as part of our interface!
88
** Since the system doesn't have it, we define it here;
89
** our callers must do likewise.
92
time_t time; /* Seconds since the epoch */
93
unsigned short millitm; /* Field not used */
94
short timezone; /* Minutes west of GMT */
95
short dstflag; /* Field not used */
97
#endif /* defined(HAVE_SYS_TIMEB_H) */
99
#endif /* defined(vms) */
101
#if defined (STDC_HEADERS) || defined (USG)
105
/* Some old versions of bison generate parsers that use bcopy.
106
That loses on systems that don't provide the function, so we have
107
to redefine it here. */
108
#if !defined (HAVE_BCOPY) && defined (HAVE_MEMCPY) && !defined (bcopy)
109
#define bcopy(from, to, len) memcpy ((to), (from), (len))
112
#if defined (STDC_HEADERS)
116
/* NOTES on rebuilding getdate.c (particularly for inclusion in CVS
119
We don't want to mess with all the portability hassles of alloca.
120
In particular, most (all?) versions of bison will use alloca in
121
their parser. If bison works on your system (e.g. it should work
122
with gcc), then go ahead and use it, but the more general solution
123
is to use byacc instead of bison, which should generate a portable
124
parser. I played with adding "#define alloca dont_use_alloca", to
125
give an error if the parser generator uses alloca (and thus detect
126
unportable getdate.c's), but that seems to cause as many problems
130
extern struct tm *gmtime();
131
extern struct tm *localtime();
134
extern time_t get_date(char * p, struct timeb * now);
136
#define yyparse getdate_yyparse
137
#define yylex getdate_yylex
138
#define yyerror getdate_yyerror
140
static int yyparse (void);
141
static int yylex (void);
142
static int yyerror(const char * s);
145
#define HOUR(x) ((time_t)(x) * 60)
146
#define SECSPERDAY (24L * 60L * 60L)
150
** An entry in the lexical lookup table.
152
typedef struct _TABLE {
160
** Daylight-savings mode: on, off, or not yet known.
162
typedef enum _DSTMODE {
163
DSTon, DSToff, DSTmaybe
167
** Meridian: am, pm, or 24-hour style.
169
typedef enum _MERIDIAN {
175
** Global variables. We could get rid of most of these by using a good
176
** union as the yacc stack. (This routine was originally written before
177
** yacc had the %union construct.) Maybe someday; right now we only use
178
** the %union very rarely.
180
static char *yyInput;
181
static DSTMODE yyDSTmode;
182
static time_t yyDayOrdinal;
183
static time_t yyDayNumber;
184
static int yyHaveDate;
185
static int yyHaveDay;
186
static int yyHaveRel;
187
static int yyHaveTime;
188
static int yyHaveZone;
189
static time_t yyTimezone;
191
static time_t yyHour;
192
static time_t yyMinutes;
193
static time_t yyMonth;
194
static time_t yySeconds;
195
static time_t yyYear;
196
static MERIDIAN yyMeridian;
197
static time_t yyRelMonth;
198
static time_t yyRelSeconds;
200
#line 184 "./getdate.y"
203
enum _MERIDIAN Meridian;
205
#line 203 "getdate.c"
206
#define YYERRCODE 256
211
#define tMERIDIAN 261
212
#define tMINUTE_UNIT 262
214
#define tMONTH_UNIT 264
215
#define tSEC_UNIT 265
220
static const short yylhs[] = { -1,
221
0, 0, 2, 2, 2, 2, 2, 2, 3, 3,
222
3, 3, 3, 4, 4, 4, 6, 6, 6, 5,
223
5, 5, 5, 5, 5, 5, 5, 7, 7, 9,
224
9, 9, 9, 9, 9, 9, 9, 9, 8, 1,
227
static const short yylen[] = { 2,
228
0, 2, 1, 1, 1, 1, 1, 1, 2, 4,
229
4, 6, 6, 1, 1, 2, 1, 2, 2, 3,
230
5, 3, 3, 2, 4, 2, 3, 2, 1, 2,
231
2, 1, 2, 2, 1, 2, 2, 1, 1, 0,
234
static const short yydefred[] = { 1,
235
0, 0, 15, 32, 0, 38, 35, 0, 0, 0,
236
2, 3, 4, 5, 6, 7, 8, 0, 18, 0,
237
31, 36, 33, 19, 9, 30, 0, 37, 34, 0,
238
0, 0, 16, 28, 0, 23, 27, 22, 0, 0,
239
25, 41, 11, 0, 10, 0, 0, 21, 13, 12,
241
static const short yydgoto[] = { 1,
242
45, 11, 12, 13, 14, 15, 16, 17, 18,
244
static const short yysindex[] = { 0,
245
-249, -38, 0, 0, -260, 0, 0, -240, -47, -248,
246
0, 0, 0, 0, 0, 0, 0, -237, 0, -18,
247
0, 0, 0, 0, 0, 0, -262, 0, 0, -239,
248
-238, -236, 0, 0, -235, 0, 0, 0, -56, -19,
249
0, 0, 0, -234, 0, -232, -258, 0, 0, 0,
251
static const short yyrindex[] = { 0,
252
0, 1, 0, 0, 0, 0, 0, 0, 69, 12,
253
0, 0, 0, 0, 0, 0, 0, 23, 0, 34,
254
0, 0, 0, 0, 0, 0, 67, 0, 0, 0,
255
0, 0, 0, 0, 0, 0, 0, 0, 56, 45,
256
0, 0, 0, 0, 0, 0, 56, 0, 0, 0,
258
static const short yygindex[] = { 0,
259
-17, 0, 0, 0, 0, 0, 0, 0, 0,
261
#define YYTABLESIZE 337
262
static const short yytable[] = { 32,
263
17, 44, 42, 36, 37, 19, 20, 49, 2, 3,
264
31, 14, 4, 5, 6, 7, 8, 9, 10, 34,
265
33, 21, 29, 22, 23, 35, 38, 46, 39, 50,
266
40, 41, 47, 24, 48, 0, 0, 0, 0, 0,
267
0, 0, 0, 0, 20, 0, 0, 0, 0, 0,
268
0, 0, 0, 0, 0, 40, 0, 0, 0, 0,
269
0, 0, 0, 0, 0, 0, 26, 0, 39, 0,
270
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
271
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
272
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
273
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
274
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
275
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
276
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
277
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
278
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
279
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
280
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
281
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
282
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
283
0, 0, 0, 0, 42, 0, 0, 0, 0, 43,
284
24, 0, 0, 25, 26, 27, 28, 29, 30, 0,
285
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
286
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
287
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
288
0, 0, 0, 0, 0, 0, 0, 0, 17, 17,
289
0, 0, 17, 17, 17, 17, 17, 17, 17, 14,
290
14, 0, 0, 14, 14, 14, 14, 14, 14, 14,
291
29, 29, 0, 0, 29, 29, 29, 29, 29, 29,
292
29, 24, 24, 0, 0, 24, 24, 24, 24, 24,
293
24, 24, 20, 20, 0, 0, 20, 20, 20, 20,
294
20, 20, 20, 40, 40, 0, 0, 40, 40, 40,
295
40, 0, 40, 40, 26, 26, 0, 39, 26, 26,
296
26, 26, 0, 0, 26, 39, 39,
298
static const short yycheck[] = { 47,
299
0, 58, 261, 266, 267, 44, 267, 266, 258, 259,
300
58, 0, 262, 263, 264, 265, 266, 267, 268, 257,
301
269, 262, 0, 264, 265, 44, 266, 47, 267, 47,
302
267, 267, 267, 0, 267, -1, -1, -1, -1, -1,
303
-1, -1, -1, -1, 0, -1, -1, -1, -1, -1,
304
-1, -1, -1, -1, -1, 0, -1, -1, -1, -1,
305
-1, -1, -1, -1, -1, -1, 0, -1, 0, -1,
306
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
307
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
308
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
309
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
310
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
311
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
312
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
313
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
314
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
315
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
316
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
317
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
318
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
319
-1, -1, -1, -1, 261, -1, -1, -1, -1, 266,
320
258, -1, -1, 261, 262, 263, 264, 265, 266, -1,
321
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
322
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
323
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
324
-1, -1, -1, -1, -1, -1, -1, -1, 258, 259,
325
-1, -1, 262, 263, 264, 265, 266, 267, 268, 258,
326
259, -1, -1, 262, 263, 264, 265, 266, 267, 268,
327
258, 259, -1, -1, 262, 263, 264, 265, 266, 267,
328
268, 258, 259, -1, -1, 262, 263, 264, 265, 266,
329
267, 268, 258, 259, -1, -1, 262, 263, 264, 265,
330
266, 267, 268, 258, 259, -1, -1, 262, 263, 264,
331
265, -1, 267, 268, 258, 259, -1, 259, 262, 263,
332
264, 265, -1, -1, 268, 267, 268,
338
#define YYMAXTOKEN 269
340
const char * const yyname[] = {
341
"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,
342
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,
343
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,
344
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,
345
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,
346
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,
347
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",
348
"tDAYZONE","tID","tMERIDIAN","tMINUTE_UNIT","tMONTH","tMONTH_UNIT","tSEC_UNIT",
349
"tSNUMBER","tUNUMBER","tZONE","tDST",
351
const char * const yyrule[] = {
361
"time : tUNUMBER tMERIDIAN",
362
"time : tUNUMBER ':' tUNUMBER o_merid",
363
"time : tUNUMBER ':' tUNUMBER tSNUMBER",
364
"time : tUNUMBER ':' tUNUMBER ':' tUNUMBER o_merid",
365
"time : tUNUMBER ':' tUNUMBER ':' tUNUMBER tSNUMBER",
371
"day : tUNUMBER tDAY",
372
"date : tUNUMBER '/' tUNUMBER",
373
"date : tUNUMBER '/' tUNUMBER '/' tUNUMBER",
374
"date : tUNUMBER tSNUMBER tSNUMBER",
375
"date : tUNUMBER tMONTH tSNUMBER",
376
"date : tMONTH tUNUMBER",
377
"date : tMONTH tUNUMBER ',' tUNUMBER",
378
"date : tUNUMBER tMONTH",
379
"date : tUNUMBER tMONTH tUNUMBER",
380
"rel : relunit tAGO",
382
"relunit : tUNUMBER tMINUTE_UNIT",
383
"relunit : tSNUMBER tMINUTE_UNIT",
384
"relunit : tMINUTE_UNIT",
385
"relunit : tSNUMBER tSEC_UNIT",
386
"relunit : tUNUMBER tSEC_UNIT",
387
"relunit : tSEC_UNIT",
388
"relunit : tSNUMBER tMONTH_UNIT",
389
"relunit : tUNUMBER tMONTH_UNIT",
390
"relunit : tMONTH_UNIT",
393
"o_merid : tMERIDIAN",
401
#define YYMAXDEPTH YYSTACKSIZE
404
#define YYSTACKSIZE YYMAXDEPTH
406
#define YYSTACKSIZE 10000
407
#define YYMAXDEPTH 10000
410
#define YYINITSTACKSIZE 200
411
/*@unused@*/ static int yydebug;
413
static int yyerrflag;
416
static YYSTYPE *yyvsp;
417
static YYSTYPE yyval;
418
static YYSTYPE yylval;
420
static short *yysslim;
421
static YYSTYPE *yyvs;
422
static int yystacksize;
423
#line 403 "./getdate.y"
425
/* Month and day table. */
426
static TABLE const MonthDayTable[] = {
427
{ "january", tMONTH, 1 },
428
{ "february", tMONTH, 2 },
429
{ "march", tMONTH, 3 },
430
{ "april", tMONTH, 4 },
431
{ "may", tMONTH, 5 },
432
{ "june", tMONTH, 6 },
433
{ "july", tMONTH, 7 },
434
{ "august", tMONTH, 8 },
435
{ "september", tMONTH, 9 },
436
{ "sept", tMONTH, 9 },
437
{ "october", tMONTH, 10 },
438
{ "november", tMONTH, 11 },
439
{ "december", tMONTH, 12 },
440
{ "sunday", tDAY, 0 },
441
{ "monday", tDAY, 1 },
442
{ "tuesday", tDAY, 2 },
444
{ "wednesday", tDAY, 3 },
445
{ "wednes", tDAY, 3 },
446
{ "thursday", tDAY, 4 },
448
{ "thurs", tDAY, 4 },
449
{ "friday", tDAY, 5 },
450
{ "saturday", tDAY, 6 },
454
/* Time units table. */
455
static TABLE const UnitsTable[] = {
456
{ "year", tMONTH_UNIT, 12 },
457
{ "month", tMONTH_UNIT, 1 },
458
{ "fortnight", tMINUTE_UNIT, 14 * 24 * 60 },
459
{ "week", tMINUTE_UNIT, 7 * 24 * 60 },
460
{ "day", tMINUTE_UNIT, 1 * 24 * 60 },
461
{ "hour", tMINUTE_UNIT, 60 },
462
{ "minute", tMINUTE_UNIT, 1 },
463
{ "min", tMINUTE_UNIT, 1 },
464
{ "second", tSEC_UNIT, 1 },
465
{ "sec", tSEC_UNIT, 1 },
469
/* Assorted relative-time words. */
470
static TABLE const OtherTable[] = {
471
{ "tomorrow", tMINUTE_UNIT, 1 * 24 * 60 },
472
{ "yesterday", tMINUTE_UNIT, -1 * 24 * 60 },
473
{ "today", tMINUTE_UNIT, 0 },
474
{ "now", tMINUTE_UNIT, 0 },
475
{ "last", tUNUMBER, -1 },
476
{ "this", tMINUTE_UNIT, 0 },
477
{ "next", tUNUMBER, 2 },
478
{ "first", tUNUMBER, 1 },
479
/* { "second", tUNUMBER, 2 }, */
480
{ "third", tUNUMBER, 3 },
481
{ "fourth", tUNUMBER, 4 },
482
{ "fifth", tUNUMBER, 5 },
483
{ "sixth", tUNUMBER, 6 },
484
{ "seventh", tUNUMBER, 7 },
485
{ "eighth", tUNUMBER, 8 },
486
{ "ninth", tUNUMBER, 9 },
487
{ "tenth", tUNUMBER, 10 },
488
{ "eleventh", tUNUMBER, 11 },
489
{ "twelfth", tUNUMBER, 12 },
494
/* The timezone table. */
495
/* Some of these are commented out because a time_t can't store a float. */
496
static TABLE const TimezoneTable[] = {
497
{ "gmt", tZONE, HOUR( 0) }, /* Greenwich Mean */
498
{ "ut", tZONE, HOUR( 0) }, /* Universal (Coordinated) */
499
{ "utc", tZONE, HOUR( 0) },
500
{ "wet", tZONE, HOUR( 0) }, /* Western European */
501
{ "bst", tDAYZONE, HOUR( 0) }, /* British Summer */
502
{ "wat", tZONE, HOUR( 1) }, /* West Africa */
503
{ "at", tZONE, HOUR( 2) }, /* Azores */
505
/* For completeness. BST is also British Summer, and GST is
506
* also Guam Standard. */
507
{ "bst", tZONE, HOUR( 3) }, /* Brazil Standard */
508
{ "gst", tZONE, HOUR( 3) }, /* Greenland Standard */
511
{ "nft", tZONE, HOUR(3.5) }, /* Newfoundland */
512
{ "nst", tZONE, HOUR(3.5) }, /* Newfoundland Standard */
513
{ "ndt", tDAYZONE, HOUR(3.5) }, /* Newfoundland Daylight */
515
{ "ast", tZONE, HOUR( 4) }, /* Atlantic Standard */
516
{ "adt", tDAYZONE, HOUR( 4) }, /* Atlantic Daylight */
517
{ "est", tZONE, HOUR( 5) }, /* Eastern Standard */
518
{ "edt", tDAYZONE, HOUR( 5) }, /* Eastern Daylight */
519
{ "cst", tZONE, HOUR( 6) }, /* Central Standard */
520
{ "cdt", tDAYZONE, HOUR( 6) }, /* Central Daylight */
521
{ "mst", tZONE, HOUR( 7) }, /* Mountain Standard */
522
{ "mdt", tDAYZONE, HOUR( 7) }, /* Mountain Daylight */
523
{ "pst", tZONE, HOUR( 8) }, /* Pacific Standard */
524
{ "pdt", tDAYZONE, HOUR( 8) }, /* Pacific Daylight */
525
{ "yst", tZONE, HOUR( 9) }, /* Yukon Standard */
526
{ "ydt", tDAYZONE, HOUR( 9) }, /* Yukon Daylight */
527
{ "hst", tZONE, HOUR(10) }, /* Hawaii Standard */
528
{ "hdt", tDAYZONE, HOUR(10) }, /* Hawaii Daylight */
529
{ "cat", tZONE, HOUR(10) }, /* Central Alaska */
530
{ "ahst", tZONE, HOUR(10) }, /* Alaska-Hawaii Standard */
531
{ "nt", tZONE, HOUR(11) }, /* Nome */
532
{ "idlw", tZONE, HOUR(12) }, /* International Date Line West */
533
{ "cet", tZONE, -HOUR(1) }, /* Central European */
534
{ "met", tZONE, -HOUR(1) }, /* Middle European */
535
{ "mewt", tZONE, -HOUR(1) }, /* Middle European Winter */
536
{ "mest", tDAYZONE, -HOUR(1) }, /* Middle European Summer */
537
{ "swt", tZONE, -HOUR(1) }, /* Swedish Winter */
538
{ "sst", tDAYZONE, -HOUR(1) }, /* Swedish Summer */
539
{ "fwt", tZONE, -HOUR(1) }, /* French Winter */
540
{ "fst", tDAYZONE, -HOUR(1) }, /* French Summer */
541
{ "eet", tZONE, -HOUR(2) }, /* Eastern Europe, USSR Zone 1 */
542
{ "bt", tZONE, -HOUR(3) }, /* Baghdad, USSR Zone 2 */
544
{ "it", tZONE, -HOUR(3.5) },/* Iran */
546
{ "zp4", tZONE, -HOUR(4) }, /* USSR Zone 3 */
547
{ "zp5", tZONE, -HOUR(5) }, /* USSR Zone 4 */
549
{ "ist", tZONE, -HOUR(5.5) },/* Indian Standard */
551
{ "zp6", tZONE, -HOUR(6) }, /* USSR Zone 5 */
553
/* For completeness. NST is also Newfoundland Stanard, and SST is
554
* also Swedish Summer. */
555
{ "nst", tZONE, -HOUR(6.5) },/* North Sumatra */
556
{ "sst", tZONE, -HOUR(7) }, /* South Sumatra, USSR Zone 6 */
558
{ "wast", tZONE, -HOUR(7) }, /* West Australian Standard */
559
{ "wadt", tDAYZONE, -HOUR(7) }, /* West Australian Daylight */
561
{ "jt", tZONE, -HOUR(7.5) },/* Java (3pm in Cronusland!) */
563
{ "cct", tZONE, -HOUR(8) }, /* China Coast, USSR Zone 7 */
564
{ "jst", tZONE, -HOUR(9) }, /* Japan Standard, USSR Zone 8 */
566
{ "cast", tZONE, -HOUR(9.5) },/* Central Australian Standard */
567
{ "cadt", tDAYZONE, -HOUR(9.5) },/* Central Australian Daylight */
569
{ "east", tZONE, -HOUR(10) }, /* Eastern Australian Standard */
570
{ "eadt", tDAYZONE, -HOUR(10) }, /* Eastern Australian Daylight */
571
{ "gst", tZONE, -HOUR(10) }, /* Guam Standard, USSR Zone 9 */
572
{ "nzt", tZONE, -HOUR(12) }, /* New Zealand */
573
{ "nzst", tZONE, -HOUR(12) }, /* New Zealand Standard */
574
{ "nzdt", tDAYZONE, -HOUR(12) }, /* New Zealand Daylight */
575
{ "idle", tZONE, -HOUR(12) }, /* International Date Line East */
579
/* Military timezone table. */
580
static TABLE const MilitaryTable[] = {
581
{ "a", tZONE, HOUR( 1) },
582
{ "b", tZONE, HOUR( 2) },
583
{ "c", tZONE, HOUR( 3) },
584
{ "d", tZONE, HOUR( 4) },
585
{ "e", tZONE, HOUR( 5) },
586
{ "f", tZONE, HOUR( 6) },
587
{ "g", tZONE, HOUR( 7) },
588
{ "h", tZONE, HOUR( 8) },
589
{ "i", tZONE, HOUR( 9) },
590
{ "k", tZONE, HOUR( 10) },
591
{ "l", tZONE, HOUR( 11) },
592
{ "m", tZONE, HOUR( 12) },
593
{ "n", tZONE, HOUR(- 1) },
594
{ "o", tZONE, HOUR(- 2) },
595
{ "p", tZONE, HOUR(- 3) },
596
{ "q", tZONE, HOUR(- 4) },
597
{ "r", tZONE, HOUR(- 5) },
598
{ "s", tZONE, HOUR(- 6) },
599
{ "t", tZONE, HOUR(- 7) },
600
{ "u", tZONE, HOUR(- 8) },
601
{ "v", tZONE, HOUR(- 9) },
602
{ "w", tZONE, HOUR(-10) },
603
{ "x", tZONE, HOUR(-11) },
604
{ "y", tZONE, HOUR(-12) },
605
{ "z", tZONE, HOUR( 0) },
614
yyerror(const char * s)
621
ToSeconds(time_t Hours, time_t Minutes, time_t Seconds, MERIDIAN Meridian)
623
if (Minutes < 0 || Minutes > 59 || Seconds < 0 || Seconds > 59)
627
if (Hours < 0 || Hours > 23)
629
return (Hours * 60L + Minutes) * 60L + Seconds;
631
if (Hours < 1 || Hours > 12)
635
return (Hours * 60L + Minutes) * 60L + Seconds;
637
if (Hours < 1 || Hours > 12)
641
return ((Hours + 12) * 60L + Minutes) * 60L + Seconds;
650
* A negative number, which means to use its absolute value (why?)
651
* A number from 0 to 99, which means a year from 1900 to 1999, or
652
* The actual year (>=100). */
654
Convert(time_t Month, time_t Day, time_t Year,
655
time_t Hours, time_t Minutes, time_t Seconds,
656
MERIDIAN Meridian, DSTMODE DSTmode)
658
static int DaysInMonth[12] = {
659
31, 0, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
671
DaysInMonth[1] = Year % 4 == 0 && (Year % 100 != 0 || Year % 400 == 0)
673
/* Checking for 2038 bogusly assumes that time_t is 32 bits. But
674
I'm too lazy to try to check for time_t overflow in another way. */
675
if (Year < EPOCH || Year > 2038
676
|| Month < 1 || Month > 12
677
/* Lint fluff: "conversion from long may lose accuracy" */
678
|| Day < 1 || Day > DaysInMonth[(int)--Month])
681
for (Julian = Day - 1, i = 0; i < Month; i++)
682
Julian += DaysInMonth[i];
683
for (i = EPOCH; i < Year; i++)
684
Julian += 365 + (i % 4 == 0);
685
Julian *= SECSPERDAY;
686
Julian += yyTimezone * 60L;
687
if ((tod = ToSeconds(Hours, Minutes, Seconds, Meridian)) < 0)
691
|| (DSTmode == DSTmaybe && localtime(&Julian)->tm_isdst))
698
DSTcorrect(time_t Start, time_t Future)
703
StartDay = (localtime(&Start)->tm_hour + 1) % 24;
704
FutureDay = (localtime(&Future)->tm_hour + 1) % 24;
705
return (Future - Start) + (StartDay - FutureDay) * 60L * 60L;
710
RelativeDate(time_t Start, time_t DayOrdinal, time_t DayNumber)
716
tm = localtime(&now);
717
now += SECSPERDAY * ((DayNumber - tm->tm_wday + 7) % 7);
718
now += 7 * SECSPERDAY * (DayOrdinal <= 0 ? DayOrdinal : DayOrdinal - 1);
719
return DSTcorrect(Start, now);
724
RelativeMonth(time_t Start, time_t RelMonth)
732
tm = localtime(&Start);
733
Month = 12 * (tm->tm_year + 1900) + tm->tm_mon + RelMonth;
735
Month = Month % 12 + 1;
736
return DSTcorrect(Start,
737
Convert(Month, (time_t)tm->tm_mday, Year,
738
(time_t)tm->tm_hour, (time_t)tm->tm_min, (time_t)tm->tm_sec,
744
LookupWord(char * buff)
748
register const TABLE *tp;
752
/* Make it lowercase. */
753
for (p = buff; *p != '\0'; p++)
757
if (strcmp(buff, "am") == 0 || strcmp(buff, "a.m.") == 0) {
758
yylval.Meridian = MERam;
761
if (strcmp(buff, "pm") == 0 || strcmp(buff, "p.m.") == 0) {
762
yylval.Meridian = MERpm;
766
/* See if we have an abbreviation for a month. */
767
if (strlen(buff) == 3)
769
else if (strlen(buff) == 4 && buff[3] == '.') {
776
for (tp = MonthDayTable; tp->name; tp++) {
778
if (strncmp(buff, tp->name, 3) == 0) {
779
yylval.Number = tp->value;
783
else if (strcmp(buff, tp->name) == 0) {
784
yylval.Number = tp->value;
789
for (tp = TimezoneTable; tp->name; tp++)
790
if (strcmp(buff, tp->name) == 0) {
791
yylval.Number = tp->value;
795
if (strcmp(buff, "dst") == 0)
798
for (tp = UnitsTable; tp->name; tp++)
799
if (strcmp(buff, tp->name) == 0) {
800
yylval.Number = tp->value;
804
/* Strip off any plural and try the units table again. */
805
i = strlen(buff) - 1;
806
if (buff[i] == 's') {
808
for (tp = UnitsTable; tp->name; tp++)
809
if (strcmp(buff, tp->name) == 0) {
810
yylval.Number = tp->value;
813
buff[i] = 's'; /* Put back for "this" in OtherTable. */
816
for (tp = OtherTable; tp->name; tp++)
817
if (strcmp(buff, tp->name) == 0) {
818
yylval.Number = tp->value;
822
/* Military timezones. */
823
if (buff[1] == '\0' && isalpha(*buff)) {
824
for (tp = MilitaryTable; tp->name; tp++)
825
if (strcmp(buff, tp->name) == 0) {
826
yylval.Number = tp->value;
831
/* Drop out any periods and try the timezone table again. */
832
for (i = 0, p = q = buff; *q != '\0'; q++)
839
for (tp = TimezoneTable; tp->name; tp++)
840
if (strcmp(buff, tp->name) == 0) {
841
yylval.Number = tp->value;
859
while (isspace(*yyInput))
862
if (isdigit(c = *yyInput) || c == '-' || c == '+') {
863
if (c == '-' || c == '+') {
864
sign = c == '-' ? -1 : 1;
865
if (!isdigit(*++yyInput))
866
/* skip the '-' sign */
871
for (yylval.Number = 0; isdigit(c = *yyInput++); )
872
yylval.Number = 10 * yylval.Number + c - '0';
875
yylval.Number = -yylval.Number;
876
return sign ? tSNUMBER : tUNUMBER;
879
for (p = buff; isalpha(c = *yyInput++) || c == '.'; )
880
if (p < &buff[sizeof buff - 1])
884
return LookupWord(buff);
903
#define TM_YEAR_ORIGIN 1900
905
/* Yield A - B, measured in seconds. */
907
difftm (const struct tm * a, const struct tm * b)
909
unsigned ay = a->tm_year + (TM_YEAR_ORIGIN - 1);
910
unsigned by = b->tm_year + (TM_YEAR_ORIGIN - 1);
912
/* difference in day of year */
913
a->tm_yday - b->tm_yday
914
/* + intervening leap days */
915
+ ((ay >> 2) - (by >> 2))
917
+ ((ay/100 >> 2) - (by/100 >> 2))
918
/* + difference in years * 365 */
919
+ (long)(ay-by) * 365
921
return (60*(60*(24*days + (a->tm_hour - b->tm_hour))
922
+ (a->tm_min - b->tm_min))
923
+ (a->tm_sec - b->tm_sec));
927
get_date(char * p, struct timeb * now)
936
memset(&gmt, 0, sizeof(gmt));
941
(void)time (&nowtime);
943
gmt_ptr = gmtime (&nowtime);
946
/* Make a copy, in case localtime modifies *tm (I think
947
that comment now applies to *gmt_ptr, but I am too
948
lazy to dig into how gmtime and locatime allocate the
949
structures they return pointers to). */
953
if (! (tm = localtime (&nowtime)))
957
/*@-observertrans -dependenttrans@*/
958
ftz.timezone = difftm (&gmt, tm) / 60;
959
/*@=observertrans =dependenttrans@*/
961
/* We are on a system like VMS, where the system clock is
962
in local time and the system has no concept of timezones.
963
Hopefully we can fake this out (for the case in which the
964
user specifies no timezone) by just saying the timezone
976
tm = localtime(&nowtime);
977
yyYear = tm->tm_year + 1900;
978
yyMonth = tm->tm_mon + 1;
980
yyTimezone = now->timezone;
981
yyDSTmode = DSTmaybe;
996
|| yyHaveTime > 1 || yyHaveZone > 1 || yyHaveDate > 1 || yyHaveDay > 1)
1000
if (yyHaveDate || yyHaveTime || yyHaveDay) {
1001
Start = Convert(yyMonth, yyDay, yyYear, yyHour, yyMinutes, yySeconds,
1002
yyMeridian, yyDSTmode);
1009
Start -= ((tm->tm_hour * 60L + tm->tm_min) * 60L) + tm->tm_sec;
1012
Start += yyRelSeconds;
1013
Start += RelativeMonth(Start, yyRelMonth);
1015
if (yyHaveDay && !yyHaveDate) {
1016
tod = RelativeDate(Start, yyDayOrdinal, yyDayNumber);
1020
/* Have to do *something* with a legitimate -1 so it's distinguishable
1021
* from the error return value. (Alternately could set errno on error.) */
1022
return Start == -1 ? 0 : Start;
1037
(void)printf("Enter date, or blank line to exit.\n\t> ");
1038
(void)fflush(stdout);
1039
while (gets(buff) && buff[0]) {
1040
d = get_date(buff, (struct timeb *)NULL);
1042
(void)printf("Bad format - couldn't convert.\n");
1044
(void)printf("%s", ctime(&d));
1045
(void)printf("\t> ");
1046
(void)fflush(stdout);
1051
#endif /* defined(TEST) */
1052
#line 1050 "getdate.c"
1053
/* allocate initial stack or double stack size, up to YYMAXDEPTH */
1054
static int yygrowstack()
1060
if ((newsize = yystacksize) == 0)
1061
newsize = YYINITSTACKSIZE;
1062
else if (newsize >= YYMAXDEPTH)
1064
else if ((newsize *= 2) > YYMAXDEPTH)
1065
newsize = YYMAXDEPTH;
1067
newss = yyss ? (short *)realloc(yyss, newsize * sizeof *newss) :
1068
(short *)malloc(newsize * sizeof *newss);
1073
newvs = yyvs ? (YYSTYPE *)realloc(yyvs, newsize * sizeof *newvs) :
1074
(YYSTYPE *)malloc(newsize * sizeof *newvs);
1079
yystacksize = newsize;
1080
yysslim = yyss + newsize - 1;
1084
#define YYABORT goto yyabort
1085
#define YYREJECT goto yyabort
1086
#define YYACCEPT goto yyaccept
1087
#define YYERROR goto yyerrlab
1089
#ifndef YYPARSE_PARAM
1090
#if defined(__cplusplus) || __STDC__
1091
#define YYPARSE_PARAM_ARG void
1092
#define YYPARSE_PARAM_DECL
1093
#else /* ! ANSI-C/C++ */
1094
#define YYPARSE_PARAM_ARG
1095
#define YYPARSE_PARAM_DECL
1096
#endif /* ANSI-C/C++ */
1097
#else /* YYPARSE_PARAM */
1098
#ifndef YYPARSE_PARAM_TYPE
1099
#define YYPARSE_PARAM_TYPE void *
1101
#if defined(__cplusplus) || __STDC__
1102
#define YYPARSE_PARAM_ARG YYPARSE_PARAM_TYPE YYPARSE_PARAM
1103
#define YYPARSE_PARAM_DECL
1104
#else /* ! ANSI-C/C++ */
1105
#define YYPARSE_PARAM_ARG YYPARSE_PARAM
1106
#define YYPARSE_PARAM_DECL YYPARSE_PARAM_TYPE YYPARSE_PARAM;
1107
#endif /* ANSI-C/C++ */
1108
#endif /* ! YYPARSE_PARAM */
1111
yyparse (YYPARSE_PARAM_ARG)
1114
register int yym, yyn, yystate;
1116
register const char *yys;
1118
if ((yys = getenv("YYDEBUG")))
1121
if (yyn >= '0' && yyn <= '9')
1122
yydebug = yyn - '0';
1130
if (yyss == NULL && yygrowstack()) goto yyoverflow;
1133
*yyssp = yystate = 0;
1136
if ((yyn = yydefred[yystate])) goto yyreduce;
1139
if ((yychar = yylex()) < 0) yychar = 0;
1144
if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
1145
if (!yys) yys = "illegal-symbol";
1146
printf("%sdebug: state %d, reading %d (%s)\n",
1147
YYPREFIX, yystate, yychar, yys);
1151
if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 &&
1152
yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
1156
printf("%sdebug: state %d, shifting to state %d\n",
1157
YYPREFIX, yystate, yytable[yyn]);
1159
if (yyssp >= yysslim && yygrowstack())
1163
*++yyssp = yystate = yytable[yyn];
1166
if (yyerrflag > 0) --yyerrflag;
1169
if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 &&
1170
yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
1175
if (yyerrflag) goto yyinrecovery;
1176
#if defined(lint) || defined(__GNUC__)
1180
yyerror("syntax error");
1181
#if defined(lint) || defined(__GNUC__)
1192
if ((yyn = yysindex[*yyssp]) && (yyn += YYERRCODE) >= 0 &&
1193
yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE)
1197
printf("%sdebug: state %d, error recovery shifting\
1198
to state %d\n", YYPREFIX, *yyssp, yytable[yyn]);
1200
if (yyssp >= yysslim && yygrowstack())
1204
*++yyssp = yystate = yytable[yyn];
1212
printf("%sdebug: error recovery discarding state %d\n",
1215
if (yyssp <= yyss) goto yyabort;
1223
if (yychar == 0) goto yyabort;
1228
if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
1229
if (!yys) yys = "illegal-symbol";
1230
printf("%sdebug: state %d, error recovery discards token %d (%s)\n",
1231
YYPREFIX, yystate, yychar, yys);
1240
printf("%sdebug: state %d, reducing by rule %d (%s)\n",
1241
YYPREFIX, yystate, yyn, yyrule[yyn]);
1244
yyval = yyvsp[1-yym];
1248
#line 202 "./getdate.y"
1254
#line 205 "./getdate.y"
1260
#line 208 "./getdate.y"
1266
#line 211 "./getdate.y"
1272
#line 214 "./getdate.y"
1278
#line 220 "./getdate.y"
1280
yyHour = yyvsp[-1].Number;
1283
yyMeridian = yyvsp[0].Meridian;
1287
#line 226 "./getdate.y"
1289
yyHour = yyvsp[-3].Number;
1290
yyMinutes = yyvsp[-1].Number;
1292
yyMeridian = yyvsp[0].Meridian;
1296
#line 232 "./getdate.y"
1298
yyHour = yyvsp[-3].Number;
1299
yyMinutes = yyvsp[-1].Number;
1302
yyTimezone = - (yyvsp[0].Number % 100 + (yyvsp[0].Number / 100) * 60);
1306
#line 239 "./getdate.y"
1308
yyHour = yyvsp[-5].Number;
1309
yyMinutes = yyvsp[-3].Number;
1310
yySeconds = yyvsp[-1].Number;
1311
yyMeridian = yyvsp[0].Meridian;
1315
#line 245 "./getdate.y"
1317
yyHour = yyvsp[-5].Number;
1318
yyMinutes = yyvsp[-3].Number;
1319
yySeconds = yyvsp[-1].Number;
1322
yyTimezone = - (yyvsp[0].Number % 100 + (yyvsp[0].Number / 100) * 60);
1326
#line 255 "./getdate.y"
1328
yyTimezone = yyvsp[0].Number;
1333
#line 259 "./getdate.y"
1335
yyTimezone = yyvsp[0].Number;
1340
#line 264 "./getdate.y"
1342
yyTimezone = yyvsp[-1].Number;
1347
#line 270 "./getdate.y"
1350
yyDayNumber = yyvsp[0].Number;
1354
#line 274 "./getdate.y"
1357
yyDayNumber = yyvsp[-1].Number;
1361
#line 278 "./getdate.y"
1363
yyDayOrdinal = yyvsp[-1].Number;
1364
yyDayNumber = yyvsp[0].Number;
1368
#line 284 "./getdate.y"
1370
yyMonth = yyvsp[-2].Number;
1371
yyDay = yyvsp[0].Number;
1375
#line 288 "./getdate.y"
1377
if (yyvsp[-4].Number >= 100) {
1378
yyYear = yyvsp[-4].Number;
1379
yyMonth = yyvsp[-2].Number;
1380
yyDay = yyvsp[0].Number;
1382
yyMonth = yyvsp[-4].Number;
1383
yyDay = yyvsp[-2].Number;
1384
yyYear = yyvsp[0].Number;
1389
#line 299 "./getdate.y"
1391
/* ISO 8601 format. yyyy-mm-dd. */
1392
yyYear = yyvsp[-2].Number;
1393
yyMonth = -yyvsp[-1].Number;
1394
yyDay = -yyvsp[0].Number;
1398
#line 305 "./getdate.y"
1400
/* e.g. 17-JUN-1992. */
1401
yyDay = yyvsp[-2].Number;
1402
yyMonth = yyvsp[-1].Number;
1403
yyYear = -yyvsp[0].Number;
1407
#line 311 "./getdate.y"
1409
yyMonth = yyvsp[-1].Number;
1410
yyDay = yyvsp[0].Number;
1414
#line 315 "./getdate.y"
1416
yyMonth = yyvsp[-3].Number;
1417
yyDay = yyvsp[-2].Number;
1418
yyYear = yyvsp[0].Number;
1422
#line 320 "./getdate.y"
1424
yyMonth = yyvsp[0].Number;
1425
yyDay = yyvsp[-1].Number;
1429
#line 324 "./getdate.y"
1431
yyMonth = yyvsp[-1].Number;
1432
yyDay = yyvsp[-2].Number;
1433
yyYear = yyvsp[0].Number;
1437
#line 331 "./getdate.y"
1439
yyRelSeconds = -yyRelSeconds;
1440
yyRelMonth = -yyRelMonth;
1444
#line 338 "./getdate.y"
1446
yyRelSeconds += yyvsp[-1].Number * yyvsp[0].Number * 60L;
1450
#line 341 "./getdate.y"
1452
yyRelSeconds += yyvsp[-1].Number * yyvsp[0].Number * 60L;
1456
#line 344 "./getdate.y"
1458
yyRelSeconds += yyvsp[0].Number * 60L;
1462
#line 347 "./getdate.y"
1464
yyRelSeconds += yyvsp[-1].Number;
1468
#line 350 "./getdate.y"
1470
yyRelSeconds += yyvsp[-1].Number;
1474
#line 353 "./getdate.y"
1480
#line 356 "./getdate.y"
1482
yyRelMonth += yyvsp[-1].Number * yyvsp[0].Number;
1486
#line 359 "./getdate.y"
1488
yyRelMonth += yyvsp[-1].Number * yyvsp[0].Number;
1492
#line 362 "./getdate.y"
1494
yyRelMonth += yyvsp[0].Number;
1498
#line 367 "./getdate.y"
1500
if (yyHaveTime && yyHaveDate && !yyHaveRel)
1501
yyYear = yyvsp[0].Number;
1503
if(yyvsp[0].Number>10000) {
1505
yyDay= (yyvsp[0].Number)%100;
1506
yyMonth= (yyvsp[0].Number/100)%100;
1507
yyYear = yyvsp[0].Number/10000;
1511
if (yyvsp[0].Number < 100) {
1512
yyHour = yyvsp[0].Number;
1516
yyHour = yyvsp[0].Number / 100;
1517
yyMinutes = yyvsp[0].Number % 100;
1526
#line 394 "./getdate.y"
1528
yyval.Meridian = MER24;
1532
#line 397 "./getdate.y"
1534
yyval.Meridian = yyvsp[0].Meridian;
1537
#line 1535 "getdate.c"
1543
if (yystate == 0 && yym == 0)
1547
printf("%sdebug: after reduction, shifting from state 0 to\
1548
state %d\n", YYPREFIX, YYFINAL);
1555
if ((yychar = yylex()) < 0) yychar = 0;
1560
if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
1561
if (!yys) yys = "illegal-symbol";
1562
printf("%sdebug: state %d, reading %d (%s)\n",
1563
YYPREFIX, YYFINAL, yychar, yys);
1567
if (yychar == 0) goto yyaccept;
1570
if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 &&
1571
yyn <= YYTABLESIZE && yycheck[yyn] == yystate)
1572
yystate = yytable[yyn];
1574
yystate = yydgoto[yym];
1577
printf("%sdebug: after reduction, shifting from state %d \
1578
to state %d\n", YYPREFIX, *yyssp, yystate);
1580
if (yyssp >= yysslim && yygrowstack())
1588
yyerror("yacc stack overflow");
1594
/*@=readonlytrans =modunconnomods @*/
1595
/*@=retvalint =usedef =varuse =nullderef =nullassign @*/
1596
/*@=globstate =statictrans =unqualifiedtrans =noparams @*/