--- rxvt-unicode/src/rxvtperl.xs 2006/01/10 04:49:54 1.53 +++ rxvt-unicode/src/rxvtperl.xs 2006/01/12 02:20:56 1.59 @@ -31,6 +31,8 @@ #include #include +#include "unistd.h" + #include "iom.h" #include "rxvt.h" #include "keyboard.h" @@ -395,10 +397,6 @@ static PerlInterpreter *perl; -rxvt_perl_interp::rxvt_perl_interp () -{ -} - rxvt_perl_interp::~rxvt_perl_interp () { if (perl) @@ -413,6 +411,9 @@ { if (!perl) { + perl_environ = rxvt_environ; + swap (perl_environ, environ); + char *argv[] = { "", "-T", @@ -431,6 +432,8 @@ perl_free (perl); perl = 0; } + + swap (perl_environ, environ); } } @@ -482,143 +485,154 @@ return false; } - dSP; - va_list ap; + swap (perl_environ, environ); - va_start (ap, htype); + try + { + dSP; + va_list ap; - ENTER; - SAVETMPS; + va_start (ap, htype); - PUSHMARK (SP); + ENTER; + SAVETMPS; - XPUSHs (sv_2mortal (newSVterm (term))); - XPUSHs (sv_2mortal (newSViv (htype))); + PUSHMARK (SP); - for (;;) { - data_type dt = (data_type)va_arg (ap, int); + XPUSHs (sv_2mortal (newSVterm (term))); + XPUSHs (sv_2mortal (newSViv (htype))); - switch (dt) - { - case DT_INT: - XPUSHs (sv_2mortal (newSViv (va_arg (ap, int)))); - break; - - case DT_LONG: - XPUSHs (sv_2mortal (newSViv (va_arg (ap, long)))); - break; - - case DT_STR: - XPUSHs (taint (sv_2mortal (newSVpv (va_arg (ap, char *), 0)))); - break; + for (;;) { + data_type dt = (data_type)va_arg (ap, int); - case DT_STR_LEN: + switch (dt) { - char *str = va_arg (ap, char *); - int len = va_arg (ap, int); + case DT_INT: + XPUSHs (sv_2mortal (newSViv (va_arg (ap, int)))); + break; + + case DT_LONG: + XPUSHs (sv_2mortal (newSViv (va_arg (ap, long)))); + break; + + case DT_STR: + XPUSHs (taint (sv_2mortal (newSVpv (va_arg (ap, char *), 0)))); + break; - XPUSHs (taint (sv_2mortal (newSVpvn (str, len)))); - } - break; + case DT_STR_LEN: + { + char *str = va_arg (ap, char *); + int len = va_arg (ap, int); - case DT_WCS_LEN: - { - wchar_t *wstr = va_arg (ap, wchar_t *); - int wlen = va_arg (ap, int); + XPUSHs (taint (sv_2mortal (newSVpvn (str, len)))); + } + break; - XPUSHs (taint (sv_2mortal (wcs2sv (wstr, wlen)))); - } - break; + case DT_WCS_LEN: + { + wchar_t *wstr = va_arg (ap, wchar_t *); + int wlen = va_arg (ap, int); - case DT_XEVENT: - { - XEvent *xe = va_arg (ap, XEvent *); - HV *hv = newHV (); + XPUSHs (taint (sv_2mortal (wcs2sv (wstr, wlen)))); + } + break; + + case DT_XEVENT: + { + XEvent *xe = va_arg (ap, XEvent *); + HV *hv = newHV (); # define set(name, sv) hv_store (hv, # name, sizeof (# name) - 1, sv, 0) # define setiv(name, val) hv_store (hv, # name, sizeof (# name) - 1, newSViv (val), 0) # undef set - setiv (type, xe->type); - setiv (send_event, xe->xany.send_event); - setiv (serial, xe->xany.serial); - - switch (xe->type) - { - case KeyPress: - case KeyRelease: - case ButtonPress: - case ButtonRelease: - case MotionNotify: - setiv (time, xe->xmotion.time); - setiv (x, xe->xmotion.x); - setiv (y, xe->xmotion.y); - setiv (row, xe->xmotion.y / term->fheight); - setiv (col, xe->xmotion.x / term->fwidth); - setiv (x_root, xe->xmotion.x_root); - setiv (y_root, xe->xmotion.y_root); - setiv (state, xe->xmotion.state); - break; - } + setiv (type, xe->type); + setiv (send_event, xe->xany.send_event); + setiv (serial, xe->xany.serial); + + switch (xe->type) + { + case KeyPress: + case KeyRelease: + case ButtonPress: + case ButtonRelease: + case MotionNotify: + setiv (time, xe->xmotion.time); + setiv (x, xe->xmotion.x); + setiv (y, xe->xmotion.y); + setiv (row, xe->xmotion.y / term->fheight); + setiv (col, xe->xmotion.x / term->fwidth); + setiv (x_root, xe->xmotion.x_root); + setiv (y_root, xe->xmotion.y_root); + setiv (state, xe->xmotion.state); + break; + } + + switch (xe->type) + { + case KeyPress: + case KeyRelease: + setiv (keycode, xe->xkey.keycode); + break; + + case ButtonPress: + case ButtonRelease: + setiv (button, xe->xbutton.button); + break; + + case MotionNotify: + setiv (is_hint, xe->xmotion.is_hint); + break; + } - switch (xe->type) - { - case KeyPress: - case KeyRelease: - setiv (keycode, xe->xkey.keycode); - break; - - case ButtonPress: - case ButtonRelease: - setiv (button, xe->xbutton.button); - break; - - case MotionNotify: - setiv (is_hint, xe->xmotion.is_hint); - break; + XPUSHs (sv_2mortal (newRV_noinc ((SV *)hv))); } + break; - XPUSHs (sv_2mortal (newRV_noinc ((SV *)hv))); - } - break; - - case DT_END: - { - va_end (ap); - - PUTBACK; - int count = call_pv ("urxvt::invoke", G_ARRAY | G_EVAL); - SPAGAIN; - - if (count) + case DT_END: { - SV *status = POPs; - count = SvTRUE (status); - } + va_end (ap); - PUTBACK; - FREETMPS; - LEAVE; + PUTBACK; + int count = call_pv ("urxvt::invoke", G_ARRAY | G_EVAL); + SPAGAIN; + + if (count) + { + SV *status = POPs; + count = SvTRUE (status); + } + + PUTBACK; + FREETMPS; + LEAVE; + + if (SvTRUE (ERRSV)) + { + rxvt_warn ("perl hook %d evaluation error: %s", htype, SvPV_nolen (ERRSV)); + ungrab (term); // better lose the grab than the session + } + + if (htype == HOOK_DESTROY) + { + clearSVptr ((SV *)term->perl.self); + SvREFCNT_dec ((SV *)term->perl.self); + } - if (SvTRUE (ERRSV)) - { - rxvt_warn ("perl hook %d evaluation error: %s", htype, SvPV_nolen (ERRSV)); - ungrab (term); // better lose the grab than the session + swap (perl_environ, environ); + return count; } - if (htype == HOOK_DESTROY) - { - clearSVptr ((SV *)term->perl.self); - SvREFCNT_dec ((SV *)term->perl.self); - } - - return count; + default: + rxvt_fatal ("FATAL: unable to pass data type %d\n", dt); } - - default: - rxvt_fatal ("FATAL: unable to pass data type %d\n", dt); } - } + } + catch (...) + { + swap (perl_environ, environ); + throw; + } } ///////////////////////////////////////////////////////////////////////////// @@ -677,36 +691,6 @@ export_const_iv (EVENT_WRITE); } -SV * -new (...) - CODE: -{ - stringvec *argv = new stringvec; - bool success; - - for (int i = 0; i < items ;i++) - argv->push_back (strdup (SvPVbyte_nolen (ST (i)))); - - rxvt_term *term = new rxvt_term; - - term->argv = argv; - - try - { - if (!term->init (argv->size (), argv->begin ())) - term = 0; - } - catch (const class rxvt_failure_exception &e) - { - term->destroy (); - croak ("exception caught while initializing new terminal instance"); - } - - RETVAL = term && term->perl.self ? newSVterm (term) : &PL_sv_undef; -} - OUTPUT: - RETVAL - void set_should_invoke (int htype, int value) CODE: @@ -730,6 +714,9 @@ OUTPUT: RETVAL +void +_exit (int status) + bool safe () CODE: @@ -794,6 +781,50 @@ MODULE = urxvt PACKAGE = urxvt::term +SV * +_new (...) + CODE: +{ + if (items < 1 || !SvROK (ST (0)) || SvTYPE (SvRV (ST (0))) != SVt_PVAV) + croak ("first argument to urxvt::term->_new must be arrayref"); + + rxvt_term *term = new rxvt_term; + + term->argv = new stringvec; + term->envv = new stringvec; + + for (int i = 1; i < items; i++) + term->argv->push_back (strdup (SvPVbyte_nolen (ST (i)))); + + AV *envv = (AV *)SvRV (ST (0)); + for (int i = av_len (envv) + 1; i--; ) + term->envv->push_back (strdup (SvPVbyte_nolen (*av_fetch (envv, i, 1)))); + + term->envv->push_back (0); + + bool success; + + try + { + success = term->init (term->argv->size (), term->argv->begin ()); + } + catch (const class rxvt_failure_exception &e) + { + success = false; + } + + if (!success) + { + term->destroy (); + croak ("error while initializing new terminal instance"); + } + + RETVAL = term && term->perl.self + ? newSVterm (term) : &PL_sv_undef; +} + OUTPUT: + RETVAL + void rxvt_term::destroy () @@ -961,6 +992,26 @@ OUTPUT: RETVAL +SV * +rxvt_term::_env () + CODE: +{ + if (THIS->envv) + { + AV *av = newAV (); + + for (char **i = THIS->envv->begin (); i != THIS->envv->end (); ++i) + if (*i) + av_push (av, newSVpv (*i, 0)); + + RETVAL = newRV_noinc ((SV *)av); + } + else + RETVAL = &PL_sv_undef; +} + OUTPUT: + RETVAL + int rxvt_term::pty_ev_events (int events = EVENT_UNDEF) CODE: @@ -1244,6 +1295,11 @@ } } +const char * +rxvt_term::x_resource (const char *name) + CLEANUP: + SvTAINTED_on (ST (0)); + bool rxvt_term::option (U32 optval, int set = -1) CODE: