=================================================================== RCS file: /cvs/mandoc/tbl_term.c,v retrieving revision 1.12 retrieving revision 1.15 diff -u -p -r1.12 -r1.15 --- mandoc/tbl_term.c 2011/01/07 13:20:58 1.12 +++ mandoc/tbl_term.c 2011/01/08 17:16:48 1.15 @@ -1,4 +1,4 @@ -/* $Id: tbl_term.c,v 1.12 2011/01/07 13:20:58 kristaps Exp $ */ +/* $Id: tbl_term.c,v 1.15 2011/01/08 17:16:48 kristaps Exp $ */ /* * Copyright (c) 2009 Kristaps Dzonsons * @@ -27,9 +27,6 @@ #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, size_t); @@ -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): @@ -344,34 +341,37 @@ tbl_literal(struct termp *tp, const struct tbl_dat *dp { 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); } @@ -391,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); @@ -402,7 +400,7 @@ tbl_number(struct termp *tp, const struct tbl *tbl, psz = term_strlen(tp, buf); - if (NULL != (cp = strchr(str, tbl->decimal))) { + if (NULL != (cp = strrchr(str, tbl->decimal))) { buf[1] = '\0'; for (ssz = 0, i = 0; cp != &str[i]; i++) { buf[0] = str[i]; @@ -418,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); }