*** empty log message ***

This commit is contained in:
hyung-hwan 2006-06-28 10:40:24 +00:00
parent 0c0be8113f
commit ce526c2b2e
5 changed files with 73 additions and 85 deletions

View File

@ -1,5 +1,5 @@
/*
* $Id: extio.c,v 1.13 2006-06-28 08:56:59 bacon Exp $
* $Id: extio.c,v 1.14 2006-06-28 10:40:24 bacon Exp $
*/
#include <xp/awk/awk_i.h>
@ -11,12 +11,38 @@
#endif
int xp_awk_readextio (
xp_awk_run_t* run, int type, const xp_char_t* name, int* errnum)
xp_awk_run_t* run, int in_type, const xp_char_t* name, int* errnum)
{
xp_awk_extio_t* p = run->extio;
xp_awk_io_t handler = run->awk->extio[type];
int ioopt;
xp_awk_io_t handler;
int extio_type, extio_opt;
static int __in_type_map[] =
{
/* the order should match the order of the
* XP_AWK_IN_XXX values in tree.h */
XP_AWK_EXTIO_PIPE,
XP_AWK_EXTIO_COPROC,
XP_AWK_EXTIO_FILE
};
static int __in_opt_map[] =
{
/* the order should match the order of the
* XP_AWK_IN_XXX values in tree.h */
XP_AWK_IO_PIPE_READ,
0,
XP_AWK_IO_FILE_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));
/* translate the out_type into the relevant extio type and option */
extio_type = __in_type_map[in_type];
extio_opt = __in_opt_map[in_type];
handler = run->awk->extio[extio_type];
if (handler == XP_NULL)
{
/* no io handler provided */
@ -26,7 +52,8 @@ int xp_awk_readextio (
while (p != XP_NULL)
{
if (p->type == type && xp_strcmp(p->name,name) == 0) break;
if (p->type == in_type &&
xp_strcmp(p->name,name) == 0) break;
p = p->next;
}
@ -47,17 +74,11 @@ int xp_awk_readextio (
return -1;
}
p->type = type;
p->type = in_type;
p->handle = XP_NULL;
p->next = XP_NULL;
if (type == XP_AWK_EXTIO_PIPE)
ioopt = XP_AWK_IO_PIPE_READ;
else if (type == XP_AWK_EXTIO_FILE)
ioopt = XP_AWK_IO_FILE_READ;
else ioopt = 0; /* TODO: how to handle this??? */
if (handler (XP_AWK_IO_OPEN, ioopt, p, XP_NULL, 0) == -1)
if (handler (XP_AWK_IO_OPEN, extio_opt, p, XP_NULL, 0) == -1)
{
xp_free (p->name);
xp_free (p);

View File

@ -1,5 +1,5 @@
/*
* $Id: parse.c,v 1.126 2006-06-28 03:44:39 bacon Exp $
* $Id: parse.c,v 1.127 2006-06-28 10:40:24 bacon Exp $
*/
#include <xp/awk/awk_i.h>
@ -1467,9 +1467,9 @@ static xp_awk_nde_t* __parse_bitwise_or_with_extio (xp_awk_t* awk)
int in_type;
if (MATCH(awk,TOKEN_BOR))
in_type = XP_AWK_GETLINE_PIPE;
in_type = XP_AWK_IN_PIPE;
else if (MATCH(awk,TOKEN_BORAND))
in_type = XP_AWK_GETLINE_COPROC;
in_type = XP_AWK_IN_COPROC;
else break;
if (__get_token(awk) == -1)
@ -1524,7 +1524,7 @@ static xp_awk_nde_t* __parse_bitwise_or_with_extio (xp_awk_t* awk)
{
xp_awk_nde_exp_t* nde;
if (in_type == XP_AWK_GETLINE_COPROC)
if (in_type == XP_AWK_IN_COPROC)
{
xp_awk_clrpt (left);
PANIC (awk, XP_AWK_EGETLINE);
@ -2009,7 +2009,7 @@ 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_GETLINE_FILE;
nde->in_type = XP_AWK_IN_FILE;
nde->in = in;
return (xp_awk_nde_t*)nde;

View File

@ -1,5 +1,5 @@
/*
* $Id: run.c,v 1.111 2006-06-28 03:44:39 bacon Exp $
* $Id: run.c,v 1.112 2006-06-28 10:40:24 bacon Exp $
*/
#include <xp/awk/awk_i.h>
@ -3061,71 +3061,35 @@ 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_nde_getline_t*)nde;
xp_awk_val_t* in;
xp_char_t* str;
int errnum, n;
if (p->in_type == XP_AWK_GETLINE_PIPE)
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);
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)
{
xp_awk_val_t* in;
xp_char_t* str;
int errnum, n;
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)
{
xp_awk_refdownval (run, in);
PANIC (run, errnum);
}
xp_awk_refdownval (run, in);
n = xp_awk_readextio (run, XP_AWK_EXTIO_PIPE, str, &errnum);
xp_free (str);
/* TODO: set the value to var if it is not null */
/* TODO: set $0 if var is null */
if (n < 0 && errnum != XP_AWK_ENOERR) PANIC (run, errnum);
return xp_awk_makeintval (run, n);
PANIC (run, errnum);
}
else if (p->in_type == XP_AWK_GETLINE_COPROC)
{
xp_printf (XP_T("eval_getline coprocess not properly implemented....\n"));
return XP_NULL;
}
else if (p->in_type == XP_AWK_GETLINE_FILE)
{
xp_awk_val_t* in;
xp_char_t* str;
int errnum, n;
xp_awk_refdownval (run, in);
in = __eval_expression (run, p->in);
if (in == XP_NULL) return XP_NULL;
n = xp_awk_readextio (run, p->in_type, str, &errnum);
xp_free (str);
xp_awk_refupval (in);
str = xp_awk_valtostr (in, &errnum, XP_NULL);
if (str == XP_NULL)
{
xp_awk_refdownval (run, in);
PANIC (run, errnum);
}
xp_awk_refdownval (run, in);
/* TODO: set the value to var if it is not null */
/* TODO: set $0 if var is null */
n = xp_awk_readextio (run, XP_AWK_EXTIO_FILE, str, &errnum);
xp_free (str);
/* TODO: set the value to var if it is not null */
/* TODO: set $0 if var is null */
if (n < 0 && errnum != XP_AWK_ENOERR) PANIC (run, errnum);
return xp_awk_makeintval (run, n);
}
else
{
xp_assert (!"should never happen - wrong in_type for getline");
PANIC (run, XP_AWK_EINTERNAL);
}
if (n < 0 && errnum != XP_AWK_ENOERR) PANIC (run, errnum);
return xp_awk_makeintval (run, n);
}
static int __raw_push (xp_awk_run_t* run, void* val)

