=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/mandoc/term.c,v retrieving revision 1.45 retrieving revision 1.46 diff -c -r1.45 -r1.46 *** src/usr.bin/mandoc/term.c 2010/07/25 18:05:54 1.45 --- src/usr.bin/mandoc/term.c 2010/07/31 21:43:07 1.46 *************** *** 1,4 **** ! /* $Id: term.c,v 1.45 2010/07/25 18:05:54 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010 Kristaps Dzonsons * Copyright (c) 2010 Ingo Schwarze --- 1,4 ---- ! /* $Id: term.c,v 1.46 2010/07/31 21:43:07 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010 Kristaps Dzonsons * Copyright (c) 2010 Ingo Schwarze *************** *** 33,39 **** 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); --- 33,38 ---- *************** *** 238,247 **** if ('\t' == p->buf[i]) break; if (' ' == p->buf[i]) { ! while (' ' == p->buf[i]) { ! vbl += (*p->width)(p, p->buf[i]); i++; ! } break; } if (ASCII_NBRSP == p->buf[i]) { --- 237,246 ---- if ('\t' == p->buf[i]) break; if (' ' == p->buf[i]) { ! j = i; ! while (' ' == p->buf[i]) i++; ! vbl += (i - j) * (*p->width)(p, ' '); break; } if (ASCII_NBRSP == p->buf[i]) { *************** *** 499,504 **** --- 498,505 ---- if ( ! (p->flags & TERMP_NONOSPACE)) p->flags &= ~TERMP_NOSPACE; + else + p->flags |= TERMP_NOSPACE; p->flags &= ~TERMP_SENTENCE; *************** *** 578,595 **** 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) { --- 579,584 ---- *************** *** 613,635 **** */ if (TERMFONT_NONE == (f = term_fonttop(p))) { ! buffera(p, word, sz); return; } for (i = 0; i < (int)sz; i++) { if ( ! isgraph((u_char)word[i])) { ! bufferc(p, word[i]); continue; } if (TERMFONT_UNDER == f) ! bufferc(p, '_'); else ! bufferc(p, word[i]); ! bufferc(p, 8); ! bufferc(p, word[i]); } } --- 602,632 ---- */ if (TERMFONT_NONE == (f = term_fonttop(p))) { ! 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])) { ! p->buf[(int)p->col++] = word[i]; continue; } if (TERMFONT_UNDER == f) ! p->buf[(int)p->col++] = '_'; else ! p->buf[(int)p->col++] = word[i]; ! p->buf[(int)p->col++] = 8; ! p->buf[(int)p->col++] = word[i]; } }