1 /* bind.c -- key binding and startup file support for the readline library. */
3 /* Copyright (C) 1987-2012 Free Software Foundation, Inc.
5 This file is part of the GNU Readline Library (Readline), a library
6 for reading lines of text with interactive input and history editing.
8 Readline is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
13 Readline is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with Readline. If not, see <http://www.gnu.org/licenses/>.
22 #define READLINE_LIBRARY
24 #if defined (__TANDEM)
28 #if defined (HAVE_CONFIG_H)
33 #include <sys/types.h>
35 #if defined (HAVE_SYS_FILE_H)
36 # include <sys/file.h>
37 #endif /* HAVE_SYS_FILE_H */
39 #if defined (HAVE_UNISTD_H)
41 #endif /* HAVE_UNISTD_H */
43 #if defined (HAVE_STDLIB_H)
46 # include "ansi_stdlib.h"
47 #endif /* HAVE_STDLIB_H */
55 #include "posixstat.h"
57 /* System-specific feature definitions and include files. */
60 /* Some standard library routines. */
64 #include "rlprivate.h"
68 #if !defined (strchr) && !defined (__STDC__)
69 extern char *strchr (), *strrchr ();
70 #endif /* !strchr && !__STDC__ */
72 /* Variables exported by this file. */
73 Keymap rl_binding_keymap;
75 static int _rl_skip_to_delim PARAMS((char *, int, int));
77 static char *_rl_read_file PARAMS((char *, size_t *));
78 static void _rl_init_file_error PARAMS((const char *));
79 static int _rl_read_init_file PARAMS((const char *, int));
80 static int glean_key_from_name PARAMS((char *));
82 static int find_boolean_var PARAMS((const char *));
83 static int find_string_var PARAMS((const char *));
85 static char *_rl_get_string_variable_value PARAMS((const char *));
86 static int substring_member_of_array PARAMS((const char *, const char * const *));
88 static int currently_reading_init_file;
90 /* used only in this file */
91 static int _rl_prefer_visible_bell = 1;
93 /* **************************************************************** */
97 /* **************************************************************** */
99 /* rl_add_defun (char *name, rl_command_func_t *function, int key)
100 Add NAME to the list of named functions. Make FUNCTION be the function
101 that gets called. If KEY is not -1, then bind it. */
103 rl_add_defun (name, function, key)
105 rl_command_func_t *function;
109 rl_bind_key (key, function);
110 rl_add_funmap_entry (name, function);
114 /* Bind KEY to FUNCTION. Returns non-zero if KEY is out of range. */
116 rl_bind_key (key, function)
118 rl_command_func_t *function;
123 if (META_CHAR (key) && _rl_convert_meta_chars_to_ascii)
125 if (_rl_keymap[ESC].type == ISKMAP)
129 escmap = FUNCTION_TO_KEYMAP (_rl_keymap, ESC);
131 escmap[key].type = ISFUNC;
132 escmap[key].function = function;
138 _rl_keymap[key].type = ISFUNC;
139 _rl_keymap[key].function = function;
140 rl_binding_keymap = _rl_keymap;
144 /* Bind KEY to FUNCTION in MAP. Returns non-zero in case of invalid
147 rl_bind_key_in_map (key, function, map)
149 rl_command_func_t *function;
157 result = rl_bind_key (key, function);
162 /* Bind key sequence KEYSEQ to DEFAULT_FUNC if KEYSEQ is unbound. Right
163 now, this is always used to attempt to bind the arrow keys, hence the
164 check for rl_vi_movement_mode. */
166 rl_bind_key_if_unbound_in_map (key, default_func, kmap)
168 rl_command_func_t *default_func;
173 keyseq[0] = (unsigned char)key;
175 return (rl_bind_keyseq_if_unbound_in_map (keyseq, default_func, kmap));
179 rl_bind_key_if_unbound (key, default_func)
181 rl_command_func_t *default_func;
185 keyseq[0] = (unsigned char)key;
187 return (rl_bind_keyseq_if_unbound_in_map (keyseq, default_func, _rl_keymap));
190 /* Make KEY do nothing in the currently selected keymap.
191 Returns non-zero in case of error. */
196 return (rl_bind_key (key, (rl_command_func_t *)NULL));
199 /* Make KEY do nothing in MAP.
200 Returns non-zero in case of error. */
202 rl_unbind_key_in_map (key, map)
206 return (rl_bind_key_in_map (key, (rl_command_func_t *)NULL, map));
209 /* Unbind all keys bound to FUNCTION in MAP. */
211 rl_unbind_function_in_map (func, map)
212 rl_command_func_t *func;
215 register int i, rval;
217 for (i = rval = 0; i < KEYMAP_SIZE; i++)
219 if (map[i].type == ISFUNC && map[i].function == func)
221 map[i].function = (rl_command_func_t *)NULL;
229 rl_unbind_command_in_map (command, map)
233 rl_command_func_t *func;
235 func = rl_named_function (command);
238 return (rl_unbind_function_in_map (func, map));
241 /* Bind the key sequence represented by the string KEYSEQ to
242 FUNCTION, starting in the current keymap. This makes new
243 keymaps as necessary. */
245 rl_bind_keyseq (keyseq, function)
247 rl_command_func_t *function;
249 return (rl_generic_bind (ISFUNC, keyseq, (char *)function, _rl_keymap));
252 /* Bind the key sequence represented by the string KEYSEQ to
253 FUNCTION. This makes new keymaps as necessary. The initial
254 place to do bindings is in MAP. */
256 rl_bind_keyseq_in_map (keyseq, function, map)
258 rl_command_func_t *function;
261 return (rl_generic_bind (ISFUNC, keyseq, (char *)function, map));
264 /* Backwards compatibility; equivalent to rl_bind_keyseq_in_map() */
266 rl_set_key (keyseq, function, map)
268 rl_command_func_t *function;
271 return (rl_generic_bind (ISFUNC, keyseq, (char *)function, map));
274 /* Bind key sequence KEYSEQ to DEFAULT_FUNC if KEYSEQ is unbound. Right
275 now, this is always used to attempt to bind the arrow keys, hence the
276 check for rl_vi_movement_mode. */
278 rl_bind_keyseq_if_unbound_in_map (keyseq, default_func, kmap)
280 rl_command_func_t *default_func;
283 rl_command_func_t *func;
287 func = rl_function_of_keyseq (keyseq, kmap, (int *)NULL);
288 #if defined (VI_MODE)
289 if (!func || func == rl_do_lowercase_version || func == rl_vi_movement_mode)
291 if (!func || func == rl_do_lowercase_version)
293 return (rl_bind_keyseq_in_map (keyseq, default_func, kmap));
301 rl_bind_keyseq_if_unbound (keyseq, default_func)
303 rl_command_func_t *default_func;
305 return (rl_bind_keyseq_if_unbound_in_map (keyseq, default_func, _rl_keymap));
308 /* Bind the key sequence represented by the string KEYSEQ to
309 the string of characters MACRO. This makes new keymaps as
310 necessary. The initial place to do bindings is in MAP. */
312 rl_macro_bind (keyseq, macro, map)
313 const char *keyseq, *macro;
319 macro_keys = (char *)xmalloc ((2 * strlen (macro)) + 1);
321 if (rl_translate_keyseq (macro, macro_keys, ¯o_keys_len))
326 rl_generic_bind (ISMACR, keyseq, macro_keys, map);
330 /* Bind the key sequence represented by the string KEYSEQ to
331 the arbitrary pointer DATA. TYPE says what kind of data is
332 pointed to by DATA, right now this can be a function (ISFUNC),
333 a macro (ISMACR), or a keymap (ISKMAP). This makes new keymaps
334 as necessary. The initial place to do bindings is in MAP. */
336 rl_generic_bind (type, keyseq, data, map)
349 /* If no keys to bind to, exit right away. */
350 if (keyseq == 0 || *keyseq == 0)
357 keys = (char *)xmalloc (1 + (2 * strlen (keyseq)));
359 /* Translate the ASCII representation of KEYSEQ into an array of
360 characters. Stuff the characters into KEYS, and the length of
361 KEYS into KEYS_LEN. */
362 if (rl_translate_keyseq (keyseq, keys, &keys_len))
368 /* Bind keys, making new keymaps as necessary. */
369 for (i = 0; i < keys_len; i++)
371 unsigned char uc = keys[i];
375 if (ic < 0 || ic >= KEYMAP_SIZE)
381 if (META_CHAR (ic) && _rl_convert_meta_chars_to_ascii)
384 if (map[ESC].type == ISKMAP)
385 map = FUNCTION_TO_KEYMAP (map, ESC);
388 if ((i + 1) < keys_len)
390 if (map[ic].type != ISKMAP)
392 /* We allow subsequences of keys. If a keymap is being
393 created that will `shadow' an existing function or macro
394 key binding, we save that keybinding into the ANYOTHERKEY
395 index in the new map. The dispatch code will look there
396 to find the function to execute if the subsequence is not
397 matched. ANYOTHERKEY was chosen to be greater than
401 map[ic].type = ISKMAP;
402 map[ic].function = KEYMAP_TO_FUNCTION (rl_make_bare_keymap());
404 map = FUNCTION_TO_KEYMAP (map, ic);
405 /* The dispatch code will return this function if no matching
406 key sequence is found in the keymap. This (with a little
407 help from the dispatch code in readline.c) allows `a' to be
408 mapped to something, `abc' to be mapped to something else,
409 and the function bound to `a' to be executed when the user
410 types `abx', leaving `bx' in the input queue. */
411 if (k.function && ((k.type == ISFUNC && k.function != rl_do_lowercase_version) || k.type == ISMACR))
413 map[ANYOTHERKEY] = k;
419 if (map[ic].type == ISMACR)
420 xfree ((char *)map[ic].function);
421 else if (map[ic].type == ISKMAP)
423 map = FUNCTION_TO_KEYMAP (map, ic);
425 /* If we're trying to override a keymap with a null function
426 (e.g., trying to unbind it), we can't use a null pointer
427 here because that's indistinguishable from having not been
428 overridden. We use a special bindable function that does
430 if (type == ISFUNC && data == 0)
431 data = (char *)_rl_null_function;
434 map[ic].function = KEYMAP_TO_FUNCTION (data);
438 rl_binding_keymap = map;
444 /* Translate the ASCII representation of SEQ, stuffing the values into ARRAY,
445 an array of characters. LEN gets the final length of ARRAY. Return
446 non-zero if there was an error parsing SEQ. */
448 rl_translate_keyseq (seq, array, len)
453 register int i, c, l, temp;
455 for (i = l = 0; c = seq[i]; i++)
464 /* Handle \C- and \M- prefixes. */
465 if ((c == 'C' || c == 'M') && seq[i + 1] == '-')
467 /* Handle special case of backwards define. */
468 if (strncmp (&seq[i], "C-\\M-", 5) == 0)
470 array[l++] = ESC; /* ESC is meta-prefix */
472 array[l++] = CTRL (_rl_to_upper (seq[i]));
478 i++; /* seq[i] == '-' */
479 /* XXX - obey convert-meta setting */
480 if (_rl_convert_meta_chars_to_ascii && _rl_keymap[ESC].type == ISKMAP)
481 array[l++] = ESC; /* ESC is meta-prefix */
482 else if (seq[i+1] == '\\' && seq[i+2] == 'C' && seq[i+3] == '-')
485 temp = (seq[i] == '?') ? RUBOUT : CTRL (_rl_to_upper (seq[i]));
486 array[l++] = META (temp);
490 /* This doesn't yet handle things like \M-\a, which may
491 or may not have any reasonable meaning. You're
492 probably better off using straight octal or hex. */
494 array[l++] = META (seq[i]);
500 /* Special hack for C-?... */
501 array[l++] = (seq[i] == '?') ? RUBOUT : CTRL (_rl_to_upper (seq[i]));
506 /* Translate other backslash-escaped characters. These are the
507 same escape sequences that bash's `echo' and `printf' builtins
508 handle, with the addition of \d -> RUBOUT. A backslash
509 preceding a character that is not special is stripped. */
519 array[l++] = RUBOUT; /* readline-specific */
528 array[l++] = NEWLINE;
542 case '0': case '1': case '2': case '3':
543 case '4': case '5': case '6': case '7':
545 for (temp = 2, c -= '0'; ISOCTAL (seq[i]) && temp--; i++)
546 c = (c * 8) + OCTVALUE (seq[i]);
547 i--; /* auto-increment in for loop */
548 array[l++] = c & largest_char;
552 for (temp = 2, c = 0; ISXDIGIT ((unsigned char)seq[i]) && temp--; i++)
553 c = (c * 16) + HEXVALUE (seq[i]);
556 i--; /* auto-increment in for loop */
557 array[l++] = c & largest_char;
559 default: /* backslashes before non-special chars just add the char */
561 break; /* the backslash is stripped */
586 case 0x0b: return (1);
597 case '\007': return ('a');
598 case '\b': return ('b');
599 case '\f': return ('f');
600 case '\n': return ('n');
601 case '\r': return ('r');
602 case TAB: return ('t');
603 case 0x0b: return ('v');
609 rl_untranslate_keyseq (seq)
612 static char kseq[16];
629 else if (CTRL_CHAR (c))
634 c = _rl_to_lower (UNCTRL (c));
636 else if (c == RUBOUT)
649 else if (c == '\\' || c == '"')
654 kseq[i++] = (unsigned char) c;
660 _rl_untranslate_macro_value (seq, use_escapes)
667 r = ret = (char *)xmalloc (7 * strlen (seq) + 1);
668 for (s = seq; *s; s++)
683 else if (CTRL_CHAR (c))
686 if (use_escapes && _rl_isescape (c))
692 c = _rl_to_lower (UNCTRL (c));
695 else if (c == RUBOUT)
708 else if (c == '\\' || c == '"')
711 *r++ = (unsigned char)c;
717 /* Return a pointer to the function that STRING represents.
718 If STRING doesn't have a matching function, then a NULL pointer
721 rl_named_function (string)
726 rl_initialize_funmap ();
728 for (i = 0; funmap[i]; i++)
729 if (_rl_stricmp (funmap[i]->name, string) == 0)
730 return (funmap[i]->function);
731 return ((rl_command_func_t *)NULL);
734 /* Return the function (or macro) definition which would be invoked via
735 KEYSEQ if executed in MAP. If MAP is NULL, then the current keymap is
736 used. TYPE, if non-NULL, is a pointer to an int which will receive the
737 type of the object pointed to. One of ISFUNC (function), ISKMAP (keymap),
738 or ISMACR (macro). */
740 rl_function_of_keyseq (keyseq, map, type)
750 for (i = 0; keyseq && keyseq[i]; i++)
752 unsigned char ic = keyseq[i];
754 if (META_CHAR (ic) && _rl_convert_meta_chars_to_ascii)
756 if (map[ESC].type == ISKMAP)
758 map = FUNCTION_TO_KEYMAP (map, ESC);
761 /* XXX - should we just return NULL here, since this obviously
766 *type = map[ESC].type;
768 return (map[ESC].function);
772 if (map[ic].type == ISKMAP)
774 /* If this is the last key in the key sequence, return the
776 if (keyseq[i + 1] == '\0')
781 return (map[ic].function);
784 map = FUNCTION_TO_KEYMAP (map, ic);
786 /* If we're not at the end of the key sequence, and the current key
787 is bound to something other than a keymap, then the entire key
788 sequence is not bound. */
789 else if (map[ic].type != ISKMAP && keyseq[i+1])
790 return ((rl_command_func_t *)NULL);
791 else /* map[ic].type != ISKMAP && keyseq[i+1] == 0 */
794 *type = map[ic].type;
796 return (map[ic].function);
799 return ((rl_command_func_t *) NULL);
802 /* The last key bindings file read. */
803 static char *last_readline_init_file = (char *)NULL;
805 /* The file we're currently reading key bindings from. */
806 static const char *current_readline_init_file;
807 static int current_readline_init_include_level;
808 static int current_readline_init_lineno;
810 /* Read FILENAME into a locally-allocated buffer and return the buffer.
811 The size of the buffer is returned in *SIZEP. Returns NULL if any
812 errors were encountered. */
814 _rl_read_file (filename, sizep)
823 if ((stat (filename, &finfo) < 0) || (file = open (filename, O_RDONLY, 0666)) < 0)
824 return ((char *)NULL);
826 file_size = (size_t)finfo.st_size;
828 /* check for overflow on very large files */
829 if (file_size != finfo.st_size || file_size + 1 < file_size)
836 return ((char *)NULL);
839 /* Read the file into BUFFER. */
840 buffer = (char *)xmalloc (file_size + 1);
841 i = read (file, buffer, file_size);
847 return ((char *)NULL);
859 /* Re-read the current keybindings file. */
861 rl_re_read_init_file (count, ignore)
865 r = rl_read_init_file ((const char *)NULL);
866 rl_set_keymap_from_edit_mode ();
870 /* Do key bindings from a file. If FILENAME is NULL it defaults
871 to the first non-null filename from this list:
872 1. the filename used for the previous call
873 2. the value of the shell variable `INPUTRC'
876 If the file existed and could be opened and read, 0 is returned,
877 otherwise errno is returned. */
879 rl_read_init_file (filename)
880 const char *filename;
882 /* Default the filename. */
884 filename = last_readline_init_file;
886 filename = sh_get_env_value ("INPUTRC");
887 if (filename == 0 || *filename == 0)
889 filename = DEFAULT_INPUTRC;
890 /* Try to read DEFAULT_INPUTRC; fall back to SYS_INPUTRC on failure */
891 if (_rl_read_init_file (filename, 0) == 0)
893 filename = SYS_INPUTRC;
896 #if defined (__MSDOS__)
897 if (_rl_read_init_file (filename, 0) == 0)
899 filename = "~/_inputrc";
901 return (_rl_read_init_file (filename, 0));
905 _rl_read_init_file (filename, include_level)
906 const char *filename;
910 char *buffer, *openname, *line, *end;
913 current_readline_init_file = filename;
914 current_readline_init_include_level = include_level;
916 openname = tilde_expand (filename);
917 buffer = _rl_read_file (openname, &file_size);
924 if (include_level == 0 && filename != last_readline_init_file)
926 FREE (last_readline_init_file);
927 last_readline_init_file = savestring (filename);
930 currently_reading_init_file = 1;
932 /* Loop over the lines in the file. Lines that start with `#' are
933 comments; all other lines are commands for readline initialization. */
934 current_readline_init_lineno = 1;
936 end = buffer + file_size;
939 /* Find the end of this line. */
940 for (i = 0; line + i != end && line[i] != '\n'; i++);
942 #if defined (__CYGWIN__)
943 /* ``Be liberal in what you accept.'' */
944 if (line[i] == '\n' && line[i-1] == '\r')
948 /* Mark end of line. */
951 /* Skip leading whitespace. */
952 while (*line && whitespace (*line))
958 /* If the line is not a comment, then parse it. */
959 if (*line && *line != '#')
960 rl_parse_and_bind (line);
962 /* Move to the next line. */
964 current_readline_init_lineno++;
968 currently_reading_init_file = 0;
973 _rl_init_file_error (msg)
976 if (currently_reading_init_file)
977 _rl_errmsg ("%s: line %d: %s\n", current_readline_init_file,
978 current_readline_init_lineno, msg);
980 _rl_errmsg ("%s", msg);
983 /* **************************************************************** */
985 /* Parser Directives */
987 /* **************************************************************** */
989 typedef int _rl_parser_func_t PARAMS((char *));
991 /* Things that mean `Control'. */
992 const char * const _rl_possible_control_prefixes[] = {
993 "Control-", "C-", "CTRL-", (const char *)NULL
996 const char * const _rl_possible_meta_prefixes[] = {
997 "Meta", "M-", (const char *)NULL
1002 /* Calling programs set this to have their argv[0]. */
1003 const char *rl_readline_name = "other";
1005 /* Stack of previous values of parsing_conditionalized_out. */
1006 static unsigned char *if_stack = (unsigned char *)NULL;
1007 static int if_stack_depth;
1008 static int if_stack_size;
1010 /* Push _rl_parsing_conditionalized_out, and set parser state based
1018 /* Push parser state. */
1019 if (if_stack_depth + 1 >= if_stack_size)
1022 if_stack = (unsigned char *)xmalloc (if_stack_size = 20);
1024 if_stack = (unsigned char *)xrealloc (if_stack, if_stack_size += 20);
1026 if_stack[if_stack_depth++] = _rl_parsing_conditionalized_out;
1028 /* If parsing is turned off, then nothing can turn it back on except
1029 for finding the matching endif. In that case, return right now. */
1030 if (_rl_parsing_conditionalized_out)
1033 /* Isolate first argument. */
1034 for (i = 0; args[i] && !whitespace (args[i]); i++);
1039 /* Handle "$if term=foo" and "$if mode=emacs" constructs. If this
1040 isn't term=foo, or mode=emacs, then check to see if the first
1041 word in ARGS is the same as the value stored in rl_readline_name. */
1042 if (rl_terminal_name && _rl_strnicmp (args, "term=", 5) == 0)
1046 /* Terminals like "aaa-60" are equivalent to "aaa". */
1047 tname = savestring (rl_terminal_name);
1048 tem = strchr (tname, '-');
1052 /* Test the `long' and `short' forms of the terminal name so that
1053 if someone has a `sun-cmd' and does not want to have bindings
1054 that will be executed if the terminal is a `sun', they can put
1055 `$if term=sun-cmd' into their .inputrc. */
1056 _rl_parsing_conditionalized_out = _rl_stricmp (args + 5, tname) &&
1057 _rl_stricmp (args + 5, rl_terminal_name);
1060 #if defined (VI_MODE)
1061 else if (_rl_strnicmp (args, "mode=", 5) == 0)
1065 if (_rl_stricmp (args + 5, "emacs") == 0)
1067 else if (_rl_stricmp (args + 5, "vi") == 0)
1072 _rl_parsing_conditionalized_out = mode != rl_editing_mode;
1074 #endif /* VI_MODE */
1075 /* Check to see if the first word in ARGS is the same as the
1076 value stored in rl_readline_name. */
1077 else if (_rl_stricmp (args, rl_readline_name) == 0)
1078 _rl_parsing_conditionalized_out = 0;
1080 _rl_parsing_conditionalized_out = 1;
1084 /* Invert the current parser state if there is anything on the stack. */
1091 if (if_stack_depth == 0)
1093 _rl_init_file_error ("$else found without matching $if");
1098 /* Check the previous (n - 1) levels of the stack to make sure that
1099 we haven't previously turned off parsing. */
1100 for (i = 0; i < if_stack_depth - 1; i++)
1102 /* Check the previous (n) levels of the stack to make sure that
1103 we haven't previously turned off parsing. */
1104 for (i = 0; i < if_stack_depth; i++)
1106 if (if_stack[i] == 1)
1109 /* Invert the state of parsing if at top level. */
1110 _rl_parsing_conditionalized_out = !_rl_parsing_conditionalized_out;
1114 /* Terminate a conditional, popping the value of
1115 _rl_parsing_conditionalized_out from the stack. */
1121 _rl_parsing_conditionalized_out = if_stack[--if_stack_depth];
1123 _rl_init_file_error ("$endif without matching $if");
1128 parser_include (args)
1131 const char *old_init_file;
1133 int old_line_number, old_include_level, r;
1135 if (_rl_parsing_conditionalized_out)
1138 old_init_file = current_readline_init_file;
1139 old_line_number = current_readline_init_lineno;
1140 old_include_level = current_readline_init_include_level;
1142 e = strchr (args, '\n');
1145 r = _rl_read_init_file ((const char *)args, old_include_level + 1);
1147 current_readline_init_file = old_init_file;
1148 current_readline_init_lineno = old_line_number;
1149 current_readline_init_include_level = old_include_level;
1154 /* Associate textual names with actual functions. */
1155 static const struct {
1156 const char * const name;
1157 _rl_parser_func_t *function;
1158 } parser_directives [] = {
1159 { "if", parser_if },
1160 { "endif", parser_endif },
1161 { "else", parser_else },
1162 { "include", parser_include },
1163 { (char *)0x0, (_rl_parser_func_t *)0x0 }
1166 /* Handle a parser directive. STATEMENT is the line of the directive
1167 without any leading `$'. */
1169 handle_parser_directive (statement)
1173 char *directive, *args;
1175 /* Isolate the actual directive. */
1177 /* Skip whitespace. */
1178 for (i = 0; whitespace (statement[i]); i++);
1180 directive = &statement[i];
1182 for (; statement[i] && !whitespace (statement[i]); i++);
1185 statement[i++] = '\0';
1187 for (; statement[i] && whitespace (statement[i]); i++);
1189 args = &statement[i];
1191 /* Lookup the command, and act on it. */
1192 for (i = 0; parser_directives[i].name; i++)
1193 if (_rl_stricmp (directive, parser_directives[i].name) == 0)
1195 (*parser_directives[i].function) (args);
1199 /* display an error message about the unknown parser directive */
1200 _rl_init_file_error ("unknown parser directive");
1204 /* Start at STRING[START] and look for DELIM. Return I where STRING[I] ==
1205 DELIM or STRING[I] == 0. DELIM is usually a double quote. */
1207 _rl_skip_to_delim (string, start, delim)
1213 for (i = start,passc = 0; c = string[i]; i++)
1236 /* Read the binding command from STRING and perform it.
1237 A key binding command looks like: Keyname: function-name\0,
1238 a variable binding command looks like: set variable value.
1239 A new-style keybinding looks like "\C-x\C-x": exchange-point-and-mark. */
1241 rl_parse_and_bind (string)
1244 char *funname, *kname;
1246 int key, equivalency;
1248 while (string && whitespace (*string))
1251 if (string == 0 || *string == 0 || *string == '#')
1254 /* If this is a parser directive, act on it. */
1257 handle_parser_directive (&string[1]);
1261 /* If we aren't supposed to be parsing right now, then we're done. */
1262 if (_rl_parsing_conditionalized_out)
1266 /* If this keyname is a complex key expression surrounded by quotes,
1267 advance to after the matching close quote. This code allows the
1268 backslash to quote characters in the key expression. */
1271 i = _rl_skip_to_delim (string, 1, '"');
1273 /* If we didn't find a closing quote, abort the line. */
1274 if (string[i] == '\0')
1276 _rl_init_file_error ("no closing `\"' in key binding");
1280 i++; /* skip past closing double quote */
1283 /* Advance to the colon (:) or whitespace which separates the two objects. */
1284 for (; (c = string[i]) && c != ':' && c != ' ' && c != '\t'; i++ );
1286 equivalency = (c == ':' && string[i + 1] == '=');
1288 /* Mark the end of the command (or keyname). */
1292 /* If doing assignment, skip the '=' sign as well. */
1296 /* If this is a command to set a variable, then do that. */
1297 if (_rl_stricmp (string, "set") == 0)
1299 char *var, *value, *e;
1303 /* Make VAR point to start of variable name. */
1304 while (*var && whitespace (*var)) var++;
1306 /* Make VALUE point to start of value string. */
1308 while (*value && whitespace (*value) == 0) value++;
1311 while (*value && whitespace (*value)) value++;
1313 /* Strip trailing whitespace from values of boolean variables. */
1314 if (find_boolean_var (var) >= 0)
1316 /* remove trailing whitespace */
1318 e = value + strlen (value) - 1;
1319 while (e >= value && whitespace (*e))
1321 e++; /* skip back to whitespace or EOS */
1323 if (*e && e >= value)
1326 else if ((i = find_string_var (var)) >= 0)
1328 /* Allow quoted strings in variable values */
1331 i = _rl_skip_to_delim (value, 1, *value);
1333 value++; /* skip past the quote */
1336 goto remove_trailing;
1339 rl_variable_bind (var, value);
1343 /* Skip any whitespace between keyname and funname. */
1344 for (; string[i] && whitespace (string[i]); i++);
1345 funname = &string[i];
1347 /* Now isolate funname.
1348 For straight function names just look for whitespace, since
1349 that will signify the end of the string. But this could be a
1350 macro definition. In that case, the string is quoted, so skip
1351 to the matching delimiter. We allow the backslash to quote the
1352 delimiter characters in the macro body. */
1353 /* This code exists to allow whitespace in macro expansions, which
1354 would otherwise be gobbled up by the next `for' loop.*/
1355 /* XXX - it may be desirable to allow backslash quoting only if " is
1356 the quoted string delimiter, like the shell. */
1357 if (*funname == '\'' || *funname == '"')
1359 i = _rl_skip_to_delim (string, i+1, *funname);
1364 /* Advance to the end of the string. */
1365 for (; string[i] && whitespace (string[i]) == 0; i++);
1367 /* No extra whitespace at the end of the string. */
1370 /* Handle equivalency bindings here. Make the left-hand side be exactly
1371 whatever the right-hand evaluates to, including keymaps. */
1377 /* If this is a new-style key-binding, then do the binding with
1378 rl_bind_keyseq (). Otherwise, let the older code deal with it. */
1382 register int j, k, passc;
1384 seq = (char *)xmalloc (1 + strlen (string));
1385 for (j = 1, k = passc = 0; string[j]; j++)
1387 /* Allow backslash to quote characters, but leave them in place.
1388 This allows a string to end with a backslash quoting another
1389 backslash, or with a backslash quoting a double quote. The
1390 backslashes are left in place for rl_translate_keyseq (). */
1391 if (passc || (string[j] == '\\'))
1393 seq[k++] = string[j];
1398 if (string[j] == '"')
1401 seq[k++] = string[j];
1405 /* Binding macro? */
1406 if (*funname == '\'' || *funname == '"')
1408 j = strlen (funname);
1410 /* Remove the delimiting quotes from each end of FUNNAME. */
1411 if (j && funname[j - 1] == *funname)
1412 funname[j - 1] = '\0';
1414 rl_macro_bind (seq, &funname[1], _rl_keymap);
1417 rl_bind_keyseq (seq, rl_named_function (funname));
1423 /* Get the actual character we want to deal with. */
1424 kname = strrchr (string, '-');
1430 key = glean_key_from_name (kname);
1432 /* Add in control and meta bits. */
1433 if (substring_member_of_array (string, _rl_possible_control_prefixes))
1434 key = CTRL (_rl_to_upper (key));
1436 if (substring_member_of_array (string, _rl_possible_meta_prefixes))
1439 /* Temporary. Handle old-style keyname with macro-binding. */
1440 if (*funname == '\'' || *funname == '"')
1443 int fl = strlen (funname);
1445 useq[0] = key; useq[1] = '\0';
1446 if (fl && funname[fl - 1] == *funname)
1447 funname[fl - 1] = '\0';
1449 rl_macro_bind (useq, &funname[1], _rl_keymap);
1451 #if defined (PREFIX_META_HACK)
1452 /* Ugly, but working hack to keep prefix-meta around. */
1453 else if (_rl_stricmp (funname, "prefix-meta") == 0)
1459 rl_generic_bind (ISKMAP, seq, (char *)emacs_meta_keymap, _rl_keymap);
1461 #endif /* PREFIX_META_HACK */
1463 rl_bind_key (key, rl_named_function (funname));
1467 /* Simple structure for boolean readline variables (i.e., those that can
1468 have one of two values; either "On" or 1 for truth, or "Off" or 0 for
1471 #define V_SPECIAL 0x1
1473 static const struct {
1474 const char * const name;
1477 } boolean_varlist [] = {
1478 { "bind-tty-special-chars", &_rl_bind_stty_chars, 0 },
1479 { "blink-matching-paren", &rl_blink_matching_paren, V_SPECIAL },
1480 { "byte-oriented", &rl_byte_oriented, 0 },
1481 #if defined (COLOR_SUPPORT)
1482 { "colored-stats", &_rl_colored_stats, 0 },
1484 { "completion-ignore-case", &_rl_completion_case_fold, 0 },
1485 { "completion-map-case", &_rl_completion_case_map, 0 },
1486 { "convert-meta", &_rl_convert_meta_chars_to_ascii, 0 },
1487 { "disable-completion", &rl_inhibit_completion, 0 },
1488 { "echo-control-characters", &_rl_echo_control_chars, 0 },
1489 { "enable-keypad", &_rl_enable_keypad, 0 },
1490 { "enable-meta-key", &_rl_enable_meta, 0 },
1491 { "expand-tilde", &rl_complete_with_tilde_expansion, 0 },
1492 { "history-preserve-point", &_rl_history_preserve_point, 0 },
1493 { "horizontal-scroll-mode", &_rl_horizontal_scroll_mode, 0 },
1494 { "input-meta", &_rl_meta_flag, 0 },
1495 { "mark-directories", &_rl_complete_mark_directories, 0 },
1496 { "mark-modified-lines", &_rl_mark_modified_lines, 0 },
1497 { "mark-symlinked-directories", &_rl_complete_mark_symlink_dirs, 0 },
1498 { "match-hidden-files", &_rl_match_hidden_files, 0 },
1499 { "menu-complete-display-prefix", &_rl_menu_complete_prefix_first, 0 },
1500 { "meta-flag", &_rl_meta_flag, 0 },
1501 { "output-meta", &_rl_output_meta_chars, 0 },
1502 { "page-completions", &_rl_page_completions, 0 },
1503 { "prefer-visible-bell", &_rl_prefer_visible_bell, V_SPECIAL },
1504 { "print-completions-horizontally", &_rl_print_completions_horizontally, 0 },
1505 { "revert-all-at-newline", &_rl_revert_all_at_newline, 0 },
1506 { "show-all-if-ambiguous", &_rl_complete_show_all, 0 },
1507 { "show-all-if-unmodified", &_rl_complete_show_unmodified, 0 },
1508 { "show-mode-in-prompt", &_rl_show_mode_in_prompt, 0 },
1509 { "skip-completed-text", &_rl_skip_completed_text, 0 },
1510 #if defined (VISIBLE_STATS)
1511 { "visible-stats", &rl_visible_stats, 0 },
1512 #endif /* VISIBLE_STATS */
1513 { (char *)NULL, (int *)NULL, 0 }
1517 find_boolean_var (name)
1522 for (i = 0; boolean_varlist[i].name; i++)
1523 if (_rl_stricmp (name, boolean_varlist[i].name) == 0)
1528 /* Hooks for handling special boolean variables, where a
1529 function needs to be called or another variable needs
1530 to be changed when they're changed. */
1532 hack_special_boolean_var (i)
1537 name = boolean_varlist[i].name;
1539 if (_rl_stricmp (name, "blink-matching-paren") == 0)
1540 _rl_enable_paren_matching (rl_blink_matching_paren);
1541 else if (_rl_stricmp (name, "prefer-visible-bell") == 0)
1543 if (_rl_prefer_visible_bell)
1544 _rl_bell_preference = VISIBLE_BELL;
1546 _rl_bell_preference = AUDIBLE_BELL;
1548 else if (_rl_stricmp (name, "show-mode-in-prompt") == 0)
1549 _rl_reset_prompt ();
1552 typedef int _rl_sv_func_t PARAMS((const char *));
1554 /* These *must* correspond to the array indices for the appropriate
1555 string variable. (Though they're not used right now.) */
1556 #define V_BELLSTYLE 0
1557 #define V_COMBEGIN 1
1558 #define V_EDITMODE 2
1559 #define V_ISRCHTERM 3
1565 /* Forward declarations */
1566 static int sv_bell_style PARAMS((const char *));
1567 static int sv_combegin PARAMS((const char *));
1568 static int sv_dispprefix PARAMS((const char *));
1569 static int sv_compquery PARAMS((const char *));
1570 static int sv_compwidth PARAMS((const char *));
1571 static int sv_editmode PARAMS((const char *));
1572 static int sv_histsize PARAMS((const char *));
1573 static int sv_isrchterm PARAMS((const char *));
1574 static int sv_keymap PARAMS((const char *));
1575 static int sv_seqtimeout PARAMS((const char *));
1577 static const struct {
1578 const char * const name;
1580 _rl_sv_func_t *set_func;
1581 } string_varlist[] = {
1582 { "bell-style", V_STRING, sv_bell_style },
1583 { "comment-begin", V_STRING, sv_combegin },
1584 { "completion-display-width", V_INT, sv_compwidth },
1585 { "completion-prefix-display-length", V_INT, sv_dispprefix },
1586 { "completion-query-items", V_INT, sv_compquery },
1587 { "editing-mode", V_STRING, sv_editmode },
1588 { "history-size", V_INT, sv_histsize },
1589 { "isearch-terminators", V_STRING, sv_isrchterm },
1590 { "keymap", V_STRING, sv_keymap },
1591 { "keyseq-timeout", V_INT, sv_seqtimeout },
1592 { (char *)NULL, 0, (_rl_sv_func_t *)0 }
1596 find_string_var (name)
1601 for (i = 0; string_varlist[i].name; i++)
1602 if (_rl_stricmp (name, string_varlist[i].name) == 0)
1607 /* A boolean value that can appear in a `set variable' command is true if
1608 the value is null or empty, `on' (case-insenstive), or "1". Any other
1609 values result in 0 (false). */
1614 return (value == 0 || *value == '\0' ||
1615 (_rl_stricmp (value, "on") == 0) ||
1616 (value[0] == '1' && value[1] == '\0'));
1620 rl_variable_value (name)
1625 /* Check for simple variables first. */
1626 i = find_boolean_var (name);
1628 return (*boolean_varlist[i].value ? "on" : "off");
1630 i = find_string_var (name);
1632 return (_rl_get_string_variable_value (string_varlist[i].name));
1634 /* Unknown variable names return NULL. */
1639 rl_variable_bind (name, value)
1640 const char *name, *value;
1645 /* Check for simple variables first. */
1646 i = find_boolean_var (name);
1649 *boolean_varlist[i].value = bool_to_int (value);
1650 if (boolean_varlist[i].flags & V_SPECIAL)
1651 hack_special_boolean_var (i);
1655 i = find_string_var (name);
1657 /* For the time being, unknown variable names or string names without a
1658 handler function are simply ignored. */
1659 if (i < 0 || string_varlist[i].set_func == 0)
1662 v = (*string_varlist[i].set_func) (value);
1670 if (_rl_strnicmp (value, "vi", 2) == 0)
1672 #if defined (VI_MODE)
1673 _rl_keymap = vi_insertion_keymap;
1674 rl_editing_mode = vi_mode;
1675 #endif /* VI_MODE */
1678 else if (_rl_strnicmp (value, "emacs", 5) == 0)
1680 _rl_keymap = emacs_standard_keymap;
1681 rl_editing_mode = emacs_mode;
1691 if (value && *value)
1693 FREE (_rl_comment_begin);
1694 _rl_comment_begin = savestring (value);
1701 sv_dispprefix (value)
1706 if (value && *value)
1708 nval = atoi (value);
1712 _rl_completion_prefix_display_length = nval;
1717 sv_compquery (value)
1722 if (value && *value)
1724 nval = atoi (value);
1728 rl_completion_query_items = nval;
1733 sv_compwidth (value)
1738 if (value && *value)
1739 nval = atoi (value);
1741 _rl_completion_columns = nval;
1752 if (value && *value)
1754 nval = atoi (value);
1757 unstifle_history ();
1761 stifle_history (nval);
1771 kmap = rl_get_keymap_by_name (value);
1774 rl_set_keymap (kmap);
1781 sv_seqtimeout (value)
1787 if (value && *value)
1789 nval = atoi (value);
1793 _rl_keyseq_timeout = nval;
1798 sv_bell_style (value)
1801 if (value == 0 || *value == '\0')
1802 _rl_bell_preference = AUDIBLE_BELL;
1803 else if (_rl_stricmp (value, "none") == 0 || _rl_stricmp (value, "off") == 0)
1804 _rl_bell_preference = NO_BELL;
1805 else if (_rl_stricmp (value, "audible") == 0 || _rl_stricmp (value, "on") == 0)
1806 _rl_bell_preference = AUDIBLE_BELL;
1807 else if (_rl_stricmp (value, "visible") == 0)
1808 _rl_bell_preference = VISIBLE_BELL;
1815 sv_isrchterm (value)
1818 int beg, end, delim;
1824 /* Isolate the value and translate it into a character string. */
1825 v = savestring (value);
1826 FREE (_rl_isearch_terminators);
1827 if (v[0] == '"' || v[0] == '\'')
1830 for (beg = end = 1; v[end] && v[end] != delim; end++)
1835 for (beg = end = 0; whitespace (v[end]) == 0; end++)
1841 /* The value starts at v + beg. Translate it into a character string. */
1842 _rl_isearch_terminators = (char *)xmalloc (2 * strlen (v) + 1);
1843 rl_translate_keyseq (v + beg, _rl_isearch_terminators, &end);
1844 _rl_isearch_terminators[end] = '\0';
1850 /* Return the character which matches NAME.
1851 For example, `Space' returns ' '. */
1854 const char * const name;
1858 static const assoc_list name_key_alist[] = {
1861 { "Escape", '\033' },
1863 { "Newline", '\n' },
1874 glean_key_from_name (name)
1879 for (i = 0; name_key_alist[i].name; i++)
1880 if (_rl_stricmp (name, name_key_alist[i].name) == 0)
1881 return (name_key_alist[i].value);
1883 return (*(unsigned char *)name); /* XXX was return (*name) */
1886 /* Auxiliary functions to manage keymaps. */
1887 static const struct {
1888 const char * const name;
1890 } keymap_names[] = {
1891 { "emacs", emacs_standard_keymap },
1892 { "emacs-standard", emacs_standard_keymap },
1893 { "emacs-meta", emacs_meta_keymap },
1894 { "emacs-ctlx", emacs_ctlx_keymap },
1895 #if defined (VI_MODE)
1896 { "vi", vi_movement_keymap },
1897 { "vi-move", vi_movement_keymap },
1898 { "vi-command", vi_movement_keymap },
1899 { "vi-insert", vi_insertion_keymap },
1900 #endif /* VI_MODE */
1901 { (char *)0x0, (Keymap)0x0 }
1905 rl_get_keymap_by_name (name)
1910 for (i = 0; keymap_names[i].name; i++)
1911 if (_rl_stricmp (name, keymap_names[i].name) == 0)
1912 return (keymap_names[i].map);
1913 return ((Keymap) NULL);
1917 rl_get_keymap_name (map)
1921 for (i = 0; keymap_names[i].name; i++)
1922 if (map == keymap_names[i].map)
1923 return ((char *)keymap_names[i].name);
1924 return ((char *)NULL);
1938 return (_rl_keymap);
1942 rl_set_keymap_from_edit_mode ()
1944 if (rl_editing_mode == emacs_mode)
1945 _rl_keymap = emacs_standard_keymap;
1946 #if defined (VI_MODE)
1947 else if (rl_editing_mode == vi_mode)
1948 _rl_keymap = vi_insertion_keymap;
1949 #endif /* VI_MODE */
1953 rl_get_keymap_name_from_edit_mode ()
1955 if (rl_editing_mode == emacs_mode)
1957 #if defined (VI_MODE)
1958 else if (rl_editing_mode == vi_mode)
1960 #endif /* VI_MODE */
1965 /* **************************************************************** */
1967 /* Key Binding and Function Information */
1969 /* **************************************************************** */
1971 /* Each of the following functions produces information about the
1972 state of keybindings and functions known to Readline. The info
1973 is always printed to rl_outstream, and in such a way that it can
1974 be read back in (i.e., passed to rl_parse_and_bind ()). */
1976 /* Print the names of functions known to Readline. */
1978 rl_list_funmap_names ()
1981 const char **funmap_names;
1983 funmap_names = rl_funmap_names ();
1988 for (i = 0; funmap_names[i]; i++)
1989 fprintf (rl_outstream, "%s\n", funmap_names[i]);
1991 xfree (funmap_names);
1995 _rl_get_keyname (key)
2001 keyname = (char *)xmalloc (8);
2004 /* Since this is going to be used to write out keysequence-function
2005 pairs for possible inclusion in an inputrc file, we don't want to
2006 do any special meta processing on KEY. */
2009 /* XXX - Experimental */
2010 /* We might want to do this, but the old version of the code did not. */
2012 /* If this is an escape character, we don't want to do any more processing.
2013 Just add the special ESC key sequence and return. */
2023 /* RUBOUT is translated directly into \C-? */
2035 /* Now add special prefixes needed for control characters. This can
2036 potentially change C. */
2039 keyname[i++] = '\\';
2042 c = _rl_to_lower (UNCTRL (c));
2045 /* XXX experimental code. Turn the characters that are not ASCII or
2046 ISO Latin 1 (128 - 159) into octal escape sequences (\200 - \237).
2048 if (c >= 128 && c <= 159)
2050 keyname[i++] = '\\';
2053 keyname[i++] = (c / 8) + '0';
2057 /* Now, if the character needs to be quoted with a backslash, do that. */
2058 if (c == '\\' || c == '"')
2059 keyname[i++] = '\\';
2061 /* Now add the key, terminate the string, and return it. */
2062 keyname[i++] = (char) c;
2068 /* Return a NULL terminated array of strings which represent the key
2069 sequences that are used to invoke FUNCTION in MAP. */
2071 rl_invoking_keyseqs_in_map (function, map)
2072 rl_command_func_t *function;
2077 int result_index, result_size;
2079 result = (char **)NULL;
2080 result_index = result_size = 0;
2082 for (key = 0; key < KEYMAP_SIZE; key++)
2084 switch (map[key].type)
2087 /* Macros match, if, and only if, the pointers are identical.
2088 Thus, they are treated exactly like functions in here. */
2090 /* If the function in the keymap is the one we are looking for,
2091 then add the current KEY to the list of invoking keys. */
2092 if (map[key].function == function)
2096 keyname = _rl_get_keyname (key);
2098 if (result_index + 2 > result_size)
2101 result = (char **)xrealloc (result, result_size * sizeof (char *));
2104 result[result_index++] = keyname;
2105 result[result_index] = (char *)NULL;
2114 /* Find the list of keyseqs in this map which have FUNCTION as
2115 their target. Add the key sequences found to RESULT. */
2116 if (map[key].function)
2118 rl_invoking_keyseqs_in_map (function, FUNCTION_TO_KEYMAP (map, key));
2125 for (i = 0; seqs[i]; i++)
2127 char *keyname = (char *)xmalloc (6 + strlen (seqs[i]));
2131 /* If ESC is the meta prefix and we're converting chars
2132 with the eighth bit set to ESC-prefixed sequences, then
2133 we can use \M-. Otherwise we need to use the sequence
2135 if (_rl_convert_meta_chars_to_ascii && map[ESC].type == ISKMAP)
2136 sprintf (keyname, "\\M-");
2138 sprintf (keyname, "\\e");
2140 else if (CTRL_CHAR (key))
2141 sprintf (keyname, "\\C-%c", _rl_to_lower (UNCTRL (key)));
2142 else if (key == RUBOUT)
2143 sprintf (keyname, "\\C-?");
2144 else if (key == '\\' || key == '"')
2147 keyname[1] = (char) key;
2152 keyname[0] = (char) key;
2156 strcat (keyname, seqs[i]);
2159 if (result_index + 2 > result_size)
2162 result = (char **)xrealloc (result, result_size * sizeof (char *));
2165 result[result_index++] = keyname;
2166 result[result_index] = (char *)NULL;
2177 /* Return a NULL terminated array of strings which represent the key
2178 sequences that can be used to invoke FUNCTION using the current keymap. */
2180 rl_invoking_keyseqs (function)
2181 rl_command_func_t *function;
2183 return (rl_invoking_keyseqs_in_map (function, _rl_keymap));
2186 /* Print all of the functions and their bindings to rl_outstream. If
2187 PRINT_READABLY is non-zero, then print the output in such a way
2188 that it can be read back in. */
2190 rl_function_dumper (print_readably)
2197 names = rl_funmap_names ();
2199 fprintf (rl_outstream, "\n");
2201 for (i = 0; name = names[i]; i++)
2203 rl_command_func_t *function;
2206 function = rl_named_function (name);
2207 invokers = rl_invoking_keyseqs_in_map (function, _rl_keymap);
2212 fprintf (rl_outstream, "# %s (not bound)\n", name);
2217 for (j = 0; invokers[j]; j++)
2219 fprintf (rl_outstream, "\"%s\": %s\n",
2221 xfree (invokers[j]);
2230 fprintf (rl_outstream, "%s is not bound to any keys\n",
2236 fprintf (rl_outstream, "%s can be found on ", name);
2238 for (j = 0; invokers[j] && j < 5; j++)
2240 fprintf (rl_outstream, "\"%s\"%s", invokers[j],
2241 invokers[j + 1] ? ", " : ".\n");
2244 if (j == 5 && invokers[j])
2245 fprintf (rl_outstream, "...\n");
2247 for (j = 0; invokers[j]; j++)
2248 xfree (invokers[j]);
2258 /* Print all of the current functions and their bindings to
2259 rl_outstream. If an explicit argument is given, then print
2260 the output in such a way that it can be read back in. */
2262 rl_dump_functions (count, key)
2266 fprintf (rl_outstream, "\r\n");
2267 rl_function_dumper (rl_explicit_arg);
2273 _rl_macro_dumper_internal (print_readably, map, prefix)
2279 char *keyname, *out;
2282 for (key = 0; key < KEYMAP_SIZE; key++)
2284 switch (map[key].type)
2287 keyname = _rl_get_keyname (key);
2288 out = _rl_untranslate_macro_value ((char *)map[key].function, 0);
2291 fprintf (rl_outstream, "\"%s%s\": \"%s\"\n", prefix ? prefix : "",
2295 fprintf (rl_outstream, "%s%s outputs %s\n", prefix ? prefix : "",
2304 prefix_len = prefix ? strlen (prefix) : 0;
2307 keyname = (char *)xmalloc (3 + prefix_len);
2309 strcpy (keyname, prefix);
2310 keyname[prefix_len] = '\\';
2311 keyname[prefix_len + 1] = 'e';
2312 keyname[prefix_len + 2] = '\0';
2316 keyname = _rl_get_keyname (key);
2319 out = (char *)xmalloc (strlen (keyname) + prefix_len + 1);
2320 strcpy (out, prefix);
2321 strcpy (out + prefix_len, keyname);
2327 _rl_macro_dumper_internal (print_readably, FUNCTION_TO_KEYMAP (map, key), keyname);
2335 rl_macro_dumper (print_readably)
2338 _rl_macro_dumper_internal (print_readably, _rl_keymap, (char *)NULL);
2342 rl_dump_macros (count, key)
2346 fprintf (rl_outstream, "\r\n");
2347 rl_macro_dumper (rl_explicit_arg);
2353 _rl_get_string_variable_value (name)
2356 static char numbuf[32];
2359 if (_rl_stricmp (name, "bell-style") == 0)
2361 switch (_rl_bell_preference)
2372 else if (_rl_stricmp (name, "comment-begin") == 0)
2373 return (_rl_comment_begin ? _rl_comment_begin : RL_COMMENT_BEGIN_DEFAULT);
2374 else if (_rl_stricmp (name, "completion-display-width") == 0)
2376 sprintf (numbuf, "%d", _rl_completion_columns);
2379 else if (_rl_stricmp (name, "completion-prefix-display-length") == 0)
2381 sprintf (numbuf, "%d", _rl_completion_prefix_display_length);
2384 else if (_rl_stricmp (name, "completion-query-items") == 0)
2386 sprintf (numbuf, "%d", rl_completion_query_items);
2389 else if (_rl_stricmp (name, "editing-mode") == 0)
2390 return (rl_get_keymap_name_from_edit_mode ());
2391 else if (_rl_stricmp (name, "history-size") == 0)
2393 sprintf (numbuf, "%d", history_is_stifled() ? history_max_entries : 0);
2396 else if (_rl_stricmp (name, "isearch-terminators") == 0)
2398 if (_rl_isearch_terminators == 0)
2400 ret = _rl_untranslate_macro_value (_rl_isearch_terminators, 0);
2403 strncpy (numbuf, ret, sizeof (numbuf) - 1);
2405 numbuf[sizeof(numbuf) - 1] = '\0';
2411 else if (_rl_stricmp (name, "keymap") == 0)
2413 ret = rl_get_keymap_name (_rl_keymap);
2415 ret = rl_get_keymap_name_from_edit_mode ();
2416 return (ret ? ret : "none");
2418 else if (_rl_stricmp (name, "keyseq-timeout") == 0)
2420 sprintf (numbuf, "%d", _rl_keyseq_timeout);
2428 rl_variable_dumper (print_readably)
2434 for (i = 0; boolean_varlist[i].name; i++)
2437 fprintf (rl_outstream, "set %s %s\n", boolean_varlist[i].name,
2438 *boolean_varlist[i].value ? "on" : "off");
2440 fprintf (rl_outstream, "%s is set to `%s'\n", boolean_varlist[i].name,
2441 *boolean_varlist[i].value ? "on" : "off");
2444 for (i = 0; string_varlist[i].name; i++)
2446 v = _rl_get_string_variable_value (string_varlist[i].name);
2447 if (v == 0) /* _rl_isearch_terminators can be NULL */
2450 fprintf (rl_outstream, "set %s %s\n", string_varlist[i].name, v);
2452 fprintf (rl_outstream, "%s is set to `%s'\n", string_varlist[i].name, v);
2456 /* Print all of the current variables and their values to
2457 rl_outstream. If an explicit argument is given, then print
2458 the output in such a way that it can be read back in. */
2460 rl_dump_variables (count, key)
2464 fprintf (rl_outstream, "\r\n");
2465 rl_variable_dumper (rl_explicit_arg);
2470 /* Return non-zero if any members of ARRAY are a substring in STRING. */
2472 substring_member_of_array (string, array)
2474 const char * const *array;
2478 if (_rl_strindex (string, *array))