1 /* funmap.c -- attach names to functions. */
3 /* Copyright (C) 1987, 1989, 1992 Free Software Foundation, Inc.
5 This file is part of the GNU Readline Library, a library for
6 reading lines of text with interactive input and history editing.
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.
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.
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
24 #if defined (STATIC_MALLOC)
25 static char *xmalloc (), *xrealloc ();
27 extern char *xmalloc (), *xrealloc ();
28 #endif /* STATIC_MALLOC */
34 #if defined (HAVE_STDLIB_H)
37 # include "ansi_stdlib.h"
38 #endif /* HAVE_STDLIB_H */
43 static int qsort_string_compare ();
45 FUNMAP **funmap = (FUNMAP **)NULL;
46 static int funmap_size = 0;
47 static int funmap_entry = 0;
49 /* After initializing the function map, this is the index of the first
50 program specific function. */
51 int funmap_program_specific_entry_start;
53 static FUNMAP default_funmap[] = {
55 { "abort", rl_abort },
56 { "accept-line", rl_newline },
57 { "arrow-key-prefix", rl_arrow_keys },
58 { "backward-char", rl_backward },
59 { "backward-delete-char", rl_rubout },
60 { "backward-kill-line", rl_backward_kill_line },
61 { "backward-kill-word", rl_backward_kill_word },
62 { "backward-word", rl_backward_word },
63 { "beginning-of-history", rl_beginning_of_history },
64 { "beginning-of-line", rl_beg_of_line },
65 { "call-last-kbd-macro", rl_call_last_kbd_macro },
66 { "capitalize-word", rl_capitalize_word },
67 { "clear-screen", rl_clear_screen },
68 { "complete", rl_complete },
69 { "delete-char", rl_delete },
70 { "delete-horizontal-space", rl_delete_horizontal_space },
71 { "digit-argument", rl_digit_argument },
72 { "do-lowercase-version", rl_do_lowercase_version },
73 { "downcase-word", rl_downcase_word },
74 { "dump-functions", rl_dump_functions },
75 { "emacs-editing-mode", rl_emacs_editing_mode },
76 { "end-kbd-macro", rl_end_kbd_macro },
77 { "end-of-history", rl_end_of_history },
78 { "end-of-line", rl_end_of_line },
79 { "forward-char", rl_forward },
80 { "forward-search-history", rl_forward_search_history },
81 { "forward-word", rl_forward_word },
82 { "history-search-backward", rl_history_search_backward },
83 { "history-search-forward", rl_history_search_forward },
84 { "insert-completions", rl_insert_completions },
85 { "kill-whole-line", rl_kill_full_line },
86 { "kill-line", rl_kill_line },
87 { "kill-word", rl_kill_word },
88 { "next-history", rl_get_next_history },
89 { "non-incremental-forward-search-history", rl_noninc_forward_search },
90 { "non-incremental-reverse-search-history", rl_noninc_reverse_search },
91 { "non-incremental-forward-search-history-again", rl_noninc_forward_search_again },
92 { "non-incremental-reverse-search-history-again", rl_noninc_reverse_search_again },
93 { "possible-completions", rl_possible_completions },
94 { "previous-history", rl_get_previous_history },
95 { "quoted-insert", rl_quoted_insert },
96 { "re-read-init-file", rl_re_read_init_file },
97 { "redraw-current-line", rl_refresh_line},
98 { "reverse-search-history", rl_reverse_search_history },
99 { "revert-line", rl_revert_line },
100 { "self-insert", rl_insert },
101 { "start-kbd-macro", rl_start_kbd_macro },
102 { "tab-insert", rl_tab_insert },
103 { "tilde-expand", rl_tilde_expand },
104 { "transpose-chars", rl_transpose_chars },
105 { "transpose-words", rl_transpose_words },
106 { "tty-status", rl_tty_status },
107 { "undo", rl_undo_command },
108 { "universal-argument", rl_universal_argument },
109 { "unix-line-discard", rl_unix_line_discard },
110 { "unix-word-rubout", rl_unix_word_rubout },
111 { "upcase-word", rl_upcase_word },
113 { "yank-last-arg", rl_yank_last_arg },
114 { "yank-nth-arg", rl_yank_nth_arg },
115 { "yank-pop", rl_yank_pop },
117 #if defined (VI_MODE)
118 { "vi-append-eol", rl_vi_append_eol },
119 { "vi-append-mode", rl_vi_append_mode },
120 { "vi-arg-digit", rl_vi_arg_digit },
121 { "vi-bWord", rl_vi_bWord },
122 { "vi-bracktype", rl_vi_bracktype },
123 { "vi-bword", rl_vi_bword },
124 { "vi-change-case", rl_vi_change_case },
125 { "vi-change-char", rl_vi_change_char },
126 { "vi-change-to", rl_vi_change_to },
127 { "vi-char-search", rl_vi_char_search },
128 { "vi-column", rl_vi_column },
129 { "vi-comment", rl_vi_comment },
130 { "vi-complete", rl_vi_complete },
131 { "vi-delete", rl_vi_delete },
132 { "vi-delete-to", rl_vi_delete_to },
133 { "vi-eWord", rl_vi_eWord },
134 { "vi-editing-mode", rl_vi_editing_mode },
135 { "vi-end-word", rl_vi_end_word },
136 { "vi-eof-maybe", rl_vi_eof_maybe },
137 { "vi-eword", rl_vi_eword },
138 { "vi-fWord", rl_vi_fWord },
139 { "vi-first-print", rl_vi_first_print },
140 { "vi-fword", rl_vi_fword },
141 { "vi-insert-beg", rl_vi_insert_beg },
142 { "vi-insertion-mode", rl_vi_insertion_mode },
143 { "vi-match", rl_vi_match },
144 { "vi-movement-mode", rl_vi_movement_mode },
145 { "vi-next-word", rl_vi_next_word },
146 { "vi-overstrike", rl_vi_overstrike },
147 { "vi-overstrike-delete", rl_vi_overstrike_delete },
148 { "vi-prev-word", rl_vi_prev_word },
149 { "vi-put", rl_vi_put },
150 { "vi-redo", rl_vi_redo },
151 { "vi-replace", rl_vi_replace },
152 { "vi-search", rl_vi_search },
153 { "vi-search-again", rl_vi_search_again },
154 { "vi-subst", rl_vi_subst },
155 { "vi-tilde-expand", rl_vi_tilde_expand },
156 { "vi-yank-arg", rl_vi_yank_arg },
157 { "vi-yank-to", rl_vi_yank_to },
160 {(char *)NULL, (Function *)NULL }
163 rl_add_funmap_entry (name, function)
167 if (funmap_entry + 2 >= funmap_size)
169 funmap = (FUNMAP **)xmalloc ((funmap_size = 80) * sizeof (FUNMAP *));
172 (FUNMAP **)xrealloc (funmap, (funmap_size += 80) * sizeof (FUNMAP *));
174 funmap[funmap_entry] = (FUNMAP *)xmalloc (sizeof (FUNMAP));
175 funmap[funmap_entry]->name = name;
176 funmap[funmap_entry]->function = function;
178 funmap[++funmap_entry] = (FUNMAP *)NULL;
182 static int funmap_initialized = 0;
184 /* Make the funmap contain all of the default entries. */
186 rl_initialize_funmap ()
190 if (funmap_initialized)
193 for (i = 0; default_funmap[i].name; i++)
194 rl_add_funmap_entry (default_funmap[i].name, default_funmap[i].function);
196 funmap_initialized = 1;
197 funmap_program_specific_entry_start = i;
200 /* Produce a NULL terminated array of known function names. The array
201 is sorted. The array itself is allocated, but not the strings inside.
202 You should free () the array when you done, but not the pointrs. */
206 char **result = (char **)NULL;
207 int result_size, result_index;
209 result_size = result_index = 0;
211 /* Make sure that the function map has been initialized. */
212 rl_initialize_funmap ();
214 for (result_index = 0; funmap[result_index]; result_index++)
216 if (result_index + 2 > result_size)
219 result = (char **)xmalloc ((result_size = 20) * sizeof (char *));
222 xrealloc (result, (result_size += 20) * sizeof (char *));
225 result[result_index] = funmap[result_index]->name;
226 result[result_index + 1] = (char *)NULL;
229 qsort (result, result_index, sizeof (char *), qsort_string_compare);
233 /* Stupid comparison routine for qsort () ing strings. */
235 qsort_string_compare (s1, s2)
236 register char **s1, **s2;
242 r = strcmp (*s1, *s2);
246 /* Things that mean `Control'. */
247 char *possible_control_prefixes[] = {
248 "Control-", "C-", "CTRL-", (char *)NULL
251 char *possible_meta_prefixes[] = {
252 "Meta", "M-", (char *)NULL
255 #if defined (STATIC_MALLOC)
257 /* **************************************************************** */
259 /* xmalloc and xrealloc () */
261 /* **************************************************************** */
263 static void memory_error_and_abort ();
269 char *temp = (char *)malloc (bytes);
272 memory_error_and_abort ();
277 xrealloc (pointer, bytes)
284 temp = (char *)malloc (bytes);
286 temp = (char *)realloc (pointer, bytes);
289 memory_error_and_abort ();
294 memory_error_and_abort ()
296 fprintf (stderr, "history: Out of virtual memory!\n");
299 #endif /* STATIC_MALLOC */