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.23 by root, Wed Jan 4 04:42:45 2006 UTC vs.
Revision 1.51 by root, Mon Jan 9 23:00:07 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.
26#include <XSUB.h> 26#include <XSUB.h>
27#undef line_t 27#undef line_t
28 28
29#include "../config.h" 29#include "../config.h"
30 30
31#include <cstddef>
31#include <cstdarg> 32#include <cstdarg>
32 33
34#include "iom.h"
33#include "rxvt.h" 35#include "rxvt.h"
34#include "iom.h" 36#include "keyboard.h"
35#include "rxvtutil.h" 37#include "rxvtutil.h"
36#include "rxvtperl.h" 38#include "rxvtperl.h"
37 39
38#include "perlxsi.c" 40#include "perlxsi.c"
41
42#if defined(HAVE_SCROLLBARS) || defined(MENUBAR)
43# define GRAB_CURSOR THIS->leftptr_cursor
44#else
45# define GRAB_CURSOR None
46#endif
39 47
40#undef LINENO 48#undef LINENO
41#define LINENO(n) MOD (THIS->term_start + int(n), THIS->total_rows) 49#define LINENO(n) MOD (THIS->term_start + int(n), THIS->total_rows)
42#undef ROW 50#undef ROW
43#define ROW(n) THIS->row_buf [LINENO (n)] 51#define ROW(n) THIS->row_buf [LINENO (n)]
44 52
45///////////////////////////////////////////////////////////////////////////// 53/////////////////////////////////////////////////////////////////////////////
46 54
55static SV *
56taint (SV *sv)
57{
58 SvTAINT (sv);
59 return sv;
60}
61
62static SV *
63taint_if (SV *sv, SV *src)
64{
65 if (SvTAINTED (src))
66 SvTAINT (sv);
67
68 return sv;
69}
70
47static wchar_t * 71static wchar_t *
48sv2wcs (SV *sv) 72sv2wcs (SV *sv)
49{ 73{
50 STRLEN len; 74 STRLEN len;
51 char *str = SvPVutf8 (sv, len); 75 char *str = SvPVutf8 (sv, len);
52 return rxvt_utf8towcs (str, len); 76 return rxvt_utf8towcs (str, len);
53} 77}
54 78
55static SV * 79static SV *
80wcs2sv (wchar_t *wstr, int len = -1)
81{
82 char *str = rxvt_wcstoutf8 (wstr, len);
83
84 SV *sv = newSVpv (str, 0);
85 SvUTF8_on (sv);
86 free (str);
87
88 return sv;
89}
90
91static SV *
56new_ref (HV *hv, const char *klass) 92new_ref (HV *hv, const char *klass)
57{ 93{
58 return sv_bless (newRV ((SV *)hv), gv_stashpv (klass, 1)); 94 return sv_bless (newRV ((SV *)hv), gv_stashpv (klass, 1));
59} 95}
60 96
89 croak ("perl code used %s object, but C++ object is already destroyed, caught", klass); 125 croak ("perl code used %s object, but C++ object is already destroyed, caught", klass);
90 126
91 return (long)mg->mg_ptr; 127 return (long)mg->mg_ptr;
92} 128}
93 129
94#define newSVterm(term) SvREFCNT_inc ((SV *)term->self) 130#define newSVterm(term) SvREFCNT_inc ((SV *)term->perl.self)
95#define SvTERM(sv) (rxvt_term *)SvPTR (sv, "urxvt::term") 131#define SvTERM(sv) (rxvt_term *)SvPTR (sv, "urxvt::term")
96 132
97///////////////////////////////////////////////////////////////////////////// 133/////////////////////////////////////////////////////////////////////////////
98 134
99struct perl_watcher 135struct perl_watcher
215 h += 2; 251 h += 2;
216 } 252 }
217 253
218 text = new text_t *[h]; 254 text = new text_t *[h];
219 rend = new rend_t *[h]; 255 rend = new rend_t *[h];
220 256
221 for (int y = 0; y < h; y++) 257 for (int y = 0; y < h; y++)
222 { 258 {
223 text_t *tp = text[y] = new text_t[w]; 259 text_t *tp = text[y] = new text_t[w];
224 rend_t *rp = rend[y] = new rend_t[w]; 260 rend_t *rp = rend[y] = new rend_t[w];
225 261
226 text_t t0, t1, t2; 262 text_t t0, t1, t2;
227 rend_t r = rstyle; 263 rend_t r = rstyle;
228 264
229 if (border == 2) 265 if (border == 2)
230 { 266 {
231 if (y == 0) 267 if (y == 0)
232 t0 = 0x2554, t1 = 0x2550, t2 = 0x2557; 268 t0 = 0x2554, t1 = 0x2550, t2 = 0x2557;
233 else if (y < h - 1) 269 else if (y < h - 1)
234 t0 = 0x2551, t1 = 0x0020, t2 = 0x2551; 270 t0 = 0x2551, t1 = 0x0020, t2 = 0x2551;
235 else 271 else
236 t0 = 0x255a, t1 = 0x2550, t2 = 0x255d; 272 t0 = 0x255a, t1 = 0x2550, t2 = 0x255d;
237 273
238 *tp++ = t0; 274 *tp++ = t0;
239 *rp++ = r; 275 *rp++ = r;
240 276
241 for (int x = w - 2; x-- > 0; ) 277 for (int x = w - 2; x-- > 0; )
242 { 278 {
243 *tp++ = t1; 279 *tp++ = t1;
244 *rp++ = r; 280 *rp++ = r;
245 } 281 }
246 282
247 *tp = t2; 283 *tp = t2;
248 *rp = r; 284 *rp = r;
249 } 285 }
250 else 286 else
251 for (int x = w; x-- > 0; ) 287 for (int x = w; x-- > 0; )
252 { 288 {
253 *tp++ = 0x0020; 289 *tp++ = 0x0020;
254 *rp++ = r; 290 *rp++ = r;
255 } 291 }
256 } 292 }
257 293
258 show (); 294 show ();
259 THIS->want_refresh = 1; 295 THIS->want_refresh = 1;
260} 296}
261 297
278void 314void
279overlay::show () 315overlay::show ()
280{ 316{
281 char key[33]; sprintf (key, "%32lx", (long)this); 317 char key[33]; sprintf (key, "%32lx", (long)this);
282 318
283 HV *hv = (HV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)THIS->self), "_overlay", 8, 0)); 319 HV *hv = (HV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)THIS->perl.self), "_overlay", 8, 0));
284 hv_store (hv, key, 32, newSViv ((long)this), 0); 320 hv_store (hv, key, 32, newSViv ((long)this), 0);
285} 321}
286 322
287void 323void
288overlay::hide () 324overlay::hide ()
289{ 325{
290 SV **ovs = hv_fetch ((HV *)SvRV ((SV *)THIS->self), "_overlay", 8, 0); 326 SV **ovs = hv_fetch ((HV *)SvRV ((SV *)THIS->perl.self), "_overlay", 8, 0);
291 327
292 if (ovs) 328 if (ovs)
293 { 329 {
294 char key[33]; sprintf (key, "%32lx", (long)this); 330 char key[33]; sprintf (key, "%32lx", (long)this);
295 331
308 344
309 for (int y = ov_h; y--; ) 345 for (int y = ov_h; y--; )
310 { 346 {
311 text_t *t1 = text [y]; 347 text_t *t1 = text [y];
312 rend_t *r1 = rend [y]; 348 rend_t *r1 = rend [y];
313 349
314 text_t *t2 = ROW(y + ov_y - THIS->view_start).t + ov_x; 350 text_t *t2 = ROW(y + ov_y - THIS->view_start).t + ov_x;
315 rend_t *r2 = ROW(y + ov_y - THIS->view_start).r + ov_x; 351 rend_t *r2 = ROW(y + ov_y - THIS->view_start).r + ov_x;
316 352
317 for (int x = ov_w; x--; ) 353 for (int x = ov_w; x--; )
318 { 354 {
319 text_t t = *t1; *t1++ = *t2; *t2++ = t; 355 text_t t = *t1; *t1++ = *t2; *t2++ = t;
320 rend_t r = *r1; *r1++ = *r2; *r2++ = SET_FONT (r, THIS->fontset [GET_STYLE (r)]->find_font (t)); 356 rend_t r = *r1; *r1++ = *r2; *r2++ = SET_FONT (r, THIS->fontset [GET_STYLE (r)]->find_font (t));
321 } 357 }
322 } 358 }
323 359
333 369
334 wchar_t *wtext = sv2wcs (text); 370 wchar_t *wtext = sv2wcs (text);
335 371
336 for (int col = min (wcslen (wtext), w - x - border); col--; ) 372 for (int col = min (wcslen (wtext), w - x - border); col--; )
337 this->text [y][x + col] = wtext [col]; 373 this->text [y][x + col] = wtext [col];
338 374
339 free (wtext); 375 free (wtext);
340 376
341 if (rend) 377 if (rend)
342 { 378 {
343 if (!SvROK (rend) || SvTYPE (SvRV (rend)) != SVt_PVAV) 379 if (!SvROK (rend) || SvTYPE (SvRV (rend)) != SVt_PVAV)
377{ 413{
378 if (!perl) 414 if (!perl)
379 { 415 {
380 char *argv[] = { 416 char *argv[] = {
381 "", 417 "",
418 "-T",
382 "-edo '" LIBDIR "/urxvt.pm' or ($@ and die $@) or exit 1", 419 "-edo '" LIBDIR "/urxvt.pm' or ($@ and die $@) or exit 1",
383 }; 420 };
384 421
385 perl = perl_alloc (); 422 perl = perl_alloc ();
386 perl_construct (perl); 423 perl_construct (perl);
387 424
388 if (perl_parse (perl, xs_init, 2, argv, (char **)NULL) 425 if (perl_parse (perl, xs_init, 3, argv, (char **)NULL)
389 || perl_run (perl)) 426 || perl_run (perl))
390 { 427 {
391 rxvt_warn ("unable to initialize perl-interpreter, continuing without.\n"); 428 rxvt_warn ("unable to initialize perl-interpreter, continuing without.\n");
392 429
393 perl_destruct (perl); 430 perl_destruct (perl);
395 perl = 0; 432 perl = 0;
396 } 433 }
397 } 434 }
398} 435}
399 436
437static void
438ungrab (rxvt_term *THIS)
439{
440 if (THIS->perl.grabtime)
441 {
442 XUngrabKeyboard (THIS->display->display, THIS->perl.grabtime);
443 XUngrabPointer (THIS->display->display, THIS->perl.grabtime);
444 THIS->perl.grabtime = 0;
445 }
446}
447
400bool 448bool
401rxvt_perl_interp::invoke (rxvt_term *term, hook_type htype, ...) 449rxvt_perl_interp::invoke (rxvt_term *term, hook_type htype, ...)
402{ 450{
403 if (!perl) 451 if (!perl)
404 return false; 452 return false;
405 453
406 if (htype == HOOK_INIT) // first hook ever called 454 if (htype == HOOK_INIT) // first hook ever called
407 { 455 {
408 term->self = (void *)newSVptr ((void *)term, "urxvt::term"); 456 term->perl.self = (void *)newSVptr ((void *)term, "urxvt::term");
409 hv_store ((HV *)SvRV ((SV *)term->self), "_overlay", 8, newRV_noinc ((SV *)newHV ()), 0); 457 hv_store ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, newRV_noinc ((SV *)newHV ()), 0);
410 } 458 }
411 else if (!term->self) 459 else if (!term->perl.self)
412 return false; // perl not initialized for this instance 460 return false; // perl not initialized for this instance
413 else if (htype == HOOK_DESTROY) 461 else if (htype == HOOK_DESTROY)
414 { 462 {
415 // handled later 463 // handled later
416 } 464 }
417 else if (htype == HOOK_REFRESH_BEGIN || htype == HOOK_REFRESH_END) 465 else
418 { 466 {
419 HV *hv = (HV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->self), "_overlay", 8, 0)); 467 if (htype == HOOK_REFRESH_BEGIN || htype == HOOK_REFRESH_END)
420
421 if (HvKEYS (hv))
422 { 468 {
469 HV *hv = (HV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, 0));
470
471 if (HvKEYS (hv))
472 {
423 hv_iterinit (hv); 473 hv_iterinit (hv);
424 474
425 while (HE *he = hv_iternext (hv)) 475 while (HE *he = hv_iternext (hv))
426 ((overlay *)SvIV (hv_iterval (hv, he)))->swap (); 476 ((overlay *)SvIV (hv_iterval (hv, he)))->swap ();
477 }
478
427 } 479 }
480
481 if (!should_invoke [htype])
482 return false;
428 } 483 }
429 else if (!should_invoke [htype])
430 return false;
431 484
432 dSP; 485 dSP;
433 va_list ap; 486 va_list ap;
434 487
435 va_start (ap, htype); 488 va_start (ap, htype);
453 506
454 case DT_LONG: 507 case DT_LONG:
455 XPUSHs (sv_2mortal (newSViv (va_arg (ap, long)))); 508 XPUSHs (sv_2mortal (newSViv (va_arg (ap, long))));
456 break; 509 break;
457 510
458 case DT_STRING: 511 case DT_STR:
459 XPUSHs (sv_2mortal (newSVpv (va_arg (ap, char *), 0))); 512 XPUSHs (taint (sv_2mortal (newSVpv (va_arg (ap, char *), 0))));
513 break;
514
515 case DT_STR_LEN:
516 {
517 char *str = va_arg (ap, char *);
518 int len = va_arg (ap, int);
519
520 XPUSHs (taint (sv_2mortal (newSVpvn (str, len))));
521 }
522 break;
523
524 case DT_WCS_LEN:
525 {
526 wchar_t *wstr = va_arg (ap, wchar_t *);
527 int wlen = va_arg (ap, int);
528
529 XPUSHs (taint (sv_2mortal (wcs2sv (wstr, wlen))));
530 }
531 break;
532
533 case DT_XEVENT:
534 {
535 XEvent *xe = va_arg (ap, XEvent *);
536 HV *hv = newHV ();
537
538# define set(name, sv) hv_store (hv, # name, sizeof (# name) - 1, sv, 0)
539# define setiv(name, val) hv_store (hv, # name, sizeof (# name) - 1, newSViv (val), 0)
540# undef set
541
542 setiv (type, xe->type);
543 setiv (send_event, xe->xany.send_event);
544 setiv (serial, xe->xany.serial);
545
546 switch (xe->type)
547 {
548 case KeyPress:
549 case KeyRelease:
550 case ButtonPress:
551 case ButtonRelease:
552 case MotionNotify:
553 setiv (time, xe->xmotion.time);
554 setiv (x, xe->xmotion.x);
555 setiv (y, xe->xmotion.y);
556 setiv (row, xe->xmotion.y / term->fheight);
557 setiv (col, xe->xmotion.x / term->fwidth);
558 setiv (x_root, xe->xmotion.x_root);
559 setiv (y_root, xe->xmotion.y_root);
560 setiv (state, xe->xmotion.state);
561 break;
562 }
563
564 switch (xe->type)
565 {
566 case KeyPress:
567 case KeyRelease:
568 setiv (keycode, xe->xkey.keycode);
569 break;
570
571 case ButtonPress:
572 case ButtonRelease:
573 setiv (button, xe->xbutton.button);
574 break;
575
576 case MotionNotify:
577 setiv (is_hint, xe->xmotion.is_hint);
578 break;
579 }
580
581 XPUSHs (sv_2mortal (newRV_noinc ((SV *)hv)));
582 }
460 break; 583 break;
461 584
462 case DT_END: 585 case DT_END:
463 { 586 {
464 va_end (ap); 587 va_end (ap);
476 PUTBACK; 599 PUTBACK;
477 FREETMPS; 600 FREETMPS;
478 LEAVE; 601 LEAVE;
479 602
480 if (SvTRUE (ERRSV)) 603 if (SvTRUE (ERRSV))
604 {
481 rxvt_warn ("perl hook %d evaluation error: %s", htype, SvPV_nolen (ERRSV)); 605 rxvt_warn ("perl hook %d evaluation error: %s", htype, SvPV_nolen (ERRSV));
606 ungrab (term); // better lose the grab than the session
607 }
482 608
483 if (htype == HOOK_DESTROY) 609 if (htype == HOOK_DESTROY)
484 { 610 {
485 clearSVptr ((SV *)term->self); 611 clearSVptr ((SV *)term->perl.self);
486 SvREFCNT_dec ((SV *)term->self); 612 SvREFCNT_dec ((SV *)term->perl.self);
487 } 613 }
488 614
489 return count; 615 return count;
490 } 616 }
491 617
501 627
502PROTOTYPES: ENABLE 628PROTOTYPES: ENABLE
503 629
504BOOT: 630BOOT:
505{ 631{
506# define export_const(name) newCONSTSUB (gv_stashpv ("urxvt", 1), # name, newSViv (name)); 632 sv_setsv (get_sv ("urxvt::LIBDIR", 1), newSVpvn (LIBDIR, sizeof (LIBDIR) - 1));
633
507 AV *hookname = get_av ("urxvt::HOOKNAME", 1); 634 AV *hookname = get_av ("urxvt::HOOKNAME", 1);
508# define def(sym) av_store (hookname, HOOK_ ## sym, newSVpv (# sym, 0)); 635# define def(sym) av_store (hookname, HOOK_ ## sym, newSVpv (# sym, 0));
509# include "hookinc.h" 636# include "hookinc.h"
510# undef def 637# undef def
511 638
639 HV *option = get_hv ("urxvt::OPTION", 1);
640# define def(name,val) hv_store (option, # name, sizeof (# name) - 1, newSVuv (Opt_ ## name), 0);
641# define nodef(name)
642# include "optinc.h"
643# undef nodef
644# undef def
645
646 HV *stash = gv_stashpv ("urxvt", 1);
647# define export_const_iv(name) newCONSTSUB (stash, # name, newSViv (name));
512 export_const (DEFAULT_RSTYLE); 648 export_const_iv (DEFAULT_RSTYLE);
513 export_const (OVERLAY_RSTYLE); 649 export_const_iv (OVERLAY_RSTYLE);
514 export_const (RS_Bold); 650 export_const_iv (RS_Bold);
515 export_const (RS_Italic); 651 export_const_iv (RS_Italic);
516 export_const (RS_Blink); 652 export_const_iv (RS_Blink);
517 export_const (RS_RVid); 653 export_const_iv (RS_RVid);
518 export_const (RS_Uline); 654 export_const_iv (RS_Uline);
519 655
520 sv_setpv (get_sv ("urxvt::LIBDIR", 1), LIBDIR); 656 export_const_iv (CurrentTime);
657 export_const_iv (ShiftMask);
658 export_const_iv (LockMask);
659 export_const_iv (ControlMask);
660 export_const_iv (Mod1Mask);
661 export_const_iv (Mod2Mask);
662 export_const_iv (Mod3Mask);
663 export_const_iv (Mod4Mask);
664 export_const_iv (Mod5Mask);
665 export_const_iv (Button1Mask);
666 export_const_iv (Button2Mask);
667 export_const_iv (Button3Mask);
668 export_const_iv (Button4Mask);
669 export_const_iv (Button5Mask);
670 export_const_iv (AnyModifier);
671
672 export_const_iv (EVENT_NONE);
673 export_const_iv (EVENT_READ);
674 export_const_iv (EVENT_WRITE);
521} 675}
676
677SV *
678new (...)
679 CODE:
680{
681 stringvec *argv = new stringvec;
682 bool success;
683
684 for (int i = 0; i < items ;i++)
685 argv->push_back (strdup (SvPVbyte_nolen (ST (i))));
686
687 rxvt_term *term = new rxvt_term;
688
689 term->argv = argv;
690
691 try
692 {
693 if (!term->init (argv->size (), argv->begin ()))
694 term = 0;
695 }
696 catch (const class rxvt_failure_exception &e)
697 {
698 term->destroy ();
699 croak ("exception caught while initializing new terminal instance");
700 }
701
702 RETVAL = term && term->perl.self ? newSVterm (term) : &PL_sv_undef;
703}
704 OUTPUT:
705 RETVAL
522 706
523void 707void
524set_should_invoke (int htype, int value) 708set_should_invoke (int htype, int value)
525 CODE: 709 CODE:
526 rxvt_perl.should_invoke [htype] = value; 710 rxvt_perl.should_invoke [htype] = value;
532 716
533void 717void
534fatal (const char *msg) 718fatal (const char *msg)
535 CODE: 719 CODE:
536 rxvt_fatal ("%s", msg); 720 rxvt_fatal ("%s", msg);
721
722SV *
723untaint (SV *sv)
724 CODE:
725 RETVAL = newSVsv (sv);
726 SvTAINTED_off (RETVAL);
727 OUTPUT:
728 RETVAL
729
730bool
731safe ()
732 CODE:
733 RETVAL = !rxvt_tainted ();
734 OUTPUT:
735 RETVAL
537 736
538NV 737NV
539NOW () 738NOW ()
540 CODE: 739 CODE:
541 RETVAL = NOW; 740 RETVAL = NOW;
589} 788}
590 OUTPUT: 789 OUTPUT:
591 RETVAL 790 RETVAL
592 791
593MODULE = urxvt PACKAGE = urxvt::term 792MODULE = urxvt PACKAGE = urxvt::term
793
794void
795rxvt_term::destroy ()
796
797void
798rxvt_term::grab_button (int button, U32 modifiers)
799 CODE:
800 XGrabButton (THIS->display->display, button, modifiers, THIS->vt, 1,
801 ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask,
802 GrabModeSync, GrabModeSync, None, GRAB_CURSOR);
803
804bool
805rxvt_term::grab (U32 eventtime, int sync = 0)
806 CODE:
807{
808 int mode = sync ? GrabModeSync : GrabModeAsync;
809
810 THIS->perl.grabtime = 0;
811
812 if (!XGrabPointer (THIS->display->display, THIS->vt, 0,
813 ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask,
814 mode, mode, None, GRAB_CURSOR, eventtime))
815 if (!XGrabKeyboard (THIS->display->display, THIS->vt, 0, mode, mode, eventtime))
816 THIS->perl.grabtime = eventtime;
817 else
818 XUngrabPointer (THIS->display->display, eventtime);
819
820 RETVAL = !!THIS->perl.grabtime;
821}
822 OUTPUT:
823 RETVAL
824
825void
826rxvt_term::allow_events_async ()
827 CODE:
828 XAllowEvents (THIS->display->display, AsyncBoth, THIS->perl.grabtime);
829
830void
831rxvt_term::allow_events_sync ()
832 CODE:
833 XAllowEvents (THIS->display->display, SyncBoth, THIS->perl.grabtime);
834
835void
836rxvt_term::allow_events_replay ()
837 CODE:
838 XAllowEvents (THIS->display->display, ReplayPointer, THIS->perl.grabtime);
839 XAllowEvents (THIS->display->display, ReplayKeyboard, THIS->perl.grabtime);
840
841void
842rxvt_term::ungrab ()
843 CODE:
844 ungrab (THIS);
594 845
595int 846int
596rxvt_term::strwidth (SV *str) 847rxvt_term::strwidth (SV *str)
597 CODE: 848 CODE:
598{ 849{
617 char *mbstr = rxvt_wcstombs (wstr); 868 char *mbstr = rxvt_wcstombs (wstr);
618 rxvt_pop_locale (); 869 rxvt_pop_locale ();
619 870
620 free (wstr); 871 free (wstr);
621 872
622 RETVAL = newSVpv (mbstr, 0); 873 RETVAL = taint_if (newSVpv (mbstr, 0), str);
623 free (mbstr); 874 free (mbstr);
624} 875}
625 OUTPUT: 876 OUTPUT:
626 RETVAL 877 RETVAL
627 878
634 885
635 rxvt_push_locale (THIS->locale); 886 rxvt_push_locale (THIS->locale);
636 wchar_t *wstr = rxvt_mbstowcs (data, len); 887 wchar_t *wstr = rxvt_mbstowcs (data, len);
637 rxvt_pop_locale (); 888 rxvt_pop_locale ();
638 889
639 char *str = rxvt_wcstoutf8 (wstr); 890 RETVAL = taint_if (wcs2sv (wstr), octets);
640 free (wstr); 891 free (wstr);
641
642 RETVAL = newSVpv (str, 0);
643 SvUTF8_on (RETVAL);
644 free (str);
645} 892}
646 OUTPUT: 893 OUTPUT:
647 RETVAL 894 RETVAL
648 895
896#define TERM_OFFSET(sym) offsetof (TermWin_t, sym)
897
898#define TERM_OFFSET_width TERM_OFFSET(width)
899#define TERM_OFFSET_height TERM_OFFSET(height)
900#define TERM_OFFSET_fwidth TERM_OFFSET(fwidth)
901#define TERM_OFFSET_fheight TERM_OFFSET(fheight)
902#define TERM_OFFSET_fbase TERM_OFFSET(fbase)
903#define TERM_OFFSET_nrow TERM_OFFSET(nrow)
904#define TERM_OFFSET_ncol TERM_OFFSET(ncol)
905#define TERM_OFFSET_focus TERM_OFFSET(focus)
906#define TERM_OFFSET_mapped TERM_OFFSET(mapped)
907#define TERM_OFFSET_saveLines TERM_OFFSET(saveLines)
908#define TERM_OFFSET_total_rows TERM_OFFSET(total_rows)
909#define TERM_OFFSET_nsaved TERM_OFFSET(nsaved)
910
649int 911int
912rxvt_term::width ()
913 ALIAS:
914 width = TERM_OFFSET_width
915 height = TERM_OFFSET_height
916 fwidth = TERM_OFFSET_fwidth
917 fheight = TERM_OFFSET_fheight
918 fbase = TERM_OFFSET_fbase
919 nrow = TERM_OFFSET_nrow
920 ncol = TERM_OFFSET_ncol
921 focus = TERM_OFFSET_focus
922 mapped = TERM_OFFSET_mapped
923 saveLines = TERM_OFFSET_saveLines
924 total_rows = TERM_OFFSET_total_rows
925 nsaved = TERM_OFFSET_nsaved
926 CODE:
927 RETVAL = *(int *)((char *)THIS + ix);
928 OUTPUT:
929 RETVAL
930
931unsigned int
932rxvt_term::ModLevel3Mask ()
933 ALIAS:
934 ModLevel3Mask = 0
935 ModMetaMask = 1
936 ModNumLockMask = 2
937 CODE:
938 switch (ix)
939 {
940 case 0: RETVAL = THIS->ModLevel3Mask; break;
941 case 1: RETVAL = THIS->ModMetaMask; break;
942 case 2: RETVAL = THIS->ModNumLockMask; break;
943 }
944 OUTPUT:
945 RETVAL
946
947char *
948rxvt_term::display_id ()
949 ALIAS:
950 display_id = 0
951 locale = 1
952 CODE:
953 switch (ix)
954 {
955 case 0: RETVAL = THIS->display->id; break;
956 case 1: RETVAL = THIS->locale; break;
957 }
958 OUTPUT:
959 RETVAL
960
961int
962rxvt_term::pty_ev_events (int events = EVENT_UNDEF)
963 CODE:
964 RETVAL = THIS->pty_ev.events;
965 if (events != EVENT_UNDEF)
966 THIS->pty_ev.set (events);
967 OUTPUT:
968 RETVAL
969
970U32
971rxvt_term::parent ()
972 CODE:
973 RETVAL = (U32)THIS->parent [0];
974 OUTPUT:
975 RETVAL
976
977U32
650rxvt_term::nsaved () 978rxvt_term::vt ()
651 CODE: 979 CODE:
980 RETVAL = (U32)THIS->vt;
981 OUTPUT:
982 RETVAL
983
984U32
985rxvt_term::rstyle (U32 new_rstyle = THIS->rstyle)
986 CODE:
987{
652 RETVAL = THIS->nsaved; 988 RETVAL = THIS->rstyle;
989 THIS->rstyle = new_rstyle;
990}
653 OUTPUT: 991 OUTPUT:
654 RETVAL 992 RETVAL
655 993
656int 994int
657rxvt_term::view_start (int newval = -1) 995rxvt_term::view_start (int newval = -1)
658 CODE: 996 CODE:
659{ 997{
666 } 1004 }
667} 1005}
668 OUTPUT: 1006 OUTPUT:
669 RETVAL 1007 RETVAL
670 1008
671int
672rxvt_term::nrow ()
673 CODE:
674 RETVAL = THIS->nrow;
675 OUTPUT:
676 RETVAL
677
678int
679rxvt_term::ncol ()
680 CODE:
681 RETVAL = THIS->ncol;
682 OUTPUT:
683 RETVAL
684
685void 1009void
686rxvt_term::want_refresh () 1010rxvt_term::want_refresh ()
687 CODE: 1011 CODE:
688 THIS->want_refresh = 1; 1012 THIS->want_refresh = 1;
689 1013
690void 1014void
691rxvt_term::ROW_t (int row_number, SV *new_text = 0, int start_col = 0) 1015rxvt_term::ROW_t (int row_number, SV *new_text = 0, int start_col = 0, int start_ofs = 0, int max_len = MAX_COLS)
692 PPCODE: 1016 PPCODE:
693{ 1017{
694 if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) 1018 if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow))
695 XSRETURN_EMPTY; 1019 XSRETURN_EMPTY;
696 1020
698 1022
699 if (GIMME_V != G_VOID) 1023 if (GIMME_V != G_VOID)
700 { 1024 {
701 wchar_t *wstr = new wchar_t [THIS->ncol]; 1025 wchar_t *wstr = new wchar_t [THIS->ncol];
702 1026
703 for (int col = 0; col <THIS->ncol; col++) 1027 for (int col = 0; col < THIS->ncol; col++)
704 wstr [col] = l.t [col]; 1028 wstr [col] = l.t [col];
705 1029
706 char *str = rxvt_wcstoutf8 (wstr, THIS->ncol); 1030 XPUSHs (taint (sv_2mortal (wcs2sv (wstr, THIS->ncol))));
707 free (wstr);
708 1031
709 SV *sv = newSVpv (str, 0); 1032 delete [] wstr;
710 SvUTF8_on (sv);
711 XPUSHs (sv_2mortal (sv));
712 free (str);
713 } 1033 }
714 1034
715 if (new_text) 1035 if (new_text)
716 { 1036 {
717 wchar_t *wstr = sv2wcs (new_text); 1037 wchar_t *wstr = sv2wcs (new_text);
718 1038
719 int len = wcslen (wstr); 1039 int len = min (wcslen (wstr) - start_ofs, max_len);
720 1040
721 if (!IN_RANGE_INC (start_col, 0, THIS->ncol - len)) 1041 if (!IN_RANGE_INC (start_col, 0, THIS->ncol - len))
722 { 1042 {
723 free (wstr); 1043 free (wstr);
724 croak ("new_text extends beyond horizontal margins"); 1044 croak ("new_text extends beyond horizontal margins");
725 } 1045 }
726 1046
727 for (int col = start_col; col < start_col + len; col++) 1047 for (int col = start_col; col < start_col + len; col++)
728 { 1048 {
729 l.t [col] = wstr [col - start_col]; 1049 l.t [col] = wstr [start_ofs + col - start_col];
730 l.r [col] = SET_FONT (l.r [col], THIS->fontset [GET_STYLE (l.r [col])]->find_font (l.t [col])); 1050 l.r [col] = SET_FONT (l.r [col], THIS->fontset [GET_STYLE (l.r [col])]->find_font (l.t [col]));
731 } 1051 }
732 1052
733 free (wstr); 1053 free (wstr);
734 } 1054 }
735} 1055}
736 1056
737void 1057void
738rxvt_term::ROW_r (int row_number, SV *new_rend = 0, int start_col = 0) 1058rxvt_term::ROW_r (int row_number, SV *new_rend = 0, int start_col = 0, int start_ofs = 0, int max_len = MAX_COLS)
739 PPCODE: 1059 PPCODE:
740{ 1060{
741 if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) 1061 if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow))
742 XSRETURN_EMPTY; 1062 XSRETURN_EMPTY;
743 1063
758 { 1078 {
759 if (!SvROK (new_rend) || SvTYPE (SvRV (new_rend)) != SVt_PVAV) 1079 if (!SvROK (new_rend) || SvTYPE (SvRV (new_rend)) != SVt_PVAV)
760 croak ("new_rend must be arrayref"); 1080 croak ("new_rend must be arrayref");
761 1081
762 AV *av = (AV *)SvRV (new_rend); 1082 AV *av = (AV *)SvRV (new_rend);
763 int len = av_len (av) + 1; 1083 int len = min (av_len (av) + 1 - start_ofs, max_len);
764 1084
765 if (!IN_RANGE_INC (start_col, 0, THIS->ncol - len)) 1085 if (!IN_RANGE_INC (start_col, 0, THIS->ncol - len))
766 croak ("new_rend array extends beyond horizontal margins"); 1086 croak ("new_rend array extends beyond horizontal margins");
767 1087
768 for (int col = start_col; col < start_col + len; col++) 1088 for (int col = start_col; col < start_col + len; col++)
769 { 1089 {
770 rend_t r = SvIV (*av_fetch (av, col - start_col, 1)) & ~RS_fontMask; 1090 rend_t r = SvIV (*av_fetch (av, start_ofs + col - start_col, 1)) & ~RS_fontMask;
771 1091
772 l.r [col] = SET_FONT (r, THIS->fontset [GET_STYLE (r)]->find_font (l.t [col])); 1092 l.r [col] = SET_FONT (r, THIS->fontset [GET_STYLE (r)]->find_font (l.t [col]));
773 } 1093 }
774 } 1094 }
775} 1095}
776 1096
777int 1097int
778rxvt_term::ROW_l (int row_number, int new_length = -2) 1098rxvt_term::ROW_l (int row_number, int new_length = -1)
779 CODE: 1099 CODE:
780{ 1100{
781 if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) 1101 if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow))
782 XSRETURN_EMPTY; 1102 XSRETURN_EMPTY;
783 1103
784 line_t &l = ROW(row_number); 1104 line_t &l = ROW(row_number);
785 RETVAL = l.l < 0 ? THIS->ncol : l.l; 1105 RETVAL = l.l;
786 1106
787 if (new_length >= -1) 1107 if (new_length >= 0)
788 l.l = new_length; 1108 l.l = new_length;
789} 1109}
790 OUTPUT: 1110 OUTPUT:
791 RETVAL 1111 RETVAL
792 1112
793bool 1113bool
794rxvt_term::ROW_is_longer (int row_number) 1114rxvt_term::ROW_is_longer (int row_number, int new_is_longer = -1)
795 CODE: 1115 CODE:
796{ 1116{
797 if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) 1117 if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow))
798 XSRETURN_EMPTY; 1118 XSRETURN_EMPTY;
799 1119
800 line_t &l = ROW(row_number); 1120 line_t &l = ROW(row_number);
801 RETVAL = l.l < 0; 1121 RETVAL = l.is_longer ();
1122
1123 if (new_is_longer >= 0)
1124 l.is_longer (new_is_longer);
802} 1125}
803 OUTPUT: 1126 OUTPUT:
804 RETVAL 1127 RETVAL
805 1128
806SV * 1129SV *
807rxvt_term::special_encode (SV *str) 1130rxvt_term::special_encode (SV *string)
808 CODE: 1131 CODE:
809 abort ();//TODO 1132{
1133 wchar_t *wstr = sv2wcs (string);
1134 int wlen = wcslen (wstr);
1135 wchar_t *rstr = new wchar_t [wlen]; // cannot become longer
1136
1137 rxvt_push_locale (THIS->locale);
1138
1139 wchar_t *r = rstr;
1140 for (wchar_t *s = wstr; *s; s++)
1141 if (wcwidth (*s) == 0)
1142 {
1143 if (r == rstr)
1144 croak ("leading combining character unencodable");
1145
1146 unicode_t n = rxvt_compose (r[-1], *s);
1147 if (n == NOCHAR)
1148 n = rxvt_composite.compose (r[-1], *s);
1149
1150 r[-1] = n;
1151 }
1152#if !UNICODE_3
1153 else if (*s >= 0x10000)
1154 *r++ = rxvt_composite.compose (*s);
1155#endif
1156 else
1157 *r++ = *s;
1158
1159 rxvt_pop_locale ();
1160
1161 RETVAL = taint_if (wcs2sv (rstr, r - rstr), string);
1162
1163 delete [] rstr;
1164}
1165 OUTPUT:
1166 RETVAL
810 1167
811SV * 1168SV *
812rxvt_term::special_decode (SV *str) 1169rxvt_term::special_decode (SV *text)
813 CODE: 1170 CODE:
814 abort ();//TODO 1171{
1172 wchar_t *wstr = sv2wcs (text);
1173 int wlen = wcslen (wstr);
1174 int dlen = 0;
1175
1176 // find length
1177 for (wchar_t *s = wstr; *s; s++)
1178 if (*s == NOCHAR)
1179 ;
1180 else if (IS_COMPOSE (*s))
1181 dlen += rxvt_composite.expand (*s, 0);
1182 else
1183 dlen++;
1184
1185 wchar_t *rstr = new wchar_t [dlen];
1186
1187 // decode
1188 wchar_t *r = rstr;
1189 for (wchar_t *s = wstr; *s; s++)
1190 if (*s == NOCHAR)
1191 ;
1192 else if (IS_COMPOSE (*s))
1193 r += rxvt_composite.expand (*s, r);
1194 else
1195 *r++ = *s;
1196
1197 RETVAL = taint_if (wcs2sv (rstr, r - rstr), text);
1198
1199 delete [] rstr;
1200}
1201 OUTPUT:
1202 RETVAL
815 1203
816void 1204void
817rxvt_term::_resource (char *name, int index, SV *newval = 0) 1205rxvt_term::_resource (char *name, int index, SV *newval = 0)
818 PPCODE: 1206 PPCODE:
819{ 1207{
836 1224
837 if (!IN_RANGE_EXC (index, 0, NUM_RESOURCES)) 1225 if (!IN_RANGE_EXC (index, 0, NUM_RESOURCES))
838 croak ("requested out-of-bound resource %s+%d,", name, index - rs->value); 1226 croak ("requested out-of-bound resource %s+%d,", name, index - rs->value);
839 1227
840 if (GIMME_V != G_VOID) 1228 if (GIMME_V != G_VOID)
841 XPUSHs (THIS->rs [index] ? sv_2mortal (newSVpv (THIS->rs [index], 0)) : &PL_sv_undef); 1229 XPUSHs (THIS->rs [index] ? sv_2mortal (taint (newSVpv (THIS->rs [index], 0))) : &PL_sv_undef);
842 1230
843 if (newval) 1231 if (newval)
844 { 1232 {
845 if (SvOK (newval)) 1233 if (SvOK (newval))
846 { 1234 {
851 else 1239 else
852 THIS->rs [index] = 0; 1240 THIS->rs [index] = 0;
853 } 1241 }
854} 1242}
855 1243
1244bool
1245rxvt_term::option (U32 optval, int set = -1)
1246 CODE:
1247{
1248 RETVAL = THIS->options & optval;
1249
1250 if (set >= 0)
1251 {
1252 if (set)
1253 THIS->options |= optval;
1254 else
1255 THIS->options &= ~optval;
1256
1257 switch (optval)
1258 {
1259 case Opt_skipBuiltinGlyphs:
1260 THIS->set_fonts ();
1261 THIS->scr_remap_chars ();
1262 THIS->scr_touch (true);
1263 THIS->want_refresh = 1;
1264 break;
1265
1266 case Opt_cursorUnderline:
1267 THIS->want_refresh = 1;
1268 break;
1269
1270# case Opt_scrollBar_floating:
1271# case Opt_scrollBar_right:
1272# THIS->resize_all_windows (THIS->width, THIS->height, 1);
1273# break;
1274 }
1275 }
1276}
1277 OUTPUT:
1278 RETVAL
1279
1280bool
1281rxvt_term::parse_keysym (char *keysym, char *str)
1282 CODE:
1283 RETVAL = 0 < THIS->parse_keysym (keysym, str);
1284 THIS->keyboard->register_done ();
1285 OUTPUT:
1286 RETVAL
1287
856void 1288void
857rxvt_term::selection_mark (...) 1289rxvt_term::screen_cur (...)
858 PROTOTYPE: $;$$ 1290 PROTOTYPE: $;$$
859 ALIAS: 1291 ALIAS:
1292 screen_cur = 0
860 selection_beg = 1 1293 selection_beg = 1
861 selection_end = 2 1294 selection_end = 2
1295 selection_mark = 3
862 PPCODE: 1296 PPCODE:
863{ 1297{
864 row_col_t &sel = ix == 1 ? THIS->selection.beg 1298 row_col_t &rc = ix == 0 ? THIS->screen.cur
1299 : ix == 1 ? THIS->selection.beg
865 : ix == 2 ? THIS->selection.end 1300 : ix == 2 ? THIS->selection.end
866 : THIS->selection.mark; 1301 : THIS->selection.mark;
867 1302
868 if (GIMME_V != G_VOID) 1303 if (GIMME_V != G_VOID)
869 { 1304 {
870 EXTEND (SP, 2); 1305 EXTEND (SP, 2);
871 PUSHs (sv_2mortal (newSViv (sel.row))); 1306 PUSHs (sv_2mortal (newSViv (rc.row)));
872 PUSHs (sv_2mortal (newSViv (sel.col))); 1307 PUSHs (sv_2mortal (newSViv (rc.col)));
873 } 1308 }
874 1309
875 if (items == 3) 1310 if (items == 3)
876 { 1311 {
877 sel.row = clamp (SvIV (ST (1)), -THIS->nsaved, THIS->nrow - 1); 1312 rc.row = clamp (SvIV (ST (1)), -THIS->nsaved, THIS->nrow - 1);
878 sel.col = clamp (SvIV (ST (2)), 0, THIS->ncol - 1); 1313 rc.col = clamp (SvIV (ST (2)), 0, THIS->ncol - 1);
879 1314
880 if (ix) 1315 if (ix)
881 THIS->want_refresh = 1; 1316 THIS->want_refresh = 1;
882 } 1317 }
883} 1318}
884 1319
885int 1320int
886rxvt_term::selection_grab (int eventtime = CurrentTime) 1321rxvt_term::selection_grab (U32 eventtime)
887 1322
888void 1323void
889rxvt_term::selection (SV *newtext = 0) 1324rxvt_term::selection (SV *newtext = 0)
890 PPCODE: 1325 PPCODE:
891{ 1326{
892 if (GIMME_V != G_VOID) 1327 if (GIMME_V != G_VOID)
893 { 1328 XPUSHs (THIS->selection.text
894 char *sel = rxvt_wcstoutf8 (THIS->selection.text, THIS->selection.len); 1329 ? taint (sv_2mortal (wcs2sv (THIS->selection.text, THIS->selection.len)))
895 SV *sv = newSVpv (sel, 0); 1330 : &PL_sv_undef);
896 SvUTF8_on (sv);
897 free (sel);
898 XPUSHs (sv_2mortal (sv));
899 }
900 1331
901 if (newtext) 1332 if (newtext)
902 { 1333 {
903 free (THIS->selection.text); 1334 free (THIS->selection.text);
904 1335
905 THIS->selection.text = sv2wcs (newtext); 1336 THIS->selection.text = sv2wcs (newtext);
906 THIS->selection.len = wcslen (THIS->selection.text); 1337 THIS->selection.len = wcslen (THIS->selection.text);
907 } 1338 }
908} 1339}
909 1340
1341void
1342rxvt_term::scr_xor_rect (int beg_row, int beg_col, int end_row, int end_col, U32 rstyle1 = RS_RVid, U32 rstyle2 = RS_RVid | RS_Uline)
1343
1344void
1345rxvt_term::scr_xor_span (int beg_row, int beg_col, int end_row, int end_col, U32 rstyle = RS_RVid)
1346
1347void
1348rxvt_term::scr_bell ()
1349
1350void
1351rxvt_term::scr_add_lines (SV *string)
1352 CODE:
1353{
1354 wchar_t *wstr = sv2wcs (string);
1355 THIS->scr_add_lines (wstr, wcslen (wstr));
1356 free (wstr);
1357}
1358
910void 1359void
911rxvt_term::tt_write (SV *octets) 1360rxvt_term::tt_write (SV *octets)
912 INIT: 1361 INIT:
913 STRLEN len; 1362 STRLEN len;
914 char *str = SvPVbyte (octets, len); 1363 char *str = SvPVbyte (octets, len);
915 C_ARGS: 1364 C_ARGS:
916 str, len 1365 str, len
917 1366
1367void
1368rxvt_term::cmd_parse (SV *octets)
1369 CODE:
1370{
1371 STRLEN len;
1372 char *str = SvPVbyte (octets, len);
1373
1374 char *old_cmdbuf_ptr = THIS->cmdbuf_ptr;
1375 char *old_cmdbuf_endp = THIS->cmdbuf_endp;
1376
1377 THIS->cmdbuf_ptr = str;
1378 THIS->cmdbuf_endp = str + len;
1379
1380 rxvt_push_locale (THIS->locale);
1381 THIS->cmd_parse ();
1382 rxvt_pop_locale ();
1383
1384 THIS->cmdbuf_ptr = old_cmdbuf_ptr;
1385 THIS->cmdbuf_endp = old_cmdbuf_endp;
1386}
1387
918SV * 1388SV *
919rxvt_term::overlay (int x, int y, int w, int h, int rstyle = OVERLAY_RSTYLE, int border = 2) 1389rxvt_term::overlay (int x, int y, int w, int h, int rstyle = OVERLAY_RSTYLE, int border = 2)
920 CODE: 1390 CODE:
921{ 1391{
922 overlay *o = new overlay (THIS, x, y, w, h, rstyle, border); 1392 overlay *o = new overlay (THIS, x, y, w, h, rstyle, border);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines