diff options
author | 2014-11-28 01:05:40 +0000 | |
---|---|---|
committer | 2014-11-28 01:05:40 +0000 | |
commit | 98b8f00a0df683df7281eb95093c78a6dd10368f (patch) | |
tree | be03a2ff94b1ebba3f4a3eaeee36d9957df2f5d0 /usr.bin/mandoc/mdoc_macro.c | |
parent | Downgrade .Bd -file from FATAL to ERROR. (diff) | |
download | wireguard-openbsd-98b8f00a0df683df7281eb95093c78a6dd10368f.tar.xz wireguard-openbsd-98b8f00a0df683df7281eb95093c78a6dd10368f.zip |
Simplify code by making mdoc validation handlers void.
No functional change, minus 90 lines of code.
Diffstat (limited to 'usr.bin/mandoc/mdoc_macro.c')
-rw-r--r-- | usr.bin/mandoc/mdoc_macro.c | 98 |
1 files changed, 45 insertions, 53 deletions
diff --git a/usr.bin/mandoc/mdoc_macro.c b/usr.bin/mandoc/mdoc_macro.c index fd758782a98..129424458ba 100644 --- a/usr.bin/mandoc/mdoc_macro.c +++ b/usr.bin/mandoc/mdoc_macro.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mdoc_macro.c,v 1.104 2014/11/27 22:27:40 schwarze Exp $ */ +/* $OpenBSD: mdoc_macro.c,v 1.105 2014/11/28 01:05:40 schwarze Exp $ */ /* * Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2010, 2012, 2013, 2014 Ingo Schwarze <schwarze@openbsd.org> @@ -60,9 +60,8 @@ static int phrase(struct mdoc *, int, int, char *); static enum mdoct rew_alt(enum mdoct); static enum rew rew_dohalt(enum mdoct, enum mdoc_type, const struct mdoc_node *); -static int rew_elem(struct mdoc *, enum mdoct); -static int rew_last(struct mdoc *, - const struct mdoc_node *); +static void rew_elem(struct mdoc *, enum mdoct); +static void rew_last(struct mdoc *, const struct mdoc_node *); static int rew_sub(enum mdoc_type, struct mdoc *, enum mdoct, int, int); @@ -236,7 +235,8 @@ mdoc_macroend(struct mdoc *mdoc) /* Rewind to the first. */ - return(rew_last(mdoc, mdoc->first)); + rew_last(mdoc, mdoc->first); + return(1); } /* @@ -266,15 +266,13 @@ lookup_raw(const char *p) return(MDOC_MAX); } -static int +static void rew_last(struct mdoc *mdoc, const struct mdoc_node *to) { struct mdoc_node *n, *np; assert(to); mdoc->next = MDOC_NEXT_SIBLING; - - while (mdoc->last != to) { /* * Save the parent here, because we may delete the @@ -283,15 +281,13 @@ rew_last(struct mdoc *mdoc, const struct mdoc_node *to) * out to be lost. */ np = mdoc->last->parent; - if ( ! mdoc_valid_post(mdoc)) - return(0); + mdoc_valid_post(mdoc); n = mdoc->last; mdoc->last = np; assert(mdoc->last); mdoc->last->last = n; } - - return(mdoc_valid_post(mdoc)); + mdoc_valid_post(mdoc); } /* @@ -453,7 +449,7 @@ rew_dohalt(enum mdoct tok, enum mdoc_type type, REWIND_FORCE : REWIND_LATER); } -static int +static void rew_elem(struct mdoc *mdoc, enum mdoct tok) { struct mdoc_node *n; @@ -463,8 +459,7 @@ rew_elem(struct mdoc *mdoc, enum mdoct tok) n = n->parent; assert(MDOC_ELEM == n->type); assert(tok == n->tok); - - return(rew_last(mdoc, n)); + rew_last(mdoc, n); } /* @@ -585,16 +580,14 @@ rew_sub(enum mdoc_type t, struct mdoc *mdoc, } assert(n); - if ( ! rew_last(mdoc, n)) - return(0); + rew_last(mdoc, n); /* * The current block extends an enclosing block. * Now that the current block ends, close the enclosing block, too. */ while (NULL != (n = n->pending)) { - if ( ! rew_last(mdoc, n)) - return(0); + rew_last(mdoc, n); if (MDOC_HEAD == n->type && ! mdoc_body_alloc(mdoc, n->line, n->pos, n->tok)) return(0); @@ -799,8 +792,7 @@ blk_exp_close(MACRO_PROT_ARGS) if ( ! mdoc_elem_alloc(mdoc, line, ppos, MDOC_br, NULL)) return(0); - if ( ! rew_elem(mdoc, MDOC_br)) - return(0); + rew_elem(mdoc, MDOC_br); } else if ( ! mdoc_tail_alloc(mdoc, line, ppos, atok)) return(0); } @@ -810,8 +802,9 @@ blk_exp_close(MACRO_PROT_ARGS) lastarg = *pos; if (j == maxargs && ! flushed) { - if ( ! (endbody != NULL ? rew_last(mdoc, endbody) : - rew_sub(MDOC_BLOCK, mdoc, tok, line, ppos))) + if (endbody != NULL) + rew_last(mdoc, endbody); + else if ( ! rew_sub(MDOC_BLOCK, mdoc, tok, line, ppos)) return(0); flushed = 1; } @@ -835,8 +828,9 @@ blk_exp_close(MACRO_PROT_ARGS) } if ( ! flushed) { - if ( ! (endbody != NULL ? rew_last(mdoc, endbody) : - rew_sub(MDOC_BLOCK, mdoc, tok, line, ppos))) + if (endbody != NULL) + rew_last(mdoc, endbody); + else if ( ! rew_sub(MDOC_BLOCK, mdoc, tok, line, ppos)) return(0); flushed = 1; } @@ -848,9 +842,12 @@ blk_exp_close(MACRO_PROT_ARGS) break; } - if ( ! flushed && ! (endbody != NULL ? rew_last(mdoc, endbody) : - rew_sub(MDOC_BLOCK, mdoc, tok, line, ppos))) - return(0); + if ( ! flushed) { + if (endbody != NULL) + rew_last(mdoc, endbody); + else if ( ! rew_sub(MDOC_BLOCK, mdoc, tok, line, ppos)) + return(0); + } if ( ! nl) return(1); @@ -957,14 +954,13 @@ in_line(MACRO_PROT_ARGS) */ if (MDOC_MAX != ntok) { - if (scope && ! rew_elem(mdoc, tok)) - return(0); + if (scope) + rew_elem(mdoc, tok); if (nc && 0 == cnt) { if ( ! mdoc_elem_alloc(mdoc, line, ppos, tok, arg)) return(0); - if ( ! rew_last(mdoc, mdoc->last)) - return(0); + rew_last(mdoc, mdoc->last); } else if ( ! nc && 0 == cnt) { mdoc_argv_free(arg); mandoc_msg(MANDOCERR_MACRO_EMPTY, @@ -1009,8 +1005,8 @@ in_line(MACRO_PROT_ARGS) * Close out our scope, if one is open, before * any punctuation. */ - if (scope && ! rew_elem(mdoc, tok)) - return(0); + if (scope) + rew_elem(mdoc, tok); scope = 0; if (tok == MDOC_Fn) mayopen = 0; @@ -1040,14 +1036,13 @@ in_line(MACRO_PROT_ARGS) * having to parse out spaces. */ if (scope && MDOC_Fl == tok) { - if ( ! rew_elem(mdoc, tok)) - return(0); + rew_elem(mdoc, tok); scope = 0; } } - if (scope && ! rew_elem(mdoc, tok)) - return(0); + if (scope) + rew_elem(mdoc, tok); /* * If no elements have been collected and we're allowed to have @@ -1058,8 +1053,7 @@ in_line(MACRO_PROT_ARGS) if (nc && 0 == cnt) { if ( ! mdoc_elem_alloc(mdoc, line, ppos, tok, arg)) return(0); - if ( ! rew_last(mdoc, mdoc->last)) - return(0); + rew_last(mdoc, mdoc->last); } else if ( ! nc && 0 == cnt) { mdoc_argv_free(arg); mandoc_msg(MANDOCERR_MACRO_EMPTY, mdoc->parse, @@ -1100,7 +1094,8 @@ blk_full(MACRO_PROT_ARGS) if ( ! mdoc_elem_alloc(mdoc, line, ppos, MDOC_br, NULL)) return(0); - return(rew_elem(mdoc, MDOC_br)); + rew_elem(mdoc, MDOC_br); + return(1); } } @@ -1641,16 +1636,15 @@ in_line_argn(MACRO_PROT_ARGS) return(0); if (j == maxargs && ! flushed) { - if ( ! rew_elem(mdoc, tok)) - return(0); + rew_elem(mdoc, tok); flushed = 1; } ntok = ARGS_QWORD == ac ? MDOC_MAX : lookup(tok, p); if (MDOC_MAX != ntok) { - if ( ! flushed && ! rew_elem(mdoc, tok)) - return(0); + if ( ! flushed) + rew_elem(mdoc, tok); flushed = 1; if ( ! mdoc_macro(mdoc, ntok, line, la, pos, buf)) return(0); @@ -1662,8 +1656,7 @@ in_line_argn(MACRO_PROT_ARGS) ARGS_QWORD != ac && ! flushed && DELIM_NONE != mdoc_isdelim(p)) { - if ( ! rew_elem(mdoc, tok)) - return(0); + rew_elem(mdoc, tok); flushed = 1; } @@ -1678,8 +1671,8 @@ in_line_argn(MACRO_PROT_ARGS) /* Close out in a consistent state. */ - if ( ! flushed && ! rew_elem(mdoc, tok)) - return(0); + if ( ! flushed) + rew_elem(mdoc, tok); if ( ! nl) return(1); return(append_delims(mdoc, line, pos, buf)); @@ -1743,15 +1736,14 @@ in_line_eoln(MACRO_PROT_ARGS) return(0); continue; } - - if ( ! rew_elem(mdoc, tok)) - return(0); + rew_elem(mdoc, tok); return(mdoc_macro(mdoc, ntok, line, la, pos, buf)); } /* Close out (no delimiters). */ - return(rew_elem(mdoc, tok)); + rew_elem(mdoc, tok); + return(1); } static int |