import gdb-1999-08-02 snapshot
[external/binutils.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 1, 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    675 Mass Ave, Cambridge, MA 02139, USA. */
22 #define READLINE_LIBRARY
23
24 #if defined (HAVE_CONFIG_H)
25 #  include <config.h>
26 #endif
27
28 extern char *xmalloc (), *xrealloc ();
29
30 #if !defined (BUFSIZ)
31 #include <stdio.h>
32 #endif /* BUFSIZ */
33
34 #if defined (HAVE_STDLIB_H)
35 #  include <stdlib.h>
36 #else
37 #  include "ansi_stdlib.h"
38 #endif /* HAVE_STDLIB_H */
39
40 #include "rlconf.h"
41 #include "readline.h"
42
43 extern int _rl_qsort_string_compare ();
44
45 FUNMAP **funmap;
46 static int funmap_size;
47 static int funmap_entry;
48
49 /* After initializing the function map, this is the index of the first
50    program specific function. */
51 int funmap_program_specific_entry_start;
52
53 static FUNMAP default_funmap[] = {
54   { "abort", rl_abort },
55   { "accept-line", rl_newline },
56   { "arrow-key-prefix", rl_arrow_keys },
57   { "backward-char", rl_backward },
58   { "backward-delete-char", rl_rubout },
59   { "backward-kill-line", rl_backward_kill_line },
60   { "backward-kill-word", rl_backward_kill_word },
61   { "backward-word", rl_backward_word },
62   { "beginning-of-history", rl_beginning_of_history },
63   { "beginning-of-line", rl_beg_of_line },
64   { "call-last-kbd-macro", rl_call_last_kbd_macro },
65   { "capitalize-word", rl_capitalize_word },
66   { "character-search", rl_char_search },
67   { "character-search-backward", rl_backward_char_search },
68   { "clear-screen", rl_clear_screen },
69   { "complete", rl_complete },
70   { "copy-backward-word", rl_copy_backward_word },
71   { "copy-forward-word", rl_copy_forward_word },
72   { "copy-region-as-kill", rl_copy_region_to_kill },
73   { "delete-char", rl_delete },
74   { "delete-char-or-list", rl_delete_or_show_completions },
75   { "delete-horizontal-space", rl_delete_horizontal_space },
76   { "digit-argument", rl_digit_argument },
77   { "do-lowercase-version", rl_do_lowercase_version },
78   { "downcase-word", rl_downcase_word },
79   { "dump-functions", rl_dump_functions },
80   { "dump-macros", rl_dump_macros },
81   { "dump-variables", rl_dump_variables },
82   { "emacs-editing-mode", rl_emacs_editing_mode },
83   { "end-kbd-macro", rl_end_kbd_macro },
84   { "end-of-history", rl_end_of_history },
85   { "end-of-line", rl_end_of_line },
86   { "exchange-point-and-mark", rl_exchange_point_and_mark },
87   { "forward-backward-delete-char", rl_rubout_or_delete },
88   { "forward-char", rl_forward },
89   { "forward-search-history", rl_forward_search_history },
90   { "forward-word", rl_forward_word },
91   { "history-search-backward", rl_history_search_backward },
92   { "history-search-forward", rl_history_search_forward },
93   { "insert-comment", rl_insert_comment },
94   { "insert-completions", rl_insert_completions },
95   { "kill-whole-line", rl_kill_full_line },
96   { "kill-line", rl_kill_line },
97   { "kill-region", rl_kill_region },
98   { "kill-word", rl_kill_word },
99   { "menu-complete", rl_menu_complete },
100   { "next-history", rl_get_next_history },
101   { "non-incremental-forward-search-history", rl_noninc_forward_search },
102   { "non-incremental-reverse-search-history", rl_noninc_reverse_search },
103   { "non-incremental-forward-search-history-again", rl_noninc_forward_search_again },
104   { "non-incremental-reverse-search-history-again", rl_noninc_reverse_search_again },
105 #ifdef __CYGWIN32__
106   { "paste-from-clipboard", rl_paste_from_clipboard },
107 #endif
108   { "possible-completions", rl_possible_completions },
109   { "previous-history", rl_get_previous_history },
110   { "quoted-insert", rl_quoted_insert },
111   { "re-read-init-file", rl_re_read_init_file },
112   { "redraw-current-line", rl_refresh_line},
113   { "reverse-search-history", rl_reverse_search_history },
114   { "revert-line", rl_revert_line },
115   { "self-insert", rl_insert },
116   { "set-mark", rl_set_mark },
117   { "start-kbd-macro", rl_start_kbd_macro },
118   { "tab-insert", rl_tab_insert },
119   { "tilde-expand", rl_tilde_expand },
120   { "transpose-chars", rl_transpose_chars },
121   { "transpose-words", rl_transpose_words },
122   { "tty-status", rl_tty_status },
123   { "undo", rl_undo_command },
124   { "universal-argument", rl_universal_argument },
125   { "unix-line-discard", rl_unix_line_discard },
126   { "unix-word-rubout", rl_unix_word_rubout },
127   { "upcase-word", rl_upcase_word },
128   { "yank", rl_yank },
129   { "yank-last-arg", rl_yank_last_arg },
130   { "yank-nth-arg", rl_yank_nth_arg },
131   { "yank-pop", rl_yank_pop },
132
133 #if defined (VI_MODE)
134   { "vi-append-eol", rl_vi_append_eol },
135   { "vi-append-mode", rl_vi_append_mode },
136   { "vi-arg-digit", rl_vi_arg_digit },
137   { "vi-back-to-indent", rl_vi_back_to_indent },
138   { "vi-bWord", rl_vi_bWord },
139   { "vi-bracktype", rl_vi_bracktype },
140   { "vi-bword", rl_vi_bword },
141   { "vi-change-case", rl_vi_change_case },
142   { "vi-change-char", rl_vi_change_char },
143   { "vi-change-to", rl_vi_change_to },
144   { "vi-char-search", rl_vi_char_search },
145   { "vi-column", rl_vi_column },
146   { "vi-complete", rl_vi_complete },
147   { "vi-delete", rl_vi_delete },
148   { "vi-delete-to", rl_vi_delete_to },
149   { "vi-eWord", rl_vi_eWord },
150   { "vi-editing-mode", rl_vi_editing_mode },
151   { "vi-end-word", rl_vi_end_word },
152   { "vi-eof-maybe", rl_vi_eof_maybe },
153   { "vi-eword", rl_vi_eword },
154   { "vi-fWord", rl_vi_fWord },
155   { "vi-fetch-history", rl_vi_fetch_history },
156   { "vi-first-print", rl_vi_first_print },
157   { "vi-fword", rl_vi_fword },
158   { "vi-goto-mark", rl_vi_goto_mark },
159   { "vi-insert-beg", rl_vi_insert_beg },
160   { "vi-insertion-mode", rl_vi_insertion_mode },
161   { "vi-match", rl_vi_match },
162   { "vi-movement-mode", rl_vi_movement_mode },
163   { "vi-next-word", rl_vi_next_word },
164   { "vi-overstrike", rl_vi_overstrike },
165   { "vi-overstrike-delete", rl_vi_overstrike_delete },
166   { "vi-prev-word", rl_vi_prev_word },
167   { "vi-put", rl_vi_put },
168   { "vi-redo", rl_vi_redo },
169   { "vi-replace", rl_vi_replace },
170   { "vi-search", rl_vi_search },
171   { "vi-search-again", rl_vi_search_again },
172   { "vi-set-mark", rl_vi_set_mark },
173   { "vi-subst", rl_vi_subst },
174   { "vi-tilde-expand", rl_vi_tilde_expand },
175   { "vi-yank-arg", rl_vi_yank_arg },
176   { "vi-yank-to", rl_vi_yank_to },
177 #endif /* VI_MODE */
178
179  {(char *)NULL, (Function *)NULL }
180 };
181
182 int
183 rl_add_funmap_entry (name, function)
184      char *name;
185      Function *function;
186 {
187   if (funmap_entry + 2 >= funmap_size)
188     {
189       funmap_size += 64;
190       funmap = (FUNMAP **)xrealloc (funmap, funmap_size * sizeof (FUNMAP *));
191     }
192   
193   funmap[funmap_entry] = (FUNMAP *)xmalloc (sizeof (FUNMAP));
194   funmap[funmap_entry]->name = name;
195   funmap[funmap_entry]->function = function;
196
197   funmap[++funmap_entry] = (FUNMAP *)NULL;
198   return funmap_entry;
199 }
200
201 static int funmap_initialized;
202
203 /* Make the funmap contain all of the default entries. */
204 void
205 rl_initialize_funmap ()
206 {
207   register int i;
208
209   if (funmap_initialized)
210     return;
211
212   for (i = 0; default_funmap[i].name; i++)
213     rl_add_funmap_entry (default_funmap[i].name, default_funmap[i].function);
214
215   funmap_initialized = 1;
216   funmap_program_specific_entry_start = i;
217 }
218
219 /* Produce a NULL terminated array of known function names.  The array
220    is sorted.  The array itself is allocated, but not the strings inside.
221    You should free () the array when you done, but not the pointrs. */
222 char **
223 rl_funmap_names ()
224 {
225   char **result;
226   int result_size, result_index;
227
228   /* Make sure that the function map has been initialized. */
229   rl_initialize_funmap ();
230
231   for (result_index = result_size = 0, result = (char **)NULL; funmap[result_index]; result_index++)
232     {
233       if (result_index + 2 > result_size)
234         {
235           result_size += 20;
236           result = (char **)xrealloc (result, result_size * sizeof (char *));
237         }
238
239       result[result_index] = funmap[result_index]->name;
240       result[result_index + 1] = (char *)NULL;
241     }
242
243   qsort (result, result_index, sizeof (char *), _rl_qsort_string_compare);
244   return (result);
245 }
246
247 /* Things that mean `Control'. */
248 char *possible_control_prefixes[] = {
249   "Control-", "C-", "CTRL-", (char *)NULL
250 };
251
252 char *possible_meta_prefixes[] = {
253   "Meta", "M-", (char *)NULL
254 };