From 9ca4d7128a23bcba5eeff74b9e5d4eaa31769c2a Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Wed, 4 Oct 2006 14:52:12 +0000 Subject: [PATCH] *** empty log message *** --- ase/awk/run.c | 87 ++++++++++++++++++++++++++++++++----------- ase/awk/val.c | 14 +++++-- ase/test/awk/comp.awk | 32 ++++++++++++++++ 3 files changed, 109 insertions(+), 24 deletions(-) diff --git a/ase/awk/run.c b/ase/awk/run.c index 73c9100b..d4c243bb 100644 --- a/ase/awk/run.c +++ b/ase/awk/run.c @@ -1,5 +1,5 @@ /* - * $Id: run.c,v 1.221 2006-10-04 10:11:04 bacon Exp $ + * $Id: run.c,v 1.222 2006-10-04 14:51:20 bacon Exp $ */ #include @@ -7,8 +7,8 @@ /* TODO: remove this dependency...*/ #include +#define CMP_ERROR -99 #define DEF_BUF_CAPA 256 - #define STACK_INCREMENT 512 #define STACK_AT(run,n) ((run)->stack[(run)->stack_base+(n)]) @@ -36,14 +36,7 @@ enum #define PANIC_I(run,code) \ do { (run)->errnum = (code); return -1; } while (0) -#if (XP_SIZEOF_LONG_DOUBLE != 0) - #define DEFAULT_OFMT XP_T("%.6Lg") -#elif (XP_SIZEOF_DOUBLE != 0) - #define DEFAULT_OFMT XP_T("%.6g") -#else - #error Unsupported floating-point type size -#endif - +#define DEFAULT_OFMT XP_T("%.6g") #define DEFAULT_OFS XP_T(" ") #define DEFAULT_ORS XP_T("\n") #define DEFAULT_SUBSEP XP_T("\034") @@ -2842,8 +2835,34 @@ static int __cmp_int_real ( static int __cmp_int_str ( xp_awk_run_t* run, xp_awk_val_t* left, xp_awk_val_t* right) { - /* TODO */ - return 0; + xp_char_t* str; + xp_size_t len; + int n; + + str = xp_awk_valtostr (run, left, xp_true, XP_NULL, &len); + if (str == XP_NULL) + { + run->errnum = XP_AWK_ENOMEM; + return CMP_ERROR; + } + + if (run->global.ignorecase) + { + n = xp_awk_strxncasecmp ( + run->awk, str, len, + ((xp_awk_val_str_t*)right)->buf, + ((xp_awk_val_str_t*)right)->len); + } + else + { + n = xp_awk_strxncmp ( + str, len, + ((xp_awk_val_str_t*)right)->buf, + ((xp_awk_val_str_t*)right)->len); + } + + XP_AWK_FREE (run->awk, str); + return n; } static int __cmp_real_nil ( @@ -2877,8 +2896,34 @@ static int __cmp_real_real ( static int __cmp_real_str ( xp_awk_run_t* run, xp_awk_val_t* left, xp_awk_val_t* right) { - /* TODO */ - return 0; + xp_char_t* str; + xp_size_t len; + int n; + + str = xp_awk_valtostr (run, left, xp_true, XP_NULL, &len); + if (str == XP_NULL) + { + run->errnum = XP_AWK_ENOMEM; + return CMP_ERROR; + } + + if (run->global.ignorecase) + { + n = xp_awk_strxncasecmp ( + run->awk, str, len, + ((xp_awk_val_str_t*)right)->buf, + ((xp_awk_val_str_t*)right)->len); + } + else + { + n = xp_awk_strxncmp ( + str, len, + ((xp_awk_val_str_t*)right)->buf, + ((xp_awk_val_str_t*)right)->len); + } + + XP_AWK_FREE (run->awk, str); + return n; } static int __cmp_str_nil ( @@ -2941,7 +2986,7 @@ static int __cmp_val ( { /* a map can't be compared againt other values */ run->errnum = XP_AWK_EOPERAND; - return -99; + return CMP_ERROR; } xp_assert (left->type >= XP_AWK_VAL_NIL && @@ -2956,7 +3001,7 @@ static xp_awk_val_t* __eval_binop_eq ( xp_awk_run_t* run, xp_awk_val_t* left, xp_awk_val_t* right) { int n = __cmp_val (run, left, right); - if (n == -99) return XP_NULL; + if (n == CMP_ERROR) return XP_NULL; return (n == 0)? xp_awk_val_one: xp_awk_val_zero; } @@ -2964,7 +3009,7 @@ static xp_awk_val_t* __eval_binop_ne ( xp_awk_run_t* run, xp_awk_val_t* left, xp_awk_val_t* right) { int n = __cmp_val (run, left, right); - if (n == -99) return XP_NULL; + if (n == CMP_ERROR) return XP_NULL; return (n != 0)? xp_awk_val_one: xp_awk_val_zero; } @@ -2972,7 +3017,7 @@ static xp_awk_val_t* __eval_binop_gt ( xp_awk_run_t* run, xp_awk_val_t* left, xp_awk_val_t* right) { int n = __cmp_val (run, left, right); - if (n == -99) return XP_NULL; + if (n == CMP_ERROR) return XP_NULL; return (n > 0)? xp_awk_val_one: xp_awk_val_zero; } @@ -2980,7 +3025,7 @@ static xp_awk_val_t* __eval_binop_ge ( xp_awk_run_t* run, xp_awk_val_t* left, xp_awk_val_t* right) { int n = __cmp_val (run, left, right); - if (n == -99) return XP_NULL; + if (n == CMP_ERROR) return XP_NULL; return (n >= 0)? xp_awk_val_one: xp_awk_val_zero; } @@ -2988,7 +3033,7 @@ static xp_awk_val_t* __eval_binop_lt ( xp_awk_run_t* run, xp_awk_val_t* left, xp_awk_val_t* right) { int n = __cmp_val (run, left, right); - if (n == -99) return XP_NULL; + if (n == CMP_ERROR) return XP_NULL; return (n < 0)? xp_awk_val_one: xp_awk_val_zero; } @@ -2996,7 +3041,7 @@ static xp_awk_val_t* __eval_binop_le ( xp_awk_run_t* run, xp_awk_val_t* left, xp_awk_val_t* right) { int n = __cmp_val (run, left, right); - if (n == -99) return XP_NULL; + if (n == CMP_ERROR) return XP_NULL; return (n <= 0)? xp_awk_val_one: xp_awk_val_zero; } diff --git a/ase/awk/val.c b/ase/awk/val.c index f5eb14f5..c66821c8 100644 --- a/ase/awk/val.c +++ b/ase/awk/val.c @@ -1,5 +1,5 @@ /* - * $Id: val.c,v 1.65 2006-09-29 11:18:13 bacon Exp $ + * $Id: val.c,v 1.66 2006-10-04 14:51:21 bacon Exp $ */ #include @@ -562,15 +562,23 @@ static xp_char_t* __val_real_to_str ( /* TODO: change the code */ xp_char_t tbuf[256], * tmp; +/* TODO: need to use awk's own version of sprintf so that it would have + * problems with handling long double or double... */ +/* #if (XP_SIZEOF_LONG_DOUBLE != 0) run->awk->syscas->sprintf ( - tbuf, xp_countof(tbuf), XP_T("%.6Lg"), (long double)v->val); + tbuf, xp_countof(tbuf), run->global.ofmt.ptr, (long double)v->val); #elif (XP_SIZEOF_DOUBLE != 0) +*/ +/* TODO: does it need to check if a null character is included in ofmt??? */ run->awk->syscas->sprintf ( - tbuf, xp_countof(tbuf), XP_T("%.6g"), (double)v->val); + tbuf, xp_countof(tbuf), + run->global.ofmt.ptr, (double)v->val); +/* #else #error unsupported floating-point data type #endif +*/ if (buf == XP_NULL) { diff --git a/ase/test/awk/comp.awk b/ase/test/awk/comp.awk index 506f02b3..884a9ebf 100644 --- a/ase/test/awk/comp.awk +++ b/ase/test/awk/comp.awk @@ -41,6 +41,38 @@ BEGIN { print "\" \" > a:", (" " > a); print "\" \" < a:", (" " < a); + print "--------------------------"; + print "10 == \"10\"", (10 == "10"); + print "10 != \"10\"", (10 != "10"); + print "10 >= \"10\"", (10 >= "10"); + print "10 <= \"10\"", (10 <= "10"); + print "10 > \"10\"", (10 > "10"); + print "10 < \"10\"", (10 < "10"); + + print "--------------------------"; + print "10 == \"11\"", (10 == "11"); + print "10 != \"11\"", (10 != "11"); + print "10 >= \"11\"", (10 >= "11"); + print "10 <= \"11\"", (10 <= "11"); + print "10 > \"11\"", (10 > "11"); + print "10 < \"11\"", (10 < "11"); + + print "--------------------------"; + print "11 == \"10\"", (11 == "10"); + print "11 != \"10\"", (11 != "10"); + print "11 >= \"10\"", (11 >= "10"); + print "11 <= \"10\"", (11 <= "10"); + print "11 > \"10\"", (11 > "10"); + print "11 < \"10\"", (11 < "10"); + + print "--------------------------"; + print "10.0 == \"10\"", (10.0 == "10"); + print "10.0 != \"10\"", (10.0 != "10"); + print "10.0 >= \"10\"", (10.0 >= "10"); + print "10.0 <= \"10\"", (10.0 <= "10"); + print "10.0 > \"10\"", (10.0 > "10"); + print "10.0 < \"10\"", (10.0 < "10"); + #a[10] = 2; #print a == 1;