#include <stdio.h>
#include <ctype.h>
#include "kctype.h"
#include "kdefs.h"
#include "ktable.h"
#ifdef TESTP
#include <widec.h>
#include <locale.h>
#endif
KCHAR c2p();
KCHAR comptopack(comp)
KCHAR comp;
{
int c;
KCHAR code;
unsigned char cnv_buf[2];
#ifdef TESTP
setlocale (LC_CTYPE, "");
#endif
#if defined(i386) || defined(__ppc)
c = comp & 0x00ff;
#else
c = comp>>8 & 0x00ff;
#endif
if (iskorea1 (c)) {
#if defined(i386) || defined(__ppc)
code = (comp >> 8 & 0x00ff) | (((comp & 0x00ff) << 8) & 0xff00);
#else
code = comp;
#endif
if (iskorea2(code&BYTE_MASK)) {
if (ishangul(c)) {
if ((code = c2p(code)) == K_ILLEGAL) {
return(K_ILLEGAL);
} else {
cnv_buf[0] = code>>8;
cnv_buf[1] = code&BYTE_MASK;
}
} else if (ishaninit(code)) {
if (X32_19[code - 0xa4a0] == -1) {
return(K_ILLEGAL);
} else {
cnv_buf[0] = (X32_19[code - 0xa4a0]<<2)|0x80;
cnv_buf[1] = 0x21;
}
} else if (ishanmid(code)) {
code -= 0xa4be;
code = ((code + code/3 + 1)<<5)|0xa401;
cnv_buf[0] = code>>8;
cnv_buf[1] = code&BYTE_MASK;
} else if (ishanja (c)) {
return(K_ILLEGAL);
} else {
return(K_ILLEGAL);
}
} else {
return(K_ILLEGAL);
}
} else {
return(comp);
}
#if defined(i386) || defined(__ppc)
return(cnv_buf[1] << 8 | cnv_buf[0]);
#else
return(cnv_buf[0] << 8 | cnv_buf[1]);
#endif
}
#ifdef TESTP
main()
{
unsigned int comp2;
unsigned short comb2;
unsigned int wc;
for(;;) {
wc = getwchar();
wctomb((char *)&comb2, wc);
comp2 = comptopack(comb2);
printf("completion, combination = 0x%x 0x%x\n",
comb2, comp2);
}
}
#endif