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/common | |
parent | 9fb1176b1bc72b6d265f8b779479dbc3040e3b8f (diff) | |
download | weechat-d9c032fee32a84fae84c82a91c141145b4c4bfd0.zip |
Added /setp command (set plugin options)
Diffstat (limited to 'src/common')
-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 |
5 files changed, 288 insertions, 5 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 *, ...); |