From: schwarze Date: Thu, 22 Oct 2015 21:53:49 +0000 (+0000) Subject: move man(7) validation into the dedicated validation phase, too X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=b3cd4c9a6cb6d4dc6ca87606113161e83f49b53a;p=openbsd move man(7) validation into the dedicated validation phase, too --- diff --git a/usr.bin/mandoc/libman.h b/usr.bin/mandoc/libman.h index 1cd48caa504..da407d98bf8 100644 --- a/usr.bin/mandoc/libman.h +++ b/usr.bin/mandoc/libman.h @@ -1,4 +1,4 @@ -/* $OpenBSD: libman.h,v 1.52 2015/04/23 15:35:39 schwarze Exp $ */ +/* $OpenBSD: libman.h,v 1.53 2015/10/22 21:53:49 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/usr.bin/mandoc/main.c b/usr.bin/mandoc/main.c index a3ff21274cd..ed3e92c79bd 100644 --- a/usr.bin/mandoc/main.c +++ b/usr.bin/mandoc/main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: main.c,v 1.160 2015/10/22 21:02:55 schwarze Exp $ */ +/* $OpenBSD: main.c,v 1.161 2015/10/22 21:53:49 schwarze Exp $ */ /* * Copyright (c) 2008-2012 Kristaps Dzonsons * Copyright (c) 2010-2012, 2014, 2015 Ingo Schwarze @@ -697,6 +697,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/usr.bin/mandoc/man.c b/usr.bin/mandoc/man.c index d0f023136f9..c8c968bfe26 100644 --- a/usr.bin/mandoc/man.c +++ b/usr.bin/mandoc/man.c @@ -1,4 +1,4 @@ -/* $OpenBSD: man.c,v 1.113 2015/10/06 18:30:43 schwarze Exp $ */ +/* $OpenBSD: man.c,v 1.114 2015/10/22 21:53:49 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons * Copyright (c) 2013, 2014, 2015 Ingo Schwarze @@ -330,3 +330,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/usr.bin/mandoc/man.h b/usr.bin/mandoc/man.h index cbd15b0c8df..f3c8d3b7744 100644 --- a/usr.bin/mandoc/man.h +++ b/usr.bin/mandoc/man.h @@ -1,4 +1,4 @@ -/* $OpenBSD: man.h,v 1.55 2015/04/23 16:17:04 schwarze Exp $ */ +/* $OpenBSD: man.h,v 1.56 2015/10/22 21:53:49 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/usr.bin/mandoc/man_macro.c b/usr.bin/mandoc/man_macro.c index 997ab2c6cd1..b91a0c30645 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.74 2015/10/06 18:30:43 schwarze Exp $ */ +/* $OpenBSD: man_macro.c,v 1.75 2015/10/22 21:53:49 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons * Copyright (c) 2012, 2013, 2014, 2015 Ingo Schwarze @@ -128,7 +128,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; } /* @@ -377,28 +377,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 @@ -406,6 +391,7 @@ man_endparse(struct roff_man *man) { man_unscope(man, man->first); + man->flags &= ~MAN_LITERAL; } static int diff --git a/usr.bin/mandoc/man_validate.c b/usr.bin/mandoc/man_validate.c index 07dde7381ec..1f05b4c5404 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.91 2015/10/12 00:07:27 schwarze Exp $ */ +/* $OpenBSD: man_validate.c,v 1.92 2015/10/22 21:53:49 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons * Copyright (c) 2010, 2012-2015 Ingo Schwarze @@ -46,9 +46,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); @@ -77,8 +75,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 */ @@ -88,8 +86,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 */ @@ -97,16 +95,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); @@ -121,6 +126,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; } } @@ -383,28 +390,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/usr.bin/mandoc/roff.c b/usr.bin/mandoc/roff.c index 3c699972173..674b17cfa7e 100644 --- a/usr.bin/mandoc/roff.c +++ b/usr.bin/mandoc/roff.c @@ -1,4 +1,4 @@ -/* $OpenBSD: roff.c,v 1.154 2015/10/21 23:49:05 schwarze Exp $ */ +/* $OpenBSD: roff.c,v 1.155 2015/10/22 21:53:49 schwarze Exp $ */ /* * Copyright (c) 2008-2012, 2014 Kristaps Dzonsons * Copyright (c) 2010-2015 Ingo Schwarze @@ -1061,7 +1061,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; } @@ -1149,7 +1149,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/usr.bin/mandoc/roff_int.h b/usr.bin/mandoc/roff_int.h index 69a45705296..dde22024be0 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.5 2015/10/21 23:49:05 schwarze Exp $ */ +/* $OpenBSD: roff_int.h,v 1.6 2015/10/22 21:53:49 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