mirror of
https://https.git.savannah.gnu.org/git/bash.git
synced 2026-08-07 18:52:35 +02:00
commit bash-20190215 snapshot
This commit is contained in:
+46
-14
@@ -135,12 +135,13 @@ rl_add_defun (const char *name, rl_command_func_t *function, int key)
|
||||
int
|
||||
rl_bind_key (int key, rl_command_func_t *function)
|
||||
{
|
||||
char keyseq[3];
|
||||
char keyseq[4];
|
||||
int l;
|
||||
|
||||
if (key < 0)
|
||||
if (key < 0 || key > largest_char)
|
||||
return (key);
|
||||
|
||||
/* Want to make this a multi-character key sequence with an ESC prefix */
|
||||
if (META_CHAR (key) && _rl_convert_meta_chars_to_ascii)
|
||||
{
|
||||
if (_rl_keymap[ESC].type == ISKMAP)
|
||||
@@ -153,7 +154,14 @@ rl_bind_key (int key, rl_command_func_t *function)
|
||||
escmap[key].function = function;
|
||||
return (0);
|
||||
}
|
||||
return (key);
|
||||
|
||||
/* Otherwise, let's just let rl_generic_bind handle the key sequence.
|
||||
We start it off with ESC here and let the code below add the rest
|
||||
of the sequence. */
|
||||
keyseq[0] = ESC;
|
||||
l = 1;
|
||||
key = UNMETA(key);
|
||||
goto bind_keyseq;
|
||||
}
|
||||
|
||||
/* If it's bound to a function or macro, just overwrite. Otherwise we have
|
||||
@@ -168,6 +176,7 @@ rl_bind_key (int key, rl_command_func_t *function)
|
||||
else
|
||||
{
|
||||
l = 0;
|
||||
bind_keyseq:
|
||||
if (key == '\\')
|
||||
keyseq[l++] = '\\';
|
||||
keyseq[l++] = key;
|
||||
@@ -397,6 +406,9 @@ rl_generic_bind (int type, const char *keyseq, char *data, Keymap map)
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* We now rely on rl_translate_keyseq to do this conversion, so this
|
||||
check is superfluous. */
|
||||
#if 0
|
||||
if (META_CHAR (ic) && _rl_convert_meta_chars_to_ascii)
|
||||
{
|
||||
ic = UNMETA (ic);
|
||||
@@ -406,6 +418,7 @@ rl_generic_bind (int type, const char *keyseq, char *data, Keymap map)
|
||||
map = FUNCTION_TO_KEYMAP (map, ESC);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if ((i + 1) < keys_len)
|
||||
{
|
||||
@@ -486,13 +499,25 @@ rl_generic_bind (int type, const char *keyseq, char *data, Keymap map)
|
||||
return 0;
|
||||
}
|
||||
|
||||
#define ADD_NORMAL_CHAR(c) \
|
||||
do { \
|
||||
if (META_CHAR (c) && _rl_convert_meta_chars_to_ascii) \
|
||||
{ \
|
||||
array[l++] = ESC; \
|
||||
array[l++] = UNMETA (c); \
|
||||
} \
|
||||
else \
|
||||
array[l++] = (c); \
|
||||
} while (0)
|
||||
|
||||
/* Translate the ASCII representation of SEQ, stuffing the values into ARRAY,
|
||||
an array of characters. LEN gets the final length of ARRAY. Return
|
||||
non-zero if there was an error parsing SEQ. */
|
||||
int
|
||||
rl_translate_keyseq (const char *seq, char *array, int *len)
|
||||
{
|
||||
register int i, c, l, temp;
|
||||
register int i, l, temp;
|
||||
unsigned char c;
|
||||
|
||||
for (i = l = 0; c = seq[i]; i++)
|
||||
{
|
||||
@@ -519,9 +544,13 @@ rl_translate_keyseq (const char *seq, char *array, int *len)
|
||||
else if (c == 'M')
|
||||
{
|
||||
i++; /* seq[i] == '-' */
|
||||
/* XXX - obey convert-meta setting */
|
||||
if (_rl_convert_meta_chars_to_ascii && _rl_keymap[ESC].type == ISKMAP)
|
||||
array[l++] = ESC; /* ESC is meta-prefix */
|
||||
/* XXX - obey convert-meta setting, convert to key seq */
|
||||
if (_rl_convert_meta_chars_to_ascii)
|
||||
{
|
||||
array[l++] = ESC; /* ESC is meta-prefix */
|
||||
i++;
|
||||
array[l++] = UNMETA (seq[i]); /* UNMETA just in case */
|
||||
}
|
||||
else if (seq[i+1] == '\\' && seq[i+2] == 'C' && seq[i+3] == '-')
|
||||
{
|
||||
i += 4;
|
||||
@@ -590,7 +619,8 @@ rl_translate_keyseq (const char *seq, char *array, int *len)
|
||||
for (temp = 2, c -= '0'; ISOCTAL ((unsigned char)seq[i]) && temp--; i++)
|
||||
c = (c * 8) + OCTVALUE (seq[i]);
|
||||
i--; /* auto-increment in for loop */
|
||||
array[l++] = c & largest_char;
|
||||
c &= largest_char;
|
||||
ADD_NORMAL_CHAR (c);
|
||||
break;
|
||||
case 'x':
|
||||
i++;
|
||||
@@ -599,16 +629,18 @@ rl_translate_keyseq (const char *seq, char *array, int *len)
|
||||
if (temp == 2)
|
||||
c = 'x';
|
||||
i--; /* auto-increment in for loop */
|
||||
array[l++] = c & largest_char;
|
||||
c &= largest_char;
|
||||
ADD_NORMAL_CHAR (c);
|
||||
break;
|
||||
default: /* backslashes before non-special chars just add the char */
|
||||
array[l++] = c;
|
||||
c &= largest_char;
|
||||
ADD_NORMAL_CHAR (c);
|
||||
break; /* the backslash is stripped */
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
array[l++] = c;
|
||||
ADD_NORMAL_CHAR (c);
|
||||
}
|
||||
|
||||
*len = l;
|
||||
@@ -809,7 +841,7 @@ _rl_function_of_keyseq_internal (const char *keyseq, size_t len, Keymap map, int
|
||||
{
|
||||
/* If this is the last key in the key sequence, return the
|
||||
map. */
|
||||
if (keyseq[i + 1] == '\0')
|
||||
if (i + 1 == len)
|
||||
{
|
||||
if (type)
|
||||
*type = ISKMAP;
|
||||
@@ -822,9 +854,9 @@ _rl_function_of_keyseq_internal (const char *keyseq, size_t len, Keymap map, int
|
||||
/* If we're not at the end of the key sequence, and the current key
|
||||
is bound to something other than a keymap, then the entire key
|
||||
sequence is not bound. */
|
||||
else if (map[ic].type != ISKMAP && keyseq[i+1])
|
||||
else if (map[ic].type != ISKMAP && i+1 < len)
|
||||
return ((rl_command_func_t *)NULL);
|
||||
else /* map[ic].type != ISKMAP && keyseq[i+1] == 0 */
|
||||
else /* map[ic].type != ISKMAP && i+1 == len */
|
||||
{
|
||||
if (type)
|
||||
*type = map[ic].type;
|
||||
|
||||
Reference in New Issue
Block a user