From: root Date: Wed, 11 Jan 2006 00:59:57 +0000 (+0000) Subject: *** empty log message *** X-Git-Url: http://git.openbox.org/?a=commitdiff_plain;h=12d2487adf3891f8752887a2464c1341a6f3af44;p=dana%2Furxvt.git *** empty log message *** --- diff --git a/Changes b/Changes index c2500173..512a5925 100644 --- a/Changes +++ b/Changes @@ -11,6 +11,7 @@ WISH: support tex fonts TODO: resources! resources! resources! TODO: better environment handling in rxvt/xim etc. and urxvt::term->new +TODO: selection-extending with rmb does not work? - added sections for DISTRIBUTION MAINTAINERS and about SETUID/SETGID to the FAQ. - selection, searchable-scrollback, selection-popup and @@ -32,6 +33,10 @@ TODO: better environment handling in rxvt/xim etc. and urxvt::term->new - applied minor cleanups by Ladislav Michnovic. - applied better configure support for openpty by Emanuele Giaquinta. - mark-urls launch-on-click by jepler. + - removed "small" resource parsing function, as it wasn't really + compatible, and not really small either. + - removed PATH_ENV and PATH file search support. + - removed support for locale-specific app-defaults file. 6.3 Wed Jan 4 22:37:10 CET 2006 - SECURITY FIX: on systems using openpty, permissions were diff --git a/autoconf/config.h.in b/autoconf/config.h.in index dcab8034..70c2cd81 100644 --- a/autoconf/config.h.in +++ b/autoconf/config.h.in @@ -229,9 +229,6 @@ /* Define if you don't want any resources read */ #undef NO_RESOURCES -/* Define if you want to use XGetDefault instead of our internal version */ -#undef USE_XGETDEFAULT - /* Fallback resource class */ #undef RESFALLBACK diff --git a/autoconf/configure.in b/autoconf/configure.in index 12c525be..99b9afeb 100644 --- a/autoconf/configure.in +++ b/autoconf/configure.in @@ -350,12 +350,6 @@ AC_ARG_ENABLE(resources, AC_DEFINE(NO_RESOURCES, 1, Define if you don't want any resources read) fi]) -AC_ARG_ENABLE(xgetdefault, - [ --enable-xgetdefault enable resources via X instead of our small version], - [if test x$enableval = xyes; then - AC_DEFINE(USE_XGETDEFAULT, 1, Define if you want to use XGetDefault instead of our internal version) - fi]) - AC_ARG_ENABLE(8bitctrls, [ --enable-8bitctrls enable 8 bit control sequences (not recommended)], [if test x$enableval = xyes -o x$enableval = xno; then diff --git a/configure b/configure index b9dade0f..6fc2b594 100755 --- a/configure +++ b/configure @@ -891,7 +891,6 @@ Optional Features: --disable-backspace-key disable handling of the backspace key --disable-delete-key disable handling of the delete key --disable-resources disable all resource checking - --enable-xgetdefault enable resources via X instead of our small version --enable-8bitctrls enable 8 bit control sequences (not recommended) --enable-fallback(=CLASS) fall back on CLASS resources in addition to URxvt ones (default: Rxvt) --enable-strings enable some replacement system functions @@ -4641,18 +4640,6 @@ _ACEOF fi fi; -# Check whether --enable-xgetdefault or --disable-xgetdefault was given. -if test "${enable_xgetdefault+set}" = set; then - enableval="$enable_xgetdefault" - if test x$enableval = xyes; then - -cat >>confdefs.h <<\_ACEOF -#define USE_XGETDEFAULT 1 -_ACEOF - - fi -fi; - # Check whether --enable-8bitctrls or --disable-8bitctrls was given. if test "${enable_8bitctrls+set}" = set; then enableval="$enable_8bitctrls" diff --git a/doc/rxvtperl.3.html b/doc/rxvtperl.3.html index 624de21d..4fb3dff4 100644 --- a/doc/rxvtperl.3.html +++ b/doc/rxvtperl.3.html @@ -185,7 +185,7 @@ hints on what they mean:

Rxvt-unicodes special way of encoding text, where one ``unicode'' character -always represents one screen cell. See row_t for a discussion of this format. +always represents one screen cell. See ROW_t for a discussion of this format.

$string
@@ -478,23 +478,11 @@ The basename of the installed binaries, usually urxvt. The current terminal. This variable stores the current urxvt::term object, whenever a callback/hook is executing. -

-
- +

Functions in the urxvt Package

-
$term = new urxvt [arg...]
-
-
-Creates a new terminal, very similar as if you had started it with -system $binfile, arg.... Croaks (and probably outputs an error message) -if the new instance couldn't be created. Returns undef if the new -instance didn't initialise perl, and the terminal object otherwise. The -init and start hooks will be called during the call. -
-

urxvt::fatal $errormessage
@@ -514,6 +502,9 @@ 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.

+
+

Messages have a size limit of 1023 bytes currently.

+

$is_safe = urxvt::safe
@@ -614,6 +605,20 @@ work.

The urxvt::term Class

+
$term = new urxvt::term $envhashref, $rxvtname, [arg...]
+
+
+Creates a new terminal, very similar as if you had started it with system +$rxvtname, arg.... $envhashref must be a reference to a %ENV-like +hash which defines the environment of the new terminal. +
+
+

Croaks (and probably outputs an error message) if the new instance +couldn't be created. Returns undef if the new instance didn't +initialise perl, and the terminal object otherwise. The init and +start hooks will be called during this call.

+
+

$term->destroy
@@ -908,16 +913,23 @@ Return the window id of the terminal window. Return various integers describing terminal characteristics.

+
$x_display = $term->display_id
+
+
+Return the DISPLAY used by rxvt-unicode. +
+

$lc_ctype = $term->locale
Returns the LC_CTYPE category string used by this rxvt-unicode.

-
$x_display = $term->display_id
+
$env = $term->env
-Return the DISPLAY used by rxvt-unicode. +Returns a copy of the environment in effect for the terminal as a hashref +similar to \%ENV.

