*** empty log message ***
This commit is contained in:
parent
7f8eb89f4e
commit
cdb1677f38
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: rex.c,v 1.18 2006-08-10 16:02:15 bacon Exp $
|
||||
* $Id: rex.c,v 1.19 2006-08-10 16:03:35 bacon Exp $
|
||||
*/
|
||||
|
||||
#include <xp/awk/awk_i.h>
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: rex.h,v 1.10 2006-07-26 16:43:35 bacon Exp $
|
||||
* $Id: rex.h,v 1.11 2006-08-10 16:02:15 bacon Exp $
|
||||
**/
|
||||
|
||||
#ifndef _XP_AWK_REX_H_
|
||||
@ -37,21 +37,6 @@
|
||||
* ab|xy -> |2|10|4|ORD_CHAR(no bound)|a|ORD_CHAR(no bound)|b|4|ORD_CHAR(no bound)|x|ORD_CHAR(no bound)|y|
|
||||
*/
|
||||
|
||||
enum
|
||||
{
|
||||
XP_AWK_REX_ENOERR, /* no error */
|
||||
XP_AWK_REX_ENOMEM, /* ran out of memory */
|
||||
XP_AWK_REX_ERPAREN, /* a right parenthesis is expected */
|
||||
XP_AWK_REX_ERBRACKET, /* a right bracket is expected */
|
||||
XP_AWK_REX_ERBRACE, /* a right brace is expected */
|
||||
XP_AWK_REX_ECOLON, /* a colon is expected */
|
||||
XP_AWK_REX_ECRANGE, /* invalid character range */
|
||||
XP_AWK_REX_ECCLASS, /* invalid character class */
|
||||
XP_AWK_REX_EBRANGE, /* invalid boundary range */
|
||||
XP_AWK_REX_EEND, /* unexpected end of the pattern */
|
||||
XP_AWK_REX_EGARBAGE /* garbage after the pattern */
|
||||
};
|
||||
|
||||
#define XP_AWK_REX_NA(code) (*(xp_size_t*)(code))
|
||||
|
||||
#define XP_AWK_REX_LEN(code) \
|
||||
@ -61,8 +46,6 @@ enum
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
const xp_char_t* xp_awk_getrexerrstr (int errnum);
|
||||
|
||||
void* xp_awk_buildrex (const xp_char_t* ptn, xp_size_t len, int* errnum);
|
||||
|
||||
int xp_awk_matchrex (void* code,
|
||||
|
173
ase/awk/run.c
173
ase/awk/run.c
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: run.c,v 1.163 2006-08-04 17:54:52 bacon Exp $
|
||||
* $Id: run.c,v 1.164 2006-08-10 16:02:15 bacon Exp $
|
||||
*/
|
||||
|
||||
#include <xp/awk/awk_i.h>
|
||||
@ -39,16 +39,16 @@ enum
|
||||
|
||||
#define PANIC(run,code) \
|
||||
do { (run)->errnum = (code); return XP_NULL; } while (0)
|
||||
#define PANIC2(run,code,subcode) \
|
||||
do { (run)->errnum = (code); (run)->suberrnum = (subcode); return XP_NULL; } while (0)
|
||||
|
||||
#define PANIC_I(run,code) \
|
||||
do { (run)->errnum = (code); return -1; } while (0)
|
||||
#define PANIC2_I(awk,code,subcode) \
|
||||
do { (run)->errnum = (code); (run)->suberrnum = (subcode); return -1; } while (0)
|
||||
|
||||
static int __open_run (xp_awk_run_t* run, xp_awk_t* awk);
|
||||
static void __close_run (xp_awk_run_t* run);
|
||||
static void __add_run (xp_awk_t* awk, xp_awk_run_t* run);
|
||||
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 __run_main (xp_awk_run_t* run);
|
||||
static int __run_pattern_blocks (xp_awk_run_t* run);
|
||||
@ -225,7 +225,9 @@ void xp_awk_seterrnum (void* run, int errnum)
|
||||
int xp_awk_run (xp_awk_t* awk, xp_awk_runios_t* runios, xp_awk_runcbs_t* runcbs)
|
||||
{
|
||||
xp_awk_run_t* run;
|
||||
int n;
|
||||
int n, errnum;
|
||||
|
||||
awk->errnum = XP_AWK_ENOERR;
|
||||
|
||||
run = (xp_awk_run_t*) xp_malloc (xp_sizeof(xp_awk_run_t));
|
||||
if (run == XP_NULL)
|
||||
@ -234,11 +236,12 @@ int xp_awk_run (xp_awk_t* awk, xp_awk_runios_t* runios, xp_awk_runcbs_t* runcbs)
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (__open_run (run, awk) == -1)
|
||||
__add_run (awk, run);
|
||||
|
||||
if (__init_run (run, runios, &errnum) == -1)
|
||||
{
|
||||
/* TODO: find a way to set the errnum into awk object in a thread-safe way */
|
||||
awk->errnum = run->errnum;
|
||||
awk->suberrnum = run->suberrnum;
|
||||
awk->errnum = errnum;
|
||||
__del_run (awk, run);
|
||||
xp_free (run);
|
||||
return -1;
|
||||
}
|
||||
@ -247,16 +250,14 @@ int xp_awk_run (xp_awk_t* awk, xp_awk_runios_t* runios, xp_awk_runcbs_t* runcbs)
|
||||
runcbs->start (awk, run, runcbs->custom_data);
|
||||
|
||||
n = __run_main (run);
|
||||
if (n == -1)
|
||||
{
|
||||
awk->errnum = run->errnum;
|
||||
awk->suberrnum = run->suberrnum;
|
||||
}
|
||||
if (n == -1) awk->errnum = XP_AWK_ERUNTIME;
|
||||
|
||||
if (runcbs->end != XP_NULL)
|
||||
runcbs->end (awk, run, runcbs->custom_data);
|
||||
|
||||
__close_run (run);
|
||||
__deinit_run (run);
|
||||
|
||||
__del_run (awk, run);
|
||||
xp_free (run);
|
||||
|
||||
return n;
|
||||
@ -264,17 +265,65 @@ int xp_awk_run (xp_awk_t* awk, xp_awk_runios_t* runios, xp_awk_runcbs_t* runcbs)
|
||||
|
||||
int xp_awk_stop (xp_awk_t* awk, void* run)
|
||||
{
|
||||
xp_awk_run_t* r = (xp_awk_run_t*)run;
|
||||
xp_awk_run_t* r;
|
||||
int n = 0;
|
||||
|
||||
if (r->awk != awk)
|
||||
if (awk->thr.lks != XP_NULL)
|
||||
awk->thr.lks->lock (awk, awk->thr.lks->custom_data);
|
||||
|
||||
/* check if the run handle given is valid */
|
||||
for (r = awk->run.ptr; r != XP_NULL; r = r->next)
|
||||
{
|
||||
/* TODO: use awk->errnum or run->errnum??? */
|
||||
r->errnum = XP_AWK_EINVAL;
|
||||
return -1;
|
||||
if (r == run)
|
||||
{
|
||||
xp_assert (r->awk == awk);
|
||||
r->exit_level = EXIT_ABORT;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
r->exit_level = EXIT_ABORT;
|
||||
return 0;
|
||||
if (r == XP_NULL)
|
||||
{
|
||||
/* if it is not found in the awk's run list,
|
||||
* it is not a valid handle */
|
||||
awk->errnum = XP_AWK_EINVAL;
|
||||
n = -1;
|
||||
}
|
||||
|
||||
if (awk->thr.lks != XP_NULL)
|
||||
awk->thr.lks->unlock (awk, awk->thr.lks->custom_data);
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
int xp_awk_getrunerrnum (xp_awk_t* awk, void* run, int* errnum)
|
||||
{
|
||||
xp_awk_run_t* r;
|
||||
int n = 0;
|
||||
|
||||
if (awk->thr.lks != XP_NULL)
|
||||
awk->thr.lks->lock (awk, awk->thr.lks->custom_data);
|
||||
|
||||
for (r = awk->run.ptr; r != XP_NULL; r = r->next)
|
||||
{
|
||||
if (r == run)
|
||||
{
|
||||
xp_assert (r->awk == awk);
|
||||
*errnum = r->errnum;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (r == XP_NULL)
|
||||
{
|
||||
awk->errnum = XP_AWK_EINVAL;
|
||||
n = -1;
|
||||
}
|
||||
|
||||
if (awk->thr.lks != XP_NULL)
|
||||
awk->thr.lks->unlock (awk, awk->thr.lks->custom_data);
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
static void __free_namedval (void* run, void* val)
|
||||
@ -282,10 +331,50 @@ static void __free_namedval (void* run, void* val)
|
||||
xp_awk_refdownval ((xp_awk_run_t*)run, val);
|
||||
}
|
||||
|
||||
static int __open_run (xp_awk_run_t* run, xp_awk_t* awk)
|
||||
static void __add_run (xp_awk_t* awk, xp_awk_run_t* run)
|
||||
{
|
||||
xp_memset (run, 0, xp_sizeof(*run));
|
||||
if (awk->thr.lks != XP_NULL)
|
||||
awk->thr.lks->lock (awk, awk->thr.lks->custom_data);
|
||||
|
||||
run->awk = awk;
|
||||
run->prev = XP_NULL;
|
||||
run->next = awk->run.ptr;
|
||||
if (run->next != XP_NULL) run->next->prev = run;
|
||||
awk->run.ptr = run;
|
||||
awk->run.count++;
|
||||
|
||||
if (awk->thr.lks != XP_NULL)
|
||||
awk->thr.lks->unlock (awk, awk->thr.lks->custom_data);
|
||||
}
|
||||
|
||||
static void __del_run (xp_awk_t* awk, xp_awk_run_t* run)
|
||||
{
|
||||
if (awk->thr.lks != XP_NULL)
|
||||
awk->thr.lks->lock (awk, awk->thr.lks->custom_data);
|
||||
|
||||
xp_assert (awk->run.ptr != XP_NULL);
|
||||
|
||||
if (run->prev == XP_NULL)
|
||||
{
|
||||
awk->run.ptr = run->next;
|
||||
if (run->next != XP_NULL) run->next->prev = XP_NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
run->prev->next = run->next;
|
||||
if (run->next != XP_NULL) run->next->prev = run->prev;
|
||||
}
|
||||
|
||||
run->awk = XP_NULL;
|
||||
awk->run.count--;
|
||||
|
||||
if (awk->thr.lks != XP_NULL)
|
||||
awk->thr.lks->unlock (awk, awk->thr.lks->custom_data);
|
||||
}
|
||||
|
||||
static int __init_run (
|
||||
xp_awk_run_t* run, xp_awk_runios_t* runios, int* errnum)
|
||||
{
|
||||
run->stack = XP_NULL;
|
||||
run->stack_top = 0;
|
||||
run->stack_base = 0;
|
||||
@ -297,10 +386,6 @@ static int __open_run (xp_awk_run_t* run, xp_awk_t* awk)
|
||||
run->rcache_count = 0;
|
||||
|
||||
run->errnum = XP_AWK_ENOERR;
|
||||
run->suberrnum = XP_AWK_ENOERR;
|
||||
/*run->tree = &awk->tree; */
|
||||
/*run->nglobals = awk->tree.nglobals;*/
|
||||
run->awk = awk;
|
||||
|
||||
run->inrec.buf_pos = 0;
|
||||
run->inrec.buf_len = 0;
|
||||
@ -310,7 +395,7 @@ static int __open_run (xp_awk_run_t* run, xp_awk_t* awk)
|
||||
run->inrec.d0 = xp_awk_val_nil;
|
||||
if (xp_str_open (&run->inrec.line, DEF_BUF_CAPA) == XP_NULL)
|
||||
{
|
||||
run->errnum = XP_AWK_ENOMEM;
|
||||
*errnum = XP_AWK_ENOMEM;
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -318,19 +403,25 @@ static int __open_run (xp_awk_run_t* run, xp_awk_t* awk)
|
||||
run, DEF_BUF_CAPA, __free_namedval) == XP_NULL)
|
||||
{
|
||||
xp_str_close (&run->inrec.line);
|
||||
run->errnum = XP_AWK_ENOMEM;
|
||||
*errnum = XP_AWK_ENOMEM;
|
||||
return -1;
|
||||
}
|
||||
|
||||
run->extio = XP_NULL;
|
||||
run->extio.handler[XP_AWK_EXTIO_PIPE] = runios->pipe;
|
||||
run->extio.handler[XP_AWK_EXTIO_COPROC] = runios->coproc;
|
||||
run->extio.handler[XP_AWK_EXTIO_FILE] = runios->file;
|
||||
run->extio.handler[XP_AWK_EXTIO_CONSOLE] = runios->console;
|
||||
run->extio.chain = XP_NULL;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void __close_run (xp_awk_run_t* run)
|
||||
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);
|
||||
|
||||
/* destroy input record. __clear_record should be called
|
||||
* before the run stack has been destroyed because it may try
|
||||
@ -385,7 +476,6 @@ static int __run_main (xp_awk_run_t* run)
|
||||
/* secure space for global variables */
|
||||
saved_stack_top = run->stack_top;
|
||||
|
||||
/*nglobals = run->nglobals;*/
|
||||
nglobals = run->awk->tree.nglobals;
|
||||
|
||||
while (nglobals > 0)
|
||||
@ -1604,7 +1694,7 @@ static xp_awk_val_t* __eval_expression (xp_awk_run_t* run, xp_awk_nde_t* nde)
|
||||
if (n == -1)
|
||||
{
|
||||
xp_awk_refdownval (run, v);
|
||||
PANIC2 (run, XP_AWK_EREXMATCH, errnum);
|
||||
PANIC (run, errnum);
|
||||
}
|
||||
|
||||
xp_awk_refdownval (run, v);
|
||||
@ -3030,7 +3120,7 @@ static xp_awk_val_t* __eval_binop_match0 (
|
||||
((xp_awk_val_str_t*)right)->buf,
|
||||
((xp_awk_val_str_t*)right)->len, &errnum);
|
||||
if (rex_code == XP_NULL)
|
||||
PANIC2 (run, XP_AWK_EREXBUILD, errnum);
|
||||
PANIC (run, errnum);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -3041,7 +3131,7 @@ static xp_awk_val_t* __eval_binop_match0 (
|
||||
if (rex_code == XP_NULL)
|
||||
{
|
||||
xp_free (str);
|
||||
PANIC2 (run, XP_AWK_EREXBUILD, errnum);
|
||||
PANIC (run, errnum);
|
||||
}
|
||||
|
||||
xp_free (str);
|
||||
@ -3057,7 +3147,7 @@ static xp_awk_val_t* __eval_binop_match0 (
|
||||
if (n == -1)
|
||||
{
|
||||
if (right->type != XP_AWK_VAL_REX) xp_free (rex_code);
|
||||
PANIC2 (run, XP_AWK_EREXMATCH, errnum);
|
||||
PANIC (run, errnum);
|
||||
}
|
||||
|
||||
res = xp_awk_makeintval (run, (n == ret));
|
||||
@ -3082,7 +3172,7 @@ static xp_awk_val_t* __eval_binop_match0 (
|
||||
{
|
||||
xp_free (str);
|
||||
if (right->type != XP_AWK_VAL_REX) xp_free (rex_code);
|
||||
PANIC2 (run, XP_AWK_EREXMATCH, errnum);
|
||||
PANIC (run, errnum);
|
||||
}
|
||||
|
||||
res = xp_awk_makeintval (run, (n == ret));
|
||||
@ -4542,3 +4632,4 @@ static xp_char_t* __idxnde_to_str (
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: awk.c,v 1.69 2006-08-06 15:03:42 bacon Exp $
|
||||
* $Id: awk.c,v 1.70 2006-08-10 16:06:52 bacon Exp $
|
||||
*/
|
||||
|
||||
#include <xp/awk/awk.h>
|
||||
@ -527,9 +527,17 @@ xp_printf (XP_T("AWK PRORAM ABOUT TO START...\n"));
|
||||
|
||||
static void __on_run_end (xp_awk_t* awk, void* handle, void* arg)
|
||||
{
|
||||
int x;
|
||||
|
||||
xp_awk_getrunerrnum (app_awk, app_run, &x);
|
||||
if (x != XP_AWK_ENOERR)
|
||||
{
|
||||
xp_printf (XP_T("AWK PRORAM ABOUT TO END WITH AN ERROR - %d - %s\n"), x, xp_awk_geterrstr (x));
|
||||
}
|
||||
else xp_printf (XP_T("AWK PRORAM ABOUT TO END...\n"));
|
||||
|
||||
app_awk = NULL;
|
||||
app_run = NULL;
|
||||
xp_printf (XP_T("AWK PRORAM ABOUT TO END...\n"));
|
||||
}
|
||||
|
||||
#if defined(__STAND_ALONE) && !defined(_WIN32)
|
||||
@ -545,39 +553,12 @@ static int __main (int argc, xp_char_t* argv[])
|
||||
struct src_io src_io = { NULL, NULL };
|
||||
int opt;
|
||||
|
||||
if ((awk = xp_awk_open()) == XP_NULL)
|
||||
if ((awk = xp_awk_open(XP_NULL)) == XP_NULL)
|
||||
{
|
||||
xp_printf (XP_T("Error: cannot open awk\n"));
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* TODO: */
|
||||
if (xp_awk_setextio (awk,
|
||||
XP_AWK_EXTIO_PIPE, process_extio_pipe, XP_NULL) == -1)
|
||||
{
|
||||
xp_awk_close (awk);
|
||||
xp_printf (XP_T("Error: cannot set extio pipe\n"));
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* TODO: */
|
||||
if (xp_awk_setextio (awk,
|
||||
XP_AWK_EXTIO_FILE, process_extio_file, XP_NULL) == -1)
|
||||
{
|
||||
xp_awk_close (awk);
|
||||
xp_printf (XP_T("Error: cannot set extio file\n"));
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (xp_awk_setextio (awk,
|
||||
XP_AWK_EXTIO_CONSOLE, process_extio_console, XP_NULL) == -1)
|
||||
{
|
||||
xp_awk_close (awk);
|
||||
xp_printf (XP_T("Error: cannot set extio file\n"));
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
opt = XP_AWK_EXPLICIT | XP_AWK_UNIQUE | XP_AWK_DBLSLASHES |
|
||||
XP_AWK_SHADING | XP_AWK_IMPLICIT | XP_AWK_SHIFT |
|
||||
XP_AWK_EXTIO | XP_AWK_BLOCKLESS;
|
||||
@ -631,26 +612,18 @@ static int __main (int argc, xp_char_t* argv[])
|
||||
|
||||
if (xp_awk_parse (awk, &srcios) == -1)
|
||||
{
|
||||
int errnum = xp_awk_geterrnum(awk);
|
||||
#if defined(__STAND_ALONE) && !defined(_WIN32) && defined(XP_CHAR_IS_WCHAR)
|
||||
xp_printf (
|
||||
XP_T("ERROR: cannot parse program - line %u [%d] %ls"),
|
||||
XP_T("ERROR: cannot parse program - line %u [%d] %ls\n"),
|
||||
(unsigned int)xp_awk_getsrcline(awk),
|
||||
xp_awk_geterrnum(awk), xp_awk_geterrstr(awk));
|
||||
if (xp_awk_getsuberrnum(awk) != XP_AWK_ENOERR)
|
||||
{
|
||||
xp_printf (XP_T(" - %ls\n"), xp_awk_getsuberrstr(awk));
|
||||
}
|
||||
errnum, xp_awk_geterrstr(errnum));
|
||||
#else
|
||||
xp_printf (
|
||||
XP_T("ERROR: cannot parse program - line %u [%d] %s"),
|
||||
XP_T("ERROR: cannot parse program - line %u [%d] %s\n"),
|
||||
(unsigned int)xp_awk_getsrcline(awk),
|
||||
xp_awk_geterrnum(awk), xp_awk_geterrstr(awk));
|
||||
if (xp_awk_getsuberrnum(awk) != XP_AWK_ENOERR)
|
||||
{
|
||||
xp_printf (XP_T(" - %s\n"), xp_awk_getsuberrstr(awk));
|
||||
}
|
||||
errnum, xp_awk_geterrstr(errnum));
|
||||
#endif
|
||||
xp_printf (XP_T("\n"));
|
||||
xp_awk_close (awk);
|
||||
return -1;
|
||||
}
|
||||
@ -661,28 +634,23 @@ static int __main (int argc, xp_char_t* argv[])
|
||||
runios.coproc = XP_NULL;
|
||||
runios.file = process_extio_file;
|
||||
runios.console = process_extio_console;
|
||||
runios.custom_data = XP_NULL;
|
||||
|
||||
runcbs.start = __on_run_start;
|
||||
runcbs.end = __on_run_end;
|
||||
runcbs.end = __on_run_end;
|
||||
runcbs.custom_data = XP_NULL;
|
||||
|
||||
if (xp_awk_run (awk, &runios, &runcbs) == -1)
|
||||
{
|
||||
int errnum = xp_awk_geterrnum(awk);
|
||||
#if defined(__STAND_ALONE) && !defined(_WIN32) && defined(XP_CHAR_IS_WCHAR)
|
||||
xp_printf (
|
||||
XP_T("error: cannot run program - [%d] %ls"),
|
||||
xp_awk_geterrnum(awk), xp_awk_geterrstr(awk));
|
||||
XP_T("error: cannot run program - [%d] %ls\n"),
|
||||
errnum, xp_awk_geterrstr(errnum));
|
||||
#else
|
||||
xp_printf (
|
||||
XP_T("error: cannot run program - [%d] %s"),
|
||||
xp_awk_geterrnum(awk), xp_awk_geterrstr(awk));
|
||||
XP_T("error: cannot run program - [%d] %s\n"),
|
||||
errnum, xp_awk_geterrstr(errnum));
|
||||
#endif
|
||||
if (xp_awk_getsuberrnum(awk) != XP_AWK_ENOERR)
|
||||
{
|
||||
xp_printf (XP_T(" - %ls\n"), xp_awk_getsuberrstr(awk));
|
||||
}
|
||||
xp_printf (XP_T("\n"));
|
||||
|
||||
xp_awk_close (awk);
|
||||
return -1;
|
||||
|
@ -1,6 +1,6 @@
|
||||
global a, b, c;
|
||||
|
||||
BEGIN { while (1) while(1) while (1) ; }
|
||||
BEGIN { while (1) while(1) while (1) a = 20; }
|
||||
|
||||
END { while (1) while(1) while (1) ; }
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user