ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/rxvtperl.xs
(Generate patch)

Comparing rxvt-unicode/src/rxvtperl.xs (file contents):
Revision 1.70 by root, Tue Jan 17 09:34:21 2006 UTC vs.
Revision 1.75 by root, Wed Jan 18 11:05:09 2006 UTC

54 54
55#define ENABLE_PERL_FRILLS 1 55#define ENABLE_PERL_FRILLS 1
56 56
57///////////////////////////////////////////////////////////////////////////// 57/////////////////////////////////////////////////////////////////////////////
58 58
59static SV *
60taint (SV *sv)
61{
62 SvTAINT (sv);
63 return sv;
64}
65
66static SV *
67taint_if (SV *sv, SV *src)
68{
69 if (SvTAINTED (src))
70 SvTAINT (sv);
71
72 return sv;
73}
74
75static wchar_t * 59static wchar_t *
76sv2wcs (SV *sv) 60sv2wcs (SV *sv)
77{ 61{
78 STRLEN len; 62 STRLEN len;
79 char *str = SvPVutf8 (sv, len); 63 char *str = SvPVutf8 (sv, 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);
518 case DT_LONG: 507 case DT_LONG:
519 XPUSHs (sv_2mortal (newSViv (va_arg (ap, long)))); 508 XPUSHs (sv_2mortal (newSViv (va_arg (ap, long))));
520 break; 509 break;
521 510
522 case DT_STR: 511 case DT_STR:
523 XPUSHs (taint (sv_2mortal (newSVpv (va_arg (ap, char *), 0)))); 512 XPUSHs (sv_2mortal (newSVpv (va_arg (ap, char *), 0)));
524 break; 513 break;
525 514
526 case DT_STR_LEN: 515 case DT_STR_LEN:
527 { 516 {
528 char *str = va_arg (ap, char *); 517 char *str = va_arg (ap, char *);
529 int len = va_arg (ap, int); 518 int len = va_arg (ap, int);
530 519
531 XPUSHs (taint (sv_2mortal (newSVpvn (str, len)))); 520 XPUSHs (sv_2mortal (newSVpvn (str, len)));
532 } 521 }
533 break; 522 break;
534 523
535 case DT_WCS_LEN: 524 case DT_WCS_LEN:
536 { 525 {
537 wchar_t *wstr = va_arg (ap, wchar_t *); 526 wchar_t *wstr = va_arg (ap, wchar_t *);
538 int wlen = va_arg (ap, int); 527 int wlen = va_arg (ap, int);
539 528
540 XPUSHs (taint (sv_2mortal (wcs2sv (wstr, wlen)))); 529 XPUSHs (sv_2mortal (wcs2sv (wstr, wlen)));
541 } 530 }
542 break; 531 break;
543 532
544 case DT_XEVENT: 533 case DT_XEVENT:
545 { 534 {
546 XEvent *xe = va_arg (ap, XEvent *); 535 XEvent *xe = va_arg (ap, XEvent *);
547 HV *hv = newHV (); 536 HV *hv = newHV ();
548 537
549# 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)
550# 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)
551# undef set 541# undef set
552 542
553 setiv (type, xe->type); 543 setiv (type, xe->type);
554 setiv (send_event, xe->xany.send_event); 544 setiv (send_event, xe->xany.send_event);
555 setiv (serial, xe->xany.serial); 545 setiv (serial, xe->xany.serial);
559 case KeyPress: 549 case KeyPress:
560 case KeyRelease: 550 case KeyRelease:
561 case ButtonPress: 551 case ButtonPress:
562 case ButtonRelease: 552 case ButtonRelease:
563 case MotionNotify: 553 case MotionNotify:
554 setuv (window, xe->xmotion.window);
555 setuv (root, xe->xmotion.root);
556 setuv (subwindow, xe->xmotion.subwindow);
564 setiv (time, xe->xmotion.time); 557 setuv (time, xe->xmotion.time);
565 setiv (x, xe->xmotion.x); 558 setiv (x, xe->xmotion.x);
566 setiv (y, xe->xmotion.y); 559 setiv (y, xe->xmotion.y);
567 setiv (row, xe->xmotion.y / term->fheight); 560 setiv (row, xe->xmotion.y / term->fheight);
568 setiv (col, xe->xmotion.x / term->fwidth); 561 setiv (col, xe->xmotion.x / term->fwidth);
569 setiv (x_root, xe->xmotion.x_root); 562 setiv (x_root, xe->xmotion.x_root);
570 setiv (y_root, xe->xmotion.y_root); 563 setiv (y_root, xe->xmotion.y_root);
571 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
572 break; 583 break;
573 }
574 584
585 case MapNotify:
586 case UnmapNotify:
587 case ConfigureNotify:
588 setuv (event, xe->xconfigure.event);
589 setuv (window, xe->xconfigure.window);
590
575 switch (xe->type) 591 switch (xe->type)
576 { 592 {
577 case KeyPress: 593 case ConfigureNotify:
578 case KeyRelease: 594 setiv (x, xe->xconfigure.x);
579 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);
580 break; 599 break;
581
582 case ButtonPress:
583 case ButtonRelease:
584 setiv (button, xe->xbutton.button);
585 break; 600 }
586 601
587 case MotionNotify:
588 setiv (is_hint, xe->xmotion.is_hint);
589 break; 602 break;
590 } 603 }
591 604
592 XPUSHs (sv_2mortal (newRV_noinc ((SV *)hv))); 605 XPUSHs (sv_2mortal (newRV_noinc ((SV *)hv)));
593 } 606 }
782void 795void
783fatal (const char *msg) 796fatal (const char *msg)
784 CODE: 797 CODE:
785 rxvt_fatal ("%s", msg); 798 rxvt_fatal ("%s", msg);
786 799
787SV *
788untaint (SV *sv)
789 CODE:
790 RETVAL = newSVsv (sv);
791 SvTAINTED_off (RETVAL);
792 OUTPUT:
793 RETVAL
794
795void 800void
796_exit (int status) 801_exit (int status)
797
798bool
799safe ()
800 CODE:
801 RETVAL = !rxvt_tainted ();
802 OUTPUT:
803 RETVAL
804 802
805NV 803NV
806NOW () 804NOW ()
807 CODE: 805 CODE:
808 RETVAL = NOW; 806 RETVAL = NOW;
1074 char *mbstr = rxvt_wcstombs (wstr); 1072 char *mbstr = rxvt_wcstombs (wstr);
1075 rxvt_pop_locale (); 1073 rxvt_pop_locale ();
1076 1074
1077 free (wstr); 1075 free (wstr);
1078 1076
1079 RETVAL = taint_if (newSVpv (mbstr, 0), str); 1077 RETVAL = newSVpv (mbstr, 0);
1080 free (mbstr); 1078 free (mbstr);
1081} 1079}
1082 OUTPUT: 1080 OUTPUT:
1083 RETVAL 1081 RETVAL
1084 1082
1091 1089
1092 rxvt_push_locale (THIS->locale); 1090 rxvt_push_locale (THIS->locale);
1093 wchar_t *wstr = rxvt_mbstowcs (data, len); 1091 wchar_t *wstr = rxvt_mbstowcs (data, len);
1094 rxvt_pop_locale (); 1092 rxvt_pop_locale ();
1095 1093
1096 RETVAL = taint_if (wcs2sv (wstr), octets); 1094 RETVAL = wcs2sv (wstr);
1097 free (wstr); 1095 free (wstr);
1098} 1096}
1099 OUTPUT: 1097 OUTPUT:
1100 RETVAL 1098 RETVAL
1101 1099
1253 wchar_t *wstr = new wchar_t [THIS->ncol]; 1251 wchar_t *wstr = new wchar_t [THIS->ncol];
1254 1252
1255 for (int col = 0; col < THIS->ncol; col++) 1253 for (int col = 0; col < THIS->ncol; col++)
1256 wstr [col] = l.t [col]; 1254 wstr [col] = l.t [col];
1257 1255
1258 XPUSHs (taint (sv_2mortal (wcs2sv (wstr, THIS->ncol)))); 1256 XPUSHs (sv_2mortal (wcs2sv (wstr, THIS->ncol)));
1259 1257
1260 delete [] wstr; 1258 delete [] wstr;
1261 } 1259 }
1262 1260
1263 if (new_text) 1261 if (new_text)
1384 else 1382 else
1385 *r++ = *s; 1383 *r++ = *s;
1386 1384
1387 rxvt_pop_locale (); 1385 rxvt_pop_locale ();
1388 1386
1389 RETVAL = taint_if (wcs2sv (rstr, r - rstr), string); 1387 RETVAL = wcs2sv (rstr, r - rstr);
1390 1388
1391 delete [] rstr; 1389 delete [] rstr;
1392} 1390}
1393 OUTPUT: 1391 OUTPUT:
1394 RETVAL 1392 RETVAL
1420 else if (IS_COMPOSE (*s)) 1418 else if (IS_COMPOSE (*s))
1421 r += rxvt_composite.expand (*s, r); 1419 r += rxvt_composite.expand (*s, r);
1422 else 1420 else
1423 *r++ = *s; 1421 *r++ = *s;
1424 1422
1425 RETVAL = taint_if (wcs2sv (rstr, r - rstr), text); 1423 RETVAL = wcs2sv (rstr, r - rstr);
1426 1424
1427 delete [] rstr; 1425 delete [] rstr;
1428} 1426}
1429 OUTPUT: 1427 OUTPUT:
1430 RETVAL 1428 RETVAL
1452 1450
1453 if (!IN_RANGE_EXC (index, 0, NUM_RESOURCES)) 1451 if (!IN_RANGE_EXC (index, 0, NUM_RESOURCES))
1454 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);
1455 1453
1456 if (GIMME_V != G_VOID) 1454 if (GIMME_V != G_VOID)
1457 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);
1458 1456
1459 if (newval) 1457 if (newval)
1460 { 1458 {
1461 if (SvOK (newval)) 1459 if (SvOK (newval))
1462 { 1460 {
1469 } 1467 }
1470} 1468}
1471 1469
1472const char * 1470const char *
1473rxvt_term::x_resource (const char *name) 1471rxvt_term::x_resource (const char *name)
1474 CLEANUP:
1475 SvTAINTED_on (ST (0));
1476 1472
1477bool 1473bool
1478rxvt_term::option (U32 optval, int set = -1) 1474rxvt_term::option (U32 optval, int set = -1)
1479 CODE: 1475 CODE:
1480{ 1476{
1540 PUSHs (sv_2mortal (newSViv (rc.col))); 1536 PUSHs (sv_2mortal (newSViv (rc.col)));
1541 } 1537 }
1542 1538
1543 if (items == 3) 1539 if (items == 3)
1544 { 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);
1545 rc.row = clamp (SvIV (ST (1)), THIS->top_row, THIS->nrow - 1); 1551 clamp_it (rc.row, THIS->top_row, THIS->nrow - 1);
1546 rc.col = clamp (SvIV (ST (2)), 0, THIS->ncol - 1);
1547 1552
1548 if (ix) 1553 if (ix)
1549 THIS->want_refresh = 1; 1554 THIS->want_refresh = 1;
1550 } 1555 }
1551} 1556}
1574rxvt_term::selection (SV *newtext = 0) 1579rxvt_term::selection (SV *newtext = 0)
1575 PPCODE: 1580 PPCODE:
1576{ 1581{
1577 if (GIMME_V != G_VOID) 1582 if (GIMME_V != G_VOID)
1578 XPUSHs (THIS->selection.text 1583 XPUSHs (THIS->selection.text
1579 ? taint (sv_2mortal (wcs2sv (THIS->selection.text, THIS->selection.len))) 1584 ? sv_2mortal (wcs2sv (THIS->selection.text, THIS->selection.len))
1580 : &PL_sv_undef); 1585 : &PL_sv_undef);
1581 1586
1582 if (newtext) 1587 if (newtext)
1583 { 1588 {
1584 free (THIS->selection.text); 1589 free (THIS->selection.text);
1710 RETVAL = THIS; 1715 RETVAL = THIS;
1711 OUTPUT: 1716 OUTPUT:
1712 RETVAL 1717 RETVAL
1713 1718
1714timer * 1719timer *
1720timer::after (NV delay)
1721 CODE:
1722 THIS->start (NOW + delay);
1723 OUTPUT:
1724 RETVAL
1725
1726timer *
1715timer::stop () 1727timer::stop ()
1716 CODE: 1728 CODE:
1717 THIS->stop (); 1729 THIS->stop ();
1718 RETVAL = THIS; 1730 RETVAL = THIS;
1719 OUTPUT: 1731 OUTPUT:

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines