version 1.2, 2010/10/15 21:33:47 |
version 1.3, 2010/10/15 22:07:12 |
|
|
/* FIXME: `n' modifier doesn't always do the right thing. */ |
/* FIXME: `n' modifier doesn't always do the right thing. */ |
/* FIXME: `n' modifier doesn't use the cell-spacing buffer. */ |
/* FIXME: `n' modifier doesn't use the cell-spacing buffer. */ |
|
|
static void calc_data(struct tbl_data *); |
static void calc_data(struct termp *, struct tbl_data *); |
static void calc_data_literal(struct tbl_data *); |
static void calc_data_literal(struct termp *, struct tbl_data *); |
static void calc_data_number(struct tbl_data *); |
static void calc_data_number(struct termp *, struct tbl_data *); |
static void calc_data_spanner(struct tbl_data *); |
static void calc_data_spanner(struct termp *, struct tbl_data *); |
static inline void write_char(struct termp *, char, int); |
static inline void write_char(struct termp *, char, int); |
static void write_data(struct termp *, |
static void write_data(struct termp *, |
const struct tbl_data *, int); |
const struct tbl_data *, int); |
|
|
|
|
|
|
int |
int |
tbl_calc_term(struct tbl *tbl) |
tbl_calc_term(struct termp *p, struct tbl *tbl) |
{ |
{ |
struct tbl_span *span; |
struct tbl_span *span; |
struct tbl_data *data; |
struct tbl_data *data; |
|
|
if (TBL_DATA_NDHORIZ & span->flags) |
if (TBL_DATA_NDHORIZ & span->flags) |
continue; |
continue; |
TAILQ_FOREACH(data, &span->data, entries) |
TAILQ_FOREACH(data, &span->data, entries) |
calc_data(data); |
calc_data(p, data); |
} |
} |
|
|
/* Calculate width as the simple spanner value. */ |
/* Calculate width as the simple spanner value. */ |
|
|
TAILQ_FOREACH(head, &tbl->head, entries) |
TAILQ_FOREACH(head, &tbl->head, entries) |
switch (head->pos) { |
switch (head->pos) { |
case (TBL_HEAD_VERT): |
case (TBL_HEAD_VERT): |
head->width = 1; |
head->width = term_len(p, 1); |
break; |
break; |
case (TBL_HEAD_DVERT): |
case (TBL_HEAD_DVERT): |
head->width = 2; |
head->width = term_len(p, 2); |
break; |
break; |
default: |
default: |
break; |
break; |
|
|
|
|
|
|
static void |
static void |
calc_data_spanner(struct tbl_data *data) |
calc_data_spanner(struct termp *p, struct tbl_data *data) |
{ |
{ |
|
|
/* N.B., these are horiz spanners (not vert) so always 1. */ |
/* N.B., these are horiz spanners (not vert) so always 1. */ |
data->cell->head->width = 1; |
data->cell->head->width = term_len(p, 1); |
} |
} |
|
|
|
|
static void |
static void |
calc_data_number(struct tbl_data *data) |
calc_data_number(struct termp *p, struct tbl_data *data) |
{ |
{ |
int sz, d; |
int sz, d; |
char *dp, pnt; |
char *dp, pnt; |
|
|
/* TODO: use spacing modifier. */ |
/* TODO: use spacing modifier. */ |
|
|
assert(data->string); |
assert(data->string); |
sz = (int)strlen(data->string); |
sz = (int)term_strlen(p, data->string); |
pnt = data->span->tbl->decimal; |
pnt = data->span->tbl->decimal; |
|
|
if (NULL == (dp = strchr(data->string, pnt))) |
dp = strchr(data->string, pnt); |
d = sz + 1; |
d = dp ? sz - (int)term_strlen(p, dp) : sz; |
else |
d += term_len(p, 1); |
d = (int)(dp - data->string) + 1; |
|
|
|
sz += 2; |
sz += term_len(p, 2); |
|
|
if (data->cell->head->decimal > d) { |
if (data->cell->head->decimal > d) { |
sz += data->cell->head->decimal - d; |
sz += data->cell->head->decimal - d; |
|
|
|
|
|
|
static void |
static void |
calc_data_literal(struct tbl_data *data) |
calc_data_literal(struct termp *p, struct tbl_data *data) |
{ |
{ |
int sz, bufsz; |
int sz, bufsz; |
|
|
|
|
*/ |
*/ |
|
|
assert(data->string); |
assert(data->string); |
sz = (int)strlen(data->string); |
sz = (int)term_strlen(p, data->string); |
|
|
switch (data->cell->pos) { |
switch (data->cell->pos) { |
case (TBL_CELL_LONG): |
case (TBL_CELL_LONG): |
|
|
bufsz = bufsz > data->cell->spacing ? |
bufsz = bufsz > data->cell->spacing ? |
bufsz : data->cell->spacing; |
bufsz : data->cell->spacing; |
|
|
sz += bufsz; |
sz += term_len(p, bufsz); |
if (data->cell->head->width < sz) |
if (data->cell->head->width < sz) |
data->cell->head->width = sz; |
data->cell->head->width = sz; |
} |
} |
|
|
|
|
static void |
static void |
calc_data(struct tbl_data *data) |
calc_data(struct termp *p, struct tbl_data *data) |
{ |
{ |
|
|
switch (data->cell->pos) { |
switch (data->cell->pos) { |
case (TBL_CELL_HORIZ): |
case (TBL_CELL_HORIZ): |
/* FALLTHROUGH */ |
/* FALLTHROUGH */ |
case (TBL_CELL_DHORIZ): |
case (TBL_CELL_DHORIZ): |
calc_data_spanner(data); |
calc_data_spanner(p, data); |
break; |
break; |
case (TBL_CELL_LONG): |
case (TBL_CELL_LONG): |
/* FALLTHROUGH */ |
/* FALLTHROUGH */ |
|
|
case (TBL_CELL_LEFT): |
case (TBL_CELL_LEFT): |
/* FALLTHROUGH */ |
/* FALLTHROUGH */ |
case (TBL_CELL_RIGHT): |
case (TBL_CELL_RIGHT): |
calc_data_literal(data); |
calc_data_literal(p, data); |
break; |
break; |
case (TBL_CELL_NUMBER): |
case (TBL_CELL_NUMBER): |
calc_data_number(data); |
calc_data_number(p, data); |
break; |
break; |
default: |
default: |
abort(); |
abort(); |
|
|
* and the maximum decimal; right-pad by the remaining amount. |
* and the maximum decimal; right-pad by the remaining amount. |
*/ |
*/ |
|
|
sz = (int)strlen(data->string); |
sz = (int)term_strlen(p, data->string); |
pnt = data->span->tbl->decimal; |
pnt = data->span->tbl->decimal; |
|
|
if (NULL == (dp = strchr(data->string, pnt))) { |
if (NULL == (dp = strchr(data->string, pnt))) { |