/* * $Id: uconv.c,v 1.1 2000/10/12 06:06:50 ishii Exp $ */ #include "pg_wchar.h" /* * convert UCS-2 to UTF-8 * returns number of bytes of a UTF-8, that is atmost 3. */ static int pg_ucs2utf(const unsigned short ucs, unsigned char *utf) { int len; if (ucs <= 0x007f) { *utf = ucs; len = 1; } else if (ucs > 0x007f && ucs <= 0x07ff) { *utf++ = (ucs >> 6) | 0xc0; *utf = (ucs & 0x003f) | 0x80; len = 2; } else { *utf++ = (ucs >> 12) | 0xe0; *utf++ = ((ucs & 0x0fc0) >> 6) | 0x80; *utf = (ucs & 0x003f) | 0x80; len = 3; } return (len); } typedef struct { unsigned short ucs; /* UCS-2 */ unsigned short code; /* local code */ unsigned char encoding; /* encoding */ } ucs_to_local; typedef struct { unsigned short code; /* local code */ unsigned short ucs; /* UCS-2 */ } local_to_ucs; #include "ucs_to_iso8859.map" #include "iso88592.rev" #include "iso88593.rev" #include "iso88594.rev" #include "iso88595.rev" #define X0208 0 #define X0212 1 #include "ucs_to_jis.map" int main() { int i,j; int l; unsigned int euc; unsigned char u[4]; FILE *fd; printf("static pg_utf_to_local mapISO8859[] = {\n"); for (i=0;i LATIN5) continue; l = pg_ucs2utf(mapISO8859[i].ucs, u); printf(" {0x"); for(j=0;jname); } printf("};\n"); printf("\nstatic pg_local_to_utf ISO8859_2[] = {\n"); for (i=0;i