From 0cc9b20c15460213e488bf5e70963b941482f628 Mon Sep 17 00:00:00 2001 From: William Harrington Date: Tue, 14 Jan 2025 16:06:02 -0600 Subject: Add source. --- spo256/getidx.c | 98 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 spo256/getidx.c (limited to 'spo256/getidx.c') 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 +#include +#include +#include +#include +#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; +} -- cgit v1.2.3-54-g00ecf