xref: /illumos-gate/usr/src/cmd/sgs/lex/common/ncform (revision 966c588f)
17c478bd9Sstevel@tonic-gate/*
27c478bd9Sstevel@tonic-gate * CDDL HEADER START
37c478bd9Sstevel@tonic-gate *
47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
57c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate * (the "License").  You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate * with the License.
87c478bd9Sstevel@tonic-gate *
97c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate * and limitations under the License.
137c478bd9Sstevel@tonic-gate *
147c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate *
207c478bd9Sstevel@tonic-gate * CDDL HEADER END
217c478bd9Sstevel@tonic-gate */
227c478bd9Sstevel@tonic-gate
237c478bd9Sstevel@tonic-gate/*	Copyright (c) 1989 AT&T	*/
24*966c588fSToomas Soome/*	  All Rights Reserved	*/
257c478bd9Sstevel@tonic-gate
267c478bd9Sstevel@tonic-gateint yylineno =1;
277c478bd9Sstevel@tonic-gate# define YYU(x) x
287c478bd9Sstevel@tonic-gate# define NLSTATE yyprevious=YYNEWLINE
297c478bd9Sstevel@tonic-gatestruct yysvf *yylstate [YYLMAX], **yylsp, **yyolsp;
307c478bd9Sstevel@tonic-gatechar yysbuf[YYLMAX];
317c478bd9Sstevel@tonic-gatechar *yysptr = yysbuf;
327c478bd9Sstevel@tonic-gateint *yyfnd;
337c478bd9Sstevel@tonic-gateextern struct yysvf *yyestate;
347c478bd9Sstevel@tonic-gateint yyprevious = YYNEWLINE;
35*966c588fSToomas Soome
36*966c588fSToomas Soomeint
37*966c588fSToomas Soomeyylook(void)
387c478bd9Sstevel@tonic-gate{
39*966c588fSToomas Soome	struct yysvf *yystate, **lsp;
40*966c588fSToomas Soome	struct yywork *yyt;
417c478bd9Sstevel@tonic-gate	struct yysvf *yyz;
427c478bd9Sstevel@tonic-gate	int yych, yyfirst;
437c478bd9Sstevel@tonic-gate	struct yywork *yyr;
447c478bd9Sstevel@tonic-gate# ifdef LEXDEBUG
457c478bd9Sstevel@tonic-gate	int debug;
467c478bd9Sstevel@tonic-gate# endif
477c478bd9Sstevel@tonic-gate	char *yylastch;
487c478bd9Sstevel@tonic-gate	/* start off machines */
497c478bd9Sstevel@tonic-gate# ifdef LEXDEBUG
507c478bd9Sstevel@tonic-gate	debug = 0;
517c478bd9Sstevel@tonic-gate# endif
527c478bd9Sstevel@tonic-gate	yyfirst=1;
537c478bd9Sstevel@tonic-gate	if (!yymorfg)
547c478bd9Sstevel@tonic-gate		yylastch = yytext;
557c478bd9Sstevel@tonic-gate	else {
567c478bd9Sstevel@tonic-gate		yymorfg=0;
577c478bd9Sstevel@tonic-gate		yylastch = yytext+yyleng;
587c478bd9Sstevel@tonic-gate		}
597c478bd9Sstevel@tonic-gate	for(;;){
607c478bd9Sstevel@tonic-gate		lsp = yylstate;
617c478bd9Sstevel@tonic-gate		yyestate = yystate = yybgin;
627c478bd9Sstevel@tonic-gate		if (yyprevious==YYNEWLINE) yystate++;
637c478bd9Sstevel@tonic-gate		for (;;){
647c478bd9Sstevel@tonic-gate# ifdef LEXDEBUG
657c478bd9Sstevel@tonic-gate			if(debug)fprintf(yyout,"state %d\n",yystate-yysvec-1);
667c478bd9Sstevel@tonic-gate# endif
677c478bd9Sstevel@tonic-gate			yyt = yystate->yystoff;
687c478bd9Sstevel@tonic-gate			if(yyt == yycrank && !yyfirst){  /* may not be any transitions */
697c478bd9Sstevel@tonic-gate				yyz = yystate->yyother;
707c478bd9Sstevel@tonic-gate				if(yyz == 0)break;
717c478bd9Sstevel@tonic-gate				if(yyz->yystoff == yycrank)break;
727c478bd9Sstevel@tonic-gate				}
737c478bd9Sstevel@tonic-gate#ifndef __cplusplus
747c478bd9Sstevel@tonic-gate			*yylastch++ = yych = input();
757c478bd9Sstevel@tonic-gate#else
767c478bd9Sstevel@tonic-gate			*yylastch++ = yych = lex_input();
777c478bd9Sstevel@tonic-gate#endif
787c478bd9Sstevel@tonic-gate#ifdef YYISARRAY
797c478bd9Sstevel@tonic-gate			if(yylastch > &yytext[YYLMAX]) {
807c478bd9Sstevel@tonic-gate				fprintf(yyout,"Input string too long, limit %d\n",YYLMAX);
817c478bd9Sstevel@tonic-gate				exit(1);
827c478bd9Sstevel@tonic-gate			}
837c478bd9Sstevel@tonic-gate#else
847c478bd9Sstevel@tonic-gate			if (yylastch >= &yytext[ yytextsz ]) {
857c478bd9Sstevel@tonic-gate				int	x = yylastch - yytext;
867c478bd9Sstevel@tonic-gate
877c478bd9Sstevel@tonic-gate				yytextsz += YYTEXTSZINC;
887c478bd9Sstevel@tonic-gate				if (yytext == yy_tbuf) {
897c478bd9Sstevel@tonic-gate				    yytext = (char *) malloc(yytextsz);
907c478bd9Sstevel@tonic-gate				    memcpy(yytext, yy_tbuf, sizeof (yy_tbuf));
917c478bd9Sstevel@tonic-gate				}
927c478bd9Sstevel@tonic-gate				else
937c478bd9Sstevel@tonic-gate				    yytext = (char *) realloc(yytext, yytextsz);
947c478bd9Sstevel@tonic-gate				if (!yytext) {
957c478bd9Sstevel@tonic-gate				    fprintf(yyout,
967c478bd9Sstevel@tonic-gate					"Cannot realloc yytext\n");
977c478bd9Sstevel@tonic-gate				    exit(1);
987c478bd9Sstevel@tonic-gate				}
997c478bd9Sstevel@tonic-gate				yylastch = yytext + x;
1007c478bd9Sstevel@tonic-gate			}
1017c478bd9Sstevel@tonic-gate#endif
1027c478bd9Sstevel@tonic-gate			yyfirst=0;
1037c478bd9Sstevel@tonic-gate		tryagain:
1047c478bd9Sstevel@tonic-gate# ifdef LEXDEBUG
1057c478bd9Sstevel@tonic-gate			if(debug){
1067c478bd9Sstevel@tonic-gate				fprintf(yyout,"char ");
1077c478bd9Sstevel@tonic-gate				allprint(yych);
1087c478bd9Sstevel@tonic-gate				putchar('\n');
1097c478bd9Sstevel@tonic-gate				}
1107c478bd9Sstevel@tonic-gate# endif
1117c478bd9Sstevel@tonic-gate			yyr = yyt;
1127c478bd9Sstevel@tonic-gate			if ( (uintptr_t)yyt > (uintptr_t)yycrank){
1137c478bd9Sstevel@tonic-gate				yyt = yyr + yych;
1147c478bd9Sstevel@tonic-gate				if (yyt <= yytop && yyt->verify+yysvec == yystate){
1157c478bd9Sstevel@tonic-gate					if(yyt->advance+yysvec == YYLERR)	/* error transitions */
1167c478bd9Sstevel@tonic-gate						{unput(*--yylastch);break;}
1177c478bd9Sstevel@tonic-gate					*lsp++ = yystate = yyt->advance+yysvec;
1187c478bd9Sstevel@tonic-gate					if(lsp > &yylstate[YYLMAX]) {
1197c478bd9Sstevel@tonic-gate						fprintf(yyout,"Input string too long, limit %d\n",YYLMAX);
1207c478bd9Sstevel@tonic-gate						exit(1);
1217c478bd9Sstevel@tonic-gate					}
1227c478bd9Sstevel@tonic-gate					goto contin;
1237c478bd9Sstevel@tonic-gate					}
1247c478bd9Sstevel@tonic-gate				}
1257c478bd9Sstevel@tonic-gate# ifdef YYOPTIM
1267c478bd9Sstevel@tonic-gate			else if((uintptr_t)yyt < (uintptr_t)yycrank) {	/* r < yycrank */
1277c478bd9Sstevel@tonic-gate				yyt = yyr = yycrank+(yycrank-yyt);
1287c478bd9Sstevel@tonic-gate# ifdef LEXDEBUG
1297c478bd9Sstevel@tonic-gate				if(debug)fprintf(yyout,"compressed state\n");
1307c478bd9Sstevel@tonic-gate# endif
1317c478bd9Sstevel@tonic-gate				yyt = yyt + yych;
1327c478bd9Sstevel@tonic-gate				if(yyt <= yytop && yyt->verify+yysvec == yystate){
1337c478bd9Sstevel@tonic-gate					if(yyt->advance+yysvec == YYLERR)	/* error transitions */
1347c478bd9Sstevel@tonic-gate						{unput(*--yylastch);break;}
1357c478bd9Sstevel@tonic-gate					*lsp++ = yystate = yyt->advance+yysvec;
1367c478bd9Sstevel@tonic-gate					if(lsp > &yylstate[YYLMAX]) {
1377c478bd9Sstevel@tonic-gate						fprintf(yyout,"Input string too long, limit %d\n",YYLMAX);
1387c478bd9Sstevel@tonic-gate						exit(1);
1397c478bd9Sstevel@tonic-gate					}
1407c478bd9Sstevel@tonic-gate					goto contin;
1417c478bd9Sstevel@tonic-gate					}
1427c478bd9Sstevel@tonic-gate				yyt = yyr + YYU(yymatch[yych]);
1437c478bd9Sstevel@tonic-gate# ifdef LEXDEBUG
1447c478bd9Sstevel@tonic-gate				if(debug){
1457c478bd9Sstevel@tonic-gate					fprintf(yyout,"try fall back character ");
1467c478bd9Sstevel@tonic-gate					allprint(YYU(yymatch[yych]));
1477c478bd9Sstevel@tonic-gate					putchar('\n');
1487c478bd9Sstevel@tonic-gate					}
1497c478bd9Sstevel@tonic-gate# endif
1507c478bd9Sstevel@tonic-gate				if(yyt <= yytop && yyt->verify+yysvec == yystate){
1517c478bd9Sstevel@tonic-gate					if(yyt->advance+yysvec == YYLERR)	/* error transition */
1527c478bd9Sstevel@tonic-gate						{unput(*--yylastch);break;}
1537c478bd9Sstevel@tonic-gate					*lsp++ = yystate = yyt->advance+yysvec;
1547c478bd9Sstevel@tonic-gate					if(lsp > &yylstate[YYLMAX]) {
1557c478bd9Sstevel@tonic-gate						fprintf(yyout,"Input string too long, limit %d\n",YYLMAX);
1567c478bd9Sstevel@tonic-gate						exit(1);
1577c478bd9Sstevel@tonic-gate					}
1587c478bd9Sstevel@tonic-gate					goto contin;
1597c478bd9Sstevel@tonic-gate					}
1607c478bd9Sstevel@tonic-gate				}
1617c478bd9Sstevel@tonic-gate			if ((yystate = yystate->yyother) && (yyt= yystate->yystoff) != yycrank){
1627c478bd9Sstevel@tonic-gate# ifdef LEXDEBUG
1637c478bd9Sstevel@tonic-gate				if(debug)fprintf(yyout,"fall back to state %d\n",yystate-yysvec-1);
1647c478bd9Sstevel@tonic-gate# endif
1657c478bd9Sstevel@tonic-gate				goto tryagain;
1667c478bd9Sstevel@tonic-gate				}
1677c478bd9Sstevel@tonic-gate# endif
1687c478bd9Sstevel@tonic-gate			else
1697c478bd9Sstevel@tonic-gate				{unput(*--yylastch);break;}
1707c478bd9Sstevel@tonic-gate		contin:
1717c478bd9Sstevel@tonic-gate# ifdef LEXDEBUG
1727c478bd9Sstevel@tonic-gate			if(debug){
1737c478bd9Sstevel@tonic-gate				fprintf(yyout,"state %d char ",yystate-yysvec-1);
1747c478bd9Sstevel@tonic-gate				allprint(yych);
1757c478bd9Sstevel@tonic-gate				putchar('\n');
1767c478bd9Sstevel@tonic-gate				}
1777c478bd9Sstevel@tonic-gate# endif
1787c478bd9Sstevel@tonic-gate			;
1797c478bd9Sstevel@tonic-gate			}
1807c478bd9Sstevel@tonic-gate# ifdef LEXDEBUG
1817c478bd9Sstevel@tonic-gate		if(debug){
1827c478bd9Sstevel@tonic-gate			fprintf(yyout,"stopped at %d with ",*(lsp-1)-yysvec-1);
1837c478bd9Sstevel@tonic-gate			allprint(yych);
1847c478bd9Sstevel@tonic-gate			putchar('\n');
1857c478bd9Sstevel@tonic-gate			}
1867c478bd9Sstevel@tonic-gate# endif
1877c478bd9Sstevel@tonic-gate		while (lsp-- > yylstate){
1887c478bd9Sstevel@tonic-gate			*yylastch-- = 0;
1897c478bd9Sstevel@tonic-gate			if (*lsp != 0 && (yyfnd= (*lsp)->yystops) && *yyfnd > 0){
1907c478bd9Sstevel@tonic-gate				yyolsp = lsp;
1917c478bd9Sstevel@tonic-gate				if(yyextra[*yyfnd]){		/* must backup */
1927c478bd9Sstevel@tonic-gate					while(yyback((*lsp)->yystops,-*yyfnd) != 1 && lsp > yylstate){
1937c478bd9Sstevel@tonic-gate						lsp--;
1947c478bd9Sstevel@tonic-gate						unput(*yylastch--);
1957c478bd9Sstevel@tonic-gate						}
1967c478bd9Sstevel@tonic-gate					}
1977c478bd9Sstevel@tonic-gate				yyprevious = YYU(*yylastch);
1987c478bd9Sstevel@tonic-gate				yylsp = lsp;
1997c478bd9Sstevel@tonic-gate				yyleng = yylastch-yytext+1;
2007c478bd9Sstevel@tonic-gate				yytext[yyleng] = 0;
2017c478bd9Sstevel@tonic-gate# ifdef LEXDEBUG
2027c478bd9Sstevel@tonic-gate				if(debug){
2037c478bd9Sstevel@tonic-gate					fprintf(yyout,"\nmatch ");
2047c478bd9Sstevel@tonic-gate					sprint(yytext);
2057c478bd9Sstevel@tonic-gate					fprintf(yyout," action %d\n",*yyfnd);
2067c478bd9Sstevel@tonic-gate					}
2077c478bd9Sstevel@tonic-gate# endif
2087c478bd9Sstevel@tonic-gate				return(*yyfnd++);
2097c478bd9Sstevel@tonic-gate				}
2107c478bd9Sstevel@tonic-gate			unput(*yylastch);
2117c478bd9Sstevel@tonic-gate			}
2127c478bd9Sstevel@tonic-gate		if (yytext[0] == 0  /* && feof(yyin) */)
2137c478bd9Sstevel@tonic-gate			{
2147c478bd9Sstevel@tonic-gate			yysptr=yysbuf;
2157c478bd9Sstevel@tonic-gate			return(0);
2167c478bd9Sstevel@tonic-gate			}
2177c478bd9Sstevel@tonic-gate#ifndef __cplusplus
2187c478bd9Sstevel@tonic-gate		yyprevious = yytext[0] = input();
2197c478bd9Sstevel@tonic-gate		if (yyprevious>0)
2207c478bd9Sstevel@tonic-gate			output(yyprevious);
2217c478bd9Sstevel@tonic-gate#else
2227c478bd9Sstevel@tonic-gate		yyprevious = yytext[0] = lex_input();
2237c478bd9Sstevel@tonic-gate		if (yyprevious>0)
2247c478bd9Sstevel@tonic-gate			lex_output(yyprevious);
2257c478bd9Sstevel@tonic-gate#endif
2267c478bd9Sstevel@tonic-gate		yylastch=yytext;
2277c478bd9Sstevel@tonic-gate# ifdef LEXDEBUG
2287c478bd9Sstevel@tonic-gate		if(debug)putchar('\n');
2297c478bd9Sstevel@tonic-gate# endif
2307c478bd9Sstevel@tonic-gate		}
231*966c588fSToomas Soome}
232*966c588fSToomas Soome
2337c478bd9Sstevel@tonic-gateint yyback(int *p, int m)
2347c478bd9Sstevel@tonic-gate{
2357c478bd9Sstevel@tonic-gate	if (p==0) return(0);
2367c478bd9Sstevel@tonic-gate	while (*p) {
2377c478bd9Sstevel@tonic-gate		if (*p++ == m)
2387c478bd9Sstevel@tonic-gate			return(1);
2397c478bd9Sstevel@tonic-gate	}
2407c478bd9Sstevel@tonic-gate	return(0);
2417c478bd9Sstevel@tonic-gate}
242*966c588fSToomas Soome
243*966c588fSToomas Soome/* the following are only used in the lex library */
244*966c588fSToomas Soomeint
245*966c588fSToomas Soomeyyinput(void)
2467c478bd9Sstevel@tonic-gate{
2477c478bd9Sstevel@tonic-gate#ifndef __cplusplus
2487c478bd9Sstevel@tonic-gate	return(input());
2497c478bd9Sstevel@tonic-gate#else
2507c478bd9Sstevel@tonic-gate	return(lex_input());
2517c478bd9Sstevel@tonic-gate#endif
252*966c588fSToomas Soome}
253*966c588fSToomas Soome
254*966c588fSToomas Soomevoid
255*966c588fSToomas Soomeyyoutput(int c)
2567c478bd9Sstevel@tonic-gate{
2577c478bd9Sstevel@tonic-gate#ifndef __cplusplus
2587c478bd9Sstevel@tonic-gate	output(c);
2597c478bd9Sstevel@tonic-gate#else
2607c478bd9Sstevel@tonic-gate	lex_output(c);
2617c478bd9Sstevel@tonic-gate#endif
262*966c588fSToomas Soome}
263*966c588fSToomas Soome
264*966c588fSToomas Soomevoid
265*966c588fSToomas Soomeyyunput(int c)
2667c478bd9Sstevel@tonic-gate{
2677c478bd9Sstevel@tonic-gate	unput(c);
268*966c588fSToomas Soome}
269