=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/mandoc/mdoc_term.c,v retrieving revision 1.275 retrieving revision 1.276 diff -c -r1.275 -r1.276 *** src/usr.bin/mandoc/mdoc_term.c 2020/01/20 10:29:31 1.275 --- src/usr.bin/mandoc/mdoc_term.c 2020/02/27 01:25:57 1.276 *************** *** 1,4 **** ! /* $OpenBSD: mdoc_term.c,v 1.275 2020/01/20 10:29:31 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons * Copyright (c) 2010, 2012-2020 Ingo Schwarze --- 1,4 ---- ! /* $OpenBSD: mdoc_term.c,v 1.276 2020/02/27 01:25:57 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons * Copyright (c) 2010, 2012-2020 Ingo Schwarze *************** *** 52,65 **** static int a2width(const struct termp *, const char *); static void print_bvspace(struct termp *, ! const struct roff_node *, ! const struct roff_node *); static void print_mdoc_node(DECL_ARGS); static void print_mdoc_nodelist(DECL_ARGS); static void print_mdoc_head(struct termp *, const struct roff_meta *); static void print_mdoc_foot(struct termp *, const struct roff_meta *); ! static void synopsis_pre(struct termp *, ! const struct roff_node *); static void termp____post(DECL_ARGS); static void termp__t_post(DECL_ARGS); --- 52,63 ---- static int a2width(const struct termp *, const char *); static void print_bvspace(struct termp *, ! struct roff_node *, struct roff_node *); static void print_mdoc_node(DECL_ARGS); static void print_mdoc_nodelist(DECL_ARGS); static void print_mdoc_head(struct termp *, const struct roff_meta *); static void print_mdoc_foot(struct termp *, const struct roff_meta *); ! static void synopsis_pre(struct termp *, struct roff_node *); static void termp____post(DECL_ARGS); static void termp__t_post(DECL_ARGS); *************** *** 580,608 **** * too. */ static void ! print_bvspace(struct termp *p, ! const struct roff_node *bl, ! const struct roff_node *n) { ! const struct roff_node *nn; - assert(n); - term_newln(p); ! if (MDOC_Bd == bl->tok && bl->norm->Bd.comp) return; - if (MDOC_Bl == bl->tok && bl->norm->Bl.comp) - return; /* Do not vspace directly after Ss/Sh. */ nn = n; ! while (nn->prev != NULL && ! (nn->prev->type == ROFFT_COMMENT || ! nn->prev->flags & NODE_NOPRT)) ! nn = nn->prev; ! while (nn->prev == NULL) { do { nn = nn->parent; if (nn->type == ROFFT_ROOT) --- 578,597 ---- * too. */ static void ! print_bvspace(struct termp *p, struct roff_node *bl, struct roff_node *n) { ! struct roff_node *nn; term_newln(p); ! if ((bl->tok == MDOC_Bd && bl->norm->Bd.comp) || ! (bl->tok == MDOC_Bl && bl->norm->Bl.comp)) return; /* Do not vspace directly after Ss/Sh. */ nn = n; ! while (roff_node_prev(nn) == NULL) { do { nn = nn->parent; if (nn->type == ROFFT_ROOT) *************** *** 615,636 **** break; } ! /* A `-column' does not assert vspace within the list. */ ! if (MDOC_Bl == bl->tok && LIST_column == bl->norm->Bl.type) ! if (n->prev && MDOC_It == n->prev->tok) ! return; ! ! /* A `-diag' without body does not vspace. */ ! ! if (MDOC_Bl == bl->tok && LIST_diag == bl->norm->Bl.type) ! if (n->prev && MDOC_It == n->prev->tok) { ! assert(n->prev->body); ! if (NULL == n->prev->body->child) ! return; ! } ! ! term_vspace(p); } --- 604,621 ---- break; } ! /* ! * No vertical space after: ! * items in .Bl -column ! * items without a body in .Bl -diag ! */ ! if (bl->tok != MDOC_Bl || ! n->prev == NULL || n->prev->tok != MDOC_It || ! (bl->norm->Bl.type != LIST_column && ! (bl->norm->Bl.type != LIST_diag || ! n->prev->body->child != NULL))) ! term_vspace(p); } *************** *** 1041,1055 **** static int termp_fl_pre(DECL_ARGS) { termp_tag_pre(p, pair, meta, n); term_fontpush(p, TERMFONT_BOLD); term_word(p, "\\-"); ! if (!(n->child == NULL && ! (n->next == NULL || ! n->next->type == ROFFT_TEXT || ! n->next->flags & NODE_LINE))) p->flags |= TERMP_NOSPACE; return 1; --- 1026,1041 ---- static int termp_fl_pre(DECL_ARGS) { + struct roff_node *nn; termp_tag_pre(p, pair, meta, n); term_fontpush(p, TERMFONT_BOLD); term_word(p, "\\-"); ! if (n->child != NULL || ! ((nn = roff_node_next(n)) != NULL && ! nn->type != ROFFT_TEXT && ! (nn->flags & NODE_LINE) == 0)) p->flags |= TERMP_NOSPACE; return 1; *************** *** 1058,1067 **** static int termp__a_pre(DECL_ARGS) { ! if (n->prev && MDOC__A == n->prev->tok) ! if (NULL == n->next || MDOC__A != n->next->tok) ! term_word(p, "and"); return 1; } --- 1044,1054 ---- static int termp__a_pre(DECL_ARGS) { + struct roff_node *nn; ! if ((nn = roff_node_prev(n)) != NULL && nn->tok == MDOC__A && ! ((nn = roff_node_next(n)) == NULL || nn->tok != MDOC__A)) ! term_word(p, "and"); return 1; } *************** *** 1102,1111 **** static int termp_rs_pre(DECL_ARGS) { - if (SEC_SEE_ALSO != n->sec) return 1; ! if (n->type == ROFFT_BLOCK && n->prev != NULL) term_vspace(p); return 1; } --- 1089,1097 ---- static int termp_rs_pre(DECL_ARGS) { if (SEC_SEE_ALSO != n->sec) return 1; ! if (n->type == ROFFT_BLOCK && roff_node_prev(n) != NULL) term_vspace(p); return 1; } *************** *** 1179,1191 **** * macro combos). */ static void ! synopsis_pre(struct termp *p, const struct roff_node *n) { ! /* ! * Obviously, if we're not in a SYNOPSIS or no prior macros ! * exist, do nothing. ! */ ! if (NULL == n->prev || ! (NODE_SYNPRETTY & n->flags)) return; /* --- 1165,1176 ---- * macro combos). */ static void ! synopsis_pre(struct termp *p, struct roff_node *n) { ! struct roff_node *np; ! ! if ((n->flags & NODE_SYNPRETTY) == 0 || ! (np = roff_node_prev(n)) == NULL) return; /* *************** *** 1193,1199 **** * newline and return. UNLESS we're `Fo', `Fn', `Fn', in which * case we soldier on. */ ! if (n->prev->tok == n->tok && MDOC_Ft != n->tok && MDOC_Fo != n->tok && MDOC_Fn != n->tok) { --- 1178,1184 ---- * newline and return. UNLESS we're `Fo', `Fn', `Fn', in which * case we soldier on. */ ! if (np->tok == n->tok && MDOC_Ft != n->tok && MDOC_Fo != n->tok && MDOC_Fn != n->tok) { *************** *** 1206,1212 **** * another (or Fn/Fo, which we've let slip through) then assert * vertical space, else only newline and move on. */ ! switch (n->prev->tok) { case MDOC_Fd: case MDOC_Fn: case MDOC_Fo: --- 1191,1197 ---- * another (or Fn/Fo, which we've let slip through) then assert * vertical space, else only newline and move on. */ ! switch (np->tok) { case MDOC_Fd: case MDOC_Fn: case MDOC_Fo: *************** *** 1215,1221 **** term_vspace(p); break; case MDOC_Ft: ! if (MDOC_Fn != n->tok && MDOC_Fo != n->tok) { term_vspace(p); break; } --- 1200,1206 ---- term_vspace(p); break; case MDOC_Ft: ! if (n->tok != MDOC_Fn && n->tok != MDOC_Fo) { term_vspace(p); break; } *************** *** 1269,1274 **** --- 1254,1260 ---- static int termp_sh_pre(DECL_ARGS) { + struct roff_node *np; switch (n->type) { case ROFFT_BLOCK: *************** *** 1276,1285 **** * Vertical space before sections, except * when the previous section was empty. */ ! if (n->prev == NULL || ! n->prev->tok != MDOC_Sh || ! (n->prev->body != NULL && ! n->prev->body->child != NULL)) term_vspace(p); break; case ROFFT_HEAD: --- 1262,1270 ---- * Vertical space before sections, except * when the previous section was empty. */ ! if ((np = roff_node_prev(n)) == NULL || ! np->tok != MDOC_Sh || ! (np->body != NULL && np->body->child != NULL)) term_vspace(p); break; case ROFFT_HEAD: *************** *** 1430,1448 **** term_fontpush(p, TERMFONT_UNDER); return 1; } ! ! for (nn = n->child; nn; nn = nn->next) { term_fontpush(p, TERMFONT_UNDER); p->flags |= TERMP_NBRWORD; term_word(p, nn->string); term_fontpop(p); ! ! if (nn->next || (n->next && n->next->tok == MDOC_Fa)) { p->flags |= TERMP_NOSPACE; term_word(p, ","); } } ! return 0; } --- 1415,1436 ---- term_fontpush(p, TERMFONT_UNDER); return 1; } ! for (nn = n->child; nn != NULL; nn = nn->next) { term_fontpush(p, TERMFONT_UNDER); p->flags |= TERMP_NBRWORD; term_word(p, nn->string); term_fontpop(p); ! if (nn->next != NULL) { p->flags |= TERMP_NOSPACE; term_word(p, ","); } } ! if (n->child != NULL && ! (nn = roff_node_next(n)) != NULL && ! nn->tok == MDOC_Fa) { ! p->flags |= TERMP_NOSPACE; ! term_word(p, ","); ! } return 0; } *************** *** 1522,1545 **** static void termp_pf_post(DECL_ARGS) { ! ! if ( ! (n->next == NULL || n->next->flags & NODE_LINE)) p->flags |= TERMP_NOSPACE; } static int termp_ss_pre(DECL_ARGS) { - struct roff_node *nn; - switch (n->type) { case ROFFT_BLOCK: ! term_newln(p); ! for (nn = n->prev; nn != NULL; nn = nn->prev) ! if (nn->type != ROFFT_COMMENT && ! (nn->flags & NODE_NOPRT) == 0) ! break; ! if (nn != NULL) term_vspace(p); break; case ROFFT_HEAD: --- 1510,1527 ---- static void termp_pf_post(DECL_ARGS) { ! if (n->next != NULL && (n->next->flags & NODE_LINE) == 0) p->flags |= TERMP_NOSPACE; } static int termp_ss_pre(DECL_ARGS) { switch (n->type) { case ROFFT_BLOCK: ! if (roff_node_prev(n) == NULL) ! term_newln(p); ! else term_vspace(p); break; case ROFFT_HEAD: *************** *** 1555,1568 **** default: break; } - return 1; } static void termp_ss_post(DECL_ARGS) { - if (n->type == ROFFT_HEAD || n->type == ROFFT_BODY) term_newln(p); } --- 1537,1548 ---- *************** *** 1890,1913 **** static void termp____post(DECL_ARGS) { /* * Handle lists of authors. In general, print each followed by * a comma. Don't print the comma if there are only two * authors. */ ! if (MDOC__A == n->tok && n->next && MDOC__A == n->next->tok) ! if (NULL == n->next->next || MDOC__A != n->next->next->tok) ! if (NULL == n->prev || MDOC__A != n->prev->tok) ! return; /* TODO: %U. */ ! if (NULL == n->parent || MDOC_Rs != n->parent->tok) return; p->flags |= TERMP_NOSPACE; ! if (NULL == n->next) { term_word(p, "."); p->flags |= TERMP_SENTENCE; } else --- 1870,1895 ---- static void termp____post(DECL_ARGS) { + struct roff_node *nn; /* * Handle lists of authors. In general, print each followed by * a comma. Don't print the comma if there are only two * authors. */ ! if (n->tok == MDOC__A && ! (nn = roff_node_next(n)) != NULL && nn->tok == MDOC__A && ! ((nn = roff_node_next(nn)) == NULL || nn->tok != MDOC__A) && ! ((nn = roff_node_prev(n)) == NULL || nn->tok != MDOC__A)) ! return; /* TODO: %U. */ ! if (n->parent == NULL || n->parent->tok != MDOC_Rs) return; p->flags |= TERMP_NOSPACE; ! if (roff_node_next(n) == NULL) { term_word(p, "."); p->flags |= TERMP_SENTENCE; } else