1 /* bind.c -- key binding and startup file support for the readline library. */
3 /* Copyright (C) 1987-2006 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
]));
465 i
++; /* seq[i] == '-' */
466 /* XXX - 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 */
469 else if (seq
[i
+1] == '\\' && seq
[i
+2] == 'C' && seq
[i
+3] == '-')
472 temp
= (seq
[i
] == '?') ? RUBOUT
: CTRL (_rl_to_upper (seq
[i
]));
473 array
[l
++] = META (temp
);
477 /* This doesn't yet handle things like \M-\a, which may
478 or may not have any reasonable meaning. You're
479 probably better off using straight octal or hex. */
481 array
[l
++] = META (seq
[i
]);
487 /* Special hack for C-?... */
488 array
[l
++] = (seq
[i
] == '?') ? RUBOUT
: CTRL (_rl_to_upper (seq
[i
]));
493 /* Translate other backslash-escaped characters. These are the
494 same escape sequences that bash's `echo' and `printf' builtins
495 handle, with the addition of \d -> RUBOUT. A backslash
496 preceding a character that is not special is stripped. */
506 array
[l
++] = RUBOUT
; /* readline-specific */
515 array
[l
++] = NEWLINE
;
529 case '0': case '1': case '2': case '3':
530 case '4': case '5': case '6': case '7':
532 for (temp
= 2, c
-= '0'; ISOCTAL (seq
[i
]) && temp
--; i
++)
533 c
= (c
* 8) + OCTVALUE (seq
[i
]);
534 i
--; /* auto-increment in for loop */
535 array
[l
++] = c
& largest_char
;
539 for (temp
= 2, c
= 0; ISXDIGIT ((unsigned char)seq
[i
]) && temp
--; i
++)
540 c
= (c
* 16) + HEXVALUE (seq
[i
]);
543 i
--; /* auto-increment in for loop */
544 array
[l
++] = c
& largest_char
;
546 default: /* backslashes before non-special chars just add the char */
548 break; /* the backslash is stripped */
562 rl_untranslate_keyseq (seq
)
565 static char kseq
[16];
582 else if (CTRL_CHAR (c
))
587 c
= _rl_to_lower (UNCTRL (c
));
589 else if (c
== RUBOUT
)
602 else if (c
== '\\' || c
== '"')
607 kseq
[i
++] = (unsigned char) c
;
613 _rl_untranslate_macro_value (seq
)
619 r
= ret
= (char *)xmalloc (7 * strlen (seq
) + 1);
620 for (s
= seq
; *s
; s
++)
635 else if (CTRL_CHAR (c
))
640 c
= _rl_to_lower (UNCTRL (c
));
642 else if (c
== RUBOUT
)
655 else if (c
== '\\' || c
== '"')
658 *r
++ = (unsigned char)c
;
664 /* Return a pointer to the function that STRING represents.
665 If STRING doesn't have a matching function, then a NULL pointer
668 rl_named_function (string
)
673 rl_initialize_funmap ();
675 for (i
= 0; funmap
[i
]; i
++)
676 if (_rl_stricmp (funmap
[i
]->name
, string
) == 0)
677 return (funmap
[i
]->function
);
678 return ((rl_command_func_t
*)NULL
);
681 /* Return the function (or macro) definition which would be invoked via
682 KEYSEQ if executed in MAP. If MAP is NULL, then the current keymap is
683 used. TYPE, if non-NULL, is a pointer to an int which will receive the
684 type of the object pointed to. One of ISFUNC (function), ISKMAP (keymap),
685 or ISMACR (macro). */
687 rl_function_of_keyseq (keyseq
, map
, type
)
697 for (i
= 0; keyseq
&& keyseq
[i
]; i
++)
699 unsigned char ic
= keyseq
[i
];
701 if (META_CHAR (ic
) && _rl_convert_meta_chars_to_ascii
)
703 if (map
[ESC
].type
== ISKMAP
)
705 map
= FUNCTION_TO_KEYMAP (map
, ESC
);
708 /* XXX - should we just return NULL here, since this obviously
713 *type
= map
[ESC
].type
;
715 return (map
[ESC
].function
);
719 if (map
[ic
].type
== ISKMAP
)
721 /* If this is the last key in the key sequence, return the
723 if (keyseq
[i
+ 1] == '\0')
728 return (map
[ic
].function
);
731 map
= FUNCTION_TO_KEYMAP (map
, ic
);
733 /* If we're not at the end of the key sequence, and the current key
734 is bound to something other than a keymap, then the entire key
735 sequence is not bound. */
736 else if (map
[ic
].type
!= ISKMAP
&& keyseq
[i
+1])
737 return ((rl_command_func_t
*)NULL
);
738 else /* map[ic].type != ISKMAP && keyseq[i+1] == 0 */
741 *type
= map
[ic
].type
;
743 return (map
[ic
].function
);
746 return ((rl_command_func_t
*) NULL
);
749 /* The last key bindings file read. */
750 static char *last_readline_init_file
= (char *)NULL
;
752 /* The file we're currently reading key bindings from. */
753 static const char *current_readline_init_file
;
754 static int current_readline_init_include_level
;
755 static int current_readline_init_lineno
;
757 /* Read FILENAME into a locally-allocated buffer and return the buffer.
758 The size of the buffer is returned in *SIZEP. Returns NULL if any
759 errors were encountered. */
761 _rl_read_file (filename
, sizep
)
770 if ((stat (filename
, &finfo
) < 0) || (file
= open (filename
, O_RDONLY
, 0666)) < 0)
771 return ((char *)NULL
);
773 file_size
= (size_t)finfo
.st_size
;
775 /* check for overflow on very large files */
776 if (file_size
!= finfo
.st_size
|| file_size
+ 1 < file_size
)
783 return ((char *)NULL
);
786 /* Read the file into BUFFER. */
787 buffer
= (char *)xmalloc (file_size
+ 1);
788 i
= read (file
, buffer
, file_size
);
794 return ((char *)NULL
);
804 /* Re-read the current keybindings file. */
806 rl_re_read_init_file (count
, ignore
)
810 r
= rl_read_init_file ((const char *)NULL
);
811 rl_set_keymap_from_edit_mode ();
815 /* Do key bindings from a file. If FILENAME is NULL it defaults
816 to the first non-null filename from this list:
817 1. the filename used for the previous call
818 2. the value of the shell variable `INPUTRC'
821 If the file existed and could be opened and read, 0 is returned,
822 otherwise errno is returned. */
824 rl_read_init_file (filename
)
825 const char *filename
;
827 /* Default the filename. */
829 filename
= last_readline_init_file
;
831 filename
= sh_get_env_value ("INPUTRC");
832 if (filename
== 0 || *filename
== 0)
834 filename
= DEFAULT_INPUTRC
;
835 /* Try to read DEFAULT_INPUTRC; fall back to SYS_INPUTRC on failure */
836 if (_rl_read_init_file (filename
, 0) == 0)
838 filename
= SYS_INPUTRC
;
841 #if defined (__MSDOS__)
842 if (_rl_read_init_file (filename
, 0) == 0)
844 filename
= "~/_inputrc";
846 return (_rl_read_init_file (filename
, 0));
850 _rl_read_init_file (filename
, include_level
)
851 const char *filename
;
855 char *buffer
, *openname
, *line
, *end
;
858 current_readline_init_file
= filename
;
859 current_readline_init_include_level
= include_level
;
861 openname
= tilde_expand (filename
);
862 buffer
= _rl_read_file (openname
, &file_size
);
868 if (include_level
== 0 && filename
!= last_readline_init_file
)
870 FREE (last_readline_init_file
);
871 last_readline_init_file
= savestring (filename
);
874 currently_reading_init_file
= 1;
876 /* Loop over the lines in the file. Lines that start with `#' are
877 comments; all other lines are commands for readline initialization. */
878 current_readline_init_lineno
= 1;
880 end
= buffer
+ file_size
;
883 /* Find the end of this line. */
884 for (i
= 0; line
+ i
!= end
&& line
[i
] != '\n'; i
++);
886 #if defined (__CYGWIN__)
887 /* ``Be liberal in what you accept.'' */
888 if (line
[i
] == '\n' && line
[i
-1] == '\r')
892 /* Mark end of line. */
895 /* Skip leading whitespace. */
896 while (*line
&& whitespace (*line
))
902 /* If the line is not a comment, then parse it. */
903 if (*line
&& *line
!= '#')
904 rl_parse_and_bind (line
);
906 /* Move to the next line. */
908 current_readline_init_lineno
++;
912 currently_reading_init_file
= 0;
917 _rl_init_file_error (msg
)
920 if (currently_reading_init_file
)
921 fprintf (stderr
, "readline: %s: line %d: %s\n", current_readline_init_file
,
922 current_readline_init_lineno
, msg
);
924 fprintf (stderr
, "readline: %s\n", msg
);
927 /* **************************************************************** */
929 /* Parser Directives */
931 /* **************************************************************** */
933 typedef int _rl_parser_func_t
PARAMS((char *));
935 /* Things that mean `Control'. */
936 const char *_rl_possible_control_prefixes
[] = {
937 "Control-", "C-", "CTRL-", (const char *)NULL
940 const char *_rl_possible_meta_prefixes
[] = {
941 "Meta", "M-", (const char *)NULL
946 /* Calling programs set this to have their argv[0]. */
947 const char *rl_readline_name
= "other";
949 /* Stack of previous values of parsing_conditionalized_out. */
950 static unsigned char *if_stack
= (unsigned char *)NULL
;
951 static int if_stack_depth
;
952 static int if_stack_size
;
954 /* Push _rl_parsing_conditionalized_out, and set parser state based
962 /* Push parser state. */
963 if (if_stack_depth
+ 1 >= if_stack_size
)
966 if_stack
= (unsigned char *)xmalloc (if_stack_size
= 20);
968 if_stack
= (unsigned char *)xrealloc (if_stack
, if_stack_size
+= 20);
970 if_stack
[if_stack_depth
++] = _rl_parsing_conditionalized_out
;
972 /* If parsing is turned off, then nothing can turn it back on except
973 for finding the matching endif. In that case, return right now. */
974 if (_rl_parsing_conditionalized_out
)
977 /* Isolate first argument. */
978 for (i
= 0; args
[i
] && !whitespace (args
[i
]); i
++);
983 /* Handle "$if term=foo" and "$if mode=emacs" constructs. If this
984 isn't term=foo, or mode=emacs, then check to see if the first
985 word in ARGS is the same as the value stored in rl_readline_name. */
986 if (rl_terminal_name
&& _rl_strnicmp (args
, "term=", 5) == 0)
990 /* Terminals like "aaa-60" are equivalent to "aaa". */
991 tname
= savestring (rl_terminal_name
);
992 tem
= strchr (tname
, '-');
996 /* Test the `long' and `short' forms of the terminal name so that
997 if someone has a `sun-cmd' and does not want to have bindings
998 that will be executed if the terminal is a `sun', they can put
999 `$if term=sun-cmd' into their .inputrc. */
1000 _rl_parsing_conditionalized_out
= _rl_stricmp (args
+ 5, tname
) &&
1001 _rl_stricmp (args
+ 5, rl_terminal_name
);
1004 #if defined (VI_MODE)
1005 else if (_rl_strnicmp (args
, "mode=", 5) == 0)
1009 if (_rl_stricmp (args
+ 5, "emacs") == 0)
1011 else if (_rl_stricmp (args
+ 5, "vi") == 0)
1016 _rl_parsing_conditionalized_out
= mode
!= rl_editing_mode
;
1018 #endif /* VI_MODE */
1019 /* Check to see if the first word in ARGS is the same as the
1020 value stored in rl_readline_name. */
1021 else if (_rl_stricmp (args
, rl_readline_name
) == 0)
1022 _rl_parsing_conditionalized_out
= 0;
1024 _rl_parsing_conditionalized_out
= 1;
1028 /* Invert the current parser state if there is anything on the stack. */
1035 if (if_stack_depth
== 0)
1037 _rl_init_file_error ("$else found without matching $if");
1042 /* Check the previous (n - 1) levels of the stack to make sure that
1043 we haven't previously turned off parsing. */
1044 for (i
= 0; i
< if_stack_depth
- 1; i
++)
1046 /* Check the previous (n) levels of the stack to make sure that
1047 we haven't previously turned off parsing. */
1048 for (i
= 0; i
< if_stack_depth
; i
++)
1050 if (if_stack
[i
] == 1)
1053 /* Invert the state of parsing if at top level. */
1054 _rl_parsing_conditionalized_out
= !_rl_parsing_conditionalized_out
;
1058 /* Terminate a conditional, popping the value of
1059 _rl_parsing_conditionalized_out from the stack. */
1065 _rl_parsing_conditionalized_out
= if_stack
[--if_stack_depth
];
1067 _rl_init_file_error ("$endif without matching $if");
1072 parser_include (args
)
1075 const char *old_init_file
;
1077 int old_line_number
, old_include_level
, r
;
1079 if (_rl_parsing_conditionalized_out
)
1082 old_init_file
= current_readline_init_file
;
1083 old_line_number
= current_readline_init_lineno
;
1084 old_include_level
= current_readline_init_include_level
;
1086 e
= strchr (args
, '\n');
1089 r
= _rl_read_init_file ((const char *)args
, old_include_level
+ 1);
1091 current_readline_init_file
= old_init_file
;
1092 current_readline_init_lineno
= old_line_number
;
1093 current_readline_init_include_level
= old_include_level
;
1098 /* Associate textual names with actual functions. */
1101 _rl_parser_func_t
*function
;
1102 } parser_directives
[] = {
1103 { "if", parser_if
},
1104 { "endif", parser_endif
},
1105 { "else", parser_else
},
1106 { "include", parser_include
},
1107 { (char *)0x0, (_rl_parser_func_t
*)0x0 }
1110 /* Handle a parser directive. STATEMENT is the line of the directive
1111 without any leading `$'. */
1113 handle_parser_directive (statement
)
1117 char *directive
, *args
;
1119 /* Isolate the actual directive. */
1121 /* Skip whitespace. */
1122 for (i
= 0; whitespace (statement
[i
]); i
++);
1124 directive
= &statement
[i
];
1126 for (; statement
[i
] && !whitespace (statement
[i
]); i
++);
1129 statement
[i
++] = '\0';
1131 for (; statement
[i
] && whitespace (statement
[i
]); i
++);
1133 args
= &statement
[i
];
1135 /* Lookup the command, and act on it. */
1136 for (i
= 0; parser_directives
[i
].name
; i
++)
1137 if (_rl_stricmp (directive
, parser_directives
[i
].name
) == 0)
1139 (*parser_directives
[i
].function
) (args
);
1143 /* display an error message about the unknown parser directive */
1144 _rl_init_file_error ("unknown parser directive");
1148 /* Read the binding command from STRING and perform it.
1149 A key binding command looks like: Keyname: function-name\0,
1150 a variable binding command looks like: set variable value.
1151 A new-style keybinding looks like "\C-x\C-x": exchange-point-and-mark. */
1153 rl_parse_and_bind (string
)
1156 char *funname
, *kname
;
1158 int key
, equivalency
;
1160 while (string
&& whitespace (*string
))
1163 if (!string
|| !*string
|| *string
== '#')
1166 /* If this is a parser directive, act on it. */
1169 handle_parser_directive (&string
[1]);
1173 /* If we aren't supposed to be parsing right now, then we're done. */
1174 if (_rl_parsing_conditionalized_out
)
1178 /* If this keyname is a complex key expression surrounded by quotes,
1179 advance to after the matching close quote. This code allows the
1180 backslash to quote characters in the key expression. */
1185 for (i
= 1; c
= string
[i
]; i
++)
1202 /* If we didn't find a closing quote, abort the line. */
1203 if (string
[i
] == '\0')
1205 _rl_init_file_error ("no closing `\"' in key binding");
1210 /* Advance to the colon (:) or whitespace which separates the two objects. */
1211 for (; (c
= string
[i
]) && c
!= ':' && c
!= ' ' && c
!= '\t'; i
++ );
1213 equivalency
= (c
== ':' && string
[i
+ 1] == '=');
1215 /* Mark the end of the command (or keyname). */
1219 /* If doing assignment, skip the '=' sign as well. */
1223 /* If this is a command to set a variable, then do that. */
1224 if (_rl_stricmp (string
, "set") == 0)
1226 char *var
, *value
, *e
;
1229 /* Make VAR point to start of variable name. */
1230 while (*var
&& whitespace (*var
)) var
++;
1232 /* Make VALUE point to start of value string. */
1234 while (*value
&& !whitespace (*value
)) value
++;
1237 while (*value
&& whitespace (*value
)) value
++;
1239 /* Strip trailing whitespace from values to boolean variables. Temp
1240 fix until I get a real quoted-string parser here. */
1241 i
= find_boolean_var (var
);
1244 /* remove trailing whitespace */
1245 e
= value
+ strlen (value
) - 1;
1246 while (e
>= value
&& whitespace (*e
))
1248 e
++; /* skip back to whitespace or EOS */
1249 if (*e
&& e
>= value
)
1253 rl_variable_bind (var
, value
);
1257 /* Skip any whitespace between keyname and funname. */
1258 for (; string
[i
] && whitespace (string
[i
]); i
++);
1259 funname
= &string
[i
];
1261 /* Now isolate funname.
1262 For straight function names just look for whitespace, since
1263 that will signify the end of the string. But this could be a
1264 macro definition. In that case, the string is quoted, so skip
1265 to the matching delimiter. We allow the backslash to quote the
1266 delimiter characters in the macro body. */
1267 /* This code exists to allow whitespace in macro expansions, which
1268 would otherwise be gobbled up by the next `for' loop.*/
1269 /* XXX - it may be desirable to allow backslash quoting only if " is
1270 the quoted string delimiter, like the shell. */
1271 if (*funname
== '\'' || *funname
== '"')
1273 int delimiter
, passc
;
1275 delimiter
= string
[i
++];
1276 for (passc
= 0; c
= string
[i
]; i
++)
1297 /* Advance to the end of the string. */
1298 for (; string
[i
] && !whitespace (string
[i
]); i
++);
1300 /* No extra whitespace at the end of the string. */
1303 /* Handle equivalency bindings here. Make the left-hand side be exactly
1304 whatever the right-hand evaluates to, including keymaps. */
1310 /* If this is a new-style key-binding, then do the binding with
1311 rl_bind_keyseq (). Otherwise, let the older code deal with it. */
1315 register int j
, k
, passc
;
1317 seq
= (char *)xmalloc (1 + strlen (string
));
1318 for (j
= 1, k
= passc
= 0; string
[j
]; j
++)
1320 /* Allow backslash to quote characters, but leave them in place.
1321 This allows a string to end with a backslash quoting another
1322 backslash, or with a backslash quoting a double quote. The
1323 backslashes are left in place for rl_translate_keyseq (). */
1324 if (passc
|| (string
[j
] == '\\'))
1326 seq
[k
++] = string
[j
];
1331 if (string
[j
] == '"')
1334 seq
[k
++] = string
[j
];
1338 /* Binding macro? */
1339 if (*funname
== '\'' || *funname
== '"')
1341 j
= strlen (funname
);
1343 /* Remove the delimiting quotes from each end of FUNNAME. */
1344 if (j
&& funname
[j
- 1] == *funname
)
1345 funname
[j
- 1] = '\0';
1347 rl_macro_bind (seq
, &funname
[1], _rl_keymap
);
1350 rl_bind_keyseq (seq
, rl_named_function (funname
));
1356 /* Get the actual character we want to deal with. */
1357 kname
= strrchr (string
, '-');
1363 key
= glean_key_from_name (kname
);
1365 /* Add in control and meta bits. */
1366 if (substring_member_of_array (string
, _rl_possible_control_prefixes
))
1367 key
= CTRL (_rl_to_upper (key
));
1369 if (substring_member_of_array (string
, _rl_possible_meta_prefixes
))
1372 /* Temporary. Handle old-style keyname with macro-binding. */
1373 if (*funname
== '\'' || *funname
== '"')
1376 int fl
= strlen (funname
);
1378 useq
[0] = key
; useq
[1] = '\0';
1379 if (fl
&& funname
[fl
- 1] == *funname
)
1380 funname
[fl
- 1] = '\0';
1382 rl_macro_bind (useq
, &funname
[1], _rl_keymap
);
1384 #if defined (PREFIX_META_HACK)
1385 /* Ugly, but working hack to keep prefix-meta around. */
1386 else if (_rl_stricmp (funname
, "prefix-meta") == 0)
1392 rl_generic_bind (ISKMAP
, seq
, (char *)emacs_meta_keymap
, _rl_keymap
);
1394 #endif /* PREFIX_META_HACK */
1396 rl_bind_key (key
, rl_named_function (funname
));
1400 /* Simple structure for boolean readline variables (i.e., those that can
1401 have one of two values; either "On" or 1 for truth, or "Off" or 0 for
1404 #define V_SPECIAL 0x1
1410 } boolean_varlist
[] = {
1411 { "bind-tty-special-chars", &_rl_bind_stty_chars
, 0 },
1412 { "blink-matching-paren", &rl_blink_matching_paren
, V_SPECIAL
},
1413 { "byte-oriented", &rl_byte_oriented
, 0 },
1414 { "completion-ignore-case", &_rl_completion_case_fold
, 0 },
1415 { "convert-meta", &_rl_convert_meta_chars_to_ascii
, 0 },
1416 { "disable-completion", &rl_inhibit_completion
, 0 },
1417 { "enable-keypad", &_rl_enable_keypad
, 0 },
1418 { "expand-tilde", &rl_complete_with_tilde_expansion
, 0 },
1419 { "history-preserve-point", &_rl_history_preserve_point
, 0 },
1420 { "horizontal-scroll-mode", &_rl_horizontal_scroll_mode
, 0 },
1421 { "input-meta", &_rl_meta_flag
, 0 },
1422 { "mark-directories", &_rl_complete_mark_directories
, 0 },
1423 { "mark-modified-lines", &_rl_mark_modified_lines
, 0 },
1424 { "mark-symlinked-directories", &_rl_complete_mark_symlink_dirs
, 0 },
1425 { "match-hidden-files", &_rl_match_hidden_files
, 0 },
1426 { "meta-flag", &_rl_meta_flag
, 0 },
1427 { "output-meta", &_rl_output_meta_chars
, 0 },
1428 { "page-completions", &_rl_page_completions
, 0 },
1429 { "prefer-visible-bell", &_rl_prefer_visible_bell
, V_SPECIAL
},
1430 { "print-completions-horizontally", &_rl_print_completions_horizontally
, 0 },
1431 { "show-all-if-ambiguous", &_rl_complete_show_all
, 0 },
1432 { "show-all-if-unmodified", &_rl_complete_show_unmodified
, 0 },
1433 #if defined (VISIBLE_STATS)
1434 { "visible-stats", &rl_visible_stats
, 0 },
1435 #endif /* VISIBLE_STATS */
1436 { (char *)NULL
, (int *)NULL
}
1440 find_boolean_var (name
)
1445 for (i
= 0; boolean_varlist
[i
].name
; i
++)
1446 if (_rl_stricmp (name
, boolean_varlist
[i
].name
) == 0)
1451 /* Hooks for handling special boolean variables, where a
1452 function needs to be called or another variable needs
1453 to be changed when they're changed. */
1455 hack_special_boolean_var (i
)
1460 name
= boolean_varlist
[i
].name
;
1462 if (_rl_stricmp (name
, "blink-matching-paren") == 0)
1463 _rl_enable_paren_matching (rl_blink_matching_paren
);
1464 else if (_rl_stricmp (name
, "prefer-visible-bell") == 0)
1466 if (_rl_prefer_visible_bell
)
1467 _rl_bell_preference
= VISIBLE_BELL
;
1469 _rl_bell_preference
= AUDIBLE_BELL
;
1473 typedef int _rl_sv_func_t
PARAMS((const char *));
1475 /* These *must* correspond to the array indices for the appropriate
1476 string variable. (Though they're not used right now.) */
1477 #define V_BELLSTYLE 0
1478 #define V_COMBEGIN 1
1479 #define V_EDITMODE 2
1480 #define V_ISRCHTERM 3
1486 /* Forward declarations */
1487 static int sv_bell_style
PARAMS((const char *));
1488 static int sv_combegin
PARAMS((const char *));
1489 static int sv_compquery
PARAMS((const char *));
1490 static int sv_editmode
PARAMS((const char *));
1491 static int sv_isrchterm
PARAMS((const char *));
1492 static int sv_keymap
PARAMS((const char *));
1497 _rl_sv_func_t
*set_func
;
1498 } string_varlist
[] = {
1499 { "bell-style", V_STRING
, sv_bell_style
},
1500 { "comment-begin", V_STRING
, sv_combegin
},
1501 { "completion-query-items", V_INT
, sv_compquery
},
1502 { "editing-mode", V_STRING
, sv_editmode
},
1503 { "isearch-terminators", V_STRING
, sv_isrchterm
},
1504 { "keymap", V_STRING
, sv_keymap
},
1509 find_string_var (name
)
1514 for (i
= 0; string_varlist
[i
].name
; i
++)
1515 if (_rl_stricmp (name
, string_varlist
[i
].name
) == 0)
1520 /* A boolean value that can appear in a `set variable' command is true if
1521 the value is null or empty, `on' (case-insenstive), or "1". Any other
1522 values result in 0 (false). */
1527 return (value
== 0 || *value
== '\0' ||
1528 (_rl_stricmp (value
, "on") == 0) ||
1529 (value
[0] == '1' && value
[1] == '\0'));
1533 rl_variable_value (name
)
1539 /* Check for simple variables first. */
1540 i
= find_boolean_var (name
);
1542 return (*boolean_varlist
[i
].value
? "on" : "off");
1544 i
= find_string_var (name
);
1546 return (_rl_get_string_variable_value (string_varlist
[i
].name
));
1548 /* Unknown variable names return NULL. */
1553 rl_variable_bind (name
, value
)
1554 const char *name
, *value
;
1559 /* Check for simple variables first. */
1560 i
= find_boolean_var (name
);
1563 *boolean_varlist
[i
].value
= bool_to_int (value
);
1564 if (boolean_varlist
[i
].flags
& V_SPECIAL
)
1565 hack_special_boolean_var (i
);
1569 i
= find_string_var (name
);
1571 /* For the time being, unknown variable names or string names without a
1572 handler function are simply ignored. */
1573 if (i
< 0 || string_varlist
[i
].set_func
== 0)
1576 v
= (*string_varlist
[i
].set_func
) (value
);
1584 if (_rl_strnicmp (value
, "vi", 2) == 0)
1586 #if defined (VI_MODE)
1587 _rl_keymap
= vi_insertion_keymap
;
1588 rl_editing_mode
= vi_mode
;
1589 #endif /* VI_MODE */
1592 else if (_rl_strnicmp (value
, "emacs", 5) == 0)
1594 _rl_keymap
= emacs_standard_keymap
;
1595 rl_editing_mode
= emacs_mode
;
1605 if (value
&& *value
)
1607 FREE (_rl_comment_begin
);
1608 _rl_comment_begin
= savestring (value
);
1615 sv_compquery (value
)
1620 if (value
&& *value
)
1622 nval
= atoi (value
);
1626 rl_completion_query_items
= nval
;
1636 kmap
= rl_get_keymap_by_name (value
);
1639 rl_set_keymap (kmap
);
1646 sv_bell_style (value
)
1649 if (value
== 0 || *value
== '\0')
1650 _rl_bell_preference
= AUDIBLE_BELL
;
1651 else if (_rl_stricmp (value
, "none") == 0 || _rl_stricmp (value
, "off") == 0)
1652 _rl_bell_preference
= NO_BELL
;
1653 else if (_rl_stricmp (value
, "audible") == 0 || _rl_stricmp (value
, "on") == 0)
1654 _rl_bell_preference
= AUDIBLE_BELL
;
1655 else if (_rl_stricmp (value
, "visible") == 0)
1656 _rl_bell_preference
= VISIBLE_BELL
;
1663 sv_isrchterm (value
)
1666 int beg
, end
, delim
;
1672 /* Isolate the value and translate it into a character string. */
1673 v
= savestring (value
);
1674 FREE (_rl_isearch_terminators
);
1675 if (v
[0] == '"' || v
[0] == '\'')
1678 for (beg
= end
= 1; v
[end
] && v
[end
] != delim
; end
++)
1683 for (beg
= end
= 0; whitespace (v
[end
]) == 0; end
++)
1689 /* The value starts at v + beg. Translate it into a character string. */
1690 _rl_isearch_terminators
= (char *)xmalloc (2 * strlen (v
) + 1);
1691 rl_translate_keyseq (v
+ beg
, _rl_isearch_terminators
, &end
);
1692 _rl_isearch_terminators
[end
] = '\0';
1698 /* Return the character which matches NAME.
1699 For example, `Space' returns ' '. */
1706 static assoc_list name_key_alist
[] = {
1709 { "Escape", '\033' },
1711 { "Newline", '\n' },
1722 glean_key_from_name (name
)
1727 for (i
= 0; name_key_alist
[i
].name
; i
++)
1728 if (_rl_stricmp (name
, name_key_alist
[i
].name
) == 0)
1729 return (name_key_alist
[i
].value
);
1731 return (*(unsigned char *)name
); /* XXX was return (*name) */
1734 /* Auxiliary functions to manage keymaps. */
1738 } keymap_names
[] = {
1739 { "emacs", emacs_standard_keymap
},
1740 { "emacs-standard", emacs_standard_keymap
},
1741 { "emacs-meta", emacs_meta_keymap
},
1742 { "emacs-ctlx", emacs_ctlx_keymap
},
1743 #if defined (VI_MODE)
1744 { "vi", vi_movement_keymap
},
1745 { "vi-move", vi_movement_keymap
},
1746 { "vi-command", vi_movement_keymap
},
1747 { "vi-insert", vi_insertion_keymap
},
1748 #endif /* VI_MODE */
1749 { (char *)0x0, (Keymap
)0x0 }
1753 rl_get_keymap_by_name (name
)
1758 for (i
= 0; keymap_names
[i
].name
; i
++)
1759 if (_rl_stricmp (name
, keymap_names
[i
].name
) == 0)
1760 return (keymap_names
[i
].map
);
1761 return ((Keymap
) NULL
);
1765 rl_get_keymap_name (map
)
1769 for (i
= 0; keymap_names
[i
].name
; i
++)
1770 if (map
== keymap_names
[i
].map
)
1771 return ((char *)keymap_names
[i
].name
);
1772 return ((char *)NULL
);
1786 return (_rl_keymap
);
1790 rl_set_keymap_from_edit_mode ()
1792 if (rl_editing_mode
== emacs_mode
)
1793 _rl_keymap
= emacs_standard_keymap
;
1794 #if defined (VI_MODE)
1795 else if (rl_editing_mode
== vi_mode
)
1796 _rl_keymap
= vi_insertion_keymap
;
1797 #endif /* VI_MODE */
1801 rl_get_keymap_name_from_edit_mode ()
1803 if (rl_editing_mode
== emacs_mode
)
1805 #if defined (VI_MODE)
1806 else if (rl_editing_mode
== vi_mode
)
1808 #endif /* VI_MODE */
1813 /* **************************************************************** */
1815 /* Key Binding and Function Information */
1817 /* **************************************************************** */
1819 /* Each of the following functions produces information about the
1820 state of keybindings and functions known to Readline. The info
1821 is always printed to rl_outstream, and in such a way that it can
1822 be read back in (i.e., passed to rl_parse_and_bind ()). */
1824 /* Print the names of functions known to Readline. */
1826 rl_list_funmap_names ()
1829 const char **funmap_names
;
1831 funmap_names
= rl_funmap_names ();
1836 for (i
= 0; funmap_names
[i
]; i
++)
1837 fprintf (rl_outstream
, "%s\n", funmap_names
[i
]);
1839 free (funmap_names
);
1843 _rl_get_keyname (key
)
1849 keyname
= (char *)xmalloc (8);
1852 /* Since this is going to be used to write out keysequence-function
1853 pairs for possible inclusion in an inputrc file, we don't want to
1854 do any special meta processing on KEY. */
1857 /* XXX - Experimental */
1858 /* We might want to do this, but the old version of the code did not. */
1860 /* If this is an escape character, we don't want to do any more processing.
1861 Just add the special ESC key sequence and return. */
1871 /* RUBOUT is translated directly into \C-? */
1883 /* Now add special prefixes needed for control characters. This can
1884 potentially change C. */
1887 keyname
[i
++] = '\\';
1890 c
= _rl_to_lower (UNCTRL (c
));
1893 /* XXX experimental code. Turn the characters that are not ASCII or
1894 ISO Latin 1 (128 - 159) into octal escape sequences (\200 - \237).
1896 if (c
>= 128 && c
<= 159)
1898 keyname
[i
++] = '\\';
1901 keyname
[i
++] = (c
/ 8) + '0';
1905 /* Now, if the character needs to be quoted with a backslash, do that. */
1906 if (c
== '\\' || c
== '"')
1907 keyname
[i
++] = '\\';
1909 /* Now add the key, terminate the string, and return it. */
1910 keyname
[i
++] = (char) c
;
1916 /* Return a NULL terminated array of strings which represent the key
1917 sequences that are used to invoke FUNCTION in MAP. */
1919 rl_invoking_keyseqs_in_map (function
, map
)
1920 rl_command_func_t
*function
;
1925 int result_index
, result_size
;
1927 result
= (char **)NULL
;
1928 result_index
= result_size
= 0;
1930 for (key
= 0; key
< KEYMAP_SIZE
; key
++)
1932 switch (map
[key
].type
)
1935 /* Macros match, if, and only if, the pointers are identical.
1936 Thus, they are treated exactly like functions in here. */
1938 /* If the function in the keymap is the one we are looking for,
1939 then add the current KEY to the list of invoking keys. */
1940 if (map
[key
].function
== function
)
1944 keyname
= _rl_get_keyname (key
);
1946 if (result_index
+ 2 > result_size
)
1949 result
= (char **)xrealloc (result
, result_size
* sizeof (char *));
1952 result
[result_index
++] = keyname
;
1953 result
[result_index
] = (char *)NULL
;
1962 /* Find the list of keyseqs in this map which have FUNCTION as
1963 their target. Add the key sequences found to RESULT. */
1964 if (map
[key
].function
)
1966 rl_invoking_keyseqs_in_map (function
, FUNCTION_TO_KEYMAP (map
, key
));
1973 for (i
= 0; seqs
[i
]; i
++)
1975 char *keyname
= (char *)xmalloc (6 + strlen (seqs
[i
]));
1979 /* If ESC is the meta prefix and we're converting chars
1980 with the eighth bit set to ESC-prefixed sequences, then
1981 we can use \M-. Otherwise we need to use the sequence
1983 if (_rl_convert_meta_chars_to_ascii
&& map
[ESC
].type
== ISKMAP
)
1984 sprintf (keyname
, "\\M-");
1986 sprintf (keyname
, "\\e");
1988 else if (CTRL_CHAR (key
))
1989 sprintf (keyname
, "\\C-%c", _rl_to_lower (UNCTRL (key
)));
1990 else if (key
== RUBOUT
)
1991 sprintf (keyname
, "\\C-?");
1992 else if (key
== '\\' || key
== '"')
1995 keyname
[1] = (char) key
;
2000 keyname
[0] = (char) key
;
2004 strcat (keyname
, seqs
[i
]);
2007 if (result_index
+ 2 > result_size
)
2010 result
= (char **)xrealloc (result
, result_size
* sizeof (char *));
2013 result
[result_index
++] = keyname
;
2014 result
[result_index
] = (char *)NULL
;
2025 /* Return a NULL terminated array of strings which represent the key
2026 sequences that can be used to invoke FUNCTION using the current keymap. */
2028 rl_invoking_keyseqs (function
)
2029 rl_command_func_t
*function
;
2031 return (rl_invoking_keyseqs_in_map (function
, _rl_keymap
));
2034 /* Print all of the functions and their bindings to rl_outstream. If
2035 PRINT_READABLY is non-zero, then print the output in such a way
2036 that it can be read back in. */
2038 rl_function_dumper (print_readably
)
2045 names
= rl_funmap_names ();
2047 fprintf (rl_outstream
, "\n");
2049 for (i
= 0; name
= names
[i
]; i
++)
2051 rl_command_func_t
*function
;
2054 function
= rl_named_function (name
);
2055 invokers
= rl_invoking_keyseqs_in_map (function
, _rl_keymap
);
2060 fprintf (rl_outstream
, "# %s (not bound)\n", name
);
2065 for (j
= 0; invokers
[j
]; j
++)
2067 fprintf (rl_outstream
, "\"%s\": %s\n",
2078 fprintf (rl_outstream
, "%s is not bound to any keys\n",
2084 fprintf (rl_outstream
, "%s can be found on ", name
);
2086 for (j
= 0; invokers
[j
] && j
< 5; j
++)
2088 fprintf (rl_outstream
, "\"%s\"%s", invokers
[j
],
2089 invokers
[j
+ 1] ? ", " : ".\n");
2092 if (j
== 5 && invokers
[j
])
2093 fprintf (rl_outstream
, "...\n");
2095 for (j
= 0; invokers
[j
]; j
++)
2104 /* Print all of the current functions and their bindings to
2105 rl_outstream. If an explicit argument is given, then print
2106 the output in such a way that it can be read back in. */
2108 rl_dump_functions (count
, key
)
2112 fprintf (rl_outstream
, "\r\n");
2113 rl_function_dumper (rl_explicit_arg
);
2119 _rl_macro_dumper_internal (print_readably
, map
, prefix
)
2125 char *keyname
, *out
;
2128 for (key
= 0; key
< KEYMAP_SIZE
; key
++)
2130 switch (map
[key
].type
)
2133 keyname
= _rl_get_keyname (key
);
2134 out
= _rl_untranslate_macro_value ((char *)map
[key
].function
);
2137 fprintf (rl_outstream
, "\"%s%s\": \"%s\"\n", prefix
? prefix
: "",
2141 fprintf (rl_outstream
, "%s%s outputs %s\n", prefix
? prefix
: "",
2150 prefix_len
= prefix
? strlen (prefix
) : 0;
2153 keyname
= (char *)xmalloc (3 + prefix_len
);
2155 strcpy (keyname
, prefix
);
2156 keyname
[prefix_len
] = '\\';
2157 keyname
[prefix_len
+ 1] = 'e';
2158 keyname
[prefix_len
+ 2] = '\0';
2162 keyname
= _rl_get_keyname (key
);
2165 out
= (char *)xmalloc (strlen (keyname
) + prefix_len
+ 1);
2166 strcpy (out
, prefix
);
2167 strcpy (out
+ prefix_len
, keyname
);
2173 _rl_macro_dumper_internal (print_readably
, FUNCTION_TO_KEYMAP (map
, key
), keyname
);
2181 rl_macro_dumper (print_readably
)
2184 _rl_macro_dumper_internal (print_readably
, _rl_keymap
, (char *)NULL
);
2188 rl_dump_macros (count
, key
)
2192 fprintf (rl_outstream
, "\r\n");
2193 rl_macro_dumper (rl_explicit_arg
);
2199 _rl_get_string_variable_value (name
)
2202 static char numbuf
[32];
2205 if (_rl_stricmp (name
, "bell-style") == 0)
2207 switch (_rl_bell_preference
)
2218 else if (_rl_stricmp (name
, "comment-begin") == 0)
2219 return (_rl_comment_begin
? _rl_comment_begin
: RL_COMMENT_BEGIN_DEFAULT
);
2220 else if (_rl_stricmp (name
, "completion-query-items") == 0)
2222 sprintf (numbuf
, "%d", rl_completion_query_items
);
2225 else if (_rl_stricmp (name
, "editing-mode") == 0)
2226 return (rl_get_keymap_name_from_edit_mode ());
2227 else if (_rl_stricmp (name
, "isearch-terminators") == 0)
2229 if (_rl_isearch_terminators
== 0)
2231 ret
= _rl_untranslate_macro_value (_rl_isearch_terminators
);
2234 strncpy (numbuf
, ret
, sizeof (numbuf
) - 1);
2236 numbuf
[sizeof(numbuf
) - 1] = '\0';
2242 else if (_rl_stricmp (name
, "keymap") == 0)
2244 ret
= rl_get_keymap_name (_rl_keymap
);
2246 ret
= rl_get_keymap_name_from_edit_mode ();
2247 return (ret
? ret
: "none");
2254 rl_variable_dumper (print_readably
)
2260 for (i
= 0; boolean_varlist
[i
].name
; i
++)
2263 fprintf (rl_outstream
, "set %s %s\n", boolean_varlist
[i
].name
,
2264 *boolean_varlist
[i
].value
? "on" : "off");
2266 fprintf (rl_outstream
, "%s is set to `%s'\n", boolean_varlist
[i
].name
,
2267 *boolean_varlist
[i
].value
? "on" : "off");
2270 for (i
= 0; string_varlist
[i
].name
; i
++)
2272 v
= _rl_get_string_variable_value (string_varlist
[i
].name
);
2273 if (v
== 0) /* _rl_isearch_terminators can be NULL */
2276 fprintf (rl_outstream
, "set %s %s\n", string_varlist
[i
].name
, v
);
2278 fprintf (rl_outstream
, "%s is set to `%s'\n", string_varlist
[i
].name
, v
);
2282 /* Print all of the current variables and their values to
2283 rl_outstream. If an explicit argument is given, then print
2284 the output in such a way that it can be read back in. */
2286 rl_dump_variables (count
, key
)
2290 fprintf (rl_outstream
, "\r\n");
2291 rl_variable_dumper (rl_explicit_arg
);
2296 /* Return non-zero if any members of ARRAY are a substring in STRING. */
2298 substring_member_of_array (string
, array
)
2304 if (_rl_strindex (string
, *array
))