*** empty log message ***

This commit is contained in:
hyung-hwan 2006-10-10 14:09:23 +00:00
parent fb46759c43
commit 2797fb2d36
5 changed files with 85 additions and 8 deletions

View File

@ -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);

View File

@ -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 <xp/awk/awk_i.h>
@ -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;

View File

@ -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 <xp/awk/awk_i.h>
@ -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;

3
ase/test/awk/arg.awk Normal file
View File

@ -0,0 +1,3 @@
BEGIN {
print "ARGC=", ARGC;
}

View File

@ -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 <xp/awk/awk.h>
@ -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)