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_STRING_LEN: |
474 | case DT_STR_LEN: |
475 | { |
475 | { |
476 | char *str = va_arg (ap, char *); |
476 | char *str = va_arg (ap, char *); |
477 | int len = va_arg (ap, int); |
477 | int len = va_arg (ap, int); |
478 | |
478 | |
479 | XPUSHs (sv_2mortal (newSVpvn (str, len))); |
479 | XPUSHs (sv_2mortal (newSVpvn (str, len))); |
480 | } |
480 | } |
481 | break; |
481 | break; |
|
|
482 | |
|
|
483 | case DT_WCS_LEN: |
|
|
484 | { |
|
|
485 | wchar_t *wstr = va_arg (ap, wchar_t *); |
|
|
486 | int wlen = va_arg (ap, int); |
|
|
487 | |
|
|
488 | XPUSHs (sv_2mortal (wcs2sv (wstr, wlen))); |
|
|
489 | } |
|
|
490 | break; |
482 | |
491 | |
483 | case DT_XEVENT: |
492 | case DT_XEVENT: |
484 | { |
493 | { |
485 | XEvent *xe = va_arg (ap, XEvent *); |
494 | XEvent *xe = va_arg (ap, XEvent *); |
486 | HV *hv = newHV (); |
495 | HV *hv = newHV (); |
… | |
… | |
530 | |
539 | |
531 | XPUSHs (sv_2mortal (newRV_noinc ((SV *)hv))); |
540 | XPUSHs (sv_2mortal (newRV_noinc ((SV *)hv))); |
532 | } |
541 | } |
533 | break; |
542 | break; |
534 | |
543 | |
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: |
544 | case DT_END: |
550 | { |
545 | { |
551 | va_end (ap); |
546 | va_end (ap); |
552 | |
547 | |
553 | PUTBACK; |
548 | PUTBACK; |
… | |
… | |
797 | RETVAL = *(int *)((char *)THIS + ix); |
792 | RETVAL = *(int *)((char *)THIS + ix); |
798 | OUTPUT: |
793 | OUTPUT: |
799 | RETVAL |
794 | RETVAL |
800 | |
795 | |
801 | U32 |
796 | U32 |
|
|
797 | rxvt_term::parent () |
|
|
798 | CODE: |
|
|
799 | RETVAL = (U32)THIS->parent [0]; |
|
|
800 | OUTPUT: |
|
|
801 | RETVAL |
|
|
802 | |
|
|
803 | U32 |
802 | rxvt_term::vt () |
804 | rxvt_term::vt () |
803 | CODE: |
805 | CODE: |
804 | RETVAL = THIS->vt; |
806 | RETVAL = (U32)THIS->vt; |
805 | OUTPUT: |
807 | OUTPUT: |
806 | RETVAL |
808 | RETVAL |
807 | |
809 | |
808 | U32 |
810 | U32 |
809 | rxvt_term::rstyle (U32 new_rstyle = THIS->rstyle) |
811 | rxvt_term::rstyle (U32 new_rstyle = THIS->rstyle) |
… | |
… | |
846 | |
848 | |
847 | if (GIMME_V != G_VOID) |
849 | if (GIMME_V != G_VOID) |
848 | { |
850 | { |
849 | wchar_t *wstr = new wchar_t [THIS->ncol]; |
851 | wchar_t *wstr = new wchar_t [THIS->ncol]; |
850 | |
852 | |
851 | for (int col = 0; col <THIS->ncol; col++) |
853 | for (int col = 0; col < THIS->ncol; col++) |
852 | wstr [col] = l.t [col]; |
854 | wstr [col] = l.t [col]; |
853 | |
855 | |
854 | XPUSHs (sv_2mortal (wcs2sv (wstr))); |
856 | XPUSHs (sv_2mortal (wcs2sv (wstr, THIS->ncol))); |
855 | |
857 | |
856 | delete [] wstr; |
858 | delete [] wstr; |
857 | } |
859 | } |
858 | |
860 | |
859 | if (new_text) |
861 | if (new_text) |
… | |
… | |
949 | } |
951 | } |
950 | OUTPUT: |
952 | OUTPUT: |
951 | RETVAL |
953 | RETVAL |
952 | |
954 | |
953 | SV * |
955 | SV * |
954 | rxvt_term::special_encode (SV *str) |
956 | rxvt_term::special_encode (SV *string) |
955 | CODE: |
957 | CODE: |
956 | abort ();//TODO |
958 | { |
|
|
959 | wchar_t *wstr = sv2wcs (string); |
|
|
960 | int wlen = wcslen (wstr); |
|
|
961 | wchar_t *rstr = new wchar_t [wlen]; // cannot become longer |
|
|
962 | |
|
|
963 | rxvt_push_locale (THIS->locale); |
|
|
964 | |
|
|
965 | wchar_t *r = rstr; |
|
|
966 | for (wchar_t *s = wstr; *s; s++) |
|
|
967 | if (wcwidth (*s) == 0) |
|
|
968 | { |
|
|
969 | if (r == rstr) |
|
|
970 | croak ("leading combining character unencodable"); |
|
|
971 | |
|
|
972 | unicode_t n = rxvt_compose (r[-1], *s); |
|
|
973 | if (n == NOCHAR) |
|
|
974 | n = rxvt_composite.compose (r[-1], *s); |
|
|
975 | |
|
|
976 | r[-1] = n; |
|
|
977 | } |
|
|
978 | #if !UNICODE_3 |
|
|
979 | else if (*s >= 0x10000) |
|
|
980 | *r++ = rxvt_composite.compose (*s); |
|
|
981 | #endif |
|
|
982 | else |
|
|
983 | *r++ = *s; |
|
|
984 | |
|
|
985 | rxvt_pop_locale (); |
|
|
986 | |
|
|
987 | RETVAL = wcs2sv (rstr, r - rstr); |
|
|
988 | |
|
|
989 | delete [] rstr; |
|
|
990 | } |
|
|
991 | OUTPUT: |
|
|
992 | RETVAL |
957 | |
993 | |
958 | SV * |
994 | SV * |
959 | rxvt_term::special_decode (SV *str) |
995 | rxvt_term::special_decode (SV *text) |
960 | CODE: |
996 | CODE: |
961 | abort ();//TODO |
997 | { |
|
|
998 | wchar_t *wstr = sv2wcs (text); |
|
|
999 | int wlen = wcslen (wstr); |
|
|
1000 | int dlen = 0; |
|
|
1001 | |
|
|
1002 | // find length |
|
|
1003 | for (wchar_t *s = wstr; *s; s++) |
|
|
1004 | if (*s == NOCHAR) |
|
|
1005 | ; |
|
|
1006 | else if (IS_COMPOSE (*s)) |
|
|
1007 | dlen += rxvt_composite.expand (*s, 0); |
|
|
1008 | else |
|
|
1009 | dlen++; |
|
|
1010 | |
|
|
1011 | wchar_t *rstr = new wchar_t [dlen]; |
|
|
1012 | |
|
|
1013 | // decode |
|
|
1014 | wchar_t *r = rstr; |
|
|
1015 | for (wchar_t *s = wstr; *s; s++) |
|
|
1016 | if (*s == NOCHAR) |
|
|
1017 | ; |
|
|
1018 | else if (IS_COMPOSE (*s)) |
|
|
1019 | r += rxvt_composite.expand (*s, r); |
|
|
1020 | else |
|
|
1021 | *r++ = *s; |
|
|
1022 | |
|
|
1023 | RETVAL = wcs2sv (rstr, r - rstr); |
|
|
1024 | |
|
|
1025 | delete [] rstr; |
|
|
1026 | } |
|
|
1027 | OUTPUT: |
|
|
1028 | RETVAL |
962 | |
1029 | |
963 | void |
1030 | void |
964 | rxvt_term::_resource (char *name, int index, SV *newval = 0) |
1031 | rxvt_term::_resource (char *name, int index, SV *newval = 0) |
965 | PPCODE: |
1032 | PPCODE: |
966 | { |
1033 | { |
… | |
… | |
1054 | void |
1121 | void |
1055 | rxvt_term::scr_add_lines (SV *string) |
1122 | rxvt_term::scr_add_lines (SV *string) |
1056 | CODE: |
1123 | CODE: |
1057 | { |
1124 | { |
1058 | wchar_t *wstr = sv2wcs (string); |
1125 | wchar_t *wstr = sv2wcs (string); |
1059 | int wlen = wcslen (wstr); |
|
|
1060 | unicode_t *ustr = new unicode_t [wlen]; |
|
|
1061 | int nlines = 0; |
|
|
1062 | |
|
|
1063 | for (int i = wlen; i--; ) |
|
|
1064 | { |
|
|
1065 | ustr [i] = wstr [i]; |
|
|
1066 | nlines += ustr [i] == '\012'; |
|
|
1067 | } |
|
|
1068 | |
|
|
1069 | THIS->scr_add_lines (ustr, nlines, wlen); |
1126 | THIS->scr_add_lines (wstr, wcslen (wstr)); |
1070 | |
|
|
1071 | free (wstr); |
1127 | free (wstr); |
1072 | delete [] ustr; |
|
|
1073 | } |
1128 | } |
1074 | |
1129 | |
1075 | void |
1130 | void |
1076 | rxvt_term::tt_write (SV *octets) |
1131 | rxvt_term::tt_write (SV *octets) |
1077 | INIT: |
1132 | INIT: |