diff options
author | Ingo Schwarze <schwarze@openbsd.org> | 2021-03-30 17:16:55 +0000 |
---|---|---|
committer | Ingo Schwarze <schwarze@openbsd.org> | 2021-03-30 17:16:55 +0000 |
commit | 6e220064abb2f2f7e5756999097a6db9c2064787 (patch) | |
tree | e10e613171ee6a84423ddbe80fd01bef27730806 | |
parent | 097ebd78c83b64e46747401071cc01d772a3d1cd (diff) | |
download | mandoc-6e220064abb2f2f7e5756999097a6db9c2064787.tar.gz mandoc-6e220064abb2f2f7e5756999097a6db9c2064787.tar.zst mandoc-6e220064abb2f2f7e5756999097a6db9c2064787.zip |
Append .html suffix to temporary files enabling browsers to recognise it.
Occasionally one might read a manual page in a webbrowser, e.g.
"MANPAGER=firefox man -T html jq", however temporary files created for
pagers lack file extensions and most web browsers are unable to detect a
file's content without it.
Special case mandoc(1)'s HTML output format by appending the ".html" suffix
to file names such that browsers will actually render HTML as such instead
of showing it as plain text.
Idea and patch from kn@, with minor help from me.
-rw-r--r-- | main.c | 3 | ||||
-rw-r--r-- | term_tag.c | 11 | ||||
-rw-r--r-- | term_tag.h | 4 |
3 files changed, 10 insertions, 8 deletions
@@ -1,4 +1,4 @@ -/* $Id: main.c,v 1.353 2020/08/07 20:56:55 schwarze Exp $ */ +/* $Id: main.c,v 1.354 2021/03/30 17:16:55 schwarze Exp $ */ /* * Copyright (c) 2010-2012, 2014-2020 Ingo Schwarze <schwarze@openbsd.org> * Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv> @@ -846,6 +846,7 @@ process_onefile(struct mparse *mp, struct manpage *resp, int startdir, if (outst->use_pager) { outst->use_pager = 0; outst->tag_files = term_tag_init(conf->output.outfilename, + outst->outtype == OUTT_HTML ? ".html" : "", conf->output.tagfilename); #if HAVE_PLEDGE if ((conf->output.outfilename != NULL || @@ -1,4 +1,4 @@ -/* $Id: term_tag.c,v 1.5 2020/07/21 15:10:01 schwarze Exp $ */ +/* $Id: term_tag.c,v 1.6 2021/03/30 17:16:55 schwarze Exp $ */ /* * Copyright (c) 2015,2016,2018,2019,2020 Ingo Schwarze <schwarze@openbsd.org> * @@ -47,7 +47,8 @@ static struct tag_files tag_files; * but for simplicity, create it anyway. */ struct tag_files * -term_tag_init(const char *outfilename, const char *tagfilename) +term_tag_init(const char *outfilename, const char *suffix, + const char *tagfilename) { struct sigaction sa; int ofd; /* In /tmp/, dup(2)ed to stdout. */ @@ -85,9 +86,9 @@ term_tag_init(const char *outfilename, const char *tagfilename) /* Create both temporary output files. */ if (outfilename == NULL) { - (void)strlcpy(tag_files.ofn, "/tmp/man.XXXXXXXXXX", - sizeof(tag_files.ofn)); - if ((ofd = mkstemp(tag_files.ofn)) == -1) { + (void)snprintf(tag_files.ofn, sizeof(tag_files.ofn), + "/tmp/man.XXXXXXXXXX%s", suffix); + if ((ofd = mkstemps(tag_files.ofn, strlen(suffix))) == -1) { mandoc_msg(MANDOCERR_MKSTEMP, 0, 0, "%s: %s", tag_files.ofn, strerror(errno)); goto fail; @@ -1,4 +1,4 @@ -/* $Id: term_tag.h,v 1.3 2020/07/21 15:10:01 schwarze Exp $ */ +/* $Id: term_tag.h,v 1.4 2021/03/30 17:16:55 schwarze Exp $ */ /* * Copyright (c) 2015, 2018, 2019, 2020 Ingo Schwarze <schwarze@openbsd.org> * @@ -28,7 +28,7 @@ struct tag_files { }; -struct tag_files *term_tag_init(const char *, const char *); +struct tag_files *term_tag_init(const char *, const char *, const char *); void term_tag_write(struct roff_node *, size_t); int term_tag_close(void); void term_tag_unlink(void); |