diff options
author | Ingo Schwarze <schwarze@openbsd.org> | 2018-12-31 04:55:46 +0000 |
---|---|---|
committer | Ingo Schwarze <schwarze@openbsd.org> | 2018-12-31 04:55:46 +0000 |
commit | c0cea6817b9d23d8e5e4a752fc1dff8dfb604cdc (patch) | |
tree | 8583999131b10c7f020825880396b50813e04620 | |
parent | 0cd2663fe9e76ba0ad357a566dc3416eccab70e5 (diff) | |
download | mandoc-c0cea6817b9d23d8e5e4a752fc1dff8dfb604cdc.tar.gz |
Cleanup, minus 15 LOC, no functional change:
Simplify the way the man(7) and mdoc(7) validators are called.
Reset the parser state with a common function before calling them.
There is no need to again reset the parser state afterwards,
the parsers are no longer used after validation.
This allows getting rid of man_node_validate() and mdoc_node_validate()
as separate functions.
-rw-r--r-- | libman.h | 1 | ||||
-rw-r--r-- | libmdoc.h | 2 | ||||
-rw-r--r-- | man.c | 9 | ||||
-rw-r--r-- | man_macro.c | 2 | ||||
-rw-r--r-- | man_validate.c | 4 | ||||
-rw-r--r-- | mdoc.c | 9 | ||||
-rw-r--r-- | mdoc_macro.c | 1 | ||||
-rw-r--r-- | mdoc_state.c | 8 | ||||
-rw-r--r-- | mdoc_validate.c | 4 | ||||
-rw-r--r-- | read.c | 1 | ||||
-rw-r--r-- | roff.c | 17 | ||||
-rw-r--r-- | roff_int.h | 1 |
12 files changed, 18 insertions, 41 deletions
@@ -39,6 +39,5 @@ struct man_macro { const struct man_macro *man_macro(enum roff_tok); void man_descope(struct roff_man *, int, int, char *); -void man_node_validate(struct roff_man *); void man_state(struct roff_man *, struct roff_node *); void man_unscope(struct roff_man *, const struct roff_node *); @@ -74,9 +74,7 @@ void mdoc_tail_alloc(struct roff_man *, int, int, enum roff_tok); struct roff_node *mdoc_endbody_alloc(struct roff_man *, int, int, enum roff_tok, struct roff_node *); -void mdoc_node_validate(struct roff_man *); void mdoc_state(struct roff_man *, struct roff_node *); -void mdoc_state_reset(struct roff_man *); const char *mdoc_a2arch(const char *); const char *mdoc_a2att(const char *); const char *mdoc_a2lib(const char *); @@ -367,12 +367,3 @@ man_state(struct roff_man *man, struct roff_node *n) } man->last->flags |= NODE_VALID; } - -void -man_validate(struct roff_man *man) -{ - - man->last = man->meta.first; - man_node_validate(man); - man->flags &= ~MAN_LITERAL; -} diff --git a/man_macro.c b/man_macro.c index 1ec9fc05..d652a431 100644 --- a/man_macro.c +++ b/man_macro.c @@ -445,9 +445,7 @@ in_line_eoln(MACRO_PROT_ARGS) void man_endparse(struct roff_man *man) { - man_unscope(man, man->meta.first); - man->flags &= ~MAN_LITERAL; } static int diff --git a/man_validate.c b/man_validate.c index 277b20ef..fcc28853 100644 --- a/man_validate.c +++ b/man_validate.c @@ -101,7 +101,7 @@ static const v_check man_valids[MAN_MAX - MAN_TH] = { /* Validate the subtree rooted at man->last. */ void -man_node_validate(struct roff_man *man) +man_validate(struct roff_man *man) { struct roff_node *n; const v_check *cp; @@ -128,7 +128,7 @@ man_node_validate(struct roff_man *man) man->last = man->last->child; while (man->last != NULL) { - man_node_validate(man); + man_validate(man); if (man->last == n) man->last = man->last->child; else @@ -428,12 +428,3 @@ mdoc_isdelim(const char *p) return DELIM_NONE; } - -void -mdoc_validate(struct roff_man *mdoc) -{ - - mdoc->last = mdoc->meta.first; - mdoc_node_validate(mdoc); - mdoc_state_reset(mdoc); -} diff --git a/mdoc_macro.c b/mdoc_macro.c index ed0891c8..892fbefe 100644 --- a/mdoc_macro.c +++ b/mdoc_macro.c @@ -234,7 +234,6 @@ mdoc_endparse(struct roff_man *mdoc) /* Rewind to the first. */ rew_last(mdoc, mdoc->meta.first); - mdoc_state_reset(mdoc); } /* diff --git a/mdoc_state.c b/mdoc_state.c index df9fca75..78ce3bcd 100644 --- a/mdoc_state.c +++ b/mdoc_state.c @@ -179,14 +179,6 @@ mdoc_state(struct roff_man *mdoc, struct roff_node *n) (*handler)(mdoc, n); } -void -mdoc_state_reset(struct roff_man *mdoc) -{ - - roff_setreg(mdoc->roff, "nS", 0, '='); - mdoc->flags = 0; -} - static void state_bd(STATE_ARGS) { diff --git a/mdoc_validate.c b/mdoc_validate.c index 29a4da6c..58755a2e 100644 --- a/mdoc_validate.c +++ b/mdoc_validate.c @@ -288,7 +288,7 @@ static const char * const secnames[SEC__MAX] = { /* Validate the subtree rooted at mdoc->last. */ void -mdoc_node_validate(struct roff_man *mdoc) +mdoc_validate(struct roff_man *mdoc) { struct roff_node *n, *np; const v_post *p; @@ -319,7 +319,7 @@ mdoc_node_validate(struct roff_man *mdoc) mdoc->last = mdoc->last->child; while (mdoc->last != NULL) { - mdoc_node_validate(mdoc); + mdoc_validate(mdoc); if (mdoc->last == n) mdoc->last = mdoc->last->child; else @@ -688,6 +688,7 @@ mparse_free(struct mparse *curp) struct roff_meta * mparse_result(struct mparse *curp) { + roff_state_reset(curp->man); if (curp->options & MPARSE_VALIDATE) { if (curp->man->meta.macroset == MACROSET_MDOC) mdoc_validate(curp->man); @@ -819,18 +819,25 @@ roff_man_free1(struct roff_man *man) free(man->meta.sodest); } +void +roff_state_reset(struct roff_man *man) +{ + man->last = man->meta.first; + man->last_es = NULL; + man->flags = 0; + man->lastsec = man->lastnamed = SEC_NONE; + man->next = ROFF_NEXT_CHILD; + roff_setreg(man->roff, "nS", 0, '='); +} + static void roff_man_alloc1(struct roff_man *man) { memset(&man->meta, 0, sizeof(man->meta)); man->meta.first = mandoc_calloc(1, sizeof(*man->meta.first)); man->meta.first->type = ROFFT_ROOT; - man->last = man->meta.first; - man->last_es = NULL; - man->flags = 0; man->meta.macroset = MACROSET_NONE; - man->lastsec = man->lastnamed = SEC_NONE; - man->next = ROFF_NEXT_CHILD; + roff_state_reset(man); } void @@ -80,6 +80,7 @@ struct ohash *roffhash_alloc(enum roff_tok, enum roff_tok); enum roff_tok roffhash_find(struct ohash *, const char *, size_t); void roffhash_free(struct ohash *); +void roff_state_reset(struct roff_man *); void roff_validate(struct roff_man *); /* |