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