Subversion Repositories Tewi

Rev

Rev 312 | Rev 315 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 312 Rev 313
Line 1... Line 1...
1
/* $Id: module.c 312 2024-10-13 18:17:37Z nishi $ */
1
/* $Id: module.c 313 2024-10-13 23:22:06Z nishi $ */
2
 
2
 
3
#define SOURCE
3
#define SOURCE
4
 
4
 
5
#include "tw_module.h"
5
#include "tw_module.h"
6
 
6
 
Line 27... Line 27...
27
#else
27
#else
28
 
28
 
29
#if defined(__MINGW32__) || defined(_MSC_VER) || defined(__BORLANDC__) || defined(__WATCOMC__)
29
#if defined(__MINGW32__) || defined(_MSC_VER) || defined(__BORLANDC__) || defined(__WATCOMC__)
30
#ifdef __OS2__
30
#ifdef __OS2__
31
#define INCL_DOSMODULEMGR
31
#define INCL_DOSMODULEMGR
-
 
32
#define INCL_DOSERRORS
32
#include <os2.h>
33
#include <os2.h>
33
#else
34
#else
34
#include <windows.h>
35
#include <windows.h>
35
#include <direct.h>
36
#include <direct.h>
36
#endif
37
#endif
Line 40... Line 41...
40
 
41
 
41
void* tw_module_load(const char* path) {
42
void* tw_module_load(const char* path) {
42
	char* p = getcwd(NULL, 0);
43
	char* p = getcwd(NULL, 0);
43
	void* lib;
44
	void* lib;
44
	char tmp[512];
45
	char tmp[512];
-
 
46
#ifdef __OS2__
45
	unsigned long l;
47
	HMODULE mod;
-
 
48
#endif
46
	chdir(config.server_root);
49
	chdir(config.server_root);
47
#if defined(__MINGW32__) || defined(_MSC_VER) || defined(__BORLANDC__) || defined(__WATCOMC__)
50
#if defined(__MINGW32__) || defined(_MSC_VER) || defined(__BORLANDC__) || defined(__WATCOMC__)
48
#ifdef __OS2__
51
#ifdef __OS2__
-
 
52
	if(DosLoadModule(tmp, 512, path, &mod) != NO_ERROR){
49
	lib = NULL;
53
		return NULL;
-
 
54
	}
50
	l = (unsigned long)lib;
55
	lib = (void*)mod;
51
	DosLoadModule(tmp, 512, path, &l);
-
 
52
#else
56
#else
53
	lib = LoadLibraryA(path);
57
	lib = LoadLibraryA(path);
54
#endif
58
#endif
55
#else
59
#else
56
	lib = dlopen(path, RTLD_LAZY);
60
	lib = dlopen(path, RTLD_LAZY);
Line 65... Line 69...
65
 
69
 
66
void* tw_module_symbol(void* mod, const char* sym) {
70
void* tw_module_symbol(void* mod, const char* sym) {
67
#if defined(__MINGW32__) || defined(_MSC_VER) || defined(__BORLANDC__) || defined(__WATCOMC__)
71
#if defined(__MINGW32__) || defined(_MSC_VER) || defined(__BORLANDC__) || defined(__WATCOMC__)
68
#ifdef __OS2__
72
#ifdef __OS2__
69
	void* ret;
73
	void* ret;
-
 
74
	APIRET rc;
70
	DosQueryProcAddr((unsigned long)mod, 0, sym, (PFN*)&ret);
75
	if((rc = DosQueryProcAddr((HMODULE)mod, 0, sym, (PFN*)&ret)) != NO_ERROR){
-
 
76
		cm_log("Module", "OS/2 error %d", (int)rc);
-
 
77
		return NULL;
-
 
78
	}
71
	return ret;
79
	return ret;
72
#else
80
#else
73
	return GetProcAddress(mod, sym);
81
	return GetProcAddress(mod, sym);
74
#endif
82
#endif
75
#else
83
#else
Line 78... Line 86...
78
}
86
}
79
 
87
 
80
int tw_module_init(void* mod) {
88
int tw_module_init(void* mod) {
81
	tw_mod_init_t mod_init = (tw_mod_init_t)tw_module_symbol(mod, "mod_init");
89
	tw_mod_init_t mod_init = (tw_mod_init_t)tw_module_symbol(mod, "mod_init");
82
	if(mod_init == NULL) {
90
	if(mod_init == NULL) {
83
		cm_log("Module", "Could not init a module");
91
		cm_log("Module", "Could not find a init call");
84
		return 1;
92
		return 1;
85
	} else {
93
	} else {
86
		struct tw_tool tools;
94
		struct tw_tool tools;
87
		tw_init_tools(&tools);
95
		tw_init_tools(&tools);
88
		return mod_init(&config, &tools);
96
		return mod_init(&config, &tools);