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.51 by root, Mon Jan 9 23:00:07 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));
591 633
592 AV *hookname = get_av ("urxvt::HOOKNAME", 1); 634 AV *hookname = get_av ("urxvt::HOOKNAME", 1);
593# define def(sym) av_store (hookname, HOOK_ ## sym, newSVpv (# sym, 0)); 635# define def(sym) av_store (hookname, HOOK_ ## sym, newSVpv (# sym, 0));
594# include "hookinc.h" 636# include "hookinc.h"
595# undef def 637# undef def
596 638
597 639 HV *option = get_hv ("urxvt::OPTION", 1);
640# define def(name,val) hv_store (option, # name, sizeof (# name) - 1, newSVuv (Opt_ ## name), 0);
641# define nodef(name)
642# include "optinc.h"
643# undef nodef
644# undef def
645
646 HV *stash = gv_stashpv ("urxvt", 1);
647# define export_const_iv(name) newCONSTSUB (stash, # name, newSViv (name));
598 export_const_iv (DEFAULT_RSTYLE); 648 export_const_iv (DEFAULT_RSTYLE);
599 export_const_iv (OVERLAY_RSTYLE); 649 export_const_iv (OVERLAY_RSTYLE);
600 export_const_iv (RS_Bold); 650 export_const_iv (RS_Bold);
601 export_const_iv (RS_Italic); 651 export_const_iv (RS_Italic);
602 export_const_iv (RS_Blink); 652 export_const_iv (RS_Blink);
617 export_const_iv (Button3Mask); 667 export_const_iv (Button3Mask);
618 export_const_iv (Button4Mask); 668 export_const_iv (Button4Mask);
619 export_const_iv (Button5Mask); 669 export_const_iv (Button5Mask);
620 export_const_iv (AnyModifier); 670 export_const_iv (AnyModifier);
621 671
622 sv_setsv (get_sv ("urxvt::LIBDIR", 1), newSVpvn (LIBDIR, sizeof (LIBDIR) - 1)); 672 export_const_iv (EVENT_NONE);
673 export_const_iv (EVENT_READ);
674 export_const_iv (EVENT_WRITE);
623} 675}
624 676
625SV * 677SV *
626new (...) 678new (...)
627 CODE: 679 CODE:
665void 717void
666fatal (const char *msg) 718fatal (const char *msg)
667 CODE: 719 CODE:
668 rxvt_fatal ("%s", msg); 720 rxvt_fatal ("%s", msg);
669 721
722SV *
723untaint (SV *sv)
724 CODE:
725 RETVAL = newSVsv (sv);
726 SvTAINTED_off (RETVAL);
727 OUTPUT:
728 RETVAL
729
730bool
731safe ()
732 CODE:
733 RETVAL = !rxvt_tainted ();
734 OUTPUT:
735 RETVAL
736
670NV 737NV
671NOW () 738NOW ()
672 CODE: 739 CODE:
673 RETVAL = NOW; 740 RETVAL = NOW;
674 OUTPUT: 741 OUTPUT:
730void 797void
731rxvt_term::grab_button (int button, U32 modifiers) 798rxvt_term::grab_button (int button, U32 modifiers)
732 CODE: 799 CODE:
733 XGrabButton (THIS->display->display, button, modifiers, THIS->vt, 1, 800 XGrabButton (THIS->display->display, button, modifiers, THIS->vt, 1,
734 ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask, 801 ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask,
735 GrabModeSync, GrabModeSync, None, None); 802 GrabModeSync, GrabModeSync, None, GRAB_CURSOR);
736 803
737bool 804bool
738rxvt_term::grab (U32 eventtime, int sync = 0) 805rxvt_term::grab (U32 eventtime, int sync = 0)
739 CODE: 806 CODE:
740{ 807{
742 809
743 THIS->perl.grabtime = 0; 810 THIS->perl.grabtime = 0;
744 811
745 if (!XGrabPointer (THIS->display->display, THIS->vt, 0, 812 if (!XGrabPointer (THIS->display->display, THIS->vt, 0,
746 ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask, 813 ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask,
747 mode, mode, None, None, eventtime)) 814 mode, mode, None, GRAB_CURSOR, eventtime))
748 if (!XGrabKeyboard (THIS->display->display, THIS->vt, 0, mode, mode, eventtime)) 815 if (!XGrabKeyboard (THIS->display->display, THIS->vt, 0, mode, mode, eventtime))
749 THIS->perl.grabtime = eventtime; 816 THIS->perl.grabtime = eventtime;
750 else 817 else
751 XUngrabPointer (THIS->display->display, eventtime); 818 XUngrabPointer (THIS->display->display, eventtime);
752 819
754} 821}
755 OUTPUT: 822 OUTPUT:
756 RETVAL 823 RETVAL
757 824
758void 825void
759rxvt_term::allow_events_async (U32 eventtime = THIS->perl.grabtime) 826rxvt_term::allow_events_async ()
760 CODE: 827 CODE:
761 XAllowEvents (THIS->display->display, AsyncBoth, eventtime); 828 XAllowEvents (THIS->display->display, AsyncBoth, THIS->perl.grabtime);
762 829
763void 830void
764rxvt_term::allow_events_sync (U32 eventtime = THIS->perl.grabtime) 831rxvt_term::allow_events_sync ()
765 CODE: 832 CODE:
766 XAllowEvents (THIS->display->display, SyncBoth, eventtime); 833 XAllowEvents (THIS->display->display, SyncBoth, THIS->perl.grabtime);
767 834
768void 835void
769rxvt_term::allow_events_replay (U32 eventtime = THIS->perl.grabtime) 836rxvt_term::allow_events_replay ()
770 CODE: 837 CODE:
771 XAllowEvents (THIS->display->display, ReplayPointer, eventtime); 838 XAllowEvents (THIS->display->display, ReplayPointer, THIS->perl.grabtime);
772 XAllowEvents (THIS->display->display, ReplayKeyboard, eventtime); 839 XAllowEvents (THIS->display->display, ReplayKeyboard, THIS->perl.grabtime);
773 840
774void 841void
775rxvt_term::ungrab (U32 eventtime = THIS->perl.grabtime) 842rxvt_term::ungrab ()
776 CODE: 843 CODE:
777 THIS->perl.grabtime = 0; 844 ungrab (THIS);
778 XUngrabKeyboard (THIS->display->display, eventtime);
779 XUngrabPointer (THIS->display->display, eventtime);
780 845
781int 846int
782rxvt_term::strwidth (SV *str) 847rxvt_term::strwidth (SV *str)
783 CODE: 848 CODE:
784{ 849{
803 char *mbstr = rxvt_wcstombs (wstr); 868 char *mbstr = rxvt_wcstombs (wstr);
804 rxvt_pop_locale (); 869 rxvt_pop_locale ();
805 870
806 free (wstr); 871 free (wstr);
807 872
808 RETVAL = newSVpv (mbstr, 0); 873 RETVAL = taint_if (newSVpv (mbstr, 0), str);
809 free (mbstr); 874 free (mbstr);
810} 875}
811 OUTPUT: 876 OUTPUT:
812 RETVAL 877 RETVAL
813 878
820 885
821 rxvt_push_locale (THIS->locale); 886 rxvt_push_locale (THIS->locale);
822 wchar_t *wstr = rxvt_mbstowcs (data, len); 887 wchar_t *wstr = rxvt_mbstowcs (data, len);
823 rxvt_pop_locale (); 888 rxvt_pop_locale ();
824 889
825 RETVAL = wcs2sv (wstr); 890 RETVAL = taint_if (wcs2sv (wstr), octets);
826 free (wstr); 891 free (wstr);
827} 892}
828 OUTPUT: 893 OUTPUT:
829 RETVAL 894 RETVAL
830 895
877 case 2: RETVAL = THIS->ModNumLockMask; break; 942 case 2: RETVAL = THIS->ModNumLockMask; break;
878 } 943 }
879 OUTPUT: 944 OUTPUT:
880 RETVAL 945 RETVAL
881 946
947char *
948rxvt_term::display_id ()
949 ALIAS:
950 display_id = 0
951 locale = 1
952 CODE:
953 switch (ix)
954 {
955 case 0: RETVAL = THIS->display->id; break;
956 case 1: RETVAL = THIS->locale; break;
957 }
958 OUTPUT:
959 RETVAL
960
961int
962rxvt_term::pty_ev_events (int events = EVENT_UNDEF)
963 CODE:
964 RETVAL = THIS->pty_ev.events;
965 if (events != EVENT_UNDEF)
966 THIS->pty_ev.set (events);
967 OUTPUT:
968 RETVAL
969
882U32 970U32
883rxvt_term::parent () 971rxvt_term::parent ()
884 CODE: 972 CODE:
885 RETVAL = (U32)THIS->parent [0]; 973 RETVAL = (U32)THIS->parent [0];
886 OUTPUT: 974 OUTPUT:
937 wchar_t *wstr = new wchar_t [THIS->ncol]; 1025 wchar_t *wstr = new wchar_t [THIS->ncol];
938 1026
939 for (int col = 0; col < THIS->ncol; col++) 1027 for (int col = 0; col < THIS->ncol; col++)
940 wstr [col] = l.t [col]; 1028 wstr [col] = l.t [col];
941 1029
942 XPUSHs (sv_2mortal (wcs2sv (wstr, THIS->ncol))); 1030 XPUSHs (taint (sv_2mortal (wcs2sv (wstr, THIS->ncol))));
943 1031
944 delete [] wstr; 1032 delete [] wstr;
945 } 1033 }
946 1034
947 if (new_text) 1035 if (new_text)
1068 else 1156 else
1069 *r++ = *s; 1157 *r++ = *s;
1070 1158
1071 rxvt_pop_locale (); 1159 rxvt_pop_locale ();
1072 1160
1073 RETVAL = wcs2sv (rstr, r - rstr); 1161 RETVAL = taint_if (wcs2sv (rstr, r - rstr), string);
1074 1162
1075 delete [] rstr; 1163 delete [] rstr;
1076} 1164}
1077 OUTPUT: 1165 OUTPUT:
1078 RETVAL 1166 RETVAL
1104 else if (IS_COMPOSE (*s)) 1192 else if (IS_COMPOSE (*s))
1105 r += rxvt_composite.expand (*s, r); 1193 r += rxvt_composite.expand (*s, r);
1106 else 1194 else
1107 *r++ = *s; 1195 *r++ = *s;
1108 1196
1109 RETVAL = wcs2sv (rstr, r - rstr); 1197 RETVAL = taint_if (wcs2sv (rstr, r - rstr), text);
1110 1198
1111 delete [] rstr; 1199 delete [] rstr;
1112} 1200}
1113 OUTPUT: 1201 OUTPUT:
1114 RETVAL 1202 RETVAL
1136 1224
1137 if (!IN_RANGE_EXC (index, 0, NUM_RESOURCES)) 1225 if (!IN_RANGE_EXC (index, 0, NUM_RESOURCES))
1138 croak ("requested out-of-bound resource %s+%d,", name, index - rs->value); 1226 croak ("requested out-of-bound resource %s+%d,", name, index - rs->value);
1139 1227
1140 if (GIMME_V != G_VOID) 1228 if (GIMME_V != G_VOID)
1141 XPUSHs (THIS->rs [index] ? sv_2mortal (newSVpv (THIS->rs [index], 0)) : &PL_sv_undef); 1229 XPUSHs (THIS->rs [index] ? sv_2mortal (taint (newSVpv (THIS->rs [index], 0))) : &PL_sv_undef);
1142 1230
1143 if (newval) 1231 if (newval)
1144 { 1232 {
1145 if (SvOK (newval)) 1233 if (SvOK (newval))
1146 { 1234 {
1151 else 1239 else
1152 THIS->rs [index] = 0; 1240 THIS->rs [index] = 0;
1153 } 1241 }
1154} 1242}
1155 1243
1244bool
1245rxvt_term::option (U32 optval, int set = -1)
1246 CODE:
1247{
1248 RETVAL = THIS->options & optval;
1249
1250 if (set >= 0)
1251 {
1252 if (set)
1253 THIS->options |= optval;
1254 else
1255 THIS->options &= ~optval;
1256
1257 switch (optval)
1258 {
1259 case Opt_skipBuiltinGlyphs:
1260 THIS->set_fonts ();
1261 THIS->scr_remap_chars ();
1262 THIS->scr_touch (true);
1263 THIS->want_refresh = 1;
1264 break;
1265
1266 case Opt_cursorUnderline:
1267 THIS->want_refresh = 1;
1268 break;
1269
1270# case Opt_scrollBar_floating:
1271# case Opt_scrollBar_right:
1272# THIS->resize_all_windows (THIS->width, THIS->height, 1);
1273# break;
1274 }
1275 }
1276}
1277 OUTPUT:
1278 RETVAL
1279
1280bool
1281rxvt_term::parse_keysym (char *keysym, char *str)
1282 CODE:
1283 RETVAL = 0 < THIS->parse_keysym (keysym, str);
1284 THIS->keyboard->register_done ();
1285 OUTPUT:
1286 RETVAL
1287
1156void 1288void
1157rxvt_term::cur (...) 1289rxvt_term::screen_cur (...)
1158 PROTOTYPE: $;$$ 1290 PROTOTYPE: $;$$
1159 ALIAS: 1291 ALIAS:
1160 screen_cur = 0 1292 screen_cur = 0
1161 selection_beg = 1 1293 selection_beg = 1
1162 selection_end = 2 1294 selection_end = 2
1191void 1323void
1192rxvt_term::selection (SV *newtext = 0) 1324rxvt_term::selection (SV *newtext = 0)
1193 PPCODE: 1325 PPCODE:
1194{ 1326{
1195 if (GIMME_V != G_VOID) 1327 if (GIMME_V != G_VOID)
1328 XPUSHs (THIS->selection.text
1196 XPUSHs (sv_2mortal (wcs2sv (THIS->selection.text, THIS->selection.len))); 1329 ? taint (sv_2mortal (wcs2sv (THIS->selection.text, THIS->selection.len)))
1330 : &PL_sv_undef);
1197 1331
1198 if (newtext) 1332 if (newtext)
1199 { 1333 {
1200 free (THIS->selection.text); 1334 free (THIS->selection.text);
1201 1335
1202 THIS->selection.text = sv2wcs (newtext); 1336 THIS->selection.text = sv2wcs (newtext);
1203 THIS->selection.len = wcslen (THIS->selection.text); 1337 THIS->selection.len = wcslen (THIS->selection.text);
1204 } 1338 }
1205} 1339}
1340
1341void
1342rxvt_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)
1343
1344void
1345rxvt_term::scr_xor_span (int beg_row, int beg_col, int end_row, int end_col, U32 rstyle = RS_RVid)
1346
1347void
1348rxvt_term::scr_bell ()
1206 1349
1207void 1350void
1208rxvt_term::scr_add_lines (SV *string) 1351rxvt_term::scr_add_lines (SV *string)
1209 CODE: 1352 CODE:
1210{ 1353{

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines