X-Git-Url: https://git.xonotic.org/?p=xonotic%2Fgmqcc.git;a=blobdiff_plain;f=ftepp.c;h=d68eed45285baa72e2fed256faa9314596a0311a;hp=595b520fec5439f34a1614f737f9f83f7ef3c150;hb=0e392f91d288017fef146f020d1166a501f5bcdf;hpb=9fee84f250dcad087d117be541588a2c122137b4 diff --git a/ftepp.c b/ftepp.c index 595b520..d68eed4 100644 --- a/ftepp.c +++ b/ftepp.c @@ -22,7 +22,10 @@ * SOFTWARE. */ #include +#include +#include #include + #include "gmqcc.h" #include "lexer.h" @@ -81,7 +84,7 @@ static uint32_t ftepp_predef_countval = 0; static uint32_t ftepp_predef_randval = 0; /* __DATE__ */ -char *ftepp_predef_date(lex_file *context) { +static char *ftepp_predef_date(lex_file *context) { struct tm *itime = NULL; time_t rtime; char *value = (char*)mem_a(82); @@ -104,7 +107,7 @@ char *ftepp_predef_date(lex_file *context) { } /* __TIME__ */ -char *ftepp_predef_time(lex_file *context) { +static char *ftepp_predef_time(lex_file *context) { struct tm *itime = NULL; time_t rtime; char *value = (char*)mem_a(82); @@ -127,13 +130,13 @@ char *ftepp_predef_time(lex_file *context) { } /* __LINE__ */ -char *ftepp_predef_line(lex_file *context) { +static char *ftepp_predef_line(lex_file *context) { char *value; util_asprintf(&value, "%d", (int)context->line); return value; } /* __FILE__ */ -char *ftepp_predef_file(lex_file *context) { +static char *ftepp_predef_file(lex_file *context) { size_t length = strlen(context->name) + 3; /* two quotes and a terminator */ char *value = (char*)mem_a(length); util_snprintf(value, length, "\"%s\"", context->name); @@ -141,7 +144,7 @@ char *ftepp_predef_file(lex_file *context) { return value; } /* __COUNTER_LAST__ */ -char *ftepp_predef_counterlast(lex_file *context) { +static char *ftepp_predef_counterlast(lex_file *context) { char *value; util_asprintf(&value, "%u", ftepp_predef_countval); @@ -149,7 +152,7 @@ char *ftepp_predef_counterlast(lex_file *context) { return value; } /* __COUNTER__ */ -char *ftepp_predef_counter(lex_file *context) { +static char *ftepp_predef_counter(lex_file *context) { char *value; ftepp_predef_countval ++; util_asprintf(&value, "%u", ftepp_predef_countval); @@ -158,7 +161,7 @@ char *ftepp_predef_counter(lex_file *context) { return value; } /* __RANDOM__ */ -char *ftepp_predef_random(lex_file *context) { +static char *ftepp_predef_random(lex_file *context) { char *value; ftepp_predef_randval = (util_rand() % 0xFF) + 1; util_asprintf(&value, "%u", ftepp_predef_randval); @@ -167,7 +170,7 @@ char *ftepp_predef_random(lex_file *context) { return value; } /* __RANDOM_LAST__ */ -char *ftepp_predef_randomlast(lex_file *context) { +static char *ftepp_predef_randomlast(lex_file *context) { char *value; util_asprintf(&value, "%u", ftepp_predef_randval); @@ -175,7 +178,7 @@ char *ftepp_predef_randomlast(lex_file *context) { return value; } /* __TIMESTAMP__ */ -char *ftepp_predef_timestamp(lex_file *context) { +static char *ftepp_predef_timestamp(lex_file *context) { struct stat finfo; char *find; char *value; @@ -186,7 +189,7 @@ char *ftepp_predef_timestamp(lex_file *context) { /* * ctime and its fucking annoying newline char, no worries, we're * professionals here. - */ + */ find = ctime(&finfo.st_mtime); value = (char*)mem_a(strlen(find) + 1); memcpy(&value[1], find, (size = strlen(find)) - 1); @@ -313,7 +316,7 @@ static void ppmacro_delete(ppmacro *self) mem_d(self); } -static ftepp_t* ftepp_new() +static ftepp_t* ftepp_new(void) { ftepp_t *ftepp; @@ -374,7 +377,7 @@ static GMQCC_INLINE ppmacro* ftepp_macro_find(ftepp_t *ftepp, const char *name) static GMQCC_INLINE void ftepp_macro_delete(ftepp_t *ftepp, const char *name) { - util_htrm(ftepp->macros, name, NULL); + util_htrm(ftepp->macros, name, (void (*)(void*))&ppmacro_delete); } static GMQCC_INLINE int ftepp_next(ftepp_t *ftepp) @@ -564,10 +567,6 @@ static bool ftepp_define(ftepp_t *ftepp) return false; } -#if 0 - if (ftepp->output_on) - vec_push(ftepp->macros, macro); -#endif if (ftepp->output_on) util_htset(ftepp->macros, macro->name, (void*)macro); else { @@ -625,7 +624,7 @@ static bool ftepp_macro_call_params(ftepp_t *ftepp, macroparam **out_params) ptok = pptoken_make(ftepp); vec_push(mp.tokens, ptok); if (ftepp_next(ftepp) >= TOKEN_EOF) { - ftepp_error(ftepp, "unexpected EOF in macro call"); + ftepp_error(ftepp, "unexpected end of file in macro call"); goto on_error; } } @@ -638,16 +637,10 @@ static bool ftepp_macro_call_params(ftepp_t *ftepp, macroparam **out_params) goto on_error; } if (ftepp_next(ftepp) >= TOKEN_EOF) { - ftepp_error(ftepp, "unexpected EOF in macro call"); + ftepp_error(ftepp, "unexpected end of file in macro call"); goto on_error; } } - /* need to leave that up - if (ftepp_next(ftepp) >= TOKEN_EOF) { - ftepp_error(ftepp, "unexpected EOF in macro call"); - goto on_error; - } - */ *out_params = params; return true; @@ -1885,7 +1878,7 @@ ftepp_t *ftepp_create() void ftepp_add_define(ftepp_t *ftepp, const char *source, const char *name) { ppmacro *macro; - lex_ctx ctx = { "__builtin__", 0 }; + lex_ctx ctx = { "__builtin__", 0, 0 }; ctx.file = source; macro = ppmacro_new(ctx, name); /*vec_push(ftepp->macros, macro);*/