diff options
author | unknown <df@pippilotta.erinye.com> | 2007-11-19 14:38:08 +0100 |
---|---|---|
committer | unknown <df@pippilotta.erinye.com> | 2007-11-19 14:38:08 +0100 |
commit | 17146fc93d49fc4354f791f9c269fc21d5000eb6 (patch) | |
tree | 6886afa4046d456ba17671394e79a76cec21267a /cmd-line-utils/readline/bind.c | |
parent | 7bb73945459e71bdd8fa1297dc3fd313306235cc (diff) | |
download | mariadb-git-17146fc93d49fc4354f791f9c269fc21d5000eb6.tar.gz |
Update readline to version 5.2. This fixes bug#18431.
cmd-line-utils/readline/INSTALL:
update readline to version 5.2
cmd-line-utils/readline/README:
update readline to version 5.2
cmd-line-utils/readline/bind.c:
update readline to version 5.2
cmd-line-utils/readline/callback.c:
update readline to version 5.2
cmd-line-utils/readline/chardefs.h:
update readline to version 5.2
cmd-line-utils/readline/compat.c:
update readline to version 5.2
cmd-line-utils/readline/complete.c:
update readline to version 5.2
cmd-line-utils/readline/configure.in:
update readline to version 5.2
cmd-line-utils/readline/display.c:
update readline to version 5.2
cmd-line-utils/readline/funmap.c:
update readline to version 5.2
cmd-line-utils/readline/histexpand.c:
update readline to version 5.2
cmd-line-utils/readline/histfile.c:
update readline to version 5.2
cmd-line-utils/readline/history.c:
update readline to version 5.2
cmd-line-utils/readline/histsearch.c:
update readline to version 5.2
cmd-line-utils/readline/input.c:
update readline to version 5.2
cmd-line-utils/readline/isearch.c:
update readline to version 5.2
cmd-line-utils/readline/keymaps.c:
update readline to version 5.2
cmd-line-utils/readline/kill.c:
update readline to version 5.2
cmd-line-utils/readline/macro.c:
update readline to version 5.2
cmd-line-utils/readline/mbutil.c:
update readline to version 5.2
cmd-line-utils/readline/misc.c:
update readline to version 5.2
cmd-line-utils/readline/nls.c:
update readline to version 5.2
cmd-line-utils/readline/parens.c:
update readline to version 5.2
cmd-line-utils/readline/readline.c:
update readline to version 5.2
cmd-line-utils/readline/readline.h:
update readline to version 5.2
cmd-line-utils/readline/rlconf.h:
update readline to version 5.2
cmd-line-utils/readline/rldefs.h:
update readline to version 5.2
cmd-line-utils/readline/rlmbutil.h:
update readline to version 5.2
cmd-line-utils/readline/rlprivate.h:
update readline to version 5.2
cmd-line-utils/readline/rltty.c:
update readline to version 5.2
cmd-line-utils/readline/savestring.c:
update readline to version 5.2
cmd-line-utils/readline/search.c:
update readline to version 5.2
cmd-line-utils/readline/shell.c:
update readline to version 5.2
cmd-line-utils/readline/signals.c:
update readline to version 5.2
cmd-line-utils/readline/terminal.c:
update readline to version 5.2
cmd-line-utils/readline/text.c:
update readline to version 5.2
cmd-line-utils/readline/tilde.c:
update readline to version 5.2
cmd-line-utils/readline/tilde.h:
update readline to version 5.2
cmd-line-utils/readline/undo.c:
update readline to version 5.2
cmd-line-utils/readline/util.c:
update readline to version 5.2
cmd-line-utils/readline/vi_keymap.c:
update readline to version 5.2
cmd-line-utils/readline/vi_mode.c:
update readline to version 5.2
cmd-line-utils/readline/xmalloc.c:
update readline to version 5.2
Diffstat (limited to 'cmd-line-utils/readline/bind.c')
-rw-r--r-- | cmd-line-utils/readline/bind.c | 310 |
1 files changed, 201 insertions, 109 deletions
diff --git a/cmd-line-utils/readline/bind.c b/cmd-line-utils/readline/bind.c index 568c3e8776a..08c906bfcc3 100644 --- a/cmd-line-utils/readline/bind.c +++ b/cmd-line-utils/readline/bind.c @@ -1,6 +1,6 @@ /* bind.c -- key binding and startup file support for the readline library. */ -/* Copyright (C) 1987, 1989, 1992 Free Software Foundation, Inc. +/* Copyright (C) 1987-2006 Free Software Foundation, Inc. This file is part of the GNU Readline Library, a library for reading lines of text with interactive input and history editing. @@ -26,7 +26,9 @@ # include <floss.h> #endif -#include "config_readline.h" +#if defined (HAVE_CONFIG_H) +# include <config.h> +#endif #include <stdio.h> #include <sys/types.h> @@ -75,6 +77,9 @@ static char *_rl_read_file PARAMS((char *, size_t *)); static void _rl_init_file_error PARAMS((const char *)); static int _rl_read_init_file PARAMS((const char *, int)); static int glean_key_from_name PARAMS((char *)); +static int find_boolean_var PARAMS((const char *)); + +static char *_rl_get_string_variable_value PARAMS((const char *)); static int substring_member_of_array PARAMS((char *, const char **)); static int currently_reading_init_file; @@ -337,10 +342,9 @@ rl_generic_bind (type, keyseq, data, map) KEYMAP_ENTRY k; k.function = 0; - k.type= 0; /* If no keys to bind to, exit right away. */ - if (!keyseq || !*keyseq) + if (keyseq == 0 || *keyseq == 0) { if (type == ISMACR) free (data); @@ -366,9 +370,12 @@ rl_generic_bind (type, keyseq, data, map) ic = uc; if (ic < 0 || ic >= KEYMAP_SIZE) - return -1; + { + free (keys); + return -1; + } - if (_rl_convert_meta_chars_to_ascii && META_CHAR (ic)) + if (META_CHAR (ic) && _rl_convert_meta_chars_to_ascii) { ic = UNMETA (ic); if (map[ESC].type == ISKMAP) @@ -435,7 +442,7 @@ rl_translate_keyseq (seq, array, len) { register int i, c, l, temp; - for (i = l = 0; (c = seq[i]); i++) + for (i = l = 0; c = seq[i]; i++) { if (c == '\\') { @@ -458,8 +465,24 @@ rl_translate_keyseq (seq, array, len) } else if (c == 'M') { - i++; - array[l++] = ESC; /* ESC is meta-prefix */ + 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 */ + else if (seq[i+1] == '\\' && seq[i+2] == 'C' && seq[i+3] == '-') + { + i += 4; + temp = (seq[i] == '?') ? RUBOUT : CTRL (_rl_to_upper (seq[i])); + array[l++] = META (temp); + } + else + { + /* This doesn't yet handle things like \M-\a, which may + or may not have any reasonable meaning. You're + probably better off using straight octal or hex. */ + i++; + array[l++] = META (seq[i]); + } } else if (c == 'C') { @@ -554,6 +577,11 @@ rl_untranslate_keyseq (seq) kseq[i++] = '-'; c = UNMETA (c); } + else if (c == ESC) + { + kseq[i++] = '\\'; + c = 'e'; + } else if (CTRL_CHAR (c)) { kseq[i++] = '\\'; @@ -602,7 +630,12 @@ _rl_untranslate_macro_value (seq) *r++ = '-'; c = UNMETA (c); } - else if (CTRL_CHAR (c) && c != ESC) + else if (c == ESC) + { + *r++ = '\\'; + c = 'e'; + } + else if (CTRL_CHAR (c)) { *r++ = '\\'; *r++ = 'C'; @@ -661,7 +694,7 @@ rl_function_of_keyseq (keyseq, map, type) { register int i; - if (!map) + if (map == 0) map = _rl_keymap; for (i = 0; keyseq && keyseq[i]; i++) @@ -670,25 +703,27 @@ rl_function_of_keyseq (keyseq, map, type) if (META_CHAR (ic) && _rl_convert_meta_chars_to_ascii) { - if (map[ESC].type != ISKMAP) + if (map[ESC].type == ISKMAP) + { + map = FUNCTION_TO_KEYMAP (map, ESC); + ic = UNMETA (ic); + } + /* XXX - should we just return NULL here, since this obviously + doesn't match? */ + else { if (type) *type = map[ESC].type; return (map[ESC].function); } - else - { - map = FUNCTION_TO_KEYMAP (map, ESC); - ic = UNMETA (ic); - } } if (map[ic].type == ISKMAP) { /* If this is the last key in the key sequence, return the map. */ - if (!keyseq[i + 1]) + if (keyseq[i + 1] == '\0') { if (type) *type = ISKMAP; @@ -698,7 +733,12 @@ rl_function_of_keyseq (keyseq, map, type) else map = FUNCTION_TO_KEYMAP (map, ic); } - else + /* 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]) + return ((rl_command_func_t *)NULL); + else /* map[ic].type != ISKMAP && keyseq[i+1] == 0 */ { if (type) *type = map[ic].type; @@ -736,8 +776,7 @@ _rl_read_file (filename, sizep) file_size = (size_t)finfo.st_size; /* check for overflow on very large files */ - if ((long long) file_size != (long long) finfo.st_size || - file_size + 1 < file_size) + if (file_size != finfo.st_size || file_size + 1 < file_size) { if (file >= 0) close (file); @@ -767,8 +806,8 @@ _rl_read_file (filename, sizep) /* Re-read the current keybindings file. */ int -rl_re_read_init_file (int count __attribute__((unused)), - int ignore __attribute__((unused))) +rl_re_read_init_file (count, ignore) + int count, ignore; { int r; r = rl_read_init_file ((const char *)NULL); @@ -781,6 +820,7 @@ rl_re_read_init_file (int count __attribute__((unused)), 1. the filename used for the previous call 2. the value of the shell variable `INPUTRC' 3. ~/.inputrc + 4. /etc/inputrc If the file existed and could be opened and read, 0 is returned, otherwise errno is returned. */ int @@ -789,17 +829,18 @@ rl_read_init_file (filename) { /* Default the filename. */ if (filename == 0) + filename = last_readline_init_file; + if (filename == 0) + filename = sh_get_env_value ("INPUTRC"); + if (filename == 0 || *filename == 0) { - filename = last_readline_init_file; - if (filename == 0) - filename = sh_get_env_value ("INPUTRC"); - if (filename == 0) - filename = DEFAULT_INPUTRC; + filename = DEFAULT_INPUTRC; + /* Try to read DEFAULT_INPUTRC; fall back to SYS_INPUTRC on failure */ + if (_rl_read_init_file (filename, 0) == 0) + return 0; + filename = SYS_INPUTRC; } - if (*filename == 0) - filename = DEFAULT_INPUTRC; - #if defined (__MSDOS__) if (_rl_read_init_file (filename, 0) == 0) return 0; @@ -989,7 +1030,8 @@ parser_if (args) /* Invert the current parser state if there is anything on the stack. */ static int -parser_else (char *args __attribute__((unused))) +parser_else (args) + char *args; { register int i; @@ -1019,7 +1061,8 @@ parser_else (char *args __attribute__((unused))) /* Terminate a conditional, popping the value of _rl_parsing_conditionalized_out from the stack. */ static int -parser_endif (char *args __attribute__((unused))) +parser_endif (args) + char *args; { if (if_stack_depth) _rl_parsing_conditionalized_out = if_stack[--if_stack_depth]; @@ -1142,7 +1185,7 @@ rl_parse_and_bind (string) { int passc = 0; - for (i = 1; (c = string[i]); i++) + for (i = 1; c = string[i]; i++) { if (passc) { @@ -1183,9 +1226,9 @@ rl_parse_and_bind (string) /* If this is a command to set a variable, then do that. */ if (_rl_stricmp (string, "set") == 0) { - char *var = string + i; - char *value; + char *var, *value, *e; + var = string + i; /* Make VAR point to start of variable name. */ while (*var && whitespace (*var)) var++; @@ -1196,6 +1239,20 @@ rl_parse_and_bind (string) *value++ = '\0'; while (*value && whitespace (*value)) value++; + /* Strip trailing whitespace from values to boolean variables. Temp + fix until I get a real quoted-string parser here. */ + i = find_boolean_var (var); + if (i >= 0) + { + /* remove trailing whitespace */ + e = value + strlen (value) - 1; + while (e >= value && whitespace (*e)) + e--; + e++; /* skip back to whitespace or EOS */ + if (*e && e >= value) + *e = '\0'; + } + rl_variable_bind (var, value); return 0; } @@ -1216,9 +1273,10 @@ rl_parse_and_bind (string) the quoted string delimiter, like the shell. */ if (*funname == '\'' || *funname == '"') { - int delimiter = string[i++], passc; + int delimiter, passc; - for (passc = 0; (c = string[i]); i++) + delimiter = string[i++]; + for (passc = 0; c = string[i]; i++) { if (passc) { @@ -1353,6 +1411,7 @@ static struct { int *value; int flags; } boolean_varlist [] = { + { "bind-tty-special-chars", &_rl_bind_stty_chars, 0 }, { "blink-matching-paren", &rl_blink_matching_paren, V_SPECIAL }, { "byte-oriented", &rl_byte_oriented, 0 }, { "completion-ignore-case", &_rl_completion_case_fold, 0 }, @@ -1377,7 +1436,7 @@ static struct { #if defined (VISIBLE_STATS) { "visible-stats", &rl_visible_stats, 0 }, #endif /* VISIBLE_STATS */ - { (char *)NULL, (int *)NULL, 0 } + { (char *)NULL, (int *)NULL } }; static int @@ -1446,7 +1505,7 @@ static struct { { "editing-mode", V_STRING, sv_editmode }, { "isearch-terminators", V_STRING, sv_isrchterm }, { "keymap", V_STRING, sv_keymap }, - { (char *)NULL, 0, 0 } + { (char *)NULL, 0 } }; static int @@ -1466,13 +1525,32 @@ find_string_var (name) values result in 0 (false). */ static int bool_to_int (value) -const char *value; + const char *value; { return (value == 0 || *value == '\0' || (_rl_stricmp (value, "on") == 0) || (value[0] == '1' && value[1] == '\0')); } +char * +rl_variable_value (name) + const char *name; +{ + register int i; + + /* Check for simple variables first. */ + i = find_boolean_var (name); + if (i >= 0) + return (*boolean_varlist[i].value ? "on" : "off"); + + i = find_string_var (name); + if (i >= 0) + return (_rl_get_string_variable_value (string_varlist[i].name)); + + /* Unknown variable names return NULL. */ + return 0; +} + int rl_variable_bind (name, value) const char *name, *value; @@ -1725,13 +1803,13 @@ char * rl_get_keymap_name_from_edit_mode () { if (rl_editing_mode == emacs_mode) - return (char*) "emacs"; + return "emacs"; #if defined (VI_MODE) else if (rl_editing_mode == vi_mode) - return (char*) "vi"; + return "vi"; #endif /* VI_MODE */ else - return (char*) "none"; + return "none"; } /* **************************************************************** */ @@ -1899,12 +1977,16 @@ rl_invoking_keyseqs_in_map (function, map) char *keyname = (char *)xmalloc (6 + strlen (seqs[i])); if (key == ESC) -#if 0 - sprintf (keyname, "\\e"); -#else - /* XXX - experimental */ - sprintf (keyname, "\\M-"); -#endif + { + /* If ESC is the meta prefix and we're converting chars + with the eighth bit set to ESC-prefixed sequences, then + we can use \M-. Otherwise we need to use the sequence + for ESC. */ + if (_rl_convert_meta_chars_to_ascii && map[ESC].type == ISKMAP) + sprintf (keyname, "\\M-"); + else + sprintf (keyname, "\\e"); + } else if (CTRL_CHAR (key)) sprintf (keyname, "\\C-%c", _rl_to_lower (UNCTRL (key))); else if (key == RUBOUT) @@ -1966,7 +2048,7 @@ rl_function_dumper (print_readably) fprintf (rl_outstream, "\n"); - for (i = 0; (name = names[i]); i++) + for (i = 0; name = names[i]; i++) { rl_command_func_t *function; char **invokers; @@ -2025,8 +2107,8 @@ rl_function_dumper (print_readably) rl_outstream. If an explicit argument is given, then print the output in such a way that it can be read back in. */ int -rl_dump_functions (int count __attribute__((unused)), - int key __attribute__((unused))) +rl_dump_functions (count, key) + int count, key; { if (rl_dispatching) fprintf (rl_outstream, "\r\n"); @@ -2105,7 +2187,8 @@ rl_macro_dumper (print_readably) } int -rl_dump_macros(int count __attribute__((unused)), int key __attribute__((unused))) +rl_dump_macros (count, key) + int count, key; { if (rl_dispatching) fprintf (rl_outstream, "\r\n"); @@ -2114,12 +2197,67 @@ rl_dump_macros(int count __attribute__((unused)), int key __attribute__((unused) return (0); } +static char * +_rl_get_string_variable_value (name) + const char *name; +{ + static char numbuf[32]; + char *ret; + + if (_rl_stricmp (name, "bell-style") == 0) + { + switch (_rl_bell_preference) + { + case NO_BELL: + return "none"; + case VISIBLE_BELL: + return "visible"; + case AUDIBLE_BELL: + default: + return "audible"; + } + } + else if (_rl_stricmp (name, "comment-begin") == 0) + return (_rl_comment_begin ? _rl_comment_begin : RL_COMMENT_BEGIN_DEFAULT); + else if (_rl_stricmp (name, "completion-query-items") == 0) + { + sprintf (numbuf, "%d", rl_completion_query_items); + return (numbuf); + } + else if (_rl_stricmp (name, "editing-mode") == 0) + return (rl_get_keymap_name_from_edit_mode ()); + else if (_rl_stricmp (name, "isearch-terminators") == 0) + { + if (_rl_isearch_terminators == 0) + return 0; + ret = _rl_untranslate_macro_value (_rl_isearch_terminators); + if (ret) + { + strncpy (numbuf, ret, sizeof (numbuf) - 1); + free (ret); + numbuf[sizeof(numbuf) - 1] = '\0'; + } + else + numbuf[0] = '\0'; + return numbuf; + } + else if (_rl_stricmp (name, "keymap") == 0) + { + ret = rl_get_keymap_name (_rl_keymap); + if (ret == 0) + ret = rl_get_keymap_name_from_edit_mode (); + return (ret ? ret : "none"); + } + else + return (0); +} + void rl_variable_dumper (print_readably) int print_readably; { int i; - const char *kname; + char *v; for (i = 0; boolean_varlist[i].name; i++) { @@ -2131,70 +2269,24 @@ rl_variable_dumper (print_readably) *boolean_varlist[i].value ? "on" : "off"); } - /* bell-style */ - switch (_rl_bell_preference) - { - case NO_BELL: - kname = "none"; break; - case VISIBLE_BELL: - kname = "visible"; break; - case AUDIBLE_BELL: - default: - kname = "audible"; break; - } - if (print_readably) - fprintf (rl_outstream, "set bell-style %s\n", kname); - else - fprintf (rl_outstream, "bell-style is set to `%s'\n", kname); - - /* comment-begin */ - if (print_readably) - fprintf (rl_outstream, "set comment-begin %s\n", _rl_comment_begin ? _rl_comment_begin : RL_COMMENT_BEGIN_DEFAULT); - else - fprintf (rl_outstream, "comment-begin is set to `%s'\n", _rl_comment_begin ? _rl_comment_begin : RL_COMMENT_BEGIN_DEFAULT); - - /* completion-query-items */ - if (print_readably) - fprintf (rl_outstream, "set completion-query-items %d\n", rl_completion_query_items); - else - fprintf (rl_outstream, "completion-query-items is set to `%d'\n", rl_completion_query_items); - - /* editing-mode */ - if (print_readably) - fprintf (rl_outstream, "set editing-mode %s\n", (rl_editing_mode == emacs_mode) ? "emacs" : "vi"); - else - fprintf (rl_outstream, "editing-mode is set to `%s'\n", (rl_editing_mode == emacs_mode) ? "emacs" : "vi"); - - /* isearch-terminators */ - if (_rl_isearch_terminators) + for (i = 0; string_varlist[i].name; i++) { - char *disp; - - disp = _rl_untranslate_macro_value (_rl_isearch_terminators); - + v = _rl_get_string_variable_value (string_varlist[i].name); + if (v == 0) /* _rl_isearch_terminators can be NULL */ + continue; if (print_readably) - fprintf (rl_outstream, "set isearch-terminators \"%s\"\n", disp); + fprintf (rl_outstream, "set %s %s\n", string_varlist[i].name, v); else - fprintf (rl_outstream, "isearch-terminators is set to \"%s\"\n", disp); - - free (disp); + fprintf (rl_outstream, "%s is set to `%s'\n", string_varlist[i].name, v); } - - /* keymap */ - kname = rl_get_keymap_name (_rl_keymap); - if (kname == 0) - kname = rl_get_keymap_name_from_edit_mode (); - if (print_readably) - fprintf (rl_outstream, "set keymap %s\n", kname ? kname : "none"); - else - fprintf (rl_outstream, "keymap is set to `%s'\n", kname ? kname : "none"); } /* Print all of the current variables and their values to rl_outstream. If an explicit argument is given, then print the output in such a way that it can be read back in. */ int -rl_dump_variables(int count __attribute__((unused)), int key __attribute__((unused))) +rl_dump_variables (count, key) + int count, key; { if (rl_dispatching) fprintf (rl_outstream, "\r\n"); |