fixed the wrong qse_awk_rtx_valtostrdupwithcmgr macro.
simplied eval_getline() a bit
This commit is contained in:
parent
00d0dc786f
commit
69f97d969e
@ -2874,7 +2874,7 @@ QSE_EXPORT qse_wchar_t* qse_awk_rtx_valtowcsdup (
|
|||||||
#define qse_awk_rtx_valtowcsdup(rtx, val, len) qse_awk_rtx_valtowcsdupwithcmgr(rtx, val, len, qse_awk_rtx_getcmgr(rtx))
|
#define qse_awk_rtx_valtowcsdup(rtx, val, len) qse_awk_rtx_valtowcsdupwithcmgr(rtx, val, len, qse_awk_rtx_getcmgr(rtx))
|
||||||
|
|
||||||
#if defined(QSE_CHAR_IS_MCHAR)
|
#if defined(QSE_CHAR_IS_MCHAR)
|
||||||
# define qse_awk_rtx_valtostrdupwithcmgr(rtx, val, len, cmgr) qse_awk_rtx_valtombsdup(rtx, val, len, cmgr)
|
# define qse_awk_rtx_valtostrdupwithcmgr(rtx, val, len, cmgr) qse_awk_rtx_valtombsdupwithcmgr(rtx, val, len, cmgr)
|
||||||
# define qse_awk_rtx_valtostrdup(rtx, val, len) qse_awk_rtx_valtombsdup(rtx, val, len)
|
# define qse_awk_rtx_valtostrdup(rtx, val, len) qse_awk_rtx_valtombsdup(rtx, val, len)
|
||||||
#else
|
#else
|
||||||
# define qse_awk_rtx_valtostrdupwithcmgr(rtx, val, len, cmgr) qse_awk_rtx_valtowcsdupwithcmgr(rtx, val, len, cmgr)
|
# define qse_awk_rtx_valtostrdupwithcmgr(rtx, val, len, cmgr) qse_awk_rtx_valtowcsdupwithcmgr(rtx, val, len, cmgr)
|
||||||
|
@ -216,22 +216,22 @@ static int fnc_close (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi)
|
|||||||
qse_char_t* name, * opt = QSE_NULL;
|
qse_char_t* name, * opt = QSE_NULL;
|
||||||
qse_size_t len, optlen = 0;
|
qse_size_t len, optlen = 0;
|
||||||
|
|
||||||
nargs = qse_awk_rtx_getnargs (rtx);
|
nargs = qse_awk_rtx_getnargs(rtx);
|
||||||
QSE_ASSERT (nargs == 1 || nargs == 2);
|
QSE_ASSERT (nargs == 1 || nargs == 2);
|
||||||
|
|
||||||
a0 = qse_awk_rtx_getarg (rtx, 0);
|
a0 = qse_awk_rtx_getarg (rtx, 0);
|
||||||
if (nargs >= 2) a1 = qse_awk_rtx_getarg (rtx, 1);
|
if (nargs >= 2) a1 = qse_awk_rtx_getarg(rtx, 1);
|
||||||
QSE_ASSERT (a0 != QSE_NULL);
|
QSE_ASSERT (a0 != QSE_NULL);
|
||||||
|
|
||||||
name = qse_awk_rtx_getvalstr (rtx, a0, &len);
|
name = qse_awk_rtx_getvalstr(rtx, a0, &len);
|
||||||
if (name == QSE_NULL) return -1;
|
if (name == QSE_NULL) return -1;
|
||||||
|
|
||||||
if (a1)
|
if (a1)
|
||||||
{
|
{
|
||||||
opt = qse_awk_rtx_getvalstr (rtx, a1, &optlen);
|
opt = qse_awk_rtx_getvalstr(rtx, a1, &optlen);
|
||||||
if (opt == QSE_NULL)
|
if (opt == QSE_NULL)
|
||||||
{
|
{
|
||||||
qse_awk_rtx_freevalstr (rtx, a0, name);
|
qse_awk_rtx_freevalstr(rtx, a0, name);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -263,8 +263,7 @@ static int fnc_close (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi)
|
|||||||
|
|
||||||
if (opt)
|
if (opt)
|
||||||
{
|
{
|
||||||
if (optlen != 1 ||
|
if (optlen != 1 || (opt[0] != QSE_T('r') && opt[0] != QSE_T('w')))
|
||||||
(opt[0] != QSE_T('r') && opt[0] != QSE_T('w')))
|
|
||||||
{
|
{
|
||||||
n = -1;
|
n = -1;
|
||||||
goto skip_close;
|
goto skip_close;
|
||||||
@ -292,25 +291,24 @@ skip_close:
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int flush_io (
|
static int flush_io (qse_awk_rtx_t* rtx, int rio, const qse_char_t* name, int n)
|
||||||
qse_awk_rtx_t* run, int rio, const qse_char_t* name, int n)
|
|
||||||
{
|
{
|
||||||
int n2;
|
int n2;
|
||||||
|
|
||||||
if (run->rio.handler[rio] != QSE_NULL)
|
if (rtx->rio.handler[rio] != QSE_NULL)
|
||||||
{
|
{
|
||||||
n2 = qse_awk_rtx_flushio (run, rio, name);
|
n2 = qse_awk_rtx_flushio (rtx, rio, name);
|
||||||
if (n2 <= -1)
|
if (n2 <= -1)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
if (run->errinf.num == QSE_AWK_EIOIMPL) n = -1;
|
if (rtx->errinf.num == QSE_AWK_EIOIMPL) n = -1;
|
||||||
else if (run->errinf.num == QSE_AWK_EIONMNF)
|
else if (rtx->errinf.num == QSE_AWK_EIONMNF)
|
||||||
{
|
{
|
||||||
if (n != 0) n = -2;
|
if (n != 0) n = -2;
|
||||||
}
|
}
|
||||||
else n = -99;
|
else n = -99;
|
||||||
*/
|
*/
|
||||||
if (run->errinf.num == QSE_AWK_EIONMNF)
|
if (rtx->errinf.num == QSE_AWK_EIONMNF)
|
||||||
{
|
{
|
||||||
if (n != 0) n = -2;
|
if (n != 0) n = -2;
|
||||||
}
|
}
|
||||||
|
@ -6647,34 +6647,22 @@ static qse_awk_val_t* eval_getline (qse_awk_rtx_t* rtx, qse_awk_nde_t* nde)
|
|||||||
qse_size_t len;
|
qse_size_t len;
|
||||||
qse_awk_rtx_valtostr_out_t out;
|
qse_awk_rtx_valtostr_out_t out;
|
||||||
|
|
||||||
v = eval_expression (rtx, p->in);
|
v = eval_expression(rtx, p->in);
|
||||||
if (v == QSE_NULL) return QSE_NULL;
|
if (!v) return QSE_NULL;
|
||||||
|
|
||||||
qse_awk_rtx_refupval (rtx, v);
|
qse_awk_rtx_refupval (rtx, v);
|
||||||
vtype = QSE_AWK_RTX_GETVALTYPE (rtx, v);
|
dst = qse_awk_rtx_getvalstr(rtx, v, &len);
|
||||||
if (vtype == QSE_AWK_VAL_STR)
|
if (!dst)
|
||||||
{
|
{
|
||||||
dst = ((qse_awk_val_str_t*)v)->val.ptr;
|
|
||||||
len = ((qse_awk_val_str_t*)v)->val.len;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
out.type = QSE_AWK_RTX_VALTOSTR_CPLDUP;
|
|
||||||
x = qse_awk_rtx_valtostr (rtx, v, &out);
|
|
||||||
qse_awk_rtx_refdownval (rtx, v);
|
qse_awk_rtx_refdownval (rtx, v);
|
||||||
if (x <= -1) return QSE_NULL;
|
return QSE_NULL;
|
||||||
|
|
||||||
dst = out.u.cpldup.ptr;
|
|
||||||
len = out.u.cpldup.len;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (len <= 0)
|
if (len <= 0)
|
||||||
{
|
{
|
||||||
/* the input source name is empty.
|
|
||||||
* make getline return -1 */
|
qse_awk_rtx_freevalstr (rtx, v, dst);
|
||||||
if (vtype == QSE_AWK_VAL_STR)
|
|
||||||
qse_awk_rtx_refdownval (rtx, v);
|
qse_awk_rtx_refdownval (rtx, v);
|
||||||
else qse_awk_rtx_freemem (rtx, dst);
|
|
||||||
|
|
||||||
n = -1;
|
n = -1;
|
||||||
goto skip_read;
|
goto skip_read;
|
||||||
@ -6688,10 +6676,8 @@ static qse_awk_val_t* eval_getline (qse_awk_rtx_t* rtx, qse_awk_nde_t* nde)
|
|||||||
* character. make getline return -1.
|
* character. make getline return -1.
|
||||||
* unlike print & printf, it is not a hard
|
* unlike print & printf, it is not a hard
|
||||||
* error */
|
* error */
|
||||||
if (vtype == QSE_AWK_VAL_STR)
|
qse_awk_rtx_freevalstr (rtx, v, dst);
|
||||||
qse_awk_rtx_refdownval (rtx, v);
|
qse_awk_rtx_refdownval (rtx, v);
|
||||||
else qse_awk_rtx_freemem (rtx, dst);
|
|
||||||
|
|
||||||
n = -1;
|
n = -1;
|
||||||
goto skip_read;
|
goto skip_read;
|
||||||
}
|
}
|
||||||
@ -6707,9 +6693,8 @@ read_console_again:
|
|||||||
|
|
||||||
if (p->in)
|
if (p->in)
|
||||||
{
|
{
|
||||||
if (vtype == QSE_AWK_VAL_STR)
|
qse_awk_rtx_freevalstr (rtx, v, dst);
|
||||||
qse_awk_rtx_refdownval (rtx, v);
|
qse_awk_rtx_refdownval (rtx, v);
|
||||||
else qse_awk_rtx_freemem (rtx, dst);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (n <= -1)
|
if (n <= -1)
|
||||||
|
@ -1583,14 +1583,14 @@ qse_wchar_t* qse_awk_rtx_valtowcsdupwithcmgr (qse_awk_rtx_t* rtx, const qse_awk_
|
|||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
#if defined(QSE_CHAR_IS_MCHAR)
|
#if defined(QSE_CHAR_IS_MCHAR)
|
||||||
qse_size_t duplen, wcslen;
|
qse_size_t wcslen;
|
||||||
qse_char_t* dup;
|
qse_awk_rtx_valtostr_out_t out;
|
||||||
|
|
||||||
dup = qse_awk_rtx_valtostrdup(rtx, v, &duplen);
|
out.type = QSE_AWK_RTX_VALTOSTR_CPLDUP;
|
||||||
if (!dup) return QSE_NULL;
|
if (qse_awk_rtx_valtostr(rtx, v, &out) <= -1) return QSE_NULL;
|
||||||
|
|
||||||
wcs = qse_mbsntowcsalldupwithcmgr(dup, &duplen, &wcslen, rtx->awk->mmgr, cmgr);
|
wcs = qse_mbsntowcsalldupwithcmgr(dup, &out.u.cpldup.len, &wcslen, rtx->awk->mmgr, cmgr);
|
||||||
qse_awk_rtx_freemem (rtx, dup);
|
qse_awk_rtx_freemem (rtx, out.u.cpldup.ptr);
|
||||||
if (!wcs)
|
if (!wcs)
|
||||||
{
|
{
|
||||||
qse_awk_rtx_seterror (rtx, QSE_AWK_ENOMEM, QSE_NULL, QSE_NULL);
|
qse_awk_rtx_seterror (rtx, QSE_AWK_ENOMEM, QSE_NULL, QSE_NULL);
|
||||||
@ -1599,10 +1599,13 @@ qse_wchar_t* qse_awk_rtx_valtowcsdupwithcmgr (qse_awk_rtx_t* rtx, const qse_awk_
|
|||||||
|
|
||||||
if (len) *len = wcslen;
|
if (len) *len = wcslen;
|
||||||
#else
|
#else
|
||||||
qse_size_t wcslen;
|
qse_awk_rtx_valtostr_out_t out;
|
||||||
wcs = qse_awk_rtx_valtostrdup(rtx, v, &wcslen);
|
|
||||||
if (!wcs) return QSE_NULL;
|
out.type = QSE_AWK_RTX_VALTOSTR_CPLDUP;
|
||||||
if (len) *len = wcslen;
|
if (qse_awk_rtx_valtostr(rtx, v, &out) <= -1) return QSE_NULL;
|
||||||
|
|
||||||
|
wcs = out.u.cpldup.ptr;
|
||||||
|
if (len) *len = out.u.cpldup.len;
|
||||||
#endif
|
#endif
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user