-
Notifications
You must be signed in to change notification settings - Fork 0
/
module.c
60 lines (49 loc) · 1.6 KB
/
module.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
/*
* ----------------------------------------------------------------------------
* "THE COFFEE-WARE LICENSE" (Revision 23):
* <toke@toke.de> wrote this file. As long as you retain this notice you
* can do whatever you want with this stuff. If we meet some day, and you think
* this stuff is worth it, you can bring me a coffee in return.
* ----------------------------------------------------------------------------
*/
#include "module.h"
void init_registry(module_registry_t * registry){
}
int register_module(module_registry_t * registry, module_t * output) {
if (registry->max_id < MAX_MODULES) {
registry->modules[registry->max_id] = * output;
registry->max_id++;
return registry->max_id; // Number of modules
}
return -1;
}
void usage_modules(module_registry_t * registry){
module_t * module;
size_t i;
printf("%s modules:\n", registry->name);
for (i=0; i < registry->max_id; i++) {
module = ®istry->modules[i];
printf("%s:\t%s", module->ident, module->name);
if (registry->default_id == (char) i) {
printf(" (default)");
}
printf("\n");
}
}
module_t * search_module(module_registry_t * registry, module_ident_t * ident){
module_t * module;
size_t i;
for (i=0; i < registry->max_id; i++) {
module = ®istry->modules[i];
if (strcmp(module->ident, (char *) ident) == 0) {
return (module);
}
}
return (module_t *) NULL;
}
module_t * get_default_module(module_registry_t * registry){
if (®istry->modules[registry->default_id] != NULL) {
return ®istry->modules[registry->default_id];
}
return (module_t *) NULL;
}