#include "dat.h" #include "fn.h" /* * Fills out[] with up to max candidates for key: the space-separated words * of the entry, minus the key itself except in the emoji dictionary, where * a query may name its own answer. */ int dictlookup(Lang *l, Str *key, Str *out, int max) { char *p, *e, *sp; Str tmp; int n, vlen; if(l == nil || key->n == 0 || trielookup(l->dict, key, &p, &vlen) != TrieExact) return 0; n = 0; e = p + vlen; while(n < max && p < e){ while(p < e && *p == ' ') p++; sp = p; while(p < e && *p != ' ') p++; if(sinit(&tmp, sp, p - sp) && tmp.n > 0 && (l->lang == LangEMOJI || scmp(&tmp, key) != 0)) out[n++] = tmp; } return n; } static Trie* langopen(char *dir, char *name, char *ext) { char *path; Trie *t; path = smprint("%s/%s.%s", dir, name, ext); if(path == nil) die("out of memory"); t = trieopen(path); free(path); return t; } void langinit(char *dir) { Lang *l; for(l = langs; l < langs + nlang; l++){ if(l->mapname != nil) l->map = langopen(dir, l->mapname, "map"); if(l->dictname != nil) l->dict = langopen(dir, l->dictname, "dict"); } }