From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from localhost (fantadrom.bsd.lv [local]) by fantadrom.bsd.lv (OpenSMTPD) with ESMTPA id feefd6a7 for ; Tue, 2 Oct 2018 07:34:07 -0500 (EST) Date: Tue, 2 Oct 2018 07:34:07 -0500 (EST) X-Mailinglist: mandoc-source Reply-To: source@mandoc.bsd.lv MIME-Version: 1.0 From: schwarze@mandoc.bsd.lv To: source@mandoc.bsd.lv Subject: mandoc: Support a second argument to -O man, selecting the format X-Mailer: activitymail 1.26, http://search.cpan.org/dist/activitymail/ Content-Type: text/plain; charset=utf-8 Message-Id: <381bc5ef7fb90a3a@fantadrom.bsd.lv> Log Message: ----------- 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. Modified Files: -------------- mandoc: TODO html.c html.h mandoc.1 mdoc_html.c Revision Data ------------- Index: TODO =================================================================== RCS file: /home/cvs/mandoc/mandoc/TODO,v retrieving revision 1.271 retrieving revision 1.272 diff -LTODO -LTODO -u -p -r1.271 -r1.272 --- TODO +++ 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
Laura Morales 21 Apr 2018 18:10:48 +0200 (Evaluate whether this is really useful and has no adverse Index: mdoc_html.c =================================================================== RCS file: /home/cvs/mandoc/mandoc/mdoc_html.c,v retrieving revision 1.311 retrieving revision 1.312 diff -Lmdoc_html.c -Lmdoc_html.c -u -p -r1.311 -r1.312 --- mdoc_html.c +++ 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); Index: mandoc.1 =================================================================== RCS file: /home/cvs/mandoc/mandoc/mandoc.1,v retrieving revision 1.228 retrieving revision 1.229 diff -Lmandoc.1 -Lmandoc.1 -u -p -r1.228 -r1.229 --- mandoc.1 +++ 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 na 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 Index: html.h =================================================================== RCS file: /home/cvs/mandoc/mandoc/html.h,v retrieving revision 1.92 retrieving revision 1.93 diff -Lhtml.h -Lhtml.h -u -p -r1.92 -r1.93 --- html.h +++ 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 */ Index: html.c =================================================================== RCS file: /home/cvs/mandoc/mandoc/html.c,v retrieving revision 1.239 retrieving revision 1.240 diff -Lhtml.c -Lhtml.c -u -p -r1.239 -r1.240 --- html.c +++ html.c @@ -18,6 +18,7 @@ #include "config.h" #include +#include #include #include @@ -128,7 +129,10 @@ html_alloc(const struct manoutput *outop 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 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') { -- To unsubscribe send an email to source+unsubscribe@mandoc.bsd.lv