xref: /illumos-gate/usr/src/cmd/sgs/lex/common/ncform (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1*7c478bd9Sstevel@tonic-gate/*
2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate *
4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate * with the License.
8*7c478bd9Sstevel@tonic-gate *
9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate *
14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate *
20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate */
22*7c478bd9Sstevel@tonic-gate
23*7c478bd9Sstevel@tonic-gate/*	Copyright (c) 1989 AT&T	*/
24*7c478bd9Sstevel@tonic-gate/*	  All Rights Reserved  	*/
25*7c478bd9Sstevel@tonic-gate
26*7c478bd9Sstevel@tonic-gate#pragma ident	"%Z%%M%	%I%	%E% SMI"
27*7c478bd9Sstevel@tonic-gate
28*7c478bd9Sstevel@tonic-gateint yylineno =1;
29*7c478bd9Sstevel@tonic-gate# define YYU(x) x
30*7c478bd9Sstevel@tonic-gate# define NLSTATE yyprevious=YYNEWLINE
31*7c478bd9Sstevel@tonic-gatestruct yysvf *yylstate [YYLMAX], **yylsp, **yyolsp;
32*7c478bd9Sstevel@tonic-gatechar yysbuf[YYLMAX];
33*7c478bd9Sstevel@tonic-gatechar *yysptr = yysbuf;
34*7c478bd9Sstevel@tonic-gateint *yyfnd;
35*7c478bd9Sstevel@tonic-gateextern struct yysvf *yyestate;
36*7c478bd9Sstevel@tonic-gateint yyprevious = YYNEWLINE;
37*7c478bd9Sstevel@tonic-gate#if defined(__cplusplus) || defined(__STDC__)
38*7c478bd9Sstevel@tonic-gateint yylook(void)
39*7c478bd9Sstevel@tonic-gate#else
40*7c478bd9Sstevel@tonic-gateyylook()
41*7c478bd9Sstevel@tonic-gate#endif
42*7c478bd9Sstevel@tonic-gate{
43*7c478bd9Sstevel@tonic-gate	register struct yysvf *yystate, **lsp;
44*7c478bd9Sstevel@tonic-gate	register struct yywork *yyt;
45*7c478bd9Sstevel@tonic-gate	struct yysvf *yyz;
46*7c478bd9Sstevel@tonic-gate	int yych, yyfirst;
47*7c478bd9Sstevel@tonic-gate	struct yywork *yyr;
48*7c478bd9Sstevel@tonic-gate# ifdef LEXDEBUG
49*7c478bd9Sstevel@tonic-gate	int debug;
50*7c478bd9Sstevel@tonic-gate# endif
51*7c478bd9Sstevel@tonic-gate	char *yylastch;
52*7c478bd9Sstevel@tonic-gate	/* start off machines */
53*7c478bd9Sstevel@tonic-gate# ifdef LEXDEBUG
54*7c478bd9Sstevel@tonic-gate	debug = 0;
55*7c478bd9Sstevel@tonic-gate# endif
56*7c478bd9Sstevel@tonic-gate	yyfirst=1;
57*7c478bd9Sstevel@tonic-gate	if (!yymorfg)
58*7c478bd9Sstevel@tonic-gate		yylastch = yytext;
59*7c478bd9Sstevel@tonic-gate	else {
60*7c478bd9Sstevel@tonic-gate		yymorfg=0;
61*7c478bd9Sstevel@tonic-gate		yylastch = yytext+yyleng;
62*7c478bd9Sstevel@tonic-gate		}
63*7c478bd9Sstevel@tonic-gate	for(;;){
64*7c478bd9Sstevel@tonic-gate		lsp = yylstate;
65*7c478bd9Sstevel@tonic-gate		yyestate = yystate = yybgin;
66*7c478bd9Sstevel@tonic-gate		if (yyprevious==YYNEWLINE) yystate++;
67*7c478bd9Sstevel@tonic-gate		for (;;){
68*7c478bd9Sstevel@tonic-gate# ifdef LEXDEBUG
69*7c478bd9Sstevel@tonic-gate			if(debug)fprintf(yyout,"state %d\n",yystate-yysvec-1);
70*7c478bd9Sstevel@tonic-gate# endif
71*7c478bd9Sstevel@tonic-gate			yyt = yystate->yystoff;
72*7c478bd9Sstevel@tonic-gate			if(yyt == yycrank && !yyfirst){  /* may not be any transitions */
73*7c478bd9Sstevel@tonic-gate				yyz = yystate->yyother;
74*7c478bd9Sstevel@tonic-gate				if(yyz == 0)break;
75*7c478bd9Sstevel@tonic-gate				if(yyz->yystoff == yycrank)break;
76*7c478bd9Sstevel@tonic-gate				}
77*7c478bd9Sstevel@tonic-gate#ifndef __cplusplus
78*7c478bd9Sstevel@tonic-gate			*yylastch++ = yych = input();
79*7c478bd9Sstevel@tonic-gate#else
80*7c478bd9Sstevel@tonic-gate			*yylastch++ = yych = lex_input();
81*7c478bd9Sstevel@tonic-gate#endif
82*7c478bd9Sstevel@tonic-gate#ifdef YYISARRAY
83*7c478bd9Sstevel@tonic-gate			if(yylastch > &yytext[YYLMAX]) {
84*7c478bd9Sstevel@tonic-gate				fprintf(yyout,"Input string too long, limit %d\n",YYLMAX);
85*7c478bd9Sstevel@tonic-gate				exit(1);
86*7c478bd9Sstevel@tonic-gate			}
87*7c478bd9Sstevel@tonic-gate#else
88*7c478bd9Sstevel@tonic-gate			if (yylastch >= &yytext[ yytextsz ]) {
89*7c478bd9Sstevel@tonic-gate				int	x = yylastch - yytext;
90*7c478bd9Sstevel@tonic-gate
91*7c478bd9Sstevel@tonic-gate				yytextsz += YYTEXTSZINC;
92*7c478bd9Sstevel@tonic-gate				if (yytext == yy_tbuf) {
93*7c478bd9Sstevel@tonic-gate				    yytext = (char *) malloc(yytextsz);
94*7c478bd9Sstevel@tonic-gate				    memcpy(yytext, yy_tbuf, sizeof (yy_tbuf));
95*7c478bd9Sstevel@tonic-gate				}
96*7c478bd9Sstevel@tonic-gate				else
97*7c478bd9Sstevel@tonic-gate				    yytext = (char *) realloc(yytext, yytextsz);
98*7c478bd9Sstevel@tonic-gate				if (!yytext) {
99*7c478bd9Sstevel@tonic-gate				    fprintf(yyout,
100*7c478bd9Sstevel@tonic-gate					"Cannot realloc yytext\n");
101*7c478bd9Sstevel@tonic-gate				    exit(1);
102*7c478bd9Sstevel@tonic-gate				}
103*7c478bd9Sstevel@tonic-gate				yylastch = yytext + x;
104*7c478bd9Sstevel@tonic-gate			}
105*7c478bd9Sstevel@tonic-gate#endif
106*7c478bd9Sstevel@tonic-gate			yyfirst=0;
107*7c478bd9Sstevel@tonic-gate		tryagain:
108*7c478bd9Sstevel@tonic-gate# ifdef LEXDEBUG
109*7c478bd9Sstevel@tonic-gate			if(debug){
110*7c478bd9Sstevel@tonic-gate				fprintf(yyout,"char ");
111*7c478bd9Sstevel@tonic-gate				allprint(yych);
112*7c478bd9Sstevel@tonic-gate				putchar('\n');
113*7c478bd9Sstevel@tonic-gate				}
114*7c478bd9Sstevel@tonic-gate# endif
115*7c478bd9Sstevel@tonic-gate			yyr = yyt;
116*7c478bd9Sstevel@tonic-gate			if ( (uintptr_t)yyt > (uintptr_t)yycrank){
117*7c478bd9Sstevel@tonic-gate				yyt = yyr + yych;
118*7c478bd9Sstevel@tonic-gate				if (yyt <= yytop && yyt->verify+yysvec == yystate){
119*7c478bd9Sstevel@tonic-gate					if(yyt->advance+yysvec == YYLERR)	/* error transitions */
120*7c478bd9Sstevel@tonic-gate						{unput(*--yylastch);break;}
121*7c478bd9Sstevel@tonic-gate					*lsp++ = yystate = yyt->advance+yysvec;
122*7c478bd9Sstevel@tonic-gate					if(lsp > &yylstate[YYLMAX]) {
123*7c478bd9Sstevel@tonic-gate						fprintf(yyout,"Input string too long, limit %d\n",YYLMAX);
124*7c478bd9Sstevel@tonic-gate						exit(1);
125*7c478bd9Sstevel@tonic-gate					}
126*7c478bd9Sstevel@tonic-gate					goto contin;
127*7c478bd9Sstevel@tonic-gate					}
128*7c478bd9Sstevel@tonic-gate				}
129*7c478bd9Sstevel@tonic-gate# ifdef YYOPTIM
130*7c478bd9Sstevel@tonic-gate			else if((uintptr_t)yyt < (uintptr_t)yycrank) {	/* r < yycrank */
131*7c478bd9Sstevel@tonic-gate				yyt = yyr = yycrank+(yycrank-yyt);
132*7c478bd9Sstevel@tonic-gate# ifdef LEXDEBUG
133*7c478bd9Sstevel@tonic-gate				if(debug)fprintf(yyout,"compressed state\n");
134*7c478bd9Sstevel@tonic-gate# endif
135*7c478bd9Sstevel@tonic-gate				yyt = yyt + yych;
136*7c478bd9Sstevel@tonic-gate				if(yyt <= yytop && yyt->verify+yysvec == yystate){
137*7c478bd9Sstevel@tonic-gate					if(yyt->advance+yysvec == YYLERR)	/* error transitions */
138*7c478bd9Sstevel@tonic-gate						{unput(*--yylastch);break;}
139*7c478bd9Sstevel@tonic-gate					*lsp++ = yystate = yyt->advance+yysvec;
140*7c478bd9Sstevel@tonic-gate					if(lsp > &yylstate[YYLMAX]) {
141*7c478bd9Sstevel@tonic-gate						fprintf(yyout,"Input string too long, limit %d\n",YYLMAX);
142*7c478bd9Sstevel@tonic-gate						exit(1);
143*7c478bd9Sstevel@tonic-gate					}
144*7c478bd9Sstevel@tonic-gate					goto contin;
145*7c478bd9Sstevel@tonic-gate					}
146*7c478bd9Sstevel@tonic-gate				yyt = yyr + YYU(yymatch[yych]);
147*7c478bd9Sstevel@tonic-gate# ifdef LEXDEBUG
148*7c478bd9Sstevel@tonic-gate				if(debug){
149*7c478bd9Sstevel@tonic-gate					fprintf(yyout,"try fall back character ");
150*7c478bd9Sstevel@tonic-gate					allprint(YYU(yymatch[yych]));
151*7c478bd9Sstevel@tonic-gate					putchar('\n');
152*7c478bd9Sstevel@tonic-gate					}
153*7c478bd9Sstevel@tonic-gate# endif
154*7c478bd9Sstevel@tonic-gate				if(yyt <= yytop && yyt->verify+yysvec == yystate){
155*7c478bd9Sstevel@tonic-gate					if(yyt->advance+yysvec == YYLERR)	/* error transition */
156*7c478bd9Sstevel@tonic-gate						{unput(*--yylastch);break;}
157*7c478bd9Sstevel@tonic-gate					*lsp++ = yystate = yyt->advance+yysvec;
158*7c478bd9Sstevel@tonic-gate					if(lsp > &yylstate[YYLMAX]) {
159*7c478bd9Sstevel@tonic-gate						fprintf(yyout,"Input string too long, limit %d\n",YYLMAX);
160*7c478bd9Sstevel@tonic-gate						exit(1);
161*7c478bd9Sstevel@tonic-gate					}
162*7c478bd9Sstevel@tonic-gate					goto contin;
163*7c478bd9Sstevel@tonic-gate					}
164*7c478bd9Sstevel@tonic-gate				}
165*7c478bd9Sstevel@tonic-gate			if ((yystate = yystate->yyother) && (yyt= yystate->yystoff) != yycrank){
166*7c478bd9Sstevel@tonic-gate# ifdef LEXDEBUG
167*7c478bd9Sstevel@tonic-gate				if(debug)fprintf(yyout,"fall back to state %d\n",yystate-yysvec-1);
168*7c478bd9Sstevel@tonic-gate# endif
169*7c478bd9Sstevel@tonic-gate				goto tryagain;
170*7c478bd9Sstevel@tonic-gate				}
171*7c478bd9Sstevel@tonic-gate# endif
172*7c478bd9Sstevel@tonic-gate			else
173*7c478bd9Sstevel@tonic-gate				{unput(*--yylastch);break;}
174*7c478bd9Sstevel@tonic-gate		contin:
175*7c478bd9Sstevel@tonic-gate# ifdef LEXDEBUG
176*7c478bd9Sstevel@tonic-gate			if(debug){
177*7c478bd9Sstevel@tonic-gate				fprintf(yyout,"state %d char ",yystate-yysvec-1);
178*7c478bd9Sstevel@tonic-gate				allprint(yych);
179*7c478bd9Sstevel@tonic-gate				putchar('\n');
180*7c478bd9Sstevel@tonic-gate				}
181*7c478bd9Sstevel@tonic-gate# endif
182*7c478bd9Sstevel@tonic-gate			;
183*7c478bd9Sstevel@tonic-gate			}
184*7c478bd9Sstevel@tonic-gate# ifdef LEXDEBUG
185*7c478bd9Sstevel@tonic-gate		if(debug){
186*7c478bd9Sstevel@tonic-gate			fprintf(yyout,"stopped at %d with ",*(lsp-1)-yysvec-1);
187*7c478bd9Sstevel@tonic-gate			allprint(yych);
188*7c478bd9Sstevel@tonic-gate			putchar('\n');
189*7c478bd9Sstevel@tonic-gate			}
190*7c478bd9Sstevel@tonic-gate# endif
191*7c478bd9Sstevel@tonic-gate		while (lsp-- > yylstate){
192*7c478bd9Sstevel@tonic-gate			*yylastch-- = 0;
193*7c478bd9Sstevel@tonic-gate			if (*lsp != 0 && (yyfnd= (*lsp)->yystops) && *yyfnd > 0){
194*7c478bd9Sstevel@tonic-gate				yyolsp = lsp;
195*7c478bd9Sstevel@tonic-gate				if(yyextra[*yyfnd]){		/* must backup */
196*7c478bd9Sstevel@tonic-gate					while(yyback((*lsp)->yystops,-*yyfnd) != 1 && lsp > yylstate){
197*7c478bd9Sstevel@tonic-gate						lsp--;
198*7c478bd9Sstevel@tonic-gate						unput(*yylastch--);
199*7c478bd9Sstevel@tonic-gate						}
200*7c478bd9Sstevel@tonic-gate					}
201*7c478bd9Sstevel@tonic-gate				yyprevious = YYU(*yylastch);
202*7c478bd9Sstevel@tonic-gate				yylsp = lsp;
203*7c478bd9Sstevel@tonic-gate				yyleng = yylastch-yytext+1;
204*7c478bd9Sstevel@tonic-gate				yytext[yyleng] = 0;
205*7c478bd9Sstevel@tonic-gate# ifdef LEXDEBUG
206*7c478bd9Sstevel@tonic-gate				if(debug){
207*7c478bd9Sstevel@tonic-gate					fprintf(yyout,"\nmatch ");
208*7c478bd9Sstevel@tonic-gate					sprint(yytext);
209*7c478bd9Sstevel@tonic-gate					fprintf(yyout," action %d\n",*yyfnd);
210*7c478bd9Sstevel@tonic-gate					}
211*7c478bd9Sstevel@tonic-gate# endif
212*7c478bd9Sstevel@tonic-gate				return(*yyfnd++);
213*7c478bd9Sstevel@tonic-gate				}
214*7c478bd9Sstevel@tonic-gate			unput(*yylastch);
215*7c478bd9Sstevel@tonic-gate			}
216*7c478bd9Sstevel@tonic-gate		if (yytext[0] == 0  /* && feof(yyin) */)
217*7c478bd9Sstevel@tonic-gate			{
218*7c478bd9Sstevel@tonic-gate			yysptr=yysbuf;
219*7c478bd9Sstevel@tonic-gate			return(0);
220*7c478bd9Sstevel@tonic-gate			}
221*7c478bd9Sstevel@tonic-gate#ifndef __cplusplus
222*7c478bd9Sstevel@tonic-gate		yyprevious = yytext[0] = input();
223*7c478bd9Sstevel@tonic-gate		if (yyprevious>0)
224*7c478bd9Sstevel@tonic-gate			output(yyprevious);
225*7c478bd9Sstevel@tonic-gate#else
226*7c478bd9Sstevel@tonic-gate		yyprevious = yytext[0] = lex_input();
227*7c478bd9Sstevel@tonic-gate		if (yyprevious>0)
228*7c478bd9Sstevel@tonic-gate			lex_output(yyprevious);
229*7c478bd9Sstevel@tonic-gate#endif
230*7c478bd9Sstevel@tonic-gate		yylastch=yytext;
231*7c478bd9Sstevel@tonic-gate# ifdef LEXDEBUG
232*7c478bd9Sstevel@tonic-gate		if(debug)putchar('\n');
233*7c478bd9Sstevel@tonic-gate# endif
234*7c478bd9Sstevel@tonic-gate		}
235*7c478bd9Sstevel@tonic-gate	}
236*7c478bd9Sstevel@tonic-gate#if defined(__cplusplus) || defined(__STDC__)
237*7c478bd9Sstevel@tonic-gateint yyback(int *p, int m)
238*7c478bd9Sstevel@tonic-gate#else
239*7c478bd9Sstevel@tonic-gateyyback(p, m)
240*7c478bd9Sstevel@tonic-gate	int *p;
241*7c478bd9Sstevel@tonic-gate#endif
242*7c478bd9Sstevel@tonic-gate{
243*7c478bd9Sstevel@tonic-gate	if (p==0) return(0);
244*7c478bd9Sstevel@tonic-gate	while (*p) {
245*7c478bd9Sstevel@tonic-gate		if (*p++ == m)
246*7c478bd9Sstevel@tonic-gate			return(1);
247*7c478bd9Sstevel@tonic-gate	}
248*7c478bd9Sstevel@tonic-gate	return(0);
249*7c478bd9Sstevel@tonic-gate}
250*7c478bd9Sstevel@tonic-gate	/* the following are only used in the lex library */
251*7c478bd9Sstevel@tonic-gate#if defined(__cplusplus) || defined(__STDC__)
252*7c478bd9Sstevel@tonic-gateint yyinput(void)
253*7c478bd9Sstevel@tonic-gate#else
254*7c478bd9Sstevel@tonic-gateyyinput()
255*7c478bd9Sstevel@tonic-gate#endif
256*7c478bd9Sstevel@tonic-gate{
257*7c478bd9Sstevel@tonic-gate#ifndef __cplusplus
258*7c478bd9Sstevel@tonic-gate	return(input());
259*7c478bd9Sstevel@tonic-gate#else
260*7c478bd9Sstevel@tonic-gate	return(lex_input());
261*7c478bd9Sstevel@tonic-gate#endif
262*7c478bd9Sstevel@tonic-gate	}
263*7c478bd9Sstevel@tonic-gate#if defined(__cplusplus) || defined(__STDC__)
264*7c478bd9Sstevel@tonic-gatevoid yyoutput(int c)
265*7c478bd9Sstevel@tonic-gate#else
266*7c478bd9Sstevel@tonic-gateyyoutput(c)
267*7c478bd9Sstevel@tonic-gate  int c;
268*7c478bd9Sstevel@tonic-gate#endif
269*7c478bd9Sstevel@tonic-gate{
270*7c478bd9Sstevel@tonic-gate#ifndef __cplusplus
271*7c478bd9Sstevel@tonic-gate	output(c);
272*7c478bd9Sstevel@tonic-gate#else
273*7c478bd9Sstevel@tonic-gate	lex_output(c);
274*7c478bd9Sstevel@tonic-gate#endif
275*7c478bd9Sstevel@tonic-gate	}
276*7c478bd9Sstevel@tonic-gate#if defined(__cplusplus) || defined(__STDC__)
277*7c478bd9Sstevel@tonic-gatevoid yyunput(int c)
278*7c478bd9Sstevel@tonic-gate#else
279*7c478bd9Sstevel@tonic-gateyyunput(c)
280*7c478bd9Sstevel@tonic-gate   int c;
281*7c478bd9Sstevel@tonic-gate#endif
282*7c478bd9Sstevel@tonic-gate{
283*7c478bd9Sstevel@tonic-gate	unput(c);
284*7c478bd9Sstevel@tonic-gate	}
285