* mdocml: Decouple the token code for "no request or macro" from the
@ 2015-04-19 14:00 schwarze
0 siblings, 0 replies; only message in thread
From: schwarze @ 2015-04-19 14:00 UTC (permalink / raw)
To: source
Log Message:
-----------
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.
Modified Files:
--------------
mdocml:
man.c
man_hash.c
man_term.c
man_validate.c
mdoc.c
mdoc_argv.c
mdoc_hash.c
mdoc_macro.c
mdoc_validate.c
read.c
roff.h
Revision Data
-------------
Index: mdoc_validate.c
===================================================================
RCS file: /home/cvs/mdocml/mdocml/mdoc_validate.c,v
retrieving revision 1.287
retrieving revision 1.288
diff -Lmdoc_validate.c -Lmdoc_validate.c -u -p -r1.287 -r1.288
--- mdoc_validate.c
+++ 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 */
Index: man_validate.c
===================================================================
RCS file: /home/cvs/mdocml/mdocml/man_validate.c,v
retrieving revision 1.118
retrieving revision 1.119
diff -Lman_validate.c -Lman_validate.c -u -p -r1.118 -r1.119
--- man_validate.c
+++ 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.
Index: man_term.c
===================================================================
RCS file: /home/cvs/mdocml/mdocml/man_term.c,v
retrieving revision 1.181
retrieving revision 1.182
diff -Lman_term.c -Lman_term.c -u -p -r1.181 -r1.182
--- man_term.c
+++ 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;
Index: mdoc_macro.c
===================================================================
RCS file: /home/cvs/mdocml/mdocml/mdoc_macro.c,v
retrieving revision 1.190
retrieving revision 1.191
diff -Lmdoc_macro.c -Lmdoc_macro.c -u -p -r1.190 -r1.191
--- mdoc_macro.c
+++ 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,
mdoc->parse, line, ppos, p);
}
}
- return(MDOC_MAX);
+ return(TOKEN_NONE);
}
/*
@@ -465,7 +465,8 @@ append_delims(struct roff_man *mdoc, int
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 parse
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);
}
Index: roff.h
===================================================================
RCS file: /home/cvs/mdocml/mdocml/roff.h,v
retrieving revision 1.32
retrieving revision 1.33
diff -Lroff.h -Lroff.h -u -p -r1.32 -r1.33
--- roff.h
+++ 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. */
Index: man.c
===================================================================
RCS file: /home/cvs/mdocml/mdocml/man.c,v
retrieving revision 1.158
retrieving revision 1.159
diff -Lman.c -Lman.c -u -p -r1.158 -r1.159
--- man.c
+++ man.c
@@ -100,7 +100,7 @@ man_word_alloc(struct roff_man *man, int
{
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 s
{
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 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,
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
* 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
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
* 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
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);
Index: mdoc.c
===================================================================
RCS file: /home/cvs/mdocml/mdocml/mdoc.c,v
retrieving revision 1.247
retrieving revision 1.248
diff -Lmdoc.c -Lmdoc.c -u -p -r1.247 -r1.248
--- mdoc.c
+++ 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
"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_A
"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 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, cons
{
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
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, i
{
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 l
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);
Index: man_hash.c
===================================================================
RCS file: /home/cvs/mdocml/mdocml/man_hash.c,v
retrieving revision 1.32
retrieving revision 1.33
diff -Lman_hash.c -Lman_hash.c -u -p -r1.32 -r1.33
--- man_hash.c
+++ 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);
}
Index: mdoc_argv.c
===================================================================
RCS file: /home/cvs/mdocml/mdocml/mdoc_argv.c,v
retrieving revision 1.103
retrieving revision 1.104
diff -Lmdoc_argv.c -Lmdoc_argv.c -u -p -r1.103 -r1.104
--- mdoc_argv.c
+++ mdoc_argv.c
@@ -422,7 +422,7 @@ mdoc_args(struct roff_man *mdoc, int lin
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));
Index: read.c
===================================================================
RCS file: /home/cvs/mdocml/mdocml/read.c,v
retrieving revision 1.137
retrieving revision 1.138
diff -Lread.c -Lread.c -u -p -r1.137 -r1.138
--- read.c
+++ 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 mandoclev
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);
}
Index: mdoc_hash.c
===================================================================
RCS file: /home/cvs/mdocml/mdocml/mdoc_hash.c,v
retrieving revision 1.24
retrieving revision 1.25
diff -Lmdoc_hash.c -Lmdoc_hash.c -u -p -r1.24 -r1.25
--- mdoc_hash.c
+++ 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);
}
--
To unsubscribe send an email to source+unsubscribe@mdocml.bsd.lv
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2015-04-19 14:00 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-04-19 14:00 mdocml: Decouple the token code for "no request or macro" from the schwarze
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).