1 /* keymaps.c -- Functions and keymaps for the GNU Readline library. */
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. */
21 #define READLINE_LIBRARY
23 #if defined (HAVE_CONFIG_H)
27 #if defined (HAVE_STDLIB_H)
30 # include "ansi_stdlib.h"
31 #endif /* HAVE_STDLIB_H */
35 #include "emacs_keymap.c"
38 #include "vi_keymap.c"
41 extern int rl_do_lowercase_version ();
42 extern int rl_rubout (), rl_insert ();
44 #if defined (STATIC_MALLOC)
45 static char *xmalloc (), *xrealloc ();
47 extern char *xmalloc (), *xrealloc ();
48 #endif /* STATIC_MALLOC */
50 /* **************************************************************** */
52 /* Functions for manipulating Keymaps. */
54 /* **************************************************************** */
57 /* Return a new, empty keymap.
58 Free it with free() when you are done. */
60 rl_make_bare_keymap ()
63 Keymap keymap = (Keymap)xmalloc (KEYMAP_SIZE * sizeof (KEYMAP_ENTRY));
65 for (i = 0; i < KEYMAP_SIZE; i++)
67 keymap[i].type = ISFUNC;
68 keymap[i].function = (Function *)NULL;
71 for (i = 'A'; i < ('Z' + 1); i++)
73 keymap[i].type = ISFUNC;
74 keymap[i].function = rl_do_lowercase_version;
80 /* Return a new keymap which is a copy of MAP. */
86 Keymap temp = rl_make_bare_keymap ();
88 for (i = 0; i < KEYMAP_SIZE; i++)
90 temp[i].type = map[i].type;
91 temp[i].function = map[i].function;
96 /* Return a new keymap with the printing characters bound to rl_insert,
97 the uppercase Meta characters bound to run their lowercase equivalents,
98 and the Meta digits bound to produce numeric arguments. */
105 newmap = rl_make_bare_keymap ();
107 /* All ASCII printing characters are self-inserting. */
108 for (i = ' '; i < 127; i++)
109 newmap[i].function = rl_insert;
111 newmap[TAB].function = rl_insert;
112 newmap[RUBOUT].function = rl_rubout;
113 newmap[CTRL('H')].function = rl_rubout;
115 #if KEYMAP_SIZE > 128
116 /* Printing characters in some 8-bit character sets. */
117 for (i = 128; i < 160; i++)
118 newmap[i].function = rl_insert;
120 /* ISO Latin-1 printing characters should self-insert. */
121 for (i = 160; i < 256; i++)
122 newmap[i].function = rl_insert;
123 #endif /* KEYMAP_SIZE > 128 */
128 /* Free the storage associated with MAP. */
130 rl_discard_keymap (map)
138 for (i = 0; i < KEYMAP_SIZE; i++)
146 rl_discard_keymap ((Keymap)map[i].function);
150 free ((char *)map[i].function);
156 #if defined (STATIC_MALLOC)
158 /* **************************************************************** */
160 /* xmalloc and xrealloc () */
162 /* **************************************************************** */
164 static void memory_error_and_abort ();
170 char *temp = (char *)malloc (bytes);
173 memory_error_and_abort ();
178 xrealloc (pointer, bytes)
185 temp = (char *)malloc (bytes);
187 temp = (char *)realloc (pointer, bytes);
190 memory_error_and_abort ();
195 memory_error_and_abort ()
197 fprintf (stderr, "readline: Out of virtual memory!\n");
200 #endif /* STATIC_MALLOC */