diff options
author | Sebastien Helleu <flashcode@flashtux.org> | 2007-11-05 15:59:43 +0100 |
---|---|---|
committer | Sebastien Helleu <flashcode@flashtux.org> | 2007-11-05 15:59:43 +0100 |
commit | 0d66286efe2ca1ee3375cef499a7a629883dc21c (patch) | |
tree | e15e3ffb5d73c2cafe548970552bc0ea64bcee20 /src | |
parent | a97e2955be68a91f0e55bbced190e5966bf3391d (diff) | |
download | weechat-0d66286efe2ca1ee3375cef499a7a629883dc21c.zip |
Added date option for printf functions (weechat core and plugins API)
Diffstat (limited to 'src')
-rw-r--r-- | src/gui/gui-buffer.h | 3 | ||||
-rw-r--r-- | src/gui/gui-chat.c | 17 | ||||
-rw-r--r-- | src/gui/gui-chat.h | 5 | ||||
-rw-r--r-- | src/plugins/demo/demo.c | 32 | ||||
-rw-r--r-- | src/plugins/plugin-api.c | 37 | ||||
-rw-r--r-- | src/plugins/plugin-api.h | 2 | ||||
-rw-r--r-- | src/plugins/plugin.c | 1 | ||||
-rw-r--r-- | src/plugins/weechat-plugin.h | 5 |
8 files changed, 84 insertions, 18 deletions
diff --git a/src/gui/gui-buffer.h b/src/gui/gui-buffer.h index e86a7b194..3b5840272 100644 --- a/src/gui/gui-buffer.h +++ b/src/gui/gui-buffer.h @@ -40,7 +40,8 @@ enum t_gui_buffer_type struct t_gui_line { - time_t date; /* date/time of line */ + time_t date; /* date/time of line (may be past) */ + time_t date_printed; /* date/time when weechat print it */ char *str_time; /* time string (for display) */ char *prefix; /* prefix for line (may be NULL) */ int prefix_length; /* prefix length (on screen) */ diff --git a/src/gui/gui-chat.c b/src/gui/gui-chat.c index 3e4a1a31b..4ae1c57a9 100644 --- a/src/gui/gui-chat.c +++ b/src/gui/gui-chat.c @@ -399,8 +399,8 @@ gui_chat_line_free (struct t_gui_line *line) */ void -gui_chat_line_add (struct t_gui_buffer *buffer, time_t date, char *prefix, - char *message) +gui_chat_line_add (struct t_gui_buffer *buffer, time_t date, + time_t date_printed, char *prefix, char *message) { struct t_gui_line *new_line, *ptr_line; @@ -413,6 +413,7 @@ gui_chat_line_add (struct t_gui_buffer *buffer, time_t date, char *prefix, /* add new line */ new_line->date = date; + new_line->date_printed = date_printed; new_line->str_time = (date == 0) ? NULL : gui_chat_get_time_string (date); new_line->prefix = (prefix) ? @@ -446,14 +447,15 @@ gui_chat_line_add (struct t_gui_buffer *buffer, time_t date, char *prefix, } /* - * gui_chat_printf: display a message in a buffer + * gui_chat_printf_date: display a message in a buffer */ void -gui_chat_printf (struct t_gui_buffer *buffer, char *message, ...) +gui_chat_printf_date (struct t_gui_buffer *buffer, time_t date, + char *message, ...) { static char buf[8192]; - time_t date; + time_t date_printed; int display_time; char *pos, *pos_prefix, *pos_tab, *pos_end; va_list argptr; @@ -476,7 +478,9 @@ gui_chat_printf (struct t_gui_buffer *buffer, char *message, ...) utf8_normalize (buf, '?'); - date = time (NULL); + date_printed = time (NULL); + if (date <= 0) + date = date_printed; pos = buf; while (pos) @@ -509,6 +513,7 @@ gui_chat_printf (struct t_gui_buffer *buffer, char *message, ...) if (gui_init_ok) gui_chat_line_add (buffer, (display_time) ? date : 0, + (display_time) ? date_printed : 0, pos_prefix, pos); else { diff --git a/src/gui/gui-chat.h b/src/gui/gui-chat.h index e2a341924..7addeff1a 100644 --- a/src/gui/gui-chat.h +++ b/src/gui/gui-chat.h @@ -22,6 +22,9 @@ #include "gui-buffer.h" +#define gui_chat_printf(buffer, argz...) \ + gui_chat_printf_date(buffer, 0, ##argz) \ + enum t_gui_prefix { GUI_CHAT_PREFIX_INFO = 0, @@ -49,7 +52,7 @@ extern int gui_chat_get_line_align (struct t_gui_buffer *, struct t_gui_line *, int); extern int gui_chat_line_search (struct t_gui_line *, char *, int); extern void gui_chat_line_free (struct t_gui_line *); -extern void gui_chat_printf (struct t_gui_buffer *, char *, ...); +extern void gui_chat_printf_date (struct t_gui_buffer *, time_t, char *, ...); extern void gui_chat_printf_raw_data (void *, int, int, char *); /* chat functions (GUI dependent) */ diff --git a/src/plugins/demo/demo.c b/src/plugins/demo/demo.c index 9b63e63a6..b5fdb9bb1 100644 --- a/src/plugins/demo/demo.c +++ b/src/plugins/demo/demo.c @@ -30,6 +30,7 @@ #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> +#include <time.h> #include "../weechat-plugin.h" #include "demo.h" @@ -47,6 +48,7 @@ demo_print_list (void *list, char *item_name) { char *fields, **argv; int i, j, argc; + time_t date; i = 1; while (weechat_list_next (list)) @@ -81,10 +83,10 @@ demo_print_list (void *list, char *item_name) argv[j] + 2)); break; case 't': - weechat_printf (NULL, " %s: %ld", + date = weechat_list_time (list, argv[j] + 2); + weechat_printf (NULL, " %s: (%ld) %s", argv[j] + 2, - weechat_list_time (list, - argv[j] + 2)); + date, ctime (&date)); break; } } @@ -115,6 +117,23 @@ demo_buffer_infos () } /* + * demo_buffer_lines: display buffer lines + */ + +static void +demo_buffer_lines () +{ + struct t_plugin_list *list; + + list = weechat_list_get ("buffer_lines", NULL); + if (list) + { + demo_print_list (list, "buffer_line"); + weechat_list_free (list); + } +} + +/* * demo_command: demo command */ @@ -132,6 +151,11 @@ demo_command (void *data, int argc, char **argv, char **argv_eol) demo_buffer_infos (); return PLUGIN_RC_SUCCESS; } + if (weechat_strcasecmp (argv[1], "buffer_lines") == 0) + { + demo_buffer_lines (); + return PLUGIN_RC_SUCCESS; + } } weechat_printf (NULL, @@ -153,7 +177,7 @@ weechat_plugin_init (struct t_weechat_plugin *plugin) weechat_hook_command ("demo", "demo command", "[action]", "action: one of following actions:\n" " buffer display infos about buffers", - "buffer", demo_command, NULL); + "buffer|buffer_lines", demo_command, NULL); return PLUGIN_RC_SUCCESS; } diff --git a/src/plugins/plugin-api.c b/src/plugins/plugin-api.c index 348bb49f5..c5b3da9ae 100644 --- a/src/plugins/plugin-api.c +++ b/src/plugins/plugin-api.c @@ -261,6 +261,28 @@ plugin_api_printf (struct t_weechat_plugin *plugin, } /* + * plugin_api_printf_date: print a message on a buffer with a specific date + */ + +void +plugin_api_printf_date (struct t_weechat_plugin *plugin, + void *buffer, time_t date, char *format, ...) +{ + va_list argptr; + char buf[8192]; + + if (!plugin || !format + || !gui_buffer_valid ((struct t_gui_buffer *)buffer)) + return; + + va_start (argptr, format); + vsnprintf (buf, sizeof (buf) - 1, format, argptr); + va_end (argptr); + + gui_chat_printf_date ((struct t_gui_buffer *)buffer, date, buf); +} + +/* * plugin_api_prefix: return a prefix for display with printf */ @@ -835,6 +857,8 @@ plugin_api_list_get_add_buffer_line (struct t_plugin_list *list, if (!plugin_list_new_var_time (ptr_item, "date", line->date)) return 0; + if (!plugin_list_new_var_time (ptr_item, "date_printed", line->date)) + return 0; if (!plugin_list_new_var_string (ptr_item, "str_time", line->str_time)) return 0; if (!plugin_list_new_var_string (ptr_item, "prefix", line->prefix)) @@ -901,13 +925,14 @@ plugin_api_list_get (struct t_weechat_plugin *plugin, char *name, } else if (string_strcasecmp (name, "buffer_lines") == 0) { - /* buffer pointer is mandatory for this list */ if (!pointer) - return NULL; - - /* invalid buffer pointer ? */ - if (!gui_buffer_valid ((struct t_gui_buffer *)pointer)) - return NULL; + pointer = gui_buffers; + else + { + /* invalid buffer pointer ? */ + if (!gui_buffer_valid ((struct t_gui_buffer *)pointer)) + return NULL; + } ptr_list = plugin_list_new (); if (ptr_list) diff --git a/src/plugins/plugin-api.h b/src/plugins/plugin-api.h index 7f34c16e6..a72e76d79 100644 --- a/src/plugins/plugin-api.h +++ b/src/plugins/plugin-api.h @@ -45,6 +45,8 @@ extern void plugin_api_exec_on_files (struct t_weechat_plugin *, char *, /* display */ extern void plugin_api_printf (struct t_weechat_plugin *, void *, char *, ...); +extern void plugin_api_printf_date (struct t_weechat_plugin *, void *, + time_t, char *, ...); extern char *plugin_api_prefix (struct t_weechat_plugin *, char *); extern char *plugin_api_color (struct t_weechat_plugin *, char *); extern void plugin_api_print_infobar (struct t_weechat_plugin *, int, diff --git a/src/plugins/plugin.c b/src/plugins/plugin.c index 842465dc5..4371670db 100644 --- a/src/plugins/plugin.c +++ b/src/plugins/plugin.c @@ -238,6 +238,7 @@ plugin_load (char *filename) new_plugin->exec_on_files = &plugin_api_exec_on_files; new_plugin->printf = &plugin_api_printf; + new_plugin->printf_date = &plugin_api_printf_date; new_plugin->prefix = &plugin_api_prefix; new_plugin->color = &plugin_api_color; new_plugin->print_infobar = &plugin_api_print_infobar; diff --git a/src/plugins/weechat-plugin.h b/src/plugins/weechat-plugin.h index 924891335..802380bd7 100644 --- a/src/plugins/weechat-plugin.h +++ b/src/plugins/weechat-plugin.h @@ -74,6 +74,8 @@ struct t_weechat_plugin /* display */ void (*printf) (struct t_weechat_plugin *, void *, char *, ...); + void (*printf_date) (struct t_weechat_plugin *, void *, time_t, + char *, ...); char *(*prefix) (struct t_weechat_plugin *, char *); char *(*color) (struct t_weechat_plugin *, char *); void (*print_infobar) (struct t_weechat_plugin *, int, char *, ...); @@ -158,6 +160,9 @@ struct t_weechat_plugin #define weechat_printf(buffer, argz...) \ weechat_plugin->printf(weechat_plugin, buffer, ##argz) +#define weechat_printf_date(buffer, datetime, argz...) \ + weechat_plugin->printf_date(weechat_plugin, buffer, datetime, \ + ##argz) #define weechat_prefix(prefix_name) \ weechat_plugin->prefix(weechat_plugin, prefix_name) #define weechat_color(color_name) \ |