mirror of
https://github.com/postgres/postgres.git
synced 2025-09-02 04:21:28 +03:00
I really hope that I haven't missed anything in this one...
From: t-ishii@sra.co.jp Attached are patches to enhance the multi-byte support. (patches are against 7/18 snapshot) * determine encoding at initdb/createdb rather than compile time Now initdb/createdb has an option to specify the encoding. Also, I modified the syntax of CREATE DATABASE to accept encoding option. See README.mb for more details. For this purpose I have added new column "encoding" to pg_database. Also pg_attribute and pg_class are changed to catch up the modification to pg_database. Actually I haved added pg_database_mb.h, pg_attribute_mb.h and pg_class_mb.h. These are used only when MB is enabled. The reason having separate files is I couldn't find a way to use ifdef or whatever in those files. I have to admit it looks ugly. No way. * support for PGCLIENTENCODING when issuing COPY command commands/copy.c modified. * support for SQL92 syntax "SET NAMES" See gram.y. * support for LATIN2-5 * add UNICODE regression test case * new test suite for MB New directory test/mb added. * clean up source files Basic idea is to have MB's own subdirectory for easier maintenance. These are include/mb and backend/utils/mb.
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
# Makefile for commands
|
||||
#
|
||||
# IDENTIFICATION
|
||||
# $Header: /cvsroot/pgsql/src/backend/commands/Makefile,v 1.13 1998/06/16 07:29:20 momjian Exp $
|
||||
# $Header: /cvsroot/pgsql/src/backend/commands/Makefile,v 1.14 1998/07/24 03:31:11 scrappy Exp $
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
|
||||
@@ -22,10 +22,6 @@ OBJS = async.o creatinh.o command.o copy.o defind.o define.o \
|
||||
recipe.o explain.o sequence.o trigger.o user.o proclang.o \
|
||||
dbcommands.o variable.o
|
||||
|
||||
ifdef MB
|
||||
OBJS += mbutils.o
|
||||
endif
|
||||
|
||||
all: SUBSYS.o
|
||||
|
||||
SUBSYS.o: $(OBJS)
|
||||
|
@@ -14,7 +14,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/commands/cluster.c,v 1.23 1998/02/26 04:30:49 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/commands/cluster.c,v 1.24 1998/07/24 03:31:13 scrappy Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -43,7 +43,11 @@
|
||||
#include <utils/excid.h>
|
||||
#include <utils/mcxt.h>
|
||||
#include <catalog/pg_proc.h>
|
||||
#ifdef MB
|
||||
#include <catalog/pg_class_mb.h>
|
||||
#else
|
||||
#include <catalog/pg_class.h>
|
||||
#endif
|
||||
#include <optimizer/internal.h>
|
||||
#ifndef NO_SECURITY
|
||||
#include <utils/acl.h>
|
||||
|
@@ -6,7 +6,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/commands/copy.c,v 1.49 1998/07/15 18:53:40 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/commands/copy.c,v 1.50 1998/07/24 03:31:14 scrappy Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -37,6 +37,10 @@
|
||||
#include "commands/trigger.h"
|
||||
#include <storage/fd.h>
|
||||
|
||||
#ifdef MB
|
||||
#include "mb/pg_wchar.h"
|
||||
#endif
|
||||
|
||||
#define ISOCTAL(c) (((c) >= '0') && ((c) <= '7'))
|
||||
#define VALUE(c) ((c) - '0')
|
||||
|
||||
@@ -61,7 +65,7 @@ static char *CopyReadAttribute(FILE *fp, bool *isnull, char *delim, int *newline
|
||||
static char *CopyReadAttribute(FILE *fp, bool *isnull, char *delim);
|
||||
|
||||
#endif
|
||||
static void CopyAttributeOut(FILE *fp, char *string, char *delim, int is_array);
|
||||
static void CopyAttributeOut(FILE *fp, unsigned char *string, char *delim, int is_array);
|
||||
static int CountTuples(Relation relation);
|
||||
|
||||
extern FILE *Pfout,
|
||||
@@ -277,7 +281,7 @@ CopyTo(Relation rel, bool binary, bool oids, FILE *fp, char *delim)
|
||||
{
|
||||
string = (char *) (*fmgr_faddr(&out_functions[i]))
|
||||
(value, elements[i], typmod[i]);
|
||||
CopyAttributeOut(fp, string, delim, attr[i]->attnelems);
|
||||
CopyAttributeOut(fp, (unsigned char*)string, delim, attr[i]->attnelems);
|
||||
pfree(string);
|
||||
}
|
||||
else
|
||||
@@ -1012,6 +1016,17 @@ CopyReadAttribute(FILE *fp, bool *isnull, char *delim)
|
||||
char c;
|
||||
int done = 0;
|
||||
int i = 0;
|
||||
#ifdef MB
|
||||
int mblen;
|
||||
int encoding;
|
||||
unsigned char s[2];
|
||||
int j;
|
||||
#endif
|
||||
|
||||
#ifdef MB
|
||||
encoding = pg_get_client_encoding();
|
||||
s[1] = 0;
|
||||
#endif
|
||||
|
||||
#ifdef COPY_PATCH
|
||||
/* if last delimiter was a newline return a NULL attribute */
|
||||
@@ -1029,9 +1044,9 @@ CopyReadAttribute(FILE *fp, bool *isnull, char *delim)
|
||||
while (!done)
|
||||
{
|
||||
c = getc(fp);
|
||||
|
||||
if (feof(fp))
|
||||
return (NULL);
|
||||
|
||||
else if (c == '\\')
|
||||
{
|
||||
c = getc(fp);
|
||||
@@ -1112,21 +1127,55 @@ CopyReadAttribute(FILE *fp, bool *isnull, char *delim)
|
||||
#endif
|
||||
done = 1;
|
||||
}
|
||||
if (!done)
|
||||
if (!done) {
|
||||
attribute[i++] = c;
|
||||
#ifdef MB
|
||||
s[0] = c;
|
||||
mblen = pg_encoding_mblen(encoding, s);
|
||||
mblen--;
|
||||
for(j=0;j<mblen;j++) {
|
||||
c = getc(fp);
|
||||
if (feof(fp))
|
||||
return (NULL);
|
||||
attribute[i++] = c;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
if (i == EXT_ATTLEN - 1)
|
||||
elog(ERROR, "CopyReadAttribute - attribute length too long. line: %d", lineno);
|
||||
}
|
||||
attribute[i] = '\0';
|
||||
#ifdef MB
|
||||
return(pg_client_to_server((unsigned char*)attribute, strlen(attribute)));
|
||||
#else
|
||||
return (&attribute[0]);
|
||||
#endif
|
||||
}
|
||||
|
||||
static void
|
||||
CopyAttributeOut(FILE *fp, char *string, char *delim, int is_array)
|
||||
CopyAttributeOut(FILE *fp, unsigned char *server_string, char *delim, int is_array)
|
||||
{
|
||||
char c;
|
||||
unsigned char *string;
|
||||
unsigned char c;
|
||||
#ifdef MB
|
||||
int mblen;
|
||||
int encoding;
|
||||
int i;
|
||||
#endif
|
||||
|
||||
#ifdef MB
|
||||
string = pg_server_to_client(server_string, strlen(server_string));
|
||||
encoding = pg_get_client_encoding();
|
||||
#else
|
||||
string = server_string;
|
||||
#endif
|
||||
|
||||
#ifdef MB
|
||||
for (; (mblen = pg_encoding_mblen(encoding, string)) &&
|
||||
((c = *string) != '\0'); string += mblen)
|
||||
#else
|
||||
for (; (c = *string) != '\0'; string++)
|
||||
#endif
|
||||
{
|
||||
if (c == delim[0] || c == '\n' ||
|
||||
(c == '\\' && !is_array))
|
||||
@@ -1148,7 +1197,13 @@ CopyAttributeOut(FILE *fp, char *string, char *delim, int is_array)
|
||||
fputc('\\', fp);
|
||||
}
|
||||
}
|
||||
#ifdef MB
|
||||
for (i=0;i<mblen;i++) {
|
||||
fputc(*(string+i), fp);
|
||||
}
|
||||
#else
|
||||
fputc(*string, fp);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -7,7 +7,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/commands/dbcommands.c,v 1.15 1998/06/15 19:28:14 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/commands/dbcommands.c,v 1.16 1998/07/24 03:31:15 scrappy Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -22,7 +22,11 @@
|
||||
#include "access/htup.h"
|
||||
#include "access/relscan.h"
|
||||
#include "catalog/catname.h"
|
||||
#ifdef MB
|
||||
#include "catalog/pg_database_mb.h"
|
||||
#else
|
||||
#include "catalog/pg_database.h"
|
||||
#endif
|
||||
#include "catalog/pg_shadow.h"
|
||||
#include "commands/dbcommands.h"
|
||||
#include "fmgr.h"
|
||||
@@ -43,7 +47,11 @@ static HeapTuple get_pg_dbtup(char *command, char *dbname, Relation dbrel);
|
||||
static void stop_vacuum(char *dbpath, char *dbname);
|
||||
|
||||
void
|
||||
#ifdef MB
|
||||
createdb(char *dbname, char *dbpath, int encoding)
|
||||
#else
|
||||
createdb(char *dbname, char *dbpath)
|
||||
#endif
|
||||
{
|
||||
Oid db_id,
|
||||
user_id;
|
||||
@@ -90,8 +98,13 @@ createdb(char *dbname, char *dbpath)
|
||||
dbname, user_id, dbname);
|
||||
#endif
|
||||
|
||||
#ifdef MB
|
||||
sprintf(buf, "insert into pg_database (datname, datdba, encoding, datpath)"
|
||||
" values (\'%s\', \'%d\', \'%d\', \'%s\');", dbname, user_id, encoding, loc);
|
||||
#else
|
||||
sprintf(buf, "insert into pg_database (datname, datdba, datpath)"
|
||||
" values (\'%s\', \'%d\', \'%s\');", dbname, user_id, loc);
|
||||
#endif
|
||||
|
||||
pg_exec_query(buf);
|
||||
}
|
||||
|
@@ -1,527 +0,0 @@
|
||||
/*
|
||||
* conversion between client encoding and server internal encoding
|
||||
* (currently mule internal code (mic) is used)
|
||||
* Tatsuo Ishii
|
||||
* $Id: mbutils.c,v 1.2 1998/07/18 18:34:01 momjian Exp $
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "postgres.h"
|
||||
#include "miscadmin.h"
|
||||
#include "regex/pg_wchar.h"
|
||||
#include "commands/variable.h"
|
||||
|
||||
static int client_encoding = MULTIBYTE; /* defalut client encoding is set to
|
||||
same as the server encoding */
|
||||
/*
|
||||
* convert bogus chars that cannot be represented in the current encoding
|
||||
* system.
|
||||
*/
|
||||
static void printBogusChar(unsigned char **mic, unsigned char **p)
|
||||
{
|
||||
char strbuf[16];
|
||||
int l = pg_mic_mblen(*mic);
|
||||
|
||||
*(*p)++ = '(';
|
||||
while (l--) {
|
||||
sprintf(strbuf,"%02x",*(*mic)++);
|
||||
*(*p)++ = strbuf[0];
|
||||
*(*p)++ = strbuf[1];
|
||||
}
|
||||
*(*p)++ = ')';
|
||||
}
|
||||
|
||||
/*
|
||||
* SJIS ---> MIC
|
||||
*/
|
||||
static void sjis2mic(unsigned char *sjis, unsigned char *p, int len)
|
||||
{
|
||||
int c1,c2;
|
||||
|
||||
while (len > 0 && (c1 = *sjis++)) {
|
||||
if (c1 >= 0xa1 && c1 <= 0xdf) { /* 1 byte kana? */
|
||||
len--;
|
||||
*p++ = LC_JISX0201K;
|
||||
*p++ = c1;
|
||||
} else if (c1 > 0x7f) { /* kanji? */
|
||||
c2 = *sjis++;
|
||||
len -= 2;
|
||||
*p++ = LC_JISX0208;
|
||||
*p++ = ((c1 & 0x3f)<<1) + 0x9f + (c2 > 0x9e);
|
||||
*p++ = c2 + ((c2 > 0x9e)? 2 : 0x60) + (c2 < 0x80);
|
||||
} else { /* should be ASCII */
|
||||
len--;
|
||||
*p++ = c1;
|
||||
}
|
||||
}
|
||||
*p = '\0';
|
||||
}
|
||||
|
||||
/*
|
||||
* MIC ---> SJIS
|
||||
*/
|
||||
static void mic2sjis(unsigned char *mic, unsigned char *p, int len)
|
||||
{
|
||||
int c1,c2;
|
||||
|
||||
while (len > 0 && (c1 = *mic)) {
|
||||
len -= pg_mic_mblen(mic++);
|
||||
|
||||
if (c1 == LC_JISX0201K) {
|
||||
*p++ = *mic++;
|
||||
} else if (c1 == LC_JISX0208) {
|
||||
c1 = *mic++;
|
||||
c2 = *mic++;
|
||||
*p++ = ((c1 - 0xa1)>>1) + ((c1 < 0xdf)? 0x81 : 0xc1);
|
||||
*p++ = c2 - ((c1 & 1)? ((c2 < 0xe0)? 0x61 : 0x60) : 2);
|
||||
} else if (c1 > 0x7f) { /* cannot convert to SJIS! */
|
||||
mic--;
|
||||
printBogusChar(&mic, &p);
|
||||
} else { /* should be ASCII */
|
||||
*p++ = c1;
|
||||
}
|
||||
}
|
||||
*p = '\0';
|
||||
}
|
||||
|
||||
/*
|
||||
* EUC_JP ---> MIC
|
||||
*/
|
||||
static void euc_jp2mic(unsigned char *euc, unsigned char *p, int len)
|
||||
{
|
||||
int c1;
|
||||
|
||||
while (len > 0 && (c1 = *euc++)) {
|
||||
if (c1 == SS2) { /* 1 byte kana? */
|
||||
len -= 2;
|
||||
*p++ = LC_JISX0201K;
|
||||
*p++ = *euc++;
|
||||
} else if (c1 == SS3) { /* JIS X0212 kanji? */
|
||||
len -= 3;
|
||||
*p++ = LC_JISX0212;
|
||||
*p++ = *euc++;
|
||||
*p++ = *euc++;
|
||||
} else if (c1 & 0x80) { /* kanji? */
|
||||
len -= 2;
|
||||
*p++ = LC_JISX0208;
|
||||
*p++ = c1;
|
||||
*p++ = *euc++;
|
||||
} else { /* should be ASCII */
|
||||
len--;
|
||||
*p++ = c1;
|
||||
}
|
||||
}
|
||||
*p = '\0';
|
||||
}
|
||||
|
||||
/*
|
||||
* MIC ---> EUC_JP
|
||||
*/
|
||||
static void mic2euc_jp(unsigned char *mic, unsigned char *p, int len)
|
||||
{
|
||||
int c1;
|
||||
|
||||
while (len > 0 && (c1 = *mic)) {
|
||||
len -= pg_mic_mblen(mic++);
|
||||
|
||||
if (c1 == LC_JISX0201K) {
|
||||
*p++ = SS2;
|
||||
*p++ = *mic++;
|
||||
} else if (c1 == LC_JISX0212) {
|
||||
*p++ = SS3;
|
||||
*p++ = *mic++;
|
||||
*p++ = *mic++;
|
||||
} else if (c1 == LC_JISX0208) {
|
||||
*p++ = *mic++;
|
||||
*p++ = *mic++;
|
||||
} else if (c1 > 0x7f) { /* cannot convert to EUC_JP! */
|
||||
mic--;
|
||||
printBogusChar(&mic, &p);
|
||||
} else { /* should be ASCII */
|
||||
*p++ = c1;
|
||||
}
|
||||
}
|
||||
*p = '\0';
|
||||
}
|
||||
|
||||
/*
|
||||
* EUC_KR ---> MIC
|
||||
*/
|
||||
static void euc_kr2mic(unsigned char *euc, unsigned char *p, int len)
|
||||
{
|
||||
int c1;
|
||||
|
||||
while (len > 0 && (c1 = *euc++)) {
|
||||
if (c1 & 0x80) {
|
||||
len -= 2;
|
||||
*p++ = LC_KS5601;
|
||||
*p++ = c1;
|
||||
*p++ = *euc++;
|
||||
} else { /* should be ASCII */
|
||||
len--;
|
||||
*p++ = c1;
|
||||
}
|
||||
}
|
||||
*p = '\0';
|
||||
}
|
||||
|
||||
/*
|
||||
* MIC ---> EUC_KR
|
||||
*/
|
||||
static void mic2euc_kr(unsigned char *mic, unsigned char *p, int len)
|
||||
{
|
||||
int c1;
|
||||
|
||||
while (len > 0 && (c1 = *mic)) {
|
||||
len -= pg_mic_mblen(mic++);
|
||||
|
||||
if (c1 == LC_KS5601) {
|
||||
*p++ = *mic++;
|
||||
*p++ = *mic++;
|
||||
} else if (c1 > 0x7f) { /* cannot convert to EUC_KR! */
|
||||
mic--;
|
||||
printBogusChar(&mic, &p);
|
||||
} else { /* should be ASCII */
|
||||
*p++ = c1;
|
||||
}
|
||||
}
|
||||
*p = '\0';
|
||||
}
|
||||
|
||||
/*
|
||||
* EUC_CN ---> MIC
|
||||
*/
|
||||
static void euc_cn2mic(unsigned char *euc, unsigned char *p, int len)
|
||||
{
|
||||
int c1;
|
||||
|
||||
while (len > 0 && (c1 = *euc++)) {
|
||||
if (c1 & 0x80) {
|
||||
len -= 2;
|
||||
*p++ = LC_GB2312_80;
|
||||
*p++ = c1;
|
||||
*p++ = *euc++;
|
||||
} else { /* should be ASCII */
|
||||
len--;
|
||||
*p++ = c1;
|
||||
}
|
||||
}
|
||||
*p = '\0';
|
||||
}
|
||||
|
||||
/*
|
||||
* MIC ---> EUC_CN
|
||||
*/
|
||||
static void mic2euc_cn(unsigned char *mic, unsigned char *p, int len)
|
||||
{
|
||||
int c1;
|
||||
|
||||
while (len > 0 && (c1 = *mic)) {
|
||||
len -= pg_mic_mblen(mic++);
|
||||
|
||||
if (c1 == LC_GB2312_80) {
|
||||
*p++ = *mic++;
|
||||
*p++ = *mic++;
|
||||
} else if (c1 > 0x7f) { /* cannot convert to EUC_CN! */
|
||||
mic--;
|
||||
printBogusChar(&mic, &p);
|
||||
} else { /* should be ASCII */
|
||||
*p++ = c1;
|
||||
}
|
||||
}
|
||||
*p = '\0';
|
||||
}
|
||||
|
||||
/*
|
||||
* EUC_TW ---> MIC
|
||||
*/
|
||||
static void euc_tw2mic(unsigned char *euc, unsigned char *p, int len)
|
||||
{
|
||||
int c1;
|
||||
|
||||
while (len > 0 && (c1 = *euc++)) {
|
||||
if (c1 == SS2) {
|
||||
len -= 4;
|
||||
c1 = *euc++; /* plane No. */
|
||||
if (c1 == 0xa1) {
|
||||
*p++ = LC_CNS11643_1;
|
||||
} else if (c1 == 0xa2) {
|
||||
*p++ = LC_CNS11643_2;
|
||||
} else {
|
||||
*p++ = 0x9d; /* LCPRV2 */
|
||||
*p++ = 0xa3 - c1 + LC_CNS11643_3;
|
||||
}
|
||||
*p++ = *euc++;
|
||||
*p++ = *euc++;
|
||||
} else if (c1 & 0x80) { /* CNS11643-1 */
|
||||
len -= 2;
|
||||
*p++ = LC_CNS11643_1;
|
||||
*p++ = c1;
|
||||
*p++ = *euc++;
|
||||
} else { /* should be ASCII */
|
||||
len --;
|
||||
*p++ = c1;
|
||||
}
|
||||
}
|
||||
*p = '\0';
|
||||
}
|
||||
|
||||
/*
|
||||
* MIC ---> EUC_TW
|
||||
*/
|
||||
static void mic2euc_tw(unsigned char *mic, unsigned char *p, int len)
|
||||
{
|
||||
int c1;
|
||||
|
||||
while (len > 0 && (c1 = *mic)) {
|
||||
len -= pg_mic_mblen(mic++);
|
||||
|
||||
if (c1 == LC_CNS11643_1 || c1 == LC_CNS11643_2) {
|
||||
*p++ = *mic++;
|
||||
*p++ = *mic++;
|
||||
} else if (c1 == 0x9d) { /* LCPRV2? */
|
||||
*p++ = SS2;
|
||||
*p++ = c1 - LC_CNS11643_3 + 0xa3;
|
||||
*p++ = *mic++;
|
||||
*p++ = *mic++;
|
||||
} else if (c1 > 0x7f) { /* cannot convert to EUC_TW! */
|
||||
mic--;
|
||||
printBogusChar(&mic, &p);
|
||||
} else { /* should be ASCII */
|
||||
*p++ = c1;
|
||||
}
|
||||
}
|
||||
*p = '\0';
|
||||
}
|
||||
|
||||
/*
|
||||
* LATIN1 ---> MIC
|
||||
*/
|
||||
static void latin12mic(unsigned char *l, unsigned char *p, int len)
|
||||
{
|
||||
int c1;
|
||||
|
||||
while (len-- > 0 && (c1 = *l++)) {
|
||||
if (c1 > 0x7f) { /* Latin1? */
|
||||
*p++ = LC_ISO8859_1;
|
||||
}
|
||||
*p++ = c1;
|
||||
}
|
||||
*p = '\0';
|
||||
}
|
||||
|
||||
/*
|
||||
* MIC ---> LATIN1
|
||||
*/
|
||||
static void mic2latin1(unsigned char *mic, unsigned char *p, int len)
|
||||
{
|
||||
int c1;
|
||||
|
||||
while (len > 0 && (c1 = *mic)) {
|
||||
len -= pg_mic_mblen(mic++);
|
||||
|
||||
if (c1 == LC_ISO8859_1) {
|
||||
*p++ = *mic++;
|
||||
} else if (c1 > 0x7f) {
|
||||
mic--;
|
||||
printBogusChar(&mic, &p);
|
||||
} else { /* should be ASCII */
|
||||
*p++ = c1;
|
||||
}
|
||||
}
|
||||
*p = '\0';
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
int encoding; /* encoding symbol value */
|
||||
char *name; /* encoding name */
|
||||
int is_client_only; /* 0: server/client bothg supported
|
||||
1: client only */
|
||||
void (*to_mic)(); /* client encoding to MIC */
|
||||
void (*from_mic)(); /* MIC to client encoding */
|
||||
} pg_encoding_conv_tbl;
|
||||
|
||||
static pg_encoding_conv_tbl conv_tbl[] = {
|
||||
{EUC_JP, "EUC_JP", 0, euc_jp2mic, mic2euc_jp}, /* EUC_JP */
|
||||
{EUC_CN, "EUC_CN", 0, euc_cn2mic, mic2euc_cn}, /* EUC_CN */
|
||||
{EUC_KR, "EUC_KR", 0, euc_kr2mic, mic2euc_kr}, /* EUC_KR */
|
||||
{EUC_TW, "EUC_TW", 0, euc_tw2mic, mic2euc_tw}, /* EUC_TW */
|
||||
{UNICODE, "UNICODE", 0, 0, 0}, /* UNICODE */
|
||||
{MULE_INTERNAL, "MULE_INTERNAL", 0, 0, 0}, /* MULE_INTERNAL */
|
||||
{LATIN1, "LATIN1", 0, latin12mic, mic2latin1}, /* ISO 8859 Latin 1 */
|
||||
{SJIS, "SJIS", 1, sjis2mic, mic2sjis}, /* SJIS */
|
||||
{-1, "", 0, 0, 0} /* end mark */
|
||||
};
|
||||
|
||||
/*
|
||||
* find encoding table entry by encoding
|
||||
*/
|
||||
static pg_encoding_conv_tbl *get_enc_ent(int encoding)
|
||||
{
|
||||
pg_encoding_conv_tbl *p = conv_tbl;
|
||||
for(;p->encoding >= 0;p++) {
|
||||
if (p->encoding == encoding) {
|
||||
return(p);
|
||||
}
|
||||
}
|
||||
return(0);
|
||||
}
|
||||
|
||||
void (*client_to_mic)(); /* something to MIC */
|
||||
void (*client_from_mic)(); /* MIC to something */
|
||||
void (*server_to_mic)(); /* something to MIC */
|
||||
void (*server_from_mic)(); /* MIC to something */
|
||||
|
||||
/*
|
||||
* set the client encoding. if client/server encoding is
|
||||
* not supported, returns -1
|
||||
*/
|
||||
int pg_set_client_encoding(int encoding)
|
||||
{
|
||||
client_encoding = encoding;
|
||||
|
||||
if (client_encoding == MULTIBYTE) { /* server == client? */
|
||||
client_to_mic = client_from_mic = 0;
|
||||
server_to_mic = server_from_mic = 0;
|
||||
} else if (MULTIBYTE == MULE_INTERNAL) { /* server == MULE_INETRNAL? */
|
||||
client_to_mic = get_enc_ent(encoding)->to_mic;
|
||||
client_from_mic = get_enc_ent(encoding)->from_mic;
|
||||
server_to_mic = server_from_mic = 0;
|
||||
if (client_to_mic == 0 || client_from_mic == 0) {
|
||||
return(-1);
|
||||
}
|
||||
} else if (encoding == MULE_INTERNAL) { /* client == MULE_INETRNAL? */
|
||||
client_to_mic = client_from_mic = 0;
|
||||
server_to_mic = get_enc_ent(MULTIBYTE)->to_mic;
|
||||
server_from_mic = get_enc_ent(MULTIBYTE)->from_mic;
|
||||
if (server_to_mic == 0 || server_from_mic == 0) {
|
||||
return(-1);
|
||||
}
|
||||
} else {
|
||||
client_to_mic = get_enc_ent(encoding)->to_mic;
|
||||
client_from_mic = get_enc_ent(encoding)->from_mic;
|
||||
server_to_mic = get_enc_ent(MULTIBYTE)->to_mic;
|
||||
server_from_mic = get_enc_ent(MULTIBYTE)->from_mic;
|
||||
if (client_to_mic == 0 || client_from_mic == 0) {
|
||||
return(-1);
|
||||
}
|
||||
if (server_to_mic == 0 || server_from_mic == 0) {
|
||||
return(-1);
|
||||
}
|
||||
}
|
||||
return(0);
|
||||
}
|
||||
|
||||
/*
|
||||
* returns the current client encoding
|
||||
*/
|
||||
int pg_get_client_encoding()
|
||||
{
|
||||
return(client_encoding);
|
||||
}
|
||||
|
||||
/*
|
||||
* convert client encoding to server encoding
|
||||
*/
|
||||
unsigned char *pg_client_to_server(unsigned char *s, int len)
|
||||
{
|
||||
static unsigned char b1[MAX_PARSE_BUFFER*4]; /* is this enough? */
|
||||
static unsigned char b2[MAX_PARSE_BUFFER*4]; /* is this enough? */
|
||||
unsigned char *p;
|
||||
|
||||
if (client_to_mic) {
|
||||
(*client_to_mic)(s, b1, len);
|
||||
len = strlen(b1);
|
||||
p = b1;
|
||||
} else {
|
||||
p = s;
|
||||
}
|
||||
if (server_from_mic) {
|
||||
(*server_from_mic)(p, b2, len);
|
||||
p = b2;
|
||||
}
|
||||
return(p);
|
||||
}
|
||||
|
||||
/*
|
||||
* convert server encoding to client encoding
|
||||
*/
|
||||
unsigned char *pg_server_to_client(unsigned char *s, int len)
|
||||
{
|
||||
static unsigned char b1[MAX_PARSE_BUFFER*4]; /* is this enough? */
|
||||
static unsigned char b2[MAX_PARSE_BUFFER*4]; /* is this enough? */
|
||||
unsigned char *p;
|
||||
|
||||
if (server_to_mic) {
|
||||
(*server_to_mic)(s, b1, len);
|
||||
len = strlen(b1);
|
||||
p = b1;
|
||||
} else {
|
||||
p = s;
|
||||
}
|
||||
if (client_from_mic) {
|
||||
(*client_from_mic)(p, b2, len);
|
||||
p = b2;
|
||||
}
|
||||
return(p);
|
||||
}
|
||||
|
||||
/*
|
||||
* convert encoding char to encoding symbol value.
|
||||
* case is ignored.
|
||||
* if there's no valid encoding, returns -1
|
||||
*/
|
||||
int pg_char_to_encoding(const char *s)
|
||||
{
|
||||
pg_encoding_conv_tbl *p = conv_tbl;
|
||||
|
||||
for(;p->encoding >= 0;p++) {
|
||||
if (!strcasecmp(s, p->name)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return(p->encoding);
|
||||
}
|
||||
|
||||
/*
|
||||
* check to see if encoding name is valid
|
||||
*/
|
||||
int pg_valid_client_encoding(const char *name)
|
||||
{
|
||||
return(pg_char_to_encoding(name));
|
||||
}
|
||||
|
||||
/*
|
||||
* convert encoding symbol to encoding char.
|
||||
* if there's no valid encoding symbol, returns ""
|
||||
*/
|
||||
const char *pg_encoding_to_char(int encoding)
|
||||
{
|
||||
pg_encoding_conv_tbl *p = get_enc_ent(encoding);
|
||||
|
||||
if (!p) return("");
|
||||
return(p->name);
|
||||
}
|
||||
|
||||
#ifdef MULTIBYTEUTILSDEBUG
|
||||
#include <stdio.h>
|
||||
|
||||
main()
|
||||
{
|
||||
unsigned char sbuf[2048],ebuf[2048];
|
||||
unsigned char *p = sbuf;
|
||||
|
||||
int c;
|
||||
while ((c = getchar()) != EOF) {
|
||||
*p++ = c;
|
||||
}
|
||||
*p = '\0';
|
||||
|
||||
/*
|
||||
mic2sjis(sbuf,ebuf,2048);
|
||||
*/
|
||||
euc_jp2mic(sbuf,ebuf,2048);
|
||||
printf("%s",ebuf);
|
||||
}
|
||||
#endif
|
@@ -7,7 +7,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/commands/Attic/rename.c,v 1.11 1998/01/05 16:38:59 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/commands/Attic/rename.c,v 1.12 1998/07/24 03:31:19 scrappy Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -30,7 +30,11 @@
|
||||
#include <utils/excid.h>
|
||||
#include <utils/mcxt.h>
|
||||
#include <catalog/pg_proc.h>
|
||||
#ifdef MB
|
||||
#include <catalog/pg_class_mb.h>
|
||||
#else
|
||||
#include <catalog/pg_class.h>
|
||||
#endif
|
||||
#include <optimizer/internal.h>
|
||||
#include <optimizer/prep.h> /* for find_all_inheritors */
|
||||
#ifndef NO_SECURITY
|
||||
|
@@ -20,7 +20,11 @@
|
||||
|
||||
#include <miscadmin.h>
|
||||
#include <catalog/catname.h>
|
||||
#ifdef MB
|
||||
#include <catalog/pg_database_mb.h>
|
||||
#else
|
||||
#include <catalog/pg_database.h>
|
||||
#endif
|
||||
#include <catalog/pg_shadow.h>
|
||||
#include <libpq/crypt.h>
|
||||
#include <access/heapam.h>
|
||||
|
@@ -7,7 +7,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/commands/vacuum.c,v 1.66 1998/07/12 04:37:52 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/commands/vacuum.c,v 1.67 1998/07/24 03:31:20 scrappy Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -27,7 +27,11 @@
|
||||
#include "catalog/catalog.h"
|
||||
#include "catalog/catname.h"
|
||||
#include "catalog/index.h"
|
||||
#ifdef MB
|
||||
#include "catalog/pg_class_mb.h"
|
||||
#else
|
||||
#include "catalog/pg_class.h"
|
||||
#endif
|
||||
#include "catalog/pg_index.h"
|
||||
#include "catalog/pg_operator.h"
|
||||
#include "catalog/pg_statistic.h"
|
||||
|
@@ -2,7 +2,7 @@
|
||||
* Routines for handling of 'SET var TO',
|
||||
* 'SHOW var' and 'RESET var' statements.
|
||||
*
|
||||
* $Id: variable.c,v 1.8 1998/07/18 18:34:01 momjian Exp $
|
||||
* $Id: variable.c,v 1.9 1998/07/24 03:31:20 scrappy Exp $
|
||||
*
|
||||
*/
|
||||
|
||||
@@ -602,6 +602,9 @@ struct VariableParsers
|
||||
{
|
||||
"client_encoding", parse_client_encoding, show_client_encoding, reset_client_encoding
|
||||
},
|
||||
{
|
||||
"server_encoding", parse_server_encoding, show_server_encoding, reset_server_encoding
|
||||
},
|
||||
#endif
|
||||
{
|
||||
NULL, NULL, NULL, NULL
|
||||
|
Reference in New Issue
Block a user