=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/mandoc/mdoc_validate.c,v retrieving revision 1.277 retrieving revision 1.278 diff -c -r1.277 -r1.278 *** src/usr.bin/mandoc/mdoc_validate.c 2018/08/17 20:31:52 1.277 --- src/usr.bin/mandoc/mdoc_validate.c 2018/12/03 21:00:06 1.278 *************** *** 1,4 **** ! /* $OpenBSD: mdoc_validate.c,v 1.277 2018/08/17 20:31:52 schwarze Exp $ */ /* * Copyright (c) 2008-2012 Kristaps Dzonsons * Copyright (c) 2010-2018 Ingo Schwarze --- 1,4 ---- ! /* $OpenBSD: mdoc_validate.c,v 1.278 2018/12/03 21:00:06 schwarze Exp $ */ /* * Copyright (c) 2008-2012 Kristaps Dzonsons * Copyright (c) 2010-2018 Ingo Schwarze *************** *** 62,67 **** --- 62,68 ---- static void rewrite_macro2len(struct roff_man *, char **); static int similar(const char *, const char *); + static void post_abort(POST_ARGS); static void post_an(POST_ARGS); static void post_an_norm(POST_ARGS); static void post_at(POST_ARGS); *************** *** 149,155 **** post_nd, /* Nd */ post_nm, /* Nm */ post_delim_nb, /* Op */ ! post_obsolete, /* Ot */ post_defaults, /* Pa */ post_rv, /* Rv */ post_st, /* St */ --- 150,156 ---- post_nd, /* Nd */ post_nm, /* Nm */ post_delim_nb, /* Op */ ! post_abort, /* Ot */ post_defaults, /* Pa */ post_rv, /* Rv */ post_st, /* St */ *************** *** 222,228 **** post_obsolete, /* Fr */ post_eoln, /* Ud */ post_lb, /* Lb */ ! post_par, /* Lp */ post_delim_nb, /* Lk */ post_defaults, /* Mt */ post_delim_nb, /* Brq */ --- 223,229 ---- post_obsolete, /* Fr */ post_eoln, /* Ud */ post_lb, /* Lb */ ! post_abort, /* Lp */ post_delim_nb, /* Lk */ post_defaults, /* Mt */ post_delim_nb, /* Brq */ *************** *** 283,295 **** --- 284,320 ---- }; + /* Validate the subtree rooted at mdoc->last. */ void mdoc_node_validate(struct roff_man *mdoc) { struct roff_node *n, *np; const v_post *p; + /* + * Translate obsolete macros to modern macros first + * such that later code does not need to look + * for the obsolete versions. + */ + n = mdoc->last; + switch (n->tok) { + case MDOC_Lp: + n->tok = MDOC_Pp; + break; + case MDOC_Ot: + post_obsolete(mdoc); + n->tok = MDOC_Ft; + break; + default: + break; + } + + /* + * Iterate over all children, recursing into each one + * in turn, depth-first. + */ + mdoc->last = mdoc->last->child; while (mdoc->last != NULL) { mdoc_node_validate(mdoc); *************** *** 299,304 **** --- 324,331 ---- mdoc->last = mdoc->last->next; } + /* Finally validate the macro itself. */ + mdoc->last = n; mdoc->next = ROFF_NEXT_SIBLING; switch (n->type) { *************** *** 485,490 **** --- 512,523 ---- } static void + post_abort(POST_ARGS) + { + abort(); + } + + static void post_delim(POST_ARGS) { const struct roff_node *nch; *************** *** 1248,1256 **** n->child->type == ROFFT_TEXT && mdoc->meta.msec != NULL) mandoc_xr_add(mdoc->meta.msec, n->child->string, -1, -1); ! if (n->last != NULL && ! (n->last->tok == MDOC_Pp || ! n->last->tok == MDOC_Lp)) mdoc_node_relink(mdoc, n->last); if (mdoc->meta.name == NULL) --- 1281,1287 ---- n->child->type == ROFFT_TEXT && mdoc->meta.msec != NULL) mandoc_xr_add(mdoc->meta.msec, n->child->string, -1, -1); ! if (n->last != NULL && n->last->tok == MDOC_Pp) mdoc_node_relink(mdoc, n->last); if (mdoc->meta.name == NULL) *************** *** 1603,1609 **** while (nc != NULL) { switch (nc->tok) { case MDOC_Pp: - case MDOC_Lp: case ROFF_br: break; default: --- 1634,1639 ---- *************** *** 2477,2483 **** } if ((np = mdoc->last->child) != NULL) ! if (np->tok == MDOC_Pp || np->tok == MDOC_Lp) { mandoc_vmsg(MANDOCERR_PAR_SKIP, mdoc->parse, np->line, np->pos, "%s after %s", roff_name[np->tok], --- 2507,2513 ---- } if ((np = mdoc->last->child) != NULL) ! if (np->tok == MDOC_Pp) { mandoc_vmsg(MANDOCERR_PAR_SKIP, mdoc->parse, np->line, np->pos, "%s after %s", roff_name[np->tok], *************** *** 2486,2492 **** } if ((np = mdoc->last->last) != NULL) ! if (np->tok == MDOC_Pp || np->tok == MDOC_Lp) { mandoc_vmsg(MANDOCERR_PAR_SKIP, mdoc->parse, np->line, np->pos, "%s at the end of %s", roff_name[np->tok], --- 2516,2522 ---- } if ((np = mdoc->last->last) != NULL) ! if (np->tok == MDOC_Pp) { mandoc_vmsg(MANDOCERR_PAR_SKIP, mdoc->parse, np->line, np->pos, "%s at the end of %s", roff_name[np->tok], *************** *** 2507,2519 **** return; /* ! * Don't allow prior `Lp' or `Pp' prior to a paragraph-type ! * block: `Lp', `Pp', or non-compact `Bd' or `Bl'. */ ! if (n->prev->tok != MDOC_Pp && ! n->prev->tok != MDOC_Lp && ! n->prev->tok != ROFF_br) return; if (n->tok == MDOC_Bl && n->norm->Bl.comp) return; --- 2537,2547 ---- return; /* ! * Don't allow `Pp' prior to a paragraph-type ! * block: `Pp' or non-compact `Bd' or `Bl'. */ ! if (n->prev->tok != MDOC_Pp && n->prev->tok != ROFF_br) return; if (n->tok == MDOC_Bl && n->norm->Bl.comp) return; *************** *** 2551,2557 **** np = mdoc->last->parent; if (np->tok != MDOC_Sh && np->tok != MDOC_Ss) return; ! } else if (np->tok != MDOC_Pp && np->tok != MDOC_Lp && (mdoc->last->tok != ROFF_br || (np->tok != ROFF_sp && np->tok != ROFF_br))) return; --- 2579,2585 ---- np = mdoc->last->parent; if (np->tok != MDOC_Sh && np->tok != MDOC_Ss) return; ! } else if (np->tok != MDOC_Pp && (mdoc->last->tok != ROFF_br || (np->tok != ROFF_sp && np->tok != ROFF_br))) return;