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.50 by root, Mon Jan 9 22:41:41 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
627 643
628PROTOTYPES: ENABLE 644PROTOTYPES: ENABLE
629 645
630BOOT: 646BOOT:
631{ 647{
632 sv_setsv (get_sv ("urxvt::LIBDIR", 1), newSVpvn (LIBDIR, sizeof (LIBDIR) - 1)); 648 sv_setsv (get_sv ("urxvt::LIBDIR", 1), newSVpvn (LIBDIR, sizeof (LIBDIR) - 1));
649 sv_setsv (get_sv ("urxvt::RESNAME", 1), newSVpvn (RESNAME, sizeof (RESNAME) - 1));
650 sv_setsv (get_sv ("urxvt::RESCLASS", 1), newSVpvn (RESCLASS, sizeof (RESCLASS) - 1));
651 sv_setsv (get_sv ("urxvt::RXVTNAME", 1), newSVpvn (RXVTNAME, sizeof (RXVTNAME) - 1));
633 652
634 AV *hookname = get_av ("urxvt::HOOKNAME", 1); 653 AV *hookname = get_av ("urxvt::HOOKNAME", 1);
635# define def(sym) av_store (hookname, HOOK_ ## sym, newSVpv (# sym, 0)); 654# define def(sym) av_store (hookname, HOOK_ ## sym, newSVpv (# sym, 0));
636# include "hookinc.h" 655# include "hookinc.h"
637# undef def 656# undef def
672 export_const_iv (EVENT_NONE); 691 export_const_iv (EVENT_NONE);
673 export_const_iv (EVENT_READ); 692 export_const_iv (EVENT_READ);
674 export_const_iv (EVENT_WRITE); 693 export_const_iv (EVENT_WRITE);
675} 694}
676 695
677SV *
678new (...)
679 CODE:
680{
681 stringvec *argv = new stringvec;
682 bool success;
683
684 for (int i = 0; i < items ;i++)
685 argv->push_back (strdup (SvPVbyte_nolen (ST (i))));
686
687 rxvt_term *term = new rxvt_term;
688
689 term->argv = argv;
690
691 try
692 {
693 if (!term->init (argv->size (), argv->begin ()))
694 term = 0;
695 }
696 catch (const class rxvt_failure_exception &e)
697 {
698 term->destroy ();
699 croak ("exception caught while initializing new terminal instance");
700 }
701
702 RETVAL = term && term->perl.self ? newSVterm (term) : &PL_sv_undef;
703}
704 OUTPUT:
705 RETVAL
706
707void 696void
708set_should_invoke (int htype, int value) 697set_should_invoke (int htype, int value)
709 CODE: 698 CODE:
710 rxvt_perl.should_invoke [htype] = value; 699 rxvt_perl.should_invoke [htype] = value;
711 700
788} 777}
789 OUTPUT: 778 OUTPUT:
790 RETVAL 779 RETVAL
791 780
792MODULE = 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
793 826
794void 827void
795rxvt_term::destroy () 828rxvt_term::destroy ()
796 829
797void 830void
956 case 1: RETVAL = THIS->locale; break; 989 case 1: RETVAL = THIS->locale; break;
957 } 990 }
958 OUTPUT: 991 OUTPUT:
959 RETVAL 992 RETVAL
960 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
961int 1014int
962rxvt_term::pty_ev_events (int events = EVENT_UNDEF) 1015rxvt_term::pty_ev_events (int events = EVENT_UNDEF)
963 CODE: 1016 CODE:
964 RETVAL = THIS->pty_ev.events; 1017 RETVAL = THIS->pty_ev.events;
965 if (events != EVENT_UNDEF) 1018 if (events != EVENT_UNDEF)
1239 else 1292 else
1240 THIS->rs [index] = 0; 1293 THIS->rs [index] = 0;
1241 } 1294 }
1242} 1295}
1243 1296
1297const char *
1298rxvt_term::x_resource (const char *name)
1299 CLEANUP:
1300 SvTAINTED_on (ST (0));
1301
1244bool 1302bool
1245rxvt_term::option (U32 optval, int set = -1) 1303rxvt_term::option (U32 optval, int set = -1)
1246 CODE: 1304 CODE:
1247{ 1305{
1248 RETVAL = THIS->options & optval; 1306 RETVAL = THIS->options & optval;
1315 if (ix) 1373 if (ix)
1316 THIS->want_refresh = 1; 1374 THIS->want_refresh = 1;
1317 } 1375 }
1318} 1376}
1319 1377
1378char
1379rxvt_term::cur_charset ()
1380 CODE:
1381 RETVAL = THIS->charsets [THIS->screen.charset];
1382 OUTPUT:
1383 RETVAL
1384
1320int 1385int
1321rxvt_term::selection_grab (U32 eventtime) 1386rxvt_term::selection_grab (U32 eventtime)
1322 1387
1323void 1388void
1324rxvt_term::selection (SV *newtext = 0) 1389rxvt_term::selection (SV *newtext = 0)
1335 1400
1336 THIS->selection.text = sv2wcs (newtext); 1401 THIS->selection.text = sv2wcs (newtext);
1337 THIS->selection.len = wcslen (THIS->selection.text); 1402 THIS->selection.len = wcslen (THIS->selection.text);
1338 } 1403 }
1339} 1404}
1405
1406void
1407rxvt_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)
1408
1409void
1410rxvt_term::scr_xor_span (int beg_row, int beg_col, int end_row, int end_col, U32 rstyle = RS_RVid)
1340 1411
1341void 1412void
1342rxvt_term::scr_bell () 1413rxvt_term::scr_bell ()
1343 1414
1344void 1415void

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines