summaryrefslogtreecommitdiff
path: root/sys/src/cmd/ktrans/main.c
diff options
context:
space:
mode:
authorJacob Moody <moody@posixcafe.org>2023-01-31 04:24:12 +0000
committerJacob Moody <moody@posixcafe.org>2023-01-31 04:24:12 +0000
commit05889d4454c61fb6f1caf6aba300ce23388ec47b (patch)
tree5dfbd13def918cf3f7d0393ade50aa1907a565b5 /sys/src/cmd/ktrans/main.c
parent006b925a2aedeff506430c4b028a04687e8560ff (diff)
ktrans: tests and various bug fixes
* exit if we get eof on kbdtap * do not nuke the line if we restore a kanji selection without okurigana * guard against unfortunate scheduling, the dictthread needs to get through all it can before the keythread processes more. In typical use, the processing was fast enough to never notice this condition but writing out a large set of input can trigger it.
Diffstat (limited to 'sys/src/cmd/ktrans/main.c')
-rw-r--r--sys/src/cmd/ktrans/main.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/sys/src/cmd/ktrans/main.c b/sys/src/cmd/ktrans/main.c
index 196956201..bd87992cc 100644
--- a/sys/src/cmd/ktrans/main.c
+++ b/sys/src/cmd/ktrans/main.c
@@ -408,6 +408,8 @@ emitutf(Channel *out, char *u, int nrune)
return e - b;
}
+static int compacting = 0;
+
static void
dictthread(void*)
{
@@ -437,6 +439,7 @@ dictthread(void*)
threadsetname("dict");
while(recv(dictch, m) != -1){
+ compacting = 1;
for(p = m+1; *p; p += n){
n = chartorune(&r, p);
switch(r){
@@ -478,7 +481,8 @@ dictthread(void*)
}
if(kouho[selected] == nil){
/* cycled through all matches; bail */
- emitutf(output, backspace, utflen(okuri.b));
+ if(utflen(okuri.b) != 0)
+ emitutf(output, backspace, utflen(okuri.b));
emitutf(output, backspace, utflen(last.b));
emitutf(output, line.b, 0);
emitutf(output, okuri.b, 0);
@@ -547,6 +551,7 @@ dictthread(void*)
hmapget(dict, line.b, kouho);
send(displaych, kouho);
}
+ compacting = 0;
}
}
@@ -623,6 +628,8 @@ keythread(void*)
}
for(p = m+1; *p; p += n){
+ while(compacting)
+ yield();
n = chartorune(&r, p);
if(checklang(&lang, r)){
emitutf(dictch, " ", 1);
@@ -718,6 +725,7 @@ kbdtap(void*)
return;
}
}
+ threadexitsall(nil);
}
static void