diff options
author | Ingo Schwarze <schwarze@openbsd.org> | 2018-10-02 12:33:36 +0000 |
---|---|---|
committer | Ingo Schwarze <schwarze@openbsd.org> | 2018-10-02 12:33:36 +0000 |
commit | dfc72caad2158b1226363fe39e7bfa995ef68f78 (patch) | |
tree | eb50cef13467679b333952697b5e1d3d599919d0 /html.c | |
parent | 5c2a309a34544b8ce4a9f64845f876bc1bc560f3 (diff) | |
download | mandoc-dfc72caad2158b1226363fe39e7bfa995ef68f78.tar.gz mandoc-dfc72caad2158b1226363fe39e7bfa995ef68f78.tar.zst mandoc-dfc72caad2158b1226363fe39e7bfa995ef68f78.zip |
Support a second argument to -O man,
selecting the format according to local existence of the file.
Suggested by kristaps@ during EuroBSDCon 2018.
Written on the train Frankfurt-Karlsruhe returning from EuroBSDCon.
Diffstat (limited to 'html.c')
-rw-r--r-- | html.c | 22 |
1 files changed, 19 insertions, 3 deletions
@@ -1,4 +1,4 @@ -/* $Id: html.c,v 1.239 2018/08/16 13:54:06 schwarze Exp $ */ +/* $Id: html.c,v 1.240 2018/10/02 12:33:37 schwarze Exp $ */ /* * Copyright (c) 2008-2011, 2014 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2011-2015, 2017, 2018 Ingo Schwarze <schwarze@openbsd.org> @@ -18,6 +18,7 @@ #include "config.h" #include <sys/types.h> +#include <sys/stat.h> #include <assert.h> #include <ctype.h> @@ -128,7 +129,10 @@ html_alloc(const struct manoutput *outopts) h->tag = NULL; h->style = outopts->style; - h->base_man = outopts->man; + if ((h->base_man1 = outopts->man) == NULL) + h->base_man2 = NULL; + else if ((h->base_man2 = strchr(h->base_man1, ';')) != NULL) + *h->base_man2++ = '\0'; h->base_includes = outopts->includes; if (outopts->fragment) h->oflags |= HTML_FRAGMENT; @@ -467,9 +471,21 @@ print_encode(struct html *h, const char *p, const char *pend, int norecurse) static void print_href(struct html *h, const char *name, const char *sec, int man) { + struct stat sb; const char *p, *pp; + char *filename; + + if (man) { + pp = h->base_man1; + if (h->base_man2 != NULL) { + mandoc_asprintf(&filename, "%s.%s", name, sec); + if (stat(filename, &sb) == -1) + pp = h->base_man2; + free(filename); + } + } else + pp = h->base_includes; - pp = man ? h->base_man : h->base_includes; while ((p = strchr(pp, '%')) != NULL) { print_encode(h, pp, p, 1); if (man && p[1] == 'S') { |