aboutsummaryrefslogtreecommitdiffstatshomepage
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
commit5909cbca3fe375aeac1e2247b3f8edbaba32e56e (patch)
tree22379e2aa842475f26d517eadfe52749991a4340 /term.c
parent2aefdbffeeeeda1b600266dae034d7133292ad46 (diff)
downloadmandoc-5909cbca3fe375aeac1e2247b3f8edbaba32e56e.tar.gz
mandoc-5909cbca3fe375aeac1e2247b3f8edbaba32e56e.tar.zst
mandoc-5909cbca3fe375aeac1e2247b3f8edbaba32e56e.zip
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.c25
1 files changed, 18 insertions, 7 deletions
diff --git a/term.c b/term.c
index b4beb633..02f69d9f 100644
--- a/term.c
+++ b/term.c
@@ -1,4 +1,4 @@
-/* $Id: term.c,v 1.139 2010/05/24 21:51:20 schwarze Exp $ */
+/* $Id: term.c,v 1.140 2010/05/25 12:37:20 kristaps Exp $ */
/*
* Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se>
*
@@ -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;