#include #define yputc(a) putc(a, yyout) #include "table.h" int oldpt = -1, nbpts = -1; int curptr = 0, p, full = 0; void putptr(void); %% "\n" { int i; int z = 0; nbpts = atoi(yytext + 7); fprintf(stderr, "nbpts = %i\n", nbpts); fwrite(&nbpts, 2, 1, yyout); for (i = 0; i < nbpts; i++) { fwrite(&z, 2, 1, yyout); } curptr = 1; p = ftell(yyout); fseek(yyout, 2, SEEK_SET); fwrite(&p, 2, 1, yyout); fseek(yyout, p, SEEK_SET); } "\n" { int d = atoi(yytext + 3); if (d != (oldpt + 1)) { fprintf(stderr, "Pointeur incorrect ligne %i: %i\n", yylineno, d); } oldpt = d; yputc(0xfe); yputc(d); } "" { int d = strtoul(yytext + 5, NULL, 16); yputc(d); } "" { int d = atoi(yytext + 4); yputc(0xfb); yputc(d); } "\n" { int d = atoi(yytext + 9); yputc(0xfb); yputc(9); yputc(d); } "" { int d = atoi(yytext + 7); yputc(0xfb); yputc(7); yputc(d); } "" { int d = atoi(yytext + 8); yputc(0xfb); yputc(d); } "\n" { yputc(0xff); putptr(); } "\n\n" { yputc(0xff); putptr(); } "" yputc(0xfa); "\n\n" { yputc(0xf9); putptr(); } "\n" { putptr(); } "\n" yputc(0xf8); "\n" yputc(0xf7); "" yputc(0x5c); "" 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); break; } } if (!trouve) { fprintf(stderr, "Caractère inconnu ligne %i: %s\n", yylineno, yytext); } } %% int yywrap(void) { if ((nbpts != -1) && (!full)) { fprintf(stderr, "Pas assez de pointeurs\n"); } exit(0); } void putptr(void) { if (nbpts == -1) return; if (curptr == nbpts) { full = 1; curptr++; return; } if (curptr > nbpts) { fprintf(stderr, "Trop de pointeurs ligne %i\n", yylineno); return; } p = ftell(yyout); fseek(yyout, 2 * curptr + 2, SEEK_SET); fwrite(&p, 2, 1, yyout); fseek(yyout, 0, SEEK_END); curptr++; } int main(int argc, char ** argv) { if ((argc < 2) || (argc > 3)) { fprintf(stderr, "Usage: %s [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; }