summaryrefslogtreecommitdiff
path: root/compil.lex
diff options
context:
space:
mode:
Diffstat (limited to 'compil.lex')
-rw-r--r--compil.lex85
1 files 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 <string.h>
+ /* 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];
+
%%
<INITIAL>"<roomscripts>" {
@@ -42,12 +57,54 @@
}
<I>"\n\n<ptr n=\""[[:digit:]]+"\" room=\""[^\"]*"\"/>\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);
+ }
+
+<WW>"<nowindowdetected/>\n" {
+ BEGIN(I);
+ }
+
+<WW>"<window type=\"fixed\"/>\n" {
+ windows[current_ptr].t = 3;
+ BEGIN(I);
+ }
+
+<WW>"<window x=\""[[:digit:]]+"\" " {
+ int d = atoi(yytext + 11);
+ windows[current_ptr].t = 1;
+ windows[current_ptr].x = d;
+ BEGIN(WWY);
+ }
+
+<WW>"<window x=\"var\" y=\""[[:digit:]]+"\" " {
+ int d = atoi(yytext + 19);
+ windows[current_ptr].t = 2;
+ windows[current_ptr].y = d;
+ BEGIN(WWW);
+ }
+
+<WWY>"y=\""[[:digit:]]+"\" " {
+ int d = atoi(yytext + 3);
+ windows[current_ptr].y = d;
+ BEGIN(WWW);
+ }
+
+<WWW>"width=\""[[:digit:]]+"\" " {
+ int d = atoi(yytext + 7);
+ windows[current_ptr].w = d;
+ BEGIN(WWH);
+ }
+
+<WWH>"height=\""[[:digit:]]+"\"/>" {
+ int d = atoi(yytext + 8);
+ windows[current_ptr].h = d;
+ BEGIN(I);
}
<I>"\n<new/>\n" {
@@ -172,7 +229,22 @@
}
<I>"</roomscripts>\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);