… | |
… | |
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 "unistd.h" |
|
|
35 | |
34 | #include "iom.h" |
36 | #include "iom.h" |
35 | #include "rxvt.h" |
37 | #include "rxvt.h" |
36 | #include "keyboard.h" |
38 | #include "keyboard.h" |
37 | #include "rxvtutil.h" |
39 | #include "rxvtutil.h" |
38 | #include "rxvtperl.h" |
40 | #include "rxvtperl.h" |
… | |
… | |
393 | |
395 | |
394 | struct rxvt_perl_interp rxvt_perl; |
396 | struct rxvt_perl_interp rxvt_perl; |
395 | |
397 | |
396 | static PerlInterpreter *perl; |
398 | static PerlInterpreter *perl; |
397 | |
399 | |
398 | rxvt_perl_interp::rxvt_perl_interp () |
|
|
399 | { |
|
|
400 | } |
|
|
401 | |
|
|
402 | rxvt_perl_interp::~rxvt_perl_interp () |
400 | rxvt_perl_interp::~rxvt_perl_interp () |
403 | { |
401 | { |
404 | if (perl) |
402 | if (perl) |
405 | { |
403 | { |
406 | perl_destruct (perl); |
404 | perl_destruct (perl); |
… | |
… | |
411 | void |
409 | void |
412 | rxvt_perl_interp::init () |
410 | rxvt_perl_interp::init () |
413 | { |
411 | { |
414 | if (!perl) |
412 | if (!perl) |
415 | { |
413 | { |
416 | temp_environ temp_environ(rxvt_environ); |
414 | perl_environ = rxvt_environ; |
|
|
415 | swap (perl_environ, environ); |
417 | |
416 | |
418 | char *argv[] = { |
417 | char *argv[] = { |
419 | "", |
418 | "", |
420 | "-T", |
419 | "-T", |
421 | "-edo '" LIBDIR "/urxvt.pm' or ($@ and die $@) or exit 1", |
420 | "-edo '" LIBDIR "/urxvt.pm' or ($@ and die $@) or exit 1", |
… | |
… | |
431 | |
430 | |
432 | perl_destruct (perl); |
431 | perl_destruct (perl); |
433 | perl_free (perl); |
432 | perl_free (perl); |
434 | perl = 0; |
433 | perl = 0; |
435 | } |
434 | } |
|
|
435 | |
|
|
436 | swap (perl_environ, environ); |
436 | } |
437 | } |
437 | } |
438 | } |
438 | |
439 | |
439 | static void |
440 | static void |
440 | ungrab (rxvt_term *THIS) |
441 | ungrab (rxvt_term *THIS) |
… | |
… | |
482 | |
483 | |
483 | if (!should_invoke [htype]) |
484 | if (!should_invoke [htype]) |
484 | return false; |
485 | return false; |
485 | } |
486 | } |
486 | |
487 | |
487 | temp_environ temp_environ(rxvt_environ); |
488 | swap (perl_environ, environ); |
488 | |
489 | |
|
|
490 | try |
|
|
491 | { |
489 | dSP; |
492 | dSP; |
490 | va_list ap; |
493 | va_list ap; |
491 | |
494 | |
492 | va_start (ap, htype); |
495 | va_start (ap, htype); |
493 | |
496 | |
494 | ENTER; |
497 | ENTER; |
495 | SAVETMPS; |
498 | SAVETMPS; |
496 | |
499 | |
497 | PUSHMARK (SP); |
500 | PUSHMARK (SP); |
498 | |
501 | |
499 | XPUSHs (sv_2mortal (newSVterm (term))); |
502 | XPUSHs (sv_2mortal (newSVterm (term))); |
500 | XPUSHs (sv_2mortal (newSViv (htype))); |
503 | XPUSHs (sv_2mortal (newSViv (htype))); |
501 | |
504 | |
502 | for (;;) { |
505 | for (;;) { |
503 | data_type dt = (data_type)va_arg (ap, int); |
506 | data_type dt = (data_type)va_arg (ap, int); |
504 | |
507 | |
505 | switch (dt) |
508 | switch (dt) |
506 | { |
509 | { |
507 | case DT_INT: |
510 | case DT_INT: |
508 | XPUSHs (sv_2mortal (newSViv (va_arg (ap, int)))); |
511 | XPUSHs (sv_2mortal (newSViv (va_arg (ap, int)))); |
509 | break; |
512 | break; |
510 | |
513 | |
511 | case DT_LONG: |
514 | case DT_LONG: |
512 | XPUSHs (sv_2mortal (newSViv (va_arg (ap, long)))); |
515 | XPUSHs (sv_2mortal (newSViv (va_arg (ap, long)))); |
513 | break; |
516 | break; |
514 | |
517 | |
515 | case DT_STR: |
518 | case DT_STR: |
516 | XPUSHs (taint (sv_2mortal (newSVpv (va_arg (ap, char *), 0)))); |
519 | XPUSHs (taint (sv_2mortal (newSVpv (va_arg (ap, char *), 0)))); |
517 | break; |
520 | break; |
518 | |
521 | |
519 | case DT_STR_LEN: |
522 | case DT_STR_LEN: |
520 | { |
523 | { |
521 | char *str = va_arg (ap, char *); |
524 | char *str = va_arg (ap, char *); |
522 | int len = va_arg (ap, int); |
525 | int len = va_arg (ap, int); |
523 | |
526 | |
524 | XPUSHs (taint (sv_2mortal (newSVpvn (str, len)))); |
527 | XPUSHs (taint (sv_2mortal (newSVpvn (str, len)))); |
525 | } |
528 | } |
526 | break; |
529 | break; |
527 | |
530 | |
528 | case DT_WCS_LEN: |
531 | case DT_WCS_LEN: |
529 | { |
532 | { |
530 | wchar_t *wstr = va_arg (ap, wchar_t *); |
533 | wchar_t *wstr = va_arg (ap, wchar_t *); |
531 | int wlen = va_arg (ap, int); |
534 | int wlen = va_arg (ap, int); |
532 | |
535 | |
533 | XPUSHs (taint (sv_2mortal (wcs2sv (wstr, wlen)))); |
536 | XPUSHs (taint (sv_2mortal (wcs2sv (wstr, wlen)))); |
534 | } |
537 | } |
535 | break; |
538 | break; |
536 | |
539 | |
537 | case DT_XEVENT: |
540 | case DT_XEVENT: |
538 | { |
541 | { |
539 | XEvent *xe = va_arg (ap, XEvent *); |
542 | XEvent *xe = va_arg (ap, XEvent *); |
540 | HV *hv = newHV (); |
543 | HV *hv = newHV (); |
541 | |
544 | |
542 | # define set(name, sv) hv_store (hv, # name, sizeof (# name) - 1, sv, 0) |
545 | # define set(name, sv) hv_store (hv, # name, sizeof (# name) - 1, sv, 0) |
543 | # define setiv(name, val) hv_store (hv, # name, sizeof (# name) - 1, newSViv (val), 0) |
546 | # define setiv(name, val) hv_store (hv, # name, sizeof (# name) - 1, newSViv (val), 0) |
544 | # undef set |
547 | # undef set |
545 | |
548 | |
546 | setiv (type, xe->type); |
549 | setiv (type, xe->type); |
547 | setiv (send_event, xe->xany.send_event); |
550 | setiv (send_event, xe->xany.send_event); |
548 | setiv (serial, xe->xany.serial); |
551 | setiv (serial, xe->xany.serial); |
549 | |
552 | |
550 | switch (xe->type) |
553 | switch (xe->type) |
|
|
554 | { |
|
|
555 | case KeyPress: |
|
|
556 | case KeyRelease: |
|
|
557 | case ButtonPress: |
|
|
558 | case ButtonRelease: |
|
|
559 | case MotionNotify: |
|
|
560 | setiv (time, xe->xmotion.time); |
|
|
561 | setiv (x, xe->xmotion.x); |
|
|
562 | setiv (y, xe->xmotion.y); |
|
|
563 | setiv (row, xe->xmotion.y / term->fheight); |
|
|
564 | setiv (col, xe->xmotion.x / term->fwidth); |
|
|
565 | setiv (x_root, xe->xmotion.x_root); |
|
|
566 | setiv (y_root, xe->xmotion.y_root); |
|
|
567 | setiv (state, xe->xmotion.state); |
|
|
568 | break; |
|
|
569 | } |
|
|
570 | |
|
|
571 | switch (xe->type) |
|
|
572 | { |
|
|
573 | case KeyPress: |
|
|
574 | case KeyRelease: |
|
|
575 | setiv (keycode, xe->xkey.keycode); |
|
|
576 | break; |
|
|
577 | |
|
|
578 | case ButtonPress: |
|
|
579 | case ButtonRelease: |
|
|
580 | setiv (button, xe->xbutton.button); |
|
|
581 | break; |
|
|
582 | |
|
|
583 | case MotionNotify: |
|
|
584 | setiv (is_hint, xe->xmotion.is_hint); |
|
|
585 | break; |
|
|
586 | } |
|
|
587 | |
|
|
588 | XPUSHs (sv_2mortal (newRV_noinc ((SV *)hv))); |
|
|
589 | } |
|
|
590 | break; |
|
|
591 | |
|
|
592 | case DT_END: |
551 | { |
593 | { |
552 | case KeyPress: |
594 | va_end (ap); |
553 | case KeyRelease: |
595 | |
554 | case ButtonPress: |
596 | PUTBACK; |
555 | case ButtonRelease: |
597 | int count = call_pv ("urxvt::invoke", G_ARRAY | G_EVAL); |
556 | case MotionNotify: |
598 | SPAGAIN; |
557 | setiv (time, xe->xmotion.time); |
599 | |
558 | setiv (x, xe->xmotion.x); |
600 | if (count) |
559 | setiv (y, xe->xmotion.y); |
|
|
560 | setiv (row, xe->xmotion.y / term->fheight); |
|
|
561 | setiv (col, xe->xmotion.x / term->fwidth); |
|
|
562 | setiv (x_root, xe->xmotion.x_root); |
|
|
563 | setiv (y_root, xe->xmotion.y_root); |
|
|
564 | setiv (state, xe->xmotion.state); |
|
|
565 | break; |
601 | { |
|
|
602 | SV *status = POPs; |
|
|
603 | count = SvTRUE (status); |
|
|
604 | } |
|
|
605 | |
|
|
606 | PUTBACK; |
|
|
607 | FREETMPS; |
|
|
608 | LEAVE; |
|
|
609 | |
|
|
610 | if (SvTRUE (ERRSV)) |
|
|
611 | { |
|
|
612 | rxvt_warn ("perl hook %d evaluation error: %s", htype, SvPV_nolen (ERRSV)); |
|
|
613 | ungrab (term); // better lose the grab than the session |
|
|
614 | } |
|
|
615 | |
|
|
616 | if (htype == HOOK_DESTROY) |
|
|
617 | { |
|
|
618 | clearSVptr ((SV *)term->perl.self); |
|
|
619 | SvREFCNT_dec ((SV *)term->perl.self); |
|
|
620 | } |
|
|
621 | |
|
|
622 | swap (perl_environ, environ); |
|
|
623 | return count; |
566 | } |
624 | } |
567 | |
625 | |
568 | switch (xe->type) |
|
|
569 | { |
|
|
570 | case KeyPress: |
|
|
571 | case KeyRelease: |
|
|
572 | setiv (keycode, xe->xkey.keycode); |
|
|
573 | break; |
|
|
574 | |
|
|
575 | case ButtonPress: |
|
|
576 | case ButtonRelease: |
|
|
577 | setiv (button, xe->xbutton.button); |
|
|
578 | break; |
|
|
579 | |
|
|
580 | case MotionNotify: |
|
|
581 | setiv (is_hint, xe->xmotion.is_hint); |
|
|
582 | break; |
|
|
583 | } |
|
|
584 | |
|
|
585 | XPUSHs (sv_2mortal (newRV_noinc ((SV *)hv))); |
|
|
586 | } |
|
|
587 | break; |
|
|
588 | |
|
|
589 | case DT_END: |
|
|
590 | { |
|
|
591 | va_end (ap); |
|
|
592 | |
|
|
593 | PUTBACK; |
|
|
594 | int count = call_pv ("urxvt::invoke", G_ARRAY | G_EVAL); |
|
|
595 | SPAGAIN; |
|
|
596 | |
|
|
597 | if (count) |
|
|
598 | { |
|
|
599 | SV *status = POPs; |
|
|
600 | count = SvTRUE (status); |
|
|
601 | } |
|
|
602 | |
|
|
603 | PUTBACK; |
|
|
604 | FREETMPS; |
|
|
605 | LEAVE; |
|
|
606 | |
|
|
607 | if (SvTRUE (ERRSV)) |
|
|
608 | { |
|
|
609 | rxvt_warn ("perl hook %d evaluation error: %s", htype, SvPV_nolen (ERRSV)); |
|
|
610 | ungrab (term); // better lose the grab than the session |
|
|
611 | } |
|
|
612 | |
|
|
613 | if (htype == HOOK_DESTROY) |
|
|
614 | { |
|
|
615 | clearSVptr ((SV *)term->perl.self); |
|
|
616 | SvREFCNT_dec ((SV *)term->perl.self); |
|
|
617 | } |
|
|
618 | |
|
|
619 | return count; |
|
|
620 | } |
|
|
621 | |
|
|
622 | default: |
626 | default: |
623 | rxvt_fatal ("FATAL: unable to pass data type %d\n", dt); |
627 | rxvt_fatal ("FATAL: unable to pass data type %d\n", dt); |
|
|
628 | } |
624 | } |
629 | } |
625 | } |
630 | } |
|
|
631 | catch (...) |
|
|
632 | { |
|
|
633 | swap (perl_environ, environ); |
|
|
634 | throw; |
|
|
635 | } |
626 | } |
636 | } |
627 | |
637 | |
628 | ///////////////////////////////////////////////////////////////////////////// |
638 | ///////////////////////////////////////////////////////////////////////////// |
629 | |
639 | |
630 | MODULE = urxvt PACKAGE = urxvt |
640 | MODULE = urxvt PACKAGE = urxvt |
… | |
… | |
702 | RETVAL = newSVsv (sv); |
712 | RETVAL = newSVsv (sv); |
703 | SvTAINTED_off (RETVAL); |
713 | SvTAINTED_off (RETVAL); |
704 | OUTPUT: |
714 | OUTPUT: |
705 | RETVAL |
715 | RETVAL |
706 | |
716 | |
|
|
717 | void |
|
|
718 | _exit (int status) |
|
|
719 | |
707 | bool |
720 | bool |
708 | safe () |
721 | safe () |
709 | CODE: |
722 | CODE: |
710 | RETVAL = !rxvt_tainted (); |
723 | RETVAL = !rxvt_tainted (); |
711 | OUTPUT: |
724 | OUTPUT: |
… | |
… | |
1032 | OUTPUT: |
1045 | OUTPUT: |
1033 | RETVAL |
1046 | RETVAL |
1034 | |
1047 | |
1035 | int |
1048 | int |
1036 | rxvt_term::view_start (int newval = -1) |
1049 | rxvt_term::view_start (int newval = -1) |
|
|
1050 | PROTOTYPE: $;$ |
1037 | CODE: |
1051 | CODE: |
1038 | { |
1052 | { |
1039 | RETVAL = THIS->view_start; |
1053 | RETVAL = THIS->view_start; |
1040 | |
1054 | |
1041 | if (newval >= 0) |
1055 | if (newval >= 0) |
… | |
… | |
1368 | CODE: |
1382 | CODE: |
1369 | RETVAL = THIS->charsets [THIS->screen.charset]; |
1383 | RETVAL = THIS->charsets [THIS->screen.charset]; |
1370 | OUTPUT: |
1384 | OUTPUT: |
1371 | RETVAL |
1385 | RETVAL |
1372 | |
1386 | |
|
|
1387 | #void |
|
|
1388 | #rxvt_term::selection_clear () |
|
|
1389 | |
|
|
1390 | void |
|
|
1391 | rxvt_term::selection_make (U32 eventtime, bool rect = false) |
|
|
1392 | CODE: |
|
|
1393 | THIS->selection.op = SELECTION_CONT; |
|
|
1394 | THIS->selection.rect = rect; |
|
|
1395 | THIS->selection_make (eventtime); |
|
|
1396 | |
1373 | int |
1397 | int |
1374 | rxvt_term::selection_grab (U32 eventtime) |
1398 | rxvt_term::selection_grab (U32 eventtime) |
1375 | |
1399 | |
1376 | void |
1400 | void |
1377 | rxvt_term::selection (SV *newtext = 0) |
1401 | rxvt_term::selection (SV *newtext = 0) |