Commit | Line | Data |
---|---|---|
d60d9f65 SS |
1 | /* keymaps.c -- Functions and keymaps for the GNU Readline library. */ |
2 | ||
cc88a640 | 3 | /* Copyright (C) 1988,1989-2009 Free Software Foundation, Inc. |
d60d9f65 | 4 | |
cc88a640 JK |
5 | This file is part of the GNU Readline Library (Readline), a library |
6 | for reading lines of text with interactive input and history editing. | |
d60d9f65 | 7 | |
cc88a640 JK |
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 3 of the License, or | |
11 | (at your option) any later version. | |
d60d9f65 | 12 | |
cc88a640 JK |
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. | |
d60d9f65 SS |
17 | |
18 | You should have received a copy of the GNU General Public License | |
cc88a640 JK |
19 | along with Readline. If not, see <http://www.gnu.org/licenses/>. |
20 | */ | |
21 | ||
d60d9f65 SS |
22 | #define READLINE_LIBRARY |
23 | ||
24 | #if defined (HAVE_CONFIG_H) | |
25 | # include <config.h> | |
26 | #endif | |
27 | ||
28 | #if defined (HAVE_STDLIB_H) | |
29 | # include <stdlib.h> | |
30 | #else | |
31 | # include "ansi_stdlib.h" | |
32 | #endif /* HAVE_STDLIB_H */ | |
33 | ||
1b17e766 EZ |
34 | #include <stdio.h> /* for FILE * definition for readline.h */ |
35 | ||
36 | #include "readline.h" | |
d60d9f65 | 37 | #include "rlconf.h" |
1b17e766 | 38 | |
d60d9f65 SS |
39 | #include "emacs_keymap.c" |
40 | ||
41 | #if defined (VI_MODE) | |
42 | #include "vi_keymap.c" | |
43 | #endif | |
44 | ||
1b17e766 | 45 | #include "xmalloc.h" |
d60d9f65 SS |
46 | |
47 | /* **************************************************************** */ | |
48 | /* */ | |
49 | /* Functions for manipulating Keymaps. */ | |
50 | /* */ | |
51 | /* **************************************************************** */ | |
52 | ||
53 | ||
54 | /* Return a new, empty keymap. | |
55 | Free it with free() when you are done. */ | |
56 | Keymap | |
57 | rl_make_bare_keymap () | |
58 | { | |
59 | register int i; | |
cc88a640 | 60 | Keymap keymap; |
d60d9f65 | 61 | |
cc88a640 | 62 | keymap = (Keymap)xmalloc (KEYMAP_SIZE * sizeof (KEYMAP_ENTRY)); |
d60d9f65 SS |
63 | for (i = 0; i < KEYMAP_SIZE; i++) |
64 | { | |
65 | keymap[i].type = ISFUNC; | |
9255ee31 | 66 | keymap[i].function = (rl_command_func_t *)NULL; |
d60d9f65 SS |
67 | } |
68 | ||
5bdf8622 | 69 | #if 0 |
d60d9f65 SS |
70 | for (i = 'A'; i < ('Z' + 1); i++) |
71 | { | |
72 | keymap[i].type = ISFUNC; | |
73 | keymap[i].function = rl_do_lowercase_version; | |
74 | } | |
5bdf8622 | 75 | #endif |
d60d9f65 SS |
76 | |
77 | return (keymap); | |
78 | } | |
79 | ||
cc88a640 JK |
80 | /* Return a new keymap which is a copy of MAP. Just copies pointers, does |
81 | not copy text of macros or descend into child keymaps. */ | |
d60d9f65 SS |
82 | Keymap |
83 | rl_copy_keymap (map) | |
84 | Keymap map; | |
85 | { | |
86 | register int i; | |
5bdf8622 | 87 | Keymap temp; |
d60d9f65 | 88 | |
5bdf8622 | 89 | temp = rl_make_bare_keymap (); |
d60d9f65 SS |
90 | for (i = 0; i < KEYMAP_SIZE; i++) |
91 | { | |
92 | temp[i].type = map[i].type; | |
93 | temp[i].function = map[i].function; | |
94 | } | |
95 | return (temp); | |
96 | } | |
97 | ||
98 | /* Return a new keymap with the printing characters bound to rl_insert, | |
99 | the uppercase Meta characters bound to run their lowercase equivalents, | |
100 | and the Meta digits bound to produce numeric arguments. */ | |
101 | Keymap | |
102 | rl_make_keymap () | |
103 | { | |
104 | register int i; | |
105 | Keymap newmap; | |
106 | ||
107 | newmap = rl_make_bare_keymap (); | |
108 | ||
109 | /* All ASCII printing characters are self-inserting. */ | |
110 | for (i = ' '; i < 127; i++) | |
111 | newmap[i].function = rl_insert; | |
112 | ||
113 | newmap[TAB].function = rl_insert; | |
114 | newmap[RUBOUT].function = rl_rubout; /* RUBOUT == 127 */ | |
115 | newmap[CTRL('H')].function = rl_rubout; | |
116 | ||
117 | #if KEYMAP_SIZE > 128 | |
5bdf8622 DJ |
118 | /* Printing characters in ISO Latin-1 and some 8-bit character sets. */ |
119 | for (i = 128; i < 256; i++) | |
d60d9f65 SS |
120 | newmap[i].function = rl_insert; |
121 | #endif /* KEYMAP_SIZE > 128 */ | |
122 | ||
123 | return (newmap); | |
124 | } | |
125 | ||
126 | /* Free the storage associated with MAP. */ | |
127 | void | |
128 | rl_discard_keymap (map) | |
c862e87b | 129 | Keymap map; |
d60d9f65 SS |
130 | { |
131 | int i; | |
132 | ||
cc88a640 | 133 | if (map == 0) |
d60d9f65 SS |
134 | return; |
135 | ||
136 | for (i = 0; i < KEYMAP_SIZE; i++) | |
137 | { | |
138 | switch (map[i].type) | |
139 | { | |
140 | case ISFUNC: | |
141 | break; | |
142 | ||
143 | case ISKMAP: | |
144 | rl_discard_keymap ((Keymap)map[i].function); | |
cc88a640 | 145 | xfree ((char *)map[i].function); |
d60d9f65 SS |
146 | break; |
147 | ||
148 | case ISMACR: | |
cc88a640 | 149 | xfree ((char *)map[i].function); |
d60d9f65 SS |
150 | break; |
151 | } | |
152 | } | |
153 | } | |
cc88a640 JK |
154 | |
155 | /* Convenience function that discards, then frees, MAP. */ | |
156 | void | |
157 | rl_free_keymap (map) | |
158 | Keymap map; | |
159 | { | |
160 | rl_discard_keymap (map); | |
161 | xfree ((char *)map); | |
162 | } |