diff f03556a76343783be1873dc39d57b63e37c07dc1 uncommitted --- /dev/null +++ b//lib/ktrans/telex.map @@ -1,0 +1,127 @@ +aw ă +aa â +dd đ +ee ê +oo ô +ow ơ +uw ư +Af À +af à +Ăf Ằ +ăf ằ +Âf Ầ +âf ầ +Ef È +ef è +Êf Ề +êf ề +If Ì +if ì +Of Ò +of ò +Ôf Ồ +ôf ồ +Ơf Ờ +ơf ờ +Uf Ù +uf ù +Ưf Ừ +ưf ừ +Yf Ỳ +yf ỳ +As Á +as á +Ăs Ắ +ăs ắ +Âs Ấ +âs ấ +Es É +es é +Ês Ế +ês ế +Is Í +is í +Os Ó +os ó +Ôs Ố +ôs ố +Ơs Ớ +ơs ớ +Us Ú +us ú +Ưs Ứ +ưs ứ +Ys Ý +ys ý +Ar Ả +ar ả +Ăr Ẳ +ăr ẳ +Âr Ẩ +âr ẩ +Er Ẻ +er ẻ +Êr Ể +êr ể +Ir Ỉ +ir ỉ +Or Ỏ +or ỏ +Ôr Ổ +ôr ổ +Ơr Ở +ơr ở +Ur Ủ +ur ủ +Ưr Ử +ưr ử +Yr Ỷ +yr ỷ +Ax à +ax ã +Ăx Ẵ +ăx ẵ +Âx Ẫ +âx ẫ +Ex Ẽ +ex ẽ +Êx Ễ +êx ễ +Ix Ĩ +ix ĩ +Ox Õ +ox õ +Ôx Ỗ +ôx ỗ +Ơx Ỡ +ơx ỡ +Ux Ũ +ux ũ +Ưx Ữ +ưx ữ +Yx Ỹ +yx ỹ +Aj Ạ +aj ạ +Ăj Ặ +ăj ặ +Âj Ậ +âj ậ +Ej Ẹ +ej ẹ +Êj Ệ +êj ệ +Ij Ị +ij ị +Oj Ọ +oj ọ +Ôj Ộ +ôj ộ +Ơj Ợ +ơj ợ +Uj Ụ +uj ụ +Ưj Ự +ưj ự +Yj Ỵ +yj ỵ --- a//sys/src/cmd/ktrans/main.c +++ b//sys/src/cmd/ktrans/main.c @@ -17,10 +17,7 @@ #include "hash.h" #include "ktrans.h" -static Hmap *jisho, *zidian; -static int deflang; static char backspace[64]; - mainstacksize = 8192*2; char* @@ -59,6 +56,14 @@ return d; } +char* +peekstr(char *s, char *b) +{ + while(s > b && (*--s & 0xC0)==0x80) + ; + return s; +} + typedef struct Str Str; struct Str { char b[128]; @@ -83,9 +88,7 @@ void popstr(Str *s) { - while(s->p > s->b && (*--s->p & 0xC0)==0x80) - ; - + s->p = peekstr(s->p, s->b); s->p[0] = '\0'; } @@ -199,15 +202,26 @@ LangEL = '', // ^o LangKO = '', // ^s LangZH = '', // ^c + LangVN = '', // ^v }; +/* explicit mapping */ +Hmap *jisho; +Hmap *zidian; + +/* implicit mapping */ Hmap *natural; Hmap *hira, *kata; Hmap *cyril; Hmap *greek; Hmap *hangul; + +/* marker only */ Hmap *hanzi; +Hmap *telex; +int deflang; + Hmap **langtab[] = { [LangEN] &natural, [LangJP] &hira, @@ -216,6 +230,7 @@ [LangEL] &greek, [LangKO] &hangul, [LangZH] &hanzi, + [LangVN] &telex, }; char *langcodetab[] = { @@ -226,6 +241,7 @@ [LangEL] "el", [LangKO] "ko", [LangZH] "zh", + [LangVN] "vn", }; int @@ -434,6 +450,43 @@ send(t->done, nil); } +int +telexlkup(Str *line, Str *out) +{ + Map lkup; + char buf[UTFmax*3], *p, *e, *x; + int n; + + p = pushutf(buf, buf+sizeof buf, line->b, 1); + n = p-buf; + + if(hmapget(telex, buf, &lkup) < 0) + return -1; + + assert(lkup.leadstomore == 1); + //All of our keys are 2 characters long, but we + //need to peek three in order to fully disambiguate. + if(utflen(line->b) < 3) + return 1; + + x = peekstr(line->p, line->b); + e = peekstr(x, line->b); + pushutf(p, buf+sizeof buf, e, 1); + if(hmapget(telex, buf, &lkup) < 0) + return 1; + + if(strcmp(x, e) == 0) + return -1; + + out->p = pushutf(out->b, strend(out), lkup.kana, 0); + //fprint(2, "%s %s\n", line->b, line->b+n); + out->p = pushutf(out->p, strend(out), line->b+n, 0); + popstr(out); + popstr(out); + out->p = pushutf(out->p, strend(out), x, 1); + return 0; +} + void keyproc(void *a) { @@ -445,7 +498,7 @@ int n; Rune r; char peek[UTFmax+1]; - Str line; + Str line, tbuf; int mode; t = a; @@ -475,6 +528,11 @@ resetstr(&line, nil); continue; } + if(lang == LangVN && utfrune(" \n", r) != nil){ + resetstr(&line, nil); + if(r == ' ') + continue; + } if(lang == LangZH || lang == LangJP){ emitutf(t->dict, p, 1); if(utfrune(" \n", r) != nil){ @@ -498,6 +556,21 @@ } line.p = pushutf(line.p, strend(&line), p, 1); + if(lang == LangVN){ + switch(telexlkup(&line, &tbuf)){ + case -1: + resetstr(&line, nil); + continue; + case 1: + continue; + case 0: + emitutf(t->output, backspace, utflen(line.b)); + emitutf(t->output, tbuf.b, 0); + //fprint(2, "tbuf: %s\n", tbuf.b); + resetstr(&line, nil); + continue; + } + } if(maplkup(lang, line.b, &lkup) < 0){ resetstr(&line, nil); pushutf(peek, peek + sizeof peek, p, 1); @@ -581,6 +654,7 @@ greek = openmap("/lib/ktrans/greek.map"); cyril = openmap("/lib/ktrans/cyril.map"); hangul = openmap("/lib/ktrans/hangul.map"); + telex = openmap("/lib/ktrans/telex.map"); launchfs(srv, mntpt, kbd); }