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.42 by root, Sun Jan 8 08:43:11 2006 UTC vs.
Revision 1.56 by root, Thu Jan 12 00:35:39 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
406 perl_free (perl); 407 perl_free (perl);
407 } 408 }
408} 409}
409 410
410void 411void
411rxvt_perl_interp::init (bool tainted) 412rxvt_perl_interp::init ()
412{ 413{
413 if (!perl) 414 if (!perl)
414 { 415 {
416 temp_environ temp_environ(rxvt_environ);
417
415 char *argv[] = { 418 char *argv[] = {
416 "", 419 "",
420 "-T",
417 "-edo '" LIBDIR "/urxvt.pm' or ($@ and die $@) or exit 1", 421 "-edo '" LIBDIR "/urxvt.pm' or ($@ and die $@) or exit 1",
418 "-T",
419 }; 422 };
420 423
421 perl = perl_alloc (); 424 perl = perl_alloc ();
422 perl_construct (perl); 425 perl_construct (perl);
423 426
424 if (perl_parse (perl, xs_init, 2 + !!tainted, argv, (char **)NULL) 427 if (perl_parse (perl, xs_init, 3, argv, (char **)NULL)
425 || perl_run (perl)) 428 || perl_run (perl))
426 { 429 {
427 rxvt_warn ("unable to initialize perl-interpreter, continuing without.\n"); 430 rxvt_warn ("unable to initialize perl-interpreter, continuing without.\n");
428 431
429 perl_destruct (perl); 432 perl_destruct (perl);
430 perl_free (perl); 433 perl_free (perl);
431 perl = 0; 434 perl = 0;
432 } 435 }
436 }
437}
438
439static void
440ungrab (rxvt_term *THIS)
441{
442 if (THIS->perl.grabtime)
443 {
444 XUngrabKeyboard (THIS->display->display, THIS->perl.grabtime);
445 XUngrabPointer (THIS->display->display, THIS->perl.grabtime);
446 THIS->perl.grabtime = 0;
433 } 447 }
434} 448}
435 449
436bool 450bool
437rxvt_perl_interp::invoke (rxvt_term *term, hook_type htype, ...) 451rxvt_perl_interp::invoke (rxvt_term *term, hook_type htype, ...)
448 return false; // perl not initialized for this instance 462 return false; // perl not initialized for this instance
449 else if (htype == HOOK_DESTROY) 463 else if (htype == HOOK_DESTROY)
450 { 464 {
451 // handled later 465 // handled later
452 } 466 }
453 else if (htype == HOOK_REFRESH_BEGIN || htype == HOOK_REFRESH_END) 467 else
454 { 468 {
455 HV *hv = (HV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, 0)); 469 if (htype == HOOK_REFRESH_BEGIN || htype == HOOK_REFRESH_END)
456
457 if (HvKEYS (hv))
458 { 470 {
471 HV *hv = (HV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, 0));
472
473 if (HvKEYS (hv))
474 {
459 hv_iterinit (hv); 475 hv_iterinit (hv);
460 476
461 while (HE *he = hv_iternext (hv)) 477 while (HE *he = hv_iternext (hv))
462 ((overlay *)SvIV (hv_iterval (hv, he)))->swap (); 478 ((overlay *)SvIV (hv_iterval (hv, he)))->swap ();
479 }
480
463 } 481 }
482
483 if (!should_invoke [htype])
484 return false;
464 } 485 }
465 else if (!should_invoke [htype]) 486
466 return false; 487 temp_environ temp_environ(rxvt_environ);
467 488
468 dSP; 489 dSP;
469 va_list ap; 490 va_list ap;
470 491
471 va_start (ap, htype); 492 va_start (ap, htype);
582 PUTBACK; 603 PUTBACK;
583 FREETMPS; 604 FREETMPS;
584 LEAVE; 605 LEAVE;
585 606
586 if (SvTRUE (ERRSV)) 607 if (SvTRUE (ERRSV))
608 {
587 rxvt_warn ("perl hook %d evaluation error: %s", htype, SvPV_nolen (ERRSV)); 609 rxvt_warn ("perl hook %d evaluation error: %s", htype, SvPV_nolen (ERRSV));
610 ungrab (term); // better lose the grab than the session
611 }
588 612
589 if (htype == HOOK_DESTROY) 613 if (htype == HOOK_DESTROY)
590 { 614 {
591 clearSVptr ((SV *)term->perl.self); 615 clearSVptr ((SV *)term->perl.self);
592 SvREFCNT_dec ((SV *)term->perl.self); 616 SvREFCNT_dec ((SV *)term->perl.self);
607 631
608PROTOTYPES: ENABLE 632PROTOTYPES: ENABLE
609 633
610BOOT: 634BOOT:
611{ 635{
612 sv_setsv (get_sv ("urxvt::LIBDIR", 1), newSVpvn (LIBDIR, sizeof (LIBDIR) - 1)); 636 sv_setsv (get_sv ("urxvt::LIBDIR", 1), newSVpvn (LIBDIR, sizeof (LIBDIR) - 1));
637 sv_setsv (get_sv ("urxvt::RESNAME", 1), newSVpvn (RESNAME, sizeof (RESNAME) - 1));
638 sv_setsv (get_sv ("urxvt::RESCLASS", 1), newSVpvn (RESCLASS, sizeof (RESCLASS) - 1));
639 sv_setsv (get_sv ("urxvt::RXVTNAME", 1), newSVpvn (RXVTNAME, sizeof (RXVTNAME) - 1));
613 640
614 AV *hookname = get_av ("urxvt::HOOKNAME", 1); 641 AV *hookname = get_av ("urxvt::HOOKNAME", 1);
615# define def(sym) av_store (hookname, HOOK_ ## sym, newSVpv (# sym, 0)); 642# define def(sym) av_store (hookname, HOOK_ ## sym, newSVpv (# sym, 0));
616# include "hookinc.h" 643# include "hookinc.h"
617# undef def 644# undef def
646 export_const_iv (Button2Mask); 673 export_const_iv (Button2Mask);
647 export_const_iv (Button3Mask); 674 export_const_iv (Button3Mask);
648 export_const_iv (Button4Mask); 675 export_const_iv (Button4Mask);
649 export_const_iv (Button5Mask); 676 export_const_iv (Button5Mask);
650 export_const_iv (AnyModifier); 677 export_const_iv (AnyModifier);
678
679 export_const_iv (EVENT_NONE);
680 export_const_iv (EVENT_READ);
681 export_const_iv (EVENT_WRITE);
651} 682}
683
684void
685set_should_invoke (int htype, int value)
686 CODE:
687 rxvt_perl.should_invoke [htype] = value;
688
689void
690warn (const char *msg)
691 CODE:
692 rxvt_warn ("%s", msg);
693
694void
695fatal (const char *msg)
696 CODE:
697 rxvt_fatal ("%s", msg);
652 698
653SV * 699SV *
654new (...) 700untaint (SV *sv)
655 CODE: 701 CODE:
656{ 702 RETVAL = newSVsv (sv);
657 stringvec *argv = new stringvec; 703 SvTAINTED_off (RETVAL);
658 bool success; 704 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 705 RETVAL
682 706
683void 707bool
684set_should_invoke (int htype, int value) 708safe ()
685 CODE: 709 CODE:
686 rxvt_perl.should_invoke [htype] = value; 710 RETVAL = !rxvt_tainted ();
687 711 OUTPUT:
688void 712 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 713
698NV 714NV
699NOW () 715NOW ()
700 CODE: 716 CODE:
701 RETVAL = NOW; 717 RETVAL = NOW;
749} 765}
750 OUTPUT: 766 OUTPUT:
751 RETVAL 767 RETVAL
752 768
753MODULE = urxvt PACKAGE = urxvt::term 769MODULE = urxvt PACKAGE = urxvt::term
770
771SV *
772_new (...)
773 CODE:
774{
775 if (items < 1 || !SvROK (ST (0)) || SvTYPE (SvRV (ST (0))) != SVt_PVAV)
776 croak ("first argument to urxvt::term->_new must be arrayref");
777
778 rxvt_term *term = new rxvt_term;
779
780 term->argv = new stringvec;
781 term->envv = new stringvec;
782
783 for (int i = 1; i < items; i++)
784 term->argv->push_back (strdup (SvPVbyte_nolen (ST (i))));
785
786 AV *envv = (AV *)SvRV (ST (0));
787 for (int i = av_len (envv) + 1; i--; )
788 term->envv->push_back (strdup (SvPVbyte_nolen (*av_fetch (envv, i, 1))));
789
790 term->envv->push_back (0);
791
792 bool success;
793
794 try
795 {
796 success = term->init (term->argv->size (), term->argv->begin ());
797 }
798 catch (const class rxvt_failure_exception &e)
799 {
800 success = false;
801 }
802
803 if (!success)
804 {
805 term->destroy ();
806 croak ("error while initializing new terminal instance");
807 }
808
809 RETVAL = term && term->perl.self
810 ? newSVterm (term) : &PL_sv_undef;
811}
812 OUTPUT:
813 RETVAL
754 814
755void 815void
756rxvt_term::destroy () 816rxvt_term::destroy ()
757 817
758void 818void
782} 842}
783 OUTPUT: 843 OUTPUT:
784 RETVAL 844 RETVAL
785 845
786void 846void
787rxvt_term::allow_events_async (U32 eventtime = THIS->perl.grabtime) 847rxvt_term::allow_events_async ()
788 CODE: 848 CODE:
789 XAllowEvents (THIS->display->display, AsyncBoth, eventtime); 849 XAllowEvents (THIS->display->display, AsyncBoth, THIS->perl.grabtime);
790 850
791void 851void
792rxvt_term::allow_events_sync (U32 eventtime = THIS->perl.grabtime) 852rxvt_term::allow_events_sync ()
793 CODE: 853 CODE:
794 XAllowEvents (THIS->display->display, SyncBoth, eventtime); 854 XAllowEvents (THIS->display->display, SyncBoth, THIS->perl.grabtime);
795 855
796void 856void
797rxvt_term::allow_events_replay (U32 eventtime = THIS->perl.grabtime) 857rxvt_term::allow_events_replay ()
798 CODE: 858 CODE:
799 XAllowEvents (THIS->display->display, ReplayPointer, eventtime); 859 XAllowEvents (THIS->display->display, ReplayPointer, THIS->perl.grabtime);
800 XAllowEvents (THIS->display->display, ReplayKeyboard, eventtime); 860 XAllowEvents (THIS->display->display, ReplayKeyboard, THIS->perl.grabtime);
801 861
802void 862void
803rxvt_term::ungrab (U32 eventtime = THIS->perl.grabtime) 863rxvt_term::ungrab ()
804 CODE: 864 CODE:
805 THIS->perl.grabtime = 0; 865 ungrab (THIS);
806 XUngrabKeyboard (THIS->display->display, eventtime);
807 XUngrabPointer (THIS->display->display, eventtime);
808 866
809int 867int
810rxvt_term::strwidth (SV *str) 868rxvt_term::strwidth (SV *str)
811 CODE: 869 CODE:
812{ 870{
905 case 2: RETVAL = THIS->ModNumLockMask; break; 963 case 2: RETVAL = THIS->ModNumLockMask; break;
906 } 964 }
907 OUTPUT: 965 OUTPUT:
908 RETVAL 966 RETVAL
909 967
968char *
969rxvt_term::display_id ()
970 ALIAS:
971 display_id = 0
972 locale = 1
973 CODE:
974 switch (ix)
975 {
976 case 0: RETVAL = THIS->display->id; break;
977 case 1: RETVAL = THIS->locale; break;
978 }
979 OUTPUT:
980 RETVAL
981
982SV *
983rxvt_term::_env ()
984 CODE:
985{
986 if (THIS->envv)
987 {
988 AV *av = newAV ();
989
990 for (char **i = THIS->envv->begin (); i != THIS->envv->end (); ++i)
991 if (*i)
992 av_push (av, newSVpv (*i, 0));
993
994 RETVAL = newRV_noinc ((SV *)av);
995 }
996 else
997 RETVAL = &PL_sv_undef;
998}
999 OUTPUT:
1000 RETVAL
1001
1002int
1003rxvt_term::pty_ev_events (int events = EVENT_UNDEF)
1004 CODE:
1005 RETVAL = THIS->pty_ev.events;
1006 if (events != EVENT_UNDEF)
1007 THIS->pty_ev.set (events);
1008 OUTPUT:
1009 RETVAL
1010
910U32 1011U32
911rxvt_term::parent () 1012rxvt_term::parent ()
912 CODE: 1013 CODE:
913 RETVAL = (U32)THIS->parent [0]; 1014 RETVAL = (U32)THIS->parent [0];
914 OUTPUT: 1015 OUTPUT:
1179 else 1280 else
1180 THIS->rs [index] = 0; 1281 THIS->rs [index] = 0;
1181 } 1282 }
1182} 1283}
1183 1284
1285const char *
1286rxvt_term::x_resource (const char *name)
1287 CLEANUP:
1288 SvTAINTED_on (ST (0));
1289
1184bool 1290bool
1185rxvt_term::option (U32 optval, int set = -1) 1291rxvt_term::option (U32 optval, int set = -1)
1186 CODE: 1292 CODE:
1187{ 1293{
1188 RETVAL = THIS->options & optval; 1294 RETVAL = THIS->options & optval;
1215 } 1321 }
1216} 1322}
1217 OUTPUT: 1323 OUTPUT:
1218 RETVAL 1324 RETVAL
1219 1325
1326bool
1327rxvt_term::parse_keysym (char *keysym, char *str)
1328 CODE:
1329 RETVAL = 0 < THIS->parse_keysym (keysym, str);
1330 THIS->keyboard->register_done ();
1331 OUTPUT:
1332 RETVAL
1333
1220void 1334void
1221rxvt_term::cur (...) 1335rxvt_term::screen_cur (...)
1222 PROTOTYPE: $;$$ 1336 PROTOTYPE: $;$$
1223 ALIAS: 1337 ALIAS:
1224 screen_cur = 0 1338 screen_cur = 0
1225 selection_beg = 1 1339 selection_beg = 1
1226 selection_end = 2 1340 selection_end = 2
1247 if (ix) 1361 if (ix)
1248 THIS->want_refresh = 1; 1362 THIS->want_refresh = 1;
1249 } 1363 }
1250} 1364}
1251 1365
1366char
1367rxvt_term::cur_charset ()
1368 CODE:
1369 RETVAL = THIS->charsets [THIS->screen.charset];
1370 OUTPUT:
1371 RETVAL
1372
1252int 1373int
1253rxvt_term::selection_grab (U32 eventtime) 1374rxvt_term::selection_grab (U32 eventtime)
1254 1375
1255void 1376void
1256rxvt_term::selection (SV *newtext = 0) 1377rxvt_term::selection (SV *newtext = 0)
1257 PPCODE: 1378 PPCODE:
1258{ 1379{
1259 if (GIMME_V != G_VOID) 1380 if (GIMME_V != G_VOID)
1381 XPUSHs (THIS->selection.text
1260 XPUSHs (taint (sv_2mortal (wcs2sv (THIS->selection.text, THIS->selection.len)))); 1382 ? taint (sv_2mortal (wcs2sv (THIS->selection.text, THIS->selection.len)))
1383 : &PL_sv_undef);
1261 1384
1262 if (newtext) 1385 if (newtext)
1263 { 1386 {
1264 free (THIS->selection.text); 1387 free (THIS->selection.text);
1265 1388
1266 THIS->selection.text = sv2wcs (newtext); 1389 THIS->selection.text = sv2wcs (newtext);
1267 THIS->selection.len = wcslen (THIS->selection.text); 1390 THIS->selection.len = wcslen (THIS->selection.text);
1268 } 1391 }
1269} 1392}
1393
1394void
1395rxvt_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)
1396
1397void
1398rxvt_term::scr_xor_span (int beg_row, int beg_col, int end_row, int end_col, U32 rstyle = RS_RVid)
1399
1400void
1401rxvt_term::scr_bell ()
1270 1402
1271void 1403void
1272rxvt_term::scr_add_lines (SV *string) 1404rxvt_term::scr_add_lines (SV *string)
1273 CODE: 1405 CODE:
1274{ 1406{

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines