summaryrefslogtreecommitdiffstats
path: root/man_term.c
diff options
context:
space:
mode:
authorKristaps Dzonsons <kristaps@bsd.lv>2010-03-23 11:30:48 +0000
committerKristaps Dzonsons <kristaps@bsd.lv>2010-03-23 11:30:48 +0000
commit664c21875228ae7f241f792abcc521bc64e42067 (patch)
tree074094c1be5f19d158836e09aeed7fabc1aca3ce /man_term.c
parent1850b321257c0b341f90c8d3c259ac54899376e6 (diff)
downloadmandoc-664c21875228ae7f241f792abcc521bc64e42067.tar.gz
Support for pod2man standard header macros (Vb, Ve, Sp). Based largely on a set of patches by Ingo Schwarze.
Diffstat (limited to 'man_term.c')
-rw-r--r--man_term.c32
1 files changed, 23 insertions, 9 deletions
diff --git a/man_term.c b/man_term.c
index 45bcf5d3..18924f29 100644
--- a/man_term.c
+++ b/man_term.c
@@ -139,6 +139,9 @@ static const struct termact termacts[MAN_MAX] = {
{ pre_ign, NULL, 0 }, /* DT */
{ pre_ign, NULL, 0 }, /* UC */
{ pre_ign, NULL, 0 }, /* PD */
+ { pre_sp, NULL, MAN_NOTEXT }, /* Sp */
+ { pre_nf, NULL, 0 }, /* Vb */
+ { pre_fi, NULL, 0 }, /* Ve */
};
@@ -156,6 +159,7 @@ terminal_man(void *arg, const struct man *man)
if (NULL == p->symtab)
switch (p->enc) {
case (TERMENC_ASCII):
+ p->maxrmargin = 65;
p->symtab = chars_init(CHARS_ASCII);
break;
default:
@@ -248,6 +252,7 @@ static int
pre_fi(DECL_ARGS)
{
+ p->rmargin = p->maxrmargin = 65;
mt->fl &= ~MANT_LITERAL;
return(1);
}
@@ -258,9 +263,11 @@ static int
pre_nf(DECL_ARGS)
{
+ p->rmargin = p->maxrmargin = 78;
term_newln(p);
mt->fl |= MANT_LITERAL;
- return(1);
+
+ return(MAN_Vb != n->tok);
}
@@ -873,6 +880,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;
@@ -880,11 +888,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);
@@ -892,18 +904,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;