bool newline;
unsigned int errors;
+ bool output_on;
ppcondition *conditions;
ppmacro **macros;
} ftepp_t;
ftepp = (ftepp_t*)mem_a(sizeof(*ftepp));
memset(ftepp, 0, sizeof(*ftepp));
+ ftepp->output_on = true;
+
return ftepp;
}
static void ftepp_out(ftepp_t *ftepp, const char *str, bool ignore_cond)
{
- if (ignore_cond ||
- !vec_size(ftepp->conditions) ||
- vec_last(ftepp->conditions).on)
+ if (ignore_cond || ftepp->output_on)
{
printf("%s", str);
}
}
-ppmacro* ftepp_macro_find(ftepp_t *ftepp, const char *name)
+static void ftepp_update_output_condition(ftepp_t *ftepp)
+{
+ size_t i;
+ ftepp->output_on = true;
+ for (i = 0; i < vec_size(ftepp->conditions); ++i)
+ ftepp->output_on = ftepp->output_on && ftepp->conditions[i].on;
+}
+
+static ppmacro* ftepp_macro_find(ftepp_t *ftepp, const char *name)
{
size_t i;
for (i = 0; i < vec_size(ftepp->macros); ++i) {
return false;
cond.was_on = cond.on;
vec_push(ftepp->conditions, cond);
+ ftepp->output_on = ftepp->output_on && cond.on;
break;
}
else if (!strcmp(ftepp_tokval(ftepp), "ifndef")) {
cond.on = !cond.on;
cond.was_on = cond.on;
vec_push(ftepp->conditions, cond);
+ ftepp->output_on = ftepp->output_on && cond.on;
break;
}
else if (!strcmp(ftepp_tokval(ftepp), "elifdef")) {
pc = &vec_last(ftepp->conditions);
pc->on = !pc->was_on && cond.on;
pc->was_on = pc->was_on || pc->on;
+ ftepp_update_output_condition(ftepp);
break;
}
else if (!strcmp(ftepp_tokval(ftepp), "elifndef")) {
pc = &vec_last(ftepp->conditions);
pc->on = !pc->was_on && cond.on;
pc->was_on = pc->was_on || pc->on;
+ ftepp_update_output_condition(ftepp);
break;
}
else if (!strcmp(ftepp_tokval(ftepp), "elif")) {
pc = &vec_last(ftepp->conditions);
pc->on = !pc->was_on && cond.on;
pc->was_on = pc->was_on || pc->on;
+ ftepp_update_output_condition(ftepp);
break;
}
else if (!strcmp(ftepp_tokval(ftepp), "if")) {
return false;
cond.was_on = cond.on;
vec_push(ftepp->conditions, cond);
+ ftepp->output_on = ftepp->output_on && cond.on;
break;
}
else if (!strcmp(ftepp_tokval(ftepp), "else")) {
pc->on = !pc->was_on;
pc->had_else = true;
ftepp_next(ftepp);
+ ftepp_update_output_condition(ftepp);
break;
}
else if (!strcmp(ftepp_tokval(ftepp), "endif")) {
}
vec_pop(ftepp->conditions);
ftepp_next(ftepp);
+ ftepp_update_output_condition(ftepp);
break;
}
else {