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