+static void
+break_intermediate(struct roff_node *n, struct roff_node *breaker)
+{
+ if (n != breaker &&
+ n->type != ROFFT_BLOCK && n->type != ROFFT_HEAD &&
+ (n->type != ROFFT_BODY || n->end != ENDBODY_NOT))
+ n = n->parent;
+ while (n != breaker) {
+ if ( ! (n->flags & NODE_VALID))
+ n->flags |= NODE_BROKEN;
+ n = n->parent;
+ }
+}
+
+/*
+ * 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 roff_man *mdoc, enum roff_tok tok, int line, int ppos,
+ struct roff_node *target)
+{
+ struct roff_node *n;
+ int irc;
+
+ if (target->flags & NODE_VALID)
+ return 0;
+
+ irc = 0;
+ for (n = mdoc->last; n != NULL && n != target; n = n->parent) {
+ if (n->flags & NODE_ENDED)
+ continue;
+ if (n->type == ROFFT_BLOCK &&
+ mdoc_macro(n->tok)->flags & MDOC_EXPLICIT) {
+ irc = 1;
+ break_intermediate(mdoc->last, target);
+ if (target->type == ROFFT_HEAD)
+ target->flags |= NODE_ENDED;
+ else if ( ! (target->flags & NODE_ENDED)) {
+ mandoc_msg(MANDOCERR_BLK_NEST,
+ line, ppos, "%s breaks %s",
+ roff_name[tok], roff_name[n->tok]);
+ mdoc_endbody_alloc(mdoc, line, ppos,
+ tok, target);
+ }
+ }
+ }
+ return irc;
+}
+