Commit Karel's patch.
------------------------------------------------------------------- Subject: Re: [PATCHES] encoding names From: Karel Zak <zakkr@zf.jcu.cz> To: Peter Eisentraut <peter_e@gmx.net> Cc: pgsql-patches <pgsql-patches@postgresql.org> Date: Fri, 31 Aug 2001 17:24:38 +0200 On Thu, Aug 30, 2001 at 01:30:40AM +0200, Peter Eisentraut wrote: > > - convert encoding 'name' to 'id' > > I thought we decided not to add functions returning "new" names until we > know exactly what the new names should be, and pending schema Ok, the patch not to add functions. > better > > ...(): encoding name too long Fixed. I found new bug in command/variable.c in parse_client_encoding(), nobody probably never see this error: if (pg_set_client_encoding(encoding)) { elog(ERROR, "Conversion between %s and %s is not supported", value, GetDatabaseEncodingName()); } because pg_set_client_encoding() returns -1 for error and 0 as true. It's fixed too. IMHO it can be apply. Karel PS: * following files are renamed: src/utils/mb/Unicode/KOI8_to_utf8.map --> src/utils/mb/Unicode/koi8r_to_utf8.map src/utils/mb/Unicode/WIN_to_utf8.map --> src/utils/mb/Unicode/win1251_to_utf8.map src/utils/mb/Unicode/utf8_to_KOI8.map --> src/utils/mb/Unicode/utf8_to_koi8r.map src/utils/mb/Unicode/utf8_to_WIN.map --> src/utils/mb/Unicode/utf8_to_win1251.map * new file: src/utils/mb/encname.c * removed file: src/utils/mb/common.c -- Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/ C, PostgreSQL, PHP, WWW, http://docs.linux.cz, http://mape.jcu.cz
This commit is contained in:
parent
50aa3020ac
commit
227767112c
@ -9,7 +9,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $Header: /cvsroot/pgsql/src/backend/commands/dbcommands.c,v 1.79 2001/08/26 16:55:59 tgl Exp $
|
* $Header: /cvsroot/pgsql/src/backend/commands/dbcommands.c,v 1.80 2001/09/06 04:57:28 ishii Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -36,6 +36,10 @@
|
|||||||
#include "utils/fmgroids.h"
|
#include "utils/fmgroids.h"
|
||||||
#include "utils/syscache.h"
|
#include "utils/syscache.h"
|
||||||
|
|
||||||
|
#ifdef MULTIBYTE
|
||||||
|
#include "mb/pg_wchar.h" /* encoding check */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/* non-export function prototypes */
|
/* non-export function prototypes */
|
||||||
static bool get_db_info(const char *name, Oid *dbIdP, int4 *ownerIdP,
|
static bool get_db_info(const char *name, Oid *dbIdP, int4 *ownerIdP,
|
||||||
@ -142,6 +146,13 @@ createdb(const char *dbname, const char *dbpath,
|
|||||||
if (encoding < 0)
|
if (encoding < 0)
|
||||||
encoding = src_encoding;
|
encoding = src_encoding;
|
||||||
|
|
||||||
|
#ifdef MULTIBYTE
|
||||||
|
/* Some encodings are client only */
|
||||||
|
if (!PG_VALID_BE_ENCODING( encoding ))
|
||||||
|
elog(ERROR, "CREATE DATABASE: invalid backend encoding");
|
||||||
|
#else
|
||||||
|
Assert(encoding == 0); /* zero is PG_SQL_ASCII */
|
||||||
|
#endif
|
||||||
/*
|
/*
|
||||||
* Preassign OID for pg_database tuple, so that we can compute db
|
* Preassign OID for pg_database tuple, so that we can compute db
|
||||||
* path.
|
* path.
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $Header: /cvsroot/pgsql/src/backend/commands/variable.c,v 1.51 2001/06/30 22:03:25 petere Exp $
|
* $Header: /cvsroot/pgsql/src/backend/commands/variable.c,v 1.52 2001/09/06 04:57:28 ishii Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -34,8 +34,8 @@
|
|||||||
#include "mb/pg_wchar.h"
|
#include "mb/pg_wchar.h"
|
||||||
#else
|
#else
|
||||||
/* Grand unified hard-coded badness */
|
/* Grand unified hard-coded badness */
|
||||||
#define pg_encoding_to_char(x) "SQL_ASCII"
|
#define pg_get_client_encoding_name() "SQL_ASCII"
|
||||||
#define pg_get_client_encoding() 0
|
#define GetDatabaseEncodingName() "SQL_ASCII"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
@ -559,15 +559,15 @@ parse_client_encoding(char *value)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (pg_set_client_encoding(encoding))
|
if (pg_set_client_encoding(encoding) < 0)
|
||||||
{
|
{
|
||||||
elog(ERROR, "Conversion between %s and %s is not supported",
|
elog(ERROR, "Conversion between %s and %s is not supported",
|
||||||
value, pg_encoding_to_char(GetDatabaseEncoding()));
|
value, GetDatabaseEncodingName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
if (value &&
|
if (value &&
|
||||||
strcasecmp(value, pg_encoding_to_char(pg_get_client_encoding())) != 0)
|
strcasecmp(value, pg_get_client_encoding_name()) != 0)
|
||||||
elog(ERROR, "Client encoding %s is not supported", value);
|
elog(ERROR, "Client encoding %s is not supported", value);
|
||||||
#endif
|
#endif
|
||||||
return TRUE;
|
return TRUE;
|
||||||
@ -577,7 +577,7 @@ static bool
|
|||||||
show_client_encoding(void)
|
show_client_encoding(void)
|
||||||
{
|
{
|
||||||
elog(NOTICE, "Current client encoding is %s",
|
elog(NOTICE, "Current client encoding is %s",
|
||||||
pg_encoding_to_char(pg_get_client_encoding()));
|
pg_get_client_encoding_name());
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -619,8 +619,7 @@ parse_server_encoding(char *value)
|
|||||||
static bool
|
static bool
|
||||||
show_server_encoding(void)
|
show_server_encoding(void)
|
||||||
{
|
{
|
||||||
elog(NOTICE, "Current server encoding is %s",
|
elog(NOTICE, "Current server encoding is %s", GetDatabaseEncodingName());
|
||||||
pg_encoding_to_char(GetDatabaseEncoding()));
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.249 2001/08/26 16:55:59 tgl Exp $
|
* $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.250 2001/09/06 04:57:28 ishii Exp $
|
||||||
*
|
*
|
||||||
* HISTORY
|
* HISTORY
|
||||||
* AUTHOR DATE MAJOR EVENT
|
* AUTHOR DATE MAJOR EVENT
|
||||||
@ -62,7 +62,7 @@
|
|||||||
#ifdef MULTIBYTE
|
#ifdef MULTIBYTE
|
||||||
#include "mb/pg_wchar.h"
|
#include "mb/pg_wchar.h"
|
||||||
#else
|
#else
|
||||||
#define GetStandardEncoding() 0 /* SQL_ASCII */
|
#define GetStandardEncoding() 0 /* PG_SQL_ASCII */
|
||||||
#define GetStandardEncodingName() "SQL_ASCII"
|
#define GetStandardEncodingName() "SQL_ASCII"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -3027,7 +3027,7 @@ createdb_opt_item: LOCATION '=' Sconst
|
|||||||
| ENCODING '=' Iconst
|
| ENCODING '=' Iconst
|
||||||
{
|
{
|
||||||
#ifdef MULTIBYTE
|
#ifdef MULTIBYTE
|
||||||
if (!pg_get_encent_by_encoding($3))
|
if (!pg_get_enconv_by_encoding($3))
|
||||||
elog(ERROR, "%d is not a valid encoding code", $3);
|
elog(ERROR, "%d is not a valid encoding code", $3);
|
||||||
#else
|
#else
|
||||||
if ($3 != GetStandardEncoding())
|
if ($3 != GetStandardEncoding())
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
/* -----------------------------------------------------------------------
|
/* -----------------------------------------------------------------------
|
||||||
* ascii.c
|
* 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
|
* 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
|
#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";
|
ascii = " cL Y \"Ca -R 'u ., ?AAAAAAACEEEEIIII NOOOOOxOUUUUYTBaaaaaaaceeeeiiii nooooo/ouuuuyty";
|
||||||
range = RANGE_160;
|
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.";
|
ascii = " A L LS \"SSTZ-ZZ a,l'ls ,sstz\"zzRAAAALCCCEEEEIIDDNNOOOOxRUUUUYTBraaaalccceeeeiiddnnoooo/ruuuuyt.";
|
||||||
range = RANGE_160;
|
range = RANGE_160;
|
||||||
}
|
}
|
||||||
else if (enc == WIN1250)
|
else if (enc == PG_WIN1250)
|
||||||
{
|
{
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* 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
|
#ifdef MULTIBYTE
|
||||||
SetDatabaseEncoding(dbform->encoding);
|
SetDatabaseEncoding(dbform->encoding);
|
||||||
#else
|
#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.",
|
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);
|
dbform->encoding);
|
||||||
#endif
|
#endif
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
# Makefile for utils/mb
|
# Makefile for utils/mb
|
||||||
#
|
#
|
||||||
# IDENTIFICATION
|
# 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 = ../../../..
|
top_builddir = ../../../..
|
||||||
include $(top_builddir)/src/Makefile.global
|
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
|
all: SUBSYS.o
|
||||||
|
|
||||||
@ -21,13 +21,13 @@ SUBSYS.o: $(OBJS)
|
|||||||
|
|
||||||
utftest.o: utftest.c conv.c wchar.c mbutils.c
|
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 $@
|
$(CC) $(CFLAGS) $(LDFLAGS) $^ $(LIBS) -o $@
|
||||||
|
|
||||||
liketest: liketest.o palloc.o $(OBJS)
|
liketest: liketest.o palloc.o $(OBJS)
|
||||||
$(CC) $(CFLAGS) $(LDFLAGS) $^ $(LIBS) -o $@
|
$(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 $@
|
$(CC) $(CFLAGS) $(LDFLAGS) $^ $(LIBS) -o $@
|
||||||
|
|
||||||
depend dep:
|
depend dep:
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
#
|
#
|
||||||
# Copyright 2001 by PostgreSQL Global Development Group
|
# 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
|
utf8_to_iso8859_4.map utf8_to_iso8859_5.map
|
||||||
|
|
||||||
|
|
||||||
CYRILLICMAPS=KOI8_to_utf8.map WIN_to_utf8.map ALT_to_utf8.map\
|
CYRILLICMAPS=koi8r_to_utf8.map win1251_to_utf8.map alt_to_utf8.map\
|
||||||
utf8_to_KOI8.map utf8_to_WIN.map utf8_to_ALT.map
|
utf8_to_koi8r.map utf8_to_win1251.map utf8_to_alt.map
|
||||||
|
|
||||||
MAPS= $(ISO8859MAPS) $(CYRILLICMAPS)\
|
MAPS= $(ISO8859MAPS) $(CYRILLICMAPS)\
|
||||||
big5_to_utf8.map euc_cn_to_utf8.map euc_jp_to_utf8.map \
|
big5_to_utf8.map euc_cn_to_utf8.map euc_jp_to_utf8.map \
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
#
|
#
|
||||||
# Copyright 2001 by PostgreSQL Global Development Group
|
# 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
|
# Generate UTF-8 <--> ISO8859 code conversion tables from
|
||||||
# map files provided by Unicode organization.
|
# map files provided by Unicode organization.
|
||||||
@ -15,10 +15,10 @@
|
|||||||
# # and Unicode name (not used in this script)
|
# # and Unicode name (not used in this script)
|
||||||
|
|
||||||
require "ucs2utf.pl";
|
require "ucs2utf.pl";
|
||||||
%filename = ('KOI8'=>'koi8-r.txt',
|
%filename = ('KOI8R'=>'koi8-r.txt',
|
||||||
'WIN'=>'cp1251.txt',
|
'WIN1251'=>'cp1251.txt',
|
||||||
'ALT'=>'cp866.txt');
|
'ALT'=>'cp866.txt');
|
||||||
@charsets = ('KOI8','ALT','WIN');
|
@charsets = ('KOI8R','ALT','WIN1251');
|
||||||
foreach $charset (@charsets) {
|
foreach $charset (@charsets) {
|
||||||
|
|
||||||
#
|
#
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
* WIN1250 client encoding support contributed by Pavel Behal
|
* WIN1250 client encoding support contributed by Pavel Behal
|
||||||
* SJIS UDC (NEC selection IBM kanji) support contributed by Eiji Tokuya
|
* 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/utf8_to_big5.map"
|
||||||
#include "Unicode/big5_to_utf8.map"
|
#include "Unicode/big5_to_utf8.map"
|
||||||
/* Cyrillic charset conversion */
|
/* Cyrillic charset conversion */
|
||||||
#include "Unicode/ALT_to_utf8.map"
|
#include "Unicode/alt_to_utf8.map"
|
||||||
#include "Unicode/KOI8_to_utf8.map"
|
#include "Unicode/koi8r_to_utf8.map"
|
||||||
#include "Unicode/WIN_to_utf8.map"
|
#include "Unicode/win1251_to_utf8.map"
|
||||||
#include "Unicode/utf8_to_ALT.map"
|
#include "Unicode/utf8_to_alt.map"
|
||||||
#include "Unicode/utf8_to_KOI8.map"
|
#include "Unicode/utf8_to_koi8r.map"
|
||||||
#include "Unicode/utf8_to_WIN.map"
|
#include "Unicode/utf8_to_win1251.map"
|
||||||
|
|
||||||
|
|
||||||
#endif /* UNICODE_CONVERSION */
|
#endif /* UNICODE_CONVERSION */
|
||||||
@ -824,16 +824,16 @@ mic2ascii(unsigned char *mic, unsigned char *p, int len)
|
|||||||
* Alternativny Variant (MS-DOS CP866)
|
* Alternativny Variant (MS-DOS CP866)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* koi2mic: KOI8-R to Mule internal code */
|
/* koi8r2mic: KOI8-R to Mule internal code */
|
||||||
static void
|
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);
|
latin2mic(l, p, len, LC_KOI8_R);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* mic2koi: Mule internal code to KOI8-R */
|
/* mic2koi8r: Mule internal code to KOI8-R */
|
||||||
static void
|
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);
|
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 */
|
/* win2mic: CP1251 to Mule internal code */
|
||||||
static void
|
static void
|
||||||
win2mic(unsigned char *l, unsigned char *p, int len)
|
win12512mic(unsigned char *l, unsigned char *p, int len)
|
||||||
{
|
{
|
||||||
static unsigned char win2koi[] = {
|
static unsigned char win2koi[] = {
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
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 */
|
/* mic2win: Mule internal code to CP1251 */
|
||||||
static void
|
static void
|
||||||
mic2win(unsigned char *mic, unsigned char *p, int len)
|
mic2win1251(unsigned char *mic, unsigned char *p, int len)
|
||||||
{
|
{
|
||||||
static unsigned char koi2win[] = {
|
static unsigned char koi2win[] = {
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
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
|
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
|
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;
|
unsigned int iiso;
|
||||||
int l;
|
int l;
|
||||||
pg_local_to_utf *p;
|
pg_local_to_utf *p;
|
||||||
pg_encoding_conv_tbl *e;
|
|
||||||
|
|
||||||
e = pg_get_enc_ent(encoding);
|
if (!PG_VALID_ENCODING(encoding))
|
||||||
if (e == 0)
|
|
||||||
elog(ERROR, "Invalid encoding number %d", encoding);
|
elog(ERROR, "Invalid encoding number %d", encoding);
|
||||||
|
|
||||||
for (; len > 0 && *iso; len -= l)
|
for (; len > 0 && *iso; len -= l)
|
||||||
@ -1424,7 +1422,7 @@ local_to_utf(unsigned char *iso, unsigned char *utf,
|
|||||||
if (p == NULL)
|
if (p == NULL)
|
||||||
{
|
{
|
||||||
elog(NOTICE, "local_to_utf: could not convert (0x%04x) %s to UTF-8. Ignored",
|
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;
|
continue;
|
||||||
}
|
}
|
||||||
if (p->utf & 0xff000000)
|
if (p->utf & 0xff000000)
|
||||||
@ -1445,7 +1443,7 @@ local_to_utf(unsigned char *iso, unsigned char *utf,
|
|||||||
static void
|
static void
|
||||||
latin2_to_utf(unsigned char *iso, unsigned char *utf, int len)
|
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
|
static void
|
||||||
latin3_to_utf(unsigned char *iso, unsigned char *utf, int len)
|
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
|
static void
|
||||||
latin4_to_utf(unsigned char *iso, unsigned char *utf, int len)
|
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
|
static void
|
||||||
latin5_to_utf(unsigned char *iso, unsigned char *utf, int len)
|
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
|
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
|
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
|
static void
|
||||||
ALT_to_utf(unsigned char *iso, unsigned char *utf, int len)
|
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
|
* UTF-8 ---> EUC_JP
|
||||||
@ -1519,7 +1517,7 @@ static void
|
|||||||
euc_jp_to_utf(unsigned char *euc, unsigned char *utf, int len)
|
euc_jp_to_utf(unsigned char *euc, unsigned char *utf, int len)
|
||||||
{
|
{
|
||||||
local_to_utf(euc, utf, LUmapEUC_JP,
|
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)
|
euc_cn_to_utf(unsigned char *euc, unsigned char *utf, int len)
|
||||||
{
|
{
|
||||||
local_to_utf(euc, utf, LUmapEUC_CN,
|
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)
|
euc_kr_to_utf(unsigned char *euc, unsigned char *utf, int len)
|
||||||
{
|
{
|
||||||
local_to_utf(euc, utf, LUmapEUC_KR,
|
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)
|
euc_tw_to_utf(unsigned char *euc, unsigned char *utf, int len)
|
||||||
{
|
{
|
||||||
local_to_utf(euc, utf, LUmapEUC_TW,
|
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)
|
sjis_to_utf(unsigned char *euc, unsigned char *utf, int len)
|
||||||
{
|
{
|
||||||
local_to_utf(euc, utf, LUmapSJIS,
|
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)
|
big5_to_utf(unsigned char *euc, unsigned char *utf, int len)
|
||||||
{
|
{
|
||||||
local_to_utf(euc, utf, LUmapBIG5,
|
local_to_utf(euc, utf, LUmapBIG5,
|
||||||
sizeof(LUmapBIG5) / sizeof(pg_local_to_utf), BIG5, len);
|
sizeof(LUmapBIG5) / sizeof(pg_local_to_utf), PG_BIG5, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*-----------------------------------------------------------------*/
|
/* ----------
|
||||||
|
* Encoding conversion routines
|
||||||
pg_encoding_conv_tbl pg_conv_tbl[] = {
|
*
|
||||||
{SQL_ASCII, "SQL_ASCII", 0, ascii2mic, mic2ascii,
|
* WARINIG: must by same order as pg_enc in include/mb/pg_wchar.h!
|
||||||
ascii2utf, utf2ascii}, /* SQL/ASCII */
|
* ----------
|
||||||
{EUC_JP, "EUC_JP", 0, euc_jp2mic, mic2euc_jp,
|
*/
|
||||||
euc_jp_to_utf, utf_to_euc_jp}, /* EUC_JP */
|
pg_enconv pg_enconv_tbl[] =
|
||||||
{EUC_CN, "EUC_CN", 0, euc_cn2mic, mic2euc_cn,
|
{
|
||||||
euc_cn_to_utf, utf_to_euc_cn}, /* EUC_CN */
|
{ PG_SQL_ASCII, ascii2mic, mic2ascii, ascii2utf, utf2ascii },
|
||||||
{EUC_KR, "EUC_KR", 0, euc_kr2mic, mic2euc_kr,
|
{ PG_EUC_JP, euc_jp2mic, mic2euc_jp, euc_jp_to_utf, utf_to_euc_jp },
|
||||||
euc_kr_to_utf, utf_to_euc_kr}, /* EUC_KR */
|
{ PG_EUC_CN, euc_cn2mic, mic2euc_cn, euc_cn_to_utf, utf_to_euc_cn },
|
||||||
{EUC_TW, "EUC_TW", 0, euc_tw2mic, mic2euc_tw,
|
{ PG_EUC_KR, euc_kr2mic, mic2euc_kr, euc_kr_to_utf, utf_to_euc_kr },
|
||||||
euc_tw_to_utf, utf_to_euc_tw}, /* EUC_TW */
|
{ PG_EUC_TW, euc_tw2mic, mic2euc_tw, euc_tw_to_utf, utf_to_euc_tw },
|
||||||
{UNICODE, "UNICODE", 0, 0, 0}, /* UNICODE */
|
{ PG_UTF8, 0, 0, 0, 0 },
|
||||||
{MULE_INTERNAL, "MULE_INTERNAL", 0, 0, 0}, /* MULE_INTERNAL */
|
{ PG_MULE_INTERNAL, 0, 0, 0, 0 },
|
||||||
{LATIN1, "LATIN1", 0, latin12mic, mic2latin1,
|
{ PG_LATIN1, latin12mic, mic2latin1, latin1_to_utf, utf_to_latin1 },
|
||||||
latin1_to_utf, utf_to_latin1}, /* ISO 8859 Latin 1 */
|
{ PG_LATIN2, latin22mic, mic2latin2, latin2_to_utf, utf_to_latin2 },
|
||||||
{LATIN2, "LATIN2", 0, latin22mic, mic2latin2,
|
{ PG_LATIN3, latin32mic, mic2latin3, latin3_to_utf, utf_to_latin3 },
|
||||||
latin2_to_utf, utf_to_latin2}, /* ISO 8859 Latin 2 */
|
{ PG_LATIN4, latin42mic, mic2latin4, latin4_to_utf, utf_to_latin4 },
|
||||||
{LATIN3, "LATIN3", 0, latin32mic, mic2latin3,
|
{ PG_LATIN5, iso2mic, mic2iso, latin5_to_utf, utf_to_latin5 },
|
||||||
latin3_to_utf, utf_to_latin3}, /* ISO 8859 Latin 3 */
|
{ PG_KOI8R, koi8r2mic, mic2koi8r, KOI8R_to_utf, utf_to_KOI8R },
|
||||||
{LATIN4, "LATIN4", 0, latin42mic, mic2latin4,
|
{ PG_WIN1251, win12512mic, mic2win1251, WIN1251_to_utf, utf_to_WIN1251 },
|
||||||
latin4_to_utf, utf_to_latin4}, /* ISO 8859 Latin 4 */
|
{ PG_ALT, alt2mic, mic2alt, ALT_to_utf, utf_to_ALT },
|
||||||
{LATIN5, "LATIN5", 0, iso2mic, mic2iso,
|
{ PG_SJIS, sjis2mic, mic2sjis, sjis_to_utf, utf_to_sjis },
|
||||||
latin5_to_utf, utf_to_latin5}, /* ISO 8859 Latin 5 */
|
{ PG_BIG5, big52mic, mic2big5, big5_to_utf, utf_to_big5},
|
||||||
{KOI8, "KOI8", 0, koi2mic, mic2koi,
|
{ PG_WIN1250, win12502mic, mic2win1250, 0, 0 },
|
||||||
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 */
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
pg_encoding_conv_tbl pg_conv_tbl[] = {
|
pg_enconv pg_enconv_tbl[] =
|
||||||
{SQL_ASCII, "SQL_ASCII", 0, ascii2mic, mic2ascii,
|
{
|
||||||
0, 0}, /* SQL/ASCII */
|
{ PG_SQL_ASCII, ascii2mic, mic2ascii, 0, 0 },
|
||||||
{EUC_JP, "EUC_JP", 0, euc_jp2mic, mic2euc_jp,
|
{ PG_EUC_JP, euc_jp2mic, mic2euc_jp, 0, 0 },
|
||||||
0, 0}, /* EUC_JP */
|
{ PG_EUC_CN, euc_cn2mic, mic2euc_cn, 0, 0 },
|
||||||
{EUC_CN, "EUC_CN", 0, euc_cn2mic, mic2euc_cn,
|
{ PG_EUC_KR, euc_kr2mic, mic2euc_kr, 0, 0 },
|
||||||
0, 0}, /* EUC_CN */
|
{ PG_EUC_TW, euc_tw2mic, mic2euc_tw, 0, 0 },
|
||||||
{EUC_KR, "EUC_KR", 0, euc_kr2mic, mic2euc_kr}, /* EUC_KR */
|
{ PG_UTF8, 0, 0, 0, 0 },
|
||||||
{EUC_TW, "EUC_TW", 0, euc_tw2mic, mic2euc_tw}, /* EUC_TW */
|
{ PG_MULE_INTERNAL, 0, 0, 0, 0 },
|
||||||
{UNICODE, "UNICODE", 0, 0, 0}, /* UNICODE */
|
{ PG_LATIN1, latin12mic, mic2latin1, 0, 0 },
|
||||||
{MULE_INTERNAL, "MULE_INTERNAL", 0, 0, 0}, /* MULE_INTERNAL */
|
{ PG_LATIN2, latin22mic, mic2latin2, 0, 0 },
|
||||||
{LATIN1, "LATIN1", 0, latin12mic, mic2latin1,
|
{ PG_LATIN3, latin32mic, mic2latin3, 0, 0 },
|
||||||
0, 0}, /* ISO 8859 Latin 1 */
|
{ PG_LATIN4, latin42mic, mic2latin4, 0, 0 },
|
||||||
{LATIN2, "LATIN2", 0, latin22mic, mic2latin2,
|
{ PG_LATIN5, iso2mic, mic2iso, 0, 0 },
|
||||||
0, 0}, /* ISO 8859 Latin 2 */
|
{ PG_KOI8R, koi8r2mic, mic2koi8r, 0, 0 },
|
||||||
{LATIN3, "LATIN3", 0, latin32mic, mic2latin3,
|
{ PG_WIN1251, win12512mic, mic2win1251, 0, 0 },
|
||||||
0, 0}, /* ISO 8859 Latin 3 */
|
{ PG_ALT, alt2mic, mic2alt, 0, 0 },
|
||||||
{LATIN4, "LATIN4", 0, latin42mic, mic2latin4,
|
{ PG_SJIS, sjis2mic, mic2sjis, 0, 0 },
|
||||||
0, 0}, /* ISO 8859 Latin 4 */
|
{ PG_BIG5, big52mic, mic2big5, 0, 0 },
|
||||||
{LATIN5, "LATIN5", 0, iso2mic, mic2iso,
|
{ PG_WIN1250, win12502mic, mic2win1250, 0, 0 },
|
||||||
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 */
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* UNICODE_CONVERSION */
|
#endif /* UNICODE_CONVERSION */
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
* client encoding and server internal encoding.
|
* client encoding and server internal encoding.
|
||||||
* (currently mule internal code (mic) is used)
|
* (currently mule internal code (mic) is used)
|
||||||
* Tatsuo Ishii
|
* 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"
|
#include "postgres.h"
|
||||||
|
|
||||||
@ -11,26 +11,36 @@
|
|||||||
#include "mb/pg_wchar.h"
|
#include "mb/pg_wchar.h"
|
||||||
#include "utils/builtins.h"
|
#include "utils/builtins.h"
|
||||||
|
|
||||||
static int client_encoding = -1;
|
/*
|
||||||
static void (*client_to_mic) ();/* something to MIC */
|
* 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 (*client_from_mic) (); /* MIC to something */
|
||||||
static void (*server_to_mic) ();/* something to MIC */
|
static void (*server_to_mic) (); /* something to MIC */
|
||||||
static void (*server_from_mic) (); /* MIC to something */
|
static void (*server_from_mic) (); /* MIC to something */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* find encoding table entry by encoding
|
* find encoding table entry by encoding
|
||||||
*/
|
*/
|
||||||
pg_encoding_conv_tbl *
|
pg_enconv *
|
||||||
pg_get_enc_ent(int encoding)
|
pg_get_enconv_by_encoding(int encoding)
|
||||||
{
|
{
|
||||||
pg_encoding_conv_tbl *p = pg_conv_tbl;
|
if (PG_VALID_ENCODING(encoding))
|
||||||
|
|
||||||
for (; p->encoding >= 0; p++)
|
|
||||||
{
|
{
|
||||||
if (p->encoding == encoding)
|
Assert((&pg_enconv_tbl[ encoding ])->encoding == encoding);
|
||||||
return (p);
|
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 == dest? */
|
||||||
*src_to_mic = *dest_from_mic = 0;
|
*src_to_mic = *dest_from_mic = 0;
|
||||||
}
|
}
|
||||||
else if (src == MULE_INTERNAL)
|
else if (src == PG_MULE_INTERNAL)
|
||||||
{ /* src == MULE_INETRNAL? */
|
{ /* 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)
|
if (*dest_from_mic == 0)
|
||||||
return (-1);
|
return (-1);
|
||||||
*src_to_mic = 0;
|
*src_to_mic = 0;
|
||||||
}
|
}
|
||||||
else if (dest == MULE_INTERNAL)
|
else if (dest == PG_MULE_INTERNAL)
|
||||||
{ /* dest == MULE_INETRNAL? */
|
{ /* 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)
|
if (*src_to_mic == 0)
|
||||||
return (-1);
|
return (-1);
|
||||||
*dest_from_mic = 0;
|
*dest_from_mic = 0;
|
||||||
}
|
}
|
||||||
else if (src == UNICODE)
|
else if (src == PG_UTF8)
|
||||||
{ /* src == UNICODE? */
|
{ /* 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)
|
if (*dest_from_mic == 0)
|
||||||
return (-1);
|
return (-1);
|
||||||
*src_to_mic = 0;
|
*src_to_mic = 0;
|
||||||
}
|
}
|
||||||
else if (dest == UNICODE)
|
else if (dest == PG_UTF8)
|
||||||
{ /* dest == UNICODE? */
|
{ /* 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)
|
if (*src_to_mic == 0)
|
||||||
return (-1);
|
return (-1);
|
||||||
*dest_from_mic = 0;
|
*dest_from_mic = 0;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
*src_to_mic = pg_get_enc_ent(src)->to_mic;
|
*src_to_mic = pg_get_enconv_by_encoding(src)->to_mic;
|
||||||
*dest_from_mic = pg_get_enc_ent(dest)->from_mic;
|
*dest_from_mic = pg_get_enconv_by_encoding(dest)->from_mic;
|
||||||
if (*src_to_mic == 0 || *dest_from_mic == 0)
|
if (*src_to_mic == 0 || *dest_from_mic == 0)
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
@ -101,11 +111,17 @@ pg_find_encoding_converters(int src, int dest, void (**src_to_mic)(), void (**de
|
|||||||
int
|
int
|
||||||
pg_set_client_encoding(int encoding)
|
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)
|
if (pg_find_encoding_converters(encoding, current_server_encoding, &client_to_mic, &server_from_mic) < 0)
|
||||||
return (-1);
|
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)
|
if (pg_find_encoding_converters(current_server_encoding, encoding, &server_to_mic, &client_from_mic) < 0)
|
||||||
return (-1);
|
return (-1);
|
||||||
@ -118,12 +134,30 @@ pg_set_client_encoding(int encoding)
|
|||||||
int
|
int
|
||||||
pg_get_client_encoding()
|
pg_get_client_encoding()
|
||||||
{
|
{
|
||||||
if (client_encoding == -1)
|
Assert(DatabaseEncoding);
|
||||||
|
|
||||||
|
if (ClientEncoding == NULL)
|
||||||
{
|
{
|
||||||
/* this is the first time */
|
/* 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);
|
text *string = PG_GETARG_TEXT_P(0);
|
||||||
Name s = PG_GETARG_NAME(1);
|
Name s = PG_GETARG_NAME(1);
|
||||||
int encoding = pg_char_to_encoding(NameStr(*s));
|
int encoding = pg_char_to_encoding(NameStr(*s));
|
||||||
int db_encoding = GetDatabaseEncoding();
|
int db_encoding = DatabaseEncoding->encoding;
|
||||||
void (*src)(), (*dest)();
|
void (*src)(), (*dest)();
|
||||||
unsigned char *result;
|
unsigned char *result;
|
||||||
text *retval;
|
text *retval;
|
||||||
@ -277,7 +311,10 @@ pg_convert2(PG_FUNCTION_ARGS)
|
|||||||
unsigned char *
|
unsigned char *
|
||||||
pg_client_to_server(unsigned char *s, int len)
|
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 s;
|
||||||
|
|
||||||
return pg_do_encoding_conversion(s, len, client_to_mic, server_from_mic);
|
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 *
|
unsigned char *
|
||||||
pg_server_to_client(unsigned char *s, int len)
|
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 s;
|
||||||
|
|
||||||
return pg_do_encoding_conversion(s, len, server_to_mic, client_from_mic);
|
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
|
int
|
||||||
pg_mb2wchar(const unsigned char *from, pg_wchar * to)
|
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 */
|
/* convert a multi-byte string to a wchar with a limited length */
|
||||||
int
|
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[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 */
|
/* returns the byte length of a multi-byte word */
|
||||||
int
|
int
|
||||||
pg_mblen(const unsigned char *mbstr)
|
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 */
|
/* 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);
|
return (clen);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* functions for utils/init */
|
|
||||||
static int DatabaseEncoding = MULTIBYTE;
|
|
||||||
|
|
||||||
void
|
void
|
||||||
SetDatabaseEncoding(int encoding)
|
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
|
int
|
||||||
GetDatabaseEncoding()
|
GetDatabaseEncoding()
|
||||||
{
|
{
|
||||||
return (DatabaseEncoding);
|
Assert(DatabaseEncoding);
|
||||||
|
return (DatabaseEncoding->encoding);
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *
|
||||||
|
GetDatabaseEncodingName()
|
||||||
|
{
|
||||||
|
Assert(DatabaseEncoding);
|
||||||
|
return (DatabaseEncoding->name);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* for builtin-function */
|
|
||||||
Datum
|
Datum
|
||||||
getdatabaseencoding(PG_FUNCTION_ARGS)
|
getdatabaseencoding(PG_FUNCTION_ARGS)
|
||||||
{
|
{
|
||||||
const char *encoding_name = pg_encoding_to_char(DatabaseEncoding);
|
Assert(DatabaseEncoding);
|
||||||
|
return DirectFunctionCall1(namein, CStringGetDatum(DatabaseEncoding->name));
|
||||||
return DirectFunctionCall1(namein, CStringGetDatum(encoding_name));
|
|
||||||
}
|
}
|
||||||
|
@ -1,16 +1,22 @@
|
|||||||
/*
|
/*
|
||||||
* conversion functions between pg_wchar and multi-byte streams.
|
* conversion functions between pg_wchar and multi-byte streams.
|
||||||
* Tatsuo Ishii
|
* 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
|
* WIN1250 client encoding updated by Pavel Behal
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
/* can be used in either frontend or backend */
|
/* can be used in either frontend or backend */
|
||||||
#include "postgres_fe.h"
|
#include "postgres_fe.h"
|
||||||
|
|
||||||
#include "mb/pg_wchar.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."
|
* conversion to pg_wchar is done by "table driven."
|
||||||
* to add an encoding support, define mb2wchar_with_len(), mblen()
|
* 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_wchar_tbl pg_wchar_table[] = {
|
||||||
{pg_ascii2wchar_with_len, pg_ascii_mblen}, /* 0 */
|
{pg_ascii2wchar_with_len, pg_ascii_mblen}, /* 0; PG_SQL_ASCII */
|
||||||
{pg_eucjp2wchar_with_len, pg_eucjp_mblen}, /* 1 */
|
{pg_eucjp2wchar_with_len, pg_eucjp_mblen}, /* 1; PG_EUC_JP */
|
||||||
{pg_euccn2wchar_with_len, pg_euccn_mblen}, /* 2 */
|
{pg_euccn2wchar_with_len, pg_euccn_mblen}, /* 2; PG_EUC_CN */
|
||||||
{pg_euckr2wchar_with_len, pg_euckr_mblen}, /* 3 */
|
{pg_euckr2wchar_with_len, pg_euckr_mblen}, /* 3; PG_EUC_KR */
|
||||||
{pg_euctw2wchar_with_len, pg_euctw_mblen}, /* 4 */
|
{pg_euctw2wchar_with_len, pg_euctw_mblen}, /* 4; PG_EUC_TW */
|
||||||
{pg_utf2wchar_with_len, pg_utf_mblen}, /* 5 */
|
{pg_utf2wchar_with_len, pg_utf_mblen}, /* 5; PG_UNICODE */
|
||||||
{pg_mule2wchar_with_len, pg_mule_mblen}, /* 6 */
|
{pg_mule2wchar_with_len, pg_mule_mblen}, /* 6; PG_MULE_INTERNAL */
|
||||||
{pg_latin12wchar_with_len, pg_latin1_mblen}, /* 7 */
|
{pg_latin12wchar_with_len, pg_latin1_mblen}, /* 7; PG_LATIN1 */
|
||||||
{pg_latin12wchar_with_len, pg_latin1_mblen}, /* 8 */
|
{pg_latin12wchar_with_len, pg_latin1_mblen}, /* 8; PG_LATIN2 */
|
||||||
{pg_latin12wchar_with_len, pg_latin1_mblen}, /* 9 */
|
{pg_latin12wchar_with_len, pg_latin1_mblen}, /* 9; PG_LATIN3 */
|
||||||
{pg_latin12wchar_with_len, pg_latin1_mblen}, /* 10 */
|
{pg_latin12wchar_with_len, pg_latin1_mblen}, /* 10; PG_LATIN4 */
|
||||||
{pg_latin12wchar_with_len, pg_latin1_mblen}, /* 11 */
|
{pg_latin12wchar_with_len, pg_latin1_mblen}, /* 11; PG_LATIN5 */
|
||||||
{pg_latin12wchar_with_len, pg_latin1_mblen}, /* 12 */
|
{pg_latin12wchar_with_len, pg_latin1_mblen}, /* 12; PG_KOI8 */
|
||||||
{pg_latin12wchar_with_len, pg_latin1_mblen}, /* 13 */
|
{pg_latin12wchar_with_len, pg_latin1_mblen}, /* 13; PG_WIN1251 */
|
||||||
{pg_latin12wchar_with_len, pg_latin1_mblen}, /* 14 */
|
{pg_latin12wchar_with_len, pg_latin1_mblen}, /* 14; PG_ALT */
|
||||||
{pg_latin12wchar_with_len, pg_latin1_mblen}, /* 15 */
|
{0, pg_sjis_mblen}, /* 15; PG_SJIS */
|
||||||
{pg_latin12wchar_with_len, pg_latin1_mblen}, /* 16 */
|
{0, pg_big5_mblen}, /* 17; PG_BIG5 */
|
||||||
{pg_latin12wchar_with_len, pg_latin1_mblen}, /* 17 */
|
{pg_latin12wchar_with_len, pg_latin1_mblen} /* 18; PG_WIN1250 */
|
||||||
{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 */
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/* returns the byte length of a word for mule internal code */
|
/* returns the byte length of a word for mule internal code */
|
||||||
@ -502,5 +491,10 @@ pg_mic_mblen(const unsigned char *mbstr)
|
|||||||
int
|
int
|
||||||
pg_encoding_mblen(int encoding, const unsigned char *mbstr)
|
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)));
|
||||||
}
|
}
|
||||||
|
@ -27,7 +27,7 @@
|
|||||||
# Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
|
# Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
|
||||||
# Portions Copyright (c) 1994, Regents of the University of California
|
# Portions Copyright (c) 1994, Regents of the University of California
|
||||||
#
|
#
|
||||||
# $Header: /cvsroot/pgsql/src/bin/initdb/Attic/initdb.sh,v 1.135 2001/08/26 16:56:00 tgl Exp $
|
# $Header: /cvsroot/pgsql/src/bin/initdb/Attic/initdb.sh,v 1.136 2001/09/06 04:57:29 ishii Exp $
|
||||||
#
|
#
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
|
|
||||||
@ -292,7 +292,7 @@ fi
|
|||||||
|
|
||||||
if [ "$MULTIBYTE" ]
|
if [ "$MULTIBYTE" ]
|
||||||
then
|
then
|
||||||
MULTIBYTEID=`$PGPATH/pg_encoding $MULTIBYTE`
|
MULTIBYTEID=`$PGPATH/pg_encoding -b $MULTIBYTE`
|
||||||
if [ "$?" -ne 0 ]
|
if [ "$?" -ne 0 ]
|
||||||
then
|
then
|
||||||
(
|
(
|
||||||
@ -305,11 +305,7 @@ then
|
|||||||
fi
|
fi
|
||||||
if [ -z "$MULTIBYTEID" ]
|
if [ -z "$MULTIBYTEID" ]
|
||||||
then
|
then
|
||||||
echo "$CMDNAME: $MULTIBYTE is not a valid encoding name" 1>&2
|
echo "$CMDNAME: $MULTIBYTE is not a valid backend encoding name" 1>&2
|
||||||
exit 1
|
|
||||||
elif [ $MULTIBYTEID -gt 31 ]
|
|
||||||
then
|
|
||||||
echo "$CMDNAME: $MULTIBYTE cannot be used as a database encoding" 1>&2
|
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $Header: /cvsroot/pgsql/src/bin/pg_encoding/Attic/pg_encoding.c,v 1.8 2000/02/19 04:59:30 ishii Exp $
|
* $Header: /cvsroot/pgsql/src/bin/pg_encoding/Attic/pg_encoding.c,v 1.9 2001/09/06 04:57:29 ishii Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -15,37 +15,75 @@
|
|||||||
#include "miscadmin.h"
|
#include "miscadmin.h"
|
||||||
#include "mb/pg_wchar.h"
|
#include "mb/pg_wchar.h"
|
||||||
|
|
||||||
|
#include <ctype.h>
|
||||||
|
|
||||||
static void usage(void);
|
static void usage(void);
|
||||||
|
|
||||||
int
|
int
|
||||||
main(int argc, char **argv)
|
main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
char c;
|
|
||||||
char *p;
|
char *p;
|
||||||
int rtn;
|
int enc;
|
||||||
|
bool be_only = FALSE;
|
||||||
|
|
||||||
if (argc < 2)
|
if (argc < 2)
|
||||||
{
|
{
|
||||||
usage();
|
usage();
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (strcmp(argv[1], "-b")==0)
|
||||||
|
{
|
||||||
|
if (argc < 3)
|
||||||
|
{
|
||||||
|
usage();
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
be_only = TRUE;
|
||||||
|
p = argv[2];
|
||||||
|
}
|
||||||
|
else
|
||||||
p = argv[1];
|
p = argv[1];
|
||||||
while ((c = *p++))
|
|
||||||
|
if (p && *p && isdigit((unsigned char) *p))
|
||||||
{
|
{
|
||||||
if (c < '0' || c > '9')
|
/*
|
||||||
|
* Encoding number to name
|
||||||
|
*/
|
||||||
|
char *name;
|
||||||
|
|
||||||
|
enc = atoi(p);
|
||||||
|
|
||||||
|
if ((name = (char *) pg_encoding_to_char(enc)))
|
||||||
{
|
{
|
||||||
rtn = pg_char_to_encoding(argv[1]);
|
if (be_only && pg_valid_server_encoding(name) < 0)
|
||||||
if (rtn >= 0)
|
exit(0);
|
||||||
printf("%d\n", rtn);
|
printf("%s\n", name);
|
||||||
|
}
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
}
|
else if (p && *p)
|
||||||
printf("%s\n", pg_encoding_to_char(atoi(argv[1])));
|
{
|
||||||
|
/*
|
||||||
|
* Encoding name to encoding number
|
||||||
|
*/
|
||||||
|
if ((enc = pg_char_to_encoding(p)) >= 0)
|
||||||
|
{
|
||||||
|
if (be_only && pg_valid_server_encoding(p) < 0)
|
||||||
exit(0);
|
exit(0);
|
||||||
|
printf("%d\n", enc);
|
||||||
|
}
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
usage()
|
usage()
|
||||||
{
|
{
|
||||||
fprintf(stderr, "\nUsage: pg_encoding encoding_name | encoding_number\n\n");
|
fprintf(stderr,
|
||||||
|
"\nUsage: pg_encoding [options] encoding_name | encoding_number\n\n"
|
||||||
|
"options:"
|
||||||
|
" -b check if encoding is valid for backend\n\n"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
#
|
#
|
||||||
#
|
#
|
||||||
# IDENTIFICATION
|
# IDENTIFICATION
|
||||||
# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/createdb,v 1.15 2001/03/27 05:47:13 ishii Exp $
|
# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/createdb,v 1.16 2001/09/06 04:57:29 ishii Exp $
|
||||||
#
|
#
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
|
|
||||||
@ -145,10 +145,6 @@ then
|
|||||||
then
|
then
|
||||||
echo "$CMDNAME: \"$MB\" is not a valid encoding name" 1>&2
|
echo "$CMDNAME: \"$MB\" is not a valid encoding name" 1>&2
|
||||||
exit 1
|
exit 1
|
||||||
elif [ $mbcode -gt 31 ]
|
|
||||||
then
|
|
||||||
echo "$CMDNAME: $MB cannot be used as a database encoding" 1>&2
|
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
|
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
|
||||||
* Portions Copyright (c) 1994, Regents of the University of California
|
* Portions Copyright (c) 1994, Regents of the University of California
|
||||||
*
|
*
|
||||||
* $Id: pg_proc.h,v 1.208 2001/09/06 03:22:42 momjian Exp $
|
* $Id: pg_proc.h,v 1.209 2001/09/06 04:57:29 ishii Exp $
|
||||||
*
|
*
|
||||||
* NOTES
|
* NOTES
|
||||||
* The script catalog/genbki.sh reads this file and generates .bki
|
* The script catalog/genbki.sh reads this file and generates .bki
|
||||||
@ -2136,6 +2136,8 @@ DATA(insert OID = 937 ( substring PGUID 14 f t t t 2 f 25 "25 23" 100 0 0 1
|
|||||||
DESCR("return portion of string");
|
DESCR("return portion of string");
|
||||||
|
|
||||||
/* for multi-byte support */
|
/* for multi-byte support */
|
||||||
|
|
||||||
|
/* old encoding names - back compatibility only */
|
||||||
DATA(insert OID = 1039 ( getdatabaseencoding PGUID 12 f t f t 0 f 19 "0" 100 0 0 100 getdatabaseencoding - ));
|
DATA(insert OID = 1039 ( getdatabaseencoding PGUID 12 f t f t 0 f 19 "0" 100 0 0 100 getdatabaseencoding - ));
|
||||||
DESCR("encoding name of current database");
|
DESCR("encoding name of current database");
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/* $Id: pg_wchar.h,v 1.28 2001/08/15 07:07:40 ishii Exp $ */
|
/* $Id: pg_wchar.h,v 1.29 2001/09/06 04:57:29 ishii Exp $ */
|
||||||
|
|
||||||
#ifndef PG_WCHAR_H
|
#ifndef PG_WCHAR_H
|
||||||
#define PG_WCHAR_H
|
#define PG_WCHAR_H
|
||||||
@ -12,30 +12,9 @@
|
|||||||
#define pfree free
|
#define pfree free
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define SQL_ASCII 0 /* SQL/ASCII */
|
/*
|
||||||
#define EUC_JP 1 /* EUC for Japanese */
|
* The pg_wchar
|
||||||
#define EUC_CN 2 /* EUC for Chinese */
|
*/
|
||||||
#define EUC_KR 3 /* EUC for Korean */
|
|
||||||
#define EUC_TW 4 /* EUC for Taiwan */
|
|
||||||
#define UNICODE 5 /* Unicode UTF-8 */
|
|
||||||
#define MULE_INTERNAL 6 /* Mule internal code */
|
|
||||||
#define LATIN1 7 /* ISO-8859 Latin 1 */
|
|
||||||
#define LATIN2 8 /* ISO-8859 Latin 2 */
|
|
||||||
#define LATIN3 9 /* ISO-8859 Latin 3 */
|
|
||||||
#define LATIN4 10 /* ISO-8859 Latin 4 */
|
|
||||||
#define LATIN5 11 /* ISO-8859 Latin 5 */
|
|
||||||
#define LATIN6 12 /* ISO-8859 Latin 6 */
|
|
||||||
#define LATIN7 13 /* ISO-8859 Latin 7 */
|
|
||||||
#define LATIN8 14 /* ISO-8859 Latin 8 */
|
|
||||||
#define LATIN9 15 /* ISO-8859 Latin 9 */
|
|
||||||
#define KOI8 16 /* KOI8-R/U */
|
|
||||||
#define WIN 17 /* windows-1251 */
|
|
||||||
#define ALT 18 /* Alternativny Variant (MS-DOS CP866) */
|
|
||||||
/* followings are for client encoding only */
|
|
||||||
#define SJIS 32 /* Shift JIS */
|
|
||||||
#define BIG5 33 /* Big5 */
|
|
||||||
#define WIN1250 34 /* windows-1250 */
|
|
||||||
|
|
||||||
#ifdef MULTIBYTE
|
#ifdef MULTIBYTE
|
||||||
typedef unsigned int pg_wchar;
|
typedef unsigned int pg_wchar;
|
||||||
|
|
||||||
@ -81,21 +60,123 @@ typedef unsigned int pg_wchar;
|
|||||||
#define LC_CNS11643_6 0xf9 /* CNS 11643-1992 Plane 6 */
|
#define LC_CNS11643_6 0xf9 /* CNS 11643-1992 Plane 6 */
|
||||||
#define LC_CNS11643_7 0xfa /* CNS 11643-1992 Plane 7 */
|
#define LC_CNS11643_7 0xfa /* CNS 11643-1992 Plane 7 */
|
||||||
|
|
||||||
#ifdef MULTIBYTE
|
/*
|
||||||
typedef struct
|
* Encoding numeral identificators
|
||||||
|
*
|
||||||
|
* WARNING: the order of this table must be same as order
|
||||||
|
* in the pg_enconv[] (mb/conv.c) and pg_enc2name[] (mb/names.c) array!
|
||||||
|
*
|
||||||
|
* If you add some encoding don'y forget check
|
||||||
|
* PG_ENCODING_[BE|FE]_LAST macros.
|
||||||
|
*
|
||||||
|
* The PG_SQL_ASCII is default encoding and must be = 0.
|
||||||
|
*/
|
||||||
|
typedef enum pg_enc
|
||||||
{
|
{
|
||||||
int encoding; /* encoding symbol value */
|
PG_SQL_ASCII = 0, /* SQL/ASCII */
|
||||||
char *name; /* encoding name */
|
PG_EUC_JP, /* EUC for Japanese */
|
||||||
int is_client_only; /* 0: server/client both supported 1:
|
PG_EUC_CN, /* EUC for Chinese */
|
||||||
* client only */
|
PG_EUC_KR, /* EUC for Korean */
|
||||||
|
PG_EUC_TW, /* EUC for Taiwan */
|
||||||
|
PG_UTF8, /* Unicode UTF-8 */
|
||||||
|
PG_MULE_INTERNAL, /* Mule internal code */
|
||||||
|
PG_LATIN1, /* ISO-8859 Latin 1 */
|
||||||
|
PG_LATIN2, /* ISO-8859 Latin 2 */
|
||||||
|
PG_LATIN3, /* ISO-8859 Latin 3 */
|
||||||
|
PG_LATIN4, /* ISO-8859 Latin 4 */
|
||||||
|
PG_LATIN5, /* ISO-8859 Latin 5 */
|
||||||
|
PG_KOI8R, /* KOI8-R */
|
||||||
|
PG_WIN1251, /* windows-1251 (was: WIN) */
|
||||||
|
PG_ALT, /* (MS-DOS CP866) */
|
||||||
|
|
||||||
|
/* followings are for client encoding only */
|
||||||
|
PG_SJIS, /* Shift JIS */
|
||||||
|
PG_BIG5, /* Big5 */
|
||||||
|
PG_WIN1250, /* windows-1250 */
|
||||||
|
|
||||||
|
_PG_LAST_ENCODING_ /* mark only */
|
||||||
|
|
||||||
|
} pg_enc;
|
||||||
|
|
||||||
|
#define PG_ENCODING_BE_LAST PG_ALT
|
||||||
|
#define PG_ENCODING_FE_LAST PG_WIN1250
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef MULTIBYTE
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Please use these tests before access to pg_encconv_tbl[]
|
||||||
|
* or to other places...
|
||||||
|
*/
|
||||||
|
#define PG_VALID_BE_ENCODING(_enc) \
|
||||||
|
((_enc) >= 0 && (_enc) <= PG_ENCODING_BE_LAST)
|
||||||
|
|
||||||
|
#define PG_ENCODING_IS_CLIEN_ONLY(_enc) \
|
||||||
|
(((_enc) > PG_ENCODING_BE_LAST && (_enc) <= PG_ENCODING_FE_LAST)
|
||||||
|
|
||||||
|
#define PG_VALID_ENCODING(_enc) \
|
||||||
|
((_enc) >= 0 && (_enc) < _PG_LAST_ENCODING_)
|
||||||
|
|
||||||
|
/* On FE are possible all encodings
|
||||||
|
*/
|
||||||
|
#define PG_VALID_FE_ENCODING(_enc) PG_VALID_ENCODING(_enc)
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Encoding names with all aliases
|
||||||
|
*/
|
||||||
|
typedef struct pg_encname
|
||||||
|
{
|
||||||
|
char *name;
|
||||||
|
pg_enc encoding;
|
||||||
|
} pg_encname;
|
||||||
|
|
||||||
|
extern pg_encname pg_encname_tbl[];
|
||||||
|
extern unsigned int pg_encname_tbl_sz;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Careful:
|
||||||
|
*
|
||||||
|
* if (PG_VALID_ENCODING(encoding))
|
||||||
|
* pg_enc2name_tbl[ encoding ];
|
||||||
|
*/
|
||||||
|
typedef struct pg_enc2name
|
||||||
|
{
|
||||||
|
char *name;
|
||||||
|
pg_enc encoding;
|
||||||
|
} pg_enc2name;
|
||||||
|
|
||||||
|
extern pg_enc2name pg_enc2name_tbl[];
|
||||||
|
|
||||||
|
extern pg_encname *pg_char_to_encname_struct(const char *name);
|
||||||
|
|
||||||
|
extern int pg_char_to_encoding(const char *s);
|
||||||
|
extern const char *pg_encoding_to_char(int encoding);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The backend encoding conversion routines
|
||||||
|
* Careful:
|
||||||
|
*
|
||||||
|
* if (PG_VALID_ENCODING(enc))
|
||||||
|
* pg_encconv_tbl[ enc ]->foo
|
||||||
|
*/
|
||||||
|
#ifndef FRONTEND
|
||||||
|
typedef struct pg_enconv
|
||||||
|
{
|
||||||
|
pg_enc encoding; /* encoding identificator */
|
||||||
void (*to_mic) (); /* client encoding to MIC */
|
void (*to_mic) (); /* client encoding to MIC */
|
||||||
void (*from_mic) (); /* MIC to client encoding */
|
void (*from_mic) (); /* MIC to client encoding */
|
||||||
void (*to_unicode) (); /* client encoding to UTF-8 */
|
void (*to_unicode) (); /* client encoding to UTF-8 */
|
||||||
void (*from_unicode) (); /* UTF-8 to client encoding */
|
void (*from_unicode) (); /* UTF-8 to client encoding */
|
||||||
} pg_encoding_conv_tbl;
|
} pg_enconv;
|
||||||
|
|
||||||
extern pg_encoding_conv_tbl pg_conv_tbl[];
|
extern pg_enconv pg_enconv_tbl[];
|
||||||
|
extern pg_enconv *pg_get_enconv_by_encoding(int encoding);
|
||||||
|
|
||||||
|
#endif /* FRONTEND */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* pg_wchar stuff
|
||||||
|
*/
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
int (*mb2wchar_with_len) (); /* convert a multi-byte
|
int (*mb2wchar_with_len) (); /* convert a multi-byte
|
||||||
@ -137,25 +218,25 @@ extern int pg_mbstrlen(const unsigned char *);
|
|||||||
extern int pg_mbstrlen_with_len(const unsigned char *, int);
|
extern int pg_mbstrlen_with_len(const unsigned char *, int);
|
||||||
extern int pg_mbcliplen(const unsigned char *, int, int);
|
extern int pg_mbcliplen(const unsigned char *, int, int);
|
||||||
extern int pg_mbcharcliplen(const unsigned char *, int, int);
|
extern int pg_mbcharcliplen(const unsigned char *, int, int);
|
||||||
extern pg_encoding_conv_tbl *pg_get_encent_by_encoding(int);
|
|
||||||
extern int pg_set_client_encoding(int);
|
extern int pg_set_client_encoding(int);
|
||||||
extern int pg_get_client_encoding(void);
|
extern int pg_get_client_encoding(void);
|
||||||
extern unsigned char *pg_client_to_server(unsigned char *, int);
|
extern const char *pg_get_client_encoding_name(void);
|
||||||
extern unsigned char *pg_server_to_client(unsigned char *, int);
|
|
||||||
extern int pg_valid_client_encoding(const char *);
|
extern void SetDatabaseEncoding(int);
|
||||||
extern pg_encoding_conv_tbl *pg_get_enc_ent(int);
|
extern int GetDatabaseEncoding(void);
|
||||||
|
extern const char *GetDatabaseEncodingName(void);
|
||||||
|
|
||||||
|
extern int pg_valid_client_encoding(const char *name);
|
||||||
|
extern int pg_valid_server_encoding(const char *name);
|
||||||
|
|
||||||
extern int pg_utf_mblen(const unsigned char *);
|
extern int pg_utf_mblen(const unsigned char *);
|
||||||
extern int pg_find_encoding_converters(int, int, void (**)(), void (**)());
|
extern int pg_find_encoding_converters(int, int, void (**)(), void (**)());
|
||||||
extern unsigned char *pg_do_encoding_conversion(unsigned char *, int, void (*)(), void (*)());
|
extern unsigned char *pg_do_encoding_conversion(unsigned char *, int, void (*)(), void (*)());
|
||||||
|
|
||||||
/* internally-used versions of functions. The PG_xxx forms of these
|
extern unsigned char *pg_client_to_server(unsigned char *, int);
|
||||||
* functions have fmgr-compatible interfaves.
|
extern unsigned char *pg_server_to_client(unsigned char *, int);
|
||||||
*/
|
|
||||||
extern const char *pg_encoding_to_char(int);
|
|
||||||
extern int pg_char_to_encoding(const char *);
|
|
||||||
|
|
||||||
extern int GetDatabaseEncoding(void);
|
|
||||||
extern void SetDatabaseEncoding(int);
|
|
||||||
extern unsigned short BIG5toCNS(unsigned short, unsigned char *);
|
extern unsigned short BIG5toCNS(unsigned short, unsigned char *);
|
||||||
extern unsigned short CNStoBIG5(unsigned short, unsigned char);
|
extern unsigned short CNStoBIG5(unsigned short, unsigned char);
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
|
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
|
||||||
* Portions Copyright (c) 1994, Regents of the University of California
|
* Portions Copyright (c) 1994, Regents of the University of California
|
||||||
*
|
*
|
||||||
* $Id: builtins.h,v 1.162 2001/08/15 07:07:40 ishii Exp $
|
* $Id: builtins.h,v 1.163 2001/09/06 04:57:29 ishii Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -579,8 +579,11 @@ extern Datum RI_FKey_setdefault_upd(PG_FUNCTION_ARGS);
|
|||||||
* since pg_proc.h has references to them.
|
* since pg_proc.h has references to them.
|
||||||
*/
|
*/
|
||||||
extern Datum getdatabaseencoding(PG_FUNCTION_ARGS);
|
extern Datum getdatabaseencoding(PG_FUNCTION_ARGS);
|
||||||
|
extern Datum database_character_set(PG_FUNCTION_ARGS);
|
||||||
extern Datum PG_encoding_to_char(PG_FUNCTION_ARGS);
|
extern Datum PG_encoding_to_char(PG_FUNCTION_ARGS);
|
||||||
extern Datum PG_char_to_encoding(PG_FUNCTION_ARGS);
|
extern Datum PG_char_to_encoding(PG_FUNCTION_ARGS);
|
||||||
|
extern Datum PG_character_set_name(PG_FUNCTION_ARGS);
|
||||||
|
extern Datum PG_character_set_id(PG_FUNCTION_ARGS);
|
||||||
extern Datum pg_convert(PG_FUNCTION_ARGS);
|
extern Datum pg_convert(PG_FUNCTION_ARGS);
|
||||||
extern Datum pg_convert2(PG_FUNCTION_ARGS);
|
extern Datum pg_convert2(PG_FUNCTION_ARGS);
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
#
|
#
|
||||||
# Copyright (c) 1994, Regents of the University of California
|
# Copyright (c) 1994, Regents of the University of California
|
||||||
#
|
#
|
||||||
# $Header: /cvsroot/pgsql/src/interfaces/libpq/Makefile,v 1.56 2001/08/28 14:20:28 petere Exp $
|
# $Header: /cvsroot/pgsql/src/interfaces/libpq/Makefile,v 1.57 2001/09/06 04:57:30 ishii Exp $
|
||||||
#
|
#
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
|
|
||||||
@ -24,7 +24,7 @@ OBJS= fe-auth.o fe-connect.o fe-exec.o fe-misc.o fe-print.o fe-lobj.o \
|
|||||||
$(INET_ATON) $(SNPRINTF) $(STRERROR)
|
$(INET_ATON) $(SNPRINTF) $(STRERROR)
|
||||||
|
|
||||||
ifdef MULTIBYTE
|
ifdef MULTIBYTE
|
||||||
OBJS+= wchar.o
|
OBJS+= wchar.o encnames.o
|
||||||
endif
|
endif
|
||||||
|
|
||||||
# Add libraries that libpq depends (or might depend) on into the
|
# Add libraries that libpq depends (or might depend) on into the
|
||||||
@ -67,6 +67,8 @@ strerror.c: $(backend_src)/port/strerror.c
|
|||||||
ifdef MULTIBYTE
|
ifdef MULTIBYTE
|
||||||
wchar.c : % : $(backend_src)/utils/mb/%
|
wchar.c : % : $(backend_src)/utils/mb/%
|
||||||
rm -f $@ && $(LN_S) $< .
|
rm -f $@ && $(LN_S) $< .
|
||||||
|
encnames.c : % : $(backend_src)/utils/mb/%
|
||||||
|
rm -f $@ && $(LN_S) $< .
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
|
||||||
@ -82,5 +84,5 @@ uninstall: uninstall-lib
|
|||||||
rm -f $(DESTDIR)$(includedir)/libpq-fe.h $(DESTDIR)$(includedir_internal)/libpq-int.h $(includedir_internal)/pqexpbuffer.h
|
rm -f $(DESTDIR)$(includedir)/libpq-fe.h $(DESTDIR)$(includedir_internal)/libpq-int.h $(includedir_internal)/pqexpbuffer.h
|
||||||
|
|
||||||
clean distclean maintainer-clean: clean-lib
|
clean distclean maintainer-clean: clean-lib
|
||||||
rm -f $(OBJS) dllist.c md5.c md5.h wchar.c
|
rm -f $(OBJS) dllist.c md5.c md5.h wchar.c encnames.c
|
||||||
rm -f $(OBJS) inet_aton.c snprintf.c strerror.c
|
rm -f $(OBJS) inet_aton.c snprintf.c strerror.c
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.176 2001/08/21 20:39:52 momjian Exp $
|
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.177 2001/09/06 04:57:30 ishii Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -1659,7 +1659,7 @@ keep_going: /* We will come back to here until there
|
|||||||
/* set client encoding in pg_conn struct */
|
/* set client encoding in pg_conn struct */
|
||||||
encoding = PQgetvalue(res, 0, 0);
|
encoding = PQgetvalue(res, 0, 0);
|
||||||
if (!encoding) /* this should not happen */
|
if (!encoding) /* this should not happen */
|
||||||
conn->client_encoding = SQL_ASCII;
|
conn->client_encoding = PG_SQL_ASCII;
|
||||||
else
|
else
|
||||||
conn->client_encoding = pg_char_to_encoding(encoding);
|
conn->client_encoding = pg_char_to_encoding(encoding);
|
||||||
PQclear(res);
|
PQclear(res);
|
||||||
@ -2758,7 +2758,8 @@ PQsetClientEncoding(PGconn *conn, const char *encoding)
|
|||||||
return (status);
|
return (status);
|
||||||
}
|
}
|
||||||
|
|
||||||
#else
|
#else /* without multibytle support */
|
||||||
|
|
||||||
int
|
int
|
||||||
PQsetClientEncoding(PGconn *conn, const char *encoding)
|
PQsetClientEncoding(PGconn *conn, const char *encoding)
|
||||||
{
|
{
|
||||||
@ -2832,73 +2833,3 @@ defaultNoticeProcessor(void *arg, const char *message)
|
|||||||
/* Note: we expect the supplied string to end with a newline already. */
|
/* Note: we expect the supplied string to end with a newline already. */
|
||||||
fprintf(stderr, "%s", message);
|
fprintf(stderr, "%s", message);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef MULTIBYTE
|
|
||||||
/*
|
|
||||||
* convert an encoding string to encoding symbol value.
|
|
||||||
* case is ignored.
|
|
||||||
* if there's no valid encoding, returns -1
|
|
||||||
*/
|
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
int encoding; /* encoding symbol value */
|
|
||||||
char *name; /* encoding string */
|
|
||||||
} PQ_encoding_conv_tbl;
|
|
||||||
|
|
||||||
static PQ_encoding_conv_tbl pq_conv_tbl[] = {
|
|
||||||
{SQL_ASCII, "SQL_ASCII"},
|
|
||||||
{EUC_JP, "EUC_JP"},
|
|
||||||
{EUC_CN, "EUC_CN"},
|
|
||||||
{EUC_KR, "EUC_KR"},
|
|
||||||
{EUC_TW, "EUC_TW"},
|
|
||||||
{UNICODE, "UNICODE"},
|
|
||||||
{MULE_INTERNAL, "MULE_INTERNAL"},
|
|
||||||
{LATIN1, "LATIN1"},
|
|
||||||
{LATIN2, "LATIN2"},
|
|
||||||
{LATIN3, "LATIN3"},
|
|
||||||
{LATIN4, "LATIN4"},
|
|
||||||
{LATIN5, "LATIN5"},
|
|
||||||
{KOI8, "KOI8"},
|
|
||||||
{WIN, "WIN"},
|
|
||||||
{ALT, "ALT"},
|
|
||||||
{SJIS, "SJIS"},
|
|
||||||
{BIG5, "BIG5"},
|
|
||||||
{WIN1250, "WIN1250"},
|
|
||||||
{-1, ""}
|
|
||||||
};
|
|
||||||
|
|
||||||
int
|
|
||||||
pg_char_to_encoding(const char *s)
|
|
||||||
{
|
|
||||||
PQ_encoding_conv_tbl *p = pq_conv_tbl;
|
|
||||||
|
|
||||||
if (!s)
|
|
||||||
return (-1);
|
|
||||||
|
|
||||||
for (; p->encoding >= 0; p++)
|
|
||||||
{
|
|
||||||
if (!strcasecmp(s, p->name))
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return (p->encoding);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* convert encoding symbol to encoding char.
|
|
||||||
* if there's no valid encoding symbol, returns ""
|
|
||||||
*/
|
|
||||||
const char *
|
|
||||||
pg_encoding_to_char(int encoding)
|
|
||||||
{
|
|
||||||
PQ_encoding_conv_tbl *p = pq_conv_tbl;
|
|
||||||
|
|
||||||
for (; p->encoding >= 0; p++)
|
|
||||||
{
|
|
||||||
if (p->encoding == encoding)
|
|
||||||
return (p->name);
|
|
||||||
}
|
|
||||||
return ("");
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
@ -25,7 +25,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-misc.c,v 1.55 2001/09/06 02:52:00 momjian Exp $
|
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-misc.c,v 1.56 2001/09/06 04:57:30 ishii Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -809,7 +809,7 @@ int
|
|||||||
PQenv2encoding(void)
|
PQenv2encoding(void)
|
||||||
{
|
{
|
||||||
char *str;
|
char *str;
|
||||||
int encoding = SQL_ASCII;
|
int encoding = PG_SQL_ASCII;
|
||||||
|
|
||||||
str = getenv("PGCLIENTENCODING");
|
str = getenv("PGCLIENTENCODING");
|
||||||
if (str && *str != '\0')
|
if (str && *str != '\0')
|
||||||
|
@ -70,12 +70,18 @@ multibyte_init(void)
|
|||||||
unsigned char *
|
unsigned char *
|
||||||
check_client_encoding(unsigned char *str)
|
check_client_encoding(unsigned char *str)
|
||||||
{
|
{
|
||||||
if (strstr(str, "%27SJIS%27") || strstr(str, "'SJIS'") || strstr(str, "'sjis'"))
|
if (strstr(str, "%27SJIS%27") ||
|
||||||
|
strstr(str, "'SJIS'") ||
|
||||||
|
strstr(str, "'sjis'") ||
|
||||||
|
strstr(str, "'Shift_JIS'"))
|
||||||
{
|
{
|
||||||
multibyte_client_encoding = SJIS;
|
multibyte_client_encoding = SJIS;
|
||||||
return ("SJIS");
|
return ("SJIS");
|
||||||
}
|
}
|
||||||
if (strstr(str, "%27BIG5%27") || strstr(str, "'BIG5'") || strstr(str, "'big5'"))
|
if (strstr(str, "%27BIG5%27") ||
|
||||||
|
strstr(str, "'BIG5'") ||
|
||||||
|
strstr(str, "'big5'")
|
||||||
|
strstr(str, "'Big5'"))
|
||||||
{
|
{
|
||||||
multibyte_client_encoding = BIG5;
|
multibyte_client_encoding = BIG5;
|
||||||
return ("BIG5");
|
return ("BIG5");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user