aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/man_hash.c
diff options
context:
space:
mode:
authorKristaps Dzonsons <kristaps@bsd.lv>2009-04-02 06:51:44 +0000
committerKristaps Dzonsons <kristaps@bsd.lv>2009-04-02 06:51:44 +0000
commitf8fe5d9a147b378ab9cd53f2287730070ded22c2 (patch)
treeac8804842dcd211cf3ee64177bff113640075a2c /man_hash.c
parent4cd2606cca8b6f78a9d90bec6f4fa0c45c2dcd0f (diff)
downloadmandoc-f8fe5d9a147b378ab9cd53f2287730070ded22c2.tar.gz
mandoc-f8fe5d9a147b378ab9cd53f2287730070ded22c2.tar.zst
mandoc-f8fe5d9a147b378ab9cd53f2287730070ded22c2.zip
mdoc_tokhash -> hash
Initial man hashtab (BROKEN).
Diffstat (limited to 'man_hash.c')
-rw-r--r--man_hash.c55
1 files changed, 46 insertions, 9 deletions
diff --git a/man_hash.c b/man_hash.c
index 039ead53..9aaafb20 100644
--- a/man_hash.c
+++ b/man_hash.c
@@ -1,4 +1,4 @@
-/* $Id: man_hash.c,v 1.4 2009/03/31 13:50:19 kristaps Exp $ */
+/* $Id: man_hash.c,v 1.5 2009/04/02 06:51:44 kristaps Exp $ */
/*
* Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@openbsd.org>
*
@@ -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);
}