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.38 by root, Sat Jan 7 21:22:02 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"
51 char *str = SvPVutf8 (sv, len); 52 char *str = SvPVutf8 (sv, len);
52 return rxvt_utf8towcs (str, len); 53 return rxvt_utf8towcs (str, len);
53} 54}
54 55
55static SV * 56static SV *
57wcs2sv (wchar_t *wstr, int len = -1)
58{
59 char *str = rxvt_wcstoutf8 (wstr, len);
60
61 SV *sv = newSVpv (str, 0);
62 SvUTF8_on (sv);
63 free (str);
64
65 return sv;
66}
67
68static SV *
56new_ref (HV *hv, const char *klass) 69new_ref (HV *hv, const char *klass)
57{ 70{
58 return sv_bless (newRV ((SV *)hv), gv_stashpv (klass, 1)); 71 return sv_bless (newRV ((SV *)hv), gv_stashpv (klass, 1));
59} 72}
60 73
89 croak ("perl code used %s object, but C++ object is already destroyed, caught", klass); 102 croak ("perl code used %s object, but C++ object is already destroyed, caught", klass);
90 103
91 return (long)mg->mg_ptr; 104 return (long)mg->mg_ptr;
92} 105}
93 106
94#define newSVterm(term) SvREFCNT_inc ((SV *)term->self) 107#define newSVterm(term) SvREFCNT_inc ((SV *)term->perl.self)
95#define SvTERM(sv) (rxvt_term *)SvPTR (sv, "urxvt::term") 108#define SvTERM(sv) (rxvt_term *)SvPTR (sv, "urxvt::term")
96 109
97///////////////////////////////////////////////////////////////////////////// 110/////////////////////////////////////////////////////////////////////////////
98 111
99struct perl_watcher 112struct perl_watcher
278void 291void
279overlay::show () 292overlay::show ()
280{ 293{
281 char key[33]; sprintf (key, "%32lx", (long)this); 294 char key[33]; sprintf (key, "%32lx", (long)this);
282 295
283 HV *hv = (HV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)THIS->self), "_overlay", 8, 0)); 296 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); 297 hv_store (hv, key, 32, newSViv ((long)this), 0);
285} 298}
286 299
287void 300void
288overlay::hide () 301overlay::hide ()
289{ 302{
290 SV **ovs = hv_fetch ((HV *)SvRV ((SV *)THIS->self), "_overlay", 8, 0); 303 SV **ovs = hv_fetch ((HV *)SvRV ((SV *)THIS->perl.self), "_overlay", 8, 0);
291 304
292 if (ovs) 305 if (ovs)
293 { 306 {
294 char key[33]; sprintf (key, "%32lx", (long)this); 307 char key[33]; sprintf (key, "%32lx", (long)this);
295 308
403 if (!perl) 416 if (!perl)
404 return false; 417 return false;
405 418
406 if (htype == HOOK_INIT) // first hook ever called 419 if (htype == HOOK_INIT) // first hook ever called
407 { 420 {
408 term->self = (void *)newSVptr ((void *)term, "urxvt::term"); 421 term->perl.self = (void *)newSVptr ((void *)term, "urxvt::term");
409 hv_store ((HV *)SvRV ((SV *)term->self), "_overlay", 8, newRV_noinc ((SV *)newHV ()), 0); 422 hv_store ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, newRV_noinc ((SV *)newHV ()), 0);
410 } 423 }
411 else if (!term->self) 424 else if (!term->perl.self)
412 return false; // perl not initialized for this instance 425 return false; // perl not initialized for this instance
413 else if (htype == HOOK_DESTROY) 426 else if (htype == HOOK_DESTROY)
414 { 427 {
415 // handled later 428 // handled later
416 } 429 }
417 else if (htype == HOOK_REFRESH_BEGIN || htype == HOOK_REFRESH_END) 430 else if (htype == HOOK_REFRESH_BEGIN || htype == HOOK_REFRESH_END)
418 { 431 {
419 HV *hv = (HV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->self), "_overlay", 8, 0)); 432 HV *hv = (HV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, 0));
420 433
421 if (HvKEYS (hv)) 434 if (HvKEYS (hv))
422 { 435 {
423 hv_iterinit (hv); 436 hv_iterinit (hv);
424 437
453 466
454 case DT_LONG: 467 case DT_LONG:
455 XPUSHs (sv_2mortal (newSViv (va_arg (ap, long)))); 468 XPUSHs (sv_2mortal (newSViv (va_arg (ap, long))));
456 break; 469 break;
457 470
458 case DT_STRING: 471 case DT_STR:
459 XPUSHs (sv_2mortal (newSVpv (va_arg (ap, char *), 0))); 472 XPUSHs (sv_2mortal (newSVpv (va_arg (ap, char *), 0)));
473 break;
474
475 case DT_STR_LEN:
476 {
477 char *str = va_arg (ap, char *);
478 int len = va_arg (ap, int);
479
480 XPUSHs (sv_2mortal (newSVpvn (str, len)));
481 }
482 break;
483
484 case DT_WCS_LEN:
485 {
486 wchar_t *wstr = va_arg (ap, wchar_t *);
487 int wlen = va_arg (ap, int);
488
489 XPUSHs (sv_2mortal (wcs2sv (wstr, wlen)));
490 }
491 break;
492
493 case DT_XEVENT:
494 {
495 XEvent *xe = va_arg (ap, XEvent *);
496 HV *hv = newHV ();
497
498# define set(name, sv) hv_store (hv, # name, sizeof (# name) - 1, sv, 0)
499# define setiv(name, val) hv_store (hv, # name, sizeof (# name) - 1, newSViv (val), 0)
500# undef set
501
502 setiv (type, xe->type);
503 setiv (send_event, xe->xany.send_event);
504 setiv (serial, xe->xany.serial);
505
506 switch (xe->type)
507 {
508 case KeyPress:
509 case KeyRelease:
510 case ButtonPress:
511 case ButtonRelease:
512 case MotionNotify:
513 setiv (time, xe->xmotion.time);
514 setiv (x, xe->xmotion.x);
515 setiv (y, xe->xmotion.y);
516 setiv (row, xe->xmotion.y / term->fheight);
517 setiv (col, xe->xmotion.x / term->fwidth);
518 setiv (x_root, xe->xmotion.x_root);
519 setiv (y_root, xe->xmotion.y_root);
520 setiv (state, xe->xmotion.state);
521 break;
522 }
523
524 switch (xe->type)
525 {
526 case KeyPress:
527 case KeyRelease:
528 setiv (keycode, xe->xkey.keycode);
529 break;
530
531 case ButtonPress:
532 case ButtonRelease:
533 setiv (button, xe->xbutton.button);
534 break;
535
536 case MotionNotify:
537 setiv (is_hint, xe->xmotion.is_hint);
538 break;
539 }
540
541 XPUSHs (sv_2mortal (newRV_noinc ((SV *)hv)));
542 }
460 break; 543 break;
461 544
462 case DT_END: 545 case DT_END:
463 { 546 {
464 va_end (ap); 547 va_end (ap);
480 if (SvTRUE (ERRSV)) 563 if (SvTRUE (ERRSV))
481 rxvt_warn ("perl hook %d evaluation error: %s", htype, SvPV_nolen (ERRSV)); 564 rxvt_warn ("perl hook %d evaluation error: %s", htype, SvPV_nolen (ERRSV));
482 565
483 if (htype == HOOK_DESTROY) 566 if (htype == HOOK_DESTROY)
484 { 567 {
485 clearSVptr ((SV *)term->self); 568 clearSVptr ((SV *)term->perl.self);
486 SvREFCNT_dec ((SV *)term->self); 569 SvREFCNT_dec ((SV *)term->perl.self);
487 } 570 }
488 571
489 return count; 572 return count;
490 } 573 }
491 574
501 584
502PROTOTYPES: ENABLE 585PROTOTYPES: ENABLE
503 586
504BOOT: 587BOOT:
505{ 588{
589 HV *stash = gv_stashpv ("urxvt", 1);
506# define export_const(name) newCONSTSUB (gv_stashpv ("urxvt", 1), # name, newSViv (name)); 590# define export_const_iv(name) newCONSTSUB (stash, # name, newSViv (name));
591
507 AV *hookname = get_av ("urxvt::HOOKNAME", 1); 592 AV *hookname = get_av ("urxvt::HOOKNAME", 1);
508# define def(sym) av_store (hookname, HOOK_ ## sym, newSVpv (# sym, 0)); 593# define def(sym) av_store (hookname, HOOK_ ## sym, newSVpv (# sym, 0));
509# include "hookinc.h" 594# include "hookinc.h"
510# undef def 595# undef def
511 596
597
512 export_const (DEFAULT_RSTYLE); 598 export_const_iv (DEFAULT_RSTYLE);
513 export_const (OVERLAY_RSTYLE); 599 export_const_iv (OVERLAY_RSTYLE);
514 export_const (RS_Bold); 600 export_const_iv (RS_Bold);
515 export_const (RS_Italic); 601 export_const_iv (RS_Italic);
516 export_const (RS_Blink); 602 export_const_iv (RS_Blink);
517 export_const (RS_RVid); 603 export_const_iv (RS_RVid);
518 export_const (RS_Uline); 604 export_const_iv (RS_Uline);
519 605
520 sv_setpv (get_sv ("urxvt::LIBDIR", 1), LIBDIR); 606 export_const_iv (CurrentTime);
607 export_const_iv (ShiftMask);
608 export_const_iv (LockMask);
609 export_const_iv (ControlMask);
610 export_const_iv (Mod1Mask);
611 export_const_iv (Mod2Mask);
612 export_const_iv (Mod3Mask);
613 export_const_iv (Mod4Mask);
614 export_const_iv (Mod5Mask);
615 export_const_iv (Button1Mask);
616 export_const_iv (Button2Mask);
617 export_const_iv (Button3Mask);
618 export_const_iv (Button4Mask);
619 export_const_iv (Button5Mask);
620 export_const_iv (AnyModifier);
621
622 sv_setsv (get_sv ("urxvt::LIBDIR", 1), newSVpvn (LIBDIR, sizeof (LIBDIR) - 1));
521} 623}
624
625SV *
626new (...)
627 CODE:
628{
629 stringvec *argv = new stringvec;
630 bool success;
631
632 for (int i = 0; i < items ;i++)
633 argv->push_back (strdup (SvPVbyte_nolen (ST (i))));
634
635 rxvt_term *term = new rxvt_term;
636
637 term->argv = argv;
638
639 try
640 {
641 if (!term->init (argv->size (), argv->begin ()))
642 term = 0;
643 }
644 catch (const class rxvt_failure_exception &e)
645 {
646 term->destroy ();
647 croak ("exception caught while initializing new terminal instance");
648 }
649
650 RETVAL = term && term->perl.self ? newSVterm (term) : &PL_sv_undef;
651}
652 OUTPUT:
653 RETVAL
522 654
523void 655void
524set_should_invoke (int htype, int value) 656set_should_invoke (int htype, int value)
525 CODE: 657 CODE:
526 rxvt_perl.should_invoke [htype] = value; 658 rxvt_perl.should_invoke [htype] = value;
589} 721}
590 OUTPUT: 722 OUTPUT:
591 RETVAL 723 RETVAL
592 724
593MODULE = urxvt PACKAGE = urxvt::term 725MODULE = urxvt PACKAGE = urxvt::term
726
727void
728rxvt_term::destroy ()
729
730void
731rxvt_term::grab_button (int button, U32 modifiers)
732 CODE:
733 XGrabButton (THIS->display->display, button, modifiers, THIS->vt, 1,
734 ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask,
735 GrabModeSync, GrabModeSync, None, None);
736
737bool
738rxvt_term::grab (U32 eventtime, int sync = 0)
739 CODE:
740{
741 int mode = sync ? GrabModeSync : GrabModeAsync;
742
743 THIS->perl.grabtime = 0;
744
745 if (!XGrabPointer (THIS->display->display, THIS->vt, 0,
746 ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask,
747 mode, mode, None, None, eventtime))
748 if (!XGrabKeyboard (THIS->display->display, THIS->vt, 0, mode, mode, eventtime))
749 THIS->perl.grabtime = eventtime;
750 else
751 XUngrabPointer (THIS->display->display, eventtime);
752
753 RETVAL = !!THIS->perl.grabtime;
754}
755 OUTPUT:
756 RETVAL
757
758void
759rxvt_term::allow_events_async (U32 eventtime = THIS->perl.grabtime)
760 CODE:
761 XAllowEvents (THIS->display->display, AsyncBoth, eventtime);
762
763void
764rxvt_term::allow_events_sync (U32 eventtime = THIS->perl.grabtime)
765 CODE:
766 XAllowEvents (THIS->display->display, SyncBoth, eventtime);
767
768void
769rxvt_term::allow_events_replay (U32 eventtime = THIS->perl.grabtime)
770 CODE:
771 XAllowEvents (THIS->display->display, ReplayPointer, eventtime);
772 XAllowEvents (THIS->display->display, ReplayKeyboard, eventtime);
773
774void
775rxvt_term::ungrab (U32 eventtime = THIS->perl.grabtime)
776 CODE:
777 THIS->perl.grabtime = 0;
778 XUngrabKeyboard (THIS->display->display, eventtime);
779 XUngrabPointer (THIS->display->display, eventtime);
594 780
595int 781int
596rxvt_term::strwidth (SV *str) 782rxvt_term::strwidth (SV *str)
597 CODE: 783 CODE:
598{ 784{
634 820
635 rxvt_push_locale (THIS->locale); 821 rxvt_push_locale (THIS->locale);
636 wchar_t *wstr = rxvt_mbstowcs (data, len); 822 wchar_t *wstr = rxvt_mbstowcs (data, len);
637 rxvt_pop_locale (); 823 rxvt_pop_locale ();
638 824
639 char *str = rxvt_wcstoutf8 (wstr); 825 RETVAL = wcs2sv (wstr);
640 free (wstr); 826 free (wstr);
641
642 RETVAL = newSVpv (str, 0);
643 SvUTF8_on (RETVAL);
644 free (str);
645} 827}
646 OUTPUT: 828 OUTPUT:
647 RETVAL 829 RETVAL
648 830
649# very portable, especially on objects as opposed to pods 831#define TERM_OFFSET(sym) offsetof (TermWin_t, sym)
650#define TERM_OFFSET(sym) (((char *)&((TermWin_t *)0)->sym) - (char *)(TermWin_t *)0)
651 832
652#define TERM_OFFSET_width TERM_OFFSET(width) 833#define TERM_OFFSET_width TERM_OFFSET(width)
653#define TERM_OFFSET_height TERM_OFFSET(height) 834#define TERM_OFFSET_height TERM_OFFSET(height)
654#define TERM_OFFSET_fwidth TERM_OFFSET(fwidth) 835#define TERM_OFFSET_fwidth TERM_OFFSET(fwidth)
655#define TERM_OFFSET_fheight TERM_OFFSET(fheight) 836#define TERM_OFFSET_fheight TERM_OFFSET(fheight)
680 CODE: 861 CODE:
681 RETVAL = *(int *)((char *)THIS + ix); 862 RETVAL = *(int *)((char *)THIS + ix);
682 OUTPUT: 863 OUTPUT:
683 RETVAL 864 RETVAL
684 865
866unsigned int
867rxvt_term::ModLevel3Mask ()
868 ALIAS:
869 ModLevel3Mask = 0
870 ModMetaMask = 1
871 ModNumLockMask = 2
872 CODE:
873 switch (ix)
874 {
875 case 0: RETVAL = THIS->ModLevel3Mask; break;
876 case 1: RETVAL = THIS->ModMetaMask; break;
877 case 2: RETVAL = THIS->ModNumLockMask; break;
878 }
879 OUTPUT:
880 RETVAL
881
685U32 882U32
883rxvt_term::parent ()
884 CODE:
885 RETVAL = (U32)THIS->parent [0];
886 OUTPUT:
887 RETVAL
888
889U32
890rxvt_term::vt ()
891 CODE:
892 RETVAL = (U32)THIS->vt;
893 OUTPUT:
894 RETVAL
895
896U32
686rxvt_term::screen_rstyle (U32 new_rstyle = THIS->screen.s_rstyle) 897rxvt_term::rstyle (U32 new_rstyle = THIS->rstyle)
687 CODE: 898 CODE:
688{ 899{
689 RETVAL = THIS->screen.s_rstyle; 900 RETVAL = THIS->rstyle;
690 THIS->screen.s_rstyle = new_rstyle; 901 THIS->rstyle = new_rstyle;
691} 902}
692 OUTPUT: 903 OUTPUT:
693 RETVAL 904 RETVAL
694 905
695int 906int
711rxvt_term::want_refresh () 922rxvt_term::want_refresh ()
712 CODE: 923 CODE:
713 THIS->want_refresh = 1; 924 THIS->want_refresh = 1;
714 925
715void 926void
716rxvt_term::ROW_t (int row_number, SV *new_text = 0, int start_col = 0) 927rxvt_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: 928 PPCODE:
718{ 929{
719 if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) 930 if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow))
720 XSRETURN_EMPTY; 931 XSRETURN_EMPTY;
721 932
723 934
724 if (GIMME_V != G_VOID) 935 if (GIMME_V != G_VOID)
725 { 936 {
726 wchar_t *wstr = new wchar_t [THIS->ncol]; 937 wchar_t *wstr = new wchar_t [THIS->ncol];
727 938
728 for (int col = 0; col <THIS->ncol; col++) 939 for (int col = 0; col < THIS->ncol; col++)
729 wstr [col] = l.t [col]; 940 wstr [col] = l.t [col];
730 941
731 char *str = rxvt_wcstoutf8 (wstr, THIS->ncol);
732 free (wstr);
733
734 SV *sv = newSVpv (str, 0);
735 SvUTF8_on (sv);
736 XPUSHs (sv_2mortal (sv)); 942 XPUSHs (sv_2mortal (wcs2sv (wstr, THIS->ncol)));
737 free (str); 943
944 delete [] wstr;
738 } 945 }
739 946
740 if (new_text) 947 if (new_text)
741 { 948 {
742 wchar_t *wstr = sv2wcs (new_text); 949 wchar_t *wstr = sv2wcs (new_text);
743 950
744 int len = wcslen (wstr); 951 int len = min (wcslen (wstr) - start_ofs, max_len);
745 952
746 if (!IN_RANGE_INC (start_col, 0, THIS->ncol - len)) 953 if (!IN_RANGE_INC (start_col, 0, THIS->ncol - len))
747 { 954 {
748 free (wstr); 955 free (wstr);
749 croak ("new_text extends beyond horizontal margins"); 956 croak ("new_text extends beyond horizontal margins");
750 } 957 }
751 958
752 for (int col = start_col; col < start_col + len; col++) 959 for (int col = start_col; col < start_col + len; col++)
753 { 960 {
754 l.t [col] = wstr [col - start_col]; 961 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])); 962 l.r [col] = SET_FONT (l.r [col], THIS->fontset [GET_STYLE (l.r [col])]->find_font (l.t [col]));
756 } 963 }
757 964
758 free (wstr); 965 free (wstr);
759 } 966 }
760} 967}
761 968
762void 969void
763rxvt_term::ROW_r (int row_number, SV *new_rend = 0, int start_col = 0) 970rxvt_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: 971 PPCODE:
765{ 972{
766 if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) 973 if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow))
767 XSRETURN_EMPTY; 974 XSRETURN_EMPTY;
768 975
783 { 990 {
784 if (!SvROK (new_rend) || SvTYPE (SvRV (new_rend)) != SVt_PVAV) 991 if (!SvROK (new_rend) || SvTYPE (SvRV (new_rend)) != SVt_PVAV)
785 croak ("new_rend must be arrayref"); 992 croak ("new_rend must be arrayref");
786 993
787 AV *av = (AV *)SvRV (new_rend); 994 AV *av = (AV *)SvRV (new_rend);
788 int len = av_len (av) + 1; 995 int len = min (av_len (av) + 1 - start_ofs, max_len);
789 996
790 if (!IN_RANGE_INC (start_col, 0, THIS->ncol - len)) 997 if (!IN_RANGE_INC (start_col, 0, THIS->ncol - len))
791 croak ("new_rend array extends beyond horizontal margins"); 998 croak ("new_rend array extends beyond horizontal margins");
792 999
793 for (int col = start_col; col < start_col + len; col++) 1000 for (int col = start_col; col < start_col + len; col++)
794 { 1001 {
795 rend_t r = SvIV (*av_fetch (av, col - start_col, 1)) & ~RS_fontMask; 1002 rend_t r = SvIV (*av_fetch (av, start_ofs + col - start_col, 1)) & ~RS_fontMask;
796 1003
797 l.r [col] = SET_FONT (r, THIS->fontset [GET_STYLE (r)]->find_font (l.t [col])); 1004 l.r [col] = SET_FONT (r, THIS->fontset [GET_STYLE (r)]->find_font (l.t [col]));
798 } 1005 }
799 } 1006 }
800} 1007}
801 1008
802int 1009int
803rxvt_term::ROW_l (int row_number, int new_length = -2) 1010rxvt_term::ROW_l (int row_number, int new_length = -1)
804 CODE: 1011 CODE:
805{ 1012{
806 if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) 1013 if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow))
807 XSRETURN_EMPTY; 1014 XSRETURN_EMPTY;
808 1015
809 line_t &l = ROW(row_number); 1016 line_t &l = ROW(row_number);
810 RETVAL = l.l < 0 ? THIS->ncol : l.l; 1017 RETVAL = l.l;
811 1018
812 if (new_length >= -1) 1019 if (new_length >= 0)
813 l.l = new_length; 1020 l.l = new_length;
814} 1021}
815 OUTPUT: 1022 OUTPUT:
816 RETVAL 1023 RETVAL
817 1024
818bool 1025bool
819rxvt_term::ROW_is_longer (int row_number) 1026rxvt_term::ROW_is_longer (int row_number, int new_is_longer = -1)
820 CODE: 1027 CODE:
821{ 1028{
822 if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) 1029 if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow))
823 XSRETURN_EMPTY; 1030 XSRETURN_EMPTY;
824 1031
825 line_t &l = ROW(row_number); 1032 line_t &l = ROW(row_number);
826 RETVAL = l.l < 0; 1033 RETVAL = l.is_longer ();
1034
1035 if (new_is_longer >= 0)
1036 l.is_longer (new_is_longer);
827} 1037}
828 OUTPUT: 1038 OUTPUT:
829 RETVAL 1039 RETVAL
830 1040
831SV * 1041SV *
832rxvt_term::special_encode (SV *str) 1042rxvt_term::special_encode (SV *string)
833 CODE: 1043 CODE:
834 abort ();//TODO 1044{
1045 wchar_t *wstr = sv2wcs (string);
1046 int wlen = wcslen (wstr);
1047 wchar_t *rstr = new wchar_t [wlen]; // cannot become longer
1048
1049 rxvt_push_locale (THIS->locale);
1050
1051 wchar_t *r = rstr;
1052 for (wchar_t *s = wstr; *s; s++)
1053 if (wcwidth (*s) == 0)
1054 {
1055 if (r == rstr)
1056 croak ("leading combining character unencodable");
1057
1058 unicode_t n = rxvt_compose (r[-1], *s);
1059 if (n == NOCHAR)
1060 n = rxvt_composite.compose (r[-1], *s);
1061
1062 r[-1] = n;
1063 }
1064#if !UNICODE_3
1065 else if (*s >= 0x10000)
1066 *r++ = rxvt_composite.compose (*s);
1067#endif
1068 else
1069 *r++ = *s;
1070
1071 rxvt_pop_locale ();
1072
1073 RETVAL = wcs2sv (rstr, r - rstr);
1074
1075 delete [] rstr;
1076}
1077 OUTPUT:
1078 RETVAL
835 1079
836SV * 1080SV *
837rxvt_term::special_decode (SV *str) 1081rxvt_term::special_decode (SV *text)
838 CODE: 1082 CODE:
839 abort ();//TODO 1083{
1084 wchar_t *wstr = sv2wcs (text);
1085 int wlen = wcslen (wstr);
1086 int dlen = 0;
1087
1088 // find length
1089 for (wchar_t *s = wstr; *s; s++)
1090 if (*s == NOCHAR)
1091 ;
1092 else if (IS_COMPOSE (*s))
1093 dlen += rxvt_composite.expand (*s, 0);
1094 else
1095 dlen++;
1096
1097 wchar_t *rstr = new wchar_t [dlen];
1098
1099 // decode
1100 wchar_t *r = rstr;
1101 for (wchar_t *s = wstr; *s; s++)
1102 if (*s == NOCHAR)
1103 ;
1104 else if (IS_COMPOSE (*s))
1105 r += rxvt_composite.expand (*s, r);
1106 else
1107 *r++ = *s;
1108
1109 RETVAL = wcs2sv (rstr, r - rstr);
1110
1111 delete [] rstr;
1112}
1113 OUTPUT:
1114 RETVAL
840 1115
841void 1116void
842rxvt_term::_resource (char *name, int index, SV *newval = 0) 1117rxvt_term::_resource (char *name, int index, SV *newval = 0)
843 PPCODE: 1118 PPCODE:
844{ 1119{
909 THIS->want_refresh = 1; 1184 THIS->want_refresh = 1;
910 } 1185 }
911} 1186}
912 1187
913int 1188int
914rxvt_term::selection_grab (int eventtime = CurrentTime) 1189rxvt_term::selection_grab (U32 eventtime)
915 1190
916void 1191void
917rxvt_term::selection (SV *newtext = 0) 1192rxvt_term::selection (SV *newtext = 0)
918 PPCODE: 1193 PPCODE:
919{ 1194{
920 if (GIMME_V != G_VOID) 1195 if (GIMME_V != G_VOID)
921 { 1196 XPUSHs (sv_2mortal (wcs2sv (THIS->selection.text, THIS->selection.len)));
922 char *sel = rxvt_wcstoutf8 (THIS->selection.text, THIS->selection.len);
923 SV *sv = newSVpv (sel, 0);
924 SvUTF8_on (sv);
925 free (sel);
926 XPUSHs (sv_2mortal (sv));
927 }
928 1197
929 if (newtext) 1198 if (newtext)
930 { 1199 {
931 free (THIS->selection.text); 1200 free (THIS->selection.text);
932 1201
933 THIS->selection.text = sv2wcs (newtext); 1202 THIS->selection.text = sv2wcs (newtext);
934 THIS->selection.len = wcslen (THIS->selection.text); 1203 THIS->selection.len = wcslen (THIS->selection.text);
935 } 1204 }
1205}
1206
1207void
1208rxvt_term::scr_add_lines (SV *string)
1209 CODE:
1210{
1211 wchar_t *wstr = sv2wcs (string);
1212 THIS->scr_add_lines (wstr, wcslen (wstr));
1213 free (wstr);
936} 1214}
937 1215
938void 1216void
939rxvt_term::tt_write (SV *octets) 1217rxvt_term::tt_write (SV *octets)
940 INIT: 1218 INIT:
941 STRLEN len; 1219 STRLEN len;
942 char *str = SvPVbyte (octets, len); 1220 char *str = SvPVbyte (octets, len);
943 C_ARGS: 1221 C_ARGS:
944 str, len 1222 str, len
945 1223
1224void
1225rxvt_term::cmd_parse (SV *octets)
1226 CODE:
1227{
1228 STRLEN len;
1229 char *str = SvPVbyte (octets, len);
1230
1231 char *old_cmdbuf_ptr = THIS->cmdbuf_ptr;
1232 char *old_cmdbuf_endp = THIS->cmdbuf_endp;
1233
1234 THIS->cmdbuf_ptr = str;
1235 THIS->cmdbuf_endp = str + len;
1236
1237 rxvt_push_locale (THIS->locale);
1238 THIS->cmd_parse ();
1239 rxvt_pop_locale ();
1240
1241 THIS->cmdbuf_ptr = old_cmdbuf_ptr;
1242 THIS->cmdbuf_endp = old_cmdbuf_endp;
1243}
1244
946SV * 1245SV *
947rxvt_term::overlay (int x, int y, int w, int h, int rstyle = OVERLAY_RSTYLE, int border = 2) 1246rxvt_term::overlay (int x, int y, int w, int h, int rstyle = OVERLAY_RSTYLE, int border = 2)
948 CODE: 1247 CODE:
949{ 1248{
950 overlay *o = new overlay (THIS, x, y, w, h, rstyle, border); 1249 overlay *o = new overlay (THIS, x, y, w, h, rstyle, border);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines