mirror of
https://github.com/reactos/wine.git
synced 2025-02-21 05:11:57 +00:00
msvcrt: Don't duplicate _setmbcp functionality inside _create_locale function.
This commit is contained in:
parent
76ef187700
commit
fea69b2305
@ -747,7 +747,6 @@ MSVCRT__locale_t MSVCRT__create_locale(int category, const char *locale)
|
||||
}
|
||||
|
||||
memset(loc->locinfo, 0, sizeof(MSVCRT_threadlocinfo));
|
||||
memset(loc->mbcinfo, 0, sizeof(MSVCRT_threadmbcinfo));
|
||||
|
||||
loc->locinfo->lconv = MSVCRT_malloc(sizeof(struct MSVCRT_lconv));
|
||||
if(!loc->locinfo->lconv) {
|
||||
@ -840,18 +839,7 @@ MSVCRT__locale_t MSVCRT__create_locale(int category, const char *locale)
|
||||
}
|
||||
}
|
||||
|
||||
loc->mbcinfo->refcount = 1;
|
||||
loc->mbcinfo->mbcodepage = loc->locinfo->lc_id[MSVCRT_LC_CTYPE].wCodePage;
|
||||
|
||||
for(i=0; i<256; i++) {
|
||||
if(loc->locinfo->pclmap[i] != i) {
|
||||
loc->mbcinfo->mbctype[i+1] |= 0x10;
|
||||
loc->mbcinfo->mbcasemap[i] = loc->locinfo->pclmap[i];
|
||||
} else if(loc->locinfo->pcumap[i] != i) {
|
||||
loc->mbcinfo->mbctype[i+1] |= 0x20;
|
||||
loc->mbcinfo->mbcasemap[i] = loc->locinfo->pcumap[i];
|
||||
}
|
||||
}
|
||||
_setmbcp_l(loc->locinfo->lc_id[MSVCRT_LC_CTYPE].wCodePage, loc->mbcinfo);
|
||||
|
||||
if(lcid[MSVCRT_LC_MONETARY] && (category==MSVCRT_LC_ALL || category==MSVCRT_LC_MONETARY)) {
|
||||
if(update_threadlocinfo_category(lcid[MSVCRT_LC_MONETARY], loc, MSVCRT_LC_MONETARY)) {
|
||||
|
@ -182,25 +182,25 @@ int* CDECL ___mb_cur_max_l_func(MSVCRT__locale_t locale)
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* _setmbcp (MSVCRT.@)
|
||||
* INTERNAL: _setmbcp_l
|
||||
*/
|
||||
int CDECL _setmbcp(int cp)
|
||||
int _setmbcp_l(int cp, MSVCRT_pthreadmbcinfo mbcinfo)
|
||||
{
|
||||
const char format[] = ".%d";
|
||||
|
||||
MSVCRT_pthreadmbcinfo mbcinfo = get_mbcinfo();
|
||||
char buf[32];
|
||||
int newcp;
|
||||
CPINFO cpi;
|
||||
BYTE *bytes;
|
||||
WORD chartypes[256];
|
||||
WORD *curr_type;
|
||||
char bufA[256];
|
||||
WCHAR bufW[256];
|
||||
int charcount;
|
||||
int ret;
|
||||
int i;
|
||||
|
||||
if(!mbcinfo)
|
||||
mbcinfo = get_mbcinfo();
|
||||
|
||||
switch (cp)
|
||||
{
|
||||
case _MB_CP_ANSI:
|
||||
@ -222,8 +222,8 @@ int CDECL _setmbcp(int cp)
|
||||
break;
|
||||
}
|
||||
|
||||
sprintf(buf, format, newcp);
|
||||
mbcinfo->mblcid = MSVCRT_locale_to_LCID(buf);
|
||||
sprintf(bufA, format, newcp);
|
||||
mbcinfo->mblcid = MSVCRT_locale_to_LCID(bufA);
|
||||
if(mbcinfo->mblcid == -1)
|
||||
{
|
||||
WARN("Can't assign LCID to codepage (%d)\n", mbcinfo->mblcid);
|
||||
@ -290,17 +290,38 @@ int CDECL _setmbcp(int cp)
|
||||
|
||||
GetStringTypeW(CT_CTYPE1, bufW, charcount, chartypes);
|
||||
|
||||
curr_type = chartypes;
|
||||
charcount = 0;
|
||||
for (i = 0; i < 256; i++)
|
||||
if (!(mbcinfo->mbctype[i + 1] & _M1))
|
||||
{
|
||||
if ((*curr_type) & C1_UPPER)
|
||||
mbcinfo->mbctype[i + 1] |= _SBUP;
|
||||
if ((*curr_type) & C1_LOWER)
|
||||
mbcinfo->mbctype[i + 1] |= _SBLOW;
|
||||
curr_type++;
|
||||
if (chartypes[charcount] & C1_UPPER)
|
||||
{
|
||||
mbcinfo->mbctype[i + 1] |= _SBUP;
|
||||
bufW[charcount] = tolowerW(bufW[charcount]);
|
||||
}
|
||||
else if (chartypes[charcount] & C1_LOWER)
|
||||
{
|
||||
mbcinfo->mbctype[i + 1] |= _SBLOW;
|
||||
bufW[charcount] = toupperW(bufW[charcount]);
|
||||
}
|
||||
charcount++;
|
||||
}
|
||||
|
||||
ret = WideCharToMultiByte(newcp, 0, bufW, charcount, bufA, charcount, NULL, NULL);
|
||||
if (ret != charcount)
|
||||
ERR("WideCharToMultiByte failed for cp %d, ret=%d (exp %d), error=%d\n", newcp, ret, charcount, GetLastError());
|
||||
|
||||
charcount = 0;
|
||||
for (i = 0; i < 256; i++)
|
||||
{
|
||||
if(!(mbcinfo->mbctype[i + 1] & _M1))
|
||||
{
|
||||
if(mbcinfo->mbctype[i] & (C1_UPPER|C1_LOWER))
|
||||
mbcinfo->mbcasemap[i] = bufA[charcount];
|
||||
charcount++;
|
||||
}
|
||||
}
|
||||
|
||||
if (newcp == 932) /* CP932 only - set _MP and _MS */
|
||||
{
|
||||
/* On Windows it's possible to calculate the _MP and _MS from CT_CTYPE1
|
||||
@ -315,12 +336,20 @@ int CDECL _setmbcp(int cp)
|
||||
}
|
||||
|
||||
mbcinfo->mbcodepage = newcp;
|
||||
if(mbcinfo == MSVCRT_locale->mbcinfo)
|
||||
if(MSVCRT_locale && mbcinfo == MSVCRT_locale->mbcinfo)
|
||||
memcpy(MSVCRT_mbctype, MSVCRT_locale->mbcinfo->mbctype, sizeof(MSVCRT_mbctype));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* _setmbcp (MSVCRT.@)
|
||||
*/
|
||||
int CDECL _setmbcp(int cp)
|
||||
{
|
||||
return _setmbcp_l(cp, NULL);
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* _getmbcp (MSVCRT.@)
|
||||
*/
|
||||
|
@ -888,6 +888,7 @@ MSVCRT_pthreadmbcinfo get_mbcinfo(void);
|
||||
void __cdecl MSVCRT__free_locale(MSVCRT__locale_t);
|
||||
void free_locinfo(MSVCRT_pthreadlocinfo);
|
||||
void free_mbcinfo(MSVCRT_pthreadmbcinfo);
|
||||
int _setmbcp_l(int, MSVCRT_pthreadmbcinfo);
|
||||
|
||||
#ifndef __WINE_MSVCRT_TEST
|
||||
int __cdecl MSVCRT__write(int,const void*,unsigned int);
|
||||
|
Loading…
x
Reference in New Issue
Block a user