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. */
84 ** Originally written by Steven M. Bellovin <smb@research.att.com> while
85 ** at the University of North Carolina at Chapel Hill. Later tweaked by
86 ** a couple of people on Usenet. Completely overhauled by Rich $alz
87 ** <rsalz@osf.org> and Jim Berets <jberets@bbn.com> in August, 1990.
88 ** Further revised (removed obsolete constructs and cleaned up timezone
89 ** names) in August, 1991, by Rich. Paul Eggert <eggert@twinsun.com>
90 ** helped in September, 1992. Art Cancro <ajc@uncensored.citadel.org> cleaned
91 ** it up for ANSI C in December, 1999.
93 ** This grammar has six shift/reduce conflicts.
95 ** This code is in the public domain and has no copyright.
97 /* SUPPRESS 530 *//* Empty body for statement */
98 /* SUPPRESS 593 on yyerrlab *//* Label was not used */
99 /* SUPPRESS 593 on yynewstate *//* Label was not used */
100 /* SUPPRESS 595 on yypvt *//* Automatic variable may be used before set */
106 #include <sys/types.h>
111 #include "parsedate.h"
115 #define yyparse date_parse
116 #define yylex date_lex
117 #define yyerror date_error
120 /* See the LeapYears table in Convert. */
122 #define END_OF_TIME 2038
123 /* Constants for general time calculations. */
125 #define SECSPERDAY (24L * 60L * 60L)
126 /* Readability for TABLE stuff. */
127 #define HOUR(x) (x * 60)
131 #define IS7BIT(x) ((unsigned int)(x) < 0200)
133 #define SIZEOF(array) ((int)(sizeof array / sizeof array[0]))
134 #define ENDOF(array) (&array[SIZEOF(array)])
138 ** An entry in the lexical lookup table.
140 typedef struct _TABLE {
147 ** Daylight-savings mode: on, off, or not yet known.
149 typedef enum _DSTMODE {
150 DSTon, DSToff, DSTmaybe
154 ** Meridian: am, pm, or 24-hour style.
156 typedef enum _MERIDIAN {
162 ** Global variables. We could get rid of most of them by using a yacc
163 ** union, but this is more efficient. (This routine predates the
164 ** yacc %union construct.)
166 static char *yyInput;
167 static DSTMODE yyDSTmode;
168 static int yyHaveDate;
169 static int yyHaveRel;
170 static int yyHaveTime;
171 static time_t yyTimezone;
173 static time_t yyHour;
174 static time_t yyMinutes;
175 static time_t yyMonth;
176 static time_t yySeconds;
177 static time_t yyYear;
178 static MERIDIAN yyMeridian;
179 static time_t yyRelMonth;
180 static time_t yyRelSeconds;
183 static void date_error(char *);
186 /* Enabling traces. */
191 /* Enabling verbose error messages. */
192 #ifdef YYERROR_VERBOSE
193 # undef YYERROR_VERBOSE
194 # define YYERROR_VERBOSE 1
196 # define YYERROR_VERBOSE 0
199 #if ! defined (YYSTYPE) && ! defined (YYSTYPE_IS_DECLARED)
200 typedef union YYSTYPE {
202 enum _MERIDIAN Meridian;
204 /* Line 191 of yacc.c. */
206 # define yystype YYSTYPE /* obsolescent; will be withdrawn */
207 # define YYSTYPE_IS_DECLARED 1
208 # define YYSTYPE_IS_TRIVIAL 1
213 /* Copy the second part of user declarations. */
216 /* Line 214 of yacc.c. */
219 #if ! defined (yyoverflow) || YYERROR_VERBOSE
221 /* The parser invokes alloca or malloc; define the necessary symbols. */
223 # if YYSTACK_USE_ALLOCA
224 # define YYSTACK_ALLOC alloca
226 # ifndef YYSTACK_USE_ALLOCA
227 # if defined (alloca) || defined (_ALLOCA_H)
228 # define YYSTACK_ALLOC alloca
231 # define YYSTACK_ALLOC __builtin_alloca
237 # ifdef YYSTACK_ALLOC
238 /* Pacify GCC's `empty if-body' warning. */
239 # define YYSTACK_FREE(Ptr) do { /* empty */; } while (0)
241 # if defined (__STDC__) || defined (__cplusplus)
242 # include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
243 # define YYSIZE_T size_t
245 # define YYSTACK_ALLOC malloc
246 # define YYSTACK_FREE free
248 #endif /* ! defined (yyoverflow) || YYERROR_VERBOSE */
251 #if (! defined (yyoverflow) \
252 && (! defined (__cplusplus) \
253 || (YYSTYPE_IS_TRIVIAL)))
255 /* A type that is properly aligned for any stack member. */
262 /* The size of the maximum gap between one aligned stack and the next. */
263 # define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1)
265 /* The size of an array large to enough to hold all stacks, each with
267 # define YYSTACK_BYTES(N) \
268 ((N) * (sizeof (short) + sizeof (YYSTYPE)) \
269 + YYSTACK_GAP_MAXIMUM)
271 /* Copy COUNT objects from FROM to TO. The source and destination do
275 # define YYCOPY(To, From, Count) \
276 __builtin_memcpy (To, From, (Count) * sizeof (*(From)))
278 # define YYCOPY(To, From, Count) \
281 register YYSIZE_T yyi; \
282 for (yyi = 0; yyi < (Count); yyi++) \
283 (To)[yyi] = (From)[yyi]; \
289 /* Relocate STACK from its old location to the new one. The
290 local variables YYSIZE and YYSTACKSIZE give the old and new number of
291 elements in the stack, and YYPTR gives the new location of the
292 stack. Advance YYPTR to a properly aligned location for the next
294 # define YYSTACK_RELOCATE(Stack) \
297 YYSIZE_T yynewbytes; \
298 YYCOPY (&yyptr->Stack, Stack, yysize); \
299 Stack = &yyptr->Stack; \
300 yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \
301 yyptr += yynewbytes / sizeof (*yyptr); \
307 #if defined (__STDC__) || defined (__cplusplus)
308 typedef signed char yysigned_char;
310 typedef short yysigned_char;
313 /* YYFINAL -- State number of the termination state. */
315 /* YYLAST -- Last index in YYTABLE. */
318 /* YYNTOKENS -- Number of terminals. */
320 /* YYNNTS -- Number of nonterminals. */
322 /* YYNRULES -- Number of rules. */
324 /* YYNRULES -- Number of states. */
327 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
329 #define YYMAXUTOK 266
331 #define YYTRANSLATE(YYX) \
332 ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
334 /* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */
335 static const unsigned char yytranslate[] =
337 0, 2, 2, 2, 2, 2, 2, 2, 2, 2,
338 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
339 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
340 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
341 2, 2, 2, 2, 14, 2, 2, 13, 2, 2,
342 2, 2, 2, 2, 2, 2, 2, 2, 12, 2,
343 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
344 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
345 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
346 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
347 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
348 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
349 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
350 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
351 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
352 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
353 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
354 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
355 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
356 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
357 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
358 2, 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, 2, 2, 1, 2, 3, 4,
363 5, 6, 7, 8, 9, 10, 11
367 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
369 static const unsigned char yyprhs[] =
371 0, 0, 3, 4, 7, 9, 12, 14, 16, 19,
372 24, 29, 36, 43, 45, 47, 50, 52, 54, 58,
373 64, 67, 72, 75, 79, 85, 88, 91, 94, 97,
377 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
378 static const yysigned_char yyrhs[] =
380 16, 0, -1, -1, 16, 17, -1, 18, -1, 18,
381 19, -1, 21, -1, 22, -1, 10, 23, -1, 10,
382 12, 10, 23, -1, 10, 12, 10, 20, -1, 10,
383 12, 10, 12, 10, 23, -1, 10, 12, 10, 12,
384 10, 20, -1, 11, -1, 4, -1, 11, 20, -1,
385 20, -1, 9, -1, 10, 13, 10, -1, 10, 13,
386 10, 13, 10, -1, 6, 10, -1, 6, 10, 14,
387 10, -1, 10, 6, -1, 10, 6, 10, -1, 3,
388 14, 10, 6, 10, -1, 9, 8, -1, 10, 8,
389 -1, 9, 7, -1, 10, 7, -1, -1, 5, -1
392 /* YYRLINE[YYN] -- source line where rule number YYN was defined. */
393 static const unsigned short yyrline[] =
395 0, 143, 143, 144, 147, 156, 160, 163, 168, 180,
396 186, 193, 199, 209, 213, 217, 225, 231, 252, 256,
397 268, 272, 277, 281, 286, 293, 296, 299, 302, 307,
402 #if YYDEBUG || YYERROR_VERBOSE
403 /* YYTNME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
404 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
405 static const char *const yytname[] =
407 "$end", "error", "$undefined", "tDAY", "tDAYZONE", "tMERIDIAN", "tMONTH",
408 "tMONTH_UNIT", "tSEC_UNIT", "tSNUMBER", "tUNUMBER", "tZONE", "':'",
409 "'/'", "','", "$accept", "spec", "item", "time", "zone", "numzone",
410 "date", "rel", "o_merid", 0
415 /* YYTOKNUM[YYLEX-NUM] -- Internal token number corresponding to
417 static const unsigned short yytoknum[] =
419 0, 256, 257, 258, 259, 260, 261, 262, 263, 264,
424 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
425 static const unsigned char yyr1[] =
427 0, 15, 16, 16, 17, 17, 17, 17, 18, 18,
428 18, 18, 18, 19, 19, 19, 19, 20, 21, 21,
429 21, 21, 21, 21, 21, 22, 22, 22, 22, 23,
433 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
434 static const unsigned char yyr2[] =
436 0, 2, 0, 2, 1, 2, 1, 1, 2, 4,
437 4, 6, 6, 1, 1, 2, 1, 1, 3, 5,
438 2, 4, 2, 3, 5, 2, 2, 2, 2, 0,
442 /* YYDEFACT[STATE-NAME] -- Default rule to reduce with in state
443 STATE-NUM when YYTABLE doesn't specify something else to do. Zero
444 means the default is an error. */
445 static const unsigned char yydefact[] =
447 2, 0, 1, 0, 0, 0, 29, 3, 4, 6,
448 7, 0, 20, 27, 25, 30, 22, 28, 26, 0,
449 0, 8, 14, 17, 13, 5, 16, 0, 0, 23,
450 29, 18, 15, 0, 21, 0, 10, 9, 0, 24,
454 /* YYDEFGOTO[NTERM-NUM]. */
455 static const yysigned_char yydefgoto[] =
457 -1, 1, 7, 8, 25, 26, 9, 10, 21
460 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
462 #define YYPACT_NINF -29
463 static const yysigned_char yypact[] =
465 -29, 1, -29, -11, 11, 20, 12, -29, 4, -29,
466 -29, 13, 16, -29, -29, -29, 21, -29, -29, 22,
467 23, -29, -29, -29, 5, -29, -29, 28, 25, -29,
468 17, 24, -29, 26, -29, 29, -29, -29, 30, -29,
472 /* YYPGOTO[NTERM-NUM]. */
473 static const yysigned_char yypgoto[] =
475 -29, -29, -29, -29, -29, -24, -29, -29, -28
478 /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
479 positive, shift that token. If negative, reduce the rule which
480 number is the opposite. If zero, do what YYDEFACT says.
481 If YYTABLE_NINF, syntax error. */
482 #define YYTABLE_NINF -1
483 static const unsigned char yytable[] =
485 32, 2, 37, 11, 3, 15, 36, 4, 22, 23,
486 5, 6, 43, 23, 23, 24, 42, 15, 16, 17,
487 18, 12, 15, 27, 19, 20, 23, 13, 14, 35,
488 28, 29, 30, 31, 33, 34, 39, 38, 0, 40,
492 static const yysigned_char yycheck[] =
494 24, 0, 30, 14, 3, 5, 30, 6, 4, 9,
495 9, 10, 40, 9, 9, 11, 40, 5, 6, 7,
496 8, 10, 5, 10, 12, 13, 9, 7, 8, 12,
497 14, 10, 10, 10, 6, 10, 10, 13, -1, 10,
501 /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
502 symbol of state STATE-NUM. */
503 static const unsigned char yystos[] =
505 0, 16, 0, 3, 6, 9, 10, 17, 18, 21,
506 22, 14, 10, 7, 8, 5, 6, 7, 8, 12,
507 13, 23, 4, 9, 11, 19, 20, 10, 14, 10,
508 10, 10, 20, 6, 10, 12, 20, 23, 13, 10,
512 #if ! defined (YYSIZE_T) && defined (__SIZE_TYPE__)
513 # define YYSIZE_T __SIZE_TYPE__
515 #if ! defined (YYSIZE_T) && defined (size_t)
516 # define YYSIZE_T size_t
518 #if ! defined (YYSIZE_T)
519 # if defined (__STDC__) || defined (__cplusplus)
520 # include <stddef.h> /* INFRINGES ON USER NAME SPACE */
521 # define YYSIZE_T size_t
524 #if ! defined (YYSIZE_T)
525 # define YYSIZE_T unsigned int
528 #define yyerrok (yyerrstatus = 0)
529 #define yyclearin (yychar = YYEMPTY)
533 #define YYACCEPT goto yyacceptlab
534 #define YYABORT goto yyabortlab
535 #define YYERROR goto yyerrlab1
538 /* Like YYERROR except do call yyerror. This remains here temporarily
539 to ease the transition to the new meaning of YYERROR, for GCC.
540 Once GCC version 2 has supplanted version 1, this can go. */
542 #define YYFAIL goto yyerrlab
544 #define YYRECOVERING() (!!yyerrstatus)
546 #define YYBACKUP(Token, Value) \
548 if (yychar == YYEMPTY && yylen == 1) \
552 yytoken = YYTRANSLATE (yychar); \
558 yyerror ("syntax error: cannot back up");\
564 #define YYERRCODE 256
566 /* YYLLOC_DEFAULT -- Compute the default location (before the actions
569 #ifndef YYLLOC_DEFAULT
570 # define YYLLOC_DEFAULT(Current, Rhs, N) \
571 Current.first_line = Rhs[1].first_line; \
572 Current.first_column = Rhs[1].first_column; \
573 Current.last_line = Rhs[N].last_line; \
574 Current.last_column = Rhs[N].last_column;
577 /* YYLEX -- calling `yylex' with the right arguments. */
580 # define YYLEX yylex (YYLEX_PARAM)
582 # define YYLEX yylex ()
585 /* Enable debugging if requested. */
589 # include <stdio.h> /* INFRINGES ON USER NAME SPACE */
590 # define YYFPRINTF fprintf
593 # define YYDPRINTF(Args) \
599 # define YYDSYMPRINT(Args) \
605 # define YYDSYMPRINTF(Title, Token, Value, Location) \
609 YYFPRINTF (stderr, "%s ", Title); \
610 yysymprint (stderr, \
612 YYFPRINTF (stderr, "\n"); \
616 /*------------------------------------------------------------------.
617 | yy_stack_print -- Print the state stack from its BOTTOM up to its |
619 `------------------------------------------------------------------*/
621 #if defined (__STDC__) || defined (__cplusplus)
623 yy_stack_print (short *bottom, short *top)
626 yy_stack_print (bottom, top)
631 YYFPRINTF (stderr, "Stack now");
632 for (/* Nothing. */; bottom <= top; ++bottom)
633 YYFPRINTF (stderr, " %d", *bottom);
634 YYFPRINTF (stderr, "\n");
637 # define YY_STACK_PRINT(Bottom, Top) \
640 yy_stack_print ((Bottom), (Top)); \
644 /*------------------------------------------------.
645 | Report that the YYRULE is going to be reduced. |
646 `------------------------------------------------*/
648 #if defined (__STDC__) || defined (__cplusplus)
650 yy_reduce_print (int yyrule)
653 yy_reduce_print (yyrule)
658 unsigned int yylineno = yyrline[yyrule];
659 YYFPRINTF (stderr, "Reducing stack by rule %d (line %u), ",
660 yyrule - 1, yylineno);
661 /* Print the symbols being reduced, and their result. */
662 for (yyi = yyprhs[yyrule]; 0 <= yyrhs[yyi]; yyi++)
663 YYFPRINTF (stderr, "%s ", yytname [yyrhs[yyi]]);
664 YYFPRINTF (stderr, "-> %s\n", yytname [yyr1[yyrule]]);
667 # define YY_REDUCE_PRINT(Rule) \
670 yy_reduce_print (Rule); \
673 /* Nonzero means print parse trace. It is left uninitialized so that
674 multiple parsers can coexist. */
677 # define YYDPRINTF(Args)
678 # define YYDSYMPRINT(Args)
679 # define YYDSYMPRINTF(Title, Token, Value, Location)
680 # define YY_STACK_PRINT(Bottom, Top)
681 # define YY_REDUCE_PRINT(Rule)
682 #endif /* !YYDEBUG */
685 /* YYINITDEPTH -- initial size of the parser's stacks. */
687 # define YYINITDEPTH 200
690 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
691 if the built-in stack extension method is used).
693 Do not make this value too large; the results are undefined if
694 SIZE_MAX < YYSTACK_BYTES (YYMAXDEPTH)
695 evaluated with infinite-precision integer arithmetic. */
702 # define YYMAXDEPTH 10000
710 # if defined (__GLIBC__) && defined (_STRING_H)
711 # define yystrlen strlen
713 /* Return the length of YYSTR. */
715 # if defined (__STDC__) || defined (__cplusplus)
716 yystrlen (const char *yystr)
722 register const char *yys = yystr;
724 while (*yys++ != '\0')
727 return yys - yystr - 1;
733 # if defined (__GLIBC__) && defined (_STRING_H) && defined (_GNU_SOURCE)
734 # define yystpcpy stpcpy
736 /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
739 # if defined (__STDC__) || defined (__cplusplus)
740 yystpcpy (char *yydest, const char *yysrc)
742 yystpcpy (yydest, yysrc)
747 register char *yyd = yydest;
748 register const char *yys = yysrc;
750 while ((*yyd++ = *yys++) != '\0')
758 #endif /* !YYERROR_VERBOSE */
763 /*--------------------------------.
764 | Print this symbol on YYOUTPUT. |
765 `--------------------------------*/
767 #if defined (__STDC__) || defined (__cplusplus)
769 yysymprint (FILE *yyoutput, int yytype, YYSTYPE *yyvaluep)
772 yysymprint (yyoutput, yytype, yyvaluep)
778 /* Pacify ``unused variable'' warnings. */
781 if (yytype < YYNTOKENS)
783 YYFPRINTF (yyoutput, "token %s (", yytname[yytype]);
785 YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep);
789 YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]);
796 YYFPRINTF (yyoutput, ")");
799 #endif /* ! YYDEBUG */
800 /*-----------------------------------------------.
801 | Release the memory associated to this symbol. |
802 `-----------------------------------------------*/
804 #if defined (__STDC__) || defined (__cplusplus)
806 yydestruct (int yytype, YYSTYPE *yyvaluep)
809 yydestruct (yytype, yyvaluep)
814 /* Pacify ``unused variable'' warnings. */
826 /* Prevent warnings from -Wmissing-prototypes. */
829 # if defined (__STDC__) || defined (__cplusplus)
830 int yyparse (void *YYPARSE_PARAM);
834 #else /* ! YYPARSE_PARAM */
835 #if defined (__STDC__) || defined (__cplusplus)
840 #endif /* ! YYPARSE_PARAM */
844 /* The lookahead symbol. */
847 /* The semantic value of the lookahead symbol. */
850 /* Number of syntax errors so far. */
860 # if defined (__STDC__) || defined (__cplusplus)
861 int yyparse (void *YYPARSE_PARAM)
863 int yyparse (YYPARSE_PARAM)
866 #else /* ! YYPARSE_PARAM */
867 #if defined (__STDC__) || defined (__cplusplus)
878 register int yystate;
881 /* Number of tokens to shift before error messages enabled. */
883 /* Lookahead token as an internal (translated) token number. */
886 /* Three stacks and their tools:
887 `yyss': related to states,
888 `yyvs': related to semantic values,
889 `yyls': related to locations.
891 Refer to the stacks thru separate pointers, to allow yyoverflow
892 to reallocate them elsewhere. */
894 /* The state stack. */
895 short yyssa[YYINITDEPTH];
897 register short *yyssp;
899 /* The semantic value stack. */
900 YYSTYPE yyvsa[YYINITDEPTH];
901 YYSTYPE *yyvs = yyvsa;
902 register YYSTYPE *yyvsp;
906 #define YYPOPSTACK (yyvsp--, yyssp--)
908 YYSIZE_T yystacksize = YYINITDEPTH;
910 /* The variables used to return semantic value and location from the
915 /* When reducing, the number of symbols on the RHS of the reduced
919 YYDPRINTF ((stderr, "Starting parse\n"));
924 yychar = YYEMPTY; /* Cause a token to be read. */
926 /* Initialize stack pointers.
927 Waste one element of value and location stack
928 so that they stay on the same level as the state stack.
929 The wasted elements are never initialized. */
936 /*------------------------------------------------------------.
937 | yynewstate -- Push a new state, which is found in yystate. |
938 `------------------------------------------------------------*/
940 /* In all cases, when you get here, the value and location stacks
941 have just been pushed. so pushing a state here evens the stacks.
948 if (yyss + yystacksize - 1 <= yyssp)
950 /* Get the current used size of the three stacks, in elements. */
951 YYSIZE_T yysize = yyssp - yyss + 1;
955 /* Give user a chance to reallocate the stack. Use copies of
956 these so that the &'s don't force the real ones into
958 YYSTYPE *yyvs1 = yyvs;
962 /* Each stack pointer address is followed by the size of the
963 data in use in that stack, in bytes. This used to be a
964 conditional around just the two extra args, but that might
965 be undefined if yyoverflow is a macro. */
966 yyoverflow ("parser stack overflow",
967 &yyss1, yysize * sizeof (*yyssp),
968 &yyvs1, yysize * sizeof (*yyvsp),
975 #else /* no yyoverflow */
976 # ifndef YYSTACK_RELOCATE
979 /* Extend the stack our own way. */
980 if (YYMAXDEPTH <= yystacksize)
983 if (YYMAXDEPTH < yystacksize)
984 yystacksize = YYMAXDEPTH;
988 union yyalloc *yyptr =
989 (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
992 YYSTACK_RELOCATE (yyss);
993 YYSTACK_RELOCATE (yyvs);
995 # undef YYSTACK_RELOCATE
997 YYSTACK_FREE (yyss1);
1000 #endif /* no yyoverflow */
1002 yyssp = yyss + yysize - 1;
1003 yyvsp = yyvs + yysize - 1;
1006 YYDPRINTF ((stderr, "Stack size increased to %lu\n",
1007 (unsigned long int) yystacksize));
1009 if (yyss + yystacksize - 1 <= yyssp)
1013 YYDPRINTF ((stderr, "Entering state %d\n", yystate));
1022 /* Do appropriate processing given the current state. */
1023 /* Read a lookahead token if we need one and don't already have one. */
1026 /* First try to decide what to do without reference to lookahead token. */
1028 yyn = yypact[yystate];
1029 if (yyn == YYPACT_NINF)
1032 /* Not known => get a lookahead token if don't already have one. */
1034 /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol. */
1035 if (yychar == YYEMPTY)
1037 YYDPRINTF ((stderr, "Reading a token: "));
1041 if (yychar <= YYEOF)
1043 yychar = yytoken = YYEOF;
1044 YYDPRINTF ((stderr, "Now at end of input.\n"));
1048 yytoken = YYTRANSLATE (yychar);
1049 YYDSYMPRINTF ("Next token is", yytoken, &yylval, &yylloc);
1052 /* If the proper action on seeing token YYTOKEN is to reduce or to
1053 detect an error, take that action. */
1055 if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
1060 if (yyn == 0 || yyn == YYTABLE_NINF)
1069 /* Shift the lookahead token. */
1070 YYDPRINTF ((stderr, "Shifting token %s, ", yytname[yytoken]));
1072 /* Discard the token being shifted unless it is eof. */
1073 if (yychar != YYEOF)
1079 /* Count tokens shifted since error; after three, turn off error
1088 /*-----------------------------------------------------------.
1089 | yydefault -- do the default action for the current state. |
1090 `-----------------------------------------------------------*/
1092 yyn = yydefact[yystate];
1098 /*-----------------------------.
1099 | yyreduce -- Do a reduction. |
1100 `-----------------------------*/
1102 /* yyn is the number of a rule to reduce with. */
1105 /* If YYLEN is nonzero, implement the default value of the action:
1108 Otherwise, the following line sets YYVAL to garbage.
1109 This behavior is undocumented and Bison
1110 users should not rely upon it. Assigning to YYVAL
1111 unconditionally makes the parser a bit smaller, and it avoids a
1112 GCC warning that YYVAL may be used uninitialized. */
1113 yyval = yyvsp[1-yylen];
1116 YY_REDUCE_PRINT (yyn);
1123 /* I am compulsive about lint natterings... */
1124 if (yyHaveTime == -1) {
1134 yyTimezone = yyvsp[0].Number;
1152 if (yyvsp[-1].Number < 100) {
1153 yyHour = yyvsp[-1].Number;
1157 yyHour = yyvsp[-1].Number / 100;
1158 yyMinutes = yyvsp[-1].Number % 100;
1161 yyMeridian = yyvsp[0].Meridian;
1167 yyHour = yyvsp[-3].Number;
1168 yyMinutes = yyvsp[-1].Number;
1170 yyMeridian = yyvsp[0].Meridian;
1176 yyHour = yyvsp[-3].Number;
1177 yyMinutes = yyvsp[-1].Number;
1178 yyTimezone = yyvsp[0].Number;
1186 yyHour = yyvsp[-5].Number;
1187 yyMinutes = yyvsp[-3].Number;
1188 yySeconds = yyvsp[-1].Number;
1189 yyMeridian = yyvsp[0].Meridian;
1195 yyHour = yyvsp[-5].Number;
1196 yyMinutes = yyvsp[-3].Number;
1197 yySeconds = yyvsp[-1].Number;
1198 yyTimezone = yyvsp[0].Number;
1206 yyval.Number = yyvsp[0].Number;
1213 yyval.Number = yyvsp[0].Number;
1220 /* Only allow "GMT+300" and "GMT-0800" */
1221 if (yyvsp[-1].Number != 0) {
1224 yyval.Number = yyvsp[0].Number;
1231 yyval.Number = yyvsp[0].Number;
1240 /* Unix and GMT and numeric timezones -- a little confusing. */
1241 if (yyvsp[0].Number < 0) {
1242 /* Don't work with negative modulus. */
1243 yyvsp[0].Number = -yyvsp[0].Number;
1244 if (yyvsp[0].Number > 9999 || (i = yyvsp[0].Number % 100) >= 60) {
1247 yyval.Number = (yyvsp[0].Number / 100) * 60 + i;
1250 if (yyvsp[0].Number > 9999 || (i = yyvsp[0].Number % 100) >= 60) {
1253 yyval.Number = -((yyvsp[0].Number / 100) * 60 + i);
1260 yyMonth = yyvsp[-2].Number;
1261 yyDay = yyvsp[0].Number;
1267 if (yyvsp[-4].Number > 100) {
1268 yyYear = yyvsp[-4].Number;
1269 yyMonth = yyvsp[-2].Number;
1270 yyDay = yyvsp[0].Number;
1273 yyMonth = yyvsp[-4].Number;
1274 yyDay = yyvsp[-2].Number;
1275 yyYear = yyvsp[0].Number;
1282 yyMonth = yyvsp[-1].Number;
1283 yyDay = yyvsp[0].Number;
1289 yyMonth = yyvsp[-3].Number;
1290 yyDay = yyvsp[-2].Number;
1291 yyYear = yyvsp[0].Number;
1297 yyDay = yyvsp[-1].Number;
1298 yyMonth = yyvsp[0].Number;
1304 yyDay = yyvsp[-2].Number;
1305 yyMonth = yyvsp[-1].Number;
1306 yyYear = yyvsp[0].Number;
1312 yyDay = yyvsp[-2].Number;
1313 yyMonth = yyvsp[-1].Number;
1314 yyYear = yyvsp[0].Number;
1320 yyRelSeconds += yyvsp[-1].Number * yyvsp[0].Number;
1326 yyRelSeconds += yyvsp[-1].Number * yyvsp[0].Number;
1332 yyRelMonth += yyvsp[-1].Number * yyvsp[0].Number;
1338 yyRelMonth += yyvsp[-1].Number * yyvsp[0].Number;
1344 yyval.Meridian = MER24;
1350 yyval.Meridian = yyvsp[0].Meridian;
1357 /* Line 999 of yacc.c. */
1358 #line 1410 "y.tab.c"
1364 YY_STACK_PRINT (yyss, yyssp);
1369 /* Now `shift' the result of the reduction. Determine what state
1370 that goes to, based on the state we popped back to and the rule
1371 number reduced by. */
1375 yystate = yypgoto[yyn - YYNTOKENS] + *yyssp;
1376 if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp)
1377 yystate = yytable[yystate];
1379 yystate = yydefgoto[yyn - YYNTOKENS];
1384 /*------------------------------------.
1385 | yyerrlab -- here on detecting error |
1386 `------------------------------------*/
1388 /* If not already recovering from an error, report this error. */
1393 yyn = yypact[yystate];
1395 if (YYPACT_NINF < yyn && yyn < YYLAST)
1397 YYSIZE_T yysize = 0;
1398 int yytype = YYTRANSLATE (yychar);
1403 /* Start YYX at -YYN if negative to avoid negative indexes in
1405 for (yyx = yyn < 0 ? -yyn : 0;
1406 yyx < (int) (sizeof (yytname) / sizeof (char *)); yyx++)
1407 if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)
1408 yysize += yystrlen (yytname[yyx]) + 15, yycount++;
1409 yysize += yystrlen ("syntax error, unexpected ") + 1;
1410 yysize += yystrlen (yytname[yytype]);
1411 yymsg = (char *) YYSTACK_ALLOC (yysize);
1414 char *yyp = yystpcpy (yymsg, "syntax error, unexpected ");
1415 yyp = yystpcpy (yyp, yytname[yytype]);
1420 for (yyx = yyn < 0 ? -yyn : 0;
1421 yyx < (int) (sizeof (yytname) / sizeof (char *));
1423 if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)
1425 const char *yyq = ! yycount ? ", expecting " : " or ";
1426 yyp = yystpcpy (yyp, yyq);
1427 yyp = yystpcpy (yyp, yytname[yyx]);
1432 YYSTACK_FREE (yymsg);
1435 yyerror ("syntax error; also virtual memory exhausted");
1438 #endif /* YYERROR_VERBOSE */
1439 yyerror ("syntax error");
1444 if (yyerrstatus == 3)
1446 /* If just tried and failed to reuse lookahead token after an
1447 error, discard it. */
1449 /* Return failure if at end of input. */
1450 if (yychar == YYEOF)
1452 /* Pop the error token. */
1454 /* Pop the rest of the stack. */
1455 while (yyss < yyssp)
1457 YYDSYMPRINTF ("Error: popping", yystos[*yyssp], yyvsp, yylsp);
1458 yydestruct (yystos[*yyssp], yyvsp);
1464 YYDSYMPRINTF ("Error: discarding", yytoken, &yylval, &yylloc);
1465 yydestruct (yytoken, &yylval);
1470 /* Else will try to reuse lookahead token after shifting the error
1475 /*----------------------------------------------------.
1476 | yyerrlab1 -- error raised explicitly by an action. |
1477 `----------------------------------------------------*/
1479 yyerrstatus = 3; /* Each real token shifted decrements this. */
1483 yyn = yypact[yystate];
1484 if (yyn != YYPACT_NINF)
1487 if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
1495 /* Pop the current state because it cannot handle the error token. */
1499 YYDSYMPRINTF ("Error: popping", yystos[*yyssp], yyvsp, yylsp);
1500 yydestruct (yystos[yystate], yyvsp);
1504 YY_STACK_PRINT (yyss, yyssp);
1510 YYDPRINTF ((stderr, "Shifting error token, "));
1519 /*-------------------------------------.
1520 | yyacceptlab -- YYACCEPT comes here. |
1521 `-------------------------------------*/
1526 /*-----------------------------------.
1527 | yyabortlab -- YYABORT comes here. |
1528 `-----------------------------------*/
1534 /*----------------------------------------------.
1535 | yyoverflowlab -- parser overflow comes here. |
1536 `----------------------------------------------*/
1538 yyerror ("parser stack overflow");
1546 YYSTACK_FREE (yyss);
1554 /* Month and day table. */
1555 static TABLE MonthDayTable[] = {
1556 { "january", tMONTH, 1 },
1557 { "february", tMONTH, 2 },
1558 { "march", tMONTH, 3 },
1559 { "april", tMONTH, 4 },
1560 { "may", tMONTH, 5 },
1561 { "june", tMONTH, 6 },
1562 { "july", tMONTH, 7 },
1563 { "august", tMONTH, 8 },
1564 { "september", tMONTH, 9 },
1565 { "october", tMONTH, 10 },
1566 { "november", tMONTH, 11 },
1567 { "december", tMONTH, 12 },
1568 /* The value of the day isn't used... */
1569 { "sunday", tDAY, 0 },
1570 { "monday", tDAY, 0 },
1571 { "tuesday", tDAY, 0 },
1572 { "wednesday", tDAY, 0 },
1573 { "thursday", tDAY, 0 },
1574 { "friday", tDAY, 0 },
1575 { "saturday", tDAY, 0 },
1578 /* Time units table. */
1579 static TABLE UnitsTable[] = {
1580 { "year", tMONTH_UNIT, 12 },
1581 { "month", tMONTH_UNIT, 1 },
1582 { "week", tSEC_UNIT, 7L * 24 * 60 * 60 },
1583 { "day", tSEC_UNIT, 1L * 24 * 60 * 60 },
1584 { "hour", tSEC_UNIT, 60 * 60 },
1585 { "minute", tSEC_UNIT, 60 },
1586 { "min", tSEC_UNIT, 60 },
1587 { "second", tSEC_UNIT, 1 },
1588 { "sec", tSEC_UNIT, 1 },
1591 /* Timezone table. */
1592 static TABLE TimezoneTable[] = {
1593 { "gmt", tZONE, HOUR( 0) }, /* Greenwich Mean */
1594 { "ut", tZONE, HOUR( 0) }, /* Universal */
1595 { "utc", tZONE, HOUR( 0) }, /* Universal Coordinated */
1596 { "cut", tZONE, HOUR( 0) }, /* Coordinated Universal */
1597 { "z", tZONE, HOUR( 0) }, /* Greenwich Mean */
1598 { "wet", tZONE, HOUR( 0) }, /* Western European */
1599 { "bst", tDAYZONE, HOUR( 0) }, /* British Summer */
1600 { "nst", tZONE, HOUR(3)+30 }, /* Newfoundland Standard */
1601 { "ndt", tDAYZONE, HOUR(3)+30 }, /* Newfoundland Daylight */
1602 { "ast", tZONE, HOUR( 4) }, /* Atlantic Standard */
1603 { "adt", tDAYZONE, HOUR( 4) }, /* Atlantic Daylight */
1604 { "est", tZONE, HOUR( 5) }, /* Eastern Standard */
1605 { "edt", tDAYZONE, HOUR( 5) }, /* Eastern Daylight */
1606 { "cst", tZONE, HOUR( 6) }, /* Central Standard */
1607 { "cdt", tDAYZONE, HOUR( 6) }, /* Central Daylight */
1608 { "mst", tZONE, HOUR( 7) }, /* Mountain Standard */
1609 { "mdt", tDAYZONE, HOUR( 7) }, /* Mountain Daylight */
1610 { "pst", tZONE, HOUR( 8) }, /* Pacific Standard */
1611 { "pdt", tDAYZONE, HOUR( 8) }, /* Pacific Daylight */
1612 { "yst", tZONE, HOUR( 9) }, /* Yukon Standard */
1613 { "ydt", tDAYZONE, HOUR( 9) }, /* Yukon Daylight */
1614 { "akst", tZONE, HOUR( 9) }, /* Alaska Standard */
1615 { "akdt", tDAYZONE, HOUR( 9) }, /* Alaska Daylight */
1616 { "hst", tZONE, HOUR(10) }, /* Hawaii Standard */
1617 { "hast", tZONE, HOUR(10) }, /* Hawaii-Aleutian Standard */
1618 { "hadt", tDAYZONE, HOUR(10) }, /* Hawaii-Aleutian Daylight */
1619 { "ces", tDAYZONE, -HOUR(1) }, /* Central European Summer */
1620 { "cest", tDAYZONE, -HOUR(1) }, /* Central European Summer */
1621 { "mez", tZONE, -HOUR(1) }, /* Middle European */
1622 { "mezt", tDAYZONE, -HOUR(1) }, /* Middle European Summer */
1623 { "cet", tZONE, -HOUR(1) }, /* Central European */
1624 { "met", tZONE, -HOUR(1) }, /* Middle European */
1625 { "eet", tZONE, -HOUR(2) }, /* Eastern Europe */
1626 { "msk", tZONE, -HOUR(3) }, /* Moscow Winter */
1627 { "msd", tDAYZONE, -HOUR(3) }, /* Moscow Summer */
1628 { "wast", tZONE, -HOUR(8) }, /* West Australian Standard */
1629 { "wadt", tDAYZONE, -HOUR(8) }, /* West Australian Daylight */
1630 { "hkt", tZONE, -HOUR(8) }, /* Hong Kong */
1631 { "cct", tZONE, -HOUR(8) }, /* China Coast */
1632 { "jst", tZONE, -HOUR(9) }, /* Japan Standard */
1633 { "kst", tZONE, -HOUR(9) }, /* Korean Standard */
1634 { "kdt", tZONE, -HOUR(9) }, /* Korean Daylight */
1635 { "cast", tZONE, -(HOUR(9)+30) }, /* Central Australian Standard */
1636 { "cadt", tDAYZONE, -(HOUR(9)+30) }, /* Central Australian Daylight */
1637 { "east", tZONE, -HOUR(10) }, /* Eastern Australian Standard */
1638 { "eadt", tDAYZONE, -HOUR(10) }, /* Eastern Australian Daylight */
1639 { "nzst", tZONE, -HOUR(12) }, /* New Zealand Standard */
1640 { "nzdt", tDAYZONE, -HOUR(12) }, /* New Zealand Daylight */
1642 /* For completeness we include the following entries. */
1645 /* Duplicate names. Either they conflict with a zone listed above
1646 * (which is either more likely to be seen or just been in circulation
1647 * longer), or they conflict with another zone in this section and
1648 * we could not reasonably choose one over the other. */
1649 { "fst", tZONE, HOUR( 2) }, /* Fernando De Noronha Standard */
1650 { "fdt", tDAYZONE, HOUR( 2) }, /* Fernando De Noronha Daylight */
1651 { "bst", tZONE, HOUR( 3) }, /* Brazil Standard */
1652 { "est", tZONE, HOUR( 3) }, /* Eastern Standard (Brazil) */
1653 { "edt", tDAYZONE, HOUR( 3) }, /* Eastern Daylight (Brazil) */
1654 { "wst", tZONE, HOUR( 4) }, /* Western Standard (Brazil) */
1655 { "wdt", tDAYZONE, HOUR( 4) }, /* Western Daylight (Brazil) */
1656 { "cst", tZONE, HOUR( 5) }, /* Chile Standard */
1657 { "cdt", tDAYZONE, HOUR( 5) }, /* Chile Daylight */
1658 { "ast", tZONE, HOUR( 5) }, /* Acre Standard */
1659 { "adt", tDAYZONE, HOUR( 5) }, /* Acre Daylight */
1660 { "cst", tZONE, HOUR( 5) }, /* Cuba Standard */
1661 { "cdt", tDAYZONE, HOUR( 5) }, /* Cuba Daylight */
1662 { "est", tZONE, HOUR( 6) }, /* Easter Island Standard */
1663 { "edt", tDAYZONE, HOUR( 6) }, /* Easter Island Daylight */
1664 { "sst", tZONE, HOUR(11) }, /* Samoa Standard */
1665 { "ist", tZONE, -HOUR(2) }, /* Israel Standard */
1666 { "idt", tDAYZONE, -HOUR(2) }, /* Israel Daylight */
1667 { "idt", tDAYZONE, -(HOUR(3)+30) }, /* Iran Daylight */
1668 { "ist", tZONE, -(HOUR(3)+30) }, /* Iran Standard */
1669 { "cst", tZONE, -HOUR(8) }, /* China Standard */
1670 { "cdt", tDAYZONE, -HOUR(8) }, /* China Daylight */
1671 { "sst", tZONE, -HOUR(8) }, /* Singapore Standard */
1673 /* Dubious (e.g., not in Olson's TIMEZONE package) or obsolete. */
1674 { "gst", tZONE, HOUR( 3) }, /* Greenland Standard */
1675 { "wat", tZONE, -HOUR(1) }, /* West Africa */
1676 { "at", tZONE, HOUR( 2) }, /* Azores */
1677 { "gst", tZONE, -HOUR(10) }, /* Guam Standard */
1678 { "nft", tZONE, HOUR(3)+30 }, /* Newfoundland */
1679 { "idlw", tZONE, HOUR(12) }, /* International Date Line West */
1680 { "mewt", tZONE, -HOUR(1) }, /* Middle European Winter */
1681 { "mest", tDAYZONE, -HOUR(1) }, /* Middle European Summer */
1682 { "swt", tZONE, -HOUR(1) }, /* Swedish Winter */
1683 { "sst", tDAYZONE, -HOUR(1) }, /* Swedish Summer */
1684 { "fwt", tZONE, -HOUR(1) }, /* French Winter */
1685 { "fst", tDAYZONE, -HOUR(1) }, /* French Summer */
1686 { "bt", tZONE, -HOUR(3) }, /* Baghdad */
1687 { "it", tZONE, -(HOUR(3)+30) }, /* Iran */
1688 { "zp4", tZONE, -HOUR(4) }, /* USSR Zone 3 */
1689 { "zp5", tZONE, -HOUR(5) }, /* USSR Zone 4 */
1690 { "ist", tZONE, -(HOUR(5)+30) }, /* Indian Standard */
1691 { "zp6", tZONE, -HOUR(6) }, /* USSR Zone 5 */
1692 { "nst", tZONE, -HOUR(7) }, /* North Sumatra */
1693 { "sst", tZONE, -HOUR(7) }, /* South Sumatra */
1694 { "jt", tZONE, -(HOUR(7)+30) }, /* Java (3pm in Cronusland!) */
1695 { "nzt", tZONE, -HOUR(12) }, /* New Zealand */
1696 { "idle", tZONE, -HOUR(12) }, /* International Date Line East */
1697 { "cat", tZONE, HOUR(10) }, /* -- expired 1967 */
1698 { "nt", tZONE, HOUR(11) }, /* -- expired 1967 */
1699 { "ahst", tZONE, HOUR(10) }, /* -- expired 1983 */
1700 { "hdt", tDAYZONE, HOUR(10) }, /* -- expired 1986 */
1714 ToSeconds(time_t Hours, time_t Minutes, time_t Seconds, MERIDIAN Meridian)
1716 if (Minutes < 0 || Minutes > 59 || Seconds < 0 || Seconds > 61)
1718 if (Meridian == MER24) {
1719 if (Hours < 0 || Hours > 23)
1723 if (Hours < 1 || Hours > 12)
1727 if (Meridian == MERpm)
1730 return (Hours * 60L + Minutes) * 60L + Seconds;
1735 Convert(time_t Month, time_t Day, time_t Year,
1736 time_t Hours, time_t Minutes, time_t Seconds,
1737 MERIDIAN Meridian, DSTMODE dst)
1739 static int DaysNormal[13] = {
1740 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
1742 static int DaysLeap[13] = {
1743 0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
1745 static int LeapYears[] = {
1746 1972, 1976, 1980, 1984, 1988, 1992, 1996,
1747 2000, 2004, 2008, 2012, 2016, 2020, 2024, 2028, 2032, 2036
1751 register time_t Julian;
1761 for (mp = DaysNormal, yp = LeapYears; yp < ENDOF(LeapYears); yp++)
1766 if (Year < EPOCH || Year > END_OF_TIME
1767 || Month < 1 || Month > 12
1768 /* NOSTRICT *//* conversion from long may lose accuracy */
1769 || Day < 1 || Day > mp[(int)Month])
1772 Julian = Day - 1 + (Year - EPOCH) * 365;
1773 for (yp = LeapYears; yp < ENDOF(LeapYears); yp++, Julian++)
1776 for (i = 1; i < Month; i++)
1778 Julian *= SECSPERDAY;
1779 Julian += yyTimezone * 60L;
1780 if ((tod = ToSeconds(Hours, Minutes, Seconds, Meridian)) < 0)
1784 if (dst == DSTon || (dst == DSTmaybe && localtime(&tod)->tm_isdst))
1785 Julian -= DST_OFFSET * 60L * 60L;
1791 DSTcorrect(time_t Start, time_t Future)
1796 StartDay = (localtime(&Start)->tm_hour + 1) % 24;
1797 FutureDay = (localtime(&Future)->tm_hour + 1) % 24;
1798 return (Future - Start) + (StartDay - FutureDay) * DST_OFFSET * 60L * 60L;
1803 RelativeMonth(time_t Start, time_t RelMonth)
1809 tm = localtime(&Start);
1810 Month = 12 * tm->tm_year + tm->tm_mon + RelMonth;
1812 Month = Month % 12 + 1;
1813 return DSTcorrect(Start,
1814 Convert(Month, (time_t)tm->tm_mday, Year,
1815 (time_t)tm->tm_hour, (time_t)tm->tm_min, (time_t)tm->tm_sec,
1821 LookupWord(char *buff, register int length)
1831 /* See if we have an abbreviation for a month. */
1832 if (length == 3 || (length == 4 && p[3] == '.'))
1833 for (tp = MonthDayTable; tp < ENDOF(MonthDayTable); tp++) {
1835 if (c == q[0] && p[1] == q[1] && p[2] == q[2]) {
1836 yylval.Number = tp->value;
1841 for (tp = MonthDayTable; tp < ENDOF(MonthDayTable); tp++)
1842 if (c == tp->name[0] && strcmp(p, tp->name) == 0) {
1843 yylval.Number = tp->value;
1847 /* Try for a timezone. */
1848 for (tp = TimezoneTable; tp < ENDOF(TimezoneTable); tp++)
1849 if (c == tp->name[0] && p[1] == tp->name[1]
1850 && strcmp(p, tp->name) == 0) {
1851 yylval.Number = tp->value;
1855 /* Try the units table. */
1856 for (tp = UnitsTable; tp < ENDOF(UnitsTable); tp++)
1857 if (c == tp->name[0] && strcmp(p, tp->name) == 0) {
1858 yylval.Number = tp->value;
1862 /* Strip off any plural and try the units table again. */
1863 if (--length > 0 && p[length] == 's') {
1865 for (tp = UnitsTable; tp < ENDOF(UnitsTable); tp++)
1866 if (c == tp->name[0] && strcmp(p, tp->name) == 0) {
1868 yylval.Number = tp->value;
1875 /* Drop out any periods. */
1876 for (p = buff, q = (char*)buff; *q; q++)
1881 /* Try the meridians. */
1882 if (buff[1] == 'm' && buff[2] == '\0') {
1883 if (buff[0] == 'a') {
1884 yylval.Meridian = MERam;
1887 if (buff[0] == 'p') {
1888 yylval.Meridian = MERpm;
1893 /* If we saw any periods, try the timezones again. */
1894 if (p - buff != length) {
1896 for (p = buff, tp = TimezoneTable; tp < ENDOF(TimezoneTable); tp++)
1897 if (c == tp->name[0] && p[1] == tp->name[1]
1898 && strcmp(p, tp->name) == 0) {
1899 yylval.Number = tp->value;
1904 /* Unknown word -- assume GMT timezone. */
1918 register int nesting;
1921 /* Get first character after the whitespace. */
1923 while (isspace(*yyInput))
1927 /* Ignore RFC 822 comments, typically time zone names. */
1930 for (nesting = 1; (c = *++yyInput) != RPAREN || --nesting; )
1933 else if (!IS7BIT(c) || c == '\0' || c == '\r'
1934 || (c == '\\' && ((c = *++yyInput) == '\0' || !IS7BIT(c))))
1935 /* Lexical error: bad comment. */
1941 if (isdigit(c) || c == '-' || c == '+') {
1942 if (c == '-' || c == '+') {
1943 sign = c == '-' ? -1 : 1;
1945 if (!isdigit(*yyInput))
1946 /* Skip the plus or minus sign. */
1951 for (i = 0; (c = *yyInput++) != '\0' && isdigit(c); )
1952 i = 10 * i + c - '0';
1954 yylval.Number = sign < 0 ? -i : i;
1955 return sign ? tSNUMBER : tUNUMBER;
1960 for (p = buff; (c = *yyInput++) == '.' || isalpha(c); )
1961 if (p < &buff[sizeof buff - 1])
1962 *p++ = isupper(c) ? tolower(c) : c;
1965 return LookupWord(buff, p - buff);
1976 extern int date_parse(void);
1985 yyDSTmode = DSTmaybe;
1996 if (date_parse() || yyHaveTime > 1 || yyHaveDate > 1)
1999 if (yyHaveDate || yyHaveTime) {
2000 Start = Convert(yyMonth, yyDay, yyYear, yyHour, yyMinutes, yySeconds,
2001 yyMeridian, yyDSTmode);
2008 Start += yyRelSeconds;
2010 Start += RelativeMonth(Start, yyRelMonth);
2012 /* Have to do *something* with a legitimate -1 so it's distinguishable
2013 * from the error return value. (Alternately could set errno on error.) */
2014 return Start == -1 ? 0 : Start;
2022 #endif /* YYDEBUG */
2026 main(int ac, char *av[])
2033 #endif /* YYDEBUG */
2035 (void)printf("Enter date, or blank line to exit.\n\t> ");
2037 (void)printf("\t> ");
2038 (void)fflush(stdout);
2039 if (fgets(buff, sizeof buff, stdin) == NULL || buff[0] == '\n')
2042 if (strcmp(buff, "yydebug") == 0) {
2044 printf("yydebug = %s\n", yydebug ? "on" : "off");
2047 #endif /* YYDEBUG */
2048 d = parsedate(buff, (TIMEINFO *)NULL);
2050 (void)printf("Bad format - couldn't convert.\n");
2052 (void)printf("%s", ctime(&d));