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.51 by root, Mon Jan 9 23:00:07 2006 UTC vs.
Revision 1.72 by root, Wed Jan 18 08:33:34 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
34#include "iom.h" 36#include "iom.h"
35#include "rxvt.h" 37#include "rxvt.h"
36#include "keyboard.h" 38#include "keyboard.h"
37#include "rxvtutil.h" 39#include "rxvtutil.h"
38#include "rxvtperl.h" 40#include "rxvtperl.h"
39 41
40#include "perlxsi.c" 42#include "perlxsi.c"
41 43
42#if defined(HAVE_SCROLLBARS) || defined(MENUBAR) 44#ifdef HAVE_SCROLLBARS
43# define GRAB_CURSOR THIS->leftptr_cursor 45# define GRAB_CURSOR THIS->leftptr_cursor
44#else 46#else
45# define GRAB_CURSOR None 47# define GRAB_CURSOR None
46#endif 48#endif
47 49
48#undef LINENO 50#undef LINENO
49#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)
50#undef ROW 52#undef ROW
51#define ROW(n) THIS->row_buf [LINENO (n)] 53#define ROW(n) THIS->row_buf [LINENO (n)]
52 54
55#define ENABLE_PERL_FRILLS 1
56
53///////////////////////////////////////////////////////////////////////////// 57/////////////////////////////////////////////////////////////////////////////
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}
70 58
71static wchar_t * 59static wchar_t *
72sv2wcs (SV *sv) 60sv2wcs (SV *sv)
73{ 61{
74 STRLEN len; 62 STRLEN len;
345 for (int y = ov_h; y--; ) 333 for (int y = ov_h; y--; )
346 { 334 {
347 text_t *t1 = text [y]; 335 text_t *t1 = text [y];
348 rend_t *r1 = rend [y]; 336 rend_t *r1 = rend [y];
349 337
350 text_t *t2 = ROW(y + ov_y - THIS->view_start).t + ov_x; 338 text_t *t2 = ROW(y + ov_y + THIS->view_start).t + ov_x;
351 rend_t *r2 = ROW(y + ov_y - THIS->view_start).r + ov_x; 339 rend_t *r2 = ROW(y + ov_y + THIS->view_start).r + ov_x;
352 340
353 for (int x = ov_w; x--; ) 341 for (int x = ov_w; x--; )
354 { 342 {
355 text_t t = *t1; *t1++ = *t2; *t2++ = t; 343 text_t t = *t1; *t1++ = *t2; *t2++ = t;
356 rend_t r = *r1; *r1++ = *r2; *r2++ = SET_FONT (r, THIS->fontset [GET_STYLE (r)]->find_font (t)); 344 rend_t r = *r1; *r1++ = *r2; *r2++ = SET_FONT (r, THIS->fontset [GET_STYLE (r)]->find_font (t));
393 381
394struct rxvt_perl_interp rxvt_perl; 382struct rxvt_perl_interp rxvt_perl;
395 383
396static PerlInterpreter *perl; 384static PerlInterpreter *perl;
397 385
398rxvt_perl_interp::rxvt_perl_interp ()
399{
400}
401
402rxvt_perl_interp::~rxvt_perl_interp () 386rxvt_perl_interp::~rxvt_perl_interp ()
403{ 387{
404 if (perl) 388 if (perl)
405 { 389 {
406 perl_destruct (perl); 390 perl_destruct (perl);
407 perl_free (perl); 391 perl_free (perl);
408 } 392 }
409} 393}
410 394
411void 395void
412rxvt_perl_interp::init () 396rxvt_perl_interp::init (rxvt_term *term)
413{ 397{
414 if (!perl) 398 if (!perl)
415 { 399 {
400 rxvt_push_locale (""); // perl init destroys current locale
401
402 perl_environ = rxvt_environ;
403 swap (perl_environ, environ);
404
416 char *argv[] = { 405 char *argv[] = {
417 "", 406 "",
418 "-T", 407 "-e"
419 "-edo '" LIBDIR "/urxvt.pm' or ($@ and die $@) or exit 1", 408 "BEGIN {"
409 " urxvt->bootstrap;"
410 " unshift @INC, '" LIBDIR "';"
411 "}"
412 ""
413 "use urxvt;"
420 }; 414 };
421 415
422 perl = perl_alloc (); 416 perl = perl_alloc ();
423 perl_construct (perl); 417 perl_construct (perl);
424 418
425 if (perl_parse (perl, xs_init, 3, argv, (char **)NULL) 419 if (perl_parse (perl, xs_init, 2, argv, (char **)NULL)
426 || perl_run (perl)) 420 || perl_run (perl))
427 { 421 {
428 rxvt_warn ("unable to initialize perl-interpreter, continuing without.\n"); 422 rxvt_warn ("unable to initialize perl-interpreter, continuing without.\n");
429 423
430 perl_destruct (perl); 424 perl_destruct (perl);
431 perl_free (perl); 425 perl_free (perl);
432 perl = 0; 426 perl = 0;
433 } 427 }
428
429 swap (perl_environ, environ);
430
431 rxvt_pop_locale ();
432 }
433
434 if (perl)
435 {
436 // runs outside of perls ENV
437 term->perl.self = (void *)newSVptr ((void *)term, "urxvt::term");
438 hv_store ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, newRV_noinc ((SV *)newHV ()), 0);
434 } 439 }
435} 440}
436 441
437static void 442static void
438ungrab (rxvt_term *THIS) 443ungrab (rxvt_term *THIS)
443 XUngrabPointer (THIS->display->display, THIS->perl.grabtime); 448 XUngrabPointer (THIS->display->display, THIS->perl.grabtime);
444 THIS->perl.grabtime = 0; 449 THIS->perl.grabtime = 0;
445 } 450 }
446} 451}
447 452
453static void
454swap_overlays (rxvt_term *term)
455{
456 HV *hv = (HV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, 0));
457
458 if (HvKEYS (hv))
459 {
460 hv_iterinit (hv);
461
462 while (HE *he = hv_iternext (hv))
463 ((overlay *)SvIV (hv_iterval (hv, he)))->swap ();
464 }
465}
466
448bool 467bool
449rxvt_perl_interp::invoke (rxvt_term *term, hook_type htype, ...) 468rxvt_perl_interp::invoke (rxvt_term *term, hook_type htype, ...)
450{ 469{
451 if (!perl) 470 if (!perl || !term->perl.self)
452 return false; 471 return false;
453 472
454 if (htype == HOOK_INIT) // first hook ever called 473 // pre-handling of some events
455 { 474 if (htype == HOOK_REFRESH_END)
456 term->perl.self = (void *)newSVptr ((void *)term, "urxvt::term"); 475 swap_overlays (term);
457 hv_store ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, newRV_noinc ((SV *)newHV ()), 0); 476
458 } 477 swap (perl_environ, environ);
459 else if (!term->perl.self) 478
460 return false; // perl not initialized for this instance 479 bool event_consumed;
461 else if (htype == HOOK_DESTROY) 480
462 { 481 if (htype == HOOK_INIT || htype == HOOK_DESTROY // must be called always
463 // handled later 482 || term->perl.should_invoke [htype])
464 } 483 try
465 else
466 {
467 if (htype == HOOK_REFRESH_BEGIN || htype == HOOK_REFRESH_END)
468 { 484 {
469 HV *hv = (HV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, 0)); 485 dSP;
486 va_list ap;
470 487
471 if (HvKEYS (hv)) 488 va_start (ap, htype);
489
490 ENTER;
491 SAVETMPS;
492
493 PUSHMARK (SP);
494
495 XPUSHs (sv_2mortal (newSVterm (term)));
496 XPUSHs (sv_2mortal (newSViv (htype)));
497
498 for (;;) {
499 data_type dt = (data_type)va_arg (ap, int);
500
501 switch (dt)
472 { 502 {
473 hv_iterinit (hv);
474
475 while (HE *he = hv_iternext (hv))
476 ((overlay *)SvIV (hv_iterval (hv, he)))->swap ();
477 }
478
479 }
480
481 if (!should_invoke [htype])
482 return false;
483 }
484
485 dSP;
486 va_list ap;
487
488 va_start (ap, htype);
489
490 ENTER;
491 SAVETMPS;
492
493 PUSHMARK (SP);
494
495 XPUSHs (sv_2mortal (newSVterm (term)));
496 XPUSHs (sv_2mortal (newSViv (htype)));
497
498 for (;;) {
499 data_type dt = (data_type)va_arg (ap, int);
500
501 switch (dt)
502 {
503 case DT_INT: 503 case DT_INT:
504 XPUSHs (sv_2mortal (newSViv (va_arg (ap, int)))); 504 XPUSHs (sv_2mortal (newSViv (va_arg (ap, int))));
505 break; 505 break;
506 506
507 case DT_LONG: 507 case DT_LONG:
508 XPUSHs (sv_2mortal (newSViv (va_arg (ap, long)))); 508 XPUSHs (sv_2mortal (newSViv (va_arg (ap, long))));
509 break; 509 break;
510 510
511 case DT_STR: 511 case DT_STR:
512 XPUSHs (taint (sv_2mortal (newSVpv (va_arg (ap, char *), 0)))); 512 XPUSHs (sv_2mortal (newSVpv (va_arg (ap, char *), 0)));
513 break; 513 break;
514 514
515 case DT_STR_LEN: 515 case DT_STR_LEN:
516 { 516 {
517 char *str = va_arg (ap, char *); 517 char *str = va_arg (ap, char *);
518 int len = va_arg (ap, int); 518 int len = va_arg (ap, int);
519 519
520 XPUSHs (taint (sv_2mortal (newSVpvn (str, len)))); 520 XPUSHs (sv_2mortal (newSVpvn (str, len)));
521 } 521 }
522 break; 522 break;
523 523
524 case DT_WCS_LEN: 524 case DT_WCS_LEN:
525 { 525 {
526 wchar_t *wstr = va_arg (ap, wchar_t *); 526 wchar_t *wstr = va_arg (ap, wchar_t *);
527 int wlen = va_arg (ap, int); 527 int wlen = va_arg (ap, int);
528 528
529 XPUSHs (taint (sv_2mortal (wcs2sv (wstr, wlen)))); 529 XPUSHs (sv_2mortal (wcs2sv (wstr, wlen)));
530 } 530 }
531 break; 531 break;
532 532
533 case DT_XEVENT: 533 case DT_XEVENT:
534 { 534 {
535 XEvent *xe = va_arg (ap, XEvent *); 535 XEvent *xe = va_arg (ap, XEvent *);
536 HV *hv = newHV (); 536 HV *hv = newHV ();
537 537
538# define set(name, sv) hv_store (hv, # name, sizeof (# name) - 1, sv, 0) 538# define set(name, sv) hv_store (hv, # name, sizeof (# name) - 1, sv, 0)
539# define setiv(name, val) hv_store (hv, # name, sizeof (# name) - 1, newSViv (val), 0) 539# define setiv(name, val) hv_store (hv, # name, sizeof (# name) - 1, newSViv (val), 0)
540# undef set 540# undef set
541 541
542 setiv (type, xe->type); 542 setiv (type, xe->type);
543 setiv (send_event, xe->xany.send_event); 543 setiv (send_event, xe->xany.send_event);
544 setiv (serial, xe->xany.serial); 544 setiv (serial, xe->xany.serial);
545 545
546 switch (xe->type) 546 switch (xe->type)
547 { 547 {
548 case KeyPress: 548 case KeyPress:
549 case KeyRelease: 549 case KeyRelease:
550 case ButtonPress: 550 case ButtonPress:
551 case ButtonRelease: 551 case ButtonRelease:
552 case MotionNotify: 552 case MotionNotify:
553 setiv (time, xe->xmotion.time); 553 setiv (time, xe->xmotion.time);
554 setiv (x, xe->xmotion.x); 554 setiv (x, xe->xmotion.x);
555 setiv (y, xe->xmotion.y); 555 setiv (y, xe->xmotion.y);
556 setiv (row, xe->xmotion.y / term->fheight); 556 setiv (row, xe->xmotion.y / term->fheight);
557 setiv (col, xe->xmotion.x / term->fwidth); 557 setiv (col, xe->xmotion.x / term->fwidth);
558 setiv (x_root, xe->xmotion.x_root); 558 setiv (x_root, xe->xmotion.x_root);
559 setiv (y_root, xe->xmotion.y_root); 559 setiv (y_root, xe->xmotion.y_root);
560 setiv (state, xe->xmotion.state); 560 setiv (state, xe->xmotion.state);
561 break;
562 }
563
564 switch (xe->type)
565 {
566 case KeyPress:
567 case KeyRelease:
568 setiv (keycode, xe->xkey.keycode);
569 break;
570
571 case ButtonPress:
572 case ButtonRelease:
573 setiv (button, xe->xbutton.button);
574 break;
575
576 case MotionNotify:
577 setiv (is_hint, xe->xmotion.is_hint);
578 break;
579 }
580
581 XPUSHs (sv_2mortal (newRV_noinc ((SV *)hv)));
582 }
561 break; 583 break;
584
585 case DT_END:
586 goto call;
587
588 default:
589 rxvt_fatal ("FATAL: unable to pass data type %d\n", dt);
562 } 590 }
563
564 switch (xe->type)
565 {
566 case KeyPress:
567 case KeyRelease:
568 setiv (keycode, xe->xkey.keycode);
569 break;
570
571 case ButtonPress:
572 case ButtonRelease:
573 setiv (button, xe->xbutton.button);
574 break;
575
576 case MotionNotify:
577 setiv (is_hint, xe->xmotion.is_hint);
578 break;
579 }
580
581 XPUSHs (sv_2mortal (newRV_noinc ((SV *)hv)));
582 } 591 }
583 break;
584 592
585 case DT_END: 593 call:
586 {
587 va_end (ap); 594 va_end (ap);
588 595
589 PUTBACK; 596 PUTBACK;
590 int count = call_pv ("urxvt::invoke", G_ARRAY | G_EVAL); 597 int count = call_pv ("urxvt::invoke", G_ARRAY | G_EVAL);
591 SPAGAIN; 598 SPAGAIN;
592 599
593 if (count) 600 if (count)
594 { 601 {
595 SV *status = POPs; 602 SV *status = POPs;
596 count = SvTRUE (status); 603 count = SvTRUE (status);
597 } 604 }
598 605
599 PUTBACK; 606 PUTBACK;
600 FREETMPS; 607 FREETMPS;
601 LEAVE; 608 LEAVE;
602 609
603 if (SvTRUE (ERRSV)) 610 if (SvTRUE (ERRSV))
604 { 611 {
605 rxvt_warn ("perl hook %d evaluation error: %s", htype, SvPV_nolen (ERRSV)); 612 rxvt_warn ("perl hook %d evaluation error: %s", htype, SvPV_nolen (ERRSV));
606 ungrab (term); // better lose the grab than the session 613 ungrab (term); // better lose the grab than the session
607 } 614 }
608 615
609 if (htype == HOOK_DESTROY) 616 event_consumed = !!count;
610 {
611 clearSVptr ((SV *)term->perl.self);
612 SvREFCNT_dec ((SV *)term->perl.self);
613 }
614
615 return count;
616 }
617
618 default:
619 rxvt_fatal ("FATAL: unable to pass data type %d\n", dt);
620 } 617 }
618 catch (...)
619 {
620 swap (perl_environ, environ);
621 throw;
622 }
623 else
624 event_consumed = false;
625
626 // post-handling of some events
627 if (htype == HOOK_REFRESH_BEGIN)
628 swap_overlays (term);
629 else if (htype == HOOK_DESTROY)
630 {
631 clearSVptr ((SV *)term->perl.self);
632 SvREFCNT_dec ((SV *)term->perl.self);
621 } 633 }
634
635 swap (perl_environ, environ);
636
637 return event_consumed;
622} 638}
623 639
624///////////////////////////////////////////////////////////////////////////// 640/////////////////////////////////////////////////////////////////////////////
625 641
626MODULE = urxvt PACKAGE = urxvt 642MODULE = urxvt PACKAGE = urxvt
627 643
628PROTOTYPES: ENABLE 644PROTOTYPES: ENABLE
629 645
630BOOT: 646BOOT:
631{ 647{
632 sv_setsv (get_sv ("urxvt::LIBDIR", 1), newSVpvn (LIBDIR, sizeof (LIBDIR) - 1)); 648 sv_setsv (get_sv ("urxvt::LIBDIR", 1), newSVpvn (LIBDIR, sizeof (LIBDIR) - 1));
649 sv_setsv (get_sv ("urxvt::RESNAME", 1), newSVpvn (RESNAME, sizeof (RESNAME) - 1));
650 sv_setsv (get_sv ("urxvt::RESCLASS", 1), newSVpvn (RESCLASS, sizeof (RESCLASS) - 1));
651 sv_setsv (get_sv ("urxvt::RXVTNAME", 1), newSVpvn (RXVTNAME, sizeof (RXVTNAME) - 1));
633 652
634 AV *hookname = get_av ("urxvt::HOOKNAME", 1); 653 AV *hookname = get_av ("urxvt::HOOKNAME", 1);
635# define def(sym) av_store (hookname, HOOK_ ## sym, newSVpv (# sym, 0)); 654# define def(sym) av_store (hookname, HOOK_ ## sym, newSVpv (# sym, 0));
636# include "hookinc.h" 655# include "hookinc.h"
637# undef def 656# undef def
642# include "optinc.h" 661# include "optinc.h"
643# undef nodef 662# undef nodef
644# undef def 663# undef def
645 664
646 HV *stash = gv_stashpv ("urxvt", 1); 665 HV *stash = gv_stashpv ("urxvt", 1);
647# define export_const_iv(name) newCONSTSUB (stash, # name, newSViv (name)); 666 struct {
667 const char *name;
668 IV iv;
669 } *civ, const_iv[] = {
670# define const_iv(name) { # name, (IV)name }
648 export_const_iv (DEFAULT_RSTYLE); 671 const_iv (DEFAULT_RSTYLE),
649 export_const_iv (OVERLAY_RSTYLE); 672 const_iv (OVERLAY_RSTYLE),
650 export_const_iv (RS_Bold); 673 const_iv (RS_Bold),
651 export_const_iv (RS_Italic); 674 const_iv (RS_Italic),
652 export_const_iv (RS_Blink); 675 const_iv (RS_Blink),
653 export_const_iv (RS_RVid); 676 const_iv (RS_RVid),
654 export_const_iv (RS_Uline); 677 const_iv (RS_Uline),
655 678
656 export_const_iv (CurrentTime); 679 const_iv (CurrentTime),
657 export_const_iv (ShiftMask); 680 const_iv (ShiftMask),
658 export_const_iv (LockMask); 681 const_iv (LockMask),
659 export_const_iv (ControlMask); 682 const_iv (ControlMask),
660 export_const_iv (Mod1Mask); 683 const_iv (Mod1Mask),
661 export_const_iv (Mod2Mask); 684 const_iv (Mod2Mask),
662 export_const_iv (Mod3Mask); 685 const_iv (Mod3Mask),
663 export_const_iv (Mod4Mask); 686 const_iv (Mod4Mask),
664 export_const_iv (Mod5Mask); 687 const_iv (Mod5Mask),
665 export_const_iv (Button1Mask); 688 const_iv (Button1Mask),
666 export_const_iv (Button2Mask); 689 const_iv (Button2Mask),
667 export_const_iv (Button3Mask); 690 const_iv (Button3Mask),
668 export_const_iv (Button4Mask); 691 const_iv (Button4Mask),
669 export_const_iv (Button5Mask); 692 const_iv (Button5Mask),
670 export_const_iv (AnyModifier); 693 const_iv (AnyModifier),
671 694
672 export_const_iv (EVENT_NONE); 695 const_iv (EVENT_NONE),
673 export_const_iv (EVENT_READ); 696 const_iv (EVENT_READ),
674 export_const_iv (EVENT_WRITE); 697 const_iv (EVENT_WRITE),
675}
676 698
677SV * 699 const_iv (NoEventMask),
678new (...) 700 const_iv (KeyPressMask),
679 CODE: 701 const_iv (KeyReleaseMask),
680{ 702 const_iv (ButtonPressMask),
681 stringvec *argv = new stringvec; 703 const_iv (ButtonReleaseMask),
682 bool success; 704 const_iv (EnterWindowMask),
705 const_iv (LeaveWindowMask),
706 const_iv (PointerMotionMask),
707 const_iv (PointerMotionHintMask),
708 const_iv (Button1MotionMask),
709 const_iv (Button2MotionMask),
710 const_iv (Button3MotionMask),
711 const_iv (Button4MotionMask),
712 const_iv (Button5MotionMask),
713 const_iv (ButtonMotionMask),
714 const_iv (KeymapStateMask),
715 const_iv (ExposureMask),
716 const_iv (VisibilityChangeMask),
717 const_iv (StructureNotifyMask),
718 const_iv (ResizeRedirectMask),
719 const_iv (SubstructureNotifyMask),
720 const_iv (SubstructureRedirectMask),
721 const_iv (FocusChangeMask),
722 const_iv (PropertyChangeMask),
723 const_iv (ColormapChangeMask),
724 const_iv (OwnerGrabButtonMask),
683 725
684 for (int i = 0; i < items ;i++) 726 const_iv (KeyPress),
685 argv->push_back (strdup (SvPVbyte_nolen (ST (i)))); 727 const_iv (KeyRelease),
728 const_iv (ButtonPress),
729 const_iv (ButtonRelease),
730 const_iv (MotionNotify),
731 const_iv (EnterNotify),
732 const_iv (LeaveNotify),
733 const_iv (FocusIn),
734 const_iv (FocusOut),
735 const_iv (KeymapNotify),
736 const_iv (Expose),
737 const_iv (GraphicsExpose),
738 const_iv (NoExpose),
739 const_iv (VisibilityNotify),
740 const_iv (CreateNotify),
741 const_iv (DestroyNotify),
742 const_iv (UnmapNotify),
743 const_iv (MapNotify),
744 const_iv (MapRequest),
745 const_iv (ReparentNotify),
746 const_iv (ConfigureNotify),
747 const_iv (ConfigureRequest),
748 const_iv (GravityNotify),
749 const_iv (ResizeRequest),
750 const_iv (CirculateNotify),
751 const_iv (CirculateRequest),
752 const_iv (PropertyNotify),
753 const_iv (SelectionClear),
754 const_iv (SelectionRequest),
755 const_iv (SelectionNotify),
756 const_iv (ColormapNotify),
757 const_iv (ClientMessage),
758 const_iv (MappingNotify),
759 };
686 760
687 rxvt_term *term = new rxvt_term; 761 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]);
688 762 civ-- > const_iv; )
689 term->argv = argv; 763 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv));
690
691 try
692 {
693 if (!term->init (argv->size (), argv->begin ()))
694 term = 0;
695 }
696 catch (const class rxvt_failure_exception &e)
697 {
698 term->destroy ();
699 croak ("exception caught while initializing new terminal instance");
700 }
701
702 RETVAL = term && term->perl.self ? newSVterm (term) : &PL_sv_undef;
703} 764}
704 OUTPUT:
705 RETVAL
706
707void
708set_should_invoke (int htype, int value)
709 CODE:
710 rxvt_perl.should_invoke [htype] = value;
711 765
712void 766void
713warn (const char *msg) 767warn (const char *msg)
714 CODE: 768 CODE:
715 rxvt_warn ("%s", msg); 769 rxvt_warn ("%s", msg);
717void 771void
718fatal (const char *msg) 772fatal (const char *msg)
719 CODE: 773 CODE:
720 rxvt_fatal ("%s", msg); 774 rxvt_fatal ("%s", msg);
721 775
722SV * 776void
723untaint (SV *sv) 777_exit (int status)
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 778
737NV 779NV
738NOW () 780NOW ()
739 CODE: 781 CODE:
740 RETVAL = NOW; 782 RETVAL = NOW;
789 OUTPUT: 831 OUTPUT:
790 RETVAL 832 RETVAL
791 833
792MODULE = urxvt PACKAGE = urxvt::term 834MODULE = urxvt PACKAGE = urxvt::term
793 835
836SV *
837_new (...)
838 CODE:
839{
840 if (items < 1 || !SvROK (ST (0)) || SvTYPE (SvRV (ST (0))) != SVt_PVAV)
841 croak ("first argument to urxvt::term->_new must be arrayref");
842
843 rxvt_term *term = new rxvt_term;
844
845 term->argv = new stringvec;
846 term->envv = new stringvec;
847
848 for (int i = 1; i < items; i++)
849 term->argv->push_back (strdup (SvPVbyte_nolen (ST (i))));
850
851 AV *envv = (AV *)SvRV (ST (0));
852 for (int i = av_len (envv) + 1; i--; )
853 term->envv->push_back (strdup (SvPVbyte_nolen (*av_fetch (envv, i, 1))));
854
855 term->envv->push_back (0);
856
857 bool success;
858
859 try
860 {
861 success = term->init (term->argv->size (), term->argv->begin ());
862 }
863 catch (const class rxvt_failure_exception &e)
864 {
865 success = false;
866 }
867
868 if (!success)
869 {
870 term->destroy ();
871 croak ("error while initializing new terminal instance");
872 }
873
874 RETVAL = term && term->perl.self
875 ? newSVterm (term) : &PL_sv_undef;
876}
877 OUTPUT:
878 RETVAL
879
794void 880void
795rxvt_term::destroy () 881rxvt_term::destroy ()
882
883#if ENABLE_PERL_FRILLS
884
885void
886rxvt_term::XListProperties (U32 window)
887 PPCODE:
888{
889 int count;
890 Atom *props = XListProperties (THIS->display->display, (Window)window, &count);
891
892 EXTEND (SP, count);
893 while (count--)
894 PUSHs (newSVuv ((U32)props [count]));
895
896 XFree (props);
897}
898
899void
900rxvt_term::XGetWindowProperty (U32 window, U32 property)
901 PPCODE:
902{
903 Atom type;
904 int format;
905 unsigned long nitems;
906 unsigned long bytes_after;
907 unsigned char *prop;
908 XGetWindowProperty (THIS->display->display, (Window)window, (Atom)property,
909 0, 1<<30, 0, AnyPropertyType,
910 &type, &format, &nitems, &bytes_after, &prop);
911 if (type != None)
912 {
913 EXTEND (SP, 3);
914 PUSHs (newSVuv ((U32)type));
915 PUSHs (newSViv (format));
916 PUSHs (newSVpvn ((char *)prop, nitems * format / 8));
917 XFree (prop);
918 }
919}
920
921void
922rxvt_term::XChangeWindowProperty (U32 window, U32 property, U32 type, int format, SV *data)
923 CODE:
924{
925 STRLEN len;
926 char *data_ = SvPVbyte (data, len);
927
928 XChangeProperty (THIS->display->display, (Window)window, (Atom)property,
929 type, format, PropModeReplace,
930 (unsigned char *)data, len * 8 / format);
931}
932
933void
934rxvt_term::XDeleteProperty (U32 window, U32 property)
935 CODE:
936 XDeleteProperty (THIS->display->display, (Window)window, (Atom)property);
937
938U32
939rxvt_term::DefaultRootWindow ()
940 CODE:
941 RETVAL = (U32)THIS->display->root;
942 OUTPUT:
943 RETVAL
944
945U32
946rxvt_term::XCreateSimpleWindow (U32 parent, int x, int y, unsigned int width, unsigned int height)
947 CODE:
948 RETVAL = XCreateSimpleWindow (THIS->display->display, (Window)parent,
949 x, y, width, height, 0,
950 THIS->pix_colors_focused[Color_border],
951 THIS->pix_colors_focused[Color_border]);
952 OUTPUT:
953 RETVAL
954
955void
956rxvt_term::XReparentWindow (U32 window, U32 parent, int x = 0, int y = 0)
957 CODE:
958 XReparentWindow (THIS->display->display, (Window)window, (Window)parent, x, y);
959
960void
961rxvt_term::XMapWindow (U32 window)
962 CODE:
963 XMapWindow (THIS->display->display, (Window)window);
964
965void
966rxvt_term::XUnmapWindow (U32 window)
967 CODE:
968 XUnmapWindow (THIS->display->display, (Window)window);
969
970#endif
971
972void
973rxvt_term::set_should_invoke (int htype, int inc)
974 CODE:
975 THIS->perl.should_invoke [htype] += inc;
796 976
797void 977void
798rxvt_term::grab_button (int button, U32 modifiers) 978rxvt_term::grab_button (int button, U32 modifiers)
799 CODE: 979 CODE:
800 XGrabButton (THIS->display->display, button, modifiers, THIS->vt, 1, 980 XGrabButton (THIS->display->display, button, modifiers, THIS->vt, 1,
868 char *mbstr = rxvt_wcstombs (wstr); 1048 char *mbstr = rxvt_wcstombs (wstr);
869 rxvt_pop_locale (); 1049 rxvt_pop_locale ();
870 1050
871 free (wstr); 1051 free (wstr);
872 1052
873 RETVAL = taint_if (newSVpv (mbstr, 0), str); 1053 RETVAL = newSVpv (mbstr, 0);
874 free (mbstr); 1054 free (mbstr);
875} 1055}
876 OUTPUT: 1056 OUTPUT:
877 RETVAL 1057 RETVAL
878 1058
885 1065
886 rxvt_push_locale (THIS->locale); 1066 rxvt_push_locale (THIS->locale);
887 wchar_t *wstr = rxvt_mbstowcs (data, len); 1067 wchar_t *wstr = rxvt_mbstowcs (data, len);
888 rxvt_pop_locale (); 1068 rxvt_pop_locale ();
889 1069
890 RETVAL = taint_if (wcs2sv (wstr), octets); 1070 RETVAL = wcs2sv (wstr);
891 free (wstr); 1071 free (wstr);
892} 1072}
893 OUTPUT: 1073 OUTPUT:
894 RETVAL 1074 RETVAL
895 1075
904#define TERM_OFFSET_ncol TERM_OFFSET(ncol) 1084#define TERM_OFFSET_ncol TERM_OFFSET(ncol)
905#define TERM_OFFSET_focus TERM_OFFSET(focus) 1085#define TERM_OFFSET_focus TERM_OFFSET(focus)
906#define TERM_OFFSET_mapped TERM_OFFSET(mapped) 1086#define TERM_OFFSET_mapped TERM_OFFSET(mapped)
907#define TERM_OFFSET_saveLines TERM_OFFSET(saveLines) 1087#define TERM_OFFSET_saveLines TERM_OFFSET(saveLines)
908#define TERM_OFFSET_total_rows TERM_OFFSET(total_rows) 1088#define TERM_OFFSET_total_rows TERM_OFFSET(total_rows)
909#define TERM_OFFSET_nsaved TERM_OFFSET(nsaved) 1089#define TERM_OFFSET_top_row TERM_OFFSET(top_row)
910 1090
911int 1091int
912rxvt_term::width () 1092rxvt_term::width ()
913 ALIAS: 1093 ALIAS:
914 width = TERM_OFFSET_width 1094 width = TERM_OFFSET_width
920 ncol = TERM_OFFSET_ncol 1100 ncol = TERM_OFFSET_ncol
921 focus = TERM_OFFSET_focus 1101 focus = TERM_OFFSET_focus
922 mapped = TERM_OFFSET_mapped 1102 mapped = TERM_OFFSET_mapped
923 saveLines = TERM_OFFSET_saveLines 1103 saveLines = TERM_OFFSET_saveLines
924 total_rows = TERM_OFFSET_total_rows 1104 total_rows = TERM_OFFSET_total_rows
925 nsaved = TERM_OFFSET_nsaved 1105 top_row = TERM_OFFSET_top_row
926 CODE: 1106 CODE:
927 RETVAL = *(int *)((char *)THIS + ix); 1107 RETVAL = *(int *)((char *)THIS + ix);
928 OUTPUT: 1108 OUTPUT:
929 RETVAL 1109 RETVAL
930 1110
956 case 1: RETVAL = THIS->locale; break; 1136 case 1: RETVAL = THIS->locale; break;
957 } 1137 }
958 OUTPUT: 1138 OUTPUT:
959 RETVAL 1139 RETVAL
960 1140
1141SV *
1142rxvt_term::_env ()
1143 CODE:
1144{
1145 if (THIS->envv)
1146 {
1147 AV *av = newAV ();
1148
1149 for (char **i = THIS->envv->begin (); i != THIS->envv->end (); ++i)
1150 if (*i)
1151 av_push (av, newSVpv (*i, 0));
1152
1153 RETVAL = newRV_noinc ((SV *)av);
1154 }
1155 else
1156 RETVAL = &PL_sv_undef;
1157}
1158 OUTPUT:
1159 RETVAL
1160
961int 1161int
962rxvt_term::pty_ev_events (int events = EVENT_UNDEF) 1162rxvt_term::pty_ev_events (int events = EVENT_UNDEF)
963 CODE: 1163 CODE:
964 RETVAL = THIS->pty_ev.events; 1164 RETVAL = THIS->pty_ev.events;
965 if (events != EVENT_UNDEF) 1165 if (events != EVENT_UNDEF)
979 CODE: 1179 CODE:
980 RETVAL = (U32)THIS->vt; 1180 RETVAL = (U32)THIS->vt;
981 OUTPUT: 1181 OUTPUT:
982 RETVAL 1182 RETVAL
983 1183
1184void
1185rxvt_term::vt_emask_add (U32 emask)
1186 CODE:
1187 THIS->vt_emask_perl |= emask;
1188 THIS->vt_select_input ();
1189
984U32 1190U32
985rxvt_term::rstyle (U32 new_rstyle = THIS->rstyle) 1191rxvt_term::rstyle (U32 new_rstyle = THIS->rstyle)
986 CODE: 1192 CODE:
987{
988 RETVAL = THIS->rstyle; 1193 RETVAL = THIS->rstyle;
989 THIS->rstyle = new_rstyle; 1194 THIS->rstyle = new_rstyle;
990}
991 OUTPUT: 1195 OUTPUT:
992 RETVAL 1196 RETVAL
993 1197
994int 1198int
995rxvt_term::view_start (int newval = -1) 1199rxvt_term::view_start (int newval = 1)
1200 PROTOTYPE: $;$
996 CODE: 1201 CODE:
997{ 1202{
998 RETVAL = THIS->view_start; 1203 RETVAL = THIS->view_start;
999 1204
1000 if (newval >= 0) 1205 if (newval <= 0)
1001 { 1206 THIS->scr_changeview (max (newval, THIS->top_row));
1002 THIS->view_start = min (newval, THIS->nsaved);
1003 THIS->scr_changeview (RETVAL);
1004 }
1005} 1207}
1006 OUTPUT: 1208 OUTPUT:
1007 RETVAL 1209 RETVAL
1008 1210
1009void 1211void
1013 1215
1014void 1216void
1015rxvt_term::ROW_t (int row_number, SV *new_text = 0, int start_col = 0, int start_ofs = 0, int max_len = MAX_COLS) 1217rxvt_term::ROW_t (int row_number, SV *new_text = 0, int start_col = 0, int start_ofs = 0, int max_len = MAX_COLS)
1016 PPCODE: 1218 PPCODE:
1017{ 1219{
1018 if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) 1220 if (!IN_RANGE_EXC (row_number, THIS->top_row, THIS->nrow))
1019 XSRETURN_EMPTY; 1221 XSRETURN_EMPTY;
1020 1222
1021 line_t &l = ROW(row_number); 1223 line_t &l = ROW(row_number);
1022 1224
1023 if (GIMME_V != G_VOID) 1225 if (GIMME_V != G_VOID)
1025 wchar_t *wstr = new wchar_t [THIS->ncol]; 1227 wchar_t *wstr = new wchar_t [THIS->ncol];
1026 1228
1027 for (int col = 0; col < THIS->ncol; col++) 1229 for (int col = 0; col < THIS->ncol; col++)
1028 wstr [col] = l.t [col]; 1230 wstr [col] = l.t [col];
1029 1231
1030 XPUSHs (taint (sv_2mortal (wcs2sv (wstr, THIS->ncol)))); 1232 XPUSHs (sv_2mortal (wcs2sv (wstr, THIS->ncol)));
1031 1233
1032 delete [] wstr; 1234 delete [] wstr;
1033 } 1235 }
1034 1236
1035 if (new_text) 1237 if (new_text)
1056 1258
1057void 1259void
1058rxvt_term::ROW_r (int row_number, SV *new_rend = 0, int start_col = 0, int start_ofs = 0, int max_len = MAX_COLS) 1260rxvt_term::ROW_r (int row_number, SV *new_rend = 0, int start_col = 0, int start_ofs = 0, int max_len = MAX_COLS)
1059 PPCODE: 1261 PPCODE:
1060{ 1262{
1061 if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) 1263 if (!IN_RANGE_EXC (row_number, THIS->top_row, THIS->nrow))
1062 XSRETURN_EMPTY; 1264 XSRETURN_EMPTY;
1063 1265
1064 line_t &l = ROW(row_number); 1266 line_t &l = ROW(row_number);
1065 1267
1066 if (GIMME_V != G_VOID) 1268 if (GIMME_V != G_VOID)
1096 1298
1097int 1299int
1098rxvt_term::ROW_l (int row_number, int new_length = -1) 1300rxvt_term::ROW_l (int row_number, int new_length = -1)
1099 CODE: 1301 CODE:
1100{ 1302{
1101 if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) 1303 if (!IN_RANGE_EXC (row_number, THIS->top_row, THIS->nrow))
1102 XSRETURN_EMPTY; 1304 XSRETURN_EMPTY;
1103 1305
1104 line_t &l = ROW(row_number); 1306 line_t &l = ROW(row_number);
1105 RETVAL = l.l; 1307 RETVAL = l.l;
1106 1308
1112 1314
1113bool 1315bool
1114rxvt_term::ROW_is_longer (int row_number, int new_is_longer = -1) 1316rxvt_term::ROW_is_longer (int row_number, int new_is_longer = -1)
1115 CODE: 1317 CODE:
1116{ 1318{
1117 if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) 1319 if (!IN_RANGE_EXC (row_number, THIS->top_row, THIS->nrow))
1118 XSRETURN_EMPTY; 1320 XSRETURN_EMPTY;
1119 1321
1120 line_t &l = ROW(row_number); 1322 line_t &l = ROW(row_number);
1121 RETVAL = l.is_longer (); 1323 RETVAL = l.is_longer ();
1122 1324
1156 else 1358 else
1157 *r++ = *s; 1359 *r++ = *s;
1158 1360
1159 rxvt_pop_locale (); 1361 rxvt_pop_locale ();
1160 1362
1161 RETVAL = taint_if (wcs2sv (rstr, r - rstr), string); 1363 RETVAL = wcs2sv (rstr, r - rstr);
1162 1364
1163 delete [] rstr; 1365 delete [] rstr;
1164} 1366}
1165 OUTPUT: 1367 OUTPUT:
1166 RETVAL 1368 RETVAL
1192 else if (IS_COMPOSE (*s)) 1394 else if (IS_COMPOSE (*s))
1193 r += rxvt_composite.expand (*s, r); 1395 r += rxvt_composite.expand (*s, r);
1194 else 1396 else
1195 *r++ = *s; 1397 *r++ = *s;
1196 1398
1197 RETVAL = taint_if (wcs2sv (rstr, r - rstr), text); 1399 RETVAL = wcs2sv (rstr, r - rstr);
1198 1400
1199 delete [] rstr; 1401 delete [] rstr;
1200} 1402}
1201 OUTPUT: 1403 OUTPUT:
1202 RETVAL 1404 RETVAL
1224 1426
1225 if (!IN_RANGE_EXC (index, 0, NUM_RESOURCES)) 1427 if (!IN_RANGE_EXC (index, 0, NUM_RESOURCES))
1226 croak ("requested out-of-bound resource %s+%d,", name, index - rs->value); 1428 croak ("requested out-of-bound resource %s+%d,", name, index - rs->value);
1227 1429
1228 if (GIMME_V != G_VOID) 1430 if (GIMME_V != G_VOID)
1229 XPUSHs (THIS->rs [index] ? sv_2mortal (taint (newSVpv (THIS->rs [index], 0))) : &PL_sv_undef); 1431 XPUSHs (THIS->rs [index] ? sv_2mortal (newSVpv (THIS->rs [index], 0)) : &PL_sv_undef);
1230 1432
1231 if (newval) 1433 if (newval)
1232 { 1434 {
1233 if (SvOK (newval)) 1435 if (SvOK (newval))
1234 { 1436 {
1239 else 1441 else
1240 THIS->rs [index] = 0; 1442 THIS->rs [index] = 0;
1241 } 1443 }
1242} 1444}
1243 1445
1446const char *
1447rxvt_term::x_resource (const char *name)
1448
1244bool 1449bool
1245rxvt_term::option (U32 optval, int set = -1) 1450rxvt_term::option (U32 optval, int set = -1)
1246 CODE: 1451 CODE:
1247{ 1452{
1248 RETVAL = THIS->options & optval; 1453 RETVAL = THIS->options & optval;
1307 PUSHs (sv_2mortal (newSViv (rc.col))); 1512 PUSHs (sv_2mortal (newSViv (rc.col)));
1308 } 1513 }
1309 1514
1310 if (items == 3) 1515 if (items == 3)
1311 { 1516 {
1312 rc.row = clamp (SvIV (ST (1)), -THIS->nsaved, THIS->nrow - 1); 1517 rc.row = clamp (SvIV (ST (1)), THIS->top_row, THIS->nrow - 1);
1313 rc.col = clamp (SvIV (ST (2)), 0, THIS->ncol - 1); 1518 rc.col = clamp (SvIV (ST (2)), 0, THIS->ncol - 1);
1314 1519
1315 if (ix) 1520 if (ix)
1316 THIS->want_refresh = 1; 1521 THIS->want_refresh = 1;
1317 } 1522 }
1318} 1523}
1319 1524
1525char
1526rxvt_term::cur_charset ()
1527 CODE:
1528 RETVAL = THIS->charsets [THIS->screen.charset];
1529 OUTPUT:
1530 RETVAL
1531
1532#void
1533#rxvt_term::selection_clear ()
1534
1535void
1536rxvt_term::selection_make (U32 eventtime, bool rect = false)
1537 CODE:
1538 THIS->selection.op = SELECTION_CONT;
1539 THIS->selection.rect = rect;
1540 THIS->selection_make (eventtime);
1541
1320int 1542int
1321rxvt_term::selection_grab (U32 eventtime) 1543rxvt_term::selection_grab (U32 eventtime)
1322 1544
1323void 1545void
1324rxvt_term::selection (SV *newtext = 0) 1546rxvt_term::selection (SV *newtext = 0)
1325 PPCODE: 1547 PPCODE:
1326{ 1548{
1327 if (GIMME_V != G_VOID) 1549 if (GIMME_V != G_VOID)
1328 XPUSHs (THIS->selection.text 1550 XPUSHs (THIS->selection.text
1329 ? taint (sv_2mortal (wcs2sv (THIS->selection.text, THIS->selection.len))) 1551 ? sv_2mortal (wcs2sv (THIS->selection.text, THIS->selection.len))
1330 : &PL_sv_undef); 1552 : &PL_sv_undef);
1331 1553
1332 if (newtext) 1554 if (newtext)
1333 { 1555 {
1334 free (THIS->selection.text); 1556 free (THIS->selection.text);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines