… | |
… | |
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; |
… | |
… | |
389 | { |
412 | { |
390 | if (!perl) |
413 | if (!perl) |
391 | { |
414 | { |
392 | char *argv[] = { |
415 | char *argv[] = { |
393 | "", |
416 | "", |
|
|
417 | "-T", |
394 | "-edo '" LIBDIR "/urxvt.pm' or ($@ and die $@) or exit 1", |
418 | "-edo '" LIBDIR "/urxvt.pm' or ($@ and die $@) or exit 1", |
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, 3, 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 | # define export_const(name) newCONSTSUB (gv_stashpv ("urxvt", 1), # name, newSViv (name)); |
612 | sv_setsv (get_sv ("urxvt::LIBDIR", 1), newSVpvn (LIBDIR, sizeof (LIBDIR) - 1)); |
|
|
613 | |
589 | AV *hookname = get_av ("urxvt::HOOKNAME", 1); |
614 | AV *hookname = get_av ("urxvt::HOOKNAME", 1); |
590 | # define def(sym) av_store (hookname, HOOK_ ## sym, newSVpv (# sym, 0)); |
615 | # define def(sym) av_store (hookname, HOOK_ ## sym, newSVpv (# sym, 0)); |
591 | # include "hookinc.h" |
616 | # include "hookinc.h" |
592 | # undef def |
617 | # undef def |
593 | |
618 | |
|
|
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)); |
594 | export_const (DEFAULT_RSTYLE); |
628 | export_const_iv (DEFAULT_RSTYLE); |
595 | export_const (OVERLAY_RSTYLE); |
629 | export_const_iv (OVERLAY_RSTYLE); |
596 | export_const (RS_Bold); |
630 | export_const_iv (RS_Bold); |
597 | export_const (RS_Italic); |
631 | export_const_iv (RS_Italic); |
598 | export_const (RS_Blink); |
632 | export_const_iv (RS_Blink); |
599 | export_const (RS_RVid); |
633 | export_const_iv (RS_RVid); |
600 | export_const (RS_Uline); |
634 | export_const_iv (RS_Uline); |
|
|
635 | |
601 | export_const (CurrentTime); |
636 | export_const_iv (CurrentTime); |
602 | |
637 | export_const_iv (ShiftMask); |
603 | sv_setpv (get_sv ("urxvt::LIBDIR", 1), LIBDIR); |
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); |
604 | } |
651 | } |
605 | |
652 | |
606 | SV * |
653 | SV * |
607 | new (...) |
654 | new (...) |
608 | CODE: |
655 | CODE: |
… | |
… | |
711 | void |
758 | void |
712 | rxvt_term::grab_button (int button, U32 modifiers) |
759 | rxvt_term::grab_button (int button, U32 modifiers) |
713 | CODE: |
760 | CODE: |
714 | XGrabButton (THIS->display->display, button, modifiers, THIS->vt, 1, |
761 | XGrabButton (THIS->display->display, button, modifiers, THIS->vt, 1, |
715 | ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask, |
762 | ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask, |
716 | GrabModeSync, GrabModeSync, None, None); |
763 | GrabModeSync, GrabModeSync, None, GRAB_CURSOR); |
717 | |
764 | |
718 | bool |
765 | bool |
719 | rxvt_term::grab (U32 eventtime, int sync = 0) |
766 | rxvt_term::grab (U32 eventtime, int sync = 0) |
720 | CODE: |
767 | CODE: |
721 | { |
768 | { |
… | |
… | |
723 | |
770 | |
724 | THIS->perl.grabtime = 0; |
771 | THIS->perl.grabtime = 0; |
725 | |
772 | |
726 | if (!XGrabPointer (THIS->display->display, THIS->vt, 0, |
773 | if (!XGrabPointer (THIS->display->display, THIS->vt, 0, |
727 | ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask, |
774 | ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask, |
728 | mode, mode, None, None, eventtime)) |
775 | mode, mode, None, GRAB_CURSOR, eventtime)) |
729 | if (!XGrabKeyboard (THIS->display->display, THIS->vt, 0, mode, mode, eventtime)) |
776 | if (!XGrabKeyboard (THIS->display->display, THIS->vt, 0, mode, mode, eventtime)) |
730 | THIS->perl.grabtime = eventtime; |
777 | THIS->perl.grabtime = eventtime; |
731 | else |
778 | else |
732 | XUngrabPointer (THIS->display->display, eventtime); |
779 | XUngrabPointer (THIS->display->display, eventtime); |
733 | |
780 | |
… | |
… | |
735 | } |
782 | } |
736 | OUTPUT: |
783 | OUTPUT: |
737 | RETVAL |
784 | RETVAL |
738 | |
785 | |
739 | void |
786 | void |
740 | rxvt_term::allow_events_async (U32 eventtime = THIS->perl.grabtime) |
787 | rxvt_term::allow_events_async () |
741 | CODE: |
788 | CODE: |
742 | XAllowEvents (THIS->display->display, AsyncBoth, eventtime); |
789 | XAllowEvents (THIS->display->display, AsyncBoth, THIS->perl.grabtime); |
743 | |
790 | |
744 | void |
791 | void |
745 | rxvt_term::allow_events_sync (U32 eventtime = THIS->perl.grabtime) |
792 | rxvt_term::allow_events_sync () |
746 | CODE: |
793 | CODE: |
747 | XAllowEvents (THIS->display->display, SyncBoth, eventtime); |
794 | XAllowEvents (THIS->display->display, SyncBoth, THIS->perl.grabtime); |
748 | |
795 | |
749 | void |
796 | void |
750 | rxvt_term::allow_events_replay (U32 eventtime = THIS->perl.grabtime) |
797 | rxvt_term::allow_events_replay () |
751 | CODE: |
798 | CODE: |
752 | XAllowEvents (THIS->display->display, ReplayPointer, eventtime); |
799 | XAllowEvents (THIS->display->display, ReplayPointer, THIS->perl.grabtime); |
753 | XAllowEvents (THIS->display->display, ReplayKeyboard, eventtime); |
800 | XAllowEvents (THIS->display->display, ReplayKeyboard, THIS->perl.grabtime); |
754 | |
801 | |
755 | void |
802 | void |
756 | rxvt_term::ungrab (U32 eventtime = THIS->perl.grabtime) |
803 | rxvt_term::ungrab () |
757 | 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); |
758 | THIS->perl.grabtime = 0; |
810 | THIS->perl.grabtime = 0; |
759 | XUngrabKeyboard (THIS->display->display, eventtime); |
811 | } |
760 | XUngrabPointer (THIS->display->display, eventtime); |
812 | } |
761 | |
813 | |
762 | int |
814 | int |
763 | rxvt_term::strwidth (SV *str) |
815 | rxvt_term::strwidth (SV *str) |
764 | CODE: |
816 | CODE: |
765 | { |
817 | { |
… | |
… | |
784 | char *mbstr = rxvt_wcstombs (wstr); |
836 | char *mbstr = rxvt_wcstombs (wstr); |
785 | rxvt_pop_locale (); |
837 | rxvt_pop_locale (); |
786 | |
838 | |
787 | free (wstr); |
839 | free (wstr); |
788 | |
840 | |
789 | RETVAL = newSVpv (mbstr, 0); |
841 | RETVAL = taint_if (newSVpv (mbstr, 0), str); |
790 | free (mbstr); |
842 | free (mbstr); |
791 | } |
843 | } |
792 | OUTPUT: |
844 | OUTPUT: |
793 | RETVAL |
845 | RETVAL |
794 | |
846 | |
… | |
… | |
801 | |
853 | |
802 | rxvt_push_locale (THIS->locale); |
854 | rxvt_push_locale (THIS->locale); |
803 | wchar_t *wstr = rxvt_mbstowcs (data, len); |
855 | wchar_t *wstr = rxvt_mbstowcs (data, len); |
804 | rxvt_pop_locale (); |
856 | rxvt_pop_locale (); |
805 | |
857 | |
806 | RETVAL = wcs2sv (wstr); |
858 | RETVAL = taint_if (wcs2sv (wstr), octets); |
807 | free (wstr); |
859 | free (wstr); |
808 | } |
860 | } |
809 | OUTPUT: |
861 | OUTPUT: |
810 | RETVAL |
862 | RETVAL |
811 | |
863 | |
812 | # very portable, especially on objects as opposed to pods |
864 | #define TERM_OFFSET(sym) offsetof (TermWin_t, sym) |
813 | #define TERM_OFFSET(sym) (((char *)&((TermWin_t *)0)->sym) - (char *)(TermWin_t *)0) |
|
|
814 | |
865 | |
815 | #define TERM_OFFSET_width TERM_OFFSET(width) |
866 | #define TERM_OFFSET_width TERM_OFFSET(width) |
816 | #define TERM_OFFSET_height TERM_OFFSET(height) |
867 | #define TERM_OFFSET_height TERM_OFFSET(height) |
817 | #define TERM_OFFSET_fwidth TERM_OFFSET(fwidth) |
868 | #define TERM_OFFSET_fwidth TERM_OFFSET(fwidth) |
818 | #define TERM_OFFSET_fheight TERM_OFFSET(fheight) |
869 | #define TERM_OFFSET_fheight TERM_OFFSET(fheight) |
… | |
… | |
843 | CODE: |
894 | CODE: |
844 | RETVAL = *(int *)((char *)THIS + ix); |
895 | RETVAL = *(int *)((char *)THIS + ix); |
845 | OUTPUT: |
896 | OUTPUT: |
846 | RETVAL |
897 | RETVAL |
847 | |
898 | |
|
|
899 | unsigned int |
|
|
900 | rxvt_term::ModLevel3Mask () |
|
|
901 | ALIAS: |
|
|
902 | ModLevel3Mask = 0 |
|
|
903 | ModMetaMask = 1 |
|
|
904 | ModNumLockMask = 2 |
|
|
905 | CODE: |
|
|
906 | switch (ix) |
|
|
907 | { |
|
|
908 | case 0: RETVAL = THIS->ModLevel3Mask; break; |
|
|
909 | case 1: RETVAL = THIS->ModMetaMask; break; |
|
|
910 | case 2: RETVAL = THIS->ModNumLockMask; break; |
|
|
911 | } |
|
|
912 | OUTPUT: |
|
|
913 | RETVAL |
|
|
914 | |
848 | U32 |
915 | U32 |
849 | rxvt_term::parent () |
916 | rxvt_term::parent () |
850 | CODE: |
917 | CODE: |
851 | RETVAL = (U32)THIS->parent [0]; |
918 | RETVAL = (U32)THIS->parent [0]; |
852 | OUTPUT: |
919 | OUTPUT: |
… | |
… | |
903 | wchar_t *wstr = new wchar_t [THIS->ncol]; |
970 | wchar_t *wstr = new wchar_t [THIS->ncol]; |
904 | |
971 | |
905 | for (int col = 0; col < THIS->ncol; col++) |
972 | for (int col = 0; col < THIS->ncol; col++) |
906 | wstr [col] = l.t [col]; |
973 | wstr [col] = l.t [col]; |
907 | |
974 | |
908 | XPUSHs (sv_2mortal (wcs2sv (wstr, THIS->ncol))); |
975 | XPUSHs (taint (sv_2mortal (wcs2sv (wstr, THIS->ncol)))); |
909 | |
976 | |
910 | delete [] wstr; |
977 | delete [] wstr; |
911 | } |
978 | } |
912 | |
979 | |
913 | if (new_text) |
980 | if (new_text) |
… | |
… | |
1034 | else |
1101 | else |
1035 | *r++ = *s; |
1102 | *r++ = *s; |
1036 | |
1103 | |
1037 | rxvt_pop_locale (); |
1104 | rxvt_pop_locale (); |
1038 | |
1105 | |
1039 | RETVAL = wcs2sv (rstr, r - rstr); |
1106 | RETVAL = taint_if (wcs2sv (rstr, r - rstr), string); |
1040 | |
1107 | |
1041 | delete [] rstr; |
1108 | delete [] rstr; |
1042 | } |
1109 | } |
1043 | OUTPUT: |
1110 | OUTPUT: |
1044 | RETVAL |
1111 | RETVAL |
… | |
… | |
1070 | else if (IS_COMPOSE (*s)) |
1137 | else if (IS_COMPOSE (*s)) |
1071 | r += rxvt_composite.expand (*s, r); |
1138 | r += rxvt_composite.expand (*s, r); |
1072 | else |
1139 | else |
1073 | *r++ = *s; |
1140 | *r++ = *s; |
1074 | |
1141 | |
1075 | RETVAL = wcs2sv (rstr, r - rstr); |
1142 | RETVAL = taint_if (wcs2sv (rstr, r - rstr), text); |
1076 | |
1143 | |
1077 | delete [] rstr; |
1144 | delete [] rstr; |
1078 | } |
1145 | } |
1079 | OUTPUT: |
1146 | OUTPUT: |
1080 | RETVAL |
1147 | RETVAL |
… | |
… | |
1102 | |
1169 | |
1103 | if (!IN_RANGE_EXC (index, 0, NUM_RESOURCES)) |
1170 | if (!IN_RANGE_EXC (index, 0, NUM_RESOURCES)) |
1104 | 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); |
1105 | |
1172 | |
1106 | if (GIMME_V != G_VOID) |
1173 | if (GIMME_V != G_VOID) |
1107 | 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); |
1108 | |
1175 | |
1109 | if (newval) |
1176 | if (newval) |
1110 | { |
1177 | { |
1111 | if (SvOK (newval)) |
1178 | if (SvOK (newval)) |
1112 | { |
1179 | { |
… | |
… | |
1117 | else |
1184 | else |
1118 | THIS->rs [index] = 0; |
1185 | THIS->rs [index] = 0; |
1119 | } |
1186 | } |
1120 | } |
1187 | } |
1121 | |
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 | |
1122 | void |
1225 | void |
1123 | rxvt_term::cur (...) |
1226 | rxvt_term::cur (...) |
1124 | PROTOTYPE: $;$$ |
1227 | PROTOTYPE: $;$$ |
1125 | ALIAS: |
1228 | ALIAS: |
1126 | screen_cur = 0 |
1229 | screen_cur = 0 |
… | |
… | |
1157 | void |
1260 | void |
1158 | rxvt_term::selection (SV *newtext = 0) |
1261 | rxvt_term::selection (SV *newtext = 0) |
1159 | PPCODE: |
1262 | PPCODE: |
1160 | { |
1263 | { |
1161 | if (GIMME_V != G_VOID) |
1264 | if (GIMME_V != G_VOID) |
1162 | XPUSHs (sv_2mortal (wcs2sv (THIS->selection.text, THIS->selection.len))); |
1265 | XPUSHs (taint (sv_2mortal (wcs2sv (THIS->selection.text, THIS->selection.len)))); |
1163 | |
1266 | |
1164 | if (newtext) |
1267 | if (newtext) |
1165 | { |
1268 | { |
1166 | free (THIS->selection.text); |
1269 | free (THIS->selection.text); |
1167 | |
1270 | |