aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/roff.c
diff options
context:
space:
mode:
authorKristaps Dzonsons <kristaps@bsd.lv>2008-11-28 18:15:29 +0000
committerKristaps Dzonsons <kristaps@bsd.lv>2008-11-28 18:15:29 +0000
commit24ab2f2f835520af37cfd66dd0ff850d758a3d71 (patch)
treeb348148698ad3b9ca638bcfb9b83508e7fb14f5d /roff.c
parenta92eb03490ddb10755d39b4006afdfee3ba71b67 (diff)
downloadmandoc-24ab2f2f835520af37cfd66dd0ff850d758a3d71.tar.gz
mandoc-24ab2f2f835520af37cfd66dd0ff850d758a3d71.tar.zst
mandoc-24ab2f2f835520af37cfd66dd0ff850d758a3d71.zip
Cleaned up exit routine.
Added roffhead and rofftail call.
Diffstat (limited to 'roff.c')
-rw-r--r--roff.c44
1 files changed, 33 insertions, 11 deletions
diff --git a/roff.c b/roff.c
index b00d32c1..c4bcb3d7 100644
--- a/roff.c
+++ b/roff.c
@@ -1,4 +1,4 @@
-/* $Id: roff.c,v 1.15 2008/11/28 15:25:49 kristaps Exp $ */
+/* $Id: roff.c,v 1.16 2008/11/28 18:15:29 kristaps Exp $ */
/*
* Copyright (c) 2008 Kristaps Dzonsons <kristaps@kth.se>
*
@@ -357,23 +357,40 @@ const char *const *tokargnames = tokargnamesp;
int
roff_free(struct rofftree *tree, int flush)
{
- int error;
+ int error, t;
struct roffnode *n;
- error = 0;
+ if ( ! flush)
+ goto end;
- for (n = tree->last; n->parent; n = n->parent)
- if (tokens[n->tok].ctx == 0) {
- roff_warn(tree, NULL, "closing explicit scope "
- "of `%s'", toknames[n->tok]);
- error = 1;
- }
+ error = 1;
- if (0 == error && (ROFF_PRELUDE & tree->state)) {
+ if (ROFF_PRELUDE & tree->state) {
roff_warn(tree, NULL, "prelude never finished");
- error = 1;
+ goto end;
+ }
+
+ for (n = tree->last; n->parent; n = n->parent) {
+ if (0 != tokens[n->tok].ctx)
+ break;
+ roff_warn(tree, NULL, "closing explicit scope `%s'",
+ toknames[n->tok]);
+ goto end;
+ }
+
+ while (tree->last) {
+ t = tree->last->tok;
+ if ( ! (*tokens[t].cb)(t, tree, NULL, ROFF_EXIT))
+ goto end;
}
+ if ( ! (*tree->cb.roffhead)(tree->arg))
+ goto end;
+
+ error = 0;
+
+end:
+
while (tree->last)
roffnode_free(tree);
@@ -395,6 +412,11 @@ roff_alloc(const struct roffcb *cb, void *args)
(void)memcpy(&tree->cb, cb, sizeof(struct roffcb));
+ if ( ! (*tree->cb.roffhead)(args)) {
+ free(tree);
+ return(NULL);
+ }
+
return(tree);
}