*** empty log message ***

This commit is contained in:
hyung-hwan 2006-08-31 14:52:12 +00:00
parent 91a547d56a
commit 809fb80456
6 changed files with 260 additions and 238 deletions

View File

@ -1,5 +1,5 @@
/*
* $Id: awk.c,v 1.71 2006-08-31 04:21:03 bacon Exp $
* $Id: awk.c,v 1.72 2006-08-31 14:52:11 bacon Exp $
*/
#include <xp/awk/awk_i.h>
@ -173,7 +173,7 @@ int xp_awk_clear (xp_awk_t* awk)
xp_awk_clrpt (awk->tree.chain->pattern);
if (awk->tree.chain->action != XP_NULL)
xp_awk_clrpt (awk->tree.chain->action);
xp_free (awk->tree.chain);
awk->syscas->free (awk->tree.chain, awk->syscas->custom_data);
awk->tree.chain = next;
}

View File

@ -1,5 +1,5 @@
/*
* $Id: awk_i.h,v 1.48 2006-08-31 04:21:03 bacon Exp $
* $Id: awk_i.h,v 1.49 2006-08-31 14:52:11 bacon Exp $
*/
#ifndef _XP_AWK_AWKI_H_
@ -40,6 +40,13 @@ typedef struct xp_awk_tree_t xp_awk_tree_t;
#define XP_AWK_MAX_LOCALS 9999
#define XP_AWK_MAX_PARAMS 9999
#define XP_AWK_MALLOC(awk,size) \
(awk)->syscas->malloc (size, (awk)->syscas->custom_data)
#define XP_AWK_REALLOC(awk,ptr,size) \
(awk)->syscas->realloc (ptr, size, (awk)->syscas->custom_data)
#define XP_AWK_FREE(awk,ptr) \
(awk)->syscas->free (ptr, (awk)->syscas->custom_data)
struct xp_awk_tree_t
{
xp_size_t nglobals; /* total number of globals */

View File

@ -1,5 +1,5 @@
/*
* $Id: extio.c,v 1.39 2006-08-30 14:48:09 bacon Exp $
* $Id: extio.c,v 1.40 2006-08-31 14:52:12 bacon Exp $
*/
#include <xp/awk/awk_i.h>
@ -120,7 +120,8 @@ int xp_awk_readextio (
if (p == XP_NULL)
{
p = (xp_awk_extio_t*) xp_malloc (xp_sizeof(xp_awk_extio_t));
p = (xp_awk_extio_t*) XP_AWK_MALLOC (
run->awk, xp_sizeof(xp_awk_extio_t));
if (p == XP_NULL)
{
run->errnum = XP_AWK_ENOMEM;
@ -130,7 +131,7 @@ int xp_awk_readextio (
p->name = xp_strdup (name);
if (p->name == XP_NULL)
{
xp_free (p);
XP_AWK_FREE (run->awk, p);
run->errnum = XP_AWK_ENOMEM;
return -1;
}
@ -149,8 +150,8 @@ int xp_awk_readextio (
n = handler (XP_AWK_IO_OPEN, p, XP_NULL, 0);
if (n == -1)
{
xp_free (p->name);
xp_free (p);
XP_AWK_FREE (run->awk, p->name);
XP_AWK_FREE (run->awk, p);
/* TODO: use meaningful error code */
if (xp_awk_setglobal (
@ -326,7 +327,7 @@ int xp_awk_readextio (
else line_len = line_len + 1;
}
if (rs_ptr != XP_NULL && rs->type != XP_AWK_VAL_STR) xp_free (rs_ptr);
if (rs_ptr != XP_NULL && rs->type != XP_AWK_VAL_STR) XP_AWK_FREE (run->awk, rs_ptr);
xp_awk_refdownval (run, rs);
/* increment NR */
@ -446,10 +447,11 @@ static int __writeextio (
/* if there is not corresponding extio for name, create one */
if (p == XP_NULL)
{
p = (xp_awk_extio_t*) xp_malloc (xp_sizeof(xp_awk_extio_t));
p = (xp_awk_extio_t*) XP_AWK_MALLOC (
run->awk, xp_sizeof(xp_awk_extio_t));
if (p == XP_NULL)
{
if (v->type != XP_AWK_VAL_STR) xp_free (str);
if (v->type != XP_AWK_VAL_STR) XP_AWK_FREE (run->awk, str);
run->errnum = XP_AWK_ENOMEM;
return -1;
}
@ -457,8 +459,8 @@ static int __writeextio (
p->name = xp_strdup (name);
if (p->name == XP_NULL)
{
xp_free (p);
if (v->type != XP_AWK_VAL_STR) xp_free (str);
XP_AWK_FREE (run->awk, p);
if (v->type != XP_AWK_VAL_STR) XP_AWK_FREE (run->awk, str);
run->errnum = XP_AWK_ENOMEM;
return -1;
}
@ -471,9 +473,9 @@ static int __writeextio (
n = handler (XP_AWK_IO_OPEN, p, XP_NULL, 0);
if (n == -1)
{
xp_free (p->name);
xp_free (p);
if (v->type != XP_AWK_VAL_STR) xp_free (str);
XP_AWK_FREE (run->awk, p->name);
XP_AWK_FREE (run->awk, p);
if (v->type != XP_AWK_VAL_STR) XP_AWK_FREE (run->awk, str);
/* TODO: use meaningful error code */
if (xp_awk_setglobal (
@ -503,7 +505,7 @@ static int __writeextio (
if (n == -1)
{
if (v->type != XP_AWK_VAL_STR) xp_free (str);
if (v->type != XP_AWK_VAL_STR) XP_AWK_FREE (run->awk, str);
/* TODO: use meaningful error code */
if (xp_awk_setglobal (
@ -516,12 +518,12 @@ static int __writeextio (
if (n == 0)
{
if (v->type != XP_AWK_VAL_STR) xp_free (str);
if (v->type != XP_AWK_VAL_STR) XP_AWK_FREE (run->awk, str);
return 0;
}
}
if (v->type != XP_AWK_VAL_STR) xp_free (str);
if (v->type != XP_AWK_VAL_STR) XP_AWK_FREE (run->awk, str);
if (nl)
{
@ -700,8 +702,8 @@ int xp_awk_closeextio_read (
if (px != XP_NULL) px->next = p->next;
else run->extio.chain = p->next;
xp_free (p->name);
xp_free (p);
XP_AWK_FREE (run->awk, p->name);
XP_AWK_FREE (run->awk, p);
return 0;
}
@ -760,8 +762,8 @@ int xp_awk_closeextio_write (
if (px != XP_NULL) px->next = p->next;
else run->extio.chain = p->next;
xp_free (p->name);
xp_free (p);
XP_AWK_FREE (run->awk, p->name);
XP_AWK_FREE (run->awk, p);
return 0;
}
@ -802,8 +804,8 @@ int xp_awk_closeextio (xp_awk_run_t* run, const xp_char_t* name)
if (px != XP_NULL) px->next = p->next;
else run->extio.chain = p->next;
xp_free (p->name);
xp_free (p);
XP_AWK_FREE (run->awk, p->name);
XP_AWK_FREE (run->awk, p);
return 0;
}
@ -825,7 +827,8 @@ void xp_awk_clearextio (xp_awk_run_t* run)
while (run->extio.chain != XP_NULL)
{
handler = run->extio.handler[run->extio.chain->type & __MASK_CLEAR];
handler = run->extio.handler[
run->extio.chain->type & __MASK_CLEAR];
next = run->extio.chain->next;
if (handler != XP_NULL)
@ -838,8 +841,8 @@ void xp_awk_clearextio (xp_awk_run_t* run)
}
}
xp_free (run->extio.chain->name);
xp_free (run->extio.chain);
XP_AWK_FREE (run->awk, run->extio.chain->name);
XP_AWK_FREE (run->awk, run->extio.chain);
run->extio.chain = next;
}

View File

@ -1,5 +1,5 @@
/*
* $Id: func.c,v 1.35 2006-08-30 14:48:09 bacon Exp $
* $Id: func.c,v 1.36 2006-08-31 14:52:12 bacon Exp $
*/
#include <xp/awk/awk_i.h>
@ -64,7 +64,7 @@ xp_awk_bfn_t* xp_awk_addbfn (
/* TODO: complete this function??? */
p = (xp_awk_bfn_t*) xp_malloc (xp_sizeof(xp_awk_bfn_t));
p = (xp_awk_bfn_t*) XP_AWK_MALLOC (awk, xp_sizeof(xp_awk_bfn_t));
if (p == XP_NULL) return XP_NULL;
/* NOTE: make sure that name is a constant string */
@ -93,7 +93,7 @@ int xp_awk_delbfn (xp_awk_t* awk, const xp_char_t* name)
awk->bfn.user = p->next;
else pp->next = p->next;
xp_free (p);
XP_AWK_FREE (awk, p);
return 0;
}
@ -111,7 +111,7 @@ void xp_awk_clrbfn (xp_awk_t* awk)
while (p != XP_NULL)
{
np = p;
xp_free (p);
XP_AWK_FREE (awk, p);
p = np;
}
@ -183,7 +183,7 @@ static int __bfn_close (xp_awk_t* awk, void* run)
* an empty string for its identification because closeextio
* closes any extios that match the name given unlike
* closeextio_read or closeextio_write. */
if (a0->type != XP_AWK_VAL_STR) xp_free (name);
if (a0->type != XP_AWK_VAL_STR) XP_AWK_FREE (awk, name);
n = -1;
/* TODO: need to set ERRNO??? */
goto skip_close;
@ -195,7 +195,7 @@ static int __bfn_close (xp_awk_t* awk, void* run)
{
/* the name contains a null string.
* make close return -1 */
if (a0->type != XP_AWK_VAL_STR) xp_free (name);
if (a0->type != XP_AWK_VAL_STR) XP_AWK_FREE (awk, name);
n = -1;
/* TODO: need to set ERRNO??? */
goto skip_close;
@ -205,11 +205,11 @@ static int __bfn_close (xp_awk_t* awk, void* run)
n = xp_awk_closeextio (run, name);
if (n == -1 && ((xp_awk_run_t*)run)->errnum != XP_AWK_EIOHANDLER)
{
if (a0->type != XP_AWK_VAL_STR) xp_free (name);
if (a0->type != XP_AWK_VAL_STR) XP_AWK_FREE (awk, name);
return -1;
}
if (a0->type != XP_AWK_VAL_STR) xp_free (name);
if (a0->type != XP_AWK_VAL_STR) XP_AWK_FREE (awk, name);
skip_close:
v = xp_awk_makeintval (run, n);
@ -299,7 +299,7 @@ static int __bfn_fflush (xp_awk_t* awk, void* run)
{
if (*ptr == XP_T('\0'))
{
if (a0->type != XP_AWK_VAL_STR) xp_free (str0);
if (a0->type != XP_AWK_VAL_STR) XP_AWK_FREE (awk, str0);
n = -1;
goto skip_flush;
}
@ -329,7 +329,7 @@ static int __bfn_fflush (xp_awk_t* awk, void* run)
* if n is -1, the io handler has returned an error */
if (n != 0) n = -1;
if (a0->type != XP_AWK_VAL_STR) xp_free (str0);
if (a0->type != XP_AWK_VAL_STR) XP_AWK_FREE (awk, str0);
}
skip_flush:
@ -385,7 +385,7 @@ static int __bfn_index (xp_awk_t* awk, void* run)
if (str1 == XP_NULL)
{
xp_awk_seterrnum (run, errnum);
if (a0->type != XP_AWK_VAL_STR) xp_free (str0);
if (a0->type != XP_AWK_VAL_STR) XP_AWK_FREE (awk, str0);
return -1;
}
}
@ -395,8 +395,8 @@ static int __bfn_index (xp_awk_t* awk, void* run)
if (xp_awk_getopt(awk) & XP_AWK_STRINDEXONE) idx = idx + 1;
if (a0->type != XP_AWK_VAL_STR) xp_free (str0);
if (a1->type != XP_AWK_VAL_STR) xp_free (str1);
if (a0->type != XP_AWK_VAL_STR) XP_AWK_FREE (awk, str0);
if (a1->type != XP_AWK_VAL_STR) XP_AWK_FREE (awk, str1);
a0 = xp_awk_makeintval (run, idx);
if (a0 == XP_NULL)
@ -434,7 +434,7 @@ static int __bfn_length (xp_awk_t* awk, void* run)
return -1;
}
xp_free (str);
XP_AWK_FREE (awk, str);
}
v = xp_awk_makeintval (run, len);
@ -483,7 +483,7 @@ static int __bfn_substr (xp_awk_t* awk, void* run)
n = xp_awk_valtonum (a1, &lindex, &rindex);
if (n == -1)
{
if (a0->type != XP_AWK_VAL_STR) xp_free (str);
if (a0->type != XP_AWK_VAL_STR) XP_AWK_FREE (awk, str);
xp_awk_seterrnum (run, XP_AWK_EVALTYPE);
return -1;
}
@ -495,7 +495,7 @@ static int __bfn_substr (xp_awk_t* awk, void* run)
n = xp_awk_valtonum (a2, &lcount, &rcount);
if (n == -1)
{
if (a0->type != XP_AWK_VAL_STR) xp_free (str);
if (a0->type != XP_AWK_VAL_STR) XP_AWK_FREE (awk, str);
xp_awk_seterrnum (run, XP_AWK_EVALTYPE);
return -1;
}
@ -512,12 +512,12 @@ static int __bfn_substr (xp_awk_t* awk, void* run)
r = xp_awk_makestrval (&str[lindex], (xp_size_t)lcount);
if (r == XP_NULL)
{
if (a0->type != XP_AWK_VAL_STR) xp_free (str);
if (a0->type != XP_AWK_VAL_STR) XP_AWK_FREE (awk, str);
xp_awk_seterrnum (run, XP_AWK_ENOMEM);
return -1;
}
if (a0->type != XP_AWK_VAL_STR) xp_free (str);
if (a0->type != XP_AWK_VAL_STR) XP_AWK_FREE (awk, str);
xp_awk_setretval (run, r);
return 0;
}
@ -576,7 +576,7 @@ static int __bfn_split (xp_awk_t* awk, void* run)
t1 = xp_awk_makemapval (run);
if (t1 == XP_NULL)
{
if (a0->type != XP_AWK_VAL_STR) xp_free (str);
if (a0->type != XP_AWK_VAL_STR) XP_AWK_FREE (awk, str);
xp_awk_seterrnum (run, XP_AWK_ENOMEM);
return -1;
}
@ -603,7 +603,7 @@ static int __bfn_split (xp_awk_t* awk, void* run)
t2 = xp_awk_makestrval (tok, tok_len);
if (t2 == XP_NULL)
{
if (a0->type != XP_AWK_VAL_STR) xp_free (str);
if (a0->type != XP_AWK_VAL_STR) XP_AWK_FREE (awk, str);
xp_awk_seterrnum (run, XP_AWK_ENOMEM);
return -1;
}
@ -624,7 +624,7 @@ static int __bfn_split (xp_awk_t* awk, void* run)
((xp_awk_val_map_t*)t1)->map,
key, xp_strlen(key), t2, XP_NULL) == -1)
{
if (a0->type != XP_AWK_VAL_STR) xp_free (str);
if (a0->type != XP_AWK_VAL_STR) XP_AWK_FREE (awk, str);
xp_awk_seterrnum (run, XP_AWK_ENOMEM);
return -1;
}
@ -638,7 +638,7 @@ static int __bfn_split (xp_awk_t* awk, void* run)
len = len - (p - str);
}
if (a0->type != XP_AWK_VAL_STR) xp_free (str);
if (a0->type != XP_AWK_VAL_STR) XP_AWK_FREE (awk, str);
t1 = xp_awk_makeintval (run, num);
if (t1 == XP_NULL)
@ -684,12 +684,12 @@ static int __bfn_tolower (xp_awk_t* awk, void* run)
r = xp_awk_makestrval (str, len);
if (r == XP_NULL)
{
if (a0->type != XP_AWK_VAL_STR) xp_free (str);
if (a0->type != XP_AWK_VAL_STR) XP_AWK_FREE (awk, str);
xp_awk_seterrnum (run, XP_AWK_ENOMEM);
return -1;
}
if (a0->type != XP_AWK_VAL_STR) xp_free (str);
if (a0->type != XP_AWK_VAL_STR) XP_AWK_FREE (awk, str);
xp_awk_setretval (run, r);
return 0;
}
@ -727,12 +727,12 @@ static int __bfn_toupper (xp_awk_t* awk, void* run)
r = xp_awk_makestrval (str, len);
if (r == XP_NULL)
{
if (a0->type != XP_AWK_VAL_STR) xp_free (str);
if (a0->type != XP_AWK_VAL_STR) XP_AWK_FREE (awk, str);
xp_awk_seterrnum (run, XP_AWK_ENOMEM);
return -1;
}
if (a0->type != XP_AWK_VAL_STR) xp_free (str);
if (a0->type != XP_AWK_VAL_STR) XP_AWK_FREE (awk, str);
xp_awk_setretval (run, r);
return 0;
}
@ -762,7 +762,7 @@ static int __bfn_system (xp_awk_t* awk, void* run)
n = -1;
#endif
xp_free (cmd);
XP_AWK_FREE (awk, cmd);
v = xp_awk_makeintval (run, n);
if (v == XP_NULL)

View File

@ -1,5 +1,5 @@
/*
* $Id: parse.c,v 1.172 2006-08-31 13:56:46 bacon Exp $
* $Id: parse.c,v 1.173 2006-08-31 14:52:12 bacon Exp $
*/
#include <xp/awk/awk_i.h>
@ -325,11 +325,6 @@ static struct __bvent __bvtab[] =
#define PANIC(awk,code) \
do { (awk)->errnum = (code); return XP_NULL; } while (0)
#define MALLOC(awk,size) \
(awk)->syscas->malloc (size, (awk)->syscas->custom_data)
#define FREE(awk,ptr) \
(awk)->syscas->free (ptr, (awk)->syscas->custom_data)
int xp_awk_parse (xp_awk_t* awk, xp_awk_srcios_t* srcios)
{
int n = 0;
@ -608,7 +603,7 @@ static xp_awk_nde_t* __parse_function (xp_awk_t* awk)
/* get the next token */
if (__get_token(awk) == -1)
{
FREE (awk, name_dup);
XP_AWK_FREE (awk, name_dup);
return XP_NULL;
}
@ -616,14 +611,14 @@ static xp_awk_nde_t* __parse_function (xp_awk_t* awk)
if (!MATCH(awk,TOKEN_LPAREN))
{
/* a function name is not followed by a left parenthesis */
FREE (awk, name_dup);
XP_AWK_FREE (awk, name_dup);
PANIC (awk, XP_AWK_ELPAREN);
}
/* get the next token */
if (__get_token(awk) == -1)
{
FREE (awk, name_dup);
XP_AWK_FREE (awk, name_dup);
return XP_NULL;
}
@ -636,7 +631,7 @@ static xp_awk_nde_t* __parse_function (xp_awk_t* awk)
/* no function parameter found. get the next token */
if (__get_token(awk) == -1)
{
FREE (awk, name_dup);
XP_AWK_FREE (awk, name_dup);
return XP_NULL;
}
}
@ -649,7 +644,7 @@ static xp_awk_nde_t* __parse_function (xp_awk_t* awk)
if (!MATCH(awk,TOKEN_IDENT))
{
FREE (awk, name_dup);
XP_AWK_FREE (awk, name_dup);
xp_awk_tab_clear (&awk->parse.params);
PANIC (awk, XP_AWK_EIDENT);
}
@ -663,7 +658,7 @@ static xp_awk_nde_t* __parse_function (xp_awk_t* awk)
if (xp_strxncmp (name_dup, name_len, param, param_len) == 0 ||
xp_awk_map_get (&awk->tree.afns, param, param_len) != XP_NULL)
{
FREE (awk, name_dup);
XP_AWK_FREE (awk, name_dup);
xp_awk_tab_clear (&awk->parse.params);
PANIC (awk, XP_AWK_EDUPNAME);
}
@ -680,7 +675,7 @@ static xp_awk_nde_t* __parse_function (xp_awk_t* awk)
&awk->parse.params,
0, param, param_len) != (xp_size_t)-1)
{
FREE (awk, name_dup);
XP_AWK_FREE (awk, name_dup);
xp_awk_tab_clear (&awk->parse.params);
PANIC (awk, XP_AWK_EDUPPARAM);
}
@ -689,7 +684,7 @@ static xp_awk_nde_t* __parse_function (xp_awk_t* awk)
if (xp_awk_tab_getsize (
&awk->parse.params) >= XP_AWK_MAX_PARAMS)
{
FREE (awk, name_dup);
XP_AWK_FREE (awk, name_dup);
xp_awk_tab_clear (&awk->parse.params);
PANIC (awk, XP_AWK_ETOOMANYPARAMS);
}
@ -698,14 +693,14 @@ static xp_awk_nde_t* __parse_function (xp_awk_t* awk)
&awk->parse.params,
param, param_len) == (xp_size_t)-1)
{
FREE (awk, name_dup);
XP_AWK_FREE (awk, name_dup);
xp_awk_tab_clear (&awk->parse.params);
PANIC (awk, XP_AWK_ENOMEM);
}
if (__get_token (awk) == -1)
{
FREE (awk, name_dup);
XP_AWK_FREE (awk, name_dup);
xp_awk_tab_clear (&awk->parse.params);
return XP_NULL;
}
@ -714,14 +709,14 @@ static xp_awk_nde_t* __parse_function (xp_awk_t* awk)
if (!MATCH(awk,TOKEN_COMMA))
{
FREE (awk, name_dup);
XP_AWK_FREE (awk, name_dup);
xp_awk_tab_clear (&awk->parse.params);
PANIC (awk, XP_AWK_ECOMMA);
}
if (__get_token(awk) == -1)
{
FREE (awk, name_dup);
XP_AWK_FREE (awk, name_dup);
xp_awk_tab_clear (&awk->parse.params);
return XP_NULL;
}
@ -729,7 +724,7 @@ static xp_awk_nde_t* __parse_function (xp_awk_t* awk)
if (__get_token(awk) == -1)
{
FREE (awk, name_dup);
XP_AWK_FREE (awk, name_dup);
xp_awk_tab_clear (&awk->parse.params);
return XP_NULL;
}
@ -738,13 +733,13 @@ static xp_awk_nde_t* __parse_function (xp_awk_t* awk)
/* check if the function body starts with a left brace */
if (!MATCH(awk,TOKEN_LBRACE))
{
FREE (awk, name_dup);
XP_AWK_FREE (awk, name_dup);
xp_awk_tab_clear (&awk->parse.params);
PANIC (awk, XP_AWK_ELBRACE);
}
if (__get_token(awk) == -1)
{
FREE (awk, name_dup);
XP_AWK_FREE (awk, name_dup);
xp_awk_tab_clear (&awk->parse.params);
return XP_NULL;
}
@ -753,7 +748,7 @@ static xp_awk_nde_t* __parse_function (xp_awk_t* awk)
body = __parse_block (awk, xp_true);
if (body == XP_NULL)
{
FREE (awk, name_dup);
XP_AWK_FREE (awk, name_dup);
xp_awk_tab_clear (&awk->parse.params);
return XP_NULL;
}
@ -764,10 +759,10 @@ static xp_awk_nde_t* __parse_function (xp_awk_t* awk)
/* parameter names are not required anymore. clear them */
xp_awk_tab_clear (&awk->parse.params);
afn = (xp_awk_afn_t*) MALLOC (awk, xp_sizeof(xp_awk_afn_t));
afn = (xp_awk_afn_t*) XP_AWK_MALLOC (awk, xp_sizeof(xp_awk_afn_t));
if (afn == XP_NULL)
{
FREE (awk, name_dup);
XP_AWK_FREE (awk, name_dup);
xp_awk_clrpt (body);
return XP_NULL;
}
@ -780,9 +775,9 @@ static xp_awk_nde_t* __parse_function (xp_awk_t* awk)
n = xp_awk_map_putx (&awk->tree.afns, name_dup, name_len, afn, &pair);
if (n < 0)
{
FREE (awk, name_dup);
XP_AWK_FREE (awk, name_dup);
xp_awk_clrpt (body);
FREE (awk, afn);
XP_AWK_FREE (awk, afn);
PANIC (awk, XP_AWK_ENOMEM);
}
@ -791,7 +786,7 @@ static xp_awk_nde_t* __parse_function (xp_awk_t* awk)
afn->name = pair->key; /* do some trick to save a string. */
afn->name_len = pair->key_len;
FREE (awk, name_dup);
XP_AWK_FREE (awk, name_dup);
return body;
}
@ -839,7 +834,7 @@ static xp_awk_chain_t* __parse_pattern_block (
if (nde == XP_NULL) return XP_NULL;
}
chain = (xp_awk_chain_t*) MALLOC (awk, xp_sizeof(xp_awk_chain_t));
chain = (xp_awk_chain_t*) XP_AWK_MALLOC (awk, xp_sizeof(xp_awk_chain_t));
if (chain == XP_NULL)
{
xp_awk_clrpt (nde);
@ -947,7 +942,7 @@ static xp_awk_nde_t* __parse_block (xp_awk_t* awk, xp_bool_t is_top)
curr = nde;
}
block = (xp_awk_nde_blk_t*) MALLOC (awk, xp_sizeof(xp_awk_nde_blk_t));
block = (xp_awk_nde_blk_t*) XP_AWK_MALLOC (awk, xp_sizeof(xp_awk_nde_blk_t));
if (block == XP_NULL)
{
xp_awk_tab_remove (
@ -1142,7 +1137,7 @@ static xp_awk_nde_t* __parse_statement (xp_awk_t* awk)
if (MATCH(awk,TOKEN_SEMICOLON))
{
/* null statement */
nde = (xp_awk_nde_t*) MALLOC (awk, xp_sizeof(xp_awk_nde_t));
nde = (xp_awk_nde_t*) XP_AWK_MALLOC (awk, xp_sizeof(xp_awk_nde_t));
if (nde == XP_NULL) PANIC (awk, XP_AWK_ENOMEM);
nde->type = XP_AWK_NDE_NULL;
@ -1150,7 +1145,7 @@ static xp_awk_nde_t* __parse_statement (xp_awk_t* awk)
if (__get_token(awk) == -1)
{
FREE (awk, nde);
XP_AWK_FREE (awk, nde);
return XP_NULL;
}
}
@ -1315,7 +1310,7 @@ static xp_awk_nde_t* __parse_expression (xp_awk_t* awk)
return XP_NULL;
}
nde = (xp_awk_nde_ass_t*) MALLOC (awk, xp_sizeof(xp_awk_nde_ass_t));
nde = (xp_awk_nde_ass_t*) XP_AWK_MALLOC (awk, xp_sizeof(xp_awk_nde_ass_t));
if (nde == XP_NULL)
{
xp_awk_clrpt (x);
@ -1363,7 +1358,7 @@ static xp_awk_nde_t* __parse_basic_expr (xp_awk_t* awk)
return XP_NULL;
}
tmp = (xp_awk_nde_cnd_t*) MALLOC (
tmp = (xp_awk_nde_cnd_t*) XP_AWK_MALLOC (
awk, xp_sizeof(xp_awk_nde_cnd_t));
if (tmp == XP_NULL)
{
@ -1470,7 +1465,7 @@ static xp_awk_nde_t* __parse_binary_expr (
/* TODO: enhance constant folding more... */
skip_constant_folding:
nde = (xp_awk_nde_exp_t*) MALLOC (
nde = (xp_awk_nde_exp_t*) XP_AWK_MALLOC (
awk, xp_sizeof(xp_awk_nde_exp_t));
if (nde == XP_NULL)
{
@ -1555,7 +1550,7 @@ static xp_awk_nde_t* __parse_in (xp_awk_t* awk)
PANIC (awk, XP_AWK_ENOTVAR);
}
nde = (xp_awk_nde_exp_t*) MALLOC (
nde = (xp_awk_nde_exp_t*) XP_AWK_MALLOC (
awk, xp_sizeof(xp_awk_nde_exp_t));
if (nde == XP_NULL)
{
@ -1655,7 +1650,7 @@ static xp_awk_nde_t* __parse_bitwise_or_with_extio (xp_awk_t* awk)
}
}
nde = (xp_awk_nde_getline_t*) MALLOC (
nde = (xp_awk_nde_getline_t*) XP_AWK_MALLOC (
awk, xp_sizeof(xp_awk_nde_getline_t));
if (nde == XP_NULL)
{
@ -1690,7 +1685,7 @@ static xp_awk_nde_t* __parse_bitwise_or_with_extio (xp_awk_t* awk)
/* TODO: do constant folding */
nde = (xp_awk_nde_exp_t*) MALLOC (
nde = (xp_awk_nde_exp_t*) XP_AWK_MALLOC (
awk, xp_sizeof(xp_awk_nde_exp_t));
if (nde == XP_NULL)
{
@ -1793,7 +1788,7 @@ static xp_awk_nde_t* __parse_concat (xp_awk_t* awk)
return XP_NULL;
}
nde = (xp_awk_nde_exp_t*) MALLOC (
nde = (xp_awk_nde_exp_t*) XP_AWK_MALLOC (
awk, xp_sizeof(xp_awk_nde_exp_t));
if (nde == XP_NULL)
{
@ -1858,7 +1853,7 @@ static xp_awk_nde_t* __parse_unary (xp_awk_t* awk)
left = __parse_unary (awk);
if (left == XP_NULL) return XP_NULL;
nde = (xp_awk_nde_exp_t*) MALLOC (awk, xp_sizeof(xp_awk_nde_exp_t));
nde = (xp_awk_nde_exp_t*) XP_AWK_MALLOC (awk, xp_sizeof(xp_awk_nde_exp_t));
if (nde == XP_NULL)
{
xp_awk_clrpt (left);
@ -1916,7 +1911,7 @@ static xp_awk_nde_t* __parse_increment (xp_awk_t* awk)
if (__get_token(awk) == -1) return XP_NULL;
}
nde = (xp_awk_nde_exp_t*) MALLOC (awk, xp_sizeof(xp_awk_nde_exp_t));
nde = (xp_awk_nde_exp_t*) XP_AWK_MALLOC (awk, xp_sizeof(xp_awk_nde_exp_t));
if (nde == XP_NULL)
{
xp_awk_clrpt (left);
@ -1942,7 +1937,7 @@ static xp_awk_nde_t* __parse_primary (xp_awk_t* awk)
{
xp_awk_nde_int_t* nde;
nde = (xp_awk_nde_int_t*) MALLOC (
nde = (xp_awk_nde_int_t*) XP_AWK_MALLOC (
awk, xp_sizeof(xp_awk_nde_int_t));
if (nde == XP_NULL) PANIC (awk, XP_AWK_ENOMEM);
@ -1957,7 +1952,7 @@ static xp_awk_nde_t* __parse_primary (xp_awk_t* awk)
if (__get_token(awk) == -1)
{
FREE (awk, nde);
XP_AWK_FREE (awk, nde);
return XP_NULL;
}
@ -1967,7 +1962,7 @@ static xp_awk_nde_t* __parse_primary (xp_awk_t* awk)
{
xp_awk_nde_real_t* nde;
nde = (xp_awk_nde_real_t*) MALLOC (
nde = (xp_awk_nde_real_t*) XP_AWK_MALLOC (
awk, xp_sizeof(xp_awk_nde_real_t));
if (nde == XP_NULL) PANIC (awk, XP_AWK_ENOMEM);
@ -1981,7 +1976,7 @@ static xp_awk_nde_t* __parse_primary (xp_awk_t* awk)
if (__get_token(awk) == -1)
{
FREE (awk, nde);
XP_AWK_FREE (awk, nde);
return XP_NULL;
}
@ -1991,7 +1986,7 @@ static xp_awk_nde_t* __parse_primary (xp_awk_t* awk)
{
xp_awk_nde_str_t* nde;
nde = (xp_awk_nde_str_t*) MALLOC (
nde = (xp_awk_nde_str_t*) XP_AWK_MALLOC (
awk, xp_sizeof(xp_awk_nde_str_t));
if (nde == XP_NULL) PANIC (awk, XP_AWK_ENOMEM);
@ -2001,14 +1996,14 @@ static xp_awk_nde_t* __parse_primary (xp_awk_t* awk)
nde->buf = xp_strxdup(XP_STR_BUF(&awk->token.name), nde->len);
if (nde->buf == XP_NULL)
{
FREE (awk, nde);
XP_AWK_FREE (awk, nde);
PANIC (awk, XP_AWK_ENOMEM);
}
if (__get_token(awk) == -1)
{
FREE (awk, nde->buf);
FREE (awk, nde);
XP_AWK_FREE (awk, nde->buf);
XP_AWK_FREE (awk, nde);
return XP_NULL;
}
@ -2026,7 +2021,7 @@ static xp_awk_nde_t* __parse_primary (xp_awk_t* awk)
if (__get_rexstr (awk) == -1) return XP_NULL;
xp_assert (MATCH(awk,TOKEN_REX));
nde = (xp_awk_nde_rex_t*) MALLOC (
nde = (xp_awk_nde_rex_t*) XP_AWK_MALLOC (
awk, xp_sizeof(xp_awk_nde_rex_t));
if (nde == XP_NULL) PANIC (awk, XP_AWK_ENOMEM);
@ -2039,7 +2034,7 @@ static xp_awk_nde_t* __parse_primary (xp_awk_t* awk)
XP_STR_LEN(&awk->token.name));
if (nde->buf == XP_NULL)
{
FREE (awk, nde);
XP_AWK_FREE (awk, nde);
PANIC (awk, XP_AWK_ENOMEM);
}
@ -2049,16 +2044,16 @@ static xp_awk_nde_t* __parse_primary (xp_awk_t* awk)
&errnum);
if (nde->code == XP_NULL)
{
FREE (awk, nde->buf);
FREE (awk, nde);
XP_AWK_FREE (awk, nde->buf);
XP_AWK_FREE (awk, nde);
PANIC (awk, errnum);
}
if (__get_token(awk) == -1)
{
FREE (awk, nde->buf);
FREE (awk, nde->code);
FREE (awk, nde);
XP_AWK_FREE (awk, nde->buf);
XP_AWK_FREE (awk, nde->code);
XP_AWK_FREE (awk, nde);
return XP_NULL;
}
@ -2074,7 +2069,7 @@ static xp_awk_nde_t* __parse_primary (xp_awk_t* awk)
prim = __parse_primary (awk);
if (prim == XP_NULL) return XP_NULL;
nde = (xp_awk_nde_pos_t*) MALLOC (
nde = (xp_awk_nde_pos_t*) XP_AWK_MALLOC (
awk, xp_sizeof(xp_awk_nde_pos_t));
if (nde == XP_NULL)
{
@ -2154,7 +2149,7 @@ static xp_awk_nde_t* __parse_primary (xp_awk_t* awk)
PANIC (awk, XP_AWK_EIN);
}
tmp = (xp_awk_nde_grp_t*) MALLOC (
tmp = (xp_awk_nde_grp_t*) XP_AWK_MALLOC (
awk, xp_sizeof(xp_awk_nde_grp_t));
if (tmp == XP_NULL)
{
@ -2207,7 +2202,7 @@ static xp_awk_nde_t* __parse_primary (xp_awk_t* awk)
}
}
nde = (xp_awk_nde_getline_t*) MALLOC (
nde = (xp_awk_nde_getline_t*) XP_AWK_MALLOC (
awk, xp_sizeof(xp_awk_nde_getline_t));
if (nde == XP_NULL)
{
@ -2245,7 +2240,7 @@ static xp_awk_nde_t* __parse_primary_ident (xp_awk_t* awk)
if (__get_token(awk) == -1)
{
FREE (awk, name_dup);
XP_AWK_FREE (awk, name_dup);
return XP_NULL;
}
@ -2255,7 +2250,7 @@ static xp_awk_nde_t* __parse_primary_ident (xp_awk_t* awk)
{
xp_awk_nde_t* nde;
FREE (awk, name_dup);
XP_AWK_FREE (awk, name_dup);
if (!MATCH(awk,TOKEN_LPAREN))
{
/* built-in function should be in the form
@ -2272,7 +2267,7 @@ static xp_awk_nde_t* __parse_primary_ident (xp_awk_t* awk)
{
xp_awk_nde_t* nde;
nde = __parse_hashidx (awk, name_dup, name_len);
if (nde == XP_NULL) FREE (awk, name_dup);
if (nde == XP_NULL) XP_AWK_FREE (awk, name_dup);
return (xp_awk_nde_t*)nde;
}
else if (MATCH(awk,TOKEN_LPAREN))
@ -2280,7 +2275,7 @@ static xp_awk_nde_t* __parse_primary_ident (xp_awk_t* awk)
/* function call */
xp_awk_nde_t* nde;
nde = __parse_fncall (awk, name_dup, name_len, XP_NULL);
if (nde == XP_NULL) FREE (awk, name_dup);
if (nde == XP_NULL) XP_AWK_FREE (awk, name_dup);
return (xp_awk_nde_t*)nde;
}
else
@ -2289,11 +2284,11 @@ static xp_awk_nde_t* __parse_primary_ident (xp_awk_t* awk)
xp_awk_nde_var_t* nde;
xp_size_t idxa;
nde = (xp_awk_nde_var_t*) MALLOC (
nde = (xp_awk_nde_var_t*) XP_AWK_MALLOC (
awk, xp_sizeof(xp_awk_nde_var_t));
if (nde == XP_NULL)
{
FREE (awk, name_dup);
XP_AWK_FREE (awk, name_dup);
PANIC (awk, XP_AWK_ENOMEM);
}
@ -2358,8 +2353,8 @@ static xp_awk_nde_t* __parse_primary_ident (xp_awk_t* awk)
}
/* undefined variable */
FREE (awk, name_dup);
FREE (awk, nde);
XP_AWK_FREE (awk, name_dup);
XP_AWK_FREE (awk, nde);
PANIC (awk, XP_AWK_EUNDEF);
}
}
@ -2416,7 +2411,7 @@ static xp_awk_nde_t* __parse_hashidx (
return XP_NULL;
}
nde = (xp_awk_nde_var_t*) MALLOC (awk, xp_sizeof(xp_awk_nde_var_t));
nde = (xp_awk_nde_var_t*) XP_AWK_MALLOC (awk, xp_sizeof(xp_awk_nde_var_t));
if (nde == XP_NULL)
{
xp_awk_clrpt (idx);
@ -2482,7 +2477,7 @@ static xp_awk_nde_t* __parse_hashidx (
/* undefined variable */
xp_awk_clrpt (idx);
FREE (awk, nde);
XP_AWK_FREE (awk, nde);
PANIC (awk, XP_AWK_EUNDEF);
}
@ -2548,7 +2543,7 @@ static xp_awk_nde_t* __parse_fncall (
}
call = (xp_awk_nde_call_t*) MALLOC (awk, xp_sizeof(xp_awk_nde_call_t));
call = (xp_awk_nde_call_t*) XP_AWK_MALLOC (awk, xp_sizeof(xp_awk_nde_call_t));
if (call == XP_NULL)
{
if (head != XP_NULL) xp_awk_clrpt (head);
@ -2635,7 +2630,7 @@ static xp_awk_nde_t* __parse_if (xp_awk_t* awk)
}
else else_part = XP_NULL;
nde = (xp_awk_nde_if_t*) MALLOC (awk, xp_sizeof(xp_awk_nde_if_t));
nde = (xp_awk_nde_if_t*) XP_AWK_MALLOC (awk, xp_sizeof(xp_awk_nde_if_t));
if (nde == XP_NULL)
{
xp_awk_clrpt (else_part);
@ -2683,7 +2678,7 @@ static xp_awk_nde_t* __parse_while (xp_awk_t* awk)
return XP_NULL;
}
nde = (xp_awk_nde_while_t*) MALLOC (awk, xp_sizeof(xp_awk_nde_while_t));
nde = (xp_awk_nde_while_t*) XP_AWK_MALLOC (awk, xp_sizeof(xp_awk_nde_while_t));
if (nde == XP_NULL)
{
xp_awk_clrpt (body);
@ -2745,7 +2740,7 @@ static xp_awk_nde_t* __parse_for (xp_awk_t* awk)
return XP_NULL;
}
nde2 = (xp_awk_nde_foreach_t*) MALLOC (
nde2 = (xp_awk_nde_foreach_t*) XP_AWK_MALLOC (
awk, xp_sizeof(xp_awk_nde_foreach_t));
if (nde2 == XP_NULL)
{
@ -2837,7 +2832,7 @@ static xp_awk_nde_t* __parse_for (xp_awk_t* awk)
return XP_NULL;
}
nde = (xp_awk_nde_for_t*) MALLOC (awk, xp_sizeof(xp_awk_nde_for_t));
nde = (xp_awk_nde_for_t*) XP_AWK_MALLOC (awk, xp_sizeof(xp_awk_nde_for_t));
if (nde == XP_NULL)
{
xp_awk_clrpt (init);
@ -2910,7 +2905,7 @@ static xp_awk_nde_t* __parse_dowhile (xp_awk_t* awk)
return XP_NULL;
}
nde = (xp_awk_nde_while_t*) MALLOC (awk, xp_sizeof(xp_awk_nde_while_t));
nde = (xp_awk_nde_while_t*) XP_AWK_MALLOC (awk, xp_sizeof(xp_awk_nde_while_t));
if (nde == XP_NULL)
{
xp_awk_clrpt (body);
@ -2932,7 +2927,7 @@ static xp_awk_nde_t* __parse_break (xp_awk_t* awk)
if (awk->parse.depth.loop <= 0) PANIC (awk, XP_AWK_EBREAK);
nde = (xp_awk_nde_break_t*) MALLOC (awk, xp_sizeof(xp_awk_nde_break_t));
nde = (xp_awk_nde_break_t*) XP_AWK_MALLOC (awk, xp_sizeof(xp_awk_nde_break_t));
if (nde == XP_NULL) PANIC (awk, XP_AWK_ENOMEM);
nde->type = XP_AWK_NDE_BREAK;
nde->next = XP_NULL;
@ -2946,7 +2941,7 @@ static xp_awk_nde_t* __parse_continue (xp_awk_t* awk)
if (awk->parse.depth.loop <= 0) PANIC (awk, XP_AWK_ECONTINUE);
nde = (xp_awk_nde_continue_t*) MALLOC (
nde = (xp_awk_nde_continue_t*) XP_AWK_MALLOC (
awk, xp_sizeof(xp_awk_nde_continue_t));
if (nde == XP_NULL) PANIC (awk, XP_AWK_ENOMEM);
nde->type = XP_AWK_NDE_CONTINUE;
@ -2960,7 +2955,7 @@ static xp_awk_nde_t* __parse_return (xp_awk_t* awk)
xp_awk_nde_return_t* nde;
xp_awk_nde_t* val;
nde = (xp_awk_nde_return_t*) MALLOC (
nde = (xp_awk_nde_return_t*) XP_AWK_MALLOC (
awk, xp_sizeof(xp_awk_nde_return_t));
if (nde == XP_NULL) PANIC (awk, XP_AWK_ENOMEM);
nde->type = XP_AWK_NDE_RETURN;
@ -2976,7 +2971,7 @@ static xp_awk_nde_t* __parse_return (xp_awk_t* awk)
val = __parse_expression (awk);
if (val == XP_NULL)
{
FREE (awk, nde);
XP_AWK_FREE (awk, nde);
return XP_NULL;
}
}
@ -2990,7 +2985,7 @@ static xp_awk_nde_t* __parse_exit (xp_awk_t* awk)
xp_awk_nde_exit_t* nde;
xp_awk_nde_t* val;
nde = (xp_awk_nde_exit_t*) MALLOC (awk, xp_sizeof(xp_awk_nde_exit_t));
nde = (xp_awk_nde_exit_t*) XP_AWK_MALLOC (awk, xp_sizeof(xp_awk_nde_exit_t));
if (nde == XP_NULL) PANIC (awk, XP_AWK_ENOMEM);
nde->type = XP_AWK_NDE_EXIT;
nde->next = XP_NULL;
@ -3005,7 +3000,7 @@ static xp_awk_nde_t* __parse_exit (xp_awk_t* awk)
val = __parse_expression (awk);
if (val == XP_NULL)
{
FREE (awk, nde);
XP_AWK_FREE (awk, nde);
return XP_NULL;
}
}
@ -3031,7 +3026,7 @@ static xp_awk_nde_t* __parse_delete (xp_awk_t* awk)
PANIC (awk, XP_AWK_EIDENT);
}
nde = (xp_awk_nde_delete_t*) MALLOC (
nde = (xp_awk_nde_delete_t*) XP_AWK_MALLOC (
awk, xp_sizeof(xp_awk_nde_delete_t));
if (nde == XP_NULL) PANIC (awk, XP_AWK_ENOMEM);
@ -3099,7 +3094,7 @@ static xp_awk_nde_t* __parse_print (xp_awk_t* awk)
out = ep->right;
out_type = XP_AWK_OUT_FILE;
FREE (awk, tmp);
XP_AWK_FREE (awk, tmp);
}
else if (ep->opcode == XP_AWK_BINOP_RSHIFT)
{
@ -3112,7 +3107,7 @@ static xp_awk_nde_t* __parse_print (xp_awk_t* awk)
out = ep->right;
out_type = XP_AWK_OUT_FILE_APPEND;
FREE (awk, tmp);
XP_AWK_FREE (awk, tmp);
}
else if (ep->opcode == XP_AWK_BINOP_BOR)
{
@ -3125,7 +3120,7 @@ static xp_awk_nde_t* __parse_print (xp_awk_t* awk)
out = ep->right;
out_type = XP_AWK_OUT_PIPE;
FREE (awk, tmp);
XP_AWK_FREE (awk, tmp);
}
}
}
@ -3155,7 +3150,7 @@ static xp_awk_nde_t* __parse_print (xp_awk_t* awk)
}
}
nde = (xp_awk_nde_print_t*) MALLOC (awk, xp_sizeof(xp_awk_nde_print_t));
nde = (xp_awk_nde_print_t*) XP_AWK_MALLOC (awk, xp_sizeof(xp_awk_nde_print_t));
if (nde == XP_NULL)
{
if (args != XP_NULL) xp_awk_clrpt (args);
@ -3188,7 +3183,7 @@ static xp_awk_nde_t* __parse_next (xp_awk_t* awk)
PANIC (awk, XP_AWK_ENEXT);
}
nde = (xp_awk_nde_next_t*) MALLOC (awk, xp_sizeof(xp_awk_nde_next_t));
nde = (xp_awk_nde_next_t*) XP_AWK_MALLOC (awk, xp_sizeof(xp_awk_nde_next_t));
if (nde == XP_NULL) PANIC (awk, XP_AWK_ENOMEM);
nde->type = XP_AWK_NDE_NEXT;
nde->next = XP_NULL;
@ -3206,7 +3201,7 @@ static xp_awk_nde_t* __parse_nextfile (xp_awk_t* awk)
PANIC (awk, XP_AWK_ENEXTFILE);
}
nde = (xp_awk_nde_nextfile_t*) MALLOC (
nde = (xp_awk_nde_nextfile_t*) XP_AWK_MALLOC (
awk, xp_sizeof(xp_awk_nde_nextfile_t));
if (nde == XP_NULL) PANIC (awk, XP_AWK_ENOMEM);
nde->type = XP_AWK_NDE_NEXTFILE;

View File

@ -1,5 +1,5 @@
/*
* $Id: run.c,v 1.186 2006-08-31 04:21:03 bacon Exp $
* $Id: run.c,v 1.187 2006-08-31 14:52:12 bacon Exp $
*/
#include <xp/awk/awk_i.h>
@ -266,7 +266,7 @@ int xp_awk_setglobal (void* run, xp_size_t idx, xp_awk_val_t* val)
if (rex == XP_NULL)
{
if (val->type != XP_AWK_VAL_STR)
xp_free (rs_ptr);
XP_AWK_FREE (((xp_awk_run_t*)run)->awk, rs_ptr);
return -1;
}
@ -275,7 +275,8 @@ int xp_awk_setglobal (void* run, xp_size_t idx, xp_awk_val_t* val)
r->extio.rs_rex = rex;
}
if (val->type != XP_AWK_VAL_STR) xp_free (rs_ptr);
if (val->type != XP_AWK_VAL_STR)
XP_AWK_FREE (((xp_awk_run_t*)run)->awk, rs_ptr);
}
/* TODO: if idx == XP_AWK_GLOBAL_NF recompute $0, etc */
@ -309,7 +310,7 @@ int xp_awk_run (xp_awk_t* awk, xp_awk_runios_t* runios, xp_awk_runcbs_t* runcbs)
awk->errnum = XP_AWK_ENOERR;
run = (xp_awk_run_t*) xp_malloc (xp_sizeof(xp_awk_run_t));
run = (xp_awk_run_t*) XP_AWK_MALLOC (awk, xp_sizeof(xp_awk_run_t));
if (run == XP_NULL)
{
awk->errnum = XP_AWK_ENOMEM;
@ -322,7 +323,7 @@ int xp_awk_run (xp_awk_t* awk, xp_awk_runios_t* runios, xp_awk_runcbs_t* runcbs)
{
awk->errnum = errnum;
__del_run (awk, run);
xp_free (run);
awk->syscas->free (run, awk->syscas->custom_data);
return -1;
}
@ -353,7 +354,7 @@ int xp_awk_run (xp_awk_t* awk, xp_awk_runios_t* runios, xp_awk_runcbs_t* runcbs)
__deinit_run (run);
__del_run (awk, run);
xp_free (run);
awk->syscas->free (run, awk->syscas->custom_data);
return n;
}
@ -541,7 +542,7 @@ static int __init_run (
static void __deinit_run (xp_awk_run_t* run)
{
xp_free (run->pattern_range_state);
XP_AWK_FREE (run->awk, run->pattern_range_state);
/* close all pending eio's */
/* TODO: what if this operation fails? */
@ -549,7 +550,7 @@ static void __deinit_run (xp_awk_run_t* run)
xp_assert (run->extio.chain == XP_NULL);
if (run->extio.rs_rex != XP_NULL)
{
xp_free (run->extio.rs_rex);
XP_AWK_FREE (run->awk, run->extio.rs_rex);
run->extio.rs_rex = XP_NULL;
}
@ -559,7 +560,7 @@ static void __deinit_run (xp_awk_run_t* run)
__clear_record (run, xp_false);
if (run->inrec.flds != XP_NULL)
{
xp_free (run->inrec.flds);
XP_AWK_FREE (run->awk, run->inrec.flds);
run->inrec.flds = XP_NULL;
run->inrec.maxflds = 0;
}
@ -570,7 +571,7 @@ static void __deinit_run (xp_awk_run_t* run)
{
xp_assert (run->stack_top == 0);
xp_free (run->stack);
XP_AWK_FREE (run->awk, run->stack);
run->stack = XP_NULL;
run->stack_top = 0;
run->stack_base = 0;
@ -1591,7 +1592,7 @@ static int __run_delete (xp_awk_run_t* run, xp_awk_nde_delete_t* nde)
if (key == XP_NULL) return -1;
xp_awk_map_remove (map, key, key_len);
xp_free (key);
XP_AWK_FREE (run->awk, key);
}
else
{
@ -1683,7 +1684,7 @@ static int __run_delete (xp_awk_run_t* run, xp_awk_nde_delete_t* nde)
if (key == XP_NULL) return -1;
xp_awk_map_remove (map, key, key_len);
xp_free (key);
XP_AWK_FREE (run->awk, key);
}
else
{
@ -1735,7 +1736,7 @@ static int __run_print (xp_awk_run_t* run, xp_awk_nde_print_t* nde)
if (len <= 0)
{
/* the output destination name is empty. */
xp_free (out);
XP_AWK_FREE (run->awk, out);
n = -1;
goto skip_write;
}
@ -1746,7 +1747,7 @@ static int __run_print (xp_awk_run_t* run, xp_awk_nde_print_t* nde)
{
/* the output destination name contains a null
* character. */
xp_free (out);
XP_AWK_FREE (run->awk, out);
n = -1;
goto skip_write;
/* TODO: how to handle error???
@ -1770,7 +1771,7 @@ static int __run_print (xp_awk_run_t* run, xp_awk_nde_print_t* nde)
n = xp_awk_writeextio (run, p->out_type, dst, v);
if (n < 0 && run->errnum != XP_AWK_EIOHANDLER)
{
if (out != XP_NULL) xp_free (out);
if (out != XP_NULL) XP_AWK_FREE (run->awk, out);
xp_awk_refdownval (run, v);
return -1;
}
@ -1785,7 +1786,7 @@ static int __run_print (xp_awk_run_t* run, xp_awk_nde_print_t* nde)
v = __eval_expression (run, np);
if (v == XP_NULL)
{
if (out != XP_NULL) xp_free (out);
if (out != XP_NULL) XP_AWK_FREE (run->awk, out);
return -1;
}
xp_awk_refupval (v);
@ -1793,7 +1794,7 @@ static int __run_print (xp_awk_run_t* run, xp_awk_nde_print_t* nde)
n = xp_awk_writeextio (run, p->out_type, dst, v);
if (n < 0 && run->errnum != XP_AWK_EIOHANDLER)
{
if (out != XP_NULL) xp_free (out);
if (out != XP_NULL) XP_AWK_FREE (run->awk, out);
xp_awk_refdownval (run, v);
return -1;
}
@ -1811,14 +1812,14 @@ static int __run_print (xp_awk_run_t* run, xp_awk_nde_print_t* nde)
n = xp_awk_writeextio_nl (run, p->out_type, dst, xp_awk_val_nil);
if (n < 0 && run->errnum != XP_AWK_EIOHANDLER)
{
if (out != XP_NULL) xp_free (out);
if (out != XP_NULL) XP_AWK_FREE (run->awk, out);
return -1;
}
/* TODO: how to handle n == -1 && errnum == XP_AWK_EIOHANDLER.
* that is the user handler returned an error... */
if (out != XP_NULL) xp_free (out);
if (out != XP_NULL) XP_AWK_FREE (run->awk, out);
skip_write:
return 0;
@ -2200,11 +2201,11 @@ xp_printf (XP_T("**** index str=>%s, map->ref=%d, map->type=%d\n"), str, map->re
n = xp_awk_map_putx (map->map, str, len, val, XP_NULL);
if (n < 0)
{
xp_free (str);
XP_AWK_FREE (run->awk, str);
PANIC (run, XP_AWK_ENOMEM);
}
xp_free (str);
XP_AWK_FREE (run->awk, str);
xp_awk_refupval (val);
return val;
}
@ -2239,16 +2240,16 @@ static xp_awk_val_t* __do_assignment_pos (
{
if (__clear_record (run, xp_false) == -1)
{
xp_free (str);
XP_AWK_FREE (run->awk, str);
return XP_NULL;
}
if (xp_str_ncpy (&run->inrec.line, str, len) == (xp_size_t)-1)
{
xp_free (str);
XP_AWK_FREE (run->awk, str);
PANIC (run, XP_AWK_ENOMEM);
}
xp_free (str);
XP_AWK_FREE (run->awk, str);
if (val->type == XP_AWK_VAL_STR)
{
@ -2287,12 +2288,12 @@ static xp_awk_val_t* __do_assignment_pos (
if (__recomp_record_fields (run, (xp_size_t)lv, str, len) == -1)
{
errnum = run->errnum;
xp_free (str);
XP_AWK_FREE (run->awk, str);
__clear_record (run, xp_false);
run->errnum = errnum;
return XP_NULL;
}
xp_free (str);
XP_AWK_FREE (run->awk, str);
/* recompose $0 */
v = xp_awk_makestrval (
@ -2529,7 +2530,7 @@ static xp_awk_val_t* __eval_binop_in (
rv = __eval_expression (run, right);
if (rv == XP_NULL)
{
xp_free (str);
XP_AWK_FREE (run->awk, str);
return XP_NULL;
}
@ -2540,12 +2541,12 @@ static xp_awk_val_t* __eval_binop_in (
res = xp_awk_makeintval (run, 0);
if (res == XP_NULL)
{
xp_free (str);
XP_AWK_FREE (run->awk, str);
xp_awk_refdownval (run, rv);
PANIC (run, XP_AWK_ENOMEM);
}
xp_free (str);
XP_AWK_FREE (run->awk, str);
xp_awk_refdownval (run, rv);
return res;
}
@ -2558,12 +2559,12 @@ static xp_awk_val_t* __eval_binop_in (
res = xp_awk_makeintval (run, r);
if (res == XP_NULL)
{
xp_free (str);
XP_AWK_FREE (run->awk, str);
xp_awk_refdownval (run, rv);
PANIC (run, XP_AWK_ENOMEM);
}
xp_free (str);
XP_AWK_FREE (run->awk, str);
xp_awk_refdownval (run, rv);
return res;
}
@ -3193,20 +3194,20 @@ static xp_awk_val_t* __eval_binop_concat (
strr = xp_awk_valtostr (right, &errnum, xp_true, XP_NULL, &strr_len);
if (strr == XP_NULL)
{
xp_free (strl);
XP_AWK_FREE (run->awk, strl);
PANIC (run, errnum);
}
res = xp_awk_makestrval2 (strl, strl_len, strr, strr_len);
if (res == XP_NULL)
{
xp_free (strl);
xp_free (strr);
XP_AWK_FREE (run->awk, strl);
XP_AWK_FREE (run->awk, strr);
PANIC (run, XP_AWK_ENOMEM);
}
xp_free (strl);
xp_free (strr);
XP_AWK_FREE (run->awk, strl);
XP_AWK_FREE (run->awk, strr);
return res;
}
@ -3303,11 +3304,11 @@ static xp_awk_val_t* __eval_binop_match0 (
rex_code = xp_awk_buildrex (str, len, &errnum);
if (rex_code == XP_NULL)
{
xp_free (str);
XP_AWK_FREE (run->awk, str);
PANIC (run, errnum);
}
xp_free (str);
XP_AWK_FREE (run->awk, str);
}
if (left->type == XP_AWK_VAL_STR)
@ -3319,14 +3320,16 @@ static xp_awk_val_t* __eval_binop_match0 (
XP_NULL, XP_NULL, &errnum);
if (n == -1)
{
if (right->type != XP_AWK_VAL_REX) xp_free (rex_code);
if (right->type != XP_AWK_VAL_REX)
XP_AWK_FREE (run->awk, rex_code);
PANIC (run, errnum);
}
res = xp_awk_makeintval (run, (n == ret));
if (res == XP_NULL)
{
if (right->type != XP_AWK_VAL_REX) xp_free (rex_code);
if (right->type != XP_AWK_VAL_REX)
XP_AWK_FREE (run->awk, rex_code);
PANIC (run, XP_AWK_ENOMEM);
}
}
@ -3335,7 +3338,8 @@ static xp_awk_val_t* __eval_binop_match0 (
str = xp_awk_valtostr (left, &errnum, xp_true, XP_NULL, &len);
if (str == XP_NULL)
{
if (right->type != XP_AWK_VAL_REX) xp_free (rex_code);
if (right->type != XP_AWK_VAL_REX)
XP_AWK_FREE (run->awk, rex_code);
PANIC (run, errnum);
}
@ -3343,23 +3347,25 @@ static xp_awk_val_t* __eval_binop_match0 (
rex_code, str, len, XP_NULL, XP_NULL, &errnum);
if (n == -1)
{
xp_free (str);
if (right->type != XP_AWK_VAL_REX) xp_free (rex_code);
XP_AWK_FREE (run->awk, str);
if (right->type != XP_AWK_VAL_REX)
XP_AWK_FREE (run->awk, rex_code);
PANIC (run, errnum);
}
res = xp_awk_makeintval (run, (n == ret));
if (res == XP_NULL)
{
xp_free (str);
if (right->type != XP_AWK_VAL_REX) xp_free (rex_code);
XP_AWK_FREE (run->awk, str);
if (right->type != XP_AWK_VAL_REX)
XP_AWK_FREE (run->awk, rex_code);
PANIC (run, XP_AWK_ENOMEM);
}
xp_free (str);
XP_AWK_FREE (run->awk, str);
}
if (right->type != XP_AWK_VAL_REX) xp_free (rex_code);
if (right->type != XP_AWK_VAL_REX) XP_AWK_FREE (run->awk, rex_code);
return res;
}
@ -4239,14 +4245,14 @@ static xp_awk_val_t** __get_reference_indexed (
str, len, xp_awk_val_nil);
if (pair == XP_NULL)
{
xp_free (str);
XP_AWK_FREE (run->awk, str);
PANIC (run, XP_AWK_ENOMEM);
}
xp_awk_refupval (pair->val);
}
xp_free (str);
XP_AWK_FREE (run->awk, str);
return (xp_awk_val_t**)&pair->val;
}
@ -4350,7 +4356,7 @@ static xp_awk_val_t* __eval_indexed (
if (str == XP_NULL) return XP_NULL;
pair = xp_awk_map_get ((*(xp_awk_val_map_t**)val)->map, str, len);
xp_free (str);
XP_AWK_FREE (run->awk, str);
return (pair == XP_NULL)? xp_awk_val_nil: (xp_awk_val_t*)pair->val;
}
@ -4459,7 +4465,7 @@ static xp_awk_val_t* __eval_getline (xp_awk_run_t* run, xp_awk_nde_t* nde)
{
/* the input source name is empty.
* make getline return -1 */
xp_free (in);
XP_AWK_FREE (run->awk, in);
n = -1;
goto skip_read;
}
@ -4471,7 +4477,7 @@ static xp_awk_val_t* __eval_getline (xp_awk_run_t* run, xp_awk_nde_t* nde)
/* the input source name contains a null
* character. make getline return -1 */
/* TODO: set ERRNO */
xp_free (in);
XP_AWK_FREE (run->awk, in);
n = -1;
goto skip_read;
}
@ -4483,12 +4489,12 @@ static xp_awk_val_t* __eval_getline (xp_awk_run_t* run, xp_awk_nde_t* nde)
/* TODO: optimize the line buffer management */
if (xp_str_open (&buf, DEF_BUF_CAPA) == XP_NULL)
{
if (in != XP_NULL) xp_free (in);
if (in != XP_NULL) XP_AWK_FREE (run->awk, in);
PANIC (run, XP_AWK_ENOMEM);
}
n = xp_awk_readextio (run, p->in_type, dst, &buf);
if (in != XP_NULL) xp_free (in);
if (in != XP_NULL) XP_AWK_FREE (run->awk, in);
if (n < 0)
{
@ -4564,20 +4570,24 @@ static int __raw_push (xp_awk_run_t* run, void* val)
n = run->stack_limit + STACK_INCREMENT;
#ifndef XP_AWK_NTDDK
tmp = (void**) xp_realloc (
run->stack, n * xp_sizeof(void*));
if (run->awk->syscas->realloc != XP_NULL)
{
tmp = (void**) XP_AWK_REALLOC (
run->awk, run->stack, n * xp_sizeof(void*));
if (tmp == XP_NULL) return -1;
#else
tmp = (void**) xp_malloc (n * xp_sizeof(void*));
}
else
{
tmp = (void**) XP_AWK_MALLOC (
run->awk, n * xp_sizeof(void*));
if (tmp == XP_NULL) return -1;
if (run->stack != XP_NULL)
{
xp_memcpy (tmp, run->stack,
run->stack_limit * xp_sizeof(void*));
xp_free (run->stack);
XP_AWK_FREE (run->awk, run->stack);
}
}
#endif
run->stack = tmp;
run->stack_limit = n;
}
@ -4719,7 +4729,7 @@ static int __split_record (xp_awk_run_t* run)
#if 0
if (fs->type != XP_AWK_VAL_STR)
{
if (fs_ptr != XP_NULL) xp_free (fs_ptr);
if (fs_ptr != XP_NULL) XP_AWK_FREE (run->awk, fs_ptr);
}
#endif
return 0;
@ -4732,23 +4742,23 @@ static int __split_record (xp_awk_run_t* run)
(p - XP_STR_BUF(&run->inrec.line));
}
/* THIS PART IS WRONG. FREE IT AFTER THE NEXT SPLIT LOOP */
/* THIS PART IS WRONG. XP_AWK_FREE IT AFTER THE NEXT SPLIT LOOP */
#if 0
if (fs->type != XP_AWK_VAL_STR)
{
if (fs_ptr != XP_NULL) xp_free (fs_ptr);
if (fs_ptr != XP_NULL) XP_AWK_FREE (run->awk, fs_ptr);
}
#endif
/* allocate space */
if (nflds > run->inrec.maxflds)
{
void* tmp = xp_malloc (
xp_sizeof(*run->inrec.flds) * nflds);
void* tmp = XP_AWK_MALLOC (
run->awk, xp_sizeof(*run->inrec.flds) * nflds);
if (tmp == XP_NULL) PANIC_I (run, XP_AWK_ENOMEM);
if (run->inrec.flds != NULL)
xp_free (run->inrec.flds);
XP_AWK_FREE (run->awk, run->inrec.flds);
run->inrec.flds = tmp;
run->inrec.maxflds = nflds;
}
@ -4838,16 +4848,21 @@ static int __recomp_record_fields (
{
void* tmp;
#ifndef XP_AWK_NTDDK
tmp = xp_realloc (
run->inrec.flds, xp_sizeof(*run->inrec.flds) * max);
if (run->awk->syscas->realloc != XP_NULL)
{
tmp = XP_AWK_REALLOC (
run->awk, run->inrec.flds,
xp_sizeof(*run->inrec.flds) * max);
if (tmp == XP_NULL)
{
run->errnum = XP_AWK_ENOMEM;
return -1;
}
#else
tmp = xp_malloc (xp_sizeof(*run->inrec.flds) * max);
}
else
{
tmp = XP_AWK_MALLOC (
run->awk, xp_sizeof(*run->inrec.flds) * max);
if (tmp == XP_NULL)
{
run->errnum = XP_AWK_ENOMEM;
@ -4857,9 +4872,11 @@ static int __recomp_record_fields (
{
xp_memcpy (tmp, run->inrec.flds,
xp_sizeof(*run->inrec.flds) * run->inrec.maxflds);
xp_free (run->inrec.flds);
run->awk->syscas->free (
run->inrec.flds,
run->awk->syscas->custom_data);
}
}
#endif
run->inrec.flds = tmp;
run->inrec.maxflds = max;
@ -4897,7 +4914,7 @@ static int __recomp_record_fields (
&run->inrec.line,
ofs, ofs_len) == (xp_size_t)-1)
{
if (ofsp != XP_NULL) xp_free (ofsp);
if (ofsp != XP_NULL) XP_AWK_FREE (run->awk, ofsp);
run->errnum = XP_AWK_ENOMEM;
return -1;
}
@ -4915,7 +4932,7 @@ static int __recomp_record_fields (
if (xp_str_ncat (
&run->inrec.line, str, len) == (xp_size_t)-1)
{
if (ofsp != XP_NULL) xp_free (ofsp);
if (ofsp != XP_NULL) XP_AWK_FREE (run->awk, ofsp);
run->errnum = XP_AWK_ENOMEM;
return -1;
}
@ -4923,7 +4940,7 @@ static int __recomp_record_fields (
tmp = xp_awk_makestrval (str,len);
if (tmp == XP_NULL)
{
if (ofsp != XP_NULL) xp_free (ofsp);
if (ofsp != XP_NULL) XP_AWK_FREE (run->awk, ofsp);
run->errnum = XP_AWK_ENOMEM;
return -1;
}
@ -4944,7 +4961,7 @@ static int __recomp_record_fields (
if (xp_str_cat (
&run->inrec.line, XP_T("")) == (xp_size_t)-1)
{
if (ofsp != XP_NULL) xp_free (ofsp);
if (ofsp != XP_NULL) XP_AWK_FREE (run->awk, ofsp);
run->errnum = XP_AWK_ENOMEM;
return -1;
}
@ -4971,14 +4988,14 @@ static int __recomp_record_fields (
if (xp_str_ncat (&run->inrec.line,
tmp->buf, tmp->len) == (xp_size_t)-1)
{
if (ofsp != XP_NULL) xp_free (ofsp);
if (ofsp != XP_NULL) XP_AWK_FREE (run->awk, ofsp);
run->errnum = XP_AWK_ENOMEM;
return -1;
}
}
}
if (ofsp != XP_NULL) xp_free (ofsp);
if (ofsp != XP_NULL) XP_AWK_FREE (run->awk, ofsp);
v = STACK_GLOBAL(run, XP_AWK_GLOBAL_NF);
xp_assert (v->type == XP_AWK_VAL_INT);