~vcs-imports/mammoth-replicator/trunk

« back to all changes in this revision

Viewing changes to src/backend/utils/mb/conversion_procs/latin_and_mic/latin_and_mic.c

  • Committer: alvherre
  • Date: 2005-12-16 21:24:52 UTC
  • Revision ID: svn-v4:db760fc0-0f08-0410-9d63-cc6633f64896:trunk:1
Initial import of the REL8_0_3 sources from the Pgsql CVS repository.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*-------------------------------------------------------------------------
 
2
 *
 
3
 *        LATINn and MULE_INTERNAL
 
4
 *
 
5
 * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
 
6
 * Portions Copyright (c) 1994, Regents of the University of California
 
7
 *
 
8
 * IDENTIFICATION
 
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 $
 
10
 *
 
11
 *-------------------------------------------------------------------------
 
12
 */
 
13
 
 
14
#include "postgres.h"
 
15
#include "fmgr.h"
 
16
#include "mb/pg_wchar.h"
 
17
 
 
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);
 
24
 
 
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);
 
31
 
 
32
/* ----------
 
33
 * conv_proc(
 
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
 
39
 * ) returns VOID;
 
40
 * ----------
 
41
 */
 
42
 
 
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);
 
49
 
 
50
Datum
 
51
latin1_to_mic(PG_FUNCTION_ARGS)
 
52
{
 
53
        unsigned char *src = PG_GETARG_CSTRING(2);
 
54
        unsigned char *dest = PG_GETARG_CSTRING(3);
 
55
        int                     len = PG_GETARG_INT32(4);
 
56
 
 
57
        Assert(PG_GETARG_INT32(0) == PG_LATIN1);
 
58
        Assert(PG_GETARG_INT32(1) == PG_MULE_INTERNAL);
 
59
        Assert(len >= 0);
 
60
 
 
61
        latin12mic(src, dest, len);
 
62
 
 
63
        PG_RETURN_VOID();
 
64
}
 
65
 
 
66
Datum
 
67
mic_to_latin1(PG_FUNCTION_ARGS)
 
68
{
 
69
        unsigned char *src = PG_GETARG_CSTRING(2);
 
70
        unsigned char *dest = PG_GETARG_CSTRING(3);
 
71
        int                     len = PG_GETARG_INT32(4);
 
72
 
 
73
        Assert(PG_GETARG_INT32(0) == PG_MULE_INTERNAL);
 
74
        Assert(PG_GETARG_INT32(1) == PG_LATIN1);
 
75
        Assert(len >= 0);
 
76
 
 
77
        mic2latin1(src, dest, len);
 
78
 
 
79
        PG_RETURN_VOID();
 
80
}
 
81
 
 
82
Datum
 
83
latin3_to_mic(PG_FUNCTION_ARGS)
 
84
{
 
85
        unsigned char *src = PG_GETARG_CSTRING(2);
 
86
        unsigned char *dest = PG_GETARG_CSTRING(3);
 
87
        int                     len = PG_GETARG_INT32(4);
 
88
 
 
89
        Assert(PG_GETARG_INT32(0) == PG_LATIN3);
 
90
        Assert(PG_GETARG_INT32(1) == PG_MULE_INTERNAL);
 
91
        Assert(len >= 0);
 
92
 
 
93
        latin32mic(src, dest, len);
 
94
 
 
95
        PG_RETURN_VOID();
 
96
}
 
97
 
 
98
Datum
 
99
mic_to_latin3(PG_FUNCTION_ARGS)
 
100
{
 
101
        unsigned char *src = PG_GETARG_CSTRING(2);
 
102
        unsigned char *dest = PG_GETARG_CSTRING(3);
 
103
        int                     len = PG_GETARG_INT32(4);
 
104
 
 
105
        Assert(PG_GETARG_INT32(0) == PG_MULE_INTERNAL);
 
106
        Assert(PG_GETARG_INT32(1) == PG_LATIN3);
 
107
        Assert(len >= 0);
 
108
 
 
109
        mic2latin3(src, dest, len);
 
110
 
 
111
        PG_RETURN_VOID();
 
112
}
 
113
 
 
114
Datum
 
115
latin4_to_mic(PG_FUNCTION_ARGS)
 
116
{
 
117
        unsigned char *src = PG_GETARG_CSTRING(2);
 
118
        unsigned char *dest = PG_GETARG_CSTRING(3);
 
119
        int                     len = PG_GETARG_INT32(4);
 
120
 
 
121
        Assert(PG_GETARG_INT32(0) == PG_LATIN4);
 
122
        Assert(PG_GETARG_INT32(1) == PG_MULE_INTERNAL);
 
123
        Assert(len >= 0);
 
124
 
 
125
        latin42mic(src, dest, len);
 
126
 
 
127
        PG_RETURN_VOID();
 
128
}
 
129
 
 
130
Datum
 
131
mic_to_latin4(PG_FUNCTION_ARGS)
 
132
{
 
133
        unsigned char *src = PG_GETARG_CSTRING(2);
 
134
        unsigned char *dest = PG_GETARG_CSTRING(3);
 
135
        int                     len = PG_GETARG_INT32(4);
 
136
 
 
137
        Assert(PG_GETARG_INT32(0) == PG_MULE_INTERNAL);
 
138
        Assert(PG_GETARG_INT32(1) == PG_LATIN4);
 
139
        Assert(len >= 0);
 
140
 
 
141
        mic2latin4(src, dest, len);
 
142
 
 
143
        PG_RETURN_VOID();
 
144
}
 
145
 
 
146
static void
 
147
latin12mic(unsigned char *l, unsigned char *p, int len)
 
148
{
 
149
        latin2mic(l, p, len, LC_ISO8859_1);
 
150
}
 
151
static void
 
152
mic2latin1(unsigned char *mic, unsigned char *p, int len)
 
153
{
 
154
        mic2latin(mic, p, len, LC_ISO8859_1);
 
155
}
 
156
static void
 
157
latin32mic(unsigned char *l, unsigned char *p, int len)
 
158
{
 
159
        latin2mic(l, p, len, LC_ISO8859_3);
 
160
}
 
161
static void
 
162
mic2latin3(unsigned char *mic, unsigned char *p, int len)
 
163
{
 
164
        mic2latin(mic, p, len, LC_ISO8859_3);
 
165
}
 
166
static void
 
167
latin42mic(unsigned char *l, unsigned char *p, int len)
 
168
{
 
169
        latin2mic(l, p, len, LC_ISO8859_4);
 
170
}
 
171
static void
 
172
mic2latin4(unsigned char *mic, unsigned char *p, int len)
 
173
{
 
174
        mic2latin(mic, p, len, LC_ISO8859_4);
 
175
}