Welcome to little lamb

Code » qmdoc » commit f500874

Read our CSS files from SHAREDIR

author Olivier Brunel
2023-01-14 16:32:55 UTC
committer Olivier Brunel
2023-01-14 16:32:55 UTC
parent 20195ba46f16fc188c74c7443ca89e028764a456

Read our CSS files from SHAREDIR

src/main.c +13 -4

diff --git a/src/main.c b/src/main.c
index 574ea18..b1a2371 100644
--- a/src/main.c
+++ b/src/main.c
@@ -1620,15 +1620,24 @@ main (int argc, char *argv[])
         out((ctx.options & OPT_INLINE_CSS) ? "Loading" : "Copying", " CSS files...");
         for (int i = 0; i < NB_CSS; ++i) {
             if (!css[i].file) continue;
+            size_t flen = strlen(css[i].file);
+            char file[strlen(QMDOC_SHAREDIR) + 1 + flen + 1];
+            if (i != CSS_CUSTOM) {
+                memcpy(file, QMDOC_SHAREDIR, strlen(QMDOC_SHAREDIR));
+                file[strlen(QMDOC_SHAREDIR)] = '/';
+                memcpy(file + strlen(QMDOC_SHAREDIR) + 1, css[i].file, flen + 1);
+            } else {
+                memcpy(file, css[i].file, flen + 1);
+            }
             if (ctx.options & OPT_INLINE_CSS) {
                 css[i].offset = ctx.sa.len;
-                if (!openreadfileclose(css[i].file, &ctx.sa, 0)
+                if (!openreadfileclose(file, &ctx.sa, 0)
                         || !stralloc_0(&ctx.sa))
-                    diefusys(-ERR_IO, "load CSS from '", css[i].file, "'");
+                    diefusys(-ERR_IO, "load CSS from '", file, "'");
             } else {
                 int from, to;
-                from = open_read(css[i].file);
-                if (from < 0) diefusys(-ERR_IO, "open '", css[i].file, "'");
+                from = open_read(file);
+                if (from < 0) diefusys(-ERR_IO, "open '", file, "'");
                 if (ctx.options & OPT_OVERWRITE)
                     to = open_truncat(fddest, css[i].file);
                 else