From e66bc70731870e9afaa3b406e8e49e65b95bfb57 Mon Sep 17 00:00:00 2001 From: Ingo Schwarze Date: Thu, 22 Oct 2015 21:54:23 +0000 Subject: move man(7) validation into the dedicated validation phase, too --- libman.h | 5 +++-- main.c | 3 ++- man.c | 37 ++++++++++++++++++++++++++++++++++++- man.h | 5 +++-- man_macro.c | 24 +++++------------------- man_validate.c | 49 +++++++++++++++++-------------------------------- roff.c | 6 +++--- roff_int.h | 3 +-- 8 files changed, 70 insertions(+), 62 deletions(-) diff --git a/libman.h b/libman.h index e3f0d9db..90c9803a 100644 --- a/libman.h +++ b/libman.h @@ -1,4 +1,4 @@ -/* $Id: libman.h,v 1.77 2015/04/23 15:35:59 schwarze Exp $ */ +/* $Id: libman.h,v 1.78 2015/10/22 21:54:23 schwarze Exp $ */ /* * Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons * Copyright (c) 2014, 2015 Ingo Schwarze @@ -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 b03ba073..31dc9994 100644 --- a/main.c +++ b/main.c @@ -1,4 +1,4 @@ -/* $Id: main.c,v 1.252 2015/10/22 21:03:43 schwarze Exp $ */ +/* $Id: main.c,v 1.253 2015/10/22 21:54:23 schwarze Exp $ */ /* * Copyright (c) 2008-2012 Kristaps Dzonsons * Copyright (c) 2010-2012, 2014, 2015 Ingo Schwarze @@ -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 d2c27bfa..31c094e8 100644 --- a/man.c +++ b/man.c @@ -1,4 +1,4 @@ -/* $Id: man.c,v 1.165 2015/10/06 18:32:19 schwarze Exp $ */ +/* $Id: man.c,v 1.166 2015/10/22 21:54:23 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons * Copyright (c) 2013, 2014, 2015 Ingo Schwarze @@ -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 249fbf94..5a8d2593 100644 --- a/man.h +++ b/man.h @@ -1,4 +1,4 @@ -/* $Id: man.h,v 1.75 2015/04/23 16:17:44 schwarze Exp $ */ +/* $Id: man.h,v 1.76 2015/10/22 21:54:23 schwarze Exp $ */ /* * Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons * Copyright (c) 2014, 2015 Ingo Schwarze @@ -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 06415308..52073410 100644 --- a/man_macro.c +++ b/man_macro.c @@ -1,4 +1,4 @@ -/* $Id: man_macro.c,v 1.112 2015/10/06 18:32:19 schwarze Exp $ */ +/* $Id: man_macro.c,v 1.113 2015/10/22 21:54:23 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons * Copyright (c) 2012, 2013, 2014, 2015 Ingo Schwarze @@ -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; } } @@ -385,28 +392,6 @@ post_TH(CHKARGS) roff_node_delete(man, man->last); } -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) { diff --git a/roff.c b/roff.c index 59207bdf..4ee44f15 100644 --- a/roff.c +++ b/roff.c @@ -1,4 +1,4 @@ -/* $Id: roff.c,v 1.282 2015/10/21 23:51:11 schwarze Exp $ */ +/* $Id: roff.c,v 1.283 2015/10/22 21:54:23 schwarze Exp $ */ /* * Copyright (c) 2008-2012, 2014 Kristaps Dzonsons * Copyright (c) 2010-2015 Ingo Schwarze @@ -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 2d82be9f..8c9cc097 100644 --- a/roff_int.h +++ b/roff_int.h @@ -1,4 +1,4 @@ -/* $Id: roff_int.h,v 1.5 2015/10/21 23:51:11 schwarze Exp $ */ +/* $Id: roff_int.h,v 1.6 2015/10/22 21:54:23 schwarze Exp $ */ /* * Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons * Copyright (c) 2013, 2014, 2015 Ingo Schwarze @@ -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 -- cgit v1.2.3