xref: /onnv-gate/usr/src/cmd/sgs/lex/common/header.c (revision 6951:59445bec7ef4)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
54538Sdamico  * Common Development and Distribution License (the "License").
64538Sdamico  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
210Sstevel@tonic-gate /*
22*6951Sab196087  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
230Sstevel@tonic-gate  * Use is subject to license terms.
240Sstevel@tonic-gate  */
250Sstevel@tonic-gate 
260Sstevel@tonic-gate /*	Copyright (c) 1988 AT&T	*/
270Sstevel@tonic-gate /*	All Rights Reserved	*/
280Sstevel@tonic-gate 
290Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
300Sstevel@tonic-gate 
314538Sdamico #include "ldefs.h"
320Sstevel@tonic-gate 
330Sstevel@tonic-gate static void rhd1(void);
340Sstevel@tonic-gate static void chd1(void);
350Sstevel@tonic-gate static void chd2(void);
360Sstevel@tonic-gate static void ctail(void);
370Sstevel@tonic-gate static void rtail(void);
380Sstevel@tonic-gate 
390Sstevel@tonic-gate void
phead1(void)400Sstevel@tonic-gate phead1(void)
410Sstevel@tonic-gate {
420Sstevel@tonic-gate 	ratfor ? rhd1() : chd1();
430Sstevel@tonic-gate }
440Sstevel@tonic-gate 
450Sstevel@tonic-gate static void
chd1(void)460Sstevel@tonic-gate chd1(void)
470Sstevel@tonic-gate {
480Sstevel@tonic-gate 	if (*v_stmp == 'y')
49*6951Sab196087 		(void) fprintf(fout, "#ident\t\"lex: %s %s\"\n",
500Sstevel@tonic-gate 		    (const char *)SGU_PKG, (const char *)SGU_REL);
510Sstevel@tonic-gate 	if (handleeuc) {
52*6951Sab196087 		(void) fprintf(fout, "#ifndef EUC\n");
53*6951Sab196087 		(void) fprintf(fout, "#define EUC\n");
54*6951Sab196087 		(void) fprintf(fout, "#endif\n");
55*6951Sab196087 		(void) fprintf(fout, "#include <stdio.h>\n");
56*6951Sab196087 		(void) fprintf(fout, "#include <stdlib.h>\n");
57*6951Sab196087 		(void) fprintf(fout, "#include <inttypes.h>\n");
58*6951Sab196087 		(void) fprintf(fout, "#include <widec.h>\n");
590Sstevel@tonic-gate 		if (widecio) { /* -w option */
60*6951Sab196087 			(void) fprintf(fout, "#define YYTEXT yytext\n");
61*6951Sab196087 			(void) fprintf(fout, "#define YYLENG yyleng\n");
62*6951Sab196087 			(void) fprintf(fout, "#ifndef __cplusplus\n");
63*6951Sab196087 			(void) fprintf(fout, "#define YYINPUT input\n");
64*6951Sab196087 			(void) fprintf(fout, "#define YYOUTPUT output\n");
65*6951Sab196087 			(void) fprintf(fout, "#else\n");
66*6951Sab196087 			(void) fprintf(fout, "#define YYINPUT lex_input\n");
67*6951Sab196087 			(void) fprintf(fout, "#define YYOUTPUT lex_output\n");
68*6951Sab196087 			(void) fprintf(fout, "#endif\n");
69*6951Sab196087 			(void) fprintf(fout, "#define YYUNPUT unput\n");
700Sstevel@tonic-gate 		} else { /* -e option */
71*6951Sab196087 			(void) fprintf(fout, "#include <limits.h>\n");
72*6951Sab196087 			(void) fprintf(fout, "#include <sys/euc.h>\n");
73*6951Sab196087 			(void) fprintf(fout, "#define YYLEX_E 1\n");
74*6951Sab196087 			(void) fprintf(fout, "#define YYTEXT yywtext\n");
75*6951Sab196087 			(void) fprintf(fout, "#define YYLENG yywleng\n");
76*6951Sab196087 			(void) fprintf(fout, "#define YYINPUT yywinput\n");
77*6951Sab196087 			(void) fprintf(fout, "#define YYOUTPUT yywoutput\n");
78*6951Sab196087 			(void) fprintf(fout, "#define YYUNPUT yywunput\n");
790Sstevel@tonic-gate 		}
800Sstevel@tonic-gate 	} else { /* ASCII compatibility mode. */
81*6951Sab196087 		(void) fprintf(fout, "#include <stdio.h>\n");
82*6951Sab196087 		(void) fprintf(fout, "#include <stdlib.h>\n");
83*6951Sab196087 		(void) fprintf(fout, "#include <inttypes.h>\n");
840Sstevel@tonic-gate 	}
850Sstevel@tonic-gate 	if (ZCH > NCH)
860Sstevel@tonic-gate 		(void) fprintf(fout, "# define U(x) ((x)&0377)\n");
870Sstevel@tonic-gate 	else
880Sstevel@tonic-gate 	(void) fprintf(fout, "# define U(x) x\n");
890Sstevel@tonic-gate 	(void) fprintf(fout, "# define NLSTATE yyprevious=YYNEWLINE\n");
900Sstevel@tonic-gate 	(void) fprintf(fout, "# define BEGIN yybgin = yysvec + 1 +\n");
910Sstevel@tonic-gate 	(void) fprintf(fout, "# define INITIAL 0\n");
920Sstevel@tonic-gate 	(void) fprintf(fout, "# define YYLERR yysvec\n");
930Sstevel@tonic-gate 	(void) fprintf(fout, "# define YYSTATE (yyestate-yysvec-1)\n");
940Sstevel@tonic-gate 	if (optim)
950Sstevel@tonic-gate 		(void) fprintf(fout, "# define YYOPTIM 1\n");
960Sstevel@tonic-gate #ifdef DEBUG
970Sstevel@tonic-gate 	(void) fprintf(fout, "# define LEXDEBUG 1\n");
980Sstevel@tonic-gate #endif
990Sstevel@tonic-gate 	(void) fprintf(fout, "# ifndef YYLMAX \n");
1000Sstevel@tonic-gate 	(void) fprintf(fout, "# define YYLMAX BUFSIZ\n");
1010Sstevel@tonic-gate 	(void) fprintf(fout, "# endif \n");
1020Sstevel@tonic-gate 	(void) fprintf(fout, "#ifndef __cplusplus\n");
1030Sstevel@tonic-gate 	if (widecio)
1040Sstevel@tonic-gate 		(void) fprintf(fout,
1050Sstevel@tonic-gate 		"# define output(c) (void)putwc(c,yyout)\n");
1060Sstevel@tonic-gate 	else
1070Sstevel@tonic-gate 		(void) fprintf(fout,
1080Sstevel@tonic-gate 		"# define output(c) (void)putc(c,yyout)\n");
1090Sstevel@tonic-gate 	(void) fprintf(fout, "#else\n");
1100Sstevel@tonic-gate 	if (widecio)
1110Sstevel@tonic-gate 		(void) fprintf(fout,
1120Sstevel@tonic-gate 		"# define lex_output(c) (void)putwc(c,yyout)\n");
1130Sstevel@tonic-gate 	else
1140Sstevel@tonic-gate 		(void) fprintf(fout,
1150Sstevel@tonic-gate 		"# define lex_output(c) (void)putc(c,yyout)\n");
1160Sstevel@tonic-gate 	(void) fprintf(fout, "#endif\n");
1170Sstevel@tonic-gate 	(void) fprintf(fout,
1180Sstevel@tonic-gate 	"\n#if defined(__cplusplus) || defined(__STDC__)\n");
1190Sstevel@tonic-gate 	(void) fprintf(fout,
1200Sstevel@tonic-gate 	"\n#if defined(__cplusplus) && defined(__EXTERN_C__)\n");
1210Sstevel@tonic-gate 	(void) fprintf(fout, "extern \"C\" {\n");
1220Sstevel@tonic-gate 	(void) fprintf(fout, "#endif\n");
1230Sstevel@tonic-gate 	(void) fprintf(fout, "\tint yyback(int *, int);\n"); /* ? */
1240Sstevel@tonic-gate 	(void) fprintf(fout, "\tint yyinput(void);\n"); /* ? */
1250Sstevel@tonic-gate 	(void) fprintf(fout, "\tint yylook(void);\n"); /* ? */
1260Sstevel@tonic-gate 	(void) fprintf(fout, "\tvoid yyoutput(int);\n"); /* ? */
1270Sstevel@tonic-gate 	(void) fprintf(fout, "\tint yyracc(int);\n"); /* ? */
1280Sstevel@tonic-gate 	(void) fprintf(fout, "\tint yyreject(void);\n"); /* ? */
1290Sstevel@tonic-gate 	(void) fprintf(fout, "\tvoid yyunput(int);\n"); /* ? */
1300Sstevel@tonic-gate 	(void) fprintf(fout, "\tint yylex(void);\n");
1310Sstevel@tonic-gate 	(void) fprintf(fout, "#ifdef YYLEX_E\n");
1320Sstevel@tonic-gate 	(void) fprintf(fout, "\tvoid yywoutput(wchar_t);\n");
1330Sstevel@tonic-gate 	(void) fprintf(fout, "\twchar_t yywinput(void);\n");
1340Sstevel@tonic-gate 	(void) fprintf(fout, "\tvoid yywunput(wchar_t);\n");
1350Sstevel@tonic-gate 	(void) fprintf(fout, "#endif\n");
1360Sstevel@tonic-gate 
1370Sstevel@tonic-gate 	/* XCU4: type of yyless is int */
1380Sstevel@tonic-gate 	(void) fprintf(fout, "#ifndef yyless\n");
1390Sstevel@tonic-gate 	(void) fprintf(fout, "\tint yyless(int);\n");
1400Sstevel@tonic-gate 	(void) fprintf(fout, "#endif\n");
1410Sstevel@tonic-gate 	(void) fprintf(fout, "#ifndef yywrap\n");
1420Sstevel@tonic-gate 	(void) fprintf(fout, "\tint yywrap(void);\n");
1430Sstevel@tonic-gate 	(void) fprintf(fout, "#endif\n");
1440Sstevel@tonic-gate 	(void) fprintf(fout, "#ifdef LEXDEBUG\n");
1450Sstevel@tonic-gate 	(void) fprintf(fout, "\tvoid allprint(char);\n");
1460Sstevel@tonic-gate 	(void) fprintf(fout, "\tvoid sprint(char *);\n");
1470Sstevel@tonic-gate 	(void) fprintf(fout, "#endif\n");
1480Sstevel@tonic-gate 	(void) fprintf(fout,
1490Sstevel@tonic-gate 	"#if defined(__cplusplus) && defined(__EXTERN_C__)\n");
1500Sstevel@tonic-gate 	(void) fprintf(fout, "}\n");
1510Sstevel@tonic-gate 	(void) fprintf(fout, "#endif\n\n");
1520Sstevel@tonic-gate 	(void) fprintf(fout, "#ifdef __cplusplus\n");
1530Sstevel@tonic-gate 	(void) fprintf(fout, "extern \"C\" {\n");
1540Sstevel@tonic-gate 	(void) fprintf(fout, "#endif\n");
1550Sstevel@tonic-gate 	(void) fprintf(fout, "\tvoid exit(int);\n");
1560Sstevel@tonic-gate 	(void) fprintf(fout, "#ifdef __cplusplus\n");
1570Sstevel@tonic-gate 	(void) fprintf(fout, "}\n");
1580Sstevel@tonic-gate 	(void) fprintf(fout, "#endif\n\n");
1590Sstevel@tonic-gate 	(void) fprintf(fout, "#endif\n");
1600Sstevel@tonic-gate 	(void) fprintf(fout,
1610Sstevel@tonic-gate 	"# define unput(c)"
1620Sstevel@tonic-gate 	" {yytchar= (c);if(yytchar=='\\n')yylineno--;*yysptr++=yytchar;}\n");
1630Sstevel@tonic-gate 	(void) fprintf(fout, "# define yymore() (yymorfg=1)\n");
1640Sstevel@tonic-gate 	if (widecio) {
1650Sstevel@tonic-gate 		(void) fprintf(fout, "#ifndef __cplusplus\n");
1660Sstevel@tonic-gate 		(void) fprintf(fout, "%s%d%s\n",
1670Sstevel@tonic-gate "# define input() (((yytchar=yysptr>yysbuf?U(*--yysptr):getwc(yyin))==",
1684538Sdamico 		    ctable['\n'],
1690Sstevel@tonic-gate "?(yylineno++,yytchar):yytchar)==EOF?0:yytchar)");
1700Sstevel@tonic-gate 		(void) fprintf(fout, "#else\n");
1710Sstevel@tonic-gate 		(void) fprintf(fout, "%s%d%s\n",
1720Sstevel@tonic-gate "# define lex_input() (((yytchar=yysptr>yysbuf?U(*--yysptr):getwc(yyin))==",
1734538Sdamico 		    ctable['\n'],
1740Sstevel@tonic-gate "?(yylineno++,yytchar):yytchar)==EOF?0:yytchar)");
1750Sstevel@tonic-gate 		(void) fprintf(fout, "#endif\n");
1760Sstevel@tonic-gate 		(void) fprintf(fout,
1770Sstevel@tonic-gate 		"# define ECHO (void)fprintf(yyout, \"%%ws\",yytext)\n");
1780Sstevel@tonic-gate 		(void) fprintf(fout,
1790Sstevel@tonic-gate 		"# define REJECT { nstr = yyreject_w(); goto yyfussy;}\n");
1800Sstevel@tonic-gate 		(void) fprintf(fout, "#define yyless yyless_w\n");
1810Sstevel@tonic-gate 		(void) fprintf(fout, "int yyleng;\n");
1820Sstevel@tonic-gate 
1830Sstevel@tonic-gate 		/*
1840Sstevel@tonic-gate 		 * XCU4:
1850Sstevel@tonic-gate 		 * If %array, yytext[] contains the token.
1860Sstevel@tonic-gate 		 * If %pointer, yytext is a pointer to yy_tbuf[].
1870Sstevel@tonic-gate 		 */
1880Sstevel@tonic-gate 
1890Sstevel@tonic-gate 		if (isArray) {
1900Sstevel@tonic-gate 			(void) fprintf(fout, "#define YYISARRAY\n");
1910Sstevel@tonic-gate 			(void) fprintf(fout, "wchar_t yytext[YYLMAX];\n");
1920Sstevel@tonic-gate 		} else {
1930Sstevel@tonic-gate 			(void) fprintf(fout, "wchar_t yy_tbuf[YYLMAX];\n");
1940Sstevel@tonic-gate 			(void) fprintf(fout, "wchar_t * yytext = yy_tbuf;\n");
1950Sstevel@tonic-gate 			(void) fprintf(fout, "int yytextsz = YYLMAX;\n");
1960Sstevel@tonic-gate 			(void) fprintf(fout, "#ifndef YYTEXTSZINC\n");
1970Sstevel@tonic-gate 			(void) fprintf(fout, "#define YYTEXTSZINC 100\n");
1980Sstevel@tonic-gate 			(void) fprintf(fout, "#endif\n");
1990Sstevel@tonic-gate 		}
2000Sstevel@tonic-gate 	} else {
2010Sstevel@tonic-gate 		(void) fprintf(fout, "#ifndef __cplusplus\n");
2020Sstevel@tonic-gate 		(void) fprintf(fout, "%s%d%s\n",
2030Sstevel@tonic-gate "# define input() (((yytchar=yysptr>yysbuf?U(*--yysptr):getc(yyin))==",
2044538Sdamico 		    ctable['\n'],
2050Sstevel@tonic-gate "?(yylineno++,yytchar):yytchar)==EOF?0:yytchar)");
2060Sstevel@tonic-gate 		(void) fprintf(fout, "#else\n");
2070Sstevel@tonic-gate 		(void) fprintf(fout, "%s%d%s\n",
2080Sstevel@tonic-gate "# define lex_input() (((yytchar=yysptr>yysbuf?U(*--yysptr):getc(yyin))==",
2094538Sdamico 		    ctable['\n'],
2100Sstevel@tonic-gate "?(yylineno++,yytchar):yytchar)==EOF?0:yytchar)");
2110Sstevel@tonic-gate 		(void) fprintf(fout, "#endif\n");
212*6951Sab196087 		(void) fprintf(fout,
213*6951Sab196087 		    "#define ECHO fprintf(yyout, \"%%s\",yytext)\n");
2140Sstevel@tonic-gate 		if (handleeuc) {
2150Sstevel@tonic-gate 			(void) fprintf(fout,
2160Sstevel@tonic-gate "# define REJECT { nstr = yyreject_e(); goto yyfussy;}\n");
2170Sstevel@tonic-gate 			(void) fprintf(fout, "int yyleng;\n");
2180Sstevel@tonic-gate 			(void) fprintf(fout, "size_t yywleng;\n");
2190Sstevel@tonic-gate 			/*
2200Sstevel@tonic-gate 			 * XCU4:
2210Sstevel@tonic-gate 			 * If %array, yytext[] contains the token.
2220Sstevel@tonic-gate 			 * If %pointer, yytext is a pointer to yy_tbuf[].
2230Sstevel@tonic-gate 			 */
2240Sstevel@tonic-gate 			if (isArray) {
2250Sstevel@tonic-gate 				(void) fprintf(fout, "#define YYISARRAY\n");
2260Sstevel@tonic-gate 				(void) fprintf(fout,
2270Sstevel@tonic-gate 				"unsigned char yytext[YYLMAX*MB_LEN_MAX];\n");
2280Sstevel@tonic-gate 				(void) fprintf(fout,
2290Sstevel@tonic-gate 				"wchar_t yywtext[YYLMAX];\n");
2300Sstevel@tonic-gate 			} else {
2310Sstevel@tonic-gate 				(void) fprintf(fout,
2320Sstevel@tonic-gate 				"wchar_t yy_twbuf[YYLMAX];\n");
2330Sstevel@tonic-gate 				(void) fprintf(fout,
2340Sstevel@tonic-gate 				"wchar_t yy_tbuf[YYLMAX*MB_LEN_MAX];\n");
2350Sstevel@tonic-gate 				(void) fprintf(fout,
2360Sstevel@tonic-gate 				"unsigned char * yytext ="
2370Sstevel@tonic-gate 				"(unsigned char *)yy_tbuf;\n");
2380Sstevel@tonic-gate 				(void) fprintf(fout,
2390Sstevel@tonic-gate 				"wchar_t * yywtext = yy_twbuf;\n");
2400Sstevel@tonic-gate 				(void) fprintf(fout,
2414538Sdamico 				    "int yytextsz = YYLMAX;\n");
2420Sstevel@tonic-gate 				(void) fprintf(fout, "#ifndef YYTEXTSZINC\n");
2430Sstevel@tonic-gate 				(void) fprintf(fout,
2444538Sdamico 				    "#define YYTEXTSZINC 100\n");
2450Sstevel@tonic-gate 				(void) fprintf(fout, "#endif\n");
2460Sstevel@tonic-gate 			}
2470Sstevel@tonic-gate 		} else {
2480Sstevel@tonic-gate 			(void) fprintf(fout,
2490Sstevel@tonic-gate "# define REJECT { nstr = yyreject(); goto yyfussy;}\n");
2500Sstevel@tonic-gate 			(void) fprintf(fout, "int yyleng;\n");
2510Sstevel@tonic-gate 
2520Sstevel@tonic-gate 			/*
2530Sstevel@tonic-gate 			 * XCU4:
2540Sstevel@tonic-gate 			 * If %array, yytext[] contains the token.
2550Sstevel@tonic-gate 			 * If %pointer, yytext is a pointer to yy_tbuf[].
2560Sstevel@tonic-gate 			 */
2570Sstevel@tonic-gate 			if (isArray) {
2580Sstevel@tonic-gate 				(void) fprintf(fout, "#define YYISARRAY\n");
2590Sstevel@tonic-gate 				(void) fprintf(fout, "char yytext[YYLMAX];\n");
2600Sstevel@tonic-gate 			} else {
2610Sstevel@tonic-gate 				(void) fprintf(fout, "char yy_tbuf[YYLMAX];\n");
2620Sstevel@tonic-gate 				(void) fprintf(fout,
2630Sstevel@tonic-gate 				"char * yytext = yy_tbuf;\n");
2640Sstevel@tonic-gate 				(void) fprintf(fout,
2654538Sdamico 				    "int yytextsz = YYLMAX;\n");
2660Sstevel@tonic-gate 				(void) fprintf(fout, "#ifndef YYTEXTSZINC\n");
2670Sstevel@tonic-gate 				(void) fprintf(fout,
2684538Sdamico 				    "#define YYTEXTSZINC 100\n");
2690Sstevel@tonic-gate 				(void) fprintf(fout, "#endif\n");
2700Sstevel@tonic-gate 			}
2710Sstevel@tonic-gate 		}
2720Sstevel@tonic-gate 	}
2730Sstevel@tonic-gate 	(void) fprintf(fout, "int yymorfg;\n");
2740Sstevel@tonic-gate 	if (handleeuc)
2750Sstevel@tonic-gate 		(void) fprintf(fout, "extern wchar_t *yysptr, yysbuf[];\n");
2760Sstevel@tonic-gate 	else
2770Sstevel@tonic-gate 		(void) fprintf(fout, "extern char *yysptr, yysbuf[];\n");
2780Sstevel@tonic-gate 	(void) fprintf(fout, "int yytchar;\n");
2790Sstevel@tonic-gate 	(void) fprintf(fout, "FILE *yyin = {stdin}, *yyout = {stdout};\n");
2800Sstevel@tonic-gate 	(void) fprintf(fout, "extern int yylineno;\n");
2810Sstevel@tonic-gate 	(void) fprintf(fout, "struct yysvf { \n");
2820Sstevel@tonic-gate 	(void) fprintf(fout, "\tstruct yywork *yystoff;\n");
2830Sstevel@tonic-gate 	(void) fprintf(fout, "\tstruct yysvf *yyother;\n");
2840Sstevel@tonic-gate 	(void) fprintf(fout, "\tint *yystops;};\n");
2850Sstevel@tonic-gate 	(void) fprintf(fout, "struct yysvf *yyestate;\n");
2860Sstevel@tonic-gate 	(void) fprintf(fout, "extern struct yysvf yysvec[], *yybgin;\n");
2870Sstevel@tonic-gate }
2880Sstevel@tonic-gate 
2890Sstevel@tonic-gate static void
rhd1(void)2900Sstevel@tonic-gate rhd1(void)
2910Sstevel@tonic-gate {
2920Sstevel@tonic-gate 	(void) fprintf(fout, "integer function yylex(dummy)\n");
2930Sstevel@tonic-gate 	(void) fprintf(fout, "define YYLMAX 200\n");
2940Sstevel@tonic-gate 	(void) fprintf(fout, "define ECHO call yyecho(yytext,yyleng)\n");
2950Sstevel@tonic-gate 	(void) fprintf(fout,
2960Sstevel@tonic-gate 	"define REJECT nstr = yyrjct(yytext,yyleng);goto 30998\n");
2970Sstevel@tonic-gate 	(void) fprintf(fout, "integer nstr,yylook,yywrap\n");
2980Sstevel@tonic-gate 	(void) fprintf(fout, "integer yyleng, yytext(YYLMAX)\n");
2990Sstevel@tonic-gate 	(void) fprintf(fout, "common /yyxel/ yyleng, yytext\n");
3000Sstevel@tonic-gate 	(void) fprintf(fout,
3010Sstevel@tonic-gate 	"common /yyldat/ yyfnd, yymorf, yyprev, yybgin, yylsp, yylsta\n");
3020Sstevel@tonic-gate 	(void) fprintf(fout,
3030Sstevel@tonic-gate 	"integer yyfnd, yymorf, yyprev, yybgin, yylsp, yylsta(YYLMAX)\n");
3040Sstevel@tonic-gate 	(void) fprintf(fout, "for(;;){\n");
3050Sstevel@tonic-gate 	(void) fprintf(fout, "\t30999 nstr = yylook(dummy)\n");
3060Sstevel@tonic-gate 	(void) fprintf(fout, "\tgoto 30998\n");
3070Sstevel@tonic-gate 	(void) fprintf(fout, "\t30000 k = yywrap(dummy)\n");
3080Sstevel@tonic-gate 	(void) fprintf(fout, "\tif(k .ne. 0){\n");
3090Sstevel@tonic-gate 	(void) fprintf(fout, "\tyylex=0; return; }\n");
3100Sstevel@tonic-gate 	(void) fprintf(fout, "\t\telse goto 30998\n");
3110Sstevel@tonic-gate }
3120Sstevel@tonic-gate 
3130Sstevel@tonic-gate void
phead2(void)3140Sstevel@tonic-gate phead2(void)
3150Sstevel@tonic-gate {
3160Sstevel@tonic-gate 	if (!ratfor)
3170Sstevel@tonic-gate 		chd2();
3180Sstevel@tonic-gate }
3190Sstevel@tonic-gate 
3200Sstevel@tonic-gate static void
chd2(void)3210Sstevel@tonic-gate chd2(void)
3220Sstevel@tonic-gate {
3230Sstevel@tonic-gate 	(void) fprintf(fout, "#ifdef __cplusplus\n");
3240Sstevel@tonic-gate 	(void) fprintf(fout,
3250Sstevel@tonic-gate 	"/* to avoid CC and lint complaining yyfussy not being used ...*/\n");
3260Sstevel@tonic-gate 	(void) fprintf(fout, "static int __lex_hack = 0;\n");
3270Sstevel@tonic-gate 	(void) fprintf(fout, "if (__lex_hack) goto yyfussy;\n");
3280Sstevel@tonic-gate 	(void) fprintf(fout, "#endif\n");
3290Sstevel@tonic-gate 	(void) fprintf(fout, "while((nstr = yylook()) >= 0)\n");
3300Sstevel@tonic-gate 	(void) fprintf(fout, "yyfussy: switch(nstr){\n");
3310Sstevel@tonic-gate 	(void) fprintf(fout, "case 0:\n");
3320Sstevel@tonic-gate 	(void) fprintf(fout, "if(yywrap()) return(0); break;\n");
3330Sstevel@tonic-gate }
3340Sstevel@tonic-gate 
3350Sstevel@tonic-gate void
ptail(void)3360Sstevel@tonic-gate ptail(void)
3370Sstevel@tonic-gate {
3380Sstevel@tonic-gate 	if (!pflag)
3390Sstevel@tonic-gate 		ratfor ? rtail() : ctail();
3400Sstevel@tonic-gate 	pflag = 1;
3410Sstevel@tonic-gate }
3420Sstevel@tonic-gate 
3430Sstevel@tonic-gate static void
ctail(void)3440Sstevel@tonic-gate ctail(void)
3450Sstevel@tonic-gate {
3460Sstevel@tonic-gate 	(void) fprintf(fout, "case -1:\nbreak;\n");		/* for reject */
3470Sstevel@tonic-gate 	(void) fprintf(fout, "default:\n");
3480Sstevel@tonic-gate 	(void) fprintf(fout,
3490Sstevel@tonic-gate 	"(void)fprintf(yyout,\"bad switch yylook %%d\",nstr);\n");
3500Sstevel@tonic-gate 	(void) fprintf(fout, "} return(0); }\n");
3510Sstevel@tonic-gate 	(void) fprintf(fout, "/* end of yylex */\n");
3520Sstevel@tonic-gate }
3530Sstevel@tonic-gate 
3540Sstevel@tonic-gate static void
rtail(void)3550Sstevel@tonic-gate rtail(void)
3560Sstevel@tonic-gate {
3570Sstevel@tonic-gate 	int i;
3580Sstevel@tonic-gate 	(void) fprintf(fout,
3590Sstevel@tonic-gate 	"\n30998 if(nstr .lt. 0 .or. nstr .gt. %d)goto 30999\n", casecount);
3600Sstevel@tonic-gate 	(void) fprintf(fout, "nstr = nstr + 1\n");
3610Sstevel@tonic-gate 	(void) fprintf(fout, "goto(\n");
3620Sstevel@tonic-gate 	for (i = 0; i < casecount; i++)
3630Sstevel@tonic-gate 		(void) fprintf(fout, "%d,\n", 30000+i);
3640Sstevel@tonic-gate 	(void) fprintf(fout, "30999),nstr\n");
3650Sstevel@tonic-gate 	(void) fprintf(fout, "30997 continue\n");
3660Sstevel@tonic-gate 	(void) fprintf(fout, "}\nend\n");
3670Sstevel@tonic-gate }
3680Sstevel@tonic-gate 
3690Sstevel@tonic-gate void
statistics(void)3700Sstevel@tonic-gate statistics(void)
3710Sstevel@tonic-gate {
3720Sstevel@tonic-gate 	(void) fprintf(errorf,
3730Sstevel@tonic-gate "%d/%d nodes(%%e), %d/%d positions(%%p), %d/%d (%%n), %ld transitions,\n",
374*6951Sab196087 	    tptr, treesize, (int)(nxtpos-positions), maxpos, stnum + 1,
375*6951Sab196087 	    nstates, rcount);
3760Sstevel@tonic-gate 	(void) fprintf(errorf,
377*6951Sab196087 	"%d/%d packed char classes(%%k), ", (int)(pcptr-pchar), pchlen);
3780Sstevel@tonic-gate 	if (optim)
3790Sstevel@tonic-gate 		(void) fprintf(errorf,
3800Sstevel@tonic-gate 		" %d/%d packed transitions(%%a), ", nptr, ntrans);
3810Sstevel@tonic-gate 	(void) fprintf(errorf, " %d/%d output slots(%%o)", yytop, outsize);
3820Sstevel@tonic-gate 	(void) putc('\n', errorf);
3830Sstevel@tonic-gate }
384