diff options
author | James Booth <boothj5@gmail.com> | 2016-06-23 00:26:50 +0100 |
---|---|---|
committer | James Booth <boothj5@gmail.com> | 2016-06-23 00:26:50 +0100 |
commit | c6288d89f9682ee090f5776956cc2e6e8e6889bc (patch) | |
tree | 431f72ba23f45674d4634e7d474c8b71397251ae | |
parent | 620e6a5a3764c0dad6c0adb203227e7b8df84083 (diff) | |
download | profani-tty-c6288d89f9682ee090f5776956cc2e6e8e6889bc.tar.gz |
Add function to get C plugin name
-rw-r--r-- | src/plugins/c_api.c | 23 | ||||
-rw-r--r-- | src/plugins/profapi.c | 2 | ||||
-rw-r--r-- | src/plugins/profapi.h | 4 |
3 files changed, 25 insertions, 4 deletions
diff --git a/src/plugins/c_api.c b/src/plugins/c_api.c index 770fd9a3..726f7d45 100644 --- a/src/plugins/c_api.c +++ b/src/plugins/c_api.c @@ -53,6 +53,8 @@ typedef struct window_wrapper_t { void(*func)(char *tag, char *line); } WindowWrapper; +static char* _c_plugin_name(const char *filename); + static void c_api_cons_alert(void) { @@ -78,10 +80,13 @@ c_api_cons_bad_cmd_usage(const char *const cmd) } static void -c_api_register_command(const char *command_name, int min_args, int max_args, +c_api_register_command(const char *filename, const char *command_name, int min_args, int max_args, const char **synopsis, const char *description, const char *arguments[][2], const char **examples, void(*callback)(char **args)) { + char *plugin_name = _c_plugin_name(filename); + log_debug("FILENAME : %s", plugin_name); + CommandWrapper *wrapper = malloc(sizeof(CommandWrapper)); wrapper->func = callback; api_register_command(command_name, min_args, max_args, synopsis, @@ -297,7 +302,7 @@ c_api_init(void) prof_cons_show = c_api_cons_show; prof_cons_show_themed = c_api_cons_show_themed; prof_cons_bad_cmd_usage = c_api_cons_bad_cmd_usage; - prof_register_command = c_api_register_command; + _prof_register_command = c_api_register_command; prof_register_timed = c_api_register_timed; prof_completer_add = c_api_completer_add; prof_completer_remove = c_api_completer_remove; @@ -328,3 +333,17 @@ c_api_init(void) prof_incoming_message = c_api_incoming_message; prof_disco_add_feature = c_api_disco_add_feature; } + +static char * +_c_plugin_name(const char *filename) +{ + GString *plugin_name_str = g_string_new(""); + char *name = strndup(filename, strlen(filename)-1); + g_string_append(plugin_name_str, name); + free(name); + g_string_append(plugin_name_str, "so"); + char *result = plugin_name_str->str; + g_string_free(plugin_name_str, FALSE); + + return result; +} diff --git a/src/plugins/profapi.c b/src/plugins/profapi.c index 4b18da3b..9c352343 100644 --- a/src/plugins/profapi.c +++ b/src/plugins/profapi.c @@ -42,7 +42,7 @@ int (*prof_cons_show)(const char * const message) = NULL; int (*prof_cons_show_themed)(const char *const group, const char *const item, const char *const def, const char *const message) = NULL; int (*prof_cons_bad_cmd_usage)(const char *const cmd) = NULL; -void (*prof_register_command)(const char *command_name, int min_args, int max_args, +void (*_prof_register_command)(const char *filename, const char *command_name, int min_args, int max_args, const char **synopsis, const char *description, const char *arguments[][2], const char **examples, void(*callback)(char **args)) = NULL; diff --git a/src/plugins/profapi.h b/src/plugins/profapi.h index 54497c8d..d25944c3 100644 --- a/src/plugins/profapi.h +++ b/src/plugins/profapi.h @@ -35,6 +35,8 @@ #ifndef PROF_API_H #define PROF_API_H +#define prof_register_command(command_name, min_args, max_args, synopsis, description, arguments, examples, callback) _prof_register_command(__FILE__, command_name, min_args, max_args, synopsis, description, arguments, examples, callback) + typedef char* PROF_WIN_TAG; void (*prof_cons_alert)(void); @@ -42,7 +44,7 @@ int (*prof_cons_show)(const char * const message); int (*prof_cons_show_themed)(const char *const group, const char *const item, const char *const def, const char *const message); int (*prof_cons_bad_cmd_usage)(const char *const cmd); -void (*prof_register_command)(const char *command_name, int min_args, int max_args, +void (*_prof_register_command)(const char *filename, const char *command_name, int min_args, int max_args, const char **synopsis, const char *description, const char *arguments[][2], const char **examples, void(*callback)(char **args)); |