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)) 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; 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)) 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; return -1;
} }

View File

@ -1208,6 +1208,12 @@ struct hcl_lxc_t
}; };
typedef struct hcl_lxc_t 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; typedef struct hcl_io_cciarg_t hcl_io_cciarg_t;
struct 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 */ int is_bytes; /* set this to non-zero if the handler fills the buffer with bytes */
union union
{ {
hcl_ooch_t c[2048]; /* TODO: resize this if necessary */ hcl_ooch_t c[HCL_CCI_BUF_LEN];
hcl_uint8_t b[2048 * HCL_SIZEOF(hcl_ooch_t)]; /* TODO: resize this if necessary */ hcl_uint8_t b[HCL_CCI_BUF_LEN * HCL_SIZEOF(hcl_ooch_t)];
} buf; } buf;
/** /**

View File

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

View File

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