qse/samples/si/sio01.c

123 lines
2.4 KiB
C
Raw Normal View History

2016-04-29 03:55:42 +00:00
#include <qse/si/sio.h>
2012-04-30 10:03:55 +00:00
#include <qse/cmn/mbwc.h>
#include <qse/cmn/mem.h>
#include <qse/cmn/mem.h>
#include <qse/cmn/fmt.h>
#include <locale.h>
#if defined(_WIN32)
# include <windows.h>
#endif
static qse_sio_t* g_out;
#define R(f) \
do { \
qse_sio_putstr (g_out,QSE_T("== ")); \
qse_sio_putstr (g_out,QSE_T(#f)); \
qse_sio_putstr (g_out,QSE_T(" ==\n")); \
qse_sio_flush (g_out); \
if (f() == -1) return -1; \
} while (0)
static int test1 (void)
{
const qse_wchar_t unistr[] =
{
0x00A2,
/*L"\uB108 \uBB50\uAC00 \uC798\uB0AC\uC5B4!",*/
0xB108,
L' ',
0xBB50,
0xAC00,
L' ',
0xC798,
0xB0AC,
0xC5B4,
L'!',
L'\n',
L'\0'
};
qse_sio_t* out;
out = qse_sio_openstd (
QSE_MMGR_GETDFL(), 0, QSE_SIO_STDOUT,
QSE_SIO_WRITE | QSE_SIO_IGNOREMBWCERR);
qse_sio_putwcs (out, unistr);
qse_sio_putwcsf (out, QSE_WT ("[%.*s] [%.*s]\n"), (int)qse_wcslen(unistr) - 1, unistr, (int)qse_wcslen(unistr) - 1, unistr);
2012-04-30 10:03:55 +00:00
qse_sio_close (out);
return 0;
}
static int test2 (void)
{
const qse_wchar_t unistr[] =
{
0x00A2,
/*L"\uB108 \uBB50\uAC00 \uC798\uB0AC\uC5B4!",*/
0xB108,
L' ',
0xBB50,
0xAC00,
L' ',
0xC798,
0xB0AC,
0xC5B4,
L'!',
L'\n',
L'\0'
};
qse_mchar_t mbsbuf[100];
qse_sio_t* out;
qse_size_t wlen, mlen;
out = qse_sio_openstd (
QSE_MMGR_GETDFL(), 0, QSE_SIO_STDOUT,
QSE_SIO_WRITE | QSE_SIO_IGNOREMBWCERR);
mlen = QSE_COUNTOF(mbsbuf);
qse_wcstombs (unistr, &wlen, mbsbuf, &mlen);
qse_sio_putmbs (out, mbsbuf);
qse_sio_putmbsf (out, QSE_MT ("[%.*s] [%.*s]\n"), (int)qse_mbslen(mbsbuf) - 1, mbsbuf, (int)qse_mbslen(mbsbuf) - 1, mbsbuf);
2012-04-30 10:03:55 +00:00
qse_sio_close (out);
return 0;
}
int main ()
{
#if defined(_WIN32)
2012-10-15 09:46:29 +00:00
char locale[100];
2012-04-30 10:03:55 +00:00
UINT codepage = GetConsoleOutputCP();
if (codepage == CP_UTF8)
{
/*SetConsoleOUtputCP (CP_UTF8);*/
2012-10-15 09:36:39 +00:00
qse_setdflcmgrbyid (QSE_CMGR_UTF8);
2012-04-30 10:03:55 +00:00
}
else
{
sprintf (locale, ".%u", (unsigned int)codepage);
setlocale (LC_ALL, locale);
/*qse_setdflcmgrbyid (QSE_CMGR_SLMB);*/
2012-04-30 10:03:55 +00:00
}
#else
setlocale (LC_ALL, "");
/*qse_setdflcmgrbyid (QSE_CMGR_SLMB);*/
2012-04-30 10:03:55 +00:00
#endif
g_out = qse_sio_openstd (QSE_MMGR_GETDFL(), 0, QSE_SIO_STDOUT, QSE_SIO_WRITE | QSE_SIO_IGNOREMBWCERR);
R (test1);
R (test2);
qse_sio_close (g_out);
return 0;
}