1 | /*----------------------------------------------------------------------* |
1 | /*----------------------------------------------------------------------* |
2 | * File: rxvtperl.xs |
2 | * File: rxvtperl.xs |
3 | *----------------------------------------------------------------------* |
3 | *----------------------------------------------------------------------* |
4 | * |
4 | * |
5 | * All portions of code are copyright by their respective author/s. |
5 | * All portions of code are copyright by their respective author/s. |
6 | * Copyright (c) 2005-2008 Marc Lehmann <pcg@goof.com> |
6 | * Copyright (c) 2005-2008,2011 Marc Lehmann <schmorp@schmorp.de> |
7 | * |
7 | * |
8 | * This program is free software; you can redistribute it and/or modify |
8 | * This program is free software; you can redistribute it and/or modify |
9 | * it under the terms of the GNU General Public License as published by |
9 | * it under the terms of the GNU General Public License as published by |
10 | * the Free Software Foundation; either version 2 of the License, or |
10 | * the Free Software Foundation; either version 2 of the License, or |
11 | * (at your option) any later version. |
11 | * (at your option) any later version. |
… | |
… | |
302 | THIS->refresh_check (); |
302 | THIS->refresh_check (); |
303 | } |
303 | } |
304 | |
304 | |
305 | ///////////////////////////////////////////////////////////////////////////// |
305 | ///////////////////////////////////////////////////////////////////////////// |
306 | |
306 | |
307 | #define IOM_CLASS "urxvt" |
|
|
308 | #define IOM_WARN rxvt_warn |
|
|
309 | #include "iom_perl.h" |
307 | #include "iom_perl.h" |
310 | |
308 | |
311 | ///////////////////////////////////////////////////////////////////////////// |
309 | ///////////////////////////////////////////////////////////////////////////// |
312 | |
310 | |
313 | struct rxvt_perl_interp rxvt_perl; |
311 | struct rxvt_perl_interp rxvt_perl; |
… | |
… | |
343 | " unshift @INC, '" LIBDIR "';" |
341 | " unshift @INC, '" LIBDIR "';" |
344 | "}" |
342 | "}" |
345 | "" |
343 | "" |
346 | "use urxvt;" |
344 | "use urxvt;" |
347 | }; |
345 | }; |
348 | int argc = sizeof (args) / sizeof (args[0]); |
346 | int argc = ARRAY_LENGTH(args); |
349 | char **argv = args; |
347 | char **argv = args; |
350 | |
348 | |
351 | PERL_SYS_INIT3 (&argc, &argv, &environ); |
349 | PERL_SYS_INIT3 (&argc, &argv, &environ); |
352 | perl = perl_alloc (); |
350 | perl = perl_alloc (); |
353 | perl_construct (perl); |
351 | perl_construct (perl); |
… | |
… | |
415 | ENTER; |
413 | ENTER; |
416 | SAVETMPS; |
414 | SAVETMPS; |
417 | |
415 | |
418 | PUSHMARK (SP); |
416 | PUSHMARK (SP); |
419 | |
417 | |
|
|
418 | EXTEND (SP, 2); |
420 | XPUSHs (sv_2mortal (newSVterm (term))); |
419 | PUSHs (sv_2mortal (newSVterm (term))); |
421 | XPUSHs (sv_2mortal (newSViv (htype))); |
420 | PUSHs (sv_2mortal (newSViv (htype))); |
422 | |
421 | |
423 | for (;;) { |
422 | for (;;) { |
424 | data_type dt = (data_type)va_arg (ap, int); |
423 | data_type dt = (data_type)va_arg (ap, int); |
425 | |
424 | |
426 | switch (dt) |
425 | switch (dt) |
… | |
… | |
583 | FREETMPS; |
582 | FREETMPS; |
584 | LEAVE; |
583 | LEAVE; |
585 | |
584 | |
586 | if (SvTRUE (ERRSV)) |
585 | if (SvTRUE (ERRSV)) |
587 | { |
586 | { |
588 | rxvt_warn ("perl hook %d evaluation error: %s", htype, SvPV_nolen (ERRSV)); |
587 | rxvt_warn ("perl hook %d evaluation error: %s", htype, SvPVbyte_nolen (ERRSV)); |
589 | ungrab (term); // better lose the grab than the session |
588 | ungrab (term); // better lose the grab than the session |
590 | } |
589 | } |
591 | |
590 | |
592 | event_consumed = !!count; |
591 | event_consumed = !!count; |
593 | } |
592 | } |
… | |
… | |
610 | // don't allow further calls |
609 | // don't allow further calls |
611 | term->perl.self = 0; |
610 | term->perl.self = 0; |
612 | } |
611 | } |
613 | |
612 | |
614 | return event_consumed; |
613 | return event_consumed; |
|
|
614 | } |
|
|
615 | |
|
|
616 | void |
|
|
617 | rxvt_perl_interp::selection_finish (rxvt_selection *sel, char *data, unsigned int len) |
|
|
618 | { |
|
|
619 | localise_env set_environ (perl_environ); |
|
|
620 | |
|
|
621 | ENTER; |
|
|
622 | SAVETMPS; |
|
|
623 | |
|
|
624 | dSP; |
|
|
625 | XPUSHs (sv_2mortal (newSVpvn (data, len))); |
|
|
626 | call_sv ((SV *)sel->cb_sv, G_VOID | G_DISCARD | G_EVAL); |
|
|
627 | |
|
|
628 | if (SvTRUE (ERRSV)) |
|
|
629 | rxvt_warn ("perl selection callback evaluation error: %s", SvPVbyte_nolen (ERRSV)); |
|
|
630 | |
|
|
631 | FREETMPS; |
|
|
632 | LEAVE; |
615 | } |
633 | } |
616 | |
634 | |
617 | ///////////////////////////////////////////////////////////////////////////// |
635 | ///////////////////////////////////////////////////////////////////////////// |
618 | |
636 | |
619 | MODULE = urxvt PACKAGE = urxvt |
637 | MODULE = urxvt PACKAGE = urxvt |
… | |
… | |
770 | const_iv (XIMDontChange), |
788 | const_iv (XIMDontChange), |
771 | # endif |
789 | # endif |
772 | # endif |
790 | # endif |
773 | }; |
791 | }; |
774 | |
792 | |
775 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
793 | for (civ = const_iv + ARRAY_LENGTH(const_iv); civ-- > const_iv; ) |
776 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
794 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
777 | } |
795 | } |
778 | |
796 | |
779 | void |
797 | void |
780 | warn (const char *msg) |
798 | warn (const char *msg) |
… | |
… | |
1448 | # include "rsinc.h" |
1466 | # include "rsinc.h" |
1449 | # undef def |
1467 | # undef def |
1450 | # undef reserve |
1468 | # undef reserve |
1451 | }; |
1469 | }; |
1452 | |
1470 | |
1453 | rs = rslist + sizeof (rslist) / sizeof (rslist [0]); |
1471 | rs = rslist + ARRAY_LENGTH(rslist); |
1454 | |
1472 | |
1455 | if (*name) |
1473 | if (*name) |
1456 | { |
1474 | { |
1457 | do { |
1475 | do { |
1458 | if (rs-- == rslist) |
1476 | if (rs-- == rslist) |