added qse_tio_writembs() and qse_tio_readmbs()
This commit is contained in:
@ -1,11 +1,12 @@
|
||||
#include <qse/cmn/sio.h>
|
||||
#include <qse/cmn/fmt.h>
|
||||
#include <locale.h>
|
||||
|
||||
#define R(f) \
|
||||
do { \
|
||||
qse_sio_puts (qse_sio_out,QSE_T("== ")); \
|
||||
qse_sio_puts (qse_sio_out,QSE_T(#f)); \
|
||||
qse_sio_puts (qse_sio_out,QSE_T(" ==\n")); \
|
||||
qse_sio_putstr (qse_sio_out,QSE_T("== ")); \
|
||||
qse_sio_putstr (qse_sio_out,QSE_T(#f)); \
|
||||
qse_sio_putstr (qse_sio_out,QSE_T(" ==\n")); \
|
||||
if (f() == -1) return -1; \
|
||||
} while (0)
|
||||
|
||||
@ -13,33 +14,51 @@ static int test1 (void)
|
||||
{
|
||||
qse_sio_t* sio;
|
||||
int i;
|
||||
|
||||
const qse_wchar_t unistr[] =
|
||||
{
|
||||
/*L"\uB108 \uBB50\uAC00 \uC798\uB0AC\uC5B4?",*/
|
||||
0xB108,
|
||||
L' ',
|
||||
0xBB50,
|
||||
0xAC00,
|
||||
L' ',
|
||||
0xC798,
|
||||
0xB0AC,
|
||||
0xC5B4,
|
||||
L'?',
|
||||
L'\0'
|
||||
};
|
||||
|
||||
const qse_wchar_t* x[] =
|
||||
{
|
||||
L"\uB108 \uBB50\uAC00 \uC798\uB0AC\uC5B4?",
|
||||
L"",
|
||||
L"Fly to the universe, kick you ass",
|
||||
L"\uB108 \uBB50\uAC00 \uC798\uB0AC\uC5B4?",
|
||||
L"",
|
||||
L"Fly to the universe, kick you ass",
|
||||
L"Fly to the universe, kick you ass",
|
||||
L"\uB108 \uBB50\uAC00 \uC798\uB0AC\uC5B4?"
|
||||
L""
|
||||
};
|
||||
|
||||
x[0] = unistr;
|
||||
x[2] = unistr;
|
||||
x[5] = unistr;
|
||||
sio = qse_sio_open (QSE_NULL, 0, QSE_T("sio.txt"),
|
||||
QSE_SIO_WRITE | QSE_SIO_CREATE | QSE_SIO_TRUNCATE);
|
||||
|
||||
if (sio == QSE_NULL)
|
||||
{
|
||||
qse_sio_puts (qse_sio_err, QSE_T("cannot open file\n"));
|
||||
qse_sio_putstr (qse_sio_err, QSE_T("cannot open file\n"));
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
for (i = 0; i < QSE_COUNTOF(x); i++)
|
||||
{
|
||||
qse_sio_puts (qse_sio_out, QSE_T("written: ["));
|
||||
qse_sio_puts (qse_sio_out, x[i]);
|
||||
qse_sio_puts (qse_sio_out, QSE_T("]\n"));
|
||||
qse_sio_putstr (qse_sio_out, QSE_T("written: ["));
|
||||
qse_sio_putstr (qse_sio_out, x[i]);
|
||||
qse_sio_putstr (qse_sio_out, QSE_T("]\n"));
|
||||
|
||||
qse_sio_puts (sio, x[i]);
|
||||
qse_sio_putstr (sio, x[i]);
|
||||
qse_sio_putc (sio, QSE_T('\n'));
|
||||
}
|
||||
|
||||
@ -51,35 +70,79 @@ static int test1 (void)
|
||||
static int test2 (void)
|
||||
{
|
||||
qse_ssize_t n;
|
||||
qse_char_t buf[20];
|
||||
qse_wchar_t buf[20];
|
||||
qse_sio_t* in, * out;
|
||||
|
||||
qse_sio_puts (qse_sio_out, QSE_T("type something...\n"));
|
||||
in = qse_sio_openstd (QSE_NULL, 0, QSE_SIO_STDIN, QSE_SIO_READ | QSE_SIO_IGNOREMBWCERR);
|
||||
out = qse_sio_openstd (QSE_NULL, 0, QSE_SIO_STDOUT, QSE_SIO_WRITE | QSE_SIO_IGNOREMBWCERR);
|
||||
|
||||
qse_sio_putstr (out, QSE_T("Type something...\n"));
|
||||
while (1)
|
||||
{
|
||||
n = qse_sio_gets (qse_sio_in, buf, QSE_COUNTOF(buf));
|
||||
n = qse_sio_getwcs (in, buf, QSE_COUNTOF(buf));
|
||||
if (n == 0) break;
|
||||
if (n < 0)
|
||||
if (n <= -1)
|
||||
{
|
||||
qse_sio_puts (qse_sio_err, QSE_T("error ....\n"));
|
||||
qse_char_t buf[32];
|
||||
qse_fmtintmax (buf, QSE_COUNTOF(buf), qse_sio_geterrnum(in), 10, -1, QSE_T('\0'), QSE_NULL);
|
||||
qse_sio_putstr (out, QSE_T("error .... "));
|
||||
qse_sio_putstr (out, buf);
|
||||
qse_sio_putstr (out, QSE_T("\n"));
|
||||
break;
|
||||
}
|
||||
|
||||
qse_sio_puts (qse_sio_out, buf);
|
||||
qse_sio_putwcs (out, buf);
|
||||
}
|
||||
|
||||
qse_sio_close (out);
|
||||
qse_sio_close (in);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int test3 (void)
|
||||
{
|
||||
qse_ssize_t n;
|
||||
qse_mchar_t buf[20];
|
||||
qse_sio_t* in, * out;
|
||||
|
||||
in = qse_sio_openstd (QSE_NULL, 0, QSE_SIO_STDIN, QSE_SIO_READ | QSE_SIO_IGNOREMBWCERR);
|
||||
out = qse_sio_openstd (QSE_NULL, 0, QSE_SIO_STDOUT, QSE_SIO_WRITE | QSE_SIO_IGNOREMBWCERR);
|
||||
|
||||
qse_sio_putstr (out, QSE_T("Type something...\n"));
|
||||
while (1)
|
||||
{
|
||||
n = qse_sio_getmbs (in, buf, QSE_COUNTOF(buf));
|
||||
if (n == 0) break;
|
||||
if (n < 0)
|
||||
{
|
||||
qse_char_t buf[32];
|
||||
qse_fmtintmax (buf, QSE_COUNTOF(buf), qse_sio_geterrnum(in), 10, -1, QSE_T('\0'), QSE_NULL);
|
||||
qse_sio_putstr (out, QSE_T("error .... "));
|
||||
qse_sio_putstr (out, buf);
|
||||
qse_sio_putstr (out, QSE_T("\n"));
|
||||
break;
|
||||
}
|
||||
|
||||
qse_sio_putmbs (out, buf);
|
||||
}
|
||||
|
||||
qse_sio_close (out);
|
||||
qse_sio_close (in);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int main ()
|
||||
{
|
||||
setlocale (LC_ALL, "");
|
||||
|
||||
qse_sio_puts (qse_sio_out, QSE_T("--------------------------------------------------------------------------------\n"));
|
||||
qse_sio_puts (qse_sio_out, QSE_T("Set the environment LANG to a Unicode locale such as UTF-8 if you see the illegal XXXXX errors. If you see such errors in Unicode locales, this program might be buggy. It is normal to see such messages in non-Unicode locales as it uses Unicode data\n"));
|
||||
qse_sio_puts (qse_sio_out, QSE_T("--------------------------------------------------------------------------------\n"));
|
||||
qse_sio_putstr (qse_sio_out, QSE_T("--------------------------------------------------------------------------------\n"));
|
||||
qse_sio_putstr (qse_sio_out, QSE_T("Set the environment LANG to a Unicode locale such as UTF-8 if you see the illegal XXXXX errors. If you see such errors in Unicode locales, this program might be buggy. It is normal to see such messages in non-Unicode locales as it uses Unicode data\n"));
|
||||
qse_sio_putstr (qse_sio_out, QSE_T("--------------------------------------------------------------------------------\n"));
|
||||
|
||||
R (test1);
|
||||
R (test2);
|
||||
R (test3);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -60,14 +60,71 @@ static int test1 (void)
|
||||
|
||||
for (i = 0; i < QSE_COUNTOF(x); i++)
|
||||
{
|
||||
qse_sio_putws (sio, x[i]);
|
||||
qse_sio_putws (sio, QSE_WT("\n"));
|
||||
qse_sio_putwcs (sio, x[i]);
|
||||
qse_sio_putwc (sio, QSE_WT('\n'));
|
||||
}
|
||||
|
||||
qse_sio_close (sio);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int test2 (void)
|
||||
{
|
||||
const qse_mchar_t* x[] =
|
||||
{
|
||||
QSE_MT("\0\0\0"),
|
||||
QSE_MT("이거슨"),
|
||||
QSE_MT("뭐냐이거"),
|
||||
QSE_MT("過去一個月"),
|
||||
QSE_MT("是成功的建商"),
|
||||
QSE_MT("뛰어 올라봐. 멀리멀리 잘난척하기는"),
|
||||
QSE_MT("Fly to the universe")
|
||||
};
|
||||
int i;
|
||||
qse_sio_t* sio;
|
||||
|
||||
sio = qse_sio_openstd (QSE_NULL, 0, QSE_SIO_STDOUT, QSE_SIO_READ | QSE_SIO_IGNOREMBWCERR | QSE_SIO_NOAUTOFLUSH);
|
||||
if (sio == QSE_NULL) return -1;
|
||||
|
||||
for (i = 0; i < QSE_COUNTOF(x); i++)
|
||||
{
|
||||
qse_sio_putmbs (sio, x[i]);
|
||||
qse_sio_putmb (sio, QSE_MT('\n'));
|
||||
}
|
||||
|
||||
qse_sio_close (sio);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int test3 (void)
|
||||
{
|
||||
const qse_mchar_t* x[] =
|
||||
{
|
||||
QSE_MT("\0\0\0"),
|
||||
QSE_MT("이거슨"),
|
||||
QSE_MT("뭐냐이거"),
|
||||
QSE_MT("過去一個月"),
|
||||
QSE_MT("是成功的建商"),
|
||||
QSE_MT("뛰어 올라봐. 멀리멀리 잘난척하기는"),
|
||||
QSE_MT("Fly to the universe")
|
||||
};
|
||||
int i;
|
||||
qse_sio_t* sio;
|
||||
|
||||
sio = qse_sio_openstd (QSE_NULL, 0, QSE_SIO_STDOUT, QSE_SIO_READ | QSE_SIO_IGNOREMBWCERR | QSE_SIO_NOAUTOFLUSH);
|
||||
if (sio == QSE_NULL) return -1;
|
||||
|
||||
for (i = 0; i < QSE_COUNTOF(x); i++)
|
||||
{
|
||||
qse_sio_putmbsn (sio, x[i], qse_mbslen(x[i]));
|
||||
qse_sio_putmb (sio, QSE_MT('\n'));
|
||||
}
|
||||
|
||||
qse_sio_close (sio);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int main ()
|
||||
{
|
||||
#if defined(_WIN32)
|
||||
@ -89,6 +146,8 @@ int main ()
|
||||
qse_printf (QSE_T("--------------------------------------------------------------------------------\n"));
|
||||
|
||||
R (test1);
|
||||
R (test2);
|
||||
R (test3);
|
||||
|
||||
#if defined(_WIN32)
|
||||
SetConsoleOutputCP (old_cp);
|
||||
|
@ -54,9 +54,9 @@ static int test1 (void)
|
||||
(int)wlen, (int)mlen, (int)wlen1, (int)mlen1, buf2);
|
||||
qse_fflush (QSE_STDOUT);
|
||||
|
||||
qse_sio_putws (QSE_SIO_OUT, QSE_T("<<"));
|
||||
qse_sio_putws (QSE_SIO_OUT, buf2);
|
||||
qse_sio_putws (QSE_SIO_OUT, QSE_T(">>\n"));
|
||||
qse_sio_putwcs (QSE_SIO_OUT, QSE_T("<<"));
|
||||
qse_sio_putwcs (QSE_SIO_OUT, buf2);
|
||||
qse_sio_putwcs (QSE_SIO_OUT, QSE_T(">>\n"));
|
||||
qse_sio_flush (QSE_SIO_OUT);
|
||||
}
|
||||
|
||||
@ -76,9 +76,9 @@ static int test1 (void)
|
||||
(int)wlen, (int)mlen, (int)wlen, (int)wlen1, (int)mlen1, buf2);
|
||||
|
||||
qse_fflush (QSE_STDOUT);
|
||||
qse_sio_putws (QSE_SIO_OUT, QSE_T("<<"));
|
||||
qse_sio_putws (QSE_SIO_OUT, buf2);
|
||||
qse_sio_putws (QSE_SIO_OUT, QSE_T(">>\n"));
|
||||
qse_sio_putwcs (QSE_SIO_OUT, QSE_T("<<"));
|
||||
qse_sio_putwcs (QSE_SIO_OUT, buf2);
|
||||
qse_sio_putwcs (QSE_SIO_OUT, QSE_T(">>\n"));
|
||||
qse_sio_flush (QSE_SIO_OUT);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user