Module Name:    src
Committed By:   christos
Date:           Thu Jul 28 01:56:27 UTC 2011

Modified Files:
        src/lib/libedit: Makefile el.c el.h map.c read.c terminal.c terminal.h
            tty.c
Added Files:
        src/lib/libedit: keymacro.c keymacro.h
Removed Files:
        src/lib/libedit: key.c key.h

Log Message:
Rename key to keymacro to avoid conflicts with term.h. The renaming of term
to terminal was again to avoid conflicts with term.h. term.h is a moving
namespace violation.


To generate a diff of this commit:
cvs rdiff -u -r1.43 -r1.44 src/lib/libedit/Makefile
cvs rdiff -u -r1.65 -r1.66 src/lib/libedit/el.c
cvs rdiff -u -r1.23 -r1.24 src/lib/libedit/el.h
cvs rdiff -u -r1.23 -r0 src/lib/libedit/key.c
cvs rdiff -u -r1.13 -r0 src/lib/libedit/key.h
cvs rdiff -u -r0 -r1.1 src/lib/libedit/keymacro.c src/lib/libedit/keymacro.h
cvs rdiff -u -r1.26 -r1.27 src/lib/libedit/map.c
cvs rdiff -u -r1.62 -r1.63 src/lib/libedit/read.c
cvs rdiff -u -r1.1 -r1.2 src/lib/libedit/terminal.c \
    src/lib/libedit/terminal.h
cvs rdiff -u -r1.36 -r1.37 src/lib/libedit/tty.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libedit/Makefile
diff -u src/lib/libedit/Makefile:1.43 src/lib/libedit/Makefile:1.44
--- src/lib/libedit/Makefile:1.43	Wed Jul 27 21:05:20 2011
+++ src/lib/libedit/Makefile	Wed Jul 27 21:56:26 2011
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.43 2011/07/28 01:05:20 christos Exp $
+#	$NetBSD: Makefile,v 1.44 2011/07/28 01:56:26 christos Exp $
 #	@(#)Makefile	8.1 (Berkeley) 6/4/93
 
 USE_SHLIBDIR=	yes
@@ -10,7 +10,7 @@
 LIBDPLIBS+=     terminfo ${.CURDIR}/../libterminfo
 
 OSRCS=	chared.c common.c el.c emacs.c fcns.c filecomplete.c help.c \
-	hist.c key.c map.c chartype.c \
+	hist.c keymacro.c map.c chartype.c \
 	parse.c prompt.c read.c refresh.c search.c sig.c terminal.c tty.c vi.c
 
 MAN=	editline.3 editrc.5

Index: src/lib/libedit/el.c
diff -u src/lib/libedit/el.c:1.65 src/lib/libedit/el.c:1.66
--- src/lib/libedit/el.c:1.65	Wed Jul 27 21:04:41 2011
+++ src/lib/libedit/el.c	Wed Jul 27 21:56:27 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: el.c,v 1.65 2011/07/28 01:04:41 christos Exp $	*/
+/*	$NetBSD: el.c,v 1.66 2011/07/28 01:56:27 christos Exp $	*/
 
 /*-
  * Copyright (c) 1992, 1993
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "@(#)el.c	8.2 (Berkeley) 1/3/94";
 #else
-__RCSID("$NetBSD: el.c,v 1.65 2011/07/28 01:04:41 christos Exp $");
+__RCSID("$NetBSD: el.c,v 1.66 2011/07/28 01:56:27 christos Exp $");
 #endif
 #endif /* not lint && not SCCSID */
 
@@ -97,7 +97,7 @@
 		el_free(el);
 		return NULL;
 	}
-	(void) key_init(el);
+	(void) keymacro_init(el);
 	(void) map_init(el);
 	if (tty_init(el) == -1)
 		el->el_flags |= NO_TTY;
@@ -125,7 +125,7 @@
 	el_reset(el);
 
 	terminal_end(el);
-	key_end(el);
+	keymacro_end(el);
 	map_end(el);
 	tty_end(el);
 	ch_end(el);

Index: src/lib/libedit/el.h
diff -u src/lib/libedit/el.h:1.23 src/lib/libedit/el.h:1.24
--- src/lib/libedit/el.h:1.23	Wed Jul 27 21:05:20 2011
+++ src/lib/libedit/el.h	Wed Jul 27 21:56:27 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: el.h,v 1.23 2011/07/28 01:05:20 christos Exp $	*/
+/*	$NetBSD: el.h,v 1.24 2011/07/28 01:56:27 christos Exp $	*/
 
 /*-
  * Copyright (c) 1992, 1993
@@ -100,7 +100,7 @@
 
 #include "tty.h"
 #include "prompt.h"
-#include "key.h"
+#include "keymacro.h"
 #include "terminal.h"
 #include "refresh.h"
 #include "chared.h"
@@ -136,7 +136,7 @@
 	el_prompt_t	  el_rprompt;	/* Prompt stuff			*/
 	el_chared_t	  el_chared;	/* Characted editor stuff	*/
 	el_map_t	  el_map;	/* Key mapping stuff		*/
-	el_key_t	  el_key;	/* Key binding stuff		*/
+	el_keymacro_t	  el_keymacro;	/* Key binding stuff		*/
 	el_history_t	  el_history;	/* History stuff		*/
 	el_search_t	  el_search;	/* Search stuff			*/
 	el_signal_t	  el_signal;	/* Signal handling stuff	*/

Index: src/lib/libedit/map.c
diff -u src/lib/libedit/map.c:1.26 src/lib/libedit/map.c:1.27
--- src/lib/libedit/map.c:1.26	Wed Jul 27 21:05:20 2011
+++ src/lib/libedit/map.c	Wed Jul 27 21:56:27 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: map.c,v 1.26 2011/07/28 01:05:20 christos Exp $	*/
+/*	$NetBSD: map.c,v 1.27 2011/07/28 01:56:27 christos Exp $	*/
 
 /*-
  * Copyright (c) 1992, 1993
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "@(#)map.c	8.1 (Berkeley) 6/4/93";
 #else
-__RCSID("$NetBSD: map.c,v 1.26 2011/07/28 01:05:20 christos Exp $");
+__RCSID("$NetBSD: map.c,v 1.27 2011/07/28 01:56:27 christos Exp $");
 #endif
 #endif /* not lint && not SCCSID */
 
@@ -1005,7 +1005,7 @@
 			break;
 		default:
 			buf[1] = i & 0177;
-			key_add(el, buf, key_map_cmd(el, (int) map[i]), XK_CMD);
+			keymacro_add(el, buf, keymacro_map_cmd(el, (int) map[i]), XK_CMD);
 			break;
 		}
 	map[(int) buf[0]] = ED_SEQUENCE_LEAD_IN;
