Added tool that reads entity definitons into a file

This commit is contained in:
Walter Hennecke 2012-11-29 10:17:28 +01:00
parent 75ec1fce7b
commit e97c97d5d3
2 changed files with 78 additions and 0 deletions

View File

@ -0,0 +1,17 @@
Entity Definitions Parser
Required tools:
* flex
Building
flex quake.l
gcc lex.yy.c -o entityDefParser -lfl
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();
}