xref: /illumos-gate/usr/src/cmd/sgs/lex/common/header.c (revision 9fce9916)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
567298654Sdamico  * Common Development and Distribution License (the "License").
667298654Sdamico  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
221dd08564Sab  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate /*	Copyright (c) 1988 AT&T	*/
277c478bd9Sstevel@tonic-gate /*	All Rights Reserved	*/
287c478bd9Sstevel@tonic-gate 
2967298654Sdamico #include "ldefs.h"
307c478bd9Sstevel@tonic-gate 
317c478bd9Sstevel@tonic-gate static void rhd1(void);
327c478bd9Sstevel@tonic-gate static void chd1(void);
337c478bd9Sstevel@tonic-gate static void chd2(void);
347c478bd9Sstevel@tonic-gate static void ctail(void);
357c478bd9Sstevel@tonic-gate static void rtail(void);
367c478bd9Sstevel@tonic-gate 
377c478bd9Sstevel@tonic-gate void
phead1(void)387c478bd9Sstevel@tonic-gate phead1(void)
397c478bd9Sstevel@tonic-gate {
407c478bd9Sstevel@tonic-gate 	ratfor ? rhd1() : chd1();
417c478bd9Sstevel@tonic-gate }
427c478bd9Sstevel@tonic-gate 
437c478bd9Sstevel@tonic-gate static void
chd1(void)447c478bd9Sstevel@tonic-gate chd1(void)
457c478bd9Sstevel@tonic-gate {
467c478bd9Sstevel@tonic-gate 	if (*v_stmp == 'y')
471dd08564Sab 		(void) fprintf(fout, "#ident\t\"lex: %s %s\"\n",
487c478bd9Sstevel@tonic-gate 		    (const char *)SGU_PKG, (const char *)SGU_REL);
497c478bd9Sstevel@tonic-gate 	if (handleeuc) {
501dd08564Sab 		(void) fprintf(fout, "#ifndef EUC\n");
511dd08564Sab 		(void) fprintf(fout, "#define EUC\n");
521dd08564Sab 		(void) fprintf(fout, "#endif\n");
531dd08564Sab 		(void) fprintf(fout, "#include <stdio.h>\n");
541dd08564Sab 		(void) fprintf(fout, "#include <stdlib.h>\n");
551dd08564Sab 		(void) fprintf(fout, "#include <inttypes.h>\n");
561dd08564Sab 		(void) fprintf(fout, "#include <widec.h>\n");
577c478bd9Sstevel@tonic-gate 		if (widecio) { /* -w option */
581dd08564Sab 			(void) fprintf(fout, "#define YYTEXT yytext\n");
591dd08564Sab 			(void) fprintf(fout, "#define YYLENG yyleng\n");
601dd08564Sab 			(void) fprintf(fout, "#ifndef __cplusplus\n");
611dd08564Sab 			(void) fprintf(fout, "#define YYINPUT input\n");
621dd08564Sab 			(void) fprintf(fout, "#define YYOUTPUT output\n");
631dd08564Sab 			(void) fprintf(fout, "#else\n");
641dd08564Sab 			(void) fprintf(fout, "#define YYINPUT lex_input\n");
651dd08564Sab 			(void) fprintf(fout, "#define YYOUTPUT lex_output\n");
661dd08564Sab 			(void) fprintf(fout, "#endif\n");
671dd08564Sab 			(void) fprintf(fout, "#define YYUNPUT unput\n");
687c478bd9Sstevel@tonic-gate 		} else { /* -e option */
691dd08564Sab 			(void) fprintf(fout, "#include <limits.h>\n");
701dd08564Sab 			(void) fprintf(fout, "#include <sys/euc.h>\n");
711dd08564Sab 			(void) fprintf(fout, "#define YYLEX_E 1\n");
721dd08564Sab 			(void) fprintf(fout, "#define YYTEXT yywtext\n");
731dd08564Sab 			(void) fprintf(fout, "#define YYLENG yywleng\n");
741dd08564Sab 			(void) fprintf(fout, "#define YYINPUT yywinput\n");
751dd08564Sab 			(void) fprintf(fout, "#define YYOUTPUT yywoutput\n");
761dd08564Sab 			(void) fprintf(fout, "#define YYUNPUT yywunput\n");
777c478bd9Sstevel@tonic-gate 		}
787c478bd9Sstevel@tonic-gate 	} else { /* ASCII compatibility mode. */
791dd08564Sab 		(void) fprintf(fout, "#include <stdio.h>\n");
801dd08564Sab 		(void) fprintf(fout, "#include <stdlib.h>\n");
811dd08564Sab 		(void) fprintf(fout, "#include <inttypes.h>\n");
827c478bd9Sstevel@tonic-gate 	}
837c478bd9Sstevel@tonic-gate 	if (ZCH > NCH)
847c478bd9Sstevel@tonic-gate 		(void) fprintf(fout, "# define U(x) ((x)&0377)\n");
857c478bd9Sstevel@tonic-gate 	else
867c478bd9Sstevel@tonic-gate 	(void) fprintf(fout, "# define U(x) x\n");
877c478bd9Sstevel@tonic-gate 	(void) fprintf(fout, "# define NLSTATE yyprevious=YYNEWLINE\n");
887c478bd9Sstevel@tonic-gate 	(void) fprintf(fout, "# define BEGIN yybgin = yysvec + 1 +\n");
897c478bd9Sstevel@tonic-gate 	(void) fprintf(fout, "# define INITIAL 0\n");
907c478bd9Sstevel@tonic-gate 	(void) fprintf(fout, "# define YYLERR yysvec\n");
917c478bd9Sstevel@tonic-gate 	(void) fprintf(fout, "# define YYSTATE (yyestate-yysvec-1)\n");
927c478bd9Sstevel@tonic-gate 	if (optim)
937c478bd9Sstevel@tonic-gate 		(void) fprintf(fout, "# define YYOPTIM 1\n");
947c478bd9Sstevel@tonic-gate #ifdef DEBUG
957c478bd9Sstevel@tonic-gate 	(void) fprintf(fout, "# define LEXDEBUG 1\n");
967c478bd9Sstevel@tonic-gate #endif
977c478bd9Sstevel@tonic-gate 	(void) fprintf(fout, "# ifndef YYLMAX \n");
987c478bd9Sstevel@tonic-gate 	(void) fprintf(fout, "# define YYLMAX BUFSIZ\n");
997c478bd9Sstevel@tonic-gate 	(void) fprintf(fout, "# endif \n");
1007c478bd9Sstevel@tonic-gate 	(void) fprintf(fout, "#ifndef __cplusplus\n");
1017c478bd9Sstevel@tonic-gate 	if (widecio)
1027c478bd9Sstevel@tonic-gate 		(void) fprintf(fout,
1037c478bd9Sstevel@tonic-gate 		"# define output(c) (void)putwc(c,yyout)\n");
1047c478bd9Sstevel@tonic-gate 	else
1057c478bd9Sstevel@tonic-gate 		(void) fprintf(fout,
1067c478bd9Sstevel@tonic-gate 		"# define output(c) (void)putc(c,yyout)\n");
1077c478bd9Sstevel@tonic-gate 	(void) fprintf(fout, "#else\n");
1087c478bd9Sstevel@tonic-gate 	if (widecio)
1097c478bd9Sstevel@tonic-gate 		(void) fprintf(fout,
1107c478bd9Sstevel@tonic-gate 		"# define lex_output(c) (void)putwc(c,yyout)\n");
1117c478bd9Sstevel@tonic-gate 	else
1127c478bd9Sstevel@tonic-gate 		(void) fprintf(fout,
1137c478bd9Sstevel@tonic-gate 		"# define lex_output(c) (void)putc(c,yyout)\n");
1147c478bd9Sstevel@tonic-gate 	(void) fprintf(fout, "#endif\n");
1157c478bd9Sstevel@tonic-gate 	(void) fprintf(fout,
1167c478bd9Sstevel@tonic-gate 	"\n#if defined(__cplusplus) || defined(__STDC__)\n");
117*9fce9916SToomas Soome 	(void) fprintf(fout, "\n#if defined(__cplusplus)\n");
1187c478bd9Sstevel@tonic-gate 	(void) fprintf(fout, "extern \"C\" {\n");
1197c478bd9Sstevel@tonic-gate 	(void) fprintf(fout, "#endif\n");
1207c478bd9Sstevel@tonic-gate 	(void) fprintf(fout, "\tint yyback(int *, int);\n"); /* ? */
1217c478bd9Sstevel@tonic-gate 	(void) fprintf(fout, "\tint yyinput(void);\n"); /* ? */
1227c478bd9Sstevel@tonic-gate 	(void) fprintf(fout, "\tint yylook(void);\n"); /* ? */
1237c478bd9Sstevel@tonic-gate 	(void) fprintf(fout, "\tvoid yyoutput(int);\n"); /* ? */
1247c478bd9Sstevel@tonic-gate 	(void) fprintf(fout, "\tint yyracc(int);\n"); /* ? */
1257c478bd9Sstevel@tonic-gate 	(void) fprintf(fout, "\tint yyreject(void);\n"); /* ? */
1267c478bd9Sstevel@tonic-gate 	(void) fprintf(fout, "\tvoid yyunput(int);\n"); /* ? */
1277c478bd9Sstevel@tonic-gate 	(void) fprintf(fout, "\tint yylex(void);\n");
1287c478bd9Sstevel@tonic-gate 	(void) fprintf(fout, "#ifdef YYLEX_E\n");
1297c478bd9Sstevel@tonic-gate 	(void) fprintf(fout, "\tvoid yywoutput(wchar_t);\n");
1307c478bd9Sstevel@tonic-gate 	(void) fprintf(fout, "\twchar_t yywinput(void);\n");
1317c478bd9Sstevel@tonic-gate 	(void) fprintf(fout, "\tvoid yywunput(wchar_t);\n");
1327c478bd9Sstevel@tonic-gate 	(void) fprintf(fout, "#endif\n");
1337c478bd9Sstevel@tonic-gate 
1347c478bd9Sstevel@tonic-gate 	/* XCU4: type of yyless is int */
1357c478bd9Sstevel@tonic-gate 	(void) fprintf(fout, "#ifndef yyless\n");
1367c478bd9Sstevel@tonic-gate 	(void) fprintf(fout, "\tint yyless(int);\n");
1377c478bd9Sstevel@tonic-gate 	(void) fprintf(fout, "#endif\n");
1387c478bd9Sstevel@tonic-gate 	(void) fprintf(fout, "#ifndef yywrap\n");
1397c478bd9Sstevel@tonic-gate 	(void) fprintf(fout, "\tint yywrap(void);\n");
1407c478bd9Sstevel@tonic-gate 	(void) fprintf(fout, "#endif\n");
1417c478bd9Sstevel@tonic-gate 	(void) fprintf(fout, "#ifdef LEXDEBUG\n");
1427c478bd9Sstevel@tonic-gate 	(void) fprintf(fout, "\tvoid allprint(char);\n");
1437c478bd9Sstevel@tonic-gate 	(void) fprintf(fout, "\tvoid sprint(char *);\n");
1447c478bd9Sstevel@tonic-gate 	(void) fprintf(fout, "#endif\n");
145*9fce9916SToomas Soome 	(void) fprintf(fout, "#if defined(__cplusplus)\n");
1467c478bd9Sstevel@tonic-gate 	(void) fprintf(fout, "}\n");
1477c478bd9Sstevel@tonic-gate 	(void) fprintf(fout, "#endif\n\n");
1487c478bd9Sstevel@tonic-gate 	(void) fprintf(fout, "#ifdef __cplusplus\n");
1497c478bd9Sstevel@tonic-gate 	(void) fprintf(fout, "extern \"C\" {\n");
1507c478bd9Sstevel@tonic-gate 	(void) fprintf(fout, "#endif\n");
1517c478bd9Sstevel@tonic-gate 	(void) fprintf(fout, "\tvoid exit(int);\n");
1527c478bd9Sstevel@tonic-gate 	(void) fprintf(fout, "#ifdef __cplusplus\n");
1537c478bd9Sstevel@tonic-gate 	(void) fprintf(fout, "}\n");
1547c478bd9Sstevel@tonic-gate 	(void) fprintf(fout, "#endif\n\n");
1557c478bd9Sstevel@tonic-gate 	(void) fprintf(fout, "#endif\n");
1567c478bd9Sstevel@tonic-gate 	(void) fprintf(fout,
1577c478bd9Sstevel@tonic-gate 	"# define unput(c)"
1587c478bd9Sstevel@tonic-gate 	" {yytchar= (c);if(yytchar=='\\n')yylineno--;*yysptr++=yytchar;}\n");
1597c478bd9Sstevel@tonic-gate 	(void) fprintf(fout, "# define yymore() (yymorfg=1)\n");
1607c478bd9Sstevel@tonic-gate 	if (widecio) {
1617c478bd9Sstevel@tonic-gate 		(void) fprintf(fout, "#ifndef __cplusplus\n");
1627c478bd9Sstevel@tonic-gate 		(void) fprintf(fout, "%s%d%s\n",
1637c478bd9Sstevel@tonic-gate "# define input() (((yytchar=yysptr>yysbuf?U(*--yysptr):getwc(yyin))==",
16467298654Sdamico 		    ctable['\n'],
1657c478bd9Sstevel@tonic-gate "?(yylineno++,yytchar):yytchar)==EOF?0:yytchar)");
1667c478bd9Sstevel@tonic-gate 		(void) fprintf(fout, "#else\n");
1677c478bd9Sstevel@tonic-gate 		(void) fprintf(fout, "%s%d%s\n",
1687c478bd9Sstevel@tonic-gate "# define lex_input() (((yytchar=yysptr>yysbuf?U(*--yysptr):getwc(yyin))==",
16967298654Sdamico 		    ctable['\n'],
1707c478bd9Sstevel@tonic-gate "?(yylineno++,yytchar):yytchar)==EOF?0:yytchar)");
1717c478bd9Sstevel@tonic-gate 		(void) fprintf(fout, "#endif\n");
1727c478bd9Sstevel@tonic-gate 		(void) fprintf(fout,
1737c478bd9Sstevel@tonic-gate 		"# define ECHO (void)fprintf(yyout, \"%%ws\",yytext)\n");
1747c478bd9Sstevel@tonic-gate 		(void) fprintf(fout,
1757c478bd9Sstevel@tonic-gate 		"# define REJECT { nstr = yyreject_w(); goto yyfussy;}\n");
1767c478bd9Sstevel@tonic-gate 		(void) fprintf(fout, "#define yyless yyless_w\n");
1777c478bd9Sstevel@tonic-gate 		(void) fprintf(fout, "int yyleng;\n");
1787c478bd9Sstevel@tonic-gate 
1797c478bd9Sstevel@tonic-gate 		/*
1807c478bd9Sstevel@tonic-gate 		 * XCU4:
1817c478bd9Sstevel@tonic-gate 		 * If %array, yytext[] contains the token.
1827c478bd9Sstevel@tonic-gate 		 * If %pointer, yytext is a pointer to yy_tbuf[].
1837c478bd9Sstevel@tonic-gate 		 */
1847c478bd9Sstevel@tonic-gate 
1857c478bd9Sstevel@tonic-gate 		if (isArray) {
1867c478bd9Sstevel@tonic-gate 			(void) fprintf(fout, "#define YYISARRAY\n");
1877c478bd9Sstevel@tonic-gate 			(void) fprintf(fout, "wchar_t yytext[YYLMAX];\n");
1887c478bd9Sstevel@tonic-gate 		} else {
1897c478bd9Sstevel@tonic-gate 			(void) fprintf(fout, "wchar_t yy_tbuf[YYLMAX];\n");
1907c478bd9Sstevel@tonic-gate 			(void) fprintf(fout, "wchar_t * yytext = yy_tbuf;\n");
1917c478bd9Sstevel@tonic-gate 			(void) fprintf(fout, "int yytextsz = YYLMAX;\n");
1927c478bd9Sstevel@tonic-gate 			(void) fprintf(fout, "#ifndef YYTEXTSZINC\n");
1937c478bd9Sstevel@tonic-gate 			(void) fprintf(fout, "#define YYTEXTSZINC 100\n");
1947c478bd9Sstevel@tonic-gate 			(void) fprintf(fout, "#endif\n");
1957c478bd9Sstevel@tonic-gate 		}
1967c478bd9Sstevel@tonic-gate 	} else {
1977c478bd9Sstevel@tonic-gate 		(void) fprintf(fout, "#ifndef __cplusplus\n");
1987c478bd9Sstevel@tonic-gate 		(void) fprintf(fout, "%s%d%s\n",
1997c478bd9Sstevel@tonic-gate "# define input() (((yytchar=yysptr>yysbuf?U(*--yysptr):getc(yyin))==",
20067298654Sdamico 		    ctable['\n'],
2017c478bd9Sstevel@tonic-gate "?(yylineno++,yytchar):yytchar)==EOF?0:yytchar)");
2027c478bd9Sstevel@tonic-gate 		(void) fprintf(fout, "#else\n");
2037c478bd9Sstevel@tonic-gate 		(void) fprintf(fout, "%s%d%s\n",
2047c478bd9Sstevel@tonic-gate "# define lex_input() (((yytchar=yysptr>yysbuf?U(*--yysptr):getc(yyin))==",
20567298654Sdamico 		    ctable['\n'],
2067c478bd9Sstevel@tonic-gate "?(yylineno++,yytchar):yytchar)==EOF?0:yytchar)");
2077c478bd9Sstevel@tonic-gate 		(void) fprintf(fout, "#endif\n");
2081dd08564Sab 		(void) fprintf(fout,
2091dd08564Sab 		    "#define ECHO fprintf(yyout, \"%%s\",yytext)\n");
2107c478bd9Sstevel@tonic-gate 		if (handleeuc) {
2117c478bd9Sstevel@tonic-gate 			(void) fprintf(fout,
2127c478bd9Sstevel@tonic-gate "# define REJECT { nstr = yyreject_e(); goto yyfussy;}\n");
2137c478bd9Sstevel@tonic-gate 			(void) fprintf(fout, "int yyleng;\n");
2147c478bd9Sstevel@tonic-gate 			(void) fprintf(fout, "size_t yywleng;\n");
2157c478bd9Sstevel@tonic-gate 			/*
2167c478bd9Sstevel@tonic-gate 			 * XCU4:
2177c478bd9Sstevel@tonic-gate 			 * If %array, yytext[] contains the token.
2187c478bd9Sstevel@tonic-gate 			 * If %pointer, yytext is a pointer to yy_tbuf[].
2197c478bd9Sstevel@tonic-gate 			 */
2207c478bd9Sstevel@tonic-gate 			if (isArray) {
2217c478bd9Sstevel@tonic-gate 				(void) fprintf(fout, "#define YYISARRAY\n");
2227c478bd9Sstevel@tonic-gate 				(void) fprintf(fout,
2237c478bd9Sstevel@tonic-gate 				"unsigned char yytext[YYLMAX*MB_LEN_MAX];\n");
2247c478bd9Sstevel@tonic-gate 				(void) fprintf(fout,
2257c478bd9Sstevel@tonic-gate 				"wchar_t yywtext[YYLMAX];\n");
2267c478bd9Sstevel@tonic-gate 			} else {
2277c478bd9Sstevel@tonic-gate 				(void) fprintf(fout,
2287c478bd9Sstevel@tonic-gate 				"wchar_t yy_twbuf[YYLMAX];\n");
2297c478bd9Sstevel@tonic-gate 				(void) fprintf(fout,
2307c478bd9Sstevel@tonic-gate 				"wchar_t yy_tbuf[YYLMAX*MB_LEN_MAX];\n");
2317c478bd9Sstevel@tonic-gate 				(void) fprintf(fout,
2327c478bd9Sstevel@tonic-gate 				"unsigned char * yytext ="
2337c478bd9Sstevel@tonic-gate 				"(unsigned char *)yy_tbuf;\n");
2347c478bd9Sstevel@tonic-gate 				(void) fprintf(fout,
2357c478bd9Sstevel@tonic-gate 				"wchar_t * yywtext = yy_twbuf;\n");
2367c478bd9Sstevel@tonic-gate 				(void) fprintf(fout,
23767298654Sdamico 				    "int yytextsz = YYLMAX;\n");
2387c478bd9Sstevel@tonic-gate 				(void) fprintf(fout, "#ifndef YYTEXTSZINC\n");
2397c478bd9Sstevel@tonic-gate 				(void) fprintf(fout,
24067298654Sdamico 				    "#define YYTEXTSZINC 100\n");
2417c478bd9Sstevel@tonic-gate 				(void) fprintf(fout, "#endif\n");
2427c478bd9Sstevel@tonic-gate 			}
2437c478bd9Sstevel@tonic-gate 		} else {
2447c478bd9Sstevel@tonic-gate 			(void) fprintf(fout,
2457c478bd9Sstevel@tonic-gate "# define REJECT { nstr = yyreject(); goto yyfussy;}\n");
2467c478bd9Sstevel@tonic-gate 			(void) fprintf(fout, "int yyleng;\n");
2477c478bd9Sstevel@tonic-gate 
2487c478bd9Sstevel@tonic-gate 			/*
2497c478bd9Sstevel@tonic-gate 			 * XCU4:
2507c478bd9Sstevel@tonic-gate 			 * If %array, yytext[] contains the token.
2517c478bd9Sstevel@tonic-gate 			 * If %pointer, yytext is a pointer to yy_tbuf[].
2527c478bd9Sstevel@tonic-gate 			 */
2537c478bd9Sstevel@tonic-gate 			if (isArray) {
2547c478bd9Sstevel@tonic-gate 				(void) fprintf(fout, "#define YYISARRAY\n");
2557c478bd9Sstevel@tonic-gate 				(void) fprintf(fout, "char yytext[YYLMAX];\n");
2567c478bd9Sstevel@tonic-gate 			} else {
2577c478bd9Sstevel@tonic-gate 				(void) fprintf(fout, "char yy_tbuf[YYLMAX];\n");
2587c478bd9Sstevel@tonic-gate 				(void) fprintf(fout,
2597c478bd9Sstevel@tonic-gate 				"char * yytext = yy_tbuf;\n");
2607c478bd9Sstevel@tonic-gate 				(void) fprintf(fout,
26167298654Sdamico 				    "int yytextsz = YYLMAX;\n");
2627c478bd9Sstevel@tonic-gate 				(void) fprintf(fout, "#ifndef YYTEXTSZINC\n");
2637c478bd9Sstevel@tonic-gate 				(void) fprintf(fout,
26467298654Sdamico 				    "#define YYTEXTSZINC 100\n");
2657c478bd9Sstevel@tonic-gate 				(void) fprintf(fout, "#endif\n");
2667c478bd9Sstevel@tonic-gate 			}
2677c478bd9Sstevel@tonic-gate 		}
2687c478bd9Sstevel@tonic-gate 	}
2697c478bd9Sstevel@tonic-gate 	(void) fprintf(fout, "int yymorfg;\n");
2707c478bd9Sstevel@tonic-gate 	if (handleeuc)
2717c478bd9Sstevel@tonic-gate 		(void) fprintf(fout, "extern wchar_t *yysptr, yysbuf[];\n");
2727c478bd9Sstevel@tonic-gate 	else
2737c478bd9Sstevel@tonic-gate 		(void) fprintf(fout, "extern char *yysptr, yysbuf[];\n");
2747c478bd9Sstevel@tonic-gate 	(void) fprintf(fout, "int yytchar;\n");
2757c478bd9Sstevel@tonic-gate 	(void) fprintf(fout, "FILE *yyin = {stdin}, *yyout = {stdout};\n");
2767c478bd9Sstevel@tonic-gate 	(void) fprintf(fout, "extern int yylineno;\n");
2777c478bd9Sstevel@tonic-gate 	(void) fprintf(fout, "struct yysvf { \n");
2787c478bd9Sstevel@tonic-gate 	(void) fprintf(fout, "\tstruct yywork *yystoff;\n");
2797c478bd9Sstevel@tonic-gate 	(void) fprintf(fout, "\tstruct yysvf *yyother;\n");
2807c478bd9Sstevel@tonic-gate 	(void) fprintf(fout, "\tint *yystops;};\n");
2817c478bd9Sstevel@tonic-gate 	(void) fprintf(fout, "struct yysvf *yyestate;\n");
2827c478bd9Sstevel@tonic-gate 	(void) fprintf(fout, "extern struct yysvf yysvec[], *yybgin;\n");
2837c478bd9Sstevel@tonic-gate }
2847c478bd9Sstevel@tonic-gate 
2857c478bd9Sstevel@tonic-gate static void
rhd1(void)2867c478bd9Sstevel@tonic-gate rhd1(void)
2877c478bd9Sstevel@tonic-gate {
2887c478bd9Sstevel@tonic-gate 	(void) fprintf(fout, "integer function yylex(dummy)\n");
2897c478bd9Sstevel@tonic-gate 	(void) fprintf(fout, "define YYLMAX 200\n");
2907c478bd9Sstevel@tonic-gate 	(void) fprintf(fout, "define ECHO call yyecho(yytext,yyleng)\n");
2917c478bd9Sstevel@tonic-gate 	(void) fprintf(fout,
2927c478bd9Sstevel@tonic-gate 	"define REJECT nstr = yyrjct(yytext,yyleng);goto 30998\n");
2937c478bd9Sstevel@tonic-gate 	(void) fprintf(fout, "integer nstr,yylook,yywrap\n");
2947c478bd9Sstevel@tonic-gate 	(void) fprintf(fout, "integer yyleng, yytext(YYLMAX)\n");
2957c478bd9Sstevel@tonic-gate 	(void) fprintf(fout, "common /yyxel/ yyleng, yytext\n");
2967c478bd9Sstevel@tonic-gate 	(void) fprintf(fout,
2977c478bd9Sstevel@tonic-gate 	"common /yyldat/ yyfnd, yymorf, yyprev, yybgin, yylsp, yylsta\n");
2987c478bd9Sstevel@tonic-gate 	(void) fprintf(fout,
2997c478bd9Sstevel@tonic-gate 	"integer yyfnd, yymorf, yyprev, yybgin, yylsp, yylsta(YYLMAX)\n");
3007c478bd9Sstevel@tonic-gate 	(void) fprintf(fout, "for(;;){\n");
3017c478bd9Sstevel@tonic-gate 	(void) fprintf(fout, "\t30999 nstr = yylook(dummy)\n");
3027c478bd9Sstevel@tonic-gate 	(void) fprintf(fout, "\tgoto 30998\n");
3037c478bd9Sstevel@tonic-gate 	(void) fprintf(fout, "\t30000 k = yywrap(dummy)\n");
3047c478bd9Sstevel@tonic-gate 	(void) fprintf(fout, "\tif(k .ne. 0){\n");
3057c478bd9Sstevel@tonic-gate 	(void) fprintf(fout, "\tyylex=0; return; }\n");
3067c478bd9Sstevel@tonic-gate 	(void) fprintf(fout, "\t\telse goto 30998\n");
3077c478bd9Sstevel@tonic-gate }
3087c478bd9Sstevel@tonic-gate 
3097c478bd9Sstevel@tonic-gate void
phead2(void)3107c478bd9Sstevel@tonic-gate phead2(void)
3117c478bd9Sstevel@tonic-gate {
3127c478bd9Sstevel@tonic-gate 	if (!ratfor)
3137c478bd9Sstevel@tonic-gate 		chd2();
3147c478bd9Sstevel@tonic-gate }
3157c478bd9Sstevel@tonic-gate 
3167c478bd9Sstevel@tonic-gate static void
chd2(void)3177c478bd9Sstevel@tonic-gate chd2(void)
3187c478bd9Sstevel@tonic-gate {
3197c478bd9Sstevel@tonic-gate 	(void) fprintf(fout, "#ifdef __cplusplus\n");
3207c478bd9Sstevel@tonic-gate 	(void) fprintf(fout,
3217c478bd9Sstevel@tonic-gate 	"/* to avoid CC and lint complaining yyfussy not being used ...*/\n");
3227c478bd9Sstevel@tonic-gate 	(void) fprintf(fout, "static int __lex_hack = 0;\n");
3237c478bd9Sstevel@tonic-gate 	(void) fprintf(fout, "if (__lex_hack) goto yyfussy;\n");
3247c478bd9Sstevel@tonic-gate 	(void) fprintf(fout, "#endif\n");
3257c478bd9Sstevel@tonic-gate 	(void) fprintf(fout, "while((nstr = yylook()) >= 0)\n");
3267c478bd9Sstevel@tonic-gate 	(void) fprintf(fout, "yyfussy: switch(nstr){\n");
3277c478bd9Sstevel@tonic-gate 	(void) fprintf(fout, "case 0:\n");
3287c478bd9Sstevel@tonic-gate 	(void) fprintf(fout, "if(yywrap()) return(0); break;\n");
3297c478bd9Sstevel@tonic-gate }
3307c478bd9Sstevel@tonic-gate 
3317c478bd9Sstevel@tonic-gate void
ptail(void)3327c478bd9Sstevel@tonic-gate ptail(void)
3337c478bd9Sstevel@tonic-gate {
3347c478bd9Sstevel@tonic-gate 	if (!pflag)
3357c478bd9Sstevel@tonic-gate 		ratfor ? rtail() : ctail();
3367c478bd9Sstevel@tonic-gate 	pflag = 1;
3377c478bd9Sstevel@tonic-gate }
3387c478bd9Sstevel@tonic-gate 
3397c478bd9Sstevel@tonic-gate static void
ctail(void)3407c478bd9Sstevel@tonic-gate ctail(void)
3417c478bd9Sstevel@tonic-gate {
3427c478bd9Sstevel@tonic-gate 	(void) fprintf(fout, "case -1:\nbreak;\n");		/* for reject */
3437c478bd9Sstevel@tonic-gate 	(void) fprintf(fout, "default:\n");
3447c478bd9Sstevel@tonic-gate 	(void) fprintf(fout,
3457c478bd9Sstevel@tonic-gate 	"(void)fprintf(yyout,\"bad switch yylook %%d\",nstr);\n");
3467c478bd9Sstevel@tonic-gate 	(void) fprintf(fout, "} return(0); }\n");
3477c478bd9Sstevel@tonic-gate 	(void) fprintf(fout, "/* end of yylex */\n");
3487c478bd9Sstevel@tonic-gate }
3497c478bd9Sstevel@tonic-gate 
3507c478bd9Sstevel@tonic-gate static void
rtail(void)3517c478bd9Sstevel@tonic-gate rtail(void)
3527c478bd9Sstevel@tonic-gate {
3537c478bd9Sstevel@tonic-gate 	int i;
3547c478bd9Sstevel@tonic-gate 	(void) fprintf(fout,
3557c478bd9Sstevel@tonic-gate 	"\n30998 if(nstr .lt. 0 .or. nstr .gt. %d)goto 30999\n", casecount);
3567c478bd9Sstevel@tonic-gate 	(void) fprintf(fout, "nstr = nstr + 1\n");
3577c478bd9Sstevel@tonic-gate 	(void) fprintf(fout, "goto(\n");
3587c478bd9Sstevel@tonic-gate 	for (i = 0; i < casecount; i++)
3597c478bd9Sstevel@tonic-gate 		(void) fprintf(fout, "%d,\n", 30000+i);
3607c478bd9Sstevel@tonic-gate 	(void) fprintf(fout, "30999),nstr\n");
3617c478bd9Sstevel@tonic-gate 	(void) fprintf(fout, "30997 continue\n");
3627c478bd9Sstevel@tonic-gate 	(void) fprintf(fout, "}\nend\n");
3637c478bd9Sstevel@tonic-gate }
3647c478bd9Sstevel@tonic-gate 
3657c478bd9Sstevel@tonic-gate void
statistics(void)3667c478bd9Sstevel@tonic-gate statistics(void)
3677c478bd9Sstevel@tonic-gate {
3687c478bd9Sstevel@tonic-gate 	(void) fprintf(errorf,
3697c478bd9Sstevel@tonic-gate "%d/%d nodes(%%e), %d/%d positions(%%p), %d/%d (%%n), %ld transitions,\n",
3701dd08564Sab 	    tptr, treesize, (int)(nxtpos-positions), maxpos, stnum + 1,
3711dd08564Sab 	    nstates, rcount);
3727c478bd9Sstevel@tonic-gate 	(void) fprintf(errorf,
3731dd08564Sab 	"%d/%d packed char classes(%%k), ", (int)(pcptr-pchar), pchlen);
3747c478bd9Sstevel@tonic-gate 	if (optim)
3757c478bd9Sstevel@tonic-gate 		(void) fprintf(errorf,
3767c478bd9Sstevel@tonic-gate 		" %d/%d packed transitions(%%a), ", nptr, ntrans);
3777c478bd9Sstevel@tonic-gate 	(void) fprintf(errorf, " %d/%d output slots(%%o)", yytop, outsize);
3787c478bd9Sstevel@tonic-gate 	(void) putc('\n', errorf);
3797c478bd9Sstevel@tonic-gate }
380