.
[coreutils.git] / lib / posixtm.c
blobc029a16dd2c593a175ef5fbf2b301274c0e821b2
2 /* A Bison parser, made from ./posixtm.y with Bison version GNU Bison version 1.22
3 */
5 #define YYBISON 1 /* Identify Bison output. */
7 #define DIGIT 258
9 #line 19 "./posixtm.y"
12 #ifdef HAVE_CONFIG_H
13 #include <config.h>
14 #endif
16 /* The following block of alloca-related preprocessor directives is here
17 solely to allow compilation by non GNU-C compilers of the C parser
18 produced from this file by old versions of bison. Newer versions of
19 bison include a block similar to this one in bison.simple. */
21 #ifdef __GNUC__
22 #define alloca __builtin_alloca
23 #else
24 #ifdef HAVE_ALLOCA_H
25 #include <alloca.h>
26 #else
27 #ifdef _AIX
28 #pragma alloca
29 #else
30 void *alloca ();
31 #endif
32 #endif
33 #endif
35 #include <stdio.h>
36 #include <sys/types.h>
38 #ifdef TM_IN_SYS_TIME
39 #include <sys/time.h>
40 #else
41 #include <time.h>
42 #endif
44 /* Some old versions of bison generate parsers that use bcopy.
45 That loses on systems that don't provide the function, so we have
46 to redefine it here. */
47 #if !defined (HAVE_BCOPY) && defined (HAVE_MEMCPY) && !defined (bcopy)
48 #define bcopy(from, to, len) memcpy ((to), (from), (len))
49 #endif
51 #define YYDEBUG 1
53 /* Lexical analyzer's current scan position in the input string. */
54 static char *curpos;
56 /* The return value. */
57 static struct tm t;
59 time_t mktime ();
61 #define zzparse posixtime_zzparse
62 static int zzlex ();
63 static int zzerror ();
65 #ifndef YYLTYPE
66 typedef
67 struct zzltype
69 int timestamp;
70 int first_line;
71 int first_column;
72 int last_line;
73 int last_column;
74 char *text;
76 zzltype;
78 #define YYLTYPE zzltype
79 #endif
81 #ifndef YYSTYPE
82 #define YYSTYPE int
83 #endif
84 #include <stdio.h>
86 #ifndef __cplusplus
87 #ifndef __STDC__
88 #define const
89 #endif
90 #endif
94 #define YYFINAL 15
95 #define YYFLAG -32768
96 #define YYNTBASE 5
98 #define YYTRANSLATE(x) ((unsigned)(x) <= 258 ? zztranslate[x] : 9)
100 static const char zztranslate[] = { 0,
101 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
102 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
103 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
104 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
105 2, 2, 2, 2, 2, 4, 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, 2, 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, 2, 2, 2, 2, 2,
125 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
126 2, 2, 2, 2, 2, 1, 2, 3
129 #if YYDEBUG != 0
130 static const short zzprhs[] = { 0,
131 0, 7, 9, 12, 13, 14, 17
134 static const short zzrhs[] = { 8,
135 8, 8, 8, 6, 7, 0, 8, 0, 8, 8,
136 0, 0, 0, 4, 8, 0, 3, 3, 0
139 #endif
141 #if YYDEBUG != 0
142 static const short zzrline[] = { 0,
143 78, 107, 114, 121, 132, 135, 144
146 static const char * const zztname[] = { "$","error","$illegal.","DIGIT","'.'",
147 "date","year","seconds","digitpair",""
149 #endif
151 static const short zzr1[] = { 0,
152 5, 6, 6, 6, 7, 7, 8
155 static const short zzr2[] = { 0,
156 6, 1, 2, 0, 0, 2, 2
159 static const short zzdefact[] = { 0,
160 0, 0, 7, 0, 0, 4, 5, 2, 0, 1,
161 3, 6, 0, 0, 0
164 static const short zzdefgoto[] = { 13,
165 7, 10, 2
168 static const short zzpact[] = { 2,
169 5, 2,-32768, 2, 2, 2, -3, 2, 2,-32768,
170 -32768,-32768, 9, 10,-32768
173 static const short zzpgoto[] = {-32768,
174 -32768,-32768, -2
178 #define YYLAST 10
181 static const short zztable[] = { 4,
182 9, 5, 6, 8, 1, 11, 12, 3, 14, 15
185 static const short zzcheck[] = { 2,
186 4, 4, 5, 6, 3, 8, 9, 3, 0, 0
188 /* -*-C-*- Note some compilers choke on comments on `#line' lines. */
189 #line 3 "/usr/local/lib/bison.simple"
191 /* Skeleton output parser for bison,
192 Copyright (C) 1984, 1989, 1990 Bob Corbett and Richard Stallman
194 This program is free software; you can redistribute it and/or modify
195 it under the terms of the GNU General Public License as published by
196 the Free Software Foundation; either version 1, or (at your option)
197 any later version.
199 This program is distributed in the hope that it will be useful,
200 but WITHOUT ANY WARRANTY; without even the implied warranty of
201 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
202 GNU General Public License for more details.
204 You should have received a copy of the GNU General Public License
205 along with this program; if not, write to the Free Software
206 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
209 #ifndef alloca
210 #ifdef __GNUC__
211 #define alloca __builtin_alloca
212 #else /* not GNU C. */
213 #if (!defined (__STDC__) && defined (sparc)) || defined (__sparc__) || defined (__sparc) || defined (__sgi)
214 #include <alloca.h>
215 #else /* not sparc */
216 #if defined (MSDOS) && !defined (__TURBOC__)
217 #include <malloc.h>
218 #else /* not MSDOS, or __TURBOC__ */
219 #if defined(_AIX)
220 #include <malloc.h>
221 #pragma alloca
222 #else /* not MSDOS, __TURBOC__, or _AIX */
223 #ifdef __hpux
224 #ifdef __cplusplus
225 extern "C" {
226 void *alloca (unsigned int);
228 #else /* not __cplusplus */
229 void *alloca ();
230 #endif /* not __cplusplus */
231 #endif /* __hpux */
232 #endif /* not _AIX */
233 #endif /* not MSDOS, or __TURBOC__ */
234 #endif /* not sparc. */
235 #endif /* not GNU C. */
236 #endif /* alloca not defined. */
238 /* This is the parser code that is written into each bison parser
239 when the %semantic_parser declaration is not specified in the grammar.
240 It was written by Richard Stallman by simplifying the hairy parser
241 used when %semantic_parser is specified. */
243 /* Note: there must be only one dollar sign in this file.
244 It is replaced by the list of actions, each action
245 as one case of the switch. */
247 #define zzerrok (zzerrstatus = 0)
248 #define zzclearin (zzchar = YYEMPTY)
249 #define YYEMPTY -2
250 #define YYEOF 0
251 #define YYACCEPT return(0)
252 #define YYABORT return(1)
253 #define YYERROR goto zzerrlab1
254 /* Like YYERROR except do call zzerror.
255 This remains here temporarily to ease the
256 transition to the new meaning of YYERROR, for GCC.
257 Once GCC version 2 has supplanted version 1, this can go. */
258 #define YYFAIL goto zzerrlab
259 #define YYRECOVERING() (!!zzerrstatus)
260 #define YYBACKUP(token, value) \
261 do \
262 if (zzchar == YYEMPTY && zzlen == 1) \
263 { zzchar = (token), zzlval = (value); \
264 zzchar1 = YYTRANSLATE (zzchar); \
265 YYPOPSTACK; \
266 goto zzbackup; \
268 else \
269 { zzerror ("syntax error: cannot back up"); YYERROR; } \
270 while (0)
272 #define YYTERROR 1
273 #define YYERRCODE 256
275 #ifndef YYPURE
276 #define YYLEX zzlex()
277 #endif
279 #ifdef YYPURE
280 #ifdef YYLSP_NEEDED
281 #define YYLEX zzlex(&zzlval, &zzlloc)
282 #else
283 #define YYLEX zzlex(&zzlval)
284 #endif
285 #endif
287 /* If nonreentrant, generate the variables here */
289 #ifndef YYPURE
291 int zzchar; /* the lookahead symbol */
292 YYSTYPE zzlval; /* the semantic value of the */
293 /* lookahead symbol */
295 #ifdef YYLSP_NEEDED
296 YYLTYPE zzlloc; /* location data for the lookahead */
297 /* symbol */
298 #endif
300 int zznerrs; /* number of parse errors so far */
301 #endif /* not YYPURE */
303 #if YYDEBUG != 0
304 int zzdebug; /* nonzero means print parse trace */
305 /* Since this is uninitialized, it does not stop multiple parsers
306 from coexisting. */
307 #endif
309 /* YYINITDEPTH indicates the initial size of the parser's stacks */
311 #ifndef YYINITDEPTH
312 #define YYINITDEPTH 200
313 #endif
315 /* YYMAXDEPTH is the maximum size the stacks can grow to
316 (effective only if the built-in stack extension method is used). */
318 #if YYMAXDEPTH == 0
319 #undef YYMAXDEPTH
320 #endif
322 #ifndef YYMAXDEPTH
323 #define YYMAXDEPTH 10000
324 #endif
326 /* Prevent warning if -Wstrict-prototypes. */
327 #ifdef __GNUC__
328 int zzparse (void);
329 #endif
331 #if __GNUC__ > 1 /* GNU C and GNU C++ define this. */
332 #define __zz_bcopy(FROM,TO,COUNT) __builtin_memcpy(TO,FROM,COUNT)
333 #else /* not GNU C or C++ */
334 #ifndef __cplusplus
336 /* This is the most reliable way to avoid incompatibilities
337 in available built-in functions on various systems. */
338 static void
339 __zz_bcopy (from, to, count)
340 char *from;
341 char *to;
342 int count;
344 register char *f = from;
345 register char *t = to;
346 register int i = count;
348 while (i-- > 0)
349 *t++ = *f++;
352 #else /* __cplusplus */
354 /* This is the most reliable way to avoid incompatibilities
355 in available built-in functions on various systems. */
356 static void
357 __zz_bcopy (char *from, char *to, int count)
359 register char *f = from;
360 register char *t = to;
361 register int i = count;
363 while (i-- > 0)
364 *t++ = *f++;
367 #endif
368 #endif
370 #line 184 "/usr/local/lib/bison.simple"
372 zzparse()
374 register int zzstate;
375 register int zzn;
376 register short *zzssp;
377 register YYSTYPE *zzvsp;
378 int zzerrstatus; /* number of tokens to shift before error messages enabled */
379 int zzchar1 = 0; /* lookahead token as an internal (translated) token number */
381 short zzssa[YYINITDEPTH]; /* the state stack */
382 YYSTYPE zzvsa[YYINITDEPTH]; /* the semantic value stack */
384 short *zzss = zzssa; /* refer to the stacks thru separate pointers */
385 YYSTYPE *zzvs = zzvsa; /* to allow zzoverflow to reallocate them elsewhere */
387 #ifdef YYLSP_NEEDED
388 YYLTYPE zzlsa[YYINITDEPTH]; /* the location stack */
389 YYLTYPE *zzls = zzlsa;
390 YYLTYPE *zzlsp;
392 #define YYPOPSTACK (zzvsp--, zzssp--, zzlsp--)
393 #else
394 #define YYPOPSTACK (zzvsp--, zzssp--)
395 #endif
397 int zzstacksize = YYINITDEPTH;
399 #ifdef YYPURE
400 int zzchar;
401 YYSTYPE zzlval;
402 int zznerrs;
403 #ifdef YYLSP_NEEDED
404 YYLTYPE zzlloc;
405 #endif
406 #endif
408 YYSTYPE zzval; /* the variable used to return */
409 /* semantic values from the action */
410 /* routines */
412 int zzlen;
414 #if YYDEBUG != 0
415 if (zzdebug)
416 fprintf(stderr, "Starting parse\n");
417 #endif
419 zzstate = 0;
420 zzerrstatus = 0;
421 zznerrs = 0;
422 zzchar = YYEMPTY; /* Cause a token to be read. */
424 /* Initialize stack pointers.
425 Waste one element of value and location stack
426 so that they stay on the same level as the state stack.
427 The wasted elements are never initialized. */
429 zzssp = zzss - 1;
430 zzvsp = zzvs;
431 #ifdef YYLSP_NEEDED
432 zzlsp = zzls;
433 #endif
435 /* Push a new state, which is found in zzstate . */
436 /* In all cases, when you get here, the value and location stacks
437 have just been pushed. so pushing a state here evens the stacks. */
438 zznewstate:
440 *++zzssp = zzstate;
442 if (zzssp >= zzss + zzstacksize - 1)
444 /* Give user a chance to reallocate the stack */
445 /* Use copies of these so that the &'s don't force the real ones into memory. */
446 YYSTYPE *zzvs1 = zzvs;
447 short *zzss1 = zzss;
448 #ifdef YYLSP_NEEDED
449 YYLTYPE *zzls1 = zzls;
450 #endif
452 /* Get the current used size of the three stacks, in elements. */
453 int size = zzssp - zzss + 1;
455 #ifdef zzoverflow
456 /* Each stack pointer address is followed by the size of
457 the data in use in that stack, in bytes. */
458 #ifdef YYLSP_NEEDED
459 /* This used to be a conditional around just the two extra args,
460 but that might be undefined if zzoverflow is a macro. */
461 zzoverflow("parser stack overflow",
462 &zzss1, size * sizeof (*zzssp),
463 &zzvs1, size * sizeof (*zzvsp),
464 &zzls1, size * sizeof (*zzlsp),
465 &zzstacksize);
466 #else
467 zzoverflow("parser stack overflow",
468 &zzss1, size * sizeof (*zzssp),
469 &zzvs1, size * sizeof (*zzvsp),
470 &zzstacksize);
471 #endif
473 zzss = zzss1; zzvs = zzvs1;
474 #ifdef YYLSP_NEEDED
475 zzls = zzls1;
476 #endif
477 #else /* no zzoverflow */
478 /* Extend the stack our own way. */
479 if (zzstacksize >= YYMAXDEPTH)
481 zzerror("parser stack overflow");
482 return 2;
484 zzstacksize *= 2;
485 if (zzstacksize > YYMAXDEPTH)
486 zzstacksize = YYMAXDEPTH;
487 zzss = (short *) alloca (zzstacksize * sizeof (*zzssp));
488 __zz_bcopy ((char *)zzss1, (char *)zzss, size * sizeof (*zzssp));
489 zzvs = (YYSTYPE *) alloca (zzstacksize * sizeof (*zzvsp));
490 __zz_bcopy ((char *)zzvs1, (char *)zzvs, size * sizeof (*zzvsp));
491 #ifdef YYLSP_NEEDED
492 zzls = (YYLTYPE *) alloca (zzstacksize * sizeof (*zzlsp));
493 __zz_bcopy ((char *)zzls1, (char *)zzls, size * sizeof (*zzlsp));
494 #endif
495 #endif /* no zzoverflow */
497 zzssp = zzss + size - 1;
498 zzvsp = zzvs + size - 1;
499 #ifdef YYLSP_NEEDED
500 zzlsp = zzls + size - 1;
501 #endif
503 #if YYDEBUG != 0
504 if (zzdebug)
505 fprintf(stderr, "Stack size increased to %d\n", zzstacksize);
506 #endif
508 if (zzssp >= zzss + zzstacksize - 1)
509 YYABORT;
512 #if YYDEBUG != 0
513 if (zzdebug)
514 fprintf(stderr, "Entering state %d\n", zzstate);
515 #endif
517 goto zzbackup;
518 zzbackup:
520 /* Do appropriate processing given the current state. */
521 /* Read a lookahead token if we need one and don't already have one. */
522 /* zzresume: */
524 /* First try to decide what to do without reference to lookahead token. */
526 zzn = zzpact[zzstate];
527 if (zzn == YYFLAG)
528 goto zzdefault;
530 /* Not known => get a lookahead token if don't already have one. */
532 /* zzchar is either YYEMPTY or YYEOF
533 or a valid token in external form. */
535 if (zzchar == YYEMPTY)
537 #if YYDEBUG != 0
538 if (zzdebug)
539 fprintf(stderr, "Reading a token: ");
540 #endif
541 zzchar = YYLEX;
544 /* Convert token to internal form (in zzchar1) for indexing tables with */
546 if (zzchar <= 0) /* This means end of input. */
548 zzchar1 = 0;
549 zzchar = YYEOF; /* Don't call YYLEX any more */
551 #if YYDEBUG != 0
552 if (zzdebug)
553 fprintf(stderr, "Now at end of input.\n");
554 #endif
556 else
558 zzchar1 = YYTRANSLATE(zzchar);
560 #if YYDEBUG != 0
561 if (zzdebug)
563 fprintf (stderr, "Next token is %d (%s", zzchar, zztname[zzchar1]);
564 /* Give the individual parser a way to print the precise meaning
565 of a token, for further debugging info. */
566 #ifdef YYPRINT
567 YYPRINT (stderr, zzchar, zzlval);
568 #endif
569 fprintf (stderr, ")\n");
571 #endif
574 zzn += zzchar1;
575 if (zzn < 0 || zzn > YYLAST || zzcheck[zzn] != zzchar1)
576 goto zzdefault;
578 zzn = zztable[zzn];
580 /* zzn is what to do for this token type in this state.
581 Negative => reduce, -zzn is rule number.
582 Positive => shift, zzn is new state.
583 New state is final state => don't bother to shift,
584 just return success.
585 0, or most negative number => error. */
587 if (zzn < 0)
589 if (zzn == YYFLAG)
590 goto zzerrlab;
591 zzn = -zzn;
592 goto zzreduce;
594 else if (zzn == 0)
595 goto zzerrlab;
597 if (zzn == YYFINAL)
598 YYACCEPT;
600 /* Shift the lookahead token. */
602 #if YYDEBUG != 0
603 if (zzdebug)
604 fprintf(stderr, "Shifting token %d (%s), ", zzchar, zztname[zzchar1]);
605 #endif
607 /* Discard the token being shifted unless it is eof. */
608 if (zzchar != YYEOF)
609 zzchar = YYEMPTY;
611 *++zzvsp = zzlval;
612 #ifdef YYLSP_NEEDED
613 *++zzlsp = zzlloc;
614 #endif
616 /* count tokens shifted since error; after three, turn off error status. */
617 if (zzerrstatus) zzerrstatus--;
619 zzstate = zzn;
620 goto zznewstate;
622 /* Do the default action for the current state. */
623 zzdefault:
625 zzn = zzdefact[zzstate];
626 if (zzn == 0)
627 goto zzerrlab;
629 /* Do a reduction. zzn is the number of a rule to reduce with. */
630 zzreduce:
631 zzlen = zzr2[zzn];
632 if (zzlen > 0)
633 zzval = zzvsp[1-zzlen]; /* implement default value of the action */
635 #if YYDEBUG != 0
636 if (zzdebug)
638 int i;
640 fprintf (stderr, "Reducing via rule %d (line %d), ",
641 zzn, zzrline[zzn]);
643 /* Print the symbols being reduced, and their result. */
644 for (i = zzprhs[zzn]; zzrhs[i] > 0; i++)
645 fprintf (stderr, "%s ", zztname[zzrhs[i]]);
646 fprintf (stderr, " -> %s\n", zztname[zzr1[zzn]]);
648 #endif
651 switch (zzn) {
653 case 1:
654 #line 84 "./posixtm.y"
656 if (zzvsp[-5] >= 1 && zzvsp[-5] <= 12)
657 t.tm_mon = zzvsp[-5] - 1;
658 else {
659 YYABORT;
661 if (zzvsp[-4] >= 1 && zzvsp[-4] <= 31)
662 t.tm_mday = zzvsp[-4];
663 else {
664 YYABORT;
666 if (zzvsp[-3] >= 0 && zzvsp[-3] <= 23)
667 t.tm_hour = zzvsp[-3];
668 else {
669 YYABORT;
671 if (zzvsp[-2] >= 0 && zzvsp[-2] <= 59)
672 t.tm_min = zzvsp[-2];
673 else {
674 YYABORT;
677 break;}
678 case 2:
679 #line 107 "./posixtm.y"
681 t.tm_year = zzvsp[0];
682 /* Deduce the century based on the year.
683 See POSIX.2 section 4.63.3. */
684 if (zzvsp[0] <= 68)
685 t.tm_year += 100;
687 break;}
688 case 3:
689 #line 114 "./posixtm.y"
691 t.tm_year = zzvsp[-1] * 100 + zzvsp[0];
692 if (t.tm_year < 1900) {
693 YYABORT;
694 } else
695 t.tm_year -= 1900;
697 break;}
698 case 4:
699 #line 121 "./posixtm.y"
701 time_t now;
702 struct tm *tmp;
704 /* Use current year. */
705 time (&now);
706 tmp = localtime (&now);
707 t.tm_year = tmp->tm_year;
709 break;}
710 case 5:
711 #line 132 "./posixtm.y"
713 t.tm_sec = 0;
715 break;}
716 case 6:
717 #line 135 "./posixtm.y"
719 if (zzvsp[0] >= 0 && zzvsp[0] <= 61)
720 t.tm_sec = zzvsp[0];
721 else {
722 YYABORT;
725 break;}
726 case 7:
727 #line 144 "./posixtm.y"
729 zzval = zzvsp[-1] * 10 + zzvsp[0];
731 break;}
733 /* the action file gets copied in in place of this dollarsign */
734 #line 465 "/usr/local/lib/bison.simple"
736 zzvsp -= zzlen;
737 zzssp -= zzlen;
738 #ifdef YYLSP_NEEDED
739 zzlsp -= zzlen;
740 #endif
742 #if YYDEBUG != 0
743 if (zzdebug)
745 short *ssp1 = zzss - 1;
746 fprintf (stderr, "state stack now");
747 while (ssp1 != zzssp)
748 fprintf (stderr, " %d", *++ssp1);
749 fprintf (stderr, "\n");
751 #endif
753 *++zzvsp = zzval;
755 #ifdef YYLSP_NEEDED
756 zzlsp++;
757 if (zzlen == 0)
759 zzlsp->first_line = zzlloc.first_line;
760 zzlsp->first_column = zzlloc.first_column;
761 zzlsp->last_line = (zzlsp-1)->last_line;
762 zzlsp->last_column = (zzlsp-1)->last_column;
763 zzlsp->text = 0;
765 else
767 zzlsp->last_line = (zzlsp+zzlen-1)->last_line;
768 zzlsp->last_column = (zzlsp+zzlen-1)->last_column;
770 #endif
772 /* Now "shift" the result of the reduction.
773 Determine what state that goes to,
774 based on the state we popped back to
775 and the rule number reduced by. */
777 zzn = zzr1[zzn];
779 zzstate = zzpgoto[zzn - YYNTBASE] + *zzssp;
780 if (zzstate >= 0 && zzstate <= YYLAST && zzcheck[zzstate] == *zzssp)
781 zzstate = zztable[zzstate];
782 else
783 zzstate = zzdefgoto[zzn - YYNTBASE];
785 goto zznewstate;
787 zzerrlab: /* here on detecting error */
789 if (! zzerrstatus)
790 /* If not already recovering from an error, report this error. */
792 ++zznerrs;
794 #ifdef YYERROR_VERBOSE
795 zzn = zzpact[zzstate];
797 if (zzn > YYFLAG && zzn < YYLAST)
799 int size = 0;
800 char *msg;
801 int x, count;
803 count = 0;
804 /* Start X at -zzn if nec to avoid negative indexes in zzcheck. */
805 for (x = (zzn < 0 ? -zzn : 0);
806 x < (sizeof(zztname) / sizeof(char *)); x++)
807 if (zzcheck[x + zzn] == x)
808 size += strlen(zztname[x]) + 15, count++;
809 msg = (char *) malloc(size + 15);
810 if (msg != 0)
812 strcpy(msg, "parse error");
814 if (count < 5)
816 count = 0;
817 for (x = (zzn < 0 ? -zzn : 0);
818 x < (sizeof(zztname) / sizeof(char *)); x++)
819 if (zzcheck[x + zzn] == x)
821 strcat(msg, count == 0 ? ", expecting `" : " or `");
822 strcat(msg, zztname[x]);
823 strcat(msg, "'");
824 count++;
827 zzerror(msg);
828 free(msg);
830 else
831 zzerror ("parse error; also virtual memory exceeded");
833 else
834 #endif /* YYERROR_VERBOSE */
835 zzerror("parse error");
838 goto zzerrlab1;
839 zzerrlab1: /* here on error raised explicitly by an action */
841 if (zzerrstatus == 3)
843 /* if just tried and failed to reuse lookahead token after an error, discard it. */
845 /* return failure if at end of input */
846 if (zzchar == YYEOF)
847 YYABORT;
849 #if YYDEBUG != 0
850 if (zzdebug)
851 fprintf(stderr, "Discarding token %d (%s).\n", zzchar, zztname[zzchar1]);
852 #endif
854 zzchar = YYEMPTY;
857 /* Else will try to reuse lookahead token
858 after shifting the error token. */
860 zzerrstatus = 3; /* Each real token shifted decrements this */
862 goto zzerrhandle;
864 zzerrdefault: /* current state does not do anything special for the error token. */
866 #if 0
867 /* This is wrong; only states that explicitly want error tokens
868 should shift them. */
869 zzn = zzdefact[zzstate]; /* If its default is to accept any token, ok. Otherwise pop it.*/
870 if (zzn) goto zzdefault;
871 #endif
873 zzerrpop: /* pop the current state because it cannot handle the error token */
875 if (zzssp == zzss) YYABORT;
876 zzvsp--;
877 zzstate = *--zzssp;
878 #ifdef YYLSP_NEEDED
879 zzlsp--;
880 #endif
882 #if YYDEBUG != 0
883 if (zzdebug)
885 short *ssp1 = zzss - 1;
886 fprintf (stderr, "Error: state stack now");
887 while (ssp1 != zzssp)
888 fprintf (stderr, " %d", *++ssp1);
889 fprintf (stderr, "\n");
891 #endif
893 zzerrhandle:
895 zzn = zzpact[zzstate];
896 if (zzn == YYFLAG)
897 goto zzerrdefault;
899 zzn += YYTERROR;
900 if (zzn < 0 || zzn > YYLAST || zzcheck[zzn] != YYTERROR)
901 goto zzerrdefault;
903 zzn = zztable[zzn];
904 if (zzn < 0)
906 if (zzn == YYFLAG)
907 goto zzerrpop;
908 zzn = -zzn;
909 goto zzreduce;
911 else if (zzn == 0)
912 goto zzerrpop;
914 if (zzn == YYFINAL)
915 YYACCEPT;
917 #if YYDEBUG != 0
918 if (zzdebug)
919 fprintf(stderr, "Shifting error token, ");
920 #endif
922 *++zzvsp = zzlval;
923 #ifdef YYLSP_NEEDED
924 *++zzlsp = zzlloc;
925 #endif
927 zzstate = zzn;
928 goto zznewstate;
930 #line 148 "./posixtm.y"
932 static int
933 zzlex ()
935 char ch = *curpos++;
937 if (ch >= '0' && ch <= '9')
939 zzlval = ch - '0';
940 return DIGIT;
942 else if (ch == '.' || ch == 0)
943 return ch;
944 else
945 return '?'; /* Cause an error. */
948 static int
949 zzerror ()
951 return 0;
954 /* Parse a POSIX-style date and return it, or (time_t)-1 for an error. */
956 time_t
957 posixtime (s)
958 char *s;
960 curpos = s;
961 /* Let mktime decide whether it is daylight savings time. */
962 t.tm_isdst = -1;
963 if (zzparse ())
964 return (time_t)-1;
965 else
966 return mktime (&t);
969 /* Parse a POSIX-style date and return it, or NULL for an error. */
971 struct tm *
972 posixtm (s)
973 char *s;
975 if (posixtime (s) == -1)
976 return NULL;
977 return &t;