summaryrefslogtreecommitdiffstats
path: root/tbl_term.c
diff options
context:
space:
mode:
authorKristaps Dzonsons <kristaps@bsd.lv>2011-01-03 15:07:59 +0000
committerKristaps Dzonsons <kristaps@bsd.lv>2011-01-03 15:07:59 +0000
commit6bf308f181c6403a1c42df8160ff64f00577ecca (patch)
tree4421387267848ef4acfefe19be5a4144045b4ba3 /tbl_term.c
parent1b96ebbbaea1f86dd2449cbe176c4e6d7eebdc59 (diff)
downloadmandoc-6bf308f181c6403a1c42df8160ff64f00577ecca.tar.gz
Add in support for number table cells that account for escapes and so
on. Note also that -Tps and -Tpdf, with these last two commits, produce more readable output ("less crappy").
Diffstat (limited to 'tbl_term.c')
-rw-r--r--tbl_term.c45
1 files changed, 28 insertions, 17 deletions
diff --git a/tbl_term.c b/tbl_term.c
index bd679ff5..3768be31 100644
--- a/tbl_term.c
+++ b/tbl_term.c
@@ -397,26 +397,31 @@ tbl_data_number(struct termp *tp, const struct tbl *tbl,
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);
@@ -502,8 +507,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 +522,20 @@ tbl_calc_data_number(struct termp *tp, const struct tbl *tbl,
/* 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;