- /*
- * 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 != NULL) {
- if (tbl->last_span->pos == TBL_SPAN_DATA) {
- for (rp = tbl->last_span->layout->next;
- rp != NULL && rp->first != NULL;
- 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 (rp == NULL)
- rp = tbl->last_span->layout;
- } else
- rp = tbl->first_row;
-
- assert(rp);
+ rp = (sp = tbl->last_span) == NULL ? tbl->first_row :
+ sp->pos == TBL_SPAN_DATA && sp->layout->next != NULL ?
+ sp->layout->next : sp->layout;