GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: lib/libedit/map.c Lines: 109 243 44.9 %
Date: 2017-11-07 Branches: 41 124 33.1 %

Line Branch Exec Source
1
/*	$OpenBSD: map.c,v 1.27 2016/05/06 13:12:52 schwarze Exp $	*/
2
/*	$NetBSD: map.c,v 1.25 2009/12/30 22:37:40 christos Exp $	*/
3
4
/*-
5
 * Copyright (c) 1992, 1993
6
 *	The Regents of the University of California.  All rights reserved.
7
 *
8
 * This code is derived from software contributed to Berkeley by
9
 * Christos Zoulas of Cornell University.
10
 *
11
 * Redistribution and use in source and binary forms, with or without
12
 * modification, are permitted provided that the following conditions
13
 * are met:
14
 * 1. Redistributions of source code must retain the above copyright
15
 *    notice, this list of conditions and the following disclaimer.
16
 * 2. Redistributions in binary form must reproduce the above copyright
17
 *    notice, this list of conditions and the following disclaimer in the
18
 *    documentation and/or other materials provided with the distribution.
19
 * 3. Neither the name of the University nor the names of its contributors
20
 *    may be used to endorse or promote products derived from this software
21
 *    without specific prior written permission.
22
 *
23
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33
 * SUCH DAMAGE.
34
 */
35
36
#include "config.h"
37
38
/*
39
 * map.c: Editor function definitions
40
 */
