1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
#include <string.h>
#define yputc(a) putc(a, yyout)
#include "table.h"
%%
"<PT"[[:digit:]]+">\n" {
int d = atoi(yytext + 3);
yputc(0xfe);
yputc(d);
}
"<UNK "[[:xdigit:]]+">" {
int d = strtoul(yytext + 5, NULL, 16);
yputc(d);
}
"<TAG0>" {
yputc(0xfb);
yputc(0);
}
"<TAG1>" {
yputc(0xfb);
yputc(1);
}
"<CHOICES "[[:digit:]]+">\n" {
int d = atoi(yytext + 9);
yputc(0xfb);
yputc(9);
yputc(d);
}
"<TIMER "[[:digit:]]+">" {
int d = atoi(yytext + 7);
yputc(0xfb);
yputc(7);
yputc(d);
}
"<UNKCMD "[[:digit:]]+">" {
int d = atoi(yytext + 8);
yputc(0xfb);
yputc(d);
}
"\n<CLOSE>\n" yputc(0xff);
"<CLOSE>\n" { yputc(0xf7); yputc(0xff); }
"<AYA>" yputc(0xfa);
"\n<TCLOSE>\n" yputc(0xf9);
"<PAUSE>\n" yputc(0xf8);
"\n" yputc(0xf7);
"<ae>" yputc(0x5c);
"<oe>" yputc(0x5d);
"<"[^>]*">" {
fprintf(stderr, "Commande inconnue ligne %i: %s\n", yylineno, yytext);
}
. {
int i, trouve = 0;
for (i = 0; i <= MAXCHAR; i++) {
if (table[i] == *yytext) {
trouve = 1;
yputc(i);
}
}
if (!trouve) {
fprintf(stderr, "Caractère inconnu ligne %i: %s\n", yylineno, yytext);
}
}
%%
int yywrap(void) {
exit(0);
}
int main(int argc, char ** argv) {
if ((argc < 2) || (argc > 3)) {
fprintf(stderr, "Usage: %s <output> [input]\n", argv[0]);
exit(-1);
}
if (!(yyout = fopen(argv[1], "wb"))) {
fprintf(stderr, "Error: can't open file %s\n", argv[1]);
exit(-1);
}
if (argc == 3) {
if (!(yyin = fopen(argv[2], "rb"))) {
fprintf(stderr, "Error: can't open file %s\n", argv[2]);
exit(-1);
}
}
fprintf(stderr, "Creating file %s\n", argv[1]);
yylex();
return 0;
}
|