From 10f51cc5172a15ad9046c732fedeff0d494f4122 Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Mon, 17 Jul 2006 06:21:39 +0000 Subject: [PATCH] *** empty log message *** --- ase/awk/func.c | 4 ++-- ase/awk/rex.c | 46 ++++++++++++++++++++++++++++++++++++++++++ ase/awk/rex.h | 31 ++++++++++++++++++++++++++++ ase/awk/val.c | 48 ++++++++++++++++++++++++++++++++++++++++---- ase/test/awk/t14.awk | 2 +- 5 files changed, 124 insertions(+), 7 deletions(-) create mode 100644 ase/awk/rex.c create mode 100644 ase/awk/rex.h diff --git a/ase/awk/func.c b/ase/awk/func.c index 8f927577..6b557489 100644 --- a/ase/awk/func.c +++ b/ase/awk/func.c @@ -1,5 +1,5 @@ /* - * $Id: func.c,v 1.11 2006-07-17 04:17:40 bacon Exp $ + * $Id: func.c,v 1.12 2006-07-17 06:19:35 bacon Exp $ */ #include @@ -226,7 +226,7 @@ static int __bfn_sin (void* run) if (n == 0) rv = (xp_real_t)lv; - v = xp_awk_makerealval (run, sin(rv)); + v = xp_awk_makerealval (run, (xp_real_t)sin(rv)); if (v == XP_NULL) { xp_awk_seterrnum (run, XP_AWK_ENOMEM); diff --git a/ase/awk/rex.c b/ase/awk/rex.c new file mode 100644 index 00000000..4527c9a4 --- /dev/null +++ b/ase/awk/rex.c @@ -0,0 +1,46 @@ +/* + * $Id: rex.c,v 1.1 2006-07-17 06:21:39 bacon Exp $ + */ + +#include + +#ifndef XP_AWK_STAND_ALONE +#include +#include +#endif + +xp_awk_rex_t* xp_awk_rex_open (xp_awk_rex_t* rex) +{ + if (rex == XP_NULL) + { + rex = (xp_awk_rex_t*) xp_malloc (xp_sizeof(xp_awk_rex_t)); + if (rex == XP_NULL) return XP_NULL; + rex->__dynamic = xp_true; + } + else rex->__dynamic = xp_false; + + return rex; +} + +void xp_awk_rex_close (xp_awk_rex_t* rex) +{ + if (rex->__dynamic) xp_free (rex); +} + +int xp_awk_rex_compile (const xp_awk_rex_t* rex, const xp_char_t* ptn) +{ + const xp_char_t* p = ptn; + xp_char_t c; + + while (*p != XP_T('\0')) + { + c = *p++; // TODO: backspace escaping... + + if (c == XP_T('|')) + { + } + + } + + return -1; +} diff --git a/ase/awk/rex.h b/ase/awk/rex.h new file mode 100644 index 00000000..d722b4fc --- /dev/null +++ b/ase/awk/rex.h @@ -0,0 +1,31 @@ +/* + * $Id: rex.h,v 1.1 2006-07-17 06:21:39 bacon Exp $ + **/ + +#ifndef _XP_AWK_REX_H_ +#define _XP_AWK_REX_H_ + +#ifndef _XP_AWK_AWK_H_ +#error Never include this file directly. Include instead +#endif + +typedef struct xp_awk_rex_t xp_awk_rex_t; + +struct xp_awk_rex_t +{ + xp_bool_t __dynamic; +}; + +#ifdef __cplusplus +extern "C" { +#endif + +xp_awk_rex_t* xp_awk_rex_open (xp_awk_rex_t* rex); +void xp_awk_rex_close (xp_awk_rex_t* rex); +int xp_awk_rex_compile (const xp_awk_rex_t* rex, const xp_char_t* ptn); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/ase/awk/val.c b/ase/awk/val.c index 9c260b61..1fcfd547 100644 --- a/ase/awk/val.c +++ b/ase/awk/val.c @@ -1,5 +1,5 @@ /* - * $Id: val.c,v 1.42 2006-07-17 04:17:40 bacon Exp $ + * $Id: val.c,v 1.43 2006-07-17 06:19:35 bacon Exp $ */ #include @@ -425,10 +425,50 @@ xp_char_t* xp_awk_valtostr ( return tmp; } - /* TODO: if (v->type == XP_AWK_VAL_REAL) { - }*/ + /* TODO: change the code */ + + xp_char_t tbuf[256], * tmp; + + #if (XP_SIZEOF_LONG_DOUBLE != 0) + xp_sprintf ( + tbuf, xp_countof(tbuf), XP_T("%Lf"), + (long double)((xp_awk_val_real_t*)v)->val); + #elif (XP_SIZEOF_DOUBLE != 0) + xp_sprintf ( + tbuf, xp_countof(tbuf), XP_T("%f"), + (double)((xp_awk_val_real_t*)v)->val); + #else + #error Unsupported floating-point data type + #endif + + if (buf == XP_NULL) + { + tmp = xp_strdup (tbuf); + if (tmp == XP_NULL) + { + *errnum = XP_AWK_ENOMEM; + return XP_NULL; + } + + if (len != XP_NULL) *len = xp_strlen(tmp); + } + else + { + xp_str_clear (buf); + if (xp_str_cat (buf, tbuf) == (xp_size_t)-1) + { + *errnum = XP_AWK_ENOMEM; + return XP_NULL; + } + + tmp = XP_STR_BUF(buf); + if (len != XP_NULL) *len = XP_STR_LEN(buf); + } + + return tmp; + } if (v->type == XP_AWK_VAL_STR) { @@ -505,7 +545,7 @@ int xp_awk_valtonum (xp_awk_val_t* v, xp_long_t* l, xp_real_t* r) return 0; /* long */ } -xp_printf (XP_T("*** ERROR: WRONG VALUE TYPE [%d] in xp_awk_valtostr v=> %p***\n"), v->type, v); +xp_printf (XP_T("*** ERROR: WRONG VALUE TYPE [%d] in xp_awk_valtonum v=> %p***\n"), v->type, v); return -1; /* error */ } diff --git a/ase/test/awk/t14.awk b/ase/test/awk/t14.awk index 6b0b7754..bfc92708 100644 --- a/ase/test/awk/t14.awk +++ b/ase/test/awk/t14.awk @@ -22,4 +22,4 @@ global x, y; print "===================="; } -END { system ("dir /w/p"); print sin(10); } +END { system ("dir /w/p"); print sin(90.0); }