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.28 by root, Fri Jan 6 02:58:02 2006 UTC vs.
Revision 1.46 by root, Mon Jan 9 01:36:56 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_USTRING_LEN: 509 case DT_STR_LEN:
475 { 510 {
476 unicode_t *ustr = va_arg (ap, unicode_t *); 511 char *str = va_arg (ap, char *);
477 int ulen = va_arg (ap, int); 512 int len = va_arg (ap, int);
513
514 XPUSHs (taint (sv_2mortal (newSVpvn (str, len))));
515 }
516 break;
517
518 case DT_WCS_LEN:
519 {
478 wchar_t *wstr = new wchar_t [ulen]; 520 wchar_t *wstr = va_arg (ap, wchar_t *);
521 int wlen = va_arg (ap, int);
479 522
480 for (int i = ulen; i--; )
481 wstr [i] = ustr [i];
482
483 XPUSHs (sv_2mortal (wcs2sv (wstr, ulen))); 523 XPUSHs (taint (sv_2mortal (wcs2sv (wstr, wlen))));
524 }
525 break;
484 526
485 delete [] wstr; 527 case DT_XEVENT:
486 } 528 {
529 XEvent *xe = va_arg (ap, XEvent *);
530 HV *hv = newHV ();
531
532# define set(name, sv) hv_store (hv, # name, sizeof (# name) - 1, sv, 0)
533# define setiv(name, val) hv_store (hv, # name, sizeof (# name) - 1, newSViv (val), 0)
534# undef set
535
536 setiv (type, xe->type);
537 setiv (send_event, xe->xany.send_event);
538 setiv (serial, xe->xany.serial);
539
540 switch (xe->type)
541 {
542 case KeyPress:
543 case KeyRelease:
544 case ButtonPress:
545 case ButtonRelease:
546 case MotionNotify:
547 setiv (time, xe->xmotion.time);
548 setiv (x, xe->xmotion.x);
549 setiv (y, xe->xmotion.y);
550 setiv (row, xe->xmotion.y / term->fheight);
551 setiv (col, xe->xmotion.x / term->fwidth);
552 setiv (x_root, xe->xmotion.x_root);
553 setiv (y_root, xe->xmotion.y_root);
554 setiv (state, xe->xmotion.state);
555 break;
556 }
557
558 switch (xe->type)
559 {
560 case KeyPress:
561 case KeyRelease:
562 setiv (keycode, xe->xkey.keycode);
563 break;
564
565 case ButtonPress:
566 case ButtonRelease:
567 setiv (button, xe->xbutton.button);
568 break;
569
570 case MotionNotify:
571 setiv (is_hint, xe->xmotion.is_hint);
572 break;
573 }
574
575 XPUSHs (sv_2mortal (newRV_noinc ((SV *)hv)));
576 }
577 break;
487 578
488 case DT_END: 579 case DT_END:
489 { 580 {
490 va_end (ap); 581 va_end (ap);
491 582
502 PUTBACK; 593 PUTBACK;
503 FREETMPS; 594 FREETMPS;
504 LEAVE; 595 LEAVE;
505 596
506 if (SvTRUE (ERRSV)) 597 if (SvTRUE (ERRSV))
598 {
507 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 }
508 602
509 if (htype == HOOK_DESTROY) 603 if (htype == HOOK_DESTROY)
510 { 604 {
511 clearSVptr ((SV *)term->self); 605 clearSVptr ((SV *)term->perl.self);
512 SvREFCNT_dec ((SV *)term->self); 606 SvREFCNT_dec ((SV *)term->perl.self);
513 } 607 }
514 608
515 return count; 609 return count;
516 } 610 }
517 611
527 621
528PROTOTYPES: ENABLE 622PROTOTYPES: ENABLE
529 623
530BOOT: 624BOOT:
531{ 625{
532# 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
533 AV *hookname = get_av ("urxvt::HOOKNAME", 1); 628 AV *hookname = get_av ("urxvt::HOOKNAME", 1);
534# define def(sym) av_store (hookname, HOOK_ ## sym, newSVpv (# sym, 0)); 629# define def(sym) av_store (hookname, HOOK_ ## sym, newSVpv (# sym, 0));
535# include "hookinc.h" 630# include "hookinc.h"
536# undef def 631# undef def
537 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));
538 export_const (DEFAULT_RSTYLE); 642 export_const_iv (DEFAULT_RSTYLE);
539 export_const (OVERLAY_RSTYLE); 643 export_const_iv (OVERLAY_RSTYLE);
540 export_const (RS_Bold); 644 export_const_iv (RS_Bold);
541 export_const (RS_Italic); 645 export_const_iv (RS_Italic);
542 export_const (RS_Blink); 646 export_const_iv (RS_Blink);
543 export_const (RS_RVid); 647 export_const_iv (RS_RVid);
544 export_const (RS_Uline); 648 export_const_iv (RS_Uline);
545 649
546 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);
547} 665}
548 666
549SV * 667SV *
550new (...) 668new (...)
551 CODE: 669 CODE:
569 { 687 {
570 term->destroy (); 688 term->destroy ();
571 croak ("exception caught while initializing new terminal instance"); 689 croak ("exception caught while initializing new terminal instance");
572 } 690 }
573 691
574 RETVAL = term && term->self ? newSVterm (term) : &PL_sv_undef; 692 RETVAL = term && term->perl.self ? newSVterm (term) : &PL_sv_undef;
575} 693}
576 OUTPUT: 694 OUTPUT:
577 RETVAL 695 RETVAL
578 696
579void 697void
588 706
589void 707void
590fatal (const char *msg) 708fatal (const char *msg)
591 CODE: 709 CODE:
592 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
593 719
594NV 720NV
595NOW () 721NOW ()
596 CODE: 722 CODE:
597 RETVAL = NOW; 723 RETVAL = NOW;
648 774
649MODULE = urxvt PACKAGE = urxvt::term 775MODULE = urxvt PACKAGE = urxvt::term
650 776
651void 777void
652rxvt_term::destroy () 778rxvt_term::destroy ()
779
780void
781rxvt_term::grab_button (int button, U32 modifiers)
782 CODE:
783 XGrabButton (THIS->display->display, button, modifiers, THIS->vt, 1,
784 ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask,
785 GrabModeSync, GrabModeSync, None, GRAB_CURSOR);
786
787bool
788rxvt_term::grab (U32 eventtime, int sync = 0)
789 CODE:
790{
791 int mode = sync ? GrabModeSync : GrabModeAsync;
792
793 THIS->perl.grabtime = 0;
794
795 if (!XGrabPointer (THIS->display->display, THIS->vt, 0,
796 ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask,
797 mode, mode, None, GRAB_CURSOR, eventtime))
798 if (!XGrabKeyboard (THIS->display->display, THIS->vt, 0, mode, mode, eventtime))
799 THIS->perl.grabtime = eventtime;
800 else
801 XUngrabPointer (THIS->display->display, eventtime);
802
803 RETVAL = !!THIS->perl.grabtime;
804}
805 OUTPUT:
806 RETVAL
807
808void
809rxvt_term::allow_events_async ()
810 CODE:
811 XAllowEvents (THIS->display->display, AsyncBoth, THIS->perl.grabtime);
812
813void
814rxvt_term::allow_events_sync ()
815 CODE:
816 XAllowEvents (THIS->display->display, SyncBoth, THIS->perl.grabtime);
817
818void
819rxvt_term::allow_events_replay ()
820 CODE:
821 XAllowEvents (THIS->display->display, ReplayPointer, THIS->perl.grabtime);
822 XAllowEvents (THIS->display->display, ReplayKeyboard, THIS->perl.grabtime);
823
824void
825rxvt_term::ungrab ()
826 CODE:
827 ungrab (THIS);
653 828
654int 829int
655rxvt_term::strwidth (SV *str) 830rxvt_term::strwidth (SV *str)
656 CODE: 831 CODE:
657{ 832{
676 char *mbstr = rxvt_wcstombs (wstr); 851 char *mbstr = rxvt_wcstombs (wstr);
677 rxvt_pop_locale (); 852 rxvt_pop_locale ();
678 853
679 free (wstr); 854 free (wstr);
680 855
681 RETVAL = newSVpv (mbstr, 0); 856 RETVAL = taint_if (newSVpv (mbstr, 0), str);
682 free (mbstr); 857 free (mbstr);
683} 858}
684 OUTPUT: 859 OUTPUT:
685 RETVAL 860 RETVAL
686 861
693 868
694 rxvt_push_locale (THIS->locale); 869 rxvt_push_locale (THIS->locale);
695 wchar_t *wstr = rxvt_mbstowcs (data, len); 870 wchar_t *wstr = rxvt_mbstowcs (data, len);
696 rxvt_pop_locale (); 871 rxvt_pop_locale ();
697 872
698 RETVAL = wcs2sv (wstr); 873 RETVAL = taint_if (wcs2sv (wstr), octets);
699 free (wstr); 874 free (wstr);
700} 875}
701 OUTPUT: 876 OUTPUT:
702 RETVAL 877 RETVAL
703 878
704# very portable, especially on objects as opposed to pods 879#define TERM_OFFSET(sym) offsetof (TermWin_t, sym)
705#define TERM_OFFSET(sym) (((char *)&((TermWin_t *)0)->sym) - (char *)(TermWin_t *)0)
706 880
707#define TERM_OFFSET_width TERM_OFFSET(width) 881#define TERM_OFFSET_width TERM_OFFSET(width)
708#define TERM_OFFSET_height TERM_OFFSET(height) 882#define TERM_OFFSET_height TERM_OFFSET(height)
709#define TERM_OFFSET_fwidth TERM_OFFSET(fwidth) 883#define TERM_OFFSET_fwidth TERM_OFFSET(fwidth)
710#define TERM_OFFSET_fheight TERM_OFFSET(fheight) 884#define TERM_OFFSET_fheight TERM_OFFSET(fheight)
735 CODE: 909 CODE:
736 RETVAL = *(int *)((char *)THIS + ix); 910 RETVAL = *(int *)((char *)THIS + ix);
737 OUTPUT: 911 OUTPUT:
738 RETVAL 912 RETVAL
739 913
914unsigned int
915rxvt_term::ModLevel3Mask ()
916 ALIAS:
917 ModLevel3Mask = 0
918 ModMetaMask = 1
919 ModNumLockMask = 2
920 CODE:
921 switch (ix)
922 {
923 case 0: RETVAL = THIS->ModLevel3Mask; break;
924 case 1: RETVAL = THIS->ModMetaMask; break;
925 case 2: RETVAL = THIS->ModNumLockMask; break;
926 }
927 OUTPUT:
928 RETVAL
929
930U32
931rxvt_term::parent ()
932 CODE:
933 RETVAL = (U32)THIS->parent [0];
934 OUTPUT:
935 RETVAL
936
937U32
938rxvt_term::vt ()
939 CODE:
940 RETVAL = (U32)THIS->vt;
941 OUTPUT:
942 RETVAL
943
740U32 944U32
741rxvt_term::rstyle (U32 new_rstyle = THIS->rstyle) 945rxvt_term::rstyle (U32 new_rstyle = THIS->rstyle)
742 CODE: 946 CODE:
743{ 947{
744 RETVAL = THIS->rstyle; 948 RETVAL = THIS->rstyle;
778 982
779 if (GIMME_V != G_VOID) 983 if (GIMME_V != G_VOID)
780 { 984 {
781 wchar_t *wstr = new wchar_t [THIS->ncol]; 985 wchar_t *wstr = new wchar_t [THIS->ncol];
782 986
783 for (int col = 0; col <THIS->ncol; col++) 987 for (int col = 0; col < THIS->ncol; col++)
784 wstr [col] = l.t [col]; 988 wstr [col] = l.t [col];
785 989
786 XPUSHs (sv_2mortal (wcs2sv (wstr))); 990 XPUSHs (taint (sv_2mortal (wcs2sv (wstr, THIS->ncol))));
787 991
788 delete [] wstr; 992 delete [] wstr;
789 } 993 }
790 994
791 if (new_text) 995 if (new_text)
881} 1085}
882 OUTPUT: 1086 OUTPUT:
883 RETVAL 1087 RETVAL
884 1088
885SV * 1089SV *
886rxvt_term::special_encode (SV *str) 1090rxvt_term::special_encode (SV *string)
887 CODE: 1091 CODE:
888 abort ();//TODO 1092{
1093 wchar_t *wstr = sv2wcs (string);
1094 int wlen = wcslen (wstr);
1095 wchar_t *rstr = new wchar_t [wlen]; // cannot become longer
1096
1097 rxvt_push_locale (THIS->locale);
1098
1099 wchar_t *r = rstr;
1100 for (wchar_t *s = wstr; *s; s++)
1101 if (wcwidth (*s) == 0)
1102 {
1103 if (r == rstr)
1104 croak ("leading combining character unencodable");
1105
1106 unicode_t n = rxvt_compose (r[-1], *s);
1107 if (n == NOCHAR)
1108 n = rxvt_composite.compose (r[-1], *s);
1109
1110 r[-1] = n;
1111 }
1112#if !UNICODE_3
1113 else if (*s >= 0x10000)
1114 *r++ = rxvt_composite.compose (*s);
1115#endif
1116 else
1117 *r++ = *s;
1118
1119 rxvt_pop_locale ();
1120
1121 RETVAL = taint_if (wcs2sv (rstr, r - rstr), string);
1122
1123 delete [] rstr;
1124}
1125 OUTPUT:
1126 RETVAL
889 1127
890SV * 1128SV *
891rxvt_term::special_decode (SV *str) 1129rxvt_term::special_decode (SV *text)
892 CODE: 1130 CODE:
893 abort ();//TODO 1131{
1132 wchar_t *wstr = sv2wcs (text);
1133 int wlen = wcslen (wstr);
1134 int dlen = 0;
1135
1136 // find length
1137 for (wchar_t *s = wstr; *s; s++)
1138 if (*s == NOCHAR)
1139 ;
1140 else if (IS_COMPOSE (*s))
1141 dlen += rxvt_composite.expand (*s, 0);
1142 else
1143 dlen++;
1144
1145 wchar_t *rstr = new wchar_t [dlen];
1146
1147 // decode
1148 wchar_t *r = rstr;
1149 for (wchar_t *s = wstr; *s; s++)
1150 if (*s == NOCHAR)
1151 ;
1152 else if (IS_COMPOSE (*s))
1153 r += rxvt_composite.expand (*s, r);
1154 else
1155 *r++ = *s;
1156
1157 RETVAL = taint_if (wcs2sv (rstr, r - rstr), text);
1158
1159 delete [] rstr;
1160}
1161 OUTPUT:
1162 RETVAL
894 1163
895void 1164void
896rxvt_term::_resource (char *name, int index, SV *newval = 0) 1165rxvt_term::_resource (char *name, int index, SV *newval = 0)
897 PPCODE: 1166 PPCODE:
898{ 1167{
915 1184
916 if (!IN_RANGE_EXC (index, 0, NUM_RESOURCES)) 1185 if (!IN_RANGE_EXC (index, 0, NUM_RESOURCES))
917 croak ("requested out-of-bound resource %s+%d,", name, index - rs->value); 1186 croak ("requested out-of-bound resource %s+%d,", name, index - rs->value);
918 1187
919 if (GIMME_V != G_VOID) 1188 if (GIMME_V != G_VOID)
920 XPUSHs (THIS->rs [index] ? sv_2mortal (newSVpv (THIS->rs [index], 0)) : &PL_sv_undef); 1189 XPUSHs (THIS->rs [index] ? sv_2mortal (taint (newSVpv (THIS->rs [index], 0))) : &PL_sv_undef);
921 1190
922 if (newval) 1191 if (newval)
923 { 1192 {
924 if (SvOK (newval)) 1193 if (SvOK (newval))
925 { 1194 {
930 else 1199 else
931 THIS->rs [index] = 0; 1200 THIS->rs [index] = 0;
932 } 1201 }
933} 1202}
934 1203
1204bool
1205rxvt_term::option (U32 optval, int set = -1)
1206 CODE:
1207{
1208 RETVAL = THIS->options & optval;
1209
1210 if (set >= 0)
1211 {
1212 if (set)
1213 THIS->options |= optval;
1214 else
1215 THIS->options &= ~optval;
1216
1217 switch (optval)
1218 {
1219 case Opt_skipBuiltinGlyphs:
1220 THIS->set_fonts ();
1221 THIS->scr_remap_chars ();
1222 THIS->scr_touch (true);
1223 THIS->want_refresh = 1;
1224 break;
1225
1226 case Opt_cursorUnderline:
1227 THIS->want_refresh = 1;
1228 break;
1229
1230# case Opt_scrollBar_floating:
1231# case Opt_scrollBar_right:
1232# THIS->resize_all_windows (THIS->width, THIS->height, 1);
1233# break;
1234 }
1235 }
1236}
1237 OUTPUT:
1238 RETVAL
1239
935void 1240void
936rxvt_term::cur (...) 1241rxvt_term::screen_cur (...)
937 PROTOTYPE: $;$$ 1242 PROTOTYPE: $;$$
938 ALIAS: 1243 ALIAS:
939 screen_cur = 0 1244 screen_cur = 0
940 selection_beg = 1 1245 selection_beg = 1
941 selection_end = 2 1246 selection_end = 2
963 THIS->want_refresh = 1; 1268 THIS->want_refresh = 1;
964 } 1269 }
965} 1270}
966 1271
967int 1272int
968rxvt_term::selection_grab (int eventtime = CurrentTime) 1273rxvt_term::selection_grab (U32 eventtime)
969 1274
970void 1275void
971rxvt_term::selection (SV *newtext = 0) 1276rxvt_term::selection (SV *newtext = 0)
972 PPCODE: 1277 PPCODE:
973{ 1278{
974 if (GIMME_V != G_VOID) 1279 if (GIMME_V != G_VOID)
1280 XPUSHs (THIS->selection.text
975 XPUSHs (sv_2mortal (wcs2sv (THIS->selection.text, THIS->selection.len))); 1281 ? taint (sv_2mortal (wcs2sv (THIS->selection.text, THIS->selection.len)))
1282 : &PL_sv_undef);
976 1283
977 if (newtext) 1284 if (newtext)
978 { 1285 {
979 free (THIS->selection.text); 1286 free (THIS->selection.text);
980 1287
986void 1293void
987rxvt_term::scr_add_lines (SV *string) 1294rxvt_term::scr_add_lines (SV *string)
988 CODE: 1295 CODE:
989{ 1296{
990 wchar_t *wstr = sv2wcs (string); 1297 wchar_t *wstr = sv2wcs (string);
991 int wlen = wcslen (wstr);
992 unicode_t *ustr = new unicode_t [wlen];
993 int nlines = 0;
994
995 for (int i = wlen; i--; )
996 {
997 ustr [i] = wstr [i];
998 nlines += ustr [i] == '\012';
999 }
1000
1001 THIS->scr_add_lines (ustr, nlines, wlen); 1298 THIS->scr_add_lines (wstr, wcslen (wstr));
1002
1003 free (wstr); 1299 free (wstr);
1004 delete [] ustr;
1005} 1300}
1006 1301
1007void 1302void
1008rxvt_term::tt_write (SV *octets) 1303rxvt_term::tt_write (SV *octets)
1009 INIT: 1304 INIT:
1023 char *old_cmdbuf_endp = THIS->cmdbuf_endp; 1318 char *old_cmdbuf_endp = THIS->cmdbuf_endp;
1024 1319
1025 THIS->cmdbuf_ptr = str; 1320 THIS->cmdbuf_ptr = str;
1026 THIS->cmdbuf_endp = str + len; 1321 THIS->cmdbuf_endp = str + len;
1027 1322
1323 rxvt_push_locale (THIS->locale);
1028 THIS->cmd_parse (); 1324 THIS->cmd_parse ();
1325 rxvt_pop_locale ();
1029 1326
1030 THIS->cmdbuf_ptr = old_cmdbuf_ptr; 1327 THIS->cmdbuf_ptr = old_cmdbuf_ptr;
1031 THIS->cmdbuf_endp = old_cmdbuf_endp; 1328 THIS->cmdbuf_endp = old_cmdbuf_endp;
1032} 1329}
1033 1330

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines