xref: /illumos-gate/usr/src/cmd/sgs/lex/common/reject.c (revision 533affcbc7fc4d0c8132976ea454aaa715fe2307)
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 /*	Copyright (c) 1989 AT&T	*/
23 /*	  All Rights Reserved	*/
24 
25 
26 #include <stdio.h>
27 
28 #ifdef EUC
29 #include <euc.h>
30 #include <widec.h>
31 #include <limits.h>
32 #endif
33 
34 
35 #ifndef JLSLEX
36 #pragma weak yyinput
37 #pragma weak yyleng
38 #pragma weak yytext
39 #pragma weak yyunput
40 
41 #define	CHR    char
42 #define	YYTEXT yytext
43 #define	YYLENG yyleng
44 #define	YYINPUT yyinput
45 #define	YYUNPUT yyunput
46 #define	YYOUTPUT yyoutput
47 #define	YYREJECT yyreject
48 #endif
49 
50 #ifdef WOPTION
51 #pragma weak yyinput
52 #pragma weak yyleng
53 #pragma weak yytext
54 #pragma weak yyunput
55 
56 #define	CHR    wchar_t
57 #define	YYTEXT yytext
58 #define	YYLENG yyleng
59 #define	YYINPUT yyinput
60 #define	YYUNPUT yyunput
61 #define	YYOUTPUT yyoutput
62 #define	YYREJECT yyreject_w
63 #endif
64 
65 #ifdef EOPTION
66 #pragma weak yyleng
67 #pragma weak yytext
68 #pragma weak yywinput
69 #pragma weak yywleng
70 #pragma weak yywtext
71 #pragma weak yywunput
72 
73 #define	CHR    wchar_t
74 #define	YYTEXT yywtext
75 #define	YYLENG yywleng
76 #define	YYINPUT yywinput
77 #define	YYUNPUT yywunput
78 #define	YYOUTPUT yywoutput
79 #define	YYREJECT yyreject_e
80 extern unsigned char yytext[];
81 extern int yyleng;
82 #endif
83 
84 #pragma weak yyback
85 extern int	yyback(int *, int);
86 extern int	YYINPUT(void);
87 extern void	YYUNPUT(int);
88 #ifdef EUC
89 	static int	yyracc(int);
90 #else
91 	extern int	yyracc(int);
92 #endif
93 #ifdef EOPTION
94 	extern size_t	wcstombs(char *, const wchar_t *, size_t);
95 #endif
96 
97 #pragma weak yyout
98 extern FILE *yyout, *yyin;
99 
100 #pragma weak yyfnd
101 #pragma weak yyprevious
102 extern int yyprevious, *yyfnd;
103 
104 #pragma weak yyextra
105 extern char yyextra[];
106 
107 extern int YYLENG;
108 extern CHR YYTEXT[];
109 
110 #pragma weak yylsp
111 #pragma weak yylstate
112 #pragma weak yyolsp
113 extern struct {int *yyaa, *yybb; int *yystops; } *yylstate[], **yylsp, **yyolsp;
114 
115 int
116 YYREJECT(void)
117 {
118 	for (; yylsp < yyolsp; yylsp++)
119 		YYTEXT[YYLENG++] = YYINPUT();
120 	if (*yyfnd > 0)
121 		return (yyracc(*yyfnd++));
122 	while (yylsp-- > yylstate) {
123 		YYUNPUT(YYTEXT[YYLENG-1]);
124 		YYTEXT[--YYLENG] = 0;
125 		if (*yylsp != 0 && (yyfnd = (*yylsp)->yystops) && *yyfnd > 0)
126 			return (yyracc(*yyfnd++));
127 	}
128 #ifdef EOPTION
129 	yyleng = wcstombs((char *)yytext, YYTEXT, YYLENG*MB_LEN_MAX);
130 #endif
131 	if (YYTEXT[0] == 0)
132 		return (0);
133 	YYLENG = 0;
134 #ifdef EOPTION
135 	yyleng = 0;
136 #endif
137 	return (-1);
138 }
139 
140 int
141 yyracc(int m)
142 {
143 	yyolsp = yylsp;
144 	if (yyextra[m]) {
145 		while (yyback((*yylsp)->yystops, -m) != 1 && yylsp > yylstate) {
146 			yylsp--;
147 			YYUNPUT(YYTEXT[--YYLENG]);
148 		}
149 	}
150 	yyprevious = YYTEXT[YYLENG-1];
151 	YYTEXT[YYLENG] = 0;
152 #ifdef EOPTION
153 	yyleng = wcstombs((char *)yytext, YYTEXT, YYLENG*MB_LEN_MAX);
154 #endif
155 	return (m);
156 }
157