41
#include <ctype.h>
42
#include <stdlib.h>
43
#include <string.h>
44
45
#include "el.h"
46
#include "common.h"
47
#include "emacs.h"
48
#include "vi.h"
49
#include "fcns.h"
50
#include "func.h"
51
#include "help.h"
52
#include "parse.h"
53
54
static void	map_print_key(EditLine *, el_action_t *, const wchar_t *);
55
static void	map_print_some_keys(EditLine *, el_action_t *, wint_t, wint_t);
56
static void	map_print_all_keys(EditLine *);
57
static void	map_init_nls(EditLine *);
58
static void	map_init_meta(EditLine *);
59
60
/* keymap tables ; should be N_KEYS*sizeof(KEYCMD) bytes long */
61
62
63
static const el_action_t  el_map_emacs[] = {
64
	/*   0 */	EM_SET_MARK,		/* ^@ */
65
	/*   1 */	ED_MOVE_TO_BEG,		/* ^A */
66
	/*   2 */	ED_PREV_CHAR,		/* ^B */
67
	/*   3 */	ED_IGNORE,		/* ^C */
68
	/*   4 */	EM_DELETE_OR_LIST,	/* ^D */
69
	/*   5 */	ED_MOVE_TO_END,		/* ^E */
70
	/*   6 */	ED_NEXT_CHAR,		/* ^F */
71
	/*   7 */	ED_UNASSIGNED,		/* ^G */
72
	/*   8 */	EM_DELETE_PREV_CHAR,	/* ^H */
73
	/*   9 */	ED_UNASSIGNED,		/* ^I */
74
	/*  10 */	ED_NEWLINE,		/* ^J */
75
	/*  11 */	ED_KILL_LINE,		/* ^K */
76
	/*  12 */	ED_CLEAR_SCREEN,	/* ^L */
77
	/*  13 */	ED_NEWLINE,		/* ^M */
78
	/*  14 */	ED_NEXT_HISTORY,	/* ^N */
79
	/*  15 */	ED_IGNORE,		/* ^O */
80
	/*  16 */	ED_PREV_HISTORY,	/* ^P */
81
	/*  17 */	ED_IGNORE,		/* ^Q */
82
	/*  18 */	ED_REDISPLAY,		/* ^R */
83
	/*  19 */	ED_IGNORE,		/* ^S */
84
	/*  20 */	ED_TRANSPOSE_CHARS,	/* ^T */
85
	/*  21 */	EM_KILL_LINE,		/* ^U */
86
	/*  22 */	ED_QUOTED_INSERT,	/* ^V */
87
	/*  23 */	EM_KILL_REGION,		/* ^W */
88
	/*  24 */	ED_SEQUENCE_LEAD_IN,	/* ^X */
89
	/*  25 */	EM_YANK,		/* ^Y */
90
	/*  26 */	ED_IGNORE,		/* ^Z */
91
	/*  27 */	EM_META_NEXT,		/* ^[ */
92
	/*  28 */	ED_IGNORE,		/* ^\ */
93
	/*  29 */	ED_IGNORE,		/* ^] */
94
	/*  30 */	ED_UNASSIGNED,		/* ^^ */
95
	/*  31 */	ED_UNASSIGNED,		/* ^_ */
96
	/*  32 */	ED_INSERT,		/* SPACE */
97
	/*  33 */	ED_INSERT,		/* ! */
98
	/*  34 */	ED_INSERT,		/* " */
99
	/*  35 */	ED_INSERT,		/* # */
100
	/*  36 */	ED_INSERT,		/* $ */
101
	/*  37 */	ED_INSERT,		/* % */
102
	/*  38 */	ED_INSERT,		/* & */
103
	/*  39 */	ED_INSERT,		/* ' */
104
	/*  40 */	ED_INSERT,		/* ( */
105
	/*  41 */	ED_INSERT,		/* ) */
106
	/*  42 */	ED_INSERT,		/* * */
107
	/*  43 */	ED_INSERT,		/* + */
108
	/*  44 */	ED_INSERT,		/* , */
109
	/*  45 */	ED_INSERT,		/* - */
110
	/*  46 */	ED_INSERT,		/* . */
111
	/*  47 */	ED_INSERT,		/* / */
112
	/*  48 */	ED_DIGIT,		/* 0 */
113
	/*  49 */	ED_DIGIT,		/* 1 */
114
	/*  50 */	ED_DIGIT,		/* 2 */
115
	/*  51 */	ED_DIGIT,		/* 3 */
116
	/*  52 */	ED_DIGIT,		/* 4 */
117
	/*  53 */	ED_DIGIT,		/* 5 */
118
	/*  54 */	ED_DIGIT,		/* 6 */
119
	/*  55 */	ED_DIGIT,		/* 7 */
120
	/*  56 */	ED_DIGIT,		/* 8 */
121
	/*  57 */	ED_DIGIT,		/* 9 */
122
	/*  58 */	ED_INSERT,		/* : */
123
	/*  59 */	ED_INSERT,		/* ; */
124
	/*  60 */	ED_INSERT,		/* < */
125
	/*  61 */	ED_INSERT,		/* = */
126
	/*  62 */	ED_INSERT,		/* > */
127
	/*  63 */	ED_INSERT,		/* ? */
128
	/*  64 */	ED_INSERT,		/* @ */
129
	/*  65 */	ED_INSERT,		/* A */
130
	/*  66 */	ED_INSERT,		/* B */
131
	/*  67 */	ED_INSERT,		/* C */
132
	/*  68 */	ED_INSERT,		/* D */
133
	/*  69 */	ED_INSERT,		/* E */
134
	/*  70 */	ED_INSERT,		/* F */
135
	/*  71 */	ED_INSERT,		/* G */
136
	/*  72 */	ED_INSERT,		/* H */
137
	/*  73 */	ED_INSERT,		/* I */
138
	/*  74 */	ED_INSERT,		/* J */
139
	/*  75 */	ED_INSERT,		/* K */
140
	/*  76 */	ED_INSERT,		/* L */
141
	/*  77 */	ED_INSERT,		/* M */
142
	/*  78 */	ED_INSERT,		/* N */
143
	/*  79 */	ED_INSERT,		/* O */
144
	/*  80 */	ED_INSERT,		/* P */
145
	/*  81 */	ED_INSERT,		/* Q */
146
	/*  82 */	ED_INSERT,		/* R */
147
	/*  83 */	ED_INSERT,		/* S */
148
	/*  84 */	ED_INSERT,		/* T */
149
	/*  85 */	ED_INSERT,		/* U */
150
	/*  86 */	ED_INSERT,		/* V */
151
	/*  87 */	ED_INSERT,		/* W */
152
	/*  88 */	ED_INSERT,		/* X */
153
	/*  89 */	ED_INSERT,		/* Y */
154
	/*  90 */	ED_INSERT,		/* Z */
155
	/*  91 */	ED_INSERT,		/* [ */
156
	/*  92 */	ED_INSERT,		/* \ */
157
	/*  93 */	ED_INSERT,		/* ] */
158
	/*  94 */	ED_INSERT,		/* ^ */
159
	/*  95 */	ED_INSERT,		/* _ */
160
	/*  96 */	ED_INSERT,		/* ` */
161
	/*  97 */	ED_INSERT,		/* a */
162
	/*  98 */	ED_INSERT,		/* b */
163
	/*  99 */	ED_INSERT,		/* c */
164
	/* 100 */	ED_INSERT,		/* d */
165
	/* 101 */	ED_INSERT,		/* e */
166
	/* 102 */	ED_INSERT,		/* f */
167
	/* 103 */	ED_INSERT,		/* g */
168
	/* 104 */	ED_INSERT,		/* h */
169
	/* 105 */	ED_INSERT,		/* i */
170
	/* 106 */	ED_INSERT,		/* j */
171
	/* 107 */	ED_INSERT,		/* k */
172
	/* 108 */	ED_INSERT,		/* l */
173
	/* 109 */	ED_INSERT,		/* m */
174
	/* 110 */	ED_INSERT,		/* n */
175
	/* 111 */	ED_INSERT,		/* o */
176
	/* 112 */	ED_INSERT,		/* p */
177
	/* 113 */	ED_INSERT,		/* q */
178
	/* 114 */	ED_INSERT,		/* r */
179
	/* 115 */	ED_INSERT,		/* s */
180
	/* 116 */	ED_INSERT,		/* t */
181
	/* 117 */	ED_INSERT,		/* u */
182
	/* 118 */	ED_INSERT,		/* v */
183
	/* 119 */	ED_INSERT,		/* w */
184
	/* 120 */	ED_INSERT,		/* x */
185
	/* 121 */	ED_INSERT,		/* y */
186
	/* 122 */	ED_INSERT,		/* z */
187
	/* 123 */	ED_INSERT,		/* { */
188
	/* 124 */	ED_INSERT,		/* | */
189
	/* 125 */	ED_INSERT,		/* } */
190
	/* 126 */	ED_INSERT,		/* ~ */
191
	/* 127 */	EM_DELETE_PREV_CHAR,	/* ^? */
192
	/* 128 */	ED_UNASSIGNED,		/* M-^@ */
193
	/* 129 */	ED_UNASSIGNED,		/* M-^A */
194
	/* 130 */	ED_UNASSIGNED,		/* M-^B */
195
	/* 131 */	ED_UNASSIGNED,		/* M-^C */
196
	/* 132 */	ED_UNASSIGNED,		/* M-^D */
197
	/* 133 */	ED_UNASSIGNED,		/* M-^E */
198
	/* 134 */	ED_UNASSIGNED,		/* M-^F */
199
	/* 135 */	ED_UNASSIGNED,		/* M-^G */
200
	/* 136 */	ED_DELETE_PREV_WORD,	/* M-^H */
201
	/* 137 */	ED_UNASSIGNED,		/* M-^I */
202
	/* 138 */	ED_UNASSIGNED,		/* M-^J */
203
	/* 139 */	ED_UNASSIGNED,		/* M-^K */
204
	/* 140 */	ED_CLEAR_SCREEN,	/* M-^L */
205
	/* 141 */	ED_UNASSIGNED,		/* M-^M */
206
	/* 142 */	ED_UNASSIGNED,		/* M-^N */
207
	/* 143 */	ED_UNASSIGNED,		/* M-^O */
208
	/* 144 */	ED_UNASSIGNED,		/* M-^P */
209
	/* 145 */	ED_UNASSIGNED,		/* M-^Q */
210
	/* 146 */	ED_UNASSIGNED,		/* M-^R */
211
	/* 147 */	ED_UNASSIGNED,		/* M-^S */
212
	/* 148 */	ED_UNASSIGNED,		/* M-^T */
213
	/* 149 */	ED_UNASSIGNED,		/* M-^U */
214
	/* 150 */	ED_UNASSIGNED,		/* M-^V */
215
	/* 151 */	ED_UNASSIGNED,		/* M-^W */
216
	/* 152 */	ED_UNASSIGNED,		/* M-^X */
217
	/* 153 */	ED_UNASSIGNED,		/* M-^Y */
218
	/* 154 */	ED_UNASSIGNED,		/* M-^Z */
219
	/* 155 */	ED_UNASSIGNED,		/* M-^[ */
220
	/* 156 */	ED_UNASSIGNED,		/* M-^\ */
221
	/* 157 */	ED_UNASSIGNED,		/* M-^] */
222
	/* 158 */	ED_UNASSIGNED,		/* M-^^ */
223
	/* 159 */	EM_COPY_PREV_WORD,	/* M-^_ */
224
	/* 160 */	ED_UNASSIGNED,		/* M-SPACE */
225
	/* 161 */	ED_UNASSIGNED,		/* M-! */
226
	/* 162 */	ED_UNASSIGNED,		/* M-" */
227
	/* 163 */	ED_UNASSIGNED,		/* M-# */
228
	/* 164 */	ED_UNASSIGNED,		/* M-$ */
229
	/* 165 */	ED_UNASSIGNED,		/* M-% */
230
	/* 166 */	ED_UNASSIGNED,		/* M-& */
231
	/* 167 */	ED_UNASSIGNED,		/* M-' */
232
	/* 168 */	ED_UNASSIGNED,		/* M-( */
233
	/* 169 */	ED_UNASSIGNED,		/* M-) */
234
	/* 170 */	ED_UNASSIGNED,		/* M-* */
235
	/* 171 */	ED_UNASSIGNED,		/* M-+ */
236
	/* 172 */	ED_UNASSIGNED,		/* M-, */
237
	/* 173 */	ED_UNASSIGNED,		/* M-- */
238
	/* 174 */	ED_UNASSIGNED,		/* M-. */
239
	/* 175 */	ED_UNASSIGNED,		/* M-/ */
240
	/* 176 */	ED_ARGUMENT_DIGIT,	/* M-0 */
241
	/* 177 */	ED_ARGUMENT_DIGIT,	/* M-1 */
242
	/* 178 */	ED_ARGUMENT_DIGIT,	/* M-2 */
243
	/* 179 */	ED_ARGUMENT_DIGIT,	/* M-3 */
244
	/* 180 */	ED_ARGUMENT_DIGIT,	/* M-4 */
245
	/* 181 */	ED_ARGUMENT_DIGIT,	/* M-5 */
246
	/* 182 */	ED_ARGUMENT_DIGIT,	/* M-6 */
247
	/* 183 */	ED_ARGUMENT_DIGIT,	/* M-7 */
248
	/* 184 */	ED_ARGUMENT_DIGIT,	/* M-8 */
249
	/* 185 */	ED_ARGUMENT_DIGIT,	/* M-9 */
250
	/* 186 */	ED_UNASSIGNED,		/* M-: */
251
	/* 187 */	ED_UNASSIGNED,		/* M-; */
252
	/* 188 */	ED_UNASSIGNED,		/* M-< */
253
	/* 189 */	ED_UNASSIGNED,		/* M-= */
254
	/* 190 */	ED_UNASSIGNED,		/* M-> */
255
	/* 191 */	ED_UNASSIGNED,		/* M-? */
256
	/* 192 */	ED_UNASSIGNED,		/* M-@ */
257
	/* 193 */	ED_UNASSIGNED,		/* M-A */
258
	/* 194 */	ED_PREV_WORD,		/* M-B */
259
	/* 195 */	EM_CAPITOL_CASE,	/* M-C */
260
	/* 196 */	EM_DELETE_NEXT_WORD,	/* M-D */
261
	/* 197 */	ED_UNASSIGNED,		/* M-E */
262
	/* 198 */	EM_NEXT_WORD,		/* M-F */
263
	/* 199 */	ED_UNASSIGNED,		/* M-G */
264
	/* 200 */	ED_UNASSIGNED,		/* M-H */
265
	/* 201 */	ED_UNASSIGNED,		/* M-I */
266
	/* 202 */	ED_UNASSIGNED,		/* M-J */
267
	/* 203 */	ED_UNASSIGNED,		/* M-K */
268
	/* 204 */	EM_LOWER_CASE,		/* M-L */
269
	/* 205 */	ED_UNASSIGNED,		/* M-M */
270
	/* 206 */	ED_SEARCH_NEXT_HISTORY,	/* M-N */
271
	/* 207 */	ED_SEQUENCE_LEAD_IN,	/* M-O */
272
	/* 208 */	ED_SEARCH_PREV_HISTORY,	/* M-P */
273
	/* 209 */	ED_UNASSIGNED,		/* M-Q */
274
	/* 210 */	ED_UNASSIGNED,		/* M-R */
275
	/* 211 */	ED_UNASSIGNED,		/* M-S */
276
	/* 212 */	ED_UNASSIGNED,		/* M-T */
277
	/* 213 */	EM_UPPER_CASE,		/* M-U */
278
	/* 214 */	ED_UNASSIGNED,		/* M-V */
279
	/* 215 */	EM_COPY_REGION,		/* M-W */
280
	/* 216 */	ED_COMMAND,		/* M-X */
281
	/* 217 */	ED_UNASSIGNED,		/* M-Y */
282
	/* 218 */	ED_UNASSIGNED,		/* M-Z */
283
	/* 219 */	ED_SEQUENCE_LEAD_IN,	/* M-[ */
284
	/* 220 */	ED_UNASSIGNED,		/* M-\ */
285
	/* 221 */	ED_UNASSIGNED,		/* M-] */
286
	/* 222 */	ED_UNASSIGNED,		/* M-^ */
287
	/* 223 */	ED_UNASSIGNED,		/* M-_ */
288
	/* 223 */	ED_UNASSIGNED,		/* M-` */
289
	/* 224 */	ED_UNASSIGNED,		/* M-a */
290
	/* 225 */	ED_PREV_WORD,		/* M-b */
291
	/* 226 */	EM_CAPITOL_CASE,	/* M-c */
292
	/* 227 */	EM_DELETE_NEXT_WORD,	/* M-d */
293
	/* 228 */	ED_UNASSIGNED,		/* M-e */
294
	/* 229 */	EM_NEXT_WORD,		/* M-f */
295
	/* 230 */	ED_UNASSIGNED,		/* M-g */
296
	/* 231 */	ED_UNASSIGNED,		/* M-h */
297
	/* 232 */	ED_UNASSIGNED,		/* M-i */
298
	/* 233 */	ED_UNASSIGNED,		/* M-j */
299
	/* 234 */	ED_UNASSIGNED,		/* M-k */
300
	/* 235 */	EM_LOWER_CASE,		/* M-l */
301
	/* 236 */	ED_UNASSIGNED,		/* M-m */
302
	/* 237 */	ED_SEARCH_NEXT_HISTORY,	/* M-n */
303
	/* 238 */	ED_UNASSIGNED,		/* M-o */
304
	/* 239 */	ED_SEARCH_PREV_HISTORY,	/* M-p */
305
	/* 240 */	ED_UNASSIGNED,		/* M-q */
306
	/* 241 */	ED_UNASSIGNED,		/* M-r */
307
	/* 242 */	ED_UNASSIGNED,		/* M-s */
308
	/* 243 */	ED_UNASSIGNED,		/* M-t */
309
	/* 244 */	EM_UPPER_CASE,		/* M-u */
310
	/* 245 */	ED_UNASSIGNED,		/* M-v */
311
	/* 246 */	EM_COPY_REGION,		/* M-w */
312
	/* 247 */	ED_COMMAND,		/* M-x */
313
	/* 248 */	ED_UNASSIGNED,		/* M-y */
314
	/* 249 */	ED_UNASSIGNED,		/* M-z */
315
	/* 250 */	ED_UNASSIGNED,		/* M-{ */
316
	/* 251 */	ED_UNASSIGNED,		/* M-| */
317
	/* 252 */	ED_UNASSIGNED,		/* M-} */
318
	/* 253 */	ED_UNASSIGNED,		/* M-~ */
319
	/* 254 */	ED_DELETE_PREV_WORD	/* M-^? */
320
	/* 255 */
321
};
322
323
324
/*
325
 * keymap table for vi.  Each index into above tbl; should be
326
 * N_KEYS entries long.  Vi mode uses a sticky-extend to do command mode:
327
 * insert mode characters are in the normal keymap, and command mode
328
 * in the extended keymap.
329
 */
