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