engine: one trans contract for every language
Japanese was never dispatched through the Lang table: dotrans and transstr both special-cased it into transjp, which edited Im in place and wrote commits through a side argument, while transko popped and cleared a pre that every caller overwrote anyway, and Vietnamese kept its key history in dotrans. Emit now carries the new raw state next to the new pre; transjp, transko and transvi are pure functions of (Im, key), and dotrans and transstr have a single path. Vietnamese history bookkeeping lives in vi.c, where the full-history flush no longer resets the caret as a side effect; istone was toneidx() >= 0.
This commit is contained in:
16
ko.c
16
ko.c
@@ -189,6 +189,10 @@ issyl(Rune r)
|
||||
return r >= Sbase && r < Sbase + Ncho*Njung*Njong;
|
||||
}
|
||||
|
||||
/*
|
||||
* The pending text is at most one syllable; a key either extends it,
|
||||
* commits it and starts another, or commits it and passes through.
|
||||
*/
|
||||
Emit
|
||||
transko(Im *im, Rune c)
|
||||
{
|
||||
@@ -199,10 +203,7 @@ transko(Im *im, Rune c)
|
||||
memset(&e, 0, sizeof e);
|
||||
jm = keytojamo(c);
|
||||
if(jm == 0){
|
||||
if(im->pre.n > 0){
|
||||
e.s = im->pre;
|
||||
sclear(&im->pre);
|
||||
}
|
||||
e.s = im->pre;
|
||||
return e;
|
||||
}
|
||||
|
||||
@@ -217,14 +218,12 @@ transko(Im *im, Rune c)
|
||||
ci = Choidx(last);
|
||||
ji = Jungidx(jm);
|
||||
if(ci >= 0 && ji >= 0){
|
||||
spopr(&im->pre);
|
||||
sputr(&e.next, compose(ci, ji, 0));
|
||||
return e;
|
||||
}
|
||||
if(Jungidx(last) >= 0 && ji >= 0){
|
||||
comb = combine(cvow, nelem(cvow), last, jm);
|
||||
if(comb){
|
||||
spopr(&im->pre);
|
||||
sputr(&e.next, comb);
|
||||
return e;
|
||||
}
|
||||
@@ -239,7 +238,6 @@ transko(Im *im, Rune c)
|
||||
if(joi == 0){
|
||||
ni = Jongidx(jm);
|
||||
if(ni > 0){
|
||||
spopr(&im->pre);
|
||||
sputr(&e.next, compose(ci, ji, ni));
|
||||
return e;
|
||||
}
|
||||
@@ -248,7 +246,6 @@ transko(Im *im, Rune c)
|
||||
comb = combine(cvow, nelem(cvow), jung[ji], jm);
|
||||
if(comb){
|
||||
ni = Jungidx(comb);
|
||||
spopr(&im->pre);
|
||||
sputr(&e.next, compose(ci, ni, 0));
|
||||
return e;
|
||||
}
|
||||
@@ -260,7 +257,6 @@ transko(Im *im, Rune c)
|
||||
if(comb){
|
||||
ni = Jongidx(comb);
|
||||
if(ni > 0){
|
||||
spopr(&im->pre);
|
||||
sputr(&e.next, compose(ci, ji, ni));
|
||||
return e;
|
||||
}
|
||||
@@ -271,14 +267,12 @@ transko(Im *im, Rune c)
|
||||
if(splitpair(cjong, nelem(cjong), jc, &stay, &next)){
|
||||
si = Jongidx(stay);
|
||||
ni = Choidx(next);
|
||||
spopr(&im->pre);
|
||||
sputr(&e.s, compose(ci, ji, si));
|
||||
sputr(&e.next, compose(ni, vi, 0));
|
||||
return e;
|
||||
}
|
||||
ni = Choidx(jc);
|
||||
if(ni >= 0){
|
||||
spopr(&im->pre);
|
||||
sputr(&e.s, compose(ci, ji, 0));
|
||||
sputr(&e.next, compose(ni, vi, 0));
|
||||
return e;
|
||||
|
||||
Reference in New Issue
Block a user