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.25 by root, Thu Jan 5 01:04:10 2006 UTC vs.
Revision 1.34 by root, Fri Jan 6 21:06:09 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 ()
620 709
621int 710int
622rxvt_term::strwidth (SV *str) 711rxvt_term::strwidth (SV *str)
623 CODE: 712 CODE:
624{ 713{
703 RETVAL = *(int *)((char *)THIS + ix); 792 RETVAL = *(int *)((char *)THIS + ix);
704 OUTPUT: 793 OUTPUT:
705 RETVAL 794 RETVAL
706 795
707U32 796U32
797rxvt_term::parent ()
798 CODE:
799 RETVAL = (U32)THIS->parent [0];
800 OUTPUT:
801 RETVAL
802
803U32
804rxvt_term::vt ()
805 CODE:
806 RETVAL = (U32)THIS->vt;
807 OUTPUT:
808 RETVAL
809
810U32
708rxvt_term::rstyle (U32 new_rstyle = THIS->rstyle) 811rxvt_term::rstyle (U32 new_rstyle = THIS->rstyle)
709 CODE: 812 CODE:
710{ 813{
711 RETVAL = THIS->rstyle; 814 RETVAL = THIS->rstyle;
712 THIS->rstyle = new_rstyle; 815 THIS->rstyle = new_rstyle;
733rxvt_term::want_refresh () 836rxvt_term::want_refresh ()
734 CODE: 837 CODE:
735 THIS->want_refresh = 1; 838 THIS->want_refresh = 1;
736 839
737void 840void
738rxvt_term::ROW_t (int row_number, SV *new_text = 0, int start_col = 0) 841rxvt_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: 842 PPCODE:
740{ 843{
741 if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) 844 if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow))
742 XSRETURN_EMPTY; 845 XSRETURN_EMPTY;
743 846
745 848
746 if (GIMME_V != G_VOID) 849 if (GIMME_V != G_VOID)
747 { 850 {
748 wchar_t *wstr = new wchar_t [THIS->ncol]; 851 wchar_t *wstr = new wchar_t [THIS->ncol];
749 852
750 for (int col = 0; col <THIS->ncol; col++) 853 for (int col = 0; col < THIS->ncol; col++)
751 wstr [col] = l.t [col]; 854 wstr [col] = l.t [col];
752 855
753 XPUSHs (sv_2mortal (wcs2sv (wstr))); 856 XPUSHs (sv_2mortal (wcs2sv (wstr, THIS->ncol)));
754 857
755 delete [] wstr; 858 delete [] wstr;
756 } 859 }
757 860
758 if (new_text) 861 if (new_text)
759 { 862 {
760 wchar_t *wstr = sv2wcs (new_text); 863 wchar_t *wstr = sv2wcs (new_text);
761 864
762 int len = wcslen (wstr); 865 int len = min (wcslen (wstr) - start_ofs, max_len);
763 866
764 if (!IN_RANGE_INC (start_col, 0, THIS->ncol - len)) 867 if (!IN_RANGE_INC (start_col, 0, THIS->ncol - len))
765 { 868 {
766 free (wstr); 869 free (wstr);
767 croak ("new_text extends beyond horizontal margins"); 870 croak ("new_text extends beyond horizontal margins");
768 } 871 }
769 872
770 for (int col = start_col; col < start_col + len; col++) 873 for (int col = start_col; col < start_col + len; col++)
771 { 874 {
772 l.t [col] = wstr [col - start_col]; 875 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])); 876 l.r [col] = SET_FONT (l.r [col], THIS->fontset [GET_STYLE (l.r [col])]->find_font (l.t [col]));
774 } 877 }
775 878
776 free (wstr); 879 free (wstr);
777 } 880 }
778} 881}
779 882
780void 883void
781rxvt_term::ROW_r (int row_number, SV *new_rend = 0, int start_col = 0) 884rxvt_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: 885 PPCODE:
783{ 886{
784 if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) 887 if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow))
785 XSRETURN_EMPTY; 888 XSRETURN_EMPTY;
786 889
801 { 904 {
802 if (!SvROK (new_rend) || SvTYPE (SvRV (new_rend)) != SVt_PVAV) 905 if (!SvROK (new_rend) || SvTYPE (SvRV (new_rend)) != SVt_PVAV)
803 croak ("new_rend must be arrayref"); 906 croak ("new_rend must be arrayref");
804 907
805 AV *av = (AV *)SvRV (new_rend); 908 AV *av = (AV *)SvRV (new_rend);
806 int len = av_len (av) + 1; 909 int len = min (av_len (av) + 1 - start_ofs, max_len);
807 910
808 if (!IN_RANGE_INC (start_col, 0, THIS->ncol - len)) 911 if (!IN_RANGE_INC (start_col, 0, THIS->ncol - len))
809 croak ("new_rend array extends beyond horizontal margins"); 912 croak ("new_rend array extends beyond horizontal margins");
810 913
811 for (int col = start_col; col < start_col + len; col++) 914 for (int col = start_col; col < start_col + len; col++)
812 { 915 {
813 rend_t r = SvIV (*av_fetch (av, col - start_col, 1)) & ~RS_fontMask; 916 rend_t r = SvIV (*av_fetch (av, start_ofs + col - start_col, 1)) & ~RS_fontMask;
814 917
815 l.r [col] = SET_FONT (r, THIS->fontset [GET_STYLE (r)]->find_font (l.t [col])); 918 l.r [col] = SET_FONT (r, THIS->fontset [GET_STYLE (r)]->find_font (l.t [col]));
816 } 919 }
817 } 920 }
818} 921}
819 922
820int 923int
821rxvt_term::ROW_l (int row_number, int new_length = -2) 924rxvt_term::ROW_l (int row_number, int new_length = -1)
822 CODE: 925 CODE:
823{ 926{
824 if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) 927 if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow))
825 XSRETURN_EMPTY; 928 XSRETURN_EMPTY;
826 929
827 line_t &l = ROW(row_number); 930 line_t &l = ROW(row_number);
828 RETVAL = l.l < 0 ? THIS->ncol : l.l; 931 RETVAL = l.l;
829 932
830 if (new_length >= -1) 933 if (new_length >= 0)
831 l.l = new_length; 934 l.l = new_length;
832} 935}
833 OUTPUT: 936 OUTPUT:
834 RETVAL 937 RETVAL
835 938
836bool 939bool
837rxvt_term::ROW_is_longer (int row_number) 940rxvt_term::ROW_is_longer (int row_number, int new_is_longer = -1)
838 CODE: 941 CODE:
839{ 942{
840 if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) 943 if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow))
841 XSRETURN_EMPTY; 944 XSRETURN_EMPTY;
842 945
843 line_t &l = ROW(row_number); 946 line_t &l = ROW(row_number);
844 RETVAL = l.l < 0; 947 RETVAL = l.is_longer ();
948
949 if (new_is_longer >= 0)
950 l.is_longer (new_is_longer);
845} 951}
846 OUTPUT: 952 OUTPUT:
847 RETVAL 953 RETVAL
848 954
849SV * 955SV *
850rxvt_term::special_encode (SV *str) 956rxvt_term::special_encode (SV *string)
851 CODE: 957 CODE:
852 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
853 993
854SV * 994SV *
855rxvt_term::special_decode (SV *str) 995rxvt_term::special_decode (SV *text)
856 CODE: 996 CODE:
857 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
858 1029
859void 1030void
860rxvt_term::_resource (char *name, int index, SV *newval = 0) 1031rxvt_term::_resource (char *name, int index, SV *newval = 0)
861 PPCODE: 1032 PPCODE:
862{ 1033{
950void 1121void
951rxvt_term::scr_add_lines (SV *string) 1122rxvt_term::scr_add_lines (SV *string)
952 CODE: 1123 CODE:
953{ 1124{
954 wchar_t *wstr = sv2wcs (string); 1125 wchar_t *wstr = sv2wcs (string);
955 int wlen = wcslen (wstr);
956 unicode_t *ustr = new unicode_t [wlen];
957 int nlines = 0;
958
959 for (int i = wlen; i--; )
960 {
961 ustr [i] = wstr [i];
962 nlines += ustr [i] == '\012';
963 }
964
965 THIS->scr_add_lines (ustr, nlines, wlen); 1126 THIS->scr_add_lines (wstr, wcslen (wstr));
966
967 free (wstr); 1127 free (wstr);
968 delete [] ustr;
969} 1128}
970 1129
971void 1130void
972rxvt_term::tt_write (SV *octets) 1131rxvt_term::tt_write (SV *octets)
973 INIT: 1132 INIT:
974 STRLEN len; 1133 STRLEN len;
975 char *str = SvPVbyte (octets, len); 1134 char *str = SvPVbyte (octets, len);
976 C_ARGS: 1135 C_ARGS:
977 str, len 1136 str, len
978 1137
1138void
1139rxvt_term::cmd_parse (SV *octets)
1140 CODE:
1141{
1142 STRLEN len;
1143 char *str = SvPVbyte (octets, len);
1144
1145 char *old_cmdbuf_ptr = THIS->cmdbuf_ptr;
1146 char *old_cmdbuf_endp = THIS->cmdbuf_endp;
1147
1148 THIS->cmdbuf_ptr = str;
1149 THIS->cmdbuf_endp = str + len;
1150
1151 THIS->cmd_parse ();
1152
1153 THIS->cmdbuf_ptr = old_cmdbuf_ptr;
1154 THIS->cmdbuf_endp = old_cmdbuf_endp;
1155}
1156
979SV * 1157SV *
980rxvt_term::overlay (int x, int y, int w, int h, int rstyle = OVERLAY_RSTYLE, int border = 2) 1158rxvt_term::overlay (int x, int y, int w, int h, int rstyle = OVERLAY_RSTYLE, int border = 2)
981 CODE: 1159 CODE:
982{ 1160{
983 overlay *o = new overlay (THIS, x, y, w, h, rstyle, border); 1161 overlay *o = new overlay (THIS, x, y, w, h, rstyle, border);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines