summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@openbsd.org>2011-09-20 09:02:23 +0000
committerIngo Schwarze <schwarze@openbsd.org>2011-09-20 09:02:23 +0000
commit6c66de1ba5c6e2228ec3b0064dd298ae9e0e1125 (patch)
treed475ac92cea66392cf12d117b5e43fed1bdda9b5
parentbbc1c34dd91da0a6589b4a76b4c861db09eeab42 (diff)
downloadmandoc-6c66de1ba5c6e2228ec3b0064dd298ae9e0e1125.tar.gz
Sync print_mdoc_head to print_man_head;
this was forgotten after man_term.c rev. 1.25 on March 2, 2010. The benefit is a sane page header line when .Dt is very long. Reminded by Thomas Klausner <wiz at NetBSD>, thanks.
-rw-r--r--man_term.c8
-rw-r--r--mdoc_term.c37
2 files changed, 26 insertions, 19 deletions
diff --git a/man_term.c b/man_term.c
index cdf0aed8..65e95e9e 100644
--- a/man_term.c
+++ b/man_term.c
@@ -1007,9 +1007,9 @@ print_man_head(struct termp *p, const void *arg)
* point we did so here.
*/
+ p->offset = 0;
p->rmargin = p->maxrmargin;
- p->offset = 0;
buf[0] = title[0] = '\0';
if (m->vol)
@@ -1019,12 +1019,12 @@ print_man_head(struct termp *p, const void *arg)
snprintf(title, BUFSIZ, "%s(%s)", m->title, m->msec);
titlen = term_strlen(p, title);
+ p->flags |= TERMP_NOBREAK | TERMP_NOSPACE;
p->offset = 0;
p->rmargin = 2 * (titlen+1) + buflen < p->maxrmargin ?
(p->maxrmargin -
term_strlen(p, buf) + term_len(p, 1)) / 2 :
p->maxrmargin - buflen;
- p->flags |= TERMP_NOBREAK | TERMP_NOSPACE;
term_word(p, title);
term_flushln(p);
@@ -1046,9 +1046,9 @@ print_man_head(struct termp *p, const void *arg)
term_flushln(p);
}
- p->rmargin = p->maxrmargin;
- p->offset = 0;
p->flags &= ~TERMP_NOSPACE;
+ p->offset = 0;
+ p->rmargin = p->maxrmargin;
/*
* Groff likes to have some leading spaces before content. Well
diff --git a/mdoc_term.c b/mdoc_term.c
index b0bea6b2..1c71f01e 100644
--- a/mdoc_term.c
+++ b/mdoc_term.c
@@ -458,13 +458,11 @@ static void
print_mdoc_head(struct termp *p, const void *arg)
{
char buf[BUFSIZ], title[BUFSIZ];
+ size_t buflen, titlen;
const struct mdoc_meta *m;
m = (const struct mdoc_meta *)arg;
- p->rmargin = p->maxrmargin;
- p->offset = 0;
-
/*
* The header is strange. It has three components, which are
* really two with the first duplicated. It goes like this:
@@ -478,8 +476,12 @@ print_mdoc_head(struct termp *p, const void *arg)
* switches on the manual section.
*/
+ p->offset = 0;
+ p->rmargin = p->maxrmargin;
+
assert(m->vol);
strlcpy(buf, m->vol, BUFSIZ);
+ buflen = term_strlen(p, buf);
if (m->arch) {
strlcat(buf, " (", BUFSIZ);
@@ -488,33 +490,38 @@ print_mdoc_head(struct termp *p, const void *arg)
}
snprintf(title, BUFSIZ, "%s(%s)", m->title, m->msec);
+ titlen = term_strlen(p, title);
- p->offset = 0;
- p->rmargin = (p->maxrmargin -
- term_strlen(p, buf) + term_len(p, 1)) / 2;
p->flags |= TERMP_NOBREAK | TERMP_NOSPACE;
+ p->offset = 0;
+ p->rmargin = 2 * (titlen+1) + buflen < p->maxrmargin ?
+ (p->maxrmargin -
+ term_strlen(p, buf) + term_len(p, 1)) / 2 :
+ p->maxrmargin - buflen;
term_word(p, title);
term_flushln(p);
- p->offset = p->rmargin;
- p->rmargin = p->maxrmargin - term_strlen(p, title);
p->flags |= TERMP_NOSPACE;
+ p->offset = p->rmargin;
+ 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_NOSPACE;
-
- term_word(p, title);
- term_flushln(p);
+ if (p->rmargin + titlen <= p->maxrmargin) {
+ p->flags |= TERMP_NOSPACE;
+ p->offset = p->rmargin;
+ p->rmargin = p->maxrmargin;
+ term_word(p, title);
+ term_flushln(p);
+ }
+ p->flags &= ~TERMP_NOSPACE;
p->offset = 0;
p->rmargin = p->maxrmargin;
- p->flags &= ~TERMP_NOSPACE;
}