* rldefs.h: On Linux, include <termios.h> to fix compile error
[deliverable/binutils-gdb.git] / readline / funmap.c
1 /* funmap.c -- attach names to functions. */
2
3 /* Copyright (C) 1988,1989 Free Software Foundation, Inc.
4
5 This file is part of GNU Readline, a library for reading lines
6 of text with interactive input and history editing.
7
8 Readline is free software; you can redistribute it and/or modify it
9 under the terms of the GNU General Public License as published by the
10 Free Software Foundation; either version 1, or (at your option) any
11 later version.
12
13 Readline is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with Readline; see the file COPYING. If not, write to the Free
20 Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
21
22 /* #define STATIC_MALLOC */
23 #if !defined (STATIC_MALLOC)
24 extern char *xmalloc (), *xrealloc ();
25 #else
26 static char *xmalloc (), *xrealloc ();
27 #endif /* STATIC_MALLOC */
28
29 #if !defined (BUFSIZ)
30 #include <stdio.h>
31 #endif /* BUFSIZ */
32
33 #include "readline.h"
34
35 FUNMAP **funmap = (FUNMAP **)NULL;
36 static int funmap_size = 0;
37 static int funmap_entry = 0;
38
39 /* After initializing the function map, this is the index of the first
40 program specific function. */
41 int funmap_program_specific_entry_start;
42
43 static FUNMAP default_funmap[] = {
44
45 { "abort", rl_abort },
46 { "accept-line", rl_newline },
47 { "arrow-key-prefix", rl_arrow_keys },
48 { "backward-char", rl_backward },
49 { "backward-delete-char", rl_rubout },
50 { "backward-kill-line", rl_backward_kill_line },
51 { "backward-kill-word", rl_backward_kill_word },
52 { "backward-word", rl_backward_word },
53 { "beginning-of-history", rl_beginning_of_history },
54 { "beginning-of-line", rl_beg_of_line },
55 { "call-last-kbd-macro", rl_call_last_kbd_macro },
56 { "capitalize-word", rl_capitalize_word },
57 { "clear-screen", rl_clear_screen },
58 { "complete", rl_complete },
59 { "delete-char", rl_delete },
60 { "digit-argument", rl_digit_argument },
61 { "do-lowercase-version", rl_do_lowercase_version },
62 { "downcase-word", rl_downcase_word },
63 { "dump-functions", rl_dump_functions },
64 { "end-kbd-macro", rl_end_kbd_macro },
65 { "end-of-history", rl_end_of_history },
66 { "end-of-line", rl_end_of_line },
67 { "forward-char", rl_forward },
68 { "forward-search-history", rl_forward_search_history },
69 { "forward-word", rl_forward_word },
70 { "kill-line", rl_kill_line },
71 { "kill-word", rl_kill_word },
72 { "next-history", rl_get_next_history },
73 { "possible-completions", rl_possible_completions },
74 { "previous-history", rl_get_previous_history },
75 { "quoted-insert", rl_quoted_insert },
76 { "re-read-init-file", rl_re_read_init_file },
77 { "redraw-current-line", rl_refresh_line},
78 { "reverse-search-history", rl_reverse_search_history },
79 { "revert-line", rl_revert_line },
80 { "self-insert", rl_insert },
81 { "start-kbd-macro", rl_start_kbd_macro },
82 { "tab-insert", rl_tab_insert },
83 { "transpose-chars", rl_transpose_chars },
84 { "transpose-words", rl_transpose_words },
85 { "undo", rl_undo_command },
86 { "universal-argument", rl_universal_argument },
87 { "unix-line-discard", rl_unix_line_discard },
88 { "unix-word-rubout", rl_unix_word_rubout },
89 { "upcase-word", rl_upcase_word },
90 { "yank", rl_yank },
91 { "yank-nth-arg", rl_yank_nth_arg },
92 { "yank-pop", rl_yank_pop },
93
94 #if defined (VI_MODE)
95
96 { "vi-append-eol", rl_vi_append_eol },
97 { "vi-append-mode", rl_vi_append_mode },
98 { "vi-arg-digit", rl_vi_arg_digit },
99 { "vi-bWord", rl_vi_bWord },
100 { "vi-bracktype", rl_vi_bracktype },
101 { "vi-bword", rl_vi_bword },
102 { "vi-change-case", rl_vi_change_case },
103 { "vi-change-char", rl_vi_change_char },
104 { "vi-change-to", rl_vi_change_to },
105 { "vi-char-search", rl_vi_char_search },
106 { "vi-column", rl_vi_column },
107 { "vi-comment", rl_vi_comment },
108 { "vi-complete", rl_vi_complete },
109 { "vi-delete", rl_vi_delete },
110 { "vi-delete-to", rl_vi_delete_to },
111 { "vi-dosearch", rl_vi_dosearch },
112 { "vi-eWord", rl_vi_eWord },
113 { "vi-editing-mode", rl_vi_editing_mode },
114 { "vi-end-word", rl_vi_end_word },
115 { "vi-eof-maybe", rl_vi_eof_maybe },
116 { "vi-eword", rl_vi_eword },
117 { "vi-fWord", rl_vi_fWord },
118 { "vi-first-print", rl_vi_first_print },
119 { "vi-fword", rl_vi_fword },
120 { "vi-insert-beg", rl_vi_insert_beg },
121 { "vi-insertion-mode", rl_vi_insertion_mode },
122 { "vi-match", rl_vi_match },
123 { "vi-movement-mode", rl_vi_movement_mode },
124 { "vi-next-word", rl_vi_next_word },
125 { "vi-overstrike", rl_vi_overstrike },
126 { "vi-overstrike-delete", rl_vi_overstrike_delete },
127 { "vi-prev-word", rl_vi_prev_word },
128 { "vi-put", rl_vi_put },
129 { "vi-replace, ", rl_vi_replace },
130 { "vi-search", rl_vi_search },
131 { "vi-search-again", rl_vi_search_again },
132 { "vi-subst", rl_vi_subst },
133 { "vi-yank-arg", rl_vi_yank_arg },
134 { "vi-yank-to", rl_vi_yank_to },
135
136 #endif /* VI_MODE */
137
138 {(char *)NULL, (Function *)NULL }
139 };
140
141 rl_add_funmap_entry (name, function)
142 char *name;
143 Function *function;
144 {
145 if (funmap_entry + 2 >= funmap_size)
146 if (!funmap)
147 funmap = (FUNMAP **)xmalloc ((funmap_size = 80) * sizeof (FUNMAP *));
148 else
149 funmap =
150 (FUNMAP **)xrealloc (funmap, (funmap_size += 80) * sizeof (FUNMAP *));
151
152 funmap[funmap_entry] = (FUNMAP *)xmalloc (sizeof (FUNMAP));
153 funmap[funmap_entry]->name = name;
154 funmap[funmap_entry]->function = function;
155
156 funmap[++funmap_entry] = (FUNMAP *)NULL;
157 }
158
159 static int funmap_initialized = 0;
160
161 /* Make the funmap contain all of the default entries. */
162 rl_initialize_funmap ()
163 {
164 register int i;
165
166 if (funmap_initialized)
167 return;
168
169 for (i = 0; default_funmap[i].name; i++)
170 rl_add_funmap_entry (default_funmap[i].name, default_funmap[i].function);
171
172 funmap_initialized = 1;
173 funmap_program_specific_entry_start = i;
174 }
175
176 /* Stupid comparison routine for qsort () ing strings. */
177 static int
178 qsort_string_compare (s1, s2)
179 register char **s1, **s2;
180 {
181 return (strcmp (*s1, *s2));
182 }
183
184 /* Produce a NULL terminated array of known function names. The array
185 is sorted. The array itself is allocated, but not the strings inside.
186 You should free () the array when you done, but not the pointrs. */
187 char **
188 rl_funmap_names ()
189 {
190 char **result = (char **)NULL;
191 int result_size, result_index;
192
193 result_size = result_index = 0;
194
195 /* Make sure that the function map has been initialized. */
196 rl_initialize_funmap ();
197
198 for (result_index = 0; funmap[result_index]; result_index++)
199 {
200 if (result_index + 2 > result_size)
201 {
202 if (!result)
203 result = (char **)xmalloc ((result_size = 20) * sizeof (char *));
204 else
205 result = (char **)
206 xrealloc (result, (result_size += 20) * sizeof (char *));
207 }
208
209 result[result_index] = funmap[result_index]->name;
210 result[result_index + 1] = (char *)NULL;
211 }
212
213 qsort (result, result_index, sizeof (char *), qsort_string_compare);
214 return (result);
215 }
216
217 /* Things that mean `Control'. */
218 char *possible_control_prefixes[] = {
219 "Control-", "C-", "CTRL-", (char *)NULL
220 };
221
222 char *possible_meta_prefixes[] = {
223 "Meta", "M-", (char *)NULL
224 };
225
226 #if defined (STATIC_MALLOC)
227 \f
228 /* **************************************************************** */
229 /* */
230 /* xmalloc and xrealloc () */
231 /* */
232 /* **************************************************************** */
233
234 static void memory_error_and_abort ();
235
236 static char *
237 xmalloc (bytes)
238 int bytes;
239 {
240 char *temp = (char *)malloc (bytes);
241
242 if (!temp)
243 memory_error_and_abort ();
244 return (temp);
245 }
246
247 static char *
248 xrealloc (pointer, bytes)
249 char *pointer;
250 int bytes;
251 {
252 char *temp;
253
254 if (!pointer)
255 temp = (char *)malloc (bytes);
256 else
257 temp = (char *)realloc (pointer, bytes);
258
259 if (!temp)
260 memory_error_and_abort ();
261 return (temp);
262 }
263
264 static void
265 memory_error_and_abort ()
266 {
267 fprintf (stderr, "history: Out of virtual memory!\n");
268 abort ();
269 }
270 #endif /* STATIC_MALLOC */
This page took 0.034503 seconds and 4 git commands to generate.