1 /*
2  * keys.c: Does command line parsing, etc
3  *
4  * Written By Michael Sandrof
5  *
6  * Copyright (c) 1990 Michael Sandrof.
7  * Copyright (c) 1991, 1992 Troy Rollo.
8  * Copyright (c) 1992-2019 Matthew R. Green.
9  * All rights reserved.
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. The name of the author may not be used to endorse or promote products
20  *    derived from this software without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
23  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25  * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
29  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30  * 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 "irc.h"
36 IRCII_RCSID("@(#)$eterna: keys.c,v 1.71 2019/01/15 10:13:07 mrg Exp $");
37 
38 #include "output.h"
39 #include "keys.h"
40 #include "names.h"
41 #include "ircaux.h"
42 #include "window.h"
43 #include "edit.h"
44 #include "vars.h"
45 #include "translat.h"
46 #include "ircterm.h"
47 #include "input.h"
48 #include "screen.h"
49 #include "menu.h"
50 #include "ircterm.h"
51 
52 /* KeyMapNames: the structure of the keymap to realname array */
53 typedef struct
54 {
55 	char	*name;
56 	KeyMap_Func func;
57 }	KeyMapNames;
58 
59 static	int	lookup_function(u_char *, int *);
60 static	u_char	* display_key(u_int);
61 static	void	show_binding(u_int, int);
62 static	int	parse_key(u_char *);
63 static	void	write_binding(u_int, u_int, FILE *, int);
64 static	void	bind_it(u_char *, u_char *, u_int, int);
65 
66 /* The string values for these *MUST* be in ALL CAPITALS */
67 static KeyMapNames key_names[] =
68 {
69 	{ "BACKSPACE",			input_backspace },
70 	{ "BACKWARD_CHARACTER",		backward_character },
71 	{ "BACKWARD_HISTORY",		backward_history },
72 	{ "BACKWARD_WORD",		input_backward_word },
73 	{ "BEGINNING_OF_LINE",		input_beginning_of_line },
74 	{ "CLEAR_SCREEN",		irc_clear_screen },
75 	{ "COMMAND_COMPLETION",		command_completion },
76 	{ "DELETE_CHARACTER",		input_delete_character },
77 	{ "DELETE_NEXT_WORD",		input_delete_next_word },
78 	{ "DELETE_PREVIOUS_WORD",	input_delete_previous_word },
79 	{ "END_OF_LINE",		input_end_of_line },
80 	{ "ENTER_DIGRAPH",		enter_digraph },
81 	{ "ENTER_MENU",			enter_menu },
82 	{ "ERASE_LINE",			input_clear_line },
83 	{ "ERASE_TO_BEG_OF_LINE",	input_clear_to_bol },
84 	{ "ERASE_TO_END_OF_LINE",	input_clear_to_eol },
85 	{ "FORWARD_CHARACTER",		forward_character },
86 	{ "FORWARD_HISTORY",		forward_history },
87 	{ "FORWARD_WORD",		input_forward_word },
88 	{ "META1_CHARACTER",		meta1_char },
89 	{ "META2_CHARACTER",		meta2_char },
90 	{ "META3_CHARACTER",		meta3_char },
91 	{ "META4_CHARACTER",		meta4_char },
92 	{ "META5_CHARACTER",		meta5_char },
93 	{ "META6_CHARACTER",		meta6_char },
94 	{ "META7_CHARACTER",		meta7_char },
95 	{ "META8_CHARACTER",		meta8_char },
96 	{ "NEXT_WINDOW",		next_window_key },
97 	{ "NOTHING",			NULL },
98 	{ "PARSE_COMMAND",		parse_text },
99 	{ "PREVIOUS_WINDOW",		previous_window },
100 	{ "QUIT_IRC",			irc_quit },
101 	{ "QUOTE_CHARACTER",		quote_char },
102 	{ "REFRESH_INPUTLINE",		refresh_inputline },
103 	{ "REFRESH_SCREEN",		refresh_screen },
104 	{ "REFRESH_WINDOW_LASTLOG",	window_refresh_lastlog_key },
105 	{ "SCROLL_BACKWARD",		scrollback_backwards },
106 	{ "SCROLL_END",			scrollback_end },
107 	{ "SCROLL_FORWARD",		scrollback_forwards },
108 	{ "SCROLL_START",		scrollback_start },
109 	{ "SELF_INSERT",		input_add_character },
110 	{ "SEND_LINE",			send_line },
111 	{ "STOP_IRC",			term_pause },
112 	{ "SWAP_LAST_WINDOW",		swap_last_window },
113 	{ "SWAP_NEXT_WINDOW",		swap_next_window },
114 	{ "SWAP_PREVIOUS_WINDOW",	swap_previous_window },
115 	{ "SWITCH_CHANNELS",		switch_channels },
116 	{ "TOGGLE_INSERT_MODE",		toggle_insert_mode },
117 	{ "TOGGLE_STOP_SCREEN",		toggle_stop_screen },
118 	{ "TRANSPOSE_CHARACTERS",	input_transpose_characters },
119 	{ "TYPE_TEXT",			type_text },
120 	{ "UNSTOP_ALL_WINDOWS",		unstop_all_windows },
121 	{ "YANK_FROM_CUTBUFFER",	input_yank_cut_buffer }
122 };
123 
124 /* Do we default to having the Emacs like meta keys? */
125 #ifdef WITH_EMACS_META_KEYS
126 # define EMACS_SCROLL_START		SCROLL_START
127 # define EMACS_SCROLL_END		SCROLL_END
128 # define EMACS_FORWARD_WORD		FORWARD_WORD
129 # define EMACS_BACKWARD_WORD		BACKWARD_WORD
130 # define EMACS_DELETE_NEXT_WORD		DELETE_NEXT_WORD
131 # define EMACS_DELETE_PREVIOUS_WORD	DELETE_PREVIOUS_WORD
132 # define EMACS_SCROLL_END		SCROLL_END
133 #else
134 # define EMACS_SCROLL_START		SELF_INSERT
135 # define EMACS_SCROLL_END		SELF_INSERT
136 # define EMACS_FORWARD_WORD		SELF_INSERT
137 # define EMACS_BACKWARD_WORD		SELF_INSERT
138 # define EMACS_DELETE_NEXT_WORD		SELF_INSERT
139 # define EMACS_DELETE_PREVIOUS_WORD	SELF_INSERT
140 # define EMACS_SCROLL_END		SELF_INSERT
141 #endif
142 
143 static KeyMap	keys[] =
144 {
145 	{ SELF_INSERT,		0, 0,	NULL },	/* 0 */
146 	{ BEGINNING_OF_LINE,	0, 0,	NULL },
147 	{ BACKWARD_CHARACTER,	0, 0,	NULL },
148 	{ QUIT_IRC,		0, 0,	NULL },
149 	{ DELETE_CHARACTER,	0, 0,	NULL },
150 	{ END_OF_LINE,		0, 0,	NULL },
151 	{ FORWARD_CHARACTER,	0, 0,	NULL },
152 	{ SELF_INSERT,		0, 0,	NULL },
153 
154 	{ BACKSPACE,		0, 0,	NULL },	/* 8 */
155 	{ TOGGLE_INSERT_MODE,	0, 0,	NULL },
156 	{ SEND_LINE,		0, 0,	NULL },
157 	{ ERASE_TO_END_OF_LINE,	0, 0,	NULL },
158 	{ REFRESH_SCREEN,	0, 0,	NULL },
159 	{ SEND_LINE,		0, 0,	NULL },
160 	{ FORWARD_HISTORY,	0, 0,	NULL },
161 	{ SELF_INSERT,		0, 0,	NULL },
162 
163 	{ BACKWARD_HISTORY,	0, 0,	NULL },	/* 16 */
164 	{ QUOTE_CHARACTER,	0, 0,	NULL },
165 	{ ENTER_MENU,		0, 0,	NULL },
166 	{ TOGGLE_STOP_SCREEN,	0, 0,	NULL },
167 	{ TRANSPOSE_CHARACTERS,	0, 0,	NULL },
168 	{ ERASE_TO_BEG_OF_LINE,	0, 0,	NULL },
169 	{ SELF_INSERT,		0, 0,	NULL },
170 	{ SELF_INSERT,		0, 0,	NULL },
171 
172 	{ META2_CHARACTER,	0, 0,	NULL },	/* 24 */
173 	{ YANK_FROM_CUTBUFFER,	0, 0,	NULL },
174 			/* And I moved STOP_IRC to META1 26 */
175 	{ ENTER_DIGRAPH,	0, 0,	NULL },
176 	{ META1_CHARACTER,	0, 0,	NULL },
177 	{ SELF_INSERT,		0, 0,	NULL },
178 	{ SELF_INSERT,		0, 0,	NULL },
179 	{ SELF_INSERT,		0, 0,	NULL },
180 	{ SELF_INSERT,		0, 0,	NULL },
181 
182 	{ SELF_INSERT,		0, 0,	NULL },	/* 32 */
183 	{ SELF_INSERT,		0, 0,	NULL },
184 	{ SELF_INSERT,		0, 0,	NULL },
185 	{ SELF_INSERT,		0, 0,	NULL },
186 	{ SELF_INSERT,		0, 0,	NULL },
187 	{ SELF_INSERT,		0, 0,	NULL },
188 	{ SELF_INSERT,		0, 0,	NULL },
189 	{ SELF_INSERT,		0, 0,	NULL },
190 
191 	{ SELF_INSERT,		0, 0,	NULL },	/* 40 */
192 	{ SELF_INSERT,		0, 0,	NULL },
193 	{ SELF_INSERT,		0, 0,	NULL },
194 	{ SELF_INSERT,		0, 0,	NULL },
195 	{ SELF_INSERT,		0, 0,	NULL },
196 	{ SELF_INSERT,		0, 0,	NULL },
197 	{ SELF_INSERT,		0, 0,	NULL },
198 	{ SELF_INSERT,		0, 0,	NULL },
199 
200 	{ SELF_INSERT,		0, 0,	NULL },	/* 48 */
201 	{ SELF_INSERT,		0, 0,	NULL },
202 	{ SELF_INSERT,		0, 0,	NULL },
203 	{ SELF_INSERT,		0, 0,	NULL },
204 	{ SELF_INSERT,		0, 0,	NULL },
205 	{ SELF_INSERT,		0, 0,	NULL },
206 	{ SELF_INSERT,		0, 0,	NULL },
207 	{ SELF_INSERT,		0, 0,	NULL },
208 
209 	{ SELF_INSERT,		0, 0,	NULL },	/* 56 */
210 	{ SELF_INSERT,		0, 0,	NULL },
211 	{ SELF_INSERT,		0, 0,	NULL },
212 	{ SELF_INSERT,		0, 0,	NULL },
213 	{ SELF_INSERT,		0, 0,	NULL },
214 	{ SELF_INSERT,		0, 0,	NULL },
215 	{ SELF_INSERT,		0, 0,	NULL },
216 	{ SELF_INSERT,		0, 0,	NULL },
217 
218 	{ SELF_INSERT,		0, 0,	NULL },	/* 64 */
219 	{ SELF_INSERT,		0, 0,	NULL },
220 	{ SELF_INSERT,		0, 0,	NULL },
221 	{ SELF_INSERT,		0, 0,	NULL },
222 	{ SELF_INSERT,		0, 0,	NULL },
223 	{ SELF_INSERT,		0, 0,	NULL },
224 	{ SELF_INSERT,		0, 0,	NULL },
225 	{ SELF_INSERT,		0, 0,	NULL },
226 
227 	{ SELF_INSERT,		0, 0,	NULL },	/* 72 */
228 	{ SELF_INSERT,		0, 0,	NULL },
229 	{ SELF_INSERT,		0, 0,	NULL },
230 	{ SELF_INSERT,		0, 0,	NULL },
231 	{ SELF_INSERT,		0, 0,	NULL },
232 	{ SELF_INSERT,		0, 0,	NULL },
233 	{ SELF_INSERT,		0, 0,	NULL },
234 	{ SELF_INSERT,		0, 0,	NULL },
235 
236 	{ SELF_INSERT,		0, 0,	NULL },	/* 80 */
237 	{ SELF_INSERT,		0, 0,	NULL },
238 	{ SELF_INSERT,		0, 0,	NULL },
239 	{ SELF_INSERT,		0, 0,	NULL },
240 	{ SELF_INSERT,		0, 0,	NULL },
241 	{ SELF_INSERT,		0, 0,	NULL },
242 	{ SELF_INSERT,		0, 0,	NULL },
243 	{ SELF_INSERT,		0, 0,	NULL },
244 
245 	{ SELF_INSERT,		0, 0,	NULL },	/* 88 */
246 	{ SELF_INSERT,		0, 0,	NULL },
247 	{ SELF_INSERT,		0, 0,	NULL },
248 	{ SELF_INSERT,		0, 0,	NULL },
249 	{ SELF_INSERT,		0, 0,	NULL },
250 	{ SELF_INSERT,		0, 0,	NULL },
251 	{ SELF_INSERT,		0, 0,	NULL },
252 	{ SELF_INSERT,		0, 0,	NULL },
253 
254 	{ SELF_INSERT,		0, 0,	NULL },	/* 96 */
255 	{ SELF_INSERT,		0, 0,	NULL },
256 	{ SELF_INSERT,		0, 0,	NULL },
257 	{ SELF_INSERT,		0, 0,	NULL },
258 	{ SELF_INSERT,		0, 0,	NULL },
259 	{ SELF_INSERT,		0, 0,	NULL },
260 	{ SELF_INSERT,		0, 0,	NULL },
261 	{ SELF_INSERT,		0, 0,	NULL },
262 
263 	{ SELF_INSERT,		0, 0,	NULL },	/* 104 */
264 	{ SELF_INSERT,		0, 0,	NULL },
265 	{ SELF_INSERT,		0, 0,	NULL },
266 	{ SELF_INSERT,		0, 0,	NULL },
267 	{ SELF_INSERT,		0, 0,	NULL },
268 	{ SELF_INSERT,		0, 0,	NULL },
269 	{ SELF_INSERT,		0, 0,	NULL },
270 	{ SELF_INSERT,		0, 0,	NULL },
271 
272 	{ SELF_INSERT,		0, 0,	NULL },	/* 112 */
273 	{ SELF_INSERT,		0, 0,	NULL },
274 	{ SELF_INSERT,		0, 0,	NULL },
275 	{ SELF_INSERT,		0, 0,	NULL },
276 	{ SELF_INSERT,		0, 0,	NULL },
277 	{ SELF_INSERT,		0, 0,	NULL },
278 	{ SELF_INSERT,		0, 0,	NULL },
279 	{ SELF_INSERT,		0, 0,	NULL },
280 
281 	{ SELF_INSERT,		0, 0,	NULL },	/* 120 */
282 	{ SELF_INSERT,		0, 0,	NULL },
283 	{ SELF_INSERT,		0, 0,	NULL },
284 	{ SELF_INSERT,		0, 0,	NULL },
285 	{ SELF_INSERT,		0, 0,	NULL },
286 	{ SELF_INSERT,		0, 0,	NULL },
287 	{ SELF_INSERT,		0, 0,	NULL },
288 	{ BACKSPACE,		0, 0,	NULL },
289 
290 	{ SELF_INSERT,		0, 0,	NULL },	/* 128 */
291 	{ SELF_INSERT,		0, 0,	NULL },
292 	{ SELF_INSERT,		0, 0,	NULL },
293 	{ SELF_INSERT,		0, 0,	NULL },
294 	{ SELF_INSERT,		0, 0,	NULL },
295 	{ SELF_INSERT,		0, 0,	NULL },
296 	{ SELF_INSERT,		0, 0,	NULL },
297 	{ SELF_INSERT,		0, 0,	NULL },
298 
299 	{ SELF_INSERT,		0, 0,	NULL },	/* 136 */
300 	{ SELF_INSERT,		0, 0,	NULL },
301 	{ SELF_INSERT,		0, 0,	NULL },
302 	{ SELF_INSERT,		0, 0,	NULL },
303 	{ SELF_INSERT,		0, 0,	NULL },
304 	{ SELF_INSERT,		0, 0,	NULL },
305 	{ SELF_INSERT,		0, 0,	NULL },
306 	{ SELF_INSERT,		0, 0,	NULL },
307 
308 	{ SELF_INSERT,		0, 0,	NULL },	/* 144 */
309 	{ SELF_INSERT,		0, 0,	NULL },
310 	{ SELF_INSERT,		0, 0,	NULL },
311 	{ SELF_INSERT,		0, 0,	NULL },
312 	{ SELF_INSERT,		0, 0,	NULL },
313 	{ SELF_INSERT,		0, 0,	NULL },
314 	{ SELF_INSERT,		0, 0,	NULL },
315 	{ SELF_INSERT,		0, 0,	NULL },
316 
317 	{ SELF_INSERT,		0, 0,	NULL },	/* 152 */
318 	{ SELF_INSERT,		0, 0,	NULL },
319 	{ SELF_INSERT,		0, 0,	NULL },
320 	{ SELF_INSERT,		0, 0,	NULL },
321 	{ SELF_INSERT,		0, 0,	NULL },
322 	{ SELF_INSERT,		0, 0,	NULL },
323 	{ SELF_INSERT,		0, 0,	NULL },
324 	{ SELF_INSERT,		0, 0,	NULL },
325 
326 	{ SELF_INSERT,		0, 0,	NULL },	/* 160 */
327 	{ SELF_INSERT,		0, 0,	NULL },
328 	{ SELF_INSERT,		0, 0,	NULL },
329 	{ SELF_INSERT,		0, 0,	NULL },
330 	{ SELF_INSERT,		0, 0,	NULL },
331 	{ SELF_INSERT,		0, 0,	NULL },
332 	{ SELF_INSERT,		0, 0,	NULL },
333 	{ SELF_INSERT,		0, 0,	NULL },
334 
335 	{ SELF_INSERT,		0, 0,	NULL },	/* 168 */
336 	{ SELF_INSERT,		0, 0,	NULL },
337 	{ SELF_INSERT,		0, 0,	NULL },
338 	{ SELF_INSERT,		0, 0,	NULL },
339 	{ SELF_INSERT,		0, 0,	NULL },
340 	{ SELF_INSERT,		0, 0,	NULL },
341 	{ SELF_INSERT,		0, 0,	NULL },
342 	{ SELF_INSERT,		0, 0,	NULL },
343 
344 	{ SELF_INSERT,		0, 0,	NULL },	/* 176 */
345 	{ SELF_INSERT,		0, 0,	NULL },
346 	{ SELF_INSERT,		0, 0,	NULL },
347 	{ SELF_INSERT,		0, 0,	NULL },
348 	{ SELF_INSERT,		0, 0,	NULL },
349 	{ SELF_INSERT,		0, 0,	NULL },
350 	{ SELF_INSERT,		0, 0,	NULL },
351 	{ SELF_INSERT,		0, 0,	NULL },
352 
353 	{ SELF_INSERT,		0, 0,	NULL },	/* 184 */
354 	{ SELF_INSERT,		0, 0,	NULL },
355 	{ SELF_INSERT,		0, 0,	NULL },
356 	{ SELF_INSERT,		0, 0,	NULL },
357 	{ SELF_INSERT,		0, 0,	NULL },
358 	{ EMACS_SCROLL_START,	0, 0,	NULL },
359 	{ SELF_INSERT,		0, 0,	NULL },
360 	{ EMACS_SCROLL_END,	0, 0,	NULL },
361 
362 	{ SELF_INSERT,		0, 0,	NULL },	/* 192 */
363 	{ SELF_INSERT,		0, 0,	NULL },
364 	{ SELF_INSERT,		0, 0,	NULL },
365 	{ SELF_INSERT,		0, 0,	NULL },
366 	{ SELF_INSERT,		0, 0,	NULL },
367 	{ SELF_INSERT,		0, 0,	NULL },
368 	{ SELF_INSERT,		0, 0,	NULL },
369 	{ SELF_INSERT,		0, 0,	NULL },
370 
371 	{ SELF_INSERT,		0, 0,	NULL },	/* 200 */
372 	{ SELF_INSERT,		0, 0,	NULL },
373 	{ SELF_INSERT,		0, 0,	NULL },
374 	{ SELF_INSERT,		0, 0,	NULL },
375 	{ SELF_INSERT,		0, 0,	NULL },
376 	{ SELF_INSERT,		0, 0,	NULL },
377 	{ SELF_INSERT,		0, 0,	NULL },
378 	{ SELF_INSERT,		0, 0,	NULL },
379 
380 	{ SELF_INSERT,		0, 0,	NULL },	/* 208 */
381 	{ SELF_INSERT,		0, 0,	NULL },
382 	{ SELF_INSERT,		0, 0,	NULL },
383 	{ SELF_INSERT,		0, 0,	NULL },
384 	{ SELF_INSERT,		0, 0,	NULL },
385 	{ SELF_INSERT,		0, 0,	NULL },
386 	{ SELF_INSERT,		0, 0,	NULL },
387 	{ SELF_INSERT,		0, 0,	NULL },
388 
389 	{ SELF_INSERT,		0, 0,	NULL },	/* 216 */
390 	{ SELF_INSERT,		0, 0,	NULL },
391 	{ SELF_INSERT,		0, 0,	NULL },
392 	{ SELF_INSERT,		0, 0,	NULL },
393 	{ SELF_INSERT,		0, 0,	NULL },
394 	{ SELF_INSERT,		0, 0,	NULL },
395 	{ SELF_INSERT,		0, 0,	NULL },
396 	{ SELF_INSERT,		0, 0,	NULL },
397 
398 	{ SELF_INSERT,		0, 0,	NULL },	/* 224 */
399 	{ SELF_INSERT,		0, 0,	NULL },
400 	{ EMACS_BACKWARD_WORD,	0, 0,	NULL },
401 	{ SELF_INSERT,		0, 0,	NULL },
402 	{ EMACS_DELETE_NEXT_WORD, 0, 0,	NULL },
403 	{ SELF_INSERT,		0, 0,	NULL },
404 	{ EMACS_SCROLL_END,	0, 0,	NULL },
405 	{ SELF_INSERT,		0, 0,	NULL }, /* EMACS_FORWARD_WORD */
406 
407 	{ EMACS_DELETE_PREVIOUS_WORD, 0, 0,	NULL },	/* 232 */
408 	{ SELF_INSERT,		0, 0,	NULL },
409 	{ SELF_INSERT,		0, 0,	NULL },
410 	{ SELF_INSERT,		0, 0,	NULL },
411 	{ SELF_INSERT,		0, 0,	NULL },
412 	{ SELF_INSERT,		0, 0,	NULL },
413 	{ SELF_INSERT,		0, 0,	NULL },
414 	{ SELF_INSERT,		0, 0,	NULL },
415 
416 	{ SELF_INSERT,		0, 0,	NULL },	/* 240 */
417 	{ SELF_INSERT,		0, 0,	NULL },
418 	{ SELF_INSERT,		0, 0,	NULL },
419 	{ SELF_INSERT,		0, 0,	NULL },
420 	{ SELF_INSERT,		0, 0,	NULL },
421 	{ SELF_INSERT,		0, 0,	NULL },
422 	{ SELF_INSERT,		0, 0,	NULL },
423 	{ SELF_INSERT,		0, 0,	NULL },
424 
425 	{ SELF_INSERT,		0, 0,	NULL },	/* 248 */
426 	{ SELF_INSERT,		0, 0,	NULL },
427 	{ SELF_INSERT,		0, 0,	NULL },
428 	{ SELF_INSERT,		0, 0,	NULL },
429 	{ SELF_INSERT,		0, 0,	NULL },
430 	{ SELF_INSERT,		0, 0,	NULL },
431 	{ SELF_INSERT,		0, 0,	NULL },
432 	{ EMACS_DELETE_PREVIOUS_WORD, 0, 0,	NULL },
433 };
434 
435 static KeyMap	meta1_keys[] =
436 {
437 	{ NOTHING,		0, 0,	NULL },	/* 0 */
438 	{ NOTHING,		0, 0,	NULL },
439 	{ NOTHING,		0, 0,	NULL },
440 	{ NOTHING,		0, 0,	NULL },
441 	{ NOTHING,		0, 0,	NULL },
442 	{ NOTHING,		0, 0,	NULL },
443 	{ NOTHING,		0, 0,	NULL },
444 	{ NOTHING,		0, 0,	NULL },
445 
446 	{ NOTHING,		0, 0,	NULL },	/* 8 */
447 	{ NOTHING,		0, 0,	NULL },
448 	{ NOTHING,		0, 0,	NULL },
449 	{ NOTHING,		0, 0,	NULL },
450 	{ NOTHING,		0, 0,	NULL },
451 	{ NOTHING,		0, 0,	NULL },
452 	{ NOTHING,		0, 0,	NULL },
453 	{ NOTHING,		0, 0,	NULL },
454 
455 	{ NOTHING,		0, 0,	NULL },	/* 16 */
456 	{ NOTHING,		0, 0,	NULL },
457 	{ NOTHING,		0, 0,	NULL },
458 	{ NOTHING,		0, 0,	NULL },
459 	{ NOTHING,		0, 0,	NULL },
460 	{ NOTHING,		0, 0,	NULL },
461 	{ NOTHING,		0, 0,	NULL },
462 	{ NOTHING,		0, 0,	NULL },
463 
464 	{ NOTHING,		0, 0,	NULL },	/* 24 */
465 	{ NOTHING,		0, 0,	NULL },
466 	{ NOTHING,		0, 0,	NULL },
467 	{ COMMAND_COMPLETION,	0, 0,	NULL },
468 	{ NOTHING,		0, 0,	NULL },
469 	{ NOTHING,		0, 0,	NULL },
470 	{ NOTHING,		0, 0,	NULL },
471 	{ NOTHING,		0, 0,	NULL },
472 
473 	{ NOTHING,		0, 0,	NULL },	/* 32 */
474 	{ NOTHING,		0, 0,	NULL },
475 	{ NOTHING,		0, 0,	NULL },
476 	{ NOTHING,		0, 0,	NULL },
477 	{ NOTHING,		0, 0,	NULL },
478 	{ NOTHING,		0, 0,	NULL },
479 	{ NOTHING,		0, 0,	NULL },
480 	{ NOTHING,		0, 0,	NULL },
481 
482 	{ NOTHING,		0, 0,	NULL },	/* 40 */
483 	{ NOTHING,		0, 0,	NULL },
484 	{ NOTHING,		0, 0,	NULL },
485 	{ NOTHING,		0, 0,	NULL },
486 	{ NOTHING,		0, 0,	NULL },
487 	{ NOTHING,		0, 0,	NULL },
488 	{ CLEAR_SCREEN,		0, 0,	NULL },
489 	{ NOTHING,		0, 0,	NULL },
490 
491 	{ NOTHING,		0, 0,	NULL },	/* 48 */
492 	{ NOTHING,		0, 0,	NULL },
493 	{ NOTHING,		0, 0,	NULL },
494 	{ NOTHING,		0, 0,	NULL },
495 	{ NOTHING,		0, 0,	NULL },
496 	{ NOTHING,		0, 0,	NULL },
497 	{ NOTHING,		0, 0,	NULL },
498 	{ NOTHING,		0, 0,	NULL },
499 
500 	{ NOTHING,		0, 0,	NULL },	/* 56 */
501 	{ NOTHING,		0, 0,	NULL },
502 	{ NOTHING,		0, 0,	NULL },
503 	{ NOTHING,		0, 0,	NULL },
504 	{ SCROLL_START,		0, 0,	NULL },
505 	{ NOTHING,		0, 0,	NULL },
506 	{ SCROLL_END,		0, 0,	NULL },
507 	{ NOTHING,		0, 0,	NULL },
508 
509 	{ NOTHING,		0, 0,	NULL },	/* 64 */
510 	{ NOTHING,		0, 0,	NULL },
511 	{ NOTHING,		0, 0,	NULL },
512 	{ NOTHING,		0, 0,	NULL },
513 	{ NOTHING,		0, 0,	NULL },
514 	{ NOTHING,		0, 0,	NULL },
515 	{ NOTHING,		0, 0,	NULL },
516 	{ NOTHING,		0, 0,	NULL },
517 
518 	{ NOTHING,		0, 0,	NULL },	/* 72 */
519 	{ NOTHING,		0, 0,	NULL },
520 	{ NOTHING,		0, 0,	NULL },
521 	{ NOTHING,		0, 0,	NULL },
522 	{ NOTHING,		0, 0,	NULL },
523 	{ NOTHING,		0, 0,	NULL },
524 	{ NOTHING,		0, 0,	NULL },
525 	{ NOTHING,		0, 0,	NULL },
526 
527 	{ NOTHING,		0, 0,	NULL },	/* 80 */
528 	{ NOTHING,		0, 0,	NULL },
529 	{ NOTHING,		0, 0,	NULL },
530 	{ NOTHING,		0, 0,	NULL },
531 	{ NOTHING,		0, 0,	NULL },
532 	{ NOTHING,		0, 0,	NULL },
533 	{ NOTHING,		0, 0,	NULL },
534 	{ NOTHING,		0, 0,	NULL },
535 
536 	{ NOTHING,		0, 0,	NULL },	/* 88 */
537 	{ NOTHING,		0, 0,	NULL },
538 	{ NOTHING,		0, 0,	NULL },
539 	{ META3_CHARACTER,	0, 0,	NULL },
540 	{ NOTHING,		0, 0,	NULL },
541 	{ NOTHING,		0, 0,	NULL },
542 	{ NOTHING,		0, 0,	NULL },
543 	{ NOTHING,		0, 0,	NULL },
544 
545 	{ NOTHING,		0, 0,	NULL },	/* 96 */
546 	{ NOTHING,		0, 0,	NULL },
547 	{ BACKWARD_WORD,	0, 0,	NULL },
548 	{ NOTHING,		0, 0,	NULL },
549 	{ DELETE_NEXT_WORD,	0, 0,	NULL },
550 	{ SCROLL_END,		0, 0,	NULL },
551 	{ FORWARD_WORD,		0, 0,	NULL },
552 	{ NOTHING,		0, 0,	NULL },
553 
554 	{ DELETE_PREVIOUS_WORD,	0, 0,	NULL },	/* 104 */
555 	{ NOTHING,		0, 0,	NULL },
556 	{ NOTHING,		0, 0,	NULL },
557 	{ NOTHING,		0, 0,	NULL },
558 	{ NOTHING,		0, 0,	NULL },
559 	{ NOTHING,		0, 0,	NULL },
560 	{ SCROLL_FORWARD,	0, 0,	NULL },
561 	{ NOTHING,		0, 0,	NULL },
562 
563 	{ SCROLL_BACKWARD,	0, 0,	NULL },	/* 112 */
564 	{ NOTHING,		0, 0,	NULL },
565 	{ NOTHING,		0, 0,	NULL },
566 	{ NOTHING,		0, 0,	NULL },
567 	{ NOTHING,		0, 0,	NULL },
568 	{ NOTHING,		0, 0,	NULL },
569 	{ NOTHING,		0, 0,	NULL },
570 	{ NOTHING,		0, 0,	NULL },
571 
572 	{ NOTHING,		0, 0,	NULL },	/* 120 */
573 	{ NOTHING,		0, 0,	NULL },
574 	{ NOTHING,		0, 0,	NULL },
575 	{ NOTHING,		0, 0,	NULL },
576 	{ NOTHING,		0, 0,	NULL },
577 	{ NOTHING,		0, 0,	NULL },
578 	{ NOTHING,		0, 0,	NULL },
579 	{ DELETE_PREVIOUS_WORD,	0, 0,	NULL },
580 
581 	{ NOTHING,		0, 0,	NULL },	/* 128 */
582 	{ NOTHING,		0, 0,	NULL },
583 	{ NOTHING,		0, 0,	NULL },
584 	{ NOTHING,		0, 0,	NULL },
585 	{ NOTHING,		0, 0,	NULL },
586 	{ NOTHING,		0, 0,	NULL },
587 	{ NOTHING,		0, 0,	NULL },
588 	{ NOTHING,		0, 0,	NULL },
589 
590 	{ NOTHING,		0, 0,	NULL },	/* 136 */
591 	{ NOTHING,		0, 0,	NULL },
592 	{ NOTHING,		0, 0,	NULL },
593 	{ NOTHING,		0, 0,	NULL },
594 	{ NOTHING,		0, 0,	NULL },
595 	{ NOTHING,		0, 0,	NULL },
596 	{ NOTHING,		0, 0,	NULL },
597 	{ NOTHING,		0, 0,	NULL },
598 
599 	{ NOTHING,		0, 0,	NULL },	/* 144 */
600 	{ NOTHING,		0, 0,	NULL },
601 	{ NOTHING,		0, 0,	NULL },
602 	{ NOTHING,		0, 0,	NULL },
603 	{ NOTHING,		0, 0,	NULL },
604 	{ NOTHING,		0, 0,	NULL },
605 	{ NOTHING,		0, 0,	NULL },
606 	{ NOTHING,		0, 0,	NULL },
607 
608 	{ NOTHING,		0, 0,	NULL },	/* 152 */
609 	{ NOTHING,		0, 0,	NULL },
610 	{ NOTHING,		0, 0,	NULL },
611 	{ NOTHING,		0, 0,	NULL },
612 	{ NOTHING,		0, 0,	NULL },
613 	{ NOTHING,		0, 0,	NULL },
614 	{ NOTHING,		0, 0,	NULL },
615 	{ NOTHING,		0, 0,	NULL },
616 
617 	{ NOTHING,		0, 0,	NULL },	/* 160 */
618 	{ NOTHING,		0, 0,	NULL },
619 	{ NOTHING,		0, 0,	NULL },
620 	{ NOTHING,		0, 0,	NULL },
621 	{ NOTHING,		0, 0,	NULL },
622 	{ NOTHING,		0, 0,	NULL },
623 	{ NOTHING,		0, 0,	NULL },
624 	{ NOTHING,		0, 0,	NULL },
625 
626 	{ NOTHING,		0, 0,	NULL },	/* 168 */
627 	{ NOTHING,		0, 0,	NULL },
628 	{ NOTHING,		0, 0,	NULL },
629 	{ NOTHING,		0, 0,	NULL },
630 	{ NOTHING,		0, 0,	NULL },
631 	{ NOTHING,		0, 0,	NULL },
632 	{ NOTHING,		0, 0,	NULL },
633 	{ NOTHING,		0, 0,	NULL },
634 
635 	{ NOTHING,		0, 0,	NULL },	/* 176 */
636 	{ NOTHING,		0, 0,	NULL },
637 	{ NOTHING,		0, 0,	NULL },
638 	{ NOTHING,		0, 0,	NULL },
639 	{ NOTHING,		0, 0,	NULL },
640 	{ NOTHING,		0, 0,	NULL },
641 	{ NOTHING,		0, 0,	NULL },
642 	{ NOTHING,		0, 0,	NULL },
643 
644 	{ NOTHING,		0, 0,	NULL },	/* 184 */
645 	{ NOTHING,		0, 0,	NULL },
646 	{ NOTHING,		0, 0,	NULL },
647 	{ NOTHING,		0, 0,	NULL },
648 	{ NOTHING,		0, 0,	NULL },
649 	{ NOTHING,		0, 0,	NULL },
650 	{ NOTHING,		0, 0,	NULL },
651 	{ NOTHING,		0, 0,	NULL },
652 
653 	{ NOTHING,		0, 0,	NULL },	/* 192 */
654 	{ NOTHING,		0, 0,	NULL },
655 	{ NOTHING,		0, 0,	NULL },
656 	{ NOTHING,		0, 0,	NULL },
657 	{ NOTHING,		0, 0,	NULL },
658 	{ NOTHING,		0, 0,	NULL },
659 	{ NOTHING,		0, 0,	NULL },
660 	{ NOTHING,		0, 0,	NULL },
661 
662 	{ NOTHING,		0, 0,	NULL },	/* 200 */
663 	{ NOTHING,		0, 0,	NULL },
664 	{ NOTHING,		0, 0,	NULL },
665 	{ NOTHING,		0, 0,	NULL },
666 	{ NOTHING,		0, 0,	NULL },
667 	{ NOTHING,		0, 0,	NULL },
668 	{ NOTHING,		0, 0,	NULL },
669 	{ NOTHING,		0, 0,	NULL },
670 
671 	{ NOTHING,		0, 0,	NULL },	/* 208 */
672 	{ NOTHING,		0, 0,	NULL },
673 	{ NOTHING,		0, 0,	NULL },
674 	{ NOTHING,		0, 0,	NULL },
675 	{ NOTHING,		0, 0,	NULL },
676 	{ NOTHING,		0, 0,	NULL },
677 	{ NOTHING,		0, 0,	NULL },
678 	{ NOTHING,		0, 0,	NULL },
679 
680 	{ NOTHING,		0, 0,	NULL },	/* 216 */
681 	{ NOTHING,		0, 0,	NULL },
682 	{ NOTHING,		0, 0,	NULL },
683 	{ NOTHING,		0, 0,	NULL },
684 	{ NOTHING,		0, 0,	NULL },
685 	{ NOTHING,		0, 0,	NULL },
686 	{ NOTHING,		0, 0,	NULL },
687 	{ NOTHING,		0, 0,	NULL },
688 
689 	{ NOTHING,		0, 0,	NULL },	/* 224 */
690 	{ NOTHING,		0, 0,	NULL },
691 	{ NOTHING,		0, 0,	NULL },
692 	{ NOTHING,		0, 0,	NULL },
693 	{ NOTHING,		0, 0,	NULL },
694 	{ NOTHING,		0, 0,	NULL },
695 	{ NOTHING,		0, 0,	NULL },
696 	{ NOTHING,		0, 0,	NULL },
697 
698 	{ NOTHING,		0, 0,	NULL },	/* 232 */
699 	{ NOTHING,		0, 0,	NULL },
700 	{ NOTHING,		0, 0,	NULL },
701 	{ NOTHING,		0, 0,	NULL },
702 	{ NOTHING,		0, 0,	NULL },
703 	{ NOTHING,		0, 0,	NULL },
704 	{ NOTHING,		0, 0,	NULL },
705 	{ NOTHING,		0, 0,	NULL },
706 
707 	{ NOTHING,		0, 0,	NULL },	/* 240 */
708 	{ NOTHING,		0, 0,	NULL },
709 	{ NOTHING,		0, 0,	NULL },
710 	{ NOTHING,		0, 0,	NULL },
711 	{ NOTHING,		0, 0,	NULL },
712 	{ NOTHING,		0, 0,	NULL },
713 	{ NOTHING,		0, 0,	NULL },
714 	{ NOTHING,		0, 0,	NULL },
715 
716 	{ NOTHING,		0, 0,	NULL },	/* 248 */
717 	{ NOTHING,		0, 0,	NULL },
718 	{ NOTHING,		0, 0,	NULL },
719 	{ NOTHING,		0, 0,	NULL },
720 	{ NOTHING,		0, 0,	NULL },
721 	{ NOTHING,		0, 0,	NULL },
722 	{ NOTHING,		0, 0,	NULL },
723 	{ NOTHING,		0, 0,	NULL }
724 };
725 
726 static KeyMap	meta2_keys[] =
727 {
728 	{ NOTHING,		0, 0,	NULL },	/* 0 */
729 	{ NOTHING,		0, 0,	NULL },
730 	{ NOTHING,		0, 0,	NULL },
731 	{ NOTHING,		0, 0,	NULL },
732 	{ NOTHING,		0, 0,	NULL },
733 	{ NOTHING,		0, 0,	NULL },
734 	{ NOTHING,		0, 0,	NULL },
735 	{ NOTHING,		0, 0,	NULL },
736 
737 	{ NOTHING,		0, 0,	NULL },	/* 8 */
738 	{ NOTHING,		0, 0,	NULL },
739 	{ NOTHING,		0, 0,	NULL },
740 	{ NOTHING,		0, 0,	NULL },
741 	{ NOTHING,		0, 0,	NULL },
742 	{ NOTHING,		0, 0,	NULL },
743 	{ NOTHING,		0, 0,	NULL },
744 	{ NOTHING,		0, 0,	NULL },
745 
746 	{ NOTHING,		0, 0,	NULL },	/* 16 */
747 	{ NOTHING,		0, 0,	NULL },
748 	{ NOTHING,		0, 0,	NULL },
749 	{ NOTHING,		0, 0,	NULL },
750 	{ NOTHING,		0, 0,	NULL },
751 	{ NOTHING,		0, 0,	NULL },
752 	{ NOTHING,		0, 0,	NULL },
753 	{ NOTHING,		0, 0,	NULL },
754 
755 	{ NOTHING,		0, 0,	NULL },	/* 24 */
756 	{ NOTHING,		0, 0,	NULL },
757 #ifdef ALLOW_STOP_IRC
758 	{ STOP_IRC,		0, 0,	NULL },
759 #else
760 	{ NOTHING,		0, 0,	NULL },
761 #endif /* ALLOW_STOP_IRC */
762 	{ NOTHING,		0, 0,	NULL },
763 	{ NOTHING,		0, 0,	NULL },
764 	{ NOTHING,		0, 0,	NULL },
765 	{ NOTHING,		0, 0,	NULL },
766 	{ NOTHING,		0, 0,	NULL },
767 
768 	{ NOTHING,		0, 0,	NULL },	/* 32 */
769 	{ NOTHING,		0, 0,	NULL },
770 	{ NOTHING,		0, 0,	NULL },
771 	{ NOTHING,		0, 0,	NULL },
772 	{ NOTHING,		0, 0,	NULL },
773 	{ NOTHING,		0, 0,	NULL },
774 	{ NOTHING,		0, 0,	NULL },
775 	{ NOTHING,		0, 0,	NULL },
776 
777 	{ NOTHING,		0, 0,	NULL },	/* 40 */
778 	{ NOTHING,		0, 0,	NULL },
779 	{ NOTHING,		0, 0,	NULL },
780 	{ NOTHING,		0, 0,	NULL },
781 	{ NOTHING,		0, 0,	NULL },
782 	{ NOTHING,		0, 0,	NULL },
783 	{ NOTHING,		0, 0,	NULL },
784 	{ NOTHING,		0, 0,	NULL },
785 
786 	{ NOTHING,		0, 0,	NULL },	/* 48 */
787 	{ NOTHING,		0, 0,	NULL },
788 	{ NOTHING,		0, 0,	NULL },
789 	{ NOTHING,		0, 0,	NULL },
790 	{ NOTHING,		0, 0,	NULL },
791 	{ NOTHING,		0, 0,	NULL },
792 	{ NOTHING,		0, 0,	NULL },
793 	{ NOTHING,		0, 0,	NULL },
794 
795 	{ NOTHING,		0, 0,	NULL },	/* 56 */
796 	{ NOTHING,		0, 0,	NULL },
797 	{ NOTHING,		0, 0,	NULL },
798 	{ NOTHING,		0, 0,	NULL },
799 	{ NOTHING,		0, 0,	NULL },
800 	{ NOTHING,		0, 0,	NULL },
801 	{ NOTHING,		0, 0,	NULL },
802 	{ NOTHING,		0, 0,	NULL },
803 
804 	{ NOTHING,		0, 0,	NULL },	/* 64 */
805 	{ NOTHING,		0, 0,	NULL },
806 	{ NOTHING,		0, 0,	NULL },
807 	{ NOTHING,		0, 0,	NULL },
808 	{ NOTHING,		0, 0,	NULL },
809 	{ NOTHING,		0, 0,	NULL },
810 	{ NOTHING,		0, 0,	NULL },
811 	{ NOTHING,		0, 0,	NULL },
812 
813 	{ NOTHING,		0, 0,	NULL },	/* 72 */
814 	{ NOTHING,		0, 0,	NULL },
815 	{ NOTHING,		0, 0,	NULL },
816 	{ NOTHING,		0, 0,	NULL },
817 	{ NOTHING,		0, 0,	NULL },
818 	{ NOTHING,		0, 0,	NULL },
819 	{ NOTHING,		0, 0,	NULL },
820 	{ NOTHING,		0, 0,	NULL },
821 
822 	{ NOTHING,		0, 0,	NULL },	/* 80 */
823 	{ NOTHING,		0, 0,	NULL },
824 	{ NOTHING,		0, 0,	NULL },
825 	{ NOTHING,		0, 0,	NULL },
826 	{ NOTHING,		0, 0,	NULL },
827 	{ NOTHING,		0, 0,	NULL },
828 	{ NOTHING,		0, 0,	NULL },
829 	{ NOTHING,		0, 0,	NULL },
830 
831 	{ NOTHING,		0, 0,	NULL },	/* 88 */
832 	{ NOTHING,		0, 0,	NULL },
833 	{ NOTHING,		0, 0,	NULL },
834 	{ NOTHING,		0, 0,	NULL },
835 	{ NOTHING,		0, 0,	NULL },
836 	{ NOTHING,		0, 0,	NULL },
837 	{ NOTHING,		0, 0,	NULL },
838 	{ NOTHING,		0, 0,	NULL },
839 
840 	{ NOTHING,		0, 0,	NULL },	/* 96 */
841 	{ NOTHING,		0, 0,	NULL },
842 	{ NOTHING,		0, 0,	NULL },
843 	{ NOTHING,		0, 0,	NULL },
844 	{ NOTHING,		0, 0,	NULL },
845 	{ NOTHING,		0, 0,	NULL },
846 	{ NOTHING,		0, 0,	NULL },
847 	{ NOTHING,		0, 0,	NULL },
848 
849 	{ NOTHING,		0, 0,	NULL },	/* 104 */
850 	{ NOTHING,		0, 0,	NULL },
851 	{ NOTHING,		0, 0,	NULL },
852 	{ NOTHING,		0, 0,	NULL },
853 	{ NOTHING,		0, 0,	NULL },
854 	{ NOTHING,		0, 0,	NULL },
855 	{ NEXT_WINDOW,		0, 0,	NULL },
856 	{ NOTHING,		0, 0,	NULL },
857 
858 	{ PREVIOUS_WINDOW,	0, 0,	NULL },	/* 112 */
859 	{ NOTHING,		0, 0,	NULL },
860 	{ NOTHING,		0, 0,	NULL },
861 	{ NOTHING,		0, 0,	NULL },
862 	{ NOTHING,		0, 0,	NULL },
863 	{ NOTHING,		0, 0,	NULL },
864 	{ NOTHING,		0, 0,	NULL },
865 	{ NOTHING,		0, 0,	NULL },
866 
867 	{ NOTHING,		0, 0,	NULL },	/* 120 */
868 	{ NOTHING,		0, 0,	NULL },
869 	{ NOTHING,		0, 0,	NULL },
870 	{ NOTHING,		0, 0,	NULL },
871 	{ NOTHING,		0, 0,	NULL },
872 	{ NOTHING,		0, 0,	NULL },
873 	{ NOTHING,		0, 0,	NULL },
874 	{ NOTHING,		0, 0,	NULL },
875 
876 	{ NOTHING,		0, 0,	NULL },	/* 128 */
877 	{ NOTHING,		0, 0,	NULL },
878 	{ NOTHING,		0, 0,	NULL },
879 	{ NOTHING,		0, 0,	NULL },
880 	{ NOTHING,		0, 0,	NULL },
881 	{ NOTHING,		0, 0,	NULL },
882 	{ NOTHING,		0, 0,	NULL },
883 	{ NOTHING,		0, 0,	NULL },
884 
885 	{ NOTHING,		0, 0,	NULL },	/* 136 */
886 	{ NOTHING,		0, 0,	NULL },
887 	{ NOTHING,		0, 0,	NULL },
888 	{ NOTHING,		0, 0,	NULL },
889 	{ NOTHING,		0, 0,	NULL },
890 	{ NOTHING,		0, 0,	NULL },
891 	{ NOTHING,		0, 0,	NULL },
892 	{ NOTHING,		0, 0,	NULL },
893 
894 	{ NOTHING,		0, 0,	NULL },	/* 144 */
895 	{ NOTHING,		0, 0,	NULL },
896 	{ NOTHING,		0, 0,	NULL },
897 	{ NOTHING,		0, 0,	NULL },
898 	{ NOTHING,		0, 0,	NULL },
899 	{ NOTHING,		0, 0,	NULL },
900 	{ NOTHING,		0, 0,	NULL },
901 	{ NOTHING,		0, 0,	NULL },
902 
903 	{ NOTHING,		0, 0,	NULL },	/* 152 */
904 	{ NOTHING,		0, 0,	NULL },
905 	{ NOTHING,		0, 0,	NULL },
906 	{ NOTHING,		0, 0,	NULL },
907 	{ NOTHING,		0, 0,	NULL },
908 	{ NOTHING,		0, 0,	NULL },
909 	{ NOTHING,		0, 0,	NULL },
910 	{ NOTHING,		0, 0,	NULL },
911 
912 	{ NOTHING,		0, 0,	NULL },	/* 160 */
913 	{ NOTHING,		0, 0,	NULL },
914 	{ NOTHING,		0, 0,	NULL },
915 	{ NOTHING,		0, 0,	NULL },
916 	{ NOTHING,		0, 0,	NULL },
917 	{ NOTHING,		0, 0,	NULL },
918 	{ NOTHING,		0, 0,	NULL },
919 	{ NOTHING,		0, 0,	NULL },
920 
921 	{ NOTHING,		0, 0,	NULL },	/* 168 */
922 	{ NOTHING,		0, 0,	NULL },
923 	{ NOTHING,		0, 0,	NULL },
924 	{ NOTHING,		0, 0,	NULL },
925 	{ NOTHING,		0, 0,	NULL },
926 	{ NOTHING,		0, 0,	NULL },
927 	{ NOTHING,		0, 0,	NULL },
928 	{ NOTHING,		0, 0,	NULL },
929 
930 	{ NOTHING,		0, 0,	NULL },	/* 176 */
931 	{ NOTHING,		0, 0,	NULL },
932 	{ NOTHING,		0, 0,	NULL },
933 	{ NOTHING,		0, 0,	NULL },
934 	{ NOTHING,		0, 0,	NULL },
935 	{ NOTHING,		0, 0,	NULL },
936 	{ NOTHING,		0, 0,	NULL },
937 	{ NOTHING,		0, 0,	NULL },
938 
939 	{ NOTHING,		0, 0,	NULL },	/* 184 */
940 	{ NOTHING,		0, 0,	NULL },
941 	{ NOTHING,		0, 0,	NULL },
942 	{ NOTHING,		0, 0,	NULL },
943 	{ NOTHING,		0, 0,	NULL },
944 	{ NOTHING,		0, 0,	NULL },
945 	{ NOTHING,		0, 0,	NULL },
946 	{ NOTHING,		0, 0,	NULL },
947 
948 	{ NOTHING,		0, 0,	NULL },	/* 192 */
949 	{ NOTHING,		0, 0,	NULL },
950 	{ NOTHING,		0, 0,	NULL },
951 	{ NOTHING,		0, 0,	NULL },
952 	{ NOTHING,		0, 0,	NULL },
953 	{ NOTHING,		0, 0,	NULL },
954 	{ NOTHING,		0, 0,	NULL },
955 	{ NOTHING,		0, 0,	NULL },
956 
957 	{ NOTHING,		0, 0,	NULL },	/* 200 */
958 	{ NOTHING,		0, 0,	NULL },
959 	{ NOTHING,		0, 0,	NULL },
960 	{ NOTHING,		0, 0,	NULL },
961 	{ NOTHING,		0, 0,	NULL },
962 	{ NOTHING,		0, 0,	NULL },
963 	{ NOTHING,		0, 0,	NULL },
964 	{ NOTHING,		0, 0,	NULL },
965 
966 	{ NOTHING,		0, 0,	NULL },	/* 208 */
967 	{ NOTHING,		0, 0,	NULL },
968 	{ NOTHING,		0, 0,	NULL },
969 	{ NOTHING,		0, 0,	NULL },
970 	{ NOTHING,		0, 0,	NULL },
971 	{ NOTHING,		0, 0,	NULL },
972 	{ NOTHING,		0, 0,	NULL },
973 	{ NOTHING,		0, 0,	NULL },
974 
975 	{ NOTHING,		0, 0,	NULL },	/* 216 */
976 	{ NOTHING,		0, 0,	NULL },
977 	{ NOTHING,		0, 0,	NULL },
978 	{ NOTHING,		0, 0,	NULL },
979 	{ NOTHING,		0, 0,	NULL },
980 	{ NOTHING,		0, 0,	NULL },
981 	{ NOTHING,		0, 0,	NULL },
982 	{ NOTHING,		0, 0,	NULL },
983 
984 	{ NOTHING,		0, 0,	NULL },	/* 224 */
985 	{ NOTHING,		0, 0,	NULL },
986 	{ NOTHING,		0, 0,	NULL },
987 	{ NOTHING,		0, 0,	NULL },
988 	{ NOTHING,		0, 0,	NULL },
989 	{ NOTHING,		0, 0,	NULL },
990 	{ NOTHING,		0, 0,	NULL },
991 	{ NOTHING,		0, 0,	NULL },
992 
993 	{ NOTHING,		0, 0,	NULL },	/* 232 */
994 	{ NOTHING,		0, 0,	NULL },
995 	{ NOTHING,		0, 0,	NULL },
996 	{ NOTHING,		0, 0,	NULL },
997 	{ NOTHING,		0, 0,	NULL },
998 	{ NOTHING,		0, 0,	NULL },
999 	{ NOTHING,		0, 0,	NULL },
1000 	{ NOTHING,		0, 0,	NULL },
1001 
1002 	{ NOTHING,		0, 0,	NULL },	/* 240 */
1003 	{ NOTHING,		0, 0,	NULL },
1004 	{ NOTHING,		0, 0,	NULL },
1005 	{ NOTHING,		0, 0,	NULL },
1006 	{ NOTHING,		0, 0,	NULL },
1007 	{ NOTHING,		0, 0,	NULL },
1008 	{ NOTHING,		0, 0,	NULL },
1009 	{ NOTHING,		0, 0,	NULL },
1010 
1011 	{ NOTHING,		0, 0,	NULL },	/* 248 */
1012 	{ NOTHING,		0, 0,	NULL },
1013 	{ NOTHING,		0, 0,	NULL },
1014 	{ NOTHING,		0, 0,	NULL },
1015 	{ NOTHING,		0, 0,	NULL },
1016 	{ NOTHING,		0, 0,	NULL },
1017 	{ NOTHING,		0, 0,	NULL },
1018 	{ NOTHING,		0, 0,	NULL }
1019 };
1020 
1021 static KeyMap	meta3_keys[] =
1022 #include "empty_metakeys.inc"
1023 
1024 static KeyMap	meta4_keys[] =
1025 {
1026 	{ NOTHING,		0, 0,	NULL },	/* 0 */
1027 	{ NOTHING,		0, 0,	NULL },
1028 	{ NOTHING,		0, 0,	NULL },
1029 	{ NOTHING,		0, 0,	NULL },
1030 	{ NOTHING,		0, 0,	NULL },
1031 	{ NOTHING,		0, 0,	NULL },
1032 	{ NOTHING,		0, 0,	NULL },
1033 	{ NOTHING,		0, 0,	NULL },
1034 
1035 	{ BACKWARD_CHARACTER,	0, 0,	NULL },	/* 8 */
1036 	{ NOTHING,		0, 0,	NULL },
1037 	{ NOTHING,		0, 0,	NULL },
1038 	{ NOTHING,		0, 0,	NULL },
1039 	{ NOTHING,		0, 0,	NULL },
1040 	{ NOTHING,		0, 0,	NULL },
1041 	{ NOTHING,		0, 0,	NULL },
1042 	{ NOTHING,		0, 0,	NULL },
1043 
1044 	{ NOTHING,		0, 0,	NULL },	/* 16 */
1045 	{ NOTHING,		0, 0,	NULL },
1046 	{ NOTHING,		0, 0,	NULL },
1047 	{ NOTHING,		0, 0,	NULL },
1048 	{ NOTHING,		0, 0,	NULL },
1049 	{ NOTHING,		0, 0,	NULL },
1050 	{ NOTHING,		0, 0,	NULL },
1051 	{ NOTHING,		0, 0,	NULL },
1052 
1053 	{ NOTHING,		0, 0,	NULL },	/* 24 */
1054 	{ NOTHING,		0, 0,	NULL },
1055 	{ NOTHING,		0, 0,	NULL },
1056 	{ NOTHING,		0, 0,	NULL },
1057 	{ NOTHING,		0, 0,	NULL },
1058 	{ NOTHING,		0, 0,	NULL },
1059 	{ NOTHING,		0, 0,	NULL },
1060 	{ NOTHING,		0, 0,	NULL },
1061 
1062 	{ FORWARD_CHARACTER,	0, 0,	NULL },	/* 32 */
1063 	{ NOTHING,		0, 0,	NULL },
1064 	{ NOTHING,		0, 0,	NULL },
1065 	{ NOTHING,		0, 0,	NULL },
1066 	{ NOTHING,		0, 0,	NULL },
1067 	{ NOTHING,		0, 0,	NULL },
1068 	{ NOTHING,		0, 0,	NULL },
1069 	{ NOTHING,		0, 0,	NULL },
1070 
1071 	{ NOTHING,		0, 0,	NULL },	/* 40 */
1072 	{ NOTHING,		0, 0,	NULL },
1073 	{ NOTHING,		0, 0,	NULL },
1074 	{ NOTHING,		0, 0,	NULL },
1075 	{ NOTHING,		0, 0,	NULL },
1076 	{ NOTHING,		0, 0,	NULL },
1077 	{ NOTHING,		0, 0,	NULL },
1078 	{ NOTHING,		0, 0,	NULL },
1079 
1080 	{ NOTHING,		0, 0,	NULL },	/* 48 */
1081 	{ NOTHING,		0, 0,	NULL },
1082 	{ NOTHING,		0, 0,	NULL },
1083 	{ NOTHING,		0, 0,	NULL },
1084 	{ NOTHING,		0, 0,	NULL },
1085 	{ NOTHING,		0, 0,	NULL },
1086 	{ NOTHING,		0, 0,	NULL },
1087 	{ NOTHING,		0, 0,	NULL },
1088 
1089 	{ NOTHING,		0, 0,	NULL },	/* 56 */
1090 	{ NOTHING,		0, 0,	NULL },
1091 	{ NOTHING,		0, 0,	NULL },
1092 	{ NOTHING,		0, 0,	NULL },
1093 	{ NOTHING,		0, 0,	NULL },
1094 	{ NOTHING,		0, 0,	NULL },
1095 	{ NOTHING,		0, 0,	NULL },
1096 	{ NOTHING,		0, 0,	NULL },
1097 
1098 	{ NOTHING,		0, 0,	NULL },	/* 64 */
1099 	{ META4_CHARACTER,	0, 0,	NULL },
1100 	{ NOTHING,		0, 0,	NULL },
1101 	{ NOTHING,		0, 0,	NULL },
1102 	{ NOTHING,		0, 0,	NULL },
1103 	{ NOTHING,		0, 0,	NULL },
1104 	{ NOTHING,		0, 0,	NULL },
1105 	{ NOTHING,		0, 0,	NULL },
1106 
1107 	{ BACKWARD_CHARACTER,	0, 0,	NULL },	/* 72 */
1108 	{ META4_CHARACTER,	0, 0,	NULL },
1109 	{ FORWARD_HISTORY,	0, 0,	NULL },
1110 	{ BACKWARD_HISTORY,	0, 0,	NULL },
1111 	{ FORWARD_CHARACTER,	0, 0,	NULL },
1112 	{ NOTHING,		0, 0,	NULL },
1113 	{ NOTHING,		0, 0,	NULL },
1114 	{ NOTHING,		0, 0,	NULL },
1115 
1116 	{ NOTHING,		0, 0,	NULL },	/* 80 */
1117 	{ NOTHING,		0, 0,	NULL },
1118 	{ NOTHING,		0, 0,	NULL },
1119 	{ NOTHING,		0, 0,	NULL },
1120 	{ NOTHING,		0, 0,	NULL },
1121 	{ NOTHING,		0, 0,	NULL },
1122 	{ NOTHING,		0, 0,	NULL },
1123 	{ NOTHING,		0, 0,	NULL },
1124 
1125 	{ DELETE_CHARACTER,	0, 0,	NULL },	/* 88 */
1126 	{ NOTHING,		0, 0,	NULL },
1127 	{ NOTHING,		0, 0,	NULL },
1128 	{ NOTHING,		0, 0,	NULL },
1129 	{ NOTHING,		0, 0,	NULL },
1130 	{ NOTHING,		0, 0,	NULL },
1131 	{ NOTHING,		0, 0,	NULL },
1132 	{ NOTHING,		0, 0,	NULL },
1133 
1134 	{ NOTHING,		0, 0,	NULL },	/* 96 */
1135 	{ META4_CHARACTER,	0, 0,	NULL },
1136 	{ NOTHING,		0, 0,	NULL },
1137 	{ NOTHING,		0, 0,	NULL },
1138 	{ NOTHING,		0, 0,	NULL },
1139 	{ NOTHING,		0, 0,	NULL },
1140 	{ NOTHING,		0, 0,	NULL },
1141 	{ NOTHING,		0, 0,	NULL },
1142 
1143 	{ BACKWARD_CHARACTER,	0, 0,	NULL },	/* 104 */
1144 	{ META4_CHARACTER,	0, 0,	NULL },
1145 	{ FORWARD_HISTORY,	0, 0,	NULL },
1146 	{ BACKWARD_HISTORY,	0, 0,	NULL },
1147 	{ FORWARD_CHARACTER,	0, 0,	NULL },
1148 	{ NOTHING,		0, 0,	NULL },
1149 	{ NOTHING,		0, 0,	NULL },
1150 	{ NOTHING,		0, 0,	NULL },
1151 
1152 	{ NOTHING,		0, 0,	NULL },	/* 112 */
1153 	{ NOTHING,		0, 0,	NULL },
1154 	{ NOTHING,		0, 0,	NULL },
1155 	{ NOTHING,		0, 0,	NULL },
1156 	{ NOTHING,		0, 0,	NULL },
1157 	{ NOTHING,		0, 0,	NULL },
1158 	{ NOTHING,		0, 0,	NULL },
1159 	{ NOTHING,		0, 0,	NULL },
1160 
1161 	{ DELETE_CHARACTER,	0, 0,	NULL },	/* 120 */
1162 	{ NOTHING,		0, 0,	NULL },
1163 	{ NOTHING,		0, 0,	NULL },
1164 	{ NOTHING,		0, 0,	NULL },
1165 	{ NOTHING,		0, 0,	NULL },
1166 	{ NOTHING,		0, 0,	NULL },
1167 	{ NOTHING,		0, 0,	NULL },
1168 	{ NOTHING,		0, 0,	NULL },
1169 
1170 	{ NOTHING,		0, 0,	NULL },	/* 128 */
1171 	{ NOTHING,		0, 0,	NULL },
1172 	{ NOTHING,		0, 0,	NULL },
1173 	{ NOTHING,		0, 0,	NULL },
1174 	{ NOTHING,		0, 0,	NULL },
1175 	{ NOTHING,		0, 0,	NULL },
1176 	{ NOTHING,		0, 0,	NULL },
1177 	{ NOTHING,		0, 0,	NULL },
1178 
1179 	{ NOTHING,		0, 0,	NULL },	/* 136 */
1180 	{ NOTHING,		0, 0,	NULL },
1181 	{ NOTHING,		0, 0,	NULL },
1182 	{ NOTHING,		0, 0,	NULL },
1183 	{ NOTHING,		0, 0,	NULL },
1184 	{ NOTHING,		0, 0,	NULL },
1185 	{ NOTHING,		0, 0,	NULL },
1186 	{ NOTHING,		0, 0,	NULL },
1187 
1188 	{ NOTHING,		0, 0,	NULL },	/* 144 */
1189 	{ NOTHING,		0, 0,	NULL },
1190 	{ NOTHING,		0, 0,	NULL },
1191 	{ NOTHING,		0, 0,	NULL },
1192 	{ NOTHING,		0, 0,	NULL },
1193 	{ NOTHING,		0, 0,	NULL },
1194 	{ NOTHING,		0, 0,	NULL },
1195 	{ NOTHING,		0, 0,	NULL },
1196 
1197 	{ NOTHING,		0, 0,	NULL },	/* 152 */
1198 	{ NOTHING,		0, 0,	NULL },
1199 	{ NOTHING,		0, 0,	NULL },
1200 	{ NOTHING,		0, 0,	NULL },
1201 	{ NOTHING,		0, 0,	NULL },
1202 	{ NOTHING,		0, 0,	NULL },
1203 	{ NOTHING,		0, 0,	NULL },
1204 	{ NOTHING,		0, 0,	NULL },
1205 
1206 	{ NOTHING,		0, 0,	NULL },	/* 160 */
1207 	{ NOTHING,		0, 0,	NULL },
1208 	{ NOTHING,		0, 0,	NULL },
1209 	{ NOTHING,		0, 0,	NULL },
1210 	{ NOTHING,		0, 0,	NULL },
1211 	{ NOTHING,		0, 0,	NULL },
1212 	{ NOTHING,		0, 0,	NULL },
1213 	{ NOTHING,		0, 0,	NULL },
1214 
1215 	{ NOTHING,		0, 0,	NULL },	/* 168 */
1216 	{ NOTHING,		0, 0,	NULL },
1217 	{ NOTHING,		0, 0,	NULL },
1218 	{ NOTHING,		0, 0,	NULL },
1219 	{ NOTHING,		0, 0,	NULL },
1220 	{ NOTHING,		0, 0,	NULL },
1221 	{ NOTHING,		0, 0,	NULL },
1222 	{ NOTHING,		0, 0,	NULL },
1223 
1224 	{ NOTHING,		0, 0,	NULL },	/* 176 */
1225 	{ NOTHING,		0, 0,	NULL },
1226 	{ NOTHING,		0, 0,	NULL },
1227 	{ NOTHING,		0, 0,	NULL },
1228 	{ NOTHING,		0, 0,	NULL },
1229 	{ NOTHING,		0, 0,	NULL },
1230 	{ NOTHING,		0, 0,	NULL },
1231 	{ NOTHING,		0, 0,	NULL },
1232 
1233 	{ NOTHING,		0, 0,	NULL },	/* 184 */
1234 	{ NOTHING,		0, 0,	NULL },
1235 	{ NOTHING,		0, 0,	NULL },
1236 	{ NOTHING,		0, 0,	NULL },
1237 	{ NOTHING,		0, 0,	NULL },
1238 	{ NOTHING,		0, 0,	NULL },
1239 	{ NOTHING,		0, 0,	NULL },
1240 	{ NOTHING,		0, 0,	NULL },
1241 
1242 	{ NOTHING,		0, 0,	NULL },	/* 192 */
1243 	{ NOTHING,		0, 0,	NULL },
1244 	{ NOTHING,		0, 0,	NULL },
1245 	{ NOTHING,		0, 0,	NULL },
1246 	{ NOTHING,		0, 0,	NULL },
1247 	{ NOTHING,		0, 0,	NULL },
1248 	{ NOTHING,		0, 0,	NULL },
1249 	{ NOTHING,		0, 0,	NULL },
1250 
1251 	{ NOTHING,		0, 0,	NULL },	/* 200 */
1252 	{ NOTHING,		0, 0,	NULL },
1253 	{ NOTHING,		0, 0,	NULL },
1254 	{ NOTHING,		0, 0,	NULL },
1255 	{ NOTHING,		0, 0,	NULL },
1256 	{ NOTHING,		0, 0,	NULL },
1257 	{ NOTHING,		0, 0,	NULL },
1258 	{ NOTHING,		0, 0,	NULL },
1259 
1260 	{ NOTHING,		0, 0,	NULL },	/* 208 */
1261 	{ NOTHING,		0, 0,	NULL },
1262 	{ NOTHING,		0, 0,	NULL },
1263 	{ NOTHING,		0, 0,	NULL },
1264 	{ NOTHING,		0, 0,	NULL },
1265 	{ NOTHING,		0, 0,	NULL },
1266 	{ NOTHING,		0, 0,	NULL },
1267 	{ NOTHING,		0, 0,	NULL },
1268 
1269 	{ NOTHING,		0, 0,	NULL },	/* 216 */
1270 	{ NOTHING,		0, 0,	NULL },
1271 	{ NOTHING,		0, 0,	NULL },
1272 	{ NOTHING,		0, 0,	NULL },
1273 	{ NOTHING,		0, 0,	NULL },
1274 	{ NOTHING,		0, 0,	NULL },
1275 	{ NOTHING,		0, 0,	NULL },
1276 	{ NOTHING,		0, 0,	NULL },
1277 
1278 	{ NOTHING,		0, 0,	NULL },	/* 224 */
1279 	{ NOTHING,		0, 0,	NULL },
1280 	{ NOTHING,		0, 0,	NULL },
1281 	{ NOTHING,		0, 0,	NULL },
1282 	{ NOTHING,		0, 0,	NULL },
1283 	{ NOTHING,		0, 0,	NULL },
1284 	{ NOTHING,		0, 0,	NULL },
1285 	{ NOTHING,		0, 0,	NULL },
1286 
1287 	{ NOTHING,		0, 0,	NULL },	/* 232 */
1288 	{ NOTHING,		0, 0,	NULL },
1289 	{ NOTHING,		0, 0,	NULL },
1290 	{ NOTHING,		0, 0,	NULL },
1291 	{ NOTHING,		0, 0,	NULL },
1292 	{ NOTHING,		0, 0,	NULL },
1293 	{ NOTHING,		0, 0,	NULL },
1294 	{ NOTHING,		0, 0,	NULL },
1295 
1296 	{ NOTHING,		0, 0,	NULL },	/* 240 */
1297 	{ NOTHING,		0, 0,	NULL },
1298 	{ NOTHING,		0, 0,	NULL },
1299 	{ NOTHING,		0, 0,	NULL },
1300 	{ NOTHING,		0, 0,	NULL },
1301 	{ NOTHING,		0, 0,	NULL },
1302 	{ NOTHING,		0, 0,	NULL },
1303 	{ NOTHING,		0, 0,	NULL },
1304 
1305 	{ NOTHING,		0, 0,	NULL },	/* 248 */
1306 	{ NOTHING,		0, 0,	NULL },
1307 	{ NOTHING,		0, 0,	NULL },
1308 	{ NOTHING,		0, 0,	NULL },
1309 	{ NOTHING,		0, 0,	NULL },
1310 	{ NOTHING,		0, 0,	NULL },
1311 	{ NOTHING,		0, 0,	NULL },
1312 	{ NOTHING,		0, 0,	NULL }
1313 };
1314 
1315 static KeyMap	meta5_keys[] =
1316 #include "empty_metakeys.inc"
1317 
1318 static KeyMap	meta6_keys[] =
1319 #include "empty_metakeys.inc"
1320 
1321 static KeyMap	meta7_keys[] =
1322 #include "empty_metakeys.inc"
1323 
1324 static KeyMap	meta8_keys[] =
1325 #include "empty_metakeys.inc"
1326 
1327 /*
1328  * lookup_function: looks up an irc function by name, and returns the
1329  * number of functions that match the name, and sets where index points
1330  * to to be the index of the (first) function found.
1331  */
1332 static int
lookup_function(u_char * name,int * func_index)1333 lookup_function(u_char *name, int *func_index)
1334 {
1335 	size_t	len;
1336 	int	cnt,
1337 		i;
1338 
1339 	if (name)
1340 	{
1341 		upper(name);
1342 		len = my_strlen(name);
1343 		cnt = 0;
1344 		*func_index = -1;
1345 		for (i = 0; i < NUMBER_OF_FUNCTIONS; i++)
1346 		{
1347 			if (my_strncmp(name, key_names[i].name, len) == 0)
1348 			{
1349 				cnt++;
1350 				if (*func_index == -1)
1351 					*func_index = i;
1352 			}
1353 		}
1354 		if (*func_index == -1)
1355 			return (0);
1356 		if (my_strcmp(name, key_names[*func_index].name) == 0)
1357 			return (1);
1358 		else
1359 			return (cnt);
1360 	}
1361 	return (0);
1362 }
1363 
1364 /*
1365  * display_key: converts the character c to a displayable form and returns
1366  * it.  Very simple indeed
1367  */
1368 static	u_char	*
display_key(u_int c)1369 display_key(u_int c)
1370 {
1371 	static	u_char key[3];
1372 
1373 	key[2] = '\0';
1374 	if (c < 32)
1375 	{
1376 		key[0] = '^';
1377 		key[1] = c + 64;
1378 	}
1379 	else if (c == '\177')
1380 	{
1381 		key[0] = '^';
1382 		key[1] = '?';
1383 	}
1384 	else
1385 	{
1386 		key[0] = c;
1387 		key[1] = '\0';
1388 	}
1389 	return (key);
1390 }
1391 
1392 /*
1393  * show_binding: given the ascii value of a key and a meta key status (1 for
1394  * meta1 keys, 2 for meta2 keys, anything else for normal keys), this will
1395  * display the key binding for the key in a nice way
1396  */
1397 static void
show_binding(u_int c,int m)1398 show_binding(u_int c, int m)
1399 {
1400 	KeyMap	*map;
1401 	char	*meta_str;
1402 
1403 	switch (m)
1404 	{
1405 	case 1:
1406 		map = meta1_keys;
1407 		meta_str = "META1-";
1408 		break;
1409 	case 2:
1410 		map = meta2_keys;
1411 		meta_str = "META2-";
1412 		break;
1413 	case 3:
1414 		map = meta3_keys;
1415 		meta_str = "META3-";
1416 		break;
1417 	case 4:
1418 		map = meta4_keys;
1419 		meta_str = "META4-";
1420 		break;
1421 	case 5:
1422 		map = meta5_keys;
1423 		meta_str = "META5-";
1424 		break;
1425 	case 6:
1426 		map = meta6_keys;
1427 		meta_str = "META6-";
1428 		break;
1429 	case 7:
1430 		map = meta7_keys;
1431 		meta_str = "META7-";
1432 		break;
1433 	case 8:
1434 		map = meta8_keys;
1435 		meta_str = "META8-";
1436 		break;
1437 	default:
1438 		map = keys;
1439 		meta_str = CP(empty_string());
1440 		break;
1441 	}
1442 	say("%s%s is bound to %s %s", meta_str, display_key(c),
1443 		key_names[map[c].index].name, (map[c].stuff &&
1444 		(*(map[c].stuff))) ? map[c].stuff : empty_string());
1445 }
1446 
1447 /*
1448  * parse_key: converts a key string. Accepts any key, or ^c where c is any
1449  * key (representing control characters), or META1- or META2- for meta1 or
1450  * meta2 keys respectively.  The string itself is converted to true ascii
1451  * value, thus "^A" is converted to 1, etc.  Meta key info is removed and
1452  * returned as the function value, 0 for no meta key, 1 for meta1, and 2 for
1453  * meta2.  Thus, "META1-a" is converted to "a" and a 1 is returned.
1454  * Furthermore, if ^X is bound to META2_CHARACTER, and "^Xa" is passed to
1455  * parse_key(), it is converted to "a" and 2 is returned.  Do ya understand
1456  * this?
1457  */
1458 static int
parse_key(u_char * key_str)1459 parse_key(u_char *key_str)
1460 {
1461 	u_char	*ptr1, *ptr2;
1462 	u_char	c;
1463 	int	m = 0;
1464 
1465 	ptr2 = ptr1 = key_str;
1466 	while (*ptr1)
1467 	{
1468 		if (*ptr1 == '^')
1469 		{
1470 			ptr1++;
1471 			switch (*ptr1)
1472 			{
1473 			case 0:
1474 				*(ptr2++) = '^';
1475 				break;
1476 			case '?':
1477 				*(ptr2++) = '\177';
1478 				ptr1++;
1479 				break;
1480 			default:
1481 				c = *(ptr1++);
1482 				if (islower(c))
1483 					c = toupper(c);
1484 				if (c < 64)
1485 				{
1486 					say("Illegal key sequence: ^%c", c);
1487 					return (-1);
1488 				}
1489 				*(ptr2++) = c - 64;
1490 			}
1491 		}
1492 		else
1493 			*(ptr2++) = *(ptr1++);
1494 	}
1495 	*ptr2 = '\0';
1496 	if ((int) my_strlen(key_str) > 1)
1497 	{
1498 		u_char	*cmd = NULL;
1499 
1500 		malloc_strcpy(&cmd, key_str);
1501 		upper(cmd);
1502 		if (my_strncmp(cmd, "META1-", 6) == 0)
1503 		{
1504 			my_strcpy(key_str, key_str + 6);
1505 			m = 1;
1506 		}
1507 		else if (my_strncmp(cmd, "META2-", 6) == 0)
1508 		{
1509 			my_strcpy(key_str, key_str + 6);
1510 			m = 2;
1511 		}
1512 		else if (my_strncmp(cmd, "META3-", 6) == 0)
1513 		{
1514 			my_strcpy(key_str, key_str + 6);
1515 			m = 3;
1516 		}
1517 		else if (my_strncmp(cmd, "META4-", 6) == 0)
1518 		{
1519 			my_strcpy(key_str, key_str + 6);
1520 			m = 4;
1521 		}
1522 		else if (my_strncmp(cmd, "META5-", 6) == 0)
1523 		{
1524 			my_strcpy(key_str, key_str + 6);
1525 			m = 5;
1526 		}
1527 		else if (my_strncmp(cmd, "META6-", 6) == 0)
1528 		{
1529 			my_strcpy(key_str, key_str + 6);
1530 			m = 6;
1531 		}
1532 		else if (my_strncmp(cmd, "META7-", 6) == 0)
1533 		{
1534 			my_strcpy(key_str, key_str + 6);
1535 			m = 7;
1536 		}
1537 		else if (my_strncmp(cmd, "META8-", 6) == 0)
1538 		{
1539 			my_strcpy(key_str, key_str + 6);
1540 			m = 8;
1541 		}
1542 		else if (keys[(u_char) *key_str].index == META1_CHARACTER)
1543 		{
1544 			m = 1;
1545 			my_strcpy(key_str, key_str + 1);
1546 		}
1547 		else if (keys[(u_char) *key_str].index == META2_CHARACTER)
1548 		{
1549 			m = 2;
1550 			my_strcpy(key_str, key_str + 1);
1551 		}
1552 		else if (keys[(u_char) *key_str].index == META3_CHARACTER)
1553 		{
1554 			m = 3;
1555 			my_strcpy(key_str, key_str + 1);
1556 		}
1557 		else if (keys[(u_char) *key_str].index == META4_CHARACTER)
1558 		{
1559 			m = 4;
1560 			my_strcpy(key_str, key_str + 1);
1561 		}
1562 		else if (keys[(u_char) *key_str].index == META5_CHARACTER)
1563 		{
1564 			m = 5;
1565 			my_strcpy(key_str, key_str + 1);
1566 		}
1567 		else if (keys[(u_char) *key_str].index == META6_CHARACTER)
1568 		{
1569 			m = 6;
1570 			my_strcpy(key_str, key_str + 1);
1571 		}
1572 		else if (keys[(u_char) *key_str].index == META7_CHARACTER)
1573 		{
1574 			m = 7;
1575 			my_strcpy(key_str, key_str + 1);
1576 		}
1577 		else if (keys[(u_char) *key_str].index == META8_CHARACTER)
1578 		{
1579 			m = 8;
1580 			my_strcpy(key_str, key_str + 1);
1581 		}
1582 		else
1583 		{
1584 			say("Illegal key sequence: %s is not a meta-key", display_key(*key_str));
1585 			return (-1);
1586 		}
1587 		new_free(&cmd);
1588 	}
1589 	return (m);
1590 }
1591 
1592 /*
1593  * bind_it: does the actually binding of the function to the key with the
1594  * given meta modifier
1595  */
1596 static	void
bind_it(u_char * function,u_char * string,u_int key,int m)1597 bind_it(u_char *function, u_char *string, u_int key, int m)
1598 {
1599 	KeyMap	*km;
1600 	int	cnt,
1601 		func_index,
1602 		i;
1603 
1604 	switch (m)
1605 	{
1606 	case 0:
1607 		km = keys;
1608 		break;
1609 	case 1:
1610 		km = meta1_keys;
1611 		break;
1612 	case 2:
1613 		km = meta2_keys;
1614 		break;
1615 	case 3:
1616 		km = meta3_keys;
1617 		break;
1618 	case 4:
1619 		km = meta4_keys;
1620 		break;
1621 	case 5:
1622 		km = meta5_keys;
1623 		break;
1624 	case 6:
1625 		km = meta6_keys;
1626 		break;
1627 	case 7:
1628 		km = meta7_keys;
1629 		break;
1630 	case 8:
1631 		km = meta8_keys;
1632 		break;
1633 	default:
1634 		km = keys;
1635 	}
1636 	if (*string == '\0')
1637 		string = NULL;
1638 	switch (cnt = lookup_function(function, &func_index))
1639 	{
1640 	case 0:
1641 		say("No such function: %s", function);
1642 		break;
1643 	case 1:
1644 		if (! km[key].changed)
1645 		{
1646 			if ((km[key].index != func_index) ||
1647 					((string == NULL) &&
1648 					km[key].stuff) ||
1649 					((km[key].stuff == NULL) &&
1650 					string) || (string && km[key].stuff &&
1651 					my_strcmp(km[key].stuff,string)))
1652 				km[key].changed = 1;
1653 		}
1654 		km[key].index = func_index;
1655 		km[key].global = loading_global();
1656 		malloc_strcpy(&(km[key].stuff), string);
1657 		show_binding(key, m);
1658 		break;
1659 	default:
1660 		say("Ambiguous function name: %s", function);
1661 		for (i = 0; i < cnt; i++, func_index++)
1662 			put_it("%s", key_names[func_index].name);
1663 		break;
1664 	}
1665 }
1666 
1667 /* parsekeycmd: does the PARSEKEY command.  */
1668 void
parsekeycmd(u_char * command,u_char * args,u_char * subargs)1669 parsekeycmd(u_char *command, u_char *args, u_char *subargs)
1670 {
1671 	int	i;
1672 	u_char	*arg;
1673 
1674 	if ((arg = next_arg(args, &args)) != NULL)
1675 	{
1676 		switch (lookup_function(arg, &i))
1677 		{
1678 		case 0:
1679 			say("No such function %s", arg);
1680 			return;
1681 		case 1:
1682 			key_names[i].func(0, args);
1683 			break;
1684 		default:
1685 			say("Ambigious function %s", arg);
1686 			break;
1687 		}
1688 	}
1689 }
1690 
1691 /*
1692  * bindcmd: the bind command, takes a key sequence followed by a function
1693  * name followed by option arguments (used depending on the function) and
1694  * binds a key.  If no function is specified, the current binding for that
1695  * key is shown
1696  */
1697 void
bindcmd(u_char * command,u_char * args,u_char * subargs)1698 bindcmd(u_char *command, u_char *args, u_char *subargs)
1699 {
1700 	u_char	*key;
1701 	u_char	*function;
1702 	int	m;
1703 
1704 	if ((key = next_arg(args, &args)) != NULL)
1705 	{
1706 		if ((m = parse_key(key)) == -1)
1707 			return;
1708 		if (my_strlen(key) > 1)
1709 		{
1710 			say("Key sequences may not contain more than two keys");
1711 			return;
1712 		}
1713 		if ((function = next_arg(args, &args)) != NULL)
1714 			bind_it(function, args, *key, m);
1715 		else
1716 			show_binding(*key, m);
1717 	}
1718 	else
1719 	{
1720 		u_int	i;
1721 		int	charsize = charset_size();
1722 
1723 		for (i = 0; i < charsize; i++)
1724 		{
1725 			if ((keys[i].index != NOTHING) && (keys[i].index !=
1726 					SELF_INSERT))
1727 				show_binding(i, 0);
1728 		}
1729 		for (i = 0; i < charsize; i++)
1730 		{
1731 			if ((meta1_keys[i].index != NOTHING) &&
1732 					(meta1_keys[i].index != SELF_INSERT))
1733 				show_binding(i, 1);
1734 		}
1735 		for (i = 0; i < charsize; i++)
1736 		{
1737 			if ((meta2_keys[i].index != NOTHING) &&
1738 					(meta2_keys[i].index != SELF_INSERT))
1739 				show_binding(i, 2);
1740 		}
1741 		for (i = 0; i < charsize; i++)
1742 		{
1743 			if ((meta3_keys[i].index != NOTHING) &&
1744 					(meta3_keys[i].index != SELF_INSERT))
1745 				show_binding(i, 3);
1746 		}
1747 		for (i = 0; i < charsize; i++)
1748 		{
1749 			if ((meta4_keys[i].index != NOTHING) &&
1750 					(meta4_keys[i].index != SELF_INSERT))
1751 				show_binding(i, 4);
1752 		}
1753 		for (i = 0; i < charsize; i++)
1754 		{
1755 			if ((meta5_keys[i].index != NOTHING) &&
1756 					(meta5_keys[i].index != SELF_INSERT))
1757 				show_binding(i, 5);
1758 		}
1759 		for (i = 0; i < charsize; i++)
1760 		{
1761 			if ((meta6_keys[i].index != NOTHING) &&
1762 					(meta6_keys[i].index != SELF_INSERT))
1763 				show_binding(i, 6);
1764 		}
1765 		for (i = 0; i < charsize; i++)
1766 		{
1767 			if ((meta7_keys[i].index != NOTHING) &&
1768 					(meta7_keys[i].index != SELF_INSERT))
1769 				show_binding(i, 7);
1770 		}
1771 		for (i = 0; i < charsize; i++)
1772 		{
1773 			if ((meta8_keys[i].index != NOTHING) &&
1774 					(meta8_keys[i].index != SELF_INSERT))
1775 				show_binding(i, 8);
1776 		}
1777 	}
1778 }
1779 
1780 /*
1781  * rbindcmd: does the rbind command.  you give it a string that something
1782  * is bound to and it tells you all the things that are bound to that
1783  * functions
1784  */
1785 void
rbindcmd(u_char * command,u_char * args,u_char * subargs)1786 rbindcmd(u_char *command, u_char *args, u_char *subargs)
1787 {
1788 	int	f;
1789 	u_char	*arg;
1790 
1791 	if ((arg = next_arg(args, &args)) != NULL)
1792 	{
1793 		u_int	i;
1794 		int	charsize = charset_size();
1795 
1796 		switch (lookup_function(arg, &f))
1797 		{
1798 		case 0:
1799 			say("No such function %s", arg);
1800 			return;
1801 
1802 		case 1:
1803 			break;
1804 
1805 		default:
1806 			say("Ambigious function %s", arg);
1807 			return;
1808 		}
1809 
1810 		for (i = 0; i < charsize; i++)
1811 			if (f == keys[i].index)
1812 				show_binding(i, 0);
1813 		for (i = 0; i < charsize; i++)
1814 			if (f == meta1_keys[i].index)
1815 				show_binding(i, 1);
1816 		for (i = 0; i < charsize; i++)
1817 			if (f == meta2_keys[i].index)
1818 				show_binding(i, 2);
1819 		for (i = 0; i < charsize; i++)
1820 			if (f == meta3_keys[i].index)
1821 				show_binding(i, 3);
1822 		for (i = 0; i < charsize; i++)
1823 			if (f == meta4_keys[i].index)
1824 				show_binding(i, 4);
1825 		for (i = 0; i < charsize; i++)
1826 			if (f == meta5_keys[i].index)
1827 				show_binding(i, 5);
1828 		for (i = 0; i < charsize; i++)
1829 			if (f == meta6_keys[i].index)
1830 				show_binding(i, 6);
1831 		for (i = 0; i < charsize; i++)
1832 			if (f == meta7_keys[i].index)
1833 				show_binding(i, 7);
1834 		for (i = 0; i < charsize; i++)
1835 			if (f == meta8_keys[i].index)
1836 				show_binding(i, 8);
1837 	}
1838 }
1839 
1840 /*
1841  * typecmd: The TYPE command.  This parses the given string and treats each
1842  * character as tho it were typed in by the user.  Thus key bindings are used
1843  * for each character parsed.  Special case characters are control character
1844  * sequences, specified by a ^ follow by a legal control key.  Thus doing
1845  * "/TYPE ^B" will be as tho ^B were hit at the keyboard, probably moving the
1846  * cursor backward one character.
1847  */
1848 void
typecmd(u_char * command,u_char * args,u_char * subargs)1849 typecmd(u_char *command, u_char *args, u_char *subargs)
1850 {
1851 	int	c;
1852 	u_char	key;
1853 
1854 	while (*args)
1855 	{
1856 		if (*args == '^')
1857 		{
1858 			switch (*(++args))
1859 			{
1860 			case '?':
1861 				key = '\177';
1862 				args++;
1863 				break;
1864 			default:
1865 				c = *(args++);
1866 				if (islower(c))
1867 					c = toupper(c);
1868 				if (c < 64)
1869 				{
1870 					say("Illegal key sequence: ^%c", c);
1871 					return;
1872 				}
1873 				key = c - 64;
1874 				break;
1875 			}
1876 		}
1877 		else if (*args == '\\')
1878 		{
1879 			key = *++args;
1880 			args++;
1881 		}
1882 		else
1883 			key = *(args++);
1884 		edit_char((u_int)key);
1885 	}
1886 }
1887 
1888 /*
1889  * write_binding: This will write to the given FILE pointer the information
1890  * about the specified key binding.  The format it writes it out is such that
1891  * it can be parsed back in later using LOAD or with the -l switch
1892  */
1893 static	void
write_binding(u_int c,u_int m,FILE * fp,int do_all)1894 write_binding(u_int c, u_int m, FILE *fp, int do_all)
1895 {
1896 	KeyMap	*map;
1897 	char	*meta_str;
1898 
1899 	if (c == 32)
1900 		return;
1901 	switch (m)
1902 	{
1903 	case 1:
1904 		map = meta1_keys;
1905 		meta_str = "META1-";
1906 		break;
1907 	case 2:
1908 		map = meta2_keys;
1909 		meta_str = "META2-";
1910 		break;
1911 	case 3:
1912 		map = meta3_keys;
1913 		meta_str = "META3-";
1914 		break;
1915 	case 4:
1916 		map = meta4_keys;
1917 		meta_str = "META4-";
1918 		break;
1919 	case 5:
1920 		map = meta5_keys;
1921 		meta_str = "META5-";
1922 		break;
1923 	case 6:
1924 		map = meta6_keys;
1925 		meta_str = "META6-";
1926 		break;
1927 	case 7:
1928 		map = meta7_keys;
1929 		meta_str = "META7-";
1930 		break;
1931 	case 8:
1932 		map = meta8_keys;
1933 		meta_str = "META8-";
1934 		break;
1935 	default:
1936 		map = keys;
1937 		meta_str = CP(empty_string());
1938 		break;
1939 	}
1940 	if (map[c].changed)
1941 	{
1942 		fprintf(fp, "BIND %s%s %s", meta_str, display_key(c),
1943 			key_names[map[c].index].name);
1944 		if (map[c].stuff && (*(map[c].stuff)))
1945 		{
1946 			fprintf(fp, " %s\n", map[c].stuff);
1947 		}
1948 		else
1949 			fprintf(fp, "\n");
1950 	}
1951 }
1952 
1953 /*
1954  * save_bindings: this writes all the keys bindings for IRCII to the given
1955  * FILE pointer using the write_binding function
1956  */
1957 void
save_bindings(FILE * fp,int do_all)1958 save_bindings(FILE *fp, int do_all)
1959 {
1960 	int	i;
1961 	int	charsize = charset_size();
1962 
1963 	for (i = 0; i < charsize; i++)
1964 		write_binding((u_char) i, 0, fp, do_all);
1965 	for (i = 0; i < charsize; i++)
1966 		write_binding((u_char) i, 1, fp, do_all);
1967 	for (i = 0; i < charsize; i++)
1968 		write_binding((u_char) i, 2, fp, do_all);
1969 	for (i = 0; i < charsize; i++)
1970 		write_binding((u_char) i, 3, fp, do_all);
1971 	for (i = 0; i < charsize; i++)
1972 		write_binding((u_char) i, 4, fp, do_all);
1973 	for (i = 0; i < charsize; i++)
1974 		write_binding((u_char) i, 5, fp, do_all);
1975 	for (i = 0; i < charsize; i++)
1976 		write_binding((u_char) i, 6, fp, do_all);
1977 	for (i = 0; i < charsize; i++)
1978 		write_binding((u_char) i, 7, fp, do_all);
1979 	for (i = 0; i < charsize; i++)
1980 		write_binding((u_char) i, 8, fp, do_all);
1981 }
1982 
1983 KeyMap_Func
keys_get_func_from_index_and_meta(u_char key,int meta_char)1984 keys_get_func_from_index_and_meta(u_char key, int meta_char)
1985 {
1986 	switch (meta_char) {
1987 	case 1:
1988 		return key_names[meta1_keys[key].index].func;
1989 	case 2:
1990 		return key_names[meta2_keys[key].index].func;
1991 	case 3:
1992 		return key_names[meta3_keys[key].index].func;
1993 	case 4:
1994 		return key_names[meta4_keys[key].index].func;
1995 	case 5:
1996 		return key_names[meta5_keys[key].index].func;
1997 	case 6:
1998 		return key_names[meta6_keys[key].index].func;
1999 	case 7:
2000 		return key_names[meta7_keys[key].index].func;
2001 	case 8:
2002 		return key_names[meta8_keys[key].index].func;
2003 	}
2004 	return key_names[keys[key].index].func;
2005 }
2006 
2007 u_char *
keys_get_str_from_key_and_meta(u_char key,int meta_char)2008 keys_get_str_from_key_and_meta(u_char key, int meta_char)
2009 {
2010 	switch (meta_char) {
2011 	case 1:
2012 		return meta1_keys[key].stuff;
2013 	case 2:
2014 		return meta2_keys[key].stuff;
2015 	case 3:
2016 		return meta3_keys[key].stuff;
2017 	case 4:
2018 		return meta4_keys[key].stuff;
2019 	case 5:
2020 		return meta5_keys[key].stuff;
2021 	case 6:
2022 		return meta6_keys[key].stuff;
2023 	case 7:
2024 		return meta7_keys[key].stuff;
2025 	case 8:
2026 		return meta8_keys[key].stuff;
2027 	}
2028 	return keys[key].stuff;
2029 }
2030