Import GNU Readline 8.1
[deliverable/binutils-gdb.git] / readline / readline / funmap.c
CommitLineData
d60d9f65
SS
1/* funmap.c -- attach names to functions. */
2
b4f26d54 3/* Copyright (C) 1987-2020 Free Software Foundation, Inc.
d60d9f65 4
cc88a640
JK
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.
d60d9f65 7
cc88a640
JK
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
d60d9f65
SS
11 (at your option) any later version.
12
cc88a640
JK
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
d60d9f65
SS
16 GNU General Public License for more details.
17
cc88a640
JK
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/>.
20*/
21
d60d9f65
SS
22#define READLINE_LIBRARY
23
24#if defined (HAVE_CONFIG_H)
25# include <config.h>
26#endif
27
d60d9f65
SS
28#if !defined (BUFSIZ)
29#include <stdio.h>
30#endif /* BUFSIZ */
31
32#if defined (HAVE_STDLIB_H)
33# include <stdlib.h>
34#else
35# include "ansi_stdlib.h"
36#endif /* HAVE_STDLIB_H */
37
38#include "rlconf.h"
39#include "readline.h"
40
1b17e766
EZ
41#include "xmalloc.h"
42
43#ifdef __STDC__
44typedef int QSFUNC (const void *, const void *);
45#else
46typedef int QSFUNC ();
47#endif
48
9255ee31 49extern int _rl_qsort_string_compare PARAMS((char **, char **));
d60d9f65
SS
50
51FUNMAP **funmap;
52static int funmap_size;
53static int funmap_entry;
54
55/* After initializing the function map, this is the index of the first
56 program specific function. */
57int funmap_program_specific_entry_start;
58
cc88a640 59static const FUNMAP default_funmap[] = {
d60d9f65
SS
60 { "abort", rl_abort },
61 { "accept-line", rl_newline },
62 { "arrow-key-prefix", rl_arrow_keys },
9255ee31
EZ
63 { "backward-byte", rl_backward_byte },
64 { "backward-char", rl_backward_char },
d60d9f65
SS
65 { "backward-delete-char", rl_rubout },
66 { "backward-kill-line", rl_backward_kill_line },
67 { "backward-kill-word", rl_backward_kill_word },
68 { "backward-word", rl_backward_word },
69 { "beginning-of-history", rl_beginning_of_history },
70 { "beginning-of-line", rl_beg_of_line },
775e241e 71 { "bracketed-paste-begin", rl_bracketed_paste_begin },
d60d9f65
SS
72 { "call-last-kbd-macro", rl_call_last_kbd_macro },
73 { "capitalize-word", rl_capitalize_word },
74 { "character-search", rl_char_search },
75 { "character-search-backward", rl_backward_char_search },
b4f26d54 76 { "clear-display", rl_clear_display },
d60d9f65
SS
77 { "clear-screen", rl_clear_screen },
78 { "complete", rl_complete },
79 { "copy-backward-word", rl_copy_backward_word },
80 { "copy-forward-word", rl_copy_forward_word },
81 { "copy-region-as-kill", rl_copy_region_to_kill },
82 { "delete-char", rl_delete },
c862e87b 83 { "delete-char-or-list", rl_delete_or_show_completions },
d60d9f65
SS
84 { "delete-horizontal-space", rl_delete_horizontal_space },
85 { "digit-argument", rl_digit_argument },
86 { "do-lowercase-version", rl_do_lowercase_version },
87 { "downcase-word", rl_downcase_word },
88 { "dump-functions", rl_dump_functions },
89 { "dump-macros", rl_dump_macros },
90 { "dump-variables", rl_dump_variables },
91 { "emacs-editing-mode", rl_emacs_editing_mode },
92 { "end-kbd-macro", rl_end_kbd_macro },
93 { "end-of-history", rl_end_of_history },
94 { "end-of-line", rl_end_of_line },
95 { "exchange-point-and-mark", rl_exchange_point_and_mark },
c862e87b 96 { "forward-backward-delete-char", rl_rubout_or_delete },
9255ee31
EZ
97 { "forward-byte", rl_forward_byte },
98 { "forward-char", rl_forward_char },
d60d9f65
SS
99 { "forward-search-history", rl_forward_search_history },
100 { "forward-word", rl_forward_word },
101 { "history-search-backward", rl_history_search_backward },
102 { "history-search-forward", rl_history_search_forward },
775e241e
TT
103 { "history-substring-search-backward", rl_history_substr_search_backward },
104 { "history-substring-search-forward", rl_history_substr_search_forward },
d60d9f65
SS
105 { "insert-comment", rl_insert_comment },
106 { "insert-completions", rl_insert_completions },
107 { "kill-whole-line", rl_kill_full_line },
108 { "kill-line", rl_kill_line },
109 { "kill-region", rl_kill_region },
110 { "kill-word", rl_kill_word },
111 { "menu-complete", rl_menu_complete },
cc88a640 112 { "menu-complete-backward", rl_backward_menu_complete },
d60d9f65 113 { "next-history", rl_get_next_history },
cb41b9e7 114 { "next-screen-line", rl_next_screen_line },
d60d9f65
SS
115 { "non-incremental-forward-search-history", rl_noninc_forward_search },
116 { "non-incremental-reverse-search-history", rl_noninc_reverse_search },
117 { "non-incremental-forward-search-history-again", rl_noninc_forward_search_again },
118 { "non-incremental-reverse-search-history-again", rl_noninc_reverse_search_again },
cc88a640 119 { "old-menu-complete", rl_old_menu_complete },
b4f26d54 120 { "operate-and-get-next", rl_operate_and_get_next },
9255ee31 121 { "overwrite-mode", rl_overwrite_mode },
775e241e 122#if defined (_WIN32)
d60d9f65
SS
123 { "paste-from-clipboard", rl_paste_from_clipboard },
124#endif
125 { "possible-completions", rl_possible_completions },
126 { "previous-history", rl_get_previous_history },
cb41b9e7 127 { "previous-screen-line", rl_previous_screen_line },
775e241e 128 { "print-last-kbd-macro", rl_print_last_kbd_macro },
d60d9f65
SS
129 { "quoted-insert", rl_quoted_insert },
130 { "re-read-init-file", rl_re_read_init_file },
131 { "redraw-current-line", rl_refresh_line},
132 { "reverse-search-history", rl_reverse_search_history },
133 { "revert-line", rl_revert_line },
134 { "self-insert", rl_insert },
135 { "set-mark", rl_set_mark },
cc88a640 136 { "skip-csi-sequence", rl_skip_csi_sequence },
d60d9f65
SS
137 { "start-kbd-macro", rl_start_kbd_macro },
138 { "tab-insert", rl_tab_insert },
139 { "tilde-expand", rl_tilde_expand },
140 { "transpose-chars", rl_transpose_chars },
141 { "transpose-words", rl_transpose_words },
142 { "tty-status", rl_tty_status },
143 { "undo", rl_undo_command },
144 { "universal-argument", rl_universal_argument },
5bdf8622 145 { "unix-filename-rubout", rl_unix_filename_rubout },
d60d9f65
SS
146 { "unix-line-discard", rl_unix_line_discard },
147 { "unix-word-rubout", rl_unix_word_rubout },
148 { "upcase-word", rl_upcase_word },
149 { "yank", rl_yank },
150 { "yank-last-arg", rl_yank_last_arg },
151 { "yank-nth-arg", rl_yank_nth_arg },
152 { "yank-pop", rl_yank_pop },
153
154#if defined (VI_MODE)
155 { "vi-append-eol", rl_vi_append_eol },
156 { "vi-append-mode", rl_vi_append_mode },
157 { "vi-arg-digit", rl_vi_arg_digit },
158 { "vi-back-to-indent", rl_vi_back_to_indent },
cc88a640
JK
159 { "vi-backward-bigword", rl_vi_bWord },
160 { "vi-backward-word", rl_vi_bword },
d60d9f65 161 { "vi-bWord", rl_vi_bWord },
b4f26d54 162 { "vi-bword", rl_vi_bword }, /* BEWARE: name matching is case insensitive */
d60d9f65
SS
163 { "vi-change-case", rl_vi_change_case },
164 { "vi-change-char", rl_vi_change_char },
165 { "vi-change-to", rl_vi_change_to },
166 { "vi-char-search", rl_vi_char_search },
167 { "vi-column", rl_vi_column },
168 { "vi-complete", rl_vi_complete },
169 { "vi-delete", rl_vi_delete },
170 { "vi-delete-to", rl_vi_delete_to },
171 { "vi-eWord", rl_vi_eWord },
172 { "vi-editing-mode", rl_vi_editing_mode },
cc88a640 173 { "vi-end-bigword", rl_vi_eWord },
d60d9f65
SS
174 { "vi-end-word", rl_vi_end_word },
175 { "vi-eof-maybe", rl_vi_eof_maybe },
b4f26d54 176 { "vi-eword", rl_vi_eword }, /* BEWARE: name matching is case insensitive */
d60d9f65
SS
177 { "vi-fWord", rl_vi_fWord },
178 { "vi-fetch-history", rl_vi_fetch_history },
179 { "vi-first-print", rl_vi_first_print },
cc88a640
JK
180 { "vi-forward-bigword", rl_vi_fWord },
181 { "vi-forward-word", rl_vi_fword },
b4f26d54 182 { "vi-fword", rl_vi_fword }, /* BEWARE: name matching is case insensitive */
d60d9f65
SS
183 { "vi-goto-mark", rl_vi_goto_mark },
184 { "vi-insert-beg", rl_vi_insert_beg },
775e241e 185 { "vi-insertion-mode", rl_vi_insert_mode },
d60d9f65
SS
186 { "vi-match", rl_vi_match },
187 { "vi-movement-mode", rl_vi_movement_mode },
188 { "vi-next-word", rl_vi_next_word },
189 { "vi-overstrike", rl_vi_overstrike },
190 { "vi-overstrike-delete", rl_vi_overstrike_delete },
191 { "vi-prev-word", rl_vi_prev_word },
192 { "vi-put", rl_vi_put },
193 { "vi-redo", rl_vi_redo },
194 { "vi-replace", rl_vi_replace },
5bdf8622 195 { "vi-rubout", rl_vi_rubout },
d60d9f65
SS
196 { "vi-search", rl_vi_search },
197 { "vi-search-again", rl_vi_search_again },
198 { "vi-set-mark", rl_vi_set_mark },
199 { "vi-subst", rl_vi_subst },
200 { "vi-tilde-expand", rl_vi_tilde_expand },
775e241e 201 { "vi-unix-word-rubout", rl_vi_unix_word_rubout },
d60d9f65 202 { "vi-yank-arg", rl_vi_yank_arg },
775e241e 203 { "vi-yank-pop", rl_vi_yank_pop },
d60d9f65
SS
204 { "vi-yank-to", rl_vi_yank_to },
205#endif /* VI_MODE */
206
9255ee31 207 {(char *)NULL, (rl_command_func_t *)NULL }
d60d9f65
SS
208};
209
210int
cb41b9e7 211rl_add_funmap_entry (const char *name, rl_command_func_t *function)
d60d9f65
SS
212{
213 if (funmap_entry + 2 >= funmap_size)
214 {
215 funmap_size += 64;
216 funmap = (FUNMAP **)xrealloc (funmap, funmap_size * sizeof (FUNMAP *));
217 }
218
219 funmap[funmap_entry] = (FUNMAP *)xmalloc (sizeof (FUNMAP));
220 funmap[funmap_entry]->name = name;
221 funmap[funmap_entry]->function = function;
222
223 funmap[++funmap_entry] = (FUNMAP *)NULL;
224 return funmap_entry;
225}
226
227static int funmap_initialized;
228
229/* Make the funmap contain all of the default entries. */
230void
cb41b9e7 231rl_initialize_funmap (void)
d60d9f65
SS
232{
233 register int i;
234
235 if (funmap_initialized)
236 return;
237
238 for (i = 0; default_funmap[i].name; i++)
239 rl_add_funmap_entry (default_funmap[i].name, default_funmap[i].function);
240
241 funmap_initialized = 1;
242 funmap_program_specific_entry_start = i;
243}
244
245/* Produce a NULL terminated array of known function names. The array
246 is sorted. The array itself is allocated, but not the strings inside.
775e241e 247 You should free () the array when you done, but not the pointers. */
9255ee31 248const char **
cb41b9e7 249rl_funmap_names (void)
d60d9f65 250{
9255ee31 251 const char **result;
d60d9f65
SS
252 int result_size, result_index;
253
254 /* Make sure that the function map has been initialized. */
255 rl_initialize_funmap ();
256
9255ee31 257 for (result_index = result_size = 0, result = (const char **)NULL; funmap[result_index]; result_index++)
d60d9f65
SS
258 {
259 if (result_index + 2 > result_size)
260 {
261 result_size += 20;
9255ee31 262 result = (const char **)xrealloc (result, result_size * sizeof (char *));
d60d9f65
SS
263 }
264
265 result[result_index] = funmap[result_index]->name;
266 result[result_index + 1] = (char *)NULL;
267 }
268
1b17e766 269 qsort (result, result_index, sizeof (char *), (QSFUNC *)_rl_qsort_string_compare);
d60d9f65
SS
270 return (result);
271}
This page took 0.897668 seconds and 4 git commands to generate.