1 | /* -*- mode: c; indent-tabs-mode: t; c-basic-offset: 8 -*- */ |
---|
2 | static const char fileIdent[] = "$Id$"; |
---|
3 | |
---|
4 | #ifdef HAVE_LIBZEPHYR |
---|
5 | #include <zephyr/zephyr.h> |
---|
6 | #endif |
---|
7 | #include <EXTERN.h> |
---|
8 | |
---|
9 | #define OWL_PERL |
---|
10 | #include "owl.h" |
---|
11 | SV *owl_perlconfig_curmessage2hashref(void); |
---|
12 | |
---|
13 | #define SV_IS_CODEREF(sv) (SvROK((sv)) && SvTYPE(SvRV((sv))) == SVt_PVCV) |
---|
14 | |
---|
15 | MODULE = BarnOwl PACKAGE = BarnOwl |
---|
16 | |
---|
17 | char * |
---|
18 | command(cmd) |
---|
19 | char *cmd |
---|
20 | PREINIT: |
---|
21 | char *rv = NULL; |
---|
22 | CODE: |
---|
23 | rv = owl_function_command(cmd); |
---|
24 | RETVAL = rv; |
---|
25 | OUTPUT: |
---|
26 | RETVAL |
---|
27 | CLEANUP: |
---|
28 | if (rv) owl_free(rv); |
---|
29 | |
---|
30 | SV * |
---|
31 | getcurmsg() |
---|
32 | CODE: |
---|
33 | ST(0) = owl_perlconfig_curmessage2hashref(); |
---|
34 | |
---|
35 | int |
---|
36 | getnumcols() |
---|
37 | CODE: |
---|
38 | RETVAL = owl_global_get_cols(&g); |
---|
39 | OUTPUT: |
---|
40 | RETVAL |
---|
41 | |
---|
42 | time_t |
---|
43 | getidletime() |
---|
44 | CODE: |
---|
45 | RETVAL = owl_global_get_idletime(&g); |
---|
46 | OUTPUT: |
---|
47 | RETVAL |
---|
48 | |
---|
49 | char * |
---|
50 | zephyr_getrealm() |
---|
51 | CODE: |
---|
52 | RETVAL = owl_zephyr_get_realm(); |
---|
53 | OUTPUT: |
---|
54 | RETVAL |
---|
55 | |
---|
56 | char * |
---|
57 | zephyr_getsender() |
---|
58 | CODE: |
---|
59 | RETVAL = owl_zephyr_get_sender(); |
---|
60 | OUTPUT: |
---|
61 | RETVAL |
---|
62 | |
---|
63 | void |
---|
64 | zephyr_zwrite(cmd,msg) |
---|
65 | char *cmd |
---|
66 | char *msg |
---|
67 | PREINIT: |
---|
68 | int i; |
---|
69 | CODE: |
---|
70 | i = owl_zwrite_create_and_send_from_line(cmd, msg); |
---|
71 | |
---|
72 | char * |
---|
73 | ztext_stylestrip(ztext) |
---|
74 | char *ztext |
---|
75 | PREINIT: |
---|
76 | char *rv = NULL; |
---|
77 | CODE: |
---|
78 | rv = owl_function_ztext_stylestrip(ztext); |
---|
79 | RETVAL = rv; |
---|
80 | OUTPUT: |
---|
81 | RETVAL |
---|
82 | CLEANUP: |
---|
83 | if (rv) owl_free(rv); |
---|
84 | |
---|
85 | void |
---|
86 | new_command_internal(name, func, summary, usage, description) |
---|
87 | char *name |
---|
88 | SV *func |
---|
89 | char *summary |
---|
90 | char *usage |
---|
91 | char *description |
---|
92 | PREINIT: |
---|
93 | owl_cmd cmd; |
---|
94 | CODE: |
---|
95 | { |
---|
96 | if(!SV_IS_CODEREF(func)) { |
---|
97 | croak("Command function must be a coderef!"); |
---|
98 | } |
---|
99 | SvREFCNT_inc(func); |
---|
100 | cmd.name = name; |
---|
101 | cmd.cmd_perl = func; |
---|
102 | cmd.summary = summary; |
---|
103 | cmd.usage = usage; |
---|
104 | cmd.description = description; |
---|
105 | cmd.validctx = OWL_CTX_ANY; |
---|
106 | cmd.cmd_aliased_to = NULL; |
---|
107 | cmd.cmd_args_fn = NULL; |
---|
108 | cmd.cmd_v_fn = NULL; |
---|
109 | cmd.cmd_i_fn = NULL; |
---|
110 | cmd.cmd_ctxargs_fn = NULL; |
---|
111 | cmd.cmd_ctxv_fn = NULL; |
---|
112 | cmd.cmd_ctxi_fn = NULL; |
---|
113 | owl_cmddict_add_cmd(owl_global_get_cmddict(&g), &cmd); |
---|
114 | } |
---|
115 | |
---|
116 | void queue_message(msg) |
---|
117 | SV *msg |
---|
118 | PREINIT: |
---|
119 | owl_message *m; |
---|
120 | CODE: |
---|
121 | { |
---|
122 | if(!SvROK(msg) || SvTYPE(SvRV(msg)) != SVt_PVHV) { |
---|
123 | croak("Usage: BarnOwl::queue_message($message)"); |
---|
124 | } |
---|
125 | |
---|
126 | m = owl_perlconfig_hashref2message(msg); |
---|
127 | |
---|
128 | owl_global_messagequeue_addmsg(&g, m); |
---|
129 | } |
---|
130 | |
---|
131 | void admin_message(header, body) |
---|
132 | char *header |
---|
133 | char *body |
---|
134 | CODE: |
---|
135 | { |
---|
136 | owl_function_adminmsg(header, body); |
---|
137 | } |
---|
138 | |
---|
139 | void start_question(line, callback) |
---|
140 | char *line |
---|
141 | SV *callback |
---|
142 | PREINIT: |
---|
143 | CODE: |
---|
144 | { |
---|
145 | if(!SV_IS_CODEREF(callback)) |
---|
146 | croak("Callback must be a subref"); |
---|
147 | |
---|
148 | owl_function_start_question(line); |
---|
149 | |
---|
150 | SvREFCNT_inc(callback); |
---|
151 | owl_editwin_set_cbdata(owl_global_get_typwin(&g), callback); |
---|
152 | owl_editwin_set_callback(owl_global_get_typwin(&g), owl_perlconfig_edit_callback); |
---|
153 | } |
---|
154 | |
---|
155 | void start_password(line, callback) |
---|
156 | char *line |
---|
157 | SV *callback |
---|
158 | PREINIT: |
---|
159 | CODE: |
---|
160 | { |
---|
161 | if(!SV_IS_CODEREF(callback)) |
---|
162 | croak("Callback must be a subref"); |
---|
163 | |
---|
164 | owl_function_start_password(line); |
---|
165 | |
---|
166 | SvREFCNT_inc(callback); |
---|
167 | owl_editwin_set_cbdata(owl_global_get_typwin(&g), callback); |
---|
168 | owl_editwin_set_callback(owl_global_get_typwin(&g), owl_perlconfig_edit_callback); |
---|
169 | } |
---|
170 | |
---|
171 | void start_edit_win(line, callback) |
---|
172 | char *line |
---|
173 | SV *callback |
---|
174 | PREINIT: |
---|
175 | owl_editwin * e; |
---|
176 | char buff[1024]; |
---|
177 | CODE: |
---|
178 | { |
---|
179 | if(!SV_IS_CODEREF(callback)) |
---|
180 | croak("Callback must be a subref"); |
---|
181 | |
---|
182 | e = owl_global_get_typwin(&g); |
---|
183 | owl_editwin_new_style(e, OWL_EDITWIN_STYLE_MULTILINE, |
---|
184 | owl_global_get_msg_history(&g)); |
---|
185 | owl_editwin_clear(e); |
---|
186 | owl_editwin_set_dotsend(e); |
---|
187 | snprintf(buff, 1023, "----> %s\n", line); |
---|
188 | owl_editwin_set_locktext(e, buff); |
---|
189 | |
---|
190 | owl_global_set_typwin_active(&g); |
---|
191 | |
---|
192 | SvREFCNT_inc(callback); |
---|
193 | owl_editwin_set_cbdata(owl_global_get_typwin(&g), callback); |
---|
194 | owl_editwin_set_callback(owl_global_get_typwin(&g), owl_perlconfig_edit_callback); |
---|
195 | } |
---|
196 | |
---|
197 | |
---|
198 | char * |
---|
199 | get_data_dir () |
---|
200 | CODE: |
---|
201 | RETVAL = (char *) owl_get_datadir(); |
---|
202 | OUTPUT: |
---|
203 | RETVAL |
---|
204 | |
---|
205 | char * |
---|
206 | get_config_dir () |
---|
207 | CODE: |
---|
208 | RETVAL = (char *) owl_global_get_confdir(&g); |
---|
209 | OUTPUT: |
---|
210 | RETVAL |
---|
211 | |
---|
212 | void |
---|
213 | popless_text(text) |
---|
214 | char *text |
---|
215 | CODE: |
---|
216 | { |
---|
217 | owl_function_popless_text(text); |
---|
218 | } |
---|
219 | |
---|
220 | void |
---|
221 | popless_ztext(text) |
---|
222 | char *text |
---|
223 | CODE: |
---|
224 | { |
---|
225 | owl_fmtext fm; |
---|
226 | owl_fmtext_init_null(&fm); |
---|
227 | owl_fmtext_append_ztext(&fm, text); |
---|
228 | owl_function_popless_fmtext(&fm); |
---|
229 | owl_fmtext_free(&fm); |
---|
230 | } |
---|
231 | |
---|
232 | void |
---|
233 | error(text) |
---|
234 | char *text |
---|
235 | CODE: |
---|
236 | { |
---|
237 | owl_function_error("%s", text); |
---|
238 | } |
---|
239 | |
---|
240 | void |
---|
241 | _create_style(name, function, description) |
---|
242 | char *name |
---|
243 | char *function |
---|
244 | char *description |
---|
245 | PREINIT: |
---|
246 | /* This is to allow us to bootstrap the default style before the |
---|
247 | command architecture has been initialized */ |
---|
248 | owl_style *s; |
---|
249 | CODE: |
---|
250 | { |
---|
251 | s = owl_malloc(sizeof(owl_style)); |
---|
252 | owl_style_create_perl(s, name, function, description); |
---|
253 | owl_global_add_style(&g, s); |
---|
254 | } |
---|
255 | |
---|
256 | int |
---|
257 | getnumcolors() |
---|
258 | CODE: |
---|
259 | RETVAL = owl_function_get_color_count(); |
---|
260 | OUTPUT: |
---|
261 | RETVAL |
---|
262 | |
---|
263 | void |
---|
264 | _remove_filter(filterName) |
---|
265 | char *filterName |
---|
266 | CODE: |
---|
267 | { |
---|
268 | /* Don't delete the current view, or the 'all' filter */ |
---|
269 | if (strcmp(filterName, owl_view_get_filtname(owl_global_get_current_view(&g))) |
---|
270 | && strcmp(filterName, "all")) { |
---|
271 | owl_global_remove_filter(&g,filterName); |
---|
272 | } |
---|
273 | } |
---|
274 | |
---|
275 | char * |
---|
276 | wordwrap(in, cols) |
---|
277 | char *in |
---|
278 | int cols |
---|
279 | PREINIT: |
---|
280 | char *rv = NULL; |
---|
281 | CODE: |
---|
282 | rv = owl_text_wordwrap(in, cols); |
---|
283 | RETVAL = rv; |
---|
284 | OUTPUT: |
---|
285 | RETVAL |
---|
286 | CLEANUP: |
---|
287 | if (rv) owl_free(rv); |
---|
288 | |
---|
289 | void |
---|
290 | new_variable_string_internal(name, ival, summ, desc) |
---|
291 | char * name |
---|
292 | char * ival |
---|
293 | char * summ |
---|
294 | char * desc |
---|
295 | CODE: |
---|
296 | owl_variable_dict_newvar_string(owl_global_get_vardict(&g), |
---|
297 | name, |
---|
298 | summ, |
---|
299 | desc, |
---|
300 | ival); |
---|
301 | |
---|
302 | void |
---|
303 | new_variable_int_internal(name, ival, summ, desc) |
---|
304 | char * name |
---|
305 | int ival |
---|
306 | char * summ |
---|
307 | char * desc |
---|
308 | CODE: |
---|
309 | owl_variable_dict_newvar_int(owl_global_get_vardict(&g), |
---|
310 | name, |
---|
311 | summ, |
---|
312 | desc, |
---|
313 | ival); |
---|
314 | |
---|
315 | void |
---|
316 | new_variable_bool_internal(name, ival, summ, desc) |
---|
317 | char * name |
---|
318 | int ival |
---|
319 | char * summ |
---|
320 | char * desc |
---|
321 | CODE: |
---|
322 | owl_variable_dict_newvar_bool(owl_global_get_vardict(&g), |
---|
323 | name, |
---|
324 | summ, |
---|
325 | desc, |
---|
326 | ival); |
---|
327 | |
---|
328 | void |
---|
329 | beep() |
---|
330 | CODE: |
---|
331 | owl_function_beep(); |
---|