summaryrefslogtreecommitdiffstats
path: root/tbl.c
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@openbsd.org>2018-12-13 02:06:07 +0000
committerIngo Schwarze <schwarze@openbsd.org>2018-12-13 02:06:07 +0000
commitae67a8ca5712135cc0c82b55de5e8d387d42b8ef (patch)
treea3718fa68884ce7736b6447028719710bcbe2109 /tbl.c
parent417f9b830578cb78d80fbbf1a605502b9022cb2e (diff)
downloadmandoc-ae67a8ca5712135cc0c82b55de5e8d387d42b8ef.tar.gz
Cleanup, no functional change:
Move tbl(7)-specific parser internals out of libroff.h. Move some tbl(7)-internal processing from roff.c to tbl.c.
Diffstat (limited to 'tbl.c')
-rw-r--r--tbl.c62
1 files changed, 35 insertions, 27 deletions
diff --git a/tbl.c b/tbl.c
index 73b4ee1a..0767c539 100644
--- a/tbl.c
+++ b/tbl.c
@@ -29,7 +29,8 @@
#include "mandoc.h"
#include "tbl.h"
#include "libmandoc.h"
-#include "libroff.h"
+#include "tbl_parse.h"
+#include "tbl_int.h"
void
@@ -87,11 +88,13 @@ tbl_read(struct tbl_node *tbl, int ln, const char *p, int pos)
}
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;
@@ -104,34 +107,37 @@ tbl_alloc(int pos, int line, struct mparse *parse)
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
@@ -146,25 +152,27 @@ tbl_restart(int line, int pos, struct tbl_node *tbl)
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");