Welcome to little lamb

Code » qmdoc » commit ac602a3

Add option --sharedir

author Olivier Brunel
2023-05-27 11:59:27 UTC
committer Olivier Brunel
2023-07-05 07:56:22 UTC
parent b0c204cb23d4fda8cba9af98bc256133b953e945

Add option --sharedir

src/qmdoc/qmdoc.c +13 -3

diff --git a/src/qmdoc/qmdoc.c b/src/qmdoc/qmdoc.c
index 8a88f7f..2491b7d 100644
--- a/src/qmdoc/qmdoc.c
+++ b/src/qmdoc/qmdoc.c
@@ -1404,10 +1404,12 @@ struct parse {
     size_t footer;
     size_t header;
     size_t ffile;
+    size_t sharedir;
 };
 
 enum {
     OPTID_VERSION = OPTID_FIRST,
+    OPTID_SHAREDIR,
     ARGID_FILE
 };
 
@@ -1434,6 +1436,7 @@ parse_cmdline(int argc, const char *argv[], const char usage[], struct parse *ct
         OPTION_ARG_NONE( 0 , "version",                 0,          OPTID_VERSION),
         OPTION_ARG_NONE('W', "wide-includes",           0,          OPTID_SHORTOPT),
         OPTION_ARG_NONE('X', "no-index",                0,          OPTID_SHORTOPT),
+        OPTION_ARG_REQ(  0 , "sharedir",                OPT_PATH,   OPTID_SHAREDIR),
         LOADOPT_ARGUMENTS,
         ARGUMENT_REQ( "file",                           OPT_PATH | OPT_RPT,   ARGID_FILE),
         LOADOPT_DONE
@@ -1479,6 +1482,7 @@ parse_cmdline(int argc, const char *argv[], const char usage[], struct parse *ct
 " -l, --lang LNG                    Set LNG as language attribute\n"
 " -M, --man-url URL                 Use URL as prefix for external man-page links\n"
 " -o, --overwrite                   Overwrite destination files if already exist\n"
+"     --sharedir DIR                Use DIR as source for qmdoc's CSS files\n"
 " -s, --subtitle TEXT               Set TEXT as general subtitle\n"
 " -T, --no-toc                      Don't write a TOC on each page. Implies --no-index\n"
 " -t, --title TITLE                 Set TITLE as general (across all pages) title\n"
@@ -1516,6 +1520,9 @@ parse_cmdline(int argc, const char *argv[], const char usage[], struct parse *ct
         case 'X':
             ctx->qmdoc->options |= OPT_NO_INDEX;
             break;
+        case OPTID_SHAREDIR:
+            ctx->sharedir = LO_OFF(&lo);
+            break;
         case OPTID_VERSION:
             dieversion(QMDOC_VERSION, "2023", QMDOC_CURYEAR, QMDOC_AUTHOR, QMDOC_URL, NULL);
             break;
@@ -1554,7 +1561,8 @@ main (int argc, const char *argv[])
         .buf.sa = STRALLOC_ZERO,
     };
     struct parse parse = { .qmdoc = &ctx, .destdir = (size_t) -1,
-        .header = (size_t) -1, .footer = (size_t) -1, .ffile = (size_t) -1 };
+        .header = (size_t) -1, .footer = (size_t) -1, .ffile = (size_t) -1,
+        .sharedir = (size_t) -1 };
     const char usage[] = "[OPTION..] FILE..";
 
     ctx.nb_pages = parse_cmdline(argc, argv, usage, &parse);
@@ -1685,9 +1693,11 @@ main (int argc, const char *argv[])
         out((ctx.options & OPT_INLINE_CSS) ? "Loading" : "Copying", " CSS files...");
         int dirfd;
         if (!(ctx.options & OPT_NO_CSS)) {
-            dirfd = open2(QMDOC_SHAREDIR, O_RDONLY | O_DIRECTORY);
+            dirfd = open2((parse.sharedir == (size_t) -1) ? QMDOC_SHAREDIR
+                          : ctx.sa.s + parse.sharedir, O_RDONLY | O_DIRECTORY);
             if (dirfd < 0)
-                diefusys(EX_IOERR, "open ", ESC, QMDOC_SHAREDIR, ESC);
+                diefusys(EX_IOERR, "open ", ESC, (parse.sharedir == (size_t) -1)
+                    ? QMDOC_SHAREDIR : ctx.sa.s + parse.sharedir, ESC);
         } else {
             dirfd = AT_FDCWD;
         }