… | |
… | |
26 | #include <XSUB.h> |
26 | #include <XSUB.h> |
27 | #undef line_t |
27 | #undef line_t |
28 | |
28 | |
29 | #include "../config.h" |
29 | #include "../config.h" |
30 | |
30 | |
|
|
31 | #include <cstddef> |
31 | #include <cstdarg> |
32 | #include <cstdarg> |
32 | |
33 | |
|
|
34 | #include "iom.h" |
33 | #include "rxvt.h" |
35 | #include "rxvt.h" |
34 | #include "iom.h" |
36 | #include "keyboard.h" |
35 | #include "rxvtutil.h" |
37 | #include "rxvtutil.h" |
36 | #include "rxvtperl.h" |
38 | #include "rxvtperl.h" |
37 | |
39 | |
38 | #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 |
39 | |
47 | |
40 | #undef LINENO |
48 | #undef LINENO |
41 | #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) |
42 | #undef ROW |
50 | #undef ROW |
43 | #define ROW(n) THIS->row_buf [LINENO (n)] |
51 | #define ROW(n) THIS->row_buf [LINENO (n)] |
44 | |
52 | |
45 | ///////////////////////////////////////////////////////////////////////////// |
53 | ///////////////////////////////////////////////////////////////////////////// |
46 | |
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 | } |
|
|
70 | |
47 | static wchar_t * |
71 | static wchar_t * |
48 | sv2wcs (SV *sv) |
72 | sv2wcs (SV *sv) |
49 | { |
73 | { |
50 | STRLEN len; |
74 | STRLEN len; |
51 | char *str = SvPVutf8 (sv, len); |
75 | char *str = SvPVutf8 (sv, len); |
… | |
… | |
101 | croak ("perl code used %s object, but C++ object is already destroyed, caught", klass); |
125 | croak ("perl code used %s object, but C++ object is already destroyed, caught", klass); |
102 | |
126 | |
103 | return (long)mg->mg_ptr; |
127 | return (long)mg->mg_ptr; |
104 | } |
128 | } |
105 | |
129 | |
106 | #define newSVterm(term) SvREFCNT_inc ((SV *)term->self) |
130 | #define newSVterm(term) SvREFCNT_inc ((SV *)term->perl.self) |
107 | #define SvTERM(sv) (rxvt_term *)SvPTR (sv, "urxvt::term") |
131 | #define SvTERM(sv) (rxvt_term *)SvPTR (sv, "urxvt::term") |
108 | |
132 | |
109 | ///////////////////////////////////////////////////////////////////////////// |
133 | ///////////////////////////////////////////////////////////////////////////// |
110 | |
134 | |
111 | struct perl_watcher |
135 | struct perl_watcher |
… | |
… | |
290 | void |
314 | void |
291 | overlay::show () |
315 | overlay::show () |
292 | { |
316 | { |
293 | char key[33]; sprintf (key, "%32lx", (long)this); |
317 | char key[33]; sprintf (key, "%32lx", (long)this); |
294 | |
318 | |
295 | HV *hv = (HV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)THIS->self), "_overlay", 8, 0)); |
319 | HV *hv = (HV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)THIS->perl.self), "_overlay", 8, 0)); |
296 | hv_store (hv, key, 32, newSViv ((long)this), 0); |
320 | hv_store (hv, key, 32, newSViv ((long)this), 0); |
297 | } |
321 | } |
298 | |
322 | |
299 | void |
323 | void |
300 | overlay::hide () |
324 | overlay::hide () |
301 | { |
325 | { |
302 | SV **ovs = hv_fetch ((HV *)SvRV ((SV *)THIS->self), "_overlay", 8, 0); |
326 | SV **ovs = hv_fetch ((HV *)SvRV ((SV *)THIS->perl.self), "_overlay", 8, 0); |
303 | |
327 | |
304 | if (ovs) |
328 | if (ovs) |
305 | { |
329 | { |
306 | char key[33]; sprintf (key, "%32lx", (long)this); |
330 | char key[33]; sprintf (key, "%32lx", (long)this); |
307 | |
331 | |
… | |
… | |
389 | { |
413 | { |
390 | if (!perl) |
414 | if (!perl) |
391 | { |
415 | { |
392 | char *argv[] = { |
416 | char *argv[] = { |
393 | "", |
417 | "", |
|
|
418 | "-T", |
394 | "-edo '" LIBDIR "/urxvt.pm' or ($@ and die $@) or exit 1", |
419 | "-edo '" LIBDIR "/urxvt.pm' or ($@ and die $@) or exit 1", |
395 | }; |
420 | }; |
396 | |
421 | |
397 | perl = perl_alloc (); |
422 | perl = perl_alloc (); |
398 | perl_construct (perl); |
423 | perl_construct (perl); |
399 | |
424 | |
400 | if (perl_parse (perl, xs_init, 2, argv, (char **)NULL) |
425 | if (perl_parse (perl, xs_init, 3, argv, (char **)NULL) |
401 | || perl_run (perl)) |
426 | || perl_run (perl)) |
402 | { |
427 | { |
403 | rxvt_warn ("unable to initialize perl-interpreter, continuing without.\n"); |
428 | rxvt_warn ("unable to initialize perl-interpreter, continuing without.\n"); |
404 | |
429 | |
405 | perl_destruct (perl); |
430 | perl_destruct (perl); |
… | |
… | |
407 | perl = 0; |
432 | perl = 0; |
408 | } |
433 | } |
409 | } |
434 | } |
410 | } |
435 | } |
411 | |
436 | |
|
|
437 | static void |
|
|
438 | ungrab (rxvt_term *THIS) |
|
|
439 | { |
|
|
440 | if (THIS->perl.grabtime) |
|
|
441 | { |
|
|
442 | XUngrabKeyboard (THIS->display->display, THIS->perl.grabtime); |
|
|
443 | XUngrabPointer (THIS->display->display, THIS->perl.grabtime); |
|
|
444 | THIS->perl.grabtime = 0; |
|
|
445 | } |
|
|
446 | } |
|
|
447 | |
412 | bool |
448 | bool |
413 | rxvt_perl_interp::invoke (rxvt_term *term, hook_type htype, ...) |
449 | rxvt_perl_interp::invoke (rxvt_term *term, hook_type htype, ...) |
414 | { |
450 | { |
415 | if (!perl) |
451 | if (!perl) |
416 | return false; |
452 | return false; |
417 | |
453 | |
418 | if (htype == HOOK_INIT) // first hook ever called |
454 | if (htype == HOOK_INIT) // first hook ever called |
419 | { |
455 | { |
420 | term->self = (void *)newSVptr ((void *)term, "urxvt::term"); |
456 | term->perl.self = (void *)newSVptr ((void *)term, "urxvt::term"); |
421 | hv_store ((HV *)SvRV ((SV *)term->self), "_overlay", 8, newRV_noinc ((SV *)newHV ()), 0); |
457 | hv_store ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, newRV_noinc ((SV *)newHV ()), 0); |
422 | } |
458 | } |
423 | else if (!term->self) |
459 | else if (!term->perl.self) |
424 | return false; // perl not initialized for this instance |
460 | return false; // perl not initialized for this instance |
425 | else if (htype == HOOK_DESTROY) |
461 | else if (htype == HOOK_DESTROY) |
426 | { |
462 | { |
427 | // handled later |
463 | // handled later |
428 | } |
464 | } |
429 | else if (htype == HOOK_REFRESH_BEGIN || htype == HOOK_REFRESH_END) |
465 | else |
430 | { |
466 | { |
431 | HV *hv = (HV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->self), "_overlay", 8, 0)); |
467 | if (htype == HOOK_REFRESH_BEGIN || htype == HOOK_REFRESH_END) |
432 | |
|
|
433 | if (HvKEYS (hv)) |
|
|
434 | { |
468 | { |
|
|
469 | HV *hv = (HV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, 0)); |
|
|
470 | |
|
|
471 | if (HvKEYS (hv)) |
|
|
472 | { |
435 | hv_iterinit (hv); |
473 | hv_iterinit (hv); |
436 | |
474 | |
437 | while (HE *he = hv_iternext (hv)) |
475 | while (HE *he = hv_iternext (hv)) |
438 | ((overlay *)SvIV (hv_iterval (hv, he)))->swap (); |
476 | ((overlay *)SvIV (hv_iterval (hv, he)))->swap (); |
|
|
477 | } |
|
|
478 | |
439 | } |
479 | } |
|
|
480 | |
|
|
481 | if (!should_invoke [htype]) |
|
|
482 | return false; |
440 | } |
483 | } |
441 | else if (!should_invoke [htype]) |
|
|
442 | return false; |
|
|
443 | |
484 | |
444 | dSP; |
485 | dSP; |
445 | va_list ap; |
486 | va_list ap; |
446 | |
487 | |
447 | va_start (ap, htype); |
488 | va_start (ap, htype); |
… | |
… | |
465 | |
506 | |
466 | case DT_LONG: |
507 | case DT_LONG: |
467 | XPUSHs (sv_2mortal (newSViv (va_arg (ap, long)))); |
508 | XPUSHs (sv_2mortal (newSViv (va_arg (ap, long)))); |
468 | break; |
509 | break; |
469 | |
510 | |
470 | case DT_STRING: |
511 | case DT_STR: |
471 | XPUSHs (sv_2mortal (newSVpv (va_arg (ap, char *), 0))); |
512 | XPUSHs (taint (sv_2mortal (newSVpv (va_arg (ap, char *), 0)))); |
472 | break; |
513 | break; |
473 | |
514 | |
474 | case DT_STRING_LEN: |
515 | case DT_STR_LEN: |
475 | { |
516 | { |
476 | char *str = va_arg (ap, char *); |
517 | char *str = va_arg (ap, char *); |
477 | int len = va_arg (ap, int); |
518 | int len = va_arg (ap, int); |
478 | |
519 | |
479 | XPUSHs (sv_2mortal (newSVpvn (str, len))); |
520 | XPUSHs (taint (sv_2mortal (newSVpvn (str, len)))); |
480 | } |
521 | } |
481 | break; |
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 (taint (sv_2mortal (wcs2sv (wstr, wlen)))); |
|
|
530 | } |
|
|
531 | break; |
482 | |
532 | |
483 | case DT_XEVENT: |
533 | case DT_XEVENT: |
484 | { |
534 | { |
485 | XEvent *xe = va_arg (ap, XEvent *); |
535 | XEvent *xe = va_arg (ap, XEvent *); |
486 | HV *hv = newHV (); |
536 | HV *hv = newHV (); |
… | |
… | |
530 | |
580 | |
531 | XPUSHs (sv_2mortal (newRV_noinc ((SV *)hv))); |
581 | XPUSHs (sv_2mortal (newRV_noinc ((SV *)hv))); |
532 | } |
582 | } |
533 | break; |
583 | break; |
534 | |
584 | |
535 | case DT_USTRING_LEN: |
|
|
536 | { |
|
|
537 | unicode_t *ustr = va_arg (ap, unicode_t *); |
|
|
538 | int ulen = va_arg (ap, int); |
|
|
539 | wchar_t *wstr = new wchar_t [ulen]; |
|
|
540 | |
|
|
541 | for (int i = ulen; i--; ) |
|
|
542 | wstr [i] = ustr [i]; |
|
|
543 | |
|
|
544 | XPUSHs (sv_2mortal (wcs2sv (wstr, ulen))); |
|
|
545 | |
|
|
546 | delete [] wstr; |
|
|
547 | } |
|
|
548 | |
|
|
549 | case DT_END: |
585 | case DT_END: |
550 | { |
586 | { |
551 | va_end (ap); |
587 | va_end (ap); |
552 | |
588 | |
553 | PUTBACK; |
589 | PUTBACK; |
… | |
… | |
563 | PUTBACK; |
599 | PUTBACK; |
564 | FREETMPS; |
600 | FREETMPS; |
565 | LEAVE; |
601 | LEAVE; |
566 | |
602 | |
567 | if (SvTRUE (ERRSV)) |
603 | if (SvTRUE (ERRSV)) |
|
|
604 | { |
568 | rxvt_warn ("perl hook %d evaluation error: %s", htype, SvPV_nolen (ERRSV)); |
605 | rxvt_warn ("perl hook %d evaluation error: %s", htype, SvPV_nolen (ERRSV)); |
|
|
606 | ungrab (term); // better lose the grab than the session |
|
|
607 | } |
569 | |
608 | |
570 | if (htype == HOOK_DESTROY) |
609 | if (htype == HOOK_DESTROY) |
571 | { |
610 | { |
572 | clearSVptr ((SV *)term->self); |
611 | clearSVptr ((SV *)term->perl.self); |
573 | SvREFCNT_dec ((SV *)term->self); |
612 | SvREFCNT_dec ((SV *)term->perl.self); |
574 | } |
613 | } |
575 | |
614 | |
576 | return count; |
615 | return count; |
577 | } |
616 | } |
578 | |
617 | |
… | |
… | |
588 | |
627 | |
589 | PROTOTYPES: ENABLE |
628 | PROTOTYPES: ENABLE |
590 | |
629 | |
591 | BOOT: |
630 | BOOT: |
592 | { |
631 | { |
593 | # define export_const(name) newCONSTSUB (gv_stashpv ("urxvt", 1), # name, newSViv (name)); |
632 | sv_setsv (get_sv ("urxvt::LIBDIR", 1), newSVpvn (LIBDIR, sizeof (LIBDIR) - 1)); |
|
|
633 | sv_setsv (get_sv ("urxvt::RESNAME", 1), newSVpvn (RESNAME, sizeof (RESNAME) - 1)); |
|
|
634 | sv_setsv (get_sv ("urxvt::RESCLASS", 1), newSVpvn (RESCLASS, sizeof (RESCLASS) - 1)); |
|
|
635 | sv_setsv (get_sv ("urxvt::RXVTNAME", 1), newSVpvn (RXVTNAME, sizeof (RXVTNAME) - 1)); |
|
|
636 | |
594 | AV *hookname = get_av ("urxvt::HOOKNAME", 1); |
637 | AV *hookname = get_av ("urxvt::HOOKNAME", 1); |
595 | # define def(sym) av_store (hookname, HOOK_ ## sym, newSVpv (# sym, 0)); |
638 | # define def(sym) av_store (hookname, HOOK_ ## sym, newSVpv (# sym, 0)); |
596 | # include "hookinc.h" |
639 | # include "hookinc.h" |
597 | # undef def |
640 | # undef def |
598 | |
641 | |
|
|
642 | HV *option = get_hv ("urxvt::OPTION", 1); |
|
|
643 | # define def(name,val) hv_store (option, # name, sizeof (# name) - 1, newSVuv (Opt_ ## name), 0); |
|
|
644 | # define nodef(name) |
|
|
645 | # include "optinc.h" |
|
|
646 | # undef nodef |
|
|
647 | # undef def |
|
|
648 | |
|
|
649 | HV *stash = gv_stashpv ("urxvt", 1); |
|
|
650 | # define export_const_iv(name) newCONSTSUB (stash, # name, newSViv (name)); |
599 | export_const (DEFAULT_RSTYLE); |
651 | export_const_iv (DEFAULT_RSTYLE); |
600 | export_const (OVERLAY_RSTYLE); |
652 | export_const_iv (OVERLAY_RSTYLE); |
601 | export_const (RS_Bold); |
653 | export_const_iv (RS_Bold); |
602 | export_const (RS_Italic); |
654 | export_const_iv (RS_Italic); |
603 | export_const (RS_Blink); |
655 | export_const_iv (RS_Blink); |
604 | export_const (RS_RVid); |
656 | export_const_iv (RS_RVid); |
605 | export_const (RS_Uline); |
657 | export_const_iv (RS_Uline); |
606 | |
658 | |
607 | sv_setpv (get_sv ("urxvt::LIBDIR", 1), LIBDIR); |
659 | export_const_iv (CurrentTime); |
|
|
660 | export_const_iv (ShiftMask); |
|
|
661 | export_const_iv (LockMask); |
|
|
662 | export_const_iv (ControlMask); |
|
|
663 | export_const_iv (Mod1Mask); |
|
|
664 | export_const_iv (Mod2Mask); |
|
|
665 | export_const_iv (Mod3Mask); |
|
|
666 | export_const_iv (Mod4Mask); |
|
|
667 | export_const_iv (Mod5Mask); |
|
|
668 | export_const_iv (Button1Mask); |
|
|
669 | export_const_iv (Button2Mask); |
|
|
670 | export_const_iv (Button3Mask); |
|
|
671 | export_const_iv (Button4Mask); |
|
|
672 | export_const_iv (Button5Mask); |
|
|
673 | export_const_iv (AnyModifier); |
|
|
674 | |
|
|
675 | export_const_iv (EVENT_NONE); |
|
|
676 | export_const_iv (EVENT_READ); |
|
|
677 | export_const_iv (EVENT_WRITE); |
608 | } |
678 | } |
|
|
679 | |
|
|
680 | void |
|
|
681 | set_should_invoke (int htype, int value) |
|
|
682 | CODE: |
|
|
683 | rxvt_perl.should_invoke [htype] = value; |
|
|
684 | |
|
|
685 | void |
|
|
686 | warn (const char *msg) |
|
|
687 | CODE: |
|
|
688 | rxvt_warn ("%s", msg); |
|
|
689 | |
|
|
690 | void |
|
|
691 | fatal (const char *msg) |
|
|
692 | CODE: |
|
|
693 | rxvt_fatal ("%s", msg); |
609 | |
694 | |
610 | SV * |
695 | SV * |
611 | new (...) |
696 | untaint (SV *sv) |
612 | CODE: |
697 | CODE: |
613 | { |
698 | RETVAL = newSVsv (sv); |
614 | stringvec *argv = new stringvec; |
699 | SvTAINTED_off (RETVAL); |
615 | bool success; |
700 | OUTPUT: |
616 | |
|
|
617 | for (int i = 0; i < items ;i++) |
|
|
618 | argv->push_back (strdup (SvPVbyte_nolen (ST (i)))); |
|
|
619 | |
|
|
620 | rxvt_term *term = new rxvt_term; |
|
|
621 | |
|
|
622 | term->argv = argv; |
|
|
623 | |
|
|
624 | try |
|
|
625 | { |
|
|
626 | if (!term->init (argv->size (), argv->begin ())) |
|
|
627 | term = 0; |
|
|
628 | } |
|
|
629 | catch (const class rxvt_failure_exception &e) |
|
|
630 | { |
|
|
631 | term->destroy (); |
|
|
632 | croak ("exception caught while initializing new terminal instance"); |
|
|
633 | } |
|
|
634 | |
|
|
635 | RETVAL = term && term->self ? newSVterm (term) : &PL_sv_undef; |
|
|
636 | } |
|
|
637 | OUTPUT: |
|
|
638 | RETVAL |
701 | RETVAL |
639 | |
702 | |
640 | void |
703 | bool |
641 | set_should_invoke (int htype, int value) |
704 | safe () |
642 | CODE: |
705 | CODE: |
643 | rxvt_perl.should_invoke [htype] = value; |
706 | RETVAL = !rxvt_tainted (); |
644 | |
707 | OUTPUT: |
645 | void |
708 | RETVAL |
646 | warn (const char *msg) |
|
|
647 | CODE: |
|
|
648 | rxvt_warn ("%s", msg); |
|
|
649 | |
|
|
650 | void |
|
|
651 | fatal (const char *msg) |
|
|
652 | CODE: |
|
|
653 | rxvt_fatal ("%s", msg); |
|
|
654 | |
709 | |
655 | NV |
710 | NV |
656 | NOW () |
711 | NOW () |
657 | CODE: |
712 | CODE: |
658 | RETVAL = NOW; |
713 | RETVAL = NOW; |
… | |
… | |
707 | OUTPUT: |
762 | OUTPUT: |
708 | RETVAL |
763 | RETVAL |
709 | |
764 | |
710 | MODULE = urxvt PACKAGE = urxvt::term |
765 | MODULE = urxvt PACKAGE = urxvt::term |
711 | |
766 | |
|
|
767 | SV * |
|
|
768 | _new (...) |
|
|
769 | CODE: |
|
|
770 | { |
|
|
771 | if (items < 1 || !SvROK (ST (0)) || SvTYPE (SvRV (ST (0))) != SVt_PVAV) |
|
|
772 | croak ("first argument to urxvt::term->_new must be arrayref"); |
|
|
773 | |
|
|
774 | rxvt_term *term = new rxvt_term; |
|
|
775 | |
|
|
776 | term->argv = new stringvec; |
|
|
777 | term->envv = new stringvec; |
|
|
778 | |
|
|
779 | for (int i = 1; i < items; i++) |
|
|
780 | term->argv->push_back (strdup (SvPVbyte_nolen (ST (i)))); |
|
|
781 | |
|
|
782 | AV *envv = (AV *)SvRV (ST (0)); |
|
|
783 | for (int i = av_len (envv) + 1; i--; ) |
|
|
784 | term->envv->push_back (strdup (SvPVbyte_nolen (*av_fetch (envv, i, 1)))); |
|
|
785 | |
|
|
786 | term->envv->push_back (0); |
|
|
787 | |
|
|
788 | bool success; |
|
|
789 | |
|
|
790 | try |
|
|
791 | { |
|
|
792 | success = term->init (term->argv->size (), term->argv->begin ()); |
|
|
793 | } |
|
|
794 | catch (const class rxvt_failure_exception &e) |
|
|
795 | { |
|
|
796 | success = false; |
|
|
797 | } |
|
|
798 | |
|
|
799 | if (!success) |
|
|
800 | { |
|
|
801 | term->destroy (); |
|
|
802 | croak ("error while initializing new terminal instance"); |
|
|
803 | } |
|
|
804 | |
|
|
805 | RETVAL = term && term->perl.self |
|
|
806 | ? newSVterm (term) : &PL_sv_undef; |
|
|
807 | } |
|
|
808 | OUTPUT: |
|
|
809 | RETVAL |
|
|
810 | |
712 | void |
811 | void |
713 | rxvt_term::destroy () |
812 | rxvt_term::destroy () |
|
|
813 | |
|
|
814 | void |
|
|
815 | rxvt_term::grab_button (int button, U32 modifiers) |
|
|
816 | CODE: |
|
|
817 | XGrabButton (THIS->display->display, button, modifiers, THIS->vt, 1, |
|
|
818 | ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask, |
|
|
819 | GrabModeSync, GrabModeSync, None, GRAB_CURSOR); |
|
|
820 | |
|
|
821 | bool |
|
|
822 | rxvt_term::grab (U32 eventtime, int sync = 0) |
|
|
823 | CODE: |
|
|
824 | { |
|
|
825 | int mode = sync ? GrabModeSync : GrabModeAsync; |
|
|
826 | |
|
|
827 | THIS->perl.grabtime = 0; |
|
|
828 | |
|
|
829 | if (!XGrabPointer (THIS->display->display, THIS->vt, 0, |
|
|
830 | ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask, |
|
|
831 | mode, mode, None, GRAB_CURSOR, eventtime)) |
|
|
832 | if (!XGrabKeyboard (THIS->display->display, THIS->vt, 0, mode, mode, eventtime)) |
|
|
833 | THIS->perl.grabtime = eventtime; |
|
|
834 | else |
|
|
835 | XUngrabPointer (THIS->display->display, eventtime); |
|
|
836 | |
|
|
837 | RETVAL = !!THIS->perl.grabtime; |
|
|
838 | } |
|
|
839 | OUTPUT: |
|
|
840 | RETVAL |
|
|
841 | |
|
|
842 | void |
|
|
843 | rxvt_term::allow_events_async () |
|
|
844 | CODE: |
|
|
845 | XAllowEvents (THIS->display->display, AsyncBoth, THIS->perl.grabtime); |
|
|
846 | |
|
|
847 | void |
|
|
848 | rxvt_term::allow_events_sync () |
|
|
849 | CODE: |
|
|
850 | XAllowEvents (THIS->display->display, SyncBoth, THIS->perl.grabtime); |
|
|
851 | |
|
|
852 | void |
|
|
853 | rxvt_term::allow_events_replay () |
|
|
854 | CODE: |
|
|
855 | XAllowEvents (THIS->display->display, ReplayPointer, THIS->perl.grabtime); |
|
|
856 | XAllowEvents (THIS->display->display, ReplayKeyboard, THIS->perl.grabtime); |
|
|
857 | |
|
|
858 | void |
|
|
859 | rxvt_term::ungrab () |
|
|
860 | CODE: |
|
|
861 | ungrab (THIS); |
714 | |
862 | |
715 | int |
863 | int |
716 | rxvt_term::strwidth (SV *str) |
864 | rxvt_term::strwidth (SV *str) |
717 | CODE: |
865 | CODE: |
718 | { |
866 | { |
… | |
… | |
737 | char *mbstr = rxvt_wcstombs (wstr); |
885 | char *mbstr = rxvt_wcstombs (wstr); |
738 | rxvt_pop_locale (); |
886 | rxvt_pop_locale (); |
739 | |
887 | |
740 | free (wstr); |
888 | free (wstr); |
741 | |
889 | |
742 | RETVAL = newSVpv (mbstr, 0); |
890 | RETVAL = taint_if (newSVpv (mbstr, 0), str); |
743 | free (mbstr); |
891 | free (mbstr); |
744 | } |
892 | } |
745 | OUTPUT: |
893 | OUTPUT: |
746 | RETVAL |
894 | RETVAL |
747 | |
895 | |
… | |
… | |
754 | |
902 | |
755 | rxvt_push_locale (THIS->locale); |
903 | rxvt_push_locale (THIS->locale); |
756 | wchar_t *wstr = rxvt_mbstowcs (data, len); |
904 | wchar_t *wstr = rxvt_mbstowcs (data, len); |
757 | rxvt_pop_locale (); |
905 | rxvt_pop_locale (); |
758 | |
906 | |
759 | RETVAL = wcs2sv (wstr); |
907 | RETVAL = taint_if (wcs2sv (wstr), octets); |
760 | free (wstr); |
908 | free (wstr); |
761 | } |
909 | } |
762 | OUTPUT: |
910 | OUTPUT: |
763 | RETVAL |
911 | RETVAL |
764 | |
912 | |
765 | # very portable, especially on objects as opposed to pods |
913 | #define TERM_OFFSET(sym) offsetof (TermWin_t, sym) |
766 | #define TERM_OFFSET(sym) (((char *)&((TermWin_t *)0)->sym) - (char *)(TermWin_t *)0) |
|
|
767 | |
914 | |
768 | #define TERM_OFFSET_width TERM_OFFSET(width) |
915 | #define TERM_OFFSET_width TERM_OFFSET(width) |
769 | #define TERM_OFFSET_height TERM_OFFSET(height) |
916 | #define TERM_OFFSET_height TERM_OFFSET(height) |
770 | #define TERM_OFFSET_fwidth TERM_OFFSET(fwidth) |
917 | #define TERM_OFFSET_fwidth TERM_OFFSET(fwidth) |
771 | #define TERM_OFFSET_fheight TERM_OFFSET(fheight) |
918 | #define TERM_OFFSET_fheight TERM_OFFSET(fheight) |
… | |
… | |
796 | CODE: |
943 | CODE: |
797 | RETVAL = *(int *)((char *)THIS + ix); |
944 | RETVAL = *(int *)((char *)THIS + ix); |
798 | OUTPUT: |
945 | OUTPUT: |
799 | RETVAL |
946 | RETVAL |
800 | |
947 | |
|
|
948 | unsigned int |
|
|
949 | rxvt_term::ModLevel3Mask () |
|
|
950 | ALIAS: |
|
|
951 | ModLevel3Mask = 0 |
|
|
952 | ModMetaMask = 1 |
|
|
953 | ModNumLockMask = 2 |
|
|
954 | CODE: |
|
|
955 | switch (ix) |
|
|
956 | { |
|
|
957 | case 0: RETVAL = THIS->ModLevel3Mask; break; |
|
|
958 | case 1: RETVAL = THIS->ModMetaMask; break; |
|
|
959 | case 2: RETVAL = THIS->ModNumLockMask; break; |
|
|
960 | } |
|
|
961 | OUTPUT: |
|
|
962 | RETVAL |
|
|
963 | |
|
|
964 | char * |
|
|
965 | rxvt_term::display_id () |
|
|
966 | ALIAS: |
|
|
967 | display_id = 0 |
|
|
968 | locale = 1 |
|
|
969 | CODE: |
|
|
970 | switch (ix) |
|
|
971 | { |
|
|
972 | case 0: RETVAL = THIS->display->id; break; |
|
|
973 | case 1: RETVAL = THIS->locale; break; |
|
|
974 | } |
|
|
975 | OUTPUT: |
|
|
976 | RETVAL |
|
|
977 | |
|
|
978 | SV * |
|
|
979 | rxvt_term::_env () |
|
|
980 | CODE: |
|
|
981 | { |
|
|
982 | if (THIS->envv) |
|
|
983 | { |
|
|
984 | AV *av = newAV (); |
|
|
985 | |
|
|
986 | for (char **i = THIS->envv->begin (); i != THIS->envv->end (); ++i) |
|
|
987 | if (*i) |
|
|
988 | av_push (av, newSVpv (*i, 0)); |
|
|
989 | |
|
|
990 | RETVAL = newRV_noinc ((SV *)av); |
|
|
991 | } |
|
|
992 | else |
|
|
993 | RETVAL = &PL_sv_undef; |
|
|
994 | } |
|
|
995 | OUTPUT: |
|
|
996 | RETVAL |
|
|
997 | |
|
|
998 | int |
|
|
999 | rxvt_term::pty_ev_events (int events = EVENT_UNDEF) |
|
|
1000 | CODE: |
|
|
1001 | RETVAL = THIS->pty_ev.events; |
|
|
1002 | if (events != EVENT_UNDEF) |
|
|
1003 | THIS->pty_ev.set (events); |
|
|
1004 | OUTPUT: |
|
|
1005 | RETVAL |
|
|
1006 | |
801 | U32 |
1007 | U32 |
802 | rxvt_term::parent () |
1008 | rxvt_term::parent () |
803 | CODE: |
1009 | CODE: |
804 | RETVAL = (U32)THIS->parent [0]; |
1010 | RETVAL = (U32)THIS->parent [0]; |
805 | OUTPUT: |
1011 | OUTPUT: |
… | |
… | |
853 | |
1059 | |
854 | if (GIMME_V != G_VOID) |
1060 | if (GIMME_V != G_VOID) |
855 | { |
1061 | { |
856 | wchar_t *wstr = new wchar_t [THIS->ncol]; |
1062 | wchar_t *wstr = new wchar_t [THIS->ncol]; |
857 | |
1063 | |
858 | for (int col = 0; col <THIS->ncol; col++) |
1064 | for (int col = 0; col < THIS->ncol; col++) |
859 | wstr [col] = l.t [col]; |
1065 | wstr [col] = l.t [col]; |
860 | |
1066 | |
861 | XPUSHs (sv_2mortal (wcs2sv (wstr))); |
1067 | XPUSHs (taint (sv_2mortal (wcs2sv (wstr, THIS->ncol)))); |
862 | |
1068 | |
863 | delete [] wstr; |
1069 | delete [] wstr; |
864 | } |
1070 | } |
865 | |
1071 | |
866 | if (new_text) |
1072 | if (new_text) |
… | |
… | |
956 | } |
1162 | } |
957 | OUTPUT: |
1163 | OUTPUT: |
958 | RETVAL |
1164 | RETVAL |
959 | |
1165 | |
960 | SV * |
1166 | SV * |
961 | rxvt_term::special_encode (SV *str) |
1167 | rxvt_term::special_encode (SV *string) |
962 | CODE: |
1168 | CODE: |
963 | abort ();//TODO |
1169 | { |
|
|
1170 | wchar_t *wstr = sv2wcs (string); |
|
|
1171 | int wlen = wcslen (wstr); |
|
|
1172 | wchar_t *rstr = new wchar_t [wlen]; // cannot become longer |
|
|
1173 | |
|
|
1174 | rxvt_push_locale (THIS->locale); |
|
|
1175 | |
|
|
1176 | wchar_t *r = rstr; |
|
|
1177 | for (wchar_t *s = wstr; *s; s++) |
|
|
1178 | if (wcwidth (*s) == 0) |
|
|
1179 | { |
|
|
1180 | if (r == rstr) |
|
|
1181 | croak ("leading combining character unencodable"); |
|
|
1182 | |
|
|
1183 | unicode_t n = rxvt_compose (r[-1], *s); |
|
|
1184 | if (n == NOCHAR) |
|
|
1185 | n = rxvt_composite.compose (r[-1], *s); |
|
|
1186 | |
|
|
1187 | r[-1] = n; |
|
|
1188 | } |
|
|
1189 | #if !UNICODE_3 |
|
|
1190 | else if (*s >= 0x10000) |
|
|
1191 | *r++ = rxvt_composite.compose (*s); |
|
|
1192 | #endif |
|
|
1193 | else |
|
|
1194 | *r++ = *s; |
|
|
1195 | |
|
|
1196 | rxvt_pop_locale (); |
|
|
1197 | |
|
|
1198 | RETVAL = taint_if (wcs2sv (rstr, r - rstr), string); |
|
|
1199 | |
|
|
1200 | delete [] rstr; |
|
|
1201 | } |
|
|
1202 | OUTPUT: |
|
|
1203 | RETVAL |
964 | |
1204 | |
965 | SV * |
1205 | SV * |
966 | rxvt_term::special_decode (SV *str) |
1206 | rxvt_term::special_decode (SV *text) |
967 | CODE: |
1207 | CODE: |
968 | abort ();//TODO |
1208 | { |
|
|
1209 | wchar_t *wstr = sv2wcs (text); |
|
|
1210 | int wlen = wcslen (wstr); |
|
|
1211 | int dlen = 0; |
|
|
1212 | |
|
|
1213 | // find length |
|
|
1214 | for (wchar_t *s = wstr; *s; s++) |
|
|
1215 | if (*s == NOCHAR) |
|
|
1216 | ; |
|
|
1217 | else if (IS_COMPOSE (*s)) |
|
|
1218 | dlen += rxvt_composite.expand (*s, 0); |
|
|
1219 | else |
|
|
1220 | dlen++; |
|
|
1221 | |
|
|
1222 | wchar_t *rstr = new wchar_t [dlen]; |
|
|
1223 | |
|
|
1224 | // decode |
|
|
1225 | wchar_t *r = rstr; |
|
|
1226 | for (wchar_t *s = wstr; *s; s++) |
|
|
1227 | if (*s == NOCHAR) |
|
|
1228 | ; |
|
|
1229 | else if (IS_COMPOSE (*s)) |
|
|
1230 | r += rxvt_composite.expand (*s, r); |
|
|
1231 | else |
|
|
1232 | *r++ = *s; |
|
|
1233 | |
|
|
1234 | RETVAL = taint_if (wcs2sv (rstr, r - rstr), text); |
|
|
1235 | |
|
|
1236 | delete [] rstr; |
|
|
1237 | } |
|
|
1238 | OUTPUT: |
|
|
1239 | RETVAL |
969 | |
1240 | |
970 | void |
1241 | void |
971 | rxvt_term::_resource (char *name, int index, SV *newval = 0) |
1242 | rxvt_term::_resource (char *name, int index, SV *newval = 0) |
972 | PPCODE: |
1243 | PPCODE: |
973 | { |
1244 | { |
… | |
… | |
990 | |
1261 | |
991 | if (!IN_RANGE_EXC (index, 0, NUM_RESOURCES)) |
1262 | if (!IN_RANGE_EXC (index, 0, NUM_RESOURCES)) |
992 | croak ("requested out-of-bound resource %s+%d,", name, index - rs->value); |
1263 | croak ("requested out-of-bound resource %s+%d,", name, index - rs->value); |
993 | |
1264 | |
994 | if (GIMME_V != G_VOID) |
1265 | if (GIMME_V != G_VOID) |
995 | XPUSHs (THIS->rs [index] ? sv_2mortal (newSVpv (THIS->rs [index], 0)) : &PL_sv_undef); |
1266 | XPUSHs (THIS->rs [index] ? sv_2mortal (taint (newSVpv (THIS->rs [index], 0))) : &PL_sv_undef); |
996 | |
1267 | |
997 | if (newval) |
1268 | if (newval) |
998 | { |
1269 | { |
999 | if (SvOK (newval)) |
1270 | if (SvOK (newval)) |
1000 | { |
1271 | { |
… | |
… | |
1005 | else |
1276 | else |
1006 | THIS->rs [index] = 0; |
1277 | THIS->rs [index] = 0; |
1007 | } |
1278 | } |
1008 | } |
1279 | } |
1009 | |
1280 | |
|
|
1281 | bool |
|
|
1282 | rxvt_term::option (U32 optval, int set = -1) |
|
|
1283 | CODE: |
|
|
1284 | { |
|
|
1285 | RETVAL = THIS->options & optval; |
|
|
1286 | |
|
|
1287 | if (set >= 0) |
|
|
1288 | { |
|
|
1289 | if (set) |
|
|
1290 | THIS->options |= optval; |
|
|
1291 | else |
|
|
1292 | THIS->options &= ~optval; |
|
|
1293 | |
|
|
1294 | switch (optval) |
|
|
1295 | { |
|
|
1296 | case Opt_skipBuiltinGlyphs: |
|
|
1297 | THIS->set_fonts (); |
|
|
1298 | THIS->scr_remap_chars (); |
|
|
1299 | THIS->scr_touch (true); |
|
|
1300 | THIS->want_refresh = 1; |
|
|
1301 | break; |
|
|
1302 | |
|
|
1303 | case Opt_cursorUnderline: |
|
|
1304 | THIS->want_refresh = 1; |
|
|
1305 | break; |
|
|
1306 | |
|
|
1307 | # case Opt_scrollBar_floating: |
|
|
1308 | # case Opt_scrollBar_right: |
|
|
1309 | # THIS->resize_all_windows (THIS->width, THIS->height, 1); |
|
|
1310 | # break; |
|
|
1311 | } |
|
|
1312 | } |
|
|
1313 | } |
|
|
1314 | OUTPUT: |
|
|
1315 | RETVAL |
|
|
1316 | |
|
|
1317 | bool |
|
|
1318 | rxvt_term::parse_keysym (char *keysym, char *str) |
|
|
1319 | CODE: |
|
|
1320 | RETVAL = 0 < THIS->parse_keysym (keysym, str); |
|
|
1321 | THIS->keyboard->register_done (); |
|
|
1322 | OUTPUT: |
|
|
1323 | RETVAL |
|
|
1324 | |
1010 | void |
1325 | void |
1011 | rxvt_term::cur (...) |
1326 | rxvt_term::screen_cur (...) |
1012 | PROTOTYPE: $;$$ |
1327 | PROTOTYPE: $;$$ |
1013 | ALIAS: |
1328 | ALIAS: |
1014 | screen_cur = 0 |
1329 | screen_cur = 0 |
1015 | selection_beg = 1 |
1330 | selection_beg = 1 |
1016 | selection_end = 2 |
1331 | selection_end = 2 |
… | |
… | |
1037 | if (ix) |
1352 | if (ix) |
1038 | THIS->want_refresh = 1; |
1353 | THIS->want_refresh = 1; |
1039 | } |
1354 | } |
1040 | } |
1355 | } |
1041 | |
1356 | |
|
|
1357 | char |
|
|
1358 | rxvt_term::cur_charset () |
|
|
1359 | CODE: |
|
|
1360 | RETVAL = THIS->charsets [THIS->screen.charset]; |
|
|
1361 | OUTPUT: |
|
|
1362 | RETVAL |
|
|
1363 | |
1042 | int |
1364 | int |
1043 | rxvt_term::selection_grab (int eventtime = CurrentTime) |
1365 | rxvt_term::selection_grab (U32 eventtime) |
1044 | |
1366 | |
1045 | void |
1367 | void |
1046 | rxvt_term::selection (SV *newtext = 0) |
1368 | rxvt_term::selection (SV *newtext = 0) |
1047 | PPCODE: |
1369 | PPCODE: |
1048 | { |
1370 | { |
1049 | if (GIMME_V != G_VOID) |
1371 | if (GIMME_V != G_VOID) |
|
|
1372 | XPUSHs (THIS->selection.text |
1050 | XPUSHs (sv_2mortal (wcs2sv (THIS->selection.text, THIS->selection.len))); |
1373 | ? taint (sv_2mortal (wcs2sv (THIS->selection.text, THIS->selection.len))) |
|
|
1374 | : &PL_sv_undef); |
1051 | |
1375 | |
1052 | if (newtext) |
1376 | if (newtext) |
1053 | { |
1377 | { |
1054 | free (THIS->selection.text); |
1378 | free (THIS->selection.text); |
1055 | |
1379 | |
… | |
… | |
1057 | THIS->selection.len = wcslen (THIS->selection.text); |
1381 | THIS->selection.len = wcslen (THIS->selection.text); |
1058 | } |
1382 | } |
1059 | } |
1383 | } |
1060 | |
1384 | |
1061 | void |
1385 | void |
|
|
1386 | 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) |
|
|
1387 | |
|
|
1388 | void |
|
|
1389 | rxvt_term::scr_xor_span (int beg_row, int beg_col, int end_row, int end_col, U32 rstyle = RS_RVid) |
|
|
1390 | |
|
|
1391 | void |
|
|
1392 | rxvt_term::scr_bell () |
|
|
1393 | |
|
|
1394 | void |
1062 | rxvt_term::scr_add_lines (SV *string) |
1395 | rxvt_term::scr_add_lines (SV *string) |
1063 | CODE: |
1396 | CODE: |
1064 | { |
1397 | { |
1065 | wchar_t *wstr = sv2wcs (string); |
1398 | wchar_t *wstr = sv2wcs (string); |
1066 | int wlen = wcslen (wstr); |
|
|
1067 | unicode_t *ustr = new unicode_t [wlen]; |
|
|
1068 | int nlines = 0; |
|
|
1069 | |
|
|
1070 | for (int i = wlen; i--; ) |
|
|
1071 | { |
|
|
1072 | ustr [i] = wstr [i]; |
|
|
1073 | nlines += ustr [i] == '\012'; |
|
|
1074 | } |
|
|
1075 | |
|
|
1076 | THIS->scr_add_lines (ustr, nlines, wlen); |
1399 | THIS->scr_add_lines (wstr, wcslen (wstr)); |
1077 | |
|
|
1078 | free (wstr); |
1400 | free (wstr); |
1079 | delete [] ustr; |
|
|
1080 | } |
1401 | } |
1081 | |
1402 | |
1082 | void |
1403 | void |
1083 | rxvt_term::tt_write (SV *octets) |
1404 | rxvt_term::tt_write (SV *octets) |
1084 | INIT: |
1405 | INIT: |
… | |
… | |
1098 | char *old_cmdbuf_endp = THIS->cmdbuf_endp; |
1419 | char *old_cmdbuf_endp = THIS->cmdbuf_endp; |
1099 | |
1420 | |
1100 | THIS->cmdbuf_ptr = str; |
1421 | THIS->cmdbuf_ptr = str; |
1101 | THIS->cmdbuf_endp = str + len; |
1422 | THIS->cmdbuf_endp = str + len; |
1102 | |
1423 | |
|
|
1424 | rxvt_push_locale (THIS->locale); |
1103 | THIS->cmd_parse (); |
1425 | THIS->cmd_parse (); |
|
|
1426 | rxvt_pop_locale (); |
1104 | |
1427 | |
1105 | THIS->cmdbuf_ptr = old_cmdbuf_ptr; |
1428 | THIS->cmdbuf_ptr = old_cmdbuf_ptr; |
1106 | THIS->cmdbuf_endp = old_cmdbuf_endp; |
1429 | THIS->cmdbuf_endp = old_cmdbuf_endp; |
1107 | } |
1430 | } |
1108 | |
1431 | |