summaryrefslogtreecommitdiff
path: root/usr.bin/mandoc
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@cvs.openbsd.org>2010-10-15 21:33:48 +0000
committerIngo Schwarze <schwarze@cvs.openbsd.org>2010-10-15 21:33:48 +0000
commit56a239481b489459700a1c4c97b917ec0f01de16 (patch)
tree5969e34730c463b7bb85cad0e3a238328934df9f /usr.bin/mandoc
parenta0860bc09a735b13d5854525b2d78db8413c641d (diff)
Move tbl output from plain stdio to mandoc terminal output routines.
This fixes (1) all escape sequences and (2) some aspects of indentation. Table column widths are still way off, though. "move forward" deraadt@
Diffstat (limited to 'usr.bin/mandoc')
-rw-r--r--usr.bin/mandoc/man.c4
-rw-r--r--usr.bin/mandoc/man_action.c4
-rw-r--r--usr.bin/mandoc/man_term.c4
-rw-r--r--usr.bin/mandoc/tbl.c8
-rw-r--r--usr.bin/mandoc/tbl.h4
-rw-r--r--usr.bin/mandoc/tbl_data.c4
-rw-r--r--usr.bin/mandoc/tbl_extern.h4
-rw-r--r--usr.bin/mandoc/tbl_layout.c4
-rw-r--r--usr.bin/mandoc/tbl_option.c4
-rw-r--r--usr.bin/mandoc/tbl_term.c148
-rw-r--r--usr.bin/mandoc/tbl_tree.c4
11 files changed, 111 insertions, 81 deletions
diff --git a/usr.bin/mandoc/man.c b/usr.bin/mandoc/man.c
index 58ca126725b..f981ae68d5d 100644
--- a/usr.bin/mandoc/man.c
+++ b/usr.bin/mandoc/man.c
@@ -1,4 +1,4 @@
-/* $Id: man.c,v 1.41 2010/10/15 20:45:03 schwarze Exp $ */
+/* $Id: man.c,v 1.42 2010/10/15 21:33:47 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010 Kristaps Dzonsons <kristaps@bsd.lv>
*
@@ -26,6 +26,8 @@
#include "libman.h"
#include "libmandoc.h"
+#include "out.h"
+#include "term.h"
#include "tbl.h"
const char *const __man_macronames[MAN_MAX] = {
diff --git a/usr.bin/mandoc/man_action.c b/usr.bin/mandoc/man_action.c
index c823738bee3..a4a488ec05c 100644
--- a/usr.bin/mandoc/man_action.c
+++ b/usr.bin/mandoc/man_action.c
@@ -1,4 +1,4 @@
-/* $Id: man_action.c,v 1.25 2010/10/15 20:45:03 schwarze Exp $ */
+/* $Id: man_action.c,v 1.26 2010/10/15 21:33:47 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010 Kristaps Dzonsons <kristaps@bsd.lv>
*
@@ -23,6 +23,8 @@
#include "libman.h"
#include "libmandoc.h"
+#include "out.h"
+#include "term.h"
#include "tbl.h"
struct actions {
diff --git a/usr.bin/mandoc/man_term.c b/usr.bin/mandoc/man_term.c
index c3e03b39d2b..5a9fd15c916 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.47 2010/10/15 20:45:03 schwarze Exp $ */
+/* $Id: man_term.c,v 1.48 2010/10/15 21:33:47 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010 Kristaps Dzonsons <kristaps@bsd.lv>
*
@@ -841,7 +841,7 @@ pre_TS(DECL_ARGS)
if ( ! tbl_close(n->data.TS, "<man>", n->line))
return(0);
- tbl_write(n->data.TS);
+ tbl_write(p, n->data.TS);
return(0);
}
diff --git a/usr.bin/mandoc/tbl.c b/usr.bin/mandoc/tbl.c
index b0e5d6b951e..64e40fbb10a 100644
--- a/usr.bin/mandoc/tbl.c
+++ b/usr.bin/mandoc/tbl.c
@@ -1,4 +1,4 @@
-/* $Id: tbl.c,v 1.1 2010/10/15 19:20:03 schwarze Exp $ */
+/* $Id: tbl.c,v 1.2 2010/10/15 21:33:47 schwarze Exp $ */
/*
* Copyright (c) 2009 Kristaps Dzonsons <kristaps@kth.se>
*
@@ -23,6 +23,8 @@
#include <stdlib.h>
#include <string.h>
+#include "out.h"
+#include "term.h"
#include "tbl.h"
#include "tbl_extern.h"
@@ -104,11 +106,11 @@ tbl_close(struct tbl *tbl, const char *f, int ln)
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 --git a/usr.bin/mandoc/tbl.h b/usr.bin/mandoc/tbl.h
index d1830453511..61a8d93849d 100644
--- a/usr.bin/mandoc/tbl.h
+++ b/usr.bin/mandoc/tbl.h
@@ -1,4 +1,4 @@
-/* $Id: tbl.h,v 1.1 2010/10/15 19:20:03 schwarze Exp $ */
+/* $Id: tbl.h,v 1.2 2010/10/15 21:33:47 schwarze Exp $ */
/*
* Copyright (c) 2009 Kristaps Dzonsons <kristaps@kth.se>
*
@@ -27,7 +27,7 @@ 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_write(const struct tbl *);
+int tbl_write(struct termp *, const struct tbl *);
__END_DECLS
diff --git a/usr.bin/mandoc/tbl_data.c b/usr.bin/mandoc/tbl_data.c
index de900cb936b..6b87ae72583 100644
--- a/usr.bin/mandoc/tbl_data.c
+++ b/usr.bin/mandoc/tbl_data.c
@@ -1,4 +1,4 @@
-/* $Id: tbl_data.c,v 1.1 2010/10/15 19:20:03 schwarze Exp $ */
+/* $Id: tbl_data.c,v 1.2 2010/10/15 21:33:47 schwarze Exp $ */
/*
* Copyright (c) 2009 Kristaps Dzonsons <kristaps@kth.se>
*
@@ -22,6 +22,8 @@
#include <stdlib.h>
#include <string.h>
+#include "out.h"
+#include "term.h"
#include "tbl_extern.h"
/* FIXME: warn about losing data contents if cell is HORIZ. */
diff --git a/usr.bin/mandoc/tbl_extern.h b/usr.bin/mandoc/tbl_extern.h
index 123253e9b10..0def00b74fb 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.1 2010/10/15 19:20:03 schwarze Exp $ */
+/* $Id: tbl_extern.h,v 1.2 2010/10/15 21:33:47 schwarze Exp $ */
/*
* Copyright (c) 2009 Kristaps Dzonsons <kristaps@kth.se>
*
@@ -173,7 +173,7 @@ struct tbl_cell *tbl_cell_alloc(struct tbl_row *, enum tbl_cellt);
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 --git a/usr.bin/mandoc/tbl_layout.c b/usr.bin/mandoc/tbl_layout.c
index eb47c2b0026..d861c8da294 100644
--- a/usr.bin/mandoc/tbl_layout.c
+++ b/usr.bin/mandoc/tbl_layout.c
@@ -1,4 +1,4 @@
-/* $Id: tbl_layout.c,v 1.1 2010/10/15 19:20:03 schwarze Exp $ */
+/* $Id: tbl_layout.c,v 1.2 2010/10/15 21:33:47 schwarze Exp $ */
/*
* Copyright (c) 2009 Kristaps Dzonsons <kristaps@kth.se>
*
@@ -22,6 +22,8 @@
#include <stdlib.h>
#include <string.h>
+#include "out.h"
+#include "term.h"
#include "tbl_extern.h"
struct tbl_phrase {
diff --git a/usr.bin/mandoc/tbl_option.c b/usr.bin/mandoc/tbl_option.c
index 9362dd0c1bf..09cd3afd680 100644
--- a/usr.bin/mandoc/tbl_option.c
+++ b/usr.bin/mandoc/tbl_option.c
@@ -1,4 +1,4 @@
-/* $Id: tbl_option.c,v 1.1 2010/10/15 19:20:03 schwarze Exp $ */
+/* $Id: tbl_option.c,v 1.2 2010/10/15 21:33:47 schwarze Exp $ */
/*
* Copyright (c) 2009 Kristaps Dzonsons <kristaps@kth.se>
*
@@ -19,6 +19,8 @@
#include <stdlib.h>
#include <string.h>
+#include "out.h"
+#include "term.h"
#include "tbl_extern.h"
struct tbl_phrase {
diff --git a/usr.bin/mandoc/tbl_term.c b/usr.bin/mandoc/tbl_term.c
index 9548e11098e..969ff1f517d 100644
--- a/usr.bin/mandoc/tbl_term.c
+++ b/usr.bin/mandoc/tbl_term.c
@@ -1,6 +1,7 @@
-/* $Id: tbl_term.c,v 1.1 2010/10/15 19:20:03 schwarze Exp $ */
+/* $Id: tbl_term.c,v 1.2 2010/10/15 21:33:47 schwarze Exp $ */
/*
* Copyright (c) 2009 Kristaps Dzonsons <kristaps@kth.se>
+ * Copyright (c) 2010 Ingo Schwarze <schwarze@openbsd.org>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
@@ -21,6 +22,8 @@
#include <stdlib.h>
#include <string.h>
+#include "out.h"
+#include "term.h"
#include "tbl_extern.h"
/* FIXME: `n' modifier doesn't always do the right thing. */
@@ -30,19 +33,23 @@ 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 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 +60,12 @@ tbl_write_term(const struct tbl *tbl)
* were set when tbl_calc_term was called.
*/
+ term_newln(p);
+ p->flags |= TERMP_NOSPACE | 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 +75,14 @@ tbl_write_term(const struct tbl *tbl)
*/
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 +92,10 @@ tbl_write_term(const struct tbl *tbl)
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,13 +104,15 @@ tbl_write_term(const struct tbl *tbl)
/* 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 +159,7 @@ tbl_calc_term(struct tbl *tbl)
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 +179,13 @@ write_hrule(const struct tbl_span *span)
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 +196,7 @@ write_hrule(const struct tbl_span *span)
static void
-write_hframe(const struct tbl *tbl)
+write_hframe(struct termp *p, const struct tbl *tbl)
{
const struct tbl_head *head;
@@ -200,35 +212,37 @@ write_hframe(const struct tbl *tbl)
*/
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 +362,7 @@ calc_data(struct tbl_data *data)
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 +370,18 @@ write_data_spanner(const struct tbl_data *data, int width)
* 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;
@@ -393,14 +407,14 @@ write_data_number(const struct tbl_data *data, int width)
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 +423,41 @@ write_data_literal(const struct tbl_data *data, int width)
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 +465,7 @@ write_data(const struct tbl_data *data, int width)
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 +474,10 @@ write_data(const struct tbl_data *data, int width)
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 +487,34 @@ write_data(const struct tbl_data *data, int width)
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 --git a/usr.bin/mandoc/tbl_tree.c b/usr.bin/mandoc/tbl_tree.c
index a4cee3ab87d..e073c66aa2f 100644
--- a/usr.bin/mandoc/tbl_tree.c
+++ b/usr.bin/mandoc/tbl_tree.c
@@ -1,4 +1,4 @@
-/* $Id: tbl_tree.c,v 1.1 2010/10/15 19:20:03 schwarze Exp $ */
+/* $Id: tbl_tree.c,v 1.2 2010/10/15 21:33:47 schwarze Exp $ */
/*
* Copyright (c) 2009 Kristaps Dzonsons <kristaps@kth.se>
*
@@ -21,6 +21,8 @@
#include <stdlib.h>
#include <string.h>
+#include "out.h"
+#include "term.h"
#include "tbl_extern.h"
static const char * const htypes[TBL_HEAD_MAX] = {