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.52 by root, Tue Jan 10 04:23:39 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
34#include "iom.h"
33#include "rxvt.h" 35#include "rxvt.h"
34#include "iom.h" 36#include "keyboard.h"
35#include "rxvtutil.h" 37#include "rxvtutil.h"
36#include "rxvtperl.h" 38#include "rxvtperl.h"
37 39
38#include "perlxsi.c" 40#include "perlxsi.c"
41
42#if defined(HAVE_SCROLLBARS) || defined(MENUBAR)
43# define GRAB_CURSOR THIS->leftptr_cursor
44#else
45# define GRAB_CURSOR None
46#endif
39 47
40#undef LINENO 48#undef LINENO
41#define LINENO(n) MOD (THIS->term_start + int(n), THIS->total_rows) 49#define LINENO(n) MOD (THIS->term_start + int(n), THIS->total_rows)
42#undef ROW 50#undef ROW
43#define ROW(n) THIS->row_buf [LINENO (n)] 51#define ROW(n) THIS->row_buf [LINENO (n)]
44 52
45///////////////////////////////////////////////////////////////////////////// 53/////////////////////////////////////////////////////////////////////////////
46 54
55static SV *
56taint (SV *sv)
57{
58 SvTAINT (sv);
59 return sv;
60}
61
62static SV *
63taint_if (SV *sv, SV *src)
64{
65 if (SvTAINTED (src))
66 SvTAINT (sv);
67
68 return sv;
69}
70
47static wchar_t * 71static wchar_t *
48sv2wcs (SV *sv) 72sv2wcs (SV *sv)
49{ 73{
50 STRLEN len; 74 STRLEN len;
51 char *str = SvPVutf8 (sv, len); 75 char *str = SvPVutf8 (sv, len);
52 return rxvt_utf8towcs (str, len); 76 return rxvt_utf8towcs (str, len);
53} 77}
54 78
55static SV * 79static SV *
80wcs2sv (wchar_t *wstr, int len = -1)
81{
82 char *str = rxvt_wcstoutf8 (wstr, len);
83
84 SV *sv = newSVpv (str, 0);
85 SvUTF8_on (sv);
86 free (str);
87
88 return sv;
89}
90
91static SV *
56new_ref (HV *hv, const char *klass) 92new_ref (HV *hv, const char *klass)
57{ 93{
58 return sv_bless (newRV ((SV *)hv), gv_stashpv (klass, 1)); 94 return sv_bless (newRV ((SV *)hv), gv_stashpv (klass, 1));
59} 95}
60 96
89 croak ("perl code used %s object, but C++ object is already destroyed, caught", klass); 125 croak ("perl code used %s object, but C++ object is already destroyed, caught", klass);
90 126
91 return (long)mg->mg_ptr; 127 return (long)mg->mg_ptr;
92} 128}
93 129
94#define newSVterm(term) SvREFCNT_inc ((SV *)term->self) 130#define newSVterm(term) SvREFCNT_inc ((SV *)term->perl.self)
95#define SvTERM(sv) (rxvt_term *)SvPTR (sv, "urxvt::term") 131#define SvTERM(sv) (rxvt_term *)SvPTR (sv, "urxvt::term")
96 132
97///////////////////////////////////////////////////////////////////////////// 133/////////////////////////////////////////////////////////////////////////////
98 134
99struct perl_watcher 135struct perl_watcher
278void 314void
279overlay::show () 315overlay::show ()
280{ 316{
281 char key[33]; sprintf (key, "%32lx", (long)this); 317 char key[33]; sprintf (key, "%32lx", (long)this);
282 318
283 HV *hv = (HV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)THIS->self), "_overlay", 8, 0)); 319 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); 320 hv_store (hv, key, 32, newSViv ((long)this), 0);
285} 321}
286 322
287void 323void
288overlay::hide () 324overlay::hide ()
289{ 325{
290 SV **ovs = hv_fetch ((HV *)SvRV ((SV *)THIS->self), "_overlay", 8, 0); 326 SV **ovs = hv_fetch ((HV *)SvRV ((SV *)THIS->perl.self), "_overlay", 8, 0);
291 327
292 if (ovs) 328 if (ovs)
293 { 329 {
294 char key[33]; sprintf (key, "%32lx", (long)this); 330 char key[33]; sprintf (key, "%32lx", (long)this);
295 331
377{ 413{
378 if (!perl) 414 if (!perl)
379 { 415 {
380 char *argv[] = { 416 char *argv[] = {
381 "", 417 "",
418 "-T",
382 "-edo '" LIBDIR "/urxvt.pm' or ($@ and die $@) or exit 1", 419 "-edo '" LIBDIR "/urxvt.pm' or ($@ and die $@) or exit 1",
383 }; 420 };
384 421
385 perl = perl_alloc (); 422 perl = perl_alloc ();
386 perl_construct (perl); 423 perl_construct (perl);
387 424
388 if (perl_parse (perl, xs_init, 2, argv, (char **)NULL) 425 if (perl_parse (perl, xs_init, 3, argv, (char **)NULL)
389 || perl_run (perl)) 426 || perl_run (perl))
390 { 427 {
391 rxvt_warn ("unable to initialize perl-interpreter, continuing without.\n"); 428 rxvt_warn ("unable to initialize perl-interpreter, continuing without.\n");
392 429
393 perl_destruct (perl); 430 perl_destruct (perl);
395 perl = 0; 432 perl = 0;
396 } 433 }
397 } 434 }
398} 435}
399 436
437static void
438ungrab (rxvt_term *THIS)
439{
440 if (THIS->perl.grabtime)
441 {
442 XUngrabKeyboard (THIS->display->display, THIS->perl.grabtime);
443 XUngrabPointer (THIS->display->display, THIS->perl.grabtime);
444 THIS->perl.grabtime = 0;
445 }
446}
447
400bool 448bool
401rxvt_perl_interp::invoke (rxvt_term *term, hook_type htype, ...) 449rxvt_perl_interp::invoke (rxvt_term *term, hook_type htype, ...)
402{ 450{
403 if (!perl) 451 if (!perl)
404 return false; 452 return false;
405 453
406 if (htype == HOOK_INIT) // first hook ever called 454 if (htype == HOOK_INIT) // first hook ever called
407 { 455 {
408 term->self = (void *)newSVptr ((void *)term, "urxvt::term"); 456 term->perl.self = (void *)newSVptr ((void *)term, "urxvt::term");
409 hv_store ((HV *)SvRV ((SV *)term->self), "_overlay", 8, newRV_noinc ((SV *)newHV ()), 0); 457 hv_store ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, newRV_noinc ((SV *)newHV ()), 0);
410 } 458 }
411 else if (!term->self) 459 else if (!term->perl.self)
412 return false; // perl not initialized for this instance 460 return false; // perl not initialized for this instance
413 else if (htype == HOOK_DESTROY) 461 else if (htype == HOOK_DESTROY)
414 { 462 {
415 // handled later 463 // handled later
416 } 464 }
417 else if (htype == HOOK_REFRESH_BEGIN || htype == HOOK_REFRESH_END) 465 else
418 { 466 {
419 HV *hv = (HV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->self), "_overlay", 8, 0)); 467 if (htype == HOOK_REFRESH_BEGIN || htype == HOOK_REFRESH_END)
420
421 if (HvKEYS (hv))
422 { 468 {
469 HV *hv = (HV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, 0));
470
471 if (HvKEYS (hv))
472 {
423 hv_iterinit (hv); 473 hv_iterinit (hv);
424 474
425 while (HE *he = hv_iternext (hv)) 475 while (HE *he = hv_iternext (hv))
426 ((overlay *)SvIV (hv_iterval (hv, he)))->swap (); 476 ((overlay *)SvIV (hv_iterval (hv, he)))->swap ();
477 }
478
427 } 479 }
480
481 if (!should_invoke [htype])
482 return false;
428 } 483 }
429 else if (!should_invoke [htype])
430 return false;
431 484
432 dSP; 485 dSP;
433 va_list ap; 486 va_list ap;
434 487
435 va_start (ap, htype); 488 va_start (ap, htype);
453 506
454 case DT_LONG: 507 case DT_LONG:
455 XPUSHs (sv_2mortal (newSViv (va_arg (ap, long)))); 508 XPUSHs (sv_2mortal (newSViv (va_arg (ap, long))));
456 break; 509 break;
457 510
458 case DT_STRING: 511 case DT_STR:
459 XPUSHs (sv_2mortal (newSVpv (va_arg (ap, char *), 0))); 512 XPUSHs (taint (sv_2mortal (newSVpv (va_arg (ap, char *), 0))));
513 break;
514
515 case DT_STR_LEN:
516 {
517 char *str = va_arg (ap, char *);
518 int len = va_arg (ap, int);
519
520 XPUSHs (taint (sv_2mortal (newSVpvn (str, len))));
521 }
522 break;
523
524 case DT_WCS_LEN:
525 {
526 wchar_t *wstr = va_arg (ap, wchar_t *);
527 int wlen = va_arg (ap, int);
528
529 XPUSHs (taint (sv_2mortal (wcs2sv (wstr, wlen))));
530 }
531 break;
532
533 case DT_XEVENT:
534 {
535 XEvent *xe = va_arg (ap, XEvent *);
536 HV *hv = newHV ();
537
538# define set(name, sv) hv_store (hv, # name, sizeof (# name) - 1, sv, 0)
539# define setiv(name, val) hv_store (hv, # name, sizeof (# name) - 1, newSViv (val), 0)
540# undef set
541
542 setiv (type, xe->type);
543 setiv (send_event, xe->xany.send_event);
544 setiv (serial, xe->xany.serial);
545
546 switch (xe->type)
547 {
548 case KeyPress:
549 case KeyRelease:
550 case ButtonPress:
551 case ButtonRelease:
552 case MotionNotify:
553 setiv (time, xe->xmotion.time);
554 setiv (x, xe->xmotion.x);
555 setiv (y, xe->xmotion.y);
556 setiv (row, xe->xmotion.y / term->fheight);
557 setiv (col, xe->xmotion.x / term->fwidth);
558 setiv (x_root, xe->xmotion.x_root);
559 setiv (y_root, xe->xmotion.y_root);
560 setiv (state, xe->xmotion.state);
561 break;
562 }
563
564 switch (xe->type)
565 {
566 case KeyPress:
567 case KeyRelease:
568 setiv (keycode, xe->xkey.keycode);
569 break;
570
571 case ButtonPress:
572 case ButtonRelease:
573 setiv (button, xe->xbutton.button);
574 break;
575
576 case MotionNotify:
577 setiv (is_hint, xe->xmotion.is_hint);
578 break;
579 }
580
581 XPUSHs (sv_2mortal (newRV_noinc ((SV *)hv)));
582 }
460 break; 583 break;
461 584
462 case DT_END: 585 case DT_END:
463 { 586 {
464 va_end (ap); 587 va_end (ap);
476 PUTBACK; 599 PUTBACK;
477 FREETMPS; 600 FREETMPS;
478 LEAVE; 601 LEAVE;
479 602
480 if (SvTRUE (ERRSV)) 603 if (SvTRUE (ERRSV))
604 {
481 rxvt_warn ("perl hook %d evaluation error: %s", htype, SvPV_nolen (ERRSV)); 605 rxvt_warn ("perl hook %d evaluation error: %s", htype, SvPV_nolen (ERRSV));
606 ungrab (term); // better lose the grab than the session
607 }
482 608
483 if (htype == HOOK_DESTROY) 609 if (htype == HOOK_DESTROY)
484 { 610 {
485 clearSVptr ((SV *)term->self); 611 clearSVptr ((SV *)term->perl.self);
486 SvREFCNT_dec ((SV *)term->self); 612 SvREFCNT_dec ((SV *)term->perl.self);
487 } 613 }
488 614
489 return count; 615 return count;
490 } 616 }
491 617
501 627
502PROTOTYPES: ENABLE 628PROTOTYPES: ENABLE
503 629
504BOOT: 630BOOT:
505{ 631{
506# define export_const(name) newCONSTSUB (gv_stashpv ("urxvt", 1), # name, newSViv (name)); 632 sv_setsv (get_sv ("urxvt::LIBDIR", 1), newSVpvn (LIBDIR, sizeof (LIBDIR) - 1));
633 sv_setsv (get_sv ("urxvt::RESNAME", 1), newSVpvn (RESNAME, sizeof (RESNAME) - 1));
634 sv_setsv (get_sv ("urxvt::RESCLASS", 1), newSVpvn (RESCLASS, sizeof (RESCLASS) - 1));
635 sv_setsv (get_sv ("urxvt::RXVTNAME", 1), newSVpvn (RXVTNAME, sizeof (RXVTNAME) - 1));
636
507 AV *hookname = get_av ("urxvt::HOOKNAME", 1); 637 AV *hookname = get_av ("urxvt::HOOKNAME", 1);
508# define def(sym) av_store (hookname, HOOK_ ## sym, newSVpv (# sym, 0)); 638# define def(sym) av_store (hookname, HOOK_ ## sym, newSVpv (# sym, 0));
509# include "hookinc.h" 639# include "hookinc.h"
510# undef def 640# undef def
511 641
642 HV *option = get_hv ("urxvt::OPTION", 1);
643# define def(name,val) hv_store (option, # name, sizeof (# name) - 1, newSVuv (Opt_ ## name), 0);
644# define nodef(name)
645# include "optinc.h"
646# undef nodef
647# undef def
648
649 HV *stash = gv_stashpv ("urxvt", 1);
650# define export_const_iv(name) newCONSTSUB (stash, # name, newSViv (name));
512 export_const (DEFAULT_RSTYLE); 651 export_const_iv (DEFAULT_RSTYLE);
513 export_const (OVERLAY_RSTYLE); 652 export_const_iv (OVERLAY_RSTYLE);
514 export_const (RS_Bold); 653 export_const_iv (RS_Bold);
515 export_const (RS_Italic); 654 export_const_iv (RS_Italic);
516 export_const (RS_Blink); 655 export_const_iv (RS_Blink);
517 export_const (RS_RVid); 656 export_const_iv (RS_RVid);
518 export_const (RS_Uline); 657 export_const_iv (RS_Uline);
519 658
520 sv_setpv (get_sv ("urxvt::LIBDIR", 1), LIBDIR); 659 export_const_iv (CurrentTime);
660 export_const_iv (ShiftMask);
661 export_const_iv (LockMask);
662 export_const_iv (ControlMask);
663 export_const_iv (Mod1Mask);
664 export_const_iv (Mod2Mask);
665 export_const_iv (Mod3Mask);
666 export_const_iv (Mod4Mask);
667 export_const_iv (Mod5Mask);
668 export_const_iv (Button1Mask);
669 export_const_iv (Button2Mask);
670 export_const_iv (Button3Mask);
671 export_const_iv (Button4Mask);
672 export_const_iv (Button5Mask);
673 export_const_iv (AnyModifier);
674
675 export_const_iv (EVENT_NONE);
676 export_const_iv (EVENT_READ);
677 export_const_iv (EVENT_WRITE);
521} 678}
679
680SV *
681new (...)
682 CODE:
683{
684 stringvec *argv = new stringvec;
685 bool success;
686
687 for (int i = 0; i < items ;i++)
688 argv->push_back (strdup (SvPVbyte_nolen (ST (i))));
689
690 rxvt_term *term = new rxvt_term;
691
692 term->argv = argv;
693
694 try
695 {
696 if (!term->init (argv->size (), argv->begin ()))
697 term = 0;
698 }
699 catch (const class rxvt_failure_exception &e)
700 {
701 term->destroy ();
702 croak ("exception caught while initializing new terminal instance");
703 }
704
705 RETVAL = term && term->perl.self ? newSVterm (term) : &PL_sv_undef;
706}
707 OUTPUT:
708 RETVAL
522 709
523void 710void
524set_should_invoke (int htype, int value) 711set_should_invoke (int htype, int value)
525 CODE: 712 CODE:
526 rxvt_perl.should_invoke [htype] = value; 713 rxvt_perl.should_invoke [htype] = value;
532 719
533void 720void
534fatal (const char *msg) 721fatal (const char *msg)
535 CODE: 722 CODE:
536 rxvt_fatal ("%s", msg); 723 rxvt_fatal ("%s", msg);
724
725SV *
726untaint (SV *sv)
727 CODE:
728 RETVAL = newSVsv (sv);
729 SvTAINTED_off (RETVAL);
730 OUTPUT:
731 RETVAL
732
733bool
734safe ()
735 CODE:
736 RETVAL = !rxvt_tainted ();
737 OUTPUT:
738 RETVAL
537 739
538NV 740NV
539NOW () 741NOW ()
540 CODE: 742 CODE:
541 RETVAL = NOW; 743 RETVAL = NOW;
589} 791}
590 OUTPUT: 792 OUTPUT:
591 RETVAL 793 RETVAL
592 794
593MODULE = urxvt PACKAGE = urxvt::term 795MODULE = urxvt PACKAGE = urxvt::term
796
797void
798rxvt_term::destroy ()
799
800void
801rxvt_term::grab_button (int button, U32 modifiers)
802 CODE:
803 XGrabButton (THIS->display->display, button, modifiers, THIS->vt, 1,
804 ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask,
805 GrabModeSync, GrabModeSync, None, GRAB_CURSOR);
806
807bool
808rxvt_term::grab (U32 eventtime, int sync = 0)
809 CODE:
810{
811 int mode = sync ? GrabModeSync : GrabModeAsync;
812
813 THIS->perl.grabtime = 0;
814
815 if (!XGrabPointer (THIS->display->display, THIS->vt, 0,
816 ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask,
817 mode, mode, None, GRAB_CURSOR, eventtime))
818 if (!XGrabKeyboard (THIS->display->display, THIS->vt, 0, mode, mode, eventtime))
819 THIS->perl.grabtime = eventtime;
820 else
821 XUngrabPointer (THIS->display->display, eventtime);
822
823 RETVAL = !!THIS->perl.grabtime;
824}
825 OUTPUT:
826 RETVAL
827
828void
829rxvt_term::allow_events_async ()
830 CODE:
831 XAllowEvents (THIS->display->display, AsyncBoth, THIS->perl.grabtime);
832
833void
834rxvt_term::allow_events_sync ()
835 CODE:
836 XAllowEvents (THIS->display->display, SyncBoth, THIS->perl.grabtime);
837
838void
839rxvt_term::allow_events_replay ()
840 CODE:
841 XAllowEvents (THIS->display->display, ReplayPointer, THIS->perl.grabtime);
842 XAllowEvents (THIS->display->display, ReplayKeyboard, THIS->perl.grabtime);
843
844void
845rxvt_term::ungrab ()
846 CODE:
847 ungrab (THIS);
594 848
595int 849int
596rxvt_term::strwidth (SV *str) 850rxvt_term::strwidth (SV *str)
597 CODE: 851 CODE:
598{ 852{
617 char *mbstr = rxvt_wcstombs (wstr); 871 char *mbstr = rxvt_wcstombs (wstr);
618 rxvt_pop_locale (); 872 rxvt_pop_locale ();
619 873
620 free (wstr); 874 free (wstr);
621 875
622 RETVAL = newSVpv (mbstr, 0); 876 RETVAL = taint_if (newSVpv (mbstr, 0), str);
623 free (mbstr); 877 free (mbstr);
624} 878}
625 OUTPUT: 879 OUTPUT:
626 RETVAL 880 RETVAL
627 881
634 888
635 rxvt_push_locale (THIS->locale); 889 rxvt_push_locale (THIS->locale);
636 wchar_t *wstr = rxvt_mbstowcs (data, len); 890 wchar_t *wstr = rxvt_mbstowcs (data, len);
637 rxvt_pop_locale (); 891 rxvt_pop_locale ();
638 892
639 char *str = rxvt_wcstoutf8 (wstr); 893 RETVAL = taint_if (wcs2sv (wstr), octets);
640 free (wstr); 894 free (wstr);
641
642 RETVAL = newSVpv (str, 0);
643 SvUTF8_on (RETVAL);
644 free (str);
645} 895}
646 OUTPUT: 896 OUTPUT:
647 RETVAL 897 RETVAL
648 898
649# very portable, especially on objects as opposed to pods 899#define TERM_OFFSET(sym) offsetof (TermWin_t, sym)
650#define TERM_OFFSET(sym) (((char *)&((TermWin_t *)0)->sym) - (char *)(TermWin_t *)0)
651 900
652#define TERM_OFFSET_width TERM_OFFSET(width) 901#define TERM_OFFSET_width TERM_OFFSET(width)
653#define TERM_OFFSET_height TERM_OFFSET(height) 902#define TERM_OFFSET_height TERM_OFFSET(height)
654#define TERM_OFFSET_fwidth TERM_OFFSET(fwidth) 903#define TERM_OFFSET_fwidth TERM_OFFSET(fwidth)
655#define TERM_OFFSET_fheight TERM_OFFSET(fheight) 904#define TERM_OFFSET_fheight TERM_OFFSET(fheight)
680 CODE: 929 CODE:
681 RETVAL = *(int *)((char *)THIS + ix); 930 RETVAL = *(int *)((char *)THIS + ix);
682 OUTPUT: 931 OUTPUT:
683 RETVAL 932 RETVAL
684 933
934unsigned int
935rxvt_term::ModLevel3Mask ()
936 ALIAS:
937 ModLevel3Mask = 0
938 ModMetaMask = 1
939 ModNumLockMask = 2
940 CODE:
941 switch (ix)
942 {
943 case 0: RETVAL = THIS->ModLevel3Mask; break;
944 case 1: RETVAL = THIS->ModMetaMask; break;
945 case 2: RETVAL = THIS->ModNumLockMask; break;
946 }
947 OUTPUT:
948 RETVAL
949
950char *
951rxvt_term::display_id ()
952 ALIAS:
953 display_id = 0
954 locale = 1
955 CODE:
956 switch (ix)
957 {
958 case 0: RETVAL = THIS->display->id; break;
959 case 1: RETVAL = THIS->locale; break;
960 }
961 OUTPUT:
962 RETVAL
963
964int
965rxvt_term::pty_ev_events (int events = EVENT_UNDEF)
966 CODE:
967 RETVAL = THIS->pty_ev.events;
968 if (events != EVENT_UNDEF)
969 THIS->pty_ev.set (events);
970 OUTPUT:
971 RETVAL
972
685U32 973U32
974rxvt_term::parent ()
975 CODE:
976 RETVAL = (U32)THIS->parent [0];
977 OUTPUT:
978 RETVAL
979
980U32
981rxvt_term::vt ()
982 CODE:
983 RETVAL = (U32)THIS->vt;
984 OUTPUT:
985 RETVAL
986
987U32
686rxvt_term::screen_rstyle (U32 new_rstyle = THIS->screen.s_rstyle) 988rxvt_term::rstyle (U32 new_rstyle = THIS->rstyle)
687 CODE: 989 CODE:
688{ 990{
689 RETVAL = THIS->screen.s_rstyle; 991 RETVAL = THIS->rstyle;
690 THIS->screen.s_rstyle = new_rstyle; 992 THIS->rstyle = new_rstyle;
691} 993}
692 OUTPUT: 994 OUTPUT:
693 RETVAL 995 RETVAL
694 996
695int 997int
711rxvt_term::want_refresh () 1013rxvt_term::want_refresh ()
712 CODE: 1014 CODE:
713 THIS->want_refresh = 1; 1015 THIS->want_refresh = 1;
714 1016
715void 1017void
716rxvt_term::ROW_t (int row_number, SV *new_text = 0, int start_col = 0) 1018rxvt_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: 1019 PPCODE:
718{ 1020{
719 if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) 1021 if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow))
720 XSRETURN_EMPTY; 1022 XSRETURN_EMPTY;
721 1023
723 1025
724 if (GIMME_V != G_VOID) 1026 if (GIMME_V != G_VOID)
725 { 1027 {
726 wchar_t *wstr = new wchar_t [THIS->ncol]; 1028 wchar_t *wstr = new wchar_t [THIS->ncol];
727 1029
728 for (int col = 0; col <THIS->ncol; col++) 1030 for (int col = 0; col < THIS->ncol; col++)
729 wstr [col] = l.t [col]; 1031 wstr [col] = l.t [col];
730 1032
731 char *str = rxvt_wcstoutf8 (wstr, THIS->ncol); 1033 XPUSHs (taint (sv_2mortal (wcs2sv (wstr, THIS->ncol))));
732 free (wstr);
733 1034
734 SV *sv = newSVpv (str, 0); 1035 delete [] wstr;
735 SvUTF8_on (sv);
736 XPUSHs (sv_2mortal (sv));
737 free (str);
738 } 1036 }
739 1037
740 if (new_text) 1038 if (new_text)
741 { 1039 {
742 wchar_t *wstr = sv2wcs (new_text); 1040 wchar_t *wstr = sv2wcs (new_text);
743 1041
744 int len = wcslen (wstr); 1042 int len = min (wcslen (wstr) - start_ofs, max_len);
745 1043
746 if (!IN_RANGE_INC (start_col, 0, THIS->ncol - len)) 1044 if (!IN_RANGE_INC (start_col, 0, THIS->ncol - len))
747 { 1045 {
748 free (wstr); 1046 free (wstr);
749 croak ("new_text extends beyond horizontal margins"); 1047 croak ("new_text extends beyond horizontal margins");
750 } 1048 }
751 1049
752 for (int col = start_col; col < start_col + len; col++) 1050 for (int col = start_col; col < start_col + len; col++)
753 { 1051 {
754 l.t [col] = wstr [col - start_col]; 1052 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])); 1053 l.r [col] = SET_FONT (l.r [col], THIS->fontset [GET_STYLE (l.r [col])]->find_font (l.t [col]));
756 } 1054 }
757 1055
758 free (wstr); 1056 free (wstr);
759 } 1057 }
760} 1058}
761 1059
762void 1060void
763rxvt_term::ROW_r (int row_number, SV *new_rend = 0, int start_col = 0) 1061rxvt_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: 1062 PPCODE:
765{ 1063{
766 if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) 1064 if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow))
767 XSRETURN_EMPTY; 1065 XSRETURN_EMPTY;
768 1066
783 { 1081 {
784 if (!SvROK (new_rend) || SvTYPE (SvRV (new_rend)) != SVt_PVAV) 1082 if (!SvROK (new_rend) || SvTYPE (SvRV (new_rend)) != SVt_PVAV)
785 croak ("new_rend must be arrayref"); 1083 croak ("new_rend must be arrayref");
786 1084
787 AV *av = (AV *)SvRV (new_rend); 1085 AV *av = (AV *)SvRV (new_rend);
788 int len = av_len (av) + 1; 1086 int len = min (av_len (av) + 1 - start_ofs, max_len);
789 1087
790 if (!IN_RANGE_INC (start_col, 0, THIS->ncol - len)) 1088 if (!IN_RANGE_INC (start_col, 0, THIS->ncol - len))
791 croak ("new_rend array extends beyond horizontal margins"); 1089 croak ("new_rend array extends beyond horizontal margins");
792 1090
793 for (int col = start_col; col < start_col + len; col++) 1091 for (int col = start_col; col < start_col + len; col++)
794 { 1092 {
795 rend_t r = SvIV (*av_fetch (av, col - start_col, 1)) & ~RS_fontMask; 1093 rend_t r = SvIV (*av_fetch (av, start_ofs + col - start_col, 1)) & ~RS_fontMask;
796 1094
797 l.r [col] = SET_FONT (r, THIS->fontset [GET_STYLE (r)]->find_font (l.t [col])); 1095 l.r [col] = SET_FONT (r, THIS->fontset [GET_STYLE (r)]->find_font (l.t [col]));
798 } 1096 }
799 } 1097 }
800} 1098}
801 1099
802int 1100int
803rxvt_term::ROW_l (int row_number, int new_length = -2) 1101rxvt_term::ROW_l (int row_number, int new_length = -1)
804 CODE: 1102 CODE:
805{ 1103{
806 if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) 1104 if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow))
807 XSRETURN_EMPTY; 1105 XSRETURN_EMPTY;
808 1106
809 line_t &l = ROW(row_number); 1107 line_t &l = ROW(row_number);
810 RETVAL = l.l < 0 ? THIS->ncol : l.l; 1108 RETVAL = l.l;
811 1109
812 if (new_length >= -1) 1110 if (new_length >= 0)
813 l.l = new_length; 1111 l.l = new_length;
814} 1112}
815 OUTPUT: 1113 OUTPUT:
816 RETVAL 1114 RETVAL
817 1115
818bool 1116bool
819rxvt_term::ROW_is_longer (int row_number) 1117rxvt_term::ROW_is_longer (int row_number, int new_is_longer = -1)
820 CODE: 1118 CODE:
821{ 1119{
822 if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) 1120 if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow))
823 XSRETURN_EMPTY; 1121 XSRETURN_EMPTY;
824 1122
825 line_t &l = ROW(row_number); 1123 line_t &l = ROW(row_number);
826 RETVAL = l.l < 0; 1124 RETVAL = l.is_longer ();
1125
1126 if (new_is_longer >= 0)
1127 l.is_longer (new_is_longer);
827} 1128}
828 OUTPUT: 1129 OUTPUT:
829 RETVAL 1130 RETVAL
830 1131
831SV * 1132SV *
832rxvt_term::special_encode (SV *str) 1133rxvt_term::special_encode (SV *string)
833 CODE: 1134 CODE:
834 abort ();//TODO 1135{
1136 wchar_t *wstr = sv2wcs (string);
1137 int wlen = wcslen (wstr);
1138 wchar_t *rstr = new wchar_t [wlen]; // cannot become longer
1139
1140 rxvt_push_locale (THIS->locale);
1141
1142 wchar_t *r = rstr;
1143 for (wchar_t *s = wstr; *s; s++)
1144 if (wcwidth (*s) == 0)
1145 {
1146 if (r == rstr)
1147 croak ("leading combining character unencodable");
1148
1149 unicode_t n = rxvt_compose (r[-1], *s);
1150 if (n == NOCHAR)
1151 n = rxvt_composite.compose (r[-1], *s);
1152
1153 r[-1] = n;
1154 }
1155#if !UNICODE_3
1156 else if (*s >= 0x10000)
1157 *r++ = rxvt_composite.compose (*s);
1158#endif
1159 else
1160 *r++ = *s;
1161
1162 rxvt_pop_locale ();
1163
1164 RETVAL = taint_if (wcs2sv (rstr, r - rstr), string);
1165
1166 delete [] rstr;
1167}
1168 OUTPUT:
1169 RETVAL
835 1170
836SV * 1171SV *
837rxvt_term::special_decode (SV *str) 1172rxvt_term::special_decode (SV *text)
838 CODE: 1173 CODE:
839 abort ();//TODO 1174{
1175 wchar_t *wstr = sv2wcs (text);
1176 int wlen = wcslen (wstr);
1177 int dlen = 0;
1178
1179 // find length
1180 for (wchar_t *s = wstr; *s; s++)
1181 if (*s == NOCHAR)
1182 ;
1183 else if (IS_COMPOSE (*s))
1184 dlen += rxvt_composite.expand (*s, 0);
1185 else
1186 dlen++;
1187
1188 wchar_t *rstr = new wchar_t [dlen];
1189
1190 // decode
1191 wchar_t *r = rstr;
1192 for (wchar_t *s = wstr; *s; s++)
1193 if (*s == NOCHAR)
1194 ;
1195 else if (IS_COMPOSE (*s))
1196 r += rxvt_composite.expand (*s, r);
1197 else
1198 *r++ = *s;
1199
1200 RETVAL = taint_if (wcs2sv (rstr, r - rstr), text);
1201
1202 delete [] rstr;
1203}
1204 OUTPUT:
1205 RETVAL
840 1206
841void 1207void
842rxvt_term::_resource (char *name, int index, SV *newval = 0) 1208rxvt_term::_resource (char *name, int index, SV *newval = 0)
843 PPCODE: 1209 PPCODE:
844{ 1210{
861 1227
862 if (!IN_RANGE_EXC (index, 0, NUM_RESOURCES)) 1228 if (!IN_RANGE_EXC (index, 0, NUM_RESOURCES))
863 croak ("requested out-of-bound resource %s+%d,", name, index - rs->value); 1229 croak ("requested out-of-bound resource %s+%d,", name, index - rs->value);
864 1230
865 if (GIMME_V != G_VOID) 1231 if (GIMME_V != G_VOID)
866 XPUSHs (THIS->rs [index] ? sv_2mortal (newSVpv (THIS->rs [index], 0)) : &PL_sv_undef); 1232 XPUSHs (THIS->rs [index] ? sv_2mortal (taint (newSVpv (THIS->rs [index], 0))) : &PL_sv_undef);
867 1233
868 if (newval) 1234 if (newval)
869 { 1235 {
870 if (SvOK (newval)) 1236 if (SvOK (newval))
871 { 1237 {
876 else 1242 else
877 THIS->rs [index] = 0; 1243 THIS->rs [index] = 0;
878 } 1244 }
879} 1245}
880 1246
1247bool
1248rxvt_term::option (U32 optval, int set = -1)
1249 CODE:
1250{
1251 RETVAL = THIS->options & optval;
1252
1253 if (set >= 0)
1254 {
1255 if (set)
1256 THIS->options |= optval;
1257 else
1258 THIS->options &= ~optval;
1259
1260 switch (optval)
1261 {
1262 case Opt_skipBuiltinGlyphs:
1263 THIS->set_fonts ();
1264 THIS->scr_remap_chars ();
1265 THIS->scr_touch (true);
1266 THIS->want_refresh = 1;
1267 break;
1268
1269 case Opt_cursorUnderline:
1270 THIS->want_refresh = 1;
1271 break;
1272
1273# case Opt_scrollBar_floating:
1274# case Opt_scrollBar_right:
1275# THIS->resize_all_windows (THIS->width, THIS->height, 1);
1276# break;
1277 }
1278 }
1279}
1280 OUTPUT:
1281 RETVAL
1282
1283bool
1284rxvt_term::parse_keysym (char *keysym, char *str)
1285 CODE:
1286 RETVAL = 0 < THIS->parse_keysym (keysym, str);
1287 THIS->keyboard->register_done ();
1288 OUTPUT:
1289 RETVAL
1290
881void 1291void
882rxvt_term::cur (...) 1292rxvt_term::screen_cur (...)
883 PROTOTYPE: $;$$ 1293 PROTOTYPE: $;$$
884 ALIAS: 1294 ALIAS:
885 screen_cur = 0 1295 screen_cur = 0
886 selection_beg = 1 1296 selection_beg = 1
887 selection_end = 2 1297 selection_end = 2
909 THIS->want_refresh = 1; 1319 THIS->want_refresh = 1;
910 } 1320 }
911} 1321}
912 1322
913int 1323int
914rxvt_term::selection_grab (int eventtime = CurrentTime) 1324rxvt_term::selection_grab (U32 eventtime)
915 1325
916void 1326void
917rxvt_term::selection (SV *newtext = 0) 1327rxvt_term::selection (SV *newtext = 0)
918 PPCODE: 1328 PPCODE:
919{ 1329{
920 if (GIMME_V != G_VOID) 1330 if (GIMME_V != G_VOID)
921 { 1331 XPUSHs (THIS->selection.text
922 char *sel = rxvt_wcstoutf8 (THIS->selection.text, THIS->selection.len); 1332 ? taint (sv_2mortal (wcs2sv (THIS->selection.text, THIS->selection.len)))
923 SV *sv = newSVpv (sel, 0); 1333 : &PL_sv_undef);
924 SvUTF8_on (sv);
925 free (sel);
926 XPUSHs (sv_2mortal (sv));
927 }
928 1334
929 if (newtext) 1335 if (newtext)
930 { 1336 {
931 free (THIS->selection.text); 1337 free (THIS->selection.text);
932 1338
933 THIS->selection.text = sv2wcs (newtext); 1339 THIS->selection.text = sv2wcs (newtext);
934 THIS->selection.len = wcslen (THIS->selection.text); 1340 THIS->selection.len = wcslen (THIS->selection.text);
935 } 1341 }
1342}
1343
1344void
1345rxvt_term::scr_xor_rect (int beg_row, int beg_col, int end_row, int end_col, U32 rstyle1 = RS_RVid, U32 rstyle2 = RS_RVid | RS_Uline)
1346
1347void
1348rxvt_term::scr_xor_span (int beg_row, int beg_col, int end_row, int end_col, U32 rstyle = RS_RVid)
1349
1350void
1351rxvt_term::scr_bell ()
1352
1353void
1354rxvt_term::scr_add_lines (SV *string)
1355 CODE:
1356{
1357 wchar_t *wstr = sv2wcs (string);
1358 THIS->scr_add_lines (wstr, wcslen (wstr));
1359 free (wstr);
936} 1360}
937 1361
938void 1362void
939rxvt_term::tt_write (SV *octets) 1363rxvt_term::tt_write (SV *octets)
940 INIT: 1364 INIT:
941 STRLEN len; 1365 STRLEN len;
942 char *str = SvPVbyte (octets, len); 1366 char *str = SvPVbyte (octets, len);
943 C_ARGS: 1367 C_ARGS:
944 str, len 1368 str, len
945 1369
1370void
1371rxvt_term::cmd_parse (SV *octets)
1372 CODE:
1373{
1374 STRLEN len;
1375 char *str = SvPVbyte (octets, len);
1376
1377 char *old_cmdbuf_ptr = THIS->cmdbuf_ptr;
1378 char *old_cmdbuf_endp = THIS->cmdbuf_endp;
1379
1380 THIS->cmdbuf_ptr = str;
1381 THIS->cmdbuf_endp = str + len;
1382
1383 rxvt_push_locale (THIS->locale);
1384 THIS->cmd_parse ();
1385 rxvt_pop_locale ();
1386
1387 THIS->cmdbuf_ptr = old_cmdbuf_ptr;
1388 THIS->cmdbuf_endp = old_cmdbuf_endp;
1389}
1390
946SV * 1391SV *
947rxvt_term::overlay (int x, int y, int w, int h, int rstyle = OVERLAY_RSTYLE, int border = 2) 1392rxvt_term::overlay (int x, int y, int w, int h, int rstyle = OVERLAY_RSTYLE, int border = 2)
948 CODE: 1393 CODE:
949{ 1394{
950 overlay *o = new overlay (THIS, x, y, w, h, rstyle, border); 1395 overlay *o = new overlay (THIS, x, y, w, h, rstyle, border);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines