From 5c871e4fe919c63ded5b3f77e1c4620eafa951ff Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Sun, 11 Feb 2007 14:08:08 +0000 Subject: [PATCH] *** empty log message *** --- ase/awk/awk.h | 13 ++++++-- ase/awk/map.h | 6 ++-- ase/awk/run.c | 76 ++++++++++++++++++++++------------------------ ase/test/awk/awk.c | 64 +++++++++++++++++++++++++------------- 4 files changed, 93 insertions(+), 66 deletions(-) diff --git a/ase/awk/awk.h b/ase/awk/awk.h index 0ddd0aa8..a76f070a 100644 --- a/ase/awk/awk.h +++ b/ase/awk/awk.h @@ -1,5 +1,5 @@ /* - * $Id: awk.h,v 1.188 2007-02-11 04:44:39 bacon Exp $ + * $Id: awk.h,v 1.189 2007-02-11 14:07:28 bacon Exp $ * * {License} */ @@ -13,6 +13,7 @@ typedef struct ase_awk_t ase_awk_t; typedef struct ase_awk_run_t ase_awk_run_t; typedef struct ase_awk_val_t ase_awk_val_t; +typedef struct ase_awk_map_t ase_awk_map_t; typedef struct ase_awk_extio_t ase_awk_extio_t; typedef struct ase_awk_prmfns_t ase_awk_prmfns_t; @@ -128,9 +129,14 @@ struct ase_awk_runios_t struct ase_awk_runcbs_t { void (*on_start) ( - ase_awk_t* awk, ase_awk_run_t* run, void* custom_data); + ase_awk_run_t* run, void* custom_data); + + void (*on_return) ( + ase_awk_run_t* run, ase_awk_val_t* ret, void* custom_data); + void (*on_end) ( - ase_awk_t* awk, ase_awk_run_t* run, int errnum, void* custom_data); + ase_awk_run_t* run, int errnum, void* custom_data); + void* custom_data; }; @@ -468,6 +474,7 @@ int ase_awk_setofilename ( ase_awk_t* ase_awk_getrunawk (ase_awk_run_t* awk); void* ase_awk_getruncustomdata (ase_awk_run_t* awk); +ase_awk_map_t* ase_awk_getrunnamedvarmap (ase_awk_run_t* awk); /* functions to manipulate the run-time error */ int ase_awk_getrunerrnum (ase_awk_run_t* run); diff --git a/ase/awk/map.h b/ase/awk/map.h index e84a5828..096ca654 100644 --- a/ase/awk/map.h +++ b/ase/awk/map.h @@ -1,5 +1,5 @@ /* - * $Id: map.h,v 1.19 2007-02-03 10:47:41 bacon Exp $ + * $Id: map.h,v 1.20 2007-02-11 14:07:28 bacon Exp $ * * {License} */ @@ -8,10 +8,10 @@ #define _ASE_AWK_MAP_H_ #ifndef _ASE_AWK_AWK_H_ -#error Never include this file directly. Include instead +#error Include first #endif -typedef struct ase_awk_map_t ase_awk_map_t; +/*typedef struct ase_awk_map_t ase_awk_map_t;*/ typedef struct ase_awk_pair_t ase_awk_pair_t; struct ase_awk_pair_t diff --git a/ase/awk/run.c b/ase/awk/run.c index 7f929423..3b70552d 100644 --- a/ase/awk/run.c +++ b/ase/awk/run.c @@ -1,5 +1,5 @@ /* - * $Id: run.c,v 1.325 2007-02-03 10:50:39 bacon Exp $ + * $Id: run.c,v 1.326 2007-02-11 14:07:28 bacon Exp $ * * {License} */ @@ -64,8 +64,10 @@ static int __build_runarg ( static void __cleanup_globals (ase_awk_run_t* run); static int __set_globals_to_default (ase_awk_run_t* run); -static int __run_main ( - ase_awk_run_t* run, const ase_char_t* main, ase_awk_runarg_t* runarg); +static int run_main ( + ase_awk_run_t* run, const ase_char_t* main, + ase_awk_runcbs_t* runcbs, ase_awk_runarg_t* runarg); + static int __run_pattern_blocks (ase_awk_run_t* run); static int __run_pattern_block_chain ( ase_awk_run_t* run, ase_awk_chain_t* chain); @@ -210,17 +212,6 @@ typedef ase_awk_val_t* (*binop_func_t) ( ase_awk_run_t* run, ase_awk_val_t* left, ase_awk_val_t* right); typedef ase_awk_val_t* (*eval_expr_t) (ase_awk_run_t* run, ase_awk_nde_t* nde); -#ifdef _DEBUG -static int __printval (ase_awk_pair_t* pair, void* arg) -{ - ase_awk_run_t* run = (ase_awk_run_t*)arg; - run->awk->prmfns.dprintf (ASE_T("%s = "), (const ase_char_t*)pair->key); - ase_awk_dprintval (run, (ase_awk_val_t*)pair->val); - run->awk->prmfns.dprintf (ASE_T("\n")); - return 0; -} -#endif - ase_size_t ase_awk_getnargs (ase_awk_run_t* run) { return (ase_size_t) STACK_NARGS (run); @@ -569,6 +560,11 @@ void* ase_awk_getruncustomdata (ase_awk_run_t* run) return run->custom_data; } +ase_awk_map_t* ase_awk_getrunnamedvarmap (ase_awk_run_t* awk) +{ + return &awk->named; +} + int ase_awk_getrunerrnum (ase_awk_run_t* run) { return run->errnum; @@ -683,10 +679,12 @@ int ase_awk_run (ase_awk_t* awk, /* execute the start callback if it exists */ if (runcbs != ASE_NULL && runcbs->on_start != ASE_NULL) - runcbs->on_start (awk, run, runcbs->custom_data); + { + runcbs->on_start (run, runcbs->custom_data); + } /* enter the main run loop */ - n = __run_main (run, main, runarg); + n = run_main (run, main, runcbs, runarg); if (n == -1) { /* if no callback is specified, awk's error number @@ -703,13 +701,11 @@ int ase_awk_run (ase_awk_t* awk, } } - /* uninitialize the run object */ - __deinit_run (run); /* the run loop ended. execute the end callback if it exists */ if (runcbs != ASE_NULL && runcbs->on_end != ASE_NULL) { - runcbs->on_end (awk, run, + runcbs->on_end (run, ((n == -1)? run->errnum: ASE_AWK_ENOERR), runcbs->custom_data); @@ -718,6 +714,9 @@ int ase_awk_run (ase_awk_t* awk, n = 0; } + /* uninitialize the run object */ + __deinit_run (run); + /* unregister the run object */ __del_run (awk, run); @@ -730,6 +729,12 @@ int ase_awk_stop (ase_awk_t* awk, ase_awk_run_t* run) ase_awk_run_t* r; int n = 0; + if (ase_awk_getrunawk(run) != awk) + { + awk->errnum = ASE_AWK_EINVAL; + return -1; + } + ASE_AWK_LOCK (awk); /* check if the run handle given is valid */ @@ -1242,8 +1247,9 @@ static int __set_globals_to_default (ase_awk_run_t* run) return 0; } -static int __run_main ( - ase_awk_run_t* run, const ase_char_t* main, ase_awk_runarg_t* runarg) +static int run_main ( + ase_awk_run_t* run, const ase_char_t* main, + ase_awk_runcbs_t* runcbs, ase_awk_runarg_t* runarg) { ase_size_t nglobals, nargs, nrunargs, i; ase_size_t saved_stack_top; @@ -1383,13 +1389,13 @@ static int __run_main ( if (v == ASE_NULL) n = -1; else { -#ifdef _DEBUG - run->awk->prmfns.dprintf (ASE_T("[RETURN] - ")); - ase_awk_dprintval (run, v); - run->awk->prmfns.dprintf (ASE_T("\n")); -#endif - /* destroy the return value if necessary */ ase_awk_refupval (run, v); + + if (runcbs != ASE_NULL && runcbs->on_return != ASE_NULL) + { + runcbs->on_return (run, v, runcbs->custom_data); + } + ase_awk_refdownval (run, v); } @@ -1502,15 +1508,13 @@ static int __run_main ( v = STACK_RETVAL(run); -#ifdef _DEBUG - run->awk->prmfns.dprintf (ASE_T("[RETURN] - ")); - ase_awk_dprintval (run, v); - run->awk->prmfns.dprintf (ASE_T("\n")); -#endif + if (runcbs != ASE_NULL && runcbs->on_return != ASE_NULL) + { + runcbs->on_return (run, v, runcbs->custom_data); + } /* the life of the global return value is over here * unlike the return value of each function */ - /*ase_awk_refdownval_nofree (awk, v);*/ ase_awk_refdownval (run, v); run->stack_top = @@ -1531,12 +1535,6 @@ static int __run_main ( /* just reset the exit level */ run->exit_level = EXIT_NONE; -#ifdef _DEBUG - run->awk->prmfns.dprintf (ASE_T("[VARIABLES]\n")); - ase_awk_map_walk (&run->named, __printval, run); - run->awk->prmfns.dprintf (ASE_T("[END VARIABLES]\n")); -#endif - return n; } diff --git a/ase/test/awk/awk.c b/ase/test/awk/awk.c index 0c2c7def..afde2c90 100644 --- a/ase/test/awk/awk.c +++ b/ase/test/awk/awk.c @@ -1,8 +1,10 @@ /* - * $Id: awk.c,v 1.164 2007-02-10 13:52:41 bacon Exp $ + * $Id: awk.c,v 1.165 2007-02-11 14:08:08 bacon Exp $ */ #include +#include +#include #include #include #include @@ -609,52 +611,69 @@ ase_awk_t* app_awk = NULL; ase_awk_run_t* app_run = NULL; #ifdef _WIN32 -static BOOL WINAPI __stop_run (DWORD ctrl_type) +static BOOL WINAPI stop_run (DWORD ctrl_type) { if (ctrl_type == CTRL_C_EVENT || ctrl_type == CTRL_CLOSE_EVENT) { - ase_awk_stop (app_awk, app_run); + ase_awk_stop (ase_awk_getrunawk(app_run), app_run); return TRUE; } return FALSE; } #else -static void __stop_run (int sig) +static void stop_run (int sig) { signal (SIGINT, SIG_IGN); - ase_awk_stop (app_awk, app_run); - /*ase_awk_stoprun (awk, handle);*/ - /*ase_awk_stopallruns (awk); */ - signal (SIGINT, __stop_run); + ase_awk_stop (ase_awk_getrunawk(app_run), app_run); + /*ase_awk_stopall (app_awk); */ + /*ase_awk_stopall (ase_awk_getrunawk(app_run)); */ + signal (SIGINT, stop_run); } #endif -static void on_run_start ( - ase_awk_t* awk, ase_awk_run_t* run, void* custom_data) +static void on_run_start (ase_awk_run_t* run, void* custom_data) { - app_awk = awk; app_run = run; - - awk_dprintf (ASE_T("AWK ABOUT TO START...\n")); + awk_dprintf (ASE_T("[AWK ABOUT TO START]\n")); } -static void on_run_end ( - ase_awk_t* awk, ase_awk_run_t* run, - int errnum, void* custom_data) +static int __printval (ase_awk_pair_t* pair, void* arg) +{ + ase_awk_run_t* run = (ase_awk_run_t*)arg; + awk_dprintf (ASE_T("%s = "), (const ase_char_t*)pair->key); + ase_awk_dprintval (run, (ase_awk_val_t*)pair->val); + awk_dprintf (ASE_T("\n")); + return 0; +} + +static void on_run_return ( + ase_awk_run_t* run, ase_awk_val_t* ret, void* custom_data) +{ + app_run = run; + + awk_dprintf (ASE_T("[RETURN] - ")); + ase_awk_dprintval (run, ret); + awk_dprintf (ASE_T("\n")); + + awk_dprintf (ASE_T("[NAMED VARIABLES]\n")); + ase_awk_map_walk (ase_awk_getrunnamedvarmap(run), __printval, run); + awk_dprintf (ASE_T("[END NAMED VARIABLES]\n")); +} + +static void on_run_end (ase_awk_run_t* run, int errnum, void* custom_data) { if (errnum != ASE_AWK_ENOERR) { - awk_dprintf (ASE_T("AWK ENDED WITH AN ERROR\n")); + awk_dprintf (ASE_T("[AWK ENDED WITH AN ERROR] - ")); awk_dprintf (ASE_T("CODE [%d] LINE [%u] %s\n"), errnum, (unsigned int)ase_awk_getrunerrlin(run), ase_awk_getrunerrmsg(run)); } - else awk_dprintf (ASE_T("AWK ENDED SUCCESSFULLY\n")); + else awk_dprintf (ASE_T("[AWK ENDED SUCCESSFULLY]\n")); - app_awk = NULL; app_run = NULL; } @@ -934,6 +953,8 @@ static int awk_main (int argc, ase_char_t* argv[]) return -1; } + app_awk = awk; + ase_awk_setoption (awk, opt); srcios.in = process_source; @@ -957,9 +978,9 @@ static int awk_main (int argc, ase_char_t* argv[]) } #ifdef _WIN32 - SetConsoleCtrlHandler (__stop_run, TRUE); + SetConsoleCtrlHandler (stop_run, TRUE); #else - signal (SIGINT, __stop_run); + signal (SIGINT, stop_run); #endif runios.pipe = process_extio_pipe; @@ -968,6 +989,7 @@ static int awk_main (int argc, ase_char_t* argv[]) runios.console = process_extio_console; runcbs.on_start = on_run_start; + runcbs.on_return = on_run_return; runcbs.on_end = on_run_end; runcbs.custom_data = ASE_NULL;