ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/rxvtperl.xs
(Generate patch)

Comparing rxvt-unicode/src/rxvtperl.xs (file contents):
Revision 1.34 by root, Fri Jan 6 21:06:09 2006 UTC vs.
Revision 1.44 by root, Sun Jan 8 22:58:13 2006 UTC

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/////////////////////////////////////////////////////////////////////////////
46 53
54static SV *
55taint (SV *sv)
56{
57 SvTAINT (sv);
58 return sv;
59}
60
61static SV *
62taint_if (SV *sv, SV *src)
63{
64 if (SvTAINTED (src))
65 SvTAINT (sv);
66
67 return sv;
68}
69
47static wchar_t * 70static wchar_t *
48sv2wcs (SV *sv) 71sv2wcs (SV *sv)
49{ 72{
50 STRLEN len; 73 STRLEN len;
51 char *str = SvPVutf8 (sv, len); 74 char *str = SvPVutf8 (sv, len);
101 croak ("perl code used %s object, but C++ object is already destroyed, caught", klass); 124 croak ("perl code used %s object, but C++ object is already destroyed, caught", klass);
102 125
103 return (long)mg->mg_ptr; 126 return (long)mg->mg_ptr;
104} 127}
105 128
106#define newSVterm(term) SvREFCNT_inc ((SV *)term->self) 129#define newSVterm(term) SvREFCNT_inc ((SV *)term->perl.self)
107#define SvTERM(sv) (rxvt_term *)SvPTR (sv, "urxvt::term") 130#define SvTERM(sv) (rxvt_term *)SvPTR (sv, "urxvt::term")
108 131
109///////////////////////////////////////////////////////////////////////////// 132/////////////////////////////////////////////////////////////////////////////
110 133
111struct perl_watcher 134struct perl_watcher
290void 313void
291overlay::show () 314overlay::show ()
292{ 315{
293 char key[33]; sprintf (key, "%32lx", (long)this); 316 char key[33]; sprintf (key, "%32lx", (long)this);
294 317
295 HV *hv = (HV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)THIS->self), "_overlay", 8, 0)); 318 HV *hv = (HV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)THIS->perl.self), "_overlay", 8, 0));
296 hv_store (hv, key, 32, newSViv ((long)this), 0); 319 hv_store (hv, key, 32, newSViv ((long)this), 0);
297} 320}
298 321
299void 322void
300overlay::hide () 323overlay::hide ()
301{ 324{
302 SV **ovs = hv_fetch ((HV *)SvRV ((SV *)THIS->self), "_overlay", 8, 0); 325 SV **ovs = hv_fetch ((HV *)SvRV ((SV *)THIS->perl.self), "_overlay", 8, 0);
303 326
304 if (ovs) 327 if (ovs)
305 { 328 {
306 char key[33]; sprintf (key, "%32lx", (long)this); 329 char key[33]; sprintf (key, "%32lx", (long)this);
307 330
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);
415 if (!perl) 439 if (!perl)
416 return false; 440 return false;
417 441
418 if (htype == HOOK_INIT) // first hook ever called 442 if (htype == HOOK_INIT) // first hook ever called
419 { 443 {
420 term->self = (void *)newSVptr ((void *)term, "urxvt::term"); 444 term->perl.self = (void *)newSVptr ((void *)term, "urxvt::term");
421 hv_store ((HV *)SvRV ((SV *)term->self), "_overlay", 8, newRV_noinc ((SV *)newHV ()), 0); 445 hv_store ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, newRV_noinc ((SV *)newHV ()), 0);
422 } 446 }
423 else if (!term->self) 447 else if (!term->perl.self)
424 return false; // perl not initialized for this instance 448 return false; // perl not initialized for this instance
425 else if (htype == HOOK_DESTROY) 449 else if (htype == HOOK_DESTROY)
426 { 450 {
427 // handled later 451 // handled later
428 } 452 }
429 else if (htype == HOOK_REFRESH_BEGIN || htype == HOOK_REFRESH_END) 453 else if (htype == HOOK_REFRESH_BEGIN || htype == HOOK_REFRESH_END)
430 { 454 {
431 HV *hv = (HV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->self), "_overlay", 8, 0)); 455 HV *hv = (HV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, 0));
432 456
433 if (HvKEYS (hv)) 457 if (HvKEYS (hv))
434 { 458 {
435 hv_iterinit (hv); 459 hv_iterinit (hv);
436 460
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 {
562 if (SvTRUE (ERRSV)) 586 if (SvTRUE (ERRSV))
563 rxvt_warn ("perl hook %d evaluation error: %s", htype, SvPV_nolen (ERRSV)); 587 rxvt_warn ("perl hook %d evaluation error: %s", htype, SvPV_nolen (ERRSV));
564 588
565 if (htype == HOOK_DESTROY) 589 if (htype == HOOK_DESTROY)
566 { 590 {
567 clearSVptr ((SV *)term->self); 591 clearSVptr ((SV *)term->perl.self);
568 SvREFCNT_dec ((SV *)term->self); 592 SvREFCNT_dec ((SV *)term->perl.self);
569 } 593 }
570 594
571 return count; 595 return count;
572 } 596 }
573 597
583 607
584PROTOTYPES: ENABLE 608PROTOTYPES: ENABLE
585 609
586BOOT: 610BOOT:
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);
601 635
602 sv_setpv (get_sv ("urxvt::LIBDIR", 1), LIBDIR); 636 export_const_iv (CurrentTime);
637 export_const_iv (ShiftMask);
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);
603} 651}
604 652
605SV * 653SV *
606new (...) 654new (...)
607 CODE: 655 CODE:
625 { 673 {
626 term->destroy (); 674 term->destroy ();
627 croak ("exception caught while initializing new terminal instance"); 675 croak ("exception caught while initializing new terminal instance");
628 } 676 }
629 677
630 RETVAL = term && term->self ? newSVterm (term) : &PL_sv_undef; 678 RETVAL = term && term->perl.self ? newSVterm (term) : &PL_sv_undef;
631} 679}
632 OUTPUT: 680 OUTPUT:
633 RETVAL 681 RETVAL
634 682
635void 683void
704 752
705MODULE = urxvt PACKAGE = urxvt::term 753MODULE = urxvt PACKAGE = urxvt::term
706 754
707void 755void
708rxvt_term::destroy () 756rxvt_term::destroy ()
757
758void
759rxvt_term::grab_button (int button, U32 modifiers)
760 CODE:
761 XGrabButton (THIS->display->display, button, modifiers, THIS->vt, 1,
762 ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask,
763 GrabModeSync, GrabModeSync, None, GRAB_CURSOR);
764
765bool
766rxvt_term::grab (U32 eventtime, int sync = 0)
767 CODE:
768{
769 int mode = sync ? GrabModeSync : GrabModeAsync;
770
771 THIS->perl.grabtime = 0;
772
773 if (!XGrabPointer (THIS->display->display, THIS->vt, 0,
774 ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask,
775 mode, mode, None, GRAB_CURSOR, eventtime))
776 if (!XGrabKeyboard (THIS->display->display, THIS->vt, 0, mode, mode, eventtime))
777 THIS->perl.grabtime = eventtime;
778 else
779 XUngrabPointer (THIS->display->display, eventtime);
780
781 RETVAL = !!THIS->perl.grabtime;
782}
783 OUTPUT:
784 RETVAL
785
786void
787rxvt_term::allow_events_async ()
788 CODE:
789 XAllowEvents (THIS->display->display, AsyncBoth, THIS->perl.grabtime);
790
791void
792rxvt_term::allow_events_sync ()
793 CODE:
794 XAllowEvents (THIS->display->display, SyncBoth, THIS->perl.grabtime);
795
796void
797rxvt_term::allow_events_replay ()
798 CODE:
799 XAllowEvents (THIS->display->display, ReplayPointer, THIS->perl.grabtime);
800 XAllowEvents (THIS->display->display, ReplayKeyboard, THIS->perl.grabtime);
801
802void
803rxvt_term::ungrab ()
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);
810 THIS->perl.grabtime = 0;
811 }
812}
709 813
710int 814int
711rxvt_term::strwidth (SV *str) 815rxvt_term::strwidth (SV *str)
712 CODE: 816 CODE:
713{ 817{
732 char *mbstr = rxvt_wcstombs (wstr); 836 char *mbstr = rxvt_wcstombs (wstr);
733 rxvt_pop_locale (); 837 rxvt_pop_locale ();
734 838
735 free (wstr); 839 free (wstr);
736 840
737 RETVAL = newSVpv (mbstr, 0); 841 RETVAL = taint_if (newSVpv (mbstr, 0), str);
738 free (mbstr); 842 free (mbstr);
739} 843}
740 OUTPUT: 844 OUTPUT:
741 RETVAL 845 RETVAL
742 846
749 853
750 rxvt_push_locale (THIS->locale); 854 rxvt_push_locale (THIS->locale);
751 wchar_t *wstr = rxvt_mbstowcs (data, len); 855 wchar_t *wstr = rxvt_mbstowcs (data, len);
752 rxvt_pop_locale (); 856 rxvt_pop_locale ();
753 857
754 RETVAL = wcs2sv (wstr); 858 RETVAL = taint_if (wcs2sv (wstr), octets);
755 free (wstr); 859 free (wstr);
756} 860}
757 OUTPUT: 861 OUTPUT:
758 RETVAL 862 RETVAL
759 863
760# very portable, especially on objects as opposed to pods 864#define TERM_OFFSET(sym) offsetof (TermWin_t, sym)
761#define TERM_OFFSET(sym) (((char *)&((TermWin_t *)0)->sym) - (char *)(TermWin_t *)0)
762 865
763#define TERM_OFFSET_width TERM_OFFSET(width) 866#define TERM_OFFSET_width TERM_OFFSET(width)
764#define TERM_OFFSET_height TERM_OFFSET(height) 867#define TERM_OFFSET_height TERM_OFFSET(height)
765#define TERM_OFFSET_fwidth TERM_OFFSET(fwidth) 868#define TERM_OFFSET_fwidth TERM_OFFSET(fwidth)
766#define TERM_OFFSET_fheight TERM_OFFSET(fheight) 869#define TERM_OFFSET_fheight TERM_OFFSET(fheight)
791 CODE: 894 CODE:
792 RETVAL = *(int *)((char *)THIS + ix); 895 RETVAL = *(int *)((char *)THIS + ix);
793 OUTPUT: 896 OUTPUT:
794 RETVAL 897 RETVAL
795 898
899unsigned int
900rxvt_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
796U32 915U32
797rxvt_term::parent () 916rxvt_term::parent ()
798 CODE: 917 CODE:
799 RETVAL = (U32)THIS->parent [0]; 918 RETVAL = (U32)THIS->parent [0];
800 OUTPUT: 919 OUTPUT:
851 wchar_t *wstr = new wchar_t [THIS->ncol]; 970 wchar_t *wstr = new wchar_t [THIS->ncol];
852 971
853 for (int col = 0; col < THIS->ncol; col++) 972 for (int col = 0; col < THIS->ncol; col++)
854 wstr [col] = l.t [col]; 973 wstr [col] = l.t [col];
855 974
856 XPUSHs (sv_2mortal (wcs2sv (wstr, THIS->ncol))); 975 XPUSHs (taint (sv_2mortal (wcs2sv (wstr, THIS->ncol))));
857 976
858 delete [] wstr; 977 delete [] wstr;
859 } 978 }
860 979
861 if (new_text) 980 if (new_text)
982 else 1101 else
983 *r++ = *s; 1102 *r++ = *s;
984 1103
985 rxvt_pop_locale (); 1104 rxvt_pop_locale ();
986 1105
987 RETVAL = wcs2sv (rstr, r - rstr); 1106 RETVAL = taint_if (wcs2sv (rstr, r - rstr), string);
988 1107
989 delete [] rstr; 1108 delete [] rstr;
990} 1109}
991 OUTPUT: 1110 OUTPUT:
992 RETVAL 1111 RETVAL
1018 else if (IS_COMPOSE (*s)) 1137 else if (IS_COMPOSE (*s))
1019 r += rxvt_composite.expand (*s, r); 1138 r += rxvt_composite.expand (*s, r);
1020 else 1139 else
1021 *r++ = *s; 1140 *r++ = *s;
1022 1141
1023 RETVAL = wcs2sv (rstr, r - rstr); 1142 RETVAL = taint_if (wcs2sv (rstr, r - rstr), text);
1024 1143
1025 delete [] rstr; 1144 delete [] rstr;
1026} 1145}
1027 OUTPUT: 1146 OUTPUT:
1028 RETVAL 1147 RETVAL
1050 1169
1051 if (!IN_RANGE_EXC (index, 0, NUM_RESOURCES)) 1170 if (!IN_RANGE_EXC (index, 0, NUM_RESOURCES))
1052 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);
1053 1172
1054 if (GIMME_V != G_VOID) 1173 if (GIMME_V != G_VOID)
1055 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);
1056 1175
1057 if (newval) 1176 if (newval)
1058 { 1177 {
1059 if (SvOK (newval)) 1178 if (SvOK (newval))
1060 { 1179 {
1065 else 1184 else
1066 THIS->rs [index] = 0; 1185 THIS->rs [index] = 0;
1067 } 1186 }
1068} 1187}
1069 1188
1189bool
1190rxvt_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
1070void 1225void
1071rxvt_term::cur (...) 1226rxvt_term::cur (...)
1072 PROTOTYPE: $;$$ 1227 PROTOTYPE: $;$$
1073 ALIAS: 1228 ALIAS:
1074 screen_cur = 0 1229 screen_cur = 0
1098 THIS->want_refresh = 1; 1253 THIS->want_refresh = 1;
1099 } 1254 }
1100} 1255}
1101 1256
1102int 1257int
1103rxvt_term::selection_grab (int eventtime = CurrentTime) 1258rxvt_term::selection_grab (U32 eventtime)
1104 1259
1105void 1260void
1106rxvt_term::selection (SV *newtext = 0) 1261rxvt_term::selection (SV *newtext = 0)
1107 PPCODE: 1262 PPCODE:
1108{ 1263{
1109 if (GIMME_V != G_VOID) 1264 if (GIMME_V != G_VOID)
1110 XPUSHs (sv_2mortal (wcs2sv (THIS->selection.text, THIS->selection.len))); 1265 XPUSHs (taint (sv_2mortal (wcs2sv (THIS->selection.text, THIS->selection.len))));
1111 1266
1112 if (newtext) 1267 if (newtext)
1113 { 1268 {
1114 free (THIS->selection.text); 1269 free (THIS->selection.text);
1115 1270
1146 char *old_cmdbuf_endp = THIS->cmdbuf_endp; 1301 char *old_cmdbuf_endp = THIS->cmdbuf_endp;
1147 1302
1148 THIS->cmdbuf_ptr = str; 1303 THIS->cmdbuf_ptr = str;
1149 THIS->cmdbuf_endp = str + len; 1304 THIS->cmdbuf_endp = str + len;
1150 1305
1306 rxvt_push_locale (THIS->locale);
1151 THIS->cmd_parse (); 1307 THIS->cmd_parse ();
1308 rxvt_pop_locale ();
1152 1309
1153 THIS->cmdbuf_ptr = old_cmdbuf_ptr; 1310 THIS->cmdbuf_ptr = old_cmdbuf_ptr;
1154 THIS->cmdbuf_endp = old_cmdbuf_endp; 1311 THIS->cmdbuf_endp = old_cmdbuf_endp;
1155} 1312}
1156 1313

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines