Piotr Caban : msvcrt: Don' t duplicate _setmbcp functionality inside _create_locale function.
Alexandre Julliard
julliard at winehq.org
Thu Oct 13 14:10:09 CDT 2011
Module: wine
Branch: master
Commit: fea69b230546cd8145c67e9f94b3e8f0fa2bea2f
URL: http://source.winehq.org/git/wine.git/?a=commit;h=fea69b230546cd8145c67e9f94b3e8f0fa2bea2f
Author: Piotr Caban <piotr at codeweavers.com>
Date: Thu Oct 13 12:24:59 2011 +0200
msvcrt: Don't duplicate _setmbcp functionality inside _create_locale function.
---
dlls/msvcrt/locale.c | 14 +-----------
dlls/msvcrt/mbcs.c | 57 +++++++++++++++++++++++++++++++++++++------------
dlls/msvcrt/msvcrt.h | 1 +
3 files changed, 45 insertions(+), 27 deletions(-)
diff --git a/dlls/msvcrt/locale.c b/dlls/msvcrt/locale.c
index 7e9cebe..0fbc0fe 100644
--- a/dlls/msvcrt/locale.c
+++ b/dlls/msvcrt/locale.c
@@ -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)) {
diff --git a/dlls/msvcrt/mbcs.c b/dlls/msvcrt/mbcs.c
index 96cea86..737f690 100644
--- a/dlls/msvcrt/mbcs.c
+++ b/dlls/msvcrt/mbcs.c
@@ -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,16 +290,37 @@ 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 */
{
@@ -315,13 +336,21 @@ 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.@)
*/
int CDECL _getmbcp(void)
diff --git a/dlls/msvcrt/msvcrt.h b/dlls/msvcrt/msvcrt.h
index 65e00a1..14bf972 100644
--- a/dlls/msvcrt/msvcrt.h
+++ b/dlls/msvcrt/msvcrt.h
@@ -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);
More information about the wine-cvs
mailing list