=================================================================== RCS file: /cvs/mandoc/man_term.c,v retrieving revision 1.204 retrieving revision 1.213 diff -u -p -r1.204 -r1.213 --- mandoc/man_term.c 2017/06/08 12:54:58 1.204 +++ mandoc/man_term.c 2018/08/16 23:43:37 1.213 @@ -1,7 +1,7 @@ -/* $Id: man_term.c,v 1.204 2017/06/08 12:54:58 schwarze Exp $ */ +/* $Id: man_term.c,v 1.213 2018/08/16 23:43:37 schwarze Exp $ */ /* * Copyright (c) 2008-2012 Kristaps Dzonsons - * Copyright (c) 2010-2015, 2017 Ingo Schwarze + * Copyright (c) 2010-2015, 2017, 2018 Ingo Schwarze * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -98,6 +98,7 @@ static const struct termact __termacts[MAN_MAX - MAN_T { pre_SH, post_SH, 0 }, /* SH */ { pre_SS, post_SS, 0 }, /* SS */ { pre_TP, post_TP, 0 }, /* TP */ + { pre_TP, post_TP, 0 }, /* TQ */ { pre_PP, NULL, 0 }, /* LP */ { pre_PP, NULL, 0 }, /* PP */ { pre_PP, NULL, 0 }, /* P */ @@ -128,6 +129,8 @@ static const struct termact __termacts[MAN_MAX - MAN_T { pre_literal, NULL, 0 }, /* EE */ { pre_UR, post_UR, 0 }, /* UR */ { NULL, NULL, 0 }, /* UE */ + { pre_UR, post_UR, 0 }, /* MT */ + { NULL, NULL, 0 }, /* ME */ }; static const struct termact *termacts = __termacts - MAN_TH; @@ -141,6 +144,9 @@ terminal_man(void *arg, const struct roff_man *man) size_t save_defindent; p = (struct termp *)arg; + save_defindent = p->defindent; + if (p->synopsisonly == 0 && p->defindent == 0) + p->defindent = 7; p->tcol->rmargin = p->maxrmargin = p->defrmargin; term_tab_set(p, NULL); term_tab_set(p, "T"); @@ -167,16 +173,13 @@ terminal_man(void *arg, const struct roff_man *man) n = n->next; } } else { - save_defindent = p->defindent; - if (p->defindent == 0) - p->defindent = 7; term_begin(p, print_man_head, print_man_foot, &man->meta); p->flags |= TERMP_NOSPACE; if (n != NULL) print_man_nodelist(p, &mt, n, &man->meta); term_end(p); - p->defindent = save_defindent; } + p->defindent = save_defindent; } /* @@ -377,7 +380,7 @@ pre_in(DECL_ARGS) if (a2roffsu(++cp, &su, SCALE_EN) == NULL) return 0; - v = (term_hspan(p, &su) + 11) / 24; + v = term_hen(p, &su); if (less < 0) p->tcol->offset -= p->tcol->offset > v ? v : p->tcol->offset; @@ -426,7 +429,7 @@ pre_HP(DECL_ARGS) if ((nn = n->parent->head->child) != NULL && a2roffsu(nn->string, &su, SCALE_EN) != NULL) { - len = term_hspan(p, &su) / 24; + len = term_hen(p, &su); if (len < 0 && (size_t)(-len) > mt->offset) len = -mt->offset; else if (len > SHRT_MAX) @@ -511,7 +514,7 @@ pre_IP(DECL_ARGS) if ((nn = n->parent->head->child) != NULL && (nn = nn->next) != NULL && a2roffsu(nn->string, &su, SCALE_EN) != NULL) { - len = term_hspan(p, &su) / 24; + len = term_hen(p, &su); if (len < 0 && (size_t)(-len) > mt->offset) len = -mt->offset; else if (len > SHRT_MAX) @@ -582,7 +585,8 @@ pre_TP(DECL_ARGS) p->flags |= TERMP_NOSPACE; break; case ROFFT_BLOCK: - print_bvspace(p, n, mt->pardist); + if (n->tok == MAN_TP) + print_bvspace(p, n, mt->pardist); /* FALLTHROUGH */ default: return 1; @@ -593,7 +597,7 @@ pre_TP(DECL_ARGS) if ((nn = n->parent->head->child) != NULL && nn->string != NULL && ! (NODE_LINE & nn->flags) && a2roffsu(nn->string, &su, SCALE_EN) != NULL) { - len = term_hspan(p, &su) / 24; + len = term_hen(p, &su); if (len < 0 && (size_t)(-len) > mt->offset) len = -mt->offset; else if (len > SHRT_MAX) @@ -671,9 +675,10 @@ pre_SS(DECL_ARGS) do { n = n->prev; - } while (n != NULL && n->tok != TOKEN_NONE && + } while (n != NULL && n->tok >= MAN_TH && termacts[n->tok].flags & MAN_NOTEXT); - if (n == NULL || (n->tok == MAN_SS && n->body->child == NULL)) + if (n == NULL || n->type == ROFFT_COMMENT || + (n->tok == MAN_SS && n->body->child == NULL)) break; for (i = 0; i < mt->pardist; i++) @@ -733,9 +738,10 @@ pre_SH(DECL_ARGS) do { n = n->prev; - } while (n != NULL && n->tok != TOKEN_NONE && + } while (n != NULL && n->tok >= MAN_TH && termacts[n->tok].flags & MAN_NOTEXT); - if (n == NULL || (n->tok == MAN_SH && n->body->child == NULL)) + if (n == NULL || n->type == ROFFT_COMMENT || + (n->tok == MAN_SH && n->body->child == NULL)) break; for (i = 0; i < mt->pardist; i++) @@ -797,7 +803,7 @@ pre_RS(DECL_ARGS) if (n->child == NULL) n->aux = mt->lmargin[mt->lmargincur]; else if (a2roffsu(n->child->string, &su, SCALE_EN) != NULL) - n->aux = term_hspan(p, &su) / 24; + n->aux = term_hen(p, &su); if (n->aux < 0 && (size_t)(-n->aux) > mt->offset) n->aux = -mt->offset; else if (n->aux > SHRT_MAX) @@ -872,15 +878,21 @@ print_man_node(DECL_ARGS) * before printing the line's data. */ if (*n->string == '\0') { - term_vspace(p); + if (p->flags & TERMP_NONEWLINE) + term_newln(p); + else + term_vspace(p); return; } else if (*n->string == ' ' && n->flags & NODE_LINE && (p->flags & TERMP_NONEWLINE) == 0) term_newln(p); + else if (n->flags & NODE_DELIMC) + p->flags |= TERMP_NOSPACE; term_word(p, n->string); goto out; - + case ROFFT_COMMENT: + return; case ROFFT_EQN: if ( ! (n->flags & NODE_LINE)) p->flags |= TERMP_NOSPACE; @@ -1024,6 +1036,18 @@ print_man_foot(struct termp *p, const struct roff_meta term_word(p, title); term_flushln(p); + + /* + * Reset the terminal state for more output after the footer: + * Some output modes, in particular PostScript and PDF, print + * the header and the footer into a buffer such that it can be + * reused for multiple output pages, then go on to format the + * main text. + */ + + p->tcol->offset = 0; + p->flags = 0; + free(title); }