- MAN_NEXT_CHILD : MAN_NEXT_SIBLING;
-}
-
-static enum rew
-rew_block(enum mant ntok, enum man_type type, const struct man_node *n)
-{
-
- if (type == MAN_BLOCK && ntok == n->parent->tok &&
- n->parent->type == MAN_BODY)
- 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);
-
- assert(n->parent);
-
- /* Normal nodes shouldn't go to the level of the root. */
- if (MAN_ROOT == n->parent->type)
- return(REW_REWIND);
-
- /* Already-validated nodes should be closed out. */
- if (MAN_VALID & n->flags)
- return(REW_NOHALT);
-
- /* First: rewind to ourselves. */
- if (type == n->type && tok == n->tok) {
- if (MAN_EXPLICIT & man_macros[n->tok].flags)
- return(REW_HALT);
- else
- return(REW_REWIND);
- }
-
- /*
- * Next follow the implicit scope-smashings as defined by man.7:
- * section, sub-section, etc.
- */
-
- switch (tok) {
- case MAN_SH:
- break;
- case MAN_SS:
- /* Rewind to a section, if a block. */
- if (REW_NOHALT != (c = rew_block(MAN_SH, type, n)))
- return(c);
- break;
- case MAN_RS:
- /* Preserve empty paragraphs before RS. */
- if (0 == n->nchild && (MAN_P == n->tok ||
- MAN_PP == n->tok || MAN_LP == n->tok))
- return(REW_HALT);
- /* Rewind to a subsection, if a block. */
- if (REW_NOHALT != (c = rew_block(MAN_SS, type, n)))
- return(c);
- /* Rewind to a section, if a block. */
- if (REW_NOHALT != (c = rew_block(MAN_SH, type, n)))
- return(c);
- break;
- default:
- /* Rewind to an offsetter, if a block. */
- if (REW_NOHALT != (c = rew_block(MAN_RS, type, n)))
- return(c);
- /* Rewind to a subsection, if a block. */
- if (REW_NOHALT != (c = rew_block(MAN_SS, type, n)))
- return(c);
- /* Rewind to a section, if a block. */
- if (REW_NOHALT != (c = rew_block(MAN_SH, type, n)))
- return(c);
- break;
- }
-
- return(REW_NOHALT);