=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/yacc/skeleton.c,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- src/usr.bin/yacc/skeleton.c 1996/03/27 19:33:21 1.3 +++ src/usr.bin/yacc/skeleton.c 1996/04/21 23:45:21 1.4 @@ -1,5 +1,50 @@ -/* $OpenBSD: skeleton.c,v 1.3 1996/03/27 19:33:21 niklas Exp $ */ +/* $OpenBSD: skeleton.c,v 1.4 1996/04/21 23:45:21 deraadt Exp $ */ +/* $NetBSD: skeleton.c,v 1.10 1996/03/25 00:36:18 mrg Exp $ */ +/* + * Copyright (c) 1989 The Regents of the University of California. + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Robert Paul Corbett. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef lint +#if 0 +static char sccsid[] = "@(#)skeleton.c 5.8 (Berkeley) 4/29/95"; +#else +static char rcsid[] = "$NetBSD: skeleton.c,v 1.10 1996/03/25 00:36:18 mrg Exp $"; +#endif +#endif /* not lint */ + #include "defs.h" /* The definition of yysccsid in the banner should be replaced with */ @@ -18,8 +63,9 @@ { "#ifndef lint", "/*static char yysccsid[] = \"from: @(#)yaccpar 1.9 (Berkeley) 02/21/93\";*/", - "static char yyrcsid[] = \"$OpenBSD: skeleton.c,v 1.3 1996/03/27 19:33:21 niklas Exp $\";", + "static char yyrcsid[] = \"$OpenBSD: skeleton.c,v 1.4 1996/04/21 23:45:21 deraadt Exp $\";", "#endif", + "#include ", "#define YYBYACC 1", "#define YYMAJOR 1", "#define YYMINOR 9", @@ -60,10 +106,11 @@ "#ifdef YYMAXDEPTH", "#define YYSTACKSIZE YYMAXDEPTH", "#else", - "#define YYSTACKSIZE 500", - "#define YYMAXDEPTH 500", + "#define YYSTACKSIZE 10000", + "#define YYMAXDEPTH 10000", "#endif", "#endif", + "#define YYINITSTACKSIZE 200", "int yydebug;", "int yynerrs;", "int yyerrflag;", @@ -72,30 +119,53 @@ "YYSTYPE *yyvsp;", "YYSTYPE yyval;", "YYSTYPE yylval;", - "short yyss[YYSTACKSIZE];", - "YYSTYPE yyvs[YYSTACKSIZE];", - "#define yystacksize YYSTACKSIZE", + "short *yyss;", + "short *yysslim;", + "YYSTYPE *yyvs;", + "int yystacksize;", 0 }; char *body[] = { + "/* allocate initial stack or double stack size, up to YYMAXDEPTH */", + "static int yygrowstack()", + "{", + " int newsize, i;", + " short *newss;", + " YYSTYPE *newvs;", + "", + " if ((newsize = yystacksize) == 0)", + " newsize = YYINITSTACKSIZE;", + " else if (newsize >= YYMAXDEPTH)", + " return -1;", + " else if ((newsize *= 2) > YYMAXDEPTH)", + " newsize = YYMAXDEPTH;", + " i = yyssp - yyss;", + " if ((newss = (short *)realloc(yyss, newsize * sizeof *newss)) == NULL)", + " return -1;", + " yyss = newss;", + " yyssp = newss + i;", + " if ((newvs = (YYSTYPE *)realloc(yyvs, newsize * sizeof *newvs)) == NULL)", + " return -1;", + " yyvs = newvs;", + " yyvsp = newvs + i;", + " yystacksize = newsize;", + " yysslim = yyss + newsize - 1;", + " return 0;", + "}", + "", "#define YYABORT goto yyabort", "#define YYREJECT goto yyabort", "#define YYACCEPT goto yyaccept", "#define YYERROR goto yyerrlab", "int", - "#if defined(__STDC__)", - "yyparse(void)", - "#else", "yyparse()", - "#endif", "{", " register int yym, yyn, yystate;", "#if YYDEBUG", " register char *yys;", - " extern char *getenv();", "", " if (yys = getenv(\"YYDEBUG\"))", " {", @@ -109,6 +179,7 @@ " yyerrflag = 0;", " yychar = (-1);", "", + " if (yyss == NULL && yygrowstack()) goto yyoverflow;", " yyssp = yyss;", " yyvsp = yyvs;", " *yyssp = yystate = 0;", @@ -137,7 +208,7 @@ " printf(\"%sdebug: state %d, shifting to state %d\\n\",", " YYPREFIX, yystate, yytable[yyn]);", "#endif", - " if (yyssp >= yyss + yystacksize - 1)", + " if (yyssp >= yysslim && yygrowstack())", " {", " goto yyoverflow;", " }", @@ -154,6 +225,10 @@ " goto yyreduce;", " }", " if (yyerrflag) goto yyinrecovery;", + "#ifdef lint", + " goto yynewerror;", + "#endif", + "yynewerror:", " yyerror(\"syntax error\");", "#ifdef lint", " goto yyerrlab;", @@ -174,7 +249,7 @@ " printf(\"%sdebug: state %d, error recovery shifting\\", " to state %d\\n\", YYPREFIX, *yyssp, yytable[yyn]);", "#endif", - " if (yyssp >= yyss + yystacksize - 1)", + " if (yyssp >= yysslim && yygrowstack())", " {", " goto yyoverflow;", " }", @@ -271,7 +346,7 @@ " printf(\"%sdebug: after reduction, shifting from state %d \\", "to state %d\\n\", YYPREFIX, *yyssp, yystate);", "#endif", - " if (yyssp >= yyss + yystacksize - 1)", + " if (yyssp >= yysslim && yygrowstack())", " {", " goto yyoverflow;", " }",