@@ -1027,7 +1027,7 @@
 	el->el_map.type = MAP_VI;
 	el->el_map.current = el->el_map.key;
 
-	key_reset(el);
+	keymacro_reset(el);
 
 	for (i = 0; i < N_KEYS; i++) {
 		key[i] = vii[i];
@@ -1056,7 +1056,7 @@
 
 	el->el_map.type = MAP_EMACS;
 	el->el_map.current = el->el_map.key;
-	key_reset(el);
+	keymacro_reset(el);
 
 	for (i = 0; i < N_KEYS; i++) {
 		key[i] = emacs[i];
@@ -1069,7 +1069,7 @@
 	buf[0] = CONTROL('X');
 	buf[1] = CONTROL('X');
 	buf[2] = 0;
-	key_add(el, buf, key_map_cmd(el, EM_EXCHANGE_MARK), XK_CMD);
+	keymacro_add(el, buf, keymacro_map_cmd(el, EM_EXCHANGE_MARK), XK_CMD);
 
 	tty_bind_char(el, 1);
 	terminal_bind_arrow(el);
@@ -1126,7 +1126,7 @@
 	el_bindings_t *bp, *ep;
 
 	if (in[0] == '\0' || in[1] == '\0') {
-		(void) key__decode_str(in, outbuf, sizeof(outbuf), "");
+		(void) keymacro__decode_str(in, outbuf, sizeof(outbuf), "");
 		ep = &el->el_map.help[el->el_map.nfunc];
 		for (bp = el->el_map.help; bp < ep; bp++)
 			if (bp->func == map[(unsigned char) *in]) {
@@ -1135,7 +1135,7 @@
 				return;
 			}
 	} else
-		key_print(el, in);
+		keymacro_print(el, in);
 }
 
 
@@ -1155,7 +1155,7 @@
 	lastbuf[1] = 0;
 	if (map[first] == ED_UNASSIGNED) {
 		if (first == last) {
-			(void) key__decode_str(firstbuf, unparsbuf, 
+			(void) keymacro__decode_str(firstbuf, unparsbuf, 
 			    sizeof(unparsbuf), STRQQ);
 			(void) fprintf(el->el_outfile,
 			    "%-15s->  is undefined\n", unparsbuf);
@@ -1166,14 +1166,14 @@
 	for (bp = el->el_map.help; bp < ep; bp++) {
 		if (bp->func == map[first]) {
 			if (first == last) {
-				(void) key__decode_str(firstbuf, unparsbuf, 
+				(void) keymacro__decode_str(firstbuf, unparsbuf, 
 				    sizeof(unparsbuf), STRQQ);
 				(void) fprintf(el->el_outfile, "%-15s->  " FSTR "\n",
 				    unparsbuf, bp->name);
 			} else {
-				(void) key__decode_str(firstbuf, unparsbuf, 
+				(void) keymacro__decode_str(firstbuf, unparsbuf, 
 				    sizeof(unparsbuf), STRQQ);
-				(void) key__decode_str(lastbuf, extrabuf, 
+				(void) keymacro__decode_str(lastbuf, extrabuf, 
 				    sizeof(extrabuf), STRQQ);
 				(void) fprintf(el->el_outfile,
 				    "%-4s to %-7s->  " FSTR "\n",
@@ -1184,14 +1184,14 @@
 	}
 #ifdef MAP_DEBUG
 	if (map == el->el_map.key) {
-		(void) key__decode_str(firstbuf, unparsbuf, 
+		(void) keymacro__decode_str(firstbuf, unparsbuf, 
 		    sizeof(unparsbuf), STRQQ);
 		(void) fprintf(el->el_outfile,
 		    "BUG!!! %s isn't bound to anything.\n", unparsbuf);
 		(void) fprintf(el->el_outfile, "el->el_map.key[%d] == %d\n",
 		    first, el->el_map.key[first]);
 	} else {
-		(void) key__decode_str(firstbuf, unparsbuf, 
+		(void) keymacro__decode_str(firstbuf, unparsbuf, 
 		    sizeof(unparsbuf), STRQQ);
 		(void) fprintf(el->el_outfile,
 		    "BUG!!! %s isn't bound to anything.\n", unparsbuf);
@@ -1232,7 +1232,7 @@
 	map_print_some_keys(el, el->el_map.alt, prev, i - 1);
 
 	(void) fprintf(el->el_outfile, "Multi-character bindings\n");
-	key_print(el, STR(""));
+	keymacro_print(el, STR(""));
 	(void) fprintf(el->el_outfile, "Arrow key bindings\n");
 	terminal_print_arrow(el, STR(""));
 }
@@ -1325,9 +1325,9 @@
 			return (-1);
 		}
 		if (in[1])
-			(void) key_delete(el, in);
+			(void) keymacro_delete(el, in);
 		else if (map[(unsigned char) *in] == ED_SEQUENCE_LEAD_IN)
-			(void) key_delete(el, in);
+			(void) keymacro_delete(el, in);
 		else
 			map[(unsigned char) *in] = ED_UNASSIGNED;
 		return (0);
@@ -1341,7 +1341,7 @@
 	}
 #ifdef notyet
 	if (argv[argc + 1] != NULL) {
-		bindkey_usage();
+		bindkeymacro_usage();
 		return (-1);
 	}
 #endif
@@ -1355,9 +1355,9 @@
 			return (-1);
 		}
 		if (key)
-			terminal_set_arrow(el, in, key_map_str(el, out), ntype);
+			terminal_set_arrow(el, in, keymacro_map_str(el, out), ntype);
 		else
-			key_add(el, in, key_map_str(el, out), ntype);
+			keymacro_add(el, in, keymacro_map_str(el, out), ntype);
 		map[(unsigned char) *in] = ED_SEQUENCE_LEAD_IN;
 		break;
 
@@ -1369,13 +1369,13 @@
 			return (-1);
 		}
 		if (key)
-			terminal_set_arrow(el, in, key_map_str(el, out), ntype);
+			terminal_set_arrow(el, in, keymacro_map_str(el, out), ntype);
 		else {
 			if (in[1]) {
-				key_add(el, in, key_map_cmd(el, cmd), ntype);
+				keymacro_add(el, in, keymacro_map_cmd(el, cmd), ntype);
 				map[(unsigned char) *in] = ED_SEQUENCE_LEAD_IN;
 			} else {
-				key_clear(el, map, in);
+				keymacro_clear(el, map, in);
 				map[(unsigned char) *in] = cmd;
 			}
 		}

Index: src/lib/libedit/read.c
diff -u src/lib/libedit/read.c:1.62 src/lib/libedit/read.c:1.63
--- src/lib/libedit/read.c:1.62	Wed Jul 27 20:44:35 2011
+++ src/lib/libedit/read.c	Wed Jul 27 21:56:27 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: read.c,v 1.62 2011/07/28 00:44:35 christos Exp $	*/
+/*	$NetBSD: read.c,v 1.63 2011/07/28 01:56:27 christos Exp $	*/
 
 /*-
  * Copyright (c) 1992, 1993
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "@(#)read.c	8.1 (Berkeley) 6/4/93";
 #else
-__RCSID("$NetBSD: read.c,v 1.62 2011/07/28 00:44:35 christos Exp $");
+__RCSID("$NetBSD: read.c,v 1.63 2011/07/28 01:56:27 christos Exp $");
 #endif
 #endif /* not lint && not SCCSID */
 
@@ -268,8 +268,8 @@
 #endif
                         cmd = el->el_map.current[(unsigned char) *ch];
 		if (cmd == ED_SEQUENCE_LEAD_IN) {
-			key_value_t val;
-			switch (key_get(el, ch, &val)) {
+			keymacro_value_t val;
+			switch (keymacro_get(el, ch, &val)) {
 			case XK_CMD:
 				cmd = val.cmd;
 				break;

Index: src/lib/libedit/terminal.c
diff -u src/lib/libedit/terminal.c:1.1 src/lib/libedit/terminal.c:1.2
--- src/lib/libedit/terminal.c:1.1	Wed Jul 27 21:05:20 2011
+++ src/lib/libedit/terminal.c	Wed Jul 27 21:56:27 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: terminal.c,v 1.1 2011/07/28 01:05:20 christos Exp $	*/
+/*	$NetBSD: terminal.c,v 1.2 2011/07/28 01:56:27 christos Exp $	*/
 
 /*-
  * Copyright (c) 1992, 1993
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "@(#)term.c	8.2 (Berkeley) 4/30/95";
 #else
-__RCSID("$NetBSD: terminal.c,v 1.1 2011/07/28 01:05:20 christos Exp $");
+__RCSID("$NetBSD: terminal.c,v 1.2 2011/07/28 01:56:27 christos Exp $");
 #endif
 #endif /* not lint && not SCCSID */
 
@@ -65,9 +65,6 @@
 #if defined(HAVE_TERM_H) && !defined(__sun)
 #include <term.h>
 #endif
-#undef key_end
-#undef key_clear
-#undef key_print
  
 #include <sys/types.h>
 #include <sys/ioctl.h>
@@ -347,7 +344,7 @@
 	el->el_terminal.t_cap = (char *) el_malloc(TC_BUFSIZE);
 	if (el->el_terminal.t_cap == NULL)
 		return (-1);
-	el->el_terminal.t_fkey = (fkey_t *) el_malloc(A_K_NKEYS * sizeof(fkey_t));
+	el->el_terminal.t_fkey = (funckey_t *) el_malloc(A_K_NKEYS * sizeof(funckey_t));
 	if (el->el_terminal.t_fkey == NULL)
 		return (-1);
 	el->el_terminal.t_loc = 0;
@@ -1074,7 +1071,7 @@
 private void
 terminal_init_arrow(EditLine *el)
 {
-	fkey_t *arrow = el->el_terminal.t_fkey;
+	funckey_t *arrow = el->el_terminal.t_fkey;
 
 	arrow[A_K_DN].name = STR("down");
 	arrow[A_K_DN].key = T_kd;
@@ -1114,7 +1111,7 @@
 private void
 terminal_reset_arrow(EditLine *el)
 {
-	fkey_t *arrow = el->el_terminal.t_fkey;
+	funckey_t *arrow = el->el_terminal.t_fkey;
 	static const Char strA[] = {033, '[', 'A', '\0'};
 	static const Char strB[] = {033, '[', 'B', '\0'};
 	static const Char strC[] = {033, '[', 'C', '\0'};
@@ -1128,32 +1125,32 @@
 	static const Char stOH[] = {033, 'O', 'H', '\0'};
 	static const Char stOF[] = {033, 'O', 'F', '\0'};
 
-	key_add(el, strA, &arrow[A_K_UP].fun, arrow[A_K_UP].type);
-	key_add(el, strB, &arrow[A_K_DN].fun, arrow[A_K_DN].type);
-	key_add(el, strC, &arrow[A_K_RT].fun, arrow[A_K_RT].type);
-	key_add(el, strD, &arrow[A_K_LT].fun, arrow[A_K_LT].type);
-	key_add(el, strH, &arrow[A_K_HO].fun, arrow[A_K_HO].type);
-	key_add(el, strF, &arrow[A_K_EN].fun, arrow[A_K_EN].type);
-	key_add(el, stOA, &arrow[A_K_UP].fun, arrow[A_K_UP].type);
-	key_add(el, stOB, &arrow[A_K_DN].fun, arrow[A_K_DN].type);
-	key_add(el, stOC, &arrow[A_K_RT].fun, arrow[A_K_RT].type);
-	key_add(el, stOD, &arrow[A_K_LT].fun, arrow[A_K_LT].type);
-	key_add(el, stOH, &arrow[A_K_HO].fun, arrow[A_K_HO].type);
-	key_add(el, stOF, &arrow[A_K_EN].fun, arrow[A_K_EN].type);
+	keymacro_add(el, strA, &arrow[A_K_UP].fun, arrow[A_K_UP].type);
+	keymacro_add(el, strB, &arrow[A_K_DN].fun, arrow[A_K_DN].type);
+	keymacro_add(el, strC, &arrow[A_K_RT].fun, arrow[A_K_RT].type);
+	keymacro_add(el, strD, &arrow[A_K_LT].fun, arrow[A_K_LT].type);
+	keymacro_add(el, strH, &arrow[A_K_HO].fun, arrow[A_K_HO].type);
+	keymacro_add(el, strF, &arrow[A_K_EN].fun, arrow[A_K_EN].type);
+	keymacro_add(el, stOA, &arrow[A_K_UP].fun, arrow[A_K_UP].type);
+	keymacro_add(el, stOB, &arrow[A_K_DN].fun, arrow[A_K_DN].type);
+	keymacro_add(el, stOC, &arrow[A_K_RT].fun, arrow[A_K_RT].type);
+	keymacro_add(el, stOD, &arrow[A_K_LT].fun, arrow[A_K_LT].type);
+	keymacro_add(el, stOH, &arrow[A_K_HO].fun, arrow[A_K_HO].type);
+	keymacro_add(el, stOF, &arrow[A_K_EN].fun, arrow[A_K_EN].type);
 
 	if (el->el_map.type == MAP_VI) {
-		key_add(el, &strA[1], &arrow[A_K_UP].fun, arrow[A_K_UP].type);
-		key_add(el, &strB[1], &arrow[A_K_DN].fun, arrow[A_K_DN].type);
-		key_add(el, &strC[1], &arrow[A_K_RT].fun, arrow[A_K_RT].type);
-		key_add(el, &strD[1], &arrow[A_K_LT].fun, arrow[A_K_LT].type);
-		key_add(el, &strH[1], &arrow[A_K_HO].fun, arrow[A_K_HO].type);
-		key_add(el, &strF[1], &arrow[A_K_EN].fun, arrow[A_K_EN].type);
-		key_add(el, &stOA[1], &arrow[A_K_UP].fun, arrow[A_K_UP].type);
-		key_add(el, &stOB[1], &arrow[A_K_DN].fun, arrow[A_K_DN].type);
-		key_add(el, &stOC[1], &arrow[A_K_RT].fun, arrow[A_K_RT].type);
-		key_add(el, &stOD[1], &arrow[A_K_LT].fun, arrow[A_K_LT].type);
-		key_add(el, &stOH[1], &arrow[A_K_HO].fun, arrow[A_K_HO].type);
-		key_add(el, &stOF[1], &arrow[A_K_EN].fun, arrow[A_K_EN].type);
+		keymacro_add(el, &strA[1], &arrow[A_K_UP].fun, arrow[A_K_UP].type);
+		keymacro_add(el, &strB[1], &arrow[A_K_DN].fun, arrow[A_K_DN].type);
+		keymacro_add(el, &strC[1], &arrow[A_K_RT].fun, arrow[A_K_RT].type);
+		keymacro_add(el, &strD[1], &arrow[A_K_LT].fun, arrow[A_K_LT].type);
+		keymacro_add(el, &strH[1], &arrow[A_K_HO].fun, arrow[A_K_HO].type);
+		keymacro_add(el, &strF[1], &arrow[A_K_EN].fun, arrow[A_K_EN].type);
+		keymacro_add(el, &stOA[1], &arrow[A_K_UP].fun, arrow[A_K_UP].type);
+		keymacro_add(el, &stOB[1], &arrow[A_K_DN].fun, arrow[A_K_DN].type);
+		keymacro_add(el, &stOC[1], &arrow[A_K_RT].fun, arrow[A_K_RT].type);
+		keymacro_add(el, &stOD[1], &arrow[A_K_LT].fun, arrow[A_K_LT].type);
+		keymacro_add(el, &stOH[1], &arrow[A_K_HO].fun, arrow[A_K_HO].type);
+		keymacro_add(el, &stOF[1], &arrow[A_K_EN].fun, arrow[A_K_EN].type);
 	}
 }
 
@@ -1162,9 +1159,9 @@
  *	Set an arrow key binding
  */
 protected int
-terminal_set_arrow(EditLine *el, const Char *name, key_value_t *fun, int type)
+terminal_set_arrow(EditLine *el, const Char *name, keymacro_value_t *fun, int type)
 {
-	fkey_t *arrow = el->el_terminal.t_fkey;
+	funckey_t *arrow = el->el_terminal.t_fkey;
 	int i;
 
 	for (i = 0; i < A_K_NKEYS; i++)
@@ -1183,7 +1180,7 @@
 protected int
 terminal_clear_arrow(EditLine *el, const Char *name)
 {
-	fkey_t *arrow = el->el_terminal.t_fkey;
+	funckey_t *arrow = el->el_terminal.t_fkey;
 	int i;
 
 	for (i = 0; i < A_K_NKEYS; i++)
@@ -1202,12 +1199,12 @@
 terminal_print_arrow(EditLine *el, const Char *name)
 {
 	int i;
-	fkey_t *arrow = el->el_terminal.t_fkey;
+	funckey_t *arrow = el->el_terminal.t_fkey;
 
 	for (i = 0; i < A_K_NKEYS; i++)
 		if (*name == '\0' || Strcmp(name, arrow[i].name) == 0)
 			if (arrow[i].type != XK_NOD)
-				key_kprint(el, arrow[i].name, &arrow[i].fun,
+				keymacro_kprint(el, arrow[i].name, &arrow[i].fun,
 				    arrow[i].type);
 }
 
@@ -1222,7 +1219,7 @@
 	const el_action_t *dmap;
 	int i, j;
 	char *p;
-	fkey_t *arrow = el->el_terminal.t_fkey;
+	funckey_t *arrow = el->el_terminal.t_fkey;
 
 	/* Check if the components needed are initialized */
 	if (el->el_terminal.t_buf == NULL || el->el_map.key == NULL)
@@ -1258,19 +1255,19 @@
 		 *    unassigned key.
 		 */
 		if (arrow[i].type == XK_NOD)
-			key_clear(el, map, px);
+			keymacro_clear(el, map, px);
 		else {
 			if (p[1] && (dmap[j] == map[j] ||
 				map[j] == ED_SEQUENCE_LEAD_IN)) {
-				key_add(el, px, &arrow[i].fun,
+				keymacro_add(el, px, &arrow[i].fun,
 				    arrow[i].type);
 				map[j] = ED_SEQUENCE_LEAD_IN;
 			} else if (map[j] == ED_UNASSIGNED) {
-				key_clear(el, map, px);
+				keymacro_clear(el, map, px);
 				if (arrow[i].type == XK_CMD)
 					map[j] = arrow[i].fun.cmd;
 				else
-					key_add(el, px, &arrow[i].fun,
+					keymacro_add(el, px, &arrow[i].fun,
 					    arrow[i].type);
 			}
 		}
Index: src/lib/libedit/terminal.h
diff -u src/lib/libedit/terminal.h:1.1 src/lib/libedit/terminal.h:1.2
--- src/lib/libedit/terminal.h:1.1	Wed Jul 27 21:05:20 2011
+++ src/lib/libedit/terminal.h	Wed Jul 27 21:56:27 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: terminal.h,v 1.1 2011/07/28 01:05:20 christos Exp $	*/
+/*	$NetBSD: terminal.h,v 1.2 2011/07/28 01:56:27 christos Exp $	*/
 
 /*-
  * Copyright (c) 1992, 1993
@@ -45,9 +45,9 @@
 typedef struct {		/* Symbolic function key bindings	*/
 	const Char	*name;	/* name of the key			*/
 	int		 key;	/* Index in termcap table		*/
-	key_value_t	 fun;	/* Function bound to it			*/
+	keymacro_value_t	 fun;	/* Function bound to it			*/
 	int		 type;	/* Type of function			*/
-} fkey_t;
+} funckey_t;
 
 typedef struct {
 	const char *t_name;		/* the terminal name	*/
@@ -67,7 +67,7 @@
 	char	**t_str;		/* termcap strings	*/
 	int	 *t_val;		/* termcap values	*/
 	char	 *t_cap;		/* Termcap buffer	*/
-	fkey_t	 *t_fkey;		/* Array of keys	*/
+	funckey_t	 *t_fkey;		/* Array of keys	*/
 } el_terminal_t;
 
 /*
@@ -95,7 +95,7 @@
 protected void	terminal_bind_arrow(EditLine *);
 protected void	terminal_print_arrow(EditLine *, const Char *);
 protected int	terminal_clear_arrow(EditLine *, const Char *);
-protected int	terminal_set_arrow(EditLine *, const Char *, key_value_t *, int);
+protected int	terminal_set_arrow(EditLine *, const Char *, keymacro_value_t *, int);
 protected void	terminal_end(EditLine *);
 protected void	terminal_get(EditLine *, const char **);
 protected int	terminal_set(EditLine *, const char *);

Index: src/lib/libedit/tty.c
diff -u src/lib/libedit/tty.c:1.36 src/lib/libedit/tty.c:1.37
--- src/lib/libedit/tty.c:1.36	Wed Jul 27 20:45:50 2011
+++ src/lib/libedit/tty.c	Wed Jul 27 21:56:27 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: tty.c,v 1.36 2011/07/28 00:45:50 christos Exp $	*/
+/*	$NetBSD: tty.c,v 1.37 2011/07/28 01:56:27 christos Exp $	*/
 
 /*-
  * Copyright (c) 1992, 1993
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "@(#)tty.c	8.1 (Berkeley) 6/4/93";
 #else
-__RCSID("$NetBSD: tty.c,v 1.36 2011/07/28 00:45:50 christos Exp $");
+__RCSID("$NetBSD: tty.c,v 1.37 2011/07/28 01:56:27 christos Exp $");
 #endif
 #endif /* not lint && not SCCSID */
 
@@ -924,15 +924,15 @@
 		if (new[0] == old[0] && !force)
 			continue;
 		/* Put the old default binding back, and set the new binding */
-		key_clear(el, map, old);
+		keymacro_clear(el, map, old);
 		map[UC(old[0])] = dmap[UC(old[0])];
-		key_clear(el, map, new);
+		keymacro_clear(el, map, new);
 		/* MAP_VI == 1, MAP_EMACS == 0... */
 		map[UC(new[0])] = tp->bind[el->el_map.type];
 		if (dalt) {
-			key_clear(el, alt, old);
+			keymacro_clear(el, alt, old);
 			alt[UC(old[0])] = dalt[UC(old[0])];
-			key_clear(el, alt, new);
+			keymacro_clear(el, alt, new);
 			alt[UC(new[0])] = tp->bind[el->el_map.type + 1];
 		}
 	}

Added files:

Index: src/lib/libedit/keymacro.c
diff -u /dev/null src/lib/libedit/keymacro.c:1.1
--- /dev/null	Wed Jul 27 21:56:27 2011
+++ src/lib/libedit/keymacro.c	Wed Jul 27 21:56:27 2011
@@ -0,0 +1,665 @@
+/*	$NetBSD: keymacro.c,v 1.1 2011/07/28 01:56:27 christos Exp $	*/
+
+/*-
+ * Copyright (c) 1992, 1993
+ *	The Regents of the University of California.  All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Christos Zoulas of Cornell University.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include "config.h"
+#if !defined(lint) && !defined(SCCSID)
+#if 0
+static char sccsid[] = "@(#)key.c	8.1 (Berkeley) 6/4/93";
+#else
+__RCSID("$NetBSD: keymacro.c,v 1.1 2011/07/28 01:56:27 christos Exp $");
+#endif
+#endif /* not lint && not SCCSID */
+
+/*
+ * key.c: This module contains the procedures for maintaining
+ *	  the extended-key map.
+ *
+ *      An extended-key (key) is a sequence of keystrokes introduced
+ *	with a sequence introducer and consisting of an arbitrary
+ *	number of characters.  This module maintains a map (the el->el_keymacro.map)
+ *	to convert these extended-key sequences into input strs
+ *	(XK_STR), editor functions (XK_CMD), or unix commands (XK_EXE).
+ *
+ *      Warning:
+ *	  If key is a substr of some other keys, then the longer
+ *	  keys are lost!!  That is, if the keys "abcd" and "abcef"
+ *	  are in el->el_keymacro.map, adding the key "abc" will cause the first two
+ *	  definitions to be lost.
+ *
+ *      Restrictions:
+ *      -------------
+ *      1) It is not possible to have one key that is a
+ *	   substr of another.
+ */
+#include <string.h>
+#include <stdlib.h>
+
+#include "el.h"
+
+/*
+ * The Nodes of the el->el_keymacro.map.  The el->el_keymacro.map is a linked list
+ * of these node elements
+ */
+struct keymacro_node_t {
+	Char		ch;		/* single character of key 	 */
+	int		type;		/* node type			 */
+	keymacro_value_t	val;		/* command code or pointer to str,  */
+					/* if this is a leaf 		 */
+	struct keymacro_node_t *next;	/* ptr to next char of this key  */
+	struct keymacro_node_t *sibling;	/* ptr to another key with same prefix*/
+};
+
+private int		 node_trav(EditLine *, keymacro_node_t *, Char *,
+    keymacro_value_t *);
+private int		 node__try(EditLine *, keymacro_node_t *, const Char *,
+    keymacro_value_t *, int);
+private keymacro_node_t	*node__get(Int);
+private void		 node__free(keymacro_node_t *);
+private void		 node__put(EditLine *, keymacro_node_t *);
+private int		 node__delete(EditLine *, keymacro_node_t **, const Char *);
+private int		 node_lookup(EditLine *, const Char *, keymacro_node_t *,
+    size_t);
+private int		 node_enum(EditLine *, keymacro_node_t *, size_t);
+
+#define	KEY_BUFSIZ	EL_BUFSIZ
+
+
+/* keymacro_init():
+ *	Initialize the key maps
+ */
+protected int
+keymacro_init(EditLine *el)
+{
+
+	el->el_keymacro.buf = el_malloc(KEY_BUFSIZ * sizeof(*el->el_keymacro.buf));
+	if (el->el_keymacro.buf == NULL)
+		return (-1);
+	el->el_keymacro.map = NULL;
+	keymacro_reset(el);
+	return (0);
+}
+
+/* keymacro_end():
+ *	Free the key maps
+ */
+protected void
+keymacro_end(EditLine *el)
+{
+
+	el_free((ptr_t) el->el_keymacro.buf);
+	el->el_keymacro.buf = NULL;
+	node__free(el->el_keymacro.map);
+}
+
+
+/* keymacro_map_cmd():
+ *	Associate cmd with a key value
+ */
+protected keymacro_value_t *
+keymacro_map_cmd(EditLine *el, int cmd)
+{
+
+	el->el_keymacro.val.cmd = (el_action_t) cmd;
+	return (&el->el_keymacro.val);
+}
+
+
+/* keymacro_map_str():
+ *	Associate str with a key value
+ */
+protected keymacro_value_t *
+keymacro_map_str(EditLine *el, Char *str)
+{
+
+	el->el_keymacro.val.str = str;
+	return (&el->el_keymacro.val);
+}
+
+
+/* keymacro_reset():
+ *	Takes all nodes on el->el_keymacro.map and puts them on free list.  Then
+ *	initializes el->el_keymacro.map with arrow keys
+ *	[Always bind the ansi arrow keys?]
+ */
+protected void
+keymacro_reset(EditLine *el)
+{
+
+	node__put(el, el->el_keymacro.map);
+	el->el_keymacro.map = NULL;
+	return;
+}
+
+
+/* keymacro_get():
+ *	Calls the recursive function with entry point el->el_keymacro.map
+ *      Looks up *ch in map and then reads characters until a
+ *      complete match is found or a mismatch occurs. Returns the
+ *      type of the match found (XK_STR, XK_CMD, or XK_EXE).
+ *      Returns NULL in val.str and XK_STR for no match.
+ *      The last character read is returned in *ch.
+ */
+protected int
+keymacro_get(EditLine *el, Char *ch, keymacro_value_t *val)
+{
+
+	return (node_trav(el, el->el_keymacro.map, ch, val));
+}
+
+
+/* keymacro_add():
+ *      Adds key to the el->el_keymacro.map and associates the value in val with it.
+ *      If key is already is in el->el_keymacro.map, the new code is applied to the
+ *      existing key. Ntype specifies if code is a command, an
+ *      out str or a unix command.
+ */
+protected void
+keymacro_add(EditLine *el, const Char *key, keymacro_value_t *val, int ntype)
+{
+
+	if (key[0] == '\0') {
+		(void) fprintf(el->el_errfile,
+		    "keymacro_add: Null extended-key not allowed.\n");
+		return;
+	}
+	if (ntype == XK_CMD && val->cmd == ED_SEQUENCE_LEAD_IN) {
+		(void) fprintf(el->el_errfile,
+		    "keymacro_add: sequence-lead-in command not allowed\n");
+		return;
+	}
+	if (el->el_keymacro.map == NULL)
+		/* tree is initially empty.  Set up new node to match key[0] */
+		el->el_keymacro.map = node__get(key[0]);
+			/* it is properly initialized */
+
+	/* Now recurse through el->el_keymacro.map */
+	(void) node__try(el, el->el_keymacro.map, key, val, ntype);
+	return;
+}
+
+
+/* keymacro_clear():
+ *
+ */
+protected void
+keymacro_clear(EditLine *el, el_action_t *map, const Char *in)
+{
+#ifdef WIDECHAR
+        if (*in > N_KEYS) /* can't be in the map */
+                return;
+#endif
+	if ((map[(unsigned char)*in] == ED_SEQUENCE_LEAD_IN) &&
+	    ((map == el->el_map.key &&
+	    el->el_map.alt[(unsigned char)*in] != ED_SEQUENCE_LEAD_IN) ||
+	    (map == el->el_map.alt &&
+	    el->el_map.key[(unsigned char)*in] != ED_SEQUENCE_LEAD_IN)))
+		(void) keymacro_delete(el, in);
+}
+
+
+/* keymacro_delete():
+ *      Delete the key and all longer keys staring with key, if
+ *      they exists.
+ */
+protected int
+keymacro_delete(EditLine *el, const Char *key)
+{
+
+	if (key[0] == '\0') {
+		(void) fprintf(el->el_errfile,
+		    "keymacro_delete: Null extended-key not allowed.\n");
+		return (-1);
+	}
+	if (el->el_keymacro.map == NULL)
+		return (0);
+
+	(void) node__delete(el, &el->el_keymacro.map, key);
+	return (0);
+}
+
+
+/* keymacro_print():
+ *	Print the binding associated with key key.
+ *	Print entire el->el_keymacro.map if null
+ */
+protected void
+keymacro_print(EditLine *el, const Char *key)
+{
+
+	/* do nothing if el->el_keymacro.map is empty and null key specified */
+	if (el->el_keymacro.map == NULL && *key == 0)
+		return;
+
+	el->el_keymacro.buf[0] = '"';
+	if (node_lookup(el, key, el->el_keymacro.map, 1) <= -1)
+		/* key is not bound */
+		(void) fprintf(el->el_errfile, "Unbound extended key \"" FSTR "\"\n",
+		    key);
+	return;
+}
+
+
+/* node_trav():
+ *	recursively traverses node in tree until match or mismatch is
+ * 	found.  May read in more characters.
+ */
+private int
+node_trav(EditLine *el, keymacro_node_t *ptr, Char *ch, keymacro_value_t *val)
+{
+
+	if (ptr->ch == *ch) {
+		/* match found */
+		if (ptr->next) {
+			/* key not complete so get next char */
+			if (FUN(el,getc)(el, ch) != 1) {/* if EOF or error */
+				val->cmd = ED_END_OF_FILE;
+				return (XK_CMD);
+				/* PWP: Pretend we just read an end-of-file */
+			}
+			return (node_trav(el, ptr->next, ch, val));
+		} else {
+			*val = ptr->val;
+			if (ptr->type != XK_CMD)
+				*ch = '\0';
+			return (ptr->type);
+		}
+	} else {
+		/* no match found here */
+		if (ptr->sibling) {
+			/* try next sibling */
+			return (node_trav(el, ptr->sibling, ch, val));
+		} else {
+			/* no next sibling -- mismatch */
+			val->str = NULL;
+			return (XK_STR);
+		}
+	}
+}
+
+
+/* node__try():
+ * 	Find a node that matches *str or allocate a new one
+ */
+private int
+node__try(EditLine *el, keymacro_node_t *ptr, const Char *str, keymacro_value_t *val, int ntype)
+{
+
+	if (ptr->ch != *str) {
+		keymacro_node_t *xm;
+
+		for (xm = ptr; xm->sibling != NULL; xm = xm->sibling)
+			if (xm->sibling->ch == *str)
+				break;
+		if (xm->sibling == NULL)
+			xm->sibling = node__get(*str);	/* setup new node */
+		ptr = xm->sibling;
+	}
+	if (*++str == '\0') {
+		/* we're there */
+		if (ptr->next != NULL) {
+			node__put(el, ptr->next);
+				/* lose longer keys with this prefix */
+			ptr->next = NULL;
+		}
+		switch (ptr->type) {
+		case XK_CMD:
+		case XK_NOD:
+			break;
+		case XK_STR:
+		case XK_EXE:
+			if (ptr->val.str)
+				el_free((ptr_t) ptr->val.str);
+			break;
+		default:
+			EL_ABORT((el->el_errfile, "Bad XK_ type %d\n",
+			    ptr->type));
+			break;
+		}
+
+		switch (ptr->type = ntype) {
+		case XK_CMD:
+			ptr->val = *val;
+			break;
+		case XK_STR:
+		case XK_EXE:
+			if ((ptr->val.str = Strdup(val->str)) == NULL)
+				return -1;
+			break;
+		default:
+			EL_ABORT((el->el_errfile, "Bad XK_ type %d\n", ntype));
+			break;
+		}
+	} else {
+		/* still more chars to go */
+		if (ptr->next == NULL)
+			ptr->next = node__get(*str);	/* setup new node */
+		(void) node__try(el, ptr->next, str, val, ntype);
+	}
+	return (0);
+}
+
+
+/* node__delete():
+ *	Delete node that matches str
+ */
+private int
+node__delete(EditLine *el, keymacro_node_t **inptr, const Char *str)
+{
+	keymacro_node_t *ptr;
+	keymacro_node_t *prev_ptr = NULL;
+
+	ptr = *inptr;
+
+	if (ptr->ch != *str) {
+		keymacro_node_t *xm;
+
+		for (xm = ptr; xm->sibling != NULL; xm = xm->sibling)
+			if (xm->sibling->ch == *str)
+				break;
+		if (xm->sibling == NULL)
+			return (0);
+		prev_ptr = xm;
+		ptr = xm->sibling;
+	}
+	if (*++str == '\0') {
+		/* we're there */
+		if (prev_ptr == NULL)
+			*inptr = ptr->sibling;
+		else
+			prev_ptr->sibling = ptr->sibling;
+		ptr->sibling = NULL;
+		node__put(el, ptr);
+		return (1);
+	} else if (ptr->next != NULL &&
+	    node__delete(el, &ptr->next, str) == 1) {
+		if (ptr->next != NULL)
+			return (0);
+		if (prev_ptr == NULL)
+			*inptr = ptr->sibling;
+		else
+			prev_ptr->sibling = ptr->sibling;
+		ptr->sibling = NULL;
+		node__put(el, ptr);
+		return (1);
+	} else {
+		return (0);
+	}
+}
+
+
+/* node__put():
+ *	Puts a tree of nodes onto free list using free(3).
+ */
+private void
+node__put(EditLine *el, keymacro_node_t *ptr)
+{
+	if (ptr == NULL)
+		return;
+
+	if (ptr->next != NULL) {
+		node__put(el, ptr->next);
+		ptr->next = NULL;
+	}
+	node__put(el, ptr->sibling);
+
+	switch (ptr->type) {
+	case XK_CMD:
+	case XK_NOD:
+		break;
+	case XK_EXE:
+	case XK_STR:
+		if (ptr->val.str != NULL)
+			el_free((ptr_t) ptr->val.str);
+		break;
+	default:
+		EL_ABORT((el->el_errfile, "Bad XK_ type %d\n", ptr->type));
+		break;
+	}
+	el_free((ptr_t) ptr);
+}
+
+
+/* node__get():
+ *	Returns pointer to a keymacro_node_t for ch.
+ */
+private keymacro_node_t *
+node__get(Int ch)
+{
+	keymacro_node_t *ptr;
+
+	ptr = (keymacro_node_t *) el_malloc((size_t) sizeof(keymacro_node_t));
+	if (ptr == NULL)
+		return NULL;
+	ptr->ch = ch;
+	ptr->type = XK_NOD;
+	ptr->val.str = NULL;
+	ptr->next = NULL;
+	ptr->sibling = NULL;
+	return (ptr);
+}
+
+private void
+node__free(keymacro_node_t *k)
+{
+	if (k == NULL)
+		return;
+	node__free(k->sibling);
+	node__free(k->next);
+	el_free((ptr_t) k);
+}
+
+/* node_lookup():
+ *	look for the str starting at node ptr.
+ *	Print if last node
+ */
+private int
+node_lookup(EditLine *el, const Char *str, keymacro_node_t *ptr, size_t cnt)
+{
+	ssize_t used;
+
+	if (ptr == NULL)
+		return (-1);	/* cannot have null ptr */
+
+	if (!str || *str == 0) {
+		/* no more chars in str.  node_enum from here. */
+		(void) node_enum(el, ptr, cnt);
+		return (0);
+	} else {
+		/* If match put this char into el->el_keymacro.buf.  Recurse */
+		if (ptr->ch == *str) {
+			/* match found */
+			used = ct_visual_char(el->el_keymacro.buf + cnt,
+			    KEY_BUFSIZ - cnt, ptr->ch);
+			if (used == -1)
+				return (-1); /* ran out of buffer space */
+			if (ptr->next != NULL)
+				/* not yet at leaf */
+				return (node_lookup(el, str + 1, ptr->next,
+				    used + cnt));
+			else {
+			    /* next node is null so key should be complete */
+				if (str[1] == 0) {
+					el->el_keymacro.buf[cnt + used    ] = '"';
+					el->el_keymacro.buf[cnt + used + 1] = '\0';
+					keymacro_kprint(el, el->el_keymacro.buf,
+					    &ptr->val, ptr->type);
+					return (0);
+				} else
+					return (-1);
+					/* mismatch -- str still has chars */
+			}
+		} else {
+			/* no match found try sibling */
+			if (ptr->sibling)
+				return (node_lookup(el, str, ptr->sibling,
+				    cnt));
+			else
+				return (-1);
+		}
+	}
+}
+
+
+/* node_enum():
+ *	Traverse the node printing the characters it is bound in buffer
+ */
+private int
+node_enum(EditLine *el, keymacro_node_t *ptr, size_t cnt)
+{
+        ssize_t used;
+
+	if (cnt >= KEY_BUFSIZ - 5) {	/* buffer too small */
+		el->el_keymacro.buf[++cnt] = '"';
+		el->el_keymacro.buf[++cnt] = '\0';
+		(void) fprintf(el->el_errfile,
+		    "Some extended keys too long for internal print buffer");
+		(void) fprintf(el->el_errfile, " \"" FSTR "...\"\n", el->el_keymacro.buf);
+		return (0);
+	}
+	if (ptr == NULL) {
+#ifdef DEBUG_EDIT
+		(void) fprintf(el->el_errfile,
+		    "node_enum: BUG!! Null ptr passed\n!");
+#endif
+		return (-1);
+	}
+	/* put this char at end of str */
+        used = ct_visual_char(el->el_keymacro.buf + cnt, KEY_BUFSIZ - cnt, ptr->ch);
+	if (ptr->next == NULL) {
+		/* print this key and function */
+		el->el_keymacro.buf[cnt + used   ] = '"';
+		el->el_keymacro.buf[cnt + used + 1] = '\0';
+		keymacro_kprint(el, el->el_keymacro.buf, &ptr->val, ptr->type);
+	} else
+		(void) node_enum(el, ptr->next, cnt + used);
+
+	/* go to sibling if there is one */
+	if (ptr->sibling)
+		(void) node_enum(el, ptr->sibling, cnt);
+	return (0);
+}
+
+
+/* keymacro_kprint():
+ *	Print the specified key and its associated
+ *	function specified by val
+ */
+protected void
+keymacro_kprint(EditLine *el, const Char *key, keymacro_value_t *val, int ntype)
+{
+	el_bindings_t *fp;
+	char unparsbuf[EL_BUFSIZ];
+	static const char fmt[] = "%-15s->  %s\n";
+
+	if (val != NULL)
+		switch (ntype) {
+		case XK_STR:
+		case XK_EXE:
+			(void) keymacro__decode_str(val->str, unparsbuf,
+			    sizeof(unparsbuf), 
+			    ntype == XK_STR ? "\"\"" : "[]");
+			(void) fprintf(el->el_outfile, fmt,
+			    ct_encode_string(key, &el->el_scratch), unparsbuf);
+			break;
+		case XK_CMD:
+			for (fp = el->el_map.help; fp->name; fp++)
+				if (val->cmd == fp->func) {
+                    ct_wcstombs(unparsbuf, fp->name, sizeof(unparsbuf));
+                    unparsbuf[sizeof(unparsbuf) -1] = '\0';
+					(void) fprintf(el->el_outfile, fmt,
+                        ct_encode_string(key, &el->el_scratch), unparsbuf);
+					break;
+				}
+#ifdef DEBUG_KEY
+			if (fp->name == NULL)
+				(void) fprintf(el->el_outfile,
+				    "BUG! Command not found.\n");
+#endif
+
+			break;
+		default:
+			EL_ABORT((el->el_errfile, "Bad XK_ type %d\n", ntype));
+			break;
+		}
+	else
+		(void) fprintf(el->el_outfile, fmt, ct_encode_string(key,
+		    &el->el_scratch), "no input");
+}
+
+
+#define ADDC(c) \
+	if (b < eb) \
+		*b++ = c; \
+	else \
+		b++
+/* keymacro__decode_str():
+ *	Make a printable version of the ey
+ */
+protected size_t
+keymacro__decode_str(const Char *str, char *buf, size_t len, const char *sep)
+{
+	char *b = buf, *eb = b + len;
+	const Char *p;
+
+	b = buf;
+	if (sep[0] != '\0') {
+		ADDC(sep[0]);
+	}
+	if (*str == '\0') {
+		ADDC('^');
+		ADDC('@');
+		goto add_endsep;
+	}
+	for (p = str; *p != 0; p++) {
+		Char dbuf[VISUAL_WIDTH_MAX];
+		Char *p2 = dbuf;
+		ssize_t l = ct_visual_char(dbuf, VISUAL_WIDTH_MAX, *p);
+		while (l-- > 0) {
+			ssize_t n = ct_encode_char(b, (size_t)(eb - b), *p2++);
+			if (n == -1) /* ran out of space */
+				goto add_endsep;
+			else
+				b += n;
+		}
+	}
+add_endsep:
+	if (sep[0] != '\0' && sep[1] != '\0') {
+		ADDC(sep[1]);
+	}
+	ADDC('\0');
+	if ((size_t)(b - buf) >= len)
+	    buf[len - 1] = '\0';
+	return (size_t)(b - buf);
+}
+
Index: src/lib/libedit/keymacro.h
diff -u /dev/null src/lib/libedit/keymacro.h:1.1
--- /dev/null	Wed Jul 27 21:56:27 2011
+++ src/lib/libedit/keymacro.h	Wed Jul 27 21:56:27 2011
@@ -0,0 +1,76 @@
+/*	$NetBSD: keymacro.h,v 1.1 2011/07/28 01:56:27 christos Exp $	*/
+
+/*-
+ * Copyright (c) 1992, 1993
+ *	The Regents of the University of California.  All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Christos Zoulas of Cornell University.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ *	@(#)key.h	8.1 (Berkeley) 6/4/93
+ */
+
+/*
+ * el.key.h: Key macro header
+ */
+#ifndef _h_el_keymacro
+#define	_h_el_keymacro
+
+typedef union keymacro_value_t {
+	el_action_t	 cmd;	/* If it is a command the #	*/
+	Char		*str;	/* If it is a string...		*/
+} keymacro_value_t;
+
+typedef struct keymacro_node_t keymacro_node_t;
+
+typedef struct el_keymacromacro_t {
+	Char		*buf;	/* Key print buffer		*/
+	keymacro_node_t	*map;	/* Key map			*/
+	keymacro_value_t	 val;	/* Local conversion buffer	*/
+} el_keymacro_t;
+
+#define	XK_CMD	0
+#define	XK_STR	1
+#define	XK_NOD	2
+#define	XK_EXE	3
+
+protected int		 keymacro_init(EditLine *);
+protected void		 keymacro_end(EditLine *);
+protected keymacro_value_t	*keymacro_map_cmd(EditLine *, int);
+protected keymacro_value_t	*keymacro_map_str(EditLine *, Char *);
+protected void		 keymacro_reset(EditLine *);
+protected int		 keymacro_get(EditLine *, Char *, keymacro_value_t *);
+protected void		 keymacro_add(EditLine *, const Char *, keymacro_value_t *, int);
+protected void		 keymacro_clear(EditLine *, el_action_t *, const Char *);
+protected int		 keymacro_delete(EditLine *, const Char *);
+protected void		 keymacro_print(EditLine *, const Char *);
+protected void	         keymacro_kprint(EditLine *, const Char *, keymacro_value_t *,
+    int);
+protected size_t	 keymacro__decode_str(const Char *, char *, size_t,
+    const char *);
+
+#endif /* _h_el_keymacro */

Reply via email to