1 /* $OpenBSD: skeleton.c,v 1.6 1996/07/28 02:03:26 deraadt Exp $ */ 2 /* $NetBSD: skeleton.c,v 1.10 1996/03/25 00:36:18 mrg Exp $ */ 3 4 /* 5 * Copyright (c) 1989 The Regents of the University of California. 6 * All rights reserved. 7 * 8 * This code is derived from software contributed to Berkeley by 9 * Robert Paul Corbett. 10 * 11 * Redistribution and use in source and binary forms, with or without 12 * modification, are permitted provided that the following conditions 13 * are met: 14 * 1. Redistributions of source code must retain the above copyright 15 * notice, this list of conditions and the following disclaimer. 16 * 2. Redistributions in binary form must reproduce the above copyright 17 * notice, this list of conditions and the following disclaimer in the 18 * documentation and/or other materials provided with the distribution. 19 * 3. All advertising materials mentioning features or use of this software 20 * must display the following acknowledgement: 21 * This product includes software developed by the University of 22 * California, Berkeley and its contributors. 23 * 4. Neither the name of the University nor the names of its contributors 24 * may be used to endorse or promote products derived from this software 25 * without specific prior written permission. 26 * 27 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 28 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 29 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 30 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 31 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 32 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 33 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 34 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 35 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 36 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 37 * SUCH DAMAGE. 38 */ 39 40 #ifndef lint 41 #if 0 42 static char sccsid[] = "@(#)skeleton.c 5.8 (Berkeley) 4/29/95"; 43 #else 44 static char rcsid[] = "$NetBSD: skeleton.c,v 1.10 1996/03/25 00:36:18 mrg Exp $"; 45 #endif 46 #endif /* not lint */ 47 48 #include "defs.h" 49 50 /* The definition of yysccsid in the banner should be replaced with */ 51 /* a #pragma ident directive if the target C compiler supports */ 52 /* #pragma ident directives. */ 53 /* */ 54 /* If the skeleton is changed, the banner should be changed so that */ 55 /* the altered version can be easily distinguished from the original. */ 56 /* */ 57 /* The #defines included with the banner are there because they are */ 58 /* useful in subsequent code. The macros #defined in the header or */ 59 /* the body either are not useful outside of semantic actions or */ 60 /* are conditional. */ 61 62 char *banner[] = 63 { 64 "#ifndef lint", 65 "/*static char yysccsid[] = \"from: @(#)yaccpar 1.9 (Berkeley) 02/21/93\";*/", 66 "static char yyrcsid[] = \"$OpenBSD: skeleton.c,v 1.6 1996/07/28 02:03:26 deraadt Exp $\";", 67 "#endif", 68 "#include <stdlib.h>", 69 "#define YYBYACC 1", 70 "#define YYMAJOR 1", 71 "#define YYMINOR 9", 72 "#define YYLEX yylex()", 73 "#define YYEMPTY -1", 74 "#define yyclearin (yychar=(YYEMPTY))", 75 "#define yyerrok (yyerrflag=0)", 76 "#define YYRECOVERING (yyerrflag!=0)", 77 0 78 }; 79 80 81 char *tables[] = 82 { 83 "extern short yylhs[];", 84 "extern short yylen[];", 85 "extern short yydefred[];", 86 "extern short yydgoto[];", 87 "extern short yysindex[];", 88 "extern short yyrindex[];", 89 "extern short yygindex[];", 90 "extern short yytable[];", 91 "extern short yycheck[];", 92 "#if YYDEBUG", 93 "extern char *yyname[];", 94 "extern char *yyrule[];", 95 "#endif", 96 0 97 }; 98 99 100 char *header[] = 101 { 102 "#ifdef YYSTACKSIZE", 103 "#undef YYMAXDEPTH", 104 "#define YYMAXDEPTH YYSTACKSIZE", 105 "#else", 106 "#ifdef YYMAXDEPTH", 107 "#define YYSTACKSIZE YYMAXDEPTH", 108 "#else", 109 "#define YYSTACKSIZE 10000", 110 "#define YYMAXDEPTH 10000", 111 "#endif", 112 "#endif", 113 "#define YYINITSTACKSIZE 200", 114 "int yydebug;", 115 "int yynerrs;", 116 "int yyerrflag;", 117 "int yychar;", 118 "short *yyssp;", 119 "YYSTYPE *yyvsp;", 120 "YYSTYPE yyval;", 121 "YYSTYPE yylval;", 122 "short *yyss;", 123 "short *yysslim;", 124 "YYSTYPE *yyvs;", 125 "int yystacksize;", 126 0 127 }; 128 129 130 char *body[] = 131 { 132 "/* allocate initial stack or double stack size, up to YYMAXDEPTH */", 133 "#if defined(__cplusplus) || __STDC__", 134 "static int yygrowstack(void)", 135 "#else", 136 "static int yygrowstack()", 137 "#endif", 138 "{", 139 " int newsize, i;", 140 " short *newss;", 141 " YYSTYPE *newvs;", 142 "", 143 " if ((newsize = yystacksize) == 0)", 144 " newsize = YYINITSTACKSIZE;", 145 " else if (newsize >= YYMAXDEPTH)", 146 " return -1;", 147 " else if ((newsize *= 2) > YYMAXDEPTH)", 148 " newsize = YYMAXDEPTH;", 149 " i = yyssp - yyss;", 150 " if ((newss = (short *)realloc(yyss, newsize * sizeof *newss)) == NULL)", 151 " return -1;", 152 " yyss = newss;", 153 " yyssp = newss + i;", 154 " if ((newvs = (YYSTYPE *)realloc(yyvs, newsize * sizeof *newvs)) == NULL)", 155 " return -1;", 156 " yyvs = newvs;", 157 " yyvsp = newvs + i;", 158 " yystacksize = newsize;", 159 " yysslim = yyss + newsize - 1;", 160 " return 0;", 161 "}", 162 "", 163 "#define YYABORT goto yyabort", 164 "#define YYREJECT goto yyabort", 165 "#define YYACCEPT goto yyaccept", 166 "#define YYERROR goto yyerrlab", 167 "int", 168 "#if defined(__cplusplus) || __STDC__", 169 "yyparse(void)", 170 "#else", 171 "yyparse()", 172 "#endif", 173 "{", 174 " register int yym, yyn, yystate;", 175 "#if YYDEBUG", 176 " register char *yys;", 177 "", 178 " if ((yys = getenv(\"YYDEBUG\")))", 179 " {", 180 " yyn = *yys;", 181 " if (yyn >= '0' && yyn <= '9')", 182 " yydebug = yyn - '0';", 183 " }", 184 "#endif", 185 "", 186 " yynerrs = 0;", 187 " yyerrflag = 0;", 188 " yychar = (-1);", 189 "", 190 " if (yyss == NULL && yygrowstack()) goto yyoverflow;", 191 " yyssp = yyss;", 192 " yyvsp = yyvs;", 193 " *yyssp = yystate = 0;", 194 "", 195 "yyloop:", 196 " if ((yyn = yydefred[yystate]) != 0) goto yyreduce;", 197 " if (yychar < 0)", 198 " {", 199 " if ((yychar = yylex()) < 0) yychar = 0;", 200 "#if YYDEBUG", 201 " if (yydebug)", 202 " {", 203 " yys = 0;", 204 " if (yychar <= YYMAXTOKEN) yys = yyname[yychar];", 205 " if (!yys) yys = \"illegal-symbol\";", 206 " printf(\"%sdebug: state %d, reading %d (%s)\\n\",", 207 " YYPREFIX, yystate, yychar, yys);", 208 " }", 209 "#endif", 210 " }", 211 " if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 &&", 212 " yyn <= YYTABLESIZE && yycheck[yyn] == yychar)", 213 " {", 214 "#if YYDEBUG", 215 " if (yydebug)", 216 " printf(\"%sdebug: state %d, shifting to state %d\\n\",", 217 " YYPREFIX, yystate, yytable[yyn]);", 218 "#endif", 219 " if (yyssp >= yysslim && yygrowstack())", 220 " {", 221 " goto yyoverflow;", 222 " }", 223 " *++yyssp = yystate = yytable[yyn];", 224 " *++yyvsp = yylval;", 225 " yychar = (-1);", 226 " if (yyerrflag > 0) --yyerrflag;", 227 " goto yyloop;", 228 " }", 229 " if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 &&", 230 " yyn <= YYTABLESIZE && yycheck[yyn] == yychar)", 231 " {", 232 " yyn = yytable[yyn];", 233 " goto yyreduce;", 234 " }", 235 " if (yyerrflag) goto yyinrecovery;", 236 "#ifdef lint", 237 " goto yynewerror;", 238 "#endif", 239 "yynewerror:", 240 " yyerror(\"syntax error\");", 241 "#ifdef lint", 242 " goto yyerrlab;", 243 "#endif", 244 "yyerrlab:", 245 " ++yynerrs;", 246 "yyinrecovery:", 247 " if (yyerrflag < 3)", 248 " {", 249 " yyerrflag = 3;", 250 " for (;;)", 251 " {", 252 " if ((yyn = yysindex[*yyssp]) && (yyn += YYERRCODE) >= 0 &&", 253 " yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE)", 254 " {", 255 "#if YYDEBUG", 256 " if (yydebug)", 257 " printf(\"%sdebug: state %d, error recovery shifting\\", 258 " to state %d\\n\", YYPREFIX, *yyssp, yytable[yyn]);", 259 "#endif", 260 " if (yyssp >= yysslim && yygrowstack())", 261 " {", 262 " goto yyoverflow;", 263 " }", 264 " *++yyssp = yystate = yytable[yyn];", 265 " *++yyvsp = yylval;", 266 " goto yyloop;", 267 " }", 268 " else", 269 " {", 270 "#if YYDEBUG", 271 " if (yydebug)", 272 " printf(\"%sdebug: error recovery discarding state %d\ 273 \\n\",", 274 " YYPREFIX, *yyssp);", 275 "#endif", 276 " if (yyssp <= yyss) goto yyabort;", 277 " --yyssp;", 278 " --yyvsp;", 279 " }", 280 " }", 281 " }", 282 " else", 283 " {", 284 " if (yychar == 0) goto yyabort;", 285 "#if YYDEBUG", 286 " if (yydebug)", 287 " {", 288 " yys = 0;", 289 " if (yychar <= YYMAXTOKEN) yys = yyname[yychar];", 290 " if (!yys) yys = \"illegal-symbol\";", 291 " printf(\"%sdebug: state %d, error recovery discards token %d\ 292 (%s)\\n\",", 293 " YYPREFIX, yystate, yychar, yys);", 294 " }", 295 "#endif", 296 " yychar = (-1);", 297 " goto yyloop;", 298 " }", 299 "yyreduce:", 300 "#if YYDEBUG", 301 " if (yydebug)", 302 " printf(\"%sdebug: state %d, reducing by rule %d (%s)\\n\",", 303 " YYPREFIX, yystate, yyn, yyrule[yyn]);", 304 "#endif", 305 " yym = yylen[yyn];", 306 " yyval = yyvsp[1-yym];", 307 " switch (yyn)", 308 " {", 309 0 310 }; 311 312 313 char *trailer[] = 314 { 315 " }", 316 " yyssp -= yym;", 317 " yystate = *yyssp;", 318 " yyvsp -= yym;", 319 " yym = yylhs[yyn];", 320 " if (yystate == 0 && yym == 0)", 321 " {", 322 "#if YYDEBUG", 323 " if (yydebug)", 324 " printf(\"%sdebug: after reduction, shifting from state 0 to\\", 325 " state %d\\n\", YYPREFIX, YYFINAL);", 326 "#endif", 327 " yystate = YYFINAL;", 328 " *++yyssp = YYFINAL;", 329 " *++yyvsp = yyval;", 330 " if (yychar < 0)", 331 " {", 332 " if ((yychar = yylex()) < 0) yychar = 0;", 333 "#if YYDEBUG", 334 " if (yydebug)", 335 " {", 336 " yys = 0;", 337 " if (yychar <= YYMAXTOKEN) yys = yyname[yychar];", 338 " if (!yys) yys = \"illegal-symbol\";", 339 " printf(\"%sdebug: state %d, reading %d (%s)\\n\",", 340 " YYPREFIX, YYFINAL, yychar, yys);", 341 " }", 342 "#endif", 343 " }", 344 " if (yychar == 0) goto yyaccept;", 345 " goto yyloop;", 346 " }", 347 " if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 &&", 348 " yyn <= YYTABLESIZE && yycheck[yyn] == yystate)", 349 " yystate = yytable[yyn];", 350 " else", 351 " yystate = yydgoto[yym];", 352 "#if YYDEBUG", 353 " if (yydebug)", 354 " printf(\"%sdebug: after reduction, shifting from state %d \\", 355 "to state %d\\n\", YYPREFIX, *yyssp, yystate);", 356 "#endif", 357 " if (yyssp >= yysslim && yygrowstack())", 358 " {", 359 " goto yyoverflow;", 360 " }", 361 " *++yyssp = yystate;", 362 " *++yyvsp = yyval;", 363 " goto yyloop;", 364 "yyoverflow:", 365 " yyerror(\"yacc stack overflow\");", 366 "yyabort:", 367 " return (1);", 368 "yyaccept:", 369 " return (0);", 370 "}", 371 0 372 }; 373 374 375 write_section(section) 376 char *section[]; 377 { 378 register int c; 379 register int i; 380 register char *s; 381 register FILE *f; 382 383 f = code_file; 384 for (i = 0; s = section[i]; ++i) 385 { 386 ++outline; 387 while (c = *s) 388 { 389 putc(c, f); 390 ++s; 391 } 392 putc('\n', f); 393 } 394 } 395