1 /* bind.c -- key binding and startup file support for the readline library. */
3 /* Copyright (C) 1987-2009 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 char *_rl_read_file
PARAMS((char *, size_t *));
76 static void _rl_init_file_error
PARAMS((const char *));
77 static int _rl_read_init_file
PARAMS((const char *, int));
78 static int glean_key_from_name
PARAMS((char *));
79 static int find_boolean_var
PARAMS((const char *));
81 static char *_rl_get_string_variable_value
PARAMS((const char *));
82 static int substring_member_of_array
PARAMS((const char *, const char * const *));
84 static int currently_reading_init_file
;
86 /* used only in this file */
87 static int _rl_prefer_visible_bell
= 1;
89 /* **************************************************************** */
93 /* **************************************************************** */
95 /* rl_add_defun (char *name, rl_command_func_t *function, int key)
96 Add NAME to the list of named functions. Make FUNCTION be the function
97 that gets called. If KEY is not -1, then bind it. */
99 rl_add_defun (name
, function
, key
)
101 rl_command_func_t
*function
;
105 rl_bind_key (key
, function
);
106 rl_add_funmap_entry (name
, function
);
110 /* Bind KEY to FUNCTION. Returns non-zero if KEY is out of range. */
112 rl_bind_key (key
, function
)
114 rl_command_func_t
*function
;
119 if (META_CHAR (key
) && _rl_convert_meta_chars_to_ascii
)
121 if (_rl_keymap
[ESC
].type
== ISKMAP
)
125 escmap
= FUNCTION_TO_KEYMAP (_rl_keymap
, ESC
);
127 escmap
[key
].type
= ISFUNC
;
128 escmap
[key
].function
= function
;
134 _rl_keymap
[key
].type
= ISFUNC
;
135 _rl_keymap
[key
].function
= function
;
136 rl_binding_keymap
= _rl_keymap
;
140 /* Bind KEY to FUNCTION in MAP. Returns non-zero in case of invalid
143 rl_bind_key_in_map (key
, function
, map
)
145 rl_command_func_t
*function
;
153 result
= rl_bind_key (key
, function
);
158 /* Bind key sequence KEYSEQ to DEFAULT_FUNC if KEYSEQ is unbound. Right
159 now, this is always used to attempt to bind the arrow keys, hence the
160 check for rl_vi_movement_mode. */
162 rl_bind_key_if_unbound_in_map (key
, default_func
, kmap
)
164 rl_command_func_t
*default_func
;
169 keyseq
[0] = (unsigned char)key
;
171 return (rl_bind_keyseq_if_unbound_in_map (keyseq
, default_func
, kmap
));
175 rl_bind_key_if_unbound (key
, default_func
)
177 rl_command_func_t
*default_func
;
181 keyseq
[0] = (unsigned char)key
;
183 return (rl_bind_keyseq_if_unbound_in_map (keyseq
, default_func
, _rl_keymap
));
186 /* Make KEY do nothing in the currently selected keymap.
187 Returns non-zero in case of error. */
192 return (rl_bind_key (key
, (rl_command_func_t
*)NULL
));
195 /* Make KEY do nothing in MAP.
196 Returns non-zero in case of error. */
198 rl_unbind_key_in_map (key
, map
)
202 return (rl_bind_key_in_map (key
, (rl_command_func_t
*)NULL
, map
));
205 /* Unbind all keys bound to FUNCTION in MAP. */
207 rl_unbind_function_in_map (func
, map
)
208 rl_command_func_t
*func
;
211 register int i
, rval
;
213 for (i
= rval
= 0; i
< KEYMAP_SIZE
; i
++)
215 if (map
[i
].type
== ISFUNC
&& map
[i
].function
== func
)
217 map
[i
].function
= (rl_command_func_t
*)NULL
;
225 rl_unbind_command_in_map (command
, map
)
229 rl_command_func_t
*func
;
231 func
= rl_named_function (command
);
234 return (rl_unbind_function_in_map (func
, map
));
237 /* Bind the key sequence represented by the string KEYSEQ to
238 FUNCTION, starting in the current keymap. This makes new
239 keymaps as necessary. */
241 rl_bind_keyseq (keyseq
, function
)
243 rl_command_func_t
*function
;
245 return (rl_generic_bind (ISFUNC
, keyseq
, (char *)function
, _rl_keymap
));
248 /* Bind the key sequence represented by the string KEYSEQ to
249 FUNCTION. This makes new keymaps as necessary. The initial
250 place to do bindings is in MAP. */
252 rl_bind_keyseq_in_map (keyseq
, function
, map
)
254 rl_command_func_t
*function
;
257 return (rl_generic_bind (ISFUNC
, keyseq
, (char *)function
, map
));
260 /* Backwards compatibility; equivalent to rl_bind_keyseq_in_map() */
262 rl_set_key (keyseq
, function
, map
)
264 rl_command_func_t
*function
;
267 return (rl_generic_bind (ISFUNC
, keyseq
, (char *)function
, map
));
270 /* Bind key sequence KEYSEQ to DEFAULT_FUNC if KEYSEQ is unbound. Right
271 now, this is always used to attempt to bind the arrow keys, hence the
272 check for rl_vi_movement_mode. */
274 rl_bind_keyseq_if_unbound_in_map (keyseq
, default_func
, kmap
)
276 rl_command_func_t
*default_func
;
279 rl_command_func_t
*func
;
283 func
= rl_function_of_keyseq (keyseq
, kmap
, (int *)NULL
);
284 #if defined (VI_MODE)
285 if (!func
|| func
== rl_do_lowercase_version
|| func
== rl_vi_movement_mode
)
287 if (!func
|| func
== rl_do_lowercase_version
)
289 return (rl_bind_keyseq_in_map (keyseq
, default_func
, kmap
));
297 rl_bind_keyseq_if_unbound (keyseq
, default_func
)
299 rl_command_func_t
*default_func
;
301 return (rl_bind_keyseq_if_unbound_in_map (keyseq
, default_func
, _rl_keymap
));
304 /* Bind the key sequence represented by the string KEYSEQ to
305 the string of characters MACRO. This makes new keymaps as
306 necessary. The initial place to do bindings is in MAP. */
308 rl_macro_bind (keyseq
, macro
, map
)
309 const char *keyseq
, *macro
;
315 macro_keys
= (char *)xmalloc ((2 * strlen (macro
)) + 1);
317 if (rl_translate_keyseq (macro
, macro_keys
, ¯o_keys_len
))
322 rl_generic_bind (ISMACR
, keyseq
, macro_keys
, map
);
326 /* Bind the key sequence represented by the string KEYSEQ to
327 the arbitrary pointer DATA. TYPE says what kind of data is
328 pointed to by DATA, right now this can be a function (ISFUNC),
329 a macro (ISMACR), or a keymap (ISKMAP). This makes new keymaps
330 as necessary. The initial place to do bindings is in MAP. */
332 rl_generic_bind (type
, keyseq
, data
, map
)
345 /* If no keys to bind to, exit right away. */
346 if (keyseq
== 0 || *keyseq
== 0)
353 keys
= (char *)xmalloc (1 + (2 * strlen (keyseq
)));
355 /* Translate the ASCII representation of KEYSEQ into an array of
356 characters. Stuff the characters into KEYS, and the length of
357 KEYS into KEYS_LEN. */
358 if (rl_translate_keyseq (keyseq
, keys
, &keys_len
))
364 /* Bind keys, making new keymaps as necessary. */
365 for (i
= 0; i
< keys_len
; i
++)
367 unsigned char uc
= keys
[i
];
371 if (ic
< 0 || ic
>= KEYMAP_SIZE
)
377 if (META_CHAR (ic
) && _rl_convert_meta_chars_to_ascii
)
380 if (map
[ESC
].type
== ISKMAP
)
381 map
= FUNCTION_TO_KEYMAP (map
, ESC
);
384 if ((i
+ 1) < keys_len
)
386 if (map
[ic
].type
!= ISKMAP
)
388 /* We allow subsequences of keys. If a keymap is being
389 created that will `shadow' an existing function or macro
390 key binding, we save that keybinding into the ANYOTHERKEY
391 index in the new map. The dispatch code will look there
392 to find the function to execute if the subsequence is not
393 matched. ANYOTHERKEY was chosen to be greater than
397 map
[ic
].type
= ISKMAP
;
398 map
[ic
].function
= KEYMAP_TO_FUNCTION (rl_make_bare_keymap());
400 map
= FUNCTION_TO_KEYMAP (map
, ic
);
401 /* The dispatch code will return this function if no matching
402 key sequence is found in the keymap. This (with a little
403 help from the dispatch code in readline.c) allows `a' to be
404 mapped to something, `abc' to be mapped to something else,
405 and the function bound to `a' to be executed when the user
406 types `abx', leaving `bx' in the input queue. */
407 if (k
.function
&& ((k
.type
== ISFUNC
&& k
.function
!= rl_do_lowercase_version
) || k
.type
== ISMACR
))
409 map
[ANYOTHERKEY
] = k
;
415 if (map
[ic
].type
== ISMACR
)
416 xfree ((char *)map
[ic
].function
);
417 else if (map
[ic
].type
== ISKMAP
)
419 map
= FUNCTION_TO_KEYMAP (map
, ic
);
423 map
[ic
].function
= KEYMAP_TO_FUNCTION (data
);
427 rl_binding_keymap
= map
;
433 /* Translate the ASCII representation of SEQ, stuffing the values into ARRAY,
434 an array of characters. LEN gets the final length of ARRAY. Return
435 non-zero if there was an error parsing SEQ. */
437 rl_translate_keyseq (seq
, array
, len
)
442 register int i
, c
, l
, temp
;
444 for (i
= l
= 0; c
= seq
[i
]; i
++)
453 /* Handle \C- and \M- prefixes. */
454 if ((c
== 'C' || c
== 'M') && seq
[i
+ 1] == '-')
456 /* Handle special case of backwards define. */
457 if (strncmp (&seq
[i
], "C-\\M-", 5) == 0)
459 array
[l
++] = ESC
; /* ESC is meta-prefix */
461 array
[l
++] = CTRL (_rl_to_upper (seq
[i
]));
467 i
++; /* seq[i] == '-' */
468 /* XXX - obey convert-meta setting */
469 if (_rl_convert_meta_chars_to_ascii
&& _rl_keymap
[ESC
].type
== ISKMAP
)
470 array
[l
++] = ESC
; /* ESC is meta-prefix */
471 else if (seq
[i
+1] == '\\' && seq
[i
+2] == 'C' && seq
[i
+3] == '-')
474 temp
= (seq
[i
] == '?') ? RUBOUT
: CTRL (_rl_to_upper (seq
[i
]));
475 array
[l
++] = META (temp
);
479 /* This doesn't yet handle things like \M-\a, which may
480 or may not have any reasonable meaning. You're
481 probably better off using straight octal or hex. */
483 array
[l
++] = META (seq
[i
]);
489 /* Special hack for C-?... */
490 array
[l
++] = (seq
[i
] == '?') ? RUBOUT
: CTRL (_rl_to_upper (seq
[i
]));
495 /* Translate other backslash-escaped characters. These are the
496 same escape sequences that bash's `echo' and `printf' builtins
497 handle, with the addition of \d -> RUBOUT. A backslash
498 preceding a character that is not special is stripped. */
508 array
[l
++] = RUBOUT
; /* readline-specific */
517 array
[l
++] = NEWLINE
;
531 case '0': case '1': case '2': case '3':
532 case '4': case '5': case '6': case '7':
534 for (temp
= 2, c
-= '0'; ISOCTAL (seq
[i
]) && temp
--; i
++)
535 c
= (c
* 8) + OCTVALUE (seq
[i
]);
536 i
--; /* auto-increment in for loop */
537 array
[l
++] = c
& largest_char
;
541 for (temp
= 2, c
= 0; ISXDIGIT ((unsigned char)seq
[i
]) && temp
--; i
++)
542 c
= (c
* 16) + HEXVALUE (seq
[i
]);
545 i
--; /* auto-increment in for loop */
546 array
[l
++] = c
& largest_char
;
548 default: /* backslashes before non-special chars just add the char */
550 break; /* the backslash is stripped */
564 rl_untranslate_keyseq (seq
)
567 static char kseq
[16];
584 else if (CTRL_CHAR (c
))
589 c
= _rl_to_lower (UNCTRL (c
));
591 else if (c
== RUBOUT
)
604 else if (c
== '\\' || c
== '"')
609 kseq
[i
++] = (unsigned char) c
;
615 _rl_untranslate_macro_value (seq
)
621 r
= ret
= (char *)xmalloc (7 * strlen (seq
) + 1);
622 for (s
= seq
; *s
; s
++)
637 else if (CTRL_CHAR (c
))
642 c
= _rl_to_lower (UNCTRL (c
));
644 else if (c
== RUBOUT
)
657 else if (c
== '\\' || c
== '"')
660 *r
++ = (unsigned char)c
;
666 /* Return a pointer to the function that STRING represents.
667 If STRING doesn't have a matching function, then a NULL pointer
670 rl_named_function (string
)
675 rl_initialize_funmap ();
677 for (i
= 0; funmap
[i
]; i
++)
678 if (_rl_stricmp (funmap
[i
]->name
, string
) == 0)
679 return (funmap
[i
]->function
);
680 return ((rl_command_func_t
*)NULL
);
683 /* Return the function (or macro) definition which would be invoked via
684 KEYSEQ if executed in MAP. If MAP is NULL, then the current keymap is
685 used. TYPE, if non-NULL, is a pointer to an int which will receive the
686 type of the object pointed to. One of ISFUNC (function), ISKMAP (keymap),
687 or ISMACR (macro). */
689 rl_function_of_keyseq (keyseq
, map
, type
)
699 for (i
= 0; keyseq
&& keyseq
[i
]; i
++)
701 unsigned char ic
= keyseq
[i
];
703 if (META_CHAR (ic
) && _rl_convert_meta_chars_to_ascii
)
705 if (map
[ESC
].type
== ISKMAP
)
707 map
= FUNCTION_TO_KEYMAP (map
, ESC
);
710 /* XXX - should we just return NULL here, since this obviously
715 *type
= map
[ESC
].type
;
717 return (map
[ESC
].function
);
721 if (map
[ic
].type
== ISKMAP
)
723 /* If this is the last key in the key sequence, return the
725 if (keyseq
[i
+ 1] == '\0')
730 return (map
[ic
].function
);
733 map
= FUNCTION_TO_KEYMAP (map
, ic
);
735 /* If we're not at the end of the key sequence, and the current key
736 is bound to something other than a keymap, then the entire key
737 sequence is not bound. */
738 else if (map
[ic
].type
!= ISKMAP
&& keyseq
[i
+1])
739 return ((rl_command_func_t
*)NULL
);
740 else /* map[ic].type != ISKMAP && keyseq[i+1] == 0 */
743 *type
= map
[ic
].type
;
745 return (map
[ic
].function
);
748 return ((rl_command_func_t
*) NULL
);
751 /* The last key bindings file read. */
752 static char *last_readline_init_file
= (char *)NULL
;
754 /* The file we're currently reading key bindings from. */
755 static const char *current_readline_init_file
;
756 static int current_readline_init_include_level
;
757 static int current_readline_init_lineno
;
759 /* Read FILENAME into a locally-allocated buffer and return the buffer.
760 The size of the buffer is returned in *SIZEP. Returns NULL if any
761 errors were encountered. */
763 _rl_read_file (filename
, sizep
)
772 if ((stat (filename
, &finfo
) < 0) || (file
= open (filename
, O_RDONLY
, 0666)) < 0)
773 return ((char *)NULL
);
775 file_size
= (size_t)finfo
.st_size
;
777 /* check for overflow on very large files */
778 if (file_size
!= finfo
.st_size
|| file_size
+ 1 < file_size
)
785 return ((char *)NULL
);
788 /* Read the file into BUFFER. */
789 buffer
= (char *)xmalloc (file_size
+ 1);
790 i
= read (file
, buffer
, file_size
);
796 return ((char *)NULL
);
808 /* Re-read the current keybindings file. */
810 rl_re_read_init_file (count
, ignore
)
814 r
= rl_read_init_file ((const char *)NULL
);
815 rl_set_keymap_from_edit_mode ();
819 /* Do key bindings from a file. If FILENAME is NULL it defaults
820 to the first non-null filename from this list:
821 1. the filename used for the previous call
822 2. the value of the shell variable `INPUTRC'
825 If the file existed and could be opened and read, 0 is returned,
826 otherwise errno is returned. */
828 rl_read_init_file (filename
)
829 const char *filename
;
831 /* Default the filename. */
833 filename
= last_readline_init_file
;
835 filename
= sh_get_env_value ("INPUTRC");
836 if (filename
== 0 || *filename
== 0)
838 filename
= DEFAULT_INPUTRC
;
839 /* Try to read DEFAULT_INPUTRC; fall back to SYS_INPUTRC on failure */
840 if (_rl_read_init_file (filename
, 0) == 0)
842 filename
= SYS_INPUTRC
;
845 #if defined (__MSDOS__)
846 if (_rl_read_init_file (filename
, 0) == 0)
848 filename
= "~/_inputrc";
850 return (_rl_read_init_file (filename
, 0));
854 _rl_read_init_file (filename
, include_level
)
855 const char *filename
;
859 char *buffer
, *openname
, *line
, *end
;
862 current_readline_init_file
= filename
;
863 current_readline_init_include_level
= include_level
;
865 openname
= tilde_expand (filename
);
866 buffer
= _rl_read_file (openname
, &file_size
);
873 if (include_level
== 0 && filename
!= last_readline_init_file
)
875 FREE (last_readline_init_file
);
876 last_readline_init_file
= savestring (filename
);
879 currently_reading_init_file
= 1;
881 /* Loop over the lines in the file. Lines that start with `#' are
882 comments; all other lines are commands for readline initialization. */
883 current_readline_init_lineno
= 1;
885 end
= buffer
+ file_size
;
888 /* Find the end of this line. */
889 for (i
= 0; line
+ i
!= end
&& line
[i
] != '\n'; i
++);
891 #if defined (__CYGWIN__)
892 /* ``Be liberal in what you accept.'' */
893 if (line
[i
] == '\n' && line
[i
-1] == '\r')
897 /* Mark end of line. */
900 /* Skip leading whitespace. */
901 while (*line
&& whitespace (*line
))
907 /* If the line is not a comment, then parse it. */
908 if (*line
&& *line
!= '#')
909 rl_parse_and_bind (line
);
911 /* Move to the next line. */
913 current_readline_init_lineno
++;
917 currently_reading_init_file
= 0;
922 _rl_init_file_error (msg
)
925 if (currently_reading_init_file
)
926 _rl_errmsg ("%s: line %d: %s\n", current_readline_init_file
,
927 current_readline_init_lineno
, msg
);
929 _rl_errmsg ("%s", msg
);
932 /* **************************************************************** */
934 /* Parser Directives */
936 /* **************************************************************** */
938 typedef int _rl_parser_func_t
PARAMS((char *));
940 /* Things that mean `Control'. */
941 const char * const _rl_possible_control_prefixes
[] = {
942 "Control-", "C-", "CTRL-", (const char *)NULL
945 const char * const _rl_possible_meta_prefixes
[] = {
946 "Meta", "M-", (const char *)NULL
951 /* Calling programs set this to have their argv[0]. */
952 const char *rl_readline_name
= "other";
954 /* Stack of previous values of parsing_conditionalized_out. */
955 static unsigned char *if_stack
= (unsigned char *)NULL
;
956 static int if_stack_depth
;
957 static int if_stack_size
;
959 /* Push _rl_parsing_conditionalized_out, and set parser state based
967 /* Push parser state. */
968 if (if_stack_depth
+ 1 >= if_stack_size
)
971 if_stack
= (unsigned char *)xmalloc (if_stack_size
= 20);
973 if_stack
= (unsigned char *)xrealloc (if_stack
, if_stack_size
+= 20);
975 if_stack
[if_stack_depth
++] = _rl_parsing_conditionalized_out
;
977 /* If parsing is turned off, then nothing can turn it back on except
978 for finding the matching endif. In that case, return right now. */
979 if (_rl_parsing_conditionalized_out
)
982 /* Isolate first argument. */
983 for (i
= 0; args
[i
] && !whitespace (args
[i
]); i
++);
988 /* Handle "$if term=foo" and "$if mode=emacs" constructs. If this
989 isn't term=foo, or mode=emacs, then check to see if the first
990 word in ARGS is the same as the value stored in rl_readline_name. */
991 if (rl_terminal_name
&& _rl_strnicmp (args
, "term=", 5) == 0)
995 /* Terminals like "aaa-60" are equivalent to "aaa". */
996 tname
= savestring (rl_terminal_name
);
997 tem
= strchr (tname
, '-');
1001 /* Test the `long' and `short' forms of the terminal name so that
1002 if someone has a `sun-cmd' and does not want to have bindings
1003 that will be executed if the terminal is a `sun', they can put
1004 `$if term=sun-cmd' into their .inputrc. */
1005 _rl_parsing_conditionalized_out
= _rl_stricmp (args
+ 5, tname
) &&
1006 _rl_stricmp (args
+ 5, rl_terminal_name
);
1009 #if defined (VI_MODE)
1010 else if (_rl_strnicmp (args
, "mode=", 5) == 0)
1014 if (_rl_stricmp (args
+ 5, "emacs") == 0)
1016 else if (_rl_stricmp (args
+ 5, "vi") == 0)
1021 _rl_parsing_conditionalized_out
= mode
!= rl_editing_mode
;
1023 #endif /* VI_MODE */
1024 /* Check to see if the first word in ARGS is the same as the
1025 value stored in rl_readline_name. */
1026 else if (_rl_stricmp (args
, rl_readline_name
) == 0)
1027 _rl_parsing_conditionalized_out
= 0;
1029 _rl_parsing_conditionalized_out
= 1;
1033 /* Invert the current parser state if there is anything on the stack. */
1040 if (if_stack_depth
== 0)
1042 _rl_init_file_error ("$else found without matching $if");
1047 /* Check the previous (n - 1) levels of the stack to make sure that
1048 we haven't previously turned off parsing. */
1049 for (i
= 0; i
< if_stack_depth
- 1; i
++)
1051 /* Check the previous (n) levels of the stack to make sure that
1052 we haven't previously turned off parsing. */
1053 for (i
= 0; i
< if_stack_depth
; i
++)
1055 if (if_stack
[i
] == 1)
1058 /* Invert the state of parsing if at top level. */
1059 _rl_parsing_conditionalized_out
= !_rl_parsing_conditionalized_out
;
1063 /* Terminate a conditional, popping the value of
1064 _rl_parsing_conditionalized_out from the stack. */
1070 _rl_parsing_conditionalized_out
= if_stack
[--if_stack_depth
];
1072 _rl_init_file_error ("$endif without matching $if");
1077 parser_include (args
)
1080 const char *old_init_file
;
1082 int old_line_number
, old_include_level
, r
;
1084 if (_rl_parsing_conditionalized_out
)
1087 old_init_file
= current_readline_init_file
;
1088 old_line_number
= current_readline_init_lineno
;
1089 old_include_level
= current_readline_init_include_level
;
1091 e
= strchr (args
, '\n');
1094 r
= _rl_read_init_file ((const char *)args
, old_include_level
+ 1);
1096 current_readline_init_file
= old_init_file
;
1097 current_readline_init_lineno
= old_line_number
;
1098 current_readline_init_include_level
= old_include_level
;
1103 /* Associate textual names with actual functions. */
1104 static const struct {
1105 const char * const name
;
1106 _rl_parser_func_t
*function
;
1107 } parser_directives
[] = {
1108 { "if", parser_if
},
1109 { "endif", parser_endif
},
1110 { "else", parser_else
},
1111 { "include", parser_include
},
1112 { (char *)0x0, (_rl_parser_func_t
*)0x0 }
1115 /* Handle a parser directive. STATEMENT is the line of the directive
1116 without any leading `$'. */
1118 handle_parser_directive (statement
)
1122 char *directive
, *args
;
1124 /* Isolate the actual directive. */
1126 /* Skip whitespace. */
1127 for (i
= 0; whitespace (statement
[i
]); i
++);
1129 directive
= &statement
[i
];
1131 for (; statement
[i
] && !whitespace (statement
[i
]); i
++);
1134 statement
[i
++] = '\0';
1136 for (; statement
[i
] && whitespace (statement
[i
]); i
++);
1138 args
= &statement
[i
];
1140 /* Lookup the command, and act on it. */
1141 for (i
= 0; parser_directives
[i
].name
; i
++)
1142 if (_rl_stricmp (directive
, parser_directives
[i
].name
) == 0)
1144 (*parser_directives
[i
].function
) (args
);
1148 /* display an error message about the unknown parser directive */
1149 _rl_init_file_error ("unknown parser directive");
1153 /* Read the binding command from STRING and perform it.
1154 A key binding command looks like: Keyname: function-name\0,
1155 a variable binding command looks like: set variable value.
1156 A new-style keybinding looks like "\C-x\C-x": exchange-point-and-mark. */
1158 rl_parse_and_bind (string
)
1161 char *funname
, *kname
;
1163 int key
, equivalency
;
1165 while (string
&& whitespace (*string
))
1168 if (!string
|| !*string
|| *string
== '#')
1171 /* If this is a parser directive, act on it. */
1174 handle_parser_directive (&string
[1]);
1178 /* If we aren't supposed to be parsing right now, then we're done. */
1179 if (_rl_parsing_conditionalized_out
)
1183 /* If this keyname is a complex key expression surrounded by quotes,
1184 advance to after the matching close quote. This code allows the
1185 backslash to quote characters in the key expression. */
1190 for (i
= 1; c
= string
[i
]; i
++)
1207 /* If we didn't find a closing quote, abort the line. */
1208 if (string
[i
] == '\0')
1210 _rl_init_file_error ("no closing `\"' in key binding");
1215 /* Advance to the colon (:) or whitespace which separates the two objects. */
1216 for (; (c
= string
[i
]) && c
!= ':' && c
!= ' ' && c
!= '\t'; i
++ );
1218 equivalency
= (c
== ':' && string
[i
+ 1] == '=');
1220 /* Mark the end of the command (or keyname). */
1224 /* If doing assignment, skip the '=' sign as well. */
1228 /* If this is a command to set a variable, then do that. */
1229 if (_rl_stricmp (string
, "set") == 0)
1231 char *var
, *value
, *e
;
1234 /* Make VAR point to start of variable name. */
1235 while (*var
&& whitespace (*var
)) var
++;
1237 /* Make VALUE point to start of value string. */
1239 while (*value
&& !whitespace (*value
)) value
++;
1242 while (*value
&& whitespace (*value
)) value
++;
1244 /* Strip trailing whitespace from values to boolean variables. Temp
1245 fix until I get a real quoted-string parser here. */
1246 i
= find_boolean_var (var
);
1249 /* remove trailing whitespace */
1250 e
= value
+ strlen (value
) - 1;
1251 while (e
>= value
&& whitespace (*e
))
1253 e
++; /* skip back to whitespace or EOS */
1254 if (*e
&& e
>= value
)
1258 rl_variable_bind (var
, value
);
1262 /* Skip any whitespace between keyname and funname. */
1263 for (; string
[i
] && whitespace (string
[i
]); i
++);
1264 funname
= &string
[i
];
1266 /* Now isolate funname.
1267 For straight function names just look for whitespace, since
1268 that will signify the end of the string. But this could be a
1269 macro definition. In that case, the string is quoted, so skip
1270 to the matching delimiter. We allow the backslash to quote the
1271 delimiter characters in the macro body. */
1272 /* This code exists to allow whitespace in macro expansions, which
1273 would otherwise be gobbled up by the next `for' loop.*/
1274 /* XXX - it may be desirable to allow backslash quoting only if " is
1275 the quoted string delimiter, like the shell. */
1276 if (*funname
== '\'' || *funname
== '"')
1278 int delimiter
, passc
;
1280 delimiter
= string
[i
++];
1281 for (passc
= 0; c
= string
[i
]; i
++)
1302 /* Advance to the end of the string. */
1303 for (; string
[i
] && !whitespace (string
[i
]); i
++);
1305 /* No extra whitespace at the end of the string. */
1308 /* Handle equivalency bindings here. Make the left-hand side be exactly
1309 whatever the right-hand evaluates to, including keymaps. */
1315 /* If this is a new-style key-binding, then do the binding with
1316 rl_bind_keyseq (). Otherwise, let the older code deal with it. */
1320 register int j
, k
, passc
;
1322 seq
= (char *)xmalloc (1 + strlen (string
));
1323 for (j
= 1, k
= passc
= 0; string
[j
]; j
++)
1325 /* Allow backslash to quote characters, but leave them in place.
1326 This allows a string to end with a backslash quoting another
1327 backslash, or with a backslash quoting a double quote. The
1328 backslashes are left in place for rl_translate_keyseq (). */
1329 if (passc
|| (string
[j
] == '\\'))
1331 seq
[k
++] = string
[j
];
1336 if (string
[j
] == '"')
1339 seq
[k
++] = string
[j
];
1343 /* Binding macro? */
1344 if (*funname
== '\'' || *funname
== '"')
1346 j
= strlen (funname
);
1348 /* Remove the delimiting quotes from each end of FUNNAME. */
1349 if (j
&& funname
[j
- 1] == *funname
)
1350 funname
[j
- 1] = '\0';
1352 rl_macro_bind (seq
, &funname
[1], _rl_keymap
);
1355 rl_bind_keyseq (seq
, rl_named_function (funname
));
1361 /* Get the actual character we want to deal with. */
1362 kname
= strrchr (string
, '-');
1368 key
= glean_key_from_name (kname
);
1370 /* Add in control and meta bits. */
1371 if (substring_member_of_array (string
, _rl_possible_control_prefixes
))
1372 key
= CTRL (_rl_to_upper (key
));
1374 if (substring_member_of_array (string
, _rl_possible_meta_prefixes
))
1377 /* Temporary. Handle old-style keyname with macro-binding. */
1378 if (*funname
== '\'' || *funname
== '"')
1381 int fl
= strlen (funname
);
1383 useq
[0] = key
; useq
[1] = '\0';
1384 if (fl
&& funname
[fl
- 1] == *funname
)
1385 funname
[fl
- 1] = '\0';
1387 rl_macro_bind (useq
, &funname
[1], _rl_keymap
);
1389 #if defined (PREFIX_META_HACK)
1390 /* Ugly, but working hack to keep prefix-meta around. */
1391 else if (_rl_stricmp (funname
, "prefix-meta") == 0)
1397 rl_generic_bind (ISKMAP
, seq
, (char *)emacs_meta_keymap
, _rl_keymap
);
1399 #endif /* PREFIX_META_HACK */
1401 rl_bind_key (key
, rl_named_function (funname
));
1405 /* Simple structure for boolean readline variables (i.e., those that can
1406 have one of two values; either "On" or 1 for truth, or "Off" or 0 for
1409 #define V_SPECIAL 0x1
1411 static const struct {
1412 const char * const name
;
1415 } boolean_varlist
[] = {
1416 { "bind-tty-special-chars", &_rl_bind_stty_chars
, 0 },
1417 { "blink-matching-paren", &rl_blink_matching_paren
, V_SPECIAL
},
1418 { "byte-oriented", &rl_byte_oriented
, 0 },
1419 { "completion-ignore-case", &_rl_completion_case_fold
, 0 },
1420 { "convert-meta", &_rl_convert_meta_chars_to_ascii
, 0 },
1421 { "disable-completion", &rl_inhibit_completion
, 0 },
1422 { "enable-keypad", &_rl_enable_keypad
, 0 },
1423 { "expand-tilde", &rl_complete_with_tilde_expansion
, 0 },
1424 { "history-preserve-point", &_rl_history_preserve_point
, 0 },
1425 { "horizontal-scroll-mode", &_rl_horizontal_scroll_mode
, 0 },
1426 { "input-meta", &_rl_meta_flag
, 0 },
1427 { "mark-directories", &_rl_complete_mark_directories
, 0 },
1428 { "mark-modified-lines", &_rl_mark_modified_lines
, 0 },
1429 { "mark-symlinked-directories", &_rl_complete_mark_symlink_dirs
, 0 },
1430 { "match-hidden-files", &_rl_match_hidden_files
, 0 },
1431 { "meta-flag", &_rl_meta_flag
, 0 },
1432 { "output-meta", &_rl_output_meta_chars
, 0 },
1433 { "page-completions", &_rl_page_completions
, 0 },
1434 { "prefer-visible-bell", &_rl_prefer_visible_bell
, V_SPECIAL
},
1435 { "print-completions-horizontally", &_rl_print_completions_horizontally
, 0 },
1436 { "revert-all-at-newline", &_rl_revert_all_at_newline
, 0 },
1437 { "show-all-if-ambiguous", &_rl_complete_show_all
, 0 },
1438 { "show-all-if-unmodified", &_rl_complete_show_unmodified
, 0 },
1439 #if defined (VISIBLE_STATS)
1440 { "visible-stats", &rl_visible_stats
, 0 },
1441 #endif /* VISIBLE_STATS */
1442 { (char *)NULL
, (int *)NULL
}
1446 find_boolean_var (name
)
1451 for (i
= 0; boolean_varlist
[i
].name
; i
++)
1452 if (_rl_stricmp (name
, boolean_varlist
[i
].name
) == 0)
1457 /* Hooks for handling special boolean variables, where a
1458 function needs to be called or another variable needs
1459 to be changed when they're changed. */
1461 hack_special_boolean_var (i
)
1466 name
= boolean_varlist
[i
].name
;
1468 if (_rl_stricmp (name
, "blink-matching-paren") == 0)
1469 _rl_enable_paren_matching (rl_blink_matching_paren
);
1470 else if (_rl_stricmp (name
, "prefer-visible-bell") == 0)
1472 if (_rl_prefer_visible_bell
)
1473 _rl_bell_preference
= VISIBLE_BELL
;
1475 _rl_bell_preference
= AUDIBLE_BELL
;
1479 typedef int _rl_sv_func_t
PARAMS((const char *));
1481 /* These *must* correspond to the array indices for the appropriate
1482 string variable. (Though they're not used right now.) */
1483 #define V_BELLSTYLE 0
1484 #define V_COMBEGIN 1
1485 #define V_EDITMODE 2
1486 #define V_ISRCHTERM 3
1492 /* Forward declarations */
1493 static int sv_bell_style
PARAMS((const char *));
1494 static int sv_combegin
PARAMS((const char *));
1495 static int sv_dispprefix
PARAMS((const char *));
1496 static int sv_compquery
PARAMS((const char *));
1497 static int sv_editmode
PARAMS((const char *));
1498 static int sv_histsize
PARAMS((const char *));
1499 static int sv_isrchterm
PARAMS((const char *));
1500 static int sv_keymap
PARAMS((const char *));
1502 static const struct {
1503 const char * const name
;
1505 _rl_sv_func_t
*set_func
;
1506 } string_varlist
[] = {
1507 { "bell-style", V_STRING
, sv_bell_style
},
1508 { "comment-begin", V_STRING
, sv_combegin
},
1509 { "completion-prefix-display-length", V_INT
, sv_dispprefix
},
1510 { "completion-query-items", V_INT
, sv_compquery
},
1511 { "editing-mode", V_STRING
, sv_editmode
},
1512 { "history-size", V_INT
, sv_histsize
},
1513 { "isearch-terminators", V_STRING
, sv_isrchterm
},
1514 { "keymap", V_STRING
, sv_keymap
},
1519 find_string_var (name
)
1524 for (i
= 0; string_varlist
[i
].name
; i
++)
1525 if (_rl_stricmp (name
, string_varlist
[i
].name
) == 0)
1530 /* A boolean value that can appear in a `set variable' command is true if
1531 the value is null or empty, `on' (case-insenstive), or "1". Any other
1532 values result in 0 (false). */
1537 return (value
== 0 || *value
== '\0' ||
1538 (_rl_stricmp (value
, "on") == 0) ||
1539 (value
[0] == '1' && value
[1] == '\0'));
1543 rl_variable_value (name
)
1548 /* Check for simple variables first. */
1549 i
= find_boolean_var (name
);
1551 return (*boolean_varlist
[i
].value
? "on" : "off");
1553 i
= find_string_var (name
);
1555 return (_rl_get_string_variable_value (string_varlist
[i
].name
));
1557 /* Unknown variable names return NULL. */
1562 rl_variable_bind (name
, value
)
1563 const char *name
, *value
;
1568 /* Check for simple variables first. */
1569 i
= find_boolean_var (name
);
1572 *boolean_varlist
[i
].value
= bool_to_int (value
);
1573 if (boolean_varlist
[i
].flags
& V_SPECIAL
)
1574 hack_special_boolean_var (i
);
1578 i
= find_string_var (name
);
1580 /* For the time being, unknown variable names or string names without a
1581 handler function are simply ignored. */
1582 if (i
< 0 || string_varlist
[i
].set_func
== 0)
1585 v
= (*string_varlist
[i
].set_func
) (value
);
1593 if (_rl_strnicmp (value
, "vi", 2) == 0)
1595 #if defined (VI_MODE)
1596 _rl_keymap
= vi_insertion_keymap
;
1597 rl_editing_mode
= vi_mode
;
1598 #endif /* VI_MODE */
1601 else if (_rl_strnicmp (value
, "emacs", 5) == 0)
1603 _rl_keymap
= emacs_standard_keymap
;
1604 rl_editing_mode
= emacs_mode
;
1614 if (value
&& *value
)
1616 FREE (_rl_comment_begin
);
1617 _rl_comment_begin
= savestring (value
);
1624 sv_dispprefix (value
)
1629 if (value
&& *value
)
1631 nval
= atoi (value
);
1635 _rl_completion_prefix_display_length
= nval
;
1640 sv_compquery (value
)
1645 if (value
&& *value
)
1647 nval
= atoi (value
);
1651 rl_completion_query_items
= nval
;
1661 if (value
&& *value
)
1663 nval
= atoi (value
);
1667 stifle_history (nval
);
1677 kmap
= rl_get_keymap_by_name (value
);
1680 rl_set_keymap (kmap
);
1687 sv_bell_style (value
)
1690 if (value
== 0 || *value
== '\0')
1691 _rl_bell_preference
= AUDIBLE_BELL
;
1692 else if (_rl_stricmp (value
, "none") == 0 || _rl_stricmp (value
, "off") == 0)
1693 _rl_bell_preference
= NO_BELL
;
1694 else if (_rl_stricmp (value
, "audible") == 0 || _rl_stricmp (value
, "on") == 0)
1695 _rl_bell_preference
= AUDIBLE_BELL
;
1696 else if (_rl_stricmp (value
, "visible") == 0)
1697 _rl_bell_preference
= VISIBLE_BELL
;
1704 sv_isrchterm (value
)
1707 int beg
, end
, delim
;
1713 /* Isolate the value and translate it into a character string. */
1714 v
= savestring (value
);
1715 FREE (_rl_isearch_terminators
);
1716 if (v
[0] == '"' || v
[0] == '\'')
1719 for (beg
= end
= 1; v
[end
] && v
[end
] != delim
; end
++)
1724 for (beg
= end
= 0; whitespace (v
[end
]) == 0; end
++)
1730 /* The value starts at v + beg. Translate it into a character string. */
1731 _rl_isearch_terminators
= (char *)xmalloc (2 * strlen (v
) + 1);
1732 rl_translate_keyseq (v
+ beg
, _rl_isearch_terminators
, &end
);
1733 _rl_isearch_terminators
[end
] = '\0';
1739 /* Return the character which matches NAME.
1740 For example, `Space' returns ' '. */
1743 const char * const name
;
1747 static const assoc_list name_key_alist
[] = {
1750 { "Escape", '\033' },
1752 { "Newline", '\n' },
1763 glean_key_from_name (name
)
1768 for (i
= 0; name_key_alist
[i
].name
; i
++)
1769 if (_rl_stricmp (name
, name_key_alist
[i
].name
) == 0)
1770 return (name_key_alist
[i
].value
);
1772 return (*(unsigned char *)name
); /* XXX was return (*name) */
1775 /* Auxiliary functions to manage keymaps. */
1776 static const struct {
1777 const char * const name
;
1779 } keymap_names
[] = {
1780 { "emacs", emacs_standard_keymap
},
1781 { "emacs-standard", emacs_standard_keymap
},
1782 { "emacs-meta", emacs_meta_keymap
},
1783 { "emacs-ctlx", emacs_ctlx_keymap
},
1784 #if defined (VI_MODE)
1785 { "vi", vi_movement_keymap
},
1786 { "vi-move", vi_movement_keymap
},
1787 { "vi-command", vi_movement_keymap
},
1788 { "vi-insert", vi_insertion_keymap
},
1789 #endif /* VI_MODE */
1790 { (char *)0x0, (Keymap
)0x0 }
1794 rl_get_keymap_by_name (name
)
1799 for (i
= 0; keymap_names
[i
].name
; i
++)
1800 if (_rl_stricmp (name
, keymap_names
[i
].name
) == 0)
1801 return (keymap_names
[i
].map
);
1802 return ((Keymap
) NULL
);
1806 rl_get_keymap_name (map
)
1810 for (i
= 0; keymap_names
[i
].name
; i
++)
1811 if (map
== keymap_names
[i
].map
)
1812 return ((char *)keymap_names
[i
].name
);
1813 return ((char *)NULL
);
1827 return (_rl_keymap
);
1831 rl_set_keymap_from_edit_mode ()
1833 if (rl_editing_mode
== emacs_mode
)
1834 _rl_keymap
= emacs_standard_keymap
;
1835 #if defined (VI_MODE)
1836 else if (rl_editing_mode
== vi_mode
)
1837 _rl_keymap
= vi_insertion_keymap
;
1838 #endif /* VI_MODE */
1842 rl_get_keymap_name_from_edit_mode ()
1844 if (rl_editing_mode
== emacs_mode
)
1846 #if defined (VI_MODE)
1847 else if (rl_editing_mode
== vi_mode
)
1849 #endif /* VI_MODE */
1854 /* **************************************************************** */
1856 /* Key Binding and Function Information */
1858 /* **************************************************************** */
1860 /* Each of the following functions produces information about the
1861 state of keybindings and functions known to Readline. The info
1862 is always printed to rl_outstream, and in such a way that it can
1863 be read back in (i.e., passed to rl_parse_and_bind ()). */
1865 /* Print the names of functions known to Readline. */
1867 rl_list_funmap_names ()
1870 const char **funmap_names
;
1872 funmap_names
= rl_funmap_names ();
1877 for (i
= 0; funmap_names
[i
]; i
++)
1878 fprintf (rl_outstream
, "%s\n", funmap_names
[i
]);
1880 xfree (funmap_names
);
1884 _rl_get_keyname (key
)
1890 keyname
= (char *)xmalloc (8);
1893 /* Since this is going to be used to write out keysequence-function
1894 pairs for possible inclusion in an inputrc file, we don't want to
1895 do any special meta processing on KEY. */
1898 /* XXX - Experimental */
1899 /* We might want to do this, but the old version of the code did not. */
1901 /* If this is an escape character, we don't want to do any more processing.
1902 Just add the special ESC key sequence and return. */
1912 /* RUBOUT is translated directly into \C-? */
1924 /* Now add special prefixes needed for control characters. This can
1925 potentially change C. */
1928 keyname
[i
++] = '\\';
1931 c
= _rl_to_lower (UNCTRL (c
));
1934 /* XXX experimental code. Turn the characters that are not ASCII or
1935 ISO Latin 1 (128 - 159) into octal escape sequences (\200 - \237).
1937 if (c
>= 128 && c
<= 159)
1939 keyname
[i
++] = '\\';
1942 keyname
[i
++] = (c
/ 8) + '0';
1946 /* Now, if the character needs to be quoted with a backslash, do that. */
1947 if (c
== '\\' || c
== '"')
1948 keyname
[i
++] = '\\';
1950 /* Now add the key, terminate the string, and return it. */
1951 keyname
[i
++] = (char) c
;
1957 /* Return a NULL terminated array of strings which represent the key
1958 sequences that are used to invoke FUNCTION in MAP. */
1960 rl_invoking_keyseqs_in_map (function
, map
)
1961 rl_command_func_t
*function
;
1966 int result_index
, result_size
;
1968 result
= (char **)NULL
;
1969 result_index
= result_size
= 0;
1971 for (key
= 0; key
< KEYMAP_SIZE
; key
++)
1973 switch (map
[key
].type
)
1976 /* Macros match, if, and only if, the pointers are identical.
1977 Thus, they are treated exactly like functions in here. */
1979 /* If the function in the keymap is the one we are looking for,
1980 then add the current KEY to the list of invoking keys. */
1981 if (map
[key
].function
== function
)
1985 keyname
= _rl_get_keyname (key
);
1987 if (result_index
+ 2 > result_size
)
1990 result
= (char **)xrealloc (result
, result_size
* sizeof (char *));
1993 result
[result_index
++] = keyname
;
1994 result
[result_index
] = (char *)NULL
;
2003 /* Find the list of keyseqs in this map which have FUNCTION as
2004 their target. Add the key sequences found to RESULT. */
2005 if (map
[key
].function
)
2007 rl_invoking_keyseqs_in_map (function
, FUNCTION_TO_KEYMAP (map
, key
));
2014 for (i
= 0; seqs
[i
]; i
++)
2016 char *keyname
= (char *)xmalloc (6 + strlen (seqs
[i
]));
2020 /* If ESC is the meta prefix and we're converting chars
2021 with the eighth bit set to ESC-prefixed sequences, then
2022 we can use \M-. Otherwise we need to use the sequence
2024 if (_rl_convert_meta_chars_to_ascii
&& map
[ESC
].type
== ISKMAP
)
2025 sprintf (keyname
, "\\M-");
2027 sprintf (keyname
, "\\e");
2029 else if (CTRL_CHAR (key
))
2030 sprintf (keyname
, "\\C-%c", _rl_to_lower (UNCTRL (key
)));
2031 else if (key
== RUBOUT
)
2032 sprintf (keyname
, "\\C-?");
2033 else if (key
== '\\' || key
== '"')
2036 keyname
[1] = (char) key
;
2041 keyname
[0] = (char) key
;
2045 strcat (keyname
, seqs
[i
]);
2048 if (result_index
+ 2 > result_size
)
2051 result
= (char **)xrealloc (result
, result_size
* sizeof (char *));
2054 result
[result_index
++] = keyname
;
2055 result
[result_index
] = (char *)NULL
;
2066 /* Return a NULL terminated array of strings which represent the key
2067 sequences that can be used to invoke FUNCTION using the current keymap. */
2069 rl_invoking_keyseqs (function
)
2070 rl_command_func_t
*function
;
2072 return (rl_invoking_keyseqs_in_map (function
, _rl_keymap
));
2075 /* Print all of the functions and their bindings to rl_outstream. If
2076 PRINT_READABLY is non-zero, then print the output in such a way
2077 that it can be read back in. */
2079 rl_function_dumper (print_readably
)
2086 names
= rl_funmap_names ();
2088 fprintf (rl_outstream
, "\n");
2090 for (i
= 0; name
= names
[i
]; i
++)
2092 rl_command_func_t
*function
;
2095 function
= rl_named_function (name
);
2096 invokers
= rl_invoking_keyseqs_in_map (function
, _rl_keymap
);
2101 fprintf (rl_outstream
, "# %s (not bound)\n", name
);
2106 for (j
= 0; invokers
[j
]; j
++)
2108 fprintf (rl_outstream
, "\"%s\": %s\n",
2110 xfree (invokers
[j
]);
2119 fprintf (rl_outstream
, "%s is not bound to any keys\n",
2125 fprintf (rl_outstream
, "%s can be found on ", name
);
2127 for (j
= 0; invokers
[j
] && j
< 5; j
++)
2129 fprintf (rl_outstream
, "\"%s\"%s", invokers
[j
],
2130 invokers
[j
+ 1] ? ", " : ".\n");
2133 if (j
== 5 && invokers
[j
])
2134 fprintf (rl_outstream
, "...\n");
2136 for (j
= 0; invokers
[j
]; j
++)
2137 xfree (invokers
[j
]);
2145 /* Print all of the current functions and their bindings to
2146 rl_outstream. If an explicit argument is given, then print
2147 the output in such a way that it can be read back in. */
2149 rl_dump_functions (count
, key
)
2153 fprintf (rl_outstream
, "\r\n");
2154 rl_function_dumper (rl_explicit_arg
);
2160 _rl_macro_dumper_internal (print_readably
, map
, prefix
)
2166 char *keyname
, *out
;
2169 for (key
= 0; key
< KEYMAP_SIZE
; key
++)
2171 switch (map
[key
].type
)
2174 keyname
= _rl_get_keyname (key
);
2175 out
= _rl_untranslate_macro_value ((char *)map
[key
].function
);
2178 fprintf (rl_outstream
, "\"%s%s\": \"%s\"\n", prefix
? prefix
: "",
2182 fprintf (rl_outstream
, "%s%s outputs %s\n", prefix
? prefix
: "",
2191 prefix_len
= prefix
? strlen (prefix
) : 0;
2194 keyname
= (char *)xmalloc (3 + prefix_len
);
2196 strcpy (keyname
, prefix
);
2197 keyname
[prefix_len
] = '\\';
2198 keyname
[prefix_len
+ 1] = 'e';
2199 keyname
[prefix_len
+ 2] = '\0';
2203 keyname
= _rl_get_keyname (key
);
2206 out
= (char *)xmalloc (strlen (keyname
) + prefix_len
+ 1);
2207 strcpy (out
, prefix
);
2208 strcpy (out
+ prefix_len
, keyname
);
2214 _rl_macro_dumper_internal (print_readably
, FUNCTION_TO_KEYMAP (map
, key
), keyname
);
2222 rl_macro_dumper (print_readably
)
2225 _rl_macro_dumper_internal (print_readably
, _rl_keymap
, (char *)NULL
);
2229 rl_dump_macros (count
, key
)
2233 fprintf (rl_outstream
, "\r\n");
2234 rl_macro_dumper (rl_explicit_arg
);
2240 _rl_get_string_variable_value (name
)
2243 static char numbuf
[32];
2246 if (_rl_stricmp (name
, "bell-style") == 0)
2248 switch (_rl_bell_preference
)
2259 else if (_rl_stricmp (name
, "comment-begin") == 0)
2260 return (_rl_comment_begin
? _rl_comment_begin
: RL_COMMENT_BEGIN_DEFAULT
);
2261 else if (_rl_stricmp (name
, "completion-prefix-display-length") == 0)
2263 sprintf (numbuf
, "%d", _rl_completion_prefix_display_length
);
2266 else if (_rl_stricmp (name
, "completion-query-items") == 0)
2268 sprintf (numbuf
, "%d", rl_completion_query_items
);
2271 else if (_rl_stricmp (name
, "editing-mode") == 0)
2272 return (rl_get_keymap_name_from_edit_mode ());
2273 else if (_rl_stricmp (name
, "history-size") == 0)
2275 sprintf (numbuf
, "%d", history_is_stifled() ? history_max_entries
: 0);
2278 else if (_rl_stricmp (name
, "isearch-terminators") == 0)
2280 if (_rl_isearch_terminators
== 0)
2282 ret
= _rl_untranslate_macro_value (_rl_isearch_terminators
);
2285 strncpy (numbuf
, ret
, sizeof (numbuf
) - 1);
2287 numbuf
[sizeof(numbuf
) - 1] = '\0';
2293 else if (_rl_stricmp (name
, "keymap") == 0)
2295 ret
= rl_get_keymap_name (_rl_keymap
);
2297 ret
= rl_get_keymap_name_from_edit_mode ();
2298 return (ret
? ret
: "none");
2305 rl_variable_dumper (print_readably
)
2311 for (i
= 0; boolean_varlist
[i
].name
; i
++)
2314 fprintf (rl_outstream
, "set %s %s\n", boolean_varlist
[i
].name
,
2315 *boolean_varlist
[i
].value
? "on" : "off");
2317 fprintf (rl_outstream
, "%s is set to `%s'\n", boolean_varlist
[i
].name
,
2318 *boolean_varlist
[i
].value
? "on" : "off");
2321 for (i
= 0; string_varlist
[i
].name
; i
++)
2323 v
= _rl_get_string_variable_value (string_varlist
[i
].name
);
2324 if (v
== 0) /* _rl_isearch_terminators can be NULL */
2327 fprintf (rl_outstream
, "set %s %s\n", string_varlist
[i
].name
, v
);
2329 fprintf (rl_outstream
, "%s is set to `%s'\n", string_varlist
[i
].name
, v
);
2333 /* Print all of the current variables and their values to
2334 rl_outstream. If an explicit argument is given, then print
2335 the output in such a way that it can be read back in. */
2337 rl_dump_variables (count
, key
)
2341 fprintf (rl_outstream
, "\r\n");
2342 rl_variable_dumper (rl_explicit_arg
);
2347 /* Return non-zero if any members of ARRAY are a substring in STRING. */
2349 substring_member_of_array (string
, array
)
2351 const char * const *array
;
2355 if (_rl_strindex (string
, *array
))