initial mod info work (need to rework this)
This commit is contained in:
parent
e0edbc83d6
commit
4eb0ddca86
1 changed files with 33 additions and 0 deletions
33
src/main.c
33
src/main.c
|
@ -47,6 +47,7 @@ int main(int argc, char *argv[]) {
|
|||
free(config_path);
|
||||
|
||||
bool hit_mod_cmd = false;
|
||||
bool hit_mod_info = false;
|
||||
|
||||
for (size_t i = 1; i < (size_t)argc; ++i) {
|
||||
if (strcmp(argv[i], "-c") == 0 || strcmp(argv[i], "--config") == 0) {
|
||||
|
@ -106,6 +107,38 @@ int main(int argc, char *argv[]) {
|
|||
}
|
||||
}
|
||||
|
||||
if (strcmp(argv[i], "info") == 0 || hit_mod_info) {
|
||||
// no more args
|
||||
if (i == (size_t)argc - 1) {
|
||||
fprintf(stderr, "error: no module passed\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
// some other -/-- option in between the info and the module
|
||||
if (argv[i][0] == '-') {
|
||||
hit_mod_info = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
i += 1;
|
||||
|
||||
for (size_t ii = 0; ii < config.module_count; ++ii) {
|
||||
Module current_module = config.modules[ii];
|
||||
void *handle = dlopen(current_module.path, RTLD_NOW);
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wpedantic"
|
||||
semver (*mod_version)(void) = dlsym(handle, "version");
|
||||
const char *(*mod_name)(void) = dlsym(handle, "name");
|
||||
#pragma GCC diagnostic pop
|
||||
|
||||
const char *_mod_name = mod_name();
|
||||
if (strcmp(argv[i], _mod_name) != 0)
|
||||
continue;
|
||||
|
||||
printf("%s-%s\n", _mod_name, svtoa(mod_version()));
|
||||
}
|
||||
}
|
||||
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue