diff options
Diffstat (limited to 'usr.bin/mandoc')
-rw-r--r-- | usr.bin/mandoc/man_term.c | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/usr.bin/mandoc/man_term.c b/usr.bin/mandoc/man_term.c index b6c7d13b229..20c6d65d522 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.24 2010/03/02 01:17:20 schwarze Exp $ */ +/* $Id: man_term.c,v 1.25 2010/03/02 01:24:04 schwarze Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se> * @@ -871,6 +871,7 @@ static void print_man_head(struct termp *p, const struct man_meta *m) { char buf[BUFSIZ], title[BUFSIZ]; + size_t buflen, titlen; p->rmargin = p->maxrmargin; p->offset = 0; @@ -878,11 +879,15 @@ print_man_head(struct termp *p, const struct man_meta *m) if (m->vol) strlcpy(buf, m->vol, BUFSIZ); + buflen = strlen(buf); snprintf(title, BUFSIZ, "%s(%d)", m->title, m->msec); + titlen = strlen(title); p->offset = 0; - p->rmargin = (p->maxrmargin - strlen(buf) + 1) / 2; + p->rmargin = 2 * (titlen+1) + buflen < p->maxrmargin ? + (p->maxrmargin - strlen(buf) + 1) / 2 : + p->maxrmargin - buflen; p->flags |= TERMP_NOBREAK | TERMP_NOSPACE; term_word(p, title); @@ -890,18 +895,20 @@ print_man_head(struct termp *p, const struct man_meta *m) p->flags |= TERMP_NOLPAD | TERMP_NOSPACE; p->offset = p->rmargin; - p->rmargin = p->maxrmargin - strlen(title); + p->rmargin = p->offset + buflen + titlen < p->maxrmargin ? + p->maxrmargin - titlen : p->maxrmargin; term_word(p, buf); term_flushln(p); - p->offset = p->rmargin; - p->rmargin = p->maxrmargin; p->flags &= ~TERMP_NOBREAK; - p->flags |= TERMP_NOLPAD | TERMP_NOSPACE; - - term_word(p, title); - term_flushln(p); + if (p->rmargin + titlen <= p->maxrmargin) { + p->flags |= TERMP_NOLPAD | TERMP_NOSPACE; + p->offset = p->rmargin; + p->rmargin = p->maxrmargin; + term_word(p, title); + term_flushln(p); + } p->rmargin = p->maxrmargin; p->offset = 0; |