330
static const el_action_t  el_map_vi_insert[] = {
331
#ifdef KSHVI
332
	/*   0 */	ED_UNASSIGNED,		/* ^@ */
333
	/*   1 */	ED_INSERT,		/* ^A */
334
	/*   2 */	ED_INSERT,		/* ^B */
335
	/*   3 */	ED_INSERT,		/* ^C */
336
	/*   4 */	VI_LIST_OR_EOF,		/* ^D */
337
	/*   5 */	ED_INSERT,		/* ^E */
338
	/*   6 */	ED_INSERT,		/* ^F */
339
	/*   7 */	ED_INSERT,		/* ^G */
340
	/*   8 */	VI_DELETE_PREV_CHAR,	/* ^H */   /* BackSpace key */
341
	/*   9 */	ED_INSERT,		/* ^I */   /* Tab Key  */
342
	/*  10 */	ED_NEWLINE,		/* ^J */
343
	/*  11 */	ED_INSERT,		/* ^K */
344
	/*  12 */	ED_INSERT,		/* ^L */
345
	/*  13 */	ED_NEWLINE,		/* ^M */
346
	/*  14 */	ED_INSERT,		/* ^N */
347
	/*  15 */	ED_INSERT,		/* ^O */
348
	/*  16 */	ED_INSERT,		/* ^P */
349
	/*  17 */	ED_IGNORE,		/* ^Q */
350
	/*  18 */	ED_INSERT,		/* ^R */
351
	/*  19 */	ED_IGNORE,		/* ^S */
352
	/*  20 */	ED_INSERT,		/* ^T */
353
	/*  21 */	VI_KILL_LINE_PREV,	/* ^U */
354
	/*  22 */	ED_QUOTED_INSERT,	/* ^V */
355
	/*  23 */	ED_DELETE_PREV_WORD,	/* ^W */
356
		/* ED_DELETE_PREV_WORD: Only until strt edit pos */
357
	/*  24 */	ED_INSERT,		/* ^X */
358
	/*  25 */	ED_INSERT,		/* ^Y */
359
	/*  26 */	ED_INSERT,		/* ^Z */
360
	/*  27 */	VI_COMMAND_MODE,	/* ^[ */  /* [ Esc ] key */
361
	/*  28 */	ED_IGNORE,		/* ^\ */
362
	/*  29 */	ED_INSERT,		/* ^] */
363
	/*  30 */	ED_INSERT,		/* ^^ */
364
	/*  31 */	ED_INSERT,		/* ^_ */
365
#else /* !KSHVI */
366
				/*
367
				 * NOTE: These mappings do NOT Correspond well
368
				 * to the KSH VI editing assignments.
369
				 * On the other and they are convenient and
370
				 * many people have have gotten used to them.
371
				 */
372
	/*   0 */	ED_UNASSIGNED,		/* ^@ */
373
	/*   1 */	ED_MOVE_TO_BEG,		/* ^A */
374
	/*   2 */	ED_PREV_CHAR,		/* ^B */
375
	/*   3 */	ED_IGNORE,		/* ^C */
376
	/*   4 */	VI_LIST_OR_EOF,		/* ^D */
377
	/*   5 */	ED_MOVE_TO_END,		/* ^E */
378
	/*   6 */	ED_NEXT_CHAR,		/* ^F */
379
	/*   7 */	ED_UNASSIGNED,		/* ^G */
380
	/*   8 */	VI_DELETE_PREV_CHAR,	/* ^H */   /* BackSpace key */
381
	/*   9 */	ED_UNASSIGNED,		/* ^I */   /* Tab Key */
382
	/*  10 */	ED_NEWLINE,		/* ^J */
383
	/*  11 */	ED_KILL_LINE,		/* ^K */
384
	/*  12 */	ED_CLEAR_SCREEN,	/* ^L */
385
	/*  13 */	ED_NEWLINE,		/* ^M */
386
	/*  14 */	ED_NEXT_HISTORY,	/* ^N */
387
	/*  15 */	ED_IGNORE,		/* ^O */
388
	/*  16 */	ED_PREV_HISTORY,	/* ^P */
389
	/*  17 */	ED_IGNORE,		/* ^Q */
390
	/*  18 */	ED_REDISPLAY,		/* ^R */
391
	/*  19 */	ED_IGNORE,		/* ^S */
392
	/*  20 */	ED_TRANSPOSE_CHARS,	/* ^T */
393
	/*  21 */	VI_KILL_LINE_PREV,	/* ^U */
394
	/*  22 */	ED_QUOTED_INSERT,	/* ^V */
395
	/*  23 */	ED_DELETE_PREV_WORD,	/* ^W */
396
	/*  24 */	ED_UNASSIGNED,		/* ^X */
397
	/*  25 */	ED_IGNORE,		/* ^Y */
398
	/*  26 */	ED_IGNORE,		/* ^Z */
399
	/*  27 */	VI_COMMAND_MODE,	/* ^[ */
400
	/*  28 */	ED_IGNORE,		/* ^\ */
401
	/*  29 */	ED_UNASSIGNED,		/* ^] */
402
	/*  30 */	ED_UNASSIGNED,		/* ^^ */
403
	/*  31 */	ED_UNASSIGNED,		/* ^_ */
404
#endif  /* KSHVI */
405
	/*  32 */	ED_INSERT,		/* SPACE */
406
	/*  33 */	ED_INSERT,		/* ! */
407
	/*  34 */	ED_INSERT,		/* " */
408
	/*  35 */	ED_INSERT,		/* # */
409
	/*  36 */	ED_INSERT,		/* $ */
410
	/*  37 */	ED_INSERT,		/* % */
411
	/*  38 */	ED_INSERT,		/* & */
412
	/*  39 */	ED_INSERT,		/* ' */
413
	/*  40 */	ED_INSERT,		/* ( */
414
	/*  41 */	ED_INSERT,		/* ) */
415
	/*  42 */	ED_INSERT,		/* * */
416
	/*  43 */	ED_INSERT,		/* + */
417
	/*  44 */	ED_INSERT,		/* , */
418
	/*  45 */	ED_INSERT,		/* - */
419
	/*  46 */	ED_INSERT,		/* . */
420
	/*  47 */	ED_INSERT,		/* / */
421
	/*  48 */	ED_INSERT,		/* 0 */
422
	/*  49 */	ED_INSERT,		/* 1 */
423
	/*  50 */	ED_INSERT,		/* 2 */
424
	/*  51 */	ED_INSERT,		/* 3 */
425
	/*  52 */	ED_INSERT,		/* 4 */
426
	/*  53 */	ED_INSERT,		/* 5 */
427
	/*  54 */	ED_INSERT,		/* 6 */
428
	/*  55 */	ED_INSERT,		/* 7 */
429
	/*  56 */	ED_INSERT,		/* 8 */
430
	/*  57 */	ED_INSERT,		/* 9 */
431
	/*  58 */	ED_INSERT,		/* : */
432
	/*  59 */	ED_INSERT,		/* ; */
433
	/*  60 */	ED_INSERT,		/* < */
434
	/*  61 */	ED_INSERT,		/* = */
435
	/*  62 */	ED_INSERT,		/* > */
436
	/*  63 */	ED_INSERT,		/* ? */
437
	/*  64 */	ED_INSERT,		/* @ */
438
	/*  65 */	ED_INSERT,		/* A */
439
	/*  66 */	ED_INSERT,		/* B */
440
	/*  67 */	ED_INSERT,		/* C */
441
	/*  68 */	ED_INSERT,		/* D */
442
	/*  69 */	ED_INSERT,		/* E */
443
	/*  70 */	ED_INSERT,		/* F */
444
	/*  71 */	ED_INSERT,		/* G */
445
	/*  72 */	ED_INSERT,		/* H */
446
	/*  73 */	ED_INSERT,		/* I */
447
	/*  74 */	ED_INSERT,		/* J */
448
	/*  75 */	ED_INSERT,		/* K */
449
	/*  76 */	ED_INSERT,		/* L */
450
	/*  77 */	ED_INSERT,		/* M */
451
	/*  78 */	ED_INSERT,		/* N */
452
	/*  79 */	ED_INSERT,		/* O */
453
	/*  80 */	ED_INSERT,		/* P */
454
	/*  81 */	ED_INSERT,		/* Q */
455
	/*  82 */	ED_INSERT,		/* R */
456
	/*  83 */	ED_INSERT,		/* S */
457
	/*  84 */	ED_INSERT,		/* T */
458
	/*  85 */	ED_INSERT,		/* U */
459
	/*  86 */	ED_INSERT,		/* V */
460
	/*  87 */	ED_INSERT,		/* W */
461
	/*  88 */	ED_INSERT,		/* X */
462
	/*  89 */	ED_INSERT,		/* Y */
463
	/*  90 */	ED_INSERT,		/* Z */
464
	/*  91 */	ED_INSERT,		/* [ */
465
	/*  92 */	ED_INSERT,		/* \ */
466
	/*  93 */	ED_INSERT,		/* ] */
467
	/*  94 */	ED_INSERT,		/* ^ */
468
	/*  95 */	ED_INSERT,		/* _ */
469
	/*  96 */	ED_INSERT,		/* ` */
470
	/*  97 */	ED_INSERT,		/* a */
471
	/*  98 */	ED_INSERT,		/* b */
472
	/*  99 */	ED_INSERT,		/* c */
473
	/* 100 */	ED_INSERT,		/* d */
474
	/* 101 */	ED_INSERT,		/* e */
475
	/* 102 */	ED_INSERT,		/* f */
476
	/* 103 */	ED_INSERT,		/* g */
477
	/* 104 */	ED_INSERT,		/* h */
478
	/* 105 */	ED_INSERT,		/* i */
479
	/* 106 */	ED_INSERT,		/* j */
480
	/* 107 */	ED_INSERT,		/* k */
481
	/* 108 */	ED_INSERT,		/* l */
482
	/* 109 */	ED_INSERT,		/* m */
483
	/* 110 */	ED_INSERT,		/* n */
484
	/* 111 */	ED_INSERT,		/* o */
485
	/* 112 */	ED_INSERT,		/* p */
486
	/* 113 */	ED_INSERT,		/* q */
487
	/* 114 */	ED_INSERT,		/* r */
488
	/* 115 */	ED_INSERT,		/* s */
489
	/* 116 */	ED_INSERT,		/* t */
490
	/* 117 */	ED_INSERT,		/* u */
491
	/* 118 */	ED_INSERT,		/* v */
492
	/* 119 */	ED_INSERT,		/* w */
493
	/* 120 */	ED_INSERT,		/* x */
494
	/* 121 */	ED_INSERT,		/* y */
495
	/* 122 */	ED_INSERT,		/* z */
496
	/* 123 */	ED_INSERT,		/* { */
497
	/* 124 */	ED_INSERT,		/* | */
498
	/* 125 */	ED_INSERT,		/* } */
499
	/* 126 */	ED_INSERT,		/* ~ */
500
	/* 127 */	VI_DELETE_PREV_CHAR,	/* ^? */
501
	/* 128 */	ED_INSERT,		/* M-^@ */
502
	/* 129 */	ED_INSERT,		/* M-^A */
503
	/* 130 */	ED_INSERT,		/* M-^B */
504
	/* 131 */	ED_INSERT,		/* M-^C */
505
	/* 132 */	ED_INSERT,		/* M-^D */
506
	/* 133 */	ED_INSERT,		/* M-^E */
507
	/* 134 */	ED_INSERT,		/* M-^F */
508
	/* 135 */	ED_INSERT,		/* M-^G */
509
	/* 136 */	ED_INSERT,		/* M-^H */
510
	/* 137 */	ED_INSERT,		/* M-^I */
511
	/* 138 */	ED_INSERT,		/* M-^J */
512
	/* 139 */	ED_INSERT,		/* M-^K */
513
	/* 140 */	ED_INSERT,		/* M-^L */
514
	/* 141 */	ED_INSERT,		/* M-^M */
515
	/* 142 */	ED_INSERT,		/* M-^N */
516
	/* 143 */	ED_INSERT,		/* M-^O */
517
	/* 144 */	ED_INSERT,		/* M-^P */
518
	/* 145 */	ED_INSERT,		/* M-^Q */
519
	/* 146 */	ED_INSERT,		/* M-^R */
520
	/* 147 */	ED_INSERT,		/* M-^S */
521
	/* 148 */	ED_INSERT,		/* M-^T */
522
	/* 149 */	ED_INSERT,		/* M-^U */
523
	/* 150 */	ED_INSERT,		/* M-^V */
524
	/* 151 */	ED_INSERT,		/* M-^W */
525
	/* 152 */	ED_INSERT,		/* M-^X */
526
	/* 153 */	ED_INSERT,		/* M-^Y */
527
	/* 154 */	ED_INSERT,		/* M-^Z */
528
	/* 155 */	ED_INSERT,		/* M-^[ */
529
	/* 156 */	ED_INSERT,		/* M-^\ */
530
	/* 157 */	ED_INSERT,		/* M-^] */
531
	/* 158 */	ED_INSERT,		/* M-^^ */
532
	/* 159 */	ED_INSERT,		/* M-^_ */
533
	/* 160 */	ED_INSERT,		/* M-SPACE */
534
	/* 161 */	ED_INSERT,		/* M-! */
535
	/* 162 */	ED_INSERT,		/* M-" */
536
	/* 163 */	ED_INSERT,		/* M-# */
537
	/* 164 */	ED_INSERT,		/* M-$ */
538
	/* 165 */	ED_INSERT,		/* M-% */
539
	/* 166 */	ED_INSERT,		/* M-& */
540
	/* 167 */	ED_INSERT,		/* M-' */
541
	/* 168 */	ED_INSERT,		/* M-( */
542
	/* 169 */	ED_INSERT,		/* M-) */
543
	/* 170 */	ED_INSERT,		/* M-* */
544
	/* 171 */	ED_INSERT,		/* M-+ */
545
	/* 172 */	ED_INSERT,		/* M-, */
546
	/* 173 */	ED_INSERT,		/* M-- */
547
	/* 174 */	ED_INSERT,		/* M-. */
548
	/* 175 */	ED_INSERT,		/* M-/ */
549
	/* 176 */	ED_INSERT,		/* M-0 */
550
	/* 177 */	ED_INSERT,		/* M-1 */
551
	/* 178 */	ED_INSERT,		/* M-2 */
552
	/* 179 */	ED_INSERT,		/* M-3 */
553
	/* 180 */	ED_INSERT,		/* M-4 */
554
	/* 181 */	ED_INSERT,		/* M-5 */
555
	/* 182 */	ED_INSERT,		/* M-6 */
556
	/* 183 */	ED_INSERT,		/* M-7 */
557
	/* 184 */	ED_INSERT,		/* M-8 */
558
	/* 185 */	ED_INSERT,		/* M-9 */
559
	/* 186 */	ED_INSERT,		/* M-: */
560
	/* 187 */	ED_INSERT,		/* M-; */
561
	/* 188 */	ED_INSERT,		/* M-< */
562
	/* 189 */	ED_INSERT,		/* M-= */
563
	/* 190 */	ED_INSERT,		/* M-> */
564
	/* 191 */	ED_INSERT,		/* M-? */
565
	/* 192 */	ED_INSERT,		/* M-@ */
566
	/* 193 */	ED_INSERT,		/* M-A */
567
	/* 194 */	ED_INSERT,		/* M-B */
568
	/* 195 */	ED_INSERT,		/* M-C */
569
	/* 196 */	ED_INSERT,		/* M-D */
570
	/* 197 */	ED_INSERT,		/* M-E */
571
	/* 198 */	ED_INSERT,		/* M-F */
572
	/* 199 */	ED_INSERT,		/* M-G */
573
	/* 200 */	ED_INSERT,		/* M-H */
574
	/* 201 */	ED_INSERT,		/* M-I */
575
	/* 202 */	ED_INSERT,		/* M-J */
576
	/* 203 */	ED_INSERT,		/* M-K */
577
	/* 204 */	ED_INSERT,		/* M-L */
578
	/* 205 */	ED_INSERT,		/* M-M */
579
	/* 206 */	ED_INSERT,		/* M-N */
580
	/* 207 */	ED_INSERT,		/* M-O */
581
	/* 208 */	ED_INSERT,		/* M-P */
582
	/* 209 */	ED_INSERT,		/* M-Q */
583
	/* 210 */	ED_INSERT,		/* M-R */
584
	/* 211 */	ED_INSERT,		/* M-S */
585
	/* 212 */	ED_INSERT,		/* M-T */
586
	/* 213 */	ED_INSERT,		/* M-U */
587
	/* 214 */	ED_INSERT,		/* M-V */
588
	/* 215 */	ED_INSERT,		/* M-W */
589
	/* 216 */	ED_INSERT,		/* M-X */
590
	/* 217 */	ED_INSERT,		/* M-Y */
591
	/* 218 */	ED_INSERT,		/* M-Z */
592
	/* 219 */	ED_INSERT,		/* M-[ */
593
	/* 220 */	ED_INSERT,		/* M-\ */
594
	/* 221 */	ED_INSERT,		/* M-] */
595
	/* 222 */	ED_INSERT,		/* M-^ */
596
	/* 223 */	ED_INSERT,		/* M-_ */
597
	/* 224 */	ED_INSERT,		/* M-` */
598
	/* 225 */	ED_INSERT,		/* M-a */
599
	/* 226 */	ED_INSERT,		/* M-b */
600
	/* 227 */	ED_INSERT,		/* M-c */
601
	/* 228 */	ED_INSERT,		/* M-d */
602
	/* 229 */	ED_INSERT,		/* M-e */
603
	/* 230 */	ED_INSERT,		/* M-f */
604
	/* 231 */	ED_INSERT,		/* M-g */
605
	/* 232 */	ED_INSERT,		/* M-h */
606
	/* 233 */	ED_INSERT,		/* M-i */
607
	/* 234 */	ED_INSERT,		/* M-j */
608
	/* 235 */	ED_INSERT,		/* M-k */
609
	/* 236 */	ED_INSERT,		/* M-l */
610
	/* 237 */	ED_INSERT,		/* M-m */
611
	/* 238 */	ED_INSERT,		/* M-n */
612
	/* 239 */	ED_INSERT,		/* M-o */
613
	/* 240 */	ED_INSERT,		/* M-p */
614
	/* 241 */	ED_INSERT,		/* M-q */
615
	/* 242 */	ED_INSERT,		/* M-r */
616
	/* 243 */	ED_INSERT,		/* M-s */
617
	/* 244 */	ED_INSERT,		/* M-t */
618
	/* 245 */	ED_INSERT,		/* M-u */
619
	/* 246 */	ED_INSERT,		/* M-v */
620
	/* 247 */	ED_INSERT,		/* M-w */
621
	/* 248 */	ED_INSERT,		/* M-x */
622
	/* 249 */	ED_INSERT,		/* M-y */
623
	/* 250 */	ED_INSERT,		/* M-z */
624
	/* 251 */	ED_INSERT,		/* M-{ */
625
	/* 252 */	ED_INSERT,		/* M-| */
626
	/* 253 */	ED_INSERT,		/* M-} */
627
	/* 254 */	ED_INSERT,		/* M-~ */
628
	/* 255 */	ED_INSERT		/* M-^? */
629
};
630
631
static const el_action_t el_map_vi_command[] = {
632
	/*   0 */	ED_UNASSIGNED,		/* ^@ */
633
	/*   1 */	ED_MOVE_TO_BEG,		/* ^A */
634
	/*   2 */	ED_UNASSIGNED,		/* ^B */
635
	/*   3 */	ED_IGNORE,		/* ^C */
636
	/*   4 */	ED_UNASSIGNED,		/* ^D */
637
	/*   5 */	ED_MOVE_TO_END,		/* ^E */
638
	/*   6 */	ED_UNASSIGNED,		/* ^F */
639
	/*   7 */	ED_UNASSIGNED,		/* ^G */
640
	/*   8 */	ED_DELETE_PREV_CHAR,	/* ^H */
641
	/*   9 */	ED_UNASSIGNED,		/* ^I */
642
	/*  10 */	ED_NEWLINE,		/* ^J */
643
	/*  11 */	ED_KILL_LINE,		/* ^K */
644
	/*  12 */	ED_CLEAR_SCREEN,	/* ^L */
645
	/*  13 */	ED_NEWLINE,		/* ^M */
646
	/*  14 */	ED_NEXT_HISTORY,	/* ^N */
647
	/*  15 */	ED_IGNORE,		/* ^O */
648
	/*  16 */	ED_PREV_HISTORY,	/* ^P */
649
	/*  17 */	ED_IGNORE,		/* ^Q */
650
	/*  18 */	ED_REDISPLAY,		/* ^R */
651
	/*  19 */	ED_IGNORE,		/* ^S */
652
	/*  20 */	ED_UNASSIGNED,		/* ^T */
653
	/*  21 */	VI_KILL_LINE_PREV,	/* ^U */
654
	/*  22 */	ED_UNASSIGNED,		/* ^V */
655
	/*  23 */	ED_DELETE_PREV_WORD,	/* ^W */
656
	/*  24 */	ED_UNASSIGNED,		/* ^X */
657
	/*  25 */	ED_UNASSIGNED,		/* ^Y */
658
	/*  26 */	ED_UNASSIGNED,		/* ^Z */
659
	/*  27 */	EM_META_NEXT,		/* ^[ */
660
	/*  28 */	ED_IGNORE,		/* ^\ */
661
	/*  29 */	ED_UNASSIGNED,		/* ^] */
662
	/*  30 */	ED_UNASSIGNED,		/* ^^ */
663
	/*  31 */	ED_UNASSIGNED,		/* ^_ */
664
	/*  32 */	ED_NEXT_CHAR,		/* SPACE */
665
	/*  33 */	ED_UNASSIGNED,		/* ! */
666
	/*  34 */	ED_UNASSIGNED,		/* " */
667
	/*  35 */	VI_COMMENT_OUT,		/* # */
668
	/*  36 */	ED_MOVE_TO_END,		/* $ */
669
	/*  37 */	VI_MATCH,		/* % */
670
	/*  38 */	ED_UNASSIGNED,		/* & */
671
	/*  39 */	ED_UNASSIGNED,		/* ' */
672
	/*  40 */	ED_UNASSIGNED,		/* ( */
673
	/*  41 */	ED_UNASSIGNED,		/* ) */
674
	/*  42 */	ED_UNASSIGNED,		/* * */
675
	/*  43 */	ED_NEXT_HISTORY,	/* + */
676
	/*  44 */	VI_REPEAT_PREV_CHAR,	/* , */
677
	/*  45 */	ED_PREV_HISTORY,	/* - */
678
	/*  46 */	VI_REDO,		/* . */
679
	/*  47 */	VI_SEARCH_PREV,		/* / */
680
	/*  48 */	VI_ZERO,		/* 0 */
681
	/*  49 */	ED_ARGUMENT_DIGIT,	/* 1 */
682
	/*  50 */	ED_ARGUMENT_DIGIT,	/* 2 */
683
	/*  51 */	ED_ARGUMENT_DIGIT,	/* 3 */
684
	/*  52 */	ED_ARGUMENT_DIGIT,	/* 4 */
685
	/*  53 */	ED_ARGUMENT_DIGIT,	/* 5 */
686
	/*  54 */	ED_ARGUMENT_DIGIT,	/* 6 */
687
	/*  55 */	ED_ARGUMENT_DIGIT,	/* 7 */
688
	/*  56 */	ED_ARGUMENT_DIGIT,	/* 8 */
689
	/*  57 */	ED_ARGUMENT_DIGIT,	/* 9 */
690
	/*  58 */	ED_COMMAND,		/* : */
691
	/*  59 */	VI_REPEAT_NEXT_CHAR,	/* ; */
692
	/*  60 */	ED_UNASSIGNED,		/* < */
693
	/*  61 */	ED_UNASSIGNED,		/* = */
694
	/*  62 */	ED_UNASSIGNED,		/* > */
695
	/*  63 */	VI_SEARCH_NEXT,		/* ? */
696
	/*  64 */	VI_ALIAS,		/* @ */
697
	/*  65 */	VI_ADD_AT_EOL,		/* A */
698
	/*  66 */	VI_PREV_BIG_WORD,	/* B */
699
	/*  67 */	VI_CHANGE_TO_EOL,	/* C */
700
	/*  68 */	ED_KILL_LINE,		/* D */
701
	/*  69 */	VI_END_BIG_WORD,	/* E */
702
	/*  70 */	VI_PREV_CHAR,		/* F */
703
	/*  71 */	VI_TO_HISTORY_LINE,	/* G */
704
	/*  72 */	ED_UNASSIGNED,		/* H */
705
	/*  73 */	VI_INSERT_AT_BOL,	/* I */
706
	/*  74 */	ED_SEARCH_NEXT_HISTORY,	/* J */
707
	/*  75 */	ED_SEARCH_PREV_HISTORY,	/* K */
708
	/*  76 */	ED_UNASSIGNED,		/* L */
709
	/*  77 */	ED_UNASSIGNED,		/* M */
710
	/*  78 */	VI_REPEAT_SEARCH_PREV,	/* N */
711
	/*  79 */	ED_SEQUENCE_LEAD_IN,	/* O */
712
	/*  80 */	VI_PASTE_PREV,		/* P */
713
	/*  81 */	ED_UNASSIGNED,		/* Q */
714
	/*  82 */	VI_REPLACE_MODE,	/* R */
715
	/*  83 */	VI_SUBSTITUTE_LINE,	/* S */
716
	/*  84 */	VI_TO_PREV_CHAR,	/* T */
717
	/*  85 */	VI_UNDO_LINE,		/* U */
718
	/*  86 */	ED_UNASSIGNED,		/* V */
719
	/*  87 */	VI_NEXT_BIG_WORD,	/* W */
720
	/*  88 */	ED_DELETE_PREV_CHAR,	/* X */
721
	/*  89 */	VI_YANK_END,		/* Y */
722
	/*  90 */	ED_UNASSIGNED,		/* Z */
723
	/*  91 */	ED_SEQUENCE_LEAD_IN,	/* [ */
724
	/*  92 */	ED_UNASSIGNED,		/* \ */
725
	/*  93 */	ED_UNASSIGNED,		/* ] */
726
	/*  94 */	ED_MOVE_TO_BEG,		/* ^ */
727
	/*  95 */	VI_HISTORY_WORD,	/* _ */
728
	/*  96 */	ED_UNASSIGNED,		/* ` */
729
	/*  97 */	VI_ADD,			/* a */
730
	/*  98 */	VI_PREV_WORD,		/* b */
731
	/*  99 */	VI_CHANGE_META,		/* c */
732
	/* 100 */	VI_DELETE_META,		/* d */
733
	/* 101 */	VI_END_WORD,		/* e */
734
	/* 102 */	VI_NEXT_CHAR,		/* f */
735
	/* 103 */	ED_UNASSIGNED,		/* g */
736
	/* 104 */	ED_PREV_CHAR,		/* h */
737
	/* 105 */	VI_INSERT,		/* i */
738
	/* 106 */	ED_NEXT_HISTORY,	/* j */
739
	/* 107 */	ED_PREV_HISTORY,	/* k */
740
	/* 108 */	ED_NEXT_CHAR,		/* l */
741
	/* 109 */	ED_UNASSIGNED,		/* m */
742
	/* 110 */	VI_REPEAT_SEARCH_NEXT,	/* n */
743
	/* 111 */	ED_UNASSIGNED,		/* o */
744
	/* 112 */	VI_PASTE_NEXT,		/* p */
745
	/* 113 */	ED_UNASSIGNED,		/* q */
746
	/* 114 */	VI_REPLACE_CHAR,	/* r */
747
	/* 115 */	VI_SUBSTITUTE_CHAR,	/* s */
748
	/* 116 */	VI_TO_NEXT_CHAR,	/* t */
749
	/* 117 */	VI_UNDO,		/* u */
750
	/* 118 */	VI_HISTEDIT,		/* v */
751
	/* 119 */	VI_NEXT_WORD,		/* w */
752
	/* 120 */	ED_DELETE_NEXT_CHAR,	/* x */
753
	/* 121 */	VI_YANK,		/* y */
754
	/* 122 */	ED_UNASSIGNED,		/* z */
755
	/* 123 */	ED_UNASSIGNED,		/* { */
756
	/* 124 */	VI_TO_COLUMN,		/* | */
757
	/* 125 */	ED_UNASSIGNED,		/* } */
758
	/* 126 */	VI_CHANGE_CASE,		/* ~ */
759
	/* 127 */	ED_DELETE_PREV_CHAR,	/* ^? */
760
	/* 128 */	ED_UNASSIGNED,		/* M-^@ */
761
	/* 129 */	ED_UNASSIGNED,		/* M-^A */
762
	/* 130 */	ED_UNASSIGNED,		/* M-^B */
763
	/* 131 */	ED_UNASSIGNED,		/* M-^C */
764
	/* 132 */	ED_UNASSIGNED,		/* M-^D */
765
	/* 133 */	ED_UNASSIGNED,		/* M-^E */
766
	/* 134 */	ED_UNASSIGNED,		/* M-^F */
767
	/* 135 */	ED_UNASSIGNED,		/* M-^G */
768
	/* 136 */	ED_UNASSIGNED,		/* M-^H */
769
	/* 137 */	ED_UNASSIGNED,		/* M-^I */
770
	/* 138 */	ED_UNASSIGNED,		/* M-^J */
771
	/* 139 */	ED_UNASSIGNED,		/* M-^K */
772
	/* 140 */	ED_UNASSIGNED,		/* M-^L */
773
	/* 141 */	ED_UNASSIGNED,		/* M-^M */
774
	/* 142 */	ED_UNASSIGNED,		/* M-^N */
775
	/* 143 */	ED_UNASSIGNED,		/* M-^O */
776
	/* 144 */	ED_UNASSIGNED,		/* M-^P */
777
	/* 145 */	ED_UNASSIGNED,		/* M-^Q */
778
	/* 146 */	ED_UNASSIGNED,		/* M-^R */
779
	/* 147 */	ED_UNASSIGNED,		/* M-^S */
780
	/* 148 */	ED_UNASSIGNED,		/* M-^T */
781
	/* 149 */	ED_UNASSIGNED,		/* M-^U */
782
	/* 150 */	ED_UNASSIGNED,		/* M-^V */
783
	/* 151 */	ED_UNASSIGNED,		/* M-^W */
784
	/* 152 */	ED_UNASSIGNED,		/* M-^X */
785
	/* 153 */	ED_UNASSIGNED,		/* M-^Y */
786
	/* 154 */	ED_UNASSIGNED,		/* M-^Z */
787
	/* 155 */	ED_UNASSIGNED,		/* M-^[ */
788
	/* 156 */	ED_UNASSIGNED,		/* M-^\ */
789
	/* 157 */	ED_UNASSIGNED,		/* M-^] */
790
	/* 158 */	ED_UNASSIGNED,		/* M-^^ */
791
	/* 159 */	ED_UNASSIGNED,		/* M-^_ */
792
	/* 160 */	ED_UNASSIGNED,		/* M-SPACE */
793
	/* 161 */	ED_UNASSIGNED,		/* M-! */
794
	/* 162 */	ED_UNASSIGNED,		/* M-" */
795
	/* 163 */	ED_UNASSIGNED,		/* M-# */
796
	/* 164 */	ED_UNASSIGNED,		/* M-$ */
797
	/* 165 */	ED_UNASSIGNED,		/* M-% */
798
	/* 166 */	ED_UNASSIGNED,		/* M-& */
799
	/* 167 */	ED_UNASSIGNED,		/* M-' */
800
	/* 168 */	ED_UNASSIGNED,		/* M-( */
801
	/* 169 */	ED_UNASSIGNED,		/* M-) */
802
	/* 170 */	ED_UNASSIGNED,		/* M-* */
803
	/* 171 */	ED_UNASSIGNED,		/* M-+ */
804
	/* 172 */	ED_UNASSIGNED,		/* M-, */
805
	/* 173 */	ED_UNASSIGNED,		/* M-- */
806
	/* 174 */	ED_UNASSIGNED,		/* M-. */
807
	/* 175 */	ED_UNASSIGNED,		/* M-/ */
808
	/* 176 */	ED_UNASSIGNED,		/* M-0 */
809
	/* 177 */	ED_UNASSIGNED,		/* M-1 */
810
	/* 178 */	ED_UNASSIGNED,		/* M-2 */
811
	/* 179 */	ED_UNASSIGNED,		/* M-3 */
812
	/* 180 */	ED_UNASSIGNED,		/* M-4 */
813
	/* 181 */	ED_UNASSIGNED,		/* M-5 */
814
	/* 182 */	ED_UNASSIGNED,		/* M-6 */
815
	/* 183 */	ED_UNASSIGNED,		/* M-7 */
816
	/* 184 */	ED_UNASSIGNED,		/* M-8 */
817
	/* 185 */	ED_UNASSIGNED,		/* M-9 */
818
	/* 186 */	ED_UNASSIGNED,		/* M-: */
819
	/* 187 */	ED_UNASSIGNED,		/* M-; */
820
	/* 188 */	ED_UNASSIGNED,		/* M-< */
821
	/* 189 */	ED_UNASSIGNED,		/* M-= */
822
	/* 190 */	ED_UNASSIGNED,		/* M-> */
823
	/* 191 */	ED_UNASSIGNED,		/* M-? */
824
	/* 192 */	ED_UNASSIGNED,		/* M-@ */
825
	/* 193 */	ED_UNASSIGNED,		/* M-A */
826
	/* 194 */	ED_UNASSIGNED,		/* M-B */
827
	/* 195 */	ED_UNASSIGNED,		/* M-C */
828
	/* 196 */	ED_UNASSIGNED,		/* M-D */
829
	/* 197 */	ED_UNASSIGNED,		/* M-E */
830
	/* 198 */	ED_UNASSIGNED,		/* M-F */
831
	/* 199 */	ED_UNASSIGNED,		/* M-G */
832
	/* 200 */	ED_UNASSIGNED,		/* M-H */
833
	/* 201 */	ED_UNASSIGNED,		/* M-I */
834
	/* 202 */	ED_UNASSIGNED,		/* M-J */
835
	/* 203 */	ED_UNASSIGNED,		/* M-K */
836
	/* 204 */	ED_UNASSIGNED,		/* M-L */
837
	/* 205 */	ED_UNASSIGNED,		/* M-M */
838
	/* 206 */	ED_UNASSIGNED,		/* M-N */
839
	/* 207 */	ED_SEQUENCE_LEAD_IN,	/* M-O */
840
	/* 208 */	ED_UNASSIGNED,		/* M-P */
841
	/* 209 */	ED_UNASSIGNED,		/* M-Q */
842
	/* 210 */	ED_UNASSIGNED,		/* M-R */
843
	/* 211 */	ED_UNASSIGNED,		/* M-S */
844
	/* 212 */	ED_UNASSIGNED,		/* M-T */
845
	/* 213 */	ED_UNASSIGNED,		/* M-U */
846
	/* 214 */	ED_UNASSIGNED,		/* M-V */
847
	/* 215 */	ED_UNASSIGNED,		/* M-W */
848
	/* 216 */	ED_UNASSIGNED,		/* M-X */
849
	/* 217 */	ED_UNASSIGNED,		/* M-Y */
850
	/* 218 */	ED_UNASSIGNED,		/* M-Z */
851
	/* 219 */	ED_SEQUENCE_LEAD_IN,	/* M-[ */
852
	/* 220 */	ED_UNASSIGNED,		/* M-\ */
853
	/* 221 */	ED_UNASSIGNED,		/* M-] */
854
	/* 222 */	ED_UNASSIGNED,		/* M-^ */
855
	/* 223 */	ED_UNASSIGNED,		/* M-_ */
856
	/* 224 */	ED_UNASSIGNED,		/* M-` */
857
	/* 225 */	ED_UNASSIGNED,		/* M-a */
858
	/* 226 */	ED_UNASSIGNED,		/* M-b */
859
	/* 227 */	ED_UNASSIGNED,		/* M-c */
860
	/* 228 */	ED_UNASSIGNED,		/* M-d */
861
	/* 229 */	ED_UNASSIGNED,		/* M-e */
862
	/* 230 */	ED_UNASSIGNED,		/* M-f */
863
	/* 231 */	ED_UNASSIGNED,		/* M-g */
864
	/* 232 */	ED_UNASSIGNED,		/* M-h */
865
	/* 233 */	ED_UNASSIGNED,		/* M-i */
866
	/* 234 */	ED_UNASSIGNED,		/* M-j */
867
	/* 235 */	ED_UNASSIGNED,		/* M-k */
868
	/* 236 */	ED_UNASSIGNED,		/* M-l */
869
	/* 237 */	ED_UNASSIGNED,		/* M-m */
870
	/* 238 */	ED_UNASSIGNED,		/* M-n */
871
	/* 239 */	ED_UNASSIGNED,		/* M-o */
872
	/* 240 */	ED_UNASSIGNED,		/* M-p */
873
	/* 241 */	ED_UNASSIGNED,		/* M-q */
874
	/* 242 */	ED_UNASSIGNED,		/* M-r */
875
	/* 243 */	ED_UNASSIGNED,		/* M-s */
876
	/* 244 */	ED_UNASSIGNED,		/* M-t */
877
	/* 245 */	ED_UNASSIGNED,		/* M-u */
878
	/* 246 */	ED_UNASSIGNED,		/* M-v */
879
	/* 247 */	ED_UNASSIGNED,		/* M-w */
880
	/* 248 */	ED_UNASSIGNED,		/* M-x */
881
	/* 249 */	ED_UNASSIGNED,		/* M-y */
882
	/* 250 */	ED_UNASSIGNED,		/* M-z */
883
	/* 251 */	ED_UNASSIGNED,		/* M-{ */
884
	/* 252 */	ED_UNASSIGNED,		/* M-| */
885
	/* 253 */	ED_UNASSIGNED,		/* M-} */
886
	/* 254 */	ED_UNASSIGNED,		/* M-~ */
887
	/* 255 */	ED_UNASSIGNED		/* M-^? */
888
};
889
890
891
/* map_init():
892
 *	Initialize and allocate the maps
893
 */
