diff options
author | Ingo Schwarze <schwarze@cvs.openbsd.org> | 2018-10-02 12:32:56 +0000 |
---|---|---|
committer | Ingo Schwarze <schwarze@cvs.openbsd.org> | 2018-10-02 12:32:56 +0000 |
commit | f4278ea97856210fca6852a217027b980dd8f3c3 (patch) | |
tree | 560b4ed6b18007ad863561cc8e03d3e6631538e2 /usr.bin/mandoc/html.c | |
parent | 53efc0197c71f0837a7acc96ed7613b126c73fc8 (diff) |
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 'usr.bin/mandoc/html.c')
-rw-r--r-- | usr.bin/mandoc/html.c | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/usr.bin/mandoc/html.c b/usr.bin/mandoc/html.c index 4b758ed130a..0268171bb44 100644 --- a/usr.bin/mandoc/html.c +++ b/usr.bin/mandoc/html.c @@ -1,4 +1,4 @@ -/* $OpenBSD: html.c,v 1.109 2018/08/16 13:49:40 schwarze Exp $ */ +/* $OpenBSD: html.c,v 1.110 2018/10/02 12:32:55 schwarze Exp $ */ /* * Copyright (c) 2008-2011, 2014 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2011-2015, 2017, 2018 Ingo Schwarze <schwarze@openbsd.org> @@ -16,6 +16,7 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #include <sys/types.h> +#include <sys/stat.h> #include <assert.h> #include <ctype.h> @@ -126,7 +127,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; @@ -465,9 +469,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') { |