From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp1.rz.uni-karlsruhe.de (Debian-exim@smtp1.rz.uni-karlsruhe.de [129.13.185.217]) by krisdoz.my.domain (8.14.3/8.14.3) with ESMTP id o6JHEGa2017457 for ; Mon, 19 Jul 2010 13:14:17 -0400 (EDT) Received: from hekate.usta.de (asta-nat.asta.uni-karlsruhe.de [172.22.63.82]) by smtp1.rz.uni-karlsruhe.de with esmtp (Exim 4.63 #1) id 1Oatuy-0000kI-1N; Mon, 19 Jul 2010 19:14:16 +0200 Received: from donnerwolke.usta.de ([172.24.96.3]) by hekate.usta.de with esmtp (Exim 4.71) (envelope-from ) id 1Oatuy-0001WQ-07 for discuss@mdocml.bsd.lv; Mon, 19 Jul 2010 19:14:16 +0200 Received: from iris.usta.de ([172.24.96.5] helo=usta.de) by donnerwolke.usta.de with esmtp (Exim 4.69) (envelope-from ) id 1Oatux-00076J-Vi for discuss@mdocml.bsd.lv; Mon, 19 Jul 2010 19:14:15 +0200 Received: from schwarze by usta.de with local (Exim 4.71) (envelope-from ) id 1Oatux-0000EM-Uo for discuss@mdocml.bsd.lv; Mon, 19 Jul 2010 19:14:15 +0200 Date: Mon, 19 Jul 2010 19:14:15 +0200 From: Ingo Schwarze To: discuss@mdocml.bsd.lv Subject: FWD: nested displays in mdoc Message-ID: <20100719171415.GE11054@iris.usta.de> X-Mailinglist: mdocml-discuss Reply-To: discuss@mdocml.bsd.lv MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.20 (2009-06-14) Hi, probably, the following patch won't apply any more as it is, it is now very old, more than five months. Anyway, this is just for your information. Yours, Ingo ----- Forwarded message from Ingo Schwarze ----- From: Ingo Schwarze Date: Wed, 17 Feb 2010 16:10:28 +0100 To: kristaps@kth.se Cc: jmc@openbsd.org Subject: FYI: nested displays in mdoc Hi Kristaps, hi Jason, our manual page mdoc.samples(7) says: Displays may be nested within displays and lists, but may not contain other displays. Huh? Groff and mandoc agree that lists (.Bl) may contains displays (e.g. .Bd). But the two halves of the above sentence do not appear to agree with each other regarding nested displays. So i checked groff, found that it does not die from nested displays, concluded that the first half of the sentence is accurate, and implemented nested displays in mandoc, see the attached patch. Only after completing mandoc support, while designing unit tests, i finally realized that nested lists are broken in groff: Groff handles literal displays within ragged displays properly, but when a literal display contains a ragged display, groff formats the inner ragged display in literal mode, and after leaving the inner display, it formats the rest of the outer literal display in ragged mode. Consequently, i now assume that the second half of the sentence is right, and i'm shelving my diff for now. Maybe we can come back to it after switching to mandoc, when comparison to groff doesn't matter that much any more, but now would not be the right time to commit it. I'm just telling you such that you are aware of it and the diff doesn't get lost. There are a handful of manual pages in OpenBSD using nested displays: - oldrdist(1) and fortune(6) use .Bd inside .Bd - openssl(1) and intro(8) use .Dl inside .Bd I'm soon going to send a patch fixing these to Jason, and i will also include a fix for the sentence cited above. Yours, Ingo Index: mdoc_action.c =================================================================== RCS file: /cvs/src/usr.bin/mandoc/mdoc_action.c,v retrieving revision 1.26 diff -u -p -r1.26 mdoc_action.c --- mdoc_action.c 23 Dec 2009 22:30:17 -0000 1.26 +++ mdoc_action.c 17 Feb 2010 14:32:40 -0000 @@ -61,9 +61,9 @@ static int post_sh(POST_ARGS); static int post_st(POST_ARGS); static int post_std(POST_ARGS); -static int pre_bd(PRE_ARGS); +static int pre_display(PRE_ARGS); +static int pre_literal(PRE_ARGS); static int pre_bl(PRE_ARGS); -static int pre_dl(PRE_ARGS); static int pre_offset(PRE_ARGS); static const struct actions mdoc_actions[MDOC_MAX] = { @@ -74,9 +74,9 @@ static const struct actions mdoc_actions { NULL, post_sh }, /* Sh */ { NULL, NULL }, /* Ss */ { NULL, NULL }, /* Pp */ - { NULL, NULL }, /* D1 */ - { pre_dl, post_display }, /* Dl */ - { pre_bd, post_display }, /* Bd */ + { pre_display, post_display }, /* D1 */ + { pre_display, post_display }, /* Dl */ + { pre_display, post_display }, /* Bd */ { NULL, NULL }, /* Ed */ { pre_bl, post_bl }, /* Bl */ { NULL, NULL }, /* El */ @@ -872,19 +872,6 @@ post_prol(POST_ARGS) } -/* - * Trigger a literal context. - */ -static int -pre_dl(PRE_ARGS) -{ - - if (MDOC_BODY == n->type) - m->flags |= MDOC_LITERAL; - return(1); -} - - /* ARGSUSED */ static int pre_offset(PRE_ARGS) @@ -914,33 +901,58 @@ pre_offset(PRE_ARGS) } +/* + * Control literal context. + * Used both when entering and exiting a display. + */ static int -pre_bl(PRE_ARGS) +pre_literal(PRE_ARGS) { + int literal = 0; - return(MDOC_BLOCK == n->type ? pre_offset(m, n) : 1); + for (; n; n = n->parent) { + if (MDOC_BLOCK != n->type) + continue; + if (MDOC_D1 == n->tok) + break; + if (MDOC_Dl == n->tok) { + literal = 1; + break; + } + if (MDOC_Bd == n->tok) { + int i; + for (i = 0; i < (int)n->args->argc; i++) + if (MDOC_Literal == n->args->argv[i].arg || + MDOC_Unfilled == n->args->argv[i].arg) + literal = 1; + break; + } + } + if (literal) + m->flags |= MDOC_LITERAL; + else + m->flags &= ~MDOC_LITERAL; + return(1); } static int -pre_bd(PRE_ARGS) +pre_display(PRE_ARGS) { - int i; - if (MDOC_BLOCK == n->type) + if (MDOC_BLOCK == n->type && MDOC_Bl == n->tok) return(pre_offset(m, n)); - if (MDOC_BODY != n->type) - return(1); + if (MDOC_BODY == n->type) + return(pre_literal(m, n)); + return(1); +} - /* Enter literal context if `Bd -literal' or `-unfilled'. */ - for (n = n->parent, i = 0; i < (int)n->args->argc; i++) - if (MDOC_Literal == n->args->argv[i].arg) - m->flags |= MDOC_LITERAL; - else if (MDOC_Unfilled == n->args->argv[i].arg) - m->flags |= MDOC_LITERAL; +static int +pre_bl(PRE_ARGS) +{ - return(1); + return(MDOC_BLOCK == n->type ? pre_offset(m, n) : 1); } @@ -948,9 +960,7 @@ static int post_display(POST_ARGS) { - if (MDOC_BODY == n->type) - m->flags &= ~MDOC_LITERAL; - return(1); + return(pre_literal(m, n->parent)); } Index: mdoc_validate.c =================================================================== RCS file: /cvs/src/usr.bin/mandoc/mdoc_validate.c,v retrieving revision 1.41 diff -u -p -r1.41 mdoc_validate.c --- mdoc_validate.c 1 Jan 2010 22:20:24 -0000 1.41 +++ mdoc_validate.c 17 Feb 2010 14:32:40 -0000 @@ -95,7 +95,6 @@ static int pre_bd(PRE_ARGS); static int pre_bl(PRE_ARGS); static int pre_cd(PRE_ARGS); static int pre_dd(PRE_ARGS); -static int pre_display(PRE_ARGS); static int pre_dt(PRE_ARGS); static int pre_er(PRE_ARGS); static int pre_ex(PRE_ARGS); @@ -130,10 +129,9 @@ static v_post posts_wline[] = { bwarn_g static v_post posts_wtext[] = { ewarn_ge1, NULL }; static v_post posts_xr[] = { eerr_ge1, eerr_le2, NULL }; static v_pre pres_an[] = { pre_an, NULL }; -static v_pre pres_bd[] = { pre_display, pre_bd, NULL }; +static v_pre pres_bd[] = { pre_bd, NULL }; static v_pre pres_bl[] = { pre_bl, NULL }; static v_pre pres_cd[] = { pre_cd, NULL }; -static v_pre pres_d1[] = { pre_display, NULL }; static v_pre pres_dd[] = { pre_dd, NULL }; static v_pre pres_dt[] = { pre_dt, NULL }; static v_pre pres_er[] = { pre_er, NULL }; @@ -154,8 +152,8 @@ const struct valids mdoc_valids[MDOC_MAX { pres_sh, posts_sh }, /* Sh */ { pres_ss, posts_ss }, /* Ss */ { NULL, posts_notext }, /* Pp */ - { pres_d1, posts_wline }, /* D1 */ - { pres_d1, posts_wline }, /* Dl */ + { NULL, posts_wline }, /* D1 */ + { NULL, posts_wline }, /* Dl */ { pres_bd, posts_bd }, /* Bd */ { NULL, NULL }, /* Ed */ { pres_bl, posts_bl }, /* Bl */ @@ -555,28 +553,6 @@ check_parent(PRE_ARGS, int tok, enum mdo MDOC_ROOT == t ? "" : mdoc_macronames[tok])); } - - -static int -pre_display(PRE_ARGS) -{ - struct mdoc_node *node; - - /* Display elements (`Bd', `D1'...) cannot be nested. */ - - if (MDOC_BLOCK != n->type) - return(1); - - /* LINTED */ - for (node = mdoc->last->parent; node; node = node->parent) - if (MDOC_BLOCK == node->type) - if (MDOC_Bd == node->tok) - break; - if (NULL == node) - return(1); - - return(mdoc_nerr(mdoc, n, ENESTDISP)); -} static int TEST CASE: .Dd $Mdocdate$ .Dt BD-NESTED 1 .Os .Sh NAME .Nm Bd-nested .Nd nested display blocks .Sh DESCRIPTION .Bd -ragged -offset indent start ragged .Bd -literal -offset indent nested literal .Ed end ragged .Ed .Bd -literal -offset indent start literal .Bd -ragged -offset indent nested ragged .Ed end literal .Ed .Bl -dash .It start list .Bd -literal -offset indent nested literal .Ed .It end list .El ----- End forwarded message ----- -- To unsubscribe send an email to discuss+unsubscribe@mdocml.bsd.lv