diff --git a/ase/awk/parse.c b/ase/awk/parse.c index 7322652c..a53d7b1e 100644 --- a/ase/awk/parse.c +++ b/ase/awk/parse.c @@ -1,5 +1,5 @@ /* - * $Id: parse.c,v 1.140 2006-07-26 05:19:45 bacon Exp $ + * $Id: parse.c,v 1.141 2006-07-26 14:59:59 bacon Exp $ */ #include @@ -1916,17 +1916,26 @@ static xp_awk_nde_t* __parse_primary (xp_awk_t* awk) nde->type = XP_AWK_NDE_REX; nde->next = XP_NULL; - nde->buf = xp_awk_buildrex ( + nde->len = XP_STR_LEN(&awk->token.name); + nde->buf = xp_strxdup ( XP_STR_BUF(&awk->token.name), XP_STR_LEN(&awk->token.name)); if (nde->buf == XP_NULL) { - /* TODO: get the proper errnum */ xp_free (nde); PANIC (awk, XP_AWK_ENOMEM); } - /* TODO: is nde->len necessary ? */ - nde->len = XP_AWK_REXLEN(nde->buf); + + nde->code = xp_awk_buildrex ( + XP_STR_BUF(&awk->token.name), + XP_STR_LEN(&awk->token.name)); + if (nde->code == XP_NULL) + { + /* TODO: get the proper errnum */ + xp_free (nde->buf); + xp_free (nde); + PANIC (awk, XP_AWK_ENOMEM); + } if (__get_token(awk) == -1) { diff --git a/ase/awk/rex.c b/ase/awk/rex.c index ada2de09..eb9fde64 100644 --- a/ase/awk/rex.c +++ b/ase/awk/rex.c @@ -1,5 +1,5 @@ /* - * $Id: rex.c,v 1.15 2006-07-26 05:19:45 bacon Exp $ + * $Id: rex.c,v 1.16 2006-07-26 15:00:00 bacon Exp $ */ #include @@ -262,7 +262,11 @@ void* xp_awk_buildrex (const xp_char_t* ptn, xp_size_t len) builder.ptn.curc.value = XP_T('\0'); //NEXT_CHAR (&builder, LEVEL_TOP); - if (__next_char (&builder, LEVEL_TOP) == -1) return XP_NULL; + if (__next_char (&builder, LEVEL_TOP) == -1) + { + xp_free (builder.code.buf); + return XP_NULL; + } if (__build_pattern (&builder) == -1) { diff --git a/ase/awk/run.c b/ase/awk/run.c index 4abcb324..b2e34773 100644 --- a/ase/awk/run.c +++ b/ase/awk/run.c @@ -1,5 +1,5 @@ /* - * $Id: run.c,v 1.138 2006-07-26 05:19:46 bacon Exp $ + * $Id: run.c,v 1.139 2006-07-26 15:00:00 bacon Exp $ */ #include @@ -644,7 +644,7 @@ static int __handle_pattern (xp_awk_run_t* run, xp_awk_val_t* val) //xp_awk_rex_setpattern (v->buf, v->len); n = xp_awk_matchrex ( - ((xp_awk_val_rex_t*)val)->buf, + ((xp_awk_val_rex_t*)val)->code, ((xp_awk_val_str_t*)run->inrec.d0)->buf, ((xp_awk_val_str_t*)run->inrec.d0)->len, XP_NULL, XP_NULL); @@ -3413,7 +3413,8 @@ static xp_awk_val_t* __eval_rex (xp_awk_run_t* run, xp_awk_nde_t* nde) val = xp_awk_makerexval ( ((xp_awk_nde_rex_t*)nde)->buf, - ((xp_awk_nde_rex_t*)nde)->len); + ((xp_awk_nde_rex_t*)nde)->len, + ((xp_awk_nde_rex_t*)nde)->code); if (val == XP_NULL) PANIC (run, XP_AWK_ENOMEM); return val; diff --git a/ase/awk/tree.c b/ase/awk/tree.c index a3ebe449..2cd98138 100644 --- a/ase/awk/tree.c +++ b/ase/awk/tree.c @@ -1,5 +1,5 @@ /* - * $Id: tree.c,v 1.67 2006-07-25 17:15:15 bacon Exp $ + * $Id: tree.c,v 1.68 2006-07-26 15:00:00 bacon Exp $ */ #include @@ -227,8 +227,8 @@ static int __print_expression (xp_awk_nde_t* nde) case XP_AWK_NDE_REX: { - /* TODO: print it properly */ - xp_printf (XP_T("/**REX**/")); + /* TODO: buf, len */ + xp_printf (XP_T("/%s/"), ((xp_awk_nde_rex_t*)nde)->buf); break; } @@ -915,6 +915,7 @@ void xp_awk_clrpt (xp_awk_nde_t* tree) case XP_AWK_NDE_REX: { xp_free (((xp_awk_nde_rex_t*)p)->buf); + xp_free (((xp_awk_nde_rex_t*)p)->code); xp_free (p); break; } diff --git a/ase/awk/tree.h b/ase/awk/tree.h index 596d824d..743fcb95 100644 --- a/ase/awk/tree.h +++ b/ase/awk/tree.h @@ -1,5 +1,5 @@ /* - * $Id: tree.h,v 1.62 2006-07-25 17:15:15 bacon Exp $ + * $Id: tree.h,v 1.63 2006-07-26 15:00:00 bacon Exp $ */ #ifndef _XP_AWK_TREE_H_ @@ -205,8 +205,9 @@ struct xp_awk_nde_str_t struct xp_awk_nde_rex_t { XP_AWK_NDE_HDR; - xp_byte_t* buf; + xp_char_t* buf; xp_size_t len; + void* code; }; /* XP_AWK_NDE_NAMED, XP_AWK_NDE_GLOBAL, diff --git a/ase/awk/val.c b/ase/awk/val.c index 2a72e0ce..ef697dc1 100644 --- a/ase/awk/val.c +++ b/ase/awk/val.c @@ -1,5 +1,5 @@ /* - * $Id: val.c,v 1.46 2006-07-25 17:15:15 bacon Exp $ + * $Id: val.c,v 1.47 2006-07-26 15:00:00 bacon Exp $ */ #include @@ -135,7 +135,8 @@ xp_awk_val_t* xp_awk_makestrval2 ( return (xp_awk_val_t*)val; } -xp_awk_val_t* xp_awk_makerexval (const xp_byte_t* buf, xp_size_t len) +xp_awk_val_t* xp_awk_makerexval ( + const xp_char_t* buf, xp_size_t len, void* code) { xp_awk_val_rex_t* val; @@ -145,14 +146,22 @@ xp_awk_val_t* xp_awk_makerexval (const xp_byte_t* buf, xp_size_t len) val->type = XP_AWK_VAL_REX; val->ref = 0; val->len = len; - val->buf = xp_malloc (len); + val->buf = xp_strxdup (buf, len); if (val->buf == XP_NULL) { xp_free (val); return XP_NULL; } - xp_memcpy (val->buf, buf, len); + val->code = xp_malloc (XP_AWK_REXLEN(code)); + if (val->code == XP_NULL) + { + xp_free (val->buf); + xp_free (val); + return XP_NULL; + } + + xp_memcpy (val->code, code, XP_AWK_REXLEN(code)); return (xp_awk_val_t*)val; } @@ -235,6 +244,7 @@ xp_printf (XP_T("\n"));*/ case XP_AWK_VAL_REX: xp_free (((xp_awk_val_rex_t*)val)->buf); + xp_free (((xp_awk_val_rex_t*)val)->code); xp_free (val); return; diff --git a/ase/awk/val.h b/ase/awk/val.h index 6ee6e420..54980c2a 100644 --- a/ase/awk/val.h +++ b/ase/awk/val.h @@ -1,5 +1,5 @@ /* - * $Id: val.h,v 1.33 2006-07-25 17:15:15 bacon Exp $ + * $Id: val.h,v 1.34 2006-07-26 15:00:00 bacon Exp $ */ #ifndef _XP_AWK_VAL_H_ @@ -75,6 +75,7 @@ struct xp_awk_val_rex_t XP_AWK_VAL_HDR; xp_char_t* buf; xp_size_t len; + void* code; }; /* XP_AWK_VAL_MAP */ @@ -104,7 +105,8 @@ xp_awk_val_t* xp_awk_makestrval (const xp_char_t* str, xp_size_t len); xp_awk_val_t* xp_awk_makestrval2 ( const xp_char_t* str1, xp_size_t len1, const xp_char_t* str2, xp_size_t len2); -xp_awk_val_t* xp_awk_makerexval (const xp_byte_t* buf, xp_size_t len); +xp_awk_val_t* xp_awk_makerexval ( + const xp_char_t* buf, xp_size_t len, void* code); xp_awk_val_t* xp_awk_makemapval (xp_awk_run_t* run); xp_bool_t xp_awk_isbuiltinval (xp_awk_val_t* val); diff --git a/ase/test/awk/t16.awk b/ase/test/awk/t16.awk index ef2ca32e..534131b7 100644 --- a/ase/test/awk/t16.awk +++ b/ase/test/awk/t16.awk @@ -1 +1 @@ -/hello/ { $0=" "; print NF; print "a" $0 "b"; x = $1; } +{ $0=" "; print NF; print "a" $0 "b"; x = $1; } diff --git a/ase/test/awk/t17.awk b/ase/test/awk/t17.awk new file mode 100644 index 00000000..a69679d3 --- /dev/null +++ b/ase/test/awk/t17.awk @@ -0,0 +1 @@ +/hello/ { print $0; }