1
0
mirror of https://github.com/postgres/postgres.git synced 2025-11-12 05:01:15 +03:00

OK, folks, here is the pgindent output.

This commit is contained in:
Bruce Momjian
1998-09-01 04:40:42 +00:00
parent af74855a60
commit fa1a8d6a97
574 changed files with 26509 additions and 24033 deletions

View File

@@ -2,7 +2,7 @@
* This file contains some public functions
* usable for both the backend and the frontend.
* Tatsuo Ishii
* $Id: common.c,v 1.1 1998/07/24 03:31:56 scrappy Exp $ */
* $Id: common.c,v 1.2 1998/09/01 04:33:19 momjian Exp $ */
#include <stdio.h>
#include <string.h>
@@ -14,54 +14,61 @@
* case is ignored.
* if there's no valid encoding, returns -1
*/
int pg_char_to_encoding(const char *s)
int
pg_char_to_encoding(const char *s)
{
pg_encoding_conv_tbl *p = pg_conv_tbl;
pg_encoding_conv_tbl *p = pg_conv_tbl;
for(;p->encoding >= 0;p++) {
if (!strcasecmp(s, p->name)) {
break;
}
}
return(p->encoding);
for (; p->encoding >= 0; p++)
{
if (!strcasecmp(s, p->name))
break;
}
return (p->encoding);
}
/*
* check to see if encoding name is valid
*/
int pg_valid_client_encoding(const char *name)
int
pg_valid_client_encoding(const char *name)
{
return(pg_char_to_encoding(name));
return (pg_char_to_encoding(name));
}
/*
* find encoding table entry by encoding
*/
pg_encoding_conv_tbl *pg_get_encent_by_encoding(int encoding)
pg_encoding_conv_tbl *
pg_get_encent_by_encoding(int encoding)
{
pg_encoding_conv_tbl *p = pg_conv_tbl;
for(;p->encoding >= 0;p++) {
if (p->encoding == encoding) {
return(p);
}
}
return(0);
pg_encoding_conv_tbl *p = pg_conv_tbl;
for (; p->encoding >= 0; p++)
{
if (p->encoding == encoding)
return (p);
}
return (0);
}
/*
* convert encoding symbol to encoding char.
* if there's no valid encoding symbol, returns ""
*/
const char *pg_encoding_to_char(int encoding)
const char *
pg_encoding_to_char(int encoding)
{
pg_encoding_conv_tbl *p = pg_get_encent_by_encoding(encoding);
pg_encoding_conv_tbl *p = pg_get_encent_by_encoding(encoding);
if (!p) return("");
return(p->name);
if (!p)
return ("");
return (p->name);
}
/* returns the byte length of a multi-byte word for an encoding */
int pg_encoding_mblen(int encoding, const unsigned char *mbstr)
int
pg_encoding_mblen(int encoding, const unsigned char *mbstr)
{
return((*pg_wchar_table[encoding].mblen)(mbstr));
return ((*pg_wchar_table[encoding].mblen) (mbstr));
}

View File

