libexpat/expat/xmlwf/codepage.c

69 lines
1.3 KiB
C
Raw Normal View History

/* Copyright (c) 1998, 1999 Thai Open Source Software Center Ltd
See the file COPYING for copying permission.
*/
1998-06-01 08:12:51 -04:00
#include "codepage.h"
#ifdef WIN32
1998-11-24 04:31:04 -05:00
#define STRICT 1
#define WIN32_LEAN_AND_MEAN 1
1998-06-01 08:12:51 -04:00
#include <windows.h>
int
codepageMap(int cp, int *map)
1998-06-01 08:12:51 -04:00
{
int i;
CPINFO info;
1998-06-02 04:57:14 -04:00
if (!GetCPInfo(cp, &info) || info.MaxCharSize > 2)
1998-06-01 08:12:51 -04:00
return 0;
1998-06-02 04:57:14 -04:00
for (i = 0; i < 256; i++)
map[i] = -1;
1998-06-02 04:57:14 -04:00
if (info.MaxCharSize > 1) {
for (i = 0; i < MAX_LEADBYTES; i++) {
int j, lim;
if (info.LeadByte[i] == 0 && info.LeadByte[i + 1] == 0)
break;
lim = info.LeadByte[i + 1];
for (j = info.LeadByte[i]; j < lim; j++)
map[j] = -2;
1998-06-02 04:57:14 -04:00
}
}
1998-06-01 08:12:51 -04:00
for (i = 0; i < 256; i++) {
if (map[i] == -1) {
char c = (char)i;
unsigned short n;
1998-06-02 04:57:14 -04:00
if (MultiByteToWideChar(cp, MB_PRECOMPOSED|MB_ERR_INVALID_CHARS,
&c, 1, &n, 1) == 1)
map[i] = n;
1998-06-02 04:57:14 -04:00
}
1998-06-01 08:12:51 -04:00
}
return 1;
}
int
codepageConvert(int cp, const char *p)
1998-06-02 04:57:14 -04:00
{
unsigned short c;
if (MultiByteToWideChar(cp, MB_PRECOMPOSED|MB_ERR_INVALID_CHARS,
p, 2, &c, 1) == 1)
1998-06-02 04:57:14 -04:00
return c;
return -1;
1998-06-02 04:57:14 -04:00
}
1998-06-01 08:12:51 -04:00
#else /* not WIN32 */
int
codepageMap(int cp, int *map)
1998-06-02 04:57:14 -04:00
{
return 0;
}
int
codepageConvert(int cp, const char *p)
1998-06-01 08:12:51 -04:00
{
return -1;
1998-06-01 08:12:51 -04:00
}
#endif /* not WIN32 */