1 | /* keymaps.c -- Functions and keymaps for the GNU Readline library. */ |
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 2, 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, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ |
21 | #define READLINE_LIBRARY |
22 | |
23 | #if defined (HAVE_CONFIG_H) |
24 | # include "config_readline.h" |
25 | #endif |
26 | |
27 | #if defined (HAVE_STDLIB_H) |
28 | # include <stdlib.h> |
29 | #else |
30 | # include "ansi_stdlib.h" |
31 | #endif /* HAVE_STDLIB_H */ |
32 | |
33 | #include <stdio.h> /* for FILE * definition for readline.h */ |
34 | |
35 | #include "readline.h" |
36 | #include "rlconf.h" |
37 | |
38 | #include "emacs_keymap.c" |
39 | |
40 | #if defined (VI_MODE) |
41 | #include "vi_keymap.c" |
42 | #endif |
43 | |
44 | #include "xmalloc.h" |
45 | |
46 | /* **************************************************************** */ |
47 | /* */ |
48 | /* Functions for manipulating Keymaps. */ |
49 | /* */ |
50 | /* **************************************************************** */ |
51 | |
52 | |
53 | /* Return a new, empty keymap. |
54 | Free it with free() when you are done. */ |
55 | Keymap |
56 | rl_make_bare_keymap () |
57 | { |
58 | register int i; |
59 | Keymap keymap = (Keymap)xmalloc (KEYMAP_SIZE * sizeof (KEYMAP_ENTRY)); |
60 | |
61 | for (i = 0; i < KEYMAP_SIZE; i++) |
62 | { |
63 | keymap[i].type = ISFUNC; |
64 | keymap[i].function = (rl_command_func_t *)NULL; |
65 | } |
66 | |
67 | #if 0 |
68 | for (i = 'A'; i < ('Z' + 1); i++) |
69 | { |
70 | keymap[i].type = ISFUNC; |
71 | keymap[i].function = rl_do_lowercase_version; |
72 | } |
73 | #endif |
74 | |
75 | return (keymap); |
76 | } |
77 | |
78 | /* Return a new keymap which is a copy of MAP. */ |
79 | Keymap |
80 | rl_copy_keymap (map) |
81 | Keymap map; |
82 | { |
83 | register int i; |
84 | Keymap temp; |
85 | |
86 | temp = rl_make_bare_keymap (); |
87 | for (i = 0; i < KEYMAP_SIZE; i++) |
88 | { |
89 | temp[i].type = map[i].type; |
90 | temp[i].function = map[i].function; |
91 | } |
92 | return (temp); |
93 | } |
94 | |
95 | /* Return a new keymap with the printing characters bound to rl_insert, |
96 | the uppercase Meta characters bound to run their lowercase equivalents, |
97 | and the Meta digits bound to produce numeric arguments. */ |
98 | Keymap |
99 | rl_make_keymap () |
100 | { |
101 | register int i; |
102 | Keymap newmap; |
103 | |
104 | newmap = rl_make_bare_keymap (); |
105 | |
106 | /* All ASCII printing characters are self-inserting. */ |
107 | for (i = ' '; i < 127; i++) |
108 | newmap[i].function = rl_insert; |
109 | |
110 | newmap[TAB].function = rl_insert; |
111 | newmap[RUBOUT].function = rl_rubout; /* RUBOUT == 127 */ |
112 | newmap[CTRL('H')].function = rl_rubout; |
113 | |
114 | #if KEYMAP_SIZE > 128 |
115 | /* Printing characters in ISO Latin-1 and some 8-bit character sets. */ |
116 | for (i = 128; i < 256; i++) |
117 | newmap[i].function = rl_insert; |
118 | #endif /* KEYMAP_SIZE > 128 */ |
119 | |
120 | return (newmap); |
121 | } |
122 | |
123 | /* Free the storage associated with MAP. */ |
124 | void |
125 | rl_discard_keymap (map) |
126 | Keymap map; |
127 | { |
128 | int i; |
129 | |
130 | if (!map) |
131 | return; |
132 | |
133 | for (i = 0; i < KEYMAP_SIZE; i++) |
134 | { |
135 | switch (map[i].type) |
136 | { |
137 | case ISFUNC: |
138 | break; |
139 | |
140 | case ISKMAP: |
141 | rl_discard_keymap ((Keymap)map[i].function); |
142 | break; |
143 | |
144 | case ISMACR: |
145 | free ((char *)map[i].function); |
146 | break; |
147 | } |
148 | } |
149 | } |
150 | |