*** empty log message ***
This commit is contained in:
parent
f518f752ba
commit
1fc79d38d4
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* $Id: awk_i.h,v 1.36 2006-08-01 15:57:42 bacon Exp $
|
* $Id: awk_i.h,v 1.37 2006-08-02 14:36:22 bacon Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _XP_AWK_AWKI_H_
|
#ifndef _XP_AWK_AWKI_H_
|
||||||
@ -157,6 +157,7 @@ struct xp_awk_t
|
|||||||
struct xp_awk_chain_t
|
struct xp_awk_chain_t
|
||||||
{
|
{
|
||||||
xp_awk_nde_t* pattern;
|
xp_awk_nde_t* pattern;
|
||||||
|
int pattern_range_state; /* used when pattern is a range */
|
||||||
xp_awk_nde_t* action;
|
xp_awk_nde_t* action;
|
||||||
xp_awk_chain_t* next;
|
xp_awk_chain_t* next;
|
||||||
};
|
};
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* $Id: parse.c,v 1.149 2006-08-01 15:59:27 bacon Exp $
|
* $Id: parse.c,v 1.150 2006-08-02 14:36:23 bacon Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <xp/awk/awk_i.h>
|
#include <xp/awk/awk_i.h>
|
||||||
@ -788,6 +788,7 @@ static xp_awk_nde_t* __parse_ptnblock (xp_awk_t* awk, xp_awk_nde_t* ptn)
|
|||||||
}
|
}
|
||||||
|
|
||||||
chain->pattern = ptn;
|
chain->pattern = ptn;
|
||||||
|
chain->pattern_range_state = 0;
|
||||||
chain->action = nde;
|
chain->action = nde;
|
||||||
chain->next = XP_NULL;
|
chain->next = XP_NULL;
|
||||||
|
|
||||||
@ -2226,14 +2227,6 @@ static xp_awk_nde_t* __parse_primary_ident (xp_awk_t* awk)
|
|||||||
PANIC (awk, XP_AWK_ENOMEM);
|
PANIC (awk, XP_AWK_ENOMEM);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* TODO: search in the builtin variable name list */
|
|
||||||
/*
|
|
||||||
idxa = ....
|
|
||||||
if (idxa != (xp_size_t)-1)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* search the parameter name list */
|
/* search the parameter name list */
|
||||||
idxa = xp_awk_tab_find(&awk->parse.params, name_dup, 0);
|
idxa = xp_awk_tab_find(&awk->parse.params, name_dup, 0);
|
||||||
if (idxa != (xp_size_t)-1)
|
if (idxa != (xp_size_t)-1)
|
||||||
@ -2352,14 +2345,6 @@ static xp_awk_nde_t* __parse_hashidx (xp_awk_t* awk, xp_char_t* name)
|
|||||||
PANIC (awk, XP_AWK_ENOMEM);
|
PANIC (awk, XP_AWK_ENOMEM);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* TODO: search in the builtin variable name list */
|
|
||||||
/*
|
|
||||||
idxa = xp_awk_tab_find (&awk->parse.params, name, 0);
|
|
||||||
if (idxa != (xp_size_t)-1)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* search the parameter name list */
|
/* search the parameter name list */
|
||||||
idxa = xp_awk_tab_find (&awk->parse.params, name, 0);
|
idxa = xp_awk_tab_find (&awk->parse.params, name, 0);
|
||||||
if (idxa != (xp_size_t)-1)
|
if (idxa != (xp_size_t)-1)
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* $Id: run.c,v 1.155 2006-08-02 11:27:07 bacon Exp $
|
* $Id: run.c,v 1.156 2006-08-02 14:36:23 bacon Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <xp/awk/awk_i.h>
|
#include <xp/awk/awk_i.h>
|
||||||
@ -53,6 +53,7 @@ static void __close_run (xp_awk_run_t* run);
|
|||||||
static int __run_main (xp_awk_run_t* run);
|
static int __run_main (xp_awk_run_t* run);
|
||||||
static int __run_pattern_blocks (xp_awk_run_t* run);
|
static int __run_pattern_blocks (xp_awk_run_t* run);
|
||||||
static int __run_pattern_block_chain (xp_awk_run_t* run, xp_awk_chain_t* chain);
|
static int __run_pattern_block_chain (xp_awk_run_t* run, xp_awk_chain_t* chain);
|
||||||
|
static int __run_pattern_block (xp_awk_run_t* run, xp_awk_chain_t* chain);
|
||||||
static int __run_block (xp_awk_run_t* run, xp_awk_nde_blk_t* nde);
|
static int __run_block (xp_awk_run_t* run, xp_awk_nde_blk_t* nde);
|
||||||
static int __run_statement (xp_awk_run_t* run, xp_awk_nde_t* nde);
|
static int __run_statement (xp_awk_run_t* run, xp_awk_nde_t* nde);
|
||||||
static int __run_if (xp_awk_run_t* run, xp_awk_nde_if_t* nde);
|
static int __run_if (xp_awk_run_t* run, xp_awk_nde_if_t* nde);
|
||||||
@ -530,11 +531,21 @@ static int __run_pattern_blocks (xp_awk_run_t* run)
|
|||||||
xp_ssize_t n;
|
xp_ssize_t n;
|
||||||
xp_bool_t need_to_close = xp_false;
|
xp_bool_t need_to_close = xp_false;
|
||||||
int errnum;
|
int errnum;
|
||||||
|
xp_awk_chain_t* chain;
|
||||||
|
|
||||||
run->inrec.buf_pos = 0;
|
run->inrec.buf_pos = 0;
|
||||||
run->inrec.buf_len = 0;
|
run->inrec.buf_len = 0;
|
||||||
run->inrec.eof = xp_false;
|
run->inrec.eof = xp_false;
|
||||||
|
|
||||||
|
/* clear the pattern_range_state */
|
||||||
|
chain = run->awk->tree.chain;
|
||||||
|
while (chain != XP_NULL)
|
||||||
|
{
|
||||||
|
chain->pattern_range_state = 0;
|
||||||
|
chain = chain->next;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* run each pattern block */
|
||||||
while (run->exit_level != EXIT_GLOBAL &&
|
while (run->exit_level != EXIT_GLOBAL &&
|
||||||
run->exit_level != EXIT_ABORT)
|
run->exit_level != EXIT_ABORT)
|
||||||
{
|
{
|
||||||
@ -562,13 +573,13 @@ static int __run_pattern_blocks (xp_awk_run_t* run)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* In case of getline, the code would getline return -1, set ERRNO,
|
/* In case of getline, the code would make getline return -1,
|
||||||
* and make this function return 0 after having checke if closextio
|
* set ERRNO, make this function return 0 after having checked
|
||||||
* has returned -1 and errnum has been set to XP_AWK_ENOERR.
|
* if closextio has returned -1 and errnum has been set to
|
||||||
* But this part of the code ends the input for the implicit
|
* XP_AWK_ENOERR. But this part of the code ends the input for
|
||||||
* pattern-block loop, which is totally different from getline.
|
* the implicit pattern-block loop, which is totally different
|
||||||
* So it just returns -1 as long as closeextio returns -1 regardless
|
* from getline. so it returns -1 as long as closeextio returns
|
||||||
* of the value of errnum */
|
* -1 regardless of the value of errnum. */
|
||||||
if (need_to_close)
|
if (need_to_close)
|
||||||
{
|
{
|
||||||
n = xp_awk_closeextio_read (
|
n = xp_awk_closeextio_read (
|
||||||
@ -587,8 +598,6 @@ static int __run_pattern_blocks (xp_awk_run_t* run)
|
|||||||
|
|
||||||
static int __run_pattern_block_chain (xp_awk_run_t* run, xp_awk_chain_t* chain)
|
static int __run_pattern_block_chain (xp_awk_run_t* run, xp_awk_chain_t* chain)
|
||||||
{
|
{
|
||||||
xp_awk_nde_t* ptn;
|
|
||||||
|
|
||||||
while (run->exit_level != EXIT_GLOBAL &&
|
while (run->exit_level != EXIT_GLOBAL &&
|
||||||
run->exit_level != EXIT_ABORT && chain != XP_NULL)
|
run->exit_level != EXIT_ABORT && chain != XP_NULL)
|
||||||
{
|
{
|
||||||
@ -598,17 +607,31 @@ static int __run_pattern_block_chain (xp_awk_run_t* run, xp_awk_chain_t* chain)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (__run_pattern_block (run, chain) == -1) return -1;
|
||||||
|
chain = chain->next;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int __run_pattern_block (xp_awk_run_t* run, xp_awk_chain_t* chain)
|
||||||
|
{
|
||||||
|
xp_awk_nde_t* ptn;
|
||||||
|
xp_awk_nde_blk_t* blk;
|
||||||
|
|
||||||
ptn = chain->pattern;
|
ptn = chain->pattern;
|
||||||
|
blk = (xp_awk_nde_blk_t*)chain->action;
|
||||||
|
|
||||||
if (ptn == XP_NULL)
|
if (ptn == XP_NULL)
|
||||||
{
|
{
|
||||||
/* just execute the block */
|
/* just execute the block */
|
||||||
xp_awk_nde_blk_t* blk;
|
|
||||||
blk = (xp_awk_nde_blk_t*)chain->action;
|
|
||||||
if (__run_block (run, blk) == -1) return -1;
|
if (__run_block (run, blk) == -1) return -1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
if (ptn->next == XP_NULL)
|
||||||
|
{
|
||||||
|
/* pattern { ... } */
|
||||||
xp_awk_val_t* v1;
|
xp_awk_val_t* v1;
|
||||||
|
|
||||||
v1 = __eval_expression (run, ptn);
|
v1 = __eval_expression (run, ptn);
|
||||||
@ -616,12 +639,8 @@ static int __run_pattern_block_chain (xp_awk_run_t* run, xp_awk_chain_t* chain)
|
|||||||
|
|
||||||
xp_awk_refupval (v1);
|
xp_awk_refupval (v1);
|
||||||
|
|
||||||
if (ptn->next == XP_NULL)
|
|
||||||
{
|
|
||||||
if (xp_awk_valtobool(v1))
|
if (xp_awk_valtobool(v1))
|
||||||
{
|
{
|
||||||
xp_awk_nde_blk_t* blk;
|
|
||||||
blk = (xp_awk_nde_blk_t*)chain->action;
|
|
||||||
if (__run_block (run, blk) == -1)
|
if (__run_block (run, blk) == -1)
|
||||||
{
|
{
|
||||||
xp_awk_refdownval (run, v1);
|
xp_awk_refdownval (run, v1);
|
||||||
@ -636,14 +655,47 @@ static int __run_pattern_block_chain (xp_awk_run_t* run, xp_awk_chain_t* chain)
|
|||||||
/* pattern, pattern { ... } */
|
/* pattern, pattern { ... } */
|
||||||
xp_assert (ptn->next->next == XP_NULL);
|
xp_assert (ptn->next->next == XP_NULL);
|
||||||
|
|
||||||
/* TODO: implement this */
|
if (chain->pattern_range_state == 0)
|
||||||
|
{
|
||||||
|
xp_awk_val_t* v1;
|
||||||
|
|
||||||
|
v1 = __eval_expression (run, ptn);
|
||||||
|
if (v1 == XP_NULL) return -1;
|
||||||
|
xp_awk_refupval (v1);
|
||||||
|
|
||||||
|
if (xp_awk_valtobool(v1))
|
||||||
|
{
|
||||||
|
if (__run_block (run, blk) == -1)
|
||||||
|
{
|
||||||
xp_awk_refdownval (run, v1);
|
xp_awk_refdownval (run, v1);
|
||||||
xp_printf (XP_T("ERROR: pattern, pattern NOT OMPLEMENTED\n"));
|
return -1;
|
||||||
PANIC_I (run, XP_AWK_EINTERNAL);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
chain = chain->next;
|
chain->pattern_range_state = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
xp_awk_refdownval (run, v1);
|
||||||
|
}
|
||||||
|
else if (chain->pattern_range_state == 1)
|
||||||
|
{
|
||||||
|
xp_awk_val_t* v2;
|
||||||
|
|
||||||
|
v2 = __eval_expression (run, ptn->next);
|
||||||
|
if (v2 == XP_NULL) return -1;
|
||||||
|
xp_awk_refupval (v2);
|
||||||
|
|
||||||
|
if (__run_block (run, blk) == -1)
|
||||||
|
{
|
||||||
|
xp_awk_refdownval (run, v2);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (xp_awk_valtobool(v2))
|
||||||
|
chain->pattern_range_state = 0;
|
||||||
|
|
||||||
|
xp_awk_refdownval (run, v2);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* $Id: awk.c,v 1.60 2006-08-01 04:42:49 bacon Exp $
|
* $Id: awk.c,v 1.61 2006-08-02 14:36:23 bacon Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <xp/awk/awk.h>
|
#include <xp/awk/awk.h>
|
||||||
@ -303,8 +303,8 @@ static int next_extio_console (xp_awk_extio_t* epa);
|
|||||||
|
|
||||||
static const xp_char_t* infiles[] =
|
static const xp_char_t* infiles[] =
|
||||||
{
|
{
|
||||||
XP_T(""),
|
//XP_T(""),
|
||||||
//XP_T("awk.in"),
|
XP_T("awk.in"),
|
||||||
XP_NULL
|
XP_NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user