blob: 363507b86778d8fb27b1b56b15194e61a28dd85f [file] [log] [blame]
Jari Aalto726f6381996-08-26 18:22:31 +00001/* funmap.c -- attach names to functions. */
2
Chet Ramey495aee42011-11-22 19:11:26 -05003/* Copyright (C) 1987-2010 Free Software Foundation, Inc.
Jari Aalto726f6381996-08-26 18:22:31 +00004
Jari Aalto31859422009-01-12 13:36:28 +00005 This file is part of the GNU Readline Library (Readline), a library
6 for reading lines of text with interactive input and history editing.
Jari Aalto726f6381996-08-26 18:22:31 +00007
Jari Aalto31859422009-01-12 13:36:28 +00008 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
Jari Aalto726f6381996-08-26 18:22:31 +000011 (at your option) any later version.
12
Jari Aalto31859422009-01-12 13:36:28 +000013 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
Jari Aalto726f6381996-08-26 18:22:31 +000016 GNU General Public License for more details.
17
Jari Aalto31859422009-01-12 13:36:28 +000018 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
Jari Aalto726f6381996-08-26 18:22:31 +000022#define READLINE_LIBRARY
23
Jari Aaltoccc6cda1996-12-23 17:02:34 +000024#if defined (HAVE_CONFIG_H)
25# include <config.h>
26#endif
27
Jari Aalto726f6381996-08-26 18:22:31 +000028#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
Jari Aaltobb706242000-03-17 21:46:59 +000041#include "xmalloc.h"
42
43#ifdef __STDC__
44typedef int QSFUNC (const void *, const void *);
45#else
46typedef int QSFUNC ();
47#endif
48
Jari Aaltof73dda02001-11-13 17:56:06 +000049extern int _rl_qsort_string_compare PARAMS((char **, char **));
Jari Aalto726f6381996-08-26 18:22:31 +000050
Jari Aaltoccc6cda1996-12-23 17:02:34 +000051FUNMAP **funmap;
52static int funmap_size;
53static int funmap_entry;
Jari Aalto726f6381996-08-26 18:22:31 +000054
55/* After initializing the function map, this is the index of the first
56 program specific function. */
57int funmap_program_specific_entry_start;
58
Jari Aalto31859422009-01-12 13:36:28 +000059static const FUNMAP default_funmap[] = {
Jari Aalto726f6381996-08-26 18:22:31 +000060 { "abort", rl_abort },
61 { "accept-line", rl_newline },
62 { "arrow-key-prefix", rl_arrow_keys },
Jari Aalto7117c2d2002-07-17 14:10:11 +000063 { "backward-byte", rl_backward_byte },
64 { "backward-char", rl_backward_char },
Jari Aalto726f6381996-08-26 18:22:31 +000065 { "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 { "call-last-kbd-macro", rl_call_last_kbd_macro },
72 { "capitalize-word", rl_capitalize_word },
Jari Aaltoccc6cda1996-12-23 17:02:34 +000073 { "character-search", rl_char_search },
74 { "character-search-backward", rl_backward_char_search },
Jari Aalto726f6381996-08-26 18:22:31 +000075 { "clear-screen", rl_clear_screen },
76 { "complete", rl_complete },
Jari Aaltoccc6cda1996-12-23 17:02:34 +000077 { "copy-backward-word", rl_copy_backward_word },
78 { "copy-forward-word", rl_copy_forward_word },
79 { "copy-region-as-kill", rl_copy_region_to_kill },
Jari Aalto726f6381996-08-26 18:22:31 +000080 { "delete-char", rl_delete },
Jari Aaltob72432f1999-02-19 17:11:39 +000081 { "delete-char-or-list", rl_delete_or_show_completions },
Jari Aalto726f6381996-08-26 18:22:31 +000082 { "delete-horizontal-space", rl_delete_horizontal_space },
83 { "digit-argument", rl_digit_argument },
84 { "do-lowercase-version", rl_do_lowercase_version },
85 { "downcase-word", rl_downcase_word },
86 { "dump-functions", rl_dump_functions },
Jari Aaltod166f041997-06-05 14:59:13 +000087 { "dump-macros", rl_dump_macros },
Jari Aaltoccc6cda1996-12-23 17:02:34 +000088 { "dump-variables", rl_dump_variables },
Jari Aalto726f6381996-08-26 18:22:31 +000089 { "emacs-editing-mode", rl_emacs_editing_mode },
90 { "end-kbd-macro", rl_end_kbd_macro },
91 { "end-of-history", rl_end_of_history },
92 { "end-of-line", rl_end_of_line },
Jari Aaltoccc6cda1996-12-23 17:02:34 +000093 { "exchange-point-and-mark", rl_exchange_point_and_mark },
Jari Aaltob72432f1999-02-19 17:11:39 +000094 { "forward-backward-delete-char", rl_rubout_or_delete },
Jari Aalto7117c2d2002-07-17 14:10:11 +000095 { "forward-byte", rl_forward_byte },
96 { "forward-char", rl_forward_char },
Jari Aalto726f6381996-08-26 18:22:31 +000097 { "forward-search-history", rl_forward_search_history },
98 { "forward-word", rl_forward_word },
99 { "history-search-backward", rl_history_search_backward },
100 { "history-search-forward", rl_history_search_forward },
Chet Rameyac50fba2014-02-26 09:36:43 -0500101 { "history-substring-search-backward", rl_history_substr_search_backward },
102 { "history-substring-search-forward", rl_history_substr_search_forward },
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000103 { "insert-comment", rl_insert_comment },
Jari Aalto726f6381996-08-26 18:22:31 +0000104 { "insert-completions", rl_insert_completions },
105 { "kill-whole-line", rl_kill_full_line },
106 { "kill-line", rl_kill_line },
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000107 { "kill-region", rl_kill_region },
Jari Aalto726f6381996-08-26 18:22:31 +0000108 { "kill-word", rl_kill_word },
Jari Aaltocce855b1998-04-17 19:52:44 +0000109 { "menu-complete", rl_menu_complete },
Chet Ramey00018032011-11-21 20:51:19 -0500110 { "menu-complete-backward", rl_backward_menu_complete },
Jari Aalto726f6381996-08-26 18:22:31 +0000111 { "next-history", rl_get_next_history },
112 { "non-incremental-forward-search-history", rl_noninc_forward_search },
113 { "non-incremental-reverse-search-history", rl_noninc_reverse_search },
114 { "non-incremental-forward-search-history-again", rl_noninc_forward_search_again },
115 { "non-incremental-reverse-search-history-again", rl_noninc_reverse_search_again },
Chet Ramey00018032011-11-21 20:51:19 -0500116 { "old-menu-complete", rl_old_menu_complete },
Jari Aalto7117c2d2002-07-17 14:10:11 +0000117 { "overwrite-mode", rl_overwrite_mode },
Jari Aalto28ef6c32001-04-06 19:14:31 +0000118#ifdef __CYGWIN__
Jari Aaltocce855b1998-04-17 19:52:44 +0000119 { "paste-from-clipboard", rl_paste_from_clipboard },
120#endif
Jari Aalto726f6381996-08-26 18:22:31 +0000121 { "possible-completions", rl_possible_completions },
122 { "previous-history", rl_get_previous_history },
Chet Rameyac50fba2014-02-26 09:36:43 -0500123 { "print-last-kbd-macro", rl_print_last_kbd_macro },
Jari Aalto726f6381996-08-26 18:22:31 +0000124 { "quoted-insert", rl_quoted_insert },
125 { "re-read-init-file", rl_re_read_init_file },
126 { "redraw-current-line", rl_refresh_line},
127 { "reverse-search-history", rl_reverse_search_history },
128 { "revert-line", rl_revert_line },
129 { "self-insert", rl_insert },
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000130 { "set-mark", rl_set_mark },
Chet Ramey00018032011-11-21 20:51:19 -0500131 { "skip-csi-sequence", rl_skip_csi_sequence },
Jari Aalto726f6381996-08-26 18:22:31 +0000132 { "start-kbd-macro", rl_start_kbd_macro },
133 { "tab-insert", rl_tab_insert },
134 { "tilde-expand", rl_tilde_expand },
135 { "transpose-chars", rl_transpose_chars },
136 { "transpose-words", rl_transpose_words },
137 { "tty-status", rl_tty_status },
138 { "undo", rl_undo_command },
139 { "universal-argument", rl_universal_argument },
Jari Aaltob80f6442004-07-27 13:29:18 +0000140 { "unix-filename-rubout", rl_unix_filename_rubout },
Jari Aalto726f6381996-08-26 18:22:31 +0000141 { "unix-line-discard", rl_unix_line_discard },
142 { "unix-word-rubout", rl_unix_word_rubout },
143 { "upcase-word", rl_upcase_word },
144 { "yank", rl_yank },
145 { "yank-last-arg", rl_yank_last_arg },
146 { "yank-nth-arg", rl_yank_nth_arg },
147 { "yank-pop", rl_yank_pop },
148
149#if defined (VI_MODE)
150 { "vi-append-eol", rl_vi_append_eol },
151 { "vi-append-mode", rl_vi_append_mode },
152 { "vi-arg-digit", rl_vi_arg_digit },
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000153 { "vi-back-to-indent", rl_vi_back_to_indent },
Chet Ramey495aee42011-11-22 19:11:26 -0500154 { "vi-backward-bigword", rl_vi_bWord },
155 { "vi-backward-word", rl_vi_bword },
Jari Aalto726f6381996-08-26 18:22:31 +0000156 { "vi-bWord", rl_vi_bWord },
Jari Aalto726f6381996-08-26 18:22:31 +0000157 { "vi-bword", rl_vi_bword },
158 { "vi-change-case", rl_vi_change_case },
159 { "vi-change-char", rl_vi_change_char },
160 { "vi-change-to", rl_vi_change_to },
161 { "vi-char-search", rl_vi_char_search },
162 { "vi-column", rl_vi_column },
Jari Aalto726f6381996-08-26 18:22:31 +0000163 { "vi-complete", rl_vi_complete },
164 { "vi-delete", rl_vi_delete },
165 { "vi-delete-to", rl_vi_delete_to },
166 { "vi-eWord", rl_vi_eWord },
167 { "vi-editing-mode", rl_vi_editing_mode },
Chet Ramey495aee42011-11-22 19:11:26 -0500168 { "vi-end-bigword", rl_vi_eWord },
Jari Aalto726f6381996-08-26 18:22:31 +0000169 { "vi-end-word", rl_vi_end_word },
170 { "vi-eof-maybe", rl_vi_eof_maybe },
171 { "vi-eword", rl_vi_eword },
172 { "vi-fWord", rl_vi_fWord },
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000173 { "vi-fetch-history", rl_vi_fetch_history },
Jari Aalto726f6381996-08-26 18:22:31 +0000174 { "vi-first-print", rl_vi_first_print },
Chet Ramey495aee42011-11-22 19:11:26 -0500175 { "vi-forward-bigword", rl_vi_fWord },
176 { "vi-forward-word", rl_vi_fword },
Jari Aalto726f6381996-08-26 18:22:31 +0000177 { "vi-fword", rl_vi_fword },
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000178 { "vi-goto-mark", rl_vi_goto_mark },
Jari Aalto726f6381996-08-26 18:22:31 +0000179 { "vi-insert-beg", rl_vi_insert_beg },
180 { "vi-insertion-mode", rl_vi_insertion_mode },
181 { "vi-match", rl_vi_match },
182 { "vi-movement-mode", rl_vi_movement_mode },
183 { "vi-next-word", rl_vi_next_word },
184 { "vi-overstrike", rl_vi_overstrike },
185 { "vi-overstrike-delete", rl_vi_overstrike_delete },
186 { "vi-prev-word", rl_vi_prev_word },
187 { "vi-put", rl_vi_put },
188 { "vi-redo", rl_vi_redo },
189 { "vi-replace", rl_vi_replace },
Jari Aalto95732b42005-12-07 14:08:12 +0000190 { "vi-rubout", rl_vi_rubout },
Jari Aalto726f6381996-08-26 18:22:31 +0000191 { "vi-search", rl_vi_search },
192 { "vi-search-again", rl_vi_search_again },
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000193 { "vi-set-mark", rl_vi_set_mark },
Jari Aalto726f6381996-08-26 18:22:31 +0000194 { "vi-subst", rl_vi_subst },
195 { "vi-tilde-expand", rl_vi_tilde_expand },
196 { "vi-yank-arg", rl_vi_yank_arg },
197 { "vi-yank-to", rl_vi_yank_to },
198#endif /* VI_MODE */
199
Jari Aalto28ef6c32001-04-06 19:14:31 +0000200 {(char *)NULL, (rl_command_func_t *)NULL }
Jari Aalto726f6381996-08-26 18:22:31 +0000201};
202
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000203int
Jari Aalto726f6381996-08-26 18:22:31 +0000204rl_add_funmap_entry (name, function)
Jari Aalto28ef6c32001-04-06 19:14:31 +0000205 const char *name;
206 rl_command_func_t *function;
Jari Aalto726f6381996-08-26 18:22:31 +0000207{
208 if (funmap_entry + 2 >= funmap_size)
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000209 {
210 funmap_size += 64;
211 funmap = (FUNMAP **)xrealloc (funmap, funmap_size * sizeof (FUNMAP *));
212 }
Jari Aalto726f6381996-08-26 18:22:31 +0000213
214 funmap[funmap_entry] = (FUNMAP *)xmalloc (sizeof (FUNMAP));
215 funmap[funmap_entry]->name = name;
216 funmap[funmap_entry]->function = function;
217
218 funmap[++funmap_entry] = (FUNMAP *)NULL;
219 return funmap_entry;
220}
221
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000222static int funmap_initialized;
Jari Aalto726f6381996-08-26 18:22:31 +0000223
224/* Make the funmap contain all of the default entries. */
225void
226rl_initialize_funmap ()
227{
228 register int i;
229
230 if (funmap_initialized)
231 return;
232
233 for (i = 0; default_funmap[i].name; i++)
234 rl_add_funmap_entry (default_funmap[i].name, default_funmap[i].function);
235
236 funmap_initialized = 1;
237 funmap_program_specific_entry_start = i;
238}
239
240/* Produce a NULL terminated array of known function names. The array
241 is sorted. The array itself is allocated, but not the strings inside.
Chet Rameyac50fba2014-02-26 09:36:43 -0500242 You should free () the array when you done, but not the pointers. */
Jari Aalto28ef6c32001-04-06 19:14:31 +0000243const char **
Jari Aalto726f6381996-08-26 18:22:31 +0000244rl_funmap_names ()
245{
Jari Aalto28ef6c32001-04-06 19:14:31 +0000246 const char **result;
Jari Aalto726f6381996-08-26 18:22:31 +0000247 int result_size, result_index;
248
Jari Aalto726f6381996-08-26 18:22:31 +0000249 /* Make sure that the function map has been initialized. */
250 rl_initialize_funmap ();
251
Jari Aalto28ef6c32001-04-06 19:14:31 +0000252 for (result_index = result_size = 0, result = (const char **)NULL; funmap[result_index]; result_index++)
Jari Aalto726f6381996-08-26 18:22:31 +0000253 {
254 if (result_index + 2 > result_size)
255 {
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000256 result_size += 20;
Jari Aalto28ef6c32001-04-06 19:14:31 +0000257 result = (const char **)xrealloc (result, result_size * sizeof (char *));
Jari Aalto726f6381996-08-26 18:22:31 +0000258 }
259
260 result[result_index] = funmap[result_index]->name;
261 result[result_index + 1] = (char *)NULL;
262 }
263
Jari Aaltobb706242000-03-17 21:46:59 +0000264 qsort (result, result_index, sizeof (char *), (QSFUNC *)_rl_qsort_string_compare);
Jari Aalto726f6381996-08-26 18:22:31 +0000265 return (result);
266}