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