*** empty log message ***

This commit is contained in:
hyung-hwan 2006-08-31 15:39:14 +00:00
parent c450eb2ac1
commit 3807832056
4 changed files with 100 additions and 142 deletions

View File

@ -1,5 +1,5 @@
/* /*
* $Id: extio.c,v 1.40 2006-08-31 14:52:12 bacon Exp $ * $Id: extio.c,v 1.41 2006-08-31 15:39:13 bacon Exp $
*/ */
#include <xp/awk/awk_i.h> #include <xp/awk/awk_i.h>
@ -193,8 +193,7 @@ int xp_awk_readextio (
} }
else else
{ {
rs_ptr = xp_awk_valtostr ( rs_ptr = xp_awk_valtostr (run, rs, xp_true, XP_NULL, &rs_len);
rs, &run->errnum, xp_true, XP_NULL, &rs_len);
if (rs_ptr == XP_NULL) if (rs_ptr == XP_NULL)
{ {
xp_awk_refdownval (run, rs); xp_awk_refdownval (run, rs);
@ -421,8 +420,7 @@ static int __writeextio (
/* TOOD: consider using a shared buffer when calling /* TOOD: consider using a shared buffer when calling
* xp_awk_valtostr. maybe run->shared_buf.extio */ * xp_awk_valtostr. maybe run->shared_buf.extio */
str = xp_awk_valtostr ( str = xp_awk_valtostr (run, v, xp_true, NULL, &len);
v, &run->errnum, xp_true, NULL, &len);
if (str == XP_NULL) return -1; if (str == XP_NULL) return -1;
} }

View File

@ -1,5 +1,5 @@
/* /*
* $Id: func.c,v 1.37 2006-08-31 15:22:13 bacon Exp $ * $Id: func.c,v 1.38 2006-08-31 15:39:13 bacon Exp $
*/ */
#include <xp/awk/awk_i.h> #include <xp/awk/awk_i.h>
@ -146,7 +146,7 @@ static int __bfn_close (xp_awk_t* awk, void* run)
{ {
xp_size_t nargs; xp_size_t nargs;
xp_awk_val_t* v, * a0; xp_awk_val_t* v, * a0;
int errnum, n; int n;
xp_char_t* name; xp_char_t* name;
xp_size_t len; xp_size_t len;
@ -165,12 +165,8 @@ static int __bfn_close (xp_awk_t* awk, void* run)
} }
else else
{ {
name = xp_awk_valtostr (a0, &errnum, xp_true, XP_NULL, &len); name = xp_awk_valtostr (run, a0, xp_true, XP_NULL, &len);
if (name == XP_NULL) if (name == XP_NULL) return -1;
{
xp_awk_seterrnum (run, errnum);
return -1;
}
} }
if (len == 0) if (len == 0)
@ -252,7 +248,7 @@ static int __bfn_fflush (xp_awk_t* awk, void* run)
xp_awk_val_t* a0; xp_awk_val_t* a0;
xp_char_t* str0; xp_char_t* str0;
xp_size_t len0; xp_size_t len0;
int errnum, n; int n;
nargs = xp_awk_getnargs (run); nargs = xp_awk_getnargs (run);
xp_assert (nargs >= 0 && nargs <= 1); xp_assert (nargs >= 0 && nargs <= 1);
@ -283,12 +279,8 @@ static int __bfn_fflush (xp_awk_t* awk, void* run)
else else
{ {
str0 = xp_awk_valtostr ( str0 = xp_awk_valtostr (
a0, &errnum, xp_true, XP_NULL, &len0); run, a0, xp_true, XP_NULL, &len0);
if (str0 == XP_NULL) if (str0 == XP_NULL) return -1;
{
xp_awk_seterrnum (run, errnum);
return -1;
}
} }
@ -351,7 +343,6 @@ static int __bfn_index (xp_awk_t* awk, void* run)
xp_char_t* str0, * str1, * ptr; xp_char_t* str0, * str1, * ptr;
xp_size_t len0, len1; xp_size_t len0, len1;
xp_long_t idx; xp_long_t idx;
int errnum;
nargs = xp_awk_getnargs (run); nargs = xp_awk_getnargs (run);
xp_assert (nargs == 2); xp_assert (nargs == 2);
@ -366,12 +357,8 @@ static int __bfn_index (xp_awk_t* awk, void* run)
} }
else else
{ {
str0 = xp_awk_valtostr (a0, &errnum, xp_true, XP_NULL, &len0); str0 = xp_awk_valtostr (run, a0, xp_true, XP_NULL, &len0);
if (str0 == XP_NULL) if (str0 == XP_NULL) return -1;
{
xp_awk_seterrnum (run, errnum);
return -1;
}
} }
if (a1->type == XP_AWK_VAL_STR) if (a1->type == XP_AWK_VAL_STR)
@ -381,10 +368,9 @@ static int __bfn_index (xp_awk_t* awk, void* run)
} }
else else
{ {
str1 = xp_awk_valtostr (a1, &errnum, xp_true, XP_NULL, &len1); str1 = xp_awk_valtostr (run, a1, xp_true, XP_NULL, &len1);
if (str1 == XP_NULL) if (str1 == XP_NULL)
{ {
xp_awk_seterrnum (run, errnum);
if (a0->type != XP_AWK_VAL_STR) XP_AWK_FREE (awk, str0); if (a0->type != XP_AWK_VAL_STR) XP_AWK_FREE (awk, str0);
return -1; return -1;
} }
@ -415,7 +401,6 @@ static int __bfn_length (xp_awk_t* awk, void* run)
xp_awk_val_t* v; xp_awk_val_t* v;
xp_char_t* str; xp_char_t* str;
xp_size_t len; xp_size_t len;
int errnum;
nargs = xp_awk_getnargs (run); nargs = xp_awk_getnargs (run);
xp_assert (nargs == 1); xp_assert (nargs == 1);
@ -427,12 +412,8 @@ static int __bfn_length (xp_awk_t* awk, void* run)
} }
else else
{ {
str = xp_awk_valtostr (v, &errnum, xp_true, XP_NULL, &len); str = xp_awk_valtostr (run, v, xp_true, XP_NULL, &len);
if (str == XP_NULL) if (str == XP_NULL) return -1;
{
xp_awk_seterrnum (run, errnum);
return -1;
}
XP_AWK_FREE (awk, str); XP_AWK_FREE (awk, str);
} }
@ -456,7 +437,7 @@ static int __bfn_substr (xp_awk_t* awk, void* run)
xp_size_t len; xp_size_t len;
xp_long_t lindex, lcount; xp_long_t lindex, lcount;
xp_real_t rindex, rcount; xp_real_t rindex, rcount;
int errnum, n; int n;
nargs = xp_awk_getnargs (run); nargs = xp_awk_getnargs (run);
xp_assert (nargs >= 2 && nargs <= 3); xp_assert (nargs >= 2 && nargs <= 3);
@ -472,12 +453,8 @@ static int __bfn_substr (xp_awk_t* awk, void* run)
} }
else else
{ {
str = xp_awk_valtostr (a0, &errnum, xp_true, XP_NULL, &len); str = xp_awk_valtostr (run, a0, xp_true, XP_NULL, &len);
if (str == XP_NULL) if (str == XP_NULL) return -1;
{
xp_awk_seterrnum (run, errnum);
return -1;
}
} }
n = xp_awk_valtonum (a1, &lindex, &rindex); n = xp_awk_valtonum (a1, &lindex, &rindex);
@ -529,7 +506,6 @@ static int __bfn_split (xp_awk_t* awk, void* run)
xp_char_t* str, * p, * tok; xp_char_t* str, * p, * tok;
xp_size_t len, left, tok_len; xp_size_t len, left, tok_len;
xp_long_t num; xp_long_t num;
int errnum;
xp_char_t key[32]; xp_char_t key[32];
nargs = xp_awk_getnargs (run); nargs = xp_awk_getnargs (run);
@ -565,12 +541,8 @@ static int __bfn_split (xp_awk_t* awk, void* run)
} }
else else
{ {
str = xp_awk_valtostr (a0, &errnum, xp_true, XP_NULL, &len); str = xp_awk_valtostr (run, a0, xp_true, XP_NULL, &len);
if (str == XP_NULL) if (str == XP_NULL) return -1;
{
xp_awk_seterrnum (run, errnum);
return -1;
}
} }
t1 = xp_awk_makemapval (run); t1 = xp_awk_makemapval (run);
@ -657,7 +629,6 @@ static int __bfn_tolower (xp_awk_t* awk, void* run)
xp_char_t* str; xp_char_t* str;
xp_size_t len, i; xp_size_t len, i;
xp_awk_val_t* a0, * r; xp_awk_val_t* a0, * r;
int errnum;
nargs = xp_awk_getnargs (run); nargs = xp_awk_getnargs (run);
xp_assert (nargs == 1); xp_assert (nargs == 1);
@ -671,12 +642,8 @@ static int __bfn_tolower (xp_awk_t* awk, void* run)
} }
else else
{ {
str = xp_awk_valtostr (a0, &errnum, xp_true, XP_NULL, &len); str = xp_awk_valtostr (run, a0, xp_true, XP_NULL, &len);
if (str == XP_NULL) if (str == XP_NULL) return -1;
{
xp_awk_seterrnum (run, errnum);
return -1;
}
} }
for (i = 0; i < len; i++) str[i] = xp_tolower(str[i]); for (i = 0; i < len; i++) str[i] = xp_tolower(str[i]);
@ -700,7 +667,6 @@ static int __bfn_toupper (xp_awk_t* awk, void* run)
xp_char_t* str; xp_char_t* str;
xp_size_t len, i; xp_size_t len, i;
xp_awk_val_t* a0, * r; xp_awk_val_t* a0, * r;
int errnum;
nargs = xp_awk_getnargs (run); nargs = xp_awk_getnargs (run);
xp_assert (nargs == 1); xp_assert (nargs == 1);
@ -714,12 +680,8 @@ static int __bfn_toupper (xp_awk_t* awk, void* run)
} }
else else
{ {
str = xp_awk_valtostr (a0, &errnum, xp_true, XP_NULL, &len); str = xp_awk_valtostr (run, a0, xp_true, XP_NULL, &len);
if (str == XP_NULL) if (str == XP_NULL) return -1;
{
xp_awk_seterrnum (run, errnum);
return -1;
}
} }
for (i = 0; i < len; i++) str[i] = xp_toupper(str[i]); for (i = 0; i < len; i++) str[i] = xp_toupper(str[i]);
@ -742,18 +704,14 @@ static int __bfn_system (xp_awk_t* awk, void* run)
xp_size_t nargs; xp_size_t nargs;
xp_char_t* cmd; xp_char_t* cmd;
xp_awk_val_t* v; xp_awk_val_t* v;
int errnum, n; int n;
nargs = xp_awk_getnargs (run); nargs = xp_awk_getnargs (run);
xp_assert (nargs == 1); xp_assert (nargs == 1);
cmd = xp_awk_valtostr ( cmd = xp_awk_valtostr (
xp_awk_getarg(run, 0), &errnum, xp_true, XP_NULL, XP_NULL); run, xp_awk_getarg(run, 0), xp_true, XP_NULL, XP_NULL);
if (cmd == XP_NULL) if (cmd == XP_NULL) return -1;
{
xp_awk_seterrnum (run, errnum);
return -1;
}
#ifdef _WIN32 #ifdef _WIN32
n = _tsystem (cmd); n = _tsystem (cmd);

