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.54 by root, Wed Jan 11 00:59:58 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
1276 else 1292 else
1277 THIS->rs [index] = 0; 1293 THIS->rs [index] = 0;
1278 } 1294 }
1279} 1295}
1280 1296
1297const char *
1298rxvt_term::x_resource (const char *name)
1299 CLEANUP:
1300 SvTAINTED_on (ST (0));
1301
1281bool 1302bool
1282rxvt_term::option (U32 optval, int set = -1) 1303rxvt_term::option (U32 optval, int set = -1)
1283 CODE: 1304 CODE:
1284{ 1305{
1285 RETVAL = THIS->options & optval; 1306 RETVAL = THIS->options & optval;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines