… | |
… | |
36 | #include "rxvtutil.h" |
36 | #include "rxvtutil.h" |
37 | #include "rxvtperl.h" |
37 | #include "rxvtperl.h" |
38 | |
38 | |
39 | #include "perlxsi.c" |
39 | #include "perlxsi.c" |
40 | |
40 | |
|
|
41 | #if defined(HAVE_SCROLLBARS) || defined(MENUBAR) |
|
|
42 | # define GRAB_CURSOR THIS->leftptr_cursor |
|
|
43 | #else |
|
|
44 | # define GRAB_CURSOR None |
|
|
45 | #endif |
|
|
46 | |
41 | #undef LINENO |
47 | #undef LINENO |
42 | #define LINENO(n) MOD (THIS->term_start + int(n), THIS->total_rows) |
48 | #define LINENO(n) MOD (THIS->term_start + int(n), THIS->total_rows) |
43 | #undef ROW |
49 | #undef ROW |
44 | #define ROW(n) THIS->row_buf [LINENO (n)] |
50 | #define ROW(n) THIS->row_buf [LINENO (n)] |
45 | |
51 | |
46 | ///////////////////////////////////////////////////////////////////////////// |
52 | ///////////////////////////////////////////////////////////////////////////// |
|
|
53 | |
|
|
54 | static SV * |
|
|
55 | taint (SV *sv) |
|
|
56 | { |
|
|
57 | SvTAINT (sv); |
|
|
58 | return sv; |
|
|
59 | } |
|
|
60 | |
|
|
61 | static SV * |
|
|
62 | taint_if (SV *sv, SV *src) |
|
|
63 | { |
|
|
64 | if (SvTAINTED (src)) |
|
|
65 | SvTAINT (sv); |
|
|
66 | |
|
|
67 | return sv; |
|
|
68 | } |
47 | |
69 | |
48 | static wchar_t * |
70 | static wchar_t * |
49 | sv2wcs (SV *sv) |
71 | sv2wcs (SV *sv) |
50 | { |
72 | { |
51 | STRLEN len; |
73 | STRLEN len; |
… | |
… | |
390 | { |
412 | { |
391 | if (!perl) |
413 | if (!perl) |
392 | { |
414 | { |
393 | char *argv[] = { |
415 | char *argv[] = { |
394 | "", |
416 | "", |
|
|
417 | "-T", |
395 | "-edo '" LIBDIR "/urxvt.pm' or ($@ and die $@) or exit 1", |
418 | "-edo '" LIBDIR "/urxvt.pm' or ($@ and die $@) or exit 1", |
396 | }; |
419 | }; |
397 | |
420 | |
398 | perl = perl_alloc (); |
421 | perl = perl_alloc (); |
399 | perl_construct (perl); |
422 | perl_construct (perl); |
400 | |
423 | |
401 | if (perl_parse (perl, xs_init, 2, argv, (char **)NULL) |
424 | if (perl_parse (perl, xs_init, 3, argv, (char **)NULL) |
402 | || perl_run (perl)) |
425 | || perl_run (perl)) |
403 | { |
426 | { |
404 | rxvt_warn ("unable to initialize perl-interpreter, continuing without.\n"); |
427 | rxvt_warn ("unable to initialize perl-interpreter, continuing without.\n"); |
405 | |
428 | |
406 | perl_destruct (perl); |
429 | perl_destruct (perl); |
407 | perl_free (perl); |
430 | perl_free (perl); |
408 | perl = 0; |
431 | perl = 0; |
409 | } |
432 | } |
|
|
433 | } |
|
|
434 | } |
|
|
435 | |
|
|
436 | static void |
|
|
437 | ungrab (rxvt_term *THIS) |
|
|
438 | { |
|
|
439 | if (THIS->perl.grabtime) |
|
|
440 | { |
|
|
441 | XUngrabKeyboard (THIS->display->display, THIS->perl.grabtime); |
|
|
442 | XUngrabPointer (THIS->display->display, THIS->perl.grabtime); |
|
|
443 | THIS->perl.grabtime = 0; |
410 | } |
444 | } |
411 | } |
445 | } |
412 | |
446 | |
413 | bool |
447 | bool |
414 | rxvt_perl_interp::invoke (rxvt_term *term, hook_type htype, ...) |
448 | rxvt_perl_interp::invoke (rxvt_term *term, hook_type htype, ...) |
… | |
… | |
467 | case DT_LONG: |
501 | case DT_LONG: |
468 | XPUSHs (sv_2mortal (newSViv (va_arg (ap, long)))); |
502 | XPUSHs (sv_2mortal (newSViv (va_arg (ap, long)))); |
469 | break; |
503 | break; |
470 | |
504 | |
471 | case DT_STR: |
505 | case DT_STR: |
472 | XPUSHs (sv_2mortal (newSVpv (va_arg (ap, char *), 0))); |
506 | XPUSHs (taint (sv_2mortal (newSVpv (va_arg (ap, char *), 0)))); |
473 | break; |
507 | break; |
474 | |
508 | |
475 | case DT_STR_LEN: |
509 | case DT_STR_LEN: |
476 | { |
510 | { |
477 | char *str = va_arg (ap, char *); |
511 | char *str = va_arg (ap, char *); |
478 | int len = va_arg (ap, int); |
512 | int len = va_arg (ap, int); |
479 | |
513 | |
480 | XPUSHs (sv_2mortal (newSVpvn (str, len))); |
514 | XPUSHs (taint (sv_2mortal (newSVpvn (str, len)))); |
481 | } |
515 | } |
482 | break; |
516 | break; |
483 | |
517 | |
484 | case DT_WCS_LEN: |
518 | case DT_WCS_LEN: |
485 | { |
519 | { |
486 | wchar_t *wstr = va_arg (ap, wchar_t *); |
520 | wchar_t *wstr = va_arg (ap, wchar_t *); |
487 | int wlen = va_arg (ap, int); |
521 | int wlen = va_arg (ap, int); |
488 | |
522 | |
489 | XPUSHs (sv_2mortal (wcs2sv (wstr, wlen))); |
523 | XPUSHs (taint (sv_2mortal (wcs2sv (wstr, wlen)))); |
490 | } |
524 | } |
491 | break; |
525 | break; |
492 | |
526 | |
493 | case DT_XEVENT: |
527 | case DT_XEVENT: |
494 | { |
528 | { |
… | |
… | |
559 | PUTBACK; |
593 | PUTBACK; |
560 | FREETMPS; |
594 | FREETMPS; |
561 | LEAVE; |
595 | LEAVE; |
562 | |
596 | |
563 | if (SvTRUE (ERRSV)) |
597 | if (SvTRUE (ERRSV)) |
|
|
598 | { |
564 | rxvt_warn ("perl hook %d evaluation error: %s", htype, SvPV_nolen (ERRSV)); |
599 | rxvt_warn ("perl hook %d evaluation error: %s", htype, SvPV_nolen (ERRSV)); |
|
|
600 | ungrab (term); // better lose the grab than the session |
|
|
601 | } |
565 | |
602 | |
566 | if (htype == HOOK_DESTROY) |
603 | if (htype == HOOK_DESTROY) |
567 | { |
604 | { |
568 | clearSVptr ((SV *)term->perl.self); |
605 | clearSVptr ((SV *)term->perl.self); |
569 | SvREFCNT_dec ((SV *)term->perl.self); |
606 | SvREFCNT_dec ((SV *)term->perl.self); |
… | |
… | |
670 | void |
707 | void |
671 | fatal (const char *msg) |
708 | fatal (const char *msg) |
672 | CODE: |
709 | CODE: |
673 | rxvt_fatal ("%s", msg); |
710 | rxvt_fatal ("%s", msg); |
674 | |
711 | |
|
|
712 | SV * |
|
|
713 | untaint (SV *sv) |
|
|
714 | CODE: |
|
|
715 | RETVAL = newSVsv (sv); |
|
|
716 | SvTAINTED_off (RETVAL); |
|
|
717 | OUTPUT: |
|
|
718 | RETVAL |
|
|
719 | |
675 | NV |
720 | NV |
676 | NOW () |
721 | NOW () |
677 | CODE: |
722 | CODE: |
678 | RETVAL = NOW; |
723 | RETVAL = NOW; |
679 | OUTPUT: |
724 | OUTPUT: |
… | |
… | |
735 | void |
780 | void |
736 | rxvt_term::grab_button (int button, U32 modifiers) |
781 | rxvt_term::grab_button (int button, U32 modifiers) |
737 | CODE: |
782 | CODE: |
738 | XGrabButton (THIS->display->display, button, modifiers, THIS->vt, 1, |
783 | XGrabButton (THIS->display->display, button, modifiers, THIS->vt, 1, |
739 | ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask, |
784 | ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask, |
740 | GrabModeSync, GrabModeSync, None, None); |
785 | GrabModeSync, GrabModeSync, None, GRAB_CURSOR); |
741 | |
786 | |
742 | bool |
787 | bool |
743 | rxvt_term::grab (U32 eventtime, int sync = 0) |
788 | rxvt_term::grab (U32 eventtime, int sync = 0) |
744 | CODE: |
789 | CODE: |
745 | { |
790 | { |
… | |
… | |
747 | |
792 | |
748 | THIS->perl.grabtime = 0; |
793 | THIS->perl.grabtime = 0; |
749 | |
794 | |
750 | if (!XGrabPointer (THIS->display->display, THIS->vt, 0, |
795 | if (!XGrabPointer (THIS->display->display, THIS->vt, 0, |
751 | ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask, |
796 | ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask, |
752 | mode, mode, None, None, eventtime)) |
797 | mode, mode, None, GRAB_CURSOR, eventtime)) |
753 | if (!XGrabKeyboard (THIS->display->display, THIS->vt, 0, mode, mode, eventtime)) |
798 | if (!XGrabKeyboard (THIS->display->display, THIS->vt, 0, mode, mode, eventtime)) |
754 | THIS->perl.grabtime = eventtime; |
799 | THIS->perl.grabtime = eventtime; |
755 | else |
800 | else |
756 | XUngrabPointer (THIS->display->display, eventtime); |
801 | XUngrabPointer (THIS->display->display, eventtime); |
757 | |
802 | |
… | |
… | |
759 | } |
804 | } |
760 | OUTPUT: |
805 | OUTPUT: |
761 | RETVAL |
806 | RETVAL |
762 | |
807 | |
763 | void |
808 | void |
764 | rxvt_term::allow_events_async (U32 eventtime = THIS->perl.grabtime) |
809 | rxvt_term::allow_events_async () |
765 | CODE: |
810 | CODE: |
766 | XAllowEvents (THIS->display->display, AsyncBoth, eventtime); |
811 | XAllowEvents (THIS->display->display, AsyncBoth, THIS->perl.grabtime); |
767 | |
812 | |
768 | void |
813 | void |
769 | rxvt_term::allow_events_sync (U32 eventtime = THIS->perl.grabtime) |
814 | rxvt_term::allow_events_sync () |
770 | CODE: |
815 | CODE: |
771 | XAllowEvents (THIS->display->display, SyncBoth, eventtime); |
816 | XAllowEvents (THIS->display->display, SyncBoth, THIS->perl.grabtime); |
772 | |
817 | |
773 | void |
818 | void |
774 | rxvt_term::allow_events_replay (U32 eventtime = THIS->perl.grabtime) |
819 | rxvt_term::allow_events_replay () |
775 | CODE: |
820 | CODE: |
776 | XAllowEvents (THIS->display->display, ReplayPointer, eventtime); |
821 | XAllowEvents (THIS->display->display, ReplayPointer, THIS->perl.grabtime); |
777 | XAllowEvents (THIS->display->display, ReplayKeyboard, eventtime); |
822 | XAllowEvents (THIS->display->display, ReplayKeyboard, THIS->perl.grabtime); |
778 | |
823 | |
779 | void |
824 | void |
780 | rxvt_term::ungrab (U32 eventtime = THIS->perl.grabtime) |
825 | rxvt_term::ungrab () |
781 | CODE: |
826 | CODE: |
782 | THIS->perl.grabtime = 0; |
827 | ungrab (THIS); |
783 | XUngrabKeyboard (THIS->display->display, eventtime); |
|
|
784 | XUngrabPointer (THIS->display->display, eventtime); |
|
|
785 | |
828 | |
786 | int |
829 | int |
787 | rxvt_term::strwidth (SV *str) |
830 | rxvt_term::strwidth (SV *str) |
788 | CODE: |
831 | CODE: |
789 | { |
832 | { |
… | |
… | |
808 | char *mbstr = rxvt_wcstombs (wstr); |
851 | char *mbstr = rxvt_wcstombs (wstr); |
809 | rxvt_pop_locale (); |
852 | rxvt_pop_locale (); |
810 | |
853 | |
811 | free (wstr); |
854 | free (wstr); |
812 | |
855 | |
813 | RETVAL = newSVpv (mbstr, 0); |
856 | RETVAL = taint_if (newSVpv (mbstr, 0), str); |
814 | free (mbstr); |
857 | free (mbstr); |
815 | } |
858 | } |
816 | OUTPUT: |
859 | OUTPUT: |
817 | RETVAL |
860 | RETVAL |
818 | |
861 | |
… | |
… | |
825 | |
868 | |
826 | rxvt_push_locale (THIS->locale); |
869 | rxvt_push_locale (THIS->locale); |
827 | wchar_t *wstr = rxvt_mbstowcs (data, len); |
870 | wchar_t *wstr = rxvt_mbstowcs (data, len); |
828 | rxvt_pop_locale (); |
871 | rxvt_pop_locale (); |
829 | |
872 | |
830 | RETVAL = wcs2sv (wstr); |
873 | RETVAL = taint_if (wcs2sv (wstr), octets); |
831 | free (wstr); |
874 | free (wstr); |
832 | } |
875 | } |
833 | OUTPUT: |
876 | OUTPUT: |
834 | RETVAL |
877 | RETVAL |
835 | |
878 | |
… | |
… | |
942 | wchar_t *wstr = new wchar_t [THIS->ncol]; |
985 | wchar_t *wstr = new wchar_t [THIS->ncol]; |
943 | |
986 | |
944 | for (int col = 0; col < THIS->ncol; col++) |
987 | for (int col = 0; col < THIS->ncol; col++) |
945 | wstr [col] = l.t [col]; |
988 | wstr [col] = l.t [col]; |
946 | |
989 | |
947 | XPUSHs (sv_2mortal (wcs2sv (wstr, THIS->ncol))); |
990 | XPUSHs (taint (sv_2mortal (wcs2sv (wstr, THIS->ncol)))); |
948 | |
991 | |
949 | delete [] wstr; |
992 | delete [] wstr; |
950 | } |
993 | } |
951 | |
994 | |
952 | if (new_text) |
995 | if (new_text) |
… | |
… | |
1073 | else |
1116 | else |
1074 | *r++ = *s; |
1117 | *r++ = *s; |
1075 | |
1118 | |
1076 | rxvt_pop_locale (); |
1119 | rxvt_pop_locale (); |
1077 | |
1120 | |
1078 | RETVAL = wcs2sv (rstr, r - rstr); |
1121 | RETVAL = taint_if (wcs2sv (rstr, r - rstr), string); |
1079 | |
1122 | |
1080 | delete [] rstr; |
1123 | delete [] rstr; |
1081 | } |
1124 | } |
1082 | OUTPUT: |
1125 | OUTPUT: |
1083 | RETVAL |
1126 | RETVAL |
… | |
… | |
1109 | else if (IS_COMPOSE (*s)) |
1152 | else if (IS_COMPOSE (*s)) |
1110 | r += rxvt_composite.expand (*s, r); |
1153 | r += rxvt_composite.expand (*s, r); |
1111 | else |
1154 | else |
1112 | *r++ = *s; |
1155 | *r++ = *s; |
1113 | |
1156 | |
1114 | RETVAL = wcs2sv (rstr, r - rstr); |
1157 | RETVAL = taint_if (wcs2sv (rstr, r - rstr), text); |
1115 | |
1158 | |
1116 | delete [] rstr; |
1159 | delete [] rstr; |
1117 | } |
1160 | } |
1118 | OUTPUT: |
1161 | OUTPUT: |
1119 | RETVAL |
1162 | RETVAL |
… | |
… | |
1141 | |
1184 | |
1142 | if (!IN_RANGE_EXC (index, 0, NUM_RESOURCES)) |
1185 | if (!IN_RANGE_EXC (index, 0, NUM_RESOURCES)) |
1143 | croak ("requested out-of-bound resource %s+%d,", name, index - rs->value); |
1186 | croak ("requested out-of-bound resource %s+%d,", name, index - rs->value); |
1144 | |
1187 | |
1145 | if (GIMME_V != G_VOID) |
1188 | if (GIMME_V != G_VOID) |
1146 | XPUSHs (THIS->rs [index] ? sv_2mortal (newSVpv (THIS->rs [index], 0)) : &PL_sv_undef); |
1189 | XPUSHs (THIS->rs [index] ? sv_2mortal (taint (newSVpv (THIS->rs [index], 0))) : &PL_sv_undef); |
1147 | |
1190 | |
1148 | if (newval) |
1191 | if (newval) |
1149 | { |
1192 | { |
1150 | if (SvOK (newval)) |
1193 | if (SvOK (newval)) |
1151 | { |
1194 | { |
… | |
… | |
1193 | } |
1236 | } |
1194 | OUTPUT: |
1237 | OUTPUT: |
1195 | RETVAL |
1238 | RETVAL |
1196 | |
1239 | |
1197 | void |
1240 | void |
1198 | rxvt_term::cur (...) |
1241 | rxvt_term::screen_cur (...) |
1199 | PROTOTYPE: $;$$ |
1242 | PROTOTYPE: $;$$ |
1200 | ALIAS: |
1243 | ALIAS: |
1201 | screen_cur = 0 |
1244 | screen_cur = 0 |
1202 | selection_beg = 1 |
1245 | selection_beg = 1 |
1203 | selection_end = 2 |
1246 | selection_end = 2 |
… | |
… | |
1232 | void |
1275 | void |
1233 | rxvt_term::selection (SV *newtext = 0) |
1276 | rxvt_term::selection (SV *newtext = 0) |
1234 | PPCODE: |
1277 | PPCODE: |
1235 | { |
1278 | { |
1236 | if (GIMME_V != G_VOID) |
1279 | if (GIMME_V != G_VOID) |
|
|
1280 | XPUSHs (THIS->selection.text |
1237 | XPUSHs (sv_2mortal (wcs2sv (THIS->selection.text, THIS->selection.len))); |
1281 | ? taint (sv_2mortal (wcs2sv (THIS->selection.text, THIS->selection.len))) |
|
|
1282 | : &PL_sv_undef); |
1238 | |
1283 | |
1239 | if (newtext) |
1284 | if (newtext) |
1240 | { |
1285 | { |
1241 | free (THIS->selection.text); |
1286 | free (THIS->selection.text); |
1242 | |
1287 | |