Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 9350174

Browse files
author
Hiroshi Inoue
committed
Oops I forgot to add new files for multibyte support.
Sorry Eiji.
1 parent 9d645fd commit 9350174

File tree

2 files changed

+163
-0
lines changed

2 files changed

+163
-0
lines changed

src/interfaces/odbc/multibyte.c

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
/*
2+
* Module : multibyte.c
3+
*
4+
* Description: Mlutibyte related additional function.
5+
*
6+
* Create 2001-03-03 Eiji Tokuya
7+
*
8+
*/
9+
#include <string.h>
10+
#include "multibyte.h"
11+
12+
int multibyte_client_encoding ; /* Multibyte Client Encoding. */
13+
int multibyte_status ; /* Multibyte Odds and ends character. */
14+
15+
unsigned char *multibyte_strchr(unsigned char *s,unsigned char c)
16+
{
17+
int mb_st = 0 ,i = 0;
18+
while (!(mb_st == 0 && s[i] == c || s[i] == 0))
19+
{
20+
if (s[i] == 0)
21+
return (0);
22+
switch ( multibyte_client_encoding )
23+
{
24+
case SJIS:
25+
{
26+
if (mb_st < 2 && s[i] > 0x80 && !(s[i] > 0x9f && s[i] < 0xe0))
27+
mb_st = 2;
28+
else if (mb_st == 2)
29+
mb_st = 1;
30+
else
31+
mb_st = 0;
32+
}
33+
break;
34+
35+
36+
/* Chinese Big5 Support. */
37+
case BIG5:
38+
{
39+
if ( mb_st < 2 && s[i] > 0xA0 )
40+
mb_st = 2;
41+
else if ( mb_st == 2 )
42+
mb_st = 1;
43+
else
44+
mb_st = 0;
45+
}
46+
break;
47+
default:
48+
{
49+
mb_st = 0;
50+
}
51+
}
52+
i++;
53+
}
54+
#ifdef _DEBUG
55+
qlog("i = %d\n",i);
56+
#endif
57+
return (s + i);
58+
}
59+
60+
void multibyte_init(void)
61+
{
62+
multibyte_status = 0;
63+
}
64+
65+
unsigned char *check_client_encoding(unsigned char *str)
66+
{
67+
if(strstr(str,"%27SJIS%27")||strstr(str,"'SJIS'")||strstr(str,"'sjis'"))
68+
{
69+
multibyte_client_encoding = SJIS;
70+
return ("SJIS");
71+
}
72+
if(strstr(str,"%27BIG5%27")||strstr(str,"'BIG5'")||strstr(str,"'big5'"))
73+
{
74+
multibyte_client_encoding = BIG5;
75+
return ("BIG5");
76+
}
77+
return ("OHTER");
78+
}
79+
80+
/*
81+
* Multibyte Status Function.
82+
* Input char
83+
* Output 0 : 1 Byte Character.
84+
* 1 : MultibyteCharacter Last Byte.
85+
* N : MultibyteCharacter Fast or Middle Byte.
86+
*/
87+
int multibyte_char_check(unsigned char s)
88+
{
89+
switch ( multibyte_client_encoding )
90+
{
91+
/* Japanese Shift-JIS(CP932) Support. */
92+
case SJIS:
93+
{
94+
if ( multibyte_status < 2 && s > 0x80 && !(s > 0x9f && s < 0xE0))
95+
multibyte_status = 2;
96+
else if (multibyte_status == 2)
97+
multibyte_status = 1;
98+
else
99+
multibyte_status = 0;
100+
}
101+
break;
102+
103+
104+
/* Chinese Big5(CP950) Support. */
105+
case BIG5:
106+
{
107+
if ( multibyte_status < 2 && s > 0xA0)
108+
multibyte_status = 2;
109+
else if (multibyte_status == 2)
110+
multibyte_status = 1;
111+
else
112+
multibyte_status = 0;
113+
}
114+
break;
115+
default:
116+
{
117+
multibyte_status = 0;
118+
}
119+
}
120+
#ifdef _DEBUG
121+
qlog("multibyte_client_encoding = %d s = 0x%02X multibyte_stat = %d\n", multibyte_client_encoding, s, multibyte_status );
122+
#endif
123+
return( multibyte_status );
124+
}

src/interfaces/odbc/multibyte.h

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
*
3+
* Multibyte library header ( psqlODBC Only )
4+
*
5+
*
6+
*/
7+
8+
/* PostgreSQL client encoding */
9+
#define SQL_ASCII 0 /* SQL/ASCII */
10+
#define EUC_JP 1 /* EUC for Japanese */
11+
#define EUC_CN 2 /* EUC for Chinese */
12+
#define EUC_KR 3 /* EUC for Korean */
13+
#define EUC_TW 4 /* EUC for Taiwan */
14+
#define UNICODE 5 /* Unicode UTF-8 */
15+
#define MULE_INTERNAL 6 /* Mule internal code */
16+
#define LATIN1 7 /* ISO-8859 Latin 1 */
17+
#define LATIN2 8 /* ISO-8859 Latin 2 */
18+
#define LATIN3 9 /* ISO-8859 Latin 3 */
19+
#define LATIN4 10 /* ISO-8859 Latin 4 */
20+
#define LATIN5 11 /* ISO-8859 Latin 5 */
21+
#define LATIN6 12 /* ISO-8859 Latin 6 */
22+
#define LATIN7 13 /* ISO-8859 Latin 7 */
23+
#define LATIN8 14 /* ISO-8859 Latin 8 */
24+
#define LATIN9 15 /* ISO-8859 Latin 9 */
25+
#define KOI8 16 /* KOI8-R */
26+
#define WIN 17 /* windows-1251 */
27+
#define ALT 18 /* Alternativny Variant (MS-DOS CP866) */
28+
#define SJIS 32 /* Shift JIS */
29+
#define BIG5 33 /* Big5 */
30+
#define WIN1250 34 /* windows-1250 */
31+
32+
33+
extern int multibyte_client_encoding ; /* Multibyte client encoding. */
34+
extern int multibyte_status ; /* Multibyte charcter status. */
35+
36+
void multibyte_init(void);
37+
unsigned char *check_client_encoding(unsigned char *str);
38+
int multibyte_char_check(unsigned char s);
39+
unsigned char *multibyte_strchr(unsigned char *s, unsigned char c);

0 commit comments

Comments
 (0)