summaryrefslogtreecommitdiff
path: root/src/plugins/demo
diff options
context:
space:
mode:
authorSebastien Helleu <flashcode@flashtux.org>2008-08-30 00:25:56 +0200
committerSebastien Helleu <flashcode@flashtux.org>2008-08-30 00:25:56 +0200
commit0839b359f9ad6fd88ef94e6ca4eac54c53156c68 (patch)
tree4580ffa94b96c331e9fb6c90a92281ef19eddc9f /src/plugins/demo
parenteb57354984dd1394f8b50911cee58180bbff2e88 (diff)
downloadweechat-0839b359f9ad6fd88ef94e6ca4eac54c53156c68.zip
Add new hooks (info and infolist), IRC plugin now return infos and infolists
Diffstat (limited to 'src/plugins/demo')
-rw-r--r--src/plugins/demo/demo.c120
1 files changed, 65 insertions, 55 deletions
diff --git a/src/plugins/demo/demo.c b/src/plugins/demo/demo.c
index 7f61244ed..334797816 100644
--- a/src/plugins/demo/demo.c
+++ b/src/plugins/demo/demo.c
@@ -210,6 +210,9 @@ demo_infolist_print (struct t_infolist *infolist, const char *item_name)
int i, j, argc, size;
time_t time;
+ if (!infolist)
+ return;
+
i = 1;
while (weechat_infolist_next (infolist))
{
@@ -268,76 +271,84 @@ demo_infolist_print (struct t_infolist *infolist, const char *item_name)
}
/*
- * demo_infolist_command_cb: demo command for list
+ * demo_info_command_cb: demo command for info_get
*/
int
-demo_infolist_command_cb (void *data, struct t_gui_buffer *buffer, int argc,
- char **argv, char **argv_eol)
+demo_info_command_cb (void *data, struct t_gui_buffer *buffer, int argc,
+ char **argv, char **argv_eol)
{
struct t_infolist *infolist;
/* make C compiler happy */
(void) data;
(void) buffer;
- (void) argv_eol;
if (argc > 1)
+ weechat_printf (NULL, "info \"%s\" = \"%s\"",
+ argv[1],
+ weechat_info_get (argv[1],
+ (argc > 2) ? argv_eol[2] : NULL));
+ else
{
- if (weechat_strcasecmp (argv[1], "buffer") == 0)
- {
- infolist = weechat_infolist_get ("buffer", NULL, NULL);
- if (infolist)
- {
- demo_infolist_print (infolist, "buffer");
- weechat_infolist_free (infolist);
- }
- return WEECHAT_RC_OK;
- }
- if (weechat_strcasecmp (argv[1], "buffer_lines") == 0)
+ infolist = weechat_infolist_get ("hook", NULL, "info");
+ if (infolist)
{
- infolist = weechat_infolist_get ("buffer_lines", NULL, NULL);
- if (infolist)
+ weechat_printf (NULL, "");
+ weechat_printf (NULL, _("Available infos:"));
+ while (weechat_infolist_next (infolist))
{
- demo_infolist_print (infolist, "buffer_line");
- weechat_infolist_free (infolist);
+ weechat_printf (NULL,
+ " %s",
+ weechat_infolist_string (infolist, "info_name"));
}
- return WEECHAT_RC_OK;
+ weechat_infolist_free (infolist);
}
}
- weechat_printf (NULL,
- _("%s%s: missing argument for \"%s\" command "
- "(try /help %s)"),
- weechat_prefix ("error"), "demo",
- "demo_infolist", "demo_infolist");
-
return WEECHAT_RC_OK;
}
/*
- * demo_info_command_cb: demo command for info_get
+ * demo_infolist_command_cb: demo command for list
*/
int
-demo_info_command_cb (void *data, struct t_gui_buffer *buffer, int argc,
- char **argv, char **argv_eol)
+demo_infolist_command_cb (void *data, struct t_gui_buffer *buffer, int argc,
+ char **argv, char **argv_eol)
{
+ struct t_infolist *infolist;
+
/* make C compiler happy */
(void) data;
(void) buffer;
- (void) argv_eol;
if (argc > 1)
- weechat_printf (NULL, "info \"%s\" = \"%s\"",
- argv[1],
- weechat_info_get (argv[1]));
+ {
+ infolist = weechat_infolist_get (argv[1], NULL,
+ (argc > 2) ? argv_eol[2] : NULL);
+ if (infolist)
+ {
+ demo_infolist_print (infolist, argv[1]);
+ weechat_infolist_free (infolist);
+ }
+ }
else
- weechat_printf (NULL,
- _("%s%s: missing argument for \"%s\" command "
- "(try /help %s)"),
- weechat_prefix ("error"), "demo",
- "demo_info", "demo_info");
+ {
+ infolist = weechat_infolist_get ("hook", NULL, "infolist");
+ if (infolist)
+ {
+ weechat_printf (NULL, "");
+ weechat_printf (NULL, _("Available infolists:"));
+ while (weechat_infolist_next (infolist))
+ {
+ weechat_printf (NULL,
+ " %s",
+ weechat_infolist_string (infolist, "infolist_name"));
+ }
+ weechat_infolist_free (infolist);
+ }
+ }
return WEECHAT_RC_OK;
}
@@ -416,7 +427,7 @@ weechat_plugin_init (struct t_weechat_plugin *plugin, int argc, char *argv[])
"",
"",
&demo_buffer_command_cb, NULL);
-
+
weechat_hook_command ("demo_buffer_set",
N_("set a buffer property"),
N_("property value"),
@@ -424,26 +435,25 @@ weechat_plugin_init (struct t_weechat_plugin *plugin, int argc, char *argv[])
"",
&demo_buffer_set_command_cb, NULL);
- weechat_hook_command ("demo_infolist",
- N_("get and display an infolist"),
- N_("infolist"),
- N_("infolist: infolist to display (values: buffer, "
- "buffer_lines)"),
- "buffer|buffer_lines",
- &demo_infolist_command_cb, NULL);
-
weechat_hook_command ("demo_info",
N_("get and display an info"),
- N_("info"),
- N_("info: info to display (values: version, "
- "weechat_dir, weechat_libdir, weechat_sharedir, "
- "charset_terminal, charset_internal, inactivity, "
- "input, input_mask, input_pos)"),
- "version|weechat_dir|weechat_libdir|"
- "weechat_sharedir|charset_terminal|charset_internal|"
- "inactivity|input|input_mask|input_pos",
+ N_("[info [arguments]]"),
+ N_(" info: info to display\n"
+ "arguments: optional arguments for info\n\n"
+ "Without argument, this command displays list "
+ "of available infos"),
+ "%i",
&demo_info_command_cb, NULL);
+ weechat_hook_command ("demo_infolist",
+ N_("get and display an infolist"),
+ N_("[infolist]"),
+ N_("infolist: infolist to display\n\n"
+ "Without argument, this command displays list "
+ "of available infolists"),
+ "%i",
+ &demo_infolist_command_cb, NULL);
+
weechat_hook_signal ("debug", &demo_debug_signal_debug_cb, NULL);
weechat_hook_signal ("*", &demo_signal_cb, NULL);