… | |
… | |
39 | #include "rxvtutil.h" |
39 | #include "rxvtutil.h" |
40 | #include "rxvtperl.h" |
40 | #include "rxvtperl.h" |
41 | |
41 | |
42 | #include "perlxsi.c" |
42 | #include "perlxsi.c" |
43 | |
43 | |
44 | #if defined(HAVE_SCROLLBARS) || defined(MENUBAR) |
44 | #ifdef HAVE_SCROLLBARS |
45 | # define GRAB_CURSOR THIS->leftptr_cursor |
45 | # define GRAB_CURSOR THIS->leftptr_cursor |
46 | #else |
46 | #else |
47 | # define GRAB_CURSOR None |
47 | # define GRAB_CURSOR None |
48 | #endif |
48 | #endif |
49 | |
49 | |
… | |
… | |
53 | #define ROW(n) THIS->row_buf [LINENO (n)] |
53 | #define ROW(n) THIS->row_buf [LINENO (n)] |
54 | |
54 | |
55 | #define ENABLE_PERL_FRILLS 1 |
55 | #define ENABLE_PERL_FRILLS 1 |
56 | |
56 | |
57 | ///////////////////////////////////////////////////////////////////////////// |
57 | ///////////////////////////////////////////////////////////////////////////// |
58 | |
|
|
59 | static SV * |
|
|
60 | taint (SV *sv) |
|
|
61 | { |
|
|
62 | SvTAINT (sv); |
|
|
63 | return sv; |
|
|
64 | } |
|
|
65 | |
|
|
66 | static SV * |
|
|
67 | taint_if (SV *sv, SV *src) |
|
|
68 | { |
|
|
69 | if (SvTAINTED (src)) |
|
|
70 | SvTAINT (sv); |
|
|
71 | |
|
|
72 | return sv; |
|
|
73 | } |
|
|
74 | |
58 | |
75 | static wchar_t * |
59 | static wchar_t * |
76 | sv2wcs (SV *sv) |
60 | sv2wcs (SV *sv) |
77 | { |
61 | { |
78 | STRLEN len; |
62 | STRLEN len; |
… | |
… | |
418 | perl_environ = rxvt_environ; |
402 | perl_environ = rxvt_environ; |
419 | swap (perl_environ, environ); |
403 | swap (perl_environ, environ); |
420 | |
404 | |
421 | char *argv[] = { |
405 | char *argv[] = { |
422 | "", |
406 | "", |
423 | "-T", |
407 | "-e" |
424 | "-edo '" LIBDIR "/urxvt.pm' or ($@ and die $@) or exit 1", |
408 | "BEGIN {" |
|
|
409 | " urxvt->bootstrap;" |
|
|
410 | " unshift @INC, '" LIBDIR "';" |
|
|
411 | "}" |
|
|
412 | "" |
|
|
413 | "use urxvt;" |
425 | }; |
414 | }; |
426 | |
415 | |
427 | perl = perl_alloc (); |
416 | perl = perl_alloc (); |
428 | perl_construct (perl); |
417 | perl_construct (perl); |
429 | |
418 | |
430 | if (perl_parse (perl, xs_init, 3, argv, (char **)NULL) |
419 | if (perl_parse (perl, xs_init, 2, argv, (char **)NULL) |
431 | || perl_run (perl)) |
420 | || perl_run (perl)) |
432 | { |
421 | { |
433 | rxvt_warn ("unable to initialize perl-interpreter, continuing without.\n"); |
422 | rxvt_warn ("unable to initialize perl-interpreter, continuing without.\n"); |
434 | |
423 | |
435 | perl_destruct (perl); |
424 | perl_destruct (perl); |
… | |
… | |
440 | swap (perl_environ, environ); |
429 | swap (perl_environ, environ); |
441 | |
430 | |
442 | rxvt_pop_locale (); |
431 | rxvt_pop_locale (); |
443 | } |
432 | } |
444 | |
433 | |
|
|
434 | if (perl) |
|
|
435 | { |
445 | // runs outside of perls ENV |
436 | // runs outside of perls ENV |
446 | term->perl.self = (void *)newSVptr ((void *)term, "urxvt::term"); |
437 | term->perl.self = (void *)newSVptr ((void *)term, "urxvt::term"); |
447 | hv_store ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, newRV_noinc ((SV *)newHV ()), 0); |
438 | hv_store ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, newRV_noinc ((SV *)newHV ()), 0); |
|
|
439 | } |
448 | } |
440 | } |
449 | |
441 | |
450 | static void |
442 | static void |
451 | ungrab (rxvt_term *THIS) |
443 | ungrab (rxvt_term *THIS) |
452 | { |
444 | { |
… | |
… | |
515 | case DT_LONG: |
507 | case DT_LONG: |
516 | XPUSHs (sv_2mortal (newSViv (va_arg (ap, long)))); |
508 | XPUSHs (sv_2mortal (newSViv (va_arg (ap, long)))); |
517 | break; |
509 | break; |
518 | |
510 | |
519 | case DT_STR: |
511 | case DT_STR: |
520 | XPUSHs (taint (sv_2mortal (newSVpv (va_arg (ap, char *), 0)))); |
512 | XPUSHs (sv_2mortal (newSVpv (va_arg (ap, char *), 0))); |
521 | break; |
513 | break; |
522 | |
514 | |
523 | case DT_STR_LEN: |
515 | case DT_STR_LEN: |
524 | { |
516 | { |
525 | char *str = va_arg (ap, char *); |
517 | char *str = va_arg (ap, char *); |
526 | int len = va_arg (ap, int); |
518 | int len = va_arg (ap, int); |
527 | |
519 | |
528 | XPUSHs (taint (sv_2mortal (newSVpvn (str, len)))); |
520 | XPUSHs (sv_2mortal (newSVpvn (str, len))); |
529 | } |
521 | } |
530 | break; |
522 | break; |
531 | |
523 | |
532 | case DT_WCS_LEN: |
524 | case DT_WCS_LEN: |
533 | { |
525 | { |
534 | wchar_t *wstr = va_arg (ap, wchar_t *); |
526 | wchar_t *wstr = va_arg (ap, wchar_t *); |
535 | int wlen = va_arg (ap, int); |
527 | int wlen = va_arg (ap, int); |
536 | |
528 | |
537 | XPUSHs (taint (sv_2mortal (wcs2sv (wstr, wlen)))); |
529 | XPUSHs (sv_2mortal (wcs2sv (wstr, wlen))); |
538 | } |
530 | } |
539 | break; |
531 | break; |
540 | |
532 | |
541 | case DT_XEVENT: |
533 | case DT_XEVENT: |
542 | { |
534 | { |
543 | XEvent *xe = va_arg (ap, XEvent *); |
535 | XEvent *xe = va_arg (ap, XEvent *); |
544 | HV *hv = newHV (); |
536 | HV *hv = newHV (); |
545 | |
537 | |
546 | # define set(name, sv) hv_store (hv, # name, sizeof (# name) - 1, sv, 0) |
538 | # define set(name, sv) hv_store (hv, # name, sizeof (# name) - 1, sv, 0) |
547 | # define setiv(name, val) hv_store (hv, # name, sizeof (# name) - 1, newSViv (val), 0) |
539 | # define setiv(name, val) hv_store (hv, # name, sizeof (# name) - 1, newSViv (val), 0) |
|
|
540 | # define setuv(name, val) hv_store (hv, # name, sizeof (# name) - 1, newSVuv (val), 0) |
548 | # undef set |
541 | # undef set |
549 | |
542 | |
550 | setiv (type, xe->type); |
543 | setiv (type, xe->type); |
551 | setiv (send_event, xe->xany.send_event); |
544 | setiv (send_event, xe->xany.send_event); |
552 | setiv (serial, xe->xany.serial); |
545 | setiv (serial, xe->xany.serial); |
… | |
… | |
556 | case KeyPress: |
549 | case KeyPress: |
557 | case KeyRelease: |
550 | case KeyRelease: |
558 | case ButtonPress: |
551 | case ButtonPress: |
559 | case ButtonRelease: |
552 | case ButtonRelease: |
560 | case MotionNotify: |
553 | case MotionNotify: |
|
|
554 | setuv (window, xe->xmotion.window); |
|
|
555 | setuv (root, xe->xmotion.root); |
|
|
556 | setuv (subwindow, xe->xmotion.subwindow); |
561 | setiv (time, xe->xmotion.time); |
557 | setuv (time, xe->xmotion.time); |
562 | setiv (x, xe->xmotion.x); |
558 | setiv (x, xe->xmotion.x); |
563 | setiv (y, xe->xmotion.y); |
559 | setiv (y, xe->xmotion.y); |
564 | setiv (row, xe->xmotion.y / term->fheight); |
560 | setiv (row, xe->xmotion.y / term->fheight); |
565 | setiv (col, xe->xmotion.x / term->fwidth); |
561 | setiv (col, xe->xmotion.x / term->fwidth); |
566 | setiv (x_root, xe->xmotion.x_root); |
562 | setiv (x_root, xe->xmotion.x_root); |
567 | setiv (y_root, xe->xmotion.y_root); |
563 | setiv (y_root, xe->xmotion.y_root); |
568 | setiv (state, xe->xmotion.state); |
564 | setuv (state, xe->xmotion.state); |
|
|
565 | |
|
|
566 | switch (xe->type) |
|
|
567 | { |
|
|
568 | case KeyPress: |
|
|
569 | case KeyRelease: |
|
|
570 | setuv (keycode, xe->xkey.keycode); |
|
|
571 | break; |
|
|
572 | |
|
|
573 | case ButtonPress: |
|
|
574 | case ButtonRelease: |
|
|
575 | setuv (button, xe->xbutton.button); |
|
|
576 | break; |
|
|
577 | |
|
|
578 | case MotionNotify: |
|
|
579 | setiv (is_hint, xe->xmotion.is_hint); |
|
|
580 | break; |
|
|
581 | } |
|
|
582 | |
569 | break; |
583 | break; |
570 | } |
|
|
571 | |
584 | |
|
|
585 | case MapNotify: |
|
|
586 | case UnmapNotify: |
|
|
587 | case ConfigureNotify: |
|
|
588 | setuv (event, xe->xconfigure.event); |
|
|
589 | setuv (window, xe->xconfigure.window); |
|
|
590 | |
572 | switch (xe->type) |
591 | switch (xe->type) |
573 | { |
592 | { |
574 | case KeyPress: |
593 | case ConfigureNotify: |
575 | case KeyRelease: |
594 | setiv (x, xe->xconfigure.x); |
576 | setiv (keycode, xe->xkey.keycode); |
595 | setiv (y, xe->xconfigure.y); |
|
|
596 | setiv (width, xe->xconfigure.width); |
|
|
597 | setiv (height, xe->xconfigure.height); |
|
|
598 | setuv (above, xe->xconfigure.above); |
577 | break; |
599 | break; |
578 | |
|
|
579 | case ButtonPress: |
|
|
580 | case ButtonRelease: |
|
|
581 | setiv (button, xe->xbutton.button); |
|
|
582 | break; |
600 | } |
583 | |
601 | |
584 | case MotionNotify: |
|
|
585 | setiv (is_hint, xe->xmotion.is_hint); |
|
|
586 | break; |
602 | break; |
587 | } |
603 | } |
588 | |
604 | |
589 | XPUSHs (sv_2mortal (newRV_noinc ((SV *)hv))); |
605 | XPUSHs (sv_2mortal (newRV_noinc ((SV *)hv))); |
590 | } |
606 | } |
… | |
… | |
779 | void |
795 | void |
780 | fatal (const char *msg) |
796 | fatal (const char *msg) |
781 | CODE: |
797 | CODE: |
782 | rxvt_fatal ("%s", msg); |
798 | rxvt_fatal ("%s", msg); |
783 | |
799 | |
784 | SV * |
|
|
785 | untaint (SV *sv) |
|
|
786 | CODE: |
|
|
787 | RETVAL = newSVsv (sv); |
|
|
788 | SvTAINTED_off (RETVAL); |
|
|
789 | OUTPUT: |
|
|
790 | RETVAL |
|
|
791 | |
|
|
792 | void |
800 | void |
793 | _exit (int status) |
801 | _exit (int status) |
794 | |
|
|
795 | bool |
|
|
796 | safe () |
|
|
797 | CODE: |
|
|
798 | RETVAL = !rxvt_tainted (); |
|
|
799 | OUTPUT: |
|
|
800 | RETVAL |
|
|
801 | |
802 | |
802 | NV |
803 | NV |
803 | NOW () |
804 | NOW () |
804 | CODE: |
805 | CODE: |
805 | RETVAL = NOW; |
806 | RETVAL = NOW; |
… | |
… | |
1071 | char *mbstr = rxvt_wcstombs (wstr); |
1072 | char *mbstr = rxvt_wcstombs (wstr); |
1072 | rxvt_pop_locale (); |
1073 | rxvt_pop_locale (); |
1073 | |
1074 | |
1074 | free (wstr); |
1075 | free (wstr); |
1075 | |
1076 | |
1076 | RETVAL = taint_if (newSVpv (mbstr, 0), str); |
1077 | RETVAL = newSVpv (mbstr, 0); |
1077 | free (mbstr); |
1078 | free (mbstr); |
1078 | } |
1079 | } |
1079 | OUTPUT: |
1080 | OUTPUT: |
1080 | RETVAL |
1081 | RETVAL |
1081 | |
1082 | |
… | |
… | |
1088 | |
1089 | |
1089 | rxvt_push_locale (THIS->locale); |
1090 | rxvt_push_locale (THIS->locale); |
1090 | wchar_t *wstr = rxvt_mbstowcs (data, len); |
1091 | wchar_t *wstr = rxvt_mbstowcs (data, len); |
1091 | rxvt_pop_locale (); |
1092 | rxvt_pop_locale (); |
1092 | |
1093 | |
1093 | RETVAL = taint_if (wcs2sv (wstr), octets); |
1094 | RETVAL = wcs2sv (wstr); |
1094 | free (wstr); |
1095 | free (wstr); |
1095 | } |
1096 | } |
1096 | OUTPUT: |
1097 | OUTPUT: |
1097 | RETVAL |
1098 | RETVAL |
1098 | |
1099 | |
… | |
… | |
1250 | wchar_t *wstr = new wchar_t [THIS->ncol]; |
1251 | wchar_t *wstr = new wchar_t [THIS->ncol]; |
1251 | |
1252 | |
1252 | for (int col = 0; col < THIS->ncol; col++) |
1253 | for (int col = 0; col < THIS->ncol; col++) |
1253 | wstr [col] = l.t [col]; |
1254 | wstr [col] = l.t [col]; |
1254 | |
1255 | |
1255 | XPUSHs (taint (sv_2mortal (wcs2sv (wstr, THIS->ncol)))); |
1256 | XPUSHs (sv_2mortal (wcs2sv (wstr, THIS->ncol))); |
1256 | |
1257 | |
1257 | delete [] wstr; |
1258 | delete [] wstr; |
1258 | } |
1259 | } |
1259 | |
1260 | |
1260 | if (new_text) |
1261 | if (new_text) |
… | |
… | |
1381 | else |
1382 | else |
1382 | *r++ = *s; |
1383 | *r++ = *s; |
1383 | |
1384 | |
1384 | rxvt_pop_locale (); |
1385 | rxvt_pop_locale (); |
1385 | |
1386 | |
1386 | RETVAL = taint_if (wcs2sv (rstr, r - rstr), string); |
1387 | RETVAL = wcs2sv (rstr, r - rstr); |
1387 | |
1388 | |
1388 | delete [] rstr; |
1389 | delete [] rstr; |
1389 | } |
1390 | } |
1390 | OUTPUT: |
1391 | OUTPUT: |
1391 | RETVAL |
1392 | RETVAL |
… | |
… | |
1417 | else if (IS_COMPOSE (*s)) |
1418 | else if (IS_COMPOSE (*s)) |
1418 | r += rxvt_composite.expand (*s, r); |
1419 | r += rxvt_composite.expand (*s, r); |
1419 | else |
1420 | else |
1420 | *r++ = *s; |
1421 | *r++ = *s; |
1421 | |
1422 | |
1422 | RETVAL = taint_if (wcs2sv (rstr, r - rstr), text); |
1423 | RETVAL = wcs2sv (rstr, r - rstr); |
1423 | |
1424 | |
1424 | delete [] rstr; |
1425 | delete [] rstr; |
1425 | } |
1426 | } |
1426 | OUTPUT: |
1427 | OUTPUT: |
1427 | RETVAL |
1428 | RETVAL |
… | |
… | |
1449 | |
1450 | |
1450 | if (!IN_RANGE_EXC (index, 0, NUM_RESOURCES)) |
1451 | if (!IN_RANGE_EXC (index, 0, NUM_RESOURCES)) |
1451 | croak ("requested out-of-bound resource %s+%d,", name, index - rs->value); |
1452 | croak ("requested out-of-bound resource %s+%d,", name, index - rs->value); |
1452 | |
1453 | |
1453 | if (GIMME_V != G_VOID) |
1454 | if (GIMME_V != G_VOID) |
1454 | XPUSHs (THIS->rs [index] ? sv_2mortal (taint (newSVpv (THIS->rs [index], 0))) : &PL_sv_undef); |
1455 | XPUSHs (THIS->rs [index] ? sv_2mortal (newSVpv (THIS->rs [index], 0)) : &PL_sv_undef); |
1455 | |
1456 | |
1456 | if (newval) |
1457 | if (newval) |
1457 | { |
1458 | { |
1458 | if (SvOK (newval)) |
1459 | if (SvOK (newval)) |
1459 | { |
1460 | { |
… | |
… | |
1466 | } |
1467 | } |
1467 | } |
1468 | } |
1468 | |
1469 | |
1469 | const char * |
1470 | const char * |
1470 | rxvt_term::x_resource (const char *name) |
1471 | rxvt_term::x_resource (const char *name) |
1471 | CLEANUP: |
|
|
1472 | SvTAINTED_on (ST (0)); |
|
|
1473 | |
1472 | |
1474 | bool |
1473 | bool |
1475 | rxvt_term::option (U32 optval, int set = -1) |
1474 | rxvt_term::option (U32 optval, int set = -1) |
1476 | CODE: |
1475 | CODE: |
1477 | { |
1476 | { |
… | |
… | |
1537 | PUSHs (sv_2mortal (newSViv (rc.col))); |
1536 | PUSHs (sv_2mortal (newSViv (rc.col))); |
1538 | } |
1537 | } |
1539 | |
1538 | |
1540 | if (items == 3) |
1539 | if (items == 3) |
1541 | { |
1540 | { |
|
|
1541 | rc.row = SvIV (ST (1)); |
|
|
1542 | rc.col = SvIV (ST (2)); |
|
|
1543 | |
|
|
1544 | if (ix == 2 && rc.col == 0) |
|
|
1545 | { |
|
|
1546 | rc.row--; |
|
|
1547 | rc.col = THIS->ncol; |
|
|
1548 | } |
|
|
1549 | |
|
|
1550 | clamp_it (rc.col, 0, THIS->ncol); |
1542 | rc.row = clamp (SvIV (ST (1)), THIS->top_row, THIS->nrow - 1); |
1551 | clamp_it (rc.row, THIS->top_row, THIS->nrow - 1); |
1543 | rc.col = clamp (SvIV (ST (2)), 0, THIS->ncol - 1); |
|
|
1544 | |
1552 | |
1545 | if (ix) |
1553 | if (ix) |
1546 | THIS->want_refresh = 1; |
1554 | THIS->want_refresh = 1; |
1547 | } |
1555 | } |
1548 | } |
1556 | } |
… | |
… | |
1571 | rxvt_term::selection (SV *newtext = 0) |
1579 | rxvt_term::selection (SV *newtext = 0) |
1572 | PPCODE: |
1580 | PPCODE: |
1573 | { |
1581 | { |
1574 | if (GIMME_V != G_VOID) |
1582 | if (GIMME_V != G_VOID) |
1575 | XPUSHs (THIS->selection.text |
1583 | XPUSHs (THIS->selection.text |
1576 | ? taint (sv_2mortal (wcs2sv (THIS->selection.text, THIS->selection.len))) |
1584 | ? sv_2mortal (wcs2sv (THIS->selection.text, THIS->selection.len)) |
1577 | : &PL_sv_undef); |
1585 | : &PL_sv_undef); |
1578 | |
1586 | |
1579 | if (newtext) |
1587 | if (newtext) |
1580 | { |
1588 | { |
1581 | free (THIS->selection.text); |
1589 | free (THIS->selection.text); |