*** empty log message ***

This commit is contained in:
hyung-hwan 2006-04-16 04:31:38 +00:00
parent eb121cd71c
commit dd49dc9e1f
24 changed files with 390 additions and 118 deletions

View File

@ -1,10 +1,10 @@
/* /*
* $Id: awk.c,v 1.40 2006-04-14 10:56:42 bacon Exp $ * $Id: awk.c,v 1.41 2006-04-16 04:31:38 bacon Exp $
*/ */
#include <xp/awk/awk_i.h> #include <xp/awk/awk_i.h>
#ifndef __STAND_ALONE #ifndef XP_AWK_STAND_ALONE
#include <xp/bas/memory.h> #include <xp/bas/memory.h>
#include <xp/bas/assert.h> #include <xp/bas/assert.h>
#endif #endif

View File

@ -43,7 +43,7 @@ RSC=rc.exe
# PROP Ignore_Export_Lib 0 # PROP Ignore_Export_Lib 0
# PROP Target_Dir "" # PROP Target_Dir ""
# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "AWK_EXPORTS" /Yu"stdafx.h" /FD /c # ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "AWK_EXPORTS" /Yu"stdafx.h" /FD /c
# ADD CPP /nologo /MT /W3 /GX /O2 /I "..\.." /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /D "_UNICODE" /D "_USRDLL" /D "__STAND_ALONE" /FD /c # ADD CPP /nologo /MT /W3 /GX /O2 /I "..\.." /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /D "_UNICODE" /D "_USRDLL" /D "XP_AWK_STAND_ALONE" /FD /c
# SUBTRACT CPP /YX /Yc /Yu # SUBTRACT CPP /YX /Yc /Yu
# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32 # ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32 # ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
@ -71,7 +71,7 @@ LINK32=link.exe
# PROP Ignore_Export_Lib 0 # PROP Ignore_Export_Lib 0
# PROP Target_Dir "" # PROP Target_Dir ""
# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "AWK_EXPORTS" /Yu"stdafx.h" /FD /GZ /c # ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "AWK_EXPORTS" /Yu"stdafx.h" /FD /GZ /c
# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "..\.." /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /D "_UNICODE" /D "_USRDLL" /D "__STAND_ALONE" /FD /GZ /c # ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "..\.." /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /D "_UNICODE" /D "_USRDLL" /D "XP_AWK_STAND_ALONE" /FD /GZ /c
# SUBTRACT CPP /YX /Yc /Yu # SUBTRACT CPP /YX /Yc /Yu
# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32 # ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32 # ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32

View File

@ -1,5 +1,5 @@
/* /*
* $Id: awk.h,v 1.48 2006-04-14 10:56:42 bacon Exp $ * $Id: awk.h,v 1.49 2006-04-16 04:31:38 bacon Exp $
*/ */
#ifndef _XP_AWK_AWK_H_ #ifndef _XP_AWK_AWK_H_
@ -106,7 +106,8 @@ int xp_awk_parse (xp_awk_t* awk);
int xp_awk_run (xp_awk_t* awk); int xp_awk_run (xp_awk_t* awk);
/* utility functions exported by awk.h */ /* utility functions exported by awk.h */
xp_long_t xp_awk_strtolong (const xp_char_t* str, int base); 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); xp_real_t xp_awk_strtoreal (const xp_char_t* str);
#ifdef __cplusplus #ifdef __cplusplus

View File

@ -1,5 +1,5 @@
/* /*
* $Id: awk_i.h,v 1.3 2006-04-14 10:56:42 bacon Exp $ * $Id: awk_i.h,v 1.4 2006-04-16 04:31:38 bacon Exp $
*/ */
#ifndef _XP_AWK_AWKI_H_ #ifndef _XP_AWK_AWKI_H_
@ -12,7 +12,7 @@
#include <xp/awk/val.h> #include <xp/awk/val.h>
#include <xp/awk/run.h> #include <xp/awk/run.h>
#ifdef __STAND_ALONE #ifdef XP_AWK_STAND_ALONE
#include <xp/awk/sa.h> #include <xp/awk/sa.h>
#else #else
#include <xp/bas/str.h> #include <xp/bas/str.h>

View File

@ -17,7 +17,7 @@ $ goto compile_loop
$ $
$ compile_file: $ compile_file:
$ write sys$output "Compiling ''name'.c..." $ write sys$output "Compiling ''name'.c..."
$ cc/define=__STAND_ALONE 'name' $ cc/define=XP_AWK_STAND_ALONE 'name'
$ return $ return
$ $
$ archive: $ archive:

View File

@ -3,7 +3,7 @@ OBJS = $(SRCS:.c=.obj)
OUT = xpawk.lib OUT = xpawk.lib
CC = bcc32 CC = bcc32
CFLAGS = -O2 -WM -w -w-inl -w-sig -w-spa -w-hid -RT- -I../.. -D__STAND_ALONE CFLAGS = -O2 -WM -w -w-inl -w-sig -w-spa -w-hid -RT- -I../.. -DXP_AWK_STAND_ALONE
all: $(OBJS) all: $(OBJS)
tlib $(OUT) @&&! tlib $(OUT) @&&!

View File