@@ -2,7 +2,7 @@
* conversion between client encoding and server internal encoding
* (currently mule internal code (mic) is used)
* Tatsuo Ishii
* $Id: conv.c,v 1.2 1998/08/24 01:13:59 momjian Exp $
* $Id: conv.c,v 1.3 1998/09/01 04:33:21 momjian Exp $
*/
#include <stdio.h>
#include <string.h>
@@ -13,405 +13,505 @@
* convert bogus chars that cannot be represented in the current encoding
* system.
*/
static void printBogusChar(unsigned char **mic, unsigned char **p)
static void
printBogusChar(unsigned char **mic, unsigned char **p)
{
char strbuf[16];
int l = pg_mic_mblen(*mic);
char strbuf[16];
int l = pg_mic_mblen(*mic);
*(*p)++ = '(';
while (l--) {
sprintf(strbuf,"%02x",*(*mic)++);
*(*p)++ = strbuf[0];
*(*p)++ = strbuf[1];
}
*(*p)++ = ')';
*(*p)++ = '(';
while (l--)
{
sprintf(strbuf, "%02x", *(*mic)++);
*(*p)++ = strbuf[0];
*(*p)++ = strbuf[1];
}
*(*p)++ = ')';
}
/*
* SJIS ---> MIC
*/
static void sjis2mic(unsigned char *sjis, unsigned char *p, int len)
static void
sjis2mic(unsigned char *sjis, unsigned char *p, int len)
{
int c1,c2;
int c1,
c2;
while (len > 0 && (c1 = *sjis++)) {
if (c1 >= 0xa1 && c1 <= 0xdf) { /* 1 byte kana? */
len--;
*p++ = LC_JISX0201K;
*p++ = c1;
} else if (c1 > 0x7f) { /* kanji? */
c2 = *sjis++;
len -= 2;
*p++ = LC_JISX0208;
*p++ = ((c1 & 0x3f)<<1) + 0x9f + (c2 > 0x9e);
*p++ = c2 + ((c2 > 0x9e)? 2 : 0x60) + (c2 < 0x80);
} else { /* should be ASCII */
len--;
*p++ = c1;
}
}
*p = '\0';
while (len > 0 && (c1 = *sjis++))
{
if (c1 >= 0xa1 && c1 <= 0xdf)
{ /* 1 byte kana? */
len--;
*p++ = LC_JISX0201K;
*p++ = c1;
}
else if (c1 > 0x7f)
{ /* kanji? */
c2 = *sjis++;
len -= 2;
*p++ = LC_JISX0208;
*p++ = ((c1 & 0x3f) << 1) + 0x9f + (c2 > 0x9e);
*p++ = c2 + ((c2 > 0x9e) ? 2 : 0x60) + (c2 < 0x80);
}
else
{ /* should be ASCII */
len--;
*p++ = c1;
}
}
*p = '\0';
}
/*
* MIC ---> SJIS
*/
static void mic2sjis(unsigned char *mic, unsigned char *p, int len)
static void
mic2sjis(unsigned char *mic, unsigned char *p, int len)
{
int c1,c2;
int c1,
c2;
while (len > 0 && (c1 = *mic)) {
len -= pg_mic_mblen(mic++);
while (len > 0 && (c1 = *mic))
{
len -= pg_mic_mblen(mic++);
if (c1 == LC_JISX0201K) {
*p++ = *mic++;
} else if (c1 == LC_JISX0208) {
c1 = *mic++;
c2 = *mic++;
*p++ = ((c1 - 0xa1)>>1) + ((c1 < 0xdf)? 0x81 : 0xc1);
*p++ = c2 - ((c1 & 1)? ((c2 < 0xe0)? 0x61 : 0x60) : 2);
} else if (c1 > 0x7f) { /* cannot convert to SJIS! */
mic--;
printBogusChar(&mic, &p);
} else { /* should be ASCII */
*p++ = c1;
}
}
*p = '\0';
if (c1 == LC_JISX0201K)
*p++ = *mic++;
else if (c1 == LC_JISX0208)
{
c1 = *mic++;
c2 = *mic++;
*p++ = ((c1 - 0xa1) >> 1) + ((c1 < 0xdf) ? 0x81 : 0xc1);
*p++ = c2 - ((c1 & 1) ? ((c2 < 0xe0) ? 0x61 : 0x60) : 2);
}
else if (c1 > 0x7f)
{ /* cannot convert to SJIS! */
mic--;
printBogusChar(&mic, &p);
}
else
{ /* should be ASCII */
*p++ = c1;
}
}
*p = '\0';
}
/*
* EUC_JP ---> MIC
*/
static void euc_jp2mic(unsigned char *euc, unsigned char *p, int len)
static void
euc_jp2mic(unsigned char *euc, unsigned char *p, int len)
{
int c1;
int c1;
while (len > 0 && (c1 = *euc++)) {
if (c1 == SS2) { /* 1 byte kana? */
len -= 2;
*p++ = LC_JISX0201K;
*p++ = *euc++;
} else if (c1 == SS3) { /* JIS X0212 kanji? */
len -= 3;
*p++ = LC_JISX0212;
*p++ = *euc++;
*p++ = *euc++;
} else if (c1 & 0x80) { /* kanji? */
len -= 2;
*p++ = LC_JISX0208;
*p++ = c1;
*p++ = *euc++;
} else { /* should be ASCII */
len--;
*p++ = c1;
}
}
*p = '\0';
while (len > 0 && (c1 = *euc++))
{
if (c1 == SS2)
{ /* 1 byte kana? */
len -= 2;
*p++ = LC_JISX0201K;
*p++ = *euc++;
}
else if (c1 == SS3)
{ /* JIS X0212 kanji? */
len -= 3;
*p++ = LC_JISX0212;
*p++ = *euc++;
*p++ = *euc++;
}
else if (c1 & 0x80)
{ /* kanji? */
len -= 2;
*p++ = LC_JISX0208;
*p++ = c1;
*p++ = *euc++;
}
else
{ /* should be ASCII */
len--;
*p++ = c1;
}
}
*p = '\0';
}
/*
* MIC ---> EUC_JP
*/
static void mic2euc_jp(unsigned char *mic, unsigned char *p, int len)
static void
mic2euc_jp(unsigned char *mic, unsigned char *p, int len)
{
int c1;
int c1;
while (len > 0 && (c1 = *mic)) {
len -= pg_mic_mblen(mic++);
while (len > 0 && (c1 = *mic))
{
len -= pg_mic_mblen(mic++);
if (c1 == LC_JISX0201K) {
*p++ = SS2;
*p++ = *mic++;
} else if (c1 == LC_JISX0212) {
*p++ = SS3;
*p++ = *mic++;
*p++ = *mic++;
} else if (c1 == LC_JISX0208) {
*p++ = *mic++;
*p++ = *mic++;
} else if (c1 > 0x7f) { /* cannot convert to EUC_JP! */
mic--;
printBogusChar(&mic, &p);
} else { /* should be ASCII */
*p++ = c1;
}
}
*p = '\0';
if (c1 == LC_JISX0201K)
{
*p++ = SS2;
*p++ = *mic++;
}
else if (c1 == LC_JISX0212)
{
*p++ = SS3;
*p++ = *mic++;
*p++ = *mic++;
}
else if (c1 == LC_JISX0208)
{
*p++ = *mic++;
*p++ = *mic++;
}
else if (c1 > 0x7f)
{ /* cannot convert to EUC_JP! */
mic--;
printBogusChar(&mic, &p);
}
else
{ /* should be ASCII */
*p++ = c1;
}
}
*p = '\0';
}
/*
* EUC_KR ---> MIC
*/
static void euc_kr2mic(unsigned char *euc, unsigned char *p, int len)
static void
euc_kr2mic(unsigned char *euc, unsigned char *p, int len)
{
int c1;
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';
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)
static void
mic2euc_kr(unsigned char *mic, unsigned char *p, int len)
{
int c1;
int c1;
while (len > 0 && (c1 = *mic)) {
len -= pg_mic_mblen(mic++);
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--;
printBogusChar(&mic, &p);
} else { /* should be ASCII */
*p++ = c1;
}
}
*p = '\0';
if (c1 == LC_KS5601)
{
*p++ = *mic++;
*p++ = *mic++;
}
else if (c1 > 0x7f)
{ /* cannot convert to EUC_KR! */
mic--;
printBogusChar(&mic, &p);
}
else
{ /* should be ASCII */
*p++ = c1;
}
}
*p = '\0';
}
/*
* EUC_CN ---> MIC
*/
static void euc_cn2mic(unsigned char *euc, unsigned char *p, int len)
static void
euc_cn2mic(unsigned char *euc, unsigned char *p, int len)
{
int c1;
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';
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)
static void
mic2euc_cn(unsigned char *mic, unsigned char *p, int len)
{
int c1;
int c1;
while (len > 0 && (c1 = *mic)) {
len -= pg_mic_mblen(mic++);
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--;
printBogusChar(&mic, &p);
} else { /* should be ASCII */
*p++ = c1;
}
}
*p = '\0';
if (c1 == LC_GB2312_80)
{
*p++ = *mic++;
*p++ = *mic++;
}
else if (c1 > 0x7f)
{ /* cannot convert to EUC_CN! */
mic--;
printBogusChar(&mic, &p);
}
else
{ /* should be ASCII */
*p++ = c1;
}
}
*p = '\0';
}
/*
* EUC_TW ---> MIC
*/
static void euc_tw2mic(unsigned char *euc, unsigned char *p, int len)
static void
euc_tw2mic(unsigned char *euc, unsigned char *p, int len)
{
int c1;
int c1;
while (len > 0 && (c1 = *euc++)) {
if (c1 == SS2) {
len -= 4;
c1 = *euc++; /* plane No. */
if (c1 == 0xa1) {
*p++ = LC_CNS11643_1;
} else if (c1 == 0xa2) {
*p++ = LC_CNS11643_2;
} else {
*p++ = 0x9d; /* LCPRV2 */
*p++ = 0xa3 - c1 + LC_CNS11643_3;
}
*p++ = *euc++;
*p++ = *euc++;
} else if (c1 & 0x80) { /* CNS11643-1 */
len -= 2;
*p++ = LC_CNS11643_1;
*p++ = c1;
*p++ = *euc++;
} else { /* should be ASCII */
len --;
*p++ = c1;
}
}
*p = '\0';
while (len > 0 && (c1 = *euc++))
{
if (c1 == SS2)
{
len -= 4;
c1 = *euc++; /* plane No. */
if (c1 == 0xa1)
*p++ = LC_CNS11643_1;
else if (c1 == 0xa2)
*p++ = LC_CNS11643_2;
else
{
*p++ = 0x9d; /* LCPRV2 */
*p++ = 0xa3 - c1 + LC_CNS11643_3;
}
*p++ = *euc++;
*p++ = *euc++;
}
else if (c1 & 0x80)
{ /* CNS11643-1 */
len -= 2;
*p++ = LC_CNS11643_1;
*p++ = c1;
*p++ = *euc++;
}
else
{ /* should be ASCII */
len--;
*p++ = c1;
}
}
*p = '\0';
}
/*
* MIC ---> EUC_TW
*/
static void mic2euc_tw(unsigned char *mic, unsigned char *p, int len)
static void
mic2euc_tw(unsigned char *mic, unsigned char *p, int len)
{
int c1;
int c1;
while (len > 0 && (c1 = *mic)) {
len -= pg_mic_mblen(mic++);
while (len > 0 && (c1 = *mic))
{
len -= pg_mic_mblen(mic++);
if (c1 == LC_CNS11643_1 || c1 == LC_CNS11643_2) {
*p++ = *mic++;
*p++ = *mic++;
} else if (c1 == 0x9d) { /* LCPRV2? */
*p++ = SS2;
*p++ = c1 - LC_CNS11643_3 + 0xa3;
*p++ = *mic++;
*p++ = *mic++;
} else if (c1 > 0x7f) { /* cannot convert to EUC_TW! */
mic--;
printBogusChar(&mic, &p);
} else { /* should be ASCII */
*p++ = c1;
}
}
*p = '\0';
if (c1 == LC_CNS11643_1 || c1 == LC_CNS11643_2)
{
*p++ = *mic++;
*p++ = *mic++;
}
else if (c1 == 0x9d)
{ /* LCPRV2? */
*p++ = SS2;
*p++ = c1 - LC_CNS11643_3 + 0xa3;
*p++ = *mic++;
*p++ = *mic++;
}
else if (c1 > 0x7f)
{ /* cannot convert to EUC_TW! */
mic--;
printBogusChar(&mic, &p);
}
else
{ /* should be ASCII */
*p++ = c1;
}
}
*p = '\0';
}
/*
* LATINn ---> MIC
*/
static void latin2mic(unsigned char *l, unsigned char *p, int len, int lc)
static void
latin2mic(unsigned char *l, unsigned char *p, int len, int lc)
{
int c1;
int c1;
while (len-- > 0 && (c1 = *l++)) {
if (c1 > 0x7f) { /* Latin1? */
*p++ = lc;
}
*p++ = c1;
}
*p = '\0';
while (len-- > 0 && (c1 = *l++))
{
if (c1 > 0x7f)
{ /* Latin1? */
*p++ = lc;
}
*p++ = c1;
}
*p = '\0';
}
/*
* MIC ---> LATINn
*/
static void mic2latin(unsigned char *mic, unsigned char *p, int len, int lc)
static void
mic2latin(unsigned char *mic, unsigned char *p, int len, int lc)
{
int c1;
int c1;
while (len > 0 && (c1 = *mic)) {
len -= pg_mic_mblen(mic++);
while (len > 0 && (c1 = *mic))
{
len -= pg_mic_mblen(mic++);
if (c1 == lc) {
*p++ = *mic++;
} else if (c1 > 0x7f) {
mic--;
printBogusChar(&mic, &p);
} else { /* should be ASCII */
*p++ = c1;
}
}
*p = '\0';
if (c1 == lc)
*p++ = *mic++;
else if (c1 > 0x7f)
{
mic--;
printBogusChar(&mic, &p);
}
else
{ /* should be ASCII */
*p++ = c1;
}
}
*p = '\0';
}
static void latin12mic(unsigned char *l, unsigned char *p, int len)
static void
latin12mic(unsigned char *l, unsigned char *p, int len)
{
latin2mic(l, p, len, LC_ISO8859_1);
latin2mic(l, p, len, LC_ISO8859_1);
}
static void mic2latin1(unsigned char *mic, unsigned char *p, int len)
static void
mic2latin1(unsigned char *mic, unsigned char *p, int len)
{
mic2latin(mic, p, len, LC_ISO8859_1);
mic2latin(mic, p, len, LC_ISO8859_1);
}
static void latin22mic(unsigned char *l, unsigned char *p, int len)
static void
latin22mic(unsigned char *l, unsigned char *p, int len)
{
latin2mic(l, p, len, LC_ISO8859_2);
latin2mic(l, p, len, LC_ISO8859_2);
}
static void mic2latin2(unsigned char *mic, unsigned char *p, int len)
static void
mic2latin2(unsigned char *mic, unsigned char *p, int len)
{
mic2latin(mic, p, len, LC_ISO8859_2);
mic2latin(mic, p, len, LC_ISO8859_2);
}
static void latin32mic(unsigned char *l, unsigned char *p, int len)
static void
latin32mic(unsigned char *l, unsigned char *p, int len)
{
latin2mic(l, p, len, LC_ISO8859_3);
latin2mic(l, p, len, LC_ISO8859_3);
}
static void mic2latin3(unsigned char *mic, unsigned char *p, int len)
static void
mic2latin3(unsigned char *mic, unsigned char *p, int len)
{
mic2latin(mic, p, len, LC_ISO8859_3);
mic2latin(mic, p, len, LC_ISO8859_3);
}
static void latin42mic(unsigned char *l, unsigned char *p, int len)
static void
latin42mic(unsigned char *l, unsigned char *p, int len)
{
latin2mic(l, p, len, LC_ISO8859_4);
latin2mic(l, p, len, LC_ISO8859_4);
}
static void mic2latin4(unsigned char *mic, unsigned char *p, int len)
static void
mic2latin4(unsigned char *mic, unsigned char *p, int len)
{
mic2latin(mic, p, len, LC_ISO8859_4);
mic2latin(mic, p, len, LC_ISO8859_4);
}
static void latin52mic(unsigned char *l, unsigned char *p, int len)
static void
latin52mic(unsigned char *l, unsigned char *p, int len)
{
latin2mic(l, p, len, LC_ISO8859_5);
latin2mic(l, p, len, LC_ISO8859_5);
}
static void mic2latin5(unsigned char *mic, unsigned char *p, int len)
static void
mic2latin5(unsigned char *mic, unsigned char *p, int len)
{
mic2latin(mic, p, len, LC_ISO8859_5);
mic2latin(mic, p, len, LC_ISO8859_5);
}
/*
* ASCII ---> MIC
*/
static void ascii2mic(unsigned char *l, unsigned char *p, int len)
static void
ascii2mic(unsigned char *l, unsigned char *p, int len)
{
int c1;
int c1;
while (len-- > 0 && (c1 = *l++)) {
*p++ = (c1 & 0x7f);
}
*p = '\0';
while (len-- > 0 && (c1 = *l++))
*p++ = (c1 & 0x7f);
*p = '\0';
}
/*
* MIC ---> ASCII
*/
static void mic2ascii(unsigned char *mic, unsigned char *p, int len)
static void
mic2ascii(unsigned char *mic, unsigned char *p, int len)
{
int c1;
int c1;
while (len > 0 && (c1 = *mic)) {
if (c1 > 0x7f) {
printBogusChar(&mic, &p);
} else { /* should be ASCII */
*p++ = c1;
}
}
*p = '\0';
while (len > 0 && (c1 = *mic))
{
if (c1 > 0x7f)
printBogusChar(&mic, &p);
else
{ /* should be ASCII */
*p++ = c1;
}
}
*p = '\0';
}
pg_encoding_conv_tbl pg_conv_tbl[] = {
{SQL_ASCII, "SQL_ASCII", 0, ascii2mic, mic2ascii}, /* SQL/ACII */
{EUC_JP, "EUC_JP", 0, euc_jp2mic, mic2euc_jp}, /* EUC_JP */
{EUC_CN, "EUC_CN", 0, euc_cn2mic, mic2euc_cn}, /* EUC_CN */
{EUC_KR, "EUC_KR", 0, euc_kr2mic, mic2euc_kr}, /* EUC_KR */
{EUC_TW, "EUC_TW", 0, euc_tw2mic, mic2euc_tw}, /* EUC_TW */
{UNICODE, "UNICODE", 0, 0, 0}, /* UNICODE */
{MULE_INTERNAL, "MULE_INTERNAL", 0, 0, 0}, /* MULE_INTERNAL */
{LATIN1, "LATIN1", 0, latin12mic, mic2latin1}, /* ISO 8859 Latin 1 */
{LATIN2, "LATIN2", 0, latin22mic, mic2latin2}, /* ISO 8859 Latin 2 */
{LATIN3, "LATIN3", 0, latin32mic, mic2latin3}, /* ISO 8859 Latin 3 */
{LATIN4, "LATIN4", 0, latin42mic, mic2latin4}, /* ISO 8859 Latin 4 */
{LATIN5, "LATIN5", 0, latin52mic, mic2latin5}, /* ISO 8859 Latin 5 */
{SJIS, "SJIS", 1, sjis2mic, mic2sjis}, /* SJIS */
{-1, "", 0, 0, 0} /* end mark */
{SQL_ASCII, "SQL_ASCII", 0, ascii2mic, mic2ascii}, /* SQL/ACII */
{EUC_JP, "EUC_JP", 0, euc_jp2mic, mic2euc_jp}, /* EUC_JP */
{EUC_CN, "EUC_CN", 0, euc_cn2mic, mic2euc_cn}, /* EUC_CN */
{EUC_KR, "EUC_KR", 0, euc_kr2mic, mic2euc_kr}, /* EUC_KR */
{EUC_TW, "EUC_TW", 0, euc_tw2mic, mic2euc_tw}, /* EUC_TW */
{UNICODE, "UNICODE", 0, 0, 0}, /* UNICODE */
{MULE_INTERNAL, "MULE_INTERNAL", 0, 0, 0}, /* MULE_INTERNAL */
{LATIN1, "LATIN1", 0, latin12mic, mic2latin1}, /* ISO 8859 Latin 1 */
{LATIN2, "LATIN2", 0, latin22mic, mic2latin2}, /* ISO 8859 Latin 2 */
{LATIN3, "LATIN3", 0, latin32mic, mic2latin3}, /* ISO 8859 Latin 3 */
{LATIN4, "LATIN4", 0, latin42mic, mic2latin4}, /* ISO 8859 Latin 4 */
{LATIN5, "LATIN5", 0, latin52mic, mic2latin5}, /* ISO 8859 Latin 5 */
{SJIS, "SJIS", 1, sjis2mic, mic2sjis}, /* SJIS */
{-1, "", 0, 0, 0} /* end mark */
};

