summaryrefslogtreecommitdiffstatshomepage
path: root/term.c
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@openbsd.org>2010-05-24 21:34:16 +0000
committerIngo Schwarze <schwarze@openbsd.org>2010-05-24 21:34:16 +0000
commite02845a612e170851ce8a57d88d5ddf83b80b3d6 (patch)
tree8f3fb70042dbabcf1eccb3b2d0d84b6d1a317e93 /term.c
parente47604840546989588e20d7885d0fba3897f3c00 (diff)
downloadmandoc-e02845a612e170851ce8a57d88d5ddf83b80b3d6.tar.gz
mandoc-e02845a612e170851ce8a57d88d5ddf83b80b3d6.tar.zst
mandoc-e02845a612e170851ce8a57d88d5ddf83b80b3d6.zip
Handle literal tab characters both in literal context (.Bd -literal)
and outside. In literal context, tab stops are at each eigth column; outside, they are at each fifth column. from OpenBSD mdoc_term.c rev. 1.75; "commit" kristaps@
Diffstat (limited to 'term.c')
-rw-r--r--term.c26
1 files changed, 23 insertions, 3 deletions
diff --git a/term.c b/term.c
index 1397418c..542ce27f 100644
--- a/term.c
+++ b/term.c
@@ -1,4 +1,4 @@
-/* $Id: term.c,v 1.137 2010/05/17 22:11:42 kristaps Exp $ */
+/* $Id: term.c,v 1.138 2010/05/24 21:34:16 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se>
*
@@ -84,6 +84,7 @@ term_alloc(enum termenc enc, size_t width)
perror(NULL);
exit(EXIT_FAILURE);
}
+ p->tabwidth = 5;
p->enc = enc;
/* Enforce some lower boundary. */
if (width < 60)
@@ -171,6 +172,17 @@ term_flushln(struct termp *p)
while (i < (int)p->col) {
/*
+ * Handle literal tab characters.
+ */
+ for (j = i; j < (int)p->col; j++) {
+ if ('\t' != p->buf[j])
+ break;
+ vend = (vis/p->tabwidth+1)*p->tabwidth;
+ vbl += vend - vis;
+ vis = vend;
+ }
+
+ /*
* Count up visible word characters. Control sequences
* (starting with the CSI) aren't counted. A space
* generates a non-printing word, which is valid (the
@@ -178,8 +190,8 @@ term_flushln(struct termp *p)
*/
/* LINTED */
- for (j = i; j < (int)p->col; j++) {
- if (j && ' ' == p->buf[j])
+ for ( ; j < (int)p->col; j++) {
+ if ((j && ' ' == p->buf[j]) || '\t' == p->buf[j])
break;
if (8 == p->buf[j])
vend--;
@@ -209,8 +221,16 @@ term_flushln(struct termp *p)
p->overstep = 0;
}
+ /*
+ * Skip leading tabs, they were handled above.
+ */
+ while (i < (int)p->col && '\t' == p->buf[i])
+ i++;
+
/* Write out the [remaining] word. */
for ( ; i < (int)p->col; i++) {
+ if ('\t' == p->buf[i])
+ break;
if (' ' == p->buf[i]) {
while (' ' == p->buf[i]) {
vbl++;