From 04622a676372303eb19c7b53e808e6212dbd3ce1 Mon Sep 17 00:00:00 2001 From: Lukas Krickl Date: Sun, 12 Nov 2023 18:34:21 +0100 Subject: [PATCH] Added \n trim to macro params --- src/ulas.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/ulas.c b/src/ulas.c index d00856d..94037d2 100644 --- a/src/ulas.c +++ b/src/ulas.c @@ -255,6 +255,15 @@ int ulas_preproclws(struct ulas_preproc *pp, const char *praw_line, return i; } +void ulas_trimend(char c, char *buf, size_t n) { + size_t buflen = strnlen(buf, n); + // remove trailing new line if present + while (buf[buflen - 1] == '\n') { + buf[buflen - 1] = '\0'; + buflen--; + } +} + char *ulas_preprocexpand(struct ulas_preproc *pp, const char *raw_line, size_t *n) { const char *praw_line = raw_line; @@ -321,6 +330,9 @@ char *ulas_preprocexpand(struct ulas_preproc *pp, const char *raw_line, while (paramc < ULAS_MACROPARAMMAX && ulas_tokuntil(&pp->macroparam[paramc], ',', &praw_line, *n) > 0) { + // trim new lines from the end of macro params + ulas_trimend('\n', pp->macroparam[paramc].buf, + strlen(pp->macroparam[paramc].buf)); paramc++; } ulas_strensr(&pp->line, strlen(def->value) + 2); @@ -424,15 +436,6 @@ int ulas_preprocdef(struct ulas_preproc *pp, struct ulas_ppdef def) { return 0; } -void ulas_trimend(char c, char *buf, size_t n) { - size_t buflen = strnlen(buf, n); - // remove trailing new line if present - while (buf[buflen - 1] == '\n') { - buf[buflen - 1] = '\0'; - buflen--; - } -} - int ulas_preprocline(struct ulas_preproc *pp, FILE *dst, FILE *src, const char *raw_line, size_t n) { /** -- 2.30.2