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.41 by root, Sun Jan 8 03:07:05 2006 UTC vs.
Revision 1.63 by root, Fri Jan 13 05:06:44 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 "unistd.h"
35
36#include "iom.h"
34#include "rxvt.h" 37#include "rxvt.h"
35#include "iom.h" 38#include "keyboard.h"
36#include "rxvtutil.h" 39#include "rxvtutil.h"
37#include "rxvtperl.h" 40#include "rxvtperl.h"
38 41
39#include "perlxsi.c" 42#include "perlxsi.c"
40 43
48#define LINENO(n) MOD (THIS->term_start + int(n), THIS->total_rows) 51#define LINENO(n) MOD (THIS->term_start + int(n), THIS->total_rows)
49#undef ROW 52#undef ROW
50#define ROW(n) THIS->row_buf [LINENO (n)] 53#define ROW(n) THIS->row_buf [LINENO (n)]
51 54
52///////////////////////////////////////////////////////////////////////////// 55/////////////////////////////////////////////////////////////////////////////
56
57static SV *
58taint (SV *sv)
59{
60 SvTAINT (sv);
61 return sv;
62}
63
64static SV *
65taint_if (SV *sv, SV *src)
66{
67 if (SvTAINTED (src))
68 SvTAINT (sv);
69
70 return sv;
71}
53 72
54static wchar_t * 73static wchar_t *
55sv2wcs (SV *sv) 74sv2wcs (SV *sv)
56{ 75{
57 STRLEN len; 76 STRLEN len;
376 395
377struct rxvt_perl_interp rxvt_perl; 396struct rxvt_perl_interp rxvt_perl;
378 397
379static PerlInterpreter *perl; 398static PerlInterpreter *perl;
380 399
381rxvt_perl_interp::rxvt_perl_interp ()
382{
383}
384
385rxvt_perl_interp::~rxvt_perl_interp () 400rxvt_perl_interp::~rxvt_perl_interp ()
386{ 401{
387 if (perl) 402 if (perl)
388 { 403 {
389 perl_destruct (perl); 404 perl_destruct (perl);
394void 409void
395rxvt_perl_interp::init () 410rxvt_perl_interp::init ()
396{ 411{
397 if (!perl) 412 if (!perl)
398 { 413 {
414 perl_environ = rxvt_environ;
415 swap (perl_environ, environ);
416
399 char *argv[] = { 417 char *argv[] = {
400 "", 418 "",
419 "-T",
401 "-edo '" LIBDIR "/urxvt.pm' or ($@ and die $@) or exit 1", 420 "-edo '" LIBDIR "/urxvt.pm' or ($@ and die $@) or exit 1",
402 }; 421 };
403 422
404 perl = perl_alloc (); 423 perl = perl_alloc ();
405 perl_construct (perl); 424 perl_construct (perl);
406 425
407 if (perl_parse (perl, xs_init, 2, argv, (char **)NULL) 426 if (perl_parse (perl, xs_init, 3, argv, (char **)NULL)
408 || perl_run (perl)) 427 || perl_run (perl))
409 { 428 {
410 rxvt_warn ("unable to initialize perl-interpreter, continuing without.\n"); 429 rxvt_warn ("unable to initialize perl-interpreter, continuing without.\n");
411 430
412 perl_destruct (perl); 431 perl_destruct (perl);
413 perl_free (perl); 432 perl_free (perl);
414 perl = 0; 433 perl = 0;
415 } 434 }
435
436 swap (perl_environ, environ);
437 }
438}
439
440static void
441ungrab (rxvt_term *THIS)
442{
443 if (THIS->perl.grabtime)
444 {
445 XUngrabKeyboard (THIS->display->display, THIS->perl.grabtime);
446 XUngrabPointer (THIS->display->display, THIS->perl.grabtime);
447 THIS->perl.grabtime = 0;
416 } 448 }
417} 449}
418 450
419bool 451bool
420rxvt_perl_interp::invoke (rxvt_term *term, hook_type htype, ...) 452rxvt_perl_interp::invoke (rxvt_term *term, hook_type htype, ...)
431 return false; // perl not initialized for this instance 463 return false; // perl not initialized for this instance
432 else if (htype == HOOK_DESTROY) 464 else if (htype == HOOK_DESTROY)
433 { 465 {
434 // handled later 466 // handled later
435 } 467 }
436 else if (htype == HOOK_REFRESH_BEGIN || htype == HOOK_REFRESH_END) 468 else
437 { 469 {
438 HV *hv = (HV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, 0)); 470 if (htype == HOOK_REFRESH_BEGIN || htype == HOOK_REFRESH_END)
439
440 if (HvKEYS (hv))
441 { 471 {
472 HV *hv = (HV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, 0));
473
474 if (HvKEYS (hv))
475 {
442 hv_iterinit (hv); 476 hv_iterinit (hv);
443 477
444 while (HE *he = hv_iternext (hv)) 478 while (HE *he = hv_iternext (hv))
445 ((overlay *)SvIV (hv_iterval (hv, he)))->swap (); 479 ((overlay *)SvIV (hv_iterval (hv, he)))->swap ();
480 }
481
446 } 482 }
483
484 if (!term->perl.should_invoke [htype])
485 return false;
447 } 486 }
448 else if (!should_invoke [htype])
449 return false;
450 487
488 swap (perl_environ, environ);
489
490 try
491 {
451 dSP; 492 dSP;
452 va_list ap; 493 va_list ap;
453 494
454 va_start (ap, htype); 495 va_start (ap, htype);
455 496
456 ENTER; 497 ENTER;
457 SAVETMPS; 498 SAVETMPS;
458 499
459 PUSHMARK (SP); 500 PUSHMARK (SP);
460 501
461 XPUSHs (sv_2mortal (newSVterm (term))); 502 XPUSHs (sv_2mortal (newSVterm (term)));
462 XPUSHs (sv_2mortal (newSViv (htype))); 503 XPUSHs (sv_2mortal (newSViv (htype)));
463 504
464 for (;;) { 505 for (;;) {
465 data_type dt = (data_type)va_arg (ap, int); 506 data_type dt = (data_type)va_arg (ap, int);
466 507
467 switch (dt) 508 switch (dt)
468 { 509 {
469 case DT_INT: 510 case DT_INT:
470 XPUSHs (sv_2mortal (newSViv (va_arg (ap, int)))); 511 XPUSHs (sv_2mortal (newSViv (va_arg (ap, int))));
471 break; 512 break;
472 513
473 case DT_LONG: 514 case DT_LONG:
474 XPUSHs (sv_2mortal (newSViv (va_arg (ap, long)))); 515 XPUSHs (sv_2mortal (newSViv (va_arg (ap, long))));
475 break; 516 break;
476 517
477 case DT_STR: 518 case DT_STR:
478 XPUSHs (sv_2mortal (newSVpv (va_arg (ap, char *), 0))); 519 XPUSHs (taint (sv_2mortal (newSVpv (va_arg (ap, char *), 0))));
479 break; 520 break;
480 521
481 case DT_STR_LEN: 522 case DT_STR_LEN:
482 { 523 {
483 char *str = va_arg (ap, char *); 524 char *str = va_arg (ap, char *);
484 int len = va_arg (ap, int); 525 int len = va_arg (ap, int);
485 526
486 XPUSHs (sv_2mortal (newSVpvn (str, len))); 527 XPUSHs (taint (sv_2mortal (newSVpvn (str, len))));
487 } 528 }
488 break; 529 break;
489 530
490 case DT_WCS_LEN: 531 case DT_WCS_LEN:
491 { 532 {
492 wchar_t *wstr = va_arg (ap, wchar_t *); 533 wchar_t *wstr = va_arg (ap, wchar_t *);
493 int wlen = va_arg (ap, int); 534 int wlen = va_arg (ap, int);
494 535
495 XPUSHs (sv_2mortal (wcs2sv (wstr, wlen))); 536 XPUSHs (taint (sv_2mortal (wcs2sv (wstr, wlen))));
496 } 537 }
497 break; 538 break;
498 539
499 case DT_XEVENT: 540 case DT_XEVENT:
500 { 541 {
501 XEvent *xe = va_arg (ap, XEvent *); 542 XEvent *xe = va_arg (ap, XEvent *);
502 HV *hv = newHV (); 543 HV *hv = newHV ();
503 544
504# define set(name, sv) hv_store (hv, # name, sizeof (# name) - 1, sv, 0) 545# define set(name, sv) hv_store (hv, # name, sizeof (# name) - 1, sv, 0)
505# define setiv(name, val) hv_store (hv, # name, sizeof (# name) - 1, newSViv (val), 0) 546# define setiv(name, val) hv_store (hv, # name, sizeof (# name) - 1, newSViv (val), 0)
506# undef set 547# undef set
507 548
508 setiv (type, xe->type); 549 setiv (type, xe->type);
509 setiv (send_event, xe->xany.send_event); 550 setiv (send_event, xe->xany.send_event);
510 setiv (serial, xe->xany.serial); 551 setiv (serial, xe->xany.serial);
511 552
512 switch (xe->type) 553 switch (xe->type)
554 {
555 case KeyPress:
556 case KeyRelease:
557 case ButtonPress:
558 case ButtonRelease:
559 case MotionNotify:
560 setiv (time, xe->xmotion.time);
561 setiv (x, xe->xmotion.x);
562 setiv (y, xe->xmotion.y);
563 setiv (row, xe->xmotion.y / term->fheight);
564 setiv (col, xe->xmotion.x / term->fwidth);
565 setiv (x_root, xe->xmotion.x_root);
566 setiv (y_root, xe->xmotion.y_root);
567 setiv (state, xe->xmotion.state);
568 break;
569 }
570
571 switch (xe->type)
572 {
573 case KeyPress:
574 case KeyRelease:
575 setiv (keycode, xe->xkey.keycode);
576 break;
577
578 case ButtonPress:
579 case ButtonRelease:
580 setiv (button, xe->xbutton.button);
581 break;
582
583 case MotionNotify:
584 setiv (is_hint, xe->xmotion.is_hint);
585 break;
586 }
587
588 XPUSHs (sv_2mortal (newRV_noinc ((SV *)hv)));
589 }
590 break;
591
592 case DT_END:
513 { 593 {
514 case KeyPress: 594 va_end (ap);
515 case KeyRelease: 595
516 case ButtonPress: 596 PUTBACK;
517 case ButtonRelease: 597 int count = call_pv ("urxvt::invoke", G_ARRAY | G_EVAL);
518 case MotionNotify: 598 SPAGAIN;
519 setiv (time, xe->xmotion.time); 599
520 setiv (x, xe->xmotion.x); 600 if (count)
521 setiv (y, xe->xmotion.y);
522 setiv (row, xe->xmotion.y / term->fheight);
523 setiv (col, xe->xmotion.x / term->fwidth);
524 setiv (x_root, xe->xmotion.x_root);
525 setiv (y_root, xe->xmotion.y_root);
526 setiv (state, xe->xmotion.state);
527 break; 601 {
602 SV *status = POPs;
603 count = SvTRUE (status);
604 }
605
606 PUTBACK;
607 FREETMPS;
608 LEAVE;
609
610 if (SvTRUE (ERRSV))
611 {
612 rxvt_warn ("perl hook %d evaluation error: %s", htype, SvPV_nolen (ERRSV));
613 ungrab (term); // better lose the grab than the session
614 }
615
616 if (htype == HOOK_DESTROY)
617 {
618 clearSVptr ((SV *)term->perl.self);
619 SvREFCNT_dec ((SV *)term->perl.self);
620 }
621
622 swap (perl_environ, environ);
623 return count;
528 } 624 }
529 625
530 switch (xe->type)
531 {
532 case KeyPress:
533 case KeyRelease:
534 setiv (keycode, xe->xkey.keycode);
535 break;
536
537 case ButtonPress:
538 case ButtonRelease:
539 setiv (button, xe->xbutton.button);
540 break;
541
542 case MotionNotify:
543 setiv (is_hint, xe->xmotion.is_hint);
544 break;
545 }
546
547 XPUSHs (sv_2mortal (newRV_noinc ((SV *)hv)));
548 }
549 break;
550
551 case DT_END:
552 {
553 va_end (ap);
554
555 PUTBACK;
556 int count = call_pv ("urxvt::invoke", G_ARRAY | G_EVAL);
557 SPAGAIN;
558
559 if (count)
560 {
561 SV *status = POPs;
562 count = SvTRUE (status);
563 }
564
565 PUTBACK;
566 FREETMPS;
567 LEAVE;
568
569 if (SvTRUE (ERRSV))
570 rxvt_warn ("perl hook %d evaluation error: %s", htype, SvPV_nolen (ERRSV));
571
572 if (htype == HOOK_DESTROY)
573 {
574 clearSVptr ((SV *)term->perl.self);
575 SvREFCNT_dec ((SV *)term->perl.self);
576 }
577
578 return count;
579 }
580
581 default: 626 default:
582 rxvt_fatal ("FATAL: unable to pass data type %d\n", dt); 627 rxvt_fatal ("FATAL: unable to pass data type %d\n", dt);
628 }
583 } 629 }
584 } 630 }
631 catch (...)
632 {
633 swap (perl_environ, environ);
634 throw;
635 }
585} 636}
586 637
587///////////////////////////////////////////////////////////////////////////// 638/////////////////////////////////////////////////////////////////////////////
588 639
589MODULE = urxvt PACKAGE = urxvt 640MODULE = urxvt PACKAGE = urxvt
590 641
591PROTOTYPES: ENABLE 642PROTOTYPES: ENABLE
592 643
593BOOT: 644BOOT:
594{ 645{
595 sv_setsv (get_sv ("urxvt::LIBDIR", 1), newSVpvn (LIBDIR, sizeof (LIBDIR) - 1)); 646 sv_setsv (get_sv ("urxvt::LIBDIR", 1), newSVpvn (LIBDIR, sizeof (LIBDIR) - 1));
647 sv_setsv (get_sv ("urxvt::RESNAME", 1), newSVpvn (RESNAME, sizeof (RESNAME) - 1));
648 sv_setsv (get_sv ("urxvt::RESCLASS", 1), newSVpvn (RESCLASS, sizeof (RESCLASS) - 1));
649 sv_setsv (get_sv ("urxvt::RXVTNAME", 1), newSVpvn (RXVTNAME, sizeof (RXVTNAME) - 1));
596 650
597 AV *hookname = get_av ("urxvt::HOOKNAME", 1); 651 AV *hookname = get_av ("urxvt::HOOKNAME", 1);
598# define def(sym) av_store (hookname, HOOK_ ## sym, newSVpv (# sym, 0)); 652# define def(sym) av_store (hookname, HOOK_ ## sym, newSVpv (# sym, 0));
599# include "hookinc.h" 653# include "hookinc.h"
600# undef def 654# undef def
605# include "optinc.h" 659# include "optinc.h"
606# undef nodef 660# undef nodef
607# undef def 661# undef def
608 662
609 HV *stash = gv_stashpv ("urxvt", 1); 663 HV *stash = gv_stashpv ("urxvt", 1);
610# define export_const_iv(name) newCONSTSUB (stash, # name, newSViv (name)); 664 struct {
665 const char *name;
666 IV iv;
667 } *civ, const_iv[] = {
668# define const_iv(name) { # name, (IV)name }
611 export_const_iv (DEFAULT_RSTYLE); 669 const_iv (DEFAULT_RSTYLE),
612 export_const_iv (OVERLAY_RSTYLE); 670 const_iv (OVERLAY_RSTYLE),
613 export_const_iv (RS_Bold); 671 const_iv (RS_Bold),
614 export_const_iv (RS_Italic); 672 const_iv (RS_Italic),
615 export_const_iv (RS_Blink); 673 const_iv (RS_Blink),
616 export_const_iv (RS_RVid); 674 const_iv (RS_RVid),
617 export_const_iv (RS_Uline); 675 const_iv (RS_Uline),
618 676
619 export_const_iv (CurrentTime); 677 const_iv (CurrentTime),
620 export_const_iv (ShiftMask); 678 const_iv (ShiftMask),
621 export_const_iv (LockMask); 679 const_iv (LockMask),
622 export_const_iv (ControlMask); 680 const_iv (ControlMask),
623 export_const_iv (Mod1Mask); 681 const_iv (Mod1Mask),
624 export_const_iv (Mod2Mask); 682 const_iv (Mod2Mask),
625 export_const_iv (Mod3Mask); 683 const_iv (Mod3Mask),
626 export_const_iv (Mod4Mask); 684 const_iv (Mod4Mask),
627 export_const_iv (Mod5Mask); 685 const_iv (Mod5Mask),
628 export_const_iv (Button1Mask); 686 const_iv (Button1Mask),
629 export_const_iv (Button2Mask); 687 const_iv (Button2Mask),
630 export_const_iv (Button3Mask); 688 const_iv (Button3Mask),
631 export_const_iv (Button4Mask); 689 const_iv (Button4Mask),
632 export_const_iv (Button5Mask); 690 const_iv (Button5Mask),
633 export_const_iv (AnyModifier); 691 const_iv (AnyModifier),
692
693 const_iv (EVENT_NONE),
694 const_iv (EVENT_READ),
695 const_iv (EVENT_WRITE),
696
697 const_iv (NoEventMask),
698 const_iv (KeyPressMask),
699 const_iv (KeyReleaseMask),
700 const_iv (ButtonPressMask),
701 const_iv (ButtonReleaseMask),
702 const_iv (EnterWindowMask),
703 const_iv (LeaveWindowMask),
704 const_iv (PointerMotionMask),
705 const_iv (PointerMotionHintMask),
706 const_iv (Button1MotionMask),
707 const_iv (Button2MotionMask),
708 const_iv (Button3MotionMask),
709 const_iv (Button4MotionMask),
710 const_iv (Button5MotionMask),
711 const_iv (ButtonMotionMask),
712 const_iv (KeymapStateMask),
713 const_iv (ExposureMask),
714 const_iv (VisibilityChangeMask),
715 const_iv (StructureNotifyMask),
716 const_iv (ResizeRedirectMask),
717 const_iv (SubstructureNotifyMask),
718 const_iv (SubstructureRedirectMask),
719 const_iv (FocusChangeMask),
720 const_iv (PropertyChangeMask),
721 const_iv (ColormapChangeMask),
722 const_iv (OwnerGrabButtonMask),
723
724 const_iv (KeyPress),
725 const_iv (KeyRelease),
726 const_iv (ButtonPress),
727 const_iv (ButtonRelease),
728 const_iv (MotionNotify),
729 const_iv (EnterNotify),
730 const_iv (LeaveNotify),
731 const_iv (FocusIn),
732 const_iv (FocusOut),
733 const_iv (KeymapNotify),
734 const_iv (Expose),
735 const_iv (GraphicsExpose),
736 const_iv (NoExpose),
737 const_iv (VisibilityNotify),
738 const_iv (CreateNotify),
739 const_iv (DestroyNotify),
740 const_iv (UnmapNotify),
741 const_iv (MapNotify),
742 const_iv (MapRequest),
743 const_iv (ReparentNotify),
744 const_iv (ConfigureNotify),
745 const_iv (ConfigureRequest),
746 const_iv (GravityNotify),
747 const_iv (ResizeRequest),
748 const_iv (CirculateNotify),
749 const_iv (CirculateRequest),
750 const_iv (PropertyNotify),
751 const_iv (SelectionClear),
752 const_iv (SelectionRequest),
753 const_iv (SelectionNotify),
754 const_iv (ColormapNotify),
755 const_iv (ClientMessage),
756 const_iv (MappingNotify),
757 };
758
759 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]);
760 civ-- > const_iv; )
761 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv));
634} 762}
763
764void
765warn (const char *msg)
766 CODE:
767 rxvt_warn ("%s", msg);
768
769void
770fatal (const char *msg)
771 CODE:
772 rxvt_fatal ("%s", msg);
635 773
636SV * 774SV *
637new (...) 775untaint (SV *sv)
638 CODE: 776 CODE:
639{ 777 RETVAL = newSVsv (sv);
640 stringvec *argv = new stringvec; 778 SvTAINTED_off (RETVAL);
641 bool success; 779 OUTPUT:
642
643 for (int i = 0; i < items ;i++)
644 argv->push_back (strdup (SvPVbyte_nolen (ST (i))));
645
646 rxvt_term *term = new rxvt_term;
647
648 term->argv = argv;
649
650 try
651 {
652 if (!term->init (argv->size (), argv->begin ()))
653 term = 0;
654 }
655 catch (const class rxvt_failure_exception &e)
656 {
657 term->destroy ();
658 croak ("exception caught while initializing new terminal instance");
659 }
660
661 RETVAL = term && term->perl.self ? newSVterm (term) : &PL_sv_undef;
662}
663 OUTPUT:
664 RETVAL 780 RETVAL
665 781
666void 782void
667set_should_invoke (int htype, int value) 783_exit (int status)
668 CODE:
669 rxvt_perl.should_invoke [htype] = value;
670 784
671void 785bool
672warn (const char *msg) 786safe ()
673 CODE: 787 CODE:
674 rxvt_warn ("%s", msg); 788 RETVAL = !rxvt_tainted ();
675 789 OUTPUT:
676void 790 RETVAL
677fatal (const char *msg)
678 CODE:
679 rxvt_fatal ("%s", msg);
680 791
681NV 792NV
682NOW () 793NOW ()
683 CODE: 794 CODE:
684 RETVAL = NOW; 795 RETVAL = NOW;
733 OUTPUT: 844 OUTPUT:
734 RETVAL 845 RETVAL
735 846
736MODULE = urxvt PACKAGE = urxvt::term 847MODULE = urxvt PACKAGE = urxvt::term
737 848
849SV *
850_new (...)
851 CODE:
852{
853 if (items < 1 || !SvROK (ST (0)) || SvTYPE (SvRV (ST (0))) != SVt_PVAV)
854 croak ("first argument to urxvt::term->_new must be arrayref");
855
856 rxvt_term *term = new rxvt_term;
857
858 term->argv = new stringvec;
859 term->envv = new stringvec;
860
861 for (int i = 1; i < items; i++)
862 term->argv->push_back (strdup (SvPVbyte_nolen (ST (i))));
863
864 AV *envv = (AV *)SvRV (ST (0));
865 for (int i = av_len (envv) + 1; i--; )
866 term->envv->push_back (strdup (SvPVbyte_nolen (*av_fetch (envv, i, 1))));
867
868 term->envv->push_back (0);
869
870 bool success;
871
872 try
873 {
874 success = term->init (term->argv->size (), term->argv->begin ());
875 }
876 catch (const class rxvt_failure_exception &e)
877 {
878 success = false;
879 }
880
881 if (!success)
882 {
883 term->destroy ();
884 croak ("error while initializing new terminal instance");
885 }
886
887 RETVAL = term && term->perl.self
888 ? newSVterm (term) : &PL_sv_undef;
889}
890 OUTPUT:
891 RETVAL
892
738void 893void
739rxvt_term::destroy () 894rxvt_term::destroy ()
895
896void
897rxvt_term::set_should_invoke (int htype, int inc)
898 CODE:
899 THIS->perl.should_invoke [htype] += inc;
740 900
741void 901void
742rxvt_term::grab_button (int button, U32 modifiers) 902rxvt_term::grab_button (int button, U32 modifiers)
743 CODE: 903 CODE:
744 XGrabButton (THIS->display->display, button, modifiers, THIS->vt, 1, 904 XGrabButton (THIS->display->display, button, modifiers, THIS->vt, 1,
765} 925}
766 OUTPUT: 926 OUTPUT:
767 RETVAL 927 RETVAL
768 928
769void 929void
770rxvt_term::allow_events_async (U32 eventtime = THIS->perl.grabtime) 930rxvt_term::allow_events_async ()
771 CODE: 931 CODE:
772 XAllowEvents (THIS->display->display, AsyncBoth, eventtime); 932 XAllowEvents (THIS->display->display, AsyncBoth, THIS->perl.grabtime);
773 933
774void 934void
775rxvt_term::allow_events_sync (U32 eventtime = THIS->perl.grabtime) 935rxvt_term::allow_events_sync ()
776 CODE: 936 CODE:
777 XAllowEvents (THIS->display->display, SyncBoth, eventtime); 937 XAllowEvents (THIS->display->display, SyncBoth, THIS->perl.grabtime);
778 938
779void 939void
780rxvt_term::allow_events_replay (U32 eventtime = THIS->perl.grabtime) 940rxvt_term::allow_events_replay ()
781 CODE: 941 CODE:
782 XAllowEvents (THIS->display->display, ReplayPointer, eventtime); 942 XAllowEvents (THIS->display->display, ReplayPointer, THIS->perl.grabtime);
783 XAllowEvents (THIS->display->display, ReplayKeyboard, eventtime); 943 XAllowEvents (THIS->display->display, ReplayKeyboard, THIS->perl.grabtime);
784 944
785void 945void
786rxvt_term::ungrab (U32 eventtime = THIS->perl.grabtime) 946rxvt_term::ungrab ()
787 CODE: 947 CODE:
788 THIS->perl.grabtime = 0; 948 ungrab (THIS);
789 XUngrabKeyboard (THIS->display->display, eventtime);
790 XUngrabPointer (THIS->display->display, eventtime);
791 949
792int 950int
793rxvt_term::strwidth (SV *str) 951rxvt_term::strwidth (SV *str)
794 CODE: 952 CODE:
795{ 953{
814 char *mbstr = rxvt_wcstombs (wstr); 972 char *mbstr = rxvt_wcstombs (wstr);
815 rxvt_pop_locale (); 973 rxvt_pop_locale ();
816 974
817 free (wstr); 975 free (wstr);
818 976
819 RETVAL = newSVpv (mbstr, 0); 977 RETVAL = taint_if (newSVpv (mbstr, 0), str);
820 free (mbstr); 978 free (mbstr);
821} 979}
822 OUTPUT: 980 OUTPUT:
823 RETVAL 981 RETVAL
824 982
831 989
832 rxvt_push_locale (THIS->locale); 990 rxvt_push_locale (THIS->locale);
833 wchar_t *wstr = rxvt_mbstowcs (data, len); 991 wchar_t *wstr = rxvt_mbstowcs (data, len);
834 rxvt_pop_locale (); 992 rxvt_pop_locale ();
835 993
836 RETVAL = wcs2sv (wstr); 994 RETVAL = taint_if (wcs2sv (wstr), octets);
837 free (wstr); 995 free (wstr);
838} 996}
839 OUTPUT: 997 OUTPUT:
840 RETVAL 998 RETVAL
841 999
888 case 2: RETVAL = THIS->ModNumLockMask; break; 1046 case 2: RETVAL = THIS->ModNumLockMask; break;
889 } 1047 }
890 OUTPUT: 1048 OUTPUT:
891 RETVAL 1049 RETVAL
892 1050
1051char *
1052rxvt_term::display_id ()
1053 ALIAS:
1054 display_id = 0
1055 locale = 1
1056 CODE:
1057 switch (ix)
1058 {
1059 case 0: RETVAL = THIS->display->id; break;
1060 case 1: RETVAL = THIS->locale; break;
1061 }
1062 OUTPUT:
1063 RETVAL
1064
1065SV *
1066rxvt_term::_env ()
1067 CODE:
1068{
1069 if (THIS->envv)
1070 {
1071 AV *av = newAV ();
1072
1073 for (char **i = THIS->envv->begin (); i != THIS->envv->end (); ++i)
1074 if (*i)
1075 av_push (av, newSVpv (*i, 0));
1076
1077 RETVAL = newRV_noinc ((SV *)av);
1078 }
1079 else
1080 RETVAL = &PL_sv_undef;
1081}
1082 OUTPUT:
1083 RETVAL
1084
1085int
1086rxvt_term::pty_ev_events (int events = EVENT_UNDEF)
1087 CODE:
1088 RETVAL = THIS->pty_ev.events;
1089 if (events != EVENT_UNDEF)
1090 THIS->pty_ev.set (events);
1091 OUTPUT:
1092 RETVAL
1093
893U32 1094U32
894rxvt_term::parent () 1095rxvt_term::parent ()
895 CODE: 1096 CODE:
896 RETVAL = (U32)THIS->parent [0]; 1097 RETVAL = (U32)THIS->parent [0];
897 OUTPUT: 1098 OUTPUT:
902 CODE: 1103 CODE:
903 RETVAL = (U32)THIS->vt; 1104 RETVAL = (U32)THIS->vt;
904 OUTPUT: 1105 OUTPUT:
905 RETVAL 1106 RETVAL
906 1107
1108void
1109rxvt_term::vt_emask_add (U32 emask)
1110 CODE:
1111 THIS->vt_emask_perl |= emask;
1112 THIS->vt_select_input ();
1113
907U32 1114U32
908rxvt_term::rstyle (U32 new_rstyle = THIS->rstyle) 1115rxvt_term::rstyle (U32 new_rstyle = THIS->rstyle)
909 CODE: 1116 CODE:
910{
911 RETVAL = THIS->rstyle; 1117 RETVAL = THIS->rstyle;
912 THIS->rstyle = new_rstyle; 1118 THIS->rstyle = new_rstyle;
913}
914 OUTPUT: 1119 OUTPUT:
915 RETVAL 1120 RETVAL
916 1121
917int 1122int
918rxvt_term::view_start (int newval = -1) 1123rxvt_term::view_start (int newval = -1)
1124 PROTOTYPE: $;$
919 CODE: 1125 CODE:
920{ 1126{
921 RETVAL = THIS->view_start; 1127 RETVAL = THIS->view_start;
922 1128
923 if (newval >= 0) 1129 if (newval >= 0)
948 wchar_t *wstr = new wchar_t [THIS->ncol]; 1154 wchar_t *wstr = new wchar_t [THIS->ncol];
949 1155
950 for (int col = 0; col < THIS->ncol; col++) 1156 for (int col = 0; col < THIS->ncol; col++)
951 wstr [col] = l.t [col]; 1157 wstr [col] = l.t [col];
952 1158
953 XPUSHs (sv_2mortal (wcs2sv (wstr, THIS->ncol))); 1159 XPUSHs (taint (sv_2mortal (wcs2sv (wstr, THIS->ncol))));
954 1160
955 delete [] wstr; 1161 delete [] wstr;
956 } 1162 }
957 1163
958 if (new_text) 1164 if (new_text)
1079 else 1285 else
1080 *r++ = *s; 1286 *r++ = *s;
1081 1287
1082 rxvt_pop_locale (); 1288 rxvt_pop_locale ();
1083 1289
1084 RETVAL = wcs2sv (rstr, r - rstr); 1290 RETVAL = taint_if (wcs2sv (rstr, r - rstr), string);
1085 1291
1086 delete [] rstr; 1292 delete [] rstr;
1087} 1293}
1088 OUTPUT: 1294 OUTPUT:
1089 RETVAL 1295 RETVAL
1115 else if (IS_COMPOSE (*s)) 1321 else if (IS_COMPOSE (*s))
1116 r += rxvt_composite.expand (*s, r); 1322 r += rxvt_composite.expand (*s, r);
1117 else 1323 else
1118 *r++ = *s; 1324 *r++ = *s;
1119 1325
1120 RETVAL = wcs2sv (rstr, r - rstr); 1326 RETVAL = taint_if (wcs2sv (rstr, r - rstr), text);
1121 1327
1122 delete [] rstr; 1328 delete [] rstr;
1123} 1329}
1124 OUTPUT: 1330 OUTPUT:
1125 RETVAL 1331 RETVAL
1147 1353
1148 if (!IN_RANGE_EXC (index, 0, NUM_RESOURCES)) 1354 if (!IN_RANGE_EXC (index, 0, NUM_RESOURCES))
1149 croak ("requested out-of-bound resource %s+%d,", name, index - rs->value); 1355 croak ("requested out-of-bound resource %s+%d,", name, index - rs->value);
1150 1356
1151 if (GIMME_V != G_VOID) 1357 if (GIMME_V != G_VOID)
1152 XPUSHs (THIS->rs [index] ? sv_2mortal (newSVpv (THIS->rs [index], 0)) : &PL_sv_undef); 1358 XPUSHs (THIS->rs [index] ? sv_2mortal (taint (newSVpv (THIS->rs [index], 0))) : &PL_sv_undef);
1153 1359
1154 if (newval) 1360 if (newval)
1155 { 1361 {
1156 if (SvOK (newval)) 1362 if (SvOK (newval))
1157 { 1363 {
1162 else 1368 else
1163 THIS->rs [index] = 0; 1369 THIS->rs [index] = 0;
1164 } 1370 }
1165} 1371}
1166 1372
1373const char *
1374rxvt_term::x_resource (const char *name)
1375 CLEANUP:
1376 SvTAINTED_on (ST (0));
1377
1167bool 1378bool
1168rxvt_term::option (U32 optval, int set = -1) 1379rxvt_term::option (U32 optval, int set = -1)
1169 CODE: 1380 CODE:
1170{ 1381{
1171 RETVAL = THIS->options & optval; 1382 RETVAL = THIS->options & optval;
1198 } 1409 }
1199} 1410}
1200 OUTPUT: 1411 OUTPUT:
1201 RETVAL 1412 RETVAL
1202 1413
1414bool
1415rxvt_term::parse_keysym (char *keysym, char *str)
1416 CODE:
1417 RETVAL = 0 < THIS->parse_keysym (keysym, str);
1418 THIS->keyboard->register_done ();
1419 OUTPUT:
1420 RETVAL
1421
1203void 1422void
1204rxvt_term::cur (...) 1423rxvt_term::screen_cur (...)
1205 PROTOTYPE: $;$$ 1424 PROTOTYPE: $;$$
1206 ALIAS: 1425 ALIAS:
1207 screen_cur = 0 1426 screen_cur = 0
1208 selection_beg = 1 1427 selection_beg = 1
1209 selection_end = 2 1428 selection_end = 2
1230 if (ix) 1449 if (ix)
1231 THIS->want_refresh = 1; 1450 THIS->want_refresh = 1;
1232 } 1451 }
1233} 1452}
1234 1453
1454char
1455rxvt_term::cur_charset ()
1456 CODE:
1457 RETVAL = THIS->charsets [THIS->screen.charset];
1458 OUTPUT:
1459 RETVAL
1460
1461#void
1462#rxvt_term::selection_clear ()
1463
1464void
1465rxvt_term::selection_make (U32 eventtime, bool rect = false)
1466 CODE:
1467 THIS->selection.op = SELECTION_CONT;
1468 THIS->selection.rect = rect;
1469 THIS->selection_make (eventtime);
1470
1235int 1471int
1236rxvt_term::selection_grab (U32 eventtime) 1472rxvt_term::selection_grab (U32 eventtime)
1237 1473
1238void 1474void
1239rxvt_term::selection (SV *newtext = 0) 1475rxvt_term::selection (SV *newtext = 0)
1240 PPCODE: 1476 PPCODE:
1241{ 1477{
1242 if (GIMME_V != G_VOID) 1478 if (GIMME_V != G_VOID)
1479 XPUSHs (THIS->selection.text
1243 XPUSHs (sv_2mortal (wcs2sv (THIS->selection.text, THIS->selection.len))); 1480 ? taint (sv_2mortal (wcs2sv (THIS->selection.text, THIS->selection.len)))
1481 : &PL_sv_undef);
1244 1482
1245 if (newtext) 1483 if (newtext)
1246 { 1484 {
1247 free (THIS->selection.text); 1485 free (THIS->selection.text);
1248 1486
1249 THIS->selection.text = sv2wcs (newtext); 1487 THIS->selection.text = sv2wcs (newtext);
1250 THIS->selection.len = wcslen (THIS->selection.text); 1488 THIS->selection.len = wcslen (THIS->selection.text);
1251 } 1489 }
1252} 1490}
1491
1492void
1493rxvt_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)
1494
1495void
1496rxvt_term::scr_xor_span (int beg_row, int beg_col, int end_row, int end_col, U32 rstyle = RS_RVid)
1497
1498void
1499rxvt_term::scr_bell ()
1253 1500
1254void 1501void
1255rxvt_term::scr_add_lines (SV *string) 1502rxvt_term::scr_add_lines (SV *string)
1256 CODE: 1503 CODE:
1257{ 1504{

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines