From afac8c1eebed17d57ca78b1d322b71cc1f48af97 Mon Sep 17 00:00:00 2001 From: Kristaps Dzonsons Date: Fri, 28 Nov 2008 18:15:29 +0000 Subject: Cleaned up exit routine. Added roffhead and rofftail call. --- roff.c | 42 ++++++++++++++++++++++++++++++++---------- 1 file changed, 32 insertions(+), 10 deletions(-) diff --git a/roff.c b/roff.c index 21f88263..7b834d8a 100644 --- a/roff.c +++ b/roff.c @@ -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); } -- cgit