From a01eb5d08e1b39d60a6f8fc26e5a87ceb92ec18f Mon Sep 17 00:00:00 2001 From: James Booth Date: Wed, 29 Jun 2016 23:35:57 +0100 Subject: WIP - Unload plugin commands --- src/command/cmd_ac.c | 9 ++++++++ src/command/cmd_ac.h | 1 + src/command/cmd_defs.c | 9 +++++--- src/command/cmd_funcs.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++++- src/command/cmd_funcs.h | 11 +++++----- 5 files changed, 76 insertions(+), 9 deletions(-) (limited to 'src/command') diff --git a/src/command/cmd_ac.c b/src/command/cmd_ac.c index 1dfc5cc0..46c1d940 100644 --- a/src/command/cmd_ac.c +++ b/src/command/cmd_ac.c @@ -702,6 +702,7 @@ cmd_ac_init(void) plugins_ac = autocomplete_new(); autocomplete_add(plugins_ac, "load"); + autocomplete_add(plugins_ac, "unload"); sendfile_ac = autocomplete_new(); @@ -784,6 +785,14 @@ cmd_ac_remove(const char *const value) } } +void +cmd_ac_remove_help(const char *const value) +{ + if (help_ac) { + autocomplete_remove(help_ac, value); + } +} + gboolean cmd_ac_exists(char *cmd) { diff --git a/src/command/cmd_ac.h b/src/command/cmd_ac.h index b294fcd5..637ebcf6 100644 --- a/src/command/cmd_ac.h +++ b/src/command/cmd_ac.h @@ -48,6 +48,7 @@ void cmd_ac_add_alias(ProfAlias *alias); void cmd_ac_add_alias_value(char *value); void cmd_ac_remove(const char *const value); +void cmd_ac_remove_help(const char *const value); void cmd_ac_remove_alias_value(char *value); gboolean cmd_ac_exists(char *cmd); diff --git a/src/command/cmd_defs.c b/src/command/cmd_defs.c index dacf1c91..663a8948 100644 --- a/src/command/cmd_defs.c +++ b/src/command/cmd_defs.c @@ -1979,13 +1979,16 @@ static struct cmd_t command_defs[] = CMD_NOTAGS CMD_SYN( "/plugins", - "/plugins load ") + "/plugins load ", + "/plugins unload ") CMD_DESC( "Manage plugins. Passing no arguments lists currently loaded plugins.") CMD_ARGS( - { "load ", "Load a plugin." }) + { "load ", "Load a plugin." }, + { "unload ", "Unload a plugin." }) CMD_EXAMPLES( - "/plugin load browser.py") + "/plugin load browser.py", + "/plugin unload pid.so") }, { "/prefs", diff --git a/src/command/cmd_funcs.c b/src/command/cmd_funcs.c index 7f3419e3..0d673248 100644 --- a/src/command/cmd_funcs.c +++ b/src/command/cmd_funcs.c @@ -95,6 +95,49 @@ static gboolean _cmd_execute(ProfWin *window, const char *const command, const c static gboolean _cmd_execute_default(ProfWin *window, const char *inp); static gboolean _cmd_execute_alias(ProfWin *window, const char *const inp, gboolean *ran); +void +command_help_free(CommandHelp *help) +{ + free(help->desc); + + if (help->tags) { + int i = 0; + while (i < 20 && help->tags[i]) { + free(help->tags[i]); + i++; + } + free(help->tags); + } + + if (help->synopsis) { + int i = 0; + while (i < 50 && help->synopsis[i]) { + free(help->synopsis[i]); + i++; + } + free(help->synopsis); + } + + if (help->examples) { + int i = 0; + while (i < 20 && help->examples[i]) { + free(help->examples[i]); + i++; + } + free(help->examples); + } + + if (help->args) { + int i = 0; + while (i < 120 && help->args[i]) { + free(help->args[i][0]); + free(help->args[i][1]); + free(help->args[i]); + } + free(help->args); + } +} + /* * Take a line of input and process it, return TRUE if profanity is to * continue, FALSE otherwise @@ -3809,7 +3852,7 @@ cmd_form(ProfWin *window, const char *const command, gchar **args) } else { mucconfwin_form_help(confwin); - const gchar **help_text = NULL; + gchar **help_text = NULL; Command *command = cmd_get("/form"); if (command) { @@ -6038,6 +6081,16 @@ cmd_plugins(ProfWin *window, const char *const command, gchar **args) cons_show("Failed to load plugin: %s", args[1]); } + return TRUE; + } else if (g_strcmp0(args[0], "unload") == 0) { + if (args[1] == NULL) { + cons_bad_cmd_usage(command); + return TRUE; + } + plugins_unload(args[1]); + prefs_remove_plugin(args[1]); + cons_show("Unloaded plugin: %s", args[1]); + return TRUE; } else { GSList *plugins = plugins_get_list(); diff --git a/src/command/cmd_funcs.h b/src/command/cmd_funcs.h index 52b9946e..c68efe43 100644 --- a/src/command/cmd_funcs.h +++ b/src/command/cmd_funcs.h @@ -39,11 +39,11 @@ // Command help strings typedef struct cmd_help_t { - const gchar *tags[20]; - const gchar *synopsis[50]; - const gchar *desc; - const gchar *args[128][2]; - const gchar *examples[20]; + gchar *tags[20]; + gchar *synopsis[50]; + gchar *desc; + gchar *args[128][2]; + gchar *examples[20]; } CommandHelp; /* @@ -69,6 +69,7 @@ typedef struct cmd_t { CommandHelp help; } Command; +void command_help_free(CommandHelp *help); gboolean cmd_process_input(ProfWin *window, char *inp); void cmd_execute_connect(ProfWin *window, const char *const account); -- cgit 1.4.1-2-gfad0