Refactored return code for preprocnext
authorLukas Krickl <lukas@krickl.dev>
Tue, 7 Nov 2023 21:18:25 +0000 (22:18 +0100)
committerLukas Krickl <lukas@krickl.dev>
Tue, 7 Nov 2023 21:18:25 +0000 (22:18 +0100)
include/ulas.h
src/ulas.c

index 072d0479d2abef59370430f296ed662ade510fc8..24b9c2c77ed028d34b54fea21f2a7d11485b591c 100644 (file)
@@ -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!
index a53a4866963b3fcde00e0c9babbee4b19055963b..330511c564fac8e776456c1e6acd711750f103ab 100644 (file)
@@ -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;
   }