#include "config.h"
#include "built_in_parsers.h"
+#include "plugin_manager.h"
+
struct user_options {
int max_jobs;
char *config_file;
if (read_args(argc, argv, &opts) < 0)
return -1;
+ init_plugin_manager(argv[0]);
register_built_in_parsers();
if (!opts.config_file) {
+#include <stdlib.h>
#include <dlfcn.h>
+#include <string.h>
+#include <libgen.h>
#include "plugin_manager.h"
#include "plugin.h"
#include "debug.h"
+static char *exec_path;
+
+int init_plugin_manager(const char *_exec_path)
+{
+ char *str = strdup(_exec_path);
+ exec_path = strdup(dirname(str));
+
+ free(str);
+ return 0;
+}
+
int load_plugin(const char *path)
{
struct plugin_info *info;
return ret;
}
+
+/*
+ * Try to load a parser plugin with file name matching some of the
+ * following candidates (%s being the requested name):
+ *
+ * "%s_parser.so"
+ * "./%s_parser.so"
+ * "<exec_path>/%s_parser.so"
+ */
+int load_parser_plugin(const char *name)
+{
+ char str[256], parser[] = "_parser.so";
+ int ret;
+
+ strncpy(str, name, sizeof(str));
+ strncat(str, parser, sizeof(str) - 1);
+ ret = load_plugin(str);
+ if (!ret)
+ return 0;
+
+ strncpy(str, "./", sizeof(str));
+ strncat(str, name, sizeof(str) - 1);
+ strncat(str, parser, sizeof(str) - 1);
+ ret = load_plugin(str);
+ if (!ret)
+ return 0;
+
+ if (!exec_path)
+ return 0;
+
+ strncpy(str, exec_path, sizeof(str));
+ strncat(str, "/", sizeof(str) - 1);
+ strncat(str, name, sizeof(str) - 1);
+ strncat(str, parser, sizeof(str) - 1);
+ return load_plugin(str);
+}