1104349Sphk/* Copyright (c) 1998, 1999 Thai Open Source Software Center Ltd 2104349Sphk See the file COPYING for copying permission. 3104349Sphk*/ 4104349Sphk 5104349Sphk#include "codepage.h" 6104349Sphk 7178848Scokane#if (defined(WIN32) || (defined(__WATCOMC__) && defined(__NT__))) 8104349Sphk#define STRICT 1 9104349Sphk#define WIN32_LEAN_AND_MEAN 1 10104349Sphk 11104349Sphk#include <windows.h> 12104349Sphk 13104349Sphkint 14104349SphkcodepageMap(int cp, int *map) 15104349Sphk{ 16104349Sphk int i; 17104349Sphk CPINFO info; 18104349Sphk if (!GetCPInfo(cp, &info) || info.MaxCharSize > 2) 19104349Sphk return 0; 20104349Sphk for (i = 0; i < 256; i++) 21104349Sphk map[i] = -1; 22104349Sphk if (info.MaxCharSize > 1) { 23178848Scokane for (i = 0; i < MAX_LEADBYTES; i+=2) { 24104349Sphk int j, lim; 25104349Sphk if (info.LeadByte[i] == 0 && info.LeadByte[i + 1] == 0) 26104349Sphk break; 27104349Sphk lim = info.LeadByte[i + 1]; 28178848Scokane for (j = info.LeadByte[i]; j <= lim; j++) 29104349Sphk map[j] = -2; 30104349Sphk } 31104349Sphk } 32104349Sphk for (i = 0; i < 256; i++) { 33104349Sphk if (map[i] == -1) { 34104349Sphk char c = (char)i; 35104349Sphk unsigned short n; 36104349Sphk if (MultiByteToWideChar(cp, MB_PRECOMPOSED|MB_ERR_INVALID_CHARS, 37104349Sphk &c, 1, &n, 1) == 1) 38104349Sphk map[i] = n; 39104349Sphk } 40104349Sphk } 41104349Sphk return 1; 42104349Sphk} 43104349Sphk 44104349Sphkint 45104349SphkcodepageConvert(int cp, const char *p) 46104349Sphk{ 47104349Sphk unsigned short c; 48104349Sphk if (MultiByteToWideChar(cp, MB_PRECOMPOSED|MB_ERR_INVALID_CHARS, 49104349Sphk p, 2, &c, 1) == 1) 50104349Sphk return c; 51104349Sphk return -1; 52104349Sphk} 53104349Sphk 54104349Sphk#else /* not WIN32 */ 55104349Sphk 56104349Sphkint 57104349SphkcodepageMap(int cp, int *map) 58104349Sphk{ 59104349Sphk return 0; 60104349Sphk} 61104349Sphk 62104349Sphkint 63104349SphkcodepageConvert(int cp, const char *p) 64104349Sphk{ 65104349Sphk return -1; 66104349Sphk} 67104349Sphk 68104349Sphk#endif /* not WIN32 */ 69