1 | /* -*- mode: c; indent-tabs-mode: t; c-basic-offset: 8 -*- */ |
---|
2 | #define OWL_PERL |
---|
3 | #include "owl.h" |
---|
4 | |
---|
5 | #define SV_IS_CODEREF(sv) (SvROK((sv)) && SvTYPE(SvRV((sv))) == SVt_PVCV) |
---|
6 | |
---|
7 | typedef char utf8; |
---|
8 | |
---|
9 | /************************************************************* |
---|
10 | * NOTE |
---|
11 | ************************************************************* |
---|
12 | * These functions, when they are intended to be user-visible, |
---|
13 | * are documented in perl/lib/BarnOwl.pm. If you add functions |
---|
14 | * to this file, add the appropriate documentation there! |
---|
15 | * |
---|
16 | * If the function is simple enough, we simply define its |
---|
17 | * entire functionality here in XS. If, however, it needs |
---|
18 | * complex argument processing or something, we define a |
---|
19 | * simple version here that takes arguments in as flat a |
---|
20 | * manner as possible, to simplify the XS code, put it in |
---|
21 | * BarnOwl::Internal::, and write a perl wrapper in BarnOwl.pm |
---|
22 | * that munges the arguments as appropriate and calls the |
---|
23 | * internal version. |
---|
24 | */ |
---|
25 | |
---|
26 | MODULE = BarnOwl PACKAGE = BarnOwl |
---|
27 | |
---|
28 | const utf8 * |
---|
29 | command(cmd, ...) |
---|
30 | const char *cmd |
---|
31 | PREINIT: |
---|
32 | char *rv = NULL; |
---|
33 | const char **argv; |
---|
34 | int i; |
---|
35 | CODE: |
---|
36 | { |
---|
37 | if (items == 1) { |
---|
38 | rv = owl_function_command(cmd); |
---|
39 | } else { |
---|
40 | /* Ensure this is NULL-terminated. */ |
---|
41 | argv = g_new0(const char *, items + 1); |
---|
42 | argv[0] = cmd; |
---|
43 | for(i = 1; i < items; i++) { |
---|
44 | argv[i] = SvPV_nolen(ST(i)); |
---|
45 | } |
---|
46 | rv = owl_function_command_argv(argv, items); |
---|
47 | g_free(argv); |
---|
48 | } |
---|
49 | RETVAL = rv; |
---|
50 | } |
---|
51 | OUTPUT: |
---|
52 | RETVAL |
---|
53 | CLEANUP: |
---|
54 | g_free(rv); |
---|
55 | |
---|
56 | SV * |
---|
57 | getcurmsg() |
---|
58 | CODE: |
---|
59 | RETVAL = owl_perlconfig_curmessage2hashref(); |
---|
60 | OUTPUT: |
---|
61 | RETVAL |
---|
62 | |
---|
63 | int |
---|
64 | getnumcols() |
---|
65 | CODE: |
---|
66 | RETVAL = owl_global_get_cols(&g); |
---|
67 | OUTPUT: |
---|
68 | RETVAL |
---|
69 | |
---|
70 | time_t |
---|
71 | getidletime() |
---|
72 | CODE: |
---|
73 | RETVAL = owl_global_get_idletime(&g); |
---|
74 | OUTPUT: |
---|
75 | RETVAL |
---|
76 | |
---|
77 | const utf8 * |
---|
78 | zephyr_getrealm() |
---|
79 | CODE: |
---|
80 | RETVAL = owl_zephyr_get_realm(); |
---|
81 | OUTPUT: |
---|
82 | RETVAL |
---|
83 | |
---|
84 | const utf8 * |
---|
85 | zephyr_getsender() |
---|
86 | CODE: |
---|
87 | RETVAL = owl_zephyr_get_sender(); |
---|
88 | OUTPUT: |
---|
89 | RETVAL |
---|
90 | |
---|
91 | void |
---|
92 | zephyr_zwrite(cmd,msg) |
---|
93 | const char *cmd |
---|
94 | const char *msg |
---|
95 | PREINIT: |
---|
96 | int i; |
---|
97 | CODE: |
---|
98 | i = owl_zwrite_create_and_send_from_line(cmd, msg); |
---|
99 | |
---|
100 | const utf8 * |
---|
101 | ztext_stylestrip(ztext) |
---|
102 | const char *ztext |
---|
103 | PREINIT: |
---|
104 | char *rv = NULL; |
---|
105 | CODE: |
---|
106 | rv = owl_function_ztext_stylestrip(ztext); |
---|
107 | RETVAL = rv; |
---|
108 | OUTPUT: |
---|
109 | RETVAL |
---|
110 | CLEANUP: |
---|
111 | g_free(rv); |
---|
112 | |
---|
113 | const utf8 * |
---|
114 | zephyr_smartstrip_user(in) |
---|
115 | const char *in |
---|
116 | PREINIT: |
---|
117 | char *rv = NULL; |
---|
118 | CODE: |
---|
119 | { |
---|
120 | rv = owl_zephyr_smartstripped_user(in); |
---|
121 | RETVAL = rv; |
---|
122 | } |
---|
123 | OUTPUT: |
---|
124 | RETVAL |
---|
125 | CLEANUP: |
---|
126 | g_free(rv); |
---|
127 | |
---|
128 | const utf8 * |
---|
129 | zephyr_getsubs() |
---|
130 | PREINIT: |
---|
131 | char *rv = NULL; |
---|
132 | CODE: |
---|
133 | rv = owl_zephyr_getsubs(); |
---|
134 | RETVAL = rv; |
---|
135 | OUTPUT: |
---|
136 | RETVAL |
---|
137 | CLEANUP: |
---|
138 | g_free(rv); |
---|
139 | |
---|
140 | SV * |
---|
141 | queue_message(msg) |
---|
142 | SV *msg |
---|
143 | PREINIT: |
---|
144 | owl_message *m; |
---|
145 | CODE: |
---|
146 | { |
---|
147 | if(!SvROK(msg) || SvTYPE(SvRV(msg)) != SVt_PVHV) { |
---|
148 | croak("Usage: BarnOwl::queue_message($message)"); |
---|
149 | } |
---|
150 | |
---|
151 | m = owl_perlconfig_hashref2message(msg); |
---|
152 | |
---|
153 | owl_global_messagequeue_addmsg(&g, m); |
---|
154 | |
---|
155 | RETVAL = owl_perlconfig_message2hashref(m); |
---|
156 | } |
---|
157 | OUTPUT: |
---|
158 | RETVAL |
---|
159 | |
---|
160 | void |
---|
161 | admin_message(header, body) |
---|
162 | const char *header |
---|
163 | const char *body |
---|
164 | CODE: |
---|
165 | { |
---|
166 | owl_function_adminmsg(header, body); |
---|
167 | } |
---|
168 | |
---|
169 | void |
---|
170 | start_question(line, callback) |
---|
171 | const char *line |
---|
172 | SV *callback |
---|
173 | PREINIT: |
---|
174 | owl_editwin *e; |
---|
175 | CODE: |
---|
176 | { |
---|
177 | if(!SV_IS_CODEREF(callback)) |
---|
178 | croak("Callback must be a subref"); |
---|
179 | |
---|
180 | e = owl_function_start_question(line); |
---|
181 | |
---|
182 | owl_editwin_set_cbdata(e, |
---|
183 | newSVsv(callback), |
---|
184 | owl_perlconfig_dec_refcnt); |
---|
185 | owl_editwin_set_callback(e, owl_perlconfig_edit_callback); |
---|
186 | } |
---|
187 | |
---|
188 | void |
---|
189 | start_password(line, callback) |
---|
190 | const char *line |
---|
191 | SV *callback |
---|
192 | PREINIT: |
---|
193 | owl_editwin *e; |
---|
194 | CODE: |
---|
195 | { |
---|
196 | if(!SV_IS_CODEREF(callback)) |
---|
197 | croak("Callback must be a subref"); |
---|
198 | |
---|
199 | e = owl_function_start_password(line); |
---|
200 | |
---|
201 | owl_editwin_set_cbdata(e, |
---|
202 | newSVsv(callback), |
---|
203 | owl_perlconfig_dec_refcnt); |
---|
204 | owl_editwin_set_callback(e, owl_perlconfig_edit_callback); |
---|
205 | } |
---|
206 | |
---|
207 | void |
---|
208 | start_edit_win(line, callback) |
---|
209 | const char *line |
---|
210 | SV *callback |
---|
211 | PREINIT: |
---|
212 | owl_editwin *e; |
---|
213 | CODE: |
---|
214 | { |
---|
215 | if(!SV_IS_CODEREF(callback)) |
---|
216 | croak("Callback must be a subref"); |
---|
217 | |
---|
218 | e = owl_function_start_edit_win(line); |
---|
219 | owl_editwin_set_cbdata(e, |
---|
220 | newSVsv(callback), |
---|
221 | owl_perlconfig_dec_refcnt); |
---|
222 | owl_editwin_set_callback(e, &owl_perlconfig_edit_callback); |
---|
223 | } |
---|
224 | |
---|
225 | |
---|
226 | const char * |
---|
227 | get_data_dir () |
---|
228 | CODE: |
---|
229 | RETVAL = owl_get_datadir(); |
---|
230 | OUTPUT: |
---|
231 | RETVAL |
---|
232 | |
---|
233 | const char * |
---|
234 | get_config_dir () |
---|
235 | CODE: |
---|
236 | RETVAL = owl_global_get_confdir(&g); |
---|
237 | OUTPUT: |
---|
238 | RETVAL |
---|
239 | |
---|
240 | void |
---|
241 | popless_text(text) |
---|
242 | const char *text |
---|
243 | CODE: |
---|
244 | { |
---|
245 | owl_function_popless_text(text); |
---|
246 | } |
---|
247 | |
---|
248 | void |
---|
249 | popless_ztext(text) |
---|
250 | const char *text |
---|
251 | CODE: |
---|
252 | { |
---|
253 | owl_fmtext fm; |
---|
254 | owl_fmtext_init_null(&fm); |
---|
255 | owl_fmtext_append_ztext(&fm, text); |
---|
256 | owl_function_popless_fmtext(&fm); |
---|
257 | owl_fmtext_cleanup(&fm); |
---|
258 | } |
---|
259 | |
---|
260 | void |
---|
261 | error(text) |
---|
262 | const char *text |
---|
263 | CODE: |
---|
264 | { |
---|
265 | owl_function_error("%s", text); |
---|
266 | } |
---|
267 | |
---|
268 | void |
---|
269 | debug(text) |
---|
270 | const char *text |
---|
271 | CODE: |
---|
272 | { |
---|
273 | owl_function_debugmsg("%s", text); |
---|
274 | } |
---|
275 | |
---|
276 | void |
---|
277 | message(text) |
---|
278 | const char *text |
---|
279 | CODE: |
---|
280 | { |
---|
281 | owl_function_makemsg("%s", text); |
---|
282 | } |
---|
283 | |
---|
284 | void |
---|
285 | create_style(name, object) |
---|
286 | const char *name |
---|
287 | SV *object |
---|
288 | PREINIT: |
---|
289 | owl_style *s; |
---|
290 | CODE: |
---|
291 | { |
---|
292 | s = g_new(owl_style, 1); |
---|
293 | owl_style_create_perl(s, name, newSVsv(object)); |
---|
294 | owl_global_add_style(&g, s); |
---|
295 | } |
---|
296 | |
---|
297 | int |
---|
298 | getnumcolors() |
---|
299 | CODE: |
---|
300 | RETVAL = owl_function_get_color_count(); |
---|
301 | OUTPUT: |
---|
302 | RETVAL |
---|
303 | |
---|
304 | void |
---|
305 | _remove_filter(filterName) |
---|
306 | const char *filterName |
---|
307 | CODE: |
---|
308 | { |
---|
309 | /* Don't delete the current view, or the 'all' filter */ |
---|
310 | if (strcmp(filterName, owl_view_get_filtname(owl_global_get_current_view(&g))) |
---|
311 | && strcmp(filterName, "all")) { |
---|
312 | owl_global_remove_filter(&g,filterName); |
---|
313 | } |
---|
314 | } |
---|
315 | |
---|
316 | const utf8 * |
---|
317 | wordwrap(in, cols) |
---|
318 | const char *in |
---|
319 | int cols |
---|
320 | PREINIT: |
---|
321 | char *rv = NULL; |
---|
322 | CODE: |
---|
323 | rv = owl_text_wordwrap(in, cols); |
---|
324 | RETVAL = rv; |
---|
325 | OUTPUT: |
---|
326 | RETVAL |
---|
327 | CLEANUP: |
---|
328 | g_free(rv); |
---|
329 | |
---|
330 | AV* |
---|
331 | all_filters() |
---|
332 | PREINIT: |
---|
333 | GPtrArray *fl; |
---|
334 | CODE: |
---|
335 | { |
---|
336 | fl = owl_dict_get_keys(&g.filters); |
---|
337 | RETVAL = owl_new_av(fl, (SV*(*)(const void*))owl_new_sv); |
---|
338 | sv_2mortal((SV*)RETVAL); |
---|
339 | owl_ptr_array_free(fl, g_free); |
---|
340 | } |
---|
341 | OUTPUT: |
---|
342 | RETVAL |
---|
343 | |
---|
344 | AV* |
---|
345 | all_styles() |
---|
346 | PREINIT: |
---|
347 | GPtrArray *l; |
---|
348 | CODE: |
---|
349 | { |
---|
350 | l = owl_global_get_style_names(&g); |
---|
351 | RETVAL = owl_new_av(l, (SV*(*)(const void*))owl_new_sv); |
---|
352 | sv_2mortal((SV*)RETVAL); |
---|
353 | } |
---|
354 | OUTPUT: |
---|
355 | RETVAL |
---|
356 | CLEANUP: |
---|
357 | owl_ptr_array_free(l, g_free); |
---|
358 | |
---|
359 | |
---|
360 | AV* |
---|
361 | all_variables() |
---|
362 | PREINIT: |
---|
363 | GPtrArray *l; |
---|
364 | CODE: |
---|
365 | { |
---|
366 | l = owl_dict_get_keys(owl_global_get_vardict(&g)); |
---|
367 | RETVAL = owl_new_av(l, (SV*(*)(const void*))owl_new_sv); |
---|
368 | sv_2mortal((SV*)RETVAL); |
---|
369 | } |
---|
370 | OUTPUT: |
---|
371 | RETVAL |
---|
372 | CLEANUP: |
---|
373 | owl_ptr_array_free(l, g_free); |
---|
374 | |
---|
375 | |
---|
376 | AV* |
---|
377 | all_keymaps() |
---|
378 | PREINIT: |
---|
379 | GPtrArray *l; |
---|
380 | const owl_keyhandler *kh; |
---|
381 | CODE: |
---|
382 | { |
---|
383 | kh = owl_global_get_keyhandler(&g); |
---|
384 | l = owl_keyhandler_get_keymap_names(kh); |
---|
385 | RETVAL = owl_new_av(l, (SV*(*)(const void*))owl_new_sv); |
---|
386 | sv_2mortal((SV*)RETVAL); |
---|
387 | } |
---|
388 | OUTPUT: |
---|
389 | RETVAL |
---|
390 | CLEANUP: |
---|
391 | owl_ptr_array_free(l, g_free); |
---|
392 | |
---|
393 | void |
---|
394 | redisplay() |
---|
395 | CODE: |
---|
396 | { |
---|
397 | owl_messagelist_invalidate_formats(owl_global_get_msglist(&g)); |
---|
398 | owl_function_calculate_topmsg(OWL_DIRECTION_DOWNWARDS); |
---|
399 | owl_mainwin_redisplay(owl_global_get_mainwin(&g)); |
---|
400 | } |
---|
401 | |
---|
402 | const char * |
---|
403 | get_zephyr_variable(name) |
---|
404 | const char *name; |
---|
405 | CODE: |
---|
406 | RETVAL = owl_zephyr_get_variable(name); |
---|
407 | OUTPUT: |
---|
408 | RETVAL |
---|
409 | |
---|
410 | const utf8 * |
---|
411 | skiptokens(str, n) |
---|
412 | const char *str; |
---|
413 | int n; |
---|
414 | CODE: |
---|
415 | RETVAL = skiptokens(str, n); |
---|
416 | OUTPUT: |
---|
417 | RETVAL |
---|
418 | |
---|
419 | |
---|
420 | MODULE = BarnOwl PACKAGE = BarnOwl::Zephyr |
---|
421 | |
---|
422 | int |
---|
423 | have_zephyr() |
---|
424 | CODE: |
---|
425 | RETVAL = owl_global_is_havezephyr(&g); |
---|
426 | OUTPUT: |
---|
427 | RETVAL |
---|
428 | |
---|
429 | MODULE = BarnOwl PACKAGE = BarnOwl::Internal |
---|
430 | |
---|
431 | |
---|
432 | void |
---|
433 | new_command(name, func, summary, usage, description) |
---|
434 | char *name |
---|
435 | SV *func |
---|
436 | char *summary |
---|
437 | char *usage |
---|
438 | char *description |
---|
439 | PREINIT: |
---|
440 | owl_cmd cmd; |
---|
441 | CODE: |
---|
442 | { |
---|
443 | if(!SV_IS_CODEREF(func)) { |
---|
444 | croak("Command function must be a coderef!"); |
---|
445 | } |
---|
446 | cmd.name = name; |
---|
447 | cmd.cmd_perl = newSVsv(func); |
---|
448 | cmd.summary = summary; |
---|
449 | cmd.usage = usage; |
---|
450 | cmd.description = description; |
---|
451 | cmd.validctx = OWL_CTX_ANY; |
---|
452 | cmd.cmd_aliased_to = NULL; |
---|
453 | cmd.cmd_args_fn = NULL; |
---|
454 | cmd.cmd_v_fn = NULL; |
---|
455 | cmd.cmd_i_fn = NULL; |
---|
456 | cmd.cmd_ctxargs_fn = NULL; |
---|
457 | cmd.cmd_ctxv_fn = NULL; |
---|
458 | cmd.cmd_ctxi_fn = NULL; |
---|
459 | owl_cmddict_add_cmd(owl_global_get_cmddict(&g), &cmd); |
---|
460 | } |
---|
461 | |
---|
462 | void |
---|
463 | new_variable_string(name, ival, summ, desc) |
---|
464 | const char * name |
---|
465 | const char * ival |
---|
466 | const char * summ |
---|
467 | const char * desc |
---|
468 | CODE: |
---|
469 | owl_variable_dict_newvar_string(owl_global_get_vardict(&g), |
---|
470 | name, |
---|
471 | summ, |
---|
472 | desc, |
---|
473 | ival); |
---|
474 | |
---|
475 | void |
---|
476 | new_variable_int(name, ival, summ, desc) |
---|
477 | const char * name |
---|
478 | int ival |
---|
479 | const char * summ |
---|
480 | const char * desc |
---|
481 | CODE: |
---|
482 | owl_variable_dict_newvar_int(owl_global_get_vardict(&g), |
---|
483 | name, |
---|
484 | summ, |
---|
485 | desc, |
---|
486 | ival); |
---|
487 | |
---|
488 | void |
---|
489 | new_variable_bool(name, ival, summ, desc) |
---|
490 | const char * name |
---|
491 | int ival |
---|
492 | const char * summ |
---|
493 | const char * desc |
---|
494 | CODE: |
---|
495 | owl_variable_dict_newvar_bool(owl_global_get_vardict(&g), |
---|
496 | name, |
---|
497 | summ, |
---|
498 | desc, |
---|
499 | ival); |
---|
500 | |
---|
501 | MODULE = BarnOwl PACKAGE = BarnOwl::Editwin |
---|
502 | |
---|
503 | int |
---|
504 | replace(count, string) |
---|
505 | int count; |
---|
506 | const char *string; |
---|
507 | PREINIT: |
---|
508 | owl_editwin *e; |
---|
509 | CODE: |
---|
510 | e = owl_global_current_typwin(&g); |
---|
511 | if (e) { |
---|
512 | RETVAL = owl_editwin_replace(e, count, string); |
---|
513 | } else { |
---|
514 | RETVAL = 0; |
---|
515 | } |
---|
516 | OUTPUT: |
---|
517 | RETVAL |
---|
518 | |
---|
519 | int |
---|
520 | point_move(delta) |
---|
521 | int delta; |
---|
522 | PREINIT: |
---|
523 | owl_editwin *e; |
---|
524 | CODE: |
---|
525 | e = owl_global_current_typwin(&g); |
---|
526 | if (e) { |
---|
527 | RETVAL = owl_editwin_point_move(e, delta); |
---|
528 | } else { |
---|
529 | RETVAL = 0; |
---|
530 | } |
---|
531 | OUTPUT: |
---|
532 | RETVAL |
---|
533 | |
---|
534 | int |
---|
535 | replace_region(string) |
---|
536 | const char *string; |
---|
537 | PREINIT: |
---|
538 | owl_editwin *e; |
---|
539 | CODE: |
---|
540 | e = owl_global_current_typwin(&g); |
---|
541 | if (e) { |
---|
542 | RETVAL = owl_editwin_replace_region(e, string); |
---|
543 | } else { |
---|
544 | RETVAL = 0; |
---|
545 | } |
---|
546 | OUTPUT: |
---|
547 | RETVAL |
---|
548 | |
---|
549 | const utf8 * |
---|
550 | get_region() |
---|
551 | PREINIT: |
---|
552 | char *region; |
---|
553 | owl_editwin *e; |
---|
554 | CODE: |
---|
555 | e = owl_global_current_typwin(&g); |
---|
556 | if (e) { |
---|
557 | region = owl_editwin_get_region(owl_global_current_typwin(&g)); |
---|
558 | } else { |
---|
559 | region = NULL; |
---|
560 | } |
---|
561 | RETVAL = region; |
---|
562 | OUTPUT: |
---|
563 | RETVAL |
---|
564 | CLEANUP: |
---|
565 | g_free(region); |
---|
566 | |
---|
567 | SV * |
---|
568 | save_excursion(sub) |
---|
569 | SV *sub; |
---|
570 | PROTOTYPE: & |
---|
571 | PREINIT: |
---|
572 | int count; |
---|
573 | owl_editwin *e; |
---|
574 | owl_editwin_excursion *x; |
---|
575 | CODE: |
---|
576 | { |
---|
577 | e = owl_global_current_typwin(&g); |
---|
578 | if(!e) |
---|
579 | croak("The edit window is not currently active!"); |
---|
580 | |
---|
581 | x = owl_editwin_begin_excursion(owl_global_current_typwin(&g)); |
---|
582 | PUSHMARK(SP); |
---|
583 | count = call_sv(sub, G_SCALAR|G_EVAL|G_NOARGS); |
---|
584 | SPAGAIN; |
---|
585 | owl_editwin_end_excursion(owl_global_current_typwin(&g), x); |
---|
586 | |
---|
587 | if(SvTRUE(ERRSV)) { |
---|
588 | croak(NULL); |
---|
589 | } |
---|
590 | |
---|
591 | if(count == 1) |
---|
592 | RETVAL = SvREFCNT_inc(POPs); |
---|
593 | else |
---|
594 | XSRETURN_UNDEF; |
---|
595 | |
---|
596 | } |
---|
597 | OUTPUT: |
---|
598 | RETVAL |
---|
599 | |
---|
600 | int |
---|
601 | current_column() |
---|
602 | PREINIT: |
---|
603 | owl_editwin *e; |
---|
604 | CODE: |
---|
605 | e = owl_global_current_typwin(&g); |
---|
606 | if (e) { |
---|
607 | RETVAL = owl_editwin_current_column(e); |
---|
608 | } else { |
---|
609 | RETVAL = 0; |
---|
610 | } |
---|
611 | OUTPUT: |
---|
612 | RETVAL |
---|
613 | |
---|
614 | int |
---|
615 | point() |
---|
616 | PREINIT: |
---|
617 | owl_editwin *e; |
---|
618 | CODE: |
---|
619 | e = owl_global_current_typwin(&g); |
---|
620 | if (e) { |
---|
621 | RETVAL = owl_editwin_get_point(e); |
---|
622 | } else { |
---|
623 | RETVAL = 0; |
---|
624 | } |
---|
625 | OUTPUT: |
---|
626 | RETVAL |
---|
627 | |
---|
628 | int |
---|
629 | mark() |
---|
630 | PREINIT: |
---|
631 | owl_editwin *e; |
---|
632 | CODE: |
---|
633 | e = owl_global_current_typwin(&g); |
---|
634 | if (e) { |
---|
635 | RETVAL = owl_editwin_get_mark(e); |
---|
636 | } else { |
---|
637 | RETVAL = 0; |
---|
638 | } |
---|
639 | OUTPUT: |
---|
640 | RETVAL |
---|