aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/man_validate.c
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@openbsd.org>2018-12-03 21:00:10 +0000
committerIngo Schwarze <schwarze@openbsd.org>2018-12-03 21:00:10 +0000
commit820b4d56427ff6a0f1e3399ac7e4aea447dd5c20 (patch)
tree021019d37963c18cc8553ccaff918c1f9ea1441f /man_validate.c
parent17e67c5cb10de07302a0f0ad1a0da7af23788f98 (diff)
downloadmandoc-820b4d56427ff6a0f1e3399ac7e4aea447dd5c20.tar.gz
mandoc-820b4d56427ff6a0f1e3399ac7e4aea447dd5c20.tar.zst
mandoc-820b4d56427ff6a0f1e3399ac7e4aea447dd5c20.zip
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.
Diffstat (limited to 'man_validate.c')
-rw-r--r--man_validate.c35
1 files changed, 31 insertions, 4 deletions
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]);