/* * 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; }