summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKristaps Dzonsons <kristaps@bsd.lv>2011-01-03 11:27:32 +0000
committerKristaps Dzonsons <kristaps@bsd.lv>2011-01-03 11:27:32 +0000
commitd5976ecf949530abbe4672ca2ab66a66cc00ddec (patch)
tree201f54e1c9c2a6293d5e4dd1300040a82f7104a7
parentacbea5cc811c026741e14c43e082ea541d143fba (diff)
downloadmandoc-d5976ecf949530abbe4672ca2ab66a66cc00ddec.tar.gz
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.
-rw-r--r--mdoc.324
-rw-r--r--mdoc.c17
2 files changed, 20 insertions, 21 deletions
diff --git a/mdoc.3 b/mdoc.3
index 358008d8..f5259bac 100644
--- a/mdoc.3
+++ b/mdoc.3
@@ -96,6 +96,16 @@ See
for details.
.El
.Ss Functions
+If
+.Fn mdoc_addspan ,
+.Fn mdoc_parseln ,
+or
+.Fn mdoc_endparse
+return 0, calls to any function but
+.Fn mdoc_reset
+or
+.Fn mdoc_free
+will raise an assertion.
.Bl -ohang
.It Fn mdoc_addspan
Add a table span to the parsing stream.
@@ -106,8 +116,8 @@ The
.Fa data
pointer is passed to
.Fa msgs .
-Returns NULL on failure.
-If non-NULL, the pointer must be freed with
+Always returns a valid pointer.
+The pointer must be freed with
.Fn mdoc_free .
.It Fn mdoc_reset
Reset the parser for another parse routine.
@@ -135,18 +145,8 @@ the resulting tree is incomplete.
Returns 0 on failure, 1 on success.
.It Fn mdoc_node
Returns the first node of the parse.
-Note that if
-.Fn mdoc_parseln
-or
-.Fn mdoc_endparse
-return 0, the tree will be incomplete.
.It Fn mdoc_meta
Returns the document's parsed meta-data.
-If this information has not yet been supplied or
-.Fn mdoc_parseln
-or
-.Fn mdoc_endparse
-return 0, the data will be incomplete.
.El
.Ss Variables
.Bl -ohang
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;