View File

@@ -3,7 +3,7 @@
* client encoding and server internal encoding.
* (currently mule internal code (mic) is used)
* Tatsuo Ishii
* $Id: mbutils.c,v 1.2 1998/07/26 04:31:04 scrappy Exp $ */
* $Id: mbutils.c,v 1.3 1998/09/01 04:33:22 momjian Exp $ */
#include <stdio.h>
#include <string.h>
@@ -11,77 +11,85 @@
#include "mb/pg_wchar.h"
static client_encoding = -1;
static void (*client_to_mic)(); /* something to MIC */
static void (*client_from_mic)(); /* MIC to something */
static void (*server_to_mic)(); /* something to MIC */
static void (*server_from_mic)(); /* MIC to something */
static void (*client_to_mic) ();/* something to MIC */
static void (*client_from_mic) (); /* MIC to something */
static void (*server_to_mic) ();/* something to MIC */
static void (*server_from_mic) (); /* MIC to something */
/*
* find encoding table entry by encoding
*/
static pg_encoding_conv_tbl *get_enc_ent(int encoding)
static pg_encoding_conv_tbl *
get_enc_ent(int encoding)
{
pg_encoding_conv_tbl *p = pg_conv_tbl;
for(;p->encoding >= 0;p++) {
if (p->encoding == encoding) {
return(p);
}
}
return(0);
pg_encoding_conv_tbl *p = pg_conv_tbl;
for (; p->encoding >= 0; p++)
{
if (p->encoding == encoding)
return (p);
}
return (0);
}
/*
* set the client encoding. if client/server encoding is
* not supported, returns -1
*/
int pg_set_client_encoding(int encoding)
int
pg_set_client_encoding(int encoding)
{
int current_server_encoding = GetDatabaseEncoding();
int current_server_encoding = GetDatabaseEncoding();
client_encoding = encoding;
client_encoding = encoding;
if (client_encoding == current_server_encoding) { /* server == client? */
client_to_mic = client_from_mic = 0;
server_to_mic = server_from_mic = 0;
} else if (current_server_encoding == MULE_INTERNAL) { /* server == MULE_INETRNAL? */
client_to_mic = get_enc_ent(encoding)->to_mic;
client_from_mic = get_enc_ent(encoding)->from_mic;
server_to_mic = server_from_mic = 0;
if (client_to_mic == 0 || client_from_mic == 0) {
return(-1);
}
} else if (encoding == MULE_INTERNAL) { /* client == MULE_INETRNAL? */
client_to_mic = client_from_mic = 0;
server_to_mic = get_enc_ent(current_server_encoding)->to_mic;
server_from_mic = get_enc_ent(current_server_encoding)->from_mic;
if (server_to_mic == 0 || server_from_mic == 0) {
return(-1);
}
} else {
client_to_mic = get_enc_ent(encoding)->to_mic;
client_from_mic = get_enc_ent(encoding)->from_mic;
server_to_mic = get_enc_ent(current_server_encoding)->to_mic;
server_from_mic = get_enc_ent(current_server_encoding)->from_mic;
if (client_to_mic == 0 || client_from_mic == 0) {
return(-1);
}
if (server_to_mic == 0 || server_from_mic == 0) {
return(-1);
}
}
return(0);
if (client_encoding == current_server_encoding)
{ /* server == client? */
client_to_mic = client_from_mic = 0;
server_to_mic = server_from_mic = 0;
}
else if (current_server_encoding == MULE_INTERNAL)
{ /* server == MULE_INETRNAL? */
client_to_mic = get_enc_ent(encoding)->to_mic;
client_from_mic = get_enc_ent(encoding)->from_mic;
server_to_mic = server_from_mic = 0;
if (client_to_mic == 0 || client_from_mic == 0)
return (-1);
}
else if (encoding == MULE_INTERNAL)
{ /* client == MULE_INETRNAL? */
client_to_mic = client_from_mic = 0;
server_to_mic = get_enc_ent(current_server_encoding)->to_mic;
server_from_mic = get_enc_ent(current_server_encoding)->from_mic;
if (server_to_mic == 0 || server_from_mic == 0)
return (-1);
}
else
{
client_to_mic = get_enc_ent(encoding)->to_mic;
client_from_mic = get_enc_ent(encoding)->from_mic;
server_to_mic = get_enc_ent(current_server_encoding)->to_mic;
server_from_mic = get_enc_ent(current_server_encoding)->from_mic;
if (client_to_mic == 0 || client_from_mic == 0)
return (-1);
if (server_to_mic == 0 || server_from_mic == 0)
return (-1);
}
return (0);
}
/*
* returns the current client encoding
*/
int pg_get_client_encoding()
int
pg_get_client_encoding()
{
if (client_encoding == -1) {
/* this is the first time */
client_encoding = GetDatabaseEncoding();
}
return(client_encoding);
if (client_encoding == -1)
{
/* this is the first time */
client_encoding = GetDatabaseEncoding();
}
return (client_encoding);
}
/*
@@ -89,25 +97,27 @@ int pg_get_client_encoding()
* client_encoding or no conversion function exists,
* returns s. So be careful.
*/
unsigned char *pg_client_to_server(unsigned char *s, int len)
unsigned char *
pg_client_to_server(unsigned char *s, int len)
{
static unsigned char b1[MAX_PARSE_BUFFER*4]; /* is this enough? */
static unsigned char b2[MAX_PARSE_BUFFER*4]; /* is this enough? */
unsigned char *p = s;
static unsigned char b1[MAX_PARSE_BUFFER * 4]; /* is this enough? */
static unsigned char b2[MAX_PARSE_BUFFER * 4]; /* is this enough? */
unsigned char *p = s;
if (client_encoding == GetDatabaseEncoding()) {
return(p);
}
if (client_to_mic) {
(*client_to_mic)(s, b1, len);
len = strlen(b1);
p = b1;
}
if (server_from_mic) {
(*server_from_mic)(p, b2, len);
p = b2;
}
return(p);
if (client_encoding == GetDatabaseEncoding())
return (p);
if (client_to_mic)
{
(*client_to_mic) (s, b1, len);
len = strlen(b1);
p = b1;
}
if (server_from_mic)
{
(*server_from_mic) (p, b2, len);
p = b2;
}
return (p);
}
/*
@@ -115,102 +125,115 @@ unsigned char *pg_client_to_server(unsigned char *s, int len)
* client_encoding or no conversion function exists,
* returns s. So be careful.
*/
unsigned char *pg_server_to_client(unsigned char *s, int len)
unsigned char *
pg_server_to_client(unsigned char *s, int len)
{
static unsigned char b1[MAX_PARSE_BUFFER*4]; /* is this enough? */
static unsigned char b2[MAX_PARSE_BUFFER*4]; /* is this enough? */
unsigned char *p = s;
static unsigned char b1[MAX_PARSE_BUFFER * 4]; /* is this enough? */
static unsigned char b2[MAX_PARSE_BUFFER * 4]; /* is this enough? */
unsigned char *p = s;
if (client_encoding == GetDatabaseEncoding()) {
return(p);
}
if (server_to_mic) {
(*server_to_mic)(s, b1, len);
len = strlen(b1);
p = b1;
}
if (client_from_mic) {
(*client_from_mic)(p, b2, len);
p = b2;
}
return(p);
if (client_encoding == GetDatabaseEncoding())
return (p);
if (server_to_mic)
{
(*server_to_mic) (s, b1, len);
len = strlen(b1);
p = b1;
}
if (client_from_mic)
{
(*client_from_mic) (p, b2, len);
p = b2;
}
return (p);
}
/* convert a multi-byte string to a wchar */
void pg_mb2wchar(const unsigned char *from, pg_wchar *to)
void
pg_mb2wchar(const unsigned char *from, pg_wchar * to)
{
(*pg_wchar_table[GetDatabaseEncoding()].mb2wchar_with_len)(from,to,strlen(from));
(*pg_wchar_table[GetDatabaseEncoding()].mb2wchar_with_len) (from, to, strlen(from));
}
/* convert a multi-byte string to a wchar with a limited length */
void pg_mb2wchar_with_len(const unsigned char *from, pg_wchar *to, int len)
void
pg_mb2wchar_with_len(const unsigned char *from, pg_wchar * to, int len)
{
(*pg_wchar_table[GetDatabaseEncoding()].mb2wchar_with_len)(from,to,len);
(*pg_wchar_table[GetDatabaseEncoding()].mb2wchar_with_len) (from, to, len);
}
/* returns the byte length of a multi-byte word */
int pg_mblen(const unsigned char *mbstr)
int
pg_mblen(const unsigned char *mbstr)
{
return((*pg_wchar_table[GetDatabaseEncoding()].mblen)(mbstr));
return ((*pg_wchar_table[GetDatabaseEncoding()].mblen) (mbstr));
}
/* returns the length (counted as a wchar) of a multi-byte string */
int pg_mbstrlen(const unsigned char *mbstr)
int
pg_mbstrlen(const unsigned char *mbstr)
{
int len = 0;
while (*mbstr) {
mbstr += pg_mblen(mbstr);
len++;
}
return(len);
int len = 0;
while (*mbstr)
{
mbstr += pg_mblen(mbstr);
len++;
}
return (len);
}
/* returns the length (counted as a wchar) of a multi-byte string
/* returns the length (counted as a wchar) of a multi-byte string
(not necessarily NULL terminated) */
int pg_mbstrlen_with_len(const unsigned char *mbstr, int limit)
int
pg_mbstrlen_with_len(const unsigned char *mbstr, int limit)
{
int len = 0;
int l;
while (*mbstr && limit > 0) {
l = pg_mblen(mbstr);
limit -= l;
mbstr += l;
len++;
}
return(len);
int len = 0;
int l;
while (*mbstr && limit > 0)
{
l = pg_mblen(mbstr);
limit -= l;
mbstr += l;
len++;
}
return (len);
}
/*
* fuctions for utils/init
*/
static int DatabaseEncoding = MULTIBYTE;
static int DatabaseEncoding = MULTIBYTE;
void
SetDatabaseEncoding(int encoding)
{
DatabaseEncoding = encoding;
DatabaseEncoding = encoding;
}
int
GetDatabaseEncoding()
{
return(DatabaseEncoding);
return (DatabaseEncoding);
}
/* for builtin-function */
const char *
getdatabaseencoding()
{
return(pg_encoding_to_char(DatabaseEncoding));
return (pg_encoding_to_char(DatabaseEncoding));
}
/* set and get template1 database encoding */
static int templateEncoding;
void SetTemplateEncoding(int encoding)
static int templateEncoding;
void
SetTemplateEncoding(int encoding)
{
templateEncoding = encoding;
templateEncoding = encoding;
}
int GetTemplateEncoding()
int
GetTemplateEncoding()
{
return(templateEncoding);
return (templateEncoding);
}

