added new string copy functions with simple formatting and changed awk

error formatter accordingly.
- added qse_strfncpy() and qse_strxfncpy().
- qse_awk_seterror() and qse_awk_rtx_seterror utilize qse_strxfncpy().
This commit is contained in:
hyung-hwan 2009-02-15 03:14:49 +00:00
parent 10adba9ed0
commit c86350bfde
13 changed files with 335 additions and 398 deletions

View File

@ -825,8 +825,7 @@ void qse_awk_seterror (
qse_awk_t* awk, qse_awk_t* awk,
int errnum, int errnum,
qse_size_t errlin, qse_size_t errlin,
const qse_cstr_t* errarg, const qse_cstr_t* errarg
qse_size_t argcnt
); );
int qse_awk_getoption ( int qse_awk_getoption (
@ -1361,8 +1360,7 @@ void qse_awk_rtx_seterror (
qse_awk_rtx_t* rtx, qse_awk_rtx_t* rtx,
int errnum, int errnum,
qse_size_t errlin, qse_size_t errlin,
const qse_cstr_t* errarg, const qse_cstr_t* errarg
qse_size_t argcnt
); );

View File

@ -181,11 +181,21 @@ qse_size_t qse_strfcpy (
); );
/******/ /******/
/****f* Common/qse_strfncpy
* NAME
* qse_strfncpy - copy a string
* SYNOPSIS
*/
qse_size_t qse_strfncpy (
qse_char_t* buf,
const qse_char_t* fmt,
const qse_cstr_t* str
);
/******/
/****f* Common/qse_strxfcpy /****f* Common/qse_strxfcpy
* NAME * NAME
* qse_strxfcpy - copy a string * qse_strxfcpy - copy a string
* DESCRIPTION
* "format $1 $3 $2 \\$1 string"
* SYNOPSIS * SYNOPSIS
*/ */
qse_size_t qse_strxfcpy ( qse_size_t qse_strxfcpy (
@ -196,10 +206,31 @@ qse_size_t qse_strxfcpy (
); );
/******/ /******/
/****f* Common/qse_strxfncpy
* NAME
* qse_strxfncpy - copy a string
* SYNOPSIS
*/
qse_size_t qse_strxfncpy (
qse_char_t* buf,
qse_size_t bsz,
const qse_char_t* fmt,
const qse_cstr_t* str
);
/******/
qse_size_t qse_strxcat ( qse_size_t qse_strxcat (
qse_char_t* buf, qse_size_t bsz, const qse_char_t* str); qse_char_t* buf,
qse_size_t bsz,
const qse_char_t* str
);
qse_size_t qse_strxncat ( qse_size_t qse_strxncat (
qse_char_t* buf, qse_size_t bsz, const qse_char_t* str, qse_size_t len); qse_char_t* buf,
qse_size_t bsz,
const qse_char_t* str,
qse_size_t len
);
int qse_strcmp (const qse_char_t* s1, const qse_char_t* s2); int qse_strcmp (const qse_char_t* s1, const qse_char_t* s2);
int qse_strxcmp (const qse_char_t* s1, qse_size_t len1, const qse_char_t* s2); int qse_strxcmp (const qse_char_t* s1, qse_size_t len1, const qse_char_t* s2);

View File

@ -30,7 +30,7 @@
qse_cstr_t errarg; \ qse_cstr_t errarg; \
errarg.len = (leng); \ errarg.len = (leng); \
errarg.ptr = (arg); \ errarg.ptr = (arg); \
qse_awk_seterror ((awk), (code), (line), &errarg, 1); \ qse_awk_seterror ((awk), (code), (line), &errarg); \
} while (0) } while (0)
static void free_fun (qse_map_t* map, void* vptr, qse_size_t vlen) static void free_fun (qse_map_t* map, void* vptr, qse_size_t vlen)

View File

