aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--man_term.c36
-rw-r--r--mdoc_term.c33
-rw-r--r--term.c59
-rw-r--r--term.h3
4 files changed, 58 insertions, 73 deletions
diff --git a/man_term.c b/man_term.c
index c7150153..219e0a2b 100644
--- a/man_term.c
+++ b/man_term.c
@@ -1,4 +1,4 @@
-/* $Id: man_term.c,v 1.116 2011/09/18 21:08:34 schwarze Exp $ */
+/* $Id: man_term.c,v 1.117 2011/09/19 22:36:16 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010, 2011 Ingo Schwarze <schwarze@openbsd.org>
@@ -245,6 +245,18 @@ pre_literal(DECL_ARGS)
else
mt->fl &= ~MANT_LITERAL;
+ /*
+ * Unlike .IP and .TP, .HP does not have a HEAD.
+ * So in case a second call to term_flushln() is needed,
+ * indentation has to be set up explicitly.
+ */
+ if (MAN_HP == n->parent->tok && p->rmargin < p->maxrmargin) {
+ p->offset = p->rmargin + 1;
+ p->rmargin = p->maxrmargin;
+ p->flags &= ~(TERMP_NOBREAK | TERMP_TWOSPACE);
+ p->flags |= TERMP_NOSPACE;
+ }
+
return(0);
}
@@ -431,7 +443,7 @@ pre_sp(DECL_ARGS)
static int
pre_HP(DECL_ARGS)
{
- size_t len;
+ size_t len, one;
int ival;
const struct man_node *nn;
@@ -456,8 +468,11 @@ pre_HP(DECL_ARGS)
if ((ival = a2width(p, nn->string)) >= 0)
len = (size_t)ival;
- if (0 == len)
- len = term_len(p, 1);
+ one = term_len(p, 1);
+ if (len > one)
+ len -= one;
+ else
+ len = one;
p->offset = mt->offset;
p->rmargin = mt->offset + len;
@@ -520,7 +535,6 @@ pre_IP(DECL_ARGS)
switch (n->type) {
case (MAN_BODY):
- p->flags |= TERMP_NOLPAD;
p->flags |= TERMP_NOSPACE;
break;
case (MAN_HEAD):
@@ -591,7 +605,6 @@ post_IP(DECL_ARGS)
break;
case (MAN_BODY):
term_newln(p);
- p->flags &= ~TERMP_NOLPAD;
break;
default:
break;
@@ -612,7 +625,6 @@ pre_TP(DECL_ARGS)
p->flags |= TERMP_NOBREAK;
break;
case (MAN_BODY):
- p->flags |= TERMP_NOLPAD;
p->flags |= TERMP_NOSPACE;
break;
case (MAN_BLOCK):
@@ -681,7 +693,6 @@ post_TP(DECL_ARGS)
break;
case (MAN_BODY):
term_newln(p);
- p->flags &= ~TERMP_NOLPAD;
break;
default:
break;
@@ -882,7 +893,7 @@ print_man_node(DECL_ARGS)
* -man doesn't have nested macros, we don't need to be
* more specific than this.
*/
- if (MANT_LITERAL & mt->fl &&
+ if (MANT_LITERAL & mt->fl && ! (TERMP_NOBREAK & p->flags) &&
(NULL == n->next ||
n->next->line > n->line)) {
rm = p->rmargin;
@@ -890,7 +901,6 @@ print_man_node(DECL_ARGS)
p->rmargin = p->maxrmargin = TERM_MAXMARGIN;
p->flags |= TERMP_NOSPACE;
term_flushln(p);
- p->flags &= ~TERMP_NOLPAD;
p->rmargin = rm;
p->maxrmargin = rmax;
}
@@ -972,7 +982,7 @@ print_man_foot(struct termp *p, const void *arg)
term_word(p, "");
term_flushln(p);
- p->flags |= TERMP_NOLPAD | TERMP_NOSPACE;
+ p->flags |= TERMP_NOSPACE;
p->offset = p->rmargin;
p->rmargin = p->maxrmargin;
p->flags &= ~TERMP_NOBREAK;
@@ -1019,7 +1029,7 @@ print_man_head(struct termp *p, const void *arg)
term_word(p, title);
term_flushln(p);
- p->flags |= TERMP_NOLPAD | TERMP_NOSPACE;
+ p->flags |= TERMP_NOSPACE;
p->offset = p->rmargin;
p->rmargin = p->offset + buflen + titlen < p->maxrmargin ?
p->maxrmargin - titlen : p->maxrmargin;
@@ -1029,7 +1039,7 @@ print_man_head(struct termp *p, const void *arg)
p->flags &= ~TERMP_NOBREAK;
if (p->rmargin + titlen <= p->maxrmargin) {
- p->flags |= TERMP_NOLPAD | TERMP_NOSPACE;
+ p->flags |= TERMP_NOSPACE;
p->offset = p->rmargin;
p->rmargin = p->maxrmargin;
term_word(p, title);
diff --git a/mdoc_term.c b/mdoc_term.c
index 0603b721..7f68c229 100644
--- a/mdoc_term.c
+++ b/mdoc_term.c
@@ -1,4 +1,4 @@
-/* $Id: mdoc_term.c,v 1.233 2011/07/22 10:50:46 kristaps Exp $ */
+/* $Id: mdoc_term.c,v 1.234 2011/09/19 22:36:16 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010 Ingo Schwarze <schwarze@openbsd.org>
@@ -435,7 +435,7 @@ print_mdoc_foot(struct termp *p, const void *arg)
p->offset = p->rmargin;
p->rmargin = p->maxrmargin - term_strlen(p, m->os);
- p->flags |= TERMP_NOLPAD | TERMP_NOSPACE;
+ p->flags |= TERMP_NOSPACE;
term_word(p, m->date);
term_flushln(p);
@@ -443,7 +443,7 @@ print_mdoc_foot(struct termp *p, const void *arg)
p->offset = p->rmargin;
p->rmargin = p->maxrmargin;
p->flags &= ~TERMP_NOBREAK;
- p->flags |= TERMP_NOLPAD | TERMP_NOSPACE;
+ p->flags |= TERMP_NOSPACE;
term_word(p, m->os);
term_flushln(p);
@@ -499,7 +499,7 @@ print_mdoc_head(struct termp *p, const void *arg)
p->offset = p->rmargin;
p->rmargin = p->maxrmargin - term_strlen(p, title);
- p->flags |= TERMP_NOLPAD | TERMP_NOSPACE;
+ p->flags |= TERMP_NOSPACE;
term_word(p, buf);
term_flushln(p);
@@ -507,7 +507,7 @@ print_mdoc_head(struct termp *p, const void *arg)
p->offset = p->rmargin;
p->rmargin = p->maxrmargin;
p->flags &= ~TERMP_NOBREAK;
- p->flags |= TERMP_NOLPAD | TERMP_NOSPACE;
+ p->flags |= TERMP_NOSPACE;
term_word(p, title);
term_flushln(p);
@@ -787,16 +787,11 @@ termp_it_pre(DECL_ARGS)
case (LIST_hyphen):
if (MDOC_HEAD == n->type)
p->flags |= TERMP_NOBREAK;
- else
- p->flags |= TERMP_NOLPAD;
break;
case (LIST_hang):
if (MDOC_HEAD == n->type)
p->flags |= TERMP_NOBREAK;
else
- p->flags |= TERMP_NOLPAD;
-
- if (MDOC_HEAD != n->type)
break;
/*
@@ -807,17 +802,14 @@ termp_it_pre(DECL_ARGS)
*/
if (n->next->child &&
(MDOC_Bl == n->next->child->tok ||
- MDOC_Bd == n->next->child->tok)) {
+ MDOC_Bd == n->next->child->tok))
p->flags &= ~TERMP_NOBREAK;
- p->flags &= ~TERMP_NOLPAD;
- } else
+ else
p->flags |= TERMP_HANG;
break;
case (LIST_tag):
if (MDOC_HEAD == n->type)
p->flags |= TERMP_NOBREAK | TERMP_TWOSPACE;
- else
- p->flags |= TERMP_NOLPAD;
if (MDOC_HEAD != n->type)
break;
@@ -833,10 +825,6 @@ termp_it_pre(DECL_ARGS)
else
p->flags |= TERMP_NOBREAK;
- assert(n->prev);
- if (MDOC_BODY == n->prev->type)
- p->flags |= TERMP_NOLPAD;
-
break;
case (LIST_diag):
if (MDOC_HEAD == n->type)
@@ -993,7 +981,6 @@ termp_it_post(DECL_ARGS)
p->flags &= ~TERMP_DANGLE;
p->flags &= ~TERMP_NOBREAK;
p->flags &= ~TERMP_TWOSPACE;
- p->flags &= ~TERMP_NOLPAD;
p->flags &= ~TERMP_HANG;
}
@@ -1009,7 +996,7 @@ termp_nm_pre(DECL_ARGS)
if (MDOC_BODY == n->type) {
if (NULL == n->child)
return(0);
- p->flags |= TERMP_NOLPAD | TERMP_NOSPACE;
+ p->flags |= TERMP_NOSPACE;
p->offset += term_len(p, 1) +
(NULL == n->prev->child ? term_strlen(p, m->name) :
MDOC_TEXT == n->prev->child->type ?
@@ -1054,10 +1041,8 @@ termp_nm_post(DECL_ARGS)
if (MDOC_HEAD == n->type && n->next->child) {
term_flushln(p);
p->flags &= ~(TERMP_NOBREAK | TERMP_HANG);
- } else if (MDOC_BODY == n->type && n->child) {
+ } else if (MDOC_BODY == n->type && n->child)
term_flushln(p);
- p->flags &= ~TERMP_NOLPAD;
- }
}
diff --git a/term.c b/term.c
index 75efa106..1ee33ece 100644
--- a/term.c
+++ b/term.c
@@ -1,4 +1,4 @@
-/* $Id: term.c,v 1.199 2011/09/18 21:18:19 schwarze Exp $ */
+/* $Id: term.c,v 1.200 2011/09/19 22:36:16 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010, 2011 Ingo Schwarze <schwarze@openbsd.org>
@@ -79,22 +79,18 @@ term_end(struct termp *p)
*
* The following flags may be specified:
*
- * - TERMP_NOLPAD: when beginning to write the line, don't left-pad the
- * offset value. This is useful when doing columnar lists where the
- * prior column has right-padded.
- *
* - TERMP_NOBREAK: this is the most important and is used when making
- * columns. In short: don't print a newline and instead pad to the
- * right margin. Used in conjunction with TERMP_NOLPAD.
+ * columns. In short: don't print a newline and instead expect the
+ * next call to do the padding up to the start of the next column.
*
- * - TERMP_TWOSPACE: when padding, make sure there are at least two
- * space characters of padding. Otherwise, rather break the line.
+ * - TERMP_TWOSPACE: make sure there is room for at least two space
+ * characters of padding. Otherwise, rather break the line.
*
* - TERMP_DANGLE: don't newline when TERMP_NOBREAK is specified and
* the line is overrun, and don't pad-right if it's underrun.
*
* - TERMP_HANG: like TERMP_DANGLE, but doesn't newline when
- * overruning, instead save the position and continue at that point
+ * overrunning, instead save the position and continue at that point
* when the next invocation.
*
* In-line line breaking:
@@ -134,9 +130,10 @@ term_flushln(struct termp *p)
bp = TERMP_NOBREAK & p->flags ? mmax : maxvis;
/*
- * Indent the first line of a paragraph.
+ * Calculate the required amount of padding.
*/
- vbl = p->flags & TERMP_NOLPAD ? (size_t)0 : p->offset;
+ vbl = p->offset + p->overstep > p->viscol ?
+ p->offset + p->overstep - p->viscol : 0;
vis = vend = 0;
i = 0;
@@ -236,10 +233,14 @@ term_flushln(struct termp *p)
if (ASCII_HYPH == p->buf[i]) {
(*p->letter)(p, '-');
p->viscol += (*p->width)(p, '-');
- } else {
- (*p->letter)(p, p->buf[i]);
- p->viscol += (*p->width)(p, p->buf[i]);
+ continue;
}
+
+ (*p->letter)(p, p->buf[i]);
+ if (8 == p->buf[i])
+ p->viscol -= (*p->width)(p, p->buf[i-1]);
+ else
+ p->viscol += (*p->width)(p, p->buf[i]);
}
vis = vend;
}
@@ -248,7 +249,8 @@ term_flushln(struct termp *p)
* If there was trailing white space, it was not printed;
* so reset the cursor position accordingly.
*/
- vis -= vbl;
+ if (vis)
+ vis -= vbl;
p->col = 0;
p->overstep = 0;
@@ -273,25 +275,18 @@ term_flushln(struct termp *p)
* move it one step LEFT and flag the rest of the line
* to be longer.
*/
- if (p->overstep >= -1) {
- assert((int)maxvis + p->overstep >= 0);
- maxvis += (size_t)p->overstep;
- } else
+ if (p->overstep < -1)
p->overstep = 0;
+ return;
} else if (TERMP_DANGLE & p->flags)
return;
- /* Right-pad. */
- if (maxvis > vis +
+ /* If the column was overrun, break the line. */
+ if (maxvis <= vis +
((TERMP_TWOSPACE & p->flags) ? (*p->width)(p, ' ') : 0)) {
- p->viscol += maxvis - vis;
- (*p->advance)(p, maxvis - vis);
- vis += (maxvis - vis);
- } else { /* ...or newline break. */
(*p->endline)(p);
- p->viscol = p->rmargin;
- (*p->advance)(p, p->rmargin);
+ p->viscol = 0;
}
}
@@ -306,12 +301,8 @@ term_newln(struct termp *p)
{
p->flags |= TERMP_NOSPACE;
- if (0 == p->col && 0 == p->viscol) {
- p->flags &= ~TERMP_NOLPAD;
- return;
- }
- term_flushln(p);
- p->flags &= ~TERMP_NOLPAD;
+ if (p->col || p->viscol)
+ term_flushln(p);
}
diff --git a/term.h b/term.h
index 348e1d53..685d0962 100644
--- a/term.h
+++ b/term.h
@@ -1,4 +1,4 @@
-/* $Id: term.h,v 1.87 2011/09/18 14:14:15 schwarze Exp $ */
+/* $Id: term.h,v 1.88 2011/09/19 22:36:16 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
*
@@ -64,7 +64,6 @@ struct termp {
int flags;
#define TERMP_SENTENCE (1 << 1) /* Space before a sentence. */
#define TERMP_NOSPACE (1 << 2) /* No space before words. */
-#define TERMP_NOLPAD (1 << 3) /* See term_flushln(). */
#define TERMP_NOBREAK (1 << 4) /* See term_flushln(). */
#define TERMP_IGNDELIM (1 << 6) /* Delims like regulars. */
#define TERMP_NONOSPACE (1 << 7) /* No space (no autounset). */