+enum rew {
+ REW_REWIND,
+ REW_NOHALT,
+ REW_HALT
+};
+
+static int blk_close(MACRO_PROT_ARGS);
+static int blk_exp(MACRO_PROT_ARGS);
+static int blk_imp(MACRO_PROT_ARGS);
+static int in_line_eoln(MACRO_PROT_ARGS);
+
+static int rew_scope(enum man_type,
+ struct man *, enum mant);
+static enum rew rew_dohalt(enum mant, enum man_type,
+ const struct man_node *);
+static enum rew rew_block(enum mant, enum man_type,
+ const struct man_node *);
+static int rew_warn(struct man *,
+ struct man_node *, enum mandocerr);
+
+const struct man_macro __man_macros[MAN_MAX] = {
+ { in_line_eoln, MAN_NSCOPED }, /* br */
+ { in_line_eoln, 0 }, /* TH */
+ { blk_imp, MAN_SCOPED }, /* SH */
+ { blk_imp, MAN_SCOPED }, /* SS */
+ { blk_imp, MAN_SCOPED | MAN_FSCOPED }, /* TP */
+ { blk_imp, 0 }, /* LP */
+ { blk_imp, 0 }, /* PP */
+ { blk_imp, 0 }, /* P */
+ { blk_imp, 0 }, /* IP */
+ { blk_imp, 0 }, /* HP */
+ { in_line_eoln, MAN_SCOPED }, /* SM */
+ { in_line_eoln, MAN_SCOPED }, /* SB */
+ { in_line_eoln, 0 }, /* BI */
+ { in_line_eoln, 0 }, /* IB */
+ { in_line_eoln, 0 }, /* BR */
+ { in_line_eoln, 0 }, /* RB */
+ { in_line_eoln, MAN_SCOPED }, /* R */
+ { in_line_eoln, MAN_SCOPED }, /* B */
+ { in_line_eoln, MAN_SCOPED }, /* I */
+ { in_line_eoln, 0 }, /* IR */
+ { in_line_eoln, 0 }, /* RI */
+ { in_line_eoln, MAN_NSCOPED }, /* na */
+ { in_line_eoln, 0 }, /* i */
+ { in_line_eoln, MAN_NSCOPED }, /* sp */
+ { in_line_eoln, 0 }, /* nf */
+ { in_line_eoln, 0 }, /* fi */
+ { in_line_eoln, 0 }, /* r */
+ { blk_close, 0 }, /* RE */
+ { blk_exp, MAN_EXPLICIT }, /* RS */
+ { in_line_eoln, 0 }, /* DT */
+ { in_line_eoln, 0 }, /* UC */
+ { in_line_eoln, 0 }, /* PD */
+ { in_line_eoln, MAN_NSCOPED }, /* Sp */
+ { in_line_eoln, 0 }, /* Vb */
+ { in_line_eoln, 0 }, /* Ve */
+ { in_line_eoln, 0 }, /* AT */
+ { in_line_eoln, 0 }, /* in */
+};
+
+const struct man_macro * const man_macros = __man_macros;
+
+
+/*
+ * Warn when "n" is an explicit non-roff macro.
+ */
+static int
+rew_warn(struct man *m, struct man_node *n, enum mandocerr er)
+{
+
+ if (er == MANDOCERR_MAX || MAN_BLOCK != n->type)
+ return(1);
+ if (MAN_VALID & n->flags)
+ return(1);
+ if ( ! (MAN_EXPLICIT & man_macros[n->tok].flags))
+ return(1);
+ return(man_nmsg(m, n, er));
+}
+
+
+/*
+ * Rewind scope. If a code "er" != MANDOCERR_MAX has been provided, it
+ * will be used if an explicit block scope is being closed out.
+ */
+int
+man_unscope(struct man *m, const struct man_node *n,
+ enum mandocerr er)
+{
+
+ assert(n);
+
+ /* LINTED */
+ while (m->last != n) {
+ if ( ! rew_warn(m, m->last, er))
+ return(0);
+ if ( ! man_valid_post(m))
+ return(0);
+ if ( ! man_action_post(m))
+ return(0);
+ m->last = m->last->parent;
+ assert(m->last);
+ }
+
+ if ( ! rew_warn(m, m->last, er))
+ return(0);
+ if ( ! man_valid_post(m))
+ return(0);
+ if ( ! man_action_post(m))
+ return(0);
+
+ m->next = MAN_ROOT == m->last->type ?
+ MAN_NEXT_CHILD : MAN_NEXT_SIBLING;
+
+ return(1);
+}
+
+
+static enum rew
+rew_block(enum mant ntok, enum man_type type, const struct man_node *n)
+{
+
+ if (MAN_BLOCK == type && ntok == n->parent->tok &&
+ MAN_BODY == n->parent->type)
+ return(REW_REWIND);
+ return(ntok == n->tok ? REW_HALT : REW_NOHALT);
+}
+
+
+/*
+ * There are three scope levels: scoped to the root (all), scoped to the
+ * section (all less sections), and scoped to subsections (all less
+ * sections and subsections).
+ */
+static enum rew
+rew_dohalt(enum mant tok, enum man_type type, const struct man_node *n)
+{
+ enum rew c;
+
+ /* We cannot progress beyond the root ever. */
+ if (MAN_ROOT == n->type)
+ return(REW_HALT);