/*---------------------------------------------------------------------------* Project: Revolution ENC sample demo File: japanese.c Copyright 2006 Nintendo. All rights reserved. These coded instructions, statements, and computer programs contain proprietary information of Nintendo of America Inc. and/or Nintendo Company Ltd., and are protected by Federal copyright law. They may not be disclosed to third parties or copied or duplicated in any form, in whole or in part, without the prior written consent of Nintendo. $Log: japanese.c,v $ Revision 1.3 2006/11/14 08:34:44 yoshioka_yasuhiro Deleted private area. Revision 1.2 2006/11/01 02:52:30 yoshioka_yasuhiro Removed test code. Revision 1.1 2006/10/27 12:20:37 yoshioka_yasuhiro Initial commit. $NoKeywords: $ *---------------------------------------------------------------------------*/ #include #include #include "validate.h" static const u8 sjis[] = { 0x82, 0xA0, 0x82, 0xA2, 0x82, 0xA4, 0x0D, 0x0A, 0x82, 0xA6, 0x82, 0xA8, 0xB1, 0xB2, 0xB3, 0x0D, 0x0A, 0xB4, 0xB5, 0x88, 0x9F, 0x88, 0xC9, 0x89, 0x46, 0x0D, 0x0A, 0x8D, 0x5D, 0x94, 0xF6, 0x61, 0x69, 0x75, 0x0D, 0x0A, 0x65, 0x6F, 0x00 }; static const u8 jis[] = { 0x1B, 0x24, 0x42, 0x24, 0x22, 0x24, 0x24, 0x24, 0x26, 0x1B, 0x28, 0x42, 0x0D, 0x0A, 0x1B, 0x24, 0x42, 0x24, 0x28, 0x24, 0x2A, 0x25, 0x22, 0x25, 0x24, 0x25, 0x26, 0x1B, 0x28, 0x42, 0x0D, 0x0A, 0x1B, 0x24, 0x42, 0x25, 0x28, 0x25, 0x2A, 0x30, 0x21, 0x30, 0x4B, 0x31, 0x27, 0x1B, 0x28, 0x42, 0x0D, 0x0A, 0x1B, 0x24, 0x42, 0x39, 0x3E, 0x48, 0x78, 0x1B, 0x28, 0x42, 0x61, 0x69, 0x75, 0x0D, 0x0A, 0x65, 0x6F, 0x00 }; static const u8 jis_kana[] = { 0x1B, 0x24, 0x42, 0x24, 0x22, 0x24, 0x24, 0x24, 0x26, 0x1B, 0x28, 0x42, 0x0D, 0x0A, 0x1B, 0x24, 0x42, 0x24, 0x28, 0x24, 0x2A, 0x1B, 0x28, 0x49, 0x31, 0x32, 0x33, 0x1B, 0x28, 0x42, 0x0D, 0x0A, 0x1B, 0x28, 0x49, 0x34, 0x35, 0x1B, 0x24, 0x42, 0x30, 0x21, 0x30, 0x4B, 0x31, 0x27, 0x1B, 0x28, 0x42, 0x0D, 0x0A, 0x1B, 0x24, 0x42, 0x39, 0x3E, 0x48, 0x78, 0x1B, 0x28, 0x42, 0x61, 0x69, 0x75, 0x0D, 0x0A, 0x65, 0x6F, 0x00 }; static const u16 uni[] = { 0x3042, 0x3044, 0x3046, 0x000D, 0x000A, 0x3048, 0x304A, 0xFF71, 0xFF72, 0xFF73, 0x000D, 0x000A, 0xFF74, 0xFF75, 0x4E9C, 0x4F0A, 0x5B87, 0x000D, 0x000A, 0x6C5F, 0x5C3E, 0x0061, 0x0069, 0x0075, 0x000D, 0x000A, 0x0065, 0x006F, 0x0000 }; int main() { BOOL test_clear = TRUE; OSReport("\n* SJIS str -> UNICODE str *\n"); test_clear = test_clear && ValidateFuncToUnicode(ENCConvertStringSjisToUnicode, uni, sjis, 8); OSReport("\n* UNICODE str -> SJIS str *\n"); test_clear = test_clear && ValidateFuncFromUnicode(ENCConvertStringUnicodeToSjis, sjis, uni, 8); OSReport("\n* JIS str -> SJIS str *\n"); test_clear = test_clear && ValidateFuncMultiByte(ENCConvertStringJisToSjis, sjis, jis_kana, 8); OSReport("\n* SJIS str -> JIS str *\n"); test_clear = test_clear && ValidateFuncMultiByte(ENCConvertStringSjisToJis, jis, sjis, 8); OSReport("\n* JIS str -> UNICODE str *\n"); test_clear = test_clear && ValidateFuncToUnicode(ENCConvertStringJisToUnicode, uni, jis_kana, 8); OSReport("\n* UNICODE str -> JIS str *\n"); test_clear = test_clear && ValidateFuncFromUnicode(ENCConvertStringUnicodeToJis, jis, uni, 8); /* character */ { u8 char8[8]; u16 char16; u8 mbs[8]; u16 wc; s32 srclen, dstlen; ENCResult err_code; *mbs = 0x94; *(mbs + 1) = 0x43; wc = 0x4EFB; /* SJIS char -> UNICODE char */ OSReport("\n* SJIS char -> UNICODE char *\n"); srclen = 2; dstlen = 1; err_code = ENCConvertStringSjisToUnicode(&char16, &dstlen, mbs, &srclen); if (char16 == wc) { OSReport("SUCCESS\n"); } else { OSReport("FAILURE\n"); test_clear = FALSE; } OSReport("%#x, %#x -> %#x\n", *mbs, *(mbs + 1), char16); /* UNICODE char -> SJIS char */ OSReport("\n* UNICODE char -> SJIS char *\n"); srclen = 1; err_code = ENCConvertStringUnicodeToSjis(NULL, &dstlen, &wc, &srclen); err_code = ENCConvertStringUnicodeToSjis(char8, &dstlen, &wc, &srclen); if (*char8 == *mbs && *(char8 + 1) == *(mbs + 1)) { OSReport("SUCCESS\n"); } else { OSReport("FAILURE\n"); test_clear = FALSE; } OSReport("%#x -> %#x, %#x\n", wc, *char8, *(char8 + 1)); /* SJIS char -> JIS char */ *mbs = 0x94; *(mbs + 1) = 0x43; OSReport("\n* SJIS char -> JIS char *\n"); srclen = 2; err_code = ENCConvertStringSjisToJis(NULL, &dstlen, mbs, &srclen); err_code = ENCConvertStringSjisToJis(char8, &dstlen, mbs, &srclen); if (*(char8 + 3) == 0x47 && *(char8 + 4) == 0x24) { OSReport("SUCCESS\n"); } else { OSReport("FAILURE\n"); test_clear = FALSE; } OSReport("%#x, %#x -> %#x, %#x\n", *mbs, *(mbs + 1), *(char8 + 3), *(char8 + 4)); /* JIS char -> SJIS char */ *mbs = 0x1B; *(mbs + 1) = 0x24; *(mbs + 2) = 0x42; *(mbs + 3) = 0x47; *(mbs + 4) = 0x24; *(mbs + 5) = 0x1B; *(mbs + 6) = 0x28; *(mbs + 7) = 0x42; OSReport("\n* JIS char -> SJIS char *\n"); srclen = 8; err_code = ENCConvertStringJisToSjis(NULL, &dstlen, mbs, &srclen); err_code = ENCConvertStringJisToSjis(char8, &dstlen, mbs, &srclen); if (*char8 == 0x94 && *(char8 + 1) == 0x43) { OSReport("SUCCESS\n"); } else { OSReport("FAILURE\n"); test_clear = FALSE; } OSReport("%#x, %#x -> %#x, %#x\n", *(mbs + 3), *(mbs + 4), *char8, *(char8 + 1)); } if (test_clear) OSReport("\nTOTAL SUCCESS\n"); else OSReport("\nTOTAL FAILURE\n"); return 0; }