xref: /illumos-gate/usr/src/cmd/sgs/lex/common/nceucform (revision 2a8bcb4e)
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 2005 Sun Microsystems, Inc.
24 * All rights reserved.
25 * Use is subject to license terms.
26 */
27
28/*	Copyright (c) 1989 AT&T	*/
29/*	  All Rights Reserved	*/
30
31int yylineno =1;
32int yygid;
33#define LONG_WCHAR_T 1
34# define YYU(x) x
35# define NLSTATE yyprevious=YYNEWLINE
36wchar_t yysbuf[YYLMAX];
37wchar_t *yysptr = yysbuf;
38struct yysvf *yylstate [YYLMAX], **yylsp, **yyolsp;
39int *yyfnd;
40extern struct yysvf *yyestate;
41int yyprevious = YYNEWLINE;
42
43int yylook(void)
44{
45	struct yysvf *yystate, **lsp;
46	struct yywork *yyt;
47	struct yysvf *yyz;
48	int yych, yyfirst;
49	struct yywork *yyr;
50# ifdef LEXDEBUG
51	int debug;
52# endif
53	wchar_t *yylastch;
54	/* start off machines */
55# ifdef LEXDEBUG
56	debug = 0;
57# endif
58	yyfirst=1;
59	if (!yymorfg)
60		yylastch = YYTEXT;
61	else {
62		yymorfg=0;
63		yylastch = YYTEXT+YYLENG;
64		}
65	for(;;){
66		lsp = yylstate;
67		yyestate = yystate = yybgin;
68		if (yyprevious==YYNEWLINE) yystate++;
69		for (;;){
70# ifdef LEXDEBUG
71			if(debug)fprintf(yyout,"state %d\n",yystate-yysvec-1);
72# endif
73			yyt = yystate->yystoff;
74			if(yyt == yycrank && !yyfirst){  /* may not be any transitions */
75				yyz = yystate->yyother;
76				if(yyz == 0)break;
77				if(yyz->yystoff == yycrank)break;
78				}
79			*yylastch++ = yych = YYINPUT();
80#ifdef YYISARRAY
81			if(yylastch > &YYTEXT[YYLMAX]) {
82				fprintf(yyout,"Input string too long, limit %d\n",YYLMAX);
83				exit(1);
84			}
85#else
86			if (yylastch >= &YYTEXT[ yytextsz ]) {
87				int	x = yylastch - YYTEXT;
88
89				yytextsz += YYTEXTSZINC;
90#ifdef YYLEX_E /* -e */
91				if (YYTEXT == yy_twbuf) {
92					YYTEXT = (wchar_t *)
93						malloc(yytextsz *
94							sizeof (wchar_t));
95					memcpy(YYTEXT, yy_twbuf,
96						sizeof (yy_twbuf));
97					yytext = (wchar_t *)
98						malloc(yytextsz *
99							sizeof (wchar_t));
100					memcpy(yytext, yy_tbuf,
101						sizeof (yy_tbuf));
102#else
103				if (YYTEXT == yy_tbuf) {
104					YYTEXT = (wchar_t *)
105						malloc(yytextsz *
106							sizeof (wchar_t));
107					memcpy(YYTEXT, yy_tbuf,
108						sizeof (yy_tbuf));
109#endif
110				}
111				else {
112					YYTEXT = (wchar_t *)
113						realloc(YYTEXT, yytextsz);
114#ifdef YYLEX_E /* -e */
115					yytext = (wchar_t *)
116						realloc(yytext,
117						yytextsz * sizeof (wchar_t));
118#endif
119				}
120				if (!YYTEXT) {
121					fprintf(yyout,
122					"Cannot realloc YYTEXT\n");
123					exit(1);
124				}
125				yylastch = YYTEXT + x;
126			}
127#endif
128			yygid = yycgid(yych);
129			yyfirst=0;
130		tryagain:
131# ifdef LEXDEBUG
132			if(debug){
133				fprintf(yyout,"wchar_t ");
134				allprint(yych);
135				fprintf(yyout," gid %d\n", yygid);
136				}
137# endif
138			yyr = yyt;
139			if ( (uintptr_t)yyt > (uintptr_t)yycrank){
140				yyt = yyr + yygid;
141				if (yyt <= yytop && yyt->verify+yysvec == yystate){
142					if(yyt->advance+yysvec == YYLERR)	/* error transitions */
143						{YYUNPUT(*--yylastch);break;}
144					*lsp++ = yystate = yyt->advance+yysvec;
145					if(lsp > &yylstate[YYLMAX]) {
146						fprintf(yyout,"Input string too long, limit %d\n",YYLMAX);
147						exit(1);
148					}
149					goto contin;
150					}
151				}
152# ifdef YYOPTIM
153			else if((uintptr_t)yyt < (uintptr_t)yycrank) {	/* r < yycrank */
154				yyt = yyr = yycrank+(yycrank-yyt);
155# ifdef LEXDEBUG
156				if(debug)fprintf(yyout,"compressed state\n");
157# endif
158				yyt = yyt + yygid;
159				if(yyt <= yytop && yyt->verify+yysvec == yystate){
160					if(yyt->advance+yysvec == YYLERR)	/* error transitions */
161						{YYUNPUT(*--yylastch);break;}
162					*lsp++ = yystate = yyt->advance+yysvec;
163					if(lsp > &yylstate[YYLMAX]) {
164						fprintf(yyout,"Input string too long, limit %d\n",YYLMAX);
165						exit(1);
166					}
167					goto contin;
168					}
169				yyt = yyr + YYU(yymatch[yygid]);
170# ifdef LEXDEBUG
171				if(debug){
172					fprintf(yyout,"try fall back character ");
173					allprint_w(YYU(yymatch[yygid]));
174					fprintf(yyout," gid %d\n", yygid);
175					}
176# endif
177				if(yyt <= yytop && yyt->verify+yysvec == yystate){
178					if(yyt->advance+yysvec == YYLERR)	/* error transition */
179						{YYUNPUT(*--yylastch);break;}
180					*lsp++ = yystate = yyt->advance+yysvec;
181					if(lsp > &yylstate[YYLMAX]) {
182						fprintf(yyout,"Input string too long, limit %d\n",YYLMAX);
183						exit(1);
184					}
185					goto contin;
186					}
187				}
188			if ((yystate = yystate->yyother) && (yyt= yystate->yystoff) != yycrank){
189# ifdef LEXDEBUG
190				if(debug)fprintf(yyout,"fall back to state %d\n",yystate-yysvec-1);
191# endif
192				goto tryagain;
193				}
194# endif
195			else
196				{YYUNPUT(*--yylastch);break;}
197		contin:
198# ifdef LEXDEBUG
199			if(debug){
200				fprintf(yyout,"state %d wchar_t ",yystate-yysvec-1);
201				allprint_w(yych);
202				fprintf(yyout," gid %d\n", yygid);
203				}
204# endif
205			;
206			}
207# ifdef LEXDEBUG
208		if(debug){
209			fprintf(yyout,"stopped at %d with ",*(lsp-1)-yysvec-1);
210			allprint_w(yych);
211			fprintf(yyout," gid %d\n", yygid);
212			}
213# endif
214		while (lsp-- > yylstate){
215			*yylastch-- = 0;
216			if (*lsp != 0 && (yyfnd= (*lsp)->yystops) && *yyfnd > 0){
217				yyolsp = lsp;
218				if(yyextra[*yyfnd]){		/* must backup */
219					while(yyback((*lsp)->yystops,-*yyfnd) != 1 && lsp > yylstate){
220						lsp--;
221						YYUNPUT(*yylastch--);
222						}
223					}
224				yyprevious = YYU(*yylastch);
225				yylsp = lsp;
226				YYLENG = yylastch-YYTEXT+1;
227				YYTEXT[YYLENG] = 0;
228# ifdef LEXDEBUG
229				if(debug){
230					fprintf(yyout,"\nmatch ");
231					sprint_w(YYTEXT);
232					fprintf(yyout," action %d\n",*yyfnd);
233					}
234# endif
235#ifdef YYLEX_E /* -e */
236				yyleng=wcstombs((char *)yytext, YYTEXT, sizeof(yytext)-1);
237#ifdef LEXDEBUG
238				if(yyleng>=sizeof(yytext)-1)
239					fprintf(yyout, "yytext[] too short\n");
240#endif
241#endif
242				return(*yyfnd++);
243				}
244			YYUNPUT(*yylastch);
245			}
246		if (YYTEXT[0] == 0  /* && feof(yyin) */)
247			{
248			yysptr=yysbuf;
249			return(0);
250			}
251		yyprevious = YYTEXT[0] = YYINPUT();
252		if (yyprevious>0)
253			YYOUTPUT(yyprevious);
254		yylastch=YYTEXT;
255# ifdef LEXDEBUG
256		if(debug)putchar('\n');
257# endif
258		}
259	}
260int
261yyback(int *p, int m)
262{
263	if (p==0) return(0);
264	while (*p) {
265		if (*p++ == m)
266			return(1);
267	}
268	return(0);
269}
270
271#ifdef YYLEX_E /* -e */
272wchar_t
273yywinput(void)
274{
275	unsigned char eucbuf[MB_LEN_MAX];
276	wchar_t wc;
277	unsigned char *p=eucbuf;
278	int n;
279
280#ifndef __cplusplus
281	*p++=input();
282	n=euclen(eucbuf);
283	while(--n>0) *p++=input();
284#else
285	*p++=lex_input();
286	n=euclen(eucbuf);
287	while(--n>0) *p++=lex_input();
288#endif
289	*p=0;
290
291	mbtowc( &wc, (char *)eucbuf, MB_LEN_MAX );
292	return wc;
293}
294
295void
296yywoutput(wchar_t wc)
297{
298	unsigned char eucbuf[MB_LEN_MAX];
299	int n;
300	unsigned char *p=eucbuf;
301
302	n=wctomb( (char *)eucbuf, wc );
303#ifndef __cplusplus
304	while(n-->0) output(*p++);
305#else
306	while(n-->0) lex_output(*p++);
307#endif
308}
309
310void
311yywunput(wchar_t wc)
312{
313	unsigned char eucbuf[MB_LEN_MAX];
314	int n;
315	unsigned char *p;
316
317	n=wctomb( (char *)eucbuf, wc );
318	p=eucbuf+n;
319	while(n-->0) unput(*--p);
320}
321#endif
322
323#ifdef LONG_WCHAR_T
324#define yylinearize(lc) lc
325#else/*!LONG_WCHAR_T*/
326unsigned long
327yylinearize(wc)
328     wchar_t    wc;
329{
330	unsigned long   prefix;
331	switch(wc&0x8080){
332	      case 0x0000:      prefix=0x00000000; break;
333	      case 0x0080:      prefix=0x20000000; break;
334	      case 0x8000:      prefix=0x40000000; break;
335	      case 0x8080:      prefix=0x60000000; break;
336	}
337	return prefix|wc;
338}
339#endif/*!LONG_WCHAR_T*/
340int
341yycgid(wchar_t c)
342{
343	int first = 0;
344	int last = YYNCGIDTBL - 1;
345	unsigned long lc=yylinearize(c);
346
347	if( yycgidtbl[YYNCGIDTBL-1] < lc ) return YYNCGIDTBL*2-1;
348
349	while (last >= 0) {
350		int i = (first+last)/2;
351		if (lc == yycgidtbl[i])
352		    return (2*i);
353		else if ( yycgidtbl[i]<lc) {
354			if (lc<yycgidtbl[i+1])
355			    return (2*i+1);
356			else
357			    first = i + 1;
358		}else
359		    last = i - 1;
360	}
361	return 0; /*Error*/
362}
363
364
365
366
367
368	/* the following are only used in the lex library */
369int
370yyinput(void)
371{
372#ifndef __cplusplus
373	return(input());
374#else
375	return(lex_input());
376#endif
377}
378
379void
380yyoutput(int c)
381{
382#ifndef __cplusplus
383	output(c);
384#else
385	lex_output(c);
386#endif
387}
388
389void
390yyunput(int c)
391{
392	unput(c);
393}
394