From cece806823c91d4de43e71ffed5ec8cee0e71098 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Gardou?= Date: Sun, 9 Dec 2012 11:42:02 +0000 Subject: [PATCH] [CRT] - make some functions locale aware - add implementation of ___mb_cur_max_func and _isctype_l [MSVCRT20] - keep up with msvcrt [MSVCRT40] - ditto svn path=/trunk/; revision=57838 --- reactos/dll/win32/msvcrt/msvcrt.spec | 4 +- reactos/dll/win32/msvcrt20/msvcrt20.c | 12 ++--- reactos/dll/win32/msvcrt40/msvcrt40.c | 12 ++--- reactos/lib/sdk/crt/include/internal/locale.h | 2 +- reactos/lib/sdk/crt/mbstring/iskana.c | 2 +- reactos/lib/sdk/crt/mbstring/ismbkaln.c | 2 +- reactos/lib/sdk/crt/mbstring/ismblead.c | 4 +- reactos/lib/sdk/crt/mbstring/ismbpun.c | 2 +- reactos/lib/sdk/crt/mbstring/ismbtrl.c | 2 +- reactos/lib/sdk/crt/misc/environ.c | 10 +++- reactos/lib/sdk/crt/string/ctype.c | 46 ++++++++++++++++++- 11 files changed, 71 insertions(+), 27 deletions(-) diff --git a/reactos/dll/win32/msvcrt/msvcrt.spec b/reactos/dll/win32/msvcrt/msvcrt.spec index 2b7604b4552..b8451fadb4f 100644 --- a/reactos/dll/win32/msvcrt/msvcrt.spec +++ b/reactos/dll/win32/msvcrt/msvcrt.spec @@ -133,7 +133,7 @@ @ cdecl ___lc_codepage_func() # @ cdecl ___lc_collate_cp_func() @ cdecl ___lc_handle_func() -# @ cdecl ___mb_cur_max_func() MSVCRT___mb_cur_max_func +@ cdecl ___mb_cur_max_func() @ cdecl ___setlc_active_func() @ cdecl ___unguarded_readlc_active_add_func() @ extern __argc @@ -492,7 +492,7 @@ @ cdecl _isatty(long) # stub _iscntrl_l @ cdecl _isctype(long long) -# stub _isctype_l +@ cdecl _isctype_l(long long ptr) # stub _isdigit_l # stub _isgraph_l # stub _isleadbyte_l diff --git a/reactos/dll/win32/msvcrt20/msvcrt20.c b/reactos/dll/win32/msvcrt20/msvcrt20.c index 841a74c7c04..e06a3902b7b 100644 --- a/reactos/dll/win32/msvcrt20/msvcrt20.c +++ b/reactos/dll/win32/msvcrt20/msvcrt20.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include @@ -93,17 +94,11 @@ DllMain(PVOID hinstDll, ULONG dwReason, PVOID reserved) /* Initialization of the WINE code */ msvcrt_init_mt_locks(); - //if(!msvcrt_init_locale()) { - // msvcrt_free_mt_locks(); - // msvcrt_free_tls_mem(); - // return FALSE; - //} //msvcrt_init_math(); msvcrt_init_io(); //msvcrt_init_console(); //msvcrt_init_args(); //msvcrt_init_signals(); - _setmbcp(_MB_CP_LOCALE); TRACE("Attach done\n"); break; @@ -126,7 +121,8 @@ DllMain(PVOID hinstDll, ULONG dwReason, PVOID reserved) msvcrt_free_tls_mem(); if (!msvcrt_free_tls()) return FALSE; - //MSVCRT__free_locale(MSVCRT_locale); + if(global_locale) + MSVCRT__free_locale(global_locale); if (__winitenv && __winitenv != _wenviron) FreeEnvironment((char**)__winitenv); @@ -169,4 +165,4 @@ void CDECL MSVCRT20__wgetmainargs( int *argc, WCHAR** *wargv, WCHAR** *wenvp, __wgetmainargs( argc, wargv, wenvp, expand_wildcards, &new_mode ); } -/* EOF */ \ No newline at end of file +/* EOF */ diff --git a/reactos/dll/win32/msvcrt40/msvcrt40.c b/reactos/dll/win32/msvcrt40/msvcrt40.c index 61ae6ad4e01..aa2201f52f4 100644 --- a/reactos/dll/win32/msvcrt40/msvcrt40.c +++ b/reactos/dll/win32/msvcrt40/msvcrt40.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include @@ -88,17 +89,11 @@ DllMain(PVOID hinstDll, ULONG dwReason, PVOID reserved) /* Initialization of the WINE code */ msvcrt_init_mt_locks(); - //if(!msvcrt_init_locale()) { - // msvcrt_free_mt_locks(); - // msvcrt_free_tls_mem(); - // return FALSE; - //} //msvcrt_init_math(); msvcrt_init_io(); //msvcrt_init_console(); //msvcrt_init_args(); //msvcrt_init_signals(); - _setmbcp(_MB_CP_LOCALE); TRACE("Attach done\n"); break; @@ -121,7 +116,8 @@ DllMain(PVOID hinstDll, ULONG dwReason, PVOID reserved) msvcrt_free_tls_mem(); if (!msvcrt_free_tls()) return FALSE; - //MSVCRT__free_locale(MSVCRT_locale); + if(global_locale) + MSVCRT__free_locale(global_locale); if (__winitenv && __winitenv != _wenviron) FreeEnvironment((char**)__winitenv); @@ -140,4 +136,4 @@ DllMain(PVOID hinstDll, ULONG dwReason, PVOID reserved) return TRUE; } -/* EOF */ \ No newline at end of file +/* EOF */ diff --git a/reactos/lib/sdk/crt/include/internal/locale.h b/reactos/lib/sdk/crt/include/internal/locale.h index b879132fde7..107f08cfc32 100644 --- a/reactos/lib/sdk/crt/include/internal/locale.h +++ b/reactos/lib/sdk/crt/include/internal/locale.h @@ -33,7 +33,7 @@ typedef struct MSVCRT_threadmbcinfostruct { int ismbcodepage; int mblcid; unsigned short mbulinfo[6]; - char mbctype[257]; + unsigned char mbctype[257]; char mbcasemap[256]; } MSVCRT_threadmbcinfo; diff --git a/reactos/lib/sdk/crt/mbstring/iskana.c b/reactos/lib/sdk/crt/mbstring/iskana.c index bb969c8ca9d..5be9d3d40a3 100644 --- a/reactos/lib/sdk/crt/mbstring/iskana.c +++ b/reactos/lib/sdk/crt/mbstring/iskana.c @@ -17,5 +17,5 @@ */ int _ismbbkana(unsigned int c) { - return (_mbctype[c & 0xff] & _MBKANA); + return (get_mbcinfo()->mbctype[c & 0xff] & _MBKANA); } diff --git a/reactos/lib/sdk/crt/mbstring/ismbkaln.c b/reactos/lib/sdk/crt/mbstring/ismbkaln.c index 084eb22c23e..fdad1367d67 100644 --- a/reactos/lib/sdk/crt/mbstring/ismbkaln.c +++ b/reactos/lib/sdk/crt/mbstring/ismbkaln.c @@ -16,5 +16,5 @@ */ int _ismbbkalnum( unsigned int c ) { - return (_mbctype[c & 0xff] & _MKMOJI); + return (get_mbcinfo()->mbctype[c & 0xff] & _MKMOJI); } diff --git a/reactos/lib/sdk/crt/mbstring/ismblead.c b/reactos/lib/sdk/crt/mbstring/ismblead.c index 30511b840b2..10f14daca32 100644 --- a/reactos/lib/sdk/crt/mbstring/ismblead.c +++ b/reactos/lib/sdk/crt/mbstring/ismblead.c @@ -19,7 +19,7 @@ */ int _ismbblead(unsigned int c) { - return (_mbctype[(c&0xff) + 1] & _M1) != 0; + return (get_mbcinfo()->mbctype[(c&0xff) + 1] & _M1) != 0; } /* @@ -47,7 +47,7 @@ int _ismbslead( const unsigned char *start, const unsigned char *str) */ unsigned char *__p__mbctype(void) { - return _mbctype; + return get_mbcinfo()->mbctype; } diff --git a/reactos/lib/sdk/crt/mbstring/ismbpun.c b/reactos/lib/sdk/crt/mbstring/ismbpun.c index 571ded523a1..e756aa24312 100644 --- a/reactos/lib/sdk/crt/mbstring/ismbpun.c +++ b/reactos/lib/sdk/crt/mbstring/ismbpun.c @@ -18,7 +18,7 @@ int _ismbbpunct(unsigned int c) { // (0xA1 <= c <= 0xA6) - return (_mbctype[c & 0xff] & _MBPUNCT); + return (get_mbcinfo()->mbctype[c & 0xff] & _MBPUNCT); } //iskana() :(0xA1 <= c <= 0xDF) diff --git a/reactos/lib/sdk/crt/mbstring/ismbtrl.c b/reactos/lib/sdk/crt/mbstring/ismbtrl.c index 7b5b630bab9..fe56d057afb 100644 --- a/reactos/lib/sdk/crt/mbstring/ismbtrl.c +++ b/reactos/lib/sdk/crt/mbstring/ismbtrl.c @@ -22,7 +22,7 @@ size_t _mbclen2(const unsigned int s); */ int _ismbbtrail(unsigned int c) { - return (_mbctype[(c&0xff) + 1] & _M2) != 0; + return (get_mbcinfo()->mbctype[(c&0xff) + 1] & _M2) != 0; } diff --git a/reactos/lib/sdk/crt/misc/environ.c b/reactos/lib/sdk/crt/misc/environ.c index ef3dda6563b..343d8a3d412 100644 --- a/reactos/lib/sdk/crt/misc/environ.c +++ b/reactos/lib/sdk/crt/misc/environ.c @@ -426,7 +426,15 @@ errno_t _get_osplatform(unsigned int *pValue) */ int *__p___mb_cur_max(void) { - return &__mb_cur_max; + return &get_locinfo()->mb_cur_max; +} + +/********************************************************************* + * ___mb_cur_max_func(MSVCRT.@) + */ +int CDECL ___mb_cur_max_func(void) +{ + return get_locinfo()->mb_cur_max; } /* diff --git a/reactos/lib/sdk/crt/string/ctype.c b/reactos/lib/sdk/crt/string/ctype.c index 20dbb3cc044..1dbbee453ac 100644 --- a/reactos/lib/sdk/crt/string/ctype.c +++ b/reactos/lib/sdk/crt/string/ctype.c @@ -3,6 +3,10 @@ #define __MINGW_IMPORT #include +#ifndef _LIBCNT_ +#include +#endif + #undef _pctype #undef _pwctype @@ -567,10 +571,50 @@ const unsigned short* __cdecl __pwctype_func(void) return _pwctype; } -int _isctype (int c, int ctypeFlags) +#ifdef _LIBCNT_ +int __cdecl _isctype (int c, int ctypeFlags) { return (_pctype[(unsigned char)(c & 0xFF)] & ctypeFlags); } +#else +/********************************************************************* + * _isctype_l (MSVCRT.@) + */ +int __cdecl _isctype_l(int c, int type, _locale_t locale) +{ + MSVCRT_pthreadlocinfo locinfo; + + if(!locale) + locinfo = get_locinfo(); + else + locinfo = ((MSVCRT__locale_t)locale)->locinfo; + + if (c >= -1 && c <= 255) + return locinfo->pctype[c] & type; + + if (locinfo->mb_cur_max != 1 && c > 0) + { + /* FIXME: Is there a faster way to do this? */ + WORD typeInfo; + char convert[3], *pconv = convert; + + if (locinfo->pctype[(UINT)c >> 8] & _LEADBYTE) + *pconv++ = (UINT)c >> 8; + *pconv++ = c & 0xff; + *pconv = 0; + + if (GetStringTypeExA(locinfo->lc_handle[LC_CTYPE], + CT_CTYPE1, convert, convert[1] ? 2 : 1, &typeInfo)) + return typeInfo & type; + } + return 0; +} + +int __cdecl _isctype (int c, int ctypeFlags) +{ + return _isctype_l(c, ctypeFlags, NULL); +} +#endif /* _LIBCNT_ */ /* * @implemented