cyrillic_and_mic.c

来自「PostgreSQL7.4.6 for Linux」· C语言 代码 · 共 630 行 · 第 1/2 页

C
630
字号
/*------------------------------------------------------------------------- * *	  Cyrillic and MULE_INTERNAL * * Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION *	  $Header: /cvsroot/pgsql/src/backend/utils/mb/conversion_procs/cyrillic_and_mic/cyrillic_and_mic.c,v 1.6 2003/08/04 02:40:07 momjian Exp $ * *------------------------------------------------------------------------- */#include "postgres.h"#include "fmgr.h"#include "mb/pg_wchar.h"#define ENCODING_GROWTH_RATE 4PG_FUNCTION_INFO_V1(koi8r_to_mic);PG_FUNCTION_INFO_V1(mic_to_koi8r);PG_FUNCTION_INFO_V1(iso_to_mic);PG_FUNCTION_INFO_V1(mic_to_iso);PG_FUNCTION_INFO_V1(win1251_to_mic);PG_FUNCTION_INFO_V1(mic_to_win1251);PG_FUNCTION_INFO_V1(alt_to_mic);PG_FUNCTION_INFO_V1(mic_to_alt);PG_FUNCTION_INFO_V1(koi8r_to_win1251);PG_FUNCTION_INFO_V1(win1251_to_koi8r);PG_FUNCTION_INFO_V1(koi8r_to_alt);PG_FUNCTION_INFO_V1(alt_to_koi8r);PG_FUNCTION_INFO_V1(alt_to_win1251);PG_FUNCTION_INFO_V1(win1251_to_alt);PG_FUNCTION_INFO_V1(iso_to_koi8r);PG_FUNCTION_INFO_V1(koi8r_to_iso);PG_FUNCTION_INFO_V1(iso_to_win1251);PG_FUNCTION_INFO_V1(win1251_to_iso);PG_FUNCTION_INFO_V1(iso_to_alt);PG_FUNCTION_INFO_V1(alt_to_iso);extern Datum koi8r_to_mic(PG_FUNCTION_ARGS);extern Datum mic_to_koi8r(PG_FUNCTION_ARGS);extern Datum iso_to_mic(PG_FUNCTION_ARGS);extern Datum mic_to_iso(PG_FUNCTION_ARGS);extern Datum win1251_to_mic(PG_FUNCTION_ARGS);extern Datum mic_to_win1251(PG_FUNCTION_ARGS);extern Datum alt_to_mic(PG_FUNCTION_ARGS);extern Datum mic_to_alt(PG_FUNCTION_ARGS);extern Datum koi8r_to_win1251(PG_FUNCTION_ARGS);extern Datum win1251_to_koi8r(PG_FUNCTION_ARGS);extern Datum koi8r_to_alt(PG_FUNCTION_ARGS);extern Datum alt_to_koi8r(PG_FUNCTION_ARGS);extern Datum alt_to_win1251(PG_FUNCTION_ARGS);extern Datum win1251_to_alt(PG_FUNCTION_ARGS);extern Datum iso_to_koi8r(PG_FUNCTION_ARGS);extern Datum koi8r_to_iso(PG_FUNCTION_ARGS);extern Datum iso_to_win1251(PG_FUNCTION_ARGS);extern Datum win1251_to_iso(PG_FUNCTION_ARGS);extern Datum iso_to_alt(PG_FUNCTION_ARGS);extern Datum alt_to_iso(PG_FUNCTION_ARGS);/* ---------- * conv_proc( *		INTEGER,	-- source encoding id *		INTEGER,	-- destination encoding id *		CSTRING,	-- source string (null terminated C string) *		CSTRING,	-- destination string (null terminated C string) *		INTEGER		-- source string length * ) returns VOID; * ---------- */static void koi8r2mic(unsigned char *l, unsigned char *p, int len);static void mic2koi8r(unsigned char *mic, unsigned char *p, int len);static void iso2mic(unsigned char *l, unsigned char *p, int len);static void mic2iso(unsigned char *mic, unsigned char *p, int len);static void win12512mic(unsigned char *l, unsigned char *p, int len);static void mic2win1251(unsigned char *mic, unsigned char *p, int len);static void alt2mic(unsigned char *l, unsigned char *p, int len);static void mic2alt(unsigned char *mic, unsigned char *p, int len);Datumkoi8r_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_KOI8R);	Assert(PG_GETARG_INT32(1) == PG_MULE_INTERNAL);	Assert(len >= 0);	koi8r2mic(src, dest, len);	PG_RETURN_VOID();}Datummic_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_MULE_INTERNAL);	Assert(PG_GETARG_INT32(1) == PG_KOI8R);	Assert(len >= 0);	mic2koi8r(src, dest, len);	PG_RETURN_VOID();}Datumiso_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_ISO_8859_5);	Assert(PG_GETARG_INT32(1) == PG_MULE_INTERNAL);	Assert(len >= 0);	iso2mic(src, dest, len);	PG_RETURN_VOID();}Datummic_to_iso(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_ISO_8859_5);	Assert(len >= 0);	mic2iso(src, dest, len);	PG_RETURN_VOID();}Datumwin1251_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_WIN1251);	Assert(PG_GETARG_INT32(1) == PG_MULE_INTERNAL);	Assert(len >= 0);	win12512mic(src, dest, len);	PG_RETURN_VOID();}Datummic_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_MULE_INTERNAL);	Assert(PG_GETARG_INT32(1) == PG_WIN1251);	Assert(len >= 0);	mic2win1251(src, dest, len);	PG_RETURN_VOID();}Datumalt_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_ALT);	Assert(PG_GETARG_INT32(1) == PG_MULE_INTERNAL);	Assert(len >= 0);	alt2mic(src, dest, len);	PG_RETURN_VOID();}Datummic_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_MULE_INTERNAL);	Assert(PG_GETARG_INT32(1) == PG_ALT);	Assert(len >= 0);	mic2alt(src, dest, len);	PG_RETURN_VOID();}Datumkoi8r_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);	unsigned char *buf;	Assert(PG_GETARG_INT32(0) == PG_KOI8R);	Assert(PG_GETARG_INT32(1) == PG_WIN1251);	Assert(len >= 0);	buf = palloc(len * ENCODING_GROWTH_RATE);	koi8r2mic(src, buf, len);	mic2win1251(buf, dest, strlen(buf));	pfree(buf);	PG_RETURN_VOID();}Datumwin1251_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);	unsigned char *buf;	Assert(PG_GETARG_INT32(0) == PG_WIN1251);	Assert(PG_GETARG_INT32(1) == PG_KOI8R);	Assert(len >= 0);	buf = palloc(len * ENCODING_GROWTH_RATE);	win12512mic(src, buf, len);	mic2koi8r(buf, dest, strlen(buf));	pfree(buf);	PG_RETURN_VOID();}Datumkoi8r_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);	unsigned char *buf;	Assert(PG_GETARG_INT32(0) == PG_KOI8R);	Assert(PG_GETARG_INT32(1) == PG_ALT);	Assert(len >= 0);	buf = palloc(len * ENCODING_GROWTH_RATE);	koi8r2mic(src, buf, len);	mic2alt(buf, dest, strlen(buf));	pfree(buf);	PG_RETURN_VOID();}Datumalt_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);	unsigned char *buf;	Assert(PG_GETARG_INT32(0) == PG_ALT);	Assert(PG_GETARG_INT32(1) == PG_KOI8R);	Assert(len >= 0);	buf = palloc(len * ENCODING_GROWTH_RATE);	alt2mic(src, buf, len);	mic2koi8r(buf, dest, strlen(buf));	pfree(buf);	PG_RETURN_VOID();}Datumalt_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);	unsigned char *buf;	Assert(PG_GETARG_INT32(0) == PG_ALT);	Assert(PG_GETARG_INT32(1) == PG_WIN1251);	Assert(len >= 0);	buf = palloc(len * ENCODING_GROWTH_RATE);	alt2mic(src, buf, len);	mic2win1251(buf, dest, strlen(buf));	pfree(buf);	PG_RETURN_VOID();}Datumwin1251_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);

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?