Skip to content

Commit

Permalink
List all known modules when the help is invoked
Browse files Browse the repository at this point in the history
  • Loading branch information
apmasell committed Dec 20, 2013
1 parent f1eab07 commit cd6a139
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
2 changes: 2 additions & 0 deletions args.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#endif
#include "pandaseq.h"
#include "misc.h"
#include "module.h"

#define MAX_OPT_LIST 53
#define MAX_MODULES 100
Expand Down Expand Up @@ -395,6 +396,7 @@ bool panda_parse_args(
fprintf(stderr, "%s(%s) %s\n\t%s\n", panda_module_get_name(modules[it]), panda_module_get_description(modules[it]), panda_module_get_version(modules[it]), panda_module_get_usage(modules[it]));
}
CLEANUP();
module_show_all();
return false;
}
#ifdef HAVE_PTHREAD
Expand Down
25 changes: 25 additions & 0 deletions module.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/
#include "config.h"
#include <libgen.h>
#include <ltdl.h>
#include <stdio.h>
#include <stdlib.h>
Expand Down Expand Up @@ -408,3 +409,27 @@ const char *panda_module_get_usage(
val = lt_dlsym(module->handle, "usage");
return val == NULL ? NULL : *val;
}

static int show_module(
const char *filename,
void *data) {
char buffer[2048];
char *base_filename;
PandaModule module = panda_module_load(filename);
strncpy(buffer, filename, sizeof(buffer));
buffer[sizeof(buffer) - 1] = '\0';
base_filename = basename(buffer);
if (module == NULL) {
fprintf(stderr, "%s: unknown module type\n", filename);
return 0;
}
fprintf(stderr, "%s (%s): %s\n\tUsage: %s\n", base_filename, panda_module_get_version(module), panda_module_get_description(module), panda_module_get_usage(module));
panda_module_unref(module);
return 0;
}

void module_show_all(
) {
fprintf(stderr, "\nKnown modules:\n");
lt_dlforeachfile(STR(PKGLIBDIR), show_module, NULL);
}
3 changes: 3 additions & 0 deletions module.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,7 @@ extern void module_cleanup(
PandaAssembler assembler);
extern void module_destroy(
PandaAssembler assembler);

extern void module_show_all(
void);
#endif

0 comments on commit cd6a139

Please sign in to comment.