diff options
author | 2020-03-13 00:31:04 +0000 | |
---|---|---|
committer | 2020-03-13 00:31:04 +0000 | |
commit | 0ac7e6ecda86f609ac723da7cedfc4880e082fdd (patch) | |
tree | 145820e83a04749363dee9d32390189b6596702c /usr.bin/mandoc/main.c | |
parent | Add speciulation barrier after the last remaining naked ERET instruction. (diff) | |
download | wireguard-openbsd-0ac7e6ecda86f609ac723da7cedfc4880e082fdd.tar.xz wireguard-openbsd-0ac7e6ecda86f609ac723da7cedfc4880e082fdd.zip |
Split tagging into a validation part including prioritization
in tag.{h,c} and {mdoc,man}_validate.c
and into a formatting part including command line argument checking
in term_tag.{h,c}, html.c, and {mdoc|man}_{term|html}.c.
Immediate functional benefits include:
* Improved prioritization of automatic tags for .Em and .Sy.
* Avoiding bogus automatic tags when .Em, .Fn, or .Sy are explicitly tagged.
* Explicit tagging of .Er and .Fl now works in HTML output.
* Automatic tagging of .IP and .TP now works in HTML output.
But mainly, this patch provides clean earth to build further improvements on.
Technical changes:
* Main program: Write a tag file for ASCII and UTF-8 output only.
* All formatters: There is no more need to delay writing the tags.
* mdoc(7)+man(7) formatters: No more need for elaborate syntax tree inspection.
* HTML formatter: If available, use the "string" attribute as the tag.
* HTML formatter: New function to write permalinks, to reduce code duplication.
Style cleanup in the vicinity while here:
* mdoc(7) terminal formatter: To set up bold font for children,
defer to termp_bold_pre() rather than calling term_fontpush() manually.
* mdoc(7) terminal formatter: Garbage collect some duplicate functions.
* mdoc(7) HTML formatter: Unify <code> handling, delete redundant functions.
* Where possible, use switch statements rather than if cascades.
* Get rid of some more Yoda notation.
The necessity for such changes was first discussed with kn@, but i didn't
bother him with a request to review the resulting -673/+782 line patch.
Diffstat (limited to 'usr.bin/mandoc/main.c')
-rw-r--r-- | usr.bin/mandoc/main.c | 38 |
1 files changed, 19 insertions, 19 deletions
diff --git a/usr.bin/mandoc/main.c b/usr.bin/mandoc/main.c index 5c72f60ce7b..8931df51ea1 100644 --- a/usr.bin/mandoc/main.c +++ b/usr.bin/mandoc/main.c @@ -1,7 +1,7 @@ -/* $OpenBSD: main.c,v 1.247 2020/02/24 21:15:05 schwarze Exp $ */ +/* $OpenBSD: main.c,v 1.248 2020/03/13 00:31:04 schwarze Exp $ */ /* - * Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2010-2012, 2014-2020 Ingo Schwarze <schwarze@openbsd.org> + * Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2010 Joerg Sonnenberger <joerg@netbsd.org> * * Permission to use, copy, modify, and distribute this software for any @@ -15,8 +15,9 @@ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * Main program for mandoc(1), man(1), apropos(1), whatis(1), and help(1). */ - #include <sys/types.h> #include <sys/ioctl.h> #include <sys/param.h> /* MACHINE */ @@ -46,7 +47,7 @@ #include "mdoc.h" #include "man.h" #include "mandoc_parse.h" -#include "tag.h" +#include "term_tag.h" #include "main.h" #include "manconf.h" #include "mansearch.h" @@ -577,7 +578,6 @@ main(int argc, char *argv[]) * readable: Maybe it won't be needed after all. */ startdir = open(".", O_RDONLY | O_DIRECTORY); - for (i = 0; i < ressz; i++) { process_onefile(mp, res + i, startdir, &outst, &conf); if (outst.wstop && mandoc_msg_getrc() != MANDOCLEVEL_OK) @@ -587,7 +587,6 @@ main(int argc, char *argv[]) (void)fchdir(startdir); close(startdir); } - if (outst.outdata != NULL) { switch (outst.outtype) { case OUTT_HTML: @@ -596,6 +595,7 @@ main(int argc, char *argv[]) case OUTT_UTF8: case OUTT_LOCALE: case OUTT_ASCII: + term_tag_finish(); ascii_free(outst.outdata); break; case OUTT_PDF: @@ -617,9 +617,8 @@ out: if (outst.tag_files != NULL) { fclose(stdout); - tag_write(); run_pager(outst.tag_files); - tag_unlink(); + term_tag_unlink(); } else if (outst.had_output && outst.outtype != OUTT_LINT) mandoc_msg_summary(); @@ -810,15 +809,16 @@ process_onefile(struct mparse *mp, struct manpage *resp, int startdir, } else fd = STDIN_FILENO; - if (outst->use_pager) { - outst->use_pager = 0; - outst->tag_files = tag_init(conf->output.tag); - } - - if (outst->had_output && outst->outtype <= OUTT_UTF8) { - if (outst->outdata == NULL) - outdata_alloc(outst, &conf->output); - terminal_sepline(outst->outdata); + if (outst->outtype <= OUTT_UTF8) { + if (outst->use_pager) { + outst->use_pager = 0; + outst->tag_files = term_tag_init(conf->output.tag); + } + if (outst->had_output) { + if (outst->outdata == NULL) + outdata_alloc(outst, &conf->output); + terminal_sepline(outst->outdata); + } } if (resp->form == FORM_SRC) @@ -832,7 +832,7 @@ process_onefile(struct mparse *mp, struct manpage *resp, int startdir, if (outst->tag_files != NULL) { mandoc_msg(MANDOCERR_WRITE, 0, 0, "%s: %s", outst->tag_files->ofn, strerror(errno)); - tag_unlink(); + term_tag_unlink(); outst->tag_files = NULL; } else mandoc_msg(MANDOCERR_WRITE, 0, 0, "%s", @@ -1251,7 +1251,7 @@ spawn_pager(struct tag_files *tag_files) _exit(mandoc_msg_getrc()); } close(tag_files->ofd); - assert(tag_files->tfd == -1); + assert(tag_files->tfs == NULL); /* Do not start the pager before controlling the terminal. */ |