diff -Naur mandoc-tbl-minglue/man_term.c mandoc-tbl-term/man_term.c --- mandoc-tbl-minglue/man_term.c Thu Oct 14 22:46:41 2010 +++ mandoc-tbl-term/man_term.c Thu Oct 14 22:49:10 2010 @@ -841,7 +841,7 @@ if ( ! tbl_close(n->data.TS, "", n->line)) return(0); - tbl_write(n->data.TS); + tbl_write(p, n->data.TS); return(0); } diff -Naur mandoc-tbl-minglue/tbl.c mandoc-tbl-term/tbl.c --- mandoc-tbl-minglue/tbl.c Wed Oct 13 00:29:08 2010 +++ mandoc-tbl-term/tbl.c Thu Oct 14 22:50:44 2010 @@ -23,6 +23,8 @@ #include #include +#include "out.h" +#include "term.h" #include "tbl.h" #include "tbl_extern.h" @@ -104,11 +106,11 @@ int -tbl_write(const struct tbl *tbl) +tbl_write(struct termp *p, const struct tbl *tbl) { #if 1 - return(tbl_write_term(tbl)); + return(tbl_write_term(p, tbl)); #else return(tbl_write_tree(tbl)); #endif diff -Naur mandoc-tbl-minglue/tbl.h mandoc-tbl-term/tbl.h --- mandoc-tbl-minglue/tbl.h Mon Sep 14 12:31:24 2009 +++ mandoc-tbl-term/tbl.h Thu Oct 14 22:50:54 2010 @@ -27,7 +27,7 @@ int tbl_read(struct tbl *, const char *, int, const char *, int); int tbl_close(struct tbl *, const char *, int); -int tbl_write(const struct tbl *); +int tbl_write(struct termp *, const struct tbl *); __END_DECLS diff -Naur mandoc-tbl-minglue/tbl_data.c mandoc-tbl-term/tbl_data.c --- mandoc-tbl-minglue/tbl_data.c Wed Oct 13 00:29:23 2010 +++ mandoc-tbl-term/tbl_data.c Thu Oct 14 23:01:09 2010 @@ -22,6 +22,8 @@ #include #include +#include "out.h" +#include "term.h" #include "tbl_extern.h" /* FIXME: warn about losing data contents if cell is HORIZ. */ diff -Naur mandoc-tbl-minglue/tbl_extern.h mandoc-tbl-term/tbl_extern.h --- mandoc-tbl-minglue/tbl_extern.h Wed Oct 13 00:29:50 2010 +++ mandoc-tbl-term/tbl_extern.h Thu Oct 14 23:00:42 2010 @@ -173,7 +173,7 @@ struct tbl_span *tbl_span_alloc(struct tbl *); struct tbl_data *tbl_data_alloc(struct tbl_span *); -int tbl_write_term(const struct tbl *); +int tbl_write_term(struct termp *, const struct tbl *); int tbl_calc_term(struct tbl *); int tbl_write_tree(const struct tbl *); int tbl_calc_tree(struct tbl *); diff -Naur mandoc-tbl-minglue/tbl_layout.c mandoc-tbl-term/tbl_layout.c --- mandoc-tbl-minglue/tbl_layout.c Wed Oct 13 00:30:00 2010 +++ mandoc-tbl-term/tbl_layout.c Thu Oct 14 23:01:22 2010 @@ -22,6 +22,8 @@ #include #include +#include "out.h" +#include "term.h" #include "tbl_extern.h" struct tbl_phrase { diff -Naur mandoc-tbl-minglue/tbl_option.c mandoc-tbl-term/tbl_option.c --- mandoc-tbl-minglue/tbl_option.c Wed Oct 13 00:30:09 2010 +++ mandoc-tbl-term/tbl_option.c Thu Oct 14 23:01:33 2010 @@ -19,6 +19,8 @@ #include #include +#include "out.h" +#include "term.h" #include "tbl_extern.h" struct tbl_phrase { diff -Naur mandoc-tbl-minglue/tbl_term.c mandoc-tbl-term/tbl_term.c --- mandoc-tbl-minglue/tbl_term.c Wed Oct 13 00:30:18 2010 +++ mandoc-tbl-term/tbl_term.c Thu Oct 14 22:55:13 2010 @@ -21,6 +21,8 @@ #include #include +#include "out.h" +#include "term.h" #include "tbl_extern.h" /* FIXME: `n' modifier doesn't always do the right thing. */ @@ -30,19 +32,23 @@ 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 inline void write_char(char, int); -static void write_data(const struct tbl_data *, int); -static void write_data_literal(const struct tbl_data *, int); -static void write_data_number(const struct tbl_data *, int); -static void write_data_spanner(const struct tbl_data *, int); -static void write_hframe(const struct tbl *); -static void write_hrule(const struct tbl_span *); -static void write_spanner(const struct tbl_head *); -static void write_vframe(const struct tbl *); +static inline void write_char(struct termp *, char, int); +static void write_data(struct termp *, + const struct tbl_data *, int); +static void write_data_literal(struct termp *, + const struct tbl_data *, int); +static void write_data_number(struct termp *, + const struct tbl_data *, int); +static void write_data_spanner(struct termp *, + const struct tbl_data *, int); +static void write_hframe(struct termp *, const struct tbl *); +static void write_hrule(struct termp *, const struct tbl_span *); +static void write_spanner(struct termp *, const struct tbl_head *); +static void write_vframe(struct termp *, const struct tbl *); int -tbl_write_term(const struct tbl *tbl) +tbl_write_term(struct termp *p, const struct tbl *tbl) { const struct tbl_span *span; const struct tbl_data *data; @@ -53,9 +59,11 @@ * were set when tbl_calc_term was called. */ + p->flags |= TERMP_NONOSPACE; + /* First, write out our head horizontal frame. */ - write_hframe(tbl); + write_hframe(p, tbl); /* * Iterate through each span, and inside, through the global @@ -65,14 +73,14 @@ */ TAILQ_FOREACH(span, &tbl->span, entries) { - write_vframe(tbl); + write_vframe(p, tbl); /* Accomodate for the horizontal rule. */ if (TBL_DATA_DHORIZ & span->flags || TBL_DATA_HORIZ & span->flags) { - write_hrule(span); - write_vframe(tbl); - printf("\n"); + write_hrule(p, span); + write_vframe(p, tbl); + term_flushln(p); continue; } @@ -82,10 +90,10 @@ case (TBL_HEAD_VERT): /* FALLTHROUGH */ case (TBL_HEAD_DVERT): - write_spanner(head); + write_spanner(p, head); break; case (TBL_HEAD_DATA): - write_data(data, head->width); + write_data(p, data, head->width); if (data) data = TAILQ_NEXT(data, entries); break; @@ -94,14 +102,16 @@ /* NOTREACHED */ } } - write_vframe(tbl); - printf("\n"); + write_vframe(p, tbl); + term_flushln(p); } /* Last, write out our tail horizontal frame. */ - write_hframe(tbl); + write_hframe(p, tbl); + p->flags &= ~TERMP_NONOSPACE; + return(1); } @@ -147,7 +157,7 @@ static void -write_hrule(const struct tbl_span *span) +write_hrule(struct termp *p, const struct tbl_span *span) { const struct tbl_head *head; char c; @@ -167,13 +177,13 @@ TAILQ_FOREACH(head, &span->tbl->head, entries) { switch (head->pos) { case (TBL_HEAD_DATA): - write_char(c, head->width); + write_char(p, c, head->width); break; case (TBL_HEAD_DVERT): - write_char('+', head->width); + write_char(p, '+', head->width); /* FALLTHROUGH */ case (TBL_HEAD_VERT): - write_char('+', head->width); + write_char(p, '+', head->width); break; default: abort(); @@ -184,7 +194,7 @@ static void -write_hframe(const struct tbl *tbl) +write_hframe(struct termp *p, const struct tbl *tbl) { const struct tbl_head *head; @@ -200,35 +210,37 @@ */ if (TBL_OPT_DBOX & tbl->opts) { - printf("+"); + term_word(p, "+"); TAILQ_FOREACH(head, &tbl->head, entries) - write_char('-', head->width); - printf("+\n"); + write_char(p, '-', head->width); + term_word(p, "+"); + term_flushln(p); } - printf("+"); + term_word(p, "+"); TAILQ_FOREACH(head, &tbl->head, entries) { switch (head->pos) { case (TBL_HEAD_DATA): - write_char('-', head->width); + write_char(p, '-', head->width); break; default: - write_char('+', head->width); + write_char(p, '+', head->width); break; } } - printf("+\n"); + term_word(p, "+"); + term_flushln(p); } static void -write_vframe(const struct tbl *tbl) +write_vframe(struct termp *p, const struct tbl *tbl) { /* Always just a single vertical line. */ if ( ! (TBL_OPT_BOX & tbl->opts || TBL_OPT_DBOX & tbl->opts)) return; - printf("|"); + term_word(p, "|"); } @@ -348,7 +360,7 @@ static void -write_data_spanner(const struct tbl_data *data, int width) +write_data_spanner(struct termp *p, const struct tbl_data *data, int width) { /* @@ -356,18 +368,18 @@ * layout) or as data. */ if (TBL_DATA_HORIZ & data->flags) - write_char('-', width); + write_char(p, '-', width); else if (TBL_DATA_DHORIZ & data->flags) - write_char('=', width); + write_char(p, '=', width); else if (TBL_CELL_HORIZ == data->cell->pos) - write_char('-', width); + write_char(p, '-', width); else if (TBL_CELL_DHORIZ == data->cell->pos) - write_char('=', width); + write_char(p, '=', width); } static void -write_data_number(const struct tbl_data *data, int width) +write_data_number(struct termp *p, const struct tbl_data *data, int width) { char *dp, pnt; int d, padl, sz; @@ -377,7 +389,7 @@ * 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))) { @@ -393,14 +405,14 @@ padl = data->cell->head->decimal - d + 1; assert(width - sz - padl); - write_char(' ', padl); - (void)printf("%s", data->string); - write_char(' ', width - sz - padl); + write_char(p, ' ', padl); + term_word(p, data->string); + write_char(p, ' ', width - sz - padl); } static void -write_data_literal(const struct tbl_data *data, int width) +write_data_literal(struct termp *p, const struct tbl_data *data, int width) { int padl, padr; @@ -409,41 +421,41 @@ switch (data->cell->pos) { case (TBL_CELL_LONG): padl = 1; - padr = width - (int)strlen(data->string) - 1; + padr = width - (int)term_strlen(p, data->string) - 1; break; case (TBL_CELL_CENTRE): - padl = width - (int)strlen(data->string); + padl = width - (int)term_strlen(p, data->string); if (padl % 2) padr++; padl /= 2; padr += padl; break; case (TBL_CELL_RIGHT): - padl = width - (int)strlen(data->string); + padl = width - (int)term_strlen(p, data->string); break; default: - padr = width - (int)strlen(data->string); + padr = width - (int)term_strlen(p, data->string); break; } - write_char(' ', padl); - (void)printf("%s", data->string); - write_char(' ', padr); + write_char(p, ' ', padl); + term_word(p, data->string); + write_char(p, ' ', padr); } static void -write_data(const struct tbl_data *data, int width) +write_data(struct termp *p, const struct tbl_data *data, int width) { if (NULL == data) { - write_char(' ', width); + write_char(p, ' ', width); return; } if (TBL_DATA_HORIZ & data->flags || TBL_DATA_DHORIZ & data->flags) { - write_data_spanner(data, width); + write_data_spanner(p, data, width); return; } @@ -451,7 +463,7 @@ case (TBL_CELL_HORIZ): /* FALLTHROUGH */ case (TBL_CELL_DHORIZ): - write_data_spanner(data, width); + write_data_spanner(p, data, width); break; case (TBL_CELL_LONG): /* FALLTHROUGH */ @@ -460,10 +472,10 @@ case (TBL_CELL_LEFT): /* FALLTHROUGH */ case (TBL_CELL_RIGHT): - write_data_literal(data, width); + write_data_literal(p, data, width); break; case (TBL_CELL_NUMBER): - write_data_number(data, width); + write_data_number(p, data, width); break; default: abort(); @@ -473,32 +485,34 @@ static void -write_spanner(const struct tbl_head *head) +write_spanner(struct termp *p, const struct tbl_head *head) { - char *p; + char *w; - p = NULL; + w = NULL; switch (head->pos) { case (TBL_HEAD_VERT): - p = "|"; + w = "|"; break; case (TBL_HEAD_DVERT): - p = "||"; + w = "||"; break; default: break; } assert(p); - printf("%s", p); + term_word(p, w); } static inline void -write_char(char c, int len) +write_char(struct termp *p, char c, int len) { int i; + static char w[2]; + w[0] = c; for (i = 0; i < len; i++) - printf("%c", c); + term_word(p, w); } diff -Naur mandoc-tbl-minglue/tbl_tree.c mandoc-tbl-term/tbl_tree.c --- mandoc-tbl-minglue/tbl_tree.c Wed Oct 13 00:30:28 2010 +++ mandoc-tbl-term/tbl_tree.c Thu Oct 14 23:01:46 2010 @@ -21,6 +21,8 @@ #include #include +#include "out.h" +#include "term.h" #include "tbl_extern.h" static const char * const htypes[TBL_HEAD_MAX] = {