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