Changes in / [d126a19:7483942]
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
commands.c
rf89cc6f rf89cc6f 479 479 480 480 OWLCMD_ARGS("away", owl_command_away, OWL_CTX_INTERACTIVE, 481 "Set, enable or disable both AIM and zephyraway messages",481 "Set, enable or disable all away messages", 482 482 "away [ on | off | toggle ]\n" 483 483 "away <message>", 484 "Turn on or off the AIM and zephyr away message. If\n"484 "Turn on or off all away messages. If\n" 485 485 "'message' is specified turn them on with that message,\n" 486 486 "otherwise use the default.\n" 487 "\n"488 "This command really just runs the 'aaway' and 'zaway'\n"489 "commands together\n"490 487 "\n" 491 488 "SEE ALSO: aaway, zaway"), … … 1531 1528 char *owl_command_away(int argc, const char *const *argv, const char *buff) 1532 1529 { 1533 if ((argc==1) || 1534 ((argc==2) && !strcmp(argv[1], "on"))) { 1530 bool away_off; 1531 const char *message = NULL; 1532 1533 if (argc == 1 || 1534 (argc == 2 && !strcmp(argv[1], "on"))) { 1535 away_off = false; 1535 1536 owl_global_set_aaway_msg(&g, owl_global_get_aaway_msg_default(&g)); 1536 1537 owl_global_set_zaway_msg(&g, owl_global_get_zaway_msg_default(&g)); 1538 } else if (argc == 2 && !strcmp(argv[1], "off")) { 1539 away_off = true; 1540 } else if (argc == 2 && !strcmp(argv[1], "toggle")) { 1541 away_off = owl_function_is_away(); 1542 } else { 1543 away_off = false; 1544 message = skiptokens(buff, 1); 1545 } 1546 1547 if (away_off) { 1548 owl_function_aaway_off(); 1549 owl_function_zaway_off(); 1550 owl_perlconfig_perl_call_norv("BarnOwl::Hooks::_away_off", 0, NULL); 1551 owl_function_makemsg("Away messages off."); 1552 } else if (message != NULL) { 1553 owl_global_set_aaway_msg(&g, message); 1554 owl_global_set_zaway_msg(&g, message); 1537 1555 owl_function_aaway_on(); 1538 1556 owl_function_zaway_on(); 1557 owl_perlconfig_perl_call_norv("BarnOwl::Hooks::_away_on", 1, &message); 1558 owl_function_makemsg("Away messages set (%s).", message); 1559 } else { 1560 owl_function_aaway_on(); 1561 owl_function_zaway_on(); 1562 owl_perlconfig_perl_call_norv("BarnOwl::Hooks::_away_on", 0, NULL); 1539 1563 owl_function_makemsg("Away messages set."); 1540 return NULL; 1541 } 1542 1543 if (argc==2 && !strcmp(argv[1], "off")) { 1544 owl_function_aaway_off(); 1545 owl_function_zaway_off(); 1546 return NULL; 1547 } 1548 1549 if (argc==2 && !strcmp(argv[1], "toggle")) { 1550 /* if either one is on, turn it off, otherwise toggle both (turn 1551 * them both on) 1552 */ 1553 if (!owl_global_is_zaway(&g) && !owl_global_is_aaway(&g)) { 1554 owl_function_aaway_toggle(); 1555 owl_function_zaway_toggle(); 1556 owl_function_makemsg("Away messages set."); 1557 } else { 1558 if (owl_global_is_zaway(&g)) owl_function_zaway_toggle(); 1559 if (owl_global_is_aaway(&g)) owl_function_aaway_toggle(); 1560 owl_function_makemsg("Away messages off."); 1561 } 1562 return NULL; 1563 } 1564 1565 buff = skiptokens(buff, 1); 1566 owl_global_set_aaway_msg(&g, buff); 1567 owl_global_set_zaway_msg(&g, buff); 1568 owl_function_aaway_on(); 1569 owl_function_zaway_on(); 1570 owl_function_makemsg("Away messages set."); 1564 } 1565 1571 1566 return NULL; 1572 1567 } -
functions.c
recfbdcc recfbdcc 993 993 } 994 994 995 bool owl_function_is_away(void) 996 { 997 return owl_global_is_zaway(&g) || 998 owl_global_is_aaway(&g) || 999 owl_perlconfig_perl_call_bool("BarnOwl::Hooks::_get_is_away", 0, NULL); 1000 } 1001 995 1002 void owl_function_quit(void) 996 1003 { -
owl_perl.h
rf271129 r0c71c58 4 4 #include <stdio.h> 5 5 6 #define OWL_PERL_VOID_CALL (void)POPs; 6 /* 7 * This macro defines a convenience wrapper around the boilerplate 8 * of pushing char * arguments on to the stack for perl calling. 9 * 10 * Arguments are 11 * * i - the counter variable to use, which must be declared prior 12 * to calling this macro 13 * * argc - the number of arguments 14 * * argv - an array of char*s, of length at least argc; the arguments 15 * to push on to the stack 16 */ 17 #define OWL_PERL_PUSH_ARGS(i, argc, argv) { \ 18 for (i = 0; i < argc; i++) { \ 19 XPUSHs(sv_2mortal(owl_new_sv(argv[i]))); \ 20 } \ 21 } 7 22 8 23 /* 9 24 * This macro defines a convenience wrapper around the boilerplate of 10 * calling a method on a perl object (SV*) from C.25 * the perlcall methods. 11 26 * 12 27 * Arguments are 13 * * obj - the SV* to call the method on 14 * * meth - a char* method name 15 * * args - a code block responsible for pushing args (other than the object) 16 * * err - a string with a %s format specifier to log in case of error 17 * * fatalp - if true, perl errors terminate BarnOwl 18 * * ret - a code block executed if the call succeeded 28 * * call - the line of code to make the perl call 29 * * args - a code block responsible for pushing args 30 * * err - a string with a %s format specifier to log in case of error 31 * * fatalp - if true, perl errors terminate BarnOwl 32 * * discardret - should be true if no return is expected 33 * (if the call is passed the flag G_DISCARD or G_VOID) 34 * * ret - a code block executed if the call succeeded 19 35 * 20 36 * See also: `perldoc perlcall', `perldoc perlapi' 21 37 */ 22 #define OWL_PERL_CALL_METHOD(obj, meth, args, err, fatalp, ret) { \ 23 int count; \ 24 dSP; \ 25 ENTER; \ 26 SAVETMPS; \ 27 PUSHMARK(SP); \ 28 XPUSHs(obj); \ 29 {args} \ 30 PUTBACK; \ 31 \ 32 count = call_method(meth, G_SCALAR|G_EVAL); \ 33 \ 34 SPAGAIN; \ 35 \ 36 if(count != 1) { \ 37 fprintf(stderr, "perl returned wrong count: %d\n", count); \ 38 abort(); \ 38 #define OWL_PERL_CALL(call, args, err, fatalp, discardret, ret) { \ 39 int count; \ 40 dSP; \ 41 \ 42 ENTER; \ 43 SAVETMPS; \ 44 \ 45 PUSHMARK(SP); \ 46 {args} \ 47 PUTBACK; \ 48 \ 49 count = call; \ 50 \ 51 SPAGAIN; \ 52 \ 53 if (!discardret && count != 1) { \ 54 croak("Perl returned wrong count: %d\n", count); \ 55 } \ 56 \ 57 if (SvTRUE(ERRSV)) { \ 58 if (fatalp) { \ 59 fprintf(stderr, err, SvPV_nolen(ERRSV)); \ 60 exit(-1); \ 61 } else { \ 62 owl_function_error(err, SvPV_nolen(ERRSV)); \ 63 if (!discardret) (void)POPs; \ 64 sv_setsv(ERRSV, &PL_sv_undef); \ 39 65 } \ 40 if (SvTRUE(ERRSV)) { \ 41 if(fatalp) { \ 42 printf(err, SvPV_nolen(ERRSV)); \ 43 exit(-1); \ 44 } else { \ 45 owl_function_error(err, SvPV_nolen(ERRSV)); \ 46 (void)POPs; \ 47 sv_setsv(ERRSV, &PL_sv_undef); \ 48 } \ 49 } else { \ 50 ret; \ 51 } \ 52 PUTBACK; \ 53 FREETMPS; \ 54 LEAVE; \ 66 } else if (!discardret) { \ 67 ret; \ 68 } \ 69 PUTBACK; \ 70 FREETMPS; \ 71 LEAVE; \ 55 72 } 56 73 -
perl/lib/BarnOwl/Hooks.pm
rb8a3e00 r6df57d4 57 57 from every function registered with this hook will be appended and 58 58 displayed in a popup window, with zephyr formatting parsed. 59 60 =item $awayOn 61 62 Called, for all protocol handlers, to go away, with the away message, 63 if any. 64 65 =item $awayOff 66 67 Called, for all protocol handlers, to come back from away. 68 69 =item $getIsAway 70 71 Called to check away status for all protocol handlers. Protocol 72 handlers should return a true value if any account of the user is away 73 for the given protocol, and a false value otherwise. 59 74 60 75 =item $getQuickstart … … 75 90 $receiveMessage $newMessage 76 91 $mainLoop $getBuddyList 77 $getQuickstart); 92 $getQuickstart 93 $awayOn $awayOff $getIsAway); 78 94 79 95 our %EXPORT_TAGS = (all => [@EXPORT_OK]); … … 88 104 our $getBuddyList = BarnOwl::Hook->new; 89 105 our $getQuickstart = BarnOwl::Hook->new; 106 our $awayOn = BarnOwl::Hook->new; 107 our $awayOff = BarnOwl::Hook->new; 108 our $getIsAway = BarnOwl::Hook->new; 90 109 91 110 # Internal startup/shutdown routines called by the C code … … 201 220 } 202 221 222 sub _away_on { 223 $awayOn->run(@_); 224 } 225 226 sub _away_off { 227 $awayOff->run(); 228 } 229 230 sub _get_is_away { 231 my @is_away = grep { $_ } $getIsAway->run(); 232 return scalar @is_away; 233 } 234 203 235 sub _new_command { 204 236 my $command = shift; -
perlconfig.c
r7803326 r57ad328 224 224 CALLER_OWN char *owl_perlconfig_call_with_message(const char *subname, const owl_message *m) 225 225 { 226 dSP ; 227 int count; 228 SV *msgref, *srv; 229 char *out; 230 231 ENTER ; 232 SAVETMPS; 233 234 PUSHMARK(SP) ; 226 SV *msgref, *rv; 227 char *out = NULL; 228 235 229 msgref = owl_perlconfig_message2hashref(m); 236 XPUSHs(sv_2mortal(msgref)); 237 PUTBACK ; 238 239 count = call_pv(subname, G_SCALAR|G_EVAL); 240 241 SPAGAIN ; 242 243 if (SvTRUE(ERRSV)) { 244 owl_function_error("Perl Error: '%s'", SvPV_nolen(ERRSV)); 245 /* and clear the error */ 246 sv_setsv (ERRSV, &PL_sv_undef); 247 } 248 249 if (count != 1) { 250 fprintf(stderr, "bad perl! no biscuit! returned wrong count!\n"); 251 abort(); 252 } 253 254 srv = POPs; 255 256 if (srv) { 257 out = g_strdup(SvPV_nolen(srv)); 258 } else { 259 out = NULL; 260 } 261 262 PUTBACK ; 263 FREETMPS ; 264 LEAVE ; 265 230 231 OWL_PERL_CALL((call_pv(subname, G_SCALAR|G_EVAL)) 232 , 233 XPUSHs(sv_2mortal(msgref)); 234 , 235 "Perl Error: '%s'" 236 , 237 false 238 , 239 false 240 , 241 rv = POPs; 242 if (rv && SvPOK(rv)) 243 out = g_strdup(SvPV_nolen(rv)); 244 ); 266 245 return out; 267 246 } … … 273 252 CALLER_OWN char *owl_perlconfig_message_call_method(const owl_message *m, const char *method, int argc, const char **argv) 274 253 { 275 dSP; 276 unsigned int count, i; 277 SV *msgref, *srv; 278 char *out; 254 SV *msgref, *rv; 255 char *out = NULL; 256 int i; 279 257 280 258 msgref = owl_perlconfig_message2hashref(m); 281 259 282 ENTER; 283 SAVETMPS; 284 285 PUSHMARK(SP); 286 XPUSHs(sv_2mortal(msgref)); 287 for(i=0;i<argc;i++) { 288 XPUSHs(sv_2mortal(owl_new_sv(argv[i]))); 289 } 290 PUTBACK; 291 292 count = call_method(method, G_SCALAR|G_EVAL); 293 294 SPAGAIN; 295 296 if(count != 1) { 297 fprintf(stderr, "perl returned wrong count %u\n", count); 298 abort(); 299 } 300 301 if (SvTRUE(ERRSV)) { 302 owl_function_error("Error: '%s'", SvPV_nolen(ERRSV)); 303 /* and clear the error */ 304 sv_setsv (ERRSV, &PL_sv_undef); 305 } 306 307 srv = POPs; 308 309 if (srv) { 310 out = g_strdup(SvPV_nolen(srv)); 311 } else { 312 out = NULL; 313 } 314 315 PUTBACK; 316 FREETMPS; 317 LEAVE; 318 260 OWL_PERL_CALL(call_method(method, G_SCALAR|G_EVAL) 261 , 262 XPUSHs(sv_2mortal(msgref)); 263 OWL_PERL_PUSH_ARGS(i, argc, argv); 264 , 265 "Perl Error: '%s'" 266 , 267 false 268 , 269 false 270 , 271 rv = POPs; 272 if (rv && SvPOK(rv)) 273 out = g_strdup(SvPV_nolen(rv)); 274 ); 319 275 return out; 320 276 } … … 455 411 void owl_perlconfig_new_command(const char *name) 456 412 { 457 dSP; 458 459 ENTER; 460 SAVETMPS; 461 462 PUSHMARK(SP); 463 XPUSHs(sv_2mortal(owl_new_sv(name))); 464 PUTBACK; 465 466 call_pv("BarnOwl::Hooks::_new_command", G_VOID|G_EVAL); 467 468 SPAGAIN; 469 470 if(SvTRUE(ERRSV)) { 471 owl_function_error("%s", SvPV_nolen(ERRSV)); 472 } 473 474 FREETMPS; 475 LEAVE; 413 OWL_PERL_CALL(call_pv("BarnOwl::Hooks::_new_command", G_VOID|G_EVAL); 414 , 415 XPUSHs(sv_2mortal(owl_new_sv(name))); 416 , 417 "Perl Error: '%s'" 418 , 419 false 420 , 421 true 422 , 423 ); 424 } 425 426 CALLER_OWN char *owl_perlconfig_perl_call(const char *method, int argc, const char *const *argv) 427 { 428 SV *rv; 429 char *out = NULL; 430 int i; 431 OWL_PERL_CALL(call_pv(method, G_SCALAR|G_EVAL) 432 , 433 OWL_PERL_PUSH_ARGS(i, argc, argv); 434 , 435 "Perl Error: '%s'" 436 , 437 false 438 , 439 false 440 , 441 rv = POPs; 442 if (rv && SvPOK(rv)) 443 out = g_strdup(SvPV_nolen(rv)); 444 ); 445 return out; 446 } 447 448 int owl_perlconfig_perl_call_int(const char *method, int argc, const char *const *argv) 449 { 450 SV *rv; 451 int ret = -1; 452 int i; 453 OWL_PERL_CALL(call_pv(method, G_SCALAR|G_EVAL) 454 , 455 OWL_PERL_PUSH_ARGS(i, argc, argv); 456 , 457 "Perl Error: '%s'" 458 , 459 false 460 , 461 false 462 , 463 rv = POPs; 464 if (rv && SvIOK(rv)) 465 ret = SvIV(rv); 466 ); 467 return ret; 468 } 469 470 bool owl_perlconfig_perl_call_bool(const char *method, int argc, const char *const *argv) 471 { 472 SV *rv; 473 bool ret = false; 474 int i; 475 OWL_PERL_CALL(call_pv(method, G_SCALAR|G_EVAL) 476 , 477 OWL_PERL_PUSH_ARGS(i, argc, argv); 478 , 479 "Perl Error: '%s'" 480 , 481 false 482 , 483 false 484 , 485 rv = POPs; 486 if (rv) 487 ret = SvTRUE(rv); 488 ); 489 return ret; 490 } 491 492 void owl_perlconfig_perl_call_norv(const char *method, int argc, const char *const *argv) 493 { 494 int i; 495 OWL_PERL_CALL(call_pv(method, G_DISCARD|G_EVAL) 496 , 497 OWL_PERL_PUSH_ARGS(i, argc, argv); 498 , 499 "Perl Error: '%s'" 500 , 501 false 502 , 503 true 504 , 505 ); 476 506 } 477 507 … … 479 509 CALLER_OWN char *owl_perlconfig_perlcmd(const owl_cmd *cmd, int argc, const char *const *argv) 480 510 { 481 int i, count; 482 char * ret = NULL; 483 SV *rv; 484 dSP; 485 486 ENTER; 487 SAVETMPS; 488 489 PUSHMARK(SP); 490 for(i=0;i<argc;i++) { 491 XPUSHs(sv_2mortal(owl_new_sv(argv[i]))); 492 } 493 PUTBACK; 494 495 count = call_sv(cmd->cmd_perl, G_SCALAR|G_EVAL); 496 497 SPAGAIN; 498 499 if(SvTRUE(ERRSV)) { 500 owl_function_error("%s", SvPV_nolen(ERRSV)); 501 (void)POPs; 502 } else { 503 if(count != 1) 504 croak("Perl command %s returned more than one value!", cmd->name); 505 rv = POPs; 506 if(SvTRUE(rv)) { 507 ret = g_strdup(SvPV_nolen(rv)); 508 } 509 } 510 511 FREETMPS; 512 LEAVE; 513 514 return ret; 511 int i; 512 SV* rv; 513 char *out = NULL; 514 515 OWL_PERL_CALL(call_sv(cmd->cmd_perl, G_SCALAR|G_EVAL) 516 , 517 OWL_PERL_PUSH_ARGS(i, argc, argv); 518 , 519 "Perl Error: '%s'" 520 , 521 false 522 , 523 false 524 , 525 rv = POPs; 526 if (rv && SvPOK(rv)) 527 out = g_strdup(SvPV_nolen(rv)); 528 ); 529 return out; 515 530 } 516 531 … … 523 538 { 524 539 SV *cb = owl_editwin_get_cbdata(e); 525 SV *text; 526 dSP; 527 528 if(cb == NULL) { 540 SV *text = owl_new_sv(owl_editwin_get_text(e)); 541 542 if (cb == NULL) { 529 543 owl_function_error("Perl callback is NULL!"); 530 544 return; 531 545 } 532 text = owl_new_sv(owl_editwin_get_text(e)); 533 534 ENTER; 535 SAVETMPS; 536 537 PUSHMARK(SP); 538 XPUSHs(sv_2mortal(text)); 539 XPUSHs(sv_2mortal(newSViv(success))); 540 PUTBACK; 541 542 call_sv(cb, G_DISCARD|G_EVAL); 543 544 if(SvTRUE(ERRSV)) { 545 owl_function_error("%s", SvPV_nolen(ERRSV)); 546 } 547 548 FREETMPS; 549 LEAVE; 546 547 OWL_PERL_CALL(call_sv(cb, G_DISCARD|G_EVAL) 548 , 549 XPUSHs(sv_2mortal(text)); 550 XPUSHs(sv_2mortal(newSViv(success))); 551 , 552 "Perl Error: '%s'" 553 , 554 false 555 , 556 true 557 , 558 ); 550 559 } 551 560 -
sepbar.c
r6eb3ed9 r6df57d4 67 67 } 68 68 69 if (owl_ global_is_zaway(&g) || owl_global_is_aaway(&g)) {69 if (owl_function_is_away()) { 70 70 getyx(sepwin, y, x); 71 71 wmove(sepwin, y, x+2); 72 72 wattron(sepwin, A_BOLD); 73 73 wattroff(sepwin, A_REVERSE); 74 if (owl_global_is_zaway(&g) && owl_global_is_aaway(&g)) { 75 waddstr(sepwin, " AWAY "); 76 } else if (owl_global_is_zaway(&g)) { 77 waddstr(sepwin, " Z-AWAY "); 78 } else if (owl_global_is_aaway(&g)) { 79 waddstr(sepwin, " A-AWAY "); 80 } 74 waddstr(sepwin, " AWAY "); 81 75 wattron(sepwin, A_REVERSE); 82 76 wattroff(sepwin, A_BOLD); -
style.c
r14be3a5 r0c71c58 23 23 { 24 24 SV *sv = NULL; 25 OWL_PERL_CALL _METHOD(s->perlobj,26 "description",27 ;,28 "Error in style_get_description: %s",29 0,30 31 32 if (sv) {25 OWL_PERL_CALL(call_method("description", G_SCALAR|G_EVAL), 26 XPUSHs(s->perlobj);, 27 "Error in style_get_description: %s", 28 0, 29 false, 30 sv = SvREFCNT_inc(POPs); 31 ); 32 if (sv) { 33 33 return SvPV_nolen(sv_2mortal(sv)); 34 34 } else { … … 50 50 51 51 /* Call the perl object */ 52 OWL_PERL_CALL_METHOD(s->perlobj, 53 "format_message", 54 XPUSHs(sv_2mortal(owl_perlconfig_message2hashref(m)));, 55 "Error in format_message: %s", 56 0, 57 sv = SvREFCNT_inc(POPs); 58 ); 52 OWL_PERL_CALL(call_method("format_message", G_SCALAR|G_EVAL), 53 XPUSHs(s->perlobj); 54 XPUSHs(sv_2mortal(owl_perlconfig_message2hashref(m)));, 55 "Error in format_message: %s", 56 0, 57 false, 58 sv = SvREFCNT_inc(POPs); 59 ); 59 60 60 if (sv) {61 if (sv) { 61 62 body = SvPV_nolen(sv); 62 63 } else {
Note: See TracChangeset
for help on using the changeset viewer.