* mandoc: Cleanup, minus 15 LOC, no functional change: Simplify the way
@ 2018-12-31 4:56 schwarze
0 siblings, 0 replies; only message in thread
From: schwarze @ 2018-12-31 4:56 UTC (permalink / raw)
To: source
Log Message:
-----------
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.
Modified Files:
--------------
mandoc:
libman.h
libmdoc.h
man.c
man_macro.c
man_validate.c
mdoc.c
mdoc_macro.c
mdoc_state.c
mdoc_validate.c
read.c
roff.c
roff_int.h
Revision Data
-------------
Index: roff_int.h
===================================================================
RCS file: /home/cvs/mandoc/mandoc/roff_int.h,v
retrieving revision 1.12
retrieving revision 1.13
diff -Lroff_int.h -Lroff_int.h -u -p -r1.12 -r1.13
--- roff_int.h
+++ roff_int.h
@@ -80,6 +80,7 @@ struct ohash *roffhash_alloc(enum roff_
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 *);
/*
Index: mdoc_macro.c
===================================================================
RCS file: /home/cvs/mandoc/mandoc/mdoc_macro.c,v
retrieving revision 1.229
retrieving revision 1.230
diff -Lmdoc_macro.c -Lmdoc_macro.c -u -p -r1.229 -r1.230
--- mdoc_macro.c
+++ mdoc_macro.c
@@ -234,7 +234,6 @@ mdoc_endparse(struct roff_man *mdoc)
/* Rewind to the first. */
rew_last(mdoc, mdoc->meta.first);
- mdoc_state_reset(mdoc);
}
/*
Index: man_validate.c
===================================================================
RCS file: /home/cvs/mandoc/mandoc/man_validate.c,v
retrieving revision 1.142
retrieving revision 1.143
diff -Lman_validate.c -Lman_validate.c -u -p -r1.142 -r1.143
--- man_validate.c
+++ man_validate.c
@@ -101,7 +101,7 @@ static const v_check man_valids[MAN_MAX
/* 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;
@@ -128,7 +128,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
Index: man.c
===================================================================
RCS file: /home/cvs/mandoc/mandoc/man.c,v
retrieving revision 1.182
retrieving revision 1.183
diff -Lman.c -Lman.c -u -p -r1.182 -r1.183
--- man.c
+++ man.c
@@ -367,12 +367,3 @@ man_state(struct roff_man *man, struct r
}
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;
-}
Index: roff.c
===================================================================
RCS file: /home/cvs/mandoc/mandoc/roff.c,v
retrieving revision 1.356
retrieving revision 1.357
diff -Lroff.c -Lroff.c -u -p -r1.356 -r1.357
--- roff.c
+++ roff.c
@@ -819,18 +819,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
Index: man_macro.c
===================================================================
RCS file: /home/cvs/mandoc/mandoc/man_macro.c,v
retrieving revision 1.138
retrieving revision 1.139
diff -Lman_macro.c -Lman_macro.c -u -p -r1.138 -r1.139
--- man_macro.c
+++ man_macro.c
@@ -445,9 +445,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
Index: libmdoc.h
===================================================================
RCS file: /home/cvs/mandoc/mandoc/libmdoc.h,v
retrieving revision 1.116
retrieving revision 1.117
diff -Llibmdoc.h -Llibmdoc.h -u -p -r1.116 -r1.117
--- libmdoc.h
+++ libmdoc.h
@@ -74,9 +74,7 @@ void mdoc_tail_alloc(struct roff_man
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 *);
const char *mdoc_a2lib(const char *);
Index: mdoc_state.c
===================================================================
RCS file: /home/cvs/mandoc/mandoc/mdoc_state.c,v
retrieving revision 1.12
retrieving revision 1.13
diff -Lmdoc_state.c -Lmdoc_state.c -u -p -r1.12 -r1.13
--- mdoc_state.c
+++ mdoc_state.c
@@ -179,14 +179,6 @@ mdoc_state(struct roff_man *mdoc, struct
(*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)
{
Index: read.c
===================================================================
RCS file: /home/cvs/mandoc/mandoc/read.c,v
retrieving revision 1.209
retrieving revision 1.210
diff -Lread.c -Lread.c -u -p -r1.209 -r1.210
--- read.c
+++ read.c
@@ -688,6 +688,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);
Index: libman.h
===================================================================
RCS file: /home/cvs/mandoc/mandoc/libman.h,v
retrieving revision 1.84
retrieving revision 1.85
diff -Llibman.h -Llibman.h -u -p -r1.84 -r1.85
--- libman.h
+++ libman.h
@@ -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 *);
Index: mdoc.c
===================================================================
RCS file: /home/cvs/mandoc/mandoc/mdoc.c,v
retrieving revision 1.272
retrieving revision 1.273
diff -Lmdoc.c -Lmdoc.c -u -p -r1.272 -r1.273
--- mdoc.c
+++ mdoc.c
@@ -428,12 +428,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);
-}
Index: mdoc_validate.c
===================================================================
RCS file: /home/cvs/mandoc/mandoc/mdoc_validate.c,v
retrieving revision 1.366
retrieving revision 1.367
diff -Lmdoc_validate.c -Lmdoc_validate.c -u -p -r1.366 -r1.367
--- mdoc_validate.c
+++ mdoc_validate.c
@@ -288,7 +288,7 @@ static const char * const secnames[SEC__
/* 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;
@@ -319,7 +319,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
--
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-31 4:56 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-12-31 4:56 mandoc: Cleanup, minus 15 LOC, no functional change: Simplify the way 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).