From 4b1aedf8c8bc3e03034d513d5482e4eacccb7b6d Mon Sep 17 00:00:00 2001 From: schwarze Date: Tue, 24 Dec 2013 20:45:21 +0000 Subject: [PATCH] It turns out SYNOPSIS mode does not imply .Bk in general, but only within .Nm blocks. Simplify the code accordingly. This reduces groff-mandoc differences in base by about 2%. Triggered by research done by Franco Fichtner. --- regress/usr.bin/mandoc/mdoc/Bk/synopsis.in | 4 +- .../usr.bin/mandoc/mdoc/Bk/synopsis.out_ascii | 2 + usr.bin/mandoc/mdoc_html.c | 4 +- usr.bin/mandoc/mdoc_macro.c | 5 +-- usr.bin/mandoc/mdoc_man.c | 37 +++++++++---------- usr.bin/mandoc/mdoc_term.c | 27 +++++--------- 6 files changed, 36 insertions(+), 43 deletions(-) diff --git a/regress/usr.bin/mandoc/mdoc/Bk/synopsis.in b/regress/usr.bin/mandoc/mdoc/Bk/synopsis.in index 7dccddb388a..37832bbd9d9 100644 --- a/regress/usr.bin/mandoc/mdoc/Bk/synopsis.in +++ b/regress/usr.bin/mandoc/mdoc/Bk/synopsis.in @@ -1,10 +1,12 @@ -.Dd $Mdocdate: May 29 2013 $ +.Dd $Mdocdate: December 24 2013 $ .Dt BK-SYNOPSIS 1 .Os OpenBSD .Sh NAME .Nm Bk-synopsis .Nd automatic keeps in the synopsis .Sh SYNOPSIS +In the synopsis, almost all macros do not show +.No the word keep effect they would get in a \&Bk block. .Nm ksh .Op Fl +abCefhiklmnpruvXx .Op Fl +o Ar option diff --git a/regress/usr.bin/mandoc/mdoc/Bk/synopsis.out_ascii b/regress/usr.bin/mandoc/mdoc/Bk/synopsis.out_ascii index 05710039eef..082defe66d9 100644 --- a/regress/usr.bin/mandoc/mdoc/Bk/synopsis.out_ascii +++ b/regress/usr.bin/mandoc/mdoc/Bk/synopsis.out_ascii @@ -4,6 +4,8 @@ NNAAMMEE BBkk--ssyynnooppssiiss - automatic keeps in the synopsis SSYYNNOOPPSSIISS + In the synopsis, almost all macros do not show the word keep effect they + would get in a Bk block. kksshh [--++aabbCCeeffhhiikkllmmnnpprruuvvXXxx] [--++oo _o_p_t_i_o_n] [--cc _s_t_r_i_n_g | --ss | _f_i_l_e [_a_r_g_u_m_e_n_t _._._.]] kksshh [--++aabbCCeeffhhiikkllmmnnpprruuvvXXxx] [--++oo _o_p_t_i_o_n] diff --git a/usr.bin/mandoc/mdoc_html.c b/usr.bin/mandoc/mdoc_html.c index ec49796ead2..ac35871afc4 100644 --- a/usr.bin/mandoc/mdoc_html.c +++ b/usr.bin/mandoc/mdoc_html.c @@ -1,4 +1,4 @@ -/* $Id: mdoc_html.c,v 1.68 2013/12/24 19:10:34 schwarze Exp $ */ +/* $Id: mdoc_html.c,v 1.69 2013/12/24 20:45:21 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons * @@ -455,7 +455,7 @@ print_mdoc_node(MDOC_ARGS) break; } - if (HTML_KEEP & h->flags || MDOC_SYNPRETTY & n->flags) { + if (HTML_KEEP & h->flags) { if (n->prev ? (n->prev->lastline != n->line) : (n->parent && n->parent->line != n->line)) { h->flags &= ~HTML_KEEP; diff --git a/usr.bin/mandoc/mdoc_macro.c b/usr.bin/mandoc/mdoc_macro.c index 759adc273b6..caca6a4e914 100644 --- a/usr.bin/mandoc/mdoc_macro.c +++ b/usr.bin/mandoc/mdoc_macro.c @@ -1,4 +1,4 @@ -/* $Id: mdoc_macro.c,v 1.81 2013/12/24 19:10:34 schwarze Exp $ */ +/* $Id: mdoc_macro.c,v 1.82 2013/12/24 20:45:21 schwarze Exp $ */ /* * Copyright (c) 2008-2012 Kristaps Dzonsons * Copyright (c) 2010, 2012, 2013 Ingo Schwarze @@ -709,8 +709,7 @@ blk_exp_close(MACRO_PROT_ARGS) maxargs = 1; break; case (MDOC_Ek): - if ( ! (MDOC_SYNOPSIS & mdoc->flags)) - mdoc->flags &= ~MDOC_KEEP; + mdoc->flags &= ~MDOC_KEEP; default: maxargs = 0; break; diff --git a/usr.bin/mandoc/mdoc_man.c b/usr.bin/mandoc/mdoc_man.c index 65f62d8b8f7..3798dea7318 100644 --- a/usr.bin/mandoc/mdoc_man.c +++ b/usr.bin/mandoc/mdoc_man.c @@ -1,4 +1,4 @@ -/* $Id: mdoc_man.c,v 1.52 2013/10/07 22:21:56 schwarze Exp $ */ +/* $Id: mdoc_man.c,v 1.53 2013/12/24 20:45:21 schwarze Exp $ */ /* * Copyright (c) 2011, 2012, 2013 Ingo Schwarze * @@ -701,24 +701,12 @@ static int pre_sect(DECL_ARGS) { - switch (n->type) { - case (MDOC_HEAD): + if (MDOC_HEAD == n->type) { outflags |= MMAN_sp; print_block(manacts[n->tok].prefix, 0); print_word(""); putchar('\"'); outflags &= ~MMAN_spc; - break; - case (MDOC_BODY): - if (MDOC_Sh == n->tok) { - if (MDOC_SYNPRETTY & n->flags) - outflags |= MMAN_Bk; - else - outflags &= ~MMAN_Bk; - } - break; - default: - break; } return(1); } @@ -896,7 +884,7 @@ static void post_bk(DECL_ARGS) { - if (MDOC_BODY == n->type && ! (MDOC_SYNPRETTY & n->flags)) + if (MDOC_BODY == n->type) outflags &= ~MMAN_Bk; } @@ -1404,8 +1392,10 @@ pre_nm(DECL_ARGS) { char *name; - if (MDOC_BLOCK == n->type) + if (MDOC_BLOCK == n->type) { + outflags |= MMAN_Bk; pre_syn(n); + } if (MDOC_ELEM != n->type && MDOC_HEAD != n->type) return(1); name = n->child ? n->child->string : meta->name; @@ -1428,9 +1418,18 @@ static void post_nm(DECL_ARGS) { - if (MDOC_ELEM != n->type && MDOC_HEAD != n->type) - return; - font_pop(); + switch (n->type) { + case (MDOC_BLOCK): + outflags &= ~MMAN_Bk; + break; + case (MDOC_HEAD): + /* FALLTHROUGH */ + case (MDOC_ELEM): + font_pop(); + break; + default: + break; + } } static int diff --git a/usr.bin/mandoc/mdoc_term.c b/usr.bin/mandoc/mdoc_term.c index a2626ac51bc..94dd7bd0497 100644 --- a/usr.bin/mandoc/mdoc_term.c +++ b/usr.bin/mandoc/mdoc_term.c @@ -1,4 +1,4 @@ -/* $Id: mdoc_term.c,v 1.154 2013/12/24 19:10:34 schwarze Exp $ */ +/* $Id: mdoc_term.c,v 1.155 2013/12/24 20:45:21 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons * Copyright (c) 2010, 2012, 2013 Ingo Schwarze @@ -303,12 +303,9 @@ print_mdoc_node(DECL_ARGS) /* * Keeps only work until the end of a line. If a keep was * invoked in a prior line, revert it to PREKEEP. - * - * Also let SYNPRETTY sections behave as if they were wrapped - * in a `Bk' block. */ - if (TERMP_KEEP & p->flags || MDOC_SYNPRETTY & n->flags) { + if (TERMP_KEEP & p->flags) { if (n->prev ? (n->prev->lastline != n->line) : (n->parent && n->parent->line != n->line)) { p->flags &= ~TERMP_KEEP; @@ -316,16 +313,6 @@ print_mdoc_node(DECL_ARGS) } } - /* - * Since SYNPRETTY sections aren't "turned off" with `Ek', - * we have to intuit whether we should disable formatting. - */ - - if ( ! (MDOC_SYNPRETTY & n->flags) && - ((n->prev && MDOC_SYNPRETTY & n->prev->flags) || - (n->parent && MDOC_SYNPRETTY & n->parent->flags))) - p->flags &= ~(TERMP_KEEP | TERMP_PREKEEP); - /* * After the keep flags have been set up, we may now * produce output. Note that some pre-handlers do so. @@ -1006,8 +993,10 @@ static int termp_nm_pre(DECL_ARGS) { - if (MDOC_BLOCK == n->type) + if (MDOC_BLOCK == n->type) { + p->flags |= TERMP_PREKEEP; return(1); + } if (MDOC_BODY == n->type) { if (NULL == n->child) @@ -1056,7 +1045,9 @@ static void termp_nm_post(DECL_ARGS) { - if (MDOC_HEAD == n->type && n->next->child) { + if (MDOC_BLOCK == n->type) { + p->flags &= ~(TERMP_KEEP | TERMP_PREKEEP); + } else if (MDOC_HEAD == n->type && n->next->child) { term_flushln(p); p->flags &= ~(TERMP_NOBREAK | TERMP_HANG); p->trailspace = 0; @@ -2236,7 +2227,7 @@ static void termp_bk_post(DECL_ARGS) { - if (MDOC_BODY == n->type && ! (MDOC_SYNPRETTY & n->flags)) + if (MDOC_BODY == n->type) p->flags &= ~(TERMP_KEEP | TERMP_PREKEEP); } -- 2.20.1