Commit 969e0246 authored by Tatsuo Ishii's avatar Tatsuo Ishii

Add Cyrillic and other encodings for encoding conversion.

Patches submitted by Kaori Inaba (i-kaori@sra.co.jp).
parent d3bd1a00
<!-- $Header: /cvsroot/pgsql/doc/src/sgml/charset.sgml,v 2.26 2002/08/08 08:21:52 ishii Exp $ --> <!-- $Header: /cvsroot/pgsql/doc/src/sgml/charset.sgml,v 2.27 2002/08/14 02:45:09 ishii Exp $ -->
<chapter id="charset"> <chapter id="charset">
<title>Localization</> <title>Localization</>
...@@ -649,8 +649,7 @@ $ <userinput>psql -l</userinput> ...@@ -649,8 +649,7 @@ $ <userinput>psql -l</userinput>
</row> </row>
<row> <row>
<entry><literal>LATIN5</literal></entry> <entry><literal>LATIN5</literal></entry>
<entry><literal>LATIN5</literal>, <literal>UNICODE</literal>, <entry><literal>LATIN5</literal>, <literal>UNICODE</literal>
<literal>MULE_INTERNAL</literal>
</entry> </entry>
</row> </row>
<row> <row>
...@@ -687,6 +686,7 @@ $ <userinput>psql -l</userinput> ...@@ -687,6 +686,7 @@ $ <userinput>psql -l</userinput>
<entry><literal>ISO_8859_5</literal></entry> <entry><literal>ISO_8859_5</literal></entry>
<entry><literal>ISO_8859_5</literal>, <entry><literal>ISO_8859_5</literal>,
<literal>UNICODE</literal>, <literal>UNICODE</literal>,
<literal>MULE_INTERNAL</literal>,
<literal>WIN</literal>, <literal>WIN</literal>,
<literal>ALT</literal>, <literal>ALT</literal>,
<literal>KOI8</literal> <literal>KOI8</literal>
...@@ -727,13 +727,17 @@ $ <userinput>psql -l</userinput> ...@@ -727,13 +727,17 @@ $ <userinput>psql -l</userinput>
<literal>WIN1256</literal>, <literal>WIN1256</literal>,
<literal>TCVN</literal>, <literal>TCVN</literal>,
<literal>WIN874</literal>, <literal>WIN874</literal>,
<literal>GB18030</literal>,
<literal>WIN1250</literal>
</entry> </entry>
</row> </row>
<row> <row>
<entry><literal>MULE_INTERNAL</literal></entry> <entry><literal>MULE_INTERNAL</literal></entry>
<entry><literal>EUC_JP</literal>, <literal>SJIS</literal>, <literal>EUC_KR</literal>, <literal>EUC_CN</literal>, <entry><literal>EUC_JP</literal>, <literal>SJIS</literal>, <literal>EUC_KR</literal>, <literal>EUC_CN</literal>,
<literal>EUC_TW</literal>, <literal>BIG5</literal>, <literal>LATIN1</literal> to <literal>LATIN5</literal>, <literal>EUC_TW</literal>, <literal>BIG5</literal>, <literal>LATIN1</literal> to <literal>LATIN5</literal>,
<literal>WIN</literal>, <literal>ALT</literal>, <literal>WIN1250</literal></entry> <literal>WIN</literal>, <literal>ALT</literal>,
<literal>WIN1250</literal>,
<literal>BIG5</literal>, <literal>ISO_8859_5</literal>, <literal>KOI8</literal></entry>
</row> </row>
<row> <row>
<entry><literal>KOI8</literal></entry> <entry><literal>KOI8</literal></entry>
......
This diff is collapsed.
This diff is collapsed.
#-------------------------------------------------------------------------
#
# $Id: Makefile,v 1.1 2002/08/14 02:45:10 ishii Exp $
#
#-------------------------------------------------------------------------
top_builddir = ../../../../../..
include $(top_builddir)/src/Makefile.global
NAME := ascii_and_mic
include ../proc.mk
/*-------------------------------------------------------------------------
*
* ASCII and MULE_INTERNAL
*
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/mb/conversion_procs/ascii_and_mic/ascii_and_mic.c,v 1.1 2002/08/14 02:45:10 ishii Exp $
*
*-------------------------------------------------------------------------
*/
#include "postgres.h"
#include "fmgr.h"
#include "mb/pg_wchar.h"
PG_FUNCTION_INFO_V1(ascii_to_mic)
PG_FUNCTION_INFO_V1(mic_to_ascii)
extern Datum ascii_to_mic(PG_FUNCTION_ARGS);
extern Datum mic_to_ascii(PG_FUNCTION_ARGS);
/* ----------
* conv_proc(
* INTEGER, -- source encoding id
* INTEGER, -- destination encoding id
* OPAQUE, -- source string (null terminated C string)
* OPAQUE, -- destination string (null terminated C string)
* INTEGER -- source string length
* ) returns INTEGER; -- dummy. returns nothing, actually.
* ----------
*/
Datum
ascii_to_mic(PG_FUNCTION_ARGS)
{
unsigned char *src = PG_GETARG_CSTRING(2);
unsigned char *dest = PG_GETARG_CSTRING(3);
int len = PG_GETARG_INT32(4);
Assert(PG_GETARG_INT32(0) == PG_SQL_ASCII);
Assert(PG_GETARG_INT32(1) == PG_MULE_INTERNAL);
Assert(len > 0);
pg_ascii2mic(src, dest, len);
PG_RETURN_INT32(0);
}
Datum
mic_to_ascii(PG_FUNCTION_ARGS)
{
unsigned char *src = PG_GETARG_CSTRING(2);
unsigned char *dest = PG_GETARG_CSTRING(3);
int len = PG_GETARG_INT32(4);
Assert(PG_GETARG_INT32(0) == PG_MULE_INTERNAL);
Assert(PG_GETARG_INT32(1) == PG_SQL_ASCII);
Assert(len > 0);
pg_mic2ascii(src, dest, len);
PG_RETURN_INT32(0);
}
#-------------------------------------------------------------------------
#
# $Id: Makefile,v 1.1 2002/08/14 02:45:10 ishii Exp $
#
#-------------------------------------------------------------------------
top_builddir = ../../../../../..
include $(top_builddir)/src/Makefile.global
NAME := cyrillic_and_mic
include ../proc.mk
#-------------------------------------------------------------------------
#
# $Id: Makefile,v 1.1 2002/08/14 02:45:10 ishii Exp $
#
#-------------------------------------------------------------------------
top_builddir = ../../../../../..
include $(top_builddir)/src/Makefile.global
NAME := euc_cn_and_mic
include ../proc.mk
/*-------------------------------------------------------------------------
*
* EUC_CN and MULE_INTERNAL
*
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/mb/conversion_procs/euc_cn_and_mic/euc_cn_and_mic.c,v 1.1 2002/08/14 02:45:10 ishii Exp $
*
*-------------------------------------------------------------------------
*/
#include "postgres.h"
#include "fmgr.h"
#include "mb/pg_wchar.h"
PG_FUNCTION_INFO_V1(euc_cn_to_mic)
PG_FUNCTION_INFO_V1(mic_to_euc_cn)
extern Datum euc_cn_to_mic(PG_FUNCTION_ARGS);
extern Datum mic_to_euc_cn(PG_FUNCTION_ARGS);
/* ----------
* conv_proc(
* INTEGER, -- source encoding id
* INTEGER, -- destination encoding id
* OPAQUE, -- source string (null terminated C string)
* OPAQUE, -- destination string (null terminated C string)
* INTEGER -- source string length
* ) returns INTEGER; -- dummy. returns nothing, actually.
* ----------
*/
static void euc_cn2mic(unsigned char *euc, unsigned char *p, int len);
static void mic2euc_cn(unsigned char *mic, unsigned char *p, int len);
Datum
euc_cn_to_mic(PG_FUNCTION_ARGS)
{
unsigned char *src = PG_GETARG_CSTRING(2);
unsigned char *dest = PG_GETARG_CSTRING(3);
int len = PG_GETARG_INT32(4);
Assert(PG_GETARG_INT32(0) == PG_EUC_CN);
Assert(PG_GETARG_INT32(1) == PG_MULE_INTERNAL);
Assert(len > 0);
euc_cn2mic(src, dest, len);
PG_RETURN_INT32(0);
}
Datum
mic_to_euc_cn(PG_FUNCTION_ARGS)
{
unsigned char *src = PG_GETARG_CSTRING(2);
unsigned char *dest = PG_GETARG_CSTRING(3);
int len = PG_GETARG_INT32(4);
Assert(PG_GETARG_INT32(0) == PG_MULE_INTERNAL);
Assert(PG_GETARG_INT32(1) == PG_EUC_CN);
Assert(len > 0);
mic2euc_cn(src, dest, len);
PG_RETURN_INT32(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--;
pg_print_bogus_char(&mic, &p);
}
else
{ /* should be ASCII */
*p++ = c1;
}
}
*p = '\0';
}
#-------------------------------------------------------------------------
#
# $Id: Makefile,v 1.1 2002/08/14 02:45:10 ishii Exp $
#
#-------------------------------------------------------------------------
top_builddir = ../../../../../..
include $(top_builddir)/src/Makefile.global
NAME := euc_kr_and_mic
include ../proc.mk
/*-------------------------------------------------------------------------
*
* EUC_KR and MULE_INTERNAL
*
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/mb/conversion_procs/euc_kr_and_mic/euc_kr_and_mic.c,v 1.1 2002/08/14 02:45:10 ishii Exp $
*
*-------------------------------------------------------------------------
*/
#include "postgres.h"
#include "fmgr.h"
#include "mb/pg_wchar.h"
PG_FUNCTION_INFO_V1(euc_kr_to_mic)
PG_FUNCTION_INFO_V1(mic_to_euc_kr)
extern Datum euc_kr_to_mic(PG_FUNCTION_ARGS);
extern Datum mic_to_euc_kr(PG_FUNCTION_ARGS);
/* ----------
* conv_proc(
* INTEGER, -- source encoding id
* INTEGER, -- destination encoding id
* OPAQUE, -- source string (null terminated C string)
* OPAQUE, -- destination string (null terminated C string)
* INTEGER -- source string length
* ) returns INTEGER; -- dummy. returns nothing, actually.
* ----------
*/
static void euc_kr2mic(unsigned char *euc, unsigned char *p, int len);
static void mic2euc_kr(unsigned char *mic, unsigned char *p, int len);
Datum
euc_kr_to_mic(PG_FUNCTION_ARGS)
{
unsigned char *src = PG_GETARG_CSTRING(2);
unsigned char *dest = PG_GETARG_CSTRING(3);
int len = PG_GETARG_INT32(4);
Assert(PG_GETARG_INT32(0) == PG_EUC_KR);
Assert(PG_GETARG_INT32(1) == PG_MULE_INTERNAL);
Assert(len > 0);
euc_kr2mic(src, dest, len);
PG_RETURN_INT32(0);
}
Datum
mic_to_euc_kr(PG_FUNCTION_ARGS)
{
unsigned char *src = PG_GETARG_CSTRING(2);
unsigned char *dest = PG_GETARG_CSTRING(3);
int len = PG_GETARG_INT32(4);
Assert(PG_GETARG_INT32(0) == PG_MULE_INTERNAL);
Assert(PG_GETARG_INT32(1) == PG_EUC_KR);
Assert(len > 0);
mic2euc_kr(src, dest, len);
PG_RETURN_INT32(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--;
pg_print_bogus_char(&mic, &p);
}
else
{ /* should be ASCII */
*p++ = c1;
}
}
*p = '\0';
}
#-------------------------------------------------------------------------
#
# $Id: Makefile,v 1.1 2002/08/14 02:45:10 ishii Exp $
#
#-------------------------------------------------------------------------
top_builddir = ../../../../../..
include $(top_builddir)/src/Makefile.global
NAME := latin2_and_win1250
include ../proc.mk
/*-------------------------------------------------------------------------
*
* LATIN2 and WIN1250
*
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/mb/conversion_procs/latin2_and_win1250/latin2_and_win1250.c,v 1.1 2002/08/14 02:45:10 ishii Exp $
*
*-------------------------------------------------------------------------
*/
#include "postgres.h"
#include "fmgr.h"
#include "mb/pg_wchar.h"
#define ENCODING_GROWTH_RATE 4
PG_FUNCTION_INFO_V1(latin2_to_mic)
PG_FUNCTION_INFO_V1(mic_to_latin2)
PG_FUNCTION_INFO_V1(win1250_to_mic)
PG_FUNCTION_INFO_V1(mic_to_win1250)
PG_FUNCTION_INFO_V1(latin2_to_win1250)
PG_FUNCTION_INFO_V1(win1250_to_latin2)
extern Datum latin2_to_mic(PG_FUNCTION_ARGS);
extern Datum mic_to_latin2(PG_FUNCTION_ARGS);
extern Datum win1250_to_mic(PG_FUNCTION_ARGS);
extern Datum mic_to_win1250(PG_FUNCTION_ARGS);
extern Datum latin2_to_win1250(PG_FUNCTION_ARGS);
extern Datum win1250_to_latin2(PG_FUNCTION_ARGS);
/* ----------
* conv_proc(
* INTEGER, -- source encoding id
* INTEGER, -- destination encoding id
* OPAQUE, -- source string (null terminated C string)
* OPAQUE, -- destination string (null terminated C string)
* INTEGER -- source string length
* ) returns INTEGER; -- dummy. returns nothing, actually.
* ----------
*/
static void latin22mic(unsigned char *l, unsigned char *p, int len);
static void mic2latin2(unsigned char *mic, unsigned char *p, int len);
static void win12502mic(unsigned char *l, unsigned char *p, int len);
static void mic2win1250(unsigned char *mic, unsigned char *p, int len);
Datum
latin2_to_mic(PG_FUNCTION_ARGS)
{
unsigned char *src = PG_GETARG_CSTRING(2);
unsigned char *dest = PG_GETARG_CSTRING(3);
int len = PG_GETARG_INT32(4);
Assert(PG_GETARG_INT32(0) == PG_LATIN2);
Assert(PG_GETARG_INT32(1) == PG_MULE_INTERNAL);
Assert(len > 0);
latin22mic(src, dest, len);
PG_RETURN_INT32(0);
}
Datum
mic_to_latin2(PG_FUNCTION_ARGS)
{
unsigned char *src = PG_GETARG_CSTRING(2);
unsigned char *dest = PG_GETARG_CSTRING(3);
int len = PG_GETARG_INT32(4);
Assert(PG_GETARG_INT32(0) == PG_MULE_INTERNAL);
Assert(PG_GETARG_INT32(1) == PG_LATIN2);
Assert(len > 0);
mic2latin2(src, dest, len);
PG_RETURN_INT32(0);
}
Datum
win1250_to_mic(PG_FUNCTION_ARGS)
{
unsigned char *src = PG_GETARG_CSTRING(2);
unsigned char *dest = PG_GETARG_CSTRING(3);
int len = PG_GETARG_INT32(4);
Assert(PG_GETARG_INT32(0) == PG_WIN1250);
Assert(PG_GETARG_INT32(1) == PG_MULE_INTERNAL);
Assert(len > 0);
win12502mic(src, dest, len);
PG_RETURN_INT32(0);
}
Datum
mic_to_win1250(PG_FUNCTION_ARGS)
{
unsigned char *src = PG_GETARG_CSTRING(2);
unsigned char *dest = PG_GETARG_CSTRING(3);
int len = PG_GETARG_INT32(4);
Assert(PG_GETARG_INT32(0) == PG_MULE_INTERNAL);
Assert(PG_GETARG_INT32(1) == PG_WIN1250);
Assert(len > 0);
mic2win1250(src, dest, len);
PG_RETURN_INT32(0);
}
Datum
latin2_to_win1250(PG_FUNCTION_ARGS)
{
unsigned char *src = PG_GETARG_CSTRING(2);
unsigned char *dest = PG_GETARG_CSTRING(3);
int len = PG_GETARG_INT32(4);
unsigned char *buf;
Assert(PG_GETARG_INT32(0) == PG_LATIN2);
Assert(PG_GETARG_INT32(1) == PG_WIN1250);
Assert(len > 0);
buf = palloc(len * ENCODING_GROWTH_RATE);
latin22mic(src, buf, len);
mic2win1250(buf, dest, strlen(buf));
pfree(buf);
PG_RETURN_INT32(0);
}
Datum
win1250_to_latin2(PG_FUNCTION_ARGS)
{
unsigned char *src = PG_GETARG_CSTRING(2);
unsigned char *dest = PG_GETARG_CSTRING(3);
int len = PG_GETARG_INT32(4);
unsigned char *buf;
Assert(PG_GETARG_INT32(0) == PG_WIN1250);
Assert(PG_GETARG_INT32(1) == PG_LATIN2);
Assert(len > 0);
buf = palloc(len * ENCODING_GROWTH_RATE);
win12502mic(src, buf, len);
mic2latin2(buf, dest, strlen(buf));
pfree(buf);
PG_RETURN_INT32(0);
}
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);
}
/*-----------------------------------------------------------------
* WIN1250
* Microsoft's CP1250(windows-1250)
*-----------------------------------------------------------------*/
static void
win12502mic(unsigned char *l, unsigned char *p, int len)
{
static unsigned char win1250_2_iso88592[] = {
0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
0x88, 0x89, 0xA9, 0x8B, 0xA6, 0xAB, 0xAE, 0xAC,
0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,
0x98, 0x99, 0xB9, 0x9B, 0xB6, 0xBB, 0xBE, 0xBC,
0xA0, 0xB7, 0xA2, 0xA3, 0xA4, 0xA1, 0x00, 0xA7,
0xA8, 0x00, 0xAA, 0x00, 0x00, 0xAD, 0x00, 0xAF,
0xB0, 0x00, 0xB2, 0xB3, 0xB4, 0x00, 0x00, 0x00,
0xB8, 0xB1, 0xBA, 0x00, 0xA5, 0xBD, 0xB5, 0xBF,
0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7,
0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF,
0xD0, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7,
0xD8, 0xD9, 0xDA, 0xDB, 0xDC, 0xDD, 0xDE, 0xDF,
0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7,
0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF,
0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7,
0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xFF
};
latin2mic_with_table(l, p, len, LC_ISO8859_2, win1250_2_iso88592);
}
static void
mic2win1250(unsigned char *mic, unsigned char *p, int len)
{
static unsigned char iso88592_2_win1250[] = {
0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
0x88, 0x89, 0x00, 0x8B, 0x00, 0x00, 0x00, 0x00,
0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,
0x98, 0x99, 0x00, 0x9B, 0x00, 0x00, 0x00, 0x00,
0xA0, 0xA5, 0xA2, 0xA3, 0xA4, 0xBC, 0x8C, 0xA7,
0xA8, 0x8A, 0xAA, 0x8D, 0x8F, 0xAD, 0x8E, 0xAF,
0xB0, 0xB9, 0xB2, 0xB3, 0xB4, 0xBE, 0x9C, 0xA1,
0xB8, 0x9A, 0xBA, 0x9D, 0x9F, 0xBD, 0x9E, 0xBF,
0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7,
0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF,
0xD0, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7,
0xD8, 0xD9, 0xDA, 0xDB, 0xDC, 0xDD, 0xDE, 0xDF,
0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7,
0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF,
0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7,
0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xFF
};
mic2latin_with_table(mic, p, len, LC_ISO8859_2, iso88592_2_win1250);
}
#-------------------------------------------------------------------------
#
# $Id: Makefile,v 1.1 2002/08/14 02:45:10 ishii Exp $
#
#-------------------------------------------------------------------------
top_builddir = ../../../../../..
include $(top_builddir)/src/Makefile.global
NAME := latin_and_mic
include ../proc.mk
/*-------------------------------------------------------------------------
*
* LATINn and MULE_INTERNAL
*
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/mb/conversion_procs/latin_and_mic/latin_and_mic.c,v 1.1 2002/08/14 02:45:10 ishii Exp $
*
*-------------------------------------------------------------------------
*/
#include "postgres.h"
#include "fmgr.h"
#include "mb/pg_wchar.h"
PG_FUNCTION_INFO_V1(latin1_to_mic)
PG_FUNCTION_INFO_V1(mic_to_latin1)
PG_FUNCTION_INFO_V1(latin3_to_mic)
PG_FUNCTION_INFO_V1(mic_to_latin3)
PG_FUNCTION_INFO_V1(latin4_to_mic)
PG_FUNCTION_INFO_V1(mic_to_latin4)
extern Datum latin1_to_mic(PG_FUNCTION_ARGS);
extern Datum mic_to_latin1(PG_FUNCTION_ARGS);
extern Datum latin3_to_mic(PG_FUNCTION_ARGS);
extern Datum mic_to_latin3(PG_FUNCTION_ARGS);
extern Datum latin4_to_mic(PG_FUNCTION_ARGS);
extern Datum mic_to_latin4(PG_FUNCTION_ARGS);
/* ----------
* conv_proc(
* INTEGER, -- source encoding id
* INTEGER, -- destination encoding id
* OPAQUE, -- source string (null terminated C string)
* OPAQUE, -- destination string (null terminated C string)
* INTEGER -- source string length
* ) returns INTEGER; -- dummy. returns nothing, actually.
* ----------
*/
static void latin12mic(unsigned char *l, unsigned char *p, int len);
static void mic2latin1(unsigned char *mic, unsigned char *p, int len);
static void latin32mic(unsigned char *l, unsigned char *p, int len);
static void mic2latin3(unsigned char *mic, unsigned char *p, int len);
static void latin42mic(unsigned char *l, unsigned char *p, int len);
static void mic2latin4(unsigned char *mic, unsigned char *p, int len);
Datum
latin1_to_mic(PG_FUNCTION_ARGS)
{
unsigned char *src = PG_GETARG_CSTRING(2);
unsigned char *dest = PG_GETARG_CSTRING(3);
int len = PG_GETARG_INT32(4);
Assert(PG_GETARG_INT32(0) == PG_LATIN1);
Assert(PG_GETARG_INT32(1) == PG_MULE_INTERNAL);
Assert(len > 0);
latin12mic(src, dest, len);
PG_RETURN_INT32(0);
}
Datum
mic_to_latin1(PG_FUNCTION_ARGS)
{
unsigned char *src = PG_GETARG_CSTRING(2);
unsigned char *dest = PG_GETARG_CSTRING(3);
int len = PG_GETARG_INT32(4);
Assert(PG_GETARG_INT32(0) == PG_MULE_INTERNAL);
Assert(PG_GETARG_INT32(1) == PG_LATIN1);
Assert(len > 0);
mic2latin1(src, dest, len);
PG_RETURN_INT32(0);
}
Datum
latin3_to_mic(PG_FUNCTION_ARGS)
{
unsigned char *src = PG_GETARG_CSTRING(2);
unsigned char *dest = PG_GETARG_CSTRING(3);
int len = PG_GETARG_INT32(4);
Assert(PG_GETARG_INT32(0) == PG_LATIN3);
Assert(PG_GETARG_INT32(1) == PG_MULE_INTERNAL);
Assert(len > 0);
latin32mic(src, dest, len);
PG_RETURN_INT32(0);
}
Datum
mic_to_latin3(PG_FUNCTION_ARGS)
{
unsigned char *src = PG_GETARG_CSTRING(2);
unsigned char *dest = PG_GETARG_CSTRING(3);
int len = PG_GETARG_INT32(4);
Assert(PG_GETARG_INT32(0) == PG_MULE_INTERNAL);
Assert(PG_GETARG_INT32(1) == PG_LATIN3);
Assert(len > 0);
mic2latin3(src, dest, len);
PG_RETURN_INT32(0);
}
Datum
latin4_to_mic(PG_FUNCTION_ARGS)
{
unsigned char *src = PG_GETARG_CSTRING(2);
unsigned char *dest = PG_GETARG_CSTRING(3);
int len = PG_GETARG_INT32(4);
Assert(PG_GETARG_INT32(0) == PG_LATIN4);
Assert(PG_GETARG_INT32(1) == PG_MULE_INTERNAL);
Assert(len > 0);
latin42mic(src, dest, len);
PG_RETURN_INT32(0);
}
Datum mic_to_latin4(PG_FUNCTION_ARGS)
{
unsigned char *src = PG_GETARG_CSTRING(2);
unsigned char *dest = PG_GETARG_CSTRING(3);
int len = PG_GETARG_INT32(4);
Assert(PG_GETARG_INT32(0) == PG_MULE_INTERNAL);
Assert(PG_GETARG_INT32(1) == PG_LATIN4);
Assert(len > 0);
mic2latin4(src, dest, len);
PG_RETURN_INT32(0);
}
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
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);
}
#-------------------------------------------------------------------------
#
# $Id: Makefile,v 1.1 2002/08/14 02:45:10 ishii Exp $
#
#-------------------------------------------------------------------------
top_builddir = ../../../../../..
include $(top_builddir)/src/Makefile.global
NAME := utf8_and_cyrillic
include ../proc.mk
/*-------------------------------------------------------------------------
*
* UTF8 and Cyrillic
*
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/mb/conversion_procs/utf8_and_cyrillic/utf8_and_cyrillic.c,v 1.1 2002/08/14 02:45:10 ishii Exp $
*
*-------------------------------------------------------------------------
*/
#include "postgres.h"
#include "fmgr.h"
#include "mb/pg_wchar.h"
#include "../../Unicode/utf8_to_koi8r.map"
#include "../../Unicode/koi8r_to_utf8.map"
#include "../../Unicode/utf8_to_win1251.map"
#include "../../Unicode/win1251_to_utf8.map"
#include "../../Unicode/utf8_to_alt.map"
#include "../../Unicode/alt_to_utf8.map"
PG_FUNCTION_INFO_V1(utf8_to_koi8r)
PG_FUNCTION_INFO_V1(koi8r_to_utf8)
PG_FUNCTION_INFO_V1(utf8_to_win1251)
PG_FUNCTION_INFO_V1(win1251_to_utf8)
PG_FUNCTION_INFO_V1(utf8_to_alt)
PG_FUNCTION_INFO_V1(alt_to_utf8)
extern Datum utf8_to_koi8r(PG_FUNCTION_ARGS);
extern Datum koi8r_to_utf8(PG_FUNCTION_ARGS);
extern Datum utf8_to_win1251(PG_FUNCTION_ARGS);
extern Datum win1251_to_utf8(PG_FUNCTION_ARGS);
extern Datum utf8_to_alt(PG_FUNCTION_ARGS);
extern Datum alt_to_utf8(PG_FUNCTION_ARGS);
/* ----------
* conv_proc(
* INTEGER, -- source encoding id
* INTEGER, -- destination encoding id
* OPAQUE, -- source string (null terminated C string)
* OPAQUE, -- destination string (null terminated C string)
* INTEGER -- source string length
* ) returns INTEGER; -- dummy. returns nothing, actually.
* ----------
*/
Datum
utf8_to_koi8r(PG_FUNCTION_ARGS)
{
unsigned char *src = PG_GETARG_CSTRING(2);
unsigned char *dest = PG_GETARG_CSTRING(3);
int len = PG_GETARG_INT32(4);
Assert(PG_GETARG_INT32(0) == PG_UTF8);
Assert(PG_GETARG_INT32(1) == PG_KOI8R);
Assert(len > 0);
UtfToLocal(src, dest, ULmap_KOI8R,
sizeof(ULmap_KOI8R) / sizeof(pg_utf_to_local), len);
PG_RETURN_INT32(0);
}
Datum
koi8r_to_utf8(PG_FUNCTION_ARGS)
{
unsigned char *src = PG_GETARG_CSTRING(2);
unsigned char *dest = PG_GETARG_CSTRING(3);
int len = PG_GETARG_INT32(4);
Assert(PG_GETARG_INT32(0) == PG_KOI8R);
Assert(PG_GETARG_INT32(1) == PG_UTF8);
Assert(len > 0);
LocalToUtf(src, dest, LUmapKOI8R,
sizeof(LUmapKOI8R) / sizeof(pg_local_to_utf), PG_KOI8R, len);
PG_RETURN_INT32(0);
}
Datum
utf8_to_win1251(PG_FUNCTION_ARGS)
{
unsigned char *src = PG_GETARG_CSTRING(2);
unsigned char *dest = PG_GETARG_CSTRING(3);
int len = PG_GETARG_INT32(4);
Assert(PG_GETARG_INT32(0) == PG_UTF8);
Assert(PG_GETARG_INT32(1) == PG_WIN1251);
Assert(len > 0);
UtfToLocal(src, dest, ULmap_WIN1251,
sizeof(ULmap_WIN1251) / sizeof(pg_utf_to_local), len);
PG_RETURN_INT32(0);
}
Datum
win1251_to_utf8(PG_FUNCTION_ARGS)
{
unsigned char *src = PG_GETARG_CSTRING(2);
unsigned char *dest = PG_GETARG_CSTRING(3);
int len = PG_GETARG_INT32(4);
Assert(PG_GETARG_INT32(0) == PG_WIN1251);
Assert(PG_GETARG_INT32(1) == PG_UTF8);
Assert(len > 0);
LocalToUtf(src, dest, LUmapWIN1251,
sizeof(LUmapWIN1251) / sizeof(pg_local_to_utf), PG_WIN1251, len);
PG_RETURN_INT32(0);
}
Datum
utf8_to_alt(PG_FUNCTION_ARGS)
{
unsigned char *src = PG_GETARG_CSTRING(2);
unsigned char *dest = PG_GETARG_CSTRING(3);
int len = PG_GETARG_INT32(4);
Assert(PG_GETARG_INT32(0) == PG_UTF8);
Assert(PG_GETARG_INT32(1) == PG_ALT);
Assert(len > 0);
UtfToLocal(src, dest, ULmap_ALT,
sizeof(ULmap_ALT) / sizeof(pg_utf_to_local), len);
PG_RETURN_INT32(0);
}
Datum
alt_to_utf8(PG_FUNCTION_ARGS)
{
unsigned char *src = PG_GETARG_CSTRING(2);
unsigned char *dest = PG_GETARG_CSTRING(3);
int len = PG_GETARG_INT32(4);
Assert(PG_GETARG_INT32(0) == PG_ALT);
Assert(PG_GETARG_INT32(1) == PG_UTF8);
Assert(len > 0);
LocalToUtf(src, dest, LUmapALT,
sizeof(LUmapALT) / sizeof(pg_local_to_utf), PG_ALT, len);
PG_RETURN_INT32(0);
}
#-------------------------------------------------------------------------
#
# $Id: Makefile,v 1.1 2002/08/14 02:45:10 ishii Exp $
#
#-------------------------------------------------------------------------
top_builddir = ../../../../../..
include $(top_builddir)/src/Makefile.global
NAME := utf8_and_win1250
include ../proc.mk
/*-------------------------------------------------------------------------
*
* WIN1250 and UTF-8
*
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/mb/conversion_procs/utf8_and_win1250/Attic/utf8_and_win1250.c,v 1.1 2002/08/14 02:45:10 ishii Exp $
*
*-------------------------------------------------------------------------
*/
#include "postgres.h"
#include "fmgr.h"
#include "mb/pg_wchar.h"
#include "../../Unicode/utf8_to_win1250.map"
#include "../../Unicode/win1250_to_utf8.map"
PG_FUNCTION_INFO_V1(utf_to_win1250)
PG_FUNCTION_INFO_V1(win1250_to_utf)
extern Datum utf_to_win1250(PG_FUNCTION_ARGS);
extern Datum win1250_to_utf(PG_FUNCTION_ARGS);
/* ----------
* conv_proc(
* INTEGER, -- source encoding id
* INTEGER, -- destination encoding id
* OPAQUE, -- source string (null terminated C string)
* OPAQUE, -- destination string (null terminated C string)
* INTEGER -- source string length
* ) returns INTEGER; -- dummy. returns nothing, actually.
* ----------
*/
Datum
utf_to_win1250(PG_FUNCTION_ARGS)
{
unsigned char *src = PG_GETARG_CSTRING(2);
unsigned char *dest = PG_GETARG_CSTRING(3);
int len = PG_GETARG_INT32(4);
Assert(PG_GETARG_INT32(0) == PG_UTF8);
Assert(PG_GETARG_INT32(1) == PG_WIN1250);
Assert(len > 0);
UtfToLocal(src, dest, ULmapWIN1250,
sizeof(ULmapWIN1250) / sizeof(pg_utf_to_local), len);
PG_RETURN_INT32(0);
}
Datum
win1250_to_utf(PG_FUNCTION_ARGS)
{
unsigned char *src = PG_GETARG_CSTRING(2);
unsigned char *dest = PG_GETARG_CSTRING(3);
int len = PG_GETARG_INT32(4);
Assert(PG_GETARG_INT32(0) == PG_WIN1250);
Assert(PG_GETARG_INT32(1) == PG_UTF8);
Assert(len > 0);
LocalToUtf(src, dest, LUmapWIN1250,
sizeof(LUmapWIN1250) / sizeof(pg_local_to_utf), PG_WIN1250, len);
PG_RETURN_INT32(0);
}
#-------------------------------------------------------------------------
#
# $Id: Makefile,v 1.1 2002/08/14 02:45:10 ishii Exp $
#
#-------------------------------------------------------------------------
top_builddir = ../../../../../..
include $(top_builddir)/src/Makefile.global
NAME := utf8_and_win1256
include ../proc.mk
/*-------------------------------------------------------------------------
*
* WIN1256 and UTF-8
*
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/mb/conversion_procs/utf8_and_win1256/Attic/utf8_and_win1256.c,v 1.1 2002/08/14 02:45:10 ishii Exp $
*
*-------------------------------------------------------------------------
*/
#include "postgres.h"
#include "fmgr.h"
#include "mb/pg_wchar.h"
#include "../../Unicode/utf8_to_win1256.map"
#include "../../Unicode/win1256_to_utf8.map"
PG_FUNCTION_INFO_V1(utf_to_win1256)
PG_FUNCTION_INFO_V1(win1256_to_utf)
extern Datum utf_to_win1256(PG_FUNCTION_ARGS);
extern Datum win1256_to_utf(PG_FUNCTION_ARGS);
/* ----------
* conv_proc(
* INTEGER, -- source encoding id
* INTEGER, -- destination encoding id
* OPAQUE, -- source string (null terminated C string)
* OPAQUE, -- destination string (null terminated C string)
* INTEGER -- source string length
* ) returns INTEGER; -- dummy. returns nothing, actually.
* ----------
*/
Datum
utf_to_win1256(PG_FUNCTION_ARGS)
{
unsigned char *src = PG_GETARG_CSTRING(2);
unsigned char *dest = PG_GETARG_CSTRING(3);
int len = PG_GETARG_INT32(4);
Assert(PG_GETARG_INT32(0) == PG_UTF8);
Assert(PG_GETARG_INT32(1) == PG_WIN1256);
Assert(len > 0);
UtfToLocal(src, dest, ULmapWIN1256,
sizeof(ULmapWIN1256) / sizeof(pg_utf_to_local), len);
PG_RETURN_INT32(0);
}
Datum
win1256_to_utf(PG_FUNCTION_ARGS)
{
unsigned char *src = PG_GETARG_CSTRING(2);
unsigned char *dest = PG_GETARG_CSTRING(3);
int len = PG_GETARG_INT32(4);
Assert(PG_GETARG_INT32(0) == PG_WIN1256);
Assert(PG_GETARG_INT32(1) == PG_UTF8);
Assert(len > 0);
LocalToUtf(src, dest, LUmapWIN1256,
sizeof(LUmapWIN1256) / sizeof(pg_local_to_utf), PG_WIN1256, len);
PG_RETURN_INT32(0);
}
#-------------------------------------------------------------------------
#
# $Id: Makefile,v 1.1 2002/08/14 02:45:10 ishii Exp $
#
#-------------------------------------------------------------------------
top_builddir = ../../../../../..
include $(top_builddir)/src/Makefile.global
NAME := utf8_and_win874
include ../proc.mk
/*-------------------------------------------------------------------------
*
* WIN874 and UTF-8
*
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/mb/conversion_procs/utf8_and_win874/Attic/utf8_and_win874.c,v 1.1 2002/08/14 02:45:10 ishii Exp $
*
*-------------------------------------------------------------------------
*/
#include "postgres.h"
#include "fmgr.h"
#include "mb/pg_wchar.h"
#include "../../Unicode/utf8_to_win874.map"
#include "../../Unicode/win874_to_utf8.map"
PG_FUNCTION_INFO_V1(utf_to_win874)
PG_FUNCTION_INFO_V1(win874_to_utf)
extern Datum utf_to_win874(PG_FUNCTION_ARGS);
extern Datum win874_to_utf(PG_FUNCTION_ARGS);
/* ----------
* conv_proc(
* INTEGER, -- source encoding id
* INTEGER, -- destination encoding id
* OPAQUE, -- source string (null terminated C string)
* OPAQUE, -- destination string (null terminated C string)
* INTEGER -- source string length
* ) returns INTEGER; -- dummy. returns nothing, actually.
* ----------
*/
Datum
utf_to_win874(PG_FUNCTION_ARGS)
{
unsigned char *src = PG_GETARG_CSTRING(2);
unsigned char *dest = PG_GETARG_CSTRING(3);
int len = PG_GETARG_INT32(4);
Assert(PG_GETARG_INT32(0) == PG_UTF8);
Assert(PG_GETARG_INT32(1) == PG_WIN874);
Assert(len > 0);
UtfToLocal(src, dest, ULmapWIN874,
sizeof(ULmapWIN874) / sizeof(pg_utf_to_local), len);
PG_RETURN_INT32(0);
}
Datum
win874_to_utf(PG_FUNCTION_ARGS)
{
unsigned char *src = PG_GETARG_CSTRING(2);
unsigned char *dest = PG_GETARG_CSTRING(3);
int len = PG_GETARG_INT32(4);
Assert(PG_GETARG_INT32(0) == PG_WIN874);
Assert(PG_GETARG_INT32(1) == PG_UTF8);
Assert(len > 0);
LocalToUtf(src, dest, LUmapWIN874,
sizeof(LUmapWIN874) / sizeof(pg_local_to_utf), PG_WIN874, len);
PG_RETURN_INT32(0);
}
/* $Id: pg_wchar.h,v 1.41 2002/07/29 08:04:55 ishii Exp $ */ /* $Id: pg_wchar.h,v 1.42 2002/08/14 02:45:10 ishii Exp $ */
#ifndef PG_WCHAR_H #ifndef PG_WCHAR_H
#define PG_WCHAR_H #define PG_WCHAR_H
...@@ -327,5 +327,9 @@ extern char *pg_verifymbstr(const unsigned char *mbstr, int len); ...@@ -327,5 +327,9 @@ extern char *pg_verifymbstr(const unsigned char *mbstr, int len);
extern void pg_ascii2mic(unsigned char *src, unsigned char *dest, int len); extern void pg_ascii2mic(unsigned char *src, unsigned char *dest, int len);
extern void pg_mic2ascii(unsigned char *src, unsigned char *dest, int len); extern void pg_mic2ascii(unsigned char *src, unsigned char *dest, int len);
extern void pg_print_bogus_char(unsigned char **mic, unsigned char **p); extern void pg_print_bogus_char(unsigned char **mic, unsigned char **p);
extern void latin2mic(unsigned char *l, unsigned char *p, int len, int lc);
extern void mic2latin(unsigned char *mic, unsigned char *p, int len, int lc);
extern void latin2mic_with_table(unsigned char *l, unsigned char *p, int len, int lc, unsigned char *tab);
extern void mic2latin_with_table(unsigned char *mic, unsigned char *p, int len, int lc, unsigned char *tab);
#endif /* PG_WCHAR_H */ #endif /* PG_WCHAR_H */
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment