From d5976ecf949530abbe4672ca2ab66a66cc00ddec Mon Sep 17 00:00:00 2001 From: Kristaps Dzonsons Date: Mon, 3 Jan 2011 11:27:32 +0000 Subject: Clarified the role of MDOC_HALT in libmdoc functions by having accessor functions assert() if they're called after MDOC_HALT is set. This makes more sense than returning 0 because this return value is used for parse errors, not programme-flow errors, and it's inconsistent to use the same value for both. Plus, prior to this, I'd return 0 without printing an error message, which would cause failure to go unreported to the operator. --- mdoc.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) (limited to 'mdoc.c') diff --git a/mdoc.c b/mdoc.c index 389f0bc1..5494b633 100644 --- a/mdoc.c +++ b/mdoc.c @@ -106,7 +106,8 @@ const struct mdoc_node * mdoc_node(const struct mdoc *m) { - return(MDOC_HALT & m->flags ? NULL : m->first); + assert( ! (MDOC_HALT & m->flags)); + return(m->first); } @@ -114,7 +115,8 @@ const struct mdoc_meta * mdoc_meta(const struct mdoc *m) { - return(MDOC_HALT & m->flags ? NULL : &m->meta); + assert( ! (MDOC_HALT & m->flags)); + return(&m->meta); } @@ -215,9 +217,8 @@ int mdoc_endparse(struct mdoc *m) { - if (MDOC_HALT & m->flags) - return(0); - else if (mdoc_macroend(m)) + assert( ! (MDOC_HALT & m->flags)); + if (mdoc_macroend(m)) return(1); m->flags |= MDOC_HALT; return(0); @@ -227,8 +228,7 @@ int mdoc_addspan(struct mdoc *m, const struct tbl_span *sp) { - if (MDOC_HALT & m->flags) - return(0); + assert( ! (MDOC_HALT & m->flags)); /* No text before an initial macro. */ @@ -250,8 +250,7 @@ int mdoc_parseln(struct mdoc *m, int ln, char *buf, int offs) { - if (MDOC_HALT & m->flags) - return(0); + assert( ! (MDOC_HALT & m->flags)); m->flags |= MDOC_NEWLINE; -- cgit