aboutsummaryrefslogtreecommitdiffstatshomepage
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
commit8778c0e49080778fd04dc5a3c1aac38addbfa5a4 (patch)
tree3f4e1c54b77a817844378231c2dc4a3aa04e9908 /tbl.c
parentabe535d017ebcf70bf575e3048cb4ea11f75a600 (diff)
downloadmandoc-8778c0e49080778fd04dc5a3c1aac38addbfa5a4.tar.gz
mandoc-8778c0e49080778fd04dc5a3c1aac38addbfa5a4.tar.zst
mandoc-8778c0e49080778fd04dc5a3c1aac38addbfa5a4.zip
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.c64
1 files changed, 36 insertions, 28 deletions
diff --git a/tbl.c b/tbl.c
index b09e34df..29ac4fd0 100644
--- a/tbl.c
+++ b/tbl.c
@@ -1,4 +1,4 @@
-/* $Id: tbl.c,v 1.43 2018/12/12 21:54:35 schwarze Exp $ */
+/* $Id: tbl.c,v 1.44 2018/12/13 02:06:07 schwarze Exp $ */
/*
* Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2011, 2015 Ingo Schwarze <schwarze@openbsd.org>
@@ -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");