version 1.2, 2011/01/03 13:59:21 |
version 1.3, 2011/01/03 14:45:59 |
Line 52 static void tbl_hrule(struct termp *, |
|
Line 52 static void tbl_hrule(struct termp *, |
|
const struct tbl_span *); |
const struct tbl_span *); |
static void tbl_vframe(struct termp *, |
static void tbl_vframe(struct termp *, |
const struct tbl *); |
const struct tbl *); |
static void tbl_calc(const struct tbl_span *, |
static void tbl_calc(struct termp *, |
|
const struct tbl_span *); |
|
static void tbl_calc_data(struct termp *, |
|
const struct tbl *, |
|
const struct tbl_dat *, |
struct termp_tbl *); |
struct termp_tbl *); |
static void tbl_calc_data(const struct tbl *, |
static void tbl_calc_data_literal(struct termp *, |
const struct tbl_dat *, |
const struct tbl_dat *, |
struct termp_tbl *); |
struct termp_tbl *); |
static void tbl_calc_data_literal(const struct tbl_dat *, |
static void tbl_calc_data_number(struct termp *, |
struct termp_tbl *); |
const struct tbl *, |
static void tbl_calc_data_number(const struct tbl *, |
|
const struct tbl_dat *, |
const struct tbl_dat *, |
struct termp_tbl *); |
struct termp_tbl *); |
|
|
Line 77 term_tbl(struct termp *tp, const struct tbl_span *sp) |
|
Line 80 term_tbl(struct termp *tp, const struct tbl_span *sp) |
|
perror(NULL); |
perror(NULL); |
exit(EXIT_FAILURE); |
exit(EXIT_FAILURE); |
} |
} |
tbl_calc(sp, tp->tbl); |
tbl_calc(tp, sp); |
term_flushln(tp); |
term_flushln(tp); |
} |
} |
|
|
Line 296 tbl_vframe(struct termp *tp, const struct tbl *tbl) |
|
Line 299 tbl_vframe(struct termp *tp, const struct tbl *tbl) |
|
static inline void |
static inline void |
tbl_char(struct termp *tp, char c, int len) |
tbl_char(struct termp *tp, char c, int len) |
{ |
{ |
int i; |
int i, sz; |
char cp[2]; |
char cp[2]; |
|
|
cp[0] = c; |
cp[0] = c; |
cp[1] = '\0'; |
cp[1] = '\0'; |
|
|
for (i = 0; i < len; i++) |
sz = term_strlen(tp, cp); |
|
|
|
for (i = 0; i < len; i += sz) |
term_word(tp, cp); |
term_word(tp, cp); |
} |
} |
|
|
Line 331 tbl_data_literal(struct termp *tp, |
|
Line 336 tbl_data_literal(struct termp *tp, |
|
const struct tbl_dat *dp, |
const struct tbl_dat *dp, |
const struct termp_tbl *tblp) |
const struct termp_tbl *tblp) |
{ |
{ |
int padl, padr; |
int padl, padr, ssz; |
enum tbl_cellt pos; |
enum tbl_cellt pos; |
|
|
padl = padr = 0; |
padl = padr = 0; |
|
|
pos = dp->layout ? dp->layout->pos : TBL_CELL_LEFT; |
pos = dp->layout ? dp->layout->pos : TBL_CELL_LEFT; |
|
ssz = term_len(tp, 1); |
|
|
switch (pos) { |
switch (pos) { |
case (TBL_CELL_LONG): |
case (TBL_CELL_LONG): |
padl = 1; |
padl = ssz; |
padr = tblp->width - (int)strlen(dp->string) - 1; |
padr = tblp->width - term_strlen(tp, dp->string) - ssz; |
break; |
break; |
case (TBL_CELL_CENTRE): |
case (TBL_CELL_CENTRE): |
padl = tblp->width - (int)strlen(dp->string); |
padl = tblp->width - term_strlen(tp, dp->string); |
if (padl % 2) |
if (padl % 2) |
padr++; |
padr++; |
padl /= 2; |
padl /= 2; |
padr += padl; |
padr += padl; |
break; |
break; |
case (TBL_CELL_RIGHT): |
case (TBL_CELL_RIGHT): |
padl = tblp->width - (int)strlen(dp->string); |
padl = tblp->width - term_strlen(tp, dp->string); |
break; |
break; |
default: |
default: |
padr = tblp->width - (int)strlen(dp->string); |
padr = tblp->width - term_strlen(tp, dp->string); |
break; |
break; |
} |
} |
|
|
Line 368 tbl_data_number(struct termp *tp, const struct tbl *tb |
|
Line 374 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, pnt; |
char *decp; |
int d, padl, sz; |
int d, padl, sz; |
|
|
/* |
/* |
Line 377 tbl_data_number(struct termp *tp, const struct tbl *tb |
|
Line 383 tbl_data_number(struct termp *tp, const struct tbl *tb |
|
*/ |
*/ |
|
|
sz = (int)strlen(dp->string); |
sz = (int)strlen(dp->string); |
pnt = tbl->decimal; |
|
|
|
if (NULL == (decp = strchr(dp->string, pnt))) { |
if (NULL == (decp = strchr(dp->string, tbl->decimal))) { |
d = sz + 1; |
d = sz + 1; |
} else { |
} else { |
d = (int)(decp - dp->string) + 1; |
d = (int)(decp - dp->string) + 1; |
Line 397 tbl_data_number(struct termp *tp, const struct tbl *tb |
|
Line 402 tbl_data_number(struct termp *tp, const struct tbl *tb |
|
} |
} |
|
|
static void |
static void |
tbl_calc(const struct tbl_span *sp, struct termp_tbl *tblp) |
tbl_calc(struct termp *tp, const struct tbl_span *sp) |
{ |
{ |
const struct tbl_dat *dp; |
const struct tbl_dat *dp; |
const struct tbl_head *hp; |
const struct tbl_head *hp; |
Line 419 tbl_calc(const struct tbl_span *sp, struct termp_tbl * |
|
Line 424 tbl_calc(const struct tbl_span *sp, struct termp_tbl * |
|
for (dp = sp->first; dp; dp = dp->next) { |
for (dp = sp->first; dp; dp = dp->next) { |
if (NULL == dp->layout) |
if (NULL == dp->layout) |
continue; |
continue; |
p = &tblp[dp->layout->head->ident]; |
p = &tp->tbl[dp->layout->head->ident]; |
tbl_calc_data(sp->tbl, dp, p); |
tbl_calc_data(tp, sp->tbl, dp, p); |
} |
} |
} |
} |
|
|
Line 429 tbl_calc(const struct tbl_span *sp, struct termp_tbl * |
|
Line 434 tbl_calc(const struct tbl_span *sp, struct termp_tbl * |
|
for ( ; hp; hp = hp->next) |
for ( ; hp; hp = hp->next) |
switch (hp->pos) { |
switch (hp->pos) { |
case (TBL_HEAD_VERT): |
case (TBL_HEAD_VERT): |
tblp[hp->ident].width = 1; |
tp->tbl[hp->ident].width = term_len(tp, 1); |
break; |
break; |
case (TBL_HEAD_DVERT): |
case (TBL_HEAD_DVERT): |
tblp[hp->ident].width = 2; |
tp->tbl[hp->ident].width = term_len(tp, 2); |
break; |
break; |
default: |
default: |
break; |
break; |
Line 440 tbl_calc(const struct tbl_span *sp, struct termp_tbl * |
|
Line 445 tbl_calc(const struct tbl_span *sp, struct termp_tbl * |
|
} |
} |
|
|
static void |
static void |
tbl_calc_data(const struct tbl *tbl, |
tbl_calc_data(struct termp *tp, const struct tbl *tbl, |
const struct tbl_dat *dp, |
const struct tbl_dat *dp, struct termp_tbl *tblp) |
struct termp_tbl *tblp) |
|
{ |
{ |
|
|
/* Branch down into data sub-types. */ |
/* Branch down into data sub-types. */ |
Line 460 tbl_calc_data(const struct tbl *tbl, |
|
Line 464 tbl_calc_data(const struct tbl *tbl, |
|
case (TBL_CELL_LEFT): |
case (TBL_CELL_LEFT): |
/* FALLTHROUGH */ |
/* FALLTHROUGH */ |
case (TBL_CELL_RIGHT): |
case (TBL_CELL_RIGHT): |
tbl_calc_data_literal(dp, tblp); |
tbl_calc_data_literal(tp, dp, tblp); |
break; |
break; |
case (TBL_CELL_NUMBER): |
case (TBL_CELL_NUMBER): |
tbl_calc_data_number(tbl, dp, tblp); |
tbl_calc_data_number(tp, tbl, dp, tblp); |
break; |
break; |
default: |
default: |
abort(); |
abort(); |
Line 472 tbl_calc_data(const struct tbl *tbl, |
|
Line 476 tbl_calc_data(const struct tbl *tbl, |
|
} |
} |
|
|
static void |
static void |
tbl_calc_data_number(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; |
char *cp, pnt; |
char *cp; |
|
|
/* |
/* |
* First calculate number width and decimal place (last + 1 for |
* First calculate number width and decimal place (last + 1 for |
Line 491 tbl_calc_data_number(const struct tbl *tbl, |
|
Line 495 tbl_calc_data_number(const struct tbl *tbl, |
|
|
|
assert(dp->string); |
assert(dp->string); |
sz = (int)strlen(dp->string); |
sz = (int)strlen(dp->string); |
pnt = tbl->decimal; |
|
|
|
if (NULL == (cp = strchr(dp->string, pnt))) |
if (NULL == (cp = strchr(dp->string, tbl->decimal))) |
d = sz + 1; |
d = sz + 1; |
else |
else |
d = (int)(cp - dp->string) + 1; |
d = (int)(cp - dp->string) + 1; |
Line 513 tbl_calc_data_number(const struct tbl *tbl, |
|
Line 516 tbl_calc_data_number(const struct tbl *tbl, |
|
} |
} |
|
|
static void |
static void |
tbl_calc_data_literal(const struct tbl_dat *dp, struct termp_tbl *tblp) |
tbl_calc_data_literal(struct termp *tp, |
|
const struct tbl_dat *dp, |
|
struct termp_tbl *tblp) |
{ |
{ |
int sz, bufsz; |
int sz, bufsz; |
|
|
Line 524 tbl_calc_data_literal(const struct tbl_dat *dp, struct |
|
Line 529 tbl_calc_data_literal(const struct tbl_dat *dp, struct |
|
*/ |
*/ |
|
|
assert(dp->string); |
assert(dp->string); |
sz = (int)strlen(dp->string); |
sz = term_strlen(tp, dp->string); |
|
|
switch (dp->layout->pos) { |
switch (dp->layout->pos) { |
case (TBL_CELL_LONG): |
case (TBL_CELL_LONG): |