ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/rxvtperl.xs
(Generate patch)

Comparing rxvt-unicode/src/rxvtperl.xs (file contents):
Revision 1.26 by root, Thu Jan 5 21:21:49 2006 UTC vs.
Revision 1.35 by root, Sat Jan 7 04:19:43 2006 UTC

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 }
490 break;
484 491
485 delete [] wstr; 492 case DT_XEVENT:
486 } 493 {
494 XEvent *xe = va_arg (ap, XEvent *);
495 HV *hv = newHV ();
496
497# define set(name, sv) hv_store (hv, # name, sizeof (# name) - 1, sv, 0)
498# define setiv(name, val) hv_store (hv, # name, sizeof (# name) - 1, newSViv (val), 0)
499# undef set
500
501 setiv (type, xe->type);
502 setiv (send_event, xe->xany.send_event);
503 setiv (serial, xe->xany.serial);
504
505 switch (xe->type)
506 {
507 case KeyPress:
508 case KeyRelease:
509 case ButtonPress:
510 case ButtonRelease:
511 case MotionNotify:
512 setiv (time, xe->xmotion.time);
513 setiv (x, xe->xmotion.x);
514 setiv (y, xe->xmotion.y);
515 setiv (row, xe->xmotion.y / term->fheight);
516 setiv (col, xe->xmotion.x / term->fwidth);
517 setiv (x_root, xe->xmotion.x_root);
518 setiv (y_root, xe->xmotion.y_root);
519 setiv (state, xe->xmotion.state);
520 break;
521 }
522
523 switch (xe->type)
524 {
525 case KeyPress:
526 case KeyRelease:
527 setiv (keycode, xe->xkey.keycode);
528 break;
529
530 case ButtonPress:
531 case ButtonRelease:
532 setiv (button, xe->xbutton.button);
533 break;
534
535 case MotionNotify:
536 setiv (is_hint, xe->xmotion.is_hint);
537 break;
538 }
539
540 XPUSHs (sv_2mortal (newRV_noinc ((SV *)hv)));
541 }
542 break;
487 543
488 case DT_END: 544 case DT_END:
489 { 545 {
490 va_end (ap); 546 va_end (ap);
491 547
544 export_const (RS_Uline); 600 export_const (RS_Uline);
545 601
546 sv_setpv (get_sv ("urxvt::LIBDIR", 1), LIBDIR); 602 sv_setpv (get_sv ("urxvt::LIBDIR", 1), LIBDIR);
547} 603}
548 604
605SV *
606new (...)
607 CODE:
608{
609 stringvec *argv = new stringvec;
610 bool success;
611
612 for (int i = 0; i < items ;i++)
613 argv->push_back (strdup (SvPVbyte_nolen (ST (i))));
614
615 rxvt_term *term = new rxvt_term;
616
617 term->argv = argv;
618
619 try
620 {
621 if (!term->init (argv->size (), argv->begin ()))
622 term = 0;
623 }
624 catch (const class rxvt_failure_exception &e)
625 {
626 term->destroy ();
627 croak ("exception caught while initializing new terminal instance");
628 }
629
630 RETVAL = term && term->self ? newSVterm (term) : &PL_sv_undef;
631}
632 OUTPUT:
633 RETVAL
634
549void 635void
550set_should_invoke (int htype, int value) 636set_should_invoke (int htype, int value)
551 CODE: 637 CODE:
552 rxvt_perl.should_invoke [htype] = value; 638 rxvt_perl.should_invoke [htype] = value;
553 639
615} 701}
616 OUTPUT: 702 OUTPUT:
617 RETVAL 703 RETVAL
618 704
619MODULE = urxvt PACKAGE = urxvt::term 705MODULE = urxvt PACKAGE = urxvt::term
706
707void
708rxvt_term::destroy ()
709
710void
711rxvt_term::grab (int eventtime)
712 CODE:
713{
714return;
715 XGrabPointer (THIS->display->display, THIS->vt, 0,
716 ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask,
717 GrabModeAsync, GrabModeAsync, None, None, eventtime);
718 XGrabKeyboard (THIS->display->display, THIS->vt, 0, GrabModeAsync, GrabModeAsync, eventtime);
719}
620 720
621int 721int
622rxvt_term::strwidth (SV *str) 722rxvt_term::strwidth (SV *str)
623 CODE: 723 CODE:
624{ 724{
703 RETVAL = *(int *)((char *)THIS + ix); 803 RETVAL = *(int *)((char *)THIS + ix);
704 OUTPUT: 804 OUTPUT:
705 RETVAL 805 RETVAL
706 806
707U32 807U32
808rxvt_term::parent ()
809 CODE:
810 RETVAL = (U32)THIS->parent [0];
811 OUTPUT:
812 RETVAL
813
814U32
815rxvt_term::vt ()
816 CODE:
817 RETVAL = (U32)THIS->vt;
818 OUTPUT:
819 RETVAL
820
821U32
708rxvt_term::rstyle (U32 new_rstyle = THIS->rstyle) 822rxvt_term::rstyle (U32 new_rstyle = THIS->rstyle)
709 CODE: 823 CODE:
710{ 824{
711 RETVAL = THIS->rstyle; 825 RETVAL = THIS->rstyle;
712 THIS->rstyle = new_rstyle; 826 THIS->rstyle = new_rstyle;
733rxvt_term::want_refresh () 847rxvt_term::want_refresh ()
734 CODE: 848 CODE:
735 THIS->want_refresh = 1; 849 THIS->want_refresh = 1;
736 850
737void 851void
738rxvt_term::ROW_t (int row_number, SV *new_text = 0, int start_col = 0) 852rxvt_term::ROW_t (int row_number, SV *new_text = 0, int start_col = 0, int start_ofs = 0, int max_len = MAX_COLS)
739 PPCODE: 853 PPCODE:
740{ 854{
741 if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) 855 if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow))
742 XSRETURN_EMPTY; 856 XSRETURN_EMPTY;
743 857
745 859
746 if (GIMME_V != G_VOID) 860 if (GIMME_V != G_VOID)
747 { 861 {
748 wchar_t *wstr = new wchar_t [THIS->ncol]; 862 wchar_t *wstr = new wchar_t [THIS->ncol];
749 863
750 for (int col = 0; col <THIS->ncol; col++) 864 for (int col = 0; col < THIS->ncol; col++)
751 wstr [col] = l.t [col]; 865 wstr [col] = l.t [col];
752 866
753 XPUSHs (sv_2mortal (wcs2sv (wstr))); 867 XPUSHs (sv_2mortal (wcs2sv (wstr, THIS->ncol)));
754 868
755 delete [] wstr; 869 delete [] wstr;
756 } 870 }
757 871
758 if (new_text) 872 if (new_text)
759 { 873 {
760 wchar_t *wstr = sv2wcs (new_text); 874 wchar_t *wstr = sv2wcs (new_text);
761 875
762 int len = wcslen (wstr); 876 int len = min (wcslen (wstr) - start_ofs, max_len);
763 877
764 if (!IN_RANGE_INC (start_col, 0, THIS->ncol - len)) 878 if (!IN_RANGE_INC (start_col, 0, THIS->ncol - len))
765 { 879 {
766 free (wstr); 880 free (wstr);
767 croak ("new_text extends beyond horizontal margins"); 881 croak ("new_text extends beyond horizontal margins");
768 } 882 }
769 883
770 for (int col = start_col; col < start_col + len; col++) 884 for (int col = start_col; col < start_col + len; col++)
771 { 885 {
772 l.t [col] = wstr [col - start_col]; 886 l.t [col] = wstr [start_ofs + col - start_col];
773 l.r [col] = SET_FONT (l.r [col], THIS->fontset [GET_STYLE (l.r [col])]->find_font (l.t [col])); 887 l.r [col] = SET_FONT (l.r [col], THIS->fontset [GET_STYLE (l.r [col])]->find_font (l.t [col]));
774 } 888 }
775 889
776 free (wstr); 890 free (wstr);
777 } 891 }
778} 892}
779 893
780void 894void
781rxvt_term::ROW_r (int row_number, SV *new_rend = 0, int start_col = 0) 895rxvt_term::ROW_r (int row_number, SV *new_rend = 0, int start_col = 0, int start_ofs = 0, int max_len = MAX_COLS)
782 PPCODE: 896 PPCODE:
783{ 897{
784 if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) 898 if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow))
785 XSRETURN_EMPTY; 899 XSRETURN_EMPTY;
786 900
801 { 915 {
802 if (!SvROK (new_rend) || SvTYPE (SvRV (new_rend)) != SVt_PVAV) 916 if (!SvROK (new_rend) || SvTYPE (SvRV (new_rend)) != SVt_PVAV)
803 croak ("new_rend must be arrayref"); 917 croak ("new_rend must be arrayref");
804 918
805 AV *av = (AV *)SvRV (new_rend); 919 AV *av = (AV *)SvRV (new_rend);
806 int len = av_len (av) + 1; 920 int len = min (av_len (av) + 1 - start_ofs, max_len);
807 921
808 if (!IN_RANGE_INC (start_col, 0, THIS->ncol - len)) 922 if (!IN_RANGE_INC (start_col, 0, THIS->ncol - len))
809 croak ("new_rend array extends beyond horizontal margins"); 923 croak ("new_rend array extends beyond horizontal margins");
810 924
811 for (int col = start_col; col < start_col + len; col++) 925 for (int col = start_col; col < start_col + len; col++)
812 { 926 {
813 rend_t r = SvIV (*av_fetch (av, col - start_col, 1)) & ~RS_fontMask; 927 rend_t r = SvIV (*av_fetch (av, start_ofs + col - start_col, 1)) & ~RS_fontMask;
814 928
815 l.r [col] = SET_FONT (r, THIS->fontset [GET_STYLE (r)]->find_font (l.t [col])); 929 l.r [col] = SET_FONT (r, THIS->fontset [GET_STYLE (r)]->find_font (l.t [col]));
816 } 930 }
817 } 931 }
818} 932}
848} 962}
849 OUTPUT: 963 OUTPUT:
850 RETVAL 964 RETVAL
851 965
852SV * 966SV *
853rxvt_term::special_encode (SV *str) 967rxvt_term::special_encode (SV *string)
854 CODE: 968 CODE:
855 abort ();//TODO 969{
970 wchar_t *wstr = sv2wcs (string);
971 int wlen = wcslen (wstr);
972 wchar_t *rstr = new wchar_t [wlen]; // cannot become longer
973
974 rxvt_push_locale (THIS->locale);
975
976 wchar_t *r = rstr;
977 for (wchar_t *s = wstr; *s; s++)
978 if (wcwidth (*s) == 0)
979 {
980 if (r == rstr)
981 croak ("leading combining character unencodable");
982
983 unicode_t n = rxvt_compose (r[-1], *s);
984 if (n == NOCHAR)
985 n = rxvt_composite.compose (r[-1], *s);
986
987 r[-1] = n;
988 }
989#if !UNICODE_3
990 else if (*s >= 0x10000)
991 *r++ = rxvt_composite.compose (*s);
992#endif
993 else
994 *r++ = *s;
995
996 rxvt_pop_locale ();
997
998 RETVAL = wcs2sv (rstr, r - rstr);
999
1000 delete [] rstr;
1001}
1002 OUTPUT:
1003 RETVAL
856 1004
857SV * 1005SV *
858rxvt_term::special_decode (SV *str) 1006rxvt_term::special_decode (SV *text)
859 CODE: 1007 CODE:
860 abort ();//TODO 1008{
1009 wchar_t *wstr = sv2wcs (text);
1010 int wlen = wcslen (wstr);
1011 int dlen = 0;
1012
1013 // find length
1014 for (wchar_t *s = wstr; *s; s++)
1015 if (*s == NOCHAR)
1016 ;
1017 else if (IS_COMPOSE (*s))
1018 dlen += rxvt_composite.expand (*s, 0);
1019 else
1020 dlen++;
1021
1022 wchar_t *rstr = new wchar_t [dlen];
1023
1024 // decode
1025 wchar_t *r = rstr;
1026 for (wchar_t *s = wstr; *s; s++)
1027 if (*s == NOCHAR)
1028 ;
1029 else if (IS_COMPOSE (*s))
1030 r += rxvt_composite.expand (*s, r);
1031 else
1032 *r++ = *s;
1033
1034 RETVAL = wcs2sv (rstr, r - rstr);
1035
1036 delete [] rstr;
1037}
1038 OUTPUT:
1039 RETVAL
861 1040
862void 1041void
863rxvt_term::_resource (char *name, int index, SV *newval = 0) 1042rxvt_term::_resource (char *name, int index, SV *newval = 0)
864 PPCODE: 1043 PPCODE:
865{ 1044{
953void 1132void
954rxvt_term::scr_add_lines (SV *string) 1133rxvt_term::scr_add_lines (SV *string)
955 CODE: 1134 CODE:
956{ 1135{
957 wchar_t *wstr = sv2wcs (string); 1136 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); 1137 THIS->scr_add_lines (wstr, wcslen (wstr));
969
970 free (wstr); 1138 free (wstr);
971 delete [] ustr;
972} 1139}
973 1140
974void 1141void
975rxvt_term::tt_write (SV *octets) 1142rxvt_term::tt_write (SV *octets)
976 INIT: 1143 INIT:
977 STRLEN len; 1144 STRLEN len;
978 char *str = SvPVbyte (octets, len); 1145 char *str = SvPVbyte (octets, len);
979 C_ARGS: 1146 C_ARGS:
980 str, len 1147 str, len
981 1148
1149void
1150rxvt_term::cmd_parse (SV *octets)
1151 CODE:
1152{
1153 STRLEN len;
1154 char *str = SvPVbyte (octets, len);
1155
1156 char *old_cmdbuf_ptr = THIS->cmdbuf_ptr;
1157 char *old_cmdbuf_endp = THIS->cmdbuf_endp;
1158
1159 THIS->cmdbuf_ptr = str;
1160 THIS->cmdbuf_endp = str + len;
1161
1162 rxvt_push_locale (THIS->locale);
1163 THIS->cmd_parse ();
1164 rxvt_pop_locale ();
1165
1166 THIS->cmdbuf_ptr = old_cmdbuf_ptr;
1167 THIS->cmdbuf_endp = old_cmdbuf_endp;
1168}
1169
982SV * 1170SV *
983rxvt_term::overlay (int x, int y, int w, int h, int rstyle = OVERLAY_RSTYLE, int border = 2) 1171rxvt_term::overlay (int x, int y, int w, int h, int rstyle = OVERLAY_RSTYLE, int border = 2)
984 CODE: 1172 CODE:
985{ 1173{
986 overlay *o = new overlay (THIS, x, y, w, h, rstyle, border); 1174 overlay *o = new overlay (THIS, x, y, w, h, rstyle, border);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines