1 /* bind.c -- key binding and startup file support for the readline library. */
3 /* Copyright (C) 1987-2005 Free Software Foundation, Inc.
5 This file is part of the GNU Readline Library, a library for
6 reading lines of text with interactive input and history editing.
8 The GNU Readline Library is free software; you can redistribute it
9 and/or modify it under the terms of the GNU General Public License
10 as published by the Free Software Foundation; either version 2, or
11 (at your option) any later version.
13 The GNU Readline Library is distributed in the hope that it will be
14 useful, but WITHOUT ANY WARRANTY; without even the implied warranty
15 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 The GNU General Public License is often shipped with GNU software, and
19 is generally kept in a file called COPYING or LICENSE. If you do not
20 have a copy of the license, write to the Free Software Foundation,
21 59 Temple Place, Suite 330, Boston, MA 02111 USA. */
23 #define READLINE_LIBRARY
25 #if defined (__TANDEM)
29 #if defined (HAVE_CONFIG_H)
34 #include <sys/types.h>
36 #if defined (HAVE_SYS_FILE_H)
37 # include <sys/file.h>
38 #endif /* HAVE_SYS_FILE_H */
40 #if defined (HAVE_UNISTD_H)
42 #endif /* HAVE_UNISTD_H */
44 #if defined (HAVE_STDLIB_H)
47 # include "ansi_stdlib.h"
48 #endif /* HAVE_STDLIB_H */
56 #include "posixstat.h"
58 /* System-specific feature definitions and include files. */
61 /* Some standard library routines. */
65 #include "rlprivate.h"
69 #if !defined (strchr) && !defined (__STDC__)
70 extern char *strchr (), *strrchr ();
71 #endif /* !strchr && !__STDC__ */
73 /* Variables exported by this file. */
74 Keymap rl_binding_keymap
;
76 static char *_rl_read_file
PARAMS((char *, size_t *));
77 static void _rl_init_file_error
PARAMS((const char *));
78 static int _rl_read_init_file
PARAMS((const char *, int));
79 static int glean_key_from_name
PARAMS((char *));
80 static int find_boolean_var
PARAMS((const char *));
82 static char *_rl_get_string_variable_value
PARAMS((const char *));
83 static int substring_member_of_array
PARAMS((char *, const char **));
85 static int currently_reading_init_file
;
87 /* used only in this file */
88 static int _rl_prefer_visible_bell
= 1;
90 /* **************************************************************** */
94 /* **************************************************************** */
96 /* rl_add_defun (char *name, rl_command_func_t *function, int key)
97 Add NAME to the list of named functions. Make FUNCTION be the function
98 that gets called. If KEY is not -1, then bind it. */
100 rl_add_defun (name
, function
, key
)
102 rl_command_func_t
*function
;
106 rl_bind_key (key
, function
);
107 rl_add_funmap_entry (name
, function
);
111 /* Bind KEY to FUNCTION. Returns non-zero if KEY is out of range. */
113 rl_bind_key (key
, function
)
115 rl_command_func_t
*function
;
120 if (META_CHAR (key
) && _rl_convert_meta_chars_to_ascii
)
122 if (_rl_keymap
[ESC
].type
== ISKMAP
)
126 escmap
= FUNCTION_TO_KEYMAP (_rl_keymap
, ESC
);
128 escmap
[key
].type
= ISFUNC
;
129 escmap
[key
].function
= function
;
135 _rl_keymap
[key
].type
= ISFUNC
;
136 _rl_keymap
[key
].function
= function
;
137 rl_binding_keymap
= _rl_keymap
;
141 /* Bind KEY to FUNCTION in MAP. Returns non-zero in case of invalid
144 rl_bind_key_in_map (key
, function
, map
)
146 rl_command_func_t
*function
;
154 result
= rl_bind_key (key
, function
);
159 /* Bind key sequence KEYSEQ to DEFAULT_FUNC if KEYSEQ is unbound. Right
160 now, this is always used to attempt to bind the arrow keys, hence the
161 check for rl_vi_movement_mode. */
163 rl_bind_key_if_unbound_in_map (key
, default_func
, kmap
)
165 rl_command_func_t
*default_func
;
170 keyseq
[0] = (unsigned char)key
;
172 return (rl_bind_keyseq_if_unbound_in_map (keyseq
, default_func
, kmap
));
176 rl_bind_key_if_unbound (key
, default_func
)
178 rl_command_func_t
*default_func
;
182 keyseq
[0] = (unsigned char)key
;
184 return (rl_bind_keyseq_if_unbound_in_map (keyseq
, default_func
, _rl_keymap
));
187 /* Make KEY do nothing in the currently selected keymap.
188 Returns non-zero in case of error. */
193 return (rl_bind_key (key
, (rl_command_func_t
*)NULL
));
196 /* Make KEY do nothing in MAP.
197 Returns non-zero in case of error. */
199 rl_unbind_key_in_map (key
, map
)
203 return (rl_bind_key_in_map (key
, (rl_command_func_t
*)NULL
, map
));
206 /* Unbind all keys bound to FUNCTION in MAP. */
208 rl_unbind_function_in_map (func
, map
)
209 rl_command_func_t
*func
;
212 register int i
, rval
;
214 for (i
= rval
= 0; i
< KEYMAP_SIZE
; i
++)
216 if (map
[i
].type
== ISFUNC
&& map
[i
].function
== func
)
218 map
[i
].function
= (rl_command_func_t
*)NULL
;
226 rl_unbind_command_in_map (command
, map
)
230 rl_command_func_t
*func
;
232 func
= rl_named_function (command
);
235 return (rl_unbind_function_in_map (func
, map
));
238 /* Bind the key sequence represented by the string KEYSEQ to
239 FUNCTION, starting in the current keymap. This makes new
240 keymaps as necessary. */
242 rl_bind_keyseq (keyseq
, function
)
244 rl_command_func_t
*function
;
246 return (rl_generic_bind (ISFUNC
, keyseq
, (char *)function
, _rl_keymap
));
249 /* Bind the key sequence represented by the string KEYSEQ to
250 FUNCTION. This makes new keymaps as necessary. The initial
251 place to do bindings is in MAP. */
253 rl_bind_keyseq_in_map (keyseq
, function
, map
)
255 rl_command_func_t
*function
;
258 return (rl_generic_bind (ISFUNC
, keyseq
, (char *)function
, map
));
261 /* Backwards compatibility; equivalent to rl_bind_keyseq_in_map() */
263 rl_set_key (keyseq
, function
, map
)
265 rl_command_func_t
*function
;
268 return (rl_generic_bind (ISFUNC
, keyseq
, (char *)function
, map
));
271 /* Bind key sequence KEYSEQ to DEFAULT_FUNC if KEYSEQ is unbound. Right
272 now, this is always used to attempt to bind the arrow keys, hence the
273 check for rl_vi_movement_mode. */
275 rl_bind_keyseq_if_unbound_in_map (keyseq
, default_func
, kmap
)
277 rl_command_func_t
*default_func
;
280 rl_command_func_t
*func
;
284 func
= rl_function_of_keyseq (keyseq
, kmap
, (int *)NULL
);
285 #if defined (VI_MODE)
286 if (!func
|| func
== rl_do_lowercase_version
|| func
== rl_vi_movement_mode
)
288 if (!func
|| func
== rl_do_lowercase_version
)
290 return (rl_bind_keyseq_in_map (keyseq
, default_func
, kmap
));
298 rl_bind_keyseq_if_unbound (keyseq
, default_func
)
300 rl_command_func_t
*default_func
;
302 return (rl_bind_keyseq_if_unbound_in_map (keyseq
, default_func
, _rl_keymap
));
305 /* Bind the key sequence represented by the string KEYSEQ to
306 the string of characters MACRO. This makes new keymaps as
307 necessary. The initial place to do bindings is in MAP. */
309 rl_macro_bind (keyseq
, macro
, map
)
310 const char *keyseq
, *macro
;
316 macro_keys
= (char *)xmalloc ((2 * strlen (macro
)) + 1);
318 if (rl_translate_keyseq (macro
, macro_keys
, ¯o_keys_len
))
323 rl_generic_bind (ISMACR
, keyseq
, macro_keys
, map
);
327 /* Bind the key sequence represented by the string KEYSEQ to
328 the arbitrary pointer DATA. TYPE says what kind of data is
329 pointed to by DATA, right now this can be a function (ISFUNC),
330 a macro (ISMACR), or a keymap (ISKMAP). This makes new keymaps
331 as necessary. The initial place to do bindings is in MAP. */
333 rl_generic_bind (type
, keyseq
, data
, map
)
346 /* If no keys to bind to, exit right away. */
347 if (keyseq
== 0 || *keyseq
== 0)
354 keys
= (char *)xmalloc (1 + (2 * strlen (keyseq
)));
356 /* Translate the ASCII representation of KEYSEQ into an array of
357 characters. Stuff the characters into KEYS, and the length of
358 KEYS into KEYS_LEN. */
359 if (rl_translate_keyseq (keyseq
, keys
, &keys_len
))
365 /* Bind keys, making new keymaps as necessary. */
366 for (i
= 0; i
< keys_len
; i
++)
368 unsigned char uc
= keys
[i
];
372 if (ic
< 0 || ic
>= KEYMAP_SIZE
)
375 if (META_CHAR (ic
) && _rl_convert_meta_chars_to_ascii
)
378 if (map
[ESC
].type
== ISKMAP
)
379 map
= FUNCTION_TO_KEYMAP (map
, ESC
);
382 if ((i
+ 1) < keys_len
)
384 if (map
[ic
].type
!= ISKMAP
)
386 /* We allow subsequences of keys. If a keymap is being
387 created that will `shadow' an existing function or macro
388 key binding, we save that keybinding into the ANYOTHERKEY
389 index in the new map. The dispatch code will look there
390 to find the function to execute if the subsequence is not
391 matched. ANYOTHERKEY was chosen to be greater than
395 map
[ic
].type
= ISKMAP
;
396 map
[ic
].function
= KEYMAP_TO_FUNCTION (rl_make_bare_keymap());
398 map
= FUNCTION_TO_KEYMAP (map
, ic
);
399 /* The dispatch code will return this function if no matching
400 key sequence is found in the keymap. This (with a little
401 help from the dispatch code in readline.c) allows `a' to be
402 mapped to something, `abc' to be mapped to something else,
403 and the function bound to `a' to be executed when the user
404 types `abx', leaving `bx' in the input queue. */
405 if (k
.function
&& ((k
.type
== ISFUNC
&& k
.function
!= rl_do_lowercase_version
) || k
.type
== ISMACR
))
407 map
[ANYOTHERKEY
] = k
;
413 if (map
[ic
].type
== ISMACR
)
414 free ((char *)map
[ic
].function
);
415 else if (map
[ic
].type
== ISKMAP
)
417 map
= FUNCTION_TO_KEYMAP (map
, ic
);
421 map
[ic
].function
= KEYMAP_TO_FUNCTION (data
);
425 rl_binding_keymap
= map
;
431 /* Translate the ASCII representation of SEQ, stuffing the values into ARRAY,
432 an array of characters. LEN gets the final length of ARRAY. Return
433 non-zero if there was an error parsing SEQ. */
435 rl_translate_keyseq (seq
, array
, len
)
440 register int i
, c
, l
, temp
;
442 for (i
= l
= 0; c
= seq
[i
]; i
++)
451 /* Handle \C- and \M- prefixes. */
452 if ((c
== 'C' || c
== 'M') && seq
[i
+ 1] == '-')
454 /* Handle special case of backwards define. */
455 if (strncmp (&seq
[i
], "C-\\M-", 5) == 0)
457 array
[l
++] = ESC
; /* ESC is meta-prefix */
459 array
[l
++] = CTRL (_rl_to_upper (seq
[i
]));
466 /* XXX - should obey convert-meta setting? */
467 if (_rl_convert_meta_chars_to_ascii
&& _rl_keymap
[ESC
].type
== ISKMAP
)
468 array
[l
++] = ESC
; /* ESC is meta-prefix */
472 array
[l
++] = META (seq
[i
]);
478 /* Special hack for C-?... */
479 array
[l
++] = (seq
[i
] == '?') ? RUBOUT
: CTRL (_rl_to_upper (seq
[i
]));
484 /* Translate other backslash-escaped characters. These are the
485 same escape sequences that bash's `echo' and `printf' builtins
486 handle, with the addition of \d -> RUBOUT. A backslash
487 preceding a character that is not special is stripped. */
497 array
[l
++] = RUBOUT
; /* readline-specific */
506 array
[l
++] = NEWLINE
;
520 case '0': case '1': case '2': case '3':
521 case '4': case '5': case '6': case '7':
523 for (temp
= 2, c
-= '0'; ISOCTAL (seq
[i
]) && temp
--; i
++)
524 c
= (c
* 8) + OCTVALUE (seq
[i
]);
525 i
--; /* auto-increment in for loop */
526 array
[l
++] = c
& largest_char
;
530 for (temp
= 2, c
= 0; ISXDIGIT ((unsigned char)seq
[i
]) && temp
--; i
++)
531 c
= (c
* 16) + HEXVALUE (seq
[i
]);
534 i
--; /* auto-increment in for loop */
535 array
[l
++] = c
& largest_char
;
537 default: /* backslashes before non-special chars just add the char */
539 break; /* the backslash is stripped */
553 rl_untranslate_keyseq (seq
)
556 static char kseq
[16];
568 else if (CTRL_CHAR (c
))
573 c
= _rl_to_lower (UNCTRL (c
));
575 else if (c
== RUBOUT
)
588 else if (c
== '\\' || c
== '"')
593 kseq
[i
++] = (unsigned char) c
;
599 _rl_untranslate_macro_value (seq
)
605 r
= ret
= (char *)xmalloc (7 * strlen (seq
) + 1);
606 for (s
= seq
; *s
; s
++)
616 else if (CTRL_CHAR (c
) && c
!= ESC
)
621 c
= _rl_to_lower (UNCTRL (c
));
623 else if (c
== RUBOUT
)
636 else if (c
== '\\' || c
== '"')
639 *r
++ = (unsigned char)c
;
645 /* Return a pointer to the function that STRING represents.
646 If STRING doesn't have a matching function, then a NULL pointer
649 rl_named_function (string
)
654 rl_initialize_funmap ();
656 for (i
= 0; funmap
[i
]; i
++)
657 if (_rl_stricmp (funmap
[i
]->name
, string
) == 0)
658 return (funmap
[i
]->function
);
659 return ((rl_command_func_t
*)NULL
);
662 /* Return the function (or macro) definition which would be invoked via
663 KEYSEQ if executed in MAP. If MAP is NULL, then the current keymap is
664 used. TYPE, if non-NULL, is a pointer to an int which will receive the
665 type of the object pointed to. One of ISFUNC (function), ISKMAP (keymap),
666 or ISMACR (macro). */
668 rl_function_of_keyseq (keyseq
, map
, type
)
678 for (i
= 0; keyseq
&& keyseq
[i
]; i
++)
680 unsigned char ic
= keyseq
[i
];
682 if (META_CHAR (ic
) && _rl_convert_meta_chars_to_ascii
)
684 if (map
[ESC
].type
!= ISKMAP
)
687 *type
= map
[ESC
].type
;
689 return (map
[ESC
].function
);
693 map
= FUNCTION_TO_KEYMAP (map
, ESC
);
698 if (map
[ic
].type
== ISKMAP
)
700 /* If this is the last key in the key sequence, return the
707 return (map
[ic
].function
);
710 map
= FUNCTION_TO_KEYMAP (map
, ic
);
715 *type
= map
[ic
].type
;
717 return (map
[ic
].function
);
720 return ((rl_command_func_t
*) NULL
);
723 /* The last key bindings file read. */
724 static char *last_readline_init_file
= (char *)NULL
;
726 /* The file we're currently reading key bindings from. */
727 static const char *current_readline_init_file
;
728 static int current_readline_init_include_level
;
729 static int current_readline_init_lineno
;
731 /* Read FILENAME into a locally-allocated buffer and return the buffer.
732 The size of the buffer is returned in *SIZEP. Returns NULL if any
733 errors were encountered. */
735 _rl_read_file (filename
, sizep
)
744 if ((stat (filename
, &finfo
) < 0) || (file
= open (filename
, O_RDONLY
, 0666)) < 0)
745 return ((char *)NULL
);
747 file_size
= (size_t)finfo
.st_size
;
749 /* check for overflow on very large files */
750 if (file_size
!= finfo
.st_size
|| file_size
+ 1 < file_size
)
757 return ((char *)NULL
);
760 /* Read the file into BUFFER. */
761 buffer
= (char *)xmalloc (file_size
+ 1);
762 i
= read (file
, buffer
, file_size
);
768 return ((char *)NULL
);
778 /* Re-read the current keybindings file. */
780 rl_re_read_init_file (count
, ignore
)
784 r
= rl_read_init_file ((const char *)NULL
);
785 rl_set_keymap_from_edit_mode ();
789 /* Do key bindings from a file. If FILENAME is NULL it defaults
790 to the first non-null filename from this list:
791 1. the filename used for the previous call
792 2. the value of the shell variable `INPUTRC'
794 If the file existed and could be opened and read, 0 is returned,
795 otherwise errno is returned. */
797 rl_read_init_file (filename
)
798 const char *filename
;
800 /* Default the filename. */
803 filename
= last_readline_init_file
;
805 filename
= sh_get_env_value ("INPUTRC");
807 filename
= DEFAULT_INPUTRC
;
811 filename
= DEFAULT_INPUTRC
;
813 #if defined (__MSDOS__)
814 if (_rl_read_init_file (filename
, 0) == 0)
816 filename
= "~/_inputrc";
818 return (_rl_read_init_file (filename
, 0));
822 _rl_read_init_file (filename
, include_level
)
823 const char *filename
;
827 char *buffer
, *openname
, *line
, *end
;
830 current_readline_init_file
= filename
;
831 current_readline_init_include_level
= include_level
;
833 openname
= tilde_expand (filename
);
834 buffer
= _rl_read_file (openname
, &file_size
);
840 if (include_level
== 0 && filename
!= last_readline_init_file
)
842 FREE (last_readline_init_file
);
843 last_readline_init_file
= savestring (filename
);
846 currently_reading_init_file
= 1;
848 /* Loop over the lines in the file. Lines that start with `#' are
849 comments; all other lines are commands for readline initialization. */
850 current_readline_init_lineno
= 1;
852 end
= buffer
+ file_size
;
855 /* Find the end of this line. */
856 for (i
= 0; line
+ i
!= end
&& line
[i
] != '\n'; i
++);
858 #if defined (__CYGWIN__)
859 /* ``Be liberal in what you accept.'' */
860 if (line
[i
] == '\n' && line
[i
-1] == '\r')
864 /* Mark end of line. */
867 /* Skip leading whitespace. */
868 while (*line
&& whitespace (*line
))
874 /* If the line is not a comment, then parse it. */
875 if (*line
&& *line
!= '#')
876 rl_parse_and_bind (line
);
878 /* Move to the next line. */
880 current_readline_init_lineno
++;
884 currently_reading_init_file
= 0;
889 _rl_init_file_error (msg
)
892 if (currently_reading_init_file
)
893 fprintf (stderr
, "readline: %s: line %d: %s\n", current_readline_init_file
,
894 current_readline_init_lineno
, msg
);
896 fprintf (stderr
, "readline: %s\n", msg
);
899 /* **************************************************************** */
901 /* Parser Directives */
903 /* **************************************************************** */
905 typedef int _rl_parser_func_t
PARAMS((char *));
907 /* Things that mean `Control'. */
908 const char *_rl_possible_control_prefixes
[] = {
909 "Control-", "C-", "CTRL-", (const char *)NULL
912 const char *_rl_possible_meta_prefixes
[] = {
913 "Meta", "M-", (const char *)NULL
918 /* Calling programs set this to have their argv[0]. */
919 const char *rl_readline_name
= "other";
921 /* Stack of previous values of parsing_conditionalized_out. */
922 static unsigned char *if_stack
= (unsigned char *)NULL
;
923 static int if_stack_depth
;
924 static int if_stack_size
;
926 /* Push _rl_parsing_conditionalized_out, and set parser state based
934 /* Push parser state. */
935 if (if_stack_depth
+ 1 >= if_stack_size
)
938 if_stack
= (unsigned char *)xmalloc (if_stack_size
= 20);
940 if_stack
= (unsigned char *)xrealloc (if_stack
, if_stack_size
+= 20);
942 if_stack
[if_stack_depth
++] = _rl_parsing_conditionalized_out
;
944 /* If parsing is turned off, then nothing can turn it back on except
945 for finding the matching endif. In that case, return right now. */
946 if (_rl_parsing_conditionalized_out
)
949 /* Isolate first argument. */
950 for (i
= 0; args
[i
] && !whitespace (args
[i
]); i
++);
955 /* Handle "$if term=foo" and "$if mode=emacs" constructs. If this
956 isn't term=foo, or mode=emacs, then check to see if the first
957 word in ARGS is the same as the value stored in rl_readline_name. */
958 if (rl_terminal_name
&& _rl_strnicmp (args
, "term=", 5) == 0)
962 /* Terminals like "aaa-60" are equivalent to "aaa". */
963 tname
= savestring (rl_terminal_name
);
964 tem
= strchr (tname
, '-');
968 /* Test the `long' and `short' forms of the terminal name so that
969 if someone has a `sun-cmd' and does not want to have bindings
970 that will be executed if the terminal is a `sun', they can put
971 `$if term=sun-cmd' into their .inputrc. */
972 _rl_parsing_conditionalized_out
= _rl_stricmp (args
+ 5, tname
) &&
973 _rl_stricmp (args
+ 5, rl_terminal_name
);
976 #if defined (VI_MODE)
977 else if (_rl_strnicmp (args
, "mode=", 5) == 0)
981 if (_rl_stricmp (args
+ 5, "emacs") == 0)
983 else if (_rl_stricmp (args
+ 5, "vi") == 0)
988 _rl_parsing_conditionalized_out
= mode
!= rl_editing_mode
;
991 /* Check to see if the first word in ARGS is the same as the
992 value stored in rl_readline_name. */
993 else if (_rl_stricmp (args
, rl_readline_name
) == 0)
994 _rl_parsing_conditionalized_out
= 0;
996 _rl_parsing_conditionalized_out
= 1;
1000 /* Invert the current parser state if there is anything on the stack. */
1007 if (if_stack_depth
== 0)
1009 _rl_init_file_error ("$else found without matching $if");
1014 /* Check the previous (n - 1) levels of the stack to make sure that
1015 we haven't previously turned off parsing. */
1016 for (i
= 0; i
< if_stack_depth
- 1; i
++)
1018 /* Check the previous (n) levels of the stack to make sure that
1019 we haven't previously turned off parsing. */
1020 for (i
= 0; i
< if_stack_depth
; i
++)
1022 if (if_stack
[i
] == 1)
1025 /* Invert the state of parsing if at top level. */
1026 _rl_parsing_conditionalized_out
= !_rl_parsing_conditionalized_out
;
1030 /* Terminate a conditional, popping the value of
1031 _rl_parsing_conditionalized_out from the stack. */
1037 _rl_parsing_conditionalized_out
= if_stack
[--if_stack_depth
];
1039 _rl_init_file_error ("$endif without matching $if");
1044 parser_include (args
)
1047 const char *old_init_file
;
1049 int old_line_number
, old_include_level
, r
;
1051 if (_rl_parsing_conditionalized_out
)
1054 old_init_file
= current_readline_init_file
;
1055 old_line_number
= current_readline_init_lineno
;
1056 old_include_level
= current_readline_init_include_level
;
1058 e
= strchr (args
, '\n');
1061 r
= _rl_read_init_file ((const char *)args
, old_include_level
+ 1);
1063 current_readline_init_file
= old_init_file
;
1064 current_readline_init_lineno
= old_line_number
;
1065 current_readline_init_include_level
= old_include_level
;
1070 /* Associate textual names with actual functions. */
1073 _rl_parser_func_t
*function
;
1074 } parser_directives
[] = {
1075 { "if", parser_if
},
1076 { "endif", parser_endif
},
1077 { "else", parser_else
},
1078 { "include", parser_include
},
1079 { (char *)0x0, (_rl_parser_func_t
*)0x0 }
1082 /* Handle a parser directive. STATEMENT is the line of the directive
1083 without any leading `$'. */
1085 handle_parser_directive (statement
)
1089 char *directive
, *args
;
1091 /* Isolate the actual directive. */
1093 /* Skip whitespace. */
1094 for (i
= 0; whitespace (statement
[i
]); i
++);
1096 directive
= &statement
[i
];
1098 for (; statement
[i
] && !whitespace (statement
[i
]); i
++);
1101 statement
[i
++] = '\0';
1103 for (; statement
[i
] && whitespace (statement
[i
]); i
++);
1105 args
= &statement
[i
];
1107 /* Lookup the command, and act on it. */
1108 for (i
= 0; parser_directives
[i
].name
; i
++)
1109 if (_rl_stricmp (directive
, parser_directives
[i
].name
) == 0)
1111 (*parser_directives
[i
].function
) (args
);
1115 /* display an error message about the unknown parser directive */
1116 _rl_init_file_error ("unknown parser directive");
1120 /* Read the binding command from STRING and perform it.
1121 A key binding command looks like: Keyname: function-name\0,
1122 a variable binding command looks like: set variable value.
1123 A new-style keybinding looks like "\C-x\C-x": exchange-point-and-mark. */
1125 rl_parse_and_bind (string
)
1128 char *funname
, *kname
;
1130 int key
, equivalency
;
1132 while (string
&& whitespace (*string
))
1135 if (!string
|| !*string
|| *string
== '#')
1138 /* If this is a parser directive, act on it. */
1141 handle_parser_directive (&string
[1]);
1145 /* If we aren't supposed to be parsing right now, then we're done. */
1146 if (_rl_parsing_conditionalized_out
)
1150 /* If this keyname is a complex key expression surrounded by quotes,
1151 advance to after the matching close quote. This code allows the
1152 backslash to quote characters in the key expression. */
1157 for (i
= 1; c
= string
[i
]; i
++)
1174 /* If we didn't find a closing quote, abort the line. */
1175 if (string
[i
] == '\0')
1177 _rl_init_file_error ("no closing `\"' in key binding");
1182 /* Advance to the colon (:) or whitespace which separates the two objects. */
1183 for (; (c
= string
[i
]) && c
!= ':' && c
!= ' ' && c
!= '\t'; i
++ );
1185 equivalency
= (c
== ':' && string
[i
+ 1] == '=');
1187 /* Mark the end of the command (or keyname). */
1191 /* If doing assignment, skip the '=' sign as well. */
1195 /* If this is a command to set a variable, then do that. */
1196 if (_rl_stricmp (string
, "set") == 0)
1198 char *var
, *value
, *e
;
1201 /* Make VAR point to start of variable name. */
1202 while (*var
&& whitespace (*var
)) var
++;
1204 /* Make VALUE point to start of value string. */
1206 while (*value
&& !whitespace (*value
)) value
++;
1209 while (*value
&& whitespace (*value
)) value
++;
1211 /* Strip trailing whitespace from values to boolean variables. Temp
1212 fix until I get a real quoted-string parser here. */
1213 i
= find_boolean_var (var
);
1216 /* remove trailing whitespace */
1217 e
= value
+ strlen (value
) - 1;
1218 while (e
>= value
&& whitespace (*e
))
1220 e
++; /* skip back to whitespace or EOS */
1221 if (*e
&& e
>= value
)
1225 rl_variable_bind (var
, value
);
1229 /* Skip any whitespace between keyname and funname. */
1230 for (; string
[i
] && whitespace (string
[i
]); i
++);
1231 funname
= &string
[i
];
1233 /* Now isolate funname.
1234 For straight function names just look for whitespace, since
1235 that will signify the end of the string. But this could be a
1236 macro definition. In that case, the string is quoted, so skip
1237 to the matching delimiter. We allow the backslash to quote the
1238 delimiter characters in the macro body. */
1239 /* This code exists to allow whitespace in macro expansions, which
1240 would otherwise be gobbled up by the next `for' loop.*/
1241 /* XXX - it may be desirable to allow backslash quoting only if " is
1242 the quoted string delimiter, like the shell. */
1243 if (*funname
== '\'' || *funname
== '"')
1245 int delimiter
, passc
;
1247 delimiter
= string
[i
++];
1248 for (passc
= 0; c
= string
[i
]; i
++)
1269 /* Advance to the end of the string. */
1270 for (; string
[i
] && !whitespace (string
[i
]); i
++);
1272 /* No extra whitespace at the end of the string. */
1275 /* Handle equivalency bindings here. Make the left-hand side be exactly
1276 whatever the right-hand evaluates to, including keymaps. */
1282 /* If this is a new-style key-binding, then do the binding with
1283 rl_bind_keyseq (). Otherwise, let the older code deal with it. */
1287 register int j
, k
, passc
;
1289 seq
= (char *)xmalloc (1 + strlen (string
));
1290 for (j
= 1, k
= passc
= 0; string
[j
]; j
++)
1292 /* Allow backslash to quote characters, but leave them in place.
1293 This allows a string to end with a backslash quoting another
1294 backslash, or with a backslash quoting a double quote. The
1295 backslashes are left in place for rl_translate_keyseq (). */
1296 if (passc
|| (string
[j
] == '\\'))
1298 seq
[k
++] = string
[j
];
1303 if (string
[j
] == '"')
1306 seq
[k
++] = string
[j
];
1310 /* Binding macro? */
1311 if (*funname
== '\'' || *funname
== '"')
1313 j
= strlen (funname
);
1315 /* Remove the delimiting quotes from each end of FUNNAME. */
1316 if (j
&& funname
[j
- 1] == *funname
)
1317 funname
[j
- 1] = '\0';
1319 rl_macro_bind (seq
, &funname
[1], _rl_keymap
);
1322 rl_bind_keyseq (seq
, rl_named_function (funname
));
1328 /* Get the actual character we want to deal with. */
1329 kname
= strrchr (string
, '-');
1335 key
= glean_key_from_name (kname
);
1337 /* Add in control and meta bits. */
1338 if (substring_member_of_array (string
, _rl_possible_control_prefixes
))
1339 key
= CTRL (_rl_to_upper (key
));
1341 if (substring_member_of_array (string
, _rl_possible_meta_prefixes
))
1344 /* Temporary. Handle old-style keyname with macro-binding. */
1345 if (*funname
== '\'' || *funname
== '"')
1348 int fl
= strlen (funname
);
1350 useq
[0] = key
; useq
[1] = '\0';
1351 if (fl
&& funname
[fl
- 1] == *funname
)
1352 funname
[fl
- 1] = '\0';
1354 rl_macro_bind (useq
, &funname
[1], _rl_keymap
);
1356 #if defined (PREFIX_META_HACK)
1357 /* Ugly, but working hack to keep prefix-meta around. */
1358 else if (_rl_stricmp (funname
, "prefix-meta") == 0)
1364 rl_generic_bind (ISKMAP
, seq
, (char *)emacs_meta_keymap
, _rl_keymap
);
1366 #endif /* PREFIX_META_HACK */
1368 rl_bind_key (key
, rl_named_function (funname
));
1372 /* Simple structure for boolean readline variables (i.e., those that can
1373 have one of two values; either "On" or 1 for truth, or "Off" or 0 for
1376 #define V_SPECIAL 0x1
1382 } boolean_varlist
[] = {
1383 { "bind-tty-special-chars", &_rl_bind_stty_chars
, 0 },
1384 { "blink-matching-paren", &rl_blink_matching_paren
, V_SPECIAL
},
1385 { "byte-oriented", &rl_byte_oriented
, 0 },
1386 { "completion-ignore-case", &_rl_completion_case_fold
, 0 },
1387 { "convert-meta", &_rl_convert_meta_chars_to_ascii
, 0 },
1388 { "disable-completion", &rl_inhibit_completion
, 0 },
1389 { "enable-keypad", &_rl_enable_keypad
, 0 },
1390 { "expand-tilde", &rl_complete_with_tilde_expansion
, 0 },
1391 { "history-preserve-point", &_rl_history_preserve_point
, 0 },
1392 { "horizontal-scroll-mode", &_rl_horizontal_scroll_mode
, 0 },
1393 { "input-meta", &_rl_meta_flag
, 0 },
1394 { "mark-directories", &_rl_complete_mark_directories
, 0 },
1395 { "mark-modified-lines", &_rl_mark_modified_lines
, 0 },
1396 { "mark-symlinked-directories", &_rl_complete_mark_symlink_dirs
, 0 },
1397 { "match-hidden-files", &_rl_match_hidden_files
, 0 },
1398 { "meta-flag", &_rl_meta_flag
, 0 },
1399 { "output-meta", &_rl_output_meta_chars
, 0 },
1400 { "page-completions", &_rl_page_completions
, 0 },
1401 { "prefer-visible-bell", &_rl_prefer_visible_bell
, V_SPECIAL
},
1402 { "print-completions-horizontally", &_rl_print_completions_horizontally
, 0 },
1403 { "show-all-if-ambiguous", &_rl_complete_show_all
, 0 },
1404 { "show-all-if-unmodified", &_rl_complete_show_unmodified
, 0 },
1405 #if defined (VISIBLE_STATS)
1406 { "visible-stats", &rl_visible_stats
, 0 },
1407 #endif /* VISIBLE_STATS */
1408 { (char *)NULL
, (int *)NULL
}
1412 find_boolean_var (name
)
1417 for (i
= 0; boolean_varlist
[i
].name
; i
++)
1418 if (_rl_stricmp (name
, boolean_varlist
[i
].name
) == 0)
1423 /* Hooks for handling special boolean variables, where a
1424 function needs to be called or another variable needs
1425 to be changed when they're changed. */
1427 hack_special_boolean_var (i
)
1432 name
= boolean_varlist
[i
].name
;
1434 if (_rl_stricmp (name
, "blink-matching-paren") == 0)
1435 _rl_enable_paren_matching (rl_blink_matching_paren
);
1436 else if (_rl_stricmp (name
, "prefer-visible-bell") == 0)
1438 if (_rl_prefer_visible_bell
)
1439 _rl_bell_preference
= VISIBLE_BELL
;
1441 _rl_bell_preference
= AUDIBLE_BELL
;
1445 typedef int _rl_sv_func_t
PARAMS((const char *));
1447 /* These *must* correspond to the array indices for the appropriate
1448 string variable. (Though they're not used right now.) */
1449 #define V_BELLSTYLE 0
1450 #define V_COMBEGIN 1
1451 #define V_EDITMODE 2
1452 #define V_ISRCHTERM 3
1458 /* Forward declarations */
1459 static int sv_bell_style
PARAMS((const char *));
1460 static int sv_combegin
PARAMS((const char *));
1461 static int sv_compquery
PARAMS((const char *));
1462 static int sv_editmode
PARAMS((const char *));
1463 static int sv_isrchterm
PARAMS((const char *));
1464 static int sv_keymap
PARAMS((const char *));
1469 _rl_sv_func_t
*set_func
;
1470 } string_varlist
[] = {
1471 { "bell-style", V_STRING
, sv_bell_style
},
1472 { "comment-begin", V_STRING
, sv_combegin
},
1473 { "completion-query-items", V_INT
, sv_compquery
},
1474 { "editing-mode", V_STRING
, sv_editmode
},
1475 { "isearch-terminators", V_STRING
, sv_isrchterm
},
1476 { "keymap", V_STRING
, sv_keymap
},
1481 find_string_var (name
)
1486 for (i
= 0; string_varlist
[i
].name
; i
++)
1487 if (_rl_stricmp (name
, string_varlist
[i
].name
) == 0)
1492 /* A boolean value that can appear in a `set variable' command is true if
1493 the value is null or empty, `on' (case-insenstive), or "1". Any other
1494 values result in 0 (false). */
1499 return (value
== 0 || *value
== '\0' ||
1500 (_rl_stricmp (value
, "on") == 0) ||
1501 (value
[0] == '1' && value
[1] == '\0'));
1505 rl_variable_value (name
)
1512 /* Check for simple variables first. */
1513 i
= find_boolean_var (name
);
1515 return (*boolean_varlist
[i
].value
? "on" : "off");
1517 i
= find_string_var (name
);
1519 return (_rl_get_string_variable_value (string_varlist
[i
].name
));
1521 /* Unknown variable names return NULL. */
1526 rl_variable_bind (name
, value
)
1527 const char *name
, *value
;
1532 /* Check for simple variables first. */
1533 i
= find_boolean_var (name
);
1536 *boolean_varlist
[i
].value
= bool_to_int (value
);
1537 if (boolean_varlist
[i
].flags
& V_SPECIAL
)
1538 hack_special_boolean_var (i
);
1542 i
= find_string_var (name
);
1544 /* For the time being, unknown variable names or string names without a
1545 handler function are simply ignored. */
1546 if (i
< 0 || string_varlist
[i
].set_func
== 0)
1549 v
= (*string_varlist
[i
].set_func
) (value
);
1557 if (_rl_strnicmp (value
, "vi", 2) == 0)
1559 #if defined (VI_MODE)
1560 _rl_keymap
= vi_insertion_keymap
;
1561 rl_editing_mode
= vi_mode
;
1562 #endif /* VI_MODE */
1565 else if (_rl_strnicmp (value
, "emacs", 5) == 0)
1567 _rl_keymap
= emacs_standard_keymap
;
1568 rl_editing_mode
= emacs_mode
;
1578 if (value
&& *value
)
1580 FREE (_rl_comment_begin
);
1581 _rl_comment_begin
= savestring (value
);
1588 sv_compquery (value
)
1593 if (value
&& *value
)
1595 nval
= atoi (value
);
1599 rl_completion_query_items
= nval
;
1609 kmap
= rl_get_keymap_by_name (value
);
1612 rl_set_keymap (kmap
);
1619 sv_bell_style (value
)
1622 if (value
== 0 || *value
== '\0')
1623 _rl_bell_preference
= AUDIBLE_BELL
;
1624 else if (_rl_stricmp (value
, "none") == 0 || _rl_stricmp (value
, "off") == 0)
1625 _rl_bell_preference
= NO_BELL
;
1626 else if (_rl_stricmp (value
, "audible") == 0 || _rl_stricmp (value
, "on") == 0)
1627 _rl_bell_preference
= AUDIBLE_BELL
;
1628 else if (_rl_stricmp (value
, "visible") == 0)
1629 _rl_bell_preference
= VISIBLE_BELL
;
1636 sv_isrchterm (value
)
1639 int beg
, end
, delim
;
1645 /* Isolate the value and translate it into a character string. */
1646 v
= savestring (value
);
1647 FREE (_rl_isearch_terminators
);
1648 if (v
[0] == '"' || v
[0] == '\'')
1651 for (beg
= end
= 1; v
[end
] && v
[end
] != delim
; end
++)
1656 for (beg
= end
= 0; whitespace (v
[end
]) == 0; end
++)
1662 /* The value starts at v + beg. Translate it into a character string. */
1663 _rl_isearch_terminators
= (char *)xmalloc (2 * strlen (v
) + 1);
1664 rl_translate_keyseq (v
+ beg
, _rl_isearch_terminators
, &end
);
1665 _rl_isearch_terminators
[end
] = '\0';
1671 /* Return the character which matches NAME.
1672 For example, `Space' returns ' '. */
1679 static assoc_list name_key_alist
[] = {
1682 { "Escape", '\033' },
1684 { "Newline", '\n' },
1695 glean_key_from_name (name
)
1700 for (i
= 0; name_key_alist
[i
].name
; i
++)
1701 if (_rl_stricmp (name
, name_key_alist
[i
].name
) == 0)
1702 return (name_key_alist
[i
].value
);
1704 return (*(unsigned char *)name
); /* XXX was return (*name) */
1707 /* Auxiliary functions to manage keymaps. */
1711 } keymap_names
[] = {
1712 { "emacs", emacs_standard_keymap
},
1713 { "emacs-standard", emacs_standard_keymap
},
1714 { "emacs-meta", emacs_meta_keymap
},
1715 { "emacs-ctlx", emacs_ctlx_keymap
},
1716 #if defined (VI_MODE)
1717 { "vi", vi_movement_keymap
},
1718 { "vi-move", vi_movement_keymap
},
1719 { "vi-command", vi_movement_keymap
},
1720 { "vi-insert", vi_insertion_keymap
},
1721 #endif /* VI_MODE */
1722 { (char *)0x0, (Keymap
)0x0 }
1726 rl_get_keymap_by_name (name
)
1731 for (i
= 0; keymap_names
[i
].name
; i
++)
1732 if (_rl_stricmp (name
, keymap_names
[i
].name
) == 0)
1733 return (keymap_names
[i
].map
);
1734 return ((Keymap
) NULL
);
1738 rl_get_keymap_name (map
)
1742 for (i
= 0; keymap_names
[i
].name
; i
++)
1743 if (map
== keymap_names
[i
].map
)
1744 return ((char *)keymap_names
[i
].name
);
1745 return ((char *)NULL
);
1759 return (_rl_keymap
);
1763 rl_set_keymap_from_edit_mode ()
1765 if (rl_editing_mode
== emacs_mode
)
1766 _rl_keymap
= emacs_standard_keymap
;
1767 #if defined (VI_MODE)
1768 else if (rl_editing_mode
== vi_mode
)
1769 _rl_keymap
= vi_insertion_keymap
;
1770 #endif /* VI_MODE */
1774 rl_get_keymap_name_from_edit_mode ()
1776 if (rl_editing_mode
== emacs_mode
)
1778 #if defined (VI_MODE)
1779 else if (rl_editing_mode
== vi_mode
)
1781 #endif /* VI_MODE */
1786 /* **************************************************************** */
1788 /* Key Binding and Function Information */
1790 /* **************************************************************** */
1792 /* Each of the following functions produces information about the
1793 state of keybindings and functions known to Readline. The info
1794 is always printed to rl_outstream, and in such a way that it can
1795 be read back in (i.e., passed to rl_parse_and_bind ()). */
1797 /* Print the names of functions known to Readline. */
1799 rl_list_funmap_names ()
1802 const char **funmap_names
;
1804 funmap_names
= rl_funmap_names ();
1809 for (i
= 0; funmap_names
[i
]; i
++)
1810 fprintf (rl_outstream
, "%s\n", funmap_names
[i
]);
1812 free (funmap_names
);
1816 _rl_get_keyname (key
)
1822 keyname
= (char *)xmalloc (8);
1825 /* Since this is going to be used to write out keysequence-function
1826 pairs for possible inclusion in an inputrc file, we don't want to
1827 do any special meta processing on KEY. */
1830 /* XXX - Experimental */
1831 /* We might want to do this, but the old version of the code did not. */
1833 /* If this is an escape character, we don't want to do any more processing.
1834 Just add the special ESC key sequence and return. */
1844 /* RUBOUT is translated directly into \C-? */
1856 /* Now add special prefixes needed for control characters. This can
1857 potentially change C. */
1860 keyname
[i
++] = '\\';
1863 c
= _rl_to_lower (UNCTRL (c
));
1866 /* XXX experimental code. Turn the characters that are not ASCII or
1867 ISO Latin 1 (128 - 159) into octal escape sequences (\200 - \237).
1869 if (c
>= 128 && c
<= 159)
1871 keyname
[i
++] = '\\';
1874 keyname
[i
++] = (c
/ 8) + '0';
1878 /* Now, if the character needs to be quoted with a backslash, do that. */
1879 if (c
== '\\' || c
== '"')
1880 keyname
[i
++] = '\\';
1882 /* Now add the key, terminate the string, and return it. */
1883 keyname
[i
++] = (char) c
;
1889 /* Return a NULL terminated array of strings which represent the key
1890 sequences that are used to invoke FUNCTION in MAP. */
1892 rl_invoking_keyseqs_in_map (function
, map
)
1893 rl_command_func_t
*function
;
1898 int result_index
, result_size
;
1900 result
= (char **)NULL
;
1901 result_index
= result_size
= 0;
1903 for (key
= 0; key
< KEYMAP_SIZE
; key
++)
1905 switch (map
[key
].type
)
1908 /* Macros match, if, and only if, the pointers are identical.
1909 Thus, they are treated exactly like functions in here. */
1911 /* If the function in the keymap is the one we are looking for,
1912 then add the current KEY to the list of invoking keys. */
1913 if (map
[key
].function
== function
)
1917 keyname
= _rl_get_keyname (key
);
1919 if (result_index
+ 2 > result_size
)
1922 result
= (char **)xrealloc (result
, result_size
* sizeof (char *));
1925 result
[result_index
++] = keyname
;
1926 result
[result_index
] = (char *)NULL
;
1935 /* Find the list of keyseqs in this map which have FUNCTION as
1936 their target. Add the key sequences found to RESULT. */
1937 if (map
[key
].function
)
1939 rl_invoking_keyseqs_in_map (function
, FUNCTION_TO_KEYMAP (map
, key
));
1946 for (i
= 0; seqs
[i
]; i
++)
1948 char *keyname
= (char *)xmalloc (6 + strlen (seqs
[i
]));
1952 sprintf (keyname
, "\\e");
1954 /* XXX - experimental */
1955 sprintf (keyname
, "\\M-");
1957 else if (CTRL_CHAR (key
))
1958 sprintf (keyname
, "\\C-%c", _rl_to_lower (UNCTRL (key
)));
1959 else if (key
== RUBOUT
)
1960 sprintf (keyname
, "\\C-?");
1961 else if (key
== '\\' || key
== '"')
1964 keyname
[1] = (char) key
;
1969 keyname
[0] = (char) key
;
1973 strcat (keyname
, seqs
[i
]);
1976 if (result_index
+ 2 > result_size
)
1979 result
= (char **)xrealloc (result
, result_size
* sizeof (char *));
1982 result
[result_index
++] = keyname
;
1983 result
[result_index
] = (char *)NULL
;
1994 /* Return a NULL terminated array of strings which represent the key
1995 sequences that can be used to invoke FUNCTION using the current keymap. */
1997 rl_invoking_keyseqs (function
)
1998 rl_command_func_t
*function
;
2000 return (rl_invoking_keyseqs_in_map (function
, _rl_keymap
));
2003 /* Print all of the functions and their bindings to rl_outstream. If
2004 PRINT_READABLY is non-zero, then print the output in such a way
2005 that it can be read back in. */
2007 rl_function_dumper (print_readably
)
2014 names
= rl_funmap_names ();
2016 fprintf (rl_outstream
, "\n");
2018 for (i
= 0; name
= names
[i
]; i
++)
2020 rl_command_func_t
*function
;
2023 function
= rl_named_function (name
);
2024 invokers
= rl_invoking_keyseqs_in_map (function
, _rl_keymap
);
2029 fprintf (rl_outstream
, "# %s (not bound)\n", name
);
2034 for (j
= 0; invokers
[j
]; j
++)
2036 fprintf (rl_outstream
, "\"%s\": %s\n",
2047 fprintf (rl_outstream
, "%s is not bound to any keys\n",
2053 fprintf (rl_outstream
, "%s can be found on ", name
);
2055 for (j
= 0; invokers
[j
] && j
< 5; j
++)
2057 fprintf (rl_outstream
, "\"%s\"%s", invokers
[j
],
2058 invokers
[j
+ 1] ? ", " : ".\n");
2061 if (j
== 5 && invokers
[j
])
2062 fprintf (rl_outstream
, "...\n");
2064 for (j
= 0; invokers
[j
]; j
++)
2073 /* Print all of the current functions and their bindings to
2074 rl_outstream. If an explicit argument is given, then print
2075 the output in such a way that it can be read back in. */
2077 rl_dump_functions (count
, key
)
2081 fprintf (rl_outstream
, "\r\n");
2082 rl_function_dumper (rl_explicit_arg
);
2088 _rl_macro_dumper_internal (print_readably
, map
, prefix
)
2094 char *keyname
, *out
;
2097 for (key
= 0; key
< KEYMAP_SIZE
; key
++)
2099 switch (map
[key
].type
)
2102 keyname
= _rl_get_keyname (key
);
2103 out
= _rl_untranslate_macro_value ((char *)map
[key
].function
);
2106 fprintf (rl_outstream
, "\"%s%s\": \"%s\"\n", prefix
? prefix
: "",
2110 fprintf (rl_outstream
, "%s%s outputs %s\n", prefix
? prefix
: "",
2119 prefix_len
= prefix
? strlen (prefix
) : 0;
2122 keyname
= (char *)xmalloc (3 + prefix_len
);
2124 strcpy (keyname
, prefix
);
2125 keyname
[prefix_len
] = '\\';
2126 keyname
[prefix_len
+ 1] = 'e';
2127 keyname
[prefix_len
+ 2] = '\0';
2131 keyname
= _rl_get_keyname (key
);
2134 out
= (char *)xmalloc (strlen (keyname
) + prefix_len
+ 1);
2135 strcpy (out
, prefix
);
2136 strcpy (out
+ prefix_len
, keyname
);
2142 _rl_macro_dumper_internal (print_readably
, FUNCTION_TO_KEYMAP (map
, key
), keyname
);
2150 rl_macro_dumper (print_readably
)
2153 _rl_macro_dumper_internal (print_readably
, _rl_keymap
, (char *)NULL
);
2157 rl_dump_macros (count
, key
)
2161 fprintf (rl_outstream
, "\r\n");
2162 rl_macro_dumper (rl_explicit_arg
);
2168 _rl_get_string_variable_value (name
)
2171 static char numbuf
[32];
2175 if (_rl_stricmp (name
, "bell-style") == 0)
2177 switch (_rl_bell_preference
)
2188 else if (_rl_stricmp (name
, "comment-begin") == 0)
2189 return (_rl_comment_begin
? _rl_comment_begin
: RL_COMMENT_BEGIN_DEFAULT
);
2190 else if (_rl_stricmp (name
, "completion-query-items") == 0)
2192 sprintf (numbuf
, "%d", rl_completion_query_items
);
2195 else if (_rl_stricmp (name
, "editing-mode") == 0)
2196 return (rl_get_keymap_name_from_edit_mode ());
2197 else if (_rl_stricmp (name
, "isearch-terminators") == 0)
2199 if (_rl_isearch_terminators
== 0)
2201 ret
= _rl_untranslate_macro_value (_rl_isearch_terminators
);
2204 strncpy (numbuf
, ret
, sizeof (numbuf
) - 1);
2206 numbuf
[sizeof(numbuf
) - 1] = '\0';
2212 else if (_rl_stricmp (name
, "keymap") == 0)
2214 ret
= rl_get_keymap_name (_rl_keymap
);
2216 ret
= rl_get_keymap_name_from_edit_mode ();
2217 return (ret
? ret
: "none");
2224 rl_variable_dumper (print_readably
)
2230 for (i
= 0; boolean_varlist
[i
].name
; i
++)
2233 fprintf (rl_outstream
, "set %s %s\n", boolean_varlist
[i
].name
,
2234 *boolean_varlist
[i
].value
? "on" : "off");
2236 fprintf (rl_outstream
, "%s is set to `%s'\n", boolean_varlist
[i
].name
,
2237 *boolean_varlist
[i
].value
? "on" : "off");
2240 for (i
= 0; string_varlist
[i
].name
; i
++)
2242 v
= _rl_get_string_variable_value (string_varlist
[i
].name
);
2243 if (v
== 0) /* _rl_isearch_terminators can be NULL */
2246 fprintf (rl_outstream
, "set %s %s\n", string_varlist
[i
].name
, v
);
2248 fprintf (rl_outstream
, "%s is set to `%s'\n", string_varlist
[i
].name
, v
);
2252 /* Print all of the current variables and their values to
2253 rl_outstream. If an explicit argument is given, then print
2254 the output in such a way that it can be read back in. */
2256 rl_dump_variables (count
, key
)
2260 fprintf (rl_outstream
, "\r\n");
2261 rl_variable_dumper (rl_explicit_arg
);
2266 /* Return non-zero if any members of ARRAY are a substring in STRING. */
2268 substring_member_of_array (string
, array
)
2274 if (_rl_strindex (string
, *array
))