View File

@@ -1,6 +1,6 @@
/*
* testing of utf2wchar()
* $Id: utftest.c,v 1.1 1998/07/24 03:31:57 scrappy Exp $
* $Id: utftest.c,v 1.2 1998/09/01 04:33:23 momjian Exp $
*/
#include <regex/regex.h>
#include <regex/utils.h>
@@ -10,24 +10,28 @@
main()
{
/* Example 1 from RFC2044 */
char utf1[] = {0x41,0xe2,0x89,0xa2,0xce,0x91,0x2e,0};
/* Example 2 from RFC2044 */
char utf2[] = {0x48,0x69,0x20,0x4d,0x6f,0x6d,0x20,0xe2,0x98,0xba,0x21,0};
/* Example 3 from RFC2044 */
char utf3[] = {0xe6,0x97,0xa5,0xe6,0x9c,0xac,0xe8,0xaa,0x9e,0};
char *utf[] = {utf1,utf2,utf3};
pg_wchar ucs[128];
pg_wchar *p;
int i;
/* Example 1 from RFC2044 */
char utf1[] = {0x41, 0xe2, 0x89, 0xa2, 0xce, 0x91, 0x2e, 0};
for (i=0;i<sizeof(utf)/sizeof(char *);i++) {
pg_utf2wchar(utf[i],ucs);
p = ucs;
while(*p) {
printf("%04x ",*p);
p++;
}
printf("\n");
}
/* Example 2 from RFC2044 */
char utf2[] = {0x48, 0x69, 0x20, 0x4d, 0x6f, 0x6d, 0x20, 0xe2, 0x98, 0xba, 0x21, 0};
/* Example 3 from RFC2044 */
char utf3[] = {0xe6, 0x97, 0xa5, 0xe6, 0x9c, 0xac, 0xe8, 0xaa, 0x9e, 0};
char *utf[] = {utf1, utf2, utf3};
pg_wchar ucs[128];
pg_wchar *p;
int i;
for (i = 0; i < sizeof(utf) / sizeof(char *); i++)
{
pg_utf2wchar(utf[i], ucs);
p = ucs;
while (*p)
{
printf("%04x ", *p);
p++;
}
printf("\n");
}
}

