1 | /*----------------------------------------------------------------------* |
1 | /*----------------------------------------------------------------------* |
2 | * File: rxvtperl.xs |
2 | * File: rxvtperl.xs |
3 | *----------------------------------------------------------------------* |
3 | *----------------------------------------------------------------------* |
4 | * |
4 | * |
5 | * All portions of code are copyright by their respective author/s. |
5 | * All portions of code are copyright by their respective author/s. |
6 | * Copyright (c) 2005-2005 Marc Lehmann <pcg@goof.com> |
6 | * Copyright (c) 2005-2006 Marc Lehmann <pcg@goof.com> |
7 | * |
7 | * |
8 | * This program is free software; you can redistribute it and/or modify |
8 | * This program is free software; you can redistribute it and/or modify |
9 | * it under the terms of the GNU General Public License as published by |
9 | * it under the terms of the GNU General Public License as published by |
10 | * the Free Software Foundation; either version 2 of the License, or |
10 | * the Free Software Foundation; either version 2 of the License, or |
11 | * (at your option) any later version. |
11 | * (at your option) any later version. |
… | |
… | |
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 | |
33 | #include "rxvt.h" |
34 | #include "rxvt.h" |
34 | #include "iom.h" |
35 | #include "iom.h" |
35 | #include "rxvtutil.h" |
36 | #include "rxvtutil.h" |
36 | #include "rxvtperl.h" |
37 | #include "rxvtperl.h" |
37 | |
38 | |
38 | #include "perlxsi.c" |
39 | #include "perlxsi.c" |
39 | |
40 | |
|
|
41 | #if defined(HAVE_SCROLLBARS) || defined(MENUBAR) |
|
|
42 | # define GRAB_CURSOR THIS->leftptr_cursor |
|
|
43 | #else |
|
|
44 | # define GRAB_CURSOR None |
|
|
45 | #endif |
|
|
46 | |
40 | #undef LINENO |
47 | #undef LINENO |
41 | #define LINENO(n) MOD (THIS->term_start + int(n), THIS->total_rows) |
48 | #define LINENO(n) MOD (THIS->term_start + int(n), THIS->total_rows) |
42 | #undef ROW |
49 | #undef ROW |
43 | #define ROW(n) THIS->row_buf [LINENO (n)] |
50 | #define ROW(n) THIS->row_buf [LINENO (n)] |
44 | |
51 | |
45 | ///////////////////////////////////////////////////////////////////////////// |
52 | ///////////////////////////////////////////////////////////////////////////// |
46 | |
53 | |
|
|
54 | static SV * |
|
|
55 | taint (SV *sv) |
|
|
56 | { |
|
|
57 | SvTAINT (sv); |
|
|
58 | return sv; |
|
|
59 | } |
|
|
60 | |
|
|
61 | static SV * |
|
|
62 | taint_if (SV *sv, SV *src) |
|
|
63 | { |
|
|
64 | if (SvTAINTED (src)) |
|
|
65 | SvTAINT (sv); |
|
|
66 | |
|
|
67 | return sv; |
|
|
68 | } |
|
|
69 | |
47 | static wchar_t * |
70 | static wchar_t * |
48 | sv2wcs (SV *sv) |
71 | sv2wcs (SV *sv) |
49 | { |
72 | { |
50 | STRLEN len; |
73 | STRLEN len; |
51 | char *str = SvPVutf8 (sv, len); |
74 | char *str = SvPVutf8 (sv, len); |
… | |
… | |
101 | croak ("perl code used %s object, but C++ object is already destroyed, caught", klass); |
124 | croak ("perl code used %s object, but C++ object is already destroyed, caught", klass); |
102 | |
125 | |
103 | return (long)mg->mg_ptr; |
126 | return (long)mg->mg_ptr; |
104 | } |
127 | } |
105 | |
128 | |
106 | #define newSVterm(term) SvREFCNT_inc ((SV *)term->self) |
129 | #define newSVterm(term) SvREFCNT_inc ((SV *)term->perl.self) |
107 | #define SvTERM(sv) (rxvt_term *)SvPTR (sv, "urxvt::term") |
130 | #define SvTERM(sv) (rxvt_term *)SvPTR (sv, "urxvt::term") |
108 | |
131 | |
109 | ///////////////////////////////////////////////////////////////////////////// |
132 | ///////////////////////////////////////////////////////////////////////////// |
110 | |
133 | |
111 | struct perl_watcher |
134 | struct perl_watcher |
… | |
… | |
290 | void |
313 | void |
291 | overlay::show () |
314 | overlay::show () |
292 | { |
315 | { |
293 | char key[33]; sprintf (key, "%32lx", (long)this); |
316 | char key[33]; sprintf (key, "%32lx", (long)this); |
294 | |
317 | |
295 | HV *hv = (HV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)THIS->self), "_overlay", 8, 0)); |
318 | 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); |
319 | hv_store (hv, key, 32, newSViv ((long)this), 0); |
297 | } |
320 | } |
298 | |
321 | |
299 | void |
322 | void |
300 | overlay::hide () |
323 | overlay::hide () |
301 | { |
324 | { |
302 | SV **ovs = hv_fetch ((HV *)SvRV ((SV *)THIS->self), "_overlay", 8, 0); |
325 | SV **ovs = hv_fetch ((HV *)SvRV ((SV *)THIS->perl.self), "_overlay", 8, 0); |
303 | |
326 | |
304 | if (ovs) |
327 | if (ovs) |
305 | { |
328 | { |
306 | char key[33]; sprintf (key, "%32lx", (long)this); |
329 | char key[33]; sprintf (key, "%32lx", (long)this); |
307 | |
330 | |
… | |
… | |
389 | { |
412 | { |
390 | if (!perl) |
413 | if (!perl) |
391 | { |
414 | { |
392 | char *argv[] = { |
415 | char *argv[] = { |
393 | "", |
416 | "", |
|
|
417 | "-T", |
394 | "-edo '" LIBDIR "/urxvt.pm' or ($@ and die $@) or exit 1", |
418 | "-edo '" LIBDIR "/urxvt.pm' or ($@ and die $@) or exit 1", |
395 | }; |
419 | }; |
396 | |
420 | |
397 | perl = perl_alloc (); |
421 | perl = perl_alloc (); |
398 | perl_construct (perl); |
422 | perl_construct (perl); |
399 | |
423 | |
400 | if (perl_parse (perl, xs_init, 2, argv, (char **)NULL) |
424 | if (perl_parse (perl, xs_init, 3, argv, (char **)NULL) |
401 | || perl_run (perl)) |
425 | || perl_run (perl)) |
402 | { |
426 | { |
403 | rxvt_warn ("unable to initialize perl-interpreter, continuing without.\n"); |
427 | rxvt_warn ("unable to initialize perl-interpreter, continuing without.\n"); |
404 | |
428 | |
405 | perl_destruct (perl); |
429 | perl_destruct (perl); |
… | |
… | |
407 | perl = 0; |
431 | perl = 0; |
408 | } |
432 | } |
409 | } |
433 | } |
410 | } |
434 | } |
411 | |
435 | |
|
|
436 | static void |
|
|
437 | ungrab (rxvt_term *THIS) |
|
|
438 | { |
|
|
439 | if (THIS->perl.grabtime) |
|
|
440 | { |
|
|
441 | XUngrabKeyboard (THIS->display->display, THIS->perl.grabtime); |
|
|
442 | XUngrabPointer (THIS->display->display, THIS->perl.grabtime); |
|
|
443 | THIS->perl.grabtime = 0; |
|
|
444 | } |
|
|
445 | } |
|
|
446 | |
412 | bool |
447 | bool |
413 | rxvt_perl_interp::invoke (rxvt_term *term, hook_type htype, ...) |
448 | rxvt_perl_interp::invoke (rxvt_term *term, hook_type htype, ...) |
414 | { |
449 | { |
415 | if (!perl) |
450 | if (!perl) |
416 | return false; |
451 | return false; |
417 | |
452 | |
418 | if (htype == HOOK_INIT) // first hook ever called |
453 | if (htype == HOOK_INIT) // first hook ever called |
419 | { |
454 | { |
420 | term->self = (void *)newSVptr ((void *)term, "urxvt::term"); |
455 | term->perl.self = (void *)newSVptr ((void *)term, "urxvt::term"); |
421 | hv_store ((HV *)SvRV ((SV *)term->self), "_overlay", 8, newRV_noinc ((SV *)newHV ()), 0); |
456 | hv_store ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, newRV_noinc ((SV *)newHV ()), 0); |
422 | } |
457 | } |
423 | else if (!term->self) |
458 | else if (!term->perl.self) |
424 | return false; // perl not initialized for this instance |
459 | return false; // perl not initialized for this instance |
425 | else if (htype == HOOK_DESTROY) |
460 | else if (htype == HOOK_DESTROY) |
426 | { |
461 | { |
427 | // handled later |
462 | // handled later |
428 | } |
463 | } |
429 | else if (htype == HOOK_REFRESH_BEGIN || htype == HOOK_REFRESH_END) |
464 | else if (htype == HOOK_REFRESH_BEGIN || htype == HOOK_REFRESH_END) |
430 | { |
465 | { |
431 | HV *hv = (HV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->self), "_overlay", 8, 0)); |
466 | HV *hv = (HV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, 0)); |
432 | |
467 | |
433 | if (HvKEYS (hv)) |
468 | if (HvKEYS (hv)) |
434 | { |
469 | { |
435 | hv_iterinit (hv); |
470 | hv_iterinit (hv); |
436 | |
471 | |
… | |
… | |
465 | |
500 | |
466 | case DT_LONG: |
501 | case DT_LONG: |
467 | XPUSHs (sv_2mortal (newSViv (va_arg (ap, long)))); |
502 | XPUSHs (sv_2mortal (newSViv (va_arg (ap, long)))); |
468 | break; |
503 | break; |
469 | |
504 | |
470 | case DT_STRING: |
505 | case DT_STR: |
471 | XPUSHs (sv_2mortal (newSVpv (va_arg (ap, char *), 0))); |
506 | XPUSHs (taint (sv_2mortal (newSVpv (va_arg (ap, char *), 0)))); |
472 | break; |
507 | break; |
473 | |
508 | |
474 | case DT_USTRING_LEN: |
509 | case DT_STR_LEN: |
475 | { |
510 | { |
476 | unicode_t *ustr = va_arg (ap, unicode_t *); |
511 | char *str = va_arg (ap, char *); |
477 | int ulen = va_arg (ap, int); |
512 | int len = va_arg (ap, int); |
|
|
513 | |
|
|
514 | XPUSHs (taint (sv_2mortal (newSVpvn (str, len)))); |
|
|
515 | } |
|
|
516 | break; |
|
|
517 | |
|
|
518 | case DT_WCS_LEN: |
|
|
519 | { |
478 | wchar_t *wstr = new wchar_t [ulen]; |
520 | wchar_t *wstr = va_arg (ap, wchar_t *); |
|
|
521 | int wlen = va_arg (ap, int); |
479 | |
522 | |
480 | for (int i = ulen; i--; ) |
|
|
481 | wstr [i] = ustr [i]; |
|
|
482 | |
|
|
483 | XPUSHs (sv_2mortal (wcs2sv (wstr, ulen))); |
523 | XPUSHs (taint (sv_2mortal (wcs2sv (wstr, wlen)))); |
|
|
524 | } |
|
|
525 | break; |
484 | |
526 | |
485 | delete [] wstr; |
527 | case DT_XEVENT: |
486 | } |
528 | { |
|
|
529 | XEvent *xe = va_arg (ap, XEvent *); |
|
|
530 | HV *hv = newHV (); |
|
|
531 | |
|
|
532 | # define set(name, sv) hv_store (hv, # name, sizeof (# name) - 1, sv, 0) |
|
|
533 | # define setiv(name, val) hv_store (hv, # name, sizeof (# name) - 1, newSViv (val), 0) |
|
|
534 | # undef set |
|
|
535 | |
|
|
536 | setiv (type, xe->type); |
|
|
537 | setiv (send_event, xe->xany.send_event); |
|
|
538 | setiv (serial, xe->xany.serial); |
|
|
539 | |
|
|
540 | switch (xe->type) |
|
|
541 | { |
|
|
542 | case KeyPress: |
|
|
543 | case KeyRelease: |
|
|
544 | case ButtonPress: |
|
|
545 | case ButtonRelease: |
|
|
546 | case MotionNotify: |
|
|
547 | setiv (time, xe->xmotion.time); |
|
|
548 | setiv (x, xe->xmotion.x); |
|
|
549 | setiv (y, xe->xmotion.y); |
|
|
550 | setiv (row, xe->xmotion.y / term->fheight); |
|
|
551 | setiv (col, xe->xmotion.x / term->fwidth); |
|
|
552 | setiv (x_root, xe->xmotion.x_root); |
|
|
553 | setiv (y_root, xe->xmotion.y_root); |
|
|
554 | setiv (state, xe->xmotion.state); |
|
|
555 | break; |
|
|
556 | } |
|
|
557 | |
|
|
558 | switch (xe->type) |
|
|
559 | { |
|
|
560 | case KeyPress: |
|
|
561 | case KeyRelease: |
|
|
562 | setiv (keycode, xe->xkey.keycode); |
|
|
563 | break; |
|
|
564 | |
|
|
565 | case ButtonPress: |
|
|
566 | case ButtonRelease: |
|
|
567 | setiv (button, xe->xbutton.button); |
|
|
568 | break; |
|
|
569 | |
|
|
570 | case MotionNotify: |
|
|
571 | setiv (is_hint, xe->xmotion.is_hint); |
|
|
572 | break; |
|
|
573 | } |
|
|
574 | |
|
|
575 | XPUSHs (sv_2mortal (newRV_noinc ((SV *)hv))); |
|
|
576 | } |
|
|
577 | break; |
487 | |
578 | |
488 | case DT_END: |
579 | case DT_END: |
489 | { |
580 | { |
490 | va_end (ap); |
581 | va_end (ap); |
491 | |
582 | |
… | |
… | |
502 | PUTBACK; |
593 | PUTBACK; |
503 | FREETMPS; |
594 | FREETMPS; |
504 | LEAVE; |
595 | LEAVE; |
505 | |
596 | |
506 | if (SvTRUE (ERRSV)) |
597 | if (SvTRUE (ERRSV)) |
|
|
598 | { |
507 | rxvt_warn ("perl hook %d evaluation error: %s", htype, SvPV_nolen (ERRSV)); |
599 | rxvt_warn ("perl hook %d evaluation error: %s", htype, SvPV_nolen (ERRSV)); |
|
|
600 | ungrab (term); // better lose the grab than the session |
|
|
601 | } |
508 | |
602 | |
509 | if (htype == HOOK_DESTROY) |
603 | if (htype == HOOK_DESTROY) |
510 | { |
604 | { |
511 | clearSVptr ((SV *)term->self); |
605 | clearSVptr ((SV *)term->perl.self); |
512 | SvREFCNT_dec ((SV *)term->self); |
606 | SvREFCNT_dec ((SV *)term->perl.self); |
513 | } |
607 | } |
514 | |
608 | |
515 | return count; |
609 | return count; |
516 | } |
610 | } |
517 | |
611 | |
… | |
… | |
527 | |
621 | |
528 | PROTOTYPES: ENABLE |
622 | PROTOTYPES: ENABLE |
529 | |
623 | |
530 | BOOT: |
624 | BOOT: |
531 | { |
625 | { |
532 | # define export_const(name) newCONSTSUB (gv_stashpv ("urxvt", 1), # name, newSViv (name)); |
626 | sv_setsv (get_sv ("urxvt::LIBDIR", 1), newSVpvn (LIBDIR, sizeof (LIBDIR) - 1)); |
|
|
627 | |
533 | AV *hookname = get_av ("urxvt::HOOKNAME", 1); |
628 | AV *hookname = get_av ("urxvt::HOOKNAME", 1); |
534 | # define def(sym) av_store (hookname, HOOK_ ## sym, newSVpv (# sym, 0)); |
629 | # define def(sym) av_store (hookname, HOOK_ ## sym, newSVpv (# sym, 0)); |
535 | # include "hookinc.h" |
630 | # include "hookinc.h" |
536 | # undef def |
631 | # undef def |
537 | |
632 | |
|
|
633 | HV *option = get_hv ("urxvt::OPTION", 1); |
|
|
634 | # define def(name,val) hv_store (option, # name, sizeof (# name) - 1, newSVuv (Opt_ ## name), 0); |
|
|
635 | # define nodef(name) |
|
|
636 | # include "optinc.h" |
|
|
637 | # undef nodef |
|
|
638 | # undef def |
|
|
639 | |
|
|
640 | HV *stash = gv_stashpv ("urxvt", 1); |
|
|
641 | # define export_const_iv(name) newCONSTSUB (stash, # name, newSViv (name)); |
538 | export_const (DEFAULT_RSTYLE); |
642 | export_const_iv (DEFAULT_RSTYLE); |
539 | export_const (OVERLAY_RSTYLE); |
643 | export_const_iv (OVERLAY_RSTYLE); |
540 | export_const (RS_Bold); |
644 | export_const_iv (RS_Bold); |
541 | export_const (RS_Italic); |
645 | export_const_iv (RS_Italic); |
542 | export_const (RS_Blink); |
646 | export_const_iv (RS_Blink); |
543 | export_const (RS_RVid); |
647 | export_const_iv (RS_RVid); |
544 | export_const (RS_Uline); |
648 | export_const_iv (RS_Uline); |
545 | |
649 | |
546 | sv_setpv (get_sv ("urxvt::LIBDIR", 1), LIBDIR); |
650 | export_const_iv (CurrentTime); |
|
|
651 | export_const_iv (ShiftMask); |
|
|
652 | export_const_iv (LockMask); |
|
|
653 | export_const_iv (ControlMask); |
|
|
654 | export_const_iv (Mod1Mask); |
|
|
655 | export_const_iv (Mod2Mask); |
|
|
656 | export_const_iv (Mod3Mask); |
|
|
657 | export_const_iv (Mod4Mask); |
|
|
658 | export_const_iv (Mod5Mask); |
|
|
659 | export_const_iv (Button1Mask); |
|
|
660 | export_const_iv (Button2Mask); |
|
|
661 | export_const_iv (Button3Mask); |
|
|
662 | export_const_iv (Button4Mask); |
|
|
663 | export_const_iv (Button5Mask); |
|
|
664 | export_const_iv (AnyModifier); |
547 | } |
665 | } |
|
|
666 | |
|
|
667 | SV * |
|
|
668 | new (...) |
|
|
669 | CODE: |
|
|
670 | { |
|
|
671 | stringvec *argv = new stringvec; |
|
|
672 | bool success; |
|
|
673 | |
|
|
674 | for (int i = 0; i < items ;i++) |
|
|
675 | argv->push_back (strdup (SvPVbyte_nolen (ST (i)))); |
|
|
676 | |
|
|
677 | rxvt_term *term = new rxvt_term; |
|
|
678 | |
|
|
679 | term->argv = argv; |
|
|
680 | |
|
|
681 | try |
|
|
682 | { |
|
|
683 | if (!term->init (argv->size (), argv->begin ())) |
|
|
684 | term = 0; |
|
|
685 | } |
|
|
686 | catch (const class rxvt_failure_exception &e) |
|
|
687 | { |
|
|
688 | term->destroy (); |
|
|
689 | croak ("exception caught while initializing new terminal instance"); |
|
|
690 | } |
|
|
691 | |
|
|
692 | RETVAL = term && term->perl.self ? newSVterm (term) : &PL_sv_undef; |
|
|
693 | } |
|
|
694 | OUTPUT: |
|
|
695 | RETVAL |
548 | |
696 | |
549 | void |
697 | void |
550 | set_should_invoke (int htype, int value) |
698 | set_should_invoke (int htype, int value) |
551 | CODE: |
699 | CODE: |
552 | rxvt_perl.should_invoke [htype] = value; |
700 | rxvt_perl.should_invoke [htype] = value; |
… | |
… | |
558 | |
706 | |
559 | void |
707 | void |
560 | fatal (const char *msg) |
708 | fatal (const char *msg) |
561 | CODE: |
709 | CODE: |
562 | rxvt_fatal ("%s", msg); |
710 | rxvt_fatal ("%s", msg); |
|
|
711 | |
|
|
712 | SV * |
|
|
713 | untaint (SV *sv) |
|
|
714 | CODE: |
|
|
715 | RETVAL = newSVsv (sv); |
|
|
716 | SvTAINTED_off (RETVAL); |
|
|
717 | OUTPUT: |
|
|
718 | RETVAL |
|
|
719 | |
|
|
720 | bool |
|
|
721 | safe () |
|
|
722 | CODE: |
|
|
723 | RETVAL = !rxvt_tainted (); |
|
|
724 | OUTPUT: |
|
|
725 | RETVAL |
563 | |
726 | |
564 | NV |
727 | NV |
565 | NOW () |
728 | NOW () |
566 | CODE: |
729 | CODE: |
567 | RETVAL = NOW; |
730 | RETVAL = NOW; |
… | |
… | |
615 | } |
778 | } |
616 | OUTPUT: |
779 | OUTPUT: |
617 | RETVAL |
780 | RETVAL |
618 | |
781 | |
619 | MODULE = urxvt PACKAGE = urxvt::term |
782 | MODULE = urxvt PACKAGE = urxvt::term |
|
|
783 | |
|
|
784 | void |
|
|
785 | rxvt_term::destroy () |
|
|
786 | |
|
|
787 | void |
|
|
788 | rxvt_term::grab_button (int button, U32 modifiers) |
|
|
789 | CODE: |
|
|
790 | XGrabButton (THIS->display->display, button, modifiers, THIS->vt, 1, |
|
|
791 | ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask, |
|
|
792 | GrabModeSync, GrabModeSync, None, GRAB_CURSOR); |
|
|
793 | |
|
|
794 | bool |
|
|
795 | rxvt_term::grab (U32 eventtime, int sync = 0) |
|
|
796 | CODE: |
|
|
797 | { |
|
|
798 | int mode = sync ? GrabModeSync : GrabModeAsync; |
|
|
799 | |
|
|
800 | THIS->perl.grabtime = 0; |
|
|
801 | |
|
|
802 | if (!XGrabPointer (THIS->display->display, THIS->vt, 0, |
|
|
803 | ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask, |
|
|
804 | mode, mode, None, GRAB_CURSOR, eventtime)) |
|
|
805 | if (!XGrabKeyboard (THIS->display->display, THIS->vt, 0, mode, mode, eventtime)) |
|
|
806 | THIS->perl.grabtime = eventtime; |
|
|
807 | else |
|
|
808 | XUngrabPointer (THIS->display->display, eventtime); |
|
|
809 | |
|
|
810 | RETVAL = !!THIS->perl.grabtime; |
|
|
811 | } |
|
|
812 | OUTPUT: |
|
|
813 | RETVAL |
|
|
814 | |
|
|
815 | void |
|
|
816 | rxvt_term::allow_events_async () |
|
|
817 | CODE: |
|
|
818 | XAllowEvents (THIS->display->display, AsyncBoth, THIS->perl.grabtime); |
|
|
819 | |
|
|
820 | void |
|
|
821 | rxvt_term::allow_events_sync () |
|
|
822 | CODE: |
|
|
823 | XAllowEvents (THIS->display->display, SyncBoth, THIS->perl.grabtime); |
|
|
824 | |
|
|
825 | void |
|
|
826 | rxvt_term::allow_events_replay () |
|
|
827 | CODE: |
|
|
828 | XAllowEvents (THIS->display->display, ReplayPointer, THIS->perl.grabtime); |
|
|
829 | XAllowEvents (THIS->display->display, ReplayKeyboard, THIS->perl.grabtime); |
|
|
830 | |
|
|
831 | void |
|
|
832 | rxvt_term::ungrab () |
|
|
833 | CODE: |
|
|
834 | ungrab (THIS); |
620 | |
835 | |
621 | int |
836 | int |
622 | rxvt_term::strwidth (SV *str) |
837 | rxvt_term::strwidth (SV *str) |
623 | CODE: |
838 | CODE: |
624 | { |
839 | { |
… | |
… | |
643 | char *mbstr = rxvt_wcstombs (wstr); |
858 | char *mbstr = rxvt_wcstombs (wstr); |
644 | rxvt_pop_locale (); |
859 | rxvt_pop_locale (); |
645 | |
860 | |
646 | free (wstr); |
861 | free (wstr); |
647 | |
862 | |
648 | RETVAL = newSVpv (mbstr, 0); |
863 | RETVAL = taint_if (newSVpv (mbstr, 0), str); |
649 | free (mbstr); |
864 | free (mbstr); |
650 | } |
865 | } |
651 | OUTPUT: |
866 | OUTPUT: |
652 | RETVAL |
867 | RETVAL |
653 | |
868 | |
… | |
… | |
660 | |
875 | |
661 | rxvt_push_locale (THIS->locale); |
876 | rxvt_push_locale (THIS->locale); |
662 | wchar_t *wstr = rxvt_mbstowcs (data, len); |
877 | wchar_t *wstr = rxvt_mbstowcs (data, len); |
663 | rxvt_pop_locale (); |
878 | rxvt_pop_locale (); |
664 | |
879 | |
665 | RETVAL = wcs2sv (wstr); |
880 | RETVAL = taint_if (wcs2sv (wstr), octets); |
666 | free (wstr); |
881 | free (wstr); |
667 | } |
882 | } |
668 | OUTPUT: |
883 | OUTPUT: |
669 | RETVAL |
884 | RETVAL |
670 | |
885 | |
671 | # very portable, especially on objects as opposed to pods |
886 | #define TERM_OFFSET(sym) offsetof (TermWin_t, sym) |
672 | #define TERM_OFFSET(sym) (((char *)&((TermWin_t *)0)->sym) - (char *)(TermWin_t *)0) |
|
|
673 | |
887 | |
674 | #define TERM_OFFSET_width TERM_OFFSET(width) |
888 | #define TERM_OFFSET_width TERM_OFFSET(width) |
675 | #define TERM_OFFSET_height TERM_OFFSET(height) |
889 | #define TERM_OFFSET_height TERM_OFFSET(height) |
676 | #define TERM_OFFSET_fwidth TERM_OFFSET(fwidth) |
890 | #define TERM_OFFSET_fwidth TERM_OFFSET(fwidth) |
677 | #define TERM_OFFSET_fheight TERM_OFFSET(fheight) |
891 | #define TERM_OFFSET_fheight TERM_OFFSET(fheight) |
… | |
… | |
702 | CODE: |
916 | CODE: |
703 | RETVAL = *(int *)((char *)THIS + ix); |
917 | RETVAL = *(int *)((char *)THIS + ix); |
704 | OUTPUT: |
918 | OUTPUT: |
705 | RETVAL |
919 | RETVAL |
706 | |
920 | |
|
|
921 | unsigned int |
|
|
922 | rxvt_term::ModLevel3Mask () |
|
|
923 | ALIAS: |
|
|
924 | ModLevel3Mask = 0 |
|
|
925 | ModMetaMask = 1 |
|
|
926 | ModNumLockMask = 2 |
|
|
927 | CODE: |
|
|
928 | switch (ix) |
|
|
929 | { |
|
|
930 | case 0: RETVAL = THIS->ModLevel3Mask; break; |
|
|
931 | case 1: RETVAL = THIS->ModMetaMask; break; |
|
|
932 | case 2: RETVAL = THIS->ModNumLockMask; break; |
|
|
933 | } |
|
|
934 | OUTPUT: |
|
|
935 | RETVAL |
|
|
936 | |
|
|
937 | char * |
|
|
938 | rxvt_term::display_id () |
|
|
939 | CODE: |
|
|
940 | RETVAL = THIS->display->id; |
|
|
941 | OUTPUT: |
|
|
942 | RETVAL |
|
|
943 | |
|
|
944 | U32 |
|
|
945 | rxvt_term::parent () |
|
|
946 | CODE: |
|
|
947 | RETVAL = (U32)THIS->parent [0]; |
|
|
948 | OUTPUT: |
|
|
949 | RETVAL |
|
|
950 | |
|
|
951 | U32 |
|
|
952 | rxvt_term::vt () |
|
|
953 | CODE: |
|
|
954 | RETVAL = (U32)THIS->vt; |
|
|
955 | OUTPUT: |
|
|
956 | RETVAL |
|
|
957 | |
707 | U32 |
958 | U32 |
708 | rxvt_term::rstyle (U32 new_rstyle = THIS->rstyle) |
959 | rxvt_term::rstyle (U32 new_rstyle = THIS->rstyle) |
709 | CODE: |
960 | CODE: |
710 | { |
961 | { |
711 | RETVAL = THIS->rstyle; |
962 | RETVAL = THIS->rstyle; |
… | |
… | |
745 | |
996 | |
746 | if (GIMME_V != G_VOID) |
997 | if (GIMME_V != G_VOID) |
747 | { |
998 | { |
748 | wchar_t *wstr = new wchar_t [THIS->ncol]; |
999 | wchar_t *wstr = new wchar_t [THIS->ncol]; |
749 | |
1000 | |
750 | for (int col = 0; col <THIS->ncol; col++) |
1001 | for (int col = 0; col < THIS->ncol; col++) |
751 | wstr [col] = l.t [col]; |
1002 | wstr [col] = l.t [col]; |
752 | |
1003 | |
753 | XPUSHs (sv_2mortal (wcs2sv (wstr))); |
1004 | XPUSHs (taint (sv_2mortal (wcs2sv (wstr, THIS->ncol)))); |
754 | |
1005 | |
755 | delete [] wstr; |
1006 | delete [] wstr; |
756 | } |
1007 | } |
757 | |
1008 | |
758 | if (new_text) |
1009 | if (new_text) |
… | |
… | |
848 | } |
1099 | } |
849 | OUTPUT: |
1100 | OUTPUT: |
850 | RETVAL |
1101 | RETVAL |
851 | |
1102 | |
852 | SV * |
1103 | SV * |
853 | rxvt_term::special_encode (SV *str) |
1104 | rxvt_term::special_encode (SV *string) |
854 | CODE: |
1105 | CODE: |
855 | abort ();//TODO |
1106 | { |
|
|
1107 | wchar_t *wstr = sv2wcs (string); |
|
|
1108 | int wlen = wcslen (wstr); |
|
|
1109 | wchar_t *rstr = new wchar_t [wlen]; // cannot become longer |
|
|
1110 | |
|
|
1111 | rxvt_push_locale (THIS->locale); |
|
|
1112 | |
|
|
1113 | wchar_t *r = rstr; |
|
|
1114 | for (wchar_t *s = wstr; *s; s++) |
|
|
1115 | if (wcwidth (*s) == 0) |
|
|
1116 | { |
|
|
1117 | if (r == rstr) |
|
|
1118 | croak ("leading combining character unencodable"); |
|
|
1119 | |
|
|
1120 | unicode_t n = rxvt_compose (r[-1], *s); |
|
|
1121 | if (n == NOCHAR) |
|
|
1122 | n = rxvt_composite.compose (r[-1], *s); |
|
|
1123 | |
|
|
1124 | r[-1] = n; |
|
|
1125 | } |
|
|
1126 | #if !UNICODE_3 |
|
|
1127 | else if (*s >= 0x10000) |
|
|
1128 | *r++ = rxvt_composite.compose (*s); |
|
|
1129 | #endif |
|
|
1130 | else |
|
|
1131 | *r++ = *s; |
|
|
1132 | |
|
|
1133 | rxvt_pop_locale (); |
|
|
1134 | |
|
|
1135 | RETVAL = taint_if (wcs2sv (rstr, r - rstr), string); |
|
|
1136 | |
|
|
1137 | delete [] rstr; |
|
|
1138 | } |
|
|
1139 | OUTPUT: |
|
|
1140 | RETVAL |
856 | |
1141 | |
857 | SV * |
1142 | SV * |
858 | rxvt_term::special_decode (SV *str) |
1143 | rxvt_term::special_decode (SV *text) |
859 | CODE: |
1144 | CODE: |
860 | abort ();//TODO |
1145 | { |
|
|
1146 | wchar_t *wstr = sv2wcs (text); |
|
|
1147 | int wlen = wcslen (wstr); |
|
|
1148 | int dlen = 0; |
|
|
1149 | |
|
|
1150 | // find length |
|
|
1151 | for (wchar_t *s = wstr; *s; s++) |
|
|
1152 | if (*s == NOCHAR) |
|
|
1153 | ; |
|
|
1154 | else if (IS_COMPOSE (*s)) |
|
|
1155 | dlen += rxvt_composite.expand (*s, 0); |
|
|
1156 | else |
|
|
1157 | dlen++; |
|
|
1158 | |
|
|
1159 | wchar_t *rstr = new wchar_t [dlen]; |
|
|
1160 | |
|
|
1161 | // decode |
|
|
1162 | wchar_t *r = rstr; |
|
|
1163 | for (wchar_t *s = wstr; *s; s++) |
|
|
1164 | if (*s == NOCHAR) |
|
|
1165 | ; |
|
|
1166 | else if (IS_COMPOSE (*s)) |
|
|
1167 | r += rxvt_composite.expand (*s, r); |
|
|
1168 | else |
|
|
1169 | *r++ = *s; |
|
|
1170 | |
|
|
1171 | RETVAL = taint_if (wcs2sv (rstr, r - rstr), text); |
|
|
1172 | |
|
|
1173 | delete [] rstr; |
|
|
1174 | } |
|
|
1175 | OUTPUT: |
|
|
1176 | RETVAL |
861 | |
1177 | |
862 | void |
1178 | void |
863 | rxvt_term::_resource (char *name, int index, SV *newval = 0) |
1179 | rxvt_term::_resource (char *name, int index, SV *newval = 0) |
864 | PPCODE: |
1180 | PPCODE: |
865 | { |
1181 | { |
… | |
… | |
882 | |
1198 | |
883 | if (!IN_RANGE_EXC (index, 0, NUM_RESOURCES)) |
1199 | if (!IN_RANGE_EXC (index, 0, NUM_RESOURCES)) |
884 | croak ("requested out-of-bound resource %s+%d,", name, index - rs->value); |
1200 | croak ("requested out-of-bound resource %s+%d,", name, index - rs->value); |
885 | |
1201 | |
886 | if (GIMME_V != G_VOID) |
1202 | if (GIMME_V != G_VOID) |
887 | XPUSHs (THIS->rs [index] ? sv_2mortal (newSVpv (THIS->rs [index], 0)) : &PL_sv_undef); |
1203 | XPUSHs (THIS->rs [index] ? sv_2mortal (taint (newSVpv (THIS->rs [index], 0))) : &PL_sv_undef); |
888 | |
1204 | |
889 | if (newval) |
1205 | if (newval) |
890 | { |
1206 | { |
891 | if (SvOK (newval)) |
1207 | if (SvOK (newval)) |
892 | { |
1208 | { |
… | |
… | |
897 | else |
1213 | else |
898 | THIS->rs [index] = 0; |
1214 | THIS->rs [index] = 0; |
899 | } |
1215 | } |
900 | } |
1216 | } |
901 | |
1217 | |
|
|
1218 | bool |
|
|
1219 | rxvt_term::option (U32 optval, int set = -1) |
|
|
1220 | CODE: |
|
|
1221 | { |
|
|
1222 | RETVAL = THIS->options & optval; |
|
|
1223 | |
|
|
1224 | if (set >= 0) |
|
|
1225 | { |
|
|
1226 | if (set) |
|
|
1227 | THIS->options |= optval; |
|
|
1228 | else |
|
|
1229 | THIS->options &= ~optval; |
|
|
1230 | |
|
|
1231 | switch (optval) |
|
|
1232 | { |
|
|
1233 | case Opt_skipBuiltinGlyphs: |
|
|
1234 | THIS->set_fonts (); |
|
|
1235 | THIS->scr_remap_chars (); |
|
|
1236 | THIS->scr_touch (true); |
|
|
1237 | THIS->want_refresh = 1; |
|
|
1238 | break; |
|
|
1239 | |
|
|
1240 | case Opt_cursorUnderline: |
|
|
1241 | THIS->want_refresh = 1; |
|
|
1242 | break; |
|
|
1243 | |
|
|
1244 | # case Opt_scrollBar_floating: |
|
|
1245 | # case Opt_scrollBar_right: |
|
|
1246 | # THIS->resize_all_windows (THIS->width, THIS->height, 1); |
|
|
1247 | # break; |
|
|
1248 | } |
|
|
1249 | } |
|
|
1250 | } |
|
|
1251 | OUTPUT: |
|
|
1252 | RETVAL |
|
|
1253 | |
902 | void |
1254 | void |
903 | rxvt_term::cur (...) |
1255 | rxvt_term::screen_cur (...) |
904 | PROTOTYPE: $;$$ |
1256 | PROTOTYPE: $;$$ |
905 | ALIAS: |
1257 | ALIAS: |
906 | screen_cur = 0 |
1258 | screen_cur = 0 |
907 | selection_beg = 1 |
1259 | selection_beg = 1 |
908 | selection_end = 2 |
1260 | selection_end = 2 |
… | |
… | |
930 | THIS->want_refresh = 1; |
1282 | THIS->want_refresh = 1; |
931 | } |
1283 | } |
932 | } |
1284 | } |
933 | |
1285 | |
934 | int |
1286 | int |
935 | rxvt_term::selection_grab (int eventtime = CurrentTime) |
1287 | rxvt_term::selection_grab (U32 eventtime) |
936 | |
1288 | |
937 | void |
1289 | void |
938 | rxvt_term::selection (SV *newtext = 0) |
1290 | rxvt_term::selection (SV *newtext = 0) |
939 | PPCODE: |
1291 | PPCODE: |
940 | { |
1292 | { |
941 | if (GIMME_V != G_VOID) |
1293 | if (GIMME_V != G_VOID) |
|
|
1294 | XPUSHs (THIS->selection.text |
942 | XPUSHs (sv_2mortal (wcs2sv (THIS->selection.text, THIS->selection.len))); |
1295 | ? taint (sv_2mortal (wcs2sv (THIS->selection.text, THIS->selection.len))) |
|
|
1296 | : &PL_sv_undef); |
943 | |
1297 | |
944 | if (newtext) |
1298 | if (newtext) |
945 | { |
1299 | { |
946 | free (THIS->selection.text); |
1300 | free (THIS->selection.text); |
947 | |
1301 | |
… | |
… | |
953 | void |
1307 | void |
954 | rxvt_term::scr_add_lines (SV *string) |
1308 | rxvt_term::scr_add_lines (SV *string) |
955 | CODE: |
1309 | CODE: |
956 | { |
1310 | { |
957 | wchar_t *wstr = sv2wcs (string); |
1311 | wchar_t *wstr = sv2wcs (string); |
958 | int wlen = wcslen (wstr); |
|
|
959 | unicode_t *ustr = new unicode_t [wlen]; |
|
|
960 | int nlines = 0; |
|
|
961 | |
|
|
962 | for (int i = wlen; i--; ) |
|
|
963 | { |
|
|
964 | ustr [i] = wstr [i]; |
|
|
965 | nlines += ustr [i] == '\012'; |
|
|
966 | } |
|
|
967 | |
|
|
968 | THIS->scr_add_lines (ustr, nlines, wlen); |
1312 | THIS->scr_add_lines (wstr, wcslen (wstr)); |
969 | |
|
|
970 | free (wstr); |
1313 | free (wstr); |
971 | delete [] ustr; |
|
|
972 | } |
1314 | } |
973 | |
1315 | |
974 | void |
1316 | void |
975 | rxvt_term::tt_write (SV *octets) |
1317 | rxvt_term::tt_write (SV *octets) |
976 | INIT: |
1318 | INIT: |
977 | STRLEN len; |
1319 | STRLEN len; |
978 | char *str = SvPVbyte (octets, len); |
1320 | char *str = SvPVbyte (octets, len); |
979 | C_ARGS: |
1321 | C_ARGS: |
980 | str, len |
1322 | str, len |
981 | |
1323 | |
|
|
1324 | void |
|
|
1325 | rxvt_term::cmd_parse (SV *octets) |
|
|
1326 | CODE: |
|
|
1327 | { |
|
|
1328 | STRLEN len; |
|
|
1329 | char *str = SvPVbyte (octets, len); |
|
|
1330 | |
|
|
1331 | char *old_cmdbuf_ptr = THIS->cmdbuf_ptr; |
|
|
1332 | char *old_cmdbuf_endp = THIS->cmdbuf_endp; |
|
|
1333 | |
|
|
1334 | THIS->cmdbuf_ptr = str; |
|
|
1335 | THIS->cmdbuf_endp = str + len; |
|
|
1336 | |
|
|
1337 | rxvt_push_locale (THIS->locale); |
|
|
1338 | THIS->cmd_parse (); |
|
|
1339 | rxvt_pop_locale (); |
|
|
1340 | |
|
|
1341 | THIS->cmdbuf_ptr = old_cmdbuf_ptr; |
|
|
1342 | THIS->cmdbuf_endp = old_cmdbuf_endp; |
|
|
1343 | } |
|
|
1344 | |
982 | SV * |
1345 | SV * |
983 | rxvt_term::overlay (int x, int y, int w, int h, int rstyle = OVERLAY_RSTYLE, int border = 2) |
1346 | rxvt_term::overlay (int x, int y, int w, int h, int rstyle = OVERLAY_RSTYLE, int border = 2) |
984 | CODE: |
1347 | CODE: |
985 | { |
1348 | { |
986 | overlay *o = new overlay (THIS, x, y, w, h, rstyle, border); |
1349 | overlay *o = new overlay (THIS, x, y, w, h, rstyle, border); |