… | |
… | |
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; |
… | |
… | |
384 | perl_free (perl); |
406 | perl_free (perl); |
385 | } |
407 | } |
386 | } |
408 | } |
387 | |
409 | |
388 | void |
410 | void |
389 | rxvt_perl_interp::init () |
411 | rxvt_perl_interp::init (bool tainted) |
390 | { |
412 | { |
391 | if (!perl) |
413 | if (!perl) |
392 | { |
414 | { |
393 | char *argv[] = { |
415 | char *argv[] = { |
394 | "", |
416 | "", |
395 | "-edo '" LIBDIR "/urxvt.pm' or ($@ and die $@) or exit 1", |
417 | "-edo '" LIBDIR "/urxvt.pm' or ($@ and die $@) or exit 1", |
|
|
418 | "-T", |
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, 2 + !!tainted, 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); |
… | |
… | |
467 | case DT_LONG: |
490 | case DT_LONG: |
468 | XPUSHs (sv_2mortal (newSViv (va_arg (ap, long)))); |
491 | XPUSHs (sv_2mortal (newSViv (va_arg (ap, long)))); |
469 | break; |
492 | break; |
470 | |
493 | |
471 | case DT_STR: |
494 | case DT_STR: |
472 | XPUSHs (sv_2mortal (newSVpv (va_arg (ap, char *), 0))); |
495 | XPUSHs (taint (sv_2mortal (newSVpv (va_arg (ap, char *), 0)))); |
473 | break; |
496 | break; |
474 | |
497 | |
475 | case DT_STR_LEN: |
498 | case DT_STR_LEN: |
476 | { |
499 | { |
477 | char *str = va_arg (ap, char *); |
500 | char *str = va_arg (ap, char *); |
478 | int len = va_arg (ap, int); |
501 | int len = va_arg (ap, int); |
479 | |
502 | |
480 | XPUSHs (sv_2mortal (newSVpvn (str, len))); |
503 | XPUSHs (taint (sv_2mortal (newSVpvn (str, len)))); |
481 | } |
504 | } |
482 | break; |
505 | break; |
483 | |
506 | |
484 | case DT_WCS_LEN: |
507 | case DT_WCS_LEN: |
485 | { |
508 | { |
486 | wchar_t *wstr = va_arg (ap, wchar_t *); |
509 | wchar_t *wstr = va_arg (ap, wchar_t *); |
487 | int wlen = va_arg (ap, int); |
510 | int wlen = va_arg (ap, int); |
488 | |
511 | |
489 | XPUSHs (sv_2mortal (wcs2sv (wstr, wlen))); |
512 | XPUSHs (taint (sv_2mortal (wcs2sv (wstr, wlen)))); |
490 | } |
513 | } |
491 | break; |
514 | break; |
492 | |
515 | |
493 | case DT_XEVENT: |
516 | case DT_XEVENT: |
494 | { |
517 | { |
… | |
… | |
584 | |
607 | |
585 | PROTOTYPES: ENABLE |
608 | PROTOTYPES: ENABLE |
586 | |
609 | |
587 | BOOT: |
610 | BOOT: |
588 | { |
611 | { |
589 | HV *stash = gv_stashpv ("urxvt", 1); |
612 | sv_setsv (get_sv ("urxvt::LIBDIR", 1), newSVpvn (LIBDIR, sizeof (LIBDIR) - 1)); |
590 | # define export_const_iv(name) newCONSTSUB (stash, # name, newSViv (name)); |
|
|
591 | |
613 | |
592 | AV *hookname = get_av ("urxvt::HOOKNAME", 1); |
614 | AV *hookname = get_av ("urxvt::HOOKNAME", 1); |
593 | # define def(sym) av_store (hookname, HOOK_ ## sym, newSVpv (# sym, 0)); |
615 | # define def(sym) av_store (hookname, HOOK_ ## sym, newSVpv (# sym, 0)); |
594 | # include "hookinc.h" |
616 | # include "hookinc.h" |
595 | # undef def |
617 | # undef def |
596 | |
618 | |
597 | |
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)); |
598 | export_const_iv (DEFAULT_RSTYLE); |
628 | export_const_iv (DEFAULT_RSTYLE); |
599 | export_const_iv (OVERLAY_RSTYLE); |
629 | export_const_iv (OVERLAY_RSTYLE); |
600 | export_const_iv (RS_Bold); |
630 | export_const_iv (RS_Bold); |
601 | export_const_iv (RS_Italic); |
631 | export_const_iv (RS_Italic); |
602 | export_const_iv (RS_Blink); |
632 | export_const_iv (RS_Blink); |
… | |
… | |
616 | export_const_iv (Button2Mask); |
646 | export_const_iv (Button2Mask); |
617 | export_const_iv (Button3Mask); |
647 | export_const_iv (Button3Mask); |
618 | export_const_iv (Button4Mask); |
648 | export_const_iv (Button4Mask); |
619 | export_const_iv (Button5Mask); |
649 | export_const_iv (Button5Mask); |
620 | export_const_iv (AnyModifier); |
650 | export_const_iv (AnyModifier); |
621 | |
|
|
622 | sv_setsv (get_sv ("urxvt::LIBDIR", 1), newSVpvn (LIBDIR, sizeof (LIBDIR) - 1)); |
|
|
623 | } |
651 | } |
624 | |
652 | |
625 | SV * |
653 | SV * |
626 | new (...) |
654 | new (...) |
627 | CODE: |
655 | CODE: |
… | |
… | |
730 | void |
758 | void |
731 | rxvt_term::grab_button (int button, U32 modifiers) |
759 | rxvt_term::grab_button (int button, U32 modifiers) |
732 | CODE: |
760 | CODE: |
733 | XGrabButton (THIS->display->display, button, modifiers, THIS->vt, 1, |
761 | XGrabButton (THIS->display->display, button, modifiers, THIS->vt, 1, |
734 | ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask, |
762 | ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask, |
735 | GrabModeSync, GrabModeSync, None, None); |
763 | GrabModeSync, GrabModeSync, None, GRAB_CURSOR); |
736 | |
764 | |
737 | bool |
765 | bool |
738 | rxvt_term::grab (U32 eventtime, int sync = 0) |
766 | rxvt_term::grab (U32 eventtime, int sync = 0) |
739 | CODE: |
767 | CODE: |
740 | { |
768 | { |
… | |
… | |
742 | |
770 | |
743 | THIS->perl.grabtime = 0; |
771 | THIS->perl.grabtime = 0; |
744 | |
772 | |
745 | if (!XGrabPointer (THIS->display->display, THIS->vt, 0, |
773 | if (!XGrabPointer (THIS->display->display, THIS->vt, 0, |
746 | ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask, |
774 | ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask, |
747 | mode, mode, None, None, eventtime)) |
775 | mode, mode, None, GRAB_CURSOR, eventtime)) |
748 | if (!XGrabKeyboard (THIS->display->display, THIS->vt, 0, mode, mode, eventtime)) |
776 | if (!XGrabKeyboard (THIS->display->display, THIS->vt, 0, mode, mode, eventtime)) |
749 | THIS->perl.grabtime = eventtime; |
777 | THIS->perl.grabtime = eventtime; |
750 | else |
778 | else |
751 | XUngrabPointer (THIS->display->display, eventtime); |
779 | XUngrabPointer (THIS->display->display, eventtime); |
752 | |
780 | |
… | |
… | |
803 | char *mbstr = rxvt_wcstombs (wstr); |
831 | char *mbstr = rxvt_wcstombs (wstr); |
804 | rxvt_pop_locale (); |
832 | rxvt_pop_locale (); |
805 | |
833 | |
806 | free (wstr); |
834 | free (wstr); |
807 | |
835 | |
808 | RETVAL = newSVpv (mbstr, 0); |
836 | RETVAL = taint_if (newSVpv (mbstr, 0), str); |
809 | free (mbstr); |
837 | free (mbstr); |
810 | } |
838 | } |
811 | OUTPUT: |
839 | OUTPUT: |
812 | RETVAL |
840 | RETVAL |
813 | |
841 | |
… | |
… | |
820 | |
848 | |
821 | rxvt_push_locale (THIS->locale); |
849 | rxvt_push_locale (THIS->locale); |
822 | wchar_t *wstr = rxvt_mbstowcs (data, len); |
850 | wchar_t *wstr = rxvt_mbstowcs (data, len); |
823 | rxvt_pop_locale (); |
851 | rxvt_pop_locale (); |
824 | |
852 | |
825 | RETVAL = wcs2sv (wstr); |
853 | RETVAL = taint_if (wcs2sv (wstr), octets); |
826 | free (wstr); |
854 | free (wstr); |
827 | } |
855 | } |
828 | OUTPUT: |
856 | OUTPUT: |
829 | RETVAL |
857 | RETVAL |
830 | |
858 | |
… | |
… | |
937 | wchar_t *wstr = new wchar_t [THIS->ncol]; |
965 | wchar_t *wstr = new wchar_t [THIS->ncol]; |
938 | |
966 | |
939 | for (int col = 0; col < THIS->ncol; col++) |
967 | for (int col = 0; col < THIS->ncol; col++) |
940 | wstr [col] = l.t [col]; |
968 | wstr [col] = l.t [col]; |
941 | |
969 | |
942 | XPUSHs (sv_2mortal (wcs2sv (wstr, THIS->ncol))); |
970 | XPUSHs (taint (sv_2mortal (wcs2sv (wstr, THIS->ncol)))); |
943 | |
971 | |
944 | delete [] wstr; |
972 | delete [] wstr; |
945 | } |
973 | } |
946 | |
974 | |
947 | if (new_text) |
975 | if (new_text) |
… | |
… | |
1068 | else |
1096 | else |
1069 | *r++ = *s; |
1097 | *r++ = *s; |
1070 | |
1098 | |
1071 | rxvt_pop_locale (); |
1099 | rxvt_pop_locale (); |
1072 | |
1100 | |
1073 | RETVAL = wcs2sv (rstr, r - rstr); |
1101 | RETVAL = taint_if (wcs2sv (rstr, r - rstr), string); |
1074 | |
1102 | |
1075 | delete [] rstr; |
1103 | delete [] rstr; |
1076 | } |
1104 | } |
1077 | OUTPUT: |
1105 | OUTPUT: |
1078 | RETVAL |
1106 | RETVAL |
… | |
… | |
1104 | else if (IS_COMPOSE (*s)) |
1132 | else if (IS_COMPOSE (*s)) |
1105 | r += rxvt_composite.expand (*s, r); |
1133 | r += rxvt_composite.expand (*s, r); |
1106 | else |
1134 | else |
1107 | *r++ = *s; |
1135 | *r++ = *s; |
1108 | |
1136 | |
1109 | RETVAL = wcs2sv (rstr, r - rstr); |
1137 | RETVAL = taint_if (wcs2sv (rstr, r - rstr), text); |
1110 | |
1138 | |
1111 | delete [] rstr; |
1139 | delete [] rstr; |
1112 | } |
1140 | } |
1113 | OUTPUT: |
1141 | OUTPUT: |
1114 | RETVAL |
1142 | RETVAL |
… | |
… | |
1136 | |
1164 | |
1137 | if (!IN_RANGE_EXC (index, 0, NUM_RESOURCES)) |
1165 | if (!IN_RANGE_EXC (index, 0, NUM_RESOURCES)) |
1138 | 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); |
1139 | |
1167 | |
1140 | if (GIMME_V != G_VOID) |
1168 | if (GIMME_V != G_VOID) |
1141 | 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); |
1142 | |
1170 | |
1143 | if (newval) |
1171 | if (newval) |
1144 | { |
1172 | { |
1145 | if (SvOK (newval)) |
1173 | if (SvOK (newval)) |
1146 | { |
1174 | { |
… | |
… | |
1151 | else |
1179 | else |
1152 | THIS->rs [index] = 0; |
1180 | THIS->rs [index] = 0; |
1153 | } |
1181 | } |
1154 | } |
1182 | } |
1155 | |
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 | |
1156 | void |
1220 | void |
1157 | rxvt_term::cur (...) |
1221 | rxvt_term::cur (...) |
1158 | PROTOTYPE: $;$$ |
1222 | PROTOTYPE: $;$$ |
1159 | ALIAS: |
1223 | ALIAS: |
1160 | screen_cur = 0 |
1224 | screen_cur = 0 |
… | |
… | |
1191 | void |
1255 | void |
1192 | rxvt_term::selection (SV *newtext = 0) |
1256 | rxvt_term::selection (SV *newtext = 0) |
1193 | PPCODE: |
1257 | PPCODE: |
1194 | { |
1258 | { |
1195 | if (GIMME_V != G_VOID) |
1259 | if (GIMME_V != G_VOID) |
1196 | XPUSHs (sv_2mortal (wcs2sv (THIS->selection.text, THIS->selection.len))); |
1260 | XPUSHs (taint (sv_2mortal (wcs2sv (THIS->selection.text, THIS->selection.len)))); |
1197 | |
1261 | |
1198 | if (newtext) |
1262 | if (newtext) |
1199 | { |
1263 | { |
1200 | free (THIS->selection.text); |
1264 | free (THIS->selection.text); |
1201 | |
1265 | |