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.47 by root, Mon Jan 9 02:06:43 2006 UTC vs.
Revision 1.58 by root, Thu Jan 12 01:38:37 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
392 393
393struct rxvt_perl_interp rxvt_perl; 394struct rxvt_perl_interp rxvt_perl;
394 395
395static PerlInterpreter *perl; 396static PerlInterpreter *perl;
396 397
397rxvt_perl_interp::rxvt_perl_interp ()
398{
399}
400
401rxvt_perl_interp::~rxvt_perl_interp () 398rxvt_perl_interp::~rxvt_perl_interp ()
402{ 399{
403 if (perl) 400 if (perl)
404 { 401 {
405 perl_destruct (perl); 402 perl_destruct (perl);
410void 407void
411rxvt_perl_interp::init () 408rxvt_perl_interp::init ()
412{ 409{
413 if (!perl) 410 if (!perl)
414 { 411 {
412 perl_environ = rxvt_environ;
413 swap (perl_environ, environ);
414
415 char *argv[] = { 415 char *argv[] = {
416 "", 416 "",
417 "-T", 417 "-T",
418 "-edo '" LIBDIR "/urxvt.pm' or ($@ and die $@) or exit 1", 418 "-edo '" LIBDIR "/urxvt.pm' or ($@ and die $@) or exit 1",
419 }; 419 };
428 428
429 perl_destruct (perl); 429 perl_destruct (perl);
430 perl_free (perl); 430 perl_free (perl);
431 perl = 0; 431 perl = 0;
432 } 432 }
433
434 swap (perl_environ, environ);
433 } 435 }
434} 436}
435 437
436static void 438static void
437ungrab (rxvt_term *THIS) 439ungrab (rxvt_term *THIS)
459 return false; // perl not initialized for this instance 461 return false; // perl not initialized for this instance
460 else if (htype == HOOK_DESTROY) 462 else if (htype == HOOK_DESTROY)
461 { 463 {
462 // handled later 464 // handled later
463 } 465 }
464 else if (htype == HOOK_REFRESH_BEGIN || htype == HOOK_REFRESH_END) 466 else
465 { 467 {
466 HV *hv = (HV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, 0)); 468 if (htype == HOOK_REFRESH_BEGIN || htype == HOOK_REFRESH_END)
467
468 if (HvKEYS (hv))
469 { 469 {
470 HV *hv = (HV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, 0));
471
472 if (HvKEYS (hv))
473 {
470 hv_iterinit (hv); 474 hv_iterinit (hv);
471 475
472 while (HE *he = hv_iternext (hv)) 476 while (HE *he = hv_iternext (hv))
473 ((overlay *)SvIV (hv_iterval (hv, he)))->swap (); 477 ((overlay *)SvIV (hv_iterval (hv, he)))->swap ();
478 }
479
474 } 480 }
481
482 if (!should_invoke [htype])
483 return false;
475 } 484 }
476 else if (!should_invoke [htype])
477 return false;
478 485
486 swap (perl_environ, environ);
487
488 try
489 {
479 dSP; 490 dSP;
480 va_list ap; 491 va_list ap;
481 492
482 va_start (ap, htype); 493 va_start (ap, htype);
483 494
484 ENTER; 495 ENTER;
485 SAVETMPS; 496 SAVETMPS;
486 497
487 PUSHMARK (SP); 498 PUSHMARK (SP);
488 499
489 XPUSHs (sv_2mortal (newSVterm (term))); 500 XPUSHs (sv_2mortal (newSVterm (term)));
490 XPUSHs (sv_2mortal (newSViv (htype))); 501 XPUSHs (sv_2mortal (newSViv (htype)));
491 502
492 for (;;) { 503 for (;;) {
493 data_type dt = (data_type)va_arg (ap, int); 504 data_type dt = (data_type)va_arg (ap, int);
494 505
495 switch (dt) 506 switch (dt)
496 { 507 {
497 case DT_INT: 508 case DT_INT:
498 XPUSHs (sv_2mortal (newSViv (va_arg (ap, int)))); 509 XPUSHs (sv_2mortal (newSViv (va_arg (ap, int))));
499 break; 510 break;
500 511
501 case DT_LONG: 512 case DT_LONG:
502 XPUSHs (sv_2mortal (newSViv (va_arg (ap, long)))); 513 XPUSHs (sv_2mortal (newSViv (va_arg (ap, long))));
503 break; 514 break;
504 515
505 case DT_STR: 516 case DT_STR:
506 XPUSHs (taint (sv_2mortal (newSVpv (va_arg (ap, char *), 0)))); 517 XPUSHs (taint (sv_2mortal (newSVpv (va_arg (ap, char *), 0))));
507 break; 518 break;
508 519
509 case DT_STR_LEN: 520 case DT_STR_LEN:
510 { 521 {
511 char *str = va_arg (ap, char *); 522 char *str = va_arg (ap, char *);
512 int len = va_arg (ap, int); 523 int len = va_arg (ap, int);
513 524
514 XPUSHs (taint (sv_2mortal (newSVpvn (str, len)))); 525 XPUSHs (taint (sv_2mortal (newSVpvn (str, len))));
515 } 526 }
516 break; 527 break;
517 528
518 case DT_WCS_LEN: 529 case DT_WCS_LEN:
519 { 530 {
520 wchar_t *wstr = va_arg (ap, wchar_t *); 531 wchar_t *wstr = va_arg (ap, wchar_t *);
521 int wlen = va_arg (ap, int); 532 int wlen = va_arg (ap, int);
522 533
523 XPUSHs (taint (sv_2mortal (wcs2sv (wstr, wlen)))); 534 XPUSHs (taint (sv_2mortal (wcs2sv (wstr, wlen))));
524 } 535 }
525 break; 536 break;
526 537
527 case DT_XEVENT: 538 case DT_XEVENT:
528 { 539 {
529 XEvent *xe = va_arg (ap, XEvent *); 540 XEvent *xe = va_arg (ap, XEvent *);
530 HV *hv = newHV (); 541 HV *hv = newHV ();
531 542
532# define set(name, sv) hv_store (hv, # name, sizeof (# name) - 1, sv, 0) 543# 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) 544# define setiv(name, val) hv_store (hv, # name, sizeof (# name) - 1, newSViv (val), 0)
534# undef set 545# undef set
535 546
536 setiv (type, xe->type); 547 setiv (type, xe->type);
537 setiv (send_event, xe->xany.send_event); 548 setiv (send_event, xe->xany.send_event);
538 setiv (serial, xe->xany.serial); 549 setiv (serial, xe->xany.serial);
539 550
540 switch (xe->type) 551 switch (xe->type)
552 {
553 case KeyPress:
554 case KeyRelease:
555 case ButtonPress:
556 case ButtonRelease:
557 case MotionNotify:
558 setiv (time, xe->xmotion.time);
559 setiv (x, xe->xmotion.x);
560 setiv (y, xe->xmotion.y);
561 setiv (row, xe->xmotion.y / term->fheight);
562 setiv (col, xe->xmotion.x / term->fwidth);
563 setiv (x_root, xe->xmotion.x_root);
564 setiv (y_root, xe->xmotion.y_root);
565 setiv (state, xe->xmotion.state);
566 break;
567 }
568
569 switch (xe->type)
570 {
571 case KeyPress:
572 case KeyRelease:
573 setiv (keycode, xe->xkey.keycode);
574 break;
575
576 case ButtonPress:
577 case ButtonRelease:
578 setiv (button, xe->xbutton.button);
579 break;
580
581 case MotionNotify:
582 setiv (is_hint, xe->xmotion.is_hint);
583 break;
584 }
585
586 XPUSHs (sv_2mortal (newRV_noinc ((SV *)hv)));
587 }
588 break;
589
590 case DT_END:
541 { 591 {
542 case KeyPress: 592 va_end (ap);
543 case KeyRelease: 593
544 case ButtonPress: 594 PUTBACK;
545 case ButtonRelease: 595 int count = call_pv ("urxvt::invoke", G_ARRAY | G_EVAL);
546 case MotionNotify: 596 SPAGAIN;
547 setiv (time, xe->xmotion.time); 597
548 setiv (x, xe->xmotion.x); 598 if (count)
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; 599 {
600 SV *status = POPs;
601 count = SvTRUE (status);
602 }
603
604 PUTBACK;
605 FREETMPS;
606 LEAVE;
607
608 if (SvTRUE (ERRSV))
609 {
610 rxvt_warn ("perl hook %d evaluation error: %s", htype, SvPV_nolen (ERRSV));
611 ungrab (term); // better lose the grab than the session
612 }
613
614 if (htype == HOOK_DESTROY)
615 {
616 clearSVptr ((SV *)term->perl.self);
617 SvREFCNT_dec ((SV *)term->perl.self);
618 }
619
620 swap (perl_environ, environ);
621 return count;
556 } 622 }
557 623
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 }
577 break;
578
579 case DT_END:
580 {
581 va_end (ap);
582
583 PUTBACK;
584 int count = call_pv ("urxvt::invoke", G_ARRAY | G_EVAL);
585 SPAGAIN;
586
587 if (count)
588 {
589 SV *status = POPs;
590 count = SvTRUE (status);
591 }
592
593 PUTBACK;
594 FREETMPS;
595 LEAVE;
596
597 if (SvTRUE (ERRSV))
598 {
599 rxvt_warn ("perl hook %d evaluation error: %s", htype, SvPV_nolen (ERRSV));
600 ungrab (term); // better lose the grab than the session
601 }
602
603 if (htype == HOOK_DESTROY)
604 {
605 clearSVptr ((SV *)term->perl.self);
606 SvREFCNT_dec ((SV *)term->perl.self);
607 }
608
609 return count;
610 }
611
612 default: 624 default:
613 rxvt_fatal ("FATAL: unable to pass data type %d\n", dt); 625 rxvt_fatal ("FATAL: unable to pass data type %d\n", dt);
626 }
614 } 627 }
615 } 628 }
629 catch (...)
630 {
631 swap (perl_environ, environ);
632 throw;
633 }
616} 634}
617 635
618///////////////////////////////////////////////////////////////////////////// 636/////////////////////////////////////////////////////////////////////////////
619 637
620MODULE = urxvt PACKAGE = urxvt 638MODULE = urxvt PACKAGE = urxvt
621 639
622PROTOTYPES: ENABLE 640PROTOTYPES: ENABLE
623 641
624BOOT: 642BOOT:
625{ 643{
626 sv_setsv (get_sv ("urxvt::LIBDIR", 1), newSVpvn (LIBDIR, sizeof (LIBDIR) - 1)); 644 sv_setsv (get_sv ("urxvt::LIBDIR", 1), newSVpvn (LIBDIR, sizeof (LIBDIR) - 1));
645 sv_setsv (get_sv ("urxvt::RESNAME", 1), newSVpvn (RESNAME, sizeof (RESNAME) - 1));
646 sv_setsv (get_sv ("urxvt::RESCLASS", 1), newSVpvn (RESCLASS, sizeof (RESCLASS) - 1));
647 sv_setsv (get_sv ("urxvt::RXVTNAME", 1), newSVpvn (RXVTNAME, sizeof (RXVTNAME) - 1));
627 648
628 AV *hookname = get_av ("urxvt::HOOKNAME", 1); 649 AV *hookname = get_av ("urxvt::HOOKNAME", 1);
629# define def(sym) av_store (hookname, HOOK_ ## sym, newSVpv (# sym, 0)); 650# define def(sym) av_store (hookname, HOOK_ ## sym, newSVpv (# sym, 0));
630# include "hookinc.h" 651# include "hookinc.h"
631# undef def 652# undef def
660 export_const_iv (Button2Mask); 681 export_const_iv (Button2Mask);
661 export_const_iv (Button3Mask); 682 export_const_iv (Button3Mask);
662 export_const_iv (Button4Mask); 683 export_const_iv (Button4Mask);
663 export_const_iv (Button5Mask); 684 export_const_iv (Button5Mask);
664 export_const_iv (AnyModifier); 685 export_const_iv (AnyModifier);
665}
666 686
667SV * 687 export_const_iv (EVENT_NONE);
668new (...) 688 export_const_iv (EVENT_READ);
669 CODE: 689 export_const_iv (EVENT_WRITE);
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} 690}
694 OUTPUT:
695 RETVAL
696 691
697void 692void
698set_should_invoke (int htype, int value) 693set_should_invoke (int htype, int value)
699 CODE: 694 CODE:
700 rxvt_perl.should_invoke [htype] = value; 695 rxvt_perl.should_invoke [htype] = value;
778} 773}
779 OUTPUT: 774 OUTPUT:
780 RETVAL 775 RETVAL
781 776
782MODULE = urxvt PACKAGE = urxvt::term 777MODULE = urxvt PACKAGE = urxvt::term
778
779SV *
780_new (...)
781 CODE:
782{
783 if (items < 1 || !SvROK (ST (0)) || SvTYPE (SvRV (ST (0))) != SVt_PVAV)
784 croak ("first argument to urxvt::term->_new must be arrayref");
785
786 rxvt_term *term = new rxvt_term;
787
788 term->argv = new stringvec;
789 term->envv = new stringvec;
790
791 for (int i = 1; i < items; i++)
792 term->argv->push_back (strdup (SvPVbyte_nolen (ST (i))));
793
794 AV *envv = (AV *)SvRV (ST (0));
795 for (int i = av_len (envv) + 1; i--; )
796 term->envv->push_back (strdup (SvPVbyte_nolen (*av_fetch (envv, i, 1))));
797
798 term->envv->push_back (0);
799
800 bool success;
801
802 try
803 {
804 success = term->init (term->argv->size (), term->argv->begin ());
805 }
806 catch (const class rxvt_failure_exception &e)
807 {
808 success = false;
809 }
810
811 if (!success)
812 {
813 term->destroy ();
814 croak ("error while initializing new terminal instance");
815 }
816
817 RETVAL = term && term->perl.self
818 ? newSVterm (term) : &PL_sv_undef;
819}
820 OUTPUT:
821 RETVAL
783 822
784void 823void
785rxvt_term::destroy () 824rxvt_term::destroy ()
786 825
787void 826void
932 case 2: RETVAL = THIS->ModNumLockMask; break; 971 case 2: RETVAL = THIS->ModNumLockMask; break;
933 } 972 }
934 OUTPUT: 973 OUTPUT:
935 RETVAL 974 RETVAL
936 975
976char *
977rxvt_term::display_id ()
978 ALIAS:
979 display_id = 0
980 locale = 1
981 CODE:
982 switch (ix)
983 {
984 case 0: RETVAL = THIS->display->id; break;
985 case 1: RETVAL = THIS->locale; break;
986 }
987 OUTPUT:
988 RETVAL
989
990SV *
991rxvt_term::_env ()
992 CODE:
993{
994 if (THIS->envv)
995 {
996 AV *av = newAV ();
997
998 for (char **i = THIS->envv->begin (); i != THIS->envv->end (); ++i)
999 if (*i)
1000 av_push (av, newSVpv (*i, 0));
1001
1002 RETVAL = newRV_noinc ((SV *)av);
1003 }
1004 else
1005 RETVAL = &PL_sv_undef;
1006}
1007 OUTPUT:
1008 RETVAL
1009
1010int
1011rxvt_term::pty_ev_events (int events = EVENT_UNDEF)
1012 CODE:
1013 RETVAL = THIS->pty_ev.events;
1014 if (events != EVENT_UNDEF)
1015 THIS->pty_ev.set (events);
1016 OUTPUT:
1017 RETVAL
1018
937U32 1019U32
938rxvt_term::parent () 1020rxvt_term::parent ()
939 CODE: 1021 CODE:
940 RETVAL = (U32)THIS->parent [0]; 1022 RETVAL = (U32)THIS->parent [0];
941 OUTPUT: 1023 OUTPUT:
1206 else 1288 else
1207 THIS->rs [index] = 0; 1289 THIS->rs [index] = 0;
1208 } 1290 }
1209} 1291}
1210 1292
1293const char *
1294rxvt_term::x_resource (const char *name)
1295 CLEANUP:
1296 SvTAINTED_on (ST (0));
1297
1211bool 1298bool
1212rxvt_term::option (U32 optval, int set = -1) 1299rxvt_term::option (U32 optval, int set = -1)
1213 CODE: 1300 CODE:
1214{ 1301{
1215 RETVAL = THIS->options & optval; 1302 RETVAL = THIS->options & optval;
1242 } 1329 }
1243} 1330}
1244 OUTPUT: 1331 OUTPUT:
1245 RETVAL 1332 RETVAL
1246 1333
1334bool
1335rxvt_term::parse_keysym (char *keysym, char *str)
1336 CODE:
1337 RETVAL = 0 < THIS->parse_keysym (keysym, str);
1338 THIS->keyboard->register_done ();
1339 OUTPUT:
1340 RETVAL
1341
1247void 1342void
1248rxvt_term::screen_cur (...) 1343rxvt_term::screen_cur (...)
1249 PROTOTYPE: $;$$ 1344 PROTOTYPE: $;$$
1250 ALIAS: 1345 ALIAS:
1251 screen_cur = 0 1346 screen_cur = 0
1274 if (ix) 1369 if (ix)
1275 THIS->want_refresh = 1; 1370 THIS->want_refresh = 1;
1276 } 1371 }
1277} 1372}
1278 1373
1374char
1375rxvt_term::cur_charset ()
1376 CODE:
1377 RETVAL = THIS->charsets [THIS->screen.charset];
1378 OUTPUT:
1379 RETVAL
1380
1279int 1381int
1280rxvt_term::selection_grab (U32 eventtime) 1382rxvt_term::selection_grab (U32 eventtime)
1281 1383
1282void 1384void
1283rxvt_term::selection (SV *newtext = 0) 1385rxvt_term::selection (SV *newtext = 0)
1294 1396
1295 THIS->selection.text = sv2wcs (newtext); 1397 THIS->selection.text = sv2wcs (newtext);
1296 THIS->selection.len = wcslen (THIS->selection.text); 1398 THIS->selection.len = wcslen (THIS->selection.text);
1297 } 1399 }
1298} 1400}
1401
1402void
1403rxvt_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)
1404
1405void
1406rxvt_term::scr_xor_span (int beg_row, int beg_col, int end_row, int end_col, U32 rstyle = RS_RVid)
1407
1408void
1409rxvt_term::scr_bell ()
1299 1410
1300void 1411void
1301rxvt_term::scr_add_lines (SV *string) 1412rxvt_term::scr_add_lines (SV *string)
1302 CODE: 1413 CODE:
1303{ 1414{

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines