=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/mandoc/tbl.c,v retrieving revision 1.24 retrieving revision 1.25 diff -u -r1.24 -r1.25 --- src/usr.bin/mandoc/tbl.c 2018/12/12 21:54:30 1.24 +++ src/usr.bin/mandoc/tbl.c 2018/12/13 02:05:57 1.25 @@ -1,4 +1,4 @@ -/* $OpenBSD: tbl.c,v 1.24 2018/12/12 21:54:30 schwarze Exp $ */ +/* $OpenBSD: tbl.c,v 1.25 2018/12/13 02:05:57 schwarze Exp $ */ /* * Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons * Copyright (c) 2011, 2015 Ingo Schwarze @@ -27,7 +27,8 @@ #include "mandoc.h" #include "tbl.h" #include "libmandoc.h" -#include "libroff.h" +#include "tbl_parse.h" +#include "tbl_int.h" void @@ -85,11 +86,13 @@ } struct tbl_node * -tbl_alloc(int pos, int line, struct mparse *parse) +tbl_alloc(int pos, int line, struct mparse *parse, struct tbl_node *last_tbl) { struct tbl_node *tbl; tbl = mandoc_calloc(1, sizeof(*tbl)); + if (last_tbl != NULL) + last_tbl->next = tbl; tbl->line = line; tbl->pos = pos; tbl->parse = parse; @@ -102,34 +105,37 @@ void tbl_free(struct tbl_node *tbl) { + struct tbl_node *old_tbl; struct tbl_row *rp; struct tbl_cell *cp; struct tbl_span *sp; struct tbl_dat *dp; - while ((rp = tbl->first_row) != NULL) { - tbl->first_row = rp->next; - while (rp->first != NULL) { - cp = rp->first; - rp->first = cp->next; - free(cp->wstr); - free(cp); + while (tbl != NULL) { + while ((rp = tbl->first_row) != NULL) { + tbl->first_row = rp->next; + while (rp->first != NULL) { + cp = rp->first; + rp->first = cp->next; + free(cp->wstr); + free(cp); + } + free(rp); } - free(rp); - } - - while ((sp = tbl->first_span) != NULL) { - tbl->first_span = sp->next; - while (sp->first != NULL) { - dp = sp->first; - sp->first = dp->next; - free(dp->string); - free(dp); + while ((sp = tbl->first_span) != NULL) { + tbl->first_span = sp->next; + while (sp->first != NULL) { + dp = sp->first; + sp->first = dp->next; + free(dp->string); + free(dp); + } + free(sp); } - free(sp); + old_tbl = tbl; + tbl = tbl->next; + free(old_tbl); } - - free(tbl); } void @@ -144,25 +150,27 @@ tbl->pos = pos; } -const struct tbl_span * +struct tbl_span * tbl_span(struct tbl_node *tbl) { struct tbl_span *span; - assert(tbl); span = tbl->current_span ? tbl->current_span->next : tbl->first_span; - if (span) + if (span != NULL) tbl->current_span = span; return span; } int -tbl_end(struct tbl_node *tbl) +tbl_end(struct tbl_node *tbl, int still_open) { struct tbl_span *sp; - if (tbl->part == TBL_PART_CDATA) + if (still_open) + mandoc_msg(MANDOCERR_BLK_NOEND, tbl->parse, + tbl->line, tbl->pos, "TS"); + else if (tbl->part == TBL_PART_CDATA) mandoc_msg(MANDOCERR_TBLDATA_BLK, tbl->parse, tbl->line, tbl->pos, "TE");