15 contributed by kuro@vodka.Eng.Sun.COM (Teruhiko Kurosaka)
19 a state machine for interpreting shift-ksc.
25 * Convert EUC in Koran locale to Unicode.
26 * Only codeset 0 and 1 are used.
29 ukscproc(int c, Rune **r, long input_loc)
31 static enum { init, cs1last /*, cs2, cs3first, cs3last*/} state = init;
32 static int korean646 = 1; /* fixed to 1 for now. */
43 if(korean646 && (c=='\\')){
58 case cs1last: /* 2nd byte of codeset 1 (KSC 5601) */
61 EPR "%s: unexpected EOF in %s\n", argv0, file);
62 c = 0x21 | (lastc&0x80);
64 n = ((lastc&0x7f)-33)*94 + (c&0x7f)-33;
65 if((n >= ksc5601max) || ((l = tabksc5601[n]) < 0)){
68 EPR "%s: unknown ksc5601 %d (from 0x%x,0x%x) near byte %ld in %s\n", argv0, n, lastc, c, input_loc, file);
78 EPR "%s: ukscproc: unknown state %d\n",
84 uksc_in(int fd, long *notused, struct convert *out)
96 while((n = read(fd, ibuf, sizeof ibuf)) > 0){
97 for(i = 0; i < n; i++){
98 ukscproc(ibuf[i], &r, nin++);
109 ukscproc(-1, &r, nin);
116 uksc_out(Rune *base, int n, long *notused)
122 static int first = 1;
127 for(i = 0; i < NRUNE; i++)
129 for(i = 0; i < ksc5601max; i++)
130 if((l = tabksc5601[i]) != -1){
139 for(i = 0; i < n; i++){
145 *p++ = 0x80 | (tab[r]/94 + 0x21);
146 *p++ = 0x80 | (tab[r]%94 + 0x21);
150 EPR "%s: rune 0x%x not in output cs\n", argv0, r);
159 write(1, obuf, p-obuf);