]> git.ipfire.org Git - thirdparty/bash.git/blame - lib/readline/funmap.c
commit bash-20090723 snapshot
[thirdparty/bash.git] / lib / readline / funmap.c
CommitLineData
726f6388
JA
1/* funmap.c -- attach names to functions. */
2
012bac39 3/* Copyright (C) 1987-2009 Free Software Foundation, Inc.
726f6388 4
2e4498b3
CR
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.
726f6388 7
2e4498b3
CR
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
726f6388
JA
11 (at your option) any later version.
12
2e4498b3
CR
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
726f6388
JA
16 GNU General Public License for more details.
17
2e4498b3
CR
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
726f6388
JA
22#define READLINE_LIBRARY
23
ccc6cda3
JA
24#if defined (HAVE_CONFIG_H)
25# include <config.h>
26#endif
27
726f6388
JA
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
bb70624e
JA
41#include "xmalloc.h"
42
43#ifdef __STDC__
44typedef int QSFUNC (const void *, const void *);
45#else
46typedef int QSFUNC ();
47#endif
48
f73dda09 49extern int _rl_qsort_string_compare PARAMS((char **, char **));
726f6388 50
ccc6cda3
JA
51FUNMAP **funmap;
52static int funmap_size;
53static int funmap_entry;
726f6388
JA
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
d3ad40de 59static const FUNMAP default_funmap[] = {
726f6388
JA
60 { "abort", rl_abort },
61 { "accept-line", rl_newline },
62 { "arrow-key-prefix", rl_arrow_keys },
7117c2d2
JA
63 { "backward-byte", rl_backward_byte },
64 { "backward-char", rl_backward_char },
726f6388
JA
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 { "call-last-kbd-macro", rl_call_last_kbd_macro },
72 { "capitalize-word", rl_capitalize_word },
ccc6cda3
JA
73 { "character-search", rl_char_search },
74 { "character-search-backward", rl_backward_char_search },
726f6388
JA
75 { "clear-screen", rl_clear_screen },
76 { "complete", rl_complete },
ccc6cda3
JA
77 { "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 },
726f6388 80 { "delete-char", rl_delete },
b72432fd 81 { "delete-char-or-list", rl_delete_or_show_completions },
726f6388
JA
82 { "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 },
d166f048 87 { "dump-macros", rl_dump_macros },
ccc6cda3 88 { "dump-variables", rl_dump_variables },
726f6388
JA
89 { "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 },
ccc6cda3 93 { "exchange-point-and-mark", rl_exchange_point_and_mark },
b72432fd 94 { "forward-backward-delete-char", rl_rubout_or_delete },
7117c2d2
JA
95 { "forward-byte", rl_forward_byte },
96 { "forward-char", rl_forward_char },
726f6388
JA
97 { "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 },
ccc6cda3 101 { "insert-comment", rl_insert_comment },
726f6388
JA
102 { "insert-completions", rl_insert_completions },
103 { "kill-whole-line", rl_kill_full_line },
104 { "kill-line", rl_kill_line },
ccc6cda3 105 { "kill-region", rl_kill_region },
726f6388 106 { "kill-word", rl_kill_word },
cce855bc 107 { "menu-complete", rl_menu_complete },
726f6388
JA
108 { "next-history", rl_get_next_history },
109 { "non-incremental-forward-search-history", rl_noninc_forward_search },
110 { "non-incremental-reverse-search-history", rl_noninc_reverse_search },
111 { "non-incremental-forward-search-history-again", rl_noninc_forward_search_again },
112 { "non-incremental-reverse-search-history-again", rl_noninc_reverse_search_again },
7117c2d2 113 { "overwrite-mode", rl_overwrite_mode },
28ef6c31 114#ifdef __CYGWIN__
cce855bc
JA
115 { "paste-from-clipboard", rl_paste_from_clipboard },
116#endif
726f6388
JA
117 { "possible-completions", rl_possible_completions },
118 { "previous-history", rl_get_previous_history },
119 { "quoted-insert", rl_quoted_insert },
120 { "re-read-init-file", rl_re_read_init_file },
121 { "redraw-current-line", rl_refresh_line},
122 { "reverse-search-history", rl_reverse_search_history },
123 { "revert-line", rl_revert_line },
124 { "self-insert", rl_insert },
ccc6cda3 125 { "set-mark", rl_set_mark },
726f6388
JA
126 { "start-kbd-macro", rl_start_kbd_macro },
127 { "tab-insert", rl_tab_insert },
128 { "tilde-expand", rl_tilde_expand },
129 { "transpose-chars", rl_transpose_chars },
130 { "transpose-words", rl_transpose_words },
131 { "tty-status", rl_tty_status },
132 { "undo", rl_undo_command },
133 { "universal-argument", rl_universal_argument },
113d85a4 134 { "unix-filename-rubout", rl_unix_filename_rubout },
726f6388
JA
135 { "unix-line-discard", rl_unix_line_discard },
136 { "unix-word-rubout", rl_unix_word_rubout },
137 { "upcase-word", rl_upcase_word },
138 { "yank", rl_yank },
139 { "yank-last-arg", rl_yank_last_arg },
140 { "yank-nth-arg", rl_yank_nth_arg },
141 { "yank-pop", rl_yank_pop },
142
143#if defined (VI_MODE)
144 { "vi-append-eol", rl_vi_append_eol },
145 { "vi-append-mode", rl_vi_append_mode },
146 { "vi-arg-digit", rl_vi_arg_digit },
ccc6cda3 147 { "vi-back-to-indent", rl_vi_back_to_indent },
726f6388 148 { "vi-bWord", rl_vi_bWord },
726f6388
JA
149 { "vi-bword", rl_vi_bword },
150 { "vi-change-case", rl_vi_change_case },
151 { "vi-change-char", rl_vi_change_char },
152 { "vi-change-to", rl_vi_change_to },
153 { "vi-char-search", rl_vi_char_search },
154 { "vi-column", rl_vi_column },
726f6388
JA
155 { "vi-complete", rl_vi_complete },
156 { "vi-delete", rl_vi_delete },
157 { "vi-delete-to", rl_vi_delete_to },
158 { "vi-eWord", rl_vi_eWord },
159 { "vi-editing-mode", rl_vi_editing_mode },
160 { "vi-end-word", rl_vi_end_word },
161 { "vi-eof-maybe", rl_vi_eof_maybe },
162 { "vi-eword", rl_vi_eword },
163 { "vi-fWord", rl_vi_fWord },
ccc6cda3 164 { "vi-fetch-history", rl_vi_fetch_history },
726f6388
JA
165 { "vi-first-print", rl_vi_first_print },
166 { "vi-fword", rl_vi_fword },
ccc6cda3 167 { "vi-goto-mark", rl_vi_goto_mark },
726f6388
JA
168 { "vi-insert-beg", rl_vi_insert_beg },
169 { "vi-insertion-mode", rl_vi_insertion_mode },
170 { "vi-match", rl_vi_match },
171 { "vi-movement-mode", rl_vi_movement_mode },
172 { "vi-next-word", rl_vi_next_word },
173 { "vi-overstrike", rl_vi_overstrike },
174 { "vi-overstrike-delete", rl_vi_overstrike_delete },
175 { "vi-prev-word", rl_vi_prev_word },
176 { "vi-put", rl_vi_put },
177 { "vi-redo", rl_vi_redo },
178 { "vi-replace", rl_vi_replace },
a82a04b3 179 { "vi-rubout", rl_vi_rubout },
726f6388
JA
180 { "vi-search", rl_vi_search },
181 { "vi-search-again", rl_vi_search_again },
ccc6cda3 182 { "vi-set-mark", rl_vi_set_mark },
726f6388
JA
183 { "vi-subst", rl_vi_subst },
184 { "vi-tilde-expand", rl_vi_tilde_expand },
185 { "vi-yank-arg", rl_vi_yank_arg },
186 { "vi-yank-to", rl_vi_yank_to },
187#endif /* VI_MODE */
188
28ef6c31 189 {(char *)NULL, (rl_command_func_t *)NULL }
726f6388
JA
190};
191
ccc6cda3 192int
726f6388 193rl_add_funmap_entry (name, function)
28ef6c31
JA
194 const char *name;
195 rl_command_func_t *function;
726f6388
JA
196{
197 if (funmap_entry + 2 >= funmap_size)
ccc6cda3
JA
198 {
199 funmap_size += 64;
200 funmap = (FUNMAP **)xrealloc (funmap, funmap_size * sizeof (FUNMAP *));
201 }
726f6388
JA
202
203 funmap[funmap_entry] = (FUNMAP *)xmalloc (sizeof (FUNMAP));
204 funmap[funmap_entry]->name = name;
205 funmap[funmap_entry]->function = function;
206
207 funmap[++funmap_entry] = (FUNMAP *)NULL;
208 return funmap_entry;
209}
210
ccc6cda3 211static int funmap_initialized;
726f6388
JA
212
213/* Make the funmap contain all of the default entries. */
214void
215rl_initialize_funmap ()
216{
217 register int i;
218
219 if (funmap_initialized)
220 return;
221
222 for (i = 0; default_funmap[i].name; i++)
223 rl_add_funmap_entry (default_funmap[i].name, default_funmap[i].function);
224
225 funmap_initialized = 1;
226 funmap_program_specific_entry_start = i;
227}
228
229/* Produce a NULL terminated array of known function names. The array
230 is sorted. The array itself is allocated, but not the strings inside.
231 You should free () the array when you done, but not the pointrs. */
28ef6c31 232const char **
726f6388
JA
233rl_funmap_names ()
234{
28ef6c31 235 const char **result;
726f6388
JA
236 int result_size, result_index;
237
726f6388
JA
238 /* Make sure that the function map has been initialized. */
239 rl_initialize_funmap ();
240
28ef6c31 241 for (result_index = result_size = 0, result = (const char **)NULL; funmap[result_index]; result_index++)
726f6388
JA
242 {
243 if (result_index + 2 > result_size)
244 {
ccc6cda3 245 result_size += 20;
28ef6c31 246 result = (const char **)xrealloc (result, result_size * sizeof (char *));
726f6388
JA
247 }
248
249 result[result_index] = funmap[result_index]->name;
250 result[result_index + 1] = (char *)NULL;
251 }
252
bb70624e 253 qsort (result, result_index, sizeof (char *), (QSFUNC *)_rl_qsort_string_compare);
726f6388
JA
254 return (result);
255}