summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@openbsd.org>2015-10-22 21:54:23 +0000
committerIngo Schwarze <schwarze@openbsd.org>2015-10-22 21:54:23 +0000
commit54ffa6b6bcb97f97cc0a3604078eb63aa8c759ef (patch)
treedc900d7df0c1cae2b95adfcc260ada272f57839b
parent9953b888e25942fa632d3e754daa293a4239d4c5 (diff)
downloadmandoc-54ffa6b6bcb97f97cc0a3604078eb63aa8c759ef.tar.gz
move man(7) validation into the dedicated validation phase, too
-rw-r--r--libman.h3
-rw-r--r--main.c1
-rw-r--r--man.c35
-rw-r--r--man.h3
-rw-r--r--man_macro.c22
-rw-r--r--man_validate.c49
-rw-r--r--roff.c4
-rw-r--r--roff_int.h1
8 files changed, 63 insertions, 55 deletions
diff --git a/libman.h b/libman.h
index 3ad58d19..a83ebd02 100644
--- a/libman.h
+++ b/libman.h
@@ -37,7 +37,8 @@ extern const struct man_macro *const man_macros;
__BEGIN_DECLS
int man_hash_find(const char *);
-void man_valid_post(struct roff_man *);
+void man_node_validate(struct roff_man *);
+void man_state(struct roff_man *, struct roff_node *);
void man_unscope(struct roff_man *, const struct roff_node *);
__END_DECLS
diff --git a/main.c b/main.c
index 8ba7da50..7a720758 100644
--- a/main.c
+++ b/main.c
@@ -721,6 +721,7 @@ parse(struct curparse *curp, int fd, const char *file)
}
}
if (man->macroset == MACROSET_MAN) {
+ man_validate(man);
switch (curp->outtype) {
case OUTT_HTML:
html_man(curp->outdata, man);
diff --git a/man.c b/man.c
index 88a4c24b..f484725a 100644
--- a/man.c
+++ b/man.c
@@ -332,3 +332,38 @@ man_mparse(const struct roff_man *man)
assert(man && man->parse);
return man->parse;
}
+
+void
+man_state(struct roff_man *man, struct roff_node *n)
+{
+
+ switch(n->tok) {
+ case MAN_nf:
+ case MAN_EX:
+ if (man->flags & MAN_LITERAL && ! (n->flags & MAN_VALID))
+ mandoc_msg(MANDOCERR_NF_SKIP, man->parse,
+ n->line, n->pos, "nf");
+ man->flags |= MAN_LITERAL;
+ break;
+ case MAN_fi:
+ case MAN_EE:
+ if ( ! (man->flags & MAN_LITERAL) &&
+ ! (n->flags & MAN_VALID))
+ mandoc_msg(MANDOCERR_FI_SKIP, man->parse,
+ n->line, n->pos, "fi");
+ man->flags &= ~MAN_LITERAL;
+ break;
+ default:
+ break;
+ }
+ man->last->flags |= MAN_VALID;
+}
+
+void
+man_validate(struct roff_man *man)
+{
+
+ man->last = man->first;
+ man_node_validate(man);
+ man->flags &= ~MAN_LITERAL;
+}
diff --git a/man.h b/man.h
index 8d2fdea9..bc8cdbd8 100644
--- a/man.h
+++ b/man.h
@@ -63,6 +63,7 @@ __BEGIN_DECLS
struct roff_man;
-const struct mparse *man_mparse(const struct roff_man *);
+const struct mparse *man_mparse(const struct roff_man *);
+void man_validate(struct roff_man *);
__END_DECLS
diff --git a/man_macro.c b/man_macro.c
index aa0ba895..4b124363 100644
--- a/man_macro.c
+++ b/man_macro.c
@@ -130,7 +130,7 @@ man_unscope(struct roff_man *man, const struct roff_node *to)
man->last = n;
n = n->parent;
- man_valid_post(man);
+ man->last->flags |= MAN_VALID;
}
/*
@@ -379,28 +379,13 @@ in_line_eoln(MACRO_PROT_ARGS)
assert(man->last->type != ROFFT_ROOT);
man->next = ROFF_NEXT_SIBLING;
- /*
- * Rewind our element scope. Note that when TH is pruned, we'll
- * be back at the root, so make sure that we don't clobber as
- * its sibling.
- */
+ /* Rewind our element scope. */
for ( ; man->last; man->last = man->last->parent) {
+ man_state(man, man->last);
if (man->last == n)
break;
- if (man->last->type == ROFFT_ROOT)
- break;
- man_valid_post(man);
}
-
- assert(man->last);
-
- /*
- * Same here regarding whether we're back at the root.
- */
-
- if (man->last->type != ROFFT_ROOT)
- man_valid_post(man);
}
void
@@ -408,6 +393,7 @@ man_endparse(struct roff_man *man)
{
man_unscope(man, man->first);
+ man->flags &= ~MAN_LITERAL;
}
static int
diff --git a/man_validate.c b/man_validate.c
index 490c68e6..ad8206b6 100644
--- a/man_validate.c
+++ b/man_validate.c
@@ -48,9 +48,7 @@ static void check_text(CHKARGS);
static void post_AT(CHKARGS);
static void post_IP(CHKARGS);
static void post_vs(CHKARGS);
-static void post_fi(CHKARGS);
static void post_ft(CHKARGS);
-static void post_nf(CHKARGS);
static void post_OP(CHKARGS);
static void post_TH(CHKARGS);
static void post_UC(CHKARGS);
@@ -79,8 +77,8 @@ static v_check man_valids[MAN_MAX] = {
NULL, /* IR */
NULL, /* RI */
post_vs, /* sp */
- post_nf, /* nf */
- post_fi, /* fi */
+ NULL, /* nf */
+ NULL, /* fi */
NULL, /* RE */
check_part, /* RS */
NULL, /* DT */
@@ -90,8 +88,8 @@ static v_check man_valids[MAN_MAX] = {
NULL, /* in */
post_ft, /* ft */
post_OP, /* OP */
- post_nf, /* EX */
- post_fi, /* EE */
+ NULL, /* EX */
+ NULL, /* EE */
post_UR, /* UR */
NULL, /* UE */
NULL, /* ll */
@@ -99,16 +97,23 @@ static v_check man_valids[MAN_MAX] = {
void
-man_valid_post(struct roff_man *man)
+man_node_validate(struct roff_man *man)
{
struct roff_node *n;
v_check *cp;
n = man->last;
- if (n->flags & MAN_VALID)
- return;
- n->flags |= MAN_VALID;
+ man->last = man->last->child;
+ while (man->last != NULL) {
+ man_node_validate(man);
+ if (man->last == n)
+ man->last = man->last->child;
+ else
+ man->last = man->last->next;
+ }
+ man->last = n;
+ man->next = ROFF_NEXT_SIBLING;
switch (n->type) {
case ROFFT_TEXT:
check_text(man, n);
@@ -123,6 +128,8 @@ man_valid_post(struct roff_man *man)
cp = man_valids + n->tok;
if (*cp)
(*cp)(man, n);
+ if (man->last == n)
+ man_state(man, n);
break;
}
}
@@ -386,28 +393,6 @@ post_TH(CHKARGS)
}
static void
-post_nf(CHKARGS)
-{
-
- if (man->flags & MAN_LITERAL)
- mandoc_msg(MANDOCERR_NF_SKIP, man->parse,
- n->line, n->pos, "nf");
-
- man->flags |= MAN_LITERAL;
-}
-
-static void
-post_fi(CHKARGS)
-{
-
- if ( ! (MAN_LITERAL & man->flags))
- mandoc_msg(MANDOCERR_FI_SKIP, man->parse,
- n->line, n->pos, "fi");
-
- man->flags &= ~MAN_LITERAL;
-}
-
-static void
post_UC(CHKARGS)
{
static const char * const bsd_versions[] = {
diff --git a/roff.c b/roff.c
index 537297ad..679b64b2 100644
--- a/roff.c
+++ b/roff.c
@@ -1063,7 +1063,7 @@ roff_word_alloc(struct roff_man *man, int line, int pos, const char *word)
if (man->macroset == MACROSET_MDOC)
n->flags |= MDOC_VALID | MDOC_ENDED;
else
- man_valid_post(man);
+ n->flags |= MAN_VALID;
man->next = ROFF_NEXT_SIBLING;
}
@@ -1151,7 +1151,7 @@ roff_addtbl(struct roff_man *man, const struct tbl_span *tbl)
if (man->macroset == MACROSET_MDOC)
n->flags |= MDOC_VALID | MDOC_ENDED;
else
- man_valid_post(man);
+ n->flags |= MAN_VALID;
man->next = ROFF_NEXT_SIBLING;
}
diff --git a/roff_int.h b/roff_int.h
index 001223a6..21954e41 100644
--- a/roff_int.h
+++ b/roff_int.h
@@ -40,7 +40,6 @@ void roff_node_delete(struct roff_man *, struct roff_node *);
*/
void man_breakscope(struct roff_man *, int);
-void man_valid_post(struct roff_man *);
void mdoc_argv_free(struct mdoc_arg *);
__END_DECLS