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.134 by root, Thu Dec 16 23:03:50 2010 UTC vs.
Revision 1.142 by sf-exg, Fri Jul 1 19:07:08 2011 UTC

1/*----------------------------------------------------------------------* 1/*----------------------------------------------------------------------*
2 * File: rxvtperl.xs 2 * File: rxvtperl.xs
3 *----------------------------------------------------------------------* 3 *----------------------------------------------------------------------*
4 * 4 *
5 * All portions of code are copyright by their respective author/s. 5 * All portions of code are copyright by their respective author/s.
6 * Copyright (c) 2005-2008 Marc Lehmann <pcg@goof.com> 6 * Copyright (c) 2005-2008,2011 Marc Lehmann <schmorp@schmorp.de>
7 * 7 *
8 * This program is free software; you can redistribute it and/or modify 8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by 9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or 10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version. 11 * (at your option) any later version.
302 THIS->refresh_check (); 302 THIS->refresh_check ();
303} 303}
304 304
305///////////////////////////////////////////////////////////////////////////// 305/////////////////////////////////////////////////////////////////////////////
306 306
307#define IOM_CLASS "urxvt"
308#define IOM_WARN rxvt_warn
309#include "iom_perl.h" 307#include "iom_perl.h"
310 308
311///////////////////////////////////////////////////////////////////////////// 309/////////////////////////////////////////////////////////////////////////////
312 310
313struct rxvt_perl_interp rxvt_perl; 311struct rxvt_perl_interp rxvt_perl;
343 " unshift @INC, '" LIBDIR "';" 341 " unshift @INC, '" LIBDIR "';"
344 "}" 342 "}"
345 "" 343 ""
346 "use urxvt;" 344 "use urxvt;"
347 }; 345 };
348 int argc = sizeof (args) / sizeof (args[0]); 346 int argc = ecb_array_length (args);
349 char **argv = args; 347 char **argv = args;
350 348
351 PERL_SYS_INIT3 (&argc, &argv, &environ); 349 PERL_SYS_INIT3 (&argc, &argv, &environ);
352 perl = perl_alloc (); 350 perl = perl_alloc ();
353 perl_construct (perl); 351 perl_construct (perl);
369 if (perl) 367 if (perl)
370 { 368 {
371 // runs outside of perls ENV 369 // runs outside of perls ENV
372 term->perl.self = (void *)newSVptr ((void *)term, "urxvt::term"); 370 term->perl.self = (void *)newSVptr ((void *)term, "urxvt::term");
373 hv_store ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, newRV_noinc ((SV *)newAV ()), 0); 371 hv_store ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, newRV_noinc ((SV *)newAV ()), 0);
372 hv_store ((HV *)SvRV ((SV *)term->perl.self), "_selection", 10, newRV_noinc ((SV *)newAV ()), 0);
374 } 373 }
375} 374}
376 375
377static void 376static void
378ungrab (rxvt_term *THIS) 377ungrab (rxvt_term *THIS)
399 AV *av = (AV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, 0)); 398 AV *av = (AV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, 0));
400 399
401 for (int i = 0; i <= AvFILL (av); i++) 400 for (int i = 0; i <= AvFILL (av); i++)
402 ((overlay *)SvIV (*av_fetch (av, i, 0)))->swap (); 401 ((overlay *)SvIV (*av_fetch (av, i, 0)))->swap ();
403 } 402 }
403 else if (htype == HOOK_DESTROY)
404 {
405 AV *av = (AV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->perl.self), "_selection", 10, 0));
406
407 for (int i = AvFILL (av); i >= 0; i--)
408 {
409 rxvt_selection *req = (rxvt_selection *)SvIV (*av_fetch (av, i, 0));
410 delete req;
411 }
412 }
404 413
405 bool event_consumed; 414 bool event_consumed;
406 415
407 if (htype == HOOK_INIT || htype == HOOK_DESTROY // must be called always 416 if (htype == HOOK_INIT || htype == HOOK_DESTROY // must be called always
408 || term->perl.should_invoke [htype]) 417 || term->perl.should_invoke [htype])
415 ENTER; 424 ENTER;
416 SAVETMPS; 425 SAVETMPS;
417 426
418 PUSHMARK (SP); 427 PUSHMARK (SP);
419 428
429 EXTEND (SP, 2);
420 XPUSHs (sv_2mortal (newSVterm (term))); 430 PUSHs (sv_2mortal (newSVterm (term)));
421 XPUSHs (sv_2mortal (newSViv (htype))); 431 PUSHs (sv_2mortal (newSViv (htype)));
422 432
423 for (;;) { 433 for (;;) {
424 data_type dt = (data_type)va_arg (ap, int); 434 data_type dt = (data_type)va_arg (ap, int);
425 435
426 switch (dt) 436 switch (dt)
583 FREETMPS; 593 FREETMPS;
584 LEAVE; 594 LEAVE;
585 595
586 if (SvTRUE (ERRSV)) 596 if (SvTRUE (ERRSV))
587 { 597 {
588 rxvt_warn ("perl hook %d evaluation error: %s", htype, SvPV_nolen (ERRSV)); 598 rxvt_warn ("perl hook %d evaluation error: %s", htype, SvPVbyte_nolen (ERRSV));
589 ungrab (term); // better lose the grab than the session 599 ungrab (term); // better lose the grab than the session
590 } 600 }
591 601
592 event_consumed = !!count; 602 event_consumed = !!count;
593 } 603 }
610 // don't allow further calls 620 // don't allow further calls
611 term->perl.self = 0; 621 term->perl.self = 0;
612 } 622 }
613 623
614 return event_consumed; 624 return event_consumed;
625}
626
627void
628rxvt_perl_interp::selection_finish (rxvt_selection *sel, char *data, unsigned int len)
629{
630 localise_env set_environ (perl_environ);
631
632 ENTER;
633 SAVETMPS;
634
635 dSP;
636 XPUSHs (sv_2mortal (newSVpvn (data, len)));
637 call_sv ((SV *)sel->cb_sv, G_VOID | G_DISCARD | G_EVAL);
638
639 if (SvTRUE (ERRSV))
640 rxvt_warn ("perl selection callback evaluation error: %s", SvPVbyte_nolen (ERRSV));
641
642 FREETMPS;
643 LEAVE;
615} 644}
616 645
617///////////////////////////////////////////////////////////////////////////// 646/////////////////////////////////////////////////////////////////////////////
618 647
619MODULE = urxvt PACKAGE = urxvt 648MODULE = urxvt PACKAGE = urxvt
770 const_iv (XIMDontChange), 799 const_iv (XIMDontChange),
771# endif 800# endif
772# endif 801# endif
773 }; 802 };
774 803
775 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) 804 for (civ = const_iv + ecb_array_length (const_iv); civ-- > const_iv; )
776 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); 805 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv));
777} 806}
778 807
779void 808void
780warn (const char *msg) 809warn (const char *msg)
852 881
853 for (rxvt_term **t = rxvt_term::termlist.begin (); t < rxvt_term::termlist.end (); t++) 882 for (rxvt_term **t = rxvt_term::termlist.begin (); t < rxvt_term::termlist.end (); t++)
854 if ((*t)->perl.self) 883 if ((*t)->perl.self)
855 PUSHs (sv_2mortal (newSVterm (*t))); 884 PUSHs (sv_2mortal (newSVterm (*t)));
856} 885}
886
887IV
888_new_selection_request (rxvt_term *term, int selnum, Time tm, Window win, Atom prop, SV *cb)
889 CODE:
890 rxvt_selection *req = new rxvt_selection (term->display, selnum, tm, win, prop, term);
891 req->cb_sv = newSVsv (cb);
892 AV *av = (AV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->perl.self), "_selection", 10, 0));
893 av_push (av, newSViv ((IV)req));
894 RETVAL = (IV)req;
895 OUTPUT:
896 RETVAL
897
898void
899_delete_selection_request (IV req_)
900 CODE:
901 rxvt_selection *req = (rxvt_selection *)req_;
902 AV *av = (AV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)req->term->perl.self), "_selection", 10, 0));
903 int i;
904
905 for (i = AvFILL (av); i >= 0; i--)
906 if (SvIV (*av_fetch (av, i, 1)) == req_)
907 break;
908
909 for (; i < AvFILL (av); i++)
910 av_store (av, i, SvREFCNT_inc (*av_fetch (av, i + 1, 0)));
911
912 av_pop (av);
913
914 delete req;
857 915
858MODULE = urxvt PACKAGE = urxvt::term 916MODULE = urxvt PACKAGE = urxvt::term
859 917
860SV * 918SV *
861_new (AV *env, AV *arg) 919_new (AV *env, AV *arg)
1169 RETVAL 1227 RETVAL
1170 1228
1171Window 1229Window
1172rxvt_term::parent () 1230rxvt_term::parent ()
1173 CODE: 1231 CODE:
1174 RETVAL = THIS->parent [0]; 1232 RETVAL = THIS->parent;
1175 OUTPUT: 1233 OUTPUT:
1176 RETVAL 1234 RETVAL
1177 1235
1178Window 1236Window
1179rxvt_term::vt () 1237rxvt_term::vt ()
1448# include "rsinc.h" 1506# include "rsinc.h"
1449# undef def 1507# undef def
1450# undef reserve 1508# undef reserve
1451 }; 1509 };
1452 1510
1453 rs = rslist + sizeof (rslist) / sizeof (rslist [0]); 1511 rs = rslist + ecb_array_length (rslist);
1454 1512
1455 if (*name) 1513 if (*name)
1456 { 1514 {
1457 do { 1515 do {
1458 if (rs-- == rslist) 1516 if (rs-- == rslist)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines