1
/*-------------------------------------------------------------------------
3
* LATINn and MULE_INTERNAL
5
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
6
* Portions Copyright (c) 1994, Regents of the University of California
9
* $PostgreSQL: pgsql/src/backend/utils/mb/conversion_procs/latin_and_mic/latin_and_mic.c,v 1.9 2004-12-31 22:02:10 pgsql Exp $
11
*-------------------------------------------------------------------------
16
#include "mb/pg_wchar.h"
18
PG_FUNCTION_INFO_V1(latin1_to_mic);
19
PG_FUNCTION_INFO_V1(mic_to_latin1);
20
PG_FUNCTION_INFO_V1(latin3_to_mic);
21
PG_FUNCTION_INFO_V1(mic_to_latin3);
22
PG_FUNCTION_INFO_V1(latin4_to_mic);
23
PG_FUNCTION_INFO_V1(mic_to_latin4);
25
extern Datum latin1_to_mic(PG_FUNCTION_ARGS);
26
extern Datum mic_to_latin1(PG_FUNCTION_ARGS);
27
extern Datum latin3_to_mic(PG_FUNCTION_ARGS);
28
extern Datum mic_to_latin3(PG_FUNCTION_ARGS);
29
extern Datum latin4_to_mic(PG_FUNCTION_ARGS);
30
extern Datum mic_to_latin4(PG_FUNCTION_ARGS);
34
* INTEGER, -- source encoding id
35
* INTEGER, -- destination encoding id
36
* CSTRING, -- source string (null terminated C string)
37
* CSTRING, -- destination string (null terminated C string)
38
* INTEGER -- source string length
43
static void latin12mic(unsigned char *l, unsigned char *p, int len);
44
static void mic2latin1(unsigned char *mic, unsigned char *p, int len);
45
static void latin32mic(unsigned char *l, unsigned char *p, int len);
46
static void mic2latin3(unsigned char *mic, unsigned char *p, int len);
47
static void latin42mic(unsigned char *l, unsigned char *p, int len);
48
static void mic2latin4(unsigned char *mic, unsigned char *p, int len);
51
latin1_to_mic(PG_FUNCTION_ARGS)
53
unsigned char *src = PG_GETARG_CSTRING(2);
54
unsigned char *dest = PG_GETARG_CSTRING(3);
55
int len = PG_GETARG_INT32(4);
57
Assert(PG_GETARG_INT32(0) == PG_LATIN1);
58
Assert(PG_GETARG_INT32(1) == PG_MULE_INTERNAL);
61
latin12mic(src, dest, len);
67
mic_to_latin1(PG_FUNCTION_ARGS)
69
unsigned char *src = PG_GETARG_CSTRING(2);
70
unsigned char *dest = PG_GETARG_CSTRING(3);
71
int len = PG_GETARG_INT32(4);
73
Assert(PG_GETARG_INT32(0) == PG_MULE_INTERNAL);
74
Assert(PG_GETARG_INT32(1) == PG_LATIN1);
77
mic2latin1(src, dest, len);
83
latin3_to_mic(PG_FUNCTION_ARGS)
85
unsigned char *src = PG_GETARG_CSTRING(2);
86
unsigned char *dest = PG_GETARG_CSTRING(3);
87
int len = PG_GETARG_INT32(4);
89
Assert(PG_GETARG_INT32(0) == PG_LATIN3);
90
Assert(PG_GETARG_INT32(1) == PG_MULE_INTERNAL);
93
latin32mic(src, dest, len);
99
mic_to_latin3(PG_FUNCTION_ARGS)
101
unsigned char *src = PG_GETARG_CSTRING(2);
102
unsigned char *dest = PG_GETARG_CSTRING(3);
103
int len = PG_GETARG_INT32(4);
105
Assert(PG_GETARG_INT32(0) == PG_MULE_INTERNAL);
106
Assert(PG_GETARG_INT32(1) == PG_LATIN3);
109
mic2latin3(src, dest, len);
115
latin4_to_mic(PG_FUNCTION_ARGS)
117
unsigned char *src = PG_GETARG_CSTRING(2);
118
unsigned char *dest = PG_GETARG_CSTRING(3);
119
int len = PG_GETARG_INT32(4);
121
Assert(PG_GETARG_INT32(0) == PG_LATIN4);
122
Assert(PG_GETARG_INT32(1) == PG_MULE_INTERNAL);
125
latin42mic(src, dest, len);
131
mic_to_latin4(PG_FUNCTION_ARGS)
133
unsigned char *src = PG_GETARG_CSTRING(2);
134
unsigned char *dest = PG_GETARG_CSTRING(3);
135
int len = PG_GETARG_INT32(4);
137
Assert(PG_GETARG_INT32(0) == PG_MULE_INTERNAL);
138
Assert(PG_GETARG_INT32(1) == PG_LATIN4);
141
mic2latin4(src, dest, len);
147
latin12mic(unsigned char *l, unsigned char *p, int len)
149
latin2mic(l, p, len, LC_ISO8859_1);
152
mic2latin1(unsigned char *mic, unsigned char *p, int len)
154
mic2latin(mic, p, len, LC_ISO8859_1);
157
latin32mic(unsigned char *l, unsigned char *p, int len)
159
latin2mic(l, p, len, LC_ISO8859_3);
162
mic2latin3(unsigned char *mic, unsigned char *p, int len)
164
mic2latin(mic, p, len, LC_ISO8859_3);
167
latin42mic(unsigned char *l, unsigned char *p, int len)
169
latin2mic(l, p, len, LC_ISO8859_4);
172
mic2latin4(unsigned char *mic, unsigned char *p, int len)
174
mic2latin(mic, p, len, LC_ISO8859_4);