… | |
… | |
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); |
… | |
… | |
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 | |
… | |
… | |
754 | } |
782 | } |
755 | OUTPUT: |
783 | OUTPUT: |
756 | RETVAL |
784 | RETVAL |
757 | |
785 | |
758 | void |
786 | void |
759 | rxvt_term::allow_events_async (U32 eventtime = THIS->perl.grabtime) |
787 | rxvt_term::allow_events_async () |
760 | CODE: |
788 | CODE: |
761 | XAllowEvents (THIS->display->display, AsyncBoth, eventtime); |
789 | XAllowEvents (THIS->display->display, AsyncBoth, THIS->perl.grabtime); |
762 | |
790 | |
763 | void |
791 | void |
764 | rxvt_term::allow_events_sync (U32 eventtime = THIS->perl.grabtime) |
792 | rxvt_term::allow_events_sync () |
765 | CODE: |
793 | CODE: |
766 | XAllowEvents (THIS->display->display, SyncBoth, eventtime); |
794 | XAllowEvents (THIS->display->display, SyncBoth, THIS->perl.grabtime); |
767 | |
795 | |
768 | void |
796 | void |
769 | rxvt_term::allow_events_replay (U32 eventtime = THIS->perl.grabtime) |
797 | rxvt_term::allow_events_replay () |
770 | CODE: |
798 | CODE: |
771 | XAllowEvents (THIS->display->display, ReplayPointer, eventtime); |
799 | XAllowEvents (THIS->display->display, ReplayPointer, THIS->perl.grabtime); |
772 | XAllowEvents (THIS->display->display, ReplayKeyboard, eventtime); |
800 | XAllowEvents (THIS->display->display, ReplayKeyboard, THIS->perl.grabtime); |
773 | |
801 | |
774 | void |
802 | void |
775 | rxvt_term::ungrab (U32 eventtime = THIS->perl.grabtime) |
803 | rxvt_term::ungrab () |
776 | CODE: |
804 | CODE: |
|
|
805 | { |
|
|
806 | if (THIS->perl.grabtime) |
|
|
807 | { |
|
|
808 | XUngrabKeyboard (THIS->display->display, THIS->perl.grabtime); |
|
|
809 | XUngrabPointer (THIS->display->display, THIS->perl.grabtime); |
777 | THIS->perl.grabtime = 0; |
810 | THIS->perl.grabtime = 0; |
778 | XUngrabKeyboard (THIS->display->display, eventtime); |
811 | } |
779 | XUngrabPointer (THIS->display->display, eventtime); |
812 | } |
780 | |
813 | |
781 | int |
814 | int |
782 | rxvt_term::strwidth (SV *str) |
815 | rxvt_term::strwidth (SV *str) |
783 | CODE: |
816 | CODE: |
784 | { |
817 | { |
… | |
… | |
803 | char *mbstr = rxvt_wcstombs (wstr); |
836 | char *mbstr = rxvt_wcstombs (wstr); |
804 | rxvt_pop_locale (); |
837 | rxvt_pop_locale (); |
805 | |
838 | |
806 | free (wstr); |
839 | free (wstr); |
807 | |
840 | |
808 | RETVAL = newSVpv (mbstr, 0); |
841 | RETVAL = taint_if (newSVpv (mbstr, 0), str); |
809 | free (mbstr); |
842 | free (mbstr); |
810 | } |
843 | } |
811 | OUTPUT: |
844 | OUTPUT: |
812 | RETVAL |
845 | RETVAL |
813 | |
846 | |
… | |
… | |
820 | |
853 | |
821 | rxvt_push_locale (THIS->locale); |
854 | rxvt_push_locale (THIS->locale); |
822 | wchar_t *wstr = rxvt_mbstowcs (data, len); |
855 | wchar_t *wstr = rxvt_mbstowcs (data, len); |
823 | rxvt_pop_locale (); |
856 | rxvt_pop_locale (); |
824 | |
857 | |
825 | RETVAL = wcs2sv (wstr); |
858 | RETVAL = taint_if (wcs2sv (wstr), octets); |
826 | free (wstr); |
859 | free (wstr); |
827 | } |
860 | } |
828 | OUTPUT: |
861 | OUTPUT: |
829 | RETVAL |
862 | RETVAL |
830 | |
863 | |
… | |
… | |
937 | wchar_t *wstr = new wchar_t [THIS->ncol]; |
970 | wchar_t *wstr = new wchar_t [THIS->ncol]; |
938 | |
971 | |
939 | for (int col = 0; col < THIS->ncol; col++) |
972 | for (int col = 0; col < THIS->ncol; col++) |
940 | wstr [col] = l.t [col]; |
973 | wstr [col] = l.t [col]; |
941 | |
974 | |
942 | XPUSHs (sv_2mortal (wcs2sv (wstr, THIS->ncol))); |
975 | XPUSHs (taint (sv_2mortal (wcs2sv (wstr, THIS->ncol)))); |
943 | |
976 | |
944 | delete [] wstr; |
977 | delete [] wstr; |
945 | } |
978 | } |
946 | |
979 | |
947 | if (new_text) |
980 | if (new_text) |
… | |
… | |
1068 | else |
1101 | else |
1069 | *r++ = *s; |
1102 | *r++ = *s; |
1070 | |
1103 | |
1071 | rxvt_pop_locale (); |
1104 | rxvt_pop_locale (); |
1072 | |
1105 | |
1073 | RETVAL = wcs2sv (rstr, r - rstr); |
1106 | RETVAL = taint_if (wcs2sv (rstr, r - rstr), string); |
1074 | |
1107 | |
1075 | delete [] rstr; |
1108 | delete [] rstr; |
1076 | } |
1109 | } |
1077 | OUTPUT: |
1110 | OUTPUT: |
1078 | RETVAL |
1111 | RETVAL |
… | |
… | |
1104 | else if (IS_COMPOSE (*s)) |
1137 | else if (IS_COMPOSE (*s)) |
1105 | r += rxvt_composite.expand (*s, r); |
1138 | r += rxvt_composite.expand (*s, r); |
1106 | else |
1139 | else |
1107 | *r++ = *s; |
1140 | *r++ = *s; |
1108 | |
1141 | |
1109 | RETVAL = wcs2sv (rstr, r - rstr); |
1142 | RETVAL = taint_if (wcs2sv (rstr, r - rstr), text); |
1110 | |
1143 | |
1111 | delete [] rstr; |
1144 | delete [] rstr; |
1112 | } |
1145 | } |
1113 | OUTPUT: |
1146 | OUTPUT: |
1114 | RETVAL |
1147 | RETVAL |
… | |
… | |
1136 | |
1169 | |
1137 | if (!IN_RANGE_EXC (index, 0, NUM_RESOURCES)) |
1170 | if (!IN_RANGE_EXC (index, 0, NUM_RESOURCES)) |
1138 | croak ("requested out-of-bound resource %s+%d,", name, index - rs->value); |
1171 | croak ("requested out-of-bound resource %s+%d,", name, index - rs->value); |
1139 | |
1172 | |
1140 | if (GIMME_V != G_VOID) |
1173 | if (GIMME_V != G_VOID) |
1141 | XPUSHs (THIS->rs [index] ? sv_2mortal (newSVpv (THIS->rs [index], 0)) : &PL_sv_undef); |
1174 | XPUSHs (THIS->rs [index] ? sv_2mortal (taint (newSVpv (THIS->rs [index], 0))) : &PL_sv_undef); |
1142 | |
1175 | |
1143 | if (newval) |
1176 | if (newval) |
1144 | { |
1177 | { |
1145 | if (SvOK (newval)) |
1178 | if (SvOK (newval)) |
1146 | { |
1179 | { |
… | |
… | |
1151 | else |
1184 | else |
1152 | THIS->rs [index] = 0; |
1185 | THIS->rs [index] = 0; |
1153 | } |
1186 | } |
1154 | } |
1187 | } |
1155 | |
1188 | |
|
|
1189 | bool |
|
|
1190 | rxvt_term::option (U32 optval, int set = -1) |
|
|
1191 | CODE: |
|
|
1192 | { |
|
|
1193 | RETVAL = THIS->options & optval; |
|
|
1194 | |
|
|
1195 | if (set >= 0) |
|
|
1196 | { |
|
|
1197 | if (set) |
|
|
1198 | THIS->options |= optval; |
|
|
1199 | else |
|
|
1200 | THIS->options &= ~optval; |
|
|
1201 | |
|
|
1202 | switch (optval) |
|
|
1203 | { |
|
|
1204 | case Opt_skipBuiltinGlyphs: |
|
|
1205 | THIS->set_fonts (); |
|
|
1206 | THIS->scr_remap_chars (); |
|
|
1207 | THIS->scr_touch (true); |
|
|
1208 | THIS->want_refresh = 1; |
|
|
1209 | break; |
|
|
1210 | |
|
|
1211 | case Opt_cursorUnderline: |
|
|
1212 | THIS->want_refresh = 1; |
|
|
1213 | break; |
|
|
1214 | |
|
|
1215 | # case Opt_scrollBar_floating: |
|
|
1216 | # case Opt_scrollBar_right: |
|
|
1217 | # THIS->resize_all_windows (THIS->width, THIS->height, 1); |
|
|
1218 | # break; |
|
|
1219 | } |
|
|
1220 | } |
|
|
1221 | } |
|
|
1222 | OUTPUT: |
|
|
1223 | RETVAL |
|
|
1224 | |
1156 | void |
1225 | void |
1157 | rxvt_term::cur (...) |
1226 | rxvt_term::cur (...) |
1158 | PROTOTYPE: $;$$ |
1227 | PROTOTYPE: $;$$ |
1159 | ALIAS: |
1228 | ALIAS: |
1160 | screen_cur = 0 |
1229 | screen_cur = 0 |
… | |
… | |
1191 | void |
1260 | void |
1192 | rxvt_term::selection (SV *newtext = 0) |
1261 | rxvt_term::selection (SV *newtext = 0) |
1193 | PPCODE: |
1262 | PPCODE: |
1194 | { |
1263 | { |
1195 | if (GIMME_V != G_VOID) |
1264 | if (GIMME_V != G_VOID) |
1196 | XPUSHs (sv_2mortal (wcs2sv (THIS->selection.text, THIS->selection.len))); |
1265 | XPUSHs (taint (sv_2mortal (wcs2sv (THIS->selection.text, THIS->selection.len)))); |
1197 | |
1266 | |
1198 | if (newtext) |
1267 | if (newtext) |
1199 | { |
1268 | { |
1200 | free (THIS->selection.text); |
1269 | free (THIS->selection.text); |
1201 | |
1270 | |