*** empty log message ***
authorroot <root>
Mon, 2 Jan 2006 18:20:23 +0000 (18:20 +0000)
committerroot <root>
Mon, 2 Jan 2006 18:20:23 +0000 (18:20 +0000)
autoconf/configure.in
configure
src/Makefile.in
src/main.C
src/rsinc.h
src/rxvt.h
src/rxvtperl.xs
src/urxvt.pm
src/xdefaults.C

index d0f99b5a68762f6f137e8305b31f56bdc8f9d211..410c76a1ea6ef2659a6c0c7c50e5bc67cb9ba7d1 100644 (file)
@@ -1395,7 +1395,7 @@ if test x$support_perl = xyes; then
      PERL_O=rxvtperl.o
      PERLFLAGS="`$PERL -MExtUtils::Embed -e ccopts`"
      PERLLIB="`$PERL -MExtUtils::Embed -e ldopts`"
-     PERLARCHLIB="`$PERL -MConfig -e 'print $Config{archlib}'`"
+     PERLPRIVLIBEXP="`$PERL -MConfig -e 'print $Config{privlibexp}'`"
      AC_MSG_RESULT(ok)
   else
      AC_MSG_ERROR(no working perl found, or perl not version >= 5.8)
@@ -1403,7 +1403,7 @@ if test x$support_perl = xyes; then
 fi
 AC_SUBST(PERLLIB)
 AC_SUBST(PERLFLAGS)
-AC_SUBST(PERLARCHLIB)
+AC_SUBST(PERLPRIVLIBEXP)
 AC_SUBST(PERL)
 AC_SUBST(IF_PERL)
 AC_SUBST(PERL_O)
index 4c9d82a91a80d19f83c29a0d83f227b6d14ab642..0145731795c3c4c9ee8932385817b0c3974bb95f 100755 (executable)
--- a/configure
+++ b/configure
@@ -309,7 +309,7 @@ ac_includes_default="\
 # include <unistd.h>
 #endif"
 
-ac_subst_vars='SHELL PATH_SEPARATOR PACKAGE_NAME PACKAGE_TARNAME PACKAGE_VERSION PACKAGE_STRING PACKAGE_BUGREPORT exec_prefix prefix program_transform_name bindir sbindir libexecdir datadir sysconfdir sharedstatedir localstatedir libdir includedir oldincludedir infodir mandir build_alias host_alias target_alias DEFS ECHO_C ECHO_N ECHO_T LIBS build build_cpu build_vendor build_os host host_cpu host_vendor host_os VERSION DATE LSMDATE LIBVERSION CC CFLAGS LDFLAGS CPPFLAGS ac_ct_CC EXEEXT OBJEXT CXX CXXFLAGS ac_ct_CXX CPP INSTALL_PROGRAM INSTALL_SCRIPT INSTALL_DATA AWK LINKER CXXCPP EGREP INSTALL_LIBRXVT RXVTNAME MV RM CP LN SED ECHO CMP TBL TIC X_CFLAGS X_PRE_LIBS X_LIBS X_EXTRA_LIBS XPM_CPPFLAGS XPM_CFLAGS XPM_LIBS rxvt_int16_typedef rxvt_uint16_typedef rxvt_int32_typedef rxvt_uint32_typedef rxvt_intp_define rxvt_u_intp_define PERL PERLLIB PERLFLAGS PERLARCHLIB IF_PERL PERL_O DEBUG DINCLUDE DLIB include_stdint_h include_stdarg_h include_stdlib_h include_unistd_h include_string_h include_fcntl_h include_util_h include_assert_h include_sys_ioctl_h include_sys_select_h include_sys_strredir_h include_sys_time_h include_time_h LIBOBJS LTLIBOBJS'
+ac_subst_vars='SHELL PATH_SEPARATOR PACKAGE_NAME PACKAGE_TARNAME PACKAGE_VERSION PACKAGE_STRING PACKAGE_BUGREPORT exec_prefix prefix program_transform_name bindir sbindir libexecdir datadir sysconfdir sharedstatedir localstatedir libdir includedir oldincludedir infodir mandir build_alias host_alias target_alias DEFS ECHO_C ECHO_N ECHO_T LIBS build build_cpu build_vendor build_os host host_cpu host_vendor host_os VERSION DATE LSMDATE LIBVERSION CC CFLAGS LDFLAGS CPPFLAGS ac_ct_CC EXEEXT OBJEXT CXX CXXFLAGS ac_ct_CXX CPP INSTALL_PROGRAM INSTALL_SCRIPT INSTALL_DATA AWK LINKER CXXCPP EGREP INSTALL_LIBRXVT RXVTNAME MV RM CP LN SED ECHO CMP TBL TIC X_CFLAGS X_PRE_LIBS X_LIBS X_EXTRA_LIBS XPM_CPPFLAGS XPM_CFLAGS XPM_LIBS rxvt_int16_typedef rxvt_uint16_typedef rxvt_int32_typedef rxvt_uint32_typedef rxvt_intp_define rxvt_u_intp_define PERL PERLLIB PERLFLAGS PERLPRIVLIBEXP IF_PERL PERL_O DEBUG DINCLUDE DLIB include_stdint_h include_stdarg_h include_stdlib_h include_unistd_h include_string_h include_fcntl_h include_util_h include_assert_h include_sys_ioctl_h include_sys_select_h include_sys_strredir_h include_sys_time_h include_time_h LIBOBJS LTLIBOBJS'
 ac_subst_files='MCOMMON'
 
 # Initialize some variables set by options.
