added a dual direction pipe (rwpipe) to awk.

- will not work on WIN32 until qse_pcp_t is completed on the platform.
This commit is contained in:
hyung-hwan 2009-01-17 04:20:22 +00:00
parent 46e4ed5087
commit 07d8efa7c2
12 changed files with 204 additions and 115 deletions

View File

@ -162,6 +162,7 @@ static struct
{ QSE_T("shift"), QSE_AWK_SHIFT }, { QSE_T("shift"), QSE_AWK_SHIFT },
{ QSE_T("idiv"), QSE_AWK_IDIV }, { QSE_T("idiv"), QSE_AWK_IDIV },
{ QSE_T("extio"), QSE_AWK_EXTIO }, { QSE_T("extio"), QSE_AWK_EXTIO },
{ QSE_T("rwpipe"), QSE_AWK_RWPIPE },
{ QSE_T("newline"), QSE_AWK_NEWLINE }, { QSE_T("newline"), QSE_AWK_NEWLINE },
{ QSE_T("baseone"), QSE_AWK_BASEONE }, { QSE_T("baseone"), QSE_AWK_BASEONE },
{ QSE_T("stripspaces"), QSE_AWK_STRIPSPACES }, { QSE_T("stripspaces"), QSE_AWK_STRIPSPACES },
@ -524,6 +525,7 @@ static int awk_main (int argc, qse_char_t* argv[])
qse_awk_runarg_t runarg[128]; qse_awk_runarg_t runarg[128];
int deparse = 0; int deparse = 0;
struct argout_t ao; struct argout_t ao;
int ret = 0;
qse_memset (&ao, 0, QSE_SIZEOF(ao)); qse_memset (&ao, 0, QSE_SIZEOF(ao));
@ -552,8 +554,8 @@ static int awk_main (int argc, qse_char_t* argv[])
qse_awk_geterrmsg(awk) qse_awk_geterrmsg(awk)
); );
qse_awk_close (awk); ret = -1;
return -1; goto oops;
} }
#ifdef _WIN32 #ifdef _WIN32
@ -577,10 +579,11 @@ static int awk_main (int argc, qse_char_t* argv[])
qse_awk_geterrmsg(awk) qse_awk_geterrmsg(awk)
); );
qse_awk_close (awk); ret = -1;
return -1; goto oops;
} }
oops:
qse_awk_close (awk); qse_awk_close (awk);
if (ao.ist == QSE_AWK_PARSE_FILES && ao.isp != QSE_NULL) free (ao.isp); if (ao.ist == QSE_AWK_PARSE_FILES && ao.isp != QSE_NULL) free (ao.isp);
@ -588,7 +591,7 @@ static int awk_main (int argc, qse_char_t* argv[])
if (ao.icf != QSE_NULL) free (ao.icf); if (ao.icf != QSE_NULL) free (ao.icf);
if (ao.vm != QSE_NULL) qse_map_close (ao.vm); if (ao.vm != QSE_NULL) qse_map_close (ao.vm);
return 0; return ret;
} }
int qse_main (int argc, qse_achar_t* argv[]) int qse_main (int argc, qse_achar_t* argv[])

View File

@ -511,7 +511,6 @@ public:
ERR_NEXTFEND = QSE_AWK_ENEXTFEND, ERR_NEXTFEND = QSE_AWK_ENEXTFEND,
ERR_PRINTFARG = QSE_AWK_EPRINTFARG, ERR_PRINTFARG = QSE_AWK_EPRINTFARG,
ERR_PREPST = QSE_AWK_EPREPST, ERR_PREPST = QSE_AWK_EPREPST,
ERR_GLNCPS = QSE_AWK_EGLNCPS,
ERR_DIVBY0 = QSE_AWK_EDIVBY0, ERR_DIVBY0 = QSE_AWK_EDIVBY0,
ERR_OPERAND = QSE_AWK_EOPERAND, ERR_OPERAND = QSE_AWK_EOPERAND,
ERR_POSIDX = QSE_AWK_EPOSIDX, ERR_POSIDX = QSE_AWK_EPOSIDX,
@ -572,7 +571,7 @@ public:
OPT_SHIFT = QSE_AWK_SHIFT, OPT_SHIFT = QSE_AWK_SHIFT,
OPT_IDIV = QSE_AWK_IDIV, OPT_IDIV = QSE_AWK_IDIV,
OPT_EXTIO = QSE_AWK_EXTIO, OPT_EXTIO = QSE_AWK_EXTIO,
OPT_COPROC = QSE_AWK_COPROC, OPT_RWPIPE = QSE_AWK_RWPIPE,
/** Can terminate a statement with a new line */ /** Can terminate a statement with a new line */
OPT_NEWLINE = QSE_AWK_NEWLINE, OPT_NEWLINE = QSE_AWK_NEWLINE,

