header.c (13032B)
1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License, Version 1.0 only 6 * (the "License"). You may not use this file except in compliance 7 * with the License. 8 * 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 * or http://www.opensolaris.org/os/licensing. 11 * See the License for the specific language governing permissions 12 * and limitations under the License. 13 * 14 * When distributing Covered Code, include this CDDL HEADER in each 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 * If applicable, add the following below this CDDL HEADER, with the 17 * fields enclosed by brackets "[]" replaced with your own identifying 18 * information: Portions Copyright [yyyy] [name of copyright owner] 19 * 20 * CDDL HEADER END 21 */ 22 /* 23 * Copyright 2005 Sun Microsystems, Inc. 24 * All rights reserved. 25 * Use is subject to license terms. 26 */ 27 28 /* Copyright (c) 1988 AT&T */ 29 /* All Rights Reserved */ 30 31 /* from OpenSolaris "header.c 6.22 05/06/08 SMI" */ 32 33 /* 34 * Portions Copyright (c) 2005 Gunnar Ritter, Freiburg i. Br., Germany 35 * 36 * Sccsid @(#)header.c 1.12 (gritter) 9/23/06 37 */ 38 39 #include "ldefs.c" 40 41 static void rhd1(void); 42 static void chd1(void); 43 static void chd2(void); 44 static void ctail(void); 45 static void rtail(void); 46 47 void 48 phead1(void) 49 { 50 ratfor ? rhd1() : chd1(); 51 } 52 53 static void 54 chd1(void) 55 { 56 if (*v_stmp == 'y') { 57 extern const char rel[]; 58 fprintf(fout, "\ 59 #if __GNUC__ >= 3 && __GNUC_MINOR__ >= 4 || __GNUC__ >= 4\n\ 60 #define YYUSED __attribute__ ((used))\n\ 61 #elif defined __GNUC__\n\ 62 #define YYUSED __attribute__ ((unused))\n\ 63 #else\n\ 64 #define YYUSED\n\ 65 #endif\n\ 66 static const char yylexid[] USED = \"lex: %s\"\n", rel); 67 } 68 if (handleeuc) { 69 fprintf(fout, "#ifndef EUC\n"); 70 fprintf(fout, "#define EUC\n"); 71 fprintf(fout, "#endif\n"); 72 fprintf(fout, "#include <stdio.h>\n"); 73 fprintf(fout, "#include <stdlib.h>\n"); 74 fprintf(fout, "#ifdef __sun\n"); 75 fprintf(fout, "#include <widec.h>\n"); 76 fprintf(fout, "#else /* !__sun */\n"); 77 fprintf(fout, "#include <wchar.h>\n"); 78 fprintf(fout, "#endif /* !__sun */\n"); 79 if (widecio) { /* -w option */ 80 fprintf(fout, "#define YYTEXT yytext\n"); 81 fprintf(fout, "#define YYLENG yyleng\n"); 82 fprintf(fout, "#ifndef __cplusplus\n"); 83 fprintf(fout, "#define YYINPUT input\n"); 84 fprintf(fout, "#define YYOUTPUT output\n"); 85 fprintf(fout, "#else\n"); 86 fprintf(fout, "#define YYINPUT lex_input\n"); 87 fprintf(fout, "#define YYOUTPUT lex_output\n"); 88 fprintf(fout, "#endif\n"); 89 fprintf(fout, "#define YYUNPUT unput\n"); 90 } else { /* -e option */ 91 fprintf(fout, "#include <limits.h>\n"); 92 fprintf(fout, "#ifdef __sun\n"); 93 fprintf(fout, "#include <sys/euc.h>\n"); 94 fprintf(fout, "#endif /* __sun */\n"); 95 fprintf(fout, "#define YYLEX_E 1\n"); 96 fprintf(fout, "#define YYTEXT yywtext\n"); 97 fprintf(fout, "#define YYLENG yywleng\n"); 98 fprintf(fout, "#define YYINPUT yywinput\n"); 99 fprintf(fout, "#define YYOUTPUT yywoutput\n"); 100 fprintf(fout, "#define YYUNPUT yywunput\n"); 101 } 102 } else { /* ASCII compatibility mode. */ 103 fprintf(fout, "#include <stdio.h>\n"); 104 fprintf(fout, "#include <stdlib.h>\n"); 105 } 106 if (ZCH > NCH) 107 fprintf(fout, "# define U(x) ((x)&0377)\n"); 108 else 109 fprintf(fout, "# define U(x) x\n"); 110 fprintf(fout, "# define NLSTATE yyprevious=YYNEWLINE\n"); 111 fprintf(fout, "# define BEGIN yybgin = yysvec + 1 +\n"); 112 fprintf(fout, "# define INITIAL 0\n"); 113 fprintf(fout, "# define YYLERR yysvec\n"); 114 fprintf(fout, "# define YYSTATE (yyestate-yysvec-1)\n"); 115 if (optim) 116 fprintf(fout, "# define YYOPTIM 1\n"); 117 #ifdef DEBUG 118 fprintf(fout, "# define LEXDEBUG 1\n"); 119 #endif 120 fprintf(fout, "# ifndef YYLMAX \n"); 121 fprintf(fout, "# define YYLMAX BUFSIZ\n"); 122 fprintf(fout, "# endif \n"); 123 fprintf(fout, "#ifndef __cplusplus\n"); 124 if (widecio) 125 fprintf(fout, "# define output(c) (void)putwc(c,yyout)\n"); 126 else 127 fprintf(fout, "# define output(c) (void)putc(c,yyout)\n"); 128 fprintf(fout, "#else\n"); 129 if (widecio) 130 fprintf(fout, "# define lex_output(c) (void)putwc(c,yyout)\n"); 131 else 132 fprintf(fout, "# define lex_output(c) (void)putc(c,yyout)\n"); 133 fprintf(fout, "#endif\n"); 134 fprintf(fout, "\n#if defined(__cplusplus) || defined(__STDC__)\n"); 135 fprintf(fout, "\n#if defined(__cplusplus) && defined(__EXTERN_C__)\n"); 136 fprintf(fout, "extern \"C\" {\n"); 137 fprintf(fout, "#endif\n"); 138 fprintf(fout, "\tint yyback(int *, int);\n"); /* ? */ 139 fprintf(fout, "\tint yyinput(void);\n"); /* ? */ 140 fprintf(fout, "\tint yylook(void);\n"); /* ? */ 141 fprintf(fout, "\tvoid yyoutput(int);\n"); /* ? */ 142 fprintf(fout, "\tint yyracc(int);\n"); /* ? */ 143 fprintf(fout, "\tint yyreject(void);\n"); /* ? */ 144 fprintf(fout, "\tvoid yyunput(int);\n"); /* ? */ 145 fprintf(fout, "\tint yylex(void);\n"); 146 fprintf(fout, "#ifdef YYLEX_E\n"); 147 fprintf(fout, "\tvoid yywoutput(wchar_t);\n"); 148 fprintf(fout, "\twchar_t yywinput(void);\n"); 149 fprintf(fout, "\tvoid yywunput(wchar_t);\n"); 150 fprintf(fout, "#endif\n"); 151 152 /* XCU4: type of yyless is int */ 153 fprintf(fout, "#ifndef yyless\n"); 154 fprintf(fout, "\tint yyless(int);\n"); 155 fprintf(fout, "#endif\n"); 156 fprintf(fout, "#ifndef yywrap\n"); 157 fprintf(fout, "\tint yywrap(void);\n"); 158 fprintf(fout, "#endif\n"); 159 fprintf(fout, "#ifdef LEXDEBUG\n"); 160 fprintf(fout, "\tvoid allprint(char);\n"); 161 fprintf(fout, "\tvoid sprint(char *);\n"); 162 fprintf(fout, "#endif\n"); 163 fprintf(fout, 164 "#if defined(__cplusplus) && defined(__EXTERN_C__)\n"); 165 fprintf(fout, "}\n"); 166 fprintf(fout, "#endif\n\n"); 167 fprintf(fout, "#ifdef __cplusplus\n"); 168 fprintf(fout, "extern \"C\" {\n"); 169 fprintf(fout, "#endif\n"); 170 fprintf(fout, "\tvoid exit(int);\n"); 171 fprintf(fout, "#ifdef __cplusplus\n"); 172 fprintf(fout, "}\n"); 173 fprintf(fout, "#endif\n\n"); 174 fprintf(fout, "#endif\n"); 175 fprintf(fout, 176 "# define unput(c)" 177 " {yytchar= (c);if(yytchar=='\\n')yylineno--;*yysptr++=yytchar;}\n"); 178 fprintf(fout, "# define yymore() (yymorfg=1)\n"); 179 if (widecio) { 180 fprintf(fout, "#ifndef __cplusplus\n"); 181 fprintf(fout, "%s%d%s\n", 182 "# define input() (((yytchar=yysptr>yysbuf?U(*--yysptr):yygetwchar())==", 183 ctable['\n'], 184 "?(yylineno++,yytchar):yytchar)==EOF?0:yytchar)"); 185 fprintf(fout, "#else\n"); 186 fprintf(fout, "%s%d%s\n", 187 "# define lex_input() (((yytchar=yysptr>yysbuf?U(*--yysptr):yygetwchar())==", 188 ctable['\n'], 189 "?(yylineno++,yytchar):yytchar)==EOF?0:yytchar)"); 190 fprintf(fout, "#endif\n"); 191 fprintf(fout, 192 "# define ECHO (void)fprintf(yyout, \"%%ls\",yytext)\n"); 193 fprintf(fout, 194 "# define REJECT { nstr = yyreject_w(); goto yyfussy;}\n"); 195 fprintf(fout, "#define yyless yyless_w\n"); 196 fprintf(fout, "int yyreject_w(void);\n"); 197 fprintf(fout, "int yyleng;\n"); 198 199 /* 200 * XCU4: 201 * If %array, yytext[] contains the token. 202 * If %pointer, yytext is a pointer to yy_tbuf[]. 203 */ 204 205 if (isArray) { 206 fprintf(fout, "#define YYISARRAY\n"); 207 fprintf(fout, "wchar_t yytext[YYLMAX];\n"); 208 } else { 209 fprintf(fout, "wchar_t yy_tbuf[YYLMAX];\n"); 210 fprintf(fout, "wchar_t * yytext = yy_tbuf;\n"); 211 fprintf(fout, "int yytextsz = YYLMAX;\n"); 212 fprintf(fout, "#ifndef YYTEXTSZINC\n"); 213 fprintf(fout, "#define YYTEXTSZINC 100\n"); 214 fprintf(fout, "#endif\n"); 215 } 216 } else { 217 fprintf(fout, "#ifndef __cplusplus\n"); 218 fprintf(fout, "%s%d%s\n", 219 "# define input() (((yytchar=yysptr>yysbuf?U(*--yysptr):getc(yyin))==", 220 ctable['\n'], 221 "?(yylineno++,yytchar):yytchar)==EOF?0:yytchar)"); 222 fprintf(fout, "#else\n"); 223 fprintf(fout, "%s%d%s\n", 224 "# define lex_input() (((yytchar=yysptr>yysbuf?U(*--yysptr):getc(yyin))==", 225 ctable['\n'], 226 "?(yylineno++,yytchar):yytchar)==EOF?0:yytchar)"); 227 fprintf(fout, "#endif\n"); 228 fprintf(fout, "#define ECHO fprintf(yyout, \"%%s\",yytext)\n"); 229 if (handleeuc) { 230 fprintf(fout, 231 "# define REJECT { nstr = yyreject_e(); goto yyfussy;}\n"); 232 fprintf(fout, "int yyreject_e(void);\n"); 233 fprintf(fout, "int yyleng;\n"); 234 fprintf(fout, "size_t yywleng;\n"); 235 /* 236 * XCU4: 237 * If %array, yytext[] contains the token. 238 * If %pointer, yytext is a pointer to yy_tbuf[]. 239 */ 240 if (isArray) { 241 fprintf(fout, "#define YYISARRAY\n"); 242 fprintf(fout, 243 "unsigned char yytext[YYLMAX*MB_LEN_MAX];\n"); 244 fprintf(fout, 245 "wchar_t yywtext[YYLMAX];\n"); 246 } else { 247 fprintf(fout, 248 "wchar_t yy_twbuf[YYLMAX];\n"); 249 fprintf(fout, 250 "wchar_t yy_tbuf[YYLMAX*MB_LEN_MAX];\n"); 251 fprintf(fout, 252 "unsigned char * yytext =" 253 "(unsigned char *)yy_tbuf;\n"); 254 fprintf(fout, 255 "wchar_t * yywtext = yy_twbuf;\n"); 256 fprintf(fout, 257 "int yytextsz = YYLMAX;\n"); 258 fprintf(fout, "#ifndef YYTEXTSZINC\n"); 259 fprintf(fout, "#define YYTEXTSZINC 100\n"); 260 fprintf(fout, "#endif\n"); 261 } 262 } else { 263 fprintf(fout, 264 "# define REJECT { nstr = yyreject(); goto yyfussy;}\n"); 265 fprintf(fout, "int yyleng;\n"); 266 267 /* 268 * XCU4: 269 * If %array, yytext[] contains the token. 270 * If %pointer, yytext is a pointer to yy_tbuf[]. 271 */ 272 if (isArray) { 273 fprintf(fout, "#define YYISARRAY\n"); 274 fprintf(fout, "char yytext[YYLMAX];\n"); 275 } else { 276 fprintf(fout, "char yy_tbuf[YYLMAX];\n"); 277 fprintf(fout, 278 "char * yytext = yy_tbuf;\n"); 279 fprintf(fout, 280 "int yytextsz = YYLMAX;\n"); 281 fprintf(fout, "#ifndef YYTEXTSZINC\n"); 282 fprintf(fout, 283 "#define YYTEXTSZINC 100\n"); 284 fprintf(fout, "#endif\n"); 285 } 286 } 287 } 288 fprintf(fout, "int yymorfg;\n"); 289 if (handleeuc) 290 fprintf(fout, "extern wchar_t *yysptr, yysbuf[];\n"); 291 else 292 fprintf(fout, "extern char *yysptr, yysbuf[];\n"); 293 fprintf(fout, "int yytchar;\n"); 294 fprintf(fout, "FILE *yyin = (FILE *)-1, *yyout = (FILE *)-1;\n"); 295 fprintf(fout, "#if defined (__GNUC__)\n"); 296 fprintf(fout, 297 "static void _yyioinit(void) __attribute__ ((constructor));\n"); 298 fprintf(fout, "#elif defined (__SUNPRO_C)\n"); 299 fprintf(fout, "#pragma init (_yyioinit)\n"); 300 fprintf(fout, "#elif defined (__HP_aCC) || defined (__hpux)\n"); 301 fprintf(fout, "#pragma INIT \"_yyioinit\"\n"); 302 fprintf(fout, "#endif\n"); 303 fprintf(fout, "static void _yyioinit(void) {\n"); 304 fprintf(fout, "yyin = stdin; yyout = stdout; }\n"); 305 fprintf(fout, "extern int yylineno;\n"); 306 fprintf(fout, "struct yysvf { \n"); 307 fprintf(fout, "\tstruct yywork *yystoff;\n"); 308 fprintf(fout, "\tstruct yysvf *yyother;\n"); 309 fprintf(fout, "\tint *yystops;};\n"); 310 fprintf(fout, "struct yysvf *yyestate;\n"); 311 fprintf(fout, "extern struct yysvf yysvec[], *yybgin;\n"); 312 } 313 314 static void 315 rhd1(void) 316 { 317 fprintf(fout, "integer function yylex(dummy)\n"); 318 fprintf(fout, "define YYLMAX 200\n"); 319 fprintf(fout, "define ECHO call yyecho(yytext,yyleng)\n"); 320 fprintf(fout, 321 "define REJECT nstr = yyrjct(yytext,yyleng);goto 30998\n"); 322 fprintf(fout, "integer nstr,yylook,yywrap\n"); 323 fprintf(fout, "integer yyleng, yytext(YYLMAX)\n"); 324 fprintf(fout, "common /yyxel/ yyleng, yytext\n"); 325 fprintf(fout, 326 "common /yyldat/ yyfnd, yymorf, yyprev, yybgin, yylsp, yylsta\n"); 327 fprintf(fout, 328 "integer yyfnd, yymorf, yyprev, yybgin, yylsp, yylsta(YYLMAX)\n"); 329 fprintf(fout, "for(;;){\n"); 330 fprintf(fout, "\t30999 nstr = yylook(dummy)\n"); 331 fprintf(fout, "\tgoto 30998\n"); 332 fprintf(fout, "\t30000 k = yywrap(dummy)\n"); 333 fprintf(fout, "\tif(k .ne. 0){\n"); 334 fprintf(fout, "\tyylex=0; return; }\n"); 335 fprintf(fout, "\t\telse goto 30998\n"); 336 } 337 338 void 339 phead2(void) 340 { 341 if (!ratfor) 342 chd2(); 343 } 344 345 static void 346 chd2(void) 347 { 348 fprintf(fout, "if (yyin == (FILE *)-1) yyin = stdin;\n"); 349 fprintf(fout, "if (yyout == (FILE *)-1) yyout = stdout;\n"); 350 fprintf(fout, "#if defined (__cplusplus) || defined (__GNUC__)\n"); 351 fprintf(fout, 352 "/* to avoid CC and lint complaining yyfussy not being used ...*/\n"); 353 fprintf(fout, "{static int __lex_hack = 0;\n"); 354 fprintf(fout, "if (__lex_hack) { yyprevious = 0; goto yyfussy; } }\n"); 355 fprintf(fout, "#endif\n"); 356 fprintf(fout, "while((nstr = yylook()) >= 0)\n"); 357 fprintf(fout, "yyfussy: switch(nstr){\n"); 358 fprintf(fout, "case 0:\n"); 359 fprintf(fout, "if(yywrap()) return(0); break;\n"); 360 } 361 362 void 363 ptail(void) 364 { 365 if (!pflag) 366 ratfor ? rtail() : ctail(); 367 pflag = 1; 368 } 369 370 static void 371 ctail(void) 372 { 373 fprintf(fout, "case -1:\nbreak;\n"); /* for reject */ 374 fprintf(fout, "default:\n"); 375 fprintf(fout, 376 "(void)fprintf(yyout,\"bad switch yylook %%d\",nstr);\n"); 377 fprintf(fout, "} return(0); }\n"); 378 fprintf(fout, "/* end of yylex */\n"); 379 } 380 381 static void 382 rtail(void) 383 { 384 int i; 385 fprintf(fout, 386 "\n30998 if(nstr .lt. 0 .or. nstr .gt. %d)goto 30999\n", casecount); 387 fprintf(fout, "nstr = nstr + 1\n"); 388 fprintf(fout, "goto(\n"); 389 for (i = 0; i < casecount; i++) 390 fprintf(fout, "%d,\n", 30000+i); 391 fprintf(fout, "30999),nstr\n"); 392 fprintf(fout, "30997 continue\n"); 393 fprintf(fout, "}\nend\n"); 394 } 395 396 void 397 statistics(void) 398 { 399 fprintf(errorf, 400 "%d/%d nodes(%%e), %d/%d positions(%%p), %d/%d (%%n), %ld transitions,\n", 401 tptr, treesize, nxtpos-positions, maxpos, stnum + 1, nstates, rcount); 402 fprintf(errorf, 403 "%d/%d packed char classes(%%k), ", pcptr-pchar, pchlen); 404 if (optim) 405 fprintf(errorf, 406 " %d/%d packed transitions(%%a), ", nptr, ntrans); 407 fprintf(errorf, " %d/%d output slots(%%o)", yytop, outsize); 408 putc('\n', errorf); 409 }