source@mandoc.bsd.lv
 help / color / mirror / Atom feed
From: schwarze@mandoc.bsd.lv
To: source@mandoc.bsd.lv
Subject: mandoc: Correctly set the ROFF_NOFILL parser flag for .Bd .Ed .Sh, such
Date: Tue, 1 Jan 2019 02:42:35 -0500 (EST)	[thread overview]
Message-ID: <05f899a7e1bb0f62@fantadrom.bsd.lv> (raw)

Log Message:
-----------
Correctly set the ROFF_NOFILL parser flag for .Bd .Ed .Sh, such
that children and later siblings get correct NODE_NOFILL assignments.
This doesn't change rendering yet but prepares for future rendering
improvements.

Modified Files:
--------------
    mandoc:
        mdoc_macro.c
        mdoc_state.c

Revision Data
-------------
Index: mdoc_state.c
===================================================================
RCS file: /home/cvs/mandoc/mandoc/mdoc_state.c,v
retrieving revision 1.14
retrieving revision 1.15
diff -Lmdoc_state.c -Lmdoc_state.c -u -p -r1.14 -r1.15
--- mdoc_state.c
+++ mdoc_state.c
@@ -32,9 +32,7 @@
 
 typedef	void	(*state_handler)(STATE_ARGS);
 
-static	void	 state_bd(STATE_ARGS);
 static	void	 state_bl(STATE_ARGS);
-static	void	 state_dl(STATE_ARGS);
 static	void	 state_sh(STATE_ARGS);
 static	void	 state_sm(STATE_ARGS);
 
@@ -46,8 +44,8 @@ static	const state_handler state_handler
 	NULL,		/* Ss */
 	NULL,		/* Pp */
 	NULL,		/* D1 */
-	state_dl,	/* Dl */
-	state_bd,	/* Bd */
+	NULL,		/* Dl */
+	NULL,		/* Bd */
 	NULL,		/* Ed */
 	state_bl,	/* Bl */
 	NULL,		/* El */
@@ -180,25 +178,6 @@ mdoc_state(struct roff_man *mdoc, struct
 }
 
 static void
-state_bd(STATE_ARGS)
-{
-	enum mdocargt arg;
-
-	if (n->type != ROFFT_HEAD &&
-	    (n->type != ROFFT_BODY || n->end != ENDBODY_NOT))
-		return;
-
-	if (n->parent->args == NULL)
-		return;
-
-	arg = n->parent->args->argv[0].arg;
-	if (arg != MDOC_Literal && arg != MDOC_Unfilled)
-		return;
-
-	state_dl(mdoc, n);
-}
-
-static void
 state_bl(STATE_ARGS)
 {
 	struct mdoc_arg	*args;
@@ -219,22 +198,6 @@ state_bl(STATE_ARGS)
 		default:
 			break;
 		}
-	}
-}
-
-static void
-state_dl(STATE_ARGS)
-{
-
-	switch (n->type) {
-	case ROFFT_HEAD:
-		mdoc->flags |= ROFF_NOFILL;
-		break;
-	case ROFFT_BODY:
-		mdoc->flags &= ~ROFF_NOFILL;
-		break;
-	default:
-		break;
 	}
 }
 
Index: mdoc_macro.c
===================================================================
RCS file: /home/cvs/mandoc/mandoc/mdoc_macro.c,v
retrieving revision 1.230
retrieving revision 1.231
diff -Lmdoc_macro.c -Lmdoc_macro.c -u -p -r1.230 -r1.231
--- mdoc_macro.c
+++ mdoc_macro.c
@@ -1,7 +1,7 @@
 /*	$Id$ */
 /*
  * Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv>
- * Copyright (c) 2010, 2012-2018 Ingo Schwarze <schwarze@openbsd.org>
+ * Copyright (c) 2010, 2012-2019 Ingo Schwarze <schwarze@openbsd.org>
  *
  * Permission to use, copy, modify, and distribute this software for any
  * purpose with or without fee is hereby granted, provided that the above
@@ -696,6 +696,19 @@ blk_exp_close(MACRO_PROT_ARGS)
 			    "%s %s", roff_name[tok], buf + *pos);
 		if (endbody == NULL && n != NULL)
 			rew_pending(mdoc, n);
+
+		/*
+		 * Restore the fill mode that was set before the display.
+		 * This needs to be done here rather than during validation
+		 * such that subsequent nodes get the right flags.
+		 */
+
+		if (tok == MDOC_Ed && body != NULL) {
+			if (body->flags & NODE_NOFILL)
+				mdoc->flags |= ROFF_NOFILL;
+			else
+				mdoc->flags &= ~ROFF_NOFILL;
+		}
 		return;
 	}
 
@@ -936,14 +949,15 @@ in_line(MACRO_PROT_ARGS)
 static void
 blk_full(MACRO_PROT_ARGS)
 {
-	int		  done, la, nl, parsed;
 	struct mdoc_arg	 *arg;
 	struct roff_node *blk; /* Our own or a broken block. */
 	struct roff_node *head; /* Our own head. */
 	struct roff_node *body; /* Our own body. */
 	struct roff_node *n;
-	enum margserr	  ac, lac;
 	char		 *p;
+	size_t		  iarg;
+	int		  done, la, nl, parsed;
+	enum margserr	  ac, lac;
 
 	nl = MDOC_NEWLINE & mdoc->flags;
 
@@ -1039,6 +1053,9 @@ blk_full(MACRO_PROT_ARGS)
 	 * regular child nodes.
 	 */
 
+	if (tok == MDOC_Sh)
+		mdoc->flags &= ~ROFF_NOFILL;
+
 	mdoc_argv(mdoc, line, tok, &arg, pos, buf);
 	blk = mdoc_block_alloc(mdoc, line, ppos, tok, arg);
 	head = body = NULL;
@@ -1180,6 +1197,31 @@ blk_full(MACRO_PROT_ARGS)
 
 	rew_last(mdoc, head);
 	body = roff_body_alloc(mdoc, line, ppos, tok);
+
+	/*
+	 * Set up fill mode for display blocks.
+	 * This needs to be done here up front rather than during
+	 * validation such that child nodes get the right flags.
+	 */
+
+	if (tok == MDOC_Bd && arg != NULL) {
+		for (iarg = 0; iarg < arg->argc; iarg++) {
+			switch (arg->argv[iarg].arg) {
+			case MDOC_Unfilled:
+			case MDOC_Literal:
+				mdoc->flags |= ROFF_NOFILL;
+				break;
+			case MDOC_Filled:
+			case MDOC_Ragged:
+			case MDOC_Centred:
+				mdoc->flags &= ~ROFF_NOFILL;
+				break;
+			default:
+				continue;
+			}
+			break;
+		}
+	}
 out:
 	if (mdoc->flags & MDOC_FREECOL) {
 		rew_last(mdoc, body);
--
 To unsubscribe send an email to source+unsubscribe@mandoc.bsd.lv

                 reply	other threads:[~2019-01-01  7:42 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=05f899a7e1bb0f62@fantadrom.bsd.lv \
    --to=schwarze@mandoc.bsd.lv \
    --cc=source@mandoc.bsd.lv \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).