added quite some code to handle byte string I/O
This commit is contained in:
parent
07be5e22d7
commit
eed3853765
@ -386,6 +386,7 @@ public:
|
||||
virtual int close (Pipe& io) = 0;
|
||||
virtual ssize_t read (Pipe& io, char_t* buf, size_t len) = 0;
|
||||
virtual ssize_t write (Pipe& io, const char_t* buf, size_t len) = 0;
|
||||
virtual ssize_t writeBytes (Pipe& io, const qse_mchar_t* buf, size_t len) = 0;
|
||||
virtual int flush (Pipe& io) = 0;
|
||||
};
|
||||
|
||||
@ -430,6 +431,7 @@ public:
|
||||
virtual int close (File& io) = 0;
|
||||
virtual ssize_t read (File& io, char_t* buf, size_t len) = 0;
|
||||
virtual ssize_t write (File& io, const char_t* buf, size_t len) = 0;
|
||||
virtual ssize_t writeBytes (File& io, const qse_mchar_t* buf, size_t len) = 0;
|
||||
virtual int flush (File& io) = 0;
|
||||
};
|
||||
|
||||
@ -493,6 +495,8 @@ public:
|
||||
/// for failure.
|
||||
virtual ssize_t write (Console& io, const char_t* buf, size_t len) = 0;
|
||||
|
||||
virtual ssize_t writeBytes (Console& io, const qse_mchar_t* buf, size_t len) = 0;
|
||||
|
||||
/// You may choose to buffer the data passed to the write()
|
||||
/// function and perform actual writing when flush() is called.
|
||||
/// It must return 0 for success and -1 for failure.
|
||||
@ -1282,6 +1286,7 @@ protected:
|
||||
|
||||
virtual ssize_t readPipe (Pipe& io, char_t* buf, size_t len);
|
||||
virtual ssize_t writePipe (Pipe& io, const char_t* buf, size_t len);
|
||||
virtual ssize_t writePipeBytes (Pipe& io, const qse_mchar_t* buf, size_t len);
|
||||
virtual int flushPipe (Pipe& io);
|
||||
/// \}
|
||||
|
||||
@ -1295,6 +1300,7 @@ protected:
|
||||
virtual int closeFile (File& io);
|
||||
virtual ssize_t readFile (File& io, char_t* buf, size_t len);
|
||||
virtual ssize_t writeFile (File& io, const char_t* buf, size_t len);
|
||||
virtual ssize_t writeFileBytes (File& io, const qse_mchar_t* buf, size_t len);
|
||||
virtual int flushFile (File& io);
|
||||
/// \}
|
||||
|
||||
@ -1308,6 +1314,7 @@ protected:
|
||||
virtual int closeConsole (Console& io);
|
||||
virtual ssize_t readConsole (Console& io, char_t* buf, size_t len);
|
||||
virtual ssize_t writeConsole (Console& io, const char_t* buf, size_t len);
|
||||
virtual ssize_t writeConsoleBytes (Console& io, const qse_mchar_t* buf, size_t len);
|
||||
virtual int flushConsole (Console& io);
|
||||
virtual int nextConsole (Console& io);
|
||||
/// \}
|
||||
@ -1330,13 +1337,13 @@ protected:
|
||||
|
||||
static ssize_t pipeHandler (
|
||||
rtx_t* rtx, rio_cmd_t cmd, rio_arg_t* riod,
|
||||
char_t* data, size_t count);
|
||||
void* data, size_t count);
|
||||
static ssize_t fileHandler (
|
||||
rtx_t* rtx, rio_cmd_t cmd, rio_arg_t* riod,
|
||||
char_t* data, size_t count);
|
||||
void* data, size_t count);
|
||||
static ssize_t consoleHandler (
|
||||
rtx_t* rtx, rio_cmd_t cmd, rio_arg_t* riod,
|
||||
char_t* data, size_t count);
|
||||
void* data, size_t count);
|
||||
|
||||
static int functionHandler (rtx_t* rtx, const fnc_info_t* fi);
|
||||
|
||||
|
@ -133,6 +133,7 @@ protected:
|
||||
int closePipe (Pipe& io);
|
||||
ssize_t readPipe (Pipe& io, char_t* buf, size_t len);
|
||||
ssize_t writePipe (Pipe& io, const char_t* buf, size_t len);
|
||||
ssize_t writePipeBytes (Pipe& io, const qse_mchar_t* buf, size_t len);
|
||||
int flushPipe (Pipe& io);
|
||||
|
||||
// file io handlers
|
||||
@ -140,6 +141,7 @@ protected:
|
||||
int closeFile (File& io);
|
||||
ssize_t readFile (File& io, char_t* buf, size_t len);
|
||||
ssize_t writeFile (File& io, const char_t* buf, size_t len);
|
||||
ssize_t writeFileBytes (File& io, const qse_mchar_t* buf, size_t len);
|
||||
int flushFile (File& io);
|
||||
|
||||
// console io handlers
|
||||
@ -147,6 +149,7 @@ protected:
|
||||
int closeConsole (Console& io);
|
||||
ssize_t readConsole (Console& io, char_t* buf, size_t len);
|
||||
ssize_t writeConsole (Console& io, const char_t* buf, size_t len);
|
||||
ssize_t writeConsoleBytes (Console& io, const qse_mchar_t* buf, size_t len);
|
||||
int flushConsole (Console& io);
|
||||
int nextConsole (Console& io);
|
||||
|
||||
|
@ -590,8 +590,10 @@ enum qse_awk_rio_cmd_t
|
||||
QSE_AWK_RIO_CLOSE = 1, /**< close a stream */
|
||||
QSE_AWK_RIO_READ = 2, /**< read a stream */
|
||||
QSE_AWK_RIO_WRITE = 3, /**< write to a stream */
|
||||
QSE_AWK_RIO_FLUSH = 4, /**< flush buffered data to a stream */
|
||||
QSE_AWK_RIO_NEXT = 5 /**< close the current stream and
|
||||
/*QSE_AWK_RIO_READ_BYTES = 4,*/
|
||||
QSE_AWK_RIO_WRITE_BYTES = 5,
|
||||
QSE_AWK_RIO_FLUSH = 6, /**< flush buffered data to a stream */
|
||||
QSE_AWK_RIO_NEXT = 7 /**< close the current stream and
|
||||
open the next stream (only for console) */
|
||||
};
|
||||
typedef enum qse_awk_rio_cmd_t qse_awk_rio_cmd_t;
|
||||
@ -644,7 +646,7 @@ struct qse_awk_rio_arg_t
|
||||
|
||||
/* read-write. a user handler can do whatever it likes to do with these. */
|
||||
void* handle; /**< I/O handle set by a handler */
|
||||
int uflags; /**< flags set by a handler */
|
||||
int uflags; /**< user-flags set by a handler */
|
||||
|
||||
/*-- from here down, internal use only --*/
|
||||
int type;
|
||||
@ -676,7 +678,7 @@ typedef qse_ssize_t (*qse_awk_rio_impl_t) (
|
||||
qse_awk_rtx_t* rtx,
|
||||
qse_awk_rio_cmd_t cmd,
|
||||
qse_awk_rio_arg_t* arg,
|
||||
qse_char_t* data,
|
||||
void* data,
|
||||
qse_size_t count
|
||||
);
|
||||
|
||||
|
@ -214,6 +214,12 @@ QSE_EXPORT qse_ssize_t qse_nwio_write (
|
||||
qse_size_t size
|
||||
);
|
||||
|
||||
QSE_EXPORT qse_ssize_t qse_nwio_writebytes (
|
||||
qse_nwio_t* nwio,
|
||||
const void* data,
|
||||
qse_size_t size
|
||||
);
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
@ -365,6 +365,13 @@ QSE_EXPORT qse_ssize_t qse_pio_write (
|
||||
qse_size_t size /**< data size */
|
||||
);
|
||||
|
||||
QSE_EXPORT qse_ssize_t qse_pio_writebytes (
|
||||
qse_pio_t* pio, /**< pio object */
|
||||
qse_pio_hid_t hid, /**< handle ID */
|
||||
const void* data, /**< data to write */
|
||||
qse_size_t size /**< data size */
|
||||
);
|
||||
|
||||
/**
|
||||
* The qse_pio_flush() flushes buffered data if #QSE_PIO_TEXT has been
|
||||
* specified to qse_pio_open() and qse_pio_init().
|
||||
|
@ -1800,9 +1800,7 @@ Awk::ssize_t Awk::writeSource (
|
||||
}
|
||||
}
|
||||
|
||||
Awk::ssize_t Awk::pipeHandler (
|
||||
rtx_t* rtx, rio_cmd_t cmd, rio_arg_t* riod,
|
||||
char_t* data, size_t count)
|
||||
Awk::ssize_t Awk::pipeHandler (rtx_t* rtx, rio_cmd_t cmd, rio_arg_t* riod, void* data, size_t count)
|
||||
{
|
||||
rxtn_t* rxtn = (rxtn_t*)QSE_XTN(rtx);
|
||||
Awk* awk = rxtn->run->awk;
|
||||
@ -1823,9 +1821,11 @@ Awk::ssize_t Awk::pipeHandler (
|
||||
return awk->pipe_handler->close(pipe);
|
||||
|
||||
case QSE_AWK_RIO_READ:
|
||||
return awk->pipe_handler->read (pipe, data, count);
|
||||
return awk->pipe_handler->read(pipe, (qse_char_t*)data, count);
|
||||
case QSE_AWK_RIO_WRITE:
|
||||
return awk->pipe_handler->write (pipe, data, count);
|
||||
return awk->pipe_handler->write(pipe, (const qse_char_t*)data, count);
|
||||
case QSE_AWK_RIO_WRITE_BYTES:
|
||||
return awk->pipe_handler->writeBytes(pipe, (const qse_mchar_t*)data, count);
|
||||
|
||||
case QSE_AWK_RIO_FLUSH:
|
||||
return awk->pipe_handler->flush(pipe);
|
||||
@ -1844,9 +1844,11 @@ Awk::ssize_t Awk::pipeHandler (
|
||||
return awk->closePipe(pipe);
|
||||
|
||||
case QSE_AWK_RIO_READ:
|
||||
return awk->readPipe (pipe, data, count);
|
||||
return awk->readPipe(pipe, (qse_char_t*)data, count);
|
||||
case QSE_AWK_RIO_WRITE:
|
||||
return awk->writePipe (pipe, data, count);
|
||||
return awk->writePipe(pipe, (const qse_char_t*)data, count);
|
||||
case QSE_AWK_RIO_WRITE_BYTES:
|
||||
return awk->writePipeBytes(pipe, (const qse_mchar_t*)data, count);
|
||||
|
||||
case QSE_AWK_RIO_FLUSH:
|
||||
return awk->flushPipe(pipe);
|
||||
@ -1862,9 +1864,7 @@ Awk::ssize_t Awk::pipeHandler (
|
||||
}
|
||||
}
|
||||
|
||||
Awk::ssize_t Awk::fileHandler (
|
||||
rtx_t* rtx, rio_cmd_t cmd, rio_arg_t* riod,
|
||||
char_t* data, size_t count)
|
||||
Awk::ssize_t Awk::fileHandler (rtx_t* rtx, rio_cmd_t cmd, rio_arg_t* riod, void* data, size_t count)
|
||||
{
|
||||
rxtn_t* rxtn = (rxtn_t*)QSE_XTN(rtx);
|
||||
Awk* awk = rxtn->run->awk;
|
||||
@ -1885,9 +1885,11 @@ Awk::ssize_t Awk::fileHandler (
|
||||
return awk->file_handler->close(file);
|
||||
|
||||
case QSE_AWK_RIO_READ:
|
||||
return awk->file_handler->read (file, data, count);
|
||||
return awk->file_handler->read(file, (qse_char_t*)data, count);
|
||||
case QSE_AWK_RIO_WRITE:
|
||||
return awk->file_handler->write (file, data, count);
|
||||
return awk->file_handler->write(file, (const qse_char_t*)data, count);
|
||||
case QSE_AWK_RIO_WRITE_BYTES:
|
||||
return awk->file_handler->writeBytes(file, (const qse_mchar_t*)data, count);
|
||||
|
||||
case QSE_AWK_RIO_FLUSH:
|
||||
return awk->file_handler->flush(file);
|
||||
@ -1906,9 +1908,11 @@ Awk::ssize_t Awk::fileHandler (
|
||||
return awk->closeFile(file);
|
||||
|
||||
case QSE_AWK_RIO_READ:
|
||||
return awk->readFile (file, data, count);
|
||||
return awk->readFile(file, (qse_char_t*)data, count);
|
||||
case QSE_AWK_RIO_WRITE:
|
||||
return awk->writeFile (file, data, count);
|
||||
return awk->writeFile(file, (const qse_char_t*)data, count);
|
||||
case QSE_AWK_RIO_WRITE_BYTES:
|
||||
return awk->writeFileBytes(file, (const qse_mchar_t*)data, count);
|
||||
|
||||
case QSE_AWK_RIO_FLUSH:
|
||||
return awk->flushFile(file);
|
||||
@ -1924,9 +1928,7 @@ Awk::ssize_t Awk::fileHandler (
|
||||
}
|
||||
}
|
||||
|
||||
Awk::ssize_t Awk::consoleHandler (
|
||||
rtx_t* rtx, rio_cmd_t cmd, rio_arg_t* riod,
|
||||
char_t* data, size_t count)
|
||||
Awk::ssize_t Awk::consoleHandler (rtx_t* rtx, rio_cmd_t cmd, rio_arg_t* riod, void* data, size_t count)
|
||||
{
|
||||
rxtn_t* rxtn = (rxtn_t*) QSE_XTN (rtx);
|
||||
Awk* awk = rxtn->run->awk;
|
||||
@ -1947,9 +1949,11 @@ Awk::ssize_t Awk::consoleHandler (
|
||||
return awk->console_handler->close(console);
|
||||
|
||||
case QSE_AWK_RIO_READ:
|
||||
return awk->console_handler->read (console, data, count);
|
||||
return awk->console_handler->read(console, (qse_char_t*)data, count);
|
||||
case QSE_AWK_RIO_WRITE:
|
||||
return awk->console_handler->write (console, data, count);
|
||||
return awk->console_handler->write(console, (const qse_char_t*)data, count);
|
||||
case QSE_AWK_RIO_WRITE_BYTES:
|
||||
return awk->console_handler->writeBytes(console, (const qse_mchar_t*)data, count);
|
||||
|
||||
case QSE_AWK_RIO_FLUSH:
|
||||
return awk->console_handler->flush(console);
|
||||
@ -1970,9 +1974,11 @@ Awk::ssize_t Awk::consoleHandler (
|
||||
return awk->closeConsole(console);
|
||||
|
||||
case QSE_AWK_RIO_READ:
|
||||
return awk->readConsole (console, data, count);
|
||||
return awk->readConsole(console, (qse_char_t*)data, count);
|
||||
case QSE_AWK_RIO_WRITE:
|
||||
return awk->writeConsole (console, data, count);
|
||||
return awk->writeConsole(console, (const qse_char_t*)data, count);
|
||||
case QSE_AWK_RIO_WRITE_BYTES:
|
||||
return awk->writeConsoleBytes(console, (const qse_mchar_t*)data, count);
|
||||
|
||||
case QSE_AWK_RIO_FLUSH:
|
||||
return awk->flushConsole(console);
|
||||
|
@ -668,6 +668,13 @@ StdAwk::ssize_t StdAwk::writePipe (Pipe& io, const char_t* buf, size_t len)
|
||||
qse_pio_write((qse_pio_t*)io.getHandle(), QSE_PIO_IN, buf, len);
|
||||
}
|
||||
|
||||
StdAwk::ssize_t StdAwk::writePipeBytes (Pipe& io, const qse_mchar_t* buf, size_t len)
|
||||
{
|
||||
return (io.getUflags() > 0)?
|
||||
qse_nwio_writebytes((qse_nwio_t*)io.getHandle(), buf, len):
|
||||
qse_pio_writebytes((qse_pio_t*)io.getHandle(), QSE_PIO_IN, buf, len);
|
||||
}
|
||||
|
||||
int StdAwk::flushPipe (Pipe& io)
|
||||
{
|
||||
return (io.getUflags() > 0)?
|
||||
@ -724,6 +731,12 @@ StdAwk::ssize_t StdAwk::writeFile (File& io, const char_t* buf, size_t len)
|
||||
return qse_sio_putstrn((qse_sio_t*)io.getHandle(), buf, len);
|
||||
}
|
||||
|
||||
StdAwk::ssize_t StdAwk::writeFileBytes (File& io, const qse_mchar_t* buf, size_t len)
|
||||
{
|
||||
return qse_sio_putmbsn((qse_sio_t*)io.getHandle(), buf, len);
|
||||
}
|
||||
|
||||
|
||||
int StdAwk::flushFile (File& io)
|
||||
{
|
||||
return qse_sio_flush((qse_sio_t*)io.getHandle());
|
||||
@ -1050,11 +1063,12 @@ StdAwk::ssize_t StdAwk::readConsole (Console& io, char_t* data, size_t size)
|
||||
|
||||
StdAwk::ssize_t StdAwk::writeConsole (Console& io, const char_t* data, size_t size)
|
||||
{
|
||||
return qse_sio_putstrn (
|
||||
(qse_sio_t*)io.getHandle(),
|
||||
data,
|
||||
size
|
||||
);
|
||||
return qse_sio_putstrn((qse_sio_t*)io.getHandle(), data, size);
|
||||
}
|
||||
|
||||
StdAwk::ssize_t StdAwk::writeConsoleBytes (Console& io, const qse_mchar_t* data, size_t size)
|
||||
{
|
||||
return qse_sio_putmbsn((qse_sio_t*)io.getHandle(), data, size);
|
||||
}
|
||||
|
||||
int StdAwk::flushConsole (Console& io)
|
||||
|
@ -1332,10 +1332,9 @@ int qse_awk_fnc_sprintf (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi)
|
||||
cs0.ptr = qse_awk_rtx_getvalstr(rtx, a0, &cs0.len);
|
||||
if (cs0.ptr == QSE_NULL) goto oops;
|
||||
|
||||
x.ptr = qse_awk_rtx_format (rtx,
|
||||
&out, &fbu, cs0.ptr, cs0.len, nargs, QSE_NULL, &x.len);
|
||||
x.ptr = qse_awk_rtx_format(rtx, &out, &fbu, cs0.ptr, cs0.len, nargs, QSE_NULL, &x.len);
|
||||
qse_awk_rtx_freevalstr (rtx, a0, cs0.ptr);
|
||||
if (x.ptr == QSE_NULL) goto oops;
|
||||
if (!x.ptr) goto oops;
|
||||
|
||||
a0 = qse_awk_rtx_makestrvalwithxstr(rtx, &x);
|
||||
if (a0 == QSE_NULL) goto oops;
|
||||
|
@ -5692,8 +5692,10 @@ static int get_string (
|
||||
return -1;
|
||||
}
|
||||
|
||||
#if !defined(QSE_CHAR_IS_MCHAR)
|
||||
if (byte_only && c != '\\' && !QSE_AWK_BYTE_PRINTABLE(c))
|
||||
#if defined(QSE_CHAR_IS_MCHAR)
|
||||
/* nothing extra to handle byte_only */
|
||||
#else
|
||||
if (byte_only && c != QSE_T('\\') && !QSE_AWK_BYTE_PRINTABLE(c))
|
||||
{
|
||||
qse_char_t wc = c;
|
||||
SETERR_ARG_LOC (awk, QSE_AWK_EMBSCHR, &wc, 1, &awk->tok.loc);
|
||||
@ -5906,8 +5908,10 @@ static int get_single_quoted_string (qse_awk_t* awk, int byte_only, qse_awk_tok_
|
||||
return -1;
|
||||
}
|
||||
|
||||
#if !defined(QSE_CHAR_IS_MCHAR)
|
||||
if (byte_only && c != '\\' && !QSE_AWK_BYTE_PRINTABLE(c))
|
||||
#if defined(QSE_CHAR_IS_MCHAR)
|
||||
/* nothing extra to handle byte_only */
|
||||
#else
|
||||
if (byte_only && c != QSE_T('\\') && !QSE_AWK_BYTE_PRINTABLE(c))
|
||||
{
|
||||
qse_char_t wc = c;
|
||||
SETERR_ARG_LOC (awk, QSE_AWK_EMBSCHR, &wc, 1, &awk->tok.loc);
|
||||
@ -5915,7 +5919,6 @@ static int get_single_quoted_string (qse_awk_t* awk, int byte_only, qse_awk_tok_
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
if (c == QSE_T('\''))
|
||||
{
|
||||
/* terminating quote */
|
||||
@ -6249,9 +6252,7 @@ retry:
|
||||
ADD_TOKEN_CHAR (awk, tok, c);
|
||||
GET_CHAR_TO (awk, c);
|
||||
}
|
||||
while (c == QSE_T('_') ||
|
||||
QSE_AWK_ISALPHA(awk, c) ||
|
||||
QSE_AWK_ISDIGIT(awk, c));
|
||||
while (c == QSE_T('_') || QSE_AWK_ISALPHA(awk, c) || QSE_AWK_ISDIGIT(awk, c));
|
||||
|
||||
type = classify_ident(awk, QSE_STR_XSTR(tok->name));
|
||||
if (type == TOK_IDENT)
|
||||
@ -6261,22 +6262,23 @@ retry:
|
||||
}
|
||||
SET_TOKEN_TYPE (awk, tok, type);
|
||||
}
|
||||
else if (c == 'M')
|
||||
else if (c == QSE_T('B'))
|
||||
{
|
||||
GET_CHAR_TO (awk, c);
|
||||
if (c == '\"')
|
||||
if (c == QSE_T('\"'))
|
||||
{
|
||||
/* multi-byte string */
|
||||
/* multi-byte string/byte array */
|
||||
SET_TOKEN_TYPE (awk, tok, TOK_MBS);
|
||||
if (get_string(awk, c, QSE_T('\\'), 0, 1, 0, tok) <= -1) return -1;
|
||||
}
|
||||
else if (c == '\'')
|
||||
else if (c == QSE_T('\''))
|
||||
{
|
||||
SET_TOKEN_TYPE (awk, tok, TOK_MBS);
|
||||
if (get_single_quoted_string(awk, 1, tok) <= -1) return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
ADD_TOKEN_CHAR (awk, tok, QSE_T('B'));
|
||||
goto process_identifier;
|
||||
}
|
||||
}
|
||||
|
@ -196,8 +196,7 @@ static int find_rio_in (
|
||||
return 0;
|
||||
}
|
||||
|
||||
static QSE_INLINE int resolve_rs (
|
||||
qse_awk_rtx_t* rtx, qse_awk_val_t* rs, qse_cstr_t* rrs)
|
||||
static QSE_INLINE int resolve_rs (qse_awk_rtx_t* rtx, qse_awk_val_t* rs, qse_cstr_t* rrs)
|
||||
{
|
||||
int ret = 0;
|
||||
qse_awk_val_type_t rs_vtype;
|
||||
@ -226,8 +225,7 @@ static QSE_INLINE int resolve_rs (
|
||||
return ret;
|
||||
}
|
||||
|
||||
static QSE_INLINE int match_long_rs (
|
||||
qse_awk_rtx_t* run, qse_str_t* buf, qse_awk_rio_arg_t* p)
|
||||
static QSE_INLINE int match_long_rs (qse_awk_rtx_t* run, qse_str_t* buf, qse_awk_rio_arg_t* p)
|
||||
{
|
||||
qse_cstr_t match;
|
||||
qse_awk_errnum_t errnum;
|
||||
@ -295,9 +293,7 @@ static QSE_INLINE int match_long_rs (
|
||||
return ret;
|
||||
}
|
||||
|
||||
int qse_awk_rtx_readio (
|
||||
qse_awk_rtx_t* run, int in_type,
|
||||
const qse_char_t* name, qse_str_t* buf)
|
||||
int qse_awk_rtx_readio (qse_awk_rtx_t* run, int in_type, const qse_char_t* name, qse_str_t* buf)
|
||||
{
|
||||
qse_awk_rio_arg_t* p;
|
||||
qse_awk_rio_impl_t handler;
|
||||
@ -640,56 +636,45 @@ int qse_awk_rtx_readio (
|
||||
return ret;
|
||||
}
|
||||
|
||||
int qse_awk_rtx_writeio_val (
|
||||
qse_awk_rtx_t* run, int out_type,
|
||||
const qse_char_t* name, qse_awk_val_t* v)
|
||||
int qse_awk_rtx_writeioval (qse_awk_rtx_t* run, int out_type, const qse_char_t* name, qse_awk_val_t* v)
|
||||
{
|
||||
qse_char_t* str;
|
||||
qse_size_t len;
|
||||
int n;
|
||||
qse_awk_val_type_t vtype;
|
||||
|
||||
|
||||
vtype = QSE_AWK_RTX_GETVALTYPE (run, v);
|
||||
|
||||
if (vtype == QSE_AWK_VAL_STR)
|
||||
switch (vtype)
|
||||
{
|
||||
str = ((qse_awk_val_str_t*)v)->val.ptr;
|
||||
len = ((qse_awk_val_str_t*)v)->val.len;
|
||||
}
|
||||
else
|
||||
case QSE_AWK_VAL_STR:
|
||||
return qse_awk_rtx_writeiostr(run, out_type, name, ((qse_awk_val_str_t*)v)->val.ptr, ((qse_awk_val_str_t*)v)->val.len);
|
||||
|
||||
case QSE_AWK_VAL_MBS:
|
||||
return qse_awk_rtx_writeiobytes(run, out_type, name, ((qse_awk_val_mbs_t*)v)->val.ptr, ((qse_awk_val_mbs_t*)v)->val.len);
|
||||
|
||||
default:
|
||||
{
|
||||
qse_awk_rtx_valtostr_out_t out;
|
||||
int n;
|
||||
|
||||
out.type = QSE_AWK_RTX_VALTOSTR_CPLDUP |
|
||||
QSE_AWK_RTX_VALTOSTR_PRINT;
|
||||
out.type = QSE_AWK_RTX_VALTOSTR_CPLDUP | QSE_AWK_RTX_VALTOSTR_PRINT;
|
||||
if (qse_awk_rtx_valtostr(run, v, &out) <= -1) return -1;
|
||||
|
||||
str = out.u.cpldup.ptr;
|
||||
len = out.u.cpldup.len;
|
||||
}
|
||||
|
||||
n = qse_awk_rtx_writeio_str (run, out_type, name, str, len);
|
||||
|
||||
if (vtype == QSE_AWK_VAL_STR)
|
||||
{
|
||||
/* nothing to free */
|
||||
}
|
||||
else
|
||||
{
|
||||
QSE_AWK_FREE (run->awk, str);
|
||||
}
|
||||
n = qse_awk_rtx_writeiostr(run, out_type, name, out.u.cpldup.ptr, out.u.cpldup.len);
|
||||
QSE_AWK_FREE (run->awk, out.u.cpldup.ptr);
|
||||
return n;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int qse_awk_rtx_writeio_str (
|
||||
qse_awk_rtx_t* run, int out_type,
|
||||
const qse_char_t* name, qse_char_t* str, qse_size_t len)
|
||||
struct write_io_data_t
|
||||
{
|
||||
qse_awk_rio_arg_t* p = run->rio.chain;
|
||||
qse_awk_rio_arg_t* p;
|
||||
qse_awk_rio_impl_t handler;
|
||||
int io_type, io_mode, io_mask;
|
||||
qse_ssize_t n;
|
||||
};
|
||||
typedef struct write_io_data_t write_io_data_t;
|
||||
|
||||
static int prepare_for_write_io_data (qse_awk_rtx_t* rtx, int out_type, const qse_char_t* name, write_io_data_t* wid)
|
||||
{
|
||||
qse_awk_rio_arg_t* p = rtx->rio.chain;
|
||||
qse_awk_rio_impl_t handler;
|
||||
int io_type, io_mode, io_mask, n;
|
||||
|
||||
QSE_ASSERT (out_type >= 0 && out_type <= QSE_COUNTOF(out_type_map));
|
||||
QSE_ASSERT (out_type >= 0 && out_type <= QSE_COUNTOF(out_mode_map));
|
||||
@ -700,11 +685,11 @@ int qse_awk_rtx_writeio_str (
|
||||
io_mode = out_mode_map[out_type];
|
||||
io_mask = out_mask_map[out_type];
|
||||
|
||||
handler = run->rio.handler[io_type];
|
||||
handler = rtx->rio.handler[io_type];
|
||||
if (handler == QSE_NULL)
|
||||
{
|
||||
/* no I/O handler provided */
|
||||
qse_awk_rtx_seterrnum (run, QSE_AWK_EIOUSER, QSE_NULL);
|
||||
qse_awk_rtx_seterrnum (rtx, QSE_AWK_EIOUSER, QSE_NULL);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -721,29 +706,27 @@ int qse_awk_rtx_writeio_str (
|
||||
* print "1111" >> "1.tmp"
|
||||
* print "1111" > "1.tmp"
|
||||
*/
|
||||
if (p->type == (io_type | io_mask) &&
|
||||
qse_strcmp (p->name, name) == 0) break;
|
||||
if (p->type == (io_type | io_mask) && qse_strcmp(p->name, name) == 0) break;
|
||||
p = p->next;
|
||||
}
|
||||
|
||||
/* if there is not corresponding rio for name, create one */
|
||||
if (p == QSE_NULL)
|
||||
{
|
||||
p = (qse_awk_rio_arg_t*) QSE_AWK_ALLOC (
|
||||
run->awk, QSE_SIZEOF(qse_awk_rio_arg_t));
|
||||
p = (qse_awk_rio_arg_t*)QSE_AWK_ALLOC(rtx->awk, QSE_SIZEOF(qse_awk_rio_arg_t));
|
||||
if (p == QSE_NULL)
|
||||
{
|
||||
qse_awk_rtx_seterrnum (run, QSE_AWK_ENOMEM, QSE_NULL);
|
||||
qse_awk_rtx_seterrnum (rtx, QSE_AWK_ENOMEM, QSE_NULL);
|
||||
return -1;
|
||||
}
|
||||
|
||||
QSE_MEMSET (p, 0, QSE_SIZEOF(*p));
|
||||
|
||||
p->name = QSE_AWK_STRDUP (run->awk, name);
|
||||
p->name = QSE_AWK_STRDUP(rtx->awk, name);
|
||||
if (p->name == QSE_NULL)
|
||||
{
|
||||
QSE_AWK_FREE (run->awk, p);
|
||||
qse_awk_rtx_seterrnum (run, QSE_AWK_ENOMEM, QSE_NULL);
|
||||
QSE_AWK_FREE (rtx->awk, p);
|
||||
qse_awk_rtx_seterrnum (rtx, QSE_AWK_ENOMEM, QSE_NULL);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -759,52 +742,55 @@ int qse_awk_rtx_writeio_str (
|
||||
p->out.eos = 0;
|
||||
*/
|
||||
|
||||
qse_awk_rtx_seterrnum (run, QSE_AWK_ENOERR, QSE_NULL);
|
||||
n = handler (run, QSE_AWK_RIO_OPEN, p, QSE_NULL, 0);
|
||||
qse_awk_rtx_seterrnum (rtx, QSE_AWK_ENOERR, QSE_NULL);
|
||||
n = handler(rtx, QSE_AWK_RIO_OPEN, p, QSE_NULL, 0);
|
||||
if (n <= -1)
|
||||
{
|
||||
QSE_AWK_FREE (run->awk, p->name);
|
||||
QSE_AWK_FREE (run->awk, p);
|
||||
QSE_AWK_FREE (rtx->awk, p->name);
|
||||
QSE_AWK_FREE (rtx->awk, p);
|
||||
|
||||
if (run->errinf.num == QSE_AWK_ENOERR)
|
||||
qse_awk_rtx_seterrnum (run, QSE_AWK_EIOIMPL, QSE_NULL);
|
||||
if (rtx->errinf.num == QSE_AWK_ENOERR)
|
||||
qse_awk_rtx_seterrnum (rtx, QSE_AWK_EIOIMPL, QSE_NULL);
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* chain it */
|
||||
p->next = run->rio.chain;
|
||||
run->rio.chain = p;
|
||||
p->next = rtx->rio.chain;
|
||||
rtx->rio.chain = p;
|
||||
}
|
||||
|
||||
if (p->out.eos)
|
||||
{
|
||||
/* no more streams */
|
||||
return 0;
|
||||
if (p->out.eos) return 0; /* no more streams */
|
||||
if (p->out.eof) return 0; /* it has reached the end of the stream but this function has been recalled */
|
||||
|
||||
wid->handler = handler;
|
||||
wid->p = p;
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (p->out.eof)
|
||||
int qse_awk_rtx_writeiostr (qse_awk_rtx_t* rtx, int out_type, const qse_char_t* name, qse_char_t* str, qse_size_t len)
|
||||
{
|
||||
/* it has reached the end of the stream but this function
|
||||
* has been recalled */
|
||||
return 0;
|
||||
}
|
||||
int x;
|
||||
write_io_data_t wid;
|
||||
|
||||
if ((x = prepare_for_write_io_data(rtx, out_type, name, &wid)) <= 0) return x;
|
||||
|
||||
while (len > 0)
|
||||
{
|
||||
qse_awk_rtx_seterrnum (run, QSE_AWK_ENOERR, QSE_NULL);
|
||||
n = handler (run, QSE_AWK_RIO_WRITE, p, str, len);
|
||||
qse_ssize_t n;
|
||||
|
||||
qse_awk_rtx_seterrnum (rtx, QSE_AWK_ENOERR, QSE_NULL);
|
||||
n = wid.handler(rtx, QSE_AWK_RIO_WRITE, wid.p, str, len);
|
||||
if (n <= -1)
|
||||
{
|
||||
if (run->errinf.num == QSE_AWK_ENOERR)
|
||||
qse_awk_rtx_seterrnum (run, QSE_AWK_EIOIMPL, QSE_NULL);
|
||||
|
||||
if (rtx->errinf.num == QSE_AWK_ENOERR)
|
||||
qse_awk_rtx_seterrnum (rtx, QSE_AWK_EIOIMPL, QSE_NULL);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (n == 0)
|
||||
{
|
||||
p->out.eof = 1;
|
||||
wid.p->out.eof = 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -815,8 +801,40 @@ int qse_awk_rtx_writeio_str (
|
||||
return 1;
|
||||
}
|
||||
|
||||
int qse_awk_rtx_flushio (
|
||||
qse_awk_rtx_t* run, int out_type, const qse_char_t* name)
|
||||
int qse_awk_rtx_writeiobytes (qse_awk_rtx_t* rtx, int out_type, const qse_char_t* name, qse_mchar_t* str, qse_size_t len)
|
||||
{
|
||||
int x;
|
||||
write_io_data_t wid;
|
||||
|
||||
if ((x = prepare_for_write_io_data(rtx, out_type, name, &wid)) <= 0) return x;
|
||||
|
||||
while (len > 0)
|
||||
{
|
||||
qse_ssize_t n;
|
||||
|
||||
qse_awk_rtx_seterrnum (rtx, QSE_AWK_ENOERR, QSE_NULL);
|
||||
n = wid.handler(rtx, QSE_AWK_RIO_WRITE_BYTES, wid.p, str, len);
|
||||
if (n <= -1)
|
||||
{
|
||||
if (rtx->errinf.num == QSE_AWK_ENOERR)
|
||||
qse_awk_rtx_seterrnum (rtx, QSE_AWK_EIOIMPL, QSE_NULL);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (n == 0)
|
||||
{
|
||||
wid.p->out.eof = 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
len -= n;
|
||||
str += n;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int qse_awk_rtx_flushio (qse_awk_rtx_t* run, int out_type, const qse_char_t* name)
|
||||
{
|
||||
qse_awk_rio_arg_t* p = run->rio.chain;
|
||||
qse_awk_rio_impl_t handler;
|
||||
|
@ -35,14 +35,18 @@ int qse_awk_rtx_readio (
|
||||
qse_awk_rtx_t* run, int in_type,
|
||||
const qse_char_t* name, qse_str_t* buf);
|
||||
|
||||
int qse_awk_rtx_writeio_val (
|
||||
int qse_awk_rtx_writeioval (
|
||||
qse_awk_rtx_t* run, int out_type,
|
||||
const qse_char_t* name, qse_awk_val_t* v);
|
||||
|
||||
int qse_awk_rtx_writeio_str (
|
||||
int qse_awk_rtx_writeiostr (
|
||||
qse_awk_rtx_t* run, int out_type,
|
||||
const qse_char_t* name, qse_char_t* str, qse_size_t len);
|
||||
|
||||
int qse_awk_rtx_writeiobytes (
|
||||
qse_awk_rtx_t* run, int out_type,
|
||||
const qse_char_t* name, qse_mchar_t* str, qse_size_t len);
|
||||
|
||||
int qse_awk_rtx_flushio (
|
||||
qse_awk_rtx_t* run, int out_type, const qse_char_t* name);
|
||||
|
||||
|
@ -1884,7 +1884,7 @@ static int run_block0 (qse_awk_rtx_t* rtx, qse_awk_nde_blk_t* nde)
|
||||
/* blockless pattern - execute print $0*/
|
||||
qse_awk_rtx_refupval (rtx, rtx->inrec.d0);
|
||||
|
||||
n = qse_awk_rtx_writeio_str (rtx,
|
||||
n = qse_awk_rtx_writeiostr (rtx,
|
||||
QSE_AWK_OUT_CONSOLE, QSE_T(""),
|
||||
QSE_STR_PTR(&rtx->inrec.line),
|
||||
QSE_STR_LEN(&rtx->inrec.line));
|
||||
@ -1895,7 +1895,7 @@ static int run_block0 (qse_awk_rtx_t* rtx, qse_awk_nde_blk_t* nde)
|
||||
return -1;
|
||||
}
|
||||
|
||||
n = qse_awk_rtx_writeio_str (
|
||||
n = qse_awk_rtx_writeiostr (
|
||||
rtx, QSE_AWK_OUT_CONSOLE, QSE_T(""),
|
||||
rtx->gbl.ors.ptr, rtx->gbl.ors.len);
|
||||
if (n == -1)
|
||||
@ -2935,10 +2935,7 @@ static int run_print (qse_awk_rtx_t* rtx, qse_awk_nde_print_t* nde)
|
||||
{
|
||||
/* if it doesn't have any arguments, print the entire
|
||||
* input record */
|
||||
n = qse_awk_rtx_writeio_str (
|
||||
rtx, nde->out_type, dst,
|
||||
QSE_STR_PTR(&rtx->inrec.line),
|
||||
QSE_STR_LEN(&rtx->inrec.line));
|
||||
n = qse_awk_rtx_writeiostr(rtx, nde->out_type, dst, QSE_STR_PTR(&rtx->inrec.line), QSE_STR_LEN(&rtx->inrec.line));
|
||||
if (n <= -1 /*&& rtx->errinf.num != QSE_AWK_EIOIMPL*/)
|
||||
{
|
||||
if (rtx->awk->opt.trait & QSE_AWK_TOLERANT)
|
||||
@ -2970,10 +2967,7 @@ static int run_print (qse_awk_rtx_t* rtx, qse_awk_nde_print_t* nde)
|
||||
{
|
||||
if (np != head)
|
||||
{
|
||||
n = qse_awk_rtx_writeio_str (
|
||||
rtx, nde->out_type, dst,
|
||||
rtx->gbl.ofs.ptr,
|
||||
rtx->gbl.ofs.len);
|
||||
n = qse_awk_rtx_writeiostr(rtx, nde->out_type, dst, rtx->gbl.ofs.ptr, rtx->gbl.ofs.len);
|
||||
if (n <= -1 /*&& rtx->errinf.num != QSE_AWK_EIOIMPL*/)
|
||||
{
|
||||
if (rtx->awk->opt.trait & QSE_AWK_TOLERANT)
|
||||
@ -2991,7 +2985,7 @@ static int run_print (qse_awk_rtx_t* rtx, qse_awk_nde_print_t* nde)
|
||||
if (v == QSE_NULL) goto oops_1;
|
||||
|
||||
qse_awk_rtx_refupval (rtx, v);
|
||||
n = qse_awk_rtx_writeio_val (rtx, nde->out_type, dst, v);
|
||||
n = qse_awk_rtx_writeioval(rtx, nde->out_type, dst, v);
|
||||
qse_awk_rtx_refdownval (rtx, v);
|
||||
|
||||
if (n <= -1 /*&& rtx->errinf.num != QSE_AWK_EIOIMPL*/)
|
||||
@ -3009,9 +3003,7 @@ static int run_print (qse_awk_rtx_t* rtx, qse_awk_nde_print_t* nde)
|
||||
}
|
||||
|
||||
/* print the value ORS to terminate the operation */
|
||||
n = qse_awk_rtx_writeio_str (
|
||||
rtx, nde->out_type, dst,
|
||||
rtx->gbl.ors.ptr, rtx->gbl.ors.len);
|
||||
n = qse_awk_rtx_writeiostr(rtx, nde->out_type, dst, rtx->gbl.ors.ptr, rtx->gbl.ors.len);
|
||||
if (n <= -1 /*&& rtx->errinf.num != QSE_AWK_EIOIMPL*/)
|
||||
{
|
||||
if (rtx->awk->opt.trait & QSE_AWK_TOLERANT)
|
||||
@ -3124,7 +3116,7 @@ static int run_printf (qse_awk_rtx_t* rtx, qse_awk_nde_print_t* nde)
|
||||
{
|
||||
/* the remaining arguments are ignored as the format cannot
|
||||
* contain any % characters. e.g. printf (1, "xxxx") */
|
||||
n = qse_awk_rtx_writeio_val (rtx, nde->out_type, dst, v);
|
||||
n = qse_awk_rtx_writeioval(rtx, nde->out_type, dst, v);
|
||||
qse_awk_rtx_refdownval (rtx, v);
|
||||
|
||||
if (n <= -1 /*&& rtx->errinf.num != QSE_AWK_EIOIMPL*/)
|
||||
@ -3186,11 +3178,10 @@ static int output_formatted (
|
||||
qse_size_t len;
|
||||
int n;
|
||||
|
||||
ptr = qse_awk_rtx_format (
|
||||
rtx, QSE_NULL, QSE_NULL, fmt, fmt_len, 0, args, &len);
|
||||
ptr = qse_awk_rtx_format(rtx, QSE_NULL, QSE_NULL, fmt, fmt_len, 0, args, &len);
|
||||
if (ptr == QSE_NULL) return -1;
|
||||
|
||||
n = qse_awk_rtx_writeio_str (rtx, out_type, dst, ptr, len);
|
||||
n = qse_awk_rtx_writeiostr(rtx, out_type, dst, ptr, len);
|
||||
if (n <= -1 /*&& rtx->errinf.num != QSE_AWK_EIOIMPL*/)
|
||||
{
|
||||
if (rtx->awk->opt.trait & QSE_AWK_TOLERANT)
|
||||
|
@ -987,7 +987,6 @@ static qse_ssize_t sf_out (
|
||||
ea.len = qse_strlen(ea.ptr);
|
||||
qse_awk_seterrnum (awk, QSE_AWK_EWRITE, &ea);
|
||||
}
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
@ -1015,8 +1014,7 @@ static qse_ssize_t sf_out (
|
||||
return -1;
|
||||
}
|
||||
|
||||
int qse_awk_parsestd (
|
||||
qse_awk_t* awk, qse_awk_parsestd_t in[], qse_awk_parsestd_t* out)
|
||||
int qse_awk_parsestd (qse_awk_t* awk, qse_awk_parsestd_t in[], qse_awk_parsestd_t* out)
|
||||
{
|
||||
qse_awk_sio_t sio;
|
||||
xtn_t* xtn = (xtn_t*) QSE_XTN (awk);
|
||||
@ -1064,9 +1062,7 @@ int qse_awk_parsestd (
|
||||
|
||||
/*** RTX_OPENSTD ***/
|
||||
|
||||
static qse_ssize_t nwio_handler_open (
|
||||
qse_awk_rtx_t* rtx, qse_awk_rio_arg_t* riod, int flags,
|
||||
qse_nwad_t* nwad, qse_nwio_tmout_t* tmout)
|
||||
static qse_ssize_t nwio_handler_open (qse_awk_rtx_t* rtx, qse_awk_rio_arg_t* riod, int flags, qse_nwad_t* nwad, qse_nwio_tmout_t* tmout)
|
||||
{
|
||||
qse_nwio_t* handle;
|
||||
|
||||
@ -1090,39 +1086,30 @@ static qse_ssize_t nwio_handler_open (
|
||||
return 1;
|
||||
}
|
||||
|
||||
static qse_ssize_t nwio_handler_rest (
|
||||
qse_awk_rtx_t* rtx, qse_awk_rio_cmd_t cmd, qse_awk_rio_arg_t* riod,
|
||||
qse_char_t* data, qse_size_t size)
|
||||
static qse_ssize_t nwio_handler_rest (qse_awk_rtx_t* rtx, qse_awk_rio_cmd_t cmd, qse_awk_rio_arg_t* riod, void* data, qse_size_t size)
|
||||
{
|
||||
switch (cmd)
|
||||
{
|
||||
case QSE_AWK_RIO_OPEN:
|
||||
{
|
||||
qse_awk_rtx_seterrnum (rtx, QSE_AWK_EINTERN, QSE_NULL);
|
||||
return -1;
|
||||
}
|
||||
|
||||
case QSE_AWK_RIO_CLOSE:
|
||||
{
|
||||
qse_nwio_close ((qse_nwio_t*)riod->handle);
|
||||
return 0;
|
||||
}
|
||||
|
||||
case QSE_AWK_RIO_READ:
|
||||
{
|
||||
return qse_nwio_read((qse_nwio_t*)riod->handle, data, size);
|
||||
}
|
||||
|
||||
case QSE_AWK_RIO_WRITE:
|
||||
{
|
||||
return qse_nwio_write((qse_nwio_t*)riod->handle, data, size);
|
||||
}
|
||||
|
||||
case QSE_AWK_RIO_WRITE_BYTES:
|
||||
return qse_nwio_writebytes((qse_nwio_t*)riod->handle, data, size);
|
||||
|
||||
case QSE_AWK_RIO_FLUSH:
|
||||
{
|
||||
/*if (riod->mode == QSE_AWK_RIO_PIPE_READ) return -1;*/
|
||||
return qse_nwio_flush((qse_nwio_t*)riod->handle);
|
||||
}
|
||||
|
||||
case QSE_AWK_RIO_NEXT:
|
||||
break;
|
||||
@ -1162,8 +1149,7 @@ static int parse_rwpipe_uri (const qse_char_t* uri, int* flags, qse_nwad_t* nwad
|
||||
return -1;
|
||||
}
|
||||
|
||||
static qse_ssize_t pio_handler_open (
|
||||
qse_awk_rtx_t* rtx, qse_awk_rio_arg_t* riod)
|
||||
static qse_ssize_t pio_handler_open (qse_awk_rtx_t* rtx, qse_awk_rio_arg_t* riod)
|
||||
{
|
||||
qse_pio_t* handle;
|
||||
int flags;
|
||||
@ -1171,8 +1157,7 @@ static qse_ssize_t pio_handler_open (
|
||||
if (riod->mode == QSE_AWK_RIO_PIPE_READ)
|
||||
{
|
||||
/* TODO: should ERRTOOUT be unset? */
|
||||
flags = QSE_PIO_READOUT |
|
||||
QSE_PIO_ERRTOOUT;
|
||||
flags = QSE_PIO_READOUT | QSE_PIO_ERRTOOUT;
|
||||
}
|
||||
else if (riod->mode == QSE_AWK_RIO_PIPE_WRITE)
|
||||
{
|
||||
@ -1180,9 +1165,7 @@ static qse_ssize_t pio_handler_open (
|
||||
}
|
||||
else if (riod->mode == QSE_AWK_RIO_PIPE_RW)
|
||||
{
|
||||
flags = QSE_PIO_READOUT |
|
||||
QSE_PIO_ERRTOOUT |
|
||||
QSE_PIO_WRITEIN;
|
||||
flags = QSE_PIO_READOUT | QSE_PIO_ERRTOOUT | QSE_PIO_WRITEIN;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -1217,17 +1200,13 @@ static qse_ssize_t pio_handler_open (
|
||||
return 1;
|
||||
}
|
||||
|
||||
static qse_ssize_t pio_handler_rest (
|
||||
qse_awk_rtx_t* rtx, qse_awk_rio_cmd_t cmd, qse_awk_rio_arg_t* riod,
|
||||
qse_char_t* data, qse_size_t size)
|
||||
static qse_ssize_t pio_handler_rest (qse_awk_rtx_t* rtx, qse_awk_rio_cmd_t cmd, qse_awk_rio_arg_t* riod, void* data, qse_size_t size)
|
||||
{
|
||||
switch (cmd)
|
||||
{
|
||||
case QSE_AWK_RIO_OPEN:
|
||||
{
|
||||
qse_awk_rtx_seterrnum (rtx, QSE_AWK_EINTERN, QSE_NULL);
|
||||
return -1;
|
||||
}
|
||||
|
||||
case QSE_AWK_RIO_CLOSE:
|
||||
{
|
||||
@ -1254,26 +1233,17 @@ static qse_ssize_t pio_handler_rest (
|
||||
}
|
||||
|
||||
case QSE_AWK_RIO_READ:
|
||||
{
|
||||
return qse_pio_read (
|
||||
(qse_pio_t*)riod->handle,
|
||||
QSE_PIO_OUT, data, size
|
||||
);
|
||||
}
|
||||
return qse_pio_read ((qse_pio_t*)riod->handle, QSE_PIO_OUT, data, size);
|
||||
|
||||
case QSE_AWK_RIO_WRITE:
|
||||
{
|
||||
return qse_pio_write (
|
||||
(qse_pio_t*)riod->handle,
|
||||
QSE_PIO_IN, data, size
|
||||
);
|
||||
}
|
||||
return qse_pio_write((qse_pio_t*)riod->handle, QSE_PIO_IN, data, size);
|
||||
|
||||
case QSE_AWK_RIO_WRITE_BYTES:
|
||||
return qse_pio_writebytes((qse_pio_t*)riod->handle, QSE_PIO_IN, data, size);
|
||||
|
||||
case QSE_AWK_RIO_FLUSH:
|
||||
{
|
||||
/*if (riod->mode == QSE_AWK_RIO_PIPE_READ) return -1;*/
|
||||
return qse_pio_flush ((qse_pio_t*)riod->handle, QSE_PIO_IN);
|
||||
}
|
||||
|
||||
case QSE_AWK_RIO_NEXT:
|
||||
break;
|
||||
@ -1283,9 +1253,7 @@ static qse_ssize_t pio_handler_rest (
|
||||
return -1;
|
||||
}
|
||||
|
||||
static qse_ssize_t awk_rio_pipe (
|
||||
qse_awk_rtx_t* rtx, qse_awk_rio_cmd_t cmd, qse_awk_rio_arg_t* riod,
|
||||
qse_char_t* data, qse_size_t size)
|
||||
static qse_ssize_t awk_rio_pipe (qse_awk_rtx_t* rtx, qse_awk_rio_cmd_t cmd, qse_awk_rio_arg_t* riod, void* data, qse_size_t size)
|
||||
{
|
||||
if (cmd == QSE_AWK_RIO_OPEN)
|
||||
{
|
||||
@ -1325,9 +1293,7 @@ static qse_ssize_t awk_rio_pipe (
|
||||
return pio_handler_rest(rtx, cmd, riod, data, size);
|
||||
}
|
||||
|
||||
static qse_ssize_t awk_rio_file (
|
||||
qse_awk_rtx_t* rtx, qse_awk_rio_cmd_t cmd, qse_awk_rio_arg_t* riod,
|
||||
qse_char_t* data, qse_size_t size)
|
||||
static qse_ssize_t awk_rio_file (qse_awk_rtx_t* rtx, qse_awk_rio_cmd_t cmd, qse_awk_rio_arg_t* riod, void* data, qse_size_t size)
|
||||
{
|
||||
switch (cmd)
|
||||
{
|
||||
@ -1342,13 +1308,10 @@ static qse_ssize_t awk_rio_file (
|
||||
flags |= QSE_SIO_READ;
|
||||
break;
|
||||
case QSE_AWK_RIO_FILE_WRITE:
|
||||
flags |= QSE_SIO_WRITE |
|
||||
QSE_SIO_CREATE |
|
||||
QSE_SIO_TRUNCATE;
|
||||
flags |= QSE_SIO_WRITE | QSE_SIO_CREATE | QSE_SIO_TRUNCATE;
|
||||
break;
|
||||
case QSE_AWK_RIO_FILE_APPEND:
|
||||
flags |= QSE_SIO_APPEND |
|
||||
QSE_SIO_CREATE;
|
||||
flags |= QSE_SIO_APPEND | QSE_SIO_CREATE;
|
||||
break;
|
||||
default:
|
||||
/* this must not happen */
|
||||
@ -1378,42 +1341,26 @@ static qse_ssize_t awk_rio_file (
|
||||
}
|
||||
|
||||
case QSE_AWK_RIO_CLOSE:
|
||||
{
|
||||
qse_sio_close ((qse_sio_t*)riod->handle);
|
||||
riod->handle = QSE_NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
case QSE_AWK_RIO_READ:
|
||||
{
|
||||
return qse_sio_getstrn (
|
||||
(qse_sio_t*)riod->handle,
|
||||
data,
|
||||
size
|
||||
);
|
||||
}
|
||||
return qse_sio_getstrn((qse_sio_t*)riod->handle, data, size);
|
||||
|
||||
case QSE_AWK_RIO_WRITE:
|
||||
{
|
||||
return qse_sio_putstrn (
|
||||
(qse_sio_t*)riod->handle,
|
||||
data,
|
||||
size
|
||||
);
|
||||
}
|
||||
return qse_sio_putstrn((qse_sio_t*)riod->handle, data, size);
|
||||
|
||||
case QSE_AWK_RIO_WRITE_BYTES:
|
||||
return qse_sio_putmbsn((qse_sio_t*)riod->handle, data, size);
|
||||
|
||||
case QSE_AWK_RIO_FLUSH:
|
||||
{
|
||||
return qse_sio_flush((qse_sio_t*)riod->handle);
|
||||
}
|
||||
|
||||
case QSE_AWK_RIO_NEXT:
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -1646,9 +1593,7 @@ static int open_rio_console (qse_awk_rtx_t* rtx, qse_awk_rio_arg_t* riod)
|
||||
return -1;
|
||||
}
|
||||
|
||||
static qse_ssize_t awk_rio_console (
|
||||
qse_awk_rtx_t* rtx, qse_awk_rio_cmd_t cmd, qse_awk_rio_arg_t* riod,
|
||||
qse_char_t* data, qse_size_t size)
|
||||
static qse_ssize_t awk_rio_console (qse_awk_rtx_t* rtx, qse_awk_rio_cmd_t cmd, qse_awk_rio_arg_t* riod, void* data, qse_size_t size)
|
||||
{
|
||||
switch (cmd)
|
||||
{
|
||||
@ -1684,11 +1629,10 @@ static qse_ssize_t awk_rio_console (
|
||||
}
|
||||
|
||||
case QSE_AWK_RIO_WRITE:
|
||||
return qse_sio_putstrn (
|
||||
(qse_sio_t*)riod->handle,
|
||||
data,
|
||||
size
|
||||
);
|
||||
return qse_sio_putstrn((qse_sio_t*)riod->handle, data, size);
|
||||
|
||||
case QSE_AWK_RIO_WRITE_BYTES:
|
||||
return qse_sio_putmbsn((qse_sio_t*)riod->handle, data, size);
|
||||
|
||||
case QSE_AWK_RIO_FLUSH:
|
||||
return qse_sio_flush((qse_sio_t*)riod->handle);
|
||||
|
@ -422,7 +422,7 @@ static int print_expr (qse_awk_t* awk, qse_awk_nde_t* nde)
|
||||
qse_mchar_t* ptr;
|
||||
qse_size_t len, i;
|
||||
|
||||
PUT_SRCSTR (awk, QSE_T("M\""));
|
||||
PUT_SRCSTR (awk, QSE_T("B\""));
|
||||
ptr = ((qse_awk_nde_mbs_t*)nde)->ptr;
|
||||
len = ((qse_awk_nde_mbs_t*)nde)->len;
|
||||
for (i = 0; i < len; i++)
|
||||
|
@ -1303,8 +1303,7 @@ static int val_flt_to_str (qse_awk_rtx_t* rtx, const qse_awk_val_flt_t* v, qse_a
|
||||
}
|
||||
fbu_inited = 1;
|
||||
|
||||
tmp = qse_awk_rtx_format(rtx, &buf, &fbu, tmp, tmp_len,
|
||||
(qse_size_t)-1, (qse_awk_nde_t*)v, &tmp_len);
|
||||
tmp = qse_awk_rtx_format(rtx, &buf, &fbu, tmp, tmp_len, (qse_size_t)-1, (qse_awk_nde_t*)v, &tmp_len);
|
||||
if (tmp == QSE_NULL) goto oops;
|
||||
|
||||
switch (type)
|
||||
|
@ -1614,6 +1614,16 @@ qse_ssize_t qse_nwio_write (qse_nwio_t* nwio, const void* data, qse_size_t size)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
qse_ssize_t qse_nwio_writebytes (qse_nwio_t* nwio, const void* data, qse_size_t size)
|
||||
{
|
||||
if (nwio->tio == QSE_NULL)
|
||||
return nwio_write(nwio, data, size);
|
||||
else
|
||||
return qse_tio_writembs(nwio->tio, data, size);
|
||||
}
|
||||
|
||||
|
||||
/* ---------------------------------------------------------- */
|
||||
|
||||
static qse_ssize_t socket_input (
|
||||
|
@ -131,8 +131,7 @@ static void free_param (qse_pio_t* pio, param_t* param)
|
||||
if (param->mcmd) QSE_MMGR_FREE (pio->mmgr, param->mcmd);
|
||||
}
|
||||
|
||||
static int make_param (
|
||||
qse_pio_t* pio, const qse_char_t* cmd, int flags, param_t* param)
|
||||
static int make_param (qse_pio_t* pio, const qse_char_t* cmd, int flags, param_t* param)
|
||||
{
|
||||
#if defined(QSE_CHAR_IS_MCHAR)
|
||||
qse_mchar_t* mcmd = QSE_NULL;
|
||||
@ -1876,8 +1875,7 @@ qse_pio_pid_t qse_pio_getchild (const qse_pio_t* pio)
|
||||
return pio->child;
|
||||
}
|
||||
|
||||
static qse_ssize_t pio_read (
|
||||
qse_pio_t* pio, void* buf, qse_size_t size, qse_pio_hnd_t hnd)
|
||||
static qse_ssize_t pio_read (qse_pio_t* pio, void* buf, qse_size_t size, qse_pio_hnd_t hnd)
|
||||
{
|
||||
#if defined(_WIN32)
|
||||
DWORD count;
|
||||
@ -1961,8 +1959,7 @@ reread:
|
||||
#endif
|
||||
}
|
||||
|
||||
qse_ssize_t qse_pio_read (
|
||||
qse_pio_t* pio, qse_pio_hid_t hid, void* buf, qse_size_t size)
|
||||
qse_ssize_t qse_pio_read (qse_pio_t* pio, qse_pio_hid_t hid, void* buf, qse_size_t size)
|
||||
{
|
||||
if (pio->pin[hid].tio == QSE_NULL)
|
||||
return pio_read(pio, buf, size, pio->pin[hid].handle);
|
||||
@ -1979,8 +1976,7 @@ qse_ssize_t qse_pio_read (
|
||||
}
|
||||
}
|
||||
|
||||
static qse_ssize_t pio_write (
|
||||
qse_pio_t* pio, const void* data, qse_size_t size, qse_pio_hnd_t hnd)
|
||||
static qse_ssize_t pio_write (qse_pio_t* pio, const void* data, qse_size_t size, qse_pio_hnd_t hnd)
|
||||
{
|
||||
#if defined(_WIN32)
|
||||
DWORD count;
|
||||
@ -2059,9 +2055,7 @@ rewrite:
|
||||
#endif
|
||||
}
|
||||
|
||||
qse_ssize_t qse_pio_write (
|
||||
qse_pio_t* pio, qse_pio_hid_t hid,
|
||||
const void* data, qse_size_t size)
|
||||
qse_ssize_t qse_pio_write (qse_pio_t* pio, qse_pio_hid_t hid, const void* data, qse_size_t size)
|
||||
{
|
||||
if (pio->pin[hid].tio == QSE_NULL)
|
||||
return pio_write(pio, data, size, pio->pin[hid].handle);
|
||||
@ -2078,6 +2072,14 @@ qse_ssize_t qse_pio_write (
|
||||
}
|
||||
}
|
||||
|
||||
qse_ssize_t qse_pio_writebytes (qse_pio_t* pio, qse_pio_hid_t hid, const void* data, qse_size_t size)
|
||||
{
|
||||
if (pio->pin[hid].tio == QSE_NULL)
|
||||
return pio_write(pio, data, size, pio->pin[hid].handle);
|
||||
else
|
||||
return qse_tio_writembs(pio->pin[hid].tio, data, size);
|
||||
}
|
||||
|
||||
qse_ssize_t qse_pio_flush (qse_pio_t* pio, qse_pio_hid_t hid)
|
||||
{
|
||||
qse_ssize_t n;
|
||||
@ -2346,8 +2348,7 @@ int qse_pio_kill (qse_pio_t* pio)
|
||||
#endif
|
||||
}
|
||||
|
||||
static qse_ssize_t pio_input (
|
||||
qse_tio_t* tio, qse_tio_cmd_t cmd, void* buf, qse_size_t size)
|
||||
static qse_ssize_t pio_input (qse_tio_t* tio, qse_tio_cmd_t cmd, void* buf, qse_size_t size)
|
||||
{
|
||||
if (cmd == QSE_TIO_DATA)
|
||||
{
|
||||
@ -2363,8 +2364,7 @@ static qse_ssize_t pio_input (
|
||||
return 0;
|
||||
}
|
||||
|
||||
static qse_ssize_t pio_output (
|
||||
qse_tio_t* tio, qse_tio_cmd_t cmd, void* buf, qse_size_t size)
|
||||
static qse_ssize_t pio_output (qse_tio_t* tio, qse_tio_cmd_t cmd, void* buf, qse_size_t size)
|
||||
{
|
||||
if (cmd == QSE_TIO_DATA)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user