Avoid use of prototype-less function pointers in MB code.
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/utils/adt/format_type.c,v 1.14 2001/08/09 18:28:18 petere Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/adt/format_type.c,v 1.15 2001/09/21 15:27:38 tgl Exp $
*
*-------------------------------------------------------------------------
*/
#include "utils/builtins.h"
#include "utils/numeric.h"
#include "utils/syscache.h"
+#ifdef MULTIBYTE
+#include "mb/pg_wchar.h"
+#endif
+
#define MAX_INT32_LEN 11
#define _textin(str) DirectFunctionCall1(textin, CStringGetDatum(str))
/*
- * type_maximum_size --- determine maximum length of a varlena column
+ * type_maximum_size --- determine maximum width of a varlena column
*
- * If the max length is indeterminate, return -1. In particular, we return
+ * If the max width is indeterminate, return -1. In particular, we return
* -1 for any type not known to this routine. We assume the caller has
* already determined that the type is a varlena type, so it's not
* necessary to look up the type's pg_type tuple here.
case BPCHAROID:
case VARCHAROID:
/* typemod includes varlena header */
+#ifdef MULTIBYTE
+ /* typemod is in characters not bytes */
+ return (typemod - VARHDRSZ) *
+ pg_encoding_max_length(GetDatabaseEncoding())
+ + VARHDRSZ;
+#else
return typemod;
+#endif
case NUMERICOID:
/* precision (ie, max # of digits) is in upper bits of typmod */
+ 2 * sizeof(int32);
}
- /* Unknown type, or unlimited-length type such as 'text' */
+ /* Unknown type, or unlimited-width type such as 'text' */
return -1;
}
* client encoding and server internal encoding.
* (currently mule internal code (mic) is used)
* Tatsuo Ishii
- * $Id: mbutils.c,v 1.22 2001/09/09 01:15:11 ishii Exp $
+ * $Id: mbutils.c,v 1.23 2001/09/21 15:27:38 tgl Exp $
*/
#include "postgres.h"
static pg_enc2name *ClientEncoding = &pg_enc2name_tbl[ PG_SQL_ASCII ];
static pg_enc2name *DatabaseEncoding = &pg_enc2name_tbl[ PG_SQL_ASCII ];
-static void (*client_to_mic) (); /* something to MIC */
-static void (*client_from_mic) (); /* MIC to something */
-static void (*server_to_mic) (); /* something to MIC */
-static void (*server_from_mic) (); /* MIC to something */
+static to_mic_converter client_to_mic; /* something to MIC */
+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 */
/*
* find encoding table entry by encoding
* appropriate function found, set to 0.
*/
int
-pg_find_encoding_converters(int src, int dest, void (**src_to_mic)(), void (**dest_from_mic)())
+pg_find_encoding_converters(int src, int dest,
+ to_mic_converter *src_to_mic,
+ from_mic_converter *dest_from_mic)
{
if (src == dest)
{ /* src == dest? */
* returns the current client encoding
*/
int
-pg_get_client_encoding()
+pg_get_client_encoding(void)
{
Assert(ClientEncoding);
return (ClientEncoding->encoding);
* returns the current client encoding name
*/
const char *
-pg_get_client_encoding_name()
+pg_get_client_encoding_name(void)
{
Assert(ClientEncoding);
return (ClientEncoding->name);
* in the length of the string --- is this enough? */
unsigned char *
-pg_do_encoding_conversion(unsigned char *src, int len, void (*src_to_mic)(), void (*dest_from_mic)())
+pg_do_encoding_conversion(unsigned char *src, int len,
+ to_mic_converter src_to_mic,
+ from_mic_converter dest_from_mic)
{
unsigned char *result = src;
unsigned char *buf;
Name s = PG_GETARG_NAME(1);
int encoding = pg_char_to_encoding(NameStr(*s));
int db_encoding = DatabaseEncoding->encoding;
- void (*src)(), (*dest)();
+ to_mic_converter src;
+ from_mic_converter dest;
unsigned char *result;
text *retval;
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);
- void (*src)(), (*dest)();
+ to_mic_converter src;
+ from_mic_converter dest;
unsigned char *result;
text *retval;
}
int
-GetDatabaseEncoding()
+GetDatabaseEncoding(void)
{
Assert(DatabaseEncoding);
return (DatabaseEncoding->encoding);
}
const char *
-GetDatabaseEncodingName()
+GetDatabaseEncodingName(void)
{
Assert(DatabaseEncoding);
return (DatabaseEncoding->name);
/*
* conversion functions between pg_wchar and multi-byte streams.
* Tatsuo Ishii
- * $Id: wchar.c,v 1.20 2001/09/11 04:50:36 ishii Exp $
+ * $Id: wchar.c,v 1.21 2001/09/21 15:27:38 tgl Exp $
*
* WIN1250 client encoding updated by Pavel Behal
*
*/
/* can be used in either frontend or backend */
-#include "postgres_fe.h"
-#include "mb/pg_wchar.h"
-
#ifdef FRONTEND
- #define Assert(condition)
+#include "postgres_fe.h"
+#define Assert(condition)
#else
- #include "postgres.h"
+#include "postgres.h"
#endif
+#include "mb/pg_wchar.h"
+
/*
* conversion to pg_wchar is done by "table driven."
((*pg_wchar_table[PG_SQL_ASCII].mblen) (mbstr)));
}
+/*
+ * fetch maximum length of a char encoding
+ */
+int
+pg_encoding_max_length(int encoding)
+{
+ Assert(PG_VALID_ENCODING(encoding));
+
+ return pg_wchar_table[encoding].maxmblen;
+}
+
#ifndef FRONTEND
/*
* Verify mbstr to make sure that it has a valid character sequence.
int slen = 0;
/* we do not check single byte encodings */
- if (pg_wchar_table[GetDatabaseEncoding()].maxmblen <= 1)
+ if (pg_encoding_max_length(GetDatabaseEncoding()) <= 1)
return NULL;
while (len > 0 && *mbstr)
-/* $Id: pg_wchar.h,v 1.30 2001/09/11 04:50:36 ishii Exp $ */
+/* $Id: pg_wchar.h,v 1.31 2001/09/21 15:27:38 tgl Exp $ */
#ifndef PG_WCHAR_H
#define PG_WCHAR_H
*/
#ifdef MULTIBYTE
typedef unsigned int pg_wchar;
-
#else
#define pg_wchar char
#endif
extern int pg_char_to_encoding(const char *s);
extern const char *pg_encoding_to_char(int encoding);
+typedef void (*to_mic_converter) (unsigned char *l, unsigned char *p, int len);
+typedef void (*from_mic_converter) (unsigned char *mic, unsigned char *p, int len);
+
/*
* The backend encoding conversion routines
* Careful:
#ifndef FRONTEND
typedef struct pg_enconv
{
- pg_enc encoding; /* encoding identificator */
- void (*to_mic) (); /* client encoding to MIC */
- void (*from_mic) (); /* MIC to client encoding */
- void (*to_unicode) (); /* client encoding to UTF-8 */
- void (*from_unicode) (); /* UTF-8 to client encoding */
+ pg_enc encoding; /* encoding identifier */
+ to_mic_converter to_mic; /* client encoding to MIC */
+ from_mic_converter from_mic; /* MIC to client encoding */
+ to_mic_converter to_unicode; /* client encoding to UTF-8 */
+ from_mic_converter from_unicode; /* UTF-8 to client encoding */
} pg_enconv;
extern pg_enconv pg_enconv_tbl[];
/*
* pg_wchar stuff
*/
+typedef int (*mb2wchar_with_len_converter) (const unsigned char *from,
+ pg_wchar *to,
+ int len);
+typedef int (*mblen_converter) (const unsigned char *mbstr);
+
typedef struct
{
- int (*mb2wchar_with_len) (); /* convert a multi-byte
- * string to a wchar */
- int (*mblen) (); /* returns the length of a multi-byte word */
- int maxmblen; /* max bytes for a letter in this charset */
-
+ mb2wchar_with_len_converter mb2wchar_with_len; /* convert a multi-byte string to a wchar */
+ mblen_converter mblen; /* returns the length of a multi-byte char */
+ int maxmblen; /* max bytes for a char in this charset */
} pg_wchar_tbl;
extern pg_wchar_tbl pg_wchar_table[];
extern int pg_mbstrlen_with_len(const unsigned char *, int);
extern int pg_mbcliplen(const unsigned char *, int, int);
extern int pg_mbcharcliplen(const unsigned char *, int, int);
+extern int pg_encoding_max_length(int);
extern int pg_set_client_encoding(int);
extern int pg_get_client_encoding(void);
extern int pg_valid_server_encoding(const char *name);
extern int pg_utf_mblen(const unsigned char *);
-extern int pg_find_encoding_converters(int, int, void (**)(), void (**)());
-extern unsigned char *pg_do_encoding_conversion(unsigned char *, int, void (*)(), void (*)());
+extern int pg_find_encoding_converters(int src, int dest,
+ to_mic_converter *src_to_mic,
+ from_mic_converter *dest_from_mic);
+extern unsigned char *pg_do_encoding_conversion(unsigned char *src, int len,
+ to_mic_converter src_to_mic,
+ from_mic_converter dest_from_mic);
extern unsigned char *pg_client_to_server(unsigned char *, int);
extern unsigned char *pg_server_to_client(unsigned char *, int);