@ -394,7 +394,7 @@ int qse_awk_readeio (
if (qse_str_ccat (buf, c) == (qse_size_t)-1) if (qse_str_ccat (buf, c) == (qse_size_t)-1)
{ {
qse_awk_rtx_seterror ( qse_awk_rtx_seterror (
run, QSE_AWK_ENOMEM, 0, QSE_NULL, 0); run, QSE_AWK_ENOMEM, 0, QSE_NULL);
ret = -1; ret = -1;
break; break;
} }
@ -491,7 +491,7 @@ int qse_awk_writeeio_str (
if (p == QSE_NULL) if (p == QSE_NULL)
{ {
qse_awk_rtx_seterror ( qse_awk_rtx_seterror (
run, QSE_AWK_ENOMEM, 0, QSE_NULL, 0); run, QSE_AWK_ENOMEM, 0, QSE_NULL);
return -1; return -1;
} }
@ -500,7 +500,7 @@ int qse_awk_writeeio_str (
{ {
QSE_AWK_FREE (run->awk, p); QSE_AWK_FREE (run->awk, p);
qse_awk_rtx_seterror ( qse_awk_rtx_seterror (
run, QSE_AWK_ENOMEM, 0, QSE_NULL, 0); run, QSE_AWK_ENOMEM, 0, QSE_NULL);
return -1; return -1;
} }
@ -673,7 +673,7 @@ int qse_awk_nexteio_read (
/* something is totally wrong */ /* something is totally wrong */
QSE_ASSERT ( QSE_ASSERT (
!"should never happen - cannot find the relevant eio entry"); !"should never happen - cannot find the relevant eio entry");
qse_awk_rtx_seterror (run, QSE_AWK_EINTERN, 0, QSE_NULL, 0); qse_awk_rtx_seterror (run, QSE_AWK_EINTERN, 0, QSE_NULL);
return -1; return -1;
} }
@ -751,7 +751,7 @@ int qse_awk_nexteio_write (
/* something is totally wrong */ /* something is totally wrong */
QSE_ASSERT (!"should never happen - cannot find the relevant eio entry"); QSE_ASSERT (!"should never happen - cannot find the relevant eio entry");
qse_awk_rtx_seterror (run, QSE_AWK_EINTERN, 0, QSE_NULL, 0); qse_awk_rtx_seterror (run, QSE_AWK_EINTERN, 0, QSE_NULL);
return -1; return -1;
} }
@ -824,7 +824,7 @@ int qse_awk_closeeio_read (
if (handler (QSE_AWK_IO_CLOSE, p, QSE_NULL, 0) <= -1) if (handler (QSE_AWK_IO_CLOSE, p, QSE_NULL, 0) <= -1)
{ {
/* this is not a run-time error.*/ /* this is not a run-time error.*/
qse_awk_rtx_seterror (run, QSE_AWK_EIOIMPL, 0, QSE_NULL, 0); qse_awk_rtx_seterror (run, QSE_AWK_EIOIMPL, 0, QSE_NULL);
return -1; return -1;
} }
} }
@ -866,7 +866,7 @@ int qse_awk_closeeio_write (
if (handler == QSE_NULL) if (handler == QSE_NULL)
{ {
/* no io handler provided */ /* no io handler provided */
qse_awk_rtx_seterror (run, QSE_AWK_EIOUSER, 0, QSE_NULL, 0); qse_awk_rtx_seterror (run, QSE_AWK_EIOUSER, 0, QSE_NULL);
return -1; return -1;
} }

View File

@ -34,20 +34,20 @@ static const qse_char_t* __geterrstr (int errnum)
QSE_T("too many open files"), QSE_T("too many open files"),
QSE_T("too many links"), QSE_T("too many links"),
QSE_T("resource temporarily unavailable"), QSE_T("resource temporarily unavailable"),
QSE_T("'%.*s' not existing"), QSE_T("'${0}' not existing"),
QSE_T("'%.*s' already exists"), QSE_T("'${0}' already exists"),
QSE_T("file or data too big"), QSE_T("file or data too big"),
QSE_T("system too busy"), QSE_T("system too busy"),
QSE_T("is a directory"), QSE_T("is a directory"),
QSE_T("i/o error"), QSE_T("i/o error"),
QSE_T("cannot open '%.*s'"), QSE_T("cannot open '${0}'"),
QSE_T("cannot read '%.*s'"), QSE_T("cannot read '${0}'"),
QSE_T("cannot write '%.*s'"), QSE_T("cannot write '${0}'"),
QSE_T("cannot close '%.*s'"), QSE_T("cannot close '${0}'"),
QSE_T("internal error that should never have happened"), QSE_T("internal error that should never have happened"),
QSE_T("general run-time error"), QSE_T("general runtime error"),
QSE_T("block nested too deeply"), QSE_T("block nested too deeply"),
QSE_T("expressio nested too deeply"), QSE_T("expressio nested too deeply"),
@ -59,46 +59,46 @@ static const qse_char_t* __geterrstr (int errnum)
QSE_T("cannot close source output"), QSE_T("cannot close source output"),
QSE_T("cannot write source output"), QSE_T("cannot write source output"),
QSE_T("invalid character '%.*s'"), QSE_T("invalid character '${0}'"),
QSE_T("invalid digit '%.*s'"), QSE_T("invalid digit '${0}'"),
QSE_T("cannot unget character"), QSE_T("cannot unget character"),
QSE_T("unexpected end of source"), QSE_T("unexpected end of source"),
QSE_T("a comment not closed properly"), QSE_T("a comment not closed properly"),
QSE_T("a string not closed with a quote"), QSE_T("a string not closed with a quote"),
QSE_T("unexpected end of a regular expression"), QSE_T("unexpected end of a regular expression"),
QSE_T("a left brace expected in place of '%.*s'"), QSE_T("a left brace expected in place of '${0}'"),
QSE_T("a left parenthesis expected in place of '%.*s'"), QSE_T("a left parenthesis expected in place of '${0}'"),
QSE_T("a right parenthesis expected in place of '%.*s'"), QSE_T("a right parenthesis expected in place of '${0}'"),
QSE_T("a right bracket expected in place of '%.*s'"), QSE_T("a right bracket expected in place of '${0}'"),
QSE_T("a comma expected in place of '%.*s'"), QSE_T("a comma expected in place of '${0}'"),
QSE_T("a semicolon expected in place of '%.*s'"), QSE_T("a semicolon expected in place of '${0}'"),
QSE_T("a colon expected in place of '%.*s'"), QSE_T("a colon expected in place of '${0}'"),
QSE_T("statement not ending with a semicolon"), QSE_T("statement not ending with a semicolon"),
QSE_T("'in' expected in place of '%.*s'"), QSE_T("'in' expected in place of '${0}'"),
QSE_T("right-hand side of the 'in' operator not a variable"), QSE_T("right-hand side of the 'in' operator not a variable"),
QSE_T("invalid expression"), QSE_T("invalid expression"),
QSE_T("keyword 'function' expected in place of '%.*s'"), QSE_T("keyword 'function' expected in place of '${0}'"),
QSE_T("keyword 'while' expected in place of '%.*s'"), QSE_T("keyword 'while' expected in place of '${0}'"),
QSE_T("invalid assignment statement"), QSE_T("invalid assignment statement"),
QSE_T("an identifier expected in place of '%.*s'"), QSE_T("an identifier expected in place of '${0}'"),
QSE_T("'%.*s' not a valid function name"), QSE_T("'${0}' not a valid function name"),
QSE_T("BEGIN not followed by a left bracket on the same line"), QSE_T("BEGIN not followed by a left bracket on the same line"),
QSE_T("END not followed by a left bracket on the same line"), QSE_T("END not followed by a left bracket on the same line"),
QSE_T("duplicate BEGIN"), QSE_T("duplicate BEGIN"),
QSE_T("duplicate END"), QSE_T("duplicate END"),
QSE_T("intrinsic function '%.*s' redefined"), QSE_T("intrinsic function '${0}' redefined"),
QSE_T("function '%.*s' redefined"), QSE_T("function '${0}' redefined"),
QSE_T("global variable '%.*s' redefined"), QSE_T("global variable '${0}' redefined"),
QSE_T("parameter '%.*s' redefined"), QSE_T("parameter '${0}' redefined"),
QSE_T("variable '%.*s' redefined"), QSE_T("variable '${0}' redefined"),
QSE_T("duplicate parameter name '%.*s'"), QSE_T("duplicate parameter name '${0}'"),
QSE_T("duplicate global variable '%.*s'"), QSE_T("duplicate global variable '${0}'"),
QSE_T("duplicate local variable '%.*s'"), QSE_T("duplicate local variable '${0}'"),
QSE_T("'%.*s' not a valid parameter name"), QSE_T("'${0}' not a valid parameter name"),
QSE_T("'%.*s' not a valid variable name"), QSE_T("'${0}' not a valid variable name"),
QSE_T("undefined identifier '%.*s'"), QSE_T("undefined identifier '${0}'"),
QSE_T("l-value required"), QSE_T("l-value required"),
QSE_T("too many global variables"), QSE_T("too many global variables"),
QSE_T("too many local variables"), QSE_T("too many local variables"),
@ -119,9 +119,9 @@ static const qse_char_t* __geterrstr (int errnum)
QSE_T("wrong position index"), QSE_T("wrong position index"),
QSE_T("too few arguments"), QSE_T("too few arguments"),
QSE_T("too many arguments"), QSE_T("too many arguments"),
QSE_T("function '%.*s' not found"), QSE_T("function '${0}' not found"),
QSE_T("variable not indexable"), QSE_T("variable not indexable"),
QSE_T("variable '%.*s' not deletable"), QSE_T("variable '${0}' not deletable"),
QSE_T("value not a map"), QSE_T("value not a map"),
QSE_T("right-hand side of the 'in' operator not a map"), QSE_T("right-hand side of the 'in' operator not a map"),
QSE_T("right-hand side of the 'in' operator not a map nor nil"), QSE_T("right-hand side of the 'in' operator not a map nor nil"),
@ -129,7 +129,7 @@ static const qse_char_t* __geterrstr (int errnum)
QSE_T("value not assignable"), QSE_T("value not assignable"),
QSE_T("an indexed value cannot be assigned a map"), QSE_T("an indexed value cannot be assigned a map"),
QSE_T("a positional value cannot be assigned a map"), QSE_T("a positional value cannot be assigned a map"),
QSE_T("map '%.*s' not assignable with a scalar"), QSE_T("map '${0}' not assignable with a scalar"),
QSE_T("cannot change a scalar value to a map"), QSE_T("cannot change a scalar value to a map"),
QSE_T("a map is not allowed"), QSE_T("a map is not allowed"),
QSE_T("invalid value type"), QSE_T("invalid value type"),
@ -221,10 +221,9 @@ void qse_awk_geterror (
if (errlin != QSE_NULL) *errlin = awk->errlin; if (errlin != QSE_NULL) *errlin = awk->errlin;
if (errmsg != QSE_NULL) if (errmsg != QSE_NULL)
{ {
if (awk->errmsg[0] == QSE_T('\0')) *errmsg = (awk->errmsg[0] == QSE_T('\0'))?
*errmsg = qse_awk_geterrstr (awk, awk->errnum); qse_awk_geterrstr (awk, awk->errnum):
else awk->errmsg;
*errmsg = awk->errmsg;
} }
} }
@ -244,105 +243,17 @@ void qse_awk_seterrmsg (qse_awk_t* awk,
} }
void qse_awk_seterror ( void qse_awk_seterror (
qse_awk_t* awk, int errnum, qse_size_t errlin, qse_awk_t* awk, int errnum,
const qse_cstr_t* errarg, qse_size_t argcnt) qse_size_t errlin, const qse_cstr_t* errarg)
{ {
const qse_char_t* errfmt; const qse_char_t* errfmt;
qse_size_t fmtlen;
QSE_ASSERT (argcnt <= 5);
awk->errnum = errnum; awk->errnum = errnum;
awk->errlin = errlin; awk->errlin = errlin;
errfmt = qse_awk_geterrstr (awk, errnum); errfmt = qse_awk_geterrstr (awk, errnum);
fmtlen = qse_strlen(errfmt); QSE_ASSERT (errfmt != QSE_NULL);
qse_strxfncpy (awk->errmsg, QSE_COUNTOF(awk->errmsg), errfmt, errarg);
switch (argcnt)
{
case 0:
awk->prm->sprintf (
awk->prm->data,
awk->errmsg,
QSE_COUNTOF(awk->errmsg),
errfmt);
return;
case 1:
{
qse_char_t tmp[QSE_COUNTOF(awk->errmsg)];
qse_size_t len, tl;
if (fmtlen < QSE_COUNTOF(awk->errmsg) &&
errarg[0].len + fmtlen >= QSE_COUNTOF(awk->errmsg))
{
len = QSE_COUNTOF(awk->errmsg) - fmtlen - 3 - 1;
tl = qse_strxncpy (tmp, QSE_COUNTOF(tmp), errarg[0].ptr, len);
tmp[tl] = QSE_T('.');
tmp[tl+1] = QSE_T('.');
tmp[tl+2] = QSE_T('.');
len += 3;
}
else
{
len = errarg[0].len;
qse_strxncpy (tmp, QSE_COUNTOF(tmp), errarg[0].ptr, len);
}
awk->prm->sprintf (
awk->prm->data,
awk->errmsg,
QSE_COUNTOF(awk->errmsg),
errfmt, (int)len, tmp);
return;
}
case 2:
awk->prm->sprintf (
awk->prm->data,
awk->errmsg,
QSE_COUNTOF(awk->errmsg),
errfmt,
(int)errarg[0].len, errarg[0].ptr,
(int)errarg[1].len, errarg[1].ptr);
return;
case 3:
awk->prm->sprintf (
awk->prm->data,
awk->errmsg,
QSE_COUNTOF(awk->errmsg),
errfmt,
(int)errarg[0].len, errarg[0].ptr,
(int)errarg[1].len, errarg[1].ptr,
(int)errarg[2].len, errarg[2].ptr);
return;
case 4:
awk->prm->sprintf (
awk->prm->data,
awk->errmsg,
QSE_COUNTOF(awk->errmsg),
errfmt,
(int)errarg[0].len, errarg[0].ptr,
(int)errarg[1].len, errarg[1].ptr,
(int)errarg[2].len, errarg[2].ptr,
(int)errarg[3].len, errarg[3].ptr);
return;
case 5:
awk->prm->sprintf (
awk->prm->data,
awk->errmsg,
QSE_COUNTOF(awk->errmsg),
errfmt,
(int)errarg[0].len, errarg[0].ptr,
(int)errarg[1].len, errarg[1].ptr,
(int)errarg[2].len, errarg[2].ptr,
(int)errarg[3].len, errarg[3].ptr,
(int)errarg[4].len, errarg[4].ptr);
return;
}
} }
int qse_awk_rtx_geterrnum (qse_awk_rtx_t* run) int qse_awk_rtx_geterrnum (qse_awk_rtx_t* run)
@ -363,139 +274,44 @@ const qse_char_t* qse_awk_rtx_geterrmsg (qse_awk_rtx_t* run)
return run->errmsg; return run->errmsg;
} }
void qse_awk_rtx_seterrnum (qse_awk_rtx_t* run, int errnum) void qse_awk_rtx_seterrnum (qse_awk_rtx_t* rtx, int errnum)
{ {
run->errnum = errnum; rtx->errnum = errnum;
run->errlin = 0; rtx->errlin = 0;
run->errmsg[0] = QSE_T('\0'); rtx->errmsg[0] = QSE_T('\0');
} }
void qse_awk_rtx_seterrmsg (qse_awk_rtx_t* run, void qse_awk_rtx_seterrmsg (qse_awk_rtx_t* rtx,
int errnum, qse_size_t errlin, const qse_char_t* errmsg) int errnum, qse_size_t errlin, const qse_char_t* errmsg)
{ {
run->errnum = errnum; rtx->errnum = errnum;
run->errlin = errlin; rtx->errlin = errlin;
qse_strxcpy (run->errmsg, QSE_COUNTOF(run->errmsg), errmsg); qse_strxcpy (rtx->errmsg, QSE_COUNTOF(rtx->errmsg), errmsg);
} }
void qse_awk_rtx_geterror ( void qse_awk_rtx_geterror (
qse_awk_rtx_t* run, int* errnum, qse_awk_rtx_t* rtx, int* errnum,
qse_size_t* errlin, const qse_char_t** errmsg) qse_size_t* errlin, const qse_char_t** errmsg)
{ {
if (errnum != QSE_NULL) *errnum = run->errnum; if (errnum != QSE_NULL) *errnum = rtx->errnum;
if (errlin != QSE_NULL) *errlin = run->errlin; if (errlin != QSE_NULL) *errlin = rtx->errlin;
if (errmsg != QSE_NULL) if (errmsg != QSE_NULL)
{ {
if (run->errmsg[0] == QSE_T('\0')) *errmsg = (rtx->errmsg[0] == QSE_T('\0'))?
*errmsg = qse_awk_geterrstr (run->awk, run->errnum); qse_awk_geterrstr (rtx->awk, rtx->errnum): rtx->errmsg;
else
*errmsg = run->errmsg;
} }
} }
void qse_awk_rtx_seterror ( void qse_awk_rtx_seterror (
qse_awk_rtx_t* run, int errnum, qse_size_t errlin, qse_awk_rtx_t* rtx, int errnum,
const qse_cstr_t* errarg, qse_size_t argcnt) qse_size_t errlin, const qse_cstr_t* errarg)
{ {
const qse_char_t* errfmt; const qse_char_t* errfmt;
qse_size_t fmtlen;
QSE_ASSERT (argcnt <= 5); rtx->errnum = errnum;
rtx->errlin = errlin;
run->errnum = errnum; errfmt = qse_awk_geterrstr (rtx->awk, errnum);
run->errlin = errlin; QSE_ASSERT (errfmt != QSE_NULL);
qse_strxfncpy (rtx->errmsg, QSE_COUNTOF(rtx->errmsg), errfmt, errarg);
errfmt = qse_awk_geterrstr (run->awk, errnum);
fmtlen = qse_strlen (errfmt);
switch (argcnt)
{
case 0:
/* TODO: convert % to %% if the original % is not
* the first % of the %% sequence */
run->awk->prm->sprintf (
run->awk->prm->data,
run->errmsg,
QSE_COUNTOF(run->errmsg),
errfmt);
return;
case 1:
{
/* TODO: what if the argument contains a null character?
* handle the case more gracefully than now... */
qse_char_t tmp[QSE_COUNTOF(run->errmsg)];
qse_size_t len, tl;
if (fmtlen < QSE_COUNTOF(run->errmsg) &&
errarg[0].len + fmtlen >= QSE_COUNTOF(run->errmsg))
{
len = QSE_COUNTOF(run->errmsg) - fmtlen - 3 - 1;
tl = qse_strxncpy (tmp, QSE_COUNTOF(tmp), errarg[0].ptr, len);
tmp[tl] = QSE_T('.');
tmp[tl+1] = QSE_T('.');
tmp[tl+2] = QSE_T('.');
len += 3;
}
else
{
len = errarg[0].len;
qse_strxncpy (tmp, QSE_COUNTOF(tmp), errarg[0].ptr, len);
}
run->awk->prm->sprintf (
run->awk->prm->data,
run->errmsg,
QSE_COUNTOF(run->errmsg),
errfmt, len, tmp);
return;
}
case 2:
run->awk->prm->sprintf (
run->awk->prm->data,
run->errmsg,
QSE_COUNTOF(run->errmsg),
errfmt,
errarg[0].len, errarg[0].ptr,
errarg[1].len, errarg[1].ptr);
return;
case 3:
run->awk->prm->sprintf (
run->awk->prm->data,
run->errmsg,
QSE_COUNTOF(run->errmsg),
errfmt,
errarg[0].len, errarg[0].ptr,
errarg[1].len, errarg[1].ptr,
errarg[2].len, errarg[2].ptr);
return;
case 4:
run->awk->prm->sprintf (
run->awk->prm->data,
run->errmsg,
QSE_COUNTOF(run->errmsg),
errfmt,
errarg[0].len, errarg[0].ptr,
errarg[1].len, errarg[1].ptr,
errarg[2].len, errarg[2].ptr,
errarg[3].len, errarg[3].ptr);
return;
case 5:
run->awk->prm->sprintf (
run->awk->prm->data,
run->errmsg,
QSE_COUNTOF(run->errmsg),
errfmt,
errarg[0].len, errarg[0].ptr,
errarg[1].len, errarg[1].ptr,
errarg[2].len, errarg[2].ptr,
errarg[3].len, errarg[3].ptr,
errarg[4].len, errarg[4].ptr);
return;
}
} }