$modifiermask = $term->ModLevel3Mask
diff --git a/doc/rxvtperl.3.man.in b/doc/rxvtperl.3.man.in index d5c939ca..e6cc2beb 100644 --- a/doc/rxvtperl.3.man.in +++ b/doc/rxvtperl.3.man.in @@ -129,7 +129,7 @@ .\" ======================================================================== .\" .IX Title "rxvt 3" -.TH rxvt 3 "2006-01-10" "6.3" "RXVT-UNICODE" +.TH rxvt 3 "2006-01-11" "6.3" "RXVT-UNICODE" .SH "NAME" @@RXVT_NAME@@perl \- rxvt\-unicode's embedded perl interpreter .SH "SYNOPSIS" @@ -246,7 +246,7 @@ hints on what they mean: .IP "$text" 4 .IX Item "$text" Rxvt-unicodes special way of encoding text, where one \*(L"unicode\*(R" character -always represents one screen cell. See row_t for a discussion of this format. +always represents one screen cell. See ROW_t for a discussion of this format. .IP "$string" 4 .IX Item "$string" A perl text string, with an emphasis on \fItext\fR. It can store all unicode @@ -477,19 +477,9 @@ The basename of the installed binaries, usually \f(CW\*(C`urxvt\*(C'\fR. .IX Item "$urxvt::TERM" The current terminal. This variable stores the current \f(CW\*(C`urxvt::term\*(C'\fR object, whenever a callback/hook is executing. -.IP "*" 4 .ie n .Sh "Functions in the ""urxvt"" Package" .el .Sh "Functions in the \f(CWurxvt\fP Package" .IX Subsection "Functions in the urxvt Package" -.PD 0 -.IP "$term = new urxvt [arg...]" 4 -.IX Item "$term = new urxvt [arg...]" -.PD -Creates a new terminal, very similar as if you had started it with -\&\f(CW\*(C`system $binfile, arg...\*(C'\fR. Croaks (and probably outputs an error message) -if the new instance couldn't be created. Returns \f(CW\*(C`undef\*(C'\fR if the new -instance didn't initialise perl, and the terminal object otherwise. The -\&\f(CW\*(C`init\*(C'\fR and \f(CW\*(C`start\*(C'\fR hooks will be called during the call. .ie n .IP "urxvt::fatal $errormessage" 4 .el .IP "urxvt::fatal \f(CW$errormessage\fR" 4 .IX Item "urxvt::fatal $errormessage" @@ -505,6 +495,8 @@ that calls this function. .Sp Using this function has the advantage that its output ends up in the correct place, e.g. on stderr of the connecting urxvtc client. +.Sp +Messages have a size limit of 1023 bytes currently. .IP "$is_safe = urxvt::safe" 4 .IX Item "$is_safe = urxvt::safe" Returns true when it is safe to do potentially unsafe things, such as @@ -582,6 +574,17 @@ work. .ie n .Sh "The ""urxvt::term"" Class" .el .Sh "The \f(CWurxvt::term\fP Class" .IX Subsection "The urxvt::term Class" +.ie n .IP "$term = new urxvt::term $envhashref\fR, \f(CW$rxvtname, [arg...]" 4 +.el .IP "$term = new urxvt::term \f(CW$envhashref\fR, \f(CW$rxvtname\fR, [arg...]" 4 +.IX Item "$term = new urxvt::term $envhashref, $rxvtname, [arg...]" +Creates a new terminal, very similar as if you had started it with system +\&\f(CW\*(C`$rxvtname, arg...\*(C'\fR. \f(CW$envhashref\fR must be a reference to a \f(CW%ENV\fR\-like +hash which defines the environment of the new terminal. +.Sp +Croaks (and probably outputs an error message) if the new instance +couldn't be created. Returns \f(CW\*(C`undef\*(C'\fR if the new instance didn't +initialise perl, and the terminal object otherwise. The \f(CW\*(C`init\*(C'\fR and +\&\f(CW\*(C`start\*(C'\fR hooks will be called during this call. .IP "$term\->destroy" 4 .IX Item "$term->destroy" Destroy the terminal object (close the window, free resources @@ -824,14 +827,19 @@ Return the window id of the terminal window. .IX Item "$lines_in_scrollback = $term->nsaved" .PD Return various integers describing terminal characteristics. -.ie n .IP "$lc_ctype = $term\->locale" 4 -.el .IP "$lc_ctype = \f(CW$term\fR\->locale" 4 -.IX Item "$lc_ctype = $term->locale" -Returns the \s-1LC_CTYPE\s0 category string used by this rxvt\-unicode. .ie n .IP "$x_display = $term\->display_id" 4 .el .IP "$x_display = \f(CW$term\fR\->display_id" 4 .IX Item "$x_display = $term->display_id" Return the \s-1DISPLAY\s0 used by rxvt\-unicode. +.ie n .IP "$lc_ctype = $term\->locale" 4 +.el .IP "$lc_ctype = \f(CW$term\fR\->locale" 4 +.IX Item "$lc_ctype = $term->locale" +Returns the \s-1LC_CTYPE\s0 category string used by this rxvt\-unicode. +.ie n .IP "$env = $term\->env" 4 +.el .IP "$env = \f(CW$term\fR\->env" 4 +.IX Item "$env = $term->env" +Returns a copy of the environment in effect for the terminal as a hashref +similar to \f(CW\*(C`\e%ENV\*(C'\fR. .ie n .IP "$modifiermask = $term\->ModLevel3Mask" 4 .el .IP "$modifiermask = \f(CW$term\fR\->ModLevel3Mask" 4 .IX Item "$modifiermask = $term->ModLevel3Mask" @@ -1010,7 +1018,7 @@ Displays the popup (which is initially hidden). .IX Subsection "The urxvt::timer Class" This class implements timer watchers/events. Time is represented as a fractional number of seconds since the epoch. Example: -.Sp +.PP .Vb 8 \& $term->{overlay} = $term->overlay (-1, 0, 8, 1, urxvt::OVERLAY_RSTYLE, 0); \& $term->{timer} = urxvt::timer @@ -1021,7 +1029,6 @@ fractional number of seconds since the epoch. Example: \& sprintf "%2d:%02d:%02d", (localtime urxvt::NOW)[2,1,0]); \& }); .Ve -.RS 4 .IP "$timer = new urxvt::timer" 4 .IX Item "$timer = new urxvt::timer" Create a new timer object in started state. It is scheduled to fire @@ -1056,13 +1063,11 @@ Set the event trigger time to \f(CW$tstamp\fR and start the timer. .el .IP "$timer = \f(CW$timer\fR\->stop" 4 .IX Item "$timer = $timer->stop" Stop the timer. -.RE -.RS 4 .ie n .Sh "The ""urxvt::iow"" Class" .el .Sh "The \f(CWurxvt::iow\fP Class" .IX Subsection "The urxvt::iow Class" This class implements io watchers/events. Example: -.Sp +.PP .Vb 12 \& $term->{socket} = ... \& $term->{iow} = urxvt::iow @@ -1103,8 +1108,6 @@ Start watching for requested events on the given handle. .el .IP "$iow = \f(CW$iow\fR\->stop" 4 .IX Item "$iow = $iow->stop" Stop watching for events on the given filehandle. -.RE -.RS 4 .SH "ENVIRONMENT" .IX Header "ENVIRONMENT" .Sh "\s-1URXVT_PERL_VERBOSITY\s0" @@ -1118,8 +1121,6 @@ numbers indicate more verbose output. .IX Item ">= 3 - script loading and management" .IP ">=10 \- all events received" 4 .IX Item ">=10 - all events received" -.RE -.RS 4 .PD .SH "AUTHOR" .IX Header "AUTHOR" diff --git a/doc/rxvtperl.3.txt b/doc/rxvtperl.3.txt index 713d8fb5..9b8b83bc 100644 --- a/doc/rxvtperl.3.txt +++ b/doc/rxvtperl.3.txt @@ -100,7 +100,7 @@ API DOCUMENTATION $text Rxvt-unicodes special way of encoding text, where one "unicode" - character always represents one screen cell. See row_t for a + character always represents one screen cell. See ROW_t for a discussion of this format. $string @@ -301,17 +301,7 @@ API DOCUMENTATION The current terminal. This variable stores the current "urxvt::term" object, whenever a callback/hook is executing. - * - Functions in the "urxvt" Package - $term = new urxvt [arg...] - Creates a new terminal, very similar as if you had started it with - "system $binfile, arg...". Croaks (and probably outputs an error - message) if the new instance couldn't be created. Returns "undef" if - the new instance didn't initialise perl, and the terminal object - otherwise. The "init" and "start" hooks will be called during the - call. - urxvt::fatal $errormessage Fatally aborts execution with the given error message. Avoid at all costs! The only time this is acceptable is when the terminal process @@ -325,6 +315,8 @@ API DOCUMENTATION Using this function has the advantage that its output ends up in the correct place, e.g. on stderr of the connecting urxvtc client. + Messages have a size limit of 1023 bytes currently. + $is_safe = urxvt::safe Returns true when it is safe to do potentially unsafe things, such as evaluating perl code specified by the user. This is true when @@ -387,6 +379,16 @@ API DOCUMENTATION should work. The "urxvt::term" Class + $term = new urxvt::term $envhashref, $rxvtname, [arg...] + Creates a new terminal, very similar as if you had started it with + system "$rxvtname, arg...". $envhashref must be a reference to a + %ENV-like hash which defines the environment of the new terminal. + + Croaks (and probably outputs an error message) if the new instance + couldn't be created. Returns "undef" if the new instance didn't + initialise perl, and the terminal object otherwise. The "init" and + "start" hooks will be called during this call. + $term->destroy Destroy the terminal object (close the window, free resources etc.). Please note that rxvt will not exit as long as any event watchers @@ -579,11 +581,15 @@ API DOCUMENTATION $lines_in_scrollback = $term->nsaved Return various integers describing terminal characteristics. + $x_display = $term->display_id + Return the DISPLAY used by rxvt-unicode. + $lc_ctype = $term->locale Returns the LC_CTYPE category string used by this rxvt-unicode. - $x_display = $term->display_id - Return the DISPLAY used by rxvt-unicode. + $env = $term->env + Returns a copy of the environment in effect for the terminal as a + hashref similar to "\%ENV". $modifiermask = $term->ModLevel3Mask $modifiermask = $term->ModMetaMask @@ -729,92 +735,92 @@ API DOCUMENTATION Displays the popup (which is initially hidden). The "urxvt::timer" Class - This class implements timer watchers/events. Time is represented as - a fractional number of seconds since the epoch. Example: + This class implements timer watchers/events. Time is represented as a + fractional number of seconds since the epoch. Example: - $term->{overlay} = $term->overlay (-1, 0, 8, 1, urxvt::OVERLAY_RSTYLE, 0); - $term->{timer} = urxvt::timer - ->new - ->interval (1) - ->cb (sub { - $term->{overlay}->set (0, 0, - sprintf "%2d:%02d:%02d", (localtime urxvt::NOW)[2,1,0]); - }); + $term->{overlay} = $term->overlay (-1, 0, 8, 1, urxvt::OVERLAY_RSTYLE, 0); + $term->{timer} = urxvt::timer + ->new + ->interval (1) + ->cb (sub { + $term->{overlay}->set (0, 0, + sprintf "%2d:%02d:%02d", (localtime urxvt::NOW)[2,1,0]); + }); - $timer = new urxvt::timer - Create a new timer object in started state. It is scheduled to - fire immediately. + $timer = new urxvt::timer + Create a new timer object in started state. It is scheduled to fire + immediately. - $timer = $timer->cb (sub { my ($timer) = @_; ... }) - Set the callback to be called when the timer triggers. + $timer = $timer->cb (sub { my ($timer) = @_; ... }) + Set the callback to be called when the timer triggers. - $tstamp = $timer->at - Return the time this watcher will fire next. + $tstamp = $timer->at + Return the time this watcher will fire next. - $timer = $timer->set ($tstamp) - Set the time the event is generated to $tstamp. + $timer = $timer->set ($tstamp) + Set the time the event is generated to $tstamp. - $timer = $timer->interval ($interval) - Normally (and when $interval is 0), the timer will automatically - stop after it has fired once. If $interval is non-zero, then the - timer is automatically rescheduled at the given intervals. + $timer = $timer->interval ($interval) + Normally (and when $interval is 0), the timer will automatically + stop after it has fired once. If $interval is non-zero, then the + timer is automatically rescheduled at the given intervals. - $timer = $timer->start - Start the timer. + $timer = $timer->start + Start the timer. - $timer = $timer->start ($tstamp) - Set the event trigger time to $tstamp and start the timer. + $timer = $timer->start ($tstamp) + Set the event trigger time to $tstamp and start the timer. - $timer = $timer->stop - Stop the timer. + $timer = $timer->stop + Stop the timer. The "urxvt::iow" Class - This class implements io watchers/events. Example: - - $term->{socket} = ... - $term->{iow} = urxvt::iow - ->new - ->fd (fileno $term->{socket}) - ->events (urxvt::EVENT_READ) - ->start - ->cb (sub { - my ($iow, $revents) = @_; - # $revents must be 1 here, no need to check - sysread $term->{socket}, my $buf, 8192 - or end-of-file; - }); - - $iow = new urxvt::iow - Create a new io watcher object in stopped state. - - $iow = $iow->cb (sub { my ($iow, $reventmask) = @_; ... }) - Set the callback to be called when io events are triggered. - $reventmask is a bitset as described in the "events" method. - - $iow = $iow->fd ($fd) - Set the filedescriptor (not handle) to watch. - - $iow = $iow->events ($eventmask) - Set the event mask to watch. The only allowed values are - "urxvt::EVENT_READ" and "urxvt::EVENT_WRITE", which might be - ORed together, or "urxvt::EVENT_NONE". - - $iow = $iow->start - Start watching for requested events on the given handle. - - $iow = $iow->stop - Stop watching for events on the given filehandle. + This class implements io watchers/events. Example: + + $term->{socket} = ... + $term->{iow} = urxvt::iow + ->new + ->fd (fileno $term->{socket}) + ->events (urxvt::EVENT_READ) + ->start + ->cb (sub { + my ($iow, $revents) = @_; + # $revents must be 1 here, no need to check + sysread $term->{socket}, my $buf, 8192 + or end-of-file; + }); + + $iow = new urxvt::iow + Create a new io watcher object in stopped state. + + $iow = $iow->cb (sub { my ($iow, $reventmask) = @_; ... }) + Set the callback to be called when io events are triggered. + $reventmask is a bitset as described in the "events" method. + + $iow = $iow->fd ($fd) + Set the filedescriptor (not handle) to watch. + + $iow = $iow->events ($eventmask) + Set the event mask to watch. The only allowed values are + "urxvt::EVENT_READ" and "urxvt::EVENT_WRITE", which might be ORed + together, or "urxvt::EVENT_NONE". + + $iow = $iow->start + Start watching for requested events on the given handle. + + $iow = $iow->stop + Stop watching for events on the given filehandle. ENVIRONMENT URXVT_PERL_VERBOSITY - This variable controls the verbosity level of the perl extension. - Higher numbers indicate more verbose output. + This variable controls the verbosity level of the perl extension. Higher + numbers indicate more verbose output. - == 0 - fatal messages - >= 3 - script loading and management - >=10 - all events received + == 0 - fatal messages + >= 3 - script loading and management + >=10 - all events received AUTHOR - Marc Lehmann - http://software.schmorp.de/pkg/rxvt-unicode + Marc Lehmann + http://software.schmorp.de/pkg/rxvt-unicode diff --git a/src/feature.h b/src/feature.h index 4f373a68..acb8097e 100644 --- a/src/feature.h +++ b/src/feature.h @@ -45,14 +45,6 @@ * report bugs, too!), but don't _expect_ them to work. */ -/* - * Define the name of the environment variable to be used in - * addition to the "PATH" environment and the `path' resource. - * Usually it should point to where you keep your background pixmaps and/or - * your menu files - */ -#define PATH_ENV "RXVTPATH" - /* * Avoid enabling the colour cursor (-cr, cursorColor, cursorColor2) */ @@ -130,13 +122,6 @@ */ /* #define ALLOW_132_MODE */ -/*------------------------------RESOURCES-------------------------------*/ -/* - * Define to find installed application defaults for rxvt - * Only if USE_XGETDEFAULT is not defined. - */ -#define USE_XAPPLOADDIR - /* * Add support for the Offix DND (Drag 'n' Drop) protocol */ @@ -164,7 +149,7 @@ * with various KeySyms (0xFF00 - 0xFFFF). * Required by perl. */ -#if (!NO_RESOURCES && ENABLE_FRILLS) || ENABLE_PERL +#if ENABLE_FRILLS || ENABLE_PERL # define KEYSYM_RESOURCE #endif diff --git a/src/hookinc.h b/src/hookinc.h index 50b4e096..c158c71b 100644 --- a/src/hookinc.h +++ b/src/hookinc.h @@ -33,3 +33,4 @@ def (MOTION_NOTIFY) def (MAP_NOTIFY) def (UNMAP_NOTIFY) + def (ON_CUSTOM_REND) // hovering over custom rendition, generate enter/leave maybe? diff --git a/src/init.C b/src/init.C index b4bf4dbc..8537a303 100644 --- a/src/init.C +++ b/src/init.C @@ -341,13 +341,17 @@ rxvt_term::init_resources (int argc, const char *const *argv) /* * Open display, get options/resources and create the window */ - if ((rs[Rs_display_name] = getenv ("DISPLAY")) == NULL) - rs[Rs_display_name] = ":0"; + { + TEMP_ENV; + + if ((rs[Rs_display_name] = getenv ("DISPLAY")) == NULL) + rs[Rs_display_name] = ":0"; - get_options (r_argc, r_argv); + get_options (r_argc, r_argv); - if (!(display = displays.get (rs[Rs_display_name]))) - rxvt_fatal ("can't open display %s, aborting.\n", rs[Rs_display_name]); + if (!(display = displays.get (rs[Rs_display_name]))) + rxvt_fatal ("can't open display %s, aborting.\n", rs[Rs_display_name]); + } extract_resources (); free (r_argv); @@ -578,6 +582,8 @@ rxvt_term::init_env () void rxvt_term::set_locale (const char *locale) { + TEMP_ENV; + #if HAVE_XSETLOCALE || HAVE_SETLOCALE free (this->locale); this->locale = setlocale (LC_CTYPE, locale); @@ -586,13 +592,13 @@ rxvt_term::set_locale (const char *locale) { if (*locale) { - rxvt_warn ("unable to set locale \"%s\", using default locale instead.\n", locale); - setlocale (LC_CTYPE, ""); + rxvt_warn ("unable to set locale \"%s\", using C locale instead.\n", locale); + setlocale (LC_CTYPE, "C"); } else rxvt_warn ("default locale unavailable, check LC_* and LANG variables. Continuing.\n"); - this->locale = ""; + this->locale = "C"; } @@ -617,6 +623,8 @@ rxvt_term::set_locale (const char *locale) void rxvt_term::init_xlocale () { + TEMP_ENV; + #ifdef USE_XIM if (!locale) rxvt_warn ("setting locale failed, working without locale support.\n"); @@ -1527,6 +1535,8 @@ rxvt_term::run_child (const char *const *argv) { char *login; + TEMP_ENV; // not very temporary... + SET_TTYMODE (STDIN_FILENO, &tio); /* init terminal attributes */ if (OPTION (Opt_console)) @@ -1582,7 +1592,7 @@ rxvt_term::run_child (const char *const *argv) } else { - const char *argv0, *shell; + const char *argv0, *shell; if ((shell = getenv ("SHELL")) == NULL || *shell == '\0') shell = "/bin/sh"; @@ -1597,6 +1607,7 @@ rxvt_term::run_child (const char *const *argv) strcpy (&login[1], argv0); argv0 = login; } + execlp (shell, argv0, NULL); /* no error message: STDERR is closed! */ } diff --git a/src/main.C b/src/main.C index 1646a80f..e148576c 100644 --- a/src/main.C +++ b/src/main.C @@ -291,9 +291,6 @@ rxvt_term::~rxvt_term () #if OFF_FOCUS_FADING delete pix_colors_unfocused; #endif -#if USE_XGETDEFAULT - XrmDestroyDatabase (xrmdatabase); -#endif displays.put (display); @@ -647,9 +644,7 @@ rxvt_init () // TODO: handle this with exceptions and tolerate the memory loss XSetIOErrorHandler (rxvt_xioerror_handler); -#ifdef USE_XGETDEFAULT XrmInitialize (); -#endif } /* ------------------------------------------------------------------------- * diff --git a/src/misc.C b/src/misc.C index ff96ed3c..51bcb81e 100644 --- a/src/misc.C +++ b/src/misc.C @@ -527,12 +527,7 @@ rxvt_File_find (const char *file, const char *ext, const char *path) if (file == NULL || *file == '\0') return NULL; - /* search environment variables here too */ - if ((f = rxvt_File_search_path (path, file, ext)) == NULL) -#ifdef PATH_ENV - if ((f = rxvt_File_search_path (getenv (PATH_ENV), file, ext)) == NULL) -#endif - f = rxvt_File_search_path (getenv ("PATH"), file, ext); + f = rxvt_File_search_path (path, file, ext); #ifdef DEBUG_SEARCH_PATH if (f) diff --git a/src/rxvt.h b/src/rxvt.h index 82d45ad5..82c47db8 100644 --- a/src/rxvt.h +++ b/src/rxvt.h @@ -213,10 +213,6 @@ typedef struct _mwmhints { # define NO_MOUSE_REPORT_SCROLLBAR 1 #endif -#ifdef NO_RESOURCES -# undef USE_XGETDEFAULT -#endif - #if defined (ISO_14755) || defined (ENABLE_PERL) # define ENABLE_OVERLAY 1 #endif @@ -701,10 +697,12 @@ enum { #define Width2Pixel(n) ((int32_t)(n) * (int32_t)fwidth) #define Height2Pixel(n) ((int32_t)(n) * (int32_t)fheight) -#define OPTION(opt) (options & (opt)) -#define DEFAULT_OPTIONS (Opt_scrollBar | Opt_scrollTtyOutput \ - | Opt_jumpScroll | Opt_secondaryScreen \ - | Opt_pastableTabs | Opt_intensityStyles) +#define TEMP_ENV temp_environ temp_environ (envv) + +#define OPTION(opt) (options & (opt)) +#define DEFAULT_OPTIONS (Opt_scrollBar | Opt_scrollTtyOutput \ + | Opt_jumpScroll | Opt_secondaryScreen \ + | Opt_pastableTabs | Opt_intensityStyles) // for m >= -n, ensure remainder lies between 0..n-1 #define MOD(m,n) (((m) + (n)) % (n)) @@ -975,14 +973,9 @@ extern class rxvt_composite_vec rxvt_composite; struct rxvt_term : zero_initialized, rxvt_vars { log_callback *log_hook; // log error messages through this hook, if != 0 getfd_callback *getfd_hook; // convert remote to local fd, if != 0 - #if ENABLE_PERL rxvt_perl_term perl; #endif -#if USE_XGETDEFAULT - XrmDatabase xrmdatabase; -#endif - struct mbstate mbstate; // current input multibyte state unsigned char want_refresh:1, diff --git a/src/rxvtd.C b/src/rxvtd.C index 4a714e1b..ddc7b76f 100644 --- a/src/rxvtd.C +++ b/src/rxvtd.C @@ -188,9 +188,6 @@ void server::read_cb (io_watcher &w, short revents) envv->push_back (0); { - char **old_environ = environ; - environ = envv->begin (); - rxvt_term *term = new rxvt_term; term->log_hook = &log_cb; @@ -211,7 +208,6 @@ void server::read_cb (io_watcher &w, short revents) term->log_hook = 0; - environ = old_environ; chdir ("/"); if (!success) diff --git a/src/rxvtdaemon.C b/src/rxvtdaemon.C index c20446c0..779ff94b 100644 --- a/src/rxvtdaemon.C +++ b/src/rxvtdaemon.C @@ -58,6 +58,9 @@ void rxvt_connection::send (const char *data, int len) { uint8_t s[2]; + if (len > 65535) + len = 65535; + s[0] = len >> 8; s[1] = len; write (fd, s, 2); @@ -78,7 +81,7 @@ bool rxvt_connection::recv (auto_str &data, int *len) return false; l = (s[0] << 8) + s[1]; - if (l > 4096) + if (l > 65535) return false; if (len) diff --git a/src/rxvtperl.xs b/src/rxvtperl.xs index e315398e..69a62de9 100644 --- a/src/rxvtperl.xs +++ b/src/rxvtperl.xs @@ -677,36 +677,6 @@ BOOT: export_const_iv (EVENT_WRITE); } -SV * -new (...) - CODE: -{ - stringvec *argv = new stringvec; - bool success; - - for (int i = 0; i < items ;i++) - argv->push_back (strdup (SvPVbyte_nolen (ST (i)))); - - rxvt_term *term = new rxvt_term; - - term->argv = argv; - - try - { - if (!term->init (argv->size (), argv->begin ())) - term = 0; - } - catch (const class rxvt_failure_exception &e) - { - term->destroy (); - croak ("exception caught while initializing new terminal instance"); - } - - RETVAL = term && term->perl.self ? newSVterm (term) : &PL_sv_undef; -} - OUTPUT: - RETVAL - void set_should_invoke (int htype, int value) CODE: @@ -794,6 +764,50 @@ SET_CUSTOM (int rend, int new_value) MODULE = urxvt PACKAGE = urxvt::term +SV * +_new (...) + CODE: +{ + if (items < 1 || !SvROK (ST (0)) || SvTYPE (SvRV (ST (0))) != SVt_PVAV) + croak ("first argument to urxvt::term->_new must be arrayref"); + + rxvt_term *term = new rxvt_term; + + term->argv = new stringvec; + term->envv = new stringvec; + + for (int i = 1; i < items; i++) + term->argv->push_back (strdup (SvPVbyte_nolen (ST (i)))); + + AV *envv = (AV *)SvRV (ST (0)); + for (int i = av_len (envv) + 1; i--; ) + term->envv->push_back (strdup (SvPVbyte_nolen (*av_fetch (envv, i, 1)))); + + term->envv->push_back (0); + + bool success; + + try + { + success = term->init (term->argv->size (), term->argv->begin ()); + } + catch (const class rxvt_failure_exception &e) + { + success = false; + } + + if (!success) + { + term->destroy (); + croak ("error while initializing new terminal instance"); + } + + RETVAL = term && term->perl.self + ? newSVterm (term) : &PL_sv_undef; +} + OUTPUT: + RETVAL + void rxvt_term::destroy () @@ -961,6 +975,26 @@ rxvt_term::display_id () OUTPUT: RETVAL +SV * +rxvt_term::_env () + CODE: +{ + if (THIS->envv) + { + AV *av = newAV (); + + for (char **i = THIS->envv->begin (); i != THIS->envv->end (); ++i) + if (*i) + av_push (av, newSVpv (*i, 0)); + + RETVAL = newRV_noinc ((SV *)av); + } + else + RETVAL = &PL_sv_undef; +} + OUTPUT: + RETVAL + int rxvt_term::pty_ev_events (int events = EVENT_UNDEF) CODE: diff --git a/src/rxvttoolkit.C b/src/rxvttoolkit.C index 46dead6d..3e79ad42 100644 --- a/src/rxvttoolkit.C +++ b/src/rxvttoolkit.C @@ -27,6 +27,8 @@ #include #include +#include + #ifndef NO_SLOW_LINK_SUPPORT # include # include @@ -49,17 +51,17 @@ T *refcache::get (const char *id) { if (!strcmp (id, (*i)->id)) { - (*i)->referenced++; + ++(*i)->referenced; + (*i)->ref_next (); return *i; } } T *obj = new T (id); - obj->referenced = 1; - - if (obj && obj->init ()) + if (obj && obj->ref_init ()) { + obj->referenced = 1; this->push_back (obj); return obj; } @@ -109,7 +111,8 @@ im_destroy_cb (XIM unused1, XPointer client_data, XPointer unused3) display->im_change_cb (); } -bool rxvt_xim::init () +bool +rxvt_xim::ref_init () { display = GET_R->display; //HACK: TODO @@ -143,7 +146,87 @@ rxvt_display::rxvt_display (const char *id) { } -bool rxvt_display::init () +XrmDatabase +rxvt_display::get_resources () +{ + char *homedir = (char *)getenv ("HOME"); + char fname[1024]; + + /* + * get resources using the X library function + */ + char *displayResource, *xe; + XrmDatabase database, rdb1; + + database = NULL; + + // for ordering, see for example http://www.faqs.org/faqs/Xt-FAQ/ Subject: 20 + + // 6. System wide per application default file. + + /* Add in $XAPPLRESDIR/Rxvt only; not bothering with XUSERFILESEARCHPATH */ + if ((xe = (char *)getenv ("XAPPLRESDIR"))) + { + snprintf (fname, sizeof (fname), "%s/%s", xe, RESCLASS); + + if ((rdb1 = XrmGetFileDatabase (fname))) + XrmMergeDatabases (rdb1, &database); + } + + // 5. User's per application default file. + // none + + // 4. User's defaults file. + /* Get any Xserver defaults */ + displayResource = XResourceManagerString (display); + + if (displayResource != NULL) + { + if ((rdb1 = XrmGetStringDatabase (displayResource))) + XrmMergeDatabases (rdb1, &database); + } + else if (homedir) + { + snprintf (fname, sizeof (fname), "%s/.Xdefaults", homedir); + + if ((rdb1 = XrmGetFileDatabase (fname))) + XrmMergeDatabases (rdb1, &database); + } + + /* Get screen specific resources */ + displayResource = XScreenResourceString (ScreenOfDisplay (display, screen)); + + if (displayResource != NULL) + { + if ((rdb1 = XrmGetStringDatabase (displayResource))) + /* Merge with screen-independent resources */ + XrmMergeDatabases (rdb1, &database); + + XFree (displayResource); + } + + // 3. User's per host defaults file + /* Add in XENVIRONMENT file */ + if ((xe = (char *)getenv ("XENVIRONMENT")) + && (rdb1 = XrmGetFileDatabase (xe))) + XrmMergeDatabases (rdb1, &database); + else if (homedir) + { + struct utsname un; + + if (!uname (&un)) + { + snprintf (fname, sizeof (fname), "%s/.Xdefaults-%s", homedir, un.nodename); + + if ((rdb1 = XrmGetFileDatabase (fname))) + XrmMergeDatabases (rdb1, &database); + } + } + + return database; +} + +bool rxvt_display::ref_init () { #ifdef LOCAL_X_IS_UNIX if (id[0] == ':') @@ -170,19 +253,7 @@ bool rxvt_display::init () cmap = DefaultColormap (display, screen); depth = DefaultDepth (display, screen); - int fd = XConnectionNumber (display); - -#ifndef NO_SLOW_LINK_SUPPORT - // try to detect wether we have a local connection. - // assume unix domains socket == local, everything else not - // TODO: might want to check for inet/127.0.0.1 - is_local = 0; - sockaddr_un sa; - socklen_t sl = sizeof (sa); - - if (!getsockname (fd, (sockaddr *)&sa, &sl)) - is_local = sa.sun_family == AF_LOCAL; -#endif + XrmSetDatabase (display, get_resources ()); #ifdef POINTER_BLANK XColor blackcolour; @@ -214,6 +285,20 @@ bool rxvt_display::init () } #endif + int fd = XConnectionNumber (display); + +#ifndef NO_SLOW_LINK_SUPPORT + // try to detect wether we have a local connection. + // assume unix domains socket == local, everything else not + // TODO: might want to check for inet/127.0.0.1 + is_local = 0; + sockaddr_un sa; + socklen_t sl = sizeof (sa); + + if (!getsockname (fd, (sockaddr *)&sa, &sl)) + is_local = sa.sun_family == AF_LOCAL; +#endif + x_ev.start (fd, EVENT_READ); fcntl (fd, F_SETFD, FD_CLOEXEC); @@ -227,6 +312,15 @@ bool rxvt_display::init () return true; } +void +rxvt_display::ref_next () +{ + // TODO: somehow check wether the database files/resources changed + // before re-loading/parsing + XrmDestroyDatabase (XrmGetDatabase (display)); + XrmSetDatabase (display, get_resources ()); +} + rxvt_display::~rxvt_display () { if (!display) diff --git a/src/rxvttoolkit.h b/src/rxvttoolkit.h index 90b47f37..4d6eb581 100644 --- a/src/rxvttoolkit.h +++ b/src/rxvttoolkit.h @@ -28,7 +28,8 @@ struct refcounted { char *id; refcounted (const char *id); - bool init () { return false; } + bool ref_init () { return false; } + void ref_next () { } ~refcounted (); }; @@ -55,7 +56,7 @@ struct rxvt_xim : refcounted { XIM xim; rxvt_xim (const char *id) : refcounted (id) { } - bool init (); + bool ref_init (); ~rxvt_xim (); }; #endif @@ -91,7 +92,9 @@ struct rxvt_display : refcounted { #endif rxvt_display (const char *id); - bool init (); + XrmDatabase get_resources (); + bool ref_init (); + void ref_next (); ~rxvt_display (); operator Display *() const { return display; } diff --git a/src/rxvtutil.h b/src/rxvtutil.h index cdab0090..2e9164cf 100644 --- a/src/rxvtutil.h +++ b/src/rxvtutil.h @@ -19,6 +19,7 @@ public: static bool vax () { return e == 0x44332211; }; } byteorder; +// various utility functions template static inline T min (T a, U b) { return a < (T)b ? a : (T)b; } template static inline void min_it (T &a, U b) { a = a < (T)b ? a : (T)b; } template static inline T max (T a, U b) { return a > (T)b ? a : (T)b; } @@ -37,6 +38,7 @@ template static inline void swap (T& a, U& b) { T t=a; a #define IN_RANGE_EXC(val,beg,end) \ ((unsigned int)(val) - (unsigned int)(beg) < (unsigned int)(end) - (unsigned int)(beg)) +// makes dynamically allocated objects zero-initialised struct zero_initialized { void *operator new (size_t s); void operator delete (void *p, size_t s); @@ -395,5 +397,25 @@ struct stringvec : simplevec } }; +// temporarily replace the process environment +extern char **environ; + +struct temp_environ +{ + char **prev; + + temp_environ (const stringvec *envv) + : prev (environ) + { + if (envv) + environ = (char **)envv->begin (); + } + + ~temp_environ () + { + environ = prev; + } +}; + #endif diff --git a/src/urxvt.pm b/src/urxvt.pm index c943bd83..44c7611c 100644 --- a/src/urxvt.pm +++ b/src/urxvt.pm @@ -125,7 +125,7 @@ hints on what they mean: =item $text Rxvt-unicodes special way of encoding text, where one "unicode" character -always represents one screen cell. See L for a discussion of this format. +always represents one screen cell. See L for a discussion of this format. =item $string @@ -345,6 +345,27 @@ subwindow. =back +=cut + +package urxvt; + +use utf8; +use strict; +use Carp (); +use Scalar::Util (); +use List::Util (); + +our $VERSION = 1; +our $TERM; +our @HOOKNAME; +our %HOOKTYPE = map +($HOOKNAME[$_] => $_), 0..$#HOOKNAME; +our %OPTION; + +our $LIBDIR; +our $RESNAME; +our $RESCLASS; +our $RXVTNAME; + =head2 Variables in the C Package =over 4 @@ -367,22 +388,12 @@ The basename of the installed binaries, usually C. The current terminal. This variable stores the current C object, whenever a callback/hook is executing. -=item - =back =head2 Functions in the C Package =over 4 -=item $term = new urxvt [arg...] - -Creates a new terminal, very similar as if you had started it with -C. Croaks (and probably outputs an error message) -if the new instance couldn't be created. Returns C if the new -instance didn't initialise perl, and the terminal object otherwise. The -C and C hooks will be called during the call. - =item urxvt::fatal $errormessage Fatally aborts execution with the given error message. Avoid at all @@ -398,6 +409,8 @@ 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. +Messages have a size limit of 1023 bytes currently. + =item $is_safe = urxvt::safe Returns true when it is safe to do potentially unsafe things, such as @@ -472,25 +485,6 @@ Change the custom value. =cut -package urxvt; - -use utf8; -use strict; -use Carp (); -use Scalar::Util (); -use List::Util (); - -our $VERSION = 1; -our $TERM; -our @HOOKNAME; -our %HOOKTYPE = map +($HOOKNAME[$_] => $_), 0..$#HOOKNAME; -our %OPTION; - -our $LIBDIR; -our $RESNAME; -our $RESCLASS; -our $RXVTNAME; - BEGIN { urxvt->bootstrap; @@ -785,6 +779,25 @@ sub register_package { } } +=item $term = new urxvt::term $envhashref, $rxvtname, [arg...] + +Creates a new terminal, very similar as if you had started it with system +C<$rxvtname, arg...>. C<$envhashref> must be a reference to a C<%ENV>-like +hash which defines the environment of the new terminal. + +Croaks (and probably outputs an error message) if the new instance +couldn't be created. Returns C if the new instance didn't +initialise perl, and the terminal object otherwise. The C and +C hooks will be called during this call. + +=cut + +sub new { + my ($class, $env, @args) = @_; + + _new ([ map "$_=$env->{$_}", keys %$env ], @args); +} + =item $term->destroy Destroy the terminal object (close the window, free resources @@ -1057,13 +1070,28 @@ Return the window id of the terminal window. Return various integers describing terminal characteristics. +=item $x_display = $term->display_id + +Return the DISPLAY used by rxvt-unicode. + =item $lc_ctype = $term->locale Returns the LC_CTYPE category string used by this rxvt-unicode. -=item $x_display = $term->display_id +=item $env = $term->env -Return the DISPLAY used by rxvt-unicode. +Returns a copy of the environment in effect for the terminal as a hashref +similar to C<\%ENV>. + +=cut + +sub env { + if (my $env = $_[0]->_env) { + +{ map /^([^=]+)(?:=(.*))?$/s && ($1 => $2), @$env } + } else { + +{ %ENV } + } +} =item $modifiermask = $term->ModLevel3Mask @@ -1394,12 +1422,16 @@ sub show { local $urxvt::popup::self = $self; - local $ENV{LC_ALL} = $self->{term}->locale; + my $env = $self->{term}->env; + # we can't hope to reproduce the locale algorithm, so nuke LC_ALL and set LC_CTYPE. + delete $env->{LC_ALL}; + $env->{LC_CTYPE} = $self->{term}->locale; - urxvt->new ("--perl-lib" => "", "--perl-ext-common" => "", "-pty-fd" => -1, "-sl" => 0, "-b" => 0, - "--transient-for" => $self->{term}->parent, - "-display" => $self->{term}->display_id, - "-pe" => "urxvt-popup") + urxvt::term->new ($env, $self->{term}->resource ("name"), + "--perl-lib" => "", "--perl-ext-common" => "", "-pty-fd" => -1, "-sl" => 0, "-b" => 0, + "--transient-for" => $self->{term}->parent, + "-display" => $self->{term}->display_id, + "-pe" => "urxvt-popup") or die "unable to create popup window\n"; } @@ -1410,6 +1442,8 @@ sub DESTROY { $self->{term}->ungrab; } +=back + =head2 The C Class This class implements timer watchers/events. Time is represented as a diff --git a/src/xdefaults.C b/src/xdefaults.C index 90a62aba..d83b008f 100644 --- a/src/xdefaults.C +++ b/src/xdefaults.C @@ -22,17 +22,11 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *----------------------------------------------------------------------*/ -/*----------------------------------------------------------------------* - * get resources from ~/.Xdefaults or ~/.Xresources with the memory-saving - * default or with XGetDefault() (#define USE_XGETDEFAULT) - *----------------------------------------------------------------------*/ #include "../config.h" /* NECESSARY */ #include "rxvt.h" /* NECESSARY */ #include "version.h" -#include - #ifdef KEYSYM_RESOURCE #include "keyboard.h" #endif @@ -266,10 +260,8 @@ optList[] = { RSTRG (Rs_perl_ext_1, "perl-ext-common", "string"), //, "colon-separated list of perl extensions to enable"),TODO STRG (Rs_perl_ext_2, "perl-ext", "pe", "string", "colon-separated list of perl extensions to enable for this instance"), #endif -#if 0 && TODO -#if !defined(NO_RESOURCES) && defined(USE_XGETDEFAULT) +#ifndef NO_RESOURCES INFO ("xrm", "string", "X resource"), -#endif #endif INFO ("e", "command arg ...", "command to execute") }; @@ -283,6 +275,9 @@ optList[] = { static const char releasestring[] = "rxvt-unicode (" RXVTNAME ") v" VERSION " - released: " DATE "\n"; static const char optionsstring[] = "options: " +#if ENABLE_PERL + "perl," +#endif #if XFT "xft," #endif @@ -404,12 +399,6 @@ static const char optionsstring[] = "options: " #endif #if defined(NO_RESOURCES) "NoResources" -#else -# if defined(USE_XGETDEFAULT) - "XGetDefault" -# else - ".Xdefaults" -# endif #endif "\nUsage: "; /* Usage */ @@ -782,107 +771,8 @@ rxvt_term::parse_keysym (const char *str, const char *arg) } # endif /* KEYSYM_RESOURCE */ - -# ifndef USE_XGETDEFAULT -/*{{{ rxvt_get_xdefaults () */ -/* - * the matching algorithm used for memory-save fake resources - */ -void -rxvt_term::get_xdefaults (FILE *stream, const char *name) -{ - unsigned int len; - char *str, buffer[256]; - - if (stream == NULL) - return; - - len = strlen (name); - while ((str = fgets (buffer, sizeof (buffer), stream)) != NULL) - { - unsigned int entry, n; - - while (*str && isspace (*str)) - str++; /* leading whitespace */ - - if ((str[len] != '*' && str[len] != '.') - || (len && strncmp (str, name, len))) - continue; - str += (len + 1); /* skip `name*' or `name.' */ - -# ifdef KEYSYM_RESOURCE - if (!parse_keysym (str, NULL)) -# endif /* KEYSYM_RESOURCE */ - for (entry = 0; entry < optList_size; entry++) - { - const char *kw = optList[entry].kw; - - if (kw == NULL) - continue; - - n = strlen (kw); - if (str[n] == ':' && rxvt_Str_match (str, kw)) - { - /* skip `keyword:' */ - str += n + 1; - rxvt_Str_trim (str); - n = strlen (str); - - if (n && rs[optList[entry].doff] == NULL) - { - /* not already set */ - int s; - char *p = 0; - - for (int o = 0;;) - { - p = (char *)rxvt_realloc (p, o + n + 1); - memcpy (p + o, str, n); - o += n; - p[o] = 0; - - if (o == 0 || p[o - 1] != '\\') // continuation line - break; - - o--; // eat "\" - - if ((str = fgets (buffer, sizeof (buffer), stream)) == NULL) - break; - - rxvt_Str_trim (str); - n = strlen (str); - } - - rs[optList[entry].doff] = p; - allocated.push_back (p); - - if (optList_isBool (entry)) - { - s = strcasecmp (str, "true") == 0 - || strcasecmp (str, "yes") == 0 - || strcasecmp (str, "on") == 0 - || strcmp (str, "1") == 0; - - if (optList_isReverse (entry)) - s = !s; - - set_option (optList[entry].flag & Optflag_mask, s); - } - } - - break; - } - } - } - - rewind (stream); -} - -/*}}} */ -# endif /* ! USE_XGETDEFAULT */ #endif /* NO_RESOURCES */ -#ifdef USE_XGETDEFAULT char *get_res (XrmDatabase database, const char *program, const char *option) { char resource[512]; @@ -894,7 +784,6 @@ char *get_res (XrmDatabase database, const char *program, const char *option) return result.addr; } -#endif /*{{{ read the resources files */ /* @@ -907,116 +796,19 @@ rxvt_term::extract_resources () dDisp; #ifndef NO_RESOURCES - - char *homedir = (char *)getenv ("HOME"); - char fname[1024]; - -# if defined XAPPLOADDIR -# if defined(HAVE_XSETLOCALE) || defined(HAVE_SETLOCALE) - /* Compute the path of the possibly available localized Rxvt file */ - char localepath[1024]; - - if (locale) - snprintf (localepath, sizeof (localepath), XAPPLOADDIRLOCALE "/" RESCLASS, locale); - else - localepath[0] = 0; -# endif -# endif - -# ifdef USE_XGETDEFAULT - /* - * get resources using the X library function - */ - int entry; - - char *displayResource, *xe; - XrmName name_prefix[3]; - XrmClass class_prefix[3]; - XrmDatabase database, rdb1; - - database = NULL; - - // for ordering, see for example http://www.faqs.org/faqs/Xt-FAQ/ Subject: 20 - - // 6. System wide per application default file. - /* Add in Rxvt file */ -# if defined(HAVE_XSETLOCALE) || defined(HAVE_SETLOCALE) - if (*localepath - && ((rdb1 = XrmGetFileDatabase (localepath)) - || (rdb1 = XrmGetFileDatabase (XAPPLOADDIR "/" RESCLASS)))) -# endif - XrmMergeDatabases (rdb1, &database); - - /* Add in $XAPPLRESDIR/Rxvt only; not bothering with XUSERFILESEARCHPATH */ - if ((xe = (char *)getenv ("XAPPLRESDIR"))) - { - snprintf (fname, sizeof (fname), "%s/%s", xe, RESCLASS); - - if ((rdb1 = XrmGetFileDatabase (fname))) - XrmMergeDatabases (rdb1, &database); - } - - // 5. User's per application default file. - // none - - // 4. User's defaults file. - /* Get any Xserver defaults */ - displayResource = XResourceManagerString (disp); - if (displayResource != NULL) - { - if ((rdb1 = XrmGetStringDatabase (displayResource))) - XrmMergeDatabases (rdb1, &database); - } - else if (homedir) - { - snprintf (fname, sizeof (fname), "%s/.Xdefaults", homedir); - - if ((rdb1 = XrmGetFileDatabase (fname))) - XrmMergeDatabases (rdb1, &database); - } - - /* Get screen specific resources */ - displayResource = XScreenResourceString (ScreenOfDisplay (disp, display->screen)); - if (displayResource != NULL) - { - if ((rdb1 = XrmGetStringDatabase (displayResource))) - /* Merge with screen-independent resources */ - XrmMergeDatabases (rdb1, &database); - - XFree (displayResource); - } - - // 3. User's per host defaults file - /* Add in XENVIRONMENT file */ - if ((xe = (char *)getenv ("XENVIRONMENT")) - && (rdb1 = XrmGetFileDatabase (xe))) - XrmMergeDatabases (rdb1, &database); - else if (homedir) - { - struct utsname un; - - if (!uname (&un)) - { - snprintf (fname, sizeof (fname), "%s/.Xdefaults-%s", homedir, un.nodename); - - if ((rdb1 = XrmGetFileDatabase (fname))) - XrmMergeDatabases (rdb1, &database); - } - } - - xrmdatabase = database; + XrmDatabase database = XrmGetDatabase (display->display); /* * Query resources for options that affect us */ - for (entry = 0; entry < optList_size; entry++) + for (int entry = 0; entry < optList_size; entry++) { int s; char *p, *p0; const char *kw = optList[entry].kw; if (kw == NULL || rs[optList[entry].doff] != NULL) - continue; /* previously set */ + continue; // previously set p = get_res (database, rs[Rs_name], kw); p0 = get_res (database, "!INVALIDPROGRAMMENAMEDONTMATCH!", kw); @@ -1034,6 +826,8 @@ rxvt_term::extract_resources () if (p) { + p = strdup (p); + allocated.push_back (p); rs[optList[entry].doff] = p; if (optList_isBool (entry)) @@ -1055,6 +849,9 @@ rxvt_term::extract_resources () * [R5 or later]: enumerate the resource database */ # ifdef KEYSYM_RESOURCE + XrmName name_prefix[3]; + XrmClass class_prefix[3]; + name_prefix[0] = XrmStringToName (rs[Rs_name]); name_prefix[1] = XrmStringToName ("keysym"); name_prefix[2] = NULLQUARK; @@ -1075,72 +872,6 @@ rxvt_term::extract_resources () # endif # endif -# else /* USE_XGETDEFAULT */ - /* get resources the hard way, but save lots of memory */ - FILE *fd = NULL; - - if (homedir) - { - static const char *const xnames[2] = { ".Xdefaults", ".Xresources" }; - - for (int i = 0; i < (sizeof (xnames) / sizeof (xnames [0])); i++) - { - snprintf (fname, sizeof (fname), "%s/%s", homedir, xnames [i]); - - if ((fd = fopen (fname, "r")) != NULL) - break; - } - } - /* - * The normal order to match resources is the following: - * @ global resources (partial match, ~/.Xdefaults) - * @ application file resources (XAPPLOADDIR/Rxvt) - * @ class resources (~/.Xdefaults) - * @ private resources (~/.Xdefaults) - * - * However, for the hand-rolled resources, the matching algorithm - * checks if a resource string value has already been allocated - * and won't overwrite it with (in this case) a less specific - * resource value. - * - * This avoids multiple allocation. Also, when we've called this - * routine command-line string options have already been applied so we - * needn't to allocate for those resources. - * - * So, search in resources from most to least specific. - * - * Also, use a special sub-class so that we can use either or both of - * "XTerm" and "Rxvt" as class names. - */ - - get_xdefaults (fd, rs[Rs_name]); - get_xdefaults (fd, RESCLASS); -# ifdef RESFALLBACK - get_xdefaults (fd, RESFALLBACK); -# endif - -# if defined(XAPPLOADDIR) && defined(USE_XAPPLOADDIR) - { - FILE *ad = NULL; - -# if defined(HAVE_XSETLOCALE) || defined(HAVE_SETLOCALE) - if (!*localepath || (ad = fopen (localepath, "r")) == NULL) -# endif - ad = fopen (XAPPLOADDIR "/" RESCLASS, "r"); - if (ad != NULL) - { - get_xdefaults (ad, RESCLASS); - get_xdefaults (ad, ""); - fclose (ad); - } - } -# endif /* XAPPLOADDIR */ - - get_xdefaults (fd, ""); /* partial match */ - if (fd != NULL) - fclose (fd); -# endif /* USE_XGETDEFAULT */ - #endif /* NO_RESOURCES */ }