… | |
… | |
39 | #include "rxvtutil.h" |
39 | #include "rxvtutil.h" |
40 | #include "rxvtperl.h" |
40 | #include "rxvtperl.h" |
41 | |
41 | |
42 | #include "perlxsi.c" |
42 | #include "perlxsi.c" |
43 | |
43 | |
44 | #if defined(HAVE_SCROLLBARS) || defined(MENUBAR) |
44 | #ifdef HAVE_SCROLLBARS |
45 | # define GRAB_CURSOR THIS->leftptr_cursor |
45 | # define GRAB_CURSOR THIS->leftptr_cursor |
46 | #else |
46 | #else |
47 | # define GRAB_CURSOR None |
47 | # define GRAB_CURSOR None |
48 | #endif |
48 | #endif |
49 | |
49 | |
50 | #undef LINENO |
50 | #undef LINENO |
51 | #define LINENO(n) MOD (THIS->term_start + int(n), THIS->total_rows) |
51 | #define LINENO(n) MOD (THIS->term_start + int(n), THIS->total_rows) |
52 | #undef ROW |
52 | #undef ROW |
53 | #define ROW(n) THIS->row_buf [LINENO (n)] |
53 | #define ROW(n) THIS->row_buf [LINENO (n)] |
54 | |
54 | |
55 | #define ENABLE_PERL_FRILLS 0 |
55 | #define ENABLE_PERL_FRILLS 1 |
56 | |
56 | |
57 | ///////////////////////////////////////////////////////////////////////////// |
57 | ///////////////////////////////////////////////////////////////////////////// |
58 | |
|
|
59 | static SV * |
|
|
60 | taint (SV *sv) |
|
|
61 | { |
|
|
62 | SvTAINT (sv); |
|
|
63 | return sv; |
|
|
64 | } |
|
|
65 | |
|
|
66 | static SV * |
|
|
67 | taint_if (SV *sv, SV *src) |
|
|
68 | { |
|
|
69 | if (SvTAINTED (src)) |
|
|
70 | SvTAINT (sv); |
|
|
71 | |
|
|
72 | return sv; |
|
|
73 | } |
|
|
74 | |
58 | |
75 | static wchar_t * |
59 | static wchar_t * |
76 | sv2wcs (SV *sv) |
60 | sv2wcs (SV *sv) |
77 | { |
61 | { |
78 | STRLEN len; |
62 | STRLEN len; |
… | |
… | |
349 | for (int y = ov_h; y--; ) |
333 | for (int y = ov_h; y--; ) |
350 | { |
334 | { |
351 | text_t *t1 = text [y]; |
335 | text_t *t1 = text [y]; |
352 | rend_t *r1 = rend [y]; |
336 | rend_t *r1 = rend [y]; |
353 | |
337 | |
354 | text_t *t2 = ROW(y + ov_y - THIS->view_start).t + ov_x; |
338 | text_t *t2 = ROW(y + ov_y + THIS->view_start).t + ov_x; |
355 | rend_t *r2 = ROW(y + ov_y - THIS->view_start).r + ov_x; |
339 | rend_t *r2 = ROW(y + ov_y + THIS->view_start).r + ov_x; |
356 | |
340 | |
357 | for (int x = ov_w; x--; ) |
341 | for (int x = ov_w; x--; ) |
358 | { |
342 | { |
359 | text_t t = *t1; *t1++ = *t2; *t2++ = t; |
343 | text_t t = *t1; *t1++ = *t2; *t2++ = t; |
360 | rend_t r = *r1; *r1++ = *r2; *r2++ = SET_FONT (r, THIS->fontset [GET_STYLE (r)]->find_font (t)); |
344 | rend_t r = *r1; *r1++ = *r2; *r2++ = SET_FONT (r, THIS->fontset [GET_STYLE (r)]->find_font (t)); |
… | |
… | |
407 | perl_free (perl); |
391 | perl_free (perl); |
408 | } |
392 | } |
409 | } |
393 | } |
410 | |
394 | |
411 | void |
395 | void |
412 | rxvt_perl_interp::init () |
396 | rxvt_perl_interp::init (rxvt_term *term) |
413 | { |
397 | { |
414 | if (!perl) |
398 | if (!perl) |
415 | { |
399 | { |
|
|
400 | rxvt_push_locale (""); // perl init destroys current locale |
|
|
401 | |
416 | perl_environ = rxvt_environ; |
402 | perl_environ = rxvt_environ; |
417 | swap (perl_environ, environ); |
403 | swap (perl_environ, environ); |
418 | |
404 | |
419 | char *argv[] = { |
405 | char *argv[] = { |
420 | "", |
406 | "", |
421 | "-T", |
407 | "-e" |
422 | "-edo '" LIBDIR "/urxvt.pm' or ($@ and die $@) or exit 1", |
408 | "BEGIN {" |
|
|
409 | " urxvt->bootstrap;" |
|
|
410 | " unshift @INC, '" LIBDIR "';" |
|
|
411 | "}" |
|
|
412 | "" |
|
|
413 | "use urxvt;" |
423 | }; |
414 | }; |
424 | |
415 | |
425 | perl = perl_alloc (); |
416 | perl = perl_alloc (); |
426 | perl_construct (perl); |
417 | perl_construct (perl); |
427 | |
418 | |
428 | if (perl_parse (perl, xs_init, 3, argv, (char **)NULL) |
419 | if (perl_parse (perl, xs_init, 2, argv, (char **)NULL) |
429 | || perl_run (perl)) |
420 | || perl_run (perl)) |
430 | { |
421 | { |
431 | rxvt_warn ("unable to initialize perl-interpreter, continuing without.\n"); |
422 | rxvt_warn ("unable to initialize perl-interpreter, continuing without.\n"); |
432 | |
423 | |
433 | perl_destruct (perl); |
424 | perl_destruct (perl); |
434 | perl_free (perl); |
425 | perl_free (perl); |
435 | perl = 0; |
426 | perl = 0; |
436 | } |
427 | } |
437 | |
428 | |
438 | swap (perl_environ, environ); |
429 | swap (perl_environ, environ); |
|
|
430 | |
|
|
431 | rxvt_pop_locale (); |
|
|
432 | } |
|
|
433 | |
|
|
434 | if (perl) |
|
|
435 | { |
|
|
436 | // runs outside of perls ENV |
|
|
437 | term->perl.self = (void *)newSVptr ((void *)term, "urxvt::term"); |
|
|
438 | hv_store ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, newRV_noinc ((SV *)newHV ()), 0); |
439 | } |
439 | } |
440 | } |
440 | } |
441 | |
441 | |
442 | static void |
442 | static void |
443 | ungrab (rxvt_term *THIS) |
443 | ungrab (rxvt_term *THIS) |
… | |
… | |
448 | XUngrabPointer (THIS->display->display, THIS->perl.grabtime); |
448 | XUngrabPointer (THIS->display->display, THIS->perl.grabtime); |
449 | THIS->perl.grabtime = 0; |
449 | THIS->perl.grabtime = 0; |
450 | } |
450 | } |
451 | } |
451 | } |
452 | |
452 | |
|
|
453 | static void |
|
|
454 | swap_overlays (rxvt_term *term) |
|
|
455 | { |
|
|
456 | HV *hv = (HV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, 0)); |
|
|
457 | |
|
|
458 | if (HvKEYS (hv)) |
|
|
459 | { |
|
|
460 | hv_iterinit (hv); |
|
|
461 | |
|
|
462 | while (HE *he = hv_iternext (hv)) |
|
|
463 | ((overlay *)SvIV (hv_iterval (hv, he)))->swap (); |
|
|
464 | } |
|
|
465 | } |
|
|
466 | |
453 | bool |
467 | bool |
454 | rxvt_perl_interp::invoke (rxvt_term *term, hook_type htype, ...) |
468 | rxvt_perl_interp::invoke (rxvt_term *term, hook_type htype, ...) |
455 | { |
469 | { |
456 | if (!perl) |
470 | if (!perl || !term->perl.self) |
457 | return false; |
471 | return false; |
458 | |
472 | |
459 | if (htype == HOOK_INIT) // first hook ever called |
473 | // pre-handling of some events |
|
|
474 | if (htype == HOOK_REFRESH_END) |
|
|
475 | swap_overlays (term); |
|
|
476 | |
|
|
477 | swap (perl_environ, environ); |
|
|
478 | |
|
|
479 | bool event_consumed; |
|
|
480 | |
|
|
481 | if (htype == HOOK_INIT || htype == HOOK_DESTROY // must be called always |
|
|
482 | || term->perl.should_invoke [htype]) |
|
|
483 | try |
460 | { |
484 | { |
461 | term->perl.self = (void *)newSVptr ((void *)term, "urxvt::term"); |
485 | dSP; |
462 | hv_store ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, newRV_noinc ((SV *)newHV ()), 0); |
486 | va_list ap; |
|
|
487 | |
|
|
488 | va_start (ap, htype); |
|
|
489 | |
|
|
490 | ENTER; |
|
|
491 | SAVETMPS; |
|
|
492 | |
|
|
493 | PUSHMARK (SP); |
|
|
494 | |
|
|
495 | XPUSHs (sv_2mortal (newSVterm (term))); |
|
|
496 | XPUSHs (sv_2mortal (newSViv (htype))); |
|
|
497 | |
|
|
498 | for (;;) { |
|
|
499 | data_type dt = (data_type)va_arg (ap, int); |
|
|
500 | |
|
|
501 | switch (dt) |
|
|
502 | { |
|
|
503 | case DT_INT: |
|
|
504 | XPUSHs (sv_2mortal (newSViv (va_arg (ap, int)))); |
|
|
505 | break; |
|
|
506 | |
|
|
507 | case DT_LONG: |
|
|
508 | XPUSHs (sv_2mortal (newSViv (va_arg (ap, long)))); |
|
|
509 | break; |
|
|
510 | |
|
|
511 | case DT_STR: |
|
|
512 | XPUSHs (sv_2mortal (newSVpv (va_arg (ap, char *), 0))); |
|
|
513 | break; |
|
|
514 | |
|
|
515 | case DT_STR_LEN: |
|
|
516 | { |
|
|
517 | char *str = va_arg (ap, char *); |
|
|
518 | int len = va_arg (ap, int); |
|
|
519 | |
|
|
520 | XPUSHs (sv_2mortal (newSVpvn (str, len))); |
|
|
521 | } |
|
|
522 | break; |
|
|
523 | |
|
|
524 | case DT_WCS_LEN: |
|
|
525 | { |
|
|
526 | wchar_t *wstr = va_arg (ap, wchar_t *); |
|
|
527 | int wlen = va_arg (ap, int); |
|
|
528 | |
|
|
529 | XPUSHs (sv_2mortal (wcs2sv (wstr, wlen))); |
|
|
530 | } |
|
|
531 | break; |
|
|
532 | |
|
|
533 | case DT_XEVENT: |
|
|
534 | { |
|
|
535 | XEvent *xe = va_arg (ap, XEvent *); |
|
|
536 | HV *hv = newHV (); |
|
|
537 | |
|
|
538 | # 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) |
|
|
540 | # define setuv(name, val) hv_store (hv, # name, sizeof (# name) - 1, newSVuv (val), 0) |
|
|
541 | # undef set |
|
|
542 | |
|
|
543 | setiv (type, xe->type); |
|
|
544 | setiv (send_event, xe->xany.send_event); |
|
|
545 | setiv (serial, xe->xany.serial); |
|
|
546 | |
|
|
547 | switch (xe->type) |
|
|
548 | { |
|
|
549 | case KeyPress: |
|
|
550 | case KeyRelease: |
|
|
551 | case ButtonPress: |
|
|
552 | case ButtonRelease: |
|
|
553 | case MotionNotify: |
|
|
554 | setuv (window, xe->xmotion.window); |
|
|
555 | setuv (root, xe->xmotion.root); |
|
|
556 | setuv (subwindow, xe->xmotion.subwindow); |
|
|
557 | setuv (time, xe->xmotion.time); |
|
|
558 | setiv (x, xe->xmotion.x); |
|
|
559 | setiv (y, xe->xmotion.y); |
|
|
560 | setiv (row, xe->xmotion.y / term->fheight); |
|
|
561 | setiv (col, xe->xmotion.x / term->fwidth); |
|
|
562 | setiv (x_root, xe->xmotion.x_root); |
|
|
563 | setiv (y_root, xe->xmotion.y_root); |
|
|
564 | setuv (state, xe->xmotion.state); |
|
|
565 | |
|
|
566 | switch (xe->type) |
|
|
567 | { |
|
|
568 | case KeyPress: |
|
|
569 | case KeyRelease: |
|
|
570 | setuv (keycode, xe->xkey.keycode); |
|
|
571 | break; |
|
|
572 | |
|
|
573 | case ButtonPress: |
|
|
574 | case ButtonRelease: |
|
|
575 | setuv (button, xe->xbutton.button); |
|
|
576 | break; |
|
|
577 | |
|
|
578 | case MotionNotify: |
|
|
579 | setiv (is_hint, xe->xmotion.is_hint); |
|
|
580 | break; |
|
|
581 | } |
|
|
582 | |
|
|
583 | break; |
|
|
584 | |
|
|
585 | case MapNotify: |
|
|
586 | case UnmapNotify: |
|
|
587 | case ConfigureNotify: |
|
|
588 | setuv (event, xe->xconfigure.event); |
|
|
589 | setuv (window, xe->xconfigure.window); |
|
|
590 | |
|
|
591 | switch (xe->type) |
|
|
592 | { |
|
|
593 | case ConfigureNotify: |
|
|
594 | setiv (x, xe->xconfigure.x); |
|
|
595 | setiv (y, xe->xconfigure.y); |
|
|
596 | setiv (width, xe->xconfigure.width); |
|
|
597 | setiv (height, xe->xconfigure.height); |
|
|
598 | setuv (above, xe->xconfigure.above); |
|
|
599 | break; |
|
|
600 | } |
|
|
601 | |
|
|
602 | break; |
|
|
603 | } |
|
|
604 | |
|
|
605 | XPUSHs (sv_2mortal (newRV_noinc ((SV *)hv))); |
|
|
606 | } |
|
|
607 | break; |
|
|
608 | |
|
|
609 | case DT_END: |
|
|
610 | goto call; |
|
|
611 | |
|
|
612 | default: |
|
|
613 | rxvt_fatal ("FATAL: unable to pass data type %d\n", dt); |
|
|
614 | } |
|
|
615 | } |
|
|
616 | |
|
|
617 | call: |
|
|
618 | va_end (ap); |
|
|
619 | |
|
|
620 | PUTBACK; |
|
|
621 | int count = call_pv ("urxvt::invoke", G_ARRAY | G_EVAL); |
|
|
622 | SPAGAIN; |
|
|
623 | |
|
|
624 | if (count) |
|
|
625 | { |
|
|
626 | SV *status = POPs; |
|
|
627 | count = SvTRUE (status); |
|
|
628 | } |
|
|
629 | |
|
|
630 | PUTBACK; |
|
|
631 | FREETMPS; |
|
|
632 | LEAVE; |
|
|
633 | |
|
|
634 | if (SvTRUE (ERRSV)) |
|
|
635 | { |
|
|
636 | rxvt_warn ("perl hook %d evaluation error: %s", htype, SvPV_nolen (ERRSV)); |
|
|
637 | ungrab (term); // better lose the grab than the session |
|
|
638 | } |
|
|
639 | |
|
|
640 | event_consumed = !!count; |
463 | } |
641 | } |
464 | else if (!term->perl.self) |
642 | catch (...) |
465 | return false; // perl not initialized for this instance |
643 | { |
|
|
644 | swap (perl_environ, environ); |
|
|
645 | throw; |
|
|
646 | } |
|
|
647 | else |
|
|
648 | event_consumed = false; |
|
|
649 | |
|
|
650 | // post-handling of some events |
|
|
651 | if (htype == HOOK_REFRESH_BEGIN) |
|
|
652 | swap_overlays (term); |
466 | else if (htype == HOOK_DESTROY) |
653 | else if (htype == HOOK_DESTROY) |
467 | { |
654 | { |
468 | // handled later |
655 | clearSVptr ((SV *)term->perl.self); |
|
|
656 | SvREFCNT_dec ((SV *)term->perl.self); |
469 | } |
657 | } |
470 | else |
|
|
471 | { |
|
|
472 | if (htype == HOOK_REFRESH_BEGIN || htype == HOOK_REFRESH_END) |
|
|
473 | { |
|
|
474 | HV *hv = (HV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, 0)); |
|
|
475 | |
|
|
476 | if (HvKEYS (hv)) |
|
|
477 | { |
|
|
478 | hv_iterinit (hv); |
|
|
479 | |
|
|
480 | while (HE *he = hv_iternext (hv)) |
|
|
481 | ((overlay *)SvIV (hv_iterval (hv, he)))->swap (); |
|
|
482 | } |
|
|
483 | |
|
|
484 | } |
|
|
485 | |
|
|
486 | if (!term->perl.should_invoke [htype]) |
|
|
487 | return false; |
|
|
488 | } |
|
|
489 | |
658 | |
490 | swap (perl_environ, environ); |
659 | swap (perl_environ, environ); |
491 | |
660 | |
492 | try |
661 | return event_consumed; |
493 | { |
|
|
494 | dSP; |
|
|
495 | va_list ap; |
|
|
496 | |
|
|
497 | va_start (ap, htype); |
|
|
498 | |
|
|
499 | ENTER; |
|
|
500 | SAVETMPS; |
|
|
501 | |
|
|
502 | PUSHMARK (SP); |
|
|
503 | |
|
|
504 | XPUSHs (sv_2mortal (newSVterm (term))); |
|
|
505 | XPUSHs (sv_2mortal (newSViv (htype))); |
|
|
506 | |
|
|
507 | for (;;) { |
|
|
508 | data_type dt = (data_type)va_arg (ap, int); |
|
|
509 | |
|
|
510 | switch (dt) |
|
|
511 | { |
|
|
512 | case DT_INT: |
|
|
513 | XPUSHs (sv_2mortal (newSViv (va_arg (ap, int)))); |
|
|
514 | break; |
|
|
515 | |
|
|
516 | case DT_LONG: |
|
|
517 | XPUSHs (sv_2mortal (newSViv (va_arg (ap, long)))); |
|
|
518 | break; |
|
|
519 | |
|
|
520 | case DT_STR: |
|
|
521 | XPUSHs (taint (sv_2mortal (newSVpv (va_arg (ap, char *), 0)))); |
|
|
522 | break; |
|
|
523 | |
|
|
524 | case DT_STR_LEN: |
|
|
525 | { |
|
|
526 | char *str = va_arg (ap, char *); |
|
|
527 | int len = va_arg (ap, int); |
|
|
528 | |
|
|
529 | XPUSHs (taint (sv_2mortal (newSVpvn (str, len)))); |
|
|
530 | } |
|
|
531 | break; |
|
|
532 | |
|
|
533 | case DT_WCS_LEN: |
|
|
534 | { |
|
|
535 | wchar_t *wstr = va_arg (ap, wchar_t *); |
|
|
536 | int wlen = va_arg (ap, int); |
|
|
537 | |
|
|
538 | XPUSHs (taint (sv_2mortal (wcs2sv (wstr, wlen)))); |
|
|
539 | } |
|
|
540 | break; |
|
|
541 | |
|
|
542 | case DT_XEVENT: |
|
|
543 | { |
|
|
544 | XEvent *xe = va_arg (ap, XEvent *); |
|
|
545 | HV *hv = newHV (); |
|
|
546 | |
|
|
547 | # define set(name, sv) hv_store (hv, # name, sizeof (# name) - 1, sv, 0) |
|
|
548 | # define setiv(name, val) hv_store (hv, # name, sizeof (# name) - 1, newSViv (val), 0) |
|
|
549 | # undef set |
|
|
550 | |
|
|
551 | setiv (type, xe->type); |
|
|
552 | setiv (send_event, xe->xany.send_event); |
|
|
553 | setiv (serial, xe->xany.serial); |
|
|
554 | |
|
|
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: |
|
|
595 | { |
|
|
596 | va_end (ap); |
|
|
597 | |
|
|
598 | PUTBACK; |
|
|
599 | int count = call_pv ("urxvt::invoke", G_ARRAY | G_EVAL); |
|
|
600 | SPAGAIN; |
|
|
601 | |
|
|
602 | if (count) |
|
|
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; |
|
|
626 | } |
|
|
627 | |
|
|
628 | default: |
|
|
629 | rxvt_fatal ("FATAL: unable to pass data type %d\n", dt); |
|
|
630 | } |
|
|
631 | } |
|
|
632 | } |
|
|
633 | catch (...) |
|
|
634 | { |
|
|
635 | swap (perl_environ, environ); |
|
|
636 | throw; |
|
|
637 | } |
|
|
638 | } |
662 | } |
639 | |
663 | |
640 | ///////////////////////////////////////////////////////////////////////////// |
664 | ///////////////////////////////////////////////////////////////////////////// |
641 | |
665 | |
642 | MODULE = urxvt PACKAGE = urxvt |
666 | MODULE = urxvt PACKAGE = urxvt |
… | |
… | |
771 | void |
795 | void |
772 | fatal (const char *msg) |
796 | fatal (const char *msg) |
773 | CODE: |
797 | CODE: |
774 | rxvt_fatal ("%s", msg); |
798 | rxvt_fatal ("%s", msg); |
775 | |
799 | |
776 | SV * |
|
|
777 | untaint (SV *sv) |
|
|
778 | CODE: |
|
|
779 | RETVAL = newSVsv (sv); |
|
|
780 | SvTAINTED_off (RETVAL); |
|
|
781 | OUTPUT: |
|
|
782 | RETVAL |
|
|
783 | |
|
|
784 | void |
800 | void |
785 | _exit (int status) |
801 | _exit (int status) |
786 | |
|
|
787 | bool |
|
|
788 | safe () |
|
|
789 | CODE: |
|
|
790 | RETVAL = !rxvt_tainted (); |
|
|
791 | OUTPUT: |
|
|
792 | RETVAL |
|
|
793 | |
802 | |
794 | NV |
803 | NV |
795 | NOW () |
804 | NOW () |
796 | CODE: |
805 | CODE: |
797 | RETVAL = NOW; |
806 | RETVAL = NOW; |
… | |
… | |
968 | RETVAL |
977 | RETVAL |
969 | |
978 | |
970 | void |
979 | void |
971 | rxvt_term::XReparentWindow (U32 window, U32 parent, int x = 0, int y = 0) |
980 | rxvt_term::XReparentWindow (U32 window, U32 parent, int x = 0, int y = 0) |
972 | CODE: |
981 | CODE: |
973 | XReparentWindow (THIS->display->display, window, parent, x, y); |
982 | XReparentWindow (THIS->display->display, (Window)window, (Window)parent, x, y); |
|
|
983 | |
|
|
984 | void |
|
|
985 | rxvt_term::XMapWindow (U32 window) |
|
|
986 | CODE: |
|
|
987 | XMapWindow (THIS->display->display, (Window)window); |
|
|
988 | |
|
|
989 | void |
|
|
990 | rxvt_term::XUnmapWindow (U32 window) |
|
|
991 | CODE: |
|
|
992 | XUnmapWindow (THIS->display->display, (Window)window); |
974 | |
993 | |
975 | #endif |
994 | #endif |
976 | |
995 | |
977 | void |
996 | void |
978 | rxvt_term::set_should_invoke (int htype, int inc) |
997 | rxvt_term::set_should_invoke (int htype, int inc) |
… | |
… | |
1053 | char *mbstr = rxvt_wcstombs (wstr); |
1072 | char *mbstr = rxvt_wcstombs (wstr); |
1054 | rxvt_pop_locale (); |
1073 | rxvt_pop_locale (); |
1055 | |
1074 | |
1056 | free (wstr); |
1075 | free (wstr); |
1057 | |
1076 | |
1058 | RETVAL = taint_if (newSVpv (mbstr, 0), str); |
1077 | RETVAL = newSVpv (mbstr, 0); |
1059 | free (mbstr); |
1078 | free (mbstr); |
1060 | } |
1079 | } |
1061 | OUTPUT: |
1080 | OUTPUT: |
1062 | RETVAL |
1081 | RETVAL |
1063 | |
1082 | |
… | |
… | |
1070 | |
1089 | |
1071 | rxvt_push_locale (THIS->locale); |
1090 | rxvt_push_locale (THIS->locale); |
1072 | wchar_t *wstr = rxvt_mbstowcs (data, len); |
1091 | wchar_t *wstr = rxvt_mbstowcs (data, len); |
1073 | rxvt_pop_locale (); |
1092 | rxvt_pop_locale (); |
1074 | |
1093 | |
1075 | RETVAL = taint_if (wcs2sv (wstr), octets); |
1094 | RETVAL = wcs2sv (wstr); |
1076 | free (wstr); |
1095 | free (wstr); |
1077 | } |
1096 | } |
1078 | OUTPUT: |
1097 | OUTPUT: |
1079 | RETVAL |
1098 | RETVAL |
1080 | |
1099 | |
… | |
… | |
1089 | #define TERM_OFFSET_ncol TERM_OFFSET(ncol) |
1108 | #define TERM_OFFSET_ncol TERM_OFFSET(ncol) |
1090 | #define TERM_OFFSET_focus TERM_OFFSET(focus) |
1109 | #define TERM_OFFSET_focus TERM_OFFSET(focus) |
1091 | #define TERM_OFFSET_mapped TERM_OFFSET(mapped) |
1110 | #define TERM_OFFSET_mapped TERM_OFFSET(mapped) |
1092 | #define TERM_OFFSET_saveLines TERM_OFFSET(saveLines) |
1111 | #define TERM_OFFSET_saveLines TERM_OFFSET(saveLines) |
1093 | #define TERM_OFFSET_total_rows TERM_OFFSET(total_rows) |
1112 | #define TERM_OFFSET_total_rows TERM_OFFSET(total_rows) |
1094 | #define TERM_OFFSET_nsaved TERM_OFFSET(nsaved) |
1113 | #define TERM_OFFSET_top_row TERM_OFFSET(top_row) |
1095 | |
1114 | |
1096 | int |
1115 | int |
1097 | rxvt_term::width () |
1116 | rxvt_term::width () |
1098 | ALIAS: |
1117 | ALIAS: |
1099 | width = TERM_OFFSET_width |
1118 | width = TERM_OFFSET_width |
… | |
… | |
1105 | ncol = TERM_OFFSET_ncol |
1124 | ncol = TERM_OFFSET_ncol |
1106 | focus = TERM_OFFSET_focus |
1125 | focus = TERM_OFFSET_focus |
1107 | mapped = TERM_OFFSET_mapped |
1126 | mapped = TERM_OFFSET_mapped |
1108 | saveLines = TERM_OFFSET_saveLines |
1127 | saveLines = TERM_OFFSET_saveLines |
1109 | total_rows = TERM_OFFSET_total_rows |
1128 | total_rows = TERM_OFFSET_total_rows |
1110 | nsaved = TERM_OFFSET_nsaved |
1129 | top_row = TERM_OFFSET_top_row |
1111 | CODE: |
1130 | CODE: |
1112 | RETVAL = *(int *)((char *)THIS + ix); |
1131 | RETVAL = *(int *)((char *)THIS + ix); |
1113 | OUTPUT: |
1132 | OUTPUT: |
1114 | RETVAL |
1133 | RETVAL |
1115 | |
1134 | |
… | |
… | |
1199 | THIS->rstyle = new_rstyle; |
1218 | THIS->rstyle = new_rstyle; |
1200 | OUTPUT: |
1219 | OUTPUT: |
1201 | RETVAL |
1220 | RETVAL |
1202 | |
1221 | |
1203 | int |
1222 | int |
1204 | rxvt_term::view_start (int newval = -1) |
1223 | rxvt_term::view_start (int newval = 1) |
1205 | PROTOTYPE: $;$ |
1224 | PROTOTYPE: $;$ |
1206 | CODE: |
1225 | CODE: |
1207 | { |
1226 | { |
1208 | RETVAL = THIS->view_start; |
1227 | RETVAL = THIS->view_start; |
1209 | |
1228 | |
1210 | if (newval >= 0) |
1229 | if (newval <= 0) |
1211 | { |
1230 | THIS->scr_changeview (max (newval, THIS->top_row)); |
1212 | THIS->view_start = min (newval, THIS->nsaved); |
|
|
1213 | THIS->scr_changeview (RETVAL); |
|
|
1214 | } |
|
|
1215 | } |
1231 | } |
1216 | OUTPUT: |
1232 | OUTPUT: |
1217 | RETVAL |
1233 | RETVAL |
1218 | |
1234 | |
1219 | void |
1235 | void |
… | |
… | |
1223 | |
1239 | |
1224 | void |
1240 | void |
1225 | rxvt_term::ROW_t (int row_number, SV *new_text = 0, int start_col = 0, int start_ofs = 0, int max_len = MAX_COLS) |
1241 | rxvt_term::ROW_t (int row_number, SV *new_text = 0, int start_col = 0, int start_ofs = 0, int max_len = MAX_COLS) |
1226 | PPCODE: |
1242 | PPCODE: |
1227 | { |
1243 | { |
1228 | if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) |
1244 | if (!IN_RANGE_EXC (row_number, THIS->top_row, THIS->nrow)) |
1229 | XSRETURN_EMPTY; |
1245 | XSRETURN_EMPTY; |
1230 | |
1246 | |
1231 | line_t &l = ROW(row_number); |
1247 | line_t &l = ROW(row_number); |
1232 | |
1248 | |
1233 | if (GIMME_V != G_VOID) |
1249 | if (GIMME_V != G_VOID) |
… | |
… | |
1235 | wchar_t *wstr = new wchar_t [THIS->ncol]; |
1251 | wchar_t *wstr = new wchar_t [THIS->ncol]; |
1236 | |
1252 | |
1237 | for (int col = 0; col < THIS->ncol; col++) |
1253 | for (int col = 0; col < THIS->ncol; col++) |
1238 | wstr [col] = l.t [col]; |
1254 | wstr [col] = l.t [col]; |
1239 | |
1255 | |
1240 | XPUSHs (taint (sv_2mortal (wcs2sv (wstr, THIS->ncol)))); |
1256 | XPUSHs (sv_2mortal (wcs2sv (wstr, THIS->ncol))); |
1241 | |
1257 | |
1242 | delete [] wstr; |
1258 | delete [] wstr; |
1243 | } |
1259 | } |
1244 | |
1260 | |
1245 | if (new_text) |
1261 | if (new_text) |
… | |
… | |
1266 | |
1282 | |
1267 | void |
1283 | void |
1268 | rxvt_term::ROW_r (int row_number, SV *new_rend = 0, int start_col = 0, int start_ofs = 0, int max_len = MAX_COLS) |
1284 | rxvt_term::ROW_r (int row_number, SV *new_rend = 0, int start_col = 0, int start_ofs = 0, int max_len = MAX_COLS) |
1269 | PPCODE: |
1285 | PPCODE: |
1270 | { |
1286 | { |
1271 | if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) |
1287 | if (!IN_RANGE_EXC (row_number, THIS->top_row, THIS->nrow)) |
1272 | XSRETURN_EMPTY; |
1288 | XSRETURN_EMPTY; |
1273 | |
1289 | |
1274 | line_t &l = ROW(row_number); |
1290 | line_t &l = ROW(row_number); |
1275 | |
1291 | |
1276 | if (GIMME_V != G_VOID) |
1292 | if (GIMME_V != G_VOID) |
… | |
… | |
1306 | |
1322 | |
1307 | int |
1323 | int |
1308 | rxvt_term::ROW_l (int row_number, int new_length = -1) |
1324 | rxvt_term::ROW_l (int row_number, int new_length = -1) |
1309 | CODE: |
1325 | CODE: |
1310 | { |
1326 | { |
1311 | if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) |
1327 | if (!IN_RANGE_EXC (row_number, THIS->top_row, THIS->nrow)) |
1312 | XSRETURN_EMPTY; |
1328 | XSRETURN_EMPTY; |
1313 | |
1329 | |
1314 | line_t &l = ROW(row_number); |
1330 | line_t &l = ROW(row_number); |
1315 | RETVAL = l.l; |
1331 | RETVAL = l.l; |
1316 | |
1332 | |
… | |
… | |
1322 | |
1338 | |
1323 | bool |
1339 | bool |
1324 | rxvt_term::ROW_is_longer (int row_number, int new_is_longer = -1) |
1340 | rxvt_term::ROW_is_longer (int row_number, int new_is_longer = -1) |
1325 | CODE: |
1341 | CODE: |
1326 | { |
1342 | { |
1327 | if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) |
1343 | if (!IN_RANGE_EXC (row_number, THIS->top_row, THIS->nrow)) |
1328 | XSRETURN_EMPTY; |
1344 | XSRETURN_EMPTY; |
1329 | |
1345 | |
1330 | line_t &l = ROW(row_number); |
1346 | line_t &l = ROW(row_number); |
1331 | RETVAL = l.is_longer (); |
1347 | RETVAL = l.is_longer (); |
1332 | |
1348 | |
… | |
… | |
1366 | else |
1382 | else |
1367 | *r++ = *s; |
1383 | *r++ = *s; |
1368 | |
1384 | |
1369 | rxvt_pop_locale (); |
1385 | rxvt_pop_locale (); |
1370 | |
1386 | |
1371 | RETVAL = taint_if (wcs2sv (rstr, r - rstr), string); |
1387 | RETVAL = wcs2sv (rstr, r - rstr); |
1372 | |
1388 | |
1373 | delete [] rstr; |
1389 | delete [] rstr; |
1374 | } |
1390 | } |
1375 | OUTPUT: |
1391 | OUTPUT: |
1376 | RETVAL |
1392 | RETVAL |
… | |
… | |
1402 | else if (IS_COMPOSE (*s)) |
1418 | else if (IS_COMPOSE (*s)) |
1403 | r += rxvt_composite.expand (*s, r); |
1419 | r += rxvt_composite.expand (*s, r); |
1404 | else |
1420 | else |
1405 | *r++ = *s; |
1421 | *r++ = *s; |
1406 | |
1422 | |
1407 | RETVAL = taint_if (wcs2sv (rstr, r - rstr), text); |
1423 | RETVAL = wcs2sv (rstr, r - rstr); |
1408 | |
1424 | |
1409 | delete [] rstr; |
1425 | delete [] rstr; |
1410 | } |
1426 | } |
1411 | OUTPUT: |
1427 | OUTPUT: |
1412 | RETVAL |
1428 | RETVAL |
… | |
… | |
1434 | |
1450 | |
1435 | if (!IN_RANGE_EXC (index, 0, NUM_RESOURCES)) |
1451 | if (!IN_RANGE_EXC (index, 0, NUM_RESOURCES)) |
1436 | croak ("requested out-of-bound resource %s+%d,", name, index - rs->value); |
1452 | croak ("requested out-of-bound resource %s+%d,", name, index - rs->value); |
1437 | |
1453 | |
1438 | if (GIMME_V != G_VOID) |
1454 | if (GIMME_V != G_VOID) |
1439 | XPUSHs (THIS->rs [index] ? sv_2mortal (taint (newSVpv (THIS->rs [index], 0))) : &PL_sv_undef); |
1455 | XPUSHs (THIS->rs [index] ? sv_2mortal (newSVpv (THIS->rs [index], 0)) : &PL_sv_undef); |
1440 | |
1456 | |
1441 | if (newval) |
1457 | if (newval) |
1442 | { |
1458 | { |
1443 | if (SvOK (newval)) |
1459 | if (SvOK (newval)) |
1444 | { |
1460 | { |
… | |
… | |
1451 | } |
1467 | } |
1452 | } |
1468 | } |
1453 | |
1469 | |
1454 | const char * |
1470 | const char * |
1455 | rxvt_term::x_resource (const char *name) |
1471 | rxvt_term::x_resource (const char *name) |
1456 | CLEANUP: |
|
|
1457 | SvTAINTED_on (ST (0)); |
|
|
1458 | |
1472 | |
1459 | bool |
1473 | bool |
1460 | rxvt_term::option (U32 optval, int set = -1) |
1474 | rxvt_term::option (U32 optval, int set = -1) |
1461 | CODE: |
1475 | CODE: |
1462 | { |
1476 | { |
… | |
… | |
1522 | PUSHs (sv_2mortal (newSViv (rc.col))); |
1536 | PUSHs (sv_2mortal (newSViv (rc.col))); |
1523 | } |
1537 | } |
1524 | |
1538 | |
1525 | if (items == 3) |
1539 | if (items == 3) |
1526 | { |
1540 | { |
1527 | rc.row = clamp (SvIV (ST (1)), -THIS->nsaved, THIS->nrow - 1); |
1541 | rc.row = SvIV (ST (1)); |
1528 | rc.col = clamp (SvIV (ST (2)), 0, THIS->ncol - 1); |
1542 | rc.col = SvIV (ST (2)); |
|
|
1543 | |
|
|
1544 | if (ix == 2 && rc.col == 0) |
|
|
1545 | { |
|
|
1546 | rc.row--; |
|
|
1547 | rc.col = THIS->ncol; |
|
|
1548 | } |
|
|
1549 | |
|
|
1550 | clamp_it (rc.col, 0, THIS->ncol); |
|
|
1551 | clamp_it (rc.row, THIS->top_row, THIS->nrow - 1); |
1529 | |
1552 | |
1530 | if (ix) |
1553 | if (ix) |
1531 | THIS->want_refresh = 1; |
1554 | THIS->want_refresh = 1; |
1532 | } |
1555 | } |
1533 | } |
1556 | } |
… | |
… | |
1556 | rxvt_term::selection (SV *newtext = 0) |
1579 | rxvt_term::selection (SV *newtext = 0) |
1557 | PPCODE: |
1580 | PPCODE: |
1558 | { |
1581 | { |
1559 | if (GIMME_V != G_VOID) |
1582 | if (GIMME_V != G_VOID) |
1560 | XPUSHs (THIS->selection.text |
1583 | XPUSHs (THIS->selection.text |
1561 | ? taint (sv_2mortal (wcs2sv (THIS->selection.text, THIS->selection.len))) |
1584 | ? sv_2mortal (wcs2sv (THIS->selection.text, THIS->selection.len)) |
1562 | : &PL_sv_undef); |
1585 | : &PL_sv_undef); |
1563 | |
1586 | |
1564 | if (newtext) |
1587 | if (newtext) |
1565 | { |
1588 | { |
1566 | free (THIS->selection.text); |
1589 | free (THIS->selection.text); |