X-Git-Url: https://git.xonotic.org/?a=blobdiff_plain;f=ftepp.c;h=68491ed6dd2af72e1c8e69035b6e48bce5384a35;hb=0367a6175d1cf265bec9cdc4a8a8d80f81a7e2ef;hp=ce5dd8ac2e0044f1388c815e797478334bac97f7;hpb=e12d492d6737380da4a1949cb04951b062d75201;p=xonotic%2Fgmqcc.git diff --git a/ftepp.c b/ftepp.c index ce5dd8a..68491ed 100644 --- a/ftepp.c +++ b/ftepp.c @@ -82,7 +82,7 @@ static uint32_t ftepp_predef_randval = 0; char *ftepp_predef_date(lex_file *context) { struct tm *itime; time_t rtime; - char *value = mem_a(82); + char *value = (char*)mem_a(82); /* 82 is enough for strftime but we also have " " in our string */ (void)context; @@ -100,7 +100,7 @@ char *ftepp_predef_date(lex_file *context) { char *ftepp_predef_time(lex_file *context) { struct tm *itime; time_t rtime; - char *value = mem_a(82); + char *value = (char*)mem_a(82); /* 82 is enough for strftime but we also have " " in our string */ (void)context; @@ -124,7 +124,6 @@ char *ftepp_predef_line(lex_file *context) { 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); - memset (value, 0, length); sprintf(value, "\"%s\"", context->name); return value; @@ -451,8 +450,12 @@ static bool ftepp_define_body(ftepp_t *ftepp, ppmacro *macro) ftepp->token = old; } } - else - { + else if (macro->variadic && !strcmp(ftepp_tokval(ftepp), "__VA_COUNT__")) { + ftepp->token = TOKEN_VA_COUNT; + ptok = pptoken_make(ftepp); + vec_push(macro->output, ptok); + ftepp_next(ftepp); + } else { ptok = pptoken_make(ftepp); vec_push(macro->output, ptok); ftepp_next(ftepp); @@ -681,6 +684,7 @@ static void ftepp_param_out(ftepp_t *ftepp, macroparam *param) static bool ftepp_preprocess(ftepp_t *ftepp); static bool ftepp_macro_expand(ftepp_t *ftepp, ppmacro *macro, macroparam *params, bool resetline) { + char *buffer = NULL; char *old_string = ftepp->output_string; char *inner_string; lex_file *old_lexer = ftepp->lex; @@ -736,6 +740,12 @@ static bool ftepp_macro_expand(ftepp_t *ftepp, ppmacro *macro, macroparam *param ftepp_param_out(ftepp, ¶ms[out->constval.i + vararg_start]); break; + case TOKEN_VA_COUNT: + util_asprintf(&buffer, "%d", varargs); + ftepp_out(ftepp, buffer, false); + mem_d(buffer); + break; + case TOKEN_IDENT: case TOKEN_TYPENAME: case TOKEN_KEYWORD: @@ -1250,9 +1260,9 @@ static char *ftepp_include_find_path(const char *file, const char *pathfile) memcpy(vec_add(filename, len+1), file, len); vec_last(filename) = 0; - fp = file_open(filename, "rb"); + fp = fs_file_open(filename, "rb"); if (fp) { - file_close(fp); + fs_file_close(fp); return filename; } vec_free(filename); @@ -1285,11 +1295,17 @@ static bool ftepp_directive_warning(ftepp_t *ftepp) { ftepp_next(ftepp); } vec_push(message, '\0'); - store = ftepp_warn(ftepp, WARN_CPP, message); + if (ftepp->output_on) + store = ftepp_warn(ftepp, WARN_CPP, message); + else + store = false; vec_free(message); return store; } + if (!ftepp->output_on) + return false; + unescape (ftepp_tokval(ftepp), ftepp_tokval(ftepp)); return ftepp_warn(ftepp, WARN_CPP, "#warning %s", ftepp_tokval(ftepp)); } @@ -1309,11 +1325,15 @@ static void ftepp_directive_error(ftepp_t *ftepp) { ftepp_next(ftepp); } vec_push(message, '\0'); - ftepp_error(ftepp, message); + if (ftepp->output_on) + ftepp_error(ftepp, message); vec_free(message); return; } + if (!ftepp->output_on) + return; + unescape (ftepp_tokval(ftepp), ftepp_tokval(ftepp)); ftepp_error(ftepp, "#error %s", ftepp_tokval(ftepp)); } @@ -1333,11 +1353,15 @@ static void ftepp_directive_message(ftepp_t *ftepp) { ftepp_next(ftepp); } vec_push(message, '\0'); - con_cprintmsg(&ftepp->lex->tok.ctx, LVL_MSG, "message", message); + if (ftepp->output_on) + con_cprintmsg(&ftepp->lex->tok.ctx, LVL_MSG, "message", message); vec_free(message); return; } + if (!ftepp->output_on) + return; + unescape (ftepp_tokval(ftepp), ftepp_tokval(ftepp)); con_cprintmsg(&ftepp->lex->tok.ctx, LVL_MSG, "message", ftepp_tokval(ftepp)); } @@ -1365,6 +1389,11 @@ static bool ftepp_include(ftepp_t *ftepp) return false; } + if (!ftepp->output_on) { + ftepp_next(ftepp); + return true; + } + ctx = ftepp_ctx(ftepp); unescape(ftepp_tokval(ftepp), ftepp_tokval(ftepp));