@ -4,7 +4,7 @@ OUT = xpawk
CC = cl CC = cl
#CFLAGS = /nologo /MT /W3 /GR- /D_WIN32_WINNT=0x0400 -I../.. #CFLAGS = /nologo /MT /W3 /GR- /D_WIN32_WINNT=0x0400 -I../..
CFLAGS = /nologo /O2 /MT /W3 /GR- /D_WIN32_WINNT=0x0400 -I../.. -D__STAND_ALONE -DXP_CHAR_IS_WCHAR CFLAGS = /nologo /O2 /MT /W3 /GR- /D_WIN32_WINNT=0x0400 -I../.. -DXP_AWK_STAND_ALONE -DXP_CHAR_IS_WCHAR
all: lib all: lib

View File

@ -3,7 +3,7 @@ OBJS = awk.obj err.obj tree.obj tab.obj map.obj parse.obj run.obj sa.obj val.obj
OUT = xpawk.lib OUT = xpawk.lib
CC = lcc CC = lcc
CFLAGS = -I../.. -A -ansic -libcdll -D__STAND_ALONE CFLAGS = -I../.. -A -ansic -libcdll -DXP_AWK_STAND_ALONE
LDFLAGS = LDFLAGS =
LIBS = LIBS =

View File

@ -3,7 +3,7 @@ OBJS = $(SRCS:.c=.o)
OUT = libxpawk.a OUT = libxpawk.a
CC = cc CC = cc
CFLAGS = -Xc -a ansi -w3 -O2 -I../.. -D__STAND_ALONE CFLAGS = -Xc -a ansi -w3 -O2 -I../.. -DXP_AWK_STAND_ALONE
all: $(OBJS) all: $(OBJS)
ar cr $(OUT) $(OBJS) ar cr $(OUT) $(OBJS)

View File

@ -1,10 +1,10 @@
/* /*
* $Id: map.c,v 1.10 2006-04-14 10:56:42 bacon Exp $ * $Id: map.c,v 1.11 2006-04-16 04:31:38 bacon Exp $
*/ */
#include <xp/awk/awk_i.h> #include <xp/awk/awk_i.h>
#ifndef __STAND_ALONE #ifndef XP_AWK_STAND_ALONE
#include <xp/bas/memory.h> #include <xp/bas/memory.h>
#include <xp/bas/string.h> #include <xp/bas/string.h>
#include <xp/bas/assert.h> #include <xp/bas/assert.h>

View File

@ -1,5 +1,5 @@
/* /*
* $Id: map.h,v 1.6 2006-03-27 14:14:00 bacon Exp $ * $Id: map.h,v 1.7 2006-04-16 04:31:38 bacon Exp $
*/ */
#ifndef _XP_AWK_MAP_H_ #ifndef _XP_AWK_MAP_H_
@ -9,7 +9,7 @@
#error Never include this file directly. Include <xp/awk/awk.h> instead #error Never include this file directly. Include <xp/awk/awk.h> instead
#endif #endif
#ifdef __STAND_ALONE #ifdef XP_AWK_STAND_ALONE
#include <xp/awk/sa.h> #include <xp/awk/sa.h>
#else #else
#include <xp/types.h> #include <xp/types.h>

View File

@ -1,15 +1,16 @@
/* /*
* $Id: misc.c,v 1.4 2006-04-10 14:53:48 bacon Exp $ * $Id: misc.c,v 1.5 2006-04-16 04:31:38 bacon Exp $
*/ */
#include <xp/awk/awk_i.h> #include <xp/awk/awk_i.h>
#ifndef __STAND_ALONE #ifndef XP_AWK_STAND_ALONE
#include <xp/bas/ctype.h> #include <xp/bas/ctype.h>
#include <xp/bas/assert.h> #include <xp/bas/assert.h>
#endif #endif
xp_long_t xp_awk_strtolong (const xp_char_t* str, int base) xp_long_t xp_awk_strtolong (
const xp_char_t* str, int base, const xp_char_t** endptr)
{ {
xp_long_t n = 0; xp_long_t n = 0;
const xp_char_t* p; const xp_char_t* p;
@ -74,6 +75,7 @@ xp_long_t xp_awk_strtolong (const xp_char_t* str, int base)
p++; p++;
} }
if (endptr != XP_NULL) *endptr = p;
return (negative)? -n: n; return (negative)? -n: n;
} }

View File