View File

@ -1,5 +1,5 @@
/* /*
* $Id: run.c,v 1.188 2006-08-31 15:22:13 bacon Exp $ * $Id: run.c,v 1.189 2006-08-31 15:39:14 bacon Exp $
*/ */
#include <xp/awk/awk_i.h> #include <xp/awk/awk_i.h>
@ -252,7 +252,7 @@ int xp_awk_setglobal (void* run, xp_size_t idx, xp_awk_val_t* val)
xp_assert (val->type != XP_AWK_VAL_REX); xp_assert (val->type != XP_AWK_VAL_REX);
rs_ptr = xp_awk_valtostr ( rs_ptr = xp_awk_valtostr (
val, &r->errnum, xp_true, XP_NULL, &rs_len); run, val, xp_true, XP_NULL, &rs_len);
if (rs_ptr == XP_NULL) return -1; if (rs_ptr == XP_NULL) return -1;
} }
@ -1586,8 +1586,7 @@ static int __run_delete (xp_awk_run_t* run, xp_awk_nde_delete_t* nde)
xp_awk_refupval (idx); xp_awk_refupval (idx);
key = xp_awk_valtostr ( key = xp_awk_valtostr (
idx, &run->errnum, run, idx, xp_true, XP_NULL, &key_len);
xp_true, XP_NULL, &key_len);
xp_awk_refdownval (run, idx); xp_awk_refdownval (run, idx);
if (key == XP_NULL) return -1; if (key == XP_NULL) return -1;
@ -1678,8 +1677,7 @@ static int __run_delete (xp_awk_run_t* run, xp_awk_nde_delete_t* nde)
xp_awk_refupval (idx); xp_awk_refupval (idx);
key = xp_awk_valtostr ( key = xp_awk_valtostr (
idx, &run->errnum, run, idx, xp_true, XP_NULL, &key_len);
xp_true, XP_NULL, &key_len);
xp_awk_refdownval (run, idx); xp_awk_refdownval (run, idx);
if (key == XP_NULL) return -1; if (key == XP_NULL) return -1;
@ -1709,7 +1707,7 @@ static int __run_print (xp_awk_run_t* run, xp_awk_nde_print_t* nde)
const xp_char_t* dst; const xp_char_t* dst;
xp_awk_val_t* v; xp_awk_val_t* v;
xp_awk_nde_t* np; xp_awk_nde_t* np;
int errnum, n; int n;
xp_assert ( xp_assert (
(p->out_type == XP_AWK_OUT_PIPE && p->out != XP_NULL) || (p->out_type == XP_AWK_OUT_PIPE && p->out != XP_NULL) ||
@ -1726,11 +1724,11 @@ static int __run_print (xp_awk_run_t* run, xp_awk_nde_print_t* nde)
if (v == XP_NULL) return -1; if (v == XP_NULL) return -1;
xp_awk_refupval (v); xp_awk_refupval (v);
out = xp_awk_valtostr (v, &errnum, xp_true, XP_NULL, &len); out = xp_awk_valtostr (run, v, xp_true, XP_NULL, &len);
if (out == XP_NULL) if (out == XP_NULL)
{ {
xp_awk_refdownval (run, v); xp_awk_refdownval (run, v);
PANIC_I (run, errnum); return -1;
} }
xp_awk_refdownval (run, v); xp_awk_refdownval (run, v);
@ -2234,8 +2232,8 @@ static xp_awk_val_t* __do_assignment_pos (
if (lv < 0) PANIC (run, XP_AWK_EPOSIDX); if (lv < 0) PANIC (run, XP_AWK_EPOSIDX);
/* convert the value to the string */ /* convert the value to the string */
str = xp_awk_valtostr (val, &errnum, xp_true, XP_NULL, &len); str = xp_awk_valtostr (run, val, xp_true, XP_NULL, &len);
if (str == XP_NULL) PANIC (run, errnum); if (str == XP_NULL) return XP_NULL;
if (lv == 0) if (lv == 0)
{ {
@ -3189,16 +3187,15 @@ static xp_awk_val_t* __eval_binop_concat (
xp_char_t* strl, * strr; xp_char_t* strl, * strr;
xp_size_t strl_len, strr_len; xp_size_t strl_len, strr_len;
xp_awk_val_t* res; xp_awk_val_t* res;
int errnum;
strl = xp_awk_valtostr (left, &errnum, xp_true, XP_NULL, &strl_len); strl = xp_awk_valtostr (run, left, xp_true, XP_NULL, &strl_len);
if (strl == XP_NULL) PANIC (run, errnum); if (strl == XP_NULL) return XP_NULL;
strr = xp_awk_valtostr (right, &errnum, xp_true, XP_NULL, &strr_len); strr = xp_awk_valtostr (run, right, xp_true, XP_NULL, &strr_len);
if (strr == XP_NULL) if (strr == XP_NULL)
{ {
XP_AWK_FREE (run->awk, strl); XP_AWK_FREE (run->awk, strl);
PANIC (run, errnum); return XP_NULL;
} }
res = xp_awk_makestrval2 (run, strl, strl_len, strr, strr_len); res = xp_awk_makestrval2 (run, strl, strl_len, strr, strr_len);
@ -3301,8 +3298,8 @@ static xp_awk_val_t* __eval_binop_match0 (
} }
else else
{ {
str = xp_awk_valtostr (right, &errnum, xp_true, XP_NULL, &len); str = xp_awk_valtostr (run, right, xp_true, XP_NULL, &len);
if (str == XP_NULL) PANIC (run, errnum); if (str == XP_NULL) return XP_NULL;
rex_code = xp_awk_buildrex (str, len, &errnum); rex_code = xp_awk_buildrex (str, len, &errnum);
if (rex_code == XP_NULL) if (rex_code == XP_NULL)
@ -3338,12 +3335,12 @@ static xp_awk_val_t* __eval_binop_match0 (
} }
else else
{ {
str = xp_awk_valtostr (left, &errnum, xp_true, XP_NULL, &len); str = xp_awk_valtostr (run, left, xp_true, XP_NULL, &len);
if (str == XP_NULL) if (str == XP_NULL)
{ {
if (right->type != XP_AWK_VAL_REX) if (right->type != XP_AWK_VAL_REX)
XP_AWK_FREE (run->awk, rex_code); XP_AWK_FREE (run->awk, rex_code);
PANIC (run, errnum); return XP_NULL;
} }
n = xp_awk_matchrex ( n = xp_awk_matchrex (
@ -4436,7 +4433,7 @@ static xp_awk_val_t* __eval_getline (xp_awk_run_t* run, xp_awk_nde_t* nde)
xp_char_t* in = XP_NULL; xp_char_t* in = XP_NULL;
const xp_char_t* dst; const xp_char_t* dst;
xp_str_t buf; xp_str_t buf;
int errnum, n; int n;
p = (xp_awk_nde_getline_t*)nde; p = (xp_awk_nde_getline_t*)nde;
@ -4458,11 +4455,11 @@ static xp_awk_val_t* __eval_getline (xp_awk_run_t* run, xp_awk_nde_t* nde)
* v->type == XP_AWK_VAL_STR, xp_awk_refdownval(v) * v->type == XP_AWK_VAL_STR, xp_awk_refdownval(v)
* should not be called immediately below */ * should not be called immediately below */
xp_awk_refupval (v); xp_awk_refupval (v);
in = xp_awk_valtostr (v, &errnum, xp_true, XP_NULL, &len); in = xp_awk_valtostr (run, v, xp_true, XP_NULL, &len);
if (in == XP_NULL) if (in == XP_NULL)
{ {
xp_awk_refdownval (run, v); xp_awk_refdownval (run, v);
PANIC (run, errnum); return XP_NULL;
} }
xp_awk_refdownval (run, v); xp_awk_refdownval (run, v);
@ -4693,7 +4690,7 @@ static int __split_record (xp_awk_run_t* run)
else else
{ {
fs_ptr = xp_awk_valtostr ( fs_ptr = xp_awk_valtostr (
fs, &run->errnum, xp_true, XP_NULL, &fs_len); run, fs, xp_true, XP_NULL, &fs_len);
if (fs_ptr == XP_NULL) return -1; if (fs_ptr == XP_NULL) return -1;
} }
#endif #endif
@ -4897,7 +4894,7 @@ static int __recomp_record_fields (
if (v != xp_awk_val_nil) if (v != xp_awk_val_nil)
{ {
ofsp = xp_awk_valtostr ( ofsp = xp_awk_valtostr (
v, &run->errnum, xp_true, XP_NULL, &ofs_len); run, v, xp_true, XP_NULL, &ofs_len);
if (ofsp == XP_NULL) return -1; if (ofsp == XP_NULL) return -1;
ofs = ofsp; ofs = ofsp;
@ -5025,7 +5022,6 @@ static xp_char_t* __idxnde_to_str (
{ {
xp_char_t* str; xp_char_t* str;
xp_awk_val_t* idx; xp_awk_val_t* idx;
int errnum;
xp_assert (nde != XP_NULL); xp_assert (nde != XP_NULL);
@ -5037,11 +5033,11 @@ static xp_char_t* __idxnde_to_str (
xp_awk_refupval (idx); xp_awk_refupval (idx);
str = xp_awk_valtostr (idx, &errnum, xp_true, XP_NULL, len); str = xp_awk_valtostr (run, idx, xp_true, XP_NULL, len);
if (str == XP_NULL) if (str == XP_NULL)
{ {
xp_awk_refdownval (run, idx); xp_awk_refdownval (run, idx);
PANIC (run, errnum); return XP_NULL;
} }
xp_awk_refdownval (run, idx); xp_awk_refdownval (run, idx);
@ -5076,12 +5072,12 @@ static xp_char_t* __idxnde_to_str (
PANIC (run, XP_AWK_ENOMEM); PANIC (run, XP_AWK_ENOMEM);
} }
if (xp_awk_valtostr (idx, &errnum, if (xp_awk_valtostr (run,
xp_false, &idxstr, XP_NULL) == XP_NULL) idx, xp_false, &idxstr, XP_NULL) == XP_NULL)
{ {
xp_awk_refdownval (run, idx); xp_awk_refdownval (run, idx);
xp_str_close (&idxstr); xp_str_close (&idxstr);
PANIC (run, errnum); return XP_NULL;
} }
xp_awk_refdownval (run, idx); xp_awk_refdownval (run, idx);

View File

@ -1,5 +1,5 @@
/* /*
* $Id: val.c,v 1.53 2006-08-31 15:22:13 bacon Exp $ * $Id: val.c,v 1.54 2006-08-31 15:39:14 bacon Exp $
*/ */
#include <xp/awk/awk_i.h> #include <xp/awk/awk_i.h>
@ -50,8 +50,8 @@ xp_awk_val_t* xp_awk_makeintval (xp_awk_run_t* run, xp_long_t v)
} }
else else
{ {
val = (xp_awk_val_int_t*) val = (xp_awk_val_int_t*) XP_AWK_MALLOC (
xp_malloc (xp_sizeof(xp_awk_val_int_t)); run->awk, xp_sizeof(xp_awk_val_int_t));
if (val == XP_NULL) return XP_NULL; if (val == XP_NULL) return XP_NULL;
} }
@ -73,8 +73,8 @@ xp_awk_val_t* xp_awk_makerealval (xp_awk_run_t* run, xp_real_t v)
} }
else else
{ {
val = (xp_awk_val_real_t*) val = (xp_awk_val_real_t*) XP_AWK_MALLOC (
xp_malloc (xp_sizeof(xp_awk_val_real_t)); run->awk, xp_sizeof(xp_awk_val_real_t));
if (val == XP_NULL) return XP_NULL; if (val == XP_NULL) return XP_NULL;
} }
@ -96,7 +96,8 @@ xp_awk_val_t* xp_awk_makestrval (
{ {
xp_awk_val_str_t* val; xp_awk_val_str_t* val;
val = (xp_awk_val_str_t*) xp_malloc (xp_sizeof(xp_awk_val_str_t)); val = (xp_awk_val_str_t*) XP_AWK_MALLOC (
run->awk, xp_sizeof(xp_awk_val_str_t));
if (val == XP_NULL) return XP_NULL; if (val == XP_NULL) return XP_NULL;
val->type = XP_AWK_VAL_STR; val->type = XP_AWK_VAL_STR;
@ -105,7 +106,7 @@ xp_awk_val_t* xp_awk_makestrval (
val->buf = xp_strxdup (str, len); val->buf = xp_strxdup (str, len);
if (val->buf == XP_NULL) if (val->buf == XP_NULL)
{ {
xp_free (val); XP_AWK_FREE (run->awk, val);
return XP_NULL; return XP_NULL;
} }
@ -120,7 +121,8 @@ xp_awk_val_t* xp_awk_makestrval2 (
{ {
xp_awk_val_str_t* val; xp_awk_val_str_t* val;
val = (xp_awk_val_str_t*) xp_malloc (xp_sizeof(xp_awk_val_str_t)); val = (xp_awk_val_str_t*) XP_AWK_MALLOC (
run->awk, xp_sizeof(xp_awk_val_str_t));
if (val == XP_NULL) return XP_NULL; if (val == XP_NULL) return XP_NULL;
val->type = XP_AWK_VAL_STR; val->type = XP_AWK_VAL_STR;
@ -129,7 +131,7 @@ xp_awk_val_t* xp_awk_makestrval2 (
val->buf = xp_strxdup2 (str1, len1, str2, len2); val->buf = xp_strxdup2 (str1, len1, str2, len2);
if (val->buf == XP_NULL) if (val->buf == XP_NULL)
{ {
xp_free (val); XP_AWK_FREE (run->awk, val);
return XP_NULL; return XP_NULL;
} }
@ -142,7 +144,8 @@ xp_awk_val_t* xp_awk_makerexval (
{ {
xp_awk_val_rex_t* val; xp_awk_val_rex_t* val;
val = (xp_awk_val_rex_t*) xp_malloc (xp_sizeof(xp_awk_val_rex_t)); val = (xp_awk_val_rex_t*) XP_AWK_MALLOC (
run->awk, xp_sizeof(xp_awk_val_rex_t));
if (val == XP_NULL) return XP_NULL; if (val == XP_NULL) return XP_NULL;
val->type = XP_AWK_VAL_REX; val->type = XP_AWK_VAL_REX;
@ -151,15 +154,15 @@ xp_awk_val_t* xp_awk_makerexval (
val->buf = xp_strxdup (buf, len); val->buf = xp_strxdup (buf, len);
if (val->buf == XP_NULL) if (val->buf == XP_NULL)
{ {
xp_free (val); XP_AWK_FREE (run->awk, val);
return XP_NULL; return XP_NULL;
} }
val->code = xp_malloc (XP_AWK_REX_LEN(code)); val->code = XP_AWK_MALLOC (run->awk, XP_AWK_REX_LEN(code));
if (val->code == XP_NULL) if (val->code == XP_NULL)
{ {
xp_free (val->buf); XP_AWK_FREE (run->awk, val->buf);
xp_free (val); XP_AWK_FREE (run->awk, val);
return XP_NULL; return XP_NULL;
} }
@ -181,7 +184,8 @@ xp_awk_val_t* xp_awk_makemapval (xp_awk_run_t* run)
{ {
xp_awk_val_map_t* val; xp_awk_val_map_t* val;
val = (xp_awk_val_map_t*) xp_malloc (xp_sizeof(xp_awk_val_map_t)); val = (xp_awk_val_map_t*) XP_AWK_MALLOC (
run->awk, xp_sizeof(xp_awk_val_map_t));
if (val == XP_NULL) return XP_NULL; if (val == XP_NULL) return XP_NULL;
val->type = XP_AWK_VAL_MAP; val->type = XP_AWK_VAL_MAP;
@ -189,7 +193,7 @@ xp_awk_val_t* xp_awk_makemapval (xp_awk_run_t* run)
val->map = xp_awk_map_open (XP_NULL, run, 256, __free_map_val); val->map = xp_awk_map_open (XP_NULL, run, 256, __free_map_val);
if (val->map == XP_NULL) if (val->map == XP_NULL)
{ {
xp_free (val); XP_AWK_FREE (run->awk, val);
return XP_NULL; return XP_NULL;
} }
@ -206,8 +210,8 @@ xp_awk_val_t* xp_awk_makerefval (xp_awk_run_t* run, int id, xp_awk_val_t** adr)
} }
else else
{ {
val = (xp_awk_val_ref_t*) val = (xp_awk_val_ref_t*) XP_AWK_MALLOC (
xp_malloc (xp_sizeof(xp_awk_val_ref_t)); run->awk, xp_sizeof(xp_awk_val_ref_t));
if (val == XP_NULL) return XP_NULL; if (val == XP_NULL) return XP_NULL;
} }
@ -237,7 +241,7 @@ xp_awk_printval (val);
xp_printf (XP_T("\n"));*/ xp_printf (XP_T("\n"));*/
if (val->type == XP_AWK_VAL_NIL) if (val->type == XP_AWK_VAL_NIL)
{ {
xp_free (val); XP_AWK_FREE (run->awk, val);
} }
else if (val->type == XP_AWK_VAL_INT) else if (val->type == XP_AWK_VAL_INT)
{ {
@ -247,7 +251,7 @@ xp_printf (XP_T("\n"));*/
run->icache[run->icache_count++] = run->icache[run->icache_count++] =
(xp_awk_val_int_t*)val; (xp_awk_val_int_t*)val;
} }
else xp_free (val); else XP_AWK_FREE (run->awk, val);
} }
else if (val->type == XP_AWK_VAL_REAL) else if (val->type == XP_AWK_VAL_REAL)
{ {
@ -257,23 +261,23 @@ xp_printf (XP_T("\n"));*/
run->rcache[run->rcache_count++] = run->rcache[run->rcache_count++] =
(xp_awk_val_real_t*)val; (xp_awk_val_real_t*)val;
} }
else xp_free (val); else XP_AWK_FREE (run->awk, val);
} }
else if (val->type == XP_AWK_VAL_STR) else if (val->type == XP_AWK_VAL_STR)
{ {
xp_free (((xp_awk_val_str_t*)val)->buf); XP_AWK_FREE (run->awk, ((xp_awk_val_str_t*)val)->buf);
xp_free (val); XP_AWK_FREE (run->awk, val);
} }
else if (val->type == XP_AWK_VAL_REX) else if (val->type == XP_AWK_VAL_REX)
{ {
xp_free (((xp_awk_val_rex_t*)val)->buf); XP_AWK_FREE (run->awk, ((xp_awk_val_rex_t*)val)->buf);
xp_awk_freerex (((xp_awk_val_rex_t*)val)->code); xp_awk_freerex (((xp_awk_val_rex_t*)val)->code);
xp_free (val); XP_AWK_FREE (run->awk, val);
} }
else if (val->type == XP_AWK_VAL_MAP) else if (val->type == XP_AWK_VAL_MAP)
{ {
xp_awk_map_close (((xp_awk_val_map_t*)val)->map); xp_awk_map_close (((xp_awk_val_map_t*)val)->map);
xp_free (val); XP_AWK_FREE (run->awk, val);
} }
else if (val->type == XP_AWK_VAL_REF) else if (val->type == XP_AWK_VAL_REF)
{ {
@ -283,7 +287,7 @@ xp_printf (XP_T("\n"));*/
run->fcache[run->fcache_count++] = run->fcache[run->fcache_count++] =
(xp_awk_val_ref_t*)val; (xp_awk_val_ref_t*)val;
} }
else xp_free (val); else XP_AWK_FREE (run->awk, val);
} }
else else
{ {
@ -361,7 +365,7 @@ xp_bool_t xp_awk_valtobool (xp_awk_val_t* val)
} }
xp_char_t* xp_awk_valtostr ( xp_char_t* xp_awk_valtostr (
xp_awk_val_t* v, int* errnum, xp_awk_run_t* run, xp_awk_val_t* v,
xp_bool_t clear_buf, xp_str_t* buf, xp_size_t* len) xp_bool_t clear_buf, xp_str_t* buf, xp_size_t* len)
{ {
if (v->type == XP_AWK_VAL_NIL) if (v->type == XP_AWK_VAL_NIL)
@ -372,7 +376,7 @@ xp_char_t* xp_awk_valtostr (
tmp = xp_strdup (XP_T("")); tmp = xp_strdup (XP_T(""));
if (tmp == XP_NULL) if (tmp == XP_NULL)
{ {
*errnum = XP_AWK_ENOMEM; run->errnum = XP_AWK_ENOMEM;
return XP_NULL; return XP_NULL;
} }
@ -400,10 +404,11 @@ xp_char_t* xp_awk_valtostr (
/* handle zero */ /* handle zero */
if (buf == XP_NULL) if (buf == XP_NULL)
{ {
tmp = xp_malloc (2 * xp_sizeof(xp_char_t)); tmp = XP_AWK_MALLOC (
run->awk, 2 * xp_sizeof(xp_char_t));
if (tmp == XP_NULL) if (tmp == XP_NULL)
{ {
*errnum = XP_AWK_ENOMEM; run->errnum = XP_AWK_ENOMEM;
return XP_NULL; return XP_NULL;
} }
@ -417,7 +422,7 @@ xp_char_t* xp_awk_valtostr (
if (clear_buf) xp_str_clear (buf); if (clear_buf) xp_str_clear (buf);
if (xp_str_cat (buf, XP_T("0")) == (xp_size_t)-1) if (xp_str_cat (buf, XP_T("0")) == (xp_size_t)-1)
{ {
*errnum = XP_AWK_ENOMEM; run->errnum = XP_AWK_ENOMEM;
return XP_NULL; return XP_NULL;
} }
@ -432,10 +437,11 @@ xp_char_t* xp_awk_valtostr (
if (buf == XP_NULL) if (buf == XP_NULL)
{ {
tmp = xp_malloc ((l + 1) * xp_sizeof(xp_char_t)); tmp = XP_AWK_MALLOC (
run->awk, (l + 1) * xp_sizeof(xp_char_t));
if (tmp == XP_NULL) if (tmp == XP_NULL)
{ {
*errnum = XP_AWK_ENOMEM; run->errnum = XP_AWK_ENOMEM;
return XP_NULL; return XP_NULL;
} }
@ -453,7 +459,7 @@ xp_char_t* xp_awk_valtostr (
if (xp_str_nccat ( if (xp_str_nccat (
buf, XP_T(' '), l) == (xp_size_t)-1) buf, XP_T(' '), l) == (xp_size_t)-1)
{ {
*errnum = XP_AWK_ENOMEM; run->errnum = XP_AWK_ENOMEM;
return XP_NULL; return XP_NULL;
} }
} }
@ -500,7 +506,7 @@ xp_char_t* xp_awk_valtostr (
tmp = xp_strdup (tbuf); tmp = xp_strdup (tbuf);
if (tmp == XP_NULL) if (tmp == XP_NULL)
{ {
*errnum = XP_AWK_ENOMEM; run->errnum = XP_AWK_ENOMEM;
return XP_NULL; return XP_NULL;
} }
@ -512,7 +518,7 @@ xp_char_t* xp_awk_valtostr (
if (xp_str_cat (buf, tbuf) == (xp_size_t)-1) if (xp_str_cat (buf, tbuf) == (xp_size_t)-1)
{ {
*errnum = XP_AWK_ENOMEM; run->errnum = XP_AWK_ENOMEM;
return XP_NULL; return XP_NULL;
} }
@ -534,7 +540,7 @@ xp_char_t* xp_awk_valtostr (
((xp_awk_val_str_t*)v)->len); ((xp_awk_val_str_t*)v)->len);
if (tmp == XP_NULL) if (tmp == XP_NULL)
{ {
*errnum = XP_AWK_ENOMEM; run->errnum = XP_AWK_ENOMEM;
return XP_NULL; return XP_NULL;
} }
@ -548,7 +554,7 @@ xp_char_t* xp_awk_valtostr (
((xp_awk_val_str_t*)v)->buf, ((xp_awk_val_str_t*)v)->buf,
((xp_awk_val_str_t*)v)->len) == (xp_size_t)-1) ((xp_awk_val_str_t*)v)->len) == (xp_size_t)-1)
{ {
*errnum = XP_AWK_ENOMEM; run->errnum = XP_AWK_ENOMEM;
return XP_NULL; return XP_NULL;
} }
@ -562,7 +568,7 @@ xp_char_t* xp_awk_valtostr (
/* TODO: process more value types */ /* TODO: process more value types */
xp_printf (XP_T("*** ERROR: WRONG VALUE TYPE [%d] in xp_awk_valtostr v=> %p***\n"), v->type, v); xp_printf (XP_T("*** ERROR: WRONG VALUE TYPE [%d] in xp_awk_valtostr v=> %p***\n"), v->type, v);
*errnum = XP_AWK_EVALTYPE; run->errnum = XP_AWK_EVALTYPE;
return XP_NULL; return XP_NULL;
} }