- sz = term_strlen(tp, dp->string);
- psz = term_strlen(tp, ".");
-
- if (NULL != (decp = strchr(dp->string, tbl->decimal))) {
- buf[1] = '\0';
- for (ssz = i = 0; decp != &dp->string[i]; i++) {
- buf[0] = dp->string[i];
- ssz += term_strlen(tp, buf);
- }
- d = ssz + psz;
- } else
- d = sz + psz;
-
- assert(d <= tblp->decimal);
- assert(sz - d <= tblp->width - tblp->decimal);
-
- padl = tblp->decimal - d + term_len(tp, 1);
- assert(tblp->width - sz - padl);
-
- tbl_char(tp, ASCII_NBRSP, padl);
- term_word(tp, dp->string);
- tbl_char(tp, ASCII_NBRSP, tblp->width - sz - padl);
-}
-
-static void
-tbl_calc(struct termp *tp, const struct tbl_span *sp)
-{
- const struct tbl_dat *dp;
- const struct tbl_head *hp;
- struct termp_tbl *p;
-
- /* Calculate width as the max of column cells' widths. */
-
- hp = sp->head;
-
- for ( ; sp; sp = sp->next) {
- if (TBL_SPAN_DATA != sp->pos)
- continue;
-
- for (dp = sp->first; dp; dp = dp->next) {
- if (NULL == dp->layout)
- continue;
- p = &tp->tbl[dp->layout->head->ident];
- tbl_calc_data(tp, sp->tbl, dp, p);
- }
- }
-
- /* Calculate width as the simple spanner value. */
-
- for ( ; hp; hp = hp->next)
- switch (hp->pos) {
- case (TBL_HEAD_VERT):
- tp->tbl[hp->ident].width = term_len(tp, 1);
- break;
- case (TBL_HEAD_DVERT):
- tp->tbl[hp->ident].width = term_len(tp, 2);
- break;
- default:
- break;
- }
-}
-
-static void
-tbl_calc_data(struct termp *tp, const struct tbl *tbl,
- const struct tbl_dat *dp, struct termp_tbl *tblp)
-{
- int sz;
-
- /* Branch down into data sub-types. */
-
- switch (dp->layout->pos) {
- case (TBL_CELL_HORIZ):
- /* FALLTHROUGH */
- case (TBL_CELL_DHORIZ):
- sz = term_len(tp, 1);
- if (tblp->width < sz)
- tblp->width = sz;
- break;
- case (TBL_CELL_LONG):
- /* FALLTHROUGH */
- case (TBL_CELL_CENTRE):
- /* FALLTHROUGH */
- case (TBL_CELL_LEFT):
- /* FALLTHROUGH */
- case (TBL_CELL_RIGHT):
- tbl_calc_data_literal(tp, dp, tblp);
- break;
- case (TBL_CELL_NUMBER):
- tbl_calc_data_number(tp, tbl, dp, tblp);
- break;
- default:
- abort();
- /* NOTREACHED */
- }
-}
-
-static void
-tbl_calc_data_number(struct termp *tp, const struct tbl *tbl,
- const struct tbl_dat *dp, struct termp_tbl *tblp)
-{
- int sz, d, psz, i, ssz;
- char *cp, buf[2];