… | |
… | |
29 | #include "../config.h" |
29 | #include "../config.h" |
30 | |
30 | |
31 | #include <cstddef> |
31 | #include <cstddef> |
32 | #include <cstdarg> |
32 | #include <cstdarg> |
33 | |
33 | |
|
|
34 | #include "iom.h" |
34 | #include "rxvt.h" |
35 | #include "rxvt.h" |
35 | #include "iom.h" |
36 | #include "keyboard.h" |
36 | #include "rxvtutil.h" |
37 | #include "rxvtutil.h" |
37 | #include "rxvtperl.h" |
38 | #include "rxvtperl.h" |
38 | |
39 | |
39 | #include "perlxsi.c" |
40 | #include "perlxsi.c" |
40 | |
41 | |
… | |
… | |
406 | perl_free (perl); |
407 | perl_free (perl); |
407 | } |
408 | } |
408 | } |
409 | } |
409 | |
410 | |
410 | void |
411 | void |
411 | rxvt_perl_interp::init (bool tainted) |
412 | rxvt_perl_interp::init () |
412 | { |
413 | { |
413 | if (!perl) |
414 | if (!perl) |
414 | { |
415 | { |
415 | char *argv[] = { |
416 | char *argv[] = { |
416 | "", |
417 | "", |
|
|
418 | "-T", |
417 | "-edo '" LIBDIR "/urxvt.pm' or ($@ and die $@) or exit 1", |
419 | "-edo '" LIBDIR "/urxvt.pm' or ($@ and die $@) or exit 1", |
418 | "-T", |
|
|
419 | }; |
420 | }; |
420 | |
421 | |
421 | perl = perl_alloc (); |
422 | perl = perl_alloc (); |
422 | perl_construct (perl); |
423 | perl_construct (perl); |
423 | |
424 | |
424 | if (perl_parse (perl, xs_init, 2 + !!tainted, argv, (char **)NULL) |
425 | if (perl_parse (perl, xs_init, 3, argv, (char **)NULL) |
425 | || perl_run (perl)) |
426 | || perl_run (perl)) |
426 | { |
427 | { |
427 | rxvt_warn ("unable to initialize perl-interpreter, continuing without.\n"); |
428 | rxvt_warn ("unable to initialize perl-interpreter, continuing without.\n"); |
428 | |
429 | |
429 | perl_destruct (perl); |
430 | perl_destruct (perl); |
430 | perl_free (perl); |
431 | perl_free (perl); |
431 | perl = 0; |
432 | perl = 0; |
432 | } |
433 | } |
|
|
434 | } |
|
|
435 | } |
|
|
436 | |
|
|
437 | static void |
|
|
438 | ungrab (rxvt_term *THIS) |
|
|
439 | { |
|
|
440 | if (THIS->perl.grabtime) |
|
|
441 | { |
|
|
442 | XUngrabKeyboard (THIS->display->display, THIS->perl.grabtime); |
|
|
443 | XUngrabPointer (THIS->display->display, THIS->perl.grabtime); |
|
|
444 | THIS->perl.grabtime = 0; |
433 | } |
445 | } |
434 | } |
446 | } |
435 | |
447 | |
436 | bool |
448 | bool |
437 | rxvt_perl_interp::invoke (rxvt_term *term, hook_type htype, ...) |
449 | rxvt_perl_interp::invoke (rxvt_term *term, hook_type htype, ...) |
… | |
… | |
448 | return false; // perl not initialized for this instance |
460 | return false; // perl not initialized for this instance |
449 | else if (htype == HOOK_DESTROY) |
461 | else if (htype == HOOK_DESTROY) |
450 | { |
462 | { |
451 | // handled later |
463 | // handled later |
452 | } |
464 | } |
453 | else if (htype == HOOK_REFRESH_BEGIN || htype == HOOK_REFRESH_END) |
465 | else |
454 | { |
466 | { |
455 | HV *hv = (HV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, 0)); |
467 | if (htype == HOOK_REFRESH_BEGIN || htype == HOOK_REFRESH_END) |
456 | |
|
|
457 | if (HvKEYS (hv)) |
|
|
458 | { |
468 | { |
|
|
469 | HV *hv = (HV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, 0)); |
|
|
470 | |
|
|
471 | if (HvKEYS (hv)) |
|
|
472 | { |
459 | hv_iterinit (hv); |
473 | hv_iterinit (hv); |
460 | |
474 | |
461 | while (HE *he = hv_iternext (hv)) |
475 | while (HE *he = hv_iternext (hv)) |
462 | ((overlay *)SvIV (hv_iterval (hv, he)))->swap (); |
476 | ((overlay *)SvIV (hv_iterval (hv, he)))->swap (); |
|
|
477 | } |
|
|
478 | |
463 | } |
479 | } |
|
|
480 | |
|
|
481 | if (!should_invoke [htype]) |
|
|
482 | return false; |
464 | } |
483 | } |
465 | else if (!should_invoke [htype]) |
|
|
466 | return false; |
|
|
467 | |
484 | |
468 | dSP; |
485 | dSP; |
469 | va_list ap; |
486 | va_list ap; |
470 | |
487 | |
471 | va_start (ap, htype); |
488 | va_start (ap, htype); |
… | |
… | |
582 | PUTBACK; |
599 | PUTBACK; |
583 | FREETMPS; |
600 | FREETMPS; |
584 | LEAVE; |
601 | LEAVE; |
585 | |
602 | |
586 | if (SvTRUE (ERRSV)) |
603 | if (SvTRUE (ERRSV)) |
|
|
604 | { |
587 | rxvt_warn ("perl hook %d evaluation error: %s", htype, SvPV_nolen (ERRSV)); |
605 | rxvt_warn ("perl hook %d evaluation error: %s", htype, SvPV_nolen (ERRSV)); |
|
|
606 | ungrab (term); // better lose the grab than the session |
|
|
607 | } |
588 | |
608 | |
589 | if (htype == HOOK_DESTROY) |
609 | if (htype == HOOK_DESTROY) |
590 | { |
610 | { |
591 | clearSVptr ((SV *)term->perl.self); |
611 | clearSVptr ((SV *)term->perl.self); |
592 | SvREFCNT_dec ((SV *)term->perl.self); |
612 | SvREFCNT_dec ((SV *)term->perl.self); |
… | |
… | |
646 | export_const_iv (Button2Mask); |
666 | export_const_iv (Button2Mask); |
647 | export_const_iv (Button3Mask); |
667 | export_const_iv (Button3Mask); |
648 | export_const_iv (Button4Mask); |
668 | export_const_iv (Button4Mask); |
649 | export_const_iv (Button5Mask); |
669 | export_const_iv (Button5Mask); |
650 | export_const_iv (AnyModifier); |
670 | export_const_iv (AnyModifier); |
|
|
671 | |
|
|
672 | export_const_iv (EVENT_NONE); |
|
|
673 | export_const_iv (EVENT_READ); |
|
|
674 | export_const_iv (EVENT_WRITE); |
651 | } |
675 | } |
652 | |
676 | |
653 | SV * |
677 | SV * |
654 | new (...) |
678 | new (...) |
655 | CODE: |
679 | CODE: |
… | |
… | |
692 | |
716 | |
693 | void |
717 | void |
694 | fatal (const char *msg) |
718 | fatal (const char *msg) |
695 | CODE: |
719 | CODE: |
696 | rxvt_fatal ("%s", msg); |
720 | rxvt_fatal ("%s", msg); |
|
|
721 | |
|
|
722 | SV * |
|
|
723 | untaint (SV *sv) |
|
|
724 | CODE: |
|
|
725 | RETVAL = newSVsv (sv); |
|
|
726 | SvTAINTED_off (RETVAL); |
|
|
727 | OUTPUT: |
|
|
728 | RETVAL |
|
|
729 | |
|
|
730 | bool |
|
|
731 | safe () |
|
|
732 | CODE: |
|
|
733 | RETVAL = !rxvt_tainted (); |
|
|
734 | OUTPUT: |
|
|
735 | RETVAL |
697 | |
736 | |
698 | NV |
737 | NV |
699 | NOW () |
738 | NOW () |
700 | CODE: |
739 | CODE: |
701 | RETVAL = NOW; |
740 | RETVAL = NOW; |
… | |
… | |
782 | } |
821 | } |
783 | OUTPUT: |
822 | OUTPUT: |
784 | RETVAL |
823 | RETVAL |
785 | |
824 | |
786 | void |
825 | void |
787 | rxvt_term::allow_events_async (U32 eventtime = THIS->perl.grabtime) |
826 | rxvt_term::allow_events_async () |
788 | CODE: |
827 | CODE: |
789 | XAllowEvents (THIS->display->display, AsyncBoth, eventtime); |
828 | XAllowEvents (THIS->display->display, AsyncBoth, THIS->perl.grabtime); |
790 | |
829 | |
791 | void |
830 | void |
792 | rxvt_term::allow_events_sync (U32 eventtime = THIS->perl.grabtime) |
831 | rxvt_term::allow_events_sync () |
793 | CODE: |
832 | CODE: |
794 | XAllowEvents (THIS->display->display, SyncBoth, eventtime); |
833 | XAllowEvents (THIS->display->display, SyncBoth, THIS->perl.grabtime); |
795 | |
834 | |
796 | void |
835 | void |
797 | rxvt_term::allow_events_replay (U32 eventtime = THIS->perl.grabtime) |
836 | rxvt_term::allow_events_replay () |
798 | CODE: |
837 | CODE: |
799 | XAllowEvents (THIS->display->display, ReplayPointer, eventtime); |
838 | XAllowEvents (THIS->display->display, ReplayPointer, THIS->perl.grabtime); |
800 | XAllowEvents (THIS->display->display, ReplayKeyboard, eventtime); |
839 | XAllowEvents (THIS->display->display, ReplayKeyboard, THIS->perl.grabtime); |
801 | |
840 | |
802 | void |
841 | void |
803 | rxvt_term::ungrab (U32 eventtime = THIS->perl.grabtime) |
842 | rxvt_term::ungrab () |
804 | CODE: |
843 | CODE: |
805 | THIS->perl.grabtime = 0; |
844 | ungrab (THIS); |
806 | XUngrabKeyboard (THIS->display->display, eventtime); |
|
|
807 | XUngrabPointer (THIS->display->display, eventtime); |
|
|
808 | |
845 | |
809 | int |
846 | int |
810 | rxvt_term::strwidth (SV *str) |
847 | rxvt_term::strwidth (SV *str) |
811 | CODE: |
848 | CODE: |
812 | { |
849 | { |
… | |
… | |
905 | case 2: RETVAL = THIS->ModNumLockMask; break; |
942 | case 2: RETVAL = THIS->ModNumLockMask; break; |
906 | } |
943 | } |
907 | OUTPUT: |
944 | OUTPUT: |
908 | RETVAL |
945 | RETVAL |
909 | |
946 | |
|
|
947 | char * |
|
|
948 | rxvt_term::display_id () |
|
|
949 | ALIAS: |
|
|
950 | display_id = 0 |
|
|
951 | locale = 1 |
|
|
952 | CODE: |
|
|
953 | switch (ix) |
|
|
954 | { |
|
|
955 | case 0: RETVAL = THIS->display->id; break; |
|
|
956 | case 1: RETVAL = THIS->locale; break; |
|
|
957 | } |
|
|
958 | OUTPUT: |
|
|
959 | RETVAL |
|
|
960 | |
|
|
961 | int |
|
|
962 | rxvt_term::pty_ev_events (int events = EVENT_UNDEF) |
|
|
963 | CODE: |
|
|
964 | RETVAL = THIS->pty_ev.events; |
|
|
965 | if (events != EVENT_UNDEF) |
|
|
966 | THIS->pty_ev.set (events); |
|
|
967 | OUTPUT: |
|
|
968 | RETVAL |
|
|
969 | |
910 | U32 |
970 | U32 |
911 | rxvt_term::parent () |
971 | rxvt_term::parent () |
912 | CODE: |
972 | CODE: |
913 | RETVAL = (U32)THIS->parent [0]; |
973 | RETVAL = (U32)THIS->parent [0]; |
914 | OUTPUT: |
974 | OUTPUT: |
… | |
… | |
1215 | } |
1275 | } |
1216 | } |
1276 | } |
1217 | OUTPUT: |
1277 | OUTPUT: |
1218 | RETVAL |
1278 | RETVAL |
1219 | |
1279 | |
|
|
1280 | bool |
|
|
1281 | rxvt_term::parse_keysym (char *keysym, char *str) |
|
|
1282 | CODE: |
|
|
1283 | RETVAL = 0 < THIS->parse_keysym (keysym, str); |
|
|
1284 | THIS->keyboard->register_done (); |
|
|
1285 | OUTPUT: |
|
|
1286 | RETVAL |
|
|
1287 | |
1220 | void |
1288 | void |
1221 | rxvt_term::cur (...) |
1289 | rxvt_term::screen_cur (...) |
1222 | PROTOTYPE: $;$$ |
1290 | PROTOTYPE: $;$$ |
1223 | ALIAS: |
1291 | ALIAS: |
1224 | screen_cur = 0 |
1292 | screen_cur = 0 |
1225 | selection_beg = 1 |
1293 | selection_beg = 1 |
1226 | selection_end = 2 |
1294 | selection_end = 2 |
… | |
… | |
1255 | void |
1323 | void |
1256 | rxvt_term::selection (SV *newtext = 0) |
1324 | rxvt_term::selection (SV *newtext = 0) |
1257 | PPCODE: |
1325 | PPCODE: |
1258 | { |
1326 | { |
1259 | if (GIMME_V != G_VOID) |
1327 | if (GIMME_V != G_VOID) |
|
|
1328 | XPUSHs (THIS->selection.text |
1260 | XPUSHs (taint (sv_2mortal (wcs2sv (THIS->selection.text, THIS->selection.len)))); |
1329 | ? taint (sv_2mortal (wcs2sv (THIS->selection.text, THIS->selection.len))) |
|
|
1330 | : &PL_sv_undef); |
1261 | |
1331 | |
1262 | if (newtext) |
1332 | if (newtext) |
1263 | { |
1333 | { |
1264 | free (THIS->selection.text); |
1334 | free (THIS->selection.text); |
1265 | |
1335 | |
1266 | THIS->selection.text = sv2wcs (newtext); |
1336 | THIS->selection.text = sv2wcs (newtext); |
1267 | THIS->selection.len = wcslen (THIS->selection.text); |
1337 | THIS->selection.len = wcslen (THIS->selection.text); |
1268 | } |
1338 | } |
1269 | } |
1339 | } |
|
|
1340 | |
|
|
1341 | void |
|
|
1342 | rxvt_term::scr_xor_rect (int beg_row, int beg_col, int end_row, int end_col, U32 rstyle1 = RS_RVid, U32 rstyle2 = RS_RVid | RS_Uline) |
|
|
1343 | |
|
|
1344 | void |
|
|
1345 | rxvt_term::scr_xor_span (int beg_row, int beg_col, int end_row, int end_col, U32 rstyle = RS_RVid) |
|
|
1346 | |
|
|
1347 | void |
|
|
1348 | rxvt_term::scr_bell () |
1270 | |
1349 | |
1271 | void |
1350 | void |
1272 | rxvt_term::scr_add_lines (SV *string) |
1351 | rxvt_term::scr_add_lines (SV *string) |
1273 | CODE: |
1352 | CODE: |
1274 | { |
1353 | { |