summaryrefslogtreecommitdiffstats
path: root/term.c
diff options
context:
space:
mode:
authorKristaps Dzonsons <kristaps@bsd.lv>2010-05-25 12:37:20 +0000
committerKristaps Dzonsons <kristaps@bsd.lv>2010-05-25 12:37:20 +0000
commitbd60b6e6dde1b45c862a7cb7092e5a6985629c1f (patch)
tree1b4eb8fbcedf0b30869618fd4adb0e76fcc58f91 /term.c
parent67f57cab47c6371e6a42d8d6952b35485c7b0b85 (diff)
downloadmandoc-bd60b6e6dde1b45c862a7cb7092e5a6985629c1f.tar.gz
Modified version of Ingo Schwarze's patch for hyphen-breaking.
Breakable hyphens are cued in the back-ends (with ASCII_HYPH) and acted upon in term.c or ignored in html.c. Also cleaned up XML decl printing (no need for extra vars).
Diffstat (limited to 'term.c')
-rw-r--r--term.c23
1 files changed, 17 insertions, 6 deletions
diff --git a/term.c b/term.c
index a41162c4..03d1ec5b 100644
--- a/term.c
+++ b/term.c
@@ -138,6 +138,7 @@ term_flushln(struct termp *p)
size_t vend; /* end of word visual position on output */
size_t bp; /* visual right border position */
int j; /* temporary loop index */
+ int jhy; /* last hyphen before line overflow */
size_t maxvis, mmax;
/*
@@ -190,20 +191,23 @@ term_flushln(struct termp *p)
*/
/* LINTED */
- for ( ; j < (int)p->col; j++) {
+ for (jhy = 0; j < (int)p->col; j++) {
if ((j && ' ' == p->buf[j]) || '\t' == p->buf[j])
break;
- if (8 == p->buf[j])
- vend--;
- else
+ if (8 != p->buf[j]) {
+ if (vend > vis && vend < bp &&
+ ASCII_HYPH == p->buf[j])
+ jhy = j;
vend++;
+ } else
+ vend--;
}
/*
* Find out whether we would exceed the right margin.
* If so, break to the next line.
*/
- if (vend > bp && vis > 0) {
+ if (vend > bp && 0 == jhy && vis > 0) {
vend -= vis;
putchar('\n');
if (TERMP_NOBREAK & p->flags) {
@@ -231,6 +235,8 @@ term_flushln(struct termp *p)
/* Write out the [remaining] word. */
for ( ; i < (int)p->col; i++) {
+ if (vend > bp && jhy > 0 && i > jhy)
+ break;
if ('\t' == p->buf[i])
break;
if (' ' == p->buf[i]) {
@@ -256,7 +262,12 @@ term_flushln(struct termp *p)
p->viscol += vbl;
vbl = 0;
}
- putchar(p->buf[i]);
+
+ if (ASCII_HYPH == p->buf[i])
+ putchar('-');
+ else
+ putchar(p->buf[i]);
+
p->viscol += 1;
}
vend += vbl;