From c1f46c95ff690688e175f5efebe6a60348b3f4a7 Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Mon, 30 Apr 2012 10:03:55 +0000 Subject: [PATCH] fixed minor source glitches --- qse/include/qse/cmn/tio.h | 4 +- qse/lib/cmn/htb.c | 2 +- qse/lib/cmn/nwio.c | 2 + qse/lib/cmn/rbt.c | 2 +- qse/samples/cmn/sio01.c | 120 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 126 insertions(+), 4 deletions(-) create mode 100644 qse/samples/cmn/sio01.c diff --git a/qse/include/qse/cmn/tio.h b/qse/include/qse/cmn/tio.h index d24efef3..b6ff38ed 100644 --- a/qse/include/qse/cmn/tio.h +++ b/qse/include/qse/cmn/tio.h @@ -68,8 +68,8 @@ enum qse_tio_flag_t QSE_TIO_NOAUTOFLUSH = (1 << 1), /* for internal use only. */ - QSE_TIO_DYNINBUF = (1 << 30), - QSE_TIO_DYNOUTBUF = (1 << 31) + QSE_TIO_DYNINBUF = (1 << 29), + QSE_TIO_DYNOUTBUF = (1 << 30) }; enum qse_tio_misc_t diff --git a/qse/lib/cmn/htb.c b/qse/lib/cmn/htb.c index 65a8b120..a5365018 100644 --- a/qse/lib/cmn/htb.c +++ b/qse/lib/cmn/htb.c @@ -257,7 +257,7 @@ static mancbs_t mancbs[] = const mancbs_t* qse_gethtbmancbs (mancbs_kind_t kind) { return &mancbs[kind]; -}; +} htb_t* qse_htb_open ( mmgr_t* mmgr, size_t xtnsize, size_t capa, diff --git a/qse/lib/cmn/nwio.c b/qse/lib/cmn/nwio.c index 2b71df5f..783801f3 100644 --- a/qse/lib/cmn/nwio.c +++ b/qse/lib/cmn/nwio.c @@ -43,7 +43,9 @@ enum union sockaddr_t { struct sockaddr_in in4; +#if defined(AF_INET6) struct sockaddr_in6 in6; +#endif }; static qse_ssize_t socket_input ( diff --git a/qse/lib/cmn/rbt.c b/qse/lib/cmn/rbt.c index d2ba599a..241a62f0 100644 --- a/qse/lib/cmn/rbt.c +++ b/qse/lib/cmn/rbt.c @@ -195,7 +195,7 @@ static mancbs_t mancbs[] = const mancbs_t* qse_getrbtmancbs (mancbs_kind_t kind) { return &mancbs[kind]; -}; +} rbt_t* qse_rbt_open (mmgr_t* mmgr, size_t xtnsize, int kscale, int vscale) { diff --git a/qse/samples/cmn/sio01.c b/qse/samples/cmn/sio01.c new file mode 100644 index 00000000..c5b8f9d5 --- /dev/null +++ b/qse/samples/cmn/sio01.c @@ -0,0 +1,120 @@ +#include +#include +#include +#include +#include +#include + + +#include +#if defined(_WIN32) +# include +#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_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_close (out); + return 0; +} + +int main () +{ +#if defined(_WIN32) + char locale[100]; + UINT codepage = GetConsoleOutputCP(); + if (codepage == CP_UTF8) + { + /*SetConsoleOUtputCP (CP_UTF8);*/ + qse_setdflcmgr (qse_utf8cmgr); + } + else + { + sprintf (locale, ".%u", (unsigned int)codepage); + setlocale (LC_ALL, locale); + qse_setdflcmgr (qse_slmbcmgr); + } +#else + setlocale (LC_ALL, ""); + qse_setdflcmgr (qse_slmbcmgr); +#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; +}