diff options
author | Kristaps Dzonsons <kristaps@bsd.lv> | 2009-04-02 06:51:44 +0000 |
---|---|---|
committer | Kristaps Dzonsons <kristaps@bsd.lv> | 2009-04-02 06:51:44 +0000 |
commit | 8a03dc6dd4f8c96b6231d1f60da2bd65f437a8b4 (patch) | |
tree | 121b76378b915aba7ec64f61d34338b21358fd46 /man_hash.c | |
parent | e487e44b52bbc7bfdb77346cc9a44d1a7c825d2c (diff) | |
download | mandoc-8a03dc6dd4f8c96b6231d1f60da2bd65f437a8b4.tar.gz |
mdoc_tokhash -> hash
Initial man hashtab (BROKEN).
Diffstat (limited to 'man_hash.c')
-rw-r--r-- | man_hash.c | 53 |
1 files changed, 45 insertions, 8 deletions
@@ -16,17 +16,19 @@ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR * PERFORMANCE OF THIS SOFTWARE. */ +#include <assert.h> #include <stdlib.h> #include <string.h> #include "libman.h" + /* ARGUSED */ void man_hash_free(void *htab) { - /* Do nothing. */ + free(htab); } @@ -34,22 +36,57 @@ man_hash_free(void *htab) void * man_hash_alloc(void) { + int *htab; + int i, j, x; + + htab = calloc(26 * 4, sizeof(int)); + if (NULL == htab) + return(NULL); + + for (i = 1; i < MAN_MAX; i++) { + x = man_macronames[i][0]; + + assert((x >= 65 && x <= 90) || + (x >= 97 && x <= 122)); + + x -= (x <= 90) ? 65 : 97; + x *= 4; - /* Do nothing. */ - return(NULL); + for (j = 0; j < 4; j++) + if (0 == htab[x + j]) { + htab[x + j] = i; + break; + } + + assert(j < 4); + } + + return((void *)htab); } int man_hash_find(const void *arg, const char *tmp) { - int i; + int x, i, tok; + const int *htab; + + htab = (const int *)arg; + + if (0 == (x = tmp[0])) + return(MAN_MAX); + if ( ! ((x >= 65 && x <= 90) || (x >= 97 && x <= 122))) + return(MAN_MAX); - /* TODO */ + x -= (x <= 90) ? 65 : 97; + x *= 4; - for (i = 0; i < MAN_MAX; i++) - if (0 == strcmp(tmp, man_macronames[i])) - return(i); + for (i = 0; i < 4; i++) { + if (0 == (tok = htab[x + i])) + return(MAN_MAX); + if (0 == strcmp(tmp, man_macronames[tok])) + return(tok); + } return(MAN_MAX); } |