mirror of
https://github.com/weechat/weechat.git
synced 2026-07-09 03:03:12 +02:00
Add of "modifier" hook, migration of charset plugin to new API, SIGHUP signal catched (reload all config files), better config files reloading
This commit is contained in:
+63
-45
@@ -31,6 +31,7 @@
|
||||
#include "weechat.h"
|
||||
#include "wee-command.h"
|
||||
#include "wee-config.h"
|
||||
#include "wee-config-file.h"
|
||||
#include "wee-hook.h"
|
||||
#include "wee-input.h"
|
||||
#include "wee-log.h"
|
||||
@@ -818,7 +819,7 @@ command_key (void *data, struct t_gui_buffer *buffer,
|
||||
else
|
||||
{
|
||||
gui_chat_printf (NULL,
|
||||
_("No key found."));
|
||||
_("No key found"));
|
||||
}
|
||||
if (internal_code)
|
||||
free (internal_code);
|
||||
@@ -1034,13 +1035,30 @@ command_plugin_list (char *name, int full)
|
||||
HOOK_COMPLETION(ptr_hook, completion));
|
||||
}
|
||||
}
|
||||
|
||||
/* modifier hooked */
|
||||
hook_found = 0;
|
||||
for (ptr_hook = weechat_hooks[HOOK_TYPE_MODIFIER]; ptr_hook;
|
||||
ptr_hook = ptr_hook->next_hook)
|
||||
{
|
||||
if (!ptr_hook->deleted && (ptr_hook->plugin == ptr_plugin))
|
||||
{
|
||||
if (!hook_found)
|
||||
gui_chat_printf (NULL,
|
||||
_(" modifiers hooked:"));
|
||||
hook_found = 1;
|
||||
gui_chat_printf (NULL,
|
||||
" %s",
|
||||
HOOK_MODIFIER(ptr_hook, modifier));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (plugins_found == 0)
|
||||
{
|
||||
if (name)
|
||||
gui_chat_printf (NULL, _("No plugin found."));
|
||||
gui_chat_printf (NULL, _("No plugin found"));
|
||||
else
|
||||
gui_chat_printf (NULL, _(" (no plugin)"));
|
||||
}
|
||||
@@ -1142,6 +1160,8 @@ int
|
||||
command_reload (void *data, struct t_gui_buffer *buffer,
|
||||
int argc, char **argv, char **argv_eol)
|
||||
{
|
||||
struct t_config_file *ptr_config_file;
|
||||
|
||||
/* make C compiler happy */
|
||||
(void) data;
|
||||
(void) buffer;
|
||||
@@ -1149,28 +1169,26 @@ command_reload (void *data, struct t_gui_buffer *buffer,
|
||||
(void) argv;
|
||||
(void) argv_eol;
|
||||
|
||||
/* reload WeeChat configuration */
|
||||
if (config_weechat_reload () == 0)
|
||||
gui_chat_printf (NULL,
|
||||
_("%sWeeChat configuration file reloaded"),
|
||||
gui_chat_prefix[GUI_CHAT_PREFIX_INFO]);
|
||||
else
|
||||
gui_chat_printf (NULL,
|
||||
_("%sError: failed to reload WeeChat configuration "
|
||||
"file"),
|
||||
gui_chat_prefix[GUI_CHAT_PREFIX_ERROR]);
|
||||
|
||||
/* reload plugins configuration */
|
||||
if (plugin_config_reload () == 0)
|
||||
gui_chat_printf (NULL, _("%sPlugins options reloaded"),
|
||||
gui_chat_prefix[GUI_CHAT_PREFIX_INFO]);
|
||||
else
|
||||
gui_chat_printf (NULL,
|
||||
_("%sError: failed to reload plugins options"),
|
||||
gui_chat_prefix[GUI_CHAT_PREFIX_ERROR]);
|
||||
|
||||
/* tell to plugins to reload their configuration */
|
||||
hook_signal_send ("config_reload", WEECHAT_HOOK_SIGNAL_STRING, NULL);
|
||||
for (ptr_config_file = config_files; ptr_config_file;
|
||||
ptr_config_file = ptr_config_file->next_config)
|
||||
{
|
||||
if (ptr_config_file->callback_reload)
|
||||
{
|
||||
if ((int) (ptr_config_file->callback_reload) (ptr_config_file) == 0)
|
||||
{
|
||||
gui_chat_printf (NULL, _("%sOptions reloaded from %s"),
|
||||
gui_chat_prefix[GUI_CHAT_PREFIX_INFO],
|
||||
ptr_config_file->filename);
|
||||
}
|
||||
else
|
||||
{
|
||||
gui_chat_printf (NULL,
|
||||
_("%sError: failed to reload options from %s"),
|
||||
gui_chat_prefix[GUI_CHAT_PREFIX_ERROR],
|
||||
ptr_config_file->filename);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return WEECHAT_RC_OK;
|
||||
}
|
||||
@@ -1183,32 +1201,32 @@ int
|
||||
command_save (void *data, struct t_gui_buffer *buffer,
|
||||
int argc, char **argv, char **argv_eol)
|
||||
{
|
||||
struct t_config_file *ptr_config_file;
|
||||
|
||||
/* make C compiler happy */
|
||||
(void) data;
|
||||
(void) buffer;
|
||||
(void) argc;
|
||||
(void) argv;
|
||||
(void) argv_eol;
|
||||
|
||||
/* save WeeChat configuration */
|
||||
if (config_weechat_write () == 0)
|
||||
gui_chat_printf (NULL,
|
||||
_("%sWeeChat configuration file saved"),
|
||||
gui_chat_prefix[GUI_CHAT_PREFIX_INFO]);
|
||||
else
|
||||
gui_chat_printf (NULL,
|
||||
_("%sError: failed to save WeeChat configuration "
|
||||
"file"),
|
||||
gui_chat_prefix[GUI_CHAT_PREFIX_ERROR]);
|
||||
|
||||
/* save plugins configuration */
|
||||
if (plugin_config_write () == 0)
|
||||
gui_chat_printf (NULL, _("%sPlugins options saved"),
|
||||
gui_chat_prefix[GUI_CHAT_PREFIX_INFO]);
|
||||
else
|
||||
gui_chat_printf (NULL,
|
||||
_("%sError: failed to save plugins options"),
|
||||
gui_chat_prefix[GUI_CHAT_PREFIX_ERROR]);
|
||||
for (ptr_config_file = config_files; ptr_config_file;
|
||||
ptr_config_file = ptr_config_file->next_config)
|
||||
{
|
||||
if (config_file_write (ptr_config_file) == 0)
|
||||
{
|
||||
gui_chat_printf (NULL, _("%sOptions saved to %s"),
|
||||
gui_chat_prefix[GUI_CHAT_PREFIX_INFO],
|
||||
ptr_config_file->filename);
|
||||
}
|
||||
else
|
||||
{
|
||||
gui_chat_printf (NULL,
|
||||
_("%sError: failed to save options to %s"),
|
||||
gui_chat_prefix[GUI_CHAT_PREFIX_ERROR],
|
||||
ptr_config_file->filename);
|
||||
}
|
||||
}
|
||||
|
||||
return WEECHAT_RC_OK;
|
||||
}
|
||||
@@ -1826,7 +1844,7 @@ command_window (void *data, struct t_gui_buffer *buffer,
|
||||
gui_chat_printf (NULL,
|
||||
_("%sError: can not merge windows, "
|
||||
"there's no other window with same "
|
||||
"size near current one."),
|
||||
"size near current one"),
|
||||
gui_chat_prefix[GUI_CHAT_PREFIX_ERROR]);
|
||||
return WEECHAT_RC_ERROR;
|
||||
}
|
||||
@@ -1972,7 +1990,7 @@ command_init ()
|
||||
"all plugins, then autoload plugins)\n"
|
||||
" unload: unload one or all plugins\n\n"
|
||||
"Without argument, /plugin command lists loaded plugins."),
|
||||
"list|listfull|load|autoload|reload|unload %p",
|
||||
"list|listfull|load|autoload|reload|unload %f|%p",
|
||||
command_plugin, NULL);
|
||||
hook_command (NULL, "quit",
|
||||
N_("quit WeeChat"),
|
||||
|
||||
@@ -20,6 +20,10 @@
|
||||
#ifndef __WEECHAT_COMMAND_H
|
||||
#define __WEECHAT_COMMAND_H 1
|
||||
|
||||
struct t_gui_buffer;
|
||||
|
||||
extern int command_reload (void *data, struct t_gui_buffer *buffer,
|
||||
int argc, char **argv, char **argv_eol);
|
||||
extern void command_init ();
|
||||
extern void command_print_stdout ();
|
||||
|
||||
|
||||
@@ -69,7 +69,8 @@ config_file_search (char *filename)
|
||||
*/
|
||||
|
||||
struct t_config_file *
|
||||
config_file_new (struct t_weechat_plugin *plugin, char *filename)
|
||||
config_file_new (struct t_weechat_plugin *plugin, char *filename,
|
||||
int (*callback_reload)(struct t_config_file *config_file))
|
||||
{
|
||||
struct t_config_file *new_config_file;
|
||||
|
||||
@@ -86,6 +87,7 @@ config_file_new (struct t_weechat_plugin *plugin, char *filename)
|
||||
new_config_file->plugin = plugin;
|
||||
new_config_file->filename = strdup (filename);
|
||||
new_config_file->file = NULL;
|
||||
new_config_file->callback_reload = callback_reload;
|
||||
new_config_file->sections = NULL;
|
||||
new_config_file->last_section = NULL;
|
||||
|
||||
|
||||
@@ -40,6 +40,8 @@ struct t_config_file
|
||||
struct t_weechat_plugin *plugin; /* plugin which created this cfg */
|
||||
char *filename; /* config filename (without path)*/
|
||||
FILE *file; /* file pointer */
|
||||
int (*callback_reload) /* callback for reloading file */
|
||||
(struct t_config_file *config_file);
|
||||
struct t_config_section *sections; /* config sections */
|
||||
struct t_config_section *last_section; /* last config section */
|
||||
struct t_config_file *prev_config; /* link to previous config file */
|
||||
@@ -87,8 +89,12 @@ struct t_config_option
|
||||
struct t_config_option *next_option; /* link to next option */
|
||||
};
|
||||
|
||||
extern struct t_config_file *config_files;
|
||||
extern struct t_config_file *last_config_file;
|
||||
|
||||
extern struct t_config_file *config_file_new (struct t_weechat_plugin *plugin,
|
||||
char *filename);
|
||||
char *filename,
|
||||
int (*callback_reload)(struct t_config_file *config_file));
|
||||
extern int config_file_valid_for_plugin (struct t_weechat_plugin *plugin,
|
||||
struct t_config_file *config_file);
|
||||
extern struct t_config_section *config_file_new_section (struct t_config_file *config_file,
|
||||
|
||||
+23
-19
@@ -414,6 +414,25 @@ config_change_day_change ()
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* config_weechat_reload: reload WeeChat configuration file
|
||||
* return: 0 = successful
|
||||
* -1 = config file file not found
|
||||
* -2 = error in config file
|
||||
*/
|
||||
|
||||
int
|
||||
config_weechat_reload (struct t_config_file *config_file)
|
||||
{
|
||||
/* make C compiler happy */
|
||||
(void) config_file;
|
||||
|
||||
/* remove all keys */
|
||||
gui_keyboard_free_all ();
|
||||
|
||||
return config_file_reload (weechat_config_file);
|
||||
}
|
||||
|
||||
/*
|
||||
* config_weechat_read_key: read a key in configuration file
|
||||
*/
|
||||
@@ -495,7 +514,8 @@ config_weechat_init ()
|
||||
{
|
||||
struct t_config_section *ptr_section;
|
||||
|
||||
weechat_config_file = config_file_new (NULL, WEECHAT_CONFIG_FILENAME);
|
||||
weechat_config_file = config_file_new (NULL, WEECHAT_CONFIG_FILENAME,
|
||||
&config_weechat_reload);
|
||||
if (!weechat_config_file)
|
||||
return 0;
|
||||
|
||||
@@ -1159,23 +1179,6 @@ config_weechat_read ()
|
||||
return rc;
|
||||
}
|
||||
|
||||
/*
|
||||
* config_weechat_reload: reload WeeChat configuration file
|
||||
* return: 0 = successful
|
||||
* -1 = configuration file file not found
|
||||
* -2 = error in configuration file
|
||||
*/
|
||||
|
||||
int
|
||||
config_weechat_reload ()
|
||||
{
|
||||
/* remove all keys */
|
||||
gui_keyboard_free_all ();
|
||||
|
||||
/* reload configuration file */
|
||||
return config_file_reload (weechat_config_file);
|
||||
}
|
||||
|
||||
/*
|
||||
* config_weechat_write: write WeeChat configuration file
|
||||
* return: 0 if ok
|
||||
@@ -1185,6 +1188,7 @@ config_weechat_reload ()
|
||||
int
|
||||
config_weechat_write ()
|
||||
{
|
||||
log_printf (_("Saving WeeChat configuration to disk"));
|
||||
log_printf (_("Saving WeeChat configuration to disk (%s)"),
|
||||
weechat_config_file->filename);
|
||||
return config_file_write (weechat_config_file);
|
||||
}
|
||||
|
||||
+151
-45
@@ -256,6 +256,30 @@ hook_valid_for_plugin (struct t_weechat_plugin *plugin, struct t_hook *hook)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* hook_exec_start: code executed before a hook exec
|
||||
*/
|
||||
|
||||
void
|
||||
hook_exec_start ()
|
||||
{
|
||||
hook_exec_recursion++;
|
||||
}
|
||||
|
||||
/*
|
||||
* hook_exec_end: code executed after a hook exec
|
||||
*/
|
||||
|
||||
void
|
||||
hook_exec_end ()
|
||||
{
|
||||
if (hook_exec_recursion > 0)
|
||||
hook_exec_recursion--;
|
||||
|
||||
if (hook_exec_recursion == 0)
|
||||
hook_remove_deleted ();
|
||||
}
|
||||
|
||||
/*
|
||||
* hook_search_command: search command hook in list
|
||||
*/
|
||||
@@ -362,7 +386,7 @@ hook_command_exec (struct t_gui_buffer *buffer, char *string, int only_builtin)
|
||||
}
|
||||
argv_eol = string_explode (string, " ", 1, 0, NULL);
|
||||
|
||||
hook_exec_recursion++;
|
||||
hook_exec_start ();
|
||||
|
||||
ptr_hook = weechat_hooks[HOOK_TYPE_COMMAND];
|
||||
while (ptr_hook)
|
||||
@@ -383,10 +407,9 @@ hook_command_exec (struct t_gui_buffer *buffer, char *string, int only_builtin)
|
||||
rc = (int) (HOOK_COMMAND(ptr_hook, callback))
|
||||
(ptr_hook->callback_data, buffer, argc, argv, argv_eol);
|
||||
ptr_hook->running = 0;
|
||||
if (hook_exec_recursion > 0)
|
||||
hook_exec_recursion--;
|
||||
if (hook_exec_recursion == 0)
|
||||
hook_remove_deleted ();
|
||||
string_free_exploded (argv);
|
||||
string_free_exploded (argv_eol);
|
||||
hook_exec_end ();
|
||||
if (rc == WEECHAT_RC_ERROR)
|
||||
return 0;
|
||||
else
|
||||
@@ -399,11 +422,7 @@ hook_command_exec (struct t_gui_buffer *buffer, char *string, int only_builtin)
|
||||
string_free_exploded (argv);
|
||||
string_free_exploded (argv_eol);
|
||||
|
||||
if (hook_exec_recursion > 0)
|
||||
hook_exec_recursion--;
|
||||
|
||||
if (hook_exec_recursion == 0)
|
||||
hook_remove_deleted ();
|
||||
hook_exec_end ();
|
||||
|
||||
/* no hook found */
|
||||
return -1;
|
||||
@@ -530,7 +549,7 @@ hook_timer_exec ()
|
||||
|
||||
gettimeofday (&tv_time, NULL);
|
||||
|
||||
hook_exec_recursion++;
|
||||
hook_exec_start ();
|
||||
|
||||
ptr_hook = weechat_hooks[HOOK_TYPE_TIMER];
|
||||
while (ptr_hook)
|
||||
@@ -566,11 +585,7 @@ hook_timer_exec ()
|
||||
ptr_hook = next_hook;
|
||||
}
|
||||
|
||||
if (hook_exec_recursion > 0)
|
||||
hook_exec_recursion--;
|
||||
|
||||
if (hook_exec_recursion == 0)
|
||||
hook_remove_deleted ();
|
||||
hook_exec_end ();
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -686,7 +701,7 @@ hook_fd_exec (fd_set *read_fds, fd_set *write_fds, fd_set *exception_fds)
|
||||
{
|
||||
struct t_hook *ptr_hook, *next_hook;
|
||||
|
||||
hook_exec_recursion++;
|
||||
hook_exec_start ();
|
||||
|
||||
ptr_hook = weechat_hooks[HOOK_TYPE_FD];
|
||||
while (ptr_hook)
|
||||
@@ -710,11 +725,7 @@ hook_fd_exec (fd_set *read_fds, fd_set *write_fds, fd_set *exception_fds)
|
||||
ptr_hook = next_hook;
|
||||
}
|
||||
|
||||
if (hook_exec_recursion > 0)
|
||||
hook_exec_recursion--;
|
||||
|
||||
if (hook_exec_recursion == 0)
|
||||
hook_remove_deleted ();
|
||||
hook_exec_end ();
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -776,7 +787,7 @@ hook_print_exec (struct t_gui_buffer *buffer, time_t date, char *prefix,
|
||||
return;
|
||||
}
|
||||
|
||||
hook_exec_recursion++;
|
||||
hook_exec_start ();
|
||||
|
||||
ptr_hook = weechat_hooks[HOOK_TYPE_PRINT];
|
||||
while (ptr_hook)
|
||||
@@ -802,11 +813,7 @@ hook_print_exec (struct t_gui_buffer *buffer, time_t date, char *prefix,
|
||||
ptr_hook = next_hook;
|
||||
}
|
||||
|
||||
if (hook_exec_recursion > 0)
|
||||
hook_exec_recursion--;
|
||||
|
||||
if (hook_exec_recursion == 0)
|
||||
hook_remove_deleted ();
|
||||
hook_exec_end ();
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -853,7 +860,7 @@ hook_signal_send (char *signal, char *type_data, void *signal_data)
|
||||
{
|
||||
struct t_hook *ptr_hook, *next_hook;
|
||||
|
||||
hook_exec_recursion++;
|
||||
hook_exec_start ();
|
||||
|
||||
ptr_hook = weechat_hooks[HOOK_TYPE_SIGNAL];
|
||||
while (ptr_hook)
|
||||
@@ -874,11 +881,7 @@ hook_signal_send (char *signal, char *type_data, void *signal_data)
|
||||
ptr_hook = next_hook;
|
||||
}
|
||||
|
||||
if (hook_exec_recursion > 0)
|
||||
hook_exec_recursion--;
|
||||
|
||||
if (hook_exec_recursion == 0)
|
||||
hook_remove_deleted ();
|
||||
hook_exec_end ();
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -923,7 +926,7 @@ hook_config_exec (char *type, char *option, char *value)
|
||||
{
|
||||
struct t_hook *ptr_hook, *next_hook;
|
||||
|
||||
hook_exec_recursion++;
|
||||
hook_exec_start ();
|
||||
|
||||
ptr_hook = weechat_hooks[HOOK_TYPE_CONFIG];
|
||||
while (ptr_hook)
|
||||
@@ -948,11 +951,7 @@ hook_config_exec (char *type, char *option, char *value)
|
||||
ptr_hook = next_hook;
|
||||
}
|
||||
|
||||
if (hook_exec_recursion > 0)
|
||||
hook_exec_recursion--;
|
||||
|
||||
if (hook_exec_recursion == 0)
|
||||
hook_remove_deleted ();
|
||||
hook_exec_end ();
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1003,7 +1002,7 @@ hook_completion_exec (struct t_weechat_plugin *plugin, char *completion,
|
||||
/* make C compiler happy */
|
||||
(void) plugin;
|
||||
|
||||
hook_exec_recursion++;
|
||||
hook_exec_start ();
|
||||
|
||||
ptr_hook = weechat_hooks[HOOK_TYPE_COMPLETION];
|
||||
while (ptr_hook)
|
||||
@@ -1024,11 +1023,103 @@ hook_completion_exec (struct t_weechat_plugin *plugin, char *completion,
|
||||
ptr_hook = next_hook;
|
||||
}
|
||||
|
||||
if (hook_exec_recursion > 0)
|
||||
hook_exec_recursion--;
|
||||
hook_exec_end ();
|
||||
}
|
||||
|
||||
/*
|
||||
* hook_modifier: hook a modifier
|
||||
*/
|
||||
|
||||
struct t_hook *
|
||||
hook_modifier (struct t_weechat_plugin *plugin, char *modifier,
|
||||
t_hook_callback_modifier *callback, void *callback_data)
|
||||
{
|
||||
struct t_hook *new_hook;
|
||||
struct t_hook_modifier *new_hook_modifier;
|
||||
|
||||
if (hook_exec_recursion == 0)
|
||||
hook_remove_deleted ();
|
||||
if (!modifier || !modifier[0])
|
||||
return NULL;
|
||||
|
||||
new_hook = (struct t_hook *)malloc (sizeof (struct t_hook));
|
||||
if (!new_hook)
|
||||
return NULL;
|
||||
new_hook_modifier = (struct t_hook_modifier *)malloc (sizeof (struct t_hook_modifier));
|
||||
if (!new_hook_modifier)
|
||||
{
|
||||
free (new_hook);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
hook_init_data (new_hook, plugin, HOOK_TYPE_MODIFIER, callback_data);
|
||||
|
||||
new_hook->hook_data = new_hook_modifier;
|
||||
new_hook_modifier->callback = callback;
|
||||
new_hook_modifier->modifier = strdup (modifier);
|
||||
|
||||
hook_add_to_list (new_hook);
|
||||
|
||||
return new_hook;
|
||||
}
|
||||
|
||||
/*
|
||||
* hook_modifier_exec: execute modifier hook
|
||||
*/
|
||||
|
||||
char *
|
||||
hook_modifier_exec (struct t_weechat_plugin *plugin, char *modifier,
|
||||
char *modifier_data, char *string)
|
||||
{
|
||||
struct t_hook *ptr_hook, *next_hook;
|
||||
char *new_msg, *message_modified;
|
||||
|
||||
/* make C compiler happy */
|
||||
(void) plugin;
|
||||
|
||||
new_msg = NULL;
|
||||
message_modified = strdup (string);
|
||||
if (!message_modified)
|
||||
return NULL;
|
||||
|
||||
hook_exec_start ();
|
||||
|
||||
ptr_hook = weechat_hooks[HOOK_TYPE_MODIFIER];
|
||||
while (ptr_hook)
|
||||
{
|
||||
next_hook = ptr_hook->next_hook;
|
||||
|
||||
if (!ptr_hook->deleted
|
||||
&& !ptr_hook->running
|
||||
&& (string_strcasecmp (HOOK_MODIFIER(ptr_hook, modifier),
|
||||
modifier) == 0))
|
||||
{
|
||||
ptr_hook->running = 1;
|
||||
new_msg = (HOOK_MODIFIER(ptr_hook, callback))
|
||||
(ptr_hook->callback_data, modifier, modifier_data,
|
||||
message_modified);
|
||||
ptr_hook->running = 0;
|
||||
|
||||
/* empty string returned => message dropped */
|
||||
if (new_msg && !new_msg[0])
|
||||
{
|
||||
free (message_modified);
|
||||
hook_exec_end ();
|
||||
return new_msg;
|
||||
}
|
||||
|
||||
/* new message => keep it as base for next modifier */
|
||||
if (new_msg)
|
||||
{
|
||||
free (message_modified);
|
||||
message_modified = new_msg;
|
||||
}
|
||||
}
|
||||
|
||||
ptr_hook = next_hook;
|
||||
}
|
||||
|
||||
hook_exec_end ();
|
||||
|
||||
return message_modified;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1104,6 +1195,11 @@ unhook (struct t_hook *hook)
|
||||
free (HOOK_COMPLETION(hook, completion));
|
||||
free ((struct t_hook_completion *)hook->hook_data);
|
||||
break;
|
||||
case HOOK_TYPE_MODIFIER:
|
||||
if (HOOK_MODIFIER(hook, modifier))
|
||||
free (HOOK_MODIFIER(hook, modifier));
|
||||
free ((struct t_hook_modifier *)hook->hook_data);
|
||||
break;
|
||||
case HOOK_NUM_TYPES:
|
||||
/* this constant is used to count types only,
|
||||
it is never used as type */
|
||||
@@ -1288,6 +1384,16 @@ hook_print_log ()
|
||||
log_printf (" completion . . . . . : '%s'", HOOK_COMPLETION(ptr_hook, completion));
|
||||
}
|
||||
break;
|
||||
case HOOK_TYPE_MODIFIER:
|
||||
log_printf (" type . . . . . . . . . : %d (modifier)", ptr_hook->type);
|
||||
log_printf (" callback_data. . . . . : 0x%x", ptr_hook->callback_data);
|
||||
if (!ptr_hook->deleted)
|
||||
{
|
||||
log_printf (" modifier data:");
|
||||
log_printf (" callback . . . . . . : 0x%x", HOOK_MODIFIER(ptr_hook, callback));
|
||||
log_printf (" modifier . . . . . . : '%s'", HOOK_MODIFIER(ptr_hook, modifier));
|
||||
}
|
||||
break;
|
||||
case HOOK_NUM_TYPES:
|
||||
/* this constant is used to count types only,
|
||||
it is never used as type */
|
||||
|
||||
+19
-1
@@ -34,6 +34,7 @@ enum t_hook_type
|
||||
HOOK_TYPE_SIGNAL, /* signal */
|
||||
HOOK_TYPE_CONFIG, /* config option */
|
||||
HOOK_TYPE_COMPLETION, /* custom completions */
|
||||
HOOK_TYPE_MODIFIER, /* stirng modifier */
|
||||
/* number of hook types */
|
||||
HOOK_NUM_TYPES,
|
||||
};
|
||||
@@ -49,6 +50,7 @@ enum t_hook_type
|
||||
#define HOOK_SIGNAL(hook, var) (((struct t_hook_signal *)hook->hook_data)->var)
|
||||
#define HOOK_CONFIG(hook, var) (((struct t_hook_config *)hook->hook_data)->var)
|
||||
#define HOOK_COMPLETION(hook, var) (((struct t_hook_completion *)hook->hook_data)->var)
|
||||
#define HOOK_MODIFIER(hook, var) (((struct t_hook_modifier *)hook->hook_data)->var)
|
||||
|
||||
struct t_hook
|
||||
{
|
||||
@@ -139,7 +141,16 @@ typedef int (t_hook_callback_completion)(void *data, char *completion,
|
||||
struct t_hook_completion
|
||||
{
|
||||
t_hook_callback_completion *callback; /* completion callback */
|
||||
char *completion; /* name of completion */
|
||||
char *completion; /* name of completion */
|
||||
};
|
||||
|
||||
typedef char *(t_hook_callback_modifier)(void *data, char *modifier,
|
||||
char *modifier_data, char *string);
|
||||
|
||||
struct t_hook_modifier
|
||||
{
|
||||
t_hook_callback_modifier *callback; /* modifier callback */
|
||||
char *modifier; /* name of modifier */
|
||||
};
|
||||
|
||||
/* hook variables */
|
||||
@@ -203,6 +214,13 @@ extern void hook_completion_exec (struct t_weechat_plugin *plugin,
|
||||
char *completion,
|
||||
struct t_gui_buffer *buffer,
|
||||
struct t_weelist *list);
|
||||
extern struct t_hook *hook_modifier (struct t_weechat_plugin *plugin,
|
||||
char *modifier,
|
||||
t_hook_callback_modifier *callback,
|
||||
void *callback_data);
|
||||
extern char *hook_modifier_exec (struct t_weechat_plugin *plugin,
|
||||
char *modifier, char *modifier_data,
|
||||
char *string);
|
||||
extern void unhook (struct t_hook *hook);
|
||||
extern void unhook_all_plugin (struct t_weechat_plugin *plugin);
|
||||
extern void unhook_all ();
|
||||
|
||||
@@ -47,12 +47,12 @@
|
||||
|
||||
|
||||
/*
|
||||
* strndup: define strndup function if not existing (FreeBSD and maybe other)
|
||||
* string_strndup: define strndup function for systems where this function does
|
||||
* not exist (FreeBSD and maybe other)
|
||||
*/
|
||||
|
||||
#ifndef HAVE_STRNDUP
|
||||
char *
|
||||
strndup (char *string, int length)
|
||||
string_strndup (char *string, int length)
|
||||
{
|
||||
char *result;
|
||||
|
||||
@@ -68,7 +68,6 @@ strndup (char *string, int length)
|
||||
|
||||
return result;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* string_tolower: locale independant string conversion to lower case
|
||||
@@ -337,7 +336,7 @@ string_remove_quotes (char *string, char *quotes)
|
||||
{
|
||||
if (pos_end == (pos_start + 1))
|
||||
return strdup ("");
|
||||
return strndup (pos_start + 1, pos_end - pos_start - 1);
|
||||
return string_strndup (pos_start + 1, pos_end - pos_start - 1);
|
||||
}
|
||||
|
||||
return strdup (string);
|
||||
|
||||
@@ -20,9 +20,7 @@
|
||||
#ifndef __WEECHAT_STRING_H
|
||||
#define __WEECHAT_STRING_H 1
|
||||
|
||||
#ifndef HAVE_STRNDUP
|
||||
extern char *strndup (char *string, int length);
|
||||
#endif
|
||||
extern char *string_strndup (char *string, int length);
|
||||
extern void string_tolower (char *string);
|
||||
extern void string_toupper (char *string);
|
||||
extern int string_strcasecmp (char *string1, char *string2);
|
||||
|
||||
Reference in New Issue
Block a user