aboutsummaryrefslogtreecommitdiffstatshomepage
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
commit6ad0ded3e0e5f75612138daaaf640827331d3b07 (patch)
treeeb37485aa6ab9a3775784b3df0453edaaf210648 /tbl_term.c
parenta22d8485bebd6532328a551135bba5f2400b01ad (diff)
downloadmandoc-6ad0ded3e0e5f75612138daaaf640827331d3b07.tar.gz
mandoc-6ad0ded3e0e5f75612138daaaf640827331d3b07.tar.zst
mandoc-6ad0ded3e0e5f75612138daaaf640827331d3b07.zip
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.c47
1 files changed, 29 insertions, 18 deletions
diff --git a/tbl_term.c b/tbl_term.c
index c1cbc629..2aaebcb8 100644
--- a/tbl_term.c
+++ b/tbl_term.c
@@ -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.5 2011/01/03 15:07:59 kristaps Exp $ */
/*
* Copyright (c) 2009 Kristaps Dzonsons <kristaps@kth.se>
*
@@ -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;