* mandoc: In the validators, translate obsolete macro aliases (Lp, Ot, LP,
@ 2018-12-03 21:00 schwarze
0 siblings, 0 replies; only message in thread
From: schwarze @ 2018-12-03 21:00 UTC (permalink / raw)
To: source
Log Message:
-----------
In the validators, translate obsolete macro aliases (Lp, Ot, LP, P)
to the standard forms (Pp, Ft, PP) up front, such that later code
does not need to look for the obsolete versions.
This reduces the risk of incomplete handling.
Modified Files:
--------------
mandoc:
man_html.c
man_term.c
man_validate.c
mdoc_html.c
mdoc_man.c
mdoc_markdown.c
mdoc_term.c
mdoc_validate.c
mandoc/regress/man/PP:
args.out_lint
Revision Data
-------------
Index: mdoc_markdown.c
===================================================================
RCS file: /home/cvs/mandoc/mandoc/mdoc_markdown.c,v
retrieving revision 1.27
retrieving revision 1.28
diff -Lmdoc_markdown.c -Lmdoc_markdown.c -u -p -r1.27 -r1.28
--- mdoc_markdown.c
+++ 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_
{ 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_
{ 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 */
@@ -720,6 +722,12 @@ static int
md_cond_body(struct roff_node *n)
{
return n->type == ROFFT_BODY;
+}
+
+static int
+md_pre_abort(struct roff_node *n)
+{
+ abort();
}
static int
Index: man_html.c
===================================================================
RCS file: /home/cvs/mandoc/mandoc/man_html.c,v
retrieving revision 1.157
retrieving revision 1.158
diff -Lman_html.c -Lman_html.c -u -p -r1.157 -r1.158
--- man_html.c
+++ man_html.c
@@ -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_htm
{ 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;
@@ -671,4 +670,10 @@ man_UR_pre(MAN_ARGS)
print_man_nodelist(man, n->child, h);
return 0;
+}
+
+static int
+man_abort_pre(MAN_ARGS)
+{
+ abort();
}
Index: mdoc_man.c
===================================================================
RCS file: /home/cvs/mandoc/mandoc/mdoc_man.c,v
retrieving revision 1.128
retrieving revision 1.129
diff -Lmdoc_man.c -Lmdoc_man.c -u -p -r1.128 -r1.129
--- mdoc_man.c
+++ mdoc_man.c
@@ -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_ma
{ 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_ma
{ 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 */
@@ -722,6 +723,12 @@ cond_body(DECL_ARGS)
{
return n->type == ROFFT_BODY;
+}
+
+static int
+pre_abort(DECL_ARGS)
+{
+ abort();
}
static int
Index: mdoc_html.c
===================================================================
RCS file: /home/cvs/mandoc/mandoc/mdoc_html.c,v
retrieving revision 1.315
retrieving revision 1.316
diff -Lmdoc_html.c -Lmdoc_html.c -u -p -r1.315 -r1.316
--- mdoc_html.c
+++ mdoc_html.c
@@ -62,6 +62,7 @@ static int mdoc_root_pre(const struct
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_h
{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_h
{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:
@@ -1807,4 +1807,10 @@ mdoc_eo_post(MDOC_ARGS)
h->flags |= HTML_NOSPACE;
else if ( ! tail)
h->flags &= ~HTML_NOSPACE;
+}
+
+static int
+mdoc_abort_pre(MDOC_ARGS)
+{
+ abort();
}
Index: mdoc_term.c
===================================================================
RCS file: /home/cvs/mandoc/mandoc/mdoc_term.c,v
retrieving revision 1.368
retrieving revision 1.369
diff -Lmdoc_term.c -Lmdoc_term.c -u -p -r1.368 -r1.369
--- mdoc_term.c
+++ 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_t
{ 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_t
{ 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:
@@ -2097,4 +2097,10 @@ termp_tag_pre(DECL_ARGS)
n->parent->parent->parent->tok == MDOC_It)))
tag_put(n->child->string, 1, p->line);
return 1;
+}
+
+static int
+termp_abort_pre(DECL_ARGS)
+{
+ abort();
}
Index: mdoc_validate.c
===================================================================
RCS file: /home/cvs/mandoc/mandoc/mdoc_validate.c,v
retrieving revision 1.362
retrieving revision 1.363
diff -Lmdoc_validate.c -Lmdoc_validate.c -u -p -r1.362 -r1.363
--- mdoc_validate.c
+++ 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
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
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__
};
+/* 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
}
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;
Index: man_term.c
===================================================================
RCS file: /home/cvs/mandoc/mandoc/man_term.c,v
retrieving revision 1.220
retrieving revision 1.221
diff -Lman_term.c -Lman_term.c -u -p -r1.220 -r1.221
--- man_term.c
+++ man_term.c
@@ -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_ter
{ 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 */
@@ -220,6 +221,12 @@ print_bvspace(struct termp *p, const str
term_vspace(p);
}
+
+static int
+pre_abort(DECL_ARGS)
+{
+ abort();
+}
static int
pre_ign(DECL_ARGS)
Index: man_validate.c
===================================================================
RCS file: /home/cvs/mandoc/mandoc/man_validate.c,v
retrieving revision 1.137
retrieving revision 1.138
diff -Lman_validate.c -Lman_validate.c -u -p -r1.137 -r1.138
--- man_validate.c
+++ 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
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
};
+/* 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]);
Index: args.out_lint
===================================================================
RCS file: /home/cvs/mandoc/mandoc/regress/man/PP/args.out_lint,v
retrieving revision 1.4
retrieving revision 1.5
diff -Lregress/man/PP/args.out_lint -Lregress/man/PP/args.out_lint -u -p -r1.4 -r1.5
--- regress/man/PP/args.out_lint
+++ 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
--
To unsubscribe send an email to source+unsubscribe@mandoc.bsd.lv
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2018-12-03 21:00 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-12-03 21:00 mandoc: In the validators, translate obsolete macro aliases (Lp, Ot, LP, schwarze
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).