From 5754c542db0b88a81c586ad64c0b592f05da1a9f Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Fri, 22 Sep 2006 14:05:30 +0000 Subject: [PATCH] *** empty log message *** --- ase/awk/awk.c | 7 +- ase/awk/awk.h | 10 +- ase/awk/awk_i.h | 25 ++-- ase/awk/extio.c | 12 +- ase/awk/func.c | 10 +- ase/awk/map.c | 6 +- ase/awk/misc.c | 232 +------------------------------------ ase/awk/parse.c | 7 +- ase/awk/rex.c | 4 +- ase/awk/run.c | 168 +++++++++++++-------------- ase/awk/str.c | 3 +- ase/awk/tab.c | 3 +- ase/awk/tree.c | 16 ++- ase/awk/val.c | 12 +- ase/test/awk/awk.c | 181 ++++++++++++++++++++++++++++- ase/test/awk/t47.awk | 19 +++ ase/test/awk/xptestawk.dsp | 2 +- 17 files changed, 335 insertions(+), 382 deletions(-) create mode 100644 ase/test/awk/t47.awk diff --git a/ase/awk/awk.c b/ase/awk/awk.c index 3799363e..1ba41c17 100644 --- a/ase/awk/awk.c +++ b/ase/awk/awk.c @@ -1,14 +1,9 @@ /* - * $Id: awk.c,v 1.76 2006-09-01 04:03:28 bacon Exp $ + * $Id: awk.c,v 1.77 2006-09-22 14:04:25 bacon Exp $ */ #include -#ifndef XP_AWK_STAND_ALONE -#include -#include -#endif - static void __free_afn (void* awk, void* afn); xp_awk_t* xp_awk_open (xp_awk_syscas_t* syscas) diff --git a/ase/awk/awk.h b/ase/awk/awk.h index 30821f4f..b239f151 100644 --- a/ase/awk/awk.h +++ b/ase/awk/awk.h @@ -1,5 +1,5 @@ /* - * $Id: awk.h,v 1.116 2006-09-14 06:40:06 bacon Exp $ + * $Id: awk.h,v 1.117 2006-09-22 14:04:25 bacon Exp $ */ #ifndef _XP_AWK_AWK_H_ @@ -74,6 +74,8 @@ struct xp_awk_syscas_t xp_cint_t (*to_upper) (xp_cint_t c); xp_cint_t (*to_lower) (xp_cint_t c); + int (*sprintf) (xp_char_t* buf, xp_size_t size, xp_char_t* fmt, ...); + void* custom_data; }; @@ -386,12 +388,6 @@ xp_char_t* xp_awk_strxnstr ( const xp_char_t* str, xp_size_t strsz, const xp_char_t* sub, xp_size_t subsz); -int xp_awk_printf (xp_awk_t* awk, const xp_char_t* fmt, ...); - -int xp_awk_sprintf ( - xp_awk_t* awk, xp_char_t* buf, - xp_size_t size, const xp_char_t* fmt, ...); - /* utility functions to convert an error number ot a string */ const xp_char_t* xp_awk_geterrstr (int errnum); diff --git a/ase/awk/awk_i.h b/ase/awk/awk_i.h index dffe7f26..51feab06 100644 --- a/ase/awk/awk_i.h +++ b/ase/awk/awk_i.h @@ -1,5 +1,5 @@ /* - * $Id: awk_i.h,v 1.57 2006-09-09 04:52:40 bacon Exp $ + * $Id: awk_i.h,v 1.58 2006-09-22 14:04:25 bacon Exp $ */ #ifndef _XP_AWK_AWKI_H_ @@ -18,7 +18,6 @@ typedef struct xp_awk_tree_t xp_awk_tree_t; #endif #include - #include #include #define xp_assert assert @@ -28,12 +27,9 @@ typedef struct xp_awk_tree_t xp_awk_tree_t; #define xp_memmove(dst,src,len) memmove(dst,src,len) #define xp_memcmp(src1,src2,len) memcmp(src1,src2,len) #define xp_memzero(dst,len) memset(dst,0,len) - - #define xp_va_start(pvar,param) va_start(pvar,param) - #define xp_va_list va_list - #define xp_va_end(pvar) va_end(pvar) - #define xp_va_arg(pvar,type) va_arg(pvar,type) - +#else + #include + #include #endif #include @@ -247,7 +243,18 @@ struct xp_awk_run_t void* rs; void* fs; int ignorecase; - } rex; + + struct + { + xp_char_t* ptr; + xp_size_t len; + } ofs; + struct + { + xp_char_t* ptr; + xp_size_t len; + } subsep; + } global; /* extio chain */ struct diff --git a/ase/awk/extio.c b/ase/awk/extio.c index 9810fcf4..f1cf8503 100644 --- a/ase/awk/extio.c +++ b/ase/awk/extio.c @@ -1,13 +1,9 @@ /* - * $Id: extio.c,v 1.47 2006-09-10 15:50:34 bacon Exp $ + * $Id: extio.c,v 1.48 2006-09-22 14:04:25 bacon Exp $ */ #include -#ifndef XP_AWK_STAND_ALONE -#include -#endif - enum { __MASK_READ = 0x0100, @@ -287,12 +283,12 @@ int xp_awk_readextio ( const xp_char_t* match_ptr; xp_size_t match_len; - xp_assert (run->rex.rs != XP_NULL); + xp_assert (run->global.rs != XP_NULL); /* TODO: safematchrex */ n = xp_awk_matchrex ( - run->awk, run->rex.rs, - ((run->rex.ignorecase)? XP_AWK_REX_IGNORECASE: 0), + run->awk, run->global.rs, + ((run->global.ignorecase)? XP_AWK_REX_IGNORECASE: 0), XP_AWK_STR_BUF(buf), XP_AWK_STR_LEN(buf), &match_ptr, &match_len, &run->errnum); if (n == -1) diff --git a/ase/awk/func.c b/ase/awk/func.c index 1aec8cea..2836e368 100644 --- a/ase/awk/func.c +++ b/ase/awk/func.c @@ -1,13 +1,9 @@ /* - * $Id: func.c,v 1.52 2006-09-16 12:58:38 bacon Exp $ + * $Id: func.c,v 1.53 2006-09-22 14:04:25 bacon Exp $ */ #include -#ifndef XP_AWK_STAND_ALONE -#include -#endif - #ifdef _WIN32 #include #include @@ -586,7 +582,7 @@ static int __bfn_split (xp_awk_t* awk, void* run) if (fs_len > 1) { - fs_rex = ((xp_awk_run_t*)run)->rex.fs; + fs_rex = ((xp_awk_run_t*)run)->global.fs; fs_rex_free = XP_NULL; } } @@ -938,7 +934,7 @@ static int __substitute (xp_awk_t* awk, void* run, xp_long_t max_count) } } - opt = (((xp_awk_run_t*)run)->rex.ignorecase)? XP_AWK_REX_IGNORECASE: 0; + opt = (((xp_awk_run_t*)run)->global.ignorecase)? XP_AWK_REX_IGNORECASE: 0; cur_ptr = a2_ptr; cur_len = a2_len; sub_count = 0; diff --git a/ase/awk/map.c b/ase/awk/map.c index 56e57aca..788c5d3e 100644 --- a/ase/awk/map.c +++ b/ase/awk/map.c @@ -1,13 +1,9 @@ /* - * $Id: map.c,v 1.24 2006-09-01 07:18:39 bacon Exp $ + * $Id: map.c,v 1.25 2006-09-22 14:04:25 bacon Exp $ */ #include -#ifndef XP_AWK_STAND_ALONE -#include -#endif - /* TODO: improve the entire map routines. support automatic bucket resizing and remaping, etc. */ diff --git a/ase/awk/misc.c b/ase/awk/misc.c index b80c9e44..1e1db7f0 100644 --- a/ase/awk/misc.c +++ b/ase/awk/misc.c @@ -1,22 +1,9 @@ /* - * $Id: misc.c,v 1.20 2006-09-10 16:04:34 bacon Exp $ + * $Id: misc.c,v 1.21 2006-09-22 14:04:25 bacon Exp $ */ #include -#ifndef XP_AWK_STAND_ALONE -#include -#include -#endif - -static int __vprintf ( - xp_awk_t* awk, const xp_char_t* fmt, xp_va_list ap); -static int __vsprintf ( - xp_awk_t* awk, xp_char_t* buf, xp_size_t size, - const xp_char_t* fmt, xp_va_list ap); - -static xp_char_t* __adjust_format (xp_awk_t* awk, const xp_char_t* format); - xp_long_t xp_awk_strtolong ( xp_awk_t* awk, const xp_char_t* str, int base, const xp_char_t** endptr) @@ -622,7 +609,7 @@ xp_char_t* xp_awk_strxntok ( { /* each token is delimited by one of charaters * in the delimeter set "delim". */ - if (run->rex.ignorecase) + if (run->global.ignorecase) { while (p < end) { @@ -657,7 +644,7 @@ xp_char_t* xp_awk_strxntok ( * in the delimeter set "delim". however, all space characters * surrounding the token are removed */ while (p < end && XP_AWK_ISSPACE(run->awk,*p)) p++; - if (run->rex.ignorecase) + if (run->global.ignorecase) { while (p < end) { @@ -730,7 +717,7 @@ xp_char_t* xp_awk_strxntokbyrex ( { n = xp_awk_matchrex ( run->awk, rex, - ((run->rex.ignorecase)? XP_AWK_REX_IGNORECASE: 0), + ((run->global.ignorecase)? XP_AWK_REX_IGNORECASE: 0), ptr, left, (const xp_char_t**)&match_ptr, &match_len, errnum); if (n == -1) return XP_NULL; @@ -809,215 +796,4 @@ exit_loop: } } -int xp_awk_printf (xp_awk_t* awk, const xp_char_t* fmt, ...) -{ - int n; - xp_va_list ap; - - xp_va_start (ap, fmt); - n = __vprintf (awk, fmt, ap); - xp_va_end (ap); - return n; -} - -static int __vprintf (xp_awk_t* awk, const xp_char_t* fmt, xp_va_list ap) -{ - int n; - xp_char_t* nf = __adjust_format (awk, fmt); - if (nf == XP_NULL) return -1; - -#ifdef XP_CHAR_IS_MCHAR - n = vprintf (nf, ap); -#else - n = vwprintf (nf, ap); -#endif - - XP_AWK_FREE (awk, nf); - return n; -} - -int xp_awk_sprintf ( - xp_awk_t* awk, xp_char_t* buf, xp_size_t size, - const xp_char_t* fmt, ...) -{ - int n; - xp_va_list ap; - - xp_va_start (ap, fmt); - n = __vsprintf (awk, buf, size, fmt, ap); - xp_va_end (ap); - return n; -} - -static int __vsprintf ( - xp_awk_t* awk, xp_char_t* buf, xp_size_t size, - const xp_char_t* fmt, xp_va_list ap) -{ - int n; - xp_char_t* nf = __adjust_format (awk, fmt); - if (nf == XP_NULL) return -1; - -#if defined(dos) || defined(__dos) - n = vsprintf (buf, nf, ap); /* TODO: write your own vsnprintf */ -#elif defined(XP_CHAR_IS_MCHAR) - n = vsnprintf (buf, size, nf, ap); -#elif defined(_WIN32) - n = _vsnwprintf (buf, size, nf, ap); -#else - n = vswprintf (buf, size, nf, ap); -#endif - XP_AWK_FREE (awk, nf); - return n; -} - -#define MOD_SHORT 1 -#define MOD_LONG 2 -#define MOD_LONGLONG 3 - -#define ADDC(str,c) \ - do { \ - if (xp_awk_str_ccat(&str, c) == (xp_size_t)-1) { \ - xp_awk_str_close (&str); \ - return XP_NULL; \ - } \ - } while (0) - -static xp_char_t* __adjust_format (xp_awk_t* awk, const xp_char_t* format) -{ - const xp_char_t* fp = format; - xp_char_t* tmp; - xp_awk_str_t str; - xp_char_t ch; - int modifier; - - if (xp_awk_str_open (&str, 256, awk) == XP_NULL) return XP_NULL; - - while (*fp != XP_T('\0')) - { - while (*fp != XP_T('\0') && *fp != XP_T('%')) - { - ADDC (str, *fp++); - } - - if (*fp == XP_T('\0')) break; - xp_assert (*fp == XP_T('%')); - - ch = *fp++; - ADDC (str, ch); /* add % */ - - ch = *fp++; - - /* flags */ - for (;;) - { - if (ch == XP_T(' ') || ch == XP_T('+') || - ch == XP_T('-') || ch == XP_T('#')) - { - ADDC (str, ch); - } - else if (ch == XP_T('0')) - { - ADDC (str, ch); - ch = *fp++; - break; - } - else break; - - ch = *fp++; - } - - /* check the width */ - if (ch == XP_T('*')) ADDC (str, ch); - else - { - while (XP_AWK_ISDIGIT (awk, ch)) - { - ADDC (str, ch); - ch = *fp++; - } - } - - /* precision */ - if (ch == XP_T('.')) - { - ADDC (str, ch); - ch = *fp++; - - if (ch == XP_T('*')) ADDC (str, ch); - else - { - while (XP_AWK_ISDIGIT (awk, ch)) - { - ADDC (str, ch); - ch = *fp++; - } - } - } - - /* modifier */ - for (modifier = 0;;) - { - if (ch == XP_T('h')) modifier = MOD_SHORT; - else if (ch == XP_T('l')) - { - modifier = (modifier == MOD_LONG)? MOD_LONGLONG: MOD_LONG; - } - else break; - ch = *fp++; - } - - - /* type */ - if (ch == XP_T('%')) ADDC (str, ch); - else if (ch == XP_T('c') || ch == XP_T('s')) - { -#if !defined(XP_CHAR_IS_MCHAR) && !defined(_WIN32) - ADDC (str, 'l'); -#endif - ADDC (str, ch); - } - else if (ch == XP_T('C') || ch == XP_T('S')) - { -#ifdef _WIN32 - ADDC (str, ch); -#else - #ifdef XP_CHAR_IS_MCHAR - ADDC (str, 'l'); - #endif - ADDC (str, XP_AWK_TOLOWER(awk,ch)); -#endif - } - else if (ch == XP_T('d') || ch == XP_T('i') || - ch == XP_T('o') || ch == XP_T('u') || - ch == XP_T('x') || ch == XP_T('X')) - { - if (modifier == MOD_SHORT) - { - ADDC (str, 'h'); - } - else if (modifier == MOD_LONG) - { - ADDC (str, 'l'); - } - else if (modifier == MOD_LONGLONG) - { -#if defined(_WIN32) && !defined(__LCC__) - ADDC (str, 'I'); - ADDC (str, '6'); - ADDC (str, '4'); -#else - ADDC (str, 'l'); - ADDC (str, 'l'); -#endif - } - ADDC (str, ch); - } - else if (ch == XP_T('\0')) break; - else ADDC (str, ch); - } - - tmp = XP_AWK_STR_BUF(&str); - xp_awk_str_forfeit (&str); - return tmp; -} diff --git a/ase/awk/parse.c b/ase/awk/parse.c index 16c607fa..a7419162 100644 --- a/ase/awk/parse.c +++ b/ase/awk/parse.c @@ -1,14 +1,9 @@ /* - * $Id: parse.c,v 1.180 2006-09-11 14:29:22 bacon Exp $ + * $Id: parse.c,v 1.181 2006-09-22 14:04:25 bacon Exp $ */ #include -#ifndef XP_AWK_STAND_ALONE -#include -#include -#endif - enum { TOKEN_EOF, diff --git a/ase/awk/rex.c b/ase/awk/rex.c index f2b7ec26..0191b334 100644 --- a/ase/awk/rex.c +++ b/ase/awk/rex.c @@ -1,13 +1,11 @@ /* - * $Id: rex.c,v 1.29 2006-09-10 15:50:34 bacon Exp $ + * $Id: rex.c,v 1.30 2006-09-22 14:04:26 bacon Exp $ */ #include #ifndef XP_AWK_STAND_ALONE -#include #include -#include #endif diff --git a/ase/awk/run.c b/ase/awk/run.c index cf3da02c..59715520 100644 --- a/ase/awk/run.c +++ b/ase/awk/run.c @@ -1,5 +1,5 @@ /* - * $Id: run.c,v 1.203 2006-09-13 14:16:13 bacon Exp $ + * $Id: run.c,v 1.204 2006-09-22 14:04:26 bacon Exp $ */ #include @@ -9,7 +9,6 @@ #ifndef XP_AWK_STAND_ALONE #include -#include #endif #define DEF_BUF_CAPA 256 @@ -41,6 +40,9 @@ enum #define PANIC_I(run,code) \ do { (run)->errnum = (code); return -1; } while (0) +#define DEFAULT_OFS XP_T(" ") +#define DEFAULT_SUBSEP XP_T("\034") + static void __add_run (xp_awk_t* awk, xp_awk_run_t* run); static void __del_run (xp_awk_t* awk, xp_awk_run_t* run); @@ -272,13 +274,13 @@ int xp_awk_setglobal (void* run, xp_size_t idx, xp_awk_val_t* val) return -1; } - if (r->rex.rs != XP_NULL) + if (r->global.rs != XP_NULL) { xp_awk_freerex ( ((xp_awk_run_t*)run)->awk, - r->rex.rs); + r->global.rs); } - r->rex.rs = rex; + r->global.rs = rex; } if (val->type != XP_AWK_VAL_STR) @@ -321,13 +323,13 @@ int xp_awk_setglobal (void* run, xp_size_t idx, xp_awk_val_t* val) return -1; } - if (r->rex.fs != XP_NULL) + if (r->global.fs != XP_NULL) { xp_awk_freerex ( ((xp_awk_run_t*)run)->awk, - r->rex.fs); + r->global.fs); } - r->rex.fs = rex; + r->global.fs = rex; } if (val->type != XP_AWK_VAL_STR) @@ -342,11 +344,11 @@ int xp_awk_setglobal (void* run, xp_size_t idx, xp_awk_val_t* val) (val->type == XP_AWK_VAL_STR && ((xp_awk_val_str_t*)val)->len == 0)) { - ((xp_awk_run_t*)run)->rex.ignorecase = 0; + ((xp_awk_run_t*)run)->global.ignorecase = 0; } else { - ((xp_awk_run_t*)run)->rex.ignorecase = 1; + ((xp_awk_run_t*)run)->global.ignorecase = 1; } } else if (idx == XP_AWK_GLOBAL_NF) @@ -355,7 +357,6 @@ int xp_awk_setglobal (void* run, xp_size_t idx, xp_awk_val_t* val) xp_long_t lv; xp_real_t rv; - /* TODO: need to recompute $0, etc */ n = xp_awk_valtonum (run, val, &lv, &rv); if (n == -1) return -1; if (n == 1) lv = (xp_long_t)rv; @@ -365,9 +366,33 @@ int xp_awk_setglobal (void* run, xp_size_t idx, xp_awk_val_t* val) if (__shorten_record (r, (xp_size_t)lv) == -1) return -1; } } + else if (idx == XP_AWK_GLOBAL_OFS) + { + xp_char_t* ofs_ptr; + xp_size_t ofs_len; - xp_awk_refdownval (run, old); - STACK_GLOBAL((xp_awk_run_t*)run,idx) = val; + ofs_ptr = xp_awk_valtostr ( + run, val, xp_true, XP_NULL, &ofs_len); + if (ofs_ptr == XP_NULL) return -1; + + r->global.ofs.ptr = ofs_ptr; + r->global.ofs.len = ofs_len; + } + else if (idx == XP_AWK_GLOBAL_SUBSEP) + { + xp_char_t* subsep_ptr; + xp_size_t subsep_len; + + subsep_ptr = xp_awk_valtostr ( + run, val, xp_true, XP_NULL, &subsep_len); + if (subsep_ptr == XP_NULL) return -1; + + r->global.subsep.ptr = subsep_ptr; + r->global.subsep.len = subsep_len; + } + + xp_awk_refdownval (r, old); + STACK_GLOBAL(r,idx) = val; xp_awk_refupval (val); return 0; @@ -615,9 +640,13 @@ static int __init_run ( run->extio.handler[XP_AWK_EXTIO_CONSOLE] = runios->console; run->extio.chain = XP_NULL; - run->rex.rs = XP_NULL; - run->rex.fs = XP_NULL; - run->rex.ignorecase = 0; + run->global.rs = XP_NULL; + run->global.fs = XP_NULL; + run->global.ignorecase = 0; + run->global.ofs.ptr = DEFAULT_OFS; + run->global.ofs.len = xp_awk_strlen(DEFAULT_OFS); + run->global.subsep.ptr = DEFAULT_SUBSEP; + run->global.subsep.len = xp_awk_strlen(DEFAULT_SUBSEP); return 0; } @@ -631,15 +660,31 @@ static void __deinit_run (xp_awk_run_t* run) xp_awk_clearextio (run); xp_assert (run->extio.chain == XP_NULL); - if (run->rex.rs != XP_NULL) + if (run->global.rs != XP_NULL) { - XP_AWK_FREE (run->awk, run->rex.rs); - run->rex.rs = XP_NULL; + XP_AWK_FREE (run->awk, run->global.rs); + run->global.rs = XP_NULL; } - if (run->rex.fs != XP_NULL) + if (run->global.fs != XP_NULL) { - XP_AWK_FREE (run->awk, run->rex.fs); - run->rex.fs = XP_NULL; + XP_AWK_FREE (run->awk, run->global.fs); + run->global.fs = XP_NULL; + } + + if (run->global.ofs.ptr != XP_NULL && + run->global.ofs.ptr != DEFAULT_SUBSEP) + { + XP_AWK_FREE (run->awk, run->global.ofs.ptr); + run->global.ofs.ptr = XP_NULL; + run->global.ofs.len = 0; + } + + if (run->global.subsep.ptr != XP_NULL && + run->global.subsep.ptr != DEFAULT_SUBSEP) + { + XP_AWK_FREE (run->awk, run->global.subsep.ptr); + run->global.subsep.ptr = XP_NULL; + run->global.subsep.len = 0; } /* destroy input record. __clear_record should be called @@ -1947,7 +1992,7 @@ static xp_awk_val_t* __eval_expression (xp_awk_run_t* run, xp_awk_nde_t* nde) n = xp_awk_matchrex ( ((xp_awk_run_t*)run)->awk, ((xp_awk_val_rex_t*)v)->code, - ((((xp_awk_run_t*)run)->rex.ignorecase)? XP_AWK_REX_IGNORECASE: 0), + ((((xp_awk_run_t*)run)->global.ignorecase)? XP_AWK_REX_IGNORECASE: 0), ((xp_awk_val_str_t*)run->inrec.d0)->buf, ((xp_awk_val_str_t*)run->inrec.d0)->len, XP_NULL, XP_NULL, &errnum); @@ -2778,7 +2823,7 @@ static xp_awk_val_t* __eval_binop_eq ( else if (left->type == XP_AWK_VAL_STR && right->type == XP_AWK_VAL_STR) { - if (run->rex.ignorecase) + if (run->global.ignorecase) { r = xp_awk_strxncasecmp ( run->awk, @@ -2845,7 +2890,7 @@ static xp_awk_val_t* __eval_binop_ne ( else if (left->type == XP_AWK_VAL_STR && right->type == XP_AWK_VAL_STR) { - if (run->rex.ignorecase) + if (run->global.ignorecase) { r = xp_awk_strxncasecmp ( run->awk, @@ -2906,7 +2951,7 @@ static xp_awk_val_t* __eval_binop_gt ( else if (left->type == XP_AWK_VAL_STR && right->type == XP_AWK_VAL_STR) { - if (run->rex.ignorecase) + if (run->global.ignorecase) { r = xp_awk_strxncasecmp ( run->awk, @@ -2967,7 +3012,7 @@ static xp_awk_val_t* __eval_binop_ge ( else if (left->type == XP_AWK_VAL_STR && right->type == XP_AWK_VAL_STR) { - if (run->rex.ignorecase) + if (run->global.ignorecase) { r = xp_awk_strxncasecmp ( run->awk, @@ -3028,7 +3073,7 @@ static xp_awk_val_t* __eval_binop_lt ( else if (left->type == XP_AWK_VAL_STR && right->type == XP_AWK_VAL_STR) { - if (run->rex.ignorecase) + if (run->global.ignorecase) { r = xp_awk_strxncasecmp ( run->awk, @@ -3089,7 +3134,7 @@ static xp_awk_val_t* __eval_binop_le ( else if (left->type == XP_AWK_VAL_STR && right->type == XP_AWK_VAL_STR) { - if (run->rex.ignorecase) + if (run->global.ignorecase) { r = xp_awk_strxncasecmp ( run->awk, @@ -3486,7 +3531,7 @@ static xp_awk_val_t* __eval_binop_match0 ( { n = xp_awk_matchrex ( run->awk, rex_code, - ((run->rex.ignorecase)? XP_AWK_REX_IGNORECASE: 0), + ((run->global.ignorecase)? XP_AWK_REX_IGNORECASE: 0), ((xp_awk_val_str_t*)left)->buf, ((xp_awk_val_str_t*)left)->len, XP_NULL, XP_NULL, &errnum); @@ -3517,7 +3562,7 @@ static xp_awk_val_t* __eval_binop_match0 ( n = xp_awk_matchrex ( run->awk, rex_code, - ((run->rex.ignorecase)? XP_AWK_REX_IGNORECASE: 0), + ((run->global.ignorecase)? XP_AWK_REX_IGNORECASE: 0), str, len, XP_NULL, XP_NULL, &errnum); if (n == -1) { @@ -4908,7 +4953,7 @@ static int __split_record (xp_awk_run_t* run) else { p = xp_awk_strxntokbyrex (run, p, len, - run->rex.fs, &tok, &tok_len, &errnum); + run->global.fs, &tok, &tok_len, &errnum); if (p == XP_NULL && errnum != XP_AWK_ENOERR) { if (fs_free != XP_NULL) @@ -4963,7 +5008,7 @@ static int __split_record (xp_awk_run_t* run) else { p = xp_awk_strxntokbyrex (run, p, len, - run->rex.fs, &tok, &tok_len, &errnum); + run->global.fs, &tok, &tok_len, &errnum); if (p == XP_NULL && errnum != XP_AWK_ENOERR) { if (fs_free != XP_NULL) @@ -5042,8 +5087,6 @@ static int __recomp_record_fields ( xp_awk_run_t* run, xp_size_t lv, xp_char_t* str, xp_size_t len) { xp_awk_val_t* v; - xp_char_t* ofs_free = XP_NULL, * ofs; - xp_size_t ofs_len; xp_size_t max, i, nflds; /* recomposes the record and the fields when $N has been assigned @@ -5097,45 +5140,15 @@ static int __recomp_record_fields ( xp_awk_str_clear (&run->inrec.line); - if (max > 1) - { - /* gets the value of OFS to use it as a field separator */ - - v = STACK_GLOBAL(run, XP_AWK_GLOBAL_OFS); - xp_awk_refupval (v); - - if (v->type == XP_AWK_VAL_NIL) - { - /* OFS not set */ - ofs = XP_T(" "); - ofs_len = 1; - } - else if (v->type == XP_AWK_VAL_STR) - { - ofs = ((xp_awk_val_str_t*)v)->buf; - ofs_len = ((xp_awk_val_str_t*)v)->len; - } - else - { - ofs = xp_awk_valtostr ( - run, v, xp_true, XP_NULL, &ofs_len); - if (ofs == XP_NULL) return -1; - - ofs_free = ofs; - } - } - for (i = 0; i < max; i++) { if (i > 0) { if (xp_awk_str_ncat ( &run->inrec.line, - ofs, ofs_len) == (xp_size_t)-1) + run->global.ofs.ptr, + run->global.ofs.len) == (xp_size_t)-1) { - if (ofs_free != XP_NULL) - XP_AWK_FREE (run->awk, ofs_free); - if (max > 1) xp_awk_refdownval (run, v); run->errnum = XP_AWK_ENOMEM; return -1; } @@ -5153,9 +5166,6 @@ static int __recomp_record_fields ( if (xp_awk_str_ncat ( &run->inrec.line, str, len) == (xp_size_t)-1) { - if (ofs_free != XP_NULL) - XP_AWK_FREE (run->awk, ofs_free); - if (max > 1) xp_awk_refdownval (run, v); run->errnum = XP_AWK_ENOMEM; return -1; } @@ -5163,9 +5173,6 @@ static int __recomp_record_fields ( tmp = xp_awk_makestrval (run, str,len); if (tmp == XP_NULL) { - if (ofs_free != XP_NULL) - XP_AWK_FREE (run->awk, ofs_free); - if (max > 1) xp_awk_refdownval (run, v); run->errnum = XP_AWK_ENOMEM; return -1; } @@ -5187,9 +5194,6 @@ static int __recomp_record_fields ( if (xp_awk_str_cat ( &run->inrec.line, XP_T("")) == (xp_size_t)-1) { - if (ofs_free != XP_NULL) - XP_AWK_FREE (run->awk, ofs_free); - if (max > 1) xp_awk_refdownval (run, v); run->errnum = XP_AWK_ENOMEM; return -1; } @@ -5216,18 +5220,12 @@ static int __recomp_record_fields ( if (xp_awk_str_ncat (&run->inrec.line, tmp->buf, tmp->len) == (xp_size_t)-1) { - if (ofs_free != XP_NULL) - XP_AWK_FREE (run->awk, ofs_free); - if (max > 1) xp_awk_refdownval (run, v); run->errnum = XP_AWK_ENOMEM; return -1; } } } - if (ofs_free != XP_NULL) XP_AWK_FREE (run->awk, ofs_free); - if (max > 1) xp_awk_refdownval (run, v); - v = STACK_GLOBAL(run, XP_AWK_GLOBAL_NF); xp_assert (v->type == XP_AWK_VAL_INT); if (((xp_awk_val_int_t*)v)->val != max) @@ -5385,9 +5383,10 @@ static xp_char_t* __idxnde_to_str ( xp_awk_refupval (idx); -/* TODO: configurable index seperator, not just a comma */ if (XP_AWK_STR_LEN(&idxstr) > 0 && - xp_awk_str_cat (&idxstr, XP_T(",")) == (xp_size_t)-1) + xp_awk_str_ncat (&idxstr, + run->global.subsep.ptr, + run->global.subsep.len) == (xp_size_t)-1) { xp_awk_refdownval (run, idx); xp_awk_str_close (&idxstr); @@ -5413,4 +5412,3 @@ static xp_char_t* __idxnde_to_str ( return str; } - diff --git a/ase/awk/str.c b/ase/awk/str.c index d47c7e74..9a837e57 100644 --- a/ase/awk/str.c +++ b/ase/awk/str.c @@ -1,11 +1,10 @@ /* - * $Id: str.c,v 1.4 2006-09-10 15:50:34 bacon Exp $ + * $Id: str.c,v 1.5 2006-09-22 14:04:26 bacon Exp $ */ #include #ifndef XP_AWK_STAND_ALONE -#include #include #endif diff --git a/ase/awk/tab.c b/ase/awk/tab.c index cd9142b4..c3a33cc2 100644 --- a/ase/awk/tab.c +++ b/ase/awk/tab.c @@ -1,11 +1,10 @@ /* - * $Id: tab.c,v 1.16 2006-09-01 07:18:40 bacon Exp $ + * $Id: tab.c,v 1.17 2006-09-22 14:04:26 bacon Exp $ */ #include #ifndef XP_AWK_STAND_ALONE -#include #include #endif diff --git a/ase/awk/tree.c b/ase/awk/tree.c index 7154c79b..bd9714d6 100644 --- a/ase/awk/tree.c +++ b/ase/awk/tree.c @@ -1,13 +1,11 @@ /* - * $Id: tree.c,v 1.74 2006-09-11 14:29:22 bacon Exp $ + * $Id: tree.c,v 1.75 2006-09-22 14:04:26 bacon Exp $ */ #include #ifndef XP_AWK_STAND_ALONE -#include #include -#include #endif static const xp_char_t* __assop_str[] = @@ -242,9 +240,17 @@ static int __print_expression (xp_awk_t* awk, xp_awk_nde_t* nde) case XP_AWK_NDE_REAL: { xp_char_t tmp[128]; - xp_awk_sprintf ( - awk, tmp, xp_countof(tmp), XP_T("%Lf"), + #if (XP_SIZEOF_LONG_DOUBLE != 0) + awk->syscas->sprintf ( + tmp, xp_countof(tmp), XP_T("%Lf"), (long double)((xp_awk_nde_real_t*)nde)->val); + #elif (XP_SIZEOF_DOUBLE != 0) + awk->syscas->sprintf ( + tmp, xp_countof(tmp), XP_T("%f"), + (double)((xp_awk_nde_real_t*)nde)->val); + #else + #error unsupported floating-point data type + #endif PUT_SRCSTR (awk, tmp); break; } diff --git a/ase/awk/val.c b/ase/awk/val.c index 2df13d3b..1149afca 100644 --- a/ase/awk/val.c +++ b/ase/awk/val.c @@ -1,13 +1,11 @@ /* - * $Id: val.c,v 1.59 2006-09-01 07:18:40 bacon Exp $ + * $Id: val.c,v 1.60 2006-09-22 14:04:26 bacon Exp $ */ #include #ifndef XP_AWK_STAND_ALONE -#include #include -#include #endif static xp_awk_val_nil_t __awk_nil = { XP_AWK_VAL_NIL, 0 }; @@ -491,12 +489,12 @@ xp_char_t* xp_awk_valtostr ( xp_char_t tbuf[256], * tmp; #if (XP_SIZEOF_LONG_DOUBLE != 0) - xp_awk_sprintf ( - run->awk, tbuf, xp_countof(tbuf), XP_T("%Lf"), + run->awk->syscas->sprintf ( + tbuf, xp_countof(tbuf), XP_T("%Lf"), (long double)((xp_awk_val_real_t*)v)->val); #elif (XP_SIZEOF_DOUBLE != 0) - xp_awk_sprintf ( - run->awk, tbuf, xp_countof(tbuf), XP_T("%f"), + run->awk->syscas->sprintf ( + tbuf, xp_countof(tbuf), XP_T("%f"), (double)((xp_awk_val_real_t*)v)->val); #else #error unsupported floating-point data type diff --git a/ase/test/awk/awk.c b/ase/test/awk/awk.c index ab22ad4c..5abc77d3 100644 --- a/ase/test/awk/awk.c +++ b/ase/test/awk/awk.c @@ -1,8 +1,9 @@ /* - * $Id: awk.c,v 1.89 2006-09-08 14:51:15 bacon Exp $ + * $Id: awk.c,v 1.90 2006-09-22 14:05:30 bacon Exp $ */ #include +#include #include #include #include @@ -670,6 +671,7 @@ static int __main (int argc, xp_char_t* argv[]) syscas.to_upper = towupper; syscas.to_lower = towlower; #endif + syscas.sprintf = xp_sprintf; #ifdef _WIN32 syscas_data.heap = HeapCreate (0, 1000000, 1000000); @@ -754,6 +756,170 @@ static int __main (int argc, xp_char_t* argv[]) return 0; } +#ifdef _WIN32 +/* +NTSYSAPI PTEB NTAPI NtCurrentTeb(); +Function NtCurrentTeb returns address of TEB (Thread Environment Block) for calling thread. +NtCurrentTeb isn't typical NT CALL realised via INT 2E, becouse TEB is accessable at address fs:[0018h]. +Microsoft declare NtCurrentTeb as __cdecl, but ntdll.dll export it as __stdcall (it don't have metter, becouse function don't have any parameters), so you cannot use ntdll.dll export. In this case the better way is write NtCurrentTeb manually, declaring it as __cdecl. + +typedef UCHAR BOOLEAN; + +typedef struct _TEB { + + NT_TIB Tib; + PVOID EnvironmentPointer; + CLIENT_ID Cid; + PVOID ActiveRpcInfo; + PVOID ThreadLocalStoragePointer; + PPEB Peb; + ULONG LastErrorValue; + ULONG CountOfOwnedCriticalSections; + PVOID CsrClientThread; + PVOID Win32ThreadInfo; + ULONG Win32ClientInfo[0x1F]; + PVOID WOW32Reserved; + ULONG CurrentLocale; + ULONG FpSoftwareStatusRegister; + PVOID SystemReserved1[0x36]; + PVOID Spare1; + ULONG ExceptionCode; + ULONG SpareBytes1[0x28]; + PVOID SystemReserved2[0xA]; + ULONG GdiRgn; + ULONG GdiPen; + ULONG GdiBrush; + CLIENT_ID RealClientId; + PVOID GdiCachedProcessHandle; + ULONG GdiClientPID; + ULONG GdiClientTID; + PVOID GdiThreadLocaleInfo; + PVOID UserReserved[5]; + PVOID GlDispatchTable[0x118]; + ULONG GlReserved1[0x1A]; + PVOID GlReserved2; + PVOID GlSectionInfo; + PVOID GlSection; + PVOID GlTable; + PVOID GlCurrentRC; + PVOID GlContext; + NTSTATUS LastStatusValue; + UNICODE_STRING StaticUnicodeString; + WCHAR StaticUnicodeBuffer[0x105]; + PVOID DeallocationStack; + PVOID TlsSlots[0x40]; + LIST_ENTRY TlsLinks; + PVOID Vdm; + PVOID ReservedForNtRpc; + PVOID DbgSsReserved[0x2]; + ULONG HardErrorDisabled; + PVOID Instrumentation[0x10]; + PVOID WinSockData; + ULONG GdiBatchCount; + ULONG Spare2; + ULONG Spare3; + ULONG Spare4; + PVOID ReservedForOle; + ULONG WaitingOnLoaderLock; + PVOID StackCommit; + PVOID StackCommitMax; + PVOID StackReserved; + +} TEB, *PTEB; + +typedef struct _PEB { + BOOLEAN InheritedAddressSpace; + BOOLEAN ReadImageFileExecOptions; + BOOLEAN BeingDebugged; + BOOLEAN Spare; + HANDLE Mutant; + PVOID ImageBaseAddress; + PPEB_LDR_DATA LoaderData; + PRTL_USER_PROCESS_PARAMETERS ProcessParameters; + PVOID SubSystemData; + PVOID ProcessHeap; + PVOID FastPebLock; + PPEBLOCKROUTINE FastPebLockRoutine; + PPEBLOCKROUTINE FastPebUnlockRoutine; + ULONG EnvironmentUpdateCount; + PPVOID KernelCallbackTable; + PVOID EventLogSection; + PVOID EventLog; + PPEB_FREE_BLOCK FreeList; + ULONG TlsExpansionCounter; + PVOID TlsBitmap; + ULONG TlsBitmapBits[0x2]; + PVOID ReadOnlySharedMemoryBase; + PVOID ReadOnlySharedMemoryHeap; + PPVOID ReadOnlyStaticServerData; + PVOID AnsiCodePageData; + PVOID OemCodePageData; + PVOID UnicodeCaseTableData; + ULONG NumberOfProcessors; + ULONG NtGlobalFlag; + BYTE Spare2[0x4]; + LARGE_INTEGER CriticalSectionTimeout; + ULONG HeapSegmentReserve; + ULONG HeapSegmentCommit; + ULONG HeapDeCommitTotalFreeThreshold; + ULONG HeapDeCommitFreeBlockThreshold; + ULONG NumberOfHeaps; + ULONG MaximumNumberOfHeaps; + PPVOID *ProcessHeaps; + PVOID GdiSharedHandleTable; + PVOID ProcessStarterHelper; + PVOID GdiDCAttributeList; + PVOID LoaderLock; + ULONG OSMajorVersion; + ULONG OSMinorVersion; + ULONG OSBuildNumber; + ULONG OSPlatformId; + ULONG ImageSubSystem; + ULONG ImageSubSystemMajorVersion; + ULONG ImageSubSystemMinorVersion; + ULONG GdiHandleBuffer[0x22]; + ULONG PostProcessInitRoutine; + ULONG TlsExpansionBitmap; + BYTE TlsExpansionBitmapBits[0x80]; + ULONG SessionId; + +} PEB, *PPEB; + + +*/ +void* get_current_teb () +{ + _asm + { + mov eax, fs:[0x18] + } +} + +void* get_current_peb () +{ + void* teb = get_current_teb (); + return *(void**)((char*)teb + 0x30); +} + +int is_debugger_present () +{ + void *peb = get_current_peb (); + return *((char*)peb+0x02); +} + + +int is_debugger_present2 () +{ + _asm + { + mov eax, fs:[0x18] + mov ebx, [eax+0x30] + xor eax, eax + mov al, byte ptr[ebx+0x02] + } +} +#endif + #if defined(__STAND_ALONE) && !defined(_WIN32) int main (int argc, char* argv[]) #else @@ -779,6 +945,19 @@ if (n == (xp_size_t)-1) } else xp_printf (XP_T("%d, %s\n"), n, buf); } + + if (IsDebuggerPresent ()) + { + xp_printf (XP_T("Running application in a debugger....\n")); + } + if (is_debugger_present ()) + { + xp_printf (XP_T("Running application in a debugger by is_debugger_present...\n")); + } + if (is_debugger_present2 ()) + { + xp_printf (XP_T("Running application in a debugger by is_debugger_present2...\n")); + } #endif n = __main (argc, argv); diff --git a/ase/test/awk/t47.awk b/ase/test/awk/t47.awk new file mode 100644 index 00000000..943d9f61 --- /dev/null +++ b/ase/test/awk/t47.awk @@ -0,0 +1,19 @@ +BEGIN { + + a[1] = 20; + a[2] = 40; + a[3,5,6] = 40; + a["abc"] = 20; + + for (i in a) print "a[" i "]=" a[i]; + #SUBSEP=",,,"; + #SUBSEP=4.5; + SUBSEP=555; + + print "------------------------"; + + a[9,x,3] = 40; + for (i in a) print "a[" i "]=" a[i]; +} + + diff --git a/ase/test/awk/xptestawk.dsp b/ase/test/awk/xptestawk.dsp index 62d1034f..12616d93 100644 --- a/ase/test/awk/xptestawk.dsp +++ b/ase/test/awk/xptestawk.dsp @@ -66,7 +66,7 @@ LINK32=link.exe # PROP Ignore_Export_Lib 0 # PROP Target_Dir "" # ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c -# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "..\..\.." /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_UNICODE" /D "__STAND_ALONE" /FR /YX /FD /GZ /c +# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "..\..\.." /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_UNICODE" /D _WIN32_WINNT=0x0400 /D "__STAND_ALONE" /FR /YX /FD /GZ /c # ADD BASE RSC /l 0x409 /d "_DEBUG" # ADD RSC /l 0x409 /d "_DEBUG" BSC32=bscmake.exe