source@mandoc.bsd.lv
 help / color / mirror / Atom feed
From: schwarze@mdocml.bsd.lv
To: source@mdocml.bsd.lv
Subject: mdocml: Simplify and reindent make_pending().
Date: Mon, 2 Feb 2015 14:23:53 -0500 (EST)	[thread overview]
Message-ID: <5044414463617318755.enqueue@fantadrom.bsd.lv> (raw)

Log Message:
-----------
Simplify and reindent make_pending().  No functional change 
except that some error messages become less confusing.
Now the function is almost readable (but still requires 
nineteen lines of comments for fourteen lines of code).

Modified Files:
--------------
    mdocml:
        mdoc_macro.c

Revision Data
-------------
Index: mdoc_macro.c
===================================================================
RCS file: /home/cvs/mdocml/mdocml/mdoc_macro.c,v
retrieving revision 1.168
retrieving revision 1.169
diff -Lmdoc_macro.c -Lmdoc_macro.c -u -p -r1.168 -r1.169
--- mdoc_macro.c
+++ mdoc_macro.c
@@ -471,71 +471,64 @@ make_pending(struct mdoc *mdoc, struct m
 {
 	struct mdoc_node *n;
 
-	/* Iterate backwards, searching for the breaker. */
+	mandoc_vmsg(MANDOCERR_BLK_NEST, mdoc->parse, line, ppos,
+	    "%s breaks %s", mdoc_macronames[breaker->tok],
+	    mdoc_macronames[broken->tok]);
+
+	/*
+	 * If the *broken block (Z) is already broken by a block (B)
+	 * contained in the breaker (A), make the breaker pending
+	 * on that inner breaker (B).  Graphically,
+	 *
+	 * breaker=[A! broken=n=[B!->A (old broken=)[Z->B B] A] Z]
+	 *
+	 * In these graphics, "->" indicates the "pending" pointer and
+	 * "!" indicates the MDOC_BREAK flag.  Each of the cases gets
+	 * one additional pointer (B->A) and one additional flag (A!).
+	 */
 
-	for (n = broken->parent; ; n = n->parent) {
-
-		/*
-		 * If the *broken block (Z) is already broken and we
-		 * encounter its breaker (B), make the tok block (A)
-		 * pending on that inner breaker (B).
-		 * Graphically, [A n=[B! broken=[Z->B B] tok=A] Z]
-		 * becomes [A broken=[B! [Z->B B] tok=A] Z]
-		 * and finally [A! [B!->A [Z->B B] A] Z].
-		 * In these graphics, "->" indicates the "pending"
-		 * pointer and "!" indicates the MDOC_BREAK flag.
-		 * Each of the cases gets one additional pointer (B->A)
-		 * and one additional flag (A!).
-		 */
-		if (n == broken->pending) {
+	for (n = broken->parent; ; n = n->parent)
+		if (n == broken->pending)
 			broken = n;
-			continue;
-		}
-
-		if (n != breaker)
-			continue;
+		else if (n == breaker)
+			break;
 
-		/*
-		 * Found the breaker.
-		 * If another, outer breaker (X) is already pending on
-		 * the *broken block (B), we must not clobber the link
-		 * to the outer breaker, but make it pending on the
-		 * new, now inner breaker (A).
-		 * Graphically, [X! breaker=[A broken=[B->X X] tok=A] B]
-		 * becomes [X! breaker=[A->X broken=[B X] tok=A] B]
-		 * and finally [X! [A!->X [B->A X] A] B].
-		 */
-		if (broken->pending) {
-			struct mdoc_node *taker;
+	/*
+	 * Found the breaker.
+	 *
+	 * If another, outer breaker (X) is already pending on
+	 * the *broken block (B), we must not clobber the link
+	 * to the outer breaker, but make it pending on the new,
+	 * now inner breaker (A).  Graphically,
+	 *
+	 * [X! n=breaker=[A!->X broken=[B(->X)->A X] A] B].
+	 */
 
-			/*
-			 * If the inner breaker (A) is already broken,
-			 * too, it cannot take on the outer breaker (X)
-			 * but must hand it on to its own breakers (Y):
-			 * [X! [Y! breaker=[A->Y Y] broken=[B->X X] tok=A] B]
-			 * [X! take=[Y!->X brea=[A->Y Y] brok=[B X] tok=A] B]
-			 * and finally [X! [Y!->X [A!->Y Y] [B->A X] A] B].
-			 */
-			taker = breaker;
-			while (taker->pending)
-				taker = taker->pending;
-			taker->pending = broken->pending;
-		}
+	if (broken->pending != NULL) {
+		n = breaker;
 
 		/*
-		 * Now we have reduced the situation to the simplest
-		 * case, which is just breaker=[A broken=[B tok=A] B]
-		 * and becomes [A! [B->A A] B].
+		 * If the inner breaker (A) is already broken, too,
+		 * it cannot take on the outer breaker (X) but must
+		 * hand it on to its own breakers (Y).  Graphically,
+		 *
+		 * [X! n=[Y!->X breaker=[A!->Y Y] broken=[B(->X)->A X] A] B]
 		 */
-		broken->pending = breaker;
-		breaker->flags |= MDOC_BREAK;
-		if (breaker->body != NULL)
-			breaker->body->flags |= MDOC_BREAK;
-		mandoc_vmsg(MANDOCERR_BLK_NEST, mdoc->parse, line, ppos,
-		    "%s breaks %s", mdoc_macronames[breaker->tok],
-		    mdoc_macronames[broken->tok]);
-		return;
+
+		while (n->pending)
+			n = n->pending;
+		n->pending = broken->pending;
 	}
+
+	/*
+	 * Now we have reduced the situation to the simplest case:
+	 * breaker=[A! broken=[B->A A] B].
+	 */
+
+	broken->pending = breaker;
+	breaker->flags |= MDOC_BREAK;
+	if (breaker->body != NULL)
+		breaker->body->flags |= MDOC_BREAK;
 }
 
 static void
--
 To unsubscribe send an email to source+unsubscribe@mdocml.bsd.lv

                 reply	other threads:[~2015-02-02 19:23 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=5044414463617318755.enqueue@fantadrom.bsd.lv \
    --to=schwarze@mdocml.bsd.lv \
    --cc=source@mdocml.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).