#include <stdlib.h>
#include <errno.h>
#include <euc.h>
#include "japanese.h"
#include "jfp_iconv_unicode.h"
#define JFP_U2E_ICONV_X0213
#include "jfp_ucs2_to_euc16.h"
#define DEF_SINGLE '?'
#define INVL 0xff
static const unsigned char rowtosj1_x0213_p1[] = {
INVL, 0x81, 0x81, 0x82, 0x82, 0x83, 0x83, 0x84,
0x84, 0x85, 0x85, 0x86, 0x86, 0x87, 0x87, 0x88,
0x88, 0x89, 0x89, 0x8a, 0x8a, 0x8b, 0x8b, 0x8c,
0x8c, 0x8d, 0x8d, 0x8e, 0x8e, 0x8f, 0x8f, 0x90,
0x90, 0x91, 0x91, 0x92, 0x92, 0x93, 0x93, 0x94,
0x94, 0x95, 0x95, 0x96, 0x96, 0x97, 0x97, 0x98,
0x98, 0x99, 0x99, 0x9a, 0x9a, 0x9b, 0x9b, 0x9c,
0x9c, 0x9d, 0x9d, 0x9e, 0x9e, 0x9f, 0x9f, 0xe0,
0xe0, 0xe1, 0xe1, 0xe2, 0xe2, 0xe3, 0xe3, 0xe4,
0xe4, 0xe5, 0xe5, 0xe6, 0xe6, 0xe7, 0xe7, 0xe8,
0xe8, 0xe9, 0xe9, 0xea, 0xea, 0xeb, 0xeb, 0xec,
0xec, 0xed, 0xed, 0xee, 0xee, 0xef, 0xef
};
static const unsigned char rowtosj1_x0213_p2[] = {
INVL, 0xf0, INVL, 0xf1, 0xf1, 0xf2, INVL, INVL,
0xf0, INVL, INVL, INVL, 0xf2, 0xf3, 0xf3, 0xf4,
INVL, INVL, INVL, INVL, INVL, INVL, INVL, INVL,
INVL, INVL, INVL, INVL, INVL, INVL, INVL, INVL,
INVL, INVL, INVL, INVL, INVL, INVL, INVL, INVL,
INVL, INVL, INVL, INVL, INVL, INVL, INVL, INVL,
INVL, INVL, INVL, INVL, INVL, INVL, INVL, INVL,
INVL, INVL, INVL, INVL, INVL, INVL, INVL, INVL,
INVL, INVL, INVL, INVL, INVL, INVL, INVL, INVL,
INVL, INVL, INVL, INVL, INVL, INVL, 0xf4, 0xf5,
0xf5, 0xf6, 0xf6, 0xf7, 0xf7, 0xf8, 0xf8, 0xf9,
0xf9, 0xfa, 0xfa, 0xfb, 0xfb, 0xfc, 0xfc
};
static unsigned char e16tosj_x0213(
unsigned short e16,
unsigned char *pc2)
{
unsigned char c1;
unsigned char r, c;
r = (e16 >> 8) - 0xa0;
if ((e16 & 0x8080) == 0x8080) {
c1 = rowtosj1_x0213_p1[r];
} else {
c1 = rowtosj1_x0213_p2[r];
}
c = (e16 & 0x7f) - 0x20;
if ((r % 2) == 1) {
*pc2 = (c - 1) + 0x40;
if (*pc2 >= 0x7f) {
(*pc2)++;
}
} else {
*pc2 = (c - 1) + 0x9f;
}
return (c1);
}
void *
_icv_open(void)
{
return (_icv_open_unicode((size_t)0));
}
void
_icv_close(void *cd)
{
_icv_close_unicode(cd);
return;
}
size_t
_icv_iconv(void *cd, char **inbuf, size_t *inbytesleft,
char **outbuf, size_t *outbytesleft)
{
unsigned int u32;
unsigned short e16;
unsigned char ic1, ic2;
size_t rv = (size_t)0;
unsigned char *ip;
size_t ileft;
char *op;
size_t oleft;
if ((inbuf == NULL) || (*inbuf == NULL)) {
_icv_reset_unicode(cd);
return ((size_t)0);
}
ip = (unsigned char *)*inbuf;
ileft = *inbytesleft;
op = *outbuf;
oleft = *outbytesleft;
while (ileft != 0) {
GETU(&u32)
e16 = _jfp_u32_to_euc16(u32);
switch (e16 & 0x8080) {
case 0x0000:
ic1 = (unsigned char)e16;
NPUT(ic1, "ASCII");
break;
case 0x8080:
ic1 = e16tosj_x0213(e16, &ic2);
NPUT(ic1, "PLANE1-1");
NPUT(ic2, "PLANE1-2");
break;
case 0x0080:
ic1 = (unsigned char)e16;
NPUT(ic1, "KANA");
break;
case 0x8000:
ic1 = e16tosj_x0213(e16, &ic2);
NPUT(ic1, "PLANE2-1");
NPUT(ic2, "PLANE2-2");
break;
}
next:
*inbuf = (char *)ip;
*inbytesleft = ileft;
*outbuf = op;
*outbytesleft = oleft;
}
ret:
DEBUGPRINTERROR
return ((rv == (size_t)-1) ? rv : *inbytesleft);
}