From 68183e3516ca405d803db497157cd8246b9b8bad Mon Sep 17 00:00:00 2001 From: Ingo Schwarze Date: Sun, 30 Dec 2018 00:49:54 +0000 Subject: 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. --- mandocdb.c | 46 +++++++++++++++++++++------------------------- 1 file changed, 21 insertions(+), 25 deletions(-) (limited to 'mandocdb.c') diff --git a/mandocdb.c b/mandocdb.c index 497e2fef..222350c9 100644 --- a/mandocdb.c +++ b/mandocdb.c @@ -1,4 +1,4 @@ -/* $Id: mandocdb.c,v 1.261 2018/12/14 01:18:26 schwarze Exp $ */ +/* $Id: mandocdb.c,v 1.262 2018/12/30 00:49:55 schwarze Exp $ */ /* * Copyright (c) 2011, 2012 Kristaps Dzonsons * Copyright (c) 2011-2018 Ingo Schwarze @@ -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) -- cgit v1.2.3-56-ge451