033314e9187f9a761e7f53fa44a04c35e34f8292
[ghc-hetmet.git] / glafp-utils / verbatim / verbatim.c
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 BUFSIZ
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;}
16 int yyleng; extern char yytext[];
17 int yymorfg;
18 extern char *yysptr, yysbuf[];
19 int yytchar;
20 FILE *yyin = {stdin}, *yyout = {stdout};
21 extern int yylineno;
22 struct yysvf { 
23         struct yywork *yystoff;
24         struct yysvf *yyother;
25         int *yystops;};
26 struct yysvf *yyestate;
27 extern struct yysvf yysvec[], *yybgin;
28   /*    This Lex script acts as a filter to pre-process Latex files.
29         It surrounds groups of lines beginning with a ">" sign, and
30         preceded and followed by a blank line, with \begin{verbatim} 
31         and \end{verbatim}.  The ">" may be preceded by a digit or digit
32         range (eg 4>, 2-5>, 3->); in this case the digits are removed.  
33         They are meant to be used for filtering out versions.
34         It takes words surrounded with @ signs (thus @letrec@) and makes them
35         come out in typewriter font, regardless of the current mode.
36   */
37 # define NORM 2
38 # define VERB 4
39 # define MIRANDA 6
40 # define VERBATIM 8
41 # define VERBATIMSIM 10
42 #define PUSH            states[top++] =
43 #define POP             BEGIN states[--top]
44 #define yywrap()        1
45 # define YYNEWLINE 10
46 yylex(){
47 int nstr; extern int yyprevious;
48                 int states[256];
49                 int top;
50                 BEGIN NORM;
51                 top = 0;
52 while((nstr = yylook()) >= 0)
53 yyfussy: switch(nstr){
54 case 0:
55 if(yywrap()) return(0); break;
56 case 1:
57         { printf ("@"); }
58 break;
59 case 2:
60                 { printf ("\\mbox{\\tt "); PUSH NORM;  BEGIN VERB; }
61 break;
62 case 3:
63                 { printf ("}");  POP; }
64 break;
65 case 4:
66         { printf ("}\\\\{}\n\\mbox{\\tt "); }
67 break;
68 case 5:
69         { printf ("\\ "); }
70 break;
71 case 6:
72         { printf ("@"); }
73 break;
74 case 7:
75         { printf ("{\\char'43}"); }
76 break;
77 case 8:
78         { printf ("{\\char'44}"); }
79 break;
80 case 9:
81         { printf ("{\\char'45}"); }
82 break;
83 case 10:
84         { printf ("{\\char'46}"); }
85 break;
86 case 11:
87         { printf ("{\\char'176}"); }
88 break;
89 case 12:
90         { printf ("{\\char'137}"); }
91 break;
92 case 13:
93         { printf ("{\\char'136}"); }
94 break;
95 case 14:
96         { printf ("{\\char'134}"); }
97 break;
98 case 15:
99         { printf ("{\\char'173}"); }
100 break;
101 case 16:
102         { printf ("{\\char'175}"); }
103 break;
104 case 17:
105         { printf( "\\begin{verbatim}\n" ); 
106                           PUSH NORM; BEGIN VERBATIMSIM; }
107 break;
108 case 18:
109 { printf( "\\end{verbatim}\n" ); POP; }
110 break;
111 case 19:
112 { printf( "\\begin{verbatim}" ); 
113                                   PUSH NORM; BEGIN VERBATIM; }
114 break;
115 case 20:
116 { printf( "\\end{verbatim}" ); POP; }
117 break;
118 case 21:
119 { printf ("\\begin{verbatim}\n>" ); 
120                           PUSH NORM; BEGIN MIRANDA; }
121 break;
122 case 22:
123 { printf( "\n>" ); }
124 break;
125 case 23:
126         { printf ("\\end{verbatim}\n"); POP; }
127 break;
128 case -1:
129 break;
130 default:
131 fprintf(yyout,"bad switch yylook %d",nstr);
132 } return(0); }
133 /* end of yylex */
134 int
135 main()
136 {
137     yylex();
138     return(0);
139 }
140 int yyvstop[] = {
141 0,
142
143 2,
144 0,
145
146 2,
147 0,
148
149 4,
150 0,
151
152 5,
153 0,
154
155 7,
156 0,
157
158 8,
159 0,
160
161 9,
162 0,
163
164 10,
165 0,
166
167 3,
168 0,
169
170 14,
171 0,
172
173 13,
174 0,
175
176 12,
177 0,
178
179 15,
180 0,
181
182 16,
183 0,
184
185 11,
186 0,
187
188 23,
189 0,
190
191 1,
192 0,
193
194 21,
195 0,
196
197 17,
198 0,
199
200 6,
201 0,
202
203 22,
204 0,
205
206 18,
207 0,
208
209 20,
210 0,
211
212 19,
213 0,
214 0};
215 # define YYTYPE char
216 struct yywork { YYTYPE verify, advance; } yycrank[] = {
217 0,0,    0,0,    0,0,    0,0,    
218 0,0,    0,0,    0,0,    0,0,    
219 0,0,    0,0,    0,0,    0,0,    
220 4,15,   5,17,   7,30,   8,31,   
221 33,43,  0,0,    0,0,    0,0,    
222 0,0,    0,0,    0,0,    0,0,    
223 0,0,    0,0,    16,38,  0,0,    
224 0,0,    0,0,    0,0,    0,0,    
225 0,0,    0,0,    0,0,    5,18,   
226 0,0,    0,0,    5,19,   5,20,   
227 5,21,   5,22,   0,0,    0,0,    
228 0,0,    0,0,    0,0,    0,0,    
229 36,45,  40,46,  0,0,    45,45,  
230 45,45,  45,45,  45,45,  45,45,  
231 45,45,  45,45,  45,45,  45,45,  
232 45,45,  0,0,    0,0,    0,0,    
233 0,0,    3,13,   4,16,   5,23,   
234 12,33,  13,34,  15,36,  15,36,  
235 15,36,  15,36,  15,36,  15,36,  
236 15,36,  15,36,  15,36,  15,36,  
237 16,34,  23,39,  0,0,    0,0,    
238 15,37,  0,0,    0,0,    0,0,    
239 0,0,    0,0,    0,0,    0,0,    
240 0,0,    3,14,   4,14,   5,24,   
241 9,32,   5,25,   5,26,   0,0,    
242 0,0,    14,35,  30,40,  30,40,  
243 30,40,  30,40,  30,40,  30,40,  
244 30,40,  30,40,  30,40,  30,40,  
245 32,42,  35,44,  42,47,  44,48,  
246 30,41,  47,49,  48,50,  53,55,  
247 56,58,  57,59,  59,61,  60,62,  
248 50,52,  62,64,  5,27,   63,65,  
249 5,28,   5,29,   46,46,  46,46,  
250 46,46,  46,46,  46,46,  46,46,  
251 46,46,  46,46,  46,46,  46,46,  
252 49,51,  51,53,  52,54,  54,56,  
253 55,57,  58,60,  61,63,  64,66,  
254 65,67,  66,68,  67,69,  68,70,  
255 70,71,  0,0,    0,0,    0,0,    
256 0,0};
257 struct yysvf yysvec[] = {
258 0,      0,      0,
259 yycrank+0,      0,              0,      
260 yycrank+0,      0,              0,      
261 yycrank+1,      0,              0,      
262 yycrank+2,      0,              0,      
263 yycrank+3,      0,              0,      
264 yycrank+0,      yysvec+5,       0,      
265 yycrank+4,      0,              0,      
266 yycrank+5,      0,              0,      
267 yycrank+4,      0,              0,      
268 yycrank+0,      yysvec+9,       0,      
269 yycrank+0,      0,              0,      
270 yycrank+4,      0,              0,      
271 yycrank+5,      0,              yyvstop+1,
272 yycrank+3,      0,              0,      
273 yycrank+22,     0,              0,      
274 yycrank+16,     0,              yyvstop+3,
275 yycrank+0,      0,              yyvstop+5,
276 yycrank+0,      0,              yyvstop+7,
277 yycrank+0,      0,              yyvstop+9,
278 yycrank+0,      0,              yyvstop+11,
279 yycrank+0,      0,              yyvstop+13,
280 yycrank+0,      0,              yyvstop+15,
281 yycrank+17,     0,              yyvstop+17,
282 yycrank+0,      0,              yyvstop+19,
283 yycrank+0,      0,              yyvstop+21,
284 yycrank+0,      0,              yyvstop+23,
285 yycrank+0,      0,              yyvstop+25,
286 yycrank+0,      0,              yyvstop+27,
287 yycrank+0,      0,              yyvstop+29,
288 yycrank+54,     0,              0,      
289 yycrank+0,      yysvec+30,      yyvstop+31,
290 yycrank+11,     0,              0,      
291 yycrank+6,      0,              0,      
292 yycrank+0,      0,              yyvstop+33,
293 yycrank+12,     0,              0,      
294 yycrank+3,      yysvec+15,      0,      
295 yycrank+0,      0,              yyvstop+35,
296 yycrank+0,      0,              yyvstop+37,
297 yycrank+0,      0,              yyvstop+39,
298 yycrank+4,      yysvec+30,      0,      
299 yycrank+0,      0,              yyvstop+41,
300 yycrank+4,      0,              0,      
301 yycrank+0,      0,              yyvstop+43,
302 yycrank+12,     0,              0,      
303 yycrank+3,      yysvec+15,      0,      
304 yycrank+82,     yysvec+30,      0,      
305 yycrank+17,     0,              0,      
306 yycrank+13,     0,              0,      
307 yycrank+17,     0,              0,      
308 yycrank+14,     0,              0,      
309 yycrank+23,     0,              0,      
310 yycrank+19,     0,              0,      
311 yycrank+18,     0,              0,      
312 yycrank+25,     0,              0,      
313 yycrank+30,     0,              0,      
314 yycrank+19,     0,              0,      
315 yycrank+23,     0,              0,      
316 yycrank+31,     0,              0,      
317 yycrank+25,     0,              0,      
318 yycrank+25,     0,              0,      
319 yycrank+30,     0,              0,      
320 yycrank+28,     0,              0,      
321 yycrank+22,     0,              0,      
322 yycrank+31,     0,              0,      
323 yycrank+39,     0,              0,      
324 yycrank+44,     0,              0,      
325 yycrank+25,     0,              0,      
326 yycrank+42,     0,              0,      
327 yycrank+0,      0,              yyvstop+45,
328 yycrank+27,     0,              0,      
329 yycrank+0,      0,              yyvstop+47,
330 0,      0,      0};
331 struct yywork *yytop = yycrank+152;
332 struct yysvf *yybgin = yysvec+1;
333 char yymatch[] = {
334 00  ,01  ,01  ,01  ,01  ,01  ,01  ,01  ,
335 01  ,01  ,01  ,01  ,01  ,01  ,01  ,01  ,
336 01  ,01  ,01  ,01  ,01  ,01  ,01  ,01  ,
337 01  ,01  ,01  ,01  ,01  ,01  ,01  ,01  ,
338 01  ,01  ,01  ,01  ,01  ,01  ,01  ,01  ,
339 01  ,01  ,01  ,01  ,01  ,01  ,01  ,01  ,
340 '0' ,'0' ,'0' ,'0' ,'0' ,'0' ,'0' ,'0' ,
341 '0' ,'0' ,01  ,01  ,01  ,01  ,01  ,01  ,
342 01  ,01  ,01  ,01  ,01  ,01  ,01  ,01  ,
343 01  ,01  ,01  ,01  ,01  ,01  ,01  ,01  ,
344 01  ,01  ,01  ,01  ,01  ,01  ,01  ,01  ,
345 01  ,01  ,01  ,01  ,01  ,01  ,01  ,01  ,
346 01  ,01  ,01  ,01  ,01  ,01  ,01  ,01  ,
347 01  ,01  ,01  ,01  ,01  ,01  ,01  ,01  ,
348 01  ,01  ,01  ,01  ,01  ,01  ,01  ,01  ,
349 01  ,01  ,01  ,01  ,01  ,01  ,01  ,01  ,
350 0};
351 char yyextra[] = {
352 0,0,0,0,0,0,0,0,
353 0,0,0,0,0,0,0,0,
354 0,0,0,0,0,0,0,0,
355 0};
356 #ifndef lint
357 static  char ncform_sccsid[] = "@(#)ncform 1.6 88/02/08 SMI"; /* from S5R2 1.2 */
358 #endif
359
360 int yylineno =1;
361 # define YYU(x) x
362 # define NLSTATE yyprevious=YYNEWLINE
363 char yytext[YYLMAX];
364 struct yysvf *yylstate [YYLMAX], **yylsp, **yyolsp;
365 char yysbuf[YYLMAX];
366 char *yysptr = yysbuf;
367 int *yyfnd;
368 extern struct yysvf *yyestate;
369 int yyprevious = YYNEWLINE;
370 yylook(){
371         register struct yysvf *yystate, **lsp;
372         register struct yywork *yyt;
373         struct yysvf *yyz;
374         int yych, yyfirst;
375         struct yywork *yyr;
376 # ifdef LEXDEBUG
377         int debug;
378 # endif
379         char *yylastch;
380         /* start off machines */
381 # ifdef LEXDEBUG
382         debug = 0;
383 # endif
384         yyfirst=1;
385         if (!yymorfg)
386                 yylastch = yytext;
387         else {
388                 yymorfg=0;
389                 yylastch = yytext+yyleng;
390                 }
391         for(;;){
392                 lsp = yylstate;
393                 yyestate = yystate = yybgin;
394                 if (yyprevious==YYNEWLINE) yystate++;
395                 for (;;){
396 # ifdef LEXDEBUG
397                         if(debug)fprintf(yyout,"state %d\n",yystate-yysvec-1);
398 # endif
399                         yyt = yystate->yystoff;
400                         if(yyt == yycrank && !yyfirst){  /* may not be any transitions */
401                                 yyz = yystate->yyother;
402                                 if(yyz == 0)break;
403                                 if(yyz->yystoff == yycrank)break;
404                                 }
405                         *yylastch++ = yych = input();
406                         yyfirst=0;
407                 tryagain:
408 # ifdef LEXDEBUG
409                         if(debug){
410                                 fprintf(yyout,"char ");
411                                 allprint(yych);
412                                 putchar('\n');
413                                 }
414 # endif
415                         yyr = yyt;
416                         if ( (int)yyt > (int)yycrank){
417                                 yyt = yyr + yych;
418                                 if (yyt <= yytop && yyt->verify+yysvec == yystate){
419                                         if(yyt->advance+yysvec == YYLERR)       /* error transitions */
420                                                 {unput(*--yylastch);break;}
421                                         *lsp++ = yystate = yyt->advance+yysvec;
422                                         goto contin;
423                                         }
424                                 }
425 # ifdef YYOPTIM
426                         else if((int)yyt < (int)yycrank) {              /* r < yycrank */
427                                 yyt = yyr = yycrank+(yycrank-yyt);
428 # ifdef LEXDEBUG
429                                 if(debug)fprintf(yyout,"compressed state\n");
430 # endif
431                                 yyt = yyt + yych;
432                                 if(yyt <= yytop && yyt->verify+yysvec == yystate){
433                                         if(yyt->advance+yysvec == YYLERR)       /* error transitions */
434                                                 {unput(*--yylastch);break;}
435                                         *lsp++ = yystate = yyt->advance+yysvec;
436                                         goto contin;
437                                         }
438                                 yyt = yyr + YYU(yymatch[yych]);
439 # ifdef LEXDEBUG
440                                 if(debug){
441                                         fprintf(yyout,"try fall back character ");
442                                         allprint(YYU(yymatch[yych]));
443                                         putchar('\n');
444                                         }
445 # endif
446                                 if(yyt <= yytop && yyt->verify+yysvec == yystate){
447                                         if(yyt->advance+yysvec == YYLERR)       /* error transition */
448                                                 {unput(*--yylastch);break;}
449                                         *lsp++ = yystate = yyt->advance+yysvec;
450                                         goto contin;
451                                         }
452                                 }
453                         if ((yystate = yystate->yyother) && (yyt= yystate->yystoff) != yycrank){
454 # ifdef LEXDEBUG
455                                 if(debug)fprintf(yyout,"fall back to state %d\n",yystate-yysvec-1);
456 # endif
457                                 goto tryagain;
458                                 }
459 # endif
460                         else
461                                 {unput(*--yylastch);break;}
462                 contin:
463 # ifdef LEXDEBUG
464                         if(debug){
465                                 fprintf(yyout,"state %d char ",yystate-yysvec-1);
466                                 allprint(yych);
467                                 putchar('\n');
468                                 }
469 # endif
470                         ;
471                         }
472 # ifdef LEXDEBUG
473                 if(debug){
474                         fprintf(yyout,"stopped at %d with ",*(lsp-1)-yysvec-1);
475                         allprint(yych);
476                         putchar('\n');
477                         }
478 # endif
479                 while (lsp-- > yylstate){
480                         *yylastch-- = 0;
481                         if (*lsp != 0 && (yyfnd= (*lsp)->yystops) && *yyfnd > 0){
482                                 yyolsp = lsp;
483                                 if(yyextra[*yyfnd]){            /* must backup */
484                                         while(yyback((*lsp)->yystops,-*yyfnd) != 1 && lsp > yylstate){
485                                                 lsp--;
486                                                 unput(*yylastch--);
487                                                 }
488                                         }
489                                 yyprevious = YYU(*yylastch);
490                                 yylsp = lsp;
491                                 yyleng = yylastch-yytext+1;
492                                 yytext[yyleng] = 0;
493 # ifdef LEXDEBUG
494                                 if(debug){
495                                         fprintf(yyout,"\nmatch ");
496                                         sprint(yytext);
497                                         fprintf(yyout," action %d\n",*yyfnd);
498                                         }
499 # endif
500                                 return(*yyfnd++);
501                                 }
502                         unput(*yylastch);
503                         }
504                 if (yytext[0] == 0  /* && feof(yyin) */)
505                         {
506                         yysptr=yysbuf;
507                         return(0);
508                         }
509                 yyprevious = yytext[0] = input();
510                 if (yyprevious>0)
511                         output(yyprevious);
512                 yylastch=yytext;
513 # ifdef LEXDEBUG
514                 if(debug)putchar('\n');
515 # endif
516                 }
517         }
518 yyback(p, m)
519         int *p;
520 {
521 if (p==0) return(0);
522 while (*p)
523         {
524         if (*p++ == m)
525                 return(1);
526         }
527 return(0);
528 }
529         /* the following are only used in the lex library */
530 yyinput(){
531         return(input());
532         }
533 yyoutput(c)
534   int c; {
535         output(c);
536         }
537 yyunput(c)
538    int c; {
539         unput(c);
540         }