=================================================================== RCS file: /cvs/mandoc/tbl_term.c,v retrieving revision 1.11 retrieving revision 1.14 diff -u -p -r1.11 -r1.14 --- mandoc/tbl_term.c 2011/01/05 15:37:23 1.11 +++ mandoc/tbl_term.c 2011/01/08 17:00:27 1.14 @@ -1,4 +1,4 @@ -/* $Id: tbl_term.c,v 1.11 2011/01/05 15:37:23 kristaps Exp $ */ +/* $Id: tbl_term.c,v 1.14 2011/01/08 17:00:27 kristaps Exp $ */ /* * Copyright (c) 2009 Kristaps Dzonsons * @@ -27,12 +27,9 @@ #include "out.h" #include "term.h" -/* FIXME: `n' modifier doesn't always do the right thing. */ -/* FIXME: `n' modifier doesn't use the cell-spacing buffer. */ - static size_t term_tbl_len(size_t, void *); static size_t term_tbl_strlen(const char *, void *); -static void tbl_char(struct termp *, char, int); +static void tbl_char(struct termp *, char, size_t); static void tbl_data(struct termp *, const struct tbl *, const struct tbl_dat *, const struct roffcol *); @@ -67,7 +64,7 @@ term_tbl(struct termp *tp, const struct tbl_span *sp) const struct tbl_head *hp; const struct tbl_dat *dp; struct roffcol *col; - int rmargin, maxrmargin; + size_t rmargin, maxrmargin; rmargin = tp->rmargin; maxrmargin = tp->maxrmargin; @@ -165,7 +162,7 @@ tbl_hrule(struct termp *tp, const struct tbl_span *sp) { const struct tbl_head *hp; char c; - int width; + size_t width; /* * An hrule extends across the entire table and is demarked by a @@ -202,7 +199,7 @@ static void tbl_hframe(struct termp *tp, const struct tbl_span *sp) { const struct tbl_head *hp; - int width; + size_t width; if ( ! (TBL_OPT_BOX & sp->tbl->opts || TBL_OPT_DBOX & sp->tbl->opts)) @@ -272,7 +269,7 @@ tbl_data(struct termp *tp, const struct tbl *tbl, break; } - pos = dp->layout ? dp->layout->pos : TBL_CELL_LEFT; + pos = dp && dp->layout ? dp->layout->pos : TBL_CELL_LEFT; switch (pos) { case (TBL_CELL_HORIZ): @@ -324,11 +321,14 @@ tbl_vframe(struct termp *tp, const struct tbl *tbl) } static void -tbl_char(struct termp *tp, char c, int len) +tbl_char(struct termp *tp, char c, size_t len) { - int i, sz; - const char cp[2] = {c, '\0'}; + size_t i, sz; + char cp[2]; + cp[0] = c; + cp[1] = '\0'; + sz = term_strlen(tp, cp); for (i = 0; i < len; i += sz) @@ -339,36 +339,39 @@ static void tbl_literal(struct termp *tp, const struct tbl_dat *dp, const struct roffcol *col) { - int padl, padr, ssz; + size_t padl, padr, ssz; enum tbl_cellt pos; + const char *str; padl = padr = 0; - pos = dp->layout ? dp->layout->pos : TBL_CELL_LEFT; + pos = dp && dp->layout ? dp->layout->pos : TBL_CELL_LEFT; + str = dp && dp->string ? dp->string : ""; + ssz = term_len(tp, 1); switch (pos) { case (TBL_CELL_LONG): padl = ssz; - padr = col->width - term_strlen(tp, dp->string) - ssz; + padr = col->width - term_strlen(tp, str) - ssz; break; case (TBL_CELL_CENTRE): - padl = col->width - term_strlen(tp, dp->string); + padl = col->width - term_strlen(tp, str); if (padl % 2) padr++; padl /= 2; padr += padl; break; case (TBL_CELL_RIGHT): - padl = col->width - term_strlen(tp, dp->string); + padl = col->width - term_strlen(tp, str); break; default: - padr = col->width - term_strlen(tp, dp->string); + padr = col->width - term_strlen(tp, str); break; } tbl_char(tp, ASCII_NBRSP, padl); - term_word(tp, dp->string); + term_word(tp, str); tbl_char(tp, ASCII_NBRSP, padr); } @@ -388,9 +391,7 @@ tbl_number(struct termp *tp, const struct tbl *tbl, * and the maximum decimal; right-pad by the remaining amount. */ - str = ""; - if (dp->string) - str = dp->string; + str = dp && dp->string ? dp->string : ""; sz = term_strlen(tp, str); @@ -415,7 +416,7 @@ tbl_number(struct termp *tp, const struct tbl *tbl, padl = col->decimal - d; tbl_char(tp, ASCII_NBRSP, padl); - term_word(tp, dp->string); + term_word(tp, str); tbl_char(tp, ASCII_NBRSP, col->width - sz - padl); }