Merge branch 'master' of git@github.com:UberGames/rpgxEF.git

This commit is contained in:
Harry Young 2012-12-04 00:43:07 +01:00
commit 1953cfaa25
5 changed files with 220 additions and 0 deletions

View file

@ -0,0 +1,28 @@
Entity Definitions Parser
Required tools:
Linux:
* flex
Windows:
* mingw
Building:
Linux:
flex quake.l
gcc lex.yy.c -o entityDefParser -lfl
Mac:
flex quake.l
gcc lex.yy.c -o entityDefParser -lfl
Windows:
flex quake.l
gcc lex.yy.c -o entityDefParser /lib/libfl.a
Usage:
./entityDefParser <code file> <output file>
Example:
./entityDefParser game/g_mover.c hm_entities.def
./entityDefParser game/g_fx.c
Will produce a def file including all entity definitions from
g_mover.c and g_fx.c.

View file

@ -0,0 +1,61 @@
%{
#include <stdio.h>
FILE *in, *out;
#define YY_DECL int yylex()
%}
%x C_QUAKED
%%
"/*QUAKED" { BEGIN(C_QUAKED); fprintf(out, "/*QUAKED"); }
<C_QUAKED>"*/" { BEGIN(INITIAL); fprintf(out, "*/\n\n"); }
<C_QUAKED>"\t" { fprintf(out, "\t"); }
<C_QUAKED>"\n" { fprintf(out, "\n"); }
<C_QUAKED>. { fprintf(out, "%s", yytext); }
[\n] ;
. ;
%%
main(int argc, char *argv[]) {
char *buf;
long len;
if(argc < 2) {
printf("Usage: %s <cfiles> <output file>\n", argv[0]);
}
in = fopen(argv[1], "r");
if(!in) {
return;
}
out = fopen(argv[2], "r");
if(out) {
fseek(out, 0, SEEK_END);
len = ftell(out);
fseek(out, 0, SEEK_SET);
buf = (char *)malloc(len+1);
if(!buf) {
fclose(out);
return;
}
fgets(buf, len, out);
fclose(out);
}
out = fopen(argv[2], "a");
if(!out) {
return;
}
if(buf != NULL) {
fprintf(out, "%s", buf);
free(buf);
}
yyin = in;
yylex();
}

View file

@ -0,0 +1,24 @@
Lua Definitions Parser (WIP)
Required tools:
Linux:
* flex
Windows:
* mingw
Building:
Linux:
flex quake.l
gcc lex.yy.c -o luaDefParser -lfl
Mac:
flex quake.l
gcc lex.yy.c -o luaDefParser -lfl
Windows:
flex quake.l
gcc lex.yy.c -o luaDefParser /lib/libfl.a
Usage:
./luaDefParser <code file> <output file>
Example:
./luaDefParser game/lua_game.c module_game.lyx

View file

@ -0,0 +1,91 @@
%{
#include <stdio.h>
#include <string.h>
FILE* out;
int lastState = 0;
#define YY_DECL int yylex()
%}
%x C_COMMENT
%x C_FUNCTION
%x C_DESC
%x C_PARAM
%x C_STRING
%x C_MODULE
FUNCTEXT [a-zA-z0-9.(), \t]+
STRING [a-zA-z0-9.(), \t\n!?<>/\\\[\]\{\}]+
VAR [a-zA-Z0-9]+
%%
"/*" { BEGIN(C_COMMENT); puts("Found a comment"); }
<C_COMMENT>"*/" { BEGIN(INITIAL); puts("End of comment"); }
<C_COMMENT>[ \t\n*] ;
<C_COMMENT>"luamodule" { BEGIN(C_MODULE); puts("Found a luamodule"); }
<C_COMMENT>"\\function" { BEGIN(C_FUNCTION); puts("Found a \\function"); }
<C_COMMENT>"\\desc" { BEGIN(C_DESC); puts("Found a \\desc"); }
<C_COMMENT>"\\param" { BEGIN(C_PARAM); puts("Found a \\param"); }
<C_COMMENT>[ \t\n]* ;
<C_COMMENT>. ;
<C_MODULE>[ \t\n] ;
<C_MODULE>{VAR} { BEGIN(C_COMMENT); printf("module name: %s\n", yytext); }
<C_MODULE>. ;
<C_FUNCTION>";" { BEGIN(C_COMMENT); puts("End of function"); }
<C_FUNCTION>{FUNCTEXT} { printf("function text: %s\n", yytext); }
<C_FUNCTION>. ;
<C_DESC>";" { BEGIN(C_COMMENT); puts("End of desc"); }
<C_DESC>"\"" { BEGIN(C_STRING); lastState = C_DESC; puts("Found a String"); }
<C_DESC>[.\n]+ { printf("desc text: %s\n", yytext); }
<C_DESC>. ;
<C_PARAM>";" { BEGIN(C_COMMENT); puts("End of param"); }
<C_PARAM>"\"" { BEGIN(C_STRING); lastState = C_PARAM; puts("Found a string"); }
<C_PARAM>[ \t] ;
<C_PARAM>"float" { printf("foud type: %s\n", yytext); }
<C_PARAM>"vec" { printf("foud type: %s\n", yytext); }
<C_PARAM>"vector" { printf("foud type: %s\n", yytext); }
<C_PARAM>"ent" { printf("foud type: %s\n", yytext); }
<C_PARAM>"entity" { printf("foud type: %s\n", yytext); }
<C_PARAM>{VAR} { printf("foud name: %s\n", yytext); }
<C_PARAM>. ;
<C_STRING>"\"" { BEGIN(lastState); puts("End of String"); }
<C_STRING>{STRING} { printf("string text: %s\n", yytext); }
<C_STRING>. ;
"\n" ;
. ;
%%
main(int argc, char *argv[]) {
FILE *in;
if(argc < 3) {
printf("Usage: %s <input file> <output file>\n", argv[0]);
return;
}
in = fopen(argv[1], "r");
if(!in) {
printf("Could not open \'%s\'.\n", argv[1]);
return;
}
out = fopen(argv[2], "a");
if(!out) {
fclose(in);
printf("Could not open \'%s\'.\n", argv[2]);
return;
}
yyin = in;
yylex();
fclose(in);
fclose(out);
}

View file

@ -0,0 +1,16 @@
/* luamodule test */
int a;
/* test */
void test() {
}
/*
* \function test.func(float a, entity b);
* \param float a "this is a";
* \desc test 123;
* \desc "test
* test2";
*/