summaryrefslogtreecommitdiff
path: root/readline.c
diff options
context:
space:
mode:
Diffstat (limited to 'readline.c')
-rw-r--r--readline.c60
1 files changed, 42 insertions, 18 deletions
diff --git a/readline.c b/readline.c
index 9d42a8d..9790909 100644
--- a/readline.c
+++ b/readline.c
@@ -1,7 +1,7 @@
/* readline.c -- a general facility for reading lines of input
with emacs style editing and completion. */
-/* Copyright (C) 1987-2022 Free Software Foundation, Inc.
+/* Copyright (C) 1987-2024 Free Software Foundation, Inc.
This file is part of the GNU Readline Library (Readline), a library
for reading lines of text with interactive input and history editing.
@@ -262,7 +262,7 @@ _rl_keyseq_cxt *_rl_kscxt = 0;
int rl_executing_key;
char *rl_executing_keyseq = 0;
-int _rl_executing_keyseq_size = 0;
+size_t _rl_executing_keyseq_size = 0;
struct _rl_cmd _rl_pending_command;
struct _rl_cmd *_rl_command_to_execute = (struct _rl_cmd *)NULL;
@@ -474,17 +474,12 @@ readline_internal_setup (void)
RL_CHECK_SIGNALS ();
}
-STATIC_CALLBACK char *
-readline_internal_teardown (int eof)
+STATIC_CALLBACK void
+readline_common_teardown (void)
{
char *temp;
HIST_ENTRY *entry;
- RL_CHECK_SIGNALS ();
-
- if (eof)
- RL_SETSTATE (RL_STATE_EOF); /* XXX */
-
/* Restore the original of this history line, iff the line that we
are editing was originally in the history, AND the line has changed. */
entry = current_history ();
@@ -510,6 +505,17 @@ readline_internal_teardown (int eof)
rid of it now. */
if (rl_undo_list)
rl_free_undo_list ();
+}
+
+STATIC_CALLBACK char *
+readline_internal_teardown (int eof)
+{
+ RL_CHECK_SIGNALS ();
+
+ if (eof)
+ RL_SETSTATE (RL_STATE_EOF); /* XXX */
+
+ readline_common_teardown ();
/* Disable the meta key, if this terminal has one and we were told to use it.
The check whether or not we sent the enable string is in
@@ -566,6 +572,7 @@ readline_internal_charloop (void)
{
static int lastc, eof_found;
int c, code, lk, r;
+ static procenv_t olevel;
lastc = EOF;
@@ -576,6 +583,9 @@ readline_internal_charloop (void)
#endif
lk = _rl_last_command_was_kill;
+ /* Save and restore _rl_top_level even though most of the time it
+ doesn't matter. */
+ memcpy ((void *)olevel, (void *)_rl_top_level, sizeof (procenv_t));
#if defined (HAVE_POSIX_SIGSETJMP)
code = sigsetjmp (_rl_top_level, 0);
#else
@@ -586,13 +596,14 @@ readline_internal_charloop (void)
{
(*rl_redisplay_function) ();
_rl_want_redisplay = 0;
+ if (RL_ISSTATE (RL_STATE_CALLBACK))
+ memcpy ((void *)_rl_top_level, (void *)olevel, sizeof (procenv_t));
/* If we longjmped because of a timeout, handle it here. */
if (RL_ISSTATE (RL_STATE_TIMEOUT))
{
RL_SETSTATE (RL_STATE_DONE);
- rl_done = 1;
- return 1;
+ return (rl_done = 1);
}
/* If we get here, we're not being called from something dispatched
@@ -703,6 +714,7 @@ readline_internal_charloop (void)
_rl_internal_char_cleanup ();
#if defined (READLINE_CALLBACKS)
+ memcpy ((void *)_rl_top_level, (void *)olevel, sizeof (procenv_t));
return 0;
#else
}
@@ -899,8 +911,17 @@ _rl_dispatch_subseq (register int key, Keymap map, int got_subseq)
{
/* Special case rl_do_lowercase_version (). */
if (func == rl_do_lowercase_version)
- /* Should we do anything special if key == ANYOTHERKEY? */
- return (_rl_dispatch (_rl_to_lower ((unsigned char)key), map));
+ {
+ /* Should we do anything special if key == ANYOTHERKEY? */
+ newkey = _rl_to_lower ((unsigned char)key);
+ if (newkey != key)
+ return (_rl_dispatch (newkey, map));
+ else
+ {
+ rl_ding (); /* gentle failure */
+ return 0;
+ }
+ }
rl_executing_keymap = map;
rl_executing_key = key;
@@ -1109,7 +1130,11 @@ _rl_subseq_result (int r, Keymap map, int key, int got_subseq)
type = m[ANYOTHERKEY].type;
func = m[ANYOTHERKEY].function;
if (type == ISFUNC && func == rl_do_lowercase_version)
- r = _rl_dispatch (_rl_to_lower ((unsigned char)key), map);
+ {
+ int newkey = _rl_to_lower ((unsigned char)key);
+ /* check that there is actually a lowercase version to avoid infinite recursion */
+ r = (newkey != key) ? _rl_dispatch (newkey, map) : 1;
+ }
else if (type == ISFUNC)
{
/* If we shadowed a function, whatever it is, we somehow need a
@@ -1322,9 +1347,8 @@ readline_initialize_everything (void)
_rl_parse_colors ();
#endif
- rl_executing_keyseq = malloc (_rl_executing_keyseq_size = 16);
- if (rl_executing_keyseq)
- rl_executing_keyseq[rl_key_sequence_length = 0] = '\0';
+ rl_executing_keyseq = xmalloc (_rl_executing_keyseq_size = 16);
+ rl_executing_keyseq[rl_key_sequence_length = 0] = '\0';
}
/* If this system allows us to look at the values of the regular
@@ -1562,7 +1586,7 @@ void
_rl_add_executing_keyseq (int key)
{
RESIZE_KEYSEQ_BUFFER ();
- rl_executing_keyseq[rl_key_sequence_length++] = key;
+ rl_executing_keyseq[rl_key_sequence_length++] = key;
}
/* `delete' the last character added to the executing key sequence. Use this