From 4b33fba56ffa7b8f9d3a6f764bf63268bed27b4a Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Fri, 17 Nov 2006 07:06:53 +0000 Subject: [PATCH] *** empty log message *** --- ase/awk/awk_i.h | 8 ++++---- ase/awk/parse.c | 7 ++++++- ase/awk/run.c | 35 ++++++++++++++++++++++++++--------- ase/awk/tree.c | 29 +++++++++++++++++++++++++++-- ase/awk/val.c | 3 ++- ase/test/awk/emp-021.awk | 2 ++ ase/test/awk/emp-022.awk | 2 ++ ase/test/awk/emp-023.awk | 1 + ase/test/awk/emp-024.awk | 4 ++++ ase/test/awk/emp.data | 6 ++++++ 10 files changed, 80 insertions(+), 17 deletions(-) create mode 100644 ase/test/awk/emp-021.awk create mode 100644 ase/test/awk/emp-022.awk create mode 100644 ase/test/awk/emp-023.awk create mode 100644 ase/test/awk/emp-024.awk create mode 100644 ase/test/awk/emp.data diff --git a/ase/awk/awk_i.h b/ase/awk/awk_i.h index d38d300f..f5ea246d 100644 --- a/ase/awk/awk_i.h +++ b/ase/awk/awk_i.h @@ -1,5 +1,5 @@ /* - * $Id: awk_i.h,v 1.80 2006-11-16 15:16:24 bacon Exp $ + * $Id: awk_i.h,v 1.81 2006-11-17 07:04:31 bacon Exp $ */ #ifndef _ASE_AWK_AWKI_H_ @@ -195,9 +195,9 @@ struct ase_awk_run_t ase_size_t stack_limit; int exit_level; - ase_awk_val_int_t* icache[100]; /* TODO: choose the optimal size */ - ase_awk_val_real_t* rcache[100]; /* TODO: choose the optimal size */ - ase_awk_val_ref_t* fcache[100]; /* TODO: choose the optimal size */ + ase_awk_val_int_t* icache[200]; /* TODO: choose the optimal size */ + ase_awk_val_real_t* rcache[200]; /* TODO: choose the optimal size */ + ase_awk_val_ref_t* fcache[200]; /* TODO: choose the optimal size */ ase_size_t icache_count; ase_size_t rcache_count; ase_size_t fcache_count; diff --git a/ase/awk/parse.c b/ase/awk/parse.c index be1c7b05..e54d7ec8 100644 --- a/ase/awk/parse.c +++ b/ase/awk/parse.c @@ -1,5 +1,5 @@ /* - * $Id: parse.c,v 1.202 2006-11-13 15:08:17 bacon Exp $ + * $Id: parse.c,v 1.203 2006-11-17 07:04:31 bacon Exp $ */ #include @@ -4376,6 +4376,11 @@ static int __deparse (ase_awk_t* awk) } else { + if (chain->pattern != ASE_NULL) + { + if (__put_char (awk, ASE_T(' ')) == -1) + EXIT_DEPARSE (ASE_AWK_ESRCOUTWRITE); + } if (ase_awk_prnpt (awk, chain->action) == -1) EXIT_DEPARSE (ASE_AWK_ESRCOUTWRITE); } diff --git a/ase/awk/run.c b/ase/awk/run.c index a9f14603..765b7ebf 100644 --- a/ase/awk/run.c +++ b/ase/awk/run.c @@ -1,5 +1,5 @@ /* - * $Id: run.c,v 1.263 2006-11-16 15:16:25 bacon Exp $ + * $Id: run.c,v 1.264 2006-11-17 07:04:31 bacon Exp $ */ #include @@ -1149,7 +1149,8 @@ static int __run_main (ase_awk_run_t* run, ase_awk_runarg_t* runarg) } if (n == 0 && - run->awk->tree.chain != ASE_NULL && + (run->awk->tree.chain != ASE_NULL || + run->awk->tree.end != ASE_NULL) && run->exit_level != EXIT_ABORT) { if (__run_pattern_blocks (run) == -1) n = -1; @@ -1197,7 +1198,7 @@ static int __run_main (ase_awk_run_t* run, ase_awk_runarg_t* runarg) } /* pops off the global variables */ - nglobals = run->awk->tree.nglobals; /*run->nglobals */ + nglobals = run->awk->tree.nglobals; while (nglobals > 0) { --nglobals; @@ -1252,15 +1253,19 @@ static int __run_pattern_blocks (ase_awk_run_t* run) __update_fnr (run, run->global.fnr + 1); - if (__run_pattern_block_chain (run, run->awk->tree.chain) == -1) + if (run->awk->tree.chain != ASE_NULL) { - int saved = run->errnum; + if (__run_pattern_block_chain ( + run, run->awk->tree.chain) == -1) + { + int saved = run->errnum; - ase_awk_closeextio_read ( - run, ASE_AWK_IN_CONSOLE, ASE_T("")); + ase_awk_closeextio_read ( + run, ASE_AWK_IN_CONSOLE, ASE_T("")); - run->errnum = saved; - return -1; + run->errnum = saved; + return -1; + } } } @@ -1428,6 +1433,18 @@ static int __run_block (ase_awk_run_t* run, ase_awk_nde_blk_t* nde) else return -1; } + n = ase_awk_writeextio_str ( + run, ASE_AWK_OUT_CONSOLE, ASE_T(""), + run->global.ors.ptr, run->global.ors.len); + if (n == -1) + { + ase_awk_refdownval (run, run->inrec.d0); + + if (run->errnum == ASE_AWK_EIOHANDLER) + PANIC_I (run, ASE_AWK_ECONOUTDATA); + else return -1; + } + ase_awk_refdownval (run, run->inrec.d0); return 0; } diff --git a/ase/awk/tree.c b/ase/awk/tree.c index 45ffa74e..548e6662 100644 --- a/ase/awk/tree.c +++ b/ase/awk/tree.c @@ -1,5 +1,5 @@ /* - * $Id: tree.c,v 1.86 2006-11-01 04:41:01 bacon Exp $ + * $Id: tree.c,v 1.87 2006-11-17 07:04:32 bacon Exp $ */ #include @@ -273,11 +273,36 @@ static int __print_expression (ase_awk_t* awk, ase_awk_nde_t* nde) case ASE_AWK_NDE_STR: { - /* TODO: ESCAPING */ + ase_char_t* ptr; + ase_size_t len, i; + PUT_SRCSTR (awk, ASE_T("\"")); + /* PUT_SRCSTRX (awk, ((ase_awk_nde_str_t*)nde)->buf, ((ase_awk_nde_str_t*)nde)->len); + */ + + ptr = ((ase_awk_nde_str_t*)nde)->buf; + len = ((ase_awk_nde_str_t*)nde)->len; + for (i = 0; i < len; i++) + { + /* TODO: more deescaping */ + if (ptr[i] == ASE_T('\n')) + PUT_SRCSTR (awk, ASE_T("\\n")); + else if (ptr[i] == ASE_T('\r')) + PUT_SRCSTR (awk, ASE_T("\\r")); + else if (ptr[i] == ASE_T('\f')) + PUT_SRCSTR (awk, ASE_T("\\f")); + else if (ptr[i] == ASE_T('\b')) + PUT_SRCSTR (awk, ASE_T("\\b")); + else if (ptr[i] == ASE_T('\v')) + PUT_SRCSTR (awk, ASE_T("\\v")); + else if (ptr[i] == ASE_T('\a')) + PUT_SRCSTR (awk, ASE_T("\\a")); + else + PUT_SRCSTRX (awk, &ptr[i], 1); + } PUT_SRCSTR (awk, ASE_T("\"")); break; } diff --git a/ase/awk/val.c b/ase/awk/val.c index bf24987e..ed8492ed 100644 --- a/ase/awk/val.c +++ b/ase/awk/val.c @@ -1,5 +1,5 @@ /* - * $Id: val.c,v 1.87 2006-11-16 15:16:25 bacon Exp $ + * $Id: val.c,v 1.88 2006-11-17 07:04:32 bacon Exp $ */ #include @@ -631,6 +631,7 @@ static ase_char_t* __val_real_to_str ( { ase_awk_str_close (&fbu); ase_awk_str_forfeit (&out); + if (len != ASE_NULL) *len = tmp_len; } else { diff --git a/ase/test/awk/emp-021.awk b/ase/test/awk/emp-021.awk new file mode 100644 index 00000000..6b112dff --- /dev/null +++ b/ase/test/awk/emp-021.awk @@ -0,0 +1,2 @@ + { names = names $1 " "; } +END { print names; } diff --git a/ase/test/awk/emp-022.awk b/ase/test/awk/emp-022.awk new file mode 100644 index 00000000..414d0979 --- /dev/null +++ b/ase/test/awk/emp-022.awk @@ -0,0 +1,2 @@ + { last = $0; } +END { print last; } diff --git a/ase/test/awk/emp-023.awk b/ase/test/awk/emp-023.awk new file mode 100644 index 00000000..fe25e4f5 --- /dev/null +++ b/ase/test/awk/emp-023.awk @@ -0,0 +1 @@ +{ print $1, length($1); } diff --git a/ase/test/awk/emp-024.awk b/ase/test/awk/emp-024.awk new file mode 100644 index 00000000..fb493296 --- /dev/null +++ b/ase/test/awk/emp-024.awk @@ -0,0 +1,4 @@ + { nc = nc + length($0) + 1; + nw = nw + NF; + } +END { print NR, "lines,", nw, "words,", nc, "characters"; } diff --git a/ase/test/awk/emp.data b/ase/test/awk/emp.data new file mode 100644 index 00000000..4c2dcb24 --- /dev/null +++ b/ase/test/awk/emp.data @@ -0,0 +1,6 @@ +Beth 4.00 0 +Dan 3.74 0 +Kathy 4.00 10 +Mark 5.00 20 +Mary 5.50 22 +Susie 4.25 18