added qse_awk_rtx_valtombs()/qse_awk_rtx_valtostr()

added sys::kill() to awk
added sys::SIGXXXX to awk
added or enhanced uci::XXXX in awk
This commit is contained in:
hyung-hwan 2012-10-31 08:31:58 +00:00
parent 3db3ab2249
commit a3af4c3eed
14 changed files with 935 additions and 429 deletions

View File

@ -251,7 +251,7 @@ static qse_htb_walk_t print_awk_value (
qse_awk_rtx_geterrinf (rtx, &oerrinf); qse_awk_rtx_geterrinf (rtx, &oerrinf);
str = qse_awk_rtx_valtocpldup (rtx, QSE_HTB_VPTR(pair), &len); str = qse_awk_rtx_valtostrdup (rtx, QSE_HTB_VPTR(pair), &len);
if (str == QSE_NULL) if (str == QSE_NULL)
{ {
if (qse_awk_rtx_geterrnum(rtx) == QSE_AWK_EVALTYPE) if (qse_awk_rtx_geterrnum(rtx) == QSE_AWK_EVALTYPE)
@ -333,7 +333,7 @@ static void dprint_return (qse_awk_rtx_t* rtx, qse_awk_val_t* ret)
} }
else else
{ {
str = qse_awk_rtx_valtocpldup (rtx, ret, &len); str = qse_awk_rtx_valtostrdup (rtx, ret, &len);
if (str == QSE_NULL) if (str == QSE_NULL)
{ {
dprint (QSE_T("[RETURN] - ***OUT OF MEMORY***\n")); dprint (QSE_T("[RETURN] - ***OUT OF MEMORY***\n"));
@ -1071,6 +1071,9 @@ static int awk_main (int argc, qse_char_t* argv[])
retv = arg.call? retv = arg.call?
qse_awk_rtx_callwithstrs (rtx, arg.call, arg.icf.ptr, arg.icf.size): qse_awk_rtx_callwithstrs (rtx, arg.call, arg.icf.ptr, arg.icf.size):
qse_awk_rtx_loop (rtx); qse_awk_rtx_loop (rtx);
unset_intr_run ();
if (retv) if (retv)
{ {
qse_long_t tmp; qse_long_t tmp;
@ -1081,10 +1084,7 @@ static int awk_main (int argc, qse_char_t* argv[])
ret = 0; ret = 0;
if (qse_awk_rtx_valtolong (rtx, retv, &tmp) >= 0) ret = tmp; if (qse_awk_rtx_valtolong (rtx, retv, &tmp) >= 0) ret = tmp;
} }
else
unset_intr_run ();
if (ret <= -1)
{ {
print_rtxerr (rtx); print_rtxerr (rtx);
goto oops; goto oops;

View File

@ -1960,6 +1960,15 @@ qse_awk_val_t* qse_awk_rtx_getarg (
qse_size_t idx qse_size_t idx
); );
/**
* The qse_awk_rtx_getsubsep() function returns the
* pointer to the internal value of SUBSEP. It's a specialized
* version of qse_awk_rtx_getgbl (rtx, QSE_AWK_GBL_SUBSEP).
*/
const qse_xstr_t* qse_awk_rtx_getsubsep (
qse_awk_rtx_t* rtx /**< runtime context */
);
/** /**
* The qse_awk_rtx_getgbl() gets the value of a global variable. * The qse_awk_rtx_getgbl() gets the value of a global variable.
* The global variable ID @a id is one of the predefined global * The global variable ID @a id is one of the predefined global
@ -2473,14 +2482,14 @@ int qse_awk_rtx_valtostr (
); );
/** /**
* The qse_awk_rtx_valtocpldup() function provides a shortcut to the * The qse_awk_rtx_valtostrdup() function provides a shortcut to the
* qse_awk_rtx_valtostr() function with the #QSE_AWK_RTX_VALTOSTR_CPLDUP type. * qse_awk_rtx_valtostr() function with the #QSE_AWK_RTX_VALTOSTR_CPLDUP type.
* It returns the pointer to a string converted from @a val and stores its * It returns the pointer to a string converted from @a val and stores its
* length to memory pointed to by @a len. You should free the returned * length to memory pointed to by @a len. You should free the returned
* memory block after use. See the code snippet below for a simple usage. * memory block after use. See the code snippet below for a simple usage.
* *
* @code * @code
* ptr = qse_awk_rtx_valtocpldup (rtx, v, &len); * ptr = qse_awk_rtx_valtostrdup (rtx, v, &len);
* if (str == QSE_NULL) handle_error(); * if (str == QSE_NULL) handle_error();
* qse_printf (QSE_T("%.*s\n"), (int)len, ptr); * qse_printf (QSE_T("%.*s\n"), (int)len, ptr);
* qse_awk_rtx_free (rtx, ptr); * qse_awk_rtx_free (rtx, ptr);
@ -2489,7 +2498,19 @@ int qse_awk_rtx_valtostr (
* @return character pointer to a string converted on success, * @return character pointer to a string converted on success,
* #QSE_NULL on failure * #QSE_NULL on failure
*/ */
qse_char_t* qse_awk_rtx_valtocpldup ( qse_char_t* qse_awk_rtx_valtostrdup (
qse_awk_rtx_t* rtx, /**< runtime context */
const qse_awk_val_t* val, /**< value to convert */
qse_size_t* len /**< result length */
);
qse_mchar_t* qse_awk_rtx_valtombsdup (
qse_awk_rtx_t* rtx, /**< runtime context */
const qse_awk_val_t* val, /**< value to convert */
qse_size_t* len /**< result length */
);
qse_wchar_t* qse_awk_rtx_valtowcsdup (
qse_awk_rtx_t* rtx, /**< runtime context */ qse_awk_rtx_t* rtx, /**< runtime context */
const qse_awk_val_t* val, /**< value to convert */ const qse_awk_val_t* val, /**< value to convert */
qse_size_t* len /**< result length */ qse_size_t* len /**< result length */

View File

@ -298,31 +298,11 @@ struct qse_awk_rtx_t
qse_long_t nr; qse_long_t nr;
qse_long_t fnr; qse_long_t fnr;
struct qse_xstr_t convfmt;
{ qse_xstr_t ofmt;
qse_char_t* ptr; qse_xstr_t ofs;
qse_size_t len; qse_xstr_t ors;
} convfmt; qse_xstr_t subsep;
struct
{
qse_char_t* ptr;
qse_size_t len;
} ofmt;
struct
{
qse_char_t* ptr;
qse_size_t len;
} ofs;
struct
{
qse_char_t* ptr;
qse_size_t len;
} ors;
struct
{
qse_char_t* ptr;
qse_size_t len;
} subsep;
} gbl; } gbl;
/* rio chain */ /* rio chain */

View File

@ -245,7 +245,7 @@ static int fnc_close (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi)
} }
else else
{ {
name = qse_awk_rtx_valtocpldup (rtx, a0, &len); name = qse_awk_rtx_valtostrdup (rtx, a0, &len);
if (name == QSE_NULL) return -1; if (name == QSE_NULL) return -1;
} }
@ -258,7 +258,7 @@ static int fnc_close (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi)
} }
else else
{ {
opt = qse_awk_rtx_valtocpldup (rtx, a1, &optlen); opt = qse_awk_rtx_valtostrdup (rtx, a1, &optlen);
if (opt == QSE_NULL) if (opt == QSE_NULL)
{ {
if (a1->type != QSE_AWK_VAL_STR) if (a1->type != QSE_AWK_VAL_STR)
@ -386,7 +386,7 @@ static int fnc_fflush (qse_awk_rtx_t* run, const qse_awk_fnc_info_t* fi)
} }
else else
{ {
str0 = qse_awk_rtx_valtocpldup (run, a0, &len0); str0 = qse_awk_rtx_valtostrdup (run, a0, &len0);
if (str0 == QSE_NULL) return -1; if (str0 == QSE_NULL) return -1;
} }
@ -462,7 +462,7 @@ static int fnc_index (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi)
} }
else else
{ {
str0 = qse_awk_rtx_valtocpldup (rtx, a0, &len0); str0 = qse_awk_rtx_valtostrdup (rtx, a0, &len0);
if (str0 == QSE_NULL) return -1; if (str0 == QSE_NULL) return -1;
} }
@ -473,7 +473,7 @@ static int fnc_index (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi)
} }
else else
{ {
str1 = qse_awk_rtx_valtocpldup (rtx, a1, &len1); str1 = qse_awk_rtx_valtostrdup (rtx, a1, &len1);
if (str1 == QSE_NULL) if (str1 == QSE_NULL)
{ {
if (a0->type != QSE_AWK_VAL_STR) if (a0->type != QSE_AWK_VAL_STR)
@ -526,7 +526,7 @@ static int fnc_length (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi)
} }
else else
{ {
str = qse_awk_rtx_valtocpldup (rtx, v, &len); str = qse_awk_rtx_valtostrdup (rtx, v, &len);
if (str == QSE_NULL) return -1; if (str == QSE_NULL) return -1;
QSE_AWK_FREE (rtx->awk, str); QSE_AWK_FREE (rtx->awk, str);
} }
@ -562,7 +562,7 @@ static int fnc_substr (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi)
} }
else else
{ {
str = qse_awk_rtx_valtocpldup (rtx, a0, &len); str = qse_awk_rtx_valtostrdup (rtx, a0, &len);
if (str == QSE_NULL) return -1; if (str == QSE_NULL) return -1;
} }
@ -667,7 +667,7 @@ static int fnc_split (qse_awk_rtx_t* run, const qse_awk_fnc_info_t* fi)
} }
else else
{ {
str.ptr = qse_awk_rtx_valtocpldup (run, a0, &str.len); str.ptr = qse_awk_rtx_valtostrdup (run, a0, &str.len);
if (str.ptr == QSE_NULL) return -1; if (str.ptr == QSE_NULL) return -1;
str_free = (qse_char_t*)str.ptr; str_free = (qse_char_t*)str.ptr;
} }
@ -688,7 +688,7 @@ static int fnc_split (qse_awk_rtx_t* run, const qse_awk_fnc_info_t* fi)
} }
else else
{ {
fs.ptr = qse_awk_rtx_valtocpldup (run, t1, &fs.len); fs.ptr = qse_awk_rtx_valtostrdup (run, t1, &fs.len);
if (fs.ptr == QSE_NULL) goto oops; if (fs.ptr == QSE_NULL) goto oops;
fs_free = (qse_char_t*)fs.ptr; fs_free = (qse_char_t*)fs.ptr;
} }
@ -714,7 +714,7 @@ static int fnc_split (qse_awk_rtx_t* run, const qse_awk_fnc_info_t* fi)
} }
else else
{ {
fs.ptr = qse_awk_rtx_valtocpldup (run, a2, &fs.len); fs.ptr = qse_awk_rtx_valtostrdup (run, a2, &fs.len);
if (fs.ptr == QSE_NULL) goto oops; if (fs.ptr == QSE_NULL) goto oops;
fs_free = (qse_char_t*)fs.ptr; fs_free = (qse_char_t*)fs.ptr;
} }
@ -831,7 +831,7 @@ static int fnc_tolower (qse_awk_rtx_t* run, const qse_awk_fnc_info_t* fi)
} }
else else
{ {
str.ptr = qse_awk_rtx_valtocpldup (run, a0, &str.len); str.ptr = qse_awk_rtx_valtostrdup (run, a0, &str.len);
if (str.ptr == QSE_NULL) return -1; if (str.ptr == QSE_NULL) return -1;
} }
@ -868,7 +868,7 @@ static int fnc_toupper (qse_awk_rtx_t* run, const qse_awk_fnc_info_t* fi)
} }
else else
{ {
str.ptr = qse_awk_rtx_valtocpldup (run, a0, &str.len); str.ptr = qse_awk_rtx_valtostrdup (run, a0, &str.len);
if (str.ptr == QSE_NULL) return -1; if (str.ptr == QSE_NULL) return -1;
} }
@ -928,7 +928,7 @@ static int __substitute (qse_awk_rtx_t* run, qse_long_t max_count)
} }
else else
{ {
s0.ptr = qse_awk_rtx_valtocpldup (run, a0, &s0.len); s0.ptr = qse_awk_rtx_valtostrdup (run, a0, &s0.len);
if (s0.ptr == QSE_NULL) goto oops; if (s0.ptr == QSE_NULL) goto oops;
s0_free = (qse_char_t*)s0.ptr; s0_free = (qse_char_t*)s0.ptr;
} }
@ -940,7 +940,7 @@ static int __substitute (qse_awk_rtx_t* run, qse_long_t max_count)
} }
else else
{ {
s1.ptr = qse_awk_rtx_valtocpldup (run, a1, &s1.len); s1.ptr = qse_awk_rtx_valtostrdup (run, a1, &s1.len);
if (s1.ptr == QSE_NULL) goto oops; if (s1.ptr == QSE_NULL) goto oops;
s1_free = (qse_char_t*)s1.ptr; s1_free = (qse_char_t*)s1.ptr;
} }
@ -990,7 +990,7 @@ static int __substitute (qse_awk_rtx_t* run, qse_long_t max_count)
} }
else else
{ {
s2.ptr = qse_awk_rtx_valtocpldup (run, *a2_ref, &s2.len); s2.ptr = qse_awk_rtx_valtostrdup (run, *a2_ref, &s2.len);
if (s2.ptr == QSE_NULL) goto oops; if (s2.ptr == QSE_NULL) goto oops;
s2_free = (qse_char_t*)s2.ptr; s2_free = (qse_char_t*)s2.ptr;
} }
@ -1241,7 +1241,7 @@ static int fnc_match (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi)
} }
else else
{ {
str0 = qse_awk_rtx_valtocpldup (rtx, a0, &len0); str0 = qse_awk_rtx_valtostrdup (rtx, a0, &len0);
if (str0 == QSE_NULL) return -1; if (str0 == QSE_NULL) return -1;
} }
@ -1260,7 +1260,7 @@ static int fnc_match (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi)
} }
else else
{ {
str1 = qse_awk_rtx_valtocpldup (rtx, a1, &len1); str1 = qse_awk_rtx_valtostrdup (rtx, a1, &len1);
if (str1 == QSE_NULL) if (str1 == QSE_NULL)
{ {
if (a0->type != QSE_AWK_VAL_STR) if (a0->type != QSE_AWK_VAL_STR)
@ -1379,7 +1379,7 @@ static int fnc_sprintf (qse_awk_rtx_t* run, const qse_awk_fnc_info_t* fi)
} }
else else
{ {
cs0.ptr = qse_awk_rtx_valtocpldup (run, a0, &cs0.len); cs0.ptr = qse_awk_rtx_valtostrdup (run, a0, &cs0.len);
if (cs0.ptr == QSE_NULL) goto oops; if (cs0.ptr == QSE_NULL) goto oops;
} }

View File

@ -4948,6 +4948,7 @@ static qse_awk_nde_t* parse_primary_ident_segs (
if (mod == QSE_NULL) if (mod == QSE_NULL)
{ {
if (ISNOERR(awk)) SETERR_LOC (awk, QSE_AWK_ENOSUP, xloc); if (ISNOERR(awk)) SETERR_LOC (awk, QSE_AWK_ENOSUP, xloc);
else ADJERR_LOC (awk, xloc);
} }
else else
{ {

View File

@ -215,7 +215,7 @@ static QSE_INLINE int resolve_rs (
break; break;
default: default:
rrs->ptr = qse_awk_rtx_valtocpldup (rtx, rs, &rrs->len); rrs->ptr = qse_awk_rtx_valtostrdup (rtx, rs, &rrs->len);
if (rrs->ptr == QSE_NULL) ret = -1; if (rrs->ptr == QSE_NULL) ret = -1;
break; break;
} }

View File

@ -299,6 +299,11 @@ QSE_INLINE qse_awk_val_t* qse_awk_rtx_getgbl (qse_awk_rtx_t* run, int id)
return STACK_GBL (run, id); return STACK_GBL (run, id);
} }
const qse_xstr_t* qse_awk_rtx_getsubsep (qse_awk_rtx_t* run)
{
return &run->gbl.subsep;
}
/* internal function to set a value to a global variable. /* internal function to set a value to a global variable.
* this function can handle a few special global variables that * this function can handle a few special global variables that
* require special treatment. */ * require special treatment. */
@ -602,7 +607,7 @@ static int set_global (
out.type = QSE_AWK_RTX_VALTOSTR_CPLDUP; out.type = QSE_AWK_RTX_VALTOSTR_CPLDUP;
if (qse_awk_rtx_valtostr (rtx, val, &out) <= -1) return -1; if (qse_awk_rtx_valtostr (rtx, val, &out) <= -1) return -1;
if (rtx->gbl.subsep.ptr != QSE_NULL) if (rtx->gbl.subsep.ptr)
QSE_AWK_FREE (rtx->awk, rtx->gbl.subsep.ptr); QSE_AWK_FREE (rtx->awk, rtx->gbl.subsep.ptr);
rtx->gbl.subsep.ptr = out.u.cpldup.ptr; rtx->gbl.subsep.ptr = out.u.cpldup.ptr;
rtx->gbl.subsep.len = out.u.cpldup.len; rtx->gbl.subsep.len = out.u.cpldup.len;

View File

@ -2167,7 +2167,7 @@ static int fnc_system (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi)
} }
else else
{ {
str = qse_awk_rtx_valtocpldup (rtx, v, &len); str = qse_awk_rtx_valtostrdup (rtx, v, &len);
if (str == QSE_NULL) return -1; if (str == QSE_NULL) return -1;
} }
@ -2302,7 +2302,7 @@ static int fnc_setioattr (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi)
} }
else else
{ {
ptr[i] = qse_awk_rtx_valtocpldup (rtx, v[i], &len[i]); ptr[i] = qse_awk_rtx_valtostrdup (rtx, v[i], &len[i]);
if (ptr[i] == QSE_NULL) if (ptr[i] == QSE_NULL)
{ {
ret = -1; ret = -1;
@ -2431,7 +2431,7 @@ static int fnc_getioattr (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi)
} }
else else
{ {
ptr[i] = qse_awk_rtx_valtocpldup (rtx, v[i], &len[i]); ptr[i] = qse_awk_rtx_valtostrdup (rtx, v[i], &len[i]);
if (ptr[i] == QSE_NULL) if (ptr[i] == QSE_NULL)
{ {
ret = -1; ret = -1;

View File

@ -245,7 +245,7 @@ qse_awk_val_t* qse_awk_rtx_makestrvalwithmcstr (
return qse_awk_rtx_makestrvalwithcstr (rtx, mcstr); return qse_awk_rtx_makestrvalwithcstr (rtx, mcstr);
#else #else
qse_awk_val_t* v; qse_awk_val_t* v;
qse_wcstr_t tmp; qse_wxstr_t tmp;
qse_size_t mbslen; qse_size_t mbslen;
mbslen = mcstr->len; mbslen = mcstr->len;
@ -267,7 +267,7 @@ qse_awk_val_t* qse_awk_rtx_makestrvalwithwcstr (
{ {
#if defined(QSE_CHAR_IS_MCHAR) #if defined(QSE_CHAR_IS_MCHAR)
qse_awk_val_t* v; qse_awk_val_t* v;
qse_mcstr_t tmp; qse_mxstr_t tmp;
qse_size_t wcslen; qse_size_t wcslen;
wcslen = wcstr->len; wcslen = wcstr->len;
@ -1266,7 +1266,7 @@ int qse_awk_rtx_valtostr (
return -1; return -1;
} }
qse_char_t* qse_awk_rtx_valtocpldup ( qse_char_t* qse_awk_rtx_valtostrdup (
qse_awk_rtx_t* rtx, const qse_awk_val_t* v, qse_size_t* len) qse_awk_rtx_t* rtx, const qse_awk_val_t* v, qse_size_t* len)
{ {
qse_awk_rtx_valtostr_out_t out; qse_awk_rtx_valtostr_out_t out;
@ -1274,10 +1274,58 @@ qse_char_t* qse_awk_rtx_valtocpldup (
out.type = QSE_AWK_RTX_VALTOSTR_CPLDUP; out.type = QSE_AWK_RTX_VALTOSTR_CPLDUP;
if (qse_awk_rtx_valtostr (rtx, v, &out) <= -1) return QSE_NULL; if (qse_awk_rtx_valtostr (rtx, v, &out) <= -1) return QSE_NULL;
*len = out.u.cpldup.len; if (len) *len = out.u.cpldup.len;
return out.u.cpldup.ptr; return out.u.cpldup.ptr;
} }
qse_mchar_t* qse_awk_rtx_valtombsdup (
qse_awk_rtx_t* rtx, const qse_awk_val_t* v, qse_size_t* len)
{
#if defined(QSE_CHAR_IS_MCHAR)
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;
if (len) *len = out.u.cpldup.len;
return out.u.cpldup.ptr;
#else
qse_awk_rtx_valtostr_out_t out;
qse_mchar_t* mbs;
out.type = QSE_AWK_RTX_VALTOSTR_CPLDUP;
if (qse_awk_rtx_valtostr (rtx, v, &out) <= -1) return QSE_NULL;
mbs = qse_wcsntombsdup (out.u.cpldup.ptr, out.u.cpldup.len, len, rtx->awk->mmgr);
QSE_AWK_FREE (rtx->awk, out.u.cpldup.ptr);
return mbs;
#endif
}
qse_wchar_t* qse_awk_rtx_valtowcsdup (
qse_awk_rtx_t* rtx, const qse_awk_val_t* v, qse_size_t* len)
{
#if defined(QSE_CHAR_IS_MCHAR)
qse_awk_rtx_valtostr_out_t out;
qse_wchar_t* wcs;
out.type = QSE_AWK_RTX_VALTOSTR_CPLDUP;
if (qse_awk_rtx_valtostr (rtx, v, &out) <= -1) return QSE_NULL;
wcs = qse_mbsntombsdup (out.u.cpldup.ptr, out.u.cpldup.len, len, rtx->awk->mmgr);
QSE_AWK_FREE (rtx->awk, out.u.cpldup.ptr);
return wcs;
#else
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;
if (len) *len = out.u.cpldup.len;
return out.u.cpldup.ptr;
#endif
}
int qse_awk_rtx_valtonum ( int qse_awk_rtx_valtonum (
qse_awk_rtx_t* rtx, const qse_awk_val_t* v, qse_long_t* l, qse_flt_t* r) qse_awk_rtx_t* rtx, const qse_awk_val_t* v, qse_long_t* l, qse_flt_t* r)
{ {

View File

@ -13,64 +13,99 @@
# include <dos.h> # include <dos.h>
#else #else
# include <unistd.h> # include <unistd.h>
# include <signal.h>
# include <sys/wait.h> # include <sys/wait.h>
# include <errno.h> # include <errno.h>
#endif #endif
static int fnc_fork (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi) static int fnc_fork (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi)
{ {
#if defined(_WIN32) qse_long_t pid;
qse_awk_rtx_seterrnum (rtx, QSE_AWK_ENOIMPL, QSE_NULL);
return -1;
#elif defined(__OS2__)
qse_awk_rtx_seterrnum (rtx, QSE_AWK_ENOIMPL, QSE_NULL);
return -1;
#elif defined(__DOS__)
qse_awk_rtx_seterrnum (rtx, QSE_AWK_ENOIMPL, QSE_NULL);
return -1;
#else
pid_t pid;
qse_awk_val_t* retv; qse_awk_val_t* retv;
#if defined(_WIN32)
/* TOOD: implement this*/
pid = -1;
#elif defined(__OS2__)
/* TOOD: implement this*/
pid = -1;
#elif defined(__DOS__)
/* TOOD: implement this*/
pid = -1;
#else
pid = fork (); pid = fork ();
#endif
retv = qse_awk_rtx_makeintval (rtx, pid); retv = qse_awk_rtx_makeintval (rtx, pid);
if (retv == QSE_NULL) return -1; if (retv == QSE_NULL) return -1;
qse_awk_rtx_setretval (rtx, retv); qse_awk_rtx_setretval (rtx, retv);
return 0; return 0;
#endif
} }
static int fnc_wait (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi) static int fnc_wait (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi)
{ {
qse_long_t lv; qse_long_t pid;
qse_awk_val_t* retv; qse_awk_val_t* retv;
int n; int rx;
/* TODO: handle more parameters */ /* TODO: handle more parameters */
n = qse_awk_rtx_valtolong (rtx, qse_awk_rtx_getarg (rtx, 0), &lv); rx = qse_awk_rtx_valtolong (rtx, qse_awk_rtx_getarg (rtx, 0), &pid);
if (n <= -1) return -1; if (rx >= 0)
{
#if defined(_WIN32) #if defined(_WIN32)
qse_awk_rtx_seterrnum (rtx, QSE_AWK_ENOIMPL, QSE_NULL); /* TOOD: implement this*/
return -1; rx = -1;
#elif defined(__OS2__) #elif defined(__OS2__)
qse_awk_rtx_seterrnum (rtx, QSE_AWK_ENOIMPL, QSE_NULL); /* TOOD: implement this*/
return -1; rx = -1;
#elif defined(__DOS__) #elif defined(__DOS__)
qse_awk_rtx_seterrnum (rtx, QSE_AWK_ENOIMPL, QSE_NULL); /* TOOD: implement this*/
return -1; rx = -1;
#else #else
n = waitpid (lv, QSE_NULL, 0); rx = waitpid (pid, QSE_NULL, 0);
#endif #endif
}
retv = qse_awk_rtx_makeintval (rtx, n); retv = qse_awk_rtx_makeintval (rtx, rx);
if (retv == QSE_NULL) return -1;
qse_awk_rtx_setretval (rtx, retv);
return 0;
}
static int fnc_kill (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi)
{
qse_long_t pid, sig;
qse_awk_val_t* retv;
int rx;
if (qse_awk_rtx_valtolong (rtx, qse_awk_rtx_getarg (rtx, 0), &pid) <= -1 ||
qse_awk_rtx_valtolong (rtx, qse_awk_rtx_getarg (rtx, 1), &sig) <= -1)
{
rx = -1;
}
else
{
#if defined(_WIN32)
/* TOOD: implement this*/
rx = -1;
#elif defined(__OS2__)
/* TOOD: implement this*/
rx = -1;
#elif defined(__DOS__)
/* TOOD: implement this*/
rx = -1;
#else
rx = kill (pid, sig);
#endif
}
retv = qse_awk_rtx_makeintval (rtx, rx);
if (retv == QSE_NULL) return -1; if (retv == QSE_NULL) return -1;
qse_awk_rtx_setretval (rtx, retv); qse_awk_rtx_setretval (rtx, retv);
@ -81,25 +116,26 @@ static int fnc_sleep (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi)
{ {
qse_long_t lv; qse_long_t lv;
qse_awk_val_t* retv; qse_awk_val_t* retv;
int n; int rx;
n = qse_awk_rtx_valtolong ( rx = qse_awk_rtx_valtolong (
rtx, qse_awk_rtx_getarg (rtx, 0), &lv); rtx, qse_awk_rtx_getarg (rtx, 0), &lv);
if (n <= -1) return -1; if (rx >= 0)
{
#if defined(_WIN32) #if defined(_WIN32)
Sleep ((DWORD)(lv * 1000)); Sleep ((DWORD)(lv * 1000));
n = 0; rx = 0;
#elif defined(__OS2__) #elif defined(__OS2__)
DosSleep ((ULONG)(lv * 1000)); DosSleep ((ULONG)(lv * 1000));
n = 0; rx = 0;
#elif defined(__DOS__) #elif defined(__DOS__)
n = sleep (lv); rx = sleep (lv);
#else #else
n = sleep (lv); rx = sleep (lv);
#endif #endif
}
retv = qse_awk_rtx_makeintval (rtx, n); retv = qse_awk_rtx_makeintval (rtx, rx);
if (retv == QSE_NULL) return -1; if (retv == QSE_NULL) return -1;
qse_awk_rtx_setretval (rtx, retv); qse_awk_rtx_setretval (rtx, retv);
@ -123,13 +159,50 @@ struct inttab_t
static fnctab_t fnctab[] = static fnctab_t fnctab[] =
{ {
{ QSE_T("fork"), { { 0, 0 }, fnc_fork } }, { QSE_T("fork"), { { 0, 0 }, fnc_fork } },
{ QSE_T("kill"), { { 2, 2 }, fnc_kill } },
{ QSE_T("sleep"), { { 1, 1 }, fnc_sleep } }, { QSE_T("sleep"), { { 1, 1 }, fnc_sleep } },
{ QSE_T("wait"), { { 1, 1 }, fnc_wait } } { QSE_T("wait"), { { 1, 1 }, fnc_wait } }
}; };
#if !defined(SIGHUP)
# define SIGHUP 1
#endif
#if !defined(SIGINT)
# define SIGINT 2
#endif
#if !defined(SIGQUIT)
# define SIGQUIT 3
#endif
#if !defined(SIGABRT)
# define SIGABRT 6
#endif
#if !defined(SIGKILL)
# define SIGKILL 9
#endif
#if !defined(SIGSEGV)
# define SIGSEGV 11
#endif
#if !defined(SIGALRM)
# define SIGALRM 14
#endif
#if !defined(SIGTERM)
# define SIGKILL 15
#endif
static inttab_t inttab[] = static inttab_t inttab[] =
{ {
{ QSE_T("WNOHANG"), { WNOHANG } } { QSE_T("SIGABRT"), { SIGABRT } },
{ QSE_T("SIGALRM"), { SIGALRM } },
{ QSE_T("SIGHUP"), { SIGHUP } },
{ QSE_T("SIGINT"), { SIGINT } },
{ QSE_T("SIGKILL"), { SIGKILL } },
{ QSE_T("SIGSEGV"), { SIGSEGV } },
{ QSE_T("SIGTERM"), { SIGTERM } },
{ QSE_T("SIGQUIT"), { SIGQUIT } }
/*
{ QSE_T("WNOHANG"), { WNOHANG } },
*/
}; };
static int query (qse_awk_mod_t* mod, qse_awk_t* awk, const qse_char_t* name, qse_awk_mod_sym_t* sym) static int query (qse_awk_mod_t* mod, qse_awk_t* awk, const qse_char_t* name, qse_awk_mod_sym_t* sym)

File diff suppressed because it is too large Load Diff

View File

@ -103,7 +103,7 @@ int main ()
ret = -1; goto oops; ret = -1; goto oops;
} }
str = qse_awk_rtx_valtocpldup (rtx, v, &len); str = qse_awk_rtx_valtostrdup (rtx, v, &len);
if (str == QSE_NULL) if (str == QSE_NULL)
{ {
qse_fprintf (QSE_STDERR, QSE_T("error: %s\n"), qse_fprintf (QSE_STDERR, QSE_T("error: %s\n"),

View File

@ -111,7 +111,7 @@ int main ()
ret = -1; goto oops; ret = -1; goto oops;
} }
str = qse_awk_rtx_valtocpldup (rtx, rtv, &len); str = qse_awk_rtx_valtostrdup (rtx, rtv, &len);
if (str == QSE_NULL) if (str == QSE_NULL)
{ {
qse_fprintf (QSE_STDERR, QSE_T("error: %s\n"), qse_fprintf (QSE_STDERR, QSE_T("error: %s\n"),

View File

@ -105,7 +105,7 @@ int main ()
{ {
qse_awk_val_t* v, * fv; qse_awk_val_t* v, * fv;
fv = qse_awk_rtx_makestrval0 (rtx, xxx[i].vptr); fv = qse_awk_rtx_makestrvalwithstr (rtx, xxx[i].vptr);
if (fv == QSE_NULL) if (fv == QSE_NULL)
{ {
qse_fprintf (QSE_STDERR, QSE_T("error: %s\n"), qse_fprintf (QSE_STDERR, QSE_T("error: %s\n"),
@ -143,7 +143,7 @@ int main ()
{ {
qse_xstr_t str; qse_xstr_t str;
str.ptr = qse_awk_rtx_valtocpldup ( str.ptr = qse_awk_rtx_valtostrdup (
rtx, QSE_AWK_VAL_MAP_ITR_VAL(iptr), &str.len); rtx, QSE_AWK_VAL_MAP_ITR_VAL(iptr), &str.len);
if (str.ptr == QSE_NULL) if (str.ptr == QSE_NULL)
{ {
@ -166,7 +166,7 @@ int main ()
{ {
qse_xstr_t str; qse_xstr_t str;
str.ptr = qse_awk_rtx_valtocpldup (rtx, rtv, &str.len); str.ptr = qse_awk_rtx_valtostrdup (rtx, rtv, &str.len);
if (str.ptr == QSE_NULL) if (str.ptr == QSE_NULL)
{ {
qse_fprintf (QSE_STDERR, QSE_T("error: %s\n"), qse_fprintf (QSE_STDERR, QSE_T("error: %s\n"),