View File

@ -180,8 +180,8 @@ enum qse_awk_option_t
/* support getline and print */ /* support getline and print */
QSE_AWK_EXTIO = (1 << 7), QSE_AWK_EXTIO = (1 << 7),
/* support co-process - NOT IMPLEMENTED YET */ /* support dual direction pipe. QSE_AWK_EXTIO must be on */
QSE_AWK_COPROC = (1 << 8), QSE_AWK_RWPIPE = (1 << 8),
/* can terminate a statement with a new line */ /* can terminate a statement with a new line */
QSE_AWK_NEWLINE = (1 << 9), QSE_AWK_NEWLINE = (1 << 9),
@ -318,7 +318,6 @@ enum qse_awk_errnum_t
QSE_AWK_EPRINTFARG, /* printf not followed by any arguments */ QSE_AWK_EPRINTFARG, /* printf not followed by any arguments */
QSE_AWK_EPREPST, /* both prefix and postfix increment/decrement QSE_AWK_EPREPST, /* both prefix and postfix increment/decrement
operator present */ operator present */
QSE_AWK_EGLNCPS, /* coprocess not supported by getline */
/* run time error */ /* run time error */
QSE_AWK_EDIVBY0, /* divide by zero */ QSE_AWK_EDIVBY0, /* divide by zero */
@ -391,7 +390,6 @@ enum qse_awk_extio_type_t
{ {
/* extio types available */ /* extio types available */
QSE_AWK_EXTIO_PIPE, QSE_AWK_EXTIO_PIPE,
QSE_AWK_EXTIO_COPROC,
QSE_AWK_EXTIO_FILE, QSE_AWK_EXTIO_FILE,
QSE_AWK_EXTIO_CONSOLE, QSE_AWK_EXTIO_CONSOLE,
@ -403,12 +401,7 @@ enum qse_awk_extio_mode_t
{ {
QSE_AWK_EXTIO_PIPE_READ = 0, QSE_AWK_EXTIO_PIPE_READ = 0,
QSE_AWK_EXTIO_PIPE_WRITE = 1, QSE_AWK_EXTIO_PIPE_WRITE = 1,
QSE_AWK_EXTIO_PIPE_RW = 2,
/*
QSE_AWK_EXTIO_COPROC_READ = 0,
QSE_AWK_EXTIO_COPROC_WRITE = 1,
QSE_AWK_EXTIO_COPROC_RDWR = 2,
*/
QSE_AWK_EXTIO_FILE_READ = 0, QSE_AWK_EXTIO_FILE_READ = 0,
QSE_AWK_EXTIO_FILE_WRITE = 1, QSE_AWK_EXTIO_FILE_WRITE = 1,

View File

@ -1327,7 +1327,6 @@ int Awk::run (const char_t* main, const char_t** args, size_t nargs)
Run runctx (this); Run runctx (this);
runios.pipe = pipeHandler; runios.pipe = pipeHandler;
runios.coproc = QSE_NULL;
runios.file = fileHandler; runios.file = fileHandler;
runios.console = consoleHandler; runios.console = consoleHandler;
runios.data = this; runios.data = this;

View File

@ -113,7 +113,6 @@ static const qse_char_t* __geterrstr (int errnum)
QSE_T("nextfile statement illegal in the END block"), QSE_T("nextfile statement illegal in the END block"),
QSE_T("printf not followed by any arguments"), QSE_T("printf not followed by any arguments"),
QSE_T("both prefix and postfix increment/decrement operator present"), QSE_T("both prefix and postfix increment/decrement operator present"),
QSE_T("coprocess not supported by getline"),
QSE_T("divide by zero"), QSE_T("divide by zero"),
QSE_T("invalid operand"), QSE_T("invalid operand"),

View File

@ -32,7 +32,7 @@ static int in_type_map[] =
/* the order should match the order of the /* the order should match the order of the
* QSE_AWK_IN_XXX values in tree.h */ * QSE_AWK_IN_XXX values in tree.h */
QSE_AWK_EXTIO_PIPE, QSE_AWK_EXTIO_PIPE,
QSE_AWK_EXTIO_COPROC, QSE_AWK_EXTIO_PIPE,
QSE_AWK_EXTIO_FILE, QSE_AWK_EXTIO_FILE,
QSE_AWK_EXTIO_CONSOLE QSE_AWK_EXTIO_CONSOLE
}; };
@ -42,7 +42,7 @@ static int in_mode_map[] =
/* the order should match the order of the /* the order should match the order of the
* QSE_AWK_IN_XXX values in tree.h */ * QSE_AWK_IN_XXX values in tree.h */
QSE_AWK_EXTIO_PIPE_READ, QSE_AWK_EXTIO_PIPE_READ,
0, QSE_AWK_EXTIO_PIPE_RW,
QSE_AWK_EXTIO_FILE_READ, QSE_AWK_EXTIO_FILE_READ,
QSE_AWK_EXTIO_CONSOLE_READ QSE_AWK_EXTIO_CONSOLE_READ
}; };
@ -60,7 +60,7 @@ static int out_type_map[] =
/* the order should match the order of the /* the order should match the order of the
* QSE_AWK_OUT_XXX values in tree.h */ * QSE_AWK_OUT_XXX values in tree.h */
QSE_AWK_EXTIO_PIPE, QSE_AWK_EXTIO_PIPE,
QSE_AWK_EXTIO_COPROC, QSE_AWK_EXTIO_PIPE,
QSE_AWK_EXTIO_FILE, QSE_AWK_EXTIO_FILE,
QSE_AWK_EXTIO_FILE, QSE_AWK_EXTIO_FILE,
QSE_AWK_EXTIO_CONSOLE QSE_AWK_EXTIO_CONSOLE
@ -71,7 +71,7 @@ static int out_mode_map[] =
/* the order should match the order of the /* the order should match the order of the
* QSE_AWK_OUT_XXX values in tree.h */ * QSE_AWK_OUT_XXX values in tree.h */
QSE_AWK_EXTIO_PIPE_WRITE, QSE_AWK_EXTIO_PIPE_WRITE,
0, QSE_AWK_EXTIO_PIPE_RW,
QSE_AWK_EXTIO_FILE_WRITE, QSE_AWK_EXTIO_FILE_WRITE,
QSE_AWK_EXTIO_FILE_APPEND, QSE_AWK_EXTIO_FILE_APPEND,
QSE_AWK_EXTIO_CONSOLE_WRITE QSE_AWK_EXTIO_CONSOLE_WRITE
@ -109,6 +109,7 @@ int qse_awk_readextio (
extio_mode = in_mode_map[in_type]; extio_mode = in_mode_map[in_type];
extio_mask = in_mask_map[in_type]; extio_mask = in_mask_map[in_type];
/* get the io handler provided by a user */
handler = run->extio.handler[extio_type]; handler = run->extio.handler[extio_type];
if (handler == QSE_NULL) if (handler == QSE_NULL)
{ {
@ -117,6 +118,7 @@ int qse_awk_readextio (
return -1; return -1;
} }
/* search the chain for exiting an existing io name */
while (p != QSE_NULL) while (p != QSE_NULL)
{ {
if (p->type == (extio_type | extio_mask) && if (p->type == (extio_type | extio_mask) &&
@ -126,6 +128,8 @@ int qse_awk_readextio (
if (p == QSE_NULL) if (p == QSE_NULL)
{ {
/* if the name doesn't exist in the chain, create an entry
* to the chain */
p = (qse_awk_extio_t*) QSE_AWK_ALLOC ( p = (qse_awk_extio_t*) QSE_AWK_ALLOC (
run->awk, QSE_SIZEOF(qse_awk_extio_t)); run->awk, QSE_SIZEOF(qse_awk_extio_t));
if (p == QSE_NULL) if (p == QSE_NULL)
@ -157,6 +161,7 @@ int qse_awk_readextio (
qse_awk_setrunerrnum (run, QSE_AWK_ENOERR); qse_awk_setrunerrnum (run, QSE_AWK_ENOERR);
/* request to open the stream */
x = handler (QSE_AWK_IO_OPEN, p, QSE_NULL, 0); x = handler (QSE_AWK_IO_OPEN, p, QSE_NULL, 0);
if (x <= -1) if (x <= -1)
{ {
@ -195,7 +200,7 @@ int qse_awk_readextio (
return 0; return 0;
} }
/* ready to read a line */ /* ready to read a line. clear the line buffer */
qse_str_clear (buf); qse_str_clear (buf);
/* get the record separator */ /* get the record separator */
@ -240,7 +245,7 @@ int qse_awk_readextio (
qse_awk_setrunerrnum (run, QSE_AWK_ENOERR); qse_awk_setrunerrnum (run, QSE_AWK_ENOERR);
n = handler (QSE_AWK_IO_READ, n = handler (QSE_AWK_IO_READ,
p, p->in.buf, QSE_COUNTOF(p->in.buf)); p, p->in.buf, QSE_COUNTOF(p->in.buf));
if (n <= -1) if (n <= -1)
{ {
@ -406,7 +411,6 @@ int qse_awk_readextio (
return ret; return ret;
} }
#include <qse/utl/stdio.h>
int qse_awk_writeextio_val ( int qse_awk_writeextio_val (
qse_awk_run_t* run, int out_type, qse_awk_run_t* run, int out_type,
const qse_char_t* name, qse_awk_val_t* v) const qse_char_t* name, qse_awk_val_t* v)
@ -467,7 +471,7 @@ int qse_awk_writeextio_str (
/* the file "1.tmp", in the following code snippets, /* the file "1.tmp", in the following code snippets,
* would be opened by the first print statement, but not by * would be opened by the first print statement, but not by
* the second print statement. this is because * the second print statement. this is because
* both QSE_AWK_OUT_FILE and QSE_AWK_OUT_FILE_APPEND are * both QSE_AWK_OUT_FILE and QSE_AWK_OUT_APFILE are
* translated to QSE_AWK_EXTIO_FILE and it is used to * translated to QSE_AWK_EXTIO_FILE and it is used to
* keep track of file handles.. * keep track of file handles..
* *

View File

@ -237,7 +237,7 @@ static int bfn_close (
nargs = qse_awk_getnargs (run); nargs = qse_awk_getnargs (run);
QSE_ASSERT (nargs == 1); QSE_ASSERT (nargs == 1);
/* TODO: support close (xxx, "to"/"from") like gawk */ /* TODO: support close (xxx, "to"/"from"/"rw"/"r"/"w"/????) */
a0 = qse_awk_getarg (run, 0); a0 = qse_awk_getarg (run, 0);
QSE_ASSERT (a0 != QSE_NULL); QSE_ASSERT (a0 != QSE_NULL);
@ -392,13 +392,9 @@ static int bfn_fflush (
run, QSE_AWK_EXTIO_PIPE, run, QSE_AWK_EXTIO_PIPE,
((len0 == 0)? QSE_NULL: str0), n); ((len0 == 0)? QSE_NULL: str0), n);
/*if (n == -99) return -1;*/ /*if (n == -99) return -1;*/
n = flush_extio (
run, QSE_AWK_EXTIO_COPROC,
((len0 == 0)? QSE_NULL: str0), n);
/*if (n == -99) return -1;*/
/* if n remains 1, no ip handlers have been defined for /* if n remains 1, no ip handlers have been defined for
* file, pipe, and coproc. so make fflush return -1. * file, pipe, and rwpipe. so make fflush return -1.
* if n is -2, no such named io has been found at all * if n is -2, no such named io has been found at all
* if n is -1, the io handler has returned an error */ * if n is -1, the io handler has returned an error */
if (n != 0) n = -1; if (n != 0) n = -1;

View File

@ -60,7 +60,6 @@ enum token_t
TOKEN_BOR, TOKEN_BOR,
TOKEN_BXOR, TOKEN_BXOR,
TOKEN_BAND, TOKEN_BAND,
TOKEN_BORAND,
TOKEN_TILDE, /* used for unary bitwise-not and regex match */ TOKEN_TILDE, /* used for unary bitwise-not and regex match */
TOKEN_RSHIFT, TOKEN_RSHIFT,
TOKEN_LSHIFT, TOKEN_LSHIFT,
@ -179,6 +178,7 @@ static qse_awk_nde_t* parse_binary_expr (
qse_awk_nde_t*(*next_level_func)(qse_awk_t*,qse_size_t)); qse_awk_nde_t*(*next_level_func)(qse_awk_t*,qse_size_t));
static qse_awk_nde_t* parse_logical_or (qse_awk_t* awk, qse_size_t line); static qse_awk_nde_t* parse_logical_or (qse_awk_t* awk, qse_size_t line);
static qse_awk_nde_t* parse_logical_or_with_extio (qse_awk_t* awk, qse_size_t line);
static qse_awk_nde_t* parse_logical_and (qse_awk_t* awk, qse_size_t line); static qse_awk_nde_t* parse_logical_and (qse_awk_t* awk, qse_size_t line);
static qse_awk_nde_t* parse_in (qse_awk_t* awk, qse_size_t line); static qse_awk_nde_t* parse_in (qse_awk_t* awk, qse_size_t line);
static qse_awk_nde_t* parse_regex_match (qse_awk_t* awk, qse_size_t line); static qse_awk_nde_t* parse_regex_match (qse_awk_t* awk, qse_size_t line);
@ -2227,13 +2227,115 @@ static qse_awk_nde_t* parse_binary_expr (
static qse_awk_nde_t* parse_logical_or (qse_awk_t* awk, qse_size_t line) static qse_awk_nde_t* parse_logical_or (qse_awk_t* awk, qse_size_t line)
{ {
static binmap_t map[] = if ((awk->option & QSE_AWK_EXTIO) &&
(awk->option & QSE_AWK_RWPIPE))
{ {
{ TOKEN_LOR, QSE_AWK_BINOP_LOR }, return parse_logical_or_with_extio (awk, line);
{ TOKEN_EOF, 0 } }
}; else
{
static binmap_t map[] =
{
{ TOKEN_LOR, QSE_AWK_BINOP_LOR },
{ TOKEN_EOF, 0 }
};
return parse_binary_expr (awk, line, 1, map, parse_logical_and); return parse_binary_expr (awk, line, 1, map, parse_logical_and);
}
}
static qse_awk_nde_t* parse_logical_or_with_extio (qse_awk_t* awk, qse_size_t line)
{
qse_awk_nde_t* left, * right;
left = parse_logical_and (awk, line);
if (left == QSE_NULL) return QSE_NULL;
while (MATCH(awk,TOKEN_LOR))
{
if (get_token(awk) == -1)
{
qse_awk_clrpt (awk, left);
return QSE_NULL;
}
if (MATCH(awk,TOKEN_GETLINE))
{
qse_awk_nde_getline_t* nde;
qse_awk_nde_t* var = QSE_NULL;
if (get_token(awk) == -1)
{
qse_awk_clrpt (awk, left);
return QSE_NULL;
}
/* TODO: is this correct? */
if (MATCH(awk,TOKEN_IDENT))
{
/* command | getline var */
var = parse_primary (awk, awk->token.line);
if (var == QSE_NULL)
{
qse_awk_clrpt (awk, left);
return QSE_NULL;
}
}
nde = (qse_awk_nde_getline_t*) QSE_AWK_ALLOC (
awk, QSE_SIZEOF(qse_awk_nde_getline_t));
if (nde == QSE_NULL)
{
qse_awk_clrpt (awk, left);
SETERRLIN (awk, QSE_AWK_ENOMEM, line);
return QSE_NULL;
}
nde->type = QSE_AWK_NDE_GETLINE;
nde->line = line;
nde->next = QSE_NULL;
nde->var = var;
nde->in_type = QSE_AWK_IN_RWPIPE;
nde->in = left;
left = (qse_awk_nde_t*)nde;
}
else
{
qse_awk_nde_exp_t* nde;
right = parse_logical_and (awk, awk->token.line);
if (right == QSE_NULL)
{
qse_awk_clrpt (awk, left);
return QSE_NULL;
}
nde = (qse_awk_nde_exp_t*) QSE_AWK_ALLOC (
awk, QSE_SIZEOF(qse_awk_nde_exp_t));
if (nde == QSE_NULL)
{
qse_awk_clrpt (awk, right);
qse_awk_clrpt (awk, left);
SETERRLIN (awk, QSE_AWK_ENOMEM, line);
return QSE_NULL;
}
nde->type = QSE_AWK_NDE_EXP_BIN;
nde->line = line;
nde->next = QSE_NULL;
nde->opcode = QSE_AWK_BINOP_LOR;
nde->left = left;
nde->right = right;
left = (qse_awk_nde_t*)nde;
}
}
return left;
} }
static qse_awk_nde_t* parse_logical_and (qse_awk_t* awk, qse_size_t line) static qse_awk_nde_t* parse_logical_and (qse_awk_t* awk, qse_size_t line)
@ -2356,16 +2458,8 @@ static qse_awk_nde_t* parse_bitwise_or_with_extio (qse_awk_t* awk, qse_size_t li
left = parse_bitwise_xor (awk, line); left = parse_bitwise_xor (awk, line);
if (left == QSE_NULL) return QSE_NULL; if (left == QSE_NULL) return QSE_NULL;
while (1) while (MATCH(awk,TOKEN_BOR))
{ {
int in_type;
if (MATCH(awk,TOKEN_BOR))
in_type = QSE_AWK_IN_PIPE;
else if (MATCH(awk,TOKEN_BORAND))
in_type = QSE_AWK_IN_COPROC;
else break;
if (get_token(awk) == -1) if (get_token(awk) == -1)
{ {
qse_awk_clrpt (awk, left); qse_awk_clrpt (awk, left);
@ -2412,7 +2506,7 @@ static qse_awk_nde_t* parse_bitwise_or_with_extio (qse_awk_t* awk, qse_size_t li
nde->line = line; nde->line = line;
nde->next = QSE_NULL; nde->next = QSE_NULL;
nde->var = var; nde->var = var;
nde->in_type = in_type; nde->in_type = QSE_AWK_IN_PIPE;
nde->in = left; nde->in = left;
left = (qse_awk_nde_t*)nde; left = (qse_awk_nde_t*)nde;
@ -2421,15 +2515,6 @@ static qse_awk_nde_t* parse_bitwise_or_with_extio (qse_awk_t* awk, qse_size_t li
{ {
qse_awk_nde_exp_t* nde; qse_awk_nde_exp_t* nde;
if (in_type == QSE_AWK_IN_COPROC)
{
qse_awk_clrpt (awk, left);
/* TODO: support coprocess */
SETERRLIN (awk, QSE_AWK_EGLNCPS, line);
return QSE_NULL;
}
right = parse_bitwise_xor (awk, awk->token.line); right = parse_bitwise_xor (awk, awk->token.line);
if (right == QSE_NULL) if (right == QSE_NULL)
{ {
@ -4423,7 +4508,7 @@ static qse_awk_nde_t* parse_print (qse_awk_t* awk, qse_size_t line, int type)
!MATCH(awk,TOKEN_GT) && !MATCH(awk,TOKEN_GT) &&
!MATCH(awk,TOKEN_RSHIFT) && !MATCH(awk,TOKEN_RSHIFT) &&
!MATCH(awk,TOKEN_BOR) && !MATCH(awk,TOKEN_BOR) &&
!MATCH(awk,TOKEN_BORAND)) !MATCH(awk,TOKEN_LOR))
{ {
qse_awk_nde_t* args_tail; qse_awk_nde_t* args_tail;
qse_awk_nde_t* tail_prev; qse_awk_nde_t* tail_prev;
@ -4467,56 +4552,68 @@ static qse_awk_nde_t* parse_print (qse_awk_t* awk, qse_size_t line, int type)
if (awk->token.prev.type != TOKEN_RPAREN && if (awk->token.prev.type != TOKEN_RPAREN &&
args_tail->type == QSE_AWK_NDE_EXP_BIN) args_tail->type == QSE_AWK_NDE_EXP_BIN)
{ {
int i;
qse_awk_nde_exp_t* ep = (qse_awk_nde_exp_t*)args_tail; qse_awk_nde_exp_t* ep = (qse_awk_nde_exp_t*)args_tail;
if (ep->opcode == QSE_AWK_BINOP_GT) struct
{ {
qse_awk_nde_t* tmp = args_tail; int opc;
int out;
if (tail_prev != QSE_NULL) int opt;
tail_prev->next = ep->left; } tab[] =
else args = ep->left;
out = ep->right;
out_type = QSE_AWK_OUT_FILE;
QSE_AWK_FREE (awk, tmp);
}
else if (ep->opcode == QSE_AWK_BINOP_RSHIFT)
{ {
qse_awk_nde_t* tmp = args_tail; {
QSE_AWK_BINOP_GT,
QSE_AWK_OUT_FILE,
0
},
{
QSE_AWK_BINOP_RSHIFT,
QSE_AWK_OUT_APFILE,
0
},
{
QSE_AWK_BINOP_BOR,
QSE_AWK_OUT_PIPE,
0
},
{
QSE_AWK_BINOP_LOR,
QSE_AWK_OUT_RWPIPE,
QSE_AWK_RWPIPE
}
};
if (tail_prev != QSE_NULL) for (i = 0; i < QSE_COUNTOF(tab); i++)
tail_prev->next = ep->left;
else args = ep->left;
out = ep->right;
out_type = QSE_AWK_OUT_FILE_APPEND;
QSE_AWK_FREE (awk, tmp);
}
else if (ep->opcode == QSE_AWK_BINOP_BOR)
{ {
qse_awk_nde_t* tmp = args_tail; if (ep->opcode == tab[i].opc)
{
if (tab[i].opt &&
!(awk->option&tab[i].opt)) break;
if (tail_prev != QSE_NULL) qse_awk_nde_t* tmp = args_tail;
tail_prev->next = ep->left;
else args = ep->left;
out = ep->right; if (tail_prev != QSE_NULL)
out_type = QSE_AWK_OUT_PIPE; tail_prev->next = ep->left;
else args = ep->left;
QSE_AWK_FREE (awk, tmp); out = ep->right;
out_type = tab[i].out;
QSE_AWK_FREE (awk, tmp);
break;
}
} }
} }
} }
if (out == QSE_NULL) if (out == QSE_NULL)
{ {
out_type = MATCH(awk,TOKEN_GT)? QSE_AWK_OUT_FILE: out_type = MATCH(awk,TOKEN_GT)? QSE_AWK_OUT_FILE:
MATCH(awk,TOKEN_RSHIFT)? QSE_AWK_OUT_FILE_APPEND: MATCH(awk,TOKEN_RSHIFT)? QSE_AWK_OUT_APFILE:
MATCH(awk,TOKEN_BOR)? QSE_AWK_OUT_PIPE: MATCH(awk,TOKEN_BOR)? QSE_AWK_OUT_PIPE:
MATCH(awk,TOKEN_BORAND)? QSE_AWK_OUT_COPROC: ((awk->option & QSE_AWK_RWPIPE) &&
QSE_AWK_OUT_CONSOLE; MATCH(awk,TOKEN_LOR))? QSE_AWK_OUT_RWPIPE:
QSE_AWK_OUT_CONSOLE;
if (out_type != QSE_AWK_OUT_CONSOLE) if (out_type != QSE_AWK_OUT_CONSOLE)
{ {
@ -4765,12 +4862,6 @@ static int get_token (qse_awk_t* awk)
ADD_TOKEN_CHAR (awk, c); ADD_TOKEN_CHAR (awk, c);
GET_CHAR (awk); GET_CHAR (awk);
} }
else if ((awk->option & QSE_AWK_COPROC) && c == QSE_T('&'))
{
SET_TOKEN_TYPE (awk, TOKEN_BORAND);
ADD_TOKEN_CHAR (awk, c);
GET_CHAR (awk);
}
else if (c == QSE_T('=')) else if (c == QSE_T('='))
{ {
SET_TOKEN_TYPE (awk, TOKEN_BOR_ASSIGN); SET_TOKEN_TYPE (awk, TOKEN_BOR_ASSIGN);

View File

@ -863,7 +863,6 @@ static int init_run (
if (runios != QSE_NULL) if (runios != QSE_NULL)
{ {
run->extio.handler[QSE_AWK_EXTIO_PIPE] = runios->pipe; run->extio.handler[QSE_AWK_EXTIO_PIPE] = runios->pipe;
run->extio.handler[QSE_AWK_EXTIO_COPROC] = runios->coproc;
run->extio.handler[QSE_AWK_EXTIO_FILE] = runios->file; run->extio.handler[QSE_AWK_EXTIO_FILE] = runios->file;
run->extio.handler[QSE_AWK_EXTIO_CONSOLE] = runios->console; run->extio.handler[QSE_AWK_EXTIO_CONSOLE] = runios->console;
run->extio.data = runios->data; run->extio.data = runios->data;
@ -2780,9 +2779,9 @@ static int run_print (qse_awk_run_t* run, qse_awk_nde_print_t* nde)
QSE_ASSERT ( QSE_ASSERT (
(nde->out_type == QSE_AWK_OUT_PIPE && nde->out != QSE_NULL) || (nde->out_type == QSE_AWK_OUT_PIPE && nde->out != QSE_NULL) ||
(nde->out_type == QSE_AWK_OUT_COPROC && nde->out != QSE_NULL) || (nde->out_type == QSE_AWK_OUT_RWPIPE && nde->out != QSE_NULL) ||
(nde->out_type == QSE_AWK_OUT_FILE && nde->out != QSE_NULL) || (nde->out_type == QSE_AWK_OUT_FILE && nde->out != QSE_NULL) ||
(nde->out_type == QSE_AWK_OUT_FILE_APPEND && nde->out != QSE_NULL) || (nde->out_type == QSE_AWK_OUT_APFILE && nde->out != QSE_NULL) ||
(nde->out_type == QSE_AWK_OUT_CONSOLE && nde->out == QSE_NULL)); (nde->out_type == QSE_AWK_OUT_CONSOLE && nde->out == QSE_NULL));
/* check if destination has been specified. */ /* check if destination has been specified. */
@ -2941,9 +2940,9 @@ static int run_printf (qse_awk_run_t* run, qse_awk_nde_print_t* nde)
QSE_ASSERT ( QSE_ASSERT (
(nde->out_type == QSE_AWK_OUT_PIPE && nde->out != QSE_NULL) || (nde->out_type == QSE_AWK_OUT_PIPE && nde->out != QSE_NULL) ||
(nde->out_type == QSE_AWK_OUT_COPROC && nde->out != QSE_NULL) || (nde->out_type == QSE_AWK_OUT_RWPIPE && nde->out != QSE_NULL) ||
(nde->out_type == QSE_AWK_OUT_FILE && nde->out != QSE_NULL) || (nde->out_type == QSE_AWK_OUT_FILE && nde->out != QSE_NULL) ||
(nde->out_type == QSE_AWK_OUT_FILE_APPEND && nde->out != QSE_NULL) || (nde->out_type == QSE_AWK_OUT_APFILE && nde->out != QSE_NULL) ||
(nde->out_type == QSE_AWK_OUT_CONSOLE && nde->out == QSE_NULL)); (nde->out_type == QSE_AWK_OUT_CONSOLE && nde->out == QSE_NULL));
if (nde->out != QSE_NULL) if (nde->out != QSE_NULL)
@ -6186,7 +6185,7 @@ static qse_awk_val_t* eval_getline (qse_awk_run_t* run, qse_awk_nde_t* nde)
QSE_ASSERT ( QSE_ASSERT (
(p->in_type == QSE_AWK_IN_PIPE && p->in != QSE_NULL) || (p->in_type == QSE_AWK_IN_PIPE && p->in != QSE_NULL) ||
(p->in_type == QSE_AWK_IN_COPROC && p->in != QSE_NULL) || (p->in_type == QSE_AWK_IN_RWPIPE && p->in != QSE_NULL) ||
(p->in_type == QSE_AWK_IN_FILE && p->in != QSE_NULL) || (p->in_type == QSE_AWK_IN_FILE && p->in != QSE_NULL) ||
(p->in_type == QSE_AWK_IN_CONSOLE && p->in == QSE_NULL)); (p->in_type == QSE_AWK_IN_CONSOLE && p->in == QSE_NULL));

View File

@ -351,14 +351,20 @@ static qse_ssize_t awk_extio_pipe (
if (epa->mode == QSE_AWK_EXTIO_PIPE_READ) if (epa->mode == QSE_AWK_EXTIO_PIPE_READ)
{ {
/* TODO: should specify ERRTOOUT */ /* TODO: should we specify ERRTOOUT? */
flags = QSE_PCP_READOUT | flags = QSE_PCP_READOUT |
QSE_PCP_ERRTOOUT; QSE_PCP_ERRTOOUT;
} }
else if (epa->mode == QSE_AWK_EXTIO_PIPE_WRITE) else if (epa->mode == QSE_AWK_EXTIO_PIPE_WRITE)
{ {
flags = QSE_PCP_WRITEIN; flags = QSE_PCP_WRITEIN;
} }
else if (epa->mode == QSE_AWK_EXTIO_PIPE_RW)
{
flags = QSE_PCP_READOUT |
QSE_PCP_ERRTOOUT |
QSE_PCP_WRITEIN;
}
else return -1; /* TODO: any way to set the error number? */ else return -1; /* TODO: any way to set the error number? */
/*dprint (QSE_T("opening %s of type %d (pipe)\n"), epa->name, epa->type);*/ /*dprint (QSE_T("opening %s of type %d (pipe)\n"), epa->name, epa->type);*/

View File

@ -87,7 +87,7 @@ static const qse_char_t* incop_str[] =
static const qse_char_t* getline_inop_str[] = static const qse_char_t* getline_inop_str[] =
{ {
QSE_T("|"), QSE_T("|"),
QSE_T("|&"), QSE_T("||"),
QSE_T("<"), QSE_T("<"),
QSE_T("") QSE_T("")
}; };
@ -95,7 +95,7 @@ static const qse_char_t* getline_inop_str[] =
static const qse_char_t* print_outop_str[] = static const qse_char_t* print_outop_str[] =
{ {
QSE_T("|"), QSE_T("|"),
QSE_T("|&"), QSE_T("||"),
QSE_T(">"), QSE_T(">"),
QSE_T(">>"), QSE_T(">>"),
QSE_T("") QSE_T("")
@ -562,7 +562,7 @@ static int print_expression (qse_awk_t* awk, qse_awk_nde_t* nde)
qse_awk_nde_getline_t* px = (qse_awk_nde_getline_t*)nde; qse_awk_nde_getline_t* px = (qse_awk_nde_getline_t*)nde;
if (px->in != QSE_NULL && if (px->in != QSE_NULL &&
(px->in_type == QSE_AWK_IN_PIPE || (px->in_type == QSE_AWK_IN_PIPE ||
px->in_type == QSE_AWK_IN_COPROC)) px->in_type == QSE_AWK_IN_RWPIPE))
{ {
PRINT_EXPRESSION (awk, px->in); PRINT_EXPRESSION (awk, px->in);
PUT_SRCSTR (awk, QSE_T(" ")); PUT_SRCSTR (awk, QSE_T(" "));

View File

@ -82,7 +82,7 @@ enum qse_awk_in_type_t
* __in_type_map and __in_opt_map in extio.c */ * __in_type_map and __in_opt_map in extio.c */
QSE_AWK_IN_PIPE, QSE_AWK_IN_PIPE,
QSE_AWK_IN_COPROC, QSE_AWK_IN_RWPIPE,
QSE_AWK_IN_FILE, QSE_AWK_IN_FILE,
QSE_AWK_IN_CONSOLE QSE_AWK_IN_CONSOLE
}; };
@ -93,9 +93,9 @@ enum qse_awk_out_type_t
* __out_type_map and __out_opt_map in extio.c */ * __out_type_map and __out_opt_map in extio.c */
QSE_AWK_OUT_PIPE, QSE_AWK_OUT_PIPE,
QSE_AWK_OUT_COPROC, QSE_AWK_OUT_RWPIPE, /* dual direction pipe */
QSE_AWK_OUT_FILE, QSE_AWK_OUT_FILE,
QSE_AWK_OUT_FILE_APPEND, QSE_AWK_OUT_APFILE, /* file for appending */
QSE_AWK_OUT_CONSOLE QSE_AWK_OUT_CONSOLE
}; };