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.53 by root, Tue Jan 10 04:49:54 2006 UTC vs.
Revision 1.57 by root, Thu Jan 12 01:30:53 2006 UTC

411void 411void
412rxvt_perl_interp::init () 412rxvt_perl_interp::init ()
413{ 413{
414 if (!perl) 414 if (!perl)
415 { 415 {
416 perl_environ = rxvt_environ;
417 swap (perl_environ, environ);
418
416 char *argv[] = { 419 char *argv[] = {
417 "", 420 "",
418 "-T", 421 "-T",
419 "-edo '" LIBDIR "/urxvt.pm' or ($@ and die $@) or exit 1", 422 "-edo '" LIBDIR "/urxvt.pm' or ($@ and die $@) or exit 1",
420 }; 423 };
429 432
430 perl_destruct (perl); 433 perl_destruct (perl);
431 perl_free (perl); 434 perl_free (perl);
432 perl = 0; 435 perl = 0;
433 } 436 }
437
438 swap (perl_environ, environ);
434 } 439 }
435} 440}
436 441
437static void 442static void
438ungrab (rxvt_term *THIS) 443ungrab (rxvt_term *THIS)
480 485
481 if (!should_invoke [htype]) 486 if (!should_invoke [htype])
482 return false; 487 return false;
483 } 488 }
484 489
490 swap (perl_environ, environ);
491
492 try
493 {
485 dSP; 494 dSP;
486 va_list ap; 495 va_list ap;
487 496
488 va_start (ap, htype); 497 va_start (ap, htype);
489 498
490 ENTER; 499 ENTER;
491 SAVETMPS; 500 SAVETMPS;
492 501
493 PUSHMARK (SP); 502 PUSHMARK (SP);
494 503
495 XPUSHs (sv_2mortal (newSVterm (term))); 504 XPUSHs (sv_2mortal (newSVterm (term)));
496 XPUSHs (sv_2mortal (newSViv (htype))); 505 XPUSHs (sv_2mortal (newSViv (htype)));
497 506
498 for (;;) { 507 for (;;) {
499 data_type dt = (data_type)va_arg (ap, int); 508 data_type dt = (data_type)va_arg (ap, int);
500 509
501 switch (dt) 510 switch (dt)
502 { 511 {
503 case DT_INT: 512 case DT_INT:
504 XPUSHs (sv_2mortal (newSViv (va_arg (ap, int)))); 513 XPUSHs (sv_2mortal (newSViv (va_arg (ap, int))));
505 break; 514 break;
506 515
507 case DT_LONG: 516 case DT_LONG:
508 XPUSHs (sv_2mortal (newSViv (va_arg (ap, long)))); 517 XPUSHs (sv_2mortal (newSViv (va_arg (ap, long))));
509 break; 518 break;
510 519
511 case DT_STR: 520 case DT_STR:
512 XPUSHs (taint (sv_2mortal (newSVpv (va_arg (ap, char *), 0)))); 521 XPUSHs (taint (sv_2mortal (newSVpv (va_arg (ap, char *), 0))));
513 break; 522 break;
514 523
515 case DT_STR_LEN: 524 case DT_STR_LEN:
516 { 525 {
517 char *str = va_arg (ap, char *); 526 char *str = va_arg (ap, char *);
518 int len = va_arg (ap, int); 527 int len = va_arg (ap, int);
519 528
520 XPUSHs (taint (sv_2mortal (newSVpvn (str, len)))); 529 XPUSHs (taint (sv_2mortal (newSVpvn (str, len))));
521 } 530 }
522 break; 531 break;
523 532
524 case DT_WCS_LEN: 533 case DT_WCS_LEN:
525 { 534 {
526 wchar_t *wstr = va_arg (ap, wchar_t *); 535 wchar_t *wstr = va_arg (ap, wchar_t *);
527 int wlen = va_arg (ap, int); 536 int wlen = va_arg (ap, int);
528 537
529 XPUSHs (taint (sv_2mortal (wcs2sv (wstr, wlen)))); 538 XPUSHs (taint (sv_2mortal (wcs2sv (wstr, wlen))));
530 } 539 }
531 break; 540 break;
532 541
533 case DT_XEVENT: 542 case DT_XEVENT:
534 { 543 {
535 XEvent *xe = va_arg (ap, XEvent *); 544 XEvent *xe = va_arg (ap, XEvent *);
536 HV *hv = newHV (); 545 HV *hv = newHV ();
537 546
538# define set(name, sv) hv_store (hv, # name, sizeof (# name) - 1, sv, 0) 547# 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) 548# define setiv(name, val) hv_store (hv, # name, sizeof (# name) - 1, newSViv (val), 0)
540# undef set 549# undef set
541 550
542 setiv (type, xe->type); 551 setiv (type, xe->type);
543 setiv (send_event, xe->xany.send_event); 552 setiv (send_event, xe->xany.send_event);
544 setiv (serial, xe->xany.serial); 553 setiv (serial, xe->xany.serial);
545 554
546 switch (xe->type) 555 switch (xe->type)
556 {
557 case KeyPress:
558 case KeyRelease:
559 case ButtonPress:
560 case ButtonRelease:
561 case MotionNotify:
562 setiv (time, xe->xmotion.time);
563 setiv (x, xe->xmotion.x);
564 setiv (y, xe->xmotion.y);
565 setiv (row, xe->xmotion.y / term->fheight);
566 setiv (col, xe->xmotion.x / term->fwidth);
567 setiv (x_root, xe->xmotion.x_root);
568 setiv (y_root, xe->xmotion.y_root);
569 setiv (state, xe->xmotion.state);
570 break;
571 }
572
573 switch (xe->type)
574 {
575 case KeyPress:
576 case KeyRelease:
577 setiv (keycode, xe->xkey.keycode);
578 break;
579
580 case ButtonPress:
581 case ButtonRelease:
582 setiv (button, xe->xbutton.button);
583 break;
584
585 case MotionNotify:
586 setiv (is_hint, xe->xmotion.is_hint);
587 break;
588 }
589
590 XPUSHs (sv_2mortal (newRV_noinc ((SV *)hv)));
591 }
592 break;
593
594 case DT_END:
547 { 595 {
548 case KeyPress: 596 va_end (ap);
549 case KeyRelease: 597
550 case ButtonPress: 598 PUTBACK;
551 case ButtonRelease: 599 int count = call_pv ("urxvt::invoke", G_ARRAY | G_EVAL);
552 case MotionNotify: 600 SPAGAIN;
553 setiv (time, xe->xmotion.time); 601
554 setiv (x, xe->xmotion.x); 602 if (count)
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; 603 {
604 SV *status = POPs;
605 count = SvTRUE (status);
606 }
607
608 PUTBACK;
609 FREETMPS;
610 LEAVE;
611
612 if (SvTRUE (ERRSV))
613 {
614 rxvt_warn ("perl hook %d evaluation error: %s", htype, SvPV_nolen (ERRSV));
615 ungrab (term); // better lose the grab than the session
616 }
617
618 if (htype == HOOK_DESTROY)
619 {
620 clearSVptr ((SV *)term->perl.self);
621 SvREFCNT_dec ((SV *)term->perl.self);
622 }
623
624 swap (perl_environ, environ);
625 return count;
562 } 626 }
563 627
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 }
583 break;
584
585 case DT_END:
586 {
587 va_end (ap);
588
589 PUTBACK;
590 int count = call_pv ("urxvt::invoke", G_ARRAY | G_EVAL);
591 SPAGAIN;
592
593 if (count)
594 {
595 SV *status = POPs;
596 count = SvTRUE (status);
597 }
598
599 PUTBACK;
600 FREETMPS;
601 LEAVE;
602
603 if (SvTRUE (ERRSV))
604 {
605 rxvt_warn ("perl hook %d evaluation error: %s", htype, SvPV_nolen (ERRSV));
606 ungrab (term); // better lose the grab than the session
607 }
608
609 if (htype == HOOK_DESTROY)
610 {
611 clearSVptr ((SV *)term->perl.self);
612 SvREFCNT_dec ((SV *)term->perl.self);
613 }
614
615 return count;
616 }
617
618 default: 628 default:
619 rxvt_fatal ("FATAL: unable to pass data type %d\n", dt); 629 rxvt_fatal ("FATAL: unable to pass data type %d\n", dt);
630 }
620 } 631 }
621 } 632 }
633 catch (...)
634 {
635 swap (perl_environ, environ);
636 throw;
637 }
622} 638}
623 639
624///////////////////////////////////////////////////////////////////////////// 640/////////////////////////////////////////////////////////////////////////////
625 641
626MODULE = urxvt PACKAGE = urxvt 642MODULE = urxvt PACKAGE = urxvt
675 export_const_iv (EVENT_NONE); 691 export_const_iv (EVENT_NONE);
676 export_const_iv (EVENT_READ); 692 export_const_iv (EVENT_READ);
677 export_const_iv (EVENT_WRITE); 693 export_const_iv (EVENT_WRITE);
678} 694}
679 695
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
709
710void 696void
711set_should_invoke (int htype, int value) 697set_should_invoke (int htype, int value)
712 CODE: 698 CODE:
713 rxvt_perl.should_invoke [htype] = value; 699 rxvt_perl.should_invoke [htype] = value;
714 700
791} 777}
792 OUTPUT: 778 OUTPUT:
793 RETVAL 779 RETVAL
794 780
795MODULE = urxvt PACKAGE = urxvt::term 781MODULE = urxvt PACKAGE = urxvt::term
782
783SV *
784_new (...)
785 CODE:
786{
787 if (items < 1 || !SvROK (ST (0)) || SvTYPE (SvRV (ST (0))) != SVt_PVAV)
788 croak ("first argument to urxvt::term->_new must be arrayref");
789
790 rxvt_term *term = new rxvt_term;
791
792 term->argv = new stringvec;
793 term->envv = new stringvec;
794
795 for (int i = 1; i < items; i++)
796 term->argv->push_back (strdup (SvPVbyte_nolen (ST (i))));
797
798 AV *envv = (AV *)SvRV (ST (0));
799 for (int i = av_len (envv) + 1; i--; )
800 term->envv->push_back (strdup (SvPVbyte_nolen (*av_fetch (envv, i, 1))));
801
802 term->envv->push_back (0);
803
804 bool success;
805
806 try
807 {
808 success = term->init (term->argv->size (), term->argv->begin ());
809 }
810 catch (const class rxvt_failure_exception &e)
811 {
812 success = false;
813 }
814
815 if (!success)
816 {
817 term->destroy ();
818 croak ("error while initializing new terminal instance");
819 }
820
821 RETVAL = term && term->perl.self
822 ? newSVterm (term) : &PL_sv_undef;
823}
824 OUTPUT:
825 RETVAL
796 826
797void 827void
798rxvt_term::destroy () 828rxvt_term::destroy ()
799 829
800void 830void
959 case 1: RETVAL = THIS->locale; break; 989 case 1: RETVAL = THIS->locale; break;
960 } 990 }
961 OUTPUT: 991 OUTPUT:
962 RETVAL 992 RETVAL
963 993
994SV *
995rxvt_term::_env ()
996 CODE:
997{
998 if (THIS->envv)
999 {
1000 AV *av = newAV ();
1001
1002 for (char **i = THIS->envv->begin (); i != THIS->envv->end (); ++i)
1003 if (*i)
1004 av_push (av, newSVpv (*i, 0));
1005
1006 RETVAL = newRV_noinc ((SV *)av);
1007 }
1008 else
1009 RETVAL = &PL_sv_undef;
1010}
1011 OUTPUT:
1012 RETVAL
1013
964int 1014int
965rxvt_term::pty_ev_events (int events = EVENT_UNDEF) 1015rxvt_term::pty_ev_events (int events = EVENT_UNDEF)
966 CODE: 1016 CODE:
967 RETVAL = THIS->pty_ev.events; 1017 RETVAL = THIS->pty_ev.events;
968 if (events != EVENT_UNDEF) 1018 if (events != EVENT_UNDEF)
1242 else 1292 else
1243 THIS->rs [index] = 0; 1293 THIS->rs [index] = 0;
1244 } 1294 }
1245} 1295}
1246 1296
1297const char *
1298rxvt_term::x_resource (const char *name)
1299 CLEANUP:
1300 SvTAINTED_on (ST (0));
1301
1247bool 1302bool
1248rxvt_term::option (U32 optval, int set = -1) 1303rxvt_term::option (U32 optval, int set = -1)
1249 CODE: 1304 CODE:
1250{ 1305{
1251 RETVAL = THIS->options & optval; 1306 RETVAL = THIS->options & optval;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines