[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: --with-installed-readline breaks tilde-expansion
From: |
Eric Blake |
Subject: |
Re: --with-installed-readline breaks tilde-expansion |
Date: |
Sat, 23 Jul 2005 07:14:24 -0600 |
User-agent: |
Mozilla Thunderbird 1.0.2 (Windows/20050317) |
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
According to Eric Blake on 7/8/2005 6:48 AM:
> On the cygwin list, a difference was pointed out between compilations of
> bash that avoid or use --with-installed-readline:
>
> static_bash$ echo $HOME ~
> /home/eblake /home/eblake
> static_bash$ HOME=/tmp; echo $HOME ~
> /tmp /tmp
>
> dynamic_bash$ echo $HOME ~
> /home/eblake /home/eblake
> dynamic_bash$ HOME=/tmp; echo $HOME ~
> /tmp /home/eblake
The following patch, to both readline and bash, allows readline to export
a hook (rather than trying to import a function, which doesn't work in
dynamic libraries for at least cygwin), so that bash can then override
getenv() even within the context of a dynamic readline library. It fixes
not only tilde expansion (HOME), but also other uses of sh_get_env_value,
where readline needs to read environment variables from bash, rather than
the original program environ: INPUTRC, LC_ALL, LANG, EMACS, TERM, COLUMNS,
and LINES.
- --
Life is short - so eat dessert first!
Eric Blake ebb9@byu.net
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org
iD8DBQFC4kKv84KuGfSFAYARAlv8AKC35rPC4MuIL/V7Hgo7TaEybefjBQCfQ6B9
gmVZVetAC8cU0PCdq9EqAgM=
=imgC
-----END PGP SIGNATURE-----
--- bash-3.0-orig/bashline.c 2005-07-22 07:39:35.654625000 -0600
+++ bash-3.0/bashline.c 2005-07-22 07:24:06.170250000 -0600
@@ -1,6 +1,6 @@
/* bashline.c -- Bash's interface to the readline library. */
-/* Copyright (C) 1987-2004 Free Software Foundation, Inc.
+/* Copyright (C) 1987-2005 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@@ -485,7 +485,11 @@
rl_filename_dequoting_function = bash_dequote_filename;
rl_char_is_quoted_p = char_is_quoted;
+ /* On cygwin, dynamically linked readline can't see bash's environment
+ without this hook. */
+ rl_getenv_hook = sh_get_env_value;
+
#if 0
/* This is superfluous and makes it impossible to use tab completion in
vi mode even when explicitly binding it in ~/.inputrc. sv_strict_posix()
--- bash-3.0-orig/lib/readline/readline.c 2003-09-18 09:04:18.000000000
-0600
+++ bash-3.0/lib/readline/readline.c 2005-07-22 07:24:19.967125000 -0600
@@ -996,4 +996,8 @@
return (0);
}
+
+/* Hook to allow application (such as bash) to override getenv() when
+ readline is dynamically linked. */
+rl_getenv_func_t *rl_getenv_hook = (rl_getenv_func_t *)NULL;
--- bash-3.0-orig/lib/readline/readline.h 2004-07-13 08:54:27.000000000
-0600
+++ bash-3.0/lib/readline/readline.h 2005-07-22 07:24:20.029625000 -0600
@@ -829,7 +829,10 @@
extern int rl_save_state PARAMS((struct readline_state *));
extern int rl_restore_state PARAMS((struct readline_state *));
+/* If non-null, the address of a replacement to getenv. */
+extern rl_getenv_func_t *rl_getenv_hook;
+
#ifdef __cplusplus
}
#endif
--- bash-3.0-orig/lib/readline/rltypedefs.h 2004-01-28 11:31:26.000000000
-0700
+++ bash-3.0/lib/readline/rltypedefs.h 2005-07-22 07:24:20.232750000 -0600
@@ -85,7 +85,9 @@
typedef char *rl_cpcpfunc_t PARAMS((char *));
typedef char *rl_cpcppfunc_t PARAMS((char **));
+typedef char *rl_getenv_func_t PARAMS((const char *));
+
#endif /* _RL_FUNCTION_TYPEDEF */
#ifdef __cplusplus
--- bash-3.0-orig/lib/readline/shell.c 2005-07-19 06:26:28.828000000 -0600
+++ bash-3.0/lib/readline/shell.c 2005-07-19 20:50:12.374875000 -0600
@@ -53,0 +53,0 @@
#include <stdio.h>
+#include "readline.h"
#include "rlstdc.h"
#include "rlshell.h"
#include "xmalloc.h"
@@ -149,5 +150,7 @@
sh_get_env_value (varname)
const char *varname;
{
+ if (rl_getenv_hook)
+ return (rl_getenv_hook) (varname);
return ((char *)getenv (varname));
}