summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@openbsd.org>2015-04-19 14:00:19 +0000
committerIngo Schwarze <schwarze@openbsd.org>2015-04-19 14:00:19 +0000
commiteed5e7f1fb85805f1b324c5a4501ed30467ae2a0 (patch)
tree78f09c634d1cfc1b83be85f07be7ee909cbd6d30
parent344327def21ee64357a9cdf57c5352f1c5575708 (diff)
downloadmandoc-eed5e7f1fb85805f1b324c5a4501ed30467ae2a0.tar.gz
Decouple the token code for "no request or macro" from the individual
high-level parsers to allow further unification of functions that only need to recognize this code, but that don't care about different high-level macrosets beyond that.
-rw-r--r--man.c20
-rw-r--r--man_hash.c10
-rw-r--r--man_term.c2
-rw-r--r--man_validate.c2
-rw-r--r--mdoc.c19
-rw-r--r--mdoc_argv.c2
-rw-r--r--mdoc_hash.c10
-rw-r--r--mdoc_macro.c35
-rw-r--r--mdoc_validate.c4
-rw-r--r--read.c9
-rw-r--r--roff.h1
11 files changed, 57 insertions, 57 deletions
diff --git a/man.c b/man.c
index 660a8175..c018870a 100644
--- a/man.c
+++ b/man.c
@@ -100,7 +100,7 @@ man_word_alloc(struct roff_man *man, int line, int pos, const char *word)
{
struct roff_node *n;
- n = roff_node_alloc(man, line, pos, ROFFT_TEXT, MAN_MAX);
+ n = roff_node_alloc(man, line, pos, ROFFT_TEXT, TOKEN_NONE);
n->string = roff_strdup(man->roff, word);
roff_node_append(man, n);
man_valid_post(man);
@@ -127,7 +127,7 @@ man_addeqn(struct roff_man *man, const struct eqn *ep)
{
struct roff_node *n;
- n = roff_node_alloc(man, ep->ln, ep->pos, ROFFT_EQN, MAN_MAX);
+ n = roff_node_alloc(man, ep->ln, ep->pos, ROFFT_EQN, TOKEN_NONE);
n->eqn = ep;
if (ep->ln > man->last->line)
n->flags |= MAN_LINE;
@@ -141,8 +141,8 @@ man_addspan(struct roff_man *man, const struct tbl_span *sp)
{
struct roff_node *n;
- man_breakscope(man, MAN_MAX);
- n = roff_node_alloc(man, sp->line, 0, ROFFT_TBL, MAN_MAX);
+ man_breakscope(man, TOKEN_NONE);
+ n = roff_node_alloc(man, sp->line, 0, ROFFT_TBL, TOKEN_NONE);
n->span = sp;
roff_node_append(man, n);
man_valid_post(man);
@@ -261,9 +261,9 @@ man_pmacro(struct roff_man *man, int ln, char *buf, int offs)
mac[i] = '\0';
- tok = (i > 0 && i < 4) ? man_hash_find(mac) : MAN_MAX;
+ tok = (i > 0 && i < 4) ? man_hash_find(mac) : TOKEN_NONE;
- if (tok == MAN_MAX) {
+ if (tok == TOKEN_NONE) {
mandoc_msg(MANDOCERR_MACRO, man->parse,
ln, ppos, buf + ppos - 1);
return(1);
@@ -349,7 +349,7 @@ man_breakscope(struct roff_man *man, int tok)
* Delete the element that is being broken.
*/
- if (man->flags & MAN_ELINE && (tok == MAN_MAX ||
+ if (man->flags & MAN_ELINE && (tok == TOKEN_NONE ||
! (man_macros[tok].flags & MAN_NSCOPED))) {
n = man->last;
assert(n->type != ROFFT_TEXT);
@@ -358,7 +358,7 @@ man_breakscope(struct roff_man *man, int tok)
mandoc_vmsg(MANDOCERR_BLK_LINE, man->parse,
n->line, n->pos, "%s breaks %s",
- tok == MAN_MAX ? "TS" : man_macronames[tok],
+ tok == TOKEN_NONE ? "TS" : man_macronames[tok],
man_macronames[n->tok]);
roff_node_delete(man, n);
@@ -371,7 +371,7 @@ man_breakscope(struct roff_man *man, int tok)
* Delete the block that is being broken.
*/
- if (man->flags & MAN_BLINE && (tok == MAN_MAX ||
+ if (man->flags & MAN_BLINE && (tok == TOKEN_NONE ||
man_macros[tok].flags & MAN_BSCOPE)) {
n = man->last;
if (n->type == ROFFT_TEXT)
@@ -386,7 +386,7 @@ man_breakscope(struct roff_man *man, int tok)
mandoc_vmsg(MANDOCERR_BLK_LINE, man->parse,
n->line, n->pos, "%s breaks %s",
- tok == MAN_MAX ? "TS" : man_macronames[tok],
+ tok == TOKEN_NONE ? "TS" : man_macronames[tok],
man_macronames[n->tok]);
roff_node_delete(man, n);
diff --git a/man_hash.c b/man_hash.c
index a0aed934..f14ad18d 100644
--- a/man_hash.c
+++ b/man_hash.c
@@ -57,8 +57,6 @@ man_hash_init(void)
memset(table, UCHAR_MAX, sizeof(table));
- assert(MAN_MAX < UCHAR_MAX);
-
for (i = 0; i < (int)MAN_MAX; i++) {
x = man_macronames[i][0];
@@ -83,20 +81,20 @@ man_hash_find(const char *tmp)
int tok;
if ('\0' == (x = tmp[0]))
- return(MAN_MAX);
+ return(TOKEN_NONE);
if ( ! (isalpha((unsigned char)x)))
- return(MAN_MAX);
+ return(TOKEN_NONE);
HASH_ROW(x);
for (i = 0; i < HASH_DEPTH; i++) {
if (UCHAR_MAX == (y = table[x + i]))
- return(MAN_MAX);
+ return(TOKEN_NONE);
tok = y;
if (0 == strcmp(tmp, man_macronames[tok]))
return(tok);
}
- return(MAN_MAX);
+ return(TOKEN_NONE);
}
diff --git a/man_term.c b/man_term.c
index 5067d0ce..863bac22 100644
--- a/man_term.c
+++ b/man_term.c
@@ -756,7 +756,7 @@ pre_SS(DECL_ARGS)
do {
n = n->prev;
- } while (n != NULL && n->tok != MAN_MAX &&
+ } while (n != NULL && n->tok != TOKEN_NONE &&
termacts[n->tok].flags & MAN_NOTEXT);
if (n == NULL || (n->tok == MAN_SS && n->body->child == NULL))
break;
diff --git a/man_validate.c b/man_validate.c
index e1303f38..59baf88a 100644
--- a/man_validate.c
+++ b/man_validate.c
@@ -505,7 +505,7 @@ post_vs(CHKARGS)
"%s after %s", man_macronames[n->tok],
man_macronames[n->parent->tok]);
/* FALLTHROUGH */
- case MAN_MAX:
+ case TOKEN_NONE:
/*
* Don't warn about this because it occurs in pod2man
* and would cause considerable (unfixable) warnage.
diff --git a/mdoc.c b/mdoc.c
index 3f2e2473..fe257b00 100644
--- a/mdoc.c
+++ b/mdoc.c
@@ -36,6 +36,7 @@
#include "libmdoc.h"
const char *const __mdoc_macronames[MDOC_MAX + 1] = {
+ "text",
"Ap", "Dd", "Dt", "Os",
"Sh", "Ss", "Pp", "D1",
"Dl", "Bd", "Ed", "Bl",
@@ -66,8 +67,8 @@ const char *const __mdoc_macronames[MDOC_MAX + 1] = {
"Lk", "Mt", "Brq", "Bro",
"Brc", "%C", "Es", "En",
"Dx", "%Q", "br", "sp",
- "%U", "Ta", "ll", "text",
- };
+ "%U", "Ta", "ll",
+};
const char *const __mdoc_argnames[MDOC_ARG_MAX] = {
"split", "nosplit", "ragged",
@@ -81,7 +82,7 @@ const char *const __mdoc_argnames[MDOC_ARG_MAX] = {
"symbolic", "nested", "centered"
};
-const char * const *mdoc_macronames = __mdoc_macronames;
+const char * const *mdoc_macronames = __mdoc_macronames + 1;
const char * const *mdoc_argnames = __mdoc_argnames;
static int mdoc_ptext(struct roff_man *, int, char *, int);
@@ -100,7 +101,7 @@ mdoc_addeqn(struct roff_man *mdoc, const struct eqn *ep)
{
struct roff_node *n;
- n = roff_node_alloc(mdoc, ep->ln, ep->pos, ROFFT_EQN, MDOC_MAX);
+ n = roff_node_alloc(mdoc, ep->ln, ep->pos, ROFFT_EQN, TOKEN_NONE);
n->eqn = ep;
if (ep->ln > mdoc->last->line)
n->flags |= MDOC_LINE;
@@ -113,7 +114,7 @@ mdoc_addspan(struct roff_man *mdoc, const struct tbl_span *sp)
{
struct roff_node *n;
- n = roff_node_alloc(mdoc, sp->line, 0, ROFFT_TBL, MDOC_MAX);
+ n = roff_node_alloc(mdoc, sp->line, 0, ROFFT_TBL, TOKEN_NONE);
n->span = sp;
roff_node_append(mdoc, n);
mdoc_valid_post(mdoc);
@@ -150,7 +151,7 @@ mdoc_parseln(struct roff_man *mdoc, int ln, char *buf, int offs)
void
mdoc_macro(MACRO_PROT_ARGS)
{
- assert(tok < MDOC_MAX);
+ assert(tok > TOKEN_NONE && tok < MDOC_MAX);
if (mdoc->flags & MDOC_PBODY) {
if (tok == MDOC_Dt) {
@@ -258,7 +259,7 @@ mdoc_word_alloc(struct roff_man *mdoc, int line, int pos, const char *p)
{
struct roff_node *n;
- n = roff_node_alloc(mdoc, line, pos, ROFFT_TEXT, MDOC_MAX);
+ n = roff_node_alloc(mdoc, line, pos, ROFFT_TEXT, TOKEN_NONE);
n->string = roff_strdup(mdoc->roff, p);
roff_node_append(mdoc, n);
mdoc_valid_post(mdoc);
@@ -430,9 +431,9 @@ mdoc_pmacro(struct roff_man *mdoc, int ln, char *buf, int offs)
mac[i] = '\0';
- tok = (i > 1 && i < 4) ? mdoc_hash_find(mac) : MDOC_MAX;
+ tok = (i > 1 && i < 4) ? mdoc_hash_find(mac) : TOKEN_NONE;
- if (tok == MDOC_MAX) {
+ if (tok == TOKEN_NONE) {
mandoc_msg(MANDOCERR_MACRO, mdoc->parse,
ln, sv, buf + sv - 1);
return(1);
diff --git a/mdoc_argv.c b/mdoc_argv.c
index 682dcd02..d7b75057 100644
--- a/mdoc_argv.c
+++ b/mdoc_argv.c
@@ -422,7 +422,7 @@ mdoc_args(struct roff_man *mdoc, int line, int *pos,
if (v == NULL)
v = &v_local;
- fl = tok == MDOC_MAX ? ARGSFL_NONE : mdocargs[tok].flags;
+ fl = tok == TOKEN_NONE ? ARGSFL_NONE : mdocargs[tok].flags;
if (tok != MDOC_It)
return(args(mdoc, line, pos, buf, fl, v));
diff --git a/mdoc_hash.c b/mdoc_hash.c
index 7f7a47b1..8543e38c 100644
--- a/mdoc_hash.c
+++ b/mdoc_hash.c
@@ -67,19 +67,19 @@ mdoc_hash_find(const char *p)
int major, i, j;
if (0 == p[0])
- return(MDOC_MAX);
+ return(TOKEN_NONE);
if ( ! isalpha((unsigned char)p[0]) && '%' != p[0])
- return(MDOC_MAX);
+ return(TOKEN_NONE);
if (isalpha((unsigned char)p[1]))
major = 12 * (tolower((unsigned char)p[1]) - 97);
else if ('1' == p[1])
major = 12 * 26;
else
- return(MDOC_MAX);
+ return(TOKEN_NONE);
if (p[2] && p[3])
- return(MDOC_MAX);
+ return(TOKEN_NONE);
for (j = 0; j < 12; j++) {
if (UCHAR_MAX == (i = table[major + j]))
@@ -88,5 +88,5 @@ mdoc_hash_find(const char *p)
return(i);
}
- return(MDOC_MAX);
+ return(TOKEN_NONE);
}
diff --git a/mdoc_macro.c b/mdoc_macro.c
index e904a6eb..fcfd517c 100644
--- a/mdoc_macro.c
+++ b/mdoc_macro.c
@@ -232,16 +232,16 @@ mdoc_macroend(struct roff_man *mdoc)
/*
* Look up the macro at *p called by "from",
- * or as a line macro if from == MDOC_MAX.
+ * or as a line macro if from == TOKEN_NONE.
*/
static int
lookup(struct roff_man *mdoc, int from, int line, int ppos, const char *p)
{
int res;
- if (from == MDOC_MAX || mdoc_macros[from].flags & MDOC_PARSED) {
+ if (from == TOKEN_NONE || mdoc_macros[from].flags & MDOC_PARSED) {
res = mdoc_hash_find(p);
- if (res != MDOC_MAX) {
+ if (res != TOKEN_NONE) {
if (mdoc_macros[res].flags & MDOC_CALLABLE)
return(res);
if (res != MDOC_br && res != MDOC_sp && res != MDOC_ll)
@@ -249,7 +249,7 @@ lookup(struct roff_man *mdoc, int from, int line, int ppos, const char *p)
mdoc->parse, line, ppos, p);
}
}
- return(MDOC_MAX);
+ return(TOKEN_NONE);
}
/*
@@ -465,7 +465,8 @@ append_delims(struct roff_man *mdoc, int line, int *pos, char *buf)
for (;;) {
la = *pos;
- if (mdoc_args(mdoc, line, pos, buf, MDOC_MAX, &p) == ARGS_EOLN)
+ if (mdoc_args(mdoc, line, pos, buf, TOKEN_NONE, &p) ==
+ ARGS_EOLN)
break;
dword(mdoc, line, la, p, DELIM_MAX, 1);
@@ -498,21 +499,21 @@ macro_or_word(MACRO_PROT_ARGS, int parsed)
int ntok;
p = buf + ppos;
- ntok = MDOC_MAX;
+ ntok = TOKEN_NONE;
if (*p == '"')
p++;
else if (parsed && ! (mdoc->flags & MDOC_PHRASELIT))
ntok = lookup(mdoc, tok, line, ppos, p);
- if (ntok == MDOC_MAX) {
- dword(mdoc, line, ppos, p, DELIM_MAX, tok == MDOC_MAX ||
+ if (ntok == TOKEN_NONE) {
+ dword(mdoc, line, ppos, p, DELIM_MAX, tok == TOKEN_NONE ||
mdoc_macros[tok].flags & MDOC_JOIN);
return(0);
} else {
if (mdoc_macros[tok].fp == in_line_eoln)
rew_elem(mdoc, tok);
mdoc_macro(mdoc, ntok, line, ppos, pos, buf);
- if (tok == MDOC_MAX)
+ if (tok == TOKEN_NONE)
append_delims(mdoc, line, pos, buf);
return(1);
}
@@ -677,10 +678,10 @@ blk_exp_close(MACRO_PROT_ARGS)
if (ac == ARGS_PUNCT || ac == ARGS_EOLN)
break;
- ntok = ac == ARGS_QWORD ? MDOC_MAX :
+ ntok = ac == ARGS_QWORD ? TOKEN_NONE :
lookup(mdoc, tok, line, lastarg, p);
- if (ntok == MDOC_MAX) {
+ if (ntok == TOKEN_NONE) {
dword(mdoc, line, lastarg, p, DELIM_MAX,
MDOC_JOIN & mdoc_macros[tok].flags);
continue;
@@ -781,7 +782,7 @@ in_line(MACRO_PROT_ARGS)
}
ntok = (ac == ARGS_QWORD || (tok == MDOC_Fn && !cnt)) ?
- MDOC_MAX : lookup(mdoc, tok, line, la, p);
+ TOKEN_NONE : lookup(mdoc, tok, line, la, p);
/*
* In this case, we've located a submacro and must
@@ -790,7 +791,7 @@ in_line(MACRO_PROT_ARGS)
* or raise a warning.
*/
- if (ntok != MDOC_MAX) {
+ if (ntok != TOKEN_NONE) {
if (scope)
rew_elem(mdoc, tok);
if (nc && ! cnt) {
@@ -1107,7 +1108,7 @@ blk_full(MACRO_PROT_ARGS)
mdoc->flags |= MDOC_PPHRASE;
if (ac == ARGS_PEND && lac == ARGS_PPHRASE)
mdoc->flags |= MDOC_PPHRASE;
- parse_rest(mdoc, MDOC_MAX, line, &la, buf);
+ parse_rest(mdoc, TOKEN_NONE, line, &la, buf);
mdoc->flags &= ~MDOC_PPHRASE;
continue;
}
@@ -1337,9 +1338,9 @@ in_line_argn(MACRO_PROT_ARGS)
}
ntok = (ac == ARGS_QWORD || (tok == MDOC_Pf && state == 0)) ?
- MDOC_MAX : lookup(mdoc, tok, line, la, p);
+ TOKEN_NONE : lookup(mdoc, tok, line, la, p);
- if (ntok != MDOC_MAX) {
+ if (ntok != TOKEN_NONE) {
if (state >= 0) {
rew_elem(mdoc, tok);
state = -2;
@@ -1473,5 +1474,5 @@ phrase_ta(MACRO_PROT_ARGS)
rew_last(mdoc, body);
roff_body_alloc(mdoc, line, ppos, MDOC_It);
- parse_rest(mdoc, MDOC_MAX, line, pos, buf);
+ parse_rest(mdoc, TOKEN_NONE, line, pos, buf);
}
diff --git a/mdoc_validate.c b/mdoc_validate.c
index c65f4f15..18c606e1 100644
--- a/mdoc_validate.c
+++ b/mdoc_validate.c
@@ -1269,7 +1269,7 @@ rewrite_macro2len(char **arg)
return;
else if ( ! strcmp(*arg, "Ds"))
width = 6;
- else if ((tok = mdoc_hash_find(*arg)) == MDOC_MAX)
+ else if ((tok = mdoc_hash_find(*arg)) == TOKEN_NONE)
return;
else
width = macro2len(tok);
@@ -1765,7 +1765,7 @@ post_sh_name(POST_ARGS)
mandoc_msg(MANDOCERR_NAMESEC_ND,
mdoc->parse, n->line, n->pos, NULL);
break;
- case MDOC_MAX:
+ case TOKEN_NONE:
if (hasnm)
break;
/* FALLTHROUGH */
diff --git a/read.c b/read.c
index 89f8aec3..002f34d8 100644
--- a/read.c
+++ b/read.c
@@ -293,17 +293,17 @@ choose_parser(struct mparse *curp)
curp->man = roff_man_alloc(curp->roff, curp, curp->defos,
curp->options & MPARSE_QUICK ? 1 : 0);
curp->man->macroset = MACROSET_MAN;
- curp->man->first->tok = MDOC_MAX;
+ curp->man->first->tok = TOKEN_NONE;
}
if (format == MPARSE_MDOC) {
mdoc_hash_init();
curp->man->macroset = MACROSET_MDOC;
- curp->man->first->tok = MDOC_MAX;
+ curp->man->first->tok = TOKEN_NONE;
} else {
man_hash_init();
curp->man->macroset = MACROSET_MAN;
- curp->man->first->tok = MAN_MAX;
+ curp->man->first->tok = TOKEN_NONE;
}
}
@@ -893,12 +893,11 @@ mparse_alloc(int options, enum mandoclevel wlevel, mandocmsg mmsg,
if (curp->options & MPARSE_MDOC) {
mdoc_hash_init();
curp->man->macroset = MACROSET_MDOC;
- curp->man->first->tok = MDOC_MAX;
} else if (curp->options & MPARSE_MAN) {
man_hash_init();
curp->man->macroset = MACROSET_MAN;
- curp->man->first->tok = MAN_MAX;
}
+ curp->man->first->tok = TOKEN_NONE;
return(curp);
}
diff --git a/roff.h b/roff.h
index fd73ad73..cf29d6d1 100644
--- a/roff.h
+++ b/roff.h
@@ -97,6 +97,7 @@ struct roff_node {
int line; /* Input file line number. */
int pos; /* Input file column number. */
int tok; /* Request or macro ID. */
+#define TOKEN_NONE (-1) /* No request or macro. */
int flags;
#define MDOC_VALID (1 << 0) /* Has been validated. */
#define MDOC_ENDED (1 << 1) /* Gone past body end mark. */