]> git.lizzy.rs Git - plan9front.git/blob - sys/src/cmd/lex/ncform
ip/tftpd: use procsetuser() instead of writing #c/user
[plan9front.git] / sys / src / cmd / lex / ncform
1 #pragma lib     "libl.a"
2 int yylineno =1;
3 # define YYU(x) x
4 char yytext[YYLMAX];
5 struct yysvf *yylstate [YYLMAX], **yylsp, **yyolsp;
6 Uchar yysbuf[YYLMAX];
7 Uchar *yysptr = yysbuf;
8 int *yyfnd;
9 extern struct yysvf *yyestate;
10 int yyprevious = YYNEWLINE;
11 # ifdef LEXDEBUG
12 extern void allprint(int);
13 # endif
14 yylook(void){
15         struct yysvf *yystate, **lsp;
16         struct yywork *yyt;
17         struct yysvf *yyz;
18         int yych;
19         struct yywork *yyr;
20 # ifdef LEXDEBUG
21         int debug;
22 # endif
23         Uchar *yylastch;
24         /* start off machines */
25 # ifdef LEXDEBUG
26         debug = 0;
27 # endif
28         if (!yymorfg)
29                 yylastch = (Uchar*)yytext;
30         else {
31                 yymorfg=0;
32                 yylastch = (Uchar*)yytext+yyleng;
33                 }
34         for(;;){
35                 lsp = yylstate;
36                 yyestate = yystate = yybgin;
37                 if (yyprevious==YYNEWLINE) yystate++;
38                 for (;;){
39 # ifdef LEXDEBUG
40                         if(debug)fprintf(yyout,"state %d\n",yystate-yysvec-1);
41 # endif
42                         yyt = yystate->yystoff;
43                         if(yyt == yycrank){             /* may not be any transitions */
44                                 yyz = yystate->yyother;
45                                 if(yyz == 0)break;
46                                 if(yyz->yystoff == yycrank)break;
47                                 }
48                         *yylastch++ = yych = input();
49                 tryagain:
50 # ifdef LEXDEBUG
51                         if(debug){
52                                 fprintf(yyout,"char ");
53                                 allprint(yych);
54                                 putchar('\n');
55                                 }
56 # endif
57                         yyr = yyt;
58                         if (yyt > yycrank){
59                                 yyt = yyr + yych;
60                                 if (yyt <= yytop && yyt->verify+yysvec == yystate){
61                                         if(yyt->advance+yysvec == YYLERR)       /* error transitions */
62                                                 {unput(*--yylastch);break;}
63                                         *lsp++ = yystate = yyt->advance+yysvec;
64                                         goto contin;
65                                         }
66                                 }
67 # ifdef YYOPTIM
68                         else if(yyt < yycrank) {        /* r < yycrank */
69                                 yyt = yyr = yycrank+(yycrank-yyt);
70 # ifdef LEXDEBUG
71                                 if(debug)fprintf(yyout,"compressed state\n");
72 # endif
73                                 yyt = yyt + yych;
74                                 if(yyt <= yytop && yyt->verify+yysvec == yystate){
75                                         if(yyt->advance+yysvec == YYLERR)       /* error transitions */
76                                                 {unput(*--yylastch);break;}
77                                         *lsp++ = yystate = yyt->advance+yysvec;
78                                         goto contin;
79                                         }
80                                 yyt = yyr + YYU(yymatch[yych]);
81 # ifdef LEXDEBUG
82                                 if(debug){
83                                         fprintf(yyout,"try fall back character ");
84                                         allprint(YYU(yymatch[yych]));
85                                         putchar('\n');
86                                         }
87 # endif
88                                 if(yyt <= yytop && yyt->verify+yysvec == yystate){
89                                         if(yyt->advance+yysvec == YYLERR)       /* error transition */
90                                                 {unput(*--yylastch);break;}
91                                         *lsp++ = yystate = yyt->advance+yysvec;
92                                         goto contin;
93                                         }
94                                 }
95                         if ((yystate = yystate->yyother) && (yyt= yystate->yystoff) != yycrank){
96 # ifdef LEXDEBUG
97                                 if(debug)fprintf(yyout,"fall back to state %d\n",yystate-yysvec-1);
98 # endif
99                                 goto tryagain;
100                                 }
101 # endif
102                         else
103                                 {unput(*--yylastch);break;}
104                 contin:
105 # ifdef LEXDEBUG
106                         if(debug){
107                                 fprintf(yyout,"state %d char ",yystate-yysvec-1);
108                                 allprint(yych);
109                                 putchar('\n');
110                                 }
111 # endif
112                         ;
113                         }
114 # ifdef LEXDEBUG
115                 if(debug){
116                         fprintf(yyout,"stopped at %d with ",lsp>yylstate?*(lsp-1)-yysvec-1:0);
117                         allprint(yych);
118                         putchar('\n');
119                         }
120 # endif
121                 while (lsp-- > yylstate){
122                         *yylastch-- = 0;
123                         if (*lsp != 0 && (yyfnd= (*lsp)->yystops) && *yyfnd > 0){
124                                 yyolsp = lsp;
125                                 if(yyextra[*yyfnd]){            /* must backup */
126                                         while(yyback((*lsp)->yystops,-*yyfnd) != 1 && lsp > yylstate){
127                                                 lsp--;
128                                                 unput(*yylastch--);
129                                                 }
130                                         }
131                                 yyprevious = YYU(*yylastch);
132                                 yylsp = lsp;
133                                 yyleng = yylastch-(Uchar*)yytext+1;
134                                 yytext[yyleng] = 0;
135 # ifdef LEXDEBUG
136                                 if(debug){
137                                         fprintf(yyout,"\nmatch '%s'", yytext);
138                                         fprintf(yyout," action %d\n",*yyfnd);
139                                         }
140 # endif
141                                 return(*yyfnd++);
142                                 }
143                         unput(*yylastch);
144                         }
145                 if (yytext[0] == 0  /* && feof(yyin) */)
146                         {
147                         yysptr=yysbuf;
148                         return(0);
149                         }
150                 yyprevious = input();
151                 yytext[0] = yyprevious;
152                 if (yyprevious>0)
153                         output(yyprevious);
154                 yylastch = (Uchar*)yytext;
155 # ifdef LEXDEBUG
156                 if(debug)putchar('\n');
157 # endif
158                 }
159         }
160 yyback(int *p, int m)
161 {
162 if (p==0) return(0);
163 while (*p)
164         {
165         if (*p++ == m)
166                 return(1);
167         }
168 return(0);
169 }
170         /* the following are only used in the lex library */
171 yyinput(void){
172         return(input());
173 }
174 void
175 yyoutput(int c)
176 {
177         output(c);
178 }
179 void
180 yyunput(int c)
181 {
182         unput(c);
183 }