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.27 by root, Fri Jan 6 01:16:58 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;
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)
848} 951}
849 OUTPUT: 952 OUTPUT:
850 RETVAL 953 RETVAL
851 954
852SV * 955SV *
853rxvt_term::special_encode (SV *str) 956rxvt_term::special_encode (SV *string)
854 CODE: 957 CODE:
855 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
856 993
857SV * 994SV *
858rxvt_term::special_decode (SV *str) 995rxvt_term::special_decode (SV *text)
859 CODE: 996 CODE:
860 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
861 1029
862void 1030void
863rxvt_term::_resource (char *name, int index, SV *newval = 0) 1031rxvt_term::_resource (char *name, int index, SV *newval = 0)
864 PPCODE: 1032 PPCODE:
865{ 1033{
953void 1121void
954rxvt_term::scr_add_lines (SV *string) 1122rxvt_term::scr_add_lines (SV *string)
955 CODE: 1123 CODE:
956{ 1124{
957 wchar_t *wstr = sv2wcs (string); 1125 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); 1126 THIS->scr_add_lines (wstr, wcslen (wstr));
969
970 free (wstr); 1127 free (wstr);
971 delete [] ustr;
972} 1128}
973 1129
974void 1130void
975rxvt_term::tt_write (SV *octets) 1131rxvt_term::tt_write (SV *octets)
976 INIT: 1132 INIT:
977 STRLEN len; 1133 STRLEN len;
978 char *str = SvPVbyte (octets, len); 1134 char *str = SvPVbyte (octets, len);
979 C_ARGS: 1135 C_ARGS:
980 str, len 1136 str, len
981 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
982SV * 1157SV *
983rxvt_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)
984 CODE: 1159 CODE:
985{ 1160{
986 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