Compare commits
No commits in common. "bcfe69fedac25fdc8af1cd445f9ac005968697b9" and "df924338dfdefa9485885302e6cc973c088a3fb2" have entirely different histories.
bcfe69feda
...
df924338df
70
lib/fmt.c
70
lib/fmt.c
@ -1807,15 +1807,15 @@ static int print_bcs (hcl_fmtout_t* fmtout, const hcl_bch_t* ptr, hcl_oow_t len)
|
||||
ucsptr = ucsbuf;
|
||||
while (ucslen > 0)
|
||||
{
|
||||
hcl->io.udo_arg.ptr = ucsptr;
|
||||
hcl->io.udo_arg.len = ucslen;
|
||||
hcl->io.outarg.ptr = ucsptr;
|
||||
hcl->io.outarg.len = ucslen;
|
||||
|
||||
if (hcl->io.udo_wrtr(hcl, HCL_IO_WRITE, &hcl->io.udo_arg) <= -1) return -1;
|
||||
if (hcl->io.udo_arg.xlen <= 0) return 0; /* end of stream. but not failure */
|
||||
if (hcl->io.printer(hcl, HCL_IO_WRITE, &hcl->io.outarg) <= -1) return -1;
|
||||
if (hcl->io.outarg.xlen <= 0) return 0; /* end of stream. but not failure */
|
||||
|
||||
HCL_ASSERT (hcl, hcl->io.udo_arg.xlen <= len);
|
||||
ucsptr += hcl->io.udo_arg.xlen;
|
||||
ucslen -= hcl->io.udo_arg.xlen;
|
||||
HCL_ASSERT (hcl, hcl->io.outarg.xlen <= len);
|
||||
ucsptr += hcl->io.outarg.xlen;
|
||||
ucslen -= hcl->io.outarg.xlen;
|
||||
}
|
||||
|
||||
ptr += bcslen;
|
||||
@ -1827,15 +1827,15 @@ static int print_bcs (hcl_fmtout_t* fmtout, const hcl_bch_t* ptr, hcl_oow_t len)
|
||||
optr = (hcl_bch_t*)ptr;
|
||||
while (len > 0)
|
||||
{
|
||||
hcl->io.udo_arg.ptr = optr;
|
||||
hcl->io.udo_arg.len = len;
|
||||
hcl->io.outarg.ptr = optr;
|
||||
hcl->io.outarg.len = len;
|
||||
|
||||
if (hcl->io.udo_wrtr(hcl, HCL_IO_WRITE, &hcl->io.udo_arg) <= -1) return -1;
|
||||
if (hcl->io.udo_arg.xlen <= 0) return 0; /* end of stream. but not failure */
|
||||
if (hcl->io.printer(hcl, HCL_IO_WRITE, &hcl->io.outarg) <= -1) return -1;
|
||||
if (hcl->io.outarg.xlen <= 0) return 0; /* end of stream. but not failure */
|
||||
|
||||
HCL_ASSERT (hcl, hcl->io.udo_arg.xlen <= len);
|
||||
optr += hcl->io.udo_arg.xlen;
|
||||
len -= hcl->io.udo_arg.xlen;
|
||||
HCL_ASSERT (hcl, hcl->io.outarg.xlen <= len);
|
||||
optr += hcl->io.outarg.xlen;
|
||||
len -= hcl->io.outarg.xlen;
|
||||
}
|
||||
#endif
|
||||
#else
|
||||
@ -1844,15 +1844,15 @@ static int print_bcs (hcl_fmtout_t* fmtout, const hcl_bch_t* ptr, hcl_oow_t len)
|
||||
optr = (hcl_bch_t*)ptr;
|
||||
while (len > 0)
|
||||
{
|
||||
hcl->io.udo_arg.ptr = optr;
|
||||
hcl->io.udo_arg.len = len;
|
||||
hcl->io.outarg.ptr = optr;
|
||||
hcl->io.outarg.len = len;
|
||||
|
||||
if (hcl->io.udo_wrtr(hcl, HCL_IO_WRITE_BYTES, &hcl->io.udo_arg) <= -1) return -1;
|
||||
if (hcl->io.udo_arg.xlen <= 0) return 0; /* end of stream. but not failure */
|
||||
if (hcl->io.printer(hcl, HCL_IO_WRITE_BYTES, &hcl->io.outarg) <= -1) return -1;
|
||||
if (hcl->io.outarg.xlen <= 0) return 0; /* end of stream. but not failure */
|
||||
|
||||
HCL_ASSERT (hcl, hcl->io.udo_arg.xlen <= len);
|
||||
optr += hcl->io.udo_arg.xlen;
|
||||
len -= hcl->io.udo_arg.xlen;
|
||||
HCL_ASSERT (hcl, hcl->io.outarg.xlen <= len);
|
||||
optr += hcl->io.outarg.xlen;
|
||||
len -= hcl->io.outarg.xlen;
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -1869,15 +1869,15 @@ static int print_ucs (hcl_fmtout_t* fmtout, const hcl_uch_t* ptr, hcl_oow_t len)
|
||||
optr = (hcl_uch_t*)ptr;
|
||||
while (len > 0)
|
||||
{
|
||||
hcl->io.udo_arg.ptr = optr;
|
||||
hcl->io.udo_arg.len = len;
|
||||
hcl->io.outarg.ptr = optr;
|
||||
hcl->io.outarg.len = len;
|
||||
|
||||
if (hcl->io.udo_wrtr(hcl, HCL_IO_WRITE, &hcl->io.udo_arg) <= -1) return -1;
|
||||
if (hcl->io.udo_arg.xlen <= 0) return 0; /* end of stream. but not failure */
|
||||
if (hcl->io.printer(hcl, HCL_IO_WRITE, &hcl->io.outarg) <= -1) return -1;
|
||||
if (hcl->io.outarg.xlen <= 0) return 0; /* end of stream. but not failure */
|
||||
|
||||
HCL_ASSERT (hcl, hcl->io.udo_arg.xlen <= len);
|
||||
optr += hcl->io.udo_arg.xlen;
|
||||
len -= hcl->io.udo_arg.xlen;
|
||||
HCL_ASSERT (hcl, hcl->io.outarg.xlen <= len);
|
||||
optr += hcl->io.outarg.xlen;
|
||||
len -= hcl->io.outarg.xlen;
|
||||
}
|
||||
#else
|
||||
hcl_oow_t bcslen, ucslen;
|
||||
@ -1892,15 +1892,15 @@ static int print_ucs (hcl_fmtout_t* fmtout, const hcl_uch_t* ptr, hcl_oow_t len)
|
||||
bcsptr = bcsbuf;
|
||||
while (bcslen > 0)
|
||||
{
|
||||
hcl->io.udo_arg.ptr = bcsptr;
|
||||
hcl->io.udo_arg.len = bcslen;
|
||||
hcl->io.outarg.ptr = bcsptr;
|
||||
hcl->io.outarg.len = bcslen;
|
||||
|
||||
if (hcl->io.udo_wrtr(hcl, HCL_IO_WRITE, &hcl->io.udo_arg) <= -1) return -1;
|
||||
if (hcl->io.udo_arg.xlen <= 0) return 0; /* end of stream. but not failure */
|
||||
if (hcl->io.printer(hcl, HCL_IO_WRITE, &hcl->io.outarg) <= -1) return -1;
|
||||
if (hcl->io.outarg.xlen <= 0) return 0; /* end of stream. but not failure */
|
||||
|
||||
HCL_ASSERT (hcl, hcl->io.udo_arg.xlen <= len);
|
||||
bcsptr += hcl->io.udo_arg.xlen;
|
||||
bcslen -= hcl->io.udo_arg.xlen;
|
||||
HCL_ASSERT (hcl, hcl->io.outarg.xlen <= len);
|
||||
bcsptr += hcl->io.outarg.xlen;
|
||||
bcslen -= hcl->io.outarg.xlen;
|
||||
}
|
||||
|
||||
ptr += ucslen;
|
||||
|
@ -644,10 +644,10 @@ struct hcl_compiler_t
|
||||
hcl_cb_t* cbp;
|
||||
|
||||
/* input handler */
|
||||
hcl_io_impl_t sci_rdr;
|
||||
hcl_io_impl_t reader;
|
||||
|
||||
/* static input data buffer */
|
||||
hcl_io_sciarg_t sci_arg;
|
||||
hcl_io_sciarg_t sciarg;
|
||||
|
||||
/* pointer to the current input data. initially, it points to &inarg */
|
||||
hcl_io_sciarg_t* curinp;
|
||||
@ -661,10 +661,10 @@ struct hcl_compiler_t
|
||||
|
||||
/* unget buffer */
|
||||
hcl_lxc_t ungot[10];
|
||||
int nungots;
|
||||
int nungots;
|
||||
|
||||
/* the last token read */
|
||||
hcl_tok_t tok;
|
||||
hcl_tok_t tok;
|
||||
hcl_link_t* sr_names;
|
||||
|
||||
hcl_synerr_t synerr;
|
||||
|
@ -572,7 +572,7 @@ static int print_handler (hcl_t* hcl, hcl_io_cmd_t cmd, void* arg)
|
||||
case HCL_IO_WRITE:
|
||||
{
|
||||
worker_hcl_xtn_t* xtn = (worker_hcl_xtn_t*)hcl_getxtn(hcl);
|
||||
hcl_io_udoarg_t* outarg = (hcl_io_udoarg_t*)arg;
|
||||
hcl_io_outarg_t* outarg = (hcl_io_outarg_t*)arg;
|
||||
|
||||
if (hcl_server_proto_feed_reply(xtn->proto, outarg->ptr, outarg->len, 0) <= -1)
|
||||
{
|
||||
@ -591,7 +591,7 @@ static int print_handler (hcl_t* hcl, hcl_io_cmd_t cmd, void* arg)
|
||||
case HCL_IO_WRITE_BYTES:
|
||||
{
|
||||
worker_hcl_xtn_t* xtn = (worker_hcl_xtn_t*)hcl_getxtn(hcl);
|
||||
hcl_io_udoarg_t* outarg = (hcl_io_udoarg_t*)arg;
|
||||
hcl_io_outarg_t* outarg = (hcl_io_outarg_t*)arg;
|
||||
|
||||
if (hcl_server_proto_feed_reply_bytes(xtn->proto, outarg->ptr, outarg->len, 0) <= -1)
|
||||
{
|
||||
|
42
lib/hcl.h
42
lib/hcl.h
@ -1268,8 +1268,8 @@ struct hcl_io_sciarg_t
|
||||
/*-----------------------------------------------------------------*/
|
||||
};
|
||||
|
||||
typedef struct hcl_io_udiarg_t hcl_io_udiarg_t;
|
||||
struct hcl_io_udiarg_t
|
||||
typedef struct hcl_io_inarg_t hcl_io_inarg_t;
|
||||
struct hcl_io_inarg_t
|
||||
{
|
||||
/**
|
||||
* [OUT] I/O handle set by a handler.
|
||||
@ -1287,11 +1287,11 @@ struct hcl_io_udiarg_t
|
||||
/**
|
||||
* [OUT] place the number of characters read here for #HCL_IO_READ
|
||||
*/
|
||||
hcl_oow_t xlen;
|
||||
hcl_oow_t xlen;
|
||||
};
|
||||
|
||||
typedef struct hcl_io_udoarg_t hcl_io_udoarg_t;
|
||||
struct hcl_io_udoarg_t
|
||||
typedef struct hcl_io_outarg_t hcl_io_outarg_t;
|
||||
struct hcl_io_outarg_t
|
||||
{
|
||||
/**
|
||||
* [OUT] I/O handle set by a handler.
|
||||
@ -1299,7 +1299,7 @@ struct hcl_io_udoarg_t
|
||||
* All subsequent operations on the stream see this field as set
|
||||
* during opening.
|
||||
*/
|
||||
void* handle;
|
||||
void* handle;
|
||||
|
||||
/**
|
||||
* [IN] the pointer to the beginning of the character/byte string
|
||||
@ -1307,18 +1307,18 @@ struct hcl_io_udoarg_t
|
||||
* hcl_ooch_t* for HCL_IO_WRITE
|
||||
* hcl_bch_t* or hcl_uint8_t* for HCL_IO_WRITE_BYTES
|
||||
*/
|
||||
void* ptr;
|
||||
void* ptr;
|
||||
|
||||
/**
|
||||
* [IN] total number of characters/bytes to write
|
||||
*/
|
||||
hcl_oow_t len;
|
||||
hcl_oow_t len;
|
||||
|
||||
/**
|
||||
* [OUT] place the number of characters/bytes written here for
|
||||
* HCL_IO_WRITE or HCL_IO_WRITE_BYTES
|
||||
*/
|
||||
hcl_oow_t xlen;
|
||||
hcl_oow_t xlen;
|
||||
};
|
||||
|
||||
/**
|
||||
@ -1327,8 +1327,8 @@ struct hcl_io_udoarg_t
|
||||
*/
|
||||
typedef int (*hcl_io_impl_t) (
|
||||
hcl_t* hcl,
|
||||
hcl_io_cmd_t cmd,
|
||||
void* arg /* one of hcl_io_sciarg_t*, hcl_io_udiarg_t*, hcl_io_udoarg_t* */
|
||||
hcl_io_cmd_t cmd,
|
||||
void* arg /* one of hcl_io_sciarg_t*, hcl_io_inarg_t*, hcl_io_outarg_t* */
|
||||
);
|
||||
|
||||
/* =========================================================================
|
||||
@ -1706,7 +1706,7 @@ struct hcl_t
|
||||
hcl_dbgi_t* dbgi;
|
||||
} code;
|
||||
|
||||
/* == PRINTER to udo stream == */
|
||||
/* == PRINTER == */
|
||||
struct
|
||||
{
|
||||
struct
|
||||
@ -1717,7 +1717,7 @@ struct hcl_t
|
||||
} s;
|
||||
hcl_oop_t e; /* top entry being printed */
|
||||
} p;
|
||||
/* == PRINTER to udo stream == */
|
||||
/* == PRINTER == */
|
||||
|
||||
struct
|
||||
{
|
||||
@ -1750,12 +1750,12 @@ struct hcl_t
|
||||
struct
|
||||
{
|
||||
/* input handler */
|
||||
hcl_io_impl_t udi_rdr;
|
||||
hcl_io_udiarg_t udi_arg;
|
||||
hcl_io_impl_t scanner;
|
||||
hcl_io_inarg_t inarg;
|
||||
|
||||
/* output handler */
|
||||
hcl_io_impl_t udo_wrtr;
|
||||
hcl_io_udoarg_t udo_arg;
|
||||
hcl_io_impl_t printer;
|
||||
hcl_io_outarg_t outarg;
|
||||
} io;
|
||||
|
||||
#if defined(HCL_INCLUDE_COMPILER)
|
||||
@ -2241,10 +2241,10 @@ HCL_EXPORT hcl_ooch_t* hcl_readbasesrraw (
|
||||
);
|
||||
|
||||
HCL_EXPORT int hcl_attachio (
|
||||
hcl_t* hcl,
|
||||
hcl_io_impl_t sci_rdr, /* source code input handler */
|
||||
hcl_io_impl_t udi_rdr, /* user data input handler */
|
||||
hcl_io_impl_t udo_wrtr /* user data output handler */
|
||||
hcl_t* hcl,
|
||||
hcl_io_impl_t reader, /* source stream heandler */
|
||||
hcl_io_impl_t scanner, /* runtime input stream handler */
|
||||
hcl_io_impl_t printer /* runtime output stream handler */
|
||||
);
|
||||
|
||||
HCL_EXPORT int hcl_attachiostdwithbcstr (
|
||||
|
@ -778,7 +778,7 @@ int hcl_outfmtobj (hcl_t* hcl, hcl_bitmask_t mask, hcl_oop_t obj, hcl_outbfmt_t
|
||||
|
||||
int hcl_print (hcl_t* hcl, hcl_oop_t obj)
|
||||
{
|
||||
HCL_ASSERT (hcl, hcl->io.udo_wrtr != HCL_NULL);
|
||||
HCL_ASSERT (hcl, hcl->io.printer != HCL_NULL);
|
||||
/*return hcl_outfmtobj(hcl, HCL_LOG_APP | HCL_LOG_FATAL, obj);*/
|
||||
return hcl_prbfmt(hcl, "%O", obj);
|
||||
}
|
||||
|
124
lib/read.c
124
lib/read.c
@ -446,7 +446,7 @@ static int _get_char (hcl_t* hcl, hcl_io_sciarg_t* inp)
|
||||
|
||||
if (inp->b.pos >= inp->b.len)
|
||||
{
|
||||
if (hcl->c->sci_rdr(hcl, HCL_IO_READ, inp) <= -1) return -1;
|
||||
if (hcl->c->reader(hcl, HCL_IO_READ, inp) <= -1) return -1;
|
||||
|
||||
if (inp->xlen <= 0)
|
||||
{
|
||||
@ -893,18 +893,18 @@ static int feed_begin_include (hcl_t* hcl)
|
||||
/*arg->nl = '\0';*/
|
||||
arg->includer = hcl->c->curinp;
|
||||
|
||||
if (hcl->c->sci_rdr(hcl, HCL_IO_OPEN, arg) <= -1)
|
||||
if (hcl->c->reader(hcl, HCL_IO_OPEN, arg) <= -1)
|
||||
{
|
||||
const hcl_ooch_t* org_errmsg = hcl_backuperrmsg(hcl);
|
||||
hcl_setsynerrbfmt (hcl, HCL_SYNERR_INCLUDE, TOKEN_LOC(hcl), TOKEN_NAME(hcl), "unable to include %js - %js", io_name, org_errmsg);
|
||||
goto oops;
|
||||
}
|
||||
|
||||
if (arg->includer == &hcl->c->sci_arg) /* top-level include */
|
||||
if (arg->includer == &hcl->c->sciarg) /* top-level include */
|
||||
{
|
||||
/* TODO: remove hcl_readbasesrchar() and clean up this part.
|
||||
* hcl_readbasesrchar(), if called in the middle of feeds,
|
||||
* updates hcl->c->sci_arg's line and colm. so use a separate
|
||||
* updates hcl->c->sciarg's line and colm. so use a separate
|
||||
* field to store the current feed location for now */
|
||||
hcl->c->feed.lx._oloc = hcl->c->feed.lx.loc;
|
||||
}
|
||||
@ -934,12 +934,12 @@ static int feed_end_include (hcl_t* hcl)
|
||||
int x;
|
||||
hcl_io_sciarg_t* cur;
|
||||
|
||||
if (hcl->c->curinp == &hcl->c->sci_arg) return 0; /* no include */
|
||||
if (hcl->c->curinp == &hcl->c->sciarg) return 0; /* no include */
|
||||
|
||||
/* if it is an included file, close it and
|
||||
* retry to read a character from an outer file */
|
||||
|
||||
x = hcl->c->sci_rdr(hcl, HCL_IO_CLOSE, hcl->c->curinp);
|
||||
x = hcl->c->reader(hcl, HCL_IO_CLOSE, hcl->c->curinp);
|
||||
|
||||
/* if closing has failed, still destroy the sio structure
|
||||
* first as normal and return the failure below. this way,
|
||||
@ -948,7 +948,7 @@ static int feed_end_include (hcl_t* hcl)
|
||||
cur = hcl->c->curinp;
|
||||
hcl->c->curinp = hcl->c->curinp->includer;
|
||||
|
||||
if (hcl->c->curinp == &hcl->c->sci_arg)
|
||||
if (hcl->c->curinp == &hcl->c->sciarg)
|
||||
{
|
||||
hcl->c->feed.lx.loc = hcl->c->feed.lx._oloc;
|
||||
}
|
||||
@ -2365,13 +2365,13 @@ static int feed_from_includee (hcl_t* hcl)
|
||||
{
|
||||
int x;
|
||||
|
||||
HCL_ASSERT (hcl, hcl->c->curinp != HCL_NULL && hcl->c->curinp != &hcl->c->sci_arg);
|
||||
HCL_ASSERT (hcl, hcl->c->curinp != HCL_NULL && hcl->c->curinp != &hcl->c->sciarg);
|
||||
|
||||
do
|
||||
{
|
||||
if (hcl->c->curinp->b.pos >= hcl->c->curinp->b.len)
|
||||
{
|
||||
if (hcl->c->sci_rdr(hcl, HCL_IO_READ, hcl->c->curinp) <= -1)
|
||||
if (hcl->c->reader(hcl, HCL_IO_READ, hcl->c->curinp) <= -1)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
@ -2406,7 +2406,7 @@ static int feed_from_includee (hcl_t* hcl)
|
||||
if (feed_begin_include(hcl) <= -1) return -1;
|
||||
}
|
||||
}
|
||||
while (hcl->c->curinp != &hcl->c->sci_arg);
|
||||
while (hcl->c->curinp != &hcl->c->sciarg);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -2465,7 +2465,7 @@ int hcl_feed (hcl_t* hcl, const hcl_ooch_t* data, hcl_oow_t len)
|
||||
hcl->c->feed.rd.do_include_file = 0;
|
||||
}
|
||||
|
||||
if (hcl->c->curinp && hcl->c->curinp != &hcl->c->sci_arg && feed_from_includee(hcl) <= -1)
|
||||
if (hcl->c->curinp && hcl->c->curinp != &hcl->c->sciarg && feed_from_includee(hcl) <= -1)
|
||||
{
|
||||
/* TODO: return the number of processed characters via an argument? */
|
||||
goto oops;
|
||||
@ -2669,7 +2669,7 @@ default callback for on_eof?
|
||||
|
||||
/* ------------------------------------------------------------------------ */
|
||||
|
||||
/* TODO: rename compiler to something else that can include reader, udo_wrtr, and compiler
|
||||
/* TODO: rename compiler to something else that can include reader, printer, and compiler
|
||||
* move compiler intialization/finalization here to more common place */
|
||||
|
||||
static void gc_compiler_cb (hcl_t* hcl)
|
||||
@ -2786,13 +2786,13 @@ static int init_compiler (hcl_t* hcl)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int hcl_attachio (hcl_t* hcl, hcl_io_impl_t sci_rdr, hcl_io_impl_t udi_rdr, hcl_io_impl_t udo_wrtr)
|
||||
int hcl_attachio (hcl_t* hcl, hcl_io_impl_t reader, hcl_io_impl_t scanner, hcl_io_impl_t printer)
|
||||
{
|
||||
int n;
|
||||
int inited_compiler = 0;
|
||||
hcl_io_sciarg_t new_sciarg;
|
||||
hcl_io_udiarg_t new_udiarg;
|
||||
hcl_io_udoarg_t new_udoarg;
|
||||
hcl_io_inarg_t new_inarg;
|
||||
hcl_io_outarg_t new_outarg;
|
||||
|
||||
if (!hcl->c)
|
||||
{
|
||||
@ -2800,7 +2800,7 @@ int hcl_attachio (hcl_t* hcl, hcl_io_impl_t sci_rdr, hcl_io_impl_t udi_rdr, hcl_
|
||||
inited_compiler = 1;
|
||||
}
|
||||
|
||||
if (sci_rdr)
|
||||
if (reader)
|
||||
{
|
||||
/* The name field and the includer field are HCL_NULL
|
||||
* for the main stream */
|
||||
@ -2809,68 +2809,68 @@ int hcl_attachio (hcl_t* hcl, hcl_io_impl_t sci_rdr, hcl_io_impl_t udi_rdr, hcl_
|
||||
new_sciarg.colm = 1;
|
||||
|
||||
/* open the top-level source input stream */
|
||||
n = sci_rdr(hcl, HCL_IO_OPEN, &new_sciarg);
|
||||
n = reader(hcl, HCL_IO_OPEN, &new_sciarg);
|
||||
if (n <= -1) goto oops;
|
||||
}
|
||||
|
||||
if (udi_rdr)
|
||||
if (scanner)
|
||||
{
|
||||
HCL_MEMSET (&new_udiarg, 0, HCL_SIZEOF(new_udiarg));
|
||||
n = udi_rdr(hcl, HCL_IO_OPEN, &new_udiarg);
|
||||
HCL_MEMSET (&new_inarg, 0, HCL_SIZEOF(new_inarg));
|
||||
n = scanner(hcl, HCL_IO_OPEN, &new_inarg);
|
||||
if (n <= -1)
|
||||
{
|
||||
sci_rdr (hcl, HCL_IO_CLOSE, &new_sciarg);
|
||||
reader (hcl, HCL_IO_CLOSE, &new_sciarg);
|
||||
goto oops;
|
||||
}
|
||||
}
|
||||
|
||||
if (udo_wrtr)
|
||||
if (printer)
|
||||
{
|
||||
/* open the new output stream */
|
||||
HCL_MEMSET (&new_udoarg, 0, HCL_SIZEOF(new_udoarg));
|
||||
n = udo_wrtr(hcl, HCL_IO_OPEN, &new_udoarg);
|
||||
HCL_MEMSET (&new_outarg, 0, HCL_SIZEOF(new_outarg));
|
||||
n = printer(hcl, HCL_IO_OPEN, &new_outarg);
|
||||
if (n <= -1)
|
||||
{
|
||||
if (udi_rdr) udi_rdr (hcl, HCL_IO_CLOSE, &new_udiarg);
|
||||
if (sci_rdr) sci_rdr (hcl, HCL_IO_CLOSE, &new_sciarg);
|
||||
if (scanner) scanner (hcl, HCL_IO_CLOSE, &new_inarg);
|
||||
if (reader) reader (hcl, HCL_IO_CLOSE, &new_sciarg);
|
||||
goto oops;
|
||||
}
|
||||
}
|
||||
|
||||
if (sci_rdr)
|
||||
if (reader)
|
||||
{
|
||||
if (hcl->c->sci_rdr)
|
||||
if (hcl->c->reader)
|
||||
{
|
||||
/* close the old source input stream */
|
||||
hcl->c->sci_rdr (hcl, HCL_IO_CLOSE, &hcl->c->sci_arg);
|
||||
hcl->c->reader (hcl, HCL_IO_CLOSE, &hcl->c->sciarg);
|
||||
}
|
||||
hcl->c->sci_rdr = sci_rdr;
|
||||
hcl->c->sci_arg = new_sciarg;
|
||||
hcl->c->reader = reader;
|
||||
hcl->c->sciarg = new_sciarg;
|
||||
}
|
||||
|
||||
if (udi_rdr)
|
||||
if (scanner)
|
||||
{
|
||||
if (hcl->io.udi_rdr)
|
||||
if (hcl->io.scanner)
|
||||
{
|
||||
/* close the old input stream */
|
||||
hcl->io.udi_rdr (hcl, HCL_IO_CLOSE, &hcl->io.udi_arg);
|
||||
hcl->io.scanner (hcl, HCL_IO_CLOSE, &hcl->io.inarg);
|
||||
}
|
||||
hcl->io.udi_rdr = udi_rdr;
|
||||
hcl->io.udi_arg = new_udiarg;
|
||||
hcl->io.scanner = scanner;
|
||||
hcl->io.inarg = new_inarg;
|
||||
}
|
||||
|
||||
if (udo_wrtr)
|
||||
if (printer)
|
||||
{
|
||||
if (hcl->io.udo_wrtr)
|
||||
if (hcl->io.printer)
|
||||
{
|
||||
/* close the old output stream */
|
||||
hcl->io.udo_wrtr (hcl, HCL_IO_CLOSE, &hcl->io.udo_arg);
|
||||
hcl->io.printer (hcl, HCL_IO_CLOSE, &hcl->io.outarg);
|
||||
}
|
||||
hcl->io.udo_wrtr = udo_wrtr;
|
||||
hcl->io.udo_arg = new_udoarg;
|
||||
hcl->io.printer = printer;
|
||||
hcl->io.outarg = new_outarg;
|
||||
}
|
||||
|
||||
if (sci_rdr)
|
||||
if (reader)
|
||||
{
|
||||
/* clear unneeded source stream names */
|
||||
/*clear_sr_names (hcl); <---- TODO: tricky to clean up here */
|
||||
@ -2878,7 +2878,7 @@ int hcl_attachio (hcl_t* hcl, hcl_io_impl_t sci_rdr, hcl_io_impl_t udi_rdr, hcl_
|
||||
/* initialize some other key fields */
|
||||
hcl->c->nungots = 0;
|
||||
/* the source stream is open. set it as the current input stream */
|
||||
hcl->c->curinp = &hcl->c->sci_arg;
|
||||
hcl->c->curinp = &hcl->c->sciarg;
|
||||
}
|
||||
|
||||
return 0;
|
||||
@ -2890,7 +2890,7 @@ oops:
|
||||
|
||||
void hcl_flushio (hcl_t* hcl)
|
||||
{
|
||||
if (hcl->io.udo_wrtr) hcl->io.udo_wrtr (hcl, HCL_IO_FLUSH, &hcl->io.udo_arg);
|
||||
if (hcl->io.printer) hcl->io.printer (hcl, HCL_IO_FLUSH, &hcl->io.outarg);
|
||||
}
|
||||
|
||||
void hcl_detachio (hcl_t* hcl)
|
||||
@ -2901,14 +2901,14 @@ void hcl_detachio (hcl_t* hcl)
|
||||
|
||||
if (hcl->c)
|
||||
{
|
||||
if (hcl->c->sci_rdr)
|
||||
if (hcl->c->reader)
|
||||
{
|
||||
while (hcl->c->curinp != &hcl->c->sci_arg)
|
||||
while (hcl->c->curinp != &hcl->c->sciarg)
|
||||
{
|
||||
hcl_io_sciarg_t* prev;
|
||||
|
||||
/* nothing much to do about a close error */
|
||||
hcl->c->sci_rdr (hcl, HCL_IO_CLOSE, hcl->c->curinp);
|
||||
hcl->c->reader (hcl, HCL_IO_CLOSE, hcl->c->curinp);
|
||||
|
||||
prev = hcl->c->curinp->includer;
|
||||
HCL_ASSERT (hcl, hcl->c->curinp->name != HCL_NULL);
|
||||
@ -2916,29 +2916,29 @@ void hcl_detachio (hcl_t* hcl)
|
||||
hcl->c->curinp = prev;
|
||||
}
|
||||
|
||||
hcl->c->sci_rdr (hcl, HCL_IO_CLOSE, hcl->c->curinp);
|
||||
hcl->c->sci_rdr = HCL_NULL; /* ready for another attachment */
|
||||
hcl->c->reader (hcl, HCL_IO_CLOSE, hcl->c->curinp);
|
||||
hcl->c->reader = HCL_NULL; /* ready for another attachment */
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (hcl->io.udi_rdr)
|
||||
if (hcl->io.scanner)
|
||||
{
|
||||
hcl->io.udi_rdr (hcl, HCL_IO_CLOSE, &hcl->io.udi_arg);
|
||||
hcl->io.udi_rdr = HCL_NULL; /* ready for another attachment */
|
||||
hcl->io.scanner (hcl, HCL_IO_CLOSE, &hcl->io.inarg);
|
||||
hcl->io.scanner = HCL_NULL; /* ready for another attachment */
|
||||
}
|
||||
|
||||
if (hcl->io.udo_wrtr)
|
||||
if (hcl->io.printer)
|
||||
{
|
||||
hcl->io.udo_wrtr (hcl, HCL_IO_CLOSE, &hcl->io.udo_arg);
|
||||
hcl->io.udo_wrtr = HCL_NULL; /* ready for another attachment */
|
||||
hcl->io.printer (hcl, HCL_IO_CLOSE, &hcl->io.outarg);
|
||||
hcl->io.printer = HCL_NULL; /* ready for another attachment */
|
||||
}
|
||||
}
|
||||
|
||||
void hcl_setbasesrloc (hcl_t* hcl, hcl_oow_t line, hcl_oow_t colm)
|
||||
{
|
||||
hcl->c->sci_arg.line = line;
|
||||
hcl->c->sci_arg.colm = colm;
|
||||
hcl->c->sciarg.line = line;
|
||||
hcl->c->sciarg.colm = colm;
|
||||
}
|
||||
|
||||
hcl_lxc_t* hcl_readbasesrchar (hcl_t* hcl)
|
||||
@ -2946,9 +2946,9 @@ hcl_lxc_t* hcl_readbasesrchar (hcl_t* hcl)
|
||||
/* read a character using the base input stream. the caller must care extra
|
||||
* care when using this function. this function reads the main stream regardless
|
||||
* of the inclusion status and ignores the ungot characters. */
|
||||
int n = _get_char(hcl, &hcl->c->sci_arg);
|
||||
int n = _get_char(hcl, &hcl->c->sciarg);
|
||||
if (n <= -1) return HCL_NULL;
|
||||
return &hcl->c->sci_arg.lxc;
|
||||
return &hcl->c->sciarg.lxc;
|
||||
}
|
||||
|
||||
hcl_ooch_t* hcl_readbasesrraw (hcl_t* hcl, hcl_oow_t* xlen)
|
||||
@ -2959,7 +2959,7 @@ hcl_ooch_t* hcl_readbasesrraw (hcl_t* hcl, hcl_oow_t* xlen)
|
||||
|
||||
HCL_ASSERT (hcl, hcl->c != HCL_NULL); /* call hio_attachio() or hio_attachiostd() with proper arguments first */
|
||||
|
||||
if (hcl->c->sci_rdr(hcl, HCL_IO_READ, &hcl->c->sci_arg) <= -1) return HCL_NULL;
|
||||
*xlen = hcl->c->sci_arg.xlen;
|
||||
return hcl->c->sci_arg.buf;
|
||||
if (hcl->c->reader(hcl, HCL_IO_READ, &hcl->c->sciarg) <= -1) return HCL_NULL;
|
||||
*xlen = hcl->c->sciarg.xlen;
|
||||
return hcl->c->sciarg.buf;
|
||||
}
|
||||
|
32
lib/std.c
32
lib/std.c
@ -3396,7 +3396,7 @@ static int sci_handler (hcl_t* hcl, hcl_io_cmd_t cmd, void* arg)
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------- */
|
||||
static HCL_INLINE int open_in_stream (hcl_t* hcl, hcl_io_udiarg_t* arg)
|
||||
static HCL_INLINE int open_in_stream (hcl_t* hcl, hcl_io_inarg_t* arg)
|
||||
{
|
||||
xtn_t* xtn = GET_XTN(hcl);
|
||||
bb_t* bb = HCL_NULL;
|
||||
@ -3438,7 +3438,7 @@ oops:
|
||||
return -1;
|
||||
}
|
||||
|
||||
static HCL_INLINE int close_in_stream (hcl_t* hcl, hcl_io_udiarg_t* arg)
|
||||
static HCL_INLINE int close_in_stream (hcl_t* hcl, hcl_io_inarg_t* arg)
|
||||
{
|
||||
/*xtn_t* xtn = GET_XTN(hcl);*/
|
||||
bb_t* bb;
|
||||
@ -3453,7 +3453,7 @@ static HCL_INLINE int close_in_stream (hcl_t* hcl, hcl_io_udiarg_t* arg)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static HCL_INLINE int read_in_stream (hcl_t* hcl, hcl_io_udiarg_t* arg)
|
||||
static HCL_INLINE int read_in_stream (hcl_t* hcl, hcl_io_inarg_t* arg)
|
||||
{
|
||||
/*xtn_t* xtn = GET_XTN(hcl);*/
|
||||
bb_t* bb;
|
||||
@ -3508,13 +3508,13 @@ static int scan_handler (hcl_t* hcl, hcl_io_cmd_t cmd, void* arg)
|
||||
switch (cmd)
|
||||
{
|
||||
case HCL_IO_OPEN:
|
||||
return open_in_stream(hcl, (hcl_io_udiarg_t*)arg);
|
||||
return open_in_stream(hcl, (hcl_io_inarg_t*)arg);
|
||||
|
||||
case HCL_IO_CLOSE:
|
||||
return close_in_stream(hcl, (hcl_io_udiarg_t*)arg);
|
||||
return close_in_stream(hcl, (hcl_io_inarg_t*)arg);
|
||||
|
||||
case HCL_IO_READ:
|
||||
return read_in_stream(hcl, (hcl_io_udiarg_t*)arg);
|
||||
return read_in_stream(hcl, (hcl_io_inarg_t*)arg);
|
||||
|
||||
case HCL_IO_FLUSH:
|
||||
/* no effect on an input stream */
|
||||
@ -3528,7 +3528,7 @@ static int scan_handler (hcl_t* hcl, hcl_io_cmd_t cmd, void* arg)
|
||||
|
||||
/* --------------------------------------------------------------------- */
|
||||
|
||||
static HCL_INLINE int open_out_stream (hcl_t* hcl, hcl_io_udoarg_t* arg)
|
||||
static HCL_INLINE int open_out_stream (hcl_t* hcl, hcl_io_outarg_t* arg)
|
||||
{
|
||||
xtn_t* xtn = GET_XTN(hcl);
|
||||
FILE* fp;
|
||||
@ -3552,7 +3552,7 @@ static HCL_INLINE int open_out_stream (hcl_t* hcl, hcl_io_udoarg_t* arg)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static HCL_INLINE int close_out_stream (hcl_t* hcl, hcl_io_udoarg_t* arg)
|
||||
static HCL_INLINE int close_out_stream (hcl_t* hcl, hcl_io_outarg_t* arg)
|
||||
{
|
||||
/*xtn_t* xtn = GET_XTN(hcl);*/
|
||||
FILE* fp;
|
||||
@ -3564,7 +3564,7 @@ static HCL_INLINE int close_out_stream (hcl_t* hcl, hcl_io_udoarg_t* arg)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static HCL_INLINE int write_out_stream (hcl_t* hcl, hcl_io_udoarg_t* arg)
|
||||
static HCL_INLINE int write_out_stream (hcl_t* hcl, hcl_io_outarg_t* arg)
|
||||
{
|
||||
/*xtn_t* xtn = GET_XTN(hcl);*/
|
||||
const hcl_ooch_t* ptr;
|
||||
@ -3604,7 +3604,7 @@ static HCL_INLINE int write_out_stream (hcl_t* hcl, hcl_io_udoarg_t* arg)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static HCL_INLINE int write_bytes_out_stream (hcl_t* hcl, hcl_io_udoarg_t* arg)
|
||||
static HCL_INLINE int write_bytes_out_stream (hcl_t* hcl, hcl_io_outarg_t* arg)
|
||||
{
|
||||
/*xtn_t* xtn = GET_XTN(hcl);*/
|
||||
const hcl_uint8_t* ptr;
|
||||
@ -3621,7 +3621,7 @@ static HCL_INLINE int write_bytes_out_stream (hcl_t* hcl, hcl_io_udoarg_t* arg)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static HCL_INLINE int flush_out_stream (hcl_t* hcl, hcl_io_udoarg_t* arg)
|
||||
static HCL_INLINE int flush_out_stream (hcl_t* hcl, hcl_io_outarg_t* arg)
|
||||
{
|
||||
FILE* fp;
|
||||
|
||||
@ -3637,19 +3637,19 @@ static int print_handler (hcl_t* hcl, hcl_io_cmd_t cmd, void* arg)
|
||||
switch (cmd)
|
||||
{
|
||||
case HCL_IO_OPEN:
|
||||
return open_out_stream(hcl, (hcl_io_udoarg_t*)arg);
|
||||
return open_out_stream(hcl, (hcl_io_outarg_t*)arg);
|
||||
|
||||
case HCL_IO_CLOSE:
|
||||
return close_out_stream(hcl, (hcl_io_udoarg_t*)arg);
|
||||
return close_out_stream(hcl, (hcl_io_outarg_t*)arg);
|
||||
|
||||
case HCL_IO_WRITE:
|
||||
return write_out_stream(hcl, (hcl_io_udoarg_t*)arg);
|
||||
return write_out_stream(hcl, (hcl_io_outarg_t*)arg);
|
||||
|
||||
case HCL_IO_WRITE_BYTES:
|
||||
return write_bytes_out_stream(hcl, (hcl_io_udoarg_t*)arg);
|
||||
return write_bytes_out_stream(hcl, (hcl_io_outarg_t*)arg);
|
||||
|
||||
case HCL_IO_FLUSH:
|
||||
return flush_out_stream(hcl, (hcl_io_udoarg_t*)arg);
|
||||
return flush_out_stream(hcl, (hcl_io_outarg_t*)arg);
|
||||
|
||||
default:
|
||||
hcl_seterrnum (hcl, HCL_EINTERN);
|
||||
|
Loading…
x
Reference in New Issue
Block a user