*** empty log message ***

This commit is contained in:
hyung-hwan 2006-07-06 13:57:32 +00:00
parent b9f2687e1d
commit d859d98608
8 changed files with 139 additions and 48 deletions

View File

@ -1,5 +1,5 @@
/*
* $Id: awk_i.h,v 1.26 2006-07-05 16:20:23 bacon Exp $
* $Id: awk_i.h,v 1.27 2006-07-06 13:57:31 bacon Exp $
*/
#ifndef _XP_AWK_AWKI_H_
@ -140,7 +140,6 @@ struct xp_awk_chain_t
xp_awk_chain_t* next;
};
struct xp_awk_run_t
{
xp_awk_map_t named;

View File

@ -1,4 +1,4 @@
SRCS = awk.c err.c tree.c tab.c map.c parse.c run.c sa.c val.c misc.c
SRCS = awk.c err.c tree.c tab.c map.c parse.c run.c sa.c val.c func.c misc.c extio.c
OBJS = $(SRCS:.c=.obj)
OUT = xpawk.lib

View File

@ -1,5 +1,5 @@
/*
* $Id: run.c,v 1.123 2006-07-05 16:20:23 bacon Exp $
* $Id: run.c,v 1.124 2006-07-06 13:57:31 bacon Exp $
*/
#include <xp/awk/awk_i.h>
@ -72,9 +72,13 @@ static xp_awk_val_t* __eval_group (xp_awk_run_t* run, xp_awk_nde_t* nde);
static xp_awk_val_t* __eval_assignment (
xp_awk_run_t* run, xp_awk_nde_t* nde);
static xp_awk_val_t* __do_assignment (
xp_awk_run_t* run, xp_awk_nde_t* var, xp_awk_val_t* val);
static xp_awk_val_t* __do_assignment_scalar (
xp_awk_run_t* run, xp_awk_nde_var_t* var, xp_awk_val_t* val);
static xp_awk_val_t* __do_assignment_map (
xp_awk_run_t* run, xp_awk_nde_var_t* var, xp_awk_val_t* val);
static xp_awk_val_t* __do_assignment_pos (
xp_awk_run_t* run, xp_awk_nde_pos_t* pos, xp_awk_val_t* val);
static xp_awk_val_t* __eval_binary (
xp_awk_run_t* run, xp_awk_nde_t* nde);
@ -969,7 +973,7 @@ static int __run_for (xp_awk_run_t* run, xp_awk_nde_for_t* nde)
struct __foreach_walker_t
{
xp_awk_run_t* run;
xp_awk_nde_var_t* var;
xp_awk_nde_t* var;
xp_awk_nde_t* body;
};
@ -1026,7 +1030,7 @@ static int __run_foreach (xp_awk_run_t* run, xp_awk_nde_foreach_t* nde)
map = ((xp_awk_val_map_t*)rv)->map;
walker.run = run;
walker.var = (xp_awk_nde_var_t*)test->left;
walker.var = test->left;
walker.body = nde->body;
n = xp_awk_map_walk (map, __walk_foreach, &walker);
@ -1495,22 +1499,71 @@ static xp_awk_val_t* __eval_assignment (xp_awk_run_t* run, xp_awk_nde_t* nde)
xp_awk_refupval (val);
}
res = __do_assignment (run, (xp_awk_nde_var_t*)ass->left, val);
res = __do_assignment (run, ass->left, val);
xp_awk_refdownval (run, val);
return res;
}
static xp_awk_val_t* __do_assignment (
xp_awk_run_t* run, xp_awk_nde_var_t* var, xp_awk_val_t* val)
xp_awk_run_t* run, xp_awk_nde_t* var, xp_awk_val_t* val)
{
if (val->type == XP_AWK_VAL_MAP)
{
/* a map cannot be assigned to a variable */
PANIC (run, XP_AWK_ENOTASSIGNABLE);
}
if (var->type == XP_AWK_NDE_NAMED ||
var->type == XP_AWK_NDE_GLOBAL ||
var->type == XP_AWK_NDE_LOCAL ||
var->type == XP_AWK_NDE_ARG)
{
if (__do_assignment_scalar (
run, (xp_awk_nde_var_t*)var, val) == XP_NULL)
{
return XP_NULL;
}
}
else if (var->type == XP_AWK_NDE_NAMEDIDX ||
var->type == XP_AWK_NDE_GLOBALIDX ||
var->type == XP_AWK_NDE_LOCALIDX ||
var->type == XP_AWK_NDE_ARGIDX)
{
if (__do_assignment_map (
run, (xp_awk_nde_var_t*)var, val) == XP_NULL)
{
return XP_NULL;
}
}
else if (var->type == XP_AWK_NDE_POS)
{
if (__do_assignment_pos (
run, (xp_awk_nde_pos_t*)var, val) == XP_NULL)
{
return XP_NULL;
}
}
else
{
xp_assert (!"should never happen - invalid variable type");
PANIC (run, XP_AWK_EINTERNAL);
}
return val;
}
static xp_awk_val_t* __do_assignment_scalar (
xp_awk_run_t* run, xp_awk_nde_var_t* var, xp_awk_val_t* val)
{
xp_assert (
(var->type == XP_AWK_NDE_NAMED ||
var->type == XP_AWK_NDE_GLOBAL ||
var->type == XP_AWK_NDE_LOCAL ||
var->type == XP_AWK_NDE_ARG) && var->idx == XP_NULL);
xp_assert (val->type != XP_AWK_VAL_MAP);
if (var->type == XP_AWK_NDE_NAMED)
{
xp_awk_pair_t* pair;
@ -1559,7 +1612,7 @@ static xp_awk_val_t* __do_assignment (
STACK_LOCAL(run,var->id.idxa) = val;
xp_awk_refupval (val);
}
else if (var->type == XP_AWK_NDE_ARG)
else /* if (var->type == XP_AWK_NDE_ARG) */
{
xp_awk_val_t* old = STACK_ARG(run,var->id.idxa);
if (old->type == XP_AWK_VAL_MAP)
@ -1573,25 +1626,6 @@ static xp_awk_val_t* __do_assignment (
STACK_ARG(run,var->id.idxa) = val;
xp_awk_refupval (val);
}
else if (var->type == XP_AWK_NDE_NAMEDIDX ||
var->type == XP_AWK_NDE_GLOBALIDX ||
var->type == XP_AWK_NDE_LOCALIDX ||
var->type == XP_AWK_NDE_ARGIDX)
{
if (__do_assignment_map(run,var,val) == XP_NULL)
return XP_NULL;
}
else if (var->type == XP_AWK_NDE_POS)
{
/* TODO: */
xp_printf (XP_T("XP_AWK_NDE_POS not implemented\n"));
PANIC (run, XP_AWK_EINTERNAL);
}
else
{
xp_assert (!"should never happen - invalid variable type");
PANIC (run, XP_AWK_EINTERNAL);
}
return val;
}
@ -1608,6 +1642,7 @@ static xp_awk_val_t* __do_assignment_map (
var->type == XP_AWK_NDE_GLOBALIDX ||
var->type == XP_AWK_NDE_LOCALIDX ||
var->type == XP_AWK_NDE_ARGIDX) && var->idx != XP_NULL);
xp_assert (val->type != XP_AWK_VAL_MAP);
if (var->type == XP_AWK_NDE_NAMEDIDX)
{
@ -1660,7 +1695,7 @@ static xp_awk_val_t* __do_assignment_map (
xp_awk_refdownval (run, (xp_awk_val_t*)map);
STACK_LOCAL(run,var->id.idxa) = tmp;
}
else
else /* if (var->type == XP_AWK_NDE_ARGIDX) */
{
xp_awk_refdownval (run, (xp_awk_val_t*)map);
STACK_ARG(run,var->id.idxa) = tmp;
@ -1692,6 +1727,43 @@ xp_printf (XP_T("**** index str=>%s, map->ref=%d, map->type=%d\n"), str, map->re
return val;
}
static xp_awk_val_t* __do_assignment_pos (
xp_awk_run_t* run, xp_awk_nde_pos_t* pos, xp_awk_val_t* val)
{
xp_awk_val_t* v;
xp_long_t lv;
xp_real_t rv;
int n, errnum;
v = __eval_expression (run, pos->val);
if (v == XP_NULL) return XP_NULL;
xp_awk_refupval (v);
n = __val_to_num (v, &lv, &rv);
xp_awk_refdownval (run, v);
if (n == -1) PANIC (run, XP_AWK_EPOSIDX);
if (n == 1) lv = (xp_long_t)rv;
if (lv == 0)
{
if (xp_awk_valtostr (
val, &errnum, &run->inrec.line) == XP_NULL)
{
PANIC (run, errnum);
}
if (__split_record (run) == -1) return XP_NULL;
}
else
{
xp_printf (XP_T("$X assignemtn NOT IMPLEMENTED\n"));
}
//xp_awk_refupval (val);
return val;
}
static xp_awk_val_t* __eval_binary (xp_awk_run_t* run, xp_awk_nde_t* nde)
{
static binop_func_t __binop_func[] =
@ -2797,7 +2869,7 @@ static xp_awk_val_t* __eval_incpre (xp_awk_run_t* run, xp_awk_nde_t* nde)
PANIC (run, XP_AWK_EINTERNAL);
}
if (__do_assignment(run, (xp_awk_nde_var_t*)exp->left, res) == XP_NULL)
if (__do_assignment (run, exp->left, res) == XP_NULL)
{
xp_awk_refdownval (run, left);
return XP_NULL;
@ -2911,7 +2983,7 @@ static xp_awk_val_t* __eval_incpst (xp_awk_run_t* run, xp_awk_nde_t* nde)
PANIC (run, XP_AWK_EINTERNAL);
}
if (__do_assignment(run, (xp_awk_nde_var_t*)exp->left, res2) == XP_NULL)
if (__do_assignment (run, exp->left, res2) == XP_NULL)
{
xp_awk_refdownval (run, left);
return XP_NULL;
@ -3424,8 +3496,7 @@ static xp_awk_val_t* __eval_getline (xp_awk_run_t* run, xp_awk_nde_t* nde)
if (v == XP_NULL) PANIC (run, XP_AWK_ENOMEM);
xp_awk_refupval (v);
if (__do_assignment(run,
(xp_awk_nde_var_t*)p->var, v) == XP_NULL)
if (__do_assignment(run, p->var, v) == XP_NULL)
{
xp_awk_refdownval (run, v);
return XP_NULL;
@ -3546,7 +3617,8 @@ static int __split_record (xp_awk_run_t* run)
nflds = 0;
while (p != XP_NULL)
{
p = xp_strxtok (p, len, XP_T(" \t"), &tok, &tok_len);
//p = xp_strxtok (p, len, XP_T(" \t"), &tok, &tok_len);
p = xp_strtok (p, XP_T(" \t"), &tok, &tok_len);
nflds++;
len = len - tok_len;
}
@ -3561,7 +3633,9 @@ static int __split_record (xp_awk_run_t* run)
while (p != XP_NULL)
{
p = xp_strxtok (p, len, XP_T(" \t"), &tok, &tok_len);
// TODO: fix the problem in in xp_strxtok...
//p = xp_strxtok (p, len, XP_T(" \t"), &tok, &tok_len);
p = xp_strtok (p, XP_T(" \t"), &tok, &tok_len);
run->inrec.flds[run->inrec.nflds].ptr = tok;
run->inrec.flds[run->inrec.nflds].len = tok_len;

View File

@ -1,5 +1,5 @@
/*
* $Id: sa.c,v 1.24 2006-07-05 16:20:23 bacon Exp $
* $Id: sa.c,v 1.25 2006-07-06 13:57:31 bacon Exp $
*/
#include <xp/awk/awk_i.h>
@ -295,7 +295,7 @@ xp_str_t* xp_str_open (xp_str_t* str, xp_size_t capa)
{
if (str == XP_NULL)
{
str = (xp_str_t*)xp_malloc (sizeof(xp_str_t));
str = (xp_str_t*) xp_malloc (sizeof(xp_str_t));
if (str == XP_NULL) return XP_NULL;
str->__dynamic = xp_true;
}

View File

@ -1,5 +1,5 @@
/*
* $Id: val.c,v 1.35 2006-07-01 16:07:06 bacon Exp $
* $Id: val.c,v 1.36 2006-07-06 13:57:31 bacon Exp $
*/
#include <xp/awk/awk_i.h>
@ -100,6 +100,7 @@ xp_awk_val_t* xp_awk_makestrval (const xp_char_t* str, xp_size_t len)
return XP_NULL;
}
xp_printf (XP_T("makestrval => %p\n"), val);
return (xp_awk_val_t*)val;
}
@ -190,6 +191,7 @@ void xp_awk_freeval (xp_awk_run_t* run, xp_awk_val_t* val, xp_bool_t cache)
/*xp_printf (XP_T("freeing [cache=%d] ... "), cache);
xp_awk_printval (val);
xp_printf (XP_T("\n"));*/
xp_printf (XP_TEXT("freeing VAL[%p]\n"), val);
switch (val->type)
{
case XP_AWK_VAL_NIL:
@ -217,6 +219,9 @@ xp_printf (XP_T("\n"));*/
return;
case XP_AWK_VAL_STR:
xp_printf (XP_TEXT("freeing STR[%p/%s]\n"),
((xp_awk_val_str_t*)val)->buf,
((xp_awk_val_str_t*)val)->buf);
xp_free (((xp_awk_val_str_t*)val)->buf);
xp_free (val);
return;
@ -262,11 +267,9 @@ xp_printf (XP_T("\n"));
val->ref--;
if (val->ref <= 0)
{
/*
xp_printf (XP_T("**FREEING "));
xp_printf (XP_T("**FREEING ["));
xp_awk_printval (val);
xp_printf (XP_T("\n"));
*/
xp_printf (XP_T("]\n"));
xp_awk_freeval(run, val, xp_true);
}
}
@ -344,6 +347,7 @@ xp_char_t* xp_awk_valtostr (xp_awk_val_t* v, int* errnum, xp_str_t* buf)
}
else
{
//xp_str_clear (buf);
if (xp_str_cat (buf, XP_T("0")) == (xp_size_t)-1)
{
*errnum = XP_AWK_ENOMEM;
@ -371,6 +375,8 @@ xp_char_t* xp_awk_valtostr (xp_awk_val_t* v, int* errnum, xp_str_t* buf)
}
else
{
//xp_str_clear (buf);
/* get the current end of the buffer */
tmp = XP_STR_BUF(buf) + XP_STR_LEN(buf);
@ -412,6 +418,7 @@ xp_char_t* xp_awk_valtostr (xp_awk_val_t* v, int* errnum, xp_str_t* buf)
}
else
{
//xp_str_clear (buf);
tmp = XP_STR_BUF(buf) + XP_STR_LEN(buf);
if (xp_str_ncat (buf,
@ -428,6 +435,7 @@ xp_char_t* xp_awk_valtostr (xp_awk_val_t* v, int* errnum, xp_str_t* buf)
/* TODO: process more value types */
xp_printf (XP_TEXT("*** ERROR: WRONG VALUE TYPE [%d] in xp_awk_valtostr v=> %p***\n"), v->type, v);
*errnum = XP_AWK_EVALTYPE;
return XP_NULL;
}

View File

@ -1,5 +1,5 @@
/*
* $Id: awk.c,v 1.51 2006-07-02 12:16:24 bacon Exp $
* $Id: awk.c,v 1.52 2006-07-06 13:57:31 bacon Exp $
*/
#include <xp/awk/awk.h>
@ -392,7 +392,7 @@ xp_printf (XP_TEXT("closing [%s] of type %d (console)\n"), epa->name, epa->type
/* TODO: how to return error or 0 */
fputs_t (data, /*size,*/ (FILE*)epa->handle);
/*fputs_t (data, stdout);*/
MessageBox (NULL, data, data, MB_OK);
/*MessageBox (NULL, data, data, MB_OK);*/
return size;
}

View File

@ -1,7 +1,7 @@
CC = bcc32
CFLAGS = -I..\..\.. -D__STAND_ALONE
LDFLAGS = -L..\..\..\xp\bas -L..\..\..\xp\awk
LIBS = import32.lib cw32mt.lib xpbas.lib xpawk.lib
LIBS = import32.lib cw32mt.lib xpawk.lib
STARTUP = c0x32w.obj
all: awk

View File

@ -18,6 +18,16 @@ END
}
*/
{
$3 = "10";
print $0, $2, $5;
//$3 = "10";
//print $0, $2, $5;
$0 = "wow this is just a test";
print "step 1--------------------";
//print $0;
a = $6;
print "step 2--------------------";
print a;
/*
print $6;
*/
print "step 3--------------------";
}