char *value;
/* a copy from the lexer */
union {
- vector v;
+ vec3_t v;
int i;
double f;
int t; /* type */
} pptoken;
typedef struct {
- lex_ctx ctx;
+ lex_ctx_t ctx;
char *name;
char **params;
/* __LINE__ */
static char *ftepp_predef_line(lex_file *context) {
char *value;
- util_asprintf(&value, "%d", (int)context->ctx.line);
+ util_asprintf(&value, "%d", (int)context->line);
return value;
}
/* __FILE__ */
static char *ftepp_predef_file(lex_file *context) {
- size_t length = strlen(context->ctx.file) + 3; /* two quotes and a terminator */
+ size_t length = strlen(context->name) + 3; /* two quotes and a terminator */
char *value = (char*)mem_a(length);
- util_snprintf(value, length, "\"%s\"", context->ctx.file);
+ util_snprintf(value, length, "\"%s\"", context->name);
return value;
}
char *find;
char *value;
size_t size;
- if (stat(context->ctx.file, &finfo))
+#ifdef _MSC_VER
+ char buffer[64];
+#endif
+ if (stat(context->name, &finfo))
return util_strdup("\"<failed to determine timestamp>\"");
/*
* ctime and its fucking annoying newline char, no worries, we're
* professionals here.
*/
+
+#ifndef _MSC_VER
find = ctime(&finfo.st_mtime);
+#else
+ ctime_s(buffer, sizeof(buffer), &finfo.st_mtime);
+ find = buffer;
+#endif
+
value = (char*)mem_a(strlen(find) + 1);
memcpy(&value[1], find, (size = strlen(find)) - 1);
{ "__TIME_STAMP__", &ftepp_predef_timestamp }
};
-static GMQCC_INLINE int ftepp_predef_index(const char *name) {
+static GMQCC_INLINE size_t ftepp_predef_index(const char *name) {
/* no hashtable here, we simply check for one to exist the naive way */
- int i;
- for(i = 0; i < (int)(sizeof(ftepp_predefs)/sizeof(*ftepp_predefs)); i++)
- if (!strcmp(ftepp_predefs[i].name, name))
+ size_t i;
+ for(i = 1; i < GMQCC_ARRAY_COUNT(ftepp_predefs) + 1; i++)
+ if (!strcmp(ftepp_predefs[i-1].name, name))
return i;
- return -1;
+ return 0;
}
+bool ftepp_predef_exists(const char *name);
bool ftepp_predef_exists(const char *name) {
- return ftepp_predef_index(name) != -1;
+ return ftepp_predef_index(name) != 0;
}
/* singleton because we're allowed */
static GMQCC_INLINE char *(*ftepp_predef(const char *name))(lex_file *context) {
- int i = ftepp_predef_index(name);
- return (i != -1) ? ftepp_predefs[i].func : NULL;
+ size_t i = ftepp_predef_index(name);
+ return (i != 0) ? ftepp_predefs[i-1].func : NULL;
}
#define ftepp_tokval(f) ((f)->lex->tok.value)
#define ftepp_ctx(f) ((f)->lex->tok.ctx)
-static void ftepp_errorat(ftepp_t *ftepp, lex_ctx *ctx, const char *fmt, ...)
+static void ftepp_errorat(ftepp_t *ftepp, lex_ctx_t ctx, const char *fmt, ...)
{
va_list ap;
ftepp->errors++;
va_start(ap, fmt);
- con_cvprintmsg((void*)ctx, LVL_ERROR, "error", fmt, ap);
+ con_cvprintmsg(ctx, LVL_ERROR, "error", fmt, ap);
va_end(ap);
}
ftepp->errors++;
va_start(ap, fmt);
- con_cvprintmsg((void*)&ftepp->lex->tok.ctx, LVL_ERROR, "error", fmt, ap);
+ con_cvprintmsg(ftepp->lex->tok.ctx, LVL_ERROR, "error", fmt, ap);
va_end(ap);
}
va_list ap;
va_start(ap, fmt);
- r = vcompile_warning(*(ftepp->lex->tok.ctx), warntype, fmt, ap);
+ r = vcompile_warning(ftepp->lex->tok.ctx, warntype, fmt, ap);
va_end(ap);
return r;
}
mem_d(self);
}
-static ppmacro *ppmacro_new(lex_ctx ctx, const char *name)
+static ppmacro *ppmacro_new(lex_ctx_t ctx, const char *name)
{
ppmacro *macro = (ppmacro*)mem_a(sizeof(ppmacro));
static bool ftepp_define(ftepp_t *ftepp)
{
ppmacro *macro = NULL;
- size_t l = ftepp_ctx(ftepp)->line;
+ size_t l = ftepp_ctx(ftepp).line;
(void)ftepp_next(ftepp);
if (!ftepp_skipspace(ftepp))
return false;
ftepp_macro_delete(ftepp, ftepp_tokval(ftepp));
}
- macro = ppmacro_new(*ftepp_ctx(ftepp), ftepp_tokval(ftepp));
+ macro = ppmacro_new(ftepp_ctx(ftepp), ftepp_tokval(ftepp));
break;
default:
ftepp_error(ftepp, "expected macro name");
ppmacro_delete(macro);
}
- for (; l < ftepp_ctx(ftepp)->line; ++l)
+ for (; l < ftepp_ctx(ftepp).line; ++l)
ftepp_out(ftepp, "\n", true);
return true;
}
/*
printf("__________\n%s\n=========\n", ftepp->output_string);
*/
- inlex = lex_open_string(ftepp->output_string, vec_size(ftepp->output_string)-1, ftepp->lex->ctx.file);
+ inlex = lex_open_string(ftepp->output_string, vec_size(ftepp->output_string)-1, ftepp->lex->name);
if (!inlex) {
ftepp_error(ftepp, "internal error: failed to instantiate lexer");
retval = false;
goto cleanup;
}
- inlex->sline = ftepp->lex->sline;
- inlex->ctx.line = ftepp->lex->ctx.line;
- ftepp->lex = inlex;
+ inlex->line = ftepp->lex->line;
+ inlex->sline = ftepp->lex->sline;
+ ftepp->lex = inlex;
old_inmacro = ftepp->in_macro;
ftepp->in_macro = true;
/* handle the odd non string constant case so it works like C */
if (ftepp->token != TOKEN_STRINGCONST) {
bool store = false;
- vec_upload(message, "#warning", 8);
+ vec_append(message, 8, "#warning");
ftepp_next(ftepp);
while (ftepp->token != TOKEN_EOL) {
- vec_upload(message, ftepp_tokval(ftepp), strlen(ftepp_tokval(ftepp)));
+ vec_append(message, strlen(ftepp_tokval(ftepp)), ftepp_tokval(ftepp));
ftepp_next(ftepp);
}
vec_push(message, '\0');
/* handle the odd non string constant case so it works like C */
if (ftepp->token != TOKEN_STRINGCONST) {
- vec_upload(message, "#error", 6);
+ vec_append(message, 6, "#error");
ftepp_next(ftepp);
while (ftepp->token != TOKEN_EOL) {
- vec_upload(message, ftepp_tokval(ftepp), strlen(ftepp_tokval(ftepp)));
+ vec_append(message, strlen(ftepp_tokval(ftepp)), ftepp_tokval(ftepp));
ftepp_next(ftepp);
}
vec_push(message, '\0');
/* handle the odd non string constant case so it works like C */
if (ftepp->token != TOKEN_STRINGCONST) {
- vec_upload(message, "#message", 8);
+ vec_append(message, 8, "#message");
ftepp_next(ftepp);
while (ftepp->token != TOKEN_EOL) {
- vec_upload(message, ftepp_tokval(ftepp), strlen(ftepp_tokval(ftepp)));
+ vec_append(message, strlen(ftepp_tokval(ftepp)), ftepp_tokval(ftepp));
ftepp_next(ftepp);
}
vec_push(message, '\0');
if (ftepp->output_on)
- con_cprintmsg(&ftepp->lex->tok.ctx, LVL_MSG, "message", message);
+ con_cprintmsg(ftepp->lex->tok.ctx, LVL_MSG, "message", message);
vec_free(message);
return;
}
return;
unescape (ftepp_tokval(ftepp), ftepp_tokval(ftepp));
- con_cprintmsg(&ftepp->lex->tok.ctx, LVL_MSG, "message", ftepp_tokval(ftepp));
+ con_cprintmsg(ftepp->lex->tok.ctx, LVL_MSG, "message", ftepp_tokval(ftepp));
}
/**
{
lex_file *old_lexer = ftepp->lex;
lex_file *inlex;
- lex_ctx ctx;
+ lex_ctx_t ctx;
char lineno[128];
char *filename;
char *old_includename;
return true;
}
- ctx = *ftepp_ctx(ftepp);
+ ctx = ftepp_ctx(ftepp);
unescape(ftepp_tokval(ftepp), ftepp_tokval(ftepp));
ppcondition cond;
ppcondition *pc;
- lex_ctx *ctx = ftepp_ctx(ftepp);
+ lex_ctx_t ctx = ftepp_ctx(ftepp);
if (!ftepp_skipspace(ftepp))
return false;
return;
}
- vec_upload(create, "#define ", 8);
- vec_upload(create, name, strlen(name));
+ vec_append(create, 8, "#define ");
+ vec_append(create, strlen(name), name);
vec_push (create, ' ');
- vec_upload(create, value, strlen(value));
+ vec_append(create, strlen(value), value);
vec_push (create, 0);
ftepp_preprocess_string(ftepp, "__builtin__", create);
void ftepp_add_define(ftepp_t *ftepp, const char *source, const char *name)
{
ppmacro *macro;
- lex_ctx ctx = { "__builtin__", 0, 0 };
+ lex_ctx_t ctx = { "__builtin__", 0, 0 };
ctx.file = source;
macro = ppmacro_new(ctx, name);
/*vec_push(ftepp->macros, macro);*/