From 16fe0cfc6f5ff992d9e21de3d5f2f032950de5e2 Mon Sep 17 00:00:00 2001 From: schwarze Date: Fri, 17 Aug 2018 20:31:52 +0000 Subject: [PATCH] Remove more pointer arithmetic passing via regions outside the array that is undefined according to the C standard. Robert Elz pointed out i wasn't quite done yet. --- usr.bin/mandoc/libman.h | 7 ++--- usr.bin/mandoc/libmdoc.h | 8 ++---- usr.bin/mandoc/man.c | 20 ++++++------- usr.bin/mandoc/man_html.c | 12 ++++---- usr.bin/mandoc/man_macro.c | 26 ++++++++++------- usr.bin/mandoc/man_term.c | 36 ++++++++++++++--------- usr.bin/mandoc/mandocdb.c | 24 +++++++++------- usr.bin/mandoc/mdoc.c | 20 +++++-------- usr.bin/mandoc/mdoc_argv.c | 13 ++++----- usr.bin/mandoc/mdoc_html.c | 16 +++++------ usr.bin/mandoc/mdoc_macro.c | 52 ++++++++++++++++++++-------------- usr.bin/mandoc/mdoc_man.c | 36 +++++++++++++---------- usr.bin/mandoc/mdoc_markdown.c | 25 ++++++++++------ usr.bin/mandoc/mdoc_state.c | 9 +++--- usr.bin/mandoc/mdoc_term.c | 20 ++++++------- usr.bin/mandoc/mdoc_validate.c | 4 +-- 16 files changed, 177 insertions(+), 151 deletions(-) diff --git a/usr.bin/mandoc/libman.h b/usr.bin/mandoc/libman.h index f3ad8d898b3..4ab0e6defd1 100644 --- a/usr.bin/mandoc/libman.h +++ b/usr.bin/mandoc/libman.h @@ -1,7 +1,7 @@ -/* $OpenBSD: libman.h,v 1.56 2017/04/29 12:43:55 schwarze Exp $ */ +/* $OpenBSD: libman.h,v 1.57 2018/08/17 20:31:52 schwarze Exp $ */ /* * Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons - * Copyright (c) 2014, 2015 Ingo Schwarze + * Copyright (c) 2014, 2015, 2018 Ingo Schwarze * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -32,8 +32,7 @@ struct man_macro { #define MAN_JOIN (1 << 3) /* Join arguments together. */ }; -extern const struct man_macro *const man_macros; - +const struct man_macro *man_macro(enum roff_tok); void man_node_validate(struct roff_man *); void man_state(struct roff_man *, struct roff_node *); diff --git a/usr.bin/mandoc/libmdoc.h b/usr.bin/mandoc/libmdoc.h index 8c86af69609..bc8bfed31e2 100644 --- a/usr.bin/mandoc/libmdoc.h +++ b/usr.bin/mandoc/libmdoc.h @@ -1,7 +1,7 @@ -/* $OpenBSD: libmdoc.h,v 1.83 2017/05/30 16:21:07 schwarze Exp $ */ +/* $OpenBSD: libmdoc.h,v 1.84 2018/08/17 20:31:52 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons - * Copyright (c) 2013, 2014, 2015, 2017 Ingo Schwarze + * Copyright (c) 2013,2014,2015,2017,2018 Ingo Schwarze * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -59,10 +59,8 @@ enum mdelim { DELIM_MAX }; -extern const struct mdoc_macro *const mdoc_macros; +const struct mdoc_macro *mdoc_macro(enum roff_tok); - -void mdoc_macro(MACRO_PROT_ARGS); void mdoc_elem_alloc(struct roff_man *, int, int, enum roff_tok, struct mdoc_arg *); struct roff_node *mdoc_block_alloc(struct roff_man *, int, int, diff --git a/usr.bin/mandoc/man.c b/usr.bin/mandoc/man.c index 92268a5184f..acba306fceb 100644 --- a/usr.bin/mandoc/man.c +++ b/usr.bin/mandoc/man.c @@ -1,7 +1,7 @@ -/* $OpenBSD: man.c,v 1.124 2017/06/28 12:52:27 schwarze Exp $ */ +/* $OpenBSD: man.c,v 1.125 2018/08/17 20:31:52 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons - * Copyright (c) 2013, 2014, 2015, 2017 Ingo Schwarze + * Copyright (c) 2013,2014,2015,2017,2018 Ingo Schwarze * Copyright (c) 2011 Joerg Sonnenberger * * Permission to use, copy, modify, and distribute this software for any @@ -236,8 +236,8 @@ man_pmacro(struct roff_man *man, int ln, char *buf, int offs) /* Call to handler... */ - assert(man_macros[tok].fp); - (*man_macros[tok].fp)(man, tok, ln, ppos, &offs, buf); + assert(man_macro(tok)->fp != NULL); + (*man_macro(tok)->fp)(man, tok, ln, ppos, &offs, buf); /* In quick mode (for mandocdb), abort after the NAME section. */ @@ -255,7 +255,7 @@ man_pmacro(struct roff_man *man, int ln, char *buf, int offs) */ if ( ! bline || man->flags & MAN_ELINE || - man_macros[tok].flags & MAN_NSCOPED) + man_macro(tok)->flags & MAN_NSCOPED) return 1; assert(man->flags & MAN_BLINE); @@ -278,12 +278,12 @@ man_breakscope(struct roff_man *man, int tok) */ if (man->flags & MAN_ELINE && (tok < MAN_TH || - ! (man_macros[tok].flags & MAN_NSCOPED))) { + (man_macro(tok)->flags & MAN_NSCOPED) == 0)) { n = man->last; if (n->type == ROFFT_TEXT) n = n->parent; if (n->tok < MAN_TH || - man_macros[n->tok].flags & MAN_NSCOPED) + man_macro(n->tok)->flags & MAN_NSCOPED) n = n->parent; mandoc_vmsg(MANDOCERR_BLK_LINE, man->parse, @@ -315,18 +315,18 @@ man_breakscope(struct roff_man *man, int tok) */ if (man->flags & MAN_BLINE && (tok < MAN_TH || - man_macros[tok].flags & MAN_BSCOPE)) { + man_macro(tok)->flags & MAN_BSCOPE)) { n = man->last; if (n->type == ROFFT_TEXT) n = n->parent; if (n->tok < MAN_TH || - (man_macros[n->tok].flags & MAN_BSCOPE) == 0) + (man_macro(n->tok)->flags & MAN_BSCOPE) == 0) n = n->parent; assert(n->type == ROFFT_HEAD); n = n->parent; assert(n->type == ROFFT_BLOCK); - assert(man_macros[n->tok].flags & MAN_SCOPED); + assert(man_macro(n->tok)->flags & MAN_SCOPED); mandoc_vmsg(MANDOCERR_BLK_LINE, man->parse, n->line, n->pos, "%s breaks %s", diff --git a/usr.bin/mandoc/man_html.c b/usr.bin/mandoc/man_html.c index 487bf9d2d0b..9f1867071b5 100644 --- a/usr.bin/mandoc/man_html.c +++ b/usr.bin/mandoc/man_html.c @@ -1,4 +1,4 @@ -/* $OpenBSD: man_html.c,v 1.107 2018/08/16 23:40:19 schwarze Exp $ */ +/* $OpenBSD: man_html.c,v 1.108 2018/08/17 20:31:52 schwarze Exp $ */ /* * Copyright (c) 2008-2012, 2014 Kristaps Dzonsons * Copyright (c) 2013,2014,2015,2017,2018 Ingo Schwarze @@ -37,7 +37,7 @@ const struct roff_node *n, \ struct html *h -struct htmlman { +struct man_html_act { int (*pre)(MAN_ARGS); int (*post)(MAN_ARGS); }; @@ -68,7 +68,7 @@ static void man_root_post(const struct roff_meta *, static void man_root_pre(const struct roff_meta *, struct html *); -static const struct htmlman __mans[MAN_MAX - MAN_TH] = { +static const struct man_html_act man_html_acts[MAN_MAX - MAN_TH] = { { NULL, NULL }, /* TH */ { man_SH_pre, NULL }, /* SH */ { man_SS_pre, NULL }, /* SS */ @@ -107,7 +107,6 @@ static const struct htmlman __mans[MAN_MAX - MAN_TH] = { { man_UR_pre, NULL }, /* MT */ { NULL, NULL }, /* ME */ }; -static const struct htmlman *const mans = __mans - MAN_TH; /* @@ -316,8 +315,9 @@ print_man_node(MAN_ARGS) } assert(n->tok >= MAN_TH && n->tok < MAN_MAX); - if (mans[n->tok].pre) - child = (*mans[n->tok].pre)(man, n, h); + if (man_html_acts[n->tok - MAN_TH].pre != NULL) + child = (*man_html_acts[n->tok - MAN_TH].pre)(man, + n, h); /* Some block macros resume .nf in the body. */ if (save_fillmode && n->type == ROFFT_BODY) diff --git a/usr.bin/mandoc/man_macro.c b/usr.bin/mandoc/man_macro.c index 6191777300a..30c26ba4da2 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.88 2018/08/16 23:40:19 schwarze Exp $ */ +/* $OpenBSD: man_macro.c,v 1.89 2018/08/17 20:31:52 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons * Copyright (c) 2012-2015, 2017, 2018 Ingo Schwarze @@ -38,7 +38,7 @@ static int man_args(struct roff_man *, int, int *, char *, char **); static void rew_scope(struct roff_man *, enum roff_tok); -const struct man_macro __man_macros[MAN_MAX - MAN_TH] = { +static const struct man_macro man_macros[MAN_MAX - MAN_TH] = { { in_line_eoln, MAN_BSCOPE }, /* TH */ { blk_imp, MAN_BSCOPE | MAN_SCOPED }, /* SH */ { blk_imp, MAN_BSCOPE | MAN_SCOPED }, /* SS */ @@ -77,9 +77,15 @@ const struct man_macro __man_macros[MAN_MAX - MAN_TH] = { { blk_exp, MAN_BSCOPE }, /* MT */ { blk_close, MAN_BSCOPE }, /* ME */ }; -const struct man_macro *const man_macros = __man_macros - MAN_TH; +const struct man_macro * +man_macro(enum roff_tok tok) +{ + assert(tok >= MAN_TH && tok <= MAN_MAX); + return man_macros + (tok - MAN_TH); +} + void man_unscope(struct roff_man *man, const struct roff_node *to) { @@ -93,7 +99,7 @@ man_unscope(struct roff_man *man, const struct roff_node *to) if (to == NULL && ! (n->flags & NODE_VALID)) { if (man->flags & (MAN_BLINE | MAN_ELINE) && - man_macros[n->tok].flags & MAN_SCOPED) { + man_macro(n->tok)->flags & MAN_SCOPED) { mandoc_vmsg(MANDOCERR_BLK_LINE, man->parse, n->line, n->pos, "EOF breaks %s", roff_name[n->tok]); @@ -110,7 +116,7 @@ man_unscope(struct roff_man *man, const struct roff_node *to) continue; } if (n->type == ROFFT_BLOCK && - man_macros[n->tok].fp == blk_exp) + man_macro(n->tok)->fp == blk_exp) mandoc_msg(MANDOCERR_BLK_NOEND, man->parse, n->line, n->pos, roff_name[n->tok]); @@ -174,7 +180,7 @@ rew_scope(struct roff_man *man, enum roff_tok tok) } if (tok != MAN_SH && (n->tok == MAN_SH || (tok != MAN_SS && (n->tok == MAN_SS || - man_macros[n->tok].fp == blk_exp)))) + man_macro(n->tok)->fp == blk_exp)))) return; man_unscope(man, n); n = man->last; @@ -325,7 +331,7 @@ blk_imp(MACRO_PROT_ARGS) * For `TP', always keep the head open. */ - if (man_macros[tok].flags & MAN_SCOPED && + if (man_macro(tok)->flags & MAN_SCOPED && (tok == MAN_TP || tok == MAN_TQ || n == man->last)) { man->flags |= MAN_BLINE; return; @@ -363,7 +369,7 @@ in_line_eoln(MACRO_PROT_ARGS) la = *pos; if ( ! man_args(man, line, pos, buf, &p)) break; - if (man_macros[tok].flags & MAN_JOIN && + if (man_macro(tok)->flags & MAN_JOIN && man->last->type == ROFFT_TEXT) roff_word_append(man, p); else @@ -385,8 +391,8 @@ in_line_eoln(MACRO_PROT_ARGS) * waiting for terms to load into our context. */ - if (n == man->last && man_macros[tok].flags & MAN_SCOPED) { - assert( ! (man_macros[tok].flags & MAN_NSCOPED)); + if (n == man->last && man_macro(tok)->flags & MAN_SCOPED) { + assert((man_macro(tok)->flags & MAN_NSCOPED) == 0); man->flags |= MAN_ELINE; return; } diff --git a/usr.bin/mandoc/man_term.c b/usr.bin/mandoc/man_term.c index 76133ba8bf0..d4a7708989e 100644 --- a/usr.bin/mandoc/man_term.c +++ b/usr.bin/mandoc/man_term.c @@ -1,4 +1,4 @@ -/* $OpenBSD: man_term.c,v 1.166 2018/08/16 23:40:19 schwarze Exp $ */ +/* $OpenBSD: man_term.c,v 1.167 2018/08/17 20:31:52 schwarze Exp $ */ /* * Copyright (c) 2008-2012 Kristaps Dzonsons * Copyright (c) 2010-2015, 2017, 2018 Ingo Schwarze @@ -49,7 +49,7 @@ struct mtermp { struct roff_node *n, \ const struct roff_meta *meta -struct termact { +struct man_term_act { int (*pre)(DECL_ARGS); void (*post)(DECL_ARGS); int flags; @@ -91,7 +91,7 @@ static void post_SS(DECL_ARGS); static void post_TP(DECL_ARGS); static void post_UR(DECL_ARGS); -static const struct termact __termacts[MAN_MAX - MAN_TH] = { +static const struct man_term_act man_term_acts[MAN_MAX - MAN_TH] = { { NULL, NULL, 0 }, /* TH */ { pre_SH, post_SH, 0 }, /* SH */ { pre_SS, post_SS, 0 }, /* SS */ @@ -130,9 +130,16 @@ static const struct termact __termacts[MAN_MAX - MAN_TH] = { { pre_UR, post_UR, 0 }, /* MT */ { NULL, NULL, 0 }, /* ME */ }; -static const struct termact *termacts = __termacts - MAN_TH; +static const struct man_term_act *man_term_act(enum roff_tok); +static const struct man_term_act * +man_term_act(enum roff_tok tok) +{ + assert(tok >= MAN_TH && tok <= MAN_MAX); + return man_term_acts + (tok - MAN_TH); +} + void terminal_man(void *arg, const struct roff_man *man) { @@ -674,7 +681,7 @@ pre_SS(DECL_ARGS) do { n = n->prev; } while (n != NULL && n->tok >= MAN_TH && - termacts[n->tok].flags & MAN_NOTEXT); + man_term_act(n->tok)->flags & MAN_NOTEXT); if (n == NULL || n->type == ROFFT_COMMENT || (n->tok == MAN_SS && n->body->child == NULL)) break; @@ -737,7 +744,7 @@ pre_SH(DECL_ARGS) do { n = n->prev; } while (n != NULL && n->tok >= MAN_TH && - termacts[n->tok].flags & MAN_NOTEXT); + man_term_act(n->tok)->flags & MAN_NOTEXT); if (n == NULL || n->type == ROFFT_COMMENT || (n->tok == MAN_SH && n->body->child == NULL)) break; @@ -866,7 +873,8 @@ post_UR(DECL_ARGS) static void print_man_node(DECL_ARGS) { - int c; + const struct man_term_act *act; + int c; switch (n->type) { case ROFFT_TEXT: @@ -912,20 +920,20 @@ print_man_node(DECL_ARGS) return; } - assert(n->tok >= MAN_TH && n->tok <= MAN_MAX); - if ( ! (MAN_NOTEXT & termacts[n->tok].flags)) + act = man_term_act(n->tok); + if ((act->flags & MAN_NOTEXT) == 0) term_fontrepl(p, TERMFONT_NONE); c = 1; - if (termacts[n->tok].pre) - c = (*termacts[n->tok].pre)(p, mt, n, meta); + if (act->pre != NULL) + c = (*act->pre)(p, mt, n, meta); if (c && n->child) print_man_nodelist(p, mt, n->child, meta); - if (termacts[n->tok].post) - (*termacts[n->tok].post)(p, mt, n, meta); - if ( ! (MAN_NOTEXT & termacts[n->tok].flags)) + if (act->post != NULL) + (*act->post)(p, mt, n, meta); + if ((act->flags & MAN_NOTEXT) == 0) term_fontrepl(p, TERMFONT_NONE); out: diff --git a/usr.bin/mandoc/mandocdb.c b/usr.bin/mandoc/mandocdb.c index 00a0cdf0b53..37de0458dac 100644 --- a/usr.bin/mandoc/mandocdb.c +++ b/usr.bin/mandoc/mandocdb.c @@ -1,7 +1,7 @@ -/* $OpenBSD: mandocdb.c,v 1.207 2018/02/23 18:24:41 schwarze Exp $ */ +/* $OpenBSD: mandocdb.c,v 1.208 2018/08/17 20:31:52 schwarze Exp $ */ /* * Copyright (c) 2011, 2012 Kristaps Dzonsons - * Copyright (c) 2011-2017 Ingo Schwarze + * Copyright (c) 2011-2018 Ingo Schwarze * Copyright (c) 2016 Ed Maste * * Permission to use, copy, modify, and distribute this software for any @@ -170,7 +170,7 @@ static struct ohash names; /* table of all names */ static struct ohash strings; /* table of all strings */ static uint64_t name_mask; -static const struct mdoc_handler __mdocs[MDOC_MAX - MDOC_Dd] = { +static const struct mdoc_handler mdoc_handlers[MDOC_MAX - MDOC_Dd] = { { NULL, 0, NODE_NOPRT }, /* Dd */ { NULL, 0, NODE_NOPRT }, /* Dt */ { NULL, 0, NODE_NOPRT }, /* Os */ @@ -292,7 +292,6 @@ static const struct mdoc_handler __mdocs[MDOC_MAX - MDOC_Dd] = { { NULL, 0, 0 }, /* %U */ { NULL, 0, 0 }, /* Ta */ }; -static const struct mdoc_handler *const mdocs = __mdocs - MDOC_Dd; int @@ -1508,25 +1507,28 @@ static void parse_mdoc(struct mpage *mpage, const struct roff_meta *meta, const struct roff_node *n) { + const struct mdoc_handler *handler; for (n = n->child; n != NULL; n = n->next) { - if (n->tok == TOKEN_NONE || - n->tok < ROFF_MAX || - n->flags & mdocs[n->tok].taboo) + if (n->tok == TOKEN_NONE || n->tok < ROFF_MAX) continue; assert(n->tok >= MDOC_Dd && n->tok < MDOC_MAX); + handler = mdoc_handlers + (n->tok - MDOC_Dd); + if (n->flags & handler->taboo) + continue; + switch (n->type) { case ROFFT_ELEM: case ROFFT_BLOCK: case ROFFT_HEAD: case ROFFT_BODY: case ROFFT_TAIL: - if (mdocs[n->tok].fp != NULL && - (*mdocs[n->tok].fp)(mpage, meta, n) == 0) + if (handler->fp != NULL && + (*handler->fp)(mpage, meta, n) == 0) break; - if (mdocs[n->tok].mask) + if (handler->mask) putmdockey(mpage, n->child, - mdocs[n->tok].mask, mdocs[n->tok].taboo); + handler->mask, handler->taboo); break; default: continue; diff --git a/usr.bin/mandoc/mdoc.c b/usr.bin/mandoc/mdoc.c index 61bbe77cd70..a5fdc03cc93 100644 --- a/usr.bin/mandoc/mdoc.c +++ b/usr.bin/mandoc/mdoc.c @@ -1,7 +1,7 @@ -/* $OpenBSD: mdoc.c,v 1.157 2017/08/11 16:55:10 schwarze Exp $ */ +/* $OpenBSD: mdoc.c,v 1.158 2018/08/17 20:31:52 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons - * Copyright (c) 2010, 2012-2017 Ingo Schwarze + * Copyright (c) 2010, 2012-2018 Ingo Schwarze * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -77,13 +77,6 @@ mdoc_parseln(struct roff_man *mdoc, int ln, char *buf, int offs) mdoc_ptext(mdoc, ln, buf, offs); } -void -mdoc_macro(MACRO_PROT_ARGS) -{ - assert(tok >= MDOC_Dd && tok < MDOC_MAX); - (*mdoc_macros[tok].fp)(mdoc, tok, line, ppos, pos, buf); -} - void mdoc_tail_alloc(struct roff_man *mdoc, int line, int pos, enum roff_tok tok) { @@ -194,7 +187,8 @@ mdoc_ptext(struct roff_man *mdoc, int line, char *buf, int offs) (n->parent != NULL && n->parent->tok == MDOC_Bl && n->parent->norm->Bl.type == LIST_column)) { mdoc->flags |= MDOC_FREECOL; - mdoc_macro(mdoc, MDOC_It, line, offs, &offs, buf); + (*mdoc_macro(MDOC_It)->fp)(mdoc, MDOC_It, + line, offs, &offs, buf); return 1; } @@ -376,7 +370,7 @@ mdoc_pmacro(struct roff_man *mdoc, int ln, char *buf, int offs) n = mdoc->last; if (n == NULL || tok == MDOC_It || tok == MDOC_El) { - mdoc_macro(mdoc, tok, ln, sv, &offs, buf); + (*mdoc_macro(tok)->fp)(mdoc, tok, ln, sv, &offs, buf); return 1; } @@ -392,13 +386,13 @@ mdoc_pmacro(struct roff_man *mdoc, int ln, char *buf, int offs) (n->parent != NULL && n->parent->tok == MDOC_Bl && n->parent->norm->Bl.type == LIST_column)) { mdoc->flags |= MDOC_FREECOL; - mdoc_macro(mdoc, MDOC_It, ln, sv, &sv, buf); + (*mdoc_macro(MDOC_It)->fp)(mdoc, MDOC_It, ln, sv, &sv, buf); return 1; } /* Normal processing of a macro. */ - mdoc_macro(mdoc, tok, ln, sv, &offs, buf); + (*mdoc_macro(tok)->fp)(mdoc, tok, ln, sv, &offs, buf); /* In quick mode (for mandocdb), abort after the NAME section. */ diff --git a/usr.bin/mandoc/mdoc_argv.c b/usr.bin/mandoc/mdoc_argv.c index bd9984ca1a9..3d427f2ec94 100644 --- a/usr.bin/mandoc/mdoc_argv.c +++ b/usr.bin/mandoc/mdoc_argv.c @@ -1,7 +1,7 @@ -/* $OpenBSD: mdoc_argv.c,v 1.71 2017/05/30 16:21:07 schwarze Exp $ */ +/* $OpenBSD: mdoc_argv.c,v 1.72 2018/08/17 20:31:52 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons - * Copyright (c) 2012, 2014-2017 Ingo Schwarze + * Copyright (c) 2012, 2014-2018 Ingo Schwarze * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -142,7 +142,7 @@ static const enum mdocargt args_Bl[] = { MDOC_ARG_MAX }; -static const struct mdocarg __mdocargs[MDOC_MAX - MDOC_Dd] = { +static const struct mdocarg mdocargs[MDOC_MAX - MDOC_Dd] = { { ARGSFL_NONE, NULL }, /* Dd */ { ARGSFL_NONE, NULL }, /* Dt */ { ARGSFL_NONE, NULL }, /* Os */ @@ -264,7 +264,6 @@ static const struct mdocarg __mdocargs[MDOC_MAX - MDOC_Dd] = { { ARGSFL_NONE, NULL }, /* %U */ { ARGSFL_NONE, NULL }, /* Ta */ }; -static const struct mdocarg *const mdocargs = __mdocargs - MDOC_Dd; /* @@ -288,7 +287,7 @@ mdoc_argv(struct roff_man *mdoc, int line, enum roff_tok tok, /* Which flags does this macro support? */ assert(tok >= MDOC_Dd && tok < MDOC_MAX); - argtable = mdocargs[tok].argvs; + argtable = mdocargs[tok - MDOC_Dd].argvs; if (argtable == NULL) return; @@ -366,7 +365,7 @@ mdoc_argv(struct roff_man *mdoc, int line, enum roff_tok tok, /* Prepare for parsing the next flag. */ *pos = ipos; - argtable = mdocargs[tok].argvs; + argtable = mdocargs[tok - MDOC_Dd].argvs; } } @@ -420,7 +419,7 @@ mdoc_args(struct roff_man *mdoc, int line, int *pos, if (v == NULL) v = &v_local; - fl = tok == TOKEN_NONE ? ARGSFL_NONE : mdocargs[tok].flags; + fl = tok == TOKEN_NONE ? ARGSFL_NONE : mdocargs[tok - MDOC_Dd].flags; /* * We know that we're in an `It', so it's reasonable to expect diff --git a/usr.bin/mandoc/mdoc_html.c b/usr.bin/mandoc/mdoc_html.c index 5d5d35d2af5..eab4bd60bf7 100644 --- a/usr.bin/mandoc/mdoc_html.c +++ b/usr.bin/mandoc/mdoc_html.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mdoc_html.c,v 1.185 2018/07/27 17:47:05 schwarze Exp $ */ +/* $OpenBSD: mdoc_html.c,v 1.186 2018/08/17 20:31:52 schwarze Exp $ */ /* * Copyright (c) 2008-2011, 2014 Kristaps Dzonsons * Copyright (c) 2014,2015,2016,2017,2018 Ingo Schwarze @@ -40,7 +40,7 @@ #define MIN(a,b) ((/*CONSTCOND*/(a)<(b))?(a):(b)) #endif -struct htmlmdoc { +struct mdoc_html_act { int (*pre)(MDOC_ARGS); void (*post)(MDOC_ARGS); }; @@ -117,7 +117,7 @@ static int mdoc_vt_pre(MDOC_ARGS); static int mdoc_xr_pre(MDOC_ARGS); static int mdoc_xx_pre(MDOC_ARGS); -static const struct htmlmdoc __mdocs[MDOC_MAX - MDOC_Dd] = { +static const struct mdoc_html_act mdoc_html_acts[MDOC_MAX - MDOC_Dd] = { {NULL, NULL}, /* Dd */ {NULL, NULL}, /* Dt */ {NULL, NULL}, /* Os */ @@ -239,7 +239,6 @@ static const struct htmlmdoc __mdocs[MDOC_MAX - MDOC_Dd] = { {mdoc__x_pre, mdoc__x_post}, /* %U */ {NULL, NULL}, /* Ta */ }; -static const struct htmlmdoc *const mdocs = __mdocs - MDOC_Dd; /* @@ -400,9 +399,10 @@ print_mdoc_node(MDOC_ARGS) break; } assert(n->tok >= MDOC_Dd && n->tok < MDOC_MAX); - if (mdocs[n->tok].pre != NULL && + if (mdoc_html_acts[n->tok - MDOC_Dd].pre != NULL && (n->end == ENDBODY_NOT || n->child != NULL)) - child = (*mdocs[n->tok].pre)(meta, n, h); + child = (*mdoc_html_acts[n->tok - MDOC_Dd].pre)(meta, + n, h); break; } @@ -421,10 +421,10 @@ print_mdoc_node(MDOC_ARGS) break; default: if (n->tok < ROFF_MAX || - mdocs[n->tok].post == NULL || + mdoc_html_acts[n->tok - MDOC_Dd].post == NULL || n->flags & NODE_ENDED) break; - (*mdocs[n->tok].post)(meta, n, h); + (*mdoc_html_acts[n->tok - MDOC_Dd].post)(meta, n, h); if (n->end != ENDBODY_NOT) n->body->flags |= NODE_ENDED; break; diff --git a/usr.bin/mandoc/mdoc_macro.c b/usr.bin/mandoc/mdoc_macro.c index b78b3ed43cd..250b04e2ad7 100644 --- a/usr.bin/mandoc/mdoc_macro.c +++ b/usr.bin/mandoc/mdoc_macro.c @@ -1,7 +1,7 @@ -/* $OpenBSD: mdoc_macro.c,v 1.181 2017/05/30 16:21:07 schwarze Exp $ */ +/* $OpenBSD: mdoc_macro.c,v 1.182 2018/08/17 20:31:52 schwarze Exp $ */ /* * Copyright (c) 2008-2012 Kristaps Dzonsons - * Copyright (c) 2010, 2012-2017 Ingo Schwarze + * Copyright (c) 2010, 2012-2018 Ingo Schwarze * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -58,7 +58,7 @@ static void rew_last(struct roff_man *, const struct roff_node *); static void rew_pending(struct roff_man *, const struct roff_node *); -const struct mdoc_macro __mdoc_macros[MDOC_MAX - MDOC_Dd] = { +static const struct mdoc_macro mdoc_macros[MDOC_MAX - MDOC_Dd] = { { in_line_eoln, MDOC_PROLOGUE }, /* Dd */ { in_line_eoln, MDOC_PROLOGUE }, /* Dt */ { in_line_eoln, MDOC_PROLOGUE }, /* Os */ @@ -199,9 +199,15 @@ const struct mdoc_macro __mdoc_macros[MDOC_MAX - MDOC_Dd] = { { in_line_eoln, 0 }, /* %U */ { phrase_ta, MDOC_CALLABLE | MDOC_PARSED | MDOC_JOIN }, /* Ta */ }; -const struct mdoc_macro *const mdoc_macros = __mdoc_macros - MDOC_Dd; +const struct mdoc_macro * +mdoc_macro(enum roff_tok tok) +{ + assert(tok >= MDOC_Dd && tok < MDOC_MAX); + return mdoc_macros + (tok - MDOC_Dd); +} + /* * This is called at the end of parsing. It must traverse up the tree, * closing out open [implicit] scopes. Obviously, open explicit scopes @@ -219,7 +225,7 @@ mdoc_endparse(struct roff_man *mdoc) for ( ; n; n = n->parent) if (n->type == ROFFT_BLOCK && - mdoc_macros[n->tok].flags & MDOC_EXPLICIT) + mdoc_macro(n->tok)->flags & MDOC_EXPLICIT) mandoc_msg(MANDOCERR_BLK_NOEND, mdoc->parse, n->line, n->pos, roff_name[n->tok]); @@ -242,10 +248,10 @@ lookup(struct roff_man *mdoc, int from, int line, int ppos, const char *p) mdoc->flags &= ~MDOC_PHRASEQF; return TOKEN_NONE; } - if (from == TOKEN_NONE || mdoc_macros[from].flags & MDOC_PARSED) { + if (from == TOKEN_NONE || mdoc_macro(from)->flags & MDOC_PARSED) { res = roffhash_find(mdoc->mdocmac, p, 0); if (res != TOKEN_NONE) { - if (mdoc_macros[res].flags & MDOC_CALLABLE) + if (mdoc_macro(res)->flags & MDOC_CALLABLE) return res; mandoc_msg(MANDOCERR_MACRO_CALL, mdoc->parse, line, ppos, p); @@ -407,7 +413,7 @@ find_pending(struct roff_man *mdoc, enum roff_tok tok, int line, int ppos, if (n->flags & NODE_ENDED) continue; if (n->type == ROFFT_BLOCK && - mdoc_macros[n->tok].flags & MDOC_EXPLICIT) { + mdoc_macro(n->tok)->flags & MDOC_EXPLICIT) { irc = 1; break_intermediate(mdoc->last, target); if (target->type == ROFFT_HEAD) @@ -516,13 +522,13 @@ macro_or_word(MACRO_PROT_ARGS, int parsed) if (ntok == TOKEN_NONE) { dword(mdoc, line, ppos, p, DELIM_MAX, tok == TOKEN_NONE || - mdoc_macros[tok].flags & MDOC_JOIN); + mdoc_macro(tok)->flags & MDOC_JOIN); return 0; } else { if (tok != TOKEN_NONE && - mdoc_macros[tok].fp == in_line_eoln) + mdoc_macro(tok)->fp == in_line_eoln) rew_elem(mdoc, tok); - mdoc_macro(mdoc, ntok, line, ppos, pos, buf); + (*mdoc_macro(ntok)->fp)(mdoc, ntok, line, ppos, pos, buf); if (tok == TOKEN_NONE) append_delims(mdoc, line, pos, buf); return 1; @@ -686,7 +692,7 @@ blk_exp_close(MACRO_PROT_ARGS) mdoc_tail_alloc(mdoc, line, ppos, atok); } - if ( ! (mdoc_macros[tok].flags & MDOC_PARSED)) { + if ((mdoc_macro(tok)->flags & MDOC_PARSED) == 0) { if (buf[*pos] != '\0') mandoc_vmsg(MANDOCERR_ARG_SKIP, mdoc->parse, line, ppos, @@ -715,14 +721,14 @@ blk_exp_close(MACRO_PROT_ARGS) if (ntok == TOKEN_NONE) { dword(mdoc, line, lastarg, p, DELIM_MAX, - MDOC_JOIN & mdoc_macros[tok].flags); + mdoc_macro(tok)->flags & MDOC_JOIN); continue; } if (n != NULL) rew_last(mdoc, n); mdoc->flags &= ~MDOC_NEWLINE; - mdoc_macro(mdoc, ntok, line, lastarg, pos, buf); + (*mdoc_macro(ntok)->fp)(mdoc, ntok, line, lastarg, pos, buf); break; } @@ -829,7 +835,8 @@ in_line(MACRO_PROT_ARGS) mdoc->parse, line, ppos, roff_name[tok]); } - mdoc_macro(mdoc, ntok, line, la, pos, buf); + (*mdoc_macro(ntok)->fp)(mdoc, ntok, + line, la, pos, buf); if (nl) append_delims(mdoc, line, pos, buf); return; @@ -873,7 +880,7 @@ in_line(MACRO_PROT_ARGS) } dword(mdoc, line, la, p, d, - mdoc_macros[tok].flags & MDOC_JOIN); + mdoc_macro(tok)->flags & MDOC_JOIN); /* * If the first argument is a closing delimiter, @@ -942,7 +949,7 @@ blk_full(MACRO_PROT_ARGS) return; } - if ( ! (mdoc_macros[tok].flags & MDOC_EXPLICIT)) { + if ((mdoc_macro(tok)->flags & MDOC_EXPLICIT) == 0) { /* Here, tok is one of Sh Ss Nm Nd It. */ @@ -967,7 +974,7 @@ blk_full(MACRO_PROT_ARGS) break; } - if (mdoc_macros[n->tok].flags & MDOC_EXPLICIT) { + if (mdoc_macro(n->tok)->flags & MDOC_EXPLICIT) { switch (tok) { case MDOC_Sh: case MDOC_Ss: @@ -1337,7 +1344,7 @@ in_line_argn(MACRO_PROT_ARGS) ac = mdoc_args(mdoc, line, pos, buf, tok, &p); if (ac == ARGS_WORD && state == -1 && - ! (mdoc_macros[tok].flags & MDOC_IGNDELIM) && + (mdoc_macro(tok)->flags & MDOC_IGNDELIM) == 0 && mdoc_isdelim(p) == DELIM_OPEN) { dword(mdoc, line, la, p, DELIM_OPEN, 0); continue; @@ -1370,11 +1377,12 @@ in_line_argn(MACRO_PROT_ARGS) rew_elem(mdoc, tok); state = -2; } - mdoc_macro(mdoc, ntok, line, la, pos, buf); + (*mdoc_macro(ntok)->fp)(mdoc, ntok, + line, la, pos, buf); break; } - if (mdoc_macros[tok].flags & MDOC_IGNDELIM || + if (mdoc_macro(tok)->flags & MDOC_IGNDELIM || mdoc_isdelim(p) == DELIM_NONE) { if (state == -1) { mdoc_elem_alloc(mdoc, line, ppos, tok, arg); @@ -1387,7 +1395,7 @@ in_line_argn(MACRO_PROT_ARGS) } dword(mdoc, line, la, p, DELIM_MAX, - mdoc_macros[tok].flags & MDOC_JOIN); + mdoc_macro(tok)->flags & MDOC_JOIN); } if (state == -1) { diff --git a/usr.bin/mandoc/mdoc_man.c b/usr.bin/mandoc/mdoc_man.c index 5573dd531d8..321eb3f4ed7 100644 --- a/usr.bin/mandoc/mdoc_man.c +++ b/usr.bin/mandoc/mdoc_man.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mdoc_man.c,v 1.124 2018/04/11 17:10:35 schwarze Exp $ */ +/* $OpenBSD: mdoc_man.c,v 1.125 2018/08/17 20:31:52 schwarze Exp $ */ /* * Copyright (c) 2011-2018 Ingo Schwarze * @@ -34,7 +34,7 @@ typedef int (*int_fp)(DECL_ARGS); typedef void (*void_fp)(DECL_ARGS); -struct manact { +struct mdoc_man_act { int_fp cond; /* DON'T run actions */ int_fp pre; /* pre-node action */ void_fp post; /* post-node action */ @@ -122,7 +122,7 @@ static void print_width(const struct mdoc_bl *, static void print_count(int *); static void print_node(DECL_ARGS); -static const void_fp roff_manacts[ROFF_MAX] = { +static const void_fp roff_man_acts[ROFF_MAX] = { pre_br, /* br */ pre_onearg, /* ce */ pre_ft, /* ft */ @@ -135,7 +135,7 @@ static const void_fp roff_manacts[ROFF_MAX] = { pre_onearg, /* ti */ }; -static const struct manact __manacts[MDOC_MAX - MDOC_Dd] = { +static const struct mdoc_man_act mdoc_man_acts[MDOC_MAX - MDOC_Dd] = { { NULL, NULL, NULL, NULL, NULL }, /* Dd */ { NULL, NULL, NULL, NULL, NULL }, /* Dt */ { NULL, NULL, NULL, NULL, NULL }, /* Os */ @@ -257,7 +257,7 @@ static const struct manact __manacts[MDOC_MAX - MDOC_Dd] = { { NULL, NULL, post_percent, NULL, NULL }, /* %U */ { NULL, NULL, NULL, NULL, NULL }, /* Ta */ }; -static const struct manact *const manacts = __manacts - MDOC_Dd; +static const struct mdoc_man_act *mdoc_man_act(enum roff_tok); static int outflags; #define MMAN_spc (1 << 0) /* blank character before next word */ @@ -288,6 +288,13 @@ static struct { } fontqueue; +static const struct mdoc_man_act * +mdoc_man_act(enum roff_tok tok) +{ + assert(tok >= MDOC_Dd && tok <= MDOC_MAX); + return mdoc_man_acts + (tok - MDOC_Dd); +} + static int man_strlen(const char *cp) { @@ -638,9 +645,9 @@ man_mdoc(void *arg, const struct roff_man *mdoc) static void print_node(DECL_ARGS) { - const struct manact *act; - struct roff_node *sub; - int cond, do_sub; + const struct mdoc_man_act *act; + struct roff_node *sub; + int cond, do_sub; if (n->flags & NODE_NOPRT) return; @@ -678,15 +685,14 @@ print_node(DECL_ARGS) else if (outflags & MMAN_Sm) outflags |= MMAN_spc; } else if (n->tok < ROFF_MAX) { - (*roff_manacts[n->tok])(meta, n); + (*roff_man_acts[n->tok])(meta, n); return; } else { - assert(n->tok >= MDOC_Dd && n->tok < MDOC_MAX); /* * Conditionally run the pre-node action handler for a * node. */ - act = manacts + n->tok; + act = mdoc_man_act(n->tok); cond = act->cond == NULL || (*act->cond)(meta, n); if (cond && act->pre != NULL && (n->end == ENDBODY_NOT || n->child != NULL)) @@ -734,7 +740,7 @@ pre_enc(DECL_ARGS) { const char *prefix; - prefix = manacts[n->tok].prefix; + prefix = mdoc_man_act(n->tok)->prefix; if (NULL == prefix) return 1; print_word(prefix); @@ -747,7 +753,7 @@ post_enc(DECL_ARGS) { const char *suffix; - suffix = manacts[n->tok].suffix; + suffix = mdoc_man_act(n->tok)->suffix; if (NULL == suffix) return; outflags &= ~(MMAN_spc | MMAN_nl); @@ -772,7 +778,7 @@ static void post_percent(DECL_ARGS) { - if (pre_em == manacts[n->tok].pre) + if (mdoc_man_act(n->tok)->pre == pre_em) font_pop(); if (n->next) { print_word(","); @@ -818,7 +824,7 @@ pre_sect(DECL_ARGS) if (n->type == ROFFT_HEAD) { outflags |= MMAN_sp; - print_block(manacts[n->tok].prefix, 0); + print_block(mdoc_man_act(n->tok)->prefix, 0); print_word(""); putchar('\"'); outflags &= ~MMAN_spc; diff --git a/usr.bin/mandoc/mdoc_markdown.c b/usr.bin/mandoc/mdoc_markdown.c index 2789efb9928..b647a98de33 100644 --- a/usr.bin/mandoc/mdoc_markdown.c +++ b/usr.bin/mandoc/mdoc_markdown.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mdoc_markdown.c,v 1.25 2018/08/16 13:49:40 schwarze Exp $ */ +/* $OpenBSD: mdoc_markdown.c,v 1.26 2018/08/17 20:31:52 schwarze Exp $ */ /* * Copyright (c) 2017, 2018 Ingo Schwarze * @@ -103,7 +103,7 @@ static void md_post_Pf(struct roff_node *); static void md_post_Vt(struct roff_node *); static void md_post__T(struct roff_node *); -static const struct md_act __md_acts[MDOC_MAX - MDOC_Dd] = { +static const struct md_act md_acts[MDOC_MAX - MDOC_Dd] = { { NULL, NULL, NULL, NULL, NULL }, /* Dd */ { NULL, NULL, NULL, NULL, NULL }, /* Dt */ { NULL, NULL, NULL, NULL, NULL }, /* Os */ @@ -225,7 +225,7 @@ static const struct md_act __md_acts[MDOC_MAX - MDOC_Dd] = { { NULL, md_pre_Lk, md_post_pc, NULL, NULL }, /* %U */ { NULL, NULL, NULL, NULL, NULL }, /* Ta */ }; -static const struct md_act *const md_acts = __md_acts - MDOC_Dd; +static const struct md_act *md_act(enum roff_tok); static int outflags; #define MD_spc (1 << 0) /* Blank character before next word. */ @@ -250,6 +250,14 @@ static int escflags; /* Escape in generated markdown code: */ static int code_blocks, quote_blocks, list_blocks; static int outcount; + +static const struct md_act * +md_act(enum roff_tok tok) +{ + assert(tok >= MDOC_Dd && tok <= MDOC_MAX); + return md_acts + (tok - MDOC_Dd); +} + void markdown_mdoc(void *arg, const struct roff_man *mdoc) { @@ -330,8 +338,7 @@ md_node(struct roff_node *n) break; } } else { - assert(n->tok >= MDOC_Dd && n->tok < MDOC_MAX); - act = md_acts + n->tok; + act = md_act(n->tok); cond = act->cond == NULL || (*act->cond)(n); if (cond && act->pre != NULL && (n->end == ENDBODY_NOT || n->child != NULL)) @@ -719,7 +726,7 @@ md_pre_raw(struct roff_node *n) { const char *prefix; - if ((prefix = md_acts[n->tok].prefix) != NULL) { + if ((prefix = md_act(n->tok)->prefix) != NULL) { md_rawword(prefix); outflags &= ~MD_spc; if (*prefix == '`') @@ -733,7 +740,7 @@ md_post_raw(struct roff_node *n) { const char *suffix; - if ((suffix = md_acts[n->tok].suffix) != NULL) { + if ((suffix = md_act(n->tok)->suffix) != NULL) { outflags &= ~(MD_spc | MD_nl); md_rawword(suffix); if (*suffix == '`') @@ -746,7 +753,7 @@ md_pre_word(struct roff_node *n) { const char *prefix; - if ((prefix = md_acts[n->tok].prefix) != NULL) { + if ((prefix = md_act(n->tok)->prefix) != NULL) { md_word(prefix); outflags &= ~MD_spc; } @@ -758,7 +765,7 @@ md_post_word(struct roff_node *n) { const char *suffix; - if ((suffix = md_acts[n->tok].suffix) != NULL) { + if ((suffix = md_act(n->tok)->suffix) != NULL) { outflags &= ~(MD_spc | MD_nl); md_word(suffix); } diff --git a/usr.bin/mandoc/mdoc_state.c b/usr.bin/mandoc/mdoc_state.c index df4e367e3ca..9d335146a35 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.9 2017/11/29 20:04:36 schwarze Exp $ */ +/* $OpenBSD: mdoc_state.c,v 1.10 2018/08/17 20:31:52 schwarze Exp $ */ /* * Copyright (c) 2014, 2015, 2017 Ingo Schwarze * @@ -36,7 +36,7 @@ static void state_dl(STATE_ARGS); static void state_sh(STATE_ARGS); static void state_sm(STATE_ARGS); -static const state_handler __state_handlers[MDOC_MAX - MDOC_Dd] = { +static const state_handler state_handlers[MDOC_MAX - MDOC_Dd] = { NULL, /* Dd */ NULL, /* Dt */ NULL, /* Os */ @@ -158,7 +158,6 @@ static const state_handler __state_handlers[MDOC_MAX - MDOC_Dd] = { NULL, /* %U */ NULL, /* Ta */ }; -static const state_handler *const state_handlers = __state_handlers - MDOC_Dd; void @@ -170,10 +169,10 @@ mdoc_state(struct roff_man *mdoc, struct roff_node *n) return; assert(n->tok >= MDOC_Dd && n->tok < MDOC_MAX); - if ( ! (mdoc_macros[n->tok].flags & MDOC_PROLOGUE)) + if ((mdoc_macro(n->tok)->flags & MDOC_PROLOGUE) == 0) mdoc->flags |= MDOC_PBODY; - handler = state_handlers[n->tok]; + handler = state_handlers[n->tok - MDOC_Dd]; if (*handler) (*handler)(mdoc, n); } diff --git a/usr.bin/mandoc/mdoc_term.c b/usr.bin/mandoc/mdoc_term.c index c226f4b5eb2..8b255bf7cb0 100644 --- a/usr.bin/mandoc/mdoc_term.c +++ b/usr.bin/mandoc/mdoc_term.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mdoc_term.c,v 1.266 2018/04/11 17:10:35 schwarze Exp $ */ +/* $OpenBSD: mdoc_term.c,v 1.267 2018/08/17 20:31:52 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons * Copyright (c) 2010, 2012-2018 Ingo Schwarze @@ -45,7 +45,7 @@ struct termpair { const struct roff_meta *meta, \ struct roff_node *n -struct termact { +struct mdoc_term_act { int (*pre)(DECL_ARGS); void (*post)(DECL_ARGS); }; @@ -122,7 +122,7 @@ static int termp_vt_pre(DECL_ARGS); static int termp_xr_pre(DECL_ARGS); static int termp_xx_pre(DECL_ARGS); -static const struct termact __termacts[MDOC_MAX - MDOC_Dd] = { +static const struct mdoc_term_act mdoc_term_acts[MDOC_MAX - MDOC_Dd] = { { NULL, NULL }, /* Dd */ { NULL, NULL }, /* Dt */ { NULL, NULL }, /* Os */ @@ -244,7 +244,6 @@ static const struct termact __termacts[MDOC_MAX - MDOC_Dd] = { { NULL, termp____post }, /* %U */ { NULL, NULL }, /* Ta */ }; -static const struct termact *const termacts = __termacts - MDOC_Dd; static int fn_prio; @@ -308,9 +307,10 @@ print_mdoc_nodelist(DECL_ARGS) static void print_mdoc_node(DECL_ARGS) { - int chld; + const struct mdoc_term_act *act; struct termpair npair; size_t offset, rmargin; + int chld; if (n->type == ROFFT_COMMENT || n->flags & NODE_NOPRT) return; @@ -368,10 +368,10 @@ print_mdoc_node(DECL_ARGS) return; } assert(n->tok >= MDOC_Dd && n->tok < MDOC_MAX); - if (termacts[n->tok].pre != NULL && + act = mdoc_term_acts + (n->tok - MDOC_Dd); + if (act->pre != NULL && (n->end == ENDBODY_NOT || n->child != NULL)) - chld = (*termacts[n->tok].pre) - (p, &npair, meta, n); + chld = (*act->pre)(p, &npair, meta, n); break; } @@ -389,9 +389,9 @@ print_mdoc_node(DECL_ARGS) case ROFFT_EQN: break; default: - if (termacts[n->tok].post == NULL || n->flags & NODE_ENDED) + if (act->post == NULL || n->flags & NODE_ENDED) break; - (void)(*termacts[n->tok].post)(p, &npair, meta, n); + (void)(*act->post)(p, &npair, meta, n); /* * Explicit end tokens not only call the post diff --git a/usr.bin/mandoc/mdoc_validate.c b/usr.bin/mandoc/mdoc_validate.c index 03a5c038db1..4059604453d 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.276 2018/08/16 15:04:45 schwarze Exp $ */ +/* $OpenBSD: mdoc_validate.c,v 1.277 2018/08/17 20:31:52 schwarze Exp $ */ /* * Copyright (c) 2008-2012 Kristaps Dzonsons * Copyright (c) 2010-2018 Ingo Schwarze @@ -1975,7 +1975,7 @@ post_root(POST_ARGS) while (n != NULL && (n->type == ROFFT_COMMENT || (n->tok >= MDOC_Dd && - mdoc_macros[n->tok].flags & MDOC_PROLOGUE))) + mdoc_macro(n->tok)->flags & MDOC_PROLOGUE))) n = n->next; if (n == NULL) -- 2.20.1