*** empty log message ***

This commit is contained in:
hyung-hwan 2006-09-01 03:44:51 +00:00
parent c5c6d23a3b
commit 758bebd0d3
19 changed files with 475 additions and 438 deletions

View File

@ -1,5 +1,5 @@
/*
* $Id: awk.c,v 1.74 2006-08-31 16:00:18 bacon Exp $
* $Id: awk.c,v 1.75 2006-09-01 03:44:15 bacon Exp $
*/
#include <xp/awk/awk_i.h>
@ -33,7 +33,7 @@ xp_awk_t* xp_awk_open (xp_awk_syscas_t* syscas)
/* TODO: initial map size?? */
if (xp_awk_map_open (
&awk->tree.afns, awk, 256, __free_afn) == XP_NULL)
&awk->tree.afns, awk, 256, __free_afn, awk) == XP_NULL)
{
xp_awk_str_close (&awk->token.name);
XP_AWK_FREE (awk, awk);
@ -158,14 +158,14 @@ int xp_awk_clear (xp_awk_t* awk)
if (awk->tree.begin != XP_NULL)
{
xp_assert (awk->tree.begin->next == XP_NULL);
xp_awk_clrpt (awk->tree.begin);
xp_awk_clrpt (awk, awk->tree.begin);
awk->tree.begin = XP_NULL;
}
if (awk->tree.end != XP_NULL)
{
xp_assert (awk->tree.end->next == XP_NULL);
xp_awk_clrpt (awk->tree.end);
xp_awk_clrpt (awk, awk->tree.end);
awk->tree.end = XP_NULL;
}
@ -173,9 +173,9 @@ int xp_awk_clear (xp_awk_t* awk)
{
xp_awk_chain_t* next = awk->tree.chain->next;
if (awk->tree.chain->pattern != XP_NULL)
xp_awk_clrpt (awk->tree.chain->pattern);
xp_awk_clrpt (awk, awk->tree.chain->pattern);
if (awk->tree.chain->action != XP_NULL)
xp_awk_clrpt (awk->tree.chain->action);
xp_awk_clrpt (awk, awk->tree.chain->action);
XP_AWK_FREE (awk, awk->tree.chain);
awk->tree.chain = next;
}
@ -202,7 +202,7 @@ static void __free_afn (void* owner, void* afn)
/* f->name doesn't have to be freed */
/*XP_AWK_FREE ((xp_awk_t*)owner, f->name);*/
xp_awk_clrpt (f->body);
xp_awk_clrpt ((xp_awk_t*)owner, f->body);
XP_AWK_FREE ((xp_awk_t*)owner, f);
}

View File

@ -1,5 +1,5 @@
/*
* $Id: awk.h,v 1.104 2006-08-31 04:21:03 bacon Exp $
* $Id: awk.h,v 1.105 2006-09-01 03:44:16 bacon Exp $
*/
#ifndef _XP_AWK_AWK_H_
@ -320,6 +320,16 @@ xp_long_t xp_awk_strtolong (
const xp_char_t* str, int base, const xp_char_t** endptr);
xp_real_t xp_awk_strtoreal (const xp_char_t* str);
/* string functions exported by awk.h */
xp_char_t* xp_awk_strdup (
xp_awk_t* awk, const xp_char_t* str);
xp_char_t* xp_awk_strxdup (
xp_awk_t* awk, const xp_char_t* str, xp_size_t len);
xp_char_t* xp_awk_strxdup2 (
xp_awk_t* awk,
const xp_char_t* str1, xp_size_t len1,
const xp_char_t* str2, xp_size_t len2);
/* utility functions to convert an error number ot a string */
const xp_char_t* xp_awk_geterrstr (int errnum);

View File