894
protected int
895
map_init(EditLine *el)
896
{
897
898
	/*
899
         * Make sure those are correct before starting.
900
         */
901
#ifdef MAP_DEBUG
902
	if (sizeof(el_map_emacs) != N_KEYS * sizeof(el_action_t))
903
		EL_ABORT((el->errfile, "Emacs map incorrect\n"));
904
	if (sizeof(el_map_vi_command) != N_KEYS * sizeof(el_action_t))
905
		EL_ABORT((el->errfile, "Vi command map incorrect\n"));
906
	if (sizeof(el_map_vi_insert) != N_KEYS * sizeof(el_action_t))
907
		EL_ABORT((el->errfile, "Vi insert map incorrect\n"));
908
#endif
909
910
12
	el->el_map.alt = reallocarray(NULL, N_KEYS, sizeof(el_action_t));
911
6
	if (el->el_map.alt == NULL)
912
		return -1;
913
6
	el->el_map.key = reallocarray(NULL, N_KEYS, sizeof(el_action_t));
914
6
	if (el->el_map.key == NULL)
915
		return -1;
916
6
	el->el_map.emacs = el_map_emacs;
917
6
	el->el_map.vic = el_map_vi_command;
918
6
	el->el_map.vii = el_map_vi_insert;
919
6
	el->el_map.help = reallocarray(NULL, EL_NUM_FCNS,
920
	    sizeof(el_bindings_t));
921
6
	if (el->el_map.help == NULL)
922
		return -1;
923
6
	(void) memcpy(el->el_map.help, el_func_help,
924
	    sizeof(el_bindings_t) * EL_NUM_FCNS);
925
6
	el->el_map.func = reallocarray(NULL, EL_NUM_FCNS,
926
	    sizeof(el_func_t));
927
6
	if (el->el_map.func == NULL)
928
		return -1;
929
6
	memcpy(el->el_map.func, el_func, sizeof(el_func_t) * EL_NUM_FCNS);
930
6
	el->el_map.nfunc = EL_NUM_FCNS;
931
932
#ifdef VIDEFAULT
933
6
	map_init_vi(el);
934
#else
935
	map_init_emacs(el);
936
#endif /* VIDEFAULT */
937
6
	return 0;
938
6
}
939
940
941
/* map_end():
942
 *	Free the space taken by the editor maps
943
 */
