Subversion Repositories Tewi

Rev

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

Rev 159 Rev 182
Line 1... Line 1...
1
/* $Id: module.c 159 2024-09-25 12:56:45Z nishi $ */
1
/* $Id: module.c 182 2024-09-27 12:55:12Z nishi $ */
2
 
2
 
3
#define SOURCE
3
#define SOURCE
4
 
4
 
5
#include "tw_module.h"
5
#include "tw_module.h"
6
 
6
 
Line 11... Line 11...
11
 
11
 
12
#include <string.h>
12
#include <string.h>
13
#include <unistd.h>
13
#include <unistd.h>
14
#include <stdlib.h>
14
#include <stdlib.h>
15
 
15
 
-
 
16
extern struct tw_config config;
-
 
17
 
-
 
18
#ifdef _PSP
-
 
19
void* tw_module_load(const char* path) { return NULL; }
-
 
20
 
-
 
21
void* tw_module_symbol(void* mod, const char* sym) { return NULL; }
-
 
22
 
-
 
23
int tw_module_init(void* mod) { return 1; }
-
 
24
 
-
 
25
#else
-
 
26
 
16
#ifdef __MINGW32__
27
#ifdef __MINGW32__
17
#include <windows.h>
28
#include <windows.h>
18
#else
29
#else
19
#include <dlfcn.h>
30
#include <dlfcn.h>
20
#endif
31
#endif
21
 
32
 
22
extern struct tw_config config;
-
 
23
 
-
 
24
void* tw_module_load(const char* path) {
33
void* tw_module_load(const char* path) {
25
	char* p = getcwd(NULL, 0);
34
	char* p = getcwd(NULL, 0);
26
	chdir(config.server_root);
35
	chdir(config.server_root);
27
	void* lib;
36
	void* lib;
28
#ifdef __MINGW32__
37
#ifdef __MINGW32__
Line 44... Line 53...
44
#else
53
#else
45
	return dlsym(mod, sym);
54
	return dlsym(mod, sym);
46
#endif
55
#endif
47
}
56
}
48
 
57
 
-
 
58
int tw_module_init(void* mod) {
-
 
59
	tw_mod_init_t mod_init = (tw_mod_init_t)tw_module_symbol(mod, "mod_init");
-
 
60
	if(mod_init == NULL) {
-
 
61
		cm_log("Module", "Could not init a module");
-
 
62
		return 1;
-
 
63
	} else {
-
 
64
		struct tw_tool tools;
-
 
65
		tw_init_tools(&tools);
-
 
66
		return mod_init(&config, &tools);
-
 
67
	}
-
 
68
}
-
 
69
#endif
-
 
70
 
49
void tw_add_version(const char* string) {
71
void tw_add_version(const char* string) {
50
	if(config.extension == NULL) {
72
	if(config.extension == NULL) {
51
		config.extension = cm_strcat(" ", string);
73
		config.extension = cm_strcat(" ", string);
52
	} else {
74
	} else {
53
		char* tmp = config.extension;
75
		char* tmp = config.extension;
Line 85... Line 107...
85
void tw_init_tools(struct tw_tool* tools) {
107
void tw_init_tools(struct tw_tool* tools) {
86
	tools->log = cm_log;
108
	tools->log = cm_log;
87
	tools->add_version = tw_add_version;
109
	tools->add_version = tw_add_version;
88
	tools->add_define = tw_add_define;
110
	tools->add_define = tw_add_define;
89
}
111
}
90
 
-
 
91
int tw_module_init(void* mod) {
-
 
92
	tw_mod_init_t mod_init = (tw_mod_init_t)tw_module_symbol(mod, "mod_init");
-
 
93
	if(mod_init == NULL) {
-
 
94
		cm_log("Module", "Could not init a module");
-
 
95
		return 1;
-
 
96
	} else {
-
 
97
		struct tw_tool tools;
-
 
98
		tw_init_tools(&tools);
-
 
99
		return mod_init(&config, &tools);
-
 
100
	}
-
 
101
}
-