almost finished the byte cci handler. yet to test more
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
hyung-hwan 2024-02-18 18:21:24 +09:00
parent 20d8a81a34
commit ca1e82816d
4 changed files with 29 additions and 15 deletions

View File

@ -1867,7 +1867,7 @@ static int print_bcs (hcl_fmtout_t* fmtout, const hcl_bch_t* ptr, hcl_oow_t len)
if (HCL_UNLIKELY(!hcl->io.udo_wrtr))
{
hcl_seterrmsg (hcl, HCL_EINVAL, "no user-defined output handler");
hcl_seterrbmsg (hcl, HCL_EINVAL, "no user-defined output handler");
return -1;
}
@ -1895,7 +1895,7 @@ static int print_ucs (hcl_fmtout_t* fmtout, const hcl_uch_t* ptr, hcl_oow_t len)
if (HCL_UNLIKELY(!hcl->io.udo_wrtr))
{
hcl_seterrmsg (hcl, HCL_EINVAL, "no user-defined output handler");
hcl_seterrbmsg (hcl, HCL_EINVAL, "no user-defined output handler");
return -1;
}

View File

@ -1208,6 +1208,12 @@ struct hcl_lxc_t
};
typedef struct hcl_lxc_t hcl_lxc_t;
/*#define HCL_CCI_BUF_LEN (1)*/
#if !defined(HCL_CCI_BUF_LEN)
#define HCL_CCI_BUF_LEN (2048)
#endif
typedef struct hcl_io_cciarg_t hcl_io_cciarg_t;
struct hcl_io_cciarg_t
{
@ -1232,8 +1238,8 @@ struct hcl_io_cciarg_t
int is_bytes; /* set this to non-zero if the handler fills the buffer with bytes */
union
{
hcl_ooch_t c[2048]; /* TODO: resize this if necessary */
hcl_uint8_t b[2048 * HCL_SIZEOF(hcl_ooch_t)]; /* TODO: resize this if necessary */
hcl_ooch_t c[HCL_CCI_BUF_LEN];
hcl_uint8_t b[HCL_CCI_BUF_LEN * HCL_SIZEOF(hcl_ooch_t)];
} buf;
/**

View File

@ -2968,12 +2968,16 @@ static int feed_from_includee (hcl_t* hcl)
curinp->b.pos = 0;
curinp->b.len = curinp->xlen;
//printf ("curinp->xlen = %d\n", (int)curinp->xlen);
}
avail = curinp->b.len - curinp->b.pos; /* available in the read buffer */
saved_rsd_len = curinp->rsd.len;
if (curinp->rsd.len > 0)
//printf ("saved_rsd_len = %d avail=%d\n", (int)saved_rsd_len, (int)avail);
if (saved_rsd_len > 0)
{
/* there is data in the residue buffer. use the residue buffer to
* locate a proper multi-byte sequence */
hcl_oow_t cpl; /* number of bytes to copy to the residue buffer */
HCL_ASSERT (hcl, curinp->b.pos == 0);
cpl = HCL_COUNTOF(curinp->rsd.buf) - curinp->rsd.len;
@ -2985,7 +2989,9 @@ static int feed_from_includee (hcl_t* hcl)
curinp->b.pos += cpl; /* advance this because the bytes moved to the residue buffer */
}
inplen = curinp->rsd.len;
n = cmgr->bctouc(curinp->rsd.buf, inplen, &c);
n = cmgr->bctouc(&curinp->rsd.buf[0], inplen, &c);
//printf ("residue -> inplen = %d cpl = %d avail=%d\n", (int)inplen, (int)cpl, (int)avail);
if (n > 0 && n <= inplen) curinp->b.pos -= curinp->rsd.len - saved_rsd_len;
}
else
{
@ -2998,19 +3004,20 @@ static int feed_from_includee (hcl_t* hcl)
hcl_seterrbfmt (hcl, HCL_EECERR, "invalid byte sequence in %js", curinp->name);
return -1;
}
if (n > inplen)
if (n > inplen) /* incomplete sequence */
{
/* incomplete sequence */
HCL_ASSERT (hcl, avail < HCL_COUNTOF(curinp->rsd.buf));
/* TODO: wrong */
HCL_MEMCPY (curinp->rsd.buf, &curinp->buf.b[curinp->b.pos], avail);
curinp->rsd.len = avail;
curinp->b.pos = curinp->b.len;
hcl_oow_t cpl;
HCL_ASSERT (hcl, curinp->rsd.len < HCL_COUNTOF(curinp->rsd.buf));
cpl = HCL_COUNTOF(curinp->rsd.buf) - curinp->rsd.len;
if (cpl > avail) cpl = avail;
HCL_MEMCPY(&curinp->rsd.buf[curinp->rsd.len], &curinp->buf.b[curinp->b.pos], cpl);
curinp->rsd.len += cpl;
curinp->b.pos += cpl;
goto start_over;
}
/* how much taken from the read buffer as input */
HCL_ASSERT (hcl, n >= saved_rsd_len);
taken = n - saved_rsd_len;
}
else
@ -3044,6 +3051,7 @@ static int feed_from_includee (hcl_t* hcl)
}
#endif
//hcl_logbfmt(hcl, HCL_LOG_STDERR, "[%jc]\n", c);
x = feed_char(hcl, c);
if (x <= -1) return -1;
if (x >= 1)

View File

@ -47,7 +47,7 @@ type
name: pwidechar;
handle: pointer;
is_bytes: integer;
buf: array[0..2047] of widechar;
buf: array[0..(2048 - 1)] of widechar;
xlen: System.SizeUint;
includer: CciArgPtr;
end;