aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend/utils')
-rw-r--r--src/backend/utils/adt/ascii.c8
-rw-r--r--src/backend/utils/init/postinit.c4
-rw-r--r--src/backend/utils/mb/Makefile8
-rw-r--r--src/backend/utils/mb/Unicode/Makefile6
-rw-r--r--src/backend/utils/mb/Unicode/UCS_to_cyrillic.pl8
-rw-r--r--src/backend/utils/mb/conv.c200
-rw-r--r--src/backend/utils/mb/mbutils.c136
-rw-r--r--src/backend/utils/mb/wchar.c70
8 files changed, 226 insertions, 214 deletions
diff --git a/src/backend/utils/adt/ascii.c b/src/backend/utils/adt/ascii.c
index 234651aebab..99bafca1baa 100644
--- a/src/backend/utils/adt/ascii.c
+++ b/src/backend/utils/adt/ascii.c
@@ -1,7 +1,7 @@
/* -----------------------------------------------------------------------
* ascii.c
*
- * $Header: /cvsroot/pgsql/src/backend/utils/adt/ascii.c,v 1.8 2001/03/22 06:16:17 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/adt/ascii.c,v 1.9 2001/09/06 04:57:29 ishii Exp $
*
* Portions Copyright (c) 1999-2000, PostgreSQL Global Development Group
*
@@ -78,7 +78,7 @@ pg_to_ascii(unsigned char *src, unsigned char *src_end, unsigned char *desc, int
#define RANGE_160 160
- if (enc == LATIN1)
+ if (enc == PG_LATIN1)
{
/*
@@ -87,7 +87,7 @@ pg_to_ascii(unsigned char *src, unsigned char *src_end, unsigned char *desc, int
ascii = " cL Y \"Ca -R 'u ., ?AAAAAAACEEEEIIII NOOOOOxOUUUUYTBaaaaaaaceeeeiiii nooooo/ouuuuyty";
range = RANGE_160;
}
- else if (enc == LATIN2)
+ else if (enc == PG_LATIN2)
{
/*
@@ -96,7 +96,7 @@ pg_to_ascii(unsigned char *src, unsigned char *src_end, unsigned char *desc, int
ascii = " A L LS \"SSTZ-ZZ a,l'ls ,sstz\"zzRAAAALCCCEEEEIIDDNNOOOOxRUUUUYTBraaaalccceeeeiiddnnoooo/ruuuuyt.";
range = RANGE_160;
}
- else if (enc == WIN1250)
+ else if (enc == PG_WIN1250)
{
/*
diff --git a/src/backend/utils/init/postinit.c b/src/backend/utils/init/postinit.c
index 51bd00bec30..edaf3893e9e 100644
--- a/src/backend/utils/init/postinit.c
+++ b/src/backend/utils/init/postinit.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/utils/init/postinit.c,v 1.88 2001/08/25 18:52:42 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/init/postinit.c,v 1.89 2001/09/06 04:57:29 ishii Exp $
*
*
*-------------------------------------------------------------------------
@@ -127,7 +127,7 @@ ReverifyMyDatabase(const char *name)
#ifdef MULTIBYTE
SetDatabaseEncoding(dbform->encoding);
#else
- if (dbform->encoding != SQL_ASCII)
+ if (dbform->encoding != PG_SQL_ASCII)
elog(FATAL, "database was initialized with MULTIBYTE encoding %d,\n\tbut the backend was compiled without multibyte support.\n\tlooks like you need to initdb or recompile.",
dbform->encoding);
#endif
diff --git a/src/backend/utils/mb/Makefile b/src/backend/utils/mb/Makefile
index 952ba8789d8..2f29a33b2bf 100644
--- a/src/backend/utils/mb/Makefile
+++ b/src/backend/utils/mb/Makefile
@@ -4,7 +4,7 @@
# Makefile for utils/mb
#
# IDENTIFICATION
-# $Header: /cvsroot/pgsql/src/backend/utils/mb/Makefile,v 1.15 2000/11/30 20:36:11 petere Exp $
+# $Header: /cvsroot/pgsql/src/backend/utils/mb/Makefile,v 1.16 2001/09/06 04:57:29 ishii Exp $
#
#-------------------------------------------------------------------------
@@ -12,7 +12,7 @@ subdir = src/backend/utils/mb
top_builddir = ../../../..
include $(top_builddir)/src/Makefile.global
-OBJS = common.o conv.o mbutils.o wchar.o wstrcmp.o wstrncmp.o big5.o
+OBJS = encnames.o conv.o mbutils.o wchar.o wstrcmp.o wstrncmp.o big5.o
all: SUBSYS.o
@@ -21,13 +21,13 @@ SUBSYS.o: $(OBJS)
utftest.o: utftest.c conv.c wchar.c mbutils.c
-sjistest: sjistest.o palloc.o common.o mbutils.o wchar.o wstrcmp.o wstrncmp.o big5.o
+sjistest: sjistest.o palloc.o encnames.o mbutils.o wchar.o wstrcmp.o wstrncmp.o big5.o
$(CC) $(CFLAGS) $(LDFLAGS) $^ $(LIBS) -o $@
liketest: liketest.o palloc.o $(OBJS)
$(CC) $(CFLAGS) $(LDFLAGS) $^ $(LIBS) -o $@
-utftest: utftest.o palloc.o common.o wstrcmp.o wstrncmp.o big5.o
+utftest: utftest.o palloc.o encnames.o wstrcmp.o wstrncmp.o big5.o
$(CC) $(CFLAGS) $(LDFLAGS) $^ $(LIBS) -o $@
depend dep:
diff --git a/src/backend/utils/mb/Unicode/Makefile b/src/backend/utils/mb/Unicode/Makefile
index 68a7750d1f0..6d9185b0381 100644
--- a/src/backend/utils/mb/Unicode/Makefile
+++ b/src/backend/utils/mb/Unicode/Makefile
@@ -4,7 +4,7 @@
#
# Copyright 2001 by PostgreSQL Global Development Group
#
-# $Header: /cvsroot/pgsql/src/backend/utils/mb/Unicode/Makefile,v 1.2 2001/04/29 07:27:38 ishii Exp $
+# $Header: /cvsroot/pgsql/src/backend/utils/mb/Unicode/Makefile,v 1.3 2001/09/06 04:57:29 ishii Exp $
#
#-------------------------------------------------------------------------
@@ -18,8 +18,8 @@ ISO8859MAPS=iso8859_2_to_utf8.map iso8859_3_to_utf8.map \
utf8_to_iso8859_4.map utf8_to_iso8859_5.map
-CYRILLICMAPS=KOI8_to_utf8.map WIN_to_utf8.map ALT_to_utf8.map\
- utf8_to_KOI8.map utf8_to_WIN.map utf8_to_ALT.map
+CYRILLICMAPS=koi8r_to_utf8.map win1251_to_utf8.map alt_to_utf8.map\
+ utf8_to_koi8r.map utf8_to_win1251.map utf8_to_alt.map
MAPS= $(ISO8859MAPS) $(CYRILLICMAPS)\
big5_to_utf8.map euc_cn_to_utf8.map euc_jp_to_utf8.map \
diff --git a/src/backend/utils/mb/Unicode/UCS_to_cyrillic.pl b/src/backend/utils/mb/Unicode/UCS_to_cyrillic.pl
index cc4fb90ac06..3557ed40fdf 100644
--- a/src/backend/utils/mb/Unicode/UCS_to_cyrillic.pl
+++ b/src/backend/utils/mb/Unicode/UCS_to_cyrillic.pl
@@ -2,7 +2,7 @@
#
# Copyright 2001 by PostgreSQL Global Development Group
#
-# $Id: UCS_to_cyrillic.pl,v 1.1 2001/04/29 07:27:38 ishii Exp $
+# $Id: UCS_to_cyrillic.pl,v 1.2 2001/09/06 04:57:29 ishii Exp $
#
# Generate UTF-8 <--> ISO8859 code conversion tables from
# map files provided by Unicode organization.
@@ -15,10 +15,10 @@
# # and Unicode name (not used in this script)
require "ucs2utf.pl";
-%filename = ('KOI8'=>'koi8-r.txt',
- 'WIN'=>'cp1251.txt',
+%filename = ('KOI8R'=>'koi8-r.txt',
+ 'WIN1251'=>'cp1251.txt',
'ALT'=>'cp866.txt');
-@charsets = ('KOI8','ALT','WIN');
+@charsets = ('KOI8R','ALT','WIN1251');
foreach $charset (@charsets) {
#
diff --git a/src/backend/utils/mb/conv.c b/src/backend/utils/mb/conv.c
index 91f781d21b6..6dbb9c6649a 100644
--- a/src/backend/utils/mb/conv.c
+++ b/src/backend/utils/mb/conv.c
@@ -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.26 2001/05/28 01:00:25 ishii Exp $
+ * $Id: conv.c,v 1.27 2001/09/06 04:57:29 ishii Exp $
*
*
*/
@@ -39,12 +39,12 @@
#include "Unicode/utf8_to_big5.map"
#include "Unicode/big5_to_utf8.map"
/* Cyrillic charset conversion */
-#include "Unicode/ALT_to_utf8.map"
-#include "Unicode/KOI8_to_utf8.map"
-#include "Unicode/WIN_to_utf8.map"
-#include "Unicode/utf8_to_ALT.map"
-#include "Unicode/utf8_to_KOI8.map"
-#include "Unicode/utf8_to_WIN.map"
+#include "Unicode/alt_to_utf8.map"
+#include "Unicode/koi8r_to_utf8.map"
+#include "Unicode/win1251_to_utf8.map"
+#include "Unicode/utf8_to_alt.map"
+#include "Unicode/utf8_to_koi8r.map"
+#include "Unicode/utf8_to_win1251.map"
#endif /* UNICODE_CONVERSION */
@@ -824,16 +824,16 @@ mic2ascii(unsigned char *mic, unsigned char *p, int len)
* Alternativny Variant (MS-DOS CP866)
*/
-/* koi2mic: KOI8-R to Mule internal code */
+/* koi8r2mic: KOI8-R to Mule internal code */
static void
-koi2mic(unsigned char *l, unsigned char *p, int len)
+koi8r2mic(unsigned char *l, unsigned char *p, int len)
{
latin2mic(l, p, len, LC_KOI8_R);
}
-/* mic2koi: Mule internal code to KOI8-R */
+/* mic2koi8r: Mule internal code to KOI8-R */
static void
-mic2koi(unsigned char *mic, unsigned char *p, int len)
+mic2koi8r(unsigned char *mic, unsigned char *p, int len)
{
mic2latin(mic, p, len, LC_KOI8_R);
}
@@ -981,7 +981,7 @@ mic2iso(unsigned char *mic, unsigned char *p, int len)
/* win2mic: CP1251 to Mule internal code */
static void
-win2mic(unsigned char *l, unsigned char *p, int len)
+win12512mic(unsigned char *l, unsigned char *p, int len)
{
static unsigned char win2koi[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
@@ -1007,7 +1007,7 @@ win2mic(unsigned char *l, unsigned char *p, int len)
/* mic2win: Mule internal code to CP1251 */
static void
-mic2win(unsigned char *mic, unsigned char *p, int len)
+mic2win1251(unsigned char *mic, unsigned char *p, int len)
{
static unsigned char koi2win[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
@@ -1343,23 +1343,23 @@ utf_to_latin5(unsigned char *utf, unsigned char *iso, int len)
*/
/*
- * UTF-8 --->KOI8
+ * UTF-8 --->KOI8-R
*/
static void
-utf_to_KOI8(unsigned char *utf, unsigned char *iso, int len)
+utf_to_KOI8R(unsigned char *utf, unsigned char *iso, int len)
{
- utf_to_local(utf, iso, ULmap_KOI8, sizeof(ULmap_KOI8) / sizeof(pg_utf_to_local), len);
+ utf_to_local(utf, iso, ULmap_KOI8R, sizeof(ULmap_KOI8R) / sizeof(pg_utf_to_local), len);
}
/*
- * UTF-8 --->WIN
+ * UTF-8 --->WIN1251
*/
static void
-utf_to_WIN(unsigned char *utf, unsigned char *iso, int len)
+utf_to_WIN1251(unsigned char *utf, unsigned char *iso, int len)
{
- utf_to_local(utf, iso, ULmap_WIN, sizeof(ULmap_WIN) / sizeof(pg_utf_to_local), len);
+ utf_to_local(utf, iso, ULmap_WIN1251, sizeof(ULmap_WIN1251) / sizeof(pg_utf_to_local), len);
}
/*
@@ -1382,10 +1382,8 @@ local_to_utf(unsigned char *iso, unsigned char *utf,
unsigned int iiso;
int l;
pg_local_to_utf *p;
- pg_encoding_conv_tbl *e;
- e = pg_get_enc_ent(encoding);
- if (e == 0)
+ if (!PG_VALID_ENCODING(encoding))
elog(ERROR, "Invalid encoding number %d", encoding);
for (; len > 0 && *iso; len -= l)
@@ -1424,7 +1422,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, e->name);
+ iiso, (&pg_enc2name_tbl[ encoding ])->name);
continue;
}
if (p->utf & 0xff000000)
@@ -1445,7 +1443,7 @@ local_to_utf(unsigned char *iso, unsigned char *utf,
static void
latin2_to_utf(unsigned char *iso, unsigned char *utf, int len)
{
- local_to_utf(iso, utf, LUmapISO8859_2, sizeof(LUmapISO8859_2) / sizeof(pg_local_to_utf), LATIN2, len);
+ local_to_utf(iso, utf, LUmapISO8859_2, sizeof(LUmapISO8859_2) / sizeof(pg_local_to_utf), PG_LATIN2, len);
}
/*
@@ -1454,7 +1452,7 @@ latin2_to_utf(unsigned char *iso, unsigned char *utf, int len)
static void
latin3_to_utf(unsigned char *iso, unsigned char *utf, int len)
{
- local_to_utf(iso, utf, LUmapISO8859_3, sizeof(LUmapISO8859_3) / sizeof(pg_local_to_utf), LATIN3, len);
+ local_to_utf(iso, utf, LUmapISO8859_3, sizeof(LUmapISO8859_3) / sizeof(pg_local_to_utf), PG_LATIN3, len);
}
/*
@@ -1463,7 +1461,7 @@ latin3_to_utf(unsigned char *iso, unsigned char *utf, int len)
static void
latin4_to_utf(unsigned char *iso, unsigned char *utf, int len)
{
- local_to_utf(iso, utf, LUmapISO8859_4, sizeof(LUmapISO8859_4) / sizeof(pg_local_to_utf), LATIN4, len);
+ local_to_utf(iso, utf, LUmapISO8859_4, sizeof(LUmapISO8859_4) / sizeof(pg_local_to_utf), PG_LATIN4, len);
}
/*
@@ -1472,25 +1470,25 @@ latin4_to_utf(unsigned char *iso, unsigned char *utf, int len)
static void
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), LATIN5, len);
+ local_to_utf(iso, utf, LUmapISO8859_5, sizeof(LUmapISO8859_5) / sizeof(pg_local_to_utf), PG_LATIN5, len);
}
/*
- * KOI8 ---> UTF-8
+ * KOI8-R ---> UTF-8
*/
static void
-KOI8_to_utf(unsigned char *iso, unsigned char *utf, int len)
+KOI8R_to_utf(unsigned char *iso, unsigned char *utf, int len)
{
- local_to_utf(iso, utf, LUmapKOI8, sizeof(LUmapKOI8) / sizeof(pg_local_to_utf), KOI8, len);
+ local_to_utf(iso, utf, LUmapKOI8R, sizeof(LUmapKOI8R) / sizeof(pg_local_to_utf), PG_KOI8R, len);
}
/*
- * WIN ---> UTF-8
+ * WIN1251 ---> UTF-8
*/
static void
-WIN_to_utf(unsigned char *iso, unsigned char *utf, int len)
+WIN1251_to_utf(unsigned char *iso, unsigned char *utf, int len)
{
- local_to_utf(iso, utf, LUmapWIN, sizeof(LUmapWIN) / sizeof(pg_local_to_utf), WIN, len);
+ local_to_utf(iso, utf, LUmapWIN1251, sizeof(LUmapWIN1251) / sizeof(pg_local_to_utf), PG_WIN1251, len);
}
/*
@@ -1499,7 +1497,7 @@ WIN_to_utf(unsigned char *iso, unsigned char *utf, int len)
static void
ALT_to_utf(unsigned char *iso, unsigned char *utf, int len)
{
- local_to_utf(iso, utf, LUmapALT, sizeof(LUmapALT) / sizeof(pg_local_to_utf), ALT, len);
+ local_to_utf(iso, utf, LUmapALT, sizeof(LUmapALT) / sizeof(pg_local_to_utf), PG_ALT, len);
}
/*
* UTF-8 ---> EUC_JP
@@ -1519,7 +1517,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), EUC_JP, len);
+ sizeof(LUmapEUC_JP) / sizeof(pg_local_to_utf), PG_EUC_JP, len);
}
/*
@@ -1540,7 +1538,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), EUC_CN, len);
+ sizeof(LUmapEUC_CN) / sizeof(pg_local_to_utf), PG_EUC_CN, len);
}
/*
@@ -1561,7 +1559,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), EUC_KR, len);
+ sizeof(LUmapEUC_KR) / sizeof(pg_local_to_utf), PG_EUC_KR, len);
}
/*
@@ -1582,7 +1580,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), EUC_TW, len);
+ sizeof(LUmapEUC_TW) / sizeof(pg_local_to_utf), PG_EUC_TW, len);
}
/*
@@ -1603,7 +1601,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), SJIS, len);
+ sizeof(LUmapSJIS) / sizeof(pg_local_to_utf), PG_SJIS, len);
}
/*
@@ -1624,85 +1622,59 @@ 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), BIG5, len);
-}
-
-/*-----------------------------------------------------------------*/
-
-pg_encoding_conv_tbl pg_conv_tbl[] = {
- {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_to_utf, utf_to_euc_cn}, /* EUC_CN */
- {EUC_KR, "EUC_KR", 0, euc_kr2mic, mic2euc_kr,
- euc_kr_to_utf, utf_to_euc_kr}, /* EUC_KR */
- {EUC_TW, "EUC_TW", 0, euc_tw2mic, mic2euc_tw,
- euc_tw_to_utf, utf_to_euc_tw}, /* EUC_TW */
- {UNICODE, "UNICODE", 0, 0, 0}, /* UNICODE */
- {MULE_INTERNAL, "MULE_INTERNAL", 0, 0, 0}, /* MULE_INTERNAL */
- {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,
- KOI8_to_utf, utf_to_KOI8}, /* KOI8-R */
- {WIN, "WIN", 0, win2mic, mic2win,
- WIN_to_utf , utf_to_WIN}, /* CP1251 */
- {ALT, "ALT", 0, alt2mic, mic2alt,
- ALT_to_utf, utf_to_ALT}, /* CP866 */
- {SJIS, "SJIS", 1, sjis2mic, mic2sjis,
- sjis_to_utf, utf_to_sjis}, /* SJIS */
- {BIG5, "BIG5", 1, big52mic, mic2big5,
- big5_to_utf, utf_to_big5}, /* Big5 */
- {WIN1250, "WIN1250", 1, win12502mic, mic2win1250,
- 0, 0}, /* WIN 1250 */
- {-1, "", 0, 0, 0, 0} /* end mark */
+ sizeof(LUmapBIG5) / sizeof(pg_local_to_utf), PG_BIG5, len);
+}
+
+/* ----------
+ * Encoding conversion routines
+ *
+ * WARINIG: must by same order as pg_enc in include/mb/pg_wchar.h!
+ * ----------
+ */
+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, latin1_to_utf, utf_to_latin1 },
+ { PG_LATIN2, latin22mic, mic2latin2, latin2_to_utf, utf_to_latin2 },
+ { PG_LATIN3, latin32mic, mic2latin3, latin3_to_utf, utf_to_latin3 },
+ { PG_LATIN4, latin42mic, mic2latin4, latin4_to_utf, utf_to_latin4 },
+ { PG_LATIN5, iso2mic, mic2iso, latin5_to_utf, utf_to_latin5 },
+ { 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_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_encoding_conv_tbl pg_conv_tbl[] = {
- {SQL_ASCII, "SQL_ASCII", 0, ascii2mic, mic2ascii,
- 0, 0}, /* SQL/ASCII */
- {EUC_JP, "EUC_JP", 0, euc_jp2mic, mic2euc_jp,
- 0, 0}, /* EUC_JP */
- {EUC_CN, "EUC_CN", 0, euc_cn2mic, mic2euc_cn,
- 0, 0}, /* 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,
- 0, 0}, /* ISO 8859 Latin 1 */
- {LATIN2, "LATIN2", 0, latin22mic, mic2latin2,
- 0, 0}, /* ISO 8859 Latin 2 */
- {LATIN3, "LATIN3", 0, latin32mic, mic2latin3,
- 0, 0}, /* ISO 8859 Latin 3 */
- {LATIN4, "LATIN4", 0, latin42mic, mic2latin4,
- 0, 0}, /* ISO 8859 Latin 4 */
- {LATIN5, "LATIN5", 0, iso2mic, mic2iso,
- 0, 0}, /* 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 */
+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_KOI8R, koi8r2mic, mic2koi8r, 0, 0 },
+ { PG_WIN1251, win12512mic, mic2win1251, 0, 0 },
+ { PG_ALT, alt2mic, mic2alt, 0, 0 },
+ { PG_SJIS, sjis2mic, mic2sjis, 0, 0 },
+ { PG_BIG5, big52mic, mic2big5, 0, 0 },
+ { PG_WIN1250, win12502mic, mic2win1250, 0, 0 },
};
#endif /* UNICODE_CONVERSION */
diff --git a/src/backend/utils/mb/mbutils.c b/src/backend/utils/mb/mbutils.c
index 8e4fc56ef09..39d59cdb140 100644
--- a/src/backend/utils/mb/mbutils.c
+++ b/src/backend/utils/mb/mbutils.c
@@ -3,7 +3,7 @@
* client encoding and server internal encoding.
* (currently mule internal code (mic) is used)
* Tatsuo Ishii
- * $Id: mbutils.c,v 1.19 2001/08/15 07:07:40 ishii Exp $
+ * $Id: mbutils.c,v 1.20 2001/09/06 04:57:29 ishii Exp $
*/
#include "postgres.h"
@@ -11,26 +11,36 @@
#include "mb/pg_wchar.h"
#include "utils/builtins.h"
-static int client_encoding = -1;
-static void (*client_to_mic) ();/* something to MIC */
-static void (*client_from_mic) (); /* MIC to something */
-static void (*server_to_mic) ();/* something to MIC */
-static void (*server_from_mic) (); /* MIC to something */
+/*
+ * 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.
+ *
+ * Default is PG_SQL_ASCII encoding (but this is never used, because
+ * backend during startup init it by SetDatabaseEncoding()).
+ *
+ * Karel Zak (Aug 2001)
+ */
+static pg_enc2name *ClientEncoding = NULL;
+static pg_enc2name *DatabaseEncoding = &pg_enc2name_tbl[ PG_SQL_ASCII ];
+
+static void (*client_to_mic) (); /* something to MIC */
+static void (*client_from_mic) (); /* MIC to something */
+static void (*server_to_mic) (); /* something to MIC */
+static void (*server_from_mic) (); /* MIC to something */
/*
* find encoding table entry by encoding
*/
-pg_encoding_conv_tbl *
-pg_get_enc_ent(int encoding)
+pg_enconv *
+pg_get_enconv_by_encoding(int encoding)
{
- pg_encoding_conv_tbl *p = pg_conv_tbl;
-
- for (; p->encoding >= 0; p++)
+ if (PG_VALID_ENCODING(encoding))
{
- if (p->encoding == encoding)
- return (p);
+ Assert((&pg_enconv_tbl[ encoding ])->encoding == encoding);
+ return &pg_enconv_tbl[ encoding ];
}
- return (0);
+ return 0;
}
/*
@@ -56,38 +66,38 @@ pg_find_encoding_converters(int src, int dest, void (**src_to_mic)(), void (**de
{ /* src == dest? */
*src_to_mic = *dest_from_mic = 0;
}
- else if (src == MULE_INTERNAL)
+ else if (src == PG_MULE_INTERNAL)
{ /* src == MULE_INETRNAL? */
- *dest_from_mic = pg_get_enc_ent(dest)->from_mic;
+ *dest_from_mic = pg_get_enconv_by_encoding(dest)->from_mic;
if (*dest_from_mic == 0)
return (-1);
*src_to_mic = 0;
}
- else if (dest == MULE_INTERNAL)
+ else if (dest == PG_MULE_INTERNAL)
{ /* dest == MULE_INETRNAL? */
- *src_to_mic = pg_get_enc_ent(src)->to_mic;
+ *src_to_mic = pg_get_enconv_by_encoding(src)->to_mic;
if (*src_to_mic == 0)
return (-1);
*dest_from_mic = 0;
}
- else if (src == UNICODE)
+ else if (src == PG_UTF8)
{ /* src == UNICODE? */
- *dest_from_mic = pg_get_enc_ent(dest)->from_unicode;
+ *dest_from_mic = pg_get_enconv_by_encoding(dest)->from_unicode;
if (*dest_from_mic == 0)
return (-1);
*src_to_mic = 0;
}
- else if (dest == UNICODE)
+ else if (dest == PG_UTF8)
{ /* dest == UNICODE? */
- *src_to_mic = pg_get_enc_ent(src)->to_unicode;
+ *src_to_mic = pg_get_enconv_by_encoding(src)->to_unicode;
if (*src_to_mic == 0)
return (-1);
*dest_from_mic = 0;
}
else
{
- *src_to_mic = pg_get_enc_ent(src)->to_mic;
- *dest_from_mic = pg_get_enc_ent(dest)->from_mic;
+ *src_to_mic = pg_get_enconv_by_encoding(src)->to_mic;
+ *dest_from_mic = pg_get_enconv_by_encoding(dest)->from_mic;
if (*src_to_mic == 0 || *dest_from_mic == 0)
return (-1);
}
@@ -101,11 +111,17 @@ pg_find_encoding_converters(int src, int dest, void (**src_to_mic)(), void (**de
int
pg_set_client_encoding(int encoding)
{
- int current_server_encoding = GetDatabaseEncoding();
+ int current_server_encoding = DatabaseEncoding->encoding;
+
+ if (!PG_VALID_FE_ENCODING(encoding))
+ return (-1);
if (pg_find_encoding_converters(encoding, current_server_encoding, &client_to_mic, &server_from_mic) < 0)
return (-1);
- client_encoding = encoding;
+
+ ClientEncoding = &pg_enc2name_tbl[ encoding ];
+
+ Assert(ClientEncoding->encoding == encoding);
if (pg_find_encoding_converters(current_server_encoding, encoding, &server_to_mic, &client_from_mic) < 0)
return (-1);
@@ -118,12 +134,30 @@ pg_set_client_encoding(int encoding)
int
pg_get_client_encoding()
{
- if (client_encoding == -1)
+ Assert(DatabaseEncoding);
+
+ if (ClientEncoding == NULL)
{
/* this is the first time */
- client_encoding = GetDatabaseEncoding();
+ ClientEncoding = DatabaseEncoding;
}
- return (client_encoding);
+ return (ClientEncoding->encoding);
+}
+
+/*
+ * returns the current client encoding name
+ */
+const char *
+pg_get_client_encoding_name()
+{
+ Assert(DatabaseEncoding);
+
+ if (ClientEncoding == NULL)
+ {
+ /* this is the first time */
+ ClientEncoding = DatabaseEncoding;
+ }
+ return (ClientEncoding->name);
}
/*
@@ -189,7 +223,7 @@ 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 = GetDatabaseEncoding();
+ int db_encoding = DatabaseEncoding->encoding;
void (*src)(), (*dest)();
unsigned char *result;
text *retval;
@@ -277,7 +311,10 @@ pg_convert2(PG_FUNCTION_ARGS)
unsigned char *
pg_client_to_server(unsigned char *s, int len)
{
- if (client_encoding == GetDatabaseEncoding())
+ Assert(ClientEncoding);
+ Assert(DatabaseEncoding);
+
+ if (ClientEncoding->encoding == DatabaseEncoding->encoding)
return s;
return pg_do_encoding_conversion(s, len, client_to_mic, server_from_mic);
@@ -299,7 +336,10 @@ pg_client_to_server(unsigned char *s, int len)
unsigned char *
pg_server_to_client(unsigned char *s, int len)
{
- if (client_encoding == GetDatabaseEncoding())
+ Assert(ClientEncoding);
+ Assert(DatabaseEncoding);
+
+ if (ClientEncoding->encoding == DatabaseEncoding->encoding)
return s;
return pg_do_encoding_conversion(s, len, server_to_mic, client_from_mic);
@@ -309,21 +349,21 @@ pg_server_to_client(unsigned char *s, int len)
int
pg_mb2wchar(const unsigned char *from, pg_wchar * to)
{
- return (*pg_wchar_table[GetDatabaseEncoding()].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)
{
- return (*pg_wchar_table[GetDatabaseEncoding()].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[GetDatabaseEncoding()].mblen) (mbstr));
+ return ((*pg_wchar_table[ DatabaseEncoding->encoding ].mblen) (mbstr));
}
/* returns the length (counted as a wchar) of a multi-byte string */
@@ -407,27 +447,33 @@ pg_mbcharcliplen(const unsigned char *mbstr, int len, int limit)
return (clen);
}
-/*
- * functions for utils/init */
-static int DatabaseEncoding = MULTIBYTE;
-
void
SetDatabaseEncoding(int encoding)
{
- DatabaseEncoding = encoding;
+ if (!PG_VALID_BE_ENCODING(encoding))
+ elog(ERROR, "SetDatabaseEncoding(): invalid database encoding");
+
+ DatabaseEncoding = &pg_enc2name_tbl[ encoding ];
+ Assert(DatabaseEncoding->encoding == encoding);
}
int
GetDatabaseEncoding()
{
- return (DatabaseEncoding);
+ Assert(DatabaseEncoding);
+ return (DatabaseEncoding->encoding);
+}
+
+const char *
+GetDatabaseEncodingName()
+{
+ Assert(DatabaseEncoding);
+ return (DatabaseEncoding->name);
}
-/* for builtin-function */
Datum
getdatabaseencoding(PG_FUNCTION_ARGS)
{
- const char *encoding_name = pg_encoding_to_char(DatabaseEncoding);
-
- return DirectFunctionCall1(namein, CStringGetDatum(encoding_name));
+ Assert(DatabaseEncoding);
+ return DirectFunctionCall1(namein, CStringGetDatum(DatabaseEncoding->name));
}
diff --git a/src/backend/utils/mb/wchar.c b/src/backend/utils/mb/wchar.c
index 43371f9477a..a7e97cc1866 100644
--- a/src/backend/utils/mb/wchar.c
+++ b/src/backend/utils/mb/wchar.c
@@ -1,16 +1,22 @@
/*
* conversion functions between pg_wchar and multi-byte streams.
* Tatsuo Ishii
- * $Id: wchar.c,v 1.18 2001/04/19 02:34:35 ishii Exp $
+ * $Id: wchar.c,v 1.19 2001/09/06 04:57:29 ishii Exp $
*
* WIN1250 client encoding updated by Pavel Behal
*
*/
/* can be used in either frontend or backend */
#include "postgres_fe.h"
-
#include "mb/pg_wchar.h"
+#ifdef FRONTEND
+ #define Assert(condition)
+#else
+ #include "postgres.h"
+#endif
+
+
/*
* conversion to pg_wchar is done by "table driven."
* to add an encoding support, define mb2wchar_with_len(), mblen()
@@ -452,41 +458,24 @@ pg_big5_mblen(const unsigned char *s)
}
pg_wchar_tbl pg_wchar_table[] = {
- {pg_ascii2wchar_with_len, pg_ascii_mblen}, /* 0 */
- {pg_eucjp2wchar_with_len, pg_eucjp_mblen}, /* 1 */
- {pg_euccn2wchar_with_len, pg_euccn_mblen}, /* 2 */
- {pg_euckr2wchar_with_len, pg_euckr_mblen}, /* 3 */
- {pg_euctw2wchar_with_len, pg_euctw_mblen}, /* 4 */
- {pg_utf2wchar_with_len, pg_utf_mblen}, /* 5 */
- {pg_mule2wchar_with_len, pg_mule_mblen}, /* 6 */
- {pg_latin12wchar_with_len, pg_latin1_mblen}, /* 7 */
- {pg_latin12wchar_with_len, pg_latin1_mblen}, /* 8 */
- {pg_latin12wchar_with_len, pg_latin1_mblen}, /* 9 */
- {pg_latin12wchar_with_len, pg_latin1_mblen}, /* 10 */
- {pg_latin12wchar_with_len, pg_latin1_mblen}, /* 11 */
- {pg_latin12wchar_with_len, pg_latin1_mblen}, /* 12 */
- {pg_latin12wchar_with_len, pg_latin1_mblen}, /* 13 */
- {pg_latin12wchar_with_len, pg_latin1_mblen}, /* 14 */
- {pg_latin12wchar_with_len, pg_latin1_mblen}, /* 15 */
- {pg_latin12wchar_with_len, pg_latin1_mblen}, /* 16 */
- {pg_latin12wchar_with_len, pg_latin1_mblen}, /* 17 */
- {pg_latin12wchar_with_len, pg_latin1_mblen}, /* 18 */
- {pg_latin12wchar_with_len, pg_latin1_mblen}, /* 19 */
- {pg_latin12wchar_with_len, pg_latin1_mblen}, /* 20 */
- {pg_latin12wchar_with_len, pg_latin1_mblen}, /* 21 */
- {pg_latin12wchar_with_len, pg_latin1_mblen}, /* 22 */
- {pg_latin12wchar_with_len, pg_latin1_mblen}, /* 23 */
- {pg_latin12wchar_with_len, pg_latin1_mblen}, /* 24 */
- {pg_latin12wchar_with_len, pg_latin1_mblen}, /* 25 */
- {pg_latin12wchar_with_len, pg_latin1_mblen}, /* 26 */
- {pg_latin12wchar_with_len, pg_latin1_mblen}, /* 27 */
- {pg_latin12wchar_with_len, pg_latin1_mblen}, /* 28 */
- {pg_latin12wchar_with_len, pg_latin1_mblen}, /* 29 */
- {pg_latin12wchar_with_len, pg_latin1_mblen}, /* 30 */
- {pg_latin12wchar_with_len, pg_latin1_mblen}, /* 31 */
- {0, pg_sjis_mblen}, /* 32 */
- {0, pg_big5_mblen}, /* 33 */
- {pg_latin12wchar_with_len, pg_latin1_mblen} /* 34 */
+ {pg_ascii2wchar_with_len, pg_ascii_mblen}, /* 0; PG_SQL_ASCII */
+ {pg_eucjp2wchar_with_len, pg_eucjp_mblen}, /* 1; PG_EUC_JP */
+ {pg_euccn2wchar_with_len, pg_euccn_mblen}, /* 2; PG_EUC_CN */
+ {pg_euckr2wchar_with_len, pg_euckr_mblen}, /* 3; PG_EUC_KR */
+ {pg_euctw2wchar_with_len, pg_euctw_mblen}, /* 4; PG_EUC_TW */
+ {pg_utf2wchar_with_len, pg_utf_mblen}, /* 5; PG_UNICODE */
+ {pg_mule2wchar_with_len, pg_mule_mblen}, /* 6; PG_MULE_INTERNAL */
+ {pg_latin12wchar_with_len, pg_latin1_mblen}, /* 7; PG_LATIN1 */
+ {pg_latin12wchar_with_len, pg_latin1_mblen}, /* 8; PG_LATIN2 */
+ {pg_latin12wchar_with_len, pg_latin1_mblen}, /* 9; PG_LATIN3 */
+ {pg_latin12wchar_with_len, pg_latin1_mblen}, /* 10; PG_LATIN4 */
+ {pg_latin12wchar_with_len, pg_latin1_mblen}, /* 11; PG_LATIN5 */
+ {pg_latin12wchar_with_len, pg_latin1_mblen}, /* 12; PG_KOI8 */
+ {pg_latin12wchar_with_len, pg_latin1_mblen}, /* 13; PG_WIN1251 */
+ {pg_latin12wchar_with_len, pg_latin1_mblen}, /* 14; PG_ALT */
+ {0, pg_sjis_mblen}, /* 15; PG_SJIS */
+ {0, pg_big5_mblen}, /* 17; PG_BIG5 */
+ {pg_latin12wchar_with_len, pg_latin1_mblen} /* 18; PG_WIN1250 */
};
/* returns the byte length of a word for mule internal code */
@@ -502,5 +491,10 @@ pg_mic_mblen(const unsigned char *mbstr)
int
pg_encoding_mblen(int encoding, const unsigned char *mbstr)
{
- return( (encoding >= 0 && encoding < sizeof(pg_wchar_table)/sizeof(pg_wchar_tbl))? ((*pg_wchar_table[encoding].mblen) (mbstr)) : ((*pg_wchar_table[SQL_ASCII].mblen) (mbstr)));
+ Assert(PG_VALID_ENCODING(encoding));
+
+ 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)));
}