View File

@@ -2,7 +2,7 @@
* This file contains some public functions
* related to show/set/reset variable commands.
* Tatsuo Ishii
* $Id: variable.c,v 1.1 1998/07/24 03:31:57 scrappy Exp $
* $Id: variable.c,v 1.2 1998/09/01 04:33:24 momjian Exp $
*/
#include "mb/pg_wchar.h"
@@ -10,64 +10,66 @@
bool
parse_client_encoding(const char *value)
{
int encoding;
int encoding;
encoding = pg_valid_client_encoding(value);
if (encoding < 0) {
elog(ERROR, "Client encoding %s is not supported", value);
} else {
if (pg_set_client_encoding(encoding)) {
elog(ERROR, "Conversion between %s and %s is not supported",
value, pg_encoding_to_char(GetDatabaseEncoding()));
}
}
return TRUE;
encoding = pg_valid_client_encoding(value);
if (encoding < 0)
elog(ERROR, "Client encoding %s is not supported", value);
else
{
if (pg_set_client_encoding(encoding))
{
elog(ERROR, "Conversion between %s and %s is not supported",
value, pg_encoding_to_char(GetDatabaseEncoding()));
}
}
return TRUE;
}
bool
show_client_encoding()
{
elog(NOTICE, "Current client encoding is %s",
pg_encoding_to_char(pg_get_client_encoding()));
return TRUE;
elog(NOTICE, "Current client encoding is %s",
pg_encoding_to_char(pg_get_client_encoding()));
return TRUE;
}
bool
reset_client_encoding()
{
int encoding;
char *env = getenv("PGCLIENTENCODING");
int encoding;
char *env = getenv("PGCLIENTENCODING");
if (env) {
encoding = pg_char_to_encoding(env);
if (encoding < 0) {
encoding = GetDatabaseEncoding();
}
} else {
encoding = GetDatabaseEncoding();
}
pg_set_client_encoding(encoding);
return TRUE;
if (env)
{
encoding = pg_char_to_encoding(env);
if (encoding < 0)
encoding = GetDatabaseEncoding();
}
else
encoding = GetDatabaseEncoding();
pg_set_client_encoding(encoding);
return TRUE;
}
bool
parse_server_encoding(const char *value)
{
elog(NOTICE, "SET SERVER_ENCODING is not supported");
return TRUE;
elog(NOTICE, "SET SERVER_ENCODING is not supported");
return TRUE;
}
bool
show_server_encoding()
{
elog(NOTICE, "Current server encoding is %s",
pg_encoding_to_char(GetDatabaseEncoding()));
return TRUE;
elog(NOTICE, "Current server encoding is %s",
pg_encoding_to_char(GetDatabaseEncoding()));
return TRUE;
}
bool
reset_server_encoding()
{
elog(NOTICE, "RESET SERVER_ENCODING is not supported");
return TRUE;
elog(NOTICE, "RESET SERVER_ENCODING is not supported");
return TRUE;
}

