diff --git a/code/tools/entityDefParser/README b/code/tools/entityDefParser/README new file mode 100644 index 0000000..aff7e80 --- /dev/null +++ b/code/tools/entityDefParser/README @@ -0,0 +1,17 @@ +Entity Definitions Parser + +Required tools: +* flex + +Building +flex quake.l +gcc lex.yy.c -o entityDefParser -lfl + +Usage: +./entityDefParser + +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. diff --git a/code/tools/entityDefParser/quaked.l b/code/tools/entityDefParser/quaked.l new file mode 100644 index 0000000..7c46316 --- /dev/null +++ b/code/tools/entityDefParser/quaked.l @@ -0,0 +1,61 @@ +%{ +#include + +FILE *in, *out; + +#define YY_DECL int yylex() +%} + +%x C_QUAKED +%% +"/*QUAKED" { BEGIN(C_QUAKED); fprintf(out, "/*QUAKED"); } +"*/" { BEGIN(INITIAL); fprintf(out, "*/\n\n"); } +"\t" { fprintf(out, "\t"); } +"\n" { fprintf(out, "\n"); } +. { fprintf(out, "%s", yytext); } +[\n] ; +. ; +%% + +main(int argc, char *argv[]) { + char *buf; + long len; + + if(argc < 2) { + printf("Usage: %s \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(); +}