#include /* Waiting for Window */ %s WW /* Waiting for Window Y */ %s WWY /* Waiting for Window W */ %s WWW /* Waiting for Window H */ %s WWH /* In text block */ %s I /* In port block */ %s P /* In delay block */ %s D /* In unknown 1 block */ %s U1 /* In unknown 2 block, arg1 */ %s U21 /* In unknown 2 block, arg2 */ %s U22 /* Script ended */ %s E void putcode(int); void putcode1(int, int); void putcode2(int, int, int); int cmd = 0; int arg1 = 0; int errstate = 0; int got_ptr = 0; int current_ptr = 0; const int max_tagsize = 64; char unknown_tag[65]; char * unknown_tag_ptr = unknown_tag; int in_unknown_tag = 0; struct window { int t, x, y, w, h; }; struct window windows[8192]; %% "" { fprintf(yyout, "rooms_txts = {\n"); BEGIN(I); } .* { fprintf(stderr, "Invalid file, must begin with \n"); errstate = 1; } "\n\n\n" { current_ptr = atoi(yytext + 10); if (got_ptr) { fprintf(yyout, "\x5d\x5d },\n"); } fprintf(yyout, " [%i] = { \x5b\x5b", current_ptr); got_ptr = 1; BEGIN(WW); } "\n" { BEGIN(I); } "\n" { windows[current_ptr].t = 3; BEGIN(I); } """y=\""[[:digit:]]+"\" " { int d = atoi(yytext + 3); windows[current_ptr].y = d; BEGIN(WWW); } "width=\""[[:digit:]]+"\" " { int d = atoi(yytext + 7); windows[current_ptr].w = d; BEGIN(WWH); } "height=\""[[:digit:]]+"\"/>\n" { int d = atoi(yytext + 8); windows[current_ptr].h = d; BEGIN(I); } "\n\n" { putcode(1); } "" { putcode1(3, 255); } "" { int d = atoi(yytext + 9); putcode1(3, d); } "" { int d = atoi(yytext + 9); putcode1(4, d); } "" { putcode(5); } "" { putcode1(7, 1); } "" { int d = atoi(yytext + 9); putcode1(7, d); } "" { putcode1(8, 1); } "" { int d = atoi(yytext + 9); putcode1(8, d); } "" { putcode2(19, 255, 255); } """ { putcode(18); } ""u=\""[[:digit:]]+"\"/>" { int d = atoi(yytext + 3); putcode2(17, d, arg1); BEGIN(I); } "" { int t = atoi(yytext + 11); putcode2(17, t, 0); } "" { int t = atoi(yytext + 11); putcode2(17, t, 1); }

"a2=\""[[:digit:]]+"\"/>" { int d = atoi(yytext + 4); putcode2(19, arg1, d); BEGIN(I); } "" { int d = atoi(yytext + 8); putcode1(14, d); } "" { int d = atoi(yytext + 7); putcode(d); } ""a1=\""[[:digit:]]+"\"/>" { int d = atoi(yytext + 4); putcode1(cmd, d); BEGIN(I); } ""a1=\""[[:digit:]]+"\" " { arg1 = atoi(yytext + 4); BEGIN(U22); } "a2=\""[[:digit:]]+"\"/>" { int d = atoi(yytext + 4); putcode2(cmd, arg1, d); BEGIN(I); } "\n" { putcode(0); } "\n" { int i; fprintf(yyout, "\x5d\x5d}\n}\n\nwindows_data = {\n"); for (i = 0; i < 8192; i++) { switch (windows[i].t) { case 1: fprintf(yyout, " [%i] = { x = \"%i\", y = \"%i\", width = \"%i\", height = \"%i\" },\n", i, windows[i].x, windows[i].y, windows[i].w, windows[i].h); break; case 2: fprintf(yyout, " [%i] = { x = \"var\", y = \"%i\", width = \"%i\", height = \"%i\" },\n", i, windows[i].y, windows[i].w, windows[i].h); break; case 3: fprintf(yyout, " [%i] = { wtype = \"fixed\" },\n", i); break; } } fprintf(yyout, "}\n"); BEGIN(E); } . { if (*yytext == '<') { in_unknown_tag = 1; unknown_tag_ptr = unknown_tag; } else if ((*yytext == '>') && in_unknown_tag) { *unknown_tag_ptr = 0; fprintf(stderr, "Got an unknown tag: %s\n", unknown_tag); in_unknown_tag = 0; } else if (in_unknown_tag) { *unknown_tag_ptr++ = *yytext; if ((unknown_tag_ptr - unknown_tag) == max_tagsize) { in_unknown_tag = 0; } } fputc(*yytext, yyout); } . { fprintf(stderr, "Hu uh, something's wrong... unexpected %s\n", yytext); } %% int yywrap(void) { exit(errstate ? -1 : 0); } 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); } } memset(windows, 0, sizeof(windows)); fprintf(stderr, "Creating file %s\n", argv[1]); yylex(); exit(errstate ? -1 : 0); } void unputs(char * s) { int l = strlen(s), i; for (i = l - 1; i >= 0; i--) { unput(s[i]); } } void putcode(int code) { fprintf(yyout, "\x5d\x5d, { %i }, \x5b\x5b", code); } void putcode1(int code, int arg) { fprintf(yyout, "\x5d\x5d, { %i, %i }, \x5b\x5b", code, arg); } void putcode2(int code, int arg1, int arg2) { fprintf(yyout, "\x5d\x5d, { %i, %i, %i }, \x5b\x5b", code, arg1, arg2); }