Old mergeps.lex
1 %{
2 /*
3 * merge.l - Flex source
4 * Merges two PostScript files
5 *
6 */
7
8 #include <stdio.h>
9
10
11 #ifndef TRUE
12 #define TRUE (1)
13 #endif
14
15 #ifndef FALSE
16 #define FALSE (0)
17 #endif
18
19 YY_BUFFER_STATE file1, file2;
20
21 int second_is_open = 0;
22
23 FILE *fp1, *fp2;
24
25 %}
26
27 %option noyywrap
28
29 %x SECOND_FILE
30
31 %%
32
33 ^showsheet {
34 printf("%%%%SHOWSHEET IN FIRST FILE: Removed!\n");
35 BEGIN(SECOND_FILE);
36 if ( !second_is_open ){
37 second_is_open = 1;
38 file1 = YY_CURRENT_BUFFER;
39 yyin = fp2;
40 file2 = yy_create_buffer(yyin, YY_BUF_SIZE);
41 }
42 yy_switch_to_buffer(file2); }
43
44 <SECOND_FILE>^showpage {
45 printf("%%%%Next line renders the merged page.\nshowsheet\n");
46 BEGIN(INITIAL);
47 yy_switch_to_buffer(file1); }
48
49 %%
50
51 void yyerror(char *msg)
52 {
53 fprintf(stderr, "Error...\n");
54 exit(1);
55 }
56
57 main(int argc, char *argv[])
58 {
59
60 if ( (fp1 = fopen(argv[1], "r")) == NULL ){
61 fprintf(stderr, "%s: file not found!\n", argv[1]);
62 exit(1);
63 }
64
65 if ( (fp2 = fopen(argv[2], "r")) == NULL ){
66 fprintf(stderr, "%s: file not found!\n", argv[2]);
67 exit(1);
68 }
69
70 yyin = fp1;
71
72 yylex();
73
74 exit(0);
75 }
76
77
78
79
80