summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/readline/doc/rltech.texi2
-rw-r--r--lib/readline/doc/rluser.texi11
-rw-r--r--lib/readline/doc/version.texi6
-rw-r--r--lib/readline/nls.c85
-rw-r--r--lib/readline/readline.c2
-rw-r--r--lib/readline/rlprivate.h1
-rw-r--r--lib/sh/setlinebuf.c22
7 files changed, 99 insertions, 30 deletions
diff --git a/lib/readline/doc/rltech.texi b/lib/readline/doc/rltech.texi
index fe64a42c..95a57b6d 100644
--- a/lib/readline/doc/rltech.texi
+++ b/lib/readline/doc/rltech.texi
@@ -1184,7 +1184,7 @@ Returns the old timeout value.
@deftypefun int rl_set_timeout (unsigned int secs, unsigned int usecs)
Set a timeout for subsequent calls to @code{readline()}. If Readline does
not read a complete line, or the number of characters specified by
-@code{rl_num_chars_to_read}, before the duration specfied by @var{secs}
+@code{rl_num_chars_to_read}, before the duration specified by @var{secs}
(in seconds) and @var{usecs} (microseconds), it returns and sets
@code{RL_STATE_TIMEOUT} in @code{rl_readline_state}.
Passing 0 for @code{secs} and @code{usecs} cancels any previously set
diff --git a/lib/readline/doc/rluser.texi b/lib/readline/doc/rluser.texi
index 4a4cee47..fbe503e7 100644
--- a/lib/readline/doc/rluser.texi
+++ b/lib/readline/doc/rluser.texi
@@ -536,9 +536,12 @@ The default limit is @code{100}.
If set to @samp{on}, Readline will convert characters with the
eighth bit set to an @sc{ascii} key sequence by stripping the eighth
bit and prefixing an @key{ESC} character, converting them to a
-meta-prefixed key sequence. The default value is @samp{on}, but
+meta-prefixed key sequence.
+The default value is @samp{on}, but
will be set to @samp{off} if the locale is one that contains
eight-bit characters.
+This variable is dependent on the @code{LC_CTYPE} locale category, and
+may change if the locale is changed.
@item disable-completion
@vindex disable-completion
@@ -649,6 +652,8 @@ regardless of what the terminal claims it can support. The
default value is @samp{off}, but Readline will set it to @samp{on} if the
locale contains eight-bit characters.
The name @code{meta-flag} is a synonym for this variable.
+This variable is dependent on the @code{LC_CTYPE} locale category, and
+may change if the locale is changed.
@item isearch-terminators
@vindex isearch-terminators
@@ -731,6 +736,8 @@ eighth bit set directly rather than as a meta-prefixed escape
sequence.
The default is @samp{off}, but Readline will set it to @samp{on} if the
locale contains eight-bit characters.
+This variable is dependent on the @code{LC_CTYPE} locale category, and
+may change if the locale is changed.
@item page-completions
@vindex page-completions
@@ -845,7 +852,7 @@ to a string that is inserted when the key is pressed (a @var{macro}).
@ifset BashFeatures
The @w{@code{bind -p}} command displays Readline function names and
-bindings in a format that can put directly into an initialization file.
+bindings in a format that can be put directly into an initialization file.
@xref{Bash Builtins}.
@end ifset
diff --git a/lib/readline/doc/version.texi b/lib/readline/doc/version.texi
index cd3f8d85..65a84577 100644
--- a/lib/readline/doc/version.texi
+++ b/lib/readline/doc/version.texi
@@ -5,7 +5,7 @@ Copyright (C) 1988-2022 Free Software Foundation, Inc.
@set EDITION 8.2
@set VERSION 8.2
-@set UPDATED 11 March 2022
-@set UPDATED-MONTH March 2022
+@set UPDATED 12 August 2022
+@set UPDATED-MONTH August 2022
-@set LASTCHANGE Fri Mar 11 10:13:51 EST 2022
+@set LASTCHANGE Fri Aug 12 11:10:50 EDT 2022
diff --git a/lib/readline/nls.c b/lib/readline/nls.c
index 8447c10f..5c6a13b6 100644
--- a/lib/readline/nls.c
+++ b/lib/readline/nls.c
@@ -57,6 +57,9 @@
static int utf8locale (char *);
+#define RL_DEFAULT_LOCALE "C"
+static char *_rl_current_locale = 0;
+
#if !defined (HAVE_SETLOCALE)
/* A list of legal values for the LANG or LC_CTYPE environment variables.
If a locale name in this list is the value for the LC_ALL, LC_CTYPE,
@@ -132,50 +135,61 @@ _rl_init_locale (void)
that doesn't return anything, we set lspec to the empty string to
force the subsequent call to setlocale() to define the `native'
environment. */
+#if defined (HAVE_SETLOCALE)
if (lspec == 0 || *lspec == 0)
lspec = setlocale (LC_CTYPE, (char *)NULL);
if (lspec == 0)
lspec = "";
ret = setlocale (LC_CTYPE, lspec); /* ok, since it does not change locale */
+#else
+ ret = (lspec == 0 || *lspec == 0) ? RL_DEFAULT_LOCALE : lspec;
+#endif
_rl_utf8locale = (ret && *ret) ? utf8locale (ret) : 0;
+ _rl_current_locale = savestring (ret);
return ret;
}
-/* Check for LC_ALL, LC_CTYPE, and LANG and use the first with a value
- to decide the defaults for 8-bit character input and output. Returns
- 1 if we set eight-bit mode. */
-int
-_rl_init_eightbit (void)
-{
/* If we have setlocale(3), just check the current LC_CTYPE category
- value, and go into eight-bit mode if it's not C or POSIX. */
+ value (passed as LOCALESTR), and go into eight-bit mode if it's not "C"
+ or "POSIX". If FORCE is non-zero, we reset the locale variables to values
+ appropriate for the C locale if the locale is "C" or "POSIX". FORCE is 0
+ when this is called from _rl_init_eightbit, since we're modifying the
+ default initial values and don't need to change anything else. If we
+ don't have setlocale(3), we check the codeset portion of LOCALESTR against
+ a set of known values and go into eight-bit mode if it matches one of those.
+ Returns 1 if we set eight-bit (multibyte) mode. */
+static int
+_rl_set_localevars (char *localestr, int force)
+{
#if defined (HAVE_SETLOCALE)
- char *lspec, *t;
-
- t = _rl_init_locale (); /* returns static pointer */
-
- if (t && *t && (t[0] != 'C' || t[1]) && (STREQ (t, "POSIX") == 0))
+ if (localestr && *localestr && (localestr[0] != 'C' || localestr[1]) && (STREQ (localestr, "POSIX") == 0))
{
_rl_meta_flag = 1;
_rl_convert_meta_chars_to_ascii = 0;
_rl_output_meta_chars = 1;
return (1);
}
+ else if (force)
+ {
+ /* Default "C" locale settings. */
+ _rl_meta_flag = 0;
+ _rl_convert_meta_chars_to_ascii = 1;
+ _rl_output_meta_chars = 0;
+ return (0);
+ }
else
return (0);
#else /* !HAVE_SETLOCALE */
- char *lspec, *t;
+ char *t;
int i;
/* We don't have setlocale. Finesse it. Check the environment for the
appropriate variables and set eight-bit mode if they have the right
values. */
- lspec = _rl_get_locale_var ("LC_CTYPE");
-
- if (lspec == 0 || (t = normalize_codeset (lspec)) == 0)
+ if (localestr == 0 || (t = normalize_codeset (localestr)) == 0)
return (0);
for (i = 0; t && legal_lang_values[i]; i++)
if (STREQ (t, legal_lang_values[i]))
@@ -186,6 +200,14 @@ _rl_init_eightbit (void)
break;
}
+ if (force && legal_lang_values[i] == 0) /* didn't find it */
+ {
+ /* Default "C" locale settings. */
+ _rl_meta_flag = 0;
+ _rl_convert_meta_chars_to_ascii = 1;
+ _rl_output_meta_chars = 0;
+ }
+
_rl_utf8locale = *t ? STREQ (t, "utf8") : 0;
xfree (t);
@@ -193,6 +215,21 @@ _rl_init_eightbit (void)
#endif /* !HAVE_SETLOCALE */
}
+/* Check for LC_ALL, LC_CTYPE, and LANG and use the first with a value
+ to decide the defaults for 8-bit character input and output. Returns
+ 1 if we set eight-bit mode. */
+int
+_rl_init_eightbit (void)
+{
+ char *t, *ol;
+
+ ol = _rl_current_locale;
+ t = _rl_init_locale (); /* resets _rl_current_locale, returns static pointer */
+ xfree (ol);
+
+ return (_rl_set_localevars (t, 0));
+}
+
#if !defined (HAVE_SETLOCALE)
static char *
normalize_codeset (char *codeset)
@@ -289,3 +326,19 @@ find_codeset (char *name, size_t *lenp)
return result;
}
+
+void
+_rl_reset_locale (void)
+{
+ char *ol, *nl;
+
+ /* This should not be NULL; _rl_init_eightbit sets it on the first call to
+ readline() or rl_initialize(). */
+ ol = _rl_current_locale;
+ nl = _rl_init_locale (); /* resets _rl_current_locale */
+
+ if ((ol == 0 && nl) || (ol && nl && (STREQ (ol, nl) == 0)))
+ (void)_rl_set_localevars (nl, 1);
+
+ xfree (ol);
+}
diff --git a/lib/readline/readline.c b/lib/readline/readline.c
index 999a23d4..9d42a8d6 100644
--- a/lib/readline/readline.c
+++ b/lib/readline/readline.c
@@ -1186,7 +1186,7 @@ rl_initialize (void)
RL_SETSTATE(RL_STATE_INITIALIZED);
}
else
- (void)_rl_init_locale (); /* check current locale */
+ _rl_reset_locale (); /* check current locale and set locale variables */
/* Initialize the current line information. */
_rl_init_line_state ();
diff --git a/lib/readline/rlprivate.h b/lib/readline/rlprivate.h
index 24ceb3a4..d87d07a7 100644
--- a/lib/readline/rlprivate.h
+++ b/lib/readline/rlprivate.h
@@ -364,6 +364,7 @@ extern void _rl_revert_all_lines (void);
/* nls.c */
extern char *_rl_init_locale (void);
extern int _rl_init_eightbit (void);
+extern void _rl_reset_locale (void);
/* parens.c */
extern void _rl_enable_paren_matching (int);
diff --git a/lib/sh/setlinebuf.c b/lib/sh/setlinebuf.c
index 67805ed0..dd76e9fc 100644
--- a/lib/sh/setlinebuf.c
+++ b/lib/sh/setlinebuf.c
@@ -1,6 +1,6 @@
/* setlinebuf.c - line-buffer a stdio stream. */
-/* Copyright (C) 1997 Free Software Foundation, Inc.
+/* Copyright (C) 1997,2022 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@@ -25,31 +25,39 @@
#include <xmalloc.h>
#if defined (USING_BASH_MALLOC)
-# define LBUF_BUFSIZE 1008
+# define LBUF_BUFSIZE 2016
#else
# define LBUF_BUFSIZE BUFSIZ
#endif
+static char *stdoutbuf = 0;
+static char *stderrbuf = 0;
+
/* Cause STREAM to buffer lines as opposed to characters or blocks. */
int
sh_setlinebuf (stream)
FILE *stream;
{
- char *local_linebuf;
-
#if !defined (HAVE_SETLINEBUF) && !defined (HAVE_SETVBUF)
return (0);
#endif
+#if defined (HAVE_SETVBUF)
+ char *local_linebuf;
+
#if defined (USING_BASH_MALLOC)
- local_linebuf = (char *)xmalloc (LBUF_BUFSIZE);
+ if (stream == stdout && stdoutbuf == 0)
+ local_linebuf = stdoutbuf = (char *)xmalloc (LBUF_BUFSIZE);
+ else if (stream == stderr && stderrbuf == 0)
+ local_linebuf = stderrbuf = (char *)xmalloc (LBUF_BUFSIZE);
+ else
+ local_linebuf = (char *)NULL; /* let stdio handle it */
#else
local_linebuf = (char *)NULL;
#endif
-#if defined (HAVE_SETVBUF)
return (setvbuf (stream, local_linebuf, _IOLBF, LBUF_BUFSIZE));
-# else /* !HAVE_SETVBUF */
+#else /* !HAVE_SETVBUF */
setlinebuf (stream);
return (0);