input handling experiment
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
hyung-hwan 2024-05-19 15:12:47 +09:00
parent 35929b8c88
commit 0bf106532d
2 changed files with 22 additions and 17 deletions

View File

@ -1263,10 +1263,16 @@ struct hcl_io_cciarg_t
*/ */
void* handle; void* handle;
/**
* [OUT] set this to non-zero in HCL_IO_OPEN if the handler fills the buffer with bytes.
* the caller issues HCL_IO_READ_BYTES if it's set to non-zero, expecting bytes.
* otherwise it issues HCL_IO_READ expecting characters.
*/
int is_bytes;
/** /**
* [OUT] place data here for #HCL_IO_READ or #HCL_IO_READ_BYTES * [OUT] place data here for #HCL_IO_READ or #HCL_IO_READ_BYTES
*/ */
int is_bytes; /* set this to non-zero if the handler fills the buffer with bytes */
union union
{ {
hcl_ooch_t c[HCL_CCI_BUF_LEN]; hcl_ooch_t c[HCL_CCI_BUF_LEN];
@ -1317,6 +1323,11 @@ struct hcl_io_udiarg_t
*/ */
void* handle; void* handle;
/**
* [OUT] indicates if HCL_IO_READ_BYTES is implemented
*/
int is_bytes;
/** /**
* [OUT] place data in c for #HCL_IO_READ and in d for #HCL_IO_READ_BYTES * [OUT] place data in c for #HCL_IO_READ and in d for #HCL_IO_READ_BYTES
*/ */
@ -1335,7 +1346,6 @@ struct hcl_io_udiarg_t
* Internal use only. Don't touch these. * Internal use only. Don't touch these.
*/ */
hcl_oow_t pos; hcl_oow_t pos;
int is_byte;
}; };
typedef struct hcl_io_udoarg_t hcl_io_udoarg_t; typedef struct hcl_io_udoarg_t hcl_io_udoarg_t;

View File

@ -224,14 +224,7 @@ static int get_udi_char (hcl_t* hcl, hcl_ooch_t* ch)
hcl->io.udi_arg.xlen = 0; hcl->io.udi_arg.xlen = 0;
if (hcl->io.udi_rdr(hcl, HCL_IO_READ, &hcl->io.udi_arg) <= -1) return -1; if (hcl->io.udi_rdr(hcl, HCL_IO_READ, &hcl->io.udi_arg) <= -1) return -1;
if (hcl->io.udi_arg.xlen <= 0) return 0; /* EOF */ if (hcl->io.udi_arg.xlen <= 0) return 0; /* EOF */
hcl->io.udi_arg.is_byte = 0; hcl->io.udi_arg.is_bytes = 0;
}
if (hcl->io.udi_arg.is_byte)
{
/* TODO: set error */
return -1;
} }
*ch = hcl->io.udi_arg.buf.c[hcl->io.udi_arg.pos++]; *ch = hcl->io.udi_arg.buf.c[hcl->io.udi_arg.pos++];
@ -240,19 +233,21 @@ static int get_udi_char (hcl_t* hcl, hcl_ooch_t* ch)
static int get_udi_byte (hcl_t* hcl, hcl_uint8_t* bt) static int get_udi_byte (hcl_t* hcl, hcl_uint8_t* bt)
{ {
#if defined(HCL_OOCH_IS_UCH)
if (!hcl->io.udi_arg.is_bytes)
{
hcl_seterrbfmt (hcl, HCL_EPERM, "prohibited byte-oriented input");
return -1;
}
#endif
if (hcl->io.udi_arg.pos >= hcl->io.udi_arg.xlen) if (hcl->io.udi_arg.pos >= hcl->io.udi_arg.xlen)
{ {
hcl->io.udi_arg.pos = 0; hcl->io.udi_arg.pos = 0;
hcl->io.udi_arg.xlen = 0; hcl->io.udi_arg.xlen = 0;
if (hcl->io.udi_rdr(hcl, HCL_IO_READ_BYTES, &hcl->io.udi_arg) <= -1) return -1; if (hcl->io.udi_rdr(hcl, HCL_IO_READ_BYTES, &hcl->io.udi_arg) <= -1) return -1;
if (hcl->io.udi_arg.xlen <= 0) return 0; /* EOF */ if (hcl->io.udi_arg.xlen <= 0) return 0; /* EOF */
hcl->io.udi_arg.is_byte = 1; hcl->io.udi_arg.is_bytes = 1;
}
if (!hcl->io.udi_arg.is_byte)
{
/* TODO: set error */
return -1;
} }
*bt = hcl->io.udi_arg.buf.b[hcl->io.udi_arg.pos++]; *bt = hcl->io.udi_arg.buf.b[hcl->io.udi_arg.pos++];