changed StdAwk to use exported functions in std.c
This commit is contained in:
		| @ -364,6 +364,8 @@ public: | |||||||
| 		class QSE_EXPORT Handler  | 		class QSE_EXPORT Handler  | ||||||
| 		{ | 		{ | ||||||
| 		public: | 		public: | ||||||
|  | 			virtual ~Handler () {} | ||||||
|  |  | ||||||
| 			virtual int     open  (Pipe& io) = 0; | 			virtual int     open  (Pipe& io) = 0; | ||||||
| 			virtual int     close (Pipe& io) = 0; | 			virtual int     close (Pipe& io) = 0; | ||||||
| 			virtual ssize_t read  (Pipe& io, char_t* buf, size_t len) = 0; | 			virtual ssize_t read  (Pipe& io, char_t* buf, size_t len) = 0; | ||||||
| @ -406,6 +408,8 @@ public: | |||||||
| 		class QSE_EXPORT Handler  | 		class QSE_EXPORT Handler  | ||||||
| 		{ | 		{ | ||||||
| 		public: | 		public: | ||||||
|  | 			virtual ~Handler () {} | ||||||
|  |  | ||||||
| 			virtual int     open  (File& io) = 0; | 			virtual int     open  (File& io) = 0; | ||||||
| 			virtual int     close (File& io) = 0; | 			virtual int     close (File& io) = 0; | ||||||
| 			virtual ssize_t read  (File& io, char_t* buf, size_t len) = 0; | 			virtual ssize_t read  (File& io, char_t* buf, size_t len) = 0; | ||||||
| @ -442,6 +446,8 @@ public: | |||||||
| 		class QSE_EXPORT Handler  | 		class QSE_EXPORT Handler  | ||||||
| 		{ | 		{ | ||||||
| 		public: | 		public: | ||||||
|  | 			virtual ~Handler () {} | ||||||
|  |  | ||||||
| 			/// The open() function is called before the initial | 			/// The open() function is called before the initial | ||||||
| 			/// access to the console for input and output. | 			/// access to the console for input and output. | ||||||
| 			/// It must return 0 for success and -1 for failure. | 			/// It must return 0 for success and -1 for failure. | ||||||
|  | |||||||
| @ -27,15 +27,7 @@ | |||||||
| #include <qse/cmn/nwio.h> | #include <qse/cmn/nwio.h> | ||||||
| #include <qse/cmn/path.h> | #include <qse/cmn/path.h> | ||||||
| #include "awk.h" | #include "awk.h" | ||||||
|  | #include "std.h" | ||||||
| #include <stdlib.h> |  | ||||||
| #include <math.h> |  | ||||||
|  |  | ||||||
| #if defined(HAVE_QUADMATH_H) |  | ||||||
| extern "C" { // some gcc distros don't have extern "C" declared in the header file. |  | ||||||
| #	include <quadmath.h> |  | ||||||
| } |  | ||||||
| #endif |  | ||||||
|  |  | ||||||
| #if defined(_WIN32) | #if defined(_WIN32) | ||||||
| #	include <windows.h> | #	include <windows.h> | ||||||
| @ -1098,228 +1090,33 @@ void  StdAwk::freeMem (void* ptr) | |||||||
|  |  | ||||||
| StdAwk::flt_t StdAwk::pow (flt_t x, flt_t y)  | StdAwk::flt_t StdAwk::pow (flt_t x, flt_t y)  | ||||||
| {  | {  | ||||||
| #if defined(QSE_USE_AWK_FLTMAX) && defined(HAVE_POWQ) | 	return qse_awk_stdmathpow (this->awk, x, y); | ||||||
| 	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 |  | ||||||
| } | } | ||||||
|  |  | ||||||
| StdAwk::flt_t StdAwk::mod (flt_t x, flt_t y)  | StdAwk::flt_t StdAwk::mod (flt_t x, flt_t y)  | ||||||
| {  | {  | ||||||
| #if defined(QSE_USE_AWK_FLTMAX) && defined(HAVE_FMODQ) | 	return qse_awk_stdmathmod (this->awk, x, y); | ||||||
| 	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 |  | ||||||
| } | } | ||||||
|  |  | ||||||
| void* StdAwk::modopen (const mod_spec_t* spec) | 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; | 	void* h; | ||||||
| 	qse_mchar_t* modpath; | 	h = qse_awk_stdmodopen (this->awk, spec); | ||||||
| 	const qse_char_t* tmp[4]; | 	if (!h) this->retrieveError (); | ||||||
| 	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); |  | ||||||
|  |  | ||||||
| 	return h; | 	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) | void StdAwk::modclose (void* handle) | ||||||
| { | { | ||||||
| #if defined(QSE_ENABLE_STATIC_MODULE) | 	qse_awk_stdmodclose (this->awk, handle); | ||||||
| 	/* 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 |  | ||||||
| } | } | ||||||
|  |  | ||||||
| void* StdAwk::modsym (void* handle, const qse_char_t* name) | void* StdAwk::modsym (void* handle, const qse_char_t* name) | ||||||
| { | { | ||||||
| 	void* s; | 	void* s; | ||||||
| 	qse_mchar_t* mname; | 	s = qse_awk_stdmodsym (this->awk, handle, name); | ||||||
|  | 	if (!s) this->retrieveError (); | ||||||
| #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 |  | ||||||
|  |  | ||||||
| 	return s; | 	return s; | ||||||
|  |  | ||||||
| } | } | ||||||
|  |  | ||||||
| int StdAwk::SourceFile::open (Data& io) | int StdAwk::SourceFile::open (Data& io) | ||||||
|  | |||||||
| @ -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 | #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) | #if defined(QSE_ENABLE_STATIC_MODULE) | ||||||
| 	/* this won't be called at all when modules are linked into | 	/* 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 | #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) | #if defined(QSE_ENABLE_STATIC_MODULE) | ||||||
| 	/* this won't be called at all when modules are linked into | 	/* 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 | #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; | 	void* s; | ||||||
| 	qse_mchar_t* mname; | 	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.pow = qse_awk_stdmathpow; | ||||||
| 	prm.math.mod = qse_awk_stdmathmod; | 	prm.math.mod = qse_awk_stdmathmod; | ||||||
|  |  | ||||||
| 	prm.modopen = custom_awk_modopen; | 	prm.modopen = qse_awk_stdmodopen; | ||||||
| 	prm.modclose = custom_awk_modclose; | 	prm.modclose = qse_awk_stdmodclose; | ||||||
| 	prm.modsym = custom_awk_modsym; | 	prm.modsym = qse_awk_stdmodsym; | ||||||
|  |  | ||||||
| 	/* create an object */ | 	/* create an object */ | ||||||
| 	awk = qse_awk_open (mmgr, QSE_SIZEOF(xtn_t) + xtnsize, &prm, errnum); | 	awk = qse_awk_open (mmgr, QSE_SIZEOF(xtn_t) + xtnsize, &prm, errnum); | ||||||
|  | |||||||
| @ -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_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); | 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 | #ifdef __cplusplus | ||||||
| } | } | ||||||
| #endif | #endif | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user