View File

@@ -1,7 +1,7 @@
/*
* conversion functions between pg_wchar and multi-byte streams.
* Tatsuo Ishii
* $Id: wchar.c,v 1.3 1998/08/25 04:19:16 momjian Exp $
* $Id: wchar.c,v 1.4 1998/09/01 04:33:26 momjian Exp $
*/
#include "mb/pg_wchar.h"
@@ -10,7 +10,7 @@
* conversion to pg_wchar is done by "table driven."
* to add an encoding support, define mb2wchar_with_len(), mblen()
* for the particular encoding. Note that if the encoding is only
* supported in the client, you don't need to define
* supported in the client, you don't need to define
* mb2wchar_with_len() function (SJIS is the case).
*/
@@ -18,18 +18,20 @@
* SQL/ASCII
*/
static void pg_ascii2wchar_with_len
(const unsigned char *from, pg_wchar *to, int len)
(const unsigned char *from, pg_wchar * to, int len)
{
while (*from && len > 0) {
*to++ = *from++;
len--;
}
*to = 0;
while (*from && len > 0)
{
*to++ = *from++;
len--;
}
*to = 0;
}
static int pg_ascii_mblen(const unsigned char *s)
static int
pg_ascii_mblen(const unsigned char *s)
{
return(1);
return (1);
}
/*
@@ -37,169 +39,195 @@ static int pg_ascii_mblen(const unsigned char *s)
*/
static void pg_euc2wchar_with_len
(const unsigned char *from, pg_wchar *to, int len)
(const unsigned char *from, pg_wchar * to, int len)
{
while (*from && len > 0) {
if (*from == SS2) {
from++;
len--;
*to = 0xff & *from++;
len--;
} else if (*from == SS3) {
from++;
*to = *from++ << 8;
*to |= 0x3f & *from++;
len -= 3;
} else if (*from & 0x80) {
*to = *from++ << 8;
*to |= *from++;
len -= 2;
} else {
*to = *from++;
len--;
}
to++;
}
*to = 0;
while (*from && len > 0)
{
if (*from == SS2)
{
from++;
len--;
*to = 0xff & *from++;
len--;
}
else if (*from == SS3)
{
from++;
*to = *from++ << 8;
*to |= 0x3f & *from++;
len -= 3;
}
else if (*from & 0x80)
{
*to = *from++ << 8;
*to |= *from++;
len -= 2;
}
else
{
*to = *from++;
len--;
}
to++;
}
*to = 0;
}
static int pg_euc_mblen(const unsigned char *s)
static int
pg_euc_mblen(const unsigned char *s)
{
int len;
int len;
if (*s == SS2) {
len = 2;
} else if (*s == SS3) {
len = 3;
} else if (*s & 0x80) {
len = 2;
} else {
len = 1;
}
return(len);
if (*s == SS2)
len = 2;
else if (*s == SS3)
len = 3;
else if (*s & 0x80)
len = 2;
else
len = 1;
return (len);
}
/*
* EUC_JP
*/
static void pg_eucjp2wchar_with_len
(const unsigned char *from, pg_wchar *to, int len)
(const unsigned char *from, pg_wchar * to, int len)
{
pg_euc2wchar_with_len(from,to,len);
pg_euc2wchar_with_len(from, to, len);
}
static int pg_eucjp_mblen(const unsigned char *s)
static int
pg_eucjp_mblen(const unsigned char *s)
{
return(pg_euc_mblen(s));
return (pg_euc_mblen(s));
}
/*
* EUC_KR
*/
static void pg_euckr2wchar_with_len
(const unsigned char *from, pg_wchar *to, int len)
(const unsigned char *from, pg_wchar * to, int len)
{
pg_euc2wchar_with_len(from,to,len);
pg_euc2wchar_with_len(from, to, len);
}
static int pg_euckr_mblen(const unsigned char *s)
static int
pg_euckr_mblen(const unsigned char *s)
{
return(pg_euc_mblen(s));
return (pg_euc_mblen(s));
}
/*
* EUC_CN
*/
static void pg_euccn2wchar_with_len
(const unsigned char *from, pg_wchar *to, int len)
(const unsigned char *from, pg_wchar * to, int len)
{
while (*from && len > 0) {
if (*from == SS2) {
from++;
len--;
*to = 0x3f00 & (*from++ << 8);
*to = *from++;
len -= 2;
} else if (*from == SS3) {
from++;
*to = *from++ << 8;
*to |= 0x3f & *from++;
len -= 3;
} else if (*from & 0x80) {
*to = *from++ << 8;
*to |= *from++;
len -= 2;
} else {
*to = *from++;
len--;
}
to++;
}
*to = 0;
while (*from && len > 0)
{
if (*from == SS2)
{
from++;
len--;
*to = 0x3f00 & (*from++ << 8);
*to = *from++;
len -= 2;
}
else if (*from == SS3)
{
from++;
*to = *from++ << 8;
*to |= 0x3f & *from++;
len -= 3;
}
else if (*from & 0x80)
{
*to = *from++ << 8;
*to |= *from++;
len -= 2;
}
else
{
*to = *from++;
len--;
}
to++;
}
*to = 0;
}
static int pg_euccn_mblen(const unsigned char *s)
static int
pg_euccn_mblen(const unsigned char *s)
{
int len;
int len;
if (*s == SS2) {
len = 3;
} else if (*s == SS3) {
len = 3;
} else if (*s & 0x80) {
len = 2;
} else {
len = 1;
}
return(len);
if (*s == SS2)
len = 3;
else if (*s == SS3)
len = 3;
else if (*s & 0x80)
len = 2;
else
len = 1;
return (len);
}
/*
* EUC_TW
*/
static void pg_euctw2wchar_with_len
(const unsigned char *from, pg_wchar *to, int len)
(const unsigned char *from, pg_wchar * to, int len)
{
while (*from && len > 0) {
if (*from == SS2) {
from++;
len--;
*to = *from++ << 16;
*to |= *from++ << 8;
*to |= *from++;
len -= 3;
} else if (*from == SS3) {
from++;
*to = *from++ << 8;
*to |= 0x3f & *from++;
len -= 3;
} else if (*from & 0x80) {
*to = *from++ << 8;
*to |= *from++;
len -= 2;
} else {
*to = *from++;
len--;
}
to++;
}
*to = 0;
while (*from && len > 0)
{
if (*from == SS2)
{
from++;
len--;
*to = *from++ << 16;
*to |= *from++ << 8;
*to |= *from++;
len -= 3;
}
else if (*from == SS3)
{
from++;
*to = *from++ << 8;
*to |= 0x3f & *from++;
len -= 3;
}
else if (*from & 0x80)
{
*to = *from++ << 8;
*to |= *from++;
len -= 2;
}
else
{
*to = *from++;
len--;
}
to++;
}
*to = 0;
}
static int pg_euctw_mblen(const unsigned char *s)
static int
pg_euctw_mblen(const unsigned char *s)
{
int len;
int len;
if (*s == SS2) {
len = 4;
} else if (*s == SS3) {
len = 3;
} else if (*s & 0x80) {
len = 2;
} else {
len = 1;
}
return(len);
if (*s == SS2)
len = 4;
else if (*s == SS3)
len = 3;
else if (*s & 0x80)
len = 2;
else
len = 1;
return (len);
}
/*
@@ -208,45 +236,55 @@ static int pg_euctw_mblen(const unsigned char *s)
* len: length of from.
* "from" not necessarily null terminated.
*/
static void pg_utf2wchar_with_len(const unsigned char *from, pg_wchar *to, int len)
static void
pg_utf2wchar_with_len(const unsigned char *from, pg_wchar * to, int len)
{
unsigned char c1,c2,c3;
while (*from && len > 0) {
if ((*from & 0x80) == 0) {
*to = *from++;
len--;
} else if ((*from & 0xe0) == 0xc0) {
c1 = *from++ & 0x1f;
c2 = *from++ & 0x3f;
len -= 2;
*to = c1 << 6;
*to |= c2;
} else if ((*from & 0xe0) == 0xe0) {
c1 = *from++ & 0x0f;
c2 = *from++ & 0x3f;
c3 = *from++ & 0x3f;
len -= 3;
*to = c1 << 12;
*to |= c2 << 6;
*to |= c3;
}
to++;
}
*to = 0;
unsigned char c1,
c2,
c3;
while (*from && len > 0)
{
if ((*from & 0x80) == 0)
{
*to = *from++;
len--;
}
else if ((*from & 0xe0) == 0xc0)
{
c1 = *from++ & 0x1f;
c2 = *from++ & 0x3f;
len -= 2;
*to = c1 << 6;
*to |= c2;
}
else if ((*from & 0xe0) == 0xe0)
{
c1 = *from++ & 0x0f;
c2 = *from++ & 0x3f;
c3 = *from++ & 0x3f;
len -= 3;
*to = c1 << 12;
*to |= c2 << 6;
*to |= c3;
}
to++;
}
*to = 0;
}
static int pg_utf_mblen(const unsigned char *s)
static int
pg_utf_mblen(const unsigned char *s)
{
int len = 1;
int len = 1;
if ((*s & 0x80) == 0) {
len = 1;
} else if ((*s & 0xe0) == 0xc0) {
len = 2;
} else if ((*s & 0xe0) == 0xe0) {
len = 3;
}
return(len);
if ((*s & 0x80) == 0)
len = 1;
else if ((*s & 0xe0) == 0xc0)
len = 2;
else if ((*s & 0xe0) == 0xe0)
len = 3;
return (len);
}
/*
@@ -255,127 +293,148 @@ static int pg_utf_mblen(const unsigned char *s)
* len: length of from.
* "from" not necessarily null terminated.
*/
static void pg_mule2wchar_with_len(const unsigned char *from, pg_wchar *to, int len)
static void
pg_mule2wchar_with_len(const unsigned char *from, pg_wchar * to, int len)
{
while (*from && len > 0) {
if (IS_LC1(*from)) {
*to = *from++ << 16;
*to |= *from++;
len -= 2;
} else if (IS_LCPRV1(*from)) {
from++;
*to = *from++ << 16;
*to |= *from++;
len -= 3;
} else if (IS_LC2(*from)) {
*to = *from++ << 16;
*to |= *from++ << 8;
*to |= *from++;
len -= 3;
} else if (IS_LCPRV2(*from)) {
from++;
*to = *from++ << 16;
*to |= *from++ << 8;
*to |= *from++;
len -= 4;
} else { /* assume ASCII */
*to = (unsigned char)*from++;
len--;
}
to++;
}
*to = 0;
while (*from && len > 0)
{
if (IS_LC1(*from))
{
*to = *from++ << 16;
*to |= *from++;
len -= 2;
}
else if (IS_LCPRV1(*from))
{
from++;
*to = *from++ << 16;
*to |= *from++;
len -= 3;
}
else if (IS_LC2(*from))
{
*to = *from++ << 16;
*to |= *from++ << 8;
*to |= *from++;
len -= 3;
}
else if (IS_LCPRV2(*from))
{
from++;
*to = *from++ << 16;
*to |= *from++ << 8;
*to |= *from++;
len -= 4;
}
else
{ /* assume ASCII */
*to = (unsigned char) *from++;
len--;
}
to++;
}
*to = 0;
}
int pg_mule_mblen(const unsigned char *s)
int
pg_mule_mblen(const unsigned char *s)
{
int len;
int len;
if (IS_LC1(*s)) {
len = 2;
} else if (IS_LCPRV1(*s)) {
len = 3;
} else if (IS_LC2(*s)) {
len = 3;
} else if (IS_LCPRV2(*s)) {
len = 4;
} else { /* assume ASCII */
len = 1;
}
return(len);
if (IS_LC1(*s))
len = 2;
else if (IS_LCPRV1(*s))
len = 3;
else if (IS_LC2(*s))
len = 3;
else if (IS_LCPRV2(*s))
len = 4;
else
{ /* assume ASCII */
len = 1;
}
return (len);
}
/*
* ISO8859-1
*/
static void pg_latin12wchar_with_len(const unsigned char *from, pg_wchar *to, int len)
static void
pg_latin12wchar_with_len(const unsigned char *from, pg_wchar * to, int len)
{
while (*from && len-- > 0) {
*to++ = *from++;
}
*to = 0;
while (*from && len-- > 0)
*to++ = *from++;
*to = 0;
}
static int pg_latin1_mblen(const unsigned char *s)
static int
pg_latin1_mblen(const unsigned char *s)
{
return(1);
return (1);
}
/*
* SJIS
*/
static int pg_sjis_mblen(const unsigned char *s)
static int
pg_sjis_mblen(const unsigned char *s)
{
int len;
int len;
if (*s >= 0xa1 && *s <= 0xdf) { /* 1 byte kana? */
len = 1;
} else if (*s > 0x7f) { /* kanji? */
len = 2;
} else { /* should be ASCII */
len = 1;
}
return(len);
if (*s >= 0xa1 && *s <= 0xdf)
{ /* 1 byte kana? */
len = 1;
}
else if (*s > 0x7f)
{ /* kanji? */
len = 2;
}
else
{ /* should be ASCII */
len = 1;
}
return (len);
}
pg_wchar_tbl pg_wchar_table[] = {
{pg_ascii2wchar_with_len, pg_ascii_mblen},
{pg_eucjp2wchar_with_len, pg_eucjp_mblen},
{pg_euccn2wchar_with_len, pg_euccn_mblen},
{pg_euckr2wchar_with_len, pg_euckr_mblen},
{pg_euctw2wchar_with_len, pg_euctw_mblen},
{pg_utf2wchar_with_len, pg_utf_mblen},
{pg_mule2wchar_with_len, pg_mule_mblen},
{pg_latin12wchar_with_len, pg_latin1_mblen},
{pg_latin12wchar_with_len, pg_latin1_mblen},
{pg_latin12wchar_with_len, pg_latin1_mblen},
{pg_latin12wchar_with_len, pg_latin1_mblen},
{pg_latin12wchar_with_len, pg_latin1_mblen},
{0, 0},
{0, 0},
{0, 0},
{0, 0},
{0, 0},
{0, 0},
{0, 0},
{0, 0},
{0, 0},
{0, 0},
{0, 0},
{0, 0},
{0, 0},
{0, 0},
{0, 0},
{0, 0},
{0, 0},
{0, 0},
{0, 0},
{0, 0},
{0, pg_sjis_mblen}
{pg_ascii2wchar_with_len, pg_ascii_mblen},
{pg_eucjp2wchar_with_len, pg_eucjp_mblen},
{pg_euccn2wchar_with_len, pg_euccn_mblen},
{pg_euckr2wchar_with_len, pg_euckr_mblen},
{pg_euctw2wchar_with_len, pg_euctw_mblen},
{pg_utf2wchar_with_len, pg_utf_mblen},
{pg_mule2wchar_with_len, pg_mule_mblen},
{pg_latin12wchar_with_len, pg_latin1_mblen},
{pg_latin12wchar_with_len, pg_latin1_mblen},
{pg_latin12wchar_with_len, pg_latin1_mblen},
{pg_latin12wchar_with_len, pg_latin1_mblen},
{pg_latin12wchar_with_len, pg_latin1_mblen},
{0, 0},
{0, 0},
{0, 0},
{0, 0},
{0, 0},
{0, 0},
{0, 0},
{0, 0},
{0, 0},
{0, 0},
{0, 0},
{0, 0},
{0, 0},
{0, 0},
{0, 0},
{0, 0},
{0, 0},
{0, 0},
{0, 0},
{0, 0},
{0, pg_sjis_mblen}
};
/* returns the byte length of a word for mule internal code */
int pg_mic_mblen(const unsigned char *mbstr)
int
pg_mic_mblen(const unsigned char *mbstr)
{
return(pg_mule_mblen(mbstr));
return (pg_mule_mblen(mbstr));
}

