source: trunk/athena/bin/lpr/filters/ln01filter.c @ 729

Revision 729, 8.3 KB checked in by tytso, 37 years ago (diff)
Initial revision
Line 
1# include "stdio.h"
2# define U(x) x
3# define NLSTATE yyprevious=YYNEWLINE
4# define BEGIN yybgin = yysvec + 1 +
5# define INITIAL 0
6# define YYLERR yysvec
7# define YYSTATE (yyestate-yysvec-1)
8# define YYOPTIM 1
9# define YYLMAX 200
10# define output(c) putc(c,yyout)
11# define input() (((yytchar=yysptr>yysbuf?U(*--yysptr):getc(yyin))==10?(yylineno++,yytchar):yytchar)==EOF?0:yytchar)
12# define unput(c) {yytchar= (c);if(yytchar=='\n')yylineno--;*yysptr++=yytchar;}
13# define yymore() (yymorfg=1)
14# define ECHO fprintf(yyout, "%s",yytext)
15# define REJECT { nstr = yyreject(); goto yyfussy;}
16int yyleng; extern char yytext[];
17int yymorfg;
18extern char *yysptr, yysbuf[];
19int yytchar;
20FILE *yyin ={stdin}, *yyout ={stdout};
21extern int yylineno;
22struct yysvf {
23        struct yywork *yystoff;
24        struct yysvf *yyother;
25        int *yystops;};
26struct yysvf *yyestate;
27extern struct yysvf yysvec[], *yybgin;
28#include <sys/file.h>
29#include <signal.h>
30extern int sighandler();
31char *reset="\033c";                    /* ris  */
32char *land_length="\033[2550t";
33char *landscape="\033[10m";
34char *port_length="\033[3300t";         /* form length = 11 inches */
35char *portrait="\033[11m";
36char *beginunderline = "\033[4m";
37char *endunderline = "\033[0m";
38char *mode;
39char *form_length;
40# define YYNEWLINE 10
41yylex(){
42int nstr; extern int yyprevious;
43while((nstr = yylook()) >= 0)
44yyfussy: switch(nstr){
45case 0:
46if(yywrap()) return(0); break;
47case 1:
48                {
49                                printf("\f%s%s%s",reset,mode,form_length);
50                                fflush(stdout);
51                        }
52break;
53case 2:
54{
55                                register char *p = &yytext[0];
56                                printf(beginunderline);
57                                while(*p)
58                                {
59                                        if((*p != '_') && (*p != '\b'))
60                                        {
61                                                putchar(*p);
62                                        }
63                                        ++p;
64                                }
65                                printf(endunderline);
66                                fflush(stdout);
67                        }
68break;
69case 3:
70        { /* ^Y^A */
71                                /*
72                                 * lpd needs to use a different filter to
73                                 * print data so stop what we are doing and
74                                 * wait for lpd to restart us.
75                                 */
76                                fflush(stdout);
77                                kill(getpid(), SIGSTOP);
78                                printf("%s%s%s",reset,mode,form_length);
79                                fflush(stdout);
80                        }
81break;
82case -1:
83break;
84default:
85fprintf(yyout,"bad switch yylook %d",nstr);
86} return(0); }
87/* end of yylex */
88
89yywrap()
90{
91        fflush(stdout);
92        flock(1, LOCK_UN);
93        return(1);
94}
95main(argc,argv)
96int argc;
97register char *argv[];
98{
99        register int i;
100        flock(1, LOCK_EX);
101        if(!strcmp(argv[0], "ln01l")) {
102                mode = landscape;
103                form_length = land_length;
104        }
105        else {
106                mode = portrait;
107                form_length = port_length;
108        }
109        setbuf(stdout, NULL);
110        printf("%s%s%s",reset,mode,form_length);
111        fflush(stdout);
112        while(1) {
113                        if(yylex() <= 0) break;
114        }
115}
116
117/* Local Modes: */
118/* Mode:C */
119/* End: */
120int yyvstop[] ={
1210,
122
1231,
1240,
125
1263,
1270,
128
1292,
1300,
1310};
132# define YYTYPE char
133struct yywork { YYTYPE verify, advance; } yycrank[] ={
1340,0,    0,0,    4,6,    0,0,   
1350,0,    0,0,    0,0,    0,0,   
1360,0,    5,7,    0,0,    0,0,   
1370,0,    1,3,    0,0,    0,0,   
1380,0,    0,0,    0,0,    0,0,   
1390,0,    0,0,    0,0,    0,0,   
1400,0,    0,0,    1,4,    7,0,   
1417,0,    7,0,    7,0,    7,0,   
1427,0,    7,0,    7,0,    7,8,   
1437,0,    7,0,    7,0,    7,0,   
1447,0,    7,0,    7,0,    7,0,   
1457,0,    7,0,    7,0,    7,0,   
1467,0,    7,0,    7,0,    7,0,   
1477,0,    7,0,    7,0,    7,0,   
1487,0,    7,0,    0,0,    0,0,   
1490,0,    0,0,    0,0,    0,0,   
1500,0,    0,0,    0,0,    0,0,   
1510,0,    0,0,    0,0,    7,0,   
1520,0,    0,0,    0,0,    0,0,   
1530,0,    0,0,    0,0,    0,0,   
1540,0,    0,0,    0,0,    0,0,   
1550,0,    0,0,    0,0,    0,0,   
1560,0,    0,0,    0,0,    0,0,   
1570,0,    0,0,    0,0,    0,0,   
1581,5,    8,5,    0,0,    0,0,   
1590,0,    0,0,    0,0,    0,0,   
1600,0,    0,0,    0,0,    0,0,   
1610,0,    0,0,    0,0,    0,0,   
1620,0,    0,0,    0,0,    0,0,   
1630,0,    0,0,    0,0,    0,0,   
1640,0,    0,0,    0,0,    0,0,   
1650,0,    0,0,    0,0,    0,0,   
1660,0,    0,0,    0,0,    0,0,   
1670,0,    0,0,    0,0,    0,0,   
1680,0,    0,0,    0,0,    0,0,   
1690,0,    0,0,    0,0,    0,0,   
1700,0,    0,0,    0,0,    0,0,   
1710,0,    0,0,    0,0,    0,0,   
1720,0,    7,0,    0,0,    0,0,   
1730,0};
174struct yysvf yysvec[] ={
1750,      0,      0,
176yycrank+1,      0,              0,     
177yycrank+0,      yysvec+1,       0,     
178yycrank+0,      0,              yyvstop+1,
179yycrank+1,      0,              0,     
180yycrank+1,      0,              0,     
181yycrank+0,      0,              yyvstop+3,
182yycrank+-26,    0,              0,     
183yycrank+2,      0,              yyvstop+5,
1840,      0,      0};
185struct yywork *yytop = yycrank+153;
186struct yysvf *yybgin = yysvec+1;
187char yymatch[] ={
18800  ,01  ,01  ,01  ,01  ,01  ,01  ,01  ,
18901  ,011 ,01  ,01  ,01  ,01  ,01  ,01  ,
19001  ,01  ,01  ,01  ,01  ,01  ,01  ,01  ,
19101  ,01  ,01  ,01  ,01  ,01  ,01  ,01  ,
192011 ,011 ,011 ,011 ,011 ,011 ,011 ,011 ,
193011 ,011 ,011 ,011 ,011 ,01  ,011 ,011 ,
194011 ,011 ,011 ,011 ,011 ,011 ,011 ,011 ,
195011 ,011 ,011 ,011 ,011 ,011 ,011 ,011 ,
196011 ,011 ,011 ,011 ,011 ,011 ,011 ,011 ,
197011 ,011 ,011 ,011 ,011 ,011 ,011 ,011 ,
198011 ,011 ,011 ,011 ,011 ,011 ,011 ,011 ,
199011 ,011 ,011 ,011 ,011 ,011 ,011 ,011 ,
200011 ,011 ,011 ,011 ,011 ,011 ,011 ,011 ,
201011 ,011 ,011 ,011 ,011 ,011 ,011 ,011 ,
202011 ,011 ,011 ,011 ,011 ,011 ,011 ,011 ,
203011 ,011 ,011 ,011 ,011 ,011 ,011 ,01  ,
2040};
205char yyextra[] ={
2060,0,0,0,0,0,0,0,
2070};
208/*      ncform  4.1     83/08/11        */
209
210int yylineno =1;
211# define YYU(x) x
212# define NLSTATE yyprevious=YYNEWLINE
213char yytext[YYLMAX];
214struct yysvf *yylstate [YYLMAX], **yylsp, **yyolsp;
215char yysbuf[YYLMAX];
216char *yysptr = yysbuf;
217int *yyfnd;
218extern struct yysvf *yyestate;
219int yyprevious = YYNEWLINE;
220yylook(){
221        register struct yysvf *yystate, **lsp;
222        register struct yywork *yyt;
223        struct yysvf *yyz;
224        int yych;
225        struct yywork *yyr;
226# ifdef LEXDEBUG
227        int debug;
228# endif
229        char *yylastch;
230        /* start off machines */
231# ifdef LEXDEBUG
232        debug = 0;
233# endif
234        if (!yymorfg)
235                yylastch = yytext;
236        else {
237                yymorfg=0;
238                yylastch = yytext+yyleng;
239                }
240        for(;;){
241                lsp = yylstate;
242                yyestate = yystate = yybgin;
243                if (yyprevious==YYNEWLINE) yystate++;
244                for (;;){
245# ifdef LEXDEBUG
246                        if(debug)fprintf(yyout,"state %d\n",yystate-yysvec-1);
247# endif
248                        yyt = yystate->yystoff;
249                        if(yyt == yycrank){             /* may not be any transitions */
250                                yyz = yystate->yyother;
251                                if(yyz == 0)break;
252                                if(yyz->yystoff == yycrank)break;
253                                }
254                        *yylastch++ = yych = input();
255                tryagain:
256# ifdef LEXDEBUG
257                        if(debug){
258                                fprintf(yyout,"char ");
259                                allprint(yych);
260                                putchar('\n');
261                                }
262# endif
263                        yyr = yyt;
264                        if ( (int)yyt > (int)yycrank){
265                                yyt = yyr + yych;
266                                if (yyt <= yytop && yyt->verify+yysvec == yystate){
267                                        if(yyt->advance+yysvec == YYLERR)       /* error transitions */
268                                                {unput(*--yylastch);break;}
269                                        *lsp++ = yystate = yyt->advance+yysvec;
270                                        goto contin;
271                                        }
272                                }
273# ifdef YYOPTIM
274                        else if((int)yyt < (int)yycrank) {              /* r < yycrank */
275                                yyt = yyr = yycrank+(yycrank-yyt);
276# ifdef LEXDEBUG
277                                if(debug)fprintf(yyout,"compressed state\n");
278# endif
279                                yyt = yyt + yych;
280                                if(yyt <= yytop && yyt->verify+yysvec == yystate){
281                                        if(yyt->advance+yysvec == YYLERR)       /* error transitions */
282                                                {unput(*--yylastch);break;}
283                                        *lsp++ = yystate = yyt->advance+yysvec;
284                                        goto contin;
285                                        }
286                                yyt = yyr + YYU(yymatch[yych]);
287# ifdef LEXDEBUG
288                                if(debug){
289                                        fprintf(yyout,"try fall back character ");
290                                        allprint(YYU(yymatch[yych]));
291                                        putchar('\n');
292                                        }
293# endif
294                                if(yyt <= yytop && yyt->verify+yysvec == yystate){
295                                        if(yyt->advance+yysvec == YYLERR)       /* error transition */
296                                                {unput(*--yylastch);break;}
297                                        *lsp++ = yystate = yyt->advance+yysvec;
298                                        goto contin;
299                                        }
300                                }
301                        if ((yystate = yystate->yyother) && (yyt= yystate->yystoff) != yycrank){
302# ifdef LEXDEBUG
303                                if(debug)fprintf(yyout,"fall back to state %d\n",yystate-yysvec-1);
304# endif
305                                goto tryagain;
306                                }
307# endif
308                        else
309                                {unput(*--yylastch);break;}
310                contin:
311# ifdef LEXDEBUG
312                        if(debug){
313                                fprintf(yyout,"state %d char ",yystate-yysvec-1);
314                                allprint(yych);
315                                putchar('\n');
316                                }
317# endif
318                        ;
319                        }
320# ifdef LEXDEBUG
321                if(debug){
322                        fprintf(yyout,"stopped at %d with ",*(lsp-1)-yysvec-1);
323                        allprint(yych);
324                        putchar('\n');
325                        }
326# endif
327                while (lsp-- > yylstate){
328                        *yylastch-- = 0;
329                        if (*lsp != 0 && (yyfnd= (*lsp)->yystops) && *yyfnd > 0){
330                                yyolsp = lsp;
331                                if(yyextra[*yyfnd]){            /* must backup */
332                                        while(yyback((*lsp)->yystops,-*yyfnd) != 1 && lsp > yylstate){
333                                                lsp--;
334                                                unput(*yylastch--);
335                                                }
336                                        }
337                                yyprevious = YYU(*yylastch);
338                                yylsp = lsp;
339                                yyleng = yylastch-yytext+1;
340                                yytext[yyleng] = 0;
341# ifdef LEXDEBUG
342                                if(debug){
343                                        fprintf(yyout,"\nmatch ");
344                                        sprint(yytext);
345                                        fprintf(yyout," action %d\n",*yyfnd);
346                                        }
347# endif
348                                return(*yyfnd++);
349                                }
350                        unput(*yylastch);
351                        }
352                if (yytext[0] == 0  && feof(yyin) )
353                        {
354                        yysptr=yysbuf;
355                        return(0);
356                        }
357                yyprevious = yytext[0] = input();
358                if (yyprevious>0)
359                        output(yyprevious);
360                yylastch=yytext;
361# ifdef LEXDEBUG
362                if(debug)putchar('\n');
363# endif
364                }
365        }
366yyback(p, m)
367        int *p;
368{
369if (p==0) return(0);
370while (*p)
371        {
372        if (*p++ == m)
373                return(1);
374        }
375return(0);
376}
377        /* the following are only used in the lex library */
378yyinput(){
379        return(input());
380        }
381yyoutput(c)
382  int c; {
383        output(c);
384        }
385yyunput(c)
386   int c; {
387        unput(c);
388        }
Note: See TracBrowser for help on using the repository browser.