summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@openbsd.org>2018-10-02 12:33:36 +0000
committerIngo Schwarze <schwarze@openbsd.org>2018-10-02 12:33:36 +0000
commit9e238facdedce54e6eeccb030929d4b3893df873 (patch)
treeaf1153e654b28c1021d8c3934f87d6691336566e
parent2b5f7b1a9ecbfb46e4d111a73e873c9ac394f261 (diff)
downloadmandoc-9e238facdedce54e6eeccb030929d4b3893df873.tar.gz
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.
-rw-r--r--TODO6
-rw-r--r--html.c20
-rw-r--r--html.h3
-rw-r--r--mandoc.16
-rw-r--r--mdoc_html.c2
5 files changed, 26 insertions, 11 deletions
diff --git a/TODO b/TODO
index a66c5bd3..4aded6d4 100644
--- a/TODO
+++ b/TODO
@@ -395,12 +395,6 @@ are mere guesses, and some may be wrong.
only if the new option -O toc is given
suggested by Adam Kalisz during EuroBSDCon 2018
-- support -O man with two arguments, typically using the first for
- a local tree (like the release pages on mandoc.bsd.lv) and the
- second for a remote tree (e.g. man.openbsd.org).
- Probable syntax: -O man=first;second
- Suggested by kristaps@ during EuroBSDCon 2018.
-
- wrap Sh and Ss content into <div>
Laura Morales <lauretas at mail dot com> 21 Apr 2018 18:10:48 +0200
(Evaluate whether this is really useful and has no adverse
diff --git a/html.c b/html.c
index 778e7953..d0c2b656 100644
--- a/html.c
+++ b/html.c
@@ -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') {
diff --git a/html.h b/html.h
index 84d88dc9..4b3e3df1 100644
--- a/html.h
+++ b/html.h
@@ -101,7 +101,8 @@ struct html {
struct tag *tag; /* last open tag */
struct rofftbl tbl; /* current table */
struct tag *tblt; /* current open table scope */
- char *base_man; /* base for manpage href */
+ char *base_man1; /* bases for manpage href */
+ char *base_man2;
char *base_includes; /* base for include href */
char *style; /* style-sheet URI */
struct tag *metaf; /* current open font scope */
diff --git a/mandoc.1 b/mandoc.1
index 4cdfe150..afea0a1b 100644
--- a/mandoc.1
+++ b/mandoc.1
@@ -345,7 +345,7 @@ Instances of
are replaced with the include filename.
The default is not to present a
hyperlink.
-.It Cm man Ns = Ns Ar fmt
+.It Cm man Ns = Ns Ar fmt Ns Op ; Ns Ar fmt
The string
.Ar fmt ,
for example,
@@ -361,6 +361,10 @@ are replaced with the linked manual's name and section, respectively.
If no section is included, section 1 is assumed.
The default is not to
present a hyperlink.
+If two formats are given and a file
+.Ar %N.%S
+exists in the current directory, the first format is used;
+otherwise, the second format is used.
.It Cm style Ns = Ns Ar style.css
The file
.Ar style.css
diff --git a/mdoc_html.c b/mdoc_html.c
index 7974605e..c66160df 100644
--- a/mdoc_html.c
+++ b/mdoc_html.c
@@ -611,7 +611,7 @@ mdoc_xr_pre(MDOC_ARGS)
if (NULL == n->child)
return 0;
- if (h->base_man)
+ if (h->base_man1)
print_otag(h, TAG_A, "cThM", "Xr",
n->child->string, n->child->next == NULL ?
NULL : n->child->next->string);