ref: 3ce0347ef33d00b70573faca983f44c07b323b0e
parent: 556618eb07d1ac6e2c629a60acd53c45d53261be
author: Jacob Moody <[email protected]>
date: Sat Sep 16 20:51:26 EDT 2023
ktrans: more tests, telex rewrite, small chinese fix
--- a/sys/src/cmd/ktrans/main.c
+++ b/sys/src/cmd/ktrans/main.c
@@ -536,6 +536,8 @@
if(selected >= 0){
resetstr(&okuri, &last, &line, nil);
+ if(dict == zidian)
+ line.p = pushutf(line.p, strend(&line), p, 1);
selected = -1;
send(selectch, &selected);
}
@@ -551,43 +553,31 @@
telexlkup(Str *line)
{
Map lkup;
- char buf[UTFmax*3], *p, *e;
+ char buf[UTFmax*3], *p, *e, *dot;
Str out;
int n, ln;
-Again:
- ln = utflen(line->b);
- p = pushutf(buf, buf+sizeof buf, line->b, 1);
- n = p-buf;
+ for(dot = line->b; (ln = utflen(dot)) >= 2; dot += n){
+ p = pushutf(buf, buf+sizeof buf, dot, 1);
+ n = p-buf;
+
+ if(hmapget(telex, buf, &lkup) < 0)
+ continue;
+
+ e = peekstr(line->p, line->b);
+ pushutf(p, buf+sizeof buf, e, 1);
+ if(hmapget(telex, buf, &lkup) < 0)
+ continue;
+
+ out.p = pushutf(out.b, strend(&out), lkup.kana, 0);
+ out.p = pushutf(out.p, strend(&out), dot+n, 0);
+ popstr(&out);
- if(hmapget(telex, buf, &lkup) < 0){
- resetstr(line, nil);
- return;
- }
-
- if(utflen(line->b) < 2)
- return;
-
- e = peekstr(line->p, line->b);
- pushutf(p, buf+sizeof buf, e, 1);
- if(hmapget(telex, buf, &lkup) < 0){
- /* not correct; matches should be allowed to span vowels */
- if(hmapget(telex, buf+n, &lkup) == 0)
- line->p = pushutf(line->b, strend(line), buf+n, 0);
- return;
- }
-
- out.p = pushutf(out.b, strend(&out), lkup.kana, 0);
- out.p = pushutf(out.p, strend(&out), line->b+n, 0);
- popstr(&out);
-
- if(ln > 0)
emitutf(output, backspace, ln);
- emitutf(output, out.b, 0);
- line->p = pushutf(line->b, strend(line), out.b, 0);
- if(utflen(lkup.kana) == 2)
+ emitutf(output, out.b, 0);
+ line->p = pushutf(line->b, strend(line), out.b, 0);
return;
- goto Again;
+ }
}
static void
@@ -847,11 +837,13 @@
if((jishoname = getenv("jisho")) == nil)
jishoname = "/lib/ktrans/kanji.dict";
- jisho = opendict(nil, jishoname);
+ if((jisho = opendict(nil, jishoname)) == nil)
+ sysfatal("failed to open jisho: %r");
if((zidianname = getenv("zidian")) == nil)
zidianname = "/lib/ktrans/wubi.dict";
- zidian = opendict(nil, zidianname);
+ if((zidian = opendict(nil, zidianname)) == nil)
+ sysfatal("failed to open zidian: %r");
natural = nil;
for(i = 0; i < nelem(inittab); i++){
--- a/sys/src/cmd/ktrans/mkfile
+++ b/sys/src/cmd/ktrans/mkfile
@@ -3,6 +3,8 @@
BIN=/$objtype/bin
TARG=ktrans
HFILES=hash.h
+TESTDEP=$O.test
+CLEANFILES=$O.test
OFILES=\
hash.$O\
main.$O\
@@ -11,3 +13,6 @@
$O.test: test.$O
$LD $LDFLAGS -o $target $prereq
+
+test:V: $O.out $O.test
+ $O.test $O.out
--- a/sys/src/cmd/ktrans/test.c
+++ b/sys/src/cmd/ktrans/test.c
@@ -16,6 +16,33 @@
"watashiHAmainichi35funijouaruIte,saraNI10fundenshaNInoTtegakkouNIkayoImasu.\nkenkouNOijiNImoyakuDAtteimasuga,nakanakatanoshiImonodesu.\n",
L"私は毎日35分以上歩いて、更に10分電車に乗って学校に通います。\n健康の維持にも役だっていますが、なかなかたのしいものです。\n",
+
+ "wonengtunxiabolierbushangshenti",
+ L"我能吞下玻璃而不伤身体",
+
+ "wodeqidianchuanzhuangmanlemanyu",
+ L"我的气垫船装满了鳗鱼",
+
+ "renrenshengerziyouzaizunyanhequanlishangyilvpingdeng",
+ L"人人生而自由在尊严和权利上一律平等",
+
+ "ngang", L"ngang",
+ "sawcs", L"sắc",
+ "ngax", L"ngã",
+ "nawngj", L"nặng",
+ "trangw", L"trăng",
+ "cana", L"cân",
+ "ddeme", L"đêm",
+ "nhoo", L"nhô",
+ "mow", L"mơ",
+ "tuw", L"tư",
+ "cari xooong", L"cải xoong",
+ "huyeenf", L"huyền",
+ "hoom qua", L"hôm qua",
+ "thuws baary", L"thứ bẩy",
+ "ddaua", L"đâu",
+ "hoir", L"hỏi",
+ "giof", L"giò",
};
char*
@@ -57,7 +84,8 @@
bin = argv[1];
pipe(io1);
pipe(io2);
- if(fork() == 0){
+ if(rfork(RFENVG|RFFDG|RFREND|RFPROC) == 0){
+ putenv("zidian", "/lib/ktrans/pinyin.dict");
dup(io1[0], 0);
dup(io2[0], 1);
close(io1[1]); close(io2[1]);