1
0
mirror of https://github.com/weechat/weechat.git synced 2026-07-01 15:26:37 +02:00

Added completion system for plugins/scripts commands, fixed plugins autoload

This commit is contained in:
Sebastien Helleu
2005-12-16 14:16:03 +00:00
parent 6eabc3aa61
commit d5b58ff068
48 changed files with 6694 additions and 6012 deletions
+2
View File
@@ -237,12 +237,14 @@ t_plugin_handler *
weechat_plugin_cmd_handler_add (t_weechat_plugin *plugin, char *command,
char *description, char *arguments,
char *arguments_description,
char *completion_template,
t_plugin_handler_func *handler_func,
char *handler_args, void *handler_pointer)
{
if (plugin && command && handler_func)
return plugin_cmd_handler_add (plugin, command, description, arguments,
arguments_description,
completion_template,
handler_func,
handler_args, handler_pointer);
+53 -49
View File
@@ -225,10 +225,11 @@ plugin_msg_handler_add (t_weechat_plugin *plugin, char *irc_command,
* 3. command description (for /help)
* 4. command arguments (for /help)
* 5. command args description (for /help)
* 6. the handler function
* 7. handler args: a string given to
* 6. completion template
* 7. the handler function
* 8. handler args: a string given to
* handler when called (used by scripts)
* 8. handler pointer: a pointer given to
* 9. handler pointer: a pointer given to
* handler when called (used by scripts)
*/
@@ -236,6 +237,7 @@ t_plugin_handler *
plugin_cmd_handler_add (t_weechat_plugin *plugin, char *command,
char *description, char *arguments,
char *arguments_description,
char *completion_template,
t_plugin_handler_func *handler_func,
char *handler_args, void *handler_pointer)
{
@@ -260,6 +262,7 @@ plugin_cmd_handler_add (t_weechat_plugin *plugin, char *command,
new_handler->description = (description) ? strdup (description) : NULL;
new_handler->arguments = (arguments) ? strdup (arguments) : NULL;
new_handler->arguments_description = (arguments_description) ? strdup (arguments_description) : NULL;
new_handler->completion_template = (completion_template) ? strdup (completion_template) : NULL;
new_handler->handler = handler_func;
new_handler->handler_args = (handler_args) ? strdup (handler_args) : NULL;
new_handler->handler_pointer = handler_pointer;
@@ -706,35 +709,61 @@ int plugin_auto_load_file (t_weechat_plugin *plugin, char *filename)
void plugin_auto_load ()
{
char *ptr_home, *dir_name;
char *ptr_home, *dir_name, *list_plugins, *pos, *pos2;
/* auto-load plugins in WeeChat home dir */
if (cfg_plugins_path && cfg_plugins_path[0])
if (cfg_plugins_autoload && cfg_plugins_autoload[0])
{
if (cfg_plugins_path[0] == '~')
if (ascii_strcasecmp (cfg_plugins_autoload, "*") == 0)
{
ptr_home = getenv ("HOME");
dir_name = (char *)malloc (strlen (cfg_plugins_path) + strlen (ptr_home) + 2);
/* auto-load plugins in WeeChat home dir */
if (cfg_plugins_path && cfg_plugins_path[0])
{
if (cfg_plugins_path[0] == '~')
{
ptr_home = getenv ("HOME");
dir_name = (char *)malloc (strlen (cfg_plugins_path) + strlen (ptr_home) + 2);
if (dir_name)
{
strcpy (dir_name, ptr_home);
strcat (dir_name, cfg_plugins_path + 1);
plugin_exec_on_files (NULL, dir_name, &plugin_auto_load_file);
free (dir_name);
}
}
else
plugin_exec_on_files (NULL, cfg_plugins_path, &plugin_auto_load_file);
}
/* auto-load plugins in WeeChat global lib dir */
dir_name = (char *)malloc (strlen (WEECHAT_LIBDIR) + 16);
if (dir_name)
{
strcpy (dir_name, ptr_home);
strcat (dir_name, cfg_plugins_path + 1);
snprintf (dir_name, strlen (WEECHAT_LIBDIR) + 16,
"%s/plugins", WEECHAT_LIBDIR);
plugin_exec_on_files (NULL, dir_name, &plugin_auto_load_file);
free (dir_name);
}
}
else
plugin_exec_on_files (NULL, cfg_plugins_path, &plugin_auto_load_file);
}
/* auto-load plugins in WeeChat global lib dir */
dir_name = (char *)malloc (strlen (WEECHAT_LIBDIR) + 16);
if (dir_name)
{
snprintf (dir_name, strlen (WEECHAT_LIBDIR) + 16,
"%s/plugins", WEECHAT_LIBDIR);
plugin_exec_on_files (NULL, dir_name, &plugin_auto_load_file);
free (dir_name);
{
list_plugins = strdup (cfg_plugins_autoload);
if (list_plugins)
{
pos = list_plugins;
while (pos && pos[0])
{
pos2 = strchr (pos, ',');
if (pos2)
pos2[0] = '\0';
plugin_load (pos);
if (pos2)
pos = pos2 + 1;
else
pos = NULL;
}
free (list_plugins);
}
}
}
}
@@ -835,37 +864,12 @@ plugin_unload_all ()
void
plugin_init (int auto_load)
{
char *list_plugins, *pos, *pos2;
/* read plugins options on disk */
plugin_config_read ();
/* auto-load plugins if asked */
if (auto_load && cfg_plugins_autoload && cfg_plugins_autoload[0])
{
if (ascii_strcasecmp (cfg_plugins_autoload, "*") == 0)
plugin_auto_load ();
else
{
list_plugins = strdup (cfg_plugins_autoload);
if (list_plugins)
{
pos = list_plugins;
while (pos && pos[0])
{
pos2 = strchr (pos, ',');
if (pos2)
pos2[0] = '\0';
plugin_load (pos);
if (pos2)
pos = pos2 + 1;
else
pos = NULL;
}
free (list_plugins);
}
}
}
if (auto_load)
plugin_auto_load ();
}
/*
+1
View File
@@ -41,6 +41,7 @@ extern t_plugin_handler *plugin_msg_handler_add (t_weechat_plugin *, char *,
char *, void *);
extern t_plugin_handler *plugin_cmd_handler_add (t_weechat_plugin *, char *,
char *, char *, char *,
char *,
t_plugin_handler_func *,
char *, void *);
extern int plugin_msg_handler_exec (char *, char *, char *);
+4
View File
@@ -426,6 +426,7 @@ static XS (XS_weechat_add_message_handler)
static XS (XS_weechat_add_command_handler)
{
char *command, *function, *description, *arguments, *arguments_description;
char *completion_template;
unsigned int integer;
dXSARGS;
@@ -453,12 +454,14 @@ static XS (XS_weechat_add_command_handler)
description = (items >= 3) ? SvPV (ST (2), integer) : NULL;
arguments = (items >= 4) ? SvPV (ST (3), integer) : NULL;
arguments_description = (items >= 5) ? SvPV (ST (4), integer) : NULL;
completion_template = (items >= 6) ? SvPV (ST (5), integer) : NULL;
if (perl_plugin->cmd_handler_add (perl_plugin,
command,
description,
arguments,
arguments_description,
completion_template,
weechat_perl_handler,
function,
(void *)perl_current_script))
@@ -1197,6 +1200,7 @@ weechat_plugin_init (t_weechat_plugin *plugin)
"[load filename] | [autoload] | [reload] | [unload]",
"filename: Perl script (file) to load\n\n"
"Without argument, /perl command lists all loaded Perl scripts.",
"load|autoload|reload|unload",
weechat_perl_cmd, NULL, NULL);
plugin->mkdir_home (plugin, "perl");
+7 -2
View File
@@ -333,6 +333,7 @@ static PyObject *
weechat_python_add_command_handler (PyObject *self, PyObject *args)
{
char *command, *function, *description, *arguments, *arguments_description;
char *completion_template;
/* make gcc happy */
(void) self;
@@ -350,9 +351,11 @@ weechat_python_add_command_handler (PyObject *self, PyObject *args)
description = NULL;
arguments = NULL;
arguments_description = NULL;
completion_template = NULL;
if (!PyArg_ParseTuple (args, "ss|sss", &command, &function,
&description, &arguments, &arguments_description))
if (!PyArg_ParseTuple (args, "ss|ssss", &command, &function,
&description, &arguments, &arguments_description,
completion_template))
{
python_plugin->printf_server (python_plugin,
"Python error: wrong parameters for "
@@ -365,6 +368,7 @@ weechat_python_add_command_handler (PyObject *self, PyObject *args)
description,
arguments,
arguments_description,
completion_template,
weechat_python_handler,
function,
(void *)python_current_script))
@@ -1151,6 +1155,7 @@ weechat_plugin_init (t_weechat_plugin *plugin)
"[load filename] | [autoload] | [reload] | [unload]",
"filename: Python script (file) to load\n\n"
"Without argument, /python command lists all loaded Python scripts.",
"load|autoload|reload|unload",
weechat_python_cmd, NULL, NULL);
plugin->mkdir_home (plugin, "python");
+16 -3
View File
@@ -448,7 +448,9 @@ static VALUE
weechat_ruby_add_command_handler (int argc, VALUE *argv, VALUE class)
{
VALUE command, function, description, arguments, arguments_description;
VALUE completion_template;
char *c_command, *c_function, *c_description, *c_arguments, *c_arguments_description;
char *c_completion_template;
/* make gcc happy */
(void) class;
@@ -466,14 +468,16 @@ weechat_ruby_add_command_handler (int argc, VALUE *argv, VALUE class)
description = Qnil;
arguments = Qnil;
arguments_description = Qnil;
completion_template = Qnil;
c_command = NULL;
c_function = NULL;
c_description = NULL;
c_arguments = NULL;
c_arguments_description = NULL;
c_completion_template = NULL;
rb_scan_args (argc, argv, "23", &command, &function, &description,
&arguments, &arguments_description);
rb_scan_args (argc, argv, "24", &command, &function, &description,
&arguments, &arguments_description, &completion_template);
if (NIL_P (command) || NIL_P (function))
{
@@ -500,16 +504,24 @@ weechat_ruby_add_command_handler (int argc, VALUE *argv, VALUE class)
c_arguments = STR2CSTR (arguments);
}
if (!NIL_P (arguments_description)) {
if (!NIL_P (arguments_description))
{
Check_Type (arguments_description, T_STRING);
c_arguments_description = STR2CSTR (arguments_description);
}
if (!NIL_P (completion_template))
{
Check_Type (completion_template, T_STRING);
c_completion_template = STR2CSTR (completion_template);
}
if (ruby_plugin->cmd_handler_add (ruby_plugin,
c_command,
c_description,
c_arguments,
c_arguments_description,
c_completion_template,
weechat_ruby_handler,
c_function,
(void *)ruby_current_script))
@@ -1322,6 +1334,7 @@ weechat_plugin_init (t_weechat_plugin *plugin)
"[load filename] | [autoload] | [reload] | [unload]",
"filename: Ruby script (file) to load\n\n"
"Without argument, /ruby command lists all loaded Ruby scripts.",
"load|autoload|reload|unload",
weechat_ruby_cmd, NULL, NULL);
plugin->mkdir_home (plugin, "ruby");
+3
View File
@@ -86,6 +86,7 @@ struct t_plugin_handler
char *description; /* (for /help) short cmd description */
char *arguments; /* (for /help) command arguments */
char *arguments_description; /* (for /help) args long description */
char *completion_template; /* template for completion */
/* data common to all handlers */
t_plugin_handler_func *handler; /* pointer to handler */
@@ -141,6 +142,7 @@ struct t_weechat_plugin
char *, void *);
t_plugin_handler *(*cmd_handler_add) (t_weechat_plugin *, char *,
char *, char *, char *,
char *,
t_plugin_handler_func *,
char *, void *);
void (*handler_remove) (t_weechat_plugin *, t_plugin_handler *);
@@ -178,6 +180,7 @@ extern t_plugin_handler *weechat_plugin_msg_handler_add (t_weechat_plugin *, cha
char *, void *);
extern t_plugin_handler *weechat_plugin_cmd_handler_add (t_weechat_plugin *, char *,
char *, char *, char *,
char *,
t_plugin_handler_func *,
char *, void *);
extern void weechat_plugin_handler_remove (t_weechat_plugin *, t_plugin_handler *);