… | |
… | |
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 | |
|
|
720 | bool |
|
|
721 | safe () |
|
|
722 | CODE: |
|
|
723 | RETVAL = !rxvt_tainted (); |
|
|
724 | OUTPUT: |
|
|
725 | RETVAL |
|
|
726 | |
675 | NV |
727 | NV |
676 | NOW () |
728 | NOW () |
677 | CODE: |
729 | CODE: |
678 | RETVAL = NOW; |
730 | RETVAL = NOW; |
679 | OUTPUT: |
731 | OUTPUT: |
… | |
… | |
735 | void |
787 | void |
736 | rxvt_term::grab_button (int button, U32 modifiers) |
788 | rxvt_term::grab_button (int button, U32 modifiers) |
737 | CODE: |
789 | CODE: |
738 | XGrabButton (THIS->display->display, button, modifiers, THIS->vt, 1, |
790 | XGrabButton (THIS->display->display, button, modifiers, THIS->vt, 1, |
739 | ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask, |
791 | ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask, |
740 | GrabModeSync, GrabModeSync, None, None); |
792 | GrabModeSync, GrabModeSync, None, GRAB_CURSOR); |
741 | |
793 | |
742 | bool |
794 | bool |
743 | rxvt_term::grab (U32 eventtime, int sync = 0) |
795 | rxvt_term::grab (U32 eventtime, int sync = 0) |
744 | CODE: |
796 | CODE: |
745 | { |
797 | { |
… | |
… | |
747 | |
799 | |
748 | THIS->perl.grabtime = 0; |
800 | THIS->perl.grabtime = 0; |
749 | |
801 | |
750 | if (!XGrabPointer (THIS->display->display, THIS->vt, 0, |
802 | if (!XGrabPointer (THIS->display->display, THIS->vt, 0, |
751 | ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask, |
803 | ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask, |
752 | mode, mode, None, None, eventtime)) |
804 | mode, mode, None, GRAB_CURSOR, eventtime)) |
753 | if (!XGrabKeyboard (THIS->display->display, THIS->vt, 0, mode, mode, eventtime)) |
805 | if (!XGrabKeyboard (THIS->display->display, THIS->vt, 0, mode, mode, eventtime)) |
754 | THIS->perl.grabtime = eventtime; |
806 | THIS->perl.grabtime = eventtime; |
755 | else |
807 | else |
756 | XUngrabPointer (THIS->display->display, eventtime); |
808 | XUngrabPointer (THIS->display->display, eventtime); |
757 | |
809 | |
… | |
… | |
759 | } |
811 | } |
760 | OUTPUT: |
812 | OUTPUT: |
761 | RETVAL |
813 | RETVAL |
762 | |
814 | |
763 | void |
815 | void |
764 | rxvt_term::allow_events_async (U32 eventtime = THIS->perl.grabtime) |
816 | rxvt_term::allow_events_async () |
765 | CODE: |
817 | CODE: |
766 | XAllowEvents (THIS->display->display, AsyncBoth, eventtime); |
818 | XAllowEvents (THIS->display->display, AsyncBoth, THIS->perl.grabtime); |
767 | |
819 | |
768 | void |
820 | void |
769 | rxvt_term::allow_events_sync (U32 eventtime = THIS->perl.grabtime) |
821 | rxvt_term::allow_events_sync () |
770 | CODE: |
822 | CODE: |
771 | XAllowEvents (THIS->display->display, SyncBoth, eventtime); |
823 | XAllowEvents (THIS->display->display, SyncBoth, THIS->perl.grabtime); |
772 | |
824 | |
773 | void |
825 | void |
774 | rxvt_term::allow_events_replay (U32 eventtime = THIS->perl.grabtime) |
826 | rxvt_term::allow_events_replay () |
775 | CODE: |
827 | CODE: |
776 | XAllowEvents (THIS->display->display, ReplayPointer, eventtime); |
828 | XAllowEvents (THIS->display->display, ReplayPointer, THIS->perl.grabtime); |
777 | XAllowEvents (THIS->display->display, ReplayKeyboard, eventtime); |
829 | XAllowEvents (THIS->display->display, ReplayKeyboard, THIS->perl.grabtime); |
778 | |
830 | |
779 | void |
831 | void |
780 | rxvt_term::ungrab (U32 eventtime = THIS->perl.grabtime) |
832 | rxvt_term::ungrab () |
781 | CODE: |
833 | CODE: |
782 | THIS->perl.grabtime = 0; |
834 | ungrab (THIS); |
783 | XUngrabKeyboard (THIS->display->display, eventtime); |
|
|
784 | XUngrabPointer (THIS->display->display, eventtime); |
|
|
785 | |
835 | |
786 | int |
836 | int |
787 | rxvt_term::strwidth (SV *str) |
837 | rxvt_term::strwidth (SV *str) |
788 | CODE: |
838 | CODE: |
789 | { |
839 | { |
… | |
… | |
808 | char *mbstr = rxvt_wcstombs (wstr); |
858 | char *mbstr = rxvt_wcstombs (wstr); |
809 | rxvt_pop_locale (); |
859 | rxvt_pop_locale (); |
810 | |
860 | |
811 | free (wstr); |
861 | free (wstr); |
812 | |
862 | |
813 | RETVAL = newSVpv (mbstr, 0); |
863 | RETVAL = taint_if (newSVpv (mbstr, 0), str); |
814 | free (mbstr); |
864 | free (mbstr); |
815 | } |
865 | } |
816 | OUTPUT: |
866 | OUTPUT: |
817 | RETVAL |
867 | RETVAL |
818 | |
868 | |
… | |
… | |
825 | |
875 | |
826 | rxvt_push_locale (THIS->locale); |
876 | rxvt_push_locale (THIS->locale); |
827 | wchar_t *wstr = rxvt_mbstowcs (data, len); |
877 | wchar_t *wstr = rxvt_mbstowcs (data, len); |
828 | rxvt_pop_locale (); |
878 | rxvt_pop_locale (); |
829 | |
879 | |
830 | RETVAL = wcs2sv (wstr); |
880 | RETVAL = taint_if (wcs2sv (wstr), octets); |
831 | free (wstr); |
881 | free (wstr); |
832 | } |
882 | } |
833 | OUTPUT: |
883 | OUTPUT: |
834 | RETVAL |
884 | RETVAL |
835 | |
885 | |
… | |
… | |
882 | case 2: RETVAL = THIS->ModNumLockMask; break; |
932 | case 2: RETVAL = THIS->ModNumLockMask; break; |
883 | } |
933 | } |
884 | OUTPUT: |
934 | OUTPUT: |
885 | RETVAL |
935 | RETVAL |
886 | |
936 | |
|
|
937 | char * |
|
|
938 | rxvt_term::display_id () |
|
|
939 | CODE: |
|
|
940 | RETVAL = THIS->display->id; |
|
|
941 | OUTPUT: |
|
|
942 | RETVAL |
|
|
943 | |
887 | U32 |
944 | U32 |
888 | rxvt_term::parent () |
945 | rxvt_term::parent () |
889 | CODE: |
946 | CODE: |
890 | RETVAL = (U32)THIS->parent [0]; |
947 | RETVAL = (U32)THIS->parent [0]; |
891 | OUTPUT: |
948 | OUTPUT: |
… | |
… | |
942 | wchar_t *wstr = new wchar_t [THIS->ncol]; |
999 | wchar_t *wstr = new wchar_t [THIS->ncol]; |
943 | |
1000 | |
944 | for (int col = 0; col < THIS->ncol; col++) |
1001 | for (int col = 0; col < THIS->ncol; col++) |
945 | wstr [col] = l.t [col]; |
1002 | wstr [col] = l.t [col]; |
946 | |
1003 | |
947 | XPUSHs (sv_2mortal (wcs2sv (wstr, THIS->ncol))); |
1004 | XPUSHs (taint (sv_2mortal (wcs2sv (wstr, THIS->ncol)))); |
948 | |
1005 | |
949 | delete [] wstr; |
1006 | delete [] wstr; |
950 | } |
1007 | } |
951 | |
1008 | |
952 | if (new_text) |
1009 | if (new_text) |
… | |
… | |
1073 | else |
1130 | else |
1074 | *r++ = *s; |
1131 | *r++ = *s; |
1075 | |
1132 | |
1076 | rxvt_pop_locale (); |
1133 | rxvt_pop_locale (); |
1077 | |
1134 | |
1078 | RETVAL = wcs2sv (rstr, r - rstr); |
1135 | RETVAL = taint_if (wcs2sv (rstr, r - rstr), string); |
1079 | |
1136 | |
1080 | delete [] rstr; |
1137 | delete [] rstr; |
1081 | } |
1138 | } |
1082 | OUTPUT: |
1139 | OUTPUT: |
1083 | RETVAL |
1140 | RETVAL |
… | |
… | |
1109 | else if (IS_COMPOSE (*s)) |
1166 | else if (IS_COMPOSE (*s)) |
1110 | r += rxvt_composite.expand (*s, r); |
1167 | r += rxvt_composite.expand (*s, r); |
1111 | else |
1168 | else |
1112 | *r++ = *s; |
1169 | *r++ = *s; |
1113 | |
1170 | |
1114 | RETVAL = wcs2sv (rstr, r - rstr); |
1171 | RETVAL = taint_if (wcs2sv (rstr, r - rstr), text); |
1115 | |
1172 | |
1116 | delete [] rstr; |
1173 | delete [] rstr; |
1117 | } |
1174 | } |
1118 | OUTPUT: |
1175 | OUTPUT: |
1119 | RETVAL |
1176 | RETVAL |
… | |
… | |
1141 | |
1198 | |
1142 | if (!IN_RANGE_EXC (index, 0, NUM_RESOURCES)) |
1199 | if (!IN_RANGE_EXC (index, 0, NUM_RESOURCES)) |
1143 | croak ("requested out-of-bound resource %s+%d,", name, index - rs->value); |
1200 | croak ("requested out-of-bound resource %s+%d,", name, index - rs->value); |
1144 | |
1201 | |
1145 | if (GIMME_V != G_VOID) |
1202 | if (GIMME_V != G_VOID) |
1146 | XPUSHs (THIS->rs [index] ? sv_2mortal (newSVpv (THIS->rs [index], 0)) : &PL_sv_undef); |
1203 | XPUSHs (THIS->rs [index] ? sv_2mortal (taint (newSVpv (THIS->rs [index], 0))) : &PL_sv_undef); |
1147 | |
1204 | |
1148 | if (newval) |
1205 | if (newval) |
1149 | { |
1206 | { |
1150 | if (SvOK (newval)) |
1207 | if (SvOK (newval)) |
1151 | { |
1208 | { |
… | |
… | |
1193 | } |
1250 | } |
1194 | OUTPUT: |
1251 | OUTPUT: |
1195 | RETVAL |
1252 | RETVAL |
1196 | |
1253 | |
1197 | void |
1254 | void |
1198 | rxvt_term::cur (...) |
1255 | rxvt_term::screen_cur (...) |
1199 | PROTOTYPE: $;$$ |
1256 | PROTOTYPE: $;$$ |
1200 | ALIAS: |
1257 | ALIAS: |
1201 | screen_cur = 0 |
1258 | screen_cur = 0 |
1202 | selection_beg = 1 |
1259 | selection_beg = 1 |
1203 | selection_end = 2 |
1260 | selection_end = 2 |
… | |
… | |
1232 | void |
1289 | void |
1233 | rxvt_term::selection (SV *newtext = 0) |
1290 | rxvt_term::selection (SV *newtext = 0) |
1234 | PPCODE: |
1291 | PPCODE: |
1235 | { |
1292 | { |
1236 | if (GIMME_V != G_VOID) |
1293 | if (GIMME_V != G_VOID) |
|
|
1294 | XPUSHs (THIS->selection.text |
1237 | XPUSHs (sv_2mortal (wcs2sv (THIS->selection.text, THIS->selection.len))); |
1295 | ? taint (sv_2mortal (wcs2sv (THIS->selection.text, THIS->selection.len))) |
|
|
1296 | : &PL_sv_undef); |
1238 | |
1297 | |
1239 | if (newtext) |
1298 | if (newtext) |
1240 | { |
1299 | { |
1241 | free (THIS->selection.text); |
1300 | free (THIS->selection.text); |
1242 | |
1301 | |