diff options
-rw-r--r-- | man_html.c | 17 | ||||
-rw-r--r-- | man_term.c | 11 | ||||
-rw-r--r-- | man_validate.c | 35 | ||||
-rw-r--r-- | mdoc_html.c | 12 | ||||
-rw-r--r-- | mdoc_man.c | 11 | ||||
-rw-r--r-- | mdoc_markdown.c | 12 | ||||
-rw-r--r-- | mdoc_term.c | 12 | ||||
-rw-r--r-- | mdoc_validate.c | 56 | ||||
-rw-r--r-- | regress/man/PP/args.out_lint | 4 |
9 files changed, 132 insertions, 38 deletions
@@ -63,6 +63,7 @@ static int man_SM_pre(MAN_ARGS); static int man_SS_pre(MAN_ARGS); static int man_SY_pre(MAN_ARGS); static int man_UR_pre(MAN_ARGS); +static int man_abort_pre(MAN_ARGS); static int man_alt_pre(MAN_ARGS); static int man_ign_pre(MAN_ARGS); static int man_in_pre(MAN_ARGS); @@ -77,9 +78,9 @@ static const struct man_html_act man_html_acts[MAN_MAX - MAN_TH] = { { man_SS_pre, NULL }, /* SS */ { man_IP_pre, NULL }, /* TP */ { man_IP_pre, NULL }, /* TQ */ - { man_PP_pre, NULL }, /* LP */ + { man_abort_pre, NULL }, /* LP */ { man_PP_pre, NULL }, /* PP */ - { man_PP_pre, NULL }, /* P */ + { man_abort_pre, NULL }, /* P */ { man_IP_pre, NULL }, /* IP */ { man_HP_pre, NULL }, /* HP */ { man_SM_pre, NULL }, /* SM */ @@ -234,10 +235,8 @@ print_man_node(MAN_ARGS) want_fillmode = MAN_fi; /* FALLTHROUGH */ case MAN_PP: /* These have no head. */ - case MAN_LP: /* They will simply */ - case MAN_P: /* reopen .nf in the body. */ - case MAN_RS: - case MAN_UR: + case MAN_RS: /* They will simply */ + case MAN_UR: /* reopen .nf in the body. */ case MAN_MT: fillmode(h, MAN_fi); break; @@ -672,3 +671,9 @@ man_UR_pre(MAN_ARGS) return 0; } + +static int +man_abort_pre(MAN_ARGS) +{ + abort(); +} @@ -81,6 +81,7 @@ static int pre_SS(DECL_ARGS); static int pre_SY(DECL_ARGS); static int pre_TP(DECL_ARGS); static int pre_UR(DECL_ARGS); +static int pre_abort(DECL_ARGS); static int pre_alternate(DECL_ARGS); static int pre_ign(DECL_ARGS); static int pre_in(DECL_ARGS); @@ -101,9 +102,9 @@ static const struct man_term_act man_term_acts[MAN_MAX - MAN_TH] = { { pre_SS, post_SS, 0 }, /* SS */ { pre_TP, post_TP, 0 }, /* TP */ { pre_TP, post_TP, 0 }, /* TQ */ - { pre_PP, NULL, 0 }, /* LP */ + { pre_abort, NULL, 0 }, /* LP */ { pre_PP, NULL, 0 }, /* PP */ - { pre_PP, NULL, 0 }, /* P */ + { pre_abort, NULL, 0 }, /* P */ { pre_IP, post_IP, 0 }, /* IP */ { pre_HP, post_HP, 0 }, /* HP */ { NULL, NULL, 0 }, /* SM */ @@ -222,6 +223,12 @@ print_bvspace(struct termp *p, const struct roff_node *n, int pardist) static int +pre_abort(DECL_ARGS) +{ + abort(); +} + +static int pre_ign(DECL_ARGS) { diff --git a/man_validate.c b/man_validate.c index fb859562..78a1fcd4 100644 --- a/man_validate.c +++ b/man_validate.c @@ -40,6 +40,7 @@ typedef void (*v_check)(CHKARGS); +static void check_abort(CHKARGS); static void check_par(CHKARGS); static void check_part(CHKARGS); static void check_root(CHKARGS); @@ -60,9 +61,9 @@ static const v_check man_valids[MAN_MAX - MAN_TH] = { NULL, /* SS */ NULL, /* TP */ NULL, /* TQ */ - check_par, /* LP */ + check_abort,/* LP */ check_par, /* PP */ - check_par, /* P */ + check_abort,/* P */ post_IP, /* IP */ NULL, /* HP */ NULL, /* SM */ @@ -97,13 +98,33 @@ static const v_check man_valids[MAN_MAX - MAN_TH] = { }; +/* Validate the subtree rooted at man->last. */ void man_node_validate(struct roff_man *man) { struct roff_node *n; const v_check *cp; + /* + * Translate obsolete macros such that later code + * does not need to look for them. + */ + n = man->last; + switch (n->tok) { + case MAN_LP: + case MAN_P: + n->tok = MAN_PP; + break; + default: + break; + } + + /* + * Iterate over all children, recursing into each one + * in turn, depth-first. + */ + man->last = man->last->child; while (man->last != NULL) { man_node_validate(man); @@ -113,6 +134,8 @@ man_node_validate(struct roff_man *man) man->last = man->last->next; } + /* Finally validate the macro itself. */ + man->last = n; man->next = ROFF_NEXT_SIBLING; switch (n->type) { @@ -183,6 +206,12 @@ check_root(CHKARGS) } static void +check_abort(CHKARGS) +{ + abort(); +} + +static void check_text(CHKARGS) { char *cp, *p; @@ -477,8 +506,6 @@ post_vs(CHKARGS) case MAN_SH: case MAN_SS: case MAN_PP: - case MAN_LP: - case MAN_P: mandoc_vmsg(MANDOCERR_PAR_SKIP, man->parse, n->line, n->pos, "%s after %s", roff_name[n->tok], roff_name[n->parent->tok]); diff --git a/mdoc_html.c b/mdoc_html.c index 073aee35..4b9c7eb0 100644 --- a/mdoc_html.c +++ b/mdoc_html.c @@ -62,6 +62,7 @@ static int mdoc_root_pre(const struct roff_meta *, static void mdoc__x_post(MDOC_ARGS); static int mdoc__x_pre(MDOC_ARGS); +static int mdoc_abort_pre(MDOC_ARGS); static int mdoc_ad_pre(MDOC_ARGS); static int mdoc_an_pre(MDOC_ARGS); static int mdoc_ap_pre(MDOC_ARGS); @@ -154,7 +155,7 @@ static const struct mdoc_html_act mdoc_html_acts[MDOC_MAX - MDOC_Dd] = { {mdoc_nd_pre, NULL}, /* Nd */ {mdoc_nm_pre, NULL}, /* Nm */ {mdoc_quote_pre, mdoc_quote_post}, /* Op */ - {mdoc_ft_pre, NULL}, /* Ot */ + {mdoc_abort_pre, NULL}, /* Ot */ {mdoc_pa_pre, NULL}, /* Pa */ {mdoc_ex_pre, NULL}, /* Rv */ {mdoc_st_pre, NULL}, /* St */ @@ -227,7 +228,7 @@ static const struct mdoc_html_act mdoc_html_acts[MDOC_MAX - MDOC_Dd] = { {mdoc_em_pre, NULL}, /* Fr */ {NULL, NULL}, /* Ud */ {mdoc_lb_pre, NULL}, /* Lb */ - {mdoc_pp_pre, NULL}, /* Lp */ + {mdoc_abort_pre, NULL}, /* Lp */ {mdoc_lk_pre, NULL}, /* Lk */ {mdoc_mt_pre, NULL}, /* Mt */ {mdoc_quote_pre, mdoc_quote_post}, /* Brq */ @@ -968,7 +969,6 @@ mdoc_bd_pre(MDOC_ARGS) case MDOC_Bl: case MDOC_D1: case MDOC_Dl: - case MDOC_Lp: case MDOC_Pp: continue; default: @@ -1808,3 +1808,9 @@ mdoc_eo_post(MDOC_ARGS) else if ( ! tail) h->flags &= ~HTML_NOSPACE; } + +static int +mdoc_abort_pre(MDOC_ARGS) +{ + abort(); +} @@ -75,6 +75,7 @@ static void post_pf(DECL_ARGS); static void post_sect(DECL_ARGS); static void post_vt(DECL_ARGS); static int pre__t(DECL_ARGS); +static int pre_abort(DECL_ARGS); static int pre_an(DECL_ARGS); static int pre_ap(DECL_ARGS); static int pre_aq(DECL_ARGS); @@ -172,7 +173,7 @@ static const struct mdoc_man_act mdoc_man_acts[MDOC_MAX - MDOC_Dd] = { { cond_head, pre_enc, NULL, "\\- ", NULL }, /* Nd */ { NULL, pre_nm, post_nm, NULL, NULL }, /* Nm */ { cond_body, pre_enc, post_enc, "[", "]" }, /* Op */ - { NULL, pre_Ft, post_font, NULL, NULL }, /* Ot */ + { NULL, pre_abort, NULL, NULL, NULL }, /* Ot */ { NULL, pre_em, post_font, NULL, NULL }, /* Pa */ { NULL, pre_ex, NULL, NULL, NULL }, /* Rv */ { NULL, NULL, NULL, NULL, NULL }, /* St */ @@ -245,7 +246,7 @@ static const struct mdoc_man_act mdoc_man_acts[MDOC_MAX - MDOC_Dd] = { { NULL, pre_em, post_font, NULL, NULL }, /* Fr */ { NULL, NULL, NULL, NULL, NULL }, /* Ud */ { NULL, NULL, post_lb, NULL, NULL }, /* Lb */ - { NULL, pre_pp, NULL, NULL, NULL }, /* Lp */ + { NULL, pre_abort, NULL, NULL, NULL }, /* Lp */ { NULL, pre_lk, NULL, NULL, NULL }, /* Lk */ { NULL, pre_em, post_font, NULL, NULL }, /* Mt */ { cond_body, pre_enc, post_enc, "{", "}" }, /* Brq */ @@ -725,6 +726,12 @@ cond_body(DECL_ARGS) } static int +pre_abort(DECL_ARGS) +{ + abort(); +} + +static int pre_enc(DECL_ARGS) { const char *prefix; diff --git a/mdoc_markdown.c b/mdoc_markdown.c index 0cefcfac..b5a856a1 100644 --- a/mdoc_markdown.c +++ b/mdoc_markdown.c @@ -19,6 +19,7 @@ #include <assert.h> #include <ctype.h> #include <stdio.h> +#include <stdlib.h> #include <string.h> #include "mandoc_aux.h" @@ -48,6 +49,7 @@ static void md_uri(const char *); static int md_cond_head(struct roff_node *); static int md_cond_body(struct roff_node *); +static int md_pre_abort(struct roff_node *); static int md_pre_raw(struct roff_node *); static int md_pre_word(struct roff_node *); static int md_pre_skip(struct roff_node *); @@ -138,7 +140,7 @@ static const struct md_act md_acts[MDOC_MAX - MDOC_Dd] = { { md_cond_head, md_pre_Nd, NULL, NULL, NULL }, /* Nd */ { NULL, md_pre_Nm, md_post_Nm, "**", "**" }, /* Nm */ { md_cond_body, md_pre_word, md_post_word, "[", "]" }, /* Op */ - { NULL, md_pre_Fd, md_post_raw, "*", "*" }, /* Ot */ + { NULL, md_pre_abort, NULL, NULL, NULL }, /* Ot */ { NULL, md_pre_raw, md_post_raw, "*", "*" }, /* Pa */ { NULL, NULL, NULL, NULL, NULL }, /* Rv */ { NULL, NULL, NULL, NULL, NULL }, /* St */ @@ -211,7 +213,7 @@ static const struct md_act md_acts[MDOC_MAX - MDOC_Dd] = { { NULL, md_pre_raw, md_post_raw, "*", "*" }, /* Fr */ { NULL, NULL, NULL, NULL, NULL }, /* Ud */ { NULL, NULL, md_post_Lb, NULL, NULL }, /* Lb */ - { NULL, md_pre_Pp, NULL, NULL, NULL }, /* Lp */ + { NULL, md_pre_abort, NULL, NULL, NULL }, /* Lp */ { NULL, md_pre_Lk, NULL, NULL, NULL }, /* Lk */ { NULL, md_pre_Mt, NULL, NULL, NULL }, /* Mt */ { md_cond_body, md_pre_word, md_post_word, "{", "}" }, /* Brq */ @@ -723,6 +725,12 @@ md_cond_body(struct roff_node *n) } static int +md_pre_abort(struct roff_node *n) +{ + abort(); +} + +static int md_pre_raw(struct roff_node *n) { const char *prefix; diff --git a/mdoc_term.c b/mdoc_term.c index 75ffd1d1..c16d5131 100644 --- a/mdoc_term.c +++ b/mdoc_term.c @@ -84,6 +84,7 @@ static void termp_xx_post(DECL_ARGS); static int termp__a_pre(DECL_ARGS); static int termp__t_pre(DECL_ARGS); +static int termp_abort_pre(DECL_ARGS); static int termp_an_pre(DECL_ARGS); static int termp_ap_pre(DECL_ARGS); static int termp_bd_pre(DECL_ARGS); @@ -159,7 +160,7 @@ static const struct mdoc_term_act mdoc_term_acts[MDOC_MAX - MDOC_Dd] = { { termp_nd_pre, NULL }, /* Nd */ { termp_nm_pre, termp_nm_post }, /* Nm */ { termp_quote_pre, termp_quote_post }, /* Op */ - { termp_ft_pre, NULL }, /* Ot */ + { termp_abort_pre, NULL }, /* Ot */ { termp_under_pre, NULL }, /* Pa */ { termp_ex_pre, NULL }, /* Rv */ { NULL, NULL }, /* St */ @@ -232,7 +233,7 @@ static const struct mdoc_term_act mdoc_term_acts[MDOC_MAX - MDOC_Dd] = { { termp_under_pre, NULL }, /* Fr */ { NULL, NULL }, /* Ud */ { NULL, termp_lb_post }, /* Lb */ - { termp_pp_pre, NULL }, /* Lp */ + { termp_abort_pre, NULL }, /* Lp */ { termp_lk_pre, NULL }, /* Lk */ { termp_under_pre, NULL }, /* Mt */ { termp_quote_pre, termp_quote_post }, /* Brq */ @@ -1493,7 +1494,6 @@ termp_bd_pre(DECL_ARGS) case MDOC_Bl: case MDOC_D1: case MDOC_Dl: - case MDOC_Lp: case MDOC_Pp: continue; default: @@ -2098,3 +2098,9 @@ termp_tag_pre(DECL_ARGS) tag_put(n->child->string, 1, p->line); return 1; } + +static int +termp_abort_pre(DECL_ARGS) +{ + abort(); +} diff --git a/mdoc_validate.c b/mdoc_validate.c index 54cf7418..5710e003 100644 --- a/mdoc_validate.c +++ b/mdoc_validate.c @@ -64,6 +64,7 @@ static size_t macro2len(enum roff_tok); 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); @@ -151,7 +152,7 @@ static const v_post mdoc_valids[MDOC_MAX - MDOC_Dd] = { post_nd, /* Nd */ post_nm, /* Nm */ post_delim_nb, /* Op */ - post_obsolete, /* Ot */ + post_abort, /* Ot */ post_defaults, /* Pa */ post_rv, /* Rv */ post_st, /* St */ @@ -224,7 +225,7 @@ static const v_post mdoc_valids[MDOC_MAX - MDOC_Dd] = { post_obsolete, /* Fr */ post_eoln, /* Ud */ post_lb, /* Lb */ - post_par, /* Lp */ + post_abort, /* Lp */ post_delim_nb, /* Lk */ post_defaults, /* Mt */ post_delim_nb, /* Brq */ @@ -285,13 +286,37 @@ static const char * const secnames[SEC__MAX] = { }; +/* 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); @@ -301,6 +326,8 @@ mdoc_node_validate(struct roff_man *mdoc) mdoc->last = mdoc->last->next; } + /* Finally validate the macro itself. */ + mdoc->last = n; mdoc->next = ROFF_NEXT_SIBLING; switch (n->type) { @@ -487,6 +514,12 @@ check_toptext(struct roff_man *mdoc, int ln, int pos, const char *p) } static void +post_abort(POST_ARGS) +{ + abort(); +} + +static void post_delim(POST_ARGS) { const struct roff_node *nch; @@ -1263,9 +1296,7 @@ post_nm(POST_ARGS) 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)) + if (n->last != NULL && n->last->tok == MDOC_Pp) mdoc_node_relink(mdoc, n->last); if (mdoc->meta.name == NULL) @@ -1618,7 +1649,6 @@ post_bl_block(POST_ARGS) while (nc != NULL) { switch (nc->tok) { case MDOC_Pp: - case MDOC_Lp: case ROFF_br: break; default: @@ -2492,7 +2522,7 @@ post_ignpar(POST_ARGS) } if ((np = mdoc->last->child) != NULL) - if (np->tok == MDOC_Pp || np->tok == MDOC_Lp) { + if (np->tok == MDOC_Pp) { mandoc_vmsg(MANDOCERR_PAR_SKIP, mdoc->parse, np->line, np->pos, "%s after %s", roff_name[np->tok], @@ -2501,7 +2531,7 @@ post_ignpar(POST_ARGS) } if ((np = mdoc->last->last) != NULL) - if (np->tok == MDOC_Pp || np->tok == MDOC_Lp) { + 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], @@ -2522,13 +2552,11 @@ post_prevpar(POST_ARGS) return; /* - * Don't allow prior `Lp' or `Pp' prior to a paragraph-type - * block: `Lp', `Pp', or non-compact `Bd' or `Bl'. + * 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 != MDOC_Lp && - n->prev->tok != ROFF_br) + if (n->prev->tok != MDOC_Pp && n->prev->tok != ROFF_br) return; if (n->tok == MDOC_Bl && n->norm->Bl.comp) return; @@ -2566,7 +2594,7 @@ post_par(POST_ARGS) np = mdoc->last->parent; if (np->tok != MDOC_Sh && np->tok != MDOC_Ss) return; - } else if (np->tok != MDOC_Pp && np->tok != MDOC_Lp && + } else if (np->tok != MDOC_Pp && (mdoc->last->tok != ROFF_br || (np->tok != ROFF_sp && np->tok != ROFF_br))) return; diff --git a/regress/man/PP/args.out_lint b/regress/man/PP/args.out_lint index c757d510..e222de8e 100644 --- a/regress/man/PP/args.out_lint +++ b/regress/man/PP/args.out_lint @@ -1,3 +1,3 @@ mandoc: args.in:7:2: ERROR: skipping all arguments: PP arg -mandoc: args.in:9:2: ERROR: skipping all arguments: LP arg1 ... -mandoc: args.in:11:2: ERROR: skipping all arguments: P arg +mandoc: args.in:9:2: ERROR: skipping all arguments: PP arg1 ... +mandoc: args.in:11:2: ERROR: skipping all arguments: PP arg |