Welcome to little lamb

Code » qmdoc » commit 36d9e22

Minor: Rename sa_names -> sa

author Olivier Brunel
2022-12-27 12:54:04 UTC
committer Olivier Brunel
2022-12-27 12:54:04 UTC
parent 1b1d2e1369262a84d397eba92b2fd2bccc7f0bfc

Minor: Rename sa_names -> sa

main.c +29 -29

diff --git a/main.c b/main.c
index 223895d..0a28f9f 100644
--- a/main.c
+++ b/main.c
@@ -63,8 +63,8 @@ enum {
 
 struct ctx {
     int options;
+    stralloc sa;
     buffer out;
-    stralloc sa_names;
     struct css *css;
     struct page *pages;
     int nb_pages;
@@ -95,10 +95,10 @@ raw_text(struct ctx *ctx, const char *text, size_t size)
         if (buffer_put(&ctx->out, text, size) != size) return 0;
         else return 1;
     } else if (ctx->buf.state == BUF_WAITING) {
-        ctx->buf.salen = ctx->sa_names.len;
+        ctx->buf.salen = ctx->sa.len;
         ctx->buf.state = BUF_ON;
     }
-    return stralloc_catb(&ctx->sa_names, text, size);
+    return stralloc_catb(&ctx->sa, text, size);
 }
 
 #define raw_str(ctx,s)      raw_text(ctx, s, strlen(s))
