From 2797fb2d3641b787d027523d4f27608abf115d72 Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Tue, 10 Oct 2006 14:09:23 +0000 Subject: [PATCH] *** empty log message *** --- ase/awk/awk.h | 12 ++++++-- ase/awk/func.c | 3 +- ase/awk/run.c | 65 ++++++++++++++++++++++++++++++++++++++++++-- ase/test/awk/arg.awk | 3 ++ ase/test/awk/awk.c | 10 +++++-- 5 files changed, 85 insertions(+), 8 deletions(-) create mode 100644 ase/test/awk/arg.awk diff --git a/ase/awk/awk.h b/ase/awk/awk.h index b701c1f6..1da55ebc 100644 --- a/ase/awk/awk.h +++ b/ase/awk/awk.h @@ -1,5 +1,5 @@ /* - * $Id: awk.h,v 1.124 2006-10-10 07:02:38 bacon Exp $ + * $Id: awk.h,v 1.125 2006-10-10 14:08:55 bacon Exp $ */ #ifndef _XP_AWK_AWK_H_ @@ -17,6 +17,7 @@ typedef struct xp_awk_syscas_t xp_awk_syscas_t; typedef struct xp_awk_srcios_t xp_awk_srcios_t; typedef struct xp_awk_runios_t xp_awk_runios_t; typedef struct xp_awk_runcbs_t xp_awk_runcbs_t; +typedef struct xp_awk_runarg_t xp_awk_runarg_t; typedef void (*xp_awk_lk_t) (xp_awk_t* awk, void* arg); typedef xp_ssize_t (*xp_awk_io_t) ( @@ -97,6 +98,11 @@ struct xp_awk_runcbs_t void* custom_data; }; +struct xp_awk_runarg_t +{ + const xp_char_t* ptr; + xp_size_t len; +}; /* io function commands */ enum @@ -331,7 +337,9 @@ int xp_awk_parse (xp_awk_t* awk, xp_awk_srcios_t* srcios); * error number. The third parameter to on_end denotes this error number. */ int xp_awk_run (xp_awk_t* awk, - xp_awk_runios_t* runios, xp_awk_runcbs_t* runcbs); + xp_awk_runios_t* runios, + xp_awk_runcbs_t* runcbs, + xp_awk_runarg_t* runarg); int xp_awk_stop (xp_awk_t* awk, xp_awk_run_t* run); void xp_awk_stopall (xp_awk_t* awk); diff --git a/ase/awk/func.c b/ase/awk/func.c index a41d349d..186332f3 100644 --- a/ase/awk/func.c +++ b/ase/awk/func.c @@ -1,5 +1,5 @@ /* - * $Id: func.c,v 1.58 2006-10-10 07:02:38 bacon Exp $ + * $Id: func.c,v 1.59 2006-10-10 14:08:55 bacon Exp $ */ #include @@ -1115,7 +1115,6 @@ static int __bfn_sub (xp_awk_run_t* run) return __substitute (run, 1); } - static int __bfn_system (xp_awk_run_t* run) { xp_size_t nargs; diff --git a/ase/awk/run.c b/ase/awk/run.c index 94fbe9f5..be3279be 100644 --- a/ase/awk/run.c +++ b/ase/awk/run.c @@ -1,5 +1,5 @@ /* - * $Id: run.c,v 1.229 2006-10-10 07:06:42 bacon Exp $ + * $Id: run.c,v 1.230 2006-10-10 14:08:55 bacon Exp $ */ #include @@ -58,6 +58,7 @@ static void __del_run (xp_awk_t* awk, xp_awk_run_t* run); static int __init_run ( xp_awk_run_t* run, xp_awk_runios_t* runios, int* errnum); static void __deinit_run (xp_awk_run_t* run); +static int __build_runarg (xp_awk_run_t* run, xp_awk_runarg_t* runarg); static int __run_main (xp_awk_run_t* run); static int __run_pattern_blocks (xp_awk_run_t* run); @@ -434,7 +435,10 @@ void xp_awk_setrunerrnum (xp_awk_run_t* run, int errnum) run->errnum = errnum; } -int xp_awk_run (xp_awk_t* awk, xp_awk_runios_t* runios, xp_awk_runcbs_t* runcbs) +int xp_awk_run (xp_awk_t* awk, + xp_awk_runios_t* runios, + xp_awk_runcbs_t* runcbs, + xp_awk_runarg_t* runarg) { xp_awk_run_t* run; int n, errnum; @@ -463,6 +467,12 @@ int xp_awk_run (xp_awk_t* awk, xp_awk_runios_t* runios, xp_awk_runcbs_t* runcbs) runcbs->on_start (awk, run, runcbs->custom_data); } + if (runarg != XP_NULL && __build_runarg (run, runarg) == -1) + { +/*TODO: cleanup. error handling */ + return -1; + } + n = __run_main (run); if (n == -1) { @@ -744,6 +754,57 @@ static void __deinit_run (xp_awk_run_t* run) } } +static int __build_runarg (xp_awk_run_t* run, xp_awk_runarg_t* runarg) +{ + xp_awk_runarg_t* p = runarg; + xp_size_t argc; + xp_awk_val_t* v_argc; + xp_awk_val_t* v_argv; + + v_argv = xp_awk_makemapval (run); + if (v_argv == XP_NULL) + { + run->errnum = XP_AWK_ENOMEM; + return -1; + } + xp_awk_refupval (v_argv); + + for (argc = 0, p = runarg; p->ptr != XP_NULL; argc++, p++) + { + xp_printf (XP_T("ptr = %s, len = %d\n"), p->ptr, p->len); +/* TODO: create values */ + } +xp_printf (XP_T("argc = %d\n"), argc); + + v_argc = xp_awk_makeintval (run, (xp_long_t)argc); + if (v_argc == XP_NULL) + { + xp_awk_refdownval (run, v_argv); + run->errnum = XP_AWK_ENOMEM; + return -1; + } + + xp_awk_refupval (v_argc); + + if (xp_awk_setglobal (run, XP_AWK_GLOBAL_ARGC, v_argc) == -1) + { + xp_awk_refdownval (run, v_argc); + xp_awk_refdownval (run, v_argv); + return -1; + } + + if (xp_awk_setglobal (run, XP_AWK_GLOBAL_ARGV, v_argv) == -1) + { + xp_awk_refdownval (run, v_argc); + xp_awk_refdownval (run, v_argv); + return -1; + } + + xp_awk_refdownval (run, v_argc); + xp_awk_refdownval (run, v_argv); + return 0; +} + static int __run_main (xp_awk_run_t* run) { xp_size_t nglobals, nargs, i; diff --git a/ase/test/awk/arg.awk b/ase/test/awk/arg.awk new file mode 100644 index 00000000..6713c771 --- /dev/null +++ b/ase/test/awk/arg.awk @@ -0,0 +1,3 @@ +BEGIN { + print "ARGC=", ARGC; +} diff --git a/ase/test/awk/awk.c b/ase/test/awk/awk.c index fe3e4ffc..119d5890 100644 --- a/ase/test/awk/awk.c +++ b/ase/test/awk/awk.c @@ -1,5 +1,5 @@ /* - * $Id: awk.c,v 1.92 2006-10-09 14:37:41 bacon Exp $ + * $Id: awk.c,v 1.93 2006-10-10 14:09:23 bacon Exp $ */ #include @@ -592,6 +592,7 @@ static int __main (int argc, xp_char_t* argv[]) xp_awk_srcios_t srcios; xp_awk_runcbs_t runcbs; xp_awk_runios_t runios; + xp_awk_runarg_t runarg[10]; xp_awk_syscas_t syscas; struct src_io src_io = { NULL, NULL }; int opt, i, file_count = 0; @@ -738,7 +739,12 @@ static int __main (int argc, xp_char_t* argv[]) runcbs.on_end = __on_run_end; runcbs.custom_data = XP_NULL; - if (xp_awk_run (awk, &runios, &runcbs) == -1) + runarg[0].ptr = XP_T("argument 0"); + runarg[0].len = xp_awk_strlen(runarg[0].ptr); + runarg[1].ptr = XP_NULL; + runarg[1].len = 0; + + if (xp_awk_run (awk, &runios, &runcbs, runarg) == -1) { int errnum = xp_awk_geterrnum(awk); #if defined(__STAND_ALONE) && !defined(_WIN32) && defined(XP_CHAR_IS_WCHAR)