=================================================================== RCS file: /cvs/mandoc/tbl_term.c,v retrieving revision 1.4 retrieving revision 1.9 diff -u -p -r1.4 -r1.9 --- mandoc/tbl_term.c 2011/01/03 14:57:04 1.4 +++ mandoc/tbl_term.c 2011/01/04 13:21:45 1.9 @@ -1,4 +1,4 @@ -/* $Id: tbl_term.c,v 1.4 2011/01/03 14:57:04 kristaps Exp $ */ +/* $Id: tbl_term.c,v 1.9 2011/01/04 13:21:45 kristaps Exp $ */ /* * Copyright (c) 2009 Kristaps Dzonsons * @@ -40,9 +40,6 @@ static void tbl_data_number(struct termp *, static void tbl_data_literal(struct termp *, const struct tbl_dat *, const struct termp_tbl *); -static void tbl_data_spanner(struct termp *, - const struct tbl_dat *, - const struct termp_tbl *); static void tbl_data(struct termp *, const struct tbl *, const struct tbl_dat *, const struct termp_tbl *); @@ -209,9 +206,6 @@ tbl_hframe(struct termp *tp, const struct tbl_span *sp TBL_OPT_DBOX & sp->tbl->opts)) return; - tp->flags |= TERMP_NONOSPACE; - tp->flags |= TERMP_NOSPACE; - /* * Print out the horizontal part of a frame or double frame. A * double frame has an unbroken `-' outer line the width of the @@ -261,8 +255,13 @@ tbl_data(struct termp *tp, const struct tbl *tbl, switch (dp->pos) { case (TBL_DATA_HORIZ): /* FALLTHROUGH */ + case (TBL_DATA_NHORIZ): + tbl_char(tp, '-', tbp->width); + return; + case (TBL_DATA_NDHORIZ): + /* FALLTHROUGH */ case (TBL_DATA_DHORIZ): - tbl_data_spanner(tp, dp, tbp); + tbl_char(tp, '=', tbp->width); return; default: break; @@ -272,9 +271,10 @@ tbl_data(struct termp *tp, const struct tbl *tbl, switch (pos) { case (TBL_CELL_HORIZ): - /* FALLTHROUGH */ + tbl_char(tp, '-', tbp->width); + break; case (TBL_CELL_DHORIZ): - tbl_data_spanner(tp, dp, tbp); + tbl_char(tp, '=', tbp->width); break; case (TBL_CELL_LONG): /* FALLTHROUGH */ @@ -318,7 +318,6 @@ tbl_vframe(struct termp *tp, const struct tbl *tbl) term_word(tp, "|"); } - static inline void tbl_char(struct termp *tp, char c, int len) { @@ -335,26 +334,6 @@ tbl_char(struct termp *tp, char c, int len) } static void -tbl_data_spanner(struct termp *tp, - const struct tbl_dat *dp, - const struct termp_tbl *tblp) -{ - - switch (dp->pos) { - case (TBL_DATA_HORIZ): - case (TBL_DATA_NHORIZ): - tbl_char(tp, '-', tblp->width); - break; - case (TBL_DATA_DHORIZ): - case (TBL_DATA_NDHORIZ): - tbl_char(tp, '=', tblp->width); - break; - default: - break; - } -} - -static void tbl_data_literal(struct termp *tp, const struct tbl_dat *dp, const struct termp_tbl *tblp) @@ -397,26 +376,31 @@ tbl_data_number(struct termp *tp, const struct tbl *tb const struct tbl_dat *dp, const struct termp_tbl *tblp) { - char *decp; - int d, padl, sz; + char *decp, buf[2]; + int d, padl, sz, psz, ssz, i; /* * See calc_data_number(). Left-pad by taking the offset of our * and the maximum decimal; right-pad by the remaining amount. */ - sz = (int)strlen(dp->string); + sz = term_strlen(tp, dp->string); + psz = term_strlen(tp, "."); - if (NULL == (decp = strchr(dp->string, tbl->decimal))) { - d = sz + 1; - } else { - d = (int)(decp - dp->string) + 1; - } + 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 + 1; + padl = tblp->decimal - d + term_len(tp, 1); assert(tblp->width - sz - padl); tbl_char(tp, ASCII_NBRSP, padl); @@ -471,6 +455,7 @@ 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. */ @@ -478,7 +463,9 @@ tbl_calc_data(struct termp *tp, const struct tbl *tbl, case (TBL_CELL_HORIZ): /* FALLTHROUGH */ case (TBL_CELL_DHORIZ): - tblp->width = 1; + sz = term_len(tp, 1); + if (tblp->width < sz) + tblp->width = sz; break; case (TBL_CELL_LONG): /* FALLTHROUGH */ @@ -502,8 +489,8 @@ 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; + int sz, d, psz, i, ssz; + char *cp, buf[2]; /* * First calculate number width and decimal place (last + 1 for @@ -517,14 +504,20 @@ tbl_calc_data_number(struct termp *tp, const struct tb /* TODO: use spacing modifier. */ assert(dp->string); - sz = (int)strlen(dp->string); + sz = term_strlen(tp, dp->string); + psz = term_strlen(tp, "."); - if (NULL == (cp = strchr(dp->string, tbl->decimal))) - d = sz + 1; - else - d = (int)(cp - dp->string) + 1; + if (NULL != (cp = strchr(dp->string, tbl->decimal))) { + buf[1] = '\0'; + for (ssz = i = 0; cp != &dp->string[i]; i++) { + buf[0] = dp->string[i]; + ssz += term_strlen(tp, buf); + } + d = ssz + psz; + } else + d = sz + psz; - sz += 2; + sz += term_len(tp, 2); if (tblp->decimal > d) { sz += tblp->decimal - d; @@ -543,7 +536,7 @@ tbl_calc_data_literal(struct termp *tp, const struct tbl_dat *dp, struct termp_tbl *tblp) { - int sz, bufsz; + int sz, bufsz, spsz; /* * Calculate our width and use the spacing, with a minimum @@ -558,16 +551,19 @@ tbl_calc_data_literal(struct termp *tp, case (TBL_CELL_LONG): /* FALLTHROUGH */ case (TBL_CELL_CENTRE): - bufsz = 2; + bufsz = term_len(tp, 2); break; default: - bufsz = 1; + bufsz = term_len(tp, 1); break; } + spsz = 0; if (dp->layout->spacing) - bufsz = bufsz > dp->layout->spacing ? - bufsz : dp->layout->spacing; + spsz = term_len(tp, dp->layout->spacing); + + if (spsz) + bufsz = bufsz > spsz ? bufsz : spsz; sz += bufsz; if (tblp->width < sz)