View File

@@ -9,22 +9,22 @@
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
@@ -38,11 +38,11 @@
int
pg_char_and_wchar_strcmp(s1, s2)
register const char *s1;
register const pg_wchar *s2;
register const char *s1;
register const pg_wchar *s2;
{
while ((pg_wchar)*s1 == *s2++)
while ((pg_wchar) * s1 == *s2++)
if (*s1++ == 0)
return 0;
return *(const unsigned char *)s1 - *(const pg_wchar *)(s2 - 1);
return *(const unsigned char *) s1 - *(const pg_wchar *) (s2 - 1);
}

View File

@@ -8,22 +8,22 @@
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
@@ -37,16 +37,18 @@
int
pg_wchar_strncmp(s1, s2, n)
register const pg_wchar *s1, *s2;
register size_t n;
register const pg_wchar *s1,
*s2;
register size_t n;
{
if (n == 0)
return 0;
do {
do
{
if (*s1 != *s2++)
return (*(const pg_wchar *)s1 -
*(const pg_wchar *)(s2 - 1));
return (*(const pg_wchar *) s1 -
*(const pg_wchar *) (s2 - 1));
if (*s1++ == 0)
break;
} while (--n != 0);
@@ -55,17 +57,18 @@ pg_wchar_strncmp(s1, s2, n)
int
pg_char_and_wchar_strncmp(s1, s2, n)
register const char *s1;
register const pg_wchar *s2;
register size_t n;
register const char *s1;
register const pg_wchar *s2;
register size_t n;
{
if (n == 0)
return 0;
do {
if ((pg_wchar )*s1 != *s2++)
return (*(const pg_wchar *)s1 -
*(const pg_wchar *)(s2 - 1));
do
{
if ((pg_wchar) * s1 != *s2++)
return (*(const pg_wchar *) s1 -
*(const pg_wchar *) (s2 - 1));
if (*s1++ == 0)
break;
} while (--n != 0);
@@ -74,10 +77,10 @@ pg_char_and_wchar_strncmp(s1, s2, n)
size_t
pg_wchar_strlen(str)
const pg_wchar *str;
const pg_wchar *str;
{
register const pg_wchar *s;
for (s = str; *s; ++s);
return(s - str);
return (s - str);
}