944
protected void
945
map_end(EditLine *el)
946
{
947
948
	free(el->el_map.alt);
949
	el->el_map.alt = NULL;
950
	free(el->el_map.key);
951
	el->el_map.key = NULL;
952
	el->el_map.emacs = NULL;
953
	el->el_map.vic = NULL;
954
	el->el_map.vii = NULL;
955
	free(el->el_map.help);
956
	el->el_map.help = NULL;
957
	free(el->el_map.func);
958
	el->el_map.func = NULL;
959
}
960
961
962
/* map_init_nls():
963
 *	Find all the printable keys and bind them to self insert
964
 */
965
static void
966
map_init_nls(EditLine *el)
967
{
968
	int i;
969
970
24
	el_action_t *map = el->el_map.key;
971
972
3096
	for (i = 0200; i <= 0377; i++)
973
1536
		if (iswprint(i))
974
			map[i] = ED_INSERT;
975
12
}
976
977
978
/* map_init_meta():
979
 *	Bind all the meta keys to the appropriate ESC-<key> sequence
980
 */
981
static void
982
map_init_meta(EditLine *el)
983
{
984
24
	wchar_t buf[3];
985
	int i;
986
12
	el_action_t *map = el->el_map.key;
987
12
	el_action_t *alt = el->el_map.alt;
988
989

5124
	for (i = 0; i <= 0377 && map[i] != EM_META_NEXT; i++)
990
		continue;
991
992
12
	if (i > 0377) {
993

504
		for (i = 0; i <= 0377 && alt[i] != EM_META_NEXT; i++)
994
			continue;
995
6
		if (i > 0377) {
996
			i = 033;
997
			if (el->el_map.type == MAP_VI)
998
				map = alt;
999
		} else
1000
			map = alt;
1001
	}
1002
12
	buf[0] = (wchar_t)i;
1003
12
	buf[2] = 0;
1004
3096
	for (i = 0200; i <= 0377; i++)
1005

1740
		switch (map[i]) {
1006
		case ED_INSERT:
1007
		case ED_UNASSIGNED:
1008
		case ED_SEQUENCE_LEAD_IN:
1009
			break;
1010
		default:
1011
204
			buf[1] = i & 0177;
1012
204
			keymacro_add(el, buf, keymacro_map_cmd(el, (int) map[i]), XK_CMD);
1013
204
			break;
1014
		}
1015
12
	map[(int) buf[0]] = ED_SEQUENCE_LEAD_IN;
1016
12
}
1017
1018
1019
/* map_init_vi():
1020
 *	Initialize the vi bindings
1021
 */
