=================================================================== RCS file: /cvs/mandoc/mdoc_term.c,v retrieving revision 1.326 retrieving revision 1.332 diff -u -p -r1.326 -r1.332 --- mandoc/mdoc_term.c 2015/09/21 13:25:00 1.326 +++ mandoc/mdoc_term.c 2016/10/09 18:16:56 1.332 @@ -1,7 +1,7 @@ -/* $Id: mdoc_term.c,v 1.326 2015/09/21 13:25:00 schwarze Exp $ */ +/* $Id: mdoc_term.c,v 1.332 2016/10/09 18:16:56 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons - * Copyright (c) 2010, 2012-2015 Ingo Schwarze + * Copyright (c) 2010, 2012-2016 Ingo Schwarze * Copyright (c) 2013 Franco Fichtner * * Permission to use, copy, modify, and distribute this software for any @@ -357,7 +357,7 @@ print_mdoc_node(DECL_ARGS) break; default: if (termacts[n->tok].pre && - (n->end == ENDBODY_NOT || n->nchild)) + (n->end == ENDBODY_NOT || n->child != NULL)) chld = (*termacts[n->tok].pre) (p, &npair, meta, n); break; @@ -535,7 +535,7 @@ a2width(const struct termp *p, const char *v) SCALE_HS_INIT(&su, term_strlen(p, v)); su.scale /= term_strlen(p, "0"); } - return(term_hspan(p, &su) / 24); + return term_hspan(p, &su) / 24; } /* @@ -598,8 +598,8 @@ static int termp_ll_pre(DECL_ARGS) { - term_setwidth(p, n->nchild ? n->child->string : NULL); - return(0); + term_setwidth(p, n->child != NULL ? n->child->string : NULL); + return 0; } static int @@ -613,7 +613,7 @@ termp_it_pre(DECL_ARGS) if (n->type == ROFFT_BLOCK) { print_bvspace(p, n->parent->parent, n); - return(1); + return 1; } bl = n->parent->parent->parent; @@ -625,20 +625,16 @@ termp_it_pre(DECL_ARGS) switch (type) { case LIST_bullet: - /* FALLTHROUGH */ case LIST_dash: - /* FALLTHROUGH */ case LIST_hyphen: - /* FALLTHROUGH */ case LIST_enum: width = term_len(p, 2); break; case LIST_hang: + case LIST_tag: width = term_len(p, 8); break; case LIST_column: - /* FALLTHROUGH */ - case LIST_tag: width = term_len(p, 10); break; default: @@ -735,7 +731,7 @@ termp_it_pre(DECL_ARGS) term_word(p, "\\ \\ "); break; case LIST_inset: - if (n->type == ROFFT_BODY && n->parent->head->nchild) + if (n->type == ROFFT_BODY && n->parent->head->child != NULL) term_word(p, "\\ "); break; default: @@ -762,16 +758,13 @@ termp_it_pre(DECL_ARGS) switch (type) { case LIST_enum: + case LIST_bullet: + case LIST_dash: + case LIST_hyphen: /* * Weird special case. * Some very narrow lists actually hang. */ - /* FALLTHROUGH */ - case LIST_bullet: - /* FALLTHROUGH */ - case LIST_dash: - /* FALLTHROUGH */ - case LIST_hyphen: if (width <= (int)term_len(p, 2)) p->flags |= TERMP_HANG; if (n->type != ROFFT_HEAD) @@ -854,13 +847,9 @@ termp_it_pre(DECL_ARGS) break; /* FALLTHROUGH */ case LIST_bullet: - /* FALLTHROUGH */ case LIST_dash: - /* FALLTHROUGH */ case LIST_enum: - /* FALLTHROUGH */ case LIST_hyphen: - /* FALLTHROUGH */ case LIST_tag: if (n->type == ROFFT_HEAD) p->rmargin = p->offset + width; @@ -896,10 +885,9 @@ termp_it_pre(DECL_ARGS) term_fontpop(p); break; case LIST_dash: - /* FALLTHROUGH */ case LIST_hyphen: term_fontpush(p, TERMFONT_BOLD); - term_word(p, "\\(hy"); + term_word(p, "-"); term_fontpop(p); break; case LIST_enum: @@ -918,26 +906,22 @@ termp_it_pre(DECL_ARGS) switch (type) { case LIST_bullet: - /* FALLTHROUGH */ case LIST_item: - /* FALLTHROUGH */ case LIST_dash: - /* FALLTHROUGH */ case LIST_hyphen: - /* FALLTHROUGH */ case LIST_enum: if (n->type == ROFFT_HEAD) - return(0); + return 0; break; case LIST_column: if (n->type == ROFFT_HEAD) - return(0); + return 0; break; default: break; } - return(1); + return 1; } static void @@ -952,9 +936,7 @@ termp_it_post(DECL_ARGS) switch (type) { case LIST_item: - /* FALLTHROUGH */ case LIST_diag: - /* FALLTHROUGH */ case LIST_inset: if (n->type == ROFFT_BODY) term_newln(p); @@ -986,12 +968,12 @@ termp_nm_pre(DECL_ARGS) if (n->type == ROFFT_BLOCK) { p->flags |= TERMP_PREKEEP; - return(1); + return 1; } if (n->type == ROFFT_BODY) { if (NULL == n->child) - return(0); + return 0; p->flags |= TERMP_NOSPACE; cp = NULL; if (n->prev->child != NULL) @@ -1002,11 +984,11 @@ termp_nm_pre(DECL_ARGS) p->offset += term_len(p, 6); else p->offset += term_len(p, 1) + term_strlen(p, cp); - return(1); + return 1; } if (NULL == n->child && NULL == meta->name) - return(0); + return 0; if (n->type == ROFFT_HEAD) synopsis_pre(p, n->parent); @@ -1031,7 +1013,7 @@ termp_nm_pre(DECL_ARGS) term_fontpush(p, TERMFONT_BOLD); if (NULL == n->child) term_word(p, meta->name); - return(1); + return 1; } static void @@ -1057,13 +1039,13 @@ termp_fl_pre(DECL_ARGS) term_fontpush(p, TERMFONT_BOLD); term_word(p, "\\-"); - if ( ! (n->nchild == 0 && + if (!(n->child == NULL && (n->next == NULL || n->next->type == ROFFT_TEXT || n->next->flags & MDOC_LINE))) p->flags |= TERMP_NOSPACE; - return(1); + return 1; } static int @@ -1074,7 +1056,7 @@ termp__a_pre(DECL_ARGS) if (NULL == n->next || MDOC__A != n->next->tok) term_word(p, "and"); - return(1); + return 1; } static int @@ -1084,12 +1066,12 @@ termp_an_pre(DECL_ARGS) if (n->norm->An.auth == AUTH_split) { p->flags &= ~TERMP_NOSPLIT; p->flags |= TERMP_SPLIT; - return(0); + return 0; } if (n->norm->An.auth == AUTH_nosplit) { p->flags &= ~TERMP_SPLIT; p->flags |= TERMP_NOSPLIT; - return(0); + return 0; } if (p->flags & TERMP_SPLIT) @@ -1098,7 +1080,7 @@ termp_an_pre(DECL_ARGS) if (n->sec == SEC_AUTHORS && ! (p->flags & TERMP_NOSPLIT)) p->flags |= TERMP_SPLIT; - return(1); + return 1; } static int @@ -1107,7 +1089,7 @@ termp_ns_pre(DECL_ARGS) if ( ! (MDOC_LINE & n->flags)) p->flags |= TERMP_NOSPACE; - return(1); + return 1; } static int @@ -1115,43 +1097,42 @@ termp_rs_pre(DECL_ARGS) { if (SEC_SEE_ALSO != n->sec) - return(1); + return 1; if (n->type == ROFFT_BLOCK && n->prev != NULL) term_vspace(p); - return(1); + return 1; } static int termp_rv_pre(DECL_ARGS) { - int nchild; + struct roff_node *nch; term_newln(p); - nchild = n->nchild; - if (nchild > 0) { + if (n->child != NULL) { term_word(p, "The"); - for (n = n->child; n; n = n->next) { + for (nch = n->child; nch != NULL; nch = nch->next) { term_fontpush(p, TERMFONT_BOLD); - term_word(p, n->string); + term_word(p, nch->string); term_fontpop(p); p->flags |= TERMP_NOSPACE; term_word(p, "()"); - if (n->next == NULL) + if (nch->next == NULL) continue; - if (nchild > 2) { + if (nch->prev != NULL || nch->next->next != NULL) { p->flags |= TERMP_NOSPACE; term_word(p, ","); } - if (n->next->next == NULL) + if (nch->next->next == NULL) term_word(p, "and"); } - if (nchild > 1) + if (n->child != NULL && n->child->next != NULL) term_word(p, "functions return"); else term_word(p, "function returns"); @@ -1171,33 +1152,35 @@ termp_rv_pre(DECL_ARGS) term_word(p, "is set to indicate the error."); p->flags |= TERMP_SENTENCE; - return(0); + return 0; } static int termp_ex_pre(DECL_ARGS) { - int nchild; + struct roff_node *nch; term_newln(p); term_word(p, "The"); - nchild = n->nchild; - for (n = n->child; n; n = n->next) { + for (nch = n->child; nch != NULL; nch = nch->next) { term_fontpush(p, TERMFONT_BOLD); - term_word(p, n->string); + term_word(p, nch->string); term_fontpop(p); - if (nchild > 2 && n->next) { + if (nch->next == NULL) + continue; + + if (nch->prev != NULL || nch->next->next != NULL) { p->flags |= TERMP_NOSPACE; term_word(p, ","); } - if (n->next && NULL == n->next->next) + if (nch->next->next == NULL) term_word(p, "and"); } - if (nchild > 1) + if (n->child != NULL && n->child->next != NULL) term_word(p, "utilities exit\\~0"); else term_word(p, "utility exits\\~0"); @@ -1205,7 +1188,7 @@ termp_ex_pre(DECL_ARGS) term_word(p, "on success, and\\~>0 if an error occurs."); p->flags |= TERMP_SENTENCE; - return(0); + return 0; } static int @@ -1214,14 +1197,14 @@ termp_nd_pre(DECL_ARGS) if (n->type == ROFFT_BODY) term_word(p, "\\(en"); - return(1); + return 1; } static int termp_bl_pre(DECL_ARGS) { - return(n->type != ROFFT_HEAD); + return n->type != ROFFT_HEAD; } static void @@ -1237,13 +1220,13 @@ termp_xr_pre(DECL_ARGS) { if (NULL == (n = n->child)) - return(0); + return 0; assert(n->type == ROFFT_TEXT); term_word(p, n->string); if (NULL == (n = n->next)) - return(0); + return 0; p->flags |= TERMP_NOSPACE; term_word(p, "("); @@ -1255,7 +1238,7 @@ termp_xr_pre(DECL_ARGS) p->flags |= TERMP_NOSPACE; term_word(p, ")"); - return(0); + return 0; } /* @@ -1293,13 +1276,9 @@ synopsis_pre(struct termp *p, const struct roff_node * */ switch (n->prev->tok) { case MDOC_Fd: - /* FALLTHROUGH */ case MDOC_Fn: - /* FALLTHROUGH */ case MDOC_Fo: - /* FALLTHROUGH */ case MDOC_In: - /* FALLTHROUGH */ case MDOC_Vt: term_vspace(p); break; @@ -1321,14 +1300,14 @@ termp_vt_pre(DECL_ARGS) if (n->type == ROFFT_ELEM) { synopsis_pre(p, n); - return(termp_under_pre(p, pair, meta, n)); + return termp_under_pre(p, pair, meta, n); } else if (n->type == ROFFT_BLOCK) { synopsis_pre(p, n); - return(1); + return 1; } else if (n->type == ROFFT_HEAD) - return(0); + return 0; - return(termp_under_pre(p, pair, meta, n)); + return termp_under_pre(p, pair, meta, n); } static int @@ -1337,7 +1316,7 @@ termp_bold_pre(DECL_ARGS) termp_tag_pre(p, pair, meta, n); term_fontpush(p, TERMFONT_BOLD); - return(1); + return 1; } static int @@ -1345,7 +1324,7 @@ termp_fd_pre(DECL_ARGS) { synopsis_pre(p, n); - return(termp_bold_pre(p, pair, meta, n)); + return termp_bold_pre(p, pair, meta, n); } static void @@ -1390,7 +1369,7 @@ termp_sh_pre(DECL_ARGS) default: break; } - return(1); + return 1; } static void @@ -1416,7 +1395,7 @@ termp_bt_pre(DECL_ARGS) term_word(p, "is currently in beta test."); p->flags |= TERMP_SENTENCE; - return(0); + return 0; } static void @@ -1433,7 +1412,7 @@ termp_ud_pre(DECL_ARGS) term_word(p, "currently under development."); p->flags |= TERMP_SENTENCE; - return(0); + return 0; } static int @@ -1441,10 +1420,10 @@ termp_d1_pre(DECL_ARGS) { if (n->type != ROFFT_BLOCK) - return(1); + return 1; term_newln(p); p->offset += term_len(p, p->defindent + 1); - return(1); + return 1; } static int @@ -1454,7 +1433,7 @@ termp_ft_pre(DECL_ARGS) /* NB: MDOC_LINE does not effect this! */ synopsis_pre(p, n); term_fontpush(p, TERMFONT_UNDER); - return(1); + return 1; } static int @@ -1468,7 +1447,7 @@ termp_fn_pre(DECL_ARGS) synopsis_pre(p, n); if (NULL == (n = n->child)) - return(0); + return 0; if (pretty) { rmargin = p->rmargin; @@ -1518,7 +1497,7 @@ termp_fn_pre(DECL_ARGS) term_flushln(p); } - return(0); + return 0; } static int @@ -1528,7 +1507,7 @@ termp_fa_pre(DECL_ARGS) if (n->parent->tok != MDOC_Fo) { term_fontpush(p, TERMFONT_UNDER); - return(1); + return 1; } for (nn = n->child; nn; nn = nn->next) { @@ -1543,7 +1522,7 @@ termp_fa_pre(DECL_ARGS) } } - return(0); + return 0; } static int @@ -1555,9 +1534,9 @@ termp_bd_pre(DECL_ARGS) if (n->type == ROFFT_BLOCK) { print_bvspace(p, n, n); - return(1); + return 1; } else if (n->type == ROFFT_HEAD) - return(0); + return 0; /* Handle the -offset argument. */ @@ -1587,7 +1566,7 @@ termp_bd_pre(DECL_ARGS) if (DISP_literal != n->norm->Bd.type && DISP_unfilled != n->norm->Bd.type && DISP_centered != n->norm->Bd.type) - return(1); + return 1; tabwidth = p->tabwidth; if (DISP_literal == n->norm->Bd.type) @@ -1617,19 +1596,12 @@ termp_bd_pre(DECL_ARGS) */ switch (nn->tok) { case MDOC_Sm: - /* FALLTHROUGH */ case MDOC_br: - /* FALLTHROUGH */ case MDOC_sp: - /* FALLTHROUGH */ case MDOC_Bl: - /* FALLTHROUGH */ case MDOC_D1: - /* FALLTHROUGH */ case MDOC_Dl: - /* FALLTHROUGH */ case MDOC_Lp: - /* FALLTHROUGH */ case MDOC_Pp: continue; default: @@ -1645,7 +1617,7 @@ termp_bd_pre(DECL_ARGS) p->tabwidth = tabwidth; p->rmargin = rm; p->maxrmargin = rmax; - return(0); + return 0; } static void @@ -1680,7 +1652,7 @@ termp_bx_pre(DECL_ARGS) term_word(p, "BSD"); } else { term_word(p, "BSD"); - return(0); + return 0; } if (NULL != (n = n->next)) { @@ -1690,7 +1662,7 @@ termp_bx_pre(DECL_ARGS) term_word(p, n->string); } - return(0); + return 0; } static int @@ -1721,7 +1693,6 @@ termp_xx_pre(DECL_ARGS) break; default: abort(); - /* NOTREACHED */ } term_word(p, pp); @@ -1731,7 +1702,7 @@ termp_xx_pre(DECL_ARGS) term_word(p, n->child->string); p->flags = flags; } - return(0); + return 0; } static void @@ -1763,7 +1734,7 @@ termp_ss_pre(DECL_ARGS) break; } - return(1); + return 1; } static void @@ -1780,7 +1751,7 @@ termp_cd_pre(DECL_ARGS) synopsis_pre(p, n); term_fontpush(p, TERMFONT_BOLD); - return(1); + return 1; } static int @@ -1799,7 +1770,7 @@ termp_in_pre(DECL_ARGS) } p->flags |= TERMP_NOSPACE; - return(1); + return 1; } static void @@ -1848,14 +1819,14 @@ termp_sp_pre(DECL_ARGS) for (i = 0; i < len; i++) term_vspace(p); - return(0); + return 0; } static int termp_skip_pre(DECL_ARGS) { - return(0); + return 0; } static int @@ -1863,66 +1834,54 @@ termp_quote_pre(DECL_ARGS) { if (n->type != ROFFT_BODY && n->type != ROFFT_ELEM) - return(1); + return 1; switch (n->tok) { case MDOC_Ao: - /* FALLTHROUGH */ case MDOC_Aq: - term_word(p, n->nchild == 1 && + term_word(p, n->child != NULL && n->child->next == NULL && n->child->tok == MDOC_Mt ? "<" : "\\(la"); break; case MDOC_Bro: - /* FALLTHROUGH */ case MDOC_Brq: term_word(p, "{"); break; case MDOC_Oo: - /* FALLTHROUGH */ case MDOC_Op: - /* FALLTHROUGH */ case MDOC_Bo: - /* FALLTHROUGH */ case MDOC_Bq: term_word(p, "["); break; case MDOC_Do: - /* FALLTHROUGH */ case MDOC_Dq: term_word(p, "\\(Lq"); break; case MDOC_En: if (NULL == n->norm->Es || NULL == n->norm->Es->child) - return(1); + return 1; term_word(p, n->norm->Es->child->string); break; case MDOC_Po: - /* FALLTHROUGH */ case MDOC_Pq: term_word(p, "("); break; case MDOC__T: - /* FALLTHROUGH */ case MDOC_Qo: - /* FALLTHROUGH */ case MDOC_Qq: term_word(p, "\""); break; case MDOC_Ql: - /* FALLTHROUGH */ case MDOC_So: - /* FALLTHROUGH */ case MDOC_Sq: term_word(p, "\\(oq"); break; default: abort(); - /* NOTREACHED */ } p->flags |= TERMP_NOSPACE; - return(1); + return 1; } static void @@ -1936,27 +1895,21 @@ termp_quote_post(DECL_ARGS) switch (n->tok) { case MDOC_Ao: - /* FALLTHROUGH */ case MDOC_Aq: - term_word(p, n->nchild == 1 && + term_word(p, n->child != NULL && n->child->next == NULL && n->child->tok == MDOC_Mt ? ">" : "\\(ra"); break; case MDOC_Bro: - /* FALLTHROUGH */ case MDOC_Brq: term_word(p, "}"); break; case MDOC_Oo: - /* FALLTHROUGH */ case MDOC_Op: - /* FALLTHROUGH */ case MDOC_Bo: - /* FALLTHROUGH */ case MDOC_Bq: term_word(p, "]"); break; case MDOC_Do: - /* FALLTHROUGH */ case MDOC_Dq: term_word(p, "\\(Rq"); break; @@ -1969,27 +1922,21 @@ termp_quote_post(DECL_ARGS) term_word(p, n->norm->Es->child->next->string); break; case MDOC_Po: - /* FALLTHROUGH */ case MDOC_Pq: term_word(p, ")"); break; case MDOC__T: - /* FALLTHROUGH */ case MDOC_Qo: - /* FALLTHROUGH */ case MDOC_Qq: term_word(p, "\""); break; case MDOC_Ql: - /* FALLTHROUGH */ case MDOC_So: - /* FALLTHROUGH */ case MDOC_Sq: term_word(p, "\\(cq"); break; default: abort(); - /* NOTREACHED */ } } @@ -1998,7 +1945,7 @@ termp_eo_pre(DECL_ARGS) { if (n->type != ROFFT_BODY) - return(1); + return 1; if (n->end == ENDBODY_NOT && n->parent->head->child == NULL && @@ -2010,7 +1957,7 @@ termp_eo_pre(DECL_ARGS) (n->parent->tail != NULL && n->parent->tail->child != NULL))) p->flags |= TERMP_NOSPACE; - return(1); + return 1; } static void @@ -2047,7 +1994,7 @@ termp_fo_pre(DECL_ARGS) if (n->type == ROFFT_BLOCK) { synopsis_pre(p, n); - return(1); + return 1; } else if (n->type == ROFFT_BODY) { if (pretty) { rmargin = p->rmargin; @@ -2065,18 +2012,18 @@ termp_fo_pre(DECL_ARGS) p->offset = p->rmargin; p->rmargin = rmargin; } - return(1); + return 1; } if (NULL == n->child) - return(0); + return 0; /* XXX: we drop non-initial arguments as per groff. */ assert(n->child->string); term_fontpush(p, TERMFONT_BOLD); term_word(p, n->child->string); - return(0); + return 0; } static void @@ -2101,9 +2048,9 @@ termp_bf_pre(DECL_ARGS) { if (n->type == ROFFT_HEAD) - return(0); + return 0; else if (n->type != ROFFT_BODY) - return(1); + return 1; if (FONT_Em == n->norm->Bf.font) term_fontpush(p, TERMFONT_UNDER); @@ -2112,7 +2059,7 @@ termp_bf_pre(DECL_ARGS) else term_fontpush(p, TERMFONT_NONE); - return(1); + return 1; } static int @@ -2129,7 +2076,7 @@ termp_sm_pre(DECL_ARGS) if (p->col && ! (TERMP_NONOSPACE & p->flags)) p->flags &= ~TERMP_NOSPACE; - return(0); + return 0; } static int @@ -2139,7 +2086,7 @@ termp_ap_pre(DECL_ARGS) p->flags |= TERMP_NOSPACE; term_word(p, "'"); p->flags |= TERMP_NOSPACE; - return(1); + return 1; } static void @@ -2174,7 +2121,7 @@ termp_li_pre(DECL_ARGS) { term_fontpush(p, TERMFONT_NONE); - return(1); + return 1; } static int @@ -2183,7 +2130,7 @@ termp_lk_pre(DECL_ARGS) const struct roff_node *link, *descr; if (NULL == (link = n->child)) - return(0); + return 0; if (NULL != (descr = link->next)) { term_fontpush(p, TERMFONT_UNDER); @@ -2200,7 +2147,7 @@ termp_lk_pre(DECL_ARGS) term_word(p, link->string); term_fontpop(p); - return(0); + return 0; } static int @@ -2211,17 +2158,16 @@ termp_bk_pre(DECL_ARGS) case ROFFT_BLOCK: break; case ROFFT_HEAD: - return(0); + return 0; case ROFFT_BODY: - if (n->parent->args || 0 == n->prev->nchild) + if (n->parent->args != NULL || n->prev->child == NULL) p->flags |= TERMP_PREKEEP; break; default: abort(); - /* NOTREACHED */ } - return(1); + return 1; } static void @@ -2257,10 +2203,10 @@ termp__t_pre(DECL_ARGS) */ if (n->parent && MDOC_Rs == n->parent->tok && n->parent->norm->Rs.quote_T) - return(termp_quote_pre(p, pair, meta, n)); + return termp_quote_pre(p, pair, meta, n); term_fontpush(p, TERMFONT_UNDER); - return(1); + return 1; } static int @@ -2268,7 +2214,7 @@ termp_under_pre(DECL_ARGS) { term_fontpush(p, TERMFONT_UNDER); - return(1); + return 1; } static int @@ -2280,7 +2226,7 @@ termp_er_pre(DECL_ARGS) (n->parent->tok == MDOC_Bq && n->parent->parent->parent->tok == MDOC_It))) tag_put(n->child->string, 1, p->line); - return(1); + return 1; } static int @@ -2295,5 +2241,5 @@ termp_tag_pre(DECL_ARGS) n->parent->parent->prev == NULL && n->parent->parent->parent->tok == MDOC_It))) tag_put(n->child->string, 1, p->line); - return(1); + return 1; }