… | |
… | |
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); |
… | |
… | |
590 | |
627 | |
591 | PROTOTYPES: ENABLE |
628 | PROTOTYPES: ENABLE |
592 | |
629 | |
593 | BOOT: |
630 | BOOT: |
594 | { |
631 | { |
595 | sv_setsv (get_sv ("urxvt::LIBDIR", 1), newSVpvn (LIBDIR, sizeof (LIBDIR) - 1)); |
632 | sv_setsv (get_sv ("urxvt::LIBDIR", 1), newSVpvn (LIBDIR, sizeof (LIBDIR) - 1)); |
|
|
633 | sv_setsv (get_sv ("urxvt::RESNAME", 1), newSVpvn (RESNAME, sizeof (RESNAME) - 1)); |
|
|
634 | sv_setsv (get_sv ("urxvt::RESCLASS", 1), newSVpvn (RESCLASS, sizeof (RESCLASS) - 1)); |
|
|
635 | sv_setsv (get_sv ("urxvt::RXVTNAME", 1), newSVpvn (RXVTNAME, sizeof (RXVTNAME) - 1)); |
596 | |
636 | |
597 | AV *hookname = get_av ("urxvt::HOOKNAME", 1); |
637 | AV *hookname = get_av ("urxvt::HOOKNAME", 1); |
598 | # define def(sym) av_store (hookname, HOOK_ ## sym, newSVpv (# sym, 0)); |
638 | # define def(sym) av_store (hookname, HOOK_ ## sym, newSVpv (# sym, 0)); |
599 | # include "hookinc.h" |
639 | # include "hookinc.h" |
600 | # undef def |
640 | # undef def |
… | |
… | |
629 | export_const_iv (Button2Mask); |
669 | export_const_iv (Button2Mask); |
630 | export_const_iv (Button3Mask); |
670 | export_const_iv (Button3Mask); |
631 | export_const_iv (Button4Mask); |
671 | export_const_iv (Button4Mask); |
632 | export_const_iv (Button5Mask); |
672 | export_const_iv (Button5Mask); |
633 | export_const_iv (AnyModifier); |
673 | export_const_iv (AnyModifier); |
|
|
674 | |
|
|
675 | export_const_iv (EVENT_NONE); |
|
|
676 | export_const_iv (EVENT_READ); |
|
|
677 | export_const_iv (EVENT_WRITE); |
634 | } |
678 | } |
635 | |
679 | |
636 | SV * |
680 | SV * |
637 | new (...) |
681 | new (...) |
638 | CODE: |
682 | CODE: |
… | |
… | |
675 | |
719 | |
676 | void |
720 | void |
677 | fatal (const char *msg) |
721 | fatal (const char *msg) |
678 | CODE: |
722 | CODE: |
679 | rxvt_fatal ("%s", msg); |
723 | rxvt_fatal ("%s", msg); |
|
|
724 | |
|
|
725 | SV * |
|
|
726 | untaint (SV *sv) |
|
|
727 | CODE: |
|
|
728 | RETVAL = newSVsv (sv); |
|
|
729 | SvTAINTED_off (RETVAL); |
|
|
730 | OUTPUT: |
|
|
731 | RETVAL |
|
|
732 | |
|
|
733 | bool |
|
|
734 | safe () |
|
|
735 | CODE: |
|
|
736 | RETVAL = !rxvt_tainted (); |
|
|
737 | OUTPUT: |
|
|
738 | RETVAL |
680 | |
739 | |
681 | NV |
740 | NV |
682 | NOW () |
741 | NOW () |
683 | CODE: |
742 | CODE: |
684 | RETVAL = NOW; |
743 | RETVAL = NOW; |
… | |
… | |
765 | } |
824 | } |
766 | OUTPUT: |
825 | OUTPUT: |
767 | RETVAL |
826 | RETVAL |
768 | |
827 | |
769 | void |
828 | void |
770 | rxvt_term::allow_events_async (U32 eventtime = THIS->perl.grabtime) |
829 | rxvt_term::allow_events_async () |
771 | CODE: |
830 | CODE: |
772 | XAllowEvents (THIS->display->display, AsyncBoth, eventtime); |
831 | XAllowEvents (THIS->display->display, AsyncBoth, THIS->perl.grabtime); |
773 | |
832 | |
774 | void |
833 | void |
775 | rxvt_term::allow_events_sync (U32 eventtime = THIS->perl.grabtime) |
834 | rxvt_term::allow_events_sync () |
776 | CODE: |
835 | CODE: |
777 | XAllowEvents (THIS->display->display, SyncBoth, eventtime); |
836 | XAllowEvents (THIS->display->display, SyncBoth, THIS->perl.grabtime); |
778 | |
837 | |
779 | void |
838 | void |
780 | rxvt_term::allow_events_replay (U32 eventtime = THIS->perl.grabtime) |
839 | rxvt_term::allow_events_replay () |
781 | CODE: |
840 | CODE: |
782 | XAllowEvents (THIS->display->display, ReplayPointer, eventtime); |
841 | XAllowEvents (THIS->display->display, ReplayPointer, THIS->perl.grabtime); |
783 | XAllowEvents (THIS->display->display, ReplayKeyboard, eventtime); |
842 | XAllowEvents (THIS->display->display, ReplayKeyboard, THIS->perl.grabtime); |
784 | |
843 | |
785 | void |
844 | void |
786 | rxvt_term::ungrab (U32 eventtime = THIS->perl.grabtime) |
845 | rxvt_term::ungrab () |
787 | CODE: |
846 | CODE: |
788 | THIS->perl.grabtime = 0; |
847 | ungrab (THIS); |
789 | XUngrabKeyboard (THIS->display->display, eventtime); |
|
|
790 | XUngrabPointer (THIS->display->display, eventtime); |
|
|
791 | |
848 | |
792 | int |
849 | int |
793 | rxvt_term::strwidth (SV *str) |
850 | rxvt_term::strwidth (SV *str) |
794 | CODE: |
851 | CODE: |
795 | { |
852 | { |
… | |
… | |
814 | char *mbstr = rxvt_wcstombs (wstr); |
871 | char *mbstr = rxvt_wcstombs (wstr); |
815 | rxvt_pop_locale (); |
872 | rxvt_pop_locale (); |
816 | |
873 | |
817 | free (wstr); |
874 | free (wstr); |
818 | |
875 | |
819 | RETVAL = newSVpv (mbstr, 0); |
876 | RETVAL = taint_if (newSVpv (mbstr, 0), str); |
820 | free (mbstr); |
877 | free (mbstr); |
821 | } |
878 | } |
822 | OUTPUT: |
879 | OUTPUT: |
823 | RETVAL |
880 | RETVAL |
824 | |
881 | |
… | |
… | |
831 | |
888 | |
832 | rxvt_push_locale (THIS->locale); |
889 | rxvt_push_locale (THIS->locale); |
833 | wchar_t *wstr = rxvt_mbstowcs (data, len); |
890 | wchar_t *wstr = rxvt_mbstowcs (data, len); |
834 | rxvt_pop_locale (); |
891 | rxvt_pop_locale (); |
835 | |
892 | |
836 | RETVAL = wcs2sv (wstr); |
893 | RETVAL = taint_if (wcs2sv (wstr), octets); |
837 | free (wstr); |
894 | free (wstr); |
838 | } |
895 | } |
839 | OUTPUT: |
896 | OUTPUT: |
840 | RETVAL |
897 | RETVAL |
841 | |
898 | |
… | |
… | |
888 | case 2: RETVAL = THIS->ModNumLockMask; break; |
945 | case 2: RETVAL = THIS->ModNumLockMask; break; |
889 | } |
946 | } |
890 | OUTPUT: |
947 | OUTPUT: |
891 | RETVAL |
948 | RETVAL |
892 | |
949 | |
|
|
950 | char * |
|
|
951 | rxvt_term::display_id () |
|
|
952 | ALIAS: |
|
|
953 | display_id = 0 |
|
|
954 | locale = 1 |
|
|
955 | CODE: |
|
|
956 | switch (ix) |
|
|
957 | { |
|
|
958 | case 0: RETVAL = THIS->display->id; break; |
|
|
959 | case 1: RETVAL = THIS->locale; break; |
|
|
960 | } |
|
|
961 | OUTPUT: |
|
|
962 | RETVAL |
|
|
963 | |
|
|
964 | int |
|
|
965 | rxvt_term::pty_ev_events (int events = EVENT_UNDEF) |
|
|
966 | CODE: |
|
|
967 | RETVAL = THIS->pty_ev.events; |
|
|
968 | if (events != EVENT_UNDEF) |
|
|
969 | THIS->pty_ev.set (events); |
|
|
970 | OUTPUT: |
|
|
971 | RETVAL |
|
|
972 | |
893 | U32 |
973 | U32 |
894 | rxvt_term::parent () |
974 | rxvt_term::parent () |
895 | CODE: |
975 | CODE: |
896 | RETVAL = (U32)THIS->parent [0]; |
976 | RETVAL = (U32)THIS->parent [0]; |
897 | OUTPUT: |
977 | OUTPUT: |
… | |
… | |
948 | wchar_t *wstr = new wchar_t [THIS->ncol]; |
1028 | wchar_t *wstr = new wchar_t [THIS->ncol]; |
949 | |
1029 | |
950 | for (int col = 0; col < THIS->ncol; col++) |
1030 | for (int col = 0; col < THIS->ncol; col++) |
951 | wstr [col] = l.t [col]; |
1031 | wstr [col] = l.t [col]; |
952 | |
1032 | |
953 | XPUSHs (sv_2mortal (wcs2sv (wstr, THIS->ncol))); |
1033 | XPUSHs (taint (sv_2mortal (wcs2sv (wstr, THIS->ncol)))); |
954 | |
1034 | |
955 | delete [] wstr; |
1035 | delete [] wstr; |
956 | } |
1036 | } |
957 | |
1037 | |
958 | if (new_text) |
1038 | if (new_text) |
… | |
… | |
1079 | else |
1159 | else |
1080 | *r++ = *s; |
1160 | *r++ = *s; |
1081 | |
1161 | |
1082 | rxvt_pop_locale (); |
1162 | rxvt_pop_locale (); |
1083 | |
1163 | |
1084 | RETVAL = wcs2sv (rstr, r - rstr); |
1164 | RETVAL = taint_if (wcs2sv (rstr, r - rstr), string); |
1085 | |
1165 | |
1086 | delete [] rstr; |
1166 | delete [] rstr; |
1087 | } |
1167 | } |
1088 | OUTPUT: |
1168 | OUTPUT: |
1089 | RETVAL |
1169 | RETVAL |
… | |
… | |
1115 | else if (IS_COMPOSE (*s)) |
1195 | else if (IS_COMPOSE (*s)) |
1116 | r += rxvt_composite.expand (*s, r); |
1196 | r += rxvt_composite.expand (*s, r); |
1117 | else |
1197 | else |
1118 | *r++ = *s; |
1198 | *r++ = *s; |
1119 | |
1199 | |
1120 | RETVAL = wcs2sv (rstr, r - rstr); |
1200 | RETVAL = taint_if (wcs2sv (rstr, r - rstr), text); |
1121 | |
1201 | |
1122 | delete [] rstr; |
1202 | delete [] rstr; |
1123 | } |
1203 | } |
1124 | OUTPUT: |
1204 | OUTPUT: |
1125 | RETVAL |
1205 | RETVAL |
… | |
… | |
1147 | |
1227 | |
1148 | if (!IN_RANGE_EXC (index, 0, NUM_RESOURCES)) |
1228 | if (!IN_RANGE_EXC (index, 0, NUM_RESOURCES)) |
1149 | croak ("requested out-of-bound resource %s+%d,", name, index - rs->value); |
1229 | croak ("requested out-of-bound resource %s+%d,", name, index - rs->value); |
1150 | |
1230 | |
1151 | if (GIMME_V != G_VOID) |
1231 | if (GIMME_V != G_VOID) |
1152 | XPUSHs (THIS->rs [index] ? sv_2mortal (newSVpv (THIS->rs [index], 0)) : &PL_sv_undef); |
1232 | XPUSHs (THIS->rs [index] ? sv_2mortal (taint (newSVpv (THIS->rs [index], 0))) : &PL_sv_undef); |
1153 | |
1233 | |
1154 | if (newval) |
1234 | if (newval) |
1155 | { |
1235 | { |
1156 | if (SvOK (newval)) |
1236 | if (SvOK (newval)) |
1157 | { |
1237 | { |
… | |
… | |
1198 | } |
1278 | } |
1199 | } |
1279 | } |
1200 | OUTPUT: |
1280 | OUTPUT: |
1201 | RETVAL |
1281 | RETVAL |
1202 | |
1282 | |
|
|
1283 | bool |
|
|
1284 | rxvt_term::parse_keysym (char *keysym, char *str) |
|
|
1285 | CODE: |
|
|
1286 | RETVAL = 0 < THIS->parse_keysym (keysym, str); |
|
|
1287 | THIS->keyboard->register_done (); |
|
|
1288 | OUTPUT: |
|
|
1289 | RETVAL |
|
|
1290 | |
1203 | void |
1291 | void |
1204 | rxvt_term::cur (...) |
1292 | rxvt_term::screen_cur (...) |
1205 | PROTOTYPE: $;$$ |
1293 | PROTOTYPE: $;$$ |
1206 | ALIAS: |
1294 | ALIAS: |
1207 | screen_cur = 0 |
1295 | screen_cur = 0 |
1208 | selection_beg = 1 |
1296 | selection_beg = 1 |
1209 | selection_end = 2 |
1297 | selection_end = 2 |
… | |
… | |
1238 | void |
1326 | void |
1239 | rxvt_term::selection (SV *newtext = 0) |
1327 | rxvt_term::selection (SV *newtext = 0) |
1240 | PPCODE: |
1328 | PPCODE: |
1241 | { |
1329 | { |
1242 | if (GIMME_V != G_VOID) |
1330 | if (GIMME_V != G_VOID) |
|
|
1331 | XPUSHs (THIS->selection.text |
1243 | XPUSHs (sv_2mortal (wcs2sv (THIS->selection.text, THIS->selection.len))); |
1332 | ? taint (sv_2mortal (wcs2sv (THIS->selection.text, THIS->selection.len))) |
|
|
1333 | : &PL_sv_undef); |
1244 | |
1334 | |
1245 | if (newtext) |
1335 | if (newtext) |
1246 | { |
1336 | { |
1247 | free (THIS->selection.text); |
1337 | free (THIS->selection.text); |
1248 | |
1338 | |
1249 | THIS->selection.text = sv2wcs (newtext); |
1339 | THIS->selection.text = sv2wcs (newtext); |
1250 | THIS->selection.len = wcslen (THIS->selection.text); |
1340 | THIS->selection.len = wcslen (THIS->selection.text); |
1251 | } |
1341 | } |
1252 | } |
1342 | } |
|
|
1343 | |
|
|
1344 | void |
|
|
1345 | 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) |
|
|
1346 | |
|
|
1347 | void |
|
|
1348 | rxvt_term::scr_xor_span (int beg_row, int beg_col, int end_row, int end_col, U32 rstyle = RS_RVid) |
|
|
1349 | |
|
|
1350 | void |
|
|
1351 | rxvt_term::scr_bell () |
1253 | |
1352 | |
1254 | void |
1353 | void |
1255 | rxvt_term::scr_add_lines (SV *string) |
1354 | rxvt_term::scr_add_lines (SV *string) |
1256 | CODE: |
1355 | CODE: |
1257 | { |
1356 | { |