diff options
Diffstat (limited to 'src/parsdate.c')
-rw-r--r-- | src/parsdate.c | 328 |
1 files changed, 182 insertions, 146 deletions
diff --git a/src/parsdate.c b/src/parsdate.c index 97578ef3..ce271e33 100644 --- a/src/parsdate.c +++ b/src/parsdate.c @@ -2,38 +2,23 @@ static const char yysccsid[] = "@(#)yaccpar 1.9 (Berkeley) 02/21/93"; #endif -#include <stdlib.h> -#include <string.h> - #define YYBYACC 1 #define YYMAJOR 1 #define YYMINOR 9 -#define YYPATCH 20081224 +#define YYPATCH 20100610 #define YYEMPTY (-1) #define yyclearin (yychar = YYEMPTY) #define yyerrok (yyerrflag = 0) #define YYRECOVERING() (yyerrflag != 0) -/* compatibility with bison */ -#ifdef YYPARSE_PARAM -/* compatibility with FreeBSD */ -#ifdef YYPARSE_PARAM_TYPE -#define YYPARSE_DECL() yyparse(YYPARSE_PARAM_TYPE YYPARSE_PARAM) -#else -#define YYPARSE_DECL() yyparse(void *YYPARSE_PARAM) -#endif -#else -#define YYPARSE_DECL() yyparse(void) -#endif /* YYPARSE_PARAM */ +#define YYPREFIX "yy" -extern int YYPARSE_DECL(); +#define YYPURE 0 -static int yygrowstack(void); -#define YYPREFIX "yy" #line 2 "./parsdate.y" /* - * $LynxId: parsdate.c,v 1.8 2009/01/01 22:12:42 tom Exp $ + * $LynxId: parsdate.c,v 1.9 2010/09/22 21:18:46 tom Exp $ * * This module is adapted and extended from tin, to use for LYmktime(). * @@ -169,7 +154,31 @@ typedef union { time_t Number; enum _MERIDIAN Meridian; } YYSTYPE; -#line 172 "y.tab.c" +#line 157 "y.tab.c" +/* compatibility with bison */ +#ifdef YYPARSE_PARAM +/* compatibility with FreeBSD */ +# ifdef YYPARSE_PARAM_TYPE +# define YYPARSE_DECL() yyparse(YYPARSE_PARAM_TYPE YYPARSE_PARAM) +# else +# define YYPARSE_DECL() yyparse(void *YYPARSE_PARAM) +# endif +#else +# define YYPARSE_DECL() yyparse(void) +#endif + +/* Parameters sent to lex. */ +#ifdef YYLEX_PARAM +# define YYLEX_DECL() yylex(void *YYLEX_PARAM) +# define YYLEX yylex(YYLEX_PARAM) +#else +# define YYLEX_DECL() yylex(void) +# define YYLEX yylex() +#endif + +extern int YYPARSE_DECL(); +extern int YYLEX_DECL(); + #define tDAY 257 #define tDAYZONE 258 #define tMERIDIAN 259 @@ -346,10 +355,6 @@ static const char *yyrule[] = { }; #endif -#if YYDEBUG -#include <stdio.h> -#endif - /* define the initial stack-sizes */ #ifdef YYSTACKSIZE #undef YYMAXDEPTH @@ -367,18 +372,22 @@ static const char *yyrule[] = { int yydebug; int yynerrs; + +typedef struct { + unsigned stacksize; + short *s_base; + short *s_mark; + short *s_last; + YYSTYPE *l_base; + YYSTYPE *l_mark; +} YYSTACKDATA; int yyerrflag; int yychar; -short *yyssp; -YYSTYPE *yyvsp; YYSTYPE yyval; YYSTYPE yylval; /* variables for the parser stack */ -static short *yyss; -static short *yysslim; -static YYSTYPE *yyvs; -static unsigned yystacksize; +static YYSTACKDATA yystack; #line 358 "./parsdate.y" /* @@ -862,7 +871,7 @@ date_lex(void) } *p = '\0'; yyInput--; - return LookupWord(buff, p - buff); + return LookupWord(buff, (int) (p - buff)); } return *yyInput++; @@ -986,44 +995,65 @@ parsedate( * from the error return value. (Alternately could set errno on error.) */ return Start == -1 ? 0 : Start; } -#line 989 "y.tab.c" +#line 998 "y.tab.c" + +#if YYDEBUG +#include <stdio.h> /* needed for printf */ +#endif + +#include <stdlib.h> /* needed for malloc, etc */ +#include <string.h> /* needed for memset */ + /* allocate initial stack or double stack size, up to YYMAXDEPTH */ -static int yygrowstack(void) +static int yygrowstack(YYSTACKDATA *data) { int i; unsigned newsize; short *newss; YYSTYPE *newvs; - if ((newsize = yystacksize) == 0) + if ((newsize = data->stacksize) == 0) newsize = YYINITSTACKSIZE; else if (newsize >= YYMAXDEPTH) return -1; else if ((newsize *= 2) > YYMAXDEPTH) newsize = YYMAXDEPTH; - i = yyssp - yyss; - newss = (yyss != 0) - ? (short *)realloc(yyss, newsize * sizeof(*newss)) + i = data->s_mark - data->s_base; + newss = (data->s_base != 0) + ? (short *)realloc(data->s_base, newsize * sizeof(*newss)) : (short *)malloc(newsize * sizeof(*newss)); if (newss == 0) return -1; - yyss = newss; - yyssp = newss + i; - newvs = (yyvs != 0) - ? (YYSTYPE *)realloc(yyvs, newsize * sizeof(*newvs)) + data->s_base = newss; + data->s_mark = newss + i; + + newvs = (data->l_base != 0) + ? (YYSTYPE *)realloc(data->l_base, newsize * sizeof(*newvs)) : (YYSTYPE *)malloc(newsize * sizeof(*newvs)); if (newvs == 0) return -1; - yyvs = newvs; - yyvsp = newvs + i; - yystacksize = newsize; - yysslim = yyss + newsize - 1; + data->l_base = newvs; + data->l_mark = newvs + i; + + data->stacksize = newsize; + data->s_last = data->s_base + newsize - 1; return 0; } +#if YYPURE || defined(YY_NO_LEAKS) +static void yyfreestack(YYSTACKDATA *data) +{ + free(data->s_base); + free(data->l_base); + memset(data, 0, sizeof(*data)); +} +#else +#define yyfreestack(data) /* nothing */ +#endif + #define YYABORT goto yyabort #define YYREJECT goto yyabort #define YYACCEPT goto yyaccept @@ -1049,17 +1079,21 @@ YYPARSE_DECL() yychar = YYEMPTY; yystate = 0; - if (yyss == NULL && yygrowstack()) goto yyoverflow; - yyssp = yyss; - yyvsp = yyvs; +#if YYPURE + memset(&yystack, 0, sizeof(yystack)); +#endif + + if (yystack.s_base == NULL && yygrowstack(&yystack)) goto yyoverflow; + yystack.s_mark = yystack.s_base; + yystack.l_mark = yystack.l_base; yystate = 0; - *yyssp = 0; + *yystack.s_mark = 0; yyloop: if ((yyn = yydefred[yystate]) != 0) goto yyreduce; if (yychar < 0) { - if ((yychar = yylex()) < 0) yychar = 0; + if ((yychar = YYLEX) < 0) yychar = 0; #if YYDEBUG if (yydebug) { @@ -1079,13 +1113,13 @@ yyloop: printf("%sdebug: state %d, shifting to state %d\n", YYPREFIX, yystate, yytable[yyn]); #endif - if (yyssp >= yysslim && yygrowstack()) + if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack)) { goto yyoverflow; } yystate = yytable[yyn]; - *++yyssp = yytable[yyn]; - *++yyvsp = yylval; + *++yystack.s_mark = yytable[yyn]; + *++yystack.l_mark = yylval; yychar = YYEMPTY; if (yyerrflag > 0) --yyerrflag; goto yyloop; @@ -1111,21 +1145,21 @@ yyinrecovery: yyerrflag = 3; for (;;) { - if ((yyn = yysindex[*yyssp]) && (yyn += YYERRCODE) >= 0 && + if ((yyn = yysindex[*yystack.s_mark]) && (yyn += YYERRCODE) >= 0 && yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE) { #if YYDEBUG if (yydebug) printf("%sdebug: state %d, error recovery shifting\ - to state %d\n", YYPREFIX, *yyssp, yytable[yyn]); + to state %d\n", YYPREFIX, *yystack.s_mark, yytable[yyn]); #endif - if (yyssp >= yysslim && yygrowstack()) + if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack)) { goto yyoverflow; } yystate = yytable[yyn]; - *++yyssp = yytable[yyn]; - *++yyvsp = yylval; + *++yystack.s_mark = yytable[yyn]; + *++yystack.l_mark = yylval; goto yyloop; } else @@ -1133,11 +1167,11 @@ yyinrecovery: #if YYDEBUG if (yydebug) printf("%sdebug: error recovery discarding state %d\n", - YYPREFIX, *yyssp); + YYPREFIX, *yystack.s_mark); #endif - if (yyssp <= yyss) goto yyabort; - --yyssp; - --yyvsp; + if (yystack.s_mark <= yystack.s_base) goto yyabort; + --yystack.s_mark; + --yystack.l_mark; } } } @@ -1166,7 +1200,7 @@ yyreduce: #endif yym = yylen[yyn]; if (yym) - yyval = yyvsp[1-yym]; + yyval = yystack.l_mark[1-yym]; else memset(&yyval, 0, sizeof yyval); switch (yyn) @@ -1187,7 +1221,7 @@ case 4: #line 163 "./parsdate.y" { yyHaveTime++; - yyTimezone = yyvsp[0].Number; + yyTimezone = yystack.l_mark[0].Number; } break; case 5: @@ -1208,7 +1242,7 @@ case 7: { yyHaveDate++; yyHaveTime++; - yyTimezone = yyvsp[0].Number; + yyTimezone = yystack.l_mark[0].Number; } break; case 8: @@ -1220,33 +1254,33 @@ break; case 9: #line 184 "./parsdate.y" { - if (yyvsp[-1].Number < 100) { - yyHour = yyvsp[-1].Number; + if (yystack.l_mark[-1].Number < 100) { + yyHour = yystack.l_mark[-1].Number; yyMinutes = 0; } else { - yyHour = yyvsp[-1].Number / 100; - yyMinutes = yyvsp[-1].Number % 100; + yyHour = yystack.l_mark[-1].Number / 100; + yyMinutes = yystack.l_mark[-1].Number % 100; } yySeconds = 0; - yyMeridian = yyvsp[0].Meridian; + yyMeridian = yystack.l_mark[0].Meridian; } break; case 10: #line 196 "./parsdate.y" { - yyHour = yyvsp[-3].Number; - yyMinutes = yyvsp[-1].Number; + yyHour = yystack.l_mark[-3].Number; + yyMinutes = yystack.l_mark[-1].Number; yySeconds = 0; - yyMeridian = yyvsp[0].Meridian; + yyMeridian = yystack.l_mark[0].Meridian; } break; case 11: #line 202 "./parsdate.y" { - yyHour = yyvsp[-3].Number; - yyMinutes = yyvsp[-1].Number; - yyTimezone = yyvsp[0].Number; + yyHour = yystack.l_mark[-3].Number; + yyMinutes = yystack.l_mark[-1].Number; + yyTimezone = yystack.l_mark[0].Number; yyMeridian = MER24; yyDSTmode = DSToff; } @@ -1254,19 +1288,19 @@ break; case 12: #line 209 "./parsdate.y" { - yyHour = yyvsp[-5].Number; - yyMinutes = yyvsp[-3].Number; - yySeconds = yyvsp[-1].Number; - yyMeridian = yyvsp[0].Meridian; + yyHour = yystack.l_mark[-5].Number; + yyMinutes = yystack.l_mark[-3].Number; + yySeconds = yystack.l_mark[-1].Number; + yyMeridian = yystack.l_mark[0].Meridian; } break; case 13: #line 215 "./parsdate.y" { - yyHour = yyvsp[-5].Number; - yyMinutes = yyvsp[-3].Number; - yySeconds = yyvsp[-1].Number; - yyTimezone = yyvsp[0].Number; + yyHour = yystack.l_mark[-5].Number; + yyMinutes = yystack.l_mark[-3].Number; + yySeconds = yystack.l_mark[-1].Number; + yyTimezone = yystack.l_mark[0].Number; yyMeridian = MER24; yyDSTmode = DSToff; } @@ -1274,21 +1308,21 @@ break; case 14: #line 225 "./parsdate.y" { - yyval.Number = yyvsp[0].Number; + yyval.Number = yystack.l_mark[0].Number; yyDSTmode = DSToff; } break; case 15: #line 229 "./parsdate.y" { - yyval.Number = yyvsp[0].Number; + yyval.Number = yystack.l_mark[0].Number; yyDSTmode = DSTon; } break; case 16: #line 233 "./parsdate.y" { - yyTimezone = yyvsp[-1].Number; + yyTimezone = yystack.l_mark[-1].Number; yyDSTmode = DSTon; } break; @@ -1296,17 +1330,17 @@ case 17: #line 237 "./parsdate.y" { /* Only allow "GMT+300" and "GMT-0800" */ - if (yyvsp[-1].Number != 0) { + if (yystack.l_mark[-1].Number != 0) { YYABORT; } - yyval.Number = yyvsp[0].Number; + yyval.Number = yystack.l_mark[0].Number; yyDSTmode = DSToff; } break; case 18: #line 245 "./parsdate.y" { - yyval.Number = yyvsp[0].Number; + yyval.Number = yystack.l_mark[0].Number; yyDSTmode = DSToff; } break; @@ -1316,96 +1350,96 @@ case 19: int i; /* Unix and GMT and numeric timezones -- a little confusing. */ - if ((int)yyvsp[0].Number < 0) { + if ((int)yystack.l_mark[0].Number < 0) { /* Don't work with negative modulus. */ - yyvsp[0].Number = -(int)yyvsp[0].Number; - if (yyvsp[0].Number > 9999 || (i = yyvsp[0].Number % 100) >= 60) { + yystack.l_mark[0].Number = -(int)yystack.l_mark[0].Number; + if (yystack.l_mark[0].Number > 9999 || (i = (int) (yystack.l_mark[0].Number % 100)) >= 60) { YYABORT; } - yyval.Number = (yyvsp[0].Number / 100) * 60 + i; + yyval.Number = (yystack.l_mark[0].Number / 100) * 60 + i; } else { - if (yyvsp[0].Number > 9999 || (i = yyvsp[0].Number % 100) >= 60) { + if (yystack.l_mark[0].Number > 9999 || (i = (int) (yystack.l_mark[0].Number % 100)) >= 60) { YYABORT; } - yyval.Number = -((yyvsp[0].Number / 100) * 60 + i); + yyval.Number = -((yystack.l_mark[0].Number / 100) * 60 + i); } } break; case 20: #line 272 "./parsdate.y" { - yyMonth = yyvsp[-2].Number; - yyDay = yyvsp[0].Number; + yyMonth = yystack.l_mark[-2].Number; + yyDay = yystack.l_mark[0].Number; } break; case 21: #line 276 "./parsdate.y" { - if (yyvsp[-4].Number > 100) { - yyYear = yyvsp[-4].Number; - yyMonth = yyvsp[-2].Number; - yyDay = yyvsp[0].Number; + if (yystack.l_mark[-4].Number > 100) { + yyYear = yystack.l_mark[-4].Number; + yyMonth = yystack.l_mark[-2].Number; + yyDay = yystack.l_mark[0].Number; } else { - yyMonth = yyvsp[-4].Number; - yyDay = yyvsp[-2].Number; - yyYear = yyvsp[0].Number; + yyMonth = yystack.l_mark[-4].Number; + yyDay = yystack.l_mark[-2].Number; + yyYear = yystack.l_mark[0].Number; } } break; case 22: #line 288 "./parsdate.y" { - yyMonth = yyvsp[-1].Number; - yyDay = yyvsp[0].Number; + yyMonth = yystack.l_mark[-1].Number; + yyDay = yystack.l_mark[0].Number; } break; case 23: #line 292 "./parsdate.y" { - yyMonth = yyvsp[-3].Number; - yyDay = yyvsp[-2].Number; - yyYear = yyvsp[0].Number; + yyMonth = yystack.l_mark[-3].Number; + yyDay = yystack.l_mark[-2].Number; + yyYear = yystack.l_mark[0].Number; } break; case 24: #line 297 "./parsdate.y" { - yyDay = yyvsp[-1].Number; - yyMonth = yyvsp[0].Number; + yyDay = yystack.l_mark[-1].Number; + yyMonth = yystack.l_mark[0].Number; } break; case 25: #line 301 "./parsdate.y" { - yyDay = yyvsp[-2].Number; - yyMonth = yyvsp[-1].Number; - yyYear = yyvsp[0].Number; + yyDay = yystack.l_mark[-2].Number; + yyMonth = yystack.l_mark[-1].Number; + yyYear = yystack.l_mark[0].Number; } break; case 26: #line 306 "./parsdate.y" { - yyDay = yyvsp[-2].Number; - yyMonth = yyvsp[-1].Number; - yyYear = yyvsp[0].Number; + yyDay = yystack.l_mark[-2].Number; + yyMonth = yystack.l_mark[-1].Number; + yyYear = yystack.l_mark[0].Number; } break; case 27: #line 311 "./parsdate.y" { - yyDay = yyvsp[-3].Number; - yyMonth = yyvsp[-1].Number; - yyYear = -yyvsp[0].Number; + yyDay = yystack.l_mark[-3].Number; + yyMonth = yystack.l_mark[-1].Number; + yyYear = -yystack.l_mark[0].Number; } break; case 28: #line 316 "./parsdate.y" { - yyDay = yyvsp[-2].Number; - yyMonth = -yyvsp[-1].Number; - yyYear = -yyvsp[0].Number; + yyDay = yystack.l_mark[-2].Number; + yyMonth = -yystack.l_mark[-1].Number; + yyYear = -yystack.l_mark[0].Number; yyDSTmode = DSToff; /* assume midnight if no time given */ yyTimezone = 0; /* Lynx assumes GMT for this format */ } @@ -1413,36 +1447,36 @@ break; case 29: #line 325 "./parsdate.y" { - yyMonth = yyvsp[-7].Number; - yyDay = yyvsp[-6].Number; - yyYear = yyvsp[0].Number; - yyHour = yyvsp[-5].Number; - yyMinutes = yyvsp[-3].Number; - yySeconds = yyvsp[-1].Number; + yyMonth = yystack.l_mark[-7].Number; + yyDay = yystack.l_mark[-6].Number; + yyYear = yystack.l_mark[0].Number; + yyHour = yystack.l_mark[-5].Number; + yyMinutes = yystack.l_mark[-3].Number; + yySeconds = yystack.l_mark[-1].Number; } break; case 30: #line 335 "./parsdate.y" { - yyRelSeconds += yyvsp[-1].Number * yyvsp[0].Number; + yyRelSeconds += yystack.l_mark[-1].Number * yystack.l_mark[0].Number; } break; case 31: #line 338 "./parsdate.y" { - yyRelSeconds += yyvsp[-1].Number * yyvsp[0].Number; + yyRelSeconds += yystack.l_mark[-1].Number * yystack.l_mark[0].Number; } break; case 32: #line 341 "./parsdate.y" { - yyRelMonth += yyvsp[-1].Number * yyvsp[0].Number; + yyRelMonth += yystack.l_mark[-1].Number * yystack.l_mark[0].Number; } break; case 33: #line 344 "./parsdate.y" { - yyRelMonth += yyvsp[-1].Number * yyvsp[0].Number; + yyRelMonth += yystack.l_mark[-1].Number * yystack.l_mark[0].Number; } break; case 34: @@ -1454,14 +1488,14 @@ break; case 35: #line 352 "./parsdate.y" { - yyval.Meridian = yyvsp[0].Meridian; + yyval.Meridian = yystack.l_mark[0].Meridian; } break; -#line 1460 "y.tab.c" +#line 1494 "y.tab.c" } - yyssp -= yym; - yystate = *yyssp; - yyvsp -= yym; + yystack.s_mark -= yym; + yystate = *yystack.s_mark; + yystack.l_mark -= yym; yym = yylhs[yyn]; if (yystate == 0 && yym == 0) { @@ -1471,11 +1505,11 @@ break; state %d\n", YYPREFIX, YYFINAL); #endif yystate = YYFINAL; - *++yyssp = YYFINAL; - *++yyvsp = yyval; + *++yystack.s_mark = YYFINAL; + *++yystack.l_mark = yyval; if (yychar < 0) { - if ((yychar = yylex()) < 0) yychar = 0; + if ((yychar = YYLEX) < 0) yychar = 0; #if YYDEBUG if (yydebug) { @@ -1498,22 +1532,24 @@ break; #if YYDEBUG if (yydebug) printf("%sdebug: after reduction, shifting from state %d \ -to state %d\n", YYPREFIX, *yyssp, yystate); +to state %d\n", YYPREFIX, *yystack.s_mark, yystate); #endif - if (yyssp >= yysslim && yygrowstack()) + if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack)) { goto yyoverflow; } - *++yyssp = (short) yystate; - *++yyvsp = yyval; + *++yystack.s_mark = (short) yystate; + *++yystack.l_mark = yyval; goto yyloop; yyoverflow: yyerror("yacc stack overflow"); yyabort: + yyfreestack(&yystack); return (1); yyaccept: + yyfreestack(&yystack); return (0); } |