diff options
author | Ingo Schwarze <schwarze@cvs.openbsd.org> | 2011-09-19 22:36:12 +0000 |
---|---|---|
committer | Ingo Schwarze <schwarze@cvs.openbsd.org> | 2011-09-19 22:36:12 +0000 |
commit | 5c2747528ce7ea3cd954f2c203665563b5a07cd1 (patch) | |
tree | 34572c53b2a262700f628bee79f4e867388c0d30 /usr.bin/mandoc/man_term.c | |
parent | 0fa515f3b610c3f733b147d1ff8416995df741e6 (diff) |
Remove the terminal frontend flag TERMP_NOLPAD.
In columnated contexts (.Bl -column, .Bl -tag, .IP, .TP, .HP etc.), do not
pad after writing a column. Instead, always pad before writing content.
In itself, this change avoids:
- writing trailing whitespace in some situations
- with .fi/.nf in .HP, breaking lines that were already padded
It allows several bugfixes included in this patch:
- Do not count backspace as a character with positive width.
- Set up proper indentation when encountering .fi/.nf in .HP.
- Adjust the .HP indentation width to what groff does.
- Never unlimit the right margin unless in the final column.
This reduces the groff/mandoc-differences in base by nearly 20%,
from 89k to 72k lines of diffs.
ok kristaps@
Diffstat (limited to 'usr.bin/mandoc/man_term.c')
-rw-r--r-- | usr.bin/mandoc/man_term.c | 36 |
1 files changed, 23 insertions, 13 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); |