fixed Hawk and HawkStd for byte reading

This commit is contained in:
hyung-hwan 2020-01-17 06:25:51 +00:00
parent 102a773bed
commit 851d485499
4 changed files with 129 additions and 28 deletions

View File

@ -2384,11 +2384,16 @@ hawk_ooi_t Hawk::pipeHandler (hawk_rtx_t* rtx, hawk_rio_cmd_t cmd, hawk_rio_arg_
{
case HAWK_RIO_CMD_OPEN:
return awk->pipe_handler->open(pipe);
case HAWK_RIO_CMD_CLOSE:
return awk->pipe_handler->close(pipe);
case HAWK_RIO_CMD_READ:
return awk->pipe_handler->read(pipe, (hawk_ooch_t*)data, count);
case HAWK_RIO_CMD_READ_BYTES:
return awk->pipe_handler->readBytes(pipe, (hawk_bch_t*)data, count);
case HAWK_RIO_CMD_WRITE:
return awk->pipe_handler->write(pipe, (const hawk_ooch_t*)data, count);
case HAWK_RIO_CMD_WRITE_BYTES:
@ -2408,13 +2413,19 @@ hawk_ooi_t Hawk::pipeHandler (hawk_rtx_t* rtx, hawk_rio_cmd_t cmd, hawk_rio_arg_
{
case HAWK_RIO_CMD_OPEN:
return awk->openPipe(pipe);
case HAWK_RIO_CMD_CLOSE:
return awk->closePipe(pipe);
case HAWK_RIO_CMD_READ:
return awk->readPipe(pipe, (hawk_ooch_t*)data, count);
case HAWK_RIO_CMD_READ_BYTES:
return awk->readPipeBytes(pipe, (hawk_bch_t*)data, count);
case HAWK_RIO_CMD_WRITE:
return awk->writePipe(pipe, (const hawk_ooch_t*)data, count);
case HAWK_RIO_CMD_WRITE_BYTES:
return awk->writePipeBytes(pipe, (const hawk_bch_t*)data, count);
@ -2450,11 +2461,16 @@ hawk_ooi_t Hawk::fileHandler (hawk_rtx_t* rtx, hawk_rio_cmd_t cmd, hawk_rio_arg_
{
case HAWK_RIO_CMD_OPEN:
return awk->file_handler->open(file);
case HAWK_RIO_CMD_CLOSE:
return awk->file_handler->close(file);
case HAWK_RIO_CMD_READ:
return awk->file_handler->read(file, (hawk_ooch_t*)data, count);
case HAWK_RIO_CMD_READ_BYTES:
return awk->file_handler->readBytes(file, (hawk_bch_t*)data, count);
case HAWK_RIO_CMD_WRITE:
return awk->file_handler->write(file, (const hawk_ooch_t*)data, count);
case HAWK_RIO_CMD_WRITE_BYTES:
@ -2474,13 +2490,19 @@ hawk_ooi_t Hawk::fileHandler (hawk_rtx_t* rtx, hawk_rio_cmd_t cmd, hawk_rio_arg_
{
case HAWK_RIO_CMD_OPEN:
return awk->openFile(file);
case HAWK_RIO_CMD_CLOSE:
return awk->closeFile(file);
case HAWK_RIO_CMD_READ:
return awk->readFile(file, (hawk_ooch_t*)data, count);
case HAWK_RIO_CMD_READ_BYTES:
return awk->readFileBytes(file, (hawk_bch_t*)data, count);
case HAWK_RIO_CMD_WRITE:
return awk->writeFile(file, (const hawk_ooch_t*)data, count);
case HAWK_RIO_CMD_WRITE_BYTES:
return awk->writeFileBytes(file, (const hawk_bch_t*)data, count);
@ -2516,11 +2538,15 @@ hawk_ooi_t Hawk::consoleHandler (hawk_rtx_t* rtx, hawk_rio_cmd_t cmd, hawk_rio_a
{
case HAWK_RIO_CMD_OPEN:
return awk->console_handler->open(console);
case HAWK_RIO_CMD_CLOSE:
return awk->console_handler->close(console);
case HAWK_RIO_CMD_READ:
return awk->console_handler->read(console, (hawk_ooch_t*)data, count);
case HAWK_RIO_CMD_READ_BYTES:
return awk->console_handler->readBytes(console, (hawk_bch_t*)data, count);
case HAWK_RIO_CMD_WRITE:
return awk->console_handler->write(console, (const hawk_ooch_t*)data, count);
case HAWK_RIO_CMD_WRITE_BYTES:
@ -2528,6 +2554,7 @@ hawk_ooi_t Hawk::consoleHandler (hawk_rtx_t* rtx, hawk_rio_cmd_t cmd, hawk_rio_a
case HAWK_RIO_CMD_FLUSH:
return awk->console_handler->flush(console);
case HAWK_RIO_CMD_NEXT:
return awk->console_handler->next(console);
@ -2542,18 +2569,25 @@ hawk_ooi_t Hawk::consoleHandler (hawk_rtx_t* rtx, hawk_rio_cmd_t cmd, hawk_rio_a
{
case HAWK_RIO_CMD_OPEN:
return awk->openConsole(console);
case HAWK_RIO_CMD_CLOSE:
return awk->closeConsole(console);
case HAWK_RIO_CMD_READ:
return awk->readConsole(console, (hawk_ooch_t*)data, count);
case HAWK_RIO_CMD_READ_BYTES:
return awk->readConsoleBytes(console, (hawk_bch_t*)data, count);
case HAWK_RIO_CMD_WRITE:
return awk->writeConsole(console, (const hawk_ooch_t*)data, count);
case HAWK_RIO_CMD_WRITE_BYTES:
return awk->writeConsoleBytes(console, (const hawk_bch_t*)data, count);
case HAWK_RIO_CMD_FLUSH:
return awk->flushConsole(console);
case HAWK_RIO_CMD_NEXT:
return awk->nextConsole(console);
@ -2587,6 +2621,12 @@ hawk_ooi_t Hawk::readPipe (Pipe& io, hawk_ooch_t* buf, hawk_oow_t len)
return -1;
}
hawk_ooi_t Hawk::readPipeBytes (Pipe& io, hawk_bch_t* buf, hawk_oow_t len)
{
((Run*)io)->setError (HAWK_ENOIMPL);
return -1;
}
hawk_ooi_t Hawk::writePipe (Pipe& io, const hawk_ooch_t* buf, hawk_oow_t len)
{
((Run*)io)->setError (HAWK_ENOIMPL);
@ -2623,6 +2663,12 @@ hawk_ooi_t Hawk::readFile (File& io, hawk_ooch_t* buf, hawk_oow_t len)
return -1;
}
hawk_ooi_t Hawk::readFileBytes (File& io, hawk_bch_t* buf, hawk_oow_t len)
{
((Run*)io)->setError (HAWK_ENOIMPL);
return -1;
}
hawk_ooi_t Hawk::writeFile (File& io, const hawk_ooch_t* buf, hawk_oow_t len)
{
((Run*)io)->setError (HAWK_ENOIMPL);
@ -2659,6 +2705,12 @@ hawk_ooi_t Hawk::readConsole (Console& io, hawk_ooch_t* buf, hawk_oow_t len)
return -1;
}
hawk_ooi_t Hawk::readConsoleBytes (Console& io, hawk_bch_t* buf, hawk_oow_t len)
{
((Run*)io)->setError (HAWK_ENOIMPL);
return -1;
}
hawk_ooi_t Hawk::writeConsole (Console& io, const hawk_ooch_t* buf, hawk_oow_t len)
{
((Run*)io)->setError (HAWK_ENOIMPL);

View File

@ -680,12 +680,13 @@ public:
public:
virtual ~Handler () {}
virtual int open (Pipe& io) = 0;
virtual int close (Pipe& io) = 0;
virtual int open (Pipe& io) = 0;
virtual int close (Pipe& io) = 0;
virtual hawk_ooi_t read (Pipe& io, hawk_ooch_t* buf, hawk_oow_t len) = 0;
virtual hawk_ooi_t readBytes (Pipe& io, hawk_bch_t* buf, hawk_oow_t len) = 0;
virtual hawk_ooi_t write (Pipe& io, const hawk_ooch_t* buf, hawk_oow_t len) = 0;
virtual hawk_ooi_t writeBytes (Pipe& io, const hawk_bch_t* buf, hawk_oow_t len) = 0;
virtual int flush (Pipe& io) = 0;
virtual int flush (Pipe& io) = 0;
};
protected:
@ -725,12 +726,13 @@ public:
public:
virtual ~Handler () {}
virtual int open (File& io) = 0;
virtual int close (File& io) = 0;
virtual hawk_ooi_t read (File& io, hawk_ooch_t* buf, hawk_oow_t len) = 0;
virtual int open (File& io) = 0;
virtual int close (File& io) = 0;
virtual hawk_ooi_t read (File& io, hawk_ooch_t* buf, hawk_oow_t len) = 0;
virtual hawk_ooi_t readBytes (File& io, hawk_bch_t* buf, hawk_oow_t len) = 0;
virtual hawk_ooi_t write (File& io, const hawk_ooch_t* buf, hawk_oow_t len) = 0;
virtual hawk_ooi_t writeBytes (File& io, const hawk_bch_t* buf, hawk_oow_t len) = 0;
virtual int flush (File& io) = 0;
virtual int flush (File& io) = 0;
};
protected:
@ -784,7 +786,9 @@ public:
/// data not more than \a len characters and return the
/// number of characters filled into the buufer. It can
/// return 0 to indicate EOF and -1 for failure.
virtual hawk_ooi_t read (Console& io, hawk_ooch_t* buf, hawk_oow_t len) = 0;
virtual hawk_ooi_t read (Console& io, hawk_ooch_t* buf, hawk_oow_t len) = 0;
virtual hawk_ooi_t readBytes (Console& io, hawk_bch_t* buf, hawk_oow_t len) = 0;
/// The write() function is called when the console
/// is written for output. It can write upto \a len characters
@ -1670,10 +1674,11 @@ protected:
/// on success and -1 on failure.
virtual int closePipe (Pipe& io);
virtual hawk_ooi_t readPipe (Pipe& io, hawk_ooch_t* buf, hawk_oow_t len);
virtual hawk_ooi_t readPipe (Pipe& io, hawk_ooch_t* buf, hawk_oow_t len);
virtual hawk_ooi_t readPipeBytes (Pipe& io, hawk_bch_t* buf, hawk_oow_t len);
virtual hawk_ooi_t writePipe (Pipe& io, const hawk_ooch_t* buf, hawk_oow_t len);
virtual hawk_ooi_t writePipeBytes (Pipe& io, const hawk_bch_t* buf, hawk_oow_t len);
virtual int flushPipe (Pipe& io);
virtual int flushPipe (Pipe& io);
/// \}
///
@ -1682,12 +1687,13 @@ protected:
/// if no external file handler is set with setFileHandler().
/// \{
///
virtual int openFile (File& io);
virtual int closeFile (File& io);
virtual hawk_ooi_t readFile (File& io, hawk_ooch_t* buf, hawk_oow_t len);
virtual int openFile (File& io);
virtual int closeFile (File& io);
virtual hawk_ooi_t readFile (File& io, hawk_ooch_t* buf, hawk_oow_t len);
virtual hawk_ooi_t readFileBytes (File& io, hawk_bch_t* buf, hawk_oow_t len);
virtual hawk_ooi_t writeFile (File& io, const hawk_ooch_t* buf, hawk_oow_t len);
virtual hawk_ooi_t writeFileBytes (File& io, const hawk_bch_t* buf, hawk_oow_t len);
virtual int flushFile (File& io);
virtual int flushFile (File& io);
/// \}
///
@ -1696,13 +1702,14 @@ protected:
/// if no external console handler is set with setConsoleHandler().
/// \{
///
virtual int openConsole (Console& io);
virtual int closeConsole (Console& io);
virtual hawk_ooi_t readConsole (Console& io, hawk_ooch_t* buf, hawk_oow_t len);
virtual int openConsole (Console& io);
virtual int closeConsole (Console& io);
virtual hawk_ooi_t readConsole (Console& io, hawk_ooch_t* buf, hawk_oow_t len);
virtual hawk_ooi_t readConsoleBytes (Console& io, hawk_bch_t* buf, hawk_oow_t len);
virtual hawk_ooi_t writeConsole (Console& io, const hawk_ooch_t* buf, hawk_oow_t len);
virtual hawk_ooi_t writeConsoleBytes (Console& io, const hawk_bch_t* buf, hawk_oow_t len);
virtual int flushConsole (Console& io);
virtual int nextConsole (Console& io);
virtual int flushConsole (Console& io);
virtual int nextConsole (Console& io);
/// \}
// primitive handlers

View File

@ -682,10 +682,21 @@ hawk_ooi_t HawkStd::readPipe (Pipe& io, hawk_ooch_t* buf, hawk_oow_t len)
{
#if defined(ENABLE_NWIO)
return (io.getUflags() > 0)?
hawk_nwio_read ((hawk_nwio_t*)io.getHandle(), buf, len):
hawk_pio_read ((hawk_pio_t*)io.getHandle(), HAWK_PIO_OUT, buf, len);
hawk_nwio_read((hawk_nwio_t*)io.getHandle(), buf, len):
hawk_pio_read((hawk_pio_t*)io.getHandle(), HAWK_PIO_OUT, buf, len);
#else
return hawk_pio_read ((hawk_pio_t*)io.getHandle(), HAWK_PIO_OUT, buf, len);
return hawk_pio_read((hawk_pio_t*)io.getHandle(), HAWK_PIO_OUT, buf, len);
#endif
}
hawk_ooi_t HawkStd::readPipeBytes (Pipe& io, hawk_bch_t* buf, hawk_oow_t len)
{
#if defined(ENABLE_NWIO)
return (io.getUflags() > 0)?
hawk_nwio_readbytes((hawk_nwio_t*)io.getHandle(), buf, len):
hawk_pio_readbytes((hawk_pio_t*)io.getHandle(), HAWK_PIO_OUT, buf, len);
#else
return hawk_pio_readbytes((hawk_pio_t*)io.getHandle(), HAWK_PIO_OUT, buf, len);
#endif
}
@ -763,6 +774,11 @@ hawk_ooi_t HawkStd::readFile (File& io, hawk_ooch_t* buf, hawk_oow_t len)
return hawk_sio_getoochars((hawk_sio_t*)io.getHandle(), buf, len);
}
hawk_ooi_t HawkStd::readFileBytes (File& io, hawk_bch_t* buf, hawk_oow_t len)
{
return hawk_sio_getbchars((hawk_sio_t*)io.getHandle(), buf, len);
}
hawk_ooi_t HawkStd::writeFile (File& io, const hawk_ooch_t* buf, hawk_oow_t len)
{
return hawk_sio_putoochars((hawk_sio_t*)io.getHandle(), buf, len);
@ -773,7 +789,6 @@ hawk_ooi_t HawkStd::writeFileBytes (File& io, const hawk_bch_t* buf, hawk_oow_t
return hawk_sio_putbchars((hawk_sio_t*)io.getHandle(), buf, len);
}
int HawkStd::flushFile (File& io)
{
return hawk_sio_flush((hawk_sio_t*)io.getHandle());
@ -1070,12 +1085,36 @@ hawk_ooi_t HawkStd::readConsole (Console& io, hawk_ooch_t* data, hawk_oow_t size
{
hawk_ooi_t nn;
while ((nn = hawk_sio_getoochars((hawk_sio_t*)io.getHandle(),data,size)) == 0)
while ((nn = hawk_sio_getoochars((hawk_sio_t*)io.getHandle(), data, size)) == 0)
{
int n;
hawk_sio_t* sio = (hawk_sio_t*)io.getHandle();
n = open_console_in (io);
n = open_console_in(io);
if (n == -1) return -1;
if (n == 0)
{
/* no more input console */
return 0;
}
if (sio) hawk_sio_close (sio);
}
return nn;
}
hawk_ooi_t HawkStd::readConsoleBytes (Console& io, hawk_bch_t* data, hawk_oow_t size)
{
hawk_ooi_t nn;
while ((nn = hawk_sio_getbchars((hawk_sio_t*)io.getHandle(), data, size)) == 0)
{
int n;
hawk_sio_t* sio = (hawk_sio_t*)io.getHandle();
n = open_console_in(io);
if (n == -1) return -1;
if (n == 0)

View File

@ -172,7 +172,8 @@ protected:
// pipe io handlers
int openPipe (Pipe& io);
int closePipe (Pipe& io);
hawk_ooi_t readPipe (Pipe& io, hawk_ooch_t* buf, hawk_oow_t len);
hawk_ooi_t readPipe (Pipe& io, hawk_ooch_t* buf, hawk_oow_t len);
hawk_ooi_t readPipeBytes (Pipe& io, hawk_bch_t* buf, hawk_oow_t len);
hawk_ooi_t writePipe (Pipe& io, const hawk_ooch_t* buf, hawk_oow_t len);
hawk_ooi_t writePipeBytes (Pipe& io, const hawk_bch_t* buf, hawk_oow_t len);
int flushPipe (Pipe& io);
@ -181,6 +182,7 @@ protected:
int openFile (File& io);
int closeFile (File& io);
hawk_ooi_t readFile (File& io, hawk_ooch_t* buf, hawk_oow_t len);
hawk_ooi_t readFileBytes (File& io, hawk_bch_t* buf, hawk_oow_t len);
hawk_ooi_t writeFile (File& io, const hawk_ooch_t* buf, hawk_oow_t len);
hawk_ooi_t writeFileBytes (File& io, const hawk_bch_t* buf, hawk_oow_t len);
int flushFile (File& io);
@ -189,15 +191,16 @@ protected:
int openConsole (Console& io);
int closeConsole (Console& io);
hawk_ooi_t readConsole (Console& io, hawk_ooch_t* buf, hawk_oow_t len);
hawk_ooi_t readConsoleBytes (Console& io, hawk_bch_t* buf, hawk_oow_t len);
hawk_ooi_t writeConsole (Console& io, const hawk_ooch_t* buf, hawk_oow_t len);
hawk_ooi_t writeConsoleBytes (Console& io, const hawk_bch_t* buf, hawk_oow_t len);
int flushConsole (Console& io);
int nextConsole (Console& io);
// primitive handlers
void* allocMem (hawk_oow_t n);
void* allocMem (hawk_oow_t n);
void* reallocMem (void* ptr, hawk_oow_t n);
void freeMem (void* ptr);
void freeMem (void* ptr);
hawk_flt_t pow (hawk_flt_t x, hawk_flt_t y);
hawk_flt_t mod (hawk_flt_t x, hawk_flt_t y);