From 5ff3d11b2e760657dd7adae6fb66cdc78ebd34ad Mon Sep 17 00:00:00 2001 From: Kristaps Dzonsons Date: Mon, 22 Jun 2009 12:04:05 +0000 Subject: Added "Spacing" part of "Punctuation and Spacing" in mandoc.1 manual. Fixed `Ds' meta-macro default width. Fixed -width and -offset "indent", "indent-two", and "left" widths. Fixed -width and -offset literal-word and numeric widths. Fixed off-by-one errors in whitespace output (schwarze@openbsd.org). --- term.c | 46 ++++++++++++++++++++++++---------------------- 1 file changed, 24 insertions(+), 22 deletions(-) (limited to 'term.c') diff --git a/term.c b/term.c index 41f606c2..ad42fc62 100644 --- a/term.c +++ b/term.c @@ -205,7 +205,7 @@ void term_flushln(struct termp *p) { int i, j; - size_t vsz, vis, maxvis, mmax, bp; + size_t vbl, vsz, vis, maxvis, mmax, bp; /* * First, establish the maximum columns of "visible" content. @@ -250,35 +250,37 @@ term_flushln(struct termp *p) } /* - * Do line-breaking. If we're greater than our - * break-point and already in-line, break to the next - * line and start writing. If we're at the line start, - * then write out the word (TODO: hyphenate) and break - * in a subsequent loop invocation. + * Choose the number of blanks to prepend: no blank at the + * beginning of a line, one between words -- but do not + * actually write them yet. */ + vbl = (size_t)(0 == vis ? 0 : 1); - if ( ! (TERMP_NOBREAK & p->flags)) { - if (vis && vis + vsz > bp) { - putchar('\n'); + /* + * Find out whether we would exceed the right margin. + * If so, break to the next line. (TODO: hyphenate) + * Otherwise, write the chosen number of blanks now. + */ + if (vis && vis + vbl + vsz > bp) { + putchar('\n'); + if (TERMP_NOBREAK & p->flags) { + for (j = 0; j < (int)p->rmargin; j++) + putchar(' '); + vis = p->rmargin - p->offset; + } else { for (j = 0; j < (int)p->offset; j++) putchar(' '); vis = 0; - } - } else if (vis && vis + vsz > bp) { - putchar('\n'); - for (j = 0; j < (int)p->rmargin; j++) + } + } else { + for (j = 0; j < (int)vbl; j++) putchar(' '); - vis = p->rmargin - p->offset; + vis += vbl; } /* - * Prepend a space if we're not already at the beginning - * of the line, then the word. + * Finally, write out the word. */ - - if (0 < vis++) - putchar(' '); - for ( ; i < (int)p->col; i++) { if (' ' == p->buf[i]) break; @@ -292,7 +294,7 @@ term_flushln(struct termp *p) * cause a newline and offset at the right margin. */ - if ((TERMP_NOBREAK & p->flags) && vis > maxvis) { + if ((TERMP_NOBREAK & p->flags) && vis >= maxvis) { if ( ! (TERMP_NONOBREAK & p->flags)) { putchar('\n'); for (i = 0; i < (int)p->rmargin; i++) @@ -309,7 +311,7 @@ term_flushln(struct termp *p) if (p->flags & TERMP_NOBREAK) { if ( ! (TERMP_NONOBREAK & p->flags)) - for ( ; vis <= maxvis; vis++) + for ( ; vis < maxvis; vis++) putchar(' '); } else putchar('\n'); -- cgit