+ tp->lasttcol = tp->tcol - tp->tcols;
+
+ /* Fill the buffers for all data columns. */
+
+ tp->tcol = tp->tcols;
+ cp = cpn = sp->layout->first;
+ dp = sp->first;
+ spans = 0;
+ for (ic = 0; ic < sp->opts->cols; ic++) {
+ if (cpn != NULL) {
+ cp = cpn;
+ cpn = cpn->next;
+ }
+ if (spans) {
+ spans--;
+ continue;
+ }
+ tp->tcol++;
+ tp->col = 0;
+ tbl_data(tp, sp->opts, cp, dp, tp->tbl.cols + ic);
+ if (dp == NULL)
+ continue;
+ spans = dp->spans;
+ if (cp->pos != TBL_CELL_SPAN)
+ dp = dp->next;
+ }
+ break;
+ }
+
+ do {
+ /* Print the vertical frame at the start of each row. */
+
+ tp->tcol = tp->tcols;
+ fc = '\0';
+ if (sp->layout->vert ||
+ (sp->next != NULL && sp->next->layout->vert &&
+ sp->next->pos == TBL_SPAN_DATA) ||
+ (sp->prev != NULL && sp->prev->layout->vert &&
+ (horiz || (IS_HORIZ(sp->layout->first) &&
+ !IS_HORIZ(sp->prev->layout->first)))) ||
+ sp->opts->opts & (TBL_OPT_BOX | TBL_OPT_DBOX))
+ fc = horiz || IS_HORIZ(sp->layout->first) ? '+' : '|';
+ else if (horiz && sp->opts->lvert)
+ fc = '-';
+ if (fc != '\0') {
+ (*tp->advance)(tp, tp->tcols->offset);
+ (*tp->letter)(tp, fc);
+ tp->viscol = tp->tcol->offset + 1;
+ }
+
+ /* Print the data cells. */
+
+ more = 0;
+ if (horiz) {
+ tbl_hrule(tp, sp, 0);
+ term_flushln(tp);
+ } else {
+ cp = sp->layout->first;
+ cpn = sp->next == NULL ? NULL :
+ sp->next->layout->first;
+ cpp = sp->prev == NULL ? NULL :
+ sp->prev->layout->first;
+ dp = sp->first;
+ spans = 0;
+ for (ic = 0; ic < sp->opts->cols; ic++) {
+
+ /*
+ * Figure out whether to print a
+ * vertical line after this cell
+ * and advance to next layout cell.
+ */
+
+ if (cp != NULL) {
+ vert = cp->vert;
+ switch (cp->pos) {
+ case TBL_CELL_HORIZ:
+ fc = '-';
+ break;
+ case TBL_CELL_DHORIZ:
+ fc = '=';
+ break;
+ default:
+ fc = ' ';
+ break;
+ }
+ } else {
+ vert = 0;
+ fc = ' ';
+ }
+ if (cpp != NULL) {
+ if (vert == 0 &&
+ cp != NULL &&
+ ((IS_HORIZ(cp) &&
+ !IS_HORIZ(cpp)) ||
+ (cp->next != NULL &&
+ cpp->next != NULL &&
+ IS_HORIZ(cp->next) &&
+ !IS_HORIZ(cpp->next))))
+ vert = cpp->vert;
+ cpp = cpp->next;
+ }
+ if (vert == 0 &&
+ sp->opts->opts & TBL_OPT_ALLBOX)
+ vert = 1;
+ if (cpn != NULL) {
+ if (vert == 0)
+ vert = cpn->vert;
+ cpn = cpn->next;
+ }
+ if (cp != NULL)
+ cp = cp->next;
+
+ /*
+ * Skip later cells in a span,
+ * figure out whether to start a span,
+ * and advance to next data cell.
+ */
+
+ if (spans) {
+ spans--;
+ continue;
+ }