@ -1,10 +1,10 @@
/* /*
* $Id: parse.c,v 1.81 2006-04-14 16:26:00 bacon Exp $ * $Id: parse.c,v 1.82 2006-04-16 04:31:38 bacon Exp $
*/ */
#include <xp/awk/awk_i.h> #include <xp/awk/awk_i.h>
#ifndef __STAND_ALONE #ifndef XP_AWK_STAND_ALONE
#include <xp/bas/memory.h> #include <xp/bas/memory.h>
#include <xp/bas/ctype.h> #include <xp/bas/ctype.h>
#include <xp/bas/string.h> #include <xp/bas/string.h>
@ -58,6 +58,7 @@ enum
TOKEN_DOLLAR, TOKEN_DOLLAR,
TOKEN_COMMA, TOKEN_COMMA,
TOKEN_PERIOD,
TOKEN_SEMICOLON, TOKEN_SEMICOLON,
TOKEN_COLON, TOKEN_COLON,
TOKEN_QUEST, TOKEN_QUEST,
@ -196,6 +197,34 @@ static struct __kwent __kwtab[] =
{ XP_NULL, 0, 0 } { XP_NULL, 0, 0 }
}; };
/* TODO:
static struct __kwent __bvtab[] =
{
{ XP_TEXT("ARGC"), TOKEN_ARGC, 0 },
{ XP_TEXT("ARGIND"), TOKEN_ARGIND, 0 },
{ XP_TEXT("ARGV"), TOKEN_ARGV, 0 },
{ XP_TEXT("CONVFMT"), TOKEN_CONVFMT, 0 },
{ XP_TEXT("FIELDWIDTHS"), TOKEN_FIELDWIDTHS, 0 },
{ XP_TEXT("ENVIRON"), TOKEN_ENVIRON, 0 },
{ XP_TEXT("ERRNO"), TOKEN_ERRNO, 0 },
{ XP_TEXT("FILENAME"), TOKEN_FILENAME, 0 },
{ XP_TEXT("FNR"), TOKEN_FNR, 0 },
{ XP_TEXT("FS"), TOKEN_FS, 0 },
{ XP_TEXT("IGNORECASE"), TOKEN_IGNORECASE, 0 },
{ XP_TEXT("NF"), TOKEN_NF, 0 },
{ XP_TEXT("NR"), TOKEN_NR, 0 },
{ XP_TEXT("OFMT"), TOKEN_OFMT, 0 },
{ XP_TEXT("OFS"), TOKEN_OFS, 0 },
{ XP_TEXT("ORS"), TOKEN_ORS, 0 },
{ XP_TEXT("RS"), TOKEN_RS, 0 },
{ XP_TEXT("RT"), TOKEN_RT, 0 },
{ XP_TEXT("RSTART"), TOKEN_RSTART, 0 },
{ XP_TEXT("RLENGTH"), TOKEN_RLENGTH, 0 },
{ XP_TEXT("SUBSEP"), TOKEN_SUBSEP, 0 },
{ XP_NULL, 0, 0 }
};
*/
#define GET_CHAR(awk) \ #define GET_CHAR(awk) \
do { if (__get_char(awk) == -1) return -1; } while(0) do { if (__get_char(awk) == -1) return -1; } while(0)
@ -233,7 +262,7 @@ do { \
do { (awk)->errnum = (code); return XP_NULL; } while (0) do { (awk)->errnum = (code); return XP_NULL; } while (0)
/* TODO: remove stdio.h */ /* TODO: remove stdio.h */
#ifndef __STAND_ALONE #ifndef XP_AWK_STAND_ALONE
#include <xp/bas/stdio.h> #include <xp/bas/stdio.h>
#endif #endif
static int __dump_func (xp_awk_pair_t* pair) static int __dump_func (xp_awk_pair_t* pair)
@ -1557,7 +1586,8 @@ static xp_awk_nde_t* __parse_primary (xp_awk_t* awk)
nde->type = XP_AWK_NDE_INT; nde->type = XP_AWK_NDE_INT;
nde->next = XP_NULL; nde->next = XP_NULL;
nde->val = xp_awk_strtolong (XP_STR_BUF(&awk->token.name), 0); nde->val = xp_awk_strtolong (
XP_STR_BUF(&awk->token.name), 0, XP_NULL);
xp_assert ( xp_assert (
XP_STR_LEN(&awk->token.name) == XP_STR_LEN(&awk->token.name) ==
@ -2572,6 +2602,12 @@ static int __get_token (xp_awk_t* awk)
ADD_TOKEN_CHAR (awk, c); ADD_TOKEN_CHAR (awk, c);
GET_CHAR_TO (awk, c); GET_CHAR_TO (awk, c);
} }
else if (c == XP_CHAR('.'))
{
SET_TOKEN_TYPE (awk, TOKEN_PERIOD);
ADD_TOKEN_CHAR (awk, c);
GET_CHAR_TO (awk, c);
}
else if (c == XP_CHAR(';')) else if (c == XP_CHAR(';'))
{ {
SET_TOKEN_TYPE (awk, TOKEN_SEMICOLON); SET_TOKEN_TYPE (awk, TOKEN_SEMICOLON);

View File

@ -1,5 +1,5 @@
/* /*
* $Id: run.c,v 1.49 2006-04-14 16:26:00 bacon Exp $ * $Id: run.c,v 1.50 2006-04-16 04:31:38 bacon Exp $
*/ */
#include <xp/awk/awk_i.h> #include <xp/awk/awk_i.h>
@ -7,7 +7,7 @@
/* TODO: remove this dependency...*/ /* TODO: remove this dependency...*/
#include <math.h> #include <math.h>
#ifndef __STAND_ALONE #ifndef XP_AWK_STAND_ALONE
#include <xp/bas/assert.h> #include <xp/bas/assert.h>
#include <xp/bas/string.h> #include <xp/bas/string.h>
#include <xp/bas/memory.h> #include <xp/bas/memory.h>
@ -115,6 +115,10 @@ static int __raw_push (xp_awk_t* awk, void* val);
static void __raw_pop (xp_awk_t* awk); static void __raw_pop (xp_awk_t* awk);
static void __raw_pop_times (xp_awk_t* awk, xp_size_t times); static void __raw_pop_times (xp_awk_t* awk, xp_size_t times);
static xp_awk_val_t* __str_to_num (
xp_awk_t* awk, xp_awk_val_str_t* str,
void (*helper) (void*,void*), void* user_data);
typedef xp_awk_val_t* (*binop_func_t) ( typedef xp_awk_val_t* (*binop_func_t) (
xp_awk_t* awk, xp_awk_val_t* left, xp_awk_val_t* right); xp_awk_t* awk, xp_awk_val_t* left, xp_awk_val_t* right);
typedef xp_awk_val_t* (*eval_expr_t) (xp_awk_t* awk, xp_awk_nde_t* nde); typedef xp_awk_val_t* (*eval_expr_t) (xp_awk_t* awk, xp_awk_nde_t* nde);
@ -672,7 +676,7 @@ 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_t* nde) static xp_awk_val_t* __eval_assignment (xp_awk_t* awk, xp_awk_nde_t* nde)
{ {
xp_awk_val_t* val; xp_awk_val_t* val, * res;
xp_awk_nde_ass_t* ass = (xp_awk_nde_ass_t*)nde; xp_awk_nde_ass_t* ass = (xp_awk_nde_ass_t*)nde;
xp_assert (ass->left != XP_NULL && ass->right != XP_NULL); xp_assert (ass->left != XP_NULL && ass->right != XP_NULL);
@ -680,8 +684,67 @@ static xp_awk_val_t* __eval_assignment (xp_awk_t* awk, xp_awk_nde_t* nde)
val = __eval_expression(awk, ass->right); val = __eval_expression(awk, ass->right);
if (val == XP_NULL) return XP_NULL; if (val == XP_NULL) return XP_NULL;
/*TODO: ass->opcode....*/ xp_awk_refupval (val);
return __do_assignment (awk, (xp_awk_nde_var_t*)ass->left, val);
if (ass->opcode != XP_AWK_ASSOP_NONE)
{
xp_awk_val_t* val2, * tmp;
val2 = __eval_expression (awk, ass->left);
if (val2 == XP_NULL)
{
xp_awk_refdownval (awk, val);
return XP_NULL;
}
xp_awk_refupval (val2);
if (ass->opcode == XP_AWK_ASSOP_PLUS)
{
tmp = __eval_binop_plus (awk, val2, val);
}
else if (ass->opcode == XP_AWK_ASSOP_MINUS)
{
tmp = __eval_binop_minus (awk, val2, val);
}
else if (ass->opcode == XP_AWK_ASSOP_MUL)
{
tmp = __eval_binop_mul (awk, val2, val);
}
else if (ass->opcode == XP_AWK_ASSOP_DIV)
{
tmp = __eval_binop_div (awk, val2, val);
}
else if (ass->opcode == XP_AWK_ASSOP_MOD)
{
tmp = __eval_binop_mod (awk, val2, val);
}
else if (ass->opcode == XP_AWK_ASSOP_EXP)
{
tmp = __eval_binop_exp (awk, val2, val);
}
else
{
xp_assert (!"should never happen - invalid assignment opcode");
PANIC (awk, XP_AWK_EINTERNAL);
}
if (tmp == XP_NULL)
{
xp_awk_refdownval (awk, val);
xp_awk_refdownval (awk, val2);
return XP_NULL;
}
xp_awk_refdownval (awk, val);
val = tmp;
xp_awk_refupval (val);
}
res = __do_assignment (awk, (xp_awk_nde_var_t*)ass->left, val);
xp_awk_refdownval (awk, val);
return res;
} }
static xp_awk_val_t* __do_assignment ( static xp_awk_val_t* __do_assignment (
@ -692,7 +755,7 @@ static xp_awk_val_t* __do_assignment (
xp_awk_pair_t* pair; xp_awk_pair_t* pair;
xp_char_t* name; xp_char_t* name;
pair = xp_awk_map_get(&awk->run.named, var->id.name); pair = xp_awk_map_get (&awk->run.named, var->id.name);
if (pair == XP_NULL) if (pair == XP_NULL)
{ {
name = xp_strdup (var->id.name); name = xp_strdup (var->id.name);
@ -1264,52 +1327,111 @@ static xp_awk_val_t* __eval_binop_plus (
{ {
xp_awk_val_t* res = XP_NULL; xp_awk_val_t* res = XP_NULL;
if (left->type == XP_AWK_VAL_INT && /* TODO: improve this ............ */
right->type == XP_AWK_VAL_INT) if (left->type == XP_AWK_VAL_NIL)
{ {
xp_long_t r = if (right->type == XP_AWK_VAL_NIL)
((xp_awk_val_int_t*)left)->val + {
((xp_awk_val_int_t*)right)->val; res = xp_awk_val_nil;
res = xp_awk_makeintval (awk, r); }
else if (right->type == XP_AWK_VAL_INT)
{
res = xp_awk_makeintval (
awk, ((xp_awk_val_int_t*)right)->val);
}
else if (right->type == XP_AWK_VAL_REAL)
{
res = xp_awk_makerealval (
awk, ((xp_awk_val_real_t*)right)->val);
}
else if (right->type == XP_AWK_VAL_STR)
{
res = __str_to_num (
awk, (xp_awk_val_str_t*)right, __helper, NULL);
}
else
{
PANIC (awk, XP_AWK_EOPERAND);
}
} }
else if (left->type == XP_AWK_VAL_REAL && else if (left->type == XP_AWK_VAL_INT)
right->type == XP_AWK_VAL_REAL)
{ {
xp_real_t r = if (right->type == XP_AWK_VAL_INT)
((xp_awk_val_real_t*)left)->val + {
((xp_awk_val_real_t*)right)->val; xp_long_t r =
res = xp_awk_makerealval (awk, r); ((xp_awk_val_int_t*)left)->val +
((xp_awk_val_int_t*)right)->val;
res = xp_awk_makeintval (awk, r);
}
else if (right->type == XP_AWK_VAL_REAL)
{
xp_real_t r =
((xp_awk_val_int_t*)left)->val +
((xp_awk_val_real_t*)right)->val;
res = xp_awk_makerealval (awk, r);
}
else if (right->type == XP_AWK_VAL_STR)
{
xp_long_t r =
((xp_awk_val_int_t*)left)->val +
xp_awk_strtolong(((xp_awk_val_str_t*)right)->buf,0,XP_NULL);
/* don't care about ((xp_awk_val_str_t*)right)->len */
res = xp_awk_makeintval (awk, r);
}
else
{
PANIC (awk, XP_AWK_EOPERAND);
}
} }
else if (left->type == XP_AWK_VAL_INT && else if (left->type == XP_AWK_VAL_REAL)
right->type == XP_AWK_VAL_REAL)
{ {
xp_real_t r = if (right->type == XP_AWK_VAL_INT)
((xp_awk_val_int_t*)left)->val + {
((xp_awk_val_real_t*)right)->val; xp_real_t r =
res = xp_awk_makerealval (awk, r); ((xp_awk_val_real_t*)left)->val +
((xp_awk_val_int_t*)right)->val;
res = xp_awk_makerealval (awk, r);
}
else if (right->type == XP_AWK_VAL_REAL)
{
xp_real_t r =
((xp_awk_val_real_t*)left)->val +
((xp_awk_val_real_t*)right)->val;
res = xp_awk_makerealval (awk, r);
}
else if (right->type == XP_AWK_VAL_STR)
{
xp_real_t r =
((xp_awk_val_real_t*)left)->val +
xp_awk_strtoreal(((xp_awk_val_str_t*)right)->buf);
/* don't care about ((xp_awk_val_str_t*)right)->len */
res = xp_awk_makerealval (awk, r);
}
else
{
PANIC (awk, XP_AWK_EOPERAND);
}
} }
else if (left->type == XP_AWK_VAL_REAL && else if (left->type == XP_AWK_VAL_STR)
right->type == XP_AWK_VAL_INT)
{ {
xp_real_t r =
((xp_awk_val_real_t*)left)->val + if (right->type == XP_AWK_VAL_STR)
((xp_awk_val_int_t*)right)->val; {
res = xp_awk_makerealval (awk, r); res = xp_awk_makestrval2 (
} ((xp_awk_val_str_t*)left)->buf,
else if (left->type == XP_AWK_VAL_STR && ((xp_awk_val_str_t*)left)->len,
right->type == XP_AWK_VAL_STR) ((xp_awk_val_str_t*)right)->buf,
{ ((xp_awk_val_str_t*)right)->len);
res = xp_awk_makestrval2 ( }
((xp_awk_val_str_t*)left)->buf, else
((xp_awk_val_str_t*)left)->len, {
((xp_awk_val_str_t*)right)->buf, PANIC (awk, XP_AWK_EOPERAND);
((xp_awk_val_str_t*)right)->len); }
} }
else else
{ {
PANIC (awk, XP_AWK_EOPERAND); PANIC (awk, XP_AWK_EOPERAND);
} }
/* TODO: addition between integer and astring??? 1 + "123" */
if (res == XP_NULL) PANIC (awk, XP_AWK_ENOMEM); if (res == XP_NULL) PANIC (awk, XP_AWK_ENOMEM);
return res; return res;
@ -1320,37 +1442,104 @@ static xp_awk_val_t* __eval_binop_minus (
{ {
xp_awk_val_t* res = XP_NULL; xp_awk_val_t* res = XP_NULL;
if (left->type == XP_AWK_VAL_INT && if (left->type == XP_AWK_VAL_NIL)
right->type == XP_AWK_VAL_INT)
{ {
xp_long_t r = if (right->type == XP_AWK_VAL_NIL)
((xp_awk_val_int_t*)left)->val - {
((xp_awk_val_int_t*)right)->val; res = xp_awk_val_nil;
res = xp_awk_makeintval (awk, r); }
else if (right->type == XP_AWK_VAL_INT)
{
res = xp_awk_makeintval (
awk, -((xp_awk_val_int_t*)right)->val);
}
else if (right->type == XP_AWK_VAL_REAL)
{
res = xp_awk_makerealval (
awk, -((xp_awk_val_real_t*)right)->val);
}
else if (right->type == XP_AWK_VAL_STR)
{
res = __str_to_num (
awk, (xp_awk_val_str_t*)right, __helper, NULL);
}
else
{
PANIC (awk, XP_AWK_EOPERAND);
}
} }
else if (left->type == XP_AWK_VAL_REAL && else if (left->type == XP_AWK_VAL_INT)
right->type == XP_AWK_VAL_REAL)
{ {
xp_real_t r = if (right->type == XP_AWK_VAL_INT)
((xp_awk_val_real_t*)left)->val - {
((xp_awk_val_real_t*)right)->val; xp_long_t r =
res = xp_awk_makerealval (awk, r); ((xp_awk_val_int_t*)left)->val -
((xp_awk_val_int_t*)right)->val;
res = xp_awk_makeintval (awk, r);
}
else if (right->type == XP_AWK_VAL_REAL)
{
xp_real_t r =
((xp_awk_val_int_t*)left)->val -
((xp_awk_val_real_t*)right)->val;
res = xp_awk_makerealval (awk, r);
}
else if (right->type == XP_AWK_VAL_STR)
{
xp_long_t r =
((xp_awk_val_int_t*)left)->val -
xp_awk_strtolong(((xp_awk_val_str_t*)right)->buf,0,XP_NULL);
res = xp_awk_makeintval (awk, r);
}
else
{
PANIC (awk, XP_AWK_EOPERAND);
}
} }
else if (left->type == XP_AWK_VAL_INT && else if (left->type == XP_AWK_VAL_REAL)
right->type == XP_AWK_VAL_REAL)
{ {
xp_real_t r = if (right->type == XP_AWK_VAL_INT)
((xp_awk_val_int_t*)left)->val - {
((xp_awk_val_real_t*)right)->val; xp_real_t r =
res = xp_awk_makerealval (awk, r); ((xp_awk_val_real_t*)left)->val -
((xp_awk_val_int_t*)right)->val;
res = xp_awk_makerealval (awk, r);
}
else if (right->type == XP_AWK_VAL_REAL)
{
xp_real_t r =
((xp_awk_val_real_t*)left)->val -
((xp_awk_val_real_t*)right)->val;
res = xp_awk_makerealval (awk, r);
}
else if (right->type == XP_AWK_VAL_STR)
{
xp_real_t r =
((xp_awk_val_real_t*)left)->val -
xp_awk_strtoreal(((xp_awk_val_str_t*)right)->buf);
/* don't care about ((xp_awk_val_str_t*)right)->len */
res = xp_awk_makerealval (awk, r);
}
else
{
PANIC (awk, XP_AWK_EOPERAND);
}
} }
else if (left->type == XP_AWK_VAL_REAL && else if (left->type == XP_AWK_VAL_STR)
right->type == XP_AWK_VAL_INT)
{ {
xp_real_t r =
((xp_awk_val_real_t*)left)->val - if (right->type == XP_AWK_VAL_STR)
((xp_awk_val_int_t*)right)->val; {
res = xp_awk_makerealval (awk, r); res = xp_awk_makestrval2 (
((xp_awk_val_str_t*)left)->buf,
((xp_awk_val_str_t*)left)->len,
((xp_awk_val_str_t*)right)->buf,
((xp_awk_val_str_t*)right)->len);
}
else
{
PANIC (awk, XP_AWK_EOPERAND);
}
} }
else else
{ {
@ -1506,24 +1695,24 @@ static xp_awk_val_t* __eval_binop_exp (
right->type == XP_AWK_VAL_REAL) right->type == XP_AWK_VAL_REAL)
{ {
/* TODO: write own pow... */ /* TODO: write own pow... */
double x = ((xp_awk_val_int_t*)left)->val; xp_real_t x = ((xp_awk_val_int_t*)left)->val;
double y = ((xp_awk_val_real_t*)right)->val; xp_real_t y = ((xp_awk_val_real_t*)right)->val;
res = xp_awk_makerealval (awk, pow (x, y)); res = xp_awk_makerealval (awk, pow (x, y));
} }
else if (left->type == XP_AWK_VAL_REAL && else if (left->type == XP_AWK_VAL_REAL &&
right->type == XP_AWK_VAL_INT) right->type == XP_AWK_VAL_INT)
{ {
/* TODO: write own pow... */ /* TODO: write own pow... */
double x = ((xp_awk_val_real_t*)left)->val; xp_real_t x = ((xp_awk_val_real_t*)left)->val;
double y = ((xp_awk_val_int_t*)right)->val; xp_real_t y = ((xp_awk_val_int_t*)right)->val;
res = xp_awk_makerealval (awk, pow (x, y)); res = xp_awk_makerealval (awk, pow (x, y));
} }
else if (left->type == XP_AWK_VAL_REAL && else if (left->type == XP_AWK_VAL_REAL &&
right->type == XP_AWK_VAL_REAL) right->type == XP_AWK_VAL_REAL)
{ {
/* TODO: wirte own pow... */ /* TODO: wirte own pow... */
double x = ((xp_awk_val_real_t*)left)->val; xp_real_t x = ((xp_awk_val_real_t*)left)->val;
double y = ((xp_awk_val_real_t*)right)->val; xp_real_t y = ((xp_awk_val_real_t*)right)->val;
res = xp_awk_makerealval (awk, pow (x, y)); res = xp_awk_makerealval (awk, pow (x, y));
} }
else else
@ -1717,8 +1906,7 @@ static xp_awk_val_t* __eval_incpre (xp_awk_t* awk, xp_awk_nde_t* nde)
PANIC (awk, XP_AWK_EINTERNAL); PANIC (awk, XP_AWK_EINTERNAL);
} }
if (__do_assignment (awk, if (__do_assignment(awk, (xp_awk_nde_var_t*)exp->left, res) == XP_NULL)
(xp_awk_nde_var_t*)exp->left, res) == XP_NULL)
{ {
xp_awk_refdownval (awk, left); xp_awk_refdownval (awk, left);
return XP_NULL; return XP_NULL;
@ -1831,8 +2019,7 @@ static xp_awk_val_t* __eval_incpst (xp_awk_t* awk, xp_awk_nde_t* nde)
PANIC (awk, XP_AWK_EINTERNAL); PANIC (awk, XP_AWK_EINTERNAL);
} }
if (__do_assignment (awk, if (__do_assignment(awk, (xp_awk_nde_var_t*)exp->left, res2) == XP_NULL)
(xp_awk_nde_var_t*)exp->left, res2) == XP_NULL)
{ {
xp_awk_refdownval (awk, left); xp_awk_refdownval (awk, left);
return XP_NULL; return XP_NULL;
@ -2158,3 +2345,35 @@ static void __raw_pop_times (xp_awk_t* awk, xp_size_t times)
__raw_pop (awk); __raw_pop (awk);
} }
} }
static xp_awk_val_t* __str_to_num (
xp_awk_t* awk, xp_awk_val_str_t* str,
void (*helper) (void*,void*), void* user_data)
{
xp_long_t l;
const xp_char_t* endptr;
xp_awk_val_t* res;
/* don't care about str->len */
l = xp_awk_strtolong (str->buf, 0, &endptr);
if (*endptr == XP_CHAR('.') ||
*endptr == XP_CHAR('E') ||
*endptr == XP_CHAR('e'))
{
xp_real_t r;
r = xp_awk_strtoreal (
((xp_awk_val_str_t*)str)->buf);
res = helper (&r, user_data);
//res = xp_awk_makerealval (awk, r * factor);
}
else
{
res = helper (&l, user_data);
//res = xp_awk_makeintval (awk, l * factor);
}
return res;
}

View File

@ -1,10 +1,10 @@
/* /*
* $Id: sa.c,v 1.15 2006-04-06 16:25:37 bacon Exp $ * $Id: sa.c,v 1.16 2006-04-16 04:31:38 bacon Exp $
*/ */
#include <xp/awk/awk_i.h> #include <xp/awk/awk_i.h>
#ifdef __STAND_ALONE #ifdef XP_AWK_STAND_ALONE
static xp_char_t* __adjust_format (const xp_char_t* format); static xp_char_t* __adjust_format (const xp_char_t* format);

View File

@ -1,5 +1,5 @@
/* /*
* $Id: sa.h,v 1.21 2006-04-10 14:53:48 bacon Exp $ * $Id: sa.h,v 1.22 2006-04-16 04:31:38 bacon Exp $
*/ */
#ifndef _XP_AWK_SA_H_ #ifndef _XP_AWK_SA_H_
@ -9,7 +9,7 @@
#error Never include this file directly. Include <xp/awk/awk.h> instead #error Never include this file directly. Include <xp/awk/awk.h> instead
#endif #endif
#ifdef __STAND_ALONE #ifdef XP_AWK_STAND_ALONE
#if !defined(XP_CHAR_IS_MCHAR) && !defined(XP_CHAR_IS_WCHAR) #if !defined(XP_CHAR_IS_MCHAR) && !defined(XP_CHAR_IS_WCHAR)
#error Neither XP_CHAR_IS_MCHAR nor XP_CHAR_IS_WCHAR is defined. #error Neither XP_CHAR_IS_MCHAR nor XP_CHAR_IS_WCHAR is defined.

View File

@ -1,10 +1,10 @@
/* /*
* $Id: tab.c,v 1.7 2006-03-31 16:35:37 bacon Exp $ * $Id: tab.c,v 1.8 2006-04-16 04:31:38 bacon Exp $
*/ */
#include <xp/awk/awk_i.h> #include <xp/awk/awk_i.h>
#ifndef __STAND_ALONE #ifndef XP_AWK_STAND_ALONE
#include <xp/bas/memory.h> #include <xp/bas/memory.h>
#include <xp/bas/string.h> #include <xp/bas/string.h>
#include <xp/bas/assert.h> #include <xp/bas/assert.h>

View File

@ -1,5 +1,5 @@
/* /*
* $Id: tab.h,v 1.6 2006-04-14 10:56:42 bacon Exp $ * $Id: tab.h,v 1.7 2006-04-16 04:31:38 bacon Exp $
*/ */
#ifndef _XP_AWK_TAB_H_ #ifndef _XP_AWK_TAB_H_
@ -9,7 +9,7 @@
#error Never include this file directly. Include <xp/awk/awk.h> instead #error Never include this file directly. Include <xp/awk/awk.h> instead
#endif #endif
#ifdef __STAND_ALONE #ifdef XP_AWK_STAND_ALONE
#include <xp/awk/sa.h> #include <xp/awk/sa.h>
#else #else
#include <xp/types.h> #include <xp/types.h>

View File

@ -1,10 +1,10 @@
/* /*
* $Id: tree.c,v 1.37 2006-04-14 16:26:00 bacon Exp $ * $Id: tree.c,v 1.38 2006-04-16 04:31:38 bacon Exp $
*/ */
#include <xp/awk/awk_i.h> #include <xp/awk/awk_i.h>
#ifndef __STAND_ALONE #ifndef XP_AWK_STAND_ALONE
#include <xp/bas/memory.h> #include <xp/bas/memory.h>
#include <xp/bas/assert.h> #include <xp/bas/assert.h>
#include <xp/bas/stdio.h> #include <xp/bas/stdio.h>
@ -630,7 +630,9 @@ void xp_awk_clrpt (xp_awk_nde_t* tree)
break; break;
default: default:
xp_assert (XP_TEXT("shoud not happen") == XP_TEXT(" here")); xp_assert (!"should never happen - invalid node type");
xp_free (p);
break;
} }
p = next; p = next;

View File

@ -1,10 +1,10 @@
/* /*
* $Id: val.c,v 1.18 2006-04-14 10:56:42 bacon Exp $ * $Id: val.c,v 1.19 2006-04-16 04:31:38 bacon Exp $
*/ */
#include <xp/awk/awk_i.h> #include <xp/awk/awk_i.h>
#ifndef __STAND_ALONE #ifndef XP_AWK_STAND_ALONE
#include <xp/bas/string.h> #include <xp/bas/string.h>
#include <xp/bas/memory.h> #include <xp/bas/memory.h>
#include <xp/bas/assert.h> #include <xp/bas/assert.h>
@ -248,7 +248,7 @@ xp_bool_t xp_awk_boolval (xp_awk_val_t* val)
return ((xp_awk_val_str_t*)val)->len > 0; return ((xp_awk_val_str_t*)val)->len > 0;
} }
xp_assert (!"should never happen"); xp_assert (!"should never happen - invalid vlaue type");
return xp_false; return xp_false;
} }
@ -287,6 +287,7 @@ void xp_awk_printval (xp_awk_val_t* val)
break; break;
default: default:
xp_printf (XP_TEXT("**** INTERNAL ERROR - UNKNOWN VALUE TYPE ****\n")); xp_assert (!"should never happen - invalid value type");
xp_printf (XP_TEXT("**** INTERNAL ERROR - INVALID VALUE TYPE ****\n"));
} }
} }

