diff --git a/qse/include/qse/awk/Awk.hpp b/qse/include/qse/awk/Awk.hpp index f112bb18..ccbf179c 100644 --- a/qse/include/qse/awk/Awk.hpp +++ b/qse/include/qse/awk/Awk.hpp @@ -364,6 +364,8 @@ public: class QSE_EXPORT Handler { public: + virtual ~Handler () {} + virtual int open (Pipe& io) = 0; virtual int close (Pipe& io) = 0; virtual ssize_t read (Pipe& io, char_t* buf, size_t len) = 0; @@ -406,6 +408,8 @@ public: class QSE_EXPORT Handler { public: + virtual ~Handler () {} + virtual int open (File& io) = 0; virtual int close (File& io) = 0; virtual ssize_t read (File& io, char_t* buf, size_t len) = 0; @@ -442,6 +446,8 @@ public: class QSE_EXPORT Handler { public: + virtual ~Handler () {} + /// The open() function is called before the initial /// access to the console for input and output. /// It must return 0 for success and -1 for failure. diff --git a/qse/lib/awk/StdAwk.cpp b/qse/lib/awk/StdAwk.cpp index 75a0f56a..caf7b25d 100644 --- a/qse/lib/awk/StdAwk.cpp +++ b/qse/lib/awk/StdAwk.cpp @@ -27,15 +27,7 @@ #include #include #include "awk.h" - -#include -#include - -#if defined(HAVE_QUADMATH_H) -extern "C" { // some gcc distros don't have extern "C" declared in the header file. -# include -} -#endif +#include "std.h" #if defined(_WIN32) # include @@ -1098,228 +1090,33 @@ void StdAwk::freeMem (void* ptr) StdAwk::flt_t StdAwk::pow (flt_t x, flt_t y) { -#if defined(QSE_USE_AWK_FLTMAX) && defined(HAVE_POWQ) - return ::powq (x, y); -#elif defined(HAVE_POWL) && (QSE_SIZEOF_LONG_DOUBLE > QSE_SIZEOF_DOUBLE) - return ::powl (x, y); -#elif defined(HAVE_POW) - return ::pow (x, y); -#elif defined(HAVE_POWF) - return ::powf (x, y); -#else - #error ### no pow function available ### -#endif + return qse_awk_stdmathpow (this->awk, x, y); } StdAwk::flt_t StdAwk::mod (flt_t x, flt_t y) { -#if defined(QSE_USE_AWK_FLTMAX) && defined(HAVE_FMODQ) - return ::fmodq (x, y); -#elif defined(HAVE_FMODL) && (QSE_SIZEOF_LONG_DOUBLE > QSE_SIZEOF_DOUBLE) - return ::fmodl (x, y); -#elif defined(HAVE_FMOD) - return ::fmod (x, y); -#elif defined(HAVE_FMODF) - return ::fmodf (x, y); -#else - #error ### no fmod function available ### -#endif + return qse_awk_stdmathmod (this->awk, x, y); } void* StdAwk::modopen (const mod_spec_t* spec) { -#if defined(QSE_ENABLE_STATIC_MODULE) - /* this won't be called at all when modules are linked into - * the main library. */ - this->setError (QSE_AWK_ENOIMPL); - return QSE_NULL; - -#elif defined(USE_LTDL) - void* h; - qse_mchar_t* modpath; - const qse_char_t* tmp[4]; - int count; - - count = 0; - if (spec->prefix) tmp[count++] = spec->prefix; - tmp[count++] = spec->name; - if (spec->postfix) tmp[count++] = spec->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; - } - - h = lt_dlopenext (modpath); - - QSE_MMGR_FREE (awk->mmgr, modpath); - + h = qse_awk_stdmodopen (this->awk, spec); + if (!h) this->retrieveError (); return h; - -#elif defined(_WIN32) - - HMODULE h; - qse_char_t* modpath; - const qse_char_t* tmp[4]; - int count; - - count = 0; - if (spec->prefix) tmp[count++] = spec->prefix; - tmp[count++] = spec->name; - if (spec->postfix) tmp[count++] = spec->postfix; - tmp[count] = QSE_NULL; - - modpath = qse_stradup (tmp, QSE_NULL, this->getMmgr()); - if (!modpath) - { - this->setError (QSE_AWK_ENOMEM); - return QSE_NULL; - } - - h = LoadLibrary (modpath); - - QSE_MMGR_FREE (awk->mmgr, modpath); - - QSE_ASSERT (QSE_SIZEOF(h) <= QSE_SIZEOF(void*)); - return h; - -#elif defined(__OS2__) - - HMODULE h; - qse_mchar_t* modpath; - const qse_char_t* tmp[4]; - int count; - char errbuf[CCHMAXPATH]; - - count = 0; - if (spec->prefix) tmp[count++] = spec->prefix; - tmp[count++] = spec->name; - if (spec->postfix) tmp[count++] = spec->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 (void*)h; - -#elif defined(__DOS__) - - void* h; - qse_mchar_t* modpath; - const qse_char_t* tmp[4]; - int count; - - count = 0; - if (spec->prefix) tmp[count++] = spec->prefix; - tmp[count++] = spec->name; - if (spec->postfix) tmp[count++] = spec->postfix; - tmp[count] = QSE_NULL; - - #if defined(QSE_CHAR_IS_MCHAR) - modpath = qse_mbsadup (tmp, QSE_NULL, awk->mmgr); - #else - modpath = qse_wcsatombsdup (tmp, QSE_NULL, awk->mmgr); - #endif - if (!modpath) - { - qse_awk_seterrnum (awk, QSE_AWK_ENOMEM, QSE_NULL); - return QSE_NULL; - } - - h = LoadModule (modpath); - - QSE_MMGR_FREE (awk->mmgr, modpath); - - QSE_ASSERT (QSE_SIZEOF(h) <= QSE_SIZEOF(void*)); - return h; - -#else - - this->setError (QSE_AWK_ENOIMPL); - return QSE_NULL; - -#endif } void StdAwk::modclose (void* handle) { -#if defined(QSE_ENABLE_STATIC_MODULE) - /* this won't be called at all when modules are linked into - * the main library. */ -#elif defined(USE_LTDL) - lt_dlclose ((lt_dlhandle)handle); -#elif defined(_WIN32) - FreeLibrary ((HMODULE)handle); -#elif defined(__OS2__) - DosFreeModule ((HMODULE)handle); -#elif defined(__DOS__) - FreeModule (handle); -#else - /* nothing to do */ -#endif + qse_awk_stdmodclose (this->awk, handle); } void* StdAwk::modsym (void* handle, const qse_char_t* name) { void* s; - qse_mchar_t* mname; - -#if defined(QSE_CHAR_IS_MCHAR) - mname = (qse_mchar_t*)name; -#else - mname = qse_wcstombsdup (name, QSE_NULL, this->getMmgr()); - if (!mname) - { - this->setError (QSE_AWK_ENOMEM); - return QSE_NULL; - } -#endif - -#if defined(QSE_ENABLE_STATIC_MODULE) - /* this won't be called at all when modules are linked into - * the main library. */ - s = QSE_NULL; -#elif defined(USE_LTDL) - s = lt_dlsym ((lt_dlhandle)handle, mname); -#elif defined(_WIN32) - s = (void*)GetProcAddress ((HMODULE)handle, mname); -#elif defined(__OS2__) - if (DosQueryProcAddr ((HMODULE)handle, 0, mname, (PFN*)&s) != NO_ERROR) s = QSE_NULL; -#elif defined(__DOS__) - s = GetProcAddress (handle, mname); -#else - s = QSE_NULL; -#endif - -#if defined(QSE_CHAR_IS_MCHAR) - /* nothing to do */ -#else - QSE_MMGR_FREE (awk->mmgr, mname); -#endif - + s = qse_awk_stdmodsym (this->awk, handle, name); + if (!s) this->retrieveError (); return s; - } int StdAwk::SourceFile::open (Data& io) diff --git a/qse/lib/awk/std.c b/qse/lib/awk/std.c index 4307e45b..064724fa 100644 --- a/qse/lib/awk/std.c +++ b/qse/lib/awk/std.c @@ -175,7 +175,7 @@ qse_awk_flt_t qse_awk_stdmathmod (qse_awk_t* awk, qse_awk_flt_t x, qse_awk_flt_t #endif } -static void* custom_awk_modopen (qse_awk_t* awk, const qse_awk_mod_spec_t* spec) +void* qse_awk_stdmodopen (qse_awk_t* awk, const qse_awk_mod_spec_t* spec) { #if defined(QSE_ENABLE_STATIC_MODULE) /* this won't be called at all when modules are linked into @@ -315,7 +315,7 @@ static void* custom_awk_modopen (qse_awk_t* awk, const qse_awk_mod_spec_t* spec) #endif } -static void custom_awk_modclose (qse_awk_t* awk, void* handle) +void qse_awk_stdmodclose (qse_awk_t* awk, void* handle) { #if defined(QSE_ENABLE_STATIC_MODULE) /* this won't be called at all when modules are linked into @@ -333,7 +333,7 @@ static void custom_awk_modclose (qse_awk_t* awk, void* handle) #endif } -static void* custom_awk_modsym (qse_awk_t* awk, void* handle, const qse_char_t* name) +void* qse_awk_stdmodsym (qse_awk_t* awk, void* handle, const qse_char_t* name) { void* s; qse_mchar_t* mname; @@ -409,9 +409,9 @@ qse_awk_t* qse_awk_openstdwithmmgr (qse_mmgr_t* mmgr, qse_size_t xtnsize, qse_aw prm.math.pow = qse_awk_stdmathpow; prm.math.mod = qse_awk_stdmathmod; - prm.modopen = custom_awk_modopen; - prm.modclose = custom_awk_modclose; - prm.modsym = custom_awk_modsym; + prm.modopen = qse_awk_stdmodopen; + prm.modclose = qse_awk_stdmodclose; + prm.modsym = qse_awk_stdmodsym; /* create an object */ awk = qse_awk_open (mmgr, QSE_SIZEOF(xtn_t) + xtnsize, &prm, errnum); diff --git a/qse/lib/awk/std.h b/qse/lib/awk/std.h index a0bb88c0..f20a82d9 100644 --- a/qse/lib/awk/std.h +++ b/qse/lib/awk/std.h @@ -30,6 +30,11 @@ extern "C" { qse_awk_flt_t qse_awk_stdmathpow (qse_awk_t* awk, qse_awk_flt_t x, qse_awk_flt_t y); qse_awk_flt_t qse_awk_stdmathmod (qse_awk_t* awk, qse_awk_flt_t x, qse_awk_flt_t y); +void* qse_awk_stdmodopen (qse_awk_t* awk, const qse_awk_mod_spec_t* spec); +void qse_awk_stdmodclose (qse_awk_t* awk, void* handle); +void* qse_awk_stdmodsym (qse_awk_t* awk, void* handle, const qse_char_t* name); + + #ifdef __cplusplus } #endif