some support code for getbline. yet to be completed

This commit is contained in:
hyung-hwan 2020-01-16 10:43:55 +00:00
parent 3325db83fb
commit 788b7a6290
4 changed files with 21 additions and 16 deletions

View File

@ -35,6 +35,10 @@ int hawk_rtx_readio (
hawk_rtx_t* run, int in_type,
const hawk_ooch_t* name, hawk_ooecs_t* buf);
int hawk_rtx_readiobytes (
hawk_rtx_t* run, int in_type,
const hawk_ooch_t* name, hawk_becs_t* buf);
int hawk_rtx_writeioval (
hawk_rtx_t* run, int out_type,
const hawk_ooch_t* name, hawk_val_t* v);

View File

@ -666,7 +666,6 @@ int hawk_rtx_readio (hawk_rtx_t* rtx, int in_type, const hawk_ooch_t* name, hawk
int hawk_rtx_readiobytes (hawk_rtx_t* rtx, int in_type, const hawk_ooch_t* name, hawk_becs_t* buf)
{
#if 1
hawk_rio_arg_t* p;
hawk_rio_impl_t handler;
int ret;
@ -695,6 +694,7 @@ int hawk_rtx_readiobytes (hawk_rtx_t* rtx, int in_type, const hawk_ooch_t* name,
ret = 1;
/* call the I/O handler */
while (1)
{
@ -716,7 +716,7 @@ int hawk_rtx_readiobytes (hawk_rtx_t* rtx, int in_type, const hawk_ooch_t* name,
break;
}
x = handler(rtx, HAWK_RIO_CMD_READ_BYTES, p, p->in.buf, HAWK_COUNTOF(p->in.buf));
x = handler(rtx, HAWK_RIO_CMD_READ_BYTES, p, (hawk_bch_t*)p->in.buf, HAWK_SIZEOF(p->in.buf));
if (x <= -1)
{
ret = -1;
@ -814,7 +814,7 @@ int hawk_rtx_readiobytes (hawk_rtx_t* rtx, int in_type, const hawk_ooch_t* name,
}
while (p->in.pos < p->in.len);
tmp = hawk_becs_ncat(buf, &p->in.buf[start_pos], end_pos - start_pos);
tmp = hawk_becs_ncat(buf, &((hawk_bch_t*)p->in.buf)[start_pos], end_pos - start_pos);
if (tmp == (hawk_oow_t)-1)
{
ret = -1;
@ -928,7 +928,7 @@ int hawk_rtx_readiobytes (hawk_rtx_t* rtx, int in_type, const hawk_ooch_t* name,
}
while (p->in.pos < p->in.len);
tmp = hawk_becs_ncat(buf, &p->in.buf[start_pos], end_pos - start_pos);
tmp = hawk_becs_ncat(buf, &((hawk_bch_t*)p->in.buf)[start_pos], end_pos - start_pos);
if (tmp == (hawk_oow_t)-1)
{
ret = -1;
@ -950,7 +950,7 @@ int hawk_rtx_readiobytes (hawk_rtx_t* rtx, int in_type, const hawk_ooch_t* name,
* to the buffer, it is the longest match.
*/
tmp = hawk_becs_ncat(buf, &p->in.buf[p->in.pos], p->in.len - p->in.pos);
tmp = hawk_becs_ncat(buf, &((hawk_bch_t*)p->in.buf)[p->in.pos], p->in.len - p->in.pos);
if (tmp == (hawk_oow_t)-1)
{
ret = -1;
@ -972,10 +972,6 @@ int hawk_rtx_readiobytes (hawk_rtx_t* rtx, int in_type, const hawk_ooch_t* name,
hawk_rtx_refdownval (rtx, brs);
return ret;
#else
hawk_rtx_seterrnum (rtx, HAWK_NULL, HAWK_ENOIMPL);
return -1;
#endif
}

View File

@ -6661,7 +6661,7 @@ static hawk_val_t* eval_pos (hawk_rtx_t* rtx, hawk_nde_t* nde)
return v;
}
static hawk_val_t* nde_to_str(hawk_rtx_t* rtx, hawk_nde_t* nde, hawk_oocs_t* dst)
static hawk_val_t* getline_target_nde_to_str(hawk_rtx_t* rtx, hawk_nde_t* nde, hawk_oocs_t* dst)
{
hawk_oow_t len;
hawk_val_t* v;
@ -6677,9 +6677,10 @@ static hawk_val_t* nde_to_str(hawk_rtx_t* rtx, hawk_nde_t* nde, hawk_oocs_t* dst
return HAWK_NULL;
}
while (dst->len > 0)
len = dst->len;
while (len > 0)
{
if (dst->ptr[--dst->len] == '\0')
if (dst->ptr[--len] == '\0')
{
dst->len = 0; /* indicate that the name is not valid */
break;
@ -6708,7 +6709,7 @@ static hawk_val_t* __eval_getline (hawk_rtx_t* rtx, hawk_nde_t* nde)
if (p->in)
{
v = nde_to_str(rtx, p->in, &dst);
v = getline_target_nde_to_str(rtx, p->in, &dst);
if (!v) return HAWK_NULL;
if (dst.len <= 0)
@ -6816,7 +6817,7 @@ static hawk_val_t* __eval_getbline (hawk_rtx_t* rtx, hawk_nde_t* nde)
if (p->in)
{
v = nde_to_str(rtx, p->in, &dst);
v = getline_target_nde_to_str(rtx, p->in, &dst);
if (!v) return HAWK_NULL;
if (dst.len <= 0)
@ -6852,6 +6853,8 @@ read_console_again:
}
else if (n > 0)
{
#if 0
/* the implementation is not perfect yet.
if (p->in_type == HAWK_IN_CONSOLE)
{
HAWK_ASSERT (p->in == HAWK_NULL);
@ -6867,7 +6870,7 @@ read_console_again:
}
}
}
#endif
if (p->var == HAWK_NULL)
{
/* set $0 with the input value */
@ -6893,12 +6896,14 @@ read_console_again:
if (tmp == HAWK_NULL) return HAWK_NULL;
}
#if 0
/* update FNR & NR if reading from console */
if (p->in_type == HAWK_IN_CONSOLE &&
update_fnr(rtx, rtx->gbl.fnr + 1, rtx->gbl.nr + 1) <= -1)
{
return HAWK_NULL;
}
#endif
}
skip_read:

View File

@ -1854,7 +1854,7 @@ static hawk_ooi_t pio_handler_rest (hawk_rtx_t* rtx, hawk_rio_cmd_t cmd, hawk_ri
return hawk_pio_read((hawk_pio_t*)riod->handle, HAWK_PIO_OUT, data, size);
case HAWK_RIO_CMD_READ_BYTES:
return hawk_pio_readbytes((hawk_pio_t*)riod->handle, HAWK_PIO_IN, data, size);
return hawk_pio_readbytes((hawk_pio_t*)riod->handle, HAWK_PIO_OUT, data, size);
case HAWK_RIO_CMD_WRITE:
return hawk_pio_write((hawk_pio_t*)riod->handle, HAWK_PIO_IN, data, size);