From: kn Date: Fri, 19 Feb 2021 19:49:49 +0000 (+0000) Subject: Append .html suffix to temporary files enabling browsers to recognise it X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=695084ad74cbe521067367c0b777a954195c6778;p=openbsd 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. Input schwarze --- diff --git a/usr.bin/mandoc/main.c b/usr.bin/mandoc/main.c index 52c961d966a..0647c2e585c 100644 --- a/usr.bin/mandoc/main.c +++ b/usr.bin/mandoc/main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: main.c,v 1.255 2020/07/21 15:08:48 schwarze Exp $ */ +/* $OpenBSD: main.c,v 1.256 2021/02/19 19:49:49 kn Exp $ */ /* * Copyright (c) 2010-2012, 2014-2020 Ingo Schwarze * Copyright (c) 2008-2012 Kristaps Dzonsons @@ -824,6 +824,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 ((conf->output.outfilename != NULL || conf->output.tagfilename != NULL) && diff --git a/usr.bin/mandoc/term_tag.c b/usr.bin/mandoc/term_tag.c index 86ad01ed65d..2d44650bc88 100644 --- a/usr.bin/mandoc/term_tag.c +++ b/usr.bin/mandoc/term_tag.c @@ -1,4 +1,4 @@ -/* $OpenBSD: term_tag.c,v 1.5 2020/07/21 15:08:49 schwarze Exp $ */ +/* $OpenBSD: term_tag.c,v 1.6 2021/02/19 19:49:49 kn Exp $ */ /* * Copyright (c) 2015,2016,2018,2019,2020 Ingo Schwarze * @@ -45,7 +45,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. */ @@ -83,9 +84,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; diff --git a/usr.bin/mandoc/term_tag.h b/usr.bin/mandoc/term_tag.h index fc692d7b5ec..8809df2927b 100644 --- a/usr.bin/mandoc/term_tag.h +++ b/usr.bin/mandoc/term_tag.h @@ -1,4 +1,4 @@ -/* $OpenBSD: term_tag.h,v 1.3 2020/07/21 15:08:49 schwarze Exp $ */ +/* $OpenBSD: term_tag.h,v 1.4 2021/02/19 19:49:49 kn Exp $ */ /* * Copyright (c) 2015, 2018, 2019, 2020 Ingo Schwarze * @@ -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);