1022
protected void
1023
map_init_vi(EditLine *el)
1024
{
1025
	int i;
1026
12
	el_action_t *key = el->el_map.key;
1027
6
	el_action_t *alt = el->el_map.alt;
1028
6
	const el_action_t *vii = el->el_map.vii;
1029
6
	const el_action_t *vic = el->el_map.vic;
1030
1031
6
	el->el_map.type = MAP_VI;
1032
6
	el->el_map.current = el->el_map.key;
1033
1034
6
	keymacro_reset(el);
1035
1036
3084
	for (i = 0; i < N_KEYS; i++) {
1037
1536
		key[i] = vii[i];
1038
1536
		alt[i] = vic[i];
1039
	}
1040
1041
6
	map_init_meta(el);
1042
6
	map_init_nls(el);
1043
1044
6
	tty_bind_char(el, 1);
1045
6
	terminal_bind_arrow(el);
1046
6
}
1047
1048
1049
/* map_init_emacs():
1050
 *	Initialize the emacs bindings
1051
 */
1052
protected void
1053
map_init_emacs(EditLine *el)
1054
{
1055
	int i;
1056
12
	wchar_t buf[3];
1057
6
	el_action_t *key = el->el_map.key;
1058
6
	el_action_t *alt = el->el_map.alt;
1059
6
	const el_action_t *emacs = el->el_map.emacs;
1060
1061
6
	el->el_map.type = MAP_EMACS;
1062
6
	el->el_map.current = el->el_map.key;
1063
6
	keymacro_reset(el);
1064
1065
3084
	for (i = 0; i < N_KEYS; i++) {
1066
1536
		key[i] = emacs[i];
1067
1536
		alt[i] = ED_UNASSIGNED;
1068
	}
1069
1070
6
	map_init_meta(el);
1071
6
	map_init_nls(el);
1072
1073
6
	buf[0] = CONTROL('X');
1074
6
	buf[1] = CONTROL('X');
1075
6
	buf[2] = 0;
1076
6
	keymacro_add(el, buf, keymacro_map_cmd(el, EM_EXCHANGE_MARK), XK_CMD);
1077
1078
6
	tty_bind_char(el, 1);
1079
6
	terminal_bind_arrow(el);
1080
6
}
1081
1082
1083
/* map_set_editor():
1084
 *	Set the editor
1085
 */
