summaryrefslogtreecommitdiffstats
path: root/usr.bin/mandoc/man_validate.c
diff options
context:
space:
mode:
authorschwarze <schwarze@openbsd.org>2018-12-03 21:00:06 +0000
committerschwarze <schwarze@openbsd.org>2018-12-03 21:00:06 +0000
commit7c539ecbb26b558e22990951d3f92863abc47ab8 (patch)
tree58fef690d527c725a0a7aa05b8d2709a138e9868 /usr.bin/mandoc/man_validate.c
parentadapt to the change in mansearch.c rev. 1.62; (diff)
downloadwireguard-openbsd-7c539ecbb26b558e22990951d3f92863abc47ab8.tar.xz
wireguard-openbsd-7c539ecbb26b558e22990951d3f92863abc47ab8.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 'usr.bin/mandoc/man_validate.c')
-rw-r--r--usr.bin/mandoc/man_validate.c37
1 files changed, 32 insertions, 5 deletions
diff --git a/usr.bin/mandoc/man_validate.c b/usr.bin/mandoc/man_validate.c
index c0d1a6f9a65..7fa99bcced2 100644
--- a/usr.bin/mandoc/man_validate.c
+++ b/usr.bin/mandoc/man_validate.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: man_validate.c,v 1.108 2018/08/18 02:03:41 schwarze Exp $ */
+/* $OpenBSD: man_validate.c,v 1.109 2018/12/03 21:00:06 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010, 2012-2018 Ingo Schwarze <schwarze@openbsd.org>
@@ -38,6 +38,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);
@@ -58,9 +59,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 */
@@ -95,13 +96,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);
@@ -111,6 +132,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) {
@@ -181,6 +204,12 @@ check_root(CHKARGS)
}
static void
+check_abort(CHKARGS)
+{
+ abort();
+}
+
+static void
check_text(CHKARGS)
{
char *cp, *p;
@@ -475,8 +504,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]);