*** empty log message ***

This commit is contained in:
hyung-hwan 2006-03-15 15:34:59 +00:00
parent 87f38b76bc
commit d1020db182
7 changed files with 63 additions and 18 deletions

View File

@ -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

View File

@ -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 <xp/awk/awk.h>
@ -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;

View File

@ -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 <xp/awk/awk.h>
@ -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

View File

@ -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 <xp/awk/awk.h>
@ -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);

View File

@ -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

View File

@ -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

View File

@ -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;