From b5f20be3d9caead0ab6221eea5d1aee5ef73e7c6 Mon Sep 17 00:00:00 2001 From: Lukas Krickl Date: Thu, 9 Nov 2023 10:25:38 +0100 Subject: [PATCH] WIP: macros --- src/ulas.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/ulas.c b/src/ulas.c index 26545ef..acf6c78 100644 --- a/src/ulas.c +++ b/src/ulas.c @@ -303,8 +303,10 @@ found: ULASERR("'%s' is not a valid #macro name!\n", pp->tok.buf); return -1; } + char *name = strdup(pp->tok.buf); if (ulas_preprochasstray(pp, pline, n)) { + free(name); return -1; } @@ -323,17 +325,22 @@ found: if (rc == ULAS_PPDIR_ENDMACRO) { break; } + + size_t len = strnlen(pp->line.buf, pp->line.maxlen); + ulas_strensr(&val, val.maxlen + len); + strncat(val.buf, pp->line.buf, val.maxlen); } if (rc != ULAS_PPDIR_ENDMACRO) { ULASERR("Unterminated macro directive\n"); ulas_strfree(&val); + free(name); return -1; } // we leak the str's buffer into the def now // this is ok because we call free for it later anyway - struct ulas_ppdef def = {ULAS_PPDEF, strdup(pp->tok.buf), val.buf, false}; + struct ulas_ppdef def = {ULAS_PPMACRO, name, val.buf, false}; ulas_preprocdef(pp, def); goto dirdone; -- 2.30.2