version 1.4, 2011/01/03 14:57:04 |
version 1.5, 2011/01/03 15:07:59 |
Line 397 tbl_data_number(struct termp *tp, const struct tbl *tb |
|
Line 397 tbl_data_number(struct termp *tp, const struct tbl *tb |
|
const struct tbl_dat *dp, |
const struct tbl_dat *dp, |
const struct termp_tbl *tblp) |
const struct termp_tbl *tblp) |
{ |
{ |
char *decp; |
char *decp, buf[2]; |
int d, padl, sz; |
int d, padl, sz, psz, ssz, i; |
|
|
/* |
/* |
* See calc_data_number(). Left-pad by taking the offset of our |
* See calc_data_number(). Left-pad by taking the offset of our |
* and the maximum decimal; right-pad by the remaining amount. |
* 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))) { |
if (NULL != (decp = strchr(dp->string, tbl->decimal))) { |
d = sz + 1; |
buf[1] = '\0'; |
} else { |
for (ssz = i = 0; decp != &dp->string[i]; i++) { |
d = (int)(decp - dp->string) + 1; |
buf[0] = dp->string[i]; |
} |
ssz += term_strlen(tp, buf); |
|
} |
|
d = ssz + psz; |
|
} else |
|
d = sz + psz; |
|
|
assert(d <= tblp->decimal); |
assert(d <= tblp->decimal); |
assert(sz - d <= tblp->width - 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); |
assert(tblp->width - sz - padl); |
|
|
tbl_char(tp, ASCII_NBRSP, padl); |
tbl_char(tp, ASCII_NBRSP, padl); |
|
|
tbl_calc_data_number(struct termp *tp, const struct tbl *tbl, |
tbl_calc_data_number(struct termp *tp, const struct tbl *tbl, |
const struct tbl_dat *dp, struct termp_tbl *tblp) |
const struct tbl_dat *dp, struct termp_tbl *tblp) |
{ |
{ |
int sz, d; |
int sz, d, psz, i, ssz; |
char *cp; |
char *cp, buf[2]; |
|
|
/* |
/* |
* First calculate number width and decimal place (last + 1 for |
* First calculate number width and decimal place (last + 1 for |
Line 517 tbl_calc_data_number(struct termp *tp, const struct tb |
|
Line 522 tbl_calc_data_number(struct termp *tp, const struct tb |
|
/* TODO: use spacing modifier. */ |
/* TODO: use spacing modifier. */ |
|
|
assert(dp->string); |
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))) |
if (NULL != (cp = strchr(dp->string, tbl->decimal))) { |
d = sz + 1; |
buf[1] = '\0'; |
else |
for (ssz = i = 0; cp != &dp->string[i]; i++) { |
d = (int)(cp - dp->string) + 1; |
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) { |
if (tblp->decimal > d) { |
sz += tblp->decimal - d; |
sz += tblp->decimal - d; |