xref: /titanic_50/usr/src/cmd/sgs/lex/common/ncform (revision 927a453e165c072d45bd6aa2945b3db0fce17c56)
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 (c) 1989 AT&T	*/
24/*	  All Rights Reserved  	*/
25
26#pragma ident	"%Z%%M%	%I%	%E% SMI"
27
28int yylineno =1;
29# define YYU(x) x
30# define NLSTATE yyprevious=YYNEWLINE
31struct yysvf *yylstate [YYLMAX], **yylsp, **yyolsp;
32char yysbuf[YYLMAX];
33char *yysptr = yysbuf;
34int *yyfnd;
35extern struct yysvf *yyestate;
36int yyprevious = YYNEWLINE;
37#if defined(__cplusplus) || defined(__STDC__)
38int yylook(void)
39#else
40yylook()
41#endif
42{
43	register struct yysvf *yystate, **lsp;
44	register struct yywork *yyt;
45	struct yysvf *yyz;
46	int yych, yyfirst;
47	struct yywork *yyr;
48# ifdef LEXDEBUG
49	int debug;
50# endif
51	char *yylastch;
52	/* start off machines */
53# ifdef LEXDEBUG
54	debug = 0;
55# endif
56	yyfirst=1;
57	if (!yymorfg)
58		yylastch = yytext;
59	else {
60		yymorfg=0;
61		yylastch = yytext+yyleng;
62		}
63	for(;;){
64		lsp = yylstate;
65		yyestate = yystate = yybgin;
66		if (yyprevious==YYNEWLINE) yystate++;
67		for (;;){
68# ifdef LEXDEBUG
69			if(debug)fprintf(yyout,"state %d\n",yystate-yysvec-1);
70# endif
71			yyt = yystate->yystoff;
72			if(yyt == yycrank && !yyfirst){  /* may not be any transitions */
73				yyz = yystate->yyother;
74				if(yyz == 0)break;
75				if(yyz->yystoff == yycrank)break;
76				}
77#ifndef __cplusplus
78			*yylastch++ = yych = input();
79#else
80			*yylastch++ = yych = lex_input();
81#endif
82#ifdef YYISARRAY
83			if(yylastch > &yytext[YYLMAX]) {
84				fprintf(yyout,"Input string too long, limit %d\n",YYLMAX);
85				exit(1);
86			}
87#else
88			if (yylastch >= &yytext[ yytextsz ]) {
89				int	x = yylastch - yytext;
90
91				yytextsz += YYTEXTSZINC;
92				if (yytext == yy_tbuf) {
93				    yytext = (char *) malloc(yytextsz);
94				    memcpy(yytext, yy_tbuf, sizeof (yy_tbuf));
95				}
96				else
97				    yytext = (char *) realloc(yytext, yytextsz);
98				if (!yytext) {
99				    fprintf(yyout,
100					"Cannot realloc yytext\n");
101				    exit(1);
102				}
103				yylastch = yytext + x;
104			}
105#endif
106			yyfirst=0;
107		tryagain:
108# ifdef LEXDEBUG
109			if(debug){
110				fprintf(yyout,"char ");
111				allprint(yych);
112				putchar('\n');
113				}
114# endif
115			yyr = yyt;
116			if ( (uintptr_t)yyt > (uintptr_t)yycrank){
117				yyt = yyr + yych;
118				if (yyt <= yytop && yyt->verify+yysvec == yystate){
119					if(yyt->advance+yysvec == YYLERR)	/* error transitions */
120						{unput(*--yylastch);break;}
121					*lsp++ = yystate = yyt->advance+yysvec;
122					if(lsp > &yylstate[YYLMAX]) {
123						fprintf(yyout,"Input string too long, limit %d\n",YYLMAX);
124						exit(1);
125					}
126					goto contin;
127					}
128				}
129# ifdef YYOPTIM
130			else if((uintptr_t)yyt < (uintptr_t)yycrank) {	/* r < yycrank */
131				yyt = yyr = yycrank+(yycrank-yyt);
132# ifdef LEXDEBUG
133				if(debug)fprintf(yyout,"compressed state\n");
134# endif
135				yyt = yyt + yych;
136				if(yyt <= yytop && yyt->verify+yysvec == yystate){
137					if(yyt->advance+yysvec == YYLERR)	/* error transitions */
138						{unput(*--yylastch);break;}
139					*lsp++ = yystate = yyt->advance+yysvec;
140					if(lsp > &yylstate[YYLMAX]) {
141						fprintf(yyout,"Input string too long, limit %d\n",YYLMAX);
142						exit(1);
143					}
144					goto contin;
145					}
146				yyt = yyr + YYU(yymatch[yych]);
147# ifdef LEXDEBUG
148				if(debug){
149					fprintf(yyout,"try fall back character ");
150					allprint(YYU(yymatch[yych]));
151					putchar('\n');
152					}
153# endif
154				if(yyt <= yytop && yyt->verify+yysvec == yystate){
155					if(yyt->advance+yysvec == YYLERR)	/* error transition */
156						{unput(*--yylastch);break;}
157					*lsp++ = yystate = yyt->advance+yysvec;
158					if(lsp > &yylstate[YYLMAX]) {
159						fprintf(yyout,"Input string too long, limit %d\n",YYLMAX);
160						exit(1);
161					}
162					goto contin;
163					}
164				}
165			if ((yystate = yystate->yyother) && (yyt= yystate->yystoff) != yycrank){
166# ifdef LEXDEBUG
167				if(debug)fprintf(yyout,"fall back to state %d\n",yystate-yysvec-1);
168# endif
169				goto tryagain;
170				}
171# endif
172			else
173				{unput(*--yylastch);break;}
174		contin:
175# ifdef LEXDEBUG
176			if(debug){
177				fprintf(yyout,"state %d char ",yystate-yysvec-1);
178				allprint(yych);
179				putchar('\n');
180				}
181# endif
182			;
183			}
184# ifdef LEXDEBUG
185		if(debug){
186			fprintf(yyout,"stopped at %d with ",*(lsp-1)-yysvec-1);
187			allprint(yych);
188			putchar('\n');
189			}
190# endif
191		while (lsp-- > yylstate){
192			*yylastch-- = 0;
193			if (*lsp != 0 && (yyfnd= (*lsp)->yystops) && *yyfnd > 0){
194				yyolsp = lsp;
195				if(yyextra[*yyfnd]){		/* must backup */
196					while(yyback((*lsp)->yystops,-*yyfnd) != 1 && lsp > yylstate){
197						lsp--;
198						unput(*yylastch--);
199						}
200					}
201				yyprevious = YYU(*yylastch);
202				yylsp = lsp;
203				yyleng = yylastch-yytext+1;
204				yytext[yyleng] = 0;
205# ifdef LEXDEBUG
206				if(debug){
207					fprintf(yyout,"\nmatch ");
208					sprint(yytext);
209					fprintf(yyout," action %d\n",*yyfnd);
210					}
211# endif
212				return(*yyfnd++);
213				}
214			unput(*yylastch);
215			}
216		if (yytext[0] == 0  /* && feof(yyin) */)
217			{
218			yysptr=yysbuf;
219			return(0);
220			}
221#ifndef __cplusplus
222		yyprevious = yytext[0] = input();
223		if (yyprevious>0)
224			output(yyprevious);
225#else
226		yyprevious = yytext[0] = lex_input();
227		if (yyprevious>0)
228			lex_output(yyprevious);
229#endif
230		yylastch=yytext;
231# ifdef LEXDEBUG
232		if(debug)putchar('\n');
233# endif
234		}
235	}
236#if defined(__cplusplus) || defined(__STDC__)
237int yyback(int *p, int m)
238#else
239yyback(p, m)
240	int *p;
241#endif
242{
243	if (p==0) return(0);
244	while (*p) {
245		if (*p++ == m)
246			return(1);
247	}
248	return(0);
249}
250	/* the following are only used in the lex library */
251#if defined(__cplusplus) || defined(__STDC__)
252int yyinput(void)
253#else
254yyinput()
255#endif
256{
257#ifndef __cplusplus
258	return(input());
259#else
260	return(lex_input());
261#endif
262	}
263#if defined(__cplusplus) || defined(__STDC__)
264void yyoutput(int c)
265#else
266yyoutput(c)
267  int c;
268#endif
269{
270#ifndef __cplusplus
271	output(c);
272#else
273	lex_output(c);
274#endif
275	}
276#if defined(__cplusplus) || defined(__STDC__)
277void yyunput(int c)
278#else
279yyunput(c)
280   int c;
281#endif
282{
283	unput(c);
284	}
285