1
0
mirror of https://github.com/postgres/postgres.git synced 2025-11-13 16:22:44 +03:00

pgindent run on all C files. Java run to follow. initdb/regression

tests pass.
This commit is contained in:
Bruce Momjian
2001-10-25 05:50:21 +00:00
parent 59da2105d8
commit b81844b173
818 changed files with 21684 additions and 20491 deletions

View File

@@ -7,7 +7,7 @@
*
* 1999/1/15 Tatsuo Ishii
*
* $Id: big5.c,v 1.7 2001/02/10 02:31:27 tgl Exp $
* $Id: big5.c,v 1.8 2001/10/25 05:49:51 momjian Exp $
*/
/* can be used in either frontend or backend */
@@ -19,7 +19,7 @@ typedef struct
{
unsigned short code,
peer;
} codes_t;
} codes_t;
/* map Big5 Level 1 to CNS 11643-1992 Plane 1 */
static codes_t big5Level1ToCnsPlane1[25] = { /* range */
@@ -205,7 +205,7 @@ static unsigned short b2c3[][2] = {
};
static unsigned short BinarySearchRange
(codes_t * array, int high, unsigned short code)
(codes_t *array, int high, unsigned short code)
{
int low,
mid,

View File

@@ -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.32 2001/10/16 10:09:17 ishii Exp $
* $Id: conv.c,v 1.33 2001/10/25 05:49:51 momjian Exp $
*
*
*/
@@ -64,7 +64,6 @@
#include "Unicode/utf8_to_koi8r.map"
#include "Unicode/utf8_to_win1251.map"
#endif /* UNICODE_CONVERSION */
/*
@@ -124,7 +123,6 @@ sjis2mic(unsigned char *sjis, unsigned char *p, int len)
}
else if (c1 > 0x7f)
{
/*
* JIS X0208, X0212, user defined extended characters
*/
@@ -168,7 +166,6 @@ sjis2mic(unsigned char *sjis, unsigned char *p, int len)
}
else if (k >= 0xf040 && k < 0xf540)
{
/*
* UDC1 mapping to X0208 85 ku - 94 ku JIS code 0x7521 -
* 0x7e7e EUC 0xf5a1 - 0xfefe
@@ -181,7 +178,6 @@ sjis2mic(unsigned char *sjis, unsigned char *p, int len)
}
else if (k >= 0xf540 && k < 0xfa40)
{
/*
* UDC2 mapping to X0212 85 ku - 94 ku JIS code 0x7521 -
* 0x7e7e EUC 0x8ff5a1 - 0x8ffefe
@@ -194,7 +190,6 @@ sjis2mic(unsigned char *sjis, unsigned char *p, int len)
}
else if (k >= 0xfa40)
{
/*
* mapping IBM kanji to X0208 and X0212
*
@@ -624,7 +619,7 @@ big52mic(unsigned char *big5, unsigned char *p, int len)
{
if (lc == LC_CNS11643_3 || lc == LC_CNS11643_4)
{
*p++ = 0x9d;/* LCPRV2 */
*p++ = 0x9d; /* LCPRV2 */
}
*p++ = lc; /* Plane No. */
*p++ = (cnsBuf >> 8) & 0x00ff;
@@ -793,7 +788,6 @@ mic2latin5(unsigned char *mic, unsigned char *p, int len)
{
mic2latin(mic, p, len, LC_ISO8859_5);
}
#endif
/*
@@ -1275,7 +1269,7 @@ compare2(const void *p1, const void *p2)
*/
static void
utf_to_local(unsigned char *utf, unsigned char *iso,
pg_utf_to_local * map, int size, int len)
pg_utf_to_local *map, int size, int len)
{
unsigned int iutf;
int l;
@@ -1355,14 +1349,14 @@ utf_to_latin5(unsigned char *utf, unsigned char *iso, int len)
{
utf_to_local(utf, iso, ULmapISO8859_5, sizeof(ULmapISO8859_5) / sizeof(pg_utf_to_local), len);
}
#endif /* NOT_USED */
#endif /* NOT_USED */
/*
* Cyrillic charsets
*/
/*
* UTF-8 --->KOI8-R
* UTF-8 --->KOI8-R
*/
static void
utf_to_KOI8R(unsigned char *utf, unsigned char *iso, int len)
@@ -1372,7 +1366,7 @@ utf_to_KOI8R(unsigned char *utf, unsigned char *iso, int len)
}
/*
* UTF-8 --->WIN1251
* UTF-8 --->WIN1251
*/
static void
utf_to_WIN1251(unsigned char *utf, unsigned char *iso, int len)
@@ -1382,7 +1376,7 @@ utf_to_WIN1251(unsigned char *utf, unsigned char *iso, int len)
}
/*
* UTF-8 --->ALT
* UTF-8 --->ALT
*/
static void
utf_to_ALT(unsigned char *utf, unsigned char *iso, int len)
@@ -1396,7 +1390,7 @@ utf_to_ALT(unsigned char *utf, unsigned char *iso, int len)
*/
static void
local_to_utf(unsigned char *iso, unsigned char *utf,
pg_local_to_utf * map, int size, int encoding, int len)
pg_local_to_utf *map, int size, int encoding, int len)
{
unsigned int iiso;
int l;
@@ -1441,7 +1435,7 @@ local_to_utf(unsigned char *iso, unsigned char *utf,
if (p == NULL)
{
elog(NOTICE, "local_to_utf: could not convert (0x%04x) %s to UTF-8. Ignored",
iiso, (&pg_enc2name_tbl[ encoding ])->name);
iiso, (&pg_enc2name_tbl[encoding])->name);
continue;
}
if (p->utf & 0xff000000)
@@ -1492,7 +1486,7 @@ latin5_to_utf(unsigned char *iso, unsigned char *utf, int len)
{
local_to_utf(iso, utf, LUmapISO8859_5, sizeof(LUmapISO8859_5) / sizeof(pg_local_to_utf), PG_LATIN5, len);
}
#endif /* NOT_USED */
#endif /* NOT_USED */
#define UTF_ISO8859(_id_) \
static void \
@@ -1546,6 +1540,7 @@ ALT_to_utf(unsigned char *iso, unsigned char *utf, int len)
{
local_to_utf(iso, utf, LUmapALT, sizeof(LUmapALT) / sizeof(pg_local_to_utf), PG_ALT, len);
}
/*
* UTF-8 ---> EUC_JP
*/
@@ -1564,7 +1559,7 @@ static void
euc_jp_to_utf(unsigned char *euc, unsigned char *utf, int len)
{
local_to_utf(euc, utf, LUmapEUC_JP,
sizeof(LUmapEUC_JP) / sizeof(pg_local_to_utf), PG_EUC_JP, len);
sizeof(LUmapEUC_JP) / sizeof(pg_local_to_utf), PG_EUC_JP, len);
}
/*
@@ -1585,7 +1580,7 @@ static void
euc_cn_to_utf(unsigned char *euc, unsigned char *utf, int len)
{
local_to_utf(euc, utf, LUmapEUC_CN,
sizeof(LUmapEUC_CN) / sizeof(pg_local_to_utf), PG_EUC_CN, len);
sizeof(LUmapEUC_CN) / sizeof(pg_local_to_utf), PG_EUC_CN, len);
}
/*
@@ -1606,7 +1601,7 @@ static void
euc_kr_to_utf(unsigned char *euc, unsigned char *utf, int len)
{
local_to_utf(euc, utf, LUmapEUC_KR,
sizeof(LUmapEUC_KR) / sizeof(pg_local_to_utf), PG_EUC_KR, len);
sizeof(LUmapEUC_KR) / sizeof(pg_local_to_utf), PG_EUC_KR, len);
}
/*
@@ -1627,7 +1622,7 @@ static void
euc_tw_to_utf(unsigned char *euc, unsigned char *utf, int len)
{
local_to_utf(euc, utf, LUmapEUC_TW,
sizeof(LUmapEUC_TW) / sizeof(pg_local_to_utf), PG_EUC_TW, len);
sizeof(LUmapEUC_TW) / sizeof(pg_local_to_utf), PG_EUC_TW, len);
}
/*
@@ -1648,7 +1643,7 @@ static void
sjis_to_utf(unsigned char *euc, unsigned char *utf, int len)
{
local_to_utf(euc, utf, LUmapSJIS,
sizeof(LUmapSJIS) / sizeof(pg_local_to_utf), PG_SJIS, len);
sizeof(LUmapSJIS) / sizeof(pg_local_to_utf), PG_SJIS, len);
}
/*
@@ -1669,7 +1664,7 @@ static void
big5_to_utf(unsigned char *euc, unsigned char *utf, int len)
{
local_to_utf(euc, utf, LUmapBIG5,
sizeof(LUmapBIG5) / sizeof(pg_local_to_utf), PG_BIG5, len);
sizeof(LUmapBIG5) / sizeof(pg_local_to_utf), PG_BIG5, len);
}
/* ----------
@@ -1678,69 +1673,176 @@ big5_to_utf(unsigned char *euc, unsigned char *utf, int len)
* WARINIG: must by same order as pg_enc in include/mb/pg_wchar.h!
* ----------
*/
pg_enconv pg_enconv_tbl[] =
pg_enconv pg_enconv_tbl[] =
{
{ PG_SQL_ASCII, ascii2mic, mic2ascii, ascii2utf, utf2ascii},
{ PG_EUC_JP, euc_jp2mic, mic2euc_jp, euc_jp_to_utf, utf_to_euc_jp},
{ PG_EUC_CN, euc_cn2mic, mic2euc_cn, euc_cn_to_utf, utf_to_euc_cn},
{ PG_EUC_KR, euc_kr2mic, mic2euc_kr, euc_kr_to_utf, utf_to_euc_kr},
{ PG_EUC_TW, euc_tw2mic, mic2euc_tw, euc_tw_to_utf, utf_to_euc_tw},
{ PG_UTF8, 0, 0, 0, 0},
{ PG_MULE_INTERNAL, 0, 0, 0, 0},
{ PG_LATIN1, latin12mic, mic2latin1, iso8859_1_to_utf, utf_to_iso8859_1},
{ PG_LATIN2, latin22mic, mic2latin2, iso8859_2_to_utf, utf_to_iso8859_2},
{ PG_LATIN3, latin32mic, mic2latin3, iso8859_3_to_utf, utf_to_iso8859_3},
{ PG_LATIN4, latin42mic, mic2latin4, iso8859_4_to_utf, utf_to_iso8859_4},
{ PG_LATIN5, iso2mic, mic2iso, iso8859_9_to_utf, utf_to_iso8859_9},
{ PG_LATIN6, 0, 0, iso8859_10_to_utf, utf_to_iso8859_10},
{ PG_LATIN7, 0, 0, iso8859_13_to_utf, utf_to_iso8859_13},
{ PG_LATIN8, 0, 0, iso8859_14_to_utf, utf_to_iso8859_14},
{ PG_LATIN9, 0, 0, iso8859_15_to_utf, utf_to_iso8859_15},
{ PG_LATIN10, 0, 0, iso8859_16_to_utf, utf_to_iso8859_16},
{ PG_KOI8R, koi8r2mic, mic2koi8r, KOI8R_to_utf, utf_to_KOI8R},
{ PG_WIN1251, win12512mic, mic2win1251, WIN1251_to_utf, utf_to_WIN1251},
{ PG_ALT, alt2mic, mic2alt, ALT_to_utf, utf_to_ALT},
{ PG_ISO_8859_5, 0, 0, iso8859_5_to_utf, utf_to_iso8859_5},
{ PG_ISO_8859_6, 0, 0, iso8859_6_to_utf, utf_to_iso8859_6},
{ PG_ISO_8859_7, 0, 0, iso8859_7_to_utf, utf_to_iso8859_7},
{ PG_ISO_8859_8, 0, 0, iso8859_8_to_utf, utf_to_iso8859_8},
{
PG_SQL_ASCII, ascii2mic, mic2ascii, ascii2utf, utf2ascii
} ,
{
PG_EUC_JP, euc_jp2mic, mic2euc_jp, euc_jp_to_utf, utf_to_euc_jp
},
{
PG_EUC_CN, euc_cn2mic, mic2euc_cn, euc_cn_to_utf, utf_to_euc_cn
},
{
PG_EUC_KR, euc_kr2mic, mic2euc_kr, euc_kr_to_utf, utf_to_euc_kr
},
{
PG_EUC_TW, euc_tw2mic, mic2euc_tw, euc_tw_to_utf, utf_to_euc_tw
},
{
PG_UTF8, 0, 0, 0, 0
},
{
PG_MULE_INTERNAL, 0, 0, 0, 0
},
{
PG_LATIN1, latin12mic, mic2latin1, iso8859_1_to_utf, utf_to_iso8859_1
},
{
PG_LATIN2, latin22mic, mic2latin2, iso8859_2_to_utf, utf_to_iso8859_2
},
{
PG_LATIN3, latin32mic, mic2latin3, iso8859_3_to_utf, utf_to_iso8859_3
},
{
PG_LATIN4, latin42mic, mic2latin4, iso8859_4_to_utf, utf_to_iso8859_4
},
{
PG_LATIN5, iso2mic, mic2iso, iso8859_9_to_utf, utf_to_iso8859_9
},
{
PG_LATIN6, 0, 0, iso8859_10_to_utf, utf_to_iso8859_10
},
{
PG_LATIN7, 0, 0, iso8859_13_to_utf, utf_to_iso8859_13
},
{
PG_LATIN8, 0, 0, iso8859_14_to_utf, utf_to_iso8859_14
},
{
PG_LATIN9, 0, 0, iso8859_15_to_utf, utf_to_iso8859_15
},
{
PG_LATIN10, 0, 0, iso8859_16_to_utf, utf_to_iso8859_16
},
{
PG_KOI8R, koi8r2mic, mic2koi8r, KOI8R_to_utf, utf_to_KOI8R
},
{
PG_WIN1251, win12512mic, mic2win1251, WIN1251_to_utf, utf_to_WIN1251
},
{
PG_ALT, alt2mic, mic2alt, ALT_to_utf, utf_to_ALT
},
{
PG_ISO_8859_5, 0, 0, iso8859_5_to_utf, utf_to_iso8859_5
},
{
PG_ISO_8859_6, 0, 0, iso8859_6_to_utf, utf_to_iso8859_6
},
{
PG_ISO_8859_7, 0, 0, iso8859_7_to_utf, utf_to_iso8859_7
},
{
PG_ISO_8859_8, 0, 0, iso8859_8_to_utf, utf_to_iso8859_8
},
{ PG_SJIS, sjis2mic, mic2sjis, sjis_to_utf, utf_to_sjis},
{ PG_BIG5, big52mic, mic2big5, big5_to_utf, utf_to_big5},
{ PG_WIN1250, win12502mic, mic2win1250, 0, 0},
{
PG_SJIS, sjis2mic, mic2sjis, sjis_to_utf, utf_to_sjis
},
{
PG_BIG5, big52mic, mic2big5, big5_to_utf, utf_to_big5
},
{
PG_WIN1250, win12502mic, mic2win1250, 0, 0
},
};
#else
pg_enconv pg_enconv_tbl[] =
pg_enconv pg_enconv_tbl[] =
{
{ PG_SQL_ASCII, ascii2mic, mic2ascii, 0, 0},
{ PG_EUC_JP, euc_jp2mic, mic2euc_jp, 0, 0},
{ PG_EUC_CN, euc_cn2mic, mic2euc_cn, 0, 0},
{ PG_EUC_KR, euc_kr2mic, mic2euc_kr, 0, 0},
{ PG_EUC_TW, euc_tw2mic, mic2euc_tw, 0, 0},
{ PG_UTF8, 0, 0, 0, 0},
{ PG_MULE_INTERNAL, 0, 0, 0, 0},
{ PG_LATIN1, latin12mic, mic2latin1, 0, 0},
{ PG_LATIN2, latin22mic, mic2latin2, 0, 0},
{ PG_LATIN3, latin32mic, mic2latin3, 0, 0},
{ PG_LATIN4, latin42mic, mic2latin4, 0, 0},
{ PG_LATIN5, iso2mic, mic2iso, 0, 0},
{ PG_LATIN6, 0, 0, 0, 0},
{ PG_LATIN7, 0, 0, 0, 0},
{ PG_LATIN8, 0, 0, 0, 0},
{ PG_LATIN9, 0, 0, 0, 0},
{ PG_LATIN10, 0, 0, 0, 0},
{ PG_KOI8R, koi8r2mic, mic2koi8r, 0, 0},
{ PG_WIN1251, win12512mic, mic2win1251, 0, 0},
{ PG_ALT, alt2mic, mic2alt, 0, 0},
{ PG_ISO_8859_5, 0, 0, 0, 0},
{ PG_ISO_8859_6, 0, 0, 0, 0},
{ PG_ISO_8859_7, 0, 0, 0, 0},
{ PG_ISO_8859_8, 0, 0, 0, 0},
{ PG_SJIS, sjis2mic, mic2sjis, 0, 0},
{ PG_BIG5, big52mic, mic2big5, 0, 0},
{ PG_WIN1250, win12502mic, mic2win1250, 0, 0},
{
PG_SQL_ASCII, ascii2mic, mic2ascii, 0, 0
} ,
{
PG_EUC_JP, euc_jp2mic, mic2euc_jp, 0, 0
},
{
PG_EUC_CN, euc_cn2mic, mic2euc_cn, 0, 0
},
{
PG_EUC_KR, euc_kr2mic, mic2euc_kr, 0, 0
},
{
PG_EUC_TW, euc_tw2mic, mic2euc_tw, 0, 0
},
{
PG_UTF8, 0, 0, 0, 0
},
{
PG_MULE_INTERNAL, 0, 0, 0, 0
},
{
PG_LATIN1, latin12mic, mic2latin1, 0, 0
},
{
PG_LATIN2, latin22mic, mic2latin2, 0, 0
},
{
PG_LATIN3, latin32mic, mic2latin3, 0, 0
},
{
PG_LATIN4, latin42mic, mic2latin4, 0, 0
},
{
PG_LATIN5, iso2mic, mic2iso, 0, 0
},
{
PG_LATIN6, 0, 0, 0, 0
},
{
PG_LATIN7, 0, 0, 0, 0
},
{
PG_LATIN8, 0, 0, 0, 0
},
{
PG_LATIN9, 0, 0, 0, 0
},
{
PG_LATIN10, 0, 0, 0, 0
},
{
PG_KOI8R, koi8r2mic, mic2koi8r, 0, 0
},
{
PG_WIN1251, win12512mic, mic2win1251, 0, 0
},
{
PG_ALT, alt2mic, mic2alt, 0, 0
},
{
PG_ISO_8859_5, 0, 0, 0, 0
},
{
PG_ISO_8859_6, 0, 0, 0, 0
},
{
PG_ISO_8859_7, 0, 0, 0, 0
},
{
PG_ISO_8859_8, 0, 0, 0, 0
},
{
PG_SJIS, sjis2mic, mic2sjis, 0, 0
},
{
PG_BIG5, big52mic, mic2big5, 0, 0
},
{
PG_WIN1250, win12502mic, mic2win1250, 0, 0
},
};
#endif /* UNICODE_CONVERSION */

