2007-05-02 01:07:00 +00:00
|
|
|
/*
|
2011-04-28 08:04:13 +00:00
|
|
|
* $Id: rio.c 444 2011-04-27 14:04:13Z hyunghwan.chung $
|
2007-05-02 01:07:00 +00:00
|
|
|
*
|
2011-04-23 08:28:43 +00:00
|
|
|
Copyright 2006-2011 Chung, Hyung-Hwan.
|
2009-09-16 04:01:02 +00:00
|
|
|
This file is part of QSE.
|
2008-12-27 04:35:14 +00:00
|
|
|
|
2009-09-16 04:01:02 +00:00
|
|
|
QSE is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU Lesser General Public License as
|
|
|
|
published by the Free Software Foundation, either version 3 of
|
|
|
|
the License, or (at your option) any later version.
|
2008-12-27 04:35:14 +00:00
|
|
|
|
2009-09-16 04:01:02 +00:00
|
|
|
QSE is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU Lesser General Public License for more details.
|
2008-12-27 04:35:14 +00:00
|
|
|
|
2009-09-16 04:01:02 +00:00
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
|
|
License along with QSE. If not, see <http://www.gnu.org/licenses/>.
|
2007-05-02 01:07:00 +00:00
|
|
|
*/
|
|
|
|
|
2008-08-21 03:17:25 +00:00
|
|
|
#include "awk.h"
|
2007-05-02 01:07:00 +00:00
|
|
|
|
2011-04-28 08:04:13 +00:00
|
|
|
enum io_mask_t
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
|
|
|
MASK_READ = 0x0100,
|
|
|
|
MASK_WRITE = 0x0200,
|
|
|
|
MASK_RDWR = 0x0400,
|
|
|
|
|
|
|
|
MASK_CLEAR = 0x00FF
|
|
|
|
};
|
|
|
|
|
|
|
|
static int in_type_map[] =
|
|
|
|
{
|
|
|
|
/* the order should match the order of the
|
2008-12-21 21:35:07 +00:00
|
|
|
* QSE_AWK_IN_XXX values in tree.h */
|
2009-02-16 08:31:34 +00:00
|
|
|
QSE_AWK_RIO_PIPE,
|
|
|
|
QSE_AWK_RIO_PIPE,
|
|
|
|
QSE_AWK_RIO_FILE,
|
|
|
|
QSE_AWK_RIO_CONSOLE
|
2007-05-02 01:07:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static int in_mode_map[] =
|
|
|
|
{
|
|
|
|
/* the order should match the order of the
|
2008-12-21 21:35:07 +00:00
|
|
|
* QSE_AWK_IN_XXX values in tree.h */
|
2009-02-16 08:31:34 +00:00
|
|
|
QSE_AWK_RIO_PIPE_READ,
|
|
|
|
QSE_AWK_RIO_PIPE_RW,
|
|
|
|
QSE_AWK_RIO_FILE_READ,
|
|
|
|
QSE_AWK_RIO_CONSOLE_READ
|
2007-05-02 01:07:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static int in_mask_map[] =
|
|
|
|
{
|
|
|
|
MASK_READ,
|
|
|
|
MASK_RDWR,
|
|
|
|
MASK_READ,
|
|
|
|
MASK_READ
|
|
|
|
};
|
|
|
|
|
|
|
|
static int out_type_map[] =
|
|
|
|
{
|
|
|
|
/* the order should match the order of the
|
2008-12-21 21:35:07 +00:00
|
|
|
* QSE_AWK_OUT_XXX values in tree.h */
|
2009-02-16 08:31:34 +00:00
|
|
|
QSE_AWK_RIO_PIPE,
|
|
|
|
QSE_AWK_RIO_PIPE,
|
|
|
|
QSE_AWK_RIO_FILE,
|
|
|
|
QSE_AWK_RIO_FILE,
|
|
|
|
QSE_AWK_RIO_CONSOLE
|
2007-05-02 01:07:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static int out_mode_map[] =
|
|
|
|
{
|
|
|
|
/* the order should match the order of the
|
2008-12-21 21:35:07 +00:00
|
|
|
* QSE_AWK_OUT_XXX values in tree.h */
|
2009-02-16 08:31:34 +00:00
|
|
|
QSE_AWK_RIO_PIPE_WRITE,
|
|
|
|
QSE_AWK_RIO_PIPE_RW,
|
|
|
|
QSE_AWK_RIO_FILE_WRITE,
|
|
|
|
QSE_AWK_RIO_FILE_APPEND,
|
|
|
|
QSE_AWK_RIO_CONSOLE_WRITE
|
2007-05-02 01:07:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static int out_mask_map[] =
|
|
|
|
{
|
|
|
|
MASK_WRITE,
|
|
|
|
MASK_RDWR,
|
|
|
|
MASK_WRITE,
|
|
|
|
MASK_WRITE,
|
|
|
|
MASK_WRITE
|
|
|
|
};
|
|
|
|
|
2011-04-28 08:04:13 +00:00
|
|
|
static QSE_INLINE int match_long_rs (qse_awk_rtx_t* run, qse_str_t* buf, int eof)
|
|
|
|
{
|
|
|
|
qse_cstr_t match;
|
|
|
|
qse_awk_errnum_t errnum;
|
|
|
|
int n;
|
|
|
|
|
|
|
|
/* TODO: minimize the number of regular expression match by minimizing the call
|
|
|
|
* to match_long_rs() and changing its code.
|
|
|
|
* currently it is called for each character added to buf.
|
|
|
|
* this is a very bad way of doing the job.
|
|
|
|
*/
|
|
|
|
QSE_ASSERT (run->gbl.rs != QSE_NULL);
|
|
|
|
|
|
|
|
n = QSE_AWK_MATCHREX (
|
|
|
|
run->awk, run->gbl.rs,
|
|
|
|
((run->gbl.ignorecase)? QSE_REX_IGNORECASE: 0),
|
|
|
|
QSE_STR_PTR(buf), QSE_STR_LEN(buf),
|
|
|
|
QSE_STR_PTR(buf), QSE_STR_LEN(buf),
|
|
|
|
&match, &errnum);
|
|
|
|
if (n <= -1)
|
|
|
|
{
|
|
|
|
qse_awk_rtx_seterrnum (run, errnum, QSE_NULL);
|
|
|
|
}
|
|
|
|
else if (n >= 1)
|
|
|
|
{
|
|
|
|
if (eof)
|
|
|
|
{
|
|
|
|
/* when EOF is reached, the record buffer
|
|
|
|
* is not added with a new character. It's
|
|
|
|
* just called again with the same record buffer
|
|
|
|
* as the previous call to this function.
|
|
|
|
* A match in this case must end at the end of
|
|
|
|
* the current record buffer */
|
|
|
|
QSE_ASSERT (
|
|
|
|
QSE_STR_PTR(buf) + QSE_STR_LEN(buf) ==
|
|
|
|
match.ptr + match.len);
|
|
|
|
|
|
|
|
/* drop the RS part. no extra character after RS to drop
|
|
|
|
* because we're at EOF and the EOF condition didn't
|
|
|
|
* add a new character to the buffer before the call
|
|
|
|
* to this function.
|
|
|
|
*/
|
|
|
|
QSE_STR_LEN(buf) -= match.len;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* the last character read so far has been added
|
|
|
|
* to the record before the call to this function.
|
|
|
|
* if the match is found and it ends one character
|
|
|
|
* before this last character, it is the longest
|
|
|
|
* match.
|
|
|
|
*/
|
|
|
|
if (QSE_STR_PTR(buf) + QSE_STR_LEN(buf) == match.ptr + match.len + 1)
|
|
|
|
{
|
|
|
|
/* drop the RS part and the last one character after RS */
|
|
|
|
QSE_STR_LEN(buf) -= match.len + 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* if the match does not ends at the desired position,
|
|
|
|
* it is no match as it is not the longest match */
|
|
|
|
n = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
2009-02-16 08:31:34 +00:00
|
|
|
int qse_awk_rtx_readio (
|
2009-01-31 04:31:40 +00:00
|
|
|
qse_awk_rtx_t* run, int in_type,
|
2008-12-21 21:35:07 +00:00
|
|
|
const qse_char_t* name, qse_str_t* buf)
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
2009-06-17 00:05:40 +00:00
|
|
|
qse_awk_rio_arg_t* p = run->rio.chain;
|
|
|
|
qse_awk_rio_fun_t handler;
|
2009-02-16 08:31:34 +00:00
|
|
|
int io_type, io_mode, io_mask, ret, n;
|
2008-12-21 21:35:07 +00:00
|
|
|
qse_ssize_t x;
|
|
|
|
qse_awk_val_t* rs;
|
|
|
|
qse_char_t* rs_ptr;
|
|
|
|
qse_size_t rs_len;
|
|
|
|
qse_size_t line_len = 0;
|
|
|
|
qse_char_t c = QSE_T('\0'), pc;
|
2007-05-02 01:07:00 +00:00
|
|
|
|
2008-12-21 21:35:07 +00:00
|
|
|
QSE_ASSERT (in_type >= 0 && in_type <= QSE_COUNTOF(in_type_map));
|
|
|
|
QSE_ASSERT (in_type >= 0 && in_type <= QSE_COUNTOF(in_mode_map));
|
|
|
|
QSE_ASSERT (in_type >= 0 && in_type <= QSE_COUNTOF(in_mask_map));
|
2007-05-02 01:07:00 +00:00
|
|
|
|
2009-02-16 08:31:34 +00:00
|
|
|
/* translate the in_type into the relevant io type and mode */
|
|
|
|
io_type = in_type_map[in_type];
|
|
|
|
io_mode = in_mode_map[in_type];
|
|
|
|
io_mask = in_mask_map[in_type];
|
2007-05-02 01:07:00 +00:00
|
|
|
|
2009-01-17 04:20:22 +00:00
|
|
|
/* get the io handler provided by a user */
|
2009-02-16 08:31:34 +00:00
|
|
|
handler = run->rio.handler[io_type];
|
2008-12-21 21:35:07 +00:00
|
|
|
if (handler == QSE_NULL)
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
|
|
|
/* no io handler provided */
|
2009-08-17 07:44:20 +00:00
|
|
|
qse_awk_rtx_seterrnum (run, QSE_AWK_EIOUSER, QSE_NULL);
|
2007-05-02 01:07:00 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2009-01-17 04:20:22 +00:00
|
|
|
/* search the chain for exiting an existing io name */
|
2008-12-21 21:35:07 +00:00
|
|
|
while (p != QSE_NULL)
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
2009-02-16 08:31:34 +00:00
|
|
|
if (p->type == (io_type | io_mask) &&
|
2008-12-21 21:35:07 +00:00
|
|
|
qse_strcmp (p->name,name) == 0) break;
|
2007-05-02 01:07:00 +00:00
|
|
|
p = p->next;
|
|
|
|
}
|
|
|
|
|
2008-12-21 21:35:07 +00:00
|
|
|
if (p == QSE_NULL)
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
2009-01-17 04:20:22 +00:00
|
|
|
/* if the name doesn't exist in the chain, create an entry
|
|
|
|
* to the chain */
|
2009-06-17 00:05:40 +00:00
|
|
|
p = (qse_awk_rio_arg_t*) QSE_AWK_ALLOC (
|
|
|
|
run->awk, QSE_SIZEOF(qse_awk_rio_arg_t));
|
2008-12-21 21:35:07 +00:00
|
|
|
if (p == QSE_NULL)
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
2009-08-17 07:44:20 +00:00
|
|
|
qse_awk_rtx_seterrnum (run, QSE_AWK_ENOMEM, QSE_NULL);
|
2007-05-02 01:07:00 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2008-12-21 21:35:07 +00:00
|
|
|
p->name = QSE_AWK_STRDUP (run->awk, name);
|
|
|
|
if (p->name == QSE_NULL)
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
2008-12-21 21:35:07 +00:00
|
|
|
QSE_AWK_FREE (run->awk, p);
|
2009-08-17 07:44:20 +00:00
|
|
|
qse_awk_rtx_seterrnum (run, QSE_AWK_ENOMEM, QSE_NULL);
|
2007-05-02 01:07:00 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2009-02-16 08:31:34 +00:00
|
|
|
p->type = (io_type | io_mask);
|
|
|
|
p->mode = io_mode;
|
2009-08-29 03:48:02 +00:00
|
|
|
p->rwcmode = QSE_AWK_RIO_CLOSE_FULL;
|
2008-12-21 21:35:07 +00:00
|
|
|
p->handle = QSE_NULL;
|
|
|
|
p->next = QSE_NULL;
|
2009-08-28 06:52:20 +00:00
|
|
|
p->rwcstate = 0;
|
2007-05-02 01:07:00 +00:00
|
|
|
|
2008-12-21 21:35:07 +00:00
|
|
|
p->in.buf[0] = QSE_T('\0');
|
2007-05-02 01:07:00 +00:00
|
|
|
p->in.pos = 0;
|
|
|
|
p->in.len = 0;
|
2009-08-28 06:52:20 +00:00
|
|
|
p->in.eof = 0;
|
|
|
|
p->in.eos = 0;
|
2007-05-02 01:07:00 +00:00
|
|
|
|
2009-08-17 07:44:20 +00:00
|
|
|
qse_awk_rtx_seterrnum (run, QSE_AWK_ENOERR, QSE_NULL);
|
2007-05-02 01:07:00 +00:00
|
|
|
|
2009-01-17 04:20:22 +00:00
|
|
|
/* request to open the stream */
|
2009-02-17 02:11:31 +00:00
|
|
|
x = handler (run, QSE_AWK_RIO_OPEN, p, QSE_NULL, 0);
|
2007-11-11 00:30:00 +00:00
|
|
|
if (x <= -1)
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
2008-12-21 21:35:07 +00:00
|
|
|
QSE_AWK_FREE (run->awk, p->name);
|
|
|
|
QSE_AWK_FREE (run->awk, p);
|
2007-05-02 01:07:00 +00:00
|
|
|
|
2009-06-15 02:40:52 +00:00
|
|
|
if (run->errinf.num == QSE_AWK_ENOERR)
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
|
|
|
/* if the error number has not been
|
|
|
|
* set by the user handler */
|
2009-08-17 07:44:20 +00:00
|
|
|
qse_awk_rtx_seterrnum (run, QSE_AWK_EIOIMPL, QSE_NULL);
|
2007-05-02 01:07:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* chain it */
|
2009-02-16 08:31:34 +00:00
|
|
|
p->next = run->rio.chain;
|
|
|
|
run->rio.chain = p;
|
2007-05-02 01:07:00 +00:00
|
|
|
|
2007-11-11 00:30:00 +00:00
|
|
|
/* usually, x == 0 indicates that it has reached the end
|
2007-05-02 01:07:00 +00:00
|
|
|
* of the input. the user io handler can return 0 for the
|
|
|
|
* open request if it doesn't have any files to open. One
|
|
|
|
* advantage of doing this would be that you can skip the
|
|
|
|
* entire pattern-block matching and exeuction. */
|
2007-11-11 00:30:00 +00:00
|
|
|
if (x == 0)
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
2009-08-28 06:52:20 +00:00
|
|
|
p->in.eos = 1;
|
2007-05-02 01:07:00 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-08-28 06:52:20 +00:00
|
|
|
if (p->in.eos)
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
|
|
|
/* no more streams. */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-01-17 04:20:22 +00:00
|
|
|
/* ready to read a line. clear the line buffer */
|
2008-12-21 21:35:07 +00:00
|
|
|
qse_str_clear (buf);
|
2007-05-02 01:07:00 +00:00
|
|
|
|
|
|
|
/* get the record separator */
|
2009-02-02 08:28:04 +00:00
|
|
|
rs = qse_awk_rtx_getgbl (run, QSE_AWK_GBL_RS);
|
2009-02-01 03:59:46 +00:00
|
|
|
qse_awk_rtx_refupval (run, rs);
|
2007-05-02 01:07:00 +00:00
|
|
|
|
2011-04-28 08:04:13 +00:00
|
|
|
switch (rs->type)
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
2011-04-28 08:04:13 +00:00
|
|
|
case QSE_AWK_VAL_NIL:
|
|
|
|
rs_ptr = QSE_NULL;
|
|
|
|
rs_len = 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case QSE_AWK_VAL_STR:
|
|
|
|
rs_ptr = ((qse_awk_val_str_t*)rs)->ptr;
|
|
|
|
rs_len = ((qse_awk_val_str_t*)rs)->len;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
rs_ptr = qse_awk_rtx_valtocpldup (run, rs, &rs_len);
|
|
|
|
if (rs_ptr == QSE_NULL)
|
|
|
|
{
|
|
|
|
qse_awk_rtx_refdownval (run, rs);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
break;
|
2007-05-02 01:07:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ret = 1;
|
|
|
|
|
|
|
|
/* call the io handler */
|
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
if (p->in.pos >= p->in.len)
|
|
|
|
{
|
2008-12-21 21:35:07 +00:00
|
|
|
qse_ssize_t n;
|
2007-05-02 01:07:00 +00:00
|
|
|
|
|
|
|
if (p->in.eof)
|
|
|
|
{
|
2008-12-21 21:35:07 +00:00
|
|
|
if (QSE_STR_LEN(buf) == 0) ret = 0;
|
2007-05-02 01:07:00 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2009-08-17 07:44:20 +00:00
|
|
|
qse_awk_rtx_seterrnum (run, QSE_AWK_ENOERR, QSE_NULL);
|
2007-05-02 01:07:00 +00:00
|
|
|
|
2009-02-17 02:11:31 +00:00
|
|
|
n = handler (run, QSE_AWK_RIO_READ,
|
2008-12-21 21:35:07 +00:00
|
|
|
p, p->in.buf, QSE_COUNTOF(p->in.buf));
|
2007-05-02 01:07:00 +00:00
|
|
|
if (n <= -1)
|
|
|
|
{
|
2009-06-15 02:40:52 +00:00
|
|
|
if (run->errinf.num == QSE_AWK_ENOERR)
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
|
|
|
/* if the error number has not been
|
|
|
|
* set by the user handler */
|
2009-08-17 07:44:20 +00:00
|
|
|
qse_awk_rtx_seterrnum (run, QSE_AWK_EIOIMPL, QSE_NULL);
|
2007-05-02 01:07:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ret = -1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (n == 0)
|
|
|
|
{
|
2011-04-28 08:04:13 +00:00
|
|
|
/* EOF reached */
|
2009-08-28 06:52:20 +00:00
|
|
|
p->in.eof = 1;
|
2007-05-20 01:45:00 +00:00
|
|
|
|
2008-12-21 21:35:07 +00:00
|
|
|
if (QSE_STR_LEN(buf) == 0) ret = 0;
|
2007-05-20 01:45:00 +00:00
|
|
|
else if (rs_len >= 2)
|
|
|
|
{
|
2011-04-28 08:04:13 +00:00
|
|
|
/* When RS is multiple characters, it should
|
|
|
|
* check for the match at the end of the
|
|
|
|
* input stream also because the previous
|
|
|
|
* match could fail as it didn't end at the
|
|
|
|
* desired position to be the longest match.
|
|
|
|
* At EOF, the match at the end is considered
|
|
|
|
* the longest as there are no more characters
|
|
|
|
* left */
|
|
|
|
n = match_long_rs (run, buf, 1);
|
|
|
|
if (n != 0)
|
2007-05-20 01:45:00 +00:00
|
|
|
{
|
2011-04-28 08:04:13 +00:00
|
|
|
if (n <= -1) ret = -1;
|
2007-05-20 01:45:00 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-05-02 01:07:00 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
p->in.len = n;
|
|
|
|
p->in.pos = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
pc = c;
|
|
|
|
c = p->in.buf[p->in.pos++];
|
|
|
|
|
2008-12-21 21:35:07 +00:00
|
|
|
if (rs_ptr == QSE_NULL)
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
|
|
|
/* separate by a new line */
|
2008-12-21 21:35:07 +00:00
|
|
|
if (c == QSE_T('\n'))
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
2008-12-21 21:35:07 +00:00
|
|
|
if (pc == QSE_T('\r') &&
|
|
|
|
QSE_STR_LEN(buf) > 0)
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
2011-04-28 08:04:13 +00:00
|
|
|
QSE_STR_LEN(buf) -= 1;
|
2007-05-02 01:07:00 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (rs_len == 0)
|
|
|
|
{
|
|
|
|
/* separate by a blank line */
|
2008-12-21 21:35:07 +00:00
|
|
|
if (c == QSE_T('\n'))
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
2008-12-21 21:35:07 +00:00
|
|
|
if (pc == QSE_T('\r') &&
|
|
|
|
QSE_STR_LEN(buf) > 0)
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
2011-04-28 08:04:13 +00:00
|
|
|
QSE_STR_LEN(buf) -= 1;
|
2007-05-02 01:07:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-21 21:35:07 +00:00
|
|
|
if (line_len == 0 && c == QSE_T('\n'))
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
2008-12-21 21:35:07 +00:00
|
|
|
if (QSE_STR_LEN(buf) <= 0)
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
|
|
|
/* if the record is empty when a blank
|
|
|
|
* line is encountered, the line
|
|
|
|
* terminator should not be added to
|
|
|
|
* the record */
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* when a blank line is encountered,
|
|
|
|
* it needs to snip off the line
|
|
|
|
* terminator of the previous line */
|
2010-09-08 06:29:25 +00:00
|
|
|
/*QSE_STR_LEN(buf) -= 1;*/
|
|
|
|
buf->len -= 1;
|
2007-05-02 01:07:00 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (rs_len == 1)
|
|
|
|
{
|
|
|
|
if (c == rs_ptr[0]) break;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-04-28 08:04:13 +00:00
|
|
|
/* I don't do anything here if RS is composed of
|
|
|
|
* multiple characters. See the comment furthur down */
|
2007-05-02 01:07:00 +00:00
|
|
|
}
|
|
|
|
|
2011-04-28 08:04:13 +00:00
|
|
|
|
2008-12-21 21:35:07 +00:00
|
|
|
if (qse_str_ccat (buf, c) == (qse_size_t)-1)
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
2009-08-17 07:44:20 +00:00
|
|
|
qse_awk_rtx_seterrnum (run, QSE_AWK_ENOMEM, QSE_NULL);
|
2007-05-02 01:07:00 +00:00
|
|
|
ret = -1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-04-28 08:04:13 +00:00
|
|
|
if (rs_len >= 2)
|
|
|
|
{
|
|
|
|
/* if RS is composed of multiple characters,
|
|
|
|
* I perform the matching after having added the
|
|
|
|
* current character 'c' to the record buffer 'buf'
|
|
|
|
* to find the longest match. If a match found ends
|
|
|
|
* one character before this character just added
|
|
|
|
* to the buffer, it is the longest match.
|
|
|
|
*/
|
|
|
|
/* TODO: change the way to find the longest match
|
|
|
|
* for performance improvement. currently,
|
|
|
|
* the function is called for every character
|
|
|
|
* added to the buffer. Stupid! */
|
|
|
|
n = match_long_rs (run, buf, 0);
|
|
|
|
if (n != 0)
|
|
|
|
{
|
|
|
|
p->in.pos--; /* unread the character in c */
|
|
|
|
if (n <= -1) ret = -1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* TODO: handle different line terminator like \r\n */
|
2008-12-21 21:35:07 +00:00
|
|
|
if (c == QSE_T('\n')) line_len = 0;
|
2007-05-02 01:07:00 +00:00
|
|
|
else line_len = line_len + 1;
|
|
|
|
}
|
|
|
|
|
2008-12-21 21:35:07 +00:00
|
|
|
if (rs_ptr != QSE_NULL &&
|
|
|
|
rs->type != QSE_AWK_VAL_STR) QSE_AWK_FREE (run->awk, rs_ptr);
|
2009-02-01 03:59:46 +00:00
|
|
|
qse_awk_rtx_refdownval (run, rs);
|
2007-05-02 01:07:00 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2009-02-16 08:31:34 +00:00
|
|
|
int qse_awk_rtx_writeio_val (
|
2009-01-31 04:31:40 +00:00
|
|
|
qse_awk_rtx_t* run, int out_type,
|
2008-12-21 21:35:07 +00:00
|
|
|
const qse_char_t* name, qse_awk_val_t* v)
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
2008-12-21 21:35:07 +00:00
|
|
|
qse_char_t* str;
|
|
|
|
qse_size_t len;
|
2007-05-02 01:07:00 +00:00
|
|
|
int n;
|
|
|
|
|
2008-12-21 21:35:07 +00:00
|
|
|
if (v->type == QSE_AWK_VAL_STR)
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
2008-12-30 04:49:25 +00:00
|
|
|
str = ((qse_awk_val_str_t*)v)->ptr;
|
2008-12-21 21:35:07 +00:00
|
|
|
len = ((qse_awk_val_str_t*)v)->len;
|
2007-05-02 01:07:00 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-03-01 09:27:03 +00:00
|
|
|
qse_awk_rtx_valtostr_out_t out;
|
|
|
|
|
|
|
|
out.type = QSE_AWK_RTX_VALTOSTR_CPLDUP |
|
|
|
|
QSE_AWK_RTX_VALTOSTR_PRINT;
|
|
|
|
if (qse_awk_rtx_valtostr (run, v, &out) == QSE_NULL) return -1;
|
|
|
|
|
|
|
|
str = out.u.cpldup.ptr;
|
|
|
|
len = out.u.cpldup.len;
|
2007-05-02 01:07:00 +00:00
|
|
|
}
|
|
|
|
|
2009-02-16 08:31:34 +00:00
|
|
|
n = qse_awk_rtx_writeio_str (run, out_type, name, str, len);
|
2007-05-02 01:07:00 +00:00
|
|
|
|
2008-12-21 21:35:07 +00:00
|
|
|
if (v->type != QSE_AWK_VAL_STR) QSE_AWK_FREE (run->awk, str);
|
2007-05-02 01:07:00 +00:00
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
2009-02-16 08:31:34 +00:00
|
|
|
int qse_awk_rtx_writeio_str (
|
2009-01-31 04:31:40 +00:00
|
|
|
qse_awk_rtx_t* run, int out_type,
|
2008-12-21 21:35:07 +00:00
|
|
|
const qse_char_t* name, qse_char_t* str, qse_size_t len)
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
2009-06-17 00:05:40 +00:00
|
|
|
qse_awk_rio_arg_t* p = run->rio.chain;
|
|
|
|
qse_awk_rio_fun_t handler;
|
2009-02-16 08:31:34 +00:00
|
|
|
int io_type, io_mode, io_mask;
|
2008-12-21 21:35:07 +00:00
|
|
|
qse_ssize_t n;
|
2007-05-02 01:07:00 +00:00
|
|
|
|
2008-12-21 21:35:07 +00:00
|
|
|
QSE_ASSERT (out_type >= 0 && out_type <= QSE_COUNTOF(out_type_map));
|
|
|
|
QSE_ASSERT (out_type >= 0 && out_type <= QSE_COUNTOF(out_mode_map));
|
|
|
|
QSE_ASSERT (out_type >= 0 && out_type <= QSE_COUNTOF(out_mask_map));
|
2007-05-02 01:07:00 +00:00
|
|
|
|
2009-02-16 08:31:34 +00:00
|
|
|
/* translate the out_type into the relevant io type and mode */
|
|
|
|
io_type = out_type_map[out_type];
|
|
|
|
io_mode = out_mode_map[out_type];
|
|
|
|
io_mask = out_mask_map[out_type];
|
2007-05-02 01:07:00 +00:00
|
|
|
|
2009-02-16 08:31:34 +00:00
|
|
|
handler = run->rio.handler[io_type];
|
2008-12-21 21:35:07 +00:00
|
|
|
if (handler == QSE_NULL)
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
|
|
|
/* no io handler provided */
|
2009-08-17 07:44:20 +00:00
|
|
|
qse_awk_rtx_seterrnum (run, QSE_AWK_EIOUSER, QSE_NULL);
|
2007-05-02 01:07:00 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2009-02-16 08:31:34 +00:00
|
|
|
/* look for the corresponding rio for name */
|
2008-12-21 21:35:07 +00:00
|
|
|
while (p != QSE_NULL)
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
|
|
|
/* the file "1.tmp", in the following code snippets,
|
|
|
|
* would be opened by the first print statement, but not by
|
|
|
|
* the second print statement. this is because
|
2009-01-17 04:20:22 +00:00
|
|
|
* both QSE_AWK_OUT_FILE and QSE_AWK_OUT_APFILE are
|
2009-02-16 08:31:34 +00:00
|
|
|
* translated to QSE_AWK_RIO_FILE and it is used to
|
2007-05-02 01:07:00 +00:00
|
|
|
* keep track of file handles..
|
|
|
|
*
|
|
|
|
* print "1111" >> "1.tmp"
|
|
|
|
* print "1111" > "1.tmp"
|
|
|
|
*/
|
2009-02-16 08:31:34 +00:00
|
|
|
if (p->type == (io_type | io_mask) &&
|
2008-12-21 21:35:07 +00:00
|
|
|
qse_strcmp (p->name, name) == 0) break;
|
2007-05-02 01:07:00 +00:00
|
|
|
p = p->next;
|
|
|
|
}
|
|
|
|
|
2009-02-16 08:31:34 +00:00
|
|
|
/* if there is not corresponding rio for name, create one */
|
2008-12-21 21:35:07 +00:00
|
|
|
if (p == QSE_NULL)
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
2009-06-17 00:05:40 +00:00
|
|
|
p = (qse_awk_rio_arg_t*) QSE_AWK_ALLOC (
|
|
|
|
run->awk, QSE_SIZEOF(qse_awk_rio_arg_t));
|
2008-12-21 21:35:07 +00:00
|
|
|
if (p == QSE_NULL)
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
2009-08-17 07:44:20 +00:00
|
|
|
qse_awk_rtx_seterrnum (run, QSE_AWK_ENOMEM, QSE_NULL);
|
2007-05-02 01:07:00 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2008-12-21 21:35:07 +00:00
|
|
|
p->name = QSE_AWK_STRDUP (run->awk, name);
|
|
|
|
if (p->name == QSE_NULL)
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
2008-12-21 21:35:07 +00:00
|
|
|
QSE_AWK_FREE (run->awk, p);
|
2009-08-17 07:44:20 +00:00
|
|
|
qse_awk_rtx_seterrnum (run, QSE_AWK_ENOMEM, QSE_NULL);
|
2007-05-02 01:07:00 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2009-02-16 08:31:34 +00:00
|
|
|
p->type = (io_type | io_mask);
|
|
|
|
p->mode = io_mode;
|
2009-08-29 03:48:02 +00:00
|
|
|
p->rwcmode = QSE_AWK_RIO_CLOSE_FULL;
|
2008-12-21 21:35:07 +00:00
|
|
|
p->handle = QSE_NULL;
|
|
|
|
p->next = QSE_NULL;
|
2009-08-28 06:52:20 +00:00
|
|
|
p->rwcstate = 0;
|
2007-05-02 01:07:00 +00:00
|
|
|
|
2009-08-28 06:52:20 +00:00
|
|
|
p->out.eof = 0;
|
|
|
|
p->out.eos = 0;
|
2007-05-02 01:07:00 +00:00
|
|
|
|
2009-08-17 07:44:20 +00:00
|
|
|
qse_awk_rtx_seterrnum (run, QSE_AWK_ENOERR, QSE_NULL);
|
2009-02-17 02:11:31 +00:00
|
|
|
n = handler (run, QSE_AWK_RIO_OPEN, p, QSE_NULL, 0);
|
2007-05-02 01:07:00 +00:00
|
|
|
if (n <= -1)
|
|
|
|
{
|
2008-12-21 21:35:07 +00:00
|
|
|
QSE_AWK_FREE (run->awk, p->name);
|
|
|
|
QSE_AWK_FREE (run->awk, p);
|
2007-05-02 01:07:00 +00:00
|
|
|
|
2009-06-15 02:40:52 +00:00
|
|
|
if (run->errinf.num == QSE_AWK_ENOERR)
|
2009-08-17 07:44:20 +00:00
|
|
|
qse_awk_rtx_seterrnum (run, QSE_AWK_EIOIMPL, QSE_NULL);
|
2007-05-02 01:07:00 +00:00
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* chain it */
|
2009-02-16 08:31:34 +00:00
|
|
|
p->next = run->rio.chain;
|
|
|
|
run->rio.chain = p;
|
2007-05-02 01:07:00 +00:00
|
|
|
|
|
|
|
/* usually, n == 0 indicates that it has reached the end
|
|
|
|
* of the input. the user io handler can return 0 for the
|
|
|
|
* open request if it doesn't have any files to open. One
|
|
|
|
* advantage of doing this would be that you can skip the
|
|
|
|
* entire pattern-block matching and exeuction. */
|
|
|
|
if (n == 0)
|
|
|
|
{
|
2009-08-28 06:52:20 +00:00
|
|
|
p->out.eos = 1;
|
2007-05-02 01:07:00 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (p->out.eos)
|
|
|
|
{
|
|
|
|
/* no more streams */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (p->out.eof)
|
|
|
|
{
|
|
|
|
/* it has reached the end of the stream but this function
|
|
|
|
* has been recalled */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (len > 0)
|
|
|
|
{
|
2009-08-17 07:44:20 +00:00
|
|
|
qse_awk_rtx_seterrnum (run, QSE_AWK_ENOERR, QSE_NULL);
|
2009-02-17 02:11:31 +00:00
|
|
|
n = handler (run, QSE_AWK_RIO_WRITE, p, str, len);
|
2007-05-02 01:07:00 +00:00
|
|
|
if (n <= -1)
|
|
|
|
{
|
2009-06-15 02:40:52 +00:00
|
|
|
if (run->errinf.num == QSE_AWK_ENOERR)
|
2009-08-17 07:44:20 +00:00
|
|
|
qse_awk_rtx_seterrnum (run, QSE_AWK_EIOIMPL, QSE_NULL);
|
2007-05-02 01:07:00 +00:00
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (n == 0)
|
|
|
|
{
|
2009-08-28 06:52:20 +00:00
|
|
|
p->out.eof = 1;
|
2007-05-02 01:07:00 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
len -= n;
|
|
|
|
str += n;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2009-02-16 08:31:34 +00:00
|
|
|
int qse_awk_rtx_flushio (
|
2009-01-31 04:31:40 +00:00
|
|
|
qse_awk_rtx_t* run, int out_type, const qse_char_t* name)
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
2009-06-17 00:05:40 +00:00
|
|
|
qse_awk_rio_arg_t* p = run->rio.chain;
|
|
|
|
qse_awk_rio_fun_t handler;
|
2009-02-16 08:31:34 +00:00
|
|
|
int io_type, /*io_mode,*/ io_mask;
|
2008-12-21 21:35:07 +00:00
|
|
|
qse_ssize_t n;
|
2009-08-28 06:52:20 +00:00
|
|
|
int ok = 0;
|
2007-05-02 01:07:00 +00:00
|
|
|
|
2008-12-21 21:35:07 +00:00
|
|
|
QSE_ASSERT (out_type >= 0 && out_type <= QSE_COUNTOF(out_type_map));
|
|
|
|
QSE_ASSERT (out_type >= 0 && out_type <= QSE_COUNTOF(out_mode_map));
|
|
|
|
QSE_ASSERT (out_type >= 0 && out_type <= QSE_COUNTOF(out_mask_map));
|
2007-05-02 01:07:00 +00:00
|
|
|
|
2009-02-16 08:31:34 +00:00
|
|
|
/* translate the out_type into the relevant io type and mode */
|
|
|
|
io_type = out_type_map[out_type];
|
|
|
|
/*io_mode = out_mode_map[out_type];*/
|
|
|
|
io_mask = out_mask_map[out_type];
|
2007-05-02 01:07:00 +00:00
|
|
|
|
2009-02-16 08:31:34 +00:00
|
|
|
handler = run->rio.handler[io_type];
|
2008-12-21 21:35:07 +00:00
|
|
|
if (handler == QSE_NULL)
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
|
|
|
/* no io handler provided */
|
2009-08-17 07:44:20 +00:00
|
|
|
qse_awk_rtx_seterrnum (run, QSE_AWK_EIOUSER, QSE_NULL);
|
2007-05-02 01:07:00 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2009-02-16 08:31:34 +00:00
|
|
|
/* look for the corresponding rio for name */
|
2008-12-21 21:35:07 +00:00
|
|
|
while (p != QSE_NULL)
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
2009-02-16 08:31:34 +00:00
|
|
|
if (p->type == (io_type | io_mask) &&
|
2008-12-21 21:35:07 +00:00
|
|
|
(name == QSE_NULL || qse_strcmp(p->name,name) == 0))
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
2009-08-17 07:44:20 +00:00
|
|
|
qse_awk_rtx_seterrnum (run, QSE_AWK_ENOERR, QSE_NULL);
|
2009-02-17 02:11:31 +00:00
|
|
|
n = handler (run, QSE_AWK_RIO_FLUSH, p, QSE_NULL, 0);
|
2007-05-02 01:07:00 +00:00
|
|
|
|
|
|
|
if (n <= -1)
|
|
|
|
{
|
2009-06-15 02:40:52 +00:00
|
|
|
if (run->errinf.num == QSE_AWK_ENOERR)
|
2009-08-17 07:44:20 +00:00
|
|
|
qse_awk_rtx_seterrnum (run, QSE_AWK_EIOIMPL, QSE_NULL);
|
2007-05-02 01:07:00 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2009-08-28 06:52:20 +00:00
|
|
|
ok = 1;
|
2007-05-02 01:07:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
p = p->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ok) return 0;
|
|
|
|
|
2009-02-16 08:31:34 +00:00
|
|
|
/* there is no corresponding rio for name */
|
2009-08-17 07:44:20 +00:00
|
|
|
qse_awk_rtx_seterrnum (run, QSE_AWK_EIONMNF, QSE_NULL);
|
2007-05-02 01:07:00 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2009-02-16 08:31:34 +00:00
|
|
|
int qse_awk_rtx_nextio_read (
|
2009-01-31 04:31:40 +00:00
|
|
|
qse_awk_rtx_t* run, int in_type, const qse_char_t* name)
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
2009-06-17 00:05:40 +00:00
|
|
|
qse_awk_rio_arg_t* p = run->rio.chain;
|
|
|
|
qse_awk_rio_fun_t handler;
|
2009-02-16 08:31:34 +00:00
|
|
|
int io_type, /*io_mode,*/ io_mask;
|
2008-12-21 21:35:07 +00:00
|
|
|
qse_ssize_t n;
|
2007-05-02 01:07:00 +00:00
|
|
|
|
2008-12-21 21:35:07 +00:00
|
|
|
QSE_ASSERT (in_type >= 0 && in_type <= QSE_COUNTOF(in_type_map));
|
|
|
|
QSE_ASSERT (in_type >= 0 && in_type <= QSE_COUNTOF(in_mode_map));
|
|
|
|
QSE_ASSERT (in_type >= 0 && in_type <= QSE_COUNTOF(in_mask_map));
|
2007-05-02 01:07:00 +00:00
|
|
|
|
2009-02-16 08:31:34 +00:00
|
|
|
/* translate the in_type into the relevant io type and mode */
|
|
|
|
io_type = in_type_map[in_type];
|
|
|
|
/*io_mode = in_mode_map[in_type];*/
|
|
|
|
io_mask = in_mask_map[in_type];
|
2007-05-02 01:07:00 +00:00
|
|
|
|
2009-02-16 08:31:34 +00:00
|
|
|
handler = run->rio.handler[io_type];
|
2008-12-21 21:35:07 +00:00
|
|
|
if (handler == QSE_NULL)
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
|
|
|
/* no io handler provided */
|
2009-08-17 07:44:20 +00:00
|
|
|
qse_awk_rtx_seterrnum (run, QSE_AWK_EIOUSER, QSE_NULL);
|
2007-05-02 01:07:00 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2008-12-21 21:35:07 +00:00
|
|
|
while (p != QSE_NULL)
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
2009-02-16 08:31:34 +00:00
|
|
|
if (p->type == (io_type | io_mask) &&
|
2008-12-21 21:35:07 +00:00
|
|
|
qse_strcmp (p->name,name) == 0) break;
|
2007-05-02 01:07:00 +00:00
|
|
|
p = p->next;
|
|
|
|
}
|
|
|
|
|
2008-12-21 21:35:07 +00:00
|
|
|
if (p == QSE_NULL)
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
|
|
|
/* something is totally wrong */
|
2008-12-21 21:35:07 +00:00
|
|
|
QSE_ASSERT (
|
2009-02-16 08:31:34 +00:00
|
|
|
!"should never happen - cannot find the relevant rio entry");
|
2009-08-17 07:44:20 +00:00
|
|
|
qse_awk_rtx_seterrnum (run, QSE_AWK_EINTERN, QSE_NULL);
|
2007-05-02 01:07:00 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (p->in.eos)
|
|
|
|
{
|
|
|
|
/* no more streams. */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-08-17 07:44:20 +00:00
|
|
|
qse_awk_rtx_seterrnum (run, QSE_AWK_ENOERR, QSE_NULL);
|
2009-02-17 02:11:31 +00:00
|
|
|
n = handler (run, QSE_AWK_RIO_NEXT, p, QSE_NULL, 0);
|
2007-05-02 01:07:00 +00:00
|
|
|
if (n <= -1)
|
|
|
|
{
|
2009-06-15 02:40:52 +00:00
|
|
|
if (run->errinf.num == QSE_AWK_ENOERR)
|
2009-08-17 07:44:20 +00:00
|
|
|
qse_awk_rtx_seterrnum (run, QSE_AWK_EIOIMPL, QSE_NULL);
|
2007-05-02 01:07:00 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (n == 0)
|
|
|
|
{
|
|
|
|
/* the next stream cannot be opened.
|
2009-02-16 08:31:34 +00:00
|
|
|
* set the eos flags so that the next call to nextio_read
|
2007-05-02 01:07:00 +00:00
|
|
|
* will return 0 without executing the handler */
|
2009-08-28 06:52:20 +00:00
|
|
|
p->in.eos = 1;
|
2007-11-11 00:30:00 +00:00
|
|
|
return 0;
|
2007-05-02 01:07:00 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* as the next stream has been opened successfully,
|
|
|
|
* the eof flag should be cleared if set */
|
2009-08-28 06:52:20 +00:00
|
|
|
p->in.eof = 0;
|
2007-05-02 01:07:00 +00:00
|
|
|
|
|
|
|
/* also the previous input buffer must be reset */
|
|
|
|
p->in.pos = 0;
|
|
|
|
p->in.len = 0;
|
|
|
|
|
2007-11-11 00:30:00 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2007-05-02 01:07:00 +00:00
|
|
|
}
|
|
|
|
|
2009-02-16 08:31:34 +00:00
|
|
|
int qse_awk_rtx_nextio_write (
|
2009-01-31 04:31:40 +00:00
|
|
|
qse_awk_rtx_t* run, int out_type, const qse_char_t* name)
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
2009-06-17 00:05:40 +00:00
|
|
|
qse_awk_rio_arg_t* p = run->rio.chain;
|
|
|
|
qse_awk_rio_fun_t handler;
|
2009-02-16 08:31:34 +00:00
|
|
|
int io_type, /*io_mode,*/ io_mask;
|
2008-12-21 21:35:07 +00:00
|
|
|
qse_ssize_t n;
|
2007-05-02 01:07:00 +00:00
|
|
|
|
2008-12-21 21:35:07 +00:00
|
|
|
QSE_ASSERT (out_type >= 0 && out_type <= QSE_COUNTOF(out_type_map));
|
|
|
|
QSE_ASSERT (out_type >= 0 && out_type <= QSE_COUNTOF(out_mode_map));
|
|
|
|
QSE_ASSERT (out_type >= 0 && out_type <= QSE_COUNTOF(out_mask_map));
|
2007-05-02 01:07:00 +00:00
|
|
|
|
2009-02-16 08:31:34 +00:00
|
|
|
/* translate the out_type into the relevant io type and mode */
|
|
|
|
io_type = out_type_map[out_type];
|
|
|
|
/*io_mode = out_mode_map[out_type];*/
|
|
|
|
io_mask = out_mask_map[out_type];
|
2007-05-02 01:07:00 +00:00
|
|
|
|
2009-02-16 08:31:34 +00:00
|
|
|
handler = run->rio.handler[io_type];
|
2008-12-21 21:35:07 +00:00
|
|
|
if (handler == QSE_NULL)
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
|
|
|
/* no io handler provided */
|
2009-08-17 07:44:20 +00:00
|
|
|
qse_awk_rtx_seterrnum (run, QSE_AWK_EIOUSER, QSE_NULL);
|
2007-05-02 01:07:00 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2008-12-21 21:35:07 +00:00
|
|
|
while (p != QSE_NULL)
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
2009-02-16 08:31:34 +00:00
|
|
|
if (p->type == (io_type | io_mask) &&
|
2008-12-21 21:35:07 +00:00
|
|
|
qse_strcmp (p->name,name) == 0) break;
|
2007-05-02 01:07:00 +00:00
|
|
|
p = p->next;
|
|
|
|
}
|
|
|
|
|
2008-12-21 21:35:07 +00:00
|
|
|
if (p == QSE_NULL)
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
|
|
|
/* something is totally wrong */
|
2009-02-16 08:31:34 +00:00
|
|
|
QSE_ASSERT (!"should never happen - cannot find the relevant rio entry");
|
2007-05-02 01:07:00 +00:00
|
|
|
|
2009-08-17 07:44:20 +00:00
|
|
|
qse_awk_rtx_seterrnum (run, QSE_AWK_EINTERN, QSE_NULL);
|
2007-05-02 01:07:00 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (p->out.eos)
|
|
|
|
{
|
|
|
|
/* no more streams. */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-08-17 07:44:20 +00:00
|
|
|
qse_awk_rtx_seterrnum (run, QSE_AWK_ENOERR, QSE_NULL);
|
2009-02-17 02:11:31 +00:00
|
|
|
n = handler (run, QSE_AWK_RIO_NEXT, p, QSE_NULL, 0);
|
2007-05-02 01:07:00 +00:00
|
|
|
if (n <= -1)
|
|
|
|
{
|
2009-06-15 02:40:52 +00:00
|
|
|
if (run->errinf.num == QSE_AWK_ENOERR)
|
2009-08-17 07:44:20 +00:00
|
|
|
qse_awk_rtx_seterrnum (run, QSE_AWK_EIOIMPL, QSE_NULL);
|
2007-05-02 01:07:00 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (n == 0)
|
|
|
|
{
|
|
|
|
/* the next stream cannot be opened.
|
2009-02-16 08:31:34 +00:00
|
|
|
* set the eos flags so that the next call to nextio_write
|
2007-05-02 01:07:00 +00:00
|
|
|
* will return 0 without executing the handler */
|
2009-08-28 06:52:20 +00:00
|
|
|
p->out.eos = 1;
|
2007-11-11 00:30:00 +00:00
|
|
|
return 0;
|
2007-05-02 01:07:00 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* as the next stream has been opened successfully,
|
|
|
|
* the eof flag should be cleared if set */
|
2009-08-28 06:52:20 +00:00
|
|
|
p->out.eof = 0;
|
2007-11-11 00:30:00 +00:00
|
|
|
return 1;
|
2007-05-02 01:07:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-16 08:31:34 +00:00
|
|
|
int qse_awk_rtx_closio_read (
|
2009-01-31 04:31:40 +00:00
|
|
|
qse_awk_rtx_t* run, int in_type, const qse_char_t* name)
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
2009-06-17 00:05:40 +00:00
|
|
|
qse_awk_rio_arg_t* p = run->rio.chain, * px = QSE_NULL;
|
|
|
|
qse_awk_rio_fun_t handler;
|
2009-02-16 08:31:34 +00:00
|
|
|
int io_type, /*io_mode,*/ io_mask;
|
2007-05-02 01:07:00 +00:00
|
|
|
|
2008-12-21 21:35:07 +00:00
|
|
|
QSE_ASSERT (in_type >= 0 && in_type <= QSE_COUNTOF(in_type_map));
|
|
|
|
QSE_ASSERT (in_type >= 0 && in_type <= QSE_COUNTOF(in_mode_map));
|
|
|
|
QSE_ASSERT (in_type >= 0 && in_type <= QSE_COUNTOF(in_mask_map));
|
2007-05-02 01:07:00 +00:00
|
|
|
|
2009-02-16 08:31:34 +00:00
|
|
|
/* translate the in_type into the relevant io type and mode */
|
|
|
|
io_type = in_type_map[in_type];
|
|
|
|
/*io_mode = in_mode_map[in_type];*/
|
|
|
|
io_mask = in_mask_map[in_type];
|
2007-05-02 01:07:00 +00:00
|
|
|
|
2009-02-16 08:31:34 +00:00
|
|
|
handler = run->rio.handler[io_type];
|
2008-12-21 21:35:07 +00:00
|
|
|
if (handler == QSE_NULL)
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
|
|
|
/* no io handler provided */
|
2009-08-17 07:44:20 +00:00
|
|
|
qse_awk_rtx_seterrnum (run, QSE_AWK_EIOUSER, QSE_NULL);
|
2007-05-02 01:07:00 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2008-12-21 21:35:07 +00:00
|
|
|
while (p != QSE_NULL)
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
2009-02-16 08:31:34 +00:00
|
|
|
if (p->type == (io_type | io_mask) &&
|
2008-12-21 21:35:07 +00:00
|
|
|
qse_strcmp (p->name, name) == 0)
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
2009-06-17 00:05:40 +00:00
|
|
|
qse_awk_rio_fun_t handler;
|
2007-05-02 01:07:00 +00:00
|
|
|
|
2009-02-16 08:31:34 +00:00
|
|
|
handler = run->rio.handler[p->type & MASK_CLEAR];
|
2008-12-21 21:35:07 +00:00
|
|
|
if (handler != QSE_NULL)
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
2009-02-17 02:11:31 +00:00
|
|
|
if (handler (run, QSE_AWK_RIO_CLOSE, p, QSE_NULL, 0) <= -1)
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
|
|
|
/* this is not a run-time error.*/
|
2009-08-17 07:44:20 +00:00
|
|
|
qse_awk_rtx_seterrnum (run, QSE_AWK_EIOIMPL, QSE_NULL);
|
2007-05-02 01:07:00 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-21 21:35:07 +00:00
|
|
|
if (px != QSE_NULL) px->next = p->next;
|
2009-02-16 08:31:34 +00:00
|
|
|
else run->rio.chain = p->next;
|
2007-05-02 01:07:00 +00:00
|
|
|
|
2008-12-21 21:35:07 +00:00
|
|
|
QSE_AWK_FREE (run->awk, p->name);
|
|
|
|
QSE_AWK_FREE (run->awk, p);
|
2007-05-02 01:07:00 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
px = p;
|
|
|
|
p = p->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* the name given is not found */
|
2009-08-17 07:44:20 +00:00
|
|
|
qse_awk_rtx_seterrnum (run, QSE_AWK_EIONMNF, QSE_NULL);
|
2007-05-02 01:07:00 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2009-02-16 08:31:34 +00:00
|
|
|
int qse_awk_rtx_closio_write (
|
2009-01-31 04:31:40 +00:00
|
|
|
qse_awk_rtx_t* run, int out_type, const qse_char_t* name)
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
2009-06-17 00:05:40 +00:00
|
|
|
qse_awk_rio_arg_t* p = run->rio.chain, * px = QSE_NULL;
|
|
|
|
qse_awk_rio_fun_t handler;
|
2009-02-16 08:31:34 +00:00
|
|
|
int io_type, /*io_mode,*/ io_mask;
|
2007-05-02 01:07:00 +00:00
|
|
|
|
2008-12-21 21:35:07 +00:00
|
|
|
QSE_ASSERT (out_type >= 0 && out_type <= QSE_COUNTOF(out_type_map));
|
|
|
|
QSE_ASSERT (out_type >= 0 && out_type <= QSE_COUNTOF(out_mode_map));
|
|
|
|
QSE_ASSERT (out_type >= 0 && out_type <= QSE_COUNTOF(out_mask_map));
|
2007-05-02 01:07:00 +00:00
|
|
|
|
2009-02-16 08:31:34 +00:00
|
|
|
/* translate the out_type into the relevant io type and mode */
|
|
|
|
io_type = out_type_map[out_type];
|
|
|
|
/*io_mode = out_mode_map[out_type];*/
|
|
|
|
io_mask = out_mask_map[out_type];
|
2007-05-02 01:07:00 +00:00
|
|
|
|
2009-02-16 08:31:34 +00:00
|
|
|
handler = run->rio.handler[io_type];
|
2008-12-21 21:35:07 +00:00
|
|
|
if (handler == QSE_NULL)
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
|
|
|
/* no io handler provided */
|
2009-08-17 07:44:20 +00:00
|
|
|
qse_awk_rtx_seterrnum (run, QSE_AWK_EIOUSER, QSE_NULL);
|
2007-05-02 01:07:00 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2008-12-21 21:35:07 +00:00
|
|
|
while (p != QSE_NULL)
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
2009-02-16 08:31:34 +00:00
|
|
|
if (p->type == (io_type | io_mask) &&
|
2008-12-21 21:35:07 +00:00
|
|
|
qse_strcmp (p->name, name) == 0)
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
2009-06-17 00:05:40 +00:00
|
|
|
qse_awk_rio_fun_t handler;
|
2007-05-02 01:07:00 +00:00
|
|
|
|
2009-02-16 08:31:34 +00:00
|
|
|
handler = run->rio.handler[p->type & MASK_CLEAR];
|
2008-12-21 21:35:07 +00:00
|
|
|
if (handler != QSE_NULL)
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
2009-08-17 07:44:20 +00:00
|
|
|
qse_awk_rtx_seterrnum (run, QSE_AWK_ENOERR, QSE_NULL);
|
2009-02-17 02:11:31 +00:00
|
|
|
if (handler (run, QSE_AWK_RIO_CLOSE, p, QSE_NULL, 0) <= -1)
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
2009-06-15 02:40:52 +00:00
|
|
|
if (run->errinf.num == QSE_AWK_ENOERR)
|
2009-08-17 07:44:20 +00:00
|
|
|
qse_awk_rtx_seterrnum (run, QSE_AWK_EIOIMPL, QSE_NULL);
|
2007-05-02 01:07:00 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-21 21:35:07 +00:00
|
|
|
if (px != QSE_NULL) px->next = p->next;
|
2009-02-16 08:31:34 +00:00
|
|
|
else run->rio.chain = p->next;
|
2007-05-02 01:07:00 +00:00
|
|
|
|
2008-12-21 21:35:07 +00:00
|
|
|
QSE_AWK_FREE (run->awk, p->name);
|
|
|
|
QSE_AWK_FREE (run->awk, p);
|
2007-05-02 01:07:00 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
px = p;
|
|
|
|
p = p->next;
|
|
|
|
}
|
|
|
|
|
2009-08-17 07:44:20 +00:00
|
|
|
qse_awk_rtx_seterrnum (run, QSE_AWK_EIONMNF, QSE_NULL);
|
2007-05-02 01:07:00 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2009-08-27 06:59:08 +00:00
|
|
|
int qse_awk_rtx_closeio (
|
|
|
|
qse_awk_rtx_t* rtx, const qse_char_t* name, const qse_char_t* opt)
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
2009-08-27 06:59:08 +00:00
|
|
|
qse_awk_rio_arg_t* p = rtx->rio.chain, * px = QSE_NULL;
|
2007-05-02 01:07:00 +00:00
|
|
|
|
2008-12-21 21:35:07 +00:00
|
|
|
while (p != QSE_NULL)
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
|
|
|
/* it handles the first that matches the given name
|
2009-02-16 08:31:34 +00:00
|
|
|
* regardless of the io type */
|
2008-12-21 21:35:07 +00:00
|
|
|
if (qse_strcmp (p->name, name) == 0)
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
2009-06-17 00:05:40 +00:00
|
|
|
qse_awk_rio_fun_t handler;
|
2009-08-29 03:48:02 +00:00
|
|
|
qse_awk_rio_rwcmode_t rwcmode = QSE_AWK_RIO_CLOSE_FULL;
|
2009-08-27 06:59:08 +00:00
|
|
|
|
|
|
|
if (opt != QSE_NULL)
|
|
|
|
{
|
|
|
|
if (opt[0] == QSE_T('r'))
|
|
|
|
{
|
2009-08-28 06:52:20 +00:00
|
|
|
if (p->type & MASK_RDWR)
|
|
|
|
{
|
2009-08-29 03:48:02 +00:00
|
|
|
if (p->rwcstate != QSE_AWK_RIO_CLOSE_WRITE)
|
2009-08-28 06:52:20 +00:00
|
|
|
{
|
|
|
|
/* if the write end is not
|
|
|
|
* closed, let io handler close
|
|
|
|
* the read end only. */
|
2009-08-29 03:48:02 +00:00
|
|
|
rwcmode = QSE_AWK_RIO_CLOSE_READ;
|
2009-08-28 06:52:20 +00:00
|
|
|
}
|
|
|
|
}
|
2009-08-27 06:59:08 +00:00
|
|
|
else if (!(p->type & MASK_READ)) goto skip;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
QSE_ASSERT (opt[0] == QSE_T('w'));
|
2009-08-28 06:52:20 +00:00
|
|
|
if (p->type & MASK_RDWR)
|
|
|
|
{
|
2009-08-29 03:48:02 +00:00
|
|
|
if (p->rwcstate != QSE_AWK_RIO_CLOSE_READ)
|
2009-08-28 06:52:20 +00:00
|
|
|
{
|
|
|
|
/* if the read end is not
|
|
|
|
* closed, let io handler close
|
|
|
|
* the write end only. */
|
2009-08-29 03:48:02 +00:00
|
|
|
rwcmode = QSE_AWK_RIO_CLOSE_WRITE;
|
2009-08-28 06:52:20 +00:00
|
|
|
}
|
|
|
|
}
|
2009-08-27 06:59:08 +00:00
|
|
|
else if (!(p->type & MASK_WRITE)) goto skip;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
handler = rtx->rio.handler[p->type & MASK_CLEAR];
|
2008-12-21 21:35:07 +00:00
|
|
|
if (handler != QSE_NULL)
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
2009-08-27 06:59:08 +00:00
|
|
|
qse_awk_rtx_seterrnum (rtx, QSE_AWK_ENOERR, QSE_NULL);
|
2009-08-29 03:48:02 +00:00
|
|
|
p->rwcmode = rwcmode;
|
2009-08-27 06:59:08 +00:00
|
|
|
if (handler (rtx, QSE_AWK_RIO_CLOSE, p, QSE_NULL, 0) <= -1)
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
|
|
|
/* this is not a run-time error.*/
|
2009-08-27 06:59:08 +00:00
|
|
|
if (rtx->errinf.num == QSE_AWK_ENOERR)
|
|
|
|
qse_awk_rtx_seterrnum (rtx, QSE_AWK_EIOIMPL, QSE_NULL);
|
2007-05-02 01:07:00 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
2009-08-28 06:52:20 +00:00
|
|
|
|
|
|
|
if (p->type & MASK_RDWR)
|
|
|
|
{
|
2009-08-29 03:48:02 +00:00
|
|
|
p->rwcmode = rwcmode;
|
|
|
|
if (p->rwcstate == 0 && rwcmode != 0)
|
2009-08-28 06:52:20 +00:00
|
|
|
{
|
|
|
|
/* if either end has not been closed.
|
|
|
|
* return success without destroying
|
|
|
|
* the internal node. rwcstate keeps
|
|
|
|
* what has been successfully closed */
|
2009-08-29 03:48:02 +00:00
|
|
|
p->rwcstate = rwcmode;
|
2009-08-28 06:52:20 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2007-05-02 01:07:00 +00:00
|
|
|
|
2008-12-21 21:35:07 +00:00
|
|
|
if (px != QSE_NULL) px->next = p->next;
|
2009-08-27 06:59:08 +00:00
|
|
|
else rtx->rio.chain = p->next;
|
2007-05-02 01:07:00 +00:00
|
|
|
|
2009-08-27 06:59:08 +00:00
|
|
|
QSE_AWK_FREE (rtx->awk, p->name);
|
|
|
|
QSE_AWK_FREE (rtx->awk, p);
|
2007-05-02 01:07:00 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-08-27 06:59:08 +00:00
|
|
|
skip:
|
2007-05-02 01:07:00 +00:00
|
|
|
px = p;
|
|
|
|
p = p->next;
|
|
|
|
}
|
|
|
|
|
2009-08-27 06:59:08 +00:00
|
|
|
qse_awk_rtx_seterrnum (rtx, QSE_AWK_EIONMNF, QSE_NULL);
|
2007-05-02 01:07:00 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2009-02-16 08:31:34 +00:00
|
|
|
void qse_awk_rtx_cleario (qse_awk_rtx_t* run)
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
2009-06-17 00:05:40 +00:00
|
|
|
qse_awk_rio_arg_t* next;
|
|
|
|
qse_awk_rio_fun_t handler;
|
2008-12-21 21:35:07 +00:00
|
|
|
qse_ssize_t n;
|
2007-05-02 01:07:00 +00:00
|
|
|
|
2009-02-16 08:31:34 +00:00
|
|
|
while (run->rio.chain != QSE_NULL)
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
2009-02-16 08:31:34 +00:00
|
|
|
handler = run->rio.handler[
|
|
|
|
run->rio.chain->type & MASK_CLEAR];
|
|
|
|
next = run->rio.chain->next;
|
2007-05-02 01:07:00 +00:00
|
|
|
|
2008-12-21 21:35:07 +00:00
|
|
|
if (handler != QSE_NULL)
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
2009-08-17 07:44:20 +00:00
|
|
|
qse_awk_rtx_seterrnum (run, QSE_AWK_ENOERR, QSE_NULL);
|
2009-08-29 03:48:02 +00:00
|
|
|
run->rio.chain->rwcmode = 0;
|
2009-02-17 02:11:31 +00:00
|
|
|
n = handler (run, QSE_AWK_RIO_CLOSE, run->rio.chain, QSE_NULL, 0);
|
2007-05-02 01:07:00 +00:00
|
|
|
if (n <= -1)
|
|
|
|
{
|
2009-06-15 02:40:52 +00:00
|
|
|
if (run->errinf.num == QSE_AWK_ENOERR)
|
2009-08-17 07:44:20 +00:00
|
|
|
qse_awk_rtx_seterrnum (run, QSE_AWK_EIOIMPL, QSE_NULL);
|
2007-05-02 01:07:00 +00:00
|
|
|
/* TODO: some warnings need to be shown??? */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-16 08:31:34 +00:00
|
|
|
QSE_AWK_FREE (run->awk, run->rio.chain->name);
|
|
|
|
QSE_AWK_FREE (run->awk, run->rio.chain);
|
2007-05-02 01:07:00 +00:00
|
|
|
|
2009-02-16 08:31:34 +00:00
|
|
|
run->rio.chain = next;
|
2007-05-02 01:07:00 +00:00
|
|
|
}
|
|
|
|
}
|