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

pgindent run over code.

This commit is contained in:
Bruce Momjian
1999-05-25 16:15:34 +00:00
parent 4b04b01aaa
commit 07842084fe
413 changed files with 11723 additions and 10769 deletions

View File

@@ -4,63 +4,69 @@
*
* Tatsuo Ishii
*
* $Id: alt.c,v 1.1 1999/03/24 07:01:36 ishii Exp $
* $Id: alt.c,v 1.2 1999/05/25 16:12:38 momjian Exp $
*/
#include <stdio.h>
main()
{
int i;
char koitab[128],alttab[128];
char buf[4096];
int koi,alt;
int i;
char koitab[128],
alttab[128];
char buf[4096];
int koi,
alt;
for (i=0;i<128;i++) {
koitab[i] = alttab[i] = 0;
}
for (i = 0; i < 128; i++)
koitab[i] = alttab[i] = 0;
while (fgets(buf,sizeof(buf),stdin) != NULL) {
if (*buf == '#') {
continue;
}
sscanf(buf,"%d %d",&koi,&alt);
if (koi < 128 || koi > 255 || alt < 128 || alt > 255) {
fprintf(stderr,"invalid value %d\n",koi);
exit(1);
}
koitab[koi-128] = alt;
alttab[alt-128] = koi;
}
while (fgets(buf, sizeof(buf), stdin) != NULL)
{
if (*buf == '#')
continue;
sscanf(buf, "%d %d", &koi, &alt);
if (koi < 128 || koi > 255 || alt < 128 || alt > 255)
{
fprintf(stderr, "invalid value %d\n", koi);
exit(1);
}
koitab[koi - 128] = alt;
alttab[alt - 128] = koi;
}
i = 0;
printf("static char koi2alt[] = {\n");
while (i < 128) {
int j = 0;
while (j < 8) {
printf("0x%02x",koitab[i++]);
j++;
if (i >= 128) {
break;
}
printf(", ");
}
printf("\n");
}
printf("};\n");
i = 0;
printf("static char koi2alt[] = {\n");
while (i < 128)
{
int j = 0;
i = 0;
printf("static char alt2koi[] = {\n");
while (i < 128) {
int j = 0;
while (j < 8) {
printf("0x%02x",alttab[i++]);
j++;
if (i >= 128) {
break;
}
printf(", ");
}
printf("\n");
}
printf("};\n");
while (j < 8)
{
printf("0x%02x", koitab[i++]);
j++;
if (i >= 128)
break;
printf(", ");
}
printf("\n");
}
printf("};\n");
i = 0;
printf("static char alt2koi[] = {\n");
while (i < 128)
{
int j = 0;
while (j < 8)
{
printf("0x%02x", alttab[i++]);
j++;
if (i >= 128)
break;
printf(", ");
}
printf("\n");
}
printf("};\n");
}

View File

