From d1020db18248d04de9cdca4528549ee5a7ce5757 Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Wed, 15 Mar 2006 15:34:59 +0000 Subject: [PATCH] *** empty log message *** --- ase/awk/Makefile.lcc | 4 ++-- ase/awk/run.c | 24 +++++++++++++++++++++++- ase/awk/tree.c | 10 ++++++---- ase/awk/val.c | 32 +++++++++++++++++++++++++++----- ase/awk/val.h | 3 ++- ase/test/awk/Makefile.lcc | 6 ++---- ase/test/awk/awk.c | 2 +- 7 files changed, 63 insertions(+), 18 deletions(-) diff --git a/ase/awk/Makefile.lcc b/ase/awk/Makefile.lcc index d0c834d8..1752593d 100644 --- a/ase/awk/Makefile.lcc +++ b/ase/awk/Makefile.lcc @@ -1,5 +1,5 @@ -SRCS = awk.c tree.c tab.c map.c parse.c run.c sa.c -OBJS = awk.obj tree.obj tab.obj map.obj parse.obj run.obj sa.obj +SRCS = awk.c err.c tree.c tab.c map.c parse.c run.c sa.c val.c +OBJS = awk.obj err.obj tree.obj tab.obj map.obj parse.obj run.obj sa.obj val.obj OUT = xpawk.lib CC = lcc diff --git a/ase/awk/run.c b/ase/awk/run.c index 16bfb957..a02387ab 100644 --- a/ase/awk/run.c +++ b/ase/awk/run.c @@ -1,5 +1,5 @@ /* - * $Id: run.c,v 1.11 2006-03-14 16:40:00 bacon Exp $ + * $Id: run.c,v 1.12 2006-03-15 15:34:59 bacon Exp $ */ #include @@ -13,6 +13,7 @@ static int __activate_block (xp_awk_t* awk, xp_awk_nde_blk_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 int __run_if_statement (xp_awk_t* awk, xp_awk_nde_if_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); @@ -86,7 +87,9 @@ static int __run_statement (xp_awk_t* awk, xp_awk_nde_t* nde) break; case XP_AWK_NDE_IF: + if (__run_if_statement(awk,(xp_awk_nde_if_t*)nde) == -1) return -1; break; + case XP_AWK_NDE_WHILE: break; case XP_AWK_NDE_DOWHILE: @@ -119,6 +122,25 @@ static int __run_statement (xp_awk_t* awk, xp_awk_nde_t* nde) return 0; } +static int __run_if_statement (xp_awk_t* awk, xp_awk_nde_if_t* nde) +{ + xp_awk_val_t* test; + int n; + + test = __eval_expression (awk, nde->test); + if (xp_awk_isvaltrue(test)) + { + n = __run_statement (awk, nde->then_part); + } + else if (nde->else_part != XP_NULL) + { + n = __run_statement (awk, nde->else_part); + } + +//TODO: how should i destroy test? + return n; +} + static xp_awk_val_t* __eval_expression (xp_awk_t* awk, xp_awk_nde_t* nde) { xp_awk_val_t* val; diff --git a/ase/awk/tree.c b/ase/awk/tree.c index 7c100633..ce093c1c 100644 --- a/ase/awk/tree.c +++ b/ase/awk/tree.c @@ -1,5 +1,5 @@ /* - * $Id: tree.c,v 1.24 2006-03-14 16:40:00 bacon Exp $ + * $Id: tree.c,v 1.25 2006-03-15 15:34:59 bacon Exp $ */ #include @@ -66,10 +66,12 @@ static int __print_expression (xp_awk_nde_t* nde) break; case XP_AWK_NDE_INT: -#if defined(vax) || defined(__vax) - xp_printf (XP_TEXT("%ld"), (long)((xp_awk_nde_int_t*)nde)->val); -#elif defined(_WIN32) +#if defined(__LCC__) + xp_printf (XP_TEXT("%lld"), (long long)((xp_awk_nde_int_t*)nde)->val); +#elif defined(__BORLANDC__) || defined(_MSC_VER) xp_printf (XP_TEXT("%I64d"), (__int64)((xp_awk_nde_int_t*)nde)->val); +#elif 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 diff --git a/ase/awk/val.c b/ase/awk/val.c index 1f499075..ffbb4e7f 100644 --- a/ase/awk/val.c +++ b/ase/awk/val.c @@ -1,5 +1,5 @@ /* - * $Id: val.c,v 1.5 2006-03-14 16:40:00 bacon Exp $ + * $Id: val.c,v 1.6 2006-03-15 15:34:59 bacon Exp $ */ #include @@ -88,6 +88,25 @@ xp_awk_val_t* xp_awk_cloneval (xp_awk_val_t* val) return XP_NULL; } +xp_bool_t xp_awk_isvaltrue (xp_awk_val_t* val) +{ + if (val == XP_NULL) return xp_false; + + switch (val->type) + { + case XP_AWK_VAL_NIL: + return xp_false; + case XP_AWK_VAL_INT: + return (((xp_awk_val_int_t*)val)->val == 0)? xp_false: xp_true; + case XP_AWK_VAL_REAL: + return (((xp_awk_val_real_t*)val)->val == 0.0)? xp_false: xp_true; + case XP_AWK_VAL_STR: + /* TODO: decide what to do */ + return (((xp_awk_val_str_t*)val)->len == 0)? xp_false: xp_true; + } + +} + void xp_awk_printval (xp_awk_val_t* val) { // TODO: better value printing...................... @@ -98,12 +117,15 @@ void xp_awk_printval (xp_awk_val_t* val) break; case XP_AWK_VAL_INT: -#if defined(vax) || defined(__vax) - xp_printf (XP_TEXT("%ld"), - (long)((xp_awk_val_int_t*)val)->val); -#elif defined(_WIN32) +#if defined(__LCC__) + xp_printf (XP_TEXT("%lld"), + (long long)((xp_awk_val_int_t*)val)->val); +#elif defined(__BORLANDC__) || defined(_MSC_VER) xp_printf (XP_TEXT("%I64d"), (__int64)((xp_awk_nde_int_t*)val)->val); +#elif defined(vax) || defined(__vax) + xp_printf (XP_TEXT("%ld"), + (long)((xp_awk_val_int_t*)val)->val); #else xp_printf (XP_TEXT("%lld"), (long long)((xp_awk_val_int_t*)val)->val); diff --git a/ase/awk/val.h b/ase/awk/val.h index 83e6a60e..c9396db0 100644 --- a/ase/awk/val.h +++ b/ase/awk/val.h @@ -1,5 +1,5 @@ /* - * $Id: val.h,v 1.4 2006-03-07 15:55:14 bacon Exp $ + * $Id: val.h,v 1.5 2006-03-15 15:34:59 bacon Exp $ */ #ifndef _XP_AWK_VAL_H_ @@ -70,6 +70,7 @@ 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); xp_awk_val_t* xp_awk_cloneval (xp_awk_val_t* val); +xp_bool_t xp_awk_isvaltrue (xp_awk_val_t* val); void xp_awk_printval (xp_awk_val_t* val); #ifdef __cplusplus diff --git a/ase/test/awk/Makefile.lcc b/ase/test/awk/Makefile.lcc index e6c1829c..fd07d18c 100644 --- a/ase/test/awk/Makefile.lcc +++ b/ase/test/awk/Makefile.lcc @@ -1,10 +1,8 @@ CC = lcc CFLAGS = -I../../.. -A -ansic -libcdll -D__STAND_ALONE -#LDFLAGS = -L../../../xp/bas -L../../../xp/awk -#LIBS = -lxpawk -lxpbas #LDFLAGS = -subsystem console -dynamic -s -LDFLAGS = -subsystem console -s -LIBS = ../../../xp/awk/xpawk.lib +LDFLAGS = -subsystem console -s -L../../../xp/awk +LIBS = xpawk.lib all: awk diff --git a/ase/test/awk/awk.c b/ase/test/awk/awk.c index 00a4f84d..5f58ffb4 100644 --- a/ase/test/awk/awk.c +++ b/ase/test/awk/awk.c @@ -12,7 +12,7 @@ static xp_ssize_t process_source (int cmd, void* arg, xp_char_t* data, xp_size_t return 0; case XP_AWK_IO_DATA: - if (size < 0) return -1; + if (size <= 0) return -1; c = fgetwc (stdin); if (c == XP_CHAR_EOF) return 0; *data = c;