*** empty log message ***

This commit is contained in:
hyung-hwan 2006-03-05 17:07:33 +00:00
parent 105878c6cf
commit 3d107dd3b2
12 changed files with 330 additions and 198 deletions

View File

@ -1,5 +1,5 @@
/*
* $Id: awk.c,v 1.26 2006-03-04 10:06:49 bacon Exp $
* $Id: awk.c,v 1.27 2006-03-05 17:07:32 bacon Exp $
*/
#include <xp/awk/awk.h>
@ -55,8 +55,8 @@ xp_awk_t* xp_awk_open (xp_awk_t* awk)
return XP_NULL;
}
/* TODO: maybe a free function .... */
if (xp_awk_map_open(&awk->run.named, 256, XP_NULL) == XP_NULL) {
// TODO: initial map size...
if (xp_awk_map_open(&awk->run.named, 256, xp_awk_freeval) == XP_NULL) {
xp_str_close (&awk->token.name);
xp_awk_map_close (&awk->tree.funcs);
xp_awk_tab_close (&awk->parse.globals);
@ -90,13 +90,17 @@ xp_awk_t* xp_awk_open (xp_awk_t* awk)
int xp_awk_close (xp_awk_t* awk)
{
xp_awk_clear (awk);
if (xp_awk_detsrc(awk) == -1) return -1;
xp_awk_map_close (&awk->run.named);
xp_awk_map_close (&awk->tree.funcs);
xp_awk_tab_close (&awk->parse.globals);
xp_awk_tab_close (&awk->parse.locals);
xp_awk_tab_close (&awk->parse.params);
xp_awk_map_close (&awk->run.named);
xp_str_close (&awk->token.name);
if (awk->__dynamic) xp_free (awk);
return 0;
}
@ -107,6 +111,8 @@ int xp_awk_close (xp_awk_t* awk)
void xp_awk_clear (xp_awk_t* awk)
{
xp_awk_map_clear (&awk->run.named);
xp_awk_tab_clear (&awk->parse.globals);
xp_awk_tab_clear (&awk->parse.locals);
xp_awk_tab_clear (&awk->parse.params);
@ -115,6 +121,7 @@ void xp_awk_clear (xp_awk_t* awk)
/* clear parse trees */
awk->tree.nglobals = 0;
xp_awk_map_clear (&awk->tree.funcs);
if (awk->tree.begin != XP_NULL) {
xp_assert (awk->tree.begin->next == XP_NULL);
xp_awk_clrpt (awk->tree.begin);

View File

@ -1,5 +1,5 @@
/*
* $Id: map.c,v 1.3 2006-03-03 11:51:48 bacon Exp $
* $Id: map.c,v 1.4 2006-03-05 17:07:32 bacon Exp $
*/
#include <xp/awk/awk.h>
@ -18,13 +18,13 @@ static xp_size_t __hash (const xp_char_t* key);
#define FREE_PAIR(map,pair) \
do { \
xp_free ((pair)->key); \
if ((map)->free_value != XP_NULL) \
(map)->free_value ((pair)->value); \
if ((map)->freeval != XP_NULL) \
(map)->freeval ((pair)->val); \
xp_free (pair); \
} while (0)
xp_awk_map_t* xp_awk_map_open (
xp_awk_map_t* map, xp_size_t capa, void (*free_value) (void*))
xp_awk_map_t* map, xp_size_t capa, void (*freeval) (void*))
{
if (map == XP_NULL) {
map = (xp_awk_map_t*) xp_malloc (xp_sizeof(xp_awk_map_t));
@ -42,7 +42,7 @@ xp_awk_map_t* xp_awk_map_open (
map->capa = capa;
map->size = 0;
map->free_value = free_value;
map->freeval = freeval;
while (capa > 0) map->buck[--capa] = XP_NULL;
return map;
@ -78,7 +78,7 @@ void xp_awk_map_clear (xp_awk_map_t* map)
xp_assert (map->size == 0);
}
xp_awk_pair_t* xp_awk_map_get (xp_awk_map_t* map, xp_char_t* key)
xp_awk_pair_t* xp_awk_map_get (xp_awk_map_t* map, const xp_char_t* key)
{
xp_awk_pair_t* pair;
xp_size_t hc;
@ -94,6 +94,16 @@ xp_awk_pair_t* xp_awk_map_get (xp_awk_map_t* map, xp_char_t* key)
return XP_NULL;
}
void* xp_awk_map_getval (xp_awk_map_t* map, const xp_char_t* key)
{
xp_awk_pair_t* pair;
pair = xp_awk_map_get (map, key);
if (pair == XP_NULL) return XP_NULL;
return pair->val;
}
xp_awk_pair_t* xp_awk_map_put (xp_awk_map_t* map, xp_char_t* key, void* value)
{
xp_awk_pair_t* pair;
@ -109,10 +119,10 @@ xp_awk_pair_t* xp_awk_map_put (xp_awk_map_t* map, xp_char_t* key, void* value)
xp_free (pair->key);
pair->key = key;
}
if (map->free_value != XP_NULL) {
map->free_value (pair->value);
if (map->freeval != XP_NULL) {
map->freeval (pair->val);
}
pair->value = value;
pair->val = value;
return pair;
}
@ -123,7 +133,7 @@ xp_awk_pair_t* xp_awk_map_put (xp_awk_map_t* map, xp_char_t* key, void* value)
if (pair == XP_NULL) return XP_NULL;
pair->key = key;
pair->value = value;
pair->val = value;
pair->next = map->buck[hc];
map->buck[hc] = pair;
map->size++;
@ -146,10 +156,10 @@ xp_awk_pair_t* xp_awk_map_set (xp_awk_map_t* map, xp_char_t* key, void* value)
pair->key = key;
}
if (map->free_value != XP_NULL) {
map->free_value (pair->value);
if (map->freeval != XP_NULL) {
map->freeval (pair->val);
}
pair->value = value;
pair->val = value;
return pair;
}
@ -159,7 +169,7 @@ xp_awk_pair_t* xp_awk_map_set (xp_awk_map_t* map, xp_char_t* key, void* value)
return XP_NULL;
}
int xp_awk_map_remove (xp_awk_map_t* map, xp_char_t* key)
int xp_awk_map_remove (xp_awk_map_t* map, const xp_char_t* key)
{
xp_awk_pair_t* pair, * prev;
xp_size_t hc;

View File

@ -1,5 +1,5 @@
/*
* $Id: map.h,v 1.2 2006-03-03 11:51:48 bacon Exp $
* $Id: map.h,v 1.3 2006-03-05 17:07:32 bacon Exp $
*/
#ifndef _XP_AWK_MAP_H_
@ -22,7 +22,7 @@ typedef struct xp_awk_pair_t xp_awk_pair_t;
struct xp_awk_pair_t
{
xp_char_t* key;
void* value;
void* val;
xp_awk_pair_t* next;
};
@ -31,7 +31,7 @@ struct xp_awk_map_t
xp_size_t size;
xp_size_t capa;
xp_awk_pair_t** buck;
void (*free_value) (void*);
void (*freeval) (void*);
xp_bool_t __dynamic;
};
@ -40,16 +40,18 @@ extern "C" {
#endif
xp_awk_map_t* xp_awk_map_open (
xp_awk_map_t* map, xp_size_t capa, void (*free_value) (void*));
xp_awk_map_t* map, xp_size_t capa, void (*freeval) (void*));
void xp_awk_map_close (xp_awk_map_t* map);
void xp_awk_map_clear (xp_awk_map_t* map);
xp_awk_pair_t* xp_awk_map_get (xp_awk_map_t* map, xp_char_t* key);
xp_awk_pair_t* xp_awk_map_put (xp_awk_map_t* map, xp_char_t* key, void* value);
xp_awk_pair_t* xp_awk_map_set (xp_awk_map_t* map, xp_char_t* key, void* value);
xp_awk_pair_t* xp_awk_map_get (xp_awk_map_t* map, const xp_char_t* key);
void* xp_awk_map_getval (xp_awk_map_t* map, const xp_char_t* key);
int xp_awk_map_remove (xp_awk_map_t* map, xp_char_t* key);
xp_awk_pair_t* xp_awk_map_put (xp_awk_map_t* map, xp_char_t* key, void* val);
xp_awk_pair_t* xp_awk_map_set (xp_awk_map_t* map, xp_char_t* key, void* val);
int xp_awk_map_remove (xp_awk_map_t* map, const xp_char_t* key);
int xp_awk_map_walk (xp_awk_map_t* map, int (*walker) (xp_awk_pair_t*));
#ifdef __cplusplus

View File

@ -1,5 +1,5 @@
/*
* $Id: parse.c,v 1.57 2006-03-04 15:54:37 bacon Exp $
* $Id: parse.c,v 1.58 2006-03-05 17:07:32 bacon Exp $
*/
#include <xp/awk/awk.h>
@ -138,8 +138,6 @@ static int __skip_spaces (xp_awk_t* awk);
static int __skip_comment (xp_awk_t* awk);
static int __classify_ident (xp_awk_t* awk, const xp_char_t* ident);
static xp_long_t __str_to_long (const xp_char_t* name);
struct __kwent
{
const xp_char_t* name;
@ -211,7 +209,7 @@ do { \
#endif
static int __dump_func (xp_awk_pair_t* pair)
{
xp_awk_func_t* func = (xp_awk_func_t*)pair->value;
xp_awk_func_t* func = (xp_awk_func_t*)pair->val;
xp_size_t i;
xp_assert (xp_strcmp(pair->key, func->name) == 0);
@ -531,7 +529,7 @@ 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);
func = (xp_awk_func_t*) xp_malloc (xp_sizeof(xp_awk_func_t));
func = (xp_awk_func_t*)xp_malloc(xp_sizeof(xp_awk_func_t));
if (func == XP_NULL)
{
xp_free (name_dup);
@ -591,7 +589,7 @@ static xp_awk_nde_t* __parse_patternless (xp_awk_t* awk)
nde = __parse_action (awk);
if (nde == XP_NULL) return XP_NULL;
chain = (xp_awk_chain_t*) xp_malloc (xp_sizeof(xp_awk_chain_t));
chain = (xp_awk_chain_t*)xp_malloc(xp_sizeof(xp_awk_chain_t));
if (chain == XP_NULL)
{
xp_awk_clrpt (nde);
@ -626,7 +624,7 @@ static xp_awk_nde_t* __parse_action (xp_awk_t* awk)
static xp_awk_nde_t* __parse_block (xp_awk_t* awk, xp_bool_t is_top)
{
xp_awk_nde_t* head, * curr, * nde;
xp_awk_nde_block_t* block;
xp_awk_nde_blk_t* block;
xp_size_t nlocals, nlocals_max, tmp;
nlocals = xp_awk_tab_getsize(&awk->parse.locals);
@ -696,15 +694,15 @@ static xp_awk_nde_t* __parse_block (xp_awk_t* awk, xp_bool_t is_top)
/* remove unnecessary statements */
if (nde->type == XP_AWK_NDE_NULL ||
(nde->type == XP_AWK_NDE_BLOCK &&
((xp_awk_nde_block_t*)nde)->body == XP_NULL)) continue;
(nde->type == XP_AWK_NDE_BLK &&
((xp_awk_nde_blk_t*)nde)->body == XP_NULL)) continue;
if (curr == XP_NULL) head = nde;
else curr->next = nde;
curr = nde;
}
block = (xp_awk_nde_block_t*) xp_malloc (xp_sizeof(xp_awk_nde_block_t));
block = (xp_awk_nde_blk_t*)xp_malloc(xp_sizeof(xp_awk_nde_blk_t));
if (block == XP_NULL)
{
xp_awk_tab_remrange (
@ -723,7 +721,7 @@ static xp_awk_nde_t* __parse_block (xp_awk_t* awk, xp_bool_t is_top)
/* adjust number of locals for a block without any statements */
if (head == NULL) tmp = 0;
block->type = XP_AWK_NDE_BLOCK;
block->type = XP_AWK_NDE_BLK;
block->next = XP_NULL;
block->body = head;
@ -863,7 +861,7 @@ static xp_awk_nde_t* __parse_statement (xp_awk_t* awk)
if (MATCH(awk,TOKEN_SEMICOLON))
{
/* null statement */
nde = (xp_awk_nde_t*) xp_malloc (xp_sizeof(xp_awk_nde_t));
nde = (xp_awk_nde_t*)xp_malloc(xp_sizeof(xp_awk_nde_t));
if (nde == XP_NULL) PANIC (awk, XP_AWK_ENOMEM);
nde->type = XP_AWK_NDE_NULL;
@ -1022,7 +1020,7 @@ static xp_awk_nde_t* __parse_expression (xp_awk_t* awk)
return XP_NULL;
}
nde = (xp_awk_nde_ass_t*)xp_malloc (xp_sizeof(xp_awk_nde_ass_t));
nde = (xp_awk_nde_ass_t*)xp_malloc(xp_sizeof(xp_awk_nde_ass_t));
if (nde == XP_NULL)
{
xp_awk_clrpt (x);
@ -1285,45 +1283,34 @@ static xp_awk_nde_t* __parse_multiplicative (xp_awk_t* awk)
/* TODO: enhance constant folding. do it in a better way */
/* TODO: differentiate different types of numbers ... */
if (left->type == XP_AWK_NDE_NUM &&
right->type == XP_AWK_NDE_NUM)
if (left->type == XP_AWK_NDE_INT &&
right->type == XP_AWK_NDE_INT)
{
xp_long_t l, r;
xp_awk_nde_trm_t* tmp;
xp_char_t buf[256];
l = __str_to_long (((xp_awk_nde_trm_t*)left)->value);
r = __str_to_long (((xp_awk_nde_trm_t*)right)->value);
l = ((xp_awk_nde_int_t*)left)->val;
r = ((xp_awk_nde_int_t*)right)->val;
xp_awk_clrpt (left);
xp_awk_clrpt (right);
if (opcode == BINOP_MUL) l *= r;
else if (opcode == BINOP_DIV) l /= r;
else if (opcode == BINOP_MOD) l %= r;
#if defined(vax) || defined(__vax)
xp_sprintf (buf, xp_countof(buf), XP_TEXT("%ld"), (long)l);
#else
xp_sprintf (buf, xp_countof(buf), XP_TEXT("%lld"), (long long)l);
#endif
tmp = (xp_awk_nde_trm_t*) xp_malloc (xp_sizeof(xp_awk_nde_trm_t));
if (tmp == XP_NULL) PANIC (awk, XP_AWK_ENOMEM);
tmp->type = XP_AWK_NDE_NUM;
tmp->next = XP_NULL;
tmp->value = xp_strdup (buf);
if (tmp->value == XP_NULL)
{
xp_free (tmp);
PANIC (awk, XP_AWK_ENOMEM);
}
left = (xp_awk_nde_t*) tmp;
((xp_awk_nde_int_t*)left)->val = l;
continue;
}
/* TODO:
else if (left->type == XP_AWK_NDE_REAL &&
right->type == XP_AWK_NDE_REAL)
{
}
else if (left->type == XP_AWK_NDE_STR &&
right->type == XP_AWK_NDE_STR)
{
// TODO: string concatenation operator....
}
*/
nde = (xp_awk_nde_exp_t*)xp_malloc(xp_sizeof(xp_awk_nde_exp_t));
if (nde == XP_NULL)
@ -1449,39 +1436,43 @@ static xp_awk_nde_t* __parse_primary (xp_awk_t* awk)
}
else if (MATCH(awk,TOKEN_INTEGER))
{
xp_awk_nde_trm_t* nde;
xp_awk_nde_int_t* nde;
nde = (xp_awk_nde_trm_t*)xp_malloc(xp_sizeof(xp_awk_nde_trm_t));
nde = (xp_awk_nde_int_t*)xp_malloc(xp_sizeof(xp_awk_nde_int_t));
if (nde == XP_NULL) PANIC (awk, XP_AWK_ENOMEM);
nde->type = XP_AWK_NDE_NUM;
nde->type = XP_AWK_NDE_INT;
nde->next = XP_NULL;
nde->value = xp_strdup(XP_STR_BUF(&awk->token.name));
if (nde->value == XP_NULL)
{
xp_free (nde);
PANIC (awk, XP_AWK_ENOMEM);
}
nde->val = xp_strtolong (XP_STR_BUF(&awk->token.name));
xp_assert (
XP_STR_LEN(&awk->token.name) ==
xp_strlen(XP_STR_BUF(&awk->token.name)));
if (__get_token(awk) == -1)
{
xp_free (nde->value);
xp_free (nde);
return XP_NULL;
}
return (xp_awk_nde_t*)nde;
}
/* TODO: floating point number */
/*
else if (MATCH(awk,TOKEN_REAL)) {
}
*/
else if (MATCH(awk,TOKEN_STRING)) {
xp_awk_nde_trm_t* nde;
xp_awk_nde_str_t* nde;
nde = (xp_awk_nde_trm_t*)xp_malloc(xp_sizeof(xp_awk_nde_trm_t));
nde = (xp_awk_nde_str_t*)xp_malloc(xp_sizeof(xp_awk_nde_str_t));
if (nde == XP_NULL) PANIC (awk, XP_AWK_ENOMEM);
nde->type = XP_AWK_NDE_STR;
nde->next = XP_NULL;
nde->value = xp_strdup(XP_STR_BUF(&awk->token.name));
if (nde->value == XP_NULL)
nde->len = XP_STR_LEN(&awk->token.name);
nde->buf = xp_strxdup(XP_STR_BUF(&awk->token.name), nde->len);
if (nde->buf == XP_NULL)
{
xp_free (nde);
PANIC (awk, XP_AWK_ENOMEM);
@ -1489,7 +1480,7 @@ static xp_awk_nde_t* __parse_primary (xp_awk_t* awk)
if (__get_token(awk) == -1)
{
xp_free (nde->value);
xp_free (nde->buf);
xp_free (nde);
return XP_NULL;
}
@ -1506,7 +1497,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*) xp_malloc (xp_sizeof(xp_awk_nde_pos_t));
nde = (xp_awk_nde_pos_t*)xp_malloc(xp_sizeof(xp_awk_nde_pos_t));
if (nde == XP_NULL)
{
xp_awk_clrpt (prim);
@ -1515,7 +1506,7 @@ static xp_awk_nde_t* __parse_primary (xp_awk_t* awk)
nde->type = XP_AWK_NDE_POS;
nde->next = XP_NULL;
nde->value = prim;
nde->val = prim;
return (xp_awk_nde_t*)nde;
}
@ -1573,7 +1564,7 @@ static xp_awk_nde_t* __parse_hashidx (xp_awk_t* awk, xp_char_t* name)
return XP_NULL;
}
nde = (xp_awk_nde_idx_t*) xp_malloc (xp_sizeof(xp_awk_nde_idx_t));
nde = (xp_awk_nde_idx_t*)xp_malloc(xp_sizeof(xp_awk_nde_idx_t));
if (nde == XP_NULL)
{
xp_awk_clrpt (idx);
@ -1692,7 +1683,7 @@ static xp_awk_nde_t* __parse_funcall (xp_awk_t* awk, xp_char_t* name)
}
call = (xp_awk_nde_call_t*)xp_malloc (xp_sizeof(xp_awk_nde_call_t));
call = (xp_awk_nde_call_t*)xp_malloc(xp_sizeof(xp_awk_nde_call_t));
if (call == XP_NULL)
{
if (head != XP_NULL) xp_awk_clrpt (head);
@ -1758,7 +1749,7 @@ static xp_awk_nde_t* __parse_if (xp_awk_t* awk)
}
else else_part = XP_NULL;
nde = (xp_awk_nde_if_t*) xp_malloc (xp_sizeof(xp_awk_nde_if_t));
nde = (xp_awk_nde_if_t*)xp_malloc(xp_sizeof(xp_awk_nde_if_t));
if (nde == XP_NULL)
{
xp_awk_clrpt (else_part);
@ -1806,7 +1797,7 @@ static xp_awk_nde_t* __parse_while (xp_awk_t* awk)
return XP_NULL;
}
nde = (xp_awk_nde_while_t*) xp_malloc (xp_sizeof(xp_awk_nde_while_t));
nde = (xp_awk_nde_while_t*)xp_malloc(xp_sizeof(xp_awk_nde_while_t));
if (nde == XP_NULL)
{
xp_awk_clrpt (body);
@ -1913,7 +1904,7 @@ static xp_awk_nde_t* __parse_for (xp_awk_t* awk)
return XP_NULL;
}
nde = (xp_awk_nde_for_t*) xp_malloc (xp_sizeof(xp_awk_nde_for_t));
nde = (xp_awk_nde_for_t*)xp_malloc(xp_sizeof(xp_awk_nde_for_t));
if (nde == XP_NULL)
{
xp_awk_clrpt (init);
@ -1986,7 +1977,7 @@ static xp_awk_nde_t* __parse_dowhile (xp_awk_t* awk)
return XP_NULL;
}
nde = (xp_awk_nde_while_t*) xp_malloc (xp_sizeof(xp_awk_nde_while_t));
nde = (xp_awk_nde_while_t*)xp_malloc(xp_sizeof(xp_awk_nde_while_t));
if (nde == XP_NULL)
{
xp_awk_clrpt (body);
@ -2006,7 +1997,7 @@ static xp_awk_nde_t* __parse_break (xp_awk_t* awk)
{
xp_awk_nde_break_t* nde;
nde = (xp_awk_nde_break_t*) xp_malloc (xp_sizeof(xp_awk_nde_break_t));
nde = (xp_awk_nde_break_t*)xp_malloc(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;
@ -2018,7 +2009,7 @@ static xp_awk_nde_t* __parse_continue (xp_awk_t* awk)
{
xp_awk_nde_continue_t* nde;
nde = (xp_awk_nde_continue_t*) xp_malloc (xp_sizeof(xp_awk_nde_continue_t));
nde = (xp_awk_nde_continue_t*)xp_malloc(xp_sizeof(xp_awk_nde_continue_t));
if (nde == XP_NULL) PANIC (awk, XP_AWK_ENOMEM);
nde->type = XP_AWK_NDE_CONTINUE;
nde->next = XP_NULL;
@ -2031,7 +2022,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*) xp_malloc (xp_sizeof(xp_awk_nde_return_t));
nde = (xp_awk_nde_return_t*)xp_malloc(xp_sizeof(xp_awk_nde_return_t));
if (nde == XP_NULL) PANIC (awk, XP_AWK_ENOMEM);
nde->type = XP_AWK_NDE_RETURN;
nde->next = XP_NULL;
@ -2051,7 +2042,7 @@ static xp_awk_nde_t* __parse_return (xp_awk_t* awk)
}
}
nde->value = val;
nde->val = val;
return (xp_awk_nde_t*)nde;
}
@ -2060,7 +2051,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*) xp_malloc (xp_sizeof(xp_awk_nde_exit_t));
nde = (xp_awk_nde_exit_t*)xp_malloc(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;
@ -2080,7 +2071,7 @@ static xp_awk_nde_t* __parse_exit (xp_awk_t* awk)
}
}
nde->value = val;
nde->val = val;
return (xp_awk_nde_t*)nde;
}
@ -2088,7 +2079,7 @@ static xp_awk_nde_t* __parse_next (xp_awk_t* awk)
{
xp_awk_nde_t* nde;
nde = (xp_awk_nde_t*) xp_malloc (xp_sizeof(xp_awk_nde_t));
nde = (xp_awk_nde_t*)xp_malloc(xp_sizeof(xp_awk_nde_t));
if (nde == XP_NULL) PANIC (awk, XP_AWK_ENOMEM);
nde->type = XP_AWK_NDE_NEXT;
nde->next = XP_NULL;
@ -2100,7 +2091,7 @@ static xp_awk_nde_t* __parse_nextfile (xp_awk_t* awk)
{
xp_awk_nde_t* nde;
nde = (xp_awk_nde_t*) xp_malloc (xp_sizeof(xp_awk_nde_t));
nde = (xp_awk_nde_t*)xp_malloc(xp_sizeof(xp_awk_nde_t));
if (nde == XP_NULL) PANIC (awk, XP_AWK_ENOMEM);
nde->type = XP_AWK_NDE_NEXTFILE;
nde->next = XP_NULL;
@ -2456,16 +2447,3 @@ static int __classify_ident (xp_awk_t* awk, const xp_char_t* ident)
return TOKEN_IDENT;
}
static xp_long_t __str_to_long (const xp_char_t* name)
{
xp_long_t n = 0;
while (xp_isdigit(*name))
{
n = n * 10 + (*name - XP_CHAR('0'));
name++;
}
return n;
}

View File

@ -1,5 +1,5 @@
/*
* $Id: run.c,v 1.6 2006-03-04 15:54:37 bacon Exp $
* $Id: run.c,v 1.7 2006-03-05 17:07:33 bacon Exp $
*/
#include <xp/awk/awk.h>
@ -8,34 +8,45 @@
#include <xp/bas/assert.h>
#endif
static int __run_block (xp_awk_t* awk, xp_awk_nde_t* nde);
static int __run_block (xp_awk_t* awk, xp_awk_nde_blk_t* nde);
static int __run_statement (xp_awk_t* awk, xp_awk_nde_t* nde);
static xp_awk_val_t* __eval_expression (xp_awk_t* awk, xp_awk_nde_t* nde);
static xp_awk_val_t* __eval_assignment (xp_awk_t* awk, xp_awk_nde_ass_t* nde);
int __printval (xp_awk_pair_t* pair)
{
xp_printf (XP_TEXT("%s = "), (const xp_char_t*)pair->key);
xp_awk_printval ((xp_awk_val_t*)pair->val);
xp_printf (XP_TEXT("\n"));
return 0;
}
int xp_awk_run (xp_awk_t* awk)
{
if (awk->tree.begin != XP_NULL)
{
if (__run_block(awk, awk->tree.begin) == -1) return -1;
xp_assert (awk->tree.begin->type == XP_AWK_NDE_BLK);
if (__run_block(awk, (xp_awk_nde_blk_t*)awk->tree.begin) == -1) return -1;
}
if (awk->tree.end != XP_NULL)
{
if (__run_block(awk, awk->tree.end) == -1) return -1;
xp_assert (awk->tree.end->type == XP_AWK_NDE_BLK);
if (__run_block(awk, (xp_awk_nde_blk_t*)awk->tree.end) == -1) return -1;
}
xp_awk_map_walk (&awk->run.named, __printval);
return 0;
}
static int __run_block (xp_awk_t* awk, xp_awk_nde_t* nde)
static int __run_block (xp_awk_t* awk, xp_awk_nde_blk_t* nde)
{
xp_awk_nde_t* p;
xp_assert (nde->type == XP_AWK_NDE_BLOCK);
xp_assert (nde->type == XP_AWK_NDE_BLK);
p = nde;
p = nde->body;
while (p != XP_NULL)
{
@ -54,8 +65,8 @@ static int __run_statement (xp_awk_t* awk, xp_awk_nde_t* nde)
/* do nothing */
break;
case XP_AWK_NDE_BLOCK:
if (__run_block(awk, nde) == -1) return -1;
case XP_AWK_NDE_BLK:
if (__run_block(awk, (xp_awk_nde_blk_t*)nde) == -1) return -1;
break;
case XP_AWK_NDE_IF:
@ -96,7 +107,8 @@ static xp_awk_val_t* __eval_expression (xp_awk_t* awk, xp_awk_nde_t* nde)
{
xp_awk_val_t* val;
switch (nde->type) {
switch (nde->type)
{
case XP_AWK_NDE_ASS:
val = __eval_assignment(awk,(xp_awk_nde_ass_t*)nde);
break;
@ -106,13 +118,21 @@ static xp_awk_val_t* __eval_expression (xp_awk_t* awk, xp_awk_nde_t* nde)
case XP_AWK_NDE_EXP_UNR:
case XP_AWK_NDE_STR:
val = xp_awk_makestrval(
((xp_awk_nde_str_t*)nde)->buf,
((xp_awk_nde_str_t*)nde)->len);
break;
case XP_AWK_NDE_NUM:
// TODO: int, real...
val = xp_awk_makeintval();
case XP_AWK_NDE_INT:
val = xp_awk_makeintval(((xp_awk_nde_int_t*)nde)->val);
break;
/* TODO:
case XP_AWK_NDE_REAL:
val = xp_awk_makerealval(((xp_awk_nde_real_t*)nde)->val);
break;
*/
case XP_AWK_NDE_ARG:
case XP_AWK_NDE_ARGIDX:
@ -145,55 +165,61 @@ static xp_awk_val_t* __eval_expression (xp_awk_t* awk, xp_awk_nde_t* nde)
static xp_awk_val_t* __eval_assignment (xp_awk_t* awk, xp_awk_nde_ass_t* nde)
{
xp_awk_val_t* v;
xp_awk_nde_var_t* tgt;
if (nde->type == XP_AWK_NDE_NAMED)
tgt = (xp_awk_nde_var_t*)nde->left;
if (tgt->type == XP_AWK_NDE_NAMED)
{
xp_awk_nde_var_t* tgt;
xp_awk_val_t* old, * new;
xp_char_t* name;
tgt = (xp_awk_nde_var_t*)nde->left;
new = __eval_expression (awk, nde->right);
new = __eval_expression(awk, nde->right);
xp_assert (tgt != XP_NULL);
if (new == XP_NULL) return XP_NULL;
old = (xp_awk_val_t*) xp_awk_map_get (&awk->run.named, tgt->id.name);
name = tgt->id.name;
old = (xp_awk_val_t*)xp_awk_map_getval(&awk->run.named, name);
if (old == XP_NULL) {
name = xp_strdup (tgt->id.name);
if (name == XP_NULL) {
xp_awk_freeval(new);
awk->errnum = XP_AWK_ENOMEM;
return XP_NULL;
}
}
if (xp_awk_map_put (
&awk->run.named, tgt->id.name, new) == XP_NULL)
if (xp_awk_map_put(&awk->run.named, name, new) == XP_NULL)
{
xp_free (name);
xp_awk_freeval (new);
awk->errnum = XP_AWK_ENOMEM;
return XP_NULL;
}
else if (old != XP_NULL)
{
/* free the old value that has been assigned to the variable */
xp_awk_freeval (old);
}
v = new;
}
else if (nde->type == XP_AWK_NDE_GLOBAL)
else if (tgt->type == XP_AWK_NDE_GLOBAL)
{
}
else if (nde->type == XP_AWK_NDE_LOCAL)
else if (tgt->type == XP_AWK_NDE_LOCAL)
{
}
else if (nde->type == XP_AWK_NDE_ARG)
else if (tgt->type == XP_AWK_NDE_ARG)
{
}
else if (nde->type == XP_AWK_NDE_NAMEDIDX)
else if (tgt->type == XP_AWK_NDE_NAMEDIDX)
{
}
else if (nde->type == XP_AWK_NDE_GLOBALIDX)
else if (tgt->type == XP_AWK_NDE_GLOBALIDX)
{
}
else if (nde->type == XP_AWK_NDE_LOCALIDX)
else if (tgt->type == XP_AWK_NDE_LOCALIDX)
{
}
else if (nde->type == XP_AWK_NDE_ARGIDX)
else if (tgt->type == XP_AWK_NDE_ARGIDX)
{
}
else

View File

@ -1,5 +1,5 @@
/*
* $Id: sa.c,v 1.8 2006-03-03 11:51:48 bacon Exp $
* $Id: sa.c,v 1.9 2006-03-05 17:07:33 bacon Exp $
*/
#include <xp/awk/awk.h>
@ -19,6 +19,44 @@ xp_char_t* xp_strdup (const xp_char_t* 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_strxncpy (tmp, len + 1, str, len);
return tmp;
}
xp_size_t xp_strxncpy (
xp_char_t* buf, xp_size_t bsz, const xp_char_t* str, xp_size_t len)
{
xp_size_t n;
if (bsz <= 0) return 0;
if ((n = bsz - 1) > len) n = len;
xp_memcpy (buf, str, n * xp_sizeof(xp_char_t));
buf[n] = XP_CHAR('\0');
return n;
}
xp_long_t xp_strtolong (xp_char_t* str)
{
xp_long_t n = 0;
while (xp_isdigit(*str))
{
n = n * 10 + (*str - XP_CHAR('0'));
str++;
}
return n;
}
int xp_printf (const xp_char_t* fmt, ...)
{
int n;

View File

@ -1,5 +1,5 @@
/*
* $Id: sa.h,v 1.12 2006-03-03 11:51:48 bacon Exp $
* $Id: sa.h,v 1.13 2006-03-05 17:07:33 bacon Exp $
*/
#ifndef _XP_AWK_SA_H_
@ -100,6 +100,12 @@ extern "C" {
#endif
xp_char_t* xp_strdup (const xp_char_t* str);
xp_char_t* xp_strxdup (const xp_char_t* str, xp_size_t len);
xp_size_t xp_strxncpy (
xp_char_t* buf, xp_size_t bsz, const xp_char_t* str, xp_size_t len);
xp_long_t xp_strtolong (xp_char_t* str);
int xp_printf (const xp_char_t* fmt, ...);
int xp_vprintf (const xp_char_t* fmt, xp_va_list ap);

View File

@ -1,5 +1,5 @@
/*
* $Id: tree.c,v 1.22 2006-03-04 15:54:37 bacon Exp $
* $Id: tree.c,v 1.23 2006-03-05 17:07:33 bacon Exp $
*/
#include <xp/awk/awk.h>
@ -65,12 +65,17 @@ static int __print_expression (xp_awk_nde_t* nde)
xp_printf (XP_TEXT("unary basic expression\n"));
break;
case XP_AWK_NDE_STR:
xp_printf (XP_TEXT("\"%s\""), ((xp_awk_nde_trm_t*)nde)->value);
case XP_AWK_NDE_INT:
#if defined(vax) || defined(__vax)
xp_printf (XP_TEXT("%ld"), (long)((xp_awk_nde_int_t*)nde)->val);
#else
xp_printf (XP_TEXT("%lld"), (long long)((xp_awk_nde_int_t*)nde)->val);
#endif
break;
case XP_AWK_NDE_NUM:
xp_printf (XP_TEXT("%s"), ((xp_awk_nde_trm_t*)nde)->value);
case XP_AWK_NDE_STR:
// TODO: buf, len
xp_printf (XP_TEXT("\"%s\""), ((xp_awk_nde_str_t*)nde)->buf);
break;
case XP_AWK_NDE_ARG:
@ -153,7 +158,7 @@ static int __print_expression (xp_awk_nde_t* nde)
case XP_AWK_NDE_POS:
xp_printf (XP_TEXT("$"));
__print_expression (((xp_awk_nde_pos_t*)nde)->value);
__print_expression (((xp_awk_nde_pos_t*)nde)->val);
break;
case XP_AWK_NDE_CALL:
@ -198,21 +203,21 @@ static void __print_statements (xp_awk_nde_t* tree, int depth)
xp_printf (XP_TEXT(";\n"));
break;
case XP_AWK_NDE_BLOCK:
case XP_AWK_NDE_BLK:
__print_tabs (depth);
xp_printf (XP_TEXT("{\n"));
if (((xp_awk_nde_block_t*)p)->nlocals > 0) {
if (((xp_awk_nde_blk_t*)p)->nlocals > 0) {
__print_tabs (depth + 1);
xp_printf (XP_TEXT("local "));
for (i = 0; i < ((xp_awk_nde_block_t*)p)->nlocals - 1; i++) {
for (i = 0; i < ((xp_awk_nde_blk_t*)p)->nlocals - 1; i++) {
xp_printf (XP_TEXT("__local%lu, "), (unsigned long)i);
}
xp_printf (XP_TEXT("__local%lu;\n"), (unsigned long)i);
}
__print_statements (((xp_awk_nde_block_t*)p)->body, depth + 1);
__print_statements (((xp_awk_nde_blk_t*)p)->body, depth + 1);
__print_tabs (depth);
xp_printf (XP_TEXT("}\n"));
break;
@ -224,7 +229,7 @@ static void __print_statements (xp_awk_nde_t* tree, int depth)
xp_printf (XP_TEXT(")\n"));
xp_assert (((xp_awk_nde_if_t*)p)->then_part != XP_NULL);
if (((xp_awk_nde_if_t*)p)->then_part->type == XP_AWK_NDE_BLOCK)
if (((xp_awk_nde_if_t*)p)->then_part->type == XP_AWK_NDE_BLK)
__print_statements (((xp_awk_nde_if_t*)p)->then_part, depth);
else
__print_statements (((xp_awk_nde_if_t*)p)->then_part, depth + 1);
@ -233,7 +238,7 @@ static void __print_statements (xp_awk_nde_t* tree, int depth)
{
__print_tabs (depth);
xp_printf (XP_TEXT("else\n"));
if (((xp_awk_nde_if_t*)p)->else_part->type == XP_AWK_NDE_BLOCK)
if (((xp_awk_nde_if_t*)p)->else_part->type == XP_AWK_NDE_BLK)
__print_statements (((xp_awk_nde_if_t*)p)->else_part, depth);
else
__print_statements (((xp_awk_nde_if_t*)p)->else_part, depth + 1);
@ -244,7 +249,7 @@ static void __print_statements (xp_awk_nde_t* tree, int depth)
xp_printf (XP_TEXT("while ("));
__print_expression (((xp_awk_nde_while_t*)p)->test);
xp_printf (XP_TEXT(")\n"));
if (((xp_awk_nde_while_t*)p)->body->type == XP_AWK_NDE_BLOCK)
if (((xp_awk_nde_while_t*)p)->body->type == XP_AWK_NDE_BLK)
{
__print_statements (((xp_awk_nde_while_t*)p)->body, depth);
}
@ -257,7 +262,7 @@ static void __print_statements (xp_awk_nde_t* tree, int depth)
case XP_AWK_NDE_DOWHILE:
__print_tabs (depth);
xp_printf (XP_TEXT("do\n"));
if (((xp_awk_nde_while_t*)p)->body->type == XP_AWK_NDE_BLOCK)
if (((xp_awk_nde_while_t*)p)->body->type == XP_AWK_NDE_BLK)
{
__print_statements (((xp_awk_nde_while_t*)p)->body, depth);
}
@ -291,7 +296,7 @@ static void __print_statements (xp_awk_nde_t* tree, int depth)
}
xp_printf (XP_TEXT(")\n"));
if (((xp_awk_nde_for_t*)p)->body->type == XP_AWK_NDE_BLOCK)
if (((xp_awk_nde_for_t*)p)->body->type == XP_AWK_NDE_BLK)
{
__print_statements (((xp_awk_nde_for_t*)p)->body, depth);
}
@ -312,15 +317,15 @@ static void __print_statements (xp_awk_nde_t* tree, int depth)
case XP_AWK_NDE_RETURN:
__print_tabs (depth);
if (((xp_awk_nde_return_t*)p)->value == XP_NULL)
if (((xp_awk_nde_return_t*)p)->val == XP_NULL)
{
xp_printf (XP_TEXT("return;\n"));
}
else
{
xp_printf (XP_TEXT("return "));
xp_assert (((xp_awk_nde_return_t*)p)->value->next == XP_NULL);
if (__print_expression(((xp_awk_nde_return_t*)p)->value) == 0) {
xp_assert (((xp_awk_nde_return_t*)p)->val->next == XP_NULL);
if (__print_expression(((xp_awk_nde_return_t*)p)->val) == 0) {
xp_printf (XP_TEXT(";\n"));
}
else
@ -334,15 +339,15 @@ static void __print_statements (xp_awk_nde_t* tree, int depth)
case XP_AWK_NDE_EXIT:
__print_tabs (depth);
if (((xp_awk_nde_exit_t*)p)->value == XP_NULL)
if (((xp_awk_nde_exit_t*)p)->val == XP_NULL)
{
xp_printf (XP_TEXT("exit;\n"));
}
else
{
xp_printf (XP_TEXT("exit "));
xp_assert (((xp_awk_nde_exit_t*)p)->value->next == XP_NULL);
if (__print_expression(((xp_awk_nde_exit_t*)p)->value) == 0)
xp_assert (((xp_awk_nde_exit_t*)p)->val->next == XP_NULL);
if (__print_expression(((xp_awk_nde_exit_t*)p)->val) == 0)
{
xp_printf (XP_TEXT(";\n"));
}
@ -400,8 +405,8 @@ void xp_awk_clrpt (xp_awk_nde_t* tree)
xp_free (p);
break;
case XP_AWK_NDE_BLOCK:
xp_awk_clrpt (((xp_awk_nde_block_t*)p)->body);
case XP_AWK_NDE_BLK:
xp_awk_clrpt (((xp_awk_nde_blk_t*)p)->body);
xp_free (p);
break;
@ -445,14 +450,14 @@ void xp_awk_clrpt (xp_awk_nde_t* tree)
break;
case XP_AWK_NDE_RETURN:
if (((xp_awk_nde_return_t*)p)->value != XP_NULL)
xp_awk_clrpt (((xp_awk_nde_return_t*)p)->value);
if (((xp_awk_nde_return_t*)p)->val != XP_NULL)
xp_awk_clrpt (((xp_awk_nde_return_t*)p)->val);
xp_free (p);
break;
case XP_AWK_NDE_EXIT:
if (((xp_awk_nde_exit_t*)p)->value != XP_NULL)
xp_awk_clrpt (((xp_awk_nde_exit_t*)p)->value);
if (((xp_awk_nde_exit_t*)p)->val != XP_NULL)
xp_awk_clrpt (((xp_awk_nde_exit_t*)p)->val);
xp_free (p);
break;
@ -476,9 +481,12 @@ void xp_awk_clrpt (xp_awk_nde_t* tree)
xp_free (p);
break;
case XP_AWK_NDE_INT:
xp_free (p);
break;
case XP_AWK_NDE_STR:
case XP_AWK_NDE_NUM:
xp_free (((xp_awk_nde_trm_t*)p)->value);
xp_free (((xp_awk_nde_str_t*)p)->buf);
xp_free (p);
break;
@ -504,8 +512,8 @@ void xp_awk_clrpt (xp_awk_nde_t* tree)
break;
case XP_AWK_NDE_POS:
xp_assert (((xp_awk_nde_pos_t*)p)->value != XP_NULL);
xp_awk_clrpt (((xp_awk_nde_pos_t*)p)->value);
xp_assert (((xp_awk_nde_pos_t*)p)->val != XP_NULL);
xp_awk_clrpt (((xp_awk_nde_pos_t*)p)->val);
xp_free (p);
break;

View File

@ -1,5 +1,5 @@
/*
* $Id: tree.h,v 1.25 2006-03-04 15:54:37 bacon Exp $
* $Id: tree.h,v 1.26 2006-03-05 17:07:33 bacon Exp $
*/
#ifndef _XP_AWK_TREE_H_
@ -12,13 +12,16 @@
enum
{
XP_AWK_NDE_NULL,
XP_AWK_NDE_BLOCK,
XP_AWK_NDE_BLK,
XP_AWK_NDE_ASS,
XP_AWK_NDE_EXP_BIN,
XP_AWK_NDE_EXP_UNR,
XP_AWK_NDE_INT,
/*TODO: XP_AWK_NDE_REAL,*/
XP_AWK_NDE_STR,
XP_AWK_NDE_NUM,
XP_AWK_NDE_NAMED,
XP_AWK_NDE_NAMEDIDX,
XP_AWK_NDE_GLOBAL,
@ -47,11 +50,12 @@ typedef struct xp_awk_func_t xp_awk_func_t;
typedef struct xp_awk_nde_t xp_awk_nde_t;
typedef struct xp_awk_nde_pos_t xp_awk_nde_pos_t;
typedef struct xp_awk_nde_block_t xp_awk_nde_block_t;
typedef struct xp_awk_nde_blk_t xp_awk_nde_blk_t;
typedef struct xp_awk_nde_ass_t xp_awk_nde_ass_t;
typedef struct xp_awk_nde_exp_t xp_awk_nde_exp_t;
typedef struct xp_awk_nde_trm_t xp_awk_nde_trm_t;
typedef struct xp_awk_nde_pos_t xp_awk_nde_pos_t;
typedef struct xp_awk_nde_int_t xp_awk_nde_int_t;
typedef struct xp_awk_nde_str_t xp_awk_nde_str_t;
typedef struct xp_awk_nde_var_t xp_awk_nde_var_t;
typedef struct xp_awk_nde_idx_t xp_awk_nde_idx_t;
typedef struct xp_awk_nde_pos_t xp_awk_nde_pos_t;
@ -81,14 +85,8 @@ struct xp_awk_nde_t
XP_AWK_NDE_HDR;
};
/* XP_AWK_NDE_POS - positional - $1, $2, $x, etc */
struct xp_awk_nde_pos_t
{
XP_AWK_NDE_HDR;
xp_awk_nde_t* value;
};
struct xp_awk_nde_block_t
/* XP_AWK_NDE_BLK - block statement including top-level blocks */
struct xp_awk_nde_blk_t
{
XP_AWK_NDE_HDR;
xp_size_t nlocals;
@ -112,11 +110,26 @@ struct xp_awk_nde_exp_t
xp_awk_nde_t* right; /* optional for XP_AWK_NDE_UNR */
};
/* XP_AWK_NDE_STR, XP_AWK_NDE_NUM */
struct xp_awk_nde_trm_t
/* XP_AWK_NDE_POS - positional - $1, $2, $x, etc */
struct xp_awk_nde_pos_t
{
XP_AWK_NDE_HDR;
xp_char_t* value;
xp_awk_nde_t* val;
};
/* XP_AWK_NDE_INT */
struct xp_awk_nde_int_t
{
XP_AWK_NDE_HDR;
xp_long_t val;
};
/* XP_AWK_NDE_STR */
struct xp_awk_nde_str_t
{
XP_AWK_NDE_HDR;
xp_char_t* buf;
xp_size_t len;
};
struct xp_awk_nde_var_t
@ -191,14 +204,14 @@ struct xp_awk_nde_continue_t
struct xp_awk_nde_return_t
{
XP_AWK_NDE_HDR;
xp_awk_nde_t* value; /* optional (no return code if XP_NULL) */
xp_awk_nde_t* val; /* optional (no return code if XP_NULL) */
};
/* XP_AWK_NDE_EXIT */
struct xp_awk_nde_exit_t
{
XP_AWK_NDE_HDR;
xp_awk_nde_t* value; /* optional (no exit code if XP_NULL) */
xp_awk_nde_t* val; /* optional (no exit code if XP_NULL) */
};
#ifdef __cplusplus

View File

@ -1,5 +1,5 @@
/*
* $Id: val.c,v 1.1 2006-03-04 15:54:37 bacon Exp $
* $Id: val.c,v 1.2 2006-03-05 17:07:33 bacon Exp $
*/
#include <xp/awk/awk.h>
@ -8,12 +8,46 @@ xp_awk_val_t* xp_awk_makeintval (xp_long_t v)
{
xp_awk_val_int_t* val;
val = xp_malloc (xp_sizeof(xp_awk_val_int_t));
val = (xp_awk_val_int_t*) xp_malloc (xp_sizeof(xp_awk_val_int_t));
if (val == XP_NULL) return XP_NULL;
val->type = XP_AWK_VAL_INT;
val->val = v;
return (xp_awk_val_t*)val;
}
xp_awk_val_t* xp_awk_makerealval (xp_real_t v)
{
xp_awk_val_real_t* val;
val = (xp_awk_val_real_t*) xp_malloc (xp_sizeof(xp_awk_val_real_t));
if (val == XP_NULL) return XP_NULL;
val->type = XP_AWK_VAL_REAL;
val->val = v;
return (xp_awk_val_t*)val;
}
xp_awk_val_t* xp_awk_makestrval (const xp_char_t* str, xp_size_t len)
{
xp_awk_val_str_t* val;
val = (xp_awk_val_str_t*) xp_malloc (xp_sizeof(xp_awk_val_str_t));
if (val == XP_NULL) return XP_NULL;
val->type = XP_AWK_VAL_STR;
val->len = len;
val->buf = xp_strxdup (str, len);
if (val->buf == XP_NULL) {
xp_free (val);
return XP_NULL;
}
return (xp_awk_val_t*)val;
}
void xp_awk_freeval (xp_awk_val_t* val)
{
switch (val->type)
@ -46,6 +80,5 @@ void xp_awk_printval (xp_awk_val_t* val)
default:
xp_printf (XP_TEXT("**** INTERNAL ERROR - UNKNOWN VALUE TYPE ****\n"));
break;
}
}

View File

@ -1,5 +1,5 @@
/*
* $Id: val.h,v 1.2 2006-03-04 15:54:37 bacon Exp $
* $Id: val.h,v 1.3 2006-03-05 17:07:33 bacon Exp $
*/
#ifndef _XP_AWK_VAL_H_
@ -55,6 +55,9 @@ struct xp_awk_val_str_t
extern "C" {
#endif
xp_awk_val_t* xp_awk_makeintval (xp_long_t v);
xp_awk_val_t* xp_awk_makestrval (const xp_char_t* str, xp_size_t len);
void xp_awk_freeval (xp_awk_val_t* val);
void xp_awk_printval (xp_awk_val_t* val);

View File

@ -79,6 +79,7 @@ int xp_main (int argc, xp_char_t* argv[])
}
awk.opt.parse = XP_AWK_EXPLICIT | XP_AWK_UNIQUE | XP_AWK_SHADING | XP_AWK_IMPLICIT;
if (xp_awk_parse(&awk) == -1) {
xp_printf (
XP_TEXT("error: cannot parse program - [%d] %s\n"),
@ -87,6 +88,13 @@ awk.opt.parse = XP_AWK_EXPLICIT | XP_AWK_UNIQUE | XP_AWK_SHADING | XP_AWK_IMPLIC
return -1;
}
if (xp_awk_run(&awk) == -1) {
xp_printf (
XP_TEXT("error: cannot run program - [%d] %s\n"),
xp_awk_geterrnum(&awk), xp_awk_geterrstr(&awk));
xp_awk_close (&awk);
}
xp_awk_close (&awk);
#ifdef __linux