1*1230fdc1SLionel Sambuc /* Copyright (c) 1998, 1999 Thai Open Source Software Center Ltd
2*1230fdc1SLionel Sambuc See the file COPYING for copying permission.
3*1230fdc1SLionel Sambuc */
4*1230fdc1SLionel Sambuc
5*1230fdc1SLionel Sambuc #include "codepage.h"
6*1230fdc1SLionel Sambuc
7*1230fdc1SLionel Sambuc #if (defined(WIN32) || (defined(__WATCOMC__) && defined(__NT__)))
8*1230fdc1SLionel Sambuc #define STRICT 1
9*1230fdc1SLionel Sambuc #define WIN32_LEAN_AND_MEAN 1
10*1230fdc1SLionel Sambuc
11*1230fdc1SLionel Sambuc #include <windows.h>
12*1230fdc1SLionel Sambuc
13*1230fdc1SLionel Sambuc int
codepageMap(int cp,int * map)14*1230fdc1SLionel Sambuc codepageMap(int cp, int *map)
15*1230fdc1SLionel Sambuc {
16*1230fdc1SLionel Sambuc int i;
17*1230fdc1SLionel Sambuc CPINFO info;
18*1230fdc1SLionel Sambuc if (!GetCPInfo(cp, &info) || info.MaxCharSize > 2)
19*1230fdc1SLionel Sambuc return 0;
20*1230fdc1SLionel Sambuc for (i = 0; i < 256; i++)
21*1230fdc1SLionel Sambuc map[i] = -1;
22*1230fdc1SLionel Sambuc if (info.MaxCharSize > 1) {
23*1230fdc1SLionel Sambuc for (i = 0; i < MAX_LEADBYTES; i+=2) {
24*1230fdc1SLionel Sambuc int j, lim;
25*1230fdc1SLionel Sambuc if (info.LeadByte[i] == 0 && info.LeadByte[i + 1] == 0)
26*1230fdc1SLionel Sambuc break;
27*1230fdc1SLionel Sambuc lim = info.LeadByte[i + 1];
28*1230fdc1SLionel Sambuc for (j = info.LeadByte[i]; j <= lim; j++)
29*1230fdc1SLionel Sambuc map[j] = -2;
30*1230fdc1SLionel Sambuc }
31*1230fdc1SLionel Sambuc }
32*1230fdc1SLionel Sambuc for (i = 0; i < 256; i++) {
33*1230fdc1SLionel Sambuc if (map[i] == -1) {
34*1230fdc1SLionel Sambuc char c = (char)i;
35*1230fdc1SLionel Sambuc unsigned short n;
36*1230fdc1SLionel Sambuc if (MultiByteToWideChar(cp, MB_PRECOMPOSED|MB_ERR_INVALID_CHARS,
37*1230fdc1SLionel Sambuc &c, 1, &n, 1) == 1)
38*1230fdc1SLionel Sambuc map[i] = n;
39*1230fdc1SLionel Sambuc }
40*1230fdc1SLionel Sambuc }
41*1230fdc1SLionel Sambuc return 1;
42*1230fdc1SLionel Sambuc }
43*1230fdc1SLionel Sambuc
44*1230fdc1SLionel Sambuc int
codepageConvert(int cp,const char * p)45*1230fdc1SLionel Sambuc codepageConvert(int cp, const char *p)
46*1230fdc1SLionel Sambuc {
47*1230fdc1SLionel Sambuc unsigned short c;
48*1230fdc1SLionel Sambuc if (MultiByteToWideChar(cp, MB_PRECOMPOSED|MB_ERR_INVALID_CHARS,
49*1230fdc1SLionel Sambuc p, 2, &c, 1) == 1)
50*1230fdc1SLionel Sambuc return c;
51*1230fdc1SLionel Sambuc return -1;
52*1230fdc1SLionel Sambuc }
53*1230fdc1SLionel Sambuc
54*1230fdc1SLionel Sambuc #else /* not WIN32 */
55*1230fdc1SLionel Sambuc
56*1230fdc1SLionel Sambuc int
codepageMap(int cp,int * map)57*1230fdc1SLionel Sambuc codepageMap(int cp, int *map)
58*1230fdc1SLionel Sambuc {
59*1230fdc1SLionel Sambuc return 0;
60*1230fdc1SLionel Sambuc }
61*1230fdc1SLionel Sambuc
62*1230fdc1SLionel Sambuc int
codepageConvert(int cp,const char * p)63*1230fdc1SLionel Sambuc codepageConvert(int cp, const char *p)
64*1230fdc1SLionel Sambuc {
65*1230fdc1SLionel Sambuc return -1;
66*1230fdc1SLionel Sambuc }
67*1230fdc1SLionel Sambuc
68*1230fdc1SLionel Sambuc #endif /* not WIN32 */
69