summaryrefslogtreecommitdiff
path: root/compil.lex
diff options
context:
space:
mode:
Diffstat (limited to 'compil.lex')
-rw-r--r--compil.lex308
1 files changed, 211 insertions, 97 deletions
diff --git a/compil.lex b/compil.lex
index ad24a2c..36db5c5 100644
--- a/compil.lex
+++ b/compil.lex
@@ -1,8 +1,18 @@
#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 */
%s P
+ /* In delay block */
+%s D
/* In unknown 1 block */
%s U1
/* In unknown 2 block, arg1 */
@@ -19,185 +29,289 @@
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];
%%
<INITIAL>"<roomscripts>" {
- fprintf(yyout, "rooms_txts = {\n");
- BEGIN(I);
+ fprintf(yyout, "rooms_txts = {\n");
+ BEGIN(I);
}
-<INITIAL>.* {
- fprintf(stderr, "Invalid file, must begin with <roomscripts>\n");
- errstate = 1;
+<INITIAL>.* {
+ fprintf(stderr, "Invalid file, must begin with <roomscripts>\n");
+ errstate = 1;
}
-<I>"\n\n<ptr n=\""[[:digit:]]+"\" room=\""[^\"]*"\"/>\n" {
- int d = atoi(yytext + 10);
- if (got_ptr) {
- fprintf(yyout, "\x5d\x5d },\n");
- }
- fprintf(yyout, " [%i] = { \x5b\x5b", d);
- got_ptr = 1;
+<I>"\n\n<ptr n=\""[[:digit:]]+"\" room=\""[^\"]*"\"/>\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);
}
-<I>"\n<new/>\n" {
- putcode(1);
+<WW>"<nowindowdetected/>\n" {
+ BEGIN(I);
}
-<I>"<rspd/>" {
- putcode1(3, 255);
+<WW>"<window type=\"fixed\"/>\n" {
+ windows[current_ptr].t = 3;
+ BEGIN(I);
}
-<I>"<st spd=\""[[:digit:]]+"\"/>" {
- int d = atoi(yytext + 9);
- putcode1(3, d);
+<WW>"<window x=\""[[:digit:]]+"\" " {
+ int d = atoi(yytext + 11);
+ windows[current_ptr].t = 1;
+ windows[current_ptr].x = d;
+ BEGIN(WWY);
}
-<I>"<st clr=\""[[:digit:]]+"\"/>" {
- int d = atoi(yytext + 9);
- putcode1(4, d);
+<WW>"<window x=\"var\" y=\""[[:digit:]]+"\" " {
+ int d = atoi(yytext + 19);
+ windows[current_ptr].t = 2;
+ windows[current_ptr].y = d;
+ BEGIN(WWW);
}
-<I>"<start/>" {
- putcode(5);
+<WWY>"y=\""[[:digit:]]+"\" " {
+ int d = atoi(yytext + 3);
+ windows[current_ptr].y = d;
+ BEGIN(WWW);
}
-<I>"<rrep/>" {
- putcode1(7, 1);
+<WWW>"width=\""[[:digit:]]+"\" " {
+ int d = atoi(yytext + 7);
+ windows[current_ptr].w = d;
+ BEGIN(WWH);
}
-<I>"<st rep=\""[[:digit:]]+"\"/>" {
- int d = atoi(yytext + 9);
- putcode1(7, d);
+<WWH>"height=\""[[:digit:]]+"\"/>" {
+ int d = atoi(yytext + 8);
+ windows[current_ptr].h = d;
+ BEGIN(I);
}
-<I>"<rsiz/>" {
- putcode1(8, 1);
+<I>"\n<new/>\n" {
+ putcode(1);
}
-<I>"<st siz=\""[[:digit:]]+"\"/>" {
- int d = atoi(yytext + 9);
- putcode1(8, d);
+<I>"<rspd/>" {
+ putcode1(3, 255);
}
-<I>"<dport/>" {
- putcode2(19, 255, 255);
+<I>"<st spd=\""[[:digit:]]+"\"/>" {
+ int d = atoi(yytext + 9);
+ putcode1(3, d);
}
-<I>"<port a1=\""[[:digit:]]+"\" " {
- arg1 = atoi(yytext + 10);
- BEGIN(P);
+<I>"<st clr=\""[[:digit:]]+"\"/>" {
+ int d = atoi(yytext + 9);
+ putcode1(4, d);
}
-<P>"a2=\""[[:digit:]]+"\"/>" {
- int d = atoi(yytext + 4);
- putcode2(19, arg1, d);
- BEGIN(I);
+<I>"<start/>" {
+ putcode(5);
}
-<I>"<var n=\""[[:digit:]]+"\"/>" {
- int d = atoi(yytext + 8);
- putcode1(14, d);
+<I>"<rrep/>" {
+ putcode1(7, 1);
}
-<I>"<uk c=\""[[:digit:]]+"\"/>" {
- int d = atoi(yytext + 7);
- putcode(d);
+<I>"<st rep=\""[[:digit:]]+"\"/>" {
+ int d = atoi(yytext + 9);
+ putcode1(7, d);
}
-<I>"<u1 c=\""[[:digit:]]+"\" " {
- cmd = atoi(yytext + 7);
- BEGIN(U1);
-}
+<I>"<rsiz/>" {
+ putcode1(8, 1);
+ }
+
+<I>"<st siz=\""[[:digit:]]+"\"/>" {
+ int d = atoi(yytext + 9);
+ putcode1(8, d);
+ }
+
+<I>"<dport/>" {
+ putcode2(19, 255, 255);
+ }
+
+<I>"<port a1=\""[[:digit:]]+"\" " {
+ arg1 = atoi(yytext + 10);
+ BEGIN(P);
+ }
+
+<I>"<ssync/>" {
+ putcode(18);
+ }
+
+<I>"<delay t=\""[[:digit:]]+"\" " {
+ arg1 = atoi(yytext + 10);
+ BEGIN(D);
+ }
+
+<D>"u=\""[[:digit:]]+"\"/>" {
+ int d = atoi(yytext + 3);
+ putcode2(17, d, arg1);
+ BEGIN(I);
+ }
+
+<I>"<delay0 t=\""[[:digit:]]+"\"/>" {
+ int t = atoi(yytext + 11);
+ putcode2(17, t, 0);
+ }
+
+<I>"<delay1 t=\""[[:digit:]]+"\"/>" {
+ int t = atoi(yytext + 11);
+ putcode2(17, t, 1);
+ }
+
+<P>"a2=\""[[:digit:]]+"\"/>" {
+ int d = atoi(yytext + 4);
+ putcode2(19, arg1, d);
+ BEGIN(I);
+ }
+
+<I>"<var n=\""[[:digit:]]+"\"/>" {
+ int d = atoi(yytext + 8);
+ putcode1(14, d);
+ }
+
+<I>"<uk c=\""[[:digit:]]+"\"/>" {
+ int d = atoi(yytext + 7);
+ putcode(d);
+ }
-<U1>"a1=\""[[:digit:]]+"\"/>" {
- int d = atoi(yytext + 4);
- putcode1(cmd, d);
- BEGIN(I);
+<I>"<u1 c=\""[[:digit:]]+"\" " {
+ cmd = atoi(yytext + 7);
+ BEGIN(U1);
}
-<I>"<u2 c=\""[[:digit:]]+"\" " {
- cmd = atoi(yytext + 7);
- BEGIN(U21);
+<U1>"a1=\""[[:digit:]]+"\"/>" {
+ int d = atoi(yytext + 4);
+ putcode1(cmd, d);
+ BEGIN(I);
}
-<U21>"a1=\""[[:digit:]]+"\" " {
- arg1 = atoi(yytext + 4);
- BEGIN(U22);
+<I>"<u2 c=\""[[:digit:]]+"\" " {
+ cmd = atoi(yytext + 7);
+ BEGIN(U21);
}
-<U22>"a2=\""[[:digit:]]+"\"/>" {
- int d = atoi(yytext + 4);
- putcode2(cmd, arg1, d);
- BEGIN(I);
+<U21>"a1=\""[[:digit:]]+"\" " {
+ arg1 = atoi(yytext + 4);
+ BEGIN(U22);
}
-<I>"\n" {
- putcode(0);
- }
+<U22>"a2=\""[[:digit:]]+"\"/>" {
+ int d = atoi(yytext + 4);
+ putcode2(cmd, arg1, d);
+ BEGIN(I);
+}
-<I>"</roomscripts>\n" {
- fprintf(yyout, "\x5d\x5d}\n}\n");
- BEGIN(E);
+<I>"\n" {
+ putcode(0);
}
-<I>"abcdef<"[^\>\n]*"/>" {
- yytext[strlen(yytext) - 2] = 0;
- fprintf(stderr, "Error: Invalid command: '%s'\n", yytext + 1);
- errstate = 1;
+<I>"</roomscripts>\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);
}
-<I>. {
- fputc(*yytext, yyout);
+<I>. {
+ 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...\n");
+. {
+ fprintf(stderr, "Hu uh, something's wrong... unexpected %s\n", yytext);
}
%%
-int yywrap(void) {
+int yywrap(void) {
exit(errstate ? -1 : 0);
}
-int main(int argc, char ** argv) {
+int main(int argc, char ** argv) {
if ((argc < 2) || (argc > 3)) {
- fprintf(stderr, "Usage: %s <output> [input]\n", argv[0]);
- exit(-1);
+ 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);
+ 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);
- }
+ 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) {
+void unputs(char * s) {
int l = strlen(s), i;
-
+
for (i = l - 1; i >= 0; i--) {
- unput(s[i]);
+ unput(s[i]);
}
}
-void putcode(int code) {
+void putcode(int code) {
fprintf(yyout, "\x5d\x5d, { %i }, \x5b\x5b", code);
}
-void putcode1(int code, int arg) {
+void putcode1(int code, int arg) {
fprintf(yyout, "\x5d\x5d, { %i, %i }, \x5b\x5b", code, arg);
}
-void putcode2(int code, int arg1, int arg2) {
+void putcode2(int code, int arg1, int arg2) {
fprintf(yyout, "\x5d\x5d, { %i, %i, %i }, \x5b\x5b", code, arg1, arg2);
}