From 9699851e8016381c1825dd2edccba24a6cea4355 Mon Sep 17 00:00:00 2001 From: Ingo Schwarze Date: Tue, 2 Mar 2010 01:24:05 +0000 Subject: In man(7), do not crash on very long title lines, and do not emulate groff's habit of printing garbage either, but just print the wanted information even though the format must be sacrificed because it won't fit. --- usr.bin/mandoc/man_term.c | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) (limited to 'usr.bin/mandoc') 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 * @@ -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; -- cgit v1.2.3