discuss@mandoc.bsd.lv
 help / color / mirror / Atom feed
* FWD: nested displays in mdoc
@ 2010-07-19 17:14 Ingo Schwarze
  0 siblings, 0 replies; only message in thread
From: Ingo Schwarze @ 2010-07-19 17:14 UTC (permalink / raw)
  To: discuss

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 <schwarze@usta.de> -----

From: Ingo Schwarze <schwarze@usta.de>
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 ? "<root>" : 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

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2010-07-19 17:14 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-07-19 17:14 FWD: nested displays in mdoc Ingo Schwarze

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).