diff options
author | Kristaps Dzonsons <kristaps@bsd.lv> | 2010-04-06 11:33:00 +0000 |
---|---|---|
committer | Kristaps Dzonsons <kristaps@bsd.lv> | 2010-04-06 11:33:00 +0000 |
commit | a3cca04329e11265db966ace2846405959d5e2d3 (patch) | |
tree | 6df1aa229b6f4facbc2325d654479a65d683c415 | |
parent | aeb53baa584ae0fe0d04a3cd1e74f509d353e8c0 (diff) | |
download | mandoc-a3cca04329e11265db966ace2846405959d5e2d3.tar.gz |
Migrating mdoc_node_free() and mdoc_node_freelist() to use mdoc_node_delete(), which has a more intuitive interface and mirrors libman.
-rw-r--r-- | libmdoc.h | 3 | ||||
-rw-r--r-- | mdoc.c | 56 | ||||
-rw-r--r-- | mdoc_action.c | 23 |
3 files changed, 50 insertions, 32 deletions
@@ -137,8 +137,7 @@ int mdoc_block_alloc(struct mdoc *, int, int, int mdoc_head_alloc(struct mdoc *, int, int, enum mdoct); int mdoc_tail_alloc(struct mdoc *, int, int, enum mdoct); int mdoc_body_alloc(struct mdoc *, int, int, enum mdoct); -void mdoc_node_free(struct mdoc_node *); -void mdoc_node_freelist(struct mdoc_node *); +void mdoc_node_delete(struct mdoc *, struct mdoc_node *); void mdoc_hash_init(void); enum mdoct mdoc_hash_find(const char *); int mdoc_iscdelim(char); @@ -141,6 +141,9 @@ const char *const __mdoc_argnames[MDOC_ARG_MAX] = { const char * const *mdoc_macronames = __mdoc_macronames; const char * const *mdoc_argnames = __mdoc_argnames; +static void mdoc_node_free(struct mdoc_node *); +static void mdoc_node_unlink(struct mdoc *, + struct mdoc_node *); static void mdoc_free1(struct mdoc *); static void mdoc_alloc1(struct mdoc *); static struct mdoc_node *node_alloc(struct mdoc *, int, int, @@ -177,7 +180,7 @@ mdoc_free1(struct mdoc *mdoc) { if (mdoc->first) - mdoc_node_freelist(mdoc->first); + mdoc_node_delete(mdoc, mdoc->first); if (mdoc->meta.title) free(mdoc->meta.title); if (mdoc->meta.os) @@ -565,8 +568,6 @@ void mdoc_node_free(struct mdoc_node *p) { - if (p->parent) - p->parent->nchild--; if (p->string) free(p->string); if (p->args) @@ -575,16 +576,53 @@ mdoc_node_free(struct mdoc_node *p) } -void -mdoc_node_freelist(struct mdoc_node *p) +static void +mdoc_node_unlink(struct mdoc *m, struct mdoc_node *n) { - if (p->child) - mdoc_node_freelist(p->child); - if (p->next) - mdoc_node_freelist(p->next); + /* Adjust siblings. */ + + if (n->prev) + n->prev->next = n->next; + if (n->next) + n->next->prev = n->prev; + + /* Adjust parent. */ + + if (n->parent) { + n->parent->nchild--; + if (n->parent->child == n) + n->parent->child = n->prev ? n->prev : n->next; + } + + /* Adjust parse point, if applicable. */ + + if (m && m->last == n) { + if (n->prev) { + m->last = n->prev; + m->next = MDOC_NEXT_SIBLING; + } else { + m->last = n->parent; + m->next = MDOC_NEXT_CHILD; + } + } + + if (m && m->first == n) + m->first = NULL; +} + +void +mdoc_node_delete(struct mdoc *m, struct mdoc_node *p) +{ + + while (p->child) { + assert(p->nchild); + mdoc_node_delete(m, p->child); + } assert(0 == p->nchild); + + mdoc_node_unlink(m, p); mdoc_node_free(p); } diff --git a/mdoc_action.c b/mdoc_action.c index 3e924dbf..c2985f85 100644 --- a/mdoc_action.c +++ b/mdoc_action.c @@ -729,7 +729,7 @@ post_bl_head(POST_ARGS) nn->string = NULL; nnp = nn; nn = nn->next; - mdoc_node_free(nnp); + mdoc_node_delete(NULL, nnp); } n->nchild = 0; @@ -854,29 +854,10 @@ post_dd(POST_ARGS) static int post_prol(POST_ARGS) { - struct mdoc_node *np; - - if (n->parent->child == n) - n->parent->child = n->prev; - if (n->prev) - n->prev->next = NULL; - - np = n; - assert(NULL == n->next); - - if (n->prev) { - m->last = n->prev; - m->next = MDOC_NEXT_SIBLING; - } else { - m->last = n->parent; - m->next = MDOC_NEXT_CHILD; - } - - mdoc_node_freelist(np); + mdoc_node_delete(m, n); if (m->meta.title && m->meta.date && m->meta.os) m->flags |= MDOC_PBODY; - return(1); } |