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.44 by root, Sun Jan 8 22:58:13 2006 UTC vs.
Revision 1.54 by root, Wed Jan 11 00:59:58 2006 UTC

29#include "../config.h" 29#include "../config.h"
30 30
31#include <cstddef> 31#include <cstddef>
32#include <cstdarg> 32#include <cstdarg>
33 33
34#include "iom.h"
34#include "rxvt.h" 35#include "rxvt.h"
35#include "iom.h" 36#include "keyboard.h"
36#include "rxvtutil.h" 37#include "rxvtutil.h"
37#include "rxvtperl.h" 38#include "rxvtperl.h"
38 39
39#include "perlxsi.c" 40#include "perlxsi.c"
40 41
428 429
429 perl_destruct (perl); 430 perl_destruct (perl);
430 perl_free (perl); 431 perl_free (perl);
431 perl = 0; 432 perl = 0;
432 } 433 }
434 }
435}
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;
433 } 445 }
434} 446}
435 447
436bool 448bool
437rxvt_perl_interp::invoke (rxvt_term *term, hook_type htype, ...) 449rxvt_perl_interp::invoke (rxvt_term *term, hook_type htype, ...)
448 return false; // perl not initialized for this instance 460 return false; // perl not initialized for this instance
449 else if (htype == HOOK_DESTROY) 461 else if (htype == HOOK_DESTROY)
450 { 462 {
451 // handled later 463 // handled later
452 } 464 }
453 else if (htype == HOOK_REFRESH_BEGIN || htype == HOOK_REFRESH_END) 465 else
454 { 466 {
455 HV *hv = (HV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, 0)); 467 if (htype == HOOK_REFRESH_BEGIN || htype == HOOK_REFRESH_END)
456
457 if (HvKEYS (hv))
458 { 468 {
469 HV *hv = (HV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, 0));
470
471 if (HvKEYS (hv))
472 {
459 hv_iterinit (hv); 473 hv_iterinit (hv);
460 474
461 while (HE *he = hv_iternext (hv)) 475 while (HE *he = hv_iternext (hv))
462 ((overlay *)SvIV (hv_iterval (hv, he)))->swap (); 476 ((overlay *)SvIV (hv_iterval (hv, he)))->swap ();
477 }
478
463 } 479 }
480
481 if (!should_invoke [htype])
482 return false;
464 } 483 }
465 else if (!should_invoke [htype])
466 return false;
467 484
468 dSP; 485 dSP;
469 va_list ap; 486 va_list ap;
470 487
471 va_start (ap, htype); 488 va_start (ap, htype);
582 PUTBACK; 599 PUTBACK;
583 FREETMPS; 600 FREETMPS;
584 LEAVE; 601 LEAVE;
585 602
586 if (SvTRUE (ERRSV)) 603 if (SvTRUE (ERRSV))
604 {
587 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 }
588 608
589 if (htype == HOOK_DESTROY) 609 if (htype == HOOK_DESTROY)
590 { 610 {
591 clearSVptr ((SV *)term->perl.self); 611 clearSVptr ((SV *)term->perl.self);
592 SvREFCNT_dec ((SV *)term->perl.self); 612 SvREFCNT_dec ((SV *)term->perl.self);
607 627
608PROTOTYPES: ENABLE 628PROTOTYPES: ENABLE
609 629
610BOOT: 630BOOT:
611{ 631{
612 sv_setsv (get_sv ("urxvt::LIBDIR", 1), newSVpvn (LIBDIR, sizeof (LIBDIR) - 1)); 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));
613 636
614 AV *hookname = get_av ("urxvt::HOOKNAME", 1); 637 AV *hookname = get_av ("urxvt::HOOKNAME", 1);
615# define def(sym) av_store (hookname, HOOK_ ## sym, newSVpv (# sym, 0)); 638# define def(sym) av_store (hookname, HOOK_ ## sym, newSVpv (# sym, 0));
616# include "hookinc.h" 639# include "hookinc.h"
617# undef def 640# undef def
646 export_const_iv (Button2Mask); 669 export_const_iv (Button2Mask);
647 export_const_iv (Button3Mask); 670 export_const_iv (Button3Mask);
648 export_const_iv (Button4Mask); 671 export_const_iv (Button4Mask);
649 export_const_iv (Button5Mask); 672 export_const_iv (Button5Mask);
650 export_const_iv (AnyModifier); 673 export_const_iv (AnyModifier);
674
675 export_const_iv (EVENT_NONE);
676 export_const_iv (EVENT_READ);
677 export_const_iv (EVENT_WRITE);
651} 678}
679
680void
681set_should_invoke (int htype, int value)
682 CODE:
683 rxvt_perl.should_invoke [htype] = value;
684
685void
686warn (const char *msg)
687 CODE:
688 rxvt_warn ("%s", msg);
689
690void
691fatal (const char *msg)
692 CODE:
693 rxvt_fatal ("%s", msg);
652 694
653SV * 695SV *
654new (...) 696untaint (SV *sv)
655 CODE: 697 CODE:
656{ 698 RETVAL = newSVsv (sv);
657 stringvec *argv = new stringvec; 699 SvTAINTED_off (RETVAL);
658 bool success; 700 OUTPUT:
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 701 RETVAL
682 702
683void 703bool
684set_should_invoke (int htype, int value) 704safe ()
685 CODE: 705 CODE:
686 rxvt_perl.should_invoke [htype] = value; 706 RETVAL = !rxvt_tainted ();
687 707 OUTPUT:
688void 708 RETVAL
689warn (const char *msg)
690 CODE:
691 rxvt_warn ("%s", msg);
692
693void
694fatal (const char *msg)
695 CODE:
696 rxvt_fatal ("%s", msg);
697 709
698NV 710NV
699NOW () 711NOW ()
700 CODE: 712 CODE:
701 RETVAL = NOW; 713 RETVAL = NOW;
749} 761}
750 OUTPUT: 762 OUTPUT:
751 RETVAL 763 RETVAL
752 764
753MODULE = urxvt PACKAGE = urxvt::term 765MODULE = urxvt PACKAGE = urxvt::term
766
767SV *
768_new (...)
769 CODE:
770{
771 if (items < 1 || !SvROK (ST (0)) || SvTYPE (SvRV (ST (0))) != SVt_PVAV)
772 croak ("first argument to urxvt::term->_new must be arrayref");
773
774 rxvt_term *term = new rxvt_term;
775
776 term->argv = new stringvec;
777 term->envv = new stringvec;
778
779 for (int i = 1; i < items; i++)
780 term->argv->push_back (strdup (SvPVbyte_nolen (ST (i))));
781
782 AV *envv = (AV *)SvRV (ST (0));
783 for (int i = av_len (envv) + 1; i--; )
784 term->envv->push_back (strdup (SvPVbyte_nolen (*av_fetch (envv, i, 1))));
785
786 term->envv->push_back (0);
787
788 bool success;
789
790 try
791 {
792 success = term->init (term->argv->size (), term->argv->begin ());
793 }
794 catch (const class rxvt_failure_exception &e)
795 {
796 success = false;
797 }
798
799 if (!success)
800 {
801 term->destroy ();
802 croak ("error while initializing new terminal instance");
803 }
804
805 RETVAL = term && term->perl.self
806 ? newSVterm (term) : &PL_sv_undef;
807}
808 OUTPUT:
809 RETVAL
754 810
755void 811void
756rxvt_term::destroy () 812rxvt_term::destroy ()
757 813
758void 814void
800 XAllowEvents (THIS->display->display, ReplayKeyboard, THIS->perl.grabtime); 856 XAllowEvents (THIS->display->display, ReplayKeyboard, THIS->perl.grabtime);
801 857
802void 858void
803rxvt_term::ungrab () 859rxvt_term::ungrab ()
804 CODE: 860 CODE:
805{ 861 ungrab (THIS);
806 if (THIS->perl.grabtime)
807 {
808 XUngrabKeyboard (THIS->display->display, THIS->perl.grabtime);
809 XUngrabPointer (THIS->display->display, THIS->perl.grabtime);
810 THIS->perl.grabtime = 0;
811 }
812}
813 862
814int 863int
815rxvt_term::strwidth (SV *str) 864rxvt_term::strwidth (SV *str)
816 CODE: 865 CODE:
817{ 866{
910 case 2: RETVAL = THIS->ModNumLockMask; break; 959 case 2: RETVAL = THIS->ModNumLockMask; break;
911 } 960 }
912 OUTPUT: 961 OUTPUT:
913 RETVAL 962 RETVAL
914 963
964char *
965rxvt_term::display_id ()
966 ALIAS:
967 display_id = 0
968 locale = 1
969 CODE:
970 switch (ix)
971 {
972 case 0: RETVAL = THIS->display->id; break;
973 case 1: RETVAL = THIS->locale; break;
974 }
975 OUTPUT:
976 RETVAL
977
978SV *
979rxvt_term::_env ()
980 CODE:
981{
982 if (THIS->envv)
983 {
984 AV *av = newAV ();
985
986 for (char **i = THIS->envv->begin (); i != THIS->envv->end (); ++i)
987 if (*i)
988 av_push (av, newSVpv (*i, 0));
989
990 RETVAL = newRV_noinc ((SV *)av);
991 }
992 else
993 RETVAL = &PL_sv_undef;
994}
995 OUTPUT:
996 RETVAL
997
998int
999rxvt_term::pty_ev_events (int events = EVENT_UNDEF)
1000 CODE:
1001 RETVAL = THIS->pty_ev.events;
1002 if (events != EVENT_UNDEF)
1003 THIS->pty_ev.set (events);
1004 OUTPUT:
1005 RETVAL
1006
915U32 1007U32
916rxvt_term::parent () 1008rxvt_term::parent ()
917 CODE: 1009 CODE:
918 RETVAL = (U32)THIS->parent [0]; 1010 RETVAL = (U32)THIS->parent [0];
919 OUTPUT: 1011 OUTPUT:
1220 } 1312 }
1221} 1313}
1222 OUTPUT: 1314 OUTPUT:
1223 RETVAL 1315 RETVAL
1224 1316
1317bool
1318rxvt_term::parse_keysym (char *keysym, char *str)
1319 CODE:
1320 RETVAL = 0 < THIS->parse_keysym (keysym, str);
1321 THIS->keyboard->register_done ();
1322 OUTPUT:
1323 RETVAL
1324
1225void 1325void
1226rxvt_term::cur (...) 1326rxvt_term::screen_cur (...)
1227 PROTOTYPE: $;$$ 1327 PROTOTYPE: $;$$
1228 ALIAS: 1328 ALIAS:
1229 screen_cur = 0 1329 screen_cur = 0
1230 selection_beg = 1 1330 selection_beg = 1
1231 selection_end = 2 1331 selection_end = 2
1252 if (ix) 1352 if (ix)
1253 THIS->want_refresh = 1; 1353 THIS->want_refresh = 1;
1254 } 1354 }
1255} 1355}
1256 1356
1357char
1358rxvt_term::cur_charset ()
1359 CODE:
1360 RETVAL = THIS->charsets [THIS->screen.charset];
1361 OUTPUT:
1362 RETVAL
1363
1257int 1364int
1258rxvt_term::selection_grab (U32 eventtime) 1365rxvt_term::selection_grab (U32 eventtime)
1259 1366
1260void 1367void
1261rxvt_term::selection (SV *newtext = 0) 1368rxvt_term::selection (SV *newtext = 0)
1262 PPCODE: 1369 PPCODE:
1263{ 1370{
1264 if (GIMME_V != G_VOID) 1371 if (GIMME_V != G_VOID)
1372 XPUSHs (THIS->selection.text
1265 XPUSHs (taint (sv_2mortal (wcs2sv (THIS->selection.text, THIS->selection.len)))); 1373 ? taint (sv_2mortal (wcs2sv (THIS->selection.text, THIS->selection.len)))
1374 : &PL_sv_undef);
1266 1375
1267 if (newtext) 1376 if (newtext)
1268 { 1377 {
1269 free (THIS->selection.text); 1378 free (THIS->selection.text);
1270 1379
1271 THIS->selection.text = sv2wcs (newtext); 1380 THIS->selection.text = sv2wcs (newtext);
1272 THIS->selection.len = wcslen (THIS->selection.text); 1381 THIS->selection.len = wcslen (THIS->selection.text);
1273 } 1382 }
1274} 1383}
1384
1385void
1386rxvt_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)
1387
1388void
1389rxvt_term::scr_xor_span (int beg_row, int beg_col, int end_row, int end_col, U32 rstyle = RS_RVid)
1390
1391void
1392rxvt_term::scr_bell ()
1275 1393
1276void 1394void
1277rxvt_term::scr_add_lines (SV *string) 1395rxvt_term::scr_add_lines (SV *string)
1278 CODE: 1396 CODE:
1279{ 1397{

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines