summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@openbsd.org>2010-05-24 21:51:20 +0000
committerIngo Schwarze <schwarze@openbsd.org>2010-05-24 21:51:20 +0000
commit4f3f2467baac85e3e184ff13cf9d87c8cad0e577 (patch)
tree5b6ae096c3fd5249306aeb28e32e346cd6957ca7
parente02845a612e170851ce8a57d88d5ddf83b80b3d6 (diff)
downloadmandoc-4f3f2467baac85e3e184ff13cf9d87c8cad0e577.tar.gz
mandoc-4f3f2467baac85e3e184ff13cf9d87c8cad0e577.tar.zst
mandoc-4f3f2467baac85e3e184ff13cf9d87c8cad0e577.zip
sync to OpenBSD:
save the visual cursor position in term_flushln() and use that to avoid multiple blank lines in nested lists while still putting subsequent empty list tags each on their own line; "go ahead" kristaps@
-rw-r--r--mdoc_term.c16
-rw-r--r--term.c16
-rw-r--r--term.h3
3 files changed, 21 insertions, 14 deletions
diff --git a/mdoc_term.c b/mdoc_term.c
index d3593093..3503483a 100644
--- a/mdoc_term.c
+++ b/mdoc_term.c
@@ -1,4 +1,4 @@
-/* $Id: mdoc_term.c,v 1.129 2010/05/24 21:34:16 schwarze Exp $ */
+/* $Id: mdoc_term.c,v 1.130 2010/05/24 21:51:20 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se>
*
@@ -1014,14 +1014,14 @@ termp_it_post(DECL_ARGS)
/* FALLTHROUGH */
case (LIST_inset):
if (MDOC_BODY == n->type)
- term_flushln(p);
+ term_newln(p);
break;
case (LIST_column):
if (MDOC_HEAD == n->type)
term_flushln(p);
break;
default:
- term_flushln(p);
+ term_newln(p);
break;
}
@@ -1633,11 +1633,9 @@ termp_bd_pre(DECL_ARGS)
for (nn = n->child; nn; nn = nn->next) {
p->flags |= TERMP_NOSPACE;
print_mdoc_node(p, pair, m, nn);
- if (NULL == nn->next)
- continue;
- if (nn->prev && nn->prev->line < nn->line)
- term_flushln(p);
- else if (NULL == nn->prev)
+ if (NULL == nn->prev ||
+ nn->prev->line < nn->line ||
+ NULL == nn->next)
term_flushln(p);
}
p->tabwidth = tabwidth;
@@ -1668,7 +1666,7 @@ termp_bd_post(DECL_ARGS)
p->rmargin = p->maxrmargin = TERM_MAXMARGIN;
p->flags |= TERMP_NOSPACE;
- term_flushln(p);
+ term_newln(p);
p->rmargin = rm;
p->maxrmargin = rmax;
diff --git a/term.c b/term.c
index 542ce27f..b4beb633 100644
--- a/term.c
+++ b/term.c
@@ -1,4 +1,4 @@
-/* $Id: term.c,v 1.138 2010/05/24 21:34:16 schwarze Exp $ */
+/* $Id: term.c,v 1.139 2010/05/24 21:51:20 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se>
*
@@ -207,10 +207,12 @@ term_flushln(struct termp *p)
vend -= vis;
putchar('\n');
if (TERMP_NOBREAK & p->flags) {
+ p->viscol = p->rmargin;
for (j = 0; j < (int)p->rmargin; j++)
putchar(' ');
vend += p->rmargin - p->offset;
} else {
+ p->viscol = 0;
vbl = p->offset;
}
@@ -251,9 +253,11 @@ term_flushln(struct termp *p)
if (vbl) {
for (j = 0; j < (int)vbl; j++)
putchar(' ');
+ p->viscol += vbl;
vbl = 0;
}
putchar(p->buf[i]);
+ p->viscol += 1;
}
vend += vbl;
vis = vend;
@@ -263,6 +267,7 @@ term_flushln(struct termp *p)
p->overstep = 0;
if ( ! (TERMP_NOBREAK & p->flags)) {
+ p->viscol = 0;
putchar('\n');
return;
}
@@ -294,11 +299,13 @@ term_flushln(struct termp *p)
/* Right-pad. */
if (maxvis > vis + /* LINTED */
- ((TERMP_TWOSPACE & p->flags) ? 1 : 0))
+ ((TERMP_TWOSPACE & p->flags) ? 1 : 0)) {
+ p->viscol += maxvis - vis;
for ( ; vis < maxvis; vis++)
putchar(' ');
- else { /* ...or newline break. */
+ } else { /* ...or newline break. */
putchar('\n');
+ p->viscol = p->rmargin;
for (i = 0; i < (int)p->rmargin; i++)
putchar(' ');
}
@@ -315,7 +322,7 @@ term_newln(struct termp *p)
{
p->flags |= TERMP_NOSPACE;
- if (0 == p->col) {
+ if (0 == p->col && 0 == p->viscol) {
p->flags &= ~TERMP_NOLPAD;
return;
}
@@ -335,6 +342,7 @@ term_vspace(struct termp *p)
{
term_newln(p);
+ p->viscol = 0;
putchar('\n');
}
diff --git a/term.h b/term.h
index f2ce1e08..09e24295 100644
--- a/term.h
+++ b/term.h
@@ -1,4 +1,4 @@
-/* $Id: term.h,v 1.56 2010/05/24 21:34:16 schwarze Exp $ */
+/* $Id: term.h,v 1.57 2010/05/24 21:51:20 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se>
*
@@ -39,6 +39,7 @@ struct termp {
size_t offset; /* Margin offest. */
size_t tabwidth; /* Distance of tab positions. */
size_t col; /* Bytes in buf. */
+ size_t viscol; /* Chars on current line. */
int overstep; /* See termp_flushln(). */
int flags;
#define TERMP_SENTENCE (1 << 1) /* Space before a sentence. */