1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-12-04 14:46:46 -05:00

Add function to get C plugin name

This commit is contained in:
James Booth 2016-06-23 00:26:50 +01:00
parent 620e6a5a37
commit c6288d89f9
3 changed files with 25 additions and 4 deletions

View File

@ -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;
}

View File

@ -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;

View File

@ -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));