33#include <sys/kernel.h>
35#include <sys/malloc.h>
38#include "iconv_converter_if.h"
48#define C2I1(c) ((c) & 0x8000 ? ((c) & 0xff) | 0x100 : (c) & 0xff)
49#define C2I2(c) ((c) & 0x8000 ? ((c) >> 8) & 0x7f : ((c) >> 8) & 0xff)
64 struct iconv_cspair *csp,
struct iconv_cspair *cspf,
void **dpp)
67 uint32_t *headp, **idxp;
70 dp = (
struct iconv_xlat16 *)kobj_create((
struct kobj_class*)dcp, M_ICONV, M_WAITOK);
71 headp = (uint32_t *)((caddr_t)csp->cp_data +
sizeof(dp->
d_table));
72 idxp = (uint32_t **)csp->cp_data;
73 for (i = 0 ; i < 0x200 ; i++) {
83 if (
strcmp(csp->cp_to, KICONV_WCTYPE_NAME) != 0) {
107 dp->
d_csp->cp_refcount--;
108 kobj_delete((
struct kobj*)data, M_ICONV);
121 size_t in, on, ir, or, inlen;
124 uint16_t c1, c2, ctmp;
133 while(ir > 0 && or > 0) {
137 c1 = ir > 1 ? *(src+1) & 0xff : 0;
141 c1 = c2 & 0x80 ? c1 | 0x100 : c1;
142 c2 = c2 & 0x80 ? c2 & 0x7f : c2;
152 ctmp =
towlower(((u_char)*src << 8) | (u_char)*(src + 1),
155 ctmp =
towupper(((u_char)*src << 8) | (u_char)*(src + 1),
174 if (
casetype & (KICONV_FROM_LOWER|KICONV_FROM_UPPER))
177 if (
casetype == KICONV_FROM_LOWER) {
180 else if (code & XLAT16_HAS_FROM_LOWER_CASE)
181 ctmp = (u_char)(code >> 16);
182 }
else if (
casetype == KICONV_FROM_UPPER) {
185 else if (code & XLAT16_HAS_FROM_UPPER_CASE)
186 ctmp = (u_char)(code >> 16);
189 c1 =
C2I1(ctmp << 8);
190 c2 =
C2I2(ctmp << 8);
200 nullin = (code & XLAT16_ACCEPT_NULL_IN) ? 1 : 0;
201 if (inlen == 1 && nullin) {
212 u = (u_char)(code >> 8);
215#ifdef XLAT16_ACCEPT_3BYTE_CHR
216 if (code & XLAT16_IS_3BYTE_CHR) {
223 *dst++ = (u_char)(code >> 16);
227 if (u || code & XLAT16_ACCEPT_NULL_OUT) {
236 u = (u_char)(code >> 8);
241 u = (u_char)(code >> 8);
253 else if (code & XLAT16_HAS_LOWER_CASE)
254 l = (u_char)(code >> 16);
259 else if (code & XLAT16_HAS_UPPER_CASE)
260 l = (u_char)(code >> 16);
272 if ((u_char)*(src+1) ==
'\0' && !nullin ) {
310 }
else if (
c < 0x10000) {
316 if (dp->
d_table[c1] && dp->
d_table[c1][c2] & XLAT16_HAS_LOWER_CASE) {
318 out = dp->
d_table[c1][c2] & 0xffff;
319 if ((out & 0xff) == 0)
320 out = (out >> 8) & 0xff;
335 }
else if (
c < 0x10000) {
341 if (dp->
d_table[c1] && dp->
d_table[c1][c2] & XLAT16_HAS_UPPER_CASE) {
342 out = dp->
d_table[c1][c2] & 0xffff;
343 if ((out & 0xff) == 0)
344 out = (out >> 8) & 0xff;
355 KOBJMETHOD(iconv_converter_init, iconv_xlat16_init),
356 KOBJMETHOD(iconv_converter_done, iconv_xlat16_done),
int towlower(int c, void *handle)
int towupper(int c, void *handle)
int iconv_close(void *handle)
int iconv_open(const char *to, const char *from, void **handle)
static kobj_method_t iconv_xlat16_methods[]
static const char * iconv_xlat16_name(struct iconv_converter_class *dcp)
static int iconv_xlat16_close(void *data)
static int iconv_xlat16_tolower(void *d2p, int c)
KICONV_CONVERTER(xlat16, sizeof(struct iconv_xlat16))
static int iconv_xlat16_toupper(void *d2p, int c)
static int iconv_xlat16_conv(void *d2p, const char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft, int convchar, int casetype)
static int iconv_xlat16_open(struct iconv_converter_class *dcp, struct iconv_cspair *csp, struct iconv_cspair *cspf, void **dpp)
int() strcmp(const char *s1, const char *s2)
uint32_t * d_table[0x200]
struct iconv_cspair * d_csp