@@ -12749,7 +12749,7 @@ _ACEOF
      PERL_O=rxvtperl.o
      PERLFLAGS="`$PERL -MExtUtils::Embed -e ccopts`"
      PERLLIB="`$PERL -MExtUtils::Embed -e ldopts`"
-     PERLARCHLIB="`$PERL -MConfig -e 'print $Config{archlib}'`"
+     PERLPRIVLIBEXP="`$PERL -MConfig -e 'print $Config{privlibexp}'`"
      echo "$as_me:$LINENO: result: ok" >&5
 echo "${ECHO_T}ok" >&6
   else
@@ -13557,7 +13557,7 @@ s,@rxvt_u_intp_define@,$rxvt_u_intp_define,;t t
 s,@PERL@,$PERL,;t t
 s,@PERLLIB@,$PERLLIB,;t t
 s,@PERLFLAGS@,$PERLFLAGS,;t t
-s,@PERLARCHLIB@,$PERLARCHLIB,;t t
+s,@PERLPRIVLIBEXP@,$PERLPRIVLIBEXP,;t t
 s,@IF_PERL@,$IF_PERL,;t t
 s,@PERL_O@,$PERL_O,;t t
 s,@DEBUG@,$DEBUG,;t t
index 695c01689a3d08b9c7bf8f106b6304151e47e9a4..3bc434adf7494b7dc8a31811e0039c3ffdc8de20 100644 (file)
@@ -110,7 +110,7 @@ perlxsi.c: Makefile
        $(PERL) -MExtUtils::Embed -e xsinit -- -std urxvt
 
 rxvtperl.C: rxvtperl.xs typemap
-       $(PERL) @PERLARCHLIB@/ExtUtils/xsubpp -C++ -typemap @PERLARCHLIB@/ExtUtils/typemap -typemap typemap -prototypes $< >$@
+       $(PERL) @PERLPRIVLIBEXP@/ExtUtils/xsubpp -C++ -typemap @PERLPRIVLIBEXP@/ExtUtils/typemap -typemap typemap -prototypes $< >$@
 
 rxvtperl.o: rxvtperl.C perlxsi.c
        $(COMPILE) @PERLFLAGS@ -DLIBDIR="\"$(libdir)/urxvt\"" -c $<
index 1f851331d388f56aa0c49fecdfa36d0ccd0e0cdc..a61dbe14a4f55be236ed85a0effec7eba9beccfc 100644 (file)
@@ -50,7 +50,7 @@
 
 vector<rxvt_term *> rxvt_term::termlist;
 
-static char curlocale[128];
+static char curlocale[128], savelocale[128];
 
 bool
 rxvt_set_locale (const char *locale)
@@ -63,6 +63,19 @@ rxvt_set_locale (const char *locale)
   return true;
 }
 
+bool
+rxvt_push_locale (const char *locale)
+{
+  strcpy (savelocale, curlocale);
+  rxvt_set_locale (locale);
+}
+
+void
+rxvt_pop_locale ()
+{
+  rxvt_set_locale (savelocale);
+}
+
 #if ENABLE_COMBINING
 class rxvt_composite_vec rxvt_composite;
 
index b66b36bcd653693fc86039e297ceb1eb670b5a00..efeb52e0f2e7142c2beba89e6cbb447031173fb1 100644 (file)
 #ifdef TINTING
   Rs_def(shade)
 #endif
+#if ENABLE_PERL
+  Rs_def(perl_lib)
+  Rs_def(perl_eval)
+  Rs_def(perl)
+#endif
index 9f91482f675a21f8d3dc675915e6b651d676581e..5c4cabbf04d4d01409a1e4f4c94e89674cd890cd 100644 (file)
@@ -851,6 +851,8 @@ extern void rxvt_exit_failure () __attribute__ ((noreturn));
 
 #define SET_LOCALE(locale) rxvt_set_locale (locale)
 extern bool rxvt_set_locale (const char *locale);
