… | |
… | |
51 | char *str = SvPVutf8 (sv, len); |
51 | char *str = SvPVutf8 (sv, len); |
52 | return rxvt_utf8towcs (str, len); |
52 | return rxvt_utf8towcs (str, len); |
53 | } |
53 | } |
54 | |
54 | |
55 | static SV * |
55 | static SV * |
|
|
56 | wcs2sv (wchar_t *wstr, int len = -1) |
|
|
57 | { |
|
|
58 | char *str = rxvt_wcstoutf8 (wstr, len); |
|
|
59 | |
|
|
60 | SV *sv = newSVpv (str, 0); |
|
|
61 | SvUTF8_on (sv); |
|
|
62 | free (str); |
|
|
63 | |
|
|
64 | return sv; |
|
|
65 | } |
|
|
66 | |
|
|
67 | static SV * |
56 | new_ref (HV *hv, const char *klass) |
68 | new_ref (HV *hv, const char *klass) |
57 | { |
69 | { |
58 | return sv_bless (newRV ((SV *)hv), gv_stashpv (klass, 1)); |
70 | return sv_bless (newRV ((SV *)hv), gv_stashpv (klass, 1)); |
59 | } |
71 | } |
60 | |
72 | |
… | |
… | |
457 | |
469 | |
458 | case DT_STRING: |
470 | case DT_STRING: |
459 | XPUSHs (sv_2mortal (newSVpv (va_arg (ap, char *), 0))); |
471 | XPUSHs (sv_2mortal (newSVpv (va_arg (ap, char *), 0))); |
460 | break; |
472 | break; |
461 | |
473 | |
|
|
474 | case DT_STRING_LEN: |
|
|
475 | { |
|
|
476 | char *str = va_arg (ap, char *); |
|
|
477 | int len = va_arg (ap, int); |
|
|
478 | |
|
|
479 | XPUSHs (sv_2mortal (newSVpvn (str, len))); |
|
|
480 | } |
|
|
481 | break; |
|
|
482 | |
|
|
483 | case DT_XEVENT: |
|
|
484 | { |
|
|
485 | XEvent *xe = va_arg (ap, XEvent *); |
|
|
486 | HV *hv = newHV (); |
|
|
487 | |
|
|
488 | # define set(name, sv) hv_store (hv, # name, sizeof (# name) - 1, sv, 0) |
|
|
489 | # define setiv(name, val) hv_store (hv, # name, sizeof (# name) - 1, newSViv (val), 0) |
|
|
490 | # undef set |
|
|
491 | |
|
|
492 | setiv (type, xe->type); |
|
|
493 | setiv (send_event, xe->xany.send_event); |
|
|
494 | setiv (serial, xe->xany.serial); |
|
|
495 | |
|
|
496 | switch (xe->type) |
|
|
497 | { |
|
|
498 | case KeyPress: |
|
|
499 | case KeyRelease: |
|
|
500 | case ButtonPress: |
|
|
501 | case ButtonRelease: |
|
|
502 | case MotionNotify: |
|
|
503 | setiv (time, xe->xmotion.time); |
|
|
504 | setiv (x, xe->xmotion.x); |
|
|
505 | setiv (y, xe->xmotion.y); |
|
|
506 | setiv (x_root, xe->xmotion.x_root); |
|
|
507 | setiv (y_root, xe->xmotion.y_root); |
|
|
508 | setiv (state, xe->xmotion.state); |
|
|
509 | break; |
|
|
510 | } |
|
|
511 | |
|
|
512 | switch (xe->type) |
|
|
513 | { |
|
|
514 | case KeyPress: |
|
|
515 | case KeyRelease: |
|
|
516 | setiv (keycode, xe->xkey.keycode); |
|
|
517 | break; |
|
|
518 | |
|
|
519 | case ButtonPress: |
|
|
520 | case ButtonRelease: |
|
|
521 | setiv (button, xe->xbutton.button); |
|
|
522 | break; |
|
|
523 | |
|
|
524 | case MotionNotify: |
|
|
525 | setiv (is_hint, xe->xmotion.is_hint); |
|
|
526 | break; |
|
|
527 | } |
|
|
528 | |
|
|
529 | XPUSHs (sv_2mortal (newRV_noinc ((SV *)hv))); |
|
|
530 | } |
|
|
531 | break; |
|
|
532 | |
|
|
533 | case DT_USTRING_LEN: |
|
|
534 | { |
|
|
535 | unicode_t *ustr = va_arg (ap, unicode_t *); |
|
|
536 | int ulen = va_arg (ap, int); |
|
|
537 | wchar_t *wstr = new wchar_t [ulen]; |
|
|
538 | |
|
|
539 | for (int i = ulen; i--; ) |
|
|
540 | wstr [i] = ustr [i]; |
|
|
541 | |
|
|
542 | XPUSHs (sv_2mortal (wcs2sv (wstr, ulen))); |
|
|
543 | |
|
|
544 | delete [] wstr; |
|
|
545 | } |
|
|
546 | |
462 | case DT_END: |
547 | case DT_END: |
463 | { |
548 | { |
464 | va_end (ap); |
549 | va_end (ap); |
465 | |
550 | |
466 | PUTBACK; |
551 | PUTBACK; |
… | |
… | |
518 | export_const (RS_Uline); |
603 | export_const (RS_Uline); |
519 | |
604 | |
520 | sv_setpv (get_sv ("urxvt::LIBDIR", 1), LIBDIR); |
605 | sv_setpv (get_sv ("urxvt::LIBDIR", 1), LIBDIR); |
521 | } |
606 | } |
522 | |
607 | |
|
|
608 | SV * |
|
|
609 | new (...) |
|
|
610 | CODE: |
|
|
611 | { |
|
|
612 | stringvec *argv = new stringvec; |
|
|
613 | bool success; |
|
|
614 | |
|
|
615 | for (int i = 0; i < items ;i++) |
|
|
616 | argv->push_back (strdup (SvPVbyte_nolen (ST (i)))); |
|
|
617 | |
|
|
618 | rxvt_term *term = new rxvt_term; |
|
|
619 | |
|
|
620 | term->argv = argv; |
|
|
621 | |
|
|
622 | try |
|
|
623 | { |
|
|
624 | if (!term->init (argv->size (), argv->begin ())) |
|
|
625 | term = 0; |
|
|
626 | } |
|
|
627 | catch (const class rxvt_failure_exception &e) |
|
|
628 | { |
|
|
629 | term->destroy (); |
|
|
630 | croak ("exception caught while initializing new terminal instance"); |
|
|
631 | } |
|
|
632 | |
|
|
633 | RETVAL = term && term->self ? newSVterm (term) : &PL_sv_undef; |
|
|
634 | } |
|
|
635 | OUTPUT: |
|
|
636 | RETVAL |
|
|
637 | |
523 | void |
638 | void |
524 | set_should_invoke (int htype, int value) |
639 | set_should_invoke (int htype, int value) |
525 | CODE: |
640 | CODE: |
526 | rxvt_perl.should_invoke [htype] = value; |
641 | rxvt_perl.should_invoke [htype] = value; |
527 | |
642 | |
… | |
… | |
589 | } |
704 | } |
590 | OUTPUT: |
705 | OUTPUT: |
591 | RETVAL |
706 | RETVAL |
592 | |
707 | |
593 | MODULE = urxvt PACKAGE = urxvt::term |
708 | MODULE = urxvt PACKAGE = urxvt::term |
|
|
709 | |
|
|
710 | void |
|
|
711 | rxvt_term::destroy () |
594 | |
712 | |
595 | int |
713 | int |
596 | rxvt_term::strwidth (SV *str) |
714 | rxvt_term::strwidth (SV *str) |
597 | CODE: |
715 | CODE: |
598 | { |
716 | { |
… | |
… | |
634 | |
752 | |
635 | rxvt_push_locale (THIS->locale); |
753 | rxvt_push_locale (THIS->locale); |
636 | wchar_t *wstr = rxvt_mbstowcs (data, len); |
754 | wchar_t *wstr = rxvt_mbstowcs (data, len); |
637 | rxvt_pop_locale (); |
755 | rxvt_pop_locale (); |
638 | |
756 | |
639 | char *str = rxvt_wcstoutf8 (wstr); |
757 | RETVAL = wcs2sv (wstr); |
640 | free (wstr); |
758 | free (wstr); |
641 | |
|
|
642 | RETVAL = newSVpv (str, 0); |
|
|
643 | SvUTF8_on (RETVAL); |
|
|
644 | free (str); |
|
|
645 | } |
759 | } |
646 | OUTPUT: |
760 | OUTPUT: |
647 | RETVAL |
761 | RETVAL |
648 | |
762 | |
649 | # very portable, especially on objects as opposed to pods |
763 | # very portable, especially on objects as opposed to pods |
… | |
… | |
681 | RETVAL = *(int *)((char *)THIS + ix); |
795 | RETVAL = *(int *)((char *)THIS + ix); |
682 | OUTPUT: |
796 | OUTPUT: |
683 | RETVAL |
797 | RETVAL |
684 | |
798 | |
685 | U32 |
799 | U32 |
686 | rxvt_term::screen_rstyle (U32 new_rstyle = THIS->screen.s_rstyle) |
800 | rxvt_term::rstyle (U32 new_rstyle = THIS->rstyle) |
687 | CODE: |
801 | CODE: |
688 | { |
802 | { |
689 | RETVAL = THIS->screen.s_rstyle; |
803 | RETVAL = THIS->rstyle; |
690 | THIS->screen.s_rstyle = new_rstyle; |
804 | THIS->rstyle = new_rstyle; |
691 | } |
805 | } |
692 | OUTPUT: |
806 | OUTPUT: |
693 | RETVAL |
807 | RETVAL |
694 | |
808 | |
695 | int |
809 | int |
… | |
… | |
711 | rxvt_term::want_refresh () |
825 | rxvt_term::want_refresh () |
712 | CODE: |
826 | CODE: |
713 | THIS->want_refresh = 1; |
827 | THIS->want_refresh = 1; |
714 | |
828 | |
715 | void |
829 | void |
716 | rxvt_term::ROW_t (int row_number, SV *new_text = 0, int start_col = 0) |
830 | rxvt_term::ROW_t (int row_number, SV *new_text = 0, int start_col = 0, int start_ofs = 0, int max_len = MAX_COLS) |
717 | PPCODE: |
831 | PPCODE: |
718 | { |
832 | { |
719 | if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) |
833 | if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) |
720 | XSRETURN_EMPTY; |
834 | XSRETURN_EMPTY; |
721 | |
835 | |
… | |
… | |
726 | wchar_t *wstr = new wchar_t [THIS->ncol]; |
840 | wchar_t *wstr = new wchar_t [THIS->ncol]; |
727 | |
841 | |
728 | for (int col = 0; col <THIS->ncol; col++) |
842 | for (int col = 0; col <THIS->ncol; col++) |
729 | wstr [col] = l.t [col]; |
843 | wstr [col] = l.t [col]; |
730 | |
844 | |
731 | char *str = rxvt_wcstoutf8 (wstr, THIS->ncol); |
|
|
732 | free (wstr); |
|
|
733 | |
|
|
734 | SV *sv = newSVpv (str, 0); |
|
|
735 | SvUTF8_on (sv); |
|
|
736 | XPUSHs (sv_2mortal (sv)); |
845 | XPUSHs (sv_2mortal (wcs2sv (wstr))); |
737 | free (str); |
846 | |
|
|
847 | delete [] wstr; |
738 | } |
848 | } |
739 | |
849 | |
740 | if (new_text) |
850 | if (new_text) |
741 | { |
851 | { |
742 | wchar_t *wstr = sv2wcs (new_text); |
852 | wchar_t *wstr = sv2wcs (new_text); |
743 | |
853 | |
744 | int len = wcslen (wstr); |
854 | int len = min (wcslen (wstr) - start_ofs, max_len); |
745 | |
855 | |
746 | if (!IN_RANGE_INC (start_col, 0, THIS->ncol - len)) |
856 | if (!IN_RANGE_INC (start_col, 0, THIS->ncol - len)) |
747 | { |
857 | { |
748 | free (wstr); |
858 | free (wstr); |
749 | croak ("new_text extends beyond horizontal margins"); |
859 | croak ("new_text extends beyond horizontal margins"); |
750 | } |
860 | } |
751 | |
861 | |
752 | for (int col = start_col; col < start_col + len; col++) |
862 | for (int col = start_col; col < start_col + len; col++) |
753 | { |
863 | { |
754 | l.t [col] = wstr [col - start_col]; |
864 | l.t [col] = wstr [start_ofs + col - start_col]; |
755 | l.r [col] = SET_FONT (l.r [col], THIS->fontset [GET_STYLE (l.r [col])]->find_font (l.t [col])); |
865 | l.r [col] = SET_FONT (l.r [col], THIS->fontset [GET_STYLE (l.r [col])]->find_font (l.t [col])); |
756 | } |
866 | } |
757 | |
867 | |
758 | free (wstr); |
868 | free (wstr); |
759 | } |
869 | } |
760 | } |
870 | } |
761 | |
871 | |
762 | void |
872 | void |
763 | rxvt_term::ROW_r (int row_number, SV *new_rend = 0, int start_col = 0) |
873 | rxvt_term::ROW_r (int row_number, SV *new_rend = 0, int start_col = 0, int start_ofs = 0, int max_len = MAX_COLS) |
764 | PPCODE: |
874 | PPCODE: |
765 | { |
875 | { |
766 | if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) |
876 | if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) |
767 | XSRETURN_EMPTY; |
877 | XSRETURN_EMPTY; |
768 | |
878 | |
… | |
… | |
783 | { |
893 | { |
784 | if (!SvROK (new_rend) || SvTYPE (SvRV (new_rend)) != SVt_PVAV) |
894 | if (!SvROK (new_rend) || SvTYPE (SvRV (new_rend)) != SVt_PVAV) |
785 | croak ("new_rend must be arrayref"); |
895 | croak ("new_rend must be arrayref"); |
786 | |
896 | |
787 | AV *av = (AV *)SvRV (new_rend); |
897 | AV *av = (AV *)SvRV (new_rend); |
788 | int len = av_len (av) + 1; |
898 | int len = min (av_len (av) + 1 - start_ofs, max_len); |
789 | |
899 | |
790 | if (!IN_RANGE_INC (start_col, 0, THIS->ncol - len)) |
900 | if (!IN_RANGE_INC (start_col, 0, THIS->ncol - len)) |
791 | croak ("new_rend array extends beyond horizontal margins"); |
901 | croak ("new_rend array extends beyond horizontal margins"); |
792 | |
902 | |
793 | for (int col = start_col; col < start_col + len; col++) |
903 | for (int col = start_col; col < start_col + len; col++) |
794 | { |
904 | { |
795 | rend_t r = SvIV (*av_fetch (av, col - start_col, 1)) & ~RS_fontMask; |
905 | rend_t r = SvIV (*av_fetch (av, start_ofs + col - start_col, 1)) & ~RS_fontMask; |
796 | |
906 | |
797 | l.r [col] = SET_FONT (r, THIS->fontset [GET_STYLE (r)]->find_font (l.t [col])); |
907 | l.r [col] = SET_FONT (r, THIS->fontset [GET_STYLE (r)]->find_font (l.t [col])); |
798 | } |
908 | } |
799 | } |
909 | } |
800 | } |
910 | } |
801 | |
911 | |
802 | int |
912 | int |
803 | rxvt_term::ROW_l (int row_number, int new_length = -2) |
913 | rxvt_term::ROW_l (int row_number, int new_length = -1) |
804 | CODE: |
914 | CODE: |
805 | { |
915 | { |
806 | if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) |
916 | if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) |
807 | XSRETURN_EMPTY; |
917 | XSRETURN_EMPTY; |
808 | |
918 | |
809 | line_t &l = ROW(row_number); |
919 | line_t &l = ROW(row_number); |
810 | RETVAL = l.l < 0 ? THIS->ncol : l.l; |
920 | RETVAL = l.l; |
811 | |
921 | |
812 | if (new_length >= -1) |
922 | if (new_length >= 0) |
813 | l.l = new_length; |
923 | l.l = new_length; |
814 | } |
924 | } |
815 | OUTPUT: |
925 | OUTPUT: |
816 | RETVAL |
926 | RETVAL |
817 | |
927 | |
818 | bool |
928 | bool |
819 | rxvt_term::ROW_is_longer (int row_number) |
929 | rxvt_term::ROW_is_longer (int row_number, int new_is_longer = -1) |
820 | CODE: |
930 | CODE: |
821 | { |
931 | { |
822 | if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) |
932 | if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) |
823 | XSRETURN_EMPTY; |
933 | XSRETURN_EMPTY; |
824 | |
934 | |
825 | line_t &l = ROW(row_number); |
935 | line_t &l = ROW(row_number); |
826 | RETVAL = l.l < 0; |
936 | RETVAL = l.is_longer (); |
|
|
937 | |
|
|
938 | if (new_is_longer >= 0) |
|
|
939 | l.is_longer (new_is_longer); |
827 | } |
940 | } |
828 | OUTPUT: |
941 | OUTPUT: |
829 | RETVAL |
942 | RETVAL |
830 | |
943 | |
831 | SV * |
944 | SV * |
… | |
… | |
916 | void |
1029 | void |
917 | rxvt_term::selection (SV *newtext = 0) |
1030 | rxvt_term::selection (SV *newtext = 0) |
918 | PPCODE: |
1031 | PPCODE: |
919 | { |
1032 | { |
920 | if (GIMME_V != G_VOID) |
1033 | if (GIMME_V != G_VOID) |
921 | { |
1034 | XPUSHs (sv_2mortal (wcs2sv (THIS->selection.text, THIS->selection.len))); |
922 | char *sel = rxvt_wcstoutf8 (THIS->selection.text, THIS->selection.len); |
|
|
923 | SV *sv = newSVpv (sel, 0); |
|
|
924 | SvUTF8_on (sv); |
|
|
925 | free (sel); |
|
|
926 | XPUSHs (sv_2mortal (sv)); |
|
|
927 | } |
|
|
928 | |
1035 | |
929 | if (newtext) |
1036 | if (newtext) |
930 | { |
1037 | { |
931 | free (THIS->selection.text); |
1038 | free (THIS->selection.text); |
932 | |
1039 | |
933 | THIS->selection.text = sv2wcs (newtext); |
1040 | THIS->selection.text = sv2wcs (newtext); |
934 | THIS->selection.len = wcslen (THIS->selection.text); |
1041 | THIS->selection.len = wcslen (THIS->selection.text); |
935 | } |
1042 | } |
|
|
1043 | } |
|
|
1044 | |
|
|
1045 | void |
|
|
1046 | rxvt_term::scr_add_lines (SV *string) |
|
|
1047 | CODE: |
|
|
1048 | { |
|
|
1049 | wchar_t *wstr = sv2wcs (string); |
|
|
1050 | int wlen = wcslen (wstr); |
|
|
1051 | unicode_t *ustr = new unicode_t [wlen]; |
|
|
1052 | int nlines = 0; |
|
|
1053 | |
|
|
1054 | for (int i = wlen; i--; ) |
|
|
1055 | { |
|
|
1056 | ustr [i] = wstr [i]; |
|
|
1057 | nlines += ustr [i] == '\012'; |
|
|
1058 | } |
|
|
1059 | |
|
|
1060 | THIS->scr_add_lines (ustr, nlines, wlen); |
|
|
1061 | |
|
|
1062 | free (wstr); |
|
|
1063 | delete [] ustr; |
936 | } |
1064 | } |
937 | |
1065 | |
938 | void |
1066 | void |
939 | rxvt_term::tt_write (SV *octets) |
1067 | rxvt_term::tt_write (SV *octets) |
940 | INIT: |
1068 | INIT: |
941 | STRLEN len; |
1069 | STRLEN len; |
942 | char *str = SvPVbyte (octets, len); |
1070 | char *str = SvPVbyte (octets, len); |
943 | C_ARGS: |
1071 | C_ARGS: |
944 | str, len |
1072 | str, len |
945 | |
1073 | |
|
|
1074 | void |
|
|
1075 | rxvt_term::cmd_parse (SV *octets) |
|
|
1076 | CODE: |
|
|
1077 | { |
|
|
1078 | STRLEN len; |
|
|
1079 | char *str = SvPVbyte (octets, len); |
|
|
1080 | |
|
|
1081 | char *old_cmdbuf_ptr = THIS->cmdbuf_ptr; |
|
|
1082 | char *old_cmdbuf_endp = THIS->cmdbuf_endp; |
|
|
1083 | |
|
|
1084 | THIS->cmdbuf_ptr = str; |
|
|
1085 | THIS->cmdbuf_endp = str + len; |
|
|
1086 | |
|
|
1087 | THIS->cmd_parse (); |
|
|
1088 | |
|
|
1089 | THIS->cmdbuf_ptr = old_cmdbuf_ptr; |
|
|
1090 | THIS->cmdbuf_endp = old_cmdbuf_endp; |
|
|
1091 | } |
|
|
1092 | |
946 | SV * |
1093 | SV * |
947 | rxvt_term::overlay (int x, int y, int w, int h, int rstyle = OVERLAY_RSTYLE, int border = 2) |
1094 | rxvt_term::overlay (int x, int y, int w, int h, int rstyle = OVERLAY_RSTYLE, int border = 2) |
948 | CODE: |
1095 | CODE: |
949 | { |
1096 | { |
950 | overlay *o = new overlay (THIS, x, y, w, h, rstyle, border); |
1097 | overlay *o = new overlay (THIS, x, y, w, h, rstyle, border); |