View File

@ -66,7 +66,7 @@ void* qse_awk_addfnc (
if (name_len <= 0) if (name_len <= 0)
{ {
qse_awk_seterror (awk, QSE_AWK_EINVAL, 0, QSE_NULL, 0); qse_awk_seterror (awk, QSE_AWK_EINVAL, 0, QSE_NULL);
return QSE_NULL; return QSE_NULL;
} }
@ -77,7 +77,7 @@ void* qse_awk_addfnc (
errarg.ptr = name; errarg.ptr = name;
errarg.len = name_len; errarg.len = name_len;
qse_awk_seterror (awk, QSE_AWK_EEXIST, 0, &errarg, 1); qse_awk_seterror (awk, QSE_AWK_EEXIST, 0, &errarg);
return QSE_NULL; return QSE_NULL;
} }
@ -131,7 +131,7 @@ int qse_awk_delfnc (
errarg.ptr = name; errarg.ptr = name;
errarg.len = name_len; errarg.len = name_len;
qse_awk_seterror (awk, QSE_AWK_ENOENT, 0, &errarg, 1); qse_awk_seterror (awk, QSE_AWK_ENOENT, 0, &errarg);
return -1; return -1;
} }
@ -1387,7 +1387,7 @@ static int fnc_sprintf (
} }
} }
x.ptr = qse_awk_format (run, x.ptr = qse_awk_rtx_format (run,
&out, &fbu, cs0.ptr, cs0.len, nargs, QSE_NULL, &x.len); &out, &fbu, cs0.ptr, cs0.len, nargs, QSE_NULL, &x.len);
if (a0->type != QSE_AWK_VAL_STR) QSE_AWK_FREE (run->awk, cs0.ptr); if (a0->type != QSE_AWK_VAL_STR) QSE_AWK_FREE (run->awk, cs0.ptr);
if (x.ptr == QSE_NULL) if (x.ptr == QSE_NULL)

View File

@ -348,7 +348,7 @@ static global_t gtab[] =
do { \ do { \
if (qse_str_ccat((awk)->token.name,(c)) == (qse_size_t)-1) \ if (qse_str_ccat((awk)->token.name,(c)) == (qse_size_t)-1) \
{ \ { \
qse_awk_seterror (awk, QSE_AWK_ENOMEM, (awk)->token.line, QSE_NULL, 0); \ qse_awk_seterror (awk, QSE_AWK_ENOMEM, (awk)->token.line, QSE_NULL); \
return -1; \ return -1; \
} \ } \
} while (0) } while (0)
@ -357,7 +357,7 @@ static global_t gtab[] =
do { \ do { \
if (qse_str_ncat((awk)->token.name,(s),(l)) == (qse_size_t)-1) \ if (qse_str_ncat((awk)->token.name,(s),(l)) == (qse_size_t)-1) \
{ \ { \
qse_awk_seterror (awk, QSE_AWK_ENOMEM, (awk)->token.line, QSE_NULL, 0); \ qse_awk_seterror (awk, QSE_AWK_ENOMEM, (awk)->token.line, QSE_NULL); \
return -1; \ return -1; \
} \ } \
} while (0) } while (0)
@ -367,16 +367,16 @@ static global_t gtab[] =
#define CLRERR(awk) qse_awk_seterrnum(awk,QSE_AWK_ENOERR) #define CLRERR(awk) qse_awk_seterrnum(awk,QSE_AWK_ENOERR)
#define ISNOERR(awk) ((awk)->errnum == QSE_AWK_ENOERR) #define ISNOERR(awk) ((awk)->errnum == QSE_AWK_ENOERR)
#define SETERR(awk,code) qse_awk_seterrnum(awk,code) #define SETERR(awk,code) qse_awk_seterrnum(awk,code)
#define SETERRLIN(awk,code,line) qse_awk_seterror(awk,code,line,QSE_NULL,0) #define SETERRLIN(awk,code,line) qse_awk_seterror(awk,code,line,QSE_NULL);
#define SETERRTOK(awk,code) \ #define SETERRTOK(awk,code) \
do { \ do { \
qse_cstr_t errarg; \ qse_cstr_t errarg; \
errarg.len = QSE_STR_LEN((awk)->token.name); \ errarg.len = QSE_STR_LEN((awk)->token.name); \
errarg.ptr = QSE_STR_PTR((awk)->token.name); \ errarg.ptr = QSE_STR_PTR((awk)->token.name); \
if (MATCH(awk,TOKEN_EOF)) \ if (MATCH(awk,TOKEN_EOF)) \
qse_awk_seterror (awk, code, (awk)->token.prev.line, &errarg, 1); \ qse_awk_seterror (awk, code, (awk)->token.prev.line, &errarg); \
else \ else \
qse_awk_seterror (awk, code, (awk)->token.line, &errarg, 1); \ qse_awk_seterror (awk, code, (awk)->token.line, &errarg); \
} while (0) } while (0)
#define SETERRARG(awk,code,line,arg,leng) \ #define SETERRARG(awk,code,line,arg,leng) \
@ -384,7 +384,7 @@ static global_t gtab[] =
qse_cstr_t errarg; \ qse_cstr_t errarg; \
errarg.len = (leng); \ errarg.len = (leng); \
errarg.ptr = (arg); \ errarg.ptr = (arg); \
qse_awk_seterror ((awk), (code), (line), &errarg, 1); \ qse_awk_seterror ((awk), (code), (line), &errarg); \
} while (0) } while (0)
#define MATCH_TERMINATOR(awk) \ #define MATCH_TERMINATOR(awk) \

View File

@ -44,7 +44,7 @@ int qse_awk_rtx_setrec (
{ {
qse_awk_rtx_clrrec (run, QSE_FALSE); qse_awk_rtx_clrrec (run, QSE_FALSE);
qse_awk_rtx_seterror ( qse_awk_rtx_seterror (
run, QSE_AWK_ENOMEM, 0, QSE_NULL, 0); run, QSE_AWK_ENOMEM, 0, QSE_NULL);
return -1; return -1;
} }
} }
@ -148,7 +148,7 @@ static int split_record (qse_awk_rtx_t* run)
{ {
if (fs_free != QSE_NULL) if (fs_free != QSE_NULL)
QSE_AWK_FREE (run->awk, fs_free); QSE_AWK_FREE (run->awk, fs_free);
qse_awk_rtx_seterror (run, errnum, 0, QSE_NULL, 0); qse_awk_rtx_seterror (run, errnum, 0, QSE_NULL);
return -1; return -1;
} }
} }
@ -176,7 +176,7 @@ static int split_record (qse_awk_rtx_t* run)
if (tmp == QSE_NULL) if (tmp == QSE_NULL)
{ {
if (fs_free != QSE_NULL) QSE_AWK_FREE (run->awk, fs_free); if (fs_free != QSE_NULL) QSE_AWK_FREE (run->awk, fs_free);
qse_awk_rtx_seterror (run, QSE_AWK_ENOMEM, 0, QSE_NULL, 0); qse_awk_rtx_seterror (run, QSE_AWK_ENOMEM, 0, QSE_NULL);
return -1; return -1;
} }
@ -205,7 +205,7 @@ static int split_record (qse_awk_rtx_t* run)
{ {
if (fs_free != QSE_NULL) if (fs_free != QSE_NULL)
QSE_AWK_FREE (run->awk, fs_free); QSE_AWK_FREE (run->awk, fs_free);
qse_awk_rtx_seterror (run, errnum, 0, QSE_NULL, 0); qse_awk_rtx_seterror (run, errnum, 0, QSE_NULL);
return -1; return -1;
} }
} }
@ -316,7 +316,7 @@ static int recomp_record_fields (
if (tmp == QSE_NULL) if (tmp == QSE_NULL)
{ {
qse_awk_rtx_seterror ( qse_awk_rtx_seterror (
run, QSE_AWK_ENOMEM, 0, QSE_NULL, 0); run, QSE_AWK_ENOMEM, 0, QSE_NULL);
return -1; return -1;
} }
} }
@ -327,7 +327,7 @@ static int recomp_record_fields (
if (tmp == QSE_NULL) if (tmp == QSE_NULL)
{ {
qse_awk_rtx_seterror ( qse_awk_rtx_seterror (
run, QSE_AWK_ENOMEM, 0, QSE_NULL, 0); run, QSE_AWK_ENOMEM, 0, QSE_NULL);
return -1; return -1;
} }
if (run->inrec.flds != QSE_NULL) if (run->inrec.flds != QSE_NULL)
@ -356,7 +356,7 @@ static int recomp_record_fields (
run->gbl.ofs.len) == (qse_size_t)-1) run->gbl.ofs.len) == (qse_size_t)-1)
{ {
qse_awk_rtx_seterror ( qse_awk_rtx_seterror (
run, QSE_AWK_ENOMEM, 0, QSE_NULL, 0); run, QSE_AWK_ENOMEM, 0, QSE_NULL);
return -1; return -1;
} }
} }
@ -374,7 +374,7 @@ static int recomp_record_fields (
&run->inrec.line, str, len) == (qse_size_t)-1) &run->inrec.line, str, len) == (qse_size_t)-1)
{ {
qse_awk_rtx_seterror ( qse_awk_rtx_seterror (
run, QSE_AWK_ENOMEM, 0, QSE_NULL, 0); run, QSE_AWK_ENOMEM, 0, QSE_NULL);
return -1; return -1;
} }
@ -399,7 +399,7 @@ static int recomp_record_fields (
&run->inrec.line, QSE_T("")) == (qse_size_t)-1) &run->inrec.line, QSE_T("")) == (qse_size_t)-1)
{ {
qse_awk_rtx_seterror ( qse_awk_rtx_seterror (
run, QSE_AWK_ENOMEM, 0, QSE_NULL, 0); run, QSE_AWK_ENOMEM, 0, QSE_NULL);
return -1; return -1;
} }
@ -426,7 +426,7 @@ static int recomp_record_fields (
tmp->ptr, tmp->len) == (qse_size_t)-1) tmp->ptr, tmp->len) == (qse_size_t)-1)
{ {
qse_awk_rtx_seterror ( qse_awk_rtx_seterror (
run, QSE_AWK_ENOMEM, 0, QSE_NULL, 0); run, QSE_AWK_ENOMEM, 0, QSE_NULL);
return -1; return -1;
} }
} }