@@ -4,344 +4,372 @@
* This program is partially copied from lv(Multilingual file viewer)
* and slightly modified. lv is written and copyrighted by NARITA Tomio
* (nrt@web.ad.jp).
*
*
* 1999/1/15 Tatsuo Ishii
*
* $Id: big5.c,v 1.1 1999/02/02 18:51:22 momjian Exp $
* $Id: big5.c,v 1.2 1999/05/25 16:12:40 momjian Exp $
*/
#include "mb/pg_wchar.h"
typedef struct {
unsigned short code, peer;
} codes_t;
typedef struct
{
unsigned short code,
peer;
} codes_t;
/* map Big5 Level 1 to CNS 11643-1992 Plane 1 */
static codes_t big5Level1ToCnsPlane1[ 25 ] = { /* range */
{ 0xA140, 0x2121 },
{ 0xA1F6, 0x2258 },
{ 0xA1F7, 0x2257 },
{ 0xA1F8, 0x2259 },
{ 0xA2AF, 0x2421 },
{ 0xA3C0, 0x4221 },
{ 0xa3e1, 0x0000 },
{ 0xA440, 0x4421 },
{ 0xACFE, 0x5753 },
{ 0xacff, 0x0000 },
{ 0xAD40, 0x5323 },
{ 0xAFD0, 0x5754 },
{ 0xBBC8, 0x6B51 },
{ 0xBE52, 0x6B50 },
{ 0xBE53, 0x6F5C },
{ 0xC1AB, 0x7536 },
{ 0xC2CB, 0x7535 },
{ 0xC2CC, 0x7737 },
{ 0xC361, 0x782E },
{ 0xC3B9, 0x7865 },
{ 0xC3BA, 0x7864 },
{ 0xC3BB, 0x7866 },
{ 0xC456, 0x782D },
{ 0xC457, 0x7962 },
{ 0xc67f, 0x0000 }
static codes_t big5Level1ToCnsPlane1[25] = { /* range */
{0xA140, 0x2121},
{0xA1F6, 0x2258},
{0xA1F7, 0x2257},
{0xA1F8, 0x2259},
{0xA2AF, 0x2421},
{0xA3C0, 0x4221},
{0xa3e1, 0x0000},
{0xA440, 0x4421},
{0xACFE, 0x5753},
{0xacff, 0x0000},
{0xAD40, 0x5323},
{0xAFD0, 0x5754},
{0xBBC8, 0x6B51},
{0xBE52, 0x6B50},
{0xBE53, 0x6F5C},
{0xC1AB, 0x7536},
{0xC2CB, 0x7535},
{0xC2CC, 0x7737},
{0xC361, 0x782E},
{0xC3B9, 0x7865},
{0xC3BA, 0x7864},
{0xC3BB, 0x7866},
{0xC456, 0x782D},
{0xC457, 0x7962},
{0xc67f, 0x0000}
};
/* map CNS 11643-1992 Plane 1 to Big5 Level 1 */
static codes_t cnsPlane1ToBig5Level1[ 26 ] = { /* range */
{ 0x2121, 0xA140 },
{ 0x2257, 0xA1F7 },
{ 0x2258, 0xA1F6 },
{ 0x2259, 0xA1F8 },
{ 0x234f, 0x0000 },
{ 0x2421, 0xA2AF },
{ 0x2571, 0x0000 },
{ 0x4221, 0xA3C0 },
{ 0x4242, 0x0000 },
{ 0x4421, 0xA440 },
{ 0x5323, 0xAD40 },
{ 0x5753, 0xACFE },
{ 0x5754, 0xAFD0 },
{ 0x6B50, 0xBE52 },
{ 0x6B51, 0xBBC8 },
{ 0x6F5C, 0xBE53 },
{ 0x7535, 0xC2CB },
{ 0x7536, 0xC1AB },
{ 0x7737, 0xC2CC },
{ 0x782D, 0xC456 },
{ 0x782E, 0xC361 },
{ 0x7864, 0xC3BA },
{ 0x7865, 0xC3B9 },
{ 0x7866, 0xC3BB },
{ 0x7962, 0xC457 },
{ 0x7d4c, 0x0000 }
static codes_t cnsPlane1ToBig5Level1[26] = { /* range */
{0x2121, 0xA140},
{0x2257, 0xA1F7},
{0x2258, 0xA1F6},
{0x2259, 0xA1F8},
{0x234f, 0x0000},
{0x2421, 0xA2AF},
{0x2571, 0x0000},
{0x4221, 0xA3C0},
{0x4242, 0x0000},
{0x4421, 0xA440},
{0x5323, 0xAD40},
{0x5753, 0xACFE},
{0x5754, 0xAFD0},
{0x6B50, 0xBE52},
{0x6B51, 0xBBC8},
{0x6F5C, 0xBE53},
{0x7535, 0xC2CB},
{0x7536, 0xC1AB},
{0x7737, 0xC2CC},
{0x782D, 0xC456},
{0x782E, 0xC361},
{0x7864, 0xC3BA},
{0x7865, 0xC3B9},
{0x7866, 0xC3BB},
{0x7962, 0xC457},
{0x7d4c, 0x0000}
};
/* map Big5 Level 2 to CNS 11643-1992 Plane 2 */
static codes_t big5Level2ToCnsPlane2[ 48 ] = { /* range */
{ 0xC940, 0x2121 },
{ 0xc94a, 0x0000 },
{ 0xC94B, 0x212B },
{ 0xC96C, 0x214D },
{ 0xC9BE, 0x214C },
{ 0xC9BF, 0x217D },
{ 0xC9ED, 0x224E },
{ 0xCAF7, 0x224D },
{ 0xCAF8, 0x2439 },
{ 0xD77A, 0x3F6A },
{ 0xD77B, 0x387E },
{ 0xDBA7, 0x3F6B },
{ 0xDDFC, 0x4176 },
{ 0xDDFD, 0x4424 },
{ 0xE8A3, 0x554C },
{ 0xE976, 0x5723 },
{ 0xEB5B, 0x5A29 },
{ 0xEBF1, 0x554B },
{ 0xEBF2, 0x5B3F },
{ 0xECDE, 0x5722 },
{ 0xECDF, 0x5C6A },
{ 0xEDAA, 0x5D75 },
{ 0xEEEB, 0x642F },
{ 0xEEEC, 0x6039 },
{ 0xF056, 0x5D74 },
{ 0xF057, 0x6243 },
{ 0xF0CB, 0x5A28 },
{ 0xF0CC, 0x6337 },
{ 0xF163, 0x6430 },
{ 0xF16B, 0x6761 },
{ 0xF16C, 0x6438 },
{ 0xF268, 0x6934 },
{ 0xF269, 0x6573 },
{ 0xF2C3, 0x664E },
{ 0xF375, 0x6762 },
{ 0xF466, 0x6935 },
{ 0xF4B5, 0x664D },
{ 0xF4B6, 0x6962 },
{ 0xF4FD, 0x6A4C },
{ 0xF663, 0x6A4B },
{ 0xF664, 0x6C52 },
{ 0xF977, 0x7167 },
{ 0xF9C4, 0x7166 },
{ 0xF9C5, 0x7234 },
{ 0xF9C6, 0x7240 },
{ 0xF9C7, 0x7235 },
{ 0xF9D2, 0x7241 },
{ 0xf9d6, 0x0000 }
static codes_t big5Level2ToCnsPlane2[48] = { /* range */
{0xC940, 0x2121},
{0xc94a, 0x0000},
{0xC94B, 0x212B},
{0xC96C, 0x214D},
{0xC9BE, 0x214C},
{0xC9BF, 0x217D},
{0xC9ED, 0x224E},
{0xCAF7, 0x224D},
{0xCAF8, 0x2439},
{0xD77A, 0x3F6A},
{0xD77B, 0x387E},
{0xDBA7, 0x3F6B},
{0xDDFC, 0x4176},
{0xDDFD, 0x4424},
{0xE8A3, 0x554C},
{0xE976, 0x5723},
{0xEB5B, 0x5A29},
{0xEBF1, 0x554B},
{0xEBF2, 0x5B3F},
{0xECDE, 0x5722},
{0xECDF, 0x5C6A},
{0xEDAA, 0x5D75},
{0xEEEB, 0x642F},
{0xEEEC, 0x6039},
{0xF056, 0x5D74},
{0xF057, 0x6243},
{0xF0CB, 0x5A28},
{0xF0CC, 0x6337},
{0xF163, 0x6430},
{0xF16B, 0x6761},
{0xF16C, 0x6438},
{0xF268, 0x6934},
{0xF269, 0x6573},
{0xF2C3, 0x664E},
{0xF375, 0x6762},
{0xF466, 0x6935},
{0xF4B5, 0x664D},
{0xF4B6, 0x6962},
{0xF4FD, 0x6A4C},
{0xF663, 0x6A4B},
{0xF664, 0x6C52},
{0xF977, 0x7167},
{0xF9C4, 0x7166},
{0xF9C5, 0x7234},
{0xF9C6, 0x7240},
{0xF9C7, 0x7235},
{0xF9D2, 0x7241},
{0xf9d6, 0x0000}
};
/* map CNS 11643-1992 Plane 2 to Big5 Level 2 */
static codes_t cnsPlane2ToBig5Level2[ 49 ] = { /* range */
{ 0x2121, 0xC940 },
{ 0x212B, 0xC94B },
{ 0x214C, 0xC9BE },
{ 0x214D, 0xC96C },
{ 0x217D, 0xC9BF },
{ 0x224D, 0xCAF7 },
{ 0x224E, 0xC9ED },
{ 0x2439, 0xCAF8 },
{ 0x387E, 0xD77B },
{ 0x3F6A, 0xD77A },
{ 0x3F6B, 0xDBA7 },
{ 0x4424, 0x0000 },
{ 0x4176, 0xDDFC },
{ 0x4177, 0x0000 },
{ 0x4424, 0xDDFD },
{ 0x554B, 0xEBF1 },
{ 0x554C, 0xE8A3 },
{ 0x5722, 0xECDE },
{ 0x5723, 0xE976 },
{ 0x5A28, 0xF0CB },
{ 0x5A29, 0xEB5B },
{ 0x5B3F, 0xEBF2 },
{ 0x5C6A, 0xECDF },
{ 0x5D74, 0xF056 },
{ 0x5D75, 0xEDAA },
{ 0x6039, 0xEEEC },
{ 0x6243, 0xF057 },
{ 0x6337, 0xF0CC },
{ 0x642F, 0xEEEB },
{ 0x6430, 0xF163 },
{ 0x6438, 0xF16C },
{ 0x6573, 0xF269 },
{ 0x664D, 0xF4B5 },
{ 0x664E, 0xF2C3 },
{ 0x6761, 0xF16B },
{ 0x6762, 0xF375 },
{ 0x6934, 0xF268 },
{ 0x6935, 0xF466 },
{ 0x6962, 0xF4B6 },
{ 0x6A4B, 0xF663 },
{ 0x6A4C, 0xF4FD },
{ 0x6C52, 0xF664 },
{ 0x7166, 0xF9C4 },
{ 0x7167, 0xF977 },
{ 0x7234, 0xF9C5 },
{ 0x7235, 0xF9C7 },
{ 0x7240, 0xF9C6 },
{ 0x7241, 0xF9D2 },
{ 0x7245, 0x0000 }
static codes_t cnsPlane2ToBig5Level2[49] = { /* range */
{0x2121, 0xC940},
{0x212B, 0xC94B},
{0x214C, 0xC9BE},
{0x214D, 0xC96C},
{0x217D, 0xC9BF},
{0x224D, 0xCAF7},
{0x224E, 0xC9ED},
{0x2439, 0xCAF8},
{0x387E, 0xD77B},
{0x3F6A, 0xD77A},
{0x3F6B, 0xDBA7},
{0x4424, 0x0000},
{0x4176, 0xDDFC},
{0x4177, 0x0000},
{0x4424, 0xDDFD},
{0x554B, 0xEBF1},
{0x554C, 0xE8A3},
{0x5722, 0xECDE},
{0x5723, 0xE976},
{0x5A28, 0xF0CB},
{0x5A29, 0xEB5B},
{0x5B3F, 0xEBF2},
{0x5C6A, 0xECDF},
{0x5D74, 0xF056},
{0x5D75, 0xEDAA},
{0x6039, 0xEEEC},
{0x6243, 0xF057},
{0x6337, 0xF0CC},
{0x642F, 0xEEEB},
{0x6430, 0xF163},
{0x6438, 0xF16C},
{0x6573, 0xF269},
{0x664D, 0xF4B5},
{0x664E, 0xF2C3},
{0x6761, 0xF16B},
{0x6762, 0xF375},
{0x6934, 0xF268},
{0x6935, 0xF466},
{0x6962, 0xF4B6},
{0x6A4B, 0xF663},
{0x6A4C, 0xF4FD},
{0x6C52, 0xF664},
{0x7166, 0xF9C4},
{0x7167, 0xF977},
{0x7234, 0xF9C5},
{0x7235, 0xF9C7},
{0x7240, 0xF9C6},
{0x7241, 0xF9D2},
{0x7245, 0x0000}
};
/* Big Five Level 1 Correspondence to CNS 11643-1992 Plane 4 */
static unsigned short b1c4[][2] = {
{0xC879, 0x2123},
{0xC87B, 0x2124},
{0xC87D, 0x212A},
{0xC8A2, 0x2152}
{0xC879, 0x2123},
{0xC87B, 0x2124},
{0xC87D, 0x212A},
{0xC8A2, 0x2152}
};
/* Big Five Level 2 Correspondence to CNS 11643-1992 Plane 3 */
static unsigned short b2c3[][2] = {
{0xF9D6, 0x4337},
{0xF9D7, 0x4F50},
{0xF9D8, 0x444E},
{0xF9D9, 0x504A},
{0xF9DA, 0x2C5D},
{0xF9DB, 0x3D7E},
{0xF9DC, 0x4B5C}
{0xF9D6, 0x4337},
{0xF9D7, 0x4F50},
{0xF9D8, 0x444E},
{0xF9D9, 0x504A},
{0xF9DA, 0x2C5D},
{0xF9DB, 0x3D7E},
{0xF9DC, 0x4B5C}
};
static unsigned short BinarySearchRange
(codes_t *array, int high, unsigned short code )
(codes_t * array, int high, unsigned short code)
{
int low, mid, distance, tmp;
int low,
mid,
distance,
tmp;
low = 0;
mid = high >> 1;
low = 0;
mid = high >> 1;
for (; low <= high; mid = (low + high) >> 1)
{
if ((array[mid].code <= code) && (array[mid + 1].code > code))
{
if (0 == array[mid].peer)
return 0;
if (code >= 0xa140 U)
{
/* big5 to cns */
tmp = ((code & 0xff00) - (array[mid].code & 0xff00)) >> 8;
high = code & 0x00ff;
low = array[mid].code & 0x00ff;
/*
* NOTE: big5 high_byte: 0xa1-0xfe, low_byte: 0x40-0x7e,
* 0xa1-0xfe (radicals: 0x00-0x3e, 0x3f-0x9c) big5 radix
* is 0x9d. [region_low, region_high]
* We should remember big5 has two different regions
* (above). There is a bias for the distance between these
* regions. 0xa1 - 0x7e + bias = 1 (Distance between 0xa1
* and 0x7e is 1.) bias = - 0x22.
*/
distance = tmp * 0x9d + high - low +
(high >= 0xa1 ? (low >= 0xa1 ? 0 : -0x22)
: (low >= 0xa1 ? +0x22 : 0));
/*
* NOTE: we have to convert the distance into a code
* point. The code point's low_byte is 0x21 plus mod_0x5e.
* In the first, we extract the mod_0x5e of the starting
* code point, subtracting 0x21, and add distance to it.
* Then we calculate again mod_0x5e of them, and restore
* the final codepoint, adding 0x21.
*/
tmp = (array[mid].peer & 0x00ff) + distance - 0x21;
tmp = (array[mid].peer & 0xff00) + ((tmp / 0x5e) << 8)
+ 0x21 + tmp % 0x5e;
return tmp;
}
else
{
/* cns to big5 */
tmp = ((code & 0xff00) - (array[mid].code & 0xff00)) >> 8;
/*
* NOTE: ISO charsets ranges between 0x21-0xfe
* (94charset). Its radix is 0x5e. But there is no
* distance bias like big5.
*/
distance = tmp * 0x5e
+ ((int) (code & 0x00ff) - (int) (array[mid].code & 0x00ff));
/*
* NOTE: Similar to big5 to cns conversion, we extract
* mod_0x9d and restore mod_0x9d into a code point.
*/
low = array[mid].peer & 0x00ff;
tmp = low + distance - (low >= 0xa1 ? 0x62 : 0x40);
low = tmp % 0x9d;
tmp = (array[mid].peer & 0xff00) + ((tmp / 0x9d) << 8)
+ (low > 0x3e ? 0x62 : 0x40) + low;
return tmp;
}
}
else if (array[mid].code > code)
high = mid - 1;
else
low = mid + 1;
}
for( ; low <= high ; mid = ( low + high ) >> 1 ){
if( ( array[ mid ].code <= code ) && ( array[ mid + 1 ].code > code ) ){
if( 0 == array[ mid ].peer )
return 0;
if( code >= 0xa140U ){
/* big5 to cns */
tmp = ( ( code & 0xff00 ) - ( array[ mid ].code & 0xff00 ) ) >> 8;
high = code & 0x00ff;
low = array[ mid ].code & 0x00ff;
/*
* NOTE: big5 high_byte: 0xa1-0xfe, low_byte: 0x40-0x7e, 0xa1-0xfe
* (radicals: 0x00-0x3e, 0x3f-0x9c)
* big5 radix is 0x9d. [region_low, region_high]
* We should remember big5 has two different regions (above).
* There is a bias for the distance between these regions.
* 0xa1 - 0x7e + bias = 1 (Distance between 0xa1 and 0x7e is 1.)
* bias = - 0x22.
*/
distance = tmp * 0x9d + high - low +
( high >= 0xa1 ? ( low >= 0xa1 ? 0 : - 0x22 )
: ( low >= 0xa1 ? + 0x22 : 0 ) );
/*
* NOTE: we have to convert the distance into a code point.
* The code point's low_byte is 0x21 plus mod_0x5e.
* In the first, we extract the mod_0x5e of the starting
* code point, subtracting 0x21, and add distance to it.
* Then we calculate again mod_0x5e of them, and restore
* the final codepoint, adding 0x21.
*/
tmp = ( array[ mid ].peer & 0x00ff ) + distance - 0x21;
tmp = ( array[ mid ].peer & 0xff00 ) + ( ( tmp / 0x5e ) << 8 )
+ 0x21 + tmp % 0x5e;
return tmp;
} else {
/* cns to big5 */
tmp = ( ( code & 0xff00 ) - ( array[ mid ].code & 0xff00 ) ) >> 8;
/*
* NOTE: ISO charsets ranges between 0x21-0xfe (94charset).
* Its radix is 0x5e. But there is no distance bias like big5.
*/
distance = tmp * 0x5e
+ ( (int)( code & 0x00ff ) - (int)( array[ mid ].code & 0x00ff ) );
/*
* NOTE: Similar to big5 to cns conversion, we extract mod_0x9d and
* restore mod_0x9d into a code point.
*/
low = array[ mid ].peer & 0x00ff;
tmp = low + distance - ( low >= 0xa1 ? 0x62 : 0x40 );
low = tmp % 0x9d;
tmp = ( array[ mid ].peer & 0xff00 ) + ( ( tmp / 0x9d ) << 8 )
+ ( low > 0x3e ? 0x62 : 0x40 ) + low;
return tmp;
}
} else if( array[ mid ].code > code ){
high = mid - 1;
} else {
low = mid + 1;
}
}
return 0;
}
unsigned short BIG5toCNS(unsigned short big5, unsigned char *lc )
unsigned short
BIG5toCNS(unsigned short big5, unsigned char *lc)
{
unsigned short cns = 0;
int i;
unsigned short cns = 0;
int i;
if( big5 < 0xc940U ){
/* level 1 */
if (big5 < 0xc940 U)
{
/* level 1 */
for (i=0;i<sizeof(b1c4)/sizeof(unsigned short);i++) {
if (b1c4[i][0] == big5) {
*lc = LC_CNS11643_4;
return(b1c4[i][1] | 0x8080U);
}
}
for (i = 0; i < sizeof(b1c4) / sizeof(unsigned short); i++)
{
if (b1c4[i][0] == big5)
{
*lc = LC_CNS11643_4;
return (b1c4[i][1] | 0x8080 U);
}
}
if( 0 < (cns = BinarySearchRange( big5Level1ToCnsPlane1, 23, big5 )) )
*lc = LC_CNS11643_1;
} else if( big5 == 0xc94aU ){
/* level 2 */
*lc = LC_CNS11643_1;
cns = 0x4442;
} else {
/* level 2 */
for (i=0;i<sizeof(b2c3)/sizeof(unsigned short);i++) {
if (b2c3[i][0] == big5) {
*lc = LC_CNS11643_3;
return(b2c3[i][1]);
}
}
if (0 < (cns = BinarySearchRange(big5Level1ToCnsPlane1, 23, big5)))
*lc = LC_CNS11643_1;
}
else if (big5 == 0xc94a U)
{
/* level 2 */
*lc = LC_CNS11643_1;
cns = 0x4442;
}
else
{
/* level 2 */
for (i = 0; i < sizeof(b2c3) / sizeof(unsigned short); i++)
{
if (b2c3[i][0] == big5)
{
*lc = LC_CNS11643_3;
return (b2c3[i][1]);
}
}
if( 0 < (cns = BinarySearchRange( big5Level2ToCnsPlane2, 46, big5 )) )
*lc = LC_CNS11643_2;
}
if (0 < (cns = BinarySearchRange(big5Level2ToCnsPlane2, 46, big5)))
*lc = LC_CNS11643_2;
}
if( 0 == cns ){ /* no mapping Big5 to CNS 11643-1992 */
*lc = 0;
return (unsigned short)'?';
}
if (0 == cns)
{ /* no mapping Big5 to CNS 11643-1992 */
*lc = 0;
return (unsigned short) '?';
}
return cns | 0x8080;
return cns | 0x8080;
}
unsigned short CNStoBIG5( unsigned short cns, unsigned char lc )
unsigned short
CNStoBIG5(unsigned short cns, unsigned char lc)
{
int i;
unsigned int big5 = 0;
int i;
unsigned int big5 = 0;
cns &= 0x7f7f;
cns &= 0x7f7f;
switch( lc ){
case LC_CNS11643_1:
big5 = BinarySearchRange( cnsPlane1ToBig5Level1, 24, cns );
break;
case LC_CNS11643_2:
big5 = BinarySearchRange( cnsPlane2ToBig5Level2, 47, cns );
break;
case LC_CNS11643_3:
for (i=0;i<sizeof(b2c3)/sizeof(unsigned short);i++) {
if (b2c3[i][1] == cns) {
return(b2c3[i][0]);
}
}
break;
case LC_CNS11643_4:
for (i=0;i<sizeof(b1c4)/sizeof(unsigned short);i++) {
if (b1c4[i][1] == cns) {
return(b1c4[i][0]);
}
}
default:
break;
}
return big5;
switch (lc)
{
case LC_CNS11643_1:
big5 = BinarySearchRange(cnsPlane1ToBig5Level1, 24, cns);
break;
case LC_CNS11643_2:
big5 = BinarySearchRange(cnsPlane2ToBig5Level2, 47, cns);
break;
case LC_CNS11643_3:
for (i = 0; i < sizeof(b2c3) / sizeof(unsigned short); i++)
{
if (b2c3[i][1] == cns)
return (b2c3[i][0]);
}
break;
case LC_CNS11643_4:
for (i = 0; i < sizeof(b1c4) / sizeof(unsigned short); i++)
{
if (b1c4[i][1] == cns)
return (b1c4[i][0]);
}
default:
break;
}
return big5;
}

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.4 1999/05/13 10:28:25 ishii Exp $ */
* $Id: common.c,v 1.5 1999/05/25 16:12:41 momjian Exp $ */
#include <stdlib.h>
@@ -28,9 +28,8 @@ pg_char_to_encoding(const char *s)
{
pg_encoding_conv_tbl *p = pg_conv_tbl;
if (!s) {
if (!s)
return (-1);
}
for (; p->encoding >= 0; p++)
{

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.7 1999/04/25 18:09:54 tgl Exp $
* $Id: conv.c,v 1.8 1999/05/25 16:12:41 momjian Exp $
*/
#include <stdio.h>
#include <string.h>
@@ -375,43 +375,52 @@ mic2euc_tw(unsigned char *mic, unsigned char *p, int len)
static void
big52mic(unsigned char *big5, unsigned char *p, int len)
{
unsigned short c1;
unsigned short big5buf, cnsBuf;
unsigned char lc;
char bogusBuf[2];
int i;
unsigned short c1;
unsigned short big5buf,
cnsBuf;
unsigned char lc;
char bogusBuf[2];
int i;
while (len > 0 && (c1 = *big5++))
{
if (c1 <= 0x007fU) { /* ASCII */
len--;
*p++ = c1;
} else {
len -= 2;
big5buf = c1 << 8;
c1 = *big5++;
big5buf |= c1;
cnsBuf = BIG5toCNS(big5buf, &lc);
if (lc != 0) {
if (lc == LC_CNS11643_3 || lc == LC_CNS11643_4) {
*p++ = 0x9d; /* LCPRV2 */
}
*p++ = lc; /* Plane No. */
*p++ = (cnsBuf >> 8) & 0x00ff;
*p++ = cnsBuf & 0x00ff;
} else { /* cannot convert */
big5 -= 2;
*p++ = '(';
for (i=0;i<2;i++) {
sprintf(bogusBuf,"%02x",*big5++);
*p++ = bogusBuf[0];
*p++ = bogusBuf[1];
}
*p++ = ')';
while (len > 0 && (c1 = *big5++))
{
if (c1 <= 0x007f U)
{ /* ASCII */
len--;
*p++ = c1;
}
else
{
len -= 2;
big5buf = c1 << 8;
c1 = *big5++;
big5buf |= c1;
cnsBuf = BIG5toCNS(big5buf, &lc);
if (lc != 0)
{
if (lc == LC_CNS11643_3 || lc == LC_CNS11643_4)
{
*p++ = 0x9d;/* LCPRV2 */
}
*p++ = lc; /* Plane No. */
*p++ = (cnsBuf >> 8) & 0x00ff;
*p++ = cnsBuf & 0x00ff;
}
else
{ /* cannot convert */
big5 -= 2;
*p++ = '(';
for (i = 0; i < 2; i++)
{
sprintf(bogusBuf, "%02x", *big5++);
*p++ = bogusBuf[0];
*p++ = bogusBuf[1];
}
*p++ = ')';
}
}
}
}
}
*p = '\0';
*p = '\0';
}
/*
@@ -420,41 +429,46 @@ big52mic(unsigned char *big5, unsigned char *p, int len)
static void
mic2big5(unsigned char *mic, unsigned char *p, int len)
{
int l;
unsigned short c1;
unsigned short big5buf, cnsBuf;
int l;
unsigned short c1;
unsigned short big5buf,
cnsBuf;
while (len > 0 && (c1 = *mic))
{
l = pg_mic_mblen(mic++);
len -= l;
while (len > 0 && (c1 = *mic))
{
l = pg_mic_mblen(mic++);
len -= l;
/* 0x9d means LCPRV2 */
if (c1 == LC_CNS11643_1 || c1 == LC_CNS11643_2 || c1 == 0x9d)
{
if (c1 == 0x9d) {
c1 = *mic++; /* get plane no. */
}
cnsBuf = (*mic++)<<8;
cnsBuf |= (*mic++) & 0x00ff;
big5buf = CNStoBIG5(cnsBuf, c1);
if (big5buf == 0) { /* cannot convert to Big5! */
mic -= l;
printBogusChar(&mic, &p);
} else {
*p++ = (big5buf >> 8) & 0x00ff;
*p++ = big5buf & 0x00ff;
}
/* 0x9d means LCPRV2 */
if (c1 == LC_CNS11643_1 || c1 == LC_CNS11643_2 || c1 == 0x9d)
{
if (c1 == 0x9d)
{
c1 = *mic++; /* get plane no. */
}
cnsBuf = (*mic++) << 8;
cnsBuf |= (*mic++) & 0x00ff;
big5buf = CNStoBIG5(cnsBuf, c1);
if (big5buf == 0)
{ /* cannot convert to Big5! */
mic -= l;
printBogusChar(&mic, &p);
}
else
{
*p++ = (big5buf >> 8) & 0x00ff;
*p++ = big5buf & 0x00ff;
}
}
else if (c1 <= 0x7f) /* ASCII */
*p++ = c1;
else
{ /* cannot convert to Big5! */
mic--;
printBogusChar(&mic, &p);
}
}
else if (c1 <= 0x7f) /* ASCII */
{
*p++ = c1;
} else { /* cannot convert to Big5! */
mic--;
printBogusChar(&mic, &p);
}
}
*p = '\0';
*p = '\0';
}
/*
@@ -543,6 +557,7 @@ mic2latin4(unsigned char *mic, unsigned char *p, int len)
{
mic2latin(mic, p, len, LC_ISO8859_4);
}
#ifdef NOT_USED
static void
latin52mic(unsigned char *l, unsigned char *p, int len)
@@ -554,6 +569,7 @@ mic2latin5(unsigned char *mic, unsigned char *p, int len)
{
mic2latin(mic, p, len, LC_ISO8859_5);
}
#endif
/*
@@ -590,7 +606,7 @@ mic2ascii(unsigned char *mic, unsigned char *p, int len)
*p = '\0';
}
/*
/*
* Cyrillic support
* currently supported Cyrillic encodings:
*
@@ -601,18 +617,18 @@ mic2ascii(unsigned char *mic, unsigned char *p, int len)
* Alternativny Variant (MS-DOS CP866)
*/
/* koi2mic: KOI8-R to Mule internal code */
/* koi2mic: KOI8-R to Mule internal code */
static void
koi2mic(unsigned char *l, unsigned char *p, int len)
{
latin2mic(l, p, len, LC_KOI8_R);
latin2mic(l, p, len, LC_KOI8_R);
}
/* mic2koi: Mule internal code to KOI8-R */
static void
mic2koi(unsigned char *mic, unsigned char *p, int len)
{
mic2latin(mic, p, len, LC_KOI8_R);
mic2latin(mic, p, len, LC_KOI8_R);
}
/*
@@ -625,30 +641,36 @@ mic2koi(unsigned char *mic, unsigned char *p, int len)
*/
static void
latin2mic_with_table(
unsigned char *l, /* local charset string (source) */
unsigned char *p, /* pointer to store mule internal code
(destination) */
int len, /* length of l */
int lc, /* leading character of p */
unsigned char *tab /* code conversion table */
)
unsigned char *l, /* local charset string (source) */
unsigned char *p, /* pointer to store mule internal
* code (destination) */
int len, /* length of l */
int lc, /* leading character of p */
unsigned char *tab /* code conversion table */
)
{
unsigned char c1,c2;
while (len-- > 0 && (c1 = *l++)) {
if (c1 < 128) {
*p++ = c1;
} else {
c2 = tab[c1 - 128];
if (c2) {
*p++ = lc;
*p++ = c2;
} else {
*p++ = ' '; /* cannot convert */
}
}
}
*p = '\0';
unsigned char c1,
c2;
while (len-- > 0 && (c1 = *l++))
{
if (c1 < 128)
*p++ = c1;
else
{
c2 = tab[c1 - 128];
if (c2)
{
*p++ = lc;
*p++ = c2;
}
else
{
*p++ = ' '; /* cannot convert */
}
}
}
*p = '\0';
}
/*
@@ -656,190 +678,202 @@ latin2mic_with_table(
* conversion from the mule internal code to a local charset
* with a encoding conversion table.
* the table is ordered according to the second byte of the mule
* internal code starting from 128 (0x80).
* internal code starting from 128 (0x80).
* each entry in the table
* holds the corresponding code point for the local code.
*/
static void
mic2latin_with_table(
unsigned char *mic, /* mule internal code (source) */
unsigned char *p, /* local code (destination) */
int len, /* length of p */
int lc, /* leading character */
unsigned char *tab /* code conversion table */
)
unsigned char *mic, /* mule internal code
* (source) */
unsigned char *p, /* local code (destination) */
int len, /* length of p */
int lc, /* leading character */
unsigned char *tab /* code conversion table */
)
{
unsigned char c1,c2;
unsigned char c1,
c2;
while (len-- > 0 && (c1 = *mic++)) {
if (c1 < 128) {
*p++ = c1;
} else if (c1 == lc) {
c1 = *mic++;
len--;
c2 = tab[c1 - 128];
if (c2) {
*p++ = c2;
} else {
*p++ = ' '; /* cannot convert */
}
} else {
*p++ = ' '; /* bogus character */
}
}
*p = '\0';
while (len-- > 0 && (c1 = *mic++))
{
if (c1 < 128)
*p++ = c1;
else if (c1 == lc)
{
c1 = *mic++;
len--;
c2 = tab[c1 - 128];
if (c2)
*p++ = c2;
else
{
*p++ = ' '; /* cannot convert */
}
}
else
{
*p++ = ' '; /* bogus character */
}
}
*p = '\0';
}
/* iso2mic: ISO-8859-5 to Mule internal code */
/* iso2mic: ISO-8859-5 to Mule internal code */
static void
iso2mic(unsigned char *l, unsigned char *p, int len)
{
static char iso2koi[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xe1, 0xe2, 0xf7, 0xe7, 0xe4, 0xe5, 0xf6, 0xfa,
0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef, 0xf0,
0xf2, 0xf3, 0xf4, 0xf5, 0xe6, 0xe8, 0xe3, 0xfe,
0xfb, 0xfd, 0xff, 0xf9, 0xf8, 0xfc, 0xe0, 0xf1,
0xc1, 0xc2, 0xd7, 0xc7, 0xc4, 0xc5, 0xd6, 0xda,
0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, 0xd0,
0xd2, 0xd3, 0xd4, 0xd5, 0xc6, 0xc8, 0xc3, 0xde,
0xdb, 0xdd, 0xdf, 0xd9, 0xd8, 0xdc, 0xc0, 0xd1,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
latin2mic_with_table(l, p, len, LC_KOI8_R, iso2koi);
static char iso2koi[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xe1, 0xe2, 0xf7, 0xe7, 0xe4, 0xe5, 0xf6, 0xfa,
0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef, 0xf0,
0xf2, 0xf3, 0xf4, 0xf5, 0xe6, 0xe8, 0xe3, 0xfe,
0xfb, 0xfd, 0xff, 0xf9, 0xf8, 0xfc, 0xe0, 0xf1,
0xc1, 0xc2, 0xd7, 0xc7, 0xc4, 0xc5, 0xd6, 0xda,
0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, 0xd0,
0xd2, 0xd3, 0xd4, 0xd5, 0xc6, 0xc8, 0xc3, 0xde,
0xdb, 0xdd, 0xdf, 0xd9, 0xd8, 0xdc, 0xc0, 0xd1,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
latin2mic_with_table(l, p, len, LC_KOI8_R, iso2koi);
}
/* mic2iso: Mule internal code to ISO8859-5 */
static void
mic2iso(unsigned char *mic, unsigned char *p, int len)
{
static char koi2iso[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xee, 0xd0, 0xd1, 0xe6, 0xd4, 0xd5, 0xe4, 0xd3,
0xe5, 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde,
0xdf, 0xef, 0xe0, 0xe1, 0xe2, 0xe3, 0xd6, 0xd2,
0xec, 0xeb, 0xd7, 0xe8, 0xed, 0xe9, 0xe7, 0xea,
0xce, 0xb0, 0xb1, 0xc6, 0xb4, 0xb5, 0xc4, 0xb3,
0xc5, 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe,
0xbf, 0xcf, 0xc0, 0xc1, 0xc2, 0xc3, 0xb6, 0xb2,
0xcc, 0xcb, 0xb7, 0xc8, 0xcd, 0xc9, 0xc7, 0xca
};
static char koi2iso[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xee, 0xd0, 0xd1, 0xe6, 0xd4, 0xd5, 0xe4, 0xd3,
0xe5, 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde,
0xdf, 0xef, 0xe0, 0xe1, 0xe2, 0xe3, 0xd6, 0xd2,
0xec, 0xeb, 0xd7, 0xe8, 0xed, 0xe9, 0xe7, 0xea,
0xce, 0xb0, 0xb1, 0xc6, 0xb4, 0xb5, 0xc4, 0xb3,
0xc5, 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe,
0xbf, 0xcf, 0xc0, 0xc1, 0xc2, 0xc3, 0xb6, 0xb2,
0xcc, 0xcb, 0xb7, 0xc8, 0xcd, 0xc9, 0xc7, 0xca
};
mic2latin_with_table(mic, p, len, LC_KOI8_R, koi2iso);
mic2latin_with_table(mic, p, len, LC_KOI8_R, koi2iso);
}
/* win2mic: CP1251 to Mule internal code */
/* win2mic: CP1251 to Mule internal code */
static void
win2mic(unsigned char *l, unsigned char *p, int len)
{
static char win2koi[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0xbd, 0x00, 0x00,
0xb3, 0x00, 0xb4, 0x00, 0x00, 0x00, 0x00, 0xb7,
0x00, 0x00, 0xb6, 0xa6, 0xad, 0x00, 0x00, 0x00,
0xa3, 0x00, 0xa4, 0x00, 0x00, 0x00, 0x00, 0xa7,
0xe1, 0xe2, 0xf7, 0xe7, 0xe4, 0xe5, 0xf6, 0xfa,
0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef, 0xf0,
0xf2, 0xf3, 0xf4, 0xf5, 0xe6, 0xe8, 0xe3, 0xfe,
0xfb, 0xfd, 0xff, 0xf9, 0xf8, 0xfc, 0xe0, 0xf1,
0xc1, 0xc2, 0xd7, 0xc7, 0xc4, 0xc5, 0xd6, 0xda,
0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, 0xd0,
0xd2, 0xd3, 0xd4, 0xd5, 0xc6, 0xc8, 0xc3, 0xde,
0xdb, 0xdd, 0xdf, 0xd9, 0xd8, 0xdc, 0xc0, 0xd1
};
latin2mic_with_table(l, p, len, LC_KOI8_R, win2koi);
static char win2koi[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0xbd, 0x00, 0x00,
0xb3, 0x00, 0xb4, 0x00, 0x00, 0x00, 0x00, 0xb7,
0x00, 0x00, 0xb6, 0xa6, 0xad, 0x00, 0x00, 0x00,
0xa3, 0x00, 0xa4, 0x00, 0x00, 0x00, 0x00, 0xa7,
0xe1, 0xe2, 0xf7, 0xe7, 0xe4, 0xe5, 0xf6, 0xfa,
0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef, 0xf0,
0xf2, 0xf3, 0xf4, 0xf5, 0xe6, 0xe8, 0xe3, 0xfe,
0xfb, 0xfd, 0xff, 0xf9, 0xf8, 0xfc, 0xe0, 0xf1,
0xc1, 0xc2, 0xd7, 0xc7, 0xc4, 0xc5, 0xd6, 0xda,
0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, 0xd0,
0xd2, 0xd3, 0xd4, 0xd5, 0xc6, 0xc8, 0xc3, 0xde,
0xdb, 0xdd, 0xdf, 0xd9, 0xd8, 0xdc, 0xc0, 0xd1
};
latin2mic_with_table(l, p, len, LC_KOI8_R, win2koi);
}
/* mic2win: Mule internal code to CP1251 */
static void
mic2win(unsigned char *mic, unsigned char *p, int len)
{
static char koi2win[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0xb8, 0xba, 0x00, 0xb3, 0xbf,
0x00, 0x00, 0x00, 0x00, 0x00, 0xb4, 0x00, 0x00,
0x00, 0x00, 0x00, 0xa8, 0xaa, 0x00, 0xb2, 0xaf,
0x00, 0x00, 0x00, 0x00, 0x00, 0xa5, 0x00, 0x00,
0xfe, 0xe0, 0xe1, 0xf6, 0xe4, 0xe5, 0xf4, 0xe3,
0xf5, 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee,
0xef, 0xff, 0xf0, 0xf1, 0xf2, 0xf3, 0xe6, 0xe2,
0xfc, 0xfb, 0xe7, 0xf8, 0xfd, 0xf9, 0xf7, 0xfa,
0xde, 0xc0, 0xc1, 0xd6, 0xc4, 0xc5, 0xd4, 0xc3,
0xd5, 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce,
0xcf, 0xdf, 0xd0, 0xd1, 0xd2, 0xd3, 0xc6, 0xc2,
0xdc, 0xdb, 0xc7, 0xd8, 0xdd, 0xd9, 0xd7, 0xda
};
mic2latin_with_table(mic, p, len, LC_KOI8_R, koi2win);
static char koi2win[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0xb8, 0xba, 0x00, 0xb3, 0xbf,
0x00, 0x00, 0x00, 0x00, 0x00, 0xb4, 0x00, 0x00,
0x00, 0x00, 0x00, 0xa8, 0xaa, 0x00, 0xb2, 0xaf,
0x00, 0x00, 0x00, 0x00, 0x00, 0xa5, 0x00, 0x00,
0xfe, 0xe0, 0xe1, 0xf6, 0xe4, 0xe5, 0xf4, 0xe3,
0xf5, 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee,
0xef, 0xff, 0xf0, 0xf1, 0xf2, 0xf3, 0xe6, 0xe2,
0xfc, 0xfb, 0xe7, 0xf8, 0xfd, 0xf9, 0xf7, 0xfa,
0xde, 0xc0, 0xc1, 0xd6, 0xc4, 0xc5, 0xd4, 0xc3,
0xd5, 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce,
0xcf, 0xdf, 0xd0, 0xd1, 0xd2, 0xd3, 0xc6, 0xc2,
0xdc, 0xdb, 0xc7, 0xd8, 0xdd, 0xd9, 0xd7, 0xda
};
mic2latin_with_table(mic, p, len, LC_KOI8_R, koi2win);
}
/* alt2mic: CP866 to Mule internal code */
/* alt2mic: CP866 to Mule internal code */
static void
alt2mic(unsigned char *l, unsigned char *p, int len)
{
static char alt2koi[] = {
0xe1, 0xe2, 0xf7, 0xe7, 0xe4, 0xe5, 0xf6, 0xfa,
0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef, 0xf0,
0xf2, 0xf3, 0xf4, 0xf5, 0xe6, 0xe8, 0xe3, 0xfe,
0xfb, 0xfd, 0xff, 0xf9, 0xf8, 0xfc, 0xe0, 0xf1,
0xc1, 0xc2, 0xd7, 0xc7, 0xc4, 0xc5, 0xd6, 0xda,
0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, 0xd0,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0xbd, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xd2, 0xd3, 0xd4, 0xd5, 0xc6, 0xc8, 0xc3, 0xde,
0xdb, 0xdd, 0xdf, 0xd9, 0xd8, 0xdc, 0xc0, 0xd1,
0xb3, 0xa3, 0xb4, 0xa4, 0xb7, 0xa7, 0x00, 0x00,
0xb6, 0xa6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
latin2mic_with_table(l, p, len, LC_KOI8_R, alt2koi);
static char alt2koi[] = {
0xe1, 0xe2, 0xf7, 0xe7, 0xe4, 0xe5, 0xf6, 0xfa,
0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef, 0xf0,
0xf2, 0xf3, 0xf4, 0xf5, 0xe6, 0xe8, 0xe3, 0xfe,
0xfb, 0xfd, 0xff, 0xf9, 0xf8, 0xfc, 0xe0, 0xf1,
0xc1, 0xc2, 0xd7, 0xc7, 0xc4, 0xc5, 0xd6, 0xda,
0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, 0xd0,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0xbd, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xd2, 0xd3, 0xd4, 0xd5, 0xc6, 0xc8, 0xc3, 0xde,
0xdb, 0xdd, 0xdf, 0xd9, 0xd8, 0xdc, 0xc0, 0xd1,
0xb3, 0xa3, 0xb4, 0xa4, 0xb7, 0xa7, 0x00, 0x00,
0xb6, 0xa6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
latin2mic_with_table(l, p, len, LC_KOI8_R, alt2koi);
}
/* mic2alt: Mule internal code to CP866 */
static void
mic2alt(unsigned char *mic, unsigned char *p, int len)
{
static char koi2alt[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0xf1, 0xf3, 0x00, 0xf9, 0xf5,
0x00, 0x00, 0x00, 0x00, 0x00, 0xad, 0x00, 0x00,
0x00, 0x00, 0x00, 0xf0, 0xf2, 0x00, 0xf8, 0xf4,
0x00, 0x00, 0x00, 0x00, 0x00, 0xbd, 0x00, 0x00,
0xee, 0xa0, 0xa1, 0xe6, 0xa4, 0xa5, 0xe4, 0xa3,
0xe5, 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae,
0xaf, 0xef, 0xe0, 0xe1, 0xe2, 0xe3, 0xa6, 0xa2,
0xec, 0xeb, 0xa7, 0xe8, 0xed, 0xe9, 0xe7, 0xea,
0x9e, 0x80, 0x81, 0x96, 0x84, 0x85, 0x94, 0x83,
0x95, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e,
0x8f, 0x9f, 0x90, 0x91, 0x92, 0x93, 0x86, 0x82,
0x9c, 0x9b, 0x87, 0x98, 0x9d, 0x99, 0x97, 0x9a
};
mic2latin_with_table(mic, p, len, LC_KOI8_R, koi2alt);
static char koi2alt[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0xf1, 0xf3, 0x00, 0xf9, 0xf5,
0x00, 0x00, 0x00, 0x00, 0x00, 0xad, 0x00, 0x00,
0x00, 0x00, 0x00, 0xf0, 0xf2, 0x00, 0xf8, 0xf4,
0x00, 0x00, 0x00, 0x00, 0x00, 0xbd, 0x00, 0x00,
0xee, 0xa0, 0xa1, 0xe6, 0xa4, 0xa5, 0xe4, 0xa3,
0xe5, 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae,
0xaf, 0xef, 0xe0, 0xe1, 0xe2, 0xe3, 0xa6, 0xa2,
0xec, 0xeb, 0xa7, 0xe8, 0xed, 0xe9, 0xe7, 0xea,
0x9e, 0x80, 0x81, 0x96, 0x84, 0x85, 0x94, 0x83,
0x95, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e,
0x8f, 0x9f, 0x90, 0x91, 0x92, 0x93, 0x86, 0x82,
0x9c, 0x9b, 0x87, 0x98, 0x9d, 0x99, 0x97, 0x9a
};
mic2latin_with_table(mic, p, len, LC_KOI8_R, koi2alt);
}
/*
@@ -858,8 +892,8 @@ pg_encoding_conv_tbl pg_conv_tbl[] = {
{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, iso2mic, mic2iso}, /* ISO 8859 Latin 5 */
{KOI8, "KOI8", 0, koi2mic, mic2koi}, /* KOI8-R */
{LATIN5, "LATIN5", 0, iso2mic, mic2iso}, /* ISO 8859 Latin 5 */
{KOI8, "KOI8", 0, koi2mic, mic2koi}, /* KOI8-R */
{WIN, "WIN", 0, win2mic, mic2win}, /* CP1251 */
{ALT, "ALT", 0, alt2mic, mic2alt}, /* CP866 */
{SJIS, "SJIS", 1, sjis2mic, mic2sjis}, /* SJIS */

View File

@@ -4,63 +4,69 @@
*
* Tatsuo Ishii
*
* $Id: iso.c,v 1.1 1999/03/24 07:01:37 ishii Exp $
* $Id: iso.c,v 1.2 1999/05/25 16:12:42 momjian Exp $
*/
#include <stdio.h>
main()
{
int i;
char koitab[128],isotab[128];
char buf[4096];
int koi,iso;
int i;
char koitab[128],
isotab[128];
char buf[4096];
int koi,
iso;
for (i=0;i<128;i++) {
koitab[i] = isotab[i] = 0;
}
for (i = 0; i < 128; i++)
koitab[i] = isotab[i] = 0;
while (fgets(buf,sizeof(buf),stdin) != NULL) {
if (*buf == '#') {
continue;
}
sscanf(buf,"%d %x",&koi,&iso);
if (koi < 128 || koi > 255 || iso < 128 || iso > 255) {
fprintf(stderr,"invalid value %d\n",koi);
exit(1);
}
koitab[koi-128] = iso;
isotab[iso-128] = koi;
}
while (fgets(buf, sizeof(buf), stdin) != NULL)
{
if (*buf == '#')
continue;
sscanf(buf, "%d %x", &koi, &iso);
if (koi < 128 || koi > 255 || iso < 128 || iso > 255)
{
fprintf(stderr, "invalid value %d\n", koi);
exit(1);
}
koitab[koi - 128] = iso;
isotab[iso - 128] = koi;
}
i = 0;
printf("static char koi2iso[] = {\n");
while (i < 128) {
int j = 0;
while (j < 8) {
printf("0x%02x",koitab[i++]);
j++;
if (i >= 128) {
break;
}
printf(", ");
}
printf("\n");
}
printf("};\n");
i = 0;
printf("static char koi2iso[] = {\n");
while (i < 128)
{
int j = 0;
i = 0;
printf("static char iso2koi[] = {\n");
while (i < 128) {
int j = 0;
while (j < 8) {
printf("0x%02x",isotab[i++]);
j++;
if (i >= 128) {
break;
}
printf(", ");
}
printf("\n");
}
printf("};\n");
while (j < 8)
{
printf("0x%02x", koitab[i++]);
j++;
if (i >= 128)
break;
printf(", ");
}
printf("\n");
}
printf("};\n");
i = 0;
printf("static char iso2koi[] = {\n");
while (i < 128)
{
int j = 0;
while (j < 8)
{
printf("0x%02x", isotab[i++]);
j++;
if (i >= 128)
break;
printf(", ");
}
printf("\n");
}
printf("};\n");
}

View File

@@ -3,14 +3,14 @@
* client encoding and server internal encoding.
* (currently mule internal code (mic) is used)
* Tatsuo Ishii
* $Id: mbutils.c,v 1.5 1999/02/02 18:51:23 momjian Exp $ */
* $Id: mbutils.c,v 1.6 1999/05/25 16:12:43 momjian Exp $ */
#include <stdio.h>
#include <string.h>
#include "mb/pg_wchar.h"
static int client_encoding = -1;
static int 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 */
@@ -213,16 +213,14 @@ pg_mbcliplen(const unsigned char *mbstr, int len, int limit)
int clen = 0;
int l;
while (*mbstr && len > 0)
while (*mbstr && len > 0)
{
l = pg_mblen(mbstr);
if ((clen + l) > limit) {
if ((clen + l) > limit)
break;
}
clen += l;
if (clen == limit) {
if (clen == limit)
break;
}
len -= l;
mbstr += l;
}

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.3 1999/05/13 10:28:26 ishii Exp $
* $Id: variable.c,v 1.4 1999/05/25 16:12:44 momjian Exp $
*/
#include "mb/pg_wchar.h"
@@ -13,12 +13,12 @@ parse_client_encoding(const char *value)
int encoding;
encoding = pg_valid_client_encoding(value);
if (encoding < 0) {
if (value) {
if (encoding < 0)
{
if (value)
elog(ERROR, "Client encoding %s is not supported", value);
} else {
else
elog(ERROR, "No client encoding is specified");
}
}
else
{

View File

@@ -1,7 +1,7 @@
/*
* conversion functions between pg_wchar and multi-byte streams.
* Tatsuo Ishii
* $Id: wchar.c,v 1.7 1999/04/25 20:35:51 tgl Exp $
* $Id: wchar.c,v 1.8 1999/05/25 16:12:45 momjian Exp $
*/
#include "mb/pg_wchar.h"
@@ -428,33 +428,33 @@ pg_wchar_tbl pg_wchar_table[] = {
{pg_euctw2wchar_with_len, pg_euctw_mblen}, /* 4 */
{pg_utf2wchar_with_len, pg_utf_mblen}, /* 5 */
{pg_mule2wchar_with_len, pg_mule_mblen}, /* 6 */
{pg_latin12wchar_with_len, pg_latin1_mblen}, /* 7 */
{pg_latin12wchar_with_len, pg_latin1_mblen}, /* 8 */
{pg_latin12wchar_with_len, pg_latin1_mblen}, /* 9 */
{pg_latin12wchar_with_len, pg_latin1_mblen}, /* 10 */
{pg_latin12wchar_with_len, pg_latin1_mblen}, /* 11 */
{pg_latin12wchar_with_len, pg_latin1_mblen}, /* 12 */
{pg_latin12wchar_with_len, pg_latin1_mblen}, /* 13 */
{pg_latin12wchar_with_len, pg_latin1_mblen}, /* 14 */
{pg_latin12wchar_with_len, pg_latin1_mblen}, /* 15 */
{pg_latin12wchar_with_len, pg_latin1_mblen}, /* 16 */
{pg_latin12wchar_with_len, pg_latin1_mblen}, /* 17 */
{pg_latin12wchar_with_len, pg_latin1_mblen}, /* 18 */
{pg_latin12wchar_with_len, pg_latin1_mblen}, /* 19 */
{pg_latin12wchar_with_len, pg_latin1_mblen}, /* 20 */
{pg_latin12wchar_with_len, pg_latin1_mblen}, /* 21 */
{pg_latin12wchar_with_len, pg_latin1_mblen}, /* 22 */
{pg_latin12wchar_with_len, pg_latin1_mblen}, /* 23 */
{pg_latin12wchar_with_len, pg_latin1_mblen}, /* 24 */
{pg_latin12wchar_with_len, pg_latin1_mblen}, /* 25 */
{pg_latin12wchar_with_len, pg_latin1_mblen}, /* 26 */
{pg_latin12wchar_with_len, pg_latin1_mblen}, /* 27 */
{pg_latin12wchar_with_len, pg_latin1_mblen}, /* 28 */
{pg_latin12wchar_with_len, pg_latin1_mblen}, /* 29 */
{pg_latin12wchar_with_len, pg_latin1_mblen}, /* 30 */
{pg_latin12wchar_with_len, pg_latin1_mblen}, /* 31 */
{0, pg_sjis_mblen}, /* 32 */
{0, pg_big5_mblen} /* 33 */
{pg_latin12wchar_with_len, pg_latin1_mblen}, /* 7 */
{pg_latin12wchar_with_len, pg_latin1_mblen}, /* 8 */
{pg_latin12wchar_with_len, pg_latin1_mblen}, /* 9 */
{pg_latin12wchar_with_len, pg_latin1_mblen}, /* 10 */
{pg_latin12wchar_with_len, pg_latin1_mblen}, /* 11 */
{pg_latin12wchar_with_len, pg_latin1_mblen}, /* 12 */
{pg_latin12wchar_with_len, pg_latin1_mblen}, /* 13 */
{pg_latin12wchar_with_len, pg_latin1_mblen}, /* 14 */
{pg_latin12wchar_with_len, pg_latin1_mblen}, /* 15 */
{pg_latin12wchar_with_len, pg_latin1_mblen}, /* 16 */
{pg_latin12wchar_with_len, pg_latin1_mblen}, /* 17 */
{pg_latin12wchar_with_len, pg_latin1_mblen}, /* 18 */
{pg_latin12wchar_with_len, pg_latin1_mblen}, /* 19 */
{pg_latin12wchar_with_len, pg_latin1_mblen}, /* 20 */
{pg_latin12wchar_with_len, pg_latin1_mblen}, /* 21 */
{pg_latin12wchar_with_len, pg_latin1_mblen}, /* 22 */
{pg_latin12wchar_with_len, pg_latin1_mblen}, /* 23 */
{pg_latin12wchar_with_len, pg_latin1_mblen}, /* 24 */
{pg_latin12wchar_with_len, pg_latin1_mblen}, /* 25 */
{pg_latin12wchar_with_len, pg_latin1_mblen}, /* 26 */
{pg_latin12wchar_with_len, pg_latin1_mblen}, /* 27 */
{pg_latin12wchar_with_len, pg_latin1_mblen}, /* 28 */
{pg_latin12wchar_with_len, pg_latin1_mblen}, /* 29 */
{pg_latin12wchar_with_len, pg_latin1_mblen}, /* 30 */
{pg_latin12wchar_with_len, pg_latin1_mblen}, /* 31 */
{0, pg_sjis_mblen}, /* 32 */
{0, pg_big5_mblen} /* 33 */
};
/* returns the byte length of a word for mule internal code */

View File

@@ -4,63 +4,69 @@
*
* Tatsuo Ishii
*
* $Id: win.c,v 1.1 1999/03/24 07:01:37 ishii Exp $
* $Id: win.c,v 1.2 1999/05/25 16:12:45 momjian Exp $
*/
#include <stdio.h>
main()
{
int i;
char koitab[128],wintab[128];
char buf[4096];
int koi,win;
int i;
char koitab[128],
wintab[128];
char buf[4096];
int koi,
win;
for (i=0;i<128;i++) {
koitab[i] = wintab[i] = 0;
}
for (i = 0; i < 128; i++)
koitab[i] = wintab[i] = 0;
while (fgets(buf,sizeof(buf),stdin) != NULL) {
if (*buf == '#') {
continue;
}
sscanf(buf,"%d %d",&koi,&win);
if (koi < 128 || koi > 255 || win < 128 || win > 255) {
fprintf(stderr,"invalid value %d\n",koi);
exit(1);
}
koitab[koi-128] = win;
wintab[win-128] = koi;
}
while (fgets(buf, sizeof(buf), stdin) != NULL)
{
if (*buf == '#')
continue;
sscanf(buf, "%d %d", &koi, &win);
if (koi < 128 || koi > 255 || win < 128 || win > 255)
{
fprintf(stderr, "invalid value %d\n", koi);
exit(1);
}
koitab[koi - 128] = win;
wintab[win - 128] = koi;
}
i = 0;
printf("static char koi2win[] = {\n");
while (i < 128) {
int j = 0;
while (j < 8) {
printf("0x%02x",koitab[i++]);
j++;
if (i >= 128) {
break;
}
printf(", ");
}
printf("\n");
}
printf("};\n");
i = 0;
printf("static char koi2win[] = {\n");
while (i < 128)
{
int j = 0;
i = 0;
printf("static char win2koi[] = {\n");
while (i < 128) {
int j = 0;
while (j < 8) {
printf("0x%02x",wintab[i++]);
j++;
if (i >= 128) {
break;
}
printf(", ");
}
printf("\n");
}
printf("};\n");
while (j < 8)
{
printf("0x%02x", koitab[i++]);
j++;
if (i >= 128)
break;
printf(", ");
}
printf("\n");
}
printf("};\n");
i = 0;
printf("static char win2koi[] = {\n");
while (i < 128)
{
int j = 0;
while (j < 8)
{
printf("0x%02x", wintab[i++]);
j++;
if (i >= 128)
break;
printf(", ");
}
printf("\n");
}
printf("};\n");
}