msvcrt: Use per thread locale in many functions.

This commit is contained in:
Piotr Caban 2010-04-15 14:26:47 +02:00 committed by Alexandre Julliard
parent 87dee43b0a
commit d1fa8b64e4
4 changed files with 49 additions and 44 deletions

View File

@ -62,7 +62,7 @@ WORD* MSVCRT__pctype;
*/ */
WORD** CDECL MSVCRT___pctype_func(void) WORD** CDECL MSVCRT___pctype_func(void)
{ {
return &MSVCRT__pctype; return &get_locale()->locinfo->pctype;
} }
/********************************************************************* /*********************************************************************
@ -70,21 +70,23 @@ WORD** CDECL MSVCRT___pctype_func(void)
*/ */
int CDECL _isctype(int c, int type) int CDECL _isctype(int c, int type)
{ {
if (c >= -1 && c <= 255) MSVCRT__locale_t locale = get_locale();
return MSVCRT__pctype[c] & type;
if (MSVCRT___mb_cur_max != 1 && c > 0) if (c >= -1 && c <= 255)
return locale->locinfo->pctype[c] & type;
if (locale->locinfo->mb_cur_max != 1 && c > 0)
{ {
/* FIXME: Is there a faster way to do this? */ /* FIXME: Is there a faster way to do this? */
WORD typeInfo; WORD typeInfo;
char convert[3], *pconv = convert; char convert[3], *pconv = convert;
if (MSVCRT__pctype[(UINT)c >> 8] & MSVCRT__LEADBYTE) if (locale->locinfo->pctype[(UINT)c >> 8] & MSVCRT__LEADBYTE)
*pconv++ = (UINT)c >> 8; *pconv++ = (UINT)c >> 8;
*pconv++ = c & 0xff; *pconv++ = c & 0xff;
*pconv = 0; *pconv = 0;
/* FIXME: Use ctype LCID, not lc_all */ /* FIXME: Use ctype LCID, not lc_all */
if (GetStringTypeExA(MSVCRT_locale->locinfo->lc_handle[MSVCRT_LC_CTYPE], if (GetStringTypeExA(get_locale()->locinfo->lc_handle[MSVCRT_LC_CTYPE],
CT_CTYPE1, convert, convert[1] ? 2 : 1, &typeInfo)) CT_CTYPE1, convert, convert[1] ? 2 : 1, &typeInfo))
return typeInfo & type; return typeInfo & type;
} }

View File

@ -2467,7 +2467,7 @@ MSVCRT_wint_t CDECL MSVCRT_fgetwc(MSVCRT_FILE* file)
} }
c = MSVCRT_fgetc(file); c = MSVCRT_fgetc(file);
if ((MSVCRT___mb_cur_max > 1) && MSVCRT_isleadbyte(c)) if ((get_locale()->locinfo->mb_cur_max > 1) && MSVCRT_isleadbyte(c))
{ {
FIXME("Treat Multibyte characters\n"); FIXME("Treat Multibyte characters\n");
} }

View File

@ -526,7 +526,7 @@ int CDECL ___lc_codepage_func(void)
*/ */
int CDECL ___lc_collate_cp_func(void) int CDECL ___lc_collate_cp_func(void)
{ {
return MSVCRT___lc_collate_cp; return get_locale()->locinfo->lc_collate_cp;
} }
/* _free_locale - not exported in native msvcrt */ /* _free_locale - not exported in native msvcrt */

View File

