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