summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@cvs.openbsd.org>2018-10-02 12:32:56 +0000
committerIngo Schwarze <schwarze@cvs.openbsd.org>2018-10-02 12:32:56 +0000
commitf4278ea97856210fca6852a217027b980dd8f3c3 (patch)
tree560b4ed6b18007ad863561cc8e03d3e6631538e2
parent53efc0197c71f0837a7acc96ed7613b126c73fc8 (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.
-rw-r--r--usr.bin/mandoc/html.c22
-rw-r--r--usr.bin/mandoc/html.h5
-rw-r--r--usr.bin/mandoc/mandoc.110
-rw-r--r--usr.bin/mandoc/mdoc_html.c4
4 files changed, 31 insertions, 10 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') {
diff --git a/usr.bin/mandoc/html.h b/usr.bin/mandoc/html.h
index 750c4b7e095..700eca2bc18 100644
--- a/usr.bin/mandoc/html.h
+++ b/usr.bin/mandoc/html.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: html.h,v 1.54 2018/06/25 16:54:55 schwarze Exp $ */
+/* $OpenBSD: html.h,v 1.55 2018/10/02 12:32:55 schwarze Exp $ */
/*
* Copyright (c) 2008-2011, 2014 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2017, 2018 Ingo Schwarze <schwarze@openbsd.org>
@@ -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/usr.bin/mandoc/mandoc.1 b/usr.bin/mandoc/mandoc.1
index aa19c49d634..02d2a00dd6a 100644
--- a/usr.bin/mandoc/mandoc.1
+++ b/usr.bin/mandoc/mandoc.1
@@ -1,4 +1,4 @@
-.\" $OpenBSD: mandoc.1,v 1.152 2018/08/25 16:43:52 schwarze Exp $
+.\" $OpenBSD: mandoc.1,v 1.153 2018/10/02 12:32:55 schwarze Exp $
.\"
.\" Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
.\" Copyright (c) 2012, 2014-2018 Ingo Schwarze <schwarze@openbsd.org>
@@ -15,7 +15,7 @@
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
-.Dd $Mdocdate: August 25 2018 $
+.Dd $Mdocdate: October 2 2018 $
.Dt MANDOC 1
.Os
.Sh NAME
@@ -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/usr.bin/mandoc/mdoc_html.c b/usr.bin/mandoc/mdoc_html.c
index eab4bd60bf7..7af29f7f2fa 100644
--- a/usr.bin/mandoc/mdoc_html.c
+++ b/usr.bin/mandoc/mdoc_html.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mdoc_html.c,v 1.186 2018/08/17 20:31:52 schwarze Exp $ */
+/* $OpenBSD: mdoc_html.c,v 1.187 2018/10/02 12:32:55 schwarze Exp $ */
/*
* Copyright (c) 2008-2011, 2014 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2014,2015,2016,2017,2018 Ingo Schwarze <schwarze@openbsd.org>
@@ -609,7 +609,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);