@ -1,5 +1,5 @@
/*
* $Id: extio.c,v 1.42 2006-08-31 16:00:18 bacon Exp $
* $Id: extio.c,v 1.43 2006-09-01 03:44:16 bacon Exp $
*/
#include <xp/awk/awk_i.h>
@ -128,7 +128,7 @@ int xp_awk_readextio (
return -1;
}
p->name = xp_strdup (name);
p->name = xp_awk_strdup (run->awk, name);
if (p->name == XP_NULL)
{
XP_AWK_FREE (run->awk, p);
@ -292,7 +292,8 @@ int xp_awk_readextio (
xp_assert (run->extio.rs_rex != NULL);
/* TODO: safematchrex */
n = xp_awk_matchrex (run->extio.rs_rex,
n = xp_awk_matchrex (
run->awk, run->extio.rs_rex,
XP_AWK_STR_BUF(buf), XP_AWK_STR_LEN(buf),
&match_ptr, &match_len, &run->errnum);
if (n == -1)
@ -454,7 +455,7 @@ static int __writeextio (
return -1;
}
p->name = xp_strdup (name);
p->name = xp_awk_strdup (run->awk, name);
if (p->name == XP_NULL)
{
XP_AWK_FREE (run->awk, p);

View File

@ -1,5 +1,5 @@
/*
* $Id: func.c,v 1.38 2006-08-31 15:39:13 bacon Exp $
* $Id: func.c,v 1.39 2006-09-01 03:44:16 bacon Exp $
*/
#include <xp/awk/awk_i.h>
@ -10,7 +10,6 @@
#include <xp/bas/assert.h>
#include <xp/bas/ctype.h>
#include <xp/bas/stdio.h>
#include <xp/bas/str.h>
#endif
#ifdef _WIN32
@ -581,15 +580,15 @@ static int __bfn_split (xp_awk_t* awk, void* run)
}
/* put it into the map */
/* TODO: remove dependency on xp_sprintf */
/* TODO: remove dependency on xp_awk_sprintf */
#if defined(__LCC__)
xp_sprintf (key, xp_countof(key), XP_T("%lld"), (long long)num);
xp_awk_sprintf (awk, key, xp_countof(key), XP_T("%lld"), (long long)num);
#elif defined(__BORLANDC__) || defined(_MSC_VER)
xp_sprintf (key, xp_countof(key), XP_T("%I64d"), (__int64)num);
xp_awk_sprintf (awk, key, xp_countof(key), XP_T("%I64d"), (__int64)num);
#elif defined(vax) || defined(__vax) || defined(_SCO_DS)
xp_sprintf (key, xp_countof(key), XP_T("%ld"), (long)num);
xp_awk_sprintf (awk, key, xp_countof(key), XP_T("%ld"), (long)num);
#else
xp_sprintf (key, xp_countof(key), XP_T("%lld"), (long long)num);
xp_awk_sprintf (awk, key, xp_countof(key), XP_T("%lld"), (long long)num);
#endif
if (xp_awk_map_putx (

View File

@ -1,5 +1,5 @@
/*
* $Id: map.c,v 1.21 2006-08-03 05:05:47 bacon Exp $
* $Id: map.c,v 1.22 2006-09-01 03:44:16 bacon Exp $
*/
#include <xp/awk/awk_i.h>
@ -17,28 +17,31 @@ static xp_size_t __hash (const xp_char_t* key, xp_size_t key_len);
#define FREE_PAIR(map,pair) \
do { \
xp_free ((xp_char_t*)(pair)->key); \
XP_AWK_FREE ((map)->awk, (xp_char_t*)(pair)->key); \
if ((map)->freeval != XP_NULL) \
(map)->freeval ((map)->owner, (pair)->val); \
xp_free (pair); \
XP_AWK_FREE ((map)->awk, pair); \
} while (0)
xp_awk_map_t* xp_awk_map_open (xp_awk_map_t* map,
void* owner, xp_size_t capa, void(*freeval)(void*,void*))
xp_awk_map_t* xp_awk_map_open (
xp_awk_map_t* map, void* owner, xp_size_t capa,
void(*freeval)(void*,void*), xp_awk_t* awk)
{
if (map == XP_NULL)
{
map = (xp_awk_map_t*) xp_malloc (xp_sizeof(xp_awk_map_t));
map = (xp_awk_map_t*) XP_AWK_MALLOC (
awk, xp_sizeof(xp_awk_map_t));
if (map == XP_NULL) return XP_NULL;
map->__dynamic = xp_true;
}
else map->__dynamic = xp_false;
map->awk = awk;
map->buck = (xp_awk_pair_t**)
xp_malloc (xp_sizeof(xp_awk_pair_t*) * capa);
XP_AWK_MALLOC (awk, xp_sizeof(xp_awk_pair_t*) * capa);
if (map->buck == XP_NULL)
{
if (map->__dynamic) xp_free (map);
if (map->__dynamic) XP_AWK_FREE (awk, map);
return XP_NULL;
}
@ -54,8 +57,8 @@ xp_awk_map_t* xp_awk_map_open (xp_awk_map_t* map,
void xp_awk_map_close (xp_awk_map_t* map)
{
xp_awk_map_clear (map);
xp_free (map->buck);
if (map->__dynamic) xp_free (map);
XP_AWK_FREE (map->awk, map->buck);
if (map->__dynamic) XP_AWK_FREE (map->awk, map);
}
void xp_awk_map_clear (xp_awk_map_t* map)
@ -138,16 +141,17 @@ int xp_awk_map_putx (
pair = pair->next;
}
pair = (xp_awk_pair_t*) xp_malloc (xp_sizeof(xp_awk_pair_t));
pair = (xp_awk_pair_t*) XP_AWK_MALLOC (
map->awk, xp_sizeof(xp_awk_pair_t));
if (pair == XP_NULL) return -1; /* error */
/*pair->key = key;*/
/* duplicate the key if it is new */
pair->key = xp_strxdup (key, key_len);
pair->key = xp_awk_strxdup (map->awk, key, key_len);
if (pair->key == XP_NULL)
{
xp_free (pair);
XP_AWK_FREE (map->awk, pair);
return -1; /* error */
}

View File

@ -1,5 +1,5 @@
/*
* $Id: map.h,v 1.14 2006-08-03 05:05:47 bacon Exp $
* $Id: map.h,v 1.15 2006-09-01 03:44:16 bacon Exp $
*/
#ifndef _XP_AWK_MAP_H_
@ -27,6 +27,7 @@ struct xp_awk_map_t
xp_size_t capa;
xp_awk_pair_t** buck;
void (*freeval) (void*,void*);
xp_awk_t* awk;
xp_bool_t __dynamic;
};
@ -34,8 +35,9 @@ struct xp_awk_map_t
extern "C" {
#endif
xp_awk_map_t* xp_awk_map_open (xp_awk_map_t* map,
void* owner, xp_size_t capa, void(*freeval)(void*,void*));
xp_awk_map_t* xp_awk_map_open (
xp_awk_map_t* map, void* owner, xp_size_t capa,
void(*freeval)(void*,void*), xp_awk_t* awk);
void xp_awk_map_close (xp_awk_map_t* map);

View File

@ -1,5 +1,5 @@
/*
* $Id: misc.c,v 1.7 2006-05-06 12:52:36 bacon Exp $
* $Id: misc.c,v 1.8 2006-09-01 03:44:16 bacon Exp $
*/
#include <xp/awk/awk_i.h>
@ -281,3 +281,43 @@ done:
return (sign)? -fraction: fraction;
}
xp_char_t* xp_awk_strdup (xp_awk_t* awk, const xp_char_t* str)
{
xp_char_t* tmp;
tmp = (xp_char_t*) XP_AWK_MALLOC (
awk, (xp_strlen(str) + 1) * xp_sizeof(xp_char_t));
if (tmp == XP_NULL) return XP_NULL;
xp_strcpy (tmp, str);
return tmp;
}
xp_char_t* xp_awk_strxdup (xp_awk_t* awk, const xp_char_t* str, xp_size_t len)
{
xp_char_t* tmp;
tmp = (xp_char_t*) XP_AWK_MALLOC (
awk, (len + 1) * xp_sizeof(xp_char_t));
if (tmp == XP_NULL) return XP_NULL;
xp_strncpy (tmp, str, len);
return tmp;
}
xp_char_t* xp_awk_strxdup2 (
xp_awk_t* awk,
const xp_char_t* str1, xp_size_t len1,
const xp_char_t* str2, xp_size_t len2)
{
xp_char_t* tmp;
tmp = (xp_char_t*) XP_AWK_MALLOC (
awk, (len1 + len2 + 1) * xp_sizeof(xp_char_t));
if (tmp == XP_NULL) return XP_NULL;
xp_strncpy (tmp, str1, len1);
xp_strncpy (tmp + len1, str2, len2);
return tmp;
}

View File

@ -1,5 +1,5 @@
/*
* $Id: parse.c,v 1.174 2006-08-31 16:00:19 bacon Exp $
* $Id: parse.c,v 1.175 2006-09-01 03:44:16 bacon Exp $
*/
#include <xp/awk/awk_i.h>
@ -499,14 +499,14 @@ static xp_awk_t* __parse_progunit (xp_awk_t* awk)
{
if (__get_token (awk) == -1)
{
xp_awk_clrpt (ptn);
xp_awk_clrpt (awk, ptn);
return XP_NULL;
}
ptn->next = __parse_expression (awk);
if (ptn->next == XP_NULL)
{
xp_awk_clrpt (ptn);
xp_awk_clrpt (awk, ptn);
return XP_NULL;
}
}
@ -521,7 +521,7 @@ static xp_awk_t* __parse_progunit (xp_awk_t* awk)
if (__parse_pattern_block (
awk, ptn, xp_true) == XP_NULL)
{
xp_awk_clrpt (ptn);
xp_awk_clrpt (awk, ptn);
return XP_NULL;
}
@ -529,7 +529,7 @@ static xp_awk_t* __parse_progunit (xp_awk_t* awk)
{
if (__get_token (awk) == -1)
{
xp_awk_clrpt (ptn);
xp_awk_clrpt (awk, ptn);
return XP_NULL;
}
}
@ -539,7 +539,7 @@ static xp_awk_t* __parse_progunit (xp_awk_t* awk)
/* parse the action block */
if (!MATCH(awk,TOKEN_LBRACE))
{
xp_awk_clrpt (ptn);
xp_awk_clrpt (awk, ptn);
PANIC (awk, XP_AWK_ELBRACE);
}
@ -547,7 +547,7 @@ static xp_awk_t* __parse_progunit (xp_awk_t* awk)
if (__parse_pattern_block (
awk, ptn, xp_false) == XP_NULL)
{
xp_awk_clrpt (ptn);
xp_awk_clrpt (awk, ptn);
return XP_NULL;
}
}
@ -597,7 +597,7 @@ static xp_awk_nde_t* __parse_function (xp_awk_t* awk)
}
/* clone the function name before it is overwritten */
name_dup = xp_strxdup (name, name_len);
name_dup = xp_awk_strxdup (awk, name, name_len);
if (name_dup == XP_NULL) PANIC (awk, XP_AWK_ENOMEM);
/* get the next token */
@ -763,7 +763,7 @@ static xp_awk_nde_t* __parse_function (xp_awk_t* awk)
if (afn == XP_NULL)
{
XP_AWK_FREE (awk, name_dup);
xp_awk_clrpt (body);
xp_awk_clrpt (awk, body);
return XP_NULL;
}
@ -776,7 +776,7 @@ static xp_awk_nde_t* __parse_function (xp_awk_t* awk)
if (n < 0)
{
XP_AWK_FREE (awk, name_dup);
xp_awk_clrpt (body);
xp_awk_clrpt (awk, body);
XP_AWK_FREE (awk, afn);
PANIC (awk, XP_AWK_ENOMEM);
}
@ -837,7 +837,7 @@ static xp_awk_chain_t* __parse_pattern_block (
chain = (xp_awk_chain_t*) XP_AWK_MALLOC (awk, xp_sizeof(xp_awk_chain_t));
if (chain == XP_NULL)
{
xp_awk_clrpt (nde);
xp_awk_clrpt (awk, nde);
PANIC (awk, XP_AWK_ENOMEM);
}
@ -905,7 +905,7 @@ static xp_awk_nde_t* __parse_block (xp_awk_t* awk, xp_bool_t is_top)
xp_awk_tab_remove (
&awk->parse.locals, nlocals,
xp_awk_tab_getsize(&awk->parse.locals) - nlocals);
if (head != XP_NULL) xp_awk_clrpt (head);
if (head != XP_NULL) xp_awk_clrpt (awk, head);
PANIC (awk, XP_AWK_EENDSRC);
}
@ -916,7 +916,7 @@ static xp_awk_nde_t* __parse_block (xp_awk_t* awk, xp_bool_t is_top)
xp_awk_tab_remove (
&awk->parse.locals, nlocals,
xp_awk_tab_getsize(&awk->parse.locals) - nlocals);
if (head != XP_NULL) xp_awk_clrpt (head);
if (head != XP_NULL) xp_awk_clrpt (awk, head);
return XP_NULL;
}
break;
@ -928,7 +928,7 @@ static xp_awk_nde_t* __parse_block (xp_awk_t* awk, xp_bool_t is_top)
xp_awk_tab_remove (
&awk->parse.locals, nlocals,
xp_awk_tab_getsize(&awk->parse.locals) - nlocals);
if (head != XP_NULL) xp_awk_clrpt (head);
if (head != XP_NULL) xp_awk_clrpt (awk, head);
return XP_NULL;
}
@ -948,7 +948,7 @@ static xp_awk_nde_t* __parse_block (xp_awk_t* awk, xp_bool_t is_top)
xp_awk_tab_remove (
&awk->parse.locals, nlocals,
xp_awk_tab_getsize(&awk->parse.locals) - nlocals);
xp_awk_clrpt (head);
xp_awk_clrpt (awk, head);
PANIC (awk, XP_AWK_ENOMEM);
}
@ -1260,14 +1260,14 @@ static xp_awk_nde_t* __parse_statement_nb (xp_awk_t* awk)
/* check if a statement ends with a semicolon */
if (!MATCH(awk,TOKEN_SEMICOLON))
{
if (nde != XP_NULL) xp_awk_clrpt (nde);
if (nde != XP_NULL) xp_awk_clrpt (awk, nde);
PANIC (awk, XP_AWK_ESEMICOLON);
}
/* eat up the semicolon and read in the next token */
if (__get_token(awk) == -1)
{
if (nde != XP_NULL) xp_awk_clrpt (nde);
if (nde != XP_NULL) xp_awk_clrpt (awk, nde);
return XP_NULL;
}
@ -1293,28 +1293,28 @@ static xp_awk_nde_t* __parse_expression (xp_awk_t* awk)
xp_assert (x->next == XP_NULL);
if (!__is_var(x) && x->type != XP_AWK_NDE_POS)
{
xp_awk_clrpt (x);
xp_awk_clrpt (awk, x);
PANIC (awk, XP_AWK_EASSIGNMENT);
}
if (__get_token(awk) == -1)
{
xp_awk_clrpt (x);
xp_awk_clrpt (awk, x);
return XP_NULL;
}
y = __parse_basic_expr (awk);
if (y == XP_NULL)
{
xp_awk_clrpt (x);
xp_awk_clrpt (awk, x);
return XP_NULL;
}
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);
xp_awk_clrpt (y);
xp_awk_clrpt (awk, x);
xp_awk_clrpt (awk, y);
PANIC (awk, XP_AWK_ENOMEM);
}
@ -1343,7 +1343,7 @@ static xp_awk_nde_t* __parse_basic_expr (xp_awk_t* awk)
n1 = __parse_basic_expr (awk);
if (n1 == XP_NULL)
{
xp_awk_clrpt (nde);
xp_awk_clrpt (awk, nde);
return XP_NULL;
}
@ -1353,8 +1353,8 @@ static xp_awk_nde_t* __parse_basic_expr (xp_awk_t* awk)
n2 = __parse_basic_expr (awk);
if (n2 == XP_NULL)
{
xp_awk_clrpt (nde);
xp_awk_clrpt (n1);
xp_awk_clrpt (awk, nde);
xp_awk_clrpt (awk, n1);
return XP_NULL;
}
@ -1362,9 +1362,9 @@ static xp_awk_nde_t* __parse_basic_expr (xp_awk_t* awk)
awk, xp_sizeof(xp_awk_nde_cnd_t));
if (tmp == XP_NULL)
{
xp_awk_clrpt (nde);
xp_awk_clrpt (n1);
xp_awk_clrpt (n2);
xp_awk_clrpt (awk, nde);
xp_awk_clrpt (awk, n1);
xp_awk_clrpt (awk, n2);
return XP_NULL;
}
@ -1410,14 +1410,14 @@ static xp_awk_nde_t* __parse_binary_expr (
if (__get_token(awk) == -1)
{
xp_awk_clrpt (left);
xp_awk_clrpt (awk, left);
return XP_NULL;
}
right = next_level_func (awk);
if (right == XP_NULL)
{
xp_awk_clrpt (left);
xp_awk_clrpt (awk, left);
return XP_NULL;
}
@ -1439,7 +1439,7 @@ static xp_awk_nde_t* __parse_binary_expr (
else if (opcode == XP_AWK_BINOP_MOD && r != 0) l %= r;
else goto skip_constant_folding;
xp_awk_clrpt (right);
xp_awk_clrpt (awk, right);
((xp_awk_nde_int_t*)left)->val = l;
continue;
}
@ -1458,7 +1458,7 @@ static xp_awk_nde_t* __parse_binary_expr (
else if (opcode == XP_AWK_BINOP_DIV) l /= r;
else goto skip_constant_folding;
xp_awk_clrpt (right);
xp_awk_clrpt (awk, right);
((xp_awk_nde_real_t*)left)->val = l;
continue;
}
@ -1469,8 +1469,8 @@ static xp_awk_nde_t* __parse_binary_expr (
awk, xp_sizeof(xp_awk_nde_exp_t));
if (nde == XP_NULL)
{
xp_awk_clrpt (right);
xp_awk_clrpt (left);
xp_awk_clrpt (awk, right);
xp_awk_clrpt (awk, left);
PANIC (awk, XP_AWK_ENOMEM);
}
@ -1532,21 +1532,21 @@ static xp_awk_nde_t* __parse_in (xp_awk_t* awk)
if (__get_token(awk) == -1)
{
xp_awk_clrpt (left);
xp_awk_clrpt (awk, left);
return XP_NULL;
}
right = __parse_regex_match (awk);
if (right == XP_NULL)
{
xp_awk_clrpt (left);
xp_awk_clrpt (awk, left);
return XP_NULL;
}
if (!__is_plain_var(right))
{
xp_awk_clrpt (right);
xp_awk_clrpt (left);
xp_awk_clrpt (awk, right);
xp_awk_clrpt (awk, left);
PANIC (awk, XP_AWK_ENOTVAR);
}
@ -1554,8 +1554,8 @@ static xp_awk_nde_t* __parse_in (xp_awk_t* awk)
awk, xp_sizeof(xp_awk_nde_exp_t));
if (nde == XP_NULL)
{
xp_awk_clrpt (right);
xp_awk_clrpt (left);
xp_awk_clrpt (awk, right);
xp_awk_clrpt (awk, left);
PANIC (awk, XP_AWK_ENOMEM);
}
@ -1620,7 +1620,7 @@ static xp_awk_nde_t* __parse_bitwise_or_with_extio (xp_awk_t* awk)
if (__get_token(awk) == -1)
{
xp_awk_clrpt (left);
xp_awk_clrpt (awk, left);
return XP_NULL;
}
@ -1632,7 +1632,7 @@ static xp_awk_nde_t* __parse_bitwise_or_with_extio (xp_awk_t* awk)
/* piped getline */
if (__get_token(awk) == -1)
{
xp_awk_clrpt (left);
xp_awk_clrpt (awk, left);
return XP_NULL;
}
@ -1645,7 +1645,7 @@ static xp_awk_nde_t* __parse_bitwise_or_with_extio (xp_awk_t* awk)
var = __parse_primary (awk);
if (var == XP_NULL)
{
xp_awk_clrpt (left);
xp_awk_clrpt (awk, left);
return XP_NULL;
}
}
@ -1654,7 +1654,7 @@ static xp_awk_nde_t* __parse_bitwise_or_with_extio (xp_awk_t* awk)
awk, xp_sizeof(xp_awk_nde_getline_t));
if (nde == XP_NULL)
{
xp_awk_clrpt (left);
xp_awk_clrpt (awk, left);
PANIC (awk, XP_AWK_ENOMEM);
}
@ -1672,14 +1672,14 @@ static xp_awk_nde_t* __parse_bitwise_or_with_extio (xp_awk_t* awk)
if (in_type == XP_AWK_IN_COPROC)
{
xp_awk_clrpt (left);
xp_awk_clrpt (awk, left);
PANIC (awk, XP_AWK_EGETLINE);
}
right = __parse_bitwise_xor (awk);
if (right == XP_NULL)
{
xp_awk_clrpt (left);
xp_awk_clrpt (awk, left);
return XP_NULL;
}
@ -1689,8 +1689,8 @@ static xp_awk_nde_t* __parse_bitwise_or_with_extio (xp_awk_t* awk)
awk, xp_sizeof(xp_awk_nde_exp_t));
if (nde == XP_NULL)
{
xp_awk_clrpt (right);
xp_awk_clrpt (left);
xp_awk_clrpt (awk, right);
xp_awk_clrpt (awk, left);
PANIC (awk, XP_AWK_ENOMEM);
}
@ -1784,7 +1784,7 @@ static xp_awk_nde_t* __parse_concat (xp_awk_t* awk)
right = __parse_additive (awk);
if (right == XP_NULL)
{
xp_awk_clrpt (left);
xp_awk_clrpt (awk, left);
return XP_NULL;
}
@ -1792,8 +1792,8 @@ static xp_awk_nde_t* __parse_concat (xp_awk_t* awk)
awk, xp_sizeof(xp_awk_nde_exp_t));
if (nde == XP_NULL)
{
xp_awk_clrpt (left);
xp_awk_clrpt (right);
xp_awk_clrpt (awk, left);
xp_awk_clrpt (awk, right);
PANIC (awk, XP_AWK_ENOMEM);
}
@ -1856,7 +1856,7 @@ static xp_awk_nde_t* __parse_unary (xp_awk_t* awk)
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);
xp_awk_clrpt (awk, left);
PANIC (awk, XP_AWK_ENOMEM);
}
@ -1891,7 +1891,7 @@ static xp_awk_nde_t* __parse_increment (xp_awk_t* awk)
if (opcode1 != -1 && opcode2 != -1)
{
xp_awk_clrpt (left);
xp_awk_clrpt (awk, left);
PANIC (awk, XP_AWK_ELVALUE);
}
else if (opcode1 == -1 && opcode2 == -1)
@ -1914,7 +1914,7 @@ static xp_awk_nde_t* __parse_increment (xp_awk_t* awk)
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);
xp_awk_clrpt (awk, left);
PANIC (awk, XP_AWK_ENOMEM);
}
@ -1993,7 +1993,8 @@ static xp_awk_nde_t* __parse_primary (xp_awk_t* awk)
nde->type = XP_AWK_NDE_STR;
nde->next = XP_NULL;
nde->len = XP_AWK_STR_LEN(&awk->token.name);
nde->buf = xp_strxdup(XP_AWK_STR_BUF(&awk->token.name), nde->len);
nde->buf = xp_awk_strxdup (
awk, XP_AWK_STR_BUF(&awk->token.name), nde->len);
if (nde->buf == XP_NULL)
{
XP_AWK_FREE (awk, nde);
@ -2029,7 +2030,8 @@ static xp_awk_nde_t* __parse_primary (xp_awk_t* awk)
nde->next = XP_NULL;
nde->len = XP_AWK_STR_LEN(&awk->token.name);
nde->buf = xp_strxdup (
nde->buf = xp_awk_strxdup (
awk,
XP_AWK_STR_BUF(&awk->token.name),
XP_AWK_STR_LEN(&awk->token.name));
if (nde->buf == XP_NULL)
@ -2039,6 +2041,7 @@ static xp_awk_nde_t* __parse_primary (xp_awk_t* awk)
}
nde->code = xp_awk_buildrex (
awk,
XP_AWK_STR_BUF(&awk->token.name),
XP_AWK_STR_LEN(&awk->token.name),
&errnum);
@ -2073,7 +2076,7 @@ static xp_awk_nde_t* __parse_primary (xp_awk_t* awk)
awk, xp_sizeof(xp_awk_nde_pos_t));
if (nde == XP_NULL)
{
xp_awk_clrpt (prim);
xp_awk_clrpt (awk, prim);
PANIC (awk, XP_AWK_ENOMEM);
}
@ -2105,14 +2108,14 @@ static xp_awk_nde_t* __parse_primary (xp_awk_t* awk)
if (__get_token(awk) == -1)
{
xp_awk_clrpt (nde);
xp_awk_clrpt (awk, nde);
return XP_NULL;
}
tmp = __parse_expression (awk);
if (tmp == XP_NULL)
{
xp_awk_clrpt (nde);
xp_awk_clrpt (awk, nde);
return XP_NULL;
}
@ -2125,13 +2128,13 @@ static xp_awk_nde_t* __parse_primary (xp_awk_t* awk)
/* check for the closing parenthesis */
if (!MATCH(awk,TOKEN_RPAREN))
{
xp_awk_clrpt (nde);
xp_awk_clrpt (awk, nde);
PANIC (awk, XP_AWK_ERPAREN);
}
if (__get_token(awk) == -1)
{
xp_awk_clrpt (nde);
xp_awk_clrpt (awk, nde);
return XP_NULL;
}
@ -2145,7 +2148,7 @@ static xp_awk_nde_t* __parse_primary (xp_awk_t* awk)
if (!MATCH(awk,TOKEN_IN))
{
xp_awk_clrpt (nde);
xp_awk_clrpt (awk, nde);
PANIC (awk, XP_AWK_EIN);
}
@ -2153,7 +2156,7 @@ static xp_awk_nde_t* __parse_primary (xp_awk_t* awk)
awk, xp_sizeof(xp_awk_nde_grp_t));
if (tmp == XP_NULL)
{
xp_awk_clrpt (nde);
xp_awk_clrpt (awk, nde);
PANIC (awk, XP_AWK_ENOMEM);
}
@ -2188,7 +2191,7 @@ static xp_awk_nde_t* __parse_primary (xp_awk_t* awk)
/* getline [var] < file */
if (__get_token(awk) == -1)
{
if (var != XP_NULL) xp_awk_clrpt (var);
if (var != XP_NULL) xp_awk_clrpt (awk, var);
return XP_NULL;
}
@ -2197,7 +2200,7 @@ static xp_awk_nde_t* __parse_primary (xp_awk_t* awk)
in = __parse_primary (awk);
if (in == XP_NULL)
{
if (var != XP_NULL) xp_awk_clrpt (var);
if (var != XP_NULL) xp_awk_clrpt (awk, var);
return XP_NULL;
}
}
@ -2206,8 +2209,8 @@ static xp_awk_nde_t* __parse_primary (xp_awk_t* awk)
awk, xp_sizeof(xp_awk_nde_getline_t));
if (nde == XP_NULL)
{
if (var != XP_NULL) xp_awk_clrpt (var);
if (in != XP_NULL) xp_awk_clrpt (in);
if (var != XP_NULL) xp_awk_clrpt (awk, var);
if (in != XP_NULL) xp_awk_clrpt (awk, in);
PANIC (awk, XP_AWK_ENOMEM);
}
@ -2233,8 +2236,10 @@ static xp_awk_nde_t* __parse_primary_ident (xp_awk_t* awk)
xp_assert (MATCH(awk,TOKEN_IDENT));
name_dup = xp_strxdup (
XP_AWK_STR_BUF(&awk->token.name), XP_AWK_STR_LEN(&awk->token.name));
name_dup = xp_awk_strxdup (
awk,
XP_AWK_STR_BUF(&awk->token.name),
XP_AWK_STR_LEN(&awk->token.name));
if (name_dup == XP_NULL) PANIC (awk, XP_AWK_ENOMEM);
name_len = XP_AWK_STR_LEN(&awk->token.name);
@ -2373,14 +2378,14 @@ static xp_awk_nde_t* __parse_hashidx (
{
if (__get_token(awk) == -1)
{
if (idx != XP_NULL) xp_awk_clrpt (idx);
if (idx != XP_NULL) xp_awk_clrpt (awk, idx);
return XP_NULL;
}
tmp = __parse_expression (awk);
if (tmp == XP_NULL)
{
if (idx != XP_NULL) xp_awk_clrpt (idx);
if (idx != XP_NULL) xp_awk_clrpt (awk, idx);
return XP_NULL;
}
@ -2401,20 +2406,20 @@ static xp_awk_nde_t* __parse_hashidx (
if (!MATCH(awk,TOKEN_RBRACK))
{
xp_awk_clrpt (idx);
xp_awk_clrpt (awk, idx);
PANIC (awk, XP_AWK_ERBRACK);
}
if (__get_token(awk) == -1)
{
xp_awk_clrpt (idx);
xp_awk_clrpt (awk, idx);
return XP_NULL;
}
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);
xp_awk_clrpt (awk, idx);
PANIC (awk, XP_AWK_ENOMEM);
}
@ -2476,7 +2481,7 @@ static xp_awk_nde_t* __parse_hashidx (
}
/* undefined variable */
xp_awk_clrpt (idx);
xp_awk_clrpt (awk, idx);
XP_AWK_FREE (awk, nde);
PANIC (awk, XP_AWK_EUNDEF);
}
@ -2507,7 +2512,7 @@ static xp_awk_nde_t* __parse_fncall (
nde = __parse_expression (awk);
if (nde == XP_NULL)
{
if (head != XP_NULL) xp_awk_clrpt (head);
if (head != XP_NULL) xp_awk_clrpt (awk, head);
return XP_NULL;
}
@ -2522,7 +2527,7 @@ static xp_awk_nde_t* __parse_fncall (
if (__get_token(awk) == -1)
{
if (head != XP_NULL)
xp_awk_clrpt (head);
xp_awk_clrpt (awk, head);
return XP_NULL;
}
break;
@ -2530,13 +2535,13 @@ static xp_awk_nde_t* __parse_fncall (
if (!MATCH(awk,TOKEN_COMMA))
{
if (head != XP_NULL) xp_awk_clrpt (head);
if (head != XP_NULL) xp_awk_clrpt (awk, head);
PANIC (awk, XP_AWK_ECOMMA);
}
if (__get_token(awk) == -1)
{
if (head != XP_NULL) xp_awk_clrpt (head);
if (head != XP_NULL) xp_awk_clrpt (awk, head);
return XP_NULL;
}
}
@ -2546,7 +2551,7 @@ static xp_awk_nde_t* __parse_fncall (
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);
if (head != XP_NULL) xp_awk_clrpt (awk, head);
PANIC (awk, XP_AWK_ENOMEM);
}
@ -2594,20 +2599,20 @@ static xp_awk_nde_t* __parse_if (xp_awk_t* awk)
if (!MATCH(awk,TOKEN_RPAREN))
{
xp_awk_clrpt (test);
xp_awk_clrpt (awk, test);
PANIC (awk, XP_AWK_ERPAREN);
}
if (__get_token(awk) == -1)
{
xp_awk_clrpt (test);
xp_awk_clrpt (awk, test);
return XP_NULL;
}
then_part = __parse_statement (awk);
if (then_part == XP_NULL)
{
xp_awk_clrpt (test);
xp_awk_clrpt (awk, test);
return XP_NULL;
}
@ -2615,16 +2620,16 @@ static xp_awk_nde_t* __parse_if (xp_awk_t* awk)
{
if (__get_token(awk) == -1)
{
xp_awk_clrpt (then_part);
xp_awk_clrpt (test);
xp_awk_clrpt (awk, then_part);
xp_awk_clrpt (awk, test);
return XP_NULL;
}
else_part = __parse_statement (awk);
if (else_part == XP_NULL)
{
xp_awk_clrpt (then_part);
xp_awk_clrpt (test);
xp_awk_clrpt (awk, then_part);
xp_awk_clrpt (awk, test);
return XP_NULL;
}
}
@ -2633,9 +2638,9 @@ static xp_awk_nde_t* __parse_if (xp_awk_t* awk)
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);
xp_awk_clrpt (then_part);
xp_awk_clrpt (test);
xp_awk_clrpt (awk, else_part);
xp_awk_clrpt (awk, then_part);
xp_awk_clrpt (awk, test);
PANIC (awk, XP_AWK_ENOMEM);
}
@ -2661,28 +2666,28 @@ static xp_awk_nde_t* __parse_while (xp_awk_t* awk)
if (!MATCH(awk,TOKEN_RPAREN))
{
xp_awk_clrpt (test);
xp_awk_clrpt (awk, test);
PANIC (awk, XP_AWK_ERPAREN);
}
if (__get_token(awk) == -1)
{
xp_awk_clrpt (test);
xp_awk_clrpt (awk, test);
return XP_NULL;
}
body = __parse_statement (awk);
if (body == XP_NULL)
{
xp_awk_clrpt (test);
xp_awk_clrpt (awk, test);
return XP_NULL;
}
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);
xp_awk_clrpt (test);
xp_awk_clrpt (awk, body);
xp_awk_clrpt (awk, test);
PANIC (awk, XP_AWK_ENOMEM);
}
@ -2722,13 +2727,13 @@ static xp_awk_nde_t* __parse_for (xp_awk_t* awk)
if (!MATCH(awk,TOKEN_RPAREN))
{
xp_awk_clrpt (init);
xp_awk_clrpt (awk, init);
PANIC (awk, XP_AWK_ERPAREN);
}
if (__get_token(awk) == -1)
{
xp_awk_clrpt (init);
xp_awk_clrpt (awk, init);
return XP_NULL;
}
@ -2736,7 +2741,7 @@ static xp_awk_nde_t* __parse_for (xp_awk_t* awk)
body = __parse_statement (awk);
if (body == XP_NULL)
{
xp_awk_clrpt (init);
xp_awk_clrpt (awk, init);
return XP_NULL;
}
@ -2744,8 +2749,8 @@ static xp_awk_nde_t* __parse_for (xp_awk_t* awk)
awk, xp_sizeof(xp_awk_nde_foreach_t));
if (nde2 == XP_NULL)
{
xp_awk_clrpt (init);
xp_awk_clrpt (body);
xp_awk_clrpt (awk, init);
xp_awk_clrpt (awk, body);
PANIC (awk, XP_AWK_ENOMEM);
}
@ -2759,14 +2764,14 @@ static xp_awk_nde_t* __parse_for (xp_awk_t* awk)
if (!MATCH(awk,TOKEN_SEMICOLON))
{
xp_awk_clrpt (init);
xp_awk_clrpt (awk, init);
PANIC (awk, XP_AWK_ESEMICOLON);
}
}
if (__get_token(awk) == -1)
{
xp_awk_clrpt (init);
xp_awk_clrpt (awk, init);
return XP_NULL;
}
@ -2776,22 +2781,22 @@ static xp_awk_nde_t* __parse_for (xp_awk_t* awk)
test = __parse_expression (awk);
if (test == XP_NULL)
{
xp_awk_clrpt (init);
xp_awk_clrpt (awk, init);
return XP_NULL;
}
if (!MATCH(awk,TOKEN_SEMICOLON))
{
xp_awk_clrpt (init);
xp_awk_clrpt (test);
xp_awk_clrpt (awk, init);
xp_awk_clrpt (awk, test);
PANIC (awk, XP_AWK_ESEMICOLON);
}
}
if (__get_token(awk) == -1)
{
xp_awk_clrpt (init);
xp_awk_clrpt (test);
xp_awk_clrpt (awk, init);
xp_awk_clrpt (awk, test);
return XP_NULL;
}
@ -2801,44 +2806,44 @@ static xp_awk_nde_t* __parse_for (xp_awk_t* awk)
incr = __parse_expression (awk);
if (incr == XP_NULL)
{
xp_awk_clrpt (init);
xp_awk_clrpt (test);
xp_awk_clrpt (awk, init);
xp_awk_clrpt (awk, test);
return XP_NULL;
}
if (!MATCH(awk,TOKEN_RPAREN))
{
xp_awk_clrpt (init);
xp_awk_clrpt (test);
xp_awk_clrpt (incr);
xp_awk_clrpt (awk, init);
xp_awk_clrpt (awk, test);
xp_awk_clrpt (awk, incr);
PANIC (awk, XP_AWK_ERPAREN);
}
}
if (__get_token(awk) == -1)
{
xp_awk_clrpt (init);
xp_awk_clrpt (test);
xp_awk_clrpt (incr);
xp_awk_clrpt (awk, init);
xp_awk_clrpt (awk, test);
xp_awk_clrpt (awk, incr);
return XP_NULL;
}
body = __parse_statement (awk);
if (body == XP_NULL)
{
xp_awk_clrpt (init);
xp_awk_clrpt (test);
xp_awk_clrpt (incr);
xp_awk_clrpt (awk, init);
xp_awk_clrpt (awk, test);
xp_awk_clrpt (awk, incr);
return XP_NULL;
}
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);
xp_awk_clrpt (test);
xp_awk_clrpt (incr);
xp_awk_clrpt (body);
xp_awk_clrpt (awk, init);
xp_awk_clrpt (awk, test);
xp_awk_clrpt (awk, incr);
xp_awk_clrpt (awk, body);
PANIC (awk, XP_AWK_ENOMEM);
}
@ -2862,54 +2867,54 @@ static xp_awk_nde_t* __parse_dowhile (xp_awk_t* awk)
if (!MATCH(awk,TOKEN_WHILE))
{
xp_awk_clrpt (body);
xp_awk_clrpt (awk, body);
PANIC (awk, XP_AWK_EWHILE);
}
if (__get_token(awk) == -1)
{
xp_awk_clrpt (body);
xp_awk_clrpt (awk, body);
return XP_NULL;
}
if (!MATCH(awk,TOKEN_LPAREN))
{
xp_awk_clrpt (body);
xp_awk_clrpt (awk, body);
PANIC (awk, XP_AWK_ELPAREN);
}
if (__get_token(awk) == -1)
{
xp_awk_clrpt (body);
xp_awk_clrpt (awk, body);
return XP_NULL;
}
test = __parse_expression (awk);
if (test == XP_NULL)
{
xp_awk_clrpt (body);
xp_awk_clrpt (awk, body);
return XP_NULL;
}
if (!MATCH(awk,TOKEN_RPAREN))
{
xp_awk_clrpt (body);
xp_awk_clrpt (test);
xp_awk_clrpt (awk, body);
xp_awk_clrpt (awk, test);
PANIC (awk, XP_AWK_ERPAREN);
}
if (__get_token(awk) == -1)
{
xp_awk_clrpt (body);
xp_awk_clrpt (test);
xp_awk_clrpt (awk, body);
xp_awk_clrpt (awk, test);
return XP_NULL;
}
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);
xp_awk_clrpt (test);
xp_awk_clrpt (awk, body);
xp_awk_clrpt (awk, test);
PANIC (awk, XP_AWK_ENOMEM);
}
@ -3022,7 +3027,7 @@ static xp_awk_nde_t* __parse_delete (xp_awk_t* awk)
if (!__is_var (var))
{
/* a normal identifier is expected */
xp_awk_clrpt (var);
xp_awk_clrpt (awk, var);
PANIC (awk, XP_AWK_EIDENT);
}
@ -3062,14 +3067,14 @@ static xp_awk_nde_t* __parse_print (xp_awk_t* awk)
{
if (__get_token(awk) == -1)
{
xp_awk_clrpt (args);
xp_awk_clrpt (awk, args);
return XP_NULL;
}
args_tail->next = __parse_expression (awk);
if (args_tail->next == XP_NULL)
{
xp_awk_clrpt (args);
xp_awk_clrpt (awk, args);
return XP_NULL;
}
@ -3137,14 +3142,14 @@ static xp_awk_nde_t* __parse_print (xp_awk_t* awk)
{
if (__get_token(awk) == -1)
{
if (args != XP_NULL) xp_awk_clrpt (args);
if (args != XP_NULL) xp_awk_clrpt (awk, args);
return XP_NULL;
}
out = __parse_expression(awk);
if (out == XP_NULL)
{
if (args != XP_NULL) xp_awk_clrpt (args);
if (args != XP_NULL) xp_awk_clrpt (awk, args);
return XP_NULL;
}
}
@ -3153,8 +3158,8 @@ static xp_awk_nde_t* __parse_print (xp_awk_t* awk)
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);
if (out != XP_NULL) xp_awk_clrpt (out);
if (args != XP_NULL) xp_awk_clrpt (awk, args);
if (out != XP_NULL) xp_awk_clrpt (awk, out);
PANIC (awk, XP_AWK_ENOMEM);
}
@ -4111,13 +4116,13 @@ static int __deparse (xp_awk_t* awk)
for (i = awk->tree.nbglobals; i < awk->tree.nglobals - 1; i++)
{
xp_sprintf (tmp, xp_countof(tmp),
xp_awk_sprintf (awk, tmp, xp_countof(tmp),
XP_T("__global%lu, "), (unsigned long)i);
if (xp_awk_putsrcstr (awk, tmp) == -1)
EXIT_DEPARSE (XP_AWK_ESRCOUTWRITE);
}
xp_sprintf (tmp, xp_countof(tmp),
xp_awk_sprintf (awk, tmp, xp_countof(tmp),
XP_T("__global%lu;\n\n"), (unsigned long)i);
if (xp_awk_putsrcstr (awk, tmp) == -1)
EXIT_DEPARSE (XP_AWK_ESRCOUTWRITE);
@ -4210,7 +4215,7 @@ static int __deparse_func (xp_awk_pair_t* pair, void* arg)
for (i = 0; i < afn->nargs; )
{
xp_sprintf (df->tmp, df->tmp_len,
xp_awk_sprintf (df->awk, df->tmp, df->tmp_len,
XP_T("__param%lu"), (unsigned long)i++);
if (xp_awk_putsrcstr (df->awk, df->tmp) == -1) return -1;
if (i >= afn->nargs) break;

View File

@ -1,5 +1,5 @@
/*
* $Id: rex.c,v 1.24 2006-08-30 07:15:14 bacon Exp $
* $Id: rex.c,v 1.25 2006-09-01 03:44:16 bacon Exp $
*/
#include <xp/awk/awk_i.h>
@ -73,6 +73,8 @@ struct __code_t
struct __builder_t
{
xp_awk_t* awk;
struct
{
const xp_char_t* ptr;
@ -103,6 +105,8 @@ struct __builder_t
struct __matcher_t
{
xp_awk_t* awk;
struct
{
struct
@ -244,19 +248,16 @@ static struct __char_class_t __char_class [] =
};
#endif
void* xp_awk_buildrex (const xp_char_t* ptn, xp_size_t len, int* errnum)
{
return xp_awk_safebuildrex (ptn, len, 0, errnum);
}
void* xp_awk_safebuildrex (
const xp_char_t* ptn, xp_size_t len, int max_depth, int* errnum)
void* xp_awk_buildrex (
xp_awk_t* awk, const xp_char_t* ptn, xp_size_t len, int* errnum)
{
__builder_t builder;
builder.awk = awk;
builder.code.capa = DEF_CODE_CAPA;
builder.code.size = 0;
builder.code.buf = (xp_byte_t*) xp_malloc (builder.code.capa);
builder.code.buf = (xp_byte_t*)
XP_AWK_MALLOC (builder.awk, builder.code.capa);
if (builder.code.buf == XP_NULL)
{
*errnum = XP_AWK_ENOMEM;
@ -270,55 +271,53 @@ void* xp_awk_safebuildrex (
builder.ptn.curc.type = CT_EOF;
builder.ptn.curc.value = XP_T('\0');
builder.depth.max = max_depth;
/* TODO: implement the maximum depth
builder.depth.max = awk->max_depth; */
builder.depth.max = 0;
builder.depth.cur = 0;
if (__next_char (&builder, LEVEL_TOP) == -1)
{
if (errnum != XP_NULL) *errnum = builder.errnum;
xp_free (builder.code.buf);
XP_AWK_FREE (builder.awk, builder.code.buf);
return XP_NULL;
}
if (__build_pattern (&builder) == -1)
{
if (errnum != XP_NULL) *errnum = builder.errnum;
xp_free (builder.code.buf);
XP_AWK_FREE (builder.awk, builder.code.buf);
return XP_NULL;
}
if (builder.ptn.curc.type != CT_EOF)
{
if (errnum != XP_NULL) *errnum = XP_AWK_EREXGARBAGE;
xp_free (builder.code.buf);
XP_AWK_FREE (builder.awk, builder.code.buf);
return XP_NULL;
}
return builder.code.buf;
}
int xp_awk_matchrex (void* code,
int xp_awk_matchrex (
xp_awk_t* awk, void* code,
const xp_char_t* str, xp_size_t len,
const xp_char_t** match_ptr, xp_size_t* match_len, int* errnum)
{
return xp_awk_safematchrex (
code, str, len, match_ptr, match_len, 0, errnum);
}
int xp_awk_safematchrex (void* code,
const xp_char_t* str, xp_size_t len,
const xp_char_t** match_ptr, xp_size_t* match_len,
int max_depth, int* errnum)
{
__matcher_t matcher;
__match_t mat;
xp_size_t offset = 0;
matcher.awk = awk;
/* store the source string */
matcher.match.str.ptr = str;
matcher.match.str.end = str + len;
matcher.depth.max = max_depth;
/* TODO: implement the maximum depth
matcher.depth.max = awk->max_depth; */
matcher.depth.max = 0;
matcher.depth.cur = 0;
mat.matched = xp_false;
@ -346,10 +345,10 @@ int xp_awk_safematchrex (void* code,
return (mat.matched)? 1: 0;
}
void xp_awk_freerex (void* code)
void xp_awk_freerex (xp_awk_t* awk, void* code)
{
xp_assert (code != XP_NULL);
xp_free (code);
XP_AWK_FREE (awk, code);
}
xp_bool_t xp_awk_isemptyrex (void* code)
@ -907,26 +906,31 @@ static int __add_code (__builder_t* builder, void* data, xp_size_t len)
if (capa == 0) capa = DEF_CODE_CAPA;
while (len > capa - builder->code.size) { capa = capa * 2; }
#ifndef XP_AWK_NTDDK
tmp = (xp_byte_t*) xp_realloc (builder->code.buf, capa);
if (tmp == XP_NULL)
if (builder->awk->syscas->realloc != NULL)
{
builder->errnum = XP_AWK_ENOMEM;
return -1;
tmp = (xp_byte_t*) XP_AWK_REALLOC (
builder->awk, builder->code.buf, capa);
if (tmp == XP_NULL)
{
builder->errnum = XP_AWK_ENOMEM;
return -1;
}
}
#else
tmp = (xp_byte_t*) xp_malloc (capa);
if (tmp == XP_NULL)
else
{
builder->errnum = XP_AWK_ENOMEM;
return -1;
tmp = (xp_byte_t*) XP_AWK_MALLOC (builder->awk, capa);
if (tmp == XP_NULL)
{
builder->errnum = XP_AWK_ENOMEM;
return -1;
}
if (builder->code.buf != XP_NULL)
{
xp_memcpy (tmp, builder->code.buf, builder->code.capa);
XP_AWK_FREE (builder->awk, builder->code.buf);
}
}
if (builder->code.buf != XP_NULL)
{
xp_memcpy (tmp, builder->code.buf, builder->code.capa);
xp_free (builder->code.buf);
}
#endif
builder->code.buf = tmp;
builder->code.capa = capa;
@ -1305,8 +1309,8 @@ static const xp_byte_t* __match_group (
}
else
{
grp_len = (xp_size_t*) xp_malloc (
xp_sizeof(xp_size_t) * cp->ubound);
grp_len = (xp_size_t*) XP_AWK_MALLOC (
matcher->awk, xp_sizeof(xp_size_t) * cp->ubound);
if (grp_len == XP_NULL)
{
matcher->errnum = XP_AWK_ENOMEM;
@ -1323,7 +1327,8 @@ static const xp_byte_t* __match_group (
if (__match_pattern (matcher, p, &mat2) == XP_NULL)
{
if (grp_len != grp_len_static) xp_free (grp_len);
if (grp_len != grp_len_static)
XP_AWK_FREE (matcher->awk, grp_len);
return XP_NULL;
}
if (!mat2.matched) break;
@ -1365,7 +1370,7 @@ static const xp_byte_t* __match_group (
if (tmp == XP_NULL)
{
if (grp_len != grp_len_static)
xp_free (grp_len);
XP_AWK_FREE (matcher->awk, grp_len);
return XP_NULL;
}
@ -1385,7 +1390,7 @@ static const xp_byte_t* __match_group (
}
if (grp_len != grp_len_static) xp_free (grp_len);
if (grp_len != grp_len_static) XP_AWK_FREE (matcher->awk, grp_len);
return p;
}

View File

@ -1,5 +1,5 @@
/*
* $Id: rex.h,v 1.14 2006-08-30 07:15:14 bacon Exp $
* $Id: rex.h,v 1.15 2006-09-01 03:44:16 bacon Exp $
**/
#ifndef _XP_AWK_REX_H_
@ -46,21 +46,16 @@
extern "C" {
#endif
void* xp_awk_buildrex (const xp_char_t* ptn, xp_size_t len, int* errnum);
void* xp_awk_buildrex (
xp_awk_t* awk, const xp_char_t* ptn,
xp_size_t len, int* errnum);
void* xp_awk_safebuildrex (
const xp_char_t* ptn, xp_size_t len, int max_depth, int* errnum);
int xp_awk_matchrex (void* code,
int xp_awk_matchrex (
xp_awk_t* awk, void* code,
const xp_char_t* str, xp_size_t len,
const xp_char_t** match_ptr, xp_size_t* match_len, int* errnum);
int xp_awk_safematchrex (void* code,
const xp_char_t* str, xp_size_t len,
const xp_char_t** match_ptr, xp_size_t* match_len,
int max_depth, int* errnum);
void xp_awk_freerex (void* code);
void xp_awk_freerex (xp_awk_t* awk, void* code);
xp_bool_t xp_awk_isemptyrex (void* code);

View File

@ -1,5 +1,5 @@
/*
* $Id: run.c,v 1.190 2006-08-31 16:00:19 bacon Exp $
* $Id: run.c,v 1.191 2006-09-01 03:44:16 bacon Exp $
*/
#include <xp/awk/awk_i.h>
@ -262,7 +262,9 @@ int xp_awk_setglobal (void* run, xp_size_t idx, xp_awk_val_t* val)
/* compile the regular expression */
/* TODO: use safebuild */
rex = xp_awk_buildrex (rs_ptr, rs_len, &r->errnum);
rex = xp_awk_buildrex (
((xp_awk_run_t*)run)->awk,
rs_ptr, rs_len, &r->errnum);
if (rex == XP_NULL)
{
if (val->type != XP_AWK_VAL_STR)
@ -271,7 +273,11 @@ int xp_awk_setglobal (void* run, xp_size_t idx, xp_awk_val_t* val)
}
if (r->extio.rs_rex != XP_NULL)
xp_awk_freerex (r->extio.rs_rex);
{
xp_awk_freerex (
((xp_awk_run_t*)run)->awk,
r->extio.rs_rex);
}
r->extio.rs_rex = rex;
}
@ -514,15 +520,15 @@ static int __init_run (
}
if (xp_awk_map_open (&run->named,
run, DEF_BUF_CAPA, __free_namedval) == XP_NULL)
run, DEF_BUF_CAPA, __free_namedval, run->awk) == XP_NULL)
{
xp_awk_str_close (&run->inrec.line);
*errnum = XP_AWK_ENOMEM;
return -1;
}
run->pattern_range_state = (xp_byte_t*)
xp_calloc (run->awk->tree.chain_size, xp_sizeof(xp_byte_t));
run->pattern_range_state = (xp_byte_t*) XP_AWK_MALLOC (
run->awk, run->awk->tree.chain_size * xp_sizeof(xp_byte_t));
if (run->pattern_range_state == XP_NULL)
{
xp_awk_map_close (&run->named);
@ -531,6 +537,9 @@ static int __init_run (
return -1;
}
xp_memzero (run->pattern_range_state,
run->awk->tree.chain_size * xp_sizeof(xp_byte_t));
run->extio.handler[XP_AWK_EXTIO_PIPE] = runios->pipe;
run->extio.handler[XP_AWK_EXTIO_COPROC] = runios->coproc;
run->extio.handler[XP_AWK_EXTIO_FILE] = runios->file;
@ -1849,6 +1858,7 @@ static xp_awk_val_t* __eval_expression (xp_awk_run_t* run, xp_awk_nde_t* nde)
xp_awk_refupval (v);
n = xp_awk_matchrex (
((xp_awk_run_t*)run)->awk,
((xp_awk_val_rex_t*)v)->code,
((xp_awk_val_str_t*)run->inrec.d0)->buf,
((xp_awk_val_str_t*)run->inrec.d0)->len,
@ -3292,6 +3302,7 @@ static xp_awk_val_t* __eval_binop_match0 (
else if (right->type == XP_AWK_VAL_STR)
{
rex_code = xp_awk_buildrex (
run->awk,
((xp_awk_val_str_t*)right)->buf,
((xp_awk_val_str_t*)right)->len, &errnum);
if (rex_code == XP_NULL)
@ -3302,7 +3313,7 @@ static xp_awk_val_t* __eval_binop_match0 (
str = xp_awk_valtostr (run, right, xp_true, XP_NULL, &len);
if (str == XP_NULL) return XP_NULL;
rex_code = xp_awk_buildrex (str, len, &errnum);
rex_code = xp_awk_buildrex (run->awk, str, len, &errnum);
if (rex_code == XP_NULL)
{
XP_AWK_FREE (run->awk, str);
@ -3315,7 +3326,7 @@ static xp_awk_val_t* __eval_binop_match0 (
if (left->type == XP_AWK_VAL_STR)
{
n = xp_awk_matchrex (
rex_code,
run->awk, rex_code,
((xp_awk_val_str_t*)left)->buf,
((xp_awk_val_str_t*)left)->len,
XP_NULL, XP_NULL, &errnum);
@ -3345,7 +3356,8 @@ static xp_awk_val_t* __eval_binop_match0 (
}
n = xp_awk_matchrex (
rex_code, str, len, XP_NULL, XP_NULL, &errnum);
run->awk, rex_code,
str, len, XP_NULL, XP_NULL, &errnum);
if (n == -1)
{
XP_AWK_FREE (run->awk, str);

View File

@ -1,12 +1,12 @@
/*
* $Id: sa.c,v 1.32 2006-08-31 16:00:19 bacon Exp $
* $Id: sa.c,v 1.33 2006-09-01 03:44:16 bacon Exp $
*/
#include <xp/awk/awk_i.h>
#ifdef XP_AWK_STAND_ALONE
static xp_char_t* __adjust_format (const xp_char_t* format);
static xp_char_t* __adjust_format (xp_awk_t* awk, const xp_char_t* format);
xp_size_t xp_strlen (const xp_char_t* str)
{
@ -15,44 +15,6 @@ xp_size_t xp_strlen (const xp_char_t* str)
return p - str;
}
xp_char_t* xp_strdup (const xp_char_t* str)
{
xp_char_t* tmp;
tmp = (xp_char_t*) xp_malloc (
(xp_strlen(str) + 1) * xp_sizeof(xp_char_t));
if (tmp == XP_NULL) return XP_NULL;
xp_strcpy (tmp, str);
return tmp;
}
xp_char_t* xp_strxdup (const xp_char_t* str, xp_size_t len)
{
xp_char_t* tmp;
tmp = (xp_char_t*) xp_malloc ((len + 1) * xp_sizeof(xp_char_t));
if (tmp == XP_NULL) return XP_NULL;
xp_strncpy (tmp, str, len);
return tmp;
}
xp_char_t* xp_strxdup2 (
const xp_char_t* str1, xp_size_t len1,
const xp_char_t* str2, xp_size_t len2)
{
xp_char_t* tmp;
tmp = (xp_char_t*) xp_malloc (
(len1 + len2 + 1) * xp_sizeof(xp_char_t));
if (tmp == XP_NULL) return XP_NULL;
xp_strncpy (tmp, str1, len1);
xp_strncpy (tmp + len1, str2, len2);
return tmp;
}
xp_size_t xp_strcpy (xp_char_t* buf, const xp_char_t* str)
{
xp_char_t* org = buf;
@ -216,21 +178,21 @@ exit_loop:
return (p >= end)? XP_NULL: ((xp_char_t*)++p);
}
int xp_printf (const xp_char_t* fmt, ...)
int xp_awk_printf (xp_awk_t* awk, const xp_char_t* fmt, ...)
{
int n;
xp_va_list ap;
xp_va_start (ap, fmt);
n = xp_vprintf (fmt, ap);
n = xp_awk_vprintf (awk, fmt, ap);
xp_va_end (ap);
return n;
}
int xp_vprintf (const xp_char_t* fmt, xp_va_list ap)
int xp_awk_vprintf (xp_awk_t* awk, const xp_char_t* fmt, xp_va_list ap)
{
int n;
xp_char_t* nf = __adjust_format (fmt);
xp_char_t* nf = __adjust_format (awk, fmt);
if (nf == XP_NULL) return -1;
#ifdef XP_CHAR_IS_MCHAR
@ -239,25 +201,29 @@ int xp_vprintf (const xp_char_t* fmt, xp_va_list ap)
n = vwprintf (nf, ap);
#endif
xp_free (nf);
XP_AWK_FREE (awk, nf);
return n;
}
int xp_sprintf (xp_char_t* buf, xp_size_t size, const xp_char_t* fmt, ...)
int xp_awk_sprintf (
xp_awk_t* awk, xp_char_t* buf, xp_size_t size,
const xp_char_t* fmt, ...)
{
int n;
xp_va_list ap;
xp_va_start (ap, fmt);
n = xp_vsprintf (buf, size, fmt, ap);
n = xp_awk_vsprintf (awk, buf, size, fmt, ap);
xp_va_end (ap);
return n;
}
int xp_vsprintf (xp_char_t* buf, xp_size_t size, const xp_char_t* fmt, xp_va_list ap)
int xp_awk_vsprintf (
xp_awk_t* awk, xp_char_t* buf, xp_size_t size,
const xp_char_t* fmt, xp_va_list ap)
{
int n;
xp_char_t* nf = __adjust_format (fmt);
xp_char_t* nf = __adjust_format (awk, fmt);
if (nf == XP_NULL) return -1;
#if defined(dos) || defined(__dos)
@ -269,7 +235,7 @@ int xp_vsprintf (xp_char_t* buf, xp_size_t size, const xp_char_t* fmt, xp_va_lis
#else
n = vswprintf (buf, size, nf, ap);
#endif
xp_free (nf);
XP_AWK_FREE (awk, nf);
return n;
}
@ -285,7 +251,7 @@ int xp_vsprintf (xp_char_t* buf, xp_size_t size, const xp_char_t* fmt, xp_va_lis
} \
} while (0)
static xp_char_t* __adjust_format (const xp_char_t* format)
static xp_char_t* __adjust_format (xp_awk_t* awk, const xp_char_t* format)
{
const xp_char_t* fp = format;
xp_char_t* tmp;
@ -293,7 +259,7 @@ static xp_char_t* __adjust_format (const xp_char_t* format)
xp_char_t ch;
int modifier;
if (xp_awk_str_open (&str, 256) == XP_NULL) return XP_NULL;
if (xp_awk_str_open (&str, 256, awk) == XP_NULL) return XP_NULL;
while (*fp != XP_T('\0'))
{

View File

@ -1,5 +1,5 @@
/*
* $Id: sa.h,v 1.35 2006-08-31 16:00:19 bacon Exp $
* $Id: sa.h,v 1.36 2006-09-01 03:44:16 bacon Exp $
*/
#ifndef _XP_AWK_SA_H_
@ -21,9 +21,6 @@
#define xp_assert ASSERT
#define xp_malloc(size) ExAllocatePool(PagedPool,size)
#define xp_free(ptr) ExFreePool(ptr)
#define xp_memset(dst,fill,len) RtlFillMemory(dst,len,fill)
#define xp_memcpy(dst,src,len) RtlCopyMemory(dst,src,len)
#define xp_memmove(dst,src,len) RtlMoveMemory(dst,src,len)
@ -48,11 +45,6 @@
#define xp_assert assert
#define xp_malloc malloc
#define xp_calloc calloc
#define xp_realloc realloc
#define xp_free free
#define xp_memset(dst,fill,len) memset(dst,fill,len)
#define xp_memcpy(dst,src,len) memcpy(dst,src,len)
#define xp_memmove(dst,src,len) memmove(dst,src,len)
@ -103,17 +95,6 @@ extern "C" {
#define xp_strlen xp_awk_strlen
xp_size_t xp_strlen (const xp_char_t* str);
#define xp_strdup xp_awk_strdup
xp_char_t* xp_strdup (const xp_char_t* str);
#define xp_strxdup xp_awk_strxdup
xp_char_t* xp_strxdup (const xp_char_t* str, xp_size_t len);
#define xp_strxdup2 xp_awk_strxdup2
xp_char_t* xp_strxdup2 (
const xp_char_t* str1, xp_size_t len1,
const xp_char_t* str2, xp_size_t len2);
#define xp_strcpy xp_awk_strcpy
xp_size_t xp_strcpy (xp_char_t* buf, const xp_char_t* str);
@ -147,19 +128,17 @@ xp_char_t* xp_strxntok (
const xp_char_t* delim, xp_size_t delim_len,
xp_char_t** tok, xp_size_t* tok_len);
#define xp_printf xp_awk_printf
int xp_printf (const xp_char_t* fmt, ...);
int xp_awk_printf (xp_awk_t* awk, const xp_char_t* fmt, ...);
#define xp_vprintf xp_awk_vprintf
int xp_vprintf (const xp_char_t* fmt, xp_va_list ap);
int xp_awk_vprintf (xp_awk_t* awk, const xp_char_t* fmt, xp_va_list ap);
#define xp_sprintf xp_awk_sprintf
int xp_sprintf (
xp_char_t* buf, xp_size_t size, const xp_char_t* fmt, ...);
int xp_awk_sprintf (
xp_awk_t* awk, xp_char_t* buf,
xp_size_t size, const xp_char_t* fmt, ...);
#define xp_vsprintf xp_awk_vsprintf
int xp_vsprintf (
xp_char_t* buf, xp_size_t size, const xp_char_t* fmt, xp_va_list ap);
int xp_awk_vsprintf (
xp_awk_t* awk, xp_char_t* buf, xp_size_t size,
const xp_char_t* fmt, xp_va_list ap);
#ifdef __cplusplus
}

View File

@ -1,5 +1,5 @@
/*
* $Id: tab.c,v 1.13 2006-08-31 15:11:17 bacon Exp $
* $Id: tab.c,v 1.14 2006-09-01 03:44:16 bacon Exp $
*/
#include <xp/awk/awk_i.h>
@ -120,7 +120,7 @@ xp_size_t xp_awk_tab_insert (
xp_size_t i;
xp_char_t* str_dup;
str_dup = xp_strxdup(str, len);
str_dup = xp_awk_strxdup (tab->awk, str, len);
if (str_dup == XP_NULL) return (xp_size_t)-1;
if (index >= tab->capa)

View File

@ -1,5 +1,5 @@
/*
* $Id: tree.c,v 1.71 2006-08-21 14:51:32 bacon Exp $
* $Id: tree.c,v 1.72 2006-09-01 03:44:17 bacon Exp $
*/
#include <xp/awk/awk_i.h>
@ -231,16 +231,20 @@ static int __print_expression (xp_awk_t* awk, xp_awk_nde_t* nde)
case XP_AWK_NDE_INT:
{
#if defined(__LCC__)
xp_sprintf (tmp, xp_countof(tmp), XP_T("%lld"),
xp_awk_sprintf (
awk, tmp, xp_countof(tmp), XP_T("%lld"),
(long long)((xp_awk_nde_int_t*)nde)->val);
#elif defined(__BORLANDC__) || defined(_MSC_VER)
xp_sprintf (tmp, xp_countof(tmp), XP_T("%I64d"),
xp_awk_sprintf (
awk, tmp, xp_countof(tmp), XP_T("%I64d"),
(__int64)((xp_awk_nde_int_t*)nde)->val);
#elif defined(vax) || defined(__vax) || defined(_SCO_DS)
xp_sprintf (tmp, xp_countof(tmp), XP_T("%ld"),
xp_awk_sprintf (
awk, tmp, xp_countof(tmp), XP_T("%ld"),
(long)((xp_awk_nde_int_t*)nde)->val);
#else
xp_sprintf (tmp, xp_countof(tmp), XP_T("%lld"),
xp_awk_sprintf (
awk, tmp, xp_countof(tmp), XP_T("%lld"),
(long long)((xp_awk_nde_int_t*)nde)->val);
#endif
@ -250,7 +254,8 @@ static int __print_expression (xp_awk_t* awk, xp_awk_nde_t* nde)
case XP_AWK_NDE_REAL:
{
xp_sprintf (tmp, xp_countof(tmp), XP_T("%Lf"),
xp_awk_sprintf (
awk, tmp, xp_countof(tmp), XP_T("%Lf"),
(long double)((xp_awk_nde_real_t*)nde)->val);
PUT_SRCSTR (awk, tmp);
break;
@ -284,7 +289,8 @@ static int __print_expression (xp_awk_t* awk, xp_awk_nde_t* nde)
xp_assert (px->id.idxa != (xp_size_t)-1);
PUT_SRCSTR (awk, XP_T("__param"));
xp_sprintf (tmp, xp_countof(tmp),
xp_awk_sprintf (
awk, tmp, xp_countof(tmp),
XP_T("%lu"), (unsigned long)px->id.idxa);
PUT_SRCSTR (awk, tmp);
@ -299,7 +305,8 @@ static int __print_expression (xp_awk_t* awk, xp_awk_nde_t* nde)
xp_assert (px->idx != XP_NULL);
PUT_SRCSTR (awk, XP_T("__param"));
xp_sprintf (tmp, xp_countof(tmp),
xp_awk_sprintf (
awk, tmp, xp_countof(tmp),
XP_T("%lu"), (unsigned long)px->id.idxa);
PUT_SRCSTR (awk, tmp);
PUT_SRCSTR (awk, XP_T("["));
@ -337,7 +344,8 @@ static int __print_expression (xp_awk_t* awk, xp_awk_nde_t* nde)
if (px->id.idxa != (xp_size_t)-1)
{
PUT_SRCSTR (awk, XP_T("__global"));
xp_sprintf (tmp, xp_countof(tmp),
xp_awk_sprintf (
awk, tmp, xp_countof(tmp),
XP_T("%lu"), (unsigned long)px->id.idxa);
PUT_SRCSTR (awk, tmp);
}
@ -355,7 +363,8 @@ static int __print_expression (xp_awk_t* awk, xp_awk_nde_t* nde)
if (px->id.idxa != (xp_size_t)-1)
{
PUT_SRCSTR (awk, XP_T("__global"));
xp_sprintf (tmp, xp_countof(tmp),
xp_awk_sprintf (
awk, tmp, xp_countof(tmp),
XP_T("%lu"), (unsigned long)px->id.idxa);
PUT_SRCSTR (awk, tmp);
PUT_SRCSTR (awk, XP_T("["));
@ -377,7 +386,8 @@ static int __print_expression (xp_awk_t* awk, xp_awk_nde_t* nde)
if (px->id.idxa != (xp_size_t)-1)
{
PUT_SRCSTR (awk, XP_T("__local"));
xp_sprintf (tmp, xp_countof(tmp),
xp_awk_sprintf (
awk, tmp, xp_countof(tmp),
XP_T("%lu"), (unsigned long)px->id.idxa);
PUT_SRCSTR (awk, tmp);
}
@ -395,7 +405,8 @@ static int __print_expression (xp_awk_t* awk, xp_awk_nde_t* nde)
if (px->id.idxa != (xp_size_t)-1)
{
PUT_SRCSTR (awk, XP_T("__local"));
xp_sprintf (tmp, xp_countof(tmp),
xp_awk_sprintf (
awk, tmp, xp_countof(tmp),
XP_T("%lu"), (unsigned long)px->id.idxa);
PUT_SRCSTR (awk, tmp);
PUT_SRCSTR (awk, XP_T("["));
@ -528,13 +539,13 @@ static int __print_statements (xp_awk_t* awk, xp_awk_nde_t* tree, int depth)
for (i = 0; i < px->nlocals - 1; i++)
{
PUT_SRCSTR (awk, XP_T("__local"));
xp_sprintf (tmp, xp_countof(tmp), XP_T("%lu"), (unsigned long)i);
xp_awk_sprintf (awk, tmp, xp_countof(tmp), XP_T("%lu"), (unsigned long)i);
PUT_SRCSTR (awk, tmp);
PUT_SRCSTR (awk, XP_T(", "));
}
PUT_SRCSTR (awk, XP_T("__local"));
xp_sprintf (tmp, xp_countof(tmp), XP_T("%lu"), (unsigned long)i);
xp_awk_sprintf (awk, tmp, xp_countof(tmp), XP_T("%lu"), (unsigned long)i);
PUT_SRCSTR (awk, tmp);
PUT_SRCSTR (awk, XP_T(";\n"));
}
@ -799,7 +810,7 @@ int xp_awk_prnptnpt (xp_awk_t* awk, xp_awk_nde_t* tree)
return 0;
}
void xp_awk_clrpt (xp_awk_nde_t* tree)
void xp_awk_clrpt (xp_awk_t* awk, xp_awk_nde_t* tree)
{
xp_awk_nde_t* p = tree;
xp_awk_nde_t* next;
@ -812,35 +823,35 @@ void xp_awk_clrpt (xp_awk_nde_t* tree)
{
case XP_AWK_NDE_NULL:
{
xp_free (p);
XP_AWK_FREE (awk, p);
break;
}
case XP_AWK_NDE_BLK:
{
xp_awk_clrpt (((xp_awk_nde_blk_t*)p)->body);
xp_free (p);
xp_awk_clrpt (awk, ((xp_awk_nde_blk_t*)p)->body);
XP_AWK_FREE (awk, p);
break;
}
case XP_AWK_NDE_IF:
{
xp_awk_nde_if_t* px = (xp_awk_nde_if_t*)p;
xp_awk_clrpt (px->test);
xp_awk_clrpt (px->then_part);
xp_awk_clrpt (awk, px->test);
xp_awk_clrpt (awk, px->then_part);
if (px->else_part != XP_NULL)
xp_awk_clrpt (px->else_part);
xp_free (p);
xp_awk_clrpt (awk, px->else_part);
XP_AWK_FREE (awk, p);
break;
}
case XP_AWK_NDE_WHILE:
case XP_AWK_NDE_DOWHILE:
{
xp_awk_clrpt (((xp_awk_nde_while_t*)p)->test);
xp_awk_clrpt (((xp_awk_nde_while_t*)p)->body);
xp_free (p);
xp_awk_clrpt (awk, ((xp_awk_nde_while_t*)p)->test);
xp_awk_clrpt (awk, ((xp_awk_nde_while_t*)p)->body);
XP_AWK_FREE (awk, p);
break;
}
@ -849,33 +860,33 @@ void xp_awk_clrpt (xp_awk_nde_t* tree)
xp_awk_nde_for_t* px = (xp_awk_nde_for_t*)p;
if (px->init != XP_NULL)
xp_awk_clrpt (px->init);
xp_awk_clrpt (awk, px->init);
if (px->test != XP_NULL)
xp_awk_clrpt (px->test);
xp_awk_clrpt (awk, px->test);
if (px->incr != XP_NULL)
xp_awk_clrpt (px->incr);
xp_awk_clrpt (px->body);
xp_free (p);
xp_awk_clrpt (awk, px->incr);
xp_awk_clrpt (awk, px->body);
XP_AWK_FREE (awk, p);
break;
}
case XP_AWK_NDE_FOREACH:
{
xp_awk_clrpt (((xp_awk_nde_foreach_t*)p)->test);
xp_awk_clrpt (((xp_awk_nde_foreach_t*)p)->body);
xp_free (p);
xp_awk_clrpt (awk, ((xp_awk_nde_foreach_t*)p)->test);
xp_awk_clrpt (awk, ((xp_awk_nde_foreach_t*)p)->body);
XP_AWK_FREE (awk, p);
break;
}
case XP_AWK_NDE_BREAK:
{
xp_free (p);
XP_AWK_FREE (awk, p);
break;
}
case XP_AWK_NDE_CONTINUE:
{
xp_free (p);
XP_AWK_FREE (awk, p);
break;
}
@ -883,30 +894,31 @@ void xp_awk_clrpt (xp_awk_nde_t* tree)
{
xp_awk_nde_return_t* px =
(xp_awk_nde_return_t*)p;
if (px->val != XP_NULL) xp_awk_clrpt (px->val);
xp_free (p);
if (px->val != XP_NULL)
xp_awk_clrpt (awk, px->val);
XP_AWK_FREE (awk, p);
break;
}
case XP_AWK_NDE_EXIT:
{
if (((xp_awk_nde_exit_t*)p)->val != XP_NULL)
xp_awk_clrpt (((xp_awk_nde_exit_t*)p)->val);
xp_free (p);
xp_awk_clrpt (awk, ((xp_awk_nde_exit_t*)p)->val);
XP_AWK_FREE (awk, p);
break;
}
case XP_AWK_NDE_NEXT:
case XP_AWK_NDE_NEXTFILE:
{
xp_free (p);
XP_AWK_FREE (awk, p);
break;
}
case XP_AWK_NDE_DELETE:
{
xp_awk_clrpt (((xp_awk_nde_delete_t*)p)->var);
xp_free (p);
xp_awk_clrpt (awk, ((xp_awk_nde_delete_t*)p)->var);
XP_AWK_FREE (awk, p);
break;
}
@ -914,24 +926,26 @@ void xp_awk_clrpt (xp_awk_nde_t* tree)
{
xp_awk_nde_print_t* px =
(xp_awk_nde_print_t*)p;
if (px->args != XP_NULL) xp_awk_clrpt (px->args);
if (px->out != XP_NULL) xp_awk_clrpt (px->out);
xp_free (p);
if (px->args != XP_NULL)
xp_awk_clrpt (awk, px->args);
if (px->out != XP_NULL)
xp_awk_clrpt (awk, px->out);
XP_AWK_FREE (awk, p);
break;
}
case XP_AWK_NDE_GRP:
{
xp_awk_clrpt (((xp_awk_nde_grp_t*)p)->body);
xp_free (p);
xp_awk_clrpt (awk, ((xp_awk_nde_grp_t*)p)->body);
XP_AWK_FREE (awk, p);
break;
}
case XP_AWK_NDE_ASS:
{
xp_awk_clrpt (((xp_awk_nde_ass_t*)p)->left);
xp_awk_clrpt (((xp_awk_nde_ass_t*)p)->right);
xp_free (p);
xp_awk_clrpt (awk, ((xp_awk_nde_ass_t*)p)->left);
xp_awk_clrpt (awk, ((xp_awk_nde_ass_t*)p)->right);
XP_AWK_FREE (awk, p);
break;
}
@ -941,9 +955,9 @@ void xp_awk_clrpt (xp_awk_nde_t* tree)
xp_assert (px->left->next == XP_NULL);
xp_assert (px->right->next == XP_NULL);
xp_awk_clrpt (px->left);
xp_awk_clrpt (px->right);
xp_free (p);
xp_awk_clrpt (awk, px->left);
xp_awk_clrpt (awk, px->right);
XP_AWK_FREE (awk, p);
break;
}
@ -953,44 +967,44 @@ void xp_awk_clrpt (xp_awk_nde_t* tree)
{
xp_awk_nde_exp_t* px = (xp_awk_nde_exp_t*)p;
xp_assert (px->right == XP_NULL);
xp_awk_clrpt (px->left);
xp_free (p);
xp_awk_clrpt (awk, px->left);
XP_AWK_FREE (awk, p);
break;
}
case XP_AWK_NDE_CND:
{
xp_awk_clrpt (((xp_awk_nde_cnd_t*)p)->test);
xp_awk_clrpt (((xp_awk_nde_cnd_t*)p)->left);
xp_awk_clrpt (((xp_awk_nde_cnd_t*)p)->right);
xp_free (p);
xp_awk_clrpt (awk, ((xp_awk_nde_cnd_t*)p)->test);
xp_awk_clrpt (awk, ((xp_awk_nde_cnd_t*)p)->left);
xp_awk_clrpt (awk, ((xp_awk_nde_cnd_t*)p)->right);
XP_AWK_FREE (awk, p);
break;
}
case XP_AWK_NDE_INT:
{
xp_free (p);
XP_AWK_FREE (awk, p);
break;
}
case XP_AWK_NDE_REAL:
{
xp_free (p);
XP_AWK_FREE (awk, p);
break;
}
case XP_AWK_NDE_STR:
{
xp_free (((xp_awk_nde_str_t*)p)->buf);
xp_free (p);
XP_AWK_FREE (awk, ((xp_awk_nde_str_t*)p)->buf);
XP_AWK_FREE (awk, p);
break;
}
case XP_AWK_NDE_REX:
{
xp_free (((xp_awk_nde_rex_t*)p)->buf);
xp_free (((xp_awk_nde_rex_t*)p)->code);
xp_free (p);
XP_AWK_FREE (awk, ((xp_awk_nde_rex_t*)p)->buf);
XP_AWK_FREE (awk, ((xp_awk_nde_rex_t*)p)->code);
XP_AWK_FREE (awk, p);
break;
}
@ -1002,8 +1016,8 @@ void xp_awk_clrpt (xp_awk_nde_t* tree)
xp_awk_nde_var_t* px = (xp_awk_nde_var_t*)p;
xp_assert (px->idx == XP_NULL);
if (px->id.name != XP_NULL)
xp_free (px->id.name);
xp_free (p);
XP_AWK_FREE (awk, px->id.name);
XP_AWK_FREE (awk, p);
break;
}
@ -1014,35 +1028,35 @@ void xp_awk_clrpt (xp_awk_nde_t* tree)
{
xp_awk_nde_var_t* px = (xp_awk_nde_var_t*)p;
xp_assert (px->idx != XP_NULL);
xp_awk_clrpt (px->idx);
xp_awk_clrpt (awk, px->idx);
if (px->id.name != XP_NULL)
xp_free (px->id.name);
xp_free (p);
XP_AWK_FREE (awk, px->id.name);
XP_AWK_FREE (awk, p);
break;
}
case XP_AWK_NDE_POS:
{
xp_awk_clrpt (((xp_awk_nde_pos_t*)p)->val);
xp_free (p);
xp_awk_clrpt (awk, ((xp_awk_nde_pos_t*)p)->val);
XP_AWK_FREE (awk, p);
break;
}
case XP_AWK_NDE_BFN:
{
xp_awk_nde_call_t* px = (xp_awk_nde_call_t*)p;
/* xp_free (px->what.bfn); */
xp_awk_clrpt (px->args);
xp_free (p);
/* XP_AWK_FREE (awk, px->what.bfn); */
xp_awk_clrpt (awk, px->args);
XP_AWK_FREE (awk, p);
break;
}
case XP_AWK_NDE_AFN:
{
xp_awk_nde_call_t* px = (xp_awk_nde_call_t*)p;
xp_free (px->what.afn.name);
xp_awk_clrpt (px->args);
xp_free (p);
XP_AWK_FREE (awk, px->what.afn.name);
xp_awk_clrpt (awk, px->args);
XP_AWK_FREE (awk, p);
break;
}
@ -1050,16 +1064,18 @@ void xp_awk_clrpt (xp_awk_nde_t* tree)
{
xp_awk_nde_getline_t* px =
(xp_awk_nde_getline_t*)p;
if (px->var != XP_NULL) xp_awk_clrpt (px->var);
if (px->in != XP_NULL) xp_awk_clrpt (px->in);
xp_free (p);
if (px->var != XP_NULL)
xp_awk_clrpt (awk, px->var);
if (px->in != XP_NULL)
xp_awk_clrpt (awk, px->in);
XP_AWK_FREE (awk, p);
break;
}
default:
{
xp_assert (!"should never happen - invalid node type");
xp_free (p);
XP_AWK_FREE (awk, p);
break;
}
}

View File

@ -1,5 +1,5 @@
/*
* $Id: tree.h,v 1.70 2006-08-20 15:49:06 bacon Exp $
* $Id: tree.h,v 1.71 2006-09-01 03:44:21 bacon Exp $
*/
#ifndef _XP_AWK_TREE_H_
@ -367,7 +367,7 @@ extern "C" {
int xp_awk_prnpt (xp_awk_t* awk, xp_awk_nde_t* tree);
int xp_awk_prnptnpt (xp_awk_t* awk, xp_awk_nde_t* tree);
void xp_awk_clrpt (xp_awk_nde_t* tree);
void xp_awk_clrpt (xp_awk_t* awk, xp_awk_nde_t* tree);
#ifdef __cplusplus
}

View File

@ -1,5 +1,5 @@
/*
* $Id: val.c,v 1.56 2006-08-31 16:00:20 bacon Exp $
* $Id: val.c,v 1.57 2006-09-01 03:44:21 bacon Exp $
*/
#include <xp/awk/awk_i.h>
@ -104,7 +104,7 @@ xp_awk_val_t* xp_awk_makestrval (
val->type = XP_AWK_VAL_STR;
val->ref = 0;
val->len = len;
val->buf = xp_strxdup (str, len);
val->buf = xp_awk_strxdup (run->awk, str, len);
if (val->buf == XP_NULL)
{
XP_AWK_FREE (run->awk, val);
@ -129,7 +129,7 @@ xp_awk_val_t* xp_awk_makestrval2 (
val->type = XP_AWK_VAL_STR;
val->ref = 0;
val->len = len1 + len2;
val->buf = xp_strxdup2 (str1, len1, str2, len2);
val->buf = xp_awk_strxdup2 (run->awk, str1, len1, str2, len2);
if (val->buf == XP_NULL)
{
XP_AWK_FREE (run->awk, val);
@ -152,7 +152,7 @@ xp_awk_val_t* xp_awk_makerexval (
val->type = XP_AWK_VAL_REX;
val->ref = 0;
val->len = len;
val->buf = xp_strxdup (buf, len);
val->buf = xp_awk_strxdup (run->awk, buf, len);
if (val->buf == XP_NULL)
{
XP_AWK_FREE (run->awk, val);
@ -191,7 +191,8 @@ xp_awk_val_t* xp_awk_makemapval (xp_awk_run_t* run)
val->type = XP_AWK_VAL_MAP;
val->ref = 0;
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, run->awk);
if (val->map == XP_NULL)
{
XP_AWK_FREE (run->awk, val);
@ -272,7 +273,7 @@ xp_printf (XP_T("\n"));*/
else if (val->type == XP_AWK_VAL_REX)
{
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 (run->awk, ((xp_awk_val_rex_t*)val)->code);
XP_AWK_FREE (run->awk, val);
}
else if (val->type == XP_AWK_VAL_MAP)
@ -374,7 +375,7 @@ xp_char_t* xp_awk_valtostr (
if (buf == XP_NULL)
{
xp_char_t* tmp;
tmp = xp_strdup (XP_T(""));
tmp = xp_awk_strdup (run->awk, XP_T(""));
if (tmp == XP_NULL)
{
run->errnum = XP_AWK_ENOMEM;
@ -491,12 +492,12 @@ xp_char_t* xp_awk_valtostr (
xp_char_t tbuf[256], * tmp;
#if (XP_SIZEOF_LONG_DOUBLE != 0)
xp_sprintf (
tbuf, xp_countof(tbuf), XP_T("%Lf"),
xp_awk_sprintf (
run->awk, tbuf, xp_countof(tbuf), XP_T("%Lf"),
(long double)((xp_awk_val_real_t*)v)->val);
#elif (XP_SIZEOF_DOUBLE != 0)
xp_sprintf (
tbuf, xp_countof(tbuf), XP_T("%f"),
xp_awk_sprintf (
run->awk, tbuf, xp_countof(tbuf), XP_T("%f"),
(double)((xp_awk_val_real_t*)v)->val);
#else
#error unsupported floating-point data type
@ -504,7 +505,7 @@ xp_char_t* xp_awk_valtostr (
if (buf == XP_NULL)
{
tmp = xp_strdup (tbuf);
tmp = xp_awk_strdup (run->awk, tbuf);
if (tmp == XP_NULL)
{
run->errnum = XP_AWK_ENOMEM;
@ -536,7 +537,8 @@ xp_char_t* xp_awk_valtostr (
if (buf == XP_NULL)
{
tmp = xp_strxdup (
tmp = xp_awk_strxdup (
run->awk,
((xp_awk_val_str_t*)v)->buf,
((xp_awk_val_str_t*)v)->len);
if (tmp == XP_NULL)

View File

@ -1,5 +1,5 @@
/*
* $Id: awk.c,v 1.81 2006-08-31 14:03:38 bacon Exp $
* $Id: awk.c,v 1.82 2006-09-01 03:44:51 bacon Exp $
*/
#include <xp/awk/awk.h>
@ -34,8 +34,6 @@
#endif
#ifdef __STAND_ALONE
#define xp_printf xp_awk_printf
extern int xp_awk_printf (const xp_char_t* fmt, ...);
#define xp_strcmp xp_awk_strcmp
extern int xp_awk_strcmp (const xp_char_t* s1, const xp_char_t* s2);
#define xp_strlen xp_awk_strlen
@ -568,7 +566,11 @@ static void* __awk_malloc (xp_size_t n, void* custom_data)
static void* __awk_realloc (void* ptr, xp_size_t n, void* custom_data)
{
#ifdef _WIN32
return HeapReAlloc (((syscas_data_t*)custom_data)->heap, 0, ptr, n);
/* HeapReAlloc behaves differently from realloc */
if (ptr == NULL)
return HeapAlloc (((syscas_data_t*)custom_data)->heap, 0, n);
else
return HeapReAlloc (((syscas_data_t*)custom_data)->heap, 0, ptr, n);
#else
return realloc (ptr, n);
#endif
@ -607,7 +609,6 @@ static int __main (int argc, xp_char_t* argv[])
if (argc <= 1)
{
xp_awk_close (awk);
xp_printf (XP_T("Usage: %s [-m] source_file [data_file]\n"), argv[0]);
return -1;
}
@ -642,13 +643,13 @@ static int __main (int argc, xp_char_t* argv[])
memset (&syscas, 0, sizeof(syscas));
syscas.malloc = __awk_malloc;
syscas.realloc = NULL;
syscas.realloc = __awk_realloc;
syscas.free = __awk_free;
syscas.lock = NULL;
syscas.unlock = NULL;
#ifdef _WIN32
syscas_data.heap = HeapCreate (0, 640 * 1024, 640 * 1024);
syscas_data.heap = HeapCreate (0, 1000000, 1000000);
if (syscas_data.heap == NULL)
{
xp_printf (XP_T("Error: cannot create an awk heap\n"));

View File

@ -2,9 +2,9 @@ CC = cl
#CFLAGS = /nologo /MT /W3 /GR- /D_WIN32_WINNT=0x0400 -I..\..\..
CFLAGS = /nologo /MT /W3 /GR- /D_WIN32_WINNT=0x0400 -I..\..\.. -D__STAND_ALONE
LDFLAGS = /libpath:..\..\bas /libpath:..\..\awk
LIBS = xpawk.lib user32.lib
LIBS = xpbas.lib xpawk.lib user32.lib
all: awk rex2 rex3
all: awk #rex2 rex3
awk: awk.obj
link /nologo /out:awk.exe $(LDFLAGS) $(LIBS) awk.obj