diff options
author | William Harrington <kb0iic@berzerkula.org> | 2025-01-14 16:06:02 -0600 |
---|---|---|
committer | William Harrington <kb0iic@berzerkula.org> | 2025-01-14 16:06:02 -0600 |
commit | 0cc9b20c15460213e488bf5e70963b941482f628 (patch) | |
tree | bb0143245583ec846630f39bfa2258dba640ccd7 /spo256/getidx.c | |
parent | 0e084ade5069756d487b5c948c48b777e37c00c9 (diff) |
Add source.
Diffstat (limited to 'spo256/getidx.c')
-rw-r--r-- | spo256/getidx.c | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/spo256/getidx.c b/spo256/getidx.c new file mode 100644 index 0000000..70a730c --- /dev/null +++ b/spo256/getidx.c @@ -0,0 +1,98 @@ +/* + * Build word and abbreviation index in memory from .conf. + * $Id: getidx.c 1.2 Mon, 24 Mar 1997 12:25:37 -0500 dyfet $ + * Copyright (c) 1997 by Tycho Softworks. + * For conditions of distribution and reuse see product license. + */ + +#include <other/string.h> +#include <other/config.h> +#include <std/files.h> +#include <std/process.h> +#include <other/memory.h> +#include "speak.h" + +MEMPOOL *mem; +IDX **widx, **aidx; + +static int key(uchar *str) +{ + unsigned int k = 0; + int len = strlen((char *)str); + + while(*str) + { + k = (k * 7) | (*str & 0x1f); + ++str; + } + + k |= len; + + return (k % KEYSIZE); +} + +void getidx(CONFIG *cfg) +{ + int i; + char *p, *q; + IDX *new; + + mem = mempool(16384, 16); + + widx = (IDX **)memreq(mem, sizeof(IDX *) * KEYSIZE); + aidx = (IDX **)memreq(mem, sizeof(IDX *) * KEYSIZE); + + + for(i = 0; i < KEYSIZE; ++i) + widx[i] = aidx[i] = NULL; + + seek_config(cfg, "words"); + while(NULL != (p = read_config(cfg))) + { + q = strchr(p, '='); + if(!q) + continue; + + *(q++) = 0; + p = strtrim(p, __SPACES); + q = strtrim(q, __SPACES); + i = key((uchar *)p); + new = memlreq(mem, sizeof(IDX)); + new->word_link = widx[i]; + widx[i] = new; + new->word_key = strreq(mem, p); + new->word_spo = strreq(mem, q); + } + seek_config(cfg, "abbrev"); + while(NULL != (p = read_config(cfg))) + { + q = strchr(p, '='); + if(!q) + continue; + + *(q++) = 0; + p = strtrim(p, __SPACES); + q = strtrim(q, __SPACES); + i = key((uchar *)p); + new = memlreq(mem, sizeof(IDX)); + new->word_link = aidx[i]; + aidx[i] = new; + new->word_key = strreq(mem, p); + new->word_spo = strreq(mem, q); + } +} + +char *find(IDX **table, char *str) +{ + IDX *next = table[key((uchar *)str)]; + + + while(next) + { + if(!stricmp(str, next->word_key)) + return next->word_spo; + + next = next->word_link; + } + return NULL; +} |