summaryrefslogtreecommitdiffstats
path: root/term.c
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@openbsd.org>2017-06-14 01:31:26 +0000
committerIngo Schwarze <schwarze@openbsd.org>2017-06-14 01:31:26 +0000
commit309a80562f7c43b81a190188a3f46c2509dd0c26 (patch)
tree0ca524ad39e42c5d6ad2499c21781722b17f0b5d /term.c
parent28aefcdcb96546f06ba44462300a9e7edaa5e9be (diff)
downloadmandoc-309a80562f7c43b81a190188a3f46c2509dd0c26.tar.gz
implement the roff(7) \p (break output line) escape sequence
Diffstat (limited to 'term.c')
-rw-r--r--term.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/term.c b/term.c
index bbadef66..a7236f87 100644
--- a/term.c
+++ b/term.c
@@ -116,6 +116,7 @@ term_flushln(struct termp *p)
size_t jhy; /* last hyph before overflow w/r/t j */
size_t maxvis; /* output position of visible boundary */
int ntab; /* number of tabs to prepend */
+ int breakline; /* after this word */
vbl = (p->flags & TERMP_NOPAD) || p->tcol->offset < p->viscol ?
0 : p->tcol->offset - p->viscol;
@@ -155,7 +156,13 @@ term_flushln(struct termp *p)
*/
jhy = 0;
+ breakline = 0;
for (j = p->tcol->col; j < p->tcol->lastcol; j++) {
+ if (p->tcol->buf[j] == '\n') {
+ if ((p->flags & TERMP_BRIND) == 0)
+ breakline = 1;
+ continue;
+ }
if (p->tcol->buf[j] == ' ' || p->tcol->buf[j] == '\t')
break;
@@ -221,6 +228,8 @@ term_flushln(struct termp *p)
for ( ; p->tcol->col < p->tcol->lastcol; p->tcol->col++) {
if (vend > bp && jhy > 0 && p->tcol->col > jhy)
break;
+ if (p->tcol->buf[p->tcol->col] == '\n')
+ continue;
if (p->tcol->buf[p->tcol->col] == '\t')
break;
if (p->tcol->buf[p->tcol->col] == ' ') {
@@ -260,6 +269,26 @@ term_flushln(struct termp *p)
p->tcol->buf[p->tcol->col]);
}
vis = vend;
+
+ if (breakline == 0)
+ continue;
+
+ /* Explicitly requested output line break. */
+
+ if (p->flags & TERMP_MULTICOL)
+ return;
+
+ endline(p);
+ breakline = 0;
+ vis = vend = 0;
+
+ /* Re-establish indentation. */
+
+ vbl = p->tcol->offset;
+ maxvis = p->tcol->rmargin > vbl ?
+ p->tcol->rmargin - vbl : 0;
+ bp = !(p->flags & TERMP_NOBREAK) ? maxvis :
+ p->maxrmargin > vbl ? p->maxrmargin - vbl : 0;
}
/*
@@ -487,6 +516,9 @@ term_word(struct termp *p, const char *word)
case ESCAPE_FONTPREV:
term_fontlast(p);
continue;
+ case ESCAPE_BREAK:
+ bufferc(p, '\n');
+ continue;
case ESCAPE_NOSPACE:
if (p->flags & TERMP_BACKAFTER)
p->flags &= ~TERMP_BACKAFTER;