/*---------------------------------------------------------------------------* Project: Revolution ENC sample demo File: alternate.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: alternate.c,v $ Revision 1.2 2007/10/30 07:09:05 yoshioka_yasuhiro Added a debug print at the end of demo. Revision 1.1 2006/12/26 00:52:44 yoshioka_yasuhiro Initial commit. $NoKeywords: $ *---------------------------------------------------------------------------*/ #include #include #define BUF_LEN 32 static u8 buffer[32]; #define SRC_LEN 16 static const u16 wcs[] ={ 0x0065, 0x0075, 0x0072, 0x006f, 0x0020, 0x0073, 0x0069, 0x0067, 0x006e, 0x0020, 0x20AC, 0x0020, 0x0074, 0x0065, 0x0073, 0x0074, 0x0000}; int main() { u8* dstbuf = buffer; const u16* srcbuf = wcs; /* length of remaining buffers */ s32 dstbuflen = BUF_LEN; s32 srcbuflen = SRC_LEN; /* IN: length of remaining buffers OUT: length of buffers read by the function */ s32 dstlen = dstbuflen; s32 srclen = srcbuflen; ENCResult result = ENCConvertStringUnicodeToLatin1(dstbuf, &dstlen, srcbuf, &srclen); while (result != ENC_OK) { switch(result) { case ENC_ERR_NO_BUF_LEFT: OSHalt("no buffer left\n"); case ENC_ERR_NO_MAP_RULE: /* no map rule */ break; case ENC_ERR_INVALID_PARAM: OSHalt("invalid param\n"); case ENC_ERR_INVALID_FORMAT: /* invalid format */ break; default: OSHalt("unknown result code\n"); } /* seek */ dstbuf += dstlen; dstbuflen -= dstlen; srcbuf += srclen; srcbuflen -= srclen; if (dstbuflen > 0) /* some buffer left */ { /* replaced with one alternative character */ *dstbuf = '?'; ++dstbuf; --dstbuflen; } else { OSHalt("no buffer left\n"); } dstlen = dstbuflen; // skip one unconvertible character ++srcbuf; --srcbuflen; srclen = srcbuflen; result = ENCConvertStringUnicodeToLatin1(dstbuf, &dstlen, srcbuf, &srclen); } OSReport("%s\n", buffer); OSHalt("Finish"); return 0; }