1 /* $NetBSD: map.c,v 1.55 2022/10/30 19:11:31 christos Exp $ */
2
3 /*-
4 * Copyright (c) 1992, 1993
5 * The Regents of the University of California. All rights reserved.
6 *
7 * This code is derived from software contributed to Berkeley by
8 * Christos Zoulas of Cornell University.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. Neither the name of the University nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE.
33 */
34
35 #include "config.h"
36 #if !defined(lint) && !defined(SCCSID)
37 #if 0
38 static char sccsid[] = "@(#)map.c 8.1 (Berkeley) 6/4/93";
39 #else
40 __RCSID("$NetBSD: map.c,v 1.55 2022/10/30 19:11:31 christos Exp $");
41 #endif
42 #endif /* not lint && not SCCSID */
43
44 /*
45 * map.c: Editor function definitions
46 */
47 #include <ctype.h>
48 #include <stdlib.h>
49 #include <string.h>
50
51 #include "el.h"
52 #include "common.h"
53 #include "emacs.h"
54 #include "vi.h"
55 #include "fcns.h"
56 #include "func.h"
57 #include "help.h"
58 #include "parse.h"
59
60 static void map_print_key(EditLine *, el_action_t *, const wchar_t *);
61 static void map_print_some_keys(EditLine *, el_action_t *, wint_t, wint_t);
62 static void map_print_all_keys(EditLine *);
63 static void map_init_nls(EditLine *);
64 static void map_init_meta(EditLine *);
65
66 /* keymap tables ; should be N_KEYS*sizeof(KEYCMD) bytes long */
67
68
69 static const el_action_t el_map_emacs[] = {
70 /* 0 */ EM_SET_MARK, /* ^@ */
71 /* 1 */ ED_MOVE_TO_BEG, /* ^A */
72 /* 2 */ ED_PREV_CHAR, /* ^B */
73 /* 3 */ ED_IGNORE, /* ^C */
74 /* 4 */ EM_DELETE_OR_LIST, /* ^D */
75 /* 5 */ ED_MOVE_TO_END, /* ^E */
76 /* 6 */ ED_NEXT_CHAR, /* ^F */
77 /* 7 */ ED_UNASSIGNED, /* ^G */
78 /* 8 */ EM_DELETE_PREV_CHAR, /* ^H */
79 /* 9 */ ED_UNASSIGNED, /* ^I */
80 /* 10 */ ED_NEWLINE, /* ^J */
81 /* 11 */ ED_KILL_LINE, /* ^K */
82 /* 12 */ ED_CLEAR_SCREEN, /* ^L */
83 /* 13 */ ED_NEWLINE, /* ^M */
84 /* 14 */ ED_NEXT_HISTORY, /* ^N */
85 /* 15 */ ED_IGNORE, /* ^O */
86 /* 16 */ ED_PREV_HISTORY, /* ^P */
87 /* 17 */ ED_IGNORE, /* ^Q */
88 /* 18 */ EM_INC_SEARCH_PREV, /* ^R */
89 /* 19 */ ED_IGNORE, /* ^S */
90 /* 20 */ ED_TRANSPOSE_CHARS, /* ^T */
91 /* 21 */ EM_KILL_LINE, /* ^U */
92 /* 22 */ ED_QUOTED_INSERT, /* ^V */
93 /* 23 */ ED_DELETE_PREV_WORD, /* ^W */
94 /* 24 */ ED_SEQUENCE_LEAD_IN, /* ^X */
95 /* 25 */ EM_YANK, /* ^Y */
96 /* 26 */ ED_IGNORE, /* ^Z */
97 /* 27 */ EM_META_NEXT, /* ^[ */
98 /* 28 */ ED_IGNORE, /* ^\ */
99 /* 29 */ ED_IGNORE, /* ^] */
100 /* 30 */ ED_UNASSIGNED, /* ^^ */
101 /* 31 */ ED_UNASSIGNED, /* ^_ */
102 /* 32 */ ED_INSERT, /* SPACE */
103 /* 33 */ ED_INSERT, /* ! */
104 /* 34 */ ED_INSERT, /* " */
105 /* 35 */ ED_INSERT, /* # */
106 /* 36 */ ED_INSERT, /* $ */
107 /* 37 */ ED_INSERT, /* % */
108 /* 38 */ ED_INSERT, /* & */
109 /* 39 */ ED_INSERT, /* ' */
110 /* 40 */ ED_INSERT, /* ( */
111 /* 41 */ ED_INSERT, /* ) */
112 /* 42 */ ED_INSERT, /* * */
113 /* 43 */ ED_INSERT, /* + */
114 /* 44 */ ED_INSERT, /* , */
115 /* 45 */ ED_INSERT, /* - */
116 /* 46 */ ED_INSERT, /* . */
117 /* 47 */ ED_INSERT, /* / */
118 /* 48 */ ED_DIGIT, /* 0 */
119 /* 49 */ ED_DIGIT, /* 1 */
120 /* 50 */ ED_DIGIT, /* 2 */
121 /* 51 */ ED_DIGIT, /* 3 */
122 /* 52 */ ED_DIGIT, /* 4 */
123 /* 53 */ ED_DIGIT, /* 5 */
124 /* 54 */ ED_DIGIT, /* 6 */
125 /* 55 */ ED_DIGIT, /* 7 */
126 /* 56 */ ED_DIGIT, /* 8 */
127 /* 57 */ ED_DIGIT, /* 9 */
128 /* 58 */ ED_INSERT, /* : */
129 /* 59 */ ED_INSERT, /* ; */
130 /* 60 */ ED_INSERT, /* < */
131 /* 61 */ ED_INSERT, /* = */
132 /* 62 */ ED_INSERT, /* > */
133 /* 63 */ ED_INSERT, /* ? */
134 /* 64 */ ED_INSERT, /* @ */
135 /* 65 */ ED_INSERT, /* A */
136 /* 66 */ ED_INSERT, /* B */
137 /* 67 */ ED_INSERT, /* C */
138 /* 68 */ ED_INSERT, /* D */
139 /* 69 */ ED_INSERT, /* E */
140 /* 70 */ ED_INSERT, /* F */
141 /* 71 */ ED_INSERT, /* G */
142 /* 72 */ ED_INSERT, /* H */
143 /* 73 */ ED_INSERT, /* I */
144 /* 74 */ ED_INSERT, /* J */
145 /* 75 */ ED_INSERT, /* K */
146 /* 76 */ ED_INSERT, /* L */
147 /* 77 */ ED_INSERT, /* M */
148 /* 78 */ ED_INSERT, /* N */
149 /* 79 */ ED_INSERT, /* O */
150 /* 80 */ ED_INSERT, /* P */
151 /* 81 */ ED_INSERT, /* Q */
152 /* 82 */ ED_INSERT, /* R */
153 /* 83 */ ED_INSERT, /* S */
154 /* 84 */ ED_INSERT, /* T */
155 /* 85 */ ED_INSERT, /* U */
156 /* 86 */ ED_INSERT, /* V */
157 /* 87 */ ED_INSERT, /* W */
158 /* 88 */ ED_INSERT, /* X */
159 /* 89 */ ED_INSERT, /* Y */
160 /* 90 */ ED_INSERT, /* Z */
161 /* 91 */ ED_INSERT, /* [ */
162 /* 92 */ ED_INSERT, /* \ */
163 /* 93 */ ED_INSERT, /* ] */
164 /* 94 */ ED_INSERT, /* ^ */
165 /* 95 */ ED_INSERT, /* _ */
166 /* 96 */ ED_INSERT, /* ` */
167 /* 97 */ ED_INSERT, /* a */
168 /* 98 */ ED_INSERT, /* b */
169 /* 99 */ ED_INSERT, /* c */
170 /* 100 */ ED_INSERT, /* d */
171 /* 101 */ ED_INSERT, /* e */
172 /* 102 */ ED_INSERT, /* f */
173 /* 103 */ ED_INSERT, /* g */
174 /* 104 */ ED_INSERT, /* h */
175 /* 105 */ ED_INSERT, /* i */
176 /* 106 */ ED_INSERT, /* j */
177 /* 107 */ ED_INSERT, /* k */
178 /* 108 */ ED_INSERT, /* l */
179 /* 109 */ ED_INSERT, /* m */
180 /* 110 */ ED_INSERT, /* n */
181 /* 111 */ ED_INSERT, /* o */
182 /* 112 */ ED_INSERT, /* p */
183 /* 113 */ ED_INSERT, /* q */
184 /* 114 */ ED_INSERT, /* r */
185 /* 115 */ ED_INSERT, /* s */
186 /* 116 */ ED_INSERT, /* t */
187 /* 117 */ ED_INSERT, /* u */
188 /* 118 */ ED_INSERT, /* v */
189 /* 119 */ ED_INSERT, /* w */
190 /* 120 */ ED_INSERT, /* x */
191 /* 121 */ ED_INSERT, /* y */
192 /* 122 */ ED_INSERT, /* z */
193 /* 123 */ ED_INSERT, /* { */
194 /* 124 */ ED_INSERT, /* | */
195 /* 125 */ ED_INSERT, /* } */
196 /* 126 */ ED_INSERT, /* ~ */
197 /* 127 */ EM_DELETE_PREV_CHAR, /* ^? */
198 /* 128 */ ED_UNASSIGNED, /* M-^@ */
199 /* 129 */ ED_UNASSIGNED, /* M-^A */
200 /* 130 */ ED_UNASSIGNED, /* M-^B */
201 /* 131 */ ED_UNASSIGNED, /* M-^C */
202 /* 132 */ ED_UNASSIGNED, /* M-^D */
203 /* 133 */ ED_UNASSIGNED, /* M-^E */
204 /* 134 */ ED_UNASSIGNED, /* M-^F */
205 /* 135 */ ED_UNASSIGNED, /* M-^G */
206 /* 136 */ ED_DELETE_PREV_WORD, /* M-^H */
207 /* 137 */ ED_UNASSIGNED, /* M-^I */
208 /* 138 */ ED_UNASSIGNED, /* M-^J */
209 /* 139 */ ED_UNASSIGNED, /* M-^K */
210 /* 140 */ ED_CLEAR_SCREEN, /* M-^L */
211 /* 141 */ ED_UNASSIGNED, /* M-^M */
212 /* 142 */ ED_UNASSIGNED, /* M-^N */
213 /* 143 */ ED_UNASSIGNED, /* M-^O */
214 /* 144 */ ED_UNASSIGNED, /* M-^P */
215 /* 145 */ ED_UNASSIGNED, /* M-^Q */
216 /* 146 */ ED_UNASSIGNED, /* M-^R */
217 /* 147 */ ED_UNASSIGNED, /* M-^S */
218 /* 148 */ ED_UNASSIGNED, /* M-^T */
219 /* 149 */ ED_UNASSIGNED, /* M-^U */
220 /* 150 */ ED_UNASSIGNED, /* M-^V */
221 /* 151 */ ED_UNASSIGNED, /* M-^W */
222 /* 152 */ ED_UNASSIGNED, /* M-^X */
223 /* 153 */ ED_UNASSIGNED, /* M-^Y */
224 /* 154 */ ED_UNASSIGNED, /* M-^Z */
225 /* 155 */ ED_UNASSIGNED, /* M-^[ */
226 /* 156 */ ED_UNASSIGNED, /* M-^\ */
227 /* 157 */ ED_UNASSIGNED, /* M-^] */
228 /* 158 */ ED_UNASSIGNED, /* M-^^ */
229 /* 159 */ EM_COPY_PREV_WORD, /* M-^_ */
230 /* 160 */ ED_UNASSIGNED, /* M-SPACE */
231 /* 161 */ ED_UNASSIGNED, /* M-! */
232 /* 162 */ ED_UNASSIGNED, /* M-" */
233 /* 163 */ ED_UNASSIGNED, /* M-# */
234 /* 164 */ ED_UNASSIGNED, /* M-$ */
235 /* 165 */ ED_UNASSIGNED, /* M-% */
236 /* 166 */ ED_UNASSIGNED, /* M-& */
237 /* 167 */ ED_UNASSIGNED, /* M-' */
238 /* 168 */ ED_UNASSIGNED, /* M-( */
239 /* 169 */ ED_UNASSIGNED, /* M-) */
240 /* 170 */ ED_UNASSIGNED, /* M-* */
241 /* 171 */ ED_UNASSIGNED, /* M-+ */
242 /* 172 */ ED_UNASSIGNED, /* M-, */
243 /* 173 */ ED_UNASSIGNED, /* M-- */
244 /* 174 */ ED_UNASSIGNED, /* M-. */
245 /* 175 */ ED_UNASSIGNED, /* M-/ */
246 /* 176 */ ED_ARGUMENT_DIGIT, /* M-0 */
247 /* 177 */ ED_ARGUMENT_DIGIT, /* M-1 */
248 /* 178 */ ED_ARGUMENT_DIGIT, /* M-2 */
249 /* 179 */ ED_ARGUMENT_DIGIT, /* M-3 */
250 /* 180 */ ED_ARGUMENT_DIGIT, /* M-4 */
251 /* 181 */ ED_ARGUMENT_DIGIT, /* M-5 */
252 /* 182 */ ED_ARGUMENT_DIGIT, /* M-6 */
253 /* 183 */ ED_ARGUMENT_DIGIT, /* M-7 */
254 /* 184 */ ED_ARGUMENT_DIGIT, /* M-8 */
255 /* 185 */ ED_ARGUMENT_DIGIT, /* M-9 */
256 /* 186 */ ED_UNASSIGNED, /* M-: */
257 /* 187 */ ED_UNASSIGNED, /* M-; */
258 /* 188 */ ED_UNASSIGNED, /* M-< */
259 /* 189 */ ED_UNASSIGNED, /* M-= */
260 /* 190 */ ED_UNASSIGNED, /* M-> */
261 /* 191 */ ED_UNASSIGNED, /* M-? */
262 /* 192 */ ED_UNASSIGNED, /* M-@ */
263 /* 193 */ ED_UNASSIGNED, /* M-A */
264 /* 194 */ ED_PREV_WORD, /* M-B */
265 /* 195 */ EM_CAPITOL_CASE, /* M-C */
266 /* 196 */ EM_DELETE_NEXT_WORD, /* M-D */
267 /* 197 */ ED_UNASSIGNED, /* M-E */
268 /* 198 */ EM_NEXT_WORD, /* M-F */
269 /* 199 */ ED_UNASSIGNED, /* M-G */
270 /* 200 */ ED_UNASSIGNED, /* M-H */
271 /* 201 */ ED_UNASSIGNED, /* M-I */
272 /* 202 */ ED_UNASSIGNED, /* M-J */
273 /* 203 */ ED_UNASSIGNED, /* M-K */
274 /* 204 */ EM_LOWER_CASE, /* M-L */
275 /* 205 */ ED_UNASSIGNED, /* M-M */
276 /* 206 */ ED_SEARCH_NEXT_HISTORY, /* M-N */
277 /* 207 */ ED_SEQUENCE_LEAD_IN, /* M-O */
278 /* 208 */ ED_SEARCH_PREV_HISTORY, /* M-P */
279 /* 209 */ ED_UNASSIGNED, /* M-Q */
280 /* 210 */ ED_UNASSIGNED, /* M-R */
281 /* 211 */ ED_UNASSIGNED, /* M-S */
282 /* 212 */ ED_UNASSIGNED, /* M-T */
283 /* 213 */ EM_UPPER_CASE, /* M-U */
284 /* 214 */ ED_UNASSIGNED, /* M-V */
285 /* 215 */ EM_COPY_REGION, /* M-W */
286 /* 216 */ ED_COMMAND, /* M-X */
287 /* 217 */ ED_UNASSIGNED, /* M-Y */
288 /* 218 */ ED_UNASSIGNED, /* M-Z */
289 /* 219 */ ED_SEQUENCE_LEAD_IN, /* M-[ */
290 /* 220 */ ED_UNASSIGNED, /* M-\ */
291 /* 221 */ ED_UNASSIGNED, /* M-] */
292 /* 222 */ ED_UNASSIGNED, /* M-^ */
293 /* 223 */ ED_UNASSIGNED, /* M-_ */
294 /* 223 */ ED_UNASSIGNED, /* M-` */
295 /* 224 */ ED_UNASSIGNED, /* M-a */
296 /* 225 */ ED_PREV_WORD, /* M-b */
297 /* 226 */ EM_CAPITOL_CASE, /* M-c */
298 /* 227 */ EM_DELETE_NEXT_WORD, /* M-d */
299 /* 228 */ ED_UNASSIGNED, /* M-e */
300 /* 229 */ EM_NEXT_WORD, /* M-f */
301 /* 230 */ ED_UNASSIGNED, /* M-g */
302 /* 231 */ ED_UNASSIGNED, /* M-h */
303 /* 232 */ ED_UNASSIGNED, /* M-i */
304 /* 233 */ ED_UNASSIGNED, /* M-j */
305 /* 234 */ ED_UNASSIGNED, /* M-k */
306 /* 235 */ EM_LOWER_CASE, /* M-l */
307 /* 236 */ ED_UNASSIGNED, /* M-m */
308 /* 237 */ ED_SEARCH_NEXT_HISTORY, /* M-n */
309 /* 238 */ ED_UNASSIGNED, /* M-o */
310 /* 239 */ ED_SEARCH_PREV_HISTORY, /* M-p */
311 /* 240 */ ED_UNASSIGNED, /* M-q */
312 /* 241 */ ED_UNASSIGNED, /* M-r */
313 /* 242 */ ED_UNASSIGNED, /* M-s */
314 /* 243 */ ED_UNASSIGNED, /* M-t */
315 /* 244 */ EM_UPPER_CASE, /* M-u */
316 /* 245 */ ED_UNASSIGNED, /* M-v */
317 /* 246 */ EM_COPY_REGION, /* M-w */
318 /* 247 */ ED_COMMAND, /* M-x */
319 /* 248 */ ED_UNASSIGNED, /* M-y */
320 /* 249 */ ED_UNASSIGNED, /* M-z */
321 /* 250 */ ED_UNASSIGNED, /* M-{ */
322 /* 251 */ ED_UNASSIGNED, /* M-| */
323 /* 252 */ ED_UNASSIGNED, /* M-} */
324 /* 253 */ ED_UNASSIGNED, /* M-~ */
325 /* 254 */ ED_DELETE_PREV_WORD /* M-^? */
326 /* 255 */
327 };
328
329
330 /*
331 * keymap table for vi. Each index into above tbl; should be
332 * N_KEYS entries long. Vi mode uses a sticky-extend to do command mode:
333 * insert mode characters are in the normal keymap, and command mode
334 * in the extended keymap.
335 */
336 static const el_action_t el_map_vi_insert[] = {
337 #ifdef KSHVI
338 /* 0 */ ED_UNASSIGNED, /* ^@ */
339 /* 1 */ ED_INSERT, /* ^A */
340 /* 2 */ ED_INSERT, /* ^B */
341 /* 3 */ ED_INSERT, /* ^C */
342 /* 4 */ VI_LIST_OR_EOF, /* ^D */
343 /* 5 */ ED_INSERT, /* ^E */
344 /* 6 */ ED_INSERT, /* ^F */
345 /* 7 */ ED_INSERT, /* ^G */
346 /* 8 */ VI_DELETE_PREV_CHAR, /* ^H */ /* BackSpace key */
347 /* 9 */ ED_INSERT, /* ^I */ /* Tab Key */
348 /* 10 */ ED_NEWLINE, /* ^J */
349 /* 11 */ ED_INSERT, /* ^K */
350 /* 12 */ ED_INSERT, /* ^L */
351 /* 13 */ ED_NEWLINE, /* ^M */
352 /* 14 */ ED_INSERT, /* ^N */
353 /* 15 */ ED_INSERT, /* ^O */
354 /* 16 */ ED_INSERT, /* ^P */
355 /* 17 */ ED_IGNORE, /* ^Q */
356 /* 18 */ ED_INSERT, /* ^R */
357 /* 19 */ ED_IGNORE, /* ^S */
358 /* 20 */ ED_INSERT, /* ^T */
359 /* 21 */ VI_KILL_LINE_PREV, /* ^U */
360 /* 22 */ ED_QUOTED_INSERT, /* ^V */
361 /* 23 */ ED_DELETE_PREV_WORD, /* ^W */
362 /* ED_DELETE_PREV_WORD: Only until strt edit pos */
363 /* 24 */ ED_INSERT, /* ^X */
364 /* 25 */ ED_INSERT, /* ^Y */
365 /* 26 */ ED_INSERT, /* ^Z */
366 /* 27 */ VI_COMMAND_MODE, /* ^[ */ /* [ Esc ] key */
367 /* 28 */ ED_IGNORE, /* ^\ */
368 /* 29 */ ED_INSERT, /* ^] */
369 /* 30 */ ED_INSERT, /* ^^ */
370 /* 31 */ ED_INSERT, /* ^_ */
371 #else /* !KSHVI */
372 /*
373 * NOTE: These mappings do NOT Correspond well
374 * to the KSH VI editing assignments.
375 * On the other and they are convenient and
376 * many people have have gotten used to them.
377 */
378 /* 0 */ ED_UNASSIGNED, /* ^@ */
379 /* 1 */ ED_MOVE_TO_BEG, /* ^A */
380 /* 2 */ ED_PREV_CHAR, /* ^B */
381 /* 3 */ ED_IGNORE, /* ^C */
382 /* 4 */ VI_LIST_OR_EOF, /* ^D */
383 /* 5 */ ED_MOVE_TO_END, /* ^E */
384 /* 6 */ ED_NEXT_CHAR, /* ^F */
385 /* 7 */ ED_UNASSIGNED, /* ^G */
386 /* 8 */ VI_DELETE_PREV_CHAR, /* ^H */ /* BackSpace key */
387 /* 9 */ ED_UNASSIGNED, /* ^I */ /* Tab Key */
388 /* 10 */ ED_NEWLINE, /* ^J */
389 /* 11 */ ED_KILL_LINE, /* ^K */
390 /* 12 */ ED_CLEAR_SCREEN, /* ^L */
391 /* 13 */ ED_NEWLINE, /* ^M */
392 /* 14 */ ED_NEXT_HISTORY, /* ^N */
393 /* 15 */ ED_IGNORE, /* ^O */
394 /* 16 */ ED_PREV_HISTORY, /* ^P */
395 /* 17 */ ED_IGNORE, /* ^Q */
396 /* 18 */ ED_REDISPLAY, /* ^R */
397 /* 19 */ ED_IGNORE, /* ^S */
398 /* 20 */ ED_TRANSPOSE_CHARS, /* ^T */
399 /* 21 */ VI_KILL_LINE_PREV, /* ^U */
400 /* 22 */ ED_QUOTED_INSERT, /* ^V */
401 /* 23 */ ED_DELETE_PREV_WORD, /* ^W */
402 /* 24 */ ED_UNASSIGNED, /* ^X */
403 /* 25 */ ED_IGNORE, /* ^Y */
404 /* 26 */ ED_IGNORE, /* ^Z */
405 /* 27 */ VI_COMMAND_MODE, /* ^[ */
406 /* 28 */ ED_IGNORE, /* ^\ */
407 /* 29 */ ED_UNASSIGNED, /* ^] */
408 /* 30 */ ED_UNASSIGNED, /* ^^ */
409 /* 31 */ ED_UNASSIGNED, /* ^_ */
410 #endif /* KSHVI */
411 /* 32 */ ED_INSERT, /* SPACE */
412 /* 33 */ ED_INSERT, /* ! */
413 /* 34 */ ED_INSERT, /* " */
414 /* 35 */ ED_INSERT, /* # */
415 /* 36 */ ED_INSERT, /* $ */
416 /* 37 */ ED_INSERT, /* % */
417 /* 38 */ ED_INSERT, /* & */
418 /* 39 */ ED_INSERT, /* ' */
419 /* 40 */ ED_INSERT, /* ( */
420 /* 41 */ ED_INSERT, /* ) */
421 /* 42 */ ED_INSERT, /* * */
422 /* 43 */ ED_INSERT, /* + */
423 /* 44 */ ED_INSERT, /* , */
424 /* 45 */ ED_INSERT, /* - */
425 /* 46 */ ED_INSERT, /* . */
426 /* 47 */ ED_INSERT, /* / */
427 /* 48 */ ED_INSERT, /* 0 */
428 /* 49 */ ED_INSERT, /* 1 */
429 /* 50 */ ED_INSERT, /* 2 */
430 /* 51 */ ED_INSERT, /* 3 */
431 /* 52 */ ED_INSERT, /* 4 */
432 /* 53 */ ED_INSERT, /* 5 */
433 /* 54 */ ED_INSERT, /* 6 */
434 /* 55 */ ED_INSERT, /* 7 */
435 /* 56 */ ED_INSERT, /* 8 */
436 /* 57 */ ED_INSERT, /* 9 */
437 /* 58 */ ED_INSERT, /* : */
438 /* 59 */ ED_INSERT, /* ; */
439 /* 60 */ ED_INSERT, /* < */
440 /* 61 */ ED_INSERT, /* = */
441 /* 62 */ ED_INSERT, /* > */
442 /* 63 */ ED_INSERT, /* ? */
443 /* 64 */ ED_INSERT, /* @ */
444 /* 65 */ ED_INSERT, /* A */
445 /* 66 */ ED_INSERT, /* B */
446 /* 67 */ ED_INSERT, /* C */
447 /* 68 */ ED_INSERT, /* D */
448 /* 69 */ ED_INSERT, /* E */
449 /* 70 */ ED_INSERT, /* F */
450 /* 71 */ ED_INSERT, /* G */
451 /* 72 */ ED_INSERT, /* H */
452 /* 73 */ ED_INSERT, /* I */
453 /* 74 */ ED_INSERT, /* J */
454 /* 75 */ ED_INSERT, /* K */
455 /* 76 */ ED_INSERT, /* L */
456 /* 77 */ ED_INSERT, /* M */
457 /* 78 */ ED_INSERT, /* N */
458 /* 79 */ ED_INSERT, /* O */
459 /* 80 */ ED_INSERT, /* P */
460 /* 81 */ ED_INSERT, /* Q */
461 /* 82 */ ED_INSERT, /* R */
462 /* 83 */ ED_INSERT, /* S */
463 /* 84 */ ED_INSERT, /* T */
464 /* 85 */ ED_INSERT, /* U */
465 /* 86 */ ED_INSERT, /* V */
466 /* 87 */ ED_INSERT, /* W */
467 /* 88 */ ED_INSERT, /* X */
468 /* 89 */ ED_INSERT, /* Y */
469 /* 90 */ ED_INSERT, /* Z */
470 /* 91 */ ED_INSERT, /* [ */
471 /* 92 */ ED_INSERT, /* \ */
472 /* 93 */ ED_INSERT, /* ] */
473 /* 94 */ ED_INSERT, /* ^ */
474 /* 95 */ ED_INSERT, /* _ */
475 /* 96 */ ED_INSERT, /* ` */
476 /* 97 */ ED_INSERT, /* a */
477 /* 98 */ ED_INSERT, /* b */
478 /* 99 */ ED_INSERT, /* c */
479 /* 100 */ ED_INSERT, /* d */
480 /* 101 */ ED_INSERT, /* e */
481 /* 102 */ ED_INSERT, /* f */
482 /* 103 */ ED_INSERT, /* g */
483 /* 104 */ ED_INSERT, /* h */
484 /* 105 */ ED_INSERT, /* i */
485 /* 106 */ ED_INSERT, /* j */
486 /* 107 */ ED_INSERT, /* k */
487 /* 108 */ ED_INSERT, /* l */
488 /* 109 */ ED_INSERT, /* m */
489 /* 110 */ ED_INSERT, /* n */
490 /* 111 */ ED_INSERT, /* o */
491 /* 112 */ ED_INSERT, /* p */
492 /* 113 */ ED_INSERT, /* q */
493 /* 114 */ ED_INSERT, /* r */
494 /* 115 */ ED_INSERT, /* s */
495 /* 116 */ ED_INSERT, /* t */
496 /* 117 */ ED_INSERT, /* u */
497 /* 118 */ ED_INSERT, /* v */
498 /* 119 */ ED_INSERT, /* w */
499 /* 120 */ ED_INSERT, /* x */
500 /* 121 */ ED_INSERT, /* y */
501 /* 122 */ ED_INSERT, /* z */
502 /* 123 */ ED_INSERT, /* { */
503 /* 124 */ ED_INSERT, /* | */
504 /* 125 */ ED_INSERT, /* } */
505 /* 126 */ ED_INSERT, /* ~ */
506 /* 127 */ VI_DELETE_PREV_CHAR, /* ^? */
507 /* 128 */ ED_INSERT, /* M-^@ */
508 /* 129 */ ED_INSERT, /* M-^A */
509 /* 130 */ ED_INSERT, /* M-^B */
510 /* 131 */ ED_INSERT, /* M-^C */
511 /* 132 */ ED_INSERT, /* M-^D */
512 /* 133 */ ED_INSERT, /* M-^E */
513 /* 134 */ ED_INSERT, /* M-^F */
514 /* 135 */ ED_INSERT, /* M-^G */
515 /* 136 */ ED_INSERT, /* M-^H */
516 /* 137 */ ED_INSERT, /* M-^I */
517 /* 138 */ ED_INSERT, /* M-^J */
518 /* 139 */ ED_INSERT, /* M-^K */
519 /* 140 */ ED_INSERT, /* M-^L */
520 /* 141 */ ED_INSERT, /* M-^M */
521 /* 142 */ ED_INSERT, /* M-^N */
522 /* 143 */ ED_INSERT, /* M-^O */
523 /* 144 */ ED_INSERT, /* M-^P */
524 /* 145 */ ED_INSERT, /* M-^Q */
525 /* 146 */ ED_INSERT, /* M-^R */
526 /* 147 */ ED_INSERT, /* M-^S */
527 /* 148 */ ED_INSERT, /* M-^T */
528 /* 149 */ ED_INSERT, /* M-^U */
529 /* 150 */ ED_INSERT, /* M-^V */
530 /* 151 */ ED_INSERT, /* M-^W */
531 /* 152 */ ED_INSERT, /* M-^X */
532 /* 153 */ ED_INSERT, /* M-^Y */
533 /* 154 */ ED_INSERT, /* M-^Z */
534 /* 155 */ ED_INSERT, /* M-^[ */
535 /* 156 */ ED_INSERT, /* M-^\ */
536 /* 157 */ ED_INSERT, /* M-^] */
537 /* 158 */ ED_INSERT, /* M-^^ */
538 /* 159 */ ED_INSERT, /* M-^_ */
539 /* 160 */ ED_INSERT, /* M-SPACE */
540 /* 161 */ ED_INSERT, /* M-! */
541 /* 162 */ ED_INSERT, /* M-" */
542 /* 163 */ ED_INSERT, /* M-# */
543 /* 164 */ ED_INSERT, /* M-$ */
544 /* 165 */ ED_INSERT, /* M-% */
545 /* 166 */ ED_INSERT, /* M-& */
546 /* 167 */ ED_INSERT, /* M-' */
547 /* 168 */ ED_INSERT, /* M-( */
548 /* 169 */ ED_INSERT, /* M-) */
549 /* 170 */ ED_INSERT, /* M-* */
550 /* 171 */ ED_INSERT, /* M-+ */
551 /* 172 */ ED_INSERT, /* M-, */
552 /* 173 */ ED_INSERT, /* M-- */
553 /* 174 */ ED_INSERT, /* M-. */
554 /* 175 */ ED_INSERT, /* M-/ */
555 /* 176 */ ED_INSERT, /* M-0 */
556 /* 177 */ ED_INSERT, /* M-1 */
557 /* 178 */ ED_INSERT, /* M-2 */
558 /* 179 */ ED_INSERT, /* M-3 */
559 /* 180 */ ED_INSERT, /* M-4 */
560 /* 181 */ ED_INSERT, /* M-5 */
561 /* 182 */ ED_INSERT, /* M-6 */
562 /* 183 */ ED_INSERT, /* M-7 */
563 /* 184 */ ED_INSERT, /* M-8 */
564 /* 185 */ ED_INSERT, /* M-9 */
565 /* 186 */ ED_INSERT, /* M-: */
566 /* 187 */ ED_INSERT, /* M-; */
567 /* 188 */ ED_INSERT, /* M-< */
568 /* 189 */ ED_INSERT, /* M-= */
569 /* 190 */ ED_INSERT, /* M-> */
570 /* 191 */ ED_INSERT, /* M-? */
571 /* 192 */ ED_INSERT, /* M-@ */
572 /* 193 */ ED_INSERT, /* M-A */
573 /* 194 */ ED_INSERT, /* M-B */
574 /* 195 */ ED_INSERT, /* M-C */
575 /* 196 */ ED_INSERT, /* M-D */
576 /* 197 */ ED_INSERT, /* M-E */
577 /* 198 */ ED_INSERT, /* M-F */
578 /* 199 */ ED_INSERT, /* M-G */
579 /* 200 */ ED_INSERT, /* M-H */
580 /* 201 */ ED_INSERT, /* M-I */
581 /* 202 */ ED_INSERT, /* M-J */
582 /* 203 */ ED_INSERT, /* M-K */
583 /* 204 */ ED_INSERT, /* M-L */
584 /* 205 */ ED_INSERT, /* M-M */
585 /* 206 */ ED_INSERT, /* M-N */
586 /* 207 */ ED_INSERT, /* M-O */
587 /* 208 */ ED_INSERT, /* M-P */
588 /* 209 */ ED_INSERT, /* M-Q */
589 /* 210 */ ED_INSERT, /* M-R */
590 /* 211 */ ED_INSERT, /* M-S */
591 /* 212 */ ED_INSERT, /* M-T */
592 /* 213 */ ED_INSERT, /* M-U */
593 /* 214 */ ED_INSERT, /* M-V */
594 /* 215 */ ED_INSERT, /* M-W */
595 /* 216 */ ED_INSERT, /* M-X */
596 /* 217 */ ED_INSERT, /* M-Y */
597 /* 218 */ ED_INSERT, /* M-Z */
598 /* 219 */ ED_INSERT, /* M-[ */
599 /* 220 */ ED_INSERT, /* M-\ */
600 /* 221 */ ED_INSERT, /* M-] */
601 /* 222 */ ED_INSERT, /* M-^ */
602 /* 223 */ ED_INSERT, /* M-_ */
603 /* 224 */ ED_INSERT, /* M-` */
604 /* 225 */ ED_INSERT, /* M-a */
605 /* 226 */ ED_INSERT, /* M-b */
606 /* 227 */ ED_INSERT, /* M-c */
607 /* 228 */ ED_INSERT, /* M-d */
608 /* 229 */ ED_INSERT, /* M-e */
609 /* 230 */ ED_INSERT, /* M-f */
610 /* 231 */ ED_INSERT, /* M-g */
611 /* 232 */ ED_INSERT, /* M-h */
612 /* 233 */ ED_INSERT, /* M-i */
613 /* 234 */ ED_INSERT, /* M-j */
614 /* 235 */ ED_INSERT, /* M-k */
615 /* 236 */ ED_INSERT, /* M-l */
616 /* 237 */ ED_INSERT, /* M-m */
617 /* 238 */ ED_INSERT, /* M-n */
618 /* 239 */ ED_INSERT, /* M-o */
619 /* 240 */ ED_INSERT, /* M-p */
620 /* 241 */ ED_INSERT, /* M-q */
621 /* 242 */ ED_INSERT, /* M-r */
622 /* 243 */ ED_INSERT, /* M-s */
623 /* 244 */ ED_INSERT, /* M-t */
624 /* 245 */ ED_INSERT, /* M-u */
625 /* 246 */ ED_INSERT, /* M-v */
626 /* 247 */ ED_INSERT, /* M-w */
627 /* 248 */ ED_INSERT, /* M-x */
628 /* 249 */ ED_INSERT, /* M-y */
629 /* 250 */ ED_INSERT, /* M-z */
630 /* 251 */ ED_INSERT, /* M-{ */
631 /* 252 */ ED_INSERT, /* M-| */
632 /* 253 */ ED_INSERT, /* M-} */
633 /* 254 */ ED_INSERT, /* M-~ */
634 /* 255 */ ED_INSERT /* M-^? */
635 };
636
637 static const el_action_t el_map_vi_command[] = {
638 /* 0 */ ED_UNASSIGNED, /* ^@ */
639 /* 1 */ ED_MOVE_TO_BEG, /* ^A */
640 /* 2 */ ED_UNASSIGNED, /* ^B */
641 /* 3 */ ED_IGNORE, /* ^C */
642 /* 4 */ ED_UNASSIGNED, /* ^D */
643 /* 5 */ ED_MOVE_TO_END, /* ^E */
644 /* 6 */ ED_UNASSIGNED, /* ^F */
645 /* 7 */ ED_UNASSIGNED, /* ^G */
646 /* 8 */ ED_DELETE_PREV_CHAR, /* ^H */
647 /* 9 */ ED_UNASSIGNED, /* ^I */
648 /* 10 */ ED_NEWLINE, /* ^J */
649 /* 11 */ ED_KILL_LINE, /* ^K */
650 /* 12 */ ED_CLEAR_SCREEN, /* ^L */
651 /* 13 */ ED_NEWLINE, /* ^M */
652 /* 14 */ ED_NEXT_HISTORY, /* ^N */
653 /* 15 */ ED_IGNORE, /* ^O */
654 /* 16 */ ED_PREV_HISTORY, /* ^P */
655 /* 17 */ ED_IGNORE, /* ^Q */
656 /* 18 */ ED_REDISPLAY, /* ^R */
657 /* 19 */ ED_IGNORE, /* ^S */
658 /* 20 */ ED_UNASSIGNED, /* ^T */
659 /* 21 */ VI_KILL_LINE_PREV, /* ^U */
660 /* 22 */ ED_UNASSIGNED, /* ^V */
661 /* 23 */ ED_DELETE_PREV_WORD, /* ^W */
662 /* 24 */ ED_UNASSIGNED, /* ^X */
663 /* 25 */ ED_UNASSIGNED, /* ^Y */
664 /* 26 */ ED_UNASSIGNED, /* ^Z */
665 /* 27 */ EM_META_NEXT, /* ^[ */
666 /* 28 */ ED_IGNORE, /* ^\ */
667 /* 29 */ ED_UNASSIGNED, /* ^] */
668 /* 30 */ ED_UNASSIGNED, /* ^^ */
669 /* 31 */ ED_UNASSIGNED, /* ^_ */
670 /* 32 */ ED_NEXT_CHAR, /* SPACE */
671 /* 33 */ ED_UNASSIGNED, /* ! */
672 /* 34 */ ED_UNASSIGNED, /* " */
673 /* 35 */ VI_COMMENT_OUT, /* # */
674 /* 36 */ ED_MOVE_TO_END, /* $ */
675 /* 37 */ VI_MATCH, /* % */
676 /* 38 */ ED_UNASSIGNED, /* & */
677 /* 39 */ ED_UNASSIGNED, /* ' */
678 /* 40 */ ED_UNASSIGNED, /* ( */
679 /* 41 */ ED_UNASSIGNED, /* ) */
680 /* 42 */ ED_UNASSIGNED, /* * */
681 /* 43 */ ED_NEXT_HISTORY, /* + */
682 /* 44 */ VI_REPEAT_PREV_CHAR, /* , */
683 /* 45 */ ED_PREV_HISTORY, /* - */
684 /* 46 */ VI_REDO, /* . */
685 /* 47 */ VI_SEARCH_PREV, /* / */
686 /* 48 */ VI_ZERO, /* 0 */
687 /* 49 */ ED_ARGUMENT_DIGIT, /* 1 */
688 /* 50 */ ED_ARGUMENT_DIGIT, /* 2 */
689 /* 51 */ ED_ARGUMENT_DIGIT, /* 3 */
690 /* 52 */ ED_ARGUMENT_DIGIT, /* 4 */
691 /* 53 */ ED_ARGUMENT_DIGIT, /* 5 */
692 /* 54 */ ED_ARGUMENT_DIGIT, /* 6 */
693 /* 55 */ ED_ARGUMENT_DIGIT, /* 7 */
694 /* 56 */ ED_ARGUMENT_DIGIT, /* 8 */
695 /* 57 */ ED_ARGUMENT_DIGIT, /* 9 */
696 /* 58 */ ED_COMMAND, /* : */
697 /* 59 */ VI_REPEAT_NEXT_CHAR, /* ; */
698 /* 60 */ ED_UNASSIGNED, /* < */
699 /* 61 */ ED_UNASSIGNED, /* = */
700 /* 62 */ ED_UNASSIGNED, /* > */
701 /* 63 */ VI_SEARCH_NEXT, /* ? */
702 /* 64 */ VI_ALIAS, /* @ */
703 /* 65 */ VI_ADD_AT_EOL, /* A */
704 /* 66 */ VI_PREV_BIG_WORD, /* B */
705 /* 67 */ VI_CHANGE_TO_EOL, /* C */
706 /* 68 */ ED_KILL_LINE, /* D */
707 /* 69 */ VI_END_BIG_WORD, /* E */
708 /* 70 */ VI_PREV_CHAR, /* F */
709 /* 71 */ VI_TO_HISTORY_LINE, /* G */
710 /* 72 */ ED_UNASSIGNED, /* H */
711 /* 73 */ VI_INSERT_AT_BOL, /* I */
712 /* 74 */ ED_SEARCH_NEXT_HISTORY, /* J */
713 /* 75 */ ED_SEARCH_PREV_HISTORY, /* K */
714 /* 76 */ ED_UNASSIGNED, /* L */
715 /* 77 */ ED_UNASSIGNED, /* M */
716 /* 78 */ VI_REPEAT_SEARCH_PREV, /* N */
717 /* 79 */ ED_SEQUENCE_LEAD_IN, /* O */
718 /* 80 */ VI_PASTE_PREV, /* P */
719 /* 81 */ ED_UNASSIGNED, /* Q */
720 /* 82 */ VI_REPLACE_MODE, /* R */
721 /* 83 */ VI_SUBSTITUTE_LINE, /* S */
722 /* 84 */ VI_TO_PREV_CHAR, /* T */
723 /* 85 */ VI_UNDO_LINE, /* U */
724 /* 86 */ ED_UNASSIGNED, /* V */
725 /* 87 */ VI_NEXT_BIG_WORD, /* W */
726 /* 88 */ ED_DELETE_PREV_CHAR, /* X */
727 /* 89 */ VI_YANK_END, /* Y */
728 /* 90 */ ED_UNASSIGNED, /* Z */
729 /* 91 */ ED_SEQUENCE_LEAD_IN, /* [ */
730 /* 92 */ ED_UNASSIGNED, /* \ */
731 /* 93 */ ED_UNASSIGNED, /* ] */
732 /* 94 */ ED_MOVE_TO_BEG, /* ^ */
733 /* 95 */ VI_HISTORY_WORD, /* _ */
734 /* 96 */ ED_UNASSIGNED, /* ` */
735 /* 97 */ VI_ADD, /* a */
736 /* 98 */ VI_PREV_WORD, /* b */
737 /* 99 */ VI_CHANGE_META, /* c */
738 /* 100 */ VI_DELETE_META, /* d */
739 /* 101 */ VI_END_WORD, /* e */
740 /* 102 */ VI_NEXT_CHAR, /* f */
741 /* 103 */ ED_UNASSIGNED, /* g */
742 /* 104 */ ED_PREV_CHAR, /* h */
743 /* 105 */ VI_INSERT, /* i */
744 /* 106 */ ED_NEXT_HISTORY, /* j */
745 /* 107 */ ED_PREV_HISTORY, /* k */
746 /* 108 */ ED_NEXT_CHAR, /* l */
747 /* 109 */ ED_UNASSIGNED, /* m */
748 /* 110 */ VI_REPEAT_SEARCH_NEXT, /* n */
749 /* 111 */ ED_UNASSIGNED, /* o */
750 /* 112 */ VI_PASTE_NEXT, /* p */
751 /* 113 */ ED_UNASSIGNED, /* q */
752 /* 114 */ VI_REPLACE_CHAR, /* r */
753 /* 115 */ VI_SUBSTITUTE_CHAR, /* s */
754 /* 116 */ VI_TO_NEXT_CHAR, /* t */
755 /* 117 */ VI_UNDO, /* u */
756 /* 118 */ VI_HISTEDIT, /* v */
757 /* 119 */ VI_NEXT_WORD, /* w */
758 /* 120 */ ED_DELETE_NEXT_CHAR, /* x */
759 /* 121 */ VI_YANK, /* y */
760 /* 122 */ ED_UNASSIGNED, /* z */
761 /* 123 */ ED_UNASSIGNED, /* { */
762 /* 124 */ VI_TO_COLUMN, /* | */
763 /* 125 */ ED_UNASSIGNED, /* } */
764 /* 126 */ VI_CHANGE_CASE, /* ~ */
765 /* 127 */ ED_DELETE_PREV_CHAR, /* ^? */
766 /* 128 */ ED_UNASSIGNED, /* M-^@ */
767 /* 129 */ ED_UNASSIGNED, /* M-^A */
768 /* 130 */ ED_UNASSIGNED, /* M-^B */
769 /* 131 */ ED_UNASSIGNED, /* M-^C */
770 /* 132 */ ED_UNASSIGNED, /* M-^D */
771 /* 133 */ ED_UNASSIGNED, /* M-^E */
772 /* 134 */ ED_UNASSIGNED, /* M-^F */
773 /* 135 */ ED_UNASSIGNED, /* M-^G */
774 /* 136 */ ED_UNASSIGNED, /* M-^H */
775 /* 137 */ ED_UNASSIGNED, /* M-^I */
776 /* 138 */ ED_UNASSIGNED, /* M-^J */
777 /* 139 */ ED_UNASSIGNED, /* M-^K */
778 /* 140 */ ED_UNASSIGNED, /* M-^L */
779 /* 141 */ ED_UNASSIGNED, /* M-^M */
780 /* 142 */ ED_UNASSIGNED, /* M-^N */
781 /* 143 */ ED_UNASSIGNED, /* M-^O */
782 /* 144 */ ED_UNASSIGNED, /* M-^P */
783 /* 145 */ ED_UNASSIGNED, /* M-^Q */
784 /* 146 */ ED_UNASSIGNED, /* M-^R */
785 /* 147 */ ED_UNASSIGNED, /* M-^S */
786 /* 148 */ ED_UNASSIGNED, /* M-^T */
787 /* 149 */ ED_UNASSIGNED, /* M-^U */
788 /* 150 */ ED_UNASSIGNED, /* M-^V */
789 /* 151 */ ED_UNASSIGNED, /* M-^W */
790 /* 152 */ ED_UNASSIGNED, /* M-^X */
791 /* 153 */ ED_UNASSIGNED, /* M-^Y */
792 /* 154 */ ED_UNASSIGNED, /* M-^Z */
793 /* 155 */ ED_UNASSIGNED, /* M-^[ */
794 /* 156 */ ED_UNASSIGNED, /* M-^\ */
795 /* 157 */ ED_UNASSIGNED, /* M-^] */
796 /* 158 */ ED_UNASSIGNED, /* M-^^ */
797 /* 159 */ ED_UNASSIGNED, /* M-^_ */
798 /* 160 */ ED_UNASSIGNED, /* M-SPACE */
799 /* 161 */ ED_UNASSIGNED, /* M-! */
800 /* 162 */ ED_UNASSIGNED, /* M-" */
801 /* 163 */ ED_UNASSIGNED, /* M-# */
802 /* 164 */ ED_UNASSIGNED, /* M-$ */
803 /* 165 */ ED_UNASSIGNED, /* M-% */
804 /* 166 */ ED_UNASSIGNED, /* M-& */
805 /* 167 */ ED_UNASSIGNED, /* M-' */
806 /* 168 */ ED_UNASSIGNED, /* M-( */
807 /* 169 */ ED_UNASSIGNED, /* M-) */
808 /* 170 */ ED_UNASSIGNED, /* M-* */
809 /* 171 */ ED_UNASSIGNED, /* M-+ */
810 /* 172 */ ED_UNASSIGNED, /* M-, */
811 /* 173 */ ED_UNASSIGNED, /* M-- */
812 /* 174 */ ED_UNASSIGNED, /* M-. */
813 /* 175 */ ED_UNASSIGNED, /* M-/ */
814 /* 176 */ ED_UNASSIGNED, /* M-0 */
815 /* 177 */ ED_UNASSIGNED, /* M-1 */
816 /* 178 */ ED_UNASSIGNED, /* M-2 */
817 /* 179 */ ED_UNASSIGNED, /* M-3 */
818 /* 180 */ ED_UNASSIGNED, /* M-4 */
819 /* 181 */ ED_UNASSIGNED, /* M-5 */
820 /* 182 */ ED_UNASSIGNED, /* M-6 */
821 /* 183 */ ED_UNASSIGNED, /* M-7 */
822 /* 184 */ ED_UNASSIGNED, /* M-8 */
823 /* 185 */ ED_UNASSIGNED, /* M-9 */
824 /* 186 */ ED_UNASSIGNED, /* M-: */
825 /* 187 */ ED_UNASSIGNED, /* M-; */
826 /* 188 */ ED_UNASSIGNED, /* M-< */
827 /* 189 */ ED_UNASSIGNED, /* M-= */
828 /* 190 */ ED_UNASSIGNED, /* M-> */
829 /* 191 */ ED_UNASSIGNED, /* M-? */
830 /* 192 */ ED_UNASSIGNED, /* M-@ */
831 /* 193 */ ED_UNASSIGNED, /* M-A */
832 /* 194 */ ED_UNASSIGNED, /* M-B */
833 /* 195 */ ED_UNASSIGNED, /* M-C */
834 /* 196 */ ED_UNASSIGNED, /* M-D */
835 /* 197 */ ED_UNASSIGNED, /* M-E */
836 /* 198 */ ED_UNASSIGNED, /* M-F */
837 /* 199 */ ED_UNASSIGNED, /* M-G */
838 /* 200 */ ED_UNASSIGNED, /* M-H */
839 /* 201 */ ED_UNASSIGNED, /* M-I */
840 /* 202 */ ED_UNASSIGNED, /* M-J */
841 /* 203 */ ED_UNASSIGNED, /* M-K */
842 /* 204 */ ED_UNASSIGNED, /* M-L */
843 /* 205 */ ED_UNASSIGNED, /* M-M */
844 /* 206 */ ED_UNASSIGNED, /* M-N */
845 /* 207 */ ED_SEQUENCE_LEAD_IN, /* M-O */
846 /* 208 */ ED_UNASSIGNED, /* M-P */
847 /* 209 */ ED_UNASSIGNED, /* M-Q */
848 /* 210 */ ED_UNASSIGNED, /* M-R */
849 /* 211 */ ED_UNASSIGNED, /* M-S */
850 /* 212 */ ED_UNASSIGNED, /* M-T */
851 /* 213 */ ED_UNASSIGNED, /* M-U */
852 /* 214 */ ED_UNASSIGNED, /* M-V */
853 /* 215 */ ED_UNASSIGNED, /* M-W */
854 /* 216 */ ED_UNASSIGNED, /* M-X */
855 /* 217 */ ED_UNASSIGNED, /* M-Y */
856 /* 218 */ ED_UNASSIGNED, /* M-Z */
857 /* 219 */ ED_SEQUENCE_LEAD_IN, /* M-[ */
858 /* 220 */ ED_UNASSIGNED, /* M-\ */
859 /* 221 */ ED_UNASSIGNED, /* M-] */
860 /* 222 */ ED_UNASSIGNED, /* M-^ */
861 /* 223 */ ED_UNASSIGNED, /* M-_ */
862 /* 224 */ ED_UNASSIGNED, /* M-` */
863 /* 225 */ ED_UNASSIGNED, /* M-a */
864 /* 226 */ ED_UNASSIGNED, /* M-b */
865 /* 227 */ ED_UNASSIGNED, /* M-c */
866 /* 228 */ ED_UNASSIGNED, /* M-d */
867 /* 229 */ ED_UNASSIGNED, /* M-e */
868 /* 230 */ ED_UNASSIGNED, /* M-f */
869 /* 231 */ ED_UNASSIGNED, /* M-g */
870 /* 232 */ ED_UNASSIGNED, /* M-h */
871 /* 233 */ ED_UNASSIGNED, /* M-i */
872 /* 234 */ ED_UNASSIGNED, /* M-j */
873 /* 235 */ ED_UNASSIGNED, /* M-k */
874 /* 236 */ ED_UNASSIGNED, /* M-l */
875 /* 237 */ ED_UNASSIGNED, /* M-m */
876 /* 238 */ ED_UNASSIGNED, /* M-n */
877 /* 239 */ ED_UNASSIGNED, /* M-o */
878 /* 240 */ ED_UNASSIGNED, /* M-p */
879 /* 241 */ ED_UNASSIGNED, /* M-q */
880 /* 242 */ ED_UNASSIGNED, /* M-r */
881 /* 243 */ ED_UNASSIGNED, /* M-s */
882 /* 244 */ ED_UNASSIGNED, /* M-t */
883 /* 245 */ ED_UNASSIGNED, /* M-u */
884 /* 246 */ ED_UNASSIGNED, /* M-v */
885 /* 247 */ ED_UNASSIGNED, /* M-w */
886 /* 248 */ ED_UNASSIGNED, /* M-x */
887 /* 249 */ ED_UNASSIGNED, /* M-y */
888 /* 250 */ ED_UNASSIGNED, /* M-z */
889 /* 251 */ ED_UNASSIGNED, /* M-{ */
890 /* 252 */ ED_UNASSIGNED, /* M-| */
891 /* 253 */ ED_UNASSIGNED, /* M-} */
892 /* 254 */ ED_UNASSIGNED, /* M-~ */
893 /* 255 */ ED_UNASSIGNED /* M-^? */
894 };
895
896
897 /* map_init():
898 * Initialize and allocate the maps
899 */
900 libedit_private int
map_init(EditLine * el)901 map_init(EditLine *el)
902 {
903
904 /*
905 * Make sure those are correct before starting.
906 */
907 #ifdef MAP_DEBUG
908 if (sizeof(el_map_emacs) != N_KEYS * sizeof(el_action_t))
909 EL_ABORT((el->el_errfile, "Emacs map incorrect\n"));
910 if (sizeof(el_map_vi_command) != N_KEYS * sizeof(el_action_t))
911 EL_ABORT((el->el_errfile, "Vi command map incorrect\n"));
912 if (sizeof(el_map_vi_insert) != N_KEYS * sizeof(el_action_t))
913 EL_ABORT((el->el_errfile, "Vi insert map incorrect\n"));
914 #endif
915
916 el->el_map.alt = el_calloc(N_KEYS, sizeof(*el->el_map.alt));
917 if (el->el_map.alt == NULL)
918 return -1;
919 el->el_map.key = el_calloc(N_KEYS, sizeof(*el->el_map.key));
920 if (el->el_map.key == NULL)
921 goto out;
922 el->el_map.emacs = el_map_emacs;
923 el->el_map.vic = el_map_vi_command;
924 el->el_map.vii = el_map_vi_insert;
925 el->el_map.help = el_calloc(EL_NUM_FCNS, sizeof(*el->el_map.help));
926 if (el->el_map.help == NULL)
927 goto out;
928 (void) memcpy(el->el_map.help, el_func_help,
929 sizeof(*el->el_map.help) * EL_NUM_FCNS);
930 el->el_map.func = el_calloc(EL_NUM_FCNS, sizeof(*el->el_map.func));
931 if (el->el_map.func == NULL)
932 goto out;
933 memcpy(el->el_map.func, el_func, sizeof(*el->el_map.func)
934 * EL_NUM_FCNS);
935 el->el_map.nfunc = EL_NUM_FCNS;
936
937 #ifdef VIDEFAULT
938 map_init_vi(el);
939 #else
940 map_init_emacs(el);
941 #endif /* VIDEFAULT */
942 return 0;
943 out:
944 map_end(el);
945 return -1;
946 }
947
948
949 /* map_end():
950 * Free the space taken by the editor maps
951 */
952 libedit_private void
map_end(EditLine * el)953 map_end(EditLine *el)
954 {
955
956 el_free(el->el_map.alt);
957 el->el_map.alt = NULL;
958 el_free(el->el_map.key);
959 el->el_map.key = NULL;
960 el->el_map.emacs = NULL;
961 el->el_map.vic = NULL;
962 el->el_map.vii = NULL;
963 el_free(el->el_map.help);
964 el->el_map.help = NULL;
965 el_free(el->el_map.func);
966 el->el_map.func = NULL;
967 }
968
969
970 /* map_init_nls():
971 * Find all the printable keys and bind them to self insert
972 */
973 static void
map_init_nls(EditLine * el)974 map_init_nls(EditLine *el)
975 {
976 int i;
977
978 el_action_t *map = el->el_map.key;
979
980 for (i = 0200; i <= 0377; i++)
981 if (iswprint(i))
982 map[i] = ED_INSERT;
983 }
984
985
986 /* map_init_meta():
987 * Bind all the meta keys to the appropriate ESC-<key> sequence
988 */
989 static void
map_init_meta(EditLine * el)990 map_init_meta(EditLine *el)
991 {
992 wchar_t buf[3];
993 int i;
994 el_action_t *map = el->el_map.key;
995 el_action_t *alt = el->el_map.alt;
996
997 for (i = 0; i <= 0377 && map[i] != EM_META_NEXT; i++)
998 continue;
999
1000 if (i > 0377) {
1001 for (i = 0; i <= 0377 && alt[i] != EM_META_NEXT; i++)
1002 continue;
1003 if (i > 0377) {
1004 i = 033;
1005 if (el->el_map.type == MAP_VI)
1006 map = alt;
1007 } else
1008 map = alt;
1009 }
1010 buf[0] = (wchar_t)i;
1011 buf[2] = 0;
1012 for (i = 0200; i <= 0377; i++)
1013 switch (map[i]) {
1014 case ED_INSERT:
1015 case ED_UNASSIGNED:
1016 case ED_SEQUENCE_LEAD_IN:
1017 break;
1018 default:
1019 buf[1] = i & 0177;
1020 keymacro_add(el, buf, keymacro_map_cmd(el, (int) map[i]), XK_CMD);
1021 break;
1022 }
1023 map[(int) buf[0]] = ED_SEQUENCE_LEAD_IN;
1024 }
1025
1026
1027 /* map_init_vi():
1028 * Initialize the vi bindings
1029 */
1030 libedit_private void
map_init_vi(EditLine * el)1031 map_init_vi(EditLine *el)
1032 {
1033 int i;
1034 el_action_t *key = el->el_map.key;
1035 el_action_t *alt = el->el_map.alt;
1036 const el_action_t *vii = el->el_map.vii;
1037 const el_action_t *vic = el->el_map.vic;
1038
1039 el->el_map.type = MAP_VI;
1040 el->el_map.current = el->el_map.key;
1041
1042 keymacro_reset(el);
1043
1044 for (i = 0; i < N_KEYS; i++) {
1045 key[i] = vii[i];
1046 alt[i] = vic[i];
1047 }
1048
1049 map_init_meta(el);
1050 map_init_nls(el);
1051
1052 tty_bind_char(el, 1);
1053 terminal_bind_arrow(el);
1054 }
1055
1056
1057 /* map_init_emacs():
1058 * Initialize the emacs bindings
1059 */
1060 libedit_private void
map_init_emacs(EditLine * el)1061 map_init_emacs(EditLine *el)
1062 {
1063 int i;
1064 wchar_t buf[3];
1065 el_action_t *key = el->el_map.key;
1066 el_action_t *alt = el->el_map.alt;
1067 const el_action_t *emacs = el->el_map.emacs;
1068
1069 el->el_map.type = MAP_EMACS;
1070 el->el_map.current = el->el_map.key;
1071 keymacro_reset(el);
1072
1073 for (i = 0; i < N_KEYS; i++) {
1074 key[i] = emacs[i];
1075 alt[i] = ED_UNASSIGNED;
1076 }
1077
1078 map_init_meta(el);
1079 map_init_nls(el);
1080
1081 buf[0] = CONTROL('X');
1082 buf[1] = CONTROL('X');
1083 buf[2] = 0;
1084 keymacro_add(el, buf, keymacro_map_cmd(el, EM_EXCHANGE_MARK), XK_CMD);
1085
1086 tty_bind_char(el, 1);
1087 terminal_bind_arrow(el);
1088 }
1089
1090
1091 /* map_set_editor():
1092 * Set the editor
1093 */
1094 libedit_private int
map_set_editor(EditLine * el,wchar_t * editor)1095 map_set_editor(EditLine *el, wchar_t *editor)
1096 {
1097
1098 if (wcscmp(editor, L"emacs") == 0) {
1099 map_init_emacs(el);
1100 return 0;
1101 }
1102 if (wcscmp(editor, L"vi") == 0) {
1103 map_init_vi(el);
1104 return 0;
1105 }
1106 return -1;
1107 }
1108
1109
1110 /* map_get_editor():
1111 * Retrieve the editor
1112 */
1113 libedit_private int
map_get_editor(EditLine * el,const wchar_t ** editor)1114 map_get_editor(EditLine *el, const wchar_t **editor)
1115 {
1116
1117 if (editor == NULL)
1118 return -1;
1119 switch (el->el_map.type) {
1120 case MAP_EMACS:
1121 *editor = L"emacs";
1122 return 0;
1123 case MAP_VI:
1124 *editor = L"vi";
1125 return 0;
1126 }
1127 return -1;
1128 }
1129
1130
1131 /* map_print_key():
1132 * Print the function description for 1 key
1133 */
1134 static void
map_print_key(EditLine * el,el_action_t * map,const wchar_t * in)1135 map_print_key(EditLine *el, el_action_t *map, const wchar_t *in)
1136 {
1137 char outbuf[EL_BUFSIZ];
1138 el_bindings_t *bp, *ep;
1139
1140 if (in[0] == '\0' || in[1] == '\0') {
1141 (void) keymacro__decode_str(in, outbuf, sizeof(outbuf), "");
1142 ep = &el->el_map.help[el->el_map.nfunc];
1143 for (bp = el->el_map.help; bp < ep; bp++)
1144 if (bp->func == map[(unsigned char) *in]) {
1145 (void) fprintf(el->el_outfile,
1146 "%s\t->\t%ls\n", outbuf, bp->name);
1147 return;
1148 }
1149 } else
1150 keymacro_print(el, in);
1151 }
1152
1153
1154 /* map_print_some_keys():
1155 * Print keys from first to last
1156 */
1157 static void
map_print_some_keys(EditLine * el,el_action_t * map,wint_t first,wint_t last)1158 map_print_some_keys(EditLine *el, el_action_t *map, wint_t first, wint_t last)
1159 {
1160 el_bindings_t *bp, *ep;
1161 wchar_t firstbuf[2], lastbuf[2];
1162 char unparsbuf[EL_BUFSIZ], extrabuf[EL_BUFSIZ];
1163
1164 firstbuf[0] = first;
1165 firstbuf[1] = 0;
1166 lastbuf[0] = last;
1167 lastbuf[1] = 0;
1168 if (map[first] == ED_UNASSIGNED) {
1169 if (first == last) {
1170 (void) keymacro__decode_str(firstbuf, unparsbuf,
1171 sizeof(unparsbuf), STRQQ);
1172 (void) fprintf(el->el_outfile,
1173 "%-15s-> is undefined\n", unparsbuf);
1174 }
1175 return;
1176 }
1177 ep = &el->el_map.help[el->el_map.nfunc];
1178 for (bp = el->el_map.help; bp < ep; bp++) {
1179 if (bp->func == map[first]) {
1180 if (first == last) {
1181 (void) keymacro__decode_str(firstbuf, unparsbuf,
1182 sizeof(unparsbuf), STRQQ);
1183 (void) fprintf(el->el_outfile, "%-15s-> %ls\n",
1184 unparsbuf, bp->name);
1185 } else {
1186 (void) keymacro__decode_str(firstbuf, unparsbuf,
1187 sizeof(unparsbuf), STRQQ);
1188 (void) keymacro__decode_str(lastbuf, extrabuf,
1189 sizeof(extrabuf), STRQQ);
1190 (void) fprintf(el->el_outfile,
1191 "%-4s to %-7s-> %ls\n",
1192 unparsbuf, extrabuf, bp->name);
1193 }
1194 return;
1195 }
1196 }
1197 #ifdef MAP_DEBUG
1198 if (map == el->el_map.key) {
1199 (void) keymacro__decode_str(firstbuf, unparsbuf,
1200 sizeof(unparsbuf), STRQQ);
1201 (void) fprintf(el->el_outfile,
1202 "BUG!!! %s isn't bound to anything.\n", unparsbuf);
1203 (void) fprintf(el->el_outfile, "el->el_map.key[%d] == %d\n",
1204 first, el->el_map.key[first]);
1205 } else {
1206 (void) keymacro__decode_str(firstbuf, unparsbuf,
1207 sizeof(unparsbuf), STRQQ);
1208 (void) fprintf(el->el_outfile,
1209 "BUG!!! %s isn't bound to anything.\n", unparsbuf);
1210 (void) fprintf(el->el_outfile, "el->el_map.alt[%d] == %d\n",
1211 first, el->el_map.alt[first]);
1212 }
1213 #endif
1214 EL_ABORT((el->el_errfile, "Error printing keys\n"));
1215 }
1216
1217
1218 /* map_print_all_keys():
1219 * Print the function description for all keys.
1220 */
1221 static void
map_print_all_keys(EditLine * el)1222 map_print_all_keys(EditLine *el)
1223 {
1224 int prev, i;
1225
1226 (void) fprintf(el->el_outfile, "Standard key bindings\n");
1227 prev = 0;
1228 for (i = 0; i < N_KEYS; i++) {
1229 if (el->el_map.key[prev] == el->el_map.key[i])
1230 continue;
1231 map_print_some_keys(el, el->el_map.key, prev, i - 1);
1232 prev = i;
1233 }
1234 map_print_some_keys(el, el->el_map.key, prev, i - 1);
1235
1236 (void) fprintf(el->el_outfile, "Alternative key bindings\n");
1237 prev = 0;
1238 for (i = 0; i < N_KEYS; i++) {
1239 if (el->el_map.alt[prev] == el->el_map.alt[i])
1240 continue;
1241 map_print_some_keys(el, el->el_map.alt, prev, i - 1);
1242 prev = i;
1243 }
1244 map_print_some_keys(el, el->el_map.alt, prev, i - 1);
1245
1246 (void) fprintf(el->el_outfile, "Multi-character bindings\n");
1247 keymacro_print(el, L"");
1248 (void) fprintf(el->el_outfile, "Arrow key bindings\n");
1249 terminal_print_arrow(el, L"");
1250 }
1251
1252
1253 /* map_bind():
1254 * Add/remove/change bindings
1255 */
1256 libedit_private int
map_bind(EditLine * el,int argc,const wchar_t ** argv)1257 map_bind(EditLine *el, int argc, const wchar_t **argv)
1258 {
1259 el_action_t *map;
1260 int ntype, rem;
1261 const wchar_t *p;
1262 wchar_t inbuf[EL_BUFSIZ];
1263 wchar_t outbuf[EL_BUFSIZ];
1264 const wchar_t *in = NULL;
1265 wchar_t *out;
1266 el_bindings_t *bp, *ep;
1267 int cmd;
1268 int key;
1269
1270 if (argv == NULL)
1271 return -1;
1272
1273 map = el->el_map.key;
1274 ntype = XK_CMD;
1275 key = rem = 0;
1276 for (argc = 1; (p = argv[argc]) != NULL; argc++)
1277 if (p[0] == '-')
1278 switch (p[1]) {
1279 case 'a':
1280 map = el->el_map.alt;
1281 break;
1282
1283 case 's':
1284 ntype = XK_STR;
1285 break;
1286 case 'k':
1287 key = 1;
1288 break;
1289
1290 case 'r':
1291 rem = 1;
1292 break;
1293
1294 case 'v':
1295 map_init_vi(el);
1296 return 0;
1297
1298 case 'e':
1299 map_init_emacs(el);
1300 return 0;
1301
1302 case 'l':
1303 ep = &el->el_map.help[el->el_map.nfunc];
1304 for (bp = el->el_map.help; bp < ep; bp++)
1305 (void) fprintf(el->el_outfile,
1306 "%ls\n\t%ls\n",
1307 bp->name, bp->description);
1308 return 0;
1309 default:
1310 (void) fprintf(el->el_errfile,
1311 "%ls: Invalid switch `%lc'.\n",
1312 argv[0], (wint_t)p[1]);
1313 }
1314 else
1315 break;
1316
1317 if (argv[argc] == NULL) {
1318 map_print_all_keys(el);
1319 return 0;
1320 }
1321 if (key)
1322 in = argv[argc++];
1323 else if ((in = parse__string(inbuf, argv[argc++])) == NULL) {
1324 (void) fprintf(el->el_errfile,
1325 "%ls: Invalid \\ or ^ in instring.\n",
1326 argv[0]);
1327 return -1;
1328 }
1329 if (rem) {
1330 if (key) {
1331 (void) terminal_clear_arrow(el, in);
1332 return -1;
1333 }
1334 if (in[1])
1335 (void) keymacro_delete(el, in);
1336 else if (map[(unsigned char) *in] == ED_SEQUENCE_LEAD_IN)
1337 (void) keymacro_delete(el, in);
1338 else
1339 map[(unsigned char) *in] = ED_UNASSIGNED;
1340 return 0;
1341 }
1342 if (argv[argc] == NULL) {
1343 if (key)
1344 terminal_print_arrow(el, in);
1345 else
1346 map_print_key(el, map, in);
1347 return 0;
1348 }
1349 #ifdef notyet
1350 if (argv[argc + 1] != NULL) {
1351 bindkeymacro_usage();
1352 return -1;
1353 }
1354 #endif
1355
1356 switch (ntype) {
1357 case XK_STR:
1358 if ((out = parse__string(outbuf, argv[argc])) == NULL) {
1359 (void) fprintf(el->el_errfile,
1360 "%ls: Invalid \\ or ^ in outstring.\n", argv[0]);
1361 return -1;
1362 }
1363 if (key)
1364 terminal_set_arrow(el, in, keymacro_map_str(el, out), ntype);
1365 else
1366 keymacro_add(el, in, keymacro_map_str(el, out), ntype);
1367 map[(unsigned char) *in] = ED_SEQUENCE_LEAD_IN;
1368 break;
1369
1370 case XK_CMD:
1371 if ((cmd = parse_cmd(el, argv[argc])) == -1) {
1372 (void) fprintf(el->el_errfile,
1373 "%ls: Invalid command `%ls'.\n",
1374 argv[0], argv[argc]);
1375 return -1;
1376 }
1377 if (key)
1378 terminal_set_arrow(el, in, keymacro_map_cmd(el, cmd), ntype);
1379 else {
1380 if (in[1]) {
1381 keymacro_add(el, in, keymacro_map_cmd(el, cmd), ntype);
1382 map[(unsigned char) *in] = ED_SEQUENCE_LEAD_IN;
1383 } else {
1384 keymacro_clear(el, map, in);
1385 map[(unsigned char) *in] = (el_action_t)cmd;
1386 }
1387 }
1388 break;
1389
1390 /* coverity[dead_error_begin] */
1391 default:
1392 EL_ABORT((el->el_errfile, "Bad XK_ type %d\n", ntype));
1393 break;
1394 }
1395 return 0;
1396 }
1397
1398
1399 /* map_addfunc():
1400 * add a user defined function
1401 */
1402 libedit_private int
map_addfunc(EditLine * el,const wchar_t * name,const wchar_t * help,el_func_t func)1403 map_addfunc(EditLine *el, const wchar_t *name, const wchar_t *help,
1404 el_func_t func)
1405 {
1406 void *p;
1407 size_t nf = el->el_map.nfunc + 1;
1408
1409 if (name == NULL || help == NULL || func == NULL)
1410 return -1;
1411
1412 if ((p = el_realloc(el->el_map.func, nf *
1413 sizeof(*el->el_map.func))) == NULL)
1414 return -1;
1415 el->el_map.func = p;
1416 if ((p = el_realloc(el->el_map.help, nf * sizeof(*el->el_map.help)))
1417 == NULL)
1418 return -1;
1419 el->el_map.help = p;
1420
1421 nf = (size_t)el->el_map.nfunc;
1422 el->el_map.func[nf] = func;
1423
1424 el->el_map.help[nf].name = name;
1425 el->el_map.help[nf].func = (int)nf;
1426 el->el_map.help[nf].description = help;
1427 el->el_map.nfunc++;
1428
1429 return 0;
1430 }
1431