summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@cvs.openbsd.org>2018-12-31 04:55:43 +0000
committerIngo Schwarze <schwarze@cvs.openbsd.org>2018-12-31 04:55:43 +0000
commit9dc0cbc9432027eab2d3c04c14013690b258818c (patch)
tree4c751989e920d43325566c37f6a4292d7ecd0f26
parent9eca19b985d2c8f9ff720551709ddebb3287cfba (diff)
Cleanup, minus 15 LOC, no functional change:
Simplify the way the man(7) and mdoc(7) validators are called. Reset the parser state with a common function before calling them. There is no need to again reset the parser state afterwards, the parsers are no longer used after validation. This allows getting rid of man_node_validate() and mdoc_node_validate() as separate functions.
-rw-r--r--usr.bin/mandoc/libman.h3
-rw-r--r--usr.bin/mandoc/libmdoc.h4
-rw-r--r--usr.bin/mandoc/man.c11
-rw-r--r--usr.bin/mandoc/man_macro.c4
-rw-r--r--usr.bin/mandoc/man_validate.c6
-rw-r--r--usr.bin/mandoc/mdoc.c11
-rw-r--r--usr.bin/mandoc/mdoc_macro.c3
-rw-r--r--usr.bin/mandoc/mdoc_state.c10
-rw-r--r--usr.bin/mandoc/mdoc_validate.c6
-rw-r--r--usr.bin/mandoc/read.c3
-rw-r--r--usr.bin/mandoc/roff.c19
-rw-r--r--usr.bin/mandoc/roff_int.h3
12 files changed, 30 insertions, 53 deletions
diff --git a/usr.bin/mandoc/libman.h b/usr.bin/mandoc/libman.h
index 3b6e222c986..21794972124 100644
--- a/usr.bin/mandoc/libman.h
+++ b/usr.bin/mandoc/libman.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: libman.h,v 1.59 2018/12/30 00:48:47 schwarze Exp $ */
+/* $OpenBSD: libman.h,v 1.60 2018/12/31 04:55:42 schwarze Exp $ */
/*
* Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2014, 2015, 2018 Ingo Schwarze <schwarze@openbsd.org>
@@ -39,6 +39,5 @@ struct man_macro {
const struct man_macro *man_macro(enum roff_tok);
void man_descope(struct roff_man *, int, int, char *);
-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 *);
diff --git a/usr.bin/mandoc/libmdoc.h b/usr.bin/mandoc/libmdoc.h
index 0f3a241ae2b..4cdea3160aa 100644
--- a/usr.bin/mandoc/libmdoc.h
+++ b/usr.bin/mandoc/libmdoc.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: libmdoc.h,v 1.87 2018/12/30 00:48:47 schwarze Exp $ */
+/* $OpenBSD: libmdoc.h,v 1.88 2018/12/31 04:55:42 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2013,2014,2015,2017,2018 Ingo Schwarze <schwarze@openbsd.org>
@@ -74,9 +74,7 @@ void mdoc_tail_alloc(struct roff_man *, int, int,
enum roff_tok);
struct roff_node *mdoc_endbody_alloc(struct roff_man *, int, int,
enum roff_tok, struct roff_node *);
-void mdoc_node_validate(struct roff_man *);
void mdoc_state(struct roff_man *, struct roff_node *);
-void mdoc_state_reset(struct roff_man *);
const char *mdoc_a2arch(const char *);
const char *mdoc_a2att(const char *);
enum roff_sec mdoc_a2sec(const char *);
diff --git a/usr.bin/mandoc/man.c b/usr.bin/mandoc/man.c
index 6bed70b9ea3..d04f816fd97 100644
--- a/usr.bin/mandoc/man.c
+++ b/usr.bin/mandoc/man.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: man.c,v 1.130 2018/12/30 00:48:47 schwarze Exp $ */
+/* $OpenBSD: man.c,v 1.131 2018/12/31 04:55:42 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2013,2014,2015,2017,2018 Ingo Schwarze <schwarze@openbsd.org>
@@ -365,12 +365,3 @@ man_state(struct roff_man *man, struct roff_node *n)
}
man->last->flags |= NODE_VALID;
}
-
-void
-man_validate(struct roff_man *man)
-{
-
- man->last = man->meta.first;
- man_node_validate(man);
- man->flags &= ~MAN_LITERAL;
-}
diff --git a/usr.bin/mandoc/man_macro.c b/usr.bin/mandoc/man_macro.c
index 4aa496cf201..5f5a748ef73 100644
--- a/usr.bin/mandoc/man_macro.c
+++ b/usr.bin/mandoc/man_macro.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: man_macro.c,v 1.100 2018/12/30 00:48:47 schwarze Exp $ */
+/* $OpenBSD: man_macro.c,v 1.101 2018/12/31 04:55:42 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2012-2015, 2017, 2018 Ingo Schwarze <schwarze@openbsd.org>
@@ -443,9 +443,7 @@ in_line_eoln(MACRO_PROT_ARGS)
void
man_endparse(struct roff_man *man)
{
-
man_unscope(man, man->meta.first);
- man->flags &= ~MAN_LITERAL;
}
static int
diff --git a/usr.bin/mandoc/man_validate.c b/usr.bin/mandoc/man_validate.c
index 4f176e127fc..bdc2aadd2b7 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.112 2018/12/14 05:17:45 schwarze Exp $ */
+/* $OpenBSD: man_validate.c,v 1.113 2018/12/31 04:55:42 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010, 2012-2018 Ingo Schwarze <schwarze@openbsd.org>
@@ -99,7 +99,7 @@ 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)
+man_validate(struct roff_man *man)
{
struct roff_node *n;
const v_check *cp;
@@ -126,7 +126,7 @@ man_node_validate(struct roff_man *man)
man->last = man->last->child;
while (man->last != NULL) {
- man_node_validate(man);
+ man_validate(man);
if (man->last == n)
man->last = man->last->child;
else
diff --git a/usr.bin/mandoc/mdoc.c b/usr.bin/mandoc/mdoc.c
index 2764dc04614..1ecb0773e07 100644
--- a/usr.bin/mandoc/mdoc.c
+++ b/usr.bin/mandoc/mdoc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mdoc.c,v 1.161 2018/12/30 00:48:47 schwarze Exp $ */
+/* $OpenBSD: mdoc.c,v 1.162 2018/12/31 04:55:42 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010, 2012-2018 Ingo Schwarze <schwarze@openbsd.org>
@@ -426,12 +426,3 @@ mdoc_isdelim(const char *p)
return DELIM_NONE;
}
-
-void
-mdoc_validate(struct roff_man *mdoc)
-{
-
- mdoc->last = mdoc->meta.first;
- mdoc_node_validate(mdoc);
- mdoc_state_reset(mdoc);
-}
diff --git a/usr.bin/mandoc/mdoc_macro.c b/usr.bin/mandoc/mdoc_macro.c
index 5b946635872..e47a590b1d8 100644
--- a/usr.bin/mandoc/mdoc_macro.c
+++ b/usr.bin/mandoc/mdoc_macro.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mdoc_macro.c,v 1.186 2018/12/30 00:48:48 schwarze Exp $ */
+/* $OpenBSD: mdoc_macro.c,v 1.187 2018/12/31 04:55:42 schwarze Exp $ */
/*
* Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010, 2012-2018 Ingo Schwarze <schwarze@openbsd.org>
@@ -232,7 +232,6 @@ mdoc_endparse(struct roff_man *mdoc)
/* Rewind to the first. */
rew_last(mdoc, mdoc->meta.first);
- mdoc_state_reset(mdoc);
}
/*
diff --git a/usr.bin/mandoc/mdoc_state.c b/usr.bin/mandoc/mdoc_state.c
index 6deb3d4e7bc..34718dcc8c1 100644
--- a/usr.bin/mandoc/mdoc_state.c
+++ b/usr.bin/mandoc/mdoc_state.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mdoc_state.c,v 1.12 2018/12/30 00:48:48 schwarze Exp $ */
+/* $OpenBSD: mdoc_state.c,v 1.13 2018/12/31 04:55:42 schwarze Exp $ */
/*
* Copyright (c) 2014, 2015, 2017, 2018 Ingo Schwarze <schwarze@openbsd.org>
*
@@ -179,14 +179,6 @@ mdoc_state(struct roff_man *mdoc, struct roff_node *n)
(*handler)(mdoc, n);
}
-void
-mdoc_state_reset(struct roff_man *mdoc)
-{
-
- roff_setreg(mdoc->roff, "nS", 0, '=');
- mdoc->flags = 0;
-}
-
static void
state_bd(STATE_ARGS)
{
diff --git a/usr.bin/mandoc/mdoc_validate.c b/usr.bin/mandoc/mdoc_validate.c
index 8a76a27f74b..8ac38a2a6a8 100644
--- a/usr.bin/mandoc/mdoc_validate.c
+++ b/usr.bin/mandoc/mdoc_validate.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mdoc_validate.c,v 1.281 2018/12/30 00:48:48 schwarze Exp $ */
+/* $OpenBSD: mdoc_validate.c,v 1.282 2018/12/31 04:55:42 schwarze Exp $ */
/*
* Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010-2018 Ingo Schwarze <schwarze@openbsd.org>
@@ -286,7 +286,7 @@ static const char * const secnames[SEC__MAX] = {
/* Validate the subtree rooted at mdoc->last. */
void
-mdoc_node_validate(struct roff_man *mdoc)
+mdoc_validate(struct roff_man *mdoc)
{
struct roff_node *n, *np;
const v_post *p;
@@ -317,7 +317,7 @@ mdoc_node_validate(struct roff_man *mdoc)
mdoc->last = mdoc->last->child;
while (mdoc->last != NULL) {
- mdoc_node_validate(mdoc);
+ mdoc_validate(mdoc);
if (mdoc->last == n)
mdoc->last = mdoc->last->child;
else
diff --git a/usr.bin/mandoc/read.c b/usr.bin/mandoc/read.c
index f9c7996e358..5a244596588 100644
--- a/usr.bin/mandoc/read.c
+++ b/usr.bin/mandoc/read.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: read.c,v 1.180 2018/12/30 00:48:48 schwarze Exp $ */
+/* $OpenBSD: read.c,v 1.181 2018/12/31 04:55:42 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010-2018 Ingo Schwarze <schwarze@openbsd.org>
@@ -686,6 +686,7 @@ mparse_free(struct mparse *curp)
struct roff_meta *
mparse_result(struct mparse *curp)
{
+ roff_state_reset(curp->man);
if (curp->options & MPARSE_VALIDATE) {
if (curp->man->meta.macroset == MACROSET_MDOC)
mdoc_validate(curp->man);
diff --git a/usr.bin/mandoc/roff.c b/usr.bin/mandoc/roff.c
index 419fd3db0d6..ab9de5dd6d5 100644
--- a/usr.bin/mandoc/roff.c
+++ b/usr.bin/mandoc/roff.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: roff.c,v 1.228 2018/12/30 00:48:48 schwarze Exp $ */
+/* $OpenBSD: roff.c,v 1.229 2018/12/31 04:55:42 schwarze Exp $ */
/*
* Copyright (c) 2008-2012, 2014 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010-2015, 2017, 2018 Ingo Schwarze <schwarze@openbsd.org>
@@ -817,18 +817,25 @@ roff_man_free1(struct roff_man *man)
free(man->meta.sodest);
}
+void
+roff_state_reset(struct roff_man *man)
+{
+ man->last = man->meta.first;
+ man->last_es = NULL;
+ man->flags = 0;
+ man->lastsec = man->lastnamed = SEC_NONE;
+ man->next = ROFF_NEXT_CHILD;
+ roff_setreg(man->roff, "nS", 0, '=');
+}
+
static void
roff_man_alloc1(struct roff_man *man)
{
memset(&man->meta, 0, sizeof(man->meta));
man->meta.first = mandoc_calloc(1, sizeof(*man->meta.first));
man->meta.first->type = ROFFT_ROOT;
- man->last = man->meta.first;
- man->last_es = NULL;
- man->flags = 0;
man->meta.macroset = MACROSET_NONE;
- man->lastsec = man->lastnamed = SEC_NONE;
- man->next = ROFF_NEXT_CHILD;
+ roff_state_reset(man);
}
void
diff --git a/usr.bin/mandoc/roff_int.h b/usr.bin/mandoc/roff_int.h
index c3928e30452..f464520f1fc 100644
--- a/usr.bin/mandoc/roff_int.h
+++ b/usr.bin/mandoc/roff_int.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: roff_int.h,v 1.12 2018/12/30 00:48:48 schwarze Exp $ */
+/* $OpenBSD: roff_int.h,v 1.13 2018/12/31 04:55:42 schwarze Exp $ */
/*
* Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2013,2014,2015,2017,2018 Ingo Schwarze <schwarze@openbsd.org>
@@ -80,6 +80,7 @@ struct ohash *roffhash_alloc(enum roff_tok, enum roff_tok);
enum roff_tok roffhash_find(struct ohash *, const char *, size_t);
void roffhash_free(struct ohash *);
+void roff_state_reset(struct roff_man *);
void roff_validate(struct roff_man *);
/*