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:
2012-11-29 14:03:59 +00:00
parent 2f96252ddd
commit 7dd9e67cd8
36 changed files with 889 additions and 792 deletions

View File

@ -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(),

View File

@ -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;

View File

@ -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;
}

View File

@ -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;

View File

@ -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;

View File

@ -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,

View File

@ -31,8 +31,6 @@
#define STRSIZE 4096
#define ARRSIZE 128
QSE_IMPLEMENT_COMMON_FUNCTIONS(env)
static int load_curenv (qse_env_t* env);
static int insert_sys_wcs (qse_env_t* env, const qse_wchar_t* name);
static int insert_sys_mbs (qse_env_t* env, const qse_mchar_t* name);
@ -75,6 +73,16 @@ void qse_env_fini (qse_env_t* env)
if (env->str.ptr) QSE_MMGR_FREE (env->mmgr, env->str.ptr);
}
qse_mmgr_t* qse_env_getmmgr (qse_env_t* env)
{
return env->mmgr;
}
void* qse_env_getxtn (qse_env_t* env)
{
return QSE_XTN (env);
}
void qse_env_clear (qse_env_t* env)
{
if (env->str.ptr)

View File

@ -53,8 +53,6 @@ enum
STATUS_NOCLOSE = (1 << 1)
};
QSE_IMPLEMENT_COMMON_FUNCTIONS (fio)
#if defined(_WIN32)
static qse_fio_errnum_t syserr_to_errnum (DWORD e)
{
@ -888,6 +886,16 @@ void qse_fio_fini (qse_fio_t* fio)
}
}
qse_mmgr_t* qse_fio_getmmgr (qse_fio_t* fio)
{
return fio->mmgr;
}
void* qse_fio_getxtn (qse_fio_t* fio)
{
return QSE_XTN (fio);
}
qse_fio_errnum_t qse_fio_geterrnum (const qse_fio_t* fio)
{
return fio->errnum;

View File

@ -54,8 +54,6 @@ struct qse_xma_blk_t
} b;
};
QSE_IMPLEMENT_COMMON_FUNCTIONS (xma)
static QSE_INLINE_ALWAYS qse_size_t szlog2 (qse_size_t n)
{
/*
@ -183,6 +181,16 @@ void qse_xma_fini (qse_xma_t* xma)
QSE_MMGR_FREE (xma->mmgr, xma->head);
}
qse_mmgr_t* qse_xma_getmmgr (qse_xma_t* xma)
{
return xma->mmgr;
}
void* qse_xma_getxtn (qse_xma_t* xma)
{
return QSE_XTN (xma);
}
static QSE_INLINE void attach_to_freelist (qse_xma_t* xma, qse_xma_blk_t* b)
{
/*