summaryrefslogtreecommitdiff
path: root/src/plugins/plugin-api.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/plugin-api.c')
-rw-r--r--src/plugins/plugin-api.c100
1 files changed, 60 insertions, 40 deletions
diff --git a/src/plugins/plugin-api.c b/src/plugins/plugin-api.c
index 1b26bea60..610855f7e 100644
--- a/src/plugins/plugin-api.c
+++ b/src/plugins/plugin-api.c
@@ -253,6 +253,53 @@ plugin_api_exec_on_files (struct t_weechat_plugin *plugin, char *directory,
}
/*
+ * plugin_api_prefix: return a prefix for display with printf
+ */
+
+char *
+plugin_api_prefix (struct t_weechat_plugin *plugin, char *prefix)
+{
+ static char empty_prefix[] = "";
+
+ if (!plugin || !prefix)
+ return empty_prefix;
+
+ if (string_strcasecmp (prefix, "info") == 0)
+ return gui_chat_prefix[GUI_CHAT_PREFIX_INFO];
+ if (string_strcasecmp (prefix, "error") == 0)
+ return gui_chat_prefix[GUI_CHAT_PREFIX_ERROR];
+ if (string_strcasecmp (prefix, "network") == 0)
+ return gui_chat_prefix[GUI_CHAT_PREFIX_NETWORK];
+ if (string_strcasecmp (prefix, "action") == 0)
+ return gui_chat_prefix[GUI_CHAT_PREFIX_ACTION];
+ if (string_strcasecmp (prefix, "join") == 0)
+ return gui_chat_prefix[GUI_CHAT_PREFIX_JOIN];
+ if (string_strcasecmp (prefix, "quit") == 0)
+ return gui_chat_prefix[GUI_CHAT_PREFIX_QUIT];
+
+ return empty_prefix;
+}
+
+/*
+ * plugin_api_color: return a WeeChat color for display with printf
+ */
+
+char *
+plugin_api_color (struct t_weechat_plugin *plugin, char *color_name)
+{
+ int num_color;
+
+ if (!plugin || !color_name)
+ return GUI_NO_COLOR;
+
+ num_color = gui_color_search_config (color_name);
+ if (num_color >= 0)
+ return GUI_COLOR(num_color);
+
+ return GUI_NO_COLOR;
+}
+
+/*
* plugin_api_printf: print a message on a buffer
*/
@@ -271,7 +318,7 @@ plugin_api_printf (struct t_weechat_plugin *plugin,
vsnprintf (buf, sizeof (buf) - 1, format, argptr);
va_end (argptr);
- gui_chat_printf ((struct t_gui_buffer *)buffer, buf);
+ gui_chat_printf ((struct t_gui_buffer *)buffer, "%s", buf);
}
/*
@@ -297,50 +344,23 @@ plugin_api_printf_date (struct t_weechat_plugin *plugin,
}
/*
- * plugin_api_prefix: return a prefix for display with printf
+ * plugin_api_log_printf: print a message in WeeChat log file
*/
-char *
-plugin_api_prefix (struct t_weechat_plugin *plugin, char *prefix)
+void
+plugin_api_log_printf (struct t_weechat_plugin *plugin, char *format, ...)
{
- static char empty_prefix[] = "";
-
- if (!plugin || !prefix)
- return empty_prefix;
-
- if (string_strcasecmp (prefix, "info") == 0)
- return gui_chat_prefix[GUI_CHAT_PREFIX_INFO];
- if (string_strcasecmp (prefix, "error") == 0)
- return gui_chat_prefix[GUI_CHAT_PREFIX_ERROR];
- if (string_strcasecmp (prefix, "network") == 0)
- return gui_chat_prefix[GUI_CHAT_PREFIX_NETWORK];
- if (string_strcasecmp (prefix, "action") == 0)
- return gui_chat_prefix[GUI_CHAT_PREFIX_ACTION];
- if (string_strcasecmp (prefix, "join") == 0)
- return gui_chat_prefix[GUI_CHAT_PREFIX_JOIN];
- if (string_strcasecmp (prefix, "quit") == 0)
- return gui_chat_prefix[GUI_CHAT_PREFIX_QUIT];
+ va_list argptr;
+ char buf[8192];
- return empty_prefix;
-}
-
-/*
- * plugin_api_color: return a WeeChat color for display with printf
- */
-
-char *
-plugin_api_color (struct t_weechat_plugin *plugin, char *color_name)
-{
- int num_color;
+ if (!plugin || !format)
+ return;
- if (!plugin || !color_name)
- return GUI_NO_COLOR;
-
- num_color = gui_color_search_config (color_name);
- if (num_color >= 0)
- return GUI_COLOR(num_color);
+ va_start (argptr, format);
+ vsnprintf (buf, sizeof (buf) - 1, format, argptr);
+ va_end (argptr);
- return GUI_NO_COLOR;
+ log_printf ("%s", buf);
}
/*
@@ -404,7 +424,7 @@ struct t_hook *
plugin_api_hook_command (struct t_weechat_plugin *plugin, char *command,
char *description, char *args,
char *args_desc, char *completion,
- int (*callback)(void *, int, char **, char **),
+ int (*callback)(void *, void *, int, char **, char **),
void *data)
{
if (plugin && callback)