diff options
author | Sebastien Helleu <flashcode@flashtux.org> | 2006-03-24 09:38:54 +0000 |
---|---|---|
committer | Sebastien Helleu <flashcode@flashtux.org> | 2006-03-24 09:38:54 +0000 |
commit | d9c032fee32a84fae84c82a91c141145b4c4bfd0 (patch) | |
tree | a03d2c3e7db1e84ad1c5d70f88a0bb07f807114a /src | |
parent | 9fb1176b1bc72b6d265f8b779479dbc3040e3b8f (diff) | |
download | weechat-d9c032fee32a84fae84c82a91c141145b4c4bfd0.zip |
Added /setp command (set plugin options)
Diffstat (limited to 'src')
-rw-r--r-- | src/common/command.c | 182 | ||||
-rw-r--r-- | src/common/command.h | 1 | ||||
-rw-r--r-- | src/common/completion.c | 78 | ||||
-rw-r--r-- | src/common/weechat.c | 30 | ||||
-rw-r--r-- | src/common/weechat.h | 2 | ||||
-rw-r--r-- | src/plugins/plugins-config.c | 79 | ||||
-rw-r--r-- | src/plugins/plugins-config.h | 6 | ||||
-rw-r--r-- | src/plugins/plugins.h | 1 |
8 files changed, 358 insertions, 21 deletions
diff --git a/src/common/command.c b/src/common/command.c index 91b74d99a..611c50c1d 100644 --- a/src/common/command.c +++ b/src/common/command.c @@ -143,14 +143,20 @@ t_weechat_command weechat_commands[] = { "save", N_("save config to disk"), N_("[file]"), N_("file: filename for writing config"), NULL, 0, 1, weechat_cmd_save, NULL }, - { "set", N_("set config parameters"), + { "set", N_("set config options"), N_("[option [ = value]]"), N_("option: name of an option (if name is full " "and no value is given, then help is displayed on option)\n" - "value: value for option\n\n" + " value: value for option\n\n" "Option may be: servername.server_xxx where \"servername\" is an " "internal server name and \"xxx\" an option for this server."), "%o = %v", 0, MAX_ARGS, NULL, weechat_cmd_set }, + { "setp", N_("set plugin config options"), + N_("[option [ = value]]"), + N_("option: name of a plugin option\n" + " value: value for option\n\n" + "Option is format: plugin.option, example: perl.myscript.item1"), + "%O = %V", 0, MAX_ARGS, NULL, weechat_cmd_setp }, { "unalias", N_("remove an alias"), N_("alias_name"), N_("alias_name: name of alias to remove"), "%a", 1, 1, NULL, weechat_cmd_unalias }, @@ -2573,8 +2579,9 @@ weechat_cmd_plugin (t_irc_server *server, t_irc_channel *channel, #else irc_display_prefix (NULL, NULL, PREFIX_ERROR); gui_printf (NULL, - _("Command \"plugin\" is not available, WeeChat was built " - "without plugins support.\n")); + _("Command \"%s\" is not available, WeeChat was built " + "without plugins support.\n"), + "plugin"); /* make gcc happy */ (void) argc; (void) argv; @@ -2974,7 +2981,7 @@ weechat_cmd_set_display_option (t_config_option *option, char *prefix, void *val } /* - * weechat_cmd_set: set options + * weechat_cmd_set: set config options */ int @@ -3295,6 +3302,171 @@ weechat_cmd_set (t_irc_server *server, t_irc_channel *channel, } /* + * weechat_cmd_setp: set plugin options + */ + +int +weechat_cmd_setp (t_irc_server *server, t_irc_channel *channel, + char *arguments) +{ +#ifdef PLUGINS + char *option, *value, *pos, *ptr_name; + t_plugin_option *ptr_option; + int number_found; + + /* make gcc happy */ + (void) server; + (void) channel; + + option = NULL; + value = NULL; + if (arguments && arguments[0]) + { + option = arguments; + value = strchr (option, '='); + if (value) + { + value[0] = '\0'; + + /* remove spaces before '=' */ + pos = value - 1; + while ((pos > option) && (pos[0] == ' ')) + { + pos[0] = '\0'; + pos--; + } + + /* skip spaces after '=' */ + value++; + while (value[0] && (value[0] == ' ')) + { + value++; + } + + /* remove simple or double quotes + and spaces at the end */ + if (strlen(value) > 1) + { + pos = value + strlen (value) - 1; + while ((pos > value) && (pos[0] == ' ')) + { + pos[0] = '\0'; + pos--; + } + pos = value + strlen (value) - 1; + if (((value[0] == '\'') && + (pos[0] == '\'')) || + ((value[0] == '"') && + (pos[0] == '"'))) + { + pos[0] = '\0'; + value++; + } + } + } + } + + if (value) + { + ptr_name = NULL; + ptr_option = plugin_config_search_internal (option); + if (ptr_option) + ptr_name = ptr_option->name; + else + { + pos = strchr (option, '.'); + if (pos) + pos[0] = '\0'; + if (!pos || !pos[1] || (!plugin_search (option))) + { + irc_display_prefix (NULL, NULL, PREFIX_ERROR); + gui_printf (NULL, _("%s plugin \"%s\" not found\n"), + WEECHAT_ERROR, option); + } + else + ptr_name = option; + if (pos) + pos[0] = '.'; + } + if (ptr_name) + { + if (plugin_config_set_internal (ptr_name, value)) + { + gui_printf (NULL, "\n %s%s = \"%s%s%s\"\n", + ptr_name, + GUI_COLOR(COLOR_WIN_CHAT_DARK), + GUI_COLOR(COLOR_WIN_CHAT_HOST), + value, + GUI_COLOR(COLOR_WIN_CHAT_DARK)); + } + else + { + irc_display_prefix (NULL, NULL, PREFIX_ERROR); + gui_printf (NULL, _("%s incorrect value for plugin option \"%s\"\n"), + WEECHAT_ERROR, ptr_name); + } + } + } + else + { + number_found = 0; + for (ptr_option = plugin_options; ptr_option; + ptr_option = ptr_option->next_option) + { + if ((!option) || + ((option) && (option[0]) + && (strstr (ptr_option->name, option) != NULL))) + { + if (number_found == 0) + gui_printf (NULL, "\n"); + gui_printf (NULL, " %s%s = \"%s%s%s\"\n", + ptr_option->name, + GUI_COLOR(COLOR_WIN_CHAT_DARK), + GUI_COLOR(COLOR_WIN_CHAT_HOST), + ptr_option->value, + GUI_COLOR(COLOR_WIN_CHAT_DARK)); + number_found++; + } + } + if (number_found == 0) + { + if (option) + gui_printf (NULL, _("No plugin option found with \"%s\"\n"), + option); + else + gui_printf (NULL, _("No plugin option found\n")); + } + else + { + gui_printf (NULL, "\n"); + gui_printf (NULL, "%s%d %s", + GUI_COLOR(COLOR_WIN_CHAT_CHANNEL), + number_found, + GUI_COLOR(COLOR_WIN_CHAT)); + if (option) + gui_printf (NULL, _("plugin option(s) found with \"%s\"\n"), + option); + else + gui_printf (NULL, _("plugin option(s) found\n")); + } + } +#else + /* make gcc happy */ + (void) server; + (void) channel; + (void) arguments; + + irc_display_prefix (NULL, NULL, PREFIX_ERROR); + gui_printf (NULL, + _("Command \"%s\" is not available, WeeChat was built " + "without plugins support.\n"), + "setp"); +#endif + + return 0; +} + +/* * cmd_unalias: remove an alias */ diff --git a/src/common/command.h b/src/common/command.h index 73fbaf42c..ccab6bb90 100644 --- a/src/common/command.h +++ b/src/common/command.h @@ -90,6 +90,7 @@ extern int weechat_cmd_plugin (t_irc_server *, t_irc_channel *, int, char **); extern int weechat_cmd_save (t_irc_server *, t_irc_channel *, int, char **); extern int weechat_cmd_server (t_irc_server *, t_irc_channel *, int, char **); extern int weechat_cmd_set (t_irc_server *, t_irc_channel *, char *); +extern int weechat_cmd_setp (t_irc_server *, t_irc_channel *, char *); extern int weechat_cmd_unalias (t_irc_server *, t_irc_channel *, char *); extern int weechat_cmd_unignore (t_irc_server *, t_irc_channel *, int, char **); extern int weechat_cmd_upgrade (t_irc_server *, t_irc_channel *, int, char **); diff --git a/src/common/completion.c b/src/common/completion.c index 9e1db9b60..400d270e8 100644 --- a/src/common/completion.c +++ b/src/common/completion.c @@ -408,6 +408,26 @@ completion_list_add_option (t_completion *completion) } /* + * completion_list_add_plugin_option: add plugin option to completion list + */ + +void +completion_list_add_plugin_option (t_completion *completion) +{ +#ifdef PLUGINS + t_plugin_option *ptr_option; + + for (ptr_option = plugin_options; ptr_option; + ptr_option = ptr_option->next_option) + { + weelist_add (&completion->completion_list, + &completion->last_completion, + ptr_option->name); + } +#endif +} + +/* * completion_list_add_part: add part message to completion list */ @@ -421,6 +441,26 @@ completion_list_add_part (t_completion *completion) } /* + * completion_list_add_plugin: add plugin name to completion list + */ + +void +completion_list_add_plugin (t_completion *completion) +{ +#ifdef PLUGINS + t_weechat_plugin *ptr_plugin; + + for (ptr_plugin = weechat_plugins; ptr_plugin; + ptr_plugin = ptr_plugin->next_plugin) + { + weelist_add (&completion->completion_list, + &completion->last_completion, + ptr_plugin->name); + } +#endif +} + +/* * completion_list_add_quit: add quit message to completion list */ @@ -569,6 +609,35 @@ completion_list_add_option_value (t_completion *completion) } /* + * completion_list_add_plugin_option_value: add plugin option value to completion list + */ + +void +completion_list_add_plugin_option_value (t_completion *completion) +{ +#ifdef PLUGINS + char *pos; + t_plugin_option *ptr_option; + + if (completion->args) + { + pos = strchr (completion->args, ' '); + if (pos) + pos[0] = '\0'; + + ptr_option = plugin_config_search_internal (completion->args); + if (ptr_option) + weelist_add (&completion->completion_list, + &completion->last_completion, + ptr_option->value); + + if (pos) + pos[0] = ' '; + } +#endif +} + +/* * completion_list_add_weechat_cmd: add WeeChat commands to completion list */ @@ -658,9 +727,15 @@ completion_build_list_template (t_completion *completion, char *template) case 'o': /* config option */ completion_list_add_option (completion); break; + case 'O': /* plugin option */ + completion_list_add_plugin_option (completion); + break; case 'p': /* part message */ completion_list_add_part (completion); break; + case 'P': /* plugin name */ + completion_list_add_plugin (completion); + break; case 'q': /* quit message */ completion_list_add_quit (completion); break; @@ -676,6 +751,9 @@ completion_build_list_template (t_completion *completion, char *template) case 'v': /* value of config option */ completion_list_add_option_value (completion); break; + case 'V': /* value of plugin option */ + completion_list_add_plugin_option_value (completion); + break; case 'w': /* WeeChat commands */ completion_list_add_weechat_cmd (completion); break; diff --git a/src/common/weechat.c b/src/common/weechat.c index 7acf4d5d3..cea92ad48 100644 --- a/src/common/weechat.c +++ b/src/common/weechat.c @@ -94,6 +94,36 @@ gnutls_certificate_credentials gnutls_xcred; /* gnutls client credentials */ /* + * ascii_tolower: locale independant string conversion to lower case + */ + +void +ascii_tolower (char *string) +{ + while (string && string[0]) + { + if ((string[0] >= 'A') && (string[0] <= 'Z')) + string[0] += ('a' - 'A'); + string++; + } +} + +/* + * ascii_toupper: locale independant string conversion to upper case + */ + +void +ascii_toupper (char *string) +{ + while (string && string[0]) + { + if ((string[0] >= 'a') && (string[0] <= 'z')) + string[0] -= ('a' - 'A'); + string++; + } +} + +/* * ascii_strcasecmp: locale and case independent string comparison */ diff --git a/src/common/weechat.h b/src/common/weechat.h index aec1ca321..6206cee37 100644 --- a/src/common/weechat.h +++ b/src/common/weechat.h @@ -105,6 +105,8 @@ extern char *local_charset; extern gnutls_certificate_credentials gnutls_xcred; #endif +extern void ascii_tolower (char *); +extern void ascii_toupper (char *); extern int ascii_strcasecmp (char *, char *); extern int ascii_strncasecmp (char *, char *, int); extern void weechat_log_printf (char *, ...); diff --git a/src/plugins/plugins-config.c b/src/plugins/plugins-config.c index 8db33242c..c959262d2 100644 --- a/src/plugins/plugins-config.c +++ b/src/plugins/plugins-config.c @@ -26,6 +26,7 @@ #include <stdlib.h> #include <string.h> +#include <ctype.h> #include <sys/types.h> #include <sys/stat.h> @@ -36,6 +37,7 @@ t_plugin_option *plugin_options = NULL; +t_plugin_option *last_plugin_option = NULL; /* @@ -51,8 +53,7 @@ plugin_config_search_internal (char *option) for (ptr_plugin_option = plugin_options; ptr_plugin_option; ptr_plugin_option = ptr_plugin_option->next_option) { - if (ascii_strcasecmp (ptr_plugin_option->option_name, - option) == 0) + if (ascii_strcasecmp (ptr_plugin_option->name, option) == 0) { return ptr_plugin_option; } @@ -89,6 +90,24 @@ plugin_config_search (t_weechat_plugin *plugin, char *option) } /* + * plugin_config_find_pos: find position for a plugin option (for sorting options) + */ + +t_plugin_option * +plugin_config_find_pos (char *name) +{ + t_plugin_option *ptr_option; + + for (ptr_option = plugin_options; ptr_option; + ptr_option = ptr_option->next_option) + { + if (ascii_strcasecmp (name, ptr_option->name) < 0) + return ptr_option; + } + return NULL; +} + +/* * plugin_config_set_internal: set value for a plugin option (internal function) * This function should not be called directly. */ @@ -96,7 +115,7 @@ plugin_config_search (t_weechat_plugin *plugin, char *option) int plugin_config_set_internal (char *option, char *value) { - t_plugin_option *ptr_plugin_option; + t_plugin_option *ptr_plugin_option, *pos_option; ptr_plugin_option = plugin_config_search_internal (option); if (ptr_plugin_option) @@ -125,18 +144,48 @@ plugin_config_set_internal (char *option, char *value) } else { - ptr_plugin_option = (t_plugin_option *)malloc (sizeof (t_plugin_option)); - if (ptr_plugin_option) + if (value && value[0]) { - /* create new option */ - ptr_plugin_option->option_name = strdup (option); - ptr_plugin_option->value = strdup (value); - if (plugin_options) - plugin_options->prev_option = ptr_plugin_option; - ptr_plugin_option->prev_option = NULL; - ptr_plugin_option->next_option = plugin_options; - plugin_options = ptr_plugin_option; - return 1; + ptr_plugin_option = (t_plugin_option *)malloc (sizeof (t_plugin_option)); + if (ptr_plugin_option) + { + /* create new option */ + ptr_plugin_option->name = strdup (option); + ascii_tolower (ptr_plugin_option->name); + ptr_plugin_option->value = strdup (value); + + if (plugin_options) + { + pos_option = plugin_config_find_pos (ptr_plugin_option->name); + if (pos_option) + { + /* insert option into the list (before option found) */ + ptr_plugin_option->prev_option = pos_option->prev_option; + ptr_plugin_option->next_option = pos_option; + if (pos_option->prev_option) + pos_option->prev_option->next_option = ptr_plugin_option; + else + plugin_options = ptr_plugin_option; + pos_option->prev_option = ptr_plugin_option; + } + else + { + /* add option to the end */ + ptr_plugin_option->prev_option = last_plugin_option; + ptr_plugin_option->next_option = NULL; + last_plugin_option->next_option = ptr_plugin_option; + last_plugin_option = ptr_plugin_option; + } + } + else + { + ptr_plugin_option->prev_option = NULL; + ptr_plugin_option->next_option = NULL; + plugin_options = ptr_plugin_option; + last_plugin_option = ptr_plugin_option; + } + return 1; + } } } @@ -318,7 +367,7 @@ plugin_config_write () ptr_plugin_option = ptr_plugin_option->next_option) { fprintf (file, "%s = \"%s\"\n", - ptr_plugin_option->option_name, + ptr_plugin_option->name, ptr_plugin_option->value); } diff --git a/src/plugins/plugins-config.h b/src/plugins/plugins-config.h index 92597b6aa..c1211ab8c 100644 --- a/src/plugins/plugins-config.h +++ b/src/plugins/plugins-config.h @@ -27,13 +27,17 @@ typedef struct t_plugin_option t_plugin_option; struct t_plugin_option { - char *option_name; /* option name in config file */ + char *name; /* option name in config file */ char *value; /* value of option */ t_plugin_option *prev_option; /* link to previous option */ t_plugin_option *next_option; /* link to next option */ }; +extern t_plugin_option *plugin_options; + +extern t_plugin_option *plugin_config_search_internal (char *); extern t_plugin_option *plugin_config_search (t_weechat_plugin *, char *); +extern int plugin_config_set_internal (char *, char *); extern int plugin_config_set (t_weechat_plugin *, char *, char *); extern void plugin_config_read (); extern int plugin_config_write (); diff --git a/src/plugins/plugins.h b/src/plugins/plugins.h index 44e2e4359..2ca01aa5b 100644 --- a/src/plugins/plugins.h +++ b/src/plugins/plugins.h @@ -22,6 +22,7 @@ #define __WEECHAT_PLUGINS_H 1 #include "weechat-plugin.h" +#include "plugins-config.h" #include "../irc/irc.h" #include "../gui/gui.h" |