diff options
author | Ingo Schwarze <schwarze@openbsd.org> | 2015-04-18 17:01:58 +0000 |
---|---|---|
committer | Ingo Schwarze <schwarze@openbsd.org> | 2015-04-18 17:01:58 +0000 |
commit | 4534f390e036ac23ee5e8f0373ffb9f4d785a17d (patch) | |
tree | ccd3380730c698bd52e2e5ea394772f7ac6e1e41 | |
parent | 19dfb5cab356150bf46d159f43ead732a6a6ade5 (diff) | |
download | mandoc-4534f390e036ac23ee5e8f0373ffb9f4d785a17d.tar.gz |
Move mdoc_hash_init() and man_hash_init() to libmandoc.h
and call them from mparse_alloc() and choose_parser(),
preparing unified allocation of struct roff_man.
-rw-r--r-- | libman.h | 1 | ||||
-rw-r--r-- | libmandoc.h | 2 | ||||
-rw-r--r-- | libmdoc.h | 1 | ||||
-rw-r--r-- | man.c | 2 | ||||
-rw-r--r-- | man_hash.c | 7 | ||||
-rw-r--r-- | mdoc.c | 1 | ||||
-rw-r--r-- | mdoc_hash.c | 7 | ||||
-rw-r--r-- | read.c | 10 |
8 files changed, 16 insertions, 15 deletions
@@ -43,7 +43,6 @@ void man_head_alloc(struct roff_man *, int, int, int); void man_body_alloc(struct roff_man *, int, int, int); void man_elem_alloc(struct roff_man *, int, int, int); void man_node_delete(struct roff_man *, struct roff_node *); -void man_hash_init(void); int man_hash_find(const char *); void man_macroend(struct roff_man *); void man_valid_post(struct roff_man *); diff --git a/libmandoc.h b/libmandoc.h index 779e3c11..c46fa691 100644 --- a/libmandoc.h +++ b/libmandoc.h @@ -58,6 +58,7 @@ void mdoc_free(struct roff_man *); struct roff_man *mdoc_alloc(struct roff *, struct mparse *, const char *, int); void mdoc_reset(struct roff_man *); +void mdoc_hash_init(void); int mdoc_parseln(struct roff_man *, int, char *, int); void mdoc_endparse(struct roff_man *); void mdoc_addspan(struct roff_man *, const struct tbl_span *); @@ -67,6 +68,7 @@ void man_free(struct roff_man *); struct roff_man *man_alloc(struct roff *, struct mparse *, const char *, int); void man_reset(struct roff_man *); +void man_hash_init(void); int man_parseln(struct roff_man *, int, char *, int); void man_endparse(struct roff_man *); void man_addspan(struct roff_man *, const struct tbl_span *); @@ -80,7 +80,6 @@ struct roff_node *mdoc_endbody_alloc(struct roff_man *, int, int, int, struct roff_node *, enum mdoc_endbody); void mdoc_node_delete(struct roff_man *, struct roff_node *); void mdoc_node_relink(struct roff_man *, struct roff_node *); -void mdoc_hash_init(void); int mdoc_hash_find(const char *); const char *mdoc_a2att(const char *); const char *mdoc_a2lib(const char *); @@ -101,8 +101,6 @@ man_alloc(struct roff *roff, struct mparse *parse, struct roff_man *p; p = mandoc_calloc(1, sizeof(*p)); - - man_hash_init(); p->parse = parse; p->defos = defos; p->quick = quick; @@ -47,15 +47,14 @@ static unsigned char table[26 * HASH_DEPTH]; -/* - * XXX - this hash has global scope, so if intended for use as a library - * with multiple callers, it will need re-invocation protection. - */ void man_hash_init(void) { int i, j, x; + if (*table != '\0') + return; + memset(table, UCHAR_MAX, sizeof(table)); assert(MAN_MAX < UCHAR_MAX); @@ -187,7 +187,6 @@ mdoc_alloc(struct roff *roff, struct mparse *parse, p->quick = quick; p->roff = roff; - mdoc_hash_init(); mdoc_alloc1(p); return(p); } diff --git a/mdoc_hash.c b/mdoc_hash.c index 2615c764..7f7a47b1 100644 --- a/mdoc_hash.c +++ b/mdoc_hash.c @@ -32,16 +32,15 @@ static unsigned char table[27 * 12]; -/* - * XXX - this hash has global scope, so if intended for use as a library - * with multiple callers, it will need re-invocation protection. - */ void mdoc_hash_init(void) { int i, j, major; const char *p; + if (*table != '\0') + return; + memset(table, UCHAR_MAX, sizeof(table)); for (i = 0; i < (int)MDOC_MAX; i++) { @@ -296,6 +296,7 @@ choose_parser(struct mparse *curp) MPARSE_QUICK & curp->options ? 1 : 0); else curp->man->macroset = MACROSET_MDOC; + mdoc_hash_init(); return; } @@ -307,6 +308,7 @@ choose_parser(struct mparse *curp) MPARSE_QUICK & curp->options ? 1 : 0); else curp->man->macroset = MACROSET_MAN; + man_hash_init(); } /* @@ -890,14 +892,18 @@ mparse_alloc(int options, enum mandoclevel wlevel, mandocmsg mmsg, curp->mchars = mchars; curp->roff = roff_alloc(curp, curp->mchars, options); - if (curp->options & MPARSE_MDOC) + if (curp->options & MPARSE_MDOC) { curp->man = mdoc_alloc( curp->roff, curp, curp->defos, curp->options & MPARSE_QUICK ? 1 : 0); - if (curp->options & MPARSE_MAN) + mdoc_hash_init(); + } + if (curp->options & MPARSE_MAN) { curp->man = man_alloc( curp->roff, curp, curp->defos, curp->options & MPARSE_QUICK ? 1 : 0); + man_hash_init(); + } return(curp); } |