fixed a bug of not checking the return value of wcrtomb properly in qse_wcrtomb().
fixed a bug of passing a wrong buffer to qse_wcrtomb() in qse_wcsntombsn(). enhanced qse_tio_writembsn() and qse_tio_writewcsn()
This commit is contained in:
@ -6,7 +6,13 @@ AM_CPPFLAGS = \
|
||||
-I$(includedir)
|
||||
|
||||
|
||||
bin_PROGRAMS = xma fma pma chr str01 str02 str03 sll dll lda oht htb rbt fio01 fio02 pio sio time main main2 rex01 env path01 tre01 fmt01 fmt02 fs01
|
||||
bin_PROGRAMS = \
|
||||
xma fma pma chr \
|
||||
str01 str02 str03 \
|
||||
sll dll lda oht htb rbt fio01 fio02 pio \
|
||||
sio01 sio02 \
|
||||
time main main2 rex01 env path01 tre01 \
|
||||
fmt01 fmt02 fs01
|
||||
|
||||
LDFLAGS = -L../../lib/cmn
|
||||
LDADD = -lqsecmn
|
||||
@ -27,7 +33,8 @@ rbt_SOURCES = rbt.c
|
||||
fio01_SOURCES = fio01.c
|
||||
fio02_SOURCES = fio02.c
|
||||
pio_SOURCES = pio.c
|
||||
sio_SOURCES = sio.c
|
||||
sio01_SOURCES = sio01.c
|
||||
sio02_SOURCES = sio02.c
|
||||
time_SOURCES = time.c
|
||||
main_SOURCES = main.c
|
||||
main2_SOURCES = main2.c
|
||||
|
@ -38,9 +38,9 @@ bin_PROGRAMS = xma$(EXEEXT) fma$(EXEEXT) pma$(EXEEXT) chr$(EXEEXT) \
|
||||
str01$(EXEEXT) str02$(EXEEXT) str03$(EXEEXT) sll$(EXEEXT) \
|
||||
dll$(EXEEXT) lda$(EXEEXT) oht$(EXEEXT) htb$(EXEEXT) \
|
||||
rbt$(EXEEXT) fio01$(EXEEXT) fio02$(EXEEXT) pio$(EXEEXT) \
|
||||
sio$(EXEEXT) time$(EXEEXT) main$(EXEEXT) main2$(EXEEXT) \
|
||||
rex01$(EXEEXT) env$(EXEEXT) path01$(EXEEXT) tre01$(EXEEXT) \
|
||||
fmt01$(EXEEXT) fmt02$(EXEEXT) fs01$(EXEEXT)
|
||||
sio01$(EXEEXT) sio02$(EXEEXT) time$(EXEEXT) main$(EXEEXT) \
|
||||
main2$(EXEEXT) rex01$(EXEEXT) env$(EXEEXT) path01$(EXEEXT) \
|
||||
tre01$(EXEEXT) fmt01$(EXEEXT) fmt02$(EXEEXT) fs01$(EXEEXT)
|
||||
subdir = samples/cmn
|
||||
DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in
|
||||
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
|
||||
@ -133,10 +133,14 @@ am_rex01_OBJECTS = rex01.$(OBJEXT)
|
||||
rex01_OBJECTS = $(am_rex01_OBJECTS)
|
||||
rex01_LDADD = $(LDADD)
|
||||
rex01_DEPENDENCIES =
|
||||
am_sio_OBJECTS = sio.$(OBJEXT)
|
||||
sio_OBJECTS = $(am_sio_OBJECTS)
|
||||
sio_LDADD = $(LDADD)
|
||||
sio_DEPENDENCIES =
|
||||
am_sio01_OBJECTS = sio01.$(OBJEXT)
|
||||
sio01_OBJECTS = $(am_sio01_OBJECTS)
|
||||
sio01_LDADD = $(LDADD)
|
||||
sio01_DEPENDENCIES =
|
||||
am_sio02_OBJECTS = sio02.$(OBJEXT)
|
||||
sio02_OBJECTS = $(am_sio02_OBJECTS)
|
||||
sio02_LDADD = $(LDADD)
|
||||
sio02_DEPENDENCIES =
|
||||
am_sll_OBJECTS = sll.$(OBJEXT)
|
||||
sll_OBJECTS = $(am_sll_OBJECTS)
|
||||
sll_LDADD = $(LDADD)
|
||||
@ -183,17 +187,19 @@ SOURCES = $(chr_SOURCES) $(dll_SOURCES) $(env_SOURCES) \
|
||||
$(fmt01_SOURCES) $(fmt02_SOURCES) $(fs01_SOURCES) \
|
||||
$(htb_SOURCES) $(lda_SOURCES) $(main_SOURCES) $(main2_SOURCES) \
|
||||
$(oht_SOURCES) $(path01_SOURCES) $(pio_SOURCES) $(pma_SOURCES) \
|
||||
$(rbt_SOURCES) $(rex01_SOURCES) $(sio_SOURCES) $(sll_SOURCES) \
|
||||
$(str01_SOURCES) $(str02_SOURCES) $(str03_SOURCES) \
|
||||
$(time_SOURCES) $(tre01_SOURCES) $(xma_SOURCES)
|
||||
$(rbt_SOURCES) $(rex01_SOURCES) $(sio01_SOURCES) \
|
||||
$(sio02_SOURCES) $(sll_SOURCES) $(str01_SOURCES) \
|
||||
$(str02_SOURCES) $(str03_SOURCES) $(time_SOURCES) \
|
||||
$(tre01_SOURCES) $(xma_SOURCES)
|
||||
DIST_SOURCES = $(chr_SOURCES) $(dll_SOURCES) $(env_SOURCES) \
|
||||
$(fio01_SOURCES) $(fio02_SOURCES) $(fma_SOURCES) \
|
||||
$(fmt01_SOURCES) $(fmt02_SOURCES) $(fs01_SOURCES) \
|
||||
$(htb_SOURCES) $(lda_SOURCES) $(main_SOURCES) $(main2_SOURCES) \
|
||||
$(oht_SOURCES) $(path01_SOURCES) $(pio_SOURCES) $(pma_SOURCES) \
|
||||
$(rbt_SOURCES) $(rex01_SOURCES) $(sio_SOURCES) $(sll_SOURCES) \
|
||||
$(str01_SOURCES) $(str02_SOURCES) $(str03_SOURCES) \
|
||||
$(time_SOURCES) $(tre01_SOURCES) $(xma_SOURCES)
|
||||
$(rbt_SOURCES) $(rex01_SOURCES) $(sio01_SOURCES) \
|
||||
$(sio02_SOURCES) $(sll_SOURCES) $(str01_SOURCES) \
|
||||
$(str02_SOURCES) $(str03_SOURCES) $(time_SOURCES) \
|
||||
$(tre01_SOURCES) $(xma_SOURCES)
|
||||
ETAGS = etags
|
||||
CTAGS = ctags
|
||||
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
|
||||
@ -361,7 +367,8 @@ rbt_SOURCES = rbt.c
|
||||
fio01_SOURCES = fio01.c
|
||||
fio02_SOURCES = fio02.c
|
||||
pio_SOURCES = pio.c
|
||||
sio_SOURCES = sio.c
|
||||
sio01_SOURCES = sio01.c
|
||||
sio02_SOURCES = sio02.c
|
||||
time_SOURCES = time.c
|
||||
main_SOURCES = main.c
|
||||
main2_SOURCES = main2.c
|
||||
@ -506,9 +513,12 @@ rbt$(EXEEXT): $(rbt_OBJECTS) $(rbt_DEPENDENCIES)
|
||||
rex01$(EXEEXT): $(rex01_OBJECTS) $(rex01_DEPENDENCIES)
|
||||
@rm -f rex01$(EXEEXT)
|
||||
$(LINK) $(rex01_OBJECTS) $(rex01_LDADD) $(LIBS)
|
||||
sio$(EXEEXT): $(sio_OBJECTS) $(sio_DEPENDENCIES)
|
||||
@rm -f sio$(EXEEXT)
|
||||
$(LINK) $(sio_OBJECTS) $(sio_LDADD) $(LIBS)
|
||||
sio01$(EXEEXT): $(sio01_OBJECTS) $(sio01_DEPENDENCIES)
|
||||
@rm -f sio01$(EXEEXT)
|
||||
$(LINK) $(sio01_OBJECTS) $(sio01_LDADD) $(LIBS)
|
||||
sio02$(EXEEXT): $(sio02_OBJECTS) $(sio02_DEPENDENCIES)
|
||||
@rm -f sio02$(EXEEXT)
|
||||
$(LINK) $(sio02_OBJECTS) $(sio02_LDADD) $(LIBS)
|
||||
sll$(EXEEXT): $(sll_OBJECTS) $(sll_DEPENDENCIES)
|
||||
@rm -f sll$(EXEEXT)
|
||||
$(LINK) $(sll_OBJECTS) $(sll_LDADD) $(LIBS)
|
||||
@ -556,7 +566,8 @@ distclean-compile:
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pma.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/rbt.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/rex01.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sio.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sio01.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sio02.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sll.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/str01.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/str02.Po@am__quote@
|
||||
|
@ -3,7 +3,6 @@
|
||||
#include <qse/cmn/str.h>
|
||||
#include <qse/cmn/stdio.h>
|
||||
|
||||
#include <string.h>
|
||||
#include <locale.h>
|
||||
|
||||
#define R(f) \
|
||||
|
@ -1,7 +1,6 @@
|
||||
#include <qse/cmn/fio.h>
|
||||
#include <qse/cmn/stdio.h>
|
||||
|
||||
#include <string.h>
|
||||
#include <locale.h>
|
||||
|
||||
#define R(f) \
|
||||
|
@ -1,6 +1,5 @@
|
||||
#include <qse/cmn/fio.h>
|
||||
#include <qse/cmn/stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#define R(f) \
|
||||
do { \
|
||||
@ -13,7 +12,6 @@ static int test1 (void)
|
||||
qse_fio_t* fio;
|
||||
qse_ssize_t n;
|
||||
char x[] = "fio test";
|
||||
char x2[] = "fio test2";
|
||||
qse_fio_off_t off;
|
||||
char buf[1000];
|
||||
int i;
|
||||
|
@ -2,7 +2,6 @@
|
||||
#include <qse/cmn/env.h>
|
||||
#include <qse/cmn/stdio.h>
|
||||
|
||||
#include <string.h>
|
||||
#include <locale.h>
|
||||
|
||||
#if defined(_WIN32)
|
||||
|
@ -1,5 +1,4 @@
|
||||
#include <qse/cmn/sio.h>
|
||||
#include <string.h>
|
||||
#include <locale.h>
|
||||
|
||||
#define R(f) \
|
97
qse/samples/cmn/sio02.c
Normal file
97
qse/samples/cmn/sio02.c
Normal file
@ -0,0 +1,97 @@
|
||||
#include <qse/cmn/stdio.h>
|
||||
#include <qse/cmn/sio.h>
|
||||
|
||||
#include <locale.h>
|
||||
|
||||
#if defined(_WIN32)
|
||||
# include <windows.h>
|
||||
#endif
|
||||
|
||||
#define R(f) \
|
||||
do { \
|
||||
qse_printf (QSE_T("== %s ==\n"), QSE_T(#f)); \
|
||||
if (f() == -1) return -1; \
|
||||
} while (0)
|
||||
|
||||
static int test1 (void)
|
||||
{
|
||||
const qse_wchar_t unistr[] =
|
||||
{
|
||||
/* ugly hack for old compilers that don't support \u */
|
||||
/*L"\uB108 \uBB50\uAC00 \uC798\uB0AC\uC5B4?",*/
|
||||
0xB108,
|
||||
L' ',
|
||||
0xBB50,
|
||||
0xAC00,
|
||||
L' ',
|
||||
0xC798,
|
||||
0xB0AC,
|
||||
0xC5B4,
|
||||
L'?',
|
||||
L'\0'
|
||||
};
|
||||
|
||||
const qse_wchar_t unistr2[] =
|
||||
{
|
||||
/* this include an illegal unicode character.
|
||||
* a strict converter should return an error so a question mark
|
||||
* should be printed for such a character */
|
||||
0xFFFF53C0u,
|
||||
0xFFFF4912u,
|
||||
0xBA00u,
|
||||
0xFFFF1234u,
|
||||
L'\0'
|
||||
};
|
||||
const qse_wchar_t* x[] =
|
||||
{
|
||||
L"",
|
||||
L"",
|
||||
L"",
|
||||
L"Fly to the universe, kick your ass"
|
||||
};
|
||||
int i;
|
||||
qse_sio_t* sio;
|
||||
|
||||
x[1] = unistr;
|
||||
x[2] = unistr2;
|
||||
|
||||
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_putws (sio, x[i]);
|
||||
qse_sio_putws (sio, QSE_WT("\n"));
|
||||
}
|
||||
|
||||
qse_sio_close (sio);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main ()
|
||||
{
|
||||
#if defined(_WIN32)
|
||||
char codepage[100];
|
||||
UINT old_cp = GetConsoleOutputCP();
|
||||
SetConsoleOutputCP (CP_UTF8);
|
||||
|
||||
/* TODO: on windows this set locale only affects those mbcs fucntions in clib.
|
||||
* it doesn't support utf8 i guess find a working way. the following won't work
|
||||
sprintf (codepage, ".%d", GetACP());
|
||||
setlocale (LC_ALL, codepage);
|
||||
*/
|
||||
#else
|
||||
setlocale (LC_ALL, "");
|
||||
#endif
|
||||
|
||||
qse_printf (QSE_T("--------------------------------------------------------------------------------\n"));
|
||||
qse_printf (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_printf (QSE_T("--------------------------------------------------------------------------------\n"));
|
||||
|
||||
R (test1);
|
||||
|
||||
#if defined(_WIN32)
|
||||
SetConsoleOutputCP (old_cp);
|
||||
#endif
|
||||
return 0;
|
||||
}
|
@ -4,8 +4,6 @@
|
||||
#include <qse/cmn/sio.h>
|
||||
|
||||
#include <locale.h>
|
||||
#include <wchar.h>
|
||||
#include <string.h>
|
||||
|
||||
#if defined(_WIN32)
|
||||
# include <windows.h>
|
||||
@ -161,30 +159,6 @@ static int test4 ()
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int test10 (void)
|
||||
{
|
||||
qse_wchar_t* wa[] = { QSE_WT("hello"), QSE_WT(","), QSE_WT("world"), QSE_NULL };
|
||||
qse_mchar_t* ma[] = { QSE_MT("HELLO"), QSE_MT(","), QSE_MT("WORLD"), QSE_NULL };
|
||||
qse_wchar_t* w;
|
||||
qse_mchar_t* m;
|
||||
|
||||
m = qse_wcsatombsdup (wa, QSE_MMGR_GETDFL());
|
||||
if (m)
|
||||
{
|
||||
qse_printf (QSE_T("[%ms]\n"), m);
|
||||
QSE_MMGR_FREE (QSE_MMGR_GETDFL(), m);
|
||||
}
|
||||
|
||||
w = qse_mbsatowcsdup (ma, QSE_MMGR_GETDFL());
|
||||
if (w)
|
||||
{
|
||||
qse_printf (QSE_T("[%ws]\n"), w);
|
||||
QSE_MMGR_FREE (QSE_MMGR_GETDFL(), w);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int test11 (void)
|
||||
{
|
||||
qse_char_t buf[1000];
|
||||
@ -418,7 +392,6 @@ int main ()
|
||||
R (test2);
|
||||
R (test3);
|
||||
R (test4);
|
||||
R (test10);
|
||||
|
||||
R (test11);
|
||||
R (test12);
|
||||
|
@ -1,11 +1,9 @@
|
||||
#include <qse/cmn/mem.h>
|
||||
#include <qse/cmn/str.h>
|
||||
#include <qse/cmn/stdio.h>
|
||||
#include <qse/cmn/sio.h>
|
||||
#include <qse/cmn/stdio.h>
|
||||
|
||||
#include <locale.h>
|
||||
#include <wchar.h>
|
||||
#include <string.h>
|
||||
|
||||
#if defined(_WIN32)
|
||||
# include <windows.h>
|
||||
|
@ -1,11 +1,9 @@
|
||||
#include <qse/cmn/mem.h>
|
||||
#include <qse/cmn/str.h>
|
||||
#include <qse/cmn/stdio.h>
|
||||
#include <qse/cmn/sio.h>
|
||||
#include <qse/cmn/stdio.h>
|
||||
|
||||
#include <locale.h>
|
||||
#include <wchar.h>
|
||||
#include <string.h>
|
||||
|
||||
#if defined(_WIN32)
|
||||
# include <windows.h>
|
||||
|
Reference in New Issue
Block a user