=================================================================== RCS file: /cvs/mandoc/man_term.c,v retrieving revision 1.201 retrieving revision 1.210 diff -u -p -r1.201 -r1.210 --- mandoc/man_term.c 2017/06/04 18:50:35 1.201 +++ mandoc/man_term.c 2018/04/11 17:11:13 1.210 @@ -1,7 +1,7 @@ -/* $Id: man_term.c,v 1.201 2017/06/04 18:50:35 schwarze Exp $ */ +/* $Id: man_term.c,v 1.210 2018/04/11 17:11:13 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 @@ -128,6 +128,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,7 +143,10 @@ terminal_man(void *arg, const struct roff_man *man) size_t save_defindent; p = (struct termp *)arg; - p->rmargin = p->maxrmargin = p->defrmargin; + 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"); term_tab_set(p, ".5i"); @@ -167,16 +172,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; } /* @@ -228,7 +230,7 @@ pre_literal(DECL_ARGS) term_newln(p); - if (MAN_nf == n->tok || MAN_EX == n->tok) + if (n->tok == MAN_nf || n->tok == MAN_EX) mt->fl |= MANT_LITERAL; else mt->fl &= ~MANT_LITERAL; @@ -238,9 +240,9 @@ pre_literal(DECL_ARGS) * So in case a second call to term_flushln() is needed, * indentation has to be set up explicitly. */ - if (MAN_HP == n->parent->tok && p->rmargin < p->maxrmargin) { - p->offset = p->rmargin; - p->rmargin = p->maxrmargin; + if (n->parent->tok == MAN_HP && p->tcol->rmargin < p->maxrmargin) { + p->tcol->offset = p->tcol->rmargin; + p->tcol->rmargin = p->maxrmargin; p->trailspace = 0; p->flags &= ~(TERMP_NOBREAK | TERMP_BRIND); p->flags |= TERMP_NOSPACE; @@ -260,7 +262,7 @@ pre_PD(DECL_ARGS) return 0; } assert(n->type == ROFFT_TEXT); - if (a2roffsu(n->string, &su, SCALE_VS)) + if (a2roffsu(n->string, &su, SCALE_VS) != NULL) mt->pardist = term_vspan(p, &su); return 0; } @@ -359,8 +361,8 @@ pre_in(DECL_ARGS) term_newln(p); - if (NULL == n->child) { - p->offset = mt->offset; + if (n->child == NULL) { + p->tcol->offset = mt->offset; return 0; } @@ -374,19 +376,19 @@ pre_in(DECL_ARGS) else cp--; - if ( ! a2roffsu(++cp, &su, SCALE_EN)) + 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->offset -= p->offset > v ? v : p->offset; + p->tcol->offset -= p->tcol->offset > v ? v : p->tcol->offset; else if (less > 0) - p->offset += v; + p->tcol->offset += v; else - p->offset = v; - if (p->offset > SHRT_MAX) - p->offset = term_len(p, p->defindent); + p->tcol->offset = v; + if (p->tcol->offset > SHRT_MAX) + p->tcol->offset = term_len(p, p->defindent); return 0; } @@ -425,8 +427,8 @@ pre_HP(DECL_ARGS) /* Calculate offset. */ if ((nn = n->parent->head->child) != NULL && - a2roffsu(nn->string, &su, SCALE_EN)) { - len = term_hspan(p, &su) / 24; + a2roffsu(nn->string, &su, SCALE_EN) != NULL) { + len = term_hen(p, &su); if (len < 0 && (size_t)(-len) > mt->offset) len = -mt->offset; else if (len > SHRT_MAX) @@ -435,8 +437,8 @@ pre_HP(DECL_ARGS) } else len = mt->lmargin[mt->lmargincur]; - p->offset = mt->offset; - p->rmargin = mt->offset + len; + p->tcol->offset = mt->offset; + p->tcol->rmargin = mt->offset + len; return 1; } @@ -460,8 +462,8 @@ post_HP(DECL_ARGS) p->flags &= ~(TERMP_NOBREAK | TERMP_BRIND); p->trailspace = 0; - p->offset = mt->offset; - p->rmargin = p->maxrmargin; + p->tcol->offset = mt->offset; + p->tcol->rmargin = p->maxrmargin; break; default: break; @@ -478,7 +480,7 @@ pre_PP(DECL_ARGS) print_bvspace(p, n, mt->pardist); break; default: - p->offset = mt->offset; + p->tcol->offset = mt->offset; break; } @@ -510,8 +512,8 @@ pre_IP(DECL_ARGS) /* Calculate the offset from the optional second argument. */ if ((nn = n->parent->head->child) != NULL && (nn = nn->next) != NULL && - a2roffsu(nn->string, &su, SCALE_EN)) { - len = term_hspan(p, &su) / 24; + a2roffsu(nn->string, &su, SCALE_EN) != NULL) { + len = term_hen(p, &su); if (len < 0 && (size_t)(-len) > mt->offset) len = -mt->offset; else if (len > SHRT_MAX) @@ -522,8 +524,8 @@ pre_IP(DECL_ARGS) switch (n->type) { case ROFFT_HEAD: - p->offset = mt->offset; - p->rmargin = mt->offset + len; + p->tcol->offset = mt->offset; + p->tcol->rmargin = mt->offset + len; savelit = MANT_LITERAL & mt->fl; mt->fl &= ~MANT_LITERAL; @@ -536,8 +538,8 @@ pre_IP(DECL_ARGS) return 0; case ROFFT_BODY: - p->offset = mt->offset + len; - p->rmargin = p->maxrmargin; + p->tcol->offset = mt->offset + len; + p->tcol->rmargin = p->maxrmargin; break; default: break; @@ -555,11 +557,11 @@ post_IP(DECL_ARGS) term_flushln(p); p->flags &= ~TERMP_NOBREAK; p->trailspace = 0; - p->rmargin = p->maxrmargin; + p->tcol->rmargin = p->maxrmargin; break; case ROFFT_BODY: term_newln(p); - p->offset = mt->offset; + p->tcol->offset = mt->offset; break; default: break; @@ -592,8 +594,8 @@ pre_TP(DECL_ARGS) if ((nn = n->parent->head->child) != NULL && nn->string != NULL && ! (NODE_LINE & nn->flags) && - a2roffsu(nn->string, &su, SCALE_EN)) { - len = term_hspan(p, &su) / 24; + a2roffsu(nn->string, &su, SCALE_EN) != NULL) { + len = term_hen(p, &su); if (len < 0 && (size_t)(-len) > mt->offset) len = -mt->offset; else if (len > SHRT_MAX) @@ -604,8 +606,8 @@ pre_TP(DECL_ARGS) switch (n->type) { case ROFFT_HEAD: - p->offset = mt->offset; - p->rmargin = mt->offset + len; + p->tcol->offset = mt->offset; + p->tcol->rmargin = mt->offset + len; savelit = MANT_LITERAL & mt->fl; mt->fl &= ~MANT_LITERAL; @@ -624,8 +626,8 @@ pre_TP(DECL_ARGS) mt->fl |= MANT_LITERAL; return 0; case ROFFT_BODY: - p->offset = mt->offset + len; - p->rmargin = p->maxrmargin; + p->tcol->offset = mt->offset + len; + p->tcol->rmargin = p->maxrmargin; p->trailspace = 0; p->flags &= ~(TERMP_NOBREAK | TERMP_BRTRSP); break; @@ -646,7 +648,7 @@ post_TP(DECL_ARGS) break; case ROFFT_BODY: term_newln(p); - p->offset = mt->offset; + p->tcol->offset = mt->offset; break; default: break; @@ -671,9 +673,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++) @@ -681,14 +684,14 @@ pre_SS(DECL_ARGS) break; case ROFFT_HEAD: term_fontrepl(p, TERMFONT_BOLD); - p->offset = term_len(p, 3); - p->rmargin = mt->offset; + p->tcol->offset = term_len(p, 3); + p->tcol->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->tcol->offset = mt->offset; + p->tcol->rmargin = p->maxrmargin; p->trailspace = 0; p->flags &= ~(TERMP_NOBREAK | TERMP_BRIND); break; @@ -733,9 +736,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++) @@ -743,14 +747,14 @@ pre_SH(DECL_ARGS) break; case ROFFT_HEAD: term_fontrepl(p, TERMFONT_BOLD); - p->offset = 0; - p->rmargin = mt->offset; + p->tcol->offset = 0; + p->tcol->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->tcol->offset = mt->offset; + p->tcol->rmargin = p->maxrmargin; p->trailspace = 0; p->flags &= ~(TERMP_NOBREAK | TERMP_BRIND); break; @@ -796,16 +800,16 @@ pre_RS(DECL_ARGS) n->aux = SHRT_MAX + 1; 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; + else if (a2roffsu(n->child->string, &su, SCALE_EN) != NULL) + 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) n->aux = term_len(p, p->defindent); mt->offset += n->aux; - p->offset = mt->offset; - p->rmargin = p->maxrmargin; + p->tcol->offset = mt->offset; + p->tcol->rmargin = p->maxrmargin; if (++mt->lmarginsz < MAXMARGINS) mt->lmargincur = mt->lmarginsz; @@ -829,7 +833,7 @@ post_RS(DECL_ARGS) } mt->offset -= n->parent->head->aux; - p->offset = mt->offset; + p->tcol->offset = mt->offset; if (--mt->lmarginsz < MAXMARGINS) mt->lmargincur = mt->lmarginsz; @@ -862,7 +866,6 @@ post_UR(DECL_ARGS) static void print_man_node(DECL_ARGS) { - size_t rm, rmax; int c; switch (n->type) { @@ -873,7 +876,10 @@ 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) @@ -881,7 +887,8 @@ print_man_node(DECL_ARGS) term_word(p, n->string); goto out; - + case ROFFT_COMMENT: + return; case ROFFT_EQN: if ( ! (n->flags & NODE_LINE)) p->flags |= TERMP_NOSPACE; @@ -930,20 +937,17 @@ out: if (mt->fl & MANT_LITERAL && ! (p->flags & (TERMP_NOBREAK | TERMP_NONEWLINE)) && (n->next == NULL || n->next->flags & NODE_LINE)) { - rm = p->rmargin; - rmax = p->maxrmargin; - p->rmargin = p->maxrmargin = TERM_MAXMARGIN; - p->flags |= TERMP_NOSPACE; + p->flags |= TERMP_BRNEVER | TERMP_NOSPACE; if (n->string != NULL && *n->string != '\0') term_flushln(p); else term_newln(p); - if (rm < rmax && n->parent->tok == MAN_HP) { - p->offset = rm; - p->rmargin = rmax; - } else - p->rmargin = rm; - p->maxrmargin = rmax; + p->flags &= ~TERMP_BRNEVER; + if (p->tcol->rmargin < p->maxrmargin && + n->parent->tok == MAN_HP) { + p->tcol->offset = p->tcol->rmargin; + p->tcol->rmargin = p->maxrmargin; + } } if (NODE_EOS & n->flags) p->flags |= TERMP_SENTENCE; @@ -999,8 +1003,8 @@ print_man_foot(struct termp *p, const struct roff_meta p->flags |= TERMP_NOSPACE | TERMP_NOBREAK; p->trailspace = 1; - p->offset = 0; - p->rmargin = p->maxrmargin > datelen ? + p->tcol->offset = 0; + p->tcol->rmargin = p->maxrmargin > datelen ? (p->maxrmargin + term_len(p, 1) - datelen) / 2 : 0; if (meta->os) @@ -1009,9 +1013,10 @@ print_man_foot(struct termp *p, const struct roff_meta /* At the bottom in the middle: manual date. */ - p->offset = p->rmargin; + p->tcol->offset = p->tcol->rmargin; titlen = term_strlen(p, title); - p->rmargin = p->maxrmargin > titlen ? p->maxrmargin - titlen : 0; + p->tcol->rmargin = p->maxrmargin > titlen ? + p->maxrmargin - titlen : 0; p->flags |= TERMP_NOSPACE; term_word(p, meta->date); @@ -1022,8 +1027,8 @@ print_man_foot(struct termp *p, const struct roff_meta p->flags &= ~TERMP_NOBREAK; p->flags |= TERMP_NOSPACE; p->trailspace = 0; - p->offset = p->rmargin; - p->rmargin = p->maxrmargin; + p->tcol->offset = p->tcol->rmargin; + p->tcol->rmargin = p->maxrmargin; term_word(p, title); term_flushln(p); @@ -1050,8 +1055,8 @@ print_man_head(struct termp *p, const struct roff_meta p->flags |= TERMP_NOBREAK | TERMP_NOSPACE; p->trailspace = 1; - p->offset = 0; - p->rmargin = 2 * (titlen+1) + vollen < p->maxrmargin ? + p->tcol->offset = 0; + p->tcol->rmargin = 2 * (titlen+1) + vollen < p->maxrmargin ? (p->maxrmargin - vollen + term_len(p, 1)) / 2 : vollen < p->maxrmargin ? p->maxrmargin - vollen : 0; @@ -1061,9 +1066,9 @@ print_man_head(struct termp *p, const struct roff_meta /* At the top in the middle: manual volume. */ p->flags |= TERMP_NOSPACE; - p->offset = p->rmargin; - p->rmargin = p->offset + vollen + titlen < p->maxrmargin ? - p->maxrmargin - titlen : p->maxrmargin; + p->tcol->offset = p->tcol->rmargin; + p->tcol->rmargin = p->tcol->offset + vollen + titlen < + p->maxrmargin ? p->maxrmargin - titlen : p->maxrmargin; term_word(p, volume); term_flushln(p); @@ -1072,17 +1077,17 @@ print_man_head(struct termp *p, const struct roff_meta p->flags &= ~TERMP_NOBREAK; p->trailspace = 0; - if (p->rmargin + titlen <= p->maxrmargin) { + if (p->tcol->rmargin + titlen <= p->maxrmargin) { p->flags |= TERMP_NOSPACE; - p->offset = p->rmargin; - p->rmargin = p->maxrmargin; + p->tcol->offset = p->tcol->rmargin; + p->tcol->rmargin = p->maxrmargin; term_word(p, title); term_flushln(p); } p->flags &= ~TERMP_NOSPACE; - p->offset = 0; - p->rmargin = p->maxrmargin; + p->tcol->offset = 0; + p->tcol->rmargin = p->maxrmargin; /* * Groff prints three blank lines before the content.