View File

@ -1,5 +1,5 @@
/* /*
* $Id: awk.c,v 1.22 2006-04-14 16:26:00 bacon Exp $ * $Id: awk.c,v 1.23 2006-04-16 04:31:38 bacon Exp $
*/ */
#include <xp/awk/awk.h> #include <xp/awk/awk.h>
@ -7,19 +7,30 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#ifdef __STAND_ALONE
#define xp_printf xp_awk_printf
extern int xp_awk_printf (const xp_char_t* fmt, ...);
#else
#ifdef XP_CHAR_IS_MCHAR #ifdef XP_CHAR_IS_MCHAR
#define xp_printf printf #define xp_printf printf
#else #else
#define xp_printf wprintf #define xp_printf wprintf
#endif #endif
#endif
#ifdef __STAND_ALONE
#define xp_strcmp xp_awk_strcmp
extern int xp_awk_strcmp (const xp_char_t* s1, const xp_char_t* s2);
#else
#ifdef XP_CHAR_IS_MCHAR #ifdef XP_CHAR_IS_MCHAR
#define xp_strcmp strcmp #define xp_strcmp strcmp
#else #else
#define xp_strcmp wcscmp #define xp_strcmp wcscmp
#endif #endif
#endif
static xp_ssize_t process_source (int cmd, void* arg, xp_char_t* data, xp_size_t size) static xp_ssize_t process_source (
int cmd, void* arg, xp_char_t* data, xp_size_t size)
{ {
xp_char_t c; xp_char_t c;

View File

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

View File

@ -1,6 +1,6 @@
CC = cl CC = cl
#CFLAGS = /nologo /MT /W3 /GR- /D_WIN32_WINNT=0x0400 -I..\..\.. #CFLAGS = /nologo /MT /W3 /GR- /D_WIN32_WINNT=0x0400 -I..\..\..
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 LDFLAGS = /libpath:..\..\bas /libpath:..\..\awk
LIBS = xpbas.lib xpawk.lib LIBS = xpbas.lib xpawk.lib
#LIBS = xpawk.lib #LIBS = xpawk.lib

View File

@ -1,5 +1,5 @@
CC = cc CC = cc
CFLAGS = -Xc -a ansi -O2 -I../../.. CFLAGS = -Xc -a ansi -O2 -I../../.. -D__STAND_ALONE
LDFLAGS = -L../../bas -L../../awk LDFLAGS = -L../../bas -L../../awk
LIBS = -lxpawk -lm LIBS = -lxpawk -lm