fix core text and map ownership

This commit is contained in:
2026-08-11 19:32:58 +09:00
parent b63122dd14
commit e70278a3d2
6 changed files with 99 additions and 31 deletions

18
dict.c
View File

@@ -1,7 +1,7 @@
#include "dat.h"
#include "fn.h"
static void
void
dictlookup(Dictreq *req, Dictres *res)
{
Lang *l;
@@ -10,6 +10,7 @@ dictlookup(Dictreq *req, Dictres *res)
char *p, *e, *sp;
Str tmp;
res->key = req->pre;
res->nkouho = 0;
if(req->key.n == 0)
return;
@@ -23,6 +24,10 @@ dictlookup(Dictreq *req, Dictres *res)
p = n->val;
e = p + n->vlen;
while(res->nkouho < Maxkouho && p < e){
while(p < e && *p == ' ')
p++;
if(p == e)
break;
sp = p;
while(p < e && *p != ' ')
p++;
@@ -47,7 +52,6 @@ dictthread(void*)
while(channbrecv(dictreqc, &req) > 0)
;
dictlookup(&req, &res);
res.key = req.pre;
chansend(dictresc, &res);
}
}
@@ -57,16 +61,18 @@ dictopen(char *path)
{
Hmap *h;
Biobuf *b;
Str key, val;
Str key;
char *line, *tab;
int len;
b = Bopen(path, OREAD);
if(b == nil)
die("can't open: %s", path);
h = hmapalloc(4096, 0);
h = hmapalloc(4096);
while((line = Brdstr(b, '\n', 1)) != nil){
len = strlen(line);
if(len > 0 && line[len-1] == '\r')
line[--len] = '\0';
if(len == 0 || line[0] == ';'){
free(line);
continue;
@@ -78,8 +84,7 @@ dictopen(char *path)
}
*tab = '\0';
sinit(&key, line, tab - line);
sinit(&val, tab+1, len - (tab - line) - 1);
hmapset(&h, &key, &val);
hmapset(&h, &key, tab+1, len - (tab - line) - 1);
free(line);
}
Bterm(b);
@@ -99,4 +104,3 @@ dictinit(char *dir)
langs[i].dict = dictopen(path);
}
}