added qse_awk_rtx_isnilval().
enhanced the qse_awk_sio_t core functions so that the implementaion can set the stream name added export specifiers to some functions
This commit is contained in:
@ -1512,9 +1512,8 @@ void* StdAwk::modsym (void* handle, const qse_char_t* name)
|
||||
int StdAwk::SourceFile::open (Data& io)
|
||||
{
|
||||
qse_sio_t* sio;
|
||||
const char_t* ioname = io.getName();
|
||||
|
||||
if (ioname == QSE_NULL)
|
||||
if (!(io.getFlags() & QSE_AWK_SIO_INCLUDED))
|
||||
{
|
||||
// open the main source file.
|
||||
|
||||
@ -1552,14 +1551,20 @@ int StdAwk::SourceFile::open (Data& io)
|
||||
dir.len = base - this->name;
|
||||
}
|
||||
}
|
||||
|
||||
io.setName (this->name);
|
||||
}
|
||||
else
|
||||
{
|
||||
// open an included file
|
||||
const char_t* file = ioname;
|
||||
const char_t* ioname, * file;
|
||||
char_t fbuf[64];
|
||||
char_t* dbuf = QSE_NULL;
|
||||
|
||||
ioname = io.getName();
|
||||
QSE_ASSERT (ioname != QSE_NULL);
|
||||
|
||||
file = ioname;
|
||||
if (dir.len > 0 && ioname[0] != QSE_T('/'))
|
||||
{
|
||||
size_t tmplen, totlen;
|
||||
@ -1622,9 +1627,8 @@ StdAwk::ssize_t StdAwk::SourceFile::write (Data& io, const char_t* buf, size_t l
|
||||
int StdAwk::SourceString::open (Data& io)
|
||||
{
|
||||
qse_sio_t* sio;
|
||||
const char_t* ioname = io.getName();
|
||||
|
||||
if (ioname == QSE_NULL)
|
||||
if (!(io.getFlags() & QSE_AWK_SIO_INCLUDED))
|
||||
{
|
||||
// open the main source file.
|
||||
// SourceString does not support writing.
|
||||
@ -1633,6 +1637,8 @@ int StdAwk::SourceString::open (Data& io)
|
||||
}
|
||||
else
|
||||
{
|
||||
const char_t* ioname = io.getName();
|
||||
|
||||
// open an included file
|
||||
sio = qse_sio_open (
|
||||
((Awk*)io)->getMmgr(),
|
||||
|
@ -404,6 +404,8 @@ int qse_awk_clear (qse_awk_t* awk)
|
||||
awk->sio.last.file = QSE_NULL;
|
||||
awk->sio.nungots = 0;
|
||||
|
||||
awk->sio.arg.flags = 0;
|
||||
awk->sio.arg.name = QSE_NULL;
|
||||
awk->sio.arg.line = 1;
|
||||
awk->sio.arg.colm = 1;
|
||||
awk->sio.arg.b.pos = 0;
|
||||
|
@ -741,6 +741,7 @@ static int begin_include (qse_awk_t* awk)
|
||||
goto oops;
|
||||
}
|
||||
|
||||
arg->flags = QSE_AWK_SIO_INCLUDED;
|
||||
arg->name = QSE_HTB_KPTR(pair);
|
||||
|
||||
CLRERR (awk);
|
||||
@ -765,7 +766,8 @@ static int begin_include (qse_awk_t* awk)
|
||||
if (get_char (awk) <= -1 || get_token (awk) <= -1)
|
||||
{
|
||||
end_include (awk);
|
||||
/* since i've called end_include(), i don't go to oops */
|
||||
/* i don't jump to oops since i've called
|
||||
* end_include() where awk->sio.inp/arg is freed. */
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -716,23 +716,37 @@ static int open_parsestd (qse_awk_t* awk, xtn_t* xtn, qse_size_t index)
|
||||
static qse_ssize_t sf_in_open (
|
||||
qse_awk_t* awk, qse_awk_sio_arg_t* arg, xtn_t* xtn)
|
||||
{
|
||||
if (arg == QSE_NULL || arg->name == QSE_NULL)
|
||||
if (arg == QSE_NULL || !(arg->flags & QSE_AWK_SIO_INCLUDED))
|
||||
{
|
||||
/* handle normal source input streams specified
|
||||
* to qse_awk_parsestd() */
|
||||
|
||||
qse_ssize_t x;
|
||||
x = open_parsestd (awk, xtn, 0);
|
||||
if (x >= 0) xtn->s.in.xindex = 0; /* update the current stream index */
|
||||
if (x >= 0)
|
||||
{
|
||||
xtn->s.in.xindex = 0; /* update the current stream index */
|
||||
/* perform some manipulation about the top-level input information */
|
||||
if (xtn->s.in.x[0].type == QSE_AWK_PARSESTD_FILE)
|
||||
awk->sio.arg.name = xtn->s.in.x[0].u.file.path;
|
||||
else
|
||||
awk->sio.arg.name = QSE_NULL;
|
||||
awk->sio.arg.line = 1;
|
||||
awk->sio.arg.colm = 1;
|
||||
}
|
||||
|
||||
return x;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* handle the included source file - @include */
|
||||
const qse_char_t* file = arg->name;
|
||||
const qse_char_t* file;
|
||||
qse_char_t fbuf[64];
|
||||
qse_char_t* dbuf = QSE_NULL;
|
||||
|
||||
QSE_ASSERT (arg->name != QSE_NULL);
|
||||
|
||||
file = arg->name;
|
||||
if (xtn->s.in.u.file.dir.len > 0 && arg->name[0] != QSE_T('/'))
|
||||
{
|
||||
qse_size_t tmplen, totlen;
|
||||
@ -778,7 +792,7 @@ static qse_ssize_t sf_in_open (
|
||||
static qse_ssize_t sf_in_close (
|
||||
qse_awk_t* awk, qse_awk_sio_arg_t* arg, xtn_t* xtn)
|
||||
{
|
||||
if (arg == QSE_NULL || arg->name == QSE_NULL)
|
||||
if (arg == QSE_NULL || !(arg->flags & QSE_AWK_SIO_INCLUDED))
|
||||
{
|
||||
switch (xtn->s.in.x[xtn->s.in.xindex].type)
|
||||
{
|
||||
@ -810,7 +824,7 @@ static qse_ssize_t sf_in_read (
|
||||
qse_char_t* data, qse_size_t size, xtn_t* xtn)
|
||||
{
|
||||
|
||||
if (arg == QSE_NULL || arg->name == QSE_NULL)
|
||||
if (arg == QSE_NULL || !(arg->flags & QSE_AWK_SIO_INCLUDED))
|
||||
{
|
||||
qse_ssize_t n;
|
||||
|
||||
@ -864,6 +878,15 @@ static qse_ssize_t sf_in_read (
|
||||
{
|
||||
/* if successful, close the current stream */
|
||||
xtn->s.in.xindex = next; /* update the next to the current */
|
||||
|
||||
/* perform some manipulation about the top-level input information */
|
||||
if (xtn->s.in.x[next].type == QSE_AWK_PARSESTD_FILE)
|
||||
awk->sio.arg.name = xtn->s.in.x[next].u.file.path;
|
||||
else
|
||||
awk->sio.arg.name = QSE_NULL;
|
||||
awk->sio.arg.line = 1;
|
||||
awk->sio.arg.colm = 1;
|
||||
|
||||
goto again;
|
||||
}
|
||||
}
|
||||
@ -876,7 +899,9 @@ static qse_ssize_t sf_in_read (
|
||||
/* handle the included source file - @include */
|
||||
qse_ssize_t n;
|
||||
|
||||
QSE_ASSERT (arg->name != QSE_NULL);
|
||||
QSE_ASSERT (arg->handle != QSE_NULL);
|
||||
|
||||
n = qse_sio_getstrn (arg->handle, data, size);
|
||||
if (n <= -1)
|
||||
{
|
||||
@ -2519,8 +2544,7 @@ done:
|
||||
return ret;
|
||||
}
|
||||
|
||||
qse_cmgr_t* qse_awk_rtx_getcmgrstd (
|
||||
qse_awk_rtx_t* rtx, const qse_char_t* ioname)
|
||||
qse_cmgr_t* qse_awk_rtx_getcmgrstd (qse_awk_rtx_t* rtx, const qse_char_t* ioname)
|
||||
{
|
||||
#if defined(QSE_CHAR_IS_WCHAR)
|
||||
rxtn_t* rxtn;
|
||||
|
@ -63,6 +63,11 @@ qse_awk_val_t* qse_awk_val_negone = (qse_awk_val_t*)&awk_int[0];
|
||||
qse_awk_val_t* qse_awk_val_zero = (qse_awk_val_t*)&awk_int[1];
|
||||
qse_awk_val_t* qse_awk_val_one = (qse_awk_val_t*)&awk_int[2];
|
||||
|
||||
int qse_awk_rtx_isnilval (qse_awk_rtx_t* rtx, qse_awk_val_t* val)
|
||||
{
|
||||
return val->type == QSE_AWK_VAL_NIL;
|
||||
}
|
||||
|
||||
qse_awk_val_t* qse_awk_rtx_makenilval (qse_awk_rtx_t* rtx)
|
||||
{
|
||||
return (qse_awk_val_t*)&awk_nil;
|
||||
|
@ -54,6 +54,22 @@ struct qse_awk_val_rchunk_t
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* represents a nil value */
|
||||
extern qse_awk_val_t* qse_awk_val_nil;
|
||||
|
||||
/* represents an empty string */
|
||||
extern qse_awk_val_t* qse_awk_val_zls;
|
||||
|
||||
/* represents a numeric value -1 */
|
||||
extern qse_awk_val_t* qse_awk_val_negone;
|
||||
|
||||
/* represents a numeric value 0 */
|
||||
extern qse_awk_val_t* qse_awk_val_zero;
|
||||
|
||||
/* represents a numeric value 1 */
|
||||
extern qse_awk_val_t* qse_awk_val_one;
|
||||
|
||||
|
||||
void qse_awk_rtx_freeval (
|
||||
qse_awk_rtx_t* rtx,
|
||||
qse_awk_val_t* val,
|
||||
|
Reference in New Issue
Block a user