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. |
… | |
… | |
465 | |
465 | |
466 | case DT_LONG: |
466 | case DT_LONG: |
467 | XPUSHs (sv_2mortal (newSViv (va_arg (ap, long)))); |
467 | XPUSHs (sv_2mortal (newSViv (va_arg (ap, long)))); |
468 | break; |
468 | break; |
469 | |
469 | |
470 | case DT_STRING: |
470 | case DT_STR: |
471 | XPUSHs (sv_2mortal (newSVpv (va_arg (ap, char *), 0))); |
471 | XPUSHs (sv_2mortal (newSVpv (va_arg (ap, char *), 0))); |
472 | break; |
472 | break; |
473 | |
473 | |
474 | case DT_USTRING_LEN: |
474 | case DT_STR_LEN: |
475 | { |
475 | { |
476 | unicode_t *ustr = va_arg (ap, unicode_t *); |
476 | char *str = va_arg (ap, char *); |
477 | int ulen = va_arg (ap, int); |
477 | int len = va_arg (ap, int); |
|
|
478 | |
|
|
479 | XPUSHs (sv_2mortal (newSVpvn (str, len))); |
|
|
480 | } |
|
|
481 | break; |
|
|
482 | |
|
|
483 | case DT_WCS_LEN: |
|
|
484 | { |
478 | wchar_t *wstr = new wchar_t [ulen]; |
485 | wchar_t *wstr = va_arg (ap, wchar_t *); |
|
|
486 | int wlen = va_arg (ap, int); |
479 | |
487 | |
480 | for (int i = ulen; i--; ) |
|
|
481 | wstr [i] = ustr [i]; |
|
|
482 | |
|
|
483 | XPUSHs (sv_2mortal (wcs2sv (wstr, ulen))); |
488 | XPUSHs (sv_2mortal (wcs2sv (wstr, wlen))); |
|
|
489 | } |
484 | |
490 | |
485 | delete [] wstr; |
491 | case DT_XEVENT: |
486 | } |
492 | { |
|
|
493 | XEvent *xe = va_arg (ap, XEvent *); |
|
|
494 | HV *hv = newHV (); |
|
|
495 | |
|
|
496 | # define set(name, sv) hv_store (hv, # name, sizeof (# name) - 1, sv, 0) |
|
|
497 | # define setiv(name, val) hv_store (hv, # name, sizeof (# name) - 1, newSViv (val), 0) |
|
|
498 | # undef set |
|
|
499 | |
|
|
500 | setiv (type, xe->type); |
|
|
501 | setiv (send_event, xe->xany.send_event); |
|
|
502 | setiv (serial, xe->xany.serial); |
|
|
503 | |
|
|
504 | switch (xe->type) |
|
|
505 | { |
|
|
506 | case KeyPress: |
|
|
507 | case KeyRelease: |
|
|
508 | case ButtonPress: |
|
|
509 | case ButtonRelease: |
|
|
510 | case MotionNotify: |
|
|
511 | setiv (time, xe->xmotion.time); |
|
|
512 | setiv (x, xe->xmotion.x); |
|
|
513 | setiv (y, xe->xmotion.y); |
|
|
514 | setiv (row, xe->xmotion.y / term->fheight); |
|
|
515 | setiv (col, xe->xmotion.x / term->fwidth); |
|
|
516 | setiv (x_root, xe->xmotion.x_root); |
|
|
517 | setiv (y_root, xe->xmotion.y_root); |
|
|
518 | setiv (state, xe->xmotion.state); |
|
|
519 | break; |
|
|
520 | } |
|
|
521 | |
|
|
522 | switch (xe->type) |
|
|
523 | { |
|
|
524 | case KeyPress: |
|
|
525 | case KeyRelease: |
|
|
526 | setiv (keycode, xe->xkey.keycode); |
|
|
527 | break; |
|
|
528 | |
|
|
529 | case ButtonPress: |
|
|
530 | case ButtonRelease: |
|
|
531 | setiv (button, xe->xbutton.button); |
|
|
532 | break; |
|
|
533 | |
|
|
534 | case MotionNotify: |
|
|
535 | setiv (is_hint, xe->xmotion.is_hint); |
|
|
536 | break; |
|
|
537 | } |
|
|
538 | |
|
|
539 | XPUSHs (sv_2mortal (newRV_noinc ((SV *)hv))); |
|
|
540 | } |
|
|
541 | break; |
487 | |
542 | |
488 | case DT_END: |
543 | case DT_END: |
489 | { |
544 | { |
490 | va_end (ap); |
545 | va_end (ap); |
491 | |
546 | |
… | |
… | |
544 | export_const (RS_Uline); |
599 | export_const (RS_Uline); |
545 | |
600 | |
546 | sv_setpv (get_sv ("urxvt::LIBDIR", 1), LIBDIR); |
601 | sv_setpv (get_sv ("urxvt::LIBDIR", 1), LIBDIR); |
547 | } |
602 | } |
548 | |
603 | |
|
|
604 | SV * |
|
|
605 | new (...) |
|
|
606 | CODE: |
|
|
607 | { |
|
|
608 | stringvec *argv = new stringvec; |
|
|
609 | bool success; |
|
|
610 | |
|
|
611 | for (int i = 0; i < items ;i++) |
|
|
612 | argv->push_back (strdup (SvPVbyte_nolen (ST (i)))); |
|
|
613 | |
|
|
614 | rxvt_term *term = new rxvt_term; |
|
|
615 | |
|
|
616 | term->argv = argv; |
|
|
617 | |
|
|
618 | try |
|
|
619 | { |
|
|
620 | if (!term->init (argv->size (), argv->begin ())) |
|
|
621 | term = 0; |
|
|
622 | } |
|
|
623 | catch (const class rxvt_failure_exception &e) |
|
|
624 | { |
|
|
625 | term->destroy (); |
|
|
626 | croak ("exception caught while initializing new terminal instance"); |
|
|
627 | } |
|
|
628 | |
|
|
629 | RETVAL = term && term->self ? newSVterm (term) : &PL_sv_undef; |
|
|
630 | } |
|
|
631 | OUTPUT: |
|
|
632 | RETVAL |
|
|
633 | |
549 | void |
634 | void |
550 | set_should_invoke (int htype, int value) |
635 | set_should_invoke (int htype, int value) |
551 | CODE: |
636 | CODE: |
552 | rxvt_perl.should_invoke [htype] = value; |
637 | rxvt_perl.should_invoke [htype] = value; |
553 | |
638 | |
… | |
… | |
615 | } |
700 | } |
616 | OUTPUT: |
701 | OUTPUT: |
617 | RETVAL |
702 | RETVAL |
618 | |
703 | |
619 | MODULE = urxvt PACKAGE = urxvt::term |
704 | MODULE = urxvt PACKAGE = urxvt::term |
|
|
705 | |
|
|
706 | void |
|
|
707 | rxvt_term::destroy () |
620 | |
708 | |
621 | int |
709 | int |
622 | rxvt_term::strwidth (SV *str) |
710 | rxvt_term::strwidth (SV *str) |
623 | CODE: |
711 | CODE: |
624 | { |
712 | { |
… | |
… | |
703 | RETVAL = *(int *)((char *)THIS + ix); |
791 | RETVAL = *(int *)((char *)THIS + ix); |
704 | OUTPUT: |
792 | OUTPUT: |
705 | RETVAL |
793 | RETVAL |
706 | |
794 | |
707 | U32 |
795 | U32 |
|
|
796 | rxvt_term::parent () |
|
|
797 | CODE: |
|
|
798 | RETVAL = (U32)THIS->parent [0]; |
|
|
799 | OUTPUT: |
|
|
800 | RETVAL |
|
|
801 | |
|
|
802 | U32 |
|
|
803 | rxvt_term::vt () |
|
|
804 | CODE: |
|
|
805 | RETVAL = (U32)THIS->vt; |
|
|
806 | OUTPUT: |
|
|
807 | RETVAL |
|
|
808 | |
|
|
809 | U32 |
708 | rxvt_term::rstyle (U32 new_rstyle = THIS->rstyle) |
810 | rxvt_term::rstyle (U32 new_rstyle = THIS->rstyle) |
709 | CODE: |
811 | CODE: |
710 | { |
812 | { |
711 | RETVAL = THIS->rstyle; |
813 | RETVAL = THIS->rstyle; |
712 | THIS->rstyle = new_rstyle; |
814 | THIS->rstyle = new_rstyle; |
… | |
… | |
745 | |
847 | |
746 | if (GIMME_V != G_VOID) |
848 | if (GIMME_V != G_VOID) |
747 | { |
849 | { |
748 | wchar_t *wstr = new wchar_t [THIS->ncol]; |
850 | wchar_t *wstr = new wchar_t [THIS->ncol]; |
749 | |
851 | |
750 | for (int col = 0; col <THIS->ncol; col++) |
852 | for (int col = 0; col < THIS->ncol; col++) |
751 | wstr [col] = l.t [col]; |
853 | wstr [col] = l.t [col]; |
752 | |
854 | |
753 | XPUSHs (sv_2mortal (wcs2sv (wstr))); |
855 | XPUSHs (sv_2mortal (wcs2sv (wstr, THIS->ncol))); |
754 | |
856 | |
755 | delete [] wstr; |
857 | delete [] wstr; |
756 | } |
858 | } |
757 | |
859 | |
758 | if (new_text) |
860 | if (new_text) |
… | |
… | |
848 | } |
950 | } |
849 | OUTPUT: |
951 | OUTPUT: |
850 | RETVAL |
952 | RETVAL |
851 | |
953 | |
852 | SV * |
954 | SV * |
853 | rxvt_term::special_encode (SV *str) |
955 | rxvt_term::special_encode (SV *string) |
854 | CODE: |
956 | CODE: |
855 | abort ();//TODO |
957 | { |
|
|
958 | wchar_t *wstr = sv2wcs (string); |
|
|
959 | int wlen = wcslen (wstr); |
|
|
960 | wchar_t *rstr = new wchar_t [wlen]; // cannot become longer |
|
|
961 | |
|
|
962 | rxvt_push_locale (THIS->locale); |
|
|
963 | |
|
|
964 | wchar_t *r = rstr; |
|
|
965 | for (wchar_t *s = wstr; *s; s++) |
|
|
966 | if (wcwidth (*s) == 0) |
|
|
967 | { |
|
|
968 | if (r == rstr) |
|
|
969 | croak ("leading combining character unencodable"); |
|
|
970 | |
|
|
971 | unicode_t n = rxvt_compose (r[-1], *s); |
|
|
972 | if (n == NOCHAR) |
|
|
973 | n = rxvt_composite.compose (r[-1], *s); |
|
|
974 | |
|
|
975 | r[-1] = n; |
|
|
976 | } |
|
|
977 | #if !UNICODE_3 |
|
|
978 | else if (*s >= 0x10000) |
|
|
979 | *r++ = rxvt_composite.compose (*s); |
|
|
980 | #endif |
|
|
981 | else |
|
|
982 | *r++ = *s; |
|
|
983 | |
|
|
984 | rxvt_pop_locale (); |
|
|
985 | |
|
|
986 | RETVAL = wcs2sv (rstr, r - rstr); |
|
|
987 | |
|
|
988 | delete [] rstr; |
|
|
989 | } |
|
|
990 | OUTPUT: |
|
|
991 | RETVAL |
856 | |
992 | |
857 | SV * |
993 | SV * |
858 | rxvt_term::special_decode (SV *str) |
994 | rxvt_term::special_decode (SV *text) |
859 | CODE: |
995 | CODE: |
860 | abort ();//TODO |
996 | { |
|
|
997 | wchar_t *wstr = sv2wcs (text); |
|
|
998 | int wlen = wcslen (wstr); |
|
|
999 | int dlen = 0; |
|
|
1000 | |
|
|
1001 | // find length |
|
|
1002 | for (wchar_t *s = wstr; *s; s++) |
|
|
1003 | if (*s == NOCHAR) |
|
|
1004 | ; |
|
|
1005 | else if (IS_COMPOSE (*s)) |
|
|
1006 | dlen += rxvt_composite.expand (*s, 0); |
|
|
1007 | else |
|
|
1008 | dlen++; |
|
|
1009 | |
|
|
1010 | wchar_t *rstr = new wchar_t [dlen]; |
|
|
1011 | |
|
|
1012 | // decode |
|
|
1013 | wchar_t *r = rstr; |
|
|
1014 | for (wchar_t *s = wstr; *s; s++) |
|
|
1015 | if (*s == NOCHAR) |
|
|
1016 | ; |
|
|
1017 | else if (IS_COMPOSE (*s)) |
|
|
1018 | r += rxvt_composite.expand (*s, r); |
|
|
1019 | else |
|
|
1020 | *r++ = *s; |
|
|
1021 | |
|
|
1022 | RETVAL = wcs2sv (rstr, r - rstr); |
|
|
1023 | |
|
|
1024 | delete [] rstr; |
|
|
1025 | } |
|
|
1026 | OUTPUT: |
|
|
1027 | RETVAL |
861 | |
1028 | |
862 | void |
1029 | void |
863 | rxvt_term::_resource (char *name, int index, SV *newval = 0) |
1030 | rxvt_term::_resource (char *name, int index, SV *newval = 0) |
864 | PPCODE: |
1031 | PPCODE: |
865 | { |
1032 | { |
… | |
… | |
953 | void |
1120 | void |
954 | rxvt_term::scr_add_lines (SV *string) |
1121 | rxvt_term::scr_add_lines (SV *string) |
955 | CODE: |
1122 | CODE: |
956 | { |
1123 | { |
957 | wchar_t *wstr = sv2wcs (string); |
1124 | 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); |
1125 | THIS->scr_add_lines (wstr, wcslen (wstr)); |
969 | |
|
|
970 | free (wstr); |
1126 | free (wstr); |
971 | delete [] ustr; |
|
|
972 | } |
1127 | } |
973 | |
1128 | |
974 | void |
1129 | void |
975 | rxvt_term::tt_write (SV *octets) |
1130 | rxvt_term::tt_write (SV *octets) |
976 | INIT: |
1131 | INIT: |
977 | STRLEN len; |
1132 | STRLEN len; |
978 | char *str = SvPVbyte (octets, len); |
1133 | char *str = SvPVbyte (octets, len); |
979 | C_ARGS: |
1134 | C_ARGS: |
980 | str, len |
1135 | str, len |
981 | |
1136 | |
|
|
1137 | void |
|
|
1138 | rxvt_term::cmd_parse (SV *octets) |
|
|
1139 | CODE: |
|
|
1140 | { |
|
|
1141 | STRLEN len; |
|
|
1142 | char *str = SvPVbyte (octets, len); |
|
|
1143 | |
|
|
1144 | char *old_cmdbuf_ptr = THIS->cmdbuf_ptr; |
|
|
1145 | char *old_cmdbuf_endp = THIS->cmdbuf_endp; |
|
|
1146 | |
|
|
1147 | THIS->cmdbuf_ptr = str; |
|
|
1148 | THIS->cmdbuf_endp = str + len; |
|
|
1149 | |
|
|
1150 | THIS->cmd_parse (); |
|
|
1151 | |
|
|
1152 | THIS->cmdbuf_ptr = old_cmdbuf_ptr; |
|
|
1153 | THIS->cmdbuf_endp = old_cmdbuf_endp; |
|
|
1154 | } |
|
|
1155 | |
982 | SV * |
1156 | SV * |
983 | rxvt_term::overlay (int x, int y, int w, int h, int rstyle = OVERLAY_RSTYLE, int border = 2) |
1157 | rxvt_term::overlay (int x, int y, int w, int h, int rstyle = OVERLAY_RSTYLE, int border = 2) |
984 | CODE: |
1158 | CODE: |
985 | { |
1159 | { |
986 | overlay *o = new overlay (THIS, x, y, w, h, rstyle, border); |
1160 | overlay *o = new overlay (THIS, x, y, w, h, rstyle, border); |