*** empty log message ***

This commit is contained in:
hyung-hwan 2006-08-04 16:31:22 +00:00
parent 3f2a87784f
commit 1ea85ed09d
6 changed files with 94 additions and 19 deletions

View File

@ -1,5 +1,5 @@
/* /*
* $Id: awk.c,v 1.64 2006-08-03 09:53:41 bacon Exp $ * $Id: awk.c,v 1.65 2006-08-04 16:31:21 bacon Exp $
*/ */
#include <xp/awk/awk_i.h> #include <xp/awk/awk_i.h>
@ -70,6 +70,7 @@ xp_awk_t* xp_awk_open (void)
awk->parse.nlocals_max = 0; awk->parse.nlocals_max = 0;
awk->tree.nglobals = 0; awk->tree.nglobals = 0;
awk->tree.nbglobals = 0;
awk->tree.begin = XP_NULL; awk->tree.begin = XP_NULL;
awk->tree.end = XP_NULL; awk->tree.end = XP_NULL;
awk->tree.chain = XP_NULL; awk->tree.chain = XP_NULL;

View File

@ -1,5 +1,5 @@
/* /*
* $Id: awk.h,v 1.87 2006-08-03 15:49:37 bacon Exp $ * $Id: awk.h,v 1.88 2006-08-04 16:31:21 bacon Exp $
*/ */
#ifndef _XP_AWK_AWK_H_ #ifndef _XP_AWK_AWK_H_
@ -12,10 +12,13 @@ typedef struct xp_awk_t xp_awk_t;
typedef struct xp_awk_val_t xp_awk_val_t; typedef struct xp_awk_val_t xp_awk_val_t;
typedef struct xp_awk_extio_t xp_awk_extio_t; typedef struct xp_awk_extio_t xp_awk_extio_t;
typedef struct xp_awk_rex_t xp_awk_rex_t; typedef struct xp_awk_rex_t xp_awk_rex_t;
typedef struct xp_awk_runcb_t xp_awk_runcb_t;
typedef xp_ssize_t (*xp_awk_io_t) ( typedef xp_ssize_t (*xp_awk_io_t) (
int cmd, void* arg, xp_char_t* data, xp_size_t count); int cmd, void* arg, xp_char_t* data, xp_size_t count);
typedef void (*xp_awk_cb_t) (xp_awk_t* awk, void* handle);
struct xp_awk_extio_t struct xp_awk_extio_t
{ {
int type; /* console, file, coproc, pipe */ int type; /* console, file, coproc, pipe */
@ -36,6 +39,12 @@ struct xp_awk_extio_t
xp_awk_extio_t* next; xp_awk_extio_t* next;
}; };
struct xp_awk_runcb_t
{
xp_awk_cb_t start;
xp_awk_cb_t end;
};
/* io function commands */ /* io function commands */
enum enum
{ {
@ -218,7 +227,8 @@ xp_size_t xp_awk_getsrcline (xp_awk_t* awk);
int xp_awk_setextio (xp_awk_t* awk, int id, xp_awk_io_t handler, void* arg); int xp_awk_setextio (xp_awk_t* awk, int id, xp_awk_io_t handler, void* arg);
int xp_awk_parse (xp_awk_t* awk); int xp_awk_parse (xp_awk_t* awk);
int xp_awk_run (xp_awk_t* awk); int xp_awk_run (xp_awk_t* awk, xp_awk_runcb_t* runcb);
int xp_awk_stop (xp_awk_t* awk, void* handle);
/* functions to access internal stack structure */ /* functions to access internal stack structure */
xp_size_t xp_awk_getnargs (void* run); xp_size_t xp_awk_getnargs (void* run);

View File

@ -1,5 +1,5 @@
/* /*
* $Id: awk_i.h,v 1.38 2006-08-03 15:49:37 bacon Exp $ * $Id: awk_i.h,v 1.39 2006-08-04 16:31:21 bacon Exp $
*/ */
#ifndef _XP_AWK_AWKI_H_ #ifndef _XP_AWK_AWKI_H_
@ -70,7 +70,8 @@ run with run_stack
struct xp_awk_tree_t struct xp_awk_tree_t
{ {
xp_size_t nglobals; xp_size_t nglobals; /* total number of globals */
xp_size_t nbglobals; /* number of builtin globals */
xp_awk_map_t afns; /* awk function map */ xp_awk_map_t afns; /* awk function map */
xp_awk_nde_t* begin; xp_awk_nde_t* begin;
xp_awk_nde_t* end; xp_awk_nde_t* end;

View File

@ -1,5 +1,5 @@
/* /*
* $Id: parse.c,v 1.156 2006-08-04 06:39:05 bacon Exp $ * $Id: parse.c,v 1.157 2006-08-04 16:31:21 bacon Exp $
*/ */
#include <xp/awk/awk_i.h> #include <xp/awk/awk_i.h>
@ -356,12 +356,13 @@ static void __dump (xp_awk_t* awk)
{ {
xp_awk_chain_t* chain; xp_awk_chain_t* chain;
if (awk->tree.nglobals > 0) if (awk->tree.nglobals > awk->tree.nbglobals)
{ {
xp_size_t i; xp_size_t i;
xp_assert (awk->tree.nglobals > 0);
xp_printf (XP_T("global ")); xp_printf (XP_T("global "));
for (i = 0; i < awk->tree.nglobals - 1; i++) for (i = awk->tree.nbglobals; i < awk->tree.nglobals - 1; i++)
{ {
xp_printf (XP_T("__global%lu, "), (unsigned long)i); xp_printf (XP_T("__global%lu, "), (unsigned long)i);
} }
@ -1020,10 +1021,12 @@ static xp_awk_t* __add_builtin_globals (xp_awk_t* awk)
{ {
struct __bvent* p = __bvtab; struct __bvent* p = __bvtab;
awk->tree.nbglobals = 0;
while (p->name != XP_NULL) while (p->name != XP_NULL)
{ {
if (__add_global (awk, if (__add_global (awk,
p->name, p->name_len) == XP_NULL) return XP_NULL; p->name, p->name_len) == XP_NULL) return XP_NULL;
awk->tree.nbglobals++;
p++; p++;
} }

View File

@ -1,5 +1,5 @@
/* /*
* $Id: run.c,v 1.159 2006-08-03 15:49:37 bacon Exp $ * $Id: run.c,v 1.160 2006-08-04 16:31:21 bacon Exp $
*/ */
#include <xp/awk/awk_i.h> #include <xp/awk/awk_i.h>
@ -222,7 +222,7 @@ void xp_awk_seterrnum (void* run, int errnum)
r->errnum = errnum; r->errnum = errnum;
} }
int xp_awk_run (xp_awk_t* awk) int xp_awk_run (xp_awk_t* awk, xp_awk_runcb_t* runcb)
{ {
xp_awk_run_t* run; xp_awk_run_t* run;
int n; int n;
@ -243,6 +243,8 @@ int xp_awk_run (xp_awk_t* awk)
return -1; return -1;
} }
if (runcb->start != XP_NULL) runcb->start (awk, run);
n = __run_main (run); n = __run_main (run);
if (n == -1) if (n == -1)
{ {
@ -250,12 +252,29 @@ int xp_awk_run (xp_awk_t* awk)
awk->suberrnum = run->suberrnum; awk->suberrnum = run->suberrnum;
} }
if (runcb->end != XP_NULL) runcb->end (awk, run);
__close_run (run); __close_run (run);
xp_free (run); xp_free (run);
return n; return n;
} }
int xp_awk_stop (xp_awk_t* awk, void* handle)
{
xp_awk_run_t* run = (xp_awk_run_t*)handle;
if (run->awk != awk)
{
/* TODO: use awk->errnum or run->errnum??? */
run->errnum = XP_AWK_EINVAL;
return -1;
}
run->exit_level = EXIT_ABORT;
return 0;
}
static void __free_namedval (void* run, void* val) static void __free_namedval (void* run, void* val)
{ {
xp_awk_refdownval ((xp_awk_run_t*)run, val); xp_awk_refdownval ((xp_awk_run_t*)run, val);
@ -270,7 +289,7 @@ static int __open_run (xp_awk_run_t* run, xp_awk_t* awk)
run->stack_base = 0; run->stack_base = 0;
run->stack_limit = 0; run->stack_limit = 0;
run->exit_level = 0; run->exit_level = EXIT_NONE;
run->icache_count = 0; run->icache_count = 0;
run->rcache_count = 0; run->rcache_count = 0;
@ -382,13 +401,13 @@ static int __run_main (xp_awk_run_t* run)
} }
} }
run->exit_level = EXIT_NONE;
if (run->opt & XP_AWK_RUNMAIN) if (run->opt & XP_AWK_RUNMAIN)
{ {
/* TODO: should the main function be user-specifiable? */ /* TODO: should the main function be user-specifiable? */
xp_awk_nde_call_t nde; xp_awk_nde_call_t nde;
run->exit_level = EXIT_NONE;
nde.type = XP_AWK_NDE_AFN; nde.type = XP_AWK_NDE_AFN;
nde.next = XP_NULL; nde.next = XP_NULL;
nde.what.afn.name = XP_T("main"); nde.what.afn.name = XP_T("main");
@ -451,7 +470,9 @@ static int __run_main (xp_awk_run_t* run)
STACK_NARGS(run) = (void*)nargs; STACK_NARGS(run) = (void*)nargs;
/* stack set up properly. ready to exeucte statement blocks */ /* stack set up properly. ready to exeucte statement blocks */
if (n == 0 && run->awk->tree.begin != XP_NULL) if (n == 0 &&
run->awk->tree.begin != XP_NULL &&
run->exit_level != EXIT_ABORT)
{ {
xp_awk_nde_blk_t* blk; xp_awk_nde_blk_t* blk;
@ -463,12 +484,16 @@ static int __run_main (xp_awk_run_t* run)
if (__run_block (run, blk) == -1) n = -1; if (__run_block (run, blk) == -1) n = -1;
} }
if (n == 0 && run->awk->tree.chain != XP_NULL) if (n == 0 &&
run->awk->tree.chain != XP_NULL &&
run->exit_level != EXIT_ABORT)
{ {
if (__run_pattern_blocks (run) == -1) n = -1; if (__run_pattern_blocks (run) == -1) n = -1;
} }
if (n == 0 && run->awk->tree.end != XP_NULL) if (n == 0 &&
run->awk->tree.end != XP_NULL &&
run->exit_level != EXIT_ABORT)
{ {
xp_awk_nde_blk_t* blk; xp_awk_nde_blk_t* blk;

View File

@ -1,10 +1,11 @@
/* /*
* $Id: awk.c,v 1.62 2006-08-03 09:53:46 bacon Exp $ * $Id: awk.c,v 1.63 2006-08-04 16:31:22 bacon Exp $
*/ */
#include <xp/awk/awk.h> #include <xp/awk/awk.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <signal.h>
#ifdef XP_CHAR_IS_WCHAR #ifdef XP_CHAR_IS_WCHAR
#include <wchar.h> #include <wchar.h>
@ -479,6 +480,33 @@ xp_printf (XP_TEXT("switching console[%s] of type %x\n"), epa->name, epa->type);
return n; return n;
} }
xp_awk_t* app_awk = NULL;
void* app_run = NULL;
static void __stop_run (int sig)
{
signal (SIGINT, SIG_IGN);
xp_awk_stop (app_awk, app_run);
//xp_awk_stoprun (awk, handle);
/*xp_awk_stopallruns (awk); */
signal (SIGINT, __stop_run);
}
static void __on_run_start (xp_awk_t* awk, void* handle)
{
app_awk = awk;
app_run = handle;
xp_printf (XP_T("AWK PRORAM ABOUT TO START...\n"));
}
static void __on_run_end (xp_awk_t* awk, void* handle)
{
app_awk = NULL;
app_run = NULL;
xp_printf (XP_T("AWK PRORAM ABOUT TO END...\n"));
}
#if defined(__STAND_ALONE) && !defined(_WIN32) #if defined(__STAND_ALONE) && !defined(_WIN32)
static int __main (int argc, char* argv[]) static int __main (int argc, char* argv[])
#else #else
@ -486,8 +514,10 @@ static int __main (int argc, xp_char_t* argv[])
#endif #endif
{ {
xp_awk_t* awk; xp_awk_t* awk;
xp_awk_runcb_t runcb;
struct src_io src_io = { NULL, NULL }; struct src_io src_io = { NULL, NULL };
if ((awk = xp_awk_open()) == XP_NULL) if ((awk = xp_awk_open()) == XP_NULL)
{ {
xp_printf (XP_T("Error: cannot open awk\n")); xp_printf (XP_T("Error: cannot open awk\n"));
@ -599,7 +629,12 @@ static int __main (int argc, xp_char_t* argv[])
return -1; return -1;
} }
if (xp_awk_run (awk) == -1) signal (SIGINT, __stop_run);
runcb.start = __on_run_start;
runcb.end = __on_run_end;
if (xp_awk_run (awk, &runcb) == -1)
{ {
#if defined(__STAND_ALONE) && !defined(_WIN32) && defined(XP_CHAR_IS_WCHAR) #if defined(__STAND_ALONE) && !defined(_WIN32) && defined(XP_CHAR_IS_WCHAR)
xp_printf ( xp_printf (