summaryrefslogtreecommitdiff
path: root/usr.bin/mandoc
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@cvs.openbsd.org>2010-03-02 01:24:05 +0000
committerIngo Schwarze <schwarze@cvs.openbsd.org>2010-03-02 01:24:05 +0000
commit9699851e8016381c1825dd2edccba24a6cea4355 (patch)
treed7d928f39025de072a5fbf9f548cfb82eeb21ef1 /usr.bin/mandoc
parent58c4f21bc4e7b936235ca98f9615e1b54b0c2c53 (diff)
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.
Diffstat (limited to 'usr.bin/mandoc')
-rw-r--r--usr.bin/mandoc/man_term.c25
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;