-
Notifications
You must be signed in to change notification settings - Fork 124
/
Copy pathmodules.c
113 lines (92 loc) · 2.92 KB
/
modules.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/*
Copyright (C) 2001-2002 A Nourai
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the included (GNU.txt) GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifdef __FreeBSD__
#include <dlfcn.h>
#endif
#include "quakedef.h"
#include "modules.h"
#include "version.h"
#if (!defined WITH_PNG_STATIC || !defined WITH_JPEG_STATIC || defined WITH_MP3_PLAYER)
typedef struct registeredModule_s {
qlib_id_t id;
qbool loaded;
qlib_shutdown_fn shutdown;
} registeredModule_t;
char _temp_modulename[MAX_OSPATH];
static registeredModule_t registeredModules[qlib_nummodules];
void QLib_Init(void)
{
int i;
for (i = 0; i < qlib_nummodules; i++) {
registeredModules[i].id = i;
registeredModules[i].loaded = false;
registeredModules[i].shutdown = NULL;
}
}
void QLib_Shutdown(void)
{
int i;
for (i = 0; i < qlib_nummodules; i++) {
if (registeredModules[i].loaded) {
registeredModules[i].shutdown();
registeredModules[i].loaded = false;
}
}
}
void QLib_RegisterModule (qlib_id_t module, qlib_shutdown_fn shutdown)
{
if (module < 0 || module >= qlib_nummodules)
Sys_Error ("QLib_isModuleLoaded: bad module %d", module);
registeredModules[module].loaded = true;
registeredModules[module].shutdown = shutdown;
}
qbool QLib_isModuleLoaded(qlib_id_t module)
{
if (module < 0 || module >= qlib_nummodules)
Sys_Error("QLib_isModuleLoaded: bad module %d", module);
return registeredModules[module].loaded;
}
qbool QLib_ProcessProcdef(QLIB_HANDLETYPE_T handle, qlib_dllfunction_t *procdefs, int size)
{
int i;
for (i = 0; i < size; i++) {
if (!(*procdefs[i].function = QLIB_GETPROCADDRESS(handle, procdefs[i].name))) {
for (i = 0; i < size; i++)
procdefs[i].function = NULL;
return false;
}
}
return true;
}
void QLib_MissingModuleError(int errortype, char *libname, char *cmdline, char *features)
{
if (!COM_CheckParm("-showliberrors"))
return;
switch (errortype) {
case QLIB_ERROR_MODULE_NOT_FOUND:
Sys_Error(
"ezQuake couldn't load the required \"%s" QLIB_LIBRARY_EXTENSION "\" library. You must\n"
"specify \"%s\" on the cmdline to disable %s.",
libname, cmdline, features
);
break;
case QLIB_ERROR_MODULE_MISSING_PROC:
Sys_Error("Broken \"%s" QLIB_LIBRARY_EXTENSION "\" library - required function missing.", libname);
break;
default:
Sys_Error("QLib_MissingModuleError: unknown error type (%d)", errortype);
}
}
#endif