summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--libman.h5
-rw-r--r--libmdoc.h6
-rw-r--r--man.c18
-rw-r--r--man_html.c10
-rw-r--r--man_macro.c24
-rw-r--r--man_term.c34
-rw-r--r--mandocdb.c22
-rw-r--r--mdoc.c18
-rw-r--r--mdoc_argv.c11
-rw-r--r--mdoc_html.c14
-rw-r--r--mdoc_macro.c50
-rw-r--r--mdoc_man.c34
-rw-r--r--mdoc_markdown.c23
-rw-r--r--mdoc_state.c7
-rw-r--r--mdoc_term.c18
-rw-r--r--mdoc_validate.c2
16 files changed, 161 insertions, 135 deletions
diff --git a/libman.h b/libman.h
index fd39d2f9..89525d4e 100644
--- a/libman.h
+++ b/libman.h
@@ -1,7 +1,7 @@
/* $Id$ */
/*
* Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
- * Copyright (c) 2014, 2015 Ingo Schwarze <schwarze@openbsd.org>
+ * Copyright (c) 2014, 2015, 2018 Ingo Schwarze <schwarze@openbsd.org>
*
* 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/libmdoc.h b/libmdoc.h
index b55305b5..7d544dfe 100644
--- a/libmdoc.h
+++ b/libmdoc.h
@@ -1,7 +1,7 @@
/* $Id$ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
- * Copyright (c) 2013, 2014, 2015, 2017 Ingo Schwarze <schwarze@openbsd.org>
+ * Copyright (c) 2013,2014,2015,2017,2018 Ingo Schwarze <schwarze@openbsd.org>
*
* 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/man.c b/man.c
index 91aa88f6..69a80374 100644
--- a/man.c
+++ b/man.c
@@ -1,7 +1,7 @@
/* $Id$ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
- * Copyright (c) 2013, 2014, 2015, 2017 Ingo Schwarze <schwarze@openbsd.org>
+ * Copyright (c) 2013,2014,2015,2017,2018 Ingo Schwarze <schwarze@openbsd.org>
* Copyright (c) 2011 Joerg Sonnenberger <joerg@netbsd.org>
*
* Permission to use, copy, modify, and distribute this software for any
@@ -238,8 +238,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. */
@@ -257,7 +257,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);
@@ -280,12 +280,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,
@@ -317,18 +317,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/man_html.c b/man_html.c
index 3fb2dccf..2d451a51 100644
--- a/man_html.c
+++ b/man_html.c
@@ -39,7 +39,7 @@
const struct roff_node *n, \
struct html *h
-struct htmlman {
+struct man_html_act {
int (*pre)(MAN_ARGS);
int (*post)(MAN_ARGS);
};
@@ -70,7 +70,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 */
@@ -109,7 +109,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;
/*
@@ -318,8 +317,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/man_macro.c b/man_macro.c
index 643bbb63..65f1afb8 100644
--- a/man_macro.c
+++ b/man_macro.c
@@ -40,7 +40,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 */
@@ -79,9 +79,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)
{
@@ -95,7 +101,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]);
@@ -112,7 +118,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]);
@@ -176,7 +182,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;
@@ -327,7 +333,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;
@@ -365,7 +371,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
@@ -387,8 +393,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/man_term.c b/man_term.c
index 234f334b..8c70a98c 100644
--- a/man_term.c
+++ b/man_term.c
@@ -51,7 +51,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;
@@ -93,7 +93,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 */
@@ -132,9 +132,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)
{
@@ -676,7 +683,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;
@@ -739,7 +746,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;
@@ -868,7 +875,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:
@@ -914,20 +922,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/mandocdb.c b/mandocdb.c
index 80d9457f..dbb24dfd 100644
--- a/mandocdb.c
+++ b/mandocdb.c
@@ -1,7 +1,7 @@
/* $Id$ */
/*
* Copyright (c) 2011, 2012 Kristaps Dzonsons <kristaps@bsd.lv>
- * Copyright (c) 2011-2017 Ingo Schwarze <schwarze@openbsd.org>
+ * Copyright (c) 2011-2018 Ingo Schwarze <schwarze@openbsd.org>
* Copyright (c) 2016 Ed Maste <emaste@freebsd.org>
*
* Permission to use, copy, modify, and distribute this software for any
@@ -185,7 +185,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 */
@@ -307,7 +307,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
@@ -1546,25 +1545,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/mdoc.c b/mdoc.c
index bc2af6f7..22f25b69 100644
--- a/mdoc.c
+++ b/mdoc.c
@@ -1,7 +1,7 @@
/* $Id$ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
- * Copyright (c) 2010, 2012-2017 Ingo Schwarze <schwarze@openbsd.org>
+ * Copyright (c) 2010, 2012-2018 Ingo Schwarze <schwarze@openbsd.org>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
@@ -80,13 +80,6 @@ mdoc_parseln(struct roff_man *mdoc, int ln, char *buf, int 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)
{
struct roff_node *p;
@@ -196,7 +189,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;
}
@@ -378,7 +372,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;
}
@@ -394,13 +388,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/mdoc_argv.c b/mdoc_argv.c
index 261890ca..9a43db9c 100644
--- a/mdoc_argv.c
+++ b/mdoc_argv.c
@@ -1,7 +1,7 @@
/* $Id$ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
- * Copyright (c) 2012, 2014-2017 Ingo Schwarze <schwarze@openbsd.org>
+ * Copyright (c) 2012, 2014-2018 Ingo Schwarze <schwarze@openbsd.org>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
@@ -144,7 +144,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 */
@@ -266,7 +266,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;
/*
@@ -290,7 +289,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;
@@ -368,7 +367,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;
}
}
@@ -422,7 +421,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/mdoc_html.c b/mdoc_html.c
index eba40485..7974605e 100644
--- a/mdoc_html.c
+++ b/mdoc_html.c
@@ -42,7 +42,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);
};
@@ -119,7 +119,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 */
@@ -241,7 +241,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;
/*
@@ -402,9 +401,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;
}
@@ -423,10 +423,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/mdoc_macro.c b/mdoc_macro.c
index 50d9159f..022dd032 100644
--- a/mdoc_macro.c
+++ b/mdoc_macro.c
@@ -1,7 +1,7 @@
/* $Id$ */
/*
* Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv>
- * Copyright (c) 2010, 2012-2017 Ingo Schwarze <schwarze@openbsd.org>
+ * Copyright (c) 2010, 2012-2018 Ingo Schwarze <schwarze@openbsd.org>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
@@ -60,7 +60,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 */
@@ -201,9 +201,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
@@ -221,7 +227,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]);
@@ -244,10 +250,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);
@@ -409,7 +415,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)
@@ -518,13 +524,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;
@@ -688,7 +694,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,
@@ -717,14 +723,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;
}
@@ -831,7 +837,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;
@@ -875,7 +882,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,
@@ -944,7 +951,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. */
@@ -969,7 +976,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:
@@ -1339,7 +1346,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;
@@ -1372,11 +1379,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);
@@ -1389,7 +1397,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/mdoc_man.c b/mdoc_man.c
index 2b7660dd..a7a85df2 100644
--- a/mdoc_man.c
+++ b/mdoc_man.c
@@ -36,7 +36,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 */
@@ -124,7 +124,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 */
@@ -137,7 +137,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 */
@@ -259,7 +259,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 */
@@ -290,6 +290,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)
{
@@ -640,9 +647,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;
@@ -680,15 +687,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))
@@ -736,7 +742,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);
@@ -749,7 +755,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);
@@ -774,7 +780,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(",");
@@ -820,7 +826,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/mdoc_markdown.c b/mdoc_markdown.c
index 2cb18420..d6310abb 100644
--- a/mdoc_markdown.c
+++ b/mdoc_markdown.c
@@ -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/mdoc_state.c b/mdoc_state.c
index d5428e2f..f96065ba 100644
--- a/mdoc_state.c
+++ b/mdoc_state.c
@@ -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/mdoc_term.c b/mdoc_term.c
index f61bbb1e..75ffd1d1 100644
--- a/mdoc_term.c
+++ b/mdoc_term.c
@@ -47,7 +47,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);
};
@@ -124,7 +124,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 */
@@ -246,7 +246,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;
@@ -310,9 +309,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;
@@ -370,10 +370,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;
}
@@ -391,9 +391,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/mdoc_validate.c b/mdoc_validate.c
index 47eb1508..54cf7418 100644
--- a/mdoc_validate.c
+++ b/mdoc_validate.c
@@ -1990,7 +1990,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)