… | |
… | |
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 "iom.h" |
34 | #include "rxvt.h" |
35 | #include "rxvt.h" |
35 | #include "iom.h" |
36 | #include "keyboard.h" |
36 | #include "rxvtutil.h" |
37 | #include "rxvtutil.h" |
37 | #include "rxvtperl.h" |
38 | #include "rxvtperl.h" |
38 | |
39 | |
39 | #include "perlxsi.c" |
40 | #include "perlxsi.c" |
|
|
41 | |
|
|
42 | #if defined(HAVE_SCROLLBARS) || defined(MENUBAR) |
|
|
43 | # define GRAB_CURSOR THIS->leftptr_cursor |
|
|
44 | #else |
|
|
45 | # define GRAB_CURSOR None |
|
|
46 | #endif |
40 | |
47 | |
41 | #undef LINENO |
48 | #undef LINENO |
42 | #define LINENO(n) MOD (THIS->term_start + int(n), THIS->total_rows) |
49 | #define LINENO(n) MOD (THIS->term_start + int(n), THIS->total_rows) |
43 | #undef ROW |
50 | #undef ROW |
44 | #define ROW(n) THIS->row_buf [LINENO (n)] |
51 | #define ROW(n) THIS->row_buf [LINENO (n)] |
45 | |
52 | |
46 | ///////////////////////////////////////////////////////////////////////////// |
53 | ///////////////////////////////////////////////////////////////////////////// |
|
|
54 | |
|
|
55 | static SV * |
|
|
56 | taint (SV *sv) |
|
|
57 | { |
|
|
58 | SvTAINT (sv); |
|
|
59 | return sv; |
|
|
60 | } |
|
|
61 | |
|
|
62 | static SV * |
|
|
63 | taint_if (SV *sv, SV *src) |
|
|
64 | { |
|
|
65 | if (SvTAINTED (src)) |
|
|
66 | SvTAINT (sv); |
|
|
67 | |
|
|
68 | return sv; |
|
|
69 | } |
47 | |
70 | |
48 | static wchar_t * |
71 | static wchar_t * |
49 | sv2wcs (SV *sv) |
72 | sv2wcs (SV *sv) |
50 | { |
73 | { |
51 | STRLEN len; |
74 | STRLEN len; |
… | |
… | |
370 | |
393 | |
371 | struct rxvt_perl_interp rxvt_perl; |
394 | struct rxvt_perl_interp rxvt_perl; |
372 | |
395 | |
373 | static PerlInterpreter *perl; |
396 | static PerlInterpreter *perl; |
374 | |
397 | |
375 | rxvt_perl_interp::rxvt_perl_interp () |
|
|
376 | { |
|
|
377 | } |
|
|
378 | |
|
|
379 | rxvt_perl_interp::~rxvt_perl_interp () |
398 | rxvt_perl_interp::~rxvt_perl_interp () |
380 | { |
399 | { |
381 | if (perl) |
400 | if (perl) |
382 | { |
401 | { |
383 | perl_destruct (perl); |
402 | perl_destruct (perl); |
… | |
… | |
388 | void |
407 | void |
389 | rxvt_perl_interp::init () |
408 | rxvt_perl_interp::init () |
390 | { |
409 | { |
391 | if (!perl) |
410 | if (!perl) |
392 | { |
411 | { |
|
|
412 | perl_environ = rxvt_environ; |
|
|
413 | swap (perl_environ, environ); |
|
|
414 | |
393 | char *argv[] = { |
415 | char *argv[] = { |
394 | "", |
416 | "", |
|
|
417 | "-T", |
395 | "-edo '" LIBDIR "/urxvt.pm' or ($@ and die $@) or exit 1", |
418 | "-edo '" LIBDIR "/urxvt.pm' or ($@ and die $@) or exit 1", |
396 | }; |
419 | }; |
397 | |
420 | |
398 | perl = perl_alloc (); |
421 | perl = perl_alloc (); |
399 | perl_construct (perl); |
422 | perl_construct (perl); |
400 | |
423 | |
401 | if (perl_parse (perl, xs_init, 2, argv, (char **)NULL) |
424 | if (perl_parse (perl, xs_init, 3, argv, (char **)NULL) |
402 | || perl_run (perl)) |
425 | || perl_run (perl)) |
403 | { |
426 | { |
404 | rxvt_warn ("unable to initialize perl-interpreter, continuing without.\n"); |
427 | rxvt_warn ("unable to initialize perl-interpreter, continuing without.\n"); |
405 | |
428 | |
406 | perl_destruct (perl); |
429 | perl_destruct (perl); |
407 | perl_free (perl); |
430 | perl_free (perl); |
408 | perl = 0; |
431 | perl = 0; |
409 | } |
432 | } |
|
|
433 | |
|
|
434 | swap (perl_environ, environ); |
|
|
435 | } |
|
|
436 | } |
|
|
437 | |
|
|
438 | static void |
|
|
439 | ungrab (rxvt_term *THIS) |
|
|
440 | { |
|
|
441 | if (THIS->perl.grabtime) |
|
|
442 | { |
|
|
443 | XUngrabKeyboard (THIS->display->display, THIS->perl.grabtime); |
|
|
444 | XUngrabPointer (THIS->display->display, THIS->perl.grabtime); |
|
|
445 | THIS->perl.grabtime = 0; |
410 | } |
446 | } |
411 | } |
447 | } |
412 | |
448 | |
413 | bool |
449 | bool |
414 | rxvt_perl_interp::invoke (rxvt_term *term, hook_type htype, ...) |
450 | rxvt_perl_interp::invoke (rxvt_term *term, hook_type htype, ...) |
… | |
… | |
425 | return false; // perl not initialized for this instance |
461 | return false; // perl not initialized for this instance |
426 | else if (htype == HOOK_DESTROY) |
462 | else if (htype == HOOK_DESTROY) |
427 | { |
463 | { |
428 | // handled later |
464 | // handled later |
429 | } |
465 | } |
430 | else if (htype == HOOK_REFRESH_BEGIN || htype == HOOK_REFRESH_END) |
466 | else |
431 | { |
467 | { |
432 | HV *hv = (HV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, 0)); |
468 | if (htype == HOOK_REFRESH_BEGIN || htype == HOOK_REFRESH_END) |
433 | |
|
|
434 | if (HvKEYS (hv)) |
|
|
435 | { |
469 | { |
|
|
470 | HV *hv = (HV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, 0)); |
|
|
471 | |
|
|
472 | if (HvKEYS (hv)) |
|
|
473 | { |
436 | hv_iterinit (hv); |
474 | hv_iterinit (hv); |
437 | |
475 | |
438 | while (HE *he = hv_iternext (hv)) |
476 | while (HE *he = hv_iternext (hv)) |
439 | ((overlay *)SvIV (hv_iterval (hv, he)))->swap (); |
477 | ((overlay *)SvIV (hv_iterval (hv, he)))->swap (); |
|
|
478 | } |
|
|
479 | |
440 | } |
480 | } |
|
|
481 | |
|
|
482 | if (!should_invoke [htype]) |
|
|
483 | return false; |
441 | } |
484 | } |
442 | else if (!should_invoke [htype]) |
|
|
443 | return false; |
|
|
444 | |
485 | |
|
|
486 | swap (perl_environ, environ); |
|
|
487 | |
|
|
488 | try |
|
|
489 | { |
445 | dSP; |
490 | dSP; |
446 | va_list ap; |
491 | va_list ap; |
447 | |
492 | |
448 | va_start (ap, htype); |
493 | va_start (ap, htype); |
449 | |
494 | |
450 | ENTER; |
495 | ENTER; |
451 | SAVETMPS; |
496 | SAVETMPS; |
452 | |
497 | |
453 | PUSHMARK (SP); |
498 | PUSHMARK (SP); |
454 | |
499 | |
455 | XPUSHs (sv_2mortal (newSVterm (term))); |
500 | XPUSHs (sv_2mortal (newSVterm (term))); |
456 | XPUSHs (sv_2mortal (newSViv (htype))); |
501 | XPUSHs (sv_2mortal (newSViv (htype))); |
457 | |
502 | |
458 | for (;;) { |
503 | for (;;) { |
459 | data_type dt = (data_type)va_arg (ap, int); |
504 | data_type dt = (data_type)va_arg (ap, int); |
460 | |
505 | |
461 | switch (dt) |
506 | switch (dt) |
462 | { |
507 | { |
463 | case DT_INT: |
508 | case DT_INT: |
464 | XPUSHs (sv_2mortal (newSViv (va_arg (ap, int)))); |
509 | XPUSHs (sv_2mortal (newSViv (va_arg (ap, int)))); |
465 | break; |
510 | break; |
466 | |
511 | |
467 | case DT_LONG: |
512 | case DT_LONG: |
468 | XPUSHs (sv_2mortal (newSViv (va_arg (ap, long)))); |
513 | XPUSHs (sv_2mortal (newSViv (va_arg (ap, long)))); |
469 | break; |
514 | break; |
470 | |
515 | |
471 | case DT_STR: |
516 | case DT_STR: |
472 | XPUSHs (sv_2mortal (newSVpv (va_arg (ap, char *), 0))); |
517 | XPUSHs (taint (sv_2mortal (newSVpv (va_arg (ap, char *), 0)))); |
473 | break; |
518 | break; |
474 | |
519 | |
475 | case DT_STR_LEN: |
520 | case DT_STR_LEN: |
476 | { |
521 | { |
477 | char *str = va_arg (ap, char *); |
522 | char *str = va_arg (ap, char *); |
478 | int len = va_arg (ap, int); |
523 | int len = va_arg (ap, int); |
479 | |
524 | |
480 | XPUSHs (sv_2mortal (newSVpvn (str, len))); |
525 | XPUSHs (taint (sv_2mortal (newSVpvn (str, len)))); |
481 | } |
526 | } |
482 | break; |
527 | break; |
483 | |
528 | |
484 | case DT_WCS_LEN: |
529 | case DT_WCS_LEN: |
485 | { |
530 | { |
486 | wchar_t *wstr = va_arg (ap, wchar_t *); |
531 | wchar_t *wstr = va_arg (ap, wchar_t *); |
487 | int wlen = va_arg (ap, int); |
532 | int wlen = va_arg (ap, int); |
488 | |
533 | |
489 | XPUSHs (sv_2mortal (wcs2sv (wstr, wlen))); |
534 | XPUSHs (taint (sv_2mortal (wcs2sv (wstr, wlen)))); |
490 | } |
535 | } |
491 | break; |
536 | break; |
492 | |
537 | |
493 | case DT_XEVENT: |
538 | case DT_XEVENT: |
494 | { |
539 | { |
495 | XEvent *xe = va_arg (ap, XEvent *); |
540 | XEvent *xe = va_arg (ap, XEvent *); |
496 | HV *hv = newHV (); |
541 | HV *hv = newHV (); |
497 | |
542 | |
498 | # define set(name, sv) hv_store (hv, # name, sizeof (# name) - 1, sv, 0) |
543 | # define set(name, sv) hv_store (hv, # name, sizeof (# name) - 1, sv, 0) |
499 | # define setiv(name, val) hv_store (hv, # name, sizeof (# name) - 1, newSViv (val), 0) |
544 | # define setiv(name, val) hv_store (hv, # name, sizeof (# name) - 1, newSViv (val), 0) |
500 | # undef set |
545 | # undef set |
501 | |
546 | |
502 | setiv (type, xe->type); |
547 | setiv (type, xe->type); |
503 | setiv (send_event, xe->xany.send_event); |
548 | setiv (send_event, xe->xany.send_event); |
504 | setiv (serial, xe->xany.serial); |
549 | setiv (serial, xe->xany.serial); |
505 | |
550 | |
506 | switch (xe->type) |
551 | switch (xe->type) |
|
|
552 | { |
|
|
553 | case KeyPress: |
|
|
554 | case KeyRelease: |
|
|
555 | case ButtonPress: |
|
|
556 | case ButtonRelease: |
|
|
557 | case MotionNotify: |
|
|
558 | setiv (time, xe->xmotion.time); |
|
|
559 | setiv (x, xe->xmotion.x); |
|
|
560 | setiv (y, xe->xmotion.y); |
|
|
561 | setiv (row, xe->xmotion.y / term->fheight); |
|
|
562 | setiv (col, xe->xmotion.x / term->fwidth); |
|
|
563 | setiv (x_root, xe->xmotion.x_root); |
|
|
564 | setiv (y_root, xe->xmotion.y_root); |
|
|
565 | setiv (state, xe->xmotion.state); |
|
|
566 | break; |
|
|
567 | } |
|
|
568 | |
|
|
569 | switch (xe->type) |
|
|
570 | { |
|
|
571 | case KeyPress: |
|
|
572 | case KeyRelease: |
|
|
573 | setiv (keycode, xe->xkey.keycode); |
|
|
574 | break; |
|
|
575 | |
|
|
576 | case ButtonPress: |
|
|
577 | case ButtonRelease: |
|
|
578 | setiv (button, xe->xbutton.button); |
|
|
579 | break; |
|
|
580 | |
|
|
581 | case MotionNotify: |
|
|
582 | setiv (is_hint, xe->xmotion.is_hint); |
|
|
583 | break; |
|
|
584 | } |
|
|
585 | |
|
|
586 | XPUSHs (sv_2mortal (newRV_noinc ((SV *)hv))); |
|
|
587 | } |
|
|
588 | break; |
|
|
589 | |
|
|
590 | case DT_END: |
507 | { |
591 | { |
508 | case KeyPress: |
592 | va_end (ap); |
509 | case KeyRelease: |
593 | |
510 | case ButtonPress: |
594 | PUTBACK; |
511 | case ButtonRelease: |
595 | int count = call_pv ("urxvt::invoke", G_ARRAY | G_EVAL); |
512 | case MotionNotify: |
596 | SPAGAIN; |
513 | setiv (time, xe->xmotion.time); |
597 | |
514 | setiv (x, xe->xmotion.x); |
598 | if (count) |
515 | setiv (y, xe->xmotion.y); |
|
|
516 | setiv (row, xe->xmotion.y / term->fheight); |
|
|
517 | setiv (col, xe->xmotion.x / term->fwidth); |
|
|
518 | setiv (x_root, xe->xmotion.x_root); |
|
|
519 | setiv (y_root, xe->xmotion.y_root); |
|
|
520 | setiv (state, xe->xmotion.state); |
|
|
521 | break; |
599 | { |
|
|
600 | SV *status = POPs; |
|
|
601 | count = SvTRUE (status); |
|
|
602 | } |
|
|
603 | |
|
|
604 | PUTBACK; |
|
|
605 | FREETMPS; |
|
|
606 | LEAVE; |
|
|
607 | |
|
|
608 | if (SvTRUE (ERRSV)) |
|
|
609 | { |
|
|
610 | rxvt_warn ("perl hook %d evaluation error: %s", htype, SvPV_nolen (ERRSV)); |
|
|
611 | ungrab (term); // better lose the grab than the session |
|
|
612 | } |
|
|
613 | |
|
|
614 | if (htype == HOOK_DESTROY) |
|
|
615 | { |
|
|
616 | clearSVptr ((SV *)term->perl.self); |
|
|
617 | SvREFCNT_dec ((SV *)term->perl.self); |
|
|
618 | } |
|
|
619 | |
|
|
620 | swap (perl_environ, environ); |
|
|
621 | return count; |
522 | } |
622 | } |
523 | |
623 | |
524 | switch (xe->type) |
|
|
525 | { |
|
|
526 | case KeyPress: |
|
|
527 | case KeyRelease: |
|
|
528 | setiv (keycode, xe->xkey.keycode); |
|
|
529 | break; |
|
|
530 | |
|
|
531 | case ButtonPress: |
|
|
532 | case ButtonRelease: |
|
|
533 | setiv (button, xe->xbutton.button); |
|
|
534 | break; |
|
|
535 | |
|
|
536 | case MotionNotify: |
|
|
537 | setiv (is_hint, xe->xmotion.is_hint); |
|
|
538 | break; |
|
|
539 | } |
|
|
540 | |
|
|
541 | XPUSHs (sv_2mortal (newRV_noinc ((SV *)hv))); |
|
|
542 | } |
|
|
543 | break; |
|
|
544 | |
|
|
545 | case DT_END: |
|
|
546 | { |
|
|
547 | va_end (ap); |
|
|
548 | |
|
|
549 | PUTBACK; |
|
|
550 | int count = call_pv ("urxvt::invoke", G_ARRAY | G_EVAL); |
|
|
551 | SPAGAIN; |
|
|
552 | |
|
|
553 | if (count) |
|
|
554 | { |
|
|
555 | SV *status = POPs; |
|
|
556 | count = SvTRUE (status); |
|
|
557 | } |
|
|
558 | |
|
|
559 | PUTBACK; |
|
|
560 | FREETMPS; |
|
|
561 | LEAVE; |
|
|
562 | |
|
|
563 | if (SvTRUE (ERRSV)) |
|
|
564 | rxvt_warn ("perl hook %d evaluation error: %s", htype, SvPV_nolen (ERRSV)); |
|
|
565 | |
|
|
566 | if (htype == HOOK_DESTROY) |
|
|
567 | { |
|
|
568 | clearSVptr ((SV *)term->perl.self); |
|
|
569 | SvREFCNT_dec ((SV *)term->perl.self); |
|
|
570 | } |
|
|
571 | |
|
|
572 | return count; |
|
|
573 | } |
|
|
574 | |
|
|
575 | default: |
624 | default: |
576 | rxvt_fatal ("FATAL: unable to pass data type %d\n", dt); |
625 | rxvt_fatal ("FATAL: unable to pass data type %d\n", dt); |
|
|
626 | } |
577 | } |
627 | } |
578 | } |
628 | } |
|
|
629 | catch (...) |
|
|
630 | { |
|
|
631 | swap (perl_environ, environ); |
|
|
632 | throw; |
|
|
633 | } |
579 | } |
634 | } |
580 | |
635 | |
581 | ///////////////////////////////////////////////////////////////////////////// |
636 | ///////////////////////////////////////////////////////////////////////////// |
582 | |
637 | |
583 | MODULE = urxvt PACKAGE = urxvt |
638 | MODULE = urxvt PACKAGE = urxvt |
584 | |
639 | |
585 | PROTOTYPES: ENABLE |
640 | PROTOTYPES: ENABLE |
586 | |
641 | |
587 | BOOT: |
642 | BOOT: |
588 | { |
643 | { |
589 | HV *stash = gv_stashpv ("urxvt", 1); |
644 | sv_setsv (get_sv ("urxvt::LIBDIR", 1), newSVpvn (LIBDIR, sizeof (LIBDIR) - 1)); |
590 | # define export_const_iv(name) newCONSTSUB (stash, # name, newSViv (name)); |
645 | sv_setsv (get_sv ("urxvt::RESNAME", 1), newSVpvn (RESNAME, sizeof (RESNAME) - 1)); |
|
|
646 | sv_setsv (get_sv ("urxvt::RESCLASS", 1), newSVpvn (RESCLASS, sizeof (RESCLASS) - 1)); |
|
|
647 | sv_setsv (get_sv ("urxvt::RXVTNAME", 1), newSVpvn (RXVTNAME, sizeof (RXVTNAME) - 1)); |
591 | |
648 | |
592 | AV *hookname = get_av ("urxvt::HOOKNAME", 1); |
649 | AV *hookname = get_av ("urxvt::HOOKNAME", 1); |
593 | # define def(sym) av_store (hookname, HOOK_ ## sym, newSVpv (# sym, 0)); |
650 | # define def(sym) av_store (hookname, HOOK_ ## sym, newSVpv (# sym, 0)); |
594 | # include "hookinc.h" |
651 | # include "hookinc.h" |
595 | # undef def |
652 | # undef def |
596 | |
653 | |
597 | |
654 | HV *option = get_hv ("urxvt::OPTION", 1); |
|
|
655 | # define def(name,val) hv_store (option, # name, sizeof (# name) - 1, newSVuv (Opt_ ## name), 0); |
|
|
656 | # define nodef(name) |
|
|
657 | # include "optinc.h" |
|
|
658 | # undef nodef |
|
|
659 | # undef def |
|
|
660 | |
|
|
661 | HV *stash = gv_stashpv ("urxvt", 1); |
|
|
662 | # define export_const_iv(name) newCONSTSUB (stash, # name, newSViv (name)); |
598 | export_const_iv (DEFAULT_RSTYLE); |
663 | export_const_iv (DEFAULT_RSTYLE); |
599 | export_const_iv (OVERLAY_RSTYLE); |
664 | export_const_iv (OVERLAY_RSTYLE); |
600 | export_const_iv (RS_Bold); |
665 | export_const_iv (RS_Bold); |
601 | export_const_iv (RS_Italic); |
666 | export_const_iv (RS_Italic); |
602 | export_const_iv (RS_Blink); |
667 | export_const_iv (RS_Blink); |
… | |
… | |
617 | export_const_iv (Button3Mask); |
682 | export_const_iv (Button3Mask); |
618 | export_const_iv (Button4Mask); |
683 | export_const_iv (Button4Mask); |
619 | export_const_iv (Button5Mask); |
684 | export_const_iv (Button5Mask); |
620 | export_const_iv (AnyModifier); |
685 | export_const_iv (AnyModifier); |
621 | |
686 | |
622 | sv_setsv (get_sv ("urxvt::LIBDIR", 1), newSVpvn (LIBDIR, sizeof (LIBDIR) - 1)); |
687 | export_const_iv (EVENT_NONE); |
|
|
688 | export_const_iv (EVENT_READ); |
|
|
689 | export_const_iv (EVENT_WRITE); |
623 | } |
690 | } |
|
|
691 | |
|
|
692 | void |
|
|
693 | set_should_invoke (int htype, int value) |
|
|
694 | CODE: |
|
|
695 | rxvt_perl.should_invoke [htype] = value; |
|
|
696 | |
|
|
697 | void |
|
|
698 | warn (const char *msg) |
|
|
699 | CODE: |
|
|
700 | rxvt_warn ("%s", msg); |
|
|
701 | |
|
|
702 | void |
|
|
703 | fatal (const char *msg) |
|
|
704 | CODE: |
|
|
705 | rxvt_fatal ("%s", msg); |
624 | |
706 | |
625 | SV * |
707 | SV * |
626 | new (...) |
708 | untaint (SV *sv) |
627 | CODE: |
709 | CODE: |
628 | { |
710 | RETVAL = newSVsv (sv); |
629 | stringvec *argv = new stringvec; |
711 | SvTAINTED_off (RETVAL); |
630 | bool success; |
712 | OUTPUT: |
631 | |
|
|
632 | for (int i = 0; i < items ;i++) |
|
|
633 | argv->push_back (strdup (SvPVbyte_nolen (ST (i)))); |
|
|
634 | |
|
|
635 | rxvt_term *term = new rxvt_term; |
|
|
636 | |
|
|
637 | term->argv = argv; |
|
|
638 | |
|
|
639 | try |
|
|
640 | { |
|
|
641 | if (!term->init (argv->size (), argv->begin ())) |
|
|
642 | term = 0; |
|
|
643 | } |
|
|
644 | catch (const class rxvt_failure_exception &e) |
|
|
645 | { |
|
|
646 | term->destroy (); |
|
|
647 | croak ("exception caught while initializing new terminal instance"); |
|
|
648 | } |
|
|
649 | |
|
|
650 | RETVAL = term && term->perl.self ? newSVterm (term) : &PL_sv_undef; |
|
|
651 | } |
|
|
652 | OUTPUT: |
|
|
653 | RETVAL |
713 | RETVAL |
654 | |
714 | |
655 | void |
715 | bool |
656 | set_should_invoke (int htype, int value) |
716 | safe () |
657 | CODE: |
717 | CODE: |
658 | rxvt_perl.should_invoke [htype] = value; |
718 | RETVAL = !rxvt_tainted (); |
659 | |
719 | OUTPUT: |
660 | void |
720 | RETVAL |
661 | warn (const char *msg) |
|
|
662 | CODE: |
|
|
663 | rxvt_warn ("%s", msg); |
|
|
664 | |
|
|
665 | void |
|
|
666 | fatal (const char *msg) |
|
|
667 | CODE: |
|
|
668 | rxvt_fatal ("%s", msg); |
|
|
669 | |
721 | |
670 | NV |
722 | NV |
671 | NOW () |
723 | NOW () |
672 | CODE: |
724 | CODE: |
673 | RETVAL = NOW; |
725 | RETVAL = NOW; |
… | |
… | |
722 | OUTPUT: |
774 | OUTPUT: |
723 | RETVAL |
775 | RETVAL |
724 | |
776 | |
725 | MODULE = urxvt PACKAGE = urxvt::term |
777 | MODULE = urxvt PACKAGE = urxvt::term |
726 | |
778 | |
|
|
779 | SV * |
|
|
780 | _new (...) |
|
|
781 | CODE: |
|
|
782 | { |
|
|
783 | if (items < 1 || !SvROK (ST (0)) || SvTYPE (SvRV (ST (0))) != SVt_PVAV) |
|
|
784 | croak ("first argument to urxvt::term->_new must be arrayref"); |
|
|
785 | |
|
|
786 | rxvt_term *term = new rxvt_term; |
|
|
787 | |
|
|
788 | term->argv = new stringvec; |
|
|
789 | term->envv = new stringvec; |
|
|
790 | |
|
|
791 | for (int i = 1; i < items; i++) |
|
|
792 | term->argv->push_back (strdup (SvPVbyte_nolen (ST (i)))); |
|
|
793 | |
|
|
794 | AV *envv = (AV *)SvRV (ST (0)); |
|
|
795 | for (int i = av_len (envv) + 1; i--; ) |
|
|
796 | term->envv->push_back (strdup (SvPVbyte_nolen (*av_fetch (envv, i, 1)))); |
|
|
797 | |
|
|
798 | term->envv->push_back (0); |
|
|
799 | |
|
|
800 | bool success; |
|
|
801 | |
|
|
802 | try |
|
|
803 | { |
|
|
804 | success = term->init (term->argv->size (), term->argv->begin ()); |
|
|
805 | } |
|
|
806 | catch (const class rxvt_failure_exception &e) |
|
|
807 | { |
|
|
808 | success = false; |
|
|
809 | } |
|
|
810 | |
|
|
811 | if (!success) |
|
|
812 | { |
|
|
813 | term->destroy (); |
|
|
814 | croak ("error while initializing new terminal instance"); |
|
|
815 | } |
|
|
816 | |
|
|
817 | RETVAL = term && term->perl.self |
|
|
818 | ? newSVterm (term) : &PL_sv_undef; |
|
|
819 | } |
|
|
820 | OUTPUT: |
|
|
821 | RETVAL |
|
|
822 | |
727 | void |
823 | void |
728 | rxvt_term::destroy () |
824 | rxvt_term::destroy () |
729 | |
825 | |
730 | void |
826 | void |
731 | rxvt_term::grab_button (int button, U32 modifiers) |
827 | rxvt_term::grab_button (int button, U32 modifiers) |
732 | CODE: |
828 | CODE: |
733 | XGrabButton (THIS->display->display, button, modifiers, THIS->vt, 1, |
829 | XGrabButton (THIS->display->display, button, modifiers, THIS->vt, 1, |
734 | ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask, |
830 | ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask, |
735 | GrabModeSync, GrabModeSync, None, None); |
831 | GrabModeSync, GrabModeSync, None, GRAB_CURSOR); |
736 | |
832 | |
737 | bool |
833 | bool |
738 | rxvt_term::grab (U32 eventtime, int sync = 0) |
834 | rxvt_term::grab (U32 eventtime, int sync = 0) |
739 | CODE: |
835 | CODE: |
740 | { |
836 | { |
… | |
… | |
742 | |
838 | |
743 | THIS->perl.grabtime = 0; |
839 | THIS->perl.grabtime = 0; |
744 | |
840 | |
745 | if (!XGrabPointer (THIS->display->display, THIS->vt, 0, |
841 | if (!XGrabPointer (THIS->display->display, THIS->vt, 0, |
746 | ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask, |
842 | ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask, |
747 | mode, mode, None, None, eventtime)) |
843 | mode, mode, None, GRAB_CURSOR, eventtime)) |
748 | if (!XGrabKeyboard (THIS->display->display, THIS->vt, 0, mode, mode, eventtime)) |
844 | if (!XGrabKeyboard (THIS->display->display, THIS->vt, 0, mode, mode, eventtime)) |
749 | THIS->perl.grabtime = eventtime; |
845 | THIS->perl.grabtime = eventtime; |
750 | else |
846 | else |
751 | XUngrabPointer (THIS->display->display, eventtime); |
847 | XUngrabPointer (THIS->display->display, eventtime); |
752 | |
848 | |
… | |
… | |
754 | } |
850 | } |
755 | OUTPUT: |
851 | OUTPUT: |
756 | RETVAL |
852 | RETVAL |
757 | |
853 | |
758 | void |
854 | void |
759 | rxvt_term::allow_events_async (U32 eventtime = THIS->perl.grabtime) |
855 | rxvt_term::allow_events_async () |
760 | CODE: |
856 | CODE: |
761 | XAllowEvents (THIS->display->display, AsyncBoth, eventtime); |
857 | XAllowEvents (THIS->display->display, AsyncBoth, THIS->perl.grabtime); |
762 | |
858 | |
763 | void |
859 | void |
764 | rxvt_term::allow_events_sync (U32 eventtime = THIS->perl.grabtime) |
860 | rxvt_term::allow_events_sync () |
765 | CODE: |
861 | CODE: |
766 | XAllowEvents (THIS->display->display, SyncBoth, eventtime); |
862 | XAllowEvents (THIS->display->display, SyncBoth, THIS->perl.grabtime); |
767 | |
863 | |
768 | void |
864 | void |
769 | rxvt_term::allow_events_replay (U32 eventtime = THIS->perl.grabtime) |
865 | rxvt_term::allow_events_replay () |
770 | CODE: |
866 | CODE: |
771 | XAllowEvents (THIS->display->display, ReplayPointer, eventtime); |
867 | XAllowEvents (THIS->display->display, ReplayPointer, THIS->perl.grabtime); |
772 | XAllowEvents (THIS->display->display, ReplayKeyboard, eventtime); |
868 | XAllowEvents (THIS->display->display, ReplayKeyboard, THIS->perl.grabtime); |
773 | |
869 | |
774 | void |
870 | void |
775 | rxvt_term::ungrab (U32 eventtime = THIS->perl.grabtime) |
871 | rxvt_term::ungrab () |
776 | CODE: |
872 | CODE: |
777 | THIS->perl.grabtime = 0; |
873 | ungrab (THIS); |
778 | XUngrabKeyboard (THIS->display->display, eventtime); |
|
|
779 | XUngrabPointer (THIS->display->display, eventtime); |
|
|
780 | |
874 | |
781 | int |
875 | int |
782 | rxvt_term::strwidth (SV *str) |
876 | rxvt_term::strwidth (SV *str) |
783 | CODE: |
877 | CODE: |
784 | { |
878 | { |
… | |
… | |
803 | char *mbstr = rxvt_wcstombs (wstr); |
897 | char *mbstr = rxvt_wcstombs (wstr); |
804 | rxvt_pop_locale (); |
898 | rxvt_pop_locale (); |
805 | |
899 | |
806 | free (wstr); |
900 | free (wstr); |
807 | |
901 | |
808 | RETVAL = newSVpv (mbstr, 0); |
902 | RETVAL = taint_if (newSVpv (mbstr, 0), str); |
809 | free (mbstr); |
903 | free (mbstr); |
810 | } |
904 | } |
811 | OUTPUT: |
905 | OUTPUT: |
812 | RETVAL |
906 | RETVAL |
813 | |
907 | |
… | |
… | |
820 | |
914 | |
821 | rxvt_push_locale (THIS->locale); |
915 | rxvt_push_locale (THIS->locale); |
822 | wchar_t *wstr = rxvt_mbstowcs (data, len); |
916 | wchar_t *wstr = rxvt_mbstowcs (data, len); |
823 | rxvt_pop_locale (); |
917 | rxvt_pop_locale (); |
824 | |
918 | |
825 | RETVAL = wcs2sv (wstr); |
919 | RETVAL = taint_if (wcs2sv (wstr), octets); |
826 | free (wstr); |
920 | free (wstr); |
827 | } |
921 | } |
828 | OUTPUT: |
922 | OUTPUT: |
829 | RETVAL |
923 | RETVAL |
830 | |
924 | |
… | |
… | |
877 | case 2: RETVAL = THIS->ModNumLockMask; break; |
971 | case 2: RETVAL = THIS->ModNumLockMask; break; |
878 | } |
972 | } |
879 | OUTPUT: |
973 | OUTPUT: |
880 | RETVAL |
974 | RETVAL |
881 | |
975 | |
|
|
976 | char * |
|
|
977 | rxvt_term::display_id () |
|
|
978 | ALIAS: |
|
|
979 | display_id = 0 |
|
|
980 | locale = 1 |
|
|
981 | CODE: |
|
|
982 | switch (ix) |
|
|
983 | { |
|
|
984 | case 0: RETVAL = THIS->display->id; break; |
|
|
985 | case 1: RETVAL = THIS->locale; break; |
|
|
986 | } |
|
|
987 | OUTPUT: |
|
|
988 | RETVAL |
|
|
989 | |
|
|
990 | SV * |
|
|
991 | rxvt_term::_env () |
|
|
992 | CODE: |
|
|
993 | { |
|
|
994 | if (THIS->envv) |
|
|
995 | { |
|
|
996 | AV *av = newAV (); |
|
|
997 | |
|
|
998 | for (char **i = THIS->envv->begin (); i != THIS->envv->end (); ++i) |
|
|
999 | if (*i) |
|
|
1000 | av_push (av, newSVpv (*i, 0)); |
|
|
1001 | |
|
|
1002 | RETVAL = newRV_noinc ((SV *)av); |
|
|
1003 | } |
|
|
1004 | else |
|
|
1005 | RETVAL = &PL_sv_undef; |
|
|
1006 | } |
|
|
1007 | OUTPUT: |
|
|
1008 | RETVAL |
|
|
1009 | |
|
|
1010 | int |
|
|
1011 | rxvt_term::pty_ev_events (int events = EVENT_UNDEF) |
|
|
1012 | CODE: |
|
|
1013 | RETVAL = THIS->pty_ev.events; |
|
|
1014 | if (events != EVENT_UNDEF) |
|
|
1015 | THIS->pty_ev.set (events); |
|
|
1016 | OUTPUT: |
|
|
1017 | RETVAL |
|
|
1018 | |
882 | U32 |
1019 | U32 |
883 | rxvt_term::parent () |
1020 | rxvt_term::parent () |
884 | CODE: |
1021 | CODE: |
885 | RETVAL = (U32)THIS->parent [0]; |
1022 | RETVAL = (U32)THIS->parent [0]; |
886 | OUTPUT: |
1023 | OUTPUT: |
… | |
… | |
937 | wchar_t *wstr = new wchar_t [THIS->ncol]; |
1074 | wchar_t *wstr = new wchar_t [THIS->ncol]; |
938 | |
1075 | |
939 | for (int col = 0; col < THIS->ncol; col++) |
1076 | for (int col = 0; col < THIS->ncol; col++) |
940 | wstr [col] = l.t [col]; |
1077 | wstr [col] = l.t [col]; |
941 | |
1078 | |
942 | XPUSHs (sv_2mortal (wcs2sv (wstr, THIS->ncol))); |
1079 | XPUSHs (taint (sv_2mortal (wcs2sv (wstr, THIS->ncol)))); |
943 | |
1080 | |
944 | delete [] wstr; |
1081 | delete [] wstr; |
945 | } |
1082 | } |
946 | |
1083 | |
947 | if (new_text) |
1084 | if (new_text) |
… | |
… | |
1068 | else |
1205 | else |
1069 | *r++ = *s; |
1206 | *r++ = *s; |
1070 | |
1207 | |
1071 | rxvt_pop_locale (); |
1208 | rxvt_pop_locale (); |
1072 | |
1209 | |
1073 | RETVAL = wcs2sv (rstr, r - rstr); |
1210 | RETVAL = taint_if (wcs2sv (rstr, r - rstr), string); |
1074 | |
1211 | |
1075 | delete [] rstr; |
1212 | delete [] rstr; |
1076 | } |
1213 | } |
1077 | OUTPUT: |
1214 | OUTPUT: |
1078 | RETVAL |
1215 | RETVAL |
… | |
… | |
1104 | else if (IS_COMPOSE (*s)) |
1241 | else if (IS_COMPOSE (*s)) |
1105 | r += rxvt_composite.expand (*s, r); |
1242 | r += rxvt_composite.expand (*s, r); |
1106 | else |
1243 | else |
1107 | *r++ = *s; |
1244 | *r++ = *s; |
1108 | |
1245 | |
1109 | RETVAL = wcs2sv (rstr, r - rstr); |
1246 | RETVAL = taint_if (wcs2sv (rstr, r - rstr), text); |
1110 | |
1247 | |
1111 | delete [] rstr; |
1248 | delete [] rstr; |
1112 | } |
1249 | } |
1113 | OUTPUT: |
1250 | OUTPUT: |
1114 | RETVAL |
1251 | RETVAL |
… | |
… | |
1136 | |
1273 | |
1137 | if (!IN_RANGE_EXC (index, 0, NUM_RESOURCES)) |
1274 | if (!IN_RANGE_EXC (index, 0, NUM_RESOURCES)) |
1138 | croak ("requested out-of-bound resource %s+%d,", name, index - rs->value); |
1275 | croak ("requested out-of-bound resource %s+%d,", name, index - rs->value); |
1139 | |
1276 | |
1140 | if (GIMME_V != G_VOID) |
1277 | if (GIMME_V != G_VOID) |
1141 | XPUSHs (THIS->rs [index] ? sv_2mortal (newSVpv (THIS->rs [index], 0)) : &PL_sv_undef); |
1278 | XPUSHs (THIS->rs [index] ? sv_2mortal (taint (newSVpv (THIS->rs [index], 0))) : &PL_sv_undef); |
1142 | |
1279 | |
1143 | if (newval) |
1280 | if (newval) |
1144 | { |
1281 | { |
1145 | if (SvOK (newval)) |
1282 | if (SvOK (newval)) |
1146 | { |
1283 | { |
… | |
… | |
1151 | else |
1288 | else |
1152 | THIS->rs [index] = 0; |
1289 | THIS->rs [index] = 0; |
1153 | } |
1290 | } |
1154 | } |
1291 | } |
1155 | |
1292 | |
|
|
1293 | const char * |
|
|
1294 | rxvt_term::x_resource (const char *name) |
|
|
1295 | CLEANUP: |
|
|
1296 | SvTAINTED_on (ST (0)); |
|
|
1297 | |
|
|
1298 | bool |
|
|
1299 | rxvt_term::option (U32 optval, int set = -1) |
|
|
1300 | CODE: |
|
|
1301 | { |
|
|
1302 | RETVAL = THIS->options & optval; |
|
|
1303 | |
|
|
1304 | if (set >= 0) |
|
|
1305 | { |
|
|
1306 | if (set) |
|
|
1307 | THIS->options |= optval; |
|
|
1308 | else |
|
|
1309 | THIS->options &= ~optval; |
|
|
1310 | |
|
|
1311 | switch (optval) |
|
|
1312 | { |
|
|
1313 | case Opt_skipBuiltinGlyphs: |
|
|
1314 | THIS->set_fonts (); |
|
|
1315 | THIS->scr_remap_chars (); |
|
|
1316 | THIS->scr_touch (true); |
|
|
1317 | THIS->want_refresh = 1; |
|
|
1318 | break; |
|
|
1319 | |
|
|
1320 | case Opt_cursorUnderline: |
|
|
1321 | THIS->want_refresh = 1; |
|
|
1322 | break; |
|
|
1323 | |
|
|
1324 | # case Opt_scrollBar_floating: |
|
|
1325 | # case Opt_scrollBar_right: |
|
|
1326 | # THIS->resize_all_windows (THIS->width, THIS->height, 1); |
|
|
1327 | # break; |
|
|
1328 | } |
|
|
1329 | } |
|
|
1330 | } |
|
|
1331 | OUTPUT: |
|
|
1332 | RETVAL |
|
|
1333 | |
|
|
1334 | bool |
|
|
1335 | rxvt_term::parse_keysym (char *keysym, char *str) |
|
|
1336 | CODE: |
|
|
1337 | RETVAL = 0 < THIS->parse_keysym (keysym, str); |
|
|
1338 | THIS->keyboard->register_done (); |
|
|
1339 | OUTPUT: |
|
|
1340 | RETVAL |
|
|
1341 | |
1156 | void |
1342 | void |
1157 | rxvt_term::cur (...) |
1343 | rxvt_term::screen_cur (...) |
1158 | PROTOTYPE: $;$$ |
1344 | PROTOTYPE: $;$$ |
1159 | ALIAS: |
1345 | ALIAS: |
1160 | screen_cur = 0 |
1346 | screen_cur = 0 |
1161 | selection_beg = 1 |
1347 | selection_beg = 1 |
1162 | selection_end = 2 |
1348 | selection_end = 2 |
… | |
… | |
1183 | if (ix) |
1369 | if (ix) |
1184 | THIS->want_refresh = 1; |
1370 | THIS->want_refresh = 1; |
1185 | } |
1371 | } |
1186 | } |
1372 | } |
1187 | |
1373 | |
|
|
1374 | char |
|
|
1375 | rxvt_term::cur_charset () |
|
|
1376 | CODE: |
|
|
1377 | RETVAL = THIS->charsets [THIS->screen.charset]; |
|
|
1378 | OUTPUT: |
|
|
1379 | RETVAL |
|
|
1380 | |
1188 | int |
1381 | int |
1189 | rxvt_term::selection_grab (U32 eventtime) |
1382 | rxvt_term::selection_grab (U32 eventtime) |
1190 | |
1383 | |
1191 | void |
1384 | void |
1192 | rxvt_term::selection (SV *newtext = 0) |
1385 | rxvt_term::selection (SV *newtext = 0) |
1193 | PPCODE: |
1386 | PPCODE: |
1194 | { |
1387 | { |
1195 | if (GIMME_V != G_VOID) |
1388 | if (GIMME_V != G_VOID) |
|
|
1389 | XPUSHs (THIS->selection.text |
1196 | XPUSHs (sv_2mortal (wcs2sv (THIS->selection.text, THIS->selection.len))); |
1390 | ? taint (sv_2mortal (wcs2sv (THIS->selection.text, THIS->selection.len))) |
|
|
1391 | : &PL_sv_undef); |
1197 | |
1392 | |
1198 | if (newtext) |
1393 | if (newtext) |
1199 | { |
1394 | { |
1200 | free (THIS->selection.text); |
1395 | free (THIS->selection.text); |
1201 | |
1396 | |
1202 | THIS->selection.text = sv2wcs (newtext); |
1397 | THIS->selection.text = sv2wcs (newtext); |
1203 | THIS->selection.len = wcslen (THIS->selection.text); |
1398 | THIS->selection.len = wcslen (THIS->selection.text); |
1204 | } |
1399 | } |
1205 | } |
1400 | } |
|
|
1401 | |
|
|
1402 | void |
|
|
1403 | 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) |
|
|
1404 | |
|
|
1405 | void |
|
|
1406 | rxvt_term::scr_xor_span (int beg_row, int beg_col, int end_row, int end_col, U32 rstyle = RS_RVid) |
|
|
1407 | |
|
|
1408 | void |
|
|
1409 | rxvt_term::scr_bell () |
1206 | |
1410 | |
1207 | void |
1411 | void |
1208 | rxvt_term::scr_add_lines (SV *string) |
1412 | rxvt_term::scr_add_lines (SV *string) |
1209 | CODE: |
1413 | CODE: |
1210 | { |
1414 | { |