diff options
author | Ingo Schwarze <schwarze@openbsd.org> | 2018-12-30 00:49:54 +0000 |
---|---|---|
committer | Ingo Schwarze <schwarze@openbsd.org> | 2018-12-30 00:49:54 +0000 |
commit | 0cd2663fe9e76ba0ad357a566dc3416eccab70e5 (patch) | |
tree | bdd4ce48b3029984474e5d53e3fdbca949b317c9 /mandocdb.c | |
parent | cf618db57fee5de46ee351c83eeb03292758f546 (diff) | |
download | mandoc-0cd2663fe9e76ba0ad357a566dc3416eccab70e5.tar.gz |
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 'mandocdb.c')
-rw-r--r-- | mandocdb.c | 44 |
1 files changed, 20 insertions, 24 deletions
@@ -347,6 +347,7 @@ mandocdb(int argc, char *argv[]) goto usage; \ } while (/*CONSTCOND*/0) + mparse_options = MPARSE_VALIDATE; path_arg = NULL; op = OP_DEFAULT; @@ -1115,8 +1116,7 @@ mpages_merge(struct dba *dba, struct mparse *mp) { struct mpage *mpage, *mpage_dest; struct mlink *mlink, *mlink_dest; - struct roff_man *man; - char *sodest; + struct roff_meta *meta; char *cp; int fd; @@ -1129,8 +1129,7 @@ mpages_merge(struct dba *dba, struct mparse *mp) mandoc_ohash_init(&names, 4, offsetof(struct str, key)); mandoc_ohash_init(&strings, 6, offsetof(struct str, key)); mparse_reset(mp); - man = NULL; - sodest = NULL; + meta = NULL; if ((fd = mparse_open(mp, mlink->file)) == -1) { say(mlink->file, "&open"); @@ -1145,14 +1144,14 @@ mpages_merge(struct dba *dba, struct mparse *mp) mparse_readfd(mp, fd, mlink->file); close(fd); fd = -1; - mparse_result(mp, &man, &sodest); + meta = mparse_result(mp); } - if (sodest != NULL) { + if (meta != NULL && meta->sodest != NULL) { mlink_dest = ohash_find(&mlinks, - ohash_qlookup(&mlinks, sodest)); + ohash_qlookup(&mlinks, meta->sodest)); if (mlink_dest == NULL) { - mandoc_asprintf(&cp, "%s.gz", sodest); + mandoc_asprintf(&cp, "%s.gz", meta->sodest); mlink_dest = ohash_find(&mlinks, ohash_qlookup(&mlinks, cp)); free(cp); @@ -1189,39 +1188,36 @@ mpages_merge(struct dba *dba, struct mparse *mp) mpage->mlinks = NULL; } goto nextpage; - } else if (man != NULL && man->macroset == MACROSET_MDOC) { - mdoc_validate(man); + } else if (meta != NULL && meta->macroset == MACROSET_MDOC) { mpage->form = FORM_SRC; - mpage->sec = man->meta.msec; + mpage->sec = meta->msec; mpage->sec = mandoc_strdup( mpage->sec == NULL ? "" : mpage->sec); - mpage->arch = man->meta.arch; + mpage->arch = meta->arch; mpage->arch = mandoc_strdup( mpage->arch == NULL ? "" : mpage->arch); - mpage->title = mandoc_strdup(man->meta.title); - } else if (man != NULL && man->macroset == MACROSET_MAN) { - man_validate(man); - if (*man->meta.msec != '\0' || - *man->meta.title != '\0') { + mpage->title = mandoc_strdup(meta->title); + } else if (meta != NULL && meta->macroset == MACROSET_MAN) { + if (*meta->msec != '\0' || *meta->title != '\0') { mpage->form = FORM_SRC; - mpage->sec = mandoc_strdup(man->meta.msec); + mpage->sec = mandoc_strdup(meta->msec); mpage->arch = mandoc_strdup(mlink->arch); - mpage->title = mandoc_strdup(man->meta.title); + mpage->title = mandoc_strdup(meta->title); } else - man = NULL; + meta = NULL; } assert(mpage->desc == NULL); - if (man == NULL) { + if (meta == NULL) { mpage->form = FORM_CAT; mpage->sec = mandoc_strdup(mlink->dsec); mpage->arch = mandoc_strdup(mlink->arch); mpage->title = mandoc_strdup(mlink->name); parse_cat(mpage, fd); - } else if (man->macroset == MACROSET_MDOC) - parse_mdoc(mpage, &man->meta, man->first); + } else if (meta->macroset == MACROSET_MDOC) + parse_mdoc(mpage, meta, meta->first); else - parse_man(mpage, &man->meta, man->first); + parse_man(mpage, meta, meta->first); if (mpage->desc == NULL) { mpage->desc = mandoc_strdup(mlink->name); if (warnings) |