1
0
mirror of https://github.com/weechat/weechat.git synced 2026-06-30 06:46:38 +02:00

Added config file functions in plugins API, improved /reload and /save commands (now possible to reload/save some files only), fixed completion bug

This commit is contained in:
Sebastien Helleu
2008-01-27 10:48:29 +01:00
parent ed26a0389c
commit ad41486543
30 changed files with 4687 additions and 4118 deletions
File diff suppressed because it is too large Load Diff
+2 -1
View File
@@ -213,7 +213,8 @@ weechat_lua_load (char *filename)
fclose (fp);
/* if script was registered, removing from list */
if (lua_current_script)
script_remove (weechat_lua_plugin, &lua_scripts, lua_current_script);
script_remove (weechat_lua_plugin, &lua_scripts,
lua_current_script);
return 0;
}
fclose (fp);
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+2 -2
View File
@@ -370,8 +370,8 @@ weechat_python_load (char *filename)
/* if script was registered, removing from list */
if (python_current_script != NULL)
{
script_remove (weechat_python_plugin,
&python_scripts, python_current_script);
script_remove (weechat_python_plugin, &python_scripts,
python_current_script);
}
return 0;
}
File diff suppressed because it is too large Load Diff
+2 -2
View File
@@ -376,8 +376,8 @@ weechat_ruby_load (char *filename)
if (ruby_current_script != NULL)
{
script_remove (weechat_ruby_plugin,
&ruby_scripts, ruby_current_script);
script_remove (weechat_ruby_plugin, &ruby_scripts,
ruby_current_script);
}
return 0;
+249 -20
View File
@@ -43,6 +43,247 @@ script_api_charset_set (struct t_plugin_script *script,
script->charset = (charset) ? strdup (charset) : NULL;
}
/*
* script_api_config_new: create a new configuration file
* return new configuration file, NULL if error
*/
struct t_config_file *
script_api_config_new (struct t_weechat_plugin *weechat_plugin,
struct t_plugin_script *script,
char *filename,
int (*callback_reload)(void *data,
struct t_config_file *config_file),
char *function)
{
struct t_script_callback *new_script_callback;
struct t_config_file *new_config_file;
if (function && function[0])
{
new_script_callback = script_callback_alloc ();
if (!new_script_callback)
return NULL;
new_config_file = weechat_config_new (filename, callback_reload,
new_script_callback);
if (!new_config_file)
{
free (new_script_callback);
return NULL;
}
new_script_callback->script = script;
new_script_callback->function = strdup (function);
new_script_callback->config_file = new_config_file;
script_callback_add (script, new_script_callback);
}
else
{
new_config_file = weechat_config_new (filename, NULL, NULL);
}
return new_config_file;
}
/*
* script_api_config_new_section: create a new section in configuration file
* return new section, NULL if error
*/
struct t_config_section *
script_api_config_new_section (struct t_weechat_plugin *weechat_plugin,
struct t_plugin_script *script,
struct t_config_file *config_file,
char *name,
void (*callback_read)(void *data,
struct t_config_file *config_file,
char *option_name,
char *value),
char *function_read,
void (*callback_write)(void *data,
struct t_config_file *config_file,
char *section_name),
char *function_write,
void (*callback_write_default)(void *data,
struct t_config_file *config_file,
char *section_name),
char *function_write_default)
{
struct t_script_callback *new_script_callback1, *new_script_callback2;
struct t_script_callback *new_script_callback3;
struct t_config_section *new_section;
void *callback1, *callback2, *callback3;
new_script_callback1 = NULL;
new_script_callback2 = NULL;
new_script_callback3 = NULL;
callback1 = NULL;
callback2 = NULL;
callback3 = NULL;
if (function_read && function_read[0])
{
new_script_callback1 = script_callback_alloc ();
if (!new_script_callback1)
return NULL;
callback1 = callback_read;
}
if (function_write && function_write[0])
{
new_script_callback2 = script_callback_alloc ();
if (!new_script_callback2)
{
if (new_script_callback1)
free (new_script_callback1);
return NULL;
}
callback2 = callback_write;
}
if (function_write_default && function_write_default[0])
{
new_script_callback3 = script_callback_alloc ();
if (!new_script_callback3)
{
if (new_script_callback1)
free (new_script_callback1);
if (new_script_callback2)
free (new_script_callback2);
return NULL;
}
callback3 = callback_write_default;
}
new_section = weechat_config_new_section (config_file,
name,
callback1,
new_script_callback1,
callback2,
new_script_callback2,
callback3,
new_script_callback3);
if (!new_section)
{
if (new_script_callback1)
free (new_script_callback1);
if (new_script_callback2)
free (new_script_callback2);
if (new_script_callback3)
free (new_script_callback3);
return NULL;
}
if (new_script_callback1)
{
new_script_callback1->script = script;
new_script_callback1->function = strdup (function_read);
new_script_callback1->config_file = config_file;
new_script_callback1->config_section = new_section;
script_callback_add (script, new_script_callback1);
}
if (new_script_callback2)
{
new_script_callback2->script = script;
new_script_callback2->function = strdup (function_write);
new_script_callback2->config_file = config_file;
new_script_callback2->config_section = new_section;
script_callback_add (script, new_script_callback2);
}
if (new_script_callback3)
{
new_script_callback3->script = script;
new_script_callback3->function = strdup (function_write_default);
new_script_callback3->config_file = config_file;
new_script_callback3->config_section = new_section;
script_callback_add (script, new_script_callback3);
}
return new_section;
}
/*
* script_api_config_new_option: create a new option in section
* return new option, NULL if error
*/
struct t_config_option *
script_api_config_new_option (struct t_weechat_plugin *weechat_plugin,
struct t_plugin_script *script,
struct t_config_file *config_file,
struct t_config_section *section,
char *name, char *type,
char *description, char *string_values,
int min, int max, char *default_value,
void (*callback_change)(void *data),
char *function)
{
struct t_script_callback *new_script_callback;
struct t_config_option *new_option;
if (function && function[0])
{
new_script_callback = script_callback_alloc ();
if (!new_script_callback)
return NULL;
new_option = weechat_config_new_option (config_file, section, name, type,
description, string_values, min,
max, default_value,
callback_change,
new_script_callback);
if (!new_option)
{
free (new_script_callback);
return NULL;
}
new_script_callback->script = script;
new_script_callback->function = strdup (function);
new_script_callback->config_file = config_file;
new_script_callback->config_section = section;
new_script_callback->config_option = new_option;
script_callback_add (script, new_script_callback);
}
else
{
new_option = weechat_config_new_option (config_file, section, name, type,
description, string_values, min,
max, default_value, NULL, NULL);
}
return new_option;
}
/*
* script_api_config_free: free configuration file
*/
void
script_api_config_free (struct t_weechat_plugin *weechat_plugin,
struct t_plugin_script *script,
struct t_config_file *config_file)
{
struct t_script_callback *ptr_script_callback;
if (!weechat_plugin || !script || !config_file)
return;
weechat_config_free (config_file);
for (ptr_script_callback = script->callbacks; ptr_script_callback;
ptr_script_callback = ptr_script_callback->next_callback)
{
if (ptr_script_callback->config_file == config_file)
script_callback_remove (script, ptr_script_callback);
}
}
/*
* script_api_printf: print a message
*/
@@ -140,10 +381,6 @@ script_api_hook_command (struct t_weechat_plugin *weechat_plugin,
if (!new_script_callback)
return NULL;
new_script_callback->script = NULL;
new_script_callback->function = NULL;
new_script_callback->hook = NULL;
new_hook = weechat_hook_command (command, description, args,
args_description, completion,
callback, new_script_callback);
@@ -423,10 +660,9 @@ script_api_hook_modifier (struct t_weechat_plugin *weechat_plugin,
/*
* script_api_unhook: unhook something
* return 1 if ok, 0 if error
*/
int
void
script_api_unhook (struct t_weechat_plugin *weechat_plugin,
struct t_plugin_script *script,
struct t_hook *hook)
@@ -434,22 +670,16 @@ script_api_unhook (struct t_weechat_plugin *weechat_plugin,
struct t_script_callback *ptr_script_callback;
if (!weechat_plugin || !script || !hook)
return 0;
return;
weechat_unhook (hook);
for (ptr_script_callback = script->callbacks; ptr_script_callback;
ptr_script_callback = ptr_script_callback->next_callback)
{
if (ptr_script_callback->hook == hook)
break;
script_callback_remove (script, ptr_script_callback);
}
if (ptr_script_callback)
{
script_callback_remove (weechat_plugin, script, ptr_script_callback);
return 1;
}
return 0;
}
/*
@@ -457,8 +687,7 @@ script_api_unhook (struct t_weechat_plugin *weechat_plugin,
*/
void
script_api_unhook_all (struct t_weechat_plugin *weechat_plugin,
struct t_plugin_script *script)
script_api_unhook_all (struct t_plugin_script *script)
{
struct t_script_callback *ptr_callback, *next_callback;
@@ -467,7 +696,7 @@ script_api_unhook_all (struct t_weechat_plugin *weechat_plugin,
{
next_callback = ptr_callback->next_callback;
script_callback_remove (weechat_plugin, script, ptr_callback);
script_callback_remove (script, ptr_callback);
ptr_callback = next_callback;
}
@@ -539,7 +768,7 @@ script_api_buffer_close (struct t_weechat_plugin *weechat_plugin,
if (ptr_script_callback)
{
script_callback_remove (weechat_plugin, script, ptr_script_callback);
script_callback_remove (script, ptr_script_callback);
}
}
+42 -5
View File
@@ -21,6 +21,44 @@
extern void script_api_charset_set (struct t_plugin_script *script,
char *charset);
extern struct t_config_file *script_api_config_new (struct t_weechat_plugin *weechat_plugin,
struct t_plugin_script *script,
char *filename,
int (*callback_reload)(void *data,
struct t_config_file *config_file),
char *function);
extern struct t_config_section *script_api_config_new_section (struct t_weechat_plugin *weechat_plugin,
struct t_plugin_script *script,
struct t_config_file *config_file,
char *name,
void (*callback_read)(void *data,
struct t_config_file *config_file,
char *option_name,
char *value),
char *function_read,
void (*callback_write)(void *data,
struct t_config_file *config_file,
char *section_name),
char *function_write,
void (*callback_write_default)(void *data,
struct t_config_file *config_file,
char *section_name),
char *function_write_default);
extern struct t_config_option *script_api_config_new_option (struct t_weechat_plugin *weechat_plugin,
struct t_plugin_script *script,
struct t_config_file *config_file,
struct t_config_section *section,
char *name,
char *type,
char *description,
char *string_values,
int min, int max,
char *default_value,
void (*callback_change)(void *data),
char *function);
extern void script_api_config_free (struct t_weechat_plugin *weechat_plugin,
struct t_plugin_script *script,
struct t_config_file *config_file);
extern void script_api_printf (struct t_weechat_plugin *weechat_plugin,
struct t_plugin_script *script,
struct t_gui_buffer *buffer,
@@ -95,11 +133,10 @@ extern struct t_hook *script_api_hook_modifier (struct t_weechat_plugin *weechat
char *modifier_data,
char *string),
char *function);
extern int script_api_unhook (struct t_weechat_plugin *weechat_plugin,
struct t_plugin_script *script,
struct t_hook *hook);
extern void script_api_unhook_all (struct t_weechat_plugin *weechat_plugin,
struct t_plugin_script *script);
extern void script_api_unhook (struct t_weechat_plugin *weechat_plugin,
struct t_plugin_script *script,
struct t_hook *hook);
extern void script_api_unhook_all (struct t_plugin_script *script);
struct t_gui_buffer *script_api_buffer_new (struct t_weechat_plugin *weechat_plugin,
struct t_plugin_script *script,
char *category, char *name,
+6 -7
View File
@@ -41,6 +41,9 @@ script_callback_alloc ()
{
new_script_callback->script = NULL;
new_script_callback->function = NULL;
new_script_callback->config_file = NULL;
new_script_callback->config_section = NULL;
new_script_callback->config_option = NULL;
new_script_callback->hook = NULL;
new_script_callback->buffer = NULL;
return new_script_callback;
@@ -69,8 +72,7 @@ script_callback_add (struct t_plugin_script *script,
*/
void
script_callback_remove (struct t_weechat_plugin *weechat_plugin,
struct t_plugin_script *script,
script_callback_remove (struct t_plugin_script *script,
struct t_script_callback *script_callback)
{
/* remove callback from list */
@@ -86,8 +88,6 @@ script_callback_remove (struct t_weechat_plugin *weechat_plugin,
/* unhook and free data */
if (script_callback->function)
free (script_callback->function);
if (script_callback->hook)
weechat_unhook (script_callback->hook);
free (script_callback);
}
@@ -97,12 +97,11 @@ script_callback_remove (struct t_weechat_plugin *weechat_plugin,
*/
void
script_callback_remove_all (struct t_weechat_plugin *weechat_plugin,
struct t_plugin_script *script)
script_callback_remove_all (struct t_plugin_script *script)
{
while (script->callbacks)
{
script_callback_remove (weechat_plugin, script, script->callbacks);
script_callback_remove (script, script->callbacks);
}
}
+9 -8
View File
@@ -21,10 +21,13 @@
struct t_script_callback
{
void *script; /* pointer to script */
char *function; /* script function called */
struct t_hook *hook; /* not NULL if hook */
struct t_gui_buffer *buffer; /* not NULL if buffer callback */
void *script; /* pointer to script */
char *function; /* script function called */
struct t_config_file *config_file; /* not NULL for config file */
struct t_config_section *config_section; /* not NULL for config section */
struct t_config_option *config_option; /* not NULL for config option */
struct t_hook *hook; /* not NULL for hook */
struct t_gui_buffer *buffer; /* not NULL for buffer callback*/
struct t_script_callback *prev_callback; /* link to next callback */
struct t_script_callback *next_callback; /* link to previous callback */
};
@@ -32,11 +35,9 @@ struct t_script_callback
extern struct t_script_callback *script_callback_alloc ();
extern void script_callback_add (struct t_plugin_script *script,
struct t_script_callback *callback);
extern void script_callback_remove (struct t_weechat_plugin *weechat_plugin,
struct t_plugin_script *script,
extern void script_callback_remove (struct t_plugin_script *script,
struct t_script_callback *script_callback);
extern void script_callback_remove_all (struct t_weechat_plugin *weechat_plugin,
struct t_plugin_script *script);
extern void script_callback_remove_all (struct t_plugin_script *script);
extern void script_callback_print_log (struct t_weechat_plugin *weechat_plugin,
struct t_script_callback *script_callback);
+20 -1
View File
@@ -411,8 +411,27 @@ script_remove (struct t_weechat_plugin *weechat_plugin,
struct t_plugin_script **scripts,
struct t_plugin_script *script)
{
struct t_script_callback *ptr_script_callback;
for (ptr_script_callback = script->callbacks; ptr_script_callback;
ptr_script_callback = ptr_script_callback->next_callback)
{
if (ptr_script_callback->hook)
{
weechat_unhook (ptr_script_callback->hook);
}
if (ptr_script_callback->config_file
&& !ptr_script_callback->config_section
&& !ptr_script_callback->config_option)
{
if (weechat_config_boolean (weechat_config_get_weechat ("plugins_save_config_on_unload")))
weechat_config_write (ptr_script_callback->config_file);
weechat_config_free (ptr_script_callback->config_file);
}
}
/* remove all callbacks created by this script */
script_callback_remove_all (weechat_plugin, script);
script_callback_remove_all (script);
/* free data */
if (script->filename)