1086
protected int
1087
map_set_editor(EditLine *el, wchar_t *editor)
1088
{
1089
1090
12
	if (wcscmp(editor, L"emacs") == 0) {
1091
6
		map_init_emacs(el);
1092
6
		return 0;
1093
	}
1094
	if (wcscmp(editor, L"vi") == 0) {
1095
		map_init_vi(el);
1096
		return 0;
1097
	}
1098
	return -1;
1099
6
}
1100
1101
1102
/* map_get_editor():
1103
 *	Retrieve the editor
1104
 */
1105
protected int
1106
map_get_editor(EditLine *el, const wchar_t **editor)
1107
{
1108
1109
	if (editor == NULL)
1110
		return -1;
1111
	switch (el->el_map.type) {
1112
	case MAP_EMACS:
1113
		*editor = L"emacs";
1114
		return 0;
1115
	case MAP_VI:
1116
		*editor = L"vi";
1117
		return 0;
1118
	}
1119
	return -1;
1120
}
1121
1122
1123
/* map_print_key():
1124
 *	Print the function description for 1 key
1125
 */
1126
static void
1127
map_print_key(EditLine *el, el_action_t *map, const wchar_t *in)
1128
{
1129
	char outbuf[EL_BUFSIZ];
1130
	el_bindings_t *bp, *ep;
1131
1132
	if (in[0] == '\0' || in[1] == '\0') {
1133
		(void) keymacro__decode_str(in, outbuf, sizeof(outbuf), "");
1134
		ep = &el->el_map.help[el->el_map.nfunc];
1135
		for (bp = el->el_map.help; bp < ep; bp++)
1136
			if (bp->func == map[(unsigned char) *in]) {
1137
				(void) fprintf(el->el_outfile,
1138
				    "%s\t->\t%ls\n", outbuf, bp->name);
1139
				return;
1140
			}
1141
	} else
1142
		keymacro_print(el, in);
1143
}
1144
1145
1146
/* map_print_some_keys():
1147
 *	Print keys from first to last
1148
 */
