2 * Copyright (C) 2012, 2013
6 * Permission is hereby granted, free of charge, to any person obtaining a copy of
7 * this software and associated documentation files (the "Software"), to deal in
8 * the Software without restriction, including without limitation the rights to
9 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
10 * of the Software, and to permit persons to whom the Software is furnished to do
11 * so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in all
14 * copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31 #define HT_MACROS 1024
42 /* a copy from the lexer */
56 /* yes we need an extra flag since `#define FOO x` is not the same as `#define FOO() x` */
63 typedef struct ftepp_s {
69 ppcondition *conditions;
71 ht macros; /* hashtable<string, ppmacro*> */
78 uint32_t predef_countval;
79 uint32_t predef_randval;
83 static char *ftepp_predef_date(ftepp_t *context) {
84 const struct tm *itime = NULL;
85 char *value = (char*)mem_a(82);
91 itime = util_localtime(&rtime);
92 strftime(value, 82, "\"%b %d %Y\"", itime);
98 static char *ftepp_predef_time(ftepp_t *context) {
99 const struct tm *itime = NULL;
100 char *value = (char*)mem_a(82);
106 itime = util_localtime(&rtime);
107 strftime(value, 82, "\"%X\"", itime);
113 static char *ftepp_predef_line(ftepp_t *context) {
116 util_asprintf(&value, "%d", (int)context->lex->line);
120 static char *ftepp_predef_file(ftepp_t *context) {
121 size_t length = strlen(context->lex->name) + 3; /* two quotes and a terminator */
122 char *value = (char*)mem_a(length);
124 util_snprintf(value, length, "\"%s\"", context->lex->name);
127 /* __COUNTER_LAST__ */
128 static char *ftepp_predef_counterlast(ftepp_t *context) {
130 util_asprintf(&value, "%u", context->predef_countval);
134 static char *ftepp_predef_counter(ftepp_t *context) {
137 context->predef_countval ++;
138 util_asprintf(&value, "%u", context->predef_countval);
143 static char *ftepp_predef_random(ftepp_t *context) {
146 context->predef_randval = (util_rand() % 0xFF) + 1;
147 util_asprintf(&value, "%u", context->predef_randval);
150 /* __RANDOM_LAST__ */
151 static char *ftepp_predef_randomlast(ftepp_t *context) {
154 util_asprintf(&value, "%u", context->predef_randval);
158 static char *ftepp_predef_timestamp(ftepp_t *context) {
164 if (stat(context->lex->name, &finfo))
165 return util_strdup("\"<failed to determine timestamp>\"");
167 find = util_ctime(&finfo.st_mtime);
168 value = (char*)mem_a(strlen(find) + 1);
169 memcpy(&value[1], find, (size = strlen(find)) - 1);
179 char *(*func)(ftepp_t *);
182 static const ftepp_predef_t ftepp_predefs[] = {
183 { "__LINE__", &ftepp_predef_line },
184 { "__FILE__", &ftepp_predef_file },
185 { "__COUNTER__", &ftepp_predef_counter },
186 { "__COUNTER_LAST__", &ftepp_predef_counterlast },
187 { "__RANDOM__", &ftepp_predef_random },
188 { "__RANDOM_LAST__", &ftepp_predef_randomlast },
189 { "__DATE__", &ftepp_predef_date },
190 { "__TIME__", &ftepp_predef_time },
191 { "__TIME_STAMP__", &ftepp_predef_timestamp }
194 static GMQCC_INLINE size_t ftepp_predef_index(const char *name) {
195 /* no hashtable here, we simply check for one to exist the naive way */
197 for(i = 1; i < GMQCC_ARRAY_COUNT(ftepp_predefs) + 1; i++)
198 if (!strcmp(ftepp_predefs[i-1].name, name))
203 bool ftepp_predef_exists(const char *name);
204 bool ftepp_predef_exists(const char *name) {
205 return ftepp_predef_index(name) != 0;
208 /* singleton because we're allowed */
209 static GMQCC_INLINE char *(*ftepp_predef(const char *name))(ftepp_t *context) {
210 size_t i = ftepp_predef_index(name);
211 return (i != 0) ? ftepp_predefs[i-1].func : NULL;
214 #define ftepp_tokval(f) ((f)->lex->tok.value)
215 #define ftepp_ctx(f) ((f)->lex->tok.ctx)
217 static void ftepp_errorat(ftepp_t *ftepp, lex_ctx_t ctx, const char *fmt, ...)
224 con_cvprintmsg(ctx, LVL_ERROR, "error", fmt, ap);
228 static void ftepp_error(ftepp_t *ftepp, const char *fmt, ...)
235 con_cvprintmsg(ftepp->lex->tok.ctx, LVL_ERROR, "error", fmt, ap);
239 static bool GMQCC_WARN ftepp_warn(ftepp_t *ftepp, int warntype, const char *fmt, ...)
245 r = vcompile_warning(ftepp->lex->tok.ctx, warntype, fmt, ap);
250 static pptoken *pptoken_make(ftepp_t *ftepp)
252 pptoken *token = (pptoken*)mem_a(sizeof(pptoken));
253 token->token = ftepp->token;
255 if (token->token == TOKEN_WHITE)
256 token->value = util_strdup(" ");
259 token->value = util_strdup(ftepp_tokval(ftepp));
261 memcpy(&token->constval, &ftepp->lex->tok.constval, sizeof(token->constval));
265 static GMQCC_INLINE void pptoken_delete(pptoken *self)
271 static ppmacro *ppmacro_new(lex_ctx_t ctx, const char *name)
273 ppmacro *macro = (ppmacro*)mem_a(sizeof(ppmacro));
276 memset(macro, 0, sizeof(*macro));
277 macro->name = util_strdup(name);
281 static void ppmacro_delete(ppmacro *self)
284 for (i = 0; i < vec_size(self->params); ++i)
285 mem_d(self->params[i]);
286 vec_free(self->params);
287 for (i = 0; i < vec_size(self->output); ++i)
288 pptoken_delete(self->output[i]);
289 vec_free(self->output);
294 static ftepp_t* ftepp_new(void)
298 ftepp = (ftepp_t*)mem_a(sizeof(*ftepp));
299 memset(ftepp, 0, sizeof(*ftepp));
301 ftepp->macros = util_htnew(HT_MACROS);
302 ftepp->output_on = true;
303 ftepp->predef_countval = 0;
304 ftepp->predef_randval = 0;
309 static GMQCC_INLINE void ftepp_flush_do(ftepp_t *self)
311 vec_free(self->output_string);
314 static void ftepp_delete(ftepp_t *self)
316 ftepp_flush_do(self);
318 mem_d(self->itemname);
319 if (self->includename)
320 vec_free(self->includename);
322 util_htrem(self->macros, (void (*)(void*))&ppmacro_delete);
324 vec_free(self->conditions);
326 lex_close(self->lex);
330 static void ftepp_out(ftepp_t *ftepp, const char *str, bool ignore_cond)
332 if (ignore_cond || ftepp->output_on)
337 data = vec_add(ftepp->output_string, len);
338 memcpy(data, str, len);
342 static GMQCC_INLINE void ftepp_update_output_condition(ftepp_t *ftepp)
345 ftepp->output_on = true;
346 for (i = 0; i < vec_size(ftepp->conditions); ++i)
347 ftepp->output_on = ftepp->output_on && ftepp->conditions[i].on;
350 static GMQCC_INLINE ppmacro* ftepp_macro_find(ftepp_t *ftepp, const char *name)
352 return (ppmacro*)util_htget(ftepp->macros, name);
355 static GMQCC_INLINE void ftepp_macro_delete(ftepp_t *ftepp, const char *name)
357 util_htrm(ftepp->macros, name, (void (*)(void*))&ppmacro_delete);
360 static GMQCC_INLINE int ftepp_next(ftepp_t *ftepp)
362 return (ftepp->token = lex_do(ftepp->lex));
365 /* Important: this does not skip newlines! */
366 static bool ftepp_skipspace(ftepp_t *ftepp)
368 if (ftepp->token != TOKEN_WHITE)
370 while (ftepp_next(ftepp) == TOKEN_WHITE) {}
371 if (ftepp->token >= TOKEN_EOF) {
372 ftepp_error(ftepp, "unexpected end of preprocessor directive");
378 /* this one skips EOLs as well */
379 static bool ftepp_skipallwhite(ftepp_t *ftepp)
381 if (ftepp->token != TOKEN_WHITE && ftepp->token != TOKEN_EOL)
385 } while (ftepp->token == TOKEN_WHITE || ftepp->token == TOKEN_EOL);
386 if (ftepp->token >= TOKEN_EOF) {
387 ftepp_error(ftepp, "unexpected end of preprocessor directive");
394 * The huge macro parsing code...
396 static bool ftepp_define_params(ftepp_t *ftepp, ppmacro *macro)
400 if (!ftepp_skipspace(ftepp))
402 if (ftepp->token == ')')
404 switch (ftepp->token) {
408 vec_push(macro->params, util_strdup(ftepp_tokval(ftepp)));
411 macro->variadic = true;
414 ftepp_error(ftepp, "unexpected token in parameter list");
418 if (!ftepp_skipspace(ftepp))
420 if (macro->variadic && ftepp->token != ')') {
421 ftepp_error(ftepp, "cannot have parameters after the variadic parameters");
424 } while (ftepp->token == ',');
426 if (ftepp->token != ')') {
427 ftepp_error(ftepp, "expected closing paren after macro parameter list");
431 /* skipspace happens in ftepp_define */
435 static bool ftepp_define_body(ftepp_t *ftepp, ppmacro *macro)
438 while (ftepp->token != TOKEN_EOL && ftepp->token < TOKEN_EOF) {
439 bool subscript = false;
441 if (macro->variadic && !strcmp(ftepp_tokval(ftepp), "__VA_ARGS__")) {
442 subscript = !!(ftepp_next(ftepp) == '#');
444 if (subscript && ftepp_next(ftepp) != '#') {
445 ftepp_error(ftepp, "expected `##` in __VA_ARGS__ for subscripting");
447 } else if (subscript) {
448 if (ftepp_next(ftepp) == '[') {
449 if (ftepp_next(ftepp) != TOKEN_INTCONST) {
450 ftepp_error(ftepp, "expected index for __VA_ARGS__ subscript");
454 index = (int)strtol(ftepp_tokval(ftepp), NULL, 10);
456 if (ftepp_next(ftepp) != ']') {
457 ftepp_error(ftepp, "expected `]` in __VA_ARGS__ subscript");
462 * mark it as an array to be handled later as such and not
463 * as traditional __VA_ARGS__
465 ftepp->token = TOKEN_VA_ARGS_ARRAY;
466 ptok = pptoken_make(ftepp);
467 ptok->constval.i = index;
468 vec_push(macro->output, ptok);
471 ftepp_error(ftepp, "expected `[` for subscripting of __VA_ARGS__");
475 int old = ftepp->token;
476 ftepp->token = TOKEN_VA_ARGS;
477 ptok = pptoken_make(ftepp);
478 vec_push(macro->output, ptok);
482 else if (macro->variadic && !strcmp(ftepp_tokval(ftepp), "__VA_COUNT__")) {
483 ftepp->token = TOKEN_VA_COUNT;
484 ptok = pptoken_make(ftepp);
485 vec_push(macro->output, ptok);
488 ptok = pptoken_make(ftepp);
489 vec_push(macro->output, ptok);
493 /* recursive expansion can cause EOFs here */
494 if (ftepp->token != TOKEN_EOL && ftepp->token != TOKEN_EOF) {
495 ftepp_error(ftepp, "unexpected junk after macro or unexpected end of file");
501 static bool ftepp_define(ftepp_t *ftepp)
503 ppmacro *macro = NULL;
504 size_t l = ftepp_ctx(ftepp).line;
506 (void)ftepp_next(ftepp);
507 if (!ftepp_skipspace(ftepp))
510 switch (ftepp->token) {
514 macro = ftepp_macro_find(ftepp, ftepp_tokval(ftepp));
515 if (macro && ftepp->output_on) {
516 if (ftepp_warn(ftepp, WARN_CPP, "redefining `%s`", ftepp_tokval(ftepp)))
518 ftepp_macro_delete(ftepp, ftepp_tokval(ftepp));
520 macro = ppmacro_new(ftepp_ctx(ftepp), ftepp_tokval(ftepp));
523 ftepp_error(ftepp, "expected macro name");
527 (void)ftepp_next(ftepp);
529 if (ftepp->token == '(') {
530 macro->has_params = true;
531 if (!ftepp_define_params(ftepp, macro)) {
532 ppmacro_delete(macro);
537 if (!ftepp_skipspace(ftepp)) {
538 ppmacro_delete(macro);
542 if (!ftepp_define_body(ftepp, macro)) {
543 ppmacro_delete(macro);
547 if (ftepp->output_on)
548 util_htset(ftepp->macros, macro->name, (void*)macro);
550 ppmacro_delete(macro);
553 for (; l < ftepp_ctx(ftepp).line; ++l)
554 ftepp_out(ftepp, "\n", true);
559 * When a macro is used we have to handle parameters as well
560 * as special-concatenation via ## or stringification via #
562 * Note: parenthesis can nest, so FOO((a),b) is valid, but only
563 * this kind of parens. Curly braces or [] don't count towards the
570 static void macroparam_clean(macroparam *self)
573 for (i = 0; i < vec_size(self->tokens); ++i)
574 pptoken_delete(self->tokens[i]);
575 vec_free(self->tokens);
578 /* need to leave the last token up */
579 static bool ftepp_macro_call_params(ftepp_t *ftepp, macroparam **out_params)
581 macroparam *params = NULL;
587 if (!ftepp_skipallwhite(ftepp))
589 while (ftepp->token != ')') {
591 if (!ftepp_skipallwhite(ftepp))
593 while (parens || ftepp->token != ',') {
594 if (ftepp->token == '(')
596 else if (ftepp->token == ')') {
601 ptok = pptoken_make(ftepp);
602 vec_push(mp.tokens, ptok);
603 if (ftepp_next(ftepp) >= TOKEN_EOF) {
604 ftepp_error(ftepp, "unexpected end of file in macro call");
608 vec_push(params, mp);
610 if (ftepp->token == ')')
612 if (ftepp->token != ',') {
613 ftepp_error(ftepp, "expected closing paren or comma in macro call");
616 if (ftepp_next(ftepp) >= TOKEN_EOF) {
617 ftepp_error(ftepp, "unexpected end of file in macro call");
621 *out_params = params;
626 macroparam_clean(&mp);
627 for (i = 0; i < vec_size(params); ++i)
628 macroparam_clean(¶ms[i]);
633 static bool macro_params_find(ppmacro *macro, const char *name, size_t *idx)
636 for (i = 0; i < vec_size(macro->params); ++i) {
637 if (!strcmp(macro->params[i], name)) {
645 static void ftepp_stringify_token(ftepp_t *ftepp, pptoken *token)
650 switch (token->token) {
651 case TOKEN_STRINGCONST:
654 /* in preprocessor mode strings already are string,
655 * so we don't get actual newline bytes here.
656 * Still need to escape backslashes and quotes.
659 case '\\': ftepp_out(ftepp, "\\\\", false); break;
660 case '"': ftepp_out(ftepp, "\\\"", false); break;
663 ftepp_out(ftepp, chs, false);
670 ftepp_out(ftepp, " ", false);
673 ftepp_out(ftepp, "\\n", false);
676 ftepp_out(ftepp, token->value, false);
681 static void ftepp_stringify(ftepp_t *ftepp, macroparam *param)
684 ftepp_out(ftepp, "\"", false);
685 for (i = 0; i < vec_size(param->tokens); ++i)
686 ftepp_stringify_token(ftepp, param->tokens[i]);
687 ftepp_out(ftepp, "\"", false);
690 static void ftepp_recursion_header(ftepp_t *ftepp)
692 ftepp_out(ftepp, "\n#pragma push(line)\n", false);
695 static void ftepp_recursion_footer(ftepp_t *ftepp)
697 ftepp_out(ftepp, "\n#pragma pop(line)\n", false);
700 static void ftepp_param_out(ftepp_t *ftepp, macroparam *param)
704 for (i = 0; i < vec_size(param->tokens); ++i) {
705 out = param->tokens[i];
706 if (out->token == TOKEN_EOL)
707 ftepp_out(ftepp, "\n", false);
709 ftepp_out(ftepp, out->value, false);
713 static bool ftepp_preprocess(ftepp_t *ftepp);
714 static bool ftepp_macro_expand(ftepp_t *ftepp, ppmacro *macro, macroparam *params, bool resetline)
717 char *old_string = ftepp->output_string;
719 lex_file *old_lexer = ftepp->lex;
720 size_t vararg_start = vec_size(macro->params);
732 if (vararg_start < vec_size(params))
733 varargs = vec_size(params) - vararg_start;
738 if (!vec_size(macro->output))
741 ftepp->output_string = NULL;
742 for (o = 0; o < vec_size(macro->output); ++o) {
743 pptoken *out = macro->output[o];
744 switch (out->token) {
746 if (!macro->variadic) {
747 ftepp_error(ftepp, "internal preprocessor error: TOKEN_VA_ARGS in non-variadic macro");
748 vec_free(old_string);
755 ftepp_param_out(ftepp, ¶ms[pi + vararg_start]);
756 for (++pi; pi < varargs; ++pi) {
757 ftepp_out(ftepp, ", ", false);
758 ftepp_param_out(ftepp, ¶ms[pi + vararg_start]);
762 case TOKEN_VA_ARGS_ARRAY:
763 if ((size_t)out->constval.i >= varargs) {
764 ftepp_error(ftepp, "subscript of `[%u]` is out of bounds for `__VA_ARGS__`", out->constval.i);
765 vec_free(old_string);
769 ftepp_param_out(ftepp, ¶ms[out->constval.i + vararg_start]);
773 util_asprintf(&buffer, "%d", varargs);
774 ftepp_out(ftepp, buffer, false);
781 if (!macro_params_find(macro, out->value, &pi)) {
782 ftepp_out(ftepp, out->value, false);
785 ftepp_param_out(ftepp, ¶ms[pi]);
788 if (o + 1 < vec_size(macro->output)) {
789 nextok = macro->output[o+1]->token;
791 /* raw concatenation */
795 if ( (nextok == TOKEN_IDENT ||
796 nextok == TOKEN_KEYWORD ||
797 nextok == TOKEN_TYPENAME) &&
798 macro_params_find(macro, macro->output[o+1]->value, &pi))
801 ftepp_stringify(ftepp, ¶ms[pi]);
805 ftepp_out(ftepp, "#", false);
808 ftepp_out(ftepp, "\n", false);
811 ftepp_out(ftepp, out->value, false);
815 vec_push(ftepp->output_string, 0);
816 /* Now run the preprocessor recursively on this string buffer */
818 printf("__________\n%s\n=========\n", ftepp->output_string);
820 inlex = lex_open_string(ftepp->output_string, vec_size(ftepp->output_string)-1, ftepp->lex->name);
822 ftepp_error(ftepp, "internal error: failed to instantiate lexer");
827 inlex->line = ftepp->lex->line;
828 inlex->sline = ftepp->lex->sline;
831 old_inmacro = ftepp->in_macro;
832 ftepp->in_macro = true;
833 ftepp->output_string = NULL;
834 if (!ftepp_preprocess(ftepp)) {
835 ftepp->in_macro = old_inmacro;
836 vec_free(ftepp->lex->open_string);
837 vec_free(ftepp->output_string);
838 lex_close(ftepp->lex);
842 ftepp->in_macro = old_inmacro;
843 vec_free(ftepp->lex->open_string);
844 lex_close(ftepp->lex);
846 inner_string = ftepp->output_string;
847 ftepp->output_string = old_string;
849 has_newlines = (strchr(inner_string, '\n') != NULL);
851 if (has_newlines && !old_inmacro)
852 ftepp_recursion_header(ftepp);
854 vec_append(ftepp->output_string, vec_size(inner_string), inner_string);
855 vec_free(inner_string);
857 if (has_newlines && !old_inmacro)
858 ftepp_recursion_footer(ftepp);
860 if (resetline && !ftepp->in_macro) {
862 util_snprintf(lineno, 128, "\n#pragma line(%lu)\n", (unsigned long)(old_lexer->sline));
863 ftepp_out(ftepp, lineno, false);
866 old_string = ftepp->output_string;
868 ftepp->lex = old_lexer;
869 ftepp->output_string = old_string;
873 static bool ftepp_macro_call(ftepp_t *ftepp, ppmacro *macro)
876 macroparam *params = NULL;
880 if (!macro->has_params) {
881 if (!ftepp_macro_expand(ftepp, macro, NULL, false))
888 if (!ftepp_skipallwhite(ftepp))
891 if (ftepp->token != '(') {
892 ftepp_error(ftepp, "expected macro parameters in parenthesis");
897 paramline = ftepp->lex->sline;
898 if (!ftepp_macro_call_params(ftepp, ¶ms))
901 if ( vec_size(params) < vec_size(macro->params) ||
902 (vec_size(params) > vec_size(macro->params) && !macro->variadic) )
904 ftepp_error(ftepp, "macro %s expects%s %u paramteters, %u provided", macro->name,
905 (macro->variadic ? " at least" : ""),
906 (unsigned int)vec_size(macro->params),
907 (unsigned int)vec_size(params));
912 if (!ftepp_macro_expand(ftepp, macro, params, (paramline != ftepp->lex->sline)))
917 for (o = 0; o < vec_size(params); ++o)
918 macroparam_clean(¶ms[o]);
924 * #if - the FTEQCC way:
925 * defined(FOO) => true if FOO was #defined regardless of parameters or contents
926 * <numbers> => True if the number is not 0
927 * !<factor> => True if the factor yields false
928 * !!<factor> => ERROR on 2 or more unary nots
929 * <macro> => becomes the macro's FIRST token regardless of parameters
930 * <e> && <e> => True if both expressions are true
931 * <e> || <e> => True if either expression is true
933 * <ident> => False (remember for macros the <macro> rule applies instead)
934 * Unary + and - are weird and wrong in fteqcc so we don't allow them
935 * parenthesis in expressions are allowed
936 * parameter lists on macros are errors
937 * No mathematical calculations are executed
939 static bool ftepp_if_expr(ftepp_t *ftepp, bool *out, double *value_out);
940 static bool ftepp_if_op(ftepp_t *ftepp)
942 ftepp->lex->flags.noops = false;
944 if (!ftepp_skipspace(ftepp))
946 ftepp->lex->flags.noops = true;
949 static bool ftepp_if_value(ftepp_t *ftepp, bool *out, double *value_out)
955 if (!ftepp_skipspace(ftepp))
958 while (ftepp->token == '!') {
961 if (!ftepp_skipspace(ftepp))
965 if (ftepp->token == TOKEN_OPERATOR && !strcmp(ftepp_tokval(ftepp), "-"))
969 if (!ftepp_skipspace(ftepp))
973 switch (ftepp->token) {
977 if (!strcmp(ftepp_tokval(ftepp), "defined")) {
979 if (!ftepp_skipspace(ftepp))
981 if (ftepp->token != '(') {
982 ftepp_error(ftepp, "`defined` keyword in #if requires a macro name in parenthesis");
986 if (!ftepp_skipspace(ftepp))
988 if (ftepp->token != TOKEN_IDENT &&
989 ftepp->token != TOKEN_TYPENAME &&
990 ftepp->token != TOKEN_KEYWORD)
992 ftepp_error(ftepp, "defined() used on an unexpected token type");
995 macro = ftepp_macro_find(ftepp, ftepp_tokval(ftepp));
998 if (!ftepp_skipspace(ftepp))
1000 if (ftepp->token != ')') {
1001 ftepp_error(ftepp, "expected closing paren");
1007 macro = ftepp_macro_find(ftepp, ftepp_tokval(ftepp));
1008 if (!macro || !vec_size(macro->output)) {
1012 /* This does not expand recursively! */
1013 switch (macro->output[0]->token) {
1014 case TOKEN_INTCONST:
1015 *value_out = macro->output[0]->constval.i;
1016 *out = !!(macro->output[0]->constval.i);
1018 case TOKEN_FLOATCONST:
1019 *value_out = macro->output[0]->constval.f;
1020 *out = !!(macro->output[0]->constval.f);
1028 case TOKEN_STRINGCONST:
1032 case TOKEN_INTCONST:
1033 *value_out = ftepp->lex->tok.constval.i;
1034 *out = !!(ftepp->lex->tok.constval.i);
1036 case TOKEN_FLOATCONST:
1037 *value_out = ftepp->lex->tok.constval.f;
1038 *out = !!(ftepp->lex->tok.constval.f);
1043 if (!ftepp_if_expr(ftepp, out, value_out))
1045 if (ftepp->token != ')') {
1046 ftepp_error(ftepp, "expected closing paren in #if expression");
1052 ftepp_error(ftepp, "junk in #if: `%s` ...", ftepp_tokval(ftepp));
1053 if (OPTS_OPTION_BOOL(OPTION_DEBUG))
1054 ftepp_error(ftepp, "internal: token %i\n", ftepp->token);
1058 *value_out = -*value_out;
1061 *value_out = (*out ? 1 : 0);
1067 static bool ftepp_if_nextvalue(ftepp_t *ftepp, bool *out, double *value_out)
1069 if (!ftepp_next(ftepp))
1071 return ftepp_if_value(ftepp, out, value_out);
1075 static bool ftepp_if_expr(ftepp_t *ftepp, bool *out, double *value_out)
1077 if (!ftepp_if_value(ftepp, out, value_out))
1080 if (!ftepp_if_op(ftepp))
1083 if (ftepp->token == ')' || ftepp->token != TOKEN_OPERATOR)
1086 /* FTEQCC is all right-associative and no precedence here */
1087 if (!strcmp(ftepp_tokval(ftepp), "&&") ||
1088 !strcmp(ftepp_tokval(ftepp), "||"))
1091 char opc = ftepp_tokval(ftepp)[0];
1095 if (!ftepp_next(ftepp))
1097 if (!ftepp_if_expr(ftepp, &next, &nextvalue))
1101 *out = *out && next;
1103 *out = *out || next;
1105 *value_out = (*out ? 1 : 0);
1108 else if (!strcmp(ftepp_tokval(ftepp), "==") ||
1109 !strcmp(ftepp_tokval(ftepp), "!=") ||
1110 !strcmp(ftepp_tokval(ftepp), ">=") ||
1111 !strcmp(ftepp_tokval(ftepp), "<=") ||
1112 !strcmp(ftepp_tokval(ftepp), ">") ||
1113 !strcmp(ftepp_tokval(ftepp), "<"))
1116 const char opc0 = ftepp_tokval(ftepp)[0];
1117 const char opc1 = ftepp_tokval(ftepp)[1];
1120 if (!ftepp_next(ftepp))
1122 if (!ftepp_if_expr(ftepp, &next, &other))
1126 *out = (*value_out == other);
1127 else if (opc0 == '!')
1128 *out = (*value_out != other);
1129 else if (opc0 == '>') {
1130 if (opc1 == '=') *out = (*value_out >= other);
1131 else *out = (*value_out > other);
1133 else if (opc0 == '<') {
1134 if (opc1 == '=') *out = (*value_out <= other);
1135 else *out = (*value_out < other);
1137 *value_out = (*out ? 1 : 0);
1142 ftepp_error(ftepp, "junk after #if");
1147 static bool ftepp_if(ftepp_t *ftepp, ppcondition *cond)
1149 bool result = false;
1152 memset(cond, 0, sizeof(*cond));
1153 (void)ftepp_next(ftepp);
1155 if (!ftepp_skipspace(ftepp))
1157 if (ftepp->token == TOKEN_EOL) {
1158 ftepp_error(ftepp, "expected expression for #if-directive");
1162 if (!ftepp_if_expr(ftepp, &result, &dummy))
1170 * ifdef is rather simple
1172 static bool ftepp_ifdef(ftepp_t *ftepp, ppcondition *cond)
1175 memset(cond, 0, sizeof(*cond));
1176 (void)ftepp_next(ftepp);
1177 if (!ftepp_skipspace(ftepp))
1180 switch (ftepp->token) {
1182 case TOKEN_TYPENAME:
1184 macro = ftepp_macro_find(ftepp, ftepp_tokval(ftepp));
1187 ftepp_error(ftepp, "expected macro name");
1191 (void)ftepp_next(ftepp);
1192 if (!ftepp_skipspace(ftepp))
1194 /* relaxing this condition
1195 if (ftepp->token != TOKEN_EOL && ftepp->token != TOKEN_EOF) {
1196 ftepp_error(ftepp, "stray tokens after #ifdef");
1205 * undef is also simple
1207 static bool ftepp_undef(ftepp_t *ftepp)
1209 (void)ftepp_next(ftepp);
1210 if (!ftepp_skipspace(ftepp))
1213 if (ftepp->output_on) {
1214 switch (ftepp->token) {
1216 case TOKEN_TYPENAME:
1218 ftepp_macro_delete(ftepp, ftepp_tokval(ftepp));
1221 ftepp_error(ftepp, "expected macro name");
1226 (void)ftepp_next(ftepp);
1227 if (!ftepp_skipspace(ftepp))
1229 /* relaxing this condition
1230 if (ftepp->token != TOKEN_EOL && ftepp->token != TOKEN_EOF) {
1231 ftepp_error(ftepp, "stray tokens after #ifdef");
1238 /* Special unescape-string function which skips a leading quote
1239 * and stops at a quote, not just at \0
1241 static void unescape(const char *str, char *out) {
1243 while (*str && *str != '"') {
1247 case '\\': *out++ = *str; break;
1248 case '"': *out++ = *str; break;
1249 case 'a': *out++ = '\a'; break;
1250 case 'b': *out++ = '\b'; break;
1251 case 'r': *out++ = '\r'; break;
1252 case 'n': *out++ = '\n'; break;
1253 case 't': *out++ = '\t'; break;
1254 case 'f': *out++ = '\f'; break;
1255 case 'v': *out++ = '\v'; break;
1270 static char *ftepp_include_find_path(const char *file, const char *pathfile)
1273 char *filename = NULL;
1274 const char *last_slash;
1280 last_slash = strrchr(pathfile, '/');
1283 len = last_slash - pathfile;
1284 memcpy(vec_add(filename, len), pathfile, len);
1285 vec_push(filename, '/');
1289 memcpy(vec_add(filename, len+1), file, len);
1290 vec_last(filename) = 0;
1292 fp = fs_file_open(filename, "rb");
1301 static char *ftepp_include_find(ftepp_t *ftepp, const char *file)
1303 char *filename = NULL;
1305 filename = ftepp_include_find_path(file, ftepp->includename);
1307 filename = ftepp_include_find_path(file, ftepp->itemname);
1311 static bool ftepp_directive_warning(ftepp_t *ftepp) {
1312 char *message = NULL;
1314 if (!ftepp_skipspace(ftepp))
1317 /* handle the odd non string constant case so it works like C */
1318 if (ftepp->token != TOKEN_STRINGCONST) {
1320 vec_append(message, 8, "#warning");
1322 while (ftepp->token != TOKEN_EOL) {
1323 vec_append(message, strlen(ftepp_tokval(ftepp)), ftepp_tokval(ftepp));
1326 vec_push(message, '\0');
1327 if (ftepp->output_on)
1328 store = ftepp_warn(ftepp, WARN_CPP, message);
1335 if (!ftepp->output_on)
1338 unescape (ftepp_tokval(ftepp), ftepp_tokval(ftepp));
1339 return ftepp_warn(ftepp, WARN_CPP, "#warning %s", ftepp_tokval(ftepp));
1342 static void ftepp_directive_error(ftepp_t *ftepp) {
1343 char *message = NULL;
1345 if (!ftepp_skipspace(ftepp))
1348 /* handle the odd non string constant case so it works like C */
1349 if (ftepp->token != TOKEN_STRINGCONST) {
1350 vec_append(message, 6, "#error");
1352 while (ftepp->token != TOKEN_EOL) {
1353 vec_append(message, strlen(ftepp_tokval(ftepp)), ftepp_tokval(ftepp));
1356 vec_push(message, '\0');
1357 if (ftepp->output_on)
1358 ftepp_error(ftepp, message);
1363 if (!ftepp->output_on)
1366 unescape (ftepp_tokval(ftepp), ftepp_tokval(ftepp));
1367 ftepp_error(ftepp, "#error %s", ftepp_tokval(ftepp));
1370 static void ftepp_directive_message(ftepp_t *ftepp) {
1371 char *message = NULL;
1373 if (!ftepp_skipspace(ftepp))
1376 /* handle the odd non string constant case so it works like C */
1377 if (ftepp->token != TOKEN_STRINGCONST) {
1378 vec_append(message, 8, "#message");
1380 while (ftepp->token != TOKEN_EOL) {
1381 vec_append(message, strlen(ftepp_tokval(ftepp)), ftepp_tokval(ftepp));
1384 vec_push(message, '\0');
1385 if (ftepp->output_on)
1386 con_cprintmsg(ftepp->lex->tok.ctx, LVL_MSG, "message", message);
1391 if (!ftepp->output_on)
1394 unescape (ftepp_tokval(ftepp), ftepp_tokval(ftepp));
1395 con_cprintmsg(ftepp->lex->tok.ctx, LVL_MSG, "message", ftepp_tokval(ftepp));
1400 * FIXME: do we need/want a -I option?
1401 * FIXME: what about when dealing with files in subdirectories coming from a progs.src?
1403 static bool ftepp_include(ftepp_t *ftepp)
1405 lex_file *old_lexer = ftepp->lex;
1410 char *old_includename;
1412 (void)ftepp_next(ftepp);
1413 if (!ftepp_skipspace(ftepp))
1416 if (ftepp->token != TOKEN_STRINGCONST) {
1417 ftepp_error(ftepp, "expected filename to include");
1421 if (!ftepp->output_on) {
1426 ctx = ftepp_ctx(ftepp);
1428 unescape(ftepp_tokval(ftepp), ftepp_tokval(ftepp));
1430 ftepp_out(ftepp, "\n#pragma file(", false);
1431 ftepp_out(ftepp, ftepp_tokval(ftepp), false);
1432 ftepp_out(ftepp, ")\n#pragma line(1)\n", false);
1434 filename = ftepp_include_find(ftepp, ftepp_tokval(ftepp));
1436 ftepp_error(ftepp, "failed to open include file `%s`", ftepp_tokval(ftepp));
1439 inlex = lex_open(filename);
1441 ftepp_error(ftepp, "open failed on include file `%s`", filename);
1446 old_includename = ftepp->includename;
1447 ftepp->includename = filename;
1448 if (!ftepp_preprocess(ftepp)) {
1449 vec_free(ftepp->includename);
1450 ftepp->includename = old_includename;
1451 lex_close(ftepp->lex);
1452 ftepp->lex = old_lexer;
1455 vec_free(ftepp->includename);
1456 ftepp->includename = old_includename;
1457 lex_close(ftepp->lex);
1458 ftepp->lex = old_lexer;
1460 ftepp_out(ftepp, "\n#pragma file(", false);
1461 ftepp_out(ftepp, ctx.file, false);
1462 util_snprintf(lineno, sizeof(lineno), ")\n#pragma line(%lu)\n", (unsigned long)(ctx.line+1));
1463 ftepp_out(ftepp, lineno, false);
1466 (void)ftepp_next(ftepp);
1467 if (!ftepp_skipspace(ftepp))
1469 if (ftepp->token != TOKEN_EOL) {
1470 ftepp_error(ftepp, "stray tokens after #include");
1473 (void)ftepp_next(ftepp);
1478 /* Basic structure handlers */
1479 static bool ftepp_else_allowed(ftepp_t *ftepp)
1481 if (!vec_size(ftepp->conditions)) {
1482 ftepp_error(ftepp, "#else without #if");
1485 if (vec_last(ftepp->conditions).had_else) {
1486 ftepp_error(ftepp, "multiple #else for a single #if");
1492 static GMQCC_INLINE void ftepp_inmacro(ftepp_t *ftepp, const char *hash) {
1493 if (ftepp->in_macro)
1494 (void)!ftepp_warn(ftepp, WARN_DIRECTIVE_INMACRO, "`#%s` directive in macro", hash);
1497 static bool ftepp_hash(ftepp_t *ftepp)
1502 lex_ctx_t ctx = ftepp_ctx(ftepp);
1504 if (!ftepp_skipspace(ftepp))
1507 switch (ftepp->token) {
1510 case TOKEN_TYPENAME:
1511 if (!strcmp(ftepp_tokval(ftepp), "define")) {
1512 ftepp_inmacro(ftepp, "define");
1513 return ftepp_define(ftepp);
1515 else if (!strcmp(ftepp_tokval(ftepp), "undef")) {
1516 ftepp_inmacro(ftepp, "undef");
1517 return ftepp_undef(ftepp);
1519 else if (!strcmp(ftepp_tokval(ftepp), "ifdef")) {
1520 ftepp_inmacro(ftepp, "ifdef");
1521 if (!ftepp_ifdef(ftepp, &cond))
1523 cond.was_on = cond.on;
1524 vec_push(ftepp->conditions, cond);
1525 ftepp->output_on = ftepp->output_on && cond.on;
1528 else if (!strcmp(ftepp_tokval(ftepp), "ifndef")) {
1529 ftepp_inmacro(ftepp, "ifndef");
1530 if (!ftepp_ifdef(ftepp, &cond))
1533 cond.was_on = cond.on;
1534 vec_push(ftepp->conditions, cond);
1535 ftepp->output_on = ftepp->output_on && cond.on;
1538 else if (!strcmp(ftepp_tokval(ftepp), "elifdef")) {
1539 ftepp_inmacro(ftepp, "elifdef");
1540 if (!ftepp_else_allowed(ftepp))
1542 if (!ftepp_ifdef(ftepp, &cond))
1544 pc = &vec_last(ftepp->conditions);
1545 pc->on = !pc->was_on && cond.on;
1546 pc->was_on = pc->was_on || pc->on;
1547 ftepp_update_output_condition(ftepp);
1550 else if (!strcmp(ftepp_tokval(ftepp), "elifndef")) {
1551 ftepp_inmacro(ftepp, "elifndef");
1552 if (!ftepp_else_allowed(ftepp))
1554 if (!ftepp_ifdef(ftepp, &cond))
1557 pc = &vec_last(ftepp->conditions);
1558 pc->on = !pc->was_on && cond.on;
1559 pc->was_on = pc->was_on || pc->on;
1560 ftepp_update_output_condition(ftepp);
1563 else if (!strcmp(ftepp_tokval(ftepp), "elif")) {
1564 ftepp_inmacro(ftepp, "elif");
1565 if (!ftepp_else_allowed(ftepp))
1567 if (!ftepp_if(ftepp, &cond))
1569 pc = &vec_last(ftepp->conditions);
1570 pc->on = !pc->was_on && cond.on;
1571 pc->was_on = pc->was_on || pc->on;
1572 ftepp_update_output_condition(ftepp);
1575 else if (!strcmp(ftepp_tokval(ftepp), "if")) {
1576 ftepp_inmacro(ftepp, "if");
1577 if (!ftepp_if(ftepp, &cond))
1579 cond.was_on = cond.on;
1580 vec_push(ftepp->conditions, cond);
1581 ftepp->output_on = ftepp->output_on && cond.on;
1584 else if (!strcmp(ftepp_tokval(ftepp), "else")) {
1585 ftepp_inmacro(ftepp, "else");
1586 if (!ftepp_else_allowed(ftepp))
1588 pc = &vec_last(ftepp->conditions);
1589 pc->on = !pc->was_on;
1590 pc->had_else = true;
1592 ftepp_update_output_condition(ftepp);
1595 else if (!strcmp(ftepp_tokval(ftepp), "endif")) {
1596 ftepp_inmacro(ftepp, "endif");
1597 if (!vec_size(ftepp->conditions)) {
1598 ftepp_error(ftepp, "#endif without #if");
1601 vec_pop(ftepp->conditions);
1603 ftepp_update_output_condition(ftepp);
1606 else if (!strcmp(ftepp_tokval(ftepp), "include")) {
1607 ftepp_inmacro(ftepp, "include");
1608 return ftepp_include(ftepp);
1610 else if (!strcmp(ftepp_tokval(ftepp), "pragma")) {
1611 ftepp_out(ftepp, "#", false);
1614 else if (!strcmp(ftepp_tokval(ftepp), "warning")) {
1615 ftepp_directive_warning(ftepp);
1618 else if (!strcmp(ftepp_tokval(ftepp), "error")) {
1619 ftepp_directive_error(ftepp);
1622 else if (!strcmp(ftepp_tokval(ftepp), "message")) {
1623 ftepp_directive_message(ftepp);
1627 if (ftepp->output_on) {
1628 ftepp_error(ftepp, "unrecognized preprocessor directive: `%s`", ftepp_tokval(ftepp));
1635 /* break; never reached */
1637 ftepp_error(ftepp, "unexpected preprocessor token: `%s`", ftepp_tokval(ftepp));
1640 ftepp_errorat(ftepp, ctx, "empty preprocessor directive");
1643 ftepp_error(ftepp, "missing newline at end of file", ftepp_tokval(ftepp));
1646 /* Builtins! Don't forget the builtins! */
1647 case TOKEN_INTCONST:
1648 case TOKEN_FLOATCONST:
1649 ftepp_out(ftepp, "#", false);
1652 if (!ftepp_skipspace(ftepp))
1657 static bool ftepp_preprocess(ftepp_t *ftepp)
1660 bool newline = true;
1663 char *expand = NULL;
1665 ftepp->lex->flags.preprocessing = true;
1666 ftepp->lex->flags.mergelines = false;
1667 ftepp->lex->flags.noops = true;
1672 if (ftepp->token >= TOKEN_EOF)
1678 switch (ftepp->token) {
1681 case TOKEN_TYPENAME:
1682 /* is it a predef? */
1683 if (OPTS_FLAG(FTEPP_PREDEFS)) {
1684 char *(*predef)(ftepp_t*) = ftepp_predef(ftepp_tokval(ftepp));
1686 expand = predef(ftepp);
1687 ftepp_out (ftepp, expand, false);
1695 if (ftepp->output_on)
1696 macro = ftepp_macro_find(ftepp, ftepp_tokval(ftepp));
1701 ftepp_out(ftepp, ftepp_tokval(ftepp), false);
1705 if (!ftepp_macro_call(ftepp, macro))
1706 ftepp->token = TOKEN_ERROR;
1710 ftepp_out(ftepp, ftepp_tokval(ftepp), false);
1714 ftepp->lex->flags.mergelines = true;
1715 if (ftepp_next(ftepp) >= TOKEN_EOF) {
1716 ftepp_error(ftepp, "error in preprocessor directive");
1717 ftepp->token = TOKEN_ERROR;
1720 if (!ftepp_hash(ftepp))
1721 ftepp->token = TOKEN_ERROR;
1722 ftepp->lex->flags.mergelines = false;
1726 ftepp_out(ftepp, "\n", true);
1730 /* same as default but don't set newline=false */
1731 ftepp_out(ftepp, ftepp_tokval(ftepp), true);
1736 ftepp_out(ftepp, ftepp_tokval(ftepp), false);
1740 } while (!ftepp->errors && ftepp->token < TOKEN_EOF);
1742 /* force a 0 at the end but don't count it as added to the output */
1743 vec_push(ftepp->output_string, 0);
1744 vec_shrinkby(ftepp->output_string, 1);
1746 return (ftepp->token == TOKEN_EOF);
1749 /* Like in parser.c - files keep the previous state so we have one global
1750 * preprocessor. Except here we will want to warn about dangling #ifs.
1752 static bool ftepp_preprocess_done(ftepp_t *ftepp)
1755 if (vec_size(ftepp->conditions)) {
1756 if (ftepp_warn(ftepp, WARN_MULTIFILE_IF, "#if spanning multiple files, is this intended?"))
1759 lex_close(ftepp->lex);
1761 if (ftepp->itemname) {
1762 mem_d(ftepp->itemname);
1763 ftepp->itemname = NULL;
1768 bool ftepp_preprocess_file(ftepp_t *ftepp, const char *filename)
1770 ftepp->lex = lex_open(filename);
1771 ftepp->itemname = util_strdup(filename);
1773 con_out("failed to open file \"%s\"\n", filename);
1776 if (!ftepp_preprocess(ftepp))
1778 return ftepp_preprocess_done(ftepp);
1781 bool ftepp_preprocess_string(ftepp_t *ftepp, const char *name, const char *str)
1783 ftepp->lex = lex_open_string(str, strlen(str), name);
1784 ftepp->itemname = util_strdup(name);
1786 con_out("failed to create lexer for string \"%s\"\n", name);
1789 if (!ftepp_preprocess(ftepp))
1791 return ftepp_preprocess_done(ftepp);
1795 void ftepp_add_macro(ftepp_t *ftepp, const char *name, const char *value) {
1796 char *create = NULL;
1798 /* use saner path for empty macros */
1800 ftepp_add_define(ftepp, "__builtin__", name);
1804 vec_append(create, 8, "#define ");
1805 vec_append(create, strlen(name), name);
1806 vec_push (create, ' ');
1807 vec_append(create, strlen(value), value);
1808 vec_push (create, 0);
1810 ftepp_preprocess_string(ftepp, "__builtin__", create);
1814 static const char *ftepp_math_constants[][2] = {
1815 { "M_E", "2.7182818284590452354" }, /* e */
1816 { "M_LOG2E", "1.4426950408889634074" }, /* log_2 e */
1817 { "M_LOG10E", "0.43429448190325182765" }, /* log_10 e */
1818 { "M_LN2", "0.69314718055994530942" }, /* log_e 2 */
1819 { "M_LN10", "2.30258509299404568402" }, /* log_e 10 */
1820 { "M_PI", "3.14159265358979323846" }, /* pi */
1821 { "M_PI_2", "1.57079632679489661923" }, /* pi/2 */
1822 { "M_PI_4", "0.78539816339744830962" }, /* pi/4 */
1823 { "M_1_PI", "0.31830988618379067154" }, /* 1/pi */
1824 { "M_2_PI", "0.63661977236758134308" }, /* 2/pi */
1825 { "M_2_SQRTPI", "1.12837916709551257390" }, /* 2/sqrt(pi) */
1826 { "M_SQRT2", "1.41421356237309504880" }, /* sqrt(2) */
1827 { "M_SQRT1_2", "0.70710678118654752440" }, /* 1/sqrt(2) */
1828 { "M_TAU", "6.28318530717958647692" } /* pi*2 */
1831 ftepp_t *ftepp_create()
1838 ftepp = ftepp_new();
1842 memset(minor, 0, sizeof(minor));
1843 memset(major, 0, sizeof(major));
1845 /* set the right macro based on the selected standard */
1846 ftepp_add_define(ftepp, NULL, "GMQCC");
1847 if (OPTS_OPTION_U32(OPTION_STANDARD) == COMPILER_FTEQCC) {
1848 ftepp_add_define(ftepp, NULL, "__STD_FTEQCC__");
1857 } else if (OPTS_OPTION_U32(OPTION_STANDARD) == COMPILER_GMQCC) {
1858 ftepp_add_define(ftepp, NULL, "__STD_GMQCC__");
1859 util_snprintf(major, 32, "\"%d\"", GMQCC_VERSION_MAJOR);
1860 util_snprintf(minor, 32, "\"%d\"", GMQCC_VERSION_MINOR);
1861 } else if (OPTS_OPTION_U32(OPTION_STANDARD) == COMPILER_QCCX) {
1862 ftepp_add_define(ftepp, NULL, "__STD_QCCX__");
1863 util_snprintf(major, 32, "\"%d\"", GMQCC_VERSION_MAJOR);
1864 util_snprintf(minor, 32, "\"%d\"", GMQCC_VERSION_MINOR);
1865 } else if (OPTS_OPTION_U32(OPTION_STANDARD) == COMPILER_QCC) {
1866 ftepp_add_define(ftepp, NULL, "__STD_QCC__");
1877 ftepp_add_macro(ftepp, "__STD_VERSION_MINOR__", minor);
1878 ftepp_add_macro(ftepp, "__STD_VERSION_MAJOR__", major);
1881 * We're going to just make __NULL__ nil, which works for 60% of the
1882 * cases of __NULL_ for fteqcc.
1884 ftepp_add_macro(ftepp, "__NULL__", "nil");
1886 /* add all the math constants */
1887 for (i = 0; i < GMQCC_ARRAY_COUNT(ftepp_math_constants); i++)
1888 ftepp_add_macro(ftepp, ftepp_math_constants[i][0], ftepp_math_constants[i][1]);
1893 void ftepp_add_define(ftepp_t *ftepp, const char *source, const char *name)
1896 lex_ctx_t ctx = { "__builtin__", 0, 0 };
1898 macro = ppmacro_new(ctx, name);
1899 /*vec_push(ftepp->macros, macro);*/
1900 util_htset(ftepp->macros, name, macro);
1903 const char *ftepp_get(ftepp_t *ftepp)
1905 return ftepp->output_string;
1908 void ftepp_flush(ftepp_t *ftepp)
1910 ftepp_flush_do(ftepp);
1913 void ftepp_finish(ftepp_t *ftepp)
1917 ftepp_delete(ftepp);