X-Git-Url: https://git.xonotic.org/?a=blobdiff_plain;f=ftepp.c;h=d867d7917c6cb4194f6eeb8f817c1112a0d37253;hb=96126b435ae831d651855d9cf4430c8540ce13b0;hp=ecc36d8e1851f422aed1c31f0e2696ae71db548a;hpb=654eceb33b73a0c81f1d6fa15d14ba60aa973d35;p=xonotic%2Fgmqcc.git diff --git a/ftepp.c b/ftepp.c index ecc36d8..d867d79 100644 --- a/ftepp.c +++ b/ftepp.c @@ -21,6 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ +#include #include "gmqcc.h" #include "lexer.h" @@ -69,11 +70,6 @@ typedef struct { char *includename; } ftepp_t; -typedef struct { - const char *name; - char *(*func)(lex_file *); -} predef_t; - /* * Implement the predef subsystem now. We can do this safely with the * help of lexer contexts. @@ -81,6 +77,42 @@ typedef struct { 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; + time_t rtime; + char *value = mem_a(82); + /* 82 is enough for strftime but we also have " " in our string */ + + (void)context; + + /* get time */ + time (&rtime); + itime = localtime(&rtime); + + strftime(value, 82, "\"%b %d %Y\"", itime); + + return value; +} + +/* __TIME__ */ +char *ftepp_predef_time(lex_file *context) { + struct tm *itime; + time_t rtime; + char *value = mem_a(82); + /* 82 is enough for strftime but we also have " " in our string */ + + (void)context; + + /* get time */ + time (&rtime); + itime = localtime(&rtime); + + strftime(value, 82, "\"%X\"", itime); + + return value; +} + /* __LINE__ */ char *ftepp_predef_line(lex_file *context) { char *value; @@ -131,13 +163,15 @@ char *ftepp_predef_randomlast(lex_file *context) { return value; } -static const predef_t ftepp_predefs[] = { +const ftepp_predef_t ftepp_predefs[FTEPP_PREDEF_COUNT] = { { "__LINE__", &ftepp_predef_line }, { "__FILE__", &ftepp_predef_file }, { "__COUNTER__", &ftepp_predef_counter }, { "__COUNTER_LAST__", &ftepp_predef_counterlast }, { "__RANDOM__", &ftepp_predef_random }, { "__RANDOM_LAST__", &ftepp_predef_randomlast }, + { "__DATE__", &ftepp_predef_date }, + { "__TIME__", &ftepp_predef_time } }; #define ftepp_tokval(f) ((f)->lex->tok.value) @@ -1618,6 +1652,10 @@ bool ftepp_init() ftepp_add_define(NULL, "__STD_GMQCC__"); sprintf(major, "\"%d\"", GMQCC_VERSION_MAJOR); sprintf(minor, "\"%d\"", GMQCC_VERSION_MINOR); + } else if (opts.standard == COMPILER_QCCX) { + ftepp_add_define(NULL, "__STD_QCCX__"); + sprintf(major, "\"%d\"", GMQCC_VERSION_MAJOR); + sprintf(minor, "\"%d\"", GMQCC_VERSION_MINOR); } else if (opts.standard == COMPILER_QCC) { ftepp_add_define(NULL, "__STD_QCC__"); /* 1.0 */