=================================================================== RCS file: /cvs/mandoc/mdoc.c,v retrieving revision 1.167 retrieving revision 1.171 diff -u -p -r1.167 -r1.171 --- mandoc/mdoc.c 2010/12/01 16:38:57 1.167 +++ mandoc/mdoc.c 2010/12/22 11:15:16 1.171 @@ -1,4 +1,4 @@ -/* $Id: mdoc.c,v 1.167 2010/12/01 16:38:57 kristaps Exp $ */ +/* $Id: mdoc.c,v 1.171 2010/12/22 11:15:16 kristaps Exp $ */ /* * Copyright (c) 2008, 2009, 2010 Kristaps Dzonsons * Copyright (c) 2010 Ingo Schwarze @@ -511,22 +511,9 @@ static void mdoc_node_free(struct mdoc_node *p) { - /* - * XXX: if these end up being problematic in terms of memory - * management and dereferencing freed blocks, then make them - * into reference-counted double-pointers. - */ + if (p->norm && 0 == --(p->norm->refcnt)) + free(p->norm); - if (MDOC_Bd == p->tok && MDOC_BLOCK == p->type) - if (p->data.Bd) - free(p->data.Bd); - if (MDOC_Bl == p->tok && MDOC_BLOCK == p->type) - if (p->data.Bl) - free(p->data.Bl); - if (MDOC_Bf == p->tok && MDOC_HEAD == p->type) - if (p->data.Bf) - free(p->data.Bf); - if (p->string) free(p->string); if (p->args) @@ -552,6 +539,8 @@ mdoc_node_unlink(struct mdoc *m, struct mdoc_node *n) n->parent->nchild--; if (n->parent->child == n) n->parent->child = n->prev ? n->prev : n->next; + if (n->parent->last == n) + n->parent->last = n->prev ? n->prev : NULL; } /* Adjust parse point, if applicable. */ @@ -619,7 +608,7 @@ mdoc_ptext(struct mdoc *m, int line, char *buf, int of */ if (MDOC_Bl == n->tok && MDOC_BODY == n->type && - LIST_column == n->data.Bl->type) { + LIST_column == n->norm->d.Bl.type) { /* `Bl' is open without any children. */ m->flags |= MDOC_FREECOL; return(mdoc_macro(m, MDOC_It, line, offs, &offs, buf)); @@ -628,7 +617,7 @@ mdoc_ptext(struct mdoc *m, int line, char *buf, int of if (MDOC_It == n->tok && MDOC_BLOCK == n->type && NULL != n->parent && MDOC_Bl == n->parent->tok && - LIST_column == n->parent->data.Bl->type) { + LIST_column == n->parent->norm->d.Bl.type) { /* `Bl' has block-level `It' children. */ m->flags |= MDOC_FREECOL; return(mdoc_macro(m, MDOC_It, line, offs, &offs, buf)); @@ -766,9 +755,7 @@ mdoc_pmacro(struct mdoc *m, int ln, char *buf, int off tok = (j > 1 || j < 4) ? mdoc_hash_find(mac) : MDOC_MAX; if (MDOC_MAX == tok) { - mdoc_vmsg(m, MANDOCERR_MACRO, ln, sv, - "unknown macro: %s%s", - buf, strlen(buf) > 3 ? "..." : ""); + mdoc_vmsg(m, MANDOCERR_MACRO, ln, sv, "%s", buf + sv - 1); return(1); } @@ -811,7 +798,7 @@ mdoc_pmacro(struct mdoc *m, int ln, char *buf, int off */ if (MDOC_Bl == n->tok && MDOC_BODY == n->type && - LIST_column == n->data.Bl->type) { + LIST_column == n->norm->d.Bl.type) { m->flags |= MDOC_FREECOL; if ( ! mdoc_macro(m, MDOC_It, ln, sv, &sv, buf)) goto err; @@ -827,7 +814,7 @@ mdoc_pmacro(struct mdoc *m, int ln, char *buf, int off if (MDOC_It == n->tok && MDOC_BLOCK == n->type && NULL != n->parent && MDOC_Bl == n->parent->tok && - LIST_column == n->parent->data.Bl->type) { + LIST_column == n->parent->norm->d.Bl.type) { m->flags |= MDOC_FREECOL; if ( ! mdoc_macro(m, MDOC_It, ln, sv, &sv, buf)) goto err;