On Wed, Jan 27, 2021 at 01:41:52AM +0100, Ingo Schwarze wrote: > It's maybe just a bikeshed, but could you put the logic selecting > the filename extension (either "" or ".html") at the place where > term_tag_init() is called? That (main.c) is the module where the OUTT_ > constants are defined, so it's the natural place to make decisions based > on them. Then just pass a third const char * into term_tag_init(). Sounds good.
> Or do you see any downside that approach might have? No. > *If* people ever request the same for PDF, it makes adding that even > easier. > > Also, maybe put the new argument in the middle position because it is > only related to the first argument and not to the second. > > Finally and KNFly, please refrain from using function calls as > variable initializers. Thanks, how about this? Index: main.c =================================================================== RCS file: /cvs/src/usr.bin/mandoc/main.c,v retrieving revision 1.255 diff -u -p -r1.255 main.c --- main.c 21 Jul 2020 15:08:48 -0000 1.255 +++ main.c 27 Jan 2021 09:44:07 -0000 @@ -824,6 +824,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 ((conf->output.outfilename != NULL || conf->output.tagfilename != NULL) && Index: term_tag.c =================================================================== RCS file: /cvs/src/usr.bin/mandoc/term_tag.c,v retrieving revision 1.5 diff -u -p -r1.5 term_tag.c --- term_tag.c 21 Jul 2020 15:08:49 -0000 1.5 +++ term_tag.c 27 Jan 2021 09:44:06 -0000 @@ -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, 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; Index: term_tag.h =================================================================== RCS file: /cvs/src/usr.bin/mandoc/term_tag.h,v retrieving revision 1.3 diff -u -p -r1.3 term_tag.h --- term_tag.h 21 Jul 2020 15:08:49 -0000 1.3 +++ term_tag.h 27 Jan 2021 09:36:10 -0000 @@ -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);