summaryrefslogtreecommitdiff
path: root/usr.bin/mandoc
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@cvs.openbsd.org>2010-10-15 22:07:13 +0000
committerIngo Schwarze <schwarze@cvs.openbsd.org>2010-10-15 22:07:13 +0000
commit03f9528658b9980bc58601f12486110e970664e3 (patch)
tree55d0c90d725719de3e38e9282e0c91d907050fc1 /usr.bin/mandoc
parent56a239481b489459700a1c4c97b917ec0f01de16 (diff)
Move tbl width calculation from plain strlen to mandoc terminal width
calculation routines. This gives us mostly sane table column widths. "move forward" deraadt@
Diffstat (limited to 'usr.bin/mandoc')
-rw-r--r--usr.bin/mandoc/man_term.c4
-rw-r--r--usr.bin/mandoc/tbl.c6
-rw-r--r--usr.bin/mandoc/tbl.h4
-rw-r--r--usr.bin/mandoc/tbl_extern.h4
-rw-r--r--usr.bin/mandoc/tbl_term.c51
5 files changed, 34 insertions, 35 deletions
diff --git a/usr.bin/mandoc/man_term.c b/usr.bin/mandoc/man_term.c
index 5a9fd15c916..2e59ae68264 100644
--- a/usr.bin/mandoc/man_term.c
+++ b/usr.bin/mandoc/man_term.c
@@ -1,4 +1,4 @@
-/* $Id: man_term.c,v 1.48 2010/10/15 21:33:47 schwarze Exp $ */
+/* $Id: man_term.c,v 1.49 2010/10/15 22:07:12 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010 Kristaps Dzonsons <kristaps@bsd.lv>
*
@@ -838,7 +838,7 @@ pre_TS(DECL_ARGS)
if (MAN_BLOCK != n->type)
return(0);
- if ( ! tbl_close(n->data.TS, "<man>", n->line))
+ if ( ! tbl_close(p, n->data.TS, "<man>", n->line))
return(0);
tbl_write(p, n->data.TS);
diff --git a/usr.bin/mandoc/tbl.c b/usr.bin/mandoc/tbl.c
index 64e40fbb10a..57d3da90880 100644
--- a/usr.bin/mandoc/tbl.c
+++ b/usr.bin/mandoc/tbl.c
@@ -1,4 +1,4 @@
-/* $Id: tbl.c,v 1.2 2010/10/15 21:33:47 schwarze Exp $ */
+/* $Id: tbl.c,v 1.3 2010/10/15 22:07:12 schwarze Exp $ */
/*
* Copyright (c) 2009 Kristaps Dzonsons <kristaps@kth.se>
*
@@ -90,7 +90,7 @@ tbl_read(struct tbl *tbl, const char *f, int ln, const char *p, int len)
int
-tbl_close(struct tbl *tbl, const char *f, int ln)
+tbl_close(struct termp *p, struct tbl *tbl, const char *f, int ln)
{
if (TBL_PART_DATA != tbl->part)
@@ -98,7 +98,7 @@ tbl_close(struct tbl *tbl, const char *f, int ln)
if ( ! tbl_data_close(tbl, f, ln))
return(0);
#if 1
- return(tbl_calc_term(tbl));
+ return(tbl_calc_term(p, tbl));
#else
return(tbl_calc_tree(tbl));
#endif
diff --git a/usr.bin/mandoc/tbl.h b/usr.bin/mandoc/tbl.h
index 61a8d93849d..29ac777496f 100644
--- a/usr.bin/mandoc/tbl.h
+++ b/usr.bin/mandoc/tbl.h
@@ -1,4 +1,4 @@
-/* $Id: tbl.h,v 1.2 2010/10/15 21:33:47 schwarze Exp $ */
+/* $Id: tbl.h,v 1.3 2010/10/15 22:07:12 schwarze Exp $ */
/*
* Copyright (c) 2009 Kristaps Dzonsons <kristaps@kth.se>
*
@@ -26,7 +26,7 @@ void tbl_free(struct tbl *);
void tbl_reset(struct tbl *);
int tbl_read(struct tbl *, const char *, int, const char *, int);
-int tbl_close(struct tbl *, const char *, int);
+int tbl_close(struct termp *, struct tbl *, const char *, int);
int tbl_write(struct termp *, const struct tbl *);
__END_DECLS
diff --git a/usr.bin/mandoc/tbl_extern.h b/usr.bin/mandoc/tbl_extern.h
index 0def00b74fb..1c73041c92b 100644
--- a/usr.bin/mandoc/tbl_extern.h
+++ b/usr.bin/mandoc/tbl_extern.h
@@ -1,4 +1,4 @@
-/* $Id: tbl_extern.h,v 1.2 2010/10/15 21:33:47 schwarze Exp $ */
+/* $Id: tbl_extern.h,v 1.3 2010/10/15 22:07:12 schwarze Exp $ */
/*
* Copyright (c) 2009 Kristaps Dzonsons <kristaps@kth.se>
*
@@ -174,7 +174,7 @@ struct tbl_span *tbl_span_alloc(struct tbl *);
struct tbl_data *tbl_data_alloc(struct tbl_span *);
int tbl_write_term(struct termp *, const struct tbl *);
-int tbl_calc_term(struct tbl *);
+int tbl_calc_term(struct termp *, struct tbl *);
int tbl_write_tree(const struct tbl *);
int tbl_calc_tree(struct tbl *);
diff --git a/usr.bin/mandoc/tbl_term.c b/usr.bin/mandoc/tbl_term.c
index 969ff1f517d..41b5c6f9015 100644
--- a/usr.bin/mandoc/tbl_term.c
+++ b/usr.bin/mandoc/tbl_term.c
@@ -1,4 +1,4 @@
-/* $Id: tbl_term.c,v 1.2 2010/10/15 21:33:47 schwarze Exp $ */
+/* $Id: tbl_term.c,v 1.3 2010/10/15 22:07:12 schwarze Exp $ */
/*
* Copyright (c) 2009 Kristaps Dzonsons <kristaps@kth.se>
* Copyright (c) 2010 Ingo Schwarze <schwarze@openbsd.org>
@@ -29,10 +29,10 @@
/* FIXME: `n' modifier doesn't always do the right thing. */
/* FIXME: `n' modifier doesn't use the cell-spacing buffer. */
-static void calc_data(struct tbl_data *);
-static void calc_data_literal(struct tbl_data *);
-static void calc_data_number(struct tbl_data *);
-static void calc_data_spanner(struct tbl_data *);
+static void calc_data(struct termp *, struct tbl_data *);
+static void calc_data_literal(struct termp *, struct tbl_data *);
+static void calc_data_number(struct termp *, struct tbl_data *);
+static void calc_data_spanner(struct termp *, struct tbl_data *);
static inline void write_char(struct termp *, char, int);
static void write_data(struct termp *,
const struct tbl_data *, int);
@@ -119,7 +119,7 @@ tbl_write_term(struct termp *p, const struct tbl *tbl)
int
-tbl_calc_term(struct tbl *tbl)
+tbl_calc_term(struct termp *p, struct tbl *tbl)
{
struct tbl_span *span;
struct tbl_data *data;
@@ -137,7 +137,7 @@ tbl_calc_term(struct tbl *tbl)
if (TBL_DATA_NDHORIZ & span->flags)
continue;
TAILQ_FOREACH(data, &span->data, entries)
- calc_data(data);
+ calc_data(p, data);
}
/* Calculate width as the simple spanner value. */
@@ -145,10 +145,10 @@ tbl_calc_term(struct tbl *tbl)
TAILQ_FOREACH(head, &tbl->head, entries)
switch (head->pos) {
case (TBL_HEAD_VERT):
- head->width = 1;
+ head->width = term_len(p, 1);
break;
case (TBL_HEAD_DVERT):
- head->width = 2;
+ head->width = term_len(p, 2);
break;
default:
break;
@@ -247,16 +247,16 @@ write_vframe(struct termp *p, const struct tbl *tbl)
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. */
- data->cell->head->width = 1;
+ data->cell->head->width = term_len(p, 1);
}
static void
-calc_data_number(struct tbl_data *data)
+calc_data_number(struct termp *p, struct tbl_data *data)
{
int sz, d;
char *dp, pnt;
@@ -273,15 +273,14 @@ calc_data_number(struct tbl_data *data)
/* TODO: use spacing modifier. */
assert(data->string);
- sz = (int)strlen(data->string);
+ sz = (int)term_strlen(p, data->string);
pnt = data->span->tbl->decimal;
- if (NULL == (dp = strchr(data->string, pnt)))
- d = sz + 1;
- else
- d = (int)(dp - data->string) + 1;
+ dp = strchr(data->string, pnt);
+ d = dp ? sz - (int)term_strlen(p, dp) : sz;
+ d += term_len(p, 1);
- sz += 2;
+ sz += term_len(p, 2);
if (data->cell->head->decimal > d) {
sz += data->cell->head->decimal - d;
@@ -298,7 +297,7 @@ calc_data_number(struct tbl_data *data)
static void
-calc_data_literal(struct tbl_data *data)
+calc_data_literal(struct termp *p, struct tbl_data *data)
{
int sz, bufsz;
@@ -309,7 +308,7 @@ calc_data_literal(struct tbl_data *data)
*/
assert(data->string);
- sz = (int)strlen(data->string);
+ sz = (int)term_strlen(p, data->string);
switch (data->cell->pos) {
case (TBL_CELL_LONG):
@@ -326,21 +325,21 @@ calc_data_literal(struct tbl_data *data)
bufsz = bufsz > data->cell->spacing ?
bufsz : data->cell->spacing;
- sz += bufsz;
+ sz += term_len(p, bufsz);
if (data->cell->head->width < sz)
data->cell->head->width = sz;
}
static void
-calc_data(struct tbl_data *data)
+calc_data(struct termp *p, struct tbl_data *data)
{
switch (data->cell->pos) {
case (TBL_CELL_HORIZ):
/* FALLTHROUGH */
case (TBL_CELL_DHORIZ):
- calc_data_spanner(data);
+ calc_data_spanner(p, data);
break;
case (TBL_CELL_LONG):
/* FALLTHROUGH */
@@ -349,10 +348,10 @@ calc_data(struct tbl_data *data)
case (TBL_CELL_LEFT):
/* FALLTHROUGH */
case (TBL_CELL_RIGHT):
- calc_data_literal(data);
+ calc_data_literal(p, data);
break;
case (TBL_CELL_NUMBER):
- calc_data_number(data);
+ calc_data_number(p, data);
break;
default:
abort();
@@ -391,7 +390,7 @@ write_data_number(struct termp *p, const struct tbl_data *data, int width)
* 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;
if (NULL == (dp = strchr(data->string, pnt))) {