@@ -198,8 +198,8 @@ enter_block(MD_BLOCKTYPE type, void *details, void *ctx_)
     switch (type) {
         case MD_BLOCK_DOC:
             {
-#define str_title(i)    ctx->sa_names.s + ctx->pages[i].titleoff
-#define str_file(i)    ctx->sa_names.s + ctx->pages[i].fileoff
+#define str_title(i)    ctx->sa.s + ctx->pages[i].titleoff
+#define str_file(i)    ctx->sa.s + ctx->pages[i].fileoff
                 if (!raw_str(ctx, "<!DOCTYPE html>\n<html><head>")
                         || !raw_str(ctx, "<title>")
                         || !escape_text(ctx, str_title(ctx->cur_page),
@@ -209,7 +209,7 @@ enter_block(MD_BLOCKTYPE type, void *details, void *ctx_)
                 if (ctx->options & OPT_INLINE_CSS) {
                     for (int i = 0; i < NB_CSS; ++i) {
                         if (!raw_str(ctx, "<style>")
-                                || !raw_str(ctx, ctx->sa_names.s + ctx->css[i].offset)
+                                || !raw_str(ctx, ctx->sa.s + ctx->css[i].offset)
                                 || !raw_str(ctx, "</style>"))
                             return ERR_PARSER_ENTER_BLOCK;
                     }
@@ -405,9 +405,9 @@ leave_block(MD_BLOCKTYPE type, void *details, void *ctx_)
                 if (!(ctx->code.flags & CODE_BUFFERED)) {
                     return (raw_str(ctx, "</pre>")) ? 0 : ERR_PARSER_LEAVE_BLOCK;
                 } else {
-                    const char *buf = ctx->sa_names.s + ctx->buf.salen;
-                    size_t blen = ctx->sa_names.len - ctx->buf.salen;
-                    ctx->sa_names.len = ctx->buf.salen;
+                    const char *buf = ctx->sa.s + ctx->buf.salen;
+                    size_t blen = ctx->sa.len - ctx->buf.salen;
+                    ctx->sa.len = ctx->buf.salen;
                     ctx->buf.state = BUF_OFF;
 
                     if (ctx->code.flags & CODE_LINES) {
@@ -661,18 +661,18 @@ static int
 convert_page(struct ctx *ctx)
 {
     size_t size = ctx->pages[ctx->cur_page].size;
-    size_t salen = ctx->sa_names.len;
+    size_t salen = ctx->sa.len;
 
-    if (!stralloc_readyplus(&ctx->sa_names, size))
+    if (!stralloc_readyplus(&ctx->sa, size))
         return ERR_MEM;
 
-    allread(ctx->pages[ctx->cur_page].fd, ctx->sa_names.s + salen, size);
+    allread(ctx->pages[ctx->cur_page].fd, ctx->sa.s + salen, size);
     if (errno) {
         int e = errno;
-        ctx->sa_names.len = salen;
+        ctx->sa.len = salen;
         errs(PROG);
         errs(": unable to read '");
-        errs(ctx->sa_names.s + ctx->pages[ctx->cur_page].fileoff);
+        errs(ctx->sa.s + ctx->pages[ctx->cur_page].fileoff);
         errs("': ");
         errse(strerror(e));
         return ERR_IO;
@@ -687,7 +687,7 @@ convert_page(struct ctx *ctx)
         .leave_span = leave_span,
         .text = text,
     };
-    int r = md_parse(ctx->sa_names.s + salen, size, &parser, ctx);
+    int r = md_parse(ctx->sa.s + salen, size, &parser, ctx);
     if (r != 0) {
         char buf[UINT32_FMT];
         buf[uint32_fmt(buf, (uint32) (r < 0) ? -r : r)] = '\0';
@@ -700,20 +700,20 @@ convert_page(struct ctx *ctx)
         return ERR_PARSER;
     }
 
-    ctx->sa_names.len = salen;
+    ctx->sa.len = salen;
     return 0;
 }
 
 static void
-load_page_from_file(const char *file, struct page *page, stralloc *sa_names)
+load_page_from_file(const char *file, struct page *page, stralloc *sa)
 {
     page->fd = open_read(file);
     if (page->fd < 0) strerr_diefu3sys(-ERR_IO, "open '", file, "'");
 
     size_t l = strlen(file);
-    page->fileoff = sa_names->len;
-    if (!stralloc_catb(sa_names, file, l - 2)
-            || !stralloc_catb(sa_names, "html", 5))
+    page->fileoff = sa->len;
+    if (!stralloc_catb(sa, file, l - 2)
+            || !stralloc_catb(sa, "html", 5))
         strerr_diefu3sys(-ERR_MEM, "load page title from '", file, "'");
 
     char buf_[256], buf[sizeof(buf_)];
@@ -735,11 +735,11 @@ load_page_from_file(const char *file, struct page *page, stralloc *sa_names)
             break;
         switch (line) {
             case 1:
-                if (begin && is_hdr) page->titleoff = sa_names->len;
+                if (begin && is_hdr) page->titleoff = sa->len;
                 if (is_hdr
-                        && (!stralloc_catb(sa_names, b + ((is_hdr) ? 2 : 0),
+                        && (!stralloc_catb(sa, b + ((is_hdr) ? 2 : 0),
                                            ((e) ? e - b : left) - ((is_hdr) ? 2 : 0))
-                            || (e && !stralloc_0(sa_names))))
+                            || (e && !stralloc_0(sa))))
                     strerr_diefu3sys(-ERR_MEM, "load page title from '", file, "'");
                 break;
             case 2:
@@ -837,7 +837,7 @@ main (int argc, char *argv[])
     struct page pages[argc - optind];
     struct ctx ctx = {
         .options = options,
-        .sa_names = STRALLOC_ZERO,
+        .sa = STRALLOC_ZERO,
         .css = css,
         .pages = pages,
         .nb_pages = sizeof(pages) / sizeof(*pages),
@@ -856,7 +856,7 @@ main (int argc, char *argv[])
             continue;
         }
 
-        load_page_from_file(file, &pages[i - optind], &ctx.sa_names);
+        load_page_from_file(file, &pages[i - optind], &ctx.sa);
     }
 
     if (!(options & OPT_NO_CSS)) {
@@ -864,9 +864,9 @@ main (int argc, char *argv[])
         outse(" CSS files...");
         for (int i = 0; i < NB_CSS; ++i) {
             if (options & OPT_INLINE_CSS) {
-                css[i].offset = ctx.sa_names.len;
-                if (!openreadfileclose(css[i].file, &ctx.sa_names, 0)
-                        || !stralloc_0(&ctx.sa_names))
+                css[i].offset = ctx.sa.len;
+                if (!openreadfileclose(css[i].file, &ctx.sa, 0)
+                        || !stralloc_0(&ctx.sa))
                     strerr_diefu3sys(-ERR_IO, "load CSS from '", css[i].file, "'");
             } else {
                 int from, to;
@@ -912,7 +912,7 @@ main (int argc, char *argv[])
         fd_close(pages[ctx.cur_page].fd);
     }
 
-    stralloc_free(&ctx.sa_names);
+    stralloc_free(&ctx.sa);
 
     outse("done.");
     return 0;