… | |
… | |
26 | #include <XSUB.h> |
26 | #include <XSUB.h> |
27 | #undef line_t |
27 | #undef line_t |
28 | |
28 | |
29 | #include "../config.h" |
29 | #include "../config.h" |
30 | |
30 | |
|
|
31 | #include <cstddef> |
31 | #include <cstdarg> |
32 | #include <cstdarg> |
32 | |
33 | |
33 | #include "rxvt.h" |
34 | #include "rxvt.h" |
34 | #include "iom.h" |
35 | #include "iom.h" |
35 | #include "rxvtutil.h" |
36 | #include "rxvtutil.h" |
36 | #include "rxvtperl.h" |
37 | #include "rxvtperl.h" |
37 | |
38 | |
38 | #include "perlxsi.c" |
39 | #include "perlxsi.c" |
39 | |
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 | |
40 | #undef LINENO |
47 | #undef LINENO |
41 | #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) |
42 | #undef ROW |
49 | #undef ROW |
43 | #define ROW(n) THIS->row_buf [LINENO (n)] |
50 | #define ROW(n) THIS->row_buf [LINENO (n)] |
44 | |
51 | |
45 | ///////////////////////////////////////////////////////////////////////////// |
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 | } |
46 | |
69 | |
47 | static wchar_t * |
70 | static wchar_t * |
48 | sv2wcs (SV *sv) |
71 | sv2wcs (SV *sv) |
49 | { |
72 | { |
50 | STRLEN len; |
73 | STRLEN len; |
… | |
… | |
383 | perl_free (perl); |
406 | perl_free (perl); |
384 | } |
407 | } |
385 | } |
408 | } |
386 | |
409 | |
387 | void |
410 | void |
388 | rxvt_perl_interp::init () |
411 | rxvt_perl_interp::init (bool tainted) |
389 | { |
412 | { |
390 | if (!perl) |
413 | if (!perl) |
391 | { |
414 | { |
392 | char *argv[] = { |
415 | char *argv[] = { |
393 | "", |
416 | "", |
394 | "-edo '" LIBDIR "/urxvt.pm' or ($@ and die $@) or exit 1", |
417 | "-edo '" LIBDIR "/urxvt.pm' or ($@ and die $@) or exit 1", |
|
|
418 | "-T", |
395 | }; |
419 | }; |
396 | |
420 | |
397 | perl = perl_alloc (); |
421 | perl = perl_alloc (); |
398 | perl_construct (perl); |
422 | perl_construct (perl); |
399 | |
423 | |
400 | if (perl_parse (perl, xs_init, 2, argv, (char **)NULL) |
424 | if (perl_parse (perl, xs_init, 2 + !!tainted, argv, (char **)NULL) |
401 | || perl_run (perl)) |
425 | || perl_run (perl)) |
402 | { |
426 | { |
403 | rxvt_warn ("unable to initialize perl-interpreter, continuing without.\n"); |
427 | rxvt_warn ("unable to initialize perl-interpreter, continuing without.\n"); |
404 | |
428 | |
405 | perl_destruct (perl); |
429 | perl_destruct (perl); |
… | |
… | |
466 | case DT_LONG: |
490 | case DT_LONG: |
467 | XPUSHs (sv_2mortal (newSViv (va_arg (ap, long)))); |
491 | XPUSHs (sv_2mortal (newSViv (va_arg (ap, long)))); |
468 | break; |
492 | break; |
469 | |
493 | |
470 | case DT_STR: |
494 | case DT_STR: |
471 | XPUSHs (sv_2mortal (newSVpv (va_arg (ap, char *), 0))); |
495 | XPUSHs (taint (sv_2mortal (newSVpv (va_arg (ap, char *), 0)))); |
472 | break; |
496 | break; |
473 | |
497 | |
474 | case DT_STR_LEN: |
498 | case DT_STR_LEN: |
475 | { |
499 | { |
476 | char *str = va_arg (ap, char *); |
500 | char *str = va_arg (ap, char *); |
477 | int len = va_arg (ap, int); |
501 | int len = va_arg (ap, int); |
478 | |
502 | |
479 | XPUSHs (sv_2mortal (newSVpvn (str, len))); |
503 | XPUSHs (taint (sv_2mortal (newSVpvn (str, len)))); |
480 | } |
504 | } |
481 | break; |
505 | break; |
482 | |
506 | |
483 | case DT_WCS_LEN: |
507 | case DT_WCS_LEN: |
484 | { |
508 | { |
485 | wchar_t *wstr = va_arg (ap, wchar_t *); |
509 | wchar_t *wstr = va_arg (ap, wchar_t *); |
486 | int wlen = va_arg (ap, int); |
510 | int wlen = va_arg (ap, int); |
487 | |
511 | |
488 | XPUSHs (sv_2mortal (wcs2sv (wstr, wlen))); |
512 | XPUSHs (taint (sv_2mortal (wcs2sv (wstr, wlen)))); |
489 | } |
513 | } |
490 | break; |
514 | break; |
491 | |
515 | |
492 | case DT_XEVENT: |
516 | case DT_XEVENT: |
493 | { |
517 | { |
… | |
… | |
583 | |
607 | |
584 | PROTOTYPES: ENABLE |
608 | PROTOTYPES: ENABLE |
585 | |
609 | |
586 | BOOT: |
610 | BOOT: |
587 | { |
611 | { |
588 | HV *stash = gv_stashpv ("urxvt", 1); |
612 | sv_setsv (get_sv ("urxvt::LIBDIR", 1), newSVpvn (LIBDIR, sizeof (LIBDIR) - 1)); |
589 | # define export_const_iv(name) newCONSTSUB (stash, # name, newSViv (name)); |
|
|
590 | |
613 | |
591 | AV *hookname = get_av ("urxvt::HOOKNAME", 1); |
614 | AV *hookname = get_av ("urxvt::HOOKNAME", 1); |
592 | # define def(sym) av_store (hookname, HOOK_ ## sym, newSVpv (# sym, 0)); |
615 | # define def(sym) av_store (hookname, HOOK_ ## sym, newSVpv (# sym, 0)); |
593 | # include "hookinc.h" |
616 | # include "hookinc.h" |
594 | # undef def |
617 | # undef def |
595 | |
618 | |
596 | |
619 | HV *option = get_hv ("urxvt::OPTION", 1); |
|
|
620 | # define def(name,val) hv_store (option, # name, sizeof (# name) - 1, newSVuv (Opt_ ## name), 0); |
|
|
621 | # define nodef(name) |
|
|
622 | # include "optinc.h" |
|
|
623 | # undef nodef |
|
|
624 | # undef def |
|
|
625 | |
|
|
626 | HV *stash = gv_stashpv ("urxvt", 1); |
|
|
627 | # define export_const_iv(name) newCONSTSUB (stash, # name, newSViv (name)); |
597 | export_const_iv (DEFAULT_RSTYLE); |
628 | export_const_iv (DEFAULT_RSTYLE); |
598 | export_const_iv (OVERLAY_RSTYLE); |
629 | export_const_iv (OVERLAY_RSTYLE); |
599 | export_const_iv (RS_Bold); |
630 | export_const_iv (RS_Bold); |
600 | export_const_iv (RS_Italic); |
631 | export_const_iv (RS_Italic); |
601 | export_const_iv (RS_Blink); |
632 | export_const_iv (RS_Blink); |
602 | export_const_iv (RS_RVid); |
633 | export_const_iv (RS_RVid); |
603 | export_const_iv (RS_Uline); |
634 | export_const_iv (RS_Uline); |
|
|
635 | |
604 | export_const_iv (CurrentTime); |
636 | export_const_iv (CurrentTime); |
605 | |
637 | export_const_iv (ShiftMask); |
606 | sv_setsv (get_sv ("urxvt::LIBDIR", 1), newSVpvn (LIBDIR, sizeof (LIBDIR) - 1)); |
638 | export_const_iv (LockMask); |
|
|
639 | export_const_iv (ControlMask); |
|
|
640 | export_const_iv (Mod1Mask); |
|
|
641 | export_const_iv (Mod2Mask); |
|
|
642 | export_const_iv (Mod3Mask); |
|
|
643 | export_const_iv (Mod4Mask); |
|
|
644 | export_const_iv (Mod5Mask); |
|
|
645 | export_const_iv (Button1Mask); |
|
|
646 | export_const_iv (Button2Mask); |
|
|
647 | export_const_iv (Button3Mask); |
|
|
648 | export_const_iv (Button4Mask); |
|
|
649 | export_const_iv (Button5Mask); |
|
|
650 | export_const_iv (AnyModifier); |
607 | } |
651 | } |
608 | |
652 | |
609 | SV * |
653 | SV * |
610 | new (...) |
654 | new (...) |
611 | CODE: |
655 | CODE: |
… | |
… | |
714 | void |
758 | void |
715 | rxvt_term::grab_button (int button, U32 modifiers) |
759 | rxvt_term::grab_button (int button, U32 modifiers) |
716 | CODE: |
760 | CODE: |
717 | XGrabButton (THIS->display->display, button, modifiers, THIS->vt, 1, |
761 | XGrabButton (THIS->display->display, button, modifiers, THIS->vt, 1, |
718 | ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask, |
762 | ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask, |
719 | GrabModeSync, GrabModeSync, None, None); |
763 | GrabModeSync, GrabModeSync, None, GRAB_CURSOR); |
720 | |
764 | |
721 | bool |
765 | bool |
722 | rxvt_term::grab (U32 eventtime, int sync = 0) |
766 | rxvt_term::grab (U32 eventtime, int sync = 0) |
723 | CODE: |
767 | CODE: |
724 | { |
768 | { |
… | |
… | |
726 | |
770 | |
727 | THIS->perl.grabtime = 0; |
771 | THIS->perl.grabtime = 0; |
728 | |
772 | |
729 | if (!XGrabPointer (THIS->display->display, THIS->vt, 0, |
773 | if (!XGrabPointer (THIS->display->display, THIS->vt, 0, |
730 | ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask, |
774 | ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask, |
731 | mode, mode, None, None, eventtime)) |
775 | mode, mode, None, GRAB_CURSOR, eventtime)) |
732 | if (!XGrabKeyboard (THIS->display->display, THIS->vt, 0, mode, mode, eventtime)) |
776 | if (!XGrabKeyboard (THIS->display->display, THIS->vt, 0, mode, mode, eventtime)) |
733 | THIS->perl.grabtime = eventtime; |
777 | THIS->perl.grabtime = eventtime; |
734 | else |
778 | else |
735 | XUngrabPointer (THIS->display->display, eventtime); |
779 | XUngrabPointer (THIS->display->display, eventtime); |
736 | |
780 | |
… | |
… | |
787 | char *mbstr = rxvt_wcstombs (wstr); |
831 | char *mbstr = rxvt_wcstombs (wstr); |
788 | rxvt_pop_locale (); |
832 | rxvt_pop_locale (); |
789 | |
833 | |
790 | free (wstr); |
834 | free (wstr); |
791 | |
835 | |
792 | RETVAL = newSVpv (mbstr, 0); |
836 | RETVAL = taint_if (newSVpv (mbstr, 0), str); |
793 | free (mbstr); |
837 | free (mbstr); |
794 | } |
838 | } |
795 | OUTPUT: |
839 | OUTPUT: |
796 | RETVAL |
840 | RETVAL |
797 | |
841 | |
… | |
… | |
804 | |
848 | |
805 | rxvt_push_locale (THIS->locale); |
849 | rxvt_push_locale (THIS->locale); |
806 | wchar_t *wstr = rxvt_mbstowcs (data, len); |
850 | wchar_t *wstr = rxvt_mbstowcs (data, len); |
807 | rxvt_pop_locale (); |
851 | rxvt_pop_locale (); |
808 | |
852 | |
809 | RETVAL = wcs2sv (wstr); |
853 | RETVAL = taint_if (wcs2sv (wstr), octets); |
810 | free (wstr); |
854 | free (wstr); |
811 | } |
855 | } |
812 | OUTPUT: |
856 | OUTPUT: |
813 | RETVAL |
857 | RETVAL |
814 | |
858 | |
815 | # very portable, especially on objects as opposed to pods |
859 | #define TERM_OFFSET(sym) offsetof (TermWin_t, sym) |
816 | #define TERM_OFFSET(sym) (((char *)&((TermWin_t *)0)->sym) - (char *)(TermWin_t *)0) |
|
|
817 | |
860 | |
818 | #define TERM_OFFSET_width TERM_OFFSET(width) |
861 | #define TERM_OFFSET_width TERM_OFFSET(width) |
819 | #define TERM_OFFSET_height TERM_OFFSET(height) |
862 | #define TERM_OFFSET_height TERM_OFFSET(height) |
820 | #define TERM_OFFSET_fwidth TERM_OFFSET(fwidth) |
863 | #define TERM_OFFSET_fwidth TERM_OFFSET(fwidth) |
821 | #define TERM_OFFSET_fheight TERM_OFFSET(fheight) |
864 | #define TERM_OFFSET_fheight TERM_OFFSET(fheight) |
… | |
… | |
846 | CODE: |
889 | CODE: |
847 | RETVAL = *(int *)((char *)THIS + ix); |
890 | RETVAL = *(int *)((char *)THIS + ix); |
848 | OUTPUT: |
891 | OUTPUT: |
849 | RETVAL |
892 | RETVAL |
850 | |
893 | |
|
|
894 | unsigned int |
|
|
895 | rxvt_term::ModLevel3Mask () |
|
|
896 | ALIAS: |
|
|
897 | ModLevel3Mask = 0 |
|
|
898 | ModMetaMask = 1 |
|
|
899 | ModNumLockMask = 2 |
|
|
900 | CODE: |
|
|
901 | switch (ix) |
|
|
902 | { |
|
|
903 | case 0: RETVAL = THIS->ModLevel3Mask; break; |
|
|
904 | case 1: RETVAL = THIS->ModMetaMask; break; |
|
|
905 | case 2: RETVAL = THIS->ModNumLockMask; break; |
|
|
906 | } |
|
|
907 | OUTPUT: |
|
|
908 | RETVAL |
|
|
909 | |
851 | U32 |
910 | U32 |
852 | rxvt_term::parent () |
911 | rxvt_term::parent () |
853 | CODE: |
912 | CODE: |
854 | RETVAL = (U32)THIS->parent [0]; |
913 | RETVAL = (U32)THIS->parent [0]; |
855 | OUTPUT: |
914 | OUTPUT: |
… | |
… | |
906 | wchar_t *wstr = new wchar_t [THIS->ncol]; |
965 | wchar_t *wstr = new wchar_t [THIS->ncol]; |
907 | |
966 | |
908 | for (int col = 0; col < THIS->ncol; col++) |
967 | for (int col = 0; col < THIS->ncol; col++) |
909 | wstr [col] = l.t [col]; |
968 | wstr [col] = l.t [col]; |
910 | |
969 | |
911 | XPUSHs (sv_2mortal (wcs2sv (wstr, THIS->ncol))); |
970 | XPUSHs (taint (sv_2mortal (wcs2sv (wstr, THIS->ncol)))); |
912 | |
971 | |
913 | delete [] wstr; |
972 | delete [] wstr; |
914 | } |
973 | } |
915 | |
974 | |
916 | if (new_text) |
975 | if (new_text) |
… | |
… | |
1037 | else |
1096 | else |
1038 | *r++ = *s; |
1097 | *r++ = *s; |
1039 | |
1098 | |
1040 | rxvt_pop_locale (); |
1099 | rxvt_pop_locale (); |
1041 | |
1100 | |
1042 | RETVAL = wcs2sv (rstr, r - rstr); |
1101 | RETVAL = taint_if (wcs2sv (rstr, r - rstr), string); |
1043 | |
1102 | |
1044 | delete [] rstr; |
1103 | delete [] rstr; |
1045 | } |
1104 | } |
1046 | OUTPUT: |
1105 | OUTPUT: |
1047 | RETVAL |
1106 | RETVAL |
… | |
… | |
1073 | else if (IS_COMPOSE (*s)) |
1132 | else if (IS_COMPOSE (*s)) |
1074 | r += rxvt_composite.expand (*s, r); |
1133 | r += rxvt_composite.expand (*s, r); |
1075 | else |
1134 | else |
1076 | *r++ = *s; |
1135 | *r++ = *s; |
1077 | |
1136 | |
1078 | RETVAL = wcs2sv (rstr, r - rstr); |
1137 | RETVAL = taint_if (wcs2sv (rstr, r - rstr), text); |
1079 | |
1138 | |
1080 | delete [] rstr; |
1139 | delete [] rstr; |
1081 | } |
1140 | } |
1082 | OUTPUT: |
1141 | OUTPUT: |
1083 | RETVAL |
1142 | RETVAL |
… | |
… | |
1105 | |
1164 | |
1106 | if (!IN_RANGE_EXC (index, 0, NUM_RESOURCES)) |
1165 | if (!IN_RANGE_EXC (index, 0, NUM_RESOURCES)) |
1107 | croak ("requested out-of-bound resource %s+%d,", name, index - rs->value); |
1166 | croak ("requested out-of-bound resource %s+%d,", name, index - rs->value); |
1108 | |
1167 | |
1109 | if (GIMME_V != G_VOID) |
1168 | if (GIMME_V != G_VOID) |
1110 | XPUSHs (THIS->rs [index] ? sv_2mortal (newSVpv (THIS->rs [index], 0)) : &PL_sv_undef); |
1169 | XPUSHs (THIS->rs [index] ? sv_2mortal (taint (newSVpv (THIS->rs [index], 0))) : &PL_sv_undef); |
1111 | |
1170 | |
1112 | if (newval) |
1171 | if (newval) |
1113 | { |
1172 | { |
1114 | if (SvOK (newval)) |
1173 | if (SvOK (newval)) |
1115 | { |
1174 | { |
… | |
… | |
1120 | else |
1179 | else |
1121 | THIS->rs [index] = 0; |
1180 | THIS->rs [index] = 0; |
1122 | } |
1181 | } |
1123 | } |
1182 | } |
1124 | |
1183 | |
|
|
1184 | bool |
|
|
1185 | rxvt_term::option (U32 optval, int set = -1) |
|
|
1186 | CODE: |
|
|
1187 | { |
|
|
1188 | RETVAL = THIS->options & optval; |
|
|
1189 | |
|
|
1190 | if (set >= 0) |
|
|
1191 | { |
|
|
1192 | if (set) |
|
|
1193 | THIS->options |= optval; |
|
|
1194 | else |
|
|
1195 | THIS->options &= ~optval; |
|
|
1196 | |
|
|
1197 | switch (optval) |
|
|
1198 | { |
|
|
1199 | case Opt_skipBuiltinGlyphs: |
|
|
1200 | THIS->set_fonts (); |
|
|
1201 | THIS->scr_remap_chars (); |
|
|
1202 | THIS->scr_touch (true); |
|
|
1203 | THIS->want_refresh = 1; |
|
|
1204 | break; |
|
|
1205 | |
|
|
1206 | case Opt_cursorUnderline: |
|
|
1207 | THIS->want_refresh = 1; |
|
|
1208 | break; |
|
|
1209 | |
|
|
1210 | # case Opt_scrollBar_floating: |
|
|
1211 | # case Opt_scrollBar_right: |
|
|
1212 | # THIS->resize_all_windows (THIS->width, THIS->height, 1); |
|
|
1213 | # break; |
|
|
1214 | } |
|
|
1215 | } |
|
|
1216 | } |
|
|
1217 | OUTPUT: |
|
|
1218 | RETVAL |
|
|
1219 | |
1125 | void |
1220 | void |
1126 | rxvt_term::cur (...) |
1221 | rxvt_term::cur (...) |
1127 | PROTOTYPE: $;$$ |
1222 | PROTOTYPE: $;$$ |
1128 | ALIAS: |
1223 | ALIAS: |
1129 | screen_cur = 0 |
1224 | screen_cur = 0 |
… | |
… | |
1160 | void |
1255 | void |
1161 | rxvt_term::selection (SV *newtext = 0) |
1256 | rxvt_term::selection (SV *newtext = 0) |
1162 | PPCODE: |
1257 | PPCODE: |
1163 | { |
1258 | { |
1164 | if (GIMME_V != G_VOID) |
1259 | if (GIMME_V != G_VOID) |
1165 | XPUSHs (sv_2mortal (wcs2sv (THIS->selection.text, THIS->selection.len))); |
1260 | XPUSHs (taint (sv_2mortal (wcs2sv (THIS->selection.text, THIS->selection.len)))); |
1166 | |
1261 | |
1167 | if (newtext) |
1262 | if (newtext) |
1168 | { |
1263 | { |
1169 | free (THIS->selection.text); |
1264 | free (THIS->selection.text); |
1170 | |
1265 | |