diff --git a/ase/awk/awk.c b/ase/awk/awk.c index 3c44b097..0a706a7b 100644 --- a/ase/awk/awk.c +++ b/ase/awk/awk.c @@ -1,5 +1,5 @@ /* - * $Id: awk.c,v 1.78 2006-10-02 14:53:44 bacon Exp $ + * $Id: awk.c,v 1.79 2006-10-12 04:17:30 bacon Exp $ */ #include @@ -29,6 +29,10 @@ xp_awk_t* xp_awk_open (xp_awk_syscas_t* syscas) syscas->to_upper == XP_NULL || syscas->to_lower == XP_NULL) return XP_NULL; + if (syscas->sprintf == XP_NULL || + syscas->dprintf == XP_NULL || + syscas->abort == XP_NULL) return XP_NULL; + #if defined(_WIN32) && defined(_DEBUG) awk = (xp_awk_t*) malloc (xp_sizeof(xp_awk_t)); #else @@ -120,7 +124,7 @@ int xp_awk_close (xp_awk_t* awk) { if (xp_awk_clear (awk) == -1) return -1; - xp_assert (awk->run.count == 0 && awk->run.ptr == XP_NULL); + xp_awk_assert (awk, awk->run.count == 0 && awk->run.ptr == XP_NULL); xp_awk_map_close (&awk->tree.afns); xp_awk_tab_close (&awk->parse.globals); @@ -171,14 +175,14 @@ int xp_awk_clear (xp_awk_t* awk) if (awk->tree.begin != XP_NULL) { - xp_assert (awk->tree.begin->next == XP_NULL); + xp_awk_assert (awk, awk->tree.begin->next == XP_NULL); xp_awk_clrpt (awk, awk->tree.begin); awk->tree.begin = XP_NULL; } if (awk->tree.end != XP_NULL) { - xp_assert (awk->tree.end->next == XP_NULL); + xp_awk_assert (awk, awk->tree.end->next == XP_NULL); xp_awk_clrpt (awk, awk->tree.end); awk->tree.end = XP_NULL; } diff --git a/ase/awk/awk.h b/ase/awk/awk.h index 1da55ebc..04c8cfdf 100644 --- a/ase/awk/awk.h +++ b/ase/awk/awk.h @@ -1,5 +1,5 @@ /* - * $Id: awk.h,v 1.125 2006-10-10 14:08:55 bacon Exp $ + * $Id: awk.h,v 1.126 2006-10-12 04:17:30 bacon Exp $ */ #ifndef _XP_AWK_AWK_H_ @@ -71,7 +71,10 @@ struct xp_awk_syscas_t /* utilities */ void* (*memcpy) (void* dst, const void* src, xp_size_t n); void* (*memset) (void* dst, int val, xp_size_t n); + int (*sprintf) (xp_char_t* buf, xp_size_t size, xp_char_t* fmt, ...); + int (*dprintf) (xp_char_t* fmt, ...); + void (*abort) (void); void* custom_data; }; diff --git a/ase/awk/awk_i.h b/ase/awk/awk_i.h index 03528582..f8a9f23f 100644 --- a/ase/awk/awk_i.h +++ b/ase/awk/awk_i.h @@ -1,5 +1,5 @@ /* - * $Id: awk_i.h,v 1.63 2006-10-11 15:01:54 bacon Exp $ + * $Id: awk_i.h,v 1.64 2006-10-12 04:17:30 bacon Exp $ */ #ifndef _XP_AWK_AWKI_H_ @@ -9,18 +9,6 @@ typedef struct xp_awk_chain_t xp_awk_chain_t; typedef struct xp_awk_tree_t xp_awk_tree_t; #include - -#ifdef XP_AWK_STAND_ALONE - #if !defined(XP_CHAR_IS_MCHAR) && !defined(XP_CHAR_IS_WCHAR) - #error Neither XP_CHAR_IS_MCHAR nor XP_CHAR_IS_WCHAR is defined. - #endif - - #include - #define xp_assert assert -#else - #include -#endif - #include #include #include @@ -33,13 +21,15 @@ typedef struct xp_awk_tree_t xp_awk_tree_t; #include #include -#ifdef _MSC_VER -#pragma warning (disable: 4996) +#ifdef NDEBUG + #define xp_awk_assert(awk,expr) ((void)0) +#else + #define xp_awk_assert(awk,expr) (void)((expr) || \ + (xp_awk_abort(awk, XP_TEXT(#expr), XP_TEXT(__FILE__), __LINE__), 0)) #endif -#if defined(_WIN32) && defined(XP_AWK_STAND_ALONE) && defined(_DEBUG) -#define _CRTDBG_MAP_ALLOC -#include +#ifdef _MSC_VER +#pragma warning (disable: 4996) #endif #define XP_AWK_MAX_GLOBALS 9999 @@ -47,6 +37,9 @@ typedef struct xp_awk_tree_t xp_awk_tree_t; #define XP_AWK_MAX_PARAMS 9999 #if defined(_WIN32) && defined(_DEBUG) + #define _CRTDBG_MAP_ALLOC + #include + #define XP_AWK_MALLOC(awk,size) malloc (size) #define XP_AWK_REALLOC(awk,ptr,size) realloc (ptr, size) #define XP_AWK_FREE(awk,ptr) free (ptr) diff --git a/ase/awk/extio.c b/ase/awk/extio.c index 9ceb76e7..605c6912 100644 --- a/ase/awk/extio.c +++ b/ase/awk/extio.c @@ -1,5 +1,5 @@ /* - * $Id: extio.c,v 1.51 2006-10-11 15:01:55 bacon Exp $ + * $Id: extio.c,v 1.52 2006-10-12 04:17:30 bacon Exp $ */ #include @@ -84,9 +84,12 @@ int xp_awk_readextio ( xp_size_t rs_len; xp_size_t line_len = 0; - xp_assert (in_type >= 0 && in_type <= xp_countof(__in_type_map)); - xp_assert (in_type >= 0 && in_type <= xp_countof(__in_mode_map)); - xp_assert (in_type >= 0 && in_type <= xp_countof(__in_mask_map)); + xp_awk_assert (run->awk, + in_type >= 0 && in_type <= xp_countof(__in_type_map)); + xp_awk_assert (run->awk, + in_type >= 0 && in_type <= xp_countof(__in_mode_map)); + xp_awk_assert (run->awk, + in_type >= 0 && in_type <= xp_countof(__in_mask_map)); /* translate the in_type into the relevant extio type and mode */ extio_type = __in_type_map[in_type]; @@ -280,7 +283,7 @@ int xp_awk_readextio ( const xp_char_t* match_ptr; xp_size_t match_len; - xp_assert (run->global.rs != XP_NULL); + xp_awk_assert (run->awk, run->global.rs != XP_NULL); /* TODO: safematchrex */ n = xp_awk_matchrex ( @@ -298,7 +301,7 @@ int xp_awk_readextio ( { /* the match should be found at the end of * the current buffer */ - xp_assert ( + xp_awk_assert (run->awk, XP_AWK_STR_BUF(buf) + XP_AWK_STR_LEN(buf) == match_ptr + match_len); @@ -373,7 +376,9 @@ int xp_awk_writeextio_val ( else { str = xp_awk_valtostr ( - run, v, XP_AWK_VALTOSTR_CLEAR, XP_NULL, &len); + run, v, + XP_AWK_VALTOSTR_CLEAR | XP_AWK_VALTOSTR_PRINT, + XP_NULL, &len); if (str == XP_NULL) return -1; } @@ -391,9 +396,12 @@ int xp_awk_writeextio_str ( xp_awk_io_t handler; int extio_type, extio_mode, extio_mask, n; - xp_assert (out_type >= 0 && out_type <= xp_countof(__out_type_map)); - xp_assert (out_type >= 0 && out_type <= xp_countof(__out_mode_map)); - xp_assert (out_type >= 0 && out_type <= xp_countof(__out_mask_map)); + xp_awk_assert (run->awk, + out_type >= 0 && out_type <= xp_countof(__out_type_map)); + xp_awk_assert (run->awk, + out_type >= 0 && out_type <= xp_countof(__out_mode_map)); + xp_awk_assert (run->awk, + out_type >= 0 && out_type <= xp_countof(__out_mask_map)); /* translate the out_type into the relevant extio type and mode */ extio_type = __out_type_map[out_type]; @@ -504,9 +512,12 @@ int xp_awk_flushextio ( int extio_type, extio_mode, extio_mask, n; xp_bool_t ok = xp_false; - xp_assert (out_type >= 0 && out_type <= xp_countof(__out_type_map)); - xp_assert (out_type >= 0 && out_type <= xp_countof(__out_mode_map)); - xp_assert (out_type >= 0 && out_type <= xp_countof(__out_mask_map)); + xp_awk_assert (run->awk, + out_type >= 0 && out_type <= xp_countof(__out_type_map)); + xp_awk_assert (run->awk, + out_type >= 0 && out_type <= xp_countof(__out_mode_map)); + xp_awk_assert (run->awk, + out_type >= 0 && out_type <= xp_countof(__out_mask_map)); /* translate the out_type into the relevant extio type and mode */ extio_type = __out_type_map[out_type]; @@ -564,9 +575,12 @@ int xp_awk_nextextio_read ( xp_awk_io_t handler; int extio_type, extio_mode, extio_mask, n; - xp_assert (in_type >= 0 && in_type <= xp_countof(__in_type_map)); - xp_assert (in_type >= 0 && in_type <= xp_countof(__in_mode_map)); - xp_assert (in_type >= 0 && in_type <= xp_countof(__in_mask_map)); + xp_awk_assert (run->awk, + in_type >= 0 && in_type <= xp_countof(__in_type_map)); + xp_awk_assert (run->awk, + in_type >= 0 && in_type <= xp_countof(__in_mode_map)); + xp_awk_assert (run->awk, + in_type >= 0 && in_type <= xp_countof(__in_mask_map)); /* translate the in_type into the relevant extio type and mode */ extio_type = __in_type_map[in_type]; @@ -613,9 +627,12 @@ int xp_awk_closeextio_read ( xp_awk_io_t handler; int extio_type, extio_mode, extio_mask; - xp_assert (in_type >= 0 && in_type <= xp_countof(__in_type_map)); - xp_assert (in_type >= 0 && in_type <= xp_countof(__in_mode_map)); - xp_assert (in_type >= 0 && in_type <= xp_countof(__in_mask_map)); + xp_awk_assert (run->awk, + in_type >= 0 && in_type <= xp_countof(__in_type_map)); + xp_awk_assert (run->awk, + in_type >= 0 && in_type <= xp_countof(__in_mode_map)); + xp_awk_assert (run->awk, + in_type >= 0 && in_type <= xp_countof(__in_mask_map)); /* translate the in_type into the relevant extio type and mode */ extio_type = __in_type_map[in_type]; @@ -673,9 +690,12 @@ int xp_awk_closeextio_write ( xp_awk_io_t handler; int extio_type, extio_mode, extio_mask; - xp_assert (out_type >= 0 && out_type <= xp_countof(__out_type_map)); - xp_assert (out_type >= 0 && out_type <= xp_countof(__out_mode_map)); - xp_assert (out_type >= 0 && out_type <= xp_countof(__out_mask_map)); + xp_awk_assert (run->awk, + out_type >= 0 && out_type <= xp_countof(__out_type_map)); + xp_awk_assert (run->awk, + out_type >= 0 && out_type <= xp_countof(__out_mode_map)); + xp_awk_assert (run->awk, + out_type >= 0 && out_type <= xp_countof(__out_mask_map)); /* translate the out_type into the relevant extio type and mode */ extio_type = __out_type_map[out_type]; diff --git a/ase/awk/func.c b/ase/awk/func.c index d440aaaa..b56420c8 100644 --- a/ase/awk/func.c +++ b/ase/awk/func.c @@ -1,5 +1,5 @@ /* - * $Id: func.c,v 1.61 2006-10-11 15:01:55 bacon Exp $ + * $Id: func.c,v 1.62 2006-10-12 04:17:30 bacon Exp $ */ #include @@ -150,11 +150,11 @@ static int __bfn_close (xp_awk_run_t* run) xp_size_t len; nargs = xp_awk_getnargs (run); - xp_assert (nargs == 1); + xp_awk_assert (run->awk, nargs == 1); /* TODO: support close (xxx, "to"/"from") like gawk */ a0 = xp_awk_getarg (run, 0); - xp_assert (a0 != XP_NULL); + xp_awk_assert (run->awk, a0 != XP_NULL); if (a0->type == XP_AWK_VAL_STR) { @@ -252,7 +252,7 @@ static int __bfn_fflush (xp_awk_run_t* run) int n; nargs = xp_awk_getnargs (run); - xp_assert (nargs >= 0 && nargs <= 1); + xp_awk_assert (run->awk, nargs >= 0 && nargs <= 1); if (nargs == 0) { @@ -347,7 +347,7 @@ static int __bfn_index (xp_awk_run_t* run) xp_long_t idx; nargs = xp_awk_getnargs (run); - xp_assert (nargs == 2); + xp_awk_assert (run->awk, nargs == 2); a0 = xp_awk_getarg (run, 0); a1 = xp_awk_getarg (run, 1); @@ -408,7 +408,7 @@ static int __bfn_length (xp_awk_run_t* run) xp_size_t len; nargs = xp_awk_getnargs (run); - xp_assert (nargs == 1); + xp_awk_assert (run->awk, nargs == 1); v = xp_awk_getarg (run, 0); if (v->type == XP_AWK_VAL_STR) @@ -445,7 +445,7 @@ static int __bfn_substr (xp_awk_run_t* run) int n; nargs = xp_awk_getnargs (run); - xp_assert (nargs >= 2 && nargs <= 3); + xp_awk_assert (run->awk, nargs >= 2 && nargs <= 3); a0 = xp_awk_getarg (run, 0); a1 = xp_awk_getarg (run, 1); @@ -520,13 +520,13 @@ static int __bfn_split (xp_awk_run_t* run) int errnum; nargs = xp_awk_getnargs (run); - xp_assert (nargs >= 2 && nargs <= 3); + xp_awk_assert (run->awk, nargs >= 2 && nargs <= 3); a0 = xp_awk_getarg (run, 0); a1 = xp_awk_getarg (run, 1); a2 = (nargs >= 3)? xp_awk_getarg (run, 2): XP_NULL; - xp_assert (a1->type == XP_AWK_VAL_REF); + xp_awk_assert (run->awk, a1->type == XP_AWK_VAL_REF); if (((xp_awk_val_ref_t*)a1)->id >= XP_AWK_VAL_REF_NAMEDIDX && ((xp_awk_val_ref_t*)a1)->id <= XP_AWK_VAL_REF_ARGIDX) @@ -687,7 +687,8 @@ static int __bfn_split (xp_awk_run_t* run) break; } - xp_assert ((tok != XP_NULL && tok_len > 0) || tok_len == 0); + xp_awk_assert (run->awk, + (tok != XP_NULL && tok_len > 0) || tok_len == 0); /* create the field string */ t2 = xp_awk_makestrval (run, tok, tok_len); @@ -706,7 +707,7 @@ static int __bfn_split (xp_awk_run_t* run) /* put it into the map */ key_len = xp_awk_longtostr ( num, 10, XP_NULL, key, xp_countof(key)); - xp_assert (key_len != (xp_size_t)-1); + xp_awk_assert (run->awk, key_len != (xp_size_t)-1); /* don't forget to update the reference count when you * handle the assignment-like situation. anyway, it is @@ -757,7 +758,7 @@ static int __bfn_tolower (xp_awk_run_t* run) xp_awk_val_t* a0, * r; nargs = xp_awk_getnargs (run); - xp_assert (nargs == 1); + xp_awk_assert (run->awk, nargs == 1); a0 = xp_awk_getarg (run, 0); @@ -796,7 +797,7 @@ static int __bfn_toupper (xp_awk_run_t* run) xp_awk_val_t* a0, * r; nargs = xp_awk_getnargs (run); - xp_assert (nargs == 1); + xp_awk_assert (run->awk, nargs == 1); a0 = xp_awk_getarg (run, 0); @@ -844,13 +845,13 @@ static int __substitute (xp_awk_run_t* run, xp_long_t max_count) xp_long_t sub_count; nargs = xp_awk_getnargs (run); - xp_assert (nargs >= 2 && nargs <= 3); + xp_awk_assert (run->awk, nargs >= 2 && nargs <= 3); a0 = xp_awk_getarg (run, 0); a1 = xp_awk_getarg (run, 1); a2 = (nargs >= 3)? xp_awk_getarg (run, 2): XP_NULL; - xp_assert (a2 == XP_NULL || a2->type == XP_AWK_VAL_REF); + xp_awk_assert (run->awk, a2 == XP_NULL || a2->type == XP_AWK_VAL_REF); #define FREE_A_PTRS(awk) \ do { \ @@ -947,8 +948,8 @@ static int __substitute (xp_awk_run_t* run, xp_long_t max_count) } else { - a2_ptr = xp_awk_valtostr (run, *a2_ref, - XP_AWK_VALTOSTR_CLEAR, XP_NULL, &a2_len); + a2_ptr = xp_awk_valtostr ( + run, *a2_ref, XP_AWK_VALTOSTR_CLEAR, XP_NULL, &a2_len); if (a2_ptr == XP_NULL) { FREE_A_PTRS (run->awk); @@ -1136,7 +1137,7 @@ static int __bfn_system (xp_awk_run_t* run) int n; nargs = xp_awk_getnargs (run); - xp_assert (nargs == 1); + xp_awk_assert (run->awk, nargs == 1); cmd = xp_awk_valtostr ( run, xp_awk_getarg(run, 0), @@ -1174,7 +1175,7 @@ static int __bfn_sin (xp_awk_run_t* run) xp_real_t rv; nargs = xp_awk_getnargs (run); - xp_assert (nargs == 1); + xp_awk_assert (run->awk, nargs == 1); n = xp_awk_valtonum (run, xp_awk_getarg(run, 0), &lv, &rv); if (n == -1) diff --git a/ase/awk/map.c b/ase/awk/map.c index 788c5d3e..dd4dadde 100644 --- a/ase/awk/map.c +++ b/ase/awk/map.c @@ -1,5 +1,5 @@ /* - * $Id: map.c,v 1.25 2006-09-22 14:04:25 bacon Exp $ + * $Id: map.c,v 1.26 2006-10-12 04:17:31 bacon Exp $ */ #include @@ -75,7 +75,7 @@ void xp_awk_map_clear (xp_awk_map_t* map) map->buck[i] = XP_NULL; } - xp_assert (map->size == 0); + xp_awk_assert (map->awk, map->size == 0); } xp_awk_pair_t* xp_awk_map_get ( diff --git a/ase/awk/misc.c b/ase/awk/misc.c index 7a94be8d..102997bd 100644 --- a/ase/awk/misc.c +++ b/ase/awk/misc.c @@ -1,5 +1,5 @@ /* - * $Id: misc.c,v 1.26 2006-10-09 14:37:14 bacon Exp $ + * $Id: misc.c,v 1.27 2006-10-12 04:17:31 bacon Exp $ */ #include @@ -43,7 +43,7 @@ xp_long_t xp_awk_strxtolong ( xp_size_t rem; int digit, negative = 0; - xp_assert (base < 37); + xp_awk_assert (awk, base < 37); p = str; end = str + len; @@ -995,7 +995,7 @@ xp_char_t* xp_awk_strxntokbyrex ( return XP_NULL; } - xp_assert (n == 1); + xp_awk_assert (run->awk, n == 1); if (match_len == 0) { @@ -1060,4 +1060,12 @@ exit_loop: } } - +int xp_awk_abort (xp_awk_t* awk, + const xp_char_t* expr, const xp_char_t* file, int line) +{ + awk->syscas->dprintf ( + XP_T("ASSERTION FAILURE AT FILE %s, LINE %d\n%s\n"), + file, line, expr); + awk->syscas->abort (); + return 0; +} diff --git a/ase/awk/misc.h b/ase/awk/misc.h index f061022d..db6b9230 100644 --- a/ase/awk/misc.h +++ b/ase/awk/misc.h @@ -1,5 +1,5 @@ /* - * $Id: misc.h,v 1.2 2006-09-25 06:17:19 bacon Exp $ + * $Id: misc.h,v 1.3 2006-10-12 04:17:31 bacon Exp $ */ #ifndef _XP_AWK_MISC_H_ @@ -17,27 +17,30 @@ void* xp_awk_memcpy (void* dst, const void* src, xp_size_t n); void* xp_awk_memset (void* dst, int val, xp_size_t n); xp_char_t* xp_awk_strtok ( - xp_awk_run_t* awk, const xp_char_t* s, + xp_awk_run_t* run, const xp_char_t* s, const xp_char_t* delim, xp_char_t** tok, xp_size_t* tok_len); xp_char_t* xp_awk_strxtok ( - xp_awk_run_t* awk, const xp_char_t* s, xp_size_t len, + xp_awk_run_t* run, const xp_char_t* s, xp_size_t len, const xp_char_t* delim, xp_char_t** tok, xp_size_t* tok_len); xp_char_t* xp_awk_strntok ( - xp_awk_run_t* awk, const xp_char_t* s, + xp_awk_run_t* run, const xp_char_t* s, const xp_char_t* delim, xp_size_t delim_len, xp_char_t** tok, xp_size_t* tok_len); xp_char_t* xp_awk_strxntok ( - xp_awk_run_t* awk, const xp_char_t* s, xp_size_t len, + xp_awk_run_t* run, const xp_char_t* s, xp_size_t len, const xp_char_t* delim, xp_size_t delim_len, xp_char_t** tok, xp_size_t* tok_len); xp_char_t* xp_awk_strxntokbyrex ( - xp_awk_run_t* awk, const xp_char_t* s, xp_size_t len, + xp_awk_run_t* run, const xp_char_t* s, xp_size_t len, void* rex, xp_char_t** tok, xp_size_t* tok_len, int* errnum); +int xp_awk_abort (xp_awk_t* awk, + const xp_char_t* expr, const xp_char_t* file, int line); + #ifdef __cplusplus } #endif diff --git a/ase/awk/parse.c b/ase/awk/parse.c index 1b36688b..8637f6f3 100644 --- a/ase/awk/parse.c +++ b/ase/awk/parse.c @@ -1,5 +1,5 @@ /* - * $Id: parse.c,v 1.187 2006-10-06 14:34:37 bacon Exp $ + * $Id: parse.c,v 1.188 2006-10-12 04:17:31 bacon Exp $ */ #include @@ -320,7 +320,7 @@ int xp_awk_parse (xp_awk_t* awk, xp_awk_srcios_t* srcios) { int n = 0; - xp_assert (srcios != XP_NULL && srcios->in != XP_NULL); + xp_awk_assert (awk, srcios != XP_NULL && srcios->in != XP_NULL); xp_awk_clear (awk); awk->src.ios = srcios; @@ -399,7 +399,7 @@ static xp_awk_t* __parse_progunit (xp_awk_t* awk) function name (parameter-list) { statement } */ - xp_assert (awk->parse.depth.loop == 0); + xp_awk_assert (awk, awk->parse.depth.loop == 0); if ((awk->option & XP_AWK_EXPLICIT) && MATCH(awk,TOKEN_GLOBAL)) { @@ -484,7 +484,7 @@ static xp_awk_t* __parse_progunit (xp_awk_t* awk) ptn = __parse_expression (awk); if (ptn == XP_NULL) return XP_NULL; - xp_assert (ptn->next == XP_NULL); + xp_awk_assert (awk, ptn->next == XP_NULL); if (MATCH(awk,TOKEN_COMMA)) { @@ -559,7 +559,7 @@ static xp_awk_nde_t* __parse_function (xp_awk_t* awk) int n; /* eat up the keyword 'function' and get the next token */ - xp_assert (MATCH(awk,TOKEN_FUNCTION)); + xp_awk_assert (awk, MATCH(awk,TOKEN_FUNCTION)); if (__get_token(awk) == -1) return XP_NULL; /* match a function name */ @@ -614,7 +614,7 @@ static xp_awk_nde_t* __parse_function (xp_awk_t* awk) } /* make sure that parameter table is empty */ - xp_assert (xp_awk_tab_getsize(&awk->parse.params) == 0); + xp_awk_assert (awk, xp_awk_tab_getsize(&awk->parse.params) == 0); /* read parameter list */ if (MATCH(awk,TOKEN_RPAREN)) @@ -773,7 +773,7 @@ static xp_awk_nde_t* __parse_function (xp_awk_t* awk) } /* duplicate functions should have been detected previously */ - xp_assert (n != 0); + xp_awk_assert (awk, n != 0); afn->name = pair->key; /* do some trick to save a string. */ afn->name_len = pair->key_len; @@ -786,7 +786,7 @@ static xp_awk_nde_t* __parse_begin (xp_awk_t* awk) { xp_awk_nde_t* nde; - xp_assert (MATCH(awk,TOKEN_LBRACE)); + xp_awk_assert (awk, MATCH(awk,TOKEN_LBRACE)); if (__get_token(awk) == -1) return XP_NULL; nde = __parse_block(awk, xp_true); @@ -800,7 +800,7 @@ static xp_awk_nde_t* __parse_end (xp_awk_t* awk) { xp_awk_nde_t* nde; - xp_assert (MATCH(awk,TOKEN_LBRACE)); + xp_awk_assert (awk, MATCH(awk,TOKEN_LBRACE)); if (__get_token(awk) == -1) return XP_NULL; nde = __parse_block(awk, xp_true); @@ -819,7 +819,7 @@ static xp_awk_chain_t* __parse_pattern_block ( if (blockless) nde = XP_NULL; else { - xp_assert (MATCH(awk,TOKEN_LBRACE)); + xp_awk_assert (awk, MATCH(awk,TOKEN_LBRACE)); if (__get_token(awk) == -1) return XP_NULL; nde = __parse_block(awk, xp_true); if (nde == XP_NULL) return XP_NULL; @@ -1281,7 +1281,7 @@ static xp_awk_nde_t* __parse_expression (xp_awk_t* awk) return x; } - xp_assert (x->next == XP_NULL); + xp_awk_assert (awk, x->next == XP_NULL); if (!__is_var(x) && x->type != XP_AWK_NDE_POS) { xp_awk_clrpt (awk, x); @@ -1965,7 +1965,7 @@ static xp_awk_nde_t* __parse_primary (xp_awk_t* awk) } nde->len = XP_AWK_STR_LEN(&awk->token.name); - xp_assert ( + xp_awk_assert (awk, XP_AWK_STR_LEN(&awk->token.name) == xp_awk_strlen(XP_AWK_STR_BUF(&awk->token.name))); @@ -2001,7 +2001,7 @@ static xp_awk_nde_t* __parse_primary (xp_awk_t* awk) } nde->len = XP_AWK_STR_LEN(&awk->token.name); - xp_assert ( + xp_awk_assert (awk, XP_AWK_STR_LEN(&awk->token.name) == xp_awk_strlen(XP_AWK_STR_BUF(&awk->token.name))); @@ -2052,7 +2052,7 @@ static xp_awk_nde_t* __parse_primary (xp_awk_t* awk) SET_TOKEN_TYPE (awk, TOKEN_REX); xp_awk_str_clear (&awk->token.name); if (__get_rexstr (awk) == -1) return XP_NULL; - xp_assert (MATCH(awk,TOKEN_REX)); + xp_awk_assert (awk, MATCH(awk,TOKEN_REX)); nde = (xp_awk_nde_rex_t*) XP_AWK_MALLOC ( awk, xp_sizeof(xp_awk_nde_rex_t)); @@ -2132,7 +2132,7 @@ static xp_awk_nde_t* __parse_primary (xp_awk_t* awk) /* parse subsequent expressions separated by a comma, if any */ last = nde; - xp_assert (last->next == XP_NULL); + xp_awk_assert (awk, last->next == XP_NULL); while (MATCH(awk,TOKEN_COMMA)) { @@ -2151,7 +2151,7 @@ static xp_awk_nde_t* __parse_primary (xp_awk_t* awk) return XP_NULL; } - xp_assert (tmp->next == XP_NULL); + xp_awk_assert (awk, tmp->next == XP_NULL); last->next = tmp; last = tmp; } @@ -2266,7 +2266,7 @@ static xp_awk_nde_t* __parse_primary_ident (xp_awk_t* awk) xp_size_t name_len; xp_awk_bfn_t* bfn; - xp_assert (MATCH(awk,TOKEN_IDENT)); + xp_awk_assert (awk, MATCH(awk,TOKEN_IDENT)); name_dup = xp_awk_strxdup ( awk, @@ -2423,7 +2423,7 @@ static xp_awk_nde_t* __parse_hashidx ( if (idx == XP_NULL) { - xp_assert (last == XP_NULL); + xp_awk_assert (awk, last == XP_NULL); idx = tmp; last = tmp; } else @@ -2434,7 +2434,7 @@ static xp_awk_nde_t* __parse_hashidx ( } while (MATCH(awk,TOKEN_COMMA)); - xp_assert (idx != XP_NULL); + xp_awk_assert (awk, idx != XP_NULL); if (!MATCH(awk,TOKEN_RBRACK)) { @@ -3645,7 +3645,7 @@ static int __get_number (xp_awk_t* awk) { xp_cint_t c; - xp_assert (XP_AWK_STR_LEN(&awk->token.name) == 0); + xp_awk_assert (awk, XP_AWK_STR_LEN(&awk->token.name) == 0); SET_TOKEN_TYPE (awk, TOKEN_INT); c = awk->src.lex.curc; @@ -4123,7 +4123,7 @@ static int __deparse (xp_awk_t* awk) struct __deparse_func_t df; int n; - xp_assert (awk->src.ios->out != XP_NULL); + xp_awk_assert (awk, awk->src.ios->out != XP_NULL); awk->src.shared.buf_len = 0; awk->src.shared.buf_pos = 0; @@ -4143,7 +4143,7 @@ static int __deparse (xp_awk_t* awk) { xp_size_t i, n; - xp_assert (awk->tree.nglobals > 0); + xp_awk_assert (awk, awk->tree.nglobals > 0); if (xp_awk_putsrcstr (awk, XP_T("global ")) == -1) EXIT_DEPARSE (XP_AWK_ESRCOUTWRITE); @@ -4151,7 +4151,7 @@ static int __deparse (xp_awk_t* awk) { n = xp_awk_longtostr ((xp_long_t)i, 10, XP_T("__global"), tmp, xp_countof(tmp)); - xp_assert (n != (xp_size_t)-1); + xp_awk_assert (awk, n != (xp_size_t)-1); if (xp_awk_putsrcstrx (awk, tmp, n) == -1) EXIT_DEPARSE (XP_AWK_ESRCOUTWRITE); if (xp_awk_putsrcstr (awk, XP_T(", ")) == -1) @@ -4160,7 +4160,7 @@ static int __deparse (xp_awk_t* awk) n = xp_awk_longtostr ((xp_long_t)i, 10, XP_T("__global"), tmp, xp_countof(tmp)); - xp_assert (n != (xp_size_t)-1); + xp_awk_assert (awk, n != (xp_size_t)-1); if (xp_awk_putsrcstrx (awk, tmp, n) == -1) EXIT_DEPARSE (XP_AWK_ESRCOUTWRITE); if (xp_awk_putsrcstr (awk, XP_T(";\n\n")) == -1) @@ -4245,7 +4245,7 @@ static int __deparse_func (xp_awk_pair_t* pair, void* arg) xp_awk_afn_t* afn = (xp_awk_afn_t*)pair->val; xp_size_t i, n; - xp_assert (xp_awk_strxncmp ( + xp_awk_assert (df->awk, xp_awk_strxncmp ( pair->key, pair->key_len, afn->name, afn->name_len) == 0); if (xp_awk_putsrcstr (df->awk, XP_T("function ")) == -1) return -1; @@ -4256,7 +4256,7 @@ static int __deparse_func (xp_awk_pair_t* pair, void* arg) { n = xp_awk_longtostr (i++, 10, XP_T("__param"), df->tmp, df->tmp_len); - xp_assert (n != (xp_size_t)-1); + xp_awk_assert (df->awk, n != (xp_size_t)-1); if (xp_awk_putsrcstrx (df->awk, df->tmp, n) == -1) return -1; if (i >= afn->nargs) break; if (xp_awk_putsrcstr (df->awk, XP_T(", ")) == -1) return -1; @@ -4284,7 +4284,7 @@ static int __flush (xp_awk_t* awk) { xp_ssize_t n; - xp_assert (awk->src.ios->out != XP_NULL); + xp_awk_assert (awk, awk->src.ios->out != XP_NULL); while (awk->src.shared.buf_pos < awk->src.shared.buf_len) { diff --git a/ase/awk/rec.c b/ase/awk/rec.c index 32ad6014..47099c48 100644 --- a/ase/awk/rec.c +++ b/ase/awk/rec.c @@ -1,5 +1,5 @@ /* - * $Id: rec.c,v 1.1 2006-10-03 14:57:01 bacon Exp $ + * $Id: rec.c,v 1.2 2006-10-12 04:17:31 bacon Exp $ */ #include @@ -42,7 +42,7 @@ int xp_awk_setrec ( return -1; } - xp_assert (run->inrec.d0->type == XP_AWK_VAL_NIL); + xp_awk_assert (run->awk, run->inrec.d0->type == XP_AWK_VAL_NIL); /* d0 should be cleared before the next line is reached * as it doesn't call xp_awk_refdownval on run->inrec.d0 */ run->inrec.d0 = v; @@ -95,7 +95,7 @@ static int __split_record (xp_awk_run_t* run) int errnum; /* inrec should be cleared before __split_record is called */ - xp_assert (run->inrec.nflds == 0); + xp_awk_assert (run->awk, run->inrec.nflds == 0); /* get FS */ fs = xp_awk_getglobal (run, XP_AWK_GLOBAL_FS); @@ -114,7 +114,7 @@ static int __split_record (xp_awk_run_t* run) else { fs_ptr = xp_awk_valtostr ( - run, fs, xp_true, XP_NULL, &fs_len); + run, fs, XP_AWK_VALTOSTR_CLEAR, XP_NULL, &fs_len); if (fs_ptr == XP_NULL) return -1; fs_free = fs_ptr; } @@ -152,7 +152,8 @@ static int __split_record (xp_awk_run_t* run) return 0; } - xp_assert ((tok != XP_NULL && tok_len > 0) || tok_len == 0); + xp_awk_assert (run->awk, + (tok != XP_NULL && tok_len > 0) || tok_len == 0); nflds++; len = XP_AWK_STR_LEN(&run->inrec.line) - @@ -201,7 +202,8 @@ static int __split_record (xp_awk_run_t* run) } } - xp_assert ((tok != XP_NULL && tok_len > 0) || tok_len == 0); + xp_awk_assert (run->awk, + (tok != XP_NULL && tok_len > 0) || tok_len == 0); run->inrec.flds[run->inrec.nflds].ptr = tok; run->inrec.flds[run->inrec.nflds].len = tok_len; @@ -234,7 +236,7 @@ static int __split_record (xp_awk_run_t* run) if (xp_awk_setglobal (run, XP_AWK_GLOBAL_NF, v) == -1) return -1; - xp_assert (nflds == run->inrec.nflds); + xp_awk_assert (run->awk, nflds == run->inrec.nflds); return 0; } @@ -251,11 +253,12 @@ int xp_awk_clrrec (xp_awk_run_t* run, xp_bool_t skip_inrec_line) if (run->inrec.nflds > 0) { - xp_assert (run->inrec.flds != XP_NULL); + xp_awk_assert (run->awk, run->inrec.flds != XP_NULL); for (i = 0; i < run->inrec.nflds; i++) { - xp_assert (run->inrec.flds[i].val != XP_NULL); + xp_awk_assert (run->awk, + run->inrec.flds[i].val != XP_NULL); xp_awk_refdownval (run, run->inrec.flds[i].val); } run->inrec.nflds = 0; @@ -270,7 +273,7 @@ int xp_awk_clrrec (xp_awk_run_t* run, xp_bool_t skip_inrec_line) } } - xp_assert (run->inrec.nflds == 0); + xp_awk_assert (run->awk, run->inrec.nflds == 0); if (!skip_inrec_line) xp_awk_str_clear (&run->inrec.line); return n; @@ -286,7 +289,7 @@ static int __recomp_record_fields ( /* recomposes the record and the fields when $N has been assigned * a new value and recomputes NF accordingly */ - xp_assert (lv > 0); + xp_awk_assert (run->awk, lv > 0); max = (lv > run->inrec.nflds)? lv: run->inrec.nflds; nflds = run->inrec.nflds; @@ -421,7 +424,7 @@ static int __recomp_record_fields ( } v = xp_awk_getglobal (run, XP_AWK_GLOBAL_NF); - xp_assert (v->type == XP_AWK_VAL_INT); + xp_awk_assert (run->awk, v->type == XP_AWK_VAL_INT); if (((xp_awk_val_int_t*)v)->val != max) { v = xp_awk_makeintval (run, (xp_long_t)max); diff --git a/ase/awk/rex.c b/ase/awk/rex.c index 920bae97..898fbfc8 100644 --- a/ase/awk/rex.c +++ b/ase/awk/rex.c @@ -1,5 +1,5 @@ /* - * $Id: rex.c,v 1.34 2006-10-08 05:46:41 bacon Exp $ + * $Id: rex.c,v 1.35 2006-10-12 04:17:31 bacon Exp $ */ #include @@ -384,16 +384,16 @@ int xp_awk_matchrex ( void xp_awk_freerex (xp_awk_t* awk, void* code) { - xp_assert (code != XP_NULL); + xp_awk_assert (awk, code != XP_NULL); XP_AWK_FREE (awk, code); } -xp_bool_t xp_awk_isemptyrex (void* code) +xp_bool_t xp_awk_isemptyrex (xp_awk_t* awk, void* code) { const xp_byte_t* p = code; xp_size_t nb, el; - xp_assert (p != XP_NULL); + xp_awk_assert (awk, p != XP_NULL); nb = *(xp_size_t*)p; p += xp_sizeof(nb); el = *(xp_size_t*)p; p += xp_sizeof(el); @@ -598,7 +598,7 @@ static int __build_atom (__builder_t* builder) n = __build_charset (builder, cmd); if (n == -1) return -1; - xp_assert (n != 0); + xp_awk_assert (builder->awk, n != 0); if (builder->ptn.curc.type != CT_SPECIAL || builder->ptn.curc.value != XP_T(']')) @@ -615,7 +615,7 @@ static int __build_atom (__builder_t* builder) } else { - xp_assert (builder->ptn.curc.type == CT_NORMAL); + xp_awk_assert (builder->awk, builder->ptn.curc.type == CT_NORMAL); tmp.cmd = CMD_ORD_CHAR; tmp.negate = 0; @@ -1145,8 +1145,9 @@ static const xp_byte_t* __match_atom ( __match_group }; - xp_assert (((struct __code_t*)base)->cmd >= 0 && - ((struct __code_t*)base)->cmd < xp_countof(matchers)); + xp_awk_assert (matcher->awk, + ((struct __code_t*)base)->cmd >= 0 && + ((struct __code_t*)base)->cmd < xp_countof(matchers)); return matchers[((struct __code_t*)base)->cmd] (matcher, base, mat); } @@ -1158,7 +1159,7 @@ static const xp_byte_t* __match_bol ( const struct __code_t* cp; cp = (const struct __code_t*)p; p += xp_sizeof(*cp); - xp_assert (cp->cmd == CMD_BOL); + xp_awk_assert (matcher->awk, cp->cmd == CMD_BOL); mat->matched = (mat->match_ptr == matcher->match.str.ptr || (cp->lbound == cp->ubound && cp->lbound == 0)); @@ -1174,7 +1175,7 @@ static const xp_byte_t* __match_eol ( const struct __code_t* cp; cp = (const struct __code_t*)p; p += xp_sizeof(*cp); - xp_assert (cp->cmd == CMD_EOL); + xp_awk_assert (matcher->awk, cp->cmd == CMD_EOL); mat->matched = (mat->match_ptr == matcher->match.str.end || (cp->lbound == cp->ubound && cp->lbound == 0)); @@ -1191,7 +1192,7 @@ static const xp_byte_t* __match_any_char ( xp_size_t si = 0, lbound, ubound; cp = (const struct __code_t*)p; p += xp_sizeof(*cp); - xp_assert (cp->cmd == CMD_ANY_CHAR); + xp_awk_assert (matcher->awk, cp->cmd == CMD_ANY_CHAR); lbound = cp->lbound; ubound = cp->ubound; @@ -1241,7 +1242,7 @@ static const xp_byte_t* __match_ord_char ( xp_char_t cc; cp = (const struct __code_t*)p; p += xp_sizeof(*cp); - xp_assert (cp->cmd == CMD_ORD_CHAR); + xp_awk_assert (matcher->awk, cp->cmd == CMD_ORD_CHAR); lbound = cp->lbound; ubound = cp->ubound; @@ -1329,7 +1330,7 @@ static const xp_byte_t* __match_charset ( xp_char_t c; cp = (const struct __code_t*)p; p += xp_sizeof(*cp); - xp_assert (cp->cmd == CMD_CHARSET); + xp_awk_assert (matcher->awk, cp->cmd == CMD_CHARSET); lbound = cp->lbound; ubound = cp->ubound; @@ -1373,7 +1374,7 @@ static const xp_byte_t* __match_group ( xp_size_t si = 0, grp_len_static[16], * grp_len; cp = (const struct __code_t*)p; p += xp_sizeof(*cp); - xp_assert (cp->cmd == CMD_GROUP); + xp_awk_assert (matcher->awk, cp->cmd == CMD_GROUP); mat->matched = xp_false; mat->match_len = 0; @@ -1454,7 +1455,7 @@ static const xp_byte_t* __match_group ( } else { - xp_assert (cp->ubound > cp->lbound); + xp_awk_assert (matcher->awk, cp->ubound > cp->lbound); do { @@ -1499,7 +1500,7 @@ static const xp_byte_t* __match_occurrences ( __matcher_t* matcher, xp_size_t si, const xp_byte_t* p, xp_size_t lbound, xp_size_t ubound, __match_t* mat) { - xp_assert (si >= lbound && si <= ubound); + xp_awk_assert (matcher->awk, si >= lbound && si <= ubound); /* the match has been found */ if (lbound == ubound || p >= mat->branch_end) @@ -1552,7 +1553,7 @@ static const xp_byte_t* __match_occurrences ( * lbound in the implementation below, though) */ - xp_assert (ubound > lbound); + xp_awk_assert (matcher->awk, ubound > lbound); do { @@ -1624,7 +1625,8 @@ xp_bool_t __test_charset ( } else { - xp_assert (!"should never happen - invalid charset code"); + xp_awk_assert (matcher->awk, + !"should never happen - invalid charset code"); break; } @@ -1799,7 +1801,7 @@ static const xp_byte_t* __print_atom (const xp_byte_t* p) } else { - xp_assert (!"should never happen - invalid charset code"); + xp_printf ("should never happen - invalid charset code\n"); } p += xp_sizeof(c1); @@ -1816,7 +1818,7 @@ static const xp_byte_t* __print_atom (const xp_byte_t* p) } else { - xp_assert (!"should never happen - invalid atom code"); + xp_printf ("should never happen - invalid atom code\n"); } if (cp->lbound == 0 && cp->ubound == BOUND_MAX) diff --git a/ase/awk/rex.h b/ase/awk/rex.h index 05192811..040e4e11 100644 --- a/ase/awk/rex.h +++ b/ase/awk/rex.h @@ -1,5 +1,5 @@ /* - * $Id: rex.h,v 1.17 2006-10-04 10:11:04 bacon Exp $ + * $Id: rex.h,v 1.18 2006-10-12 04:17:31 bacon Exp $ **/ #ifndef _XP_AWK_REX_H_ @@ -62,7 +62,7 @@ int xp_awk_matchrex ( void xp_awk_freerex (xp_awk_t* awk, void* code); -xp_bool_t xp_awk_isemptyrex (void* code); +xp_bool_t xp_awk_isemptyrex (xp_awk_t* awk, void* code); void xp_awk_printrex (void* code); diff --git a/ase/awk/run.c b/ase/awk/run.c index 5a8e65d6..82df838d 100644 --- a/ase/awk/run.c +++ b/ase/awk/run.c @@ -1,5 +1,5 @@ /* - * $Id: run.c,v 1.232 2006-10-11 15:01:55 bacon Exp $ + * $Id: run.c,v 1.233 2006-10-12 04:17:31 bacon Exp $ */ #include @@ -183,7 +183,7 @@ static xp_awk_val_t* __eval_getline (xp_awk_run_t* run, xp_awk_nde_t* nde); static int __raw_push (xp_awk_run_t* run, void* val); #define __raw_pop(run) \ do { \ - xp_assert ((run)->stack_top > (run)->stack_base); \ + xp_awk_assert (run->awk, (run)->stack_top > (run)->stack_base); \ (run)->stack_top--; \ } while (0) static void __raw_pop_times (xp_awk_run_t* run, xp_size_t times); @@ -247,7 +247,7 @@ int xp_awk_setglobal (xp_awk_run_t* run, xp_size_t idx, xp_awk_val_t* val) xp_size_t convfmt_len; convfmt_ptr = xp_awk_valtostr ( - run, val, xp_true, XP_NULL, &convfmt_len); + run, val, XP_AWK_VALTOSTR_CLEAR, XP_NULL, &convfmt_len); if (convfmt_ptr == XP_NULL) return -1; run->global.convfmt.ptr = convfmt_ptr; @@ -267,10 +267,10 @@ int xp_awk_setglobal (xp_awk_run_t* run, xp_size_t idx, xp_awk_val_t* val) { /* due to the expression evaluation rule, the * regular expression can not be an assigned value */ - xp_assert (val->type != XP_AWK_VAL_REX); + xp_awk_assert (run->awk, val->type != XP_AWK_VAL_REX); fs_ptr = xp_awk_valtostr ( - run, val, xp_true, XP_NULL, &fs_len); + run, val, XP_AWK_VALTOSTR_CLEAR, XP_NULL, &fs_len); if (fs_ptr == XP_NULL) return -1; } @@ -335,7 +335,7 @@ int xp_awk_setglobal (xp_awk_run_t* run, xp_size_t idx, xp_awk_val_t* val) xp_size_t ofmt_len; ofmt_ptr = xp_awk_valtostr ( - run, val, xp_true, XP_NULL, &ofmt_len); + run, val, XP_AWK_VALTOSTR_CLEAR, XP_NULL, &ofmt_len); if (ofmt_ptr == XP_NULL) return -1; run->global.ofmt.ptr = ofmt_ptr; @@ -347,7 +347,7 @@ int xp_awk_setglobal (xp_awk_run_t* run, xp_size_t idx, xp_awk_val_t* val) xp_size_t ofs_len; ofs_ptr = xp_awk_valtostr ( - run, val, xp_true, XP_NULL, &ofs_len); + run, val, XP_AWK_VALTOSTR_CLEAR, XP_NULL, &ofs_len); if (ofs_ptr == XP_NULL) return -1; run->global.ofs.ptr = ofs_ptr; @@ -359,7 +359,7 @@ int xp_awk_setglobal (xp_awk_run_t* run, xp_size_t idx, xp_awk_val_t* val) xp_size_t ors_len; ors_ptr = xp_awk_valtostr ( - run, val, xp_true, XP_NULL, &ors_len); + run, val, XP_AWK_VALTOSTR_CLEAR, XP_NULL, &ors_len); if (ors_ptr == XP_NULL) return -1; run->global.ors.ptr = ors_ptr; @@ -379,10 +379,10 @@ int xp_awk_setglobal (xp_awk_run_t* run, xp_size_t idx, xp_awk_val_t* val) { /* due to the expression evaluation rule, the * regular expression can not be an assigned value */ - xp_assert (val->type != XP_AWK_VAL_REX); + xp_awk_assert (run->awk, val->type != XP_AWK_VAL_REX); rs_ptr = xp_awk_valtostr ( - run, val, xp_true, XP_NULL, &rs_len); + run, val, XP_AWK_VALTOSTR_CLEAR, XP_NULL, &rs_len); if (rs_ptr == XP_NULL) return -1; } @@ -416,7 +416,7 @@ int xp_awk_setglobal (xp_awk_run_t* run, xp_size_t idx, xp_awk_val_t* val) xp_size_t subsep_len; subsep_ptr = xp_awk_valtostr ( - run, val, xp_true, XP_NULL, &subsep_len); + run, val, XP_AWK_VALTOSTR_CLEAR, XP_NULL, &subsep_len); if (subsep_ptr == XP_NULL) return -1; run->global.subsep.ptr = subsep_ptr; @@ -517,7 +517,7 @@ int xp_awk_stop (xp_awk_t* awk, xp_awk_run_t* run) { if (r == run) { - xp_assert (r->awk == awk); + xp_awk_assert (run->awk, r->awk == awk); r->exit_level = EXIT_ABORT; break; } @@ -573,7 +573,7 @@ static void __del_run (xp_awk_t* awk, xp_awk_run_t* run) { XP_AWK_LOCK (awk); - xp_assert (awk->run.ptr != XP_NULL); + xp_awk_assert (run->awk, awk->run.ptr != XP_NULL); if (run->prev == XP_NULL) { @@ -671,7 +671,7 @@ static void __deinit_run (xp_awk_run_t* run) /* close all pending eio's */ /* TODO: what if this operation fails? */ xp_awk_clearextio (run); - xp_assert (run->extio.chain == XP_NULL); + xp_awk_assert (run->awk, run->extio.chain == XP_NULL); if (run->global.rs != XP_NULL) { @@ -739,7 +739,7 @@ static void __deinit_run (xp_awk_run_t* run) /* destroy run stack */ if (run->stack != XP_NULL) { - xp_assert (run->stack_top == 0); + xp_awk_assert (run->awk, run->stack_top == 0); XP_AWK_FREE (run->awk, run->stack); run->stack = XP_NULL; @@ -801,7 +801,7 @@ static int __build_runarg (xp_awk_run_t* run, xp_awk_runarg_t* runarg) key_len = xp_awk_longtostr ( argc, 10, XP_NULL, key, xp_countof(key)); - xp_assert (key_len != (xp_size_t)-1); + xp_awk_assert (run->awk, key_len != (xp_size_t)-1); /* increment reference count of v_tmp in advance as if * it has successfully been assigned into the ARGV map */ @@ -834,7 +834,7 @@ static int __build_runarg (xp_awk_run_t* run, xp_awk_runarg_t* runarg) xp_awk_refupval (v_argc); - xp_assert (STACK_GLOBAL(run,XP_AWK_GLOBAL_ARGC) == xp_awk_val_nil); + xp_awk_assert (run->awk, STACK_GLOBAL(run,XP_AWK_GLOBAL_ARGC) == xp_awk_val_nil); if (xp_awk_setglobal (run, XP_AWK_GLOBAL_ARGC, v_argc) == -1) { @@ -869,7 +869,7 @@ static int __run_main (xp_awk_run_t* run, xp_awk_runarg_t* runarg) xp_awk_val_t* v; int n = 0; - xp_assert (run->stack_base == 0 && run->stack_top == 0); + xp_awk_assert (run->awk, run->stack_base == 0 && run->stack_top == 0); /* secure space for global variables */ saved_stack_top = run->stack_top; @@ -990,7 +990,7 @@ static int __run_main (xp_awk_run_t* run, xp_awk_runarg_t* runarg) xp_awk_nde_blk_t* blk; blk = (xp_awk_nde_blk_t*)run->awk->tree.begin; - xp_assert (blk->type == XP_AWK_NDE_BLK); + xp_awk_assert (run->awk, blk->type == XP_AWK_NDE_BLK); run->active_block = blk; run->exit_level = EXIT_NONE; @@ -1011,7 +1011,7 @@ static int __run_main (xp_awk_run_t* run, xp_awk_runarg_t* runarg) xp_awk_nde_blk_t* blk; blk = (xp_awk_nde_blk_t*)run->awk->tree.end; - xp_assert (blk->type == XP_AWK_NDE_BLK); + xp_awk_assert (run->awk, blk->type == XP_AWK_NDE_BLK); run->active_block = blk; run->exit_level = EXIT_NONE; @@ -1020,7 +1020,7 @@ static int __run_main (xp_awk_run_t* run, xp_awk_runarg_t* runarg) /* restore stack */ nargs = (xp_size_t)STACK_NARGS(run); - xp_assert (nargs == 0); + xp_awk_assert (run->awk, nargs == 0); for (i = 0; i < nargs; i++) { xp_awk_refdownval (run, STACK_ARG(run,i)); @@ -1176,7 +1176,7 @@ static int __run_pattern_block ( xp_awk_refupval (v1); - if (xp_awk_valtobool(v1)) + if (xp_awk_valtobool (run, v1)) { run->active_block = blk; if (__run_block (run, blk) == -1) @@ -1191,7 +1191,7 @@ static int __run_pattern_block ( else { /* pattern, pattern { ... } */ - xp_assert (ptn->next->next == XP_NULL); + xp_awk_assert (run->awk, ptn->next->next == XP_NULL); if (run->pattern_range_state[block_no] == 0) { @@ -1201,7 +1201,7 @@ static int __run_pattern_block ( if (v1 == XP_NULL) return -1; xp_awk_refupval (v1); - if (xp_awk_valtobool(v1)) + if (xp_awk_valtobool (run, v1)) { run->active_block = blk; if (__run_block (run, blk) == -1) @@ -1230,7 +1230,7 @@ static int __run_pattern_block ( return -1; } - if (xp_awk_valtobool(v2)) + if (xp_awk_valtobool (run, v2)) run->pattern_range_state[block_no] = 0; xp_awk_refdownval (run, v2); @@ -1272,7 +1272,7 @@ static int __run_block (xp_awk_run_t* run, xp_awk_nde_blk_t* nde) return 0; } - xp_assert (nde->type == XP_AWK_NDE_BLK); + xp_awk_assert (run->awk, nde->type == XP_AWK_NDE_BLK); p = nde->body; nlocals = nde->nlocals; @@ -1445,13 +1445,13 @@ static int __run_if (xp_awk_run_t* run, xp_awk_nde_if_t* nde) /* the test expression for the if statement cannot have * chained expressions. this should not be allowed by the * parser first of all */ - xp_assert (nde->test->next == XP_NULL); + xp_awk_assert (run->awk, nde->test->next == XP_NULL); test = __eval_expression (run, nde->test); if (test == XP_NULL) return -1; xp_awk_refupval (test); - if (xp_awk_valtobool(test)) + if (xp_awk_valtobool (run, test)) { n = __run_statement (run, nde->then_part); } @@ -1472,7 +1472,7 @@ static int __run_while (xp_awk_run_t* run, xp_awk_nde_while_t* nde) { /* no chained expressions are allowed for the test * expression of the while statement */ - xp_assert (nde->test->next == XP_NULL); + xp_awk_assert (run->awk, nde->test->next == XP_NULL); /* TODO: handle run-time abortion... */ while (1) @@ -1482,7 +1482,7 @@ static int __run_while (xp_awk_run_t* run, xp_awk_nde_while_t* nde) xp_awk_refupval (test); - if (xp_awk_valtobool(test)) + if (xp_awk_valtobool (run, test)) { if (__run_statement(run,nde->body) == -1) { @@ -1514,7 +1514,7 @@ static int __run_while (xp_awk_run_t* run, xp_awk_nde_while_t* nde) { /* no chained expressions are allowed for the test * expression of the while statement */ - xp_assert (nde->test->next == XP_NULL); + xp_awk_assert (run->awk, nde->test->next == XP_NULL); /* TODO: handle run-time abortion... */ do @@ -1537,7 +1537,7 @@ static int __run_while (xp_awk_run_t* run, xp_awk_nde_while_t* nde) xp_awk_refupval (test); - if (!xp_awk_valtobool(test)) + if (!xp_awk_valtobool (run, test)) { xp_awk_refdownval (run, test); break; @@ -1557,7 +1557,7 @@ static int __run_for (xp_awk_run_t* run, xp_awk_nde_for_t* nde) if (nde->init != XP_NULL) { - xp_assert (nde->init->next == XP_NULL); + xp_awk_assert (run->awk, nde->init->next == XP_NULL); val = __eval_expression(run,nde->init); if (val == XP_NULL) return -1; @@ -1573,13 +1573,13 @@ static int __run_for (xp_awk_run_t* run, xp_awk_nde_for_t* nde) /* no chained expressions for the test expression of * the for statement are allowed */ - xp_assert (nde->test->next == XP_NULL); + xp_awk_assert (run->awk, nde->test->next == XP_NULL); test = __eval_expression (run, nde->test); if (test == XP_NULL) return -1; xp_awk_refupval (test); - if (xp_awk_valtobool(test)) + if (xp_awk_valtobool (run, test)) { if (__run_statement(run,nde->body) == -1) { @@ -1616,7 +1616,7 @@ static int __run_for (xp_awk_run_t* run, xp_awk_nde_for_t* nde) if (nde->incr != XP_NULL) { - xp_assert (nde->incr->next == XP_NULL); + xp_awk_assert (run->awk, nde->incr->next == XP_NULL); val = __eval_expression(run,nde->incr); if (val == XP_NULL) return -1; @@ -1670,12 +1670,12 @@ static int __run_foreach (xp_awk_run_t* run, xp_awk_nde_foreach_t* nde) struct __foreach_walker_t walker; test = (xp_awk_nde_exp_t*)nde->test; - xp_assert (test->type == XP_AWK_NDE_EXP_BIN && + xp_awk_assert (run->awk, test->type == XP_AWK_NDE_EXP_BIN && test->opcode == XP_AWK_BINOP_IN); /* chained expressions should not be allowed * by the parser first of all */ - xp_assert (test->right->next == XP_NULL); + xp_awk_assert (run->awk, test->right->next == XP_NULL); rv = __eval_expression (run, test->right); if (rv == XP_NULL) return -1; @@ -1717,7 +1717,7 @@ static int __run_return (xp_awk_run_t* run, xp_awk_nde_return_t* nde) /* chained expressions should not be allowed * by the parser first of all */ - xp_assert (nde->val->next == XP_NULL); + xp_awk_assert (run->awk, nde->val->next == XP_NULL); /*xp_printf (XP_T("returning....\n"));*/ val = __eval_expression (run, nde->val); @@ -1741,7 +1741,7 @@ static int __run_exit (xp_awk_run_t* run, xp_awk_nde_exit_t* nde) /* chained expressions should not be allowed * by the parser first of all */ - xp_assert (nde->val->next == XP_NULL); + xp_awk_assert (run->awk, nde->val->next == XP_NULL); val = __eval_expression (run, nde->val); if (val == XP_NULL) return -1; @@ -1818,7 +1818,7 @@ static int __run_delete (xp_awk_run_t* run, xp_awk_nde_delete_t* nde) { xp_awk_pair_t* pair; - xp_assert ((var->type == XP_AWK_NDE_NAMED && + xp_awk_assert (run->awk, (var->type == XP_AWK_NDE_NAMED && var->idx == XP_NULL) || (var->type == XP_AWK_NDE_NAMEDIDX && var->idx != XP_NULL)); @@ -1851,7 +1851,7 @@ static int __run_delete (xp_awk_run_t* run, xp_awk_nde_delete_t* nde) xp_awk_map_t* map; val = (xp_awk_val_t*)pair->val; - xp_assert (val != XP_NULL); + xp_awk_assert (run->awk, val != XP_NULL); if (val->type != XP_AWK_VAL_MAP) PANIC_I (run, XP_AWK_ENOTDELETABLE); @@ -1863,14 +1863,14 @@ static int __run_delete (xp_awk_run_t* run, xp_awk_nde_delete_t* nde) xp_size_t key_len; xp_awk_val_t* idx; - xp_assert (var->idx != XP_NULL); + xp_awk_assert (run->awk, var->idx != XP_NULL); idx = __eval_expression (run, var->idx); if (idx == XP_NULL) return -1; xp_awk_refupval (idx); key = xp_awk_valtostr ( - run, idx, xp_true, XP_NULL, &key_len); + run, idx, XP_AWK_VALTOSTR_CLEAR, XP_NULL, &key_len); xp_awk_refdownval (run, idx); if (key == XP_NULL) return -1; @@ -1901,7 +1901,7 @@ static int __run_delete (xp_awk_run_t* run, xp_awk_nde_delete_t* nde) val = STACK_LOCAL (run,var->id.idxa); else val = STACK_ARG (run,var->id.idxa); - xp_assert (val != XP_NULL); + xp_awk_assert (run->awk, val != XP_NULL); if (val->type == XP_AWK_VAL_NIL) { @@ -1954,14 +1954,14 @@ static int __run_delete (xp_awk_run_t* run, xp_awk_nde_delete_t* nde) xp_size_t key_len; xp_awk_val_t* idx; - xp_assert (var->idx != XP_NULL); + xp_awk_assert (run->awk, var->idx != XP_NULL); idx = __eval_expression (run, var->idx); if (idx == XP_NULL) return -1; xp_awk_refupval (idx); key = xp_awk_valtostr ( - run, idx, xp_true, XP_NULL, &key_len); + run, idx, XP_AWK_VALTOSTR_CLEAR, XP_NULL, &key_len); xp_awk_refdownval (run, idx); if (key == XP_NULL) return -1; @@ -1977,7 +1977,7 @@ static int __run_delete (xp_awk_run_t* run, xp_awk_nde_delete_t* nde) } else { - xp_assert (!"should never happen - wrong variable type for delete"); + xp_awk_assert (run->awk, !"should never happen - wrong variable type for delete"); PANIC_I (run, XP_AWK_EINTERNAL); } @@ -1993,7 +1993,7 @@ static int __run_print (xp_awk_run_t* run, xp_awk_nde_print_t* nde) xp_awk_nde_t* np; int n; - xp_assert ( + xp_awk_assert (run->awk, (p->out_type == XP_AWK_OUT_PIPE && p->out != XP_NULL) || (p->out_type == XP_AWK_OUT_COPROC && p->out != XP_NULL) || (p->out_type == XP_AWK_OUT_FILE && p->out != XP_NULL) || @@ -2008,7 +2008,8 @@ static int __run_print (xp_awk_run_t* run, xp_awk_nde_print_t* nde) if (v == XP_NULL) return -1; xp_awk_refupval (v); - out = xp_awk_valtostr (run, v, xp_true, XP_NULL, &len); + out = xp_awk_valtostr ( + run, v, XP_AWK_VALTOSTR_CLEAR, XP_NULL, &len); if (out == XP_NULL) { xp_awk_refdownval (run, v); @@ -2080,7 +2081,8 @@ static int __run_print (xp_awk_run_t* run, xp_awk_nde_print_t* nde) { n = xp_awk_writeextio_str ( run, p->out_type, dst, - run->global.ofs.ptr, run->global.ofs.len); + 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); @@ -2146,12 +2148,11 @@ static xp_awk_val_t* __eval_expression (xp_awk_run_t* run, xp_awk_nde_t* nde) /* the record has never been read. * probably, this functions has been triggered * by the statements in the BEGIN block */ - n = xp_awk_isemptyrex ( - ((xp_awk_val_rex_t*)v)->code)? 1: 0; + n = xp_awk_isemptyrex (run->awk, ((xp_awk_val_rex_t*)v)->code)? 1: 0; } else { - xp_assert (run->inrec.d0->type == XP_AWK_VAL_STR); + xp_awk_assert (run->awk, run->inrec.d0->type == XP_AWK_VAL_STR); n = xp_awk_matchrex ( ((xp_awk_run_t*)run)->awk, @@ -2208,7 +2209,7 @@ static xp_awk_val_t* __eval_expression0 (xp_awk_run_t* run, xp_awk_nde_t* nde) __eval_getline }; - xp_assert (nde->type >= XP_AWK_NDE_GRP && + xp_awk_assert (run->awk, nde->type >= XP_AWK_NDE_GRP && (nde->type - XP_AWK_NDE_GRP) < xp_countof(__eval_func)); return __eval_func[nde->type-XP_AWK_NDE_GRP] (run, nde); @@ -2218,7 +2219,7 @@ static xp_awk_val_t* __eval_group (xp_awk_run_t* run, xp_awk_nde_t* nde) { /* __eval_binop_in evaluates the XP_AWK_NDE_GRP specially. * so this function should never be reached. */ - xp_assert (!"should never happen - NDE_GRP only for in"); + xp_awk_assert (run->awk, !"should never happen - NDE_GRP only for in"); PANIC (run, XP_AWK_EINTERNAL); return XP_NULL; } @@ -2228,9 +2229,9 @@ static xp_awk_val_t* __eval_assignment (xp_awk_run_t* run, xp_awk_nde_t* nde) xp_awk_val_t* val, * ret; xp_awk_nde_ass_t* ass = (xp_awk_nde_ass_t*)nde; - xp_assert (ass->left != XP_NULL && ass->right != XP_NULL); + xp_awk_assert (run->awk, ass->left != XP_NULL && ass->right != XP_NULL); - xp_assert (ass->right->next == XP_NULL); + xp_awk_assert (run->awk, ass->right->next == XP_NULL); val = __eval_expression (run, ass->right); if (val == XP_NULL) return XP_NULL; @@ -2240,7 +2241,7 @@ static xp_awk_val_t* __eval_assignment (xp_awk_run_t* run, xp_awk_nde_t* nde) { xp_awk_val_t* val2, * tmp; - xp_assert (ass->left->next == XP_NULL); + xp_awk_assert (run->awk, ass->left->next == XP_NULL); val2 = __eval_expression (run, ass->left); if (val2 == XP_NULL) { @@ -2276,7 +2277,7 @@ static xp_awk_val_t* __eval_assignment (xp_awk_run_t* run, xp_awk_nde_t* nde) } else { - xp_assert (!"should never happen - invalid assignment opcode"); + xp_awk_assert (run->awk, !"should never happen - invalid assignment opcode"); PANIC (run, XP_AWK_EINTERNAL); } @@ -2329,7 +2330,7 @@ static xp_awk_val_t* __do_assignment ( } else { - xp_assert (!"should never happen - invalid variable type"); + xp_awk_assert (run->awk, !"should never happen - invalid variable type"); PANIC (run, XP_AWK_EINTERNAL); } @@ -2339,13 +2340,13 @@ static xp_awk_val_t* __do_assignment ( static xp_awk_val_t* __do_assignment_scalar ( xp_awk_run_t* run, xp_awk_nde_var_t* var, xp_awk_val_t* val) { - xp_assert ( + xp_awk_assert (run->awk, (var->type == XP_AWK_NDE_NAMED || var->type == XP_AWK_NDE_GLOBAL || var->type == XP_AWK_NDE_LOCAL || var->type == XP_AWK_NDE_ARG) && var->idx == XP_NULL); - xp_assert (val->type != XP_AWK_VAL_MAP); + xp_awk_assert (run->awk, val->type != XP_AWK_VAL_MAP); if (var->type == XP_AWK_NDE_NAMED) { @@ -2413,12 +2414,12 @@ static xp_awk_val_t* __do_assignment_map ( xp_size_t len; int n; - xp_assert ( + xp_awk_assert (run->awk, (var->type == XP_AWK_NDE_NAMEDIDX || var->type == XP_AWK_NDE_GLOBALIDX || var->type == XP_AWK_NDE_LOCALIDX || var->type == XP_AWK_NDE_ARGIDX) && var->idx != XP_NULL); - xp_assert (val->type != XP_AWK_VAL_MAP); + xp_awk_assert (run->awk, val->type != XP_AWK_VAL_MAP); if (var->type == XP_AWK_NDE_NAMEDIDX) { @@ -2544,7 +2545,7 @@ static xp_awk_val_t* __do_assignment_pos ( } else { - str = xp_awk_valtostr (run, val, xp_true, XP_NULL, &len); + str = xp_awk_valtostr (run, val, XP_AWK_VALTOSTR_CLEAR, XP_NULL, &len); if (str == XP_NULL) return XP_NULL; } @@ -2596,7 +2597,7 @@ static xp_awk_val_t* __eval_binary (xp_awk_run_t* run, xp_awk_nde_t* nde) xp_awk_nde_exp_t* exp = (xp_awk_nde_exp_t*)nde; xp_awk_val_t* left, * right, * res; - xp_assert (exp->type == XP_AWK_NDE_EXP_BIN); + xp_awk_assert (run->awk, exp->type == XP_AWK_NDE_EXP_BIN); if (exp->opcode == XP_AWK_BINOP_LAND) { @@ -2621,13 +2622,13 @@ static xp_awk_val_t* __eval_binary (xp_awk_run_t* run, xp_awk_nde_t* nde) } else { - xp_assert (exp->left->next == XP_NULL); + xp_awk_assert (run->awk, exp->left->next == XP_NULL); left = __eval_expression (run, exp->left); if (left == XP_NULL) return XP_NULL; xp_awk_refupval (left); - xp_assert (exp->right->next == XP_NULL); + xp_awk_assert (run->awk, exp->right->next == XP_NULL); right = __eval_expression (run, exp->right); if (right == XP_NULL) { @@ -2637,9 +2638,9 @@ static xp_awk_val_t* __eval_binary (xp_awk_run_t* run, xp_awk_nde_t* nde) xp_awk_refupval (right); - xp_assert (exp->opcode >= 0 && + xp_awk_assert (run->awk, exp->opcode >= 0 && exp->opcode < xp_countof(__binop_func)); - xp_assert (__binop_func[exp->opcode] != XP_NULL); + xp_awk_assert (run->awk, __binop_func[exp->opcode] != XP_NULL); res = __binop_func[exp->opcode] (run, left, right); @@ -2657,7 +2658,7 @@ static xp_awk_val_t* __eval_binop_lor ( xp_awk_val_t* res = XP_NULL; res = xp_awk_makeintval (run, - xp_awk_valtobool(left) || xp_awk_valtobool(right)); + xp_awk_valtobool(run left) || xp_awk_valtobool(run,right)); if (res == XP_NULL) PANIC (run, XP_AWK_ENOMEM); return res; @@ -2666,19 +2667,19 @@ static xp_awk_val_t* __eval_binop_lor ( /* short-circuit evaluation required special treatment */ xp_awk_val_t* lv, * rv, * res; - xp_assert (left->next == XP_NULL); + xp_awk_assert (run->awk, left->next == XP_NULL); lv = __eval_expression (run, left); if (lv == XP_NULL) return XP_NULL; xp_awk_refupval (lv); - if (xp_awk_valtobool(lv)) + if (xp_awk_valtobool (run, lv)) { /*res = xp_awk_makeintval (run, 1);*/ res = xp_awk_val_one; } else { - xp_assert (right->next == XP_NULL); + xp_awk_assert (run->awk, right->next == XP_NULL); rv = __eval_expression (run, right); if (rv == XP_NULL) { @@ -2687,8 +2688,8 @@ static xp_awk_val_t* __eval_binop_lor ( } xp_awk_refupval (rv); - /*res = xp_awk_makeintval (run, (xp_awk_valtobool(rv)? 1: 0));*/ - res = xp_awk_valtobool(rv)? xp_awk_val_one: xp_awk_val_zero; + /*res = xp_awk_makeintval (run, (xp_awk_valtobool(run,rv)? 1: 0));*/ + res = xp_awk_valtobool(run,rv)? xp_awk_val_one: xp_awk_val_zero; xp_awk_refdownval (run, rv); } @@ -2705,7 +2706,7 @@ static xp_awk_val_t* __eval_binop_land ( xp_awk_val_t* res = XP_NULL; res = xp_awk_makeintval (run, - xp_awk_valtobool(left) && xp_awk_valtobool(right)); + xp_awk_valtobool(run,left) && xp_awk_valtobool(run,right)); if (res == XP_NULL) PANIC (run, XP_AWK_ENOMEM); return res; @@ -2714,19 +2715,19 @@ static xp_awk_val_t* __eval_binop_land ( /* short-circuit evaluation required special treatment */ xp_awk_val_t* lv, * rv, * res; - xp_assert (left->next == XP_NULL); + xp_awk_assert (run->awk, left->next == XP_NULL); lv = __eval_expression (run, left); if (lv == XP_NULL) return XP_NULL; xp_awk_refupval (lv); - if (!xp_awk_valtobool(lv)) + if (!xp_awk_valtobool (run, lv)) { /*res = xp_awk_makeintval (run, 0);*/ res = xp_awk_val_zero; } else { - xp_assert (right->next == XP_NULL); + xp_awk_assert (run->awk, right->next == XP_NULL); rv = __eval_expression (run, right); if (rv == XP_NULL) { @@ -2735,8 +2736,8 @@ static xp_awk_val_t* __eval_binop_land ( } xp_awk_refupval (rv); - /*res = xp_awk_makeintval (run, (xp_awk_valtobool(rv)? 1: 0));*/ - res = xp_awk_valtobool(rv)? xp_awk_val_one: xp_awk_val_zero; + /*res = xp_awk_makeintval (run, (xp_awk_valtobool(run,rv)? 1: 0));*/ + res = xp_awk_valtobool(run,rv)? xp_awk_val_one: xp_awk_val_zero; xp_awk_refdownval (run, rv); } @@ -2759,7 +2760,7 @@ static xp_awk_val_t* __eval_binop_in ( right->type != XP_AWK_NDE_NAMED) { /* the compiler should have handled this case */ - xp_assert (!"should never happen - in needs a plain variable"); + xp_awk_assert (run->awk, !"should never happen - in needs a plain variable"); PANIC (run, XP_AWK_EINTERNAL); return XP_NULL; } @@ -2771,7 +2772,7 @@ static xp_awk_val_t* __eval_binop_in ( if (str == XP_NULL) return XP_NULL; /* evaluate the right-hand side of the operator */ - xp_assert (right->next == XP_NULL); + xp_awk_assert (run->awk, right->next == XP_NULL); rv = __eval_expression (run, right); if (rv == XP_NULL) { @@ -2973,7 +2974,7 @@ static int __cmp_int_str ( } } - str = xp_awk_valtostr (run, left, xp_true, XP_NULL, &len); + str = xp_awk_valtostr (run, left, XP_AWK_VALTOSTR_CLEAR, XP_NULL, &len); if (str == XP_NULL) { run->errnum = XP_AWK_ENOMEM; @@ -3047,7 +3048,7 @@ static int __cmp_real_str ( return 0; } - str = xp_awk_valtostr (run, left, xp_true, XP_NULL, &len); + str = xp_awk_valtostr (run, left, XP_AWK_VALTOSTR_CLEAR, XP_NULL, &len); if (str == XP_NULL) { run->errnum = XP_AWK_ENOMEM; @@ -3136,9 +3137,9 @@ static int __cmp_val ( return CMP_ERROR; } - xp_assert (left->type >= XP_AWK_VAL_NIL && + xp_awk_assert (run->awk, left->type >= XP_AWK_VAL_NIL && left->type <= XP_AWK_VAL_STR); - xp_assert (right->type >= XP_AWK_VAL_NIL && + xp_awk_assert (run->awk, right->type >= XP_AWK_VAL_NIL && right->type <= XP_AWK_VAL_STR); return func[left->type*4+right->type] (run, left, right); @@ -3262,7 +3263,7 @@ static xp_awk_val_t* __eval_binop_plus ( 1 1 = 3 */ n3 = n1 + (n2 << 1); - xp_assert (n3 >= 0 && n3 <= 3); + xp_awk_assert (run->awk, n3 >= 0 && n3 <= 3); res = (n3 == 0)? xp_awk_makeintval(run,(xp_long_t)l1+(xp_long_t)l2): (n3 == 1)? xp_awk_makerealval(run,(xp_real_t)r1+(xp_real_t)l2): (n3 == 2)? xp_awk_makerealval(run,(xp_real_t)l1+(xp_real_t)r2): @@ -3286,7 +3287,7 @@ static xp_awk_val_t* __eval_binop_minus ( if (n1 == -1 || n2 == -1) PANIC (run, XP_AWK_EOPERAND); n3 = n1 + (n2 << 1); - xp_assert (n3 >= 0 && n3 <= 3); + xp_awk_assert (run->awk, n3 >= 0 && n3 <= 3); res = (n3 == 0)? xp_awk_makeintval(run,(xp_long_t)l1-(xp_long_t)l2): (n3 == 1)? xp_awk_makerealval(run,(xp_real_t)r1-(xp_real_t)l2): (n3 == 2)? xp_awk_makerealval(run,(xp_real_t)l1-(xp_real_t)r2): @@ -3310,7 +3311,7 @@ static xp_awk_val_t* __eval_binop_mul ( if (n1 == -1 || n2 == -1) PANIC (run, XP_AWK_EOPERAND); n3 = n1 + (n2 << 1); - xp_assert (n3 >= 0 && n3 <= 3); + xp_awk_assert (run->awk, n3 >= 0 && n3 <= 3); res = (n3 == 0)? xp_awk_makeintval(run,(xp_long_t)l1*(xp_long_t)l2): (n3 == 1)? xp_awk_makerealval(run,(xp_real_t)r1*(xp_real_t)l2): (n3 == 2)? xp_awk_makerealval(run,(xp_real_t)l1*(xp_real_t)r2): @@ -3349,7 +3350,7 @@ static xp_awk_val_t* __eval_binop_div ( } else { - xp_assert (n3 == 3); + xp_awk_assert (run->awk, n3 == 3); res = xp_awk_makerealval (run, (xp_real_t)r1 / (xp_real_t)r2); } @@ -3417,7 +3418,7 @@ static xp_awk_val_t* __eval_binop_exp ( } else { - xp_assert (n3 == 3); + xp_awk_assert (run->awk, n3 == 3); res = xp_awk_makerealval ( run, pow((xp_real_t)r1,(xp_real_t)r2)); } @@ -3433,10 +3434,12 @@ static xp_awk_val_t* __eval_binop_concat ( xp_size_t strl_len, strr_len; xp_awk_val_t* res; - strl = xp_awk_valtostr (run, left, xp_true, XP_NULL, &strl_len); + strl = xp_awk_valtostr ( + run, left, XP_AWK_VALTOSTR_CLEAR, XP_NULL, &strl_len); if (strl == XP_NULL) return XP_NULL; - strr = xp_awk_valtostr (run, right, xp_true, XP_NULL, &strr_len); + strr = xp_awk_valtostr ( + run, right, XP_AWK_VALTOSTR_CLEAR, XP_NULL, &strr_len); if (strr == XP_NULL) { XP_AWK_FREE (run->awk, strl); @@ -3462,8 +3465,8 @@ static xp_awk_val_t* __eval_binop_ma ( { xp_awk_val_t* lv, * rv, * res; - xp_assert (left->next == XP_NULL); - xp_assert (right->next == XP_NULL); + xp_awk_assert (run->awk, left->next == XP_NULL); + xp_awk_assert (run->awk, right->next == XP_NULL); lv = __eval_expression (run, left); if (lv == XP_NULL) @@ -3495,8 +3498,8 @@ static xp_awk_val_t* __eval_binop_nm ( { xp_awk_val_t* lv, * rv, * res; - xp_assert (left->next == XP_NULL); - xp_assert (right->next == XP_NULL); + xp_awk_assert (run->awk, left->next == XP_NULL); + xp_awk_assert (run->awk, right->next == XP_NULL); lv = __eval_expression (run, left); if (lv == XP_NULL) return XP_NULL; @@ -3544,7 +3547,8 @@ static xp_awk_val_t* __eval_binop_match0 ( } else { - str = xp_awk_valtostr (run, right, xp_true, XP_NULL, &len); + str = xp_awk_valtostr ( + run, right, XP_AWK_VALTOSTR_CLEAR, XP_NULL, &len); if (str == XP_NULL) return XP_NULL; rex_code = xp_awk_buildrex (run->awk, str, len, &errnum); @@ -3582,7 +3586,8 @@ static xp_awk_val_t* __eval_binop_match0 ( } else { - str = xp_awk_valtostr (run, left, xp_true, XP_NULL, &len); + str = xp_awk_valtostr ( + run, left, XP_AWK_VALTOSTR_CLEAR, XP_NULL, &len); if (str == XP_NULL) { if (right->type != XP_AWK_VAL_REX) @@ -3623,10 +3628,10 @@ static xp_awk_val_t* __eval_unary (xp_awk_run_t* run, xp_awk_nde_t* nde) xp_awk_val_t* left, * res = XP_NULL; xp_awk_nde_exp_t* exp = (xp_awk_nde_exp_t*)nde; - xp_assert (exp->type == XP_AWK_NDE_EXP_UNR); - xp_assert (exp->left != XP_NULL && exp->right == XP_NULL); + xp_awk_assert (run->awk, exp->type == XP_AWK_NDE_EXP_UNR); + xp_awk_assert (run->awk, exp->left != XP_NULL && exp->right == XP_NULL); - xp_assert (exp->left->next == XP_NULL); + xp_awk_assert (run->awk, exp->left->next == XP_NULL); left = __eval_expression (run, exp->left); if (left == XP_NULL) return XP_NULL; @@ -3715,8 +3720,8 @@ static xp_awk_val_t* __eval_incpre (xp_awk_run_t* run, xp_awk_nde_t* nde) xp_awk_val_t* left, * res; xp_awk_nde_exp_t* exp = (xp_awk_nde_exp_t*)nde; - xp_assert (exp->type == XP_AWK_NDE_EXP_INCPRE); - xp_assert (exp->left != XP_NULL && exp->right == XP_NULL); + xp_awk_assert (run->awk, exp->type == XP_AWK_NDE_EXP_INCPRE); + xp_awk_assert (run->awk, exp->left != XP_NULL && exp->right == XP_NULL); /* this way of checking if the l-value is assignable is * ugly as it is dependent of the values defined in tree.h. @@ -3727,7 +3732,7 @@ static xp_awk_val_t* __eval_incpre (xp_awk_run_t* run, xp_awk_nde_t* nde) PANIC (run, XP_AWK_EOPERAND); } - xp_assert (exp->left->next == XP_NULL); + xp_awk_assert (run->awk, exp->left->next == XP_NULL); left = __eval_expression (run, exp->left); if (left == XP_NULL) return XP_NULL; @@ -3774,7 +3779,7 @@ static xp_awk_val_t* __eval_incpre (xp_awk_run_t* run, xp_awk_nde_t* nde) } else /* if (n == 1) */ { - xp_assert (n == 1); + xp_awk_assert (run->awk, n == 1); res = xp_awk_makerealval (run, v2 + 1.0); } @@ -3826,7 +3831,7 @@ static xp_awk_val_t* __eval_incpre (xp_awk_run_t* run, xp_awk_nde_t* nde) } else /* if (n == 1) */ { - xp_assert (n == 1); + xp_awk_assert (run->awk, n == 1); res = xp_awk_makerealval (run, v2 - 1.0); } @@ -3839,7 +3844,7 @@ static xp_awk_val_t* __eval_incpre (xp_awk_run_t* run, xp_awk_nde_t* nde) } else { - xp_assert (!"should never happen - invalid opcode"); + xp_awk_assert (run->awk, !"should never happen - invalid opcode"); xp_awk_refdownval (run, left); PANIC (run, XP_AWK_EINTERNAL); } @@ -3859,8 +3864,8 @@ static xp_awk_val_t* __eval_incpst (xp_awk_run_t* run, xp_awk_nde_t* nde) xp_awk_val_t* left, * res, * res2; xp_awk_nde_exp_t* exp = (xp_awk_nde_exp_t*)nde; - xp_assert (exp->type == XP_AWK_NDE_EXP_INCPST); - xp_assert (exp->left != XP_NULL && exp->right == XP_NULL); + xp_awk_assert (run->awk, exp->type == XP_AWK_NDE_EXP_INCPST); + xp_awk_assert (run->awk, exp->left != XP_NULL && exp->right == XP_NULL); /* this way of checking if the l-value is assignable is * ugly as it is dependent of the values defined in tree.h. @@ -3871,7 +3876,7 @@ static xp_awk_val_t* __eval_incpst (xp_awk_run_t* run, xp_awk_nde_t* nde) PANIC (run, XP_AWK_EOPERAND); } - xp_assert (exp->left->next == XP_NULL); + xp_awk_assert (run->awk, exp->left->next == XP_NULL); left = __eval_expression (run, exp->left); if (left == XP_NULL) return XP_NULL; @@ -3947,7 +3952,7 @@ static xp_awk_val_t* __eval_incpst (xp_awk_run_t* run, xp_awk_nde_t* nde) } else /* if (n == 1) */ { - xp_assert (n == 1); + xp_awk_assert (run->awk, n == 1); res = xp_awk_makerealval (run, v2); if (res == XP_NULL) { @@ -4035,7 +4040,7 @@ static xp_awk_val_t* __eval_incpst (xp_awk_run_t* run, xp_awk_nde_t* nde) } else /* if (n == 1) */ { - xp_assert (n == 1); + xp_awk_assert (run->awk, n == 1); res = xp_awk_makerealval (run, v2); if (res == XP_NULL) { @@ -4055,7 +4060,7 @@ static xp_awk_val_t* __eval_incpst (xp_awk_run_t* run, xp_awk_nde_t* nde) } else { - xp_assert (!"should never happen - invalid opcode"); + xp_awk_assert (run->awk, !"should never happen - invalid opcode"); xp_awk_refdownval (run, left); PANIC (run, XP_AWK_EINTERNAL); } @@ -4075,15 +4080,15 @@ static xp_awk_val_t* __eval_cnd (xp_awk_run_t* run, xp_awk_nde_t* nde) xp_awk_val_t* tv, * v; xp_awk_nde_cnd_t* cnd = (xp_awk_nde_cnd_t*)nde; - xp_assert (cnd->test->next == XP_NULL); + xp_awk_assert (run->awk, cnd->test->next == XP_NULL); tv = __eval_expression (run, cnd->test); if (tv == XP_NULL) return XP_NULL; xp_awk_refupval (tv); - xp_assert (cnd->left->next == XP_NULL && + xp_awk_assert (run->awk, cnd->left->next == XP_NULL && cnd->right->next == XP_NULL); - v = (xp_awk_valtobool(tv))? + v = (xp_awk_valtobool (run, tv))? __eval_expression (run, cnd->left): __eval_expression (run, cnd->right); @@ -4120,7 +4125,7 @@ static xp_awk_val_t* __eval_afn (xp_awk_run_t* run, xp_awk_nde_t* nde) if (pair == XP_NULL) PANIC (run, XP_AWK_ENOSUCHFUNC); afn = (xp_awk_afn_t*)pair->val; - xp_assert (afn != XP_NULL); + xp_awk_assert (run->awk, afn != XP_NULL); if (call->nargs > afn->nargs) { @@ -4200,8 +4205,8 @@ static xp_awk_val_t* __eval_call ( * --------------------- */ - xp_assert (xp_sizeof(void*) >= xp_sizeof(run->stack_top)); - xp_assert (xp_sizeof(void*) >= xp_sizeof(run->stack_base)); + xp_awk_assert (run->awk, xp_sizeof(void*) >= xp_sizeof(run->stack_top)); + xp_awk_assert (run->awk, xp_sizeof(void*) >= xp_sizeof(run->stack_base)); saved_stack_top = run->stack_top; @@ -4238,7 +4243,7 @@ static xp_awk_val_t* __eval_call ( p = call->args; while (p != XP_NULL) { - xp_assert (bfn_arg_spec == XP_NULL || + xp_awk_assert (run->awk, bfn_arg_spec == XP_NULL || (bfn_arg_spec != XP_NULL && xp_awk_strlen(bfn_arg_spec) > nargs)); @@ -4331,7 +4336,7 @@ static xp_awk_val_t* __eval_call ( p = p->next; } - xp_assert (nargs == call->nargs); + xp_awk_assert (run->awk, nargs == call->nargs); if (afn != XP_NULL) { @@ -4358,7 +4363,7 @@ static xp_awk_val_t* __eval_call ( if (afn != XP_NULL) { /* normal awk function */ - xp_assert (afn->body->type == XP_AWK_NDE_BLK); + xp_awk_assert (run->awk, afn->body->type == XP_AWK_NDE_BLK); n = __run_block(run,(xp_awk_nde_blk_t*)afn->body); } else @@ -4366,7 +4371,7 @@ static xp_awk_val_t* __eval_call ( n = 0; /* built-in function */ - xp_assert (call->nargs >= call->what.bfn.min_args && + xp_awk_assert (run->awk, call->nargs >= call->what.bfn.min_args && call->nargs <= call->what.bfn.max_args); if (call->what.bfn.handler != XP_NULL) @@ -4526,7 +4531,7 @@ static xp_awk_val_t** __get_reference_indexed ( xp_char_t* str; xp_size_t len; - xp_assert (val != XP_NULL); + xp_awk_assert (run->awk, val != XP_NULL); if ((*val)->type == XP_AWK_VAL_NIL) { @@ -4544,7 +4549,7 @@ static xp_awk_val_t** __get_reference_indexed ( PANIC (run, XP_AWK_ENOTINDEXABLE); } - xp_assert (nde->idx != XP_NULL); + xp_awk_assert (run->awk, nde->idx != XP_NULL); str = __idxnde_to_str (run, nde->idx, &len); if (str == XP_NULL) return XP_NULL; @@ -4648,7 +4653,7 @@ static xp_awk_val_t* __eval_indexed ( xp_char_t* str; xp_size_t len; - xp_assert (val != XP_NULL); + xp_awk_assert (run->awk, val != XP_NULL); if ((*val)->type == XP_AWK_VAL_NIL) { @@ -4666,7 +4671,7 @@ static xp_awk_val_t* __eval_indexed ( PANIC (run, XP_AWK_ENOTINDEXABLE); } - xp_assert (nde->idx != XP_NULL); + xp_awk_assert (run->awk, nde->idx != XP_NULL); str = __idxnde_to_str (run, nde->idx, &len); if (str == XP_NULL) return XP_NULL; @@ -4751,7 +4756,7 @@ static xp_awk_val_t* __eval_getline (xp_awk_run_t* run, xp_awk_nde_t* nde) p = (xp_awk_nde_getline_t*)nde; - xp_assert ((p->in_type == XP_AWK_IN_PIPE && p->in != XP_NULL) || + xp_awk_assert (run->awk, (p->in_type == XP_AWK_IN_PIPE && p->in != XP_NULL) || (p->in_type == XP_AWK_IN_COPROC && p->in != XP_NULL) || (p->in_type == XP_AWK_IN_FILE && p->in != XP_NULL) || (p->in_type == XP_AWK_IN_CONSOLE && p->in == XP_NULL)); @@ -4769,7 +4774,8 @@ static xp_awk_val_t* __eval_getline (xp_awk_run_t* run, xp_awk_nde_t* nde) * v->type == XP_AWK_VAL_STR, xp_awk_refdownval(v) * should not be called immediately below */ xp_awk_refupval (v); - in = xp_awk_valtostr (run, v, xp_true, XP_NULL, &len); + in = xp_awk_valtostr ( + run, v, XP_AWK_VALTOSTR_CLEAR, XP_NULL, &len); if (in == XP_NULL) { xp_awk_refdownval (run, v); @@ -4938,7 +4944,7 @@ xp_printf (XP_T("len = %d str=[%s]\n"), */ if (n == 0) { - xp_assert (XP_AWK_STR_LEN(&run->inrec.line) == 0); + xp_awk_assert (run->awk, XP_AWK_STR_LEN(&run->inrec.line) == 0); return 0; } @@ -4956,7 +4962,7 @@ static int __shorten_record (xp_awk_run_t* run, xp_size_t nflds) xp_size_t ofs_len, i; xp_awk_str_t tmp; - xp_assert (nflds <= run->inrec.nflds); + xp_awk_assert (run->awk, nflds <= run->inrec.nflds); if (nflds > 1) { @@ -4977,7 +4983,7 @@ static int __shorten_record (xp_awk_run_t* run, xp_size_t nflds) else { ofs = xp_awk_valtostr ( - run, v, xp_true, XP_NULL, &ofs_len); + run, v, XP_AWK_VALTOSTR_CLEAR, XP_NULL, &ofs_len); if (ofs == XP_NULL) return -1; ofs_free = ofs; @@ -5047,7 +5053,7 @@ static xp_char_t* __idxnde_to_str ( xp_char_t* str; xp_awk_val_t* idx; - xp_assert (nde != XP_NULL); + xp_awk_assert (run->awk, nde != XP_NULL); if (nde->next == XP_NULL) { @@ -5057,7 +5063,8 @@ static xp_char_t* __idxnde_to_str ( xp_awk_refupval (idx); - str = xp_awk_valtostr (run, idx, xp_true, XP_NULL, len); + str = xp_awk_valtostr ( + run, idx, XP_AWK_VALTOSTR_CLEAR, XP_NULL, len); if (str == XP_NULL) { xp_awk_refdownval (run, idx); @@ -5098,8 +5105,8 @@ static xp_char_t* __idxnde_to_str ( PANIC (run, XP_AWK_ENOMEM); } - if (xp_awk_valtostr (run, - idx, xp_false, &idxstr, XP_NULL) == XP_NULL) + if (xp_awk_valtostr ( + run, idx, 0, &idxstr, XP_NULL) == XP_NULL) { xp_awk_refdownval (run, idx); xp_awk_str_close (&idxstr); diff --git a/ase/awk/tab.c b/ase/awk/tab.c index ffeb6711..ead0a60c 100644 --- a/ase/awk/tab.c +++ b/ase/awk/tab.c @@ -1,5 +1,5 @@ /* - * $Id: tab.c,v 1.19 2006-09-28 06:56:30 bacon Exp $ + * $Id: tab.c,v 1.20 2006-10-12 04:17:31 bacon Exp $ */ #include @@ -53,7 +53,7 @@ xp_awk_tab_t* xp_awk_tab_setcapa (xp_awk_tab_t* tab, xp_size_t capa) if (tab->size > capa) { xp_awk_tab_remove (tab, capa, tab->size - capa); - xp_assert (tab->size <= capa); + xp_awk_assert (tab->awk, tab->size <= capa); } if (capa > 0) @@ -96,8 +96,6 @@ void xp_awk_tab_clear (xp_awk_tab_t* tab) { xp_size_t i; - xp_assert (tab != XP_NULL); - for (i = 0; i < tab->size; i++) { XP_AWK_FREE (tab->awk, tab->buf[i].name); diff --git a/ase/awk/tree.c b/ase/awk/tree.c index 844091fd..2fc36e19 100644 --- a/ase/awk/tree.c +++ b/ase/awk/tree.c @@ -1,5 +1,5 @@ /* - * $Id: tree.c,v 1.78 2006-10-06 03:33:43 bacon Exp $ + * $Id: tree.c,v 1.79 2006-10-12 04:17:31 bacon Exp $ */ #include @@ -144,7 +144,7 @@ static int __print_expression (xp_awk_t* awk, xp_awk_nde_t* nde) PUT_SRCSTR (awk, XP_T(" ")); PRINT_EXPRESSION (awk, px->right); - xp_assert (px->right->next == XP_NULL); + xp_awk_assert (awk, px->right->next == XP_NULL); break; } @@ -154,7 +154,7 @@ static int __print_expression (xp_awk_t* awk, xp_awk_nde_t* nde) PUT_SRCSTR (awk, XP_T("(")); PRINT_EXPRESSION (awk, px->left); - xp_assert (px->left->next == XP_NULL); + xp_awk_assert (awk, px->left->next == XP_NULL); PUT_SRCSTR (awk, XP_T(" ")); PUT_SRCSTR (awk, __binop_str[px->opcode]); @@ -165,7 +165,7 @@ static int __print_expression (xp_awk_t* awk, xp_awk_nde_t* nde) PRINT_EXPRESSION (awk, px->right); if (px->right->type == XP_AWK_NDE_ASS) PUT_SRCSTR (awk, XP_T(")")); - xp_assert (px->right->next == XP_NULL); + xp_awk_assert (awk, px->right->next == XP_NULL); PUT_SRCSTR (awk, XP_T(")")); break; } @@ -173,7 +173,7 @@ static int __print_expression (xp_awk_t* awk, xp_awk_nde_t* nde) case XP_AWK_NDE_EXP_UNR: { xp_awk_nde_exp_t* px = (xp_awk_nde_exp_t*)nde; - xp_assert (px->right == XP_NULL); + xp_awk_assert (awk, px->right == XP_NULL); PUT_SRCSTR (awk, __unrop_str[px->opcode]); PUT_SRCSTR (awk, XP_T("(")); @@ -185,7 +185,7 @@ static int __print_expression (xp_awk_t* awk, xp_awk_nde_t* nde) case XP_AWK_NDE_EXP_INCPRE: { xp_awk_nde_exp_t* px = (xp_awk_nde_exp_t*)nde; - xp_assert (px->right == XP_NULL); + xp_awk_assert (awk, px->right == XP_NULL); PUT_SRCSTR (awk, __incop_str[px->opcode]); PUT_SRCSTR (awk, XP_T("(")); @@ -197,7 +197,7 @@ static int __print_expression (xp_awk_t* awk, xp_awk_nde_t* nde) case XP_AWK_NDE_EXP_INCPST: { xp_awk_nde_exp_t* px = (xp_awk_nde_exp_t*)nde; - xp_assert (px->right == XP_NULL); + xp_awk_assert (awk, px->right == XP_NULL); PUT_SRCSTR (awk, XP_T("(")); PRINT_EXPRESSION (awk, px->left); @@ -296,7 +296,7 @@ static int __print_expression (xp_awk_t* awk, xp_awk_nde_t* nde) xp_char_t tmp[xp_sizeof(xp_long_t)*8+2]; xp_size_t n; xp_awk_nde_var_t* px = (xp_awk_nde_var_t*)nde; - xp_assert (px->id.idxa != (xp_size_t)-1); + xp_awk_assert (awk, px->id.idxa != (xp_size_t)-1); n = xp_awk_longtostr ( px->id.idxa, 10, XP_NULL, tmp, xp_countof(tmp)); @@ -304,7 +304,7 @@ static int __print_expression (xp_awk_t* awk, xp_awk_nde_t* nde) PUT_SRCSTR (awk, XP_T("__param")); PUT_SRCSTRX (awk, tmp, n); - xp_assert (px->idx == XP_NULL); + xp_awk_assert (awk, px->idx == XP_NULL); break; } @@ -313,8 +313,8 @@ static int __print_expression (xp_awk_t* awk, xp_awk_nde_t* nde) xp_char_t tmp[xp_sizeof(xp_long_t)*8+2]; xp_size_t n; xp_awk_nde_var_t* px = (xp_awk_nde_var_t*)nde; - xp_assert (px->id.idxa != (xp_size_t)-1); - xp_assert (px->idx != XP_NULL); + xp_awk_assert (awk, px->id.idxa != (xp_size_t)-1); + xp_awk_assert (awk, px->idx != XP_NULL); PUT_SRCSTR (awk, XP_T("__param")); n = xp_awk_longtostr ( @@ -329,8 +329,8 @@ static int __print_expression (xp_awk_t* awk, xp_awk_nde_t* nde) case XP_AWK_NDE_NAMED: { xp_awk_nde_var_t* px = (xp_awk_nde_var_t*)nde; - xp_assert (px->id.idxa == (xp_size_t)-1); - xp_assert (px->idx == XP_NULL); + xp_awk_assert (awk, px->id.idxa == (xp_size_t)-1); + xp_awk_assert (awk, px->idx == XP_NULL); PUT_SRCSTRX (awk, px->id.name, px->id.name_len); break; @@ -339,8 +339,8 @@ static int __print_expression (xp_awk_t* awk, xp_awk_nde_t* nde) case XP_AWK_NDE_NAMEDIDX: { xp_awk_nde_var_t* px = (xp_awk_nde_var_t*)nde; - xp_assert (px->id.idxa == (xp_size_t)-1); - xp_assert (px->idx != XP_NULL); + xp_awk_assert (awk, px->id.idxa == (xp_size_t)-1); + xp_awk_assert (awk, px->idx != XP_NULL); PUT_SRCSTRX (awk, px->id.name, px->id.name_len); PUT_SRCSTR (awk, XP_T("[")); @@ -367,7 +367,7 @@ static int __print_expression (xp_awk_t* awk, xp_awk_nde_t* nde) { PUT_SRCSTRX (awk, px->id.name, px->id.name_len); } - xp_assert (px->idx == XP_NULL); + xp_awk_assert (awk, px->idx == XP_NULL); break; } @@ -391,7 +391,7 @@ static int __print_expression (xp_awk_t* awk, xp_awk_nde_t* nde) PUT_SRCSTRX (awk, px->id.name, px->id.name_len); PUT_SRCSTR (awk, XP_T("[")); } - xp_assert (px->idx != XP_NULL); + xp_awk_assert (awk, px->idx != XP_NULL); PRINT_EXPRESSION_LIST (awk, px->idx); PUT_SRCSTR (awk, XP_T("]")); break; @@ -415,7 +415,7 @@ static int __print_expression (xp_awk_t* awk, xp_awk_nde_t* nde) { PUT_SRCSTRX (awk, px->id.name, px->id.name_len); } - xp_assert (px->idx == XP_NULL); + xp_awk_assert (awk, px->idx == XP_NULL); break; } @@ -439,7 +439,7 @@ static int __print_expression (xp_awk_t* awk, xp_awk_nde_t* nde) PUT_SRCSTRX (awk, px->id.name, px->id.name_len); PUT_SRCSTR (awk, XP_T("[")); } - xp_assert (px->idx != XP_NULL); + xp_awk_assert (awk, px->idx != XP_NULL); PRINT_EXPRESSION_LIST (awk, px->idx); PUT_SRCSTR (awk, XP_T("]")); break; @@ -591,7 +591,7 @@ static int __print_statements (xp_awk_t* awk, xp_awk_nde_t* tree, int depth) PRINT_EXPRESSION (awk, px->test); PUT_SRCSTR (awk, XP_T(")\n")); - xp_assert (px->then_part != XP_NULL); + xp_awk_assert (awk, px->then_part != XP_NULL); if (px->then_part->type == XP_AWK_NDE_BLK) PRINT_STATEMENTS (awk, px->then_part, depth); else @@ -726,7 +726,7 @@ static int __print_statements (xp_awk_t* awk, xp_awk_nde_t* tree, int depth) else { PUT_SRCSTR (awk, XP_T("return ")); - xp_assert (((xp_awk_nde_return_t*)p)->val->next == XP_NULL); + xp_awk_assert (awk, ((xp_awk_nde_return_t*)p)->val->next == XP_NULL); PRINT_EXPRESSION (awk, ((xp_awk_nde_return_t*)p)->val); PUT_SRCSTR (awk, XP_T(";\n")); @@ -746,7 +746,7 @@ static int __print_statements (xp_awk_t* awk, xp_awk_nde_t* tree, int depth) else { PUT_SRCSTR (awk, XP_T("exit ")); - xp_assert (px->val->next == XP_NULL); + xp_awk_assert (awk, px->val->next == XP_NULL); PRINT_EXPRESSION (awk, px->val); PUT_SRCSTR (awk, XP_T(";\n")); } @@ -978,8 +978,8 @@ void xp_awk_clrpt (xp_awk_t* awk, xp_awk_nde_t* tree) case XP_AWK_NDE_EXP_BIN: { xp_awk_nde_exp_t* px = (xp_awk_nde_exp_t*)p; - xp_assert (px->left->next == XP_NULL); - xp_assert (px->right->next == XP_NULL); + xp_awk_assert (awk, px->left->next == XP_NULL); + xp_awk_assert (awk, px->right->next == XP_NULL); xp_awk_clrpt (awk, px->left); xp_awk_clrpt (awk, px->right); @@ -992,7 +992,7 @@ void xp_awk_clrpt (xp_awk_t* awk, xp_awk_nde_t* tree) case XP_AWK_NDE_EXP_INCPST: { xp_awk_nde_exp_t* px = (xp_awk_nde_exp_t*)p; - xp_assert (px->right == XP_NULL); + xp_awk_assert (awk, px->right == XP_NULL); xp_awk_clrpt (awk, px->left); XP_AWK_FREE (awk, p); break; @@ -1044,7 +1044,7 @@ void xp_awk_clrpt (xp_awk_t* awk, xp_awk_nde_t* tree) case XP_AWK_NDE_ARG: { xp_awk_nde_var_t* px = (xp_awk_nde_var_t*)p; - xp_assert (px->idx == XP_NULL); + xp_awk_assert (awk, px->idx == XP_NULL); if (px->id.name != XP_NULL) XP_AWK_FREE (awk, px->id.name); XP_AWK_FREE (awk, p); @@ -1057,7 +1057,7 @@ void xp_awk_clrpt (xp_awk_t* awk, xp_awk_nde_t* tree) case XP_AWK_NDE_ARGIDX: { xp_awk_nde_var_t* px = (xp_awk_nde_var_t*)p; - xp_assert (px->idx != XP_NULL); + xp_awk_assert (awk, px->idx != XP_NULL); xp_awk_clrpt (awk, px->idx); if (px->id.name != XP_NULL) XP_AWK_FREE (awk, px->id.name); @@ -1104,7 +1104,7 @@ void xp_awk_clrpt (xp_awk_t* awk, xp_awk_nde_t* tree) default: { - xp_assert (!"should never happen - invalid node type"); + xp_awk_assert (awk, !"should never happen - invalid node type"); XP_AWK_FREE (awk, p); break; } diff --git a/ase/awk/val.c b/ase/awk/val.c index 0b371389..46386ac0 100644 --- a/ase/awk/val.c +++ b/ase/awk/val.c @@ -1,5 +1,5 @@ /* - * $Id: val.c,v 1.71 2006-10-11 15:01:55 bacon Exp $ + * $Id: val.c,v 1.72 2006-10-12 04:17:31 bacon Exp $ */ #include @@ -298,7 +298,8 @@ xp_printf (XP_T("\n"));*/ } else { - xp_assert (!"should never happen - invalid value type"); + xp_awk_assert (run->awk, + !"should never happen - invalid value type"); } } @@ -324,7 +325,7 @@ xp_awk_printval (val); xp_printf (XP_T("\n")); */ - xp_assert (val->ref > 0); + xp_awk_assert (run->awk, val->ref > 0); val->ref--; if (val->ref <= 0) { @@ -341,11 +342,11 @@ void xp_awk_refdownval_nofree (xp_awk_run_t* run, xp_awk_val_t* val) { if (xp_awk_isbuiltinval(val)) return; - xp_assert (val->ref > 0); + xp_awk_assert (run->awk, val->ref > 0); val->ref--; } -xp_bool_t xp_awk_valtobool (xp_awk_val_t* val) +xp_bool_t xp_awk_valtobool (xp_awk_run_t* run, xp_awk_val_t* val) { if (val == XP_NULL) return xp_false; @@ -367,7 +368,7 @@ xp_bool_t xp_awk_valtobool (xp_awk_val_t* val) return xp_false; /* TODO: is this correct? */ } - xp_assert (!"should never happen - invalid value type"); + xp_awk_assert (run->awk, !"should never happen - invalid value type"); return xp_false; } @@ -706,7 +707,6 @@ void xp_awk_printval (xp_awk_val_t* val) break; default: - xp_assert (!"should never happen - invalid value type"); xp_printf (XP_T("**** INTERNAL ERROR - INVALID VALUE TYPE ****\n")); } } diff --git a/ase/awk/val.h b/ase/awk/val.h index 3c1e0f46..78f4da40 100644 --- a/ase/awk/val.h +++ b/ase/awk/val.h @@ -1,5 +1,5 @@ /* - * $Id: val.h,v 1.45 2006-10-11 15:01:55 bacon Exp $ + * $Id: val.h,v 1.46 2006-10-12 04:17:31 bacon Exp $ */ #ifndef _XP_AWK_VAL_H_ @@ -164,10 +164,13 @@ void xp_awk_refupval (xp_awk_val_t* val); void xp_awk_refdownval (xp_awk_run_t* run, xp_awk_val_t* val); void xp_awk_refdownval_nofree (xp_awk_run_t* run, xp_awk_val_t* val); -xp_bool_t xp_awk_valtobool (xp_awk_val_t* val); +xp_bool_t xp_awk_valtobool ( + xp_awk_run_t* run, xp_awk_val_t* val); + xp_char_t* xp_awk_valtostr ( xp_awk_run_t* run, xp_awk_val_t* val, int opt, xp_awk_str_t* buf, xp_size_t* len); + int xp_awk_valtonum ( xp_awk_run_t* run, xp_awk_val_t* v, xp_long_t* l, xp_real_t* r); diff --git a/ase/test/awk/arg.awk b/ase/test/awk/arg.awk index 06aa667c..680c9d35 100644 --- a/ase/test/awk/arg.awk +++ b/ase/test/awk/arg.awk @@ -13,4 +13,6 @@ BEGIN { print "ARGV[" i "]", ARGV[i]; } + + if (ARGC >= 0) print "ARGC is positive"; } diff --git a/ase/test/awk/awk.c b/ase/test/awk/awk.c index 0b2ead65..ccc1506d 100644 --- a/ase/test/awk/awk.c +++ b/ase/test/awk/awk.c @@ -1,11 +1,12 @@ /* - * $Id: awk.c,v 1.94 2006-10-11 03:19:08 bacon Exp $ + * $Id: awk.c,v 1.95 2006-10-12 04:17:58 bacon Exp $ */ #include #include #include #include +#include #ifdef XP_CHAR_IS_WCHAR #include @@ -21,6 +22,7 @@ #include #include #else + #include #include #ifndef PATH_MAX #define XP_PATH_MAX 4096 @@ -86,6 +88,25 @@ static FILE* fopen_t (const xp_char_t* path, const xp_char_t* mode) #endif } +static int __dprintf (const xp_char_t* fmt, ...) +{ + int n; + va_list ap; +#ifdef _WIN32 + xp_char_t buf[1024]; +#endif + + va_start (ap, fmt); +#ifdef _WIN32 + n = xp_vsprintf (buf, xp_countof(buf), fmt, ap); + MessageBox (NULL, buf, XP_T("ASSERTION FAILURE"), MB_OK | MB_ICONERROR); +#else + n = xp_vprintf (fmt, ap); +#endif + va_end (ap); + return n; +} + static FILE* popen_t (const xp_char_t* cmd, const xp_char_t* mode) { #ifdef _WIN32 @@ -679,6 +700,8 @@ static int __main (int argc, xp_char_t* argv[]) syscas.memcpy = memcpy; syscas.memset = memset; syscas.sprintf = xp_sprintf; + syscas.dprintf = __dprintf; + syscas.abort = abort; #ifdef _WIN32 syscas_data.heap = HeapCreate (0, 1000000, 1000000); diff --git a/ase/test/awk/t40.awk b/ase/test/awk/t40.awk index 0896fc4f..d0fdfddc 100644 --- a/ase/test/awk/t40.awk +++ b/ase/test/awk/t40.awk @@ -6,4 +6,3 @@ BEGIN { print "NF=" NF; for (i = 0; i < NF; i++) print i " [" $(i+1) "]"; } -