1149
static void
1150
map_print_some_keys(EditLine *el, el_action_t *map, wint_t first, wint_t last)
1151
{
1152
	el_bindings_t *bp, *ep;
1153
	wchar_t firstbuf[2], lastbuf[2];
1154
	char unparsbuf[EL_BUFSIZ], extrabuf[EL_BUFSIZ];
1155
1156
	firstbuf[0] = first;
1157
	firstbuf[1] = 0;
1158
	lastbuf[0] = last;
1159
	lastbuf[1] = 0;
1160
	if (map[first] == ED_UNASSIGNED) {
1161
		if (first == last) {
1162
			(void) keymacro__decode_str(firstbuf, unparsbuf,
1163
			    sizeof(unparsbuf), STRQQ);
1164
			(void) fprintf(el->el_outfile,
1165
			    "%-15s->  is undefined\n", unparsbuf);
1166
		}
1167
		return;
1168
	}
1169
	ep = &el->el_map.help[el->el_map.nfunc];
1170
	for (bp = el->el_map.help; bp < ep; bp++) {
1171
		if (bp->func == map[first]) {
1172
			if (first == last) {
1173
				(void) keymacro__decode_str(firstbuf, unparsbuf,
1174
				    sizeof(unparsbuf), STRQQ);
1175
				(void) fprintf(el->el_outfile, "%-15s->  %ls\n",
1176
				    unparsbuf, bp->name);
1177
			} else {
1178
				(void) keymacro__decode_str(firstbuf, unparsbuf,
1179
				    sizeof(unparsbuf), STRQQ);
1180
				(void) keymacro__decode_str(lastbuf, extrabuf,
1181
				    sizeof(extrabuf), STRQQ);
1182
				(void) fprintf(el->el_outfile,
1183
				    "%-4s to %-7s->  %ls\n",
1184
				    unparsbuf, extrabuf, bp->name);
1185
			}
1186
			return;
1187
		}
1188
	}
1189
#ifdef MAP_DEBUG
1190
	if (map == el->el_map.key) {
1191
		(void) keymacro__decode_str(firstbuf, unparsbuf,
1192
		    sizeof(unparsbuf), STRQQ);
1193
		(void) fprintf(el->el_outfile,
1194
		    "BUG!!! %s isn't bound to anything.\n", unparsbuf);
1195
		(void) fprintf(el->el_outfile, "el->el_map.key[%d] == %d\n",
1196
		    first, el->el_map.key[first]);
1197
	} else {
1198
		(void) keymacro__decode_str(firstbuf, unparsbuf,
1199
		    sizeof(unparsbuf), STRQQ);
1200
		(void) fprintf(el->el_outfile,
1201
		    "BUG!!! %s isn't bound to anything.\n", unparsbuf);
1202
		(void) fprintf(el->el_outfile, "el->el_map.alt[%d] == %d\n",
1203
		    first, el->el_map.alt[first]);
1204
	}
1205
#endif
1206
	EL_ABORT((el->el_errfile, "Error printing keys\n"));
1207
}
1208
1209
1210
/* map_print_all_keys():
1211
 *	Print the function description for all keys.
1212
 */
1213
static void
1214
map_print_all_keys(EditLine *el)
1215
{
1216
	int prev, i;
1217
1218
	(void) fprintf(el->el_outfile, "Standard key bindings\n");
1219
	prev = 0;
1220
	for (i = 0; i < N_KEYS; i++) {
1221
		if (el->el_map.key[prev] == el->el_map.key[i])
1222
			continue;
1223
		map_print_some_keys(el, el->el_map.key, prev, i - 1);
1224
		prev = i;
1225
	}
1226
	map_print_some_keys(el, el->el_map.key, prev, i - 1);
1227
1228
	(void) fprintf(el->el_outfile, "Alternative key bindings\n");
1229
	prev = 0;
1230
	for (i = 0; i < N_KEYS; i++) {
1231
		if (el->el_map.alt[prev] == el->el_map.alt[i])
1232
			continue;
1233
		map_print_some_keys(el, el->el_map.alt, prev, i - 1);
1234
		prev = i;
1235
	}
1236
	map_print_some_keys(el, el->el_map.alt, prev, i - 1);
1237
1238
	(void) fprintf(el->el_outfile, "Multi-character bindings\n");
1239
	keymacro_print(el, L"");
1240
	(void) fprintf(el->el_outfile, "Arrow key bindings\n");
1241
	terminal_print_arrow(el, L"");
1242
}
1243
1244
1245
/* map_bind():
1246
 *	Add/remove/change bindings
1247
 */
1248
protected int
1249
map_bind(EditLine *el, int argc, const wchar_t **argv)
1250
{
1251
	el_action_t *map;
1252
	int ntype, rem;
1253
	const wchar_t *p;
1254
24
	wchar_t inbuf[EL_BUFSIZ];
1255
12
	wchar_t outbuf[EL_BUFSIZ];
1256
	const wchar_t *in = NULL;
1257
	wchar_t *out = NULL;
1258
	el_bindings_t *bp, *ep;
1259
	int cmd;
1260
	int key;
1261
1262
12
	if (argv == NULL)
1263
		return -1;
1264
1265
12
	map = el->el_map.key;
1266
	ntype = XK_CMD;
1267
	key = rem = 0;
1268
24
	for (argc = 1; (p = argv[argc]) != NULL; argc++)
1269
12
		if (p[0] == '-')
1270
			switch (p[1]) {
1271
			case 'a':
1272
				map = el->el_map.alt;
1273
				break;
1274
1275
			case 's':
1276
				ntype = XK_STR;
1277
				break;
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
					    "%ls\n\t%ls\n",
1299
					    bp->name, bp->description);
1300
				return 0;
1301
			default:
1302
				(void) fprintf(el->el_errfile,
1303
				    "%ls: Invalid switch `%lc'.\n",
1304
				    argv[0], (wint_t)p[1]);
1305
			}
1306
		else
1307
			break;
1308
1309
12
	if (argv[argc] == NULL) {
1310
		map_print_all_keys(el);
1311
		return 0;
1312
	}
1313
12
	if (key)
1314
		in = argv[argc++];
1315
12
	else if ((in = parse__string(inbuf, argv[argc++])) == NULL) {
1316
		(void) fprintf(el->el_errfile,
1317
		    "%ls: Invalid \\ or ^ in instring.\n",
1318
		    argv[0]);
1319
		return -1;
1320
	}
1321
12
	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
12
	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
		bindkey_usage();
1344
		return -1;
1345
	}
1346
#endif
1347
1348
12
	switch (ntype) {
1349
	case XK_STR:
1350
		if ((out = parse__string(outbuf, argv[argc])) == NULL) {
1351
			(void) fprintf(el->el_errfile,
1352
			    "%ls: Invalid \\ or ^ in outstring.\n", argv[0]);
1353
			return -1;
1354
		}
1355
		if (key)
1356
			terminal_set_arrow(el, in, keymacro_map_str(el, out), ntype);
1357
		else
1358
			keymacro_add(el, in, keymacro_map_str(el, out), ntype);
1359
		map[(unsigned char) *in] = ED_SEQUENCE_LEAD_IN;
1360
		break;
1361
1362
	case XK_CMD:
1363
12
		if ((cmd = parse_cmd(el, argv[argc])) == -1) {
1364
			(void) fprintf(el->el_errfile,
1365
			    "%ls: Invalid command `%ls'.\n",
1366
			    argv[0], argv[argc]);
1367
			return -1;
1368
		}
1369
12
		if (key)
1370
			terminal_set_arrow(el, in, keymacro_map_str(el, out), ntype);
1371
		else {
1372
12
			if (in[1]) {
1373
				keymacro_add(el, in, keymacro_map_cmd(el, cmd), ntype);
1374
				map[(unsigned char) *in] = ED_SEQUENCE_LEAD_IN;
1375
			} else {
1376
12
				keymacro_clear(el, map, in);
1377
12
				map[(unsigned char) *in] = cmd;
1378
			}
1379
		}
1380
		break;
1381
1382
	default:
1383
		EL_ABORT((el->el_errfile, "Bad XK_ type %d\n", ntype));
1384
		break;
1385
	}
1386
12
	return 0;
1387
12
}
1388
1389
1390
/* map_addfunc():
1391
 *	add a user defined function
1392
 */
1393
protected int
1394
map_addfunc(EditLine *el, const wchar_t *name, const wchar_t *help,
1395
    el_func_t func)
1396
{
1397
	void *p;
1398
24
	int nf = el->el_map.nfunc + 1;
1399
1400
12
	if (name == NULL || help == NULL || func == NULL)
1401
		return -1;
1402
1403
12
	if ((p = reallocarray(el->el_map.func, nf, sizeof(el_func_t))) == NULL)
1404
		return -1;
1405
12
	el->el_map.func = (el_func_t *) p;
1406
24
	if ((p = reallocarray(el->el_map.help, nf, sizeof(el_bindings_t)))
1407
12
	    == NULL)
1408
		return -1;
1409
12
	el->el_map.help = (el_bindings_t *) p;
1410
1411
12
	nf = el->el_map.nfunc;
1412
12
	el->el_map.func[nf] = func;
1413
1414
12
	el->el_map.help[nf].name = name;
1415
12
	el->el_map.help[nf].func = nf;
1416
12
	el->el_map.help[nf].description = help;
1417
12
	el->el_map.nfunc++;
1418
1419
12
	return 0;
1420
12
}