X-Git-Url: https://git.cameronkatri.com/mandoc.git/blobdiff_plain/d5899efe4a68c00b14f7b4e40042b60c86db4898..7310229a6bc4ea0f603478894a168e2aa4dff9e6:/man_hash.c diff --git a/man_hash.c b/man_hash.c index 86c5c40a..00e3c9d3 100644 --- a/man_hash.c +++ b/man_hash.c @@ -1,4 +1,4 @@ -/* $Id: man_hash.c,v 1.25 2011/07/24 18:15:14 kristaps Exp $ */ +/* $Id: man_hash.c,v 1.33 2015/04/19 14:00:19 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010 Kristaps Dzonsons * @@ -14,20 +14,17 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#ifdef HAVE_CONFIG_H #include "config.h" -#endif #include #include #include #include -#include #include +#include "roff.h" #include "man.h" -#include "mandoc.h" #include "libman.h" #define HASH_DEPTH 6 @@ -49,19 +46,16 @@ */ 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; - memset(table, UCHAR_MAX, sizeof(table)); + if (*table != '\0') + return; - assert(/* LINTED */ - MAN_MAX < UCHAR_MAX); + memset(table, UCHAR_MAX, sizeof(table)); for (i = 0; i < (int)MAN_MAX; i++) { x = man_macronames[i][0]; @@ -80,28 +74,27 @@ man_hash_init(void) } } - -enum mant +int man_hash_find(const char *tmp) { int x, y, i; - enum mant tok; + 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 = (enum mant)y; + tok = y; if (0 == strcmp(tmp, man_macronames[tok])) return(tok); } - return(MAN_MAX); + return(TOKEN_NONE); }