View File

@@ -2,7 +2,7 @@
* Encoding names and routines for work with it. All
* in this file is shared bedween FE and BE.
*
* $Id: encnames.c,v 1.4 2001/10/16 10:09:17 ishii Exp $
* $Id: encnames.c,v 1.5 2001/10/25 05:49:51 momjian Exp $
*/
#ifdef FRONTEND
#include "postgres_fe.h"
@@ -23,7 +23,7 @@
#include <ctype.h>
/* ----------
* All encoding names, sorted: *** A L P H A B E T I C ***
* All encoding names, sorted: *** A L P H A B E T I C ***
*
* All names must be without irrelevan chars, search routines use
* isalnum() chars only. It means ISO-8859-1, iso_8859-1 and Iso8859_1
@@ -34,58 +34,153 @@
* Karel Zak, Aug 2001
* ----------
*/
pg_encname pg_encname_tbl[] =
pg_encname pg_encname_tbl[] =
{
{ "alt", PG_ALT }, /* IBM866 */
{ "big5", PG_BIG5 }, /* Big5; Chinese for Taiwan Multi-byte set */
{ "euccn", PG_EUC_CN }, /* EUC-CN; Extended Unix Code for simplified Chinese */
{ "eucjp", PG_EUC_JP }, /* EUC-JP; Extended UNIX Code fixed Width for Japanese, stdandard OSF */
{ "euckr", PG_EUC_KR }, /* EUC-KR; RFC1557,Choi */
{ "euctw", PG_EUC_TW }, /* EUC-TW; Extended Unix Code for traditional Chinese */
{ "iso88591", PG_LATIN1 }, /* ISO-8859-1; RFC1345,KXS2 */
{ "iso885910", PG_LATIN6 }, /* ISO-8859-10; RFC1345,KXS2 */
{ "iso885913", PG_LATIN7 }, /* ISO-8859-13; RFC1345,KXS2 */
{ "iso885914", PG_LATIN8 }, /* ISO-8859-14; RFC1345,KXS2 */
{ "iso885915", PG_LATIN9 }, /* ISO-8859-15; RFC1345,KXS2 */
{ "iso885916", PG_LATIN10 }, /* ISO-8859-16; RFC1345,KXS2 */
{ "iso88592", PG_LATIN2 }, /* ISO-8859-2; RFC1345,KXS2 */
{ "iso88593", PG_LATIN3 }, /* ISO-8859-3; RFC1345,KXS2 */
{ "iso88594", PG_LATIN4 }, /* ISO-8859-4; RFC1345,KXS2 */
{ "iso88595", PG_ISO_8859_5 }, /* ISO-8859-5; RFC1345,KXS2 */
{ "iso88596", PG_ISO_8859_6 }, /* ISO-8859-6; RFC1345,KXS2 */
{ "iso88597", PG_ISO_8859_7 }, /* ISO-8859-7; RFC1345,KXS2 */
{ "iso88598", PG_ISO_8859_8 }, /* ISO-8859-8; RFC1345,KXS2 */
{ "iso88599", PG_LATIN5 }, /* ISO-8859-9; RFC1345,KXS2 */
{ "koi8", PG_KOI8R }, /* _dirty_ alias for KOI8-R (backward compatibility) */
{ "koi8r", PG_KOI8R }, /* KOI8-R; RFC1489 */
{ "latin1", PG_LATIN1 }, /* alias for ISO-8859-1 */
{ "latin10", PG_LATIN10}, /* alias for ISO-8859-16 */
{ "latin2", PG_LATIN2 }, /* alias for ISO-8859-2 */
{ "latin3", PG_LATIN3 }, /* alias for ISO-8859-3 */
{ "latin4", PG_LATIN4 }, /* alias for ISO-8859-4 */
{ "latin5", PG_LATIN5 }, /* alias for ISO-8859-9 */
{ "latin6", PG_LATIN6}, /* alias for ISO-8859-10 */
{ "latin7", PG_LATIN7}, /* alias for ISO-8859-13 */
{ "latin8", PG_LATIN8}, /* alias for ISO-8859-14 */
{ "latin9", PG_LATIN9}, /* alias for ISO-8859-15 */
{ "mskanji", PG_SJIS }, /* alias for Shift_JIS */
{ "muleinternal",PG_MULE_INTERNAL },
{ "shiftjis", PG_SJIS }, /* Shift_JIS; JIS X 0202-1991 */
{ "sjis", PG_SJIS }, /* alias for Shift_JIS */
{ "sqlascii", PG_SQL_ASCII },
{ "unicode", PG_UTF8 }, /* alias for UTF-8 */
{ "utf8", PG_UTF8 }, /* UTF-8; RFC2279 */
{ "win", PG_WIN1251 }, /* _dirty_ alias for windows-1251 (backward compatibility) */
{ "win1250", PG_WIN1250 }, /* alias for Windows-1250 */
{ "win1251", PG_WIN1251 }, /* alias for Windows-1251 */
{ "windows1250",PG_WIN1250 }, /* Windows-1251; Microsoft */
{ "windows1251",PG_WIN1251 }, /* Windows-1251; Microsoft */
{
"alt", PG_ALT
} , /* IBM866 */
{
"big5", PG_BIG5
}, /* Big5; Chinese for Taiwan Multi-byte set */
{
"euccn", PG_EUC_CN
}, /* EUC-CN; Extended Unix Code for
* simplified Chinese */
{
"eucjp", PG_EUC_JP
}, /* EUC-JP; Extended UNIX Code fixed Width
* for Japanese, stdandard OSF */
{
"euckr", PG_EUC_KR
}, /* EUC-KR; RFC1557,Choi */
{
"euctw", PG_EUC_TW
}, /* EUC-TW; Extended Unix Code for
* traditional Chinese */
{
"iso88591", PG_LATIN1
}, /* ISO-8859-1; RFC1345,KXS2 */
{
"iso885910", PG_LATIN6
}, /* ISO-8859-10; RFC1345,KXS2 */
{
"iso885913", PG_LATIN7
}, /* ISO-8859-13; RFC1345,KXS2 */
{
"iso885914", PG_LATIN8
}, /* ISO-8859-14; RFC1345,KXS2 */
{
"iso885915", PG_LATIN9
}, /* ISO-8859-15; RFC1345,KXS2 */
{
"iso885916", PG_LATIN10
}, /* ISO-8859-16; RFC1345,KXS2 */
{
"iso88592", PG_LATIN2
}, /* ISO-8859-2; RFC1345,KXS2 */
{
"iso88593", PG_LATIN3
}, /* ISO-8859-3; RFC1345,KXS2 */
{
"iso88594", PG_LATIN4
}, /* ISO-8859-4; RFC1345,KXS2 */
{
"iso88595", PG_ISO_8859_5
}, /* ISO-8859-5; RFC1345,KXS2 */
{
"iso88596", PG_ISO_8859_6
}, /* ISO-8859-6; RFC1345,KXS2 */
{
"iso88597", PG_ISO_8859_7
}, /* ISO-8859-7; RFC1345,KXS2 */
{
"iso88598", PG_ISO_8859_8
}, /* ISO-8859-8; RFC1345,KXS2 */
{
"iso88599", PG_LATIN5
}, /* ISO-8859-9; RFC1345,KXS2 */
{
"koi8", PG_KOI8R
}, /* _dirty_ alias for KOI8-R (backward
* compatibility) */
{
"koi8r", PG_KOI8R
}, /* KOI8-R; RFC1489 */
{
"latin1", PG_LATIN1
}, /* alias for ISO-8859-1 */
{
"latin10", PG_LATIN10
}, /* alias for ISO-8859-16 */
{
"latin2", PG_LATIN2
}, /* alias for ISO-8859-2 */
{
"latin3", PG_LATIN3
}, /* alias for ISO-8859-3 */
{
"latin4", PG_LATIN4
}, /* alias for ISO-8859-4 */
{
"latin5", PG_LATIN5
}, /* alias for ISO-8859-9 */
{
"latin6", PG_LATIN6
}, /* alias for ISO-8859-10 */
{
"latin7", PG_LATIN7
}, /* alias for ISO-8859-13 */
{
"latin8", PG_LATIN8
}, /* alias for ISO-8859-14 */
{
"latin9", PG_LATIN9
}, /* alias for ISO-8859-15 */
{
"mskanji", PG_SJIS
}, /* alias for Shift_JIS */
{
"muleinternal", PG_MULE_INTERNAL
},
{
"shiftjis", PG_SJIS
}, /* Shift_JIS; JIS X 0202-1991 */
{
"sjis", PG_SJIS
}, /* alias for Shift_JIS */
{
"sqlascii", PG_SQL_ASCII
},
{
"unicode", PG_UTF8
}, /* alias for UTF-8 */
{
"utf8", PG_UTF8
}, /* UTF-8; RFC2279 */
{
"win", PG_WIN1251
}, /* _dirty_ alias for windows-1251
* (backward compatibility) */
{
"win1250", PG_WIN1250
}, /* alias for Windows-1250 */
{
"win1251", PG_WIN1251
}, /* alias for Windows-1251 */
{
"windows1250", PG_WIN1250
}, /* Windows-1251; Microsoft */
{
"windows1251", PG_WIN1251
}, /* Windows-1251; Microsoft */
{ NULL, 0 } /* last */
{
NULL, 0
} /* last */
};
unsigned int pg_encname_tbl_sz = \
sizeof(pg_encname_tbl) / sizeof(pg_encname_tbl[0]) -1;
sizeof(pg_encname_tbl) / sizeof(pg_encname_tbl[0]) - 1;
/* ----------
* These are "official" encoding names.
@@ -94,33 +189,87 @@ unsigned int pg_encname_tbl_sz = \
*/
pg_enc2name pg_enc2name_tbl[] =
{
{ "SQL_ASCII", PG_SQL_ASCII },
{ "EUC_JP", PG_EUC_JP },
{ "EUC_CN", PG_EUC_CN },
{ "EUC_KR", PG_EUC_KR },
{ "EUC_TW", PG_EUC_TW },
{ "UNICODE", PG_UTF8 },
{ "MULE_INTERNAL",PG_MULE_INTERNAL },
{ "LATIN1", PG_LATIN1 },
{ "LATIN2", PG_LATIN2 },
{ "LATIN3", PG_LATIN3 },
{ "LATIN4", PG_LATIN4 },
{ "LATIN5", PG_LATIN5 },
{ "LATIN6", PG_LATIN6 },
{ "LATIN7", PG_LATIN7 },
{ "LATIN8", PG_LATIN8 },
{ "LATIN9", PG_LATIN9 },
{ "LATIN10", PG_LATIN10 },
{ "KOI8", PG_KOI8R },
{ "WIN", PG_WIN1251 },
{ "ALT", PG_ALT },
{ "ISO_8859_5", PG_ISO_8859_5 },
{ "ISO_8859_6", PG_ISO_8859_6 },
{ "ISO_8859_7", PG_ISO_8859_7 },
{ "ISO_8859_8", PG_ISO_8859_8 },
{ "SJIS", PG_SJIS },
{ "BIG5", PG_BIG5 },
{ "WIN1250", PG_WIN1250 }
{
"SQL_ASCII", PG_SQL_ASCII
} ,
{
"EUC_JP", PG_EUC_JP
},
{
"EUC_CN", PG_EUC_CN
},
{
"EUC_KR", PG_EUC_KR
},
{
"EUC_TW", PG_EUC_TW
},
{
"UNICODE", PG_UTF8
},
{
"MULE_INTERNAL", PG_MULE_INTERNAL
},
{
"LATIN1", PG_LATIN1
},
{
"LATIN2", PG_LATIN2
},
{
"LATIN3", PG_LATIN3
},
{
"LATIN4", PG_LATIN4
},
{
"LATIN5", PG_LATIN5
},
{
"LATIN6", PG_LATIN6
},
{
"LATIN7", PG_LATIN7
},
{
"LATIN8", PG_LATIN8
},
{
"LATIN9", PG_LATIN9
},
{
"LATIN10", PG_LATIN10
},
{
"KOI8", PG_KOI8R
},
{
"WIN", PG_WIN1251
},
{
"ALT", PG_ALT
},
{
"ISO_8859_5", PG_ISO_8859_5
},
{
"ISO_8859_6", PG_ISO_8859_6
},
{
"ISO_8859_7", PG_ISO_8859_7
},
{
"ISO_8859_8", PG_ISO_8859_8
},
{
"SJIS", PG_SJIS
},
{
"BIG5", PG_BIG5
},
{
"WIN1250", PG_WIN1250
}
};
/* ----------
@@ -130,12 +279,12 @@ pg_enc2name pg_enc2name_tbl[] =
int
pg_valid_client_encoding(const char *name)
{
int enc;
int enc;
if ((enc = pg_char_to_encoding(name)) < 0)
return -1;
if (!PG_VALID_FE_ENCODING( enc))
if (!PG_VALID_FE_ENCODING(enc))
return -1;
return enc;
@@ -144,12 +293,12 @@ pg_valid_client_encoding(const char *name)
int
pg_valid_server_encoding(const char *name)
{
int enc;
int enc;
if ((enc = pg_char_to_encoding(name)) < 0)
return -1;
if (!PG_VALID_BE_ENCODING( enc))
if (!PG_VALID_BE_ENCODING(enc))
return -1;
return enc;
@@ -162,12 +311,13 @@ pg_valid_server_encoding(const char *name)
static char *
clean_encoding_name(char *key, char *newkey)
{
char *p, *np;
char *p,
*np;
for(p=key, np=newkey; *p!='\0'; p++)
for (p = key, np = newkey; *p != '\0'; p++)
{
if (isalnum((unsigned char) *p))
*np++=tolower((unsigned char) *p);
*np++ = tolower((unsigned char) *p);
}
*np = '\0';
return newkey;
@@ -180,15 +330,15 @@ clean_encoding_name(char *key, char *newkey)
pg_encname *
pg_char_to_encname_struct(const char *name)
{
unsigned int nel = pg_encname_tbl_sz;
pg_encname *base = pg_encname_tbl,
*last = base + nel - 1,
*position;
int result;
unsigned int nel = pg_encname_tbl_sz;
pg_encname *base = pg_encname_tbl,
*last = base + nel - 1,
*position;
int result;
char buff[NAMEDATALEN],
*key;
*key;
if(name==NULL || *name=='\0')
if (name == NULL || *name == '\0')
return NULL;
if (strlen(name) > NAMEDATALEN)
@@ -241,6 +391,7 @@ Datum
PG_char_to_encoding(PG_FUNCTION_ARGS)
{
Name s = PG_GETARG_NAME(0);
PG_RETURN_INT32(pg_char_to_encoding(NameStr(*s)));
}
#endif
@@ -250,8 +401,9 @@ pg_encoding_to_char(int encoding)
{
if (PG_VALID_ENCODING(encoding))
{
pg_enc2name *p = &pg_enc2name_tbl[ encoding ];
Assert( encoding == p->encoding );
pg_enc2name *p = &pg_enc2name_tbl[encoding];
Assert(encoding == p->encoding);
return p->name;
}
return "";
@@ -262,9 +414,8 @@ Datum
PG_encoding_to_char(PG_FUNCTION_ARGS)
{
int32 encoding = PG_GETARG_INT32(0);
const char *encoding_name = pg_encoding_to_char(encoding);
const char *encoding_name = pg_encoding_to_char(encoding);
return DirectFunctionCall1(namein, CStringGetDatum(encoding_name));
}
#endif

View File

@@ -3,7 +3,7 @@
* client encoding and server internal encoding.
* (currently mule internal code (mic) is used)
* Tatsuo Ishii
* $Id: mbutils.c,v 1.24 2001/10/12 02:08:34 ishii Exp $
* $Id: mbutils.c,v 1.25 2001/10/25 05:49:51 momjian Exp $
*/
#include "postgres.h"
@@ -12,7 +12,7 @@
#include "utils/builtins.h"
/*
* We handle for actual FE and BE encoding setting encoding-identificator
* We handle for actual FE and BE encoding setting encoding-identificator
* and encoding-name too. It prevent searching and conversion from encoding
* to encoding name in getdatabaseencoding() and other routines.
*
@@ -21,13 +21,13 @@
*
* Karel Zak (Aug 2001)
*/
static pg_enc2name *ClientEncoding = &pg_enc2name_tbl[ PG_SQL_ASCII ];
static pg_enc2name *DatabaseEncoding = &pg_enc2name_tbl[ PG_SQL_ASCII ];
static pg_enc2name *ClientEncoding = &pg_enc2name_tbl[PG_SQL_ASCII];
static pg_enc2name *DatabaseEncoding = &pg_enc2name_tbl[PG_SQL_ASCII];
static to_mic_converter client_to_mic; /* something to MIC */
static from_mic_converter client_from_mic; /* MIC to something */
static from_mic_converter client_from_mic; /* MIC to something */
static to_mic_converter server_to_mic; /* something to MIC */
static from_mic_converter server_from_mic; /* MIC to something */
static from_mic_converter server_from_mic; /* MIC to something */
/*
* find encoding table entry by encoding
@@ -37,8 +37,8 @@ pg_get_enconv_by_encoding(int encoding)
{
if (PG_VALID_ENCODING(encoding))
{
Assert((&pg_enconv_tbl[ encoding ])->encoding == encoding);
return &pg_enconv_tbl[ encoding ];
Assert((&pg_enconv_tbl[encoding])->encoding == encoding);
return &pg_enconv_tbl[encoding];
}
return 0;
}
@@ -113,7 +113,7 @@ pg_find_encoding_converters(int src, int dest,
int
pg_set_client_encoding(int encoding)
{
int current_server_encoding = DatabaseEncoding->encoding;
int current_server_encoding = DatabaseEncoding->encoding;
if (!PG_VALID_FE_ENCODING(encoding))
return (-1);
@@ -121,7 +121,7 @@ pg_set_client_encoding(int encoding)
if (pg_find_encoding_converters(encoding, current_server_encoding, &client_to_mic, &server_from_mic) < 0)
return (-1);
ClientEncoding = &pg_enc2name_tbl[ encoding ];
ClientEncoding = &pg_enc2name_tbl[encoding];
Assert(ClientEncoding->encoding == encoding);
@@ -162,7 +162,7 @@ pg_get_client_encoding_name(void)
* function). Another case is you have direct-conversion function from
* src to dest. In this case either src_to_mic or dest_from_mic could
* be set to 0 also.
*
*
* Note that If src or dest is UNICODE, we have to do
* direct-conversion, since we don't support conversion bwteen UNICODE
* and MULE_INTERNAL, we cannot go through MULE_INTERNAL.
@@ -175,7 +175,7 @@ pg_get_client_encoding_name(void)
* to determine whether to pfree the result or not!
*
* Note: we assume that conversion cannot cause more than a 4-to-1 growth
* in the length of the string --- is this enough? */
* in the length of the string --- is this enough? */
unsigned char *
pg_do_encoding_conversion(unsigned char *src, int len,
@@ -212,32 +212,33 @@ pg_do_encoding_conversion(unsigned char *src, int len,
Datum
pg_convert(PG_FUNCTION_ARGS)
{
text *string = PG_GETARG_TEXT_P(0);
Name s = PG_GETARG_NAME(1);
int encoding = pg_char_to_encoding(NameStr(*s));
int db_encoding = DatabaseEncoding->encoding;
text *string = PG_GETARG_TEXT_P(0);
Name s = PG_GETARG_NAME(1);
int encoding = pg_char_to_encoding(NameStr(*s));
int db_encoding = DatabaseEncoding->encoding;
to_mic_converter src;
from_mic_converter dest;
unsigned char *result;
text *retval;
unsigned char *result;
text *retval;
if (encoding < 0)
elog(ERROR, "Invalid encoding name %s", NameStr(*s));
elog(ERROR, "Invalid encoding name %s", NameStr(*s));
if (pg_find_encoding_converters(db_encoding, encoding, &src, &dest) < 0)
{
char *encoding_name = (char *)pg_encoding_to_char(db_encoding);
elog(ERROR, "Conversion from %s to %s is not possible", NameStr(*s), encoding_name);
char *encoding_name = (char *) pg_encoding_to_char(db_encoding);
elog(ERROR, "Conversion from %s to %s is not possible", NameStr(*s), encoding_name);
}
result = pg_do_encoding_conversion(VARDATA(string), VARSIZE(string)-VARHDRSZ,
src, dest);
result = pg_do_encoding_conversion(VARDATA(string), VARSIZE(string) - VARHDRSZ,
src, dest);
if (result == NULL)
elog(ERROR, "Encoding conversion failed");
elog(ERROR, "Encoding conversion failed");
retval = DatumGetTextP(DirectFunctionCall1(textin, CStringGetDatum(result)));
if (result != (unsigned char *)VARDATA(string))
pfree(result);
if (result != (unsigned char *) VARDATA(string))
pfree(result);
/* free memory if allocated by the toaster */
PG_FREE_IF_COPY(string, 0);
@@ -253,35 +254,35 @@ pg_convert(PG_FUNCTION_ARGS)
Datum
pg_convert2(PG_FUNCTION_ARGS)
{
text *string = PG_GETARG_TEXT_P(0);
char *src_encoding_name = NameStr(*PG_GETARG_NAME(1));
int src_encoding = pg_char_to_encoding(src_encoding_name);
char *dest_encoding_name = NameStr(*PG_GETARG_NAME(2));
int dest_encoding = pg_char_to_encoding(dest_encoding_name);
text *string = PG_GETARG_TEXT_P(0);
char *src_encoding_name = NameStr(*PG_GETARG_NAME(1));
int src_encoding = pg_char_to_encoding(src_encoding_name);
char *dest_encoding_name = NameStr(*PG_GETARG_NAME(2));
int dest_encoding = pg_char_to_encoding(dest_encoding_name);
to_mic_converter src;
from_mic_converter dest;
unsigned char *result;
text *retval;
unsigned char *result;
text *retval;
if (src_encoding < 0)
elog(ERROR, "Invalid source encoding name %s", src_encoding_name);
elog(ERROR, "Invalid source encoding name %s", src_encoding_name);
if (dest_encoding < 0)
elog(ERROR, "Invalid destination encoding name %s", dest_encoding_name);
elog(ERROR, "Invalid destination encoding name %s", dest_encoding_name);
if (pg_find_encoding_converters(src_encoding, dest_encoding, &src, &dest) < 0)
{
elog(ERROR, "Conversion from %s to %s is not possible",
src_encoding_name, dest_encoding_name);
elog(ERROR, "Conversion from %s to %s is not possible",
src_encoding_name, dest_encoding_name);
}
result = pg_do_encoding_conversion(VARDATA(string), VARSIZE(string)-VARHDRSZ,
src, dest);
result = pg_do_encoding_conversion(VARDATA(string), VARSIZE(string) - VARHDRSZ,
src, dest);
if (result == NULL)
elog(ERROR, "Encoding conversion failed");
elog(ERROR, "Encoding conversion failed");
retval = DatumGetTextP(DirectFunctionCall1(textin, CStringGetDatum(result)));
if (result != (unsigned char *)VARDATA(string))
pfree(result);
if (result != (unsigned char *) VARDATA(string))
pfree(result);
/* free memory if allocated by the toaster */
PG_FREE_IF_COPY(string, 0);
@@ -309,7 +310,7 @@ pg_client_to_server(unsigned char *s, int len)
Assert(ClientEncoding);
if (ClientEncoding->encoding == DatabaseEncoding->encoding)
return s;
return s;
return pg_do_encoding_conversion(s, len, client_to_mic, server_from_mic);
}
@@ -341,23 +342,23 @@ pg_server_to_client(unsigned char *s, int len)
/* convert a multi-byte string to a wchar */
int
pg_mb2wchar(const unsigned char *from, pg_wchar * to)
pg_mb2wchar(const unsigned char *from, pg_wchar *to)
{
return (*pg_wchar_table[ DatabaseEncoding->encoding ].mb2wchar_with_len) (from, to, strlen(from));
return (*pg_wchar_table[DatabaseEncoding->encoding].mb2wchar_with_len) (from, to, strlen(from));
}
/* convert a multi-byte string to a wchar with a limited length */
int
pg_mb2wchar_with_len(const unsigned char *from, pg_wchar * to, int len)
pg_mb2wchar_with_len(const unsigned char *from, pg_wchar *to, int len)
{
return (*pg_wchar_table[ DatabaseEncoding->encoding ].mb2wchar_with_len) (from, to, len);
return (*pg_wchar_table[DatabaseEncoding->encoding].mb2wchar_with_len) (from, to, len);
}
/* returns the byte length of a multi-byte word */
int
pg_mblen(const unsigned char *mbstr)
{
return ((*pg_wchar_table[ DatabaseEncoding->encoding ].mblen) (mbstr));
return ((*pg_wchar_table[DatabaseEncoding->encoding].mblen) (mbstr));
}
/* returns the length (counted as a wchar) of a multi-byte string */
@@ -447,7 +448,7 @@ SetDatabaseEncoding(int encoding)
if (!PG_VALID_BE_ENCODING(encoding))
elog(ERROR, "SetDatabaseEncoding(): invalid database encoding");
DatabaseEncoding = &pg_enc2name_tbl[ encoding ];
DatabaseEncoding = &pg_enc2name_tbl[encoding];
Assert(DatabaseEncoding->encoding == encoding);
}

View File

@@ -1,7 +1,7 @@
/*
* conversion functions between pg_wchar and multi-byte streams.
* Tatsuo Ishii
* $Id: wchar.c,v 1.24 2001/10/15 01:19:15 ishii Exp $
* $Id: wchar.c,v 1.25 2001/10/25 05:49:51 momjian Exp $
*
* WIN1250 client encoding updated by Pavel Behal
*
@@ -29,7 +29,7 @@
* SQL/ASCII
*/
static int pg_ascii2wchar_with_len
(const unsigned char *from, pg_wchar * to, int len)
(const unsigned char *from, pg_wchar *to, int len)
{
int cnt = 0;
@@ -54,7 +54,7 @@ pg_ascii_mblen(const unsigned char *s)
*/
static int pg_euc2wchar_with_len
(const unsigned char *from, pg_wchar * to, int len)
(const unsigned char *from, pg_wchar *to, int len)
{
int cnt = 0;
@@ -111,7 +111,7 @@ pg_euc_mblen(const unsigned char *s)
* EUC_JP
*/
static int pg_eucjp2wchar_with_len
(const unsigned char *from, pg_wchar * to, int len)
(const unsigned char *from, pg_wchar *to, int len)
{
return (pg_euc2wchar_with_len(from, to, len));
}
@@ -126,7 +126,7 @@ pg_eucjp_mblen(const unsigned char *s)
* EUC_KR
*/
static int pg_euckr2wchar_with_len
(const unsigned char *from, pg_wchar * to, int len)
(const unsigned char *from, pg_wchar *to, int len)
{
return (pg_euc2wchar_with_len(from, to, len));
}
@@ -141,7 +141,7 @@ pg_euckr_mblen(const unsigned char *s)
* EUC_CN
*/
static int pg_euccn2wchar_with_len
(const unsigned char *from, pg_wchar * to, int len)
(const unsigned char *from, pg_wchar *to, int len)
{
int cnt = 0;
@@ -195,7 +195,7 @@ pg_euccn_mblen(const unsigned char *s)
* EUC_TW
*/
static int pg_euctw2wchar_with_len
(const unsigned char *from, pg_wchar * to, int len)
(const unsigned char *from, pg_wchar *to, int len)
{
int cnt = 0;
@@ -257,7 +257,7 @@ pg_euctw_mblen(const unsigned char *s)
* "from" not necessarily null terminated.
*/
static int
pg_utf2wchar_with_len(const unsigned char *from, pg_wchar * to, int len)
pg_utf2wchar_with_len(const unsigned char *from, pg_wchar *to, int len)
{
unsigned char c1,
c2,
@@ -325,7 +325,7 @@ pg_utf_mblen(const unsigned char *s)
* "from" not necessarily null terminated.
*/
static int
pg_mule2wchar_with_len(const unsigned char *from, pg_wchar * to, int len)
pg_mule2wchar_with_len(const unsigned char *from, pg_wchar *to, int len)
{
int cnt = 0;
@@ -395,7 +395,7 @@ pg_mule_mblen(const unsigned char *s)
* ISO8859-1
*/
static int
pg_latin12wchar_with_len(const unsigned char *from, pg_wchar * to, int len)
pg_latin12wchar_with_len(const unsigned char *from, pg_wchar *to, int len)
{
int cnt = 0;
@@ -458,33 +458,33 @@ pg_big5_mblen(const unsigned char *s)
}
pg_wchar_tbl pg_wchar_table[] = {
{pg_ascii2wchar_with_len, pg_ascii_mblen, 1}, /* 0; PG_SQL_ASCII */
{pg_eucjp2wchar_with_len, pg_eucjp_mblen, 3}, /* 1; PG_EUC_JP */
{pg_euccn2wchar_with_len, pg_euccn_mblen, 3}, /* 2; PG_EUC_CN */
{pg_euckr2wchar_with_len, pg_euckr_mblen, 3}, /* 3; PG_EUC_KR */
{pg_euctw2wchar_with_len, pg_euctw_mblen, 3}, /* 4; PG_EUC_TW */
{pg_ascii2wchar_with_len, pg_ascii_mblen, 1}, /* 0; PG_SQL_ASCII */
{pg_eucjp2wchar_with_len, pg_eucjp_mblen, 3}, /* 1; PG_EUC_JP */
{pg_euccn2wchar_with_len, pg_euccn_mblen, 3}, /* 2; PG_EUC_CN */
{pg_euckr2wchar_with_len, pg_euckr_mblen, 3}, /* 3; PG_EUC_KR */
{pg_euctw2wchar_with_len, pg_euctw_mblen, 3}, /* 4; PG_EUC_TW */
{pg_utf2wchar_with_len, pg_utf_mblen, 3}, /* 5; PG_UNICODE */
{pg_mule2wchar_with_len, pg_mule_mblen, 3}, /* 6; PG_MULE_INTERNAL */
{pg_latin12wchar_with_len, pg_latin1_mblen, 1}, /* 7; PG_LATIN1 */
{pg_latin12wchar_with_len, pg_latin1_mblen, 1}, /* 8; PG_LATIN2 */
{pg_latin12wchar_with_len, pg_latin1_mblen, 1}, /* 9; PG_LATIN3 */
{pg_latin12wchar_with_len, pg_latin1_mblen, 1}, /* 10; PG_LATIN4 */
{pg_latin12wchar_with_len, pg_latin1_mblen, 1}, /* 11; PG_LATIN5 */
{pg_latin12wchar_with_len, pg_latin1_mblen, 1}, /* 12; PG_KOI8 */
{pg_latin12wchar_with_len, pg_latin1_mblen, 1}, /* 13; PG_WIN1251 */
{pg_latin12wchar_with_len, pg_latin1_mblen, 1}, /* 14; PG_ALT */
{pg_latin12wchar_with_len, pg_latin1_mblen, 1}, /* 15; ISO-8859-5 */
{pg_latin12wchar_with_len, pg_latin1_mblen, 1}, /* 16; ISO-8859-6 */
{pg_latin12wchar_with_len, pg_latin1_mblen, 1}, /* 17; ISO-8859-7 */
{pg_latin12wchar_with_len, pg_latin1_mblen, 1}, /* 18; ISO-8859-8 */
{pg_latin12wchar_with_len, pg_latin1_mblen, 1}, /* 19; ISO-8859-10 */
{pg_latin12wchar_with_len, pg_latin1_mblen, 1}, /* 20; ISO-8859-13 */
{pg_latin12wchar_with_len, pg_latin1_mblen, 1}, /* 21; ISO-8859-14 */
{pg_latin12wchar_with_len, pg_latin1_mblen, 1}, /* 22; ISO-8859-15 */
{pg_latin12wchar_with_len, pg_latin1_mblen, 1}, /* 23; ISO-8859-16 */
{0, pg_sjis_mblen, 2}, /* 24; PG_SJIS */
{0, pg_big5_mblen, 2}, /* 25; PG_BIG5 */
{pg_latin12wchar_with_len, pg_latin1_mblen, 1} /* 26; PG_WIN1250 */
{pg_mule2wchar_with_len, pg_mule_mblen, 3}, /* 6; PG_MULE_INTERNAL */
{pg_latin12wchar_with_len, pg_latin1_mblen, 1}, /* 7; PG_LATIN1 */
{pg_latin12wchar_with_len, pg_latin1_mblen, 1}, /* 8; PG_LATIN2 */
{pg_latin12wchar_with_len, pg_latin1_mblen, 1}, /* 9; PG_LATIN3 */
{pg_latin12wchar_with_len, pg_latin1_mblen, 1}, /* 10; PG_LATIN4 */
{pg_latin12wchar_with_len, pg_latin1_mblen, 1}, /* 11; PG_LATIN5 */
{pg_latin12wchar_with_len, pg_latin1_mblen, 1}, /* 12; PG_KOI8 */
{pg_latin12wchar_with_len, pg_latin1_mblen, 1}, /* 13; PG_WIN1251 */
{pg_latin12wchar_with_len, pg_latin1_mblen, 1}, /* 14; PG_ALT */
{pg_latin12wchar_with_len, pg_latin1_mblen, 1}, /* 15; ISO-8859-5 */
{pg_latin12wchar_with_len, pg_latin1_mblen, 1}, /* 16; ISO-8859-6 */
{pg_latin12wchar_with_len, pg_latin1_mblen, 1}, /* 17; ISO-8859-7 */
{pg_latin12wchar_with_len, pg_latin1_mblen, 1}, /* 18; ISO-8859-8 */
{pg_latin12wchar_with_len, pg_latin1_mblen, 1}, /* 19; ISO-8859-10 */
{pg_latin12wchar_with_len, pg_latin1_mblen, 1}, /* 20; ISO-8859-13 */
{pg_latin12wchar_with_len, pg_latin1_mblen, 1}, /* 21; ISO-8859-14 */
{pg_latin12wchar_with_len, pg_latin1_mblen, 1}, /* 22; ISO-8859-15 */
{pg_latin12wchar_with_len, pg_latin1_mblen, 1}, /* 23; ISO-8859-16 */
{0, pg_sjis_mblen, 2}, /* 24; PG_SJIS */
{0, pg_big5_mblen, 2}, /* 25; PG_BIG5 */
{pg_latin12wchar_with_len, pg_latin1_mblen, 1} /* 26; PG_WIN1250 */
};
/* returns the byte length of a word for mule internal code */
@@ -502,9 +502,9 @@ pg_encoding_mblen(int encoding, const unsigned char *mbstr)
{
Assert(PG_VALID_ENCODING(encoding));
return( (encoding >= 0 &&
encoding < sizeof(pg_wchar_table)/sizeof(pg_wchar_tbl)) ?
((*pg_wchar_table[encoding].mblen) (mbstr)) :
return ((encoding >= 0 &&
encoding < sizeof(pg_wchar_table) / sizeof(pg_wchar_tbl)) ?
((*pg_wchar_table[encoding].mblen) (mbstr)) :
((*pg_wchar_table[PG_SQL_ASCII].mblen) (mbstr)));
}
@@ -531,59 +531,62 @@ pg_encoding_max_length(int encoding)
char *
pg_verifymbstr(const unsigned char *mbstr, int len)
{
int l;
int i, j;
static char buf[256];
int slen = 0;
int l;
int i,
j;
static char buf[256];
int slen = 0;
/* we do not check single byte encodings */
if (pg_database_encoding_max_length() <= 1)
return NULL;
return NULL;
while (len > 0 && *mbstr)
{
/* special UTF-8 check */
if (GetDatabaseEncoding() == PG_UTF8 &&
(*mbstr & 0xf8) == 0xf0)
(*mbstr & 0xf8) == 0xf0)
{
snprintf(buf, sizeof(buf), "Unicode >= 0x10000 is not supoorted");
return(buf);
snprintf(buf, sizeof(buf), "Unicode >= 0x10000 is not supoorted");
return (buf);
}
l = pg_mblen(mbstr);
/* multi-byte letter? */
if (l > 1)
{
for (i=1;i<l;i++)
{
if (i > len || *(mbstr+i) == '\0' ||
/* we assume that every muti-byte letter
* consists of bytes being the 8th bit set
*/
((*(mbstr+i) & 0x80) == 0))
for (i = 1; i < l; i++)
{
int remains = sizeof(buf);
char *p = buf;
if (i > len || *(mbstr + i) == '\0' ||
slen = snprintf(p, remains, "Invalid %s character sequence found (0x",
GetDatabaseEncodingName());
p += slen;
remains -= slen;
/*
* we assume that every muti-byte letter consists of bytes
* being the 8th bit set
*/
((*(mbstr + i) & 0x80) == 0))
{
int remains = sizeof(buf);
char *p = buf;
i = ((*(mbstr+i) & 0x80) == 0)?l:i;
slen = snprintf(p, remains, "Invalid %s character sequence found (0x",
GetDatabaseEncodingName());
p += slen;
remains -= slen;
for (j=0;j<i;j++)
{
slen = snprintf(p, remains, "%02x",
*(mbstr+j));
p += slen;
remains -= slen;
}
snprintf(p, remains, ")");
return(buf);
i = ((*(mbstr + i) & 0x80) == 0) ? l : i;
for (j = 0; j < i; j++)
{
slen = snprintf(p, remains, "%02x",
*(mbstr + j));
p += slen;
remains -= slen;
}
snprintf(p, remains, ")");
return (buf);
}
}
}
}
len -= l;
mbstr += l;
@@ -599,5 +602,4 @@ pg_database_encoding_max_length(void)
{
return pg_wchar_table[GetDatabaseEncoding()].maxmblen;
}
#endif

View File

@@ -43,7 +43,7 @@ pg_char_and_wchar_strcmp(s1, s2)
register const char *s1;
register const pg_wchar *s2;
{
while ((pg_wchar) * s1 == *s2++)
while ((pg_wchar) *s1 == *s2++)
if (*s1++ == 0)
return 0;
return *(const unsigned char *) s1 - *(const pg_wchar *) (s2 - 1);