… | |
… | |
29 | #include "../config.h" |
29 | #include "../config.h" |
30 | |
30 | |
31 | #include <cstddef> |
31 | #include <cstddef> |
32 | #include <cstdarg> |
32 | #include <cstdarg> |
33 | |
33 | |
|
|
34 | #include "unistd.h" |
|
|
35 | |
|
|
36 | #include "iom.h" |
34 | #include "rxvt.h" |
37 | #include "rxvt.h" |
35 | #include "iom.h" |
38 | #include "keyboard.h" |
36 | #include "rxvtutil.h" |
39 | #include "rxvtutil.h" |
37 | #include "rxvtperl.h" |
40 | #include "rxvtperl.h" |
38 | |
41 | |
39 | #include "perlxsi.c" |
42 | #include "perlxsi.c" |
40 | |
43 | |
… | |
… | |
48 | #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) |
49 | #undef ROW |
52 | #undef ROW |
50 | #define ROW(n) THIS->row_buf [LINENO (n)] |
53 | #define ROW(n) THIS->row_buf [LINENO (n)] |
51 | |
54 | |
52 | ///////////////////////////////////////////////////////////////////////////// |
55 | ///////////////////////////////////////////////////////////////////////////// |
|
|
56 | |
|
|
57 | static SV * |
|
|
58 | taint (SV *sv) |
|
|
59 | { |
|
|
60 | SvTAINT (sv); |
|
|
61 | return sv; |
|
|
62 | } |
|
|
63 | |
|
|
64 | static SV * |
|
|
65 | taint_if (SV *sv, SV *src) |
|
|
66 | { |
|
|
67 | if (SvTAINTED (src)) |
|
|
68 | SvTAINT (sv); |
|
|
69 | |
|
|
70 | return sv; |
|
|
71 | } |
53 | |
72 | |
54 | static wchar_t * |
73 | static wchar_t * |
55 | sv2wcs (SV *sv) |
74 | sv2wcs (SV *sv) |
56 | { |
75 | { |
57 | STRLEN len; |
76 | STRLEN len; |
… | |
… | |
376 | |
395 | |
377 | struct rxvt_perl_interp rxvt_perl; |
396 | struct rxvt_perl_interp rxvt_perl; |
378 | |
397 | |
379 | static PerlInterpreter *perl; |
398 | static PerlInterpreter *perl; |
380 | |
399 | |
381 | rxvt_perl_interp::rxvt_perl_interp () |
|
|
382 | { |
|
|
383 | } |
|
|
384 | |
|
|
385 | rxvt_perl_interp::~rxvt_perl_interp () |
400 | rxvt_perl_interp::~rxvt_perl_interp () |
386 | { |
401 | { |
387 | if (perl) |
402 | if (perl) |
388 | { |
403 | { |
389 | perl_destruct (perl); |
404 | perl_destruct (perl); |
… | |
… | |
394 | void |
409 | void |
395 | rxvt_perl_interp::init () |
410 | rxvt_perl_interp::init () |
396 | { |
411 | { |
397 | if (!perl) |
412 | if (!perl) |
398 | { |
413 | { |
|
|
414 | perl_environ = rxvt_environ; |
|
|
415 | swap (perl_environ, environ); |
|
|
416 | |
399 | char *argv[] = { |
417 | char *argv[] = { |
400 | "", |
418 | "", |
|
|
419 | "-T", |
401 | "-edo '" LIBDIR "/urxvt.pm' or ($@ and die $@) or exit 1", |
420 | "-edo '" LIBDIR "/urxvt.pm' or ($@ and die $@) or exit 1", |
402 | }; |
421 | }; |
403 | |
422 | |
404 | perl = perl_alloc (); |
423 | perl = perl_alloc (); |
405 | perl_construct (perl); |
424 | perl_construct (perl); |
406 | |
425 | |
407 | if (perl_parse (perl, xs_init, 2, argv, (char **)NULL) |
426 | if (perl_parse (perl, xs_init, 3, argv, (char **)NULL) |
408 | || perl_run (perl)) |
427 | || perl_run (perl)) |
409 | { |
428 | { |
410 | rxvt_warn ("unable to initialize perl-interpreter, continuing without.\n"); |
429 | rxvt_warn ("unable to initialize perl-interpreter, continuing without.\n"); |
411 | |
430 | |
412 | perl_destruct (perl); |
431 | perl_destruct (perl); |
413 | perl_free (perl); |
432 | perl_free (perl); |
414 | perl = 0; |
433 | perl = 0; |
415 | } |
434 | } |
|
|
435 | |
|
|
436 | swap (perl_environ, environ); |
|
|
437 | } |
|
|
438 | } |
|
|
439 | |
|
|
440 | static void |
|
|
441 | ungrab (rxvt_term *THIS) |
|
|
442 | { |
|
|
443 | if (THIS->perl.grabtime) |
|
|
444 | { |
|
|
445 | XUngrabKeyboard (THIS->display->display, THIS->perl.grabtime); |
|
|
446 | XUngrabPointer (THIS->display->display, THIS->perl.grabtime); |
|
|
447 | THIS->perl.grabtime = 0; |
416 | } |
448 | } |
417 | } |
449 | } |
418 | |
450 | |
419 | bool |
451 | bool |
420 | rxvt_perl_interp::invoke (rxvt_term *term, hook_type htype, ...) |
452 | rxvt_perl_interp::invoke (rxvt_term *term, hook_type htype, ...) |
… | |
… | |
431 | return false; // perl not initialized for this instance |
463 | return false; // perl not initialized for this instance |
432 | else if (htype == HOOK_DESTROY) |
464 | else if (htype == HOOK_DESTROY) |
433 | { |
465 | { |
434 | // handled later |
466 | // handled later |
435 | } |
467 | } |
436 | else if (htype == HOOK_REFRESH_BEGIN || htype == HOOK_REFRESH_END) |
468 | else |
437 | { |
469 | { |
438 | HV *hv = (HV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, 0)); |
470 | if (htype == HOOK_REFRESH_BEGIN || htype == HOOK_REFRESH_END) |
439 | |
|
|
440 | if (HvKEYS (hv)) |
|
|
441 | { |
471 | { |
|
|
472 | HV *hv = (HV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, 0)); |
|
|
473 | |
|
|
474 | if (HvKEYS (hv)) |
|
|
475 | { |
442 | hv_iterinit (hv); |
476 | hv_iterinit (hv); |
443 | |
477 | |
444 | while (HE *he = hv_iternext (hv)) |
478 | while (HE *he = hv_iternext (hv)) |
445 | ((overlay *)SvIV (hv_iterval (hv, he)))->swap (); |
479 | ((overlay *)SvIV (hv_iterval (hv, he)))->swap (); |
|
|
480 | } |
|
|
481 | |
446 | } |
482 | } |
|
|
483 | |
|
|
484 | if (!should_invoke [htype]) |
|
|
485 | return false; |
447 | } |
486 | } |
448 | else if (!should_invoke [htype]) |
|
|
449 | return false; |
|
|
450 | |
487 | |
|
|
488 | swap (perl_environ, environ); |
|
|
489 | |
|
|
490 | try |
|
|
491 | { |
451 | dSP; |
492 | dSP; |
452 | va_list ap; |
493 | va_list ap; |
453 | |
494 | |
454 | va_start (ap, htype); |
495 | va_start (ap, htype); |
455 | |
496 | |
456 | ENTER; |
497 | ENTER; |
457 | SAVETMPS; |
498 | SAVETMPS; |
458 | |
499 | |
459 | PUSHMARK (SP); |
500 | PUSHMARK (SP); |
460 | |
501 | |
461 | XPUSHs (sv_2mortal (newSVterm (term))); |
502 | XPUSHs (sv_2mortal (newSVterm (term))); |
462 | XPUSHs (sv_2mortal (newSViv (htype))); |
503 | XPUSHs (sv_2mortal (newSViv (htype))); |
463 | |
504 | |
464 | for (;;) { |
505 | for (;;) { |
465 | data_type dt = (data_type)va_arg (ap, int); |
506 | data_type dt = (data_type)va_arg (ap, int); |
466 | |
507 | |
467 | switch (dt) |
508 | switch (dt) |
468 | { |
509 | { |
469 | case DT_INT: |
510 | case DT_INT: |
470 | XPUSHs (sv_2mortal (newSViv (va_arg (ap, int)))); |
511 | XPUSHs (sv_2mortal (newSViv (va_arg (ap, int)))); |
471 | break; |
512 | break; |
472 | |
513 | |
473 | case DT_LONG: |
514 | case DT_LONG: |
474 | XPUSHs (sv_2mortal (newSViv (va_arg (ap, long)))); |
515 | XPUSHs (sv_2mortal (newSViv (va_arg (ap, long)))); |
475 | break; |
516 | break; |
476 | |
517 | |
477 | case DT_STR: |
518 | case DT_STR: |
478 | XPUSHs (sv_2mortal (newSVpv (va_arg (ap, char *), 0))); |
519 | XPUSHs (taint (sv_2mortal (newSVpv (va_arg (ap, char *), 0)))); |
479 | break; |
520 | break; |
480 | |
521 | |
481 | case DT_STR_LEN: |
522 | case DT_STR_LEN: |
482 | { |
523 | { |
483 | char *str = va_arg (ap, char *); |
524 | char *str = va_arg (ap, char *); |
484 | int len = va_arg (ap, int); |
525 | int len = va_arg (ap, int); |
485 | |
526 | |
486 | XPUSHs (sv_2mortal (newSVpvn (str, len))); |
527 | XPUSHs (taint (sv_2mortal (newSVpvn (str, len)))); |
487 | } |
528 | } |
488 | break; |
529 | break; |
489 | |
530 | |
490 | case DT_WCS_LEN: |
531 | case DT_WCS_LEN: |
491 | { |
532 | { |
492 | wchar_t *wstr = va_arg (ap, wchar_t *); |
533 | wchar_t *wstr = va_arg (ap, wchar_t *); |
493 | int wlen = va_arg (ap, int); |
534 | int wlen = va_arg (ap, int); |
494 | |
535 | |
495 | XPUSHs (sv_2mortal (wcs2sv (wstr, wlen))); |
536 | XPUSHs (taint (sv_2mortal (wcs2sv (wstr, wlen)))); |
496 | } |
537 | } |
497 | break; |
538 | break; |
498 | |
539 | |
499 | case DT_XEVENT: |
540 | case DT_XEVENT: |
500 | { |
541 | { |
501 | XEvent *xe = va_arg (ap, XEvent *); |
542 | XEvent *xe = va_arg (ap, XEvent *); |
502 | HV *hv = newHV (); |
543 | HV *hv = newHV (); |
503 | |
544 | |
504 | # define set(name, sv) hv_store (hv, # name, sizeof (# name) - 1, sv, 0) |
545 | # define set(name, sv) hv_store (hv, # name, sizeof (# name) - 1, sv, 0) |
505 | # define setiv(name, val) hv_store (hv, # name, sizeof (# name) - 1, newSViv (val), 0) |
546 | # define setiv(name, val) hv_store (hv, # name, sizeof (# name) - 1, newSViv (val), 0) |
506 | # undef set |
547 | # undef set |
507 | |
548 | |
508 | setiv (type, xe->type); |
549 | setiv (type, xe->type); |
509 | setiv (send_event, xe->xany.send_event); |
550 | setiv (send_event, xe->xany.send_event); |
510 | setiv (serial, xe->xany.serial); |
551 | setiv (serial, xe->xany.serial); |
511 | |
552 | |
512 | switch (xe->type) |
553 | switch (xe->type) |
|
|
554 | { |
|
|
555 | case KeyPress: |
|
|
556 | case KeyRelease: |
|
|
557 | case ButtonPress: |
|
|
558 | case ButtonRelease: |
|
|
559 | case MotionNotify: |
|
|
560 | setiv (time, xe->xmotion.time); |
|
|
561 | setiv (x, xe->xmotion.x); |
|
|
562 | setiv (y, xe->xmotion.y); |
|
|
563 | setiv (row, xe->xmotion.y / term->fheight); |
|
|
564 | setiv (col, xe->xmotion.x / term->fwidth); |
|
|
565 | setiv (x_root, xe->xmotion.x_root); |
|
|
566 | setiv (y_root, xe->xmotion.y_root); |
|
|
567 | setiv (state, xe->xmotion.state); |
|
|
568 | break; |
|
|
569 | } |
|
|
570 | |
|
|
571 | switch (xe->type) |
|
|
572 | { |
|
|
573 | case KeyPress: |
|
|
574 | case KeyRelease: |
|
|
575 | setiv (keycode, xe->xkey.keycode); |
|
|
576 | break; |
|
|
577 | |
|
|
578 | case ButtonPress: |
|
|
579 | case ButtonRelease: |
|
|
580 | setiv (button, xe->xbutton.button); |
|
|
581 | break; |
|
|
582 | |
|
|
583 | case MotionNotify: |
|
|
584 | setiv (is_hint, xe->xmotion.is_hint); |
|
|
585 | break; |
|
|
586 | } |
|
|
587 | |
|
|
588 | XPUSHs (sv_2mortal (newRV_noinc ((SV *)hv))); |
|
|
589 | } |
|
|
590 | break; |
|
|
591 | |
|
|
592 | case DT_END: |
513 | { |
593 | { |
514 | case KeyPress: |
594 | va_end (ap); |
515 | case KeyRelease: |
595 | |
516 | case ButtonPress: |
596 | PUTBACK; |
517 | case ButtonRelease: |
597 | int count = call_pv ("urxvt::invoke", G_ARRAY | G_EVAL); |
518 | case MotionNotify: |
598 | SPAGAIN; |
519 | setiv (time, xe->xmotion.time); |
599 | |
520 | setiv (x, xe->xmotion.x); |
600 | if (count) |
521 | setiv (y, xe->xmotion.y); |
|
|
522 | setiv (row, xe->xmotion.y / term->fheight); |
|
|
523 | setiv (col, xe->xmotion.x / term->fwidth); |
|
|
524 | setiv (x_root, xe->xmotion.x_root); |
|
|
525 | setiv (y_root, xe->xmotion.y_root); |
|
|
526 | setiv (state, xe->xmotion.state); |
|
|
527 | break; |
601 | { |
|
|
602 | SV *status = POPs; |
|
|
603 | count = SvTRUE (status); |
|
|
604 | } |
|
|
605 | |
|
|
606 | PUTBACK; |
|
|
607 | FREETMPS; |
|
|
608 | LEAVE; |
|
|
609 | |
|
|
610 | if (SvTRUE (ERRSV)) |
|
|
611 | { |
|
|
612 | rxvt_warn ("perl hook %d evaluation error: %s", htype, SvPV_nolen (ERRSV)); |
|
|
613 | ungrab (term); // better lose the grab than the session |
|
|
614 | } |
|
|
615 | |
|
|
616 | if (htype == HOOK_DESTROY) |
|
|
617 | { |
|
|
618 | clearSVptr ((SV *)term->perl.self); |
|
|
619 | SvREFCNT_dec ((SV *)term->perl.self); |
|
|
620 | } |
|
|
621 | |
|
|
622 | swap (perl_environ, environ); |
|
|
623 | return count; |
528 | } |
624 | } |
529 | |
625 | |
530 | switch (xe->type) |
|
|
531 | { |
|
|
532 | case KeyPress: |
|
|
533 | case KeyRelease: |
|
|
534 | setiv (keycode, xe->xkey.keycode); |
|
|
535 | break; |
|
|
536 | |
|
|
537 | case ButtonPress: |
|
|
538 | case ButtonRelease: |
|
|
539 | setiv (button, xe->xbutton.button); |
|
|
540 | break; |
|
|
541 | |
|
|
542 | case MotionNotify: |
|
|
543 | setiv (is_hint, xe->xmotion.is_hint); |
|
|
544 | break; |
|
|
545 | } |
|
|
546 | |
|
|
547 | XPUSHs (sv_2mortal (newRV_noinc ((SV *)hv))); |
|
|
548 | } |
|
|
549 | break; |
|
|
550 | |
|
|
551 | case DT_END: |
|
|
552 | { |
|
|
553 | va_end (ap); |
|
|
554 | |
|
|
555 | PUTBACK; |
|
|
556 | int count = call_pv ("urxvt::invoke", G_ARRAY | G_EVAL); |
|
|
557 | SPAGAIN; |
|
|
558 | |
|
|
559 | if (count) |
|
|
560 | { |
|
|
561 | SV *status = POPs; |
|
|
562 | count = SvTRUE (status); |
|
|
563 | } |
|
|
564 | |
|
|
565 | PUTBACK; |
|
|
566 | FREETMPS; |
|
|
567 | LEAVE; |
|
|
568 | |
|
|
569 | if (SvTRUE (ERRSV)) |
|
|
570 | rxvt_warn ("perl hook %d evaluation error: %s", htype, SvPV_nolen (ERRSV)); |
|
|
571 | |
|
|
572 | if (htype == HOOK_DESTROY) |
|
|
573 | { |
|
|
574 | clearSVptr ((SV *)term->perl.self); |
|
|
575 | SvREFCNT_dec ((SV *)term->perl.self); |
|
|
576 | } |
|
|
577 | |
|
|
578 | return count; |
|
|
579 | } |
|
|
580 | |
|
|
581 | default: |
626 | default: |
582 | rxvt_fatal ("FATAL: unable to pass data type %d\n", dt); |
627 | rxvt_fatal ("FATAL: unable to pass data type %d\n", dt); |
|
|
628 | } |
583 | } |
629 | } |
584 | } |
630 | } |
|
|
631 | catch (...) |
|
|
632 | { |
|
|
633 | swap (perl_environ, environ); |
|
|
634 | throw; |
|
|
635 | } |
585 | } |
636 | } |
586 | |
637 | |
587 | ///////////////////////////////////////////////////////////////////////////// |
638 | ///////////////////////////////////////////////////////////////////////////// |
588 | |
639 | |
589 | MODULE = urxvt PACKAGE = urxvt |
640 | MODULE = urxvt PACKAGE = urxvt |
590 | |
641 | |
591 | PROTOTYPES: ENABLE |
642 | PROTOTYPES: ENABLE |
592 | |
643 | |
593 | BOOT: |
644 | BOOT: |
594 | { |
645 | { |
595 | sv_setsv (get_sv ("urxvt::LIBDIR", 1), newSVpvn (LIBDIR, sizeof (LIBDIR) - 1)); |
646 | sv_setsv (get_sv ("urxvt::LIBDIR", 1), newSVpvn (LIBDIR, sizeof (LIBDIR) - 1)); |
|
|
647 | sv_setsv (get_sv ("urxvt::RESNAME", 1), newSVpvn (RESNAME, sizeof (RESNAME) - 1)); |
|
|
648 | sv_setsv (get_sv ("urxvt::RESCLASS", 1), newSVpvn (RESCLASS, sizeof (RESCLASS) - 1)); |
|
|
649 | sv_setsv (get_sv ("urxvt::RXVTNAME", 1), newSVpvn (RXVTNAME, sizeof (RXVTNAME) - 1)); |
596 | |
650 | |
597 | AV *hookname = get_av ("urxvt::HOOKNAME", 1); |
651 | AV *hookname = get_av ("urxvt::HOOKNAME", 1); |
598 | # define def(sym) av_store (hookname, HOOK_ ## sym, newSVpv (# sym, 0)); |
652 | # define def(sym) av_store (hookname, HOOK_ ## sym, newSVpv (# sym, 0)); |
599 | # include "hookinc.h" |
653 | # include "hookinc.h" |
600 | # undef def |
654 | # undef def |
… | |
… | |
629 | export_const_iv (Button2Mask); |
683 | export_const_iv (Button2Mask); |
630 | export_const_iv (Button3Mask); |
684 | export_const_iv (Button3Mask); |
631 | export_const_iv (Button4Mask); |
685 | export_const_iv (Button4Mask); |
632 | export_const_iv (Button5Mask); |
686 | export_const_iv (Button5Mask); |
633 | export_const_iv (AnyModifier); |
687 | export_const_iv (AnyModifier); |
|
|
688 | |
|
|
689 | export_const_iv (EVENT_NONE); |
|
|
690 | export_const_iv (EVENT_READ); |
|
|
691 | export_const_iv (EVENT_WRITE); |
634 | } |
692 | } |
|
|
693 | |
|
|
694 | void |
|
|
695 | set_should_invoke (int htype, int value) |
|
|
696 | CODE: |
|
|
697 | rxvt_perl.should_invoke [htype] = value; |
|
|
698 | |
|
|
699 | void |
|
|
700 | warn (const char *msg) |
|
|
701 | CODE: |
|
|
702 | rxvt_warn ("%s", msg); |
|
|
703 | |
|
|
704 | void |
|
|
705 | fatal (const char *msg) |
|
|
706 | CODE: |
|
|
707 | rxvt_fatal ("%s", msg); |
635 | |
708 | |
636 | SV * |
709 | SV * |
637 | new (...) |
710 | untaint (SV *sv) |
638 | CODE: |
711 | CODE: |
639 | { |
712 | RETVAL = newSVsv (sv); |
640 | stringvec *argv = new stringvec; |
713 | SvTAINTED_off (RETVAL); |
641 | bool success; |
714 | OUTPUT: |
642 | |
|
|
643 | for (int i = 0; i < items ;i++) |
|
|
644 | argv->push_back (strdup (SvPVbyte_nolen (ST (i)))); |
|
|
645 | |
|
|
646 | rxvt_term *term = new rxvt_term; |
|
|
647 | |
|
|
648 | term->argv = argv; |
|
|
649 | |
|
|
650 | try |
|
|
651 | { |
|
|
652 | if (!term->init (argv->size (), argv->begin ())) |
|
|
653 | term = 0; |
|
|
654 | } |
|
|
655 | catch (const class rxvt_failure_exception &e) |
|
|
656 | { |
|
|
657 | term->destroy (); |
|
|
658 | croak ("exception caught while initializing new terminal instance"); |
|
|
659 | } |
|
|
660 | |
|
|
661 | RETVAL = term && term->perl.self ? newSVterm (term) : &PL_sv_undef; |
|
|
662 | } |
|
|
663 | OUTPUT: |
|
|
664 | RETVAL |
715 | RETVAL |
665 | |
716 | |
666 | void |
717 | void |
667 | set_should_invoke (int htype, int value) |
718 | _exit (int status) |
668 | CODE: |
|
|
669 | rxvt_perl.should_invoke [htype] = value; |
|
|
670 | |
719 | |
671 | void |
720 | bool |
672 | warn (const char *msg) |
721 | safe () |
673 | CODE: |
722 | CODE: |
674 | rxvt_warn ("%s", msg); |
723 | RETVAL = !rxvt_tainted (); |
675 | |
724 | OUTPUT: |
676 | void |
725 | RETVAL |
677 | fatal (const char *msg) |
|
|
678 | CODE: |
|
|
679 | rxvt_fatal ("%s", msg); |
|
|
680 | |
726 | |
681 | NV |
727 | NV |
682 | NOW () |
728 | NOW () |
683 | CODE: |
729 | CODE: |
684 | RETVAL = NOW; |
730 | RETVAL = NOW; |
… | |
… | |
732 | } |
778 | } |
733 | OUTPUT: |
779 | OUTPUT: |
734 | RETVAL |
780 | RETVAL |
735 | |
781 | |
736 | MODULE = urxvt PACKAGE = urxvt::term |
782 | MODULE = urxvt PACKAGE = urxvt::term |
|
|
783 | |
|
|
784 | SV * |
|
|
785 | _new (...) |
|
|
786 | CODE: |
|
|
787 | { |
|
|
788 | if (items < 1 || !SvROK (ST (0)) || SvTYPE (SvRV (ST (0))) != SVt_PVAV) |
|
|
789 | croak ("first argument to urxvt::term->_new must be arrayref"); |
|
|
790 | |
|
|
791 | rxvt_term *term = new rxvt_term; |
|
|
792 | |
|
|
793 | term->argv = new stringvec; |
|
|
794 | term->envv = new stringvec; |
|
|
795 | |
|
|
796 | for (int i = 1; i < items; i++) |
|
|
797 | term->argv->push_back (strdup (SvPVbyte_nolen (ST (i)))); |
|
|
798 | |
|
|
799 | AV *envv = (AV *)SvRV (ST (0)); |
|
|
800 | for (int i = av_len (envv) + 1; i--; ) |
|
|
801 | term->envv->push_back (strdup (SvPVbyte_nolen (*av_fetch (envv, i, 1)))); |
|
|
802 | |
|
|
803 | term->envv->push_back (0); |
|
|
804 | |
|
|
805 | bool success; |
|
|
806 | |
|
|
807 | try |
|
|
808 | { |
|
|
809 | success = term->init (term->argv->size (), term->argv->begin ()); |
|
|
810 | } |
|
|
811 | catch (const class rxvt_failure_exception &e) |
|
|
812 | { |
|
|
813 | success = false; |
|
|
814 | } |
|
|
815 | |
|
|
816 | if (!success) |
|
|
817 | { |
|
|
818 | term->destroy (); |
|
|
819 | croak ("error while initializing new terminal instance"); |
|
|
820 | } |
|
|
821 | |
|
|
822 | RETVAL = term && term->perl.self |
|
|
823 | ? newSVterm (term) : &PL_sv_undef; |
|
|
824 | } |
|
|
825 | OUTPUT: |
|
|
826 | RETVAL |
737 | |
827 | |
738 | void |
828 | void |
739 | rxvt_term::destroy () |
829 | rxvt_term::destroy () |
740 | |
830 | |
741 | void |
831 | void |
… | |
… | |
765 | } |
855 | } |
766 | OUTPUT: |
856 | OUTPUT: |
767 | RETVAL |
857 | RETVAL |
768 | |
858 | |
769 | void |
859 | void |
770 | rxvt_term::allow_events_async (U32 eventtime = THIS->perl.grabtime) |
860 | rxvt_term::allow_events_async () |
771 | CODE: |
861 | CODE: |
772 | XAllowEvents (THIS->display->display, AsyncBoth, eventtime); |
862 | XAllowEvents (THIS->display->display, AsyncBoth, THIS->perl.grabtime); |
773 | |
863 | |
774 | void |
864 | void |
775 | rxvt_term::allow_events_sync (U32 eventtime = THIS->perl.grabtime) |
865 | rxvt_term::allow_events_sync () |
776 | CODE: |
866 | CODE: |
777 | XAllowEvents (THIS->display->display, SyncBoth, eventtime); |
867 | XAllowEvents (THIS->display->display, SyncBoth, THIS->perl.grabtime); |
778 | |
868 | |
779 | void |
869 | void |
780 | rxvt_term::allow_events_replay (U32 eventtime = THIS->perl.grabtime) |
870 | rxvt_term::allow_events_replay () |
781 | CODE: |
871 | CODE: |
782 | XAllowEvents (THIS->display->display, ReplayPointer, eventtime); |
872 | XAllowEvents (THIS->display->display, ReplayPointer, THIS->perl.grabtime); |
783 | XAllowEvents (THIS->display->display, ReplayKeyboard, eventtime); |
873 | XAllowEvents (THIS->display->display, ReplayKeyboard, THIS->perl.grabtime); |
784 | |
874 | |
785 | void |
875 | void |
786 | rxvt_term::ungrab (U32 eventtime = THIS->perl.grabtime) |
876 | rxvt_term::ungrab () |
787 | CODE: |
877 | CODE: |
788 | THIS->perl.grabtime = 0; |
878 | ungrab (THIS); |
789 | XUngrabKeyboard (THIS->display->display, eventtime); |
|
|
790 | XUngrabPointer (THIS->display->display, eventtime); |
|
|
791 | |
879 | |
792 | int |
880 | int |
793 | rxvt_term::strwidth (SV *str) |
881 | rxvt_term::strwidth (SV *str) |
794 | CODE: |
882 | CODE: |
795 | { |
883 | { |
… | |
… | |
814 | char *mbstr = rxvt_wcstombs (wstr); |
902 | char *mbstr = rxvt_wcstombs (wstr); |
815 | rxvt_pop_locale (); |
903 | rxvt_pop_locale (); |
816 | |
904 | |
817 | free (wstr); |
905 | free (wstr); |
818 | |
906 | |
819 | RETVAL = newSVpv (mbstr, 0); |
907 | RETVAL = taint_if (newSVpv (mbstr, 0), str); |
820 | free (mbstr); |
908 | free (mbstr); |
821 | } |
909 | } |
822 | OUTPUT: |
910 | OUTPUT: |
823 | RETVAL |
911 | RETVAL |
824 | |
912 | |
… | |
… | |
831 | |
919 | |
832 | rxvt_push_locale (THIS->locale); |
920 | rxvt_push_locale (THIS->locale); |
833 | wchar_t *wstr = rxvt_mbstowcs (data, len); |
921 | wchar_t *wstr = rxvt_mbstowcs (data, len); |
834 | rxvt_pop_locale (); |
922 | rxvt_pop_locale (); |
835 | |
923 | |
836 | RETVAL = wcs2sv (wstr); |
924 | RETVAL = taint_if (wcs2sv (wstr), octets); |
837 | free (wstr); |
925 | free (wstr); |
838 | } |
926 | } |
839 | OUTPUT: |
927 | OUTPUT: |
840 | RETVAL |
928 | RETVAL |
841 | |
929 | |
… | |
… | |
888 | case 2: RETVAL = THIS->ModNumLockMask; break; |
976 | case 2: RETVAL = THIS->ModNumLockMask; break; |
889 | } |
977 | } |
890 | OUTPUT: |
978 | OUTPUT: |
891 | RETVAL |
979 | RETVAL |
892 | |
980 | |
|
|
981 | char * |
|
|
982 | rxvt_term::display_id () |
|
|
983 | ALIAS: |
|
|
984 | display_id = 0 |
|
|
985 | locale = 1 |
|
|
986 | CODE: |
|
|
987 | switch (ix) |
|
|
988 | { |
|
|
989 | case 0: RETVAL = THIS->display->id; break; |
|
|
990 | case 1: RETVAL = THIS->locale; break; |
|
|
991 | } |
|
|
992 | OUTPUT: |
|
|
993 | RETVAL |
|
|
994 | |
|
|
995 | SV * |
|
|
996 | rxvt_term::_env () |
|
|
997 | CODE: |
|
|
998 | { |
|
|
999 | if (THIS->envv) |
|
|
1000 | { |
|
|
1001 | AV *av = newAV (); |
|
|
1002 | |
|
|
1003 | for (char **i = THIS->envv->begin (); i != THIS->envv->end (); ++i) |
|
|
1004 | if (*i) |
|
|
1005 | av_push (av, newSVpv (*i, 0)); |
|
|
1006 | |
|
|
1007 | RETVAL = newRV_noinc ((SV *)av); |
|
|
1008 | } |
|
|
1009 | else |
|
|
1010 | RETVAL = &PL_sv_undef; |
|
|
1011 | } |
|
|
1012 | OUTPUT: |
|
|
1013 | RETVAL |
|
|
1014 | |
|
|
1015 | int |
|
|
1016 | rxvt_term::pty_ev_events (int events = EVENT_UNDEF) |
|
|
1017 | CODE: |
|
|
1018 | RETVAL = THIS->pty_ev.events; |
|
|
1019 | if (events != EVENT_UNDEF) |
|
|
1020 | THIS->pty_ev.set (events); |
|
|
1021 | OUTPUT: |
|
|
1022 | RETVAL |
|
|
1023 | |
893 | U32 |
1024 | U32 |
894 | rxvt_term::parent () |
1025 | rxvt_term::parent () |
895 | CODE: |
1026 | CODE: |
896 | RETVAL = (U32)THIS->parent [0]; |
1027 | RETVAL = (U32)THIS->parent [0]; |
897 | OUTPUT: |
1028 | OUTPUT: |
… | |
… | |
914 | OUTPUT: |
1045 | OUTPUT: |
915 | RETVAL |
1046 | RETVAL |
916 | |
1047 | |
917 | int |
1048 | int |
918 | rxvt_term::view_start (int newval = -1) |
1049 | rxvt_term::view_start (int newval = -1) |
|
|
1050 | PROTOTYPE: $;$ |
919 | CODE: |
1051 | CODE: |
920 | { |
1052 | { |
921 | RETVAL = THIS->view_start; |
1053 | RETVAL = THIS->view_start; |
922 | |
1054 | |
923 | if (newval >= 0) |
1055 | if (newval >= 0) |
… | |
… | |
948 | wchar_t *wstr = new wchar_t [THIS->ncol]; |
1080 | wchar_t *wstr = new wchar_t [THIS->ncol]; |
949 | |
1081 | |
950 | for (int col = 0; col < THIS->ncol; col++) |
1082 | for (int col = 0; col < THIS->ncol; col++) |
951 | wstr [col] = l.t [col]; |
1083 | wstr [col] = l.t [col]; |
952 | |
1084 | |
953 | XPUSHs (sv_2mortal (wcs2sv (wstr, THIS->ncol))); |
1085 | XPUSHs (taint (sv_2mortal (wcs2sv (wstr, THIS->ncol)))); |
954 | |
1086 | |
955 | delete [] wstr; |
1087 | delete [] wstr; |
956 | } |
1088 | } |
957 | |
1089 | |
958 | if (new_text) |
1090 | if (new_text) |
… | |
… | |
1079 | else |
1211 | else |
1080 | *r++ = *s; |
1212 | *r++ = *s; |
1081 | |
1213 | |
1082 | rxvt_pop_locale (); |
1214 | rxvt_pop_locale (); |
1083 | |
1215 | |
1084 | RETVAL = wcs2sv (rstr, r - rstr); |
1216 | RETVAL = taint_if (wcs2sv (rstr, r - rstr), string); |
1085 | |
1217 | |
1086 | delete [] rstr; |
1218 | delete [] rstr; |
1087 | } |
1219 | } |
1088 | OUTPUT: |
1220 | OUTPUT: |
1089 | RETVAL |
1221 | RETVAL |
… | |
… | |
1115 | else if (IS_COMPOSE (*s)) |
1247 | else if (IS_COMPOSE (*s)) |
1116 | r += rxvt_composite.expand (*s, r); |
1248 | r += rxvt_composite.expand (*s, r); |
1117 | else |
1249 | else |
1118 | *r++ = *s; |
1250 | *r++ = *s; |
1119 | |
1251 | |
1120 | RETVAL = wcs2sv (rstr, r - rstr); |
1252 | RETVAL = taint_if (wcs2sv (rstr, r - rstr), text); |
1121 | |
1253 | |
1122 | delete [] rstr; |
1254 | delete [] rstr; |
1123 | } |
1255 | } |
1124 | OUTPUT: |
1256 | OUTPUT: |
1125 | RETVAL |
1257 | RETVAL |
… | |
… | |
1147 | |
1279 | |
1148 | if (!IN_RANGE_EXC (index, 0, NUM_RESOURCES)) |
1280 | if (!IN_RANGE_EXC (index, 0, NUM_RESOURCES)) |
1149 | croak ("requested out-of-bound resource %s+%d,", name, index - rs->value); |
1281 | croak ("requested out-of-bound resource %s+%d,", name, index - rs->value); |
1150 | |
1282 | |
1151 | if (GIMME_V != G_VOID) |
1283 | if (GIMME_V != G_VOID) |
1152 | XPUSHs (THIS->rs [index] ? sv_2mortal (newSVpv (THIS->rs [index], 0)) : &PL_sv_undef); |
1284 | XPUSHs (THIS->rs [index] ? sv_2mortal (taint (newSVpv (THIS->rs [index], 0))) : &PL_sv_undef); |
1153 | |
1285 | |
1154 | if (newval) |
1286 | if (newval) |
1155 | { |
1287 | { |
1156 | if (SvOK (newval)) |
1288 | if (SvOK (newval)) |
1157 | { |
1289 | { |
… | |
… | |
1162 | else |
1294 | else |
1163 | THIS->rs [index] = 0; |
1295 | THIS->rs [index] = 0; |
1164 | } |
1296 | } |
1165 | } |
1297 | } |
1166 | |
1298 | |
|
|
1299 | const char * |
|
|
1300 | rxvt_term::x_resource (const char *name) |
|
|
1301 | CLEANUP: |
|
|
1302 | SvTAINTED_on (ST (0)); |
|
|
1303 | |
1167 | bool |
1304 | bool |
1168 | rxvt_term::option (U32 optval, int set = -1) |
1305 | rxvt_term::option (U32 optval, int set = -1) |
1169 | CODE: |
1306 | CODE: |
1170 | { |
1307 | { |
1171 | RETVAL = THIS->options & optval; |
1308 | RETVAL = THIS->options & optval; |
… | |
… | |
1198 | } |
1335 | } |
1199 | } |
1336 | } |
1200 | OUTPUT: |
1337 | OUTPUT: |
1201 | RETVAL |
1338 | RETVAL |
1202 | |
1339 | |
|
|
1340 | bool |
|
|
1341 | rxvt_term::parse_keysym (char *keysym, char *str) |
|
|
1342 | CODE: |
|
|
1343 | RETVAL = 0 < THIS->parse_keysym (keysym, str); |
|
|
1344 | THIS->keyboard->register_done (); |
|
|
1345 | OUTPUT: |
|
|
1346 | RETVAL |
|
|
1347 | |
1203 | void |
1348 | void |
1204 | rxvt_term::cur (...) |
1349 | rxvt_term::screen_cur (...) |
1205 | PROTOTYPE: $;$$ |
1350 | PROTOTYPE: $;$$ |
1206 | ALIAS: |
1351 | ALIAS: |
1207 | screen_cur = 0 |
1352 | screen_cur = 0 |
1208 | selection_beg = 1 |
1353 | selection_beg = 1 |
1209 | selection_end = 2 |
1354 | selection_end = 2 |
… | |
… | |
1230 | if (ix) |
1375 | if (ix) |
1231 | THIS->want_refresh = 1; |
1376 | THIS->want_refresh = 1; |
1232 | } |
1377 | } |
1233 | } |
1378 | } |
1234 | |
1379 | |
|
|
1380 | char |
|
|
1381 | rxvt_term::cur_charset () |
|
|
1382 | CODE: |
|
|
1383 | RETVAL = THIS->charsets [THIS->screen.charset]; |
|
|
1384 | OUTPUT: |
|
|
1385 | RETVAL |
|
|
1386 | |
|
|
1387 | #void |
|
|
1388 | #rxvt_term::selection_clear () |
|
|
1389 | |
|
|
1390 | void |
|
|
1391 | rxvt_term::selection_make (U32 eventtime, bool rect = false) |
|
|
1392 | CODE: |
|
|
1393 | THIS->selection.op = SELECTION_CONT; |
|
|
1394 | THIS->selection.rect = rect; |
|
|
1395 | THIS->selection_make (eventtime); |
|
|
1396 | |
1235 | int |
1397 | int |
1236 | rxvt_term::selection_grab (U32 eventtime) |
1398 | rxvt_term::selection_grab (U32 eventtime) |
1237 | |
1399 | |
1238 | void |
1400 | void |
1239 | rxvt_term::selection (SV *newtext = 0) |
1401 | rxvt_term::selection (SV *newtext = 0) |
1240 | PPCODE: |
1402 | PPCODE: |
1241 | { |
1403 | { |
1242 | if (GIMME_V != G_VOID) |
1404 | if (GIMME_V != G_VOID) |
|
|
1405 | XPUSHs (THIS->selection.text |
1243 | XPUSHs (sv_2mortal (wcs2sv (THIS->selection.text, THIS->selection.len))); |
1406 | ? taint (sv_2mortal (wcs2sv (THIS->selection.text, THIS->selection.len))) |
|
|
1407 | : &PL_sv_undef); |
1244 | |
1408 | |
1245 | if (newtext) |
1409 | if (newtext) |
1246 | { |
1410 | { |
1247 | free (THIS->selection.text); |
1411 | free (THIS->selection.text); |
1248 | |
1412 | |
1249 | THIS->selection.text = sv2wcs (newtext); |
1413 | THIS->selection.text = sv2wcs (newtext); |
1250 | THIS->selection.len = wcslen (THIS->selection.text); |
1414 | THIS->selection.len = wcslen (THIS->selection.text); |
1251 | } |
1415 | } |
1252 | } |
1416 | } |
|
|
1417 | |
|
|
1418 | void |
|
|
1419 | rxvt_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) |
|
|
1420 | |
|
|
1421 | void |
|
|
1422 | rxvt_term::scr_xor_span (int beg_row, int beg_col, int end_row, int end_col, U32 rstyle = RS_RVid) |
|
|
1423 | |
|
|
1424 | void |
|
|
1425 | rxvt_term::scr_bell () |
1253 | |
1426 | |
1254 | void |
1427 | void |
1255 | rxvt_term::scr_add_lines (SV *string) |
1428 | rxvt_term::scr_add_lines (SV *string) |
1256 | CODE: |
1429 | CODE: |
1257 | { |
1430 | { |