aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@openbsd.org>2017-06-04 18:50:35 +0000
committerIngo Schwarze <schwarze@openbsd.org>2017-06-04 18:50:35 +0000
commitab795e726e781905db61f736dacb3fbb0e35a301 (patch)
tree00d8e7751848ecf740e79624193cbb0809dff465
parentd019f1f6d4b986db56f6fa599968bc395d7ce072 (diff)
downloadmandoc-ab795e726e781905db61f736dacb3fbb0e35a301.tar.gz
mandoc-ab795e726e781905db61f736dacb3fbb0e35a301.tar.zst
mandoc-ab795e726e781905db61f736dacb3fbb0e35a301.zip
Make term_flushln() simpler and more robust:
Eliminate the "overstep" state variable. The information is already contained in "viscol". Minus 60 lines of code, no functional change intended.
-rw-r--r--man_term.c3
-rw-r--r--mdoc_term.c53
-rw-r--r--term.c87
-rw-r--r--term.h8
4 files changed, 42 insertions, 109 deletions
diff --git a/man_term.c b/man_term.c
index b090bc43..a32213fb 100644
--- a/man_term.c
+++ b/man_term.c
@@ -1,4 +1,4 @@
-/* $Id: man_term.c,v 1.200 2017/05/09 14:10:01 schwarze Exp $ */
+/* $Id: man_term.c,v 1.201 2017/06/04 18:50:35 schwarze Exp $ */
/*
* Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010-2015, 2017 Ingo Schwarze <schwarze@openbsd.org>
@@ -141,7 +141,6 @@ terminal_man(void *arg, const struct roff_man *man)
size_t save_defindent;
p = (struct termp *)arg;
- p->overstep = 0;
p->rmargin = p->maxrmargin = p->defrmargin;
term_tab_set(p, NULL);
term_tab_set(p, "T");
diff --git a/mdoc_term.c b/mdoc_term.c
index 77bb6be2..0f885f81 100644
--- a/mdoc_term.c
+++ b/mdoc_term.c
@@ -1,4 +1,4 @@
-/* $Id: mdoc_term.c,v 1.359 2017/06/01 19:05:37 schwarze Exp $ */
+/* $Id: mdoc_term.c,v 1.360 2017/06/04 18:50:35 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010, 2012-2017 Ingo Schwarze <schwarze@openbsd.org>
@@ -259,7 +259,6 @@ terminal_mdoc(void *arg, const struct roff_man *mdoc)
size_t save_defindent;
p = (struct termp *)arg;
- p->overstep = 0;
p->rmargin = p->maxrmargin = p->defrmargin;
term_tab_set(p, NULL);
term_tab_set(p, "T");
@@ -765,33 +764,15 @@ termp_it_pre(DECL_ARGS)
case LIST_bullet:
case LIST_dash:
case LIST_hyphen:
- /*
- * Weird special case.
- * Some very narrow lists actually hang.
- */
- if (width <= (int)term_len(p, 2))
- p->flags |= TERMP_HANG;
- if (n->type != ROFFT_HEAD)
- break;
- p->flags |= TERMP_NOBREAK;
- p->trailspace = 1;
+ if (n->type == ROFFT_HEAD) {
+ p->flags |= TERMP_NOBREAK | TERMP_HANG;
+ p->trailspace = 1;
+ } else if (width <= (int)term_len(p, 2))
+ p->flags |= TERMP_NOPAD;
break;
case LIST_hang:
if (n->type != ROFFT_HEAD)
break;
-
- /*
- * This is ugly. If `-hang' is specified and the body
- * is a `Bl' or `Bd', then we want basically to nullify
- * the "overstep" effect in term_flushln() and treat
- * this as a `-ohang' list instead.
- */
- if (NULL != n->next &&
- NULL != n->next->child &&
- (MDOC_Bl == n->next->child->tok ||
- MDOC_Bd == n->next->child->tok))
- break;
-
p->flags |= TERMP_NOBREAK | TERMP_BRIND | TERMP_HANG;
p->trailspace = 1;
break;
@@ -803,7 +784,7 @@ termp_it_pre(DECL_ARGS)
p->trailspace = 2;
if (NULL == n->next || NULL == n->next->child)
- p->flags |= TERMP_DANGLE;
+ p->flags |= TERMP_HANG;
break;
case LIST_column:
if (n->type == ROFFT_HEAD)
@@ -837,23 +818,11 @@ termp_it_pre(DECL_ARGS)
p->offset += offset;
switch (type) {
- case LIST_hang:
- /*
- * Same stipulation as above, regarding `-hang'. We
- * don't want to recalculate rmargin and offsets when
- * using `Bd' or `Bl' within `-hang' overstep lists.
- */
- if (n->type == ROFFT_HEAD &&
- NULL != n->next &&
- NULL != n->next->child &&
- (MDOC_Bl == n->next->child->tok ||
- MDOC_Bd == n->next->child->tok))
- break;
- /* FALLTHROUGH */
case LIST_bullet:
case LIST_dash:
case LIST_enum:
case LIST_hyphen:
+ case LIST_hang:
case LIST_tag:
if (n->type == ROFFT_HEAD)
p->rmargin = p->offset + width;
@@ -920,6 +889,7 @@ termp_it_pre(DECL_ARGS)
case LIST_column:
if (n->type == ROFFT_HEAD)
return 0;
+ p->minbl = 0;
break;
default:
break;
@@ -960,8 +930,7 @@ termp_it_post(DECL_ARGS)
* has munged them in the meanwhile.
*/
- p->flags &= ~(TERMP_NOBREAK | TERMP_BRTRSP | TERMP_BRIND |
- TERMP_DANGLE | TERMP_HANG);
+ p->flags &= ~(TERMP_NOBREAK | TERMP_BRTRSP | TERMP_BRIND | TERMP_HANG);
p->trailspace = 0;
}
@@ -1381,6 +1350,7 @@ termp_fn_pre(DECL_ARGS)
if (pretty) {
term_flushln(p);
p->flags &= ~(TERMP_NOBREAK | TERMP_BRIND | TERMP_HANG);
+ p->flags |= TERMP_NOPAD;
p->offset = p->rmargin;
p->rmargin = rmargin;
}
@@ -1859,6 +1829,7 @@ termp_fo_pre(DECL_ARGS)
term_flushln(p);
p->flags &= ~(TERMP_NOBREAK | TERMP_BRIND |
TERMP_HANG);
+ p->flags |= TERMP_NOPAD;
p->offset = p->rmargin;
p->rmargin = rmargin;
}
diff --git a/term.c b/term.c
index afd5951a..3918f7d4 100644
--- a/term.c
+++ b/term.c
@@ -1,4 +1,4 @@
-/* $Id: term.c,v 1.262 2017/06/02 19:21:23 schwarze Exp $ */
+/* $Id: term.c,v 1.263 2017/06/04 18:50:35 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010-2017 Ingo Schwarze <schwarze@openbsd.org>
@@ -84,11 +84,11 @@ term_end(struct termp *p)
* to be broken, start the next line at the right margin instead
* of at the offset. Used together with TERMP_NOBREAK for the tags
* in various kinds of tagged lists.
- * - TERMP_DANGLE: Do not break the output line at the right margin,
+ * - TERMP_HANG: Do not break the output line at the right margin,
* append the next chunk after it even if this one is too long.
* To be used together with TERMP_NOBREAK.
- * - TERMP_HANG: Like TERMP_DANGLE, and also suppress padding before
- * the next chunk if this column is not full.
+ * - TERMP_NOPAD: Start writing at the current position,
+ * do not pad with blank characters up to the offset.
*/
void
term_flushln(struct termp *p)
@@ -104,34 +104,15 @@ term_flushln(struct termp *p)
size_t jhy; /* last hyph before overflow w/r/t j */
size_t maxvis; /* output position of visible boundary */
- /*
- * First, establish the maximum columns of "visible" content.
- * This is usually the difference between the right-margin and
- * an indentation, but can be, for tagged lists or columns, a
- * small set of values.
- *
- * The following unsigned-signed subtractions look strange,
- * but they are actually correct. If the int p->overstep
- * is negative, it gets sign extended. Subtracting that
- * very large size_t effectively adds a small number to dv.
- */
- dv = p->rmargin > p->offset ? p->rmargin - p->offset : 0;
- maxvis = (int)dv > p->overstep ? dv - (size_t)p->overstep : 0;
-
- if (p->flags & TERMP_NOBREAK) {
- dv = p->maxrmargin > p->offset ?
- p->maxrmargin - p->offset : 0;
- bp = (int)dv > p->overstep ?
- dv - (size_t)p->overstep : 0;
- } else
- bp = maxvis;
-
- /*
- * Calculate the required amount of padding.
- */
- vbl = p->offset + p->overstep > p->viscol ?
- p->offset + p->overstep - p->viscol : 0;
-
+ vbl = (p->flags & TERMP_NOPAD) || p->offset < p->viscol ? 0 :
+ p->offset - p->viscol;
+ if (p->minbl && vbl < p->minbl)
+ vbl = p->minbl;
+ maxvis = p->rmargin > p->viscol + vbl ?
+ p->rmargin - p->viscol - vbl : 0;
+ bp = !(p->flags & TERMP_NOBREAK) ? maxvis :
+ p->maxrmargin > p->viscol + vbl ?
+ p->maxrmargin - p->viscol - vbl : 0;
vis = vend = 0;
i = 0;
@@ -201,20 +182,13 @@ term_flushln(struct termp *p)
/* Re-establish indentation. */
- if (p->flags & TERMP_BRIND) {
+ if (p->flags & TERMP_BRIND)
vbl += p->rmargin;
- vend += p->rmargin - p->offset;
- } else
+ else
vbl += p->offset;
-
- /*
- * Remove the p->overstep width.
- * Again, if p->overstep is negative,
- * sign extension does the right thing.
- */
-
- bp += (size_t)p->overstep;
- p->overstep = 0;
+ maxvis = p->rmargin > vbl ? p->rmargin - vbl : 0;
+ bp = !(p->flags & TERMP_NOBREAK) ? maxvis :
+ p->maxrmargin > vbl ? p->maxrmargin - vbl : 0;
}
/* Write out the [remaining] word. */
@@ -269,32 +243,19 @@ term_flushln(struct termp *p)
vis = 0;
p->col = 0;
- p->overstep = 0;
- p->flags &= ~(TERMP_BACKAFTER | TERMP_BACKBEFORE);
+ p->flags &= ~(TERMP_BACKAFTER | TERMP_BACKBEFORE | TERMP_NOPAD);
if ( ! (TERMP_NOBREAK & p->flags)) {
p->viscol = 0;
+ p->minbl = 0;
(*p->endline)(p);
return;
}
if (TERMP_HANG & p->flags) {
- p->overstep += (int)(p->offset + vis - p->rmargin +
- p->trailspace * (*p->width)(p, ' '));
-
- /*
- * If we have overstepped the margin, temporarily move
- * it to the right and flag the rest of the line to be
- * shorter.
- * If there is a request to keep the columns together,
- * allow negative overstep when the column is not full.
- */
- if (p->trailspace && p->overstep < 0)
- p->overstep = 0;
- return;
-
- } else if (TERMP_DANGLE & p->flags)
+ p->minbl = p->trailspace;
return;
+ }
/* Trailing whitespace is significant in some columns. */
if (vis && vbl && (TERMP_BRTRSP & p->flags))
@@ -304,7 +265,9 @@ term_flushln(struct termp *p)
if (maxvis < vis + p->trailspace * (*p->width)(p, ' ')) {
(*p->endline)(p);
p->viscol = 0;
- }
+ p->minbl = 0;
+ } else
+ p->minbl = p->trailspace;
}
/*
diff --git a/term.h b/term.h
index 25600d42..ac5f5858 100644
--- a/term.h
+++ b/term.h
@@ -1,4 +1,4 @@
-/* $Id: term.h,v 1.121 2017/05/08 15:34:54 schwarze Exp $ */
+/* $Id: term.h,v 1.122 2017/06/04 18:50:35 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2011-2015, 2017 Ingo Schwarze <schwarze@openbsd.org>
@@ -67,7 +67,7 @@ struct termp {
size_t col; /* Bytes in buf. */
size_t viscol; /* Chars on current line. */
size_t trailspace; /* See termp_flushln(). */
- int overstep; /* See termp_flushln(). */
+ size_t minbl; /* Minimum blanks before next field. */
int ti; /* Temporary indent for one line. */
int skipvsp; /* Vertical space to skip. */
int flags;
@@ -82,8 +82,8 @@ struct termp {
#define TERMP_NOBREAK (1 << 8) /* See term_flushln(). */
#define TERMP_BRTRSP (1 << 9) /* See term_flushln(). */
#define TERMP_BRIND (1 << 10) /* See term_flushln(). */
-#define TERMP_DANGLE (1 << 11) /* See term_flushln(). */
-#define TERMP_HANG (1 << 12) /* See term_flushln(). */
+#define TERMP_HANG (1 << 11) /* See term_flushln(). */
+#define TERMP_NOPAD (1 << 12) /* See term_flushln(). */
#define TERMP_NOSPLIT (1 << 13) /* Do not break line before .An. */
#define TERMP_SPLIT (1 << 14) /* Break line before .An. */
#define TERMP_NONEWLINE (1 << 15) /* No line break in nofill mode. */