From 9847a900fb95b5c3a0138844395adac466143c52 Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Mon, 4 Dec 2006 12:59:01 +0000 Subject: [PATCH] *** empty log message *** --- ase/awk/awk.c | 22 ++++++++++++++++------ ase/awk/awk.h | 4 +++- ase/awk/awk_i.h | 32 +++++++++++++++++++++++++++++++- ase/awk/parse.c | 14 +++++++++----- ase/awk/run.c | 37 ++++++++++++++++++++++++++++++------- ase/awk/val.c | 4 ++-- ase/awk/val.h | 4 ++-- ase/test/awk/awk.c | 14 +++----------- ase/test/awk/cou-022.awk | 4 ++-- 9 files changed, 98 insertions(+), 37 deletions(-) diff --git a/ase/awk/awk.c b/ase/awk/awk.c index 18233414..10be4087 100644 --- a/ase/awk/awk.c +++ b/ase/awk/awk.c @@ -1,5 +1,5 @@ /* - * $Id: awk.c,v 1.95 2006-11-29 03:18:18 bacon Exp $ + * $Id: awk.c,v 1.96 2006-12-04 12:58:23 bacon Exp $ */ #if defined(__BORLANDC__) @@ -138,6 +138,8 @@ ase_awk_t* ase_awk_open (const ase_awk_syscas_t* syscas) ase_awk_setmaxparsedepth (awk, ASE_AWK_DEPTH_BLOCK, 0); ase_awk_setmaxparsedepth (awk, ASE_AWK_DEPTH_EXPR, 0); + ase_awk_setmaxrundepth (awk, ASE_AWK_DEPTH_BLOCK, 0); + ase_awk_setmaxrundepth (awk, ASE_AWK_DEPTH_EXPR, 0); awk->run.count = 0; awk->run.ptr = ASE_NULL; @@ -174,11 +176,6 @@ int ase_awk_clear (ase_awk_t* awk) return -1; } -/* TOOD: clear bfns when they can be added dynamically - awk->bfn.sys - awk->bfn.user -*/ - ASE_AWK_MEMSET (awk, &awk->src.ios, 0, ASE_SIZEOF(awk->src.ios)); awk->src.lex.curc = ASE_CHAR_EOF; awk->src.lex.ungotc_count = 0; @@ -258,3 +255,16 @@ ase_size_t ase_awk_getsrcline (ase_awk_t* awk) return awk->token.line; } +void ase_awk_setmaxrundepth (ase_awk_t* awk, int types, ase_size_t depth) +{ + if (types & ASE_AWK_DEPTH_BLOCK) + { + awk->run.depth.max.block = depth; + } + + if (types & ASE_AWK_DEPTH_EXPR) + { + awk->run.depth.max.expr = depth; + } +} + diff --git a/ase/awk/awk.h b/ase/awk/awk.h index 6b6397fa..d14b044e 100644 --- a/ase/awk/awk.h +++ b/ase/awk/awk.h @@ -1,5 +1,5 @@ /* - * $Id: awk.h,v 1.159 2006-12-04 06:04:05 bacon Exp $ + * $Id: awk.h,v 1.160 2006-12-04 12:58:23 bacon Exp $ */ #ifndef _ASE_AWK_AWK_H_ @@ -380,6 +380,8 @@ int ase_awk_getopt (ase_awk_t* awk); void ase_awk_setopt (ase_awk_t* awk, int opt); void ase_awk_setmaxparsedepth (ase_awk_t*, int types, ase_size_t depth); +void ase_awk_setmaxrundepth (ase_awk_t*, int types, ase_size_t depth); + int ase_awk_parse (ase_awk_t* awk, ase_awk_srcios_t* srcios); /* diff --git a/ase/awk/awk_i.h b/ase/awk/awk_i.h index 6d8c0f79..222712cb 100644 --- a/ase/awk/awk_i.h +++ b/ase/awk/awk_i.h @@ -1,5 +1,5 @@ /* - * $Id: awk_i.h,v 1.87 2006-11-29 03:18:18 bacon Exp $ + * $Id: awk_i.h,v 1.88 2006-12-04 12:58:23 bacon Exp $ */ #ifndef _ASE_AWK_AWKI_H_ @@ -184,6 +184,21 @@ struct ase_awk_t { ase_size_t count; ase_awk_run_t* ptr; + + struct + { + struct + { + ase_size_t block; + ase_size_t expr; + } cur; + + struct + { + ase_size_t block; + ase_size_t expr; + } max; + } depth; } run; /* housekeeping */ @@ -294,6 +309,21 @@ struct ase_awk_run_t } tmp; } format; + struct + { + struct + { + ase_size_t block; + ase_size_t expr; /* expression */ + } cur; + + struct + { + ase_size_t block; + ase_size_t expr; + } max; + } depth; + int errnum; void* custom_data; ase_awk_t* awk; diff --git a/ase/awk/parse.c b/ase/awk/parse.c index 31787346..8d043807 100644 --- a/ase/awk/parse.c +++ b/ase/awk/parse.c @@ -1,5 +1,5 @@ /* - * $Id: parse.c,v 1.215 2006-12-04 06:04:06 bacon Exp $ + * $Id: parse.c,v 1.216 2006-12-04 12:58:23 bacon Exp $ */ #include @@ -1424,14 +1424,16 @@ static ase_awk_nde_t* __parse_expression0 (ase_awk_t* awk) return ASE_NULL; } - y = __parse_basic_expr (awk); + /*y = __parse_basic_expr (awk);*/ + y = __parse_expression (awk); if (y == ASE_NULL) { ase_awk_clrpt (awk, x); return ASE_NULL; } - nde = (ase_awk_nde_ass_t*) ASE_AWK_MALLOC (awk, ASE_SIZEOF(ase_awk_nde_ass_t)); + nde = (ase_awk_nde_ass_t*) + ASE_AWK_MALLOC (awk, ASE_SIZEOF(ase_awk_nde_ass_t)); if (nde == ASE_NULL) { ase_awk_clrpt (awk, x); @@ -1461,7 +1463,8 @@ static ase_awk_nde_t* __parse_basic_expr (ase_awk_t* awk) if (__get_token(awk) == -1) return ASE_NULL; - n1 = __parse_basic_expr (awk); + /*n1 = __parse_basic_expr (awk);*/ + n1 = __parse_expression (awk); if (n1 == ASE_NULL) { ase_awk_clrpt (awk, nde); @@ -1471,7 +1474,8 @@ static ase_awk_nde_t* __parse_basic_expr (ase_awk_t* awk) if (!MATCH(awk,TOKEN_COLON)) PANIC (awk, ASE_AWK_ECOLON); if (__get_token(awk) == -1) return ASE_NULL; - n2 = __parse_basic_expr (awk); + /*n2 = __parse_basic_expr (awk);*/ + n2 = __parse_expression (awk); if (n2 == ASE_NULL) { ase_awk_clrpt (awk, nde); diff --git a/ase/awk/run.c b/ase/awk/run.c index 50cba9f1..14676b48 100644 --- a/ase/awk/run.c +++ b/ase/awk/run.c @@ -1,5 +1,5 @@ /* - * $Id: run.c,v 1.292 2006-12-04 06:50:26 bacon Exp $ + * $Id: run.c,v 1.293 2006-12-04 12:58:24 bacon Exp $ */ #include @@ -54,8 +54,8 @@ static void __add_run (ase_awk_t* awk, ase_awk_run_t* run); static void __del_run (ase_awk_t* awk, ase_awk_run_t* run); static int __init_run ( - ase_awk_run_t* run, ase_awk_runios_t* runios, - void* custom_data, int* errnum); + ase_awk_run_t* run, ase_awk_t* awk, + ase_awk_runios_t* runios, void* custom_data, int* errnum); static void __deinit_run (ase_awk_run_t* run); static int __build_runarg (ase_awk_run_t* run, ase_awk_runarg_t* runarg); @@ -69,6 +69,7 @@ static int __run_pattern_block_chain ( static int __run_pattern_block ( ase_awk_run_t* run, ase_awk_chain_t* chain, ase_size_t block_no); static int __run_block (ase_awk_run_t* run, ase_awk_nde_blk_t* nde); +static int __run_block0 (ase_awk_run_t* run, ase_awk_nde_blk_t* nde); static int __run_statement (ase_awk_run_t* run, ase_awk_nde_t* nde); static int __run_if (ase_awk_run_t* run, ase_awk_nde_if_t* nde); static int __run_while (ase_awk_run_t* run, ase_awk_nde_while_t* nde); @@ -572,7 +573,7 @@ int ase_awk_run (ase_awk_t* awk, __add_run (awk, run); - if (__init_run (run, runios, custom_data, &errnum) == -1) + if (__init_run (run, awk, runios, custom_data, &errnum) == -1) { awk->errnum = errnum; __del_run (awk, run); @@ -699,8 +700,8 @@ static void __del_run (ase_awk_t* awk, ase_awk_run_t* run) } static int __init_run ( - ase_awk_run_t* run, ase_awk_runios_t* runios, - void* custom_data, int* errnum) + ase_awk_run_t* run, ase_awk_t* awk, + ase_awk_runios_t* runios, void* custom_data, int* errnum) { run->custom_data = custom_data; @@ -800,6 +801,11 @@ static int __init_run ( run->global.fs = ASE_NULL; run->global.ignorecase = 0; + run->depth.max.block = awk->run.depth.max.block; + run->depth.max.expr = awk->run.depth.max.expr; + run->depth.cur.block = 0; + run->depth.cur.expr = 0; + return 0; } @@ -1496,6 +1502,24 @@ static int __run_pattern_block ( } static int __run_block (ase_awk_run_t* run, ase_awk_nde_blk_t* nde) +{ + int n; + + if (run->depth.max.block > 0 && + run->depth.cur.block >= run->depth.max.block) + { + run->errnum = ASE_AWK_ERECURSION; + return -1;; + } + + run->depth.cur.block++; + n = __run_block0 (run, nde); + run->depth.cur.block--; + + return n; +} + +static int __run_block0 (ase_awk_run_t* run, ase_awk_nde_blk_t* nde) { ase_awk_nde_t* p; ase_size_t nlocals; @@ -4159,7 +4183,6 @@ static ase_awk_val_t* __eval_binop_match0 ( PANIC (run, errnum); } -wprintf (L"n=%d, ret=%d\n", n, ret); res = ase_awk_makeintval (run, (n == ret)); if (res == ASE_NULL) { diff --git a/ase/awk/val.c b/ase/awk/val.c index f55bcc6c..33a41bca 100644 --- a/ase/awk/val.c +++ b/ase/awk/val.c @@ -1,5 +1,5 @@ /* - * $Id: val.c,v 1.95 2006-12-02 16:26:03 bacon Exp $ + * $Id: val.c,v 1.96 2006-12-04 12:58:24 bacon Exp $ */ #include @@ -718,7 +718,7 @@ int ase_awk_valtonum ( } int ase_awk_strtonum ( - ase_awk_run_t* run, const ase_awk_str_t* ptr, ase_size_t len, + ase_awk_run_t* run, const ase_char_t* ptr, ase_size_t len, ase_long_t* l, ase_real_t* r) { const ase_char_t* endptr; diff --git a/ase/awk/val.h b/ase/awk/val.h index 5d3d6e13..852470df 100644 --- a/ase/awk/val.h +++ b/ase/awk/val.h @@ -1,5 +1,5 @@ /* - * $Id: val.h,v 1.55 2006-12-02 16:26:03 bacon Exp $ + * $Id: val.h,v 1.56 2006-12-04 12:58:24 bacon Exp $ */ #ifndef _ASE_AWK_VAL_H_ @@ -178,7 +178,7 @@ ase_char_t* ase_awk_valtostr ( int ase_awk_valtonum ( ase_awk_run_t* run, ase_awk_val_t* v, ase_long_t* l, ase_real_t* r); int ase_awk_strtonum ( - ase_awk_run_t* run, const ase_awk_str_t* ptr, ase_size_t len, + ase_awk_run_t* run, const ase_char_t* ptr, ase_size_t len, ase_long_t* l, ase_real_t* r); void ase_awk_dprintval (ase_awk_run_t* run, ase_awk_val_t* val); diff --git a/ase/test/awk/awk.c b/ase/test/awk/awk.c index eca9bfb3..33c5d3f0 100644 --- a/ase/test/awk/awk.c +++ b/ase/test/awk/awk.c @@ -1,5 +1,5 @@ /* - * $Id: awk.c,v 1.134 2006-12-04 06:04:07 bacon Exp $ + * $Id: awk.c,v 1.135 2006-12-04 12:59:00 bacon Exp $ */ #include @@ -730,12 +730,6 @@ static void __awk_free (void* ptr, void* custom_data) #define __awk_tolower towlower #endif -static int __handle_bfn (ase_awk_run_t* run, const ase_char_t* fnm, ase_size_t fnl) -{ - xp_printf (ASE_T("__handle_bfn\n")); - return 0; -} - static int __main (int argc, ase_char_t* argv[]) { ase_awk_t* awk; @@ -851,12 +845,10 @@ static int __main (int argc, ase_char_t* argv[]) srcios.custom_data = &src_io; -ase_awk_addbfn (awk, ASE_T("bufa"), 4, 0, - 1, 1, ASE_NULL, __handle_bfn); - - ase_awk_setmaxparsedepth ( awk, ASE_AWK_DEPTH_BLOCK | ASE_AWK_DEPTH_EXPR, 20); + ase_awk_setmaxrundepth ( + awk, ASE_AWK_DEPTH_BLOCK | ASE_AWK_DEPTH_EXPR, 50); if (ase_awk_parse (awk, &srcios) == -1) { diff --git a/ase/test/awk/cou-022.awk b/ase/test/awk/cou-022.awk index df0e5a32..7767c865 100644 --- a/ase/test/awk/cou-022.awk +++ b/ase/test/awk/cou-022.awk @@ -1,5 +1,5 @@ -BEGIN { FS = "\t"; OFS = "\t"; } -#BEGIN { FS = OFS = "\t"; } +#BEGIN { FS = "\t"; OFS = "\t"; } +BEGIN { FS = OFS = "\t"; } $4 == "North America" { $4 = "NA"; } $4 == "South America" { $4 = "SA"; } { print; }