-fix __lc_codepage confusion
 -fix implementations of _mbsjistojms and _mbsjmstojis

svn path=/trunk/; revision=57910
This commit is contained in:
Jérôme Gardou 2012-12-13 21:13:06 +00:00
parent bc5d860b9e
commit 301e93be58
6 changed files with 32 additions and 27 deletions

View file

@ -156,7 +156,7 @@
@ cdecl __isascii(long)
@ cdecl __iscsym(long)
@ cdecl __iscsymf(long)
@ extern __lc_codepage MSVCRT___lc_codepage
@ extern __lc_codepage
# @ stub __lc_collate # not in XP / 7
@ extern __lc_collate_cp MSVCRT___lc_collate_cp
@ extern __lc_handle MSVCRT___lc_handle

View file

@ -39,7 +39,6 @@
#define MAX_LOCALE_LENGTH 256
extern unsigned char _mbctype[257];
extern unsigned int MSVCRT___lc_codepage;
extern char MSVCRT_current_lc_all[MAX_LOCALE_LENGTH];
#if defined (_MSC_VER)

View file

@ -25,7 +25,7 @@
#include "windef.h"
#include "winbase.h"
extern int __lc_codepage;
extern unsigned int __lc_codepage;
extern int __lc_collate_cp;
extern int __mb_cur_max;
extern const unsigned short _ctype [257];

View file

@ -31,7 +31,7 @@
#error _pctype should not be defined
#endif
unsigned int MSVCRT___lc_codepage = 0;
unsigned int __lc_codepage = 0;
int MSVCRT___lc_collate_cp = 0;
LCID MSVCRT___lc_handle[LC_MAX - LC_MIN + 1] = { 0 };
int __mb_cur_max = 1;
@ -622,7 +622,7 @@ LCID* CDECL ___lc_handle_func(void)
*/
unsigned int CDECL ___lc_codepage_func(void)
{
return MSVCRT___lc_codepage;
return __lc_codepage;
}
/*********************************************************************
@ -1391,7 +1391,7 @@ char* CDECL setlocale(int category, const char* locale)
if(locinfo == MSVCRT_locale->locinfo) {
int i;
MSVCRT___lc_codepage = locinfo->lc_codepage;
__lc_codepage = locinfo->lc_codepage;
MSVCRT___lc_collate_cp = locinfo->lc_collate_cp;
__mb_cur_max = locinfo->mb_cur_max;
_pctype = locinfo->pctype;
@ -1488,7 +1488,7 @@ void __init_global_locale()
return;
global_locale = MSVCRT__create_locale(0, "C");
MSVCRT___lc_codepage = MSVCRT_locale->locinfo->lc_codepage;
__lc_codepage = MSVCRT_locale->locinfo->lc_codepage;
MSVCRT___lc_collate_cp = MSVCRT_locale->locinfo->lc_collate_cp;
__mb_cur_max = MSVCRT_locale->locinfo->mb_cur_max;
for(i=LC_MIN; i<=LC_MAX; i++)

View file

@ -33,7 +33,7 @@ unsigned int _mbcjistojms(unsigned int c)
{
/* Conversion takes place only when codepage is 932.
In all other cases, c is returned unchanged */
if(MSVCRT___lc_codepage == 932)
if(get_mbcinfo()->mbcodepage == 932)
{
if(HIBYTE(c) >= 0x21 && HIBYTE(c) <= 0x7e &&
LOBYTE(c) >= 0x21 && LOBYTE(c) <= 0x7e)
@ -43,7 +43,7 @@ unsigned int _mbcjistojms(unsigned int c)
else
c += 0x7d;
if(LOBYTE(c) > 0x7F)
if(LOBYTE(c) >= 0x7F)
c += 0x1;
c = (((HIBYTE(c) - 0x21)/2 + 0x81) << 8) | LOBYTE(c);

View file

@ -1,28 +1,34 @@
#include <precomp.h>
#include <mbstring.h>
#include <locale.h>
/*
* @implemented
*/
unsigned int _mbcjmstojis(unsigned int c)
unsigned int __cdecl _mbcjmstojis(unsigned int c)
{
int c1, c2;
/* Conversion takes place only when codepage is 932.
In all other cases, c is returned unchanged */
if(get_mbcinfo()->mbcodepage == 932)
{
if(_ismbclegal(c) && HIBYTE(c) < 0xf0)
{
if(HIBYTE(c) >= 0xe0)
c -= 0x4000;
c2 = (unsigned char)c;
c1 = c >> 8;
if (c1 < 0xf0 && _ismbblead(c1) && _ismbbtrail(c2)) {
if (c1 >= 0xe0)
c1 -= 0x40;
c1 -= 0x70;
c1 <<= 1;
if (c2 < 0x9f) {
c1 --;
c2 -= 0x1f;
if (c2 >= (0x80-0x1f))
c2 --;
} else {
c2 -= 0x7e;
c = (((HIBYTE(c) - 0x81)*2 + 0x21) << 8) | LOBYTE(c);
if(LOBYTE(c) > 0x7f)
c -= 0x1;
if(LOBYTE(c) > 0x9d)
c += 0x83;
else
c -= 0x1f;
}
return ((c1 << 8) | c2);
else
return 0; /* Codepage is 932, but c can't be converted */
}
return 0;
return c;
}