View File

@ -1,5 +1,5 @@
/*
* $Id: tree.c,v 1.58 2006-06-27 14:18:19 bacon Exp $
* $Id: tree.c,v 1.59 2006-06-28 10:40:24 bacon Exp $
*/
#include <xp/awk/awk_i.h>
@ -364,8 +364,8 @@ static int __print_expression (xp_awk_nde_t* nde)
/* TODO */
xp_awk_nde_getline_t* px = (xp_awk_nde_getline_t*)nde;
if (px->in != XP_NULL &&
(px->in_type == XP_AWK_GETLINE_PIPE ||
px->in_type == XP_AWK_GETLINE_COPROC))
(px->in_type == XP_AWK_IN_PIPE ||
px->in_type == XP_AWK_IN_COPROC))
{
__print_expression (px->in);
xp_printf (XP_T(" %s "),
@ -380,7 +380,7 @@ static int __print_expression (xp_awk_nde_t* nde)
}
if (px->in != XP_NULL &&
px->in_type == XP_AWK_GETLINE_FILE)
px->in_type == XP_AWK_IN_FILE)
{
xp_printf (XP_T(" %s "),
__getline_inop_str[px->in_type]);

View File

@ -1,5 +1,5 @@
/*
* $Id: tree.h,v 1.52 2006-06-28 03:44:40 bacon Exp $
* $Id: tree.h,v 1.53 2006-06-28 10:40:24 bacon Exp $
*/
#ifndef _XP_AWK_TREE_H_
@ -60,9 +60,12 @@ enum
enum
{
XP_AWK_GETLINE_PIPE,
XP_AWK_GETLINE_COPROC,
XP_AWK_GETLINE_FILE
/* the order of these values match
* __in_type_map and __in_opt_map in extio.c */
XP_AWK_IN_PIPE,
XP_AWK_IN_COPROC,
XP_AWK_IN_FILE
};
enum