summaryrefslogtreecommitdiff
path: root/usr.bin/mandoc/term.c
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@cvs.openbsd.org>2010-07-31 21:43:08 +0000
committerIngo Schwarze <schwarze@cvs.openbsd.org>2010-07-31 21:43:08 +0000
commit3899aa7d9f9840170b2e9994620915755836cb36 (patch)
treefdd6b73a9dffcbaf843f41b1b41ea98aec410645 /usr.bin/mandoc/term.c
parent95555926e891428a659b23aaeaa8442245823c11 (diff)
Merge bsd.lv version 1.10.5: last larger batch of bug fixes before release.
NOT including Kristaps' .Bd -literal changes which cause regressions. Features: * -Tpdf now fully working Bugfixes: * proper handling of quoted strings by .ds in roff(7) * allow empty .Dd * make .Sm start no-spacing after the first output word * underline .Ad * minor fixes in -Thtml and some optimisations in terminal output.
Diffstat (limited to 'usr.bin/mandoc/term.c')
-rw-r--r--usr.bin/mandoc/term.c43
1 files changed, 20 insertions, 23 deletions
diff --git a/usr.bin/mandoc/term.c b/usr.bin/mandoc/term.c
index 231616c31c8..562a5250e6c 100644
--- a/usr.bin/mandoc/term.c
+++ b/usr.bin/mandoc/term.c
@@ -1,4 +1,4 @@
-/* $Id: term.c,v 1.45 2010/07/25 18:05:54 schwarze Exp $ */
+/* $Id: term.c,v 1.46 2010/07/31 21:43:07 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010 Ingo Schwarze <schwarze@openbsd.org>
@@ -33,7 +33,6 @@
static void spec(struct termp *, enum roffdeco,
const char *, size_t);
static void res(struct termp *, const char *, size_t);
-static void buffera(struct termp *, const char *, size_t);
static void bufferc(struct termp *, char);
static void adjbuf(struct termp *p, size_t);
static void encode(struct termp *, const char *, size_t);
@@ -238,10 +237,10 @@ term_flushln(struct termp *p)
if ('\t' == p->buf[i])
break;
if (' ' == p->buf[i]) {
- while (' ' == p->buf[i]) {
- vbl += (*p->width)(p, p->buf[i]);
+ j = i;
+ while (' ' == p->buf[i])
i++;
- }
+ vbl += (i - j) * (*p->width)(p, ' ');
break;
}
if (ASCII_NBRSP == p->buf[i]) {
@@ -499,6 +498,8 @@ term_word(struct termp *p, const char *word)
if ( ! (p->flags & TERMP_NONOSPACE))
p->flags &= ~TERMP_NOSPACE;
+ else
+ p->flags |= TERMP_NOSPACE;
p->flags &= ~TERMP_SENTENCE;
@@ -578,18 +579,6 @@ adjbuf(struct termp *p, size_t sz)
static void
-buffera(struct termp *p, const char *word, size_t sz)
-{
-
- if (p->col + sz >= p->maxcols)
- adjbuf(p, p->col + sz);
-
- memcpy(&p->buf[(int)p->col], word, sz);
- p->col += sz;
-}
-
-
-static void
bufferc(struct termp *p, char c)
{
@@ -613,23 +602,31 @@ encode(struct termp *p, const char *word, size_t sz)
*/
if (TERMFONT_NONE == (f = term_fonttop(p))) {
- buffera(p, word, sz);
+ if (p->col + sz >= p->maxcols)
+ adjbuf(p, p->col + sz);
+ memcpy(&p->buf[(int)p->col], word, sz);
+ p->col += sz;
return;
}
+ /* Pre-buffer, assuming worst-case. */
+
+ if (p->col + 1 + (sz * 3) >= p->maxcols)
+ adjbuf(p, p->col + 1 + (sz * 3));
+
for (i = 0; i < (int)sz; i++) {
if ( ! isgraph((u_char)word[i])) {
- bufferc(p, word[i]);
+ p->buf[(int)p->col++] = word[i];
continue;
}
if (TERMFONT_UNDER == f)
- bufferc(p, '_');
+ p->buf[(int)p->col++] = '_';
else
- bufferc(p, word[i]);
+ p->buf[(int)p->col++] = word[i];
- bufferc(p, 8);
- bufferc(p, word[i]);
+ p->buf[(int)p->col++] = 8;
+ p->buf[(int)p->col++] = word[i];
}
}