#include <stdio.h>
#include <string.h>
#include "kdefs.h"
#include "ktable.h"
int input_typ(char c);
struct _cv_state {
char temp_ibuf[5];
int ibuf_left;
int istart, iend;
char temp_obuf[1];
int flush_obuf;
};
KCHAR packtocomp(KCHAR comb2);
#ifndef SUNVIEW
char vowel_mix(char c1,char c2);
#endif
static int cur_stat = 1;
static int cur_act;
static char han_buf[5] = {0,0,0,0,0 };
static int temp_flag;
static int han_temp = 0;
static int next_stat[14][21]={
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{ 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1},
{ 0, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 2, 1, 2},
{ 0, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 2, 1, 2},
{ 0, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 8, 8, 8, 8, 5, 6, 7, 2, 1, 2},
{ 0, 4, 9,10,11,12,13,13,13,13,13, 3, 8, 3, 8, 3, 3, 3, 2, 1, 2},
{ 0, 4, 9,10,11,12,13,13,13,13,13, 3, 3, 8, 8, 3, 3, 3, 2, 1, 2},
{ 0, 4, 9,10,11,12,13,13,13,13,13, 3, 3, 3, 8, 3, 3, 3, 2, 1, 2},
{ 0, 4, 9,10,11,12,13,13,13,13,13, 3, 3, 3, 3, 3, 3, 3, 2, 1, 2},
{ 0, 4, 4, 4, 4, 4, 4,13, 4, 4, 4, 8, 8, 8, 8, 5, 6, 7, 2, 1, 2},
{ 0, 4, 4, 4, 4, 4, 4, 4,13,13, 4, 8, 8, 8, 8, 5, 6, 7, 2, 1, 2},
{ 0, 4,13, 4, 4,13, 4,13, 4,13,13, 8, 8, 8, 8, 5, 6, 7, 2, 1, 2},
{ 0, 4, 4, 4, 4, 4, 4,13, 4, 4, 4, 8, 8, 8, 8, 5, 6, 7, 2, 1, 2},
{ 0, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 8, 8, 8, 8, 5, 6, 7, 2, 1, 2}
};
static int next_act[14][21]={
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{ 0, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 2, 1, 4},
{ 0, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,15,15,15,15,15,15,15, 1, 3, 4},
{ 0, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,15,15,15,15,15,15,15, 1, 3, 4},
{ 0, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 6, 6, 6, 6, 6, 6, 6,16,12,13},
{ 0, 9, 7, 7, 7, 7, 7, 7, 7, 7, 7,10,14,10,14,10,10,10,16,12,13},
{ 0, 9, 7, 7, 7, 7, 7, 7, 7, 7, 7,10,10,14,14,10,10,10,16,12,13},
{ 0, 9, 7, 7, 7, 7, 7, 7, 7, 7, 7,10,10,10,14,10,10,10,16,12,13},
{ 0, 9, 7, 7, 7, 7, 7, 7, 7, 7, 7,10,10,10,10,10,10,10,16,12,13},
{ 0, 9, 9, 9, 9, 9, 9, 8, 9, 9, 9,17,17,17,17,17,17,17,16,12,13},
{ 0, 9, 9, 9, 9, 9, 9, 9, 8, 8, 9,17,17,17,17,17,17,17,16,12,13},
{ 0, 9, 8, 9, 9, 8, 9, 8, 9, 8, 8,17,17,17,17,17,17,17,16,12,13},
{ 0, 9, 9, 9, 9, 9, 9, 8, 9, 9, 9,17,17,17,17,17,17,17,16,12,13},
{ 0, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,17,17,17,17,17,17,17,16,12,13}
};
KCHAR
getc_12(my_inbuf, my_inbytesleft, st)
char **my_inbuf;
size_t *my_inbytesleft;
struct _cv_state *st;
{
register char c;
register int cur_input;
register KCHAR code_2;
KCHAR make_2();
if(temp_flag == 1){
code_2 = han_temp;
temp_flag = 0;
return(code_2);
}
for(;;){
if (st->ibuf_left) {
c = st->temp_ibuf[st->istart];
st->istart++;
if (st->istart >= st->iend) {
st->ibuf_left = 0;
st->istart = 0;
st->iend = 0;
}
} else {
c = **my_inbuf;
(*my_inbuf)++, (*my_inbytesleft)--;
}
cur_input = input_typ(c);
cur_act = next_act[cur_stat][cur_input];
cur_stat = next_stat[cur_stat][cur_input];
switch (cur_act) {
case 1:
break;
case 2:
break;
case 3:
break;
case 4:
return(0x0000 | c);
case 5:
han_buf[1] = c;
break;
case 6:
han_buf[2] = c;
if((code_2=packtocomp(make_2(2))) == 0xFFFF){
han_buf[2] = 0;
code_2 = make_2(0);
if (st->ibuf_left) {
st->istart--;
} else {
(*my_inbuf)--, (*my_inbytesleft)++;
}
cur_stat = 2;
return(code_2);
}
break;
case 7:
han_buf[3] = c;
if((code_2=packtocomp(make_2(2))) == 0xFFFF){
han_buf[3] = 0;
code_2 = make_2(0);
if (st->ibuf_left) {
st->istart--;
} else {
(*my_inbuf)--, (*my_inbytesleft)++;
}
cur_stat = 2;
return(code_2);
}
break;
case 8:
han_buf[4] = c;
if((code_2=packtocomp(make_2(2))) == 0xFFFF){
han_buf[4] = 0;
code_2 = make_2(0);
cur_stat = 2;
if (st->ibuf_left) {
st->istart--;
} else {
(*my_inbuf)--, (*my_inbytesleft)++;
}
return(code_2);
}
break;
case 9:
code_2 = make_2(0);
han_buf[1] = c;
return(code_2);
case 10:
code_2 = make_2(0);
han_buf[2] = c;
han_temp = make_2(0);
temp_flag = 1;
return(code_2);
case 11:
return(make_2(0));
case 12:
return(make_2(0));
case 13:
code_2 = make_2(0);
han_temp = (0x0000 | c);
temp_flag = 1;
return(code_2);
case 14:
han_buf[0] = han_buf[2];
han_buf[2] = vowel_mix(han_buf[2],c);
if((code_2=packtocomp(make_2(2))) == 0xFFFF){
han_buf[2] = han_buf[0];
code_2 = make_2(0);
if (st->ibuf_left) {
st->istart--;
} else {
(*my_inbuf)--, (*my_inbytesleft)++;
}
cur_stat = 2;
return(code_2);
}
break;
case 15:
han_buf[2] = c;
return(make_2(0));
case 16:
return(make_2(0));
case 17:
code_2 = make_2(1);
han_buf[2] = c;
return(code_2);
default:
break;
}
}
}
int input_typ(char c)
{
switch(c) {
case D_DI_GUD:
case D_BI_UB:
case D_JI_UD:
return(1);
case GI_UG:
return(2);
case NI_UN:
return(3);
case RI_UL:
return(4);
case BI_UB:
return(5);
case D_GI_UG:
case DI_GUD:
case D_SI_OD:
case YI_UNG:
case CHI_UD:
case KI_UK:
return(6);
case SI_OD:
return(7);
case JI_UD:
return(8);
case HI_UD:
return(9);
case MI_UM:
case PI_UP:
case TI_GUT:
return(10);
case YEA:
case IA:
case IYAI:
case IE:
case YO:
case YU:
return(11);
case A:
case AE:
return(12);
case E:
case EA:
return(13);
case I:
return(14);
case O:
return(15);
case U:
return(16);
case EU:
return(17);
default:
if(c == '\016')
return(18);
if(c == '\017' || c == '\024')
return(19);
return(20);
}
}
KCHAR make_2(n)
register int n;
{
register KCHAR code_2 = 0;
register char tmp = 0;
register int i;
if (n == 1) {
if(han_buf[4]){
tmp = han_buf[4];
han_buf[4] = 0;
} else{
tmp = han_buf[3];
han_buf[3] = 0;
}
}
if(han_buf[1] > BEG_OF_CONSO){
code_2 = code_2 | X32_19[han_buf[1] - BEG_OF_CONSO];
} else {
code_2 = 0x9;
}
if(han_buf[2] > BEG_OF_VOW){
code_2 = ((code_2 << 5) | X32_21[han_buf[2] - BEG_OF_VOW]);
} else{
code_2 = (code_2 << 5) | 0x1;
}
if(han_buf[3] > BEG_OF_CONSO){
code_2 = ((code_2 << 5) | X32_28[han_buf[3] - BEG_OF_CONSO]);
} else {
code_2 = code_2 << 5 | 0x01;
}
if(han_buf[4] > BEG_OF_CONSO){
switch(han_buf[3]){
case GI_UG:
if(han_buf[4] == SI_OD){
code_2 += 2;
}
break;
case NI_UN:
switch (han_buf[4]) {
case JI_UD:
code_2++;
break;
case HI_UD:
code_2 += 2;
break;
default:
break;
}
break;
case RI_UL:
switch (han_buf[4]) {
case GI_UG:
code_2++;
break;
case MI_UM:
code_2 += 2;
break;
case BI_UB:
code_2 += 3;
break;
case SI_OD:
code_2 += 4;
break;
case TI_GUT:
code_2 += 5;
break;
case PI_UP:
code_2 += 6;
break;
case HI_UD:
code_2 += 7;
break;
default:
break;
}
break;
case BI_UB:
if(han_buf[4] == SI_OD){
code_2++;
}
break;
case SI_OD:
if(han_buf[4] == SI_OD){
code_2++;
}
break;
}
}
code_2 = code_2 | 0x8000;
if(n != 2)
for(i = 0; i < 5; i++){
han_buf[i] = 0;
}
if(n == 1){
han_buf[1] = tmp;
}
return(code_2);
}
#ifndef SUNVIEW
char vowel_mix(char c1,char c2)
{
register char c = '\0';
switch(c1){
case O:
switch (c2) {
case A:
c = c1 + 1;
break;
case AE:
c = c1 + 2;
break;
case I:
c = c1 + 3;
break;
}
break;
case U:
switch (c2) {
case E:
c = c1 + 1;
break;
case EA:
c = c1 + 2;
break;
case I:
c = c1 + 3;
break;
}
break;
case EU:
if(c2 == I){
c = c1 + 1;
}
break;
}
return(c);
}
#endif