1
0
mirror of https://github.com/postgres/postgres.git synced 2025-11-12 05:01:15 +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:
Marc G. Fournier
1998-07-24 03:32:46 +00:00
parent 6e66468f3a
commit bf00bbb0c4
82 changed files with 2161 additions and 759 deletions

View File

@@ -4,7 +4,7 @@
# Makefile for the bootstrap module
#
# IDENTIFICATION
# $Header: /cvsroot/pgsql/src/backend/bootstrap/Makefile,v 1.13 1998/04/06 00:22:02 momjian Exp $
# $Header: /cvsroot/pgsql/src/backend/bootstrap/Makefile,v 1.14 1998/07/24 03:31:06 scrappy Exp $
#
#
# We must build bootparse.c and bootscanner.c with yacc and lex and sed,
@@ -22,6 +22,9 @@ SRCDIR= ../..
include ../../Makefile.global
CFLAGS += -I..
ifdef MB
CFLAGS += -DMB=$(MB)
endif
ifeq ($(CC), gcc)
CFLAGS+= -Wno-error

View File

@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/bootstrap/bootparse.y,v 1.16 1998/04/26 04:05:51 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/bootstrap/bootparse.y,v 1.17 1998/07/24 03:31:07 scrappy Exp $
*
*-------------------------------------------------------------------------
*/
@@ -31,8 +31,13 @@
#include "bootstrap/bootstrap.h"
#include "catalog/heap.h"
#include "catalog/pg_am.h"
#ifdef MB
#include "catalog/pg_attribute_mb.h"
#include "catalog/pg_class_mb.h"
#else
#include "catalog/pg_attribute.h"
#include "catalog/pg_class.h"
#endif
#include "commands/defrem.h"
#include "nodes/nodes.h"
#include "nodes/parsenodes.h"

View File

@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/bootstrap/bootscanner.l,v 1.8 1997/11/24 05:07:56 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/bootstrap/bootscanner.l,v 1.9 1998/07/24 03:31:08 scrappy Exp $
*
*-------------------------------------------------------------------------
*/
@@ -20,7 +20,11 @@
#include "storage/block.h"
#include "storage/off.h"
#include "storage/itemptr.h"
#ifdef MB
#include "catalog/pg_attribute_mb.h"
#else
#include "catalog/pg_attribute.h"
#endif
#include "access/attnum.h"
#include "nodes/pg_list.h"
#include "access/tupdesc.h"
@@ -28,7 +32,11 @@
#include "access/funcindex.h"
#include "storage/fd.h"
#include "catalog/pg_am.h"
#ifdef MB
#include "catalog/pg_class_mb.h"
#else
#include "catalog/pg_class.h"
#endif
#include "nodes/nodes.h"
#include "rewrite/prs2lock.h"
#include "access/skey.h"

View File

@@ -7,7 +7,7 @@
* Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/bootstrap/bootstrap.c,v 1.44 1998/06/27 04:53:29 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/bootstrap/bootstrap.c,v 1.45 1998/07/24 03:31:08 scrappy Exp $
*
*-------------------------------------------------------------------------
*/
@@ -41,8 +41,13 @@
#include "catalog/catname.h"
#include "catalog/index.h"
#include "catalog/pg_am.h"
#ifdef MB
#include "catalog/pg_attribute_mb.h"
#include "catalog/pg_class_mb.h"
#else
#include "catalog/pg_attribute.h"
#include "catalog/pg_class.h"
#endif
#include "catalog/pg_type.h"
#include "executor/execdesc.h"
#include "executor/hashjoin.h"

View File

@@ -4,7 +4,7 @@
# Makefile for catalog
#
# IDENTIFICATION
# $Header: /cvsroot/pgsql/src/backend/catalog/Makefile,v 1.10 1998/04/06 00:22:13 momjian Exp $
# $Header: /cvsroot/pgsql/src/backend/catalog/Makefile,v 1.11 1998/07/24 03:31:09 scrappy Exp $
#
#-------------------------------------------------------------------------
@@ -24,11 +24,28 @@ SUBSYS.o: $(OBJS)
GENBKI= ./genbki.sh
ifdef MB
GLOBALBKI_SRCS= $(addprefix ../../include/catalog/, \
pg_database_mb.h pg_variable.h pg_shadow.h \
pg_group.h pg_log.h \
)
else
GLOBALBKI_SRCS= $(addprefix ../../include/catalog/, \
pg_database.h pg_variable.h pg_shadow.h \
pg_group.h pg_log.h \
)
endif
ifdef MB
LOCALBKI_SRCS= $(addprefix ../../include/catalog/, \
pg_proc.h pg_type.h pg_attribute_mb.h pg_class_mb.h \
pg_inherits.h pg_index.h pg_version.h pg_statistic.h \
pg_operator.h pg_opclass.h pg_am.h pg_amop.h pg_amproc.h \
pg_language.h pg_parg.h \
pg_aggregate.h pg_ipl.h pg_inheritproc.h \
pg_rewrite.h pg_listener.h pg_description.h indexing.h \
)
else
LOCALBKI_SRCS= $(addprefix ../../include/catalog/, \
pg_proc.h pg_type.h pg_attribute.h pg_class.h \
pg_inherits.h pg_index.h pg_version.h pg_statistic.h \
@@ -37,7 +54,7 @@ LOCALBKI_SRCS= $(addprefix ../../include/catalog/, \
pg_aggregate.h pg_ipl.h pg_inheritproc.h \
pg_rewrite.h pg_listener.h pg_description.h indexing.h \
)
endif
global1.bki.source: $(GENBKI) $(GLOBALBKI_SRCS)
sh $(SHOPTS) $(GENBKI) $(BKIOPTS) $(GLOBALBKI_SRCS) > $@ 2>global1.description

View File

@@ -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)

View File

@@ -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>

View File

@@ -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
}
}

View File

@@ -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);
}

View File

@@ -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

View File

