summaryrefslogtreecommitdiff
path: root/usr.bin/mandoc
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@cvs.openbsd.org>2022-08-15 10:21:02 +0000
committerIngo Schwarze <schwarze@cvs.openbsd.org>2022-08-15 10:21:02 +0000
commitcc3f5ab42691d8d80230e7fae6da937c2174b673 (patch)
tree409aba2a0d21e1b089ae6da97c1b1522da4c9936 /usr.bin/mandoc
parenta2e1901af1d98af23841b3b6f18b7e53ea8e1ec8 (diff)
In GNU, Heirloom, and Plan 9 roff, literal tab characters are
non-breakable in exactly the same way as "\ ". That is, the preceding word, the tab character, and the following word are always kept together on the same output line. If filling is enabled and an output line break is required before the end of the following word, the break occurs before the beginning of the preceding word. Make mandoc behave in the same way. Of course, using literal tab characters in filled text remains a bad idea, and the "WARNING: tab in filled text" remains unchanged.
Diffstat (limited to 'usr.bin/mandoc')
-rw-r--r--usr.bin/mandoc/term.c36
1 files changed, 16 insertions, 20 deletions
diff --git a/usr.bin/mandoc/term.c b/usr.bin/mandoc/term.c
index f89da26450e..b57296c45ce 100644
--- a/usr.bin/mandoc/term.c
+++ b/usr.bin/mandoc/term.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: term.c,v 1.146 2022/04/27 13:30:19 schwarze Exp $ */
+/* $OpenBSD: term.c,v 1.147 2022/08/15 10:21:01 schwarze Exp $ */
/*
* Copyright (c) 2010-2022 Ingo Schwarze <schwarze@openbsd.org>
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
@@ -266,22 +266,11 @@ term_fill(struct termp *p, size_t *nbr, size_t *vbr, size_t vtarget)
vis -= (*p->width)(p, p->tcol->buf[ic - 1]);
continue;
- case '\t': /* Normal ASCII whitespace. */
case ' ':
case ASCII_BREAK: /* Escape \: (breakpoint). */
- switch (p->tcol->buf[ic]) {
- case '\t':
- vn = term_tab_next(vis);
- break;
- case ' ':
- vn = vis + (*p->width)(p, ' ');
- break;
- case ASCII_BREAK:
- vn = vis;
- break;
- default:
- abort();
- }
+ vn = vis;
+ if (p->tcol->buf[ic] == ' ')
+ vn += (*p->width)(p, ' ');
/* Can break at the end of a word. */
if (breakline || vn > vtarget)
break;
@@ -315,12 +304,19 @@ term_fill(struct termp *p, size_t *nbr, size_t *vbr, size_t vtarget)
*vbr = vis;
continue;
- case ASCII_NBRSP: /* Non-breakable space. */
- p->tcol->buf[ic] = ' ';
- /* FALLTHROUGH */
- default: /* Printable character. */
+ default:
+ switch (p->tcol->buf[ic]) {
+ case '\t':
+ vis = term_tab_next(vis);
+ break;
+ case ASCII_NBRSP: /* Non-breakable space. */
+ p->tcol->buf[ic] = ' ';
+ /* FALLTHROUGH */
+ default: /* Printable character. */
+ vis += (*p->width)(p, p->tcol->buf[ic]);
+ break;
+ }
graph = 1;
- vis += (*p->width)(p, p->tcol->buf[ic]);
if (vis > vtarget && *nbr > 0)
return;
continue;