version 1.15, 2011/01/08 17:16:48 |
version 1.19, 2011/01/25 12:07:30 |
|
|
/* $Id$ */ |
/* $Id$ */ |
/* |
/* |
* Copyright (c) 2009 Kristaps Dzonsons <kristaps@kth.se> |
* Copyright (c) 2009, 2011 Kristaps Dzonsons <kristaps@kth.se> |
|
* Copyright (c) 2011 Ingo Schwarze <schwarze@openbsd.org> |
* |
* |
* Permission to use, copy, modify, and distribute this software for any |
* Permission to use, copy, modify, and distribute this software for any |
* purpose with or without fee is hereby granted, provided that the above |
* purpose with or without fee is hereby granted, provided that the above |
Line 64 term_tbl(struct termp *tp, const struct tbl_span *sp) |
|
Line 65 term_tbl(struct termp *tp, const struct tbl_span *sp) |
|
const struct tbl_head *hp; |
const struct tbl_head *hp; |
const struct tbl_dat *dp; |
const struct tbl_dat *dp; |
struct roffcol *col; |
struct roffcol *col; |
|
int spans; |
size_t rmargin, maxrmargin; |
size_t rmargin, maxrmargin; |
|
|
rmargin = tp->rmargin; |
rmargin = tp->rmargin; |
Line 115 term_tbl(struct termp *tp, const struct tbl_span *sp) |
|
Line 117 term_tbl(struct termp *tp, const struct tbl_span *sp) |
|
case (TBL_SPAN_DATA): |
case (TBL_SPAN_DATA): |
/* Iterate over template headers. */ |
/* Iterate over template headers. */ |
dp = sp->first; |
dp = sp->first; |
|
spans = 0; |
for (hp = sp->head; hp; hp = hp->next) { |
for (hp = sp->head; hp; hp = hp->next) { |
|
/* |
|
* If the current data header is invoked during |
|
* a spanner ("spans" > 0), don't emit anything |
|
* at all. |
|
*/ |
switch (hp->pos) { |
switch (hp->pos) { |
case (TBL_HEAD_VERT): |
case (TBL_HEAD_VERT): |
/* FALLTHROUGH */ |
/* FALLTHROUGH */ |
case (TBL_HEAD_DVERT): |
case (TBL_HEAD_DVERT): |
tbl_vrule(tp, hp); |
if (spans <= 0) |
|
tbl_vrule(tp, hp); |
continue; |
continue; |
case (TBL_HEAD_DATA): |
case (TBL_HEAD_DATA): |
break; |
break; |
} |
} |
|
|
|
if (--spans >= 0) |
|
continue; |
|
|
col = &tp->tbl.cols[hp->ident]; |
col = &tp->tbl.cols[hp->ident]; |
tbl_data(tp, sp->tbl, dp, col); |
tbl_data(tp, sp->tbl, dp, col); |
|
|
/* Go to the next data cell. */ |
/* |
if (dp) |
* Go to the next data cell and assign the |
|
* number of subsequent spans, if applicable. |
|
*/ |
|
|
|
if (dp) { |
|
spans = dp->spans; |
dp = dp->next; |
dp = dp->next; |
|
} |
} |
} |
break; |
break; |
} |
} |
Line 180 tbl_hrule(struct termp *tp, const struct tbl_span *sp) |
|
Line 198 tbl_hrule(struct termp *tp, const struct tbl_span *sp) |
|
width = tp->tbl.cols[hp->ident].width; |
width = tp->tbl.cols[hp->ident].width; |
switch (hp->pos) { |
switch (hp->pos) { |
case (TBL_HEAD_DATA): |
case (TBL_HEAD_DATA): |
|
if (hp->next) |
|
width += 2; |
tbl_char(tp, c, width); |
tbl_char(tp, c, width); |
break; |
break; |
case (TBL_HEAD_DVERT): |
case (TBL_HEAD_DVERT): |
Line 244 tbl_data(struct termp *tp, const struct tbl *tbl, |
|
Line 264 tbl_data(struct termp *tp, const struct tbl *tbl, |
|
const struct tbl_dat *dp, |
const struct tbl_dat *dp, |
const struct roffcol *col) |
const struct roffcol *col) |
{ |
{ |
enum tbl_cellt pos; |
|
|
|
if (NULL == dp) { |
if (NULL == dp) { |
tbl_char(tp, ASCII_NBRSP, col->width); |
tbl_char(tp, ASCII_NBRSP, col->width); |
return; |
return; |
} |
} |
|
assert(dp->layout); |
|
|
switch (dp->pos) { |
switch (dp->pos) { |
case (TBL_DATA_NONE): |
case (TBL_DATA_NONE): |
Line 269 tbl_data(struct termp *tp, const struct tbl *tbl, |
|
Line 289 tbl_data(struct termp *tp, const struct tbl *tbl, |
|
break; |
break; |
} |
} |
|
|
pos = dp && dp->layout ? dp->layout->pos : TBL_CELL_LEFT; |
switch (dp->layout->pos) { |
|
|
switch (pos) { |
|
case (TBL_CELL_HORIZ): |
case (TBL_CELL_HORIZ): |
tbl_char(tp, '-', col->width); |
tbl_char(tp, '-', col->width); |
break; |
break; |
Line 290 tbl_data(struct termp *tp, const struct tbl *tbl, |
|
Line 308 tbl_data(struct termp *tp, const struct tbl *tbl, |
|
case (TBL_CELL_NUMBER): |
case (TBL_CELL_NUMBER): |
tbl_number(tp, tbl, dp, col); |
tbl_number(tp, tbl, dp, col); |
break; |
break; |
|
case (TBL_CELL_DOWN): |
|
tbl_char(tp, ASCII_NBRSP, col->width); |
|
break; |
default: |
default: |
abort(); |
abort(); |
/* NOTREACHED */ |
/* NOTREACHED */ |
Line 340 tbl_literal(struct termp *tp, const struct tbl_dat *dp |
|
Line 361 tbl_literal(struct termp *tp, const struct tbl_dat *dp |
|
const struct roffcol *col) |
const struct roffcol *col) |
{ |
{ |
size_t padl, padr, ssz; |
size_t padl, padr, ssz; |
enum tbl_cellt pos; |
|
const char *str; |
|
|
|
padl = padr = 0; |
padl = padr = 0; |
|
|
pos = dp && dp->layout ? dp->layout->pos : TBL_CELL_LEFT; |
assert(dp->string); |
str = dp && dp->string ? dp->string : ""; |
|
|
|
ssz = term_len(tp, 1); |
ssz = term_len(tp, 1); |
|
|
switch (pos) { |
switch (dp->layout->pos) { |
case (TBL_CELL_LONG): |
case (TBL_CELL_LONG): |
padl = ssz; |
padl = ssz; |
padr = col->width - term_strlen(tp, str) - ssz; |
padr = col->width - term_strlen(tp, dp->string) - ssz; |
break; |
break; |
case (TBL_CELL_CENTRE): |
case (TBL_CELL_CENTRE): |
padl = col->width - term_strlen(tp, str); |
padr = col->width - term_strlen(tp, dp->string); |
if (padl % 2) |
if (3 > padr) |
padr++; |
break; |
padl /= 2; |
padl = (padr - 1) / 2; |
padr += padl; |
padr -= padl; |
break; |
break; |
case (TBL_CELL_RIGHT): |
case (TBL_CELL_RIGHT): |
padl = col->width - term_strlen(tp, str); |
padl = col->width - term_strlen(tp, dp->string); |
break; |
break; |
default: |
default: |
padr = col->width - term_strlen(tp, str); |
padr = col->width - term_strlen(tp, dp->string); |
break; |
break; |
} |
} |
|
|
tbl_char(tp, ASCII_NBRSP, padl); |
tbl_char(tp, ASCII_NBRSP, padl); |
term_word(tp, str); |
term_word(tp, dp->string); |
tbl_char(tp, ASCII_NBRSP, padr); |
tbl_char(tp, ASCII_NBRSP, padr + 2); |
} |
} |
|
|
static void |
static void |
Line 382 tbl_number(struct termp *tp, const struct tbl *tbl, |
|
Line 400 tbl_number(struct termp *tp, const struct tbl *tbl, |
|
{ |
{ |
char *cp; |
char *cp; |
char buf[2]; |
char buf[2]; |
const char *str; |
|
size_t sz, psz, ssz, d, padl; |
size_t sz, psz, ssz, d, padl; |
int i; |
int i; |
|
|
Line 391 tbl_number(struct termp *tp, const struct tbl *tbl, |
|
Line 408 tbl_number(struct termp *tp, const struct tbl *tbl, |
|
* and the maximum decimal; right-pad by the remaining amount. |
* and the maximum decimal; right-pad by the remaining amount. |
*/ |
*/ |
|
|
str = dp && dp->string ? dp->string : ""; |
assert(dp->string); |
|
|
sz = term_strlen(tp, str); |
sz = term_strlen(tp, dp->string); |
|
|
buf[0] = tbl->decimal; |
buf[0] = tbl->decimal; |
buf[1] = '\0'; |
buf[1] = '\0'; |
|
|
psz = term_strlen(tp, buf); |
psz = term_strlen(tp, buf); |
|
|
if (NULL != (cp = strrchr(str, tbl->decimal))) { |
if (NULL != (cp = strrchr(dp->string, tbl->decimal))) { |
buf[1] = '\0'; |
buf[1] = '\0'; |
for (ssz = 0, i = 0; cp != &str[i]; i++) { |
for (ssz = 0, i = 0; cp != &dp->string[i]; i++) { |
buf[0] = str[i]; |
buf[0] = dp->string[i]; |
ssz += term_strlen(tp, buf); |
ssz += term_strlen(tp, buf); |
} |
} |
d = ssz + psz; |
d = ssz + psz; |
Line 416 tbl_number(struct termp *tp, const struct tbl *tbl, |
|
Line 433 tbl_number(struct termp *tp, const struct tbl *tbl, |
|
padl = col->decimal - d; |
padl = col->decimal - d; |
|
|
tbl_char(tp, ASCII_NBRSP, padl); |
tbl_char(tp, ASCII_NBRSP, padl); |
term_word(tp, str); |
term_word(tp, dp->string); |
tbl_char(tp, ASCII_NBRSP, col->width - sz - padl); |
tbl_char(tp, ASCII_NBRSP, col->width - sz - padl); |
} |
} |
|
|