Welcome to little lamb

Code » qmdoc » commit 926d91a

More skalibs refactoring

author Olivier Brunel
2022-12-26 20:27:39 UTC
committer Olivier Brunel
2022-12-26 20:27:39 UTC
parent 9048d14eed74be741a2b3fc534a7b0178a679c2b

More skalibs refactoring

main.c +17 -4

diff --git a/main.c b/main.c
index a95ae2f..42836b2 100644
--- a/main.c
+++ b/main.c
@@ -11,6 +11,7 @@
 #include <skalibs/strerr2.h>
 #include <skalibs/buffer.h>
 #include <skalibs/djbunix.h>
+#include <skalibs/uint32.h>
 #include <err.h>
 #include "qmdoc.h"
 #include "output.h"
@@ -600,7 +601,13 @@ convert_page(struct ctx *ctx)
 
     allread(ctx->pages[ctx->cur_page].fd, ctx->sa_names.s + salen, size);
     if (errno) {
+        int e = errno;
         ctx->sa_names.len = salen;
+        errs(PROG);
+        errs(": unable to read '");
+        errs(ctx->sa_names.s + ctx->pages[ctx->cur_page].fileoff);
+        errs("': ");
+        errse(strerror(e));
         return ERR_IO;
     }
 
@@ -614,10 +621,16 @@ convert_page(struct ctx *ctx)
         .text = text,
     };
     int r = md_parse(ctx->sa_names.s + salen, size, &parser, ctx);
-    if (r < 0) {
-        retx(ERR_PARSER, "parser internal error %d", -r);
-    } else if (r > 0) {
-        retx(-r - 100, "parser error %d", r);
+    if (r != 0) {
+        char buf[UINT32_FMT];
+        buf[uint32_fmt(buf, (uint32) (r < 0) ? -r : r)] = '\0';
+
+        errs(PROG);
+        errs(": ");
+        errs((r < 0) ? "parser internal error " : "parser error ");
+        errse(buf);
+
+        return ERR_PARSER;
     }
 
     ctx->sa_names.len = salen;