clarify that the import contains local changes as well.
[deliverable/binutils-gdb.git] / readline / funmap.c
1 /* funmap.c -- attach names to functions. */
2
3 /* Copyright (C) 1987, 1989, 1992 Free Software Foundation, Inc.
4
5 This file is part of the GNU Readline Library, a library for
6 reading lines of text with interactive input and history editing.
7
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.
12
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.
17
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. */
22 #define READLINE_LIBRARY
23
24 #if defined (HAVE_CONFIG_H)
25 # include <config.h>
26 #endif
27
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
41 #include "xmalloc.h"
42
43 #ifdef __STDC__
44 typedef int QSFUNC (const void *, const void *);
45 #else
46 typedef int QSFUNC ();
47 #endif
48
49 extern int _rl_qsort_string_compare PARAMS((char **, char **));
50
51 FUNMAP **funmap;
52 static int funmap_size;
53 static int funmap_entry;
54
55 /* After initializing the function map, this is the index of the first
56 program specific function. */
57 int funmap_program_specific_entry_start;
58
59 static 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 { "call-last-kbd-macro", rl_call_last_kbd_macro },
72 { "capitalize-word", rl_capitalize_word },
73 { "character-search", rl_char_search },
74 { "character-search-backward", rl_backward_char_search },
75 { "clear-screen", rl_clear_screen },
76 { "complete", rl_complete },
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 },
80 { "delete-char", rl_delete },
81 { "delete-char-or-list", rl_delete_or_show_completions },
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 },
87 { "dump-macros", rl_dump_macros },
88 { "dump-variables", rl_dump_variables },
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 },
93 { "exchange-point-and-mark", rl_exchange_point_and_mark },
94 { "forward-backward-delete-char", rl_rubout_or_delete },
95 { "forward-byte", rl_forward_byte },
96 { "forward-char", rl_forward_char },
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 },
101 { "insert-comment", rl_insert_comment },
102 { "insert-completions", rl_insert_completions },
103 { "kill-whole-line", rl_kill_full_line },
104 { "kill-line", rl_kill_line },
105 { "kill-region", rl_kill_region },
106 { "kill-word", rl_kill_word },
107 { "menu-complete", rl_menu_complete },
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 },
113 { "overwrite-mode", rl_overwrite_mode },
114 #ifdef __CYGWIN__
115 { "paste-from-clipboard", rl_paste_from_clipboard },
116 #endif
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 },
125 { "set-mark", rl_set_mark },
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 },
134 { "unix-line-discard", rl_unix_line_discard },
135 { "unix-word-rubout", rl_unix_word_rubout },
136 { "upcase-word", rl_upcase_word },
137 { "yank", rl_yank },
138 { "yank-last-arg", rl_yank_last_arg },
139 { "yank-nth-arg", rl_yank_nth_arg },
140 { "yank-pop", rl_yank_pop },
141
142 #if defined (VI_MODE)
143 { "vi-append-eol", rl_vi_append_eol },
144 { "vi-append-mode", rl_vi_append_mode },
145 { "vi-arg-digit", rl_vi_arg_digit },
146 { "vi-back-to-indent", rl_vi_back_to_indent },
147 { "vi-bWord", rl_vi_bWord },
148 { "vi-bword", rl_vi_bword },
149 { "vi-change-case", rl_vi_change_case },
150 { "vi-change-char", rl_vi_change_char },
151 { "vi-change-to", rl_vi_change_to },
152 { "vi-char-search", rl_vi_char_search },
153 { "vi-column", rl_vi_column },
154 { "vi-complete", rl_vi_complete },
155 { "vi-delete", rl_vi_delete },
156 { "vi-delete-to", rl_vi_delete_to },
157 { "vi-eWord", rl_vi_eWord },
158 { "vi-editing-mode", rl_vi_editing_mode },
159 { "vi-end-word", rl_vi_end_word },
160 { "vi-eof-maybe", rl_vi_eof_maybe },
161 { "vi-eword", rl_vi_eword },
162 { "vi-fWord", rl_vi_fWord },
163 { "vi-fetch-history", rl_vi_fetch_history },
164 { "vi-first-print", rl_vi_first_print },
165 { "vi-fword", rl_vi_fword },
166 { "vi-goto-mark", rl_vi_goto_mark },
167 { "vi-insert-beg", rl_vi_insert_beg },
168 { "vi-insertion-mode", rl_vi_insertion_mode },
169 { "vi-match", rl_vi_match },
170 { "vi-movement-mode", rl_vi_movement_mode },
171 { "vi-next-word", rl_vi_next_word },
172 { "vi-overstrike", rl_vi_overstrike },
173 { "vi-overstrike-delete", rl_vi_overstrike_delete },
174 { "vi-prev-word", rl_vi_prev_word },
175 { "vi-put", rl_vi_put },
176 { "vi-redo", rl_vi_redo },
177 { "vi-replace", rl_vi_replace },
178 { "vi-search", rl_vi_search },
179 { "vi-search-again", rl_vi_search_again },
180 { "vi-set-mark", rl_vi_set_mark },
181 { "vi-subst", rl_vi_subst },
182 { "vi-tilde-expand", rl_vi_tilde_expand },
183 { "vi-yank-arg", rl_vi_yank_arg },
184 { "vi-yank-to", rl_vi_yank_to },
185 #endif /* VI_MODE */
186
187 {(char *)NULL, (rl_command_func_t *)NULL }
188 };
189
190 int
191 rl_add_funmap_entry (name, function)
192 const char *name;
193 rl_command_func_t *function;
194 {
195 if (funmap_entry + 2 >= funmap_size)
196 {
197 funmap_size += 64;
198 funmap = (FUNMAP **)xrealloc (funmap, funmap_size * sizeof (FUNMAP *));
199 }
200
201 funmap[funmap_entry] = (FUNMAP *)xmalloc (sizeof (FUNMAP));
202 funmap[funmap_entry]->name = name;
203 funmap[funmap_entry]->function = function;
204
205 funmap[++funmap_entry] = (FUNMAP *)NULL;
206 return funmap_entry;
207 }
208
209 static int funmap_initialized;
210
211 /* Make the funmap contain all of the default entries. */
212 void
213 rl_initialize_funmap ()
214 {
215 register int i;
216
217 if (funmap_initialized)
218 return;
219
220 for (i = 0; default_funmap[i].name; i++)
221 rl_add_funmap_entry (default_funmap[i].name, default_funmap[i].function);
222
223 funmap_initialized = 1;
224 funmap_program_specific_entry_start = i;
225 }
226
227 /* Produce a NULL terminated array of known function names. The array
228 is sorted. The array itself is allocated, but not the strings inside.
229 You should free () the array when you done, but not the pointrs. */
230 const char **
231 rl_funmap_names ()
232 {
233 const char **result;
234 int result_size, result_index;
235
236 /* Make sure that the function map has been initialized. */
237 rl_initialize_funmap ();
238
239 for (result_index = result_size = 0, result = (const char **)NULL; funmap[result_index]; result_index++)
240 {
241 if (result_index + 2 > result_size)
242 {
243 result_size += 20;
244 result = (const char **)xrealloc (result, result_size * sizeof (char *));
245 }
246
247 result[result_index] = funmap[result_index]->name;
248 result[result_index + 1] = (char *)NULL;
249 }
250
251 qsort (result, result_index, sizeof (char *), (QSFUNC *)_rl_qsort_string_compare);
252 return (result);
253 }
This page took 0.045491 seconds and 4 git commands to generate.