X-Git-Url: https://git.xonotic.org/?a=blobdiff_plain;f=ftepp.c;h=b07899a327e936ba45771ccb46c9f01b3940cc0b;hb=489ad486bcbb04da48715c4f59aa3da8dd5983a6;hp=320afc8182874580f98202f16d5aace610caf5b2;hpb=0b0b6423bae15eae22685f9efc41d6efe70e8ae4;p=xonotic%2Fgmqcc.git diff --git a/ftepp.c b/ftepp.c old mode 100644 new mode 100755 index 320afc8..b07899a --- a/ftepp.c +++ b/ftepp.c @@ -1,7 +1,7 @@ /* * Copyright (C) 2012, 2013 * Wolfgang Bumiller - * Dale Weiler + * Dale Weiler * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in @@ -76,13 +76,13 @@ typedef struct ftepp_s { /* * Implement the predef subsystem now. We can do this safely with the * help of lexer contexts. - */ + */ static uint32_t ftepp_predef_countval = 0; static uint32_t ftepp_predef_randval = 0; /* __DATE__ */ char *ftepp_predef_date(lex_file *context) { - struct tm *itime; + struct tm *itime = NULL; time_t rtime; char *value = (char*)mem_a(82); /* 82 is enough for strftime but we also have " " in our string */ @@ -91,7 +91,12 @@ char *ftepp_predef_date(lex_file *context) { /* get time */ time (&rtime); + +#ifdef _MSC_VER + localtime_s(itime, &rtime); +#else itime = localtime(&rtime); +#endif strftime(value, 82, "\"%b %d %Y\"", itime); @@ -100,7 +105,7 @@ char *ftepp_predef_date(lex_file *context) { /* __TIME__ */ char *ftepp_predef_time(lex_file *context) { - struct tm *itime; + struct tm *itime = NULL; time_t rtime; char *value = (char*)mem_a(82); /* 82 is enough for strftime but we also have " " in our string */ @@ -109,7 +114,12 @@ char *ftepp_predef_time(lex_file *context) { /* get time */ time (&rtime); + +#ifdef _MSC_VER + localtime_s(itime, &rtime); +#else itime = localtime(&rtime); +#endif strftime(value, 82, "\"%X\"", itime); @@ -126,7 +136,7 @@ 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); - snprintf(value, length, "\"%s\"", context->name); + util_snprintf(value, length, "\"%s\"", context->name); return value; } @@ -227,7 +237,7 @@ static pptoken *pptoken_make(ftepp_t *ftepp) return token; } -static void pptoken_delete(pptoken *self) +static GMQCC_INLINE void pptoken_delete(pptoken *self) { mem_d(self->value); mem_d(self); @@ -269,7 +279,7 @@ static ftepp_t* ftepp_new() return ftepp; } -static void ftepp_flush_do(ftepp_t *self) +static GMQCC_INLINE void ftepp_flush_do(ftepp_t *self) { vec_free(self->output_string); } @@ -282,13 +292,6 @@ static void ftepp_delete(ftepp_t *self) if (self->includename) vec_free(self->includename); - /* - for (i = 0; i < vec_size(self->macros); ++i) - ppmacro_delete(self->macros[i]); - - vec_free(self->macros); -*/ - util_htrem(self->macros, (void (*)(void*))&ppmacro_delete); vec_free(self->conditions); @@ -309,7 +312,7 @@ static void ftepp_out(ftepp_t *ftepp, const char *str, bool ignore_cond) } } -static void ftepp_update_output_condition(ftepp_t *ftepp) +static GMQCC_INLINE void ftepp_update_output_condition(ftepp_t *ftepp) { size_t i; ftepp->output_on = true; @@ -317,12 +320,12 @@ static void ftepp_update_output_condition(ftepp_t *ftepp) ftepp->output_on = ftepp->output_on && ftepp->conditions[i].on; } -static ppmacro* ftepp_macro_find(ftepp_t *ftepp, const char *name) +static GMQCC_INLINE ppmacro* ftepp_macro_find(ftepp_t *ftepp, const char *name) { - return util_htget(ftepp->macros, name); + return (ppmacro*)util_htget(ftepp->macros, name); } -static void ftepp_macro_delete(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); } @@ -839,7 +842,7 @@ static bool ftepp_macro_expand(ftepp_t *ftepp, ppmacro *macro, macroparam *param if (resetline && !ftepp->in_macro) { char lineno[128]; - snprintf(lineno, 128, "\n#pragma line(%lu)\n", (unsigned long)(old_lexer->sline)); + util_snprintf(lineno, 128, "\n#pragma line(%lu)\n", (unsigned long)(old_lexer->sline)); ftepp_out(ftepp, lineno, false); } @@ -1439,7 +1442,7 @@ static bool ftepp_include(ftepp_t *ftepp) ftepp_out(ftepp, "\n#pragma file(", false); ftepp_out(ftepp, ctx.file, false); - snprintf(lineno, sizeof(lineno), ")\n#pragma line(%lu)\n", (unsigned long)(ctx.line+1)); + util_snprintf(lineno, sizeof(lineno), ")\n#pragma line(%lu)\n", (unsigned long)(ctx.line+1)); ftepp_out(ftepp, lineno, false); /* skip the line */ @@ -1804,12 +1807,12 @@ ftepp_t *ftepp_create() minor[2] = '"'; } else if (OPTS_OPTION_U32(OPTION_STANDARD) == COMPILER_GMQCC) { ftepp_add_define(ftepp, NULL, "__STD_GMQCC__"); - snprintf(major, 32, "\"%d\"", GMQCC_VERSION_MAJOR); - snprintf(minor, 32, "\"%d\"", GMQCC_VERSION_MINOR); + util_snprintf(major, 32, "\"%d\"", GMQCC_VERSION_MAJOR); + util_snprintf(minor, 32, "\"%d\"", GMQCC_VERSION_MINOR); } else if (OPTS_OPTION_U32(OPTION_STANDARD) == COMPILER_QCCX) { ftepp_add_define(ftepp, NULL, "__STD_QCCX__"); - snprintf(major, 32, "\"%d\"", GMQCC_VERSION_MAJOR); - snprintf(minor, 32, "\"%d\"", GMQCC_VERSION_MINOR); + util_snprintf(major, 32, "\"%d\"", GMQCC_VERSION_MAJOR); + util_snprintf(minor, 32, "\"%d\"", GMQCC_VERSION_MINOR); } else if (OPTS_OPTION_U32(OPTION_STANDARD) == COMPILER_QCC) { ftepp_add_define(ftepp, NULL, "__STD_QCC__"); /* 1.0 */