1 /* A Bison parser, made by GNU Bison 1.875. */
3 /* Skeleton parser for Yacc-like parsing with Bison,
4 Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002 Free Software Foundation, Inc.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
21 /* As a special exception, when this file is copied by Bison into a
22 Bison output file, you may use that output file without restriction.
23 This special exception was added by the Free Software Foundation
24 in version 1.24 of Bison. */
26 /* Written by Richard Stallman by simplifying the original so called
27 ``semantic'' parser. */
29 /* All symbols defined below should begin with yy or YY, to avoid
30 infringing on user name space. This should be done even for local
31 variables, as they might otherwise be expanded by user macros.
32 There are some unavoidable exceptions within include files to
33 define necessary library symbols; they are noted "INFRINGES ON
34 USER NAME SPACE" below. */
36 /* Identify Bison output. */
40 #define YYSKELETON_NAME "yacc.c"
45 /* Using locations. */
46 #define YYLSP_NEEDED 0
53 /* Put the tokens into the symbol table, so that GDB and other debuggers
71 #define tMONTH_UNIT 262
80 /* Copy the first part of user declarations. */
85 ** Originally written by Steven M. Bellovin <smb@research.att.com> while
86 ** at the University of North Carolina at Chapel Hill. Later tweaked by
87 ** a couple of people on Usenet. Completely overhauled by Rich $alz
88 ** <rsalz@osf.org> and Jim Berets <jberets@bbn.com> in August, 1990.
89 ** Further revised (removed obsolete constructs and cleaned up timezone
90 ** names) in August, 1991, by Rich. Paul Eggert <eggert@twinsun.com>
91 ** helped in September, 1992. Art Cancro <ajc@uncensored.citadel.org> cleaned
92 ** it up for ANSI C in December, 1999.
94 ** This grammar has six shift/reduce conflicts.
96 ** This code is in the public domain and has no copyright.
98 /* SUPPRESS 530 *//* Empty body for statement */
99 /* SUPPRESS 593 on yyerrlab *//* Label was not used */
100 /* SUPPRESS 593 on yynewstate *//* Label was not used */
101 /* SUPPRESS 595 on yypvt *//* Automatic variable may be used before set */
107 #include <sys/types.h>
110 #if TIME_WITH_SYS_TIME
111 # include <sys/time.h>
115 # include <sys/time.h>
122 # if !STDC_HEADERS && HAVE_MEMORY_H
128 # include <strings.h>
131 #include "parsedate.h"
135 #define yyparse date_parse
136 #define yylex date_lex
137 #define yyerror date_error
140 /* See the LeapYears table in Convert. */
142 #define END_OF_TIME 2038
143 /* Constants for general time calculations. */
145 #define SECSPERDAY (24L * 60L * 60L)
146 /* Readability for TABLE stuff. */
147 #define HOUR(x) (x * 60)
151 #define IS7BIT(x) ((unsigned int)(x) < 0200)
153 #define SIZEOF(array) ((int)(sizeof array / sizeof array[0]))
154 #define ENDOF(array) (&array[SIZEOF(array)])
158 ** An entry in the lexical lookup table.
160 typedef struct _TABLE {
167 ** Daylight-savings mode: on, off, or not yet known.
169 typedef enum _DSTMODE {
170 DSTon, DSToff, DSTmaybe
174 ** Meridian: am, pm, or 24-hour style.
176 typedef enum _MERIDIAN {
182 ** Global variables. We could get rid of most of them by using a yacc
183 ** union, but this is more efficient. (This routine predates the
184 ** yacc %union construct.)
186 static char *yyInput;
187 static DSTMODE yyDSTmode;
188 static int yyHaveDate;
189 static int yyHaveRel;
190 static int yyHaveTime;
191 static time_t yyTimezone;
193 static time_t yyHour;
194 static time_t yyMinutes;
195 static time_t yyMonth;
196 static time_t yySeconds;
197 static time_t yyYear;
198 static MERIDIAN yyMeridian;
199 static time_t yyRelMonth;
200 static time_t yyRelSeconds;
203 static void date_error(char *);
206 /* Enabling traces. */
211 /* Enabling verbose error messages. */
212 #ifdef YYERROR_VERBOSE
213 # undef YYERROR_VERBOSE
214 # define YYERROR_VERBOSE 1
216 # define YYERROR_VERBOSE 0
219 #if ! defined (YYSTYPE) && ! defined (YYSTYPE_IS_DECLARED)
220 #line 125 "parsedate.y"
221 typedef union YYSTYPE {
223 enum _MERIDIAN Meridian;
225 /* Line 191 of yacc.c. */
227 # define yystype YYSTYPE /* obsolescent; will be withdrawn */
228 # define YYSTYPE_IS_DECLARED 1
229 # define YYSTYPE_IS_TRIVIAL 1
234 /* Copy the second part of user declarations. */
237 /* Line 214 of yacc.c. */
240 #if ! defined (yyoverflow) || YYERROR_VERBOSE
242 /* The parser invokes alloca or malloc; define the necessary symbols. */
244 # if YYSTACK_USE_ALLOCA
245 # define YYSTACK_ALLOC alloca
247 # ifndef YYSTACK_USE_ALLOCA
248 # if defined (alloca) || defined (_ALLOCA_H)
249 # define YYSTACK_ALLOC alloca
252 # define YYSTACK_ALLOC __builtin_alloca
258 # ifdef YYSTACK_ALLOC
259 /* Pacify GCC's `empty if-body' warning. */
260 # define YYSTACK_FREE(Ptr) do { /* empty */; } while (0)
262 # if defined (__STDC__) || defined (__cplusplus)
263 # include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
264 # define YYSIZE_T size_t
266 # define YYSTACK_ALLOC malloc
267 # define YYSTACK_FREE free
269 #endif /* ! defined (yyoverflow) || YYERROR_VERBOSE */
272 #if (! defined (yyoverflow) \
273 && (! defined (__cplusplus) \
274 || (YYSTYPE_IS_TRIVIAL)))
276 /* A type that is properly aligned for any stack member. */
283 /* The size of the maximum gap between one aligned stack and the next. */
284 # define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1)
286 /* The size of an array large to enough to hold all stacks, each with
288 # define YYSTACK_BYTES(N) \
289 ((N) * (sizeof (short) + sizeof (YYSTYPE)) \
290 + YYSTACK_GAP_MAXIMUM)
292 /* Copy COUNT objects from FROM to TO. The source and destination do
296 # define YYCOPY(To, From, Count) \
297 __builtin_memcpy (To, From, (Count) * sizeof (*(From)))
299 # define YYCOPY(To, From, Count) \
302 register YYSIZE_T yyi; \
303 for (yyi = 0; yyi < (Count); yyi++) \
304 (To)[yyi] = (From)[yyi]; \
310 /* Relocate STACK from its old location to the new one. The
311 local variables YYSIZE and YYSTACKSIZE give the old and new number of
312 elements in the stack, and YYPTR gives the new location of the
313 stack. Advance YYPTR to a properly aligned location for the next
315 # define YYSTACK_RELOCATE(Stack) \
318 YYSIZE_T yynewbytes; \
319 YYCOPY (&yyptr->Stack, Stack, yysize); \
320 Stack = &yyptr->Stack; \
321 yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \
322 yyptr += yynewbytes / sizeof (*yyptr); \
328 #if defined (__STDC__) || defined (__cplusplus)
329 typedef signed char yysigned_char;
331 typedef short yysigned_char;
334 /* YYFINAL -- State number of the termination state. */
336 /* YYLAST -- Last index in YYTABLE. */
339 /* YYNTOKENS -- Number of terminals. */
341 /* YYNNTS -- Number of nonterminals. */
343 /* YYNRULES -- Number of rules. */
345 /* YYNRULES -- Number of states. */
348 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
350 #define YYMAXUTOK 266
352 #define YYTRANSLATE(YYX) \
353 ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
355 /* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */
356 static const unsigned char yytranslate[] =
358 0, 2, 2, 2, 2, 2, 2, 2, 2, 2,
359 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
360 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
361 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
362 2, 2, 2, 2, 14, 2, 2, 13, 2, 2,
363 2, 2, 2, 2, 2, 2, 2, 2, 12, 2,
364 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
365 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
366 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
367 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
368 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
369 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
370 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
371 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
372 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
373 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
374 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
375 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
376 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
377 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
378 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
379 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
380 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
381 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
382 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
383 2, 2, 2, 2, 2, 2, 1, 2, 3, 4,
384 5, 6, 7, 8, 9, 10, 11
388 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
390 static const unsigned char yyprhs[] =
392 0, 0, 3, 4, 7, 9, 12, 14, 16, 19,
393 24, 29, 36, 43, 45, 47, 50, 52, 54, 58,
394 64, 67, 72, 75, 79, 85, 88, 91, 94, 97,
398 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
399 static const yysigned_char yyrhs[] =
401 16, 0, -1, -1, 16, 17, -1, 18, -1, 18,
402 19, -1, 21, -1, 22, -1, 10, 23, -1, 10,
403 12, 10, 23, -1, 10, 12, 10, 20, -1, 10,
404 12, 10, 12, 10, 23, -1, 10, 12, 10, 12,
405 10, 20, -1, 11, -1, 4, -1, 11, 20, -1,
406 20, -1, 9, -1, 10, 13, 10, -1, 10, 13,
407 10, 13, 10, -1, 6, 10, -1, 6, 10, 14,
408 10, -1, 10, 6, -1, 10, 6, 10, -1, 3,
409 14, 10, 6, 10, -1, 9, 8, -1, 10, 8,
410 -1, 9, 7, -1, 10, 7, -1, -1, 5, -1
413 /* YYRLINE[YYN] -- source line where rule number YYN was defined. */
414 static const unsigned short yyrline[] =
416 0, 139, 139, 140, 143, 152, 156, 159, 164, 176,
417 182, 189, 195, 205, 209, 213, 221, 227, 248, 252,
418 264, 268, 273, 277, 282, 289, 292, 295, 298, 303,
423 #if YYDEBUG || YYERROR_VERBOSE
424 /* YYTNME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
425 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
426 static const char *const yytname[] =
428 "$end", "error", "$undefined", "tDAY", "tDAYZONE", "tMERIDIAN", "tMONTH",
429 "tMONTH_UNIT", "tSEC_UNIT", "tSNUMBER", "tUNUMBER", "tZONE", "':'",
430 "'/'", "','", "$accept", "spec", "item", "time", "zone", "numzone",
431 "date", "rel", "o_merid", 0
436 /* YYTOKNUM[YYLEX-NUM] -- Internal token number corresponding to
438 static const unsigned short yytoknum[] =
440 0, 256, 257, 258, 259, 260, 261, 262, 263, 264,
445 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
446 static const unsigned char yyr1[] =
448 0, 15, 16, 16, 17, 17, 17, 17, 18, 18,
449 18, 18, 18, 19, 19, 19, 19, 20, 21, 21,
450 21, 21, 21, 21, 21, 22, 22, 22, 22, 23,
454 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
455 static const unsigned char yyr2[] =
457 0, 2, 0, 2, 1, 2, 1, 1, 2, 4,
458 4, 6, 6, 1, 1, 2, 1, 1, 3, 5,
459 2, 4, 2, 3, 5, 2, 2, 2, 2, 0,
463 /* YYDEFACT[STATE-NAME] -- Default rule to reduce with in state
464 STATE-NUM when YYTABLE doesn't specify something else to do. Zero
465 means the default is an error. */
466 static const unsigned char yydefact[] =
468 2, 0, 1, 0, 0, 0, 29, 3, 4, 6,
469 7, 0, 20, 27, 25, 30, 22, 28, 26, 0,
470 0, 8, 14, 17, 13, 5, 16, 0, 0, 23,
471 29, 18, 15, 0, 21, 0, 10, 9, 0, 24,
475 /* YYDEFGOTO[NTERM-NUM]. */
476 static const yysigned_char yydefgoto[] =
478 -1, 1, 7, 8, 25, 26, 9, 10, 21
481 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
483 #define YYPACT_NINF -29
484 static const yysigned_char yypact[] =
486 -29, 1, -29, -11, 11, 20, 12, -29, 4, -29,
487 -29, 13, 16, -29, -29, -29, 21, -29, -29, 22,
488 23, -29, -29, -29, 5, -29, -29, 28, 25, -29,
489 17, 24, -29, 26, -29, 29, -29, -29, 30, -29,
493 /* YYPGOTO[NTERM-NUM]. */
494 static const yysigned_char yypgoto[] =
496 -29, -29, -29, -29, -29, -24, -29, -29, -28
499 /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
500 positive, shift that token. If negative, reduce the rule which
501 number is the opposite. If zero, do what YYDEFACT says.
502 If YYTABLE_NINF, syntax error. */
503 #define YYTABLE_NINF -1
504 static const unsigned char yytable[] =
506 32, 2, 37, 11, 3, 15, 36, 4, 22, 23,
507 5, 6, 43, 23, 23, 24, 42, 15, 16, 17,
508 18, 12, 15, 27, 19, 20, 23, 13, 14, 35,
509 28, 29, 30, 31, 33, 34, 39, 38, 0, 40,
513 static const yysigned_char yycheck[] =
515 24, 0, 30, 14, 3, 5, 30, 6, 4, 9,
516 9, 10, 40, 9, 9, 11, 40, 5, 6, 7,
517 8, 10, 5, 10, 12, 13, 9, 7, 8, 12,
518 14, 10, 10, 10, 6, 10, 10, 13, -1, 10,
522 /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
523 symbol of state STATE-NUM. */
524 static const unsigned char yystos[] =
526 0, 16, 0, 3, 6, 9, 10, 17, 18, 21,
527 22, 14, 10, 7, 8, 5, 6, 7, 8, 12,
528 13, 23, 4, 9, 11, 19, 20, 10, 14, 10,
529 10, 10, 20, 6, 10, 12, 20, 23, 13, 10,
533 #if ! defined (YYSIZE_T) && defined (__SIZE_TYPE__)
534 # define YYSIZE_T __SIZE_TYPE__
536 #if ! defined (YYSIZE_T) && defined (size_t)
537 # define YYSIZE_T size_t
539 #if ! defined (YYSIZE_T)
540 # if defined (__STDC__) || defined (__cplusplus)
541 # include <stddef.h> /* INFRINGES ON USER NAME SPACE */
542 # define YYSIZE_T size_t
545 #if ! defined (YYSIZE_T)
546 # define YYSIZE_T unsigned int
549 #define yyerrok (yyerrstatus = 0)
550 #define yyclearin (yychar = YYEMPTY)
554 #define YYACCEPT goto yyacceptlab
555 #define YYABORT goto yyabortlab
556 #define YYERROR goto yyerrlab1
559 /* Like YYERROR except do call yyerror. This remains here temporarily
560 to ease the transition to the new meaning of YYERROR, for GCC.
561 Once GCC version 2 has supplanted version 1, this can go. */
563 #define YYFAIL goto yyerrlab
565 #define YYRECOVERING() (!!yyerrstatus)
567 #define YYBACKUP(Token, Value) \
569 if (yychar == YYEMPTY && yylen == 1) \
573 yytoken = YYTRANSLATE (yychar); \
579 yyerror ("syntax error: cannot back up");\
585 #define YYERRCODE 256
587 /* YYLLOC_DEFAULT -- Compute the default location (before the actions
590 #ifndef YYLLOC_DEFAULT
591 # define YYLLOC_DEFAULT(Current, Rhs, N) \
592 Current.first_line = Rhs[1].first_line; \
593 Current.first_column = Rhs[1].first_column; \
594 Current.last_line = Rhs[N].last_line; \
595 Current.last_column = Rhs[N].last_column;
598 /* YYLEX -- calling `yylex' with the right arguments. */
601 # define YYLEX yylex (YYLEX_PARAM)
603 # define YYLEX yylex ()
606 /* Enable debugging if requested. */
610 # include <stdio.h> /* INFRINGES ON USER NAME SPACE */
611 # define YYFPRINTF fprintf
614 # define YYDPRINTF(Args) \
620 # define YYDSYMPRINT(Args) \
626 # define YYDSYMPRINTF(Title, Token, Value, Location) \
630 YYFPRINTF (stderr, "%s ", Title); \
631 yysymprint (stderr, \
633 YYFPRINTF (stderr, "\n"); \
637 /*------------------------------------------------------------------.
638 | yy_stack_print -- Print the state stack from its BOTTOM up to its |
640 `------------------------------------------------------------------*/
642 #if defined (__STDC__) || defined (__cplusplus)
644 yy_stack_print (short *bottom, short *top)
647 yy_stack_print (bottom, top)
652 YYFPRINTF (stderr, "Stack now");
653 for (/* Nothing. */; bottom <= top; ++bottom)
654 YYFPRINTF (stderr, " %d", *bottom);
655 YYFPRINTF (stderr, "\n");
658 # define YY_STACK_PRINT(Bottom, Top) \
661 yy_stack_print ((Bottom), (Top)); \
665 /*------------------------------------------------.
666 | Report that the YYRULE is going to be reduced. |
667 `------------------------------------------------*/
669 #if defined (__STDC__) || defined (__cplusplus)
671 yy_reduce_print (int yyrule)
674 yy_reduce_print (yyrule)
679 unsigned int yylineno = yyrline[yyrule];
680 YYFPRINTF (stderr, "Reducing stack by rule %d (line %u), ",
681 yyrule - 1, yylineno);
682 /* Print the symbols being reduced, and their result. */
683 for (yyi = yyprhs[yyrule]; 0 <= yyrhs[yyi]; yyi++)
684 YYFPRINTF (stderr, "%s ", yytname [yyrhs[yyi]]);
685 YYFPRINTF (stderr, "-> %s\n", yytname [yyr1[yyrule]]);
688 # define YY_REDUCE_PRINT(Rule) \
691 yy_reduce_print (Rule); \
694 /* Nonzero means print parse trace. It is left uninitialized so that
695 multiple parsers can coexist. */
698 # define YYDPRINTF(Args)
699 # define YYDSYMPRINT(Args)
700 # define YYDSYMPRINTF(Title, Token, Value, Location)
701 # define YY_STACK_PRINT(Bottom, Top)
702 # define YY_REDUCE_PRINT(Rule)
703 #endif /* !YYDEBUG */
706 /* YYINITDEPTH -- initial size of the parser's stacks. */
708 # define YYINITDEPTH 200
711 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
712 if the built-in stack extension method is used).
714 Do not make this value too large; the results are undefined if
715 SIZE_MAX < YYSTACK_BYTES (YYMAXDEPTH)
716 evaluated with infinite-precision integer arithmetic. */
723 # define YYMAXDEPTH 10000
731 # if defined (__GLIBC__) && defined (_STRING_H)
732 # define yystrlen strlen
734 /* Return the length of YYSTR. */
736 # if defined (__STDC__) || defined (__cplusplus)
737 yystrlen (const char *yystr)
743 register const char *yys = yystr;
745 while (*yys++ != '\0')
748 return yys - yystr - 1;
754 # if defined (__GLIBC__) && defined (_STRING_H) && defined (_GNU_SOURCE)
755 # define yystpcpy stpcpy
757 /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
760 # if defined (__STDC__) || defined (__cplusplus)
761 yystpcpy (char *yydest, const char *yysrc)
763 yystpcpy (yydest, yysrc)
768 register char *yyd = yydest;
769 register const char *yys = yysrc;
771 while ((*yyd++ = *yys++) != '\0')
779 #endif /* !YYERROR_VERBOSE */
784 /*--------------------------------.
785 | Print this symbol on YYOUTPUT. |
786 `--------------------------------*/
788 #if defined (__STDC__) || defined (__cplusplus)
790 yysymprint (FILE *yyoutput, int yytype, YYSTYPE *yyvaluep)
793 yysymprint (yyoutput, yytype, yyvaluep)
799 /* Pacify ``unused variable'' warnings. */
802 if (yytype < YYNTOKENS)
804 YYFPRINTF (yyoutput, "token %s (", yytname[yytype]);
806 YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep);
810 YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]);
817 YYFPRINTF (yyoutput, ")");
820 #endif /* ! YYDEBUG */
821 /*-----------------------------------------------.
822 | Release the memory associated to this symbol. |
823 `-----------------------------------------------*/
825 #if defined (__STDC__) || defined (__cplusplus)
827 yydestruct (int yytype, YYSTYPE *yyvaluep)
830 yydestruct (yytype, yyvaluep)
835 /* Pacify ``unused variable'' warnings. */
847 /* Prevent warnings from -Wmissing-prototypes. */
850 # if defined (__STDC__) || defined (__cplusplus)
851 int yyparse (void *YYPARSE_PARAM);
855 #else /* ! YYPARSE_PARAM */
856 #if defined (__STDC__) || defined (__cplusplus)
861 #endif /* ! YYPARSE_PARAM */
865 /* The lookahead symbol. */
868 /* The semantic value of the lookahead symbol. */
871 /* Number of syntax errors so far. */
881 # if defined (__STDC__) || defined (__cplusplus)
882 int yyparse (void *YYPARSE_PARAM)
884 int yyparse (YYPARSE_PARAM)
887 #else /* ! YYPARSE_PARAM */
888 #if defined (__STDC__) || defined (__cplusplus)
899 register int yystate;
902 /* Number of tokens to shift before error messages enabled. */
904 /* Lookahead token as an internal (translated) token number. */
907 /* Three stacks and their tools:
908 `yyss': related to states,
909 `yyvs': related to semantic values,
910 `yyls': related to locations.
912 Refer to the stacks thru separate pointers, to allow yyoverflow
913 to reallocate them elsewhere. */
915 /* The state stack. */
916 short yyssa[YYINITDEPTH];
918 register short *yyssp;
920 /* The semantic value stack. */
921 YYSTYPE yyvsa[YYINITDEPTH];
922 YYSTYPE *yyvs = yyvsa;
923 register YYSTYPE *yyvsp;
927 #define YYPOPSTACK (yyvsp--, yyssp--)
929 YYSIZE_T yystacksize = YYINITDEPTH;
931 /* The variables used to return semantic value and location from the
936 /* When reducing, the number of symbols on the RHS of the reduced
940 YYDPRINTF ((stderr, "Starting parse\n"));
945 yychar = YYEMPTY; /* Cause a token to be read. */
947 /* Initialize stack pointers.
948 Waste one element of value and location stack
949 so that they stay on the same level as the state stack.
950 The wasted elements are never initialized. */
957 /*------------------------------------------------------------.
958 | yynewstate -- Push a new state, which is found in yystate. |
959 `------------------------------------------------------------*/
961 /* In all cases, when you get here, the value and location stacks
962 have just been pushed. so pushing a state here evens the stacks.
969 if (yyss + yystacksize - 1 <= yyssp)
971 /* Get the current used size of the three stacks, in elements. */
972 YYSIZE_T yysize = yyssp - yyss + 1;
976 /* Give user a chance to reallocate the stack. Use copies of
977 these so that the &'s don't force the real ones into
979 YYSTYPE *yyvs1 = yyvs;
983 /* Each stack pointer address is followed by the size of the
984 data in use in that stack, in bytes. This used to be a
985 conditional around just the two extra args, but that might
986 be undefined if yyoverflow is a macro. */
987 yyoverflow ("parser stack overflow",
988 &yyss1, yysize * sizeof (*yyssp),
989 &yyvs1, yysize * sizeof (*yyvsp),
996 #else /* no yyoverflow */
997 # ifndef YYSTACK_RELOCATE
1000 /* Extend the stack our own way. */
1001 if (YYMAXDEPTH <= yystacksize)
1004 if (YYMAXDEPTH < yystacksize)
1005 yystacksize = YYMAXDEPTH;
1008 short *yyss1 = yyss;
1009 union yyalloc *yyptr =
1010 (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
1013 YYSTACK_RELOCATE (yyss);
1014 YYSTACK_RELOCATE (yyvs);
1016 # undef YYSTACK_RELOCATE
1018 YYSTACK_FREE (yyss1);
1021 #endif /* no yyoverflow */
1023 yyssp = yyss + yysize - 1;
1024 yyvsp = yyvs + yysize - 1;
1027 YYDPRINTF ((stderr, "Stack size increased to %lu\n",
1028 (unsigned long int) yystacksize));
1030 if (yyss + yystacksize - 1 <= yyssp)
1034 YYDPRINTF ((stderr, "Entering state %d\n", yystate));
1043 /* Do appropriate processing given the current state. */
1044 /* Read a lookahead token if we need one and don't already have one. */
1047 /* First try to decide what to do without reference to lookahead token. */
1049 yyn = yypact[yystate];
1050 if (yyn == YYPACT_NINF)
1053 /* Not known => get a lookahead token if don't already have one. */
1055 /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol. */
1056 if (yychar == YYEMPTY)
1058 YYDPRINTF ((stderr, "Reading a token: "));
1062 if (yychar <= YYEOF)
1064 yychar = yytoken = YYEOF;
1065 YYDPRINTF ((stderr, "Now at end of input.\n"));
1069 yytoken = YYTRANSLATE (yychar);
1070 YYDSYMPRINTF ("Next token is", yytoken, &yylval, &yylloc);
1073 /* If the proper action on seeing token YYTOKEN is to reduce or to
1074 detect an error, take that action. */
1076 if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
1081 if (yyn == 0 || yyn == YYTABLE_NINF)
1090 /* Shift the lookahead token. */
1091 YYDPRINTF ((stderr, "Shifting token %s, ", yytname[yytoken]));
1093 /* Discard the token being shifted unless it is eof. */
1094 if (yychar != YYEOF)
1100 /* Count tokens shifted since error; after three, turn off error
1109 /*-----------------------------------------------------------.
1110 | yydefault -- do the default action for the current state. |
1111 `-----------------------------------------------------------*/
1113 yyn = yydefact[yystate];
1119 /*-----------------------------.
1120 | yyreduce -- Do a reduction. |
1121 `-----------------------------*/
1123 /* yyn is the number of a rule to reduce with. */
1126 /* If YYLEN is nonzero, implement the default value of the action:
1129 Otherwise, the following line sets YYVAL to garbage.
1130 This behavior is undocumented and Bison
1131 users should not rely upon it. Assigning to YYVAL
1132 unconditionally makes the parser a bit smaller, and it avoids a
1133 GCC warning that YYVAL may be used uninitialized. */
1134 yyval = yyvsp[1-yylen];
1137 YY_REDUCE_PRINT (yyn);
1141 #line 143 "parsedate.y"
1145 /* I am compulsive about lint natterings... */
1146 if (yyHaveTime == -1) {
1154 #line 152 "parsedate.y"
1157 yyTimezone = yyvsp[0].Number;
1162 #line 156 "parsedate.y"
1169 #line 159 "parsedate.y"
1176 #line 164 "parsedate.y"
1178 if (yyvsp[-1].Number < 100) {
1179 yyHour = yyvsp[-1].Number;
1183 yyHour = yyvsp[-1].Number / 100;
1184 yyMinutes = yyvsp[-1].Number % 100;
1187 yyMeridian = yyvsp[0].Meridian;
1192 #line 176 "parsedate.y"
1194 yyHour = yyvsp[-3].Number;
1195 yyMinutes = yyvsp[-1].Number;
1197 yyMeridian = yyvsp[0].Meridian;
1202 #line 182 "parsedate.y"
1204 yyHour = yyvsp[-3].Number;
1205 yyMinutes = yyvsp[-1].Number;
1206 yyTimezone = yyvsp[0].Number;
1213 #line 189 "parsedate.y"
1215 yyHour = yyvsp[-5].Number;
1216 yyMinutes = yyvsp[-3].Number;
1217 yySeconds = yyvsp[-1].Number;
1218 yyMeridian = yyvsp[0].Meridian;
1223 #line 195 "parsedate.y"
1225 yyHour = yyvsp[-5].Number;
1226 yyMinutes = yyvsp[-3].Number;
1227 yySeconds = yyvsp[-1].Number;
1228 yyTimezone = yyvsp[0].Number;
1235 #line 205 "parsedate.y"
1237 yyval.Number = yyvsp[0].Number;
1243 #line 209 "parsedate.y"
1245 yyval.Number = yyvsp[0].Number;
1251 #line 213 "parsedate.y"
1253 /* Only allow "GMT+300" and "GMT-0800" */
1254 if (yyvsp[-1].Number != 0) {
1257 yyval.Number = yyvsp[0].Number;
1263 #line 221 "parsedate.y"
1265 yyval.Number = yyvsp[0].Number;
1271 #line 227 "parsedate.y"
1275 /* Unix and GMT and numeric timezones -- a little confusing. */
1276 if (yyvsp[0].Number < 0) {
1277 /* Don't work with negative modulus. */
1278 yyvsp[0].Number = -yyvsp[0].Number;
1279 if (yyvsp[0].Number > 9999 || (i = yyvsp[0].Number % 100) >= 60) {
1282 yyval.Number = (yyvsp[0].Number / 100) * 60 + i;
1285 if (yyvsp[0].Number > 9999 || (i = yyvsp[0].Number % 100) >= 60) {
1288 yyval.Number = -((yyvsp[0].Number / 100) * 60 + i);
1294 #line 248 "parsedate.y"
1296 yyMonth = yyvsp[-2].Number;
1297 yyDay = yyvsp[0].Number;
1302 #line 252 "parsedate.y"
1304 if (yyvsp[-4].Number > 100) {
1305 yyYear = yyvsp[-4].Number;
1306 yyMonth = yyvsp[-2].Number;
1307 yyDay = yyvsp[0].Number;
1310 yyMonth = yyvsp[-4].Number;
1311 yyDay = yyvsp[-2].Number;
1312 yyYear = yyvsp[0].Number;
1318 #line 264 "parsedate.y"
1320 yyMonth = yyvsp[-1].Number;
1321 yyDay = yyvsp[0].Number;
1326 #line 268 "parsedate.y"
1328 yyMonth = yyvsp[-3].Number;
1329 yyDay = yyvsp[-2].Number;
1330 yyYear = yyvsp[0].Number;
1335 #line 273 "parsedate.y"
1337 yyDay = yyvsp[-1].Number;
1338 yyMonth = yyvsp[0].Number;
1343 #line 277 "parsedate.y"
1345 yyDay = yyvsp[-2].Number;
1346 yyMonth = yyvsp[-1].Number;
1347 yyYear = yyvsp[0].Number;
1352 #line 282 "parsedate.y"
1354 yyDay = yyvsp[-2].Number;
1355 yyMonth = yyvsp[-1].Number;
1356 yyYear = yyvsp[0].Number;
1361 #line 289 "parsedate.y"
1363 yyRelSeconds += yyvsp[-1].Number * yyvsp[0].Number;
1368 #line 292 "parsedate.y"
1370 yyRelSeconds += yyvsp[-1].Number * yyvsp[0].Number;
1375 #line 295 "parsedate.y"
1377 yyRelMonth += yyvsp[-1].Number * yyvsp[0].Number;
1382 #line 298 "parsedate.y"
1384 yyRelMonth += yyvsp[-1].Number * yyvsp[0].Number;
1389 #line 303 "parsedate.y"
1391 yyval.Meridian = MER24;
1396 #line 306 "parsedate.y"
1398 yyval.Meridian = yyvsp[0].Meridian;
1405 /* Line 999 of yacc.c. */
1406 #line 1406 "y.tab.c"
1412 YY_STACK_PRINT (yyss, yyssp);
1417 /* Now `shift' the result of the reduction. Determine what state
1418 that goes to, based on the state we popped back to and the rule
1419 number reduced by. */
1423 yystate = yypgoto[yyn - YYNTOKENS] + *yyssp;
1424 if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp)
1425 yystate = yytable[yystate];
1427 yystate = yydefgoto[yyn - YYNTOKENS];
1432 /*------------------------------------.
1433 | yyerrlab -- here on detecting error |
1434 `------------------------------------*/
1436 /* If not already recovering from an error, report this error. */
1441 yyn = yypact[yystate];
1443 if (YYPACT_NINF < yyn && yyn < YYLAST)
1445 YYSIZE_T yysize = 0;
1446 int yytype = YYTRANSLATE (yychar);
1451 /* Start YYX at -YYN if negative to avoid negative indexes in
1453 for (yyx = yyn < 0 ? -yyn : 0;
1454 yyx < (int) (sizeof (yytname) / sizeof (char *)); yyx++)
1455 if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)
1456 yysize += yystrlen (yytname[yyx]) + 15, yycount++;
1457 yysize += yystrlen ("syntax error, unexpected ") + 1;
1458 yysize += yystrlen (yytname[yytype]);
1459 yymsg = (char *) YYSTACK_ALLOC (yysize);
1462 char *yyp = yystpcpy (yymsg, "syntax error, unexpected ");
1463 yyp = yystpcpy (yyp, yytname[yytype]);
1468 for (yyx = yyn < 0 ? -yyn : 0;
1469 yyx < (int) (sizeof (yytname) / sizeof (char *));
1471 if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)
1473 const char *yyq = ! yycount ? ", expecting " : " or ";
1474 yyp = yystpcpy (yyp, yyq);
1475 yyp = yystpcpy (yyp, yytname[yyx]);
1480 YYSTACK_FREE (yymsg);
1483 yyerror ("syntax error; also virtual memory exhausted");
1486 #endif /* YYERROR_VERBOSE */
1487 yyerror ("syntax error");
1492 if (yyerrstatus == 3)
1494 /* If just tried and failed to reuse lookahead token after an
1495 error, discard it. */
1497 /* Return failure if at end of input. */
1498 if (yychar == YYEOF)
1500 /* Pop the error token. */
1502 /* Pop the rest of the stack. */
1503 while (yyss < yyssp)
1505 YYDSYMPRINTF ("Error: popping", yystos[*yyssp], yyvsp, yylsp);
1506 yydestruct (yystos[*yyssp], yyvsp);
1512 YYDSYMPRINTF ("Error: discarding", yytoken, &yylval, &yylloc);
1513 yydestruct (yytoken, &yylval);
1518 /* Else will try to reuse lookahead token after shifting the error
1523 /*----------------------------------------------------.
1524 | yyerrlab1 -- error raised explicitly by an action. |
1525 `----------------------------------------------------*/
1527 yyerrstatus = 3; /* Each real token shifted decrements this. */
1531 yyn = yypact[yystate];
1532 if (yyn != YYPACT_NINF)
1535 if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
1543 /* Pop the current state because it cannot handle the error token. */
1547 YYDSYMPRINTF ("Error: popping", yystos[*yyssp], yyvsp, yylsp);
1548 yydestruct (yystos[yystate], yyvsp);
1552 YY_STACK_PRINT (yyss, yyssp);
1558 YYDPRINTF ((stderr, "Shifting error token, "));
1567 /*-------------------------------------.
1568 | yyacceptlab -- YYACCEPT comes here. |
1569 `-------------------------------------*/
1574 /*-----------------------------------.
1575 | yyabortlab -- YYABORT comes here. |
1576 `-----------------------------------*/
1582 /*----------------------------------------------.
1583 | yyoverflowlab -- parser overflow comes here. |
1584 `----------------------------------------------*/
1586 yyerror ("parser stack overflow");
1594 YYSTACK_FREE (yyss);
1600 #line 311 "parsedate.y"
1603 /* Month and day table. */
1604 static TABLE MonthDayTable[] = {
1605 { "january", tMONTH, 1 },
1606 { "february", tMONTH, 2 },
1607 { "march", tMONTH, 3 },
1608 { "april", tMONTH, 4 },
1609 { "may", tMONTH, 5 },
1610 { "june", tMONTH, 6 },
1611 { "july", tMONTH, 7 },
1612 { "august", tMONTH, 8 },
1613 { "september", tMONTH, 9 },
1614 { "october", tMONTH, 10 },
1615 { "november", tMONTH, 11 },
1616 { "december", tMONTH, 12 },
1617 /* The value of the day isn't used... */
1618 { "sunday", tDAY, 0 },
1619 { "monday", tDAY, 0 },
1620 { "tuesday", tDAY, 0 },
1621 { "wednesday", tDAY, 0 },
1622 { "thursday", tDAY, 0 },
1623 { "friday", tDAY, 0 },
1624 { "saturday", tDAY, 0 },
1627 /* Time units table. */
1628 static TABLE UnitsTable[] = {
1629 { "year", tMONTH_UNIT, 12 },
1630 { "month", tMONTH_UNIT, 1 },
1631 { "week", tSEC_UNIT, 7L * 24 * 60 * 60 },
1632 { "day", tSEC_UNIT, 1L * 24 * 60 * 60 },
1633 { "hour", tSEC_UNIT, 60 * 60 },
1634 { "minute", tSEC_UNIT, 60 },
1635 { "min", tSEC_UNIT, 60 },
1636 { "second", tSEC_UNIT, 1 },
1637 { "sec", tSEC_UNIT, 1 },
1640 /* Timezone table. */
1641 static TABLE TimezoneTable[] = {
1642 { "gmt", tZONE, HOUR( 0) }, /* Greenwich Mean */
1643 { "ut", tZONE, HOUR( 0) }, /* Universal */
1644 { "utc", tZONE, HOUR( 0) }, /* Universal Coordinated */
1645 { "cut", tZONE, HOUR( 0) }, /* Coordinated Universal */
1646 { "z", tZONE, HOUR( 0) }, /* Greenwich Mean */
1647 { "wet", tZONE, HOUR( 0) }, /* Western European */
1648 { "bst", tDAYZONE, HOUR( 0) }, /* British Summer */
1649 { "nst", tZONE, HOUR(3)+30 }, /* Newfoundland Standard */
1650 { "ndt", tDAYZONE, HOUR(3)+30 }, /* Newfoundland Daylight */
1651 { "ast", tZONE, HOUR( 4) }, /* Atlantic Standard */
1652 { "adt", tDAYZONE, HOUR( 4) }, /* Atlantic Daylight */
1653 { "est", tZONE, HOUR( 5) }, /* Eastern Standard */
1654 { "edt", tDAYZONE, HOUR( 5) }, /* Eastern Daylight */
1655 { "cst", tZONE, HOUR( 6) }, /* Central Standard */
1656 { "cdt", tDAYZONE, HOUR( 6) }, /* Central Daylight */
1657 { "mst", tZONE, HOUR( 7) }, /* Mountain Standard */
1658 { "mdt", tDAYZONE, HOUR( 7) }, /* Mountain Daylight */
1659 { "pst", tZONE, HOUR( 8) }, /* Pacific Standard */
1660 { "pdt", tDAYZONE, HOUR( 8) }, /* Pacific Daylight */
1661 { "yst", tZONE, HOUR( 9) }, /* Yukon Standard */
1662 { "ydt", tDAYZONE, HOUR( 9) }, /* Yukon Daylight */
1663 { "akst", tZONE, HOUR( 9) }, /* Alaska Standard */
1664 { "akdt", tDAYZONE, HOUR( 9) }, /* Alaska Daylight */
1665 { "hst", tZONE, HOUR(10) }, /* Hawaii Standard */
1666 { "hast", tZONE, HOUR(10) }, /* Hawaii-Aleutian Standard */
1667 { "hadt", tDAYZONE, HOUR(10) }, /* Hawaii-Aleutian Daylight */
1668 { "ces", tDAYZONE, -HOUR(1) }, /* Central European Summer */
1669 { "cest", tDAYZONE, -HOUR(1) }, /* Central European Summer */
1670 { "mez", tZONE, -HOUR(1) }, /* Middle European */
1671 { "mezt", tDAYZONE, -HOUR(1) }, /* Middle European Summer */
1672 { "cet", tZONE, -HOUR(1) }, /* Central European */
1673 { "met", tZONE, -HOUR(1) }, /* Middle European */
1674 { "eet", tZONE, -HOUR(2) }, /* Eastern Europe */
1675 { "msk", tZONE, -HOUR(3) }, /* Moscow Winter */
1676 { "msd", tDAYZONE, -HOUR(3) }, /* Moscow Summer */
1677 { "wast", tZONE, -HOUR(8) }, /* West Australian Standard */
1678 { "wadt", tDAYZONE, -HOUR(8) }, /* West Australian Daylight */
1679 { "hkt", tZONE, -HOUR(8) }, /* Hong Kong */
1680 { "cct", tZONE, -HOUR(8) }, /* China Coast */
1681 { "jst", tZONE, -HOUR(9) }, /* Japan Standard */
1682 { "kst", tZONE, -HOUR(9) }, /* Korean Standard */
1683 { "kdt", tZONE, -HOUR(9) }, /* Korean Daylight */
1684 { "cast", tZONE, -(HOUR(9)+30) }, /* Central Australian Standard */
1685 { "cadt", tDAYZONE, -(HOUR(9)+30) }, /* Central Australian Daylight */
1686 { "east", tZONE, -HOUR(10) }, /* Eastern Australian Standard */
1687 { "eadt", tDAYZONE, -HOUR(10) }, /* Eastern Australian Daylight */
1688 { "nzst", tZONE, -HOUR(12) }, /* New Zealand Standard */
1689 { "nzdt", tDAYZONE, -HOUR(12) }, /* New Zealand Daylight */
1691 /* For completeness we include the following entries. */
1694 /* Duplicate names. Either they conflict with a zone listed above
1695 * (which is either more likely to be seen or just been in circulation
1696 * longer), or they conflict with another zone in this section and
1697 * we could not reasonably choose one over the other. */
1698 { "fst", tZONE, HOUR( 2) }, /* Fernando De Noronha Standard */
1699 { "fdt", tDAYZONE, HOUR( 2) }, /* Fernando De Noronha Daylight */
1700 { "bst", tZONE, HOUR( 3) }, /* Brazil Standard */
1701 { "est", tZONE, HOUR( 3) }, /* Eastern Standard (Brazil) */
1702 { "edt", tDAYZONE, HOUR( 3) }, /* Eastern Daylight (Brazil) */
1703 { "wst", tZONE, HOUR( 4) }, /* Western Standard (Brazil) */
1704 { "wdt", tDAYZONE, HOUR( 4) }, /* Western Daylight (Brazil) */
1705 { "cst", tZONE, HOUR( 5) }, /* Chile Standard */
1706 { "cdt", tDAYZONE, HOUR( 5) }, /* Chile Daylight */
1707 { "ast", tZONE, HOUR( 5) }, /* Acre Standard */
1708 { "adt", tDAYZONE, HOUR( 5) }, /* Acre Daylight */
1709 { "cst", tZONE, HOUR( 5) }, /* Cuba Standard */
1710 { "cdt", tDAYZONE, HOUR( 5) }, /* Cuba Daylight */
1711 { "est", tZONE, HOUR( 6) }, /* Easter Island Standard */
1712 { "edt", tDAYZONE, HOUR( 6) }, /* Easter Island Daylight */
1713 { "sst", tZONE, HOUR(11) }, /* Samoa Standard */
1714 { "ist", tZONE, -HOUR(2) }, /* Israel Standard */
1715 { "idt", tDAYZONE, -HOUR(2) }, /* Israel Daylight */
1716 { "idt", tDAYZONE, -(HOUR(3)+30) }, /* Iran Daylight */
1717 { "ist", tZONE, -(HOUR(3)+30) }, /* Iran Standard */
1718 { "cst", tZONE, -HOUR(8) }, /* China Standard */
1719 { "cdt", tDAYZONE, -HOUR(8) }, /* China Daylight */
1720 { "sst", tZONE, -HOUR(8) }, /* Singapore Standard */
1722 /* Dubious (e.g., not in Olson's TIMEZONE package) or obsolete. */
1723 { "gst", tZONE, HOUR( 3) }, /* Greenland Standard */
1724 { "wat", tZONE, -HOUR(1) }, /* West Africa */
1725 { "at", tZONE, HOUR( 2) }, /* Azores */
1726 { "gst", tZONE, -HOUR(10) }, /* Guam Standard */
1727 { "nft", tZONE, HOUR(3)+30 }, /* Newfoundland */
1728 { "idlw", tZONE, HOUR(12) }, /* International Date Line West */
1729 { "mewt", tZONE, -HOUR(1) }, /* Middle European Winter */
1730 { "mest", tDAYZONE, -HOUR(1) }, /* Middle European Summer */
1731 { "swt", tZONE, -HOUR(1) }, /* Swedish Winter */
1732 { "sst", tDAYZONE, -HOUR(1) }, /* Swedish Summer */
1733 { "fwt", tZONE, -HOUR(1) }, /* French Winter */
1734 { "fst", tDAYZONE, -HOUR(1) }, /* French Summer */
1735 { "bt", tZONE, -HOUR(3) }, /* Baghdad */
1736 { "it", tZONE, -(HOUR(3)+30) }, /* Iran */
1737 { "zp4", tZONE, -HOUR(4) }, /* USSR Zone 3 */
1738 { "zp5", tZONE, -HOUR(5) }, /* USSR Zone 4 */
1739 { "ist", tZONE, -(HOUR(5)+30) }, /* Indian Standard */
1740 { "zp6", tZONE, -HOUR(6) }, /* USSR Zone 5 */
1741 { "nst", tZONE, -HOUR(7) }, /* North Sumatra */
1742 { "sst", tZONE, -HOUR(7) }, /* South Sumatra */
1743 { "jt", tZONE, -(HOUR(7)+30) }, /* Java (3pm in Cronusland!) */
1744 { "nzt", tZONE, -HOUR(12) }, /* New Zealand */
1745 { "idle", tZONE, -HOUR(12) }, /* International Date Line East */
1746 { "cat", tZONE, HOUR(10) }, /* -- expired 1967 */
1747 { "nt", tZONE, HOUR(11) }, /* -- expired 1967 */
1748 { "ahst", tZONE, HOUR(10) }, /* -- expired 1983 */
1749 { "hdt", tDAYZONE, HOUR(10) }, /* -- expired 1986 */
1763 ToSeconds(time_t Hours, time_t Minutes, time_t Seconds, MERIDIAN Meridian)
1765 if (Minutes < 0 || Minutes > 59 || Seconds < 0 || Seconds > 61)
1767 if (Meridian == MER24) {
1768 if (Hours < 0 || Hours > 23)
1772 if (Hours < 1 || Hours > 12)
1776 if (Meridian == MERpm)
1779 return (Hours * 60L + Minutes) * 60L + Seconds;
1784 Convert(time_t Month, time_t Day, time_t Year,
1785 time_t Hours, time_t Minutes, time_t Seconds,
1786 MERIDIAN Meridian, DSTMODE dst)
1788 static int DaysNormal[13] = {
1789 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
1791 static int DaysLeap[13] = {
1792 0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
1794 static int LeapYears[] = {
1795 1972, 1976, 1980, 1984, 1988, 1992, 1996,
1796 2000, 2004, 2008, 2012, 2016, 2020, 2024, 2028, 2032, 2036
1800 register time_t Julian;
1810 for (mp = DaysNormal, yp = LeapYears; yp < ENDOF(LeapYears); yp++)
1815 if (Year < EPOCH || Year > END_OF_TIME
1816 || Month < 1 || Month > 12
1817 /* NOSTRICT *//* conversion from long may lose accuracy */
1818 || Day < 1 || Day > mp[(int)Month])
1821 Julian = Day - 1 + (Year - EPOCH) * 365;
1822 for (yp = LeapYears; yp < ENDOF(LeapYears); yp++, Julian++)
1825 for (i = 1; i < Month; i++)
1827 Julian *= SECSPERDAY;
1828 Julian += yyTimezone * 60L;
1829 if ((tod = ToSeconds(Hours, Minutes, Seconds, Meridian)) < 0)
1833 if (dst == DSTon || (dst == DSTmaybe && localtime(&tod)->tm_isdst))
1834 Julian -= DST_OFFSET * 60L * 60L;
1840 DSTcorrect(time_t Start, time_t Future)
1845 StartDay = (localtime(&Start)->tm_hour + 1) % 24;
1846 FutureDay = (localtime(&Future)->tm_hour + 1) % 24;
1847 return (Future - Start) + (StartDay - FutureDay) * DST_OFFSET * 60L * 60L;
1852 RelativeMonth(time_t Start, time_t RelMonth)
1858 tm = localtime(&Start);
1859 Month = 12 * tm->tm_year + tm->tm_mon + RelMonth;
1861 Month = Month % 12 + 1;
1862 return DSTcorrect(Start,
1863 Convert(Month, (time_t)tm->tm_mday, Year,
1864 (time_t)tm->tm_hour, (time_t)tm->tm_min, (time_t)tm->tm_sec,
1870 LookupWord(char *buff, register int length)
1880 /* See if we have an abbreviation for a month. */
1881 if (length == 3 || (length == 4 && p[3] == '.'))
1882 for (tp = MonthDayTable; tp < ENDOF(MonthDayTable); tp++) {
1884 if (c == q[0] && p[1] == q[1] && p[2] == q[2]) {
1885 yylval.Number = tp->value;
1890 for (tp = MonthDayTable; tp < ENDOF(MonthDayTable); tp++)
1891 if (c == tp->name[0] && strcmp(p, tp->name) == 0) {
1892 yylval.Number = tp->value;
1896 /* Try for a timezone. */
1897 for (tp = TimezoneTable; tp < ENDOF(TimezoneTable); tp++)
1898 if (c == tp->name[0] && p[1] == tp->name[1]
1899 && strcmp(p, tp->name) == 0) {
1900 yylval.Number = tp->value;
1904 /* Try the units table. */
1905 for (tp = UnitsTable; tp < ENDOF(UnitsTable); tp++)
1906 if (c == tp->name[0] && strcmp(p, tp->name) == 0) {
1907 yylval.Number = tp->value;
1911 /* Strip off any plural and try the units table again. */
1912 if (--length > 0 && p[length] == 's') {
1914 for (tp = UnitsTable; tp < ENDOF(UnitsTable); tp++)
1915 if (c == tp->name[0] && strcmp(p, tp->name) == 0) {
1917 yylval.Number = tp->value;
1924 /* Drop out any periods. */
1925 for (p = buff, q = (char*)buff; *q; q++)
1930 /* Try the meridians. */
1931 if (buff[1] == 'm' && buff[2] == '\0') {
1932 if (buff[0] == 'a') {
1933 yylval.Meridian = MERam;
1936 if (buff[0] == 'p') {
1937 yylval.Meridian = MERpm;
1942 /* If we saw any periods, try the timezones again. */
1943 if (p - buff != length) {
1945 for (p = buff, tp = TimezoneTable; tp < ENDOF(TimezoneTable); tp++)
1946 if (c == tp->name[0] && p[1] == tp->name[1]
1947 && strcmp(p, tp->name) == 0) {
1948 yylval.Number = tp->value;
1953 /* Unknown word -- assume GMT timezone. */
1967 register int nesting;
1970 /* Get first character after the whitespace. */
1972 while (isspace(*yyInput))
1976 /* Ignore RFC 822 comments, typically time zone names. */
1979 for (nesting = 1; (c = *++yyInput) != RPAREN || --nesting; )
1982 else if (!IS7BIT(c) || c == '\0' || c == '\r'
1983 || (c == '\\' && ((c = *++yyInput) == '\0' || !IS7BIT(c))))
1984 /* Lexical error: bad comment. */
1990 if (isdigit(c) || c == '-' || c == '+') {
1991 if (c == '-' || c == '+') {
1992 sign = c == '-' ? -1 : 1;
1994 if (!isdigit(*yyInput))
1995 /* Skip the plus or minus sign. */
2000 for (i = 0; (c = *yyInput++) != '\0' && isdigit(c); )
2001 i = 10 * i + c - '0';
2003 yylval.Number = sign < 0 ? -i : i;
2004 return sign ? tSNUMBER : tUNUMBER;
2009 for (p = buff; (c = *yyInput++) == '.' || isalpha(c); )
2010 if (p < &buff[sizeof buff - 1])
2011 *p++ = isupper(c) ? tolower(c) : c;
2014 return LookupWord(buff, p - buff);
2025 extern int date_parse(void);
2034 yyDSTmode = DSTmaybe;
2045 if (date_parse() || yyHaveTime > 1 || yyHaveDate > 1)
2048 if (yyHaveDate || yyHaveTime) {
2049 Start = Convert(yyMonth, yyDay, yyYear, yyHour, yyMinutes, yySeconds,
2050 yyMeridian, yyDSTmode);
2057 Start += yyRelSeconds;
2059 Start += RelativeMonth(Start, yyRelMonth);
2061 /* Have to do *something* with a legitimate -1 so it's distinguishable
2062 * from the error return value. (Alternately could set errno on error.) */
2063 return Start == -1 ? 0 : Start;
2071 #endif /* YYDEBUG */
2075 main(int ac, char *av[])
2082 #endif /* YYDEBUG */
2084 (void)printf("Enter date, or blank line to exit.\n\t> ");
2086 (void)printf("\t> ");
2087 (void)fflush(stdout);
2088 if (fgets(buff, sizeof buff, stdin) == NULL || buff[0] == '\n')
2091 if (strcmp(buff, "yydebug") == 0) {
2093 printf("yydebug = %s\n", yydebug ? "on" : "off");
2096 #endif /* YYDEBUG */
2097 d = parsedate(buff, (TIMEINFO *)NULL);
2099 (void)printf("Bad format - couldn't convert.\n");
2101 (void)printf("%s", ctime(&d));