aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/main.c
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@openbsd.org>2018-12-30 00:49:54 +0000
committerIngo Schwarze <schwarze@openbsd.org>2018-12-30 00:49:54 +0000
commit68183e3516ca405d803db497157cd8246b9b8bad (patch)
treed88411ec1f7435c594c8afcfc4b99cca3a0d5bdf /main.c
parentb4f47224dd1036f4d89f641195a444eea00a55e8 (diff)
downloadmandoc-68183e3516ca405d803db497157cd8246b9b8bad.tar.gz
mandoc-68183e3516ca405d803db497157cd8246b9b8bad.tar.zst
mandoc-68183e3516ca405d803db497157cd8246b9b8bad.zip
Cleanup, no functional change:
The struct roff_man used to be a bad mixture of internal parser state and public parsing results. Move the public results to the parsing result struct roff_meta, which is already public. Move the rest of struct roff_man to the parser-internal header roff_int.h. Since the validators need access to the parser state, call them from the top level parser during mparse_result() rather than from the main programs, also reducing code duplication. This keeps parser internal state out of thee main programs (five in mandoc portable) and out of eight formatters.
Diffstat (limited to 'main.c')
-rw-r--r--main.c37
1 files changed, 17 insertions, 20 deletions
diff --git a/main.c b/main.c
index 150e808a..ad9ebf97 100644
--- a/main.c
+++ b/main.c
@@ -1,4 +1,4 @@
-/* $Id: main.c,v 1.314 2018/12/20 21:30:32 schwarze Exp $ */
+/* $Id: main.c,v 1.315 2018/12/30 00:49:55 schwarze Exp $ */
/*
* Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010-2012, 2014-2018 Ingo Schwarze <schwarze@openbsd.org>
@@ -308,6 +308,9 @@ main(int argc, char *argv[])
}
}
+ if (curp.outtype != OUTT_TREE || !curp.outopts->noval)
+ options |= MPARSE_VALIDATE;
+
if (outmode == OUTMODE_FLN ||
outmode == OUTMODE_LST ||
!isatty(STDOUT_FILENO))
@@ -801,7 +804,7 @@ fs_search(const struct mansearch *cfg, const struct manpaths *paths,
static void
parse(struct curparse *curp, int fd, const char *file)
{
- struct roff_man *man;
+ struct roff_meta *meta;
/* Begin by parsing the file itself. */
@@ -823,49 +826,43 @@ parse(struct curparse *curp, int fd, const char *file)
if (curp->outdata == NULL)
outdata_alloc(curp);
- mparse_result(curp->mp, &man, NULL);
+ mandoc_xr_reset();
+ meta = mparse_result(curp->mp);
/* Execute the out device, if it exists. */
- if (man == NULL)
- return;
- mandoc_xr_reset();
- if (man->macroset == MACROSET_MDOC) {
- if (curp->outtype != OUTT_TREE || !curp->outopts->noval)
- mdoc_validate(man);
+ if (meta->macroset == MACROSET_MDOC) {
switch (curp->outtype) {
case OUTT_HTML:
- html_mdoc(curp->outdata, man);
+ html_mdoc(curp->outdata, meta);
break;
case OUTT_TREE:
- tree_mdoc(curp->outdata, man);
+ tree_mdoc(curp->outdata, meta);
break;
case OUTT_MAN:
- man_mdoc(curp->outdata, man);
+ man_mdoc(curp->outdata, meta);
break;
case OUTT_PDF:
case OUTT_ASCII:
case OUTT_UTF8:
case OUTT_LOCALE:
case OUTT_PS:
- terminal_mdoc(curp->outdata, man);
+ terminal_mdoc(curp->outdata, meta);
break;
case OUTT_MARKDOWN:
- markdown_mdoc(curp->outdata, man);
+ markdown_mdoc(curp->outdata, meta);
break;
default:
break;
}
}
- if (man->macroset == MACROSET_MAN) {
- if (curp->outtype != OUTT_TREE || !curp->outopts->noval)
- man_validate(man);
+ if (meta->macroset == MACROSET_MAN) {
switch (curp->outtype) {
case OUTT_HTML:
- html_man(curp->outdata, man);
+ html_man(curp->outdata, meta);
break;
case OUTT_TREE:
- tree_man(curp->outdata, man);
+ tree_man(curp->outdata, meta);
break;
case OUTT_MAN:
mparse_copy(curp->mp);
@@ -875,7 +872,7 @@ parse(struct curparse *curp, int fd, const char *file)
case OUTT_UTF8:
case OUTT_LOCALE:
case OUTT_PS:
- terminal_man(curp->outdata, man);
+ terminal_man(curp->outdata, meta);
break;
default:
break;