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
558 /* Like YYERROR except do call yyerror. This remains here temporarily
559 to ease the transition to the new meaning of YYERROR, for GCC.
560 Once GCC version 2 has supplanted version 1, this can go. */
562 #define YYFAIL goto yyerrlab
564 #define YYRECOVERING() (!!yyerrstatus)
566 #define YYBACKUP(Token, Value) \
568 if (yychar == YYEMPTY && yylen == 1) \
572 yytoken = YYTRANSLATE (yychar); \
578 yyerror ("syntax error: cannot back up");\
584 #define YYERRCODE 256
586 /* YYLLOC_DEFAULT -- Compute the default location (before the actions
589 #ifndef YYLLOC_DEFAULT
590 # define YYLLOC_DEFAULT(Current, Rhs, N) \
591 Current.first_line = Rhs[1].first_line; \
592 Current.first_column = Rhs[1].first_column; \
593 Current.last_line = Rhs[N].last_line; \
594 Current.last_column = Rhs[N].last_column;
597 /* YYLEX -- calling `yylex' with the right arguments. */
600 # define YYLEX yylex (YYLEX_PARAM)
602 # define YYLEX yylex ()
605 /* Enable debugging if requested. */
609 # include <stdio.h> /* INFRINGES ON USER NAME SPACE */
610 # define YYFPRINTF fprintf
613 # define YYDPRINTF(Args) \
619 # define YYDSYMPRINT(Args) \
625 # define YYDSYMPRINTF(Title, Token, Value, Location) \
629 YYFPRINTF (stderr, "%s ", Title); \
630 yysymprint (stderr, \
632 YYFPRINTF (stderr, "\n"); \
636 /*------------------------------------------------------------------.
637 | yy_stack_print -- Print the state stack from its BOTTOM up to its |
639 `------------------------------------------------------------------*/
641 #if defined (__STDC__) || defined (__cplusplus)
643 yy_stack_print (short *bottom, short *top)
646 yy_stack_print (bottom, top)
651 YYFPRINTF (stderr, "Stack now");
652 for (/* Nothing. */; bottom <= top; ++bottom)
653 YYFPRINTF (stderr, " %d", *bottom);
654 YYFPRINTF (stderr, "\n");
657 # define YY_STACK_PRINT(Bottom, Top) \
660 yy_stack_print ((Bottom), (Top)); \
664 /*------------------------------------------------.
665 | Report that the YYRULE is going to be reduced. |
666 `------------------------------------------------*/
668 #if defined (__STDC__) || defined (__cplusplus)
670 yy_reduce_print (int yyrule)
673 yy_reduce_print (yyrule)
678 unsigned int yylineno = yyrline[yyrule];
679 YYFPRINTF (stderr, "Reducing stack by rule %d (line %u), ",
680 yyrule - 1, yylineno);
681 /* Print the symbols being reduced, and their result. */
682 for (yyi = yyprhs[yyrule]; 0 <= yyrhs[yyi]; yyi++)
683 YYFPRINTF (stderr, "%s ", yytname [yyrhs[yyi]]);
684 YYFPRINTF (stderr, "-> %s\n", yytname [yyr1[yyrule]]);
687 # define YY_REDUCE_PRINT(Rule) \
690 yy_reduce_print (Rule); \
693 /* Nonzero means print parse trace. It is left uninitialized so that
694 multiple parsers can coexist. */
697 # define YYDPRINTF(Args)
698 # define YYDSYMPRINT(Args)
699 # define YYDSYMPRINTF(Title, Token, Value, Location)
700 # define YY_STACK_PRINT(Bottom, Top)
701 # define YY_REDUCE_PRINT(Rule)
702 #endif /* !YYDEBUG */
705 /* YYINITDEPTH -- initial size of the parser's stacks. */
707 # define YYINITDEPTH 200
710 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
711 if the built-in stack extension method is used).
713 Do not make this value too large; the results are undefined if
714 SIZE_MAX < YYSTACK_BYTES (YYMAXDEPTH)
715 evaluated with infinite-precision integer arithmetic. */
722 # define YYMAXDEPTH 10000
730 # if defined (__GLIBC__) && defined (_STRING_H)
731 # define yystrlen strlen
733 /* Return the length of YYSTR. */
735 # if defined (__STDC__) || defined (__cplusplus)
736 yystrlen (const char *yystr)
742 register const char *yys = yystr;
744 while (*yys++ != '\0')
747 return yys - yystr - 1;
753 # if defined (__GLIBC__) && defined (_STRING_H) && defined (_GNU_SOURCE)
754 # define yystpcpy stpcpy
756 /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
759 # if defined (__STDC__) || defined (__cplusplus)
760 yystpcpy (char *yydest, const char *yysrc)
762 yystpcpy (yydest, yysrc)
767 register char *yyd = yydest;
768 register const char *yys = yysrc;
770 while ((*yyd++ = *yys++) != '\0')
778 #endif /* !YYERROR_VERBOSE */
783 /*--------------------------------.
784 | Print this symbol on YYOUTPUT. |
785 `--------------------------------*/
787 #if defined (__STDC__) || defined (__cplusplus)
789 yysymprint (FILE *yyoutput, int yytype, YYSTYPE *yyvaluep)
792 yysymprint (yyoutput, yytype, yyvaluep)
798 /* Pacify ``unused variable'' warnings. */
801 if (yytype < YYNTOKENS)
803 YYFPRINTF (yyoutput, "token %s (", yytname[yytype]);
805 YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep);
809 YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]);
816 YYFPRINTF (yyoutput, ")");
819 #endif /* ! YYDEBUG */
820 /*-----------------------------------------------.
821 | Release the memory associated to this symbol. |
822 `-----------------------------------------------*/
824 #if defined (__STDC__) || defined (__cplusplus)
826 yydestruct (int yytype, YYSTYPE *yyvaluep)
829 yydestruct (yytype, yyvaluep)
834 /* Pacify ``unused variable'' warnings. */
846 /* Prevent warnings from -Wmissing-prototypes. */
849 # if defined (__STDC__) || defined (__cplusplus)
850 int yyparse (void *YYPARSE_PARAM);
854 #else /* ! YYPARSE_PARAM */
855 #if defined (__STDC__) || defined (__cplusplus)
860 #endif /* ! YYPARSE_PARAM */
864 /* The lookahead symbol. */
867 /* The semantic value of the lookahead symbol. */
870 /* Number of syntax errors so far. */
880 # if defined (__STDC__) || defined (__cplusplus)
881 int yyparse (void *YYPARSE_PARAM)
883 int yyparse (YYPARSE_PARAM)
886 #else /* ! YYPARSE_PARAM */
887 #if defined (__STDC__) || defined (__cplusplus)
898 register int yystate;
901 /* Number of tokens to shift before error messages enabled. */
903 /* Lookahead token as an internal (translated) token number. */
906 /* Three stacks and their tools:
907 `yyss': related to states,
908 `yyvs': related to semantic values,
909 `yyls': related to locations.
911 Refer to the stacks thru separate pointers, to allow yyoverflow
912 to reallocate them elsewhere. */
914 /* The state stack. */
915 short yyssa[YYINITDEPTH];
917 register short *yyssp;
919 /* The semantic value stack. */
920 YYSTYPE yyvsa[YYINITDEPTH];
921 YYSTYPE *yyvs = yyvsa;
922 register YYSTYPE *yyvsp;
926 #define YYPOPSTACK (yyvsp--, yyssp--)
928 YYSIZE_T yystacksize = YYINITDEPTH;
930 /* The variables used to return semantic value and location from the
935 /* When reducing, the number of symbols on the RHS of the reduced
939 YYDPRINTF ((stderr, "Starting parse\n"));
944 yychar = YYEMPTY; /* Cause a token to be read. */
946 /* Initialize stack pointers.
947 Waste one element of value and location stack
948 so that they stay on the same level as the state stack.
949 The wasted elements are never initialized. */
956 /*------------------------------------------------------------.
957 | yynewstate -- Push a new state, which is found in yystate. |
958 `------------------------------------------------------------*/
960 /* In all cases, when you get here, the value and location stacks
961 have just been pushed. so pushing a state here evens the stacks.
968 if (yyss + yystacksize - 1 <= yyssp)
970 /* Get the current used size of the three stacks, in elements. */
971 YYSIZE_T yysize = yyssp - yyss + 1;
975 /* Give user a chance to reallocate the stack. Use copies of
976 these so that the &'s don't force the real ones into
978 YYSTYPE *yyvs1 = yyvs;
982 /* Each stack pointer address is followed by the size of the
983 data in use in that stack, in bytes. This used to be a
984 conditional around just the two extra args, but that might
985 be undefined if yyoverflow is a macro. */
986 yyoverflow ("parser stack overflow",
987 &yyss1, yysize * sizeof (*yyssp),
988 &yyvs1, yysize * sizeof (*yyvsp),
995 #else /* no yyoverflow */
996 # ifndef YYSTACK_RELOCATE
999 /* Extend the stack our own way. */
1000 if (YYMAXDEPTH <= yystacksize)
1003 if (YYMAXDEPTH < yystacksize)
1004 yystacksize = YYMAXDEPTH;
1007 short *yyss1 = yyss;
1008 union yyalloc *yyptr =
1009 (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
1012 YYSTACK_RELOCATE (yyss);
1013 YYSTACK_RELOCATE (yyvs);
1015 # undef YYSTACK_RELOCATE
1017 YYSTACK_FREE (yyss1);
1020 #endif /* no yyoverflow */
1022 yyssp = yyss + yysize - 1;
1023 yyvsp = yyvs + yysize - 1;
1026 YYDPRINTF ((stderr, "Stack size increased to %lu\n",
1027 (unsigned long int) yystacksize));
1029 if (yyss + yystacksize - 1 <= yyssp)
1033 YYDPRINTF ((stderr, "Entering state %d\n", yystate));
1042 /* Do appropriate processing given the current state. */
1043 /* Read a lookahead token if we need one and don't already have one. */
1046 /* First try to decide what to do without reference to lookahead token. */
1048 yyn = yypact[yystate];
1049 if (yyn == YYPACT_NINF)
1052 /* Not known => get a lookahead token if don't already have one. */
1054 /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol. */
1055 if (yychar == YYEMPTY)
1057 YYDPRINTF ((stderr, "Reading a token: "));
1061 if (yychar <= YYEOF)
1063 yychar = yytoken = YYEOF;
1064 YYDPRINTF ((stderr, "Now at end of input.\n"));
1068 yytoken = YYTRANSLATE (yychar);
1069 YYDSYMPRINTF ("Next token is", yytoken, &yylval, &yylloc);
1072 /* If the proper action on seeing token YYTOKEN is to reduce or to
1073 detect an error, take that action. */
1075 if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
1080 if (yyn == 0 || yyn == YYTABLE_NINF)
1089 /* Shift the lookahead token. */
1090 YYDPRINTF ((stderr, "Shifting token %s, ", yytname[yytoken]));
1092 /* Discard the token being shifted unless it is eof. */
1093 if (yychar != YYEOF)
1099 /* Count tokens shifted since error; after three, turn off error
1108 /*-----------------------------------------------------------.
1109 | yydefault -- do the default action for the current state. |
1110 `-----------------------------------------------------------*/
1112 yyn = yydefact[yystate];
1118 /*-----------------------------.
1119 | yyreduce -- Do a reduction. |
1120 `-----------------------------*/
1122 /* yyn is the number of a rule to reduce with. */
1125 /* If YYLEN is nonzero, implement the default value of the action:
1128 Otherwise, the following line sets YYVAL to garbage.
1129 This behavior is undocumented and Bison
1130 users should not rely upon it. Assigning to YYVAL
1131 unconditionally makes the parser a bit smaller, and it avoids a
1132 GCC warning that YYVAL may be used uninitialized. */
1133 yyval = yyvsp[1-yylen];
1136 YY_REDUCE_PRINT (yyn);
1140 #line 143 "parsedate.y"
1144 /* I am compulsive about lint natterings... */
1145 if (yyHaveTime == -1) {
1153 #line 152 "parsedate.y"
1156 yyTimezone = yyvsp[0].Number;
1161 #line 156 "parsedate.y"
1168 #line 159 "parsedate.y"
1175 #line 164 "parsedate.y"
1177 if (yyvsp[-1].Number < 100) {
1178 yyHour = yyvsp[-1].Number;
1182 yyHour = yyvsp[-1].Number / 100;
1183 yyMinutes = yyvsp[-1].Number % 100;
1186 yyMeridian = yyvsp[0].Meridian;
1191 #line 176 "parsedate.y"
1193 yyHour = yyvsp[-3].Number;
1194 yyMinutes = yyvsp[-1].Number;
1196 yyMeridian = yyvsp[0].Meridian;
1201 #line 182 "parsedate.y"
1203 yyHour = yyvsp[-3].Number;
1204 yyMinutes = yyvsp[-1].Number;
1205 yyTimezone = yyvsp[0].Number;
1212 #line 189 "parsedate.y"
1214 yyHour = yyvsp[-5].Number;
1215 yyMinutes = yyvsp[-3].Number;
1216 yySeconds = yyvsp[-1].Number;
1217 yyMeridian = yyvsp[0].Meridian;
1222 #line 195 "parsedate.y"
1224 yyHour = yyvsp[-5].Number;
1225 yyMinutes = yyvsp[-3].Number;
1226 yySeconds = yyvsp[-1].Number;
1227 yyTimezone = yyvsp[0].Number;
1234 #line 205 "parsedate.y"
1236 yyval.Number = yyvsp[0].Number;
1242 #line 209 "parsedate.y"
1244 yyval.Number = yyvsp[0].Number;
1250 #line 213 "parsedate.y"
1252 /* Only allow "GMT+300" and "GMT-0800" */
1253 if (yyvsp[-1].Number != 0) {
1256 yyval.Number = yyvsp[0].Number;
1262 #line 221 "parsedate.y"
1264 yyval.Number = yyvsp[0].Number;
1270 #line 227 "parsedate.y"
1274 /* Unix and GMT and numeric timezones -- a little confusing. */
1275 if (yyvsp[0].Number < 0) {
1276 /* Don't work with negative modulus. */
1277 yyvsp[0].Number = -yyvsp[0].Number;
1278 if (yyvsp[0].Number > 9999 || (i = yyvsp[0].Number % 100) >= 60) {
1281 yyval.Number = (yyvsp[0].Number / 100) * 60 + i;
1284 if (yyvsp[0].Number > 9999 || (i = yyvsp[0].Number % 100) >= 60) {
1287 yyval.Number = -((yyvsp[0].Number / 100) * 60 + i);
1293 #line 248 "parsedate.y"
1295 yyMonth = yyvsp[-2].Number;
1296 yyDay = yyvsp[0].Number;
1301 #line 252 "parsedate.y"
1303 if (yyvsp[-4].Number > 100) {
1304 yyYear = yyvsp[-4].Number;
1305 yyMonth = yyvsp[-2].Number;
1306 yyDay = yyvsp[0].Number;
1309 yyMonth = yyvsp[-4].Number;
1310 yyDay = yyvsp[-2].Number;
1311 yyYear = yyvsp[0].Number;
1317 #line 264 "parsedate.y"
1319 yyMonth = yyvsp[-1].Number;
1320 yyDay = yyvsp[0].Number;
1325 #line 268 "parsedate.y"
1327 yyMonth = yyvsp[-3].Number;
1328 yyDay = yyvsp[-2].Number;
1329 yyYear = yyvsp[0].Number;
1334 #line 273 "parsedate.y"
1336 yyDay = yyvsp[-1].Number;
1337 yyMonth = yyvsp[0].Number;
1342 #line 277 "parsedate.y"
1344 yyDay = yyvsp[-2].Number;
1345 yyMonth = yyvsp[-1].Number;
1346 yyYear = yyvsp[0].Number;
1351 #line 282 "parsedate.y"
1353 yyDay = yyvsp[-2].Number;
1354 yyMonth = yyvsp[-1].Number;
1355 yyYear = yyvsp[0].Number;
1360 #line 289 "parsedate.y"
1362 yyRelSeconds += yyvsp[-1].Number * yyvsp[0].Number;
1367 #line 292 "parsedate.y"
1369 yyRelSeconds += yyvsp[-1].Number * yyvsp[0].Number;
1374 #line 295 "parsedate.y"
1376 yyRelMonth += yyvsp[-1].Number * yyvsp[0].Number;
1381 #line 298 "parsedate.y"
1383 yyRelMonth += yyvsp[-1].Number * yyvsp[0].Number;
1388 #line 303 "parsedate.y"
1390 yyval.Meridian = MER24;
1395 #line 306 "parsedate.y"
1397 yyval.Meridian = yyvsp[0].Meridian;
1404 /* Line 991 of yacc.c. */
1405 #line 1405 "y.tab.c"
1411 YY_STACK_PRINT (yyss, yyssp);
1416 /* Now `shift' the result of the reduction. Determine what state
1417 that goes to, based on the state we popped back to and the rule
1418 number reduced by. */
1422 yystate = yypgoto[yyn - YYNTOKENS] + *yyssp;
1423 if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp)
1424 yystate = yytable[yystate];
1426 yystate = yydefgoto[yyn - YYNTOKENS];
1431 /*------------------------------------.
1432 | yyerrlab -- here on detecting error |
1433 `------------------------------------*/
1435 /* If not already recovering from an error, report this error. */
1440 yyn = yypact[yystate];
1442 if (YYPACT_NINF < yyn && yyn < YYLAST)
1444 YYSIZE_T yysize = 0;
1445 int yytype = YYTRANSLATE (yychar);
1450 /* Start YYX at -YYN if negative to avoid negative indexes in
1452 for (yyx = yyn < 0 ? -yyn : 0;
1453 yyx < (int) (sizeof (yytname) / sizeof (char *)); yyx++)
1454 if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)
1455 yysize += yystrlen (yytname[yyx]) + 15, yycount++;
1456 yysize += yystrlen ("syntax error, unexpected ") + 1;
1457 yysize += yystrlen (yytname[yytype]);
1458 yymsg = (char *) YYSTACK_ALLOC (yysize);
1461 char *yyp = yystpcpy (yymsg, "syntax error, unexpected ");
1462 yyp = yystpcpy (yyp, yytname[yytype]);
1467 for (yyx = yyn < 0 ? -yyn : 0;
1468 yyx < (int) (sizeof (yytname) / sizeof (char *));
1470 if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)
1472 const char *yyq = ! yycount ? ", expecting " : " or ";
1473 yyp = yystpcpy (yyp, yyq);
1474 yyp = yystpcpy (yyp, yytname[yyx]);
1479 YYSTACK_FREE (yymsg);
1482 yyerror ("syntax error; also virtual memory exhausted");
1485 #endif /* YYERROR_VERBOSE */
1486 yyerror ("syntax error");
1491 if (yyerrstatus == 3)
1493 /* If just tried and failed to reuse lookahead token after an
1494 error, discard it. */
1496 /* Return failure if at end of input. */
1497 if (yychar == YYEOF)
1499 /* Pop the error token. */
1501 /* Pop the rest of the stack. */
1502 while (yyss < yyssp)
1504 YYDSYMPRINTF ("Error: popping", yystos[*yyssp], yyvsp, yylsp);
1505 yydestruct (yystos[*yyssp], yyvsp);
1511 YYDSYMPRINTF ("Error: discarding", yytoken, &yylval, &yylloc);
1512 yydestruct (yytoken, &yylval);
1517 /* Else will try to reuse lookahead token after shifting the error
1522 /*----------------------------------------------------.
1523 | yyerrlab1 -- error raised explicitly by an action. |
1524 `----------------------------------------------------*/
1527 /* Suppress GCC warning that yyerrlab1 is unused when no action
1529 #if defined (__GNUC_MINOR__) && 2093 <= (__GNUC__ * 1000 + __GNUC_MINOR__) \
1530 && !defined __cplusplus
1531 __attribute__ ((__unused__))
1538 /*---------------------------------------------------------------.
1539 | yyerrlab2 -- pop states until the error token can be shifted. |
1540 `---------------------------------------------------------------*/
1542 yyerrstatus = 3; /* Each real token shifted decrements this. */
1546 yyn = yypact[yystate];
1547 if (yyn != YYPACT_NINF)
1550 if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
1558 /* Pop the current state because it cannot handle the error token. */
1562 YYDSYMPRINTF ("Error: popping", yystos[*yyssp], yyvsp, yylsp);
1563 yydestruct (yystos[yystate], yyvsp);
1567 YY_STACK_PRINT (yyss, yyssp);
1573 YYDPRINTF ((stderr, "Shifting error token, "));
1582 /*-------------------------------------.
1583 | yyacceptlab -- YYACCEPT comes here. |
1584 `-------------------------------------*/
1589 /*-----------------------------------.
1590 | yyabortlab -- YYABORT comes here. |
1591 `-----------------------------------*/
1597 /*----------------------------------------------.
1598 | yyoverflowlab -- parser overflow comes here. |
1599 `----------------------------------------------*/
1601 yyerror ("parser stack overflow");
1609 YYSTACK_FREE (yyss);
1615 #line 311 "parsedate.y"
1618 /* Month and day table. */
1619 static TABLE MonthDayTable[] = {
1620 { "january", tMONTH, 1 },
1621 { "february", tMONTH, 2 },
1622 { "march", tMONTH, 3 },
1623 { "april", tMONTH, 4 },
1624 { "may", tMONTH, 5 },
1625 { "june", tMONTH, 6 },
1626 { "july", tMONTH, 7 },
1627 { "august", tMONTH, 8 },
1628 { "september", tMONTH, 9 },
1629 { "october", tMONTH, 10 },
1630 { "november", tMONTH, 11 },
1631 { "december", tMONTH, 12 },
1632 /* The value of the day isn't used... */
1633 { "sunday", tDAY, 0 },
1634 { "monday", tDAY, 0 },
1635 { "tuesday", tDAY, 0 },
1636 { "wednesday", tDAY, 0 },
1637 { "thursday", tDAY, 0 },
1638 { "friday", tDAY, 0 },
1639 { "saturday", tDAY, 0 },
1642 /* Time units table. */
1643 static TABLE UnitsTable[] = {
1644 { "year", tMONTH_UNIT, 12 },
1645 { "month", tMONTH_UNIT, 1 },
1646 { "week", tSEC_UNIT, 7L * 24 * 60 * 60 },
1647 { "day", tSEC_UNIT, 1L * 24 * 60 * 60 },
1648 { "hour", tSEC_UNIT, 60 * 60 },
1649 { "minute", tSEC_UNIT, 60 },
1650 { "min", tSEC_UNIT, 60 },
1651 { "second", tSEC_UNIT, 1 },
1652 { "sec", tSEC_UNIT, 1 },
1655 /* Timezone table. */
1656 static TABLE TimezoneTable[] = {
1657 { "gmt", tZONE, HOUR( 0) }, /* Greenwich Mean */
1658 { "ut", tZONE, HOUR( 0) }, /* Universal */
1659 { "utc", tZONE, HOUR( 0) }, /* Universal Coordinated */
1660 { "cut", tZONE, HOUR( 0) }, /* Coordinated Universal */
1661 { "z", tZONE, HOUR( 0) }, /* Greenwich Mean */
1662 { "wet", tZONE, HOUR( 0) }, /* Western European */
1663 { "bst", tDAYZONE, HOUR( 0) }, /* British Summer */
1664 { "nst", tZONE, HOUR(3)+30 }, /* Newfoundland Standard */
1665 { "ndt", tDAYZONE, HOUR(3)+30 }, /* Newfoundland Daylight */
1666 { "ast", tZONE, HOUR( 4) }, /* Atlantic Standard */
1667 { "adt", tDAYZONE, HOUR( 4) }, /* Atlantic Daylight */
1668 { "est", tZONE, HOUR( 5) }, /* Eastern Standard */
1669 { "edt", tDAYZONE, HOUR( 5) }, /* Eastern Daylight */
1670 { "cst", tZONE, HOUR( 6) }, /* Central Standard */
1671 { "cdt", tDAYZONE, HOUR( 6) }, /* Central Daylight */
1672 { "mst", tZONE, HOUR( 7) }, /* Mountain Standard */
1673 { "mdt", tDAYZONE, HOUR( 7) }, /* Mountain Daylight */
1674 { "pst", tZONE, HOUR( 8) }, /* Pacific Standard */
1675 { "pdt", tDAYZONE, HOUR( 8) }, /* Pacific Daylight */
1676 { "yst", tZONE, HOUR( 9) }, /* Yukon Standard */
1677 { "ydt", tDAYZONE, HOUR( 9) }, /* Yukon Daylight */
1678 { "akst", tZONE, HOUR( 9) }, /* Alaska Standard */
1679 { "akdt", tDAYZONE, HOUR( 9) }, /* Alaska Daylight */
1680 { "hst", tZONE, HOUR(10) }, /* Hawaii Standard */
1681 { "hast", tZONE, HOUR(10) }, /* Hawaii-Aleutian Standard */
1682 { "hadt", tDAYZONE, HOUR(10) }, /* Hawaii-Aleutian Daylight */
1683 { "ces", tDAYZONE, -HOUR(1) }, /* Central European Summer */
1684 { "cest", tDAYZONE, -HOUR(1) }, /* Central European Summer */
1685 { "mez", tZONE, -HOUR(1) }, /* Middle European */
1686 { "mezt", tDAYZONE, -HOUR(1) }, /* Middle European Summer */
1687 { "cet", tZONE, -HOUR(1) }, /* Central European */
1688 { "met", tZONE, -HOUR(1) }, /* Middle European */
1689 { "eet", tZONE, -HOUR(2) }, /* Eastern Europe */
1690 { "msk", tZONE, -HOUR(3) }, /* Moscow Winter */
1691 { "msd", tDAYZONE, -HOUR(3) }, /* Moscow Summer */
1692 { "wast", tZONE, -HOUR(8) }, /* West Australian Standard */
1693 { "wadt", tDAYZONE, -HOUR(8) }, /* West Australian Daylight */
1694 { "hkt", tZONE, -HOUR(8) }, /* Hong Kong */
1695 { "cct", tZONE, -HOUR(8) }, /* China Coast */
1696 { "jst", tZONE, -HOUR(9) }, /* Japan Standard */
1697 { "kst", tZONE, -HOUR(9) }, /* Korean Standard */
1698 { "kdt", tZONE, -HOUR(9) }, /* Korean Daylight */
1699 { "cast", tZONE, -(HOUR(9)+30) }, /* Central Australian Standard */
1700 { "cadt", tDAYZONE, -(HOUR(9)+30) }, /* Central Australian Daylight */
1701 { "east", tZONE, -HOUR(10) }, /* Eastern Australian Standard */
1702 { "eadt", tDAYZONE, -HOUR(10) }, /* Eastern Australian Daylight */
1703 { "nzst", tZONE, -HOUR(12) }, /* New Zealand Standard */
1704 { "nzdt", tDAYZONE, -HOUR(12) }, /* New Zealand Daylight */
1706 /* For completeness we include the following entries. */
1709 /* Duplicate names. Either they conflict with a zone listed above
1710 * (which is either more likely to be seen or just been in circulation
1711 * longer), or they conflict with another zone in this section and
1712 * we could not reasonably choose one over the other. */
1713 { "fst", tZONE, HOUR( 2) }, /* Fernando De Noronha Standard */
1714 { "fdt", tDAYZONE, HOUR( 2) }, /* Fernando De Noronha Daylight */
1715 { "bst", tZONE, HOUR( 3) }, /* Brazil Standard */
1716 { "est", tZONE, HOUR( 3) }, /* Eastern Standard (Brazil) */
1717 { "edt", tDAYZONE, HOUR( 3) }, /* Eastern Daylight (Brazil) */
1718 { "wst", tZONE, HOUR( 4) }, /* Western Standard (Brazil) */
1719 { "wdt", tDAYZONE, HOUR( 4) }, /* Western Daylight (Brazil) */
1720 { "cst", tZONE, HOUR( 5) }, /* Chile Standard */
1721 { "cdt", tDAYZONE, HOUR( 5) }, /* Chile Daylight */
1722 { "ast", tZONE, HOUR( 5) }, /* Acre Standard */
1723 { "adt", tDAYZONE, HOUR( 5) }, /* Acre Daylight */
1724 { "cst", tZONE, HOUR( 5) }, /* Cuba Standard */
1725 { "cdt", tDAYZONE, HOUR( 5) }, /* Cuba Daylight */
1726 { "est", tZONE, HOUR( 6) }, /* Easter Island Standard */
1727 { "edt", tDAYZONE, HOUR( 6) }, /* Easter Island Daylight */
1728 { "sst", tZONE, HOUR(11) }, /* Samoa Standard */
1729 { "ist", tZONE, -HOUR(2) }, /* Israel Standard */
1730 { "idt", tDAYZONE, -HOUR(2) }, /* Israel Daylight */
1731 { "idt", tDAYZONE, -(HOUR(3)+30) }, /* Iran Daylight */
1732 { "ist", tZONE, -(HOUR(3)+30) }, /* Iran Standard */
1733 { "cst", tZONE, -HOUR(8) }, /* China Standard */
1734 { "cdt", tDAYZONE, -HOUR(8) }, /* China Daylight */
1735 { "sst", tZONE, -HOUR(8) }, /* Singapore Standard */
1737 /* Dubious (e.g., not in Olson's TIMEZONE package) or obsolete. */
1738 { "gst", tZONE, HOUR( 3) }, /* Greenland Standard */
1739 { "wat", tZONE, -HOUR(1) }, /* West Africa */
1740 { "at", tZONE, HOUR( 2) }, /* Azores */
1741 { "gst", tZONE, -HOUR(10) }, /* Guam Standard */
1742 { "nft", tZONE, HOUR(3)+30 }, /* Newfoundland */
1743 { "idlw", tZONE, HOUR(12) }, /* International Date Line West */
1744 { "mewt", tZONE, -HOUR(1) }, /* Middle European Winter */
1745 { "mest", tDAYZONE, -HOUR(1) }, /* Middle European Summer */
1746 { "swt", tZONE, -HOUR(1) }, /* Swedish Winter */
1747 { "sst", tDAYZONE, -HOUR(1) }, /* Swedish Summer */
1748 { "fwt", tZONE, -HOUR(1) }, /* French Winter */
1749 { "fst", tDAYZONE, -HOUR(1) }, /* French Summer */
1750 { "bt", tZONE, -HOUR(3) }, /* Baghdad */
1751 { "it", tZONE, -(HOUR(3)+30) }, /* Iran */
1752 { "zp4", tZONE, -HOUR(4) }, /* USSR Zone 3 */
1753 { "zp5", tZONE, -HOUR(5) }, /* USSR Zone 4 */
1754 { "ist", tZONE, -(HOUR(5)+30) }, /* Indian Standard */
1755 { "zp6", tZONE, -HOUR(6) }, /* USSR Zone 5 */
1756 { "nst", tZONE, -HOUR(7) }, /* North Sumatra */
1757 { "sst", tZONE, -HOUR(7) }, /* South Sumatra */
1758 { "jt", tZONE, -(HOUR(7)+30) }, /* Java (3pm in Cronusland!) */
1759 { "nzt", tZONE, -HOUR(12) }, /* New Zealand */
1760 { "idle", tZONE, -HOUR(12) }, /* International Date Line East */
1761 { "cat", tZONE, HOUR(10) }, /* -- expired 1967 */
1762 { "nt", tZONE, HOUR(11) }, /* -- expired 1967 */
1763 { "ahst", tZONE, HOUR(10) }, /* -- expired 1983 */
1764 { "hdt", tDAYZONE, HOUR(10) }, /* -- expired 1986 */
1778 ToSeconds(time_t Hours, time_t Minutes, time_t Seconds, MERIDIAN Meridian)
1780 if (Minutes < 0 || Minutes > 59 || Seconds < 0 || Seconds > 61)
1782 if (Meridian == MER24) {
1783 if (Hours < 0 || Hours > 23)
1787 if (Hours < 1 || Hours > 12)
1791 if (Meridian == MERpm)
1794 return (Hours * 60L + Minutes) * 60L + Seconds;
1799 Convert(time_t Month, time_t Day, time_t Year,
1800 time_t Hours, time_t Minutes, time_t Seconds,
1801 MERIDIAN Meridian, DSTMODE dst)
1803 static int DaysNormal[13] = {
1804 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
1806 static int DaysLeap[13] = {
1807 0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
1809 static int LeapYears[] = {
1810 1972, 1976, 1980, 1984, 1988, 1992, 1996,
1811 2000, 2004, 2008, 2012, 2016, 2020, 2024, 2028, 2032, 2036
1815 register time_t Julian;
1825 for (mp = DaysNormal, yp = LeapYears; yp < ENDOF(LeapYears); yp++)
1830 if (Year < EPOCH || Year > END_OF_TIME
1831 || Month < 1 || Month > 12
1832 /* NOSTRICT *//* conversion from long may lose accuracy */
1833 || Day < 1 || Day > mp[(int)Month])
1836 Julian = Day - 1 + (Year - EPOCH) * 365;
1837 for (yp = LeapYears; yp < ENDOF(LeapYears); yp++, Julian++)
1840 for (i = 1; i < Month; i++)
1842 Julian *= SECSPERDAY;
1843 Julian += yyTimezone * 60L;
1844 if ((tod = ToSeconds(Hours, Minutes, Seconds, Meridian)) < 0)
1848 if (dst == DSTon || (dst == DSTmaybe && localtime(&tod)->tm_isdst))
1849 Julian -= DST_OFFSET * 60L * 60L;
1855 DSTcorrect(time_t Start, time_t Future)
1860 StartDay = (localtime(&Start)->tm_hour + 1) % 24;
1861 FutureDay = (localtime(&Future)->tm_hour + 1) % 24;
1862 return (Future - Start) + (StartDay - FutureDay) * DST_OFFSET * 60L * 60L;
1867 RelativeMonth(time_t Start, time_t RelMonth)
1873 tm = localtime(&Start);
1874 Month = 12 * tm->tm_year + tm->tm_mon + RelMonth;
1876 Month = Month % 12 + 1;
1877 return DSTcorrect(Start,
1878 Convert(Month, (time_t)tm->tm_mday, Year,
1879 (time_t)tm->tm_hour, (time_t)tm->tm_min, (time_t)tm->tm_sec,
1885 LookupWord(char *buff, register int length)
1895 /* See if we have an abbreviation for a month. */
1896 if (length == 3 || (length == 4 && p[3] == '.'))
1897 for (tp = MonthDayTable; tp < ENDOF(MonthDayTable); tp++) {
1899 if (c == q[0] && p[1] == q[1] && p[2] == q[2]) {
1900 yylval.Number = tp->value;
1905 for (tp = MonthDayTable; tp < ENDOF(MonthDayTable); tp++)
1906 if (c == tp->name[0] && strcmp(p, tp->name) == 0) {
1907 yylval.Number = tp->value;
1911 /* Try for a timezone. */
1912 for (tp = TimezoneTable; tp < ENDOF(TimezoneTable); tp++)
1913 if (c == tp->name[0] && p[1] == tp->name[1]
1914 && strcmp(p, tp->name) == 0) {
1915 yylval.Number = tp->value;
1919 /* Try the units table. */
1920 for (tp = UnitsTable; tp < ENDOF(UnitsTable); tp++)
1921 if (c == tp->name[0] && strcmp(p, tp->name) == 0) {
1922 yylval.Number = tp->value;
1926 /* Strip off any plural and try the units table again. */
1927 if (--length > 0 && p[length] == 's') {
1929 for (tp = UnitsTable; tp < ENDOF(UnitsTable); tp++)
1930 if (c == tp->name[0] && strcmp(p, tp->name) == 0) {
1932 yylval.Number = tp->value;
1939 /* Drop out any periods. */
1940 for (p = buff, q = (char*)buff; *q; q++)
1945 /* Try the meridians. */
1946 if (buff[1] == 'm' && buff[2] == '\0') {
1947 if (buff[0] == 'a') {
1948 yylval.Meridian = MERam;
1951 if (buff[0] == 'p') {
1952 yylval.Meridian = MERpm;
1957 /* If we saw any periods, try the timezones again. */
1958 if (p - buff != length) {
1960 for (p = buff, tp = TimezoneTable; tp < ENDOF(TimezoneTable); tp++)
1961 if (c == tp->name[0] && p[1] == tp->name[1]
1962 && strcmp(p, tp->name) == 0) {
1963 yylval.Number = tp->value;
1968 /* Unknown word -- assume GMT timezone. */
1982 register int nesting;
1985 /* Get first character after the whitespace. */
1987 while (isspace(*yyInput))
1991 /* Ignore RFC 822 comments, typically time zone names. */
1994 for (nesting = 1; (c = *++yyInput) != RPAREN || --nesting; )
1997 else if (!IS7BIT(c) || c == '\0' || c == '\r'
1998 || (c == '\\' && ((c = *++yyInput) == '\0' || !IS7BIT(c))))
1999 /* Lexical error: bad comment. */
2005 if (isdigit(c) || c == '-' || c == '+') {
2006 if (c == '-' || c == '+') {
2007 sign = c == '-' ? -1 : 1;
2009 if (!isdigit(*yyInput))
2010 /* Skip the plus or minus sign. */
2015 for (i = 0; (c = *yyInput++) != '\0' && isdigit(c); )
2016 i = 10 * i + c - '0';
2018 yylval.Number = sign < 0 ? -i : i;
2019 return sign ? tSNUMBER : tUNUMBER;
2024 for (p = buff; (c = *yyInput++) == '.' || isalpha(c); )
2025 if (p < &buff[sizeof buff - 1])
2026 *p++ = isupper(c) ? tolower(c) : c;
2029 return LookupWord(buff, p - buff);
2040 extern int date_parse(void);
2049 yyDSTmode = DSTmaybe;
2060 if (date_parse() || yyHaveTime > 1 || yyHaveDate > 1)
2063 if (yyHaveDate || yyHaveTime) {
2064 Start = Convert(yyMonth, yyDay, yyYear, yyHour, yyMinutes, yySeconds,
2065 yyMeridian, yyDSTmode);
2072 Start += yyRelSeconds;
2074 Start += RelativeMonth(Start, yyRelMonth);
2076 /* Have to do *something* with a legitimate -1 so it's distinguishable
2077 * from the error return value. (Alternately could set errno on error.) */
2078 return Start == -1 ? 0 : Start;
2086 #endif /* YYDEBUG */
2090 main(int ac, char *av[])
2097 #endif /* YYDEBUG */
2099 (void)printf("Enter date, or blank line to exit.\n\t> ");
2101 (void)printf("\t> ");
2102 (void)fflush(stdout);
2103 if (fgets(buff, sizeof buff, stdin) == NULL || buff[0] == '\n')
2106 if (strcmp(buff, "yydebug") == 0) {
2108 printf("yydebug = %s\n", yydebug ? "on" : "off");
2111 #endif /* YYDEBUG */
2112 d = parsedate(buff, (TIMEINFO *)NULL);
2114 (void)printf("Bad format - couldn't convert.\n");
2116 (void)printf("%s", ctime(&d));