/*
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <stdio.h>
#include "Xlibint.h"
#include "XlcGeneric.h"
/*
* codesets will derived from XLC_XLOCALE and codesets[0] is
* gb18030.2000-1 in XLC_XLOCALE
*/
#define ASCII_CODESET 0
typedef unsigned char Uchar;
typedef unsigned long Ulong;
typedef unsigned int Uint;
typedef struct _CT_DATA
{
char *charset;
char *encode_string;
} CT_DATA;
{
{"ASCII", "\033(B" },
{"GB2312", "\033$(A" },
{"GB18030-0", "\033%/2??SUN-GB18030-0" },
{"GB18030-1", "\033%/2??SUN-GB18030-1" }
};
static char *
{
if (charset) {
int i;
for (i=0; i < num_ct_data; ++i)
return default_ct_data[i].encode_string;
}
return NULL;
}
static CharSet_Type
get_charset_with_encode_string(const char *s)
{
if (s) {
int i;
for (i=0; i < num_ct_data; ++i)
return i;
}
return t_NONE;
}
static void
{
int tmp;
}
static void
{
int tmp;
}
/*
* In GB2312 range or not
*/
static int
isgb(unsigned char *s)
{
/* consider the first byte */
if (s[0] >= 0xA1 && s[0] <= 0xFE && s[1] >= 0xA1 &&
s[1] <= 0xFE) {
return True;
}else{
return False;
}
}
/*
* In GB18030 2 bytes range or not
*/
static int
isgb18030_2(unsigned char *s)
{
/* consider the first byte */
if (s[0] >= 0x81 && s[0] <= 0xfe &&
((s[1] >= 0x40 && s[1] <= 0x7e) ||
(s[1] >= 0x80 && s[1] <= 0xfe)))
return True;
else
return False;
}
/*
* In GB18030 4 bytes range or not
*/
static int isgb18030_4(unsigned char *s)
{
/* consider the first byte */
if (s[0] >= 0x81 && s[0] <= 0xfe && s[1] >= 0x30 && s[1] <= 0x39 &&
s[2] >= 0x81 && s[2] <= 0xfe && s[3] >= 0x30 && s[3] <= 0x39)
return True;
else
return False;
}
/*
* multibyte -> charset: codesets[0], codesets[1], codeset[2]
*/
static int
int *from_left,
int *to_left,
int num_args)
{
int unconv_num = 0;
int char_size = 0;
if (isgb18030_2(src)) {
if (GBK2K_CODESET1 >= codeset_num)
return -1;
} else {
return -1;
}
} else if (isgb18030_4(src)) {
if (GBK2K_CODESET2 >= codeset_num)
return -1;
src += 4;
} else {
return -1;
}
*from_left -= 4;
if (ASCII_CODESET >= codeset_num)
return -1;
else
return -1;
} else { /* unknown */
unconv_num++;
src++;
*from_left -= 1;
}
if (num_args > 0)
return unconv_num;
}
static int
int *from_left,
int *to_left,
int num_args)
{
int char_size = 0;
int unconv_num = 0;
int flag = 0;
for (;;) {
if (isgb18030_2(src)) {
if (flag == 0)
flag = 1;
break;
if (GBK2K_CODESET1 >= codeset_num)
return -1;
}else {
return -1;
}
} else if (isgb18030_4(src)) {
if (flag == 0)
flag = 2;
break;
if (GBK2K_CODESET2 >= codeset_num)
return -1;
src += 4;
*from_left -= 4;
} else {
return -1;
}
if (flag == 0)
flag = 3;
break;
if (ASCII_CODESET >= codeset_num)
return -1;
} else {
break;
}
} else{ /* unknown */
unconv_num++;
src++;
*from_left -= 1;
}
if (*from_left <= 0)
break;
}
if (num_args > 0)
return unconv_num;
}
static int
int *from_left,
int *to_left,
int num_args)
{
int char_size = 0;
int unconv_num = 0;
int flag = 0;
for (;;) {
if (isgb18030_2((unsigned char*)tmp)) {
if (flag == 0)
flag = 1;
break;
if (GBK2K_CODESET1 >= codeset_num)
return -1;
} else {
return -1;
}
} else if (isgb18030_4((unsigned char*)tmp)) {
if (flag == 0)
flag = 2;
break;
if (GBK2K_CODESET2 >= codeset_num)
return -1;
} else {
return -1;
}
if (flag == 0)
flag = 3;
break;
if (ASCII_CODESET >= codeset_num)
return -1;
} else {
return -1;
}
} else { /* unknown */
unconv_num++;
}
src++; /* advance one wchar_t */
(*from_left)--;
if (*from_left <= 0)
break;
}
if (num_args > 0)
return unconv_num;
}
static CodeSet
{
for (; codeset_num-- > 0; codeset++) {
for (; num_charsets-- > 0; charset_list++)
if (*charset_list == charset)
return *codeset;
}
}
static int
int *from_left,
int *to_left,
int num_args)
{
int char_size = 0;
int unconv_num = 0;
return -1;
for (;;) {
char_size = 2;
*to_left -= 4;
} else {
return -1;
}
char_size = 2;
*to_left -= 2;
} else {
return -1;
}
char_size = 1;
*to_left -= 1;
} else {
return -1;
}
} else { /* unknown */
unconv_num++;
src++;
char_size = 1;
}
if (*from_left <= 0)
break;
}
if (num_args > 0)
return unconv_num;
}
static int
int *from_left,
int *to_left,
int num_args)
{
*outbufptr='\0';
return rtn;
}
/*
* In gb18030 locale, we only consider the following possibilities
* all other ct formats are ignored, keep looping until end of buffer
* ASCII
* GB2312
* GB18030-0
* GB18030-1
*/
static int
int *from_left,
int *to_left,
int num_args)
{
int unconv_num = 0;
int i, j;
/*
* If outbufptr is NULL, doen't save output, but just counts
* a length to hold the output.
*/
save_outbuf = False;
i = 0;
j = 0;
while (i < *from_left) {
(const char *)inbufptr + i);
switch (charset_type) {
case t_ASCII:
for (;;) {
if (i >= *from_left) { /* end of from buffer */
goto FINISHED;
}
goto FINISHED;
}
if (save_outbuf == True)
(*to_left)--;
++i;
} else {
break;
}
}
break;
case t_GB2312:
for (;;) {
if (i >= *from_left) { /* end of from buffer */
goto FINISHED;
}
goto FINISHED;
}
if (save_outbuf == True) {
}
*to_left -= 2;
i = i + 2;
} else {
break;
}
}
break;
case t_GB18030_0:
for (;;) {
if (i >= *from_left) { /* end of from buffer */
goto FINISHED;
}
if (isgb18030_2(inbufptr + i)) {
goto FINISHED;
}
if (save_outbuf == True) {
}
*to_left -= 2;
i = i + 2;
} else {
break;
}
}
break;
case t_GB18030_1: /* gb18030.2000-1 character */
for (;;) {
if (i >= *from_left) { /* end of from buffer */
goto FINISHED;
}
if (isgb18030_4(inbufptr + i)) {
goto FINISHED;
}
if (save_outbuf == True) {
}
*to_left -= 4;
i = i + 4;
} else {
break;
}
}
break;
case t_NONE:
i++; /* encounter unknown escape sequence */
unconv_num++;
break;
}
/* Process default CT G0 ascii character */
if (*to_left < 1) {
goto FINISHED;
}
if (save_outbuf == True)
i++;
*to_left -= 1;
} else { /* unknown character */
i++;
unconv_num++;
}
}
if (i >= *from_left)
*from_left = 0;
else
*from_left -= i;
return (unconv_num);
}
static int
int *from_left,
int *to_left,
int num_args)
{
from,
args,
num_args);
*outbufptr='\0';
return rtn;
}
/*
* The mbs is GB18030 code, must be converted to euc code,
* then pack to ct format.
*/
static int
int *from_left,
int *to_left,
int num_args)
{
int unconv_num = 0;
int flag = 0, j = 0, i = 0;
int encode_string_len;
char *encode_string;
if (! encode_string )
return -1;
break;
j += encode_string_len;
flag = 2;
}
if (j + 2 >= *to_left)
break;
if (! encode_string )
return -1;
break;
j += encode_string_len;
flag = 4;
}
if (j + 2 >= *to_left)
break;
if (!encode_string)
return -1;
break;
j += encode_string_len;
flag = 5;
}
if (j + 4 >= *to_left)
break;
if (!encode_string )
return -1;
break;
j += encode_string_len;
flag = 3;
}
if (j + 1 >= *to_left)
break;
} else{
i++; /* Skip this byte */
unconv_num++; /* Count this as an unconverted byte */
}
}
return unconv_num;
}
static int
int *from_left,
int *to_left,
int num_args)
{
int unconv_num = 0;
int flag,j,i,k;
char *encode_string;
int encode_string_len;
i = k = j = 0;
flag = 0;
while (k < *from_left) {
return (-1);
i=0;
if (! encode_string)
return (-1);
break;
j += encode_string_len;
flag = 1;
}
if (j + 2 >= *to_left)
break;
} else if (isgb18030_2(&inbufptr[i])) {
if (! encode_string)
return -1;
break;
j += encode_string_len;
flag = 2;
}
if (j + 2 >= *to_left)
break;
} else if (isgb18030_4(&inbufptr[i])) {
if (! encode_string)
return -1;
break;
j += encode_string_len;
flag = 6;
}
if (j + 4 >= *to_left)
break;
if (! encode_string)
return -1;
break;
j += encode_string_len;
flag = 3;
}
} else {
unconv_num++;
}
}
return unconv_num;
}
static int
int *from_left,
int *to_left,
int num_args)
{
if (mblen > 0) {
dst++;
dst_left--;
} else {
src++;
src_left--;
if (mblen < 0) {
unconv_num++;
} else {
*dst++ = L'\0';
dst_left--;
}
}
}
return unconv_num;
}
static int
int *from_left,
int *to_left,
int num_args)
{
while (src_left > 0) {
break;
}
src++;
src_left--;
if (mblen < 0) {
unconv_num++;
continue;
}
for (int i = 0; i < mblen; i++) {
}
}
return unconv_num;
}
static void
{
}
static XlcConv
{
return conv;
}
};
static XlcConv
const char *from_type,
const char *to_type)
{
}
static XlcConv
const char *from_type,
const char *to_type)
{
}
static XlcConv
const char *from_type,
const char *to_type)
{
}
static XlcConv
const char *from_type,
const char *to_type)
{
}
static XlcConv
const char *from_type,
const char *to_type)
{
}
static XlcConv
const char *from_type,
const char *to_type)
{
}
static XlcConv
const char *from_type,
const char *to_type)
{
}
static XlcConv
const char *from_type,
const char *to_type)
{
}
static XlcConv
const char *from_type,
const char *to_type)
{
}
static XlcConv
const char *from_type,
const char *to_type)
{
}
static XlcConv
const char *from_type,
const char *to_type)
{
}
{
return lcd;
}
/* MB <-> WC */
return lcd;
}