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.29 by root, Fri Jan 6 03:40:19 2006 UTC vs.
Revision 1.49 by root, Mon Jan 9 19:25:57 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
33#include "rxvt.h" 34#include "rxvt.h"
34#include "iom.h" 35#include "iom.h"
35#include "rxvtutil.h" 36#include "rxvtutil.h"
36#include "rxvtperl.h" 37#include "rxvtperl.h"
37 38
38#include "perlxsi.c" 39#include "perlxsi.c"
39 40
41#if defined(HAVE_SCROLLBARS) || defined(MENUBAR)
42# define GRAB_CURSOR THIS->leftptr_cursor
43#else
44# define GRAB_CURSOR None
45#endif
46
40#undef LINENO 47#undef LINENO
41#define LINENO(n) MOD (THIS->term_start + int(n), THIS->total_rows) 48#define LINENO(n) MOD (THIS->term_start + int(n), THIS->total_rows)
42#undef ROW 49#undef ROW
43#define ROW(n) THIS->row_buf [LINENO (n)] 50#define ROW(n) THIS->row_buf [LINENO (n)]
44 51
45///////////////////////////////////////////////////////////////////////////// 52/////////////////////////////////////////////////////////////////////////////
46 53
54static SV *
55taint (SV *sv)
56{
57 SvTAINT (sv);
58 return sv;
59}
60
61static SV *
62taint_if (SV *sv, SV *src)
63{
64 if (SvTAINTED (src))
65 SvTAINT (sv);
66
67 return sv;
68}
69
47static wchar_t * 70static wchar_t *
48sv2wcs (SV *sv) 71sv2wcs (SV *sv)
49{ 72{
50 STRLEN len; 73 STRLEN len;
51 char *str = SvPVutf8 (sv, len); 74 char *str = SvPVutf8 (sv, len);
101 croak ("perl code used %s object, but C++ object is already destroyed, caught", klass); 124 croak ("perl code used %s object, but C++ object is already destroyed, caught", klass);
102 125
103 return (long)mg->mg_ptr; 126 return (long)mg->mg_ptr;
104} 127}
105 128
106#define newSVterm(term) SvREFCNT_inc ((SV *)term->self) 129#define newSVterm(term) SvREFCNT_inc ((SV *)term->perl.self)
107#define SvTERM(sv) (rxvt_term *)SvPTR (sv, "urxvt::term") 130#define SvTERM(sv) (rxvt_term *)SvPTR (sv, "urxvt::term")
108 131
109///////////////////////////////////////////////////////////////////////////// 132/////////////////////////////////////////////////////////////////////////////
110 133
111struct perl_watcher 134struct perl_watcher
290void 313void
291overlay::show () 314overlay::show ()
292{ 315{
293 char key[33]; sprintf (key, "%32lx", (long)this); 316 char key[33]; sprintf (key, "%32lx", (long)this);
294 317
295 HV *hv = (HV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)THIS->self), "_overlay", 8, 0)); 318 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); 319 hv_store (hv, key, 32, newSViv ((long)this), 0);
297} 320}
298 321
299void 322void
300overlay::hide () 323overlay::hide ()
301{ 324{
302 SV **ovs = hv_fetch ((HV *)SvRV ((SV *)THIS->self), "_overlay", 8, 0); 325 SV **ovs = hv_fetch ((HV *)SvRV ((SV *)THIS->perl.self), "_overlay", 8, 0);
303 326
304 if (ovs) 327 if (ovs)
305 { 328 {
306 char key[33]; sprintf (key, "%32lx", (long)this); 329 char key[33]; sprintf (key, "%32lx", (long)this);
307 330
389{ 412{
390 if (!perl) 413 if (!perl)
391 { 414 {
392 char *argv[] = { 415 char *argv[] = {
393 "", 416 "",
417 "-T",
394 "-edo '" LIBDIR "/urxvt.pm' or ($@ and die $@) or exit 1", 418 "-edo '" LIBDIR "/urxvt.pm' or ($@ and die $@) or exit 1",
395 }; 419 };
396 420
397 perl = perl_alloc (); 421 perl = perl_alloc ();
398 perl_construct (perl); 422 perl_construct (perl);
399 423
400 if (perl_parse (perl, xs_init, 2, argv, (char **)NULL) 424 if (perl_parse (perl, xs_init, 3, argv, (char **)NULL)
401 || perl_run (perl)) 425 || perl_run (perl))
402 { 426 {
403 rxvt_warn ("unable to initialize perl-interpreter, continuing without.\n"); 427 rxvt_warn ("unable to initialize perl-interpreter, continuing without.\n");
404 428
405 perl_destruct (perl); 429 perl_destruct (perl);
407 perl = 0; 431 perl = 0;
408 } 432 }
409 } 433 }
410} 434}
411 435
436static void
437ungrab (rxvt_term *THIS)
438{
439 if (THIS->perl.grabtime)
440 {
441 XUngrabKeyboard (THIS->display->display, THIS->perl.grabtime);
442 XUngrabPointer (THIS->display->display, THIS->perl.grabtime);
443 THIS->perl.grabtime = 0;
444 }
445}
446
412bool 447bool
413rxvt_perl_interp::invoke (rxvt_term *term, hook_type htype, ...) 448rxvt_perl_interp::invoke (rxvt_term *term, hook_type htype, ...)
414{ 449{
415 if (!perl) 450 if (!perl)
416 return false; 451 return false;
417 452
418 if (htype == HOOK_INIT) // first hook ever called 453 if (htype == HOOK_INIT) // first hook ever called
419 { 454 {
420 term->self = (void *)newSVptr ((void *)term, "urxvt::term"); 455 term->perl.self = (void *)newSVptr ((void *)term, "urxvt::term");
421 hv_store ((HV *)SvRV ((SV *)term->self), "_overlay", 8, newRV_noinc ((SV *)newHV ()), 0); 456 hv_store ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, newRV_noinc ((SV *)newHV ()), 0);
422 } 457 }
423 else if (!term->self) 458 else if (!term->perl.self)
424 return false; // perl not initialized for this instance 459 return false; // perl not initialized for this instance
425 else if (htype == HOOK_DESTROY) 460 else if (htype == HOOK_DESTROY)
426 { 461 {
427 // handled later 462 // handled later
428 } 463 }
429 else if (htype == HOOK_REFRESH_BEGIN || htype == HOOK_REFRESH_END) 464 else if (htype == HOOK_REFRESH_BEGIN || htype == HOOK_REFRESH_END)
430 { 465 {
431 HV *hv = (HV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->self), "_overlay", 8, 0)); 466 HV *hv = (HV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, 0));
432 467
433 if (HvKEYS (hv)) 468 if (HvKEYS (hv))
434 { 469 {
435 hv_iterinit (hv); 470 hv_iterinit (hv);
436 471
465 500
466 case DT_LONG: 501 case DT_LONG:
467 XPUSHs (sv_2mortal (newSViv (va_arg (ap, long)))); 502 XPUSHs (sv_2mortal (newSViv (va_arg (ap, long))));
468 break; 503 break;
469 504
470 case DT_STRING: 505 case DT_STR:
471 XPUSHs (sv_2mortal (newSVpv (va_arg (ap, char *), 0))); 506 XPUSHs (taint (sv_2mortal (newSVpv (va_arg (ap, char *), 0))));
472 break; 507 break;
473 508
474 case DT_STRING_LEN: 509 case DT_STR_LEN:
475 { 510 {
476 char *str = va_arg (ap, char *); 511 char *str = va_arg (ap, char *);
477 int len = va_arg (ap, int); 512 int len = va_arg (ap, int);
478 513
479 XPUSHs (sv_2mortal (newSVpvn (str, len))); 514 XPUSHs (taint (sv_2mortal (newSVpvn (str, len))));
480 } 515 }
481 break; 516 break;
517
518 case DT_WCS_LEN:
519 {
520 wchar_t *wstr = va_arg (ap, wchar_t *);
521 int wlen = va_arg (ap, int);
522
523 XPUSHs (taint (sv_2mortal (wcs2sv (wstr, wlen))));
524 }
525 break;
482 526
483 case DT_XEVENT: 527 case DT_XEVENT:
484 { 528 {
485 XEvent *xe = va_arg (ap, XEvent *); 529 XEvent *xe = va_arg (ap, XEvent *);
486 HV *hv = newHV (); 530 HV *hv = newHV ();
501 case ButtonRelease: 545 case ButtonRelease:
502 case MotionNotify: 546 case MotionNotify:
503 setiv (time, xe->xmotion.time); 547 setiv (time, xe->xmotion.time);
504 setiv (x, xe->xmotion.x); 548 setiv (x, xe->xmotion.x);
505 setiv (y, xe->xmotion.y); 549 setiv (y, xe->xmotion.y);
550 setiv (row, xe->xmotion.y / term->fheight);
551 setiv (col, xe->xmotion.x / term->fwidth);
506 setiv (x_root, xe->xmotion.x_root); 552 setiv (x_root, xe->xmotion.x_root);
507 setiv (y_root, xe->xmotion.y_root); 553 setiv (y_root, xe->xmotion.y_root);
508 setiv (state, xe->xmotion.state); 554 setiv (state, xe->xmotion.state);
509 break; 555 break;
510 } 556 }
528 574
529 XPUSHs (sv_2mortal (newRV_noinc ((SV *)hv))); 575 XPUSHs (sv_2mortal (newRV_noinc ((SV *)hv)));
530 } 576 }
531 break; 577 break;
532 578
533 case DT_USTRING_LEN:
534 {
535 unicode_t *ustr = va_arg (ap, unicode_t *);
536 int ulen = va_arg (ap, int);
537 wchar_t *wstr = new wchar_t [ulen];
538
539 for (int i = ulen; i--; )
540 wstr [i] = ustr [i];
541
542 XPUSHs (sv_2mortal (wcs2sv (wstr, ulen)));
543
544 delete [] wstr;
545 }
546
547 case DT_END: 579 case DT_END:
548 { 580 {
549 va_end (ap); 581 va_end (ap);
550 582
551 PUTBACK; 583 PUTBACK;
561 PUTBACK; 593 PUTBACK;
562 FREETMPS; 594 FREETMPS;
563 LEAVE; 595 LEAVE;
564 596
565 if (SvTRUE (ERRSV)) 597 if (SvTRUE (ERRSV))
598 {
566 rxvt_warn ("perl hook %d evaluation error: %s", htype, SvPV_nolen (ERRSV)); 599 rxvt_warn ("perl hook %d evaluation error: %s", htype, SvPV_nolen (ERRSV));
600 ungrab (term); // better lose the grab than the session
601 }
567 602
568 if (htype == HOOK_DESTROY) 603 if (htype == HOOK_DESTROY)
569 { 604 {
570 clearSVptr ((SV *)term->self); 605 clearSVptr ((SV *)term->perl.self);
571 SvREFCNT_dec ((SV *)term->self); 606 SvREFCNT_dec ((SV *)term->perl.self);
572 } 607 }
573 608
574 return count; 609 return count;
575 } 610 }
576 611
586 621
587PROTOTYPES: ENABLE 622PROTOTYPES: ENABLE
588 623
589BOOT: 624BOOT:
590{ 625{
591# define export_const(name) newCONSTSUB (gv_stashpv ("urxvt", 1), # name, newSViv (name)); 626 sv_setsv (get_sv ("urxvt::LIBDIR", 1), newSVpvn (LIBDIR, sizeof (LIBDIR) - 1));
627
592 AV *hookname = get_av ("urxvt::HOOKNAME", 1); 628 AV *hookname = get_av ("urxvt::HOOKNAME", 1);
593# define def(sym) av_store (hookname, HOOK_ ## sym, newSVpv (# sym, 0)); 629# define def(sym) av_store (hookname, HOOK_ ## sym, newSVpv (# sym, 0));
594# include "hookinc.h" 630# include "hookinc.h"
595# undef def 631# undef def
596 632
633 HV *option = get_hv ("urxvt::OPTION", 1);
634# define def(name,val) hv_store (option, # name, sizeof (# name) - 1, newSVuv (Opt_ ## name), 0);
635# define nodef(name)
636# include "optinc.h"
637# undef nodef
638# undef def
639
640 HV *stash = gv_stashpv ("urxvt", 1);
641# define export_const_iv(name) newCONSTSUB (stash, # name, newSViv (name));
597 export_const (DEFAULT_RSTYLE); 642 export_const_iv (DEFAULT_RSTYLE);
598 export_const (OVERLAY_RSTYLE); 643 export_const_iv (OVERLAY_RSTYLE);
599 export_const (RS_Bold); 644 export_const_iv (RS_Bold);
600 export_const (RS_Italic); 645 export_const_iv (RS_Italic);
601 export_const (RS_Blink); 646 export_const_iv (RS_Blink);
602 export_const (RS_RVid); 647 export_const_iv (RS_RVid);
603 export_const (RS_Uline); 648 export_const_iv (RS_Uline);
604 649
605 sv_setpv (get_sv ("urxvt::LIBDIR", 1), LIBDIR); 650 export_const_iv (CurrentTime);
651 export_const_iv (ShiftMask);
652 export_const_iv (LockMask);
653 export_const_iv (ControlMask);
654 export_const_iv (Mod1Mask);
655 export_const_iv (Mod2Mask);
656 export_const_iv (Mod3Mask);
657 export_const_iv (Mod4Mask);
658 export_const_iv (Mod5Mask);
659 export_const_iv (Button1Mask);
660 export_const_iv (Button2Mask);
661 export_const_iv (Button3Mask);
662 export_const_iv (Button4Mask);
663 export_const_iv (Button5Mask);
664 export_const_iv (AnyModifier);
606} 665}
607 666
608SV * 667SV *
609new (...) 668new (...)
610 CODE: 669 CODE:
628 { 687 {
629 term->destroy (); 688 term->destroy ();
630 croak ("exception caught while initializing new terminal instance"); 689 croak ("exception caught while initializing new terminal instance");
631 } 690 }
632 691
633 RETVAL = term && term->self ? newSVterm (term) : &PL_sv_undef; 692 RETVAL = term && term->perl.self ? newSVterm (term) : &PL_sv_undef;
634} 693}
635 OUTPUT: 694 OUTPUT:
636 RETVAL 695 RETVAL
637 696
638void 697void
647 706
648void 707void
649fatal (const char *msg) 708fatal (const char *msg)
650 CODE: 709 CODE:
651 rxvt_fatal ("%s", msg); 710 rxvt_fatal ("%s", msg);
711
712SV *
713untaint (SV *sv)
714 CODE:
715 RETVAL = newSVsv (sv);
716 SvTAINTED_off (RETVAL);
717 OUTPUT:
718 RETVAL
719
720bool
721safe ()
722 CODE:
723 RETVAL = !rxvt_tainted ();
724 OUTPUT:
725 RETVAL
652 726
653NV 727NV
654NOW () 728NOW ()
655 CODE: 729 CODE:
656 RETVAL = NOW; 730 RETVAL = NOW;
707 781
708MODULE = urxvt PACKAGE = urxvt::term 782MODULE = urxvt PACKAGE = urxvt::term
709 783
710void 784void
711rxvt_term::destroy () 785rxvt_term::destroy ()
786
787void
788rxvt_term::grab_button (int button, U32 modifiers)
789 CODE:
790 XGrabButton (THIS->display->display, button, modifiers, THIS->vt, 1,
791 ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask,
792 GrabModeSync, GrabModeSync, None, GRAB_CURSOR);
793
794bool
795rxvt_term::grab (U32 eventtime, int sync = 0)
796 CODE:
797{
798 int mode = sync ? GrabModeSync : GrabModeAsync;
799
800 THIS->perl.grabtime = 0;
801
802 if (!XGrabPointer (THIS->display->display, THIS->vt, 0,
803 ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask,
804 mode, mode, None, GRAB_CURSOR, eventtime))
805 if (!XGrabKeyboard (THIS->display->display, THIS->vt, 0, mode, mode, eventtime))
806 THIS->perl.grabtime = eventtime;
807 else
808 XUngrabPointer (THIS->display->display, eventtime);
809
810 RETVAL = !!THIS->perl.grabtime;
811}
812 OUTPUT:
813 RETVAL
814
815void
816rxvt_term::allow_events_async ()
817 CODE:
818 XAllowEvents (THIS->display->display, AsyncBoth, THIS->perl.grabtime);
819
820void
821rxvt_term::allow_events_sync ()
822 CODE:
823 XAllowEvents (THIS->display->display, SyncBoth, THIS->perl.grabtime);
824
825void
826rxvt_term::allow_events_replay ()
827 CODE:
828 XAllowEvents (THIS->display->display, ReplayPointer, THIS->perl.grabtime);
829 XAllowEvents (THIS->display->display, ReplayKeyboard, THIS->perl.grabtime);
830
831void
832rxvt_term::ungrab ()
833 CODE:
834 ungrab (THIS);
712 835
713int 836int
714rxvt_term::strwidth (SV *str) 837rxvt_term::strwidth (SV *str)
715 CODE: 838 CODE:
716{ 839{
735 char *mbstr = rxvt_wcstombs (wstr); 858 char *mbstr = rxvt_wcstombs (wstr);
736 rxvt_pop_locale (); 859 rxvt_pop_locale ();
737 860
738 free (wstr); 861 free (wstr);
739 862
740 RETVAL = newSVpv (mbstr, 0); 863 RETVAL = taint_if (newSVpv (mbstr, 0), str);
741 free (mbstr); 864 free (mbstr);
742} 865}
743 OUTPUT: 866 OUTPUT:
744 RETVAL 867 RETVAL
745 868
752 875
753 rxvt_push_locale (THIS->locale); 876 rxvt_push_locale (THIS->locale);
754 wchar_t *wstr = rxvt_mbstowcs (data, len); 877 wchar_t *wstr = rxvt_mbstowcs (data, len);
755 rxvt_pop_locale (); 878 rxvt_pop_locale ();
756 879
757 RETVAL = wcs2sv (wstr); 880 RETVAL = taint_if (wcs2sv (wstr), octets);
758 free (wstr); 881 free (wstr);
759} 882}
760 OUTPUT: 883 OUTPUT:
761 RETVAL 884 RETVAL
762 885
763# very portable, especially on objects as opposed to pods 886#define TERM_OFFSET(sym) offsetof (TermWin_t, sym)
764#define TERM_OFFSET(sym) (((char *)&((TermWin_t *)0)->sym) - (char *)(TermWin_t *)0)
765 887
766#define TERM_OFFSET_width TERM_OFFSET(width) 888#define TERM_OFFSET_width TERM_OFFSET(width)
767#define TERM_OFFSET_height TERM_OFFSET(height) 889#define TERM_OFFSET_height TERM_OFFSET(height)
768#define TERM_OFFSET_fwidth TERM_OFFSET(fwidth) 890#define TERM_OFFSET_fwidth TERM_OFFSET(fwidth)
769#define TERM_OFFSET_fheight TERM_OFFSET(fheight) 891#define TERM_OFFSET_fheight TERM_OFFSET(fheight)
794 CODE: 916 CODE:
795 RETVAL = *(int *)((char *)THIS + ix); 917 RETVAL = *(int *)((char *)THIS + ix);
796 OUTPUT: 918 OUTPUT:
797 RETVAL 919 RETVAL
798 920
921unsigned int
922rxvt_term::ModLevel3Mask ()
923 ALIAS:
924 ModLevel3Mask = 0
925 ModMetaMask = 1
926 ModNumLockMask = 2
927 CODE:
928 switch (ix)
929 {
930 case 0: RETVAL = THIS->ModLevel3Mask; break;
931 case 1: RETVAL = THIS->ModMetaMask; break;
932 case 2: RETVAL = THIS->ModNumLockMask; break;
933 }
934 OUTPUT:
935 RETVAL
936
937char *
938rxvt_term::display_id ()
939 ALIAS:
940 display_id = 0
941 locale = 1
942 CODE:
943 switch (ix)
944 {
945 case 0: RETVAL = THIS->display->id; break;
946 case 1: RETVAL = THIS->locale; break;
947 }
948 OUTPUT:
949 RETVAL
950
951U32
952rxvt_term::parent ()
953 CODE:
954 RETVAL = (U32)THIS->parent [0];
955 OUTPUT:
956 RETVAL
957
958U32
959rxvt_term::vt ()
960 CODE:
961 RETVAL = (U32)THIS->vt;
962 OUTPUT:
963 RETVAL
964
799U32 965U32
800rxvt_term::rstyle (U32 new_rstyle = THIS->rstyle) 966rxvt_term::rstyle (U32 new_rstyle = THIS->rstyle)
801 CODE: 967 CODE:
802{ 968{
803 RETVAL = THIS->rstyle; 969 RETVAL = THIS->rstyle;
837 1003
838 if (GIMME_V != G_VOID) 1004 if (GIMME_V != G_VOID)
839 { 1005 {
840 wchar_t *wstr = new wchar_t [THIS->ncol]; 1006 wchar_t *wstr = new wchar_t [THIS->ncol];
841 1007
842 for (int col = 0; col <THIS->ncol; col++) 1008 for (int col = 0; col < THIS->ncol; col++)
843 wstr [col] = l.t [col]; 1009 wstr [col] = l.t [col];
844 1010
845 XPUSHs (sv_2mortal (wcs2sv (wstr))); 1011 XPUSHs (taint (sv_2mortal (wcs2sv (wstr, THIS->ncol))));
846 1012
847 delete [] wstr; 1013 delete [] wstr;
848 } 1014 }
849 1015
850 if (new_text) 1016 if (new_text)
940} 1106}
941 OUTPUT: 1107 OUTPUT:
942 RETVAL 1108 RETVAL
943 1109
944SV * 1110SV *
945rxvt_term::special_encode (SV *str) 1111rxvt_term::special_encode (SV *string)
946 CODE: 1112 CODE:
947 abort ();//TODO 1113{
1114 wchar_t *wstr = sv2wcs (string);
1115 int wlen = wcslen (wstr);
1116 wchar_t *rstr = new wchar_t [wlen]; // cannot become longer
1117
1118 rxvt_push_locale (THIS->locale);
1119
1120 wchar_t *r = rstr;
1121 for (wchar_t *s = wstr; *s; s++)
1122 if (wcwidth (*s) == 0)
1123 {
1124 if (r == rstr)
1125 croak ("leading combining character unencodable");
1126
1127 unicode_t n = rxvt_compose (r[-1], *s);
1128 if (n == NOCHAR)
1129 n = rxvt_composite.compose (r[-1], *s);
1130
1131 r[-1] = n;
1132 }
1133#if !UNICODE_3
1134 else if (*s >= 0x10000)
1135 *r++ = rxvt_composite.compose (*s);
1136#endif
1137 else
1138 *r++ = *s;
1139
1140 rxvt_pop_locale ();
1141
1142 RETVAL = taint_if (wcs2sv (rstr, r - rstr), string);
1143
1144 delete [] rstr;
1145}
1146 OUTPUT:
1147 RETVAL
948 1148
949SV * 1149SV *
950rxvt_term::special_decode (SV *str) 1150rxvt_term::special_decode (SV *text)
951 CODE: 1151 CODE:
952 abort ();//TODO 1152{
1153 wchar_t *wstr = sv2wcs (text);
1154 int wlen = wcslen (wstr);
1155 int dlen = 0;
1156
1157 // find length
1158 for (wchar_t *s = wstr; *s; s++)
1159 if (*s == NOCHAR)
1160 ;
1161 else if (IS_COMPOSE (*s))
1162 dlen += rxvt_composite.expand (*s, 0);
1163 else
1164 dlen++;
1165
1166 wchar_t *rstr = new wchar_t [dlen];
1167
1168 // decode
1169 wchar_t *r = rstr;
1170 for (wchar_t *s = wstr; *s; s++)
1171 if (*s == NOCHAR)
1172 ;
1173 else if (IS_COMPOSE (*s))
1174 r += rxvt_composite.expand (*s, r);
1175 else
1176 *r++ = *s;
1177
1178 RETVAL = taint_if (wcs2sv (rstr, r - rstr), text);
1179
1180 delete [] rstr;
1181}
1182 OUTPUT:
1183 RETVAL
953 1184
954void 1185void
955rxvt_term::_resource (char *name, int index, SV *newval = 0) 1186rxvt_term::_resource (char *name, int index, SV *newval = 0)
956 PPCODE: 1187 PPCODE:
957{ 1188{
974 1205
975 if (!IN_RANGE_EXC (index, 0, NUM_RESOURCES)) 1206 if (!IN_RANGE_EXC (index, 0, NUM_RESOURCES))
976 croak ("requested out-of-bound resource %s+%d,", name, index - rs->value); 1207 croak ("requested out-of-bound resource %s+%d,", name, index - rs->value);
977 1208
978 if (GIMME_V != G_VOID) 1209 if (GIMME_V != G_VOID)
979 XPUSHs (THIS->rs [index] ? sv_2mortal (newSVpv (THIS->rs [index], 0)) : &PL_sv_undef); 1210 XPUSHs (THIS->rs [index] ? sv_2mortal (taint (newSVpv (THIS->rs [index], 0))) : &PL_sv_undef);
980 1211
981 if (newval) 1212 if (newval)
982 { 1213 {
983 if (SvOK (newval)) 1214 if (SvOK (newval))
984 { 1215 {
989 else 1220 else
990 THIS->rs [index] = 0; 1221 THIS->rs [index] = 0;
991 } 1222 }
992} 1223}
993 1224
1225bool
1226rxvt_term::option (U32 optval, int set = -1)
1227 CODE:
1228{
1229 RETVAL = THIS->options & optval;
1230
1231 if (set >= 0)
1232 {
1233 if (set)
1234 THIS->options |= optval;
1235 else
1236 THIS->options &= ~optval;
1237
1238 switch (optval)
1239 {
1240 case Opt_skipBuiltinGlyphs:
1241 THIS->set_fonts ();
1242 THIS->scr_remap_chars ();
1243 THIS->scr_touch (true);
1244 THIS->want_refresh = 1;
1245 break;
1246
1247 case Opt_cursorUnderline:
1248 THIS->want_refresh = 1;
1249 break;
1250
1251# case Opt_scrollBar_floating:
1252# case Opt_scrollBar_right:
1253# THIS->resize_all_windows (THIS->width, THIS->height, 1);
1254# break;
1255 }
1256 }
1257}
1258 OUTPUT:
1259 RETVAL
1260
994void 1261void
995rxvt_term::cur (...) 1262rxvt_term::screen_cur (...)
996 PROTOTYPE: $;$$ 1263 PROTOTYPE: $;$$
997 ALIAS: 1264 ALIAS:
998 screen_cur = 0 1265 screen_cur = 0
999 selection_beg = 1 1266 selection_beg = 1
1000 selection_end = 2 1267 selection_end = 2
1022 THIS->want_refresh = 1; 1289 THIS->want_refresh = 1;
1023 } 1290 }
1024} 1291}
1025 1292
1026int 1293int
1027rxvt_term::selection_grab (int eventtime = CurrentTime) 1294rxvt_term::selection_grab (U32 eventtime)
1028 1295
1029void 1296void
1030rxvt_term::selection (SV *newtext = 0) 1297rxvt_term::selection (SV *newtext = 0)
1031 PPCODE: 1298 PPCODE:
1032{ 1299{
1033 if (GIMME_V != G_VOID) 1300 if (GIMME_V != G_VOID)
1301 XPUSHs (THIS->selection.text
1034 XPUSHs (sv_2mortal (wcs2sv (THIS->selection.text, THIS->selection.len))); 1302 ? taint (sv_2mortal (wcs2sv (THIS->selection.text, THIS->selection.len)))
1303 : &PL_sv_undef);
1035 1304
1036 if (newtext) 1305 if (newtext)
1037 { 1306 {
1038 free (THIS->selection.text); 1307 free (THIS->selection.text);
1039 1308
1045void 1314void
1046rxvt_term::scr_add_lines (SV *string) 1315rxvt_term::scr_add_lines (SV *string)
1047 CODE: 1316 CODE:
1048{ 1317{
1049 wchar_t *wstr = sv2wcs (string); 1318 wchar_t *wstr = sv2wcs (string);
1050 int wlen = wcslen (wstr);
1051 unicode_t *ustr = new unicode_t [wlen];
1052 int nlines = 0;
1053
1054 for (int i = wlen; i--; )
1055 {
1056 ustr [i] = wstr [i];
1057 nlines += ustr [i] == '\012';
1058 }
1059
1060 THIS->scr_add_lines (ustr, nlines, wlen); 1319 THIS->scr_add_lines (wstr, wcslen (wstr));
1061
1062 free (wstr); 1320 free (wstr);
1063 delete [] ustr;
1064} 1321}
1065 1322
1066void 1323void
1067rxvt_term::tt_write (SV *octets) 1324rxvt_term::tt_write (SV *octets)
1068 INIT: 1325 INIT:
1082 char *old_cmdbuf_endp = THIS->cmdbuf_endp; 1339 char *old_cmdbuf_endp = THIS->cmdbuf_endp;
1083 1340
1084 THIS->cmdbuf_ptr = str; 1341 THIS->cmdbuf_ptr = str;
1085 THIS->cmdbuf_endp = str + len; 1342 THIS->cmdbuf_endp = str + len;
1086 1343
1344 rxvt_push_locale (THIS->locale);
1087 THIS->cmd_parse (); 1345 THIS->cmd_parse ();
1346 rxvt_pop_locale ();
1088 1347
1089 THIS->cmdbuf_ptr = old_cmdbuf_ptr; 1348 THIS->cmdbuf_ptr = old_cmdbuf_ptr;
1090 THIS->cmdbuf_endp = old_cmdbuf_endp; 1349 THIS->cmdbuf_endp = old_cmdbuf_endp;
1091} 1350}
1092 1351

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines