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