From d0f1de7c988060895fa78550174754f334d3b8ff Mon Sep 17 00:00:00 2001 From: Ingo Schwarze Date: Mon, 24 May 2010 21:34:16 +0000 Subject: 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@ --- term.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) (limited to 'term.c') diff --git a/term.c b/term.c index 0424fb38..471056c4 100644 --- a/term.c +++ b/term.c @@ -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) @@ -170,6 +171,17 @@ term_flushln(struct termp *p) vis = vend = i = 0; 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 @@ -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++; -- cgit