diff --git a/ase/awk/err.c b/ase/awk/err.c index ca7b8d0a..ed7a0db0 100644 --- a/ase/awk/err.c +++ b/ase/awk/err.c @@ -1,5 +1,5 @@ /* - * $Id: err.c,v 1.40 2006-09-14 06:40:06 bacon Exp $ + * $Id: err.c,v 1.41 2006-09-30 17:02:35 bacon Exp $ */ #include @@ -16,7 +16,7 @@ const xp_char_t* xp_awk_geterrstr (int errnum) XP_T("no error"), XP_T("out of memory"), XP_T("invalid parameter"), - XP_T("run-time error"), + XP_T("general run-time error"), XP_T("one or more running instances"), XP_T("too many running instances"), XP_T("recursion too deep"), diff --git a/ase/awk/func.c b/ase/awk/func.c index 2836e368..449e0db7 100644 --- a/ase/awk/func.c +++ b/ase/awk/func.c @@ -1,5 +1,5 @@ /* - * $Id: func.c,v 1.53 2006-09-22 14:04:25 bacon Exp $ + * $Id: func.c,v 1.54 2006-09-30 17:02:35 bacon Exp $ */ #include @@ -888,6 +888,14 @@ static int __substitute (xp_awk_t* awk, void* run, xp_long_t max_count) else { /* operation is on a2 */ +if (((xp_awk_val_ref_t*)a2)->id == XP_AWK_VAL_REF_POS) +{ +FREE_A_PTRS (awk); +/* a map is not allowed as the third parameter */ +xp_awk_seterrnum (run, XP_AWK_EMAPNOTALLOWED); +return -1; +} + a2_ref = (xp_awk_val_t**)((xp_awk_val_ref_t*)a2)->adr; if ((*a2_ref)->type == XP_AWK_VAL_MAP) { @@ -1009,8 +1017,8 @@ static int __substitute (xp_awk_t* awk, void* run, xp_long_t max_count) } sub_count++; - cur_ptr = mat_ptr + mat_len; cur_len = cur_len - ((mat_ptr - cur_ptr) + mat_len); + cur_ptr = mat_ptr + mat_len; } FREE_A0_REX (awk, rex); diff --git a/ase/awk/run.c b/ase/awk/run.c index 02b3f1eb..ec17128c 100644 --- a/ase/awk/run.c +++ b/ase/awk/run.c @@ -1,5 +1,5 @@ /* - * $Id: run.c,v 1.212 2006-09-29 11:18:13 bacon Exp $ + * $Id: run.c,v 1.213 2006-09-30 17:02:36 bacon Exp $ */ #include @@ -1956,8 +1956,8 @@ static int __run_print (xp_awk_run_t* run, xp_awk_nde_print_t* nde) if (p->args == XP_NULL) { + /* v = run->inrec.d0; - xp_awk_refupval (v); n = xp_awk_writeextio_val (run, p->out_type, dst, v); if (n < 0 && run->errnum != XP_AWK_EIOHANDLER) @@ -1967,6 +1967,16 @@ static int __run_print (xp_awk_run_t* run, xp_awk_nde_print_t* nde) return -1; } xp_awk_refdownval (run, v); + */ + n = xp_awk_writeextio_str ( + run, p->out_type, dst, + XP_AWK_STR_BUF(&run->inrec.line), + XP_AWK_STR_LEN(&run->inrec.line)); + if (n < 0 && run->errnum != XP_AWK_EIOHANDLER) + { + if (out != XP_NULL) XP_AWK_FREE (run->awk, out); + return -1; + } /* TODO: how to handle n == -1 && errnum == XP_AWK_EIOHANDLER. * that is the user handler returned an error... */ } @@ -1974,6 +1984,18 @@ static int __run_print (xp_awk_run_t* run, xp_awk_nde_print_t* nde) { for (np = p->args; np != XP_NULL; np = np->next) { + if (np != p->args) + { + n = xp_awk_writeextio_str ( + run, p->out_type, dst, + run->global.ofs.ptr, run->global.ofs.len); + if (n < 0 && run->errnum != XP_AWK_EIOHANDLER) + { + if (out != XP_NULL) XP_AWK_FREE (run->awk, out); + return -1; + } + } + v = __eval_expression (run, np); if (v == XP_NULL) { @@ -1991,19 +2013,9 @@ static int __run_print (xp_awk_run_t* run, xp_awk_nde_print_t* nde) } xp_awk_refdownval (run, v); - n = xp_awk_writeextio_str ( - run, p->out_type, dst, - run->global.ofs.ptr, run->global.ofs.len); - if (n < 0 && run->errnum != XP_AWK_EIOHANDLER) - { - if (out != XP_NULL) XP_AWK_FREE (run->awk, out); - return -1; - } /* TODO: how to handle n == -1 && run->errnum == XP_AWK_EIOHANDLER. * that is the user handler returned an error... */ - - /* TODO: print proper field separator */ } } @@ -4113,7 +4125,25 @@ static xp_awk_val_t* __eval_call ( xp_awk_strlen(bfn_arg_spec) > nargs)); if (bfn_arg_spec != XP_NULL && - bfn_arg_spec[nargs] == XP_T('x')) + bfn_arg_spec[nargs] == XP_T('r')) + { + xp_awk_val_t** ref; + xp_awk_val_t* tmp; + + ref = __get_reference (run, p); + if (ref == XP_NULL) + { + UNWIND_RUN_STACK (run, nargs); + return XP_NULL; + } + + /* p->type-XP_AWK_NDE_NAMED assumes that the + * derived value matches XP_AWK_VAL_REF_XXX */ + v = xp_awk_makerefval ( + run, p->type-XP_AWK_NDE_NAMED, ref); + } + else if (bfn_arg_spec != XP_NULL && + bfn_arg_spec[nargs] == XP_T('x')) { /* a regular expression is passed to * the function as it is */ @@ -4129,6 +4159,7 @@ static xp_awk_val_t* __eval_call ( return XP_NULL; } +#if 0 if (bfn_arg_spec != XP_NULL && bfn_arg_spec[nargs] == XP_T('r')) { @@ -4163,6 +4194,7 @@ static xp_awk_val_t* __eval_call ( v = tmp; } +#endif if (__raw_push(run,v) == -1) { @@ -4312,7 +4344,6 @@ static xp_awk_val_t** __get_reference (xp_awk_run_t* run, xp_awk_nde_t* nde) run, tgt, (xp_awk_val_t**)&pair->val); } - if (nde->type == XP_AWK_NDE_GLOBALIDX) { return __get_reference_indexed (run, tgt, @@ -4331,6 +4362,31 @@ static xp_awk_val_t** __get_reference (xp_awk_run_t* run, xp_awk_nde_t* nde) (xp_awk_val_t**)&STACK_ARG(run,tgt->id.idxa)); } + if (nde->type == XP_AWK_NDE_POS) + { + int n; + xp_long_t lv; + xp_real_t rv; + xp_awk_val_t* v; + + /* the position number is returned for the positional + * variable unlike other reference types. */ + v = __eval_expression (run, ((xp_awk_nde_pos_t*)nde)->val); + if (v == XP_NULL) return XP_NULL; + + xp_awk_refupval (v); + n = xp_awk_valtonum (run, v, &lv, &rv); + xp_awk_refdownval (run, v); + + if (n == -1) PANIC (run, XP_AWK_EPOSIDX); + if (n == 1) lv = (xp_long_t)rv; + + if (lv < 0) PANIC (run, XP_AWK_EPOSIDX); + +/* TODO: ............................................. */ + return (xp_awk_val_t**)(lv+1); + } + PANIC (run, XP_AWK_ENOTREFERENCEABLE); } diff --git a/ase/awk/tree.h b/ase/awk/tree.h index 183218ef..dec71ce7 100644 --- a/ase/awk/tree.h +++ b/ase/awk/tree.h @@ -1,5 +1,5 @@ /* - * $Id: tree.h,v 1.72 2006-09-11 14:29:23 bacon Exp $ + * $Id: tree.h,v 1.73 2006-09-30 17:02:36 bacon Exp $ */ #ifndef _XP_AWK_TREE_H_ @@ -58,9 +58,9 @@ enum XP_AWK_NDE_GLOBALIDX, XP_AWK_NDE_LOCALIDX, XP_AWK_NDE_ARGIDX, + XP_AWK_NDE_POS, /* ---------------------------------- */ - XP_AWK_NDE_POS, XP_AWK_NDE_GETLINE, }; diff --git a/ase/awk/val.h b/ase/awk/val.h index f05321aa..fbe589a6 100644 --- a/ase/awk/val.h +++ b/ase/awk/val.h @@ -1,5 +1,5 @@ /* - * $Id: val.h,v 1.42 2006-09-28 06:56:30 bacon Exp $ + * $Id: val.h,v 1.43 2006-09-30 17:02:36 bacon Exp $ */ #ifndef _XP_AWK_VAL_H_ @@ -35,7 +35,8 @@ enum XP_AWK_VAL_REF_NAMEDIDX, XP_AWK_VAL_REF_GLOBALIDX, XP_AWK_VAL_REF_LOCALIDX, - XP_AWK_VAL_REF_ARGIDX + XP_AWK_VAL_REF_ARGIDX, + XP_AWK_VAL_REF_POS }; typedef struct xp_awk_val_nil_t xp_awk_val_nil_t; diff --git a/ase/test/awk/comp.awk b/ase/test/awk/comp.awk index 132c175f..506f02b3 100644 --- a/ase/test/awk/comp.awk +++ b/ase/test/awk/comp.awk @@ -1,43 +1,45 @@ BEGIN { - print "1==1 : ", (1 == 1); - print "1==0 : ", (1 == 0); + OFS="\t\t"; - print "1.0==1 : " (1.0 == 1); - print "1.1==1 : " (1.1 == 1); + print "1==1 :", (1 == 1); + print "1==0 :", (1 == 0); - print "1.0!=1 : " (1.0 != 1); - print "1.1!=1 : " (1.1 != 1); + print "1.0==1 :", (1.0 == 1); + print "1.1==1 :", (1.1 == 1); + + print "1.0!=1 :", (1.0 != 1); + print "1.1!=1 :", (1.1 != 1); print "abc" == "abc"; print "abc" != "abc"; - print "------------------------"; - print "a == \"\" : " (a == ""); - print "a >= \"\" : " (a >= ""); - print "a <= \"\" : " (a <= ""); - print "a > \"\" : " (a > ""); - print "a < \"\" : " (a < ""); + print "--------------------------"; + print "a == \"\" :", (a == ""); + print "a >= \"\" :", (a >= ""); + print "a <= \"\" :", (a <= ""); + print "a > \"\" :", (a > ""); + print "a < \"\" :", (a < ""); - print "------------------------"; - print "a == \" \" : " (a == " "); - print "a >= \" \" : " (a >= " "); - print "a <= \" \" : " (a <= " "); - print "a > \" \" : " (a > " "); - print "a < \" \" : " (a < " "); + print "--------------------------"; + print "a == \" \" :", (a == " "); + print "a >= \" \" :", (a >= " "); + print "a <= \" \" :", (a <= " "); + print "a > \" \" :", (a > " "); + print "a < \" \" :", (a < " "); - print "------------------------"; - print "\"\" == a : " ("" == a); - print "\"\" >= a: " ("" >= a); - print "\"\" <= a: " ("" <= a); - print "\"\" > a: " ("" > a); - print "\"\" < a: " ("" < a); + print "--------------------------"; + print "\"\" == a :", ("" == a); + print "\"\" >= a:", ("" >= a); + print "\"\" <= a:", ("" <= a); + print "\"\" > a:", ("" > a); + print "\"\" < a:", ("" < a); - print "------------------------"; - print "\" \" == a : " (" " == a); - print "\" \" >= a: " (" " >= a); - print "\" \" <= a: " (" " <= a); - print "\" \" > a: " (" " > a); - print "\" \" < a: " (" " < a); + print "--------------------------"; + print "\" \" == a :", (" " == a); + print "\" \" >= a:", (" " >= a); + print "\" \" <= a:", (" " <= a); + print "\" \" > a:", (" " > a); + print "\" \" < a:", (" " < a); #a[10] = 2; #print a == 1; diff --git a/ase/test/awk/wordfreq.awk b/ase/test/awk/wordfreq.awk index cf8277cb..364f4d94 100644 --- a/ase/test/awk/wordfreq.awk +++ b/ase/test/awk/wordfreq.awk @@ -2,15 +2,18 @@ { $0 = tolower($0); # remove case distinctions + # remove punctuation - #gsub(/[^[:alnum:]_[:blank:]]/, "", $0); + a=0; + gsub(/[^[:alnum:]_[:blank:]]/, " ", $a); + #gsub(/[^[:alnum:]_[:blank:]]/, " "); for (i = 1; i <= NF; i++) freq[$i]++; } END { for (word in freq) - print word, "\t", freq[word]; + print word, freq[word]; }