summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--usr.bin/mandoc/man_term.c36
-rw-r--r--usr.bin/mandoc/mdoc_term.c33
-rw-r--r--usr.bin/mandoc/term.c59
-rw-r--r--usr.bin/mandoc/term.h3
4 files changed, 58 insertions, 73 deletions
diff --git a/usr.bin/mandoc/man_term.c b/usr.bin/mandoc/man_term.c
index f976892aaa6..f6649d314d8 100644
--- a/usr.bin/mandoc/man_term.c
+++ b/usr.bin/mandoc/man_term.c
@@ -1,4 +1,4 @@
-/* $Id: man_term.c,v 1.71 2011/09/18 10:25:28 schwarze Exp $ */
+/* $Id: man_term.c,v 1.72 2011/09/19 22:36:11 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010, 2011 Ingo Schwarze <schwarze@openbsd.org>
@@ -241,6 +241,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);
}
@@ -427,7 +439,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;
@@ -452,8 +464,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;
@@ -516,7 +531,6 @@ pre_IP(DECL_ARGS)
switch (n->type) {
case (MAN_BODY):
- p->flags |= TERMP_NOLPAD;
p->flags |= TERMP_NOSPACE;
break;
case (MAN_HEAD):
@@ -587,7 +601,6 @@ post_IP(DECL_ARGS)
break;
case (MAN_BODY):
term_newln(p);
- p->flags &= ~TERMP_NOLPAD;
break;
default:
break;
@@ -608,7 +621,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):
@@ -677,7 +689,6 @@ post_TP(DECL_ARGS)
break;
case (MAN_BODY):
term_newln(p);
- p->flags &= ~TERMP_NOLPAD;
break;
default:
break;
@@ -878,7 +889,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;
@@ -886,7 +897,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;
}
@@ -968,7 +978,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;
@@ -1015,7 +1025,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;
@@ -1025,7 +1035,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/usr.bin/mandoc/mdoc_term.c b/usr.bin/mandoc/mdoc_term.c
index be0b13560cb..90bdba97ef6 100644
--- a/usr.bin/mandoc/mdoc_term.c
+++ b/usr.bin/mandoc/mdoc_term.c
@@ -1,4 +1,4 @@
-/* $Id: mdoc_term.c,v 1.135 2011/09/18 10:25:28 schwarze Exp $ */
+/* $Id: mdoc_term.c,v 1.136 2011/09/19 22:36:11 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010 Ingo Schwarze <schwarze@openbsd.org>
@@ -431,7 +431,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);
@@ -439,7 +439,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);
@@ -495,7 +495,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);
@@ -503,7 +503,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);
@@ -783,16 +783,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;
/*
@@ -803,17 +798,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;
@@ -829,10 +821,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)
@@ -989,7 +977,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;
}
@@ -1005,7 +992,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 ?
@@ -1050,10 +1037,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/usr.bin/mandoc/term.c b/usr.bin/mandoc/term.c
index b29f9a4f2f6..e4b3c95c60e 100644
--- a/usr.bin/mandoc/term.c
+++ b/usr.bin/mandoc/term.c
@@ -1,4 +1,4 @@
-/* $Id: term.c,v 1.60 2011/09/18 20:38:02 schwarze Exp $ */
+/* $Id: term.c,v 1.61 2011/09/19 22:36:11 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010, 2011 Ingo Schwarze <schwarze@openbsd.org>
@@ -75,22 +75,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:
@@ -130,9 +126,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;
@@ -232,10 +229,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;
}
@@ -244,7 +245,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;
@@ -269,25 +271,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;
}
}
@@ -302,12 +297,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/usr.bin/mandoc/term.h b/usr.bin/mandoc/term.h
index 22366b29b33..7301c942233 100644
--- a/usr.bin/mandoc/term.h
+++ b/usr.bin/mandoc/term.h
@@ -1,4 +1,4 @@
-/* $Id: term.h,v 1.31 2011/09/18 10:25:28 schwarze Exp $ */
+/* $Id: term.h,v 1.32 2011/09/19 22:36:11 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). */