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.24 by root, Wed Jan 4 21:37:55 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);
52 return rxvt_utf8towcs (str, len); 75 return rxvt_utf8towcs (str, len);
53} 76}
54 77
55static SV * 78static SV *
79wcs2sv (wchar_t *wstr, int len = -1)
80{
81 char *str = rxvt_wcstoutf8 (wstr, len);
82
83 SV *sv = newSVpv (str, 0);
84 SvUTF8_on (sv);
85 free (str);
86
87 return sv;
88}
89
90static SV *
56new_ref (HV *hv, const char *klass) 91new_ref (HV *hv, const char *klass)
57{ 92{
58 return sv_bless (newRV ((SV *)hv), gv_stashpv (klass, 1)); 93 return sv_bless (newRV ((SV *)hv), gv_stashpv (klass, 1));
59} 94}
60 95
89 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);
90 125
91 return (long)mg->mg_ptr; 126 return (long)mg->mg_ptr;
92} 127}
93 128
94#define newSVterm(term) SvREFCNT_inc ((SV *)term->self) 129#define newSVterm(term) SvREFCNT_inc ((SV *)term->perl.self)
95#define SvTERM(sv) (rxvt_term *)SvPTR (sv, "urxvt::term") 130#define SvTERM(sv) (rxvt_term *)SvPTR (sv, "urxvt::term")
96 131
97///////////////////////////////////////////////////////////////////////////// 132/////////////////////////////////////////////////////////////////////////////
98 133
99struct perl_watcher 134struct perl_watcher
278void 313void
279overlay::show () 314overlay::show ()
280{ 315{
281 char key[33]; sprintf (key, "%32lx", (long)this); 316 char key[33]; sprintf (key, "%32lx", (long)this);
282 317
283 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));
284 hv_store (hv, key, 32, newSViv ((long)this), 0); 319 hv_store (hv, key, 32, newSViv ((long)this), 0);
285} 320}
286 321
287void 322void
288overlay::hide () 323overlay::hide ()
289{ 324{
290 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);
291 326
292 if (ovs) 327 if (ovs)
293 { 328 {
294 char key[33]; sprintf (key, "%32lx", (long)this); 329 char key[33]; sprintf (key, "%32lx", (long)this);
295 330
377{ 412{
378 if (!perl) 413 if (!perl)
379 { 414 {
380 char *argv[] = { 415 char *argv[] = {
381 "", 416 "",
417 "-T",
382 "-edo '" LIBDIR "/urxvt.pm' or ($@ and die $@) or exit 1", 418 "-edo '" LIBDIR "/urxvt.pm' or ($@ and die $@) or exit 1",
383 }; 419 };
384 420
385 perl = perl_alloc (); 421 perl = perl_alloc ();
386 perl_construct (perl); 422 perl_construct (perl);
387 423
388 if (perl_parse (perl, xs_init, 2, argv, (char **)NULL) 424 if (perl_parse (perl, xs_init, 3, argv, (char **)NULL)
389 || perl_run (perl)) 425 || perl_run (perl))
390 { 426 {
391 rxvt_warn ("unable to initialize perl-interpreter, continuing without.\n"); 427 rxvt_warn ("unable to initialize perl-interpreter, continuing without.\n");
392 428
393 perl_destruct (perl); 429 perl_destruct (perl);
395 perl = 0; 431 perl = 0;
396 } 432 }
397 } 433 }
398} 434}
399 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
400bool 447bool
401rxvt_perl_interp::invoke (rxvt_term *term, hook_type htype, ...) 448rxvt_perl_interp::invoke (rxvt_term *term, hook_type htype, ...)
402{ 449{
403 if (!perl) 450 if (!perl)
404 return false; 451 return false;
405 452
406 if (htype == HOOK_INIT) // first hook ever called 453 if (htype == HOOK_INIT) // first hook ever called
407 { 454 {
408 term->self = (void *)newSVptr ((void *)term, "urxvt::term"); 455 term->perl.self = (void *)newSVptr ((void *)term, "urxvt::term");
409 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);
410 } 457 }
411 else if (!term->self) 458 else if (!term->perl.self)
412 return false; // perl not initialized for this instance 459 return false; // perl not initialized for this instance
413 else if (htype == HOOK_DESTROY) 460 else if (htype == HOOK_DESTROY)
414 { 461 {
415 // handled later 462 // handled later
416 } 463 }
417 else if (htype == HOOK_REFRESH_BEGIN || htype == HOOK_REFRESH_END) 464 else if (htype == HOOK_REFRESH_BEGIN || htype == HOOK_REFRESH_END)
418 { 465 {
419 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));
420 467
421 if (HvKEYS (hv)) 468 if (HvKEYS (hv))
422 { 469 {
423 hv_iterinit (hv); 470 hv_iterinit (hv);
424 471
453 500
454 case DT_LONG: 501 case DT_LONG:
455 XPUSHs (sv_2mortal (newSViv (va_arg (ap, long)))); 502 XPUSHs (sv_2mortal (newSViv (va_arg (ap, long))));
456 break; 503 break;
457 504
458 case DT_STRING: 505 case DT_STR:
459 XPUSHs (sv_2mortal (newSVpv (va_arg (ap, char *), 0))); 506 XPUSHs (taint (sv_2mortal (newSVpv (va_arg (ap, char *), 0))));
507 break;
508
509 case DT_STR_LEN:
510 {
511 char *str = va_arg (ap, char *);
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 {
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;
526
527 case DT_XEVENT:
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 }
460 break; 577 break;
461 578
462 case DT_END: 579 case DT_END:
463 { 580 {
464 va_end (ap); 581 va_end (ap);
476 PUTBACK; 593 PUTBACK;
477 FREETMPS; 594 FREETMPS;
478 LEAVE; 595 LEAVE;
479 596
480 if (SvTRUE (ERRSV)) 597 if (SvTRUE (ERRSV))
598 {
481 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 }
482 602
483 if (htype == HOOK_DESTROY) 603 if (htype == HOOK_DESTROY)
484 { 604 {
485 clearSVptr ((SV *)term->self); 605 clearSVptr ((SV *)term->perl.self);
486 SvREFCNT_dec ((SV *)term->self); 606 SvREFCNT_dec ((SV *)term->perl.self);
487 } 607 }
488 608
489 return count; 609 return count;
490 } 610 }
491 611
501 621
502PROTOTYPES: ENABLE 622PROTOTYPES: ENABLE
503 623
504BOOT: 624BOOT:
505{ 625{
506# 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
507 AV *hookname = get_av ("urxvt::HOOKNAME", 1); 628 AV *hookname = get_av ("urxvt::HOOKNAME", 1);
508# define def(sym) av_store (hookname, HOOK_ ## sym, newSVpv (# sym, 0)); 629# define def(sym) av_store (hookname, HOOK_ ## sym, newSVpv (# sym, 0));
509# include "hookinc.h" 630# include "hookinc.h"
510# undef def 631# undef def
511 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));
512 export_const (DEFAULT_RSTYLE); 642 export_const_iv (DEFAULT_RSTYLE);
513 export_const (OVERLAY_RSTYLE); 643 export_const_iv (OVERLAY_RSTYLE);
514 export_const (RS_Bold); 644 export_const_iv (RS_Bold);
515 export_const (RS_Italic); 645 export_const_iv (RS_Italic);
516 export_const (RS_Blink); 646 export_const_iv (RS_Blink);
517 export_const (RS_RVid); 647 export_const_iv (RS_RVid);
518 export_const (RS_Uline); 648 export_const_iv (RS_Uline);
519 649
520 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);
521} 665}
666
667SV *
668new (...)
669 CODE:
670{
671 stringvec *argv = new stringvec;
672 bool success;
673
674 for (int i = 0; i < items ;i++)
675 argv->push_back (strdup (SvPVbyte_nolen (ST (i))));
676
677 rxvt_term *term = new rxvt_term;
678
679 term->argv = argv;
680
681 try
682 {
683 if (!term->init (argv->size (), argv->begin ()))
684 term = 0;
685 }
686 catch (const class rxvt_failure_exception &e)
687 {
688 term->destroy ();
689 croak ("exception caught while initializing new terminal instance");
690 }
691
692 RETVAL = term && term->perl.self ? newSVterm (term) : &PL_sv_undef;
693}
694 OUTPUT:
695 RETVAL
522 696
523void 697void
524set_should_invoke (int htype, int value) 698set_should_invoke (int htype, int value)
525 CODE: 699 CODE:
526 rxvt_perl.should_invoke [htype] = value; 700 rxvt_perl.should_invoke [htype] = value;
532 706
533void 707void
534fatal (const char *msg) 708fatal (const char *msg)
535 CODE: 709 CODE:
536 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
537 726
538NV 727NV
539NOW () 728NOW ()
540 CODE: 729 CODE:
541 RETVAL = NOW; 730 RETVAL = NOW;
589} 778}
590 OUTPUT: 779 OUTPUT:
591 RETVAL 780 RETVAL
592 781
593MODULE = urxvt PACKAGE = urxvt::term 782MODULE = urxvt PACKAGE = urxvt::term
783
784void
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);
594 835
595int 836int
596rxvt_term::strwidth (SV *str) 837rxvt_term::strwidth (SV *str)
597 CODE: 838 CODE:
598{ 839{
617 char *mbstr = rxvt_wcstombs (wstr); 858 char *mbstr = rxvt_wcstombs (wstr);
618 rxvt_pop_locale (); 859 rxvt_pop_locale ();
619 860
620 free (wstr); 861 free (wstr);
621 862
622 RETVAL = newSVpv (mbstr, 0); 863 RETVAL = taint_if (newSVpv (mbstr, 0), str);
623 free (mbstr); 864 free (mbstr);
624} 865}
625 OUTPUT: 866 OUTPUT:
626 RETVAL 867 RETVAL
627 868
634 875
635 rxvt_push_locale (THIS->locale); 876 rxvt_push_locale (THIS->locale);
636 wchar_t *wstr = rxvt_mbstowcs (data, len); 877 wchar_t *wstr = rxvt_mbstowcs (data, len);
637 rxvt_pop_locale (); 878 rxvt_pop_locale ();
638 879
639 char *str = rxvt_wcstoutf8 (wstr); 880 RETVAL = taint_if (wcs2sv (wstr), octets);
640 free (wstr); 881 free (wstr);
641
642 RETVAL = newSVpv (str, 0);
643 SvUTF8_on (RETVAL);
644 free (str);
645} 882}
646 OUTPUT: 883 OUTPUT:
647 RETVAL 884 RETVAL
648 885
649# very portable, especially on objects as opposed to pods 886#define TERM_OFFSET(sym) offsetof (TermWin_t, sym)
650#define TERM_OFFSET(sym) (((char *)&((TermWin_t *)0)->sym) - (char *)(TermWin_t *)0)
651 887
652#define TERM_OFFSET_width TERM_OFFSET(width) 888#define TERM_OFFSET_width TERM_OFFSET(width)
653#define TERM_OFFSET_height TERM_OFFSET(height) 889#define TERM_OFFSET_height TERM_OFFSET(height)
654#define TERM_OFFSET_fwidth TERM_OFFSET(fwidth) 890#define TERM_OFFSET_fwidth TERM_OFFSET(fwidth)
655#define TERM_OFFSET_fheight TERM_OFFSET(fheight) 891#define TERM_OFFSET_fheight TERM_OFFSET(fheight)
680 CODE: 916 CODE:
681 RETVAL = *(int *)((char *)THIS + ix); 917 RETVAL = *(int *)((char *)THIS + ix);
682 OUTPUT: 918 OUTPUT:
683 RETVAL 919 RETVAL
684 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
685U32 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
965U32
686rxvt_term::screen_rstyle (U32 new_rstyle = THIS->screen.s_rstyle) 966rxvt_term::rstyle (U32 new_rstyle = THIS->rstyle)
687 CODE: 967 CODE:
688{ 968{
689 RETVAL = THIS->screen.s_rstyle; 969 RETVAL = THIS->rstyle;
690 THIS->screen.s_rstyle = new_rstyle; 970 THIS->rstyle = new_rstyle;
691} 971}
692 OUTPUT: 972 OUTPUT:
693 RETVAL 973 RETVAL
694 974
695int 975int
711rxvt_term::want_refresh () 991rxvt_term::want_refresh ()
712 CODE: 992 CODE:
713 THIS->want_refresh = 1; 993 THIS->want_refresh = 1;
714 994
715void 995void
716rxvt_term::ROW_t (int row_number, SV *new_text = 0, int start_col = 0) 996rxvt_term::ROW_t (int row_number, SV *new_text = 0, int start_col = 0, int start_ofs = 0, int max_len = MAX_COLS)
717 PPCODE: 997 PPCODE:
718{ 998{
719 if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) 999 if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow))
720 XSRETURN_EMPTY; 1000 XSRETURN_EMPTY;
721 1001
723 1003
724 if (GIMME_V != G_VOID) 1004 if (GIMME_V != G_VOID)
725 { 1005 {
726 wchar_t *wstr = new wchar_t [THIS->ncol]; 1006 wchar_t *wstr = new wchar_t [THIS->ncol];
727 1007
728 for (int col = 0; col <THIS->ncol; col++) 1008 for (int col = 0; col < THIS->ncol; col++)
729 wstr [col] = l.t [col]; 1009 wstr [col] = l.t [col];
730 1010
731 char *str = rxvt_wcstoutf8 (wstr, THIS->ncol); 1011 XPUSHs (taint (sv_2mortal (wcs2sv (wstr, THIS->ncol))));
732 free (wstr);
733 1012
734 SV *sv = newSVpv (str, 0); 1013 delete [] wstr;
735 SvUTF8_on (sv);
736 XPUSHs (sv_2mortal (sv));
737 free (str);
738 } 1014 }
739 1015
740 if (new_text) 1016 if (new_text)
741 { 1017 {
742 wchar_t *wstr = sv2wcs (new_text); 1018 wchar_t *wstr = sv2wcs (new_text);
743 1019
744 int len = wcslen (wstr); 1020 int len = min (wcslen (wstr) - start_ofs, max_len);
745 1021
746 if (!IN_RANGE_INC (start_col, 0, THIS->ncol - len)) 1022 if (!IN_RANGE_INC (start_col, 0, THIS->ncol - len))
747 { 1023 {
748 free (wstr); 1024 free (wstr);
749 croak ("new_text extends beyond horizontal margins"); 1025 croak ("new_text extends beyond horizontal margins");
750 } 1026 }
751 1027
752 for (int col = start_col; col < start_col + len; col++) 1028 for (int col = start_col; col < start_col + len; col++)
753 { 1029 {
754 l.t [col] = wstr [col - start_col]; 1030 l.t [col] = wstr [start_ofs + col - start_col];
755 l.r [col] = SET_FONT (l.r [col], THIS->fontset [GET_STYLE (l.r [col])]->find_font (l.t [col])); 1031 l.r [col] = SET_FONT (l.r [col], THIS->fontset [GET_STYLE (l.r [col])]->find_font (l.t [col]));
756 } 1032 }
757 1033
758 free (wstr); 1034 free (wstr);
759 } 1035 }
760} 1036}
761 1037
762void 1038void
763rxvt_term::ROW_r (int row_number, SV *new_rend = 0, int start_col = 0) 1039rxvt_term::ROW_r (int row_number, SV *new_rend = 0, int start_col = 0, int start_ofs = 0, int max_len = MAX_COLS)
764 PPCODE: 1040 PPCODE:
765{ 1041{
766 if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) 1042 if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow))
767 XSRETURN_EMPTY; 1043 XSRETURN_EMPTY;
768 1044
783 { 1059 {
784 if (!SvROK (new_rend) || SvTYPE (SvRV (new_rend)) != SVt_PVAV) 1060 if (!SvROK (new_rend) || SvTYPE (SvRV (new_rend)) != SVt_PVAV)
785 croak ("new_rend must be arrayref"); 1061 croak ("new_rend must be arrayref");
786 1062
787 AV *av = (AV *)SvRV (new_rend); 1063 AV *av = (AV *)SvRV (new_rend);
788 int len = av_len (av) + 1; 1064 int len = min (av_len (av) + 1 - start_ofs, max_len);
789 1065
790 if (!IN_RANGE_INC (start_col, 0, THIS->ncol - len)) 1066 if (!IN_RANGE_INC (start_col, 0, THIS->ncol - len))
791 croak ("new_rend array extends beyond horizontal margins"); 1067 croak ("new_rend array extends beyond horizontal margins");
792 1068
793 for (int col = start_col; col < start_col + len; col++) 1069 for (int col = start_col; col < start_col + len; col++)
794 { 1070 {
795 rend_t r = SvIV (*av_fetch (av, col - start_col, 1)) & ~RS_fontMask; 1071 rend_t r = SvIV (*av_fetch (av, start_ofs + col - start_col, 1)) & ~RS_fontMask;
796 1072
797 l.r [col] = SET_FONT (r, THIS->fontset [GET_STYLE (r)]->find_font (l.t [col])); 1073 l.r [col] = SET_FONT (r, THIS->fontset [GET_STYLE (r)]->find_font (l.t [col]));
798 } 1074 }
799 } 1075 }
800} 1076}
801 1077
802int 1078int
803rxvt_term::ROW_l (int row_number, int new_length = -2) 1079rxvt_term::ROW_l (int row_number, int new_length = -1)
804 CODE: 1080 CODE:
805{ 1081{
806 if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) 1082 if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow))
807 XSRETURN_EMPTY; 1083 XSRETURN_EMPTY;
808 1084
809 line_t &l = ROW(row_number); 1085 line_t &l = ROW(row_number);
810 RETVAL = l.l < 0 ? THIS->ncol : l.l; 1086 RETVAL = l.l;
811 1087
812 if (new_length >= -1) 1088 if (new_length >= 0)
813 l.l = new_length; 1089 l.l = new_length;
814} 1090}
815 OUTPUT: 1091 OUTPUT:
816 RETVAL 1092 RETVAL
817 1093
818bool 1094bool
819rxvt_term::ROW_is_longer (int row_number) 1095rxvt_term::ROW_is_longer (int row_number, int new_is_longer = -1)
820 CODE: 1096 CODE:
821{ 1097{
822 if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) 1098 if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow))
823 XSRETURN_EMPTY; 1099 XSRETURN_EMPTY;
824 1100
825 line_t &l = ROW(row_number); 1101 line_t &l = ROW(row_number);
826 RETVAL = l.l < 0; 1102 RETVAL = l.is_longer ();
1103
1104 if (new_is_longer >= 0)
1105 l.is_longer (new_is_longer);
827} 1106}
828 OUTPUT: 1107 OUTPUT:
829 RETVAL 1108 RETVAL
830 1109
831SV * 1110SV *
832rxvt_term::special_encode (SV *str) 1111rxvt_term::special_encode (SV *string)
833 CODE: 1112 CODE:
834 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
835 1148
836SV * 1149SV *
837rxvt_term::special_decode (SV *str) 1150rxvt_term::special_decode (SV *text)
838 CODE: 1151 CODE:
839 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
840 1184
841void 1185void
842rxvt_term::_resource (char *name, int index, SV *newval = 0) 1186rxvt_term::_resource (char *name, int index, SV *newval = 0)
843 PPCODE: 1187 PPCODE:
844{ 1188{
861 1205
862 if (!IN_RANGE_EXC (index, 0, NUM_RESOURCES)) 1206 if (!IN_RANGE_EXC (index, 0, NUM_RESOURCES))
863 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);
864 1208
865 if (GIMME_V != G_VOID) 1209 if (GIMME_V != G_VOID)
866 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);
867 1211
868 if (newval) 1212 if (newval)
869 { 1213 {
870 if (SvOK (newval)) 1214 if (SvOK (newval))
871 { 1215 {
876 else 1220 else
877 THIS->rs [index] = 0; 1221 THIS->rs [index] = 0;
878 } 1222 }
879} 1223}
880 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
881void 1261void
882rxvt_term::cur (...) 1262rxvt_term::screen_cur (...)
883 PROTOTYPE: $;$$ 1263 PROTOTYPE: $;$$
884 ALIAS: 1264 ALIAS:
885 screen_cur = 0 1265 screen_cur = 0
886 selection_beg = 1 1266 selection_beg = 1
887 selection_end = 2 1267 selection_end = 2
909 THIS->want_refresh = 1; 1289 THIS->want_refresh = 1;
910 } 1290 }
911} 1291}
912 1292
913int 1293int
914rxvt_term::selection_grab (int eventtime = CurrentTime) 1294rxvt_term::selection_grab (U32 eventtime)
915 1295
916void 1296void
917rxvt_term::selection (SV *newtext = 0) 1297rxvt_term::selection (SV *newtext = 0)
918 PPCODE: 1298 PPCODE:
919{ 1299{
920 if (GIMME_V != G_VOID) 1300 if (GIMME_V != G_VOID)
921 { 1301 XPUSHs (THIS->selection.text
922 char *sel = rxvt_wcstoutf8 (THIS->selection.text, THIS->selection.len); 1302 ? taint (sv_2mortal (wcs2sv (THIS->selection.text, THIS->selection.len)))
923 SV *sv = newSVpv (sel, 0); 1303 : &PL_sv_undef);
924 SvUTF8_on (sv);
925 free (sel);
926 XPUSHs (sv_2mortal (sv));
927 }
928 1304
929 if (newtext) 1305 if (newtext)
930 { 1306 {
931 free (THIS->selection.text); 1307 free (THIS->selection.text);
932 1308
933 THIS->selection.text = sv2wcs (newtext); 1309 THIS->selection.text = sv2wcs (newtext);
934 THIS->selection.len = wcslen (THIS->selection.text); 1310 THIS->selection.len = wcslen (THIS->selection.text);
935 } 1311 }
1312}
1313
1314void
1315rxvt_term::scr_add_lines (SV *string)
1316 CODE:
1317{
1318 wchar_t *wstr = sv2wcs (string);
1319 THIS->scr_add_lines (wstr, wcslen (wstr));
1320 free (wstr);
936} 1321}
937 1322
938void 1323void
939rxvt_term::tt_write (SV *octets) 1324rxvt_term::tt_write (SV *octets)
940 INIT: 1325 INIT:
941 STRLEN len; 1326 STRLEN len;
942 char *str = SvPVbyte (octets, len); 1327 char *str = SvPVbyte (octets, len);
943 C_ARGS: 1328 C_ARGS:
944 str, len 1329 str, len
945 1330
1331void
1332rxvt_term::cmd_parse (SV *octets)
1333 CODE:
1334{
1335 STRLEN len;
1336 char *str = SvPVbyte (octets, len);
1337
1338 char *old_cmdbuf_ptr = THIS->cmdbuf_ptr;
1339 char *old_cmdbuf_endp = THIS->cmdbuf_endp;
1340
1341 THIS->cmdbuf_ptr = str;
1342 THIS->cmdbuf_endp = str + len;
1343
1344 rxvt_push_locale (THIS->locale);
1345 THIS->cmd_parse ();
1346 rxvt_pop_locale ();
1347
1348 THIS->cmdbuf_ptr = old_cmdbuf_ptr;
1349 THIS->cmdbuf_endp = old_cmdbuf_endp;
1350}
1351
946SV * 1352SV *
947rxvt_term::overlay (int x, int y, int w, int h, int rstyle = OVERLAY_RSTYLE, int border = 2) 1353rxvt_term::overlay (int x, int y, int w, int h, int rstyle = OVERLAY_RSTYLE, int border = 2)
948 CODE: 1354 CODE:
949{ 1355{
950 overlay *o = new overlay (THIS, x, y, w, h, rstyle, border); 1356 overlay *o = new overlay (THIS, x, y, w, h, rstyle, border);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines