1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
|
/*
* Copyright (c) 2003-2007 by FlashCode <flashcode@flashtux.org>
* See README for License detail, AUTHORS for developers list.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/* demo.c: demo plugin for WeeChat */
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <time.h>
#include "../weechat-plugin.h"
#include "demo.h"
static struct t_weechat_plugin *weechat_plugin = NULL;
/*
* demo_print_list: display a list
*/
static void
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))
{
weechat_printf (NULL, "--- %s #%d ---", item_name, i);
fields = weechat_list_fields (list);
if (fields)
{
argv = weechat_string_explode (fields, ",", 0, 0, &argc);
if (argv && (argc > 0))
{
for (j = 0; j < argc; j++)
{
switch (argv[j][0])
{
case 'i':
weechat_printf (NULL, " %s: %d",
argv[j] + 2,
weechat_list_int (list,
argv[j] + 2));
break;
case 's':
weechat_printf (NULL, " %s: %s",
argv[j] + 2,
weechat_list_string (list,
argv[j] + 2));
break;
case 'p':
weechat_printf (NULL, " %s: %X",
argv[j] + 2,
weechat_list_pointer (list,
argv[j] + 2));
break;
case 't':
date = weechat_list_time (list, argv[j] + 2);
weechat_printf (NULL, " %s: (%ld) %s",
argv[j] + 2,
date, ctime (&date));
break;
}
}
}
if (argv)
weechat_string_free_exploded (argv);
}
i++;
}
}
/*
* demo_buffer_infos: display buffer infos
*/
static void
demo_buffer_infos ()
{
struct t_plugin_list *list;
list = weechat_list_get ("buffer", NULL);
if (list)
{
demo_print_list (list, "buffer");
weechat_list_free (list);
}
}
/*
* 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
*/
static int
demo_command (void *data, int argc, char **argv, char **argv_eol)
{
/* make C compiler happy */
(void) data;
(void) argv_eol;
if (argc > 1)
{
if (weechat_strcasecmp (argv[1], "buffer") == 0)
{
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,
"Demo: missing argument for /demo command "
"(try /help demo)");
return PLUGIN_RC_SUCCESS;
}
/*
* weechat_plugin_init: init demo plugin
*/
int
weechat_plugin_init (struct t_weechat_plugin *plugin)
{
weechat_plugin = plugin;
weechat_hook_command ("demo", "demo command", "[action]",
"action: one of following actions:\n"
" buffer display infos about buffers",
"buffer|buffer_lines", demo_command, NULL);
weechat_buffer_new ("categ", "nam");
return PLUGIN_RC_SUCCESS;
}
/*
* weechat_plugin_end: end demo plugin
*/
int
weechat_plugin_end ()
{
return PLUGIN_RC_SUCCESS;
}
|