xref: /plan9/sys/src/ape/lib/l/reject.c (revision 3e12c5d1bb89fc02707907988834ef147769ddaf)
1 #include	<libl.h>
2 #include	<stdio.h>
3 
4 extern	FILE*	yyout;
5 extern	FILE*	yyin;
6 extern	int	yyprevious, *yyfnd;
7 extern	char	yyextra[];
8 extern	char	yytext[];
9 extern	int	yyleng;
10 
11 extern
12 struct
13 {
14 	int *yyaa, *yybb;
15 	int *yystops;
16 } *yylstate [], **yylsp, **yyolsp;
17 
18 int	yyback(int *p, int m);
19 int	yyinput(void);
20 void	yyoutput(int c);
21 void	yyunput(int c);
22 
23 int
yyracc(int m)24 yyracc(int m)
25 {
26 
27 	yyolsp = yylsp;
28 	if(yyextra[m]) {
29 		while(yyback((*yylsp)->yystops, -m) != 1 && yylsp > yylstate) {
30 			yylsp--;
31 			yyunput(yytext[--yyleng]);
32 		}
33 	}
34 	yyprevious = yytext[yyleng-1];
35 	yytext[yyleng] = 0;
36 	return m;
37 }
38 
39 int
yyreject(void)40 yyreject(void)
41 {
42 	for(; yylsp < yyolsp; yylsp++)
43 		yytext[yyleng++] = yyinput();
44 	if(*yyfnd > 0)
45 		return yyracc(*yyfnd++);
46 	while(yylsp-- > yylstate) {
47 		yyunput(yytext[yyleng-1]);
48 		yytext[--yyleng] = 0;
49 		if(*yylsp != 0 && (yyfnd = (*yylsp)->yystops) && *yyfnd > 0)
50 			return yyracc(*yyfnd++);
51 	}
52 	if(yytext[0] == 0)
53 		return 0;
54 	yyoutput(yyprevious = yyinput());
55 	yyleng = 0;
56 	return -1;
57 }
58