File: modules.c

package info (click to toggle)
xsystem35 2.17.0-1
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 8,096 kB
  • sloc: ansic: 38,159; java: 4,085; xml: 249; sh: 134; python: 15; makefile: 12
file content (86 lines) | stat: -rw-r--r-- 2,232 bytes parent folder | download | duplicates (2)
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
/*
 * Copyright (C) 2020 <KichikuouChrome@gmail.com>
 *
 * 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
 * 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
 *
*/

#include "config.h"

#include <stdlib.h>
#include <string.h>

#include "system.h"
#include "s39ain.h"
#include "modules.h"

static const Module *modules[] = {
	&module_AliceLogo,
	&module_Confirm,
	&module_Gpx,
	&module_Math,
	&module_MsgSkip,
	&module_NIGHTDLL,
	&module_NightDemonDemo,
	&module_RandMT,
	&module_S3xMusic,
	&module_SACT,
	&module_ShArray,
	&module_ShCalc,
	&module_ShGraph,
	&module_ShPort,
	&module_ShSound,
	&module_ShString,
	&module_dDemo,
	&module_eDemo,
	&module_eeDemo,
	&module_nDEMO,
	&module_nDEMOE,
	&module_oDEMO,
	&module_oujimisc,
	&module_tDemo,
	NULL
};

static int compare_name(const void *f1, const void *f2) {
	return strcmp(((const ModuleFunc *)f1)->name,
				  ((const ModuleFunc *)f2)->name);
}

static void resolve_func(S39AIN_DLLFN *func, const Module *mod) {
	ModuleFunc key = {.name = func->name};
	ModuleFunc *mf = bsearch(&key, mod->funcs, mod->nfunc, sizeof(ModuleFunc), compare_name);

	if (mf)
		func->entrypoint = mf->entrypoint;
	else
		WARNING("Cannot resolve DLL function %s.%s", mod->name, func->name);
}

bool resolve_module(S39AIN_DLLINF *dll) {
	if (dll->function_num == 0)
		return true;

	for (const Module **mod = modules; *mod; mod++) {
		if (strcasecmp((*mod)->name, dll->name) == 0) {
			for (int i = 0; i < dll->function_num; i++)
				resolve_func(&dll->function[i], *mod);
			dll->reset = (*mod)->reset;
			return true;
		}
	}
	WARNING("Cannot resolve DLL: %s", dll->name);
	return false;
}