@ -85,7 +85,7 @@ static MSVCRT_wchar_t msvcrt_mbc_to_wc(unsigned int ch)
mbch[1] = ch & 0xff; mbch[1] = ch & 0xff;
n_chars = 2; n_chars = 2;
} }
if (!MultiByteToWideChar(MSVCRT___lc_codepage, 0, mbch, n_chars, &chW, 1)) if (!MultiByteToWideChar(get_locale()->locinfo->lc_codepage, 0, mbch, n_chars, &chW, 1))
{ {
WARN("MultiByteToWideChar failed on %x\n", ch); WARN("MultiByteToWideChar failed on %x\n", ch);
return 0; return 0;
@ -166,7 +166,7 @@ unsigned char* CDECL __p__mbctype(void)
*/ */
int* CDECL MSVCRT____mb_cur_max_func(void) int* CDECL MSVCRT____mb_cur_max_func(void)
{ {
return &MSVCRT___mb_cur_max; return &get_locale()->locinfo->mb_cur_max;
} }
/********************************************************************* /*********************************************************************
@ -174,6 +174,7 @@ int* CDECL MSVCRT____mb_cur_max_func(void)
*/ */
int CDECL _setmbcp(int cp) int CDECL _setmbcp(int cp)
{ {
MSVCRT__locale_t locale = get_locale();
int newcp; int newcp;
CPINFO cpi; CPINFO cpi;
BYTE *bytes; BYTE *bytes;
@ -194,7 +195,7 @@ int CDECL _setmbcp(int cp)
newcp = GetOEMCP(); newcp = GetOEMCP();
break; break;
case _MB_CP_LOCALE: case _MB_CP_LOCALE:
newcp = MSVCRT___lc_codepage; newcp = locale->locinfo->lc_codepage;
break; break;
case _MB_CP_SBCS: case _MB_CP_SBCS:
newcp = 20127; /* ASCII */ newcp = 20127; /* ASCII */
@ -287,8 +288,9 @@ int CDECL _setmbcp(int cp)
MSVCRT_mbctype[i + 1] |= _MS; MSVCRT_mbctype[i + 1] |= _MS;
} }
MSVCRT___lc_collate_cp = MSVCRT___lc_codepage = newcp; locale->locinfo->lc_collate_cp = newcp;
TRACE("(%d) -> %d\n", cp, MSVCRT___lc_codepage); locale->locinfo->lc_codepage = newcp;
TRACE("(%d) -> %d\n", cp, locale->locinfo->lc_codepage);
return 0; return 0;
} }
@ -297,7 +299,8 @@ int CDECL _setmbcp(int cp)
*/ */
int CDECL _getmbcp(void) int CDECL _getmbcp(void)
{ {
return MSVCRT___lc_codepage; /* FIXME: get_locale()->mbcinfo->mbcodepage should be used here */
return get_locale()->locinfo->lc_codepage;
} }
/********************************************************************* /*********************************************************************
@ -343,7 +346,7 @@ unsigned int CDECL _mbctombb(unsigned int c)
{ {
unsigned int value; unsigned int value;
if(MSVCRT___lc_codepage == 932) if(get_locale()->locinfo->lc_codepage == 932)
{ {
if(c >= 0x829f && c <= 0x82f1) /* Hiragana */ if(c >= 0x829f && c <= 0x82f1) /* Hiragana */
return mbctombb_932_kana[c - 0x829f]; return mbctombb_932_kana[c - 0x829f];
@ -375,7 +378,7 @@ unsigned int CDECL _mbcjistojms(unsigned int c)
{ {
/* Conversion takes place only when codepage is 932. /* Conversion takes place only when codepage is 932.
In all other cases, c is returned unchanged */ In all other cases, c is returned unchanged */
if(MSVCRT___lc_codepage == 932) if(get_locale()->locinfo->lc_codepage == 932)
{ {
if(HIBYTE(c) >= 0x21 && HIBYTE(c) <= 0x7e && if(HIBYTE(c) >= 0x21 && HIBYTE(c) <= 0x7e &&
LOBYTE(c) >= 0x21 && LOBYTE(c) <= 0x7e) LOBYTE(c) >= 0x21 && LOBYTE(c) <= 0x7e)
@ -405,7 +408,7 @@ unsigned int CDECL _mbcjistojms(unsigned int c)
*/ */
unsigned char* CDECL _mbsdec(const unsigned char* start, const unsigned char* cur) unsigned char* CDECL _mbsdec(const unsigned char* start, const unsigned char* cur)
{ {
if(MSVCRT___mb_cur_max > 1) if(get_locale()->locinfo->mb_cur_max > 1)
return (unsigned char *)(_ismbstrail(start,cur-1) ? cur - 2 : cur -1); return (unsigned char *)(_ismbstrail(start,cur-1) ? cur - 2 : cur -1);
return (unsigned char *)cur - 1; /* ASCII CP or SB char */ return (unsigned char *)cur - 1; /* ASCII CP or SB char */
@ -629,7 +632,7 @@ unsigned char* CDECL _mbsnbcpy(unsigned char* dst, const unsigned char* src, MSV
*/ */
int CDECL _mbscmp(const unsigned char* str, const unsigned char* cmp) int CDECL _mbscmp(const unsigned char* str, const unsigned char* cmp)
{ {
if(MSVCRT___mb_cur_max > 1) if(get_locale()->locinfo->mb_cur_max > 1)
{ {
unsigned int strc, cmpc; unsigned int strc, cmpc;
do { do {
@ -654,7 +657,7 @@ int CDECL _mbscmp(const unsigned char* str, const unsigned char* cmp)
*/ */
int CDECL _mbsicoll(const unsigned char* str, const unsigned char* cmp) int CDECL _mbsicoll(const unsigned char* str, const unsigned char* cmp)
{ {
if(MSVCRT___mb_cur_max > 1) if(get_locale()->locinfo->mb_cur_max > 1)
{ {
unsigned int strc, cmpc; unsigned int strc, cmpc;
do { do {
@ -682,7 +685,7 @@ int CDECL _mbsicoll(const unsigned char* str, const unsigned char* cmp)
*/ */
int CDECL _mbscoll(const unsigned char* str, const unsigned char* cmp) int CDECL _mbscoll(const unsigned char* str, const unsigned char* cmp)
{ {
if(MSVCRT___mb_cur_max > 1) if(get_locale()->locinfo->mb_cur_max > 1)
{ {
unsigned int strc, cmpc; unsigned int strc, cmpc;
do { do {
@ -707,7 +710,7 @@ int CDECL _mbscoll(const unsigned char* str, const unsigned char* cmp)
*/ */
int CDECL _mbsicmp(const unsigned char* str, const unsigned char* cmp) int CDECL _mbsicmp(const unsigned char* str, const unsigned char* cmp)
{ {
if(MSVCRT___mb_cur_max > 1) if(get_locale()->locinfo->mb_cur_max > 1)
{ {
unsigned int strc, cmpc; unsigned int strc, cmpc;
do { do {
@ -734,7 +737,7 @@ int CDECL _mbsncmp(const unsigned char* str, const unsigned char* cmp, MSVCRT_si
if(!len) if(!len)
return 0; return 0;
if(MSVCRT___mb_cur_max > 1) if(get_locale()->locinfo->mb_cur_max > 1)
{ {
unsigned int strc, cmpc; unsigned int strc, cmpc;
while(len--) while(len--)
@ -764,7 +767,7 @@ int CDECL _mbsnbcmp(const unsigned char* str, const unsigned char* cmp, MSVCRT_s
{ {
if (!len) if (!len)
return 0; return 0;
if(MSVCRT___mb_cur_max > 1) if(get_locale()->locinfo->mb_cur_max > 1)
{ {
unsigned int strc, cmpc; unsigned int strc, cmpc;
while (len) while (len)
@ -807,7 +810,7 @@ int CDECL _mbsnbcmp(const unsigned char* str, const unsigned char* cmp, MSVCRT_s
int CDECL _mbsnicmp(const unsigned char* str, const unsigned char* cmp, MSVCRT_size_t len) int CDECL _mbsnicmp(const unsigned char* str, const unsigned char* cmp, MSVCRT_size_t len)
{ {
/* FIXME: No tolower() for mb strings yet */ /* FIXME: No tolower() for mb strings yet */
if(MSVCRT___mb_cur_max > 1) if(get_locale()->locinfo->mb_cur_max > 1)
{ {
unsigned int strc, cmpc; unsigned int strc, cmpc;
while(len--) while(len--)
@ -835,7 +838,7 @@ int CDECL _mbsnbicmp(const unsigned char* str, const unsigned char* cmp, MSVCRT_
{ {
if (!len) if (!len)
return 0; return 0;
if(MSVCRT___mb_cur_max > 1) if(get_locale()->locinfo->mb_cur_max > 1)
{ {
unsigned int strc, cmpc; unsigned int strc, cmpc;
while (len) while (len)
@ -905,7 +908,7 @@ unsigned char * CDECL _mbsstr(const unsigned char *haystack, const unsigned char
*/ */
unsigned char* CDECL _mbschr(const unsigned char* s, unsigned int x) unsigned char* CDECL _mbschr(const unsigned char* s, unsigned int x)
{ {
if(MSVCRT___mb_cur_max > 1) if(get_locale()->locinfo->mb_cur_max > 1)
{ {
unsigned int c; unsigned int c;
while (1) while (1)
@ -926,7 +929,7 @@ unsigned char* CDECL _mbschr(const unsigned char* s, unsigned int x)
*/ */
unsigned char* CDECL _mbsrchr(const unsigned char* s, unsigned int x) unsigned char* CDECL _mbsrchr(const unsigned char* s, unsigned int x)
{ {
if(MSVCRT___mb_cur_max > 1) if(get_locale()->locinfo->mb_cur_max > 1)
{ {
unsigned int c; unsigned int c;
unsigned char* match=NULL; unsigned char* match=NULL;
@ -954,7 +957,7 @@ unsigned char* CDECL _mbstok(unsigned char *str, const unsigned char *delim)
thread_data_t *data = msvcrt_get_thread_data(); thread_data_t *data = msvcrt_get_thread_data();
unsigned char *ret; unsigned char *ret;
if(MSVCRT___mb_cur_max > 1) if(get_locale()->locinfo->mb_cur_max > 1)
{ {
unsigned int c; unsigned int c;
@ -1006,7 +1009,7 @@ int CDECL MSVCRT_mbtowc(MSVCRT_wchar_t *dst, const char* str, MSVCRT_size_t n)
*/ */
unsigned int CDECL _mbbtombc(unsigned int c) unsigned int CDECL _mbbtombc(unsigned int c)
{ {
if(MSVCRT___mb_cur_max > 1 && if(get_locale()->locinfo->mb_cur_max > 1 &&
((c >= 0x20 && c <=0x7e) ||(c >= 0xa1 && c <= 0xdf))) ((c >= 0x20 && c <=0x7e) ||(c >= 0xa1 && c <= 0xdf)))
{ {
/* FIXME: I can't get this function to return anything /* FIXME: I can't get this function to return anything
@ -1047,7 +1050,7 @@ int CDECL _mbbtype(unsigned char c, int type)
int CDECL _ismbbkana(unsigned int c) int CDECL _ismbbkana(unsigned int c)
{ {
/* FIXME: use lc_ctype when supported, not lc_all */ /* FIXME: use lc_ctype when supported, not lc_all */
if(MSVCRT___lc_codepage == 932) if(get_locale()->locinfo->lc_codepage == 932)
{ {
/* Japanese/Katakana, CP 932 */ /* Japanese/Katakana, CP 932 */
return (c >= 0xa1 && c <= 0xdf); return (c >= 0xa1 && c <= 0xdf);
@ -1157,7 +1160,7 @@ int CDECL _ismbcpunct(unsigned int ch)
int CDECL _ismbchira(unsigned int c) int CDECL _ismbchira(unsigned int c)
{ {
/* FIXME: use lc_ctype when supported, not lc_all */ /* FIXME: use lc_ctype when supported, not lc_all */
if(MSVCRT___lc_codepage == 932) if(get_locale()->locinfo->lc_codepage == 932)
{ {
/* Japanese/Hiragana, CP 932 */ /* Japanese/Hiragana, CP 932 */
return (c >= 0x829f && c <= 0x82f1); return (c >= 0x829f && c <= 0x82f1);
@ -1171,7 +1174,7 @@ int CDECL _ismbchira(unsigned int c)
int CDECL _ismbckata(unsigned int c) int CDECL _ismbckata(unsigned int c)
{ {
/* FIXME: use lc_ctype when supported, not lc_all */ /* FIXME: use lc_ctype when supported, not lc_all */
if(MSVCRT___lc_codepage == 932) if(get_locale()->locinfo->lc_codepage == 932)
{ {
if(c < 256) if(c < 256)
return _ismbbkana(c); return _ismbbkana(c);
@ -1280,7 +1283,7 @@ unsigned char* CDECL _mbsset(unsigned char* str, unsigned int c)
{ {
unsigned char* ret = str; unsigned char* ret = str;
if(MSVCRT___mb_cur_max == 1 || c < 256) if(get_locale()->locinfo->mb_cur_max == 1 || c < 256)
return u__strset(str, c); /* ASCII CP or SB char */ return u__strset(str, c); /* ASCII CP or SB char */
c &= 0xffff; /* Strip high bits */ c &= 0xffff; /* Strip high bits */
@ -1306,7 +1309,7 @@ unsigned char* CDECL _mbsnbset(unsigned char *str, unsigned int c, MSVCRT_size_t
if(!len) if(!len)
return ret; return ret;
if(MSVCRT___mb_cur_max == 1 || c < 256) if(get_locale()->locinfo->mb_cur_max == 1 || c < 256)
return u__strnset(str, c, len); /* ASCII CP or SB char */ return u__strnset(str, c, len); /* ASCII CP or SB char */
c &= 0xffff; /* Strip high bits */ c &= 0xffff; /* Strip high bits */
@ -1336,7 +1339,7 @@ unsigned char* CDECL _mbsnset(unsigned char* str, unsigned int c, MSVCRT_size_t
if(!len) if(!len)
return ret; return ret;
if(MSVCRT___mb_cur_max == 1 || c < 256) if(get_locale()->locinfo->mb_cur_max == 1 || c < 256)
return u__strnset(str, c, len); /* ASCII CP or SB char */ return u__strnset(str, c, len); /* ASCII CP or SB char */
c &= 0xffff; /* Strip high bits */ c &= 0xffff; /* Strip high bits */
@ -1359,7 +1362,7 @@ unsigned char* CDECL _mbsnset(unsigned char* str, unsigned int c, MSVCRT_size_t
MSVCRT_size_t CDECL _mbsnccnt(const unsigned char* str, MSVCRT_size_t len) MSVCRT_size_t CDECL _mbsnccnt(const unsigned char* str, MSVCRT_size_t len)
{ {
MSVCRT_size_t ret; MSVCRT_size_t ret;
if(MSVCRT___mb_cur_max > 1) if(get_locale()->locinfo->mb_cur_max > 1)
{ {
ret=0; ret=0;
while(*str && len-- > 0) while(*str && len-- > 0)
@ -1387,7 +1390,7 @@ MSVCRT_size_t CDECL _mbsnccnt(const unsigned char* str, MSVCRT_size_t len)
MSVCRT_size_t CDECL _mbsnbcnt(const unsigned char* str, MSVCRT_size_t len) MSVCRT_size_t CDECL _mbsnbcnt(const unsigned char* str, MSVCRT_size_t len)
{ {
MSVCRT_size_t ret; MSVCRT_size_t ret;
if(MSVCRT___mb_cur_max > 1) if(get_locale()->locinfo->mb_cur_max > 1)
{ {
const unsigned char* xstr = str; const unsigned char* xstr = str;
while(*xstr && len-- > 0) while(*xstr && len-- > 0)
@ -1406,7 +1409,7 @@ MSVCRT_size_t CDECL _mbsnbcnt(const unsigned char* str, MSVCRT_size_t len)
*/ */
unsigned char* CDECL _mbsnbcat(unsigned char* dst, const unsigned char* src, MSVCRT_size_t len) unsigned char* CDECL _mbsnbcat(unsigned char* dst, const unsigned char* src, MSVCRT_size_t len)
{ {
if(MSVCRT___mb_cur_max > 1) if(get_locale()->locinfo->mb_cur_max > 1)
{ {
unsigned char *res = dst; unsigned char *res = dst;
while (*dst) { while (*dst) {
@ -1433,7 +1436,7 @@ unsigned char* CDECL _mbsnbcat(unsigned char* dst, const unsigned char* src, MSV
*/ */
unsigned char* CDECL _mbsncat(unsigned char* dst, const unsigned char* src, MSVCRT_size_t len) unsigned char* CDECL _mbsncat(unsigned char* dst, const unsigned char* src, MSVCRT_size_t len)
{ {
if(MSVCRT___mb_cur_max > 1) if(get_locale()->locinfo->mb_cur_max > 1)
{ {
unsigned char *res = dst; unsigned char *res = dst;
while (*dst) while (*dst)
@ -1462,7 +1465,7 @@ unsigned char* CDECL _mbslwr(unsigned char* s)
unsigned char *ret = s; unsigned char *ret = s;
if (!s) if (!s)
return NULL; return NULL;
if (MSVCRT___mb_cur_max > 1) if (get_locale()->locinfo->mb_cur_max > 1)
{ {
unsigned int c; unsigned int c;
while (*s) while (*s)
@ -1490,7 +1493,7 @@ unsigned char* CDECL _mbsupr(unsigned char* s)
unsigned char *ret = s; unsigned char *ret = s;
if (!s) if (!s)
return NULL; return NULL;
if (MSVCRT___mb_cur_max > 1) if (get_locale()->locinfo->mb_cur_max > 1)
{ {
unsigned int c; unsigned int c;
while (*s) while (*s)
@ -1581,7 +1584,7 @@ unsigned char* CDECL _mbsspnp(const unsigned char* string, const unsigned char*
*/ */
MSVCRT_size_t CDECL _mbscspn(const unsigned char* str, const unsigned char* cmp) MSVCRT_size_t CDECL _mbscspn(const unsigned char* str, const unsigned char* cmp)
{ {
if (MSVCRT___mb_cur_max > 1) if (get_locale()->locinfo->mb_cur_max > 1)
FIXME("don't handle double character case\n"); FIXME("don't handle double character case\n");
return u_strcspn(str, cmp); return u_strcspn(str, cmp);
} }
@ -1668,7 +1671,7 @@ int CDECL MSVCRT_mblen(const char* str, MSVCRT_size_t size)
{ {
if (str && *str && size) if (str && *str && size)
{ {
if(MSVCRT___mb_cur_max == 1) if(get_locale()->locinfo->mb_cur_max == 1)
return 1; /* ASCII CP */ return 1; /* ASCII CP */
return !MSVCRT_isleadbyte(*str) ? 1 : (size>1 ? 2 : -1); return !MSVCRT_isleadbyte(*str) ? 1 : (size>1 ? 2 : -1);
@ -1684,7 +1687,7 @@ int CDECL MSVCRT_mblen(const char* str, MSVCRT_size_t size)
*/ */
MSVCRT_size_t CDECL _mbstrlen(const char* str) MSVCRT_size_t CDECL _mbstrlen(const char* str)
{ {
if(MSVCRT___mb_cur_max > 1) if(get_locale()->locinfo->mb_cur_max > 1)
{ {
MSVCRT_size_t len = 0; MSVCRT_size_t len = 0;
while(*str) while(*str)