2 /* A Bison parser, made from parsetime.y with Bison version GNU Bison version 1.22
5 #define YYBISON 1 /* Identify Bison output. */
49 #include "parsetime.h"
58 int add_date(int number, int period);
60 #line 17 "parsetime.y"
79 #define YYLTYPE yyltype
96 #define YYTRANSLATE(x) ((unsigned)(x) <= 293 ? yytranslate[x] : 67)
98 static const char yytranslate[] = { 0,
99 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
100 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
101 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
102 2, 2, 2, 2, 2, 2, 2, 2, 45, 2,
103 2, 2, 43, 39, 40, 41, 42, 2, 2, 2,
104 2, 2, 2, 2, 2, 2, 2, 44, 2, 2,
105 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
106 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
107 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
108 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
109 2, 2, 2, 46, 2, 2, 2, 2, 2, 2,
110 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
111 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
112 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
113 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
114 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
115 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
116 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
117 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
118 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
119 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
120 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
121 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
122 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
123 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
124 2, 2, 2, 2, 2, 1, 2, 3, 4, 5,
125 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
126 16, 17, 18, 19, 20, 21, 22, 23, 24, 25,
127 26, 27, 28, 29, 30, 31, 32, 33, 34, 35,
132 static const short yyprhs[] = { 0,
133 0, 2, 5, 8, 12, 15, 19, 21, 23, 26,
134 29, 31, 33, 36, 40, 45, 48, 52, 57, 63,
135 65, 67, 69, 72, 77, 79, 81, 83, 89, 95,
136 99, 102, 106, 112, 116, 119, 122, 126, 128, 130,
137 132, 134, 136, 138, 140, 142, 144, 146, 148, 150,
138 152, 154, 156, 158, 160, 162, 164, 166, 168, 170,
139 172, 174, 176, 178, 180, 182, 184, 186, 188, 190,
140 192, 194, 196, 198, 200, 202, 204
143 static const short yyrhs[] = { 50,
144 0, 50, 51, 0, 50, 52, 0, 50, 51, 52,
145 0, 50, 53, 0, 50, 51, 53, 0, 48, 0,
146 49, 0, 49, 52, 0, 49, 53, 0, 4, 0,
147 55, 0, 55, 56, 0, 57, 66, 58, 0, 57,
148 66, 58, 56, 0, 57, 59, 0, 57, 59, 56,
149 0, 57, 66, 58, 59, 0, 57, 66, 58, 59,
150 56, 0, 7, 0, 8, 0, 9, 0, 60, 62,
151 0, 60, 62, 39, 63, 0, 64, 0, 17, 0,
152 18, 0, 63, 40, 61, 40, 62, 0, 62, 41,
153 61, 41, 63, 0, 62, 41, 61, 0, 62, 60,
154 0, 62, 60, 63, 0, 61, 42, 62, 42, 63,
155 0, 43, 65, 54, 0, 19, 54, 0, 19, 64,
156 0, 40, 65, 54, 0, 20, 0, 21, 0, 22,
157 0, 23, 0, 24, 0, 25, 0, 3, 0, 38,
158 0, 55, 0, 3, 0, 5, 0, 6, 0, 26,
159 0, 27, 0, 28, 0, 29, 0, 30, 0, 31,
160 0, 32, 0, 33, 0, 34, 0, 35, 0, 36,
161 0, 37, 0, 3, 0, 3, 0, 3, 0, 10,
162 0, 11, 0, 12, 0, 13, 0, 14, 0, 15,
163 0, 16, 0, 3, 0, 44, 0, 45, 0, 41,
170 static const short yyrline[] = { 0,
171 39, 43, 44, 45, 46, 47, 48, 51, 52, 53,
172 56, 59, 60, 61, 62, 63, 64, 65, 66, 67,
173 72, 78, 85, 86, 87, 91, 92, 96, 97, 98,
174 99, 100, 101, 104, 108, 112, 118, 124, 125, 126,
175 127, 128, 129, 132, 157, 170, 173, 183, 184, 197,
176 198, 199, 200, 201, 202, 203, 204, 205, 206, 207,
177 208, 211, 225, 238, 261, 262, 263, 264, 265, 266,
178 267, 270, 280, 281, 282, 283, 284
181 static const char * const yytname[] = { "$","error","$illegal.","INT","NOW",
182 "AM","PM","NOON","MIDNIGHT","TEATIME","SUN","MON","TUE","WED","THU","FRI","SAT",
183 "TODAY","TOMORROW","NEXT","MINUTE","HOUR","DAY","WEEK","MONTH","YEAR","JAN",
184 "FEB","MAR","APR","MAY","JUN","JUL","AUG","SEP","OCT","NOV","DEC","WORD","','",
185 "'-'","'.'","'/'","'+'","':'","'\\''","'h'","timespec","nowspec","now","time",
186 "date","increment","decrement","inc_period","hr24clock_hr_min","timezone_name",
187 "hr24clock_hour","minute","am_pm","month_name","month_number","day_number","year_number",
188 "day_of_week","inc_number","time_sep",""
192 static const short yyr1[] = { 0,
193 47, 47, 47, 47, 47, 47, 47, 48, 48, 48,
194 49, 50, 50, 50, 50, 50, 50, 50, 50, 50,
195 50, 50, 51, 51, 51, 51, 51, 51, 51, 51,
196 51, 51, 51, 52, 52, 52, 53, 54, 54, 54,
197 54, 54, 54, 55, 56, 57, 58, 59, 59, 60,
198 60, 60, 60, 60, 60, 60, 60, 60, 60, 60,
199 60, 61, 62, 63, 64, 64, 64, 64, 64, 64,
200 64, 65, 66, 66, 66, 66, 66
203 static const short yyr2[] = { 0,
204 1, 2, 2, 3, 2, 3, 1, 1, 2, 2,
205 1, 1, 2, 3, 4, 2, 3, 4, 5, 1,
206 1, 1, 2, 4, 1, 1, 1, 5, 5, 3,
207 2, 3, 5, 3, 2, 2, 3, 1, 1, 1,
208 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
209 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
210 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
214 static const short yydefact[] = { 0,
215 44, 11, 20, 21, 22, 7, 8, 1, 12, 0,
216 0, 0, 0, 9, 10, 63, 65, 66, 67, 68,
217 69, 70, 71, 26, 27, 50, 51, 52, 53, 54,
218 55, 56, 57, 58, 59, 60, 61, 2, 3, 5,
219 0, 0, 0, 0, 25, 45, 13, 48, 49, 77,
220 75, 73, 74, 76, 16, 0, 38, 39, 40, 41,
221 42, 43, 35, 36, 72, 0, 0, 4, 6, 63,
222 23, 0, 0, 31, 0, 17, 47, 14, 37, 34,
223 0, 0, 62, 30, 64, 32, 0, 15, 18, 24,
224 0, 0, 0, 19, 33, 29, 28, 0, 0, 0
227 static const short yydefgoto[] = { 98,
228 6, 7, 8, 38, 14, 15, 63, 9, 47, 10,
229 78, 55, 41, 42, 43, 44, 45, 66, 56
232 static const short yypact[] = { 8,
233 -32768,-32768,-32768,-32768,-32768,-32768, -14, 43, -4, 4,
234 80, 5, 5,-32768,-32768, -12,-32768,-32768,-32768,-32768,
235 -32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,
236 -32768,-32768,-32768,-32768,-32768,-32768,-32768, -14,-32768,-32768,
237 10, -6, 81, -8,-32768,-32768,-32768,-32768,-32768,-32768,
238 -32768,-32768,-32768,-32768, 9, 48,-32768,-32768,-32768,-32768,
239 -32768,-32768,-32768,-32768,-32768, -2, -2,-32768,-32768,-32768,
240 25, 10, 63, 64, 63,-32768,-32768, 1,-32768,-32768,
241 64, 26,-32768, 41,-32768,-32768, 44,-32768, 9,-32768,
242 64, 64, 10,-32768,-32768,-32768,-32768, 85, 87,-32768
245 static const short yypgoto[] = {-32768,
246 -32768,-32768,-32768,-32768, -5, 6, -42,-32768, -51,-32768,
247 -32768, 11, 54, -10, -41, 7, 95, 106,-32768
254 static const short yytable[] = { 71,
255 -46, -46, 39, 76, 11, 48, 49, 65, 48, 49,
256 1, 2, 70, 40, 3, 4, 5, 57, 58, 59,
257 60, 61, 62, 79, 80, 12, 88, -64, 13, -62,
258 82, 75, 68, 46, -46, 72, -46, 94, 46, -46,
259 -46, -46, 50, 69, 51, 16, 46, 52, 53, 54,
260 77, 97, 17, 18, 19, 20, 21, 22, 23, 24,
261 25, 11, 84, 81, 87, 83, 85, 91, 26, 27,
262 28, 29, 30, 31, 32, 33, 34, 35, 36, 37,
263 86, 92, 12, 93, 99, 13, 100, 90, 89, 17,
264 18, 19, 20, 21, 22, 23, 74, 95, 96, 57,
265 58, 59, 60, 61, 62, 64, 26, 27, 28, 29,
266 30, 31, 32, 33, 34, 35, 36, 37, 67, 0,
270 static const short yycheck[] = { 41,
271 5, 6, 8, 55, 19, 5, 6, 3, 5, 6,
272 3, 4, 3, 8, 7, 8, 9, 20, 21, 22,
273 23, 24, 25, 66, 67, 40, 78, 40, 43, 42,
274 72, 40, 38, 38, 39, 42, 41, 89, 38, 44,
275 45, 46, 39, 38, 41, 3, 38, 44, 45, 46,
276 3, 93, 10, 11, 12, 13, 14, 15, 16, 17,
277 18, 19, 73, 39, 75, 3, 3, 42, 26, 27,
278 28, 29, 30, 31, 32, 33, 34, 35, 36, 37,
279 74, 41, 40, 40, 0, 43, 0, 81, 78, 10,
280 11, 12, 13, 14, 15, 16, 43, 91, 92, 20,
281 21, 22, 23, 24, 25, 11, 26, 27, 28, 29,
282 30, 31, 32, 33, 34, 35, 36, 37, 13, -1,
285 /* -*-C-*- Note some compilers choke on comments on `#line' lines. */
286 #line 3 "/usr/lib/bison.simple"
288 /* Skeleton output parser for bison,
289 Copyright (C) 1984, 1989, 1990 Bob Corbett and Richard Stallman
291 This program is free software; you can redistribute it and/or modify
292 it under the terms of the GNU General Public License as published by
293 the Free Software Foundation; either version 1, or (at your option)
296 This program is distributed in the hope that it will be useful,
297 but WITHOUT ANY WARRANTY; without even the implied warranty of
298 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
299 GNU General Public License for more details.
301 You should have received a copy of the GNU General Public License
302 along with this program; if not, write to the Free Software
303 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
308 #define alloca __builtin_alloca
309 #else /* not GNU C. */
310 #if (!defined (__STDC__) && defined (sparc)) || defined (__sparc__) || defined (__sparc) || defined (__sgi)
312 #else /* not sparc */
313 #if defined (MSDOS) && !defined (__TURBOC__)
315 #else /* not MSDOS, or __TURBOC__ */
319 #else /* not MSDOS, __TURBOC__, or _AIX */
323 void *alloca (unsigned int);
325 #else /* not __cplusplus */
327 #endif /* not __cplusplus */
329 #endif /* not _AIX */
330 #endif /* not MSDOS, or __TURBOC__ */
331 #endif /* not sparc. */
332 #endif /* not GNU C. */
333 #endif /* alloca not defined. */
335 /* This is the parser code that is written into each bison parser
336 when the %semantic_parser declaration is not specified in the grammar.
337 It was written by Richard Stallman by simplifying the hairy parser
338 used when %semantic_parser is specified. */
340 /* Note: there must be only one dollar sign in this file.
341 It is replaced by the list of actions, each action
342 as one case of the switch. */
344 #define yyerrok (yyerrstatus = 0)
345 #define yyclearin (yychar = YYEMPTY)
348 #define YYACCEPT return(0)
349 #define YYABORT return(1)
350 #define YYERROR goto yyerrlab1
351 /* Like YYERROR except do call yyerror.
352 This remains here temporarily to ease the
353 transition to the new meaning of YYERROR, for GCC.
354 Once GCC version 2 has supplanted version 1, this can go. */
355 #define YYFAIL goto yyerrlab
356 #define YYRECOVERING() (!!yyerrstatus)
357 #define YYBACKUP(token, value) \
359 if (yychar == YYEMPTY && yylen == 1) \
360 { yychar = (token), yylval = (value); \
361 yychar1 = YYTRANSLATE (yychar); \
366 { yyerror ("syntax error: cannot back up"); YYERROR; } \
370 #define YYERRCODE 256
373 #define YYLEX yylex()
378 #define YYLEX yylex(&yylval, &yylloc)
380 #define YYLEX yylex(&yylval)
384 /* If nonreentrant, generate the variables here */
388 int yychar; /* the lookahead symbol */
389 YYSTYPE yylval; /* the semantic value of the */
390 /* lookahead symbol */
393 YYLTYPE yylloc; /* location data for the lookahead */
397 int yynerrs; /* number of parse errors so far */
398 #endif /* not YYPURE */
401 int yydebug; /* nonzero means print parse trace */
402 /* Since this is uninitialized, it does not stop multiple parsers
406 /* YYINITDEPTH indicates the initial size of the parser's stacks */
409 #define YYINITDEPTH 200
412 /* YYMAXDEPTH is the maximum size the stacks can grow to
413 (effective only if the built-in stack extension method is used). */
420 #define YYMAXDEPTH 10000
423 /* Prevent warning if -Wstrict-prototypes. */
428 #if __GNUC__ > 1 /* GNU C and GNU C++ define this. */
429 #define __yy_bcopy(FROM,TO,COUNT) __builtin_memcpy(TO,FROM,COUNT)
430 #else /* not GNU C or C++ */
433 /* This is the most reliable way to avoid incompatibilities
434 in available built-in functions on various systems. */
436 __yy_bcopy (from, to, count)
441 register char *f = from;
442 register char *t = to;
443 register int i = count;
449 #else /* __cplusplus */
451 /* This is the most reliable way to avoid incompatibilities
452 in available built-in functions on various systems. */
454 __yy_bcopy (char *from, char *to, int count)
456 register char *f = from;
457 register char *t = to;
458 register int i = count;
467 #line 184 "/usr/lib/bison.simple"
471 register int yystate;
473 register short *yyssp;
474 register YYSTYPE *yyvsp;
475 int yyerrstatus; /* number of tokens to shift before error messages enabled */
476 int yychar1 = 0; /* lookahead token as an internal (translated) token number */
478 short yyssa[YYINITDEPTH]; /* the state stack */
479 YYSTYPE yyvsa[YYINITDEPTH]; /* the semantic value stack */
481 short *yyss = yyssa; /* refer to the stacks thru separate pointers */
482 YYSTYPE *yyvs = yyvsa; /* to allow yyoverflow to reallocate them elsewhere */
485 YYLTYPE yylsa[YYINITDEPTH]; /* the location stack */
486 YYLTYPE *yyls = yylsa;
489 #define YYPOPSTACK (yyvsp--, yyssp--, yylsp--)
491 #define YYPOPSTACK (yyvsp--, yyssp--)
494 int yystacksize = YYINITDEPTH;
505 YYSTYPE yyval; /* the variable used to return */
506 /* semantic values from the action */
513 fprintf(stderr, "Starting parse\n");
519 yychar = YYEMPTY; /* Cause a token to be read. */
521 /* Initialize stack pointers.
522 Waste one element of value and location stack
523 so that they stay on the same level as the state stack.
524 The wasted elements are never initialized. */
532 /* Push a new state, which is found in yystate . */
533 /* In all cases, when you get here, the value and location stacks
534 have just been pushed. so pushing a state here evens the stacks. */
539 if (yyssp >= yyss + yystacksize - 1)
541 /* Give user a chance to reallocate the stack */
542 /* Use copies of these so that the &'s don't force the real ones into memory. */
543 YYSTYPE *yyvs1 = yyvs;
546 YYLTYPE *yyls1 = yyls;
549 /* Get the current used size of the three stacks, in elements. */
550 int size = yyssp - yyss + 1;
553 /* Each stack pointer address is followed by the size of
554 the data in use in that stack, in bytes. */
556 /* This used to be a conditional around just the two extra args,
557 but that might be undefined if yyoverflow is a macro. */
558 yyoverflow("parser stack overflow",
559 &yyss1, size * sizeof (*yyssp),
560 &yyvs1, size * sizeof (*yyvsp),
561 &yyls1, size * sizeof (*yylsp),
564 yyoverflow("parser stack overflow",
565 &yyss1, size * sizeof (*yyssp),
566 &yyvs1, size * sizeof (*yyvsp),
570 yyss = yyss1; yyvs = yyvs1;
574 #else /* no yyoverflow */
575 /* Extend the stack our own way. */
576 if (yystacksize >= YYMAXDEPTH)
578 yyerror("parser stack overflow");
582 if (yystacksize > YYMAXDEPTH)
583 yystacksize = YYMAXDEPTH;
584 yyss = (short *) alloca (yystacksize * sizeof (*yyssp));
585 __yy_bcopy ((char *)yyss1, (char *)yyss, size * sizeof (*yyssp));
586 yyvs = (YYSTYPE *) alloca (yystacksize * sizeof (*yyvsp));
587 __yy_bcopy ((char *)yyvs1, (char *)yyvs, size * sizeof (*yyvsp));
589 yyls = (YYLTYPE *) alloca (yystacksize * sizeof (*yylsp));
590 __yy_bcopy ((char *)yyls1, (char *)yyls, size * sizeof (*yylsp));
592 #endif /* no yyoverflow */
594 yyssp = yyss + size - 1;
595 yyvsp = yyvs + size - 1;
597 yylsp = yyls + size - 1;
602 fprintf(stderr, "Stack size increased to %d\n", yystacksize);
605 if (yyssp >= yyss + yystacksize - 1)
611 fprintf(stderr, "Entering state %d\n", yystate);
617 /* Do appropriate processing given the current state. */
618 /* Read a lookahead token if we need one and don't already have one. */
621 /* First try to decide what to do without reference to lookahead token. */
623 yyn = yypact[yystate];
627 /* Not known => get a lookahead token if don't already have one. */
629 /* yychar is either YYEMPTY or YYEOF
630 or a valid token in external form. */
632 if (yychar == YYEMPTY)
636 fprintf(stderr, "Reading a token: ");
641 /* Convert token to internal form (in yychar1) for indexing tables with */
643 if (yychar <= 0) /* This means end of input. */
646 yychar = YYEOF; /* Don't call YYLEX any more */
650 fprintf(stderr, "Now at end of input.\n");
655 yychar1 = YYTRANSLATE(yychar);
660 fprintf (stderr, "Next token is %d (%s", yychar, yytname[yychar1]);
661 /* Give the individual parser a way to print the precise meaning
662 of a token, for further debugging info. */
664 YYPRINT (stderr, yychar, yylval);
666 fprintf (stderr, ")\n");
672 if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != yychar1)
677 /* yyn is what to do for this token type in this state.
678 Negative => reduce, -yyn is rule number.
679 Positive => shift, yyn is new state.
680 New state is final state => don't bother to shift,
682 0, or most negative number => error. */
697 /* Shift the lookahead token. */
701 fprintf(stderr, "Shifting token %d (%s), ", yychar, yytname[yychar1]);
704 /* Discard the token being shifted unless it is eof. */
713 /* count tokens shifted since error; after three, turn off error status. */
714 if (yyerrstatus) yyerrstatus--;
719 /* Do the default action for the current state. */
722 yyn = yydefact[yystate];
726 /* Do a reduction. yyn is the number of a rule to reduce with. */
730 yyval = yyvsp[1-yylen]; /* implement default value of the action */
737 fprintf (stderr, "Reducing via rule %d (line %d), ",
740 /* Print the symbols being reduced, and their result. */
741 for (i = yyprhs[yyn]; yyrhs[i] > 0; i++)
742 fprintf (stderr, "%s ", yytname[yyrhs[i]]);
743 fprintf (stderr, " -> %s\n", yytname[yyr1[yyn]]);
751 #line 40 "parsetime.y"
757 #line 68 "parsetime.y"
764 #line 73 "parsetime.y"
772 #line 79 "parsetime.y"
779 #line 88 "parsetime.y"
781 add_date ((7 + yyvsp[0].intval - exectm.tm_wday) %7, DAY);
785 #line 93 "parsetime.y"
791 #line 105 "parsetime.y"
793 add_date(yyvsp[-1].intval, yyvsp[0].intval);
797 #line 109 "parsetime.y"
799 add_date(1, yyvsp[0].intval);
803 #line 113 "parsetime.y"
805 add_date ((7 + yyvsp[0].intval - exectm.tm_wday) %7, DAY);
809 #line 119 "parsetime.y"
811 add_date(-yyvsp[-1].intval, yyvsp[0].intval);
815 #line 124 "parsetime.y"
816 { yyval.intval = MINUTE ; ;
819 #line 125 "parsetime.y"
820 { yyval.intval = HOUR ; ;
823 #line 126 "parsetime.y"
824 { yyval.intval = DAY ; ;
827 #line 127 "parsetime.y"
828 { yyval.intval = WEEK ; ;
831 #line 128 "parsetime.y"
832 { yyval.intval = MONTH ; ;
835 #line 129 "parsetime.y"
836 { yyval.intval = YEAR ; ;
839 #line 133 "parsetime.y"
843 if (strlen(yyvsp[0].charval) == 4) {
844 sscanf(yyvsp[0].charval, "%2d %2d", &exectm.tm_hour,
848 sscanf(yyvsp[0].charval, "%d", &exectm.tm_hour);
851 free(yyvsp[0].charval);
853 if (exectm.tm_min > 60 || exectm.tm_min < 0) {
854 yyerror("Problem in minutes specification");
857 if (exectm.tm_hour > 24 || exectm.tm_hour < 0) {
858 yyerror("Problem in minutes specification");
864 #line 158 "parsetime.y"
866 if (strcasecmp(yyvsp[0].charval,"utc") == 0) {
870 yyerror("Only UTC timezone is supported");
873 free(yyvsp[0].charval);
877 #line 174 "parsetime.y"
879 if (sscanf(yyvsp[0].charval, "%d", &exectm.tm_min) != 1) {
880 yyerror("Error in minute");
883 free(yyvsp[0].charval);
887 #line 185 "parsetime.y"
889 if (exectm.tm_hour > 12) {
890 yyerror("Hour too large for PM");
893 else if (exectm.tm_hour < 12) {
899 #line 197 "parsetime.y"
900 { exectm.tm_mon = 0; ;
903 #line 198 "parsetime.y"
904 { exectm.tm_mon = 1; ;
907 #line 199 "parsetime.y"
908 { exectm.tm_mon = 2; ;
911 #line 200 "parsetime.y"
912 { exectm.tm_mon = 3; ;
915 #line 201 "parsetime.y"
916 { exectm.tm_mon = 4; ;
919 #line 202 "parsetime.y"
920 { exectm.tm_mon = 5; ;
923 #line 203 "parsetime.y"
924 { exectm.tm_mon = 6; ;
927 #line 204 "parsetime.y"
928 { exectm.tm_mon = 7; ;
931 #line 205 "parsetime.y"
932 { exectm.tm_mon = 8; ;
935 #line 206 "parsetime.y"
936 { exectm.tm_mon = 9; ;
939 #line 207 "parsetime.y"
940 { exectm.tm_mon =10; ;
943 #line 208 "parsetime.y"
944 { exectm.tm_mon =11; ;
947 #line 212 "parsetime.y"
951 sscanf(yyvsp[0].charval, "%d", &mnum);
953 if (mnum < 1 || mnum > 12) {
954 yyerror("Error in month number");
957 exectm.tm_mon = mnum -1;
958 free(yyvsp[0].charval);
963 #line 226 "parsetime.y"
966 sscanf(yyvsp[0].charval, "%d", &exectm.tm_mday);
967 if (exectm.tm_mday < 0 || exectm.tm_mday > 31)
969 yyerror("Error in day of month");
972 free(yyvsp[0].charval);
976 #line 239 "parsetime.y"
981 if ( sscanf(yyvsp[0].charval, "%d", &ynum) != 1) {
982 yyerror("Error in year");
988 else if (ynum > 1900) {
992 exectm.tm_year = ynum ;
993 free(yyvsp[0].charval);
998 #line 261 "parsetime.y"
999 { yyval.intval = 0; ;
1002 #line 262 "parsetime.y"
1003 { yyval.intval = 1; ;
1006 #line 263 "parsetime.y"
1007 { yyval.intval = 2; ;
1010 #line 264 "parsetime.y"
1011 { yyval.intval = 3; ;
1014 #line 265 "parsetime.y"
1015 { yyval.intval = 4; ;
1018 #line 266 "parsetime.y"
1019 { yyval.intval = 5; ;
1022 #line 267 "parsetime.y"
1023 { yyval.intval = 6; ;
1026 #line 271 "parsetime.y"
1028 if (sscanf(yyvsp[0].charval, "%d", &yyval.intval) != 1) {
1029 yyerror("Unknown increment");
1032 free(yyvsp[0].charval);
1036 /* the action file gets copied in in place of this dollarsign */
1037 #line 465 "/usr/lib/bison.simple"
1048 short *ssp1 = yyss - 1;
1049 fprintf (stderr, "state stack now");
1050 while (ssp1 != yyssp)
1051 fprintf (stderr, " %d", *++ssp1);
1052 fprintf (stderr, "\n");
1062 yylsp->first_line = yylloc.first_line;
1063 yylsp->first_column = yylloc.first_column;
1064 yylsp->last_line = (yylsp-1)->last_line;
1065 yylsp->last_column = (yylsp-1)->last_column;
1070 yylsp->last_line = (yylsp+yylen-1)->last_line;
1071 yylsp->last_column = (yylsp+yylen-1)->last_column;
1075 /* Now "shift" the result of the reduction.
1076 Determine what state that goes to,
1077 based on the state we popped back to
1078 and the rule number reduced by. */
1082 yystate = yypgoto[yyn - YYNTBASE] + *yyssp;
1083 if (yystate >= 0 && yystate <= YYLAST && yycheck[yystate] == *yyssp)
1084 yystate = yytable[yystate];
1086 yystate = yydefgoto[yyn - YYNTBASE];
1090 yyerrlab: /* here on detecting error */
1093 /* If not already recovering from an error, report this error. */
1097 #ifdef YYERROR_VERBOSE
1098 yyn = yypact[yystate];
1100 if (yyn > YYFLAG && yyn < YYLAST)
1107 /* Start X at -yyn if nec to avoid negative indexes in yycheck. */
1108 for (x = (yyn < 0 ? -yyn : 0);
1109 x < (sizeof(yytname) / sizeof(char *)); x++)
1110 if (yycheck[x + yyn] == x)
1111 size += strlen(yytname[x]) + 15, count++;
1112 msg = (char *) malloc(size + 15);
1115 strcpy(msg, "parse error");
1120 for (x = (yyn < 0 ? -yyn : 0);
1121 x < (sizeof(yytname) / sizeof(char *)); x++)
1122 if (yycheck[x + yyn] == x)
1124 strcat(msg, count == 0 ? ", expecting `" : " or `");
1125 strcat(msg, yytname[x]);
1134 yyerror ("parse error; also virtual memory exceeded");
1137 #endif /* YYERROR_VERBOSE */
1138 yyerror("parse error");
1142 yyerrlab1: /* here on error raised explicitly by an action */
1144 if (yyerrstatus == 3)
1146 /* if just tried and failed to reuse lookahead token after an error, discard it. */
1148 /* return failure if at end of input */
1149 if (yychar == YYEOF)
1154 fprintf(stderr, "Discarding token %d (%s).\n", yychar, yytname[yychar1]);
1160 /* Else will try to reuse lookahead token
1161 after shifting the error token. */
1163 yyerrstatus = 3; /* Each real token shifted decrements this */
1167 yyerrdefault: /* current state does not do anything special for the error token. */
1170 /* This is wrong; only states that explicitly want error tokens
1171 should shift them. */
1172 yyn = yydefact[yystate]; /* If its default is to accept any token, ok. Otherwise pop it.*/
1173 if (yyn) goto yydefault;
1176 yyerrpop: /* pop the current state because it cannot handle the error token */
1178 if (yyssp == yyss) YYABORT;
1188 short *ssp1 = yyss - 1;
1189 fprintf (stderr, "Error: state stack now");
1190 while (ssp1 != yyssp)
1191 fprintf (stderr, " %d", *++ssp1);
1192 fprintf (stderr, "\n");
1198 yyn = yypact[yystate];
1203 if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != YYTERROR)
1222 fprintf(stderr, "Shifting error token, ");
1233 #line 287 "parsetime.y"
1237 time_t parsetime(int, char **);
1240 parsetime(int argc, char **argv)
1245 currtime = time(NULL);
1246 exectm = *localtime(&currtime);
1248 exectm.tm_isdst = -1;
1250 if (yyparse() == 0) {
1251 exectime = mktime(&exectm);
1253 exectime += timezone;
1258 if (time_only && (currtime > exectime)) {
1259 exectime += 24*3600;
1270 main(int argc, char **argv)
1273 res = parsetime(argc-1, &argv[1]);
1275 printf("%s",ctime(&res));
1278 printf("Ooops...\n");
1284 int yyerror(char *s)
1286 if (last_token == NULL)
1287 last_token = "(empty)";
1288 fprintf(stderr,"%s. Last token seen: %s\n",s, last_token);
1293 add_seconds(struct tm *tm, long numsec)
1296 timeval = mktime(tm);
1298 *tm = *localtime(&timeval);
1302 add_date(int number, int period)
1306 add_seconds(&exectm , 60l*number);
1310 add_seconds(&exectm, 3600l * number);
1314 add_seconds(&exectm, 24*3600l * number);
1318 add_seconds(&exectm, 7*24*3600l*number);
1323 int newmonth = exectm.tm_mon + number;
1325 while (newmonth < 0) {
1329 exectm.tm_mon = newmonth % 12;
1330 number += newmonth / 12 ;
1338 exectm.tm_year += number;
1342 yyerror("Internal parser error");
1343 fprintf(stderr,"Unexpected case %d\n", period);