*** empty log message ***

This commit is contained in:
2006-06-29 14:38:01 +00:00
parent 501a22ab04
commit a60f6124dc
7 changed files with 172 additions and 57 deletions

View File

@ -1,5 +1,5 @@
/*
* $Id: extio.c,v 1.15 2006-06-28 14:19:01 bacon Exp $
* $Id: extio.c,v 1.16 2006-06-29 14:38:01 bacon Exp $
*/
#include <xp/awk/awk_i.h>
@ -10,13 +10,21 @@
#include <xp/bas/memory.h>
#endif
enum
{
__MASK_READ = 0x01FF,
__MASK_WRITE = 0x02FF,
__MASK_RDWR = 0x04FF,
__MASK_CLEAR = 0x00FF
};
int xp_awk_readextio (
xp_awk_run_t* run, int in_type,
const xp_char_t* name, xp_str_t* buf, int* errnum)
{
xp_awk_extio_t* p = run->extio;
xp_awk_io_t handler;
int extio_type, extio_opt;
int extio_type, extio_opt, extio_mask;
static int __in_type_map[] =
{
@ -24,7 +32,8 @@ int xp_awk_readextio (
* XP_AWK_IN_XXX values in tree.h */
XP_AWK_EXTIO_PIPE,
XP_AWK_EXTIO_COPROC,
XP_AWK_EXTIO_FILE
XP_AWK_EXTIO_FILE,
XP_AWK_EXTIO_CONSOLE
};
static int __in_opt_map[] =
@ -33,15 +42,26 @@ int xp_awk_readextio (
* XP_AWK_IN_XXX values in tree.h */
XP_AWK_IO_PIPE_READ,
0,
XP_AWK_IO_FILE_READ,
XP_AWK_IO_FILE_READ
};
static int __in_mask_map[] =
{
__MASK_READ,
__MASK_RDWR,
__MASK_READ,
__MASK_READ
};
xp_assert (in_type >= 0 && in_type <= xp_countof(__in_type_map));
xp_assert (in_type >= 0 && in_type <= xp_countof(__in_opt_map));
xp_assert (in_type >= 0 && in_type <= xp_countof(__in_mask_map));
/* translate the out_type into the relevant extio type and option */
/* translate the in_type into the relevant extio type and option */
extio_type = __in_type_map[in_type];
extio_opt = __in_opt_map[in_type];
extio_mask = __in_mask_map[in_type];
handler = run->awk->extio[extio_type];
if (handler == XP_NULL)
@ -53,7 +73,7 @@ int xp_awk_readextio (
while (p != XP_NULL)
{
if (p->type == in_type &&
if (p->type == (extio_type | extio_mask) &&
xp_strcmp(p->name,name) == 0) break;
p = p->next;
}
@ -75,7 +95,7 @@ int xp_awk_readextio (
return -1;
}
p->type = in_type;
p->type = (extio_type | extio_mask);
p->handle = XP_NULL;
p->in.buf[0] = XP_C('\0');
@ -170,7 +190,7 @@ int xp_awk_writeextio (
xp_awk_extio_t* p = run->extio;
xp_awk_io_t handler;
xp_str_t buf;
int extio_type, extio_opt;
int extio_type, extio_opt, extio_mask;
static int __out_type_map[] =
{
@ -194,12 +214,23 @@ int xp_awk_writeextio (
XP_AWK_IO_CONSOLE_WRITE
};
static int __out_mask_map[] =
{
__MASK_WRITE,
__MASK_RDWR,
__MASK_WRITE,
__MASK_WRITE,
__MASK_WRITE
};
xp_assert (out_type >= 0 && out_type <= xp_countof(__out_type_map));
xp_assert (out_type >= 0 && out_type <= xp_countof(__out_opt_map));
xp_assert (out_type >= 0 && out_type <= xp_countof(__out_mask_map));
/* translate the out_type into the relevant extio type and option */
extio_type = __out_type_map[out_type];
extio_opt = __out_opt_map[out_type];
extio_mask = __out_mask_map[out_type];
handler = run->awk->extio[extio_type];
if (handler == XP_NULL)
@ -237,7 +268,7 @@ int xp_awk_writeextio (
* print "1111" > "1.tmp"
*/
if (p->type == extio_type &&
if (p->type == (extio_type | extio_mask) &&
xp_strcmp(p->name,name) == 0) break;
p = p->next;
}
@ -262,7 +293,7 @@ int xp_awk_writeextio (
return -1;
}
p->type = extio_type;
p->type = (extio_type | extio_mask);
p->handle = XP_NULL;
p->next = XP_NULL;
@ -316,8 +347,9 @@ int xp_awk_closeextio (xp_awk_run_t* run, const xp_char_t* name, int* errnum)
* regardless of the extio type */
if (xp_strcmp(p->name,name) == 0)
{
xp_awk_io_t handler = run->awk->extio[p->type];
xp_awk_io_t handler;
handler = run->awk->extio[p->type & __MASK_CLEAR];
if (handler != NULL)
{
/* TODO: io command should not be XP_AWK_IO_CLOSE
@ -355,7 +387,7 @@ void xp_awk_clearextio (xp_awk_run_t* run)
while (run->extio != XP_NULL)
{
handler = run->awk->extio[run->extio->type];
handler = run->awk->extio[run->extio->type & __MASK_CLEAR];
next = run->extio->next;
if (handler != XP_NULL)

View File

@ -1,5 +1,5 @@
/*
* $Id: parse.c,v 1.127 2006-06-28 10:40:24 bacon Exp $
* $Id: parse.c,v 1.128 2006-06-29 14:38:01 bacon Exp $
*/
#include <xp/awk/awk_i.h>
@ -1142,7 +1142,11 @@ static xp_awk_nde_t* __parse_expression (xp_awk_t* awk)
if (x == XP_NULL) return XP_NULL;
opcode = __assign_to_opcode (awk);
if (opcode == -1) return x;
if (opcode == -1)
{
/* no assignment operator found. */
return x;
}
xp_assert (x->next == XP_NULL);
if (!__is_var(x) && x->type != XP_AWK_NDE_POS)
@ -2009,7 +2013,8 @@ static xp_awk_nde_t* __parse_primary (xp_awk_t* awk)
nde->type = XP_AWK_NDE_GETLINE;
nde->next = XP_NULL;
nde->var = var;
nde->in_type = XP_AWK_IN_FILE;
nde->in_type = (in == XP_NULL)?
XP_AWK_IN_CONSOLE: XP_AWK_IN_FILE;
nde->in = in;
return (xp_awk_nde_t*)nde;

View File

@ -1,5 +1,5 @@
/*
* $Id: run.c,v 1.113 2006-06-28 14:19:01 bacon Exp $
* $Id: run.c,v 1.114 2006-06-29 14:38:01 bacon Exp $
*/
#include <xp/awk/awk_i.h>
@ -3066,39 +3066,45 @@ static xp_awk_val_t* __eval_pos (xp_awk_run_t* run, xp_awk_nde_t* nde)
static xp_awk_val_t* __eval_getline (xp_awk_run_t* run, xp_awk_nde_t* nde)
{
xp_awk_nde_getline_t* p;
xp_awk_val_t* in, * res;
xp_char_t* str;
xp_awk_val_t* v, * res;
xp_char_t* in = XP_NULL;
const xp_char_t* dst;
xp_str_t buf;
int errnum, n;
p = (xp_awk_nde_getline_t*)nde;
xp_assert (p->in_type == XP_AWK_IN_PIPE ||
p->in_type == XP_AWK_IN_COPROC ||
p->in_type == XP_AWK_IN_FILE);
xp_assert (p->in != XP_NULL);
xp_assert ((p->in_type == XP_AWK_IN_PIPE && p->in != XP_NULL) ||
(p->in_type == XP_AWK_IN_COPROC && p->in != XP_NULL) ||
(p->in_type == XP_AWK_IN_FILE && p->in != XP_NULL) ||
(p->in_type == XP_AWK_IN_CONSOLE && p->in == XP_NULL));
in = __eval_expression (run, p->in);
if (in == XP_NULL) return XP_NULL;
xp_awk_refupval (in);
str = xp_awk_valtostr (in, &errnum, XP_NULL);
if (str == XP_NULL)
if (p->in != XP_NULL)
{
xp_awk_refdownval (run, in);
PANIC (run, errnum);
v = __eval_expression (run, p->in);
if (v == XP_NULL) return XP_NULL;
xp_awk_refupval (v);
in = xp_awk_valtostr (v, &errnum, XP_NULL);
if (in == XP_NULL)
{
xp_awk_refdownval (run, v);
PANIC (run, errnum);
}
xp_awk_refdownval (run, v);
}
xp_awk_refdownval (run, in);
dst = (in == XP_NULL)? XP_T(""): in;
/* TODO: optimization in line buffer management */
if (xp_str_open (&buf, 256) == XP_NULL)
{
xp_free (str);
if (in != XP_NULL) xp_free (in);
PANIC (run, XP_AWK_ENOMEM);
}
n = xp_awk_readextio (run, p->in_type, str, &buf, &errnum);
xp_free (str);
n = xp_awk_readextio (run, p->in_type, dst, &buf, &errnum);
if (in != XP_NULL) xp_free (in);
if (n < 0 && errnum != XP_AWK_ENOERR)
{

View File

@ -1,5 +1,5 @@
/*
* $Id: tree.c,v 1.59 2006-06-28 10:40:24 bacon Exp $
* $Id: tree.c,v 1.60 2006-06-29 14:38:01 bacon Exp $
*/
#include <xp/awk/awk_i.h>
@ -72,7 +72,8 @@ static const xp_char_t* __getline_inop_str[] =
{
XP_T("|"),
XP_T("|&"),
XP_T("<")
XP_T("<"),
XP_T("")
};
static const xp_char_t* __print_outop_str[] =

View File

@ -1,5 +1,5 @@
/*
* $Id: tree.h,v 1.54 2006-06-28 14:19:01 bacon Exp $
* $Id: tree.h,v 1.55 2006-06-29 14:38:01 bacon Exp $
*/
#ifndef _XP_AWK_TREE_H_
@ -65,7 +65,8 @@ enum
XP_AWK_IN_PIPE,
XP_AWK_IN_COPROC,
XP_AWK_IN_FILE
XP_AWK_IN_FILE,
XP_AWK_IN_CONSOLE
};
enum