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:
hyung-hwan 2011-12-13 15:48:00 +00:00
parent 283f388ae9
commit 7f0ad74286
23 changed files with 278 additions and 165 deletions

View File

@ -248,13 +248,13 @@ qse_ssize_t qse_tio_write (
qse_size_t size qse_size_t size
); );
qse_ssize_t qse_tio_writem ( qse_ssize_t qse_tio_writembsn (
qse_tio_t* tio, qse_tio_t* tio,
const qse_mchar_t* data, const qse_mchar_t* data,
qse_size_t size qse_size_t size
); );
qse_ssize_t qse_tio_writew ( qse_ssize_t qse_tio_writewcsn (
qse_tio_t* tio, qse_tio_t* tio,
const qse_wchar_t* data, const qse_wchar_t* data,
qse_size_t size qse_size_t size

View File

@ -6057,7 +6057,7 @@ static int deparse (qse_awk_t* awk)
QSE_ASSERT (awk->tree.ngbls > 0); QSE_ASSERT (awk->tree.ngbls > 0);
qse_awk_getkwname (awk, QSE_AWK_KWID_GLOBAL, &kw); qse_awk_getkwname (awk, QSE_AWK_KWID_GLOBAL, &kw);
if (qse_awk_putsrcstrx(awk,kw.ptr,kw.len) <= -1) if (qse_awk_putsrcstrn(awk,kw.ptr,kw.len) <= -1)
{ {
EXIT_DEPARSE (); EXIT_DEPARSE ();
} }
@ -6073,7 +6073,7 @@ static int deparse (qse_awk_t* awk)
{ {
/* use the actual name if no named variable /* use the actual name if no named variable
* is allowed */ * is allowed */
if (qse_awk_putsrcstrx (awk, if (qse_awk_putsrcstrn (awk,
QSE_LDA_DPTR(awk->parse.gbls,i), QSE_LDA_DPTR(awk->parse.gbls,i),
QSE_LDA_DLEN(awk->parse.gbls,i)) <= -1) QSE_LDA_DLEN(awk->parse.gbls,i)) <= -1)
{ {
@ -6086,7 +6086,7 @@ static int deparse (qse_awk_t* awk)
awk, (qse_long_t)i, awk, (qse_long_t)i,
10, QSE_T("__g"), tmp, QSE_COUNTOF(tmp)); 10, QSE_T("__g"), tmp, QSE_COUNTOF(tmp));
QSE_ASSERT (len != (qse_size_t)-1); QSE_ASSERT (len != (qse_size_t)-1);
if (qse_awk_putsrcstrx (awk, tmp, len) <= -1) if (qse_awk_putsrcstrn (awk, tmp, len) <= -1)
{ {
EXIT_DEPARSE (); EXIT_DEPARSE ();
} }
@ -6099,7 +6099,7 @@ static int deparse (qse_awk_t* awk)
if ((awk->option & QSE_AWK_EXPLICIT) && if ((awk->option & QSE_AWK_EXPLICIT) &&
!(awk->option & QSE_AWK_IMPLICIT)) !(awk->option & QSE_AWK_IMPLICIT))
{ {
if (qse_awk_putsrcstrx (awk, if (qse_awk_putsrcstrn (awk,
QSE_LDA_DPTR(awk->parse.gbls,i), QSE_LDA_DPTR(awk->parse.gbls,i),
QSE_LDA_DLEN(awk->parse.gbls,i)) <= -1) QSE_LDA_DLEN(awk->parse.gbls,i)) <= -1)
{ {
@ -6112,7 +6112,7 @@ static int deparse (qse_awk_t* awk)
awk, (qse_long_t)i, awk, (qse_long_t)i,
10, QSE_T("__g"), tmp, QSE_COUNTOF(tmp)); 10, QSE_T("__g"), tmp, QSE_COUNTOF(tmp));
QSE_ASSERT (len != (qse_size_t)-1); QSE_ASSERT (len != (qse_size_t)-1);
if (qse_awk_putsrcstrx (awk, tmp, len) <= -1) if (qse_awk_putsrcstrn (awk, tmp, len) <= -1)
{ {
EXIT_DEPARSE (); EXIT_DEPARSE ();
} }
@ -6151,7 +6151,7 @@ static int deparse (qse_awk_t* awk)
qse_awk_getkwname (awk, QSE_AWK_KWID_BEGIN, &kw); qse_awk_getkwname (awk, QSE_AWK_KWID_BEGIN, &kw);
if (qse_awk_putsrcstrx (awk, kw.ptr, kw.len) <= -1) EXIT_DEPARSE (); if (qse_awk_putsrcstrn (awk, kw.ptr, kw.len) <= -1) EXIT_DEPARSE ();
if (qse_awk_putsrcstr (awk, QSE_T(" ")) <= -1) EXIT_DEPARSE (); if (qse_awk_putsrcstr (awk, QSE_T(" ")) <= -1) EXIT_DEPARSE ();
if (qse_awk_prnnde (awk, nde) <= -1) EXIT_DEPARSE (); if (qse_awk_prnnde (awk, nde) <= -1) EXIT_DEPARSE ();
@ -6213,7 +6213,7 @@ static int deparse (qse_awk_t* awk)
qse_awk_getkwname (awk, QSE_AWK_KWID_END, &kw); qse_awk_getkwname (awk, QSE_AWK_KWID_END, &kw);
if (qse_awk_putsrcstrx (awk, kw.ptr, kw.len) <= -1) EXIT_DEPARSE (); if (qse_awk_putsrcstrn (awk, kw.ptr, kw.len) <= -1) EXIT_DEPARSE ();
if (qse_awk_putsrcstr (awk, QSE_T(" ")) <= -1) EXIT_DEPARSE (); if (qse_awk_putsrcstr (awk, QSE_T(" ")) <= -1) EXIT_DEPARSE ();
if (qse_awk_prnnde (awk, nde) <= -1) EXIT_DEPARSE (); if (qse_awk_prnnde (awk, nde) <= -1) EXIT_DEPARSE ();
@ -6266,7 +6266,7 @@ static qse_htb_walk_t deparse_func (
} }
#define PUT_SX(x,str,len) \ #define PUT_SX(x,str,len) \
if (qse_awk_putsrcstrx (x->awk, str, len) <= -1) { \ if (qse_awk_putsrcstrn (x->awk, str, len) <= -1) { \
x->ret = -1; return QSE_HTB_WALK_STOP; \ x->ret = -1; return QSE_HTB_WALK_STOP; \
} }
@ -6356,7 +6356,7 @@ int qse_awk_putsrcstr (qse_awk_t* awk, const qse_char_t* str)
return 0; return 0;
} }
int qse_awk_putsrcstrx ( int qse_awk_putsrcstrn (
qse_awk_t* awk, const qse_char_t* str, qse_size_t len) qse_awk_t* awk, const qse_char_t* str, qse_size_t len)
{ {
const qse_char_t* end = str + len; const qse_char_t* end = str + len;

View File

@ -61,7 +61,7 @@ int qse_awk_putsrcstr (
const qse_char_t* str const qse_char_t* str
); );
int qse_awk_putsrcstrx ( int qse_awk_putsrcstrn (
qse_awk_t* awk, qse_awk_t* awk,
const qse_char_t* str, const qse_char_t* str,
qse_size_t len qse_size_t len

View File

@ -113,8 +113,8 @@ static const qse_char_t* print_outop_str[] =
PUT_SRCSTR (awk, QSE_T("\n")); \ PUT_SRCSTR (awk, QSE_T("\n")); \
) )
#define PUT_SRCSTRX(awk,str,len) QSE_BLOCK (\ #define PUT_SRCSTRN(awk,str,len) QSE_BLOCK (\
if (qse_awk_putsrcstrx (awk, str, len) == -1) return -1; \ if (qse_awk_putsrcstrn (awk, str, len) == -1) return -1; \
) )
#define PRINT_TABS(awk,depth) QSE_BLOCK (\ #define PRINT_TABS(awk,depth) QSE_BLOCK (\
@ -263,7 +263,7 @@ static int print_expr (qse_awk_t* awk, qse_awk_nde_t* nde)
{ {
if (((qse_awk_nde_int_t*)nde)->str) if (((qse_awk_nde_int_t*)nde)->str)
{ {
PUT_SRCSTRX (awk, PUT_SRCSTRN (awk,
((qse_awk_nde_int_t*)nde)->str, ((qse_awk_nde_int_t*)nde)->str,
((qse_awk_nde_int_t*)nde)->len); ((qse_awk_nde_int_t*)nde)->len);
} }
@ -298,7 +298,7 @@ static int print_expr (qse_awk_t* awk, qse_awk_nde_t* nde)
{ {
if (((qse_awk_nde_flt_t*)nde)->str) if (((qse_awk_nde_flt_t*)nde)->str)
{ {
PUT_SRCSTRX (awk, PUT_SRCSTRN (awk,
((qse_awk_nde_flt_t*)nde)->str, ((qse_awk_nde_flt_t*)nde)->str,
((qse_awk_nde_flt_t*)nde)->len); ((qse_awk_nde_flt_t*)nde)->len);
} }
@ -358,7 +358,7 @@ static int print_expr (qse_awk_t* awk, qse_awk_nde_t* nde)
PUT_SRCSTR (awk, QSE_T("\\\\")); PUT_SRCSTR (awk, QSE_T("\\\\"));
break; break;
default: default:
PUT_SRCSTRX (awk, &ptr[i], 1); PUT_SRCSTRN (awk, &ptr[i], 1);
break; break;
} }
} }
@ -369,7 +369,7 @@ static int print_expr (qse_awk_t* awk, qse_awk_nde_t* nde)
case QSE_AWK_NDE_REX: case QSE_AWK_NDE_REX:
{ {
PUT_SRCSTR (awk, QSE_T("/")); PUT_SRCSTR (awk, QSE_T("/"));
PUT_SRCSTRX (awk, PUT_SRCSTRN (awk,
((qse_awk_nde_rex_t*)nde)->ptr, ((qse_awk_nde_rex_t*)nde)->ptr,
((qse_awk_nde_rex_t*)nde)->len); ((qse_awk_nde_rex_t*)nde)->len);
PUT_SRCSTR (awk, QSE_T("/")); PUT_SRCSTR (awk, QSE_T("/"));
@ -390,7 +390,7 @@ static int print_expr (qse_awk_t* awk, qse_awk_nde_t* nde)
); );
PUT_SRCSTR (awk, QSE_T("__p")); PUT_SRCSTR (awk, QSE_T("__p"));
PUT_SRCSTRX (awk, tmp, n); PUT_SRCSTRN (awk, tmp, n);
QSE_ASSERT (px->idx == QSE_NULL); QSE_ASSERT (px->idx == QSE_NULL);
break; break;
@ -409,7 +409,7 @@ static int print_expr (qse_awk_t* awk, qse_awk_nde_t* nde)
px->id.idxa, 10, QSE_NULL, px->id.idxa, 10, QSE_NULL,
awk->tmp.fmt, QSE_COUNTOF(awk->tmp.fmt) awk->tmp.fmt, QSE_COUNTOF(awk->tmp.fmt)
); );
PUT_SRCSTRX (awk, awk->tmp.fmt, n); PUT_SRCSTRN (awk, awk->tmp.fmt, n);
PUT_SRCSTR (awk, QSE_T("[")); PUT_SRCSTR (awk, QSE_T("["));
PRINT_EXPR_LIST (awk, px->idx); PRINT_EXPR_LIST (awk, px->idx);
PUT_SRCSTR (awk, QSE_T("]")); PUT_SRCSTR (awk, QSE_T("]"));
@ -422,7 +422,7 @@ static int print_expr (qse_awk_t* awk, qse_awk_nde_t* nde)
QSE_ASSERT (px->id.idxa == (qse_size_t)-1); QSE_ASSERT (px->id.idxa == (qse_size_t)-1);
QSE_ASSERT (px->idx == QSE_NULL); QSE_ASSERT (px->idx == QSE_NULL);
PUT_SRCSTRX (awk, px->id.name.ptr, px->id.name.len); PUT_SRCSTRN (awk, px->id.name.ptr, px->id.name.len);
break; break;
} }
@ -432,7 +432,7 @@ static int print_expr (qse_awk_t* awk, qse_awk_nde_t* nde)
QSE_ASSERT (px->id.idxa == (qse_size_t)-1); QSE_ASSERT (px->id.idxa == (qse_size_t)-1);
QSE_ASSERT (px->idx != QSE_NULL); QSE_ASSERT (px->idx != QSE_NULL);
PUT_SRCSTRX (awk, px->id.name.ptr, px->id.name.len); PUT_SRCSTRN (awk, px->id.name.ptr, px->id.name.len);
PUT_SRCSTR (awk, QSE_T("[")); PUT_SRCSTR (awk, QSE_T("["));
PRINT_EXPR_LIST (awk, px->idx); PRINT_EXPR_LIST (awk, px->idx);
PUT_SRCSTR (awk, QSE_T("]")); PUT_SRCSTR (awk, QSE_T("]"));
@ -451,12 +451,12 @@ static int print_expr (qse_awk_t* awk, qse_awk_nde_t* nde)
{ {
/* no implicit(named) variable is allowed. /* no implicit(named) variable is allowed.
* use the actual name */ * use the actual name */
PUT_SRCSTRX (awk, px->id.name.ptr, px->id.name.len); PUT_SRCSTRN (awk, px->id.name.ptr, px->id.name.len);
} }
else if (px->id.idxa < awk->tree.ngbls_base) else if (px->id.idxa < awk->tree.ngbls_base)
{ {
/* static global variables */ /* static global variables */
PUT_SRCSTRX (awk, px->id.name.ptr, px->id.name.len); PUT_SRCSTRN (awk, px->id.name.ptr, px->id.name.len);
} }
else else
{ {
@ -471,12 +471,12 @@ static int print_expr (qse_awk_t* awk, qse_awk_nde_t* nde)
QSE_NULL, QSE_NULL,
tmp, QSE_COUNTOF(tmp) tmp, QSE_COUNTOF(tmp)
); );
PUT_SRCSTRX (awk, tmp, n); PUT_SRCSTRN (awk, tmp, n);
} }
} }
else else
{ {
PUT_SRCSTRX (awk, px->id.name.ptr, px->id.name.len); PUT_SRCSTRN (awk, px->id.name.ptr, px->id.name.len);
} }
QSE_ASSERT (px->idx == QSE_NULL); QSE_ASSERT (px->idx == QSE_NULL);
break; break;
@ -493,12 +493,12 @@ static int print_expr (qse_awk_t* awk, qse_awk_nde_t* nde)
{ {
/* no implicit(named) variable is allowed. /* no implicit(named) variable is allowed.
* use the actual name */ * use the actual name */
PUT_SRCSTRX (awk, px->id.name.ptr, px->id.name.len); PUT_SRCSTRN (awk, px->id.name.ptr, px->id.name.len);
} }
else if (px->id.idxa < awk->tree.ngbls_base) else if (px->id.idxa < awk->tree.ngbls_base)
{ {
/* static global variables */ /* static global variables */
PUT_SRCSTRX (awk, px->id.name.ptr, px->id.name.len); PUT_SRCSTRN (awk, px->id.name.ptr, px->id.name.len);
} }
else else
{ {
@ -513,13 +513,13 @@ static int print_expr (qse_awk_t* awk, qse_awk_nde_t* nde)
QSE_NULL, QSE_NULL,
tmp, QSE_COUNTOF(tmp) tmp, QSE_COUNTOF(tmp)
); );
PUT_SRCSTRX (awk, tmp, n); PUT_SRCSTRN (awk, tmp, n);
} }
PUT_SRCSTR (awk, QSE_T("[")); PUT_SRCSTR (awk, QSE_T("["));
} }
else else
{ {
PUT_SRCSTRX (awk, px->id.name.ptr, px->id.name.len); PUT_SRCSTRN (awk, px->id.name.ptr, px->id.name.len);
PUT_SRCSTR (awk, QSE_T("[")); PUT_SRCSTR (awk, QSE_T("["));
} }
QSE_ASSERT (px->idx != QSE_NULL); QSE_ASSERT (px->idx != QSE_NULL);
@ -544,11 +544,11 @@ static int print_expr (qse_awk_t* awk, qse_awk_nde_t* nde)
awk->tmp.fmt, awk->tmp.fmt,
QSE_COUNTOF(awk->tmp.fmt) QSE_COUNTOF(awk->tmp.fmt)
); );
PUT_SRCSTRX (awk, awk->tmp.fmt, n); PUT_SRCSTRN (awk, awk->tmp.fmt, n);
} }
else else
{ {
PUT_SRCSTRX (awk, px->id.name.ptr, px->id.name.len); PUT_SRCSTRN (awk, px->id.name.ptr, px->id.name.len);
} }
QSE_ASSERT (px->idx == QSE_NULL); QSE_ASSERT (px->idx == QSE_NULL);
break; break;
@ -570,12 +570,12 @@ static int print_expr (qse_awk_t* awk, qse_awk_nde_t* nde)
awk->tmp.fmt, awk->tmp.fmt,
QSE_COUNTOF(awk->tmp.fmt) QSE_COUNTOF(awk->tmp.fmt)
); );
PUT_SRCSTRX (awk, awk->tmp.fmt, n); PUT_SRCSTRN (awk, awk->tmp.fmt, n);
PUT_SRCSTR (awk, QSE_T("[")); PUT_SRCSTR (awk, QSE_T("["));
} }
else else
{ {
PUT_SRCSTRX (awk, px->id.name.ptr, px->id.name.len); PUT_SRCSTRN (awk, px->id.name.ptr, px->id.name.len);
PUT_SRCSTR (awk, QSE_T("[")); PUT_SRCSTR (awk, QSE_T("["));
} }
QSE_ASSERT (px->idx != QSE_NULL); QSE_ASSERT (px->idx != QSE_NULL);
@ -594,7 +594,7 @@ static int print_expr (qse_awk_t* awk, qse_awk_nde_t* nde)
case QSE_AWK_NDE_FNC: case QSE_AWK_NDE_FNC:
{ {
qse_awk_nde_fncall_t* px = (qse_awk_nde_fncall_t*)nde; qse_awk_nde_fncall_t* px = (qse_awk_nde_fncall_t*)nde;
PUT_SRCSTRX (awk, PUT_SRCSTRN (awk,
px->u.fnc.name.ptr, px->u.fnc.name.len); px->u.fnc.name.ptr, px->u.fnc.name.len);
PUT_SRCSTR (awk, QSE_T("(")); PUT_SRCSTR (awk, QSE_T("("));
PRINT_EXPR_LIST (awk, px->args); PRINT_EXPR_LIST (awk, px->args);
@ -605,7 +605,7 @@ static int print_expr (qse_awk_t* awk, qse_awk_nde_t* nde)
case QSE_AWK_NDE_FUN: case QSE_AWK_NDE_FUN:
{ {
qse_awk_nde_fncall_t* px = (qse_awk_nde_fncall_t*)nde; qse_awk_nde_fncall_t* px = (qse_awk_nde_fncall_t*)nde;
PUT_SRCSTRX (awk, PUT_SRCSTRN (awk,
px->u.fun.name.ptr, px->u.fun.name.len); px->u.fun.name.ptr, px->u.fun.name.len);
PUT_SRCSTR (awk, QSE_T("(")); PUT_SRCSTR (awk, QSE_T("("));
PRINT_EXPR_LIST (awk, px->args); PRINT_EXPR_LIST (awk, px->args);
@ -630,7 +630,7 @@ static int print_expr (qse_awk_t* awk, qse_awk_nde_t* nde)
} }
qse_awk_getkwname (awk, QSE_AWK_KWID_GETLINE, &kw); qse_awk_getkwname (awk, QSE_AWK_KWID_GETLINE, &kw);
PUT_SRCSTRX (awk, kw.ptr, kw.len); PUT_SRCSTRN (awk, kw.ptr, kw.len);
if (px->var != QSE_NULL) if (px->var != QSE_NULL)
{ {
PUT_SRCSTR (awk, QSE_T(" ")); PUT_SRCSTR (awk, QSE_T(" "));
@ -701,7 +701,7 @@ static int print_stmt (qse_awk_t* awk, qse_awk_nde_t* p, int depth)
{ {
PRINT_TABS (awk, depth + 1); PRINT_TABS (awk, depth + 1);
qse_awk_getkwname (awk, QSE_AWK_KWID_LOCAL, &kw); qse_awk_getkwname (awk, QSE_AWK_KWID_LOCAL, &kw);
PUT_SRCSTRX (awk, kw.ptr, kw.len); PUT_SRCSTRN (awk, kw.ptr, kw.len);
PUT_SRCSTR (awk, QSE_T(" ")); PUT_SRCSTR (awk, QSE_T(" "));
for (i = 0; i < px->nlcls - 1; i++) for (i = 0; i < px->nlcls - 1; i++)
@ -715,7 +715,7 @@ static int print_stmt (qse_awk_t* awk, qse_awk_nde_t* p, int depth)
awk->tmp.fmt, awk->tmp.fmt,
QSE_COUNTOF(awk->tmp.fmt) QSE_COUNTOF(awk->tmp.fmt)
); );
PUT_SRCSTRX (awk, awk->tmp.fmt, n); PUT_SRCSTRN (awk, awk->tmp.fmt, n);
PUT_SRCSTR (awk, QSE_T(", ")); PUT_SRCSTR (awk, QSE_T(", "));
} }
@ -728,7 +728,7 @@ static int print_stmt (qse_awk_t* awk, qse_awk_nde_t* p, int depth)
awk->tmp.fmt, awk->tmp.fmt,
QSE_COUNTOF(awk->tmp.fmt) QSE_COUNTOF(awk->tmp.fmt)
); );
PUT_SRCSTRX (awk, awk->tmp.fmt, n); PUT_SRCSTRN (awk, awk->tmp.fmt, n);
PUT_SRCSTR (awk, QSE_T(";")); PUT_SRCSTR (awk, QSE_T(";"));
PUT_NL (awk); PUT_NL (awk);
} }
@ -746,7 +746,7 @@ static int print_stmt (qse_awk_t* awk, qse_awk_nde_t* p, int depth)
PRINT_TABS (awk, depth); PRINT_TABS (awk, depth);
qse_awk_getkwname (awk, QSE_AWK_KWID_IF, &kw); qse_awk_getkwname (awk, QSE_AWK_KWID_IF, &kw);
PUT_SRCSTRX (awk, kw.ptr, kw.len); PUT_SRCSTRN (awk, kw.ptr, kw.len);
PUT_SRCSTR (awk, QSE_T(" (")); PUT_SRCSTR (awk, QSE_T(" ("));
PRINT_EXPR (awk, px->test); PRINT_EXPR (awk, px->test);
PUT_SRCSTR (awk, QSE_T(")")); PUT_SRCSTR (awk, QSE_T(")"));
@ -762,7 +762,7 @@ static int print_stmt (qse_awk_t* awk, qse_awk_nde_t* p, int depth)
{ {
PRINT_TABS (awk, depth); PRINT_TABS (awk, depth);
qse_awk_getkwname (awk, QSE_AWK_KWID_ELSE, &kw); qse_awk_getkwname (awk, QSE_AWK_KWID_ELSE, &kw);
PUT_SRCSTRX (awk, kw.ptr, kw.len); PUT_SRCSTRN (awk, kw.ptr, kw.len);
PUT_NL (awk); PUT_NL (awk);
if (px->else_part->type == QSE_AWK_NDE_BLK) if (px->else_part->type == QSE_AWK_NDE_BLK)
PRINT_STMTS (awk, px->else_part, depth); PRINT_STMTS (awk, px->else_part, depth);
@ -778,7 +778,7 @@ static int print_stmt (qse_awk_t* awk, qse_awk_nde_t* p, int depth)
PRINT_TABS (awk, depth); PRINT_TABS (awk, depth);
qse_awk_getkwname (awk, QSE_AWK_KWID_WHILE, &kw); qse_awk_getkwname (awk, QSE_AWK_KWID_WHILE, &kw);
PUT_SRCSTRX (awk, kw.ptr, kw.len); PUT_SRCSTRN (awk, kw.ptr, kw.len);
PUT_SRCSTR (awk, QSE_T(" (")); PUT_SRCSTR (awk, QSE_T(" ("));
PRINT_EXPR (awk, px->test); PRINT_EXPR (awk, px->test);
PUT_SRCSTR (awk, QSE_T(")")); PUT_SRCSTR (awk, QSE_T(")"));
@ -800,7 +800,7 @@ static int print_stmt (qse_awk_t* awk, qse_awk_nde_t* p, int depth)
PRINT_TABS (awk, depth); PRINT_TABS (awk, depth);
qse_awk_getkwname (awk, QSE_AWK_KWID_DO, &kw); qse_awk_getkwname (awk, QSE_AWK_KWID_DO, &kw);
PUT_SRCSTRX (awk, kw.ptr, kw.len); PUT_SRCSTRN (awk, kw.ptr, kw.len);
PUT_NL (awk); PUT_NL (awk);
if (px->body->type == QSE_AWK_NDE_BLK) if (px->body->type == QSE_AWK_NDE_BLK)
{ {
@ -813,7 +813,7 @@ static int print_stmt (qse_awk_t* awk, qse_awk_nde_t* p, int depth)
PRINT_TABS (awk, depth); PRINT_TABS (awk, depth);
qse_awk_getkwname (awk, QSE_AWK_KWID_WHILE, &kw); qse_awk_getkwname (awk, QSE_AWK_KWID_WHILE, &kw);
PUT_SRCSTRX (awk, kw.ptr, kw.len); PUT_SRCSTRN (awk, kw.ptr, kw.len);
PUT_SRCSTR (awk, QSE_T(" (")); PUT_SRCSTR (awk, QSE_T(" ("));
PRINT_EXPR (awk, px->test); PRINT_EXPR (awk, px->test);
PUT_SRCSTR (awk, QSE_T(");")); PUT_SRCSTR (awk, QSE_T(");"));
@ -827,7 +827,7 @@ static int print_stmt (qse_awk_t* awk, qse_awk_nde_t* p, int depth)
PRINT_TABS (awk, depth); PRINT_TABS (awk, depth);
qse_awk_getkwname (awk, QSE_AWK_KWID_FOR, &kw); qse_awk_getkwname (awk, QSE_AWK_KWID_FOR, &kw);
PUT_SRCSTRX (awk, kw.ptr, kw.len); PUT_SRCSTRN (awk, kw.ptr, kw.len);
PUT_SRCSTR (awk, QSE_T(" (")); PUT_SRCSTR (awk, QSE_T(" ("));
if (px->init != QSE_NULL) if (px->init != QSE_NULL)
{ {
@ -863,7 +863,7 @@ static int print_stmt (qse_awk_t* awk, qse_awk_nde_t* p, int depth)
PRINT_TABS (awk, depth); PRINT_TABS (awk, depth);
qse_awk_getkwname (awk, QSE_AWK_KWID_FOR, &kw); qse_awk_getkwname (awk, QSE_AWK_KWID_FOR, &kw);
PUT_SRCSTRX (awk, kw.ptr, kw.len); PUT_SRCSTRN (awk, kw.ptr, kw.len);
PUT_SRCSTR (awk, QSE_T(" ")); PUT_SRCSTR (awk, QSE_T(" "));
PRINT_EXPR (awk, px->test); PRINT_EXPR (awk, px->test);
PUT_NL (awk); PUT_NL (awk);
@ -882,7 +882,7 @@ static int print_stmt (qse_awk_t* awk, qse_awk_nde_t* p, int depth)
{ {
PRINT_TABS (awk, depth); PRINT_TABS (awk, depth);
qse_awk_getkwname (awk, QSE_AWK_KWID_BREAK, &kw); qse_awk_getkwname (awk, QSE_AWK_KWID_BREAK, &kw);
PUT_SRCSTRX (awk, kw.ptr, kw.len); PUT_SRCSTRN (awk, kw.ptr, kw.len);
PUT_SRCSTR (awk, QSE_T(";")); PUT_SRCSTR (awk, QSE_T(";"));
PUT_NL (awk); PUT_NL (awk);
break; break;
@ -892,7 +892,7 @@ static int print_stmt (qse_awk_t* awk, qse_awk_nde_t* p, int depth)
{ {
PRINT_TABS (awk, depth); PRINT_TABS (awk, depth);
qse_awk_getkwname (awk, QSE_AWK_KWID_CONTINUE, &kw); qse_awk_getkwname (awk, QSE_AWK_KWID_CONTINUE, &kw);
PUT_SRCSTRX (awk, kw.ptr, kw.len); PUT_SRCSTRN (awk, kw.ptr, kw.len);
PUT_SRCSTR (awk, QSE_T(";")); PUT_SRCSTR (awk, QSE_T(";"));
PUT_NL (awk); PUT_NL (awk);
break; break;
@ -904,14 +904,14 @@ static int print_stmt (qse_awk_t* awk, qse_awk_nde_t* p, int depth)
if (((qse_awk_nde_return_t*)p)->val == QSE_NULL) if (((qse_awk_nde_return_t*)p)->val == QSE_NULL)
{ {
qse_awk_getkwname (awk, QSE_AWK_KWID_RETURN, &kw); qse_awk_getkwname (awk, QSE_AWK_KWID_RETURN, &kw);
PUT_SRCSTRX (awk, kw.ptr, kw.len); PUT_SRCSTRN (awk, kw.ptr, kw.len);
PUT_SRCSTR (awk, QSE_T(";")); PUT_SRCSTR (awk, QSE_T(";"));
PUT_NL (awk); PUT_NL (awk);
} }
else else
{ {
qse_awk_getkwname (awk, QSE_AWK_KWID_RETURN, &kw); qse_awk_getkwname (awk, QSE_AWK_KWID_RETURN, &kw);
PUT_SRCSTRX (awk, kw.ptr, kw.len); PUT_SRCSTRN (awk, kw.ptr, kw.len);
PUT_SRCSTR (awk, QSE_T(" ")); PUT_SRCSTR (awk, QSE_T(" "));
QSE_ASSERT (((qse_awk_nde_return_t*)p)->val->next == QSE_NULL); QSE_ASSERT (((qse_awk_nde_return_t*)p)->val->next == QSE_NULL);
@ -930,14 +930,14 @@ static int print_stmt (qse_awk_t* awk, qse_awk_nde_t* p, int depth)
if (px->val == QSE_NULL) if (px->val == QSE_NULL)
{ {
qse_awk_getkwname (awk, QSE_AWK_KWID_EXIT, &kw); qse_awk_getkwname (awk, QSE_AWK_KWID_EXIT, &kw);
PUT_SRCSTRX (awk, kw.ptr, kw.len); PUT_SRCSTRN (awk, kw.ptr, kw.len);
PUT_SRCSTR (awk, QSE_T(";")); PUT_SRCSTR (awk, QSE_T(";"));
PUT_NL (awk); PUT_NL (awk);
} }
else else
{ {
qse_awk_getkwname (awk, QSE_AWK_KWID_EXIT, &kw); qse_awk_getkwname (awk, QSE_AWK_KWID_EXIT, &kw);
PUT_SRCSTRX (awk, kw.ptr, kw.len); PUT_SRCSTRN (awk, kw.ptr, kw.len);
PUT_SRCSTR (awk, QSE_T(" ")); PUT_SRCSTR (awk, QSE_T(" "));
QSE_ASSERT (px->val->next == QSE_NULL); QSE_ASSERT (px->val->next == QSE_NULL);
PRINT_EXPR (awk, px->val); PRINT_EXPR (awk, px->val);
@ -951,7 +951,7 @@ static int print_stmt (qse_awk_t* awk, qse_awk_nde_t* p, int depth)
{ {
PRINT_TABS (awk, depth); PRINT_TABS (awk, depth);
qse_awk_getkwname (awk, QSE_AWK_KWID_NEXT, &kw); qse_awk_getkwname (awk, QSE_AWK_KWID_NEXT, &kw);
PUT_SRCSTRX (awk, kw.ptr, kw.len); PUT_SRCSTRN (awk, kw.ptr, kw.len);
PUT_SRCSTR (awk, QSE_T(";")); PUT_SRCSTR (awk, QSE_T(";"));
PUT_NL (awk); PUT_NL (awk);
break; break;
@ -963,12 +963,12 @@ static int print_stmt (qse_awk_t* awk, qse_awk_nde_t* p, int depth)
if (((qse_awk_nde_nextfile_t*)p)->out) if (((qse_awk_nde_nextfile_t*)p)->out)
{ {
qse_awk_getkwname (awk, QSE_AWK_KWID_NEXTOFILE, &kw); qse_awk_getkwname (awk, QSE_AWK_KWID_NEXTOFILE, &kw);
PUT_SRCSTRX (awk, kw.ptr, kw.len); PUT_SRCSTRN (awk, kw.ptr, kw.len);
} }
else else
{ {
qse_awk_getkwname (awk, QSE_AWK_KWID_NEXTFILE, &kw); qse_awk_getkwname (awk, QSE_AWK_KWID_NEXTFILE, &kw);
PUT_SRCSTRX (awk, kw.ptr, kw.len); PUT_SRCSTRN (awk, kw.ptr, kw.len);
} }
PUT_SRCSTR (awk, QSE_T(";")); PUT_SRCSTR (awk, QSE_T(";"));
PUT_NL (awk); PUT_NL (awk);
@ -979,7 +979,7 @@ static int print_stmt (qse_awk_t* awk, qse_awk_nde_t* p, int depth)
{ {
PRINT_TABS (awk, depth); PRINT_TABS (awk, depth);
qse_awk_getkwname (awk, QSE_AWK_KWID_DELETE, &kw); qse_awk_getkwname (awk, QSE_AWK_KWID_DELETE, &kw);
PUT_SRCSTRX (awk, kw.ptr, kw.len); PUT_SRCSTRN (awk, kw.ptr, kw.len);
PUT_SRCSTR (awk, QSE_T(" ")); PUT_SRCSTR (awk, QSE_T(" "));
qse_awk_prnpt (awk, ((qse_awk_nde_delete_t*)p)->var); qse_awk_prnpt (awk, ((qse_awk_nde_delete_t*)p)->var);
break; break;
@ -989,7 +989,7 @@ static int print_stmt (qse_awk_t* awk, qse_awk_nde_t* p, int depth)
{ {
PRINT_TABS (awk, depth); PRINT_TABS (awk, depth);
qse_awk_getkwname (awk, QSE_AWK_KWID_RESET, &kw); qse_awk_getkwname (awk, QSE_AWK_KWID_RESET, &kw);
PUT_SRCSTRX (awk, kw.ptr, kw.len); PUT_SRCSTRN (awk, kw.ptr, kw.len);
PUT_SRCSTR (awk, QSE_T(" ")); PUT_SRCSTR (awk, QSE_T(" "));
qse_awk_prnpt (awk, ((qse_awk_nde_reset_t*)p)->var); qse_awk_prnpt (awk, ((qse_awk_nde_reset_t*)p)->var);
break; break;
@ -1005,12 +1005,12 @@ static int print_stmt (qse_awk_t* awk, qse_awk_nde_t* p, int depth)
if (p->type == QSE_AWK_NDE_PRINT) if (p->type == QSE_AWK_NDE_PRINT)
{ {
qse_awk_getkwname (awk, QSE_AWK_KWID_PRINT, &kw); qse_awk_getkwname (awk, QSE_AWK_KWID_PRINT, &kw);
PUT_SRCSTRX (awk, kw.ptr, kw.len); PUT_SRCSTRN (awk, kw.ptr, kw.len);
} }
else else
{ {
qse_awk_getkwname (awk, QSE_AWK_KWID_PRINTF, &kw); qse_awk_getkwname (awk, QSE_AWK_KWID_PRINTF, &kw);
PUT_SRCSTRX (awk, kw.ptr, kw.len); PUT_SRCSTRN (awk, kw.ptr, kw.len);
} }
if (px->args != QSE_NULL) if (px->args != QSE_NULL)

View File

@ -23,7 +23,6 @@
#ifndef NDEBUG #ifndef NDEBUG
#include <stdio.h>
#include <qse/cmn/sio.h> #include <qse/cmn/sio.h>
#include "mem.h" #include "mem.h"
@ -95,8 +94,12 @@ void qse_assert_failed (
qse_sio_t* sio, siobuf; qse_sio_t* sio, siobuf;
sio = &siobuf; sio = &siobuf;
if (qse_sio_initstd (sio, QSE_MMGR_GETDFL(), QSE_SIO_STDERR, QSE_SIO_NOAUTOFLUSH) <= -1) if (qse_sio_initstd (
sio, QSE_MMGR_GETDFL(), QSE_SIO_STDERR,
QSE_SIO_WRITE | QSE_SIO_IGNOREMBWCERR | QSE_SIO_NOAUTOFLUSH) <= -1)
{
sio = QSE_SIO_ERR; sio = QSE_SIO_ERR;
}
qse_sio_putms (sio, QSE_MT("=[ASSERTION FAILURE]============================================================\n")); qse_sio_putms (sio, QSE_MT("=[ASSERTION FAILURE]============================================================\n"));

View File

@ -59,8 +59,8 @@ qse_size_t qse_mbrlen (
#if 0 #if 0
n = mblen (mb, mbl); n = mblen (mb, mbl);
if (n == 0) return 1; /* a null character */
if (n == (size_t)-1) return 0; /* invalid or incomplete sequence */ if (n == (size_t)-1) return 0; /* invalid or incomplete sequence */
if (n == 0) return 1; /* a null character */
return (qse_size_t)n; return (qse_size_t)n;
#endif #endif
#else #else
@ -119,16 +119,20 @@ qse_size_t qse_wcrtomb (
qse_mchar_t buf[QSE_MBLEN_MAX]; qse_mchar_t buf[QSE_MBLEN_MAX];
n = wcrtomb (buf, wc, (mbstate_t*)state); n = wcrtomb (buf, wc, (mbstate_t*)state);
if (n > mbl) return mbl + 1; /* buffer to small */ /* it's important that n is checked againt (size_t)-1
* before againt mbl. n > mbl is true if n is (size_t)-1.
* if the check comes later, i won't have a chance to
* determine the case of an illegal character */
if (n == (size_t)-1) return 0; /* illegal character */ if (n == (size_t)-1) return 0; /* illegal character */
if (n > mbl) return mbl + 1; /* buffer to small */
QSE_MEMCPY (mb, buf, mbl); QSE_MEMCPY (mb, buf, mbl);
} }
else else
{ {
n = wcrtomb (mb, wc, (mbstate_t*)state); n = wcrtomb (mb, wc, (mbstate_t*)state);
if (n > mbl) return mbl + 1; /* buffer to small */
if (n == (size_t)-1) return 0; /* illegal character */ if (n == (size_t)-1) return 0; /* illegal character */
if (n > mbl) return mbl + 1; /* buffer to small */
} }
return n; /* number of bytes written to the buffer */ return n; /* number of bytes written to the buffer */

View File

@ -262,7 +262,7 @@ int qse_sio_initstd (
void qse_sio_fini (qse_sio_t* sio) void qse_sio_fini (qse_sio_t* sio)
{ {
/*if (qse_sio_flush (sio) == -1) return -1;*/ /*if (qse_sio_flush (sio) <= -1) return -1;*/
qse_sio_flush (sio); qse_sio_flush (sio);
qse_tio_fini (&sio->tio); qse_tio_fini (&sio->tio);
qse_fio_fini (&sio->fio); qse_fio_fini (&sio->fio);
@ -325,24 +325,24 @@ qse_ssize_t qse_sio_puts (qse_sio_t* sio, const qse_char_t* str)
qse_ssize_t qse_sio_putms (qse_sio_t* sio, const qse_mchar_t* str) qse_ssize_t qse_sio_putms (qse_sio_t* sio, const qse_mchar_t* str)
{ {
return qse_tio_writem (&sio->tio, str, qse_mbslen(str)); return qse_tio_writembsn (&sio->tio, str, qse_mbslen(str));
} }
qse_ssize_t qse_sio_putws (qse_sio_t* sio, const qse_wchar_t* str) qse_ssize_t qse_sio_putws (qse_sio_t* sio, const qse_wchar_t* str)
{ {
return qse_tio_writew (&sio->tio, str, qse_wcslen(str)); return qse_tio_writewcsn (&sio->tio, str, qse_wcslen(str));
} }
qse_ssize_t qse_sio_putmsn ( qse_ssize_t qse_sio_putmsn (
qse_sio_t* sio, const qse_mchar_t* str, qse_size_t size) qse_sio_t* sio, const qse_mchar_t* str, qse_size_t size)
{ {
return qse_tio_writem (&sio->tio, str, size); return qse_tio_writembsn (&sio->tio, str, size);
} }
qse_ssize_t qse_sio_putwsn ( qse_ssize_t qse_sio_putwsn (
qse_sio_t* sio, const qse_wchar_t* str, qse_size_t size) qse_sio_t* sio, const qse_wchar_t* str, qse_size_t size)
{ {
return qse_tio_writew (&sio->tio, str, size); return qse_tio_writewcsn (&sio->tio, str, size);
} }
int qse_sio_getpos (qse_sio_t* sio, qse_sio_pos_t* pos) int qse_sio_getpos (qse_sio_t* sio, qse_sio_pos_t* pos)

View File

@ -342,7 +342,7 @@ int qse_wcstombs (
if (rem > 0) *mbs = QSE_MT('\0'); if (rem > 0) *mbs = QSE_MT('\0');
else else
{ {
/* if ret is -2 and wcs[wcslen] == QSE_T('\0'), /* if ret is -2 and wcs[wcslen] == QSE_WT('\0'),
* this means that the mbs buffer was lacking one * this means that the mbs buffer was lacking one
* slot for the terminating null */ * slot for the terminating null */
ret = -2; /* buffer too small */ ret = -2; /* buffer too small */
@ -428,7 +428,7 @@ int qse_wcsntombsn (
{ {
qse_size_t n; qse_size_t n;
n = qse_wcrtomb (*p, mbs, QSE_COUNTOF(mbsbuf), &state); n = qse_wcrtomb (*p, mbsbuf, QSE_COUNTOF(mbsbuf), &state);
if (n == 0) if (n == 0)
{ {
ret = -1; ret = -1;

View File

@ -199,6 +199,7 @@ static int __mbsxnfnmat (
if (pl >= 9) if (pl >= 9)
{ {
/* TODO: binary search or something more efficient ? */
if (qse_mbszcmp(pp, QSE_MT("[:upper:]"), 9) == 0) if (qse_mbszcmp(pp, QSE_MT("[:upper:]"), 9) == 0)
{ {
matched = QSE_ISMUPPER(sc); matched = QSE_ISMUPPER(sc);

View File

@ -129,7 +129,7 @@ qse_ssize_t qse_tio_write (qse_tio_t* tio, const qse_char_t* str, qse_size_t siz
return p - str; return p - str;
} }
qse_ssize_t qse_tio_writem ( qse_ssize_t qse_tio_writembsn (
qse_tio_t* tio, const qse_mchar_t* mptr, qse_size_t mlen) qse_tio_t* tio, const qse_mchar_t* mptr, qse_size_t mlen)
{ {
const qse_mchar_t* xptr, * xend; const qse_mchar_t* xptr, * xend;
@ -155,7 +155,7 @@ qse_ssize_t qse_tio_writem (
{ {
for (xend = xptr + capa; xptr < xend; xptr++) for (xend = xptr + capa; xptr < xend; xptr++)
tio->outbuf[tio->outbuf_len++] = *xptr; tio->outbuf[tio->outbuf_len++] = *xptr;
if (qse_tio_flush (tio) == -1) return -1; if (qse_tio_flush (tio) <= -1) return -1;
mlen -= capa; mlen -= capa;
} }
@ -171,20 +171,27 @@ qse_ssize_t qse_tio_writem (
for (xend = xptr + mlen; xptr < xend; xptr++) for (xend = xptr + mlen; xptr < xend; xptr++)
{ {
/* TODO: support different line terminating characeter */ /* TODO: support different line terminating characeter */
if (*xptr == QSE_MT('\n')) nl = 1;
tio->outbuf[tio->outbuf_len++] = *xptr; tio->outbuf[tio->outbuf_len++] = *xptr;
if (*xptr == QSE_MT('\n'))
{
nl = 1;
break;
}
} }
for (; xptr < xend; xptr++)
tio->outbuf[tio->outbuf_len++] = *xptr;
} }
/* if the last part contains a new line, flush the internal /* if the last part contains a new line, flush the internal
* buffer. note that this flushes characters after nl also.*/ * buffer. note that this flushes characters after nl also.*/
if (nl && qse_tio_flush (tio) == -1) return -1; if (nl && qse_tio_flush (tio) <= -1) return -1;
/* returns the number multi-bytes characters handled */ /* returns the number multi-bytes characters handled */
return xptr - mptr; return xptr - mptr;
} }
qse_ssize_t qse_tio_writew ( qse_ssize_t qse_tio_writewcsn (
qse_tio_t* tio, const qse_wchar_t* wptr, qse_size_t wlen) qse_tio_t* tio, const qse_wchar_t* wptr, qse_size_t wlen)
{ {
qse_size_t capa, wcnt, mcnt, xwlen; qse_size_t capa, wcnt, mcnt, xwlen;
@ -198,49 +205,69 @@ qse_ssize_t qse_tio_writew (
capa = QSE_COUNTOF(tio->outbuf) - tio->outbuf_len; capa = QSE_COUNTOF(tio->outbuf) - tio->outbuf_len;
wcnt = xwlen; mcnt = capa; wcnt = xwlen; mcnt = capa;
n = qse_wcsntombsn (wptr, &wcnt, &tio->outbuf[tio->outbuf_len], &mcnt); n = qse_wcsntombsn (
wptr, &wcnt, &tio->outbuf[tio->outbuf_len], &mcnt);
tio->outbuf_len += mcnt; tio->outbuf_len += mcnt;
if (n == -2) if (n == -2)
{ {
/* the buffer is not large enough to /* the buffer is not large enough to
* convert more. so flush now and continue */ * convert more. so flush now and continue.
if (qse_tio_flush (tio) == -1) return -1; * note that the buffer may not be full though
* it not large enough in this case */
if (qse_tio_flush (tio) <= -1) return -1;
nl = 0; nl = 0;
} }
else if (n <= -1)
{
/* invalid wide-character is encountered. */
if (tio->flags & QSE_TIO_IGNOREMBWCERR)
{
/* though an error occurred, wcnt and mcnt
* are valid for the bytes and characters
* processed so far. so i can insert a question
* mark using mcnt as an index */
tio->outbuf[tio->outbuf_len + mcnt] = QSE_MT('?');
mcnt++; wcnt++;
}
else
{
tio->errnum = QSE_TIO_EILCHR;
return -1;
}
}
else else
{ {
if (!(tio->flags & QSE_TIO_NOAUTOFLUSH)) if (tio->outbuf_len >= QSE_COUNTOF(tio->outbuf))
{ {
qse_size_t i; /* flush the full buffer regardless of conversion
/* checking for a newline this way looks damn ugly. * result. */
* TODO: how can i do this more elegantly? */ if (qse_tio_flush (tio) <= -1) return -1;
for (i = 0; i < wcnt; i++) nl = 0;
if (wptr[i] == QSE_WT('\n')) nl = 1;
} }
if (n <= -1)
{
/* an invalid wide-character is encountered. */
if (tio->flags & QSE_TIO_IGNOREMBWCERR)
{
/* insert a question mark for an illegal
* character. */
QSE_ASSERT (tio->outbuf_len < QSE_COUNTOF(tio->outbuf));
tio->outbuf[tio->outbuf_len++] = QSE_MT('?');
wcnt++; /* skip this illegal character */
/* don't need to increment mcnt since
* it's not used below */
}
else
{
tio->errnum = QSE_TIO_EILCHR;
return -1;
}
}
else
{
if (!(tio->flags & QSE_TIO_NOAUTOFLUSH) && !nl)
{
qse_size_t i;
/* checking for a newline this way looks damn ugly.
* TODO: how can i do this more elegantly? */
for (i = 0; i < wcnt; i++)
{
if (wptr[i] == QSE_WT('\n'))
{
nl = 1;
break;
}
}
}
}
} }
wptr += wcnt; xwlen -= wcnt; wptr += wcnt; xwlen -= wcnt;
} }
if (nl && qse_tio_flush (tio) == -1) return -1; if (nl && qse_tio_flush (tio) <= -1) return -1;
return wlen; return wlen;
} }

View File

@ -33,7 +33,7 @@ qse_word_t qse_stx_hashstr (qse_stx_t* stx, const qse_char_t* str)
return h; return h;
} }
qse_word_t qse_stx_hashstrx ( qse_word_t qse_stx_hashstrn (
qse_stx_t* stx, const qse_char_t* str, qse_word_t len) qse_stx_t* stx, const qse_char_t* str, qse_word_t len)
{ {
return qse_stx_hashbytes (stx, str, len * QSE_SIZEOF(*str)); return qse_stx_hashbytes (stx, str, len * QSE_SIZEOF(*str));

View File

@ -20,7 +20,7 @@ qse_word_t qse_stx_hashstr (
const qse_char_t* str const qse_char_t* str
); );
qse_word_t qse_stx_hashstrx ( qse_word_t qse_stx_hashstrn (
qse_stx_t* stx, qse_stx_t* stx,
const qse_char_t* str, const qse_char_t* str,
qse_word_t len qse_word_t len

View File

@ -6,7 +6,13 @@ AM_CPPFLAGS = \
-I$(includedir) -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 LDFLAGS = -L../../lib/cmn
LDADD = -lqsecmn LDADD = -lqsecmn
@ -27,7 +33,8 @@ rbt_SOURCES = rbt.c
fio01_SOURCES = fio01.c fio01_SOURCES = fio01.c
fio02_SOURCES = fio02.c fio02_SOURCES = fio02.c
pio_SOURCES = pio.c pio_SOURCES = pio.c
sio_SOURCES = sio.c sio01_SOURCES = sio01.c
sio02_SOURCES = sio02.c
time_SOURCES = time.c time_SOURCES = time.c
main_SOURCES = main.c main_SOURCES = main.c
main2_SOURCES = main2.c main2_SOURCES = main2.c

View File

@ -38,9 +38,9 @@ bin_PROGRAMS = xma$(EXEEXT) fma$(EXEEXT) pma$(EXEEXT) chr$(EXEEXT) \
str01$(EXEEXT) str02$(EXEEXT) str03$(EXEEXT) sll$(EXEEXT) \ str01$(EXEEXT) str02$(EXEEXT) str03$(EXEEXT) sll$(EXEEXT) \
dll$(EXEEXT) lda$(EXEEXT) oht$(EXEEXT) htb$(EXEEXT) \ dll$(EXEEXT) lda$(EXEEXT) oht$(EXEEXT) htb$(EXEEXT) \
rbt$(EXEEXT) fio01$(EXEEXT) fio02$(EXEEXT) pio$(EXEEXT) \ rbt$(EXEEXT) fio01$(EXEEXT) fio02$(EXEEXT) pio$(EXEEXT) \
sio$(EXEEXT) time$(EXEEXT) main$(EXEEXT) main2$(EXEEXT) \ sio01$(EXEEXT) sio02$(EXEEXT) time$(EXEEXT) main$(EXEEXT) \
rex01$(EXEEXT) env$(EXEEXT) path01$(EXEEXT) tre01$(EXEEXT) \ main2$(EXEEXT) rex01$(EXEEXT) env$(EXEEXT) path01$(EXEEXT) \
fmt01$(EXEEXT) fmt02$(EXEEXT) fs01$(EXEEXT) tre01$(EXEEXT) fmt01$(EXEEXT) fmt02$(EXEEXT) fs01$(EXEEXT)
subdir = samples/cmn subdir = samples/cmn
DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
@ -133,10 +133,14 @@ am_rex01_OBJECTS = rex01.$(OBJEXT)
rex01_OBJECTS = $(am_rex01_OBJECTS) rex01_OBJECTS = $(am_rex01_OBJECTS)
rex01_LDADD = $(LDADD) rex01_LDADD = $(LDADD)
rex01_DEPENDENCIES = rex01_DEPENDENCIES =
am_sio_OBJECTS = sio.$(OBJEXT) am_sio01_OBJECTS = sio01.$(OBJEXT)
sio_OBJECTS = $(am_sio_OBJECTS) sio01_OBJECTS = $(am_sio01_OBJECTS)
sio_LDADD = $(LDADD) sio01_LDADD = $(LDADD)
sio_DEPENDENCIES = sio01_DEPENDENCIES =
am_sio02_OBJECTS = sio02.$(OBJEXT)
sio02_OBJECTS = $(am_sio02_OBJECTS)
sio02_LDADD = $(LDADD)
sio02_DEPENDENCIES =
am_sll_OBJECTS = sll.$(OBJEXT) am_sll_OBJECTS = sll.$(OBJEXT)
sll_OBJECTS = $(am_sll_OBJECTS) sll_OBJECTS = $(am_sll_OBJECTS)
sll_LDADD = $(LDADD) sll_LDADD = $(LDADD)
@ -183,17 +187,19 @@ SOURCES = $(chr_SOURCES) $(dll_SOURCES) $(env_SOURCES) \
$(fmt01_SOURCES) $(fmt02_SOURCES) $(fs01_SOURCES) \ $(fmt01_SOURCES) $(fmt02_SOURCES) $(fs01_SOURCES) \
$(htb_SOURCES) $(lda_SOURCES) $(main_SOURCES) $(main2_SOURCES) \ $(htb_SOURCES) $(lda_SOURCES) $(main_SOURCES) $(main2_SOURCES) \
$(oht_SOURCES) $(path01_SOURCES) $(pio_SOURCES) $(pma_SOURCES) \ $(oht_SOURCES) $(path01_SOURCES) $(pio_SOURCES) $(pma_SOURCES) \
$(rbt_SOURCES) $(rex01_SOURCES) $(sio_SOURCES) $(sll_SOURCES) \ $(rbt_SOURCES) $(rex01_SOURCES) $(sio01_SOURCES) \
$(str01_SOURCES) $(str02_SOURCES) $(str03_SOURCES) \ $(sio02_SOURCES) $(sll_SOURCES) $(str01_SOURCES) \
$(time_SOURCES) $(tre01_SOURCES) $(xma_SOURCES) $(str02_SOURCES) $(str03_SOURCES) $(time_SOURCES) \
$(tre01_SOURCES) $(xma_SOURCES)
DIST_SOURCES = $(chr_SOURCES) $(dll_SOURCES) $(env_SOURCES) \ DIST_SOURCES = $(chr_SOURCES) $(dll_SOURCES) $(env_SOURCES) \
$(fio01_SOURCES) $(fio02_SOURCES) $(fma_SOURCES) \ $(fio01_SOURCES) $(fio02_SOURCES) $(fma_SOURCES) \
$(fmt01_SOURCES) $(fmt02_SOURCES) $(fs01_SOURCES) \ $(fmt01_SOURCES) $(fmt02_SOURCES) $(fs01_SOURCES) \
$(htb_SOURCES) $(lda_SOURCES) $(main_SOURCES) $(main2_SOURCES) \ $(htb_SOURCES) $(lda_SOURCES) $(main_SOURCES) $(main2_SOURCES) \
$(oht_SOURCES) $(path01_SOURCES) $(pio_SOURCES) $(pma_SOURCES) \ $(oht_SOURCES) $(path01_SOURCES) $(pio_SOURCES) $(pma_SOURCES) \
$(rbt_SOURCES) $(rex01_SOURCES) $(sio_SOURCES) $(sll_SOURCES) \ $(rbt_SOURCES) $(rex01_SOURCES) $(sio01_SOURCES) \
$(str01_SOURCES) $(str02_SOURCES) $(str03_SOURCES) \ $(sio02_SOURCES) $(sll_SOURCES) $(str01_SOURCES) \
$(time_SOURCES) $(tre01_SOURCES) $(xma_SOURCES) $(str02_SOURCES) $(str03_SOURCES) $(time_SOURCES) \
$(tre01_SOURCES) $(xma_SOURCES)
ETAGS = etags ETAGS = etags
CTAGS = ctags CTAGS = ctags
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
@ -361,7 +367,8 @@ rbt_SOURCES = rbt.c
fio01_SOURCES = fio01.c fio01_SOURCES = fio01.c
fio02_SOURCES = fio02.c fio02_SOURCES = fio02.c
pio_SOURCES = pio.c pio_SOURCES = pio.c
sio_SOURCES = sio.c sio01_SOURCES = sio01.c
sio02_SOURCES = sio02.c
time_SOURCES = time.c time_SOURCES = time.c
main_SOURCES = main.c main_SOURCES = main.c
main2_SOURCES = main2.c main2_SOURCES = main2.c
@ -506,9 +513,12 @@ rbt$(EXEEXT): $(rbt_OBJECTS) $(rbt_DEPENDENCIES)
rex01$(EXEEXT): $(rex01_OBJECTS) $(rex01_DEPENDENCIES) rex01$(EXEEXT): $(rex01_OBJECTS) $(rex01_DEPENDENCIES)
@rm -f rex01$(EXEEXT) @rm -f rex01$(EXEEXT)
$(LINK) $(rex01_OBJECTS) $(rex01_LDADD) $(LIBS) $(LINK) $(rex01_OBJECTS) $(rex01_LDADD) $(LIBS)
sio$(EXEEXT): $(sio_OBJECTS) $(sio_DEPENDENCIES) sio01$(EXEEXT): $(sio01_OBJECTS) $(sio01_DEPENDENCIES)
@rm -f sio$(EXEEXT) @rm -f sio01$(EXEEXT)
$(LINK) $(sio_OBJECTS) $(sio_LDADD) $(LIBS) $(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) sll$(EXEEXT): $(sll_OBJECTS) $(sll_DEPENDENCIES)
@rm -f sll$(EXEEXT) @rm -f sll$(EXEEXT)
$(LINK) $(sll_OBJECTS) $(sll_LDADD) $(LIBS) $(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)/pma.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/rbt.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)/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)/sll.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/str01.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@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/str02.Po@am__quote@

View File

@ -3,7 +3,6 @@
#include <qse/cmn/str.h> #include <qse/cmn/str.h>
#include <qse/cmn/stdio.h> #include <qse/cmn/stdio.h>
#include <string.h>
#include <locale.h> #include <locale.h>
#define R(f) \ #define R(f) \

View File

@ -1,7 +1,6 @@
#include <qse/cmn/fio.h> #include <qse/cmn/fio.h>
#include <qse/cmn/stdio.h> #include <qse/cmn/stdio.h>
#include <string.h>
#include <locale.h> #include <locale.h>
#define R(f) \ #define R(f) \

View File

@ -1,6 +1,5 @@
#include <qse/cmn/fio.h> #include <qse/cmn/fio.h>
#include <qse/cmn/stdio.h> #include <qse/cmn/stdio.h>
#include <string.h>
#define R(f) \ #define R(f) \
do { \ do { \
@ -13,7 +12,6 @@ static int test1 (void)
qse_fio_t* fio; qse_fio_t* fio;
qse_ssize_t n; qse_ssize_t n;
char x[] = "fio test"; char x[] = "fio test";
char x2[] = "fio test2";
qse_fio_off_t off; qse_fio_off_t off;
char buf[1000]; char buf[1000];
int i; int i;

View File

@ -2,7 +2,6 @@
#include <qse/cmn/env.h> #include <qse/cmn/env.h>
#include <qse/cmn/stdio.h> #include <qse/cmn/stdio.h>
#include <string.h>
#include <locale.h> #include <locale.h>
#if defined(_WIN32) #if defined(_WIN32)

View File

@ -1,5 +1,4 @@
#include <qse/cmn/sio.h> #include <qse/cmn/sio.h>
#include <string.h>
#include <locale.h> #include <locale.h>
#define R(f) \ #define R(f) \

97
qse/samples/cmn/sio02.c Normal file
View 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;
}

View File

@ -4,8 +4,6 @@
#include <qse/cmn/sio.h> #include <qse/cmn/sio.h>
#include <locale.h> #include <locale.h>
#include <wchar.h>
#include <string.h>
#if defined(_WIN32) #if defined(_WIN32)
# include <windows.h> # include <windows.h>
@ -161,30 +159,6 @@ static int test4 ()
return 0; 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) static int test11 (void)
{ {
qse_char_t buf[1000]; qse_char_t buf[1000];
@ -418,7 +392,6 @@ int main ()
R (test2); R (test2);
R (test3); R (test3);
R (test4); R (test4);
R (test10);
R (test11); R (test11);
R (test12); R (test12);

View File

@ -1,11 +1,9 @@
#include <qse/cmn/mem.h> #include <qse/cmn/mem.h>
#include <qse/cmn/str.h> #include <qse/cmn/str.h>
#include <qse/cmn/stdio.h>
#include <qse/cmn/sio.h> #include <qse/cmn/sio.h>
#include <qse/cmn/stdio.h>
#include <locale.h> #include <locale.h>
#include <wchar.h>
#include <string.h>
#if defined(_WIN32) #if defined(_WIN32)
# include <windows.h> # include <windows.h>

View File

@ -1,11 +1,9 @@
#include <qse/cmn/mem.h> #include <qse/cmn/mem.h>
#include <qse/cmn/str.h> #include <qse/cmn/str.h>
#include <qse/cmn/stdio.h>
#include <qse/cmn/sio.h> #include <qse/cmn/sio.h>
#include <qse/cmn/stdio.h>
#include <locale.h> #include <locale.h>
#include <wchar.h>
#include <string.h>
#if defined(_WIN32) #if defined(_WIN32)
# include <windows.h> # include <windows.h>