source@mandoc.bsd.lv
 help / color / mirror / Atom feed
* mdocml: Reduce code duplication, no functional change: Both partial and
@ 2015-04-05 22:44 schwarze
  0 siblings, 0 replies; only message in thread
From: schwarze @ 2015-04-05 22:44 UTC (permalink / raw)
  To: source

Log Message:
-----------
Reduce code duplication, no functional change:
Both partial and full implicit blocks can break explicit blocks.
Put the code to handle both cases into a common function.

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.186
retrieving revision 1.187
diff -Lmdoc_macro.c -Lmdoc_macro.c -u -p -r1.186 -r1.187
--- mdoc_macro.c
+++ mdoc_macro.c
@@ -42,9 +42,11 @@ static	void		in_line_argn(MACRO_PROT_ARG
 static	void		in_line(MACRO_PROT_ARGS);
 static	void		phrase_ta(MACRO_PROT_ARGS);
 
-static	void		dword(struct mdoc *, int, int, const char *,
-				 enum mdelim, int);
 static	void		append_delims(struct mdoc *, int, int *, char *);
+static	void		dword(struct mdoc *, int, int, const char *,
+				enum mdelim, int);
+static	int		find_pending(struct mdoc *, int, int, int,
+				struct roff_node *);
 static	int		lookup(struct mdoc *, int, int, int, const char *);
 static	int		macro_or_word(MACRO_PROT_ARGS, int);
 static	int		parse_rest(struct mdoc *, int, int, int *, char *);
@@ -375,6 +377,44 @@ rew_elem(struct mdoc *mdoc, int tok)
 }
 
 /*
+ * If there is an open sub-block of the target requiring
+ * explicit close-out, postpone closing out the target until
+ * the rew_pending() call closing out the sub-block.
+ */
+static int
+find_pending(struct mdoc *mdoc, int tok, int line, int ppos,
+	struct roff_node *target)
+{
+	struct roff_node	*n;
+	int			 irc;
+
+	irc = 0;
+	for (n = mdoc->last; n != NULL && n != target; n = n->parent) {
+		if (n->flags & MDOC_ENDED) {
+			if ( ! (n->flags & MDOC_VALID))
+				n->flags |= MDOC_BROKEN;
+			continue;
+		}
+		if (n->type == ROFFT_BLOCK &&
+		    mdoc_macros[n->tok].flags & MDOC_EXPLICIT) {
+			irc = 1;
+			n->flags = MDOC_BROKEN;
+			if (target->type == ROFFT_HEAD)
+				target->flags = MDOC_ENDED;
+			else if ( ! (target->flags & MDOC_ENDED)) {
+				mandoc_vmsg(MANDOCERR_BLK_NEST,
+				    mdoc->parse, line, ppos,
+				    "%s breaks %s", mdoc_macronames[tok],
+				    mdoc_macronames[n->tok]);
+				mdoc_endbody_alloc(mdoc, line, ppos,
+				    tok, target, ENDBODY_NOSPACE);
+			}
+		}
+	}
+	return(irc);
+}
+
+/*
  * Allocate a word and check whether it's punctuation or not.
  * Punctuation consists of those tokens found in mdoc_isdelim().
  */
@@ -1070,26 +1110,7 @@ blk_full(MACRO_PROT_ARGS)
 		append_delims(mdoc, line, pos, buf);
 	if (body != NULL)
 		goto out;
-
-	/*
-	 * If there is an open (i.e., unvalidated) sub-block requiring
-	 * explicit close-out, postpone switching the current block from
-	 * head to body until the rew_pending() call closing out that
-	 * sub-block.
-	 */
-	for (n = mdoc->last; n && n != head; n = n->parent) {
-		if (n->flags & MDOC_ENDED) {
-			if ( ! (n->flags & MDOC_VALID))
-				n->flags |= MDOC_BROKEN;
-			continue;
-		}
-		if (n->type == ROFFT_BLOCK &&
-		    mdoc_macros[n->tok].flags & MDOC_EXPLICIT) {
-			n->flags = MDOC_BROKEN;
-			head->flags = MDOC_ENDED;
-		}
-	}
-	if (head->flags & MDOC_ENDED)
+	if (find_pending(mdoc, tok, line, ppos, head))
 		return;
 
 	/* Close out scopes to remain in a consistent state. */
@@ -1155,34 +1176,7 @@ blk_part_imp(MACRO_PROT_ARGS)
 	if (body == NULL)
 		body = mdoc_body_alloc(mdoc, line, ppos, tok);
 
-	/*
-	 * If there is an open sub-block requiring explicit close-out,
-	 * postpone closing out the current block until the
-	 * rew_pending() call closing out the sub-block.
-	 */
-
-	for (n = mdoc->last; n && n != body && n != blk->parent;
-	     n = n->parent) {
-		if (n->flags & MDOC_ENDED) {
-			if ( ! (n->flags & MDOC_VALID))
-				n->flags |= MDOC_BROKEN;
-			continue;
-		}
-		if (n->type == ROFFT_BLOCK &&
-		    mdoc_macros[n->tok].flags & MDOC_EXPLICIT) {
-			n->flags |= MDOC_BROKEN;
-			if ( ! (body->flags & MDOC_ENDED)) {
-				mandoc_vmsg(MANDOCERR_BLK_NEST,
-				    mdoc->parse, line, ppos,
-				    "%s breaks %s", mdoc_macronames[tok],
-				    mdoc_macronames[n->tok]);
-				mdoc_endbody_alloc(mdoc, line, ppos,
-				    tok, body, ENDBODY_NOSPACE);
-			}
-		}
-	}
-	assert(n == body);
-	if (body->flags & MDOC_ENDED)
+	if (find_pending(mdoc, tok, line, ppos, body))
 		return;
 
 	rew_last(mdoc, body);
--
 To unsubscribe send an email to source+unsubscribe@mdocml.bsd.lv

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

only message in thread, other threads:[~2015-04-05 22:44 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-04-05 22:44 mdocml: Reduce code duplication, no functional change: Both partial and 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).