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.25 by root, Thu Jan 5 01:04:10 2006 UTC vs.
Revision 1.56 by root, Thu Jan 12 00:35:39 2006 UTC

1/*----------------------------------------------------------------------* 1/*----------------------------------------------------------------------*
2 * File: rxvtperl.xs 2 * File: rxvtperl.xs
3 *----------------------------------------------------------------------* 3 *----------------------------------------------------------------------*
4 * 4 *
5 * All portions of code are copyright by their respective author/s. 5 * All portions of code are copyright by their respective author/s.
6 * Copyright (c) 2005-2005 Marc Lehmann <pcg@goof.com> 6 * Copyright (c) 2005-2006 Marc Lehmann <pcg@goof.com>
7 * 7 *
8 * This program is free software; you can redistribute it and/or modify 8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by 9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or 10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version. 11 * (at your option) any later version.
26#include <XSUB.h> 26#include <XSUB.h>
27#undef line_t 27#undef line_t
28 28
29#include "../config.h" 29#include "../config.h"
30 30
31#include <cstddef>
31#include <cstdarg> 32#include <cstdarg>
32 33
34#include "iom.h"
33#include "rxvt.h" 35#include "rxvt.h"
34#include "iom.h" 36#include "keyboard.h"
35#include "rxvtutil.h" 37#include "rxvtutil.h"
36#include "rxvtperl.h" 38#include "rxvtperl.h"
37 39
38#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
39 47
40#undef LINENO 48#undef LINENO
41#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)
42#undef ROW 50#undef ROW
43#define ROW(n) THIS->row_buf [LINENO (n)] 51#define ROW(n) THIS->row_buf [LINENO (n)]
44 52
45///////////////////////////////////////////////////////////////////////////// 53/////////////////////////////////////////////////////////////////////////////
46 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
47static wchar_t * 71static wchar_t *
48sv2wcs (SV *sv) 72sv2wcs (SV *sv)
49{ 73{
50 STRLEN len; 74 STRLEN len;
51 char *str = SvPVutf8 (sv, len); 75 char *str = SvPVutf8 (sv, len);
101 croak ("perl code used %s object, but C++ object is already destroyed, caught", klass); 125 croak ("perl code used %s object, but C++ object is already destroyed, caught", klass);
102 126
103 return (long)mg->mg_ptr; 127 return (long)mg->mg_ptr;
104} 128}
105 129
106#define newSVterm(term) SvREFCNT_inc ((SV *)term->self) 130#define newSVterm(term) SvREFCNT_inc ((SV *)term->perl.self)
107#define SvTERM(sv) (rxvt_term *)SvPTR (sv, "urxvt::term") 131#define SvTERM(sv) (rxvt_term *)SvPTR (sv, "urxvt::term")
108 132
109///////////////////////////////////////////////////////////////////////////// 133/////////////////////////////////////////////////////////////////////////////
110 134
111struct perl_watcher 135struct perl_watcher
290void 314void
291overlay::show () 315overlay::show ()
292{ 316{
293 char key[33]; sprintf (key, "%32lx", (long)this); 317 char key[33]; sprintf (key, "%32lx", (long)this);
294 318
295 HV *hv = (HV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)THIS->self), "_overlay", 8, 0)); 319 HV *hv = (HV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)THIS->perl.self), "_overlay", 8, 0));
296 hv_store (hv, key, 32, newSViv ((long)this), 0); 320 hv_store (hv, key, 32, newSViv ((long)this), 0);
297} 321}
298 322
299void 323void
300overlay::hide () 324overlay::hide ()
301{ 325{
302 SV **ovs = hv_fetch ((HV *)SvRV ((SV *)THIS->self), "_overlay", 8, 0); 326 SV **ovs = hv_fetch ((HV *)SvRV ((SV *)THIS->perl.self), "_overlay", 8, 0);
303 327
304 if (ovs) 328 if (ovs)
305 { 329 {
306 char key[33]; sprintf (key, "%32lx", (long)this); 330 char key[33]; sprintf (key, "%32lx", (long)this);
307 331
387void 411void
388rxvt_perl_interp::init () 412rxvt_perl_interp::init ()
389{ 413{
390 if (!perl) 414 if (!perl)
391 { 415 {
416 temp_environ temp_environ(rxvt_environ);
417
392 char *argv[] = { 418 char *argv[] = {
393 "", 419 "",
420 "-T",
394 "-edo '" LIBDIR "/urxvt.pm' or ($@ and die $@) or exit 1", 421 "-edo '" LIBDIR "/urxvt.pm' or ($@ and die $@) or exit 1",
395 }; 422 };
396 423
397 perl = perl_alloc (); 424 perl = perl_alloc ();
398 perl_construct (perl); 425 perl_construct (perl);
399 426
400 if (perl_parse (perl, xs_init, 2, argv, (char **)NULL) 427 if (perl_parse (perl, xs_init, 3, argv, (char **)NULL)
401 || perl_run (perl)) 428 || perl_run (perl))
402 { 429 {
403 rxvt_warn ("unable to initialize perl-interpreter, continuing without.\n"); 430 rxvt_warn ("unable to initialize perl-interpreter, continuing without.\n");
404 431
405 perl_destruct (perl); 432 perl_destruct (perl);
407 perl = 0; 434 perl = 0;
408 } 435 }
409 } 436 }
410} 437}
411 438
439static void
440ungrab (rxvt_term *THIS)
441{
442 if (THIS->perl.grabtime)
443 {
444 XUngrabKeyboard (THIS->display->display, THIS->perl.grabtime);
445 XUngrabPointer (THIS->display->display, THIS->perl.grabtime);
446 THIS->perl.grabtime = 0;
447 }
448}
449
412bool 450bool
413rxvt_perl_interp::invoke (rxvt_term *term, hook_type htype, ...) 451rxvt_perl_interp::invoke (rxvt_term *term, hook_type htype, ...)
414{ 452{
415 if (!perl) 453 if (!perl)
416 return false; 454 return false;
417 455
418 if (htype == HOOK_INIT) // first hook ever called 456 if (htype == HOOK_INIT) // first hook ever called
419 { 457 {
420 term->self = (void *)newSVptr ((void *)term, "urxvt::term"); 458 term->perl.self = (void *)newSVptr ((void *)term, "urxvt::term");
421 hv_store ((HV *)SvRV ((SV *)term->self), "_overlay", 8, newRV_noinc ((SV *)newHV ()), 0); 459 hv_store ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, newRV_noinc ((SV *)newHV ()), 0);
422 } 460 }
423 else if (!term->self) 461 else if (!term->perl.self)
424 return false; // perl not initialized for this instance 462 return false; // perl not initialized for this instance
425 else if (htype == HOOK_DESTROY) 463 else if (htype == HOOK_DESTROY)
426 { 464 {
427 // handled later 465 // handled later
428 } 466 }
429 else if (htype == HOOK_REFRESH_BEGIN || htype == HOOK_REFRESH_END) 467 else
430 { 468 {
431 HV *hv = (HV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->self), "_overlay", 8, 0)); 469 if (htype == HOOK_REFRESH_BEGIN || htype == HOOK_REFRESH_END)
432
433 if (HvKEYS (hv))
434 { 470 {
471 HV *hv = (HV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, 0));
472
473 if (HvKEYS (hv))
474 {
435 hv_iterinit (hv); 475 hv_iterinit (hv);
436 476
437 while (HE *he = hv_iternext (hv)) 477 while (HE *he = hv_iternext (hv))
438 ((overlay *)SvIV (hv_iterval (hv, he)))->swap (); 478 ((overlay *)SvIV (hv_iterval (hv, he)))->swap ();
479 }
480
439 } 481 }
482
483 if (!should_invoke [htype])
484 return false;
440 } 485 }
441 else if (!should_invoke [htype]) 486
442 return false; 487 temp_environ temp_environ(rxvt_environ);
443 488
444 dSP; 489 dSP;
445 va_list ap; 490 va_list ap;
446 491
447 va_start (ap, htype); 492 va_start (ap, htype);
465 510
466 case DT_LONG: 511 case DT_LONG:
467 XPUSHs (sv_2mortal (newSViv (va_arg (ap, long)))); 512 XPUSHs (sv_2mortal (newSViv (va_arg (ap, long))));
468 break; 513 break;
469 514
470 case DT_STRING: 515 case DT_STR:
471 XPUSHs (sv_2mortal (newSVpv (va_arg (ap, char *), 0))); 516 XPUSHs (taint (sv_2mortal (newSVpv (va_arg (ap, char *), 0))));
472 break; 517 break;
473 518
474 case DT_USTRING_LEN: 519 case DT_STR_LEN:
475 { 520 {
476 unicode_t *ustr = va_arg (ap, unicode_t *); 521 char *str = va_arg (ap, char *);
477 int ulen = va_arg (ap, int); 522 int len = va_arg (ap, int);
523
524 XPUSHs (taint (sv_2mortal (newSVpvn (str, len))));
525 }
526 break;
527
528 case DT_WCS_LEN:
529 {
478 wchar_t *wstr = new wchar_t [ulen]; 530 wchar_t *wstr = va_arg (ap, wchar_t *);
531 int wlen = va_arg (ap, int);
479 532
480 for (int i = ulen; i--; )
481 wstr [i] = ustr [i];
482
483 XPUSHs (sv_2mortal (wcs2sv (wstr, ulen))); 533 XPUSHs (taint (sv_2mortal (wcs2sv (wstr, wlen))));
534 }
535 break;
484 536
485 delete [] wstr; 537 case DT_XEVENT:
486 } 538 {
539 XEvent *xe = va_arg (ap, XEvent *);
540 HV *hv = newHV ();
541
542# define set(name, sv) hv_store (hv, # name, sizeof (# name) - 1, sv, 0)
543# define setiv(name, val) hv_store (hv, # name, sizeof (# name) - 1, newSViv (val), 0)
544# undef set
545
546 setiv (type, xe->type);
547 setiv (send_event, xe->xany.send_event);
548 setiv (serial, xe->xany.serial);
549
550 switch (xe->type)
551 {
552 case KeyPress:
553 case KeyRelease:
554 case ButtonPress:
555 case ButtonRelease:
556 case MotionNotify:
557 setiv (time, xe->xmotion.time);
558 setiv (x, xe->xmotion.x);
559 setiv (y, xe->xmotion.y);
560 setiv (row, xe->xmotion.y / term->fheight);
561 setiv (col, xe->xmotion.x / term->fwidth);
562 setiv (x_root, xe->xmotion.x_root);
563 setiv (y_root, xe->xmotion.y_root);
564 setiv (state, xe->xmotion.state);
565 break;
566 }
567
568 switch (xe->type)
569 {
570 case KeyPress:
571 case KeyRelease:
572 setiv (keycode, xe->xkey.keycode);
573 break;
574
575 case ButtonPress:
576 case ButtonRelease:
577 setiv (button, xe->xbutton.button);
578 break;
579
580 case MotionNotify:
581 setiv (is_hint, xe->xmotion.is_hint);
582 break;
583 }
584
585 XPUSHs (sv_2mortal (newRV_noinc ((SV *)hv)));
586 }
587 break;
487 588
488 case DT_END: 589 case DT_END:
489 { 590 {
490 va_end (ap); 591 va_end (ap);
491 592
502 PUTBACK; 603 PUTBACK;
503 FREETMPS; 604 FREETMPS;
504 LEAVE; 605 LEAVE;
505 606
506 if (SvTRUE (ERRSV)) 607 if (SvTRUE (ERRSV))
608 {
507 rxvt_warn ("perl hook %d evaluation error: %s", htype, SvPV_nolen (ERRSV)); 609 rxvt_warn ("perl hook %d evaluation error: %s", htype, SvPV_nolen (ERRSV));
610 ungrab (term); // better lose the grab than the session
611 }
508 612
509 if (htype == HOOK_DESTROY) 613 if (htype == HOOK_DESTROY)
510 { 614 {
511 clearSVptr ((SV *)term->self); 615 clearSVptr ((SV *)term->perl.self);
512 SvREFCNT_dec ((SV *)term->self); 616 SvREFCNT_dec ((SV *)term->perl.self);
513 } 617 }
514 618
515 return count; 619 return count;
516 } 620 }
517 621
527 631
528PROTOTYPES: ENABLE 632PROTOTYPES: ENABLE
529 633
530BOOT: 634BOOT:
531{ 635{
532# define export_const(name) newCONSTSUB (gv_stashpv ("urxvt", 1), # name, newSViv (name)); 636 sv_setsv (get_sv ("urxvt::LIBDIR", 1), newSVpvn (LIBDIR, sizeof (LIBDIR) - 1));
637 sv_setsv (get_sv ("urxvt::RESNAME", 1), newSVpvn (RESNAME, sizeof (RESNAME) - 1));
638 sv_setsv (get_sv ("urxvt::RESCLASS", 1), newSVpvn (RESCLASS, sizeof (RESCLASS) - 1));
639 sv_setsv (get_sv ("urxvt::RXVTNAME", 1), newSVpvn (RXVTNAME, sizeof (RXVTNAME) - 1));
640
533 AV *hookname = get_av ("urxvt::HOOKNAME", 1); 641 AV *hookname = get_av ("urxvt::HOOKNAME", 1);
534# define def(sym) av_store (hookname, HOOK_ ## sym, newSVpv (# sym, 0)); 642# define def(sym) av_store (hookname, HOOK_ ## sym, newSVpv (# sym, 0));
535# include "hookinc.h" 643# include "hookinc.h"
536# undef def 644# undef def
537 645
646 HV *option = get_hv ("urxvt::OPTION", 1);
647# define def(name,val) hv_store (option, # name, sizeof (# name) - 1, newSVuv (Opt_ ## name), 0);
648# define nodef(name)
649# include "optinc.h"
650# undef nodef
651# undef def
652
653 HV *stash = gv_stashpv ("urxvt", 1);
654# define export_const_iv(name) newCONSTSUB (stash, # name, newSViv (name));
538 export_const (DEFAULT_RSTYLE); 655 export_const_iv (DEFAULT_RSTYLE);
539 export_const (OVERLAY_RSTYLE); 656 export_const_iv (OVERLAY_RSTYLE);
540 export_const (RS_Bold); 657 export_const_iv (RS_Bold);
541 export_const (RS_Italic); 658 export_const_iv (RS_Italic);
542 export_const (RS_Blink); 659 export_const_iv (RS_Blink);
543 export_const (RS_RVid); 660 export_const_iv (RS_RVid);
544 export_const (RS_Uline); 661 export_const_iv (RS_Uline);
545 662
546 sv_setpv (get_sv ("urxvt::LIBDIR", 1), LIBDIR); 663 export_const_iv (CurrentTime);
664 export_const_iv (ShiftMask);
665 export_const_iv (LockMask);
666 export_const_iv (ControlMask);
667 export_const_iv (Mod1Mask);
668 export_const_iv (Mod2Mask);
669 export_const_iv (Mod3Mask);
670 export_const_iv (Mod4Mask);
671 export_const_iv (Mod5Mask);
672 export_const_iv (Button1Mask);
673 export_const_iv (Button2Mask);
674 export_const_iv (Button3Mask);
675 export_const_iv (Button4Mask);
676 export_const_iv (Button5Mask);
677 export_const_iv (AnyModifier);
678
679 export_const_iv (EVENT_NONE);
680 export_const_iv (EVENT_READ);
681 export_const_iv (EVENT_WRITE);
547} 682}
548 683
549void 684void
550set_should_invoke (int htype, int value) 685set_should_invoke (int htype, int value)
551 CODE: 686 CODE:
558 693
559void 694void
560fatal (const char *msg) 695fatal (const char *msg)
561 CODE: 696 CODE:
562 rxvt_fatal ("%s", msg); 697 rxvt_fatal ("%s", msg);
698
699SV *
700untaint (SV *sv)
701 CODE:
702 RETVAL = newSVsv (sv);
703 SvTAINTED_off (RETVAL);
704 OUTPUT:
705 RETVAL
706
707bool
708safe ()
709 CODE:
710 RETVAL = !rxvt_tainted ();
711 OUTPUT:
712 RETVAL
563 713
564NV 714NV
565NOW () 715NOW ()
566 CODE: 716 CODE:
567 RETVAL = NOW; 717 RETVAL = NOW;
615} 765}
616 OUTPUT: 766 OUTPUT:
617 RETVAL 767 RETVAL
618 768
619MODULE = urxvt PACKAGE = urxvt::term 769MODULE = urxvt PACKAGE = urxvt::term
770
771SV *
772_new (...)
773 CODE:
774{
775 if (items < 1 || !SvROK (ST (0)) || SvTYPE (SvRV (ST (0))) != SVt_PVAV)
776 croak ("first argument to urxvt::term->_new must be arrayref");
777
778 rxvt_term *term = new rxvt_term;
779
780 term->argv = new stringvec;
781 term->envv = new stringvec;
782
783 for (int i = 1; i < items; i++)
784 term->argv->push_back (strdup (SvPVbyte_nolen (ST (i))));
785
786 AV *envv = (AV *)SvRV (ST (0));
787 for (int i = av_len (envv) + 1; i--; )
788 term->envv->push_back (strdup (SvPVbyte_nolen (*av_fetch (envv, i, 1))));
789
790 term->envv->push_back (0);
791
792 bool success;
793
794 try
795 {
796 success = term->init (term->argv->size (), term->argv->begin ());
797 }
798 catch (const class rxvt_failure_exception &e)
799 {
800 success = false;
801 }
802
803 if (!success)
804 {
805 term->destroy ();
806 croak ("error while initializing new terminal instance");
807 }
808
809 RETVAL = term && term->perl.self
810 ? newSVterm (term) : &PL_sv_undef;
811}
812 OUTPUT:
813 RETVAL
814
815void
816rxvt_term::destroy ()
817
818void
819rxvt_term::grab_button (int button, U32 modifiers)
820 CODE:
821 XGrabButton (THIS->display->display, button, modifiers, THIS->vt, 1,
822 ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask,
823 GrabModeSync, GrabModeSync, None, GRAB_CURSOR);
824
825bool
826rxvt_term::grab (U32 eventtime, int sync = 0)
827 CODE:
828{
829 int mode = sync ? GrabModeSync : GrabModeAsync;
830
831 THIS->perl.grabtime = 0;
832
833 if (!XGrabPointer (THIS->display->display, THIS->vt, 0,
834 ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask,
835 mode, mode, None, GRAB_CURSOR, eventtime))
836 if (!XGrabKeyboard (THIS->display->display, THIS->vt, 0, mode, mode, eventtime))
837 THIS->perl.grabtime = eventtime;
838 else
839 XUngrabPointer (THIS->display->display, eventtime);
840
841 RETVAL = !!THIS->perl.grabtime;
842}
843 OUTPUT:
844 RETVAL
845
846void
847rxvt_term::allow_events_async ()
848 CODE:
849 XAllowEvents (THIS->display->display, AsyncBoth, THIS->perl.grabtime);
850
851void
852rxvt_term::allow_events_sync ()
853 CODE:
854 XAllowEvents (THIS->display->display, SyncBoth, THIS->perl.grabtime);
855
856void
857rxvt_term::allow_events_replay ()
858 CODE:
859 XAllowEvents (THIS->display->display, ReplayPointer, THIS->perl.grabtime);
860 XAllowEvents (THIS->display->display, ReplayKeyboard, THIS->perl.grabtime);
861
862void
863rxvt_term::ungrab ()
864 CODE:
865 ungrab (THIS);
620 866
621int 867int
622rxvt_term::strwidth (SV *str) 868rxvt_term::strwidth (SV *str)
623 CODE: 869 CODE:
624{ 870{
643 char *mbstr = rxvt_wcstombs (wstr); 889 char *mbstr = rxvt_wcstombs (wstr);
644 rxvt_pop_locale (); 890 rxvt_pop_locale ();
645 891
646 free (wstr); 892 free (wstr);
647 893
648 RETVAL = newSVpv (mbstr, 0); 894 RETVAL = taint_if (newSVpv (mbstr, 0), str);
649 free (mbstr); 895 free (mbstr);
650} 896}
651 OUTPUT: 897 OUTPUT:
652 RETVAL 898 RETVAL
653 899
660 906
661 rxvt_push_locale (THIS->locale); 907 rxvt_push_locale (THIS->locale);
662 wchar_t *wstr = rxvt_mbstowcs (data, len); 908 wchar_t *wstr = rxvt_mbstowcs (data, len);
663 rxvt_pop_locale (); 909 rxvt_pop_locale ();
664 910
665 RETVAL = wcs2sv (wstr); 911 RETVAL = taint_if (wcs2sv (wstr), octets);
666 free (wstr); 912 free (wstr);
667} 913}
668 OUTPUT: 914 OUTPUT:
669 RETVAL 915 RETVAL
670 916
671# very portable, especially on objects as opposed to pods 917#define TERM_OFFSET(sym) offsetof (TermWin_t, sym)
672#define TERM_OFFSET(sym) (((char *)&((TermWin_t *)0)->sym) - (char *)(TermWin_t *)0)
673 918
674#define TERM_OFFSET_width TERM_OFFSET(width) 919#define TERM_OFFSET_width TERM_OFFSET(width)
675#define TERM_OFFSET_height TERM_OFFSET(height) 920#define TERM_OFFSET_height TERM_OFFSET(height)
676#define TERM_OFFSET_fwidth TERM_OFFSET(fwidth) 921#define TERM_OFFSET_fwidth TERM_OFFSET(fwidth)
677#define TERM_OFFSET_fheight TERM_OFFSET(fheight) 922#define TERM_OFFSET_fheight TERM_OFFSET(fheight)
702 CODE: 947 CODE:
703 RETVAL = *(int *)((char *)THIS + ix); 948 RETVAL = *(int *)((char *)THIS + ix);
704 OUTPUT: 949 OUTPUT:
705 RETVAL 950 RETVAL
706 951
952unsigned int
953rxvt_term::ModLevel3Mask ()
954 ALIAS:
955 ModLevel3Mask = 0
956 ModMetaMask = 1
957 ModNumLockMask = 2
958 CODE:
959 switch (ix)
960 {
961 case 0: RETVAL = THIS->ModLevel3Mask; break;
962 case 1: RETVAL = THIS->ModMetaMask; break;
963 case 2: RETVAL = THIS->ModNumLockMask; break;
964 }
965 OUTPUT:
966 RETVAL
967
968char *
969rxvt_term::display_id ()
970 ALIAS:
971 display_id = 0
972 locale = 1
973 CODE:
974 switch (ix)
975 {
976 case 0: RETVAL = THIS->display->id; break;
977 case 1: RETVAL = THIS->locale; break;
978 }
979 OUTPUT:
980 RETVAL
981
982SV *
983rxvt_term::_env ()
984 CODE:
985{
986 if (THIS->envv)
987 {
988 AV *av = newAV ();
989
990 for (char **i = THIS->envv->begin (); i != THIS->envv->end (); ++i)
991 if (*i)
992 av_push (av, newSVpv (*i, 0));
993
994 RETVAL = newRV_noinc ((SV *)av);
995 }
996 else
997 RETVAL = &PL_sv_undef;
998}
999 OUTPUT:
1000 RETVAL
1001
1002int
1003rxvt_term::pty_ev_events (int events = EVENT_UNDEF)
1004 CODE:
1005 RETVAL = THIS->pty_ev.events;
1006 if (events != EVENT_UNDEF)
1007 THIS->pty_ev.set (events);
1008 OUTPUT:
1009 RETVAL
1010
1011U32
1012rxvt_term::parent ()
1013 CODE:
1014 RETVAL = (U32)THIS->parent [0];
1015 OUTPUT:
1016 RETVAL
1017
1018U32
1019rxvt_term::vt ()
1020 CODE:
1021 RETVAL = (U32)THIS->vt;
1022 OUTPUT:
1023 RETVAL
1024
707U32 1025U32
708rxvt_term::rstyle (U32 new_rstyle = THIS->rstyle) 1026rxvt_term::rstyle (U32 new_rstyle = THIS->rstyle)
709 CODE: 1027 CODE:
710{ 1028{
711 RETVAL = THIS->rstyle; 1029 RETVAL = THIS->rstyle;
733rxvt_term::want_refresh () 1051rxvt_term::want_refresh ()
734 CODE: 1052 CODE:
735 THIS->want_refresh = 1; 1053 THIS->want_refresh = 1;
736 1054
737void 1055void
738rxvt_term::ROW_t (int row_number, SV *new_text = 0, int start_col = 0) 1056rxvt_term::ROW_t (int row_number, SV *new_text = 0, int start_col = 0, int start_ofs = 0, int max_len = MAX_COLS)
739 PPCODE: 1057 PPCODE:
740{ 1058{
741 if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) 1059 if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow))
742 XSRETURN_EMPTY; 1060 XSRETURN_EMPTY;
743 1061
745 1063
746 if (GIMME_V != G_VOID) 1064 if (GIMME_V != G_VOID)
747 { 1065 {
748 wchar_t *wstr = new wchar_t [THIS->ncol]; 1066 wchar_t *wstr = new wchar_t [THIS->ncol];
749 1067
750 for (int col = 0; col <THIS->ncol; col++) 1068 for (int col = 0; col < THIS->ncol; col++)
751 wstr [col] = l.t [col]; 1069 wstr [col] = l.t [col];
752 1070
753 XPUSHs (sv_2mortal (wcs2sv (wstr))); 1071 XPUSHs (taint (sv_2mortal (wcs2sv (wstr, THIS->ncol))));
754 1072
755 delete [] wstr; 1073 delete [] wstr;
756 } 1074 }
757 1075
758 if (new_text) 1076 if (new_text)
759 { 1077 {
760 wchar_t *wstr = sv2wcs (new_text); 1078 wchar_t *wstr = sv2wcs (new_text);
761 1079
762 int len = wcslen (wstr); 1080 int len = min (wcslen (wstr) - start_ofs, max_len);
763 1081
764 if (!IN_RANGE_INC (start_col, 0, THIS->ncol - len)) 1082 if (!IN_RANGE_INC (start_col, 0, THIS->ncol - len))
765 { 1083 {
766 free (wstr); 1084 free (wstr);
767 croak ("new_text extends beyond horizontal margins"); 1085 croak ("new_text extends beyond horizontal margins");
768 } 1086 }
769 1087
770 for (int col = start_col; col < start_col + len; col++) 1088 for (int col = start_col; col < start_col + len; col++)
771 { 1089 {
772 l.t [col] = wstr [col - start_col]; 1090 l.t [col] = wstr [start_ofs + col - start_col];
773 l.r [col] = SET_FONT (l.r [col], THIS->fontset [GET_STYLE (l.r [col])]->find_font (l.t [col])); 1091 l.r [col] = SET_FONT (l.r [col], THIS->fontset [GET_STYLE (l.r [col])]->find_font (l.t [col]));
774 } 1092 }
775 1093
776 free (wstr); 1094 free (wstr);
777 } 1095 }
778} 1096}
779 1097
780void 1098void
781rxvt_term::ROW_r (int row_number, SV *new_rend = 0, int start_col = 0) 1099rxvt_term::ROW_r (int row_number, SV *new_rend = 0, int start_col = 0, int start_ofs = 0, int max_len = MAX_COLS)
782 PPCODE: 1100 PPCODE:
783{ 1101{
784 if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) 1102 if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow))
785 XSRETURN_EMPTY; 1103 XSRETURN_EMPTY;
786 1104
801 { 1119 {
802 if (!SvROK (new_rend) || SvTYPE (SvRV (new_rend)) != SVt_PVAV) 1120 if (!SvROK (new_rend) || SvTYPE (SvRV (new_rend)) != SVt_PVAV)
803 croak ("new_rend must be arrayref"); 1121 croak ("new_rend must be arrayref");
804 1122
805 AV *av = (AV *)SvRV (new_rend); 1123 AV *av = (AV *)SvRV (new_rend);
806 int len = av_len (av) + 1; 1124 int len = min (av_len (av) + 1 - start_ofs, max_len);
807 1125
808 if (!IN_RANGE_INC (start_col, 0, THIS->ncol - len)) 1126 if (!IN_RANGE_INC (start_col, 0, THIS->ncol - len))
809 croak ("new_rend array extends beyond horizontal margins"); 1127 croak ("new_rend array extends beyond horizontal margins");
810 1128
811 for (int col = start_col; col < start_col + len; col++) 1129 for (int col = start_col; col < start_col + len; col++)
812 { 1130 {
813 rend_t r = SvIV (*av_fetch (av, col - start_col, 1)) & ~RS_fontMask; 1131 rend_t r = SvIV (*av_fetch (av, start_ofs + col - start_col, 1)) & ~RS_fontMask;
814 1132
815 l.r [col] = SET_FONT (r, THIS->fontset [GET_STYLE (r)]->find_font (l.t [col])); 1133 l.r [col] = SET_FONT (r, THIS->fontset [GET_STYLE (r)]->find_font (l.t [col]));
816 } 1134 }
817 } 1135 }
818} 1136}
819 1137
820int 1138int
821rxvt_term::ROW_l (int row_number, int new_length = -2) 1139rxvt_term::ROW_l (int row_number, int new_length = -1)
822 CODE: 1140 CODE:
823{ 1141{
824 if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) 1142 if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow))
825 XSRETURN_EMPTY; 1143 XSRETURN_EMPTY;
826 1144
827 line_t &l = ROW(row_number); 1145 line_t &l = ROW(row_number);
828 RETVAL = l.l < 0 ? THIS->ncol : l.l; 1146 RETVAL = l.l;
829 1147
830 if (new_length >= -1) 1148 if (new_length >= 0)
831 l.l = new_length; 1149 l.l = new_length;
832} 1150}
833 OUTPUT: 1151 OUTPUT:
834 RETVAL 1152 RETVAL
835 1153
836bool 1154bool
837rxvt_term::ROW_is_longer (int row_number) 1155rxvt_term::ROW_is_longer (int row_number, int new_is_longer = -1)
838 CODE: 1156 CODE:
839{ 1157{
840 if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) 1158 if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow))
841 XSRETURN_EMPTY; 1159 XSRETURN_EMPTY;
842 1160
843 line_t &l = ROW(row_number); 1161 line_t &l = ROW(row_number);
844 RETVAL = l.l < 0; 1162 RETVAL = l.is_longer ();
1163
1164 if (new_is_longer >= 0)
1165 l.is_longer (new_is_longer);
845} 1166}
846 OUTPUT: 1167 OUTPUT:
847 RETVAL 1168 RETVAL
848 1169
849SV * 1170SV *
850rxvt_term::special_encode (SV *str) 1171rxvt_term::special_encode (SV *string)
851 CODE: 1172 CODE:
852 abort ();//TODO 1173{
1174 wchar_t *wstr = sv2wcs (string);
1175 int wlen = wcslen (wstr);
1176 wchar_t *rstr = new wchar_t [wlen]; // cannot become longer
1177
1178 rxvt_push_locale (THIS->locale);
1179
1180 wchar_t *r = rstr;
1181 for (wchar_t *s = wstr; *s; s++)
1182 if (wcwidth (*s) == 0)
1183 {
1184 if (r == rstr)
1185 croak ("leading combining character unencodable");
1186
1187 unicode_t n = rxvt_compose (r[-1], *s);
1188 if (n == NOCHAR)
1189 n = rxvt_composite.compose (r[-1], *s);
1190
1191 r[-1] = n;
1192 }
1193#if !UNICODE_3
1194 else if (*s >= 0x10000)
1195 *r++ = rxvt_composite.compose (*s);
1196#endif
1197 else
1198 *r++ = *s;
1199
1200 rxvt_pop_locale ();
1201
1202 RETVAL = taint_if (wcs2sv (rstr, r - rstr), string);
1203
1204 delete [] rstr;
1205}
1206 OUTPUT:
1207 RETVAL
853 1208
854SV * 1209SV *
855rxvt_term::special_decode (SV *str) 1210rxvt_term::special_decode (SV *text)
856 CODE: 1211 CODE:
857 abort ();//TODO 1212{
1213 wchar_t *wstr = sv2wcs (text);
1214 int wlen = wcslen (wstr);
1215 int dlen = 0;
1216
1217 // find length
1218 for (wchar_t *s = wstr; *s; s++)
1219 if (*s == NOCHAR)
1220 ;
1221 else if (IS_COMPOSE (*s))
1222 dlen += rxvt_composite.expand (*s, 0);
1223 else
1224 dlen++;
1225
1226 wchar_t *rstr = new wchar_t [dlen];
1227
1228 // decode
1229 wchar_t *r = rstr;
1230 for (wchar_t *s = wstr; *s; s++)
1231 if (*s == NOCHAR)
1232 ;
1233 else if (IS_COMPOSE (*s))
1234 r += rxvt_composite.expand (*s, r);
1235 else
1236 *r++ = *s;
1237
1238 RETVAL = taint_if (wcs2sv (rstr, r - rstr), text);
1239
1240 delete [] rstr;
1241}
1242 OUTPUT:
1243 RETVAL
858 1244
859void 1245void
860rxvt_term::_resource (char *name, int index, SV *newval = 0) 1246rxvt_term::_resource (char *name, int index, SV *newval = 0)
861 PPCODE: 1247 PPCODE:
862{ 1248{
879 1265
880 if (!IN_RANGE_EXC (index, 0, NUM_RESOURCES)) 1266 if (!IN_RANGE_EXC (index, 0, NUM_RESOURCES))
881 croak ("requested out-of-bound resource %s+%d,", name, index - rs->value); 1267 croak ("requested out-of-bound resource %s+%d,", name, index - rs->value);
882 1268
883 if (GIMME_V != G_VOID) 1269 if (GIMME_V != G_VOID)
884 XPUSHs (THIS->rs [index] ? sv_2mortal (newSVpv (THIS->rs [index], 0)) : &PL_sv_undef); 1270 XPUSHs (THIS->rs [index] ? sv_2mortal (taint (newSVpv (THIS->rs [index], 0))) : &PL_sv_undef);
885 1271
886 if (newval) 1272 if (newval)
887 { 1273 {
888 if (SvOK (newval)) 1274 if (SvOK (newval))
889 { 1275 {
894 else 1280 else
895 THIS->rs [index] = 0; 1281 THIS->rs [index] = 0;
896 } 1282 }
897} 1283}
898 1284
1285const char *
1286rxvt_term::x_resource (const char *name)
1287 CLEANUP:
1288 SvTAINTED_on (ST (0));
1289
1290bool
1291rxvt_term::option (U32 optval, int set = -1)
1292 CODE:
1293{
1294 RETVAL = THIS->options & optval;
1295
1296 if (set >= 0)
1297 {
1298 if (set)
1299 THIS->options |= optval;
1300 else
1301 THIS->options &= ~optval;
1302
1303 switch (optval)
1304 {
1305 case Opt_skipBuiltinGlyphs:
1306 THIS->set_fonts ();
1307 THIS->scr_remap_chars ();
1308 THIS->scr_touch (true);
1309 THIS->want_refresh = 1;
1310 break;
1311
1312 case Opt_cursorUnderline:
1313 THIS->want_refresh = 1;
1314 break;
1315
1316# case Opt_scrollBar_floating:
1317# case Opt_scrollBar_right:
1318# THIS->resize_all_windows (THIS->width, THIS->height, 1);
1319# break;
1320 }
1321 }
1322}
1323 OUTPUT:
1324 RETVAL
1325
1326bool
1327rxvt_term::parse_keysym (char *keysym, char *str)
1328 CODE:
1329 RETVAL = 0 < THIS->parse_keysym (keysym, str);
1330 THIS->keyboard->register_done ();
1331 OUTPUT:
1332 RETVAL
1333
899void 1334void
900rxvt_term::cur (...) 1335rxvt_term::screen_cur (...)
901 PROTOTYPE: $;$$ 1336 PROTOTYPE: $;$$
902 ALIAS: 1337 ALIAS:
903 screen_cur = 0 1338 screen_cur = 0
904 selection_beg = 1 1339 selection_beg = 1
905 selection_end = 2 1340 selection_end = 2
926 if (ix) 1361 if (ix)
927 THIS->want_refresh = 1; 1362 THIS->want_refresh = 1;
928 } 1363 }
929} 1364}
930 1365
1366char
1367rxvt_term::cur_charset ()
1368 CODE:
1369 RETVAL = THIS->charsets [THIS->screen.charset];
1370 OUTPUT:
1371 RETVAL
1372
931int 1373int
932rxvt_term::selection_grab (int eventtime = CurrentTime) 1374rxvt_term::selection_grab (U32 eventtime)
933 1375
934void 1376void
935rxvt_term::selection (SV *newtext = 0) 1377rxvt_term::selection (SV *newtext = 0)
936 PPCODE: 1378 PPCODE:
937{ 1379{
938 if (GIMME_V != G_VOID) 1380 if (GIMME_V != G_VOID)
1381 XPUSHs (THIS->selection.text
939 XPUSHs (sv_2mortal (wcs2sv (THIS->selection.text, THIS->selection.len))); 1382 ? taint (sv_2mortal (wcs2sv (THIS->selection.text, THIS->selection.len)))
1383 : &PL_sv_undef);
940 1384
941 if (newtext) 1385 if (newtext)
942 { 1386 {
943 free (THIS->selection.text); 1387 free (THIS->selection.text);
944 1388
946 THIS->selection.len = wcslen (THIS->selection.text); 1390 THIS->selection.len = wcslen (THIS->selection.text);
947 } 1391 }
948} 1392}
949 1393
950void 1394void
1395rxvt_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)
1396
1397void
1398rxvt_term::scr_xor_span (int beg_row, int beg_col, int end_row, int end_col, U32 rstyle = RS_RVid)
1399
1400void
1401rxvt_term::scr_bell ()
1402
1403void
951rxvt_term::scr_add_lines (SV *string) 1404rxvt_term::scr_add_lines (SV *string)
952 CODE: 1405 CODE:
953{ 1406{
954 wchar_t *wstr = sv2wcs (string); 1407 wchar_t *wstr = sv2wcs (string);
955 int wlen = wcslen (wstr);
956 unicode_t *ustr = new unicode_t [wlen];
957 int nlines = 0;
958
959 for (int i = wlen; i--; )
960 {
961 ustr [i] = wstr [i];
962 nlines += ustr [i] == '\012';
963 }
964
965 THIS->scr_add_lines (ustr, nlines, wlen); 1408 THIS->scr_add_lines (wstr, wcslen (wstr));
966
967 free (wstr); 1409 free (wstr);
968 delete [] ustr;
969} 1410}
970 1411
971void 1412void
972rxvt_term::tt_write (SV *octets) 1413rxvt_term::tt_write (SV *octets)
973 INIT: 1414 INIT:
974 STRLEN len; 1415 STRLEN len;
975 char *str = SvPVbyte (octets, len); 1416 char *str = SvPVbyte (octets, len);
976 C_ARGS: 1417 C_ARGS:
977 str, len 1418 str, len
978 1419
1420void
1421rxvt_term::cmd_parse (SV *octets)
1422 CODE:
1423{
1424 STRLEN len;
1425 char *str = SvPVbyte (octets, len);
1426
1427 char *old_cmdbuf_ptr = THIS->cmdbuf_ptr;
1428 char *old_cmdbuf_endp = THIS->cmdbuf_endp;
1429
1430 THIS->cmdbuf_ptr = str;
1431 THIS->cmdbuf_endp = str + len;
1432
1433 rxvt_push_locale (THIS->locale);
1434 THIS->cmd_parse ();
1435 rxvt_pop_locale ();
1436
1437 THIS->cmdbuf_ptr = old_cmdbuf_ptr;
1438 THIS->cmdbuf_endp = old_cmdbuf_endp;
1439}
1440
979SV * 1441SV *
980rxvt_term::overlay (int x, int y, int w, int h, int rstyle = OVERLAY_RSTYLE, int border = 2) 1442rxvt_term::overlay (int x, int y, int w, int h, int rstyle = OVERLAY_RSTYLE, int border = 2)
981 CODE: 1443 CODE:
982{ 1444{
983 overlay *o = new overlay (THIS, x, y, w, h, rstyle, border); 1445 overlay *o = new overlay (THIS, x, y, w, h, rstyle, border);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines