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