+ tbl->current_span = NULL;
+ dp->flags |= TBL_SPAN_FIRST;
+ }
+
+ return(dp);
+}
+
+int
+tbl_data(struct tbl_node *tbl, int ln, const char *p)
+{
+ struct tbl_span *dp;
+ struct tbl_row *rp;
+ int pos;
+
+ pos = 0;
+
+ if ('\0' == p[pos]) {
+ mandoc_msg(MANDOCERR_TBL, tbl->parse, ln, pos, NULL);
+ return(0);
+ }
+
+ /*
+ * Choose a layout row: take the one following the last parsed
+ * span's. If that doesn't exist, use the last parsed span's.
+ * If there's no last parsed span, use the first row. Lastly,
+ * if the last span was a horizontal line, use the same layout
+ * (it doesn't "consume" the layout).
+ */
+
+ if (tbl->last_span) {
+ assert(tbl->last_span->layout);
+ if (tbl->last_span->pos == TBL_SPAN_DATA) {
+ for (rp = tbl->last_span->layout->next;
+ rp && rp->first; rp = rp->next) {
+ switch (rp->first->pos) {
+ case (TBL_CELL_HORIZ):
+ dp = newspan(tbl, ln, rp);
+ dp->pos = TBL_SPAN_HORIZ;
+ continue;
+ case (TBL_CELL_DHORIZ):
+ dp = newspan(tbl, ln, rp);
+ dp->pos = TBL_SPAN_DHORIZ;
+ continue;
+ default:
+ break;
+ }
+ break;
+ }
+ } else
+ rp = tbl->last_span->layout;
+
+ if (NULL == rp)
+ rp = tbl->last_span->layout;
+ } else
+ rp = tbl->first_row;
+
+ assert(rp);
+
+ dp = newspan(tbl, ln, rp);