… | |
… | |
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 | |
… | |
… | |
48 | #define LINENO(n) MOD (THIS->term_start + int(n), THIS->total_rows) |
49 | #define LINENO(n) MOD (THIS->term_start + int(n), THIS->total_rows) |
49 | #undef ROW |
50 | #undef ROW |
50 | #define ROW(n) THIS->row_buf [LINENO (n)] |
51 | #define ROW(n) THIS->row_buf [LINENO (n)] |
51 | |
52 | |
52 | ///////////////////////////////////////////////////////////////////////////// |
53 | ///////////////////////////////////////////////////////////////////////////// |
|
|
54 | |
|
|
55 | static SV * |
|
|
56 | taint (SV *sv) |
|
|
57 | { |
|
|
58 | SvTAINT (sv); |
|
|
59 | return sv; |
|
|
60 | } |
|
|
61 | |
|
|
62 | static SV * |
|
|
63 | taint_if (SV *sv, SV *src) |
|
|
64 | { |
|
|
65 | if (SvTAINTED (src)) |
|
|
66 | SvTAINT (sv); |
|
|
67 | |
|
|
68 | return sv; |
|
|
69 | } |
53 | |
70 | |
54 | static wchar_t * |
71 | static wchar_t * |
55 | sv2wcs (SV *sv) |
72 | sv2wcs (SV *sv) |
56 | { |
73 | { |
57 | STRLEN len; |
74 | STRLEN len; |
… | |
… | |
396 | { |
413 | { |
397 | if (!perl) |
414 | if (!perl) |
398 | { |
415 | { |
399 | char *argv[] = { |
416 | char *argv[] = { |
400 | "", |
417 | "", |
|
|
418 | "-T", |
401 | "-edo '" LIBDIR "/urxvt.pm' or ($@ and die $@) or exit 1", |
419 | "-edo '" LIBDIR "/urxvt.pm' or ($@ and die $@) or exit 1", |
402 | }; |
420 | }; |
403 | |
421 | |
404 | perl = perl_alloc (); |
422 | perl = perl_alloc (); |
405 | perl_construct (perl); |
423 | perl_construct (perl); |
406 | |
424 | |
407 | if (perl_parse (perl, xs_init, 2, argv, (char **)NULL) |
425 | if (perl_parse (perl, xs_init, 3, argv, (char **)NULL) |
408 | || perl_run (perl)) |
426 | || perl_run (perl)) |
409 | { |
427 | { |
410 | rxvt_warn ("unable to initialize perl-interpreter, continuing without.\n"); |
428 | rxvt_warn ("unable to initialize perl-interpreter, continuing without.\n"); |
411 | |
429 | |
412 | perl_destruct (perl); |
430 | perl_destruct (perl); |
413 | perl_free (perl); |
431 | perl_free (perl); |
414 | perl = 0; |
432 | perl = 0; |
415 | } |
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; |
416 | } |
445 | } |
417 | } |
446 | } |
418 | |
447 | |
419 | bool |
448 | bool |
420 | rxvt_perl_interp::invoke (rxvt_term *term, hook_type htype, ...) |
449 | rxvt_perl_interp::invoke (rxvt_term *term, hook_type htype, ...) |
… | |
… | |
431 | return false; // perl not initialized for this instance |
460 | return false; // perl not initialized for this instance |
432 | else if (htype == HOOK_DESTROY) |
461 | else if (htype == HOOK_DESTROY) |
433 | { |
462 | { |
434 | // handled later |
463 | // handled later |
435 | } |
464 | } |
436 | else if (htype == HOOK_REFRESH_BEGIN || htype == HOOK_REFRESH_END) |
465 | else |
437 | { |
466 | { |
438 | 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) |
439 | |
|
|
440 | if (HvKEYS (hv)) |
|
|
441 | { |
468 | { |
|
|
469 | HV *hv = (HV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, 0)); |
|
|
470 | |
|
|
471 | if (HvKEYS (hv)) |
|
|
472 | { |
442 | hv_iterinit (hv); |
473 | hv_iterinit (hv); |
443 | |
474 | |
444 | while (HE *he = hv_iternext (hv)) |
475 | while (HE *he = hv_iternext (hv)) |
445 | ((overlay *)SvIV (hv_iterval (hv, he)))->swap (); |
476 | ((overlay *)SvIV (hv_iterval (hv, he)))->swap (); |
|
|
477 | } |
|
|
478 | |
446 | } |
479 | } |
|
|
480 | |
|
|
481 | if (!should_invoke [htype]) |
|
|
482 | return false; |
447 | } |
483 | } |
448 | else if (!should_invoke [htype]) |
|
|
449 | return false; |
|
|
450 | |
484 | |
451 | dSP; |
485 | dSP; |
452 | va_list ap; |
486 | va_list ap; |
453 | |
487 | |
454 | va_start (ap, htype); |
488 | va_start (ap, htype); |
… | |
… | |
473 | case DT_LONG: |
507 | case DT_LONG: |
474 | XPUSHs (sv_2mortal (newSViv (va_arg (ap, long)))); |
508 | XPUSHs (sv_2mortal (newSViv (va_arg (ap, long)))); |
475 | break; |
509 | break; |
476 | |
510 | |
477 | case DT_STR: |
511 | case DT_STR: |
478 | XPUSHs (sv_2mortal (newSVpv (va_arg (ap, char *), 0))); |
512 | XPUSHs (taint (sv_2mortal (newSVpv (va_arg (ap, char *), 0)))); |
479 | break; |
513 | break; |
480 | |
514 | |
481 | case DT_STR_LEN: |
515 | case DT_STR_LEN: |
482 | { |
516 | { |
483 | char *str = va_arg (ap, char *); |
517 | char *str = va_arg (ap, char *); |
484 | int len = va_arg (ap, int); |
518 | int len = va_arg (ap, int); |
485 | |
519 | |
486 | XPUSHs (sv_2mortal (newSVpvn (str, len))); |
520 | XPUSHs (taint (sv_2mortal (newSVpvn (str, len)))); |
487 | } |
521 | } |
488 | break; |
522 | break; |
489 | |
523 | |
490 | case DT_WCS_LEN: |
524 | case DT_WCS_LEN: |
491 | { |
525 | { |
492 | wchar_t *wstr = va_arg (ap, wchar_t *); |
526 | wchar_t *wstr = va_arg (ap, wchar_t *); |
493 | int wlen = va_arg (ap, int); |
527 | int wlen = va_arg (ap, int); |
494 | |
528 | |
495 | XPUSHs (sv_2mortal (wcs2sv (wstr, wlen))); |
529 | XPUSHs (taint (sv_2mortal (wcs2sv (wstr, wlen)))); |
496 | } |
530 | } |
497 | break; |
531 | break; |
498 | |
532 | |
499 | case DT_XEVENT: |
533 | case DT_XEVENT: |
500 | { |
534 | { |
… | |
… | |
565 | PUTBACK; |
599 | PUTBACK; |
566 | FREETMPS; |
600 | FREETMPS; |
567 | LEAVE; |
601 | LEAVE; |
568 | |
602 | |
569 | if (SvTRUE (ERRSV)) |
603 | if (SvTRUE (ERRSV)) |
|
|
604 | { |
570 | 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 | } |
571 | |
608 | |
572 | if (htype == HOOK_DESTROY) |
609 | if (htype == HOOK_DESTROY) |
573 | { |
610 | { |
574 | clearSVptr ((SV *)term->perl.self); |
611 | clearSVptr ((SV *)term->perl.self); |
575 | SvREFCNT_dec ((SV *)term->perl.self); |
612 | SvREFCNT_dec ((SV *)term->perl.self); |
… | |
… | |
629 | export_const_iv (Button2Mask); |
666 | export_const_iv (Button2Mask); |
630 | export_const_iv (Button3Mask); |
667 | export_const_iv (Button3Mask); |
631 | export_const_iv (Button4Mask); |
668 | export_const_iv (Button4Mask); |
632 | export_const_iv (Button5Mask); |
669 | export_const_iv (Button5Mask); |
633 | 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); |
634 | } |
675 | } |
635 | |
676 | |
636 | SV * |
677 | SV * |
637 | new (...) |
678 | new (...) |
638 | CODE: |
679 | CODE: |
… | |
… | |
675 | |
716 | |
676 | void |
717 | void |
677 | fatal (const char *msg) |
718 | fatal (const char *msg) |
678 | CODE: |
719 | CODE: |
679 | 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 |
680 | |
736 | |
681 | NV |
737 | NV |
682 | NOW () |
738 | NOW () |
683 | CODE: |
739 | CODE: |
684 | RETVAL = NOW; |
740 | RETVAL = NOW; |
… | |
… | |
765 | } |
821 | } |
766 | OUTPUT: |
822 | OUTPUT: |
767 | RETVAL |
823 | RETVAL |
768 | |
824 | |
769 | void |
825 | void |
770 | rxvt_term::allow_events_async (U32 eventtime = THIS->perl.grabtime) |
826 | rxvt_term::allow_events_async () |
771 | CODE: |
827 | CODE: |
772 | XAllowEvents (THIS->display->display, AsyncBoth, eventtime); |
828 | XAllowEvents (THIS->display->display, AsyncBoth, THIS->perl.grabtime); |
773 | |
829 | |
774 | void |
830 | void |
775 | rxvt_term::allow_events_sync (U32 eventtime = THIS->perl.grabtime) |
831 | rxvt_term::allow_events_sync () |
776 | CODE: |
832 | CODE: |
777 | XAllowEvents (THIS->display->display, SyncBoth, eventtime); |
833 | XAllowEvents (THIS->display->display, SyncBoth, THIS->perl.grabtime); |
778 | |
834 | |
779 | void |
835 | void |
780 | rxvt_term::allow_events_replay (U32 eventtime = THIS->perl.grabtime) |
836 | rxvt_term::allow_events_replay () |
781 | CODE: |
837 | CODE: |
782 | XAllowEvents (THIS->display->display, ReplayPointer, eventtime); |
838 | XAllowEvents (THIS->display->display, ReplayPointer, THIS->perl.grabtime); |
783 | XAllowEvents (THIS->display->display, ReplayKeyboard, eventtime); |
839 | XAllowEvents (THIS->display->display, ReplayKeyboard, THIS->perl.grabtime); |
784 | |
840 | |
785 | void |
841 | void |
786 | rxvt_term::ungrab (U32 eventtime = THIS->perl.grabtime) |
842 | rxvt_term::ungrab () |
787 | CODE: |
843 | CODE: |
788 | THIS->perl.grabtime = 0; |
844 | ungrab (THIS); |
789 | XUngrabKeyboard (THIS->display->display, eventtime); |
|
|
790 | XUngrabPointer (THIS->display->display, eventtime); |
|
|
791 | |
845 | |
792 | int |
846 | int |
793 | rxvt_term::strwidth (SV *str) |
847 | rxvt_term::strwidth (SV *str) |
794 | CODE: |
848 | CODE: |
795 | { |
849 | { |
… | |
… | |
814 | char *mbstr = rxvt_wcstombs (wstr); |
868 | char *mbstr = rxvt_wcstombs (wstr); |
815 | rxvt_pop_locale (); |
869 | rxvt_pop_locale (); |
816 | |
870 | |
817 | free (wstr); |
871 | free (wstr); |
818 | |
872 | |
819 | RETVAL = newSVpv (mbstr, 0); |
873 | RETVAL = taint_if (newSVpv (mbstr, 0), str); |
820 | free (mbstr); |
874 | free (mbstr); |
821 | } |
875 | } |
822 | OUTPUT: |
876 | OUTPUT: |
823 | RETVAL |
877 | RETVAL |
824 | |
878 | |
… | |
… | |
831 | |
885 | |
832 | rxvt_push_locale (THIS->locale); |
886 | rxvt_push_locale (THIS->locale); |
833 | wchar_t *wstr = rxvt_mbstowcs (data, len); |
887 | wchar_t *wstr = rxvt_mbstowcs (data, len); |
834 | rxvt_pop_locale (); |
888 | rxvt_pop_locale (); |
835 | |
889 | |
836 | RETVAL = wcs2sv (wstr); |
890 | RETVAL = taint_if (wcs2sv (wstr), octets); |
837 | free (wstr); |
891 | free (wstr); |
838 | } |
892 | } |
839 | OUTPUT: |
893 | OUTPUT: |
840 | RETVAL |
894 | RETVAL |
841 | |
895 | |
… | |
… | |
888 | case 2: RETVAL = THIS->ModNumLockMask; break; |
942 | case 2: RETVAL = THIS->ModNumLockMask; break; |
889 | } |
943 | } |
890 | OUTPUT: |
944 | OUTPUT: |
891 | RETVAL |
945 | RETVAL |
892 | |
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 | |
893 | U32 |
970 | U32 |
894 | rxvt_term::parent () |
971 | rxvt_term::parent () |
895 | CODE: |
972 | CODE: |
896 | RETVAL = (U32)THIS->parent [0]; |
973 | RETVAL = (U32)THIS->parent [0]; |
897 | OUTPUT: |
974 | OUTPUT: |
… | |
… | |
948 | wchar_t *wstr = new wchar_t [THIS->ncol]; |
1025 | wchar_t *wstr = new wchar_t [THIS->ncol]; |
949 | |
1026 | |
950 | for (int col = 0; col < THIS->ncol; col++) |
1027 | for (int col = 0; col < THIS->ncol; col++) |
951 | wstr [col] = l.t [col]; |
1028 | wstr [col] = l.t [col]; |
952 | |
1029 | |
953 | XPUSHs (sv_2mortal (wcs2sv (wstr, THIS->ncol))); |
1030 | XPUSHs (taint (sv_2mortal (wcs2sv (wstr, THIS->ncol)))); |
954 | |
1031 | |
955 | delete [] wstr; |
1032 | delete [] wstr; |
956 | } |
1033 | } |
957 | |
1034 | |
958 | if (new_text) |
1035 | if (new_text) |
… | |
… | |
1079 | else |
1156 | else |
1080 | *r++ = *s; |
1157 | *r++ = *s; |
1081 | |
1158 | |
1082 | rxvt_pop_locale (); |
1159 | rxvt_pop_locale (); |
1083 | |
1160 | |
1084 | RETVAL = wcs2sv (rstr, r - rstr); |
1161 | RETVAL = taint_if (wcs2sv (rstr, r - rstr), string); |
1085 | |
1162 | |
1086 | delete [] rstr; |
1163 | delete [] rstr; |
1087 | } |
1164 | } |
1088 | OUTPUT: |
1165 | OUTPUT: |
1089 | RETVAL |
1166 | RETVAL |
… | |
… | |
1115 | else if (IS_COMPOSE (*s)) |
1192 | else if (IS_COMPOSE (*s)) |
1116 | r += rxvt_composite.expand (*s, r); |
1193 | r += rxvt_composite.expand (*s, r); |
1117 | else |
1194 | else |
1118 | *r++ = *s; |
1195 | *r++ = *s; |
1119 | |
1196 | |
1120 | RETVAL = wcs2sv (rstr, r - rstr); |
1197 | RETVAL = taint_if (wcs2sv (rstr, r - rstr), text); |
1121 | |
1198 | |
1122 | delete [] rstr; |
1199 | delete [] rstr; |
1123 | } |
1200 | } |
1124 | OUTPUT: |
1201 | OUTPUT: |
1125 | RETVAL |
1202 | RETVAL |
… | |
… | |
1147 | |
1224 | |
1148 | if (!IN_RANGE_EXC (index, 0, NUM_RESOURCES)) |
1225 | if (!IN_RANGE_EXC (index, 0, NUM_RESOURCES)) |
1149 | croak ("requested out-of-bound resource %s+%d,", name, index - rs->value); |
1226 | croak ("requested out-of-bound resource %s+%d,", name, index - rs->value); |
1150 | |
1227 | |
1151 | if (GIMME_V != G_VOID) |
1228 | if (GIMME_V != G_VOID) |
1152 | XPUSHs (THIS->rs [index] ? sv_2mortal (newSVpv (THIS->rs [index], 0)) : &PL_sv_undef); |
1229 | XPUSHs (THIS->rs [index] ? sv_2mortal (taint (newSVpv (THIS->rs [index], 0))) : &PL_sv_undef); |
1153 | |
1230 | |
1154 | if (newval) |
1231 | if (newval) |
1155 | { |
1232 | { |
1156 | if (SvOK (newval)) |
1233 | if (SvOK (newval)) |
1157 | { |
1234 | { |
… | |
… | |
1198 | } |
1275 | } |
1199 | } |
1276 | } |
1200 | OUTPUT: |
1277 | OUTPUT: |
1201 | RETVAL |
1278 | RETVAL |
1202 | |
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 | |
1203 | void |
1288 | void |
1204 | rxvt_term::cur (...) |
1289 | rxvt_term::screen_cur (...) |
1205 | PROTOTYPE: $;$$ |
1290 | PROTOTYPE: $;$$ |
1206 | ALIAS: |
1291 | ALIAS: |
1207 | screen_cur = 0 |
1292 | screen_cur = 0 |
1208 | selection_beg = 1 |
1293 | selection_beg = 1 |
1209 | selection_end = 2 |
1294 | selection_end = 2 |
… | |
… | |
1238 | void |
1323 | void |
1239 | rxvt_term::selection (SV *newtext = 0) |
1324 | rxvt_term::selection (SV *newtext = 0) |
1240 | PPCODE: |
1325 | PPCODE: |
1241 | { |
1326 | { |
1242 | if (GIMME_V != G_VOID) |
1327 | if (GIMME_V != G_VOID) |
|
|
1328 | XPUSHs (THIS->selection.text |
1243 | XPUSHs (sv_2mortal (wcs2sv (THIS->selection.text, THIS->selection.len))); |
1329 | ? taint (sv_2mortal (wcs2sv (THIS->selection.text, THIS->selection.len))) |
|
|
1330 | : &PL_sv_undef); |
1244 | |
1331 | |
1245 | if (newtext) |
1332 | if (newtext) |
1246 | { |
1333 | { |
1247 | free (THIS->selection.text); |
1334 | free (THIS->selection.text); |
1248 | |
1335 | |
1249 | THIS->selection.text = sv2wcs (newtext); |
1336 | THIS->selection.text = sv2wcs (newtext); |
1250 | THIS->selection.len = wcslen (THIS->selection.text); |
1337 | THIS->selection.len = wcslen (THIS->selection.text); |
1251 | } |
1338 | } |
1252 | } |
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 () |
1253 | |
1349 | |
1254 | void |
1350 | void |
1255 | rxvt_term::scr_add_lines (SV *string) |
1351 | rxvt_term::scr_add_lines (SV *string) |
1256 | CODE: |
1352 | CODE: |
1257 | { |
1353 | { |