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.26 by root, Thu Jan 5 21:21:49 2006 UTC vs.
Revision 1.42 by root, Sun Jan 8 08:43:11 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
383 perl_free (perl); 406 perl_free (perl);
384 } 407 }
385} 408}
386 409
387void 410void
388rxvt_perl_interp::init () 411rxvt_perl_interp::init (bool tainted)
389{ 412{
390 if (!perl) 413 if (!perl)
391 { 414 {
392 char *argv[] = { 415 char *argv[] = {
393 "", 416 "",
394 "-edo '" LIBDIR "/urxvt.pm' or ($@ and die $@) or exit 1", 417 "-edo '" LIBDIR "/urxvt.pm' or ($@ and die $@) or exit 1",
418 "-T",
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, 2 + !!tainted, 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);
415 if (!perl) 439 if (!perl)
416 return false; 440 return false;
417 441
418 if (htype == HOOK_INIT) // first hook ever called 442 if (htype == HOOK_INIT) // first hook ever called
419 { 443 {
420 term->self = (void *)newSVptr ((void *)term, "urxvt::term"); 444 term->perl.self = (void *)newSVptr ((void *)term, "urxvt::term");
421 hv_store ((HV *)SvRV ((SV *)term->self), "_overlay", 8, newRV_noinc ((SV *)newHV ()), 0); 445 hv_store ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, newRV_noinc ((SV *)newHV ()), 0);
422 } 446 }
423 else if (!term->self) 447 else if (!term->perl.self)
424 return false; // perl not initialized for this instance 448 return false; // perl not initialized for this instance
425 else if (htype == HOOK_DESTROY) 449 else if (htype == HOOK_DESTROY)
426 { 450 {
427 // handled later 451 // handled later
428 } 452 }
429 else if (htype == HOOK_REFRESH_BEGIN || htype == HOOK_REFRESH_END) 453 else if (htype == HOOK_REFRESH_BEGIN || htype == HOOK_REFRESH_END)
430 { 454 {
431 HV *hv = (HV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->self), "_overlay", 8, 0)); 455 HV *hv = (HV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, 0));
432 456
433 if (HvKEYS (hv)) 457 if (HvKEYS (hv))
434 { 458 {
435 hv_iterinit (hv); 459 hv_iterinit (hv);
436 460
465 489
466 case DT_LONG: 490 case DT_LONG:
467 XPUSHs (sv_2mortal (newSViv (va_arg (ap, long)))); 491 XPUSHs (sv_2mortal (newSViv (va_arg (ap, long))));
468 break; 492 break;
469 493
470 case DT_STRING: 494 case DT_STR:
471 XPUSHs (sv_2mortal (newSVpv (va_arg (ap, char *), 0))); 495 XPUSHs (taint (sv_2mortal (newSVpv (va_arg (ap, char *), 0))));
472 break; 496 break;
473 497
474 case DT_USTRING_LEN: 498 case DT_STR_LEN:
475 { 499 {
476 unicode_t *ustr = va_arg (ap, unicode_t *); 500 char *str = va_arg (ap, char *);
477 int ulen = va_arg (ap, int); 501 int len = va_arg (ap, int);
502
503 XPUSHs (taint (sv_2mortal (newSVpvn (str, len))));
504 }
505 break;
506
507 case DT_WCS_LEN:
508 {
478 wchar_t *wstr = new wchar_t [ulen]; 509 wchar_t *wstr = va_arg (ap, wchar_t *);
510 int wlen = va_arg (ap, int);
479 511
480 for (int i = ulen; i--; )
481 wstr [i] = ustr [i];
482
483 XPUSHs (sv_2mortal (wcs2sv (wstr, ulen))); 512 XPUSHs (taint (sv_2mortal (wcs2sv (wstr, wlen))));
513 }
514 break;
484 515
485 delete [] wstr; 516 case DT_XEVENT:
486 } 517 {
518 XEvent *xe = va_arg (ap, XEvent *);
519 HV *hv = newHV ();
520
521# define set(name, sv) hv_store (hv, # name, sizeof (# name) - 1, sv, 0)
522# define setiv(name, val) hv_store (hv, # name, sizeof (# name) - 1, newSViv (val), 0)
523# undef set
524
525 setiv (type, xe->type);
526 setiv (send_event, xe->xany.send_event);
527 setiv (serial, xe->xany.serial);
528
529 switch (xe->type)
530 {
531 case KeyPress:
532 case KeyRelease:
533 case ButtonPress:
534 case ButtonRelease:
535 case MotionNotify:
536 setiv (time, xe->xmotion.time);
537 setiv (x, xe->xmotion.x);
538 setiv (y, xe->xmotion.y);
539 setiv (row, xe->xmotion.y / term->fheight);
540 setiv (col, xe->xmotion.x / term->fwidth);
541 setiv (x_root, xe->xmotion.x_root);
542 setiv (y_root, xe->xmotion.y_root);
543 setiv (state, xe->xmotion.state);
544 break;
545 }
546
547 switch (xe->type)
548 {
549 case KeyPress:
550 case KeyRelease:
551 setiv (keycode, xe->xkey.keycode);
552 break;
553
554 case ButtonPress:
555 case ButtonRelease:
556 setiv (button, xe->xbutton.button);
557 break;
558
559 case MotionNotify:
560 setiv (is_hint, xe->xmotion.is_hint);
561 break;
562 }
563
564 XPUSHs (sv_2mortal (newRV_noinc ((SV *)hv)));
565 }
566 break;
487 567
488 case DT_END: 568 case DT_END:
489 { 569 {
490 va_end (ap); 570 va_end (ap);
491 571
506 if (SvTRUE (ERRSV)) 586 if (SvTRUE (ERRSV))
507 rxvt_warn ("perl hook %d evaluation error: %s", htype, SvPV_nolen (ERRSV)); 587 rxvt_warn ("perl hook %d evaluation error: %s", htype, SvPV_nolen (ERRSV));
508 588
509 if (htype == HOOK_DESTROY) 589 if (htype == HOOK_DESTROY)
510 { 590 {
511 clearSVptr ((SV *)term->self); 591 clearSVptr ((SV *)term->perl.self);
512 SvREFCNT_dec ((SV *)term->self); 592 SvREFCNT_dec ((SV *)term->perl.self);
513 } 593 }
514 594
515 return count; 595 return count;
516 } 596 }
517 597
527 607
528PROTOTYPES: ENABLE 608PROTOTYPES: ENABLE
529 609
530BOOT: 610BOOT:
531{ 611{
532# define export_const(name) newCONSTSUB (gv_stashpv ("urxvt", 1), # name, newSViv (name)); 612 sv_setsv (get_sv ("urxvt::LIBDIR", 1), newSVpvn (LIBDIR, sizeof (LIBDIR) - 1));
613
533 AV *hookname = get_av ("urxvt::HOOKNAME", 1); 614 AV *hookname = get_av ("urxvt::HOOKNAME", 1);
534# define def(sym) av_store (hookname, HOOK_ ## sym, newSVpv (# sym, 0)); 615# define def(sym) av_store (hookname, HOOK_ ## sym, newSVpv (# sym, 0));
535# include "hookinc.h" 616# include "hookinc.h"
536# undef def 617# undef def
537 618
619 HV *option = get_hv ("urxvt::OPTION", 1);
620# define def(name,val) hv_store (option, # name, sizeof (# name) - 1, newSVuv (Opt_ ## name), 0);
621# define nodef(name)
622# include "optinc.h"
623# undef nodef
624# undef def
625
626 HV *stash = gv_stashpv ("urxvt", 1);
627# define export_const_iv(name) newCONSTSUB (stash, # name, newSViv (name));
538 export_const (DEFAULT_RSTYLE); 628 export_const_iv (DEFAULT_RSTYLE);
539 export_const (OVERLAY_RSTYLE); 629 export_const_iv (OVERLAY_RSTYLE);
540 export_const (RS_Bold); 630 export_const_iv (RS_Bold);
541 export_const (RS_Italic); 631 export_const_iv (RS_Italic);
542 export_const (RS_Blink); 632 export_const_iv (RS_Blink);
543 export_const (RS_RVid); 633 export_const_iv (RS_RVid);
544 export_const (RS_Uline); 634 export_const_iv (RS_Uline);
545 635
546 sv_setpv (get_sv ("urxvt::LIBDIR", 1), LIBDIR); 636 export_const_iv (CurrentTime);
637 export_const_iv (ShiftMask);
638 export_const_iv (LockMask);
639 export_const_iv (ControlMask);
640 export_const_iv (Mod1Mask);
641 export_const_iv (Mod2Mask);
642 export_const_iv (Mod3Mask);
643 export_const_iv (Mod4Mask);
644 export_const_iv (Mod5Mask);
645 export_const_iv (Button1Mask);
646 export_const_iv (Button2Mask);
647 export_const_iv (Button3Mask);
648 export_const_iv (Button4Mask);
649 export_const_iv (Button5Mask);
650 export_const_iv (AnyModifier);
547} 651}
652
653SV *
654new (...)
655 CODE:
656{
657 stringvec *argv = new stringvec;
658 bool success;
659
660 for (int i = 0; i < items ;i++)
661 argv->push_back (strdup (SvPVbyte_nolen (ST (i))));
662
663 rxvt_term *term = new rxvt_term;
664
665 term->argv = argv;
666
667 try
668 {
669 if (!term->init (argv->size (), argv->begin ()))
670 term = 0;
671 }
672 catch (const class rxvt_failure_exception &e)
673 {
674 term->destroy ();
675 croak ("exception caught while initializing new terminal instance");
676 }
677
678 RETVAL = term && term->perl.self ? newSVterm (term) : &PL_sv_undef;
679}
680 OUTPUT:
681 RETVAL
548 682
549void 683void
550set_should_invoke (int htype, int value) 684set_should_invoke (int htype, int value)
551 CODE: 685 CODE:
552 rxvt_perl.should_invoke [htype] = value; 686 rxvt_perl.should_invoke [htype] = value;
615} 749}
616 OUTPUT: 750 OUTPUT:
617 RETVAL 751 RETVAL
618 752
619MODULE = urxvt PACKAGE = urxvt::term 753MODULE = urxvt PACKAGE = urxvt::term
754
755void
756rxvt_term::destroy ()
757
758void
759rxvt_term::grab_button (int button, U32 modifiers)
760 CODE:
761 XGrabButton (THIS->display->display, button, modifiers, THIS->vt, 1,
762 ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask,
763 GrabModeSync, GrabModeSync, None, GRAB_CURSOR);
764
765bool
766rxvt_term::grab (U32 eventtime, int sync = 0)
767 CODE:
768{
769 int mode = sync ? GrabModeSync : GrabModeAsync;
770
771 THIS->perl.grabtime = 0;
772
773 if (!XGrabPointer (THIS->display->display, THIS->vt, 0,
774 ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask,
775 mode, mode, None, GRAB_CURSOR, eventtime))
776 if (!XGrabKeyboard (THIS->display->display, THIS->vt, 0, mode, mode, eventtime))
777 THIS->perl.grabtime = eventtime;
778 else
779 XUngrabPointer (THIS->display->display, eventtime);
780
781 RETVAL = !!THIS->perl.grabtime;
782}
783 OUTPUT:
784 RETVAL
785
786void
787rxvt_term::allow_events_async (U32 eventtime = THIS->perl.grabtime)
788 CODE:
789 XAllowEvents (THIS->display->display, AsyncBoth, eventtime);
790
791void
792rxvt_term::allow_events_sync (U32 eventtime = THIS->perl.grabtime)
793 CODE:
794 XAllowEvents (THIS->display->display, SyncBoth, eventtime);
795
796void
797rxvt_term::allow_events_replay (U32 eventtime = THIS->perl.grabtime)
798 CODE:
799 XAllowEvents (THIS->display->display, ReplayPointer, eventtime);
800 XAllowEvents (THIS->display->display, ReplayKeyboard, eventtime);
801
802void
803rxvt_term::ungrab (U32 eventtime = THIS->perl.grabtime)
804 CODE:
805 THIS->perl.grabtime = 0;
806 XUngrabKeyboard (THIS->display->display, eventtime);
807 XUngrabPointer (THIS->display->display, eventtime);
620 808
621int 809int
622rxvt_term::strwidth (SV *str) 810rxvt_term::strwidth (SV *str)
623 CODE: 811 CODE:
624{ 812{
643 char *mbstr = rxvt_wcstombs (wstr); 831 char *mbstr = rxvt_wcstombs (wstr);
644 rxvt_pop_locale (); 832 rxvt_pop_locale ();
645 833
646 free (wstr); 834 free (wstr);
647 835
648 RETVAL = newSVpv (mbstr, 0); 836 RETVAL = taint_if (newSVpv (mbstr, 0), str);
649 free (mbstr); 837 free (mbstr);
650} 838}
651 OUTPUT: 839 OUTPUT:
652 RETVAL 840 RETVAL
653 841
660 848
661 rxvt_push_locale (THIS->locale); 849 rxvt_push_locale (THIS->locale);
662 wchar_t *wstr = rxvt_mbstowcs (data, len); 850 wchar_t *wstr = rxvt_mbstowcs (data, len);
663 rxvt_pop_locale (); 851 rxvt_pop_locale ();
664 852
665 RETVAL = wcs2sv (wstr); 853 RETVAL = taint_if (wcs2sv (wstr), octets);
666 free (wstr); 854 free (wstr);
667} 855}
668 OUTPUT: 856 OUTPUT:
669 RETVAL 857 RETVAL
670 858
671# very portable, especially on objects as opposed to pods 859#define TERM_OFFSET(sym) offsetof (TermWin_t, sym)
672#define TERM_OFFSET(sym) (((char *)&((TermWin_t *)0)->sym) - (char *)(TermWin_t *)0)
673 860
674#define TERM_OFFSET_width TERM_OFFSET(width) 861#define TERM_OFFSET_width TERM_OFFSET(width)
675#define TERM_OFFSET_height TERM_OFFSET(height) 862#define TERM_OFFSET_height TERM_OFFSET(height)
676#define TERM_OFFSET_fwidth TERM_OFFSET(fwidth) 863#define TERM_OFFSET_fwidth TERM_OFFSET(fwidth)
677#define TERM_OFFSET_fheight TERM_OFFSET(fheight) 864#define TERM_OFFSET_fheight TERM_OFFSET(fheight)
702 CODE: 889 CODE:
703 RETVAL = *(int *)((char *)THIS + ix); 890 RETVAL = *(int *)((char *)THIS + ix);
704 OUTPUT: 891 OUTPUT:
705 RETVAL 892 RETVAL
706 893
894unsigned int
895rxvt_term::ModLevel3Mask ()
896 ALIAS:
897 ModLevel3Mask = 0
898 ModMetaMask = 1
899 ModNumLockMask = 2
900 CODE:
901 switch (ix)
902 {
903 case 0: RETVAL = THIS->ModLevel3Mask; break;
904 case 1: RETVAL = THIS->ModMetaMask; break;
905 case 2: RETVAL = THIS->ModNumLockMask; break;
906 }
907 OUTPUT:
908 RETVAL
909
910U32
911rxvt_term::parent ()
912 CODE:
913 RETVAL = (U32)THIS->parent [0];
914 OUTPUT:
915 RETVAL
916
917U32
918rxvt_term::vt ()
919 CODE:
920 RETVAL = (U32)THIS->vt;
921 OUTPUT:
922 RETVAL
923
707U32 924U32
708rxvt_term::rstyle (U32 new_rstyle = THIS->rstyle) 925rxvt_term::rstyle (U32 new_rstyle = THIS->rstyle)
709 CODE: 926 CODE:
710{ 927{
711 RETVAL = THIS->rstyle; 928 RETVAL = THIS->rstyle;
733rxvt_term::want_refresh () 950rxvt_term::want_refresh ()
734 CODE: 951 CODE:
735 THIS->want_refresh = 1; 952 THIS->want_refresh = 1;
736 953
737void 954void
738rxvt_term::ROW_t (int row_number, SV *new_text = 0, int start_col = 0) 955rxvt_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: 956 PPCODE:
740{ 957{
741 if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) 958 if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow))
742 XSRETURN_EMPTY; 959 XSRETURN_EMPTY;
743 960
745 962
746 if (GIMME_V != G_VOID) 963 if (GIMME_V != G_VOID)
747 { 964 {
748 wchar_t *wstr = new wchar_t [THIS->ncol]; 965 wchar_t *wstr = new wchar_t [THIS->ncol];
749 966
750 for (int col = 0; col <THIS->ncol; col++) 967 for (int col = 0; col < THIS->ncol; col++)
751 wstr [col] = l.t [col]; 968 wstr [col] = l.t [col];
752 969
753 XPUSHs (sv_2mortal (wcs2sv (wstr))); 970 XPUSHs (taint (sv_2mortal (wcs2sv (wstr, THIS->ncol))));
754 971
755 delete [] wstr; 972 delete [] wstr;
756 } 973 }
757 974
758 if (new_text) 975 if (new_text)
759 { 976 {
760 wchar_t *wstr = sv2wcs (new_text); 977 wchar_t *wstr = sv2wcs (new_text);
761 978
762 int len = wcslen (wstr); 979 int len = min (wcslen (wstr) - start_ofs, max_len);
763 980
764 if (!IN_RANGE_INC (start_col, 0, THIS->ncol - len)) 981 if (!IN_RANGE_INC (start_col, 0, THIS->ncol - len))
765 { 982 {
766 free (wstr); 983 free (wstr);
767 croak ("new_text extends beyond horizontal margins"); 984 croak ("new_text extends beyond horizontal margins");
768 } 985 }
769 986
770 for (int col = start_col; col < start_col + len; col++) 987 for (int col = start_col; col < start_col + len; col++)
771 { 988 {
772 l.t [col] = wstr [col - start_col]; 989 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])); 990 l.r [col] = SET_FONT (l.r [col], THIS->fontset [GET_STYLE (l.r [col])]->find_font (l.t [col]));
774 } 991 }
775 992
776 free (wstr); 993 free (wstr);
777 } 994 }
778} 995}
779 996
780void 997void
781rxvt_term::ROW_r (int row_number, SV *new_rend = 0, int start_col = 0) 998rxvt_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: 999 PPCODE:
783{ 1000{
784 if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) 1001 if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow))
785 XSRETURN_EMPTY; 1002 XSRETURN_EMPTY;
786 1003
801 { 1018 {
802 if (!SvROK (new_rend) || SvTYPE (SvRV (new_rend)) != SVt_PVAV) 1019 if (!SvROK (new_rend) || SvTYPE (SvRV (new_rend)) != SVt_PVAV)
803 croak ("new_rend must be arrayref"); 1020 croak ("new_rend must be arrayref");
804 1021
805 AV *av = (AV *)SvRV (new_rend); 1022 AV *av = (AV *)SvRV (new_rend);
806 int len = av_len (av) + 1; 1023 int len = min (av_len (av) + 1 - start_ofs, max_len);
807 1024
808 if (!IN_RANGE_INC (start_col, 0, THIS->ncol - len)) 1025 if (!IN_RANGE_INC (start_col, 0, THIS->ncol - len))
809 croak ("new_rend array extends beyond horizontal margins"); 1026 croak ("new_rend array extends beyond horizontal margins");
810 1027
811 for (int col = start_col; col < start_col + len; col++) 1028 for (int col = start_col; col < start_col + len; col++)
812 { 1029 {
813 rend_t r = SvIV (*av_fetch (av, col - start_col, 1)) & ~RS_fontMask; 1030 rend_t r = SvIV (*av_fetch (av, start_ofs + col - start_col, 1)) & ~RS_fontMask;
814 1031
815 l.r [col] = SET_FONT (r, THIS->fontset [GET_STYLE (r)]->find_font (l.t [col])); 1032 l.r [col] = SET_FONT (r, THIS->fontset [GET_STYLE (r)]->find_font (l.t [col]));
816 } 1033 }
817 } 1034 }
818} 1035}
848} 1065}
849 OUTPUT: 1066 OUTPUT:
850 RETVAL 1067 RETVAL
851 1068
852SV * 1069SV *
853rxvt_term::special_encode (SV *str) 1070rxvt_term::special_encode (SV *string)
854 CODE: 1071 CODE:
855 abort ();//TODO 1072{
1073 wchar_t *wstr = sv2wcs (string);
1074 int wlen = wcslen (wstr);
1075 wchar_t *rstr = new wchar_t [wlen]; // cannot become longer
1076
1077 rxvt_push_locale (THIS->locale);
1078
1079 wchar_t *r = rstr;
1080 for (wchar_t *s = wstr; *s; s++)
1081 if (wcwidth (*s) == 0)
1082 {
1083 if (r == rstr)
1084 croak ("leading combining character unencodable");
1085
1086 unicode_t n = rxvt_compose (r[-1], *s);
1087 if (n == NOCHAR)
1088 n = rxvt_composite.compose (r[-1], *s);
1089
1090 r[-1] = n;
1091 }
1092#if !UNICODE_3
1093 else if (*s >= 0x10000)
1094 *r++ = rxvt_composite.compose (*s);
1095#endif
1096 else
1097 *r++ = *s;
1098
1099 rxvt_pop_locale ();
1100
1101 RETVAL = taint_if (wcs2sv (rstr, r - rstr), string);
1102
1103 delete [] rstr;
1104}
1105 OUTPUT:
1106 RETVAL
856 1107
857SV * 1108SV *
858rxvt_term::special_decode (SV *str) 1109rxvt_term::special_decode (SV *text)
859 CODE: 1110 CODE:
860 abort ();//TODO 1111{
1112 wchar_t *wstr = sv2wcs (text);
1113 int wlen = wcslen (wstr);
1114 int dlen = 0;
1115
1116 // find length
1117 for (wchar_t *s = wstr; *s; s++)
1118 if (*s == NOCHAR)
1119 ;
1120 else if (IS_COMPOSE (*s))
1121 dlen += rxvt_composite.expand (*s, 0);
1122 else
1123 dlen++;
1124
1125 wchar_t *rstr = new wchar_t [dlen];
1126
1127 // decode
1128 wchar_t *r = rstr;
1129 for (wchar_t *s = wstr; *s; s++)
1130 if (*s == NOCHAR)
1131 ;
1132 else if (IS_COMPOSE (*s))
1133 r += rxvt_composite.expand (*s, r);
1134 else
1135 *r++ = *s;
1136
1137 RETVAL = taint_if (wcs2sv (rstr, r - rstr), text);
1138
1139 delete [] rstr;
1140}
1141 OUTPUT:
1142 RETVAL
861 1143
862void 1144void
863rxvt_term::_resource (char *name, int index, SV *newval = 0) 1145rxvt_term::_resource (char *name, int index, SV *newval = 0)
864 PPCODE: 1146 PPCODE:
865{ 1147{
882 1164
883 if (!IN_RANGE_EXC (index, 0, NUM_RESOURCES)) 1165 if (!IN_RANGE_EXC (index, 0, NUM_RESOURCES))
884 croak ("requested out-of-bound resource %s+%d,", name, index - rs->value); 1166 croak ("requested out-of-bound resource %s+%d,", name, index - rs->value);
885 1167
886 if (GIMME_V != G_VOID) 1168 if (GIMME_V != G_VOID)
887 XPUSHs (THIS->rs [index] ? sv_2mortal (newSVpv (THIS->rs [index], 0)) : &PL_sv_undef); 1169 XPUSHs (THIS->rs [index] ? sv_2mortal (taint (newSVpv (THIS->rs [index], 0))) : &PL_sv_undef);
888 1170
889 if (newval) 1171 if (newval)
890 { 1172 {
891 if (SvOK (newval)) 1173 if (SvOK (newval))
892 { 1174 {
897 else 1179 else
898 THIS->rs [index] = 0; 1180 THIS->rs [index] = 0;
899 } 1181 }
900} 1182}
901 1183
1184bool
1185rxvt_term::option (U32 optval, int set = -1)
1186 CODE:
1187{
1188 RETVAL = THIS->options & optval;
1189
1190 if (set >= 0)
1191 {
1192 if (set)
1193 THIS->options |= optval;
1194 else
1195 THIS->options &= ~optval;
1196
1197 switch (optval)
1198 {
1199 case Opt_skipBuiltinGlyphs:
1200 THIS->set_fonts ();
1201 THIS->scr_remap_chars ();
1202 THIS->scr_touch (true);
1203 THIS->want_refresh = 1;
1204 break;
1205
1206 case Opt_cursorUnderline:
1207 THIS->want_refresh = 1;
1208 break;
1209
1210# case Opt_scrollBar_floating:
1211# case Opt_scrollBar_right:
1212# THIS->resize_all_windows (THIS->width, THIS->height, 1);
1213# break;
1214 }
1215 }
1216}
1217 OUTPUT:
1218 RETVAL
1219
902void 1220void
903rxvt_term::cur (...) 1221rxvt_term::cur (...)
904 PROTOTYPE: $;$$ 1222 PROTOTYPE: $;$$
905 ALIAS: 1223 ALIAS:
906 screen_cur = 0 1224 screen_cur = 0
930 THIS->want_refresh = 1; 1248 THIS->want_refresh = 1;
931 } 1249 }
932} 1250}
933 1251
934int 1252int
935rxvt_term::selection_grab (int eventtime = CurrentTime) 1253rxvt_term::selection_grab (U32 eventtime)
936 1254
937void 1255void
938rxvt_term::selection (SV *newtext = 0) 1256rxvt_term::selection (SV *newtext = 0)
939 PPCODE: 1257 PPCODE:
940{ 1258{
941 if (GIMME_V != G_VOID) 1259 if (GIMME_V != G_VOID)
942 XPUSHs (sv_2mortal (wcs2sv (THIS->selection.text, THIS->selection.len))); 1260 XPUSHs (taint (sv_2mortal (wcs2sv (THIS->selection.text, THIS->selection.len))));
943 1261
944 if (newtext) 1262 if (newtext)
945 { 1263 {
946 free (THIS->selection.text); 1264 free (THIS->selection.text);
947 1265
953void 1271void
954rxvt_term::scr_add_lines (SV *string) 1272rxvt_term::scr_add_lines (SV *string)
955 CODE: 1273 CODE:
956{ 1274{
957 wchar_t *wstr = sv2wcs (string); 1275 wchar_t *wstr = sv2wcs (string);
958 int wlen = wcslen (wstr);
959 unicode_t *ustr = new unicode_t [wlen];
960 int nlines = 0;
961
962 for (int i = wlen; i--; )
963 {
964 ustr [i] = wstr [i];
965 nlines += ustr [i] == '\012';
966 }
967
968 THIS->scr_add_lines (ustr, nlines, wlen); 1276 THIS->scr_add_lines (wstr, wcslen (wstr));
969
970 free (wstr); 1277 free (wstr);
971 delete [] ustr;
972} 1278}
973 1279
974void 1280void
975rxvt_term::tt_write (SV *octets) 1281rxvt_term::tt_write (SV *octets)
976 INIT: 1282 INIT:
977 STRLEN len; 1283 STRLEN len;
978 char *str = SvPVbyte (octets, len); 1284 char *str = SvPVbyte (octets, len);
979 C_ARGS: 1285 C_ARGS:
980 str, len 1286 str, len
981 1287
1288void
1289rxvt_term::cmd_parse (SV *octets)
1290 CODE:
1291{
1292 STRLEN len;
1293 char *str = SvPVbyte (octets, len);
1294
1295 char *old_cmdbuf_ptr = THIS->cmdbuf_ptr;
1296 char *old_cmdbuf_endp = THIS->cmdbuf_endp;
1297
1298 THIS->cmdbuf_ptr = str;
1299 THIS->cmdbuf_endp = str + len;
1300
1301 rxvt_push_locale (THIS->locale);
1302 THIS->cmd_parse ();
1303 rxvt_pop_locale ();
1304
1305 THIS->cmdbuf_ptr = old_cmdbuf_ptr;
1306 THIS->cmdbuf_endp = old_cmdbuf_endp;
1307}
1308
982SV * 1309SV *
983rxvt_term::overlay (int x, int y, int w, int h, int rstyle = OVERLAY_RSTYLE, int border = 2) 1310rxvt_term::overlay (int x, int y, int w, int h, int rstyle = OVERLAY_RSTYLE, int border = 2)
984 CODE: 1311 CODE:
985{ 1312{
986 overlay *o = new overlay (THIS, x, y, w, h, rstyle, border); 1313 overlay *o = new overlay (THIS, x, y, w, h, rstyle, border);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines