mirror of
https://github.com/weechat/weechat.git
synced 2026-06-26 04:46:37 +02:00
Added /setp command (set plugin options)
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
WeeChat - Wee Enhanced Environment for Chat
|
||||
===========================================
|
||||
|
||||
ChangeLog - 2006-03-21
|
||||
ChangeLog - 2006-03-24
|
||||
|
||||
|
||||
Version 0.1.9 (under dev!):
|
||||
* added /setp command (set plugin options)
|
||||
* fixed high CPU usage when running under a screen that has been killed
|
||||
* aliases are executed before WeeChat/IRC commands, /builtin command added
|
||||
* added /cycle command, /part command does close buffer any more (use
|
||||
|
||||
+220
-185
File diff suppressed because it is too large
Load Diff
+177
-5
@@ -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
|
||||
@@ -3294,6 +3301,171 @@ weechat_cmd_set (t_irc_server *server, t_irc_channel *channel,
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* 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
|
||||
*/
|
||||
|
||||
@@ -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 **);
|
||||
|
||||
@@ -407,6 +407,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
|
||||
*/
|
||||
@@ -420,6 +440,26 @@ completion_list_add_part (t_completion *completion)
|
||||
cfg_irc_default_msg_part);
|
||||
}
|
||||
|
||||
/*
|
||||
* 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
|
||||
*/
|
||||
@@ -568,6 +608,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;
|
||||
|
||||
@@ -93,6 +93,36 @@ gnutls_certificate_credentials gnutls_xcred; /* gnutls client credentials */
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
* 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
|
||||
*/
|
||||
|
||||
@@ -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 *, ...);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
@@ -88,6 +89,24 @@ plugin_config_search (t_weechat_plugin *plugin, char *option)
|
||||
return ptr_plugin_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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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 ();
|
||||
|
||||
@@ -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"
|
||||
|
||||
|
||||
+2
-1
@@ -1,10 +1,11 @@
|
||||
WeeChat - Wee Enhanced Environment for Chat
|
||||
===========================================
|
||||
|
||||
ChangeLog - 2006-03-21
|
||||
ChangeLog - 2006-03-24
|
||||
|
||||
|
||||
Version 0.1.9 (under dev!):
|
||||
* added /setp command (set plugin options)
|
||||
* fixed high CPU usage when running under a screen that has been killed
|
||||
* aliases are executed before WeeChat/IRC commands, /builtin command added
|
||||
* added /cycle command, /part command does close buffer any more (use
|
||||
|
||||
+225
-182
File diff suppressed because it is too large
Load Diff
+225
-182
File diff suppressed because it is too large
Load Diff
+232
-187
File diff suppressed because it is too large
Load Diff
+228
-185
File diff suppressed because it is too large
Load Diff
+220
-185
File diff suppressed because it is too large
Load Diff
@@ -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
|
||||
@@ -3294,6 +3301,171 @@ weechat_cmd_set (t_irc_server *server, t_irc_channel *channel,
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* 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
|
||||
*/
|
||||
|
||||
@@ -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 **);
|
||||
|
||||
@@ -407,6 +407,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
|
||||
*/
|
||||
@@ -420,6 +440,26 @@ completion_list_add_part (t_completion *completion)
|
||||
cfg_irc_default_msg_part);
|
||||
}
|
||||
|
||||
/*
|
||||
* 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
|
||||
*/
|
||||
@@ -568,6 +608,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;
|
||||
|
||||
@@ -93,6 +93,36 @@ gnutls_certificate_credentials gnutls_xcred; /* gnutls client credentials */
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
* 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
|
||||
*/
|
||||
|
||||
@@ -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 *, ...);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
@@ -88,6 +89,24 @@ plugin_config_search (t_weechat_plugin *plugin, char *option)
|
||||
return ptr_plugin_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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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 ();
|
||||
|
||||
@@ -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"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user