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