enhanced module handling
This commit is contained in:
@ -2012,10 +2012,10 @@ Awk::flt_t Awk::sqrt (awk_t* awk, flt_t x)
|
||||
return xtn->awk->sqrt (x);
|
||||
}
|
||||
|
||||
void* Awk::modopen (awk_t* awk, const char_t* dir, const char_t* name)
|
||||
void* Awk::modopen (awk_t* awk, const mod_info_t* info)
|
||||
{
|
||||
xtn_t* xtn = (xtn_t*) QSE_XTN (awk);
|
||||
return xtn->awk->modopen (dir, name);
|
||||
return xtn->awk->modopen (info);
|
||||
}
|
||||
|
||||
void Awk::modclose (awk_t* awk, void* handle)
|
||||
|
@ -3,8 +3,15 @@ AUTOMAKE_OPTIONS = nostdinc
|
||||
AM_CPPFLAGS = \
|
||||
-I$(top_builddir)/include \
|
||||
-I$(top_srcdir)/include \
|
||||
-I$(includedir) \
|
||||
-DDEFAULT_MODDIR=\"$(libdir)\" $(LTDLINCL)
|
||||
-I$(includedir) $(LTDLINCL)
|
||||
|
||||
if WIN32
|
||||
# you must adjust the value of DEFAULT_MODPOSTFIX according to
|
||||
# -version-info in ../../mod/awk/Makefile.am
|
||||
AM_CPPFLAGS += -DDEFAULT_MODPREFIX=\"libqseawk-\" -DDEFAULT_MODPOSTFIX=\"-1\"
|
||||
else
|
||||
AM_CPPFLAGS += -DDEFAULT_MODPREFIX=\"$(libdir)/libqseawk-\" -DDEFAULT_MODPOSTFIX=\"\"
|
||||
endif
|
||||
|
||||
lib_LTLIBRARIES = libqseawk.la
|
||||
libqseawk_la_SOURCES = awk.c err.c tree.c parse.c run.c rec.c val.c fnc.c misc.c rio.c std.c awk.h err.h rio.h val.h fnc.h misc.h parse.h run.h tree.h
|
||||
|
@ -34,7 +34,12 @@ PRE_UNINSTALL = :
|
||||
POST_UNINSTALL = :
|
||||
build_triplet = @build@
|
||||
host_triplet = @host@
|
||||
@ENABLE_CXX_TRUE@am__append_1 = libqseawkxx.la
|
||||
|
||||
# you must adjust the value of DEFAULT_MODPOSTFIX according to
|
||||
# -version-info in ../../mod/awk/Makefile.am
|
||||
@WIN32_TRUE@am__append_1 = -DDEFAULT_MODPREFIX=\"libqseawk-\" -DDEFAULT_MODPOSTFIX=\"-1\"
|
||||
@WIN32_FALSE@am__append_2 = -DDEFAULT_MODPREFIX=\"$(libdir)/libqseawk-\" -DDEFAULT_MODPOSTFIX=\"\"
|
||||
@ENABLE_CXX_TRUE@am__append_3 = libqseawkxx.la
|
||||
subdir = lib/awk
|
||||
DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in
|
||||
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
|
||||
@ -297,13 +302,9 @@ top_build_prefix = @top_build_prefix@
|
||||
top_builddir = @top_builddir@
|
||||
top_srcdir = @top_srcdir@
|
||||
AUTOMAKE_OPTIONS = nostdinc
|
||||
AM_CPPFLAGS = \
|
||||
-I$(top_builddir)/include \
|
||||
-I$(top_srcdir)/include \
|
||||
-I$(includedir) \
|
||||
-DDEFAULT_MODDIR=\"$(libdir)\" $(LTDLINCL)
|
||||
|
||||
lib_LTLIBRARIES = libqseawk.la $(am__append_1)
|
||||
AM_CPPFLAGS = -I$(top_builddir)/include -I$(top_srcdir)/include \
|
||||
-I$(includedir) $(LTDLINCL) $(am__append_1) $(am__append_2)
|
||||
lib_LTLIBRARIES = libqseawk.la $(am__append_3)
|
||||
libqseawk_la_SOURCES = awk.c err.c tree.c parse.c run.c rec.c val.c fnc.c misc.c rio.c std.c awk.h err.h rio.h val.h fnc.h misc.h parse.h run.h tree.h
|
||||
libqseawk_la_LDFLAGS = -L../cmn -L$(libdir) -version-info 1:0:0 -no-undefined
|
||||
libqseawk_la_LIBADD = -lqsecmn $(LIBM) $(LIBLTDL)
|
||||
|
@ -1394,22 +1394,19 @@ StdAwk::flt_t StdAwk::sqrt (flt_t x)
|
||||
#endif
|
||||
}
|
||||
|
||||
void* StdAwk::modopen (const qse_char_t* dir, const qse_char_t* name)
|
||||
void* StdAwk::modopen (const mod_info_t* info)
|
||||
{
|
||||
#if defined(USE_LTDL)
|
||||
|
||||
void* h;
|
||||
qse_mchar_t* modpath;
|
||||
const qse_char_t* tmp[5];
|
||||
int count = 0;
|
||||
const qse_char_t* tmp[4];
|
||||
int count;
|
||||
|
||||
if (dir && dir[0] != QSE_T('\0'))
|
||||
{
|
||||
tmp[count++] = dir;
|
||||
tmp[count++] = QSE_T("/");
|
||||
}
|
||||
tmp[count++] = QSE_T("libqseawk-");
|
||||
tmp[count++] = name;
|
||||
count = 0;
|
||||
if (info->prefix) tmp[count++] = info->prefix;
|
||||
tmp[count++] = info->name;
|
||||
if (info->postfix) tmp[count++] = info->postfix;
|
||||
tmp[count] = QSE_NULL;
|
||||
|
||||
#if defined(QSE_CHAR_IS_MCHAR)
|
||||
@ -1430,14 +1427,66 @@ void* StdAwk::modopen (const qse_char_t* dir, const qse_char_t* name)
|
||||
return h;
|
||||
|
||||
#elif defined(_WIN32)
|
||||
/*TODO: implemente this - use LoadLibrary... */
|
||||
this->setError (QSE_AWK_ENOIMPL);
|
||||
return QSE_NULL;
|
||||
|
||||
HMODULE h;
|
||||
qse_char_t* path;
|
||||
const qse_char_t* tmp[4];
|
||||
int count;
|
||||
|
||||
count = 0;
|
||||
if (info->prefix) tmp[count++] = info->prefix;
|
||||
tmp[count++] = info->name;
|
||||
if (info->postfix) tmp[count++] = info->postfix;
|
||||
tmp[count] = QSE_NULL;
|
||||
|
||||
path = qse_stradup (tmp, QSE_NULL, this->getMmgr());
|
||||
if (!path)
|
||||
{
|
||||
this->setError (QSE_AWK_ENOMEM);
|
||||
return QSE_NULL;
|
||||
}
|
||||
|
||||
h = LoadLibrary (path);
|
||||
|
||||
QSE_MMGR_FREE (awk->mmgr, path);
|
||||
|
||||
QSE_ASSERT (QSE_SIZEOF(h) <= QSE_SIZEOF(void*));
|
||||
return h;
|
||||
|
||||
#elif defined(__OS2__)
|
||||
/*TODO: implemente this */
|
||||
this->setError (QSE_AWK_ENOIMPL);
|
||||
return QSE_NULL;
|
||||
|
||||
void* h;
|
||||
qse_mchar_t* modpath;
|
||||
const qse_char_t* tmp[4];
|
||||
int count;
|
||||
UCHAR errbuf[CCHMAXPATH];
|
||||
|
||||
count = 0;
|
||||
if (info->prefix) tmp[count++] = info->prefix;
|
||||
tmp[count++] = info->name;
|
||||
if (info->postfix) tmp[count++] = info->postfix;
|
||||
tmp[count] = QSE_NULL;
|
||||
|
||||
#if defined(QSE_CHAR_IS_MCHAR)
|
||||
modpath = qse_mbsadup (tmp, QSE_NULL, this->getMmgr());
|
||||
#else
|
||||
modpath = qse_wcsatombsdup (tmp, QSE_NULL, this->getMmgr());
|
||||
#endif
|
||||
if (!modpath)
|
||||
{
|
||||
this->setError (QSE_AWK_ENOMEM);
|
||||
return QSE_NULL;
|
||||
}
|
||||
|
||||
if (DosLoadModule (errbuf, QSE_COUNTOF(errbuf) - 1, modpath, &h) != NO_ERROR) h = QSE_NULL;
|
||||
|
||||
QSE_MMGR_FREE (awk->mmgr, modpath);
|
||||
|
||||
QSE_ASSERT (QSE_SIZEOF(h) <= QSE_SIZEOF(void*));
|
||||
return h;
|
||||
|
||||
#elif defined(__DOS__)
|
||||
|
||||
/*TODO: implemente this */
|
||||
this->setError (QSE_AWK_ENOIMPL);
|
||||
return QSE_NULL;
|
||||
@ -1456,7 +1505,7 @@ void StdAwk::modclose (void* handle)
|
||||
#elif defined(_WIN32)
|
||||
FreeLibrary ((HMODULE)handle);
|
||||
#elif defined(__OS2__)
|
||||
/*TODO: implemente this */
|
||||
DosFreeModule ((HMODULE)handle);
|
||||
#elif defined(__DOS__)
|
||||
/*TODO: implemente this */
|
||||
#else
|
||||
@ -1469,24 +1518,23 @@ void* StdAwk::modsym (void* handle, const qse_char_t* name)
|
||||
void* s;
|
||||
qse_mchar_t* mname;
|
||||
|
||||
#if defined(QSE_CHAR_IS_MCHAR)
|
||||
#if defined(QSE_CHAR_IS_MCHAR)
|
||||
mname = name;
|
||||
#else
|
||||
#else
|
||||
mname = qse_wcstombsdup (name, QSE_NULL, this->getMmgr());
|
||||
if (!mname)
|
||||
{
|
||||
this->setError (QSE_AWK_ENOMEM);
|
||||
return QSE_NULL;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(USE_LTDL)
|
||||
s = lt_dlsym ((lt_dlhandle)handle, mname);
|
||||
#elif defined(_WIN32)
|
||||
s = (void*)GetProcAddress ((HMODULE)handle, mname);
|
||||
#elif defined(__OS2__)
|
||||
/*TODO: implemente this */
|
||||
s = QSE_NULL;
|
||||
if (DosQueryProcAddr ((HMODULE)handle, 0, mname, (PFN*)&s) != NO_ERROR) s = QSE_NULL;
|
||||
#elif defined(__DOS__)
|
||||
/*TODO: implemente this */
|
||||
s = QSE_NULL;
|
||||
@ -1494,11 +1542,11 @@ void* StdAwk::modsym (void* handle, const qse_char_t* name)
|
||||
s = QSE_NULL;
|
||||
#endif
|
||||
|
||||
#if defined(QSE_CHAR_IS_MCHAR)
|
||||
#if defined(QSE_CHAR_IS_MCHAR)
|
||||
/* nothing to do */
|
||||
#else
|
||||
#else
|
||||
QSE_MMGR_FREE (awk->mmgr, mname);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
return s;
|
||||
|
||||
|
@ -269,6 +269,7 @@ oops:
|
||||
int qse_awk_close (qse_awk_t* awk)
|
||||
{
|
||||
qse_awk_ecb_t* ecb;
|
||||
int i;
|
||||
|
||||
if (qse_awk_clear (awk) <= -1) return -1;
|
||||
/*qse_awk_clrfnc (awk);*/
|
||||
@ -293,8 +294,11 @@ int qse_awk_close (qse_awk_t* awk)
|
||||
fini_token (&awk->ptok);
|
||||
|
||||
/* destroy dynamically allocated options */
|
||||
if (awk->opt.moddir.ptr)
|
||||
QSE_MMGR_FREE (awk->mmgr, awk->opt.moddir.ptr);
|
||||
for (i = 0; i < QSE_COUNTOF(awk->opt.mod); i++)
|
||||
{
|
||||
if (awk->opt.mod[i].ptr)
|
||||
QSE_MMGR_FREE (awk->mmgr, awk->opt.mod[i].ptr);
|
||||
}
|
||||
|
||||
/* QSE_AWK_ALLOC, QSE_AWK_FREE, etc can not be used
|
||||
* from the next line onwards */
|
||||
@ -436,10 +440,13 @@ int qse_awk_setopt (qse_awk_t* awk, qse_awk_opt_t id, const void* value)
|
||||
awk->opt.trait = *(const int*)value;
|
||||
return 0;
|
||||
|
||||
case QSE_AWK_MODDIR:
|
||||
case QSE_AWK_MODPREFIX:
|
||||
case QSE_AWK_MODPOSTFIX:
|
||||
{
|
||||
qse_xstr_t tmp;
|
||||
int idx;
|
||||
|
||||
idx = id - QSE_AWK_MODPREFIX;
|
||||
if (value)
|
||||
{
|
||||
tmp.ptr = qse_strdup (value, awk->mmgr);
|
||||
@ -456,10 +463,10 @@ int qse_awk_setopt (qse_awk_t* awk, qse_awk_opt_t id, const void* value)
|
||||
tmp.len = 0;
|
||||
}
|
||||
|
||||
if (awk->opt.moddir.ptr)
|
||||
QSE_MMGR_FREE (awk->mmgr, awk->opt.moddir.ptr);
|
||||
if (awk->opt.mod[idx].ptr)
|
||||
QSE_MMGR_FREE (awk->mmgr, awk->opt.mod[idx].ptr);
|
||||
|
||||
awk->opt.moddir = tmp;
|
||||
awk->opt.mod[idx] = tmp;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -486,11 +493,11 @@ int qse_awk_getopt (qse_awk_t* awk, qse_awk_opt_t id, void* value)
|
||||
*(int*)value = awk->opt.trait;
|
||||
return 0;
|
||||
|
||||
case QSE_AWK_MODDIR:
|
||||
*(const qse_char_t**)value = awk->opt.moddir.ptr;
|
||||
case QSE_AWK_MODPREFIX:
|
||||
case QSE_AWK_MODPOSTFIX:
|
||||
*(const qse_char_t**)value = awk->opt.mod[id - QSE_AWK_MODPREFIX].ptr;
|
||||
return 0;
|
||||
|
||||
|
||||
case QSE_AWK_DEPTH_INCLUDE:
|
||||
case QSE_AWK_DEPTH_BLOCK_PARSE:
|
||||
case QSE_AWK_DEPTH_BLOCK_RUN:
|
||||
|
@ -123,7 +123,7 @@ struct qse_awk_t
|
||||
struct
|
||||
{
|
||||
int trait;
|
||||
qse_xstr_t moddir;
|
||||
qse_xstr_t mod[2];
|
||||
|
||||
union
|
||||
{
|
||||
|
@ -25,9 +25,6 @@ enum tok_t
|
||||
TOK_EOF,
|
||||
TOK_NEWLINE,
|
||||
|
||||
/* special token to direct the parser to include a file specified */
|
||||
TOK_INCLUDE,
|
||||
|
||||
/* TOK_XXX_ASSNs should be in sync with assop in assign_to_opcode.
|
||||
* it also should be in the order as qse_awk_assop_type_t in run.h */
|
||||
TOK_ASSN,
|
||||
@ -274,7 +271,6 @@ static kwent_t kwtab[] =
|
||||
{ { QSE_T("global"), 6 }, TOK_GLOBAL, QSE_AWK_EXPLICIT },
|
||||
{ { QSE_T("if"), 2 }, TOK_IF, 0 },
|
||||
{ { QSE_T("in"), 2 }, TOK_IN, 0 },
|
||||
{ { QSE_T("include"), 7 }, TOK_INCLUDE, QSE_AWK_EXTRAKWS },
|
||||
{ { QSE_T("local"), 5 }, TOK_LOCAL, QSE_AWK_EXPLICIT },
|
||||
{ { QSE_T("next"), 4 }, TOK_NEXT, QSE_AWK_PABLOCK },
|
||||
{ { QSE_T("nextfile"), 8 }, TOK_NEXTFILE, QSE_AWK_PABLOCK },
|
||||
@ -836,7 +832,8 @@ static int parse_progunit (qse_awk_t* awk)
|
||||
{
|
||||
if (get_token(awk) <= -1) return -1;
|
||||
|
||||
if (MATCH(awk,TOK_INCLUDE)) /* TOOD: INCLUDE must not be a separate keyword... */
|
||||
if (MATCH(awk,TOK_IDENT) &&
|
||||
qse_strcmp (QSE_STR_PTR(awk->tok.name), QSE_T("include")) == 0)
|
||||
{
|
||||
if (awk->opt.depth.s.incl > 0 &&
|
||||
awk->parse.depth.incl >= awk->opt.depth.s.incl)
|
||||
@ -6450,25 +6447,30 @@ static qse_awk_mod_t* query_module (
|
||||
else
|
||||
{
|
||||
qse_awk_mod_load_t load;
|
||||
const qse_char_t* moddir;
|
||||
qse_awk_mod_info_t info;
|
||||
qse_awk_mod_data_t md;
|
||||
|
||||
if (awk->opt.moddir.len > 0)
|
||||
{
|
||||
moddir = awk->opt.moddir.ptr;
|
||||
}
|
||||
#if defined(DEFAULT_MODDIR)
|
||||
else
|
||||
{
|
||||
moddir = QSE_T(DEFAULT_MODDIR);
|
||||
}
|
||||
QSE_MEMSET (&info, 0, QSE_SIZEOF(info));
|
||||
|
||||
if (awk->opt.mod[0].len > 0)
|
||||
info.prefix = awk->opt.mod[0].ptr;
|
||||
#if defined(DEFAULT_MODPREFIX)
|
||||
else info.prefix = QSE_T(DEFAULT_MODPREFIX);
|
||||
#endif
|
||||
|
||||
if (awk->opt.mod[1].len > 0)
|
||||
info.postfix = awk->opt.mod[1].ptr;
|
||||
#if defined(DEFAULT_MODPOSTFIX)
|
||||
else info.postfix = QSE_T(DEFAULT_MODPOSTFIX);
|
||||
#endif
|
||||
|
||||
QSE_MEMSET (&md, 0, QSE_SIZEOF(md));
|
||||
if (awk->prm.modopen && awk->prm.modsym && awk->prm.modclose)
|
||||
md.handle = awk->prm.modopen (awk, moddir, segs[0].ptr);
|
||||
else
|
||||
md.handle = QSE_NULL;
|
||||
{
|
||||
info.name = segs[0].ptr;
|
||||
md.handle = awk->prm.modopen (awk, &info);
|
||||
}
|
||||
else md.handle = QSE_NULL;
|
||||
|
||||
if (!md.handle)
|
||||
{
|
||||
|
@ -46,6 +46,7 @@
|
||||
# endif
|
||||
#elif defined(__OS2__)
|
||||
# define INCL_DOSMODULEMGR
|
||||
# define INCL_DOSPROCESS
|
||||
# define INCL_DOSERRORS
|
||||
# include <os2.h>
|
||||
#elif defined(__DOS__)
|
||||
@ -314,23 +315,18 @@ static int custom_awk_sprintf (
|
||||
return n;
|
||||
}
|
||||
|
||||
static void* custom_awk_modopen (
|
||||
qse_awk_t* awk, const qse_char_t* dir, const qse_char_t* name)
|
||||
static void* custom_awk_modopen (qse_awk_t* awk, const qse_awk_mod_info_t* info)
|
||||
{
|
||||
#if defined(USE_LTDL)
|
||||
void* h;
|
||||
qse_mchar_t* modpath;
|
||||
const qse_char_t* tmp[6];
|
||||
const qse_char_t* tmp[4];
|
||||
int count;
|
||||
|
||||
count = 0;
|
||||
if (dir && dir[0] != QSE_T('\0'))
|
||||
{
|
||||
tmp[count++] = dir;
|
||||
tmp[count++] = QSE_T("/");
|
||||
}
|
||||
tmp[count++] = QSE_T("libqseawk-");
|
||||
tmp[count++] = name;
|
||||
if (info->prefix) tmp[count++] = info->prefix;
|
||||
tmp[count++] = info->name;
|
||||
if (info->postfix) tmp[count++] = info->postfix;
|
||||
tmp[count] = QSE_NULL;
|
||||
|
||||
#if defined(QSE_CHAR_IS_MCHAR)
|
||||
@ -351,19 +347,16 @@ static void* custom_awk_modopen (
|
||||
return h;
|
||||
|
||||
#elif defined(_WIN32)
|
||||
|
||||
HMODULE h;
|
||||
qse_char_t* path;
|
||||
const qse_char_t* tmp[5];
|
||||
int count = 0;
|
||||
const qse_char_t* tmp[4];
|
||||
int count;
|
||||
|
||||
if (dir && dir[0] != QSE_T('\0'))
|
||||
{
|
||||
tmp[count++] = dir;
|
||||
tmp[count++] = QSE_T("/");
|
||||
}
|
||||
|
||||
tmp[count++] = QSE_T("libqseawk-");
|
||||
tmp[count++] = name;
|
||||
count = 0;
|
||||
if (info->prefix) tmp[count++] = info->prefix;
|
||||
tmp[count++] = info->name;
|
||||
if (info->postfix) tmp[count++] = info->postfix;
|
||||
tmp[count] = QSE_NULL;
|
||||
|
||||
path = qse_stradup (tmp, QSE_NULL, awk->mmgr);
|
||||
@ -377,21 +370,21 @@ static void* custom_awk_modopen (
|
||||
|
||||
QSE_MMGR_FREE (awk->mmgr, path);
|
||||
|
||||
QSE_ASSERT (QSE_SIZEOF(h) <= QSE_SIZEOF(void*));
|
||||
return h;
|
||||
|
||||
#elif defined(__OS2__)
|
||||
|
||||
HMODULE h;
|
||||
qse_mchar_t* modpath;
|
||||
const qse_char_t* tmp[6];
|
||||
const qse_char_t* tmp[4];
|
||||
int count;
|
||||
UCHAR errbuf[CCHMAXPATH];
|
||||
|
||||
count = 0;
|
||||
if (dir && dir[0] != QSE_T('\0'))
|
||||
{
|
||||
tmp[count++] = dir;
|
||||
tmp[count++] = QSE_T("/");
|
||||
}
|
||||
tmp[count++] = QSE_T("libqseawk-");
|
||||
tmp[count++] = name;
|
||||
if (info->prefix) tmp[count++] = info->prefix;
|
||||
tmp[count++] = info->name;
|
||||
if (info->postfix) tmp[count++] = info->postfix;
|
||||
tmp[count] = QSE_NULL;
|
||||
|
||||
#if defined(QSE_CHAR_IS_MCHAR)
|
||||
@ -405,10 +398,11 @@ static void* custom_awk_modopen (
|
||||
return QSE_NULL;
|
||||
}
|
||||
|
||||
if (DosLoadModule (errbuf, QSE_COUNTOF(errbuf), modpath, &h) != NO_ERROR) h = QSE_NULL;
|
||||
if (DosLoadModule (errbuf, QSE_COUNTOF(errbuf) - 1, modpath, &h) != NO_ERROR) h = QSE_NULL;
|
||||
|
||||
QSE_MMGR_FREE (awk->mmgr, modpath);
|
||||
|
||||
QSE_ASSERT (QSE_SIZEOF(h) <= QSE_SIZEOF(void*));
|
||||
return h;
|
||||
|
||||
#elif defined(__DOS__)
|
||||
@ -452,7 +446,7 @@ static void* custom_awk_modsym (qse_awk_t* awk, void* handle, const qse_char_t*
|
||||
qse_awk_seterrnum (awk, QSE_AWK_ENOMEM, QSE_NULL);
|
||||
return QSE_NULL;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(USE_LTDL)
|
||||
s = lt_dlsym (handle, mname);
|
||||
|
Reference in New Issue
Block a user