1 /* funmap.c -- attach names to functions. */
3 /* Copyright (C) 1988,1989 Free Software Foundation, Inc.
5 This file is part of GNU Readline, a library for reading lines
6 of text with interactive input and history editing.
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
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.
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. */
22 /* #define STATIC_MALLOC */
23 #if !defined (STATIC_MALLOC)
24 extern char *xmalloc (), *xrealloc ();
26 static char *xmalloc (), *xrealloc ();
27 #endif /* STATIC_MALLOC */
35 FUNMAP **funmap = (FUNMAP **)NULL;
36 static int funmap_size = 0;
37 static int funmap_entry = 0;
39 /* After initializing the function map, this is the index of the first
40 program specific function. */
41 int funmap_program_specific_entry_start;
43 static FUNMAP default_funmap[] = {
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 },
91 { "yank-nth-arg", rl_yank_nth_arg },
92 { "yank-pop", rl_yank_pop },
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 },
138 {(char *)NULL, (Function *)NULL }
141 rl_add_funmap_entry (name, function)
145 if (funmap_entry + 2 >= funmap_size)
147 funmap = (FUNMAP **)xmalloc ((funmap_size = 80) * sizeof (FUNMAP *));
150 (FUNMAP **)xrealloc (funmap, (funmap_size += 80) * sizeof (FUNMAP *));
152 funmap[funmap_entry] = (FUNMAP *)xmalloc (sizeof (FUNMAP));
153 funmap[funmap_entry]->name = name;
154 funmap[funmap_entry]->function = function;
156 funmap[++funmap_entry] = (FUNMAP *)NULL;
159 static int funmap_initialized = 0;
161 /* Make the funmap contain all of the default entries. */
162 rl_initialize_funmap ()
166 if (funmap_initialized)
169 for (i = 0; default_funmap[i].name; i++)
170 rl_add_funmap_entry (default_funmap[i].name, default_funmap[i].function);
172 funmap_initialized = 1;
173 funmap_program_specific_entry_start = i;
176 /* Stupid comparison routine for qsort () ing strings. */
178 qsort_string_compare (s1, s2)
179 register char **s1, **s2;
181 return (strcmp (*s1, *s2));
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. */
190 char **result = (char **)NULL;
191 int result_size, result_index;
193 result_size = result_index = 0;
195 /* Make sure that the function map has been initialized. */
196 rl_initialize_funmap ();
198 for (result_index = 0; funmap[result_index]; result_index++)
200 if (result_index + 2 > result_size)
203 result = (char **)xmalloc ((result_size = 20) * sizeof (char *));
206 xrealloc (result, (result_size += 20) * sizeof (char *));
209 result[result_index] = funmap[result_index]->name;
210 result[result_index + 1] = (char *)NULL;
213 qsort (result, result_index, sizeof (char *), qsort_string_compare);
217 /* Things that mean `Control'. */
218 char *possible_control_prefixes[] = {
219 "Control-", "C-", "CTRL-", (char *)NULL
222 char *possible_meta_prefixes[] = {
223 "Meta", "M-", (char *)NULL
226 #if defined (STATIC_MALLOC)
228 /* **************************************************************** */
230 /* xmalloc and xrealloc () */
232 /* **************************************************************** */
234 static void memory_error_and_abort ();
240 char *temp = (char *)malloc (bytes);
243 memory_error_and_abort ();
248 xrealloc (pointer, bytes)
255 temp = (char *)malloc (bytes);
257 temp = (char *)realloc (pointer, bytes);
260 memory_error_and_abort ();
265 memory_error_and_abort ()
267 fprintf (stderr, "history: Out of virtual memory!\n");
270 #endif /* STATIC_MALLOC */