From 9eede342a1046ce8e26c87495737585d042add19 Mon Sep 17 00:00:00 2001 From: Pixel Date: Mon, 29 Oct 2012 00:55:15 -0700 Subject: First step in getting the windows re-inserted properly: parsing them and transforming them into Lua code. --- compil.lex | 85 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 79 insertions(+), 6 deletions(-) diff --git a/compil.lex b/compil.lex index 960cab9..d75f157 100644 --- a/compil.lex +++ b/compil.lex @@ -1,4 +1,12 @@ #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 */ @@ -21,14 +29,21 @@ 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; + char * unknown_tag_ptr = unknown_tag; int in_unknown_tag = 0; + struct window { + int t, x, y, w, h; + }; + + struct window windows[8192]; + %% "" { @@ -42,12 +57,54 @@ } "\n\n\n" { - int d = atoi(yytext + 10); + current_ptr = atoi(yytext + 10); if (got_ptr) { fprintf(yyout, "\x5d\x5d },\n"); } - fprintf(yyout, " [%i] = { \x5b\x5b", d); + 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:]]+"\"/>" { + int d = atoi(yytext + 8); + windows[current_ptr].h = d; + BEGIN(I); } "\n\n" { @@ -172,7 +229,22 @@ } "\n" { - fprintf(yyout, "\x5d\x5d}\n}\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", current_ptr); + break; + } + } + fprintf(yyout, "}\n"); BEGIN(E); } @@ -180,7 +252,7 @@ if (*yytext == '<') { in_unknown_tag = 1; unknown_tag_ptr = unknown_tag; - } else if (*yytext == '>') { + } else if ((*yytext == '>') && in_unknown_tag) { *unknown_tag_ptr = 0; fprintf(stderr, "Got an unknown tag: %s\n", unknown_tag); in_unknown_tag = 0; @@ -194,7 +266,7 @@ } . { - fprintf(stderr, "Hu uh, something's wrong...\n"); + fprintf(stderr, "Hu uh, something's wrong... unexpected %s\n", yytext); } %% @@ -218,6 +290,7 @@ int main(int argc, char ** argv) { exit(-1); } } + memset(windows, 0, sizeof(windows)); fprintf(stderr, "Creating file %s\n", argv[1]); yylex(); exit(errstate ? -1 : 0); -- cgit v1.2.3