mirror of
https://github.com/weechat/weechat.git
synced 2026-07-08 18:53:12 +02:00
Added print hooks (to catch any printf on buffers)
This commit is contained in:
+36
-28
@@ -1268,28 +1268,37 @@ command_plugin_list (char *name, int full)
|
||||
hook_found = 1;
|
||||
gui_chat_printf (NULL,
|
||||
" /%s %s%s%s",
|
||||
((struct t_hook_command *)ptr_hook->hook_data)->command,
|
||||
(((struct t_hook_command *)ptr_hook->hook_data)->description) ? "(" : "",
|
||||
(((struct t_hook_command *)ptr_hook->hook_data)->description) ?
|
||||
((struct t_hook_command *)ptr_hook->hook_data)->description : "",
|
||||
(((struct t_hook_command *)ptr_hook->hook_data)->description) ? ")" : "");
|
||||
HOOK_COMMAND(ptr_hook, command),
|
||||
HOOK_COMMAND(ptr_hook, description) ? "(" : "",
|
||||
HOOK_COMMAND(ptr_hook, description) ?
|
||||
HOOK_COMMAND(ptr_hook, description) : "",
|
||||
HOOK_COMMAND(ptr_hook, description) ? ")" : "");
|
||||
}
|
||||
}
|
||||
|
||||
/* messages hooked */
|
||||
/* prints hooked */
|
||||
hook_found = 0;
|
||||
for (ptr_hook = weechat_hooks; ptr_hook;
|
||||
ptr_hook = ptr_hook->next_hook)
|
||||
{
|
||||
if ((ptr_hook->plugin == ptr_plugin)
|
||||
&& (ptr_hook->type == HOOK_TYPE_MESSAGE))
|
||||
&& (ptr_hook->type == HOOK_TYPE_PRINT))
|
||||
{
|
||||
if (!hook_found)
|
||||
gui_chat_printf (NULL, _(" messages hooked:"));
|
||||
gui_chat_printf (NULL, _(" prints hooked:"));
|
||||
hook_found = 1;
|
||||
gui_chat_printf (NULL,
|
||||
" %s",
|
||||
((struct t_hook_message *)ptr_hook->hook_data)->message);
|
||||
if (HOOK_PRINT(ptr_hook, buffer))
|
||||
gui_chat_printf (NULL,
|
||||
_(" buffer: %s / %s, message: \"%s\""),
|
||||
HOOK_PRINT(ptr_hook, buffer)->category,
|
||||
HOOK_PRINT(ptr_hook, buffer)->name,
|
||||
HOOK_PRINT(ptr_hook, message) ?
|
||||
HOOK_PRINT(ptr_hook, message) : _("(none)"));
|
||||
else
|
||||
gui_chat_printf (NULL,
|
||||
_(" message: \"%s\""),
|
||||
HOOK_PRINT(ptr_hook, message) ?
|
||||
HOOK_PRINT(ptr_hook, message) : _("(none)"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1299,7 +1308,7 @@ command_plugin_list (char *name, int full)
|
||||
ptr_hook = ptr_hook->next_hook)
|
||||
{
|
||||
if ((ptr_hook->plugin == ptr_plugin)
|
||||
&& (ptr_hook->type == HOOK_TYPE_MESSAGE))
|
||||
&& (ptr_hook->type == HOOK_TYPE_CONFIG))
|
||||
{
|
||||
if (!hook_found)
|
||||
gui_chat_printf (NULL,
|
||||
@@ -1308,11 +1317,10 @@ command_plugin_list (char *name, int full)
|
||||
hook_found = 1;
|
||||
gui_chat_printf (NULL,
|
||||
" (%s) %s",
|
||||
((struct t_hook_config *)ptr_hook->hook_data)->type ?
|
||||
((struct t_hook_config *)ptr_hook->hook_data)->type : "*",
|
||||
((struct t_hook_config *)ptr_hook->hook_data)->option ?
|
||||
((struct t_hook_config *)ptr_hook->hook_data)->option : "*");
|
||||
|
||||
HOOK_CONFIG(ptr_hook, type) ?
|
||||
HOOK_CONFIG(ptr_hook, type) : "*",
|
||||
HOOK_CONFIG(ptr_hook, option) ?
|
||||
HOOK_CONFIG(ptr_hook, option) : "*");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1327,28 +1335,28 @@ command_plugin_list (char *name, int full)
|
||||
if (!hook_found)
|
||||
gui_chat_printf (NULL, _(" timers hooked:"));
|
||||
hook_found = 1;
|
||||
interval = (((struct t_hook_timer *)ptr_hook->hook_data)->interval % 1000 == 0) ?
|
||||
((struct t_hook_timer *)ptr_hook->hook_data)->interval / 1000 :
|
||||
((struct t_hook_timer *)ptr_hook->hook_data)->interval;
|
||||
if (((struct t_hook_timer *)ptr_hook->hook_data)->remaining_calls > 0)
|
||||
interval = (HOOK_TIMER(ptr_hook, interval) % 1000 == 0) ?
|
||||
HOOK_TIMER(ptr_hook, interval) / 1000 :
|
||||
HOOK_TIMER(ptr_hook, interval);
|
||||
if (HOOK_TIMER(ptr_hook, remaining_calls) > 0)
|
||||
gui_chat_printf (NULL,
|
||||
_(" %d %s "
|
||||
"(%d calls remaining)"),
|
||||
interval,
|
||||
(((struct t_hook_timer *)ptr_hook->hook_data)->interval % 1000 == 0) ?
|
||||
(HOOK_TIMER(ptr_hook, interval) % 1000 == 0) ?
|
||||
((interval > 1) ?
|
||||
_("seconds") :
|
||||
_("second")) :
|
||||
((interval > 1) ?
|
||||
_("milliseconds") :
|
||||
_("millisecond")),
|
||||
((struct t_hook_timer *)ptr_hook->hook_data)->remaining_calls);
|
||||
HOOK_TIMER(ptr_hook, remaining_calls));
|
||||
else
|
||||
gui_chat_printf (NULL,
|
||||
_(" %d %s "
|
||||
"(no call limit)"),
|
||||
interval,
|
||||
(((struct t_hook_timer *)ptr_hook->hook_data)->interval % 1000 == 0) ?
|
||||
(HOOK_TIMER(ptr_hook, interval) % 1000 == 0) ?
|
||||
((interval > 1) ?
|
||||
_("seconds") :
|
||||
_("second")) :
|
||||
@@ -1357,14 +1365,14 @@ command_plugin_list (char *name, int full)
|
||||
_("millisecond")));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* fd hooked */
|
||||
hook_found = 0;
|
||||
for (ptr_hook = weechat_hooks; ptr_hook;
|
||||
ptr_hook = ptr_hook->next_hook)
|
||||
{
|
||||
if ((ptr_hook->plugin == ptr_plugin)
|
||||
&& (ptr_hook->type == HOOK_TYPE_MESSAGE))
|
||||
&& (ptr_hook->type == HOOK_TYPE_FD))
|
||||
{
|
||||
if (!hook_found)
|
||||
gui_chat_printf (NULL,
|
||||
@@ -1372,8 +1380,8 @@ command_plugin_list (char *name, int full)
|
||||
hook_found = 1;
|
||||
gui_chat_printf (NULL,
|
||||
_(" %d (flags: %d)"),
|
||||
((struct t_hook_fd *)ptr_hook->hook_data)->fd,
|
||||
((struct t_hook_fd *)ptr_hook->hook_data)->flags);
|
||||
HOOK_FD(ptr_hook, fd),
|
||||
HOOK_FD(ptr_hook, flags));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+107
-26
@@ -73,6 +73,28 @@ hook_init (struct t_hook *hook, void *plugin, int type, void *callback_data)
|
||||
hook->running = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* hook_valid: check if a hook pointer exists
|
||||
* return 1 if hook exists
|
||||
* 0 if hook is not found
|
||||
*/
|
||||
|
||||
int
|
||||
hook_valid (struct t_hook *hook)
|
||||
{
|
||||
struct t_hook *ptr_hook;
|
||||
|
||||
for (ptr_hook = weechat_hooks; ptr_hook;
|
||||
ptr_hook = ptr_hook->next_hook)
|
||||
{
|
||||
if (ptr_hook == hook)
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* hook not found */
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* hook_valid_for_plugin: check if a hook pointer exists for a plugin
|
||||
* return 1 if hook exists for plugin
|
||||
@@ -152,9 +174,9 @@ hook_command (void *plugin, char *command, char *description,
|
||||
int
|
||||
hook_command_exec (void *plugin, char *string)
|
||||
{
|
||||
struct t_hook *ptr_hook;
|
||||
struct t_hook *ptr_hook, *next_hook;
|
||||
char **argv, **argv_eol;
|
||||
int argc;
|
||||
int argc, rc;
|
||||
|
||||
if (!string || !string[0])
|
||||
return -1;
|
||||
@@ -166,21 +188,30 @@ hook_command_exec (void *plugin, char *string)
|
||||
return -1;
|
||||
}
|
||||
argv_eol = string_explode (string, " ", 1, 0, NULL);
|
||||
|
||||
for (ptr_hook = weechat_hooks; ptr_hook;
|
||||
ptr_hook = ptr_hook->next_hook)
|
||||
|
||||
ptr_hook = weechat_hooks;
|
||||
while (ptr_hook)
|
||||
{
|
||||
next_hook = ptr_hook->next_hook;
|
||||
|
||||
if ((ptr_hook->type == HOOK_TYPE_COMMAND)
|
||||
&& (!ptr_hook->running)
|
||||
&& (!plugin || (plugin == ptr_hook->plugin))
|
||||
&& (string_strcasecmp (argv[0] + 1,
|
||||
HOOK_COMMAND(ptr_hook, command)) == 0))
|
||||
{
|
||||
if ((int) (HOOK_COMMAND(ptr_hook, callback))
|
||||
(ptr_hook->callback_data, argc, argv, argv_eol) == PLUGIN_RC_FAILED)
|
||||
ptr_hook->running = 1;
|
||||
rc = (int) (HOOK_COMMAND(ptr_hook, callback))
|
||||
(ptr_hook->callback_data, argc, argv, argv_eol);
|
||||
if (hook_valid (ptr_hook))
|
||||
ptr_hook->running = 0;
|
||||
if (rc == PLUGIN_RC_FAILED)
|
||||
return 0;
|
||||
else
|
||||
return 1;
|
||||
}
|
||||
|
||||
ptr_hook = next_hook;
|
||||
}
|
||||
|
||||
string_free_exploded (argv);
|
||||
@@ -191,37 +222,72 @@ hook_command_exec (void *plugin, char *string)
|
||||
}
|
||||
|
||||
/*
|
||||
* hook_message: hook a message
|
||||
* hook_print: hook a message printed by WeeChat
|
||||
*/
|
||||
|
||||
struct t_hook *
|
||||
hook_message (void *plugin, char *message,
|
||||
t_hook_callback_message *callback, void *callback_data)
|
||||
hook_print (void *plugin, void *buffer, char *message,
|
||||
t_hook_callback_print *callback, void *callback_data)
|
||||
{
|
||||
struct t_hook *new_hook;
|
||||
struct t_hook_message *new_hook_message;
|
||||
struct t_hook_print *new_hook_print;
|
||||
|
||||
new_hook = (struct t_hook *)malloc (sizeof (struct t_hook));
|
||||
if (!new_hook)
|
||||
return NULL;
|
||||
new_hook_message = (struct t_hook_message *)malloc (sizeof (struct t_hook_message));
|
||||
if (!new_hook_message)
|
||||
new_hook_print = (struct t_hook_print *)malloc (sizeof (struct t_hook_print));
|
||||
if (!new_hook_print)
|
||||
{
|
||||
free (new_hook);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
hook_init (new_hook, plugin, HOOK_TYPE_MESSAGE, callback_data);
|
||||
|
||||
new_hook->hook_data = new_hook_message;
|
||||
new_hook_message->callback = callback;
|
||||
new_hook_message->message = (message) ? strdup (message) : strdup ("");
|
||||
hook_init (new_hook, plugin, HOOK_TYPE_PRINT, callback_data);
|
||||
|
||||
new_hook->hook_data = new_hook_print;
|
||||
new_hook_print->callback = callback;
|
||||
new_hook_print->buffer = (struct t_gui_buffer *)buffer;
|
||||
new_hook_print->message = (message) ? strdup (message) : NULL;
|
||||
|
||||
hook_add_to_list (new_hook);
|
||||
|
||||
return new_hook;
|
||||
}
|
||||
|
||||
/*
|
||||
* hook_print_exec: execute print hook
|
||||
*/
|
||||
|
||||
void
|
||||
hook_print_exec (void *buffer, time_t date, char *prefix, char *message)
|
||||
{
|
||||
struct t_hook *ptr_hook, *next_hook;
|
||||
|
||||
if (!message || !message[0])
|
||||
return;
|
||||
|
||||
ptr_hook = weechat_hooks;
|
||||
while (ptr_hook)
|
||||
{
|
||||
next_hook = ptr_hook->next_hook;
|
||||
|
||||
if ((ptr_hook->type == HOOK_TYPE_PRINT)
|
||||
&& (!ptr_hook->running)
|
||||
&& (!HOOK_PRINT(ptr_hook, buffer)
|
||||
|| ((struct t_gui_buffer *)buffer == HOOK_PRINT(ptr_hook, buffer)))
|
||||
&& (string_strcasestr (message, HOOK_PRINT(ptr_hook, message))))
|
||||
{
|
||||
ptr_hook->running = 1;
|
||||
(void) (HOOK_PRINT(ptr_hook, callback))
|
||||
(ptr_hook->callback_data, buffer, date, prefix, message);
|
||||
if (hook_valid (ptr_hook))
|
||||
ptr_hook->running = 0;
|
||||
}
|
||||
|
||||
ptr_hook = next_hook;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* hook_config: hook a config option
|
||||
*/
|
||||
@@ -270,6 +336,7 @@ hook_config_exec (char *type, char *option, char *value)
|
||||
next_hook = ptr_hook->next_hook;
|
||||
|
||||
if ((ptr_hook->type == HOOK_TYPE_CONFIG)
|
||||
&& (!ptr_hook->running)
|
||||
&& (!HOOK_CONFIG(ptr_hook, type)
|
||||
|| (string_strcasecmp (HOOK_CONFIG(ptr_hook, type),
|
||||
type) == 0))
|
||||
@@ -277,8 +344,11 @@ hook_config_exec (char *type, char *option, char *value)
|
||||
|| (string_strcasecmp (HOOK_CONFIG(ptr_hook, option),
|
||||
option) == 0)))
|
||||
{
|
||||
ptr_hook->running = 1;
|
||||
(void) (HOOK_CONFIG(ptr_hook, callback))
|
||||
(ptr_hook->callback_data, type, option, value);
|
||||
if (hook_valid (ptr_hook))
|
||||
ptr_hook->running = 0;
|
||||
}
|
||||
|
||||
ptr_hook = next_hook;
|
||||
@@ -334,14 +404,18 @@ hook_timer_exec (struct timeval *tv_time)
|
||||
{
|
||||
next_hook = ptr_hook->next_hook;
|
||||
|
||||
if (ptr_hook->type == HOOK_TYPE_TIMER)
|
||||
if ((ptr_hook->type == HOOK_TYPE_TIMER)
|
||||
&& (!ptr_hook->running))
|
||||
{
|
||||
time_diff = util_get_timeval_diff (&HOOK_TIMER(ptr_hook, last_exec),
|
||||
tv_time);
|
||||
if (time_diff >= HOOK_TIMER(ptr_hook, interval))
|
||||
{
|
||||
ptr_hook->running = 1;
|
||||
(void) (HOOK_TIMER(ptr_hook, callback))
|
||||
(ptr_hook->callback_data);
|
||||
if (hook_valid (ptr_hook))
|
||||
ptr_hook->running = 0;
|
||||
HOOK_TIMER(ptr_hook, last_exec).tv_sec = tv_time->tv_sec;
|
||||
HOOK_TIMER(ptr_hook, last_exec).tv_usec = tv_time->tv_usec;
|
||||
if (HOOK_TIMER(ptr_hook, remaining_calls) > 0)
|
||||
@@ -457,13 +531,19 @@ hook_fd_exec (fd_set *read_fds, fd_set *write_fds, fd_set *except_fds)
|
||||
next_hook = ptr_hook->next_hook;
|
||||
|
||||
if ((ptr_hook->type == HOOK_TYPE_FD)
|
||||
&& (!ptr_hook->running)
|
||||
&& (((HOOK_FD(ptr_hook, flags)& HOOK_FD_FLAG_READ)
|
||||
&& (FD_ISSET(HOOK_FD(ptr_hook, fd), read_fds)))
|
||||
|| ((HOOK_FD(ptr_hook, flags) & HOOK_FD_FLAG_WRITE)
|
||||
&& (FD_ISSET(HOOK_FD(ptr_hook, fd), write_fds)))
|
||||
|| ((HOOK_FD(ptr_hook, flags) & HOOK_FD_FLAG_EXCEPTION)
|
||||
&& (FD_ISSET(HOOK_FD(ptr_hook, fd), except_fds)))))
|
||||
{
|
||||
ptr_hook->running = 1;
|
||||
(HOOK_FD(ptr_hook, callback)) (ptr_hook->callback_data);
|
||||
if (hook_valid (ptr_hook))
|
||||
ptr_hook->running = 0;
|
||||
}
|
||||
|
||||
ptr_hook = next_hook;
|
||||
}
|
||||
@@ -499,10 +579,10 @@ unhook (struct t_hook *hook)
|
||||
free (HOOK_COMMAND(hook, completion));
|
||||
free ((struct t_hook_command *)hook->hook_data);
|
||||
break;
|
||||
case HOOK_TYPE_MESSAGE:
|
||||
if (HOOK_MESSAGE(hook, message))
|
||||
free (HOOK_MESSAGE(hook, message));
|
||||
free ((struct t_hook_message *)hook->hook_data);
|
||||
case HOOK_TYPE_PRINT:
|
||||
if (HOOK_PRINT(hook, message))
|
||||
free (HOOK_PRINT(hook, message));
|
||||
free ((struct t_hook_print *)hook->hook_data);
|
||||
break;
|
||||
case HOOK_TYPE_CONFIG:
|
||||
if (HOOK_CONFIG(hook, type))
|
||||
@@ -601,9 +681,10 @@ hook_print_log ()
|
||||
weechat_log_printf (" command_args_desc. . : '%s'\n", HOOK_COMMAND(ptr_hook, args_description));
|
||||
weechat_log_printf (" command_completion . : '%s'\n", HOOK_COMMAND(ptr_hook, completion));
|
||||
break;
|
||||
case HOOK_TYPE_MESSAGE:
|
||||
weechat_log_printf (" message data:\n");
|
||||
weechat_log_printf (" message. . . . . . . : '%s'\n", HOOK_MESSAGE(ptr_hook, message));
|
||||
case HOOK_TYPE_PRINT:
|
||||
weechat_log_printf (" print data:\n");
|
||||
weechat_log_printf (" buffer . . . . . . . : 0x%X\n", HOOK_PRINT(ptr_hook, buffer));
|
||||
weechat_log_printf (" message. . . . . . . : '%s'\n", HOOK_PRINT(ptr_hook, message));
|
||||
break;
|
||||
case HOOK_TYPE_CONFIG:
|
||||
weechat_log_printf (" config data:\n");
|
||||
|
||||
+13
-11
@@ -25,10 +25,9 @@
|
||||
enum t_hook_type
|
||||
{
|
||||
HOOK_TYPE_COMMAND = 0, /* new command */
|
||||
HOOK_TYPE_MESSAGE, /* message */
|
||||
HOOK_TYPE_PRINT, /* printed messages */
|
||||
HOOK_TYPE_CONFIG, /* config option */
|
||||
HOOK_TYPE_TIMER, /* timer (called each N milliseconds)*/
|
||||
/* (precision is about 20 msec) */
|
||||
HOOK_TYPE_TIMER, /* timer */
|
||||
HOOK_TYPE_FD, /* socket of file descriptor */
|
||||
HOOK_TYPE_KEYBOARD, /* keyboard handler */
|
||||
};
|
||||
@@ -38,7 +37,7 @@ enum t_hook_type
|
||||
#define HOOK_FD_FLAG_EXCEPTION 4
|
||||
|
||||
#define HOOK_COMMAND(hook, var) (((struct t_hook_command *)hook->hook_data)->var)
|
||||
#define HOOK_MESSAGE(hook, var) (((struct t_hook_message *)hook->hook_data)->var)
|
||||
#define HOOK_PRINT(hook, var) (((struct t_hook_print *)hook->hook_data)->var)
|
||||
#define HOOK_CONFIG(hook, var) (((struct t_hook_config *)hook->hook_data)->var)
|
||||
#define HOOK_TIMER(hook, var) (((struct t_hook_timer *)hook->hook_data)->var)
|
||||
#define HOOK_FD(hook, var) (((struct t_hook_fd *)hook->hook_data)->var)
|
||||
@@ -71,19 +70,20 @@ struct t_hook_command
|
||||
char *completion; /* template for completion */
|
||||
};
|
||||
|
||||
typedef int (t_hook_callback_message)(void *, char *);
|
||||
typedef int (t_hook_callback_print)(void *, void *, time_t, char *, char *);
|
||||
|
||||
struct t_hook_message
|
||||
struct t_hook_print
|
||||
{
|
||||
t_hook_callback_message *callback; /* message callback */
|
||||
char *message; /* message for hook */
|
||||
t_hook_callback_print *callback; /* print callback */
|
||||
struct t_gui_buffer *buffer; /* buffer selected (NULL = all) */
|
||||
char *message; /* part of message (NULL/empty = all)*/
|
||||
};
|
||||
|
||||
typedef int (t_hook_callback_config)(void *, char *, char *, char *);
|
||||
|
||||
struct t_hook_config
|
||||
{
|
||||
t_hook_callback_config *callback; /* message callback */
|
||||
t_hook_callback_config *callback; /* config callback */
|
||||
char *type; /* "weechat" or "plugin" */
|
||||
char *option; /* config option for hook */
|
||||
/* (NULL = hook for all options) */
|
||||
@@ -115,12 +115,14 @@ extern struct t_hook *last_weechat_hook;
|
||||
|
||||
/* hook functions */
|
||||
|
||||
extern int hook_valid (struct t_hook *);
|
||||
extern int hook_valid_for_plugin (void *, struct t_hook *);
|
||||
extern struct t_hook *hook_command (void *, char *, char *, char *, char *,
|
||||
char *, t_hook_callback_command *, void *);
|
||||
extern int hook_command_exec (void *, char *);
|
||||
extern struct t_hook *hook_message (void *, char *, t_hook_callback_message *,
|
||||
void *);
|
||||
extern struct t_hook *hook_print (void *, void *, char *,
|
||||
t_hook_callback_print *, void *);
|
||||
extern void hook_print_exec (void *, time_t, char *, char *);
|
||||
extern struct t_hook *hook_config (void *, char *, char *,
|
||||
t_hook_callback_config *, void *);
|
||||
extern void hook_config_exec (char *, char *, char *);
|
||||
|
||||
+11
-1
@@ -30,6 +30,7 @@
|
||||
|
||||
#include "../core/weechat.h"
|
||||
#include "../core/wee-config.h"
|
||||
#include "../core/wee-hook.h"
|
||||
#include "../core/wee-log.h"
|
||||
#include "../core/wee-string.h"
|
||||
#include "../core/wee-utf8.h"
|
||||
@@ -454,11 +455,12 @@ void
|
||||
gui_chat_printf_date (struct t_gui_buffer *buffer, time_t date,
|
||||
char *message, ...)
|
||||
{
|
||||
static char buf[8192];
|
||||
char buf[8192];
|
||||
time_t date_printed;
|
||||
int display_time;
|
||||
char *pos, *pos_prefix, *pos_tab, *pos_end;
|
||||
va_list argptr;
|
||||
struct t_gui_line *ptr_line;
|
||||
|
||||
if (gui_init_ok)
|
||||
{
|
||||
@@ -481,6 +483,8 @@ gui_chat_printf_date (struct t_gui_buffer *buffer, time_t date,
|
||||
date_printed = time (NULL);
|
||||
if (date <= 0)
|
||||
date = date_printed;
|
||||
|
||||
ptr_line = buffer->last_line;
|
||||
|
||||
pos = buf;
|
||||
while (pos)
|
||||
@@ -512,9 +516,15 @@ gui_chat_printf_date (struct t_gui_buffer *buffer, time_t date,
|
||||
pos_end[0] = '\0';
|
||||
|
||||
if (gui_init_ok)
|
||||
{
|
||||
gui_chat_line_add (buffer, (display_time) ? date : 0,
|
||||
(display_time) ? date_printed : 0,
|
||||
pos_prefix, pos);
|
||||
if (buffer->last_line)
|
||||
hook_print_exec (buffer, buffer->last_line->date,
|
||||
buffer->last_line->prefix,
|
||||
buffer->last_line->message);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (pos_prefix)
|
||||
|
||||
+45
-34
@@ -39,6 +39,44 @@
|
||||
static struct t_weechat_plugin *weechat_plugin = NULL;
|
||||
|
||||
|
||||
/*
|
||||
* demo_printf_command: demo command for printf
|
||||
*/
|
||||
|
||||
static int
|
||||
demo_printf_command (void *data, int argc, char **argv, char **argv_eol)
|
||||
{
|
||||
(void) data;
|
||||
(void) argc;
|
||||
(void) argv;
|
||||
(void) argv_eol;
|
||||
|
||||
if (argc > 1)
|
||||
weechat_printf (weechat_current_buffer,
|
||||
"demo_printf: %s", argv_eol[1]);
|
||||
else
|
||||
{
|
||||
weechat_printf (weechat_current_buffer,
|
||||
"demo message without prefix");
|
||||
weechat_printf (weechat_current_buffer,
|
||||
"%sdemo message with info prefix",
|
||||
weechat_prefix ("info"));
|
||||
weechat_printf (weechat_current_buffer,
|
||||
"%sdemo message with error prefix",
|
||||
weechat_prefix ("error"));
|
||||
weechat_printf (weechat_current_buffer,
|
||||
"colors: %s buffer %s nick1 %s nick2 %s nick3 "
|
||||
"%s nick4",
|
||||
weechat_color ("col_chat_buffer"),
|
||||
weechat_color ("col_chat_nick_color1"),
|
||||
weechat_color ("col_chat_nick_color2"),
|
||||
weechat_color ("col_chat_nick_color3"),
|
||||
weechat_color ("col_chat_nick_color4"));
|
||||
}
|
||||
|
||||
return PLUGIN_RC_SUCCESS;
|
||||
}
|
||||
|
||||
/*
|
||||
* demo_print_list: display a list
|
||||
*/
|
||||
@@ -143,34 +181,6 @@ demo_list_command (void *data, int argc, char **argv, char **argv_eol)
|
||||
return PLUGIN_RC_SUCCESS;
|
||||
}
|
||||
|
||||
/*
|
||||
* demo_printf_command: demo command for printf
|
||||
*/
|
||||
|
||||
static int
|
||||
demo_printf_command (void *data, int argc, char **argv, char **argv_eol)
|
||||
{
|
||||
(void) data;
|
||||
(void) argc;
|
||||
(void) argv;
|
||||
(void) argv_eol;
|
||||
|
||||
weechat_printf (NULL, "demo message without prefix");
|
||||
weechat_printf (NULL, "%sdemo message with info prefix",
|
||||
weechat_prefix ("info"));
|
||||
weechat_printf (NULL, "%sdemo message with error prefix",
|
||||
weechat_prefix ("error"));
|
||||
weechat_printf (NULL,
|
||||
"colors: %s buffer %s server %s nick1 %s nick2 %s nick3",
|
||||
weechat_color ("col_chat_buffer"),
|
||||
weechat_color ("col_chat_server"),
|
||||
weechat_color ("col_chat_nick_color1"),
|
||||
weechat_color ("col_chat_nick_color2"),
|
||||
weechat_color ("col_chat_nick_color3"));
|
||||
|
||||
return PLUGIN_RC_SUCCESS;
|
||||
}
|
||||
|
||||
/*
|
||||
* demo_info_command: demo command for info_get
|
||||
*/
|
||||
@@ -203,18 +213,19 @@ int
|
||||
weechat_plugin_init (struct t_weechat_plugin *plugin)
|
||||
{
|
||||
weechat_plugin = plugin;
|
||||
|
||||
|
||||
weechat_hook_command ("demo_printf", "demo command: print some messages",
|
||||
"[text]", "text: write some text on current buffer",
|
||||
"",
|
||||
demo_printf_command, NULL);
|
||||
|
||||
weechat_hook_command ("demo_list", "demo command: get and display list",
|
||||
"list",
|
||||
"list: list to display (values: buffer, "
|
||||
"buffer_lines)",
|
||||
"buffer|buffer_lines",
|
||||
demo_list_command, NULL);
|
||||
|
||||
weechat_hook_command ("demo_printf", "demo command: print some messages",
|
||||
"", "", "",
|
||||
demo_printf_command, NULL);
|
||||
|
||||
|
||||
weechat_hook_command ("demo_info", "demo command: get and display info",
|
||||
"info",
|
||||
"info: info to display (values: version, "
|
||||
|
||||
@@ -402,15 +402,18 @@ plugin_api_hook_command (struct t_weechat_plugin *plugin, char *command,
|
||||
}
|
||||
|
||||
/*
|
||||
* plugin_api_hook_message: hook a message
|
||||
* plugin_api_hook_print: hook a printed message
|
||||
*/
|
||||
|
||||
struct t_hook *
|
||||
plugin_api_hook_message (struct t_weechat_plugin *plugin, char *message,
|
||||
int (*callback)(void *, char *), void *data)
|
||||
plugin_api_hook_print (struct t_weechat_plugin *plugin, void *buffer,
|
||||
char *message,
|
||||
int (*callback)(void *, void *, time_t, char *, char *),
|
||||
void *data)
|
||||
{
|
||||
if (plugin && callback)
|
||||
return hook_message (plugin, message, callback, data);
|
||||
if (plugin && gui_buffer_valid ((struct t_gui_buffer *)buffer)
|
||||
&& callback)
|
||||
return hook_print (plugin, buffer, message, callback, data);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -59,9 +59,10 @@ extern struct t_hook *plugin_api_hook_command (struct t_weechat_plugin *,
|
||||
char *,
|
||||
int (*)(void *, int, char **, char **),
|
||||
void *);
|
||||
extern struct t_hook *plugin_api_hook_message (struct t_weechat_plugin *,
|
||||
char *, int (*)(void *, char *),
|
||||
void *);
|
||||
extern struct t_hook *plugin_api_hook_print (struct t_weechat_plugin *,
|
||||
void *, char *,
|
||||
int (*)(void *, void *, time_t, char *, char *),
|
||||
void *);
|
||||
extern struct t_hook *plugin_api_hook_config (struct t_weechat_plugin *,
|
||||
char *, char *,
|
||||
int (*)(void *, char *, char *, char *),
|
||||
|
||||
@@ -245,7 +245,7 @@ plugin_load (char *filename)
|
||||
new_plugin->infobar_remove = &plugin_api_infobar_remove;
|
||||
|
||||
new_plugin->hook_command = &plugin_api_hook_command;
|
||||
new_plugin->hook_message = &plugin_api_hook_message;
|
||||
new_plugin->hook_print = &plugin_api_hook_print;
|
||||
new_plugin->hook_config = &plugin_api_hook_config;
|
||||
new_plugin->hook_timer = &plugin_api_hook_timer;
|
||||
new_plugin->hook_fd = &plugin_api_hook_fd;
|
||||
|
||||
@@ -86,8 +86,9 @@ struct t_weechat_plugin
|
||||
char *, char *, char *,
|
||||
int (*)(void *, int, char **, char **),
|
||||
void *);
|
||||
struct t_hook *(*hook_message) (struct t_weechat_plugin *, char *,
|
||||
int (*)(void *, char *), void *);
|
||||
struct t_hook *(*hook_print) (struct t_weechat_plugin *, void *, char *,
|
||||
int (*)(void *, void *, time_t, char *, char *),
|
||||
void *);
|
||||
struct t_hook *(*hook_config) (struct t_weechat_plugin *, char *, char *,
|
||||
int (*)(void *, char *, char *, char *),
|
||||
void *);
|
||||
@@ -173,8 +174,9 @@ struct t_weechat_plugin
|
||||
weechat_plugin->hook_command(weechat_plugin, command, description, \
|
||||
args, args_desc, completion, callback, \
|
||||
data)
|
||||
#define weechat_hook_message(msg, callback, data) \
|
||||
weechat_plugin->hook_message(weechat_plugin, msg, callback, data)
|
||||
#define weechat_hook_print(buffer, msg, callback, data) \
|
||||
weechat_plugin->hook_print(weechat_plugin, buffer, msg, \
|
||||
callback, data)
|
||||
#define weechat_hook_config(type, option, callback, data) \
|
||||
weechat_plugin->hook_config(weechat_plugin, type, option, \
|
||||
callback, data)
|
||||
@@ -194,6 +196,8 @@ struct t_weechat_plugin
|
||||
weechat_plugin->buffer_new(weechat_plugin, category, name)
|
||||
#define weechat_buffer_search(category, name) \
|
||||
weechat_plugin->buffer_search(weechat_plugin, category, name)
|
||||
#define weechat_current_buffer \
|
||||
weechat_plugin->buffer_search(weechat_plugin, NULL, NULL)
|
||||
#define weechat_buffer_close(ptr_buffer) \
|
||||
weechat_plugin->buffer_close(weechat_plugin, ptr_buffer)
|
||||
#define weechat_buffer_set(ptr_buffer, property, value) \
|
||||
|
||||
Reference in New Issue
Block a user