- 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)
-{
-
- /* Branch down into data sub-types. */
-
- switch (dp->layout->pos) {
- case (TBL_CELL_HORIZ):
- /* FALLTHROUGH */
- case (TBL_CELL_DHORIZ):
- tblp->width = 1;
- 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;
- char *cp;
-
- /*
- * First calculate number width and decimal place (last + 1 for
- * no-decimal numbers). If the stored decimal is subsequent
- * ours, make our size longer by that difference
- * (right-"shifting"); similarly, if ours is subsequent the
- * stored, then extend the stored size by the difference.
- * Finally, re-assign the stored values.
- */
-
- /* TODO: use spacing modifier. */
-
- assert(dp->string);
- sz = (int)strlen(dp->string);
-
- if (NULL == (cp = strchr(dp->string, tbl->decimal)))
- d = sz + 1;
- else
- d = (int)(cp - dp->string) + 1;
-
- sz += 2;
-
- if (tblp->decimal > d) {
- sz += tblp->decimal - d;
- d = tblp->decimal;