@@ -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>

View File

@@ -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"

View File

@@ -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

View File

@@ -4,7 +4,7 @@
# Makefile for parser
#
# IDENTIFICATION
# $Header: /cvsroot/pgsql/src/backend/parser/Makefile,v 1.17 1998/05/13 04:54:16 thomas Exp $
# $Header: /cvsroot/pgsql/src/backend/parser/Makefile,v 1.18 1998/07/24 03:31:21 scrappy Exp $
#
#-------------------------------------------------------------------------
@@ -17,6 +17,9 @@ ifeq ($(CC), gcc)
CFLAGS+= -Wno-error
endif
ifdef MB
CFLAGS+= -DMB=$(MB)
endif
OBJS= analyze.o gram.o keywords.o parser.o parse_agg.o parse_clause.o \
parse_expr.o parse_func.o parse_node.o parse_oper.o parse_relation.o \

View File

@@ -10,7 +10,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.15 1998/07/19 05:49:22 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.16 1998/07/24 03:31:23 scrappy Exp $
*
* HISTORY
* AUTHOR DATE MAJOR EVENT
@@ -46,6 +46,10 @@
#include "utils/elog.h"
#include "access/xact.h"
#ifdef MB
#include "mb/pg_wchar.h"
#endif
static char saved_relname[NAMEDATALEN]; /* need this for complex attributes */
static bool QueryIsRule = FALSE;
static List *saved_In_Expr = NIL;
@@ -126,7 +130,7 @@ Oid param_type(int t); /* used in parse_expr.c */
ExplainStmt, VariableSetStmt, VariableShowStmt, VariableResetStmt,
CreateUserStmt, AlterUserStmt, DropUserStmt
%type <str> opt_database, location
%type <str> opt_database1, opt_database2, location, encoding
%type <pboolean> user_createdb_clause, user_createuser_clause
%type <str> user_passwd_clause
@@ -262,7 +266,7 @@ Oid param_type(int t); /* used in parse_expr.c */
GRANT, GROUP, HAVING, HOUR_P,
IN, INNER_P, INSERT, INTERVAL, INTO, IS,
JOIN, KEY, LANGUAGE, LEADING, LEFT, LIKE, LOCAL,
MATCH, MINUTE_P, MONTH_P,
MATCH, MINUTE_P, MONTH_P, NAMES,
NATIONAL, NATURAL, NCHAR, NO, NOT, NOTIFY, NULL_P, NUMERIC,
ON, OPTION, OR, ORDER, OUTER_P,
PARTIAL, POSITION, PRECISION, PRIMARY, PRIVILEGES, PROCEDURE, PUBLIC,
@@ -290,7 +294,7 @@ Oid param_type(int t); /* used in parse_expr.c */
NEW, NONE, NOTHING, NOTNULL, OIDS, OPERATOR, PROCEDURAL,
RECIPE, RENAME, RESET, RETURNS, ROW, RULE,
SEQUENCE, SETOF, SHOW, START, STATEMENT, STDIN, STDOUT, TRUSTED,
VACUUM, VERBOSE, VERSION
VACUUM, VERBOSE, VERSION, ENCODING
/* Keywords (obsolete; retain through next version for parser - thomas 1997-12-04) */
%token ARCHIVE
@@ -535,6 +539,17 @@ VariableSetStmt: SET ColId TO var_value
n->value = $4;
$$ = (Node *) n;
}
| SET NAMES encoding
{
#ifdef MB
VariableSetStmt *n = makeNode(VariableSetStmt);
n->name = "client_encoding";
n->value = $3;
$$ = (Node *) n;
#else
elog(ERROR, "SET NAMES is not supported");
#endif
}
;
var_value: Sconst { $$ = $1; }
@@ -2094,16 +2109,45 @@ LoadStmt: LOAD file_name
*
*****************************************************************************/
CreatedbStmt: CREATE DATABASE database_name opt_database
CreatedbStmt: CREATE DATABASE database_name WITH opt_database1 opt_database2
{
CreatedbStmt *n = makeNode(CreatedbStmt);
if ($5 == NULL && $6 == NULL) {
elog(ERROR, "CREATE DATABASE WITH requires at least an option");
}
n->dbname = $3;
n->dbpath = $5;
#ifdef MB
if ($6 != NULL) {
n->encoding = pg_char_to_encoding($6);
if (n->encoding < 0) {
elog(ERROR, "invalid encoding name %s", $6);
}
} else {
n->encoding = GetTemplateEncoding();
}
#else
elog(ERROR, "WITH ENCODING is not supported");
#endif
$$ = (Node *)n;
}
| CREATE DATABASE database_name
{
CreatedbStmt *n = makeNode(CreatedbStmt);
n->dbname = $3;
n->dbpath = $4;
n->dbpath = NULL;
#ifdef MB
n->encoding = GetTemplateEncoding();
#endif
$$ = (Node *)n;
}
;
opt_database: WITH LOCATION '=' location { $$ = $4; }
opt_database1: LOCATION '=' location { $$ = $3; }
| /*EMPTY*/ { $$ = NULL; }
;
opt_database2: ENCODING '=' encoding { $$ = $3; }
| /*EMPTY*/ { $$ = NULL; }
;
@@ -2112,6 +2156,11 @@ location: Sconst { $$ = $1; }
| /*EMPTY*/ { $$ = NULL; }
;
encoding: Sconst { $$ = $1; }
| DEFAULT { $$ = NULL; }
| /*EMPTY*/ { $$ = NULL; }
;
/*****************************************************************************
*
* QUERY:
@@ -4487,6 +4536,7 @@ ColId: IDENT { $$ = $1; }
| DELIMITERS { $$ = "delimiters"; }
| DOUBLE { $$ = "double"; }
| EACH { $$ = "each"; }
| ENCODING { $$ = "encoding"; }
| FUNCTION { $$ = "function"; }
| INCREMENT { $$ = "increment"; }
| INDEX { $$ = "index"; }

View File

@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/parser/keywords.c,v 1.37 1998/05/09 23:28:49 thomas Exp $
* $Header: /cvsroot/pgsql/src/backend/parser/keywords.c,v 1.38 1998/07/24 03:31:24 scrappy Exp $
*
*-------------------------------------------------------------------------
*/
@@ -86,6 +86,7 @@ static ScanKeyword ScanKeywords[] = {
{"double", DOUBLE},
{"drop", DROP},
{"each", EACH},
{"encoding", ENCODING},
{"end", END_TRANS},
{"execute", EXECUTE},
{"exists", EXISTS},
@@ -135,6 +136,7 @@ static ScanKeyword ScanKeywords[] = {
{"minvalue", MINVALUE},
{"month", MONTH_P},
{"move", MOVE},
{"names", NAMES},
{"national", NATIONAL},
{"natural", NATURAL},
{"nchar", NCHAR},

View File

@@ -4,7 +4,7 @@
# Makefile for regex
#
# IDENTIFICATION
# $Header: /cvsroot/pgsql/src/backend/regex/Makefile,v 1.6 1998/04/06 00:24:39 momjian Exp $
# $Header: /cvsroot/pgsql/src/backend/regex/Makefile,v 1.7 1998/07/24 03:31:24 scrappy Exp $
#
#-------------------------------------------------------------------------
@@ -16,7 +16,6 @@ CFLAGS += -DPOSIX_MISTAKE
OBJS = regcomp.o regerror.o regexec.o regfree.o
ifdef MB
OBJS += utils.o wstrcmp.o wstrncmp.o
CFLAGS += -DMB=$(MB)
endif

View File

@@ -4,7 +4,7 @@
# Makefile for rewrite
#
# IDENTIFICATION
# $Header: /cvsroot/pgsql/src/backend/rewrite/Makefile,v 1.6 1998/04/06 00:24:49 momjian Exp $
# $Header: /cvsroot/pgsql/src/backend/rewrite/Makefile,v 1.7 1998/07/24 03:31:30 scrappy Exp $
#
#-------------------------------------------------------------------------
@@ -12,6 +12,9 @@ SRCDIR = ../..
include ../../Makefile.global
CFLAGS += -I..
ifdef MB
CFLAGS += -DMB=$(MB)
endif
OBJS = rewriteRemove.o rewriteDefine.o \
rewriteHandler.o rewriteManip.o rewriteSupport.o locks.o

View File

@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/rewrite/rewriteSupport.c,v 1.21 1998/06/15 19:29:08 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/rewrite/rewriteSupport.c,v 1.22 1998/07/24 03:31:31 scrappy Exp $
*
*-------------------------------------------------------------------------
*/
@@ -16,7 +16,11 @@
#include "access/heapam.h"
#include "catalog/catname.h"
#include "catalog/indexing.h"
#ifdef MB
#include "catalog/pg_class_mb.h"
#else
#include "catalog/pg_class.h"
#endif
#include "catalog/pg_rewrite.h"
#include "fmgr.h"
#include "nodes/parsenodes.h"

View File

@@ -4,7 +4,7 @@
# Makefile for storage/lmgr
#
# IDENTIFICATION
# $Header: /cvsroot/pgsql/src/backend/storage/lmgr/Makefile,v 1.6 1998/04/06 00:25:43 momjian Exp $
# $Header: /cvsroot/pgsql/src/backend/storage/lmgr/Makefile,v 1.7 1998/07/24 03:31:32 scrappy Exp $
#
#-------------------------------------------------------------------------
@@ -12,6 +12,9 @@ SRCDIR = ../../..
include ../../../Makefile.global
CFLAGS += -I../..
ifdef MB
CFLAGS += -DMB=$(MB)
endif
OBJS = lmgr.o lock.o multi.o proc.o single.o

View File

@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/storage/lmgr/lmgr.c,v 1.13 1998/07/13 16:34:50 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/storage/lmgr/lmgr.c,v 1.14 1998/07/24 03:31:33 scrappy Exp $
*
*-------------------------------------------------------------------------
*/
@@ -41,7 +41,11 @@
#include "catalog/catname.h"
#include "catalog/catalog.h"
#ifdef MB
#include "catalog/pg_class_mb.h"
#else
#include "catalog/pg_class.h"
#endif
#include "nodes/memnodes.h"
#include "storage/bufmgr.h"

View File

@@ -4,7 +4,7 @@
# Makefile for storage/smgr
#
# IDENTIFICATION
# $Header: /cvsroot/pgsql/src/backend/storage/smgr/Makefile,v 1.6 1998/04/06 00:25:58 momjian Exp $
# $Header: /cvsroot/pgsql/src/backend/storage/smgr/Makefile,v 1.7 1998/07/24 03:31:35 scrappy Exp $
#
#-------------------------------------------------------------------------
@@ -13,6 +13,10 @@ include ../../../Makefile.global
CFLAGS += -I../..
ifdef MB
CFLAGS += -DMB=$(MB)
endif
OBJS = md.o mm.o smgr.o smgrtype.o
all: SUBSYS.o

View File

@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/storage/smgr/md.c,v 1.33 1998/07/20 16:56:55 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/storage/smgr/md.c,v 1.34 1998/07/24 03:31:35 scrappy Exp $
*
*-------------------------------------------------------------------------
*/
@@ -568,8 +568,15 @@ mdblindwrt(char *dbstr,
Oid owner,
id;
char *tmpPath;
#ifdef MB
int tmpEncoding;
#endif
#ifdef MB
GetRawDatabaseInfo(dbstr, &owner, &id, dbpath, &tmpEncoding);
#else
GetRawDatabaseInfo(dbstr, &owner, &id, dbpath);
#endif
if (id != dbid)
elog(FATAL, "mdblindwrt: oid of db %s is not %u", dbstr, dbid);
@@ -607,7 +614,15 @@ mdblindwrt(char *dbstr,
id;
char *tmpPath;
#ifdef MB
int tmpEncoding;
#endif
#ifdef MB
GetRawDatabaseInfo(dbstr, &owner, &id, dbpath, &tmpEncoding);
#else
GetRawDatabaseInfo(dbstr, &owner, &id, dbpath);
#endif
if (id != dbid)
elog(FATAL, "mdblindwrt: oid of db %s is not %u", dbstr, dbid);

View File

@@ -9,7 +9,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/tcop/utility.c,v 1.42 1998/06/16 02:53:26 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/tcop/utility.c,v 1.43 1998/07/24 03:31:38 scrappy Exp $
*
*-------------------------------------------------------------------------
*/
@@ -558,7 +558,11 @@ ProcessUtility(Node *parsetree,
*ps_status = commandTag = "CREATEDB";
CHECK_IF_ABORTED();
#ifdef MB
createdb(stmt->dbname, stmt->dbpath, stmt->encoding);
#else
createdb(stmt->dbname, stmt->dbpath);
#endif
}
break;

View File

@@ -4,7 +4,7 @@
# Makefile for utils
#
# IDENTIFICATION
# $Header: /cvsroot/pgsql/src/backend/utils/Makefile,v 1.6 1998/04/06 00:26:13 momjian Exp $
# $Header: /cvsroot/pgsql/src/backend/utils/Makefile,v 1.7 1998/07/24 03:31:39 scrappy Exp $
#
#-------------------------------------------------------------------------
@@ -23,6 +23,11 @@ OBJS = fmgrtab.o adt/SUBSYS.o cache/SUBSYS.o error/SUBSYS.o \
DIRS = adt cache error fmgr hash init misc mmgr sort time
ifdef MB
OBJS += mb/SUBSYS.o
DIRS += mb
endif
SUBSYS.o: $(OBJS)
$(LD) -r -o SUBSYS.o $(OBJS)

View File

@@ -21,7 +21,7 @@
#include "postgres.h" /* postgres system include file */
#include "utils/palloc.h"
#include "utils/builtins.h" /* where the function declarations go */
#include "regex/pg_wchar.h"
#include "mb/pg_wchar.h"
static int like(pg_wchar *text, pg_wchar *p);
@@ -111,7 +111,7 @@ textnlike(struct varlena * s, struct varlena * p)
}
/* $Revision: 1.17 $
/* $Revision: 1.18 $
** "like.c" A first attempt at a LIKE operator for Postgres95.
**
** Originally written by Rich $alz, mirror!rs, Wed Nov 26 19:03:17 EST 1986.

View File

@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/varchar.c,v 1.36 1998/07/18 18:34:12 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/adt/varchar.c,v 1.37 1998/07/24 03:31:42 scrappy Exp $
*
*-------------------------------------------------------------------------
*/
@@ -21,7 +21,7 @@ char *convertstr(char *, int, int);
#endif
#include "regex/pg_wchar.h"
#include "mb/pg_wchar.h"
/*
* CHAR() and VARCHAR() types are part of the ANSI SQL standard. CHAR()

View File

@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/varlena.c,v 1.38 1998/07/18 18:34:13 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/adt/varlena.c,v 1.39 1998/07/24 03:31:43 scrappy Exp $
*
*-------------------------------------------------------------------------
*/
@@ -18,7 +18,7 @@
#include "utils/palloc.h"
#include "utils/builtins.h" /* where function declarations go */
#include "regex/pg_wchar.h"
#include "mb/pg_wchar.h"
/*****************************************************************************
* USER I/O ROUTINES *

View File

@@ -4,7 +4,7 @@
# Makefile for utils/cache
#
# IDENTIFICATION
# $Header: /cvsroot/pgsql/src/backend/utils/cache/Makefile,v 1.6 1998/04/06 00:26:33 momjian Exp $
# $Header: /cvsroot/pgsql/src/backend/utils/cache/Makefile,v 1.7 1998/07/24 03:31:46 scrappy Exp $
#
#-------------------------------------------------------------------------
@@ -12,6 +12,9 @@ SRCDIR = ../../..
include ../../../Makefile.global
CFLAGS += -I../..
ifdef MB
CFLAGS += -DMB=$(MB)
endif
OBJS = catcache.o inval.o rel.o relcache.o syscache.o lsyscache.o fcache.o

View File

@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/cache/Attic/fcache.c,v 1.12 1998/06/15 19:29:39 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/cache/Attic/fcache.c,v 1.13 1998/07/24 03:31:46 scrappy Exp $
*
*-------------------------------------------------------------------------
*/
@@ -22,7 +22,11 @@
#include "catalog/pg_type.h"
#include "catalog/pg_proc.h"
#include "catalog/pg_language.h"
#ifdef MB
#include "catalog/pg_class_mb.h"
#else
#include "catalog/pg_class.h"
#endif
#include "parser/parsetree.h" /* for getrelname() */
#include "utils/builtins.h"
#include "utils/fcache.h"

View File

@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/cache/relcache.c,v 1.41 1998/07/20 16:14:16 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/cache/relcache.c,v 1.42 1998/07/24 03:31:47 scrappy Exp $
*
*-------------------------------------------------------------------------
*/
@@ -53,7 +53,11 @@
#include "catalog/indexing.h"
#include "catalog/pg_aggregate.h"
#include "catalog/pg_attrdef.h"
#ifdef MB
#include "catalog/pg_attribute_mb.h"
#else
#include "catalog/pg_attribute.h"
#endif
#include "catalog/pg_index.h"
#include "catalog/pg_proc.h"
#include "catalog/pg_class.h"

View File

@@ -4,7 +4,7 @@
# Makefile for utils/init
#
# IDENTIFICATION
# $Header: /cvsroot/pgsql/src/backend/utils/init/Makefile,v 1.7 1998/04/06 00:27:07 momjian Exp $
# $Header: /cvsroot/pgsql/src/backend/utils/init/Makefile,v 1.8 1998/07/24 03:31:49 scrappy Exp $
#
#-------------------------------------------------------------------------
@@ -12,6 +12,9 @@ SRCDIR = ../../..
include ../../../Makefile.global
CFLAGS += -I../..
ifdef MB
CFLAGS += -DMB=$(MB)
endif
OBJS = enbl.o findbe.o globals.o miscinit.o postinit.o

View File

@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/init/miscinit.c,v 1.16 1998/06/27 04:53:47 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/init/miscinit.c,v 1.17 1998/07/24 03:31:50 scrappy Exp $
*
*-------------------------------------------------------------------------
*/
@@ -234,6 +234,18 @@ SetDatabaseName(char *name)
strcpy(DatabaseName, name);
}
#ifndef MB
/* even if MB is not enabled, this function is neccesary
* since pg_proc.h does have.
*/
const char *
getdatabaseencoding()
{
elog(ERROR, "you need to enable MB to use this function");
return("");
}
#endif
#ifdef CYR_RECODE
#define MAX_TOKEN 80

View File

@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/init/postinit.c,v 1.30 1998/06/27 04:53:48 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/init/postinit.c,v 1.31 1998/07/24 03:31:50 scrappy Exp $
*
* NOTES
* InitPostgres() is the function called from PostgresMain
@@ -66,7 +66,12 @@
#include "utils/inval.h"
#include "catalog/catname.h"
#ifdef MB
#include "catalog/pg_database_mb.h"
#include "mb/pg_wchar.h"
#else
#include "catalog/pg_database.h"
#endif
#include "libpq/libpq.h"
@@ -78,7 +83,11 @@ static void InitStdio(void);
static void InitUserid(void);
extern char *ExpandDatabasePath(char *name);
#ifdef MB
extern void GetRawDatabaseInfo(char *name, Oid *owner, Oid *db_id, char *path, int *encoding);
#else
extern void GetRawDatabaseInfo(char *name, Oid *owner, Oid *db_id, char *path);
#endif
static IPCKey PostgresIpcKey;
@@ -119,9 +128,16 @@ InitMyDatabaseInfo(char *name)
Oid owner;
char *path,
myPath[MAXPGPATH + 1];
#ifdef MB
int encoding;
#endif
SetDatabaseName(name);
#ifdef MB
GetRawDatabaseInfo(name, &owner, &MyDatabaseId, myPath, &encoding);
#else
GetRawDatabaseInfo(name, &owner, &MyDatabaseId, myPath);
#endif
if (!OidIsValid(MyDatabaseId))
elog(FATAL,
@@ -131,6 +147,9 @@ InitMyDatabaseInfo(char *name)
path = ExpandDatabasePath(myPath);
SetDatabasePath(path);
#ifdef MB
SetDatabaseEncoding(encoding);
#endif
return;
} /* InitMyDatabaseInfo() */

View File

@@ -0,0 +1,35 @@
#-------------------------------------------------------------------------
#
# Makefile--
# Makefile for utils/mb
#
# IDENTIFICATION
# $Header: /cvsroot/pgsql/src/backend/utils/mb/Makefile,v 1.1 1998/07/24 03:31:54 scrappy Exp $
#
#-------------------------------------------------------------------------
SRCDIR = ../../..
include ../../../Makefile.global
CFLAGS += -I../..
ifdef MB
CFLAGS += -DMB=$(MB)
endif
OBJS = common.o conv.o mbutils.o wchar.o wstrcmp.o wstrncmp.o variable.o
all: SUBSYS.o
SUBSYS.o: $(OBJS)
$(LD) -r -o SUBSYS.o $(OBJS)
depend dep:
$(CC) -MM $(CFLAGS) *.c >depend
clean:
rm -f SUBSYS.o $(OBJS)
ifeq (depend,$(wildcard depend))
include depend
endif

View File

@@ -0,0 +1,10 @@
common.c: public functions for both the backend and the frontend.
requires conv.c and wchar.c
conv.c: static functions and a public table for code conversion
wchar.c: mostly static functions and a public table for mb string and
multi-byte conversion
mbutilc.c: public functions for the backend only.
requires conv.c and wchar.c
wstrcmp.c: strcmp for mb
wstrncmp.c: strncmp for mb
varable.c: public functions for show/set/reset variable commands

View File

@@ -0,0 +1,67 @@
/*
* This file contains some public functions
* usable for both the backend and the frontend.
* Tatsuo Ishii
* $Id: common.c,v 1.1 1998/07/24 03:31:56 scrappy Exp $ */
#include <stdio.h>
#include <string.h>
#include "mb/pg_wchar.h"
/*
* 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 = pg_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));
}
/*
* find encoding table entry by encoding
*/
pg_encoding_conv_tbl *pg_get_encent_by_encoding(int encoding)
{
pg_encoding_conv_tbl *p = pg_conv_tbl;
for(;p->encoding >= 0;p++) {
if (p->encoding == encoding) {
return(p);
}
}
return(0);
}
/*
* 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 = pg_get_encent_by_encoding(encoding);
if (!p) return("");
return(p->name);
}
/* returns the byte length of a multi-byte word for an encoding */
int pg_encoding_mblen(int encoding, const unsigned char *mbstr)
{
return((*pg_wchar_table[encoding].mblen)(mbstr));
}

View File

@@ -2,18 +2,13 @@
* 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 $
* $Id: conv.c,v 1.1 1998/07/24 03:31:56 scrappy Exp $
*/
#include <stdio.h>
#include <string.h>
#include "postgres.h"
#include "miscadmin.h"
#include "regex/pg_wchar.h"
#include "commands/variable.h"
#include "mb/pg_wchar.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.
@@ -296,15 +291,15 @@ static void mic2euc_tw(unsigned char *mic, unsigned char *p, int len)
}
/*
* LATIN1 ---> MIC
* LATINn ---> MIC
*/
static void latin12mic(unsigned char *l, unsigned char *p, int len)
static void latin2mic(unsigned char *l, unsigned char *p, int len, int lc)
{
int c1;
while (len-- > 0 && (c1 = *l++)) {
if (c1 > 0x7f) { /* Latin1? */
*p++ = LC_ISO8859_1;
*p++ = lc;
}
*p++ = c1;
}
@@ -312,16 +307,16 @@ static void latin12mic(unsigned char *l, unsigned char *p, int len)
}
/*
* MIC ---> LATIN1
* MIC ---> LATINn
*/
static void mic2latin1(unsigned char *mic, unsigned char *p, int len)
static void mic2latin(unsigned char *mic, unsigned char *p, int len, int lc)
{
int c1;
while (len > 0 && (c1 = *mic)) {
len -= pg_mic_mblen(mic++);
if (c1 == LC_ISO8859_1) {
if (c1 == lc) {
*p++ = *mic++;
} else if (c1 > 0x7f) {
mic--;
@@ -333,16 +328,48 @@ static void mic2latin1(unsigned char *mic, unsigned char *p, int len)
*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 void latin12mic(unsigned char *l, unsigned char *p, int len)
{
latin2mic(l, p, len, LC_ISO8859_1);
}
static void mic2latin1(unsigned char *mic, unsigned char *p, int len)
{
mic2latin(mic, p, len, LC_ISO8859_1);
}
static void latin22mic(unsigned char *l, unsigned char *p, int len)
{
latin2mic(l, p, len, LC_ISO8859_2);
}
static void mic2latin2(unsigned char *mic, unsigned char *p, int len)
{
mic2latin(mic, p, len, LC_ISO8859_2);
}
static void latin32mic(unsigned char *l, unsigned char *p, int len)
{
latin2mic(l, p, len, LC_ISO8859_3);
}
static void mic2latin3(unsigned char *mic, unsigned char *p, int len)
{
mic2latin(mic, p, len, LC_ISO8859_3);
}
static void latin42mic(unsigned char *l, unsigned char *p, int len)
{
latin2mic(l, p, len, LC_ISO8859_4);
}
static void mic2latin4(unsigned char *mic, unsigned char *p, int len)
{
mic2latin(mic, p, len, LC_ISO8859_4);
}
static void latin52mic(unsigned char *l, unsigned char *p, int len)
{
latin2mic(l, p, len, LC_ISO8859_5);
}
static void mic2latin5(unsigned char *mic, unsigned char *p, int len)
{
mic2latin(mic, p, len, LC_ISO8859_5);
}
static pg_encoding_conv_tbl conv_tbl[] = {
pg_encoding_conv_tbl pg_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 */
@@ -350,178 +377,10 @@ static pg_encoding_conv_tbl conv_tbl[] = {
{UNICODE, "UNICODE", 0, 0, 0}, /* UNICODE */
{MULE_INTERNAL, "MULE_INTERNAL", 0, 0, 0}, /* MULE_INTERNAL */
{LATIN1, "LATIN1", 0, latin12mic, mic2latin1}, /* ISO 8859 Latin 1 */
{LATIN2, "LATIN2", 0, latin22mic, mic2latin2}, /* ISO 8859 Latin 2 */
{LATIN3, "LATIN3", 0, latin32mic, mic2latin3}, /* ISO 8859 Latin 3 */
{LATIN4, "LATIN4", 0, latin42mic, mic2latin4}, /* ISO 8859 Latin 4 */
{LATIN5, "LATIN5", 0, latin52mic, mic2latin5}, /* ISO 8859 Latin 5 */
{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

View File

@@ -0,0 +1,216 @@
/*
* This file contains public functions for conversion between
* client encoding and server internal encoding.
* (currently mule internal code (mic) is used)
* Tatsuo Ishii
* $Id: mbutils.c,v 1.1 1998/07/24 03:31:56 scrappy Exp $ */
#include <stdio.h>
#include <string.h>
#include "mb/pg_wchar.h"
static client_encoding = -1;
static void (*client_to_mic)(); /* something to MIC */
static void (*client_from_mic)(); /* MIC to something */
static void (*server_to_mic)(); /* something to MIC */
static void (*server_from_mic)(); /* MIC to something */
/*
* find encoding table entry by encoding
*/
static pg_encoding_conv_tbl *get_enc_ent(int encoding)
{
pg_encoding_conv_tbl *p = pg_conv_tbl;
for(;p->encoding >= 0;p++) {
if (p->encoding == encoding) {
return(p);
}
}
return(0);
}
/*
* set the client encoding. if client/server encoding is
* not supported, returns -1
*/
int pg_set_client_encoding(int encoding)
{
int current_server_encoding = GetDatabaseEncoding();
client_encoding = encoding;
if (client_encoding == current_server_encoding) { /* server == client? */
client_to_mic = client_from_mic = 0;
server_to_mic = server_from_mic = 0;
} else if (current_server_encoding == MULE_INTERNAL) { /* server == MULE_INETRNAL? */
client_to_mic = get_enc_ent(encoding)->to_mic;
client_from_mic = get_enc_ent(encoding)->from_mic;
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(current_server_encoding)->to_mic;
server_from_mic = get_enc_ent(current_server_encoding)->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(current_server_encoding)->to_mic;
server_from_mic = get_enc_ent(current_server_encoding)->from_mic;
if (client_to_mic == 0 || client_from_mic == 0) {
return(-1);
}
if (server_to_mic == 0 || server_from_mic == 0) {
return(-1);
}
}
return(0);
}
/*
* returns the current client encoding
*/
int pg_get_client_encoding()
{
if (client_encoding == -1) {
/* this is the first time */
client_encoding = GetDatabaseEncoding();
}
return(client_encoding);
}
/*
* convert client encoding to server encoding. if server_encoding ==
* client_encoding or no conversion function exists,
* returns s. So be careful.
*/
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 = s;
if (client_encoding == GetDatabaseEncoding()) {
return(p);
}
if (client_to_mic) {
(*client_to_mic)(s, b1, len);
len = strlen(b1);
p = b1;
}
if (server_from_mic) {
(*server_from_mic)(p, b2, len);
p = b2;
}
return(p);
}
/*
* convert server encoding to client encoding. if server_encoding ==
* client_encoding or no conversion function exists,
* returns s. So be careful.
*/
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 = s;
if (client_encoding == GetDatabaseEncoding()) {
return(p);
}
if (server_to_mic) {
(*server_to_mic)(s, b1, len);
len = strlen(b1);
p = b1;
}
if (client_from_mic) {
(*client_from_mic)(p, b2, len);
p = b2;
}
return(p);
}
/* convert a multi-byte string to a wchar */
void pg_mb2wchar(const unsigned char *from, pg_wchar *to)
{
(*pg_wchar_table[GetDatabaseEncoding()].mb2wchar_with_len)(from,to,strlen(from));
}
/* convert a multi-byte string to a wchar with a limited length */
void pg_mb2wchar_with_len(const unsigned char *from, pg_wchar *to, int len)
{
(*pg_wchar_table[GetDatabaseEncoding()].mb2wchar_with_len)(from,to,len);
}
/* returns the byte length of a multi-byte word */
int pg_mblen(const unsigned char *mbstr)
{
return((*pg_wchar_table[GetDatabaseEncoding()].mblen)(mbstr));
}
/* returns the length (counted as a wchar) of a multi-byte string */
int pg_mbstrlen(const unsigned char *mbstr)
{
int len = 0;
while (*mbstr) {
mbstr += pg_mblen(mbstr);
len++;
}
return(len);
}
/* returns the length (counted as a wchar) of a multi-byte string
(not necessarily NULL terminated) */
int pg_mbstrlen_with_len(const unsigned char *mbstr, int limit)
{
int len = 0;
int l;
while (*mbstr && limit > 0) {
l = pg_mblen(mbstr);
limit -= l;
mbstr += l;
len++;
}
return(len);
}
/*
* fuctions for utils/init
*/
static int DatabaseEncoding = MB;
void
SetDatabaseEncoding(int encoding)
{
DatabaseEncoding = encoding;
}
int
GetDatabaseEncoding()
{
return(DatabaseEncoding);
}
/* for builtin-function */
const char *
getdatabaseencoding()
{
return(pg_encoding_to_char(DatabaseEncoding));
}
/* set and get template1 database encoding */
static int templateEncoding;
void SetTemplateEncoding(int encoding)
{
templateEncoding = encoding;
}
int GetTemplateEncoding()
{
return(templateEncoding);
}

View File

@@ -1,6 +1,6 @@
/*
* testing of utf2wchar()
* $Id: utftest.c,v 1.1 1998/03/15 07:38:37 scrappy Exp $
* $Id: utftest.c,v 1.1 1998/07/24 03:31:57 scrappy Exp $
*/
#include <regex/regex.h>
#include <regex/utils.h>

View File

@@ -0,0 +1,73 @@
/*
* This file contains some public functions
* related to show/set/reset variable commands.
* Tatsuo Ishii
* $Id: variable.c,v 1.1 1998/07/24 03:31:57 scrappy Exp $
*/
#include "mb/pg_wchar.h"
bool
parse_client_encoding(const char *value)
{
int encoding;
encoding = pg_valid_client_encoding(value);
if (encoding < 0) {
elog(ERROR, "Client encoding %s is not supported", value);
} else {
if (pg_set_client_encoding(encoding)) {
elog(ERROR, "Conversion between %s and %s is not supported",
value, pg_encoding_to_char(GetDatabaseEncoding()));
}
}
return TRUE;
}
bool
show_client_encoding()
{
elog(NOTICE, "Current client encoding is %s",
pg_encoding_to_char(pg_get_client_encoding()));
return TRUE;
}
bool
reset_client_encoding()
{
int encoding;
char *env = getenv("PGCLIENTENCODING");
if (env) {
encoding = pg_char_to_encoding(env);
if (encoding < 0) {
encoding = GetDatabaseEncoding();
}
} else {
encoding = GetDatabaseEncoding();
}
pg_set_client_encoding(encoding);
return TRUE;
}
bool
parse_server_encoding(const char *value)
{
elog(NOTICE, "SET SERVER_ENCODING is not supported");
return TRUE;
}
bool
show_server_encoding()
{
elog(NOTICE, "Current server encoding is %s",
pg_encoding_to_char(GetDatabaseEncoding()));
return TRUE;
}
bool
reset_server_encoding()
{
elog(NOTICE, "RESET SERVER_ENCODING is not supported");
return TRUE;
}

View File

@@ -1,9 +1,10 @@
/*
* misc conversion functions between pg_wchar and other encodings.
* conversion functions between pg_wchar and multi-byte streams.
* Tatsuo Ishii
* $Id: utils.c,v 1.4 1998/07/18 18:34:08 momjian Exp $
* $Id: wchar.c,v 1.1 1998/07/24 03:31:57 scrappy Exp $
*/
#include <regex/pg_wchar.h>
#include "mb/pg_wchar.h"
/*
* conversion to pg_wchar is done by "table driven."
@@ -12,11 +13,6 @@
* supported in the client, you don't need to define
* mb2wchar_with_len() function (SJIS is the case).
*/
typedef struct {
void (*mb2wchar_with_len)(); /* convert a multi-byte string to a wchar */
int (*mblen)(); /* returns the length of a multi-byte word */
} pg_wchar_tbl;
static void pg_euc2wchar_with_len
(const unsigned char *from, pg_wchar *to, int len)
{
@@ -268,7 +264,7 @@ static void pg_mule2wchar_with_len(const unsigned char *from, pg_wchar *to, int
*to = 0;
}
static int pg_mule_mblen(const unsigned char *s)
int pg_mule_mblen(const unsigned char *s)
{
int len;
@@ -319,7 +315,7 @@ static int pg_sjis_mblen(const unsigned char *s)
return(len);
}
static pg_wchar_tbl pg_wchar_table[] = {
pg_wchar_tbl pg_wchar_table[] = {
{pg_eucjp2wchar_with_len, pg_eucjp_mblen},
{pg_euccn2wchar_with_len, pg_euccn_mblen},
{pg_euckr2wchar_with_len, pg_euckr_mblen},
@@ -327,6 +323,22 @@ static pg_wchar_tbl pg_wchar_table[] = {
{pg_utf2wchar_with_len, pg_utf_mblen},
{pg_mule2wchar_with_len, pg_mule_mblen},
{pg_latin12wchar_with_len, pg_latin1_mblen},
{pg_latin12wchar_with_len, pg_latin1_mblen},
{pg_latin12wchar_with_len, pg_latin1_mblen},
{pg_latin12wchar_with_len, pg_latin1_mblen},
{pg_latin12wchar_with_len, pg_latin1_mblen},
{0, 0},
{0, 0},
{0, 0},
{0, 0},
{0, 0},
{0, 0},
{0, 0},
{0, 0},
{0, 0},
{0, 0},
{0, 0},
{0, 0},
{0, 0},
{0, 0},
{0, 0},
@@ -339,66 +351,8 @@ static pg_wchar_tbl pg_wchar_table[] = {
{0, pg_sjis_mblen}
};
/*
*########################################################################
*
* Public functions
*
*########################################################################
*/
/* convert a multi-byte string to a wchar */
void pg_mb2wchar(const unsigned char *from, pg_wchar *to)
{
(*pg_wchar_table[MULTIBYTE].mb2wchar_with_len)(from,to,strlen(from));
}
/* convert a multi-byte string to a wchar with a limited length */
void pg_mb2wchar_with_len(const unsigned char *from, pg_wchar *to, int len)
{
(*pg_wchar_table[MULTIBYTE].mb2wchar_with_len)(from,to,len);
}
/* returns the byte length of a multi-byte word */
int pg_mblen(const unsigned char *mbstr)
{
return((*pg_wchar_table[MULTIBYTE].mblen)(mbstr));
}
/* returns the byte length of a multi-byte word for an encoding */
int pg_encoding_mblen(int encoding, const unsigned char *mbstr)
{
return((*pg_wchar_table[encoding].mblen)(mbstr));
}
/* returns the byte length of a word for mule internal code */
int pg_mic_mblen(const unsigned char *mbstr)
{
return(pg_mule_mblen(mbstr));
}
/* returns the length (counted as a wchar) of a multi-byte string */
int pg_mbstrlen(const unsigned char *mbstr)
{
int len = 0;
while (*mbstr) {
mbstr += pg_mblen(mbstr);
len++;
}
return(len);
}
/* returns the length (counted as a wchar) of a multi-byte string
(not necessarily NULL terminated) */
int pg_mbstrlen_with_len(const unsigned char *mbstr, int limit)
{
int len = 0;
int l;
while (*mbstr && limit > 0) {
l = pg_mblen(mbstr);
limit -= l;
mbstr += l;
len++;
}
return(len);
}

View File

@@ -34,7 +34,7 @@
* SUCH DAMAGE.
*/
#include <regex/pg_wchar.h>
#include <mb/pg_wchar.h>
int
pg_char_and_wchar_strcmp(s1, s2)

View File

@@ -33,7 +33,7 @@
* SUCH DAMAGE.
*/
#include <regex/pg_wchar.h>
#include <mb/pg_wchar.h>
int
pg_wchar_strncmp(s1, s2, n)

View File

@@ -4,7 +4,7 @@
# Makefile for utils/misc
#
# IDENTIFICATION
# $Header: /cvsroot/pgsql/src/backend/utils/misc/Makefile,v 1.6 1998/04/06 00:27:16 momjian Exp $
# $Header: /cvsroot/pgsql/src/backend/utils/misc/Makefile,v 1.7 1998/07/24 03:31:58 scrappy Exp $
#
#-------------------------------------------------------------------------
@@ -13,6 +13,10 @@ include ../../../Makefile.global
CFLAGS += -I../..
ifdef MB
CFLAGS += -DMB=$(MB)
endif
OBJS = database.o superuser.o
all: SUBSYS.o

View File

@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/misc/Attic/database.c,v 1.11 1998/07/20 16:14:18 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/misc/Attic/database.c,v 1.12 1998/07/24 03:31:59 scrappy Exp $
*
*-------------------------------------------------------------------------
*/
@@ -22,7 +22,12 @@
#include "access/heapam.h"
#include "access/xact.h"
#include "catalog/catname.h"
#ifdef MB
#include "catalog/pg_database_mb.h"
#include "mb/pg_wchar.h"
#else
#include "catalog/pg_database.h"
#endif
#include "fmgr.h"
#include "miscadmin.h"
#include "storage/bufmgr.h"
@@ -179,7 +184,11 @@ ExpandDatabasePath(char *dbpath)
* --------------------------------
*/
void
#ifdef MB
GetRawDatabaseInfo(char *name, Oid *owner, Oid *db_id, char *path, int *encoding)
#else
GetRawDatabaseInfo(char *name, Oid *owner, Oid *db_id, char *path)
#endif
{
int dbfd;
int fileflags;
@@ -273,7 +282,9 @@ GetRawDatabaseInfo(char *name, Oid *owner, Oid *db_id, char *path)
strncpy(path, VARDATA(&(tup_db->datpath)),
(VARSIZE(&(tup_db->datpath)) - VARHDRSZ));
*(path + VARSIZE(&(tup_db->datpath)) - VARHDRSZ) = '\0';
#ifdef MB
*encoding = tup_db->encoding;
#endif
goto done;
}
}