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.38 by root, Sat Jan 7 21:22:02 2006 UTC vs.
Revision 1.53 by root, Tue Jan 10 04:49:54 2006 UTC

29#include "../config.h" 29#include "../config.h"
30 30
31#include <cstddef> 31#include <cstddef>
32#include <cstdarg> 32#include <cstdarg>
33 33
34#include "iom.h"
34#include "rxvt.h" 35#include "rxvt.h"
35#include "iom.h" 36#include "keyboard.h"
36#include "rxvtutil.h" 37#include "rxvtutil.h"
37#include "rxvtperl.h" 38#include "rxvtperl.h"
38 39
39#include "perlxsi.c" 40#include "perlxsi.c"
41
42#if defined(HAVE_SCROLLBARS) || defined(MENUBAR)
43# define GRAB_CURSOR THIS->leftptr_cursor
44#else
45# define GRAB_CURSOR None
46#endif
40 47
41#undef LINENO 48#undef LINENO
42#define LINENO(n) MOD (THIS->term_start + int(n), THIS->total_rows) 49#define LINENO(n) MOD (THIS->term_start + int(n), THIS->total_rows)
43#undef ROW 50#undef ROW
44#define ROW(n) THIS->row_buf [LINENO (n)] 51#define ROW(n) THIS->row_buf [LINENO (n)]
45 52
46///////////////////////////////////////////////////////////////////////////// 53/////////////////////////////////////////////////////////////////////////////
54
55static SV *
56taint (SV *sv)
57{
58 SvTAINT (sv);
59 return sv;
60}
61
62static SV *
63taint_if (SV *sv, SV *src)
64{
65 if (SvTAINTED (src))
66 SvTAINT (sv);
67
68 return sv;
69}
47 70
48static wchar_t * 71static wchar_t *
49sv2wcs (SV *sv) 72sv2wcs (SV *sv)
50{ 73{
51 STRLEN len; 74 STRLEN len;
390{ 413{
391 if (!perl) 414 if (!perl)
392 { 415 {
393 char *argv[] = { 416 char *argv[] = {
394 "", 417 "",
418 "-T",
395 "-edo '" LIBDIR "/urxvt.pm' or ($@ and die $@) or exit 1", 419 "-edo '" LIBDIR "/urxvt.pm' or ($@ and die $@) or exit 1",
396 }; 420 };
397 421
398 perl = perl_alloc (); 422 perl = perl_alloc ();
399 perl_construct (perl); 423 perl_construct (perl);
400 424
401 if (perl_parse (perl, xs_init, 2, argv, (char **)NULL) 425 if (perl_parse (perl, xs_init, 3, argv, (char **)NULL)
402 || perl_run (perl)) 426 || perl_run (perl))
403 { 427 {
404 rxvt_warn ("unable to initialize perl-interpreter, continuing without.\n"); 428 rxvt_warn ("unable to initialize perl-interpreter, continuing without.\n");
405 429
406 perl_destruct (perl); 430 perl_destruct (perl);
407 perl_free (perl); 431 perl_free (perl);
408 perl = 0; 432 perl = 0;
409 } 433 }
434 }
435}
436
437static void
438ungrab (rxvt_term *THIS)
439{
440 if (THIS->perl.grabtime)
441 {
442 XUngrabKeyboard (THIS->display->display, THIS->perl.grabtime);
443 XUngrabPointer (THIS->display->display, THIS->perl.grabtime);
444 THIS->perl.grabtime = 0;
410 } 445 }
411} 446}
412 447
413bool 448bool
414rxvt_perl_interp::invoke (rxvt_term *term, hook_type htype, ...) 449rxvt_perl_interp::invoke (rxvt_term *term, hook_type htype, ...)
425 return false; // perl not initialized for this instance 460 return false; // perl not initialized for this instance
426 else if (htype == HOOK_DESTROY) 461 else if (htype == HOOK_DESTROY)
427 { 462 {
428 // handled later 463 // handled later
429 } 464 }
430 else if (htype == HOOK_REFRESH_BEGIN || htype == HOOK_REFRESH_END) 465 else
431 { 466 {
432 HV *hv = (HV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, 0)); 467 if (htype == HOOK_REFRESH_BEGIN || htype == HOOK_REFRESH_END)
433
434 if (HvKEYS (hv))
435 { 468 {
469 HV *hv = (HV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, 0));
470
471 if (HvKEYS (hv))
472 {
436 hv_iterinit (hv); 473 hv_iterinit (hv);
437 474
438 while (HE *he = hv_iternext (hv)) 475 while (HE *he = hv_iternext (hv))
439 ((overlay *)SvIV (hv_iterval (hv, he)))->swap (); 476 ((overlay *)SvIV (hv_iterval (hv, he)))->swap ();
477 }
478
440 } 479 }
480
481 if (!should_invoke [htype])
482 return false;
441 } 483 }
442 else if (!should_invoke [htype])
443 return false;
444 484
445 dSP; 485 dSP;
446 va_list ap; 486 va_list ap;
447 487
448 va_start (ap, htype); 488 va_start (ap, htype);
467 case DT_LONG: 507 case DT_LONG:
468 XPUSHs (sv_2mortal (newSViv (va_arg (ap, long)))); 508 XPUSHs (sv_2mortal (newSViv (va_arg (ap, long))));
469 break; 509 break;
470 510
471 case DT_STR: 511 case DT_STR:
472 XPUSHs (sv_2mortal (newSVpv (va_arg (ap, char *), 0))); 512 XPUSHs (taint (sv_2mortal (newSVpv (va_arg (ap, char *), 0))));
473 break; 513 break;
474 514
475 case DT_STR_LEN: 515 case DT_STR_LEN:
476 { 516 {
477 char *str = va_arg (ap, char *); 517 char *str = va_arg (ap, char *);
478 int len = va_arg (ap, int); 518 int len = va_arg (ap, int);
479 519
480 XPUSHs (sv_2mortal (newSVpvn (str, len))); 520 XPUSHs (taint (sv_2mortal (newSVpvn (str, len))));
481 } 521 }
482 break; 522 break;
483 523
484 case DT_WCS_LEN: 524 case DT_WCS_LEN:
485 { 525 {
486 wchar_t *wstr = va_arg (ap, wchar_t *); 526 wchar_t *wstr = va_arg (ap, wchar_t *);
487 int wlen = va_arg (ap, int); 527 int wlen = va_arg (ap, int);
488 528
489 XPUSHs (sv_2mortal (wcs2sv (wstr, wlen))); 529 XPUSHs (taint (sv_2mortal (wcs2sv (wstr, wlen))));
490 } 530 }
491 break; 531 break;
492 532
493 case DT_XEVENT: 533 case DT_XEVENT:
494 { 534 {
559 PUTBACK; 599 PUTBACK;
560 FREETMPS; 600 FREETMPS;
561 LEAVE; 601 LEAVE;
562 602
563 if (SvTRUE (ERRSV)) 603 if (SvTRUE (ERRSV))
604 {
564 rxvt_warn ("perl hook %d evaluation error: %s", htype, SvPV_nolen (ERRSV)); 605 rxvt_warn ("perl hook %d evaluation error: %s", htype, SvPV_nolen (ERRSV));
606 ungrab (term); // better lose the grab than the session
607 }
565 608
566 if (htype == HOOK_DESTROY) 609 if (htype == HOOK_DESTROY)
567 { 610 {
568 clearSVptr ((SV *)term->perl.self); 611 clearSVptr ((SV *)term->perl.self);
569 SvREFCNT_dec ((SV *)term->perl.self); 612 SvREFCNT_dec ((SV *)term->perl.self);
584 627
585PROTOTYPES: ENABLE 628PROTOTYPES: ENABLE
586 629
587BOOT: 630BOOT:
588{ 631{
589 HV *stash = gv_stashpv ("urxvt", 1); 632 sv_setsv (get_sv ("urxvt::LIBDIR", 1), newSVpvn (LIBDIR, sizeof (LIBDIR) - 1));
590# define export_const_iv(name) newCONSTSUB (stash, # name, newSViv (name)); 633 sv_setsv (get_sv ("urxvt::RESNAME", 1), newSVpvn (RESNAME, sizeof (RESNAME) - 1));
634 sv_setsv (get_sv ("urxvt::RESCLASS", 1), newSVpvn (RESCLASS, sizeof (RESCLASS) - 1));
635 sv_setsv (get_sv ("urxvt::RXVTNAME", 1), newSVpvn (RXVTNAME, sizeof (RXVTNAME) - 1));
591 636
592 AV *hookname = get_av ("urxvt::HOOKNAME", 1); 637 AV *hookname = get_av ("urxvt::HOOKNAME", 1);
593# define def(sym) av_store (hookname, HOOK_ ## sym, newSVpv (# sym, 0)); 638# define def(sym) av_store (hookname, HOOK_ ## sym, newSVpv (# sym, 0));
594# include "hookinc.h" 639# include "hookinc.h"
595# undef def 640# undef def
596 641
597 642 HV *option = get_hv ("urxvt::OPTION", 1);
643# define def(name,val) hv_store (option, # name, sizeof (# name) - 1, newSVuv (Opt_ ## name), 0);
644# define nodef(name)
645# include "optinc.h"
646# undef nodef
647# undef def
648
649 HV *stash = gv_stashpv ("urxvt", 1);
650# define export_const_iv(name) newCONSTSUB (stash, # name, newSViv (name));
598 export_const_iv (DEFAULT_RSTYLE); 651 export_const_iv (DEFAULT_RSTYLE);
599 export_const_iv (OVERLAY_RSTYLE); 652 export_const_iv (OVERLAY_RSTYLE);
600 export_const_iv (RS_Bold); 653 export_const_iv (RS_Bold);
601 export_const_iv (RS_Italic); 654 export_const_iv (RS_Italic);
602 export_const_iv (RS_Blink); 655 export_const_iv (RS_Blink);
617 export_const_iv (Button3Mask); 670 export_const_iv (Button3Mask);
618 export_const_iv (Button4Mask); 671 export_const_iv (Button4Mask);
619 export_const_iv (Button5Mask); 672 export_const_iv (Button5Mask);
620 export_const_iv (AnyModifier); 673 export_const_iv (AnyModifier);
621 674
622 sv_setsv (get_sv ("urxvt::LIBDIR", 1), newSVpvn (LIBDIR, sizeof (LIBDIR) - 1)); 675 export_const_iv (EVENT_NONE);
676 export_const_iv (EVENT_READ);
677 export_const_iv (EVENT_WRITE);
623} 678}
624 679
625SV * 680SV *
626new (...) 681new (...)
627 CODE: 682 CODE:
665void 720void
666fatal (const char *msg) 721fatal (const char *msg)
667 CODE: 722 CODE:
668 rxvt_fatal ("%s", msg); 723 rxvt_fatal ("%s", msg);
669 724
725SV *
726untaint (SV *sv)
727 CODE:
728 RETVAL = newSVsv (sv);
729 SvTAINTED_off (RETVAL);
730 OUTPUT:
731 RETVAL
732
733bool
734safe ()
735 CODE:
736 RETVAL = !rxvt_tainted ();
737 OUTPUT:
738 RETVAL
739
670NV 740NV
671NOW () 741NOW ()
672 CODE: 742 CODE:
673 RETVAL = NOW; 743 RETVAL = NOW;
674 OUTPUT: 744 OUTPUT:
730void 800void
731rxvt_term::grab_button (int button, U32 modifiers) 801rxvt_term::grab_button (int button, U32 modifiers)
732 CODE: 802 CODE:
733 XGrabButton (THIS->display->display, button, modifiers, THIS->vt, 1, 803 XGrabButton (THIS->display->display, button, modifiers, THIS->vt, 1,
734 ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask, 804 ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask,
735 GrabModeSync, GrabModeSync, None, None); 805 GrabModeSync, GrabModeSync, None, GRAB_CURSOR);
736 806
737bool 807bool
738rxvt_term::grab (U32 eventtime, int sync = 0) 808rxvt_term::grab (U32 eventtime, int sync = 0)
739 CODE: 809 CODE:
740{ 810{
742 812
743 THIS->perl.grabtime = 0; 813 THIS->perl.grabtime = 0;
744 814
745 if (!XGrabPointer (THIS->display->display, THIS->vt, 0, 815 if (!XGrabPointer (THIS->display->display, THIS->vt, 0,
746 ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask, 816 ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask,
747 mode, mode, None, None, eventtime)) 817 mode, mode, None, GRAB_CURSOR, eventtime))
748 if (!XGrabKeyboard (THIS->display->display, THIS->vt, 0, mode, mode, eventtime)) 818 if (!XGrabKeyboard (THIS->display->display, THIS->vt, 0, mode, mode, eventtime))
749 THIS->perl.grabtime = eventtime; 819 THIS->perl.grabtime = eventtime;
750 else 820 else
751 XUngrabPointer (THIS->display->display, eventtime); 821 XUngrabPointer (THIS->display->display, eventtime);
752 822
754} 824}
755 OUTPUT: 825 OUTPUT:
756 RETVAL 826 RETVAL
757 827
758void 828void
759rxvt_term::allow_events_async (U32 eventtime = THIS->perl.grabtime) 829rxvt_term::allow_events_async ()
760 CODE: 830 CODE:
761 XAllowEvents (THIS->display->display, AsyncBoth, eventtime); 831 XAllowEvents (THIS->display->display, AsyncBoth, THIS->perl.grabtime);
762 832
763void 833void
764rxvt_term::allow_events_sync (U32 eventtime = THIS->perl.grabtime) 834rxvt_term::allow_events_sync ()
765 CODE: 835 CODE:
766 XAllowEvents (THIS->display->display, SyncBoth, eventtime); 836 XAllowEvents (THIS->display->display, SyncBoth, THIS->perl.grabtime);
767 837
768void 838void
769rxvt_term::allow_events_replay (U32 eventtime = THIS->perl.grabtime) 839rxvt_term::allow_events_replay ()
770 CODE: 840 CODE:
771 XAllowEvents (THIS->display->display, ReplayPointer, eventtime); 841 XAllowEvents (THIS->display->display, ReplayPointer, THIS->perl.grabtime);
772 XAllowEvents (THIS->display->display, ReplayKeyboard, eventtime); 842 XAllowEvents (THIS->display->display, ReplayKeyboard, THIS->perl.grabtime);
773 843
774void 844void
775rxvt_term::ungrab (U32 eventtime = THIS->perl.grabtime) 845rxvt_term::ungrab ()
776 CODE: 846 CODE:
777 THIS->perl.grabtime = 0; 847 ungrab (THIS);
778 XUngrabKeyboard (THIS->display->display, eventtime);
779 XUngrabPointer (THIS->display->display, eventtime);
780 848
781int 849int
782rxvt_term::strwidth (SV *str) 850rxvt_term::strwidth (SV *str)
783 CODE: 851 CODE:
784{ 852{
803 char *mbstr = rxvt_wcstombs (wstr); 871 char *mbstr = rxvt_wcstombs (wstr);
804 rxvt_pop_locale (); 872 rxvt_pop_locale ();
805 873
806 free (wstr); 874 free (wstr);
807 875
808 RETVAL = newSVpv (mbstr, 0); 876 RETVAL = taint_if (newSVpv (mbstr, 0), str);
809 free (mbstr); 877 free (mbstr);
810} 878}
811 OUTPUT: 879 OUTPUT:
812 RETVAL 880 RETVAL
813 881
820 888
821 rxvt_push_locale (THIS->locale); 889 rxvt_push_locale (THIS->locale);
822 wchar_t *wstr = rxvt_mbstowcs (data, len); 890 wchar_t *wstr = rxvt_mbstowcs (data, len);
823 rxvt_pop_locale (); 891 rxvt_pop_locale ();
824 892
825 RETVAL = wcs2sv (wstr); 893 RETVAL = taint_if (wcs2sv (wstr), octets);
826 free (wstr); 894 free (wstr);
827} 895}
828 OUTPUT: 896 OUTPUT:
829 RETVAL 897 RETVAL
830 898
877 case 2: RETVAL = THIS->ModNumLockMask; break; 945 case 2: RETVAL = THIS->ModNumLockMask; break;
878 } 946 }
879 OUTPUT: 947 OUTPUT:
880 RETVAL 948 RETVAL
881 949
950char *
951rxvt_term::display_id ()
952 ALIAS:
953 display_id = 0
954 locale = 1
955 CODE:
956 switch (ix)
957 {
958 case 0: RETVAL = THIS->display->id; break;
959 case 1: RETVAL = THIS->locale; break;
960 }
961 OUTPUT:
962 RETVAL
963
964int
965rxvt_term::pty_ev_events (int events = EVENT_UNDEF)
966 CODE:
967 RETVAL = THIS->pty_ev.events;
968 if (events != EVENT_UNDEF)
969 THIS->pty_ev.set (events);
970 OUTPUT:
971 RETVAL
972
882U32 973U32
883rxvt_term::parent () 974rxvt_term::parent ()
884 CODE: 975 CODE:
885 RETVAL = (U32)THIS->parent [0]; 976 RETVAL = (U32)THIS->parent [0];
886 OUTPUT: 977 OUTPUT:
937 wchar_t *wstr = new wchar_t [THIS->ncol]; 1028 wchar_t *wstr = new wchar_t [THIS->ncol];
938 1029
939 for (int col = 0; col < THIS->ncol; col++) 1030 for (int col = 0; col < THIS->ncol; col++)
940 wstr [col] = l.t [col]; 1031 wstr [col] = l.t [col];
941 1032
942 XPUSHs (sv_2mortal (wcs2sv (wstr, THIS->ncol))); 1033 XPUSHs (taint (sv_2mortal (wcs2sv (wstr, THIS->ncol))));
943 1034
944 delete [] wstr; 1035 delete [] wstr;
945 } 1036 }
946 1037
947 if (new_text) 1038 if (new_text)
1068 else 1159 else
1069 *r++ = *s; 1160 *r++ = *s;
1070 1161
1071 rxvt_pop_locale (); 1162 rxvt_pop_locale ();
1072 1163
1073 RETVAL = wcs2sv (rstr, r - rstr); 1164 RETVAL = taint_if (wcs2sv (rstr, r - rstr), string);
1074 1165
1075 delete [] rstr; 1166 delete [] rstr;
1076} 1167}
1077 OUTPUT: 1168 OUTPUT:
1078 RETVAL 1169 RETVAL
1104 else if (IS_COMPOSE (*s)) 1195 else if (IS_COMPOSE (*s))
1105 r += rxvt_composite.expand (*s, r); 1196 r += rxvt_composite.expand (*s, r);
1106 else 1197 else
1107 *r++ = *s; 1198 *r++ = *s;
1108 1199
1109 RETVAL = wcs2sv (rstr, r - rstr); 1200 RETVAL = taint_if (wcs2sv (rstr, r - rstr), text);
1110 1201
1111 delete [] rstr; 1202 delete [] rstr;
1112} 1203}
1113 OUTPUT: 1204 OUTPUT:
1114 RETVAL 1205 RETVAL
1136 1227
1137 if (!IN_RANGE_EXC (index, 0, NUM_RESOURCES)) 1228 if (!IN_RANGE_EXC (index, 0, NUM_RESOURCES))
1138 croak ("requested out-of-bound resource %s+%d,", name, index - rs->value); 1229 croak ("requested out-of-bound resource %s+%d,", name, index - rs->value);
1139 1230
1140 if (GIMME_V != G_VOID) 1231 if (GIMME_V != G_VOID)
1141 XPUSHs (THIS->rs [index] ? sv_2mortal (newSVpv (THIS->rs [index], 0)) : &PL_sv_undef); 1232 XPUSHs (THIS->rs [index] ? sv_2mortal (taint (newSVpv (THIS->rs [index], 0))) : &PL_sv_undef);
1142 1233
1143 if (newval) 1234 if (newval)
1144 { 1235 {
1145 if (SvOK (newval)) 1236 if (SvOK (newval))
1146 { 1237 {
1151 else 1242 else
1152 THIS->rs [index] = 0; 1243 THIS->rs [index] = 0;
1153 } 1244 }
1154} 1245}
1155 1246
1247bool
1248rxvt_term::option (U32 optval, int set = -1)
1249 CODE:
1250{
1251 RETVAL = THIS->options & optval;
1252
1253 if (set >= 0)
1254 {
1255 if (set)
1256 THIS->options |= optval;
1257 else
1258 THIS->options &= ~optval;
1259
1260 switch (optval)
1261 {
1262 case Opt_skipBuiltinGlyphs:
1263 THIS->set_fonts ();
1264 THIS->scr_remap_chars ();
1265 THIS->scr_touch (true);
1266 THIS->want_refresh = 1;
1267 break;
1268
1269 case Opt_cursorUnderline:
1270 THIS->want_refresh = 1;
1271 break;
1272
1273# case Opt_scrollBar_floating:
1274# case Opt_scrollBar_right:
1275# THIS->resize_all_windows (THIS->width, THIS->height, 1);
1276# break;
1277 }
1278 }
1279}
1280 OUTPUT:
1281 RETVAL
1282
1283bool
1284rxvt_term::parse_keysym (char *keysym, char *str)
1285 CODE:
1286 RETVAL = 0 < THIS->parse_keysym (keysym, str);
1287 THIS->keyboard->register_done ();
1288 OUTPUT:
1289 RETVAL
1290
1156void 1291void
1157rxvt_term::cur (...) 1292rxvt_term::screen_cur (...)
1158 PROTOTYPE: $;$$ 1293 PROTOTYPE: $;$$
1159 ALIAS: 1294 ALIAS:
1160 screen_cur = 0 1295 screen_cur = 0
1161 selection_beg = 1 1296 selection_beg = 1
1162 selection_end = 2 1297 selection_end = 2
1183 if (ix) 1318 if (ix)
1184 THIS->want_refresh = 1; 1319 THIS->want_refresh = 1;
1185 } 1320 }
1186} 1321}
1187 1322
1323char
1324rxvt_term::cur_charset ()
1325 CODE:
1326 RETVAL = THIS->charsets [THIS->screen.charset];
1327 OUTPUT:
1328 RETVAL
1329
1188int 1330int
1189rxvt_term::selection_grab (U32 eventtime) 1331rxvt_term::selection_grab (U32 eventtime)
1190 1332
1191void 1333void
1192rxvt_term::selection (SV *newtext = 0) 1334rxvt_term::selection (SV *newtext = 0)
1193 PPCODE: 1335 PPCODE:
1194{ 1336{
1195 if (GIMME_V != G_VOID) 1337 if (GIMME_V != G_VOID)
1338 XPUSHs (THIS->selection.text
1196 XPUSHs (sv_2mortal (wcs2sv (THIS->selection.text, THIS->selection.len))); 1339 ? taint (sv_2mortal (wcs2sv (THIS->selection.text, THIS->selection.len)))
1340 : &PL_sv_undef);
1197 1341
1198 if (newtext) 1342 if (newtext)
1199 { 1343 {
1200 free (THIS->selection.text); 1344 free (THIS->selection.text);
1201 1345
1202 THIS->selection.text = sv2wcs (newtext); 1346 THIS->selection.text = sv2wcs (newtext);
1203 THIS->selection.len = wcslen (THIS->selection.text); 1347 THIS->selection.len = wcslen (THIS->selection.text);
1204 } 1348 }
1205} 1349}
1350
1351void
1352rxvt_term::scr_xor_rect (int beg_row, int beg_col, int end_row, int end_col, U32 rstyle1 = RS_RVid, U32 rstyle2 = RS_RVid | RS_Uline)
1353
1354void
1355rxvt_term::scr_xor_span (int beg_row, int beg_col, int end_row, int end_col, U32 rstyle = RS_RVid)
1356
1357void
1358rxvt_term::scr_bell ()
1206 1359
1207void 1360void
1208rxvt_term::scr_add_lines (SV *string) 1361rxvt_term::scr_add_lines (SV *string)
1209 CODE: 1362 CODE:
1210{ 1363{

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines