Module: wine Branch: master Commit: 2254a549a66f053c906a281057e4548a8e66313e URL: http://source.winehq.org/git/wine.git/?a=commit;h=2254a549a66f053c906a281057...
Author: David Hedberg david.hedberg@gmail.com Date: Sat Jan 24 00:37:57 2009 +0100
msvcrt: Implement _mbcjistojms.
---
dlls/msvcrt/mbcs.c | 36 ++++++++++++++++++++++++++++++++++++ dlls/msvcrt/msvcrt.spec | 2 +- dlls/msvcrt/tests/string.c | 23 +++++++++++++++++++++++ 3 files changed, 60 insertions(+), 1 deletions(-)
diff --git a/dlls/msvcrt/mbcs.c b/dlls/msvcrt/mbcs.c index d1a84e7..a6e0cca 100644 --- a/dlls/msvcrt/mbcs.c +++ b/dlls/msvcrt/mbcs.c @@ -318,6 +318,42 @@ unsigned int CDECL _mbctoupper(unsigned int c) }
/********************************************************************* + * _mbcjistojms(MSVCRT.@) + * + * Converts a jis character to sjis. + * Based on description from + * http://www.slayers.ne.jp/~oouchi/code/jistosjis.html + */ +unsigned int CDECL _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(HIBYTE(c) >= 0x21 && HIBYTE(c) <= 0x7e && + LOBYTE(c) >= 0x21 && LOBYTE(c) <= 0x7e) + { + if(HIBYTE(c) % 2) + c += 0x1f; + else + c += 0x7d; + + if(LOBYTE(c) > 0x7F) + c += 0x1; + + c = (((HIBYTE(c) - 0x21)/2 + 0x81) << 8) | LOBYTE(c); + + if(HIBYTE(c) > 0x9f) + c += 0x4000; + } + else + return 0; /* Codepage is 932, but c can't be converted */ + } + + return c; +} + +/********************************************************************* * _mbsdec(MSVCRT.@) */ unsigned char* CDECL _mbsdec(const unsigned char* start, const unsigned char* cur) diff --git a/dlls/msvcrt/msvcrt.spec b/dlls/msvcrt/msvcrt.spec index 32ef01c..1a9bc12 100644 --- a/dlls/msvcrt/msvcrt.spec +++ b/dlls/msvcrt/msvcrt.spec @@ -358,7 +358,7 @@ @ cdecl _mbbtype(long long) # extern _mbcasemap @ cdecl _mbccpy (str str) -@ stub _mbcjistojms #(long) +@ cdecl _mbcjistojms (long) @ stub _mbcjmstojis #(long) @ cdecl _mbclen(ptr) @ stub _mbctohira #(long) diff --git a/dlls/msvcrt/tests/string.c b/dlls/msvcrt/tests/string.c index 9134100..45c40d5 100644 --- a/dlls/msvcrt/tests/string.c +++ b/dlls/msvcrt/tests/string.c @@ -597,6 +597,28 @@ static void test_wcscpy_s(void) ok(szDestShort[0] == 0, "szDestShort[0] not 0\n"); }
+static void test_mbcjisjms(void) +{ + /* List of value-pairs to test. The test assumes the last pair to be {0, ..} */ + unsigned int jisjms[][2] = { {0x2020, 0}, {0x2021, 0}, {0x2120, 0}, {0x2121, 0x8140}, + {0x7f7f, 0}, {0x7f7e, 0}, {0x7e7f, 0}, {0x7e7e, 0xeffc}, + {0x2121FFFF, 0}, {0x2223, 0x81a1}, {0x237e, 0x829e}, {0, 0}}; + unsigned int ret, exp, i; + + i = 0; + do + { + ret = _mbcjistojms(jisjms[i][0]); + + if(_getmbcp() == 932) /* Japanese codepage? */ + exp = jisjms[i][1]; + else + exp = jisjms[i][0]; /* If not, no conversion */ + + ok(ret == exp, "Expected 0x%x, got 0x%x\n", exp, ret); + } while(jisjms[i++][0] != 0); +} + START_TEST(string) { char mem[100]; @@ -637,6 +659,7 @@ START_TEST(string) test_strcpy_s(); test_strcat_s(); test__mbsnbcpy_s(); + test_mbcjisjms();
test_wcscpy_s(); }