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 | |
|
|
55 | static SV * |
|
|
56 | taint (SV *sv) |
|
|
57 | { |
|
|
58 | SvTAINT (sv); |
|
|
59 | return sv; |
|
|
60 | } |
|
|
61 | |
|
|
62 | static SV * |
|
|
63 | taint_if (SV *sv, SV *src) |
|
|
64 | { |
|
|
65 | if (SvTAINTED (src)) |
|
|
66 | SvTAINT (sv); |
|
|
67 | |
|
|
68 | return sv; |
|
|
69 | } |
|
|
70 | |
47 | static wchar_t * |
71 | static wchar_t * |
48 | sv2wcs (SV *sv) |
72 | sv2wcs (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 | |
55 | static SV * |
79 | static SV * |
|
|
80 | wcs2sv (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 | |
|
|
91 | static SV * |
56 | new_ref (HV *hv, const char *klass) |
92 | new_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 | |
99 | struct perl_watcher |
135 | struct 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 | |
… | |
… | |
278 | void |
314 | void |
279 | overlay::show () |
315 | overlay::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 | |
287 | void |
323 | void |
288 | overlay::hide () |
324 | overlay::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) |
… | |
… | |
375 | void |
411 | void |
376 | rxvt_perl_interp::init () |
412 | rxvt_perl_interp::init () |
377 | { |
413 | { |
378 | if (!perl) |
414 | if (!perl) |
379 | { |
415 | { |
|
|
416 | perl_environ = rxvt_environ; |
|
|
417 | swap (perl_environ, environ); |
|
|
418 | |
380 | char *argv[] = { |
419 | char *argv[] = { |
381 | "", |
420 | "", |
|
|
421 | "-T", |
382 | "-edo '" LIBDIR "/urxvt.pm' or ($@ and die $@) or exit 1", |
422 | "-edo '" LIBDIR "/urxvt.pm' or ($@ and die $@) or exit 1", |
383 | }; |
423 | }; |
384 | |
424 | |
385 | perl = perl_alloc (); |
425 | perl = perl_alloc (); |
386 | perl_construct (perl); |
426 | perl_construct (perl); |
387 | |
427 | |
388 | if (perl_parse (perl, xs_init, 2, argv, (char **)NULL) |
428 | if (perl_parse (perl, xs_init, 3, argv, (char **)NULL) |
389 | || perl_run (perl)) |
429 | || perl_run (perl)) |
390 | { |
430 | { |
391 | rxvt_warn ("unable to initialize perl-interpreter, continuing without.\n"); |
431 | rxvt_warn ("unable to initialize perl-interpreter, continuing without.\n"); |
392 | |
432 | |
393 | perl_destruct (perl); |
433 | perl_destruct (perl); |
394 | perl_free (perl); |
434 | perl_free (perl); |
395 | perl = 0; |
435 | perl = 0; |
396 | } |
436 | } |
|
|
437 | |
|
|
438 | swap (perl_environ, environ); |
|
|
439 | } |
|
|
440 | } |
|
|
441 | |
|
|
442 | static void |
|
|
443 | ungrab (rxvt_term *THIS) |
|
|
444 | { |
|
|
445 | if (THIS->perl.grabtime) |
|
|
446 | { |
|
|
447 | XUngrabKeyboard (THIS->display->display, THIS->perl.grabtime); |
|
|
448 | XUngrabPointer (THIS->display->display, THIS->perl.grabtime); |
|
|
449 | THIS->perl.grabtime = 0; |
397 | } |
450 | } |
398 | } |
451 | } |
399 | |
452 | |
400 | bool |
453 | bool |
401 | rxvt_perl_interp::invoke (rxvt_term *term, hook_type htype, ...) |
454 | rxvt_perl_interp::invoke (rxvt_term *term, hook_type htype, ...) |
402 | { |
455 | { |
403 | if (!perl) |
456 | if (!perl) |
404 | return false; |
457 | return false; |
405 | |
458 | |
406 | if (htype == HOOK_INIT) // first hook ever called |
459 | if (htype == HOOK_INIT) // first hook ever called |
407 | { |
460 | { |
408 | term->self = (void *)newSVptr ((void *)term, "urxvt::term"); |
461 | term->perl.self = (void *)newSVptr ((void *)term, "urxvt::term"); |
409 | hv_store ((HV *)SvRV ((SV *)term->self), "_overlay", 8, newRV_noinc ((SV *)newHV ()), 0); |
462 | hv_store ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, newRV_noinc ((SV *)newHV ()), 0); |
410 | } |
463 | } |
411 | else if (!term->self) |
464 | else if (!term->perl.self) |
412 | return false; // perl not initialized for this instance |
465 | return false; // perl not initialized for this instance |
413 | else if (htype == HOOK_DESTROY) |
466 | else if (htype == HOOK_DESTROY) |
414 | { |
467 | { |
415 | // handled later |
468 | // handled later |
416 | } |
469 | } |
417 | else if (htype == HOOK_REFRESH_BEGIN || htype == HOOK_REFRESH_END) |
470 | else |
418 | { |
471 | { |
419 | HV *hv = (HV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->self), "_overlay", 8, 0)); |
472 | if (htype == HOOK_REFRESH_BEGIN || htype == HOOK_REFRESH_END) |
420 | |
|
|
421 | if (HvKEYS (hv)) |
|
|
422 | { |
473 | { |
|
|
474 | HV *hv = (HV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, 0)); |
|
|
475 | |
|
|
476 | if (HvKEYS (hv)) |
|
|
477 | { |
423 | hv_iterinit (hv); |
478 | hv_iterinit (hv); |
424 | |
479 | |
425 | while (HE *he = hv_iternext (hv)) |
480 | while (HE *he = hv_iternext (hv)) |
426 | ((overlay *)SvIV (hv_iterval (hv, he)))->swap (); |
481 | ((overlay *)SvIV (hv_iterval (hv, he)))->swap (); |
|
|
482 | } |
|
|
483 | |
427 | } |
484 | } |
|
|
485 | |
|
|
486 | if (!should_invoke [htype]) |
|
|
487 | return false; |
428 | } |
488 | } |
429 | else if (!should_invoke [htype]) |
|
|
430 | return false; |
|
|
431 | |
489 | |
|
|
490 | swap (perl_environ, environ); |
|
|
491 | |
|
|
492 | try |
|
|
493 | { |
432 | dSP; |
494 | dSP; |
433 | va_list ap; |
495 | va_list ap; |
434 | |
496 | |
435 | va_start (ap, htype); |
497 | va_start (ap, htype); |
436 | |
498 | |
437 | ENTER; |
499 | ENTER; |
438 | SAVETMPS; |
500 | SAVETMPS; |
439 | |
501 | |
440 | PUSHMARK (SP); |
502 | PUSHMARK (SP); |
441 | |
503 | |
442 | XPUSHs (sv_2mortal (newSVterm (term))); |
504 | XPUSHs (sv_2mortal (newSVterm (term))); |
443 | XPUSHs (sv_2mortal (newSViv (htype))); |
505 | XPUSHs (sv_2mortal (newSViv (htype))); |
444 | |
506 | |
445 | for (;;) { |
507 | for (;;) { |
446 | data_type dt = (data_type)va_arg (ap, int); |
508 | data_type dt = (data_type)va_arg (ap, int); |
447 | |
509 | |
448 | switch (dt) |
510 | switch (dt) |
449 | { |
511 | { |
450 | case DT_INT: |
512 | case DT_INT: |
451 | XPUSHs (sv_2mortal (newSViv (va_arg (ap, int)))); |
513 | XPUSHs (sv_2mortal (newSViv (va_arg (ap, int)))); |
452 | break; |
514 | break; |
453 | |
515 | |
454 | case DT_LONG: |
516 | case DT_LONG: |
455 | XPUSHs (sv_2mortal (newSViv (va_arg (ap, long)))); |
517 | XPUSHs (sv_2mortal (newSViv (va_arg (ap, long)))); |
456 | break; |
518 | break; |
457 | |
519 | |
458 | case DT_STRING: |
520 | case DT_STR: |
459 | XPUSHs (sv_2mortal (newSVpv (va_arg (ap, char *), 0))); |
521 | XPUSHs (taint (sv_2mortal (newSVpv (va_arg (ap, char *), 0)))); |
460 | break; |
522 | break; |
461 | |
523 | |
462 | case DT_END: |
524 | case DT_STR_LEN: |
463 | { |
|
|
464 | va_end (ap); |
|
|
465 | |
|
|
466 | PUTBACK; |
|
|
467 | int count = call_pv ("urxvt::invoke", G_ARRAY | G_EVAL); |
|
|
468 | SPAGAIN; |
|
|
469 | |
|
|
470 | if (count) |
|
|
471 | { |
525 | { |
472 | SV *status = POPs; |
526 | char *str = va_arg (ap, char *); |
473 | count = SvTRUE (status); |
527 | int len = va_arg (ap, int); |
|
|
528 | |
|
|
529 | XPUSHs (taint (sv_2mortal (newSVpvn (str, len)))); |
474 | } |
530 | } |
|
|
531 | break; |
475 | |
532 | |
476 | PUTBACK; |
533 | case DT_WCS_LEN: |
477 | FREETMPS; |
|
|
478 | LEAVE; |
|
|
479 | |
|
|
480 | if (SvTRUE (ERRSV)) |
|
|
481 | rxvt_warn ("perl hook %d evaluation error: %s", htype, SvPV_nolen (ERRSV)); |
|
|
482 | |
|
|
483 | if (htype == HOOK_DESTROY) |
|
|
484 | { |
534 | { |
485 | clearSVptr ((SV *)term->self); |
535 | wchar_t *wstr = va_arg (ap, wchar_t *); |
486 | SvREFCNT_dec ((SV *)term->self); |
536 | int wlen = va_arg (ap, int); |
|
|
537 | |
|
|
538 | XPUSHs (taint (sv_2mortal (wcs2sv (wstr, wlen)))); |
487 | } |
539 | } |
|
|
540 | break; |
488 | |
541 | |
|
|
542 | case DT_XEVENT: |
|
|
543 | { |
|
|
544 | XEvent *xe = va_arg (ap, XEvent *); |
|
|
545 | HV *hv = newHV (); |
|
|
546 | |
|
|
547 | # define set(name, sv) hv_store (hv, # name, sizeof (# name) - 1, sv, 0) |
|
|
548 | # define setiv(name, val) hv_store (hv, # name, sizeof (# name) - 1, newSViv (val), 0) |
|
|
549 | # undef set |
|
|
550 | |
|
|
551 | setiv (type, xe->type); |
|
|
552 | setiv (send_event, xe->xany.send_event); |
|
|
553 | setiv (serial, xe->xany.serial); |
|
|
554 | |
|
|
555 | switch (xe->type) |
|
|
556 | { |
|
|
557 | case KeyPress: |
|
|
558 | case KeyRelease: |
|
|
559 | case ButtonPress: |
|
|
560 | case ButtonRelease: |
|
|
561 | case MotionNotify: |
|
|
562 | setiv (time, xe->xmotion.time); |
|
|
563 | setiv (x, xe->xmotion.x); |
|
|
564 | setiv (y, xe->xmotion.y); |
|
|
565 | setiv (row, xe->xmotion.y / term->fheight); |
|
|
566 | setiv (col, xe->xmotion.x / term->fwidth); |
|
|
567 | setiv (x_root, xe->xmotion.x_root); |
|
|
568 | setiv (y_root, xe->xmotion.y_root); |
|
|
569 | setiv (state, xe->xmotion.state); |
|
|
570 | break; |
|
|
571 | } |
|
|
572 | |
|
|
573 | switch (xe->type) |
|
|
574 | { |
|
|
575 | case KeyPress: |
|
|
576 | case KeyRelease: |
|
|
577 | setiv (keycode, xe->xkey.keycode); |
|
|
578 | break; |
|
|
579 | |
|
|
580 | case ButtonPress: |
|
|
581 | case ButtonRelease: |
|
|
582 | setiv (button, xe->xbutton.button); |
|
|
583 | break; |
|
|
584 | |
|
|
585 | case MotionNotify: |
|
|
586 | setiv (is_hint, xe->xmotion.is_hint); |
|
|
587 | break; |
|
|
588 | } |
|
|
589 | |
|
|
590 | XPUSHs (sv_2mortal (newRV_noinc ((SV *)hv))); |
|
|
591 | } |
|
|
592 | break; |
|
|
593 | |
|
|
594 | case DT_END: |
|
|
595 | { |
|
|
596 | va_end (ap); |
|
|
597 | |
|
|
598 | PUTBACK; |
|
|
599 | int count = call_pv ("urxvt::invoke", G_ARRAY | G_EVAL); |
|
|
600 | SPAGAIN; |
|
|
601 | |
|
|
602 | if (count) |
|
|
603 | { |
|
|
604 | SV *status = POPs; |
|
|
605 | count = SvTRUE (status); |
|
|
606 | } |
|
|
607 | |
|
|
608 | PUTBACK; |
|
|
609 | FREETMPS; |
|
|
610 | LEAVE; |
|
|
611 | |
|
|
612 | if (SvTRUE (ERRSV)) |
|
|
613 | { |
|
|
614 | rxvt_warn ("perl hook %d evaluation error: %s", htype, SvPV_nolen (ERRSV)); |
|
|
615 | ungrab (term); // better lose the grab than the session |
|
|
616 | } |
|
|
617 | |
|
|
618 | if (htype == HOOK_DESTROY) |
|
|
619 | { |
|
|
620 | clearSVptr ((SV *)term->perl.self); |
|
|
621 | SvREFCNT_dec ((SV *)term->perl.self); |
|
|
622 | } |
|
|
623 | |
|
|
624 | swap (perl_environ, environ); |
489 | return count; |
625 | return count; |
490 | } |
626 | } |
491 | |
627 | |
492 | default: |
628 | default: |
493 | rxvt_fatal ("FATAL: unable to pass data type %d\n", dt); |
629 | rxvt_fatal ("FATAL: unable to pass data type %d\n", dt); |
|
|
630 | } |
494 | } |
631 | } |
495 | } |
632 | } |
|
|
633 | catch (...) |
|
|
634 | { |
|
|
635 | swap (perl_environ, environ); |
|
|
636 | throw; |
|
|
637 | } |
496 | } |
638 | } |
497 | |
639 | |
498 | ///////////////////////////////////////////////////////////////////////////// |
640 | ///////////////////////////////////////////////////////////////////////////// |
499 | |
641 | |
500 | MODULE = urxvt PACKAGE = urxvt |
642 | MODULE = urxvt PACKAGE = urxvt |
501 | |
643 | |
502 | PROTOTYPES: ENABLE |
644 | PROTOTYPES: ENABLE |
503 | |
645 | |
504 | BOOT: |
646 | BOOT: |
505 | { |
647 | { |
506 | # define set_hookname(sym) av_store (hookname, PP_CONCAT(HOOK_, sym), newSVpv (PP_STRINGIFY(sym), 0)) |
648 | 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)); |
649 | sv_setsv (get_sv ("urxvt::RESNAME", 1), newSVpvn (RESNAME, sizeof (RESNAME) - 1)); |
|
|
650 | sv_setsv (get_sv ("urxvt::RESCLASS", 1), newSVpvn (RESCLASS, sizeof (RESCLASS) - 1)); |
|
|
651 | sv_setsv (get_sv ("urxvt::RXVTNAME", 1), newSVpvn (RXVTNAME, sizeof (RXVTNAME) - 1)); |
|
|
652 | |
508 | AV *hookname = get_av ("urxvt::HOOKNAME", 1); |
653 | AV *hookname = get_av ("urxvt::HOOKNAME", 1); |
509 | set_hookname (INIT); |
654 | # define def(sym) av_store (hookname, HOOK_ ## sym, newSVpv (# sym, 0)); |
510 | set_hookname (RESET); |
655 | # include "hookinc.h" |
511 | set_hookname (START); |
656 | # 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 (REFRESH_BEGIN); |
|
|
523 | set_hookname (REFRESH_END); |
|
|
524 | set_hookname (KEYBOARD_COMMAND); |
|
|
525 | |
657 | |
|
|
658 | HV *option = get_hv ("urxvt::OPTION", 1); |
|
|
659 | # define def(name,val) hv_store (option, # name, sizeof (# name) - 1, newSVuv (Opt_ ## name), 0); |
|
|
660 | # define nodef(name) |
|
|
661 | # include "optinc.h" |
|
|
662 | # undef nodef |
|
|
663 | # undef def |
|
|
664 | |
|
|
665 | HV *stash = gv_stashpv ("urxvt", 1); |
|
|
666 | # define export_const_iv(name) newCONSTSUB (stash, # name, newSViv (name)); |
526 | export_const (DEFAULT_RSTYLE); |
667 | export_const_iv (DEFAULT_RSTYLE); |
527 | export_const (OVERLAY_RSTYLE); |
668 | export_const_iv (OVERLAY_RSTYLE); |
528 | export_const (RS_Bold); |
669 | export_const_iv (RS_Bold); |
529 | export_const (RS_Italic); |
670 | export_const_iv (RS_Italic); |
530 | export_const (RS_Blink); |
671 | export_const_iv (RS_Blink); |
531 | export_const (RS_RVid); |
672 | export_const_iv (RS_RVid); |
532 | export_const (RS_Uline); |
673 | export_const_iv (RS_Uline); |
533 | |
674 | |
534 | sv_setpv (get_sv ("urxvt::LIBDIR", 1), LIBDIR); |
675 | export_const_iv (CurrentTime); |
|
|
676 | export_const_iv (ShiftMask); |
|
|
677 | export_const_iv (LockMask); |
|
|
678 | export_const_iv (ControlMask); |
|
|
679 | export_const_iv (Mod1Mask); |
|
|
680 | export_const_iv (Mod2Mask); |
|
|
681 | export_const_iv (Mod3Mask); |
|
|
682 | export_const_iv (Mod4Mask); |
|
|
683 | export_const_iv (Mod5Mask); |
|
|
684 | export_const_iv (Button1Mask); |
|
|
685 | export_const_iv (Button2Mask); |
|
|
686 | export_const_iv (Button3Mask); |
|
|
687 | export_const_iv (Button4Mask); |
|
|
688 | export_const_iv (Button5Mask); |
|
|
689 | export_const_iv (AnyModifier); |
|
|
690 | |
|
|
691 | export_const_iv (EVENT_NONE); |
|
|
692 | export_const_iv (EVENT_READ); |
|
|
693 | export_const_iv (EVENT_WRITE); |
535 | } |
694 | } |
536 | |
695 | |
537 | void |
696 | void |
538 | set_should_invoke (int htype, int value) |
697 | set_should_invoke (int htype, int value) |
539 | CODE: |
698 | CODE: |
… | |
… | |
546 | |
705 | |
547 | void |
706 | void |
548 | fatal (const char *msg) |
707 | fatal (const char *msg) |
549 | CODE: |
708 | CODE: |
550 | rxvt_fatal ("%s", msg); |
709 | rxvt_fatal ("%s", msg); |
|
|
710 | |
|
|
711 | SV * |
|
|
712 | untaint (SV *sv) |
|
|
713 | CODE: |
|
|
714 | RETVAL = newSVsv (sv); |
|
|
715 | SvTAINTED_off (RETVAL); |
|
|
716 | OUTPUT: |
|
|
717 | RETVAL |
|
|
718 | |
|
|
719 | bool |
|
|
720 | safe () |
|
|
721 | CODE: |
|
|
722 | RETVAL = !rxvt_tainted (); |
|
|
723 | OUTPUT: |
|
|
724 | RETVAL |
551 | |
725 | |
552 | NV |
726 | NV |
553 | NOW () |
727 | NOW () |
554 | CODE: |
728 | CODE: |
555 | RETVAL = NOW; |
729 | RETVAL = NOW; |
… | |
… | |
603 | } |
777 | } |
604 | OUTPUT: |
778 | OUTPUT: |
605 | RETVAL |
779 | RETVAL |
606 | |
780 | |
607 | MODULE = urxvt PACKAGE = urxvt::term |
781 | MODULE = urxvt PACKAGE = urxvt::term |
|
|
782 | |
|
|
783 | SV * |
|
|
784 | _new (...) |
|
|
785 | CODE: |
|
|
786 | { |
|
|
787 | if (items < 1 || !SvROK (ST (0)) || SvTYPE (SvRV (ST (0))) != SVt_PVAV) |
|
|
788 | croak ("first argument to urxvt::term->_new must be arrayref"); |
|
|
789 | |
|
|
790 | rxvt_term *term = new rxvt_term; |
|
|
791 | |
|
|
792 | term->argv = new stringvec; |
|
|
793 | term->envv = new stringvec; |
|
|
794 | |
|
|
795 | for (int i = 1; i < items; i++) |
|
|
796 | term->argv->push_back (strdup (SvPVbyte_nolen (ST (i)))); |
|
|
797 | |
|
|
798 | AV *envv = (AV *)SvRV (ST (0)); |
|
|
799 | for (int i = av_len (envv) + 1; i--; ) |
|
|
800 | term->envv->push_back (strdup (SvPVbyte_nolen (*av_fetch (envv, i, 1)))); |
|
|
801 | |
|
|
802 | term->envv->push_back (0); |
|
|
803 | |
|
|
804 | bool success; |
|
|
805 | |
|
|
806 | try |
|
|
807 | { |
|
|
808 | success = term->init (term->argv->size (), term->argv->begin ()); |
|
|
809 | } |
|
|
810 | catch (const class rxvt_failure_exception &e) |
|
|
811 | { |
|
|
812 | success = false; |
|
|
813 | } |
|
|
814 | |
|
|
815 | if (!success) |
|
|
816 | { |
|
|
817 | term->destroy (); |
|
|
818 | croak ("error while initializing new terminal instance"); |
|
|
819 | } |
|
|
820 | |
|
|
821 | RETVAL = term && term->perl.self |
|
|
822 | ? newSVterm (term) : &PL_sv_undef; |
|
|
823 | } |
|
|
824 | OUTPUT: |
|
|
825 | RETVAL |
|
|
826 | |
|
|
827 | void |
|
|
828 | rxvt_term::destroy () |
|
|
829 | |
|
|
830 | void |
|
|
831 | rxvt_term::grab_button (int button, U32 modifiers) |
|
|
832 | CODE: |
|
|
833 | XGrabButton (THIS->display->display, button, modifiers, THIS->vt, 1, |
|
|
834 | ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask, |
|
|
835 | GrabModeSync, GrabModeSync, None, GRAB_CURSOR); |
|
|
836 | |
|
|
837 | bool |
|
|
838 | rxvt_term::grab (U32 eventtime, int sync = 0) |
|
|
839 | CODE: |
|
|
840 | { |
|
|
841 | int mode = sync ? GrabModeSync : GrabModeAsync; |
|
|
842 | |
|
|
843 | THIS->perl.grabtime = 0; |
|
|
844 | |
|
|
845 | if (!XGrabPointer (THIS->display->display, THIS->vt, 0, |
|
|
846 | ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask, |
|
|
847 | mode, mode, None, GRAB_CURSOR, eventtime)) |
|
|
848 | if (!XGrabKeyboard (THIS->display->display, THIS->vt, 0, mode, mode, eventtime)) |
|
|
849 | THIS->perl.grabtime = eventtime; |
|
|
850 | else |
|
|
851 | XUngrabPointer (THIS->display->display, eventtime); |
|
|
852 | |
|
|
853 | RETVAL = !!THIS->perl.grabtime; |
|
|
854 | } |
|
|
855 | OUTPUT: |
|
|
856 | RETVAL |
|
|
857 | |
|
|
858 | void |
|
|
859 | rxvt_term::allow_events_async () |
|
|
860 | CODE: |
|
|
861 | XAllowEvents (THIS->display->display, AsyncBoth, THIS->perl.grabtime); |
|
|
862 | |
|
|
863 | void |
|
|
864 | rxvt_term::allow_events_sync () |
|
|
865 | CODE: |
|
|
866 | XAllowEvents (THIS->display->display, SyncBoth, THIS->perl.grabtime); |
|
|
867 | |
|
|
868 | void |
|
|
869 | rxvt_term::allow_events_replay () |
|
|
870 | CODE: |
|
|
871 | XAllowEvents (THIS->display->display, ReplayPointer, THIS->perl.grabtime); |
|
|
872 | XAllowEvents (THIS->display->display, ReplayKeyboard, THIS->perl.grabtime); |
|
|
873 | |
|
|
874 | void |
|
|
875 | rxvt_term::ungrab () |
|
|
876 | CODE: |
|
|
877 | ungrab (THIS); |
608 | |
878 | |
609 | int |
879 | int |
610 | rxvt_term::strwidth (SV *str) |
880 | rxvt_term::strwidth (SV *str) |
611 | CODE: |
881 | CODE: |
612 | { |
882 | { |
… | |
… | |
631 | char *mbstr = rxvt_wcstombs (wstr); |
901 | char *mbstr = rxvt_wcstombs (wstr); |
632 | rxvt_pop_locale (); |
902 | rxvt_pop_locale (); |
633 | |
903 | |
634 | free (wstr); |
904 | free (wstr); |
635 | |
905 | |
636 | RETVAL = newSVpv (mbstr, 0); |
906 | RETVAL = taint_if (newSVpv (mbstr, 0), str); |
637 | free (mbstr); |
907 | free (mbstr); |
638 | } |
908 | } |
639 | OUTPUT: |
909 | OUTPUT: |
640 | RETVAL |
910 | RETVAL |
641 | |
911 | |
… | |
… | |
648 | |
918 | |
649 | rxvt_push_locale (THIS->locale); |
919 | rxvt_push_locale (THIS->locale); |
650 | wchar_t *wstr = rxvt_mbstowcs (data, len); |
920 | wchar_t *wstr = rxvt_mbstowcs (data, len); |
651 | rxvt_pop_locale (); |
921 | rxvt_pop_locale (); |
652 | |
922 | |
653 | char *str = rxvt_wcstoutf8 (wstr); |
923 | RETVAL = taint_if (wcs2sv (wstr), octets); |
654 | free (wstr); |
924 | free (wstr); |
655 | |
|
|
656 | RETVAL = newSVpv (str, 0); |
|
|
657 | SvUTF8_on (RETVAL); |
|
|
658 | free (str); |
|
|
659 | } |
925 | } |
660 | OUTPUT: |
926 | OUTPUT: |
661 | RETVAL |
927 | RETVAL |
|
|
928 | |
|
|
929 | #define TERM_OFFSET(sym) offsetof (TermWin_t, sym) |
|
|
930 | |
|
|
931 | #define TERM_OFFSET_width TERM_OFFSET(width) |
|
|
932 | #define TERM_OFFSET_height TERM_OFFSET(height) |
|
|
933 | #define TERM_OFFSET_fwidth TERM_OFFSET(fwidth) |
|
|
934 | #define TERM_OFFSET_fheight TERM_OFFSET(fheight) |
|
|
935 | #define TERM_OFFSET_fbase TERM_OFFSET(fbase) |
|
|
936 | #define TERM_OFFSET_nrow TERM_OFFSET(nrow) |
|
|
937 | #define TERM_OFFSET_ncol TERM_OFFSET(ncol) |
|
|
938 | #define TERM_OFFSET_focus TERM_OFFSET(focus) |
|
|
939 | #define TERM_OFFSET_mapped TERM_OFFSET(mapped) |
|
|
940 | #define TERM_OFFSET_saveLines TERM_OFFSET(saveLines) |
|
|
941 | #define TERM_OFFSET_total_rows TERM_OFFSET(total_rows) |
|
|
942 | #define TERM_OFFSET_nsaved TERM_OFFSET(nsaved) |
662 | |
943 | |
663 | int |
944 | int |
|
|
945 | rxvt_term::width () |
|
|
946 | ALIAS: |
|
|
947 | width = TERM_OFFSET_width |
|
|
948 | height = TERM_OFFSET_height |
|
|
949 | fwidth = TERM_OFFSET_fwidth |
|
|
950 | fheight = TERM_OFFSET_fheight |
|
|
951 | fbase = TERM_OFFSET_fbase |
|
|
952 | nrow = TERM_OFFSET_nrow |
|
|
953 | ncol = TERM_OFFSET_ncol |
|
|
954 | focus = TERM_OFFSET_focus |
|
|
955 | mapped = TERM_OFFSET_mapped |
|
|
956 | saveLines = TERM_OFFSET_saveLines |
|
|
957 | total_rows = TERM_OFFSET_total_rows |
|
|
958 | nsaved = TERM_OFFSET_nsaved |
|
|
959 | CODE: |
|
|
960 | RETVAL = *(int *)((char *)THIS + ix); |
|
|
961 | OUTPUT: |
|
|
962 | RETVAL |
|
|
963 | |
|
|
964 | unsigned int |
|
|
965 | rxvt_term::ModLevel3Mask () |
|
|
966 | ALIAS: |
|
|
967 | ModLevel3Mask = 0 |
|
|
968 | ModMetaMask = 1 |
|
|
969 | ModNumLockMask = 2 |
|
|
970 | CODE: |
|
|
971 | switch (ix) |
|
|
972 | { |
|
|
973 | case 0: RETVAL = THIS->ModLevel3Mask; break; |
|
|
974 | case 1: RETVAL = THIS->ModMetaMask; break; |
|
|
975 | case 2: RETVAL = THIS->ModNumLockMask; break; |
|
|
976 | } |
|
|
977 | OUTPUT: |
|
|
978 | RETVAL |
|
|
979 | |
|
|
980 | char * |
|
|
981 | rxvt_term::display_id () |
|
|
982 | ALIAS: |
|
|
983 | display_id = 0 |
|
|
984 | locale = 1 |
|
|
985 | CODE: |
|
|
986 | switch (ix) |
|
|
987 | { |
|
|
988 | case 0: RETVAL = THIS->display->id; break; |
|
|
989 | case 1: RETVAL = THIS->locale; break; |
|
|
990 | } |
|
|
991 | OUTPUT: |
|
|
992 | RETVAL |
|
|
993 | |
|
|
994 | SV * |
664 | rxvt_term::nsaved () |
995 | rxvt_term::_env () |
665 | CODE: |
996 | CODE: |
|
|
997 | { |
|
|
998 | if (THIS->envv) |
|
|
999 | { |
|
|
1000 | AV *av = newAV (); |
|
|
1001 | |
|
|
1002 | for (char **i = THIS->envv->begin (); i != THIS->envv->end (); ++i) |
|
|
1003 | if (*i) |
|
|
1004 | av_push (av, newSVpv (*i, 0)); |
|
|
1005 | |
|
|
1006 | RETVAL = newRV_noinc ((SV *)av); |
|
|
1007 | } |
|
|
1008 | else |
|
|
1009 | RETVAL = &PL_sv_undef; |
|
|
1010 | } |
|
|
1011 | OUTPUT: |
|
|
1012 | RETVAL |
|
|
1013 | |
|
|
1014 | int |
|
|
1015 | rxvt_term::pty_ev_events (int events = EVENT_UNDEF) |
|
|
1016 | CODE: |
|
|
1017 | RETVAL = THIS->pty_ev.events; |
|
|
1018 | if (events != EVENT_UNDEF) |
|
|
1019 | THIS->pty_ev.set (events); |
|
|
1020 | OUTPUT: |
|
|
1021 | RETVAL |
|
|
1022 | |
|
|
1023 | U32 |
|
|
1024 | rxvt_term::parent () |
|
|
1025 | CODE: |
|
|
1026 | RETVAL = (U32)THIS->parent [0]; |
|
|
1027 | OUTPUT: |
|
|
1028 | RETVAL |
|
|
1029 | |
|
|
1030 | U32 |
|
|
1031 | rxvt_term::vt () |
|
|
1032 | CODE: |
|
|
1033 | RETVAL = (U32)THIS->vt; |
|
|
1034 | OUTPUT: |
|
|
1035 | RETVAL |
|
|
1036 | |
|
|
1037 | U32 |
|
|
1038 | rxvt_term::rstyle (U32 new_rstyle = THIS->rstyle) |
|
|
1039 | CODE: |
|
|
1040 | { |
666 | RETVAL = THIS->nsaved; |
1041 | RETVAL = THIS->rstyle; |
|
|
1042 | THIS->rstyle = new_rstyle; |
|
|
1043 | } |
667 | OUTPUT: |
1044 | OUTPUT: |
668 | RETVAL |
1045 | RETVAL |
669 | |
1046 | |
670 | int |
1047 | int |
671 | rxvt_term::view_start (int newval = -1) |
1048 | rxvt_term::view_start (int newval = -1) |
672 | CODE: |
1049 | CODE: |
673 | { |
1050 | { |
… | |
… | |
680 | } |
1057 | } |
681 | } |
1058 | } |
682 | OUTPUT: |
1059 | OUTPUT: |
683 | RETVAL |
1060 | RETVAL |
684 | |
1061 | |
685 | int |
|
|
686 | rxvt_term::nrow () |
|
|
687 | CODE: |
|
|
688 | RETVAL = THIS->nrow; |
|
|
689 | OUTPUT: |
|
|
690 | RETVAL |
|
|
691 | |
|
|
692 | int |
|
|
693 | rxvt_term::ncol () |
|
|
694 | CODE: |
|
|
695 | RETVAL = THIS->ncol; |
|
|
696 | OUTPUT: |
|
|
697 | RETVAL |
|
|
698 | |
|
|
699 | void |
1062 | void |
700 | rxvt_term::want_refresh () |
1063 | rxvt_term::want_refresh () |
701 | CODE: |
1064 | CODE: |
702 | THIS->want_refresh = 1; |
1065 | THIS->want_refresh = 1; |
703 | |
1066 | |
704 | void |
1067 | void |
705 | rxvt_term::ROW_t (int row_number, SV *new_text = 0, int start_col = 0) |
1068 | rxvt_term::ROW_t (int row_number, SV *new_text = 0, int start_col = 0, int start_ofs = 0, int max_len = MAX_COLS) |
706 | PPCODE: |
1069 | PPCODE: |
707 | { |
1070 | { |
708 | if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) |
1071 | if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) |
709 | XSRETURN_EMPTY; |
1072 | XSRETURN_EMPTY; |
710 | |
1073 | |
… | |
… | |
712 | |
1075 | |
713 | if (GIMME_V != G_VOID) |
1076 | if (GIMME_V != G_VOID) |
714 | { |
1077 | { |
715 | wchar_t *wstr = new wchar_t [THIS->ncol]; |
1078 | wchar_t *wstr = new wchar_t [THIS->ncol]; |
716 | |
1079 | |
717 | for (int col = 0; col <THIS->ncol; col++) |
1080 | for (int col = 0; col < THIS->ncol; col++) |
718 | wstr [col] = l.t [col]; |
1081 | wstr [col] = l.t [col]; |
719 | |
1082 | |
720 | char *str = rxvt_wcstoutf8 (wstr, THIS->ncol); |
1083 | XPUSHs (taint (sv_2mortal (wcs2sv (wstr, THIS->ncol)))); |
721 | free (wstr); |
|
|
722 | |
1084 | |
723 | SV *sv = newSVpv (str, 0); |
1085 | delete [] wstr; |
724 | SvUTF8_on (sv); |
|
|
725 | XPUSHs (sv_2mortal (sv)); |
|
|
726 | free (str); |
|
|
727 | } |
1086 | } |
728 | |
1087 | |
729 | if (new_text) |
1088 | if (new_text) |
730 | { |
1089 | { |
731 | wchar_t *wstr = sv2wcs (new_text); |
1090 | wchar_t *wstr = sv2wcs (new_text); |
732 | |
1091 | |
733 | int len = wcslen (wstr); |
1092 | int len = min (wcslen (wstr) - start_ofs, max_len); |
734 | |
1093 | |
735 | if (!IN_RANGE_INC (start_col, 0, THIS->ncol - len)) |
1094 | if (!IN_RANGE_INC (start_col, 0, THIS->ncol - len)) |
736 | { |
1095 | { |
737 | free (wstr); |
1096 | free (wstr); |
738 | croak ("new_text extends beyond horizontal margins"); |
1097 | croak ("new_text extends beyond horizontal margins"); |
739 | } |
1098 | } |
740 | |
1099 | |
741 | for (int col = start_col; col < start_col + len; col++) |
1100 | for (int col = start_col; col < start_col + len; col++) |
742 | { |
1101 | { |
743 | l.t [col] = wstr [col - start_col]; |
1102 | l.t [col] = wstr [start_ofs + col - start_col]; |
744 | l.r [col] = SET_FONT (l.r [col], THIS->fontset [GET_STYLE (l.r [col])]->find_font (l.t [col])); |
1103 | l.r [col] = SET_FONT (l.r [col], THIS->fontset [GET_STYLE (l.r [col])]->find_font (l.t [col])); |
745 | } |
1104 | } |
746 | |
1105 | |
747 | free (wstr); |
1106 | free (wstr); |
748 | } |
1107 | } |
749 | } |
1108 | } |
750 | |
1109 | |
751 | void |
1110 | void |
752 | rxvt_term::ROW_r (int row_number, SV *new_rend = 0, int start_col = 0) |
1111 | rxvt_term::ROW_r (int row_number, SV *new_rend = 0, int start_col = 0, int start_ofs = 0, int max_len = MAX_COLS) |
753 | PPCODE: |
1112 | PPCODE: |
754 | { |
1113 | { |
755 | if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) |
1114 | if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) |
756 | XSRETURN_EMPTY; |
1115 | XSRETURN_EMPTY; |
757 | |
1116 | |
… | |
… | |
772 | { |
1131 | { |
773 | if (!SvROK (new_rend) || SvTYPE (SvRV (new_rend)) != SVt_PVAV) |
1132 | if (!SvROK (new_rend) || SvTYPE (SvRV (new_rend)) != SVt_PVAV) |
774 | croak ("new_rend must be arrayref"); |
1133 | croak ("new_rend must be arrayref"); |
775 | |
1134 | |
776 | AV *av = (AV *)SvRV (new_rend); |
1135 | AV *av = (AV *)SvRV (new_rend); |
777 | int len = av_len (av) + 1; |
1136 | int len = min (av_len (av) + 1 - start_ofs, max_len); |
778 | |
1137 | |
779 | if (!IN_RANGE_INC (start_col, 0, THIS->ncol - len)) |
1138 | if (!IN_RANGE_INC (start_col, 0, THIS->ncol - len)) |
780 | croak ("new_rend array extends beyond horizontal margins"); |
1139 | croak ("new_rend array extends beyond horizontal margins"); |
781 | |
1140 | |
782 | for (int col = start_col; col < start_col + len; col++) |
1141 | for (int col = start_col; col < start_col + len; col++) |
783 | { |
1142 | { |
784 | rend_t r = SvIV (*av_fetch (av, col - start_col, 1)) & ~RS_fontMask; |
1143 | rend_t r = SvIV (*av_fetch (av, start_ofs + col - start_col, 1)) & ~RS_fontMask; |
785 | |
1144 | |
786 | l.r [col] = SET_FONT (r, THIS->fontset [GET_STYLE (r)]->find_font (l.t [col])); |
1145 | l.r [col] = SET_FONT (r, THIS->fontset [GET_STYLE (r)]->find_font (l.t [col])); |
787 | } |
1146 | } |
788 | } |
1147 | } |
789 | } |
1148 | } |
790 | |
1149 | |
791 | int |
1150 | int |
792 | rxvt_term::ROW_l (int row_number, int new_length = -2) |
1151 | rxvt_term::ROW_l (int row_number, int new_length = -1) |
793 | CODE: |
1152 | CODE: |
794 | { |
1153 | { |
795 | if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) |
1154 | if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) |
796 | XSRETURN_EMPTY; |
1155 | XSRETURN_EMPTY; |
797 | |
1156 | |
798 | line_t &l = ROW(row_number); |
1157 | line_t &l = ROW(row_number); |
799 | RETVAL = l.l < 0 ? THIS->ncol : l.l; |
1158 | RETVAL = l.l; |
800 | |
1159 | |
801 | if (new_length >= -1) |
1160 | if (new_length >= 0) |
802 | l.l = new_length; |
1161 | l.l = new_length; |
803 | } |
1162 | } |
804 | OUTPUT: |
1163 | OUTPUT: |
805 | RETVAL |
1164 | RETVAL |
806 | |
1165 | |
807 | bool |
1166 | bool |
808 | rxvt_term::ROW_is_longer (int row_number) |
1167 | rxvt_term::ROW_is_longer (int row_number, int new_is_longer = -1) |
809 | CODE: |
1168 | CODE: |
810 | { |
1169 | { |
811 | if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) |
1170 | if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) |
812 | XSRETURN_EMPTY; |
1171 | XSRETURN_EMPTY; |
813 | |
1172 | |
814 | line_t &l = ROW(row_number); |
1173 | line_t &l = ROW(row_number); |
815 | RETVAL = l.l < 0; |
1174 | RETVAL = l.is_longer (); |
|
|
1175 | |
|
|
1176 | if (new_is_longer >= 0) |
|
|
1177 | l.is_longer (new_is_longer); |
816 | } |
1178 | } |
817 | OUTPUT: |
1179 | OUTPUT: |
818 | RETVAL |
1180 | RETVAL |
819 | |
1181 | |
820 | SV * |
1182 | SV * |
821 | rxvt_term::special_encode (SV *str) |
1183 | rxvt_term::special_encode (SV *string) |
822 | CODE: |
1184 | CODE: |
823 | abort ();//TODO |
1185 | { |
|
|
1186 | wchar_t *wstr = sv2wcs (string); |
|
|
1187 | int wlen = wcslen (wstr); |
|
|
1188 | wchar_t *rstr = new wchar_t [wlen]; // cannot become longer |
|
|
1189 | |
|
|
1190 | rxvt_push_locale (THIS->locale); |
|
|
1191 | |
|
|
1192 | wchar_t *r = rstr; |
|
|
1193 | for (wchar_t *s = wstr; *s; s++) |
|
|
1194 | if (wcwidth (*s) == 0) |
|
|
1195 | { |
|
|
1196 | if (r == rstr) |
|
|
1197 | croak ("leading combining character unencodable"); |
|
|
1198 | |
|
|
1199 | unicode_t n = rxvt_compose (r[-1], *s); |
|
|
1200 | if (n == NOCHAR) |
|
|
1201 | n = rxvt_composite.compose (r[-1], *s); |
|
|
1202 | |
|
|
1203 | r[-1] = n; |
|
|
1204 | } |
|
|
1205 | #if !UNICODE_3 |
|
|
1206 | else if (*s >= 0x10000) |
|
|
1207 | *r++ = rxvt_composite.compose (*s); |
|
|
1208 | #endif |
|
|
1209 | else |
|
|
1210 | *r++ = *s; |
|
|
1211 | |
|
|
1212 | rxvt_pop_locale (); |
|
|
1213 | |
|
|
1214 | RETVAL = taint_if (wcs2sv (rstr, r - rstr), string); |
|
|
1215 | |
|
|
1216 | delete [] rstr; |
|
|
1217 | } |
|
|
1218 | OUTPUT: |
|
|
1219 | RETVAL |
824 | |
1220 | |
825 | SV * |
1221 | SV * |
826 | rxvt_term::special_decode (SV *str) |
1222 | rxvt_term::special_decode (SV *text) |
827 | CODE: |
1223 | CODE: |
828 | abort ();//TODO |
1224 | { |
|
|
1225 | wchar_t *wstr = sv2wcs (text); |
|
|
1226 | int wlen = wcslen (wstr); |
|
|
1227 | int dlen = 0; |
|
|
1228 | |
|
|
1229 | // find length |
|
|
1230 | for (wchar_t *s = wstr; *s; s++) |
|
|
1231 | if (*s == NOCHAR) |
|
|
1232 | ; |
|
|
1233 | else if (IS_COMPOSE (*s)) |
|
|
1234 | dlen += rxvt_composite.expand (*s, 0); |
|
|
1235 | else |
|
|
1236 | dlen++; |
|
|
1237 | |
|
|
1238 | wchar_t *rstr = new wchar_t [dlen]; |
|
|
1239 | |
|
|
1240 | // decode |
|
|
1241 | wchar_t *r = rstr; |
|
|
1242 | for (wchar_t *s = wstr; *s; s++) |
|
|
1243 | if (*s == NOCHAR) |
|
|
1244 | ; |
|
|
1245 | else if (IS_COMPOSE (*s)) |
|
|
1246 | r += rxvt_composite.expand (*s, r); |
|
|
1247 | else |
|
|
1248 | *r++ = *s; |
|
|
1249 | |
|
|
1250 | RETVAL = taint_if (wcs2sv (rstr, r - rstr), text); |
|
|
1251 | |
|
|
1252 | delete [] rstr; |
|
|
1253 | } |
|
|
1254 | OUTPUT: |
|
|
1255 | RETVAL |
829 | |
1256 | |
830 | void |
1257 | void |
831 | rxvt_term::_resource (char *name, int index, SV *newval = 0) |
1258 | rxvt_term::_resource (char *name, int index, SV *newval = 0) |
832 | PPCODE: |
1259 | PPCODE: |
833 | { |
1260 | { |
834 | struct resval { const char *name; int value; } rslist [] = { |
1261 | struct resval { const char *name; int value; } rslist [] = { |
835 | # define Rs_def(name) { # name, Rs_ ## name }, |
1262 | # define def(name) { # name, Rs_ ## name }, |
836 | # define Rs_reserve(name,count) |
1263 | # define reserve(name,count) |
837 | # include "rsinc.h" |
1264 | # include "rsinc.h" |
838 | # undef Rs_def |
1265 | # undef def |
839 | # undef Rs_reserve |
1266 | # undef reserve |
840 | }; |
1267 | }; |
841 | |
1268 | |
842 | struct resval *rs = rslist + sizeof (rslist) / sizeof (rslist [0]); |
1269 | struct resval *rs = rslist + sizeof (rslist) / sizeof (rslist [0]); |
843 | |
1270 | |
844 | do { |
1271 | do { |
… | |
… | |
850 | |
1277 | |
851 | if (!IN_RANGE_EXC (index, 0, NUM_RESOURCES)) |
1278 | if (!IN_RANGE_EXC (index, 0, NUM_RESOURCES)) |
852 | croak ("requested out-of-bound resource %s+%d,", name, index - rs->value); |
1279 | croak ("requested out-of-bound resource %s+%d,", name, index - rs->value); |
853 | |
1280 | |
854 | if (GIMME_V != G_VOID) |
1281 | if (GIMME_V != G_VOID) |
855 | XPUSHs (THIS->rs [index] ? sv_2mortal (newSVpv (THIS->rs [index], 0)) : &PL_sv_undef); |
1282 | XPUSHs (THIS->rs [index] ? sv_2mortal (taint (newSVpv (THIS->rs [index], 0))) : &PL_sv_undef); |
856 | |
1283 | |
857 | if (newval) |
1284 | if (newval) |
858 | { |
1285 | { |
859 | if (SvOK (newval)) |
1286 | if (SvOK (newval)) |
860 | { |
1287 | { |
… | |
… | |
865 | else |
1292 | else |
866 | THIS->rs [index] = 0; |
1293 | THIS->rs [index] = 0; |
867 | } |
1294 | } |
868 | } |
1295 | } |
869 | |
1296 | |
|
|
1297 | const char * |
|
|
1298 | rxvt_term::x_resource (const char *name) |
|
|
1299 | CLEANUP: |
|
|
1300 | SvTAINTED_on (ST (0)); |
|
|
1301 | |
|
|
1302 | bool |
|
|
1303 | rxvt_term::option (U32 optval, int set = -1) |
|
|
1304 | CODE: |
|
|
1305 | { |
|
|
1306 | RETVAL = THIS->options & optval; |
|
|
1307 | |
|
|
1308 | if (set >= 0) |
|
|
1309 | { |
|
|
1310 | if (set) |
|
|
1311 | THIS->options |= optval; |
|
|
1312 | else |
|
|
1313 | THIS->options &= ~optval; |
|
|
1314 | |
|
|
1315 | switch (optval) |
|
|
1316 | { |
|
|
1317 | case Opt_skipBuiltinGlyphs: |
|
|
1318 | THIS->set_fonts (); |
|
|
1319 | THIS->scr_remap_chars (); |
|
|
1320 | THIS->scr_touch (true); |
|
|
1321 | THIS->want_refresh = 1; |
|
|
1322 | break; |
|
|
1323 | |
|
|
1324 | case Opt_cursorUnderline: |
|
|
1325 | THIS->want_refresh = 1; |
|
|
1326 | break; |
|
|
1327 | |
|
|
1328 | # case Opt_scrollBar_floating: |
|
|
1329 | # case Opt_scrollBar_right: |
|
|
1330 | # THIS->resize_all_windows (THIS->width, THIS->height, 1); |
|
|
1331 | # break; |
|
|
1332 | } |
|
|
1333 | } |
|
|
1334 | } |
|
|
1335 | OUTPUT: |
|
|
1336 | RETVAL |
|
|
1337 | |
|
|
1338 | bool |
|
|
1339 | rxvt_term::parse_keysym (char *keysym, char *str) |
|
|
1340 | CODE: |
|
|
1341 | RETVAL = 0 < THIS->parse_keysym (keysym, str); |
|
|
1342 | THIS->keyboard->register_done (); |
|
|
1343 | OUTPUT: |
|
|
1344 | RETVAL |
|
|
1345 | |
870 | void |
1346 | void |
871 | rxvt_term::selection_mark (...) |
1347 | rxvt_term::screen_cur (...) |
872 | PROTOTYPE: $;$$ |
1348 | PROTOTYPE: $;$$ |
873 | ALIAS: |
1349 | ALIAS: |
|
|
1350 | screen_cur = 0 |
874 | selection_beg = 1 |
1351 | selection_beg = 1 |
875 | selection_end = 2 |
1352 | selection_end = 2 |
|
|
1353 | selection_mark = 3 |
876 | PPCODE: |
1354 | PPCODE: |
877 | { |
1355 | { |
878 | row_col_t &sel = ix == 1 ? THIS->selection.beg |
1356 | row_col_t &rc = ix == 0 ? THIS->screen.cur |
|
|
1357 | : ix == 1 ? THIS->selection.beg |
879 | : ix == 2 ? THIS->selection.end |
1358 | : ix == 2 ? THIS->selection.end |
880 | : THIS->selection.mark; |
1359 | : THIS->selection.mark; |
881 | |
1360 | |
882 | if (GIMME_V != G_VOID) |
1361 | if (GIMME_V != G_VOID) |
883 | { |
1362 | { |
884 | EXTEND (SP, 2); |
1363 | EXTEND (SP, 2); |
885 | PUSHs (sv_2mortal (newSViv (sel.row))); |
1364 | PUSHs (sv_2mortal (newSViv (rc.row))); |
886 | PUSHs (sv_2mortal (newSViv (sel.col))); |
1365 | PUSHs (sv_2mortal (newSViv (rc.col))); |
887 | } |
1366 | } |
888 | |
1367 | |
889 | if (items == 3) |
1368 | if (items == 3) |
890 | { |
1369 | { |
891 | sel.row = clamp (SvIV (ST (1)), -THIS->nsaved, THIS->nrow - 1); |
1370 | rc.row = clamp (SvIV (ST (1)), -THIS->nsaved, THIS->nrow - 1); |
892 | sel.col = clamp (SvIV (ST (2)), 0, THIS->ncol - 1); |
1371 | rc.col = clamp (SvIV (ST (2)), 0, THIS->ncol - 1); |
893 | |
1372 | |
894 | if (ix) |
1373 | if (ix) |
895 | THIS->want_refresh = 1; |
1374 | THIS->want_refresh = 1; |
896 | } |
1375 | } |
897 | } |
1376 | } |
898 | |
1377 | |
|
|
1378 | char |
|
|
1379 | rxvt_term::cur_charset () |
|
|
1380 | CODE: |
|
|
1381 | RETVAL = THIS->charsets [THIS->screen.charset]; |
|
|
1382 | OUTPUT: |
|
|
1383 | RETVAL |
|
|
1384 | |
899 | int |
1385 | int |
900 | rxvt_term::selection_grab (int eventtime = CurrentTime) |
1386 | rxvt_term::selection_grab (U32 eventtime) |
901 | |
1387 | |
902 | void |
1388 | void |
903 | rxvt_term::selection (SV *newtext = 0) |
1389 | rxvt_term::selection (SV *newtext = 0) |
904 | PPCODE: |
1390 | PPCODE: |
905 | { |
1391 | { |
906 | if (GIMME_V != G_VOID) |
1392 | if (GIMME_V != G_VOID) |
907 | { |
1393 | XPUSHs (THIS->selection.text |
908 | char *sel = rxvt_wcstoutf8 (THIS->selection.text, THIS->selection.len); |
1394 | ? taint (sv_2mortal (wcs2sv (THIS->selection.text, THIS->selection.len))) |
909 | SV *sv = newSVpv (sel, 0); |
1395 | : &PL_sv_undef); |
910 | SvUTF8_on (sv); |
|
|
911 | free (sel); |
|
|
912 | XPUSHs (sv_2mortal (sv)); |
|
|
913 | } |
|
|
914 | |
1396 | |
915 | if (newtext) |
1397 | if (newtext) |
916 | { |
1398 | { |
917 | free (THIS->selection.text); |
1399 | free (THIS->selection.text); |
918 | |
1400 | |
919 | THIS->selection.text = sv2wcs (newtext); |
1401 | THIS->selection.text = sv2wcs (newtext); |
920 | THIS->selection.len = wcslen (THIS->selection.text); |
1402 | THIS->selection.len = wcslen (THIS->selection.text); |
921 | } |
1403 | } |
922 | } |
1404 | } |
923 | |
1405 | |
|
|
1406 | void |
|
|
1407 | rxvt_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) |
|
|
1408 | |
|
|
1409 | void |
|
|
1410 | rxvt_term::scr_xor_span (int beg_row, int beg_col, int end_row, int end_col, U32 rstyle = RS_RVid) |
|
|
1411 | |
|
|
1412 | void |
|
|
1413 | rxvt_term::scr_bell () |
|
|
1414 | |
|
|
1415 | void |
|
|
1416 | rxvt_term::scr_add_lines (SV *string) |
|
|
1417 | CODE: |
|
|
1418 | { |
|
|
1419 | wchar_t *wstr = sv2wcs (string); |
|
|
1420 | THIS->scr_add_lines (wstr, wcslen (wstr)); |
|
|
1421 | free (wstr); |
|
|
1422 | } |
|
|
1423 | |
924 | void |
1424 | void |
925 | rxvt_term::tt_write (SV *octets) |
1425 | rxvt_term::tt_write (SV *octets) |
926 | INIT: |
1426 | INIT: |
927 | STRLEN len; |
1427 | STRLEN len; |
928 | char *str = SvPVbyte (octets, len); |
1428 | char *str = SvPVbyte (octets, len); |
929 | C_ARGS: |
1429 | C_ARGS: |
930 | (unsigned char *)str, len |
1430 | str, len |
|
|
1431 | |
|
|
1432 | void |
|
|
1433 | rxvt_term::cmd_parse (SV *octets) |
|
|
1434 | CODE: |
|
|
1435 | { |
|
|
1436 | STRLEN len; |
|
|
1437 | char *str = SvPVbyte (octets, len); |
|
|
1438 | |
|
|
1439 | char *old_cmdbuf_ptr = THIS->cmdbuf_ptr; |
|
|
1440 | char *old_cmdbuf_endp = THIS->cmdbuf_endp; |
|
|
1441 | |
|
|
1442 | THIS->cmdbuf_ptr = str; |
|
|
1443 | THIS->cmdbuf_endp = str + len; |
|
|
1444 | |
|
|
1445 | rxvt_push_locale (THIS->locale); |
|
|
1446 | THIS->cmd_parse (); |
|
|
1447 | rxvt_pop_locale (); |
|
|
1448 | |
|
|
1449 | THIS->cmdbuf_ptr = old_cmdbuf_ptr; |
|
|
1450 | THIS->cmdbuf_endp = old_cmdbuf_endp; |
|
|
1451 | } |
931 | |
1452 | |
932 | SV * |
1453 | SV * |
933 | rxvt_term::overlay (int x, int y, int w, int h, int rstyle = OVERLAY_RSTYLE, int border = 2) |
1454 | rxvt_term::overlay (int x, int y, int w, int h, int rstyle = OVERLAY_RSTYLE, int border = 2) |
934 | CODE: |
1455 | CODE: |
935 | { |
1456 | { |