+extern bool rxvt_push_locale (const char *locale);
+extern void rxvt_pop_locale ();
 
 /*
  *****************************************************************************
index 23945bd59600cf0570adbc2d74086f31279f7129..5be34cb0ebeb3260625d9dbfbfa586065a3e47f8 100644 (file)
@@ -326,25 +326,68 @@ fatal (const char *msg)
        CODE:
         rxvt_fatal ("%s", msg);
 
+NV
+NOW ()
+       CODE:
+        RETVAL = NOW;
+        OUTPUT:
+        RETVAL
+
+MODULE = urxvt             PACKAGE = urxvt::term
+
 int
-wcswidth (SV *str)
+rxvt_term::strwidth (SV *str)
        CODE:
 {
         wchar_t *wstr = sv2wcs (str);
+
+       rxvt_push_locale (THIS->locale);
         RETVAL = wcswidth (wstr, wcslen (wstr));
+        rxvt_pop_locale ();
+
         free (wstr);
 }
        OUTPUT:
         RETVAL
 
-NV
-NOW ()
+SV *
+rxvt_term::locale_encode (SV *str)
        CODE:
-        RETVAL = NOW;
-        OUTPUT:
+{
+        wchar_t *wstr = sv2wcs (str);
+
+       rxvt_push_locale (THIS->locale);
+        char *mbstr = rxvt_wcstombs (wstr);
+        rxvt_pop_locale ();
+
+        free (wstr);
+
+        RETVAL = newSVpv (mbstr, 0);
+        free (mbstr);
+}
+       OUTPUT:
         RETVAL
 
-MODULE = urxvt             PACKAGE = urxvt::term
+SV *
+rxvt_term::locale_decode (SV *octets)
+       CODE:
+{
+       STRLEN len;
+        char *data = SvPVbyte (octets, len);
+
+       rxvt_push_locale (THIS->locale);
+        wchar_t *wstr = rxvt_mbstowcs (data, len);
+        rxvt_pop_locale ();
+
+        char *str = rxvt_wcstoutf8 (wstr);
+        free (wstr);
+
+        RETVAL = newSVpv (str, 0);
+        SvUTF8_on (RETVAL);
+        free (str);
+}
+       OUTPUT:
+        RETVAL
 
 void
 rxvt_term::_resource (char *name, int index, SV *newval = 0)
@@ -460,6 +503,14 @@ rxvt_term::scr_overlay_set (int x, int y, SV *text)
         free (wtext);
 }
 
+void
+rxvt_term::tt_write (SV *octets)
+        INIT:
+          STRLEN len;
+          char *str = SvPVbyte (octets, len);
+       C_ARGS:
+          (unsigned char *)str, len
+
 MODULE = urxvt             PACKAGE = urxvt::timer
 
 SV *
index 5f20d721f56094aa0f5ab616d02e6becd504adeb..eabcb6c1c0c35bd1ef0aa8f18911c314256cb050 100644 (file)
@@ -6,9 +6,6 @@ rxvtperl - rxvt-unicode's embedded perl interpreter
 
 * Put your scripts into F<@@RXVT_LIBDIR@@/urxvt/perl-ext/>, they will be loaded automatically.
 
-* Each script will only be loaded once, even in urxvtd, and will be valid
-globally.
-
 * Scripts are evaluated in a 'use strict' and 'use utf8' environment, and
 thus must be encoded as UTF-8.
 
@@ -21,6 +18,28 @@ thus must be encoded as UTF-8.
 
 =head1 DESCRIPTION
 
+On startup, @@RXVT_NAME@@ will scan F<@@RXVT_LIBDIR@@/urxvt/perl-ext/>
+for files and will load them. Everytime a terminal object gets created,
+the directory specified by the C<perl-lib> resource will be additionally
+scanned.
+
+Each script will only ever be loaded once, even in @@RXVT_NAME@@d, where
+scripts will be shared for all terminals.
+
+Hooks in scripts specified by C<perl-lib> will only be called for the
+terminals created with that specific option value.
+
+=head2 General API Considerations
+
+All objects (such as terminals, time watchers etc.) are typical
+reference-to-hash objects. The hash can be used to store anything you
+like. The only reserved member is C<_ptr>, which must not be changed.
+
+When objects are destroyed on the C++ side, the perl object hashes are
+emptied, so its best to store related objects such as time watchers and
+the like inside the terminal object so they get destroyed as soon as the
+terminal is destroyed.
+
 =head2 Hooks
 
 The following subroutines can be declared in loaded scripts, and will be called
@@ -122,18 +141,13 @@ starts up.
 
 =item urxvt::warn $string
 
-Calls C<rxvt_warn> witht eh given string which should not include a
+Calls C<rxvt_warn> with the given string which should not include a
 newline. The module also overwrites the C<warn> builtin with a function
 that calls this function.
 
 Using this function has the advantage that its output ends up in the
 correct place, e.g. on stderr of the connecting urxvtc client.
 
-=item $cellwidth = urxvt::wcswidth $string
-
-Returns the number of screen-cells this string would need. Correctly
-accounts for wide and combining characters.
-
 =item $time = urxvt::NOW
 
 Returns the "current time" (as per the event loop).
@@ -227,7 +241,27 @@ sub load_script($) {
    };
 }
 
-load_script $_ for grep -f $_, <$LIBDIR/perl-ext/*>;
+sub load_scripts($) {
+   my ($dir) = @_;
+
+   verbose 3, "loading scripts from '$dir'";
+
+   load_script $_
+      for grep -f $_,
+         <$dir/perl-ext/*>;
+}
+
+sub on_init {
+   my ($term) = @_;
+
+   my $libdir = $term->resource ("perl_lib");
+
+   load_scripts $libdir
+      if defined $libdir;
+}
+
+register_package __PACKAGE__;
+load_scripts $LIBDIR;
 
 =back
 
@@ -261,13 +295,13 @@ list:
   display_name embed ext_bwidth fade font geometry hold iconName
   imFont imLocale inputMethod insecure int_bwidth intensityStyles
   italicFont jumpScroll lineSpace loginShell mapAlert menu meta8
-  modifier mouseWheelScrollPage name pastableTabs path pointerBlank
-  pointerBlankDelay preeditType print_pipe pty_fd reverseVideo saveLines
-  scrollBar scrollBar_align scrollBar_floating scrollBar_right
-  scrollBar_thickness scrollTtyKeypress scrollTtyOutput scrollWithBuffer
-  scrollstyle secondaryScreen secondaryScroll selectstyle shade term_name
-  title transparent transparent_all tripleclickwords utmpInhibit
-  visualBell
+  modifier mouseWheelScrollPage name pastableTabs path perl perl_eval
+  perl_lib pointerBlank pointerBlankDelay preeditType print_pipe pty_fd
+  reverseVideo saveLines scrollBar scrollBar_align scrollBar_floating
+  scrollBar_right scrollBar_thickness scrollTtyKeypress scrollTtyOutput
+  scrollWithBuffer scrollstyle secondaryScreen secondaryScroll selectstyle
+  shade term_name title transparent transparent_all tripleclickwords
+  utmpInhibit visualBell
 
 =cut
 
@@ -307,7 +341,7 @@ sub urxvt::term::scr_overlay {
    my @lines = split /\n/, $text;
 
    my $w = 0;
-   for (map urxvt::wcswidth $_, @lines) {
+   for (map $self->strwidth ($_), @lines) {
       $w = $_ if $w < $_;
    }
 
@@ -335,6 +369,25 @@ position.
 
 Write a string at the given position into the overlay.
 
+=item $cellwidth = $term->strwidth $string
+
+Returns the number of screen-cells this string would need. Correctly
+accounts for wide and combining characters.
+
+=item $octets = $term->locale_encode $string
+
+Convert the given text string into the corresponding locale encoding.
+
+=item $string = $term->locale_decode $octets
+
+Convert the given locale-encoded octets into a perl string.
+
+=item $term->tt_write ($octets)
+
+Write the octets given in C<$data> to the tty (i.e. as program input). To
+pass characters instead of octets, you should convetr you strings first to
+the locale-specific encoding using C<< $term->locale_encode >>.
+
 =back
 
 =head2 The C<urxvt::timer> Class
index a161b738761f0eba523bb5833f1b8c4d2a05a285..034ba8d7b9fad0c53ddc480769450eab480ab364 100644 (file)
@@ -260,6 +260,11 @@ optList[] = {
               BOOL (Rs_secondaryScreen, "secondaryScreen", "ssc", Opt_secondaryScreen, "enable secondary screen"),
               BOOL (Rs_secondaryScroll, "secondaryScroll", "ssr", Opt_secondaryScroll, "enable secondary screen scroll"),
 #endif
+#if ENABLE_PERL
+              STRG (Rs_perl_lib, "perl-lib", 0, "string", "directory where to look for additional extension scripts"),
+              STRG (Rs_perl_eval, "perl-eval", 0, "string", "string to be evaluated after all extensions have been loaded"),
+              STRG (Rs_perl, "perl", "perl", "string", "unused by urxvt proper, free for extensions to use"),
+#endif
 #if 0 && TODO
 #if !defined(NO_RESOURCES) && defined(USE_XGETDEFAULT)
               INFO ("xrm", "string", "X resource"),