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))
|
||||
|
||||
#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)
|
||||
#else
|
||||
# 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_size_t len, optlen = 0;
|
||||
|
||||
nargs = qse_awk_rtx_getnargs (rtx);
|
||||
nargs = qse_awk_rtx_getnargs(rtx);
|
||||
QSE_ASSERT (nargs == 1 || nargs == 2);
|
||||
|
||||
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);
|
||||
|
||||
name = qse_awk_rtx_getvalstr (rtx, a0, &len);
|
||||
name = qse_awk_rtx_getvalstr(rtx, a0, &len);
|
||||
if (name == QSE_NULL) return -1;
|
||||
|
||||
if (a1)
|
||||
{
|
||||
opt = qse_awk_rtx_getvalstr (rtx, a1, &optlen);
|
||||
opt = qse_awk_rtx_getvalstr(rtx, a1, &optlen);
|
||||
if (opt == QSE_NULL)
|
||||
{
|
||||
qse_awk_rtx_freevalstr (rtx, a0, name);
|
||||
qse_awk_rtx_freevalstr(rtx, a0, name);
|
||||
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 (optlen != 1 ||
|
||||
(opt[0] != QSE_T('r') && opt[0] != QSE_T('w')))
|
||||
if (optlen != 1 || (opt[0] != QSE_T('r') && opt[0] != QSE_T('w')))
|
||||
{
|
||||
n = -1;
|
||||
goto skip_close;
|
||||
@ -292,25 +291,24 @@ skip_close:
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int flush_io (
|
||||
qse_awk_rtx_t* run, int rio, const qse_char_t* name, int n)
|
||||
static int flush_io (qse_awk_rtx_t* rtx, int rio, const qse_char_t* name, int n)
|
||||
{
|
||||
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 (run->errinf.num == QSE_AWK_EIOIMPL) n = -1;
|
||||
else if (run->errinf.num == QSE_AWK_EIONMNF)
|
||||
if (rtx->errinf.num == QSE_AWK_EIOIMPL) n = -1;
|
||||
else if (rtx->errinf.num == QSE_AWK_EIONMNF)
|
||||
{
|
||||
if (n != 0) n = -2;
|
||||
}
|
||||
else n = -99;
|
||||
*/
|
||||
if (run->errinf.num == QSE_AWK_EIONMNF)
|
||||
if (rtx->errinf.num == QSE_AWK_EIONMNF)
|
||||
{
|
||||
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_awk_rtx_valtostr_out_t out;
|
||||
|
||||
v = eval_expression (rtx, p->in);
|
||||
if (v == QSE_NULL) return QSE_NULL;
|
||||
v = eval_expression(rtx, p->in);
|
||||
if (!v) return QSE_NULL;
|
||||
|
||||
qse_awk_rtx_refupval (rtx, v);
|
||||
vtype = QSE_AWK_RTX_GETVALTYPE (rtx, v);
|
||||
if (vtype == QSE_AWK_VAL_STR)
|
||||
dst = qse_awk_rtx_getvalstr(rtx, v, &len);
|
||||
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);
|
||||
if (x <= -1) return QSE_NULL;
|
||||
|
||||
dst = out.u.cpldup.ptr;
|
||||
len = out.u.cpldup.len;
|
||||
return QSE_NULL;
|
||||
}
|
||||
|
||||
if (len <= 0)
|
||||
if (len <= 0)
|
||||
{
|
||||
/* the input source name is empty.
|
||||
* make getline return -1 */
|
||||
if (vtype == QSE_AWK_VAL_STR)
|
||||
qse_awk_rtx_refdownval (rtx, v);
|
||||
else qse_awk_rtx_freemem (rtx, dst);
|
||||
|
||||
qse_awk_rtx_freevalstr (rtx, v, dst);
|
||||
qse_awk_rtx_refdownval (rtx, v);
|
||||
|
||||
n = -1;
|
||||
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.
|
||||
* unlike print & printf, it is not a hard
|
||||
* error */
|
||||
if (vtype == QSE_AWK_VAL_STR)
|
||||
qse_awk_rtx_refdownval (rtx, v);
|
||||
else qse_awk_rtx_freemem (rtx, dst);
|
||||
|
||||
qse_awk_rtx_freevalstr (rtx, v, dst);
|
||||
qse_awk_rtx_refdownval (rtx, v);
|
||||
n = -1;
|
||||
goto skip_read;
|
||||
}
|
||||
@ -6705,11 +6691,10 @@ read_console_again:
|
||||
|
||||
n = qse_awk_rtx_readio(rtx, p->in_type, dst, buf);
|
||||
|
||||
if (p->in)
|
||||
if (p->in)
|
||||
{
|
||||
if (vtype == QSE_AWK_VAL_STR)
|
||||
qse_awk_rtx_refdownval (rtx, v);
|
||||
else qse_awk_rtx_freemem (rtx, dst);
|
||||
qse_awk_rtx_freevalstr (rtx, v, dst);
|
||||
qse_awk_rtx_refdownval (rtx, v);
|
||||
}
|
||||
|
||||
if (n <= -1)
|
||||
|
@ -1583,14 +1583,14 @@ qse_wchar_t* qse_awk_rtx_valtowcsdupwithcmgr (qse_awk_rtx_t* rtx, const qse_awk_
|
||||
default:
|
||||
{
|
||||
#if defined(QSE_CHAR_IS_MCHAR)
|
||||
qse_size_t duplen, wcslen;
|
||||
qse_char_t* dup;
|
||||
qse_size_t wcslen;
|
||||
qse_awk_rtx_valtostr_out_t out;
|
||||
|
||||
dup = qse_awk_rtx_valtostrdup(rtx, v, &duplen);
|
||||
if (!dup) return QSE_NULL;
|
||||
out.type = QSE_AWK_RTX_VALTOSTR_CPLDUP;
|
||||
if (qse_awk_rtx_valtostr(rtx, v, &out) <= -1) return QSE_NULL;
|
||||
|
||||
wcs = qse_mbsntowcsalldupwithcmgr(dup, &duplen, &wcslen, rtx->awk->mmgr, cmgr);
|
||||
qse_awk_rtx_freemem (rtx, dup);
|
||||
wcs = qse_mbsntowcsalldupwithcmgr(dup, &out.u.cpldup.len, &wcslen, rtx->awk->mmgr, cmgr);
|
||||
qse_awk_rtx_freemem (rtx, out.u.cpldup.ptr);
|
||||
if (!wcs)
|
||||
{
|
||||
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;
|
||||
#else
|
||||
qse_size_t wcslen;
|
||||
wcs = qse_awk_rtx_valtostrdup(rtx, v, &wcslen);
|
||||
if (!wcs) return QSE_NULL;
|
||||
if (len) *len = wcslen;
|
||||
qse_awk_rtx_valtostr_out_t out;
|
||||
|
||||
out.type = QSE_AWK_RTX_VALTOSTR_CPLDUP;
|
||||
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
|
||||
break;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user