Commit de53ce81 authored by Tatsuo Ishii's avatar Tatsuo Ishii

Support for conversion between UNICODE and other encodings

currently ISO8859-[1-5] and EUC_JP are supported.
support for other encodings will be coming soon.
parent 6619ad11
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -4,7 +4,7 @@
# Makefile for utils/mb
#
# IDENTIFICATION
# $Header: /cvsroot/pgsql/src/backend/utils/mb/Makefile,v 1.10 2000/08/31 16:10:56 petere Exp $
# $Header: /cvsroot/pgsql/src/backend/utils/mb/Makefile,v 1.11 2000/10/12 06:06:49 ishii Exp $
#
#-------------------------------------------------------------------------
......@@ -29,6 +29,15 @@ sjistest.o: sjistest.c
liketest.o: liketest.c
$(CC) -c $(CFLAGS) liketest.c
uconv.o: uconv.c
$(CC) -c $(CFLAGS) uconv.c
uconv2.o: uconv2.c
$(CC) -c $(CFLAGS) uconv2.c
utftest.o: utftest.c conv.c wchar.c mbutils.c
$(CC) -c $(CFLAGS) utftest.c
sjistest: $(OBJS) sjistest.o palloc.o
$(CC) -o sjistest sjistest.o palloc.o \
common.o mbutils.o wchar.o wstrcmp.o wstrncmp.o variable.o \
......@@ -39,6 +48,21 @@ liketest: $(OBJS) liketest.o palloc.o
common.o mbutils.o wchar.o wstrcmp.o wstrncmp.o variable.o \
big5.o $(LDFLAGS)
utftest: $(OBJS) utftest.o palloc.o
$(CC) -o utftest utftest.o palloc.o \
common.o wstrcmp.o wstrncmp.o variable.o \
big5.o $(LDFLAGS)
uconv: uconv.o palloc.o
$(CC) -o uconv uconv.o palloc.o \
common.o conv.o wchar.o \
big5.o mbutils.o $(LDFLAGS)
uconv2: uconv2.o palloc.o
$(CC) -o uconv2 uconv2.o palloc.o \
common.o conv.o wchar.o \
big5.o mbutils.o $(LDFLAGS)
depend dep:
$(CC) -MM $(CFLAGS) *.c >depend
......
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -6,7 +6,7 @@
* WIN1250 client encoding support contributed by Pavel Behal
* SJIS UDC (NEC selection IBM kanji) support contributed by Eiji Tokuya
*
* $Id: conv.c,v 1.17 2000/08/27 10:40:48 ishii Exp $
* $Id: conv.c,v 1.18 2000/10/12 06:06:50 ishii Exp $
*
*
*/
......@@ -16,6 +16,13 @@
#include "mb/pg_wchar.h"
/*
* for Unicode (UTF-8) support
*/
#include "iso8859.map" /* UTF-8 <--> ISO8859 map */
#include "UTF_to_EUC_JP.map" /* UTF-8 --> EUC_JP map */
#include "EUC_JP_to_UTF.map" /* UTF-8 <-- EUC_JP map */
/*
* SJIS alternative code.
* this code is used if a mapping EUC -> SJIS is not defined.
......@@ -26,404 +33,8 @@
/*
* conversion table between SJIS UDC (IBM kanji) and EUC_JP
*/
/* Eiji Tokuya patched begin */
static struct
{
unsigned short int nec; /* SJIS UDC (NEC selection IBM kanji) */
unsigned short int sjis; /* SJIS UDC (IBM kanji) */
int euc; /* EUC_JP */
} ibmkanji[] = {
{ 0xEEEF , 0xfa40 , 0x8ff3f3 },
{ 0xEEF0 , 0xfa41 , 0x8ff3f4 },
{ 0xEEF1 , 0xfa42 , 0x8ff3f5 },
{ 0xEEF2 , 0xfa43 , 0x8ff3f6 },
{ 0xEEF3 , 0xfa44 , 0x8ff3f7 },
{ 0xEEF4 , 0xfa45 , 0x8ff3f8 },
{ 0xEEF5 , 0xfa46 , 0x8ff3f9 },
{ 0xEEF6 , 0xfa47 , 0x8ff3fa },
{ 0xEEF7 , 0xfa48 , 0x8ff3fb },
{ 0xEEF8 , 0xfa49 , 0x8ff3fc },
{ 0x8754 , 0xfa4a , 0x8ff3fd },
{ 0x8755 , 0xfa4b , 0x8ff3fe },
{ 0x8756 , 0xfa4c , 0x8ff4a1 },
{ 0x8757 , 0xfa4d , 0x8ff4a2 },
{ 0x8758 , 0xfa4e , 0x8ff4a3 },
{ 0x8759 , 0xfa4f , 0x8ff4a4 },
{ 0x875A , 0xfa50 , 0x8ff4a5 },
{ 0x875B , 0xfa51 , 0x8ff4a6 },
{ 0x875C , 0xfa52 , 0x8ff4a7 },
{ 0x875D , 0xfa53 , 0x8ff4a8 },
{ 0xEEF9 , 0xfa54 , 0xa2cc },
{ 0xEEFA , 0xfa55 , 0x8fa2c3 },
{ 0xEEFB , 0xfa56 , 0x8ff4a9 },
{ 0xEEFC , 0xfa57 , 0x8ff4aa },
{ 0x878A , 0xfa58 , 0x8ff4ab },
{ 0x8782 , 0xfa59 , 0x8ff4ac },
{ 0x8784 , 0xfa5a , 0x8ff4ad },
{ 0x879A , 0xfa5b , 0xa2e8 },
{ 0xED40 , 0xfa5c , 0x8fd4e3 },
{ 0xED41 , 0xfa5d , 0x8fdcdf },
{ 0xED42 , 0xfa5e , 0x8fe4e9 },
{ 0xED43 , 0xfa5f , 0x8fe3f8 },
{ 0xED44 , 0xfa60 , 0x8fd9a1 },
{ 0xED45 , 0xfa61 , 0x8fb1bb },
{ 0xED46 , 0xfa62 , 0x8ff4ae },
{ 0xED47 , 0xfa63 , 0x8fc2ad },
{ 0xED48 , 0xfa64 , 0x8fc3fc },
{ 0xED49 , 0xfa65 , 0x8fe4d0 },
{ 0xED4A , 0xfa66 , 0x8fc2bf },
{ 0xED4B , 0xfa67 , 0x8fbcf4 },
{ 0xED4C , 0xfa68 , 0x8fb0a9 },
{ 0xED4D , 0xfa69 , 0x8fb0c8 },
{ 0xED4E , 0xfa6a , 0x8ff4af },
{ 0xED4F , 0xfa6b , 0x8fb0d2 },
{ 0xED50 , 0xfa6c , 0x8fb0d4 },
{ 0xED51 , 0xfa6d , 0x8fb0e3 },
{ 0xED52 , 0xfa6e , 0x8fb0ee },
{ 0xED53 , 0xfa6f , 0x8fb1a7 },
{ 0xED54 , 0xfa70 , 0x8fb1a3 },
{ 0xED55 , 0xfa71 , 0x8fb1ac },
{ 0xED56 , 0xfa72 , 0x8fb1a9 },
{ 0xED57 , 0xfa73 , 0x8fb1be },
{ 0xED58 , 0xfa74 , 0x8fb1df },
{ 0xED59 , 0xfa75 , 0x8fb1d8 },
{ 0xED5A , 0xfa76 , 0x8fb1c8 },
{ 0xED5B , 0xfa77 , 0x8fb1d7 },
{ 0xED5C , 0xfa78 , 0x8fb1e3 },
{ 0xED5D , 0xfa79 , 0x8fb1f4 },
{ 0xED5E , 0xfa7a , 0x8fb1e1 },
{ 0xED5F , 0xfa7b , 0x8fb2a3 },
{ 0xED60 , 0xfa7c , 0x8ff4b0 },
{ 0xED61 , 0xfa7d , 0x8fb2bb },
{ 0xED62 , 0xfa7e , 0x8fb2e6 },
{ 0xED63 , 0xfa80 , 0x8fb2ed },
{ 0xED64 , 0xfa81 , 0x8fb2f5 },
{ 0xED65 , 0xfa82 , 0x8fb2fc },
{ 0xED66 , 0xfa83 , 0x8ff4b1 },
{ 0xED67 , 0xfa84 , 0x8fb3b5 },
{ 0xED68 , 0xfa85 , 0x8fb3d8 },
{ 0xED69 , 0xfa86 , 0x8fb3db },
{ 0xED6A , 0xfa87 , 0x8fb3e5 },
{ 0xED6B , 0xfa88 , 0x8fb3ee },
{ 0xED6C , 0xfa89 , 0x8fb3fb },
{ 0xED6D , 0xfa8a , 0x8ff4b2 },
{ 0xED6E , 0xfa8b , 0x8ff4b3 },
{ 0xED6F , 0xfa8c , 0x8fb4c0 },
{ 0xED70 , 0xfa8d , 0x8fb4c7 },
{ 0xED71 , 0xfa8e , 0x8fb4d0 },
{ 0xED72 , 0xfa8f , 0x8fb4de },
{ 0xED73 , 0xfa90 , 0x8ff4b4 },
{ 0xED74 , 0xfa91 , 0x8fb5aa },
{ 0xED75 , 0xfa92 , 0x8ff4b5 },
{ 0xED76 , 0xfa93 , 0x8fb5af },
{ 0xED77 , 0xfa94 , 0x8fb5c4 },
{ 0xED78 , 0xfa95 , 0x8fb5e8 },
{ 0xED79 , 0xfa96 , 0x8ff4b6 },
{ 0xED7A , 0xfa97 , 0x8fb7c2 },
{ 0xED7B , 0xfa98 , 0x8fb7e4 },
{ 0xED7C , 0xfa99 , 0x8fb7e8 },
{ 0xED7D , 0xfa9a , 0x8fb7e7 },
{ 0xED7E , 0xfa9b , 0x8ff4b7 },
{ 0xED80 , 0xfa9c , 0x8ff4b8 },
{ 0xED81 , 0xfa9d , 0x8ff4b9 },
{ 0xED82 , 0xfa9e , 0x8fb8ce },
{ 0xED83 , 0xfa9f , 0x8fb8e1 },
{ 0xED84 , 0xfaa0 , 0x8fb8f5 },
{ 0xED85 , 0xfaa1 , 0x8fb8f7 },
{ 0xED86 , 0xfaa2 , 0x8fb8f8 },
{ 0xED87 , 0xfaa3 , 0x8fb8fc },
{ 0xED88 , 0xfaa4 , 0x8fb9af },
{ 0xED89 , 0xfaa5 , 0x8fb9b7 },
{ 0xED8A , 0xfaa6 , 0x8fbabe },
{ 0xED8B , 0xfaa7 , 0x8fbadb },
{ 0xED8C , 0xfaa8 , 0x8fcdaa },
{ 0xED8D , 0xfaa9 , 0x8fbae1 },
{ 0xED8E , 0xfaaa , 0x8ff4ba },
{ 0xED8F , 0xfaab , 0x8fbaeb },
{ 0xED90 , 0xfaac , 0x8fbbb3 },
{ 0xED91 , 0xfaad , 0x8fbbb8 },
{ 0xED92 , 0xfaae , 0x8ff4bb },
{ 0xED93 , 0xfaaf , 0x8fbbca },
{ 0xED94 , 0xfab0 , 0x8ff4bc },
{ 0xED95 , 0xfab1 , 0x8ff4bd },
{ 0xED96 , 0xfab2 , 0x8fbbd0 },
{ 0xED97 , 0xfab3 , 0x8fbbde },
{ 0xED98 , 0xfab4 , 0x8fbbf4 },
{ 0xED99 , 0xfab5 , 0x8fbbf5 },
{ 0xED9A , 0xfab6 , 0x8fbbf9 },
{ 0xED9B , 0xfab7 , 0x8fbce4 },
{ 0xED9C , 0xfab8 , 0x8fbced },
{ 0xED9D , 0xfab9 , 0x8fbcfe },
{ 0xED9E , 0xfaba , 0x8ff4be },
{ 0xED9F , 0xfabb , 0x8fbdc2 },
{ 0xEDA0 , 0xfabc , 0x8fbde7 },
{ 0xEDA1 , 0xfabd , 0x8ff4bf },
{ 0xEDA2 , 0xfabe , 0x8fbdf0 },
{ 0xEDA3 , 0xfabf , 0x8fbeb0 },
{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EED8 , 0xfbf4 , 0x8fe8b1 },
{ 0xEED9 , 0xfbf5 , 0x8fe8b6 },
{ 0xEEDA , 0xfbf6 , 0x8ff4f7 },
{ 0xEEDB , 0xfbf7 , 0x8ff4f8 },
{ 0xEEDC , 0xfbf8 , 0x8fe8dd },
{ 0xEEDD , 0xfbf9 , 0x8ff4f9 },
{ 0xEEDE , 0xfbfa , 0x8ff4fa },
{ 0xEEDF , 0xfbfb , 0x8fe9d1 },
{ 0xEEE0 , 0xfbfc , 0x8ff4fb },
{ 0xEEE1 , 0xfc40 , 0x8fe9ed },
{ 0xEEE2 , 0xfc41 , 0x8feacd },
{ 0xEEE3 , 0xfc42 , 0x8ff4fc },
{ 0xEEE4 , 0xfc43 , 0x8feadb },
{ 0xEEE5 , 0xfc44 , 0x8feae6 },
{ 0xEEE6 , 0xfc45 , 0x8feaea },
{ 0xEEE7 , 0xfc46 , 0x8feba5 },
{ 0xEEE8 , 0xfc47 , 0x8febfb },
{ 0xEEE9 , 0xfc48 , 0x8febfa },
{ 0xEEEA , 0xfc49 , 0x8ff4fd },
{ 0xEEEB , 0xfc4a , 0x8fecd6 },
{ 0xEEEC , 0xfc4b , 0x8ff4fe },
{ 0xffff , 0xffff , 0xffff } /* Stop code */
};
/* Eiji Tokuya patched End */
#include "sjis.map"
/*
* convert bogus chars that cannot be represented in the current
encoding
......@@ -1496,26 +1107,373 @@ mic2win1250(unsigned char *mic, unsigned char *p, int len)
mic2latin_with_table(mic, p, len, LC_ISO8859_2, iso88592_2_win1250);
}
/*
* UNICODE(UTF-8) support
*/
/*
* ASCII ---> UTF-8
*/
static void
ascii2utf(unsigned char *ascii, unsigned char *utf, int len)
{
ascii2mic(ascii, utf, len);
}
/*
* UTF-8 ---> ASCII
*/
static void
utf2ascii(unsigned char *utf, unsigned char *ascii, int len)
{
mic2ascii(utf, ascii, len);
}
/*
* ISO8859-1 ---> UTF-8
*/
static void
latin1_to_utf(unsigned char *iso, unsigned char *utf, int len)
{
unsigned short c;
while (len-- > 0 && (c = *iso++))
{
if (c < 0x80)
{
*utf++ = c;
}
else
{
*utf++ = (c >> 6) | 0xc0;
*utf++ = (c & 0x003f) | 0x80;
}
}
*utf = '\0';
}
/*
* UTF-8 ---> ISO8859-1
*/
static void
utf_to_latin1(unsigned char *utf, unsigned char *iso, int len)
{
unsigned short c, c1, c2;
while (len > 0 && (c = *utf++))
{
if ((c & 0xe0) == 0xc0)
{
c1 = c & 0x1f;
c2 = *utf++ & 0x3f;
*iso = c1 << 6;
*iso++ |= c2;
len -= 2;
}
else if ((c & 0xe0) == 0xe0)
{
elog(ERROR, "Could not convert UTF-8 to ISO8859-1");
}
else
{
*iso++ = c;
len--;
}
}
*iso = '\0';
}
/*
* comparison routine for bsearch()
* this routine is intended for UTF-8 -> local code
*/
static int compare1(const void *p1, const void *p2)
{
unsigned int v1, v2;
v1 = *(unsigned int *)p1;
v2 = ((pg_utf_to_local *)p2)->utf;
return(v1 - v2);
}
/*
* comparison routine for bsearch()
* this routine is intended for local code -> UTF-8
*/
static int compare2(const void *p1, const void *p2)
{
unsigned int v1, v2;
v1 = *(unsigned int *)p1;
v2 = ((pg_local_to_utf *)p2)->code;
return(v1 - v2);
}
/*
* UTF-8 ---> local code
*/
static void
utf_to_local(unsigned char *utf, unsigned char *iso,
pg_utf_to_local *map, int size, int encoding, int len)
{
unsigned int iutf;
int l;
pg_utf_to_local *p;
pg_encoding_conv_tbl *e;
e = pg_get_enc_ent(encoding);
if (e == 0)
{
elog(ERROR, "Invalid encoding number %d", encoding);
}
for (;len > 0 && *utf; len -= l)
{
l = pg_utf_mblen(utf);
if (l == 1)
{
*iso++ = *utf++;
continue;
}
else if (l == 2)
{
iutf = *utf++ << 8;
iutf |= *utf++;
}
else
{
iutf = *utf++ << 16;
iutf |= *utf++ << 8;
iutf |= *utf++;
}
p = bsearch(&iutf, map, size,
sizeof(pg_utf_to_local), compare1);
if (p == NULL || p->encoding != encoding)
{
elog(NOTICE, "utf_to_latin: could not convert UTF-8 (0x%04x) to %s. Ignored",
iutf, e->name);
/*
printf("utf_to_latin: could not convert UTF-8 (0x%04x) to %s. Ignored",
iutf, e->name);
*/
continue;
}
if (p->code & 0xff000000)
*iso++ = p->code >> 24;
if (p->code & 0x00ff0000)
*iso++ = (p->code & 0x00ff0000) >> 16;
if (p->code & 0x0000ff00)
*iso++ = (p->code & 0x0000ff00) >> 8;
if (p->code & 0x000000ff)
*iso++ = p->code & 0x000000ff;
}
*iso = '\0';
}
/*
* UTF-8 ---> ISO8859-2
*/
static void
utf_to_latin2(unsigned char *utf, unsigned char *iso, int len)
{
utf_to_local(utf, iso, mapISO8859, sizeof(mapISO8859)/sizeof(pg_utf_to_local), LATIN2, len);
}
/*
* UTF-8 ---> ISO8859-3
*/
static void
utf_to_latin3(unsigned char *utf, unsigned char *iso, int len)
{
utf_to_local(utf, iso, mapISO8859, sizeof(mapISO8859)/sizeof(pg_utf_to_local), LATIN3, len);
}
/*
* UTF-8 ---> ISO8859-4
*/
static void
utf_to_latin4(unsigned char *utf, unsigned char *iso, int len)
{
utf_to_local(utf, iso, mapISO8859, sizeof(mapISO8859)/sizeof(pg_utf_to_local), LATIN4, len);
}
/*
* UTF-8 ---> ISO8859-5
*/
static void
utf_to_latin5(unsigned char *utf, unsigned char *iso, int len)
{
utf_to_local(utf, iso, mapISO8859, sizeof(mapISO8859)/sizeof(pg_utf_to_local), LATIN5, len);
}
/*
* local code ---> UTF-8
*/
static void
local_to_utf(unsigned char *iso, unsigned char *utf,
pg_local_to_utf *map, int size, int encoding, int len)
{
unsigned int iiso;
int l;
pg_local_to_utf *p;
pg_encoding_conv_tbl *e;
e = pg_get_enc_ent(encoding);
if (e == 0)
{
elog(ERROR, "Invalid encoding number %d", encoding);
}
for (;len > 0 && *iso; len -= l)
{
if (*iso < 0x80)
{
*utf++ = *iso++;
l = 1;
continue;
}
l = pg_mblen_with_encoding(iso, encoding);
if (l == 1)
{
iiso = *iso++;
}
else if (l == 2)
{
iiso = *iso++ << 8;
iiso |= *iso++;
}
else if (l == 3)
{
iiso = *iso++ << 16;
iiso |= *iso++ << 8;
iiso |= *iso++;
}
else if (l == 4)
{
iiso = *iso++ << 24;
iiso |= *iso++ << 16;
iiso |= *iso++ << 8;
iiso |= *iso++;
}
p = bsearch(&iiso, map, size,
sizeof(pg_local_to_utf), compare2);
if (p == NULL)
{
elog(NOTICE, "local_to_utf: could not convert (0x%04x) %s to UTF-8. Ignored",
iiso, e->name);
/*
printf("local_to_utf: could not convert (0x%04x) %s to UTF-8. Ignored",
iiso, e->name);
*/
continue;
}
if (p->utf & 0xff000000)
*utf++ = p->utf >> 24;
if (p->utf & 0x00ff0000)
*utf++ = (p->utf & 0x00ff0000) >> 16;
if (p->utf & 0x0000ff00)
*utf++ = (p->utf & 0x0000ff00) >> 8;
if (p->utf & 0x000000ff)
*utf++ = p->utf & 0x000000ff;
}
*utf = '\0';
}
/*
* ISO-8859-2 ---> UTF-8
*/
static void
latin2_to_utf(unsigned char *iso, unsigned char *utf, int len)
{
local_to_utf(iso, utf, ISO8859_2, sizeof(ISO8859_2)/sizeof(pg_local_to_utf), LATIN2, len);
}
/*
* ISO-8859-3 ---> UTF-8
*/
static void
latin3_to_utf(unsigned char *iso, unsigned char *utf, int len)
{
local_to_utf(iso, utf, ISO8859_3, sizeof(ISO8859_3)/sizeof(pg_local_to_utf), LATIN2, len);
}
/*
* ISO-8859-4 ---> UTF-8
*/
static void
latin4_to_utf(unsigned char *iso, unsigned char *utf, int len)
{
local_to_utf(iso, utf, ISO8859_4, sizeof(ISO8859_4)/sizeof(pg_local_to_utf), LATIN2, len);
}
/*
* ISO-8859-5 ---> UTF-8
*/
static void
latin5_to_utf(unsigned char *iso, unsigned char *utf, int len)
{
local_to_utf(iso, utf, ISO8859_5, sizeof(ISO8859_5)/sizeof(pg_local_to_utf), LATIN2, len);
}
/*
* UTF-8 ---> EUC_JP
*/
static void
utf_to_euc_jp(unsigned char *utf, unsigned char *euc, int len)
{
utf_to_local(utf, euc, mapUTF_to_EUC_JP,
sizeof(mapUTF_to_EUC_JP)/sizeof(pg_utf_to_local), EUC_JP, len);
}
/*
* EUC_JP ---> UTF-8
*/
static void
euc_jp_to_utf(unsigned char *euc, unsigned char *utf, int len)
{
local_to_utf(euc, utf, mapEUC_JP_to_UTF,
sizeof(mapEUC_JP_to_UTF)/sizeof(pg_local_to_utf), EUC_JP, len);
}
/*-----------------------------------------------------------------*/
pg_encoding_conv_tbl pg_conv_tbl[] = {
{SQL_ASCII, "SQL_ASCII", 0, ascii2mic, mic2ascii}, /* SQL/ACII */
{EUC_JP, "EUC_JP", 0, euc_jp2mic, mic2euc_jp}, /* EUC_JP */
{SQL_ASCII, "SQL_ASCII", 0, ascii2mic, mic2ascii,
ascii2utf, utf2ascii}, /* SQL/ASCII */
{EUC_JP, "EUC_JP", 0, euc_jp2mic, mic2euc_jp,
euc_jp_to_utf, utf_to_euc_jp}, /* EUC_JP */
{EUC_CN, "EUC_CN", 0, euc_cn2mic, mic2euc_cn}, /* EUC_CN */
{EUC_KR, "EUC_KR", 0, euc_kr2mic, mic2euc_kr}, /* EUC_KR */
{EUC_TW, "EUC_TW", 0, euc_tw2mic, mic2euc_tw}, /* EUC_TW */
{UNICODE, "UNICODE", 0, 0, 0}, /* UNICODE */
{MULE_INTERNAL, "MULE_INTERNAL", 0, 0, 0}, /* MULE_INTERNAL */
{LATIN1, "LATIN1", 0, latin12mic, mic2latin1}, /* ISO 8859 Latin 1 */
{LATIN2, "LATIN2", 0, latin22mic, mic2latin2}, /* ISO 8859 Latin 2 */
{LATIN3, "LATIN3", 0, latin32mic, mic2latin3}, /* ISO 8859 Latin 3 */
{LATIN4, "LATIN4", 0, latin42mic, mic2latin4}, /* ISO 8859 Latin 4 */
{LATIN5, "LATIN5", 0, iso2mic, mic2iso}, /* ISO 8859 Latin 5 */
{KOI8, "KOI8", 0, koi2mic, mic2koi}, /* KOI8-R */
{WIN, "WIN", 0, win2mic, mic2win}, /* CP1251 */
{ALT, "ALT", 0, alt2mic, mic2alt}, /* CP866 */
{SJIS, "SJIS", 1, sjis2mic, mic2sjis}, /* SJIS */
{BIG5, "BIG5", 1, big52mic, mic2big5}, /* Big5 */
{WIN1250, "WIN1250", 1, win12502mic, mic2win1250}, /* WIN 1250 */
{-1, "", 0, 0, 0} /* end mark */
{LATIN1, "LATIN1", 0, latin12mic, mic2latin1,
latin1_to_utf, utf_to_latin1}, /* ISO 8859 Latin 1 */
{LATIN2, "LATIN2", 0, latin22mic, mic2latin2,
latin2_to_utf, utf_to_latin2}, /* ISO 8859 Latin 2 */
{LATIN3, "LATIN3", 0, latin32mic, mic2latin3,
latin3_to_utf, utf_to_latin3}, /* ISO 8859 Latin 3 */
{LATIN4, "LATIN4", 0, latin42mic, mic2latin4,
latin4_to_utf, utf_to_latin4}, /* ISO 8859 Latin 4 */
{LATIN5, "LATIN5", 0, iso2mic, mic2iso,
latin5_to_utf, utf_to_latin5}, /* ISO 8859 Latin 5 */
{KOI8, "KOI8", 0, koi2mic, mic2koi,
0, 0}, /* KOI8-R */
{WIN, "WIN", 0, win2mic, mic2win,
0,0}, /* CP1251 */
{ALT, "ALT", 0, alt2mic, mic2alt,
0,0}, /* CP866 */
{SJIS, "SJIS", 1, sjis2mic, mic2sjis,
0,0}, /* SJIS */
{BIG5, "BIG5", 1, big52mic, mic2big5,
0,0}, /* Big5 */
{WIN1250, "WIN1250", 1, win12502mic, mic2win1250,
0,0}, /* WIN 1250 */
{-1, "", 0, 0, 0, 0} /* end mark */
};
static pg_utf_to_local mapISO8859[] = {
{0xc480, 0x00c0, LATIN4},
{0xc481, 0x00e0, LATIN4},
{0xc482, 0x00c3, LATIN2},
{0xc483, 0x00e3, LATIN2},
{0xc484, 0x00a1, LATIN2},
{0xc485, 0x00b1, LATIN2},
{0xc486, 0x00c6, LATIN2},
{0xc487, 0x00e6, LATIN2},
{0xc488, 0x00c6, LATIN3},
{0xc489, 0x00e6, LATIN3},
{0xc48a, 0x00c5, LATIN3},
{0xc48b, 0x00e5, LATIN3},
{0xc48c, 0x00c8, LATIN2},
{0xc48d, 0x00e8, LATIN2},
{0xc48e, 0x00cf, LATIN2},
{0xc48f, 0x00ef, LATIN2},
{0xc490, 0x00d0, LATIN2},
{0xc491, 0x00f0, LATIN2},
{0xc492, 0x00aa, LATIN4},
{0xc493, 0x00ba, LATIN4},
{0xc496, 0x00cc, LATIN4},
{0xc497, 0x00ec, LATIN4},
{0xc498, 0x00ca, LATIN2},
{0xc499, 0x00ea, LATIN2},
{0xc49a, 0x00cc, LATIN2},
{0xc49b, 0x00ec, LATIN2},
{0xc49c, 0x00d8, LATIN3},
{0xc49d, 0x00f8, LATIN3},
{0xc49e, 0x00ab, LATIN3},
{0xc49f, 0x00bb, LATIN3},
{0xc4a0, 0x00d5, LATIN3},
{0xc4a1, 0x00f5, LATIN3},
{0xc4a2, 0x00ab, LATIN4},
{0xc4a3, 0x00bb, LATIN4},
{0xc4a4, 0x00a6, LATIN3},
{0xc4a5, 0x00b6, LATIN3},
{0xc4a6, 0x00a1, LATIN3},
{0xc4a7, 0x00b1, LATIN3},
{0xc4a8, 0x00a5, LATIN4},
{0xc4a9, 0x00b5, LATIN4},
{0xc4aa, 0x00cf, LATIN4},
{0xc4ab, 0x00ef, LATIN4},
{0xc4ae, 0x00c7, LATIN4},
{0xc4af, 0x00e7, LATIN4},
{0xc4b0, 0x00a9, LATIN3},
{0xc4b1, 0x00b9, LATIN3},
{0xc4b4, 0x00ac, LATIN3},
{0xc4b5, 0x00bc, LATIN3},
{0xc4b6, 0x00d3, LATIN4},
{0xc4b7, 0x00f3, LATIN4},
{0xc4b8, 0x00a2, LATIN4},
{0xc4b9, 0x00c5, LATIN2},
{0xc4ba, 0x00e5, LATIN2},
{0xc4bb, 0x00a6, LATIN4},
{0xc4bc, 0x00b6, LATIN4},
{0xc4bd, 0x00a5, LATIN2},
{0xc4be, 0x00b5, LATIN2},
{0xc581, 0x00a3, LATIN2},
{0xc582, 0x00b3, LATIN2},
{0xc583, 0x00d1, LATIN2},
{0xc584, 0x00f1, LATIN2},
{0xc585, 0x00d1, LATIN4},
{0xc586, 0x00f1, LATIN4},
{0xc587, 0x00d2, LATIN2},
{0xc588, 0x00f2, LATIN2},
{0xc58a, 0x00bd, LATIN4},
{0xc58b, 0x00bf, LATIN4},
{0xc58c, 0x00d2, LATIN4},
{0xc58d, 0x00f2, LATIN4},
{0xc590, 0x00d5, LATIN2},
{0xc591, 0x00f5, LATIN2},
{0xc594, 0x00c0, LATIN2},
{0xc595, 0x00e0, LATIN2},
{0xc596, 0x00a3, LATIN4},
{0xc597, 0x00b3, LATIN4},
{0xc598, 0x00d8, LATIN2},
{0xc599, 0x00f8, LATIN2},
{0xc59a, 0x00a6, LATIN2},
{0xc59b, 0x00b6, LATIN2},
{0xc59c, 0x00de, LATIN3},
{0xc59d, 0x00fe, LATIN3},
{0xc59e, 0x00aa, LATIN2},
{0xc59f, 0x00ba, LATIN2},
{0xc5a0, 0x00a9, LATIN2},
{0xc5a1, 0x00b9, LATIN2},
{0xc5a2, 0x00de, LATIN2},
{0xc5a3, 0x00fe, LATIN2},
{0xc5a4, 0x00ab, LATIN2},
{0xc5a5, 0x00bb, LATIN2},
{0xc5a6, 0x00ac, LATIN4},
{0xc5a7, 0x00bc, LATIN4},
{0xc5a8, 0x00dd, LATIN4},
{0xc5a9, 0x00fd, LATIN4},
{0xc5aa, 0x00de, LATIN4},
{0xc5ab, 0x00fe, LATIN4},
{0xc5ac, 0x00dd, LATIN3},
{0xc5ad, 0x00fd, LATIN3},
{0xc5ae, 0x00d9, LATIN2},
{0xc5af, 0x00f9, LATIN2},
{0xc5b0, 0x00db, LATIN2},
{0xc5b1, 0x00fb, LATIN2},
{0xc5b2, 0x00d9, LATIN4},
{0xc5b3, 0x00f9, LATIN4},
{0xc5b9, 0x00ac, LATIN2},
{0xc5ba, 0x00bc, LATIN2},
{0xc5bb, 0x00af, LATIN2},
{0xc5bc, 0x00bf, LATIN2},
{0xc5bd, 0x00ae, LATIN2},
{0xc5be, 0x00be, LATIN2},
{0xcb87, 0x00b7, LATIN2},
{0xcb98, 0x00a2, LATIN2},
{0xcb99, 0x00ff, LATIN2},
{0xcb9b, 0x00b2, LATIN2},
{0xcb9d, 0x00bd, LATIN2},
{0xd081, 0x00a1, LATIN5},
{0xd082, 0x00a2, LATIN5},
{0xd083, 0x00a3, LATIN5},
{0xd084, 0x00a4, LATIN5},
{0xd085, 0x00a5, LATIN5},
{0xd086, 0x00a6, LATIN5},
{0xd087, 0x00a7, LATIN5},
{0xd088, 0x00a8, LATIN5},
{0xd089, 0x00a9, LATIN5},
{0xd08a, 0x00aa, LATIN5},
{0xd08b, 0x00ab, LATIN5},
{0xd08c, 0x00ac, LATIN5},
{0xd08e, 0x00ae, LATIN5},
{0xd08f, 0x00af, LATIN5},
{0xd090, 0x00b0, LATIN5},
{0xd091, 0x00b1, LATIN5},
{0xd092, 0x00b2, LATIN5},
{0xd093, 0x00b3, LATIN5},
{0xd094, 0x00b4, LATIN5},
{0xd095, 0x00b5, LATIN5},
{0xd096, 0x00b6, LATIN5},
{0xd097, 0x00b7, LATIN5},
{0xd098, 0x00b8, LATIN5},
{0xd099, 0x00b9, LATIN5},
{0xd09a, 0x00ba, LATIN5},
{0xd09b, 0x00bb, LATIN5},
{0xd09c, 0x00bc, LATIN5},
{0xd09d, 0x00bd, LATIN5},
{0xd09e, 0x00be, LATIN5},
{0xd09f, 0x00bf, LATIN5},
{0xd0a0, 0x00c0, LATIN5},
{0xd0a1, 0x00c1, LATIN5},
{0xd0a2, 0x00c2, LATIN5},
{0xd0a3, 0x00c3, LATIN5},
{0xd0a4, 0x00c4, LATIN5},
{0xd0a5, 0x00c5, LATIN5},
{0xd0a6, 0x00c6, LATIN5},
{0xd0a7, 0x00c7, LATIN5},
{0xd0a8, 0x00c8, LATIN5},
{0xd0a9, 0x00c9, LATIN5},
{0xd0aa, 0x00ca, LATIN5},
{0xd0ab, 0x00cb, LATIN5},
{0xd0ac, 0x00cc, LATIN5},
{0xd0ad, 0x00cd, LATIN5},
{0xd0ae, 0x00ce, LATIN5},
{0xd0af, 0x00cf, LATIN5},
{0xd0b0, 0x00d0, LATIN5},
{0xd0b1, 0x00d1, LATIN5},
{0xd0b2, 0x00d2, LATIN5},
{0xd0b3, 0x00d3, LATIN5},
{0xd0b4, 0x00d4, LATIN5},
{0xd0b5, 0x00d5, LATIN5},
{0xd0b6, 0x00d6, LATIN5},
{0xd0b7, 0x00d7, LATIN5},
{0xd0b8, 0x00d8, LATIN5},
{0xd0b9, 0x00d9, LATIN5},
{0xd0ba, 0x00da, LATIN5},
{0xd0bb, 0x00db, LATIN5},
{0xd0bc, 0x00dc, LATIN5},
{0xd0bd, 0x00dd, LATIN5},
{0xd0be, 0x00de, LATIN5},
{0xd0bf, 0x00df, LATIN5},
{0xd180, 0x00e0, LATIN5},
{0xd181, 0x00e1, LATIN5},
{0xd182, 0x00e2, LATIN5},
{0xd183, 0x00e3, LATIN5},
{0xd184, 0x00e4, LATIN5},
{0xd185, 0x00e5, LATIN5},
{0xd186, 0x00e6, LATIN5},
{0xd187, 0x00e7, LATIN5},
{0xd188, 0x00e8, LATIN5},
{0xd189, 0x00e9, LATIN5},
{0xd18a, 0x00ea, LATIN5},
{0xd18b, 0x00eb, LATIN5},
{0xd18c, 0x00ec, LATIN5},
{0xd18d, 0x00ed, LATIN5},
{0xd18e, 0x00ee, LATIN5},
{0xd18f, 0x00ef, LATIN5},
{0xd191, 0x00f1, LATIN5},
{0xd192, 0x00f2, LATIN5},
{0xd193, 0x00f3, LATIN5},
{0xd194, 0x00f4, LATIN5},
{0xd195, 0x00f5, LATIN5},
{0xd196, 0x00f6, LATIN5},
{0xd197, 0x00f7, LATIN5},
{0xd198, 0x00f8, LATIN5},
{0xd199, 0x00f9, LATIN5},
{0xd19a, 0x00fa, LATIN5},
{0xd19b, 0x00fb, LATIN5},
{0xd19c, 0x00fc, LATIN5},
{0xd19e, 0x00fe, LATIN5},
{0xd19f, 0x00ff, LATIN5},
{0xe28496, 0x00f0, LATIN5},
};
static pg_local_to_utf ISO8859_2[] = {
{0x00a0, 0xc2a0},
{0x00a1, 0xc484},
{0x00a2, 0xcb98},
{0x00a3, 0xc581},
{0x00a4, 0xc2a4},
{0x00a5, 0xc4bd},
{0x00a6, 0xc59a},
{0x00a7, 0xc2a7},
{0x00a8, 0xc2a8},
{0x00a9, 0xc5a0},
{0x00aa, 0xc59e},
{0x00ab, 0xc5a4},
{0x00ac, 0xc5b9},
{0x00ad, 0xc2ad},
{0x00ae, 0xc5bd},
{0x00af, 0xc5bb},
{0x00b0, 0xc2b0},
{0x00b1, 0xc485},
{0x00b2, 0xcb9b},
{0x00b3, 0xc582},
{0x00b4, 0xc2b4},
{0x00b5, 0xc4be},
{0x00b6, 0xc59b},
{0x00b7, 0xcb87},
{0x00b8, 0xc2b8},
{0x00b9, 0xc5a1},
{0x00ba, 0xc59f},
{0x00bb, 0xc5a5},
{0x00bc, 0xc5ba},
{0x00bd, 0xcb9d},
{0x00be, 0xc5be},
{0x00bf, 0xc5bc},
{0x00c0, 0xc594},
{0x00c1, 0xc381},
{0x00c2, 0xc382},
{0x00c3, 0xc482},
{0x00c4, 0xc384},
{0x00c5, 0xc4b9},
{0x00c6, 0xc486},
{0x00c7, 0xc387},
{0x00c8, 0xc48c},
{0x00c9, 0xc389},
{0x00ca, 0xc498},
{0x00cb, 0xc38b},
{0x00cc, 0xc49a},
{0x00cd, 0xc38d},
{0x00ce, 0xc38e},
{0x00cf, 0xc48e},
{0x00d0, 0xc490},
{0x00d1, 0xc583},
{0x00d2, 0xc587},
{0x00d3, 0xc393},
{0x00d4, 0xc394},
{0x00d5, 0xc590},
{0x00d6, 0xc396},
{0x00d7, 0xc397},
{0x00d8, 0xc598},
{0x00d9, 0xc5ae},
{0x00da, 0xc39a},
{0x00db, 0xc5b0},
{0x00dc, 0xc39c},
{0x00dd, 0xc39d},
{0x00de, 0xc5a2},
{0x00df, 0xc39f},
{0x00e0, 0xc595},
{0x00e1, 0xc3a1},
{0x00e2, 0xc3a2},
{0x00e3, 0xc483},
{0x00e4, 0xc3a4},
{0x00e5, 0xc4ba},
{0x00e6, 0xc487},
{0x00e7, 0xc3a7},
{0x00e8, 0xc48d},
{0x00e9, 0xc3a9},
{0x00ea, 0xc499},
{0x00eb, 0xc3ab},
{0x00ec, 0xc49b},
{0x00ed, 0xc3ad},
{0x00ee, 0xc3ae},
{0x00ef, 0xc48f},
{0x00f0, 0xc491},
{0x00f1, 0xc584},
{0x00f2, 0xc588},
{0x00f3, 0xc3b3},
{0x00f4, 0xc3b4},
{0x00f5, 0xc591},
{0x00f6, 0xc3b6},
{0x00f7, 0xc3b7},
{0x00f8, 0xc599},
{0x00f9, 0xc5af},
{0x00fa, 0xc3ba},
{0x00fb, 0xc5b1},
{0x00fc, 0xc3bc},
{0x00fd, 0xc3bd},
{0x00fe, 0xc5a3},
{0x00ff, 0xcb99},
};
static pg_local_to_utf ISO8859_3[] = {
{0x00a0, 0xc2a0},
{0x00a1, 0xc4a6},
{0x00a2, 0xcb98},
{0x00a3, 0xc2a3},
{0x00a4, 0xc2a4},
{0x00a6, 0xc4a4},
{0x00a7, 0xc2a7},
{0x00a8, 0xc2a8},
{0x00a9, 0xc4b0},
{0x00aa, 0xc59e},
{0x00ab, 0xc49e},
{0x00ac, 0xc4b4},
{0x00ad, 0xc2ad},
{0x00af, 0xc5bb},
{0x00b0, 0xc2b0},
{0x00b1, 0xc4a7},
{0x00b2, 0xc2b2},
{0x00b3, 0xc2b3},
{0x00b4, 0xc2b4},
{0x00b5, 0xc2b5},
{0x00b6, 0xc4a5},
{0x00b7, 0xc2b7},
{0x00b8, 0xc2b8},
{0x00b9, 0xc4b1},
{0x00ba, 0xc59f},
{0x00bb, 0xc49f},
{0x00bc, 0xc4b5},
{0x00bd, 0xc2bd},
{0x00bf, 0xc5bc},
{0x00c0, 0xc380},
{0x00c1, 0xc381},
{0x00c2, 0xc382},
{0x00c4, 0xc384},
{0x00c5, 0xc48a},
{0x00c6, 0xc488},
{0x00c7, 0xc387},
{0x00c8, 0xc388},
{0x00c9, 0xc389},
{0x00ca, 0xc38a},
{0x00cb, 0xc38b},
{0x00cc, 0xc38c},
{0x00cd, 0xc38d},
{0x00ce, 0xc38e},
{0x00cf, 0xc38f},
{0x00d1, 0xc391},
{0x00d2, 0xc392},
{0x00d3, 0xc393},
{0x00d4, 0xc394},
{0x00d5, 0xc4a0},
{0x00d6, 0xc396},
{0x00d7, 0xc397},
{0x00d8, 0xc49c},
{0x00d9, 0xc399},
{0x00da, 0xc39a},
{0x00db, 0xc39b},
{0x00dc, 0xc39c},
{0x00dd, 0xc5ac},
{0x00de, 0xc59c},
{0x00df, 0xc39f},
{0x00e0, 0xc3a0},
{0x00e1, 0xc3a1},
{0x00e2, 0xc3a2},
{0x00e4, 0xc3a4},
{0x00e5, 0xc48b},
{0x00e6, 0xc489},
{0x00e7, 0xc3a7},
{0x00e8, 0xc3a8},
{0x00e9, 0xc3a9},
{0x00ea, 0xc3aa},
{0x00eb, 0xc3ab},
{0x00ec, 0xc3ac},
{0x00ed, 0xc3ad},
{0x00ee, 0xc3ae},
{0x00ef, 0xc3af},
{0x00f1, 0xc3b1},
{0x00f2, 0xc3b2},
{0x00f3, 0xc3b3},
{0x00f4, 0xc3b4},
{0x00f5, 0xc4a1},
{0x00f6, 0xc3b6},
{0x00f7, 0xc3b7},
{0x00f8, 0xc49d},
{0x00f9, 0xc3b9},
{0x00fa, 0xc3ba},
{0x00fb, 0xc3bb},
{0x00fc, 0xc3bc},
{0x00fd, 0xc5ad},
{0x00fe, 0xc59d},
{0x00ff, 0xcb99},
};
static pg_local_to_utf ISO8859_4[] = {
{0x00a0, 0xc2a0},
{0x00a1, 0xc484},
{0x00a2, 0xc4b8},
{0x00a3, 0xc596},
{0x00a4, 0xc2a4},
{0x00a5, 0xc4a8},
{0x00a6, 0xc4bb},
{0x00a7, 0xc2a7},
{0x00a8, 0xc2a8},
{0x00a9, 0xc5a0},
{0x00aa, 0xc492},
{0x00ab, 0xc4a2},
{0x00ac, 0xc5a6},
{0x00ad, 0xc2ad},
{0x00ae, 0xc5bd},
{0x00af, 0xc2af},
{0x00b0, 0xc2b0},
{0x00b1, 0xc485},
{0x00b2, 0xcb9b},
{0x00b3, 0xc597},
{0x00b4, 0xc2b4},
{0x00b5, 0xc4a9},
{0x00b6, 0xc4bc},
{0x00b7, 0xcb87},
{0x00b8, 0xc2b8},
{0x00b9, 0xc5a1},
{0x00ba, 0xc493},
{0x00bb, 0xc4a3},
{0x00bc, 0xc5a7},
{0x00bd, 0xc58a},
{0x00be, 0xc5be},
{0x00bf, 0xc58b},
{0x00c0, 0xc480},
{0x00c1, 0xc381},
{0x00c2, 0xc382},
{0x00c3, 0xc383},
{0x00c4, 0xc384},
{0x00c5, 0xc385},
{0x00c6, 0xc386},
{0x00c7, 0xc4ae},
{0x00c8, 0xc48c},
{0x00c9, 0xc389},
{0x00ca, 0xc498},
{0x00cb, 0xc38b},
{0x00cc, 0xc496},
{0x00cd, 0xc38d},
{0x00ce, 0xc38e},
{0x00cf, 0xc4aa},
{0x00d0, 0xc490},
{0x00d1, 0xc585},
{0x00d2, 0xc58c},
{0x00d3, 0xc4b6},
{0x00d4, 0xc394},
{0x00d5, 0xc395},
{0x00d6, 0xc396},
{0x00d7, 0xc397},
{0x00d8, 0xc398},
{0x00d9, 0xc5b2},
{0x00da, 0xc39a},
{0x00db, 0xc39b},
{0x00dc, 0xc39c},
{0x00dd, 0xc5a8},
{0x00de, 0xc5aa},
{0x00df, 0xc39f},
{0x00e0, 0xc481},
{0x00e1, 0xc3a1},
{0x00e2, 0xc3a2},
{0x00e3, 0xc3a3},
{0x00e4, 0xc3a4},
{0x00e5, 0xc3a5},
{0x00e6, 0xc3a6},
{0x00e7, 0xc4af},
{0x00e8, 0xc48d},
{0x00e9, 0xc3a9},
{0x00ea, 0xc499},
{0x00eb, 0xc3ab},
{0x00ec, 0xc497},
{0x00ed, 0xc3ad},
{0x00ee, 0xc3ae},
{0x00ef, 0xc4ab},
{0x00f0, 0xc491},
{0x00f1, 0xc586},
{0x00f2, 0xc58d},
{0x00f3, 0xc4b7},
{0x00f4, 0xc3b4},
{0x00f5, 0xc3b5},
{0x00f6, 0xc3b6},
{0x00f7, 0xc3b7},
{0x00f8, 0xc3b8},
{0x00f9, 0xc5b3},
{0x00fa, 0xc3ba},
{0x00fb, 0xc3bb},
{0x00fc, 0xc3bc},
{0x00fd, 0xc5a9},
{0x00fe, 0xc5ab},
{0x00ff, 0xcb99},
};
static pg_local_to_utf ISO8859_5[] = {
{0x00a0, 0xc2a0},
{0x00a1, 0xd081},
{0x00a2, 0xd082},
{0x00a3, 0xd083},
{0x00a4, 0xd084},
{0x00a5, 0xd085},
{0x00a6, 0xd086},
{0x00a7, 0xd087},
{0x00a8, 0xd088},
{0x00a9, 0xd089},
{0x00aa, 0xd08a},
{0x00ab, 0xd08b},
{0x00ac, 0xd08c},
{0x00ad, 0xc2ad},
{0x00ae, 0xd08e},
{0x00af, 0xd08f},
{0x00b0, 0xd090},
{0x00b1, 0xd091},
{0x00b2, 0xd092},
{0x00b3, 0xd093},
{0x00b4, 0xd094},
{0x00b5, 0xd095},
{0x00b6, 0xd096},
{0x00b7, 0xd097},
{0x00b8, 0xd098},
{0x00b9, 0xd099},
{0x00ba, 0xd09a},
{0x00bb, 0xd09b},
{0x00bc, 0xd09c},
{0x00bd, 0xd09d},
{0x00be, 0xd09e},
{0x00bf, 0xd09f},
{0x00c0, 0xd0a0},
{0x00c1, 0xd0a1},
{0x00c2, 0xd0a2},
{0x00c3, 0xd0a3},
{0x00c4, 0xd0a4},
{0x00c5, 0xd0a5},
{0x00c6, 0xd0a6},
{0x00c7, 0xd0a7},
{0x00c8, 0xd0a8},
{0x00c9, 0xd0a9},
{0x00ca, 0xd0aa},
{0x00cb, 0xd0ab},
{0x00cc, 0xd0ac},
{0x00cd, 0xd0ad},
{0x00ce, 0xd0ae},
{0x00cf, 0xd0af},
{0x00d0, 0xd0b0},
{0x00d1, 0xd0b1},
{0x00d2, 0xd0b2},
{0x00d3, 0xd0b3},
{0x00d4, 0xd0b4},
{0x00d5, 0xd0b5},
{0x00d6, 0xd0b6},
{0x00d7, 0xd0b7},
{0x00d8, 0xd0b8},
{0x00d9, 0xd0b9},
{0x00da, 0xd0ba},
{0x00db, 0xd0bb},
{0x00dc, 0xd0bc},
{0x00dd, 0xd0bd},
{0x00de, 0xd0be},
{0x00df, 0xd0bf},
{0x00e0, 0xd180},
{0x00e1, 0xd181},
{0x00e2, 0xd182},
{0x00e3, 0xd183},
{0x00e4, 0xd184},
{0x00e5, 0xd185},
{0x00e6, 0xd186},
{0x00e7, 0xd187},
{0x00e8, 0xd188},
{0x00e9, 0xd189},
{0x00ea, 0xd18a},
{0x00eb, 0xd18b},
{0x00ec, 0xd18c},
{0x00ed, 0xd18d},
{0x00ee, 0xd18e},
{0x00ef, 0xd18f},
{0x00f0, 0xe28496},
{0x00f1, 0xd191},
{0x00f2, 0xd192},
{0x00f3, 0xd193},
{0x00f4, 0xd194},
{0x00f5, 0xd195},
{0x00f6, 0xd196},
{0x00f7, 0xd197},
{0x00f8, 0xd198},
{0x00f9, 0xd199},
{0x00fa, 0xd19a},
{0x00fb, 0xd19b},
{0x00fc, 0xd19c},
{0x00fd, 0xc2a7},
{0x00fe, 0xd19e},
{0x00ff, 0xd19f},
};
#include <stdio.h>
#include <string.h>
#include "mb/pg_wchar.h"
#define LIKE_FALSE 0
#define LIKE_TRUE 1
#define LIKE_ABORT 2
#define PG_CHAR unsigned char
#define UCHARMAX 0xff
/*----------------------------------------------------------------*/
static int wchareq(unsigned char *p1, unsigned char *p2)
{
int l;
l = pg_mblen(p1);
if (pg_mblen(p2) != l) {
return(0);
}
while (l--) {
if (*p1++ != *p2++)
return(0);
}
return(1);
}
static int iwchareq(unsigned char *p1, unsigned char *p2)
{
int c1, c2;
int l;
/* short cut. if *p1 and *p2 is lower than UCHARMAX, then
we assume they are ASCII */
if (*p1 < UCHARMAX && *p2 < UCHARMAX)
return(tolower(*p1) == tolower(*p2));
if (*p1 < UCHARMAX)
c1 = tolower(*p1);
else
{
l = pg_mblen(p1);
(void)pg_mb2wchar_with_len(p1, (pg_wchar *)&c1, l);
c1 = tolower(c1);
}
if (*p2 < UCHARMAX)
c2 = tolower(*p2);
else
{
l = pg_mblen(p2);
(void)pg_mb2wchar_with_len(p2, (pg_wchar *)&c2, l);
c2 = tolower(c2);
}
return(c1 == c2);
}
#ifdef MULTIBYTE
#define CHAREQ(p1, p2) wchareq(p1, p2)
#define ICHAREQ(p1, p2) iwchareq(p1, p2)
#define NextChar(p, plen) {int __l = pg_mblen(p); (p) +=__l; (plen) -=__l;}
#else
#define CHAREQ(p1, p2) (*(p1) == *(p2))
#define ICHAREQ(p1, p2) (tolower(*(p1)) == tolower(*(p2)))
#define NextChar(p, plen) (p)++, (plen)--
#endif
static int
MatchText(PG_CHAR * t, int tlen, PG_CHAR * p, int plen, char *e)
{
/* Fast path for match-everything pattern
* Include weird case of escape character as a percent sign or underscore,
* when presumably that wildcard character becomes a literal.
*/
if ((plen == 1) && (*p == '%')
&& ! ((e != NULL) && (*e == '%')))
return LIKE_TRUE;
while ((tlen > 0) && (plen > 0))
{
/* If an escape character was specified and we find it here in the pattern,
* then we'd better have an exact match for the next character.
*/
if ((e != NULL) && CHAREQ(p,e))
{
NextChar(p, plen);
if ((plen <= 0) || !CHAREQ(t,p))
return LIKE_FALSE;
}
else if (*p == '%')
{
/* %% is the same as % according to the SQL standard */
/* Advance past all %'s */
while ((plen > 0) && (*p == '%'))
NextChar(p, plen);
/* Trailing percent matches everything. */
if (plen <= 0)
return LIKE_TRUE;
/*
* Otherwise, scan for a text position at which we can
* match the rest of the pattern.
*/
while (tlen > 0)
{
/*
* Optimization to prevent most recursion: don't
* recurse unless first pattern char might match this
* text char.
*/
if (CHAREQ(t,p) || (*p == '_')
|| ((e != NULL) && CHAREQ(p,e)))
{
int matched = MatchText(t, tlen, p, plen, e);
if (matched != LIKE_FALSE)
return matched; /* TRUE or ABORT */
}
NextChar(t, tlen);
}
/*
* End of text with no match, so no point in trying later
* places to start matching this pattern.
*/
return LIKE_ABORT;
}
else if ((*p != '_') && !CHAREQ(t,p))
{
/* Not the single-character wildcard and no explicit match?
* Then time to quit...
*/
return LIKE_FALSE;
}
NextChar(t, tlen);
NextChar(p, plen);
}
if (tlen > 0)
return LIKE_FALSE; /* end of pattern, but not of text */
/* End of input string. Do we have matching pattern remaining? */
while ((plen > 0) && (*p == '%')) /* allow multiple %'s at end of pattern */
NextChar(p, plen);
if (plen <= 0)
return LIKE_TRUE;
/*
* End of text with no match, so no point in trying later places to
* start matching this pattern.
*/
return LIKE_ABORT;
} /* MatchText() */
static int
MatchTextLower(PG_CHAR * t, int tlen, PG_CHAR * p, int plen, char *e)
{
/* Fast path for match-everything pattern
* Include weird case of escape character as a percent sign or underscore,
* when presumably that wildcard character becomes a literal.
*/
if ((plen == 1) && (*p == '%')
&& ! ((e != NULL) && (*e == '%')))
return LIKE_TRUE;
while ((tlen > 0) && (plen > 0))
{
/* If an escape character was specified and we find it here in the pattern,
* then we'd better have an exact match for the next character.
*/
if ((e != NULL) && ICHAREQ(p,e))
{
NextChar(p, plen);
if ((plen <= 0) || !ICHAREQ(t,p))
return LIKE_FALSE;
}
else if (*p == '%')
{
/* %% is the same as % according to the SQL standard */
/* Advance past all %'s */
while ((plen > 0) && (*p == '%'))
NextChar(p, plen);
/* Trailing percent matches everything. */
if (plen <= 0)
return LIKE_TRUE;
/*
* Otherwise, scan for a text position at which we can
* match the rest of the pattern.
*/
while (tlen > 0)
{
/*
* Optimization to prevent most recursion: don't
* recurse unless first pattern char might match this
* text char.
*/
if (ICHAREQ(t,p) || (*p == '_')
|| ((e != NULL) && ICHAREQ(p,e)))
{
int matched = MatchText(t, tlen, p, plen, e);
if (matched != LIKE_FALSE)
return matched; /* TRUE or ABORT */
}
NextChar(t, tlen);
}
/*
* End of text with no match, so no point in trying later
* places to start matching this pattern.
*/
return LIKE_ABORT;
}
else if ((*p != '_') && !ICHAREQ(t,p))
{
return LIKE_FALSE;
}
NextChar(t, tlen);
NextChar(p, plen);
}
if (tlen > 0)
return LIKE_FALSE; /* end of pattern, but not of text */
/* End of input string. Do we have matching pattern remaining? */
while ((plen > 0) && (*p == '%')) /* allow multiple %'s at end of pattern */
NextChar(p, plen);
if (plen <= 0)
return LIKE_TRUE;
/*
* End of text with no match, so no point in trying later places to
* start matching this pattern.
*/
return LIKE_ABORT;
} /* MatchTextLower() */
main()
{
unsigned char *t = "Z01";
unsigned char *p = "_Z%";
int tlen, plen;
tlen = strlen(t);
plen = strlen(p);
printf("%d\n",MatchTextLower(t,tlen,p,plen,"\\"));
}
......@@ -3,7 +3,7 @@
* client encoding and server internal encoding.
* (currently mule internal code (mic) is used)
* Tatsuo Ishii
* $Id: mbutils.c,v 1.11 2000/08/27 10:40:48 ishii Exp $ */
* $Id: mbutils.c,v 1.12 2000/10/12 06:06:50 ishii Exp $ */
#include "postgres.h"
......@@ -21,8 +21,8 @@ static void (*server_from_mic) (); /* MIC to something */
/*
* find encoding table entry by encoding
*/
static pg_encoding_conv_tbl *
get_enc_ent(int encoding)
pg_encoding_conv_tbl *
pg_get_enc_ent(int encoding)
{
pg_encoding_conv_tbl *p = pg_conv_tbl;
......@@ -35,8 +35,8 @@ get_enc_ent(int encoding)
}
/*
* set the client encoding. if client/server encoding is
* not supported, returns -1
* set the client encoding. if encoding conversion between
* client/server encoding is not supported, returns -1
*/
int
pg_set_client_encoding(int encoding)
......@@ -52,8 +52,8 @@ pg_set_client_encoding(int encoding)
}
else if (current_server_encoding == MULE_INTERNAL)
{ /* server == MULE_INETRNAL? */
client_to_mic = get_enc_ent(encoding)->to_mic;
client_from_mic = get_enc_ent(encoding)->from_mic;
client_to_mic = pg_get_enc_ent(encoding)->to_mic;
client_from_mic = pg_get_enc_ent(encoding)->from_mic;
server_to_mic = server_from_mic = 0;
if (client_to_mic == 0 || client_from_mic == 0)
return (-1);
......@@ -61,17 +61,33 @@ pg_set_client_encoding(int encoding)
else if (encoding == MULE_INTERNAL)
{ /* client == MULE_INETRNAL? */
client_to_mic = client_from_mic = 0;
server_to_mic = get_enc_ent(current_server_encoding)->to_mic;
server_from_mic = get_enc_ent(current_server_encoding)->from_mic;
server_to_mic = pg_get_enc_ent(current_server_encoding)->to_mic;
server_from_mic = pg_get_enc_ent(current_server_encoding)->from_mic;
if (server_to_mic == 0 || server_from_mic == 0)
return (-1);
}
else if (current_server_encoding == UNICODE)
{ /* server == UNICODE? */
client_to_mic = pg_get_enc_ent(encoding)->to_unicode;
client_from_mic = pg_get_enc_ent(encoding)->from_unicode;
server_to_mic = server_from_mic = 0;
if (client_to_mic == 0 || client_from_mic == 0)
return (-1);
}
else if (encoding == UNICODE)
{ /* client == UNICODE? */
client_to_mic = client_from_mic = 0;
server_to_mic = pg_get_enc_ent(current_server_encoding)->to_unicode;
server_from_mic = pg_get_enc_ent(current_server_encoding)->from_unicode;
if (server_to_mic == 0 || server_from_mic == 0)
return (-1);
}
else
{
client_to_mic = get_enc_ent(encoding)->to_mic;
client_from_mic = get_enc_ent(encoding)->from_mic;
server_to_mic = get_enc_ent(current_server_encoding)->to_mic;
server_from_mic = get_enc_ent(current_server_encoding)->from_mic;
client_to_mic = pg_get_enc_ent(encoding)->to_mic;
client_from_mic = pg_get_enc_ent(encoding)->from_mic;
server_to_mic = pg_get_enc_ent(current_server_encoding)->to_mic;
server_from_mic = pg_get_enc_ent(current_server_encoding)->from_mic;
if (client_to_mic == 0 || client_from_mic == 0)
return (-1);
if (server_to_mic == 0 || server_from_mic == 0)
......@@ -193,6 +209,13 @@ pg_mblen(const unsigned char *mbstr)
return ((*pg_wchar_table[GetDatabaseEncoding()].mblen) (mbstr));
}
/* returns the byte length of a multi-byte word with specified enciding */
int
pg_mblen_with_encoding(const unsigned char *mbstr, int encoding)
{
return ((*pg_wchar_table[encoding].mblen) (mbstr));
}
/* returns the length (counted as a wchar) of a multi-byte string */
int
pg_mbstrlen(const unsigned char *mbstr)
......
#include "postgres.h"
#include "utils/memutils.h"
void
elog(int lev, const char *fmt,...)
{
printf(fmt);
}
MemoryContext CurrentMemoryContext;
void *
MemoryContextAlloc(MemoryContext context, Size size)
{
}
void
pfree(void *pointer)
{
}
void *
repalloc(void *pointer, Size size)
{
}
static struct
{
unsigned short int nec; /* SJIS UDC (NEC selection IBM kanji) */
unsigned short int sjis; /* SJIS UDC (IBM kanji) */
int euc; /* EUC_JP */
} ibmkanji[] = {
{ 0xEEEF , 0xfa40 , 0x8ff3f3 },
{ 0xEEF0 , 0xfa41 , 0x8ff3f4 },
{ 0xEEF1 , 0xfa42 , 0x8ff3f5 },
{ 0xEEF2 , 0xfa43 , 0x8ff3f6 },
{ 0xEEF3 , 0xfa44 , 0x8ff3f7 },
{ 0xEEF4 , 0xfa45 , 0x8ff3f8 },
{ 0xEEF5 , 0xfa46 , 0x8ff3f9 },
{ 0xEEF6 , 0xfa47 , 0x8ff3fa },
{ 0xEEF7 , 0xfa48 , 0x8ff3fb },
{ 0xEEF8 , 0xfa49 , 0x8ff3fc },
{ 0x8754 , 0xfa4a , 0x8ff3fd },
{ 0x8755 , 0xfa4b , 0x8ff3fe },
{ 0x8756 , 0xfa4c , 0x8ff4a1 },
{ 0x8757 , 0xfa4d , 0x8ff4a2 },
{ 0x8758 , 0xfa4e , 0x8ff4a3 },
{ 0x8759 , 0xfa4f , 0x8ff4a4 },
{ 0x875A , 0xfa50 , 0x8ff4a5 },
{ 0x875B , 0xfa51 , 0x8ff4a6 },
{ 0x875C , 0xfa52 , 0x8ff4a7 },
{ 0x875D , 0xfa53 , 0x8ff4a8 },
{ 0xEEF9 , 0xfa54 , 0xa2cc },
{ 0xEEFA , 0xfa55 , 0x8fa2c3 },
{ 0xEEFB , 0xfa56 , 0x8ff4a9 },
{ 0xEEFC , 0xfa57 , 0x8ff4aa },
{ 0x878A , 0xfa58 , 0x8ff4ab },
{ 0x8782 , 0xfa59 , 0x8ff4ac },
{ 0x8784 , 0xfa5a , 0x8ff4ad },
{ 0x879A , 0xfa5b , 0xa2e8 },
{ 0xED40 , 0xfa5c , 0x8fd4e3 },
{ 0xED41 , 0xfa5d , 0x8fdcdf },
{ 0xED42 , 0xfa5e , 0x8fe4e9 },
{ 0xED43 , 0xfa5f , 0x8fe3f8 },
{ 0xED44 , 0xfa60 , 0x8fd9a1 },
{ 0xED45 , 0xfa61 , 0x8fb1bb },
{ 0xED46 , 0xfa62 , 0x8ff4ae },
{ 0xED47 , 0xfa63 , 0x8fc2ad },
{ 0xED48 , 0xfa64 , 0x8fc3fc },
{ 0xED49 , 0xfa65 , 0x8fe4d0 },
{ 0xED4A , 0xfa66 , 0x8fc2bf },
{ 0xED4B , 0xfa67 , 0x8fbcf4 },
{ 0xED4C , 0xfa68 , 0x8fb0a9 },
{ 0xED4D , 0xfa69 , 0x8fb0c8 },
{ 0xED4E , 0xfa6a , 0x8ff4af },
{ 0xED4F , 0xfa6b , 0x8fb0d2 },
{ 0xED50 , 0xfa6c , 0x8fb0d4 },
{ 0xED51 , 0xfa6d , 0x8fb0e3 },
{ 0xED52 , 0xfa6e , 0x8fb0ee },
{ 0xED53 , 0xfa6f , 0x8fb1a7 },
{ 0xED54 , 0xfa70 , 0x8fb1a3 },
{ 0xED55 , 0xfa71 , 0x8fb1ac },
{ 0xED56 , 0xfa72 , 0x8fb1a9 },
{ 0xED57 , 0xfa73 , 0x8fb1be },
{ 0xED58 , 0xfa74 , 0x8fb1df },
{ 0xED59 , 0xfa75 , 0x8fb1d8 },
{ 0xED5A , 0xfa76 , 0x8fb1c8 },
{ 0xED5B , 0xfa77 , 0x8fb1d7 },
{ 0xED5C , 0xfa78 , 0x8fb1e3 },
{ 0xED5D , 0xfa79 , 0x8fb1f4 },
{ 0xED5E , 0xfa7a , 0x8fb1e1 },
{ 0xED5F , 0xfa7b , 0x8fb2a3 },
{ 0xED60 , 0xfa7c , 0x8ff4b0 },
{ 0xED61 , 0xfa7d , 0x8fb2bb },
{ 0xED62 , 0xfa7e , 0x8fb2e6 },
{ 0xED63 , 0xfa80 , 0x8fb2ed },
{ 0xED64 , 0xfa81 , 0x8fb2f5 },
{ 0xED65 , 0xfa82 , 0x8fb2fc },
{ 0xED66 , 0xfa83 , 0x8ff4b1 },
{ 0xED67 , 0xfa84 , 0x8fb3b5 },
{ 0xED68 , 0xfa85 , 0x8fb3d8 },
{ 0xED69 , 0xfa86 , 0x8fb3db },
{ 0xED6A , 0xfa87 , 0x8fb3e5 },
{ 0xED6B , 0xfa88 , 0x8fb3ee },
{ 0xED6C , 0xfa89 , 0x8fb3fb },
{ 0xED6D , 0xfa8a , 0x8ff4b2 },
{ 0xED6E , 0xfa8b , 0x8ff4b3 },
{ 0xED6F , 0xfa8c , 0x8fb4c0 },
{ 0xED70 , 0xfa8d , 0x8fb4c7 },
{ 0xED71 , 0xfa8e , 0x8fb4d0 },
{ 0xED72 , 0xfa8f , 0x8fb4de },
{ 0xED73 , 0xfa90 , 0x8ff4b4 },
{ 0xED74 , 0xfa91 , 0x8fb5aa },
{ 0xED75 , 0xfa92 , 0x8ff4b5 },
{ 0xED76 , 0xfa93 , 0x8fb5af },
{ 0xED77 , 0xfa94 , 0x8fb5c4 },
{ 0xED78 , 0xfa95 , 0x8fb5e8 },
{ 0xED79 , 0xfa96 , 0x8ff4b6 },
{ 0xED7A , 0xfa97 , 0x8fb7c2 },
{ 0xED7B , 0xfa98 , 0x8fb7e4 },
{ 0xED7C , 0xfa99 , 0x8fb7e8 },
{ 0xED7D , 0xfa9a , 0x8fb7e7 },
{ 0xED7E , 0xfa9b , 0x8ff4b7 },
{ 0xED80 , 0xfa9c , 0x8ff4b8 },
{ 0xED81 , 0xfa9d , 0x8ff4b9 },
{ 0xED82 , 0xfa9e , 0x8fb8ce },
{ 0xED83 , 0xfa9f , 0x8fb8e1 },
{ 0xED84 , 0xfaa0 , 0x8fb8f5 },
{ 0xED85 , 0xfaa1 , 0x8fb8f7 },
{ 0xED86 , 0xfaa2 , 0x8fb8f8 },
{ 0xED87 , 0xfaa3 , 0x8fb8fc },
{ 0xED88 , 0xfaa4 , 0x8fb9af },
{ 0xED89 , 0xfaa5 , 0x8fb9b7 },
{ 0xED8A , 0xfaa6 , 0x8fbabe },
{ 0xED8B , 0xfaa7 , 0x8fbadb },
{ 0xED8C , 0xfaa8 , 0x8fcdaa },
{ 0xED8D , 0xfaa9 , 0x8fbae1 },
{ 0xED8E , 0xfaaa , 0x8ff4ba },
{ 0xED8F , 0xfaab , 0x8fbaeb },
{ 0xED90 , 0xfaac , 0x8fbbb3 },
{ 0xED91 , 0xfaad , 0x8fbbb8 },
{ 0xED92 , 0xfaae , 0x8ff4bb },
{ 0xED93 , 0xfaaf , 0x8fbbca },
{ 0xED94 , 0xfab0 , 0x8ff4bc },
{ 0xED95 , 0xfab1 , 0x8ff4bd },
{ 0xED96 , 0xfab2 , 0x8fbbd0 },
{ 0xED97 , 0xfab3 , 0x8fbbde },
{ 0xED98 , 0xfab4 , 0x8fbbf4 },
{ 0xED99 , 0xfab5 , 0x8fbbf5 },
{ 0xED9A , 0xfab6 , 0x8fbbf9 },
{ 0xED9B , 0xfab7 , 0x8fbce4 },
{ 0xED9C , 0xfab8 , 0x8fbced },
{ 0xED9D , 0xfab9 , 0x8fbcfe },
{ 0xED9E , 0xfaba , 0x8ff4be },
{ 0xED9F , 0xfabb , 0x8fbdc2 },
{ 0xEDA0 , 0xfabc , 0x8fbde7 },
{ 0xEDA1 , 0xfabd , 0x8ff4bf },
{ 0xEDA2 , 0xfabe , 0x8fbdf0 },
{ 0xEDA3 , 0xfabf , 0x8fbeb0 },
{ 0xEDA4 , 0xfac0 , 0x8fbeac },
{ 0xEDA5 , 0xfac1 , 0x8ff4c0 },
{ 0xEDA6 , 0xfac2 , 0x8fbeb3 },
{ 0xEDA7 , 0xfac3 , 0x8fbebd },
{ 0xEDA8 , 0xfac4 , 0x8fbecd },
{ 0xEDA9 , 0xfac5 , 0x8fbec9 },
{ 0xEDAA , 0xfac6 , 0x8fbee4 },
{ 0xEDAB , 0xfac7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bfb , 0x8fe9d1 },
{ 0xEEE0 , 0xfbfc , 0x8ff4fb },
{ 0xEEE1 , 0xfc40 , 0x8fe9ed },
{ 0xEEE2 , 0xfc41 , 0x8feacd },
{ 0xEEE3 , 0xfc42 , 0x8ff4fc },
{ 0xEEE4 , 0xfc43 , 0x8feadb },
{ 0xEEE5 , 0xfc44 , 0x8feae6 },
{ 0xEEE6 , 0xfc45 , 0x8feaea },
{ 0xEEE7 , 0xfc46 , 0x8feba5 },
{ 0xEEE8 , 0xfc47 , 0x8febfb },
{ 0xEEE9 , 0xfc48 , 0x8febfa },
{ 0xEEEA , 0xfc49 , 0x8ff4fd },
{ 0xEEEB , 0xfc4a , 0x8fecd6 },
{ 0xEEEC , 0xfc4b , 0x8ff4fe },
{ 0xffff , 0xffff , 0xffff } /* Stop code */
};
/*
* testing for sjis2mic() and mic2sjis()
*/
#include "conv.c"
int
main()
{
unsigned char eucbuf[1024];
unsigned char sjisbuf[1024];
unsigned char sjis[] = {0x81, 0x40, 0xa1, 0xf0, 0x40, 0xf0, 0x9e, 0xf5, 0x40, 0xfa, 0x40, 0xfa, 0x54, 0xfa, 0x7b, 0x00};
int i;
sjis2mic(sjis, eucbuf, 1024);
for (i = 0; i < 1024; i++)
{
if (eucbuf[i])
printf("%02x ", eucbuf[i]);
else
{
printf("\n");
break;
}
}
mic2sjis(eucbuf, sjisbuf, 1024);
for (i = 0; i < 1024; i++)
{
if (sjisbuf[i])
printf("%02x ", sjisbuf[i]);
else
{
printf("\n");
break;
}
}
return (0);
}
/*
* $Id: uconv.c,v 1.1 2000/10/12 06:06:50 ishii Exp $
*/
#include "pg_wchar.h"
/*
* convert UCS-2 to UTF-8
* returns number of bytes of a UTF-8, that is atmost 3.
*/
static int
pg_ucs2utf(const unsigned short ucs, unsigned char *utf)
{
int len;
if (ucs <= 0x007f)
{
*utf = ucs;
len = 1;
}
else if (ucs > 0x007f && ucs <= 0x07ff)
{
*utf++ = (ucs >> 6) | 0xc0;
*utf = (ucs & 0x003f) | 0x80;
len = 2;
}
else
{
*utf++ = (ucs >> 12) | 0xe0;
*utf++ = ((ucs & 0x0fc0) >> 6) | 0x80;
*utf = (ucs & 0x003f) | 0x80;
len = 3;
}
return (len);
}
typedef struct
{
unsigned short ucs; /* UCS-2 */
unsigned short code; /* local code */
unsigned char encoding; /* encoding */
} ucs_to_local;
typedef struct
{
unsigned short code; /* local code */
unsigned short ucs; /* UCS-2 */
} local_to_ucs;
#include "ucs_to_iso8859.map"
#include "iso88592.rev"
#include "iso88593.rev"
#include "iso88594.rev"
#include "iso88595.rev"
#define X0208 0
#define X0212 1
#include "ucs_to_jis.map"
int
main()
{
int i,j;
int l;
unsigned int euc;
unsigned char u[4];
FILE *fd;
printf("static pg_utf_to_local mapISO8859[] = {\n");
for (i=0;i<sizeof(mapISO8859)/sizeof(ucs_to_local);i++) {
if (mapISO8859[i].encoding > LATIN5)
continue;
l = pg_ucs2utf(mapISO8859[i].ucs, u);
printf(" {0x");
for(j=0;j<l;j++) {
printf("%02x", u[j]);
}
printf(", 0x%04x, %s},\n",
mapISO8859[i].code|0x80,
pg_get_enc_ent(mapISO8859[i].encoding)->name);
}
printf("};\n");
printf("\nstatic pg_local_to_utf ISO8859_2[] = {\n");
for (i=0;i<sizeof(revISO8859_2)/sizeof(local_to_ucs);i++) {
l = pg_ucs2utf(revISO8859_2[i].ucs, u);
printf(" {0x%04x, ", revISO8859_2[i].code|0x80);
printf("0x");
for(j=0;j<l;j++) {
printf("%02x", u[j]);
}
printf("},\n");
}
printf("};\n");
printf("\nstatic pg_local_to_utf ISO8859_3[] = {\n");
for (i=0;i<sizeof(revISO8859_3)/sizeof(local_to_ucs);i++) {
l = pg_ucs2utf(revISO8859_3[i].ucs, u);
printf(" {0x%04x, ", revISO8859_3[i].code|0x80);
printf("0x");
for(j=0;j<l;j++) {
printf("%02x", u[j]);
}
printf("},\n");
}
printf("};\n");
printf("\nstatic pg_local_to_utf ISO8859_4[] = {\n");
for (i=0;i<sizeof(revISO8859_4)/sizeof(local_to_ucs);i++) {
l = pg_ucs2utf(revISO8859_4[i].ucs, u);
printf(" {0x%04x, ", revISO8859_4[i].code|0x80);
printf("0x");
for(j=0;j<l;j++) {
printf("%02x", u[j]);
}
printf("},\n");
}
printf("};\n");
printf("\nstatic pg_local_to_utf ISO8859_5[] = {\n");
for (i=0;i<sizeof(revISO8859_5)/sizeof(local_to_ucs);i++) {
l = pg_ucs2utf(revISO8859_5[i].ucs, u);
printf(" {0x%04x, ", revISO8859_5[i].code|0x80);
printf("0x");
for(j=0;j<l;j++) {
printf("%02x", u[j]);
}
printf("},\n");
}
printf("};\n");
fd = fopen("UTF_to_EUC_JP.map", "w");
fprintf(fd, "static pg_utf_to_local mapUTF_to_EUC_JP[] = {\n");
for (i=0;i<sizeof(mapJIS)/sizeof(ucs_to_local);i++) {
l = pg_ucs2utf(mapJIS[i].ucs, u);
fprintf(fd, " {0x");
for(j=0;j<l;j++) {
fprintf(fd, "%02x", u[j]);
}
if (mapJIS[i].encoding == X0208)
{
euc = mapJIS[i].code|0x8080;
}
else
{
euc = SS3 << 16 | mapJIS[i].code | 0x8080;
}
fprintf(fd, ", 0x%04x, %s},\n",
euc,
"EUC_JP");
}
fprintf(fd, "};\n");
fclose(fd);
return(0);
}
/*
* $Id: uconv2.c,v 1.1 2000/10/12 06:06:50 ishii Exp $
*/
#include "pg_wchar.h"
#include "UTF_to_EUC_JP.map"
static int compare1(const void *p1, const void *p2)
{
unsigned int v1, v2;
v1 = ((pg_utf_to_local *)p1)->code;
v2 = ((pg_utf_to_local *)p2)->code;
return(v1 - v2);
}
int
main()
{
int i;
FILE *fd;
qsort(mapUTF_to_EUC_JP, sizeof(mapUTF_to_EUC_JP)/sizeof(pg_utf_to_local),
sizeof(pg_utf_to_local),compare1);
fd = fopen("EUC_JP_to_UTF.map", "w");
fprintf(fd, "static pg_local_to_utf mapEUC_JP_to_UTF[] = {\n");
for (i=0;i<sizeof(mapUTF_to_EUC_JP)/sizeof(pg_utf_to_local);i++) {
fprintf(fd, " {0x%08x, 0x%08x},\n",
mapUTF_to_EUC_JP[i].code,
mapUTF_to_EUC_JP[i].utf);
}
fprintf(fd, "};\n");
fclose(fd);
return(0);
}
/*
* testing of utf2wchar()
* $Id: utftest.c,v 1.3 1999/07/15 23:03:31 momjian Exp $
* $Id: utftest.c,v 1.4 2000/10/12 06:06:50 ishii Exp $
*/
#include "regex/regex.h"
#include "regex/utils.h"
#include "regex/regex2.h"
#include "regex/pg_wchar.h"
#include "conv.c"
#include "wchar.c"
#include "mbutils.c"
int
main()
{
/* Example 1 from RFC2044 */
......@@ -21,11 +19,17 @@ main()
char *utf[] = {utf1, utf2, utf3};
pg_wchar ucs[128];
pg_wchar *p;
unsigned char iso[1024];
int i;
/* UTF8-->ISO8859-2 test */
unsigned char utf_iso8859_2[] = {0x01, 0x00, 0x01, 0x02, 0x01, 0x55, 0x02, 0xdd, 0x00};
printf("===== testing of pg_utf2wchar_with_len =====\n");
for (i = 0; i < sizeof(utf) / sizeof(char *); i++)
{
pg_utf2wchar(utf[i], ucs);
pg_utf2wchar_with_len(utf[i], ucs, 128);
p = ucs;
while (*p)
{
......@@ -34,4 +38,16 @@ main()
}
printf("\n");
}
printf("===== testing of utf_to_latin2 =====\n");
utf_to_latin(utf_iso8859_2, iso, LATIN2, 128);
for (i = 0; i < sizeof(iso) / sizeof(char *); i++)
{
printf("%04x ", iso[i]);
if (iso[i] == 0x00)
break;
}
printf("\n");
return(0);
}
/*
* conversion functions between pg_wchar and multi-byte streams.
* Tatsuo Ishii
* $Id: wchar.c,v 1.12 2000/08/27 10:40:48 ishii Exp $
* $Id: wchar.c,v 1.13 2000/10/12 06:06:50 ishii Exp $
*
* WIN1250 client encoding updated by Pavel Behal
*
......@@ -246,7 +246,7 @@ pg_euctw_mblen(const unsigned char *s)
}
/*
* convert UTF-8 to pg_wchar (UCS-2)
* convert UTF-8 string to pg_wchar (UCS-2)
* caller should allocate enough space for "to"
* len: length of from.
* "from" not necessarily null terminated.
......@@ -296,7 +296,10 @@ pg_utf2wchar_with_len(const unsigned char *from, pg_wchar * to, int len)
return(cnt);
}
static int
/*
* returns the byte length of a UTF-8 word pointed to by s
*/
int
pg_utf_mblen(const unsigned char *s)
{
int len = 1;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment