1 /* funmap.c -- attach names to functions. */
3 /* Copyright (C) 1987-2016 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 (HAVE_CONFIG_H)
32 #if defined (HAVE_STDLIB_H)
35 # include "ansi_stdlib.h"
36 #endif /* HAVE_STDLIB_H */
44 typedef int QSFUNC (const void *, const void *);
46 typedef int QSFUNC ();
49 extern int _rl_qsort_string_compare PARAMS((char **, char **));
52 static int funmap_size;
53 static int funmap_entry;
55 /* After initializing the function map, this is the index of the first
56 program specific function. */
57 int funmap_program_specific_entry_start;
59 static const FUNMAP default_funmap[] = {
60 { "abort", rl_abort },
61 { "accept-line", rl_newline },
62 { "arrow-key-prefix", rl_arrow_keys },
63 { "backward-byte", rl_backward_byte },
64 { "backward-char", rl_backward_char },
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 },
71 { "bracketed-paste-begin", rl_bracketed_paste_begin },
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 },
76 { "clear-screen", rl_clear_screen },
77 { "complete", rl_complete },
78 { "copy-backward-word", rl_copy_backward_word },
79 { "copy-forward-word", rl_copy_forward_word },
80 { "copy-region-as-kill", rl_copy_region_to_kill },
81 { "delete-char", rl_delete },
82 { "delete-char-or-list", rl_delete_or_show_completions },
83 { "delete-horizontal-space", rl_delete_horizontal_space },
84 { "digit-argument", rl_digit_argument },
85 { "do-lowercase-version", rl_do_lowercase_version },
86 { "downcase-word", rl_downcase_word },
87 { "dump-functions", rl_dump_functions },
88 { "dump-macros", rl_dump_macros },
89 { "dump-variables", rl_dump_variables },
90 { "emacs-editing-mode", rl_emacs_editing_mode },
91 { "end-kbd-macro", rl_end_kbd_macro },
92 { "end-of-history", rl_end_of_history },
93 { "end-of-line", rl_end_of_line },
94 { "exchange-point-and-mark", rl_exchange_point_and_mark },
95 { "forward-backward-delete-char", rl_rubout_or_delete },
96 { "forward-byte", rl_forward_byte },
97 { "forward-char", rl_forward_char },
98 { "forward-search-history", rl_forward_search_history },
99 { "forward-word", rl_forward_word },
100 { "history-search-backward", rl_history_search_backward },
101 { "history-search-forward", rl_history_search_forward },
102 { "history-substring-search-backward", rl_history_substr_search_backward },
103 { "history-substring-search-forward", rl_history_substr_search_forward },
104 { "insert-comment", rl_insert_comment },
105 { "insert-completions", rl_insert_completions },
106 { "kill-whole-line", rl_kill_full_line },
107 { "kill-line", rl_kill_line },
108 { "kill-region", rl_kill_region },
109 { "kill-word", rl_kill_word },
110 { "menu-complete", rl_menu_complete },
111 { "menu-complete-backward", rl_backward_menu_complete },
112 { "next-history", rl_get_next_history },
113 { "non-incremental-forward-search-history", rl_noninc_forward_search },
114 { "non-incremental-reverse-search-history", rl_noninc_reverse_search },
115 { "non-incremental-forward-search-history-again", rl_noninc_forward_search_again },
116 { "non-incremental-reverse-search-history-again", rl_noninc_reverse_search_again },
117 { "old-menu-complete", rl_old_menu_complete },
118 { "overwrite-mode", rl_overwrite_mode },
120 { "paste-from-clipboard", rl_paste_from_clipboard },
122 { "possible-completions", rl_possible_completions },
123 { "previous-history", rl_get_previous_history },
124 { "print-last-kbd-macro", rl_print_last_kbd_macro },
125 { "quoted-insert", rl_quoted_insert },
126 { "re-read-init-file", rl_re_read_init_file },
127 { "redraw-current-line", rl_refresh_line},
128 { "reverse-search-history", rl_reverse_search_history },
129 { "revert-line", rl_revert_line },
130 { "self-insert", rl_insert },
131 { "set-mark", rl_set_mark },
132 { "skip-csi-sequence", rl_skip_csi_sequence },
133 { "start-kbd-macro", rl_start_kbd_macro },
134 { "tab-insert", rl_tab_insert },
135 { "tilde-expand", rl_tilde_expand },
136 { "transpose-chars", rl_transpose_chars },
137 { "transpose-words", rl_transpose_words },
138 { "tty-status", rl_tty_status },
139 { "undo", rl_undo_command },
140 { "universal-argument", rl_universal_argument },
141 { "unix-filename-rubout", rl_unix_filename_rubout },
142 { "unix-line-discard", rl_unix_line_discard },
143 { "unix-word-rubout", rl_unix_word_rubout },
144 { "upcase-word", rl_upcase_word },
146 { "yank-last-arg", rl_yank_last_arg },
147 { "yank-nth-arg", rl_yank_nth_arg },
148 { "yank-pop", rl_yank_pop },
150 #if defined (VI_MODE)
151 { "vi-append-eol", rl_vi_append_eol },
152 { "vi-append-mode", rl_vi_append_mode },
153 { "vi-arg-digit", rl_vi_arg_digit },
154 { "vi-back-to-indent", rl_vi_back_to_indent },
155 { "vi-backward-bigword", rl_vi_bWord },
156 { "vi-backward-word", rl_vi_bword },
157 { "vi-bWord", rl_vi_bWord },
158 { "vi-bword", rl_vi_bword },
159 { "vi-change-case", rl_vi_change_case },
160 { "vi-change-char", rl_vi_change_char },
161 { "vi-change-to", rl_vi_change_to },
162 { "vi-char-search", rl_vi_char_search },
163 { "vi-column", rl_vi_column },
164 { "vi-complete", rl_vi_complete },
165 { "vi-delete", rl_vi_delete },
166 { "vi-delete-to", rl_vi_delete_to },
167 { "vi-eWord", rl_vi_eWord },
168 { "vi-editing-mode", rl_vi_editing_mode },
169 { "vi-end-bigword", rl_vi_eWord },
170 { "vi-end-word", rl_vi_end_word },
171 { "vi-eof-maybe", rl_vi_eof_maybe },
172 { "vi-eword", rl_vi_eword },
173 { "vi-fWord", rl_vi_fWord },
174 { "vi-fetch-history", rl_vi_fetch_history },
175 { "vi-first-print", rl_vi_first_print },
176 { "vi-forward-bigword", rl_vi_fWord },
177 { "vi-forward-word", rl_vi_fword },
178 { "vi-fword", rl_vi_fword },
179 { "vi-goto-mark", rl_vi_goto_mark },
180 { "vi-insert-beg", rl_vi_insert_beg },
181 { "vi-insertion-mode", rl_vi_insert_mode },
182 { "vi-match", rl_vi_match },
183 { "vi-movement-mode", rl_vi_movement_mode },
184 { "vi-next-word", rl_vi_next_word },
185 { "vi-overstrike", rl_vi_overstrike },
186 { "vi-overstrike-delete", rl_vi_overstrike_delete },
187 { "vi-prev-word", rl_vi_prev_word },
188 { "vi-put", rl_vi_put },
189 { "vi-redo", rl_vi_redo },
190 { "vi-replace", rl_vi_replace },
191 { "vi-rubout", rl_vi_rubout },
192 { "vi-search", rl_vi_search },
193 { "vi-search-again", rl_vi_search_again },
194 { "vi-set-mark", rl_vi_set_mark },
195 { "vi-subst", rl_vi_subst },
196 { "vi-tilde-expand", rl_vi_tilde_expand },
197 { "vi-unix-word-rubout", rl_vi_unix_word_rubout },
198 { "vi-yank-arg", rl_vi_yank_arg },
199 { "vi-yank-pop", rl_vi_yank_pop },
200 { "vi-yank-to", rl_vi_yank_to },
203 {(char *)NULL, (rl_command_func_t *)NULL }
207 rl_add_funmap_entry (name, function)
209 rl_command_func_t *function;
211 if (funmap_entry + 2 >= funmap_size)
214 funmap = (FUNMAP **)xrealloc (funmap, funmap_size * sizeof (FUNMAP *));
217 funmap[funmap_entry] = (FUNMAP *)xmalloc (sizeof (FUNMAP));
218 funmap[funmap_entry]->name = name;
219 funmap[funmap_entry]->function = function;
221 funmap[++funmap_entry] = (FUNMAP *)NULL;
225 static int funmap_initialized;
227 /* Make the funmap contain all of the default entries. */
229 rl_initialize_funmap ()
233 if (funmap_initialized)
236 for (i = 0; default_funmap[i].name; i++)
237 rl_add_funmap_entry (default_funmap[i].name, default_funmap[i].function);
239 funmap_initialized = 1;
240 funmap_program_specific_entry_start = i;
243 /* Produce a NULL terminated array of known function names. The array
244 is sorted. The array itself is allocated, but not the strings inside.
245 You should free () the array when you done, but not the pointers. */
250 int result_size, result_index;
252 /* Make sure that the function map has been initialized. */
253 rl_initialize_funmap ();
255 for (result_index = result_size = 0, result = (const char **)NULL; funmap[result_index]; result_index++)
257 if (result_index + 2 > result_size)
260 result = (const char **)xrealloc (result, result_size * sizeof (char *));
263 result[result_index] = funmap[result_index]->name;
264 result[result_index + 1] = (char *)NULL;
267 qsort (result, result_index, sizeof (char *), (QSFUNC *)_rl_qsort_string_compare);