source@mandoc.bsd.lv
 help / color / mirror / Atom feed
* mandoc: Append .html suffix to temporary files enabling browsers to
@ 2021-03-30 17:17 schwarze
  0 siblings, 0 replies; only message in thread
From: schwarze @ 2021-03-30 17:17 UTC (permalink / raw)
  To: source

Log Message:
-----------
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.

Modified Files:
--------------
    mandoc:
        main.c
        term_tag.c
        term_tag.h

Revision Data
-------------
Index: term_tag.h
===================================================================
RCS file: /home/cvs/mandoc/mandoc/term_tag.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -Lterm_tag.h -Lterm_tag.h -u -p -r1.3 -r1.4
--- term_tag.h
+++ term_tag.h
@@ -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);
Index: main.c
===================================================================
RCS file: /home/cvs/mandoc/mandoc/main.c,v
retrieving revision 1.353
retrieving revision 1.354
diff -Lmain.c -Lmain.c -u -p -r1.353 -r1.354
--- main.c
+++ main.c
@@ -846,6 +846,7 @@ process_onefile(struct mparse *mp, struc
 	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 ||
Index: term_tag.c
===================================================================
RCS file: /home/cvs/mandoc/mandoc/term_tag.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -Lterm_tag.c -Lterm_tag.c -u -p -r1.5 -r1.6
--- term_tag.c
+++ term_tag.c
@@ -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, c
 	/* 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;
--
 To unsubscribe send an email to source+unsubscribe@mandoc.bsd.lv


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-03-30 17:17 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-30 17:17 mandoc: Append .html suffix to temporary files enabling browsers to schwarze

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).