From ae8d1abfeee9efda17d655d54276de4d5ce5ab8d Mon Sep 17 00:00:00 2001 From: Lukas Krickl Date: Tue, 7 Nov 2023 22:18:25 +0100 Subject: [PATCH] Refactored return code for preprocnext --- include/ulas.h | 4 ++-- src/ulas.c | 8 +++----- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/include/ulas.h b/include/ulas.h index 072d047..24b9c2c 100644 --- a/include/ulas.h +++ b/include/ulas.h @@ -107,7 +107,7 @@ extern struct ulas ulas; */ enum ulas_ppdirs { - ULAS_PPDIR_NONE = 0, + ULAS_PPDIR_NONE = 1, ULAS_PPDIR_DEF, ULAS_PPDIR_MACRO, ULAS_PPDIR_ENDMACRO, @@ -247,7 +247,7 @@ int ulas_preproc(FILE *dst, FILE *src); // reads the next line // returns 0 if no more data can be read -// 1 if data was read +// > 0 if data was read (enum ulas_ppdirs id) // -1 on error // it also places the processed line into pp->line.buf // note that this is overwritten by every call! diff --git a/src/ulas.c b/src/ulas.c index a53a486..330511c 100644 --- a/src/ulas.c +++ b/src/ulas.c @@ -243,7 +243,7 @@ int ulas_preprocline(struct ulas_preproc *pp, FILE *dst, FILE *src, } found: - if (found_dir) { + if (found_dir != ULAS_PPDIR_NONE) { switch (found_dir) { case ULAS_PPDIR_DEF: { // next token is a name @@ -296,7 +296,7 @@ found: fwrite(line, 1, n, dst); } - return 0; + return ULAS_PPDIR_NONE; } int ulas_preprocnext(struct ulas_preproc *pp, FILE *dst, FILE *src, char *buf, @@ -304,9 +304,7 @@ int ulas_preprocnext(struct ulas_preproc *pp, FILE *dst, FILE *src, char *buf, int rc = 1; if (fgets(buf, n, src) != NULL) { ulas.line++; - if (ulas_preprocline(pp, dst, src, buf, strlen(buf)) == -1) { - rc = -1; - } + rc = ulas_preprocline(pp, dst, src, buf, strlen(buf)); } else { rc = 0; } -- 2.30.2