=================================================================== RCS file: /cvs/mandoc/man_term.c,v retrieving revision 1.171 retrieving revision 1.177 diff -u -p -r1.171 -r1.177 --- mandoc/man_term.c 2015/04/02 21:36:50 1.171 +++ mandoc/man_term.c 2015/04/06 13:35:08 1.177 @@ -1,4 +1,4 @@ -/* $Id: man_term.c,v 1.171 2015/04/02 21:36:50 schwarze Exp $ */ +/* $Id: man_term.c,v 1.177 2015/04/06 13:35:08 schwarze Exp $ */ /* * Copyright (c) 2008-2012 Kristaps Dzonsons * Copyright (c) 2010-2015 Ingo Schwarze @@ -48,8 +48,8 @@ struct mtermp { #define DECL_ARGS struct termp *p, \ struct mtermp *mt, \ - struct man_node *n, \ - const struct man_meta *meta + struct roff_node *n, \ + const struct roff_meta *meta struct termact { int (*pre)(DECL_ARGS); @@ -60,10 +60,12 @@ struct termact { static void print_man_nodelist(DECL_ARGS); static void print_man_node(DECL_ARGS); -static void print_man_head(struct termp *, const void *); -static void print_man_foot(struct termp *, const void *); +static void print_man_head(struct termp *, + const struct roff_meta *); +static void print_man_foot(struct termp *, + const struct roff_meta *); static void print_bvspace(struct termp *, - const struct man_node *, int); + const struct roff_node *, int); static int pre_B(DECL_ARGS); static int pre_HP(DECL_ARGS); @@ -139,8 +141,8 @@ void terminal_man(void *arg, const struct man *man) { struct termp *p; - const struct man_meta *meta; - struct man_node *n; + const struct roff_meta *meta; + struct roff_node *n; struct mtermp mt; p = (struct termp *)arg; @@ -191,7 +193,7 @@ terminal_man(void *arg, const struct man *man) * first, print it. */ static void -print_bvspace(struct termp *p, const struct man_node *n, int pardist) +print_bvspace(struct termp *p, const struct roff_node *n, int pardist) { int i; @@ -280,7 +282,7 @@ static int pre_alternate(DECL_ARGS) { enum termfont font[2]; - struct man_node *nn; + struct roff_node *nn; int savelit, i; switch (n->tok) { @@ -425,7 +427,7 @@ pre_in(DECL_ARGS) if ( ! a2roffsu(++cp, &su, SCALE_EN)) return(0); - v = term_hspan(p, &su); + v = (term_hspan(p, &su) + 11) / 24; if (less < 0) p->offset -= p->offset > v ? v : p->offset; @@ -488,7 +490,7 @@ static int pre_HP(DECL_ARGS) { struct roffsu su; - const struct man_node *nn; + const struct roff_node *nn; int len; switch (n->type) { @@ -510,7 +512,7 @@ pre_HP(DECL_ARGS) if ((nn = n->parent->head->child) != NULL && a2roffsu(nn->string, &su, SCALE_EN)) { - len = term_hspan(p, &su); + len = term_hspan(p, &su) / 24; if (len < 0 && (size_t)(-len) > mt->offset) len = -mt->offset; else if (len > SHRT_MAX) @@ -531,6 +533,17 @@ post_HP(DECL_ARGS) switch (n->type) { case ROFFT_BODY: term_newln(p); + + /* + * Compatibility with a groff bug. + * The .HP macro uses the undocumented .tag request + * which causes a line break and cancels no-space + * mode even if there isn't any output. + */ + + if (n->child == NULL) + term_vspace(p); + p->flags &= ~(TERMP_NOBREAK | TERMP_BRIND); p->trailspace = 0; p->offset = mt->offset; @@ -562,7 +575,7 @@ static int pre_IP(DECL_ARGS) { struct roffsu su; - const struct man_node *nn; + const struct roff_node *nn; int len, savelit; switch (n->type) { @@ -584,7 +597,7 @@ pre_IP(DECL_ARGS) if ((nn = n->parent->head->child) != NULL && (nn = nn->next) != NULL && a2roffsu(nn->string, &su, SCALE_EN)) { - len = term_hspan(p, &su); + len = term_hspan(p, &su) / 24; if (len < 0 && (size_t)(-len) > mt->offset) len = -mt->offset; else if (len > SHRT_MAX) @@ -643,7 +656,7 @@ static int pre_TP(DECL_ARGS) { struct roffsu su; - struct man_node *nn; + struct roff_node *nn; int len, savelit; switch (n->type) { @@ -666,7 +679,7 @@ pre_TP(DECL_ARGS) if ((nn = n->parent->head->child) != NULL && nn->string != NULL && ! (MAN_LINE & nn->flags) && a2roffsu(nn->string, &su, SCALE_EN)) { - len = term_hspan(p, &su); + len = term_hspan(p, &su) / 24; if (len < 0 && (size_t)(-len) > mt->offset) len = -mt->offset; else if (len > SHRT_MAX) @@ -755,9 +768,15 @@ pre_SS(DECL_ARGS) case ROFFT_HEAD: term_fontrepl(p, TERMFONT_BOLD); p->offset = term_len(p, 3); + p->rmargin = mt->offset; + p->trailspace = mt->offset; + p->flags |= TERMP_NOBREAK | TERMP_BRIND; break; case ROFFT_BODY: p->offset = mt->offset; + p->rmargin = p->maxrmargin; + p->trailspace = 0; + p->flags &= ~(TERMP_NOBREAK | TERMP_BRIND); break; default: break; @@ -810,9 +829,15 @@ pre_SH(DECL_ARGS) case ROFFT_HEAD: term_fontrepl(p, TERMFONT_BOLD); p->offset = 0; + p->rmargin = mt->offset; + p->trailspace = mt->offset; + p->flags |= TERMP_NOBREAK | TERMP_BRIND; break; case ROFFT_BODY: p->offset = mt->offset; + p->rmargin = p->maxrmargin; + p->trailspace = 0; + p->flags &= ~(TERMP_NOBREAK | TERMP_BRIND); break; default: break; @@ -854,8 +879,10 @@ pre_RS(DECL_ARGS) n = n->parent->head; n->aux = SHRT_MAX + 1; - if (n->child != NULL && a2roffsu(n->child->string, &su, SCALE_EN)) - n->aux = term_hspan(p, &su); + if (n->child == NULL) + n->aux = mt->lmargin[mt->lmargincur]; + else if (a2roffsu(n->child->string, &su, SCALE_EN)) + n->aux = term_hspan(p, &su) / 24; if (n->aux < 0 && (size_t)(-n->aux) > mt->offset) n->aux = -mt->offset; else if (n->aux > SHRT_MAX) @@ -1012,13 +1039,11 @@ print_man_nodelist(DECL_ARGS) } static void -print_man_foot(struct termp *p, const void *arg) +print_man_foot(struct termp *p, const struct roff_meta *meta) { - const struct man_meta *meta; char *title; size_t datelen, titlen; - meta = (const struct man_meta *)arg; assert(meta->title); assert(meta->msec); assert(meta->date); @@ -1030,8 +1055,8 @@ print_man_foot(struct termp *p, const void *arg) /* * Temporary, undocumented option to imitate mdoc(7) output. - * In the bottom right corner, use the source instead of - * the title. + * In the bottom right corner, use the operating system + * instead of the title. */ if ( ! p->mdocstyle) { @@ -1041,14 +1066,14 @@ print_man_foot(struct termp *p, const void *arg) } mandoc_asprintf(&title, "%s(%s)", meta->title, meta->msec); - } else if (meta->source) { - title = mandoc_strdup(meta->source); + } else if (meta->os) { + title = mandoc_strdup(meta->os); } else { title = mandoc_strdup(""); } datelen = term_strlen(p, meta->date); - /* Bottom left corner: manual source. */ + /* Bottom left corner: operating system. */ p->flags |= TERMP_NOSPACE | TERMP_NOBREAK; p->trailspace = 1; @@ -1056,8 +1081,8 @@ print_man_foot(struct termp *p, const void *arg) p->rmargin = p->maxrmargin > datelen ? (p->maxrmargin + term_len(p, 1) - datelen) / 2 : 0; - if (meta->source) - term_word(p, meta->source); + if (meta->os) + term_word(p, meta->os); term_flushln(p); /* At the bottom in the middle: manual date. */ @@ -1084,14 +1109,12 @@ print_man_foot(struct termp *p, const void *arg) } static void -print_man_head(struct termp *p, const void *arg) +print_man_head(struct termp *p, const struct roff_meta *meta) { - const struct man_meta *meta; const char *volume; char *title; size_t vollen, titlen; - meta = (const struct man_meta *)arg; assert(meta->title); assert(meta->msec);