enhanded StdAwk::Pipe to support CloseMode
This commit is contained in:
parent
81b3d369e8
commit
2ba054c1a3
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: Awk.hpp 267 2009-08-25 09:50:07Z hyunghwan.chung $
|
||||
* $Id: Awk.hpp 272 2009-08-28 09:48:02Z hyunghwan.chung $
|
||||
*
|
||||
Copyright 2006-2009 Chung, Hyung-Hwan.
|
||||
|
||||
@ -403,11 +403,23 @@ public:
|
||||
RW = QSE_AWK_RIO_PIPE_RW
|
||||
};
|
||||
|
||||
enum CloseMode
|
||||
{
|
||||
CLOSE_FULL = QSE_AWK_RIO_CLOSE_FULL,
|
||||
CLOSE_READ = QSE_AWK_RIO_CLOSE_READ,
|
||||
CLOSE_WRITE = QSE_AWK_RIO_CLOSE_WRITE
|
||||
};
|
||||
|
||||
protected:
|
||||
Pipe (Run* run, rio_arg_t* riod);
|
||||
|
||||
public:
|
||||
/// The function returns the requested opening mode.
|
||||
Mode getMode () const;
|
||||
|
||||
/// The getCloseMode() function returns the requested closing
|
||||
/// mode. The returned value is valid if getMode() returns RW.
|
||||
CloseMode getCloseMode () const;
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: awk.h 271 2009-08-27 12:52:20Z hyunghwan.chung $
|
||||
* $Id: awk.h 272 2009-08-28 09:48:02Z hyunghwan.chung $
|
||||
*
|
||||
Copyright 2006-2009 Chung, Hyung-Hwan.
|
||||
|
||||
@ -351,13 +351,13 @@ enum qse_awk_rio_mode_t
|
||||
};
|
||||
typedef enum qse_awk_rio_mode_t qse_awk_rio_mode_t;
|
||||
|
||||
enum qse_awk_rio_rwcopt_t
|
||||
enum qse_awk_rio_rwcmode_t
|
||||
{
|
||||
QSE_AWK_RIO_CLOSE_A = 0,
|
||||
QSE_AWK_RIO_CLOSE_R = 1,
|
||||
QSE_AWK_RIO_CLOSE_W = 2
|
||||
QSE_AWK_RIO_CLOSE_FULL = 0,
|
||||
QSE_AWK_RIO_CLOSE_READ = 1,
|
||||
QSE_AWK_RIO_CLOSE_WRITE = 2
|
||||
};
|
||||
typedef enum qse_awk_rio_rwcopt_t qse_awk_rio_rwcopt_t;
|
||||
typedef enum qse_awk_rio_rwcmode_t qse_awk_rio_rwcmode_t;
|
||||
|
||||
/**
|
||||
* The qse_awk_rio_arg_t defines the data structure passed to a runtime
|
||||
@ -369,9 +369,9 @@ typedef enum qse_awk_rio_rwcopt_t qse_awk_rio_rwcopt_t;
|
||||
typedef struct qse_awk_rio_arg_t qse_awk_rio_arg_t;
|
||||
struct qse_awk_rio_arg_t
|
||||
{
|
||||
qse_awk_rio_mode_t mode; /**< [IN] I/O mode */
|
||||
qse_awk_rio_mode_t mode; /**< [IN] opening mode */
|
||||
qse_char_t* name; /**< [IN] name of I/O object */
|
||||
qse_awk_rio_rwcopt_t rwcopt; /**< [IN] closing option for rwpipe */
|
||||
qse_awk_rio_rwcmode_t rwcmode; /**< [IN] closing mode for rwpipe */
|
||||
void* handle; /**< [OUT] I/O handle set by a handler */
|
||||
|
||||
/*-- from here down, internal use only --*/
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: Awk.cpp 267 2009-08-25 09:50:07Z hyunghwan.chung $
|
||||
* $Id: Awk.cpp 272 2009-08-28 09:48:02Z hyunghwan.chung $
|
||||
*
|
||||
Copyright 2006-2009 Chung, Hyung-Hwan.
|
||||
|
||||
@ -106,6 +106,11 @@ Awk::Pipe::Mode Awk::Pipe::getMode () const
|
||||
return (Mode)riod->mode;
|
||||
}
|
||||
|
||||
Awk::Pipe::CloseMode Awk::Pipe::getCloseMode () const
|
||||
{
|
||||
return (CloseMode)riod->rwcmode;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////
|
||||
// Awk::File
|
||||
//////////////////////////////////////////////////////////////////
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: StdAwk.cpp 271 2009-08-27 12:52:20Z hyunghwan.chung $
|
||||
* $Id: StdAwk.cpp 272 2009-08-28 09:48:02Z hyunghwan.chung $
|
||||
*
|
||||
Copyright 2006-2009 Chung, Hyung-Hwan.
|
||||
|
||||
@ -318,20 +318,17 @@ int StdAwk::closePipe (Pipe& io)
|
||||
qse_pio_t* pio = (qse_pio_t*)io.getHandle();
|
||||
if (io.getMode() == Awk::Pipe::RW)
|
||||
{
|
||||
#if 0
|
||||
TODO: support partial close....
|
||||
rwcopt = io.getCloseRW();
|
||||
if (rwcopt == Awk::Pipe::CLOSE_R)
|
||||
Pipe::CloseMode rwcopt = io.getCloseMode();
|
||||
if (rwcopt == Awk::Pipe::CLOSE_READ)
|
||||
{
|
||||
qse_pio_end (pio, QSE_PIO_IN);
|
||||
return 0;
|
||||
}
|
||||
else if (rwcopt == Awk::Pipe::CLOSE_W)
|
||||
else if (rwcopt == Awk::Pipe::CLOSE_WRITE)
|
||||
{
|
||||
qse_pio_end (pio, QSE_PIO_OUT);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
qse_pio_close (pio);
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: rio.c 271 2009-08-27 12:52:20Z hyunghwan.chung $
|
||||
* $Id: rio.c 272 2009-08-28 09:48:02Z hyunghwan.chung $
|
||||
*
|
||||
Copyright 2006-2009 Chung, Hyung-Hwan.
|
||||
|
||||
@ -148,7 +148,7 @@ int qse_awk_rtx_readio (
|
||||
|
||||
p->type = (io_type | io_mask);
|
||||
p->mode = io_mode;
|
||||
p->rwcopt = QSE_AWK_RIO_CLOSE_A;
|
||||
p->rwcmode = QSE_AWK_RIO_CLOSE_FULL;
|
||||
p->handle = QSE_NULL;
|
||||
p->next = QSE_NULL;
|
||||
p->rwcstate = 0;
|
||||
@ -509,7 +509,7 @@ int qse_awk_rtx_writeio_str (
|
||||
|
||||
p->type = (io_type | io_mask);
|
||||
p->mode = io_mode;
|
||||
p->rwcopt = QSE_AWK_RIO_CLOSE_A;
|
||||
p->rwcmode = QSE_AWK_RIO_CLOSE_FULL;
|
||||
p->handle = QSE_NULL;
|
||||
p->next = QSE_NULL;
|
||||
p->rwcstate = 0;
|
||||
@ -920,7 +920,7 @@ int qse_awk_rtx_closeio (
|
||||
if (qse_strcmp (p->name, name) == 0)
|
||||
{
|
||||
qse_awk_rio_fun_t handler;
|
||||
qse_awk_rio_rwcopt_t rwcopt = QSE_AWK_RIO_CLOSE_A;
|
||||
qse_awk_rio_rwcmode_t rwcmode = QSE_AWK_RIO_CLOSE_FULL;
|
||||
|
||||
if (opt != QSE_NULL)
|
||||
{
|
||||
@ -928,12 +928,12 @@ int qse_awk_rtx_closeio (
|
||||
{
|
||||
if (p->type & MASK_RDWR)
|
||||
{
|
||||
if (p->rwcstate != QSE_AWK_RIO_CLOSE_W)
|
||||
if (p->rwcstate != QSE_AWK_RIO_CLOSE_WRITE)
|
||||
{
|
||||
/* if the write end is not
|
||||
* closed, let io handler close
|
||||
* the read end only. */
|
||||
rwcopt = QSE_AWK_RIO_CLOSE_R;
|
||||
rwcmode = QSE_AWK_RIO_CLOSE_READ;
|
||||
}
|
||||
}
|
||||
else if (!(p->type & MASK_READ)) goto skip;
|
||||
@ -943,12 +943,12 @@ int qse_awk_rtx_closeio (
|
||||
QSE_ASSERT (opt[0] == QSE_T('w'));
|
||||
if (p->type & MASK_RDWR)
|
||||
{
|
||||
if (p->rwcstate != QSE_AWK_RIO_CLOSE_R)
|
||||
if (p->rwcstate != QSE_AWK_RIO_CLOSE_READ)
|
||||
{
|
||||
/* if the read end is not
|
||||
* closed, let io handler close
|
||||
* the write end only. */
|
||||
rwcopt = QSE_AWK_RIO_CLOSE_W;
|
||||
rwcmode = QSE_AWK_RIO_CLOSE_WRITE;
|
||||
}
|
||||
}
|
||||
else if (!(p->type & MASK_WRITE)) goto skip;
|
||||
@ -959,7 +959,7 @@ int qse_awk_rtx_closeio (
|
||||
if (handler != QSE_NULL)
|
||||
{
|
||||
qse_awk_rtx_seterrnum (rtx, QSE_AWK_ENOERR, QSE_NULL);
|
||||
p->rwcopt = rwcopt;
|
||||
p->rwcmode = rwcmode;
|
||||
if (handler (rtx, QSE_AWK_RIO_CLOSE, p, QSE_NULL, 0) <= -1)
|
||||
{
|
||||
/* this is not a run-time error.*/
|
||||
@ -971,14 +971,14 @@ int qse_awk_rtx_closeio (
|
||||
|
||||
if (p->type & MASK_RDWR)
|
||||
{
|
||||
p->rwcopt = rwcopt;
|
||||
if (p->rwcstate == 0 && rwcopt != 0)
|
||||
p->rwcmode = rwcmode;
|
||||
if (p->rwcstate == 0 && rwcmode != 0)
|
||||
{
|
||||
/* if either end has not been closed.
|
||||
* return success without destroying
|
||||
* the internal node. rwcstate keeps
|
||||
* what has been successfully closed */
|
||||
p->rwcstate = rwcopt;
|
||||
p->rwcstate = rwcmode;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@ -1016,7 +1016,7 @@ void qse_awk_rtx_cleario (qse_awk_rtx_t* run)
|
||||
if (handler != QSE_NULL)
|
||||
{
|
||||
qse_awk_rtx_seterrnum (run, QSE_AWK_ENOERR, QSE_NULL);
|
||||
run->rio.chain->rwcopt = 0;
|
||||
run->rio.chain->rwcmode = 0;
|
||||
n = handler (run, QSE_AWK_RIO_CLOSE, run->rio.chain, QSE_NULL, 0);
|
||||
if (n <= -1)
|
||||
{
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: std.c 271 2009-08-27 12:52:20Z hyunghwan.chung $
|
||||
* $Id: std.c 272 2009-08-28 09:48:02Z hyunghwan.chung $
|
||||
*
|
||||
Copyright 2006-2009 Chung, Hyung-Hwan.
|
||||
|
||||
@ -623,14 +623,14 @@ static qse_ssize_t awk_rio_pipe (
|
||||
if (riod->mode == QSE_AWK_RIO_PIPE_RW)
|
||||
{
|
||||
/* specialy treatment is needef for rwpipe.
|
||||
* inspect rwcopt to see if partial closing is
|
||||
* inspect rwcmode to see if partial closing is
|
||||
* requested. */
|
||||
if (riod->rwcopt == QSE_AWK_RIO_CLOSE_R)
|
||||
if (riod->rwcmode == QSE_AWK_RIO_CLOSE_READ)
|
||||
{
|
||||
qse_pio_end (pio, QSE_PIO_IN);
|
||||
return 0;
|
||||
}
|
||||
else if (riod->rwcopt == QSE_AWK_RIO_CLOSE_W)
|
||||
if (riod->rwcmode == QSE_AWK_RIO_CLOSE_WRITE)
|
||||
{
|
||||
qse_pio_end (pio, QSE_PIO_OUT);
|
||||
return 0;
|
||||
|
@ -339,7 +339,8 @@ static int awk_main_2 (MyAwk& awk, int argc, qse_char_t* argv[])
|
||||
cmdline_t cmdline;
|
||||
int n;
|
||||
|
||||
awk.setOption (awk.getOption() | awk.OPT_INCLUDE | awk.OPT_MAPTOVAR);
|
||||
awk.setOption (awk.getOption() | awk.OPT_INCLUDE |
|
||||
awk.OPT_MAPTOVAR | awk.OPT_RWPIPE | awk.OPT_EXTRAOPS);
|
||||
|
||||
// ARGV[0]
|
||||
if (awk.addArgument (QSE_T("awk08")) <= -1)
|
||||
|
Loading…
Reference in New Issue
Block a user