View File

@ -284,7 +284,7 @@ static int set_global (
errarg.len = var->id.name.len; errarg.len = var->id.name.len;
qse_awk_rtx_seterror (run, qse_awk_rtx_seterror (run,
QSE_AWK_EMAPTOSCALAR, var->line, &errarg, 1); QSE_AWK_EMAPTOSCALAR, var->line, &errarg);
} }
else else
{ {
@ -294,7 +294,7 @@ static int set_global (
errarg.ptr = qse_awk_getgblname ( errarg.ptr = qse_awk_getgblname (
run->awk, idx, &errarg.len); run->awk, idx, &errarg.len);
qse_awk_rtx_seterror (run, qse_awk_rtx_seterror (run,
QSE_AWK_EMAPTOSCALAR, 0, &errarg, 1); QSE_AWK_EMAPTOSCALAR, 0, &errarg);
} }
return -1; return -1;
@ -645,7 +645,7 @@ qse_awk_rtx_t* qse_awk_rtx_open (
QSE_ASSERTX (awk->prm != QSE_NULL, "Call qse_awk_setprm() first"); QSE_ASSERTX (awk->prm != QSE_NULL, "Call qse_awk_setprm() first");
/* clear the awk error code */ /* clear the awk error code */
qse_awk_seterror (awk, QSE_AWK_ENOERR, 0, QSE_NULL, 0); qse_awk_seterror (awk, QSE_AWK_ENOERR, 0, QSE_NULL);
/* check if the code has ever been parsed */ /* check if the code has ever been parsed */
if (awk->tree.ngbls == 0 && if (awk->tree.ngbls == 0 &&
@ -654,7 +654,7 @@ qse_awk_rtx_t* qse_awk_rtx_open (
awk->tree.chain_size == 0 && awk->tree.chain_size == 0 &&
qse_map_getsize(awk->tree.funs) == 0) qse_map_getsize(awk->tree.funs) == 0)
{ {
qse_awk_seterror (awk, QSE_AWK_ENOPER, 0, QSE_NULL, 0); qse_awk_seterror (awk, QSE_AWK_ENOPER, 0, QSE_NULL);
return QSE_NULL; return QSE_NULL;
} }
@ -665,7 +665,7 @@ qse_awk_rtx_t* qse_awk_rtx_open (
{ {
/* if it fails, the failure is reported thru /* if it fails, the failure is reported thru
* the awk object */ * the awk object */
qse_awk_seterror (awk, QSE_AWK_ENOMEM, 0, QSE_NULL, 0); qse_awk_seterror (awk, QSE_AWK_ENOMEM, 0, QSE_NULL);
return QSE_NULL; return QSE_NULL;
} }
@ -766,14 +766,14 @@ static int init_rtx (qse_awk_rtx_t* rtx, qse_awk_t* awk, qse_awk_rio_t* rio)
if (qse_str_init ( if (qse_str_init (
&rtx->inrec.line, MMGR(rtx), DEF_BUF_CAPA) == QSE_NULL) &rtx->inrec.line, MMGR(rtx), DEF_BUF_CAPA) == QSE_NULL)
{ {
qse_awk_seterror (awk, QSE_AWK_ENOMEM, 0, QSE_NULL, 0); qse_awk_seterror (awk, QSE_AWK_ENOMEM, 0, QSE_NULL);
return -1; return -1;
} }
if (qse_str_init (&rtx->format.out, MMGR(rtx), 256) == QSE_NULL) if (qse_str_init (&rtx->format.out, MMGR(rtx), 256) == QSE_NULL)
{ {
qse_str_fini (&rtx->inrec.line); qse_str_fini (&rtx->inrec.line);
qse_awk_seterror (awk, QSE_AWK_ENOMEM, 0, QSE_NULL, 0); qse_awk_seterror (awk, QSE_AWK_ENOMEM, 0, QSE_NULL);
return -1; return -1;
} }
@ -781,7 +781,7 @@ static int init_rtx (qse_awk_rtx_t* rtx, qse_awk_t* awk, qse_awk_rio_t* rio)
{ {
qse_str_fini (&rtx->format.out); qse_str_fini (&rtx->format.out);
qse_str_fini (&rtx->inrec.line); qse_str_fini (&rtx->inrec.line);
qse_awk_seterror (awk, QSE_AWK_ENOMEM, 0, QSE_NULL, 0); qse_awk_seterror (awk, QSE_AWK_ENOMEM, 0, QSE_NULL);
return -1; return -1;
} }
@ -792,7 +792,7 @@ static int init_rtx (qse_awk_rtx_t* rtx, qse_awk_t* awk, qse_awk_rio_t* rio)
qse_str_fini (&rtx->format.fmt); qse_str_fini (&rtx->format.fmt);
qse_str_fini (&rtx->format.out); qse_str_fini (&rtx->format.out);
qse_str_fini (&rtx->inrec.line); qse_str_fini (&rtx->inrec.line);
qse_awk_seterror (awk, QSE_AWK_ENOMEM, 0, QSE_NULL, 0); qse_awk_seterror (awk, QSE_AWK_ENOMEM, 0, QSE_NULL);
return -1; return -1;
} }
*(qse_awk_rtx_t**)qse_map_getxtn(rtx->named) = rtx; *(qse_awk_rtx_t**)qse_map_getxtn(rtx->named) = rtx;
@ -809,7 +809,7 @@ static int init_rtx (qse_awk_rtx_t* rtx, qse_awk_t* awk, qse_awk_rio_t* rio)
qse_str_fini (&rtx->format.fmt); qse_str_fini (&rtx->format.fmt);
qse_str_fini (&rtx->format.out); qse_str_fini (&rtx->format.out);
qse_str_fini (&rtx->inrec.line); qse_str_fini (&rtx->inrec.line);
qse_awk_seterror (awk, QSE_AWK_ENOMEM, 0, QSE_NULL, 0); qse_awk_seterror (awk, QSE_AWK_ENOMEM, 0, QSE_NULL);
return -1; return -1;
} }
rtx->format.tmp.len = 4096; rtx->format.tmp.len = 4096;
@ -826,7 +826,7 @@ static int init_rtx (qse_awk_rtx_t* rtx, qse_awk_t* awk, qse_awk_rio_t* rio)
qse_str_fini (&rtx->format.fmt); qse_str_fini (&rtx->format.fmt);
qse_str_fini (&rtx->format.out); qse_str_fini (&rtx->format.out);
qse_str_fini (&rtx->inrec.line); qse_str_fini (&rtx->inrec.line);
qse_awk_seterror (awk, QSE_AWK_ENOMEM, 0, QSE_NULL, 0); qse_awk_seterror (awk, QSE_AWK_ENOMEM, 0, QSE_NULL);
return -1; return -1;
} }
@ -1481,7 +1481,7 @@ int qse_awk_rtx_call (
{ {
/* cannot call the function again when exit() is called /* cannot call the function again when exit() is called
* in an AWK program or qse_awk_rtx_stop() is invoked */ * in an AWK program or qse_awk_rtx_stop() is invoked */
qse_awk_rtx_seterror (rtx, QSE_AWK_ENOPER, 0, QSE_NULL, 0); qse_awk_rtx_seterror (rtx, QSE_AWK_ENOPER, 0, QSE_NULL);
return -1; return -1;
} }
/*rtx->exit_level = EXIT_NONE;*/ /*rtx->exit_level = EXIT_NONE;*/
@ -1505,7 +1505,7 @@ int qse_awk_rtx_call (
errarg.ptr = call.what.fun.name.ptr; errarg.ptr = call.what.fun.name.ptr;
errarg.len = call.what.fun.name.len; errarg.len = call.what.fun.name.len;
qse_awk_rtx_seterror (rtx, QSE_AWK_EFUNNONE, 0, &errarg, 1); qse_awk_rtx_seterror (rtx, QSE_AWK_EFUNNONE, 0, &errarg);
return -1; return -1;
} }
@ -1517,7 +1517,7 @@ int qse_awk_rtx_call (
{ {
/* TODO: is this correct? what if i want to /* TODO: is this correct? what if i want to
* allow arbitarary numbers of arguments? */ * allow arbitarary numbers of arguments? */
qse_awk_rtx_seterror (rtx, QSE_AWK_EARGTM, 0, QSE_NULL, 0); qse_awk_rtx_seterror (rtx, QSE_AWK_EARGTM, 0, QSE_NULL);
return -1; return -1;
} }
@ -1737,7 +1737,7 @@ static int run_block (qse_awk_rtx_t* run, qse_awk_nde_blk_t* nde)
run->depth.cur.block >= run->depth.max.block) run->depth.cur.block >= run->depth.max.block)
{ {
qse_awk_rtx_seterror ( qse_awk_rtx_seterror (
run, QSE_AWK_EBLKNST, nde->line, QSE_NULL, 0); run, QSE_AWK_EBLKNST, nde->line, QSE_NULL);
return -1;; return -1;;
} }
@ -2253,7 +2253,7 @@ static int run_foreach (qse_awk_rtx_t* run, qse_awk_nde_foreach_t* nde)
qse_awk_rtx_refdownval (run, rv); qse_awk_rtx_refdownval (run, rv);
qse_awk_rtx_seterror ( qse_awk_rtx_seterror (
run, QSE_AWK_ENOTMAPIN, test->right->line, QSE_NULL, 0); run, QSE_AWK_ENOTMAPIN, test->right->line, QSE_NULL);
return -1; return -1;
} }
map = ((qse_awk_val_map_t*)rv)->map; map = ((qse_awk_val_map_t*)rv)->map;
@ -2303,7 +2303,7 @@ static int run_return (qse_awk_rtx_t* run, qse_awk_nde_return_t* nde)
qse_awk_rtx_seterror ( qse_awk_rtx_seterror (
run, QSE_AWK_EMAPNOTALLOWED, run, QSE_AWK_EMAPNOTALLOWED,
nde->line, QSE_NULL, 0); nde->line, QSE_NULL);
return -1; return -1;
} }
} }
@ -2350,13 +2350,13 @@ static int run_next (qse_awk_rtx_t* run, qse_awk_nde_next_t* nde)
if (run->active_block == (qse_awk_nde_blk_t*)run->awk->tree.begin) if (run->active_block == (qse_awk_nde_blk_t*)run->awk->tree.begin)
{ {
qse_awk_rtx_seterror ( qse_awk_rtx_seterror (
run, QSE_AWK_ERNEXTBEG, nde->line, QSE_NULL, 0); run, QSE_AWK_ERNEXTBEG, nde->line, QSE_NULL);
return -1; return -1;
} }
else if (run->active_block == (qse_awk_nde_blk_t*)run->awk->tree.end) else if (run->active_block == (qse_awk_nde_blk_t*)run->awk->tree.end)
{ {
qse_awk_rtx_seterror ( qse_awk_rtx_seterror (
run, QSE_AWK_ERNEXTEND, nde->line, QSE_NULL, 0); run, QSE_AWK_ERNEXTEND, nde->line, QSE_NULL);
return -1; return -1;
} }
@ -2372,13 +2372,13 @@ static int run_nextinfile (qse_awk_rtx_t* run, qse_awk_nde_nextfile_t* nde)
if (run->active_block == (qse_awk_nde_blk_t*)run->awk->tree.begin) if (run->active_block == (qse_awk_nde_blk_t*)run->awk->tree.begin)
{ {
qse_awk_rtx_seterror ( qse_awk_rtx_seterror (
run, QSE_AWK_ERNEXTFBEG, nde->line, QSE_NULL, 0); run, QSE_AWK_ERNEXTFBEG, nde->line, QSE_NULL);
return -1; return -1;
} }
else if (run->active_block == (qse_awk_nde_blk_t*)run->awk->tree.end) else if (run->active_block == (qse_awk_nde_blk_t*)run->awk->tree.end)
{ {
qse_awk_rtx_seterror ( qse_awk_rtx_seterror (
run, QSE_AWK_ERNEXTFEND, nde->line, QSE_NULL, 0); run, QSE_AWK_ERNEXTFEND, nde->line, QSE_NULL);
return -1; return -1;
} }
@ -2483,8 +2483,7 @@ static int run_delete (qse_awk_rtx_t* run, qse_awk_nde_delete_t* nde)
qse_awk_rtx_refdownval (run, tmp); qse_awk_rtx_refdownval (run, tmp);
qse_awk_rtx_seterror ( qse_awk_rtx_seterror (
run, QSE_AWK_ENOMEM, var->line, run, QSE_AWK_ENOMEM, var->line, QSE_NULL);
QSE_NULL, 0);
return -1; return -1;
} }
@ -2508,8 +2507,7 @@ static int run_delete (qse_awk_rtx_t* run, qse_awk_nde_delete_t* nde)
errarg.len = var->id.name.len; errarg.len = var->id.name.len;
qse_awk_rtx_seterror ( qse_awk_rtx_seterror (
run, QSE_AWK_ENOTDEL, var->line, run, QSE_AWK_ENOTDEL, var->line, &errarg);
&errarg, 1);
return -1; return -1;
} }
@ -2632,8 +2630,7 @@ static int run_delete (qse_awk_rtx_t* run, qse_awk_nde_delete_t* nde)
errarg.len = var->id.name.len; errarg.len = var->id.name.len;
qse_awk_rtx_seterror ( qse_awk_rtx_seterror (
run, QSE_AWK_ENOTDEL, var->line, run, QSE_AWK_ENOTDEL, var->line, &errarg);
&errarg, 1);
return -1; return -1;
} }
@ -2690,7 +2687,7 @@ static int run_delete (qse_awk_rtx_t* run, qse_awk_nde_delete_t* nde)
"the delete statement cannot be called with other nodes than the variables such as a named variable, a named indexed variable, etc"); "the delete statement cannot be called with other nodes than the variables such as a named variable, a named indexed variable, etc");
qse_awk_rtx_seterror ( qse_awk_rtx_seterror (
run, QSE_AWK_ERDELETE, var->line, QSE_NULL, 0); run, QSE_AWK_ERDELETE, var->line, QSE_NULL);
return -1; return -1;
} }
@ -2745,7 +2742,7 @@ static int run_reset (qse_awk_rtx_t* run, qse_awk_nde_reset_t* nde)
"the reset statement can only be called with plain variables"); "the reset statement can only be called with plain variables");
qse_awk_rtx_seterror ( qse_awk_rtx_seterror (
run, QSE_AWK_ERRESET, var->line, QSE_NULL, 0); run, QSE_AWK_ERRESET, var->line, QSE_NULL);
return -1; return -1;
} }
@ -2793,7 +2790,7 @@ static int run_print (qse_awk_rtx_t* run, qse_awk_nde_print_t* nde)
/* the destination name is empty */ /* the destination name is empty */
QSE_AWK_FREE (run->awk, out); QSE_AWK_FREE (run->awk, out);
qse_awk_rtx_seterror ( qse_awk_rtx_seterror (
run, QSE_AWK_EIONMEM, nde->line, QSE_NULL, 0); run, QSE_AWK_EIONMEM, nde->line, QSE_NULL);
return -1; return -1;
} }
@ -2806,8 +2803,7 @@ static int run_print (qse_awk_rtx_t* run, qse_awk_nde_print_t* nde)
/* if so, it skips writing */ /* if so, it skips writing */
QSE_AWK_FREE (run->awk, out); QSE_AWK_FREE (run->awk, out);
qse_awk_rtx_seterror ( qse_awk_rtx_seterror (
run, QSE_AWK_EIONMNL, nde->line, run, QSE_AWK_EIONMNL, nde->line, QSE_NULL);
QSE_NULL, 0);
return -1; return -1;
} }
} }
@ -2952,7 +2948,7 @@ static int run_printf (qse_awk_rtx_t* run, qse_awk_nde_print_t* nde)
/* the output destination name is empty. */ /* the output destination name is empty. */
QSE_AWK_FREE (run->awk, out); QSE_AWK_FREE (run->awk, out);
qse_awk_rtx_seterror ( qse_awk_rtx_seterror (
run, QSE_AWK_EIONMEM, nde->line, QSE_NULL, 0); run, QSE_AWK_EIONMEM, nde->line, QSE_NULL);
return -1; return -1;
} }
@ -2964,8 +2960,7 @@ static int run_printf (qse_awk_rtx_t* run, qse_awk_nde_print_t* nde)
* character. */ * character. */
QSE_AWK_FREE (run->awk, out); QSE_AWK_FREE (run->awk, out);
qse_awk_rtx_seterror ( qse_awk_rtx_seterror (
run, QSE_AWK_EIONMNL, nde->line, run, QSE_AWK_EIONMNL, nde->line, QSE_NULL);
QSE_NULL, 0);
return -1; return -1;
} }
} }
@ -3043,7 +3038,7 @@ static int output_formatted (
qse_size_t len; qse_size_t len;
int n; int n;
ptr = qse_awk_format (run, ptr = qse_awk_rtx_format (run,
QSE_NULL, QSE_NULL, fmt, fmt_len, 0, args, &len); QSE_NULL, QSE_NULL, fmt, fmt_len, 0, args, &len);
if (ptr == QSE_NULL) return -1; if (ptr == QSE_NULL) return -1;
@ -3107,7 +3102,7 @@ static qse_awk_val_t* eval_expression (qse_awk_rtx_t* run, qse_awk_nde_t* nde)
* character. otherwise, the following way of * character. otherwise, the following way of
* setting the error information may not work */ * setting the error information may not work */
qse_awk_rtx_seterror ( qse_awk_rtx_seterror (
run, errnum, nde->line, QSE_NULL, 0); run, errnum, nde->line, QSE_NULL);
return QSE_NULL; return QSE_NULL;
} }
} }
@ -3185,7 +3180,7 @@ static qse_awk_val_t* eval_group (qse_awk_rtx_t* run, qse_awk_nde_t* nde)
/* eval_binop_in evaluates the QSE_AWK_NDE_GRP specially. /* eval_binop_in evaluates the QSE_AWK_NDE_GRP specially.
* so this function should never be reached. */ * so this function should never be reached. */
QSE_ASSERT (!"should never happen - NDE_GRP only for in"); QSE_ASSERT (!"should never happen - NDE_GRP only for in");
qse_awk_rtx_seterror (run, QSE_AWK_EINTERN, nde->line, QSE_NULL, 0); qse_awk_rtx_seterror (run, QSE_AWK_EINTERN, nde->line, QSE_NULL);
return QSE_NULL; return QSE_NULL;
} }
@ -3314,7 +3309,7 @@ static qse_awk_val_t* do_assignment (
return ret; return ret;
exit_on_error: exit_on_error:
qse_awk_rtx_seterror (run, errnum, var->line, QSE_NULL, 0); qse_awk_rtx_seterror (run, errnum, var->line, QSE_NULL);
return QSE_NULL; return QSE_NULL;
} }
@ -3348,7 +3343,7 @@ static qse_awk_val_t* do_assignment_scalar (
errarg.len = var->id.name.len; errarg.len = var->id.name.len;
qse_awk_rtx_seterror (run, qse_awk_rtx_seterror (run,
QSE_AWK_EMAPTOSCALAR, var->line, &errarg, 1); QSE_AWK_EMAPTOSCALAR, var->line, &errarg);
return QSE_NULL; return QSE_NULL;
} }
@ -3356,7 +3351,7 @@ static qse_awk_val_t* do_assignment_scalar (
var->id.name.ptr, var->id.name.len, val, 0) == QSE_NULL) var->id.name.ptr, var->id.name.len, val, 0) == QSE_NULL)
{ {
qse_awk_rtx_seterror ( qse_awk_rtx_seterror (
run, QSE_AWK_ENOMEM, var->line, QSE_NULL, 0); run, QSE_AWK_ENOMEM, var->line, QSE_NULL);
return QSE_NULL; return QSE_NULL;
} }
@ -3384,7 +3379,7 @@ static qse_awk_val_t* do_assignment_scalar (
errarg.len = var->id.name.len; errarg.len = var->id.name.len;
qse_awk_rtx_seterror (run, qse_awk_rtx_seterror (run,
QSE_AWK_EMAPTOSCALAR, var->line, &errarg, 1); QSE_AWK_EMAPTOSCALAR, var->line, &errarg);
return QSE_NULL; return QSE_NULL;
} }
@ -3405,7 +3400,7 @@ static qse_awk_val_t* do_assignment_scalar (
errarg.len = var->id.name.len; errarg.len = var->id.name.len;
qse_awk_rtx_seterror (run, qse_awk_rtx_seterror (run,
QSE_AWK_EMAPTOSCALAR, var->line, &errarg, 1); QSE_AWK_EMAPTOSCALAR, var->line, &errarg);
return QSE_NULL; return QSE_NULL;
} }
@ -3479,7 +3474,7 @@ static qse_awk_val_t* do_assignment_map (
qse_awk_rtx_refdownval (run, tmp); qse_awk_rtx_refdownval (run, tmp);
qse_awk_rtx_seterror ( qse_awk_rtx_seterror (
run, QSE_AWK_ENOMEM, var->line, QSE_NULL, 0); run, QSE_AWK_ENOMEM, var->line, QSE_NULL);
return QSE_NULL; return QSE_NULL;
} }
@ -3517,7 +3512,7 @@ static qse_awk_val_t* do_assignment_map (
{ {
/* variable assigned is not a map */ /* variable assigned is not a map */
qse_awk_rtx_seterror ( qse_awk_rtx_seterror (
run, QSE_AWK_ENOTIDX, var->line, QSE_NULL, 0); run, QSE_AWK_ENOTIDX, var->line, QSE_NULL);
return QSE_NULL; return QSE_NULL;
} }
@ -3537,7 +3532,7 @@ static qse_awk_val_t* do_assignment_map (
if (qse_map_upsert (map->map, str, len, val, 0) == QSE_NULL) if (qse_map_upsert (map->map, str, len, val, 0) == QSE_NULL)
{ {
if (str != idxbuf) QSE_AWK_FREE (run->awk, str); if (str != idxbuf) QSE_AWK_FREE (run->awk, str);
qse_awk_rtx_seterror (run, QSE_AWK_ENOMEM, var->line, QSE_NULL, 0); qse_awk_rtx_seterror (run, QSE_AWK_ENOMEM, var->line, QSE_NULL);
return QSE_NULL; return QSE_NULL;
} }
@ -3566,14 +3561,14 @@ static qse_awk_val_t* do_assignment_pos (
if (n == -1) if (n == -1)
{ {
qse_awk_rtx_seterror ( qse_awk_rtx_seterror (
run, QSE_AWK_EPOSIDX, pos->line, QSE_NULL, 0); run, QSE_AWK_EPOSIDX, pos->line, QSE_NULL);
return QSE_NULL; return QSE_NULL;
} }
if (n == 1) lv = (qse_long_t)rv; if (n == 1) lv = (qse_long_t)rv;
if (!IS_VALID_POSIDX(lv)) if (!IS_VALID_POSIDX(lv))
{ {
qse_awk_rtx_seterror ( qse_awk_rtx_seterror (
run, QSE_AWK_EPOSIDX, pos->line, QSE_NULL, 0); run, QSE_AWK_EPOSIDX, pos->line, QSE_NULL);
return QSE_NULL; return QSE_NULL;
} }
@ -3818,7 +3813,7 @@ static qse_awk_val_t* eval_binop_in (
!"should never happen - in needs a plain variable"); !"should never happen - in needs a plain variable");
qse_awk_rtx_seterror ( qse_awk_rtx_seterror (
run, QSE_AWK_EINTERN, right->line, QSE_NULL, 0); run, QSE_AWK_EINTERN, right->line, QSE_NULL);
return QSE_NULL; return QSE_NULL;
} }
@ -3870,7 +3865,7 @@ static qse_awk_val_t* eval_binop_in (
if (str != idxbuf) QSE_AWK_FREE (run->awk, str); if (str != idxbuf) QSE_AWK_FREE (run->awk, str);
qse_awk_rtx_refdownval (run, rv); qse_awk_rtx_refdownval (run, rv);
qse_awk_rtx_seterror (run, QSE_AWK_ENOTMAPNILIN, right->line, QSE_NULL, 0); qse_awk_rtx_seterror (run, QSE_AWK_ENOTMAPNILIN, right->line, QSE_NULL);
return QSE_NULL; return QSE_NULL;
} }
@ -4729,7 +4724,7 @@ static qse_awk_val_t* eval_binop_match0 (
((qse_awk_val_str_t*)right)->len, &errnum); ((qse_awk_val_str_t*)right)->len, &errnum);
if (rex_code == QSE_NULL) if (rex_code == QSE_NULL)
{ {
qse_awk_rtx_seterror (run, errnum, rline, QSE_NULL, 0); qse_awk_rtx_seterror (run, errnum, rline, QSE_NULL);
return QSE_NULL; return QSE_NULL;
} }
} }
@ -4744,7 +4739,7 @@ static qse_awk_val_t* eval_binop_match0 (
{ {
QSE_AWK_FREE (run->awk, str); QSE_AWK_FREE (run->awk, str);
qse_awk_rtx_seterror (run, errnum, rline, QSE_NULL, 0); qse_awk_rtx_seterror (run, errnum, rline, QSE_NULL);
return QSE_NULL; return QSE_NULL;
} }
@ -4764,7 +4759,7 @@ static qse_awk_val_t* eval_binop_match0 (
if (right->type != QSE_AWK_VAL_REX) if (right->type != QSE_AWK_VAL_REX)
QSE_AWK_FREE (run->awk, rex_code); QSE_AWK_FREE (run->awk, rex_code);
qse_awk_rtx_seterror (run, errnum, lline, QSE_NULL, 0); qse_awk_rtx_seterror (run, errnum, lline, QSE_NULL);
return QSE_NULL; return QSE_NULL;
} }
@ -4800,7 +4795,7 @@ static qse_awk_val_t* eval_binop_match0 (
if (right->type != QSE_AWK_VAL_REX) if (right->type != QSE_AWK_VAL_REX)
QSE_AWK_FREE (run->awk, rex_code); QSE_AWK_FREE (run->awk, rex_code);
qse_awk_rtx_seterror (run, errnum, lline, QSE_NULL, 0); qse_awk_rtx_seterror (run, errnum, lline, QSE_NULL);
return QSE_NULL; return QSE_NULL;
} }
@ -4910,7 +4905,7 @@ static qse_awk_val_t* eval_incpre (qse_awk_rtx_t* run, qse_awk_nde_t* nde)
exp->left->type > QSE_AWK_NDE_POS) exp->left->type > QSE_AWK_NDE_POS)
{ {
qse_awk_rtx_seterror ( qse_awk_rtx_seterror (
run, QSE_AWK_EOPERAND, nde->line, QSE_NULL, 0); run, QSE_AWK_EOPERAND, nde->line, QSE_NULL);
return QSE_NULL; return QSE_NULL;
} }
@ -4959,7 +4954,7 @@ static qse_awk_val_t* eval_incpre (qse_awk_rtx_t* run, qse_awk_nde_t* nde)
/* /*
qse_awk_rtx_seterror ( qse_awk_rtx_seterror (
run, QSE_AWK_EOPERAND, nde->line, run, QSE_AWK_EOPERAND, nde->line,
QSE_NULL, 0); QSE_NULL);
*/ */
run->errlin = nde->line; run->errlin = nde->line;
return QSE_NULL; return QSE_NULL;
@ -5023,7 +5018,7 @@ static qse_awk_val_t* eval_incpre (qse_awk_rtx_t* run, qse_awk_nde_t* nde)
/* /*
qse_awk_rtx_seterror ( qse_awk_rtx_seterror (
run, QSE_AWK_EOPERAND, nde->line, run, QSE_AWK_EOPERAND, nde->line,
QSE_NULL, 0); QSE_NULL);
*/ */
run->errlin = nde->line; run->errlin = nde->line;
return QSE_NULL; return QSE_NULL;
@ -5055,7 +5050,7 @@ static qse_awk_val_t* eval_incpre (qse_awk_rtx_t* run, qse_awk_nde_t* nde)
qse_awk_rtx_refdownval (run, left); qse_awk_rtx_refdownval (run, left);
qse_awk_rtx_seterror ( qse_awk_rtx_seterror (
run, QSE_AWK_EINTERN, nde->line, QSE_NULL, 0); run, QSE_AWK_EINTERN, nde->line, QSE_NULL);
return QSE_NULL; return QSE_NULL;
} }
@ -5085,7 +5080,7 @@ static qse_awk_val_t* eval_incpst (qse_awk_rtx_t* run, qse_awk_nde_t* nde)
exp->left->type > QSE_AWK_NDE_POS) exp->left->type > QSE_AWK_NDE_POS)
{ {
qse_awk_rtx_seterror ( qse_awk_rtx_seterror (
run, QSE_AWK_EOPERAND, nde->line, QSE_NULL, 0); run, QSE_AWK_EOPERAND, nde->line, QSE_NULL);
return QSE_NULL; return QSE_NULL;
} }
@ -5154,7 +5149,7 @@ static qse_awk_val_t* eval_incpst (qse_awk_rtx_t* run, qse_awk_nde_t* nde)
/* /*
qse_awk_rtx_seterror ( qse_awk_rtx_seterror (
run, QSE_AWK_EOPERAND, nde->line, run, QSE_AWK_EOPERAND, nde->line,
QSE_NULL, 0); QSE_NULL);
*/ */
run->errlin = nde->line; run->errlin = nde->line;
return QSE_NULL; return QSE_NULL;
@ -5264,7 +5259,7 @@ static qse_awk_val_t* eval_incpst (qse_awk_rtx_t* run, qse_awk_nde_t* nde)
/* /*
qse_awk_rtx_seterror ( qse_awk_rtx_seterror (
run, QSE_AWK_EOPERAND, nde->line, run, QSE_AWK_EOPERAND, nde->line,
QSE_NULL, 0); QSE_NULL);
*/ */
run->errlin = nde->line; run->errlin = nde->line;
return QSE_NULL; return QSE_NULL;
@ -5322,7 +5317,7 @@ static qse_awk_val_t* eval_incpst (qse_awk_rtx_t* run, qse_awk_nde_t* nde)
qse_awk_rtx_refdownval (run, left); qse_awk_rtx_refdownval (run, left);
qse_awk_rtx_seterror ( qse_awk_rtx_seterror (
run, QSE_AWK_EINTERN, nde->line, QSE_NULL, 0); run, QSE_AWK_EINTERN, nde->line, QSE_NULL);
return QSE_NULL; return QSE_NULL;
} }
@ -5367,14 +5362,14 @@ static qse_awk_val_t* eval_fnc (qse_awk_rtx_t* run, qse_awk_nde_t* nde)
if (call->nargs < call->what.fnc.arg.min) if (call->nargs < call->what.fnc.arg.min)
{ {
qse_awk_rtx_seterror ( qse_awk_rtx_seterror (
run, QSE_AWK_EARGTF, nde->line, QSE_NULL, 0); run, QSE_AWK_EARGTF, nde->line, QSE_NULL);
return QSE_NULL; return QSE_NULL;
} }
if (call->nargs > call->what.fnc.arg.max) if (call->nargs > call->what.fnc.arg.max)
{ {
qse_awk_rtx_seterror ( qse_awk_rtx_seterror (
run, QSE_AWK_EARGTM, nde->line, QSE_NULL, 0); run, QSE_AWK_EARGTM, nde->line, QSE_NULL);
return QSE_NULL; return QSE_NULL;
} }
@ -5400,7 +5395,7 @@ static qse_awk_val_t* eval_fun_ex (
errarg.len = call->what.fun.name.len, errarg.len = call->what.fun.name.len,
qse_awk_rtx_seterror (run, qse_awk_rtx_seterror (run,
QSE_AWK_EFUNNONE, nde->line, &errarg, 1); QSE_AWK_EFUNNONE, nde->line, &errarg);
return QSE_NULL; return QSE_NULL;
} }
@ -5412,7 +5407,7 @@ static qse_awk_val_t* eval_fun_ex (
/* TODO: is this correct? what if i want to /* TODO: is this correct? what if i want to
* allow arbitarary numbers of arguments? */ * allow arbitarary numbers of arguments? */
qse_awk_rtx_seterror ( qse_awk_rtx_seterror (
run, QSE_AWK_EARGTM, nde->line, QSE_NULL, 0); run, QSE_AWK_EARGTM, nde->line, QSE_NULL);
return QSE_NULL; return QSE_NULL;
} }
@ -5522,7 +5517,7 @@ static qse_awk_val_t* __eval_call (
if (__raw_push(run,(void*)run->stack_base) == -1) if (__raw_push(run,(void*)run->stack_base) == -1)
{ {
qse_awk_rtx_seterror ( qse_awk_rtx_seterror (
run, QSE_AWK_ENOMEM, nde->line, QSE_NULL, 0); run, QSE_AWK_ENOMEM, nde->line, QSE_NULL);
return QSE_NULL; return QSE_NULL;
} }
@ -5530,7 +5525,7 @@ static qse_awk_val_t* __eval_call (
{ {
__raw_pop (run); __raw_pop (run);
qse_awk_rtx_seterror ( qse_awk_rtx_seterror (
run, QSE_AWK_ENOMEM, nde->line, QSE_NULL, 0); run, QSE_AWK_ENOMEM, nde->line, QSE_NULL);
return QSE_NULL; return QSE_NULL;
} }
@ -5540,7 +5535,7 @@ static qse_awk_val_t* __eval_call (
__raw_pop (run); __raw_pop (run);
__raw_pop (run); __raw_pop (run);
qse_awk_rtx_seterror ( qse_awk_rtx_seterror (
run, QSE_AWK_ENOMEM, nde->line, QSE_NULL, 0); run, QSE_AWK_ENOMEM, nde->line, QSE_NULL);
return QSE_NULL; return QSE_NULL;
} }
@ -5551,7 +5546,7 @@ static qse_awk_val_t* __eval_call (
__raw_pop (run); __raw_pop (run);
__raw_pop (run); __raw_pop (run);
qse_awk_rtx_seterror ( qse_awk_rtx_seterror (
run, QSE_AWK_ENOMEM, nde->line, QSE_NULL, 0); run, QSE_AWK_ENOMEM, nde->line, QSE_NULL);
return QSE_NULL; return QSE_NULL;
} }
@ -5577,7 +5572,7 @@ static qse_awk_val_t* __eval_call (
UNWIND_RTX_STACK (run, nargs); UNWIND_RTX_STACK (run, nargs);
qse_awk_rtx_seterror ( qse_awk_rtx_seterror (
run, QSE_AWK_ENOMEM, nde->line, run, QSE_AWK_ENOMEM, nde->line,
QSE_NULL, 0); QSE_NULL);
return QSE_NULL; return QSE_NULL;
} }
@ -5627,7 +5622,7 @@ static qse_awk_val_t* __eval_call (
* fix it */ * fix it */
qse_awk_rtx_seterror ( qse_awk_rtx_seterror (
run, QSE_AWK_EFNCIMPL, run, QSE_AWK_EFNCIMPL,
nde->line, QSE_NULL, 0); nde->line, QSE_NULL);
} }
else else
{ {
@ -5714,7 +5709,7 @@ static qse_size_t push_arg_from_vals (qse_awk_rtx_t* rtx, qse_awk_nde_call_t* ca
UNWIND_RTX_STACK_ARG (rtx, nargs); UNWIND_RTX_STACK_ARG (rtx, nargs);
qse_awk_rtx_seterror ( qse_awk_rtx_seterror (
rtx, QSE_AWK_ENOMEM, call->line, QSE_NULL, 0); rtx, QSE_AWK_ENOMEM, call->line, QSE_NULL);
return (qse_size_t)-1; return (qse_size_t)-1;
} }
} }
@ -5781,7 +5776,7 @@ static qse_size_t push_arg_from_nde (qse_awk_rtx_t* rtx, qse_awk_nde_call_t* cal
UNWIND_RTX_STACK_ARG (rtx, nargs); UNWIND_RTX_STACK_ARG (rtx, nargs);
qse_awk_rtx_seterror ( qse_awk_rtx_seterror (
rtx, QSE_AWK_ENOMEM, call->line, QSE_NULL, 0); rtx, QSE_AWK_ENOMEM, call->line, QSE_NULL);
return (qse_size_t)-1; return (qse_size_t)-1;
} }
@ -5828,7 +5823,7 @@ static int get_reference (
{ {
qse_awk_rtx_seterror ( qse_awk_rtx_seterror (
run, QSE_AWK_ENOMEM, nde->line, run, QSE_AWK_ENOMEM, nde->line,
QSE_NULL, 0); QSE_NULL);
return -1; return -1;
} }
} }
@ -5870,7 +5865,7 @@ static int get_reference (
{ {
qse_awk_rtx_seterror ( qse_awk_rtx_seterror (
run, QSE_AWK_ENOMEM, nde->line, run, QSE_AWK_ENOMEM, nde->line,
QSE_NULL, 0); QSE_NULL);
return -1; return -1;
} }
} }
@ -5924,14 +5919,14 @@ static int get_reference (
if (n == -1) if (n == -1)
{ {
qse_awk_rtx_seterror ( qse_awk_rtx_seterror (
run, QSE_AWK_EPOSIDX, nde->line, QSE_NULL, 0); run, QSE_AWK_EPOSIDX, nde->line, QSE_NULL);
return -1; return -1;
} }
if (n == 1) lv = (qse_long_t)rv; if (n == 1) lv = (qse_long_t)rv;
if (!IS_VALID_POSIDX(lv)) if (!IS_VALID_POSIDX(lv))
{ {
qse_awk_rtx_seterror ( qse_awk_rtx_seterror (
run, QSE_AWK_EPOSIDX, nde->line, QSE_NULL, 0); run, QSE_AWK_EPOSIDX, nde->line, QSE_NULL);
return -1; return -1;
} }
@ -5939,7 +5934,7 @@ static int get_reference (
return 0; return 0;
} }
qse_awk_rtx_seterror (run, QSE_AWK_ENOTREF, nde->line, QSE_NULL, 0); qse_awk_rtx_seterror (run, QSE_AWK_ENOTREF, nde->line, QSE_NULL);
return -1; return -1;
} }
@ -5971,7 +5966,7 @@ static qse_awk_val_t** get_reference_indexed (
else if ((*val)->type != QSE_AWK_VAL_MAP) else if ((*val)->type != QSE_AWK_VAL_MAP)
{ {
qse_awk_rtx_seterror ( qse_awk_rtx_seterror (
run, QSE_AWK_ENOTMAP, nde->line, QSE_NULL, 0); run, QSE_AWK_ENOTMAP, nde->line, QSE_NULL);
return QSE_NULL; return QSE_NULL;
} }
@ -5995,7 +5990,7 @@ static qse_awk_val_t** get_reference_indexed (
{ {
if (str != idxbuf) QSE_AWK_FREE (run->awk, str); if (str != idxbuf) QSE_AWK_FREE (run->awk, str);
qse_awk_rtx_seterror ( qse_awk_rtx_seterror (
run, QSE_AWK_ENOMEM, nde->line, QSE_NULL, 0); run, QSE_AWK_ENOMEM, nde->line, QSE_NULL);
return QSE_NULL; return QSE_NULL;
} }
@ -6123,7 +6118,7 @@ static qse_awk_val_t* eval_indexed (
else if ((*val)->type != QSE_AWK_VAL_MAP) else if ((*val)->type != QSE_AWK_VAL_MAP)
{ {
qse_awk_rtx_seterror ( qse_awk_rtx_seterror (
run, QSE_AWK_ENOTMAP, nde->line, QSE_NULL, 0); run, QSE_AWK_ENOTMAP, nde->line, QSE_NULL);
return QSE_NULL; return QSE_NULL;
} }
@ -6157,7 +6152,7 @@ static qse_awk_val_t* eval_namedidx (qse_awk_rtx_t* run, qse_awk_nde_t* nde)
if (pair == QSE_NULL) if (pair == QSE_NULL)
{ {
qse_awk_rtx_seterror ( qse_awk_rtx_seterror (
run, QSE_AWK_ENOMEM, nde->line, QSE_NULL, 0); run, QSE_AWK_ENOMEM, nde->line, QSE_NULL);
return QSE_NULL; return QSE_NULL;
} }
@ -6202,7 +6197,7 @@ static qse_awk_val_t* eval_pos (qse_awk_rtx_t* run, qse_awk_nde_t* nde)
if (n == -1) if (n == -1)
{ {
qse_awk_rtx_seterror ( qse_awk_rtx_seterror (
run, QSE_AWK_EPOSIDX, nde->line, QSE_NULL, 0); run, QSE_AWK_EPOSIDX, nde->line, QSE_NULL);
return QSE_NULL; return QSE_NULL;
} }
if (n == 1) lv = (qse_long_t)rv; if (n == 1) lv = (qse_long_t)rv;
@ -6210,7 +6205,7 @@ static qse_awk_val_t* eval_pos (qse_awk_rtx_t* run, qse_awk_nde_t* nde)
if (lv < 0) if (lv < 0)
{ {
qse_awk_rtx_seterror ( qse_awk_rtx_seterror (
run, QSE_AWK_EPOSIDX, nde->line, QSE_NULL, 0); run, QSE_AWK_EPOSIDX, nde->line, QSE_NULL);
return QSE_NULL; return QSE_NULL;
} }
if (lv == 0) v = run->inrec.d0; if (lv == 0) v = run->inrec.d0;
@ -6289,7 +6284,7 @@ static qse_awk_val_t* eval_getline (qse_awk_rtx_t* run, qse_awk_nde_t* nde)
{ {
if (in != QSE_NULL) QSE_AWK_FREE (run->awk, in); if (in != QSE_NULL) QSE_AWK_FREE (run->awk, in);
qse_awk_rtx_seterror ( qse_awk_rtx_seterror (
run, QSE_AWK_ENOMEM, nde->line, QSE_NULL, 0); run, QSE_AWK_ENOMEM, nde->line, QSE_NULL);
return QSE_NULL; return QSE_NULL;
} }
@ -6560,7 +6555,7 @@ static qse_char_t* idxnde_to_str (
if (qse_str_init (&idxstr, MMGR(run), DEF_BUF_CAPA) == QSE_NULL) if (qse_str_init (&idxstr, MMGR(run), DEF_BUF_CAPA) == QSE_NULL)
{ {
qse_awk_rtx_seterror ( qse_awk_rtx_seterror (
run, QSE_AWK_ENOMEM, nde->line, QSE_NULL, 0); run, QSE_AWK_ENOMEM, nde->line, QSE_NULL);
return QSE_NULL; return QSE_NULL;
} }
@ -6584,8 +6579,7 @@ static qse_char_t* idxnde_to_str (
qse_str_fini (&idxstr); qse_str_fini (&idxstr);
qse_awk_rtx_seterror ( qse_awk_rtx_seterror (
run, QSE_AWK_ENOMEM, nde->line, run, QSE_AWK_ENOMEM, nde->line, QSE_NULL);
QSE_NULL, 0);
return QSE_NULL; return QSE_NULL;
} }
@ -6612,7 +6606,7 @@ static qse_char_t* idxnde_to_str (
return str; return str;
} }
qse_char_t* qse_awk_format ( qse_char_t* qse_awk_rtx_format (
qse_awk_rtx_t* run, qse_str_t* out, qse_str_t* fbu, qse_awk_rtx_t* run, qse_str_t* out, qse_str_t* fbu,
const qse_char_t* fmt, qse_size_t fmt_len, const qse_char_t* fmt, qse_size_t fmt_len,
qse_size_t nargs_on_stack, qse_awk_nde_t* args, qse_size_t* len) qse_size_t nargs_on_stack, qse_awk_nde_t* args, qse_size_t* len)

View File

@ -95,7 +95,7 @@ enum qse_awk_incop_type_t
extern "C" { extern "C" {
#endif #endif
qse_char_t* qse_awk_format ( qse_char_t* qse_awk_rtx_format (
qse_awk_rtx_t* run, qse_awk_rtx_t* run,
qse_str_t* out, qse_str_t* out,
qse_str_t* fbu, qse_str_t* fbu,

View File

@ -469,7 +469,7 @@ static qse_ssize_t awk_eio_file (
errarg.ptr = epa->name; errarg.ptr = epa->name;
errarg.len = qse_strlen(epa->name); errarg.len = qse_strlen(epa->name);
qse_awk_rtx_seterror (epa->rtx, QSE_AWK_EOPEN, 0, &errarg, 1); qse_awk_rtx_seterror (epa->rtx, QSE_AWK_EOPEN, 0, &errarg);
return -1; return -1;
} }
@ -557,7 +557,7 @@ static int open_eio_console (qse_awk_eio_t* epa)
errarg.ptr = rd->ic.files[rd->ic.index]; errarg.ptr = rd->ic.files[rd->ic.index];
errarg.len = qse_strlen(rd->ic.files[rd->ic.index]); errarg.len = qse_strlen(rd->ic.files[rd->ic.index]);
qse_awk_rtx_seterror (epa->rtx, QSE_AWK_EOPEN, 0, &errarg, 1); qse_awk_rtx_seterror (epa->rtx, QSE_AWK_EOPEN, 0, &errarg);
return -1; return -1;
} }
@ -660,7 +660,7 @@ static qse_ssize_t awk_eio_console (
errarg.ptr = rd->ic.files[rd->ic.index]; errarg.ptr = rd->ic.files[rd->ic.index];
errarg.len = qse_strlen(rd->ic.files[rd->ic.index]); errarg.len = qse_strlen(rd->ic.files[rd->ic.index]);
qse_awk_rtx_seterror (epa->rtx, QSE_AWK_EOPEN, 0, &errarg, 1); qse_awk_rtx_seterror (epa->rtx, QSE_AWK_EOPEN, 0, &errarg);
return -1; return -1;
} }

View File

@ -805,7 +805,7 @@ qse_char_t* qse_awk_rtx_valtostr (
v->type); v->type);
#endif #endif
qse_awk_rtx_seterror (run, QSE_AWK_EVALTYPE, 0, QSE_NULL, 0); qse_awk_rtx_seterror (run, QSE_AWK_EVALTYPE, 0, QSE_NULL);
return QSE_NULL; return QSE_NULL;
} }
@ -819,8 +819,7 @@ static qse_char_t* str_to_str (
tmp = QSE_AWK_STRXDUP (run->awk, str, str_len); tmp = QSE_AWK_STRXDUP (run->awk, str, str_len);
if (tmp == QSE_NULL) if (tmp == QSE_NULL)
{ {
qse_awk_rtx_seterror ( qse_awk_rtx_seterror (run, QSE_AWK_ENOMEM, 0, QSE_NULL);
run, QSE_AWK_ENOMEM, 0, QSE_NULL, 0);
return QSE_NULL; return QSE_NULL;
} }
@ -833,8 +832,7 @@ static qse_char_t* str_to_str (
if (str_len >= *len) if (str_len >= *len)
{ {
qse_awk_rtx_seterror ( qse_awk_rtx_seterror (run, QSE_AWK_EINVAL, 0, QSE_NULL);
run, QSE_AWK_EINVAL, 0, QSE_NULL, 0);
*len = str_len + 1; *len = str_len + 1;
return QSE_NULL; return QSE_NULL;
} }
@ -850,8 +848,7 @@ static qse_char_t* str_to_str (
n = qse_str_ncat (buf, str, str_len); n = qse_str_ncat (buf, str, str_len);
if (n == (qse_size_t)-1) if (n == (qse_size_t)-1)
{ {
qse_awk_rtx_seterror ( qse_awk_rtx_seterror (run, QSE_AWK_ENOMEM, 0, QSE_NULL);
run, QSE_AWK_ENOMEM, 0, QSE_NULL, 0);
return QSE_NULL; return QSE_NULL;
} }
@ -879,7 +876,7 @@ static qse_char_t* val_int_to_str (
if (tmp == QSE_NULL) if (tmp == QSE_NULL)
{ {
qse_awk_rtx_seterror ( qse_awk_rtx_seterror (
run, QSE_AWK_ENOMEM, 0, QSE_NULL, 0); run, QSE_AWK_ENOMEM, 0, QSE_NULL);
return QSE_NULL; return QSE_NULL;
} }
@ -895,7 +892,7 @@ static qse_char_t* val_int_to_str (
if (1 >= *len) if (1 >= *len)
{ {
qse_awk_rtx_seterror ( qse_awk_rtx_seterror (
run, QSE_AWK_EINVAL, 0, QSE_NULL, 0); run, QSE_AWK_EINVAL, 0, QSE_NULL);
*len = 2; /* buffer size required */ *len = 2; /* buffer size required */
return QSE_NULL; return QSE_NULL;
} }
@ -912,7 +909,7 @@ static qse_char_t* val_int_to_str (
if (qse_str_cat (buf, QSE_T("0")) == (qse_size_t)-1) if (qse_str_cat (buf, QSE_T("0")) == (qse_size_t)-1)
{ {
qse_awk_rtx_seterror ( qse_awk_rtx_seterror (
run, QSE_AWK_ENOMEM, 0, QSE_NULL, 0); run, QSE_AWK_ENOMEM, 0, QSE_NULL);
return QSE_NULL; return QSE_NULL;
} }
@ -931,8 +928,7 @@ static qse_char_t* val_int_to_str (
run->awk, (rlen + 1) * QSE_SIZEOF(qse_char_t)); run->awk, (rlen + 1) * QSE_SIZEOF(qse_char_t));
if (tmp == QSE_NULL) if (tmp == QSE_NULL)
{ {
qse_awk_rtx_seterror ( qse_awk_rtx_seterror (run, QSE_AWK_ENOMEM, 0, QSE_NULL);
run, QSE_AWK_ENOMEM, 0, QSE_NULL, 0);
return QSE_NULL; return QSE_NULL;
} }
@ -945,8 +941,7 @@ static qse_char_t* val_int_to_str (
if (rlen >= *len) if (rlen >= *len)
{ {
qse_awk_rtx_seterror ( qse_awk_rtx_seterror (run, QSE_AWK_EINVAL, 0, QSE_NULL);
run, QSE_AWK_EINVAL, 0, QSE_NULL, 0);
*len = rlen + 1; /* buffer size required */ *len = rlen + 1; /* buffer size required */
return QSE_NULL; return QSE_NULL;
} }
@ -967,7 +962,7 @@ static qse_char_t* val_int_to_str (
buf, QSE_T(' '), rlen) == (qse_size_t)-1) buf, QSE_T(' '), rlen) == (qse_size_t)-1)
{ {
qse_awk_rtx_seterror ( qse_awk_rtx_seterror (
run, QSE_AWK_ENOMEM, 0, QSE_NULL, 0); run, QSE_AWK_ENOMEM, 0, QSE_NULL);
return QSE_NULL; return QSE_NULL;
} }
} }
@ -1013,18 +1008,18 @@ static qse_char_t* val_real_to_str (
if (qse_str_init (&out, run->awk->mmgr, 256) == QSE_NULL) if (qse_str_init (&out, run->awk->mmgr, 256) == QSE_NULL)
{ {
qse_awk_rtx_seterror (run, QSE_AWK_ENOMEM, 0, QSE_NULL, 0); qse_awk_rtx_seterror (run, QSE_AWK_ENOMEM, 0, QSE_NULL);
return QSE_NULL; return QSE_NULL;
} }
if (qse_str_init (&fbu, run->awk->mmgr, 256) == QSE_NULL) if (qse_str_init (&fbu, run->awk->mmgr, 256) == QSE_NULL)
{ {
qse_str_fini (&out); qse_str_fini (&out);
qse_awk_rtx_seterror (run, QSE_AWK_ENOMEM, 0, QSE_NULL, 0); qse_awk_rtx_seterror (run, QSE_AWK_ENOMEM, 0, QSE_NULL);
return QSE_NULL; return QSE_NULL;
} }
tmp = qse_awk_format (run, &out, &fbu, tmp, tmp_len, tmp = qse_awk_rtx_format (run, &out, &fbu, tmp, tmp_len,
(qse_size_t)-1, (qse_awk_nde_t*)v, &tmp_len); (qse_size_t)-1, (qse_awk_nde_t*)v, &tmp_len);
if (tmp == QSE_NULL) if (tmp == QSE_NULL)
{ {
@ -1049,7 +1044,7 @@ static qse_char_t* val_real_to_str (
if (tmp_len >= *len) if (tmp_len >= *len)
{ {
qse_awk_rtx_seterror ( qse_awk_rtx_seterror (
run, QSE_AWK_EINVAL, 0, QSE_NULL, 0); run, QSE_AWK_EINVAL, 0, QSE_NULL);
*len = tmp_len + 1; /* buffer size required */ *len = tmp_len + 1; /* buffer size required */
qse_str_close (&fbu); qse_str_close (&fbu);
qse_str_close (&out); qse_str_close (&out);
@ -1072,7 +1067,7 @@ static qse_char_t* val_real_to_str (
qse_str_fini (&fbu); qse_str_fini (&fbu);
qse_str_fini (&out); qse_str_fini (&out);
qse_awk_rtx_seterror ( qse_awk_rtx_seterror (
run, QSE_AWK_ENOMEM, 0, QSE_NULL, 0); run, QSE_AWK_ENOMEM, 0, QSE_NULL);
return QSE_NULL; return QSE_NULL;
} }
@ -1120,7 +1115,7 @@ int qse_awk_rtx_valtonum (
v->type); v->type);
#endif #endif
qse_awk_rtx_seterror (run, QSE_AWK_EVALTYPE, 0, QSE_NULL, 0); qse_awk_rtx_seterror (run, QSE_AWK_EVALTYPE, 0, QSE_NULL);
return -1; /* error */ return -1; /* error */
} }

View File

@ -159,6 +159,52 @@ qse_size_t qse_strfcpy (qse_char_t* buf, const qse_char_t* fmt, ...)
return b - buf; return b - buf;
} }
qse_size_t qse_strfncpy (qse_char_t* buf, const qse_char_t* fmt, const qse_cstr_t* str)
{
qse_char_t* b = buf;
const qse_char_t* f = fmt;
while (*f != QSE_T('\0'))
{
if (*f == QSE_T('$'))
{
if (f[1] == QSE_T('{') &&
(f[2] >= QSE_T('0') && f[2] <= QSE_T('9')))
{
const qse_char_t* tmp, * tmpend;
qse_size_t idx = 0;
tmp = f;
f += 2;
do idx = idx * 10 + (*f++ - QSE_T('0'));
while (*f >= QSE_T('0') && *f <= QSE_T('9'));
if (*f != QSE_T('}'))
{
f = tmp;
goto normal;
}
f++;
tmp = str[idx].ptr;
tmpend = tmp + str[idx].len;
while (tmp < tmpend) *b++ = *tmp++;
continue;
}
else if (f[1] == QSE_T('$')) f++;
}
normal:
*b++ = *f++;
}
*b = QSE_T('\0');
return b - buf;
}
qse_size_t qse_strxfcpy ( qse_size_t qse_strxfcpy (
qse_char_t* buf, qse_size_t bsz, const qse_char_t* fmt, ...) qse_char_t* buf, qse_size_t bsz, const qse_char_t* fmt, ...)
{ {
@ -221,6 +267,63 @@ fini:
return b - buf; return b - buf;
} }
qse_size_t qse_strxfncpy (
qse_char_t* buf, qse_size_t bsz,
const qse_char_t* fmt, const qse_cstr_t* str)
{
qse_char_t* b = buf;
qse_char_t* end = buf + bsz - 1;
const qse_char_t* f = fmt;
if (bsz <= 0) return 0;
while (*f != QSE_T('\0'))
{
if (*f == QSE_T('$'))
{
if (f[1] == QSE_T('{') &&
(f[2] >= QSE_T('0') && f[2] <= QSE_T('9')))
{
const qse_char_t* tmp, * tmpend;
qse_size_t idx = 0;
tmp = f;
f += 2;
do idx = idx * 10 + (*f++ - QSE_T('0'));
while (*f >= QSE_T('0') && *f <= QSE_T('9'));
if (*f != QSE_T('}'))
{
f = tmp;
goto normal;
}
f++;
tmp = str[idx].ptr;
tmpend = tmp + str[idx].len;
while (tmp < tmpend)
{
if (b >= end) goto fini;
*b++ = *tmp++;
}
continue;
}
else if (f[1] == QSE_T('$')) f++;
}
normal:
if (b >= end) break;
*b++ = *f++;
}
fini:
*b = QSE_T('\0');
return b - buf;
}
qse_size_t qse_strxcat (qse_char_t* buf, qse_size_t bsz, const qse_char_t* str) qse_size_t qse_strxcat (qse_char_t* buf, qse_size_t bsz, const qse_char_t* str)
{ {